blob: ffc3c987eaae0dbccacd20c139fa3288a9d0cb74 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming9082eea2011-04-07 21:56:05 -05002/*
3 * Micrel PHY drivers
4 *
Andy Fleming9082eea2011-04-07 21:56:05 -05005 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
David Andrey62d7dba2013-02-06 22:18:37 +01007 * (C) 2012 NetModule AG, David Andrey, added KSZ9031
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -07008 * (C) Copyright 2017 Adaptrum, Inc.
9 * Written by Alexandru Gagniuc <alex.g@adaptrum.com> for Adaptrum, Inc.
Andy Fleming9082eea2011-04-07 21:56:05 -050010 */
Troy Kisky8682aba2012-02-07 14:08:48 +000011#include <common.h>
Marek Vasut22854bd2015-12-05 17:41:58 +010012#include <dm.h>
Simon Glass7b51b572019-08-01 09:46:52 -060013#include <env.h>
Marek Vasut22854bd2015-12-05 17:41:58 +010014#include <errno.h>
Troy Kisky8682aba2012-02-07 14:08:48 +000015#include <micrel.h>
Andy Fleming9082eea2011-04-07 21:56:05 -050016#include <phy.h>
17
Pavel Machek58ec63d2014-09-09 14:26:51 +020018/*
David Andrey62d7dba2013-02-06 22:18:37 +010019 * 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 Gagniucd397f7c2017-07-07 11:36:57 -070028/* 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 Byrne83f71ef2019-03-04 17:40:33 +000037#define KSZ9021_PS_TO_REG 120
38
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -070039/* KSZ9031 PHY Registers */
40#define MII_KSZ9031_MMD_ACCES_CTRL 0x0d
41#define MII_KSZ9031_MMD_REG_DATA 0x0e
42
James Byrne83f71ef2019-03-04 17:40:33 +000043#define KSZ9031_PS_TO_REG 60
44
David Andrey62d7dba2013-02-06 22:18:37 +010045static int ksz90xx_startup(struct phy_device *phydev)
46{
47 unsigned phy_ctl;
Michal Simekb733c272016-05-18 12:46:12 +020048 int ret;
49
50 ret = genphy_update_link(phydev);
51 if (ret)
52 return ret;
53
David Andrey62d7dba2013-02-06 22:18:37 +010054 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 Andrey62d7dba2013-02-06 22:18:37 +010069
Marek Vasut22854bd2015-12-05 17:41:58 +010070/* Common OF config bits for KSZ9021 and KSZ9031 */
Marek Vasut22854bd2015-12-05 17:41:58 +010071struct 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
78struct ksz90x1_ofcfg {
79 const u16 reg;
80 const u16 devad;
81 const struct ksz90x1_reg_field *grp;
82 const u16 grpsz;
83};
84
85static 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
90static 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 Gagniucd397f7c2017-07-07 11:36:57 -070095static 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
100static const struct ksz90x1_reg_field ksz9031_ctl_grp[] = {
101 { "txen-skew-ps", 4, 0, 0x7 }, { "rxdv-skew-ps", 4, 4, 0x7 }
102};
103
104static const struct ksz90x1_reg_field ksz9031_clk_grp[] = {
105 { "rxc-skew-ps", 5, 0, 0xf }, { "txc-skew-ps", 5, 5, 0xf }
106};
107
Marek Vasut22854bd2015-12-05 17:41:58 +0100108static int ksz90x1_of_config_group(struct phy_device *phydev,
James Byrne83f71ef2019-03-04 17:40:33 +0000109 struct ksz90x1_ofcfg *ofcfg,
110 int ps_to_regval)
Marek Vasut22854bd2015-12-05 17:41:58 +0100111{
112 struct udevice *dev = phydev->dev;
113 struct phy_driver *drv = phydev->drv;
Marek Vasut22854bd2015-12-05 17:41:58 +0100114 int val[4];
115 int i, changed = 0, offset, max;
116 u16 regval = 0;
James Byrne6314d1c2019-03-04 17:40:34 +0000117 ofnode node;
Marek Vasut22854bd2015-12-05 17:41:58 +0100118
119 if (!drv || !drv->writeext)
120 return -EOPNOTSUPP;
121
Marek Vasutb5f09df2021-01-17 00:16:16 +0100122 node = phydev->node;
123
124 if (!ofnode_valid(node)) {
125 /* Look for a PHY node under the Ethernet node */
126 node = dev_read_subnode(dev, "ethernet-phy");
127 }
128
James Byrne6314d1c2019-03-04 17:40:34 +0000129 if (!ofnode_valid(node)) {
130 /* No node found, look in the Ethernet node */
131 node = dev_ofnode(dev);
132 }
133
Marek Vasut22854bd2015-12-05 17:41:58 +0100134 for (i = 0; i < ofcfg->grpsz; i++) {
James Byrne6314d1c2019-03-04 17:40:34 +0000135 val[i] = ofnode_read_u32_default(node, ofcfg->grp[i].name, ~0);
Marek Vasut22854bd2015-12-05 17:41:58 +0100136 offset = ofcfg->grp[i].off;
137 if (val[i] == -1) {
138 /* Default register value for KSZ9021 */
139 regval |= ofcfg->grp[i].dflt << offset;
140 } else {
141 changed = 1; /* Value was changed in OF */
142 /* Calculate the register value and fix corner cases */
Andreas Pretzsch3b4cda32018-11-29 20:04:53 +0100143 max = (1 << ofcfg->grp[i].size) - 1;
144 if (val[i] > ps_to_regval * max) {
Marek Vasut22854bd2015-12-05 17:41:58 +0100145 regval |= max << offset;
146 } else {
147 regval |= (val[i] / ps_to_regval) << offset;
148 }
149 }
150 }
151
152 if (!changed)
153 return 0;
154
155 return drv->writeext(phydev, 0, ofcfg->devad, ofcfg->reg, regval);
156}
Marek Vasut22854bd2015-12-05 17:41:58 +0100157
158static int ksz9021_of_config(struct phy_device *phydev)
159{
160 struct ksz90x1_ofcfg ofcfg[] = {
161 { MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0, ksz90x1_rxd_grp, 4 },
162 { MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0, ksz90x1_txd_grp, 4 },
163 { MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0, ksz9021_clk_grp, 4 },
164 };
165 int i, ret = 0;
166
Marek Vasut75c056d2016-11-14 15:08:42 +0100167 for (i = 0; i < ARRAY_SIZE(ofcfg); i++) {
James Byrne83f71ef2019-03-04 17:40:33 +0000168 ret = ksz90x1_of_config_group(phydev, &ofcfg[i],
169 KSZ9021_PS_TO_REG);
Marek Vasut22854bd2015-12-05 17:41:58 +0100170 if (ret)
171 return ret;
Marek Vasut75c056d2016-11-14 15:08:42 +0100172 }
Marek Vasut22854bd2015-12-05 17:41:58 +0100173
174 return 0;
175}
Marek Vasut22854bd2015-12-05 17:41:58 +0100176
177static int ksz9031_of_config(struct phy_device *phydev)
178{
179 struct ksz90x1_ofcfg ofcfg[] = {
180 { MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW, 2, ksz9031_ctl_grp, 2 },
181 { MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW, 2, ksz90x1_rxd_grp, 4 },
182 { MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW, 2, ksz90x1_txd_grp, 4 },
183 { MII_KSZ9031_EXT_RGMII_CLOCK_SKEW, 2, ksz9031_clk_grp, 2 },
184 };
185 int i, ret = 0;
186
Marek Vasut75c056d2016-11-14 15:08:42 +0100187 for (i = 0; i < ARRAY_SIZE(ofcfg); i++) {
James Byrne83f71ef2019-03-04 17:40:33 +0000188 ret = ksz90x1_of_config_group(phydev, &ofcfg[i],
189 KSZ9031_PS_TO_REG);
Marek Vasut22854bd2015-12-05 17:41:58 +0100190 if (ret)
191 return ret;
Marek Vasut75c056d2016-11-14 15:08:42 +0100192 }
Marek Vasut22854bd2015-12-05 17:41:58 +0100193
194 return 0;
195}
Ash Charlesf0185452016-10-21 17:31:33 -0400196
197static int ksz9031_center_flp_timing(struct phy_device *phydev)
198{
199 struct phy_driver *drv = phydev->drv;
200 int ret = 0;
201
202 if (!drv || !drv->writeext)
203 return -EOPNOTSUPP;
204
205 ret = drv->writeext(phydev, 0, 0, MII_KSZ9031_FLP_BURST_TX_LO, 0x1A80);
206 if (ret)
207 return ret;
208
209 ret = drv->writeext(phydev, 0, 0, MII_KSZ9031_FLP_BURST_TX_HI, 0x6);
210 return ret;
211}
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700212
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700213/*
214 * KSZ9021
215 */
216int ksz9021_phy_extended_write(struct phy_device *phydev, int regnum, u16 val)
217{
218 /* extended registers */
219 phy_write(phydev, MDIO_DEVAD_NONE,
220 MII_KSZ9021_EXTENDED_CTRL, regnum | 0x8000);
221 return phy_write(phydev, MDIO_DEVAD_NONE,
222 MII_KSZ9021_EXTENDED_DATAW, val);
223}
224
225int ksz9021_phy_extended_read(struct phy_device *phydev, int regnum)
226{
227 /* extended registers */
228 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_CTRL, regnum);
229 return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_DATAR);
230}
231
232
233static int ksz9021_phy_extread(struct phy_device *phydev, int addr, int devaddr,
234 int regnum)
235{
236 return ksz9021_phy_extended_read(phydev, regnum);
237}
238
239static int ksz9021_phy_extwrite(struct phy_device *phydev, int addr,
240 int devaddr, int regnum, u16 val)
241{
242 return ksz9021_phy_extended_write(phydev, regnum, val);
243}
244
245static int ksz9021_config(struct phy_device *phydev)
246{
247 unsigned ctrl1000 = 0;
248 const unsigned master = CTRL1000_PREFER_MASTER |
249 CTRL1000_CONFIG_MASTER | CTRL1000_MANUAL_CONFIG;
250 unsigned features = phydev->drv->features;
251 int ret;
252
253 ret = ksz9021_of_config(phydev);
254 if (ret)
255 return ret;
256
Simon Glass00caae62017-08-03 12:22:12 -0600257 if (env_get("disable_giga"))
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700258 features &= ~(SUPPORTED_1000baseT_Half |
259 SUPPORTED_1000baseT_Full);
260 /* force master mode for 1000BaseT due to chip errata */
261 if (features & SUPPORTED_1000baseT_Half)
262 ctrl1000 |= ADVERTISE_1000HALF | master;
263 if (features & SUPPORTED_1000baseT_Full)
264 ctrl1000 |= ADVERTISE_1000FULL | master;
265 phydev->advertising = features;
266 phydev->supported = features;
267 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, ctrl1000);
268 genphy_config_aneg(phydev);
269 genphy_restart_aneg(phydev);
270 return 0;
271}
272
Marek Vasut6b5eea72023-03-19 18:02:56 +0100273U_BOOT_PHY_DRIVER(ksz9021) = {
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700274 .name = "Micrel ksz9021",
275 .uid = 0x221610,
James Byrne77b508d2019-03-06 12:48:27 +0000276 .mask = 0xfffffe,
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700277 .features = PHY_GBIT_FEATURES,
278 .config = &ksz9021_config,
279 .startup = &ksz90xx_startup,
280 .shutdown = &genphy_shutdown,
281 .writeext = &ksz9021_phy_extwrite,
282 .readext = &ksz9021_phy_extread,
283};
284
285/*
286 * KSZ9031
287 */
SARTRE Leo42a7cb52013-04-30 16:57:25 +0200288int ksz9031_phy_extended_write(struct phy_device *phydev,
289 int devaddr, int regnum, u16 mode, u16 val)
290{
291 /*select register addr for mmd*/
292 phy_write(phydev, MDIO_DEVAD_NONE,
293 MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
294 /*select register for mmd*/
295 phy_write(phydev, MDIO_DEVAD_NONE,
296 MII_KSZ9031_MMD_REG_DATA, regnum);
297 /*setup mode*/
298 phy_write(phydev, MDIO_DEVAD_NONE,
299 MII_KSZ9031_MMD_ACCES_CTRL, (mode | devaddr));
300 /*write the value*/
301 return phy_write(phydev, MDIO_DEVAD_NONE,
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700302 MII_KSZ9031_MMD_REG_DATA, val);
SARTRE Leo42a7cb52013-04-30 16:57:25 +0200303}
304
305int ksz9031_phy_extended_read(struct phy_device *phydev, int devaddr,
306 int regnum, u16 mode)
307{
308 phy_write(phydev, MDIO_DEVAD_NONE,
309 MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
310 phy_write(phydev, MDIO_DEVAD_NONE,
311 MII_KSZ9031_MMD_REG_DATA, regnum);
312 phy_write(phydev, MDIO_DEVAD_NONE,
313 MII_KSZ9031_MMD_ACCES_CTRL, (devaddr | mode));
314 return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9031_MMD_REG_DATA);
315}
316
Stefano Babic9ced16f2013-09-02 15:42:31 +0200317static int ksz9031_phy_extread(struct phy_device *phydev, int addr, int devaddr,
318 int regnum)
319{
320 return ksz9031_phy_extended_read(phydev, devaddr, regnum,
321 MII_KSZ9031_MOD_DATA_NO_POST_INC);
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700322}
Stefano Babic9ced16f2013-09-02 15:42:31 +0200323
324static int ksz9031_phy_extwrite(struct phy_device *phydev, int addr,
325 int devaddr, int regnum, u16 val)
326{
327 return ksz9031_phy_extended_write(phydev, devaddr, regnum,
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700328 MII_KSZ9031_MOD_DATA_POST_INC_RW, val);
329}
Stefano Babic9ced16f2013-09-02 15:42:31 +0200330
Marek Vasut22854bd2015-12-05 17:41:58 +0100331static int ksz9031_config(struct phy_device *phydev)
332{
333 int ret;
Sebastien Bourdelinef1f61a2017-07-28 15:59:22 -0400334
Marek Vasut22854bd2015-12-05 17:41:58 +0100335 ret = ksz9031_of_config(phydev);
336 if (ret)
337 return ret;
Ash Charlesf0185452016-10-21 17:31:33 -0400338 ret = ksz9031_center_flp_timing(phydev);
339 if (ret)
340 return ret;
Sebastien Bourdelinef1f61a2017-07-28 15:59:22 -0400341
342 /* add an option to disable the gigabit feature of this PHY */
Simon Glass00caae62017-08-03 12:22:12 -0600343 if (env_get("disable_giga")) {
Sebastien Bourdelinef1f61a2017-07-28 15:59:22 -0400344 unsigned features;
345 unsigned bmcr;
346
347 /* disable speed 1000 in features supported by the PHY */
348 features = phydev->drv->features;
349 features &= ~(SUPPORTED_1000baseT_Half |
350 SUPPORTED_1000baseT_Full);
351 phydev->advertising = phydev->supported = features;
352
353 /* disable speed 1000 in Basic Control Register */
354 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
355 bmcr &= ~(1 << 6);
356 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr);
357
358 /* disable speed 1000 in 1000Base-T Control Register */
359 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0);
360
361 /* start autoneg */
362 genphy_config_aneg(phydev);
363 genphy_restart_aneg(phydev);
364
365 return 0;
366 }
367
Marek Vasut22854bd2015-12-05 17:41:58 +0100368 return genphy_config(phydev);
369}
Stefano Babic9ced16f2013-09-02 15:42:31 +0200370
Marek Vasut6b5eea72023-03-19 18:02:56 +0100371U_BOOT_PHY_DRIVER(ksz9031) = {
David Andrey62d7dba2013-02-06 22:18:37 +0100372 .name = "Micrel ksz9031",
Philippe Schenker0861aa82020-03-11 11:59:22 +0100373 .uid = PHY_ID_KSZ9031,
374 .mask = MII_KSZ9x31_SILICON_REV_MASK,
David Andrey62d7dba2013-02-06 22:18:37 +0100375 .features = PHY_GBIT_FEATURES,
Marek Vasut22854bd2015-12-05 17:41:58 +0100376 .config = &ksz9031_config,
David Andrey62d7dba2013-02-06 22:18:37 +0100377 .startup = &ksz90xx_startup,
378 .shutdown = &genphy_shutdown,
Stefano Babic9ced16f2013-09-02 15:42:31 +0200379 .writeext = &ksz9031_phy_extwrite,
380 .readext = &ksz9031_phy_extread,
David Andrey62d7dba2013-02-06 22:18:37 +0100381};
382
Philippe Schenkerc51eef52020-03-11 11:59:23 +0100383/*
384 * KSZ9131
385 */
Claudiu Bezneac6df0e22020-12-03 11:18:30 +0200386
387#define KSZ9131RN_MMD_COMMON_CTRL_REG 2
388#define KSZ9131RN_RXC_DLL_CTRL 76
389#define KSZ9131RN_TXC_DLL_CTRL 77
390#define KSZ9131RN_DLL_CTRL_BYPASS BIT_MASK(12)
391#define KSZ9131RN_DLL_ENABLE_DELAY 0
392#define KSZ9131RN_DLL_DISABLE_DELAY BIT(12)
393
394static int ksz9131_config_rgmii_delay(struct phy_device *phydev)
395{
396 struct phy_driver *drv = phydev->drv;
397 u16 rxcdll_val, txcdll_val, val;
398 int ret;
399
400 switch (phydev->interface) {
401 case PHY_INTERFACE_MODE_RGMII:
402 rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
403 txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
404 break;
405 case PHY_INTERFACE_MODE_RGMII_ID:
406 rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
407 txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
408 break;
409 case PHY_INTERFACE_MODE_RGMII_RXID:
410 rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
411 txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
412 break;
413 case PHY_INTERFACE_MODE_RGMII_TXID:
414 rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
415 txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
416 break;
417 default:
418 return 0;
419 }
420
421 val = drv->readext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
422 KSZ9131RN_RXC_DLL_CTRL);
423 val &= ~KSZ9131RN_DLL_CTRL_BYPASS;
424 val |= rxcdll_val;
425 ret = drv->writeext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
426 KSZ9131RN_RXC_DLL_CTRL, val);
427 if (ret)
428 return ret;
429
430 val = drv->readext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
431 KSZ9131RN_TXC_DLL_CTRL);
432
433 val &= ~KSZ9131RN_DLL_CTRL_BYPASS;
434 val |= txcdll_val;
435 ret = drv->writeext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
436 KSZ9131RN_TXC_DLL_CTRL, val);
437
438 return ret;
439}
440
Philippe Schenkerc51eef52020-03-11 11:59:23 +0100441static int ksz9131_config(struct phy_device *phydev)
442{
Claudiu Bezneac6df0e22020-12-03 11:18:30 +0200443 int ret;
444
445 if (phy_interface_is_rgmii(phydev)) {
446 ret = ksz9131_config_rgmii_delay(phydev);
447 if (ret)
448 return ret;
449 }
Philippe Schenkerc51eef52020-03-11 11:59:23 +0100450
451 /* add an option to disable the gigabit feature of this PHY */
452 if (env_get("disable_giga")) {
453 unsigned features;
454 unsigned bmcr;
455
456 /* disable speed 1000 in features supported by the PHY */
457 features = phydev->drv->features;
458 features &= ~(SUPPORTED_1000baseT_Half |
459 SUPPORTED_1000baseT_Full);
460 phydev->advertising = phydev->supported = features;
461
462 /* disable speed 1000 in Basic Control Register */
463 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
464 bmcr &= ~(1 << 6);
465 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr);
466
467 /* disable speed 1000 in 1000Base-T Control Register */
468 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0);
469
470 /* start autoneg */
471 genphy_config_aneg(phydev);
472 genphy_restart_aneg(phydev);
473
474 return 0;
475 }
476
477 return genphy_config(phydev);
478}
479
Marek Vasut6b5eea72023-03-19 18:02:56 +0100480U_BOOT_PHY_DRIVER(ksz9131) = {
Claudiu Beznea36dfddc2020-12-03 11:18:31 +0200481 .name = "Micrel ksz9131",
Philippe Schenkerc51eef52020-03-11 11:59:23 +0100482 .uid = PHY_ID_KSZ9131,
483 .mask = MII_KSZ9x31_SILICON_REV_MASK,
484 .features = PHY_GBIT_FEATURES,
485 .config = &ksz9131_config,
486 .startup = &ksz90xx_startup,
487 .shutdown = &genphy_shutdown,
488 .writeext = &ksz9031_phy_extwrite,
489 .readext = &ksz9031_phy_extread,
490};
491
492int ksz9xx1_phy_get_id(struct phy_device *phydev)
493{
494 unsigned int phyid;
495
496 get_phy_id(phydev->bus, phydev->addr, MDIO_DEVAD_NONE, &phyid);
497
498 return phyid;
499}