blob: ec628bb27ad5548b1271bde14214d371a8e36093 [file] [log] [blame]
Andy Fleming9082eea2011-04-07 21:56:05 -05001/*
2 * Micrel PHY drivers
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Andy Fleming9082eea2011-04-07 21:56:05 -05005 *
6 * Copyright 2010-2011 Freescale Semiconductor, Inc.
7 * author Andy Fleming
David Andrey62d7dba2013-02-06 22:18:37 +01008 * (C) 2012 NetModule AG, David Andrey, added KSZ9031
Andy Fleming9082eea2011-04-07 21:56:05 -05009 */
Troy Kisky8682aba2012-02-07 14:08:48 +000010#include <config.h>
11#include <common.h>
Marek Vasut22854bd2015-12-05 17:41:58 +010012#include <dm.h>
13#include <errno.h>
14#include <fdtdec.h>
Troy Kisky8682aba2012-02-07 14:08:48 +000015#include <micrel.h>
Andy Fleming9082eea2011-04-07 21:56:05 -050016#include <phy.h>
17
Marek Vasut22854bd2015-12-05 17:41:58 +010018DECLARE_GLOBAL_DATA_PTR;
19
Andy Fleming9082eea2011-04-07 21:56:05 -050020static struct phy_driver KSZ804_driver = {
21 .name = "Micrel KSZ804",
22 .uid = 0x221510,
23 .mask = 0xfffff0,
24 .features = PHY_BASIC_FEATURES,
25 .config = &genphy_config,
26 .startup = &genphy_startup,
27 .shutdown = &genphy_shutdown,
28};
29
Alexandre Messier79e3efd2016-01-22 14:06:33 -050030#define MII_KSZPHY_OMSO 0x16
31#define KSZPHY_OMSO_B_CAST_OFF (1 << 9)
32
33static int ksz_genconfig_bcastoff(struct phy_device *phydev)
34{
35 int ret;
36
37 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO);
38 if (ret < 0)
39 return ret;
40
41 ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO,
42 ret | KSZPHY_OMSO_B_CAST_OFF);
43 if (ret < 0)
44 return ret;
45
46 return genphy_config(phydev);
47}
48
Sylvain Lemieux6617f872015-09-09 16:29:51 -040049static struct phy_driver KSZ8031_driver = {
50 .name = "Micrel KSZ8021/KSZ8031",
51 .uid = 0x221550,
52 .mask = 0xfffff0,
53 .features = PHY_BASIC_FEATURES,
Alexandre Messier79e3efd2016-01-22 14:06:33 -050054 .config = &ksz_genconfig_bcastoff,
Sylvain Lemieux6617f872015-09-09 16:29:51 -040055 .startup = &genphy_startup,
56 .shutdown = &genphy_shutdown,
57};
58
Sylvain Rochet4f485152015-10-07 22:54:22 +020059/**
60 * KSZ8051
61 */
62#define MII_KSZ8051_PHY_OMSO 0x16
63#define MII_KSZ8051_PHY_OMSO_NAND_TREE_ON (1 << 5)
64
65static int ksz8051_config(struct phy_device *phydev)
66{
67 unsigned val;
68
69 /* Disable NAND-tree */
70 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO);
71 val &= ~MII_KSZ8051_PHY_OMSO_NAND_TREE_ON;
72 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO, val);
73
74 return genphy_config(phydev);
75}
76
77static struct phy_driver KSZ8051_driver = {
78 .name = "Micrel KSZ8051",
79 .uid = 0x221550,
80 .mask = 0xfffff0,
81 .features = PHY_BASIC_FEATURES,
82 .config = &ksz8051_config,
83 .startup = &genphy_startup,
84 .shutdown = &genphy_shutdown,
85};
86
Luca Elleroc6a40f62015-03-24 11:32:24 +010087static struct phy_driver KSZ8081_driver = {
88 .name = "Micrel KSZ8081",
89 .uid = 0x221560,
90 .mask = 0xfffff0,
91 .features = PHY_BASIC_FEATURES,
Alexandre Messier79e3efd2016-01-22 14:06:33 -050092 .config = &ksz_genconfig_bcastoff,
Luca Elleroc6a40f62015-03-24 11:32:24 +010093 .startup = &genphy_startup,
94 .shutdown = &genphy_shutdown,
95};
96
Philippe De Muyterb7a5b082014-02-19 17:21:59 +010097/**
98 * KSZ8895
99 */
100
101static unsigned short smireg_to_phy(unsigned short reg)
102{
103 return ((reg & 0xc0) >> 3) + 0x06 + ((reg & 0x20) >> 5);
104}
105
106static unsigned short smireg_to_reg(unsigned short reg)
107{
108 return reg & 0x1F;
109}
110
111static void ksz8895_write_smireg(struct phy_device *phydev, int smireg, int val)
112{
113 phydev->bus->write(phydev->bus, smireg_to_phy(smireg), MDIO_DEVAD_NONE,
114 smireg_to_reg(smireg), val);
115}
116
117#if 0
118static int ksz8895_read_smireg(struct phy_device *phydev, int smireg)
119{
120 return phydev->bus->read(phydev->bus, smireg_to_phy(smireg),
121 MDIO_DEVAD_NONE, smireg_to_reg(smireg));
122}
123#endif
124
125int ksz8895_config(struct phy_device *phydev)
126{
127 /* we are connected directly to the switch without
128 * dedicated PHY. SCONF1 == 001 */
129 phydev->link = 1;
130 phydev->duplex = DUPLEX_FULL;
131 phydev->speed = SPEED_100;
132
133 /* Force the switch to start */
134 ksz8895_write_smireg(phydev, 1, 1);
135
136 return 0;
137}
138
139static int ksz8895_startup(struct phy_device *phydev)
140{
141 return 0;
142}
143
144static struct phy_driver ksz8895_driver = {
145 .name = "Micrel KSZ8895/KSZ8864",
146 .uid = 0x221450,
147 .mask = 0xffffe1,
148 .features = PHY_BASIC_FEATURES,
149 .config = &ksz8895_config,
150 .startup = &ksz8895_startup,
151 .shutdown = &genphy_shutdown,
152};
153
Alexandru Gagniucfbc120e2017-07-07 11:36:59 -0700154/* Micrel used the exact same part number for the KSZ9021. */
Vladimir Zapolskiyfcc0c752011-12-06 02:47:57 +0000155static struct phy_driver KS8721_driver = {
156 .name = "Micrel KS8721BL",
157 .uid = 0x221610,
158 .mask = 0xfffff0,
159 .features = PHY_BASIC_FEATURES,
160 .config = &genphy_config,
161 .startup = &genphy_startup,
162 .shutdown = &genphy_shutdown,
163};
David Andrey62d7dba2013-02-06 22:18:37 +0100164
Alexey Firago79887742016-05-26 16:28:44 +0300165int ksz886x_config(struct phy_device *phydev)
166{
167 /* we are connected directly to the switch without
168 * dedicated PHY. */
169 phydev->link = 1;
170 phydev->duplex = DUPLEX_FULL;
171 phydev->speed = SPEED_100;
172 return 0;
173}
174
175static int ksz886x_startup(struct phy_device *phydev)
176{
177 return 0;
178}
179
180static struct phy_driver ksz886x_driver = {
181 .name = "Micrel KSZ886x Switch",
182 .uid = 0x00221430,
183 .mask = 0xfffff0,
184 .features = PHY_BASIC_FEATURES,
185 .config = &ksz886x_config,
186 .startup = &ksz886x_startup,
187 .shutdown = &genphy_shutdown,
188};
189
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700190int phy_micrel_ksz8xxx_init(void)
Andy Fleming9082eea2011-04-07 21:56:05 -0500191{
192 phy_register(&KSZ804_driver);
Sylvain Lemieux6617f872015-09-09 16:29:51 -0400193 phy_register(&KSZ8031_driver);
Sylvain Rochet4f485152015-10-07 22:54:22 +0200194 phy_register(&KSZ8051_driver);
Luca Elleroc6a40f62015-03-24 11:32:24 +0100195 phy_register(&KSZ8081_driver);
Troy Kiskycc5f5522012-06-28 08:00:28 +0000196 phy_register(&KS8721_driver);
Philippe De Muyterb7a5b082014-02-19 17:21:59 +0100197 phy_register(&ksz8895_driver);
Alexey Firago79887742016-05-26 16:28:44 +0300198 phy_register(&ksz886x_driver);
Andy Fleming9082eea2011-04-07 21:56:05 -0500199 return 0;
200}