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