Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Micrel PHY drivers |
| 4 | * |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 5 | * Copyright 2010-2011 Freescale Semiconductor, Inc. |
| 6 | * author Andy Fleming |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 7 | * (C) 2012 NetModule AG, David Andrey, added KSZ9031 |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 8 | */ |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 9 | #include <common.h> |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <errno.h> |
| 12 | #include <fdtdec.h> |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 13 | #include <micrel.h> |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 14 | #include <phy.h> |
| 15 | |
| 16 | static struct phy_driver KSZ804_driver = { |
| 17 | .name = "Micrel KSZ804", |
| 18 | .uid = 0x221510, |
| 19 | .mask = 0xfffff0, |
| 20 | .features = PHY_BASIC_FEATURES, |
| 21 | .config = &genphy_config, |
| 22 | .startup = &genphy_startup, |
| 23 | .shutdown = &genphy_shutdown, |
| 24 | }; |
| 25 | |
Alexandre Messier | 94bde10 | 2016-01-22 14:06:33 -0500 | [diff] [blame] | 26 | #define MII_KSZPHY_OMSO 0x16 |
Nicolas Ferre | 45d262d | 2019-10-23 10:46:44 +0000 | [diff] [blame] | 27 | #define KSZPHY_OMSO_FACTORY_TEST BIT(15) |
Alexandre Messier | 94bde10 | 2016-01-22 14:06:33 -0500 | [diff] [blame] | 28 | #define KSZPHY_OMSO_B_CAST_OFF (1 << 9) |
| 29 | |
| 30 | static int ksz_genconfig_bcastoff(struct phy_device *phydev) |
| 31 | { |
| 32 | int ret; |
| 33 | |
| 34 | ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO); |
| 35 | if (ret < 0) |
| 36 | return ret; |
| 37 | |
| 38 | ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO, |
| 39 | ret | KSZPHY_OMSO_B_CAST_OFF); |
| 40 | if (ret < 0) |
| 41 | return ret; |
| 42 | |
| 43 | return genphy_config(phydev); |
| 44 | } |
| 45 | |
Sylvain Lemieux | bd8d300 | 2015-09-09 16:29:51 -0400 | [diff] [blame] | 46 | static struct phy_driver KSZ8031_driver = { |
| 47 | .name = "Micrel KSZ8021/KSZ8031", |
| 48 | .uid = 0x221550, |
| 49 | .mask = 0xfffff0, |
| 50 | .features = PHY_BASIC_FEATURES, |
Alexandre Messier | 94bde10 | 2016-01-22 14:06:33 -0500 | [diff] [blame] | 51 | .config = &ksz_genconfig_bcastoff, |
Sylvain Lemieux | bd8d300 | 2015-09-09 16:29:51 -0400 | [diff] [blame] | 52 | .startup = &genphy_startup, |
| 53 | .shutdown = &genphy_shutdown, |
| 54 | }; |
| 55 | |
Sylvain Rochet | 23e9d5c | 2015-10-07 22:54:22 +0200 | [diff] [blame] | 56 | /** |
| 57 | * KSZ8051 |
| 58 | */ |
| 59 | #define MII_KSZ8051_PHY_OMSO 0x16 |
| 60 | #define MII_KSZ8051_PHY_OMSO_NAND_TREE_ON (1 << 5) |
| 61 | |
| 62 | static int ksz8051_config(struct phy_device *phydev) |
| 63 | { |
| 64 | unsigned val; |
| 65 | |
| 66 | /* Disable NAND-tree */ |
| 67 | val = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO); |
| 68 | val &= ~MII_KSZ8051_PHY_OMSO_NAND_TREE_ON; |
| 69 | phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO, val); |
| 70 | |
| 71 | return genphy_config(phydev); |
| 72 | } |
| 73 | |
| 74 | static struct phy_driver KSZ8051_driver = { |
| 75 | .name = "Micrel KSZ8051", |
| 76 | .uid = 0x221550, |
| 77 | .mask = 0xfffff0, |
| 78 | .features = PHY_BASIC_FEATURES, |
| 79 | .config = &ksz8051_config, |
| 80 | .startup = &genphy_startup, |
| 81 | .shutdown = &genphy_shutdown, |
| 82 | }; |
| 83 | |
Nicolas Ferre | 45d262d | 2019-10-23 10:46:44 +0000 | [diff] [blame] | 84 | static int ksz8081_config(struct phy_device *phydev) |
| 85 | { |
| 86 | int ret; |
| 87 | |
| 88 | ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO); |
| 89 | if (ret < 0) |
| 90 | return ret; |
| 91 | |
| 92 | ret &= ~KSZPHY_OMSO_FACTORY_TEST; |
| 93 | |
| 94 | ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO, |
| 95 | ret | KSZPHY_OMSO_B_CAST_OFF); |
| 96 | if (ret < 0) |
| 97 | return ret; |
| 98 | |
| 99 | return genphy_config(phydev); |
| 100 | } |
| 101 | |
Luca Ellero | adeb9ea | 2015-03-24 11:32:24 +0100 | [diff] [blame] | 102 | static struct phy_driver KSZ8081_driver = { |
| 103 | .name = "Micrel KSZ8081", |
| 104 | .uid = 0x221560, |
| 105 | .mask = 0xfffff0, |
| 106 | .features = PHY_BASIC_FEATURES, |
Nicolas Ferre | 45d262d | 2019-10-23 10:46:44 +0000 | [diff] [blame] | 107 | .config = &ksz8081_config, |
Luca Ellero | adeb9ea | 2015-03-24 11:32:24 +0100 | [diff] [blame] | 108 | .startup = &genphy_startup, |
| 109 | .shutdown = &genphy_shutdown, |
| 110 | }; |
| 111 | |
Philippe De Muyter | 2616b21 | 2014-02-19 17:21:59 +0100 | [diff] [blame] | 112 | /** |
| 113 | * KSZ8895 |
| 114 | */ |
| 115 | |
| 116 | static unsigned short smireg_to_phy(unsigned short reg) |
| 117 | { |
| 118 | return ((reg & 0xc0) >> 3) + 0x06 + ((reg & 0x20) >> 5); |
| 119 | } |
| 120 | |
| 121 | static unsigned short smireg_to_reg(unsigned short reg) |
| 122 | { |
| 123 | return reg & 0x1F; |
| 124 | } |
| 125 | |
| 126 | static void ksz8895_write_smireg(struct phy_device *phydev, int smireg, int val) |
| 127 | { |
| 128 | phydev->bus->write(phydev->bus, smireg_to_phy(smireg), MDIO_DEVAD_NONE, |
| 129 | smireg_to_reg(smireg), val); |
| 130 | } |
| 131 | |
| 132 | #if 0 |
| 133 | static int ksz8895_read_smireg(struct phy_device *phydev, int smireg) |
| 134 | { |
| 135 | return phydev->bus->read(phydev->bus, smireg_to_phy(smireg), |
| 136 | MDIO_DEVAD_NONE, smireg_to_reg(smireg)); |
| 137 | } |
| 138 | #endif |
| 139 | |
| 140 | int ksz8895_config(struct phy_device *phydev) |
| 141 | { |
| 142 | /* we are connected directly to the switch without |
| 143 | * dedicated PHY. SCONF1 == 001 */ |
| 144 | phydev->link = 1; |
| 145 | phydev->duplex = DUPLEX_FULL; |
| 146 | phydev->speed = SPEED_100; |
| 147 | |
| 148 | /* Force the switch to start */ |
| 149 | ksz8895_write_smireg(phydev, 1, 1); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static int ksz8895_startup(struct phy_device *phydev) |
| 155 | { |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static struct phy_driver ksz8895_driver = { |
| 160 | .name = "Micrel KSZ8895/KSZ8864", |
| 161 | .uid = 0x221450, |
| 162 | .mask = 0xffffe1, |
| 163 | .features = PHY_BASIC_FEATURES, |
| 164 | .config = &ksz8895_config, |
| 165 | .startup = &ksz8895_startup, |
| 166 | .shutdown = &genphy_shutdown, |
| 167 | }; |
| 168 | |
James Byrne | bc292c2 | 2019-03-06 12:48:27 +0000 | [diff] [blame] | 169 | /* Micrel used the exact same model number for the KSZ9021, |
| 170 | * so the revision number is used to distinguish them. |
| 171 | */ |
Vladimir Zapolskiy | a4baa58 | 2011-12-06 02:47:57 +0000 | [diff] [blame] | 172 | static struct phy_driver KS8721_driver = { |
| 173 | .name = "Micrel KS8721BL", |
James Byrne | bc292c2 | 2019-03-06 12:48:27 +0000 | [diff] [blame] | 174 | .uid = 0x221618, |
| 175 | .mask = 0xfffffc, |
Vladimir Zapolskiy | a4baa58 | 2011-12-06 02:47:57 +0000 | [diff] [blame] | 176 | .features = PHY_BASIC_FEATURES, |
| 177 | .config = &genphy_config, |
| 178 | .startup = &genphy_startup, |
| 179 | .shutdown = &genphy_shutdown, |
| 180 | }; |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 181 | |
Alexey Firago | 73823fa | 2016-05-26 16:28:44 +0300 | [diff] [blame] | 182 | int ksz886x_config(struct phy_device *phydev) |
| 183 | { |
| 184 | /* we are connected directly to the switch without |
| 185 | * dedicated PHY. */ |
| 186 | phydev->link = 1; |
| 187 | phydev->duplex = DUPLEX_FULL; |
| 188 | phydev->speed = SPEED_100; |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | static int ksz886x_startup(struct phy_device *phydev) |
| 193 | { |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static struct phy_driver ksz886x_driver = { |
| 198 | .name = "Micrel KSZ886x Switch", |
| 199 | .uid = 0x00221430, |
| 200 | .mask = 0xfffff0, |
| 201 | .features = PHY_BASIC_FEATURES, |
| 202 | .config = &ksz886x_config, |
| 203 | .startup = &ksz886x_startup, |
| 204 | .shutdown = &genphy_shutdown, |
| 205 | }; |
| 206 | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 207 | int phy_micrel_ksz8xxx_init(void) |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 208 | { |
| 209 | phy_register(&KSZ804_driver); |
Sylvain Lemieux | bd8d300 | 2015-09-09 16:29:51 -0400 | [diff] [blame] | 210 | phy_register(&KSZ8031_driver); |
Sylvain Rochet | 23e9d5c | 2015-10-07 22:54:22 +0200 | [diff] [blame] | 211 | phy_register(&KSZ8051_driver); |
Luca Ellero | adeb9ea | 2015-03-24 11:32:24 +0100 | [diff] [blame] | 212 | phy_register(&KSZ8081_driver); |
Troy Kisky | b4fd97f | 2012-06-28 08:00:28 +0000 | [diff] [blame] | 213 | phy_register(&KS8721_driver); |
Philippe De Muyter | 2616b21 | 2014-02-19 17:21:59 +0100 | [diff] [blame] | 214 | phy_register(&ksz8895_driver); |
Alexey Firago | 73823fa | 2016-05-26 16:28:44 +0300 | [diff] [blame] | 215 | phy_register(&ksz886x_driver); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 216 | return 0; |
| 217 | } |