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 |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 8 | * (C) Copyright 2017 Adaptrum, Inc. |
| 9 | * Written by Alexandru Gagniuc <alex.g@adaptrum.com> for Adaptrum, Inc. |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 10 | */ |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 11 | #include <common.h> |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 12 | #include <dm.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 13 | #include <env.h> |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 14 | #include <errno.h> |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 15 | #include <micrel.h> |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 16 | #include <phy.h> |
| 17 | |
Pavel Machek | 5f02211 | 2014-09-09 14:26:51 +0200 | [diff] [blame] | 18 | /* |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 19 | * KSZ9021 - KSZ9031 common |
| 20 | */ |
| 21 | |
| 22 | #define MII_KSZ90xx_PHY_CTL 0x1f |
| 23 | #define MIIM_KSZ90xx_PHYCTL_1000 (1 << 6) |
| 24 | #define MIIM_KSZ90xx_PHYCTL_100 (1 << 5) |
| 25 | #define MIIM_KSZ90xx_PHYCTL_10 (1 << 4) |
| 26 | #define MIIM_KSZ90xx_PHYCTL_DUPLEX (1 << 3) |
| 27 | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 28 | /* KSZ9021 PHY Registers */ |
| 29 | #define MII_KSZ9021_EXTENDED_CTRL 0x0b |
| 30 | #define MII_KSZ9021_EXTENDED_DATAW 0x0c |
| 31 | #define MII_KSZ9021_EXTENDED_DATAR 0x0d |
| 32 | |
| 33 | #define CTRL1000_PREFER_MASTER (1 << 10) |
| 34 | #define CTRL1000_CONFIG_MASTER (1 << 11) |
| 35 | #define CTRL1000_MANUAL_CONFIG (1 << 12) |
| 36 | |
James Byrne | 457107f | 2019-03-04 17:40:33 +0000 | [diff] [blame] | 37 | #define KSZ9021_PS_TO_REG 120 |
| 38 | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 39 | /* KSZ9031 PHY Registers */ |
| 40 | #define MII_KSZ9031_MMD_ACCES_CTRL 0x0d |
| 41 | #define MII_KSZ9031_MMD_REG_DATA 0x0e |
| 42 | |
James Byrne | 457107f | 2019-03-04 17:40:33 +0000 | [diff] [blame] | 43 | #define KSZ9031_PS_TO_REG 60 |
| 44 | |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 45 | static int ksz90xx_startup(struct phy_device *phydev) |
| 46 | { |
| 47 | unsigned phy_ctl; |
Michal Simek | 5ff8966 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 48 | int ret; |
| 49 | |
| 50 | ret = genphy_update_link(phydev); |
| 51 | if (ret) |
| 52 | return ret; |
| 53 | |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 54 | phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ90xx_PHY_CTL); |
| 55 | |
| 56 | if (phy_ctl & MIIM_KSZ90xx_PHYCTL_DUPLEX) |
| 57 | phydev->duplex = DUPLEX_FULL; |
| 58 | else |
| 59 | phydev->duplex = DUPLEX_HALF; |
| 60 | |
| 61 | if (phy_ctl & MIIM_KSZ90xx_PHYCTL_1000) |
| 62 | phydev->speed = SPEED_1000; |
| 63 | else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_100) |
| 64 | phydev->speed = SPEED_100; |
| 65 | else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_10) |
| 66 | phydev->speed = SPEED_10; |
| 67 | return 0; |
| 68 | } |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 69 | |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 70 | /* Common OF config bits for KSZ9021 and KSZ9031 */ |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 71 | #ifdef CONFIG_DM_ETH |
| 72 | struct ksz90x1_reg_field { |
| 73 | const char *name; |
| 74 | const u8 size; /* Size of the bitfield, in bits */ |
| 75 | const u8 off; /* Offset from bit 0 */ |
| 76 | const u8 dflt; /* Default value */ |
| 77 | }; |
| 78 | |
| 79 | struct ksz90x1_ofcfg { |
| 80 | const u16 reg; |
| 81 | const u16 devad; |
| 82 | const struct ksz90x1_reg_field *grp; |
| 83 | const u16 grpsz; |
| 84 | }; |
| 85 | |
| 86 | static const struct ksz90x1_reg_field ksz90x1_rxd_grp[] = { |
| 87 | { "rxd0-skew-ps", 4, 0, 0x7 }, { "rxd1-skew-ps", 4, 4, 0x7 }, |
| 88 | { "rxd2-skew-ps", 4, 8, 0x7 }, { "rxd3-skew-ps", 4, 12, 0x7 } |
| 89 | }; |
| 90 | |
| 91 | static const struct ksz90x1_reg_field ksz90x1_txd_grp[] = { |
| 92 | { "txd0-skew-ps", 4, 0, 0x7 }, { "txd1-skew-ps", 4, 4, 0x7 }, |
| 93 | { "txd2-skew-ps", 4, 8, 0x7 }, { "txd3-skew-ps", 4, 12, 0x7 }, |
| 94 | }; |
| 95 | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 96 | static const struct ksz90x1_reg_field ksz9021_clk_grp[] = { |
| 97 | { "txen-skew-ps", 4, 0, 0x7 }, { "txc-skew-ps", 4, 4, 0x7 }, |
| 98 | { "rxdv-skew-ps", 4, 8, 0x7 }, { "rxc-skew-ps", 4, 12, 0x7 }, |
| 99 | }; |
| 100 | |
| 101 | static const struct ksz90x1_reg_field ksz9031_ctl_grp[] = { |
| 102 | { "txen-skew-ps", 4, 0, 0x7 }, { "rxdv-skew-ps", 4, 4, 0x7 } |
| 103 | }; |
| 104 | |
| 105 | static const struct ksz90x1_reg_field ksz9031_clk_grp[] = { |
| 106 | { "rxc-skew-ps", 5, 0, 0xf }, { "txc-skew-ps", 5, 5, 0xf } |
| 107 | }; |
| 108 | |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 109 | static int ksz90x1_of_config_group(struct phy_device *phydev, |
James Byrne | 457107f | 2019-03-04 17:40:33 +0000 | [diff] [blame] | 110 | struct ksz90x1_ofcfg *ofcfg, |
| 111 | int ps_to_regval) |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 112 | { |
| 113 | struct udevice *dev = phydev->dev; |
| 114 | struct phy_driver *drv = phydev->drv; |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 115 | int val[4]; |
| 116 | int i, changed = 0, offset, max; |
| 117 | u16 regval = 0; |
James Byrne | 9e79144 | 2019-03-04 17:40:34 +0000 | [diff] [blame] | 118 | ofnode node; |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 119 | |
| 120 | if (!drv || !drv->writeext) |
| 121 | return -EOPNOTSUPP; |
| 122 | |
James Byrne | 9e79144 | 2019-03-04 17:40:34 +0000 | [diff] [blame] | 123 | /* Look for a PHY node under the Ethernet node */ |
| 124 | node = dev_read_subnode(dev, "ethernet-phy"); |
| 125 | if (!ofnode_valid(node)) { |
| 126 | /* No node found, look in the Ethernet node */ |
| 127 | node = dev_ofnode(dev); |
| 128 | } |
| 129 | |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 130 | for (i = 0; i < ofcfg->grpsz; i++) { |
James Byrne | 9e79144 | 2019-03-04 17:40:34 +0000 | [diff] [blame] | 131 | val[i] = ofnode_read_u32_default(node, ofcfg->grp[i].name, ~0); |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 132 | offset = ofcfg->grp[i].off; |
| 133 | if (val[i] == -1) { |
| 134 | /* Default register value for KSZ9021 */ |
| 135 | regval |= ofcfg->grp[i].dflt << offset; |
| 136 | } else { |
| 137 | changed = 1; /* Value was changed in OF */ |
| 138 | /* Calculate the register value and fix corner cases */ |
Andreas Pretzsch | f7c689d | 2018-11-29 20:04:53 +0100 | [diff] [blame] | 139 | max = (1 << ofcfg->grp[i].size) - 1; |
| 140 | if (val[i] > ps_to_regval * max) { |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 141 | regval |= max << offset; |
| 142 | } else { |
| 143 | regval |= (val[i] / ps_to_regval) << offset; |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if (!changed) |
| 149 | return 0; |
| 150 | |
| 151 | return drv->writeext(phydev, 0, ofcfg->devad, ofcfg->reg, regval); |
| 152 | } |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 153 | |
| 154 | static int ksz9021_of_config(struct phy_device *phydev) |
| 155 | { |
| 156 | struct ksz90x1_ofcfg ofcfg[] = { |
| 157 | { MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0, ksz90x1_rxd_grp, 4 }, |
| 158 | { MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0, ksz90x1_txd_grp, 4 }, |
| 159 | { MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0, ksz9021_clk_grp, 4 }, |
| 160 | }; |
| 161 | int i, ret = 0; |
| 162 | |
Marek Vasut | 0c76630 | 2016-11-14 15:08:42 +0100 | [diff] [blame] | 163 | for (i = 0; i < ARRAY_SIZE(ofcfg); i++) { |
James Byrne | 457107f | 2019-03-04 17:40:33 +0000 | [diff] [blame] | 164 | ret = ksz90x1_of_config_group(phydev, &ofcfg[i], |
| 165 | KSZ9021_PS_TO_REG); |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 166 | if (ret) |
| 167 | return ret; |
Marek Vasut | 0c76630 | 2016-11-14 15:08:42 +0100 | [diff] [blame] | 168 | } |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 169 | |
| 170 | return 0; |
| 171 | } |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 172 | |
| 173 | static int ksz9031_of_config(struct phy_device *phydev) |
| 174 | { |
| 175 | struct ksz90x1_ofcfg ofcfg[] = { |
| 176 | { MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW, 2, ksz9031_ctl_grp, 2 }, |
| 177 | { MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW, 2, ksz90x1_rxd_grp, 4 }, |
| 178 | { MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW, 2, ksz90x1_txd_grp, 4 }, |
| 179 | { MII_KSZ9031_EXT_RGMII_CLOCK_SKEW, 2, ksz9031_clk_grp, 2 }, |
| 180 | }; |
| 181 | int i, ret = 0; |
| 182 | |
| 183 | for (i = 0; i < ARRAY_SIZE(ofcfg); i++) { |
James Byrne | 457107f | 2019-03-04 17:40:33 +0000 | [diff] [blame] | 184 | ret = ksz90x1_of_config_group(phydev, &ofcfg[i], |
| 185 | KSZ9031_PS_TO_REG); |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 186 | if (ret) |
| 187 | return ret; |
| 188 | } |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static int ksz9031_center_flp_timing(struct phy_device *phydev) |
| 194 | { |
| 195 | struct phy_driver *drv = phydev->drv; |
| 196 | int ret = 0; |
| 197 | |
| 198 | if (!drv || !drv->writeext) |
| 199 | return -EOPNOTSUPP; |
| 200 | |
| 201 | ret = drv->writeext(phydev, 0, 0, MII_KSZ9031_FLP_BURST_TX_LO, 0x1A80); |
| 202 | if (ret) |
| 203 | return ret; |
| 204 | |
| 205 | ret = drv->writeext(phydev, 0, 0, MII_KSZ9031_FLP_BURST_TX_HI, 0x6); |
| 206 | return ret; |
| 207 | } |
| 208 | |
| 209 | #else /* !CONFIG_DM_ETH */ |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 210 | static int ksz9021_of_config(struct phy_device *phydev) |
| 211 | { |
| 212 | return 0; |
| 213 | } |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 214 | |
| 215 | static int ksz9031_of_config(struct phy_device *phydev) |
| 216 | { |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static int ksz9031_center_flp_timing(struct phy_device *phydev) |
| 221 | { |
| 222 | return 0; |
| 223 | } |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 224 | #endif |
| 225 | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 226 | /* |
| 227 | * KSZ9021 |
| 228 | */ |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 229 | int ksz9021_phy_extended_write(struct phy_device *phydev, int regnum, u16 val) |
| 230 | { |
| 231 | /* extended registers */ |
| 232 | phy_write(phydev, MDIO_DEVAD_NONE, |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 233 | MII_KSZ9021_EXTENDED_CTRL, regnum | 0x8000); |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 234 | return phy_write(phydev, MDIO_DEVAD_NONE, |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 235 | MII_KSZ9021_EXTENDED_DATAW, val); |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | int ksz9021_phy_extended_read(struct phy_device *phydev, int regnum) |
| 239 | { |
| 240 | /* extended registers */ |
| 241 | phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_CTRL, regnum); |
| 242 | return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_DATAR); |
| 243 | } |
| 244 | |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 245 | |
| 246 | static int ksz9021_phy_extread(struct phy_device *phydev, int addr, int devaddr, |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 247 | int regnum) |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 248 | { |
| 249 | return ksz9021_phy_extended_read(phydev, regnum); |
| 250 | } |
| 251 | |
| 252 | static int ksz9021_phy_extwrite(struct phy_device *phydev, int addr, |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 253 | int devaddr, int regnum, u16 val) |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 254 | { |
| 255 | return ksz9021_phy_extended_write(phydev, regnum, val); |
| 256 | } |
| 257 | |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 258 | static int ksz9021_config(struct phy_device *phydev) |
| 259 | { |
| 260 | unsigned ctrl1000 = 0; |
| 261 | const unsigned master = CTRL1000_PREFER_MASTER | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 262 | CTRL1000_CONFIG_MASTER | CTRL1000_MANUAL_CONFIG; |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 263 | unsigned features = phydev->drv->features; |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 264 | int ret; |
| 265 | |
| 266 | ret = ksz9021_of_config(phydev); |
| 267 | if (ret) |
| 268 | return ret; |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 269 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 270 | if (env_get("disable_giga")) |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 271 | features &= ~(SUPPORTED_1000baseT_Half | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 272 | SUPPORTED_1000baseT_Full); |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 273 | /* force master mode for 1000BaseT due to chip errata */ |
| 274 | if (features & SUPPORTED_1000baseT_Half) |
| 275 | ctrl1000 |= ADVERTISE_1000HALF | master; |
| 276 | if (features & SUPPORTED_1000baseT_Full) |
| 277 | ctrl1000 |= ADVERTISE_1000FULL | master; |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 278 | phydev->advertising = features; |
| 279 | phydev->supported = features; |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 280 | phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, ctrl1000); |
| 281 | genphy_config_aneg(phydev); |
| 282 | genphy_restart_aneg(phydev); |
| 283 | return 0; |
| 284 | } |
| 285 | |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 286 | static struct phy_driver ksz9021_driver = { |
| 287 | .name = "Micrel ksz9021", |
| 288 | .uid = 0x221610, |
James Byrne | bc292c2 | 2019-03-06 12:48:27 +0000 | [diff] [blame] | 289 | .mask = 0xfffffe, |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 290 | .features = PHY_GBIT_FEATURES, |
| 291 | .config = &ksz9021_config, |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 292 | .startup = &ksz90xx_startup, |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 293 | .shutdown = &genphy_shutdown, |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 294 | .writeext = &ksz9021_phy_extwrite, |
| 295 | .readext = &ksz9021_phy_extread, |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 296 | }; |
| 297 | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 298 | /* |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 299 | * KSZ9031 |
| 300 | */ |
SARTRE Leo | eaf68ac | 2013-04-30 16:57:25 +0200 | [diff] [blame] | 301 | int ksz9031_phy_extended_write(struct phy_device *phydev, |
| 302 | int devaddr, int regnum, u16 mode, u16 val) |
| 303 | { |
| 304 | /*select register addr for mmd*/ |
| 305 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 306 | MII_KSZ9031_MMD_ACCES_CTRL, devaddr); |
| 307 | /*select register for mmd*/ |
| 308 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 309 | MII_KSZ9031_MMD_REG_DATA, regnum); |
| 310 | /*setup mode*/ |
| 311 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 312 | MII_KSZ9031_MMD_ACCES_CTRL, (mode | devaddr)); |
| 313 | /*write the value*/ |
| 314 | return phy_write(phydev, MDIO_DEVAD_NONE, |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 315 | MII_KSZ9031_MMD_REG_DATA, val); |
SARTRE Leo | eaf68ac | 2013-04-30 16:57:25 +0200 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | int ksz9031_phy_extended_read(struct phy_device *phydev, int devaddr, |
| 319 | int regnum, u16 mode) |
| 320 | { |
| 321 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 322 | MII_KSZ9031_MMD_ACCES_CTRL, devaddr); |
| 323 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 324 | MII_KSZ9031_MMD_REG_DATA, regnum); |
| 325 | phy_write(phydev, MDIO_DEVAD_NONE, |
| 326 | MII_KSZ9031_MMD_ACCES_CTRL, (devaddr | mode)); |
| 327 | return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9031_MMD_REG_DATA); |
| 328 | } |
| 329 | |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 330 | static int ksz9031_phy_extread(struct phy_device *phydev, int addr, int devaddr, |
| 331 | int regnum) |
| 332 | { |
| 333 | return ksz9031_phy_extended_read(phydev, devaddr, regnum, |
| 334 | MII_KSZ9031_MOD_DATA_NO_POST_INC); |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 335 | } |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 336 | |
| 337 | static int ksz9031_phy_extwrite(struct phy_device *phydev, int addr, |
| 338 | int devaddr, int regnum, u16 val) |
| 339 | { |
| 340 | return ksz9031_phy_extended_write(phydev, devaddr, regnum, |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 341 | MII_KSZ9031_MOD_DATA_POST_INC_RW, val); |
| 342 | } |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 343 | |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 344 | static int ksz9031_config(struct phy_device *phydev) |
| 345 | { |
| 346 | int ret; |
Sebastien Bourdelin | 3a6e033 | 2017-07-28 15:59:22 -0400 | [diff] [blame] | 347 | |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 348 | ret = ksz9031_of_config(phydev); |
| 349 | if (ret) |
| 350 | return ret; |
Ash Charles | 3f55bb6 | 2016-10-21 17:31:33 -0400 | [diff] [blame] | 351 | ret = ksz9031_center_flp_timing(phydev); |
| 352 | if (ret) |
| 353 | return ret; |
Sebastien Bourdelin | 3a6e033 | 2017-07-28 15:59:22 -0400 | [diff] [blame] | 354 | |
| 355 | /* add an option to disable the gigabit feature of this PHY */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 356 | if (env_get("disable_giga")) { |
Sebastien Bourdelin | 3a6e033 | 2017-07-28 15:59:22 -0400 | [diff] [blame] | 357 | unsigned features; |
| 358 | unsigned bmcr; |
| 359 | |
| 360 | /* disable speed 1000 in features supported by the PHY */ |
| 361 | features = phydev->drv->features; |
| 362 | features &= ~(SUPPORTED_1000baseT_Half | |
| 363 | SUPPORTED_1000baseT_Full); |
| 364 | phydev->advertising = phydev->supported = features; |
| 365 | |
| 366 | /* disable speed 1000 in Basic Control Register */ |
| 367 | bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR); |
| 368 | bmcr &= ~(1 << 6); |
| 369 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr); |
| 370 | |
| 371 | /* disable speed 1000 in 1000Base-T Control Register */ |
| 372 | phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0); |
| 373 | |
| 374 | /* start autoneg */ |
| 375 | genphy_config_aneg(phydev); |
| 376 | genphy_restart_aneg(phydev); |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 381 | return genphy_config(phydev); |
| 382 | } |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 383 | |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 384 | static struct phy_driver ksz9031_driver = { |
| 385 | .name = "Micrel ksz9031", |
| 386 | .uid = 0x221620, |
Stefano Babic | d9e36ad | 2013-09-02 15:42:29 +0200 | [diff] [blame] | 387 | .mask = 0xfffff0, |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 388 | .features = PHY_GBIT_FEATURES, |
Marek Vasut | 1005ce5 | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 389 | .config = &ksz9031_config, |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 390 | .startup = &ksz90xx_startup, |
| 391 | .shutdown = &genphy_shutdown, |
Stefano Babic | a8aa299 | 2013-09-02 15:42:31 +0200 | [diff] [blame] | 392 | .writeext = &ksz9031_phy_extwrite, |
| 393 | .readext = &ksz9031_phy_extread, |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 394 | }; |
| 395 | |
Alexandru Gagniuc | 757bb67 | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 396 | int phy_micrel_ksz90x1_init(void) |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 397 | { |
Troy Kisky | 80b6b09 | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 398 | phy_register(&ksz9021_driver); |
David Andrey | f0d83c4 | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 399 | phy_register(&ksz9031_driver); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 400 | return 0; |
| 401 | } |