blob: c48ae6e88f307de19b46b86a74cb923192e79081 [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 */
Marek Vasut22854bd2015-12-05 17:41:58 +010011#include <dm.h>
Simon Glass7b51b572019-08-01 09:46:52 -060012#include <env.h>
Marek Vasut22854bd2015-12-05 17:41:58 +010013#include <errno.h>
Troy Kisky8682aba2012-02-07 14:08:48 +000014#include <micrel.h>
Andy Fleming9082eea2011-04-07 21:56:05 -050015#include <phy.h>
16
Pavel Machek58ec63d2014-09-09 14:26:51 +020017/*
David Andrey62d7dba2013-02-06 22:18:37 +010018 * 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 Gagniucd397f7c2017-07-07 11:36:57 -070027/* 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 Byrne83f71ef2019-03-04 17:40:33 +000036#define KSZ9021_PS_TO_REG 120
37
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -070038/* KSZ9031 PHY Registers */
39#define MII_KSZ9031_MMD_ACCES_CTRL 0x0d
40#define MII_KSZ9031_MMD_REG_DATA 0x0e
41
James Byrne83f71ef2019-03-04 17:40:33 +000042#define KSZ9031_PS_TO_REG 60
43
David Andrey62d7dba2013-02-06 22:18:37 +010044static int ksz90xx_startup(struct phy_device *phydev)
45{
46 unsigned phy_ctl;
Michal Simekb733c272016-05-18 12:46:12 +020047 int ret;
48
49 ret = genphy_update_link(phydev);
50 if (ret)
51 return ret;
52
David Andrey62d7dba2013-02-06 22:18:37 +010053 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 Andrey62d7dba2013-02-06 22:18:37 +010068
Marek Vasut22854bd2015-12-05 17:41:58 +010069/* Common OF config bits for KSZ9021 and KSZ9031 */
Marek Vasut22854bd2015-12-05 17:41:58 +010070struct ksz90x1_reg_field {
71 const char *name;
72 const u8 size; /* Size of the bitfield, in bits */
73 const u8 off; /* Offset from bit 0 */
74 const u8 dflt; /* Default value */
75};
76
77struct ksz90x1_ofcfg {
78 const u16 reg;
79 const u16 devad;
80 const struct ksz90x1_reg_field *grp;
81 const u16 grpsz;
82};
83
84static const struct ksz90x1_reg_field ksz90x1_rxd_grp[] = {
85 { "rxd0-skew-ps", 4, 0, 0x7 }, { "rxd1-skew-ps", 4, 4, 0x7 },
86 { "rxd2-skew-ps", 4, 8, 0x7 }, { "rxd3-skew-ps", 4, 12, 0x7 }
87};
88
89static const struct ksz90x1_reg_field ksz90x1_txd_grp[] = {
90 { "txd0-skew-ps", 4, 0, 0x7 }, { "txd1-skew-ps", 4, 4, 0x7 },
91 { "txd2-skew-ps", 4, 8, 0x7 }, { "txd3-skew-ps", 4, 12, 0x7 },
92};
93
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -070094static const struct ksz90x1_reg_field ksz9021_clk_grp[] = {
95 { "txen-skew-ps", 4, 0, 0x7 }, { "txc-skew-ps", 4, 4, 0x7 },
96 { "rxdv-skew-ps", 4, 8, 0x7 }, { "rxc-skew-ps", 4, 12, 0x7 },
97};
98
99static const struct ksz90x1_reg_field ksz9031_ctl_grp[] = {
100 { "txen-skew-ps", 4, 0, 0x7 }, { "rxdv-skew-ps", 4, 4, 0x7 }
101};
102
103static const struct ksz90x1_reg_field ksz9031_clk_grp[] = {
104 { "rxc-skew-ps", 5, 0, 0xf }, { "txc-skew-ps", 5, 5, 0xf }
105};
106
Marek Vasut22854bd2015-12-05 17:41:58 +0100107static int ksz90x1_of_config_group(struct phy_device *phydev,
James Byrne83f71ef2019-03-04 17:40:33 +0000108 struct ksz90x1_ofcfg *ofcfg,
109 int ps_to_regval)
Marek Vasut22854bd2015-12-05 17:41:58 +0100110{
111 struct udevice *dev = phydev->dev;
112 struct phy_driver *drv = phydev->drv;
Marek Vasut22854bd2015-12-05 17:41:58 +0100113 int val[4];
114 int i, changed = 0, offset, max;
115 u16 regval = 0;
James Byrne6314d1c2019-03-04 17:40:34 +0000116 ofnode node;
Marek Vasut22854bd2015-12-05 17:41:58 +0100117
118 if (!drv || !drv->writeext)
119 return -EOPNOTSUPP;
120
Marek Vasutb5f09df2021-01-17 00:16:16 +0100121 node = phydev->node;
122
123 if (!ofnode_valid(node)) {
124 /* Look for a PHY node under the Ethernet node */
125 node = dev_read_subnode(dev, "ethernet-phy");
126 }
127
James Byrne6314d1c2019-03-04 17:40:34 +0000128 if (!ofnode_valid(node)) {
129 /* No node found, look in the Ethernet node */
130 node = dev_ofnode(dev);
131 }
132
Marek Vasut22854bd2015-12-05 17:41:58 +0100133 for (i = 0; i < ofcfg->grpsz; i++) {
James Byrne6314d1c2019-03-04 17:40:34 +0000134 val[i] = ofnode_read_u32_default(node, ofcfg->grp[i].name, ~0);
Marek Vasut22854bd2015-12-05 17:41:58 +0100135 offset = ofcfg->grp[i].off;
136 if (val[i] == -1) {
137 /* Default register value for KSZ9021 */
138 regval |= ofcfg->grp[i].dflt << offset;
139 } else {
140 changed = 1; /* Value was changed in OF */
141 /* Calculate the register value and fix corner cases */
Andreas Pretzsch3b4cda32018-11-29 20:04:53 +0100142 max = (1 << ofcfg->grp[i].size) - 1;
143 if (val[i] > ps_to_regval * max) {
Marek Vasut22854bd2015-12-05 17:41:58 +0100144 regval |= max << offset;
145 } else {
146 regval |= (val[i] / ps_to_regval) << offset;
147 }
148 }
149 }
150
151 if (!changed)
152 return 0;
153
154 return drv->writeext(phydev, 0, ofcfg->devad, ofcfg->reg, regval);
155}
Marek Vasut22854bd2015-12-05 17:41:58 +0100156
157static int ksz9021_of_config(struct phy_device *phydev)
158{
159 struct ksz90x1_ofcfg ofcfg[] = {
160 { MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0, ksz90x1_rxd_grp, 4 },
161 { MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0, ksz90x1_txd_grp, 4 },
162 { MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0, ksz9021_clk_grp, 4 },
163 };
164 int i, ret = 0;
165
Marek Vasut75c056d2016-11-14 15:08:42 +0100166 for (i = 0; i < ARRAY_SIZE(ofcfg); i++) {
James Byrne83f71ef2019-03-04 17:40:33 +0000167 ret = ksz90x1_of_config_group(phydev, &ofcfg[i],
168 KSZ9021_PS_TO_REG);
Marek Vasut22854bd2015-12-05 17:41:58 +0100169 if (ret)
170 return ret;
Marek Vasut75c056d2016-11-14 15:08:42 +0100171 }
Marek Vasut22854bd2015-12-05 17:41:58 +0100172
173 return 0;
174}
Marek Vasut22854bd2015-12-05 17:41:58 +0100175
176static int ksz9031_of_config(struct phy_device *phydev)
177{
178 struct ksz90x1_ofcfg ofcfg[] = {
179 { MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW, 2, ksz9031_ctl_grp, 2 },
180 { MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW, 2, ksz90x1_rxd_grp, 4 },
181 { MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW, 2, ksz90x1_txd_grp, 4 },
182 { MII_KSZ9031_EXT_RGMII_CLOCK_SKEW, 2, ksz9031_clk_grp, 2 },
183 };
184 int i, ret = 0;
185
Marek Vasut75c056d2016-11-14 15:08:42 +0100186 for (i = 0; i < ARRAY_SIZE(ofcfg); i++) {
James Byrne83f71ef2019-03-04 17:40:33 +0000187 ret = ksz90x1_of_config_group(phydev, &ofcfg[i],
188 KSZ9031_PS_TO_REG);
Marek Vasut22854bd2015-12-05 17:41:58 +0100189 if (ret)
190 return ret;
Marek Vasut75c056d2016-11-14 15:08:42 +0100191 }
Marek Vasut22854bd2015-12-05 17:41:58 +0100192
193 return 0;
194}
Ash Charlesf0185452016-10-21 17:31:33 -0400195
196static int ksz9031_center_flp_timing(struct phy_device *phydev)
197{
198 struct phy_driver *drv = phydev->drv;
199 int ret = 0;
200
201 if (!drv || !drv->writeext)
202 return -EOPNOTSUPP;
203
204 ret = drv->writeext(phydev, 0, 0, MII_KSZ9031_FLP_BURST_TX_LO, 0x1A80);
205 if (ret)
206 return ret;
207
208 ret = drv->writeext(phydev, 0, 0, MII_KSZ9031_FLP_BURST_TX_HI, 0x6);
209 return ret;
210}
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700211
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700212/*
213 * KSZ9021
214 */
215int ksz9021_phy_extended_write(struct phy_device *phydev, int regnum, u16 val)
216{
217 /* extended registers */
218 phy_write(phydev, MDIO_DEVAD_NONE,
219 MII_KSZ9021_EXTENDED_CTRL, regnum | 0x8000);
220 return phy_write(phydev, MDIO_DEVAD_NONE,
221 MII_KSZ9021_EXTENDED_DATAW, val);
222}
223
224int ksz9021_phy_extended_read(struct phy_device *phydev, int regnum)
225{
226 /* extended registers */
227 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_CTRL, regnum);
228 return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_DATAR);
229}
230
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700231static int ksz9021_phy_extread(struct phy_device *phydev, int addr, int devaddr,
232 int regnum)
233{
234 return ksz9021_phy_extended_read(phydev, regnum);
235}
236
237static int ksz9021_phy_extwrite(struct phy_device *phydev, int addr,
238 int devaddr, int regnum, u16 val)
239{
240 return ksz9021_phy_extended_write(phydev, regnum, val);
241}
242
243static int ksz9021_config(struct phy_device *phydev)
244{
245 unsigned ctrl1000 = 0;
246 const unsigned master = CTRL1000_PREFER_MASTER |
247 CTRL1000_CONFIG_MASTER | CTRL1000_MANUAL_CONFIG;
248 unsigned features = phydev->drv->features;
249 int ret;
250
251 ret = ksz9021_of_config(phydev);
252 if (ret)
253 return ret;
254
Simon Glass00caae62017-08-03 12:22:12 -0600255 if (env_get("disable_giga"))
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700256 features &= ~(SUPPORTED_1000baseT_Half |
257 SUPPORTED_1000baseT_Full);
258 /* force master mode for 1000BaseT due to chip errata */
259 if (features & SUPPORTED_1000baseT_Half)
260 ctrl1000 |= ADVERTISE_1000HALF | master;
261 if (features & SUPPORTED_1000baseT_Full)
262 ctrl1000 |= ADVERTISE_1000FULL | master;
263 phydev->advertising = features;
264 phydev->supported = features;
265 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, ctrl1000);
266 genphy_config_aneg(phydev);
267 genphy_restart_aneg(phydev);
268 return 0;
269}
270
Marek Vasut6b5eea72023-03-19 18:02:56 +0100271U_BOOT_PHY_DRIVER(ksz9021) = {
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700272 .name = "Micrel ksz9021",
273 .uid = 0x221610,
James Byrne77b508d2019-03-06 12:48:27 +0000274 .mask = 0xfffffe,
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700275 .features = PHY_GBIT_FEATURES,
276 .config = &ksz9021_config,
277 .startup = &ksz90xx_startup,
278 .shutdown = &genphy_shutdown,
279 .writeext = &ksz9021_phy_extwrite,
280 .readext = &ksz9021_phy_extread,
281};
282
283/*
284 * KSZ9031
285 */
SARTRE Leo42a7cb52013-04-30 16:57:25 +0200286int ksz9031_phy_extended_write(struct phy_device *phydev,
287 int devaddr, int regnum, u16 mode, u16 val)
288{
289 /*select register addr for mmd*/
290 phy_write(phydev, MDIO_DEVAD_NONE,
291 MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
292 /*select register for mmd*/
293 phy_write(phydev, MDIO_DEVAD_NONE,
294 MII_KSZ9031_MMD_REG_DATA, regnum);
295 /*setup mode*/
296 phy_write(phydev, MDIO_DEVAD_NONE,
297 MII_KSZ9031_MMD_ACCES_CTRL, (mode | devaddr));
298 /*write the value*/
299 return phy_write(phydev, MDIO_DEVAD_NONE,
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700300 MII_KSZ9031_MMD_REG_DATA, val);
SARTRE Leo42a7cb52013-04-30 16:57:25 +0200301}
302
303int ksz9031_phy_extended_read(struct phy_device *phydev, int devaddr,
304 int regnum, u16 mode)
305{
306 phy_write(phydev, MDIO_DEVAD_NONE,
307 MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
308 phy_write(phydev, MDIO_DEVAD_NONE,
309 MII_KSZ9031_MMD_REG_DATA, regnum);
310 phy_write(phydev, MDIO_DEVAD_NONE,
311 MII_KSZ9031_MMD_ACCES_CTRL, (devaddr | mode));
312 return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9031_MMD_REG_DATA);
313}
314
Stefano Babic9ced16f2013-09-02 15:42:31 +0200315static int ksz9031_phy_extread(struct phy_device *phydev, int addr, int devaddr,
316 int regnum)
317{
318 return ksz9031_phy_extended_read(phydev, devaddr, regnum,
319 MII_KSZ9031_MOD_DATA_NO_POST_INC);
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700320}
Stefano Babic9ced16f2013-09-02 15:42:31 +0200321
322static int ksz9031_phy_extwrite(struct phy_device *phydev, int addr,
323 int devaddr, int regnum, u16 val)
324{
325 return ksz9031_phy_extended_write(phydev, devaddr, regnum,
Alexandru Gagniucd397f7c2017-07-07 11:36:57 -0700326 MII_KSZ9031_MOD_DATA_POST_INC_RW, val);
327}
Stefano Babic9ced16f2013-09-02 15:42:31 +0200328
Marek Vasut22854bd2015-12-05 17:41:58 +0100329static int ksz9031_config(struct phy_device *phydev)
330{
331 int ret;
Sebastien Bourdelinef1f61a2017-07-28 15:59:22 -0400332
Marek Vasut22854bd2015-12-05 17:41:58 +0100333 ret = ksz9031_of_config(phydev);
334 if (ret)
335 return ret;
Ash Charlesf0185452016-10-21 17:31:33 -0400336 ret = ksz9031_center_flp_timing(phydev);
337 if (ret)
338 return ret;
Sebastien Bourdelinef1f61a2017-07-28 15:59:22 -0400339
340 /* add an option to disable the gigabit feature of this PHY */
Simon Glass00caae62017-08-03 12:22:12 -0600341 if (env_get("disable_giga")) {
Sebastien Bourdelinef1f61a2017-07-28 15:59:22 -0400342 unsigned features;
343 unsigned bmcr;
344
345 /* disable speed 1000 in features supported by the PHY */
346 features = phydev->drv->features;
347 features &= ~(SUPPORTED_1000baseT_Half |
348 SUPPORTED_1000baseT_Full);
349 phydev->advertising = phydev->supported = features;
350
351 /* disable speed 1000 in Basic Control Register */
352 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
353 bmcr &= ~(1 << 6);
354 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr);
355
356 /* disable speed 1000 in 1000Base-T Control Register */
357 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0);
358
359 /* start autoneg */
360 genphy_config_aneg(phydev);
361 genphy_restart_aneg(phydev);
362
363 return 0;
364 }
365
Marek Vasut22854bd2015-12-05 17:41:58 +0100366 return genphy_config(phydev);
367}
Stefano Babic9ced16f2013-09-02 15:42:31 +0200368
Marek Vasut6b5eea72023-03-19 18:02:56 +0100369U_BOOT_PHY_DRIVER(ksz9031) = {
David Andrey62d7dba2013-02-06 22:18:37 +0100370 .name = "Micrel ksz9031",
Philippe Schenker0861aa82020-03-11 11:59:22 +0100371 .uid = PHY_ID_KSZ9031,
372 .mask = MII_KSZ9x31_SILICON_REV_MASK,
David Andrey62d7dba2013-02-06 22:18:37 +0100373 .features = PHY_GBIT_FEATURES,
Marek Vasut22854bd2015-12-05 17:41:58 +0100374 .config = &ksz9031_config,
David Andrey62d7dba2013-02-06 22:18:37 +0100375 .startup = &ksz90xx_startup,
376 .shutdown = &genphy_shutdown,
Stefano Babic9ced16f2013-09-02 15:42:31 +0200377 .writeext = &ksz9031_phy_extwrite,
378 .readext = &ksz9031_phy_extread,
David Andrey62d7dba2013-02-06 22:18:37 +0100379};
380
Philippe Schenkerc51eef52020-03-11 11:59:23 +0100381/*
382 * KSZ9131
383 */
Claudiu Bezneac6df0e22020-12-03 11:18:30 +0200384
385#define KSZ9131RN_MMD_COMMON_CTRL_REG 2
386#define KSZ9131RN_RXC_DLL_CTRL 76
387#define KSZ9131RN_TXC_DLL_CTRL 77
388#define KSZ9131RN_DLL_CTRL_BYPASS BIT_MASK(12)
389#define KSZ9131RN_DLL_ENABLE_DELAY 0
390#define KSZ9131RN_DLL_DISABLE_DELAY BIT(12)
391
392static int ksz9131_config_rgmii_delay(struct phy_device *phydev)
393{
394 struct phy_driver *drv = phydev->drv;
395 u16 rxcdll_val, txcdll_val, val;
396 int ret;
397
398 switch (phydev->interface) {
399 case PHY_INTERFACE_MODE_RGMII:
400 rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
401 txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
402 break;
403 case PHY_INTERFACE_MODE_RGMII_ID:
404 rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
405 txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
406 break;
407 case PHY_INTERFACE_MODE_RGMII_RXID:
408 rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
409 txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
410 break;
411 case PHY_INTERFACE_MODE_RGMII_TXID:
412 rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
413 txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
414 break;
415 default:
416 return 0;
417 }
418
419 val = drv->readext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
420 KSZ9131RN_RXC_DLL_CTRL);
421 val &= ~KSZ9131RN_DLL_CTRL_BYPASS;
422 val |= rxcdll_val;
423 ret = drv->writeext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
424 KSZ9131RN_RXC_DLL_CTRL, val);
425 if (ret)
426 return ret;
427
428 val = drv->readext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
429 KSZ9131RN_TXC_DLL_CTRL);
430
431 val &= ~KSZ9131RN_DLL_CTRL_BYPASS;
432 val |= txcdll_val;
433 ret = drv->writeext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
434 KSZ9131RN_TXC_DLL_CTRL, val);
435
436 return ret;
437}
438
Philippe Schenkerc51eef52020-03-11 11:59:23 +0100439static int ksz9131_config(struct phy_device *phydev)
440{
Claudiu Bezneac6df0e22020-12-03 11:18:30 +0200441 int ret;
442
443 if (phy_interface_is_rgmii(phydev)) {
444 ret = ksz9131_config_rgmii_delay(phydev);
445 if (ret)
446 return ret;
447 }
Philippe Schenkerc51eef52020-03-11 11:59:23 +0100448
449 /* add an option to disable the gigabit feature of this PHY */
450 if (env_get("disable_giga")) {
451 unsigned features;
452 unsigned bmcr;
453
454 /* disable speed 1000 in features supported by the PHY */
455 features = phydev->drv->features;
456 features &= ~(SUPPORTED_1000baseT_Half |
457 SUPPORTED_1000baseT_Full);
458 phydev->advertising = phydev->supported = features;
459
460 /* disable speed 1000 in Basic Control Register */
461 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
462 bmcr &= ~(1 << 6);
463 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr);
464
465 /* disable speed 1000 in 1000Base-T Control Register */
466 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0);
467
468 /* start autoneg */
469 genphy_config_aneg(phydev);
470 genphy_restart_aneg(phydev);
471
472 return 0;
473 }
474
475 return genphy_config(phydev);
476}
477
Marek Vasut6b5eea72023-03-19 18:02:56 +0100478U_BOOT_PHY_DRIVER(ksz9131) = {
Claudiu Beznea36dfddc2020-12-03 11:18:31 +0200479 .name = "Micrel ksz9131",
Philippe Schenkerc51eef52020-03-11 11:59:23 +0100480 .uid = PHY_ID_KSZ9131,
481 .mask = MII_KSZ9x31_SILICON_REV_MASK,
482 .features = PHY_GBIT_FEATURES,
483 .config = &ksz9131_config,
484 .startup = &ksz90xx_startup,
485 .shutdown = &genphy_shutdown,
486 .writeext = &ksz9031_phy_extwrite,
487 .readext = &ksz9031_phy_extread,
488};
489
490int ksz9xx1_phy_get_id(struct phy_device *phydev)
491{
492 unsigned int phyid;
493
494 get_phy_id(phydev->bus, phydev->addr, MDIO_DEVAD_NONE, &phyid);
495
496 return phyid;
497}