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 | * Marvell 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 |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 7 | */ |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | b3d61dd | 2016-07-05 17:10:12 -0600 | [diff] [blame] | 9 | #include <errno.h> |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 10 | #include <marvell_phy.h> |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 11 | #include <phy.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 14 | |
| 15 | #define PHY_AUTONEGOTIATE_TIMEOUT 5000 |
| 16 | |
Phil Edworthy | 19d03be | 2017-05-24 14:43:06 +0100 | [diff] [blame] | 17 | #define MII_MARVELL_PHY_PAGE 22 |
| 18 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 19 | /* 88E1011 PHY Status Register */ |
| 20 | #define MIIM_88E1xxx_PHY_STATUS 0x11 |
| 21 | #define MIIM_88E1xxx_PHYSTAT_SPEED 0xc000 |
| 22 | #define MIIM_88E1xxx_PHYSTAT_GBIT 0x8000 |
| 23 | #define MIIM_88E1xxx_PHYSTAT_100 0x4000 |
| 24 | #define MIIM_88E1xxx_PHYSTAT_DUPLEX 0x2000 |
| 25 | #define MIIM_88E1xxx_PHYSTAT_SPDDONE 0x0800 |
| 26 | #define MIIM_88E1xxx_PHYSTAT_LINK 0x0400 |
| 27 | |
| 28 | #define MIIM_88E1xxx_PHY_SCR 0x10 |
| 29 | #define MIIM_88E1xxx_PHY_MDI_X_AUTO 0x0060 |
| 30 | |
| 31 | /* 88E1111 PHY LED Control Register */ |
| 32 | #define MIIM_88E1111_PHY_LED_CONTROL 24 |
| 33 | #define MIIM_88E1111_PHY_LED_DIRECT 0x4100 |
| 34 | #define MIIM_88E1111_PHY_LED_COMBINE 0x411C |
| 35 | |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 36 | /* 88E1111 Extended PHY Specific Control Register */ |
| 37 | #define MIIM_88E1111_PHY_EXT_CR 0x14 |
| 38 | #define MIIM_88E1111_RX_DELAY 0x80 |
| 39 | #define MIIM_88E1111_TX_DELAY 0x2 |
| 40 | |
| 41 | /* 88E1111 Extended PHY Specific Status Register */ |
| 42 | #define MIIM_88E1111_PHY_EXT_SR 0x1b |
| 43 | #define MIIM_88E1111_HWCFG_MODE_MASK 0xf |
| 44 | #define MIIM_88E1111_HWCFG_MODE_COPPER_RGMII 0xb |
| 45 | #define MIIM_88E1111_HWCFG_MODE_FIBER_RGMII 0x3 |
| 46 | #define MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK 0x4 |
| 47 | #define MIIM_88E1111_HWCFG_MODE_COPPER_RTBI 0x9 |
| 48 | #define MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO 0x8000 |
| 49 | #define MIIM_88E1111_HWCFG_FIBER_COPPER_RES 0x2000 |
| 50 | |
| 51 | #define MIIM_88E1111_COPPER 0 |
| 52 | #define MIIM_88E1111_FIBER 1 |
| 53 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 54 | /* 88E1118 PHY defines */ |
| 55 | #define MIIM_88E1118_PHY_PAGE 22 |
| 56 | #define MIIM_88E1118_PHY_LED_PAGE 3 |
| 57 | |
| 58 | /* 88E1121 PHY LED Control Register */ |
| 59 | #define MIIM_88E1121_PHY_LED_CTRL 16 |
| 60 | #define MIIM_88E1121_PHY_LED_PAGE 3 |
| 61 | #define MIIM_88E1121_PHY_LED_DEF 0x0030 |
| 62 | |
| 63 | /* 88E1121 PHY IRQ Enable/Status Register */ |
| 64 | #define MIIM_88E1121_PHY_IRQ_EN 18 |
| 65 | #define MIIM_88E1121_PHY_IRQ_STATUS 19 |
| 66 | |
| 67 | #define MIIM_88E1121_PHY_PAGE 22 |
| 68 | |
| 69 | /* 88E1145 Extended PHY Specific Control Register */ |
| 70 | #define MIIM_88E1145_PHY_EXT_CR 20 |
| 71 | #define MIIM_M88E1145_RGMII_RX_DELAY 0x0080 |
| 72 | #define MIIM_M88E1145_RGMII_TX_DELAY 0x0002 |
| 73 | |
| 74 | #define MIIM_88E1145_PHY_LED_CONTROL 24 |
| 75 | #define MIIM_88E1145_PHY_LED_DIRECT 0x4100 |
| 76 | |
| 77 | #define MIIM_88E1145_PHY_PAGE 29 |
| 78 | #define MIIM_88E1145_PHY_CAL_OV 30 |
| 79 | |
| 80 | #define MIIM_88E1149_PHY_PAGE 29 |
| 81 | |
Sebastian Hesselbarth | 1b3352f | 2012-12-04 09:31:59 +0100 | [diff] [blame] | 82 | /* 88E1310 PHY defines */ |
| 83 | #define MIIM_88E1310_PHY_LED_CTRL 16 |
| 84 | #define MIIM_88E1310_PHY_IRQ_EN 18 |
| 85 | #define MIIM_88E1310_PHY_RGMII_CTRL 21 |
| 86 | #define MIIM_88E1310_PHY_PAGE 22 |
| 87 | |
Joe Hershberger | 27a8e03 | 2016-12-09 11:54:39 -0600 | [diff] [blame] | 88 | /* 88E151x PHY defines */ |
Phil Edworthy | 19d03be | 2017-05-24 14:43:06 +0100 | [diff] [blame] | 89 | /* Page 2 registers */ |
| 90 | #define MIIM_88E151x_PHY_MSCR 21 |
| 91 | #define MIIM_88E151x_RGMII_RX_DELAY BIT(5) |
| 92 | #define MIIM_88E151x_RGMII_TX_DELAY BIT(4) |
| 93 | #define MIIM_88E151x_RGMII_RXTX_DELAY (BIT(5) | BIT(4)) |
Joe Hershberger | 27a8e03 | 2016-12-09 11:54:39 -0600 | [diff] [blame] | 94 | /* Page 3 registers */ |
| 95 | #define MIIM_88E151x_LED_FUNC_CTRL 16 |
| 96 | #define MIIM_88E151x_LED_FLD_SZ 4 |
| 97 | #define MIIM_88E151x_LED0_OFFS (0 * MIIM_88E151x_LED_FLD_SZ) |
| 98 | #define MIIM_88E151x_LED1_OFFS (1 * MIIM_88E151x_LED_FLD_SZ) |
| 99 | #define MIIM_88E151x_LED0_ACT 3 |
| 100 | #define MIIM_88E151x_LED1_100_1000_LINK 6 |
| 101 | #define MIIM_88E151x_LED_TIMER_CTRL 18 |
| 102 | #define MIIM_88E151x_INT_EN_OFFS 7 |
| 103 | /* Page 18 registers */ |
| 104 | #define MIIM_88E151x_GENERAL_CTRL 20 |
| 105 | #define MIIM_88E151x_MODE_SGMII 1 |
| 106 | #define MIIM_88E151x_RESET_OFFS 15 |
| 107 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 108 | static int marvell_read_page(struct phy_device *phydev) |
| 109 | { |
| 110 | return phy_read(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE); |
| 111 | } |
| 112 | |
| 113 | static int marvell_write_page(struct phy_device *phydev, int page) |
| 114 | { |
| 115 | return phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, page); |
| 116 | } |
| 117 | |
| 118 | /* Set and/or override some configuration registers based on the |
| 119 | * marvell,reg-init property stored in the of_node for the phydev. |
| 120 | * |
| 121 | * marvell,reg-init = <reg-page reg mask value>,...; |
| 122 | * |
| 123 | * There may be one or more sets of <reg-page reg mask value>: |
| 124 | * |
| 125 | * reg-page: which register bank to use. |
| 126 | * reg: the register. |
| 127 | * mask: if non-zero, ANDed with existing register value. |
| 128 | * value: ORed with the masked value and written to the regiser. |
| 129 | * |
| 130 | */ |
| 131 | static int marvell_of_reg_init(struct phy_device *phydev) |
| 132 | { |
| 133 | const __be32 *prop; |
| 134 | int len, i, saved_page, current_page, ret = 0; |
| 135 | |
| 136 | if (!ofnode_valid(phydev->node)) |
| 137 | return 0; |
| 138 | |
| 139 | prop = ofnode_get_property(phydev->node, "marvell,reg-init", &len); |
| 140 | if (!prop) |
| 141 | return 0; |
| 142 | |
| 143 | saved_page = marvell_read_page(phydev); |
| 144 | if (saved_page < 0) |
| 145 | goto err; |
| 146 | current_page = saved_page; |
| 147 | |
| 148 | len /= sizeof(*prop); |
| 149 | for (i = 0; i < len - 3; i += 4) { |
| 150 | u16 page = be32_to_cpup(prop + i); |
| 151 | u16 reg = be32_to_cpup(prop + i + 1); |
| 152 | u16 mask = be32_to_cpup(prop + i + 2); |
| 153 | u16 val_bits = be32_to_cpup(prop + i + 3); |
| 154 | int val; |
| 155 | |
| 156 | if (page != current_page) { |
| 157 | current_page = page; |
| 158 | ret = marvell_write_page(phydev, page); |
| 159 | if (ret < 0) |
| 160 | goto err; |
| 161 | } |
| 162 | |
| 163 | val = 0; |
| 164 | if (mask) { |
| 165 | val = phy_read(phydev, MDIO_DEVAD_NONE, reg); |
| 166 | if (val < 0) { |
| 167 | ret = val; |
| 168 | goto err; |
| 169 | } |
| 170 | val &= mask; |
| 171 | } |
| 172 | val |= val_bits; |
| 173 | |
| 174 | ret = phy_write(phydev, MDIO_DEVAD_NONE, reg, val); |
| 175 | if (ret < 0) |
| 176 | goto err; |
| 177 | } |
| 178 | |
| 179 | err: |
| 180 | return marvell_write_page(phydev, saved_page); |
| 181 | } |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 182 | |
Lukasz Majewski | 3857a16 | 2017-10-30 22:57:53 +0100 | [diff] [blame] | 183 | static int m88e1xxx_phy_extread(struct phy_device *phydev, int addr, |
| 184 | int devaddr, int regnum) |
| 185 | { |
| 186 | int oldpage = phy_read(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE); |
| 187 | int val; |
| 188 | |
| 189 | phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, devaddr); |
| 190 | val = phy_read(phydev, MDIO_DEVAD_NONE, regnum); |
| 191 | phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, oldpage); |
| 192 | |
| 193 | return val; |
| 194 | } |
| 195 | |
| 196 | static int m88e1xxx_phy_extwrite(struct phy_device *phydev, int addr, |
| 197 | int devaddr, int regnum, u16 val) |
| 198 | { |
| 199 | int oldpage = phy_read(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE); |
| 200 | |
| 201 | phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, devaddr); |
| 202 | phy_write(phydev, MDIO_DEVAD_NONE, regnum, val); |
| 203 | phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, oldpage); |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 208 | /* Marvell 88E1011S */ |
| 209 | static int m88e1011s_config(struct phy_device *phydev) |
| 210 | { |
| 211 | /* Reset and configure the PHY */ |
| 212 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET); |
| 213 | |
| 214 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f); |
| 215 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x200c); |
| 216 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5); |
| 217 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0); |
| 218 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100); |
| 219 | |
| 220 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET); |
| 221 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 222 | marvell_of_reg_init(phydev); |
| 223 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 224 | genphy_config_aneg(phydev); |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /* Parse the 88E1011's status register for speed and duplex |
| 230 | * information |
| 231 | */ |
Michal Simek | cf6677b | 2016-05-18 12:48:57 +0200 | [diff] [blame] | 232 | static int m88e1xxx_parse_status(struct phy_device *phydev) |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 233 | { |
| 234 | unsigned int speed; |
| 235 | unsigned int mii_reg; |
| 236 | |
| 237 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_STATUS); |
| 238 | |
| 239 | if ((mii_reg & MIIM_88E1xxx_PHYSTAT_LINK) && |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 240 | !(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 241 | int i = 0; |
| 242 | |
| 243 | puts("Waiting for PHY realtime link"); |
| 244 | while (!(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) { |
| 245 | /* Timeout reached ? */ |
| 246 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
| 247 | puts(" TIMEOUT !\n"); |
| 248 | phydev->link = 0; |
Michal Simek | cf6677b | 2016-05-18 12:48:57 +0200 | [diff] [blame] | 249 | return -ETIMEDOUT; |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | if ((i++ % 1000) == 0) |
| 253 | putc('.'); |
| 254 | udelay(1000); |
| 255 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 256 | MIIM_88E1xxx_PHY_STATUS); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 257 | } |
| 258 | puts(" done\n"); |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 259 | mdelay(500); /* another 500 ms (results in faster booting) */ |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 260 | } else { |
| 261 | if (mii_reg & MIIM_88E1xxx_PHYSTAT_LINK) |
| 262 | phydev->link = 1; |
| 263 | else |
| 264 | phydev->link = 0; |
| 265 | } |
| 266 | |
| 267 | if (mii_reg & MIIM_88E1xxx_PHYSTAT_DUPLEX) |
| 268 | phydev->duplex = DUPLEX_FULL; |
| 269 | else |
| 270 | phydev->duplex = DUPLEX_HALF; |
| 271 | |
| 272 | speed = mii_reg & MIIM_88E1xxx_PHYSTAT_SPEED; |
| 273 | |
| 274 | switch (speed) { |
| 275 | case MIIM_88E1xxx_PHYSTAT_GBIT: |
| 276 | phydev->speed = SPEED_1000; |
| 277 | break; |
| 278 | case MIIM_88E1xxx_PHYSTAT_100: |
| 279 | phydev->speed = SPEED_100; |
| 280 | break; |
| 281 | default: |
| 282 | phydev->speed = SPEED_10; |
| 283 | break; |
| 284 | } |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int m88e1011s_startup(struct phy_device *phydev) |
| 290 | { |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 291 | int ret; |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 292 | |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 293 | ret = genphy_update_link(phydev); |
| 294 | if (ret) |
| 295 | return ret; |
| 296 | |
| 297 | return m88e1xxx_parse_status(phydev); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* Marvell 88E1111S */ |
| 301 | static int m88e1111s_config(struct phy_device *phydev) |
| 302 | { |
| 303 | int reg; |
| 304 | |
Phil Edworthy | e4c26ee | 2016-12-12 12:54:15 +0000 | [diff] [blame] | 305 | if (phy_interface_is_rgmii(phydev)) { |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 306 | reg = phy_read(phydev, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 307 | MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 308 | if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) || |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 309 | (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) { |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 310 | reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY); |
| 311 | } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { |
| 312 | reg &= ~MIIM_88E1111_TX_DELAY; |
| 313 | reg |= MIIM_88E1111_RX_DELAY; |
| 314 | } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { |
| 315 | reg &= ~MIIM_88E1111_RX_DELAY; |
| 316 | reg |= MIIM_88E1111_TX_DELAY; |
| 317 | } |
| 318 | |
| 319 | phy_write(phydev, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 320 | MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 321 | |
| 322 | reg = phy_read(phydev, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 323 | MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 324 | |
| 325 | reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK); |
| 326 | |
| 327 | if (reg & MIIM_88E1111_HWCFG_FIBER_COPPER_RES) |
| 328 | reg |= MIIM_88E1111_HWCFG_MODE_FIBER_RGMII; |
| 329 | else |
| 330 | reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RGMII; |
| 331 | |
| 332 | phy_write(phydev, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 333 | MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR, reg); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
| 337 | reg = phy_read(phydev, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 338 | MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 339 | |
| 340 | reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK); |
| 341 | reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK; |
| 342 | reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO; |
| 343 | |
| 344 | phy_write(phydev, MDIO_DEVAD_NONE, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 345 | MIIM_88E1111_PHY_EXT_SR, reg); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | if (phydev->interface == PHY_INTERFACE_MODE_RTBI) { |
| 349 | reg = phy_read(phydev, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 350 | MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 351 | reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY); |
| 352 | phy_write(phydev, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 353 | MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 354 | |
| 355 | reg = phy_read(phydev, MDIO_DEVAD_NONE, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 356 | MIIM_88E1111_PHY_EXT_SR); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 357 | reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK | |
| 358 | MIIM_88E1111_HWCFG_FIBER_COPPER_RES); |
| 359 | reg |= 0x7 | MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO; |
| 360 | phy_write(phydev, MDIO_DEVAD_NONE, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 361 | MIIM_88E1111_PHY_EXT_SR, reg); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 362 | |
| 363 | /* soft reset */ |
Stefan Roese | d1b5282 | 2016-02-10 07:06:05 +0100 | [diff] [blame] | 364 | phy_reset(phydev); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 365 | |
| 366 | reg = phy_read(phydev, MDIO_DEVAD_NONE, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 367 | MIIM_88E1111_PHY_EXT_SR); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 368 | reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK | |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 369 | MIIM_88E1111_HWCFG_FIBER_COPPER_RES); |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 370 | reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RTBI | |
| 371 | MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO; |
| 372 | phy_write(phydev, MDIO_DEVAD_NONE, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 373 | MIIM_88E1111_PHY_EXT_SR, reg); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 374 | } |
| 375 | |
Zang Roy-R61911 | 20ffbf3 | 2011-10-27 18:52:09 +0000 | [diff] [blame] | 376 | /* soft reset */ |
Stefan Roese | d1b5282 | 2016-02-10 07:06:05 +0100 | [diff] [blame] | 377 | phy_reset(phydev); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 378 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 379 | marvell_of_reg_init(phydev); |
| 380 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 381 | genphy_config_aneg(phydev); |
Stefan Roese | eb06f02 | 2016-02-10 07:06:06 +0100 | [diff] [blame] | 382 | genphy_restart_aneg(phydev); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 387 | /** |
Clemens Gruber | 4eb793e | 2020-02-24 20:52:20 +0100 | [diff] [blame] | 388 | * m88e151x_phy_writebits - write bits to a register |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 389 | */ |
Clemens Gruber | 4eb793e | 2020-02-24 20:52:20 +0100 | [diff] [blame] | 390 | void m88e151x_phy_writebits(struct phy_device *phydev, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 391 | u8 reg_num, u16 offset, u16 len, u16 data) |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 392 | { |
| 393 | u16 reg, mask; |
| 394 | |
| 395 | if ((len + offset) >= 16) |
| 396 | mask = 0 - (1 << offset); |
| 397 | else |
| 398 | mask = (1 << (len + offset)) - (1 << offset); |
| 399 | |
| 400 | reg = phy_read(phydev, MDIO_DEVAD_NONE, reg_num); |
| 401 | |
| 402 | reg &= ~mask; |
| 403 | reg |= data << offset; |
| 404 | |
| 405 | phy_write(phydev, MDIO_DEVAD_NONE, reg_num, reg); |
| 406 | } |
| 407 | |
Clemens Gruber | 4eb793e | 2020-02-24 20:52:20 +0100 | [diff] [blame] | 408 | static int m88e151x_config(struct phy_device *phydev) |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 409 | { |
Phil Edworthy | 19d03be | 2017-05-24 14:43:06 +0100 | [diff] [blame] | 410 | u16 reg; |
| 411 | |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 412 | /* |
| 413 | * As per Marvell Release Notes - Alaska 88E1510/88E1518/88E1512 |
| 414 | * /88E1514 Rev A0, Errata Section 3.1 |
| 415 | */ |
Clemens Gruber | f10d89c | 2015-06-06 14:44:57 +0200 | [diff] [blame] | 416 | |
| 417 | /* EEE initialization */ |
Joe Hershberger | 27a8e03 | 2016-12-09 11:54:39 -0600 | [diff] [blame] | 418 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00ff); |
Clemens Gruber | f10d89c | 2015-06-06 14:44:57 +0200 | [diff] [blame] | 419 | phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x214B); |
| 420 | phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2144); |
| 421 | phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x0C28); |
| 422 | phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2146); |
| 423 | phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xB233); |
| 424 | phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x214D); |
| 425 | phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xCC0C); |
| 426 | phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2159); |
Joe Hershberger | 27a8e03 | 2016-12-09 11:54:39 -0600 | [diff] [blame] | 427 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000); |
Clemens Gruber | f10d89c | 2015-06-06 14:44:57 +0200 | [diff] [blame] | 428 | |
| 429 | /* SGMII-to-Copper mode initialization */ |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 430 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
Clemens Gruber | f10d89c | 2015-06-06 14:44:57 +0200 | [diff] [blame] | 431 | /* Select page 18 */ |
Joe Hershberger | 27a8e03 | 2016-12-09 11:54:39 -0600 | [diff] [blame] | 432 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 18); |
Clemens Gruber | f10d89c | 2015-06-06 14:44:57 +0200 | [diff] [blame] | 433 | |
| 434 | /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */ |
Clemens Gruber | 4eb793e | 2020-02-24 20:52:20 +0100 | [diff] [blame] | 435 | m88e151x_phy_writebits(phydev, MIIM_88E151x_GENERAL_CTRL, |
Joe Hershberger | 27a8e03 | 2016-12-09 11:54:39 -0600 | [diff] [blame] | 436 | 0, 3, MIIM_88E151x_MODE_SGMII); |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 437 | |
Clemens Gruber | f10d89c | 2015-06-06 14:44:57 +0200 | [diff] [blame] | 438 | /* PHY reset is necessary after changing MODE[2:0] */ |
Clemens Gruber | 4eb793e | 2020-02-24 20:52:20 +0100 | [diff] [blame] | 439 | m88e151x_phy_writebits(phydev, MIIM_88E151x_GENERAL_CTRL, |
Joe Hershberger | 27a8e03 | 2016-12-09 11:54:39 -0600 | [diff] [blame] | 440 | MIIM_88E151x_RESET_OFFS, 1, 1); |
Clemens Gruber | f10d89c | 2015-06-06 14:44:57 +0200 | [diff] [blame] | 441 | |
| 442 | /* Reset page selection */ |
Joe Hershberger | 27a8e03 | 2016-12-09 11:54:39 -0600 | [diff] [blame] | 443 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0); |
Clemens Gruber | f10d89c | 2015-06-06 14:44:57 +0200 | [diff] [blame] | 444 | |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 445 | udelay(100); |
| 446 | } |
| 447 | |
Phil Edworthy | 19d03be | 2017-05-24 14:43:06 +0100 | [diff] [blame] | 448 | if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { |
| 449 | reg = phy_read(phydev, MDIO_DEVAD_NONE, |
| 450 | MIIM_88E1111_PHY_EXT_SR); |
| 451 | |
| 452 | reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK); |
| 453 | reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK; |
| 454 | reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO; |
| 455 | |
| 456 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 457 | MIIM_88E1111_PHY_EXT_SR, reg); |
| 458 | } |
| 459 | |
| 460 | if (phy_interface_is_rgmii(phydev)) { |
| 461 | phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, 2); |
| 462 | |
| 463 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR); |
| 464 | reg &= ~MIIM_88E151x_RGMII_RXTX_DELAY; |
Mario Six | c1de131 | 2018-01-15 11:08:25 +0100 | [diff] [blame] | 465 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII || |
| 466 | phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
Phil Edworthy | 19d03be | 2017-05-24 14:43:06 +0100 | [diff] [blame] | 467 | reg |= MIIM_88E151x_RGMII_RXTX_DELAY; |
| 468 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 469 | reg |= MIIM_88E151x_RGMII_RX_DELAY; |
| 470 | else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 471 | reg |= MIIM_88E151x_RGMII_TX_DELAY; |
| 472 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR, reg); |
| 473 | |
| 474 | phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, 0); |
| 475 | } |
| 476 | |
| 477 | /* soft reset */ |
| 478 | phy_reset(phydev); |
| 479 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 480 | marvell_of_reg_init(phydev); |
| 481 | |
Phil Edworthy | 19d03be | 2017-05-24 14:43:06 +0100 | [diff] [blame] | 482 | genphy_config_aneg(phydev); |
| 483 | genphy_restart_aneg(phydev); |
| 484 | |
| 485 | return 0; |
Hao Zhang | f0c53a4 | 2014-10-30 18:59:43 +0200 | [diff] [blame] | 486 | } |
| 487 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 488 | /* Marvell 88E1118 */ |
| 489 | static int m88e1118_config(struct phy_device *phydev) |
| 490 | { |
| 491 | /* Change Page Number */ |
| 492 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0002); |
| 493 | /* Delay RGMII TX and RX */ |
| 494 | phy_write(phydev, MDIO_DEVAD_NONE, 0x15, 0x1070); |
| 495 | /* Change Page Number */ |
| 496 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0003); |
| 497 | /* Adjust LED control */ |
| 498 | phy_write(phydev, MDIO_DEVAD_NONE, 0x10, 0x021e); |
| 499 | /* Change Page Number */ |
| 500 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000); |
| 501 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 502 | marvell_of_reg_init(phydev); |
| 503 | |
Michal Simek | 0b56710 | 2016-05-18 14:46:28 +0200 | [diff] [blame] | 504 | return genphy_config_aneg(phydev); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static int m88e1118_startup(struct phy_device *phydev) |
| 508 | { |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 509 | int ret; |
| 510 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 511 | /* Change Page Number */ |
| 512 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000); |
| 513 | |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 514 | ret = genphy_update_link(phydev); |
| 515 | if (ret) |
| 516 | return ret; |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 517 | |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 518 | return m88e1xxx_parse_status(phydev); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /* Marvell 88E1121R */ |
| 522 | static int m88e1121_config(struct phy_device *phydev) |
| 523 | { |
| 524 | int pg; |
| 525 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 526 | marvell_of_reg_init(phydev); |
| 527 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 528 | /* Configure the PHY */ |
| 529 | genphy_config_aneg(phydev); |
| 530 | |
| 531 | /* Switch the page to access the led register */ |
| 532 | pg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE); |
| 533 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 534 | MIIM_88E1121_PHY_LED_PAGE); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 535 | /* Configure leds */ |
| 536 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_LED_CTRL, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 537 | MIIM_88E1121_PHY_LED_DEF); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 538 | /* Restore the page pointer */ |
| 539 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE, pg); |
| 540 | |
| 541 | /* Disable IRQs and de-assert interrupt */ |
| 542 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_IRQ_EN, 0); |
| 543 | phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_IRQ_STATUS); |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | /* Marvell 88E1145 */ |
| 549 | static int m88e1145_config(struct phy_device *phydev) |
| 550 | { |
| 551 | int reg; |
| 552 | |
| 553 | /* Errata E0, E1 */ |
| 554 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_PAGE, 0x001b); |
| 555 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0x418f); |
| 556 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_PAGE, 0x0016); |
| 557 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0xa2da); |
| 558 | |
| 559 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_SCR, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 560 | MIIM_88E1xxx_PHY_MDI_X_AUTO); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 561 | |
| 562 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR); |
| 563 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 564 | reg |= MIIM_M88E1145_RGMII_RX_DELAY | |
| 565 | MIIM_M88E1145_RGMII_TX_DELAY; |
| 566 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR, reg); |
| 567 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 568 | marvell_of_reg_init(phydev); |
| 569 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 570 | genphy_config_aneg(phydev); |
| 571 | |
York Sun | bf94cfb | 2017-06-06 09:22:40 -0700 | [diff] [blame] | 572 | /* soft reset */ |
| 573 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR); |
| 574 | reg |= BMCR_RESET; |
| 575 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, reg); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | static int m88e1145_startup(struct phy_device *phydev) |
| 581 | { |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 582 | int ret; |
| 583 | |
| 584 | ret = genphy_update_link(phydev); |
| 585 | if (ret) |
| 586 | return ret; |
| 587 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 588 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_LED_CONTROL, |
Mario Six | 618d42b | 2018-01-15 11:08:24 +0100 | [diff] [blame] | 589 | MIIM_88E1145_PHY_LED_DIRECT); |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 590 | return m88e1xxx_parse_status(phydev); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /* Marvell 88E1149S */ |
| 594 | static int m88e1149_config(struct phy_device *phydev) |
| 595 | { |
| 596 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1149_PHY_PAGE, 0x1f); |
| 597 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x200c); |
| 598 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1149_PHY_PAGE, 0x5); |
| 599 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x0); |
| 600 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100); |
| 601 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 602 | marvell_of_reg_init(phydev); |
| 603 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 604 | genphy_config_aneg(phydev); |
| 605 | |
| 606 | phy_reset(phydev); |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
Stefan Roese | 09d5f76 | 2022-03-31 11:43:07 +0200 | [diff] [blame] | 611 | /* Marvell 88E1240 */ |
| 612 | static int m88e1240_config(struct phy_device *phydev) |
| 613 | { |
| 614 | marvell_of_reg_init(phydev); |
| 615 | |
| 616 | genphy_config_aneg(phydev); |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
Sebastian Hesselbarth | 1b3352f | 2012-12-04 09:31:59 +0100 | [diff] [blame] | 621 | /* Marvell 88E1310 */ |
| 622 | static int m88e1310_config(struct phy_device *phydev) |
| 623 | { |
| 624 | u16 reg; |
| 625 | |
| 626 | /* LED link and activity */ |
| 627 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0003); |
| 628 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_LED_CTRL); |
| 629 | reg = (reg & ~0xf) | 0x1; |
| 630 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_LED_CTRL, reg); |
| 631 | |
| 632 | /* Set LED2/INT to INT mode, low active */ |
| 633 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0003); |
| 634 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_IRQ_EN); |
| 635 | reg = (reg & 0x77ff) | 0x0880; |
| 636 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_IRQ_EN, reg); |
| 637 | |
| 638 | /* Set RGMII delay */ |
| 639 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0002); |
| 640 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_RGMII_CTRL); |
| 641 | reg |= 0x0030; |
| 642 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_RGMII_CTRL, reg); |
| 643 | |
| 644 | /* Ensure to return to page 0 */ |
| 645 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0000); |
| 646 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 647 | marvell_of_reg_init(phydev); |
| 648 | |
Nathan Rossi | fcdcc55 | 2016-06-03 23:16:17 +1000 | [diff] [blame] | 649 | return genphy_config_aneg(phydev); |
Sebastian Hesselbarth | 1b3352f | 2012-12-04 09:31:59 +0100 | [diff] [blame] | 650 | } |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 651 | |
Dirk Eibach | 4f96f3f | 2017-01-11 16:00:46 +0100 | [diff] [blame] | 652 | static int m88e1680_config(struct phy_device *phydev) |
| 653 | { |
| 654 | /* |
| 655 | * As per Marvell Release Notes - Alaska V 88E1680 Rev A2 |
| 656 | * Errata Section 4.1 |
| 657 | */ |
| 658 | u16 reg; |
| 659 | int res; |
| 660 | |
| 661 | /* Matrix LED mode (not neede if single LED mode is used */ |
| 662 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0004); |
| 663 | reg = phy_read(phydev, MDIO_DEVAD_NONE, 27); |
| 664 | reg |= (1 << 5); |
| 665 | phy_write(phydev, MDIO_DEVAD_NONE, 27, reg); |
| 666 | |
| 667 | /* QSGMII TX amplitude change */ |
| 668 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00fd); |
| 669 | phy_write(phydev, MDIO_DEVAD_NONE, 8, 0x0b53); |
| 670 | phy_write(phydev, MDIO_DEVAD_NONE, 7, 0x200d); |
| 671 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000); |
| 672 | |
| 673 | /* EEE initialization */ |
| 674 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00ff); |
| 675 | phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xb030); |
| 676 | phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x215c); |
| 677 | phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x00fc); |
| 678 | phy_write(phydev, MDIO_DEVAD_NONE, 24, 0x888c); |
| 679 | phy_write(phydev, MDIO_DEVAD_NONE, 25, 0x888c); |
| 680 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000); |
| 681 | phy_write(phydev, MDIO_DEVAD_NONE, 0, 0x9140); |
| 682 | |
Stefan Roese | 2ae0fc2 | 2022-03-31 11:43:06 +0200 | [diff] [blame] | 683 | marvell_of_reg_init(phydev); |
| 684 | |
Dirk Eibach | 4f96f3f | 2017-01-11 16:00:46 +0100 | [diff] [blame] | 685 | res = genphy_config_aneg(phydev); |
| 686 | if (res < 0) |
| 687 | return res; |
| 688 | |
| 689 | /* soft reset */ |
| 690 | reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR); |
| 691 | reg |= BMCR_RESET; |
| 692 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, reg); |
| 693 | |
| 694 | return 0; |
| 695 | } |
| 696 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 697 | U_BOOT_PHY_DRIVER(m88e1011s) = { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 698 | .name = "Marvell 88E1011S", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 699 | .uid = MARVELL_PHY_ID_88E1101, |
| 700 | .mask = MARVELL_PHY_ID_MASK, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 701 | .features = PHY_GBIT_FEATURES, |
| 702 | .config = &m88e1011s_config, |
| 703 | .startup = &m88e1011s_startup, |
| 704 | .shutdown = &genphy_shutdown, |
| 705 | }; |
| 706 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 707 | U_BOOT_PHY_DRIVER(m88e1111s) = { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 708 | .name = "Marvell 88E1111S", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 709 | .uid = MARVELL_PHY_ID_88E1111, |
| 710 | .mask = MARVELL_PHY_ID_MASK, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 711 | .features = PHY_GBIT_FEATURES, |
| 712 | .config = &m88e1111s_config, |
| 713 | .startup = &m88e1011s_startup, |
| 714 | .shutdown = &genphy_shutdown, |
| 715 | }; |
| 716 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 717 | U_BOOT_PHY_DRIVER(m88e1118) = { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 718 | .name = "Marvell 88E1118", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 719 | .uid = MARVELL_PHY_ID_88E1118, |
| 720 | .mask = MARVELL_PHY_ID_MASK, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 721 | .features = PHY_GBIT_FEATURES, |
| 722 | .config = &m88e1118_config, |
| 723 | .startup = &m88e1118_startup, |
| 724 | .shutdown = &genphy_shutdown, |
| 725 | }; |
| 726 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 727 | U_BOOT_PHY_DRIVER(m88e1118r) = { |
Michal Simek | 130aa52 | 2012-08-07 02:23:07 +0000 | [diff] [blame] | 728 | .name = "Marvell 88E1118R", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 729 | .uid = MARVELL_PHY_ID_88E1116R, |
| 730 | .mask = MARVELL_PHY_ID_MASK, |
Michal Simek | 130aa52 | 2012-08-07 02:23:07 +0000 | [diff] [blame] | 731 | .features = PHY_GBIT_FEATURES, |
| 732 | .config = &m88e1118_config, |
| 733 | .startup = &m88e1118_startup, |
| 734 | .shutdown = &genphy_shutdown, |
| 735 | }; |
| 736 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 737 | U_BOOT_PHY_DRIVER(m88e1121r) = { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 738 | .name = "Marvell 88E1121R", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 739 | .uid = MARVELL_PHY_ID_88E1121R, |
| 740 | .mask = MARVELL_PHY_ID_MASK, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 741 | .features = PHY_GBIT_FEATURES, |
| 742 | .config = &m88e1121_config, |
| 743 | .startup = &genphy_startup, |
| 744 | .shutdown = &genphy_shutdown, |
| 745 | }; |
| 746 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 747 | U_BOOT_PHY_DRIVER(m88e1145) = { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 748 | .name = "Marvell 88E1145", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 749 | .uid = MARVELL_PHY_ID_88E1145, |
| 750 | .mask = MARVELL_PHY_ID_MASK, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 751 | .features = PHY_GBIT_FEATURES, |
| 752 | .config = &m88e1145_config, |
| 753 | .startup = &m88e1145_startup, |
| 754 | .shutdown = &genphy_shutdown, |
| 755 | }; |
| 756 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 757 | U_BOOT_PHY_DRIVER(m88e1149s) = { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 758 | .name = "Marvell 88E1149S", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 759 | .uid = 0x01410ca0, |
| 760 | .mask = MARVELL_PHY_ID_MASK, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 761 | .features = PHY_GBIT_FEATURES, |
| 762 | .config = &m88e1149_config, |
| 763 | .startup = &m88e1011s_startup, |
| 764 | .shutdown = &genphy_shutdown, |
| 765 | }; |
| 766 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 767 | U_BOOT_PHY_DRIVER(m88e1240) = { |
Stefan Roese | 09d5f76 | 2022-03-31 11:43:07 +0200 | [diff] [blame] | 768 | .name = "Marvell 88E1240", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 769 | .uid = MARVELL_PHY_ID_88E1240, |
| 770 | .mask = MARVELL_PHY_ID_MASK, |
Stefan Roese | 09d5f76 | 2022-03-31 11:43:07 +0200 | [diff] [blame] | 771 | .features = PHY_GBIT_FEATURES, |
| 772 | .config = &m88e1240_config, |
| 773 | .startup = &m88e1011s_startup, |
| 774 | .shutdown = &genphy_shutdown, |
| 775 | }; |
| 776 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 777 | U_BOOT_PHY_DRIVER(m88e151x) = { |
Clemens Gruber | 4eb793e | 2020-02-24 20:52:20 +0100 | [diff] [blame] | 778 | .name = "Marvell 88E151x", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 779 | .uid = MARVELL_PHY_ID_88E1510, |
| 780 | .mask = MARVELL_PHY_ID_MASK, |
Michal Simek | 4d74cf1 | 2012-10-15 14:03:00 +0200 | [diff] [blame] | 781 | .features = PHY_GBIT_FEATURES, |
Clemens Gruber | 4eb793e | 2020-02-24 20:52:20 +0100 | [diff] [blame] | 782 | .config = &m88e151x_config, |
Michal Simek | 4d74cf1 | 2012-10-15 14:03:00 +0200 | [diff] [blame] | 783 | .startup = &m88e1011s_startup, |
| 784 | .shutdown = &genphy_shutdown, |
Lukasz Majewski | 3857a16 | 2017-10-30 22:57:53 +0100 | [diff] [blame] | 785 | .readext = &m88e1xxx_phy_extread, |
| 786 | .writeext = &m88e1xxx_phy_extwrite, |
Michal Simek | 4d74cf1 | 2012-10-15 14:03:00 +0200 | [diff] [blame] | 787 | }; |
| 788 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 789 | U_BOOT_PHY_DRIVER(m88e1310) = { |
Sebastian Hesselbarth | 1b3352f | 2012-12-04 09:31:59 +0100 | [diff] [blame] | 790 | .name = "Marvell 88E1310", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 791 | .uid = MARVELL_PHY_ID_88E1318S, |
| 792 | .mask = MARVELL_PHY_ID_MASK, |
Sebastian Hesselbarth | 1b3352f | 2012-12-04 09:31:59 +0100 | [diff] [blame] | 793 | .features = PHY_GBIT_FEATURES, |
| 794 | .config = &m88e1310_config, |
| 795 | .startup = &m88e1011s_startup, |
| 796 | .shutdown = &genphy_shutdown, |
| 797 | }; |
| 798 | |
Marek Vasut | 5859efa | 2023-03-19 18:02:54 +0100 | [diff] [blame] | 799 | U_BOOT_PHY_DRIVER(m88e1680) = { |
Dirk Eibach | 4f96f3f | 2017-01-11 16:00:46 +0100 | [diff] [blame] | 800 | .name = "Marvell 88E1680", |
Marek Vasut | f7c5c23 | 2023-03-19 18:08:06 +0100 | [diff] [blame] | 801 | .uid = 0x01410ed0, |
| 802 | .mask = MARVELL_PHY_ID_MASK, |
Dirk Eibach | 4f96f3f | 2017-01-11 16:00:46 +0100 | [diff] [blame] | 803 | .features = PHY_GBIT_FEATURES, |
| 804 | .config = &m88e1680_config, |
| 805 | .startup = &genphy_startup, |
| 806 | .shutdown = &genphy_shutdown, |
| 807 | }; |