blob: 556d75e31ede027e38d753dd8bc20744079b393b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming60ca78b2011-04-07 21:56:05 -05002/*
3 * Micrel PHY drivers
4 *
Andy Fleming60ca78b2011-04-07 21:56:05 -05005 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
David Andreyf0d83c42013-02-06 22:18:37 +01007 * (C) 2012 NetModule AG, David Andrey, added KSZ9031
Alexandru Gagniuc757bb672017-07-07 11:36:57 -07008 * (C) Copyright 2017 Adaptrum, Inc.
9 * Written by Alexandru Gagniuc <alex.g@adaptrum.com> for Adaptrum, Inc.
Andy Fleming60ca78b2011-04-07 21:56:05 -050010 */
Marek Vasut1005ce52015-12-05 17:41:58 +010011#include <dm.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060012#include <env.h>
Marek Vasut1005ce52015-12-05 17:41:58 +010013#include <errno.h>
Troy Kisky80b6b092012-02-07 14:08:48 +000014#include <micrel.h>
Andy Fleming60ca78b2011-04-07 21:56:05 -050015#include <phy.h>
16
Pavel Machek5f022112014-09-09 14:26:51 +020017/*
David Andreyf0d83c42013-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 Gagniuc757bb672017-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 Byrne457107f2019-03-04 17:40:33 +000036#define KSZ9021_PS_TO_REG 120
37
Alexandru Gagniuc757bb672017-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 Byrne457107f2019-03-04 17:40:33 +000042#define KSZ9031_PS_TO_REG 60
43
David Andreyf0d83c42013-02-06 22:18:37 +010044static int ksz90xx_startup(struct phy_device *phydev)
45{
46 unsigned phy_ctl;
Michal Simek5ff89662016-05-18 12:46:12 +020047 int ret;
48
49 ret = genphy_update_link(phydev);
50 if (ret)
51 return ret;
52
David Andreyf0d83c42013-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 Andreyf0d83c42013-02-06 22:18:37 +010068
Marek Vasut1005ce52015-12-05 17:41:58 +010069/* Common OF config bits for KSZ9021 and KSZ9031 */
Marek Vasut1005ce52015-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 Gagniuc757bb672017-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 Vasut1005ce52015-12-05 17:41:58 +0100107static int ksz90x1_of_config_group(struct phy_device *phydev,
James Byrne457107f2019-03-04 17:40:33 +0000108 struct ksz90x1_ofcfg *ofcfg,
109 int ps_to_regval)
Marek Vasut1005ce52015-12-05 17:41:58 +0100110{
111 struct udevice *dev = phydev->dev;
112 struct phy_driver *drv = phydev->drv;
Marek Vasut1005ce52015-12-05 17:41:58 +0100113 int val[4];
114 int i, changed = 0, offset, max;
115 u16 regval = 0;
James Byrne9e791442019-03-04 17:40:34 +0000116 ofnode node;
Marek Vasut1005ce52015-12-05 17:41:58 +0100117
118 if (!drv || !drv->writeext)
119 return -EOPNOTSUPP;
120
Marek Vasut7bbc25b2021-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 Byrne9e791442019-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 Vasut1005ce52015-12-05 17:41:58 +0100133 for (i = 0; i < ofcfg->grpsz; i++) {
James Byrne9e791442019-03-04 17:40:34 +0000134 val[i] = ofnode_read_u32_default(node, ofcfg->grp[i].name, ~0);
Marek Vasut1005ce52015-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 Pretzschf7c689d2018-11-29 20:04:53 +0100142 max = (1 << ofcfg->grp[i].size) - 1;
143 if (val[i] > ps_to_regval * max) {
Marek Vasut1005ce52015-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 Vasut1005ce52015-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 Vasut0c766302016-11-14 15:08:42 +0100166 for (i = 0; i < ARRAY_SIZE(ofcfg); i++) {
James Byrne457107f2019-03-04 17:40:33 +0000167 ret = ksz90x1_of_config_group(phydev, &ofcfg[i],
168 KSZ9021_PS_TO_REG);
Marek Vasut1005ce52015-12-05 17:41:58 +0100169 if (ret)
170 return ret;
Marek Vasut0c766302016-11-14 15:08:42 +0100171 }
Marek Vasut1005ce52015-12-05 17:41:58 +0100172
173 return 0;
174}
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700175
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
186 for (i = 0; i < ARRAY_SIZE(ofcfg); i++) {
James Byrne457107f2019-03-04 17:40:33 +0000187 ret = ksz90x1_of_config_group(phydev, &ofcfg[i],
188 KSZ9031_PS_TO_REG);
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700189 if (ret)
190 return ret;
191 }
192
193 return 0;
194}
195
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}
211
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700212/*
213 * KSZ9021
214 */
Troy Kisky80b6b092012-02-07 14:08:48 +0000215int ksz9021_phy_extended_write(struct phy_device *phydev, int regnum, u16 val)
216{
217 /* extended registers */
218 phy_write(phydev, MDIO_DEVAD_NONE,
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700219 MII_KSZ9021_EXTENDED_CTRL, regnum | 0x8000);
Troy Kisky80b6b092012-02-07 14:08:48 +0000220 return phy_write(phydev, MDIO_DEVAD_NONE,
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700221 MII_KSZ9021_EXTENDED_DATAW, val);
Troy Kisky80b6b092012-02-07 14:08:48 +0000222}
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
Stefano Babica8aa2992013-09-02 15:42:31 +0200231
232static int ksz9021_phy_extread(struct phy_device *phydev, int addr, int devaddr,
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700233 int regnum)
Stefano Babica8aa2992013-09-02 15:42:31 +0200234{
235 return ksz9021_phy_extended_read(phydev, regnum);
236}
237
238static int ksz9021_phy_extwrite(struct phy_device *phydev, int addr,
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700239 int devaddr, int regnum, u16 val)
Stefano Babica8aa2992013-09-02 15:42:31 +0200240{
241 return ksz9021_phy_extended_write(phydev, regnum, val);
242}
243
Troy Kisky80b6b092012-02-07 14:08:48 +0000244static int ksz9021_config(struct phy_device *phydev)
245{
246 unsigned ctrl1000 = 0;
247 const unsigned master = CTRL1000_PREFER_MASTER |
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700248 CTRL1000_CONFIG_MASTER | CTRL1000_MANUAL_CONFIG;
Troy Kisky80b6b092012-02-07 14:08:48 +0000249 unsigned features = phydev->drv->features;
Marek Vasut1005ce52015-12-05 17:41:58 +0100250 int ret;
251
252 ret = ksz9021_of_config(phydev);
253 if (ret)
254 return ret;
Troy Kisky80b6b092012-02-07 14:08:48 +0000255
Simon Glass64b723f2017-08-03 12:22:12 -0600256 if (env_get("disable_giga"))
Troy Kisky80b6b092012-02-07 14:08:48 +0000257 features &= ~(SUPPORTED_1000baseT_Half |
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700258 SUPPORTED_1000baseT_Full);
Troy Kisky80b6b092012-02-07 14:08:48 +0000259 /* force master mode for 1000BaseT due to chip errata */
260 if (features & SUPPORTED_1000baseT_Half)
261 ctrl1000 |= ADVERTISE_1000HALF | master;
262 if (features & SUPPORTED_1000baseT_Full)
263 ctrl1000 |= ADVERTISE_1000FULL | master;
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700264 phydev->advertising = features;
265 phydev->supported = features;
Troy Kisky80b6b092012-02-07 14:08:48 +0000266 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, ctrl1000);
267 genphy_config_aneg(phydev);
268 genphy_restart_aneg(phydev);
269 return 0;
270}
271
Marek Vasutce250e92023-03-19 18:02:56 +0100272U_BOOT_PHY_DRIVER(ksz9021) = {
Troy Kisky80b6b092012-02-07 14:08:48 +0000273 .name = "Micrel ksz9021",
274 .uid = 0x221610,
James Byrnebc292c22019-03-06 12:48:27 +0000275 .mask = 0xfffffe,
Troy Kisky80b6b092012-02-07 14:08:48 +0000276 .features = PHY_GBIT_FEATURES,
277 .config = &ksz9021_config,
David Andreyf0d83c42013-02-06 22:18:37 +0100278 .startup = &ksz90xx_startup,
Troy Kisky80b6b092012-02-07 14:08:48 +0000279 .shutdown = &genphy_shutdown,
Stefano Babica8aa2992013-09-02 15:42:31 +0200280 .writeext = &ksz9021_phy_extwrite,
281 .readext = &ksz9021_phy_extread,
Troy Kisky80b6b092012-02-07 14:08:48 +0000282};
283
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700284/*
David Andreyf0d83c42013-02-06 22:18:37 +0100285 * KSZ9031
286 */
SARTRE Leoeaf68ac2013-04-30 16:57:25 +0200287int ksz9031_phy_extended_write(struct phy_device *phydev,
288 int devaddr, int regnum, u16 mode, u16 val)
289{
290 /*select register addr for mmd*/
291 phy_write(phydev, MDIO_DEVAD_NONE,
292 MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
293 /*select register for mmd*/
294 phy_write(phydev, MDIO_DEVAD_NONE,
295 MII_KSZ9031_MMD_REG_DATA, regnum);
296 /*setup mode*/
297 phy_write(phydev, MDIO_DEVAD_NONE,
298 MII_KSZ9031_MMD_ACCES_CTRL, (mode | devaddr));
299 /*write the value*/
300 return phy_write(phydev, MDIO_DEVAD_NONE,
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700301 MII_KSZ9031_MMD_REG_DATA, val);
SARTRE Leoeaf68ac2013-04-30 16:57:25 +0200302}
303
304int ksz9031_phy_extended_read(struct phy_device *phydev, int devaddr,
305 int regnum, u16 mode)
306{
307 phy_write(phydev, MDIO_DEVAD_NONE,
308 MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
309 phy_write(phydev, MDIO_DEVAD_NONE,
310 MII_KSZ9031_MMD_REG_DATA, regnum);
311 phy_write(phydev, MDIO_DEVAD_NONE,
312 MII_KSZ9031_MMD_ACCES_CTRL, (devaddr | mode));
313 return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9031_MMD_REG_DATA);
314}
315
Stefano Babica8aa2992013-09-02 15:42:31 +0200316static int ksz9031_phy_extread(struct phy_device *phydev, int addr, int devaddr,
317 int regnum)
318{
319 return ksz9031_phy_extended_read(phydev, devaddr, regnum,
320 MII_KSZ9031_MOD_DATA_NO_POST_INC);
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700321}
Stefano Babica8aa2992013-09-02 15:42:31 +0200322
323static int ksz9031_phy_extwrite(struct phy_device *phydev, int addr,
324 int devaddr, int regnum, u16 val)
325{
326 return ksz9031_phy_extended_write(phydev, devaddr, regnum,
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700327 MII_KSZ9031_MOD_DATA_POST_INC_RW, val);
328}
Stefano Babica8aa2992013-09-02 15:42:31 +0200329
Marek Vasut1005ce52015-12-05 17:41:58 +0100330static int ksz9031_config(struct phy_device *phydev)
331{
332 int ret;
Sebastien Bourdelin3a6e0332017-07-28 15:59:22 -0400333
Marek Vasut1005ce52015-12-05 17:41:58 +0100334 ret = ksz9031_of_config(phydev);
335 if (ret)
336 return ret;
Ash Charles3f55bb62016-10-21 17:31:33 -0400337 ret = ksz9031_center_flp_timing(phydev);
338 if (ret)
339 return ret;
Sebastien Bourdelin3a6e0332017-07-28 15:59:22 -0400340
341 /* add an option to disable the gigabit feature of this PHY */
Simon Glass64b723f2017-08-03 12:22:12 -0600342 if (env_get("disable_giga")) {
Sebastien Bourdelin3a6e0332017-07-28 15:59:22 -0400343 unsigned features;
344 unsigned bmcr;
345
346 /* disable speed 1000 in features supported by the PHY */
347 features = phydev->drv->features;
348 features &= ~(SUPPORTED_1000baseT_Half |
349 SUPPORTED_1000baseT_Full);
350 phydev->advertising = phydev->supported = features;
351
352 /* disable speed 1000 in Basic Control Register */
353 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
354 bmcr &= ~(1 << 6);
355 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr);
356
357 /* disable speed 1000 in 1000Base-T Control Register */
358 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0);
359
360 /* start autoneg */
361 genphy_config_aneg(phydev);
362 genphy_restart_aneg(phydev);
363
364 return 0;
365 }
366
Marek Vasut1005ce52015-12-05 17:41:58 +0100367 return genphy_config(phydev);
368}
Stefano Babica8aa2992013-09-02 15:42:31 +0200369
Marek Vasutce250e92023-03-19 18:02:56 +0100370U_BOOT_PHY_DRIVER(ksz9031) = {
David Andreyf0d83c42013-02-06 22:18:37 +0100371 .name = "Micrel ksz9031",
Philippe Schenkerbe988372020-03-11 11:59:22 +0100372 .uid = PHY_ID_KSZ9031,
373 .mask = MII_KSZ9x31_SILICON_REV_MASK,
David Andreyf0d83c42013-02-06 22:18:37 +0100374 .features = PHY_GBIT_FEATURES,
Marek Vasut1005ce52015-12-05 17:41:58 +0100375 .config = &ksz9031_config,
David Andreyf0d83c42013-02-06 22:18:37 +0100376 .startup = &ksz90xx_startup,
377 .shutdown = &genphy_shutdown,
Stefano Babica8aa2992013-09-02 15:42:31 +0200378 .writeext = &ksz9031_phy_extwrite,
379 .readext = &ksz9031_phy_extread,
David Andreyf0d83c42013-02-06 22:18:37 +0100380};
381
Philippe Schenker3060ecc2020-03-11 11:59:23 +0100382/*
383 * KSZ9131
384 */
Claudiu Beznea840a6b02020-12-03 11:18:30 +0200385
386#define KSZ9131RN_MMD_COMMON_CTRL_REG 2
387#define KSZ9131RN_RXC_DLL_CTRL 76
388#define KSZ9131RN_TXC_DLL_CTRL 77
389#define KSZ9131RN_DLL_CTRL_BYPASS BIT_MASK(12)
390#define KSZ9131RN_DLL_ENABLE_DELAY 0
391#define KSZ9131RN_DLL_DISABLE_DELAY BIT(12)
392
393static int ksz9131_config_rgmii_delay(struct phy_device *phydev)
394{
395 struct phy_driver *drv = phydev->drv;
396 u16 rxcdll_val, txcdll_val, val;
397 int ret;
398
399 switch (phydev->interface) {
400 case PHY_INTERFACE_MODE_RGMII:
401 rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
402 txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
403 break;
404 case PHY_INTERFACE_MODE_RGMII_ID:
405 rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
406 txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
407 break;
408 case PHY_INTERFACE_MODE_RGMII_RXID:
409 rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
410 txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
411 break;
412 case PHY_INTERFACE_MODE_RGMII_TXID:
413 rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY;
414 txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY;
415 break;
416 default:
417 return 0;
418 }
419
420 val = drv->readext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
421 KSZ9131RN_RXC_DLL_CTRL);
422 val &= ~KSZ9131RN_DLL_CTRL_BYPASS;
423 val |= rxcdll_val;
424 ret = drv->writeext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
425 KSZ9131RN_RXC_DLL_CTRL, val);
426 if (ret)
427 return ret;
428
429 val = drv->readext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
430 KSZ9131RN_TXC_DLL_CTRL);
431
432 val &= ~KSZ9131RN_DLL_CTRL_BYPASS;
433 val |= txcdll_val;
434 ret = drv->writeext(phydev, 0, KSZ9131RN_MMD_COMMON_CTRL_REG,
435 KSZ9131RN_TXC_DLL_CTRL, val);
436
437 return ret;
438}
439
Philippe Schenker3060ecc2020-03-11 11:59:23 +0100440static int ksz9131_config(struct phy_device *phydev)
441{
Claudiu Beznea840a6b02020-12-03 11:18:30 +0200442 int ret;
443
444 if (phy_interface_is_rgmii(phydev)) {
445 ret = ksz9131_config_rgmii_delay(phydev);
446 if (ret)
447 return ret;
448 }
Philippe Schenker3060ecc2020-03-11 11:59:23 +0100449
450 /* add an option to disable the gigabit feature of this PHY */
451 if (env_get("disable_giga")) {
452 unsigned features;
453 unsigned bmcr;
454
455 /* disable speed 1000 in features supported by the PHY */
456 features = phydev->drv->features;
457 features &= ~(SUPPORTED_1000baseT_Half |
458 SUPPORTED_1000baseT_Full);
459 phydev->advertising = phydev->supported = features;
460
461 /* disable speed 1000 in Basic Control Register */
462 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
463 bmcr &= ~(1 << 6);
464 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr);
465
466 /* disable speed 1000 in 1000Base-T Control Register */
467 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, 0);
468
469 /* start autoneg */
470 genphy_config_aneg(phydev);
471 genphy_restart_aneg(phydev);
472
473 return 0;
474 }
475
476 return genphy_config(phydev);
477}
478
Marek Vasutce250e92023-03-19 18:02:56 +0100479U_BOOT_PHY_DRIVER(ksz9131) = {
Claudiu Beznea3f1606f2020-12-03 11:18:31 +0200480 .name = "Micrel ksz9131",
Philippe Schenker3060ecc2020-03-11 11:59:23 +0100481 .uid = PHY_ID_KSZ9131,
482 .mask = MII_KSZ9x31_SILICON_REV_MASK,
483 .features = PHY_GBIT_FEATURES,
484 .config = &ksz9131_config,
485 .startup = &ksz90xx_startup,
486 .shutdown = &genphy_shutdown,
487 .writeext = &ksz9031_phy_extwrite,
488 .readext = &ksz9031_phy_extread,
489};
490
491int ksz9xx1_phy_get_id(struct phy_device *phydev)
492{
493 unsigned int phyid;
494
495 get_phy_id(phydev->bus, phydev->addr, MDIO_DEVAD_NONE, &phyid);
496
497 return phyid;
498}