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 | * RealTek PHY drivers |
| 4 | * |
Codrin Ciubotariu | de947a1 | 2015-02-13 14:47:58 +0200 | [diff] [blame] | 5 | * Copyright 2010-2011, 2015 Freescale Semiconductor, Inc. |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 6 | * author Andy Fleming |
Karsten Merker | 10800de | 2016-03-21 20:29:07 +0100 | [diff] [blame] | 7 | * Copyright 2016 Karsten Merker <merker@debian.org> |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 8 | */ |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 9 | #include <common.h> |
oliver@schinagl.nl | ec1b26f | 2016-11-08 17:38:57 +0100 | [diff] [blame] | 10 | #include <linux/bitops.h> |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 11 | #include <phy.h> |
| 12 | |
oliver@schinagl.nl | 6a25090 | 2016-11-08 17:38:59 +0100 | [diff] [blame] | 13 | #define PHY_RTL8211x_FORCE_MASTER BIT(1) |
kevans@FreeBSD.org | 7c82401 | 2018-02-14 17:02:15 -0600 | [diff] [blame] | 14 | #define PHY_RTL8211E_PINE64_GIGABIT_FIX BIT(2) |
oliver@schinagl.nl | 6a25090 | 2016-11-08 17:38:59 +0100 | [diff] [blame] | 15 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 16 | #define PHY_AUTONEGOTIATE_TIMEOUT 5000 |
| 17 | |
Michael Haas | 0cf2b4e | 2016-03-25 18:22:50 +0100 | [diff] [blame] | 18 | /* RTL8211x 1000BASE-T Control Register */ |
oliver@schinagl.nl | ec1b26f | 2016-11-08 17:38:57 +0100 | [diff] [blame] | 19 | #define MIIM_RTL8211x_CTRL1000T_MSCE BIT(12); |
oliver@schinagl.nl | 1beb735 | 2016-11-08 17:38:58 +0100 | [diff] [blame] | 20 | #define MIIM_RTL8211x_CTRL1000T_MASTER BIT(11); |
Michael Haas | 0cf2b4e | 2016-03-25 18:22:50 +0100 | [diff] [blame] | 21 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 22 | /* RTL8211x PHY Status Register */ |
| 23 | #define MIIM_RTL8211x_PHY_STATUS 0x11 |
| 24 | #define MIIM_RTL8211x_PHYSTAT_SPEED 0xc000 |
| 25 | #define MIIM_RTL8211x_PHYSTAT_GBIT 0x8000 |
| 26 | #define MIIM_RTL8211x_PHYSTAT_100 0x4000 |
| 27 | #define MIIM_RTL8211x_PHYSTAT_DUPLEX 0x2000 |
| 28 | #define MIIM_RTL8211x_PHYSTAT_SPDDONE 0x0800 |
| 29 | #define MIIM_RTL8211x_PHYSTAT_LINK 0x0400 |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 30 | |
Codrin Ciubotariu | de947a1 | 2015-02-13 14:47:58 +0200 | [diff] [blame] | 31 | /* RTL8211x PHY Interrupt Enable Register */ |
| 32 | #define MIIM_RTL8211x_PHY_INER 0x12 |
| 33 | #define MIIM_RTL8211x_PHY_INTR_ENA 0x9f01 |
| 34 | #define MIIM_RTL8211x_PHY_INTR_DIS 0x0000 |
| 35 | |
| 36 | /* RTL8211x PHY Interrupt Status Register */ |
| 37 | #define MIIM_RTL8211x_PHY_INSR 0x13 |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 38 | |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 39 | /* RTL8211F PHY Status Register */ |
| 40 | #define MIIM_RTL8211F_PHY_STATUS 0x1a |
| 41 | #define MIIM_RTL8211F_AUTONEG_ENABLE 0x1000 |
| 42 | #define MIIM_RTL8211F_PHYSTAT_SPEED 0x0030 |
| 43 | #define MIIM_RTL8211F_PHYSTAT_GBIT 0x0020 |
| 44 | #define MIIM_RTL8211F_PHYSTAT_100 0x0010 |
| 45 | #define MIIM_RTL8211F_PHYSTAT_DUPLEX 0x0008 |
| 46 | #define MIIM_RTL8211F_PHYSTAT_SPDDONE 0x0800 |
| 47 | #define MIIM_RTL8211F_PHYSTAT_LINK 0x0004 |
| 48 | |
kevans@FreeBSD.org | 7c82401 | 2018-02-14 17:02:15 -0600 | [diff] [blame] | 49 | #define MIIM_RTL8211E_CONFREG 0x1c |
| 50 | #define MIIM_RTL8211E_CONFREG_TXD 0x0002 |
| 51 | #define MIIM_RTL8211E_CONFREG_RXD 0x0004 |
| 52 | #define MIIM_RTL8211E_CONFREG_MAGIC 0xb400 /* Undocumented */ |
| 53 | |
| 54 | #define MIIM_RTL8211E_EXT_PAGE_SELECT 0x1e |
| 55 | |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 56 | #define MIIM_RTL8211F_PAGE_SELECT 0x1f |
Shengzhou Liu | 6750089 | 2015-04-24 16:57:17 +0800 | [diff] [blame] | 57 | #define MIIM_RTL8211F_TX_DELAY 0x100 |
Shengzhou Liu | 5487fc6 | 2015-05-21 18:07:35 +0800 | [diff] [blame] | 58 | #define MIIM_RTL8211F_LCR 0x10 |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 59 | |
Carlo Caione | b8d167e | 2019-01-16 11:34:50 +0000 | [diff] [blame] | 60 | static int rtl8211f_phy_extread(struct phy_device *phydev, int addr, |
| 61 | int devaddr, int regnum) |
| 62 | { |
| 63 | int oldpage = phy_read(phydev, MDIO_DEVAD_NONE, |
| 64 | MIIM_RTL8211F_PAGE_SELECT); |
| 65 | int val; |
| 66 | |
| 67 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT, devaddr); |
| 68 | val = phy_read(phydev, MDIO_DEVAD_NONE, regnum); |
| 69 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT, oldpage); |
| 70 | |
| 71 | return val; |
| 72 | } |
| 73 | |
| 74 | static int rtl8211f_phy_extwrite(struct phy_device *phydev, int addr, |
| 75 | int devaddr, int regnum, u16 val) |
| 76 | { |
| 77 | int oldpage = phy_read(phydev, MDIO_DEVAD_NONE, |
| 78 | MIIM_RTL8211F_PAGE_SELECT); |
| 79 | |
| 80 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT, devaddr); |
| 81 | phy_write(phydev, MDIO_DEVAD_NONE, regnum, val); |
| 82 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT, oldpage); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
oliver@schinagl.nl | 6a25090 | 2016-11-08 17:38:59 +0100 | [diff] [blame] | 87 | static int rtl8211b_probe(struct phy_device *phydev) |
| 88 | { |
| 89 | #ifdef CONFIG_RTL8211X_PHY_FORCE_MASTER |
| 90 | phydev->flags |= PHY_RTL8211x_FORCE_MASTER; |
| 91 | #endif |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
kevans@FreeBSD.org | 7c82401 | 2018-02-14 17:02:15 -0600 | [diff] [blame] | 96 | static int rtl8211e_probe(struct phy_device *phydev) |
| 97 | { |
| 98 | #ifdef CONFIG_RTL8211E_PINE64_GIGABIT_FIX |
| 99 | phydev->flags |= PHY_RTL8211E_PINE64_GIGABIT_FIX; |
| 100 | #endif |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 105 | /* RealTek RTL8211x */ |
| 106 | static int rtl8211x_config(struct phy_device *phydev) |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 107 | { |
| 108 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET); |
| 109 | |
Codrin Ciubotariu | de947a1 | 2015-02-13 14:47:58 +0200 | [diff] [blame] | 110 | /* mask interrupt at init; if the interrupt is |
| 111 | * needed indeed, it should be explicitly enabled |
| 112 | */ |
| 113 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211x_PHY_INER, |
| 114 | MIIM_RTL8211x_PHY_INTR_DIS); |
oliver@schinagl.nl | 6a25090 | 2016-11-08 17:38:59 +0100 | [diff] [blame] | 115 | |
| 116 | if (phydev->flags & PHY_RTL8211x_FORCE_MASTER) { |
| 117 | unsigned int reg; |
| 118 | |
| 119 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000); |
| 120 | /* force manual master/slave configuration */ |
| 121 | reg |= MIIM_RTL8211x_CTRL1000T_MSCE; |
| 122 | /* force master mode */ |
| 123 | reg |= MIIM_RTL8211x_CTRL1000T_MASTER; |
| 124 | phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, reg); |
| 125 | } |
kevans@FreeBSD.org | 7c82401 | 2018-02-14 17:02:15 -0600 | [diff] [blame] | 126 | if (phydev->flags & PHY_RTL8211E_PINE64_GIGABIT_FIX) { |
| 127 | unsigned int reg; |
| 128 | |
| 129 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT, |
| 130 | 7); |
| 131 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 132 | MIIM_RTL8211E_EXT_PAGE_SELECT, 0xa4); |
| 133 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211E_CONFREG); |
| 134 | /* Ensure both internal delays are turned off */ |
| 135 | reg &= ~(MIIM_RTL8211E_CONFREG_TXD | MIIM_RTL8211E_CONFREG_RXD); |
| 136 | /* Flip the magic undocumented bits */ |
| 137 | reg |= MIIM_RTL8211E_CONFREG_MAGIC; |
| 138 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211E_CONFREG, reg); |
| 139 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT, |
| 140 | 0); |
| 141 | } |
Codrin Ciubotariu | de947a1 | 2015-02-13 14:47:58 +0200 | [diff] [blame] | 142 | /* read interrupt status just to clear it */ |
| 143 | phy_read(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211x_PHY_INER); |
| 144 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 145 | genphy_config_aneg(phydev); |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
Shengzhou Liu | 6750089 | 2015-04-24 16:57:17 +0800 | [diff] [blame] | 150 | static int rtl8211f_config(struct phy_device *phydev) |
| 151 | { |
| 152 | u16 reg; |
| 153 | |
| 154 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET); |
| 155 | |
Madalin Bucur | 83ba7aa | 2017-08-18 11:35:24 +0300 | [diff] [blame] | 156 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 157 | MIIM_RTL8211F_PAGE_SELECT, 0xd08); |
| 158 | reg = phy_read(phydev, MDIO_DEVAD_NONE, 0x11); |
| 159 | |
| 160 | /* enable TX-delay for rgmii-id and rgmii-txid, otherwise disable it */ |
| 161 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
| 162 | phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
Shengzhou Liu | 6750089 | 2015-04-24 16:57:17 +0800 | [diff] [blame] | 163 | reg |= MIIM_RTL8211F_TX_DELAY; |
Madalin Bucur | 83ba7aa | 2017-08-18 11:35:24 +0300 | [diff] [blame] | 164 | else |
| 165 | reg &= ~MIIM_RTL8211F_TX_DELAY; |
| 166 | |
| 167 | phy_write(phydev, MDIO_DEVAD_NONE, 0x11, reg); |
| 168 | /* restore to default page 0 */ |
| 169 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 170 | MIIM_RTL8211F_PAGE_SELECT, 0x0); |
Shengzhou Liu | 6750089 | 2015-04-24 16:57:17 +0800 | [diff] [blame] | 171 | |
Shengzhou Liu | 5487fc6 | 2015-05-21 18:07:35 +0800 | [diff] [blame] | 172 | /* Set green LED for Link, yellow LED for Active */ |
| 173 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 174 | MIIM_RTL8211F_PAGE_SELECT, 0xd04); |
| 175 | phy_write(phydev, MDIO_DEVAD_NONE, 0x10, 0x617f); |
| 176 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 177 | MIIM_RTL8211F_PAGE_SELECT, 0x0); |
| 178 | |
Shengzhou Liu | 6750089 | 2015-04-24 16:57:17 +0800 | [diff] [blame] | 179 | genphy_config_aneg(phydev); |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 184 | static int rtl8211x_parse_status(struct phy_device *phydev) |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 185 | { |
| 186 | unsigned int speed; |
| 187 | unsigned int mii_reg; |
| 188 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 189 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211x_PHY_STATUS); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 190 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 191 | if (!(mii_reg & MIIM_RTL8211x_PHYSTAT_SPDDONE)) { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 192 | int i = 0; |
| 193 | |
| 194 | /* in case of timeout ->link is cleared */ |
| 195 | phydev->link = 1; |
| 196 | puts("Waiting for PHY realtime link"); |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 197 | while (!(mii_reg & MIIM_RTL8211x_PHYSTAT_SPDDONE)) { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 198 | /* Timeout reached ? */ |
| 199 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
| 200 | puts(" TIMEOUT !\n"); |
| 201 | phydev->link = 0; |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | if ((i++ % 1000) == 0) |
| 206 | putc('.'); |
| 207 | udelay(1000); /* 1 ms */ |
| 208 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 209 | MIIM_RTL8211x_PHY_STATUS); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 210 | } |
| 211 | puts(" done\n"); |
| 212 | udelay(500000); /* another 500 ms (results in faster booting) */ |
| 213 | } else { |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 214 | if (mii_reg & MIIM_RTL8211x_PHYSTAT_LINK) |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 215 | phydev->link = 1; |
| 216 | else |
| 217 | phydev->link = 0; |
| 218 | } |
| 219 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 220 | if (mii_reg & MIIM_RTL8211x_PHYSTAT_DUPLEX) |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 221 | phydev->duplex = DUPLEX_FULL; |
| 222 | else |
| 223 | phydev->duplex = DUPLEX_HALF; |
| 224 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 225 | speed = (mii_reg & MIIM_RTL8211x_PHYSTAT_SPEED); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 226 | |
| 227 | switch (speed) { |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 228 | case MIIM_RTL8211x_PHYSTAT_GBIT: |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 229 | phydev->speed = SPEED_1000; |
| 230 | break; |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 231 | case MIIM_RTL8211x_PHYSTAT_100: |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 232 | phydev->speed = SPEED_100; |
| 233 | break; |
| 234 | default: |
| 235 | phydev->speed = SPEED_10; |
| 236 | } |
| 237 | |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static int rtl8211f_parse_status(struct phy_device *phydev) |
| 242 | { |
| 243 | unsigned int speed; |
| 244 | unsigned int mii_reg; |
| 245 | int i = 0; |
| 246 | |
| 247 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PAGE_SELECT, 0xa43); |
| 248 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_RTL8211F_PHY_STATUS); |
| 249 | |
| 250 | phydev->link = 1; |
| 251 | while (!(mii_reg & MIIM_RTL8211F_PHYSTAT_LINK)) { |
| 252 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
| 253 | puts(" TIMEOUT !\n"); |
| 254 | phydev->link = 0; |
| 255 | break; |
| 256 | } |
| 257 | |
| 258 | if ((i++ % 1000) == 0) |
| 259 | putc('.'); |
| 260 | udelay(1000); |
| 261 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, |
| 262 | MIIM_RTL8211F_PHY_STATUS); |
| 263 | } |
| 264 | |
| 265 | if (mii_reg & MIIM_RTL8211F_PHYSTAT_DUPLEX) |
| 266 | phydev->duplex = DUPLEX_FULL; |
| 267 | else |
| 268 | phydev->duplex = DUPLEX_HALF; |
| 269 | |
| 270 | speed = (mii_reg & MIIM_RTL8211F_PHYSTAT_SPEED); |
| 271 | |
| 272 | switch (speed) { |
| 273 | case MIIM_RTL8211F_PHYSTAT_GBIT: |
| 274 | phydev->speed = SPEED_1000; |
| 275 | break; |
| 276 | case MIIM_RTL8211F_PHYSTAT_100: |
| 277 | phydev->speed = SPEED_100; |
| 278 | break; |
| 279 | default: |
| 280 | phydev->speed = SPEED_10; |
| 281 | } |
| 282 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 283 | return 0; |
| 284 | } |
| 285 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 286 | static int rtl8211x_startup(struct phy_device *phydev) |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 287 | { |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 288 | int ret; |
| 289 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 290 | /* Read the Status (2x to make sure link is right) */ |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 291 | ret = genphy_update_link(phydev); |
| 292 | if (ret) |
| 293 | return ret; |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 294 | |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 295 | return rtl8211x_parse_status(phydev); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 296 | } |
| 297 | |
Michal Simek | bdf0b72 | 2016-02-13 10:31:32 +0100 | [diff] [blame] | 298 | static int rtl8211e_startup(struct phy_device *phydev) |
| 299 | { |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 300 | int ret; |
| 301 | |
| 302 | ret = genphy_update_link(phydev); |
| 303 | if (ret) |
| 304 | return ret; |
Michal Simek | bdf0b72 | 2016-02-13 10:31:32 +0100 | [diff] [blame] | 305 | |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 306 | return genphy_parse_link(phydev); |
Michal Simek | bdf0b72 | 2016-02-13 10:31:32 +0100 | [diff] [blame] | 307 | } |
| 308 | |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 309 | static int rtl8211f_startup(struct phy_device *phydev) |
| 310 | { |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 311 | int ret; |
| 312 | |
| 313 | /* Read the Status (2x to make sure link is right) */ |
| 314 | ret = genphy_update_link(phydev); |
| 315 | if (ret) |
| 316 | return ret; |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 317 | /* Read the Status (2x to make sure link is right) */ |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 318 | |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 319 | return rtl8211f_parse_status(phydev); |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 320 | } |
| 321 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 322 | /* Support for RTL8211B PHY */ |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 323 | static struct phy_driver RTL8211B_driver = { |
| 324 | .name = "RealTek RTL8211B", |
Karsten Merker | 10800de | 2016-03-21 20:29:07 +0100 | [diff] [blame] | 325 | .uid = 0x1cc912, |
Bhupesh Sharma | ad4cd95 | 2013-09-01 04:40:52 +0530 | [diff] [blame] | 326 | .mask = 0xffffff, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 327 | .features = PHY_GBIT_FEATURES, |
oliver@schinagl.nl | 6a25090 | 2016-11-08 17:38:59 +0100 | [diff] [blame] | 328 | .probe = &rtl8211b_probe, |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 329 | .config = &rtl8211x_config, |
| 330 | .startup = &rtl8211x_startup, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 331 | .shutdown = &genphy_shutdown, |
| 332 | }; |
| 333 | |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 334 | /* Support for RTL8211E-VB-CG, RTL8211E-VL-CG and RTL8211EG-VB-CG PHYs */ |
| 335 | static struct phy_driver RTL8211E_driver = { |
| 336 | .name = "RealTek RTL8211E", |
| 337 | .uid = 0x1cc915, |
Bhupesh Sharma | ad4cd95 | 2013-09-01 04:40:52 +0530 | [diff] [blame] | 338 | .mask = 0xffffff, |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 339 | .features = PHY_GBIT_FEATURES, |
kevans@FreeBSD.org | 7c82401 | 2018-02-14 17:02:15 -0600 | [diff] [blame] | 340 | .probe = &rtl8211e_probe, |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 341 | .config = &rtl8211x_config, |
Michal Simek | bdf0b72 | 2016-02-13 10:31:32 +0100 | [diff] [blame] | 342 | .startup = &rtl8211e_startup, |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 343 | .shutdown = &genphy_shutdown, |
| 344 | }; |
| 345 | |
| 346 | /* Support for RTL8211DN PHY */ |
| 347 | static struct phy_driver RTL8211DN_driver = { |
| 348 | .name = "RealTek RTL8211DN", |
| 349 | .uid = 0x1cc914, |
Bhupesh Sharma | ad4cd95 | 2013-09-01 04:40:52 +0530 | [diff] [blame] | 350 | .mask = 0xffffff, |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 351 | .features = PHY_GBIT_FEATURES, |
| 352 | .config = &rtl8211x_config, |
| 353 | .startup = &rtl8211x_startup, |
| 354 | .shutdown = &genphy_shutdown, |
| 355 | }; |
| 356 | |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 357 | /* Support for RTL8211F PHY */ |
| 358 | static struct phy_driver RTL8211F_driver = { |
| 359 | .name = "RealTek RTL8211F", |
| 360 | .uid = 0x1cc916, |
| 361 | .mask = 0xffffff, |
| 362 | .features = PHY_GBIT_FEATURES, |
Shengzhou Liu | 6750089 | 2015-04-24 16:57:17 +0800 | [diff] [blame] | 363 | .config = &rtl8211f_config, |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 364 | .startup = &rtl8211f_startup, |
| 365 | .shutdown = &genphy_shutdown, |
Carlo Caione | b8d167e | 2019-01-16 11:34:50 +0000 | [diff] [blame] | 366 | .readext = &rtl8211f_phy_extread, |
| 367 | .writeext = &rtl8211f_phy_extwrite, |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 368 | }; |
| 369 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 370 | int phy_realtek_init(void) |
| 371 | { |
| 372 | phy_register(&RTL8211B_driver); |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 373 | phy_register(&RTL8211E_driver); |
Shengzhou Liu | 210f17f | 2015-03-12 18:54:59 +0800 | [diff] [blame] | 374 | phy_register(&RTL8211F_driver); |
Bhupesh Sharma | 85eb780 | 2013-07-18 13:58:20 +0530 | [diff] [blame] | 375 | phy_register(&RTL8211DN_driver); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 376 | |
| 377 | return 0; |
| 378 | } |