1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright 2010-2011 Freescale Semiconductor, Inc.
7 * (C) 2012 NetModule AG, David Andrey, added KSZ9031
15 #include <linux/bitops.h>
17 static struct phy_driver KSZ804_driver = {
18 .name = "Micrel KSZ804",
21 .features = PHY_BASIC_FEATURES,
22 .config = &genphy_config,
23 .startup = &genphy_startup,
24 .shutdown = &genphy_shutdown,
27 #define MII_KSZPHY_OMSO 0x16
28 #define KSZPHY_OMSO_FACTORY_TEST BIT(15)
29 #define KSZPHY_OMSO_B_CAST_OFF (1 << 9)
31 static int ksz_genconfig_bcastoff(struct phy_device *phydev)
35 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO);
39 ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO,
40 ret | KSZPHY_OMSO_B_CAST_OFF);
44 return genphy_config(phydev);
47 static struct phy_driver KSZ8031_driver = {
48 .name = "Micrel KSZ8021/KSZ8031",
51 .features = PHY_BASIC_FEATURES,
52 .config = &ksz_genconfig_bcastoff,
53 .startup = &genphy_startup,
54 .shutdown = &genphy_shutdown,
60 #define MII_KSZ8051_PHY_OMSO 0x16
61 #define MII_KSZ8051_PHY_OMSO_NAND_TREE_ON (1 << 5)
63 static int ksz8051_config(struct phy_device *phydev)
67 /* Disable NAND-tree */
68 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO);
69 val &= ~MII_KSZ8051_PHY_OMSO_NAND_TREE_ON;
70 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO, val);
72 return genphy_config(phydev);
75 static struct phy_driver KSZ8051_driver = {
76 .name = "Micrel KSZ8051",
79 .features = PHY_BASIC_FEATURES,
80 .config = &ksz8051_config,
81 .startup = &genphy_startup,
82 .shutdown = &genphy_shutdown,
85 static int ksz8061_config(struct phy_device *phydev)
87 return phy_write(phydev, MDIO_MMD_PMAPMD, MDIO_DEVID1, 0xB61A);
90 static struct phy_driver KSZ8061_driver = {
91 .name = "Micrel KSZ8061",
94 .features = PHY_BASIC_FEATURES,
95 .config = &ksz8061_config,
96 .startup = &genphy_startup,
97 .shutdown = &genphy_shutdown,
100 static int ksz8081_config(struct phy_device *phydev)
104 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO);
108 ret &= ~KSZPHY_OMSO_FACTORY_TEST;
110 ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO,
111 ret | KSZPHY_OMSO_B_CAST_OFF);
115 return genphy_config(phydev);
118 static struct phy_driver KSZ8081_driver = {
119 .name = "Micrel KSZ8081",
122 .features = PHY_BASIC_FEATURES,
123 .config = &ksz8081_config,
124 .startup = &genphy_startup,
125 .shutdown = &genphy_shutdown,
132 static unsigned short smireg_to_phy(unsigned short reg)
134 return ((reg & 0xc0) >> 3) + 0x06 + ((reg & 0x20) >> 5);
137 static unsigned short smireg_to_reg(unsigned short reg)
142 static void ksz8895_write_smireg(struct phy_device *phydev, int smireg, int val)
144 phydev->bus->write(phydev->bus, smireg_to_phy(smireg), MDIO_DEVAD_NONE,
145 smireg_to_reg(smireg), val);
149 static int ksz8895_read_smireg(struct phy_device *phydev, int smireg)
151 return phydev->bus->read(phydev->bus, smireg_to_phy(smireg),
152 MDIO_DEVAD_NONE, smireg_to_reg(smireg));
156 int ksz8895_config(struct phy_device *phydev)
158 /* we are connected directly to the switch without
159 * dedicated PHY. SCONF1 == 001 */
161 phydev->duplex = DUPLEX_FULL;
162 phydev->speed = SPEED_100;
164 /* Force the switch to start */
165 ksz8895_write_smireg(phydev, 1, 1);
170 static int ksz8895_startup(struct phy_device *phydev)
175 static struct phy_driver ksz8895_driver = {
176 .name = "Micrel KSZ8895/KSZ8864",
179 .features = PHY_BASIC_FEATURES,
180 .config = &ksz8895_config,
181 .startup = &ksz8895_startup,
182 .shutdown = &genphy_shutdown,
185 /* Micrel used the exact same model number for the KSZ9021,
186 * so the revision number is used to distinguish them.
188 static struct phy_driver KS8721_driver = {
189 .name = "Micrel KS8721BL",
192 .features = PHY_BASIC_FEATURES,
193 .config = &genphy_config,
194 .startup = &genphy_startup,
195 .shutdown = &genphy_shutdown,
198 int ksz886x_config(struct phy_device *phydev)
200 /* we are connected directly to the switch without
203 phydev->duplex = DUPLEX_FULL;
204 phydev->speed = SPEED_100;
208 static int ksz886x_startup(struct phy_device *phydev)
213 static struct phy_driver ksz886x_driver = {
214 .name = "Micrel KSZ886x Switch",
217 .features = PHY_BASIC_FEATURES,
218 .config = &ksz886x_config,
219 .startup = &ksz886x_startup,
220 .shutdown = &genphy_shutdown,
223 int phy_micrel_ksz8xxx_init(void)
225 phy_register(&KSZ804_driver);
226 phy_register(&KSZ8031_driver);
227 phy_register(&KSZ8051_driver);
228 phy_register(&KSZ8061_driver);
229 phy_register(&KSZ8081_driver);
230 phy_register(&KS8721_driver);
231 phy_register(&ksz8895_driver);
232 phy_register(&ksz886x_driver);