blob: 0a90f710dfe49701d7b4a12605c5b34ec3d09f4c [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 * Marvell PHY drivers
4 *
Andy Fleming9082eea2011-04-07 21:56:05 -05005 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
Andy Fleming9082eea2011-04-07 21:56:05 -05007 */
Andy Fleming9082eea2011-04-07 21:56:05 -05008#include <common.h>
Simon Glassfbfa1ab2016-07-05 17:10:12 -06009#include <errno.h>
Marek Vasutbf3dabb2023-03-19 18:08:06 +010010#include <marvell_phy.h>
Andy Fleming9082eea2011-04-07 21:56:05 -050011#include <phy.h>
Simon Glasscd93d622020-05-10 11:40:13 -060012#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060013#include <linux/delay.h>
Andy Fleming9082eea2011-04-07 21:56:05 -050014
15#define PHY_AUTONEGOTIATE_TIMEOUT 5000
16
Phil Edworthy68e6eca2017-05-24 14:43:06 +010017#define MII_MARVELL_PHY_PAGE 22
18
Andy Fleming9082eea2011-04-07 21:56:05 -050019/* 88E1011 PHY Status Register */
20#define MIIM_88E1xxx_PHY_STATUS 0x11
21#define MIIM_88E1xxx_PHYSTAT_SPEED 0xc000
22#define MIIM_88E1xxx_PHYSTAT_GBIT 0x8000
23#define MIIM_88E1xxx_PHYSTAT_100 0x4000
24#define MIIM_88E1xxx_PHYSTAT_DUPLEX 0x2000
25#define MIIM_88E1xxx_PHYSTAT_SPDDONE 0x0800
26#define MIIM_88E1xxx_PHYSTAT_LINK 0x0400
27
28#define MIIM_88E1xxx_PHY_SCR 0x10
29#define MIIM_88E1xxx_PHY_MDI_X_AUTO 0x0060
30
31/* 88E1111 PHY LED Control Register */
32#define MIIM_88E1111_PHY_LED_CONTROL 24
33#define MIIM_88E1111_PHY_LED_DIRECT 0x4100
34#define MIIM_88E1111_PHY_LED_COMBINE 0x411C
35
Zang Roy-R61911fa12a082011-10-27 18:52:09 +000036/* 88E1111 Extended PHY Specific Control Register */
37#define MIIM_88E1111_PHY_EXT_CR 0x14
38#define MIIM_88E1111_RX_DELAY 0x80
39#define MIIM_88E1111_TX_DELAY 0x2
40
41/* 88E1111 Extended PHY Specific Status Register */
42#define MIIM_88E1111_PHY_EXT_SR 0x1b
43#define MIIM_88E1111_HWCFG_MODE_MASK 0xf
44#define MIIM_88E1111_HWCFG_MODE_COPPER_RGMII 0xb
45#define MIIM_88E1111_HWCFG_MODE_FIBER_RGMII 0x3
46#define MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK 0x4
47#define MIIM_88E1111_HWCFG_MODE_COPPER_RTBI 0x9
48#define MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO 0x8000
49#define MIIM_88E1111_HWCFG_FIBER_COPPER_RES 0x2000
50
51#define MIIM_88E1111_COPPER 0
52#define MIIM_88E1111_FIBER 1
53
Andy Fleming9082eea2011-04-07 21:56:05 -050054/* 88E1118 PHY defines */
55#define MIIM_88E1118_PHY_PAGE 22
56#define MIIM_88E1118_PHY_LED_PAGE 3
57
58/* 88E1121 PHY LED Control Register */
59#define MIIM_88E1121_PHY_LED_CTRL 16
60#define MIIM_88E1121_PHY_LED_PAGE 3
61#define MIIM_88E1121_PHY_LED_DEF 0x0030
62
63/* 88E1121 PHY IRQ Enable/Status Register */
64#define MIIM_88E1121_PHY_IRQ_EN 18
65#define MIIM_88E1121_PHY_IRQ_STATUS 19
66
67#define MIIM_88E1121_PHY_PAGE 22
68
69/* 88E1145 Extended PHY Specific Control Register */
70#define MIIM_88E1145_PHY_EXT_CR 20
71#define MIIM_M88E1145_RGMII_RX_DELAY 0x0080
72#define MIIM_M88E1145_RGMII_TX_DELAY 0x0002
73
74#define MIIM_88E1145_PHY_LED_CONTROL 24
75#define MIIM_88E1145_PHY_LED_DIRECT 0x4100
76
77#define MIIM_88E1145_PHY_PAGE 29
78#define MIIM_88E1145_PHY_CAL_OV 30
79
80#define MIIM_88E1149_PHY_PAGE 29
81
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +010082/* 88E1310 PHY defines */
83#define MIIM_88E1310_PHY_LED_CTRL 16
84#define MIIM_88E1310_PHY_IRQ_EN 18
85#define MIIM_88E1310_PHY_RGMII_CTRL 21
86#define MIIM_88E1310_PHY_PAGE 22
87
Joe Hershberger93cc2952016-12-09 11:54:39 -060088/* 88E151x PHY defines */
Phil Edworthy68e6eca2017-05-24 14:43:06 +010089/* Page 2 registers */
90#define MIIM_88E151x_PHY_MSCR 21
91#define MIIM_88E151x_RGMII_RX_DELAY BIT(5)
92#define MIIM_88E151x_RGMII_TX_DELAY BIT(4)
93#define MIIM_88E151x_RGMII_RXTX_DELAY (BIT(5) | BIT(4))
Joe Hershberger93cc2952016-12-09 11:54:39 -060094/* Page 3 registers */
95#define MIIM_88E151x_LED_FUNC_CTRL 16
96#define MIIM_88E151x_LED_FLD_SZ 4
97#define MIIM_88E151x_LED0_OFFS (0 * MIIM_88E151x_LED_FLD_SZ)
98#define MIIM_88E151x_LED1_OFFS (1 * MIIM_88E151x_LED_FLD_SZ)
99#define MIIM_88E151x_LED0_ACT 3
100#define MIIM_88E151x_LED1_100_1000_LINK 6
101#define MIIM_88E151x_LED_TIMER_CTRL 18
102#define MIIM_88E151x_INT_EN_OFFS 7
103/* Page 18 registers */
104#define MIIM_88E151x_GENERAL_CTRL 20
105#define MIIM_88E151x_MODE_SGMII 1
106#define MIIM_88E151x_RESET_OFFS 15
107
Stefan Roese0ef02612022-03-31 11:43:06 +0200108static int marvell_read_page(struct phy_device *phydev)
109{
110 return phy_read(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE);
111}
112
113static int marvell_write_page(struct phy_device *phydev, int page)
114{
115 return phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, page);
116}
117
118/* Set and/or override some configuration registers based on the
119 * marvell,reg-init property stored in the of_node for the phydev.
120 *
121 * marvell,reg-init = <reg-page reg mask value>,...;
122 *
123 * There may be one or more sets of <reg-page reg mask value>:
124 *
125 * reg-page: which register bank to use.
126 * reg: the register.
127 * mask: if non-zero, ANDed with existing register value.
128 * value: ORed with the masked value and written to the regiser.
129 *
130 */
131static int marvell_of_reg_init(struct phy_device *phydev)
132{
133 const __be32 *prop;
134 int len, i, saved_page, current_page, ret = 0;
135
136 if (!ofnode_valid(phydev->node))
137 return 0;
138
139 prop = ofnode_get_property(phydev->node, "marvell,reg-init", &len);
140 if (!prop)
141 return 0;
142
143 saved_page = marvell_read_page(phydev);
144 if (saved_page < 0)
145 goto err;
146 current_page = saved_page;
147
148 len /= sizeof(*prop);
149 for (i = 0; i < len - 3; i += 4) {
150 u16 page = be32_to_cpup(prop + i);
151 u16 reg = be32_to_cpup(prop + i + 1);
152 u16 mask = be32_to_cpup(prop + i + 2);
153 u16 val_bits = be32_to_cpup(prop + i + 3);
154 int val;
155
156 if (page != current_page) {
157 current_page = page;
158 ret = marvell_write_page(phydev, page);
159 if (ret < 0)
160 goto err;
161 }
162
163 val = 0;
164 if (mask) {
165 val = phy_read(phydev, MDIO_DEVAD_NONE, reg);
166 if (val < 0) {
167 ret = val;
168 goto err;
169 }
170 val &= mask;
171 }
172 val |= val_bits;
173
174 ret = phy_write(phydev, MDIO_DEVAD_NONE, reg, val);
175 if (ret < 0)
176 goto err;
177 }
178
179err:
180 return marvell_write_page(phydev, saved_page);
181}
Stefan Roese0ef02612022-03-31 11:43:06 +0200182
Lukasz Majewskice27eb92017-10-30 22:57:53 +0100183static int m88e1xxx_phy_extread(struct phy_device *phydev, int addr,
184 int devaddr, int regnum)
185{
186 int oldpage = phy_read(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE);
187 int val;
188
189 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, devaddr);
190 val = phy_read(phydev, MDIO_DEVAD_NONE, regnum);
191 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, oldpage);
192
193 return val;
194}
195
196static int m88e1xxx_phy_extwrite(struct phy_device *phydev, int addr,
197 int devaddr, int regnum, u16 val)
198{
199 int oldpage = phy_read(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE);
200
201 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, devaddr);
202 phy_write(phydev, MDIO_DEVAD_NONE, regnum, val);
203 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, oldpage);
204
205 return 0;
206}
207
Andy Fleming9082eea2011-04-07 21:56:05 -0500208/* Marvell 88E1011S */
209static int m88e1011s_config(struct phy_device *phydev)
210{
211 /* Reset and configure the PHY */
212 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
213
214 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
215 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x200c);
216 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
217 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0);
218 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
219
220 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
221
Stefan Roese0ef02612022-03-31 11:43:06 +0200222 marvell_of_reg_init(phydev);
223
Andy Fleming9082eea2011-04-07 21:56:05 -0500224 genphy_config_aneg(phydev);
225
226 return 0;
227}
228
229/* Parse the 88E1011's status register for speed and duplex
230 * information
231 */
Michal Simekef5e8212016-05-18 12:48:57 +0200232static int m88e1xxx_parse_status(struct phy_device *phydev)
Andy Fleming9082eea2011-04-07 21:56:05 -0500233{
234 unsigned int speed;
235 unsigned int mii_reg;
236
237 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_STATUS);
238
239 if ((mii_reg & MIIM_88E1xxx_PHYSTAT_LINK) &&
Mario Six76f11d32018-01-15 11:08:24 +0100240 !(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) {
Andy Fleming9082eea2011-04-07 21:56:05 -0500241 int i = 0;
242
243 puts("Waiting for PHY realtime link");
244 while (!(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) {
245 /* Timeout reached ? */
246 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
247 puts(" TIMEOUT !\n");
248 phydev->link = 0;
Michal Simekef5e8212016-05-18 12:48:57 +0200249 return -ETIMEDOUT;
Andy Fleming9082eea2011-04-07 21:56:05 -0500250 }
251
252 if ((i++ % 1000) == 0)
253 putc('.');
254 udelay(1000);
255 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE,
Mario Six76f11d32018-01-15 11:08:24 +0100256 MIIM_88E1xxx_PHY_STATUS);
Andy Fleming9082eea2011-04-07 21:56:05 -0500257 }
258 puts(" done\n");
Mario Six76f11d32018-01-15 11:08:24 +0100259 mdelay(500); /* another 500 ms (results in faster booting) */
Andy Fleming9082eea2011-04-07 21:56:05 -0500260 } else {
261 if (mii_reg & MIIM_88E1xxx_PHYSTAT_LINK)
262 phydev->link = 1;
263 else
264 phydev->link = 0;
265 }
266
267 if (mii_reg & MIIM_88E1xxx_PHYSTAT_DUPLEX)
268 phydev->duplex = DUPLEX_FULL;
269 else
270 phydev->duplex = DUPLEX_HALF;
271
272 speed = mii_reg & MIIM_88E1xxx_PHYSTAT_SPEED;
273
274 switch (speed) {
275 case MIIM_88E1xxx_PHYSTAT_GBIT:
276 phydev->speed = SPEED_1000;
277 break;
278 case MIIM_88E1xxx_PHYSTAT_100:
279 phydev->speed = SPEED_100;
280 break;
281 default:
282 phydev->speed = SPEED_10;
283 break;
284 }
285
286 return 0;
287}
288
289static int m88e1011s_startup(struct phy_device *phydev)
290{
Michal Simekb733c272016-05-18 12:46:12 +0200291 int ret;
Andy Fleming9082eea2011-04-07 21:56:05 -0500292
Michal Simekb733c272016-05-18 12:46:12 +0200293 ret = genphy_update_link(phydev);
294 if (ret)
295 return ret;
296
297 return m88e1xxx_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500298}
299
300/* Marvell 88E1111S */
301static int m88e1111s_config(struct phy_device *phydev)
302{
303 int reg;
304
Phil Edworthy24d98cb2016-12-12 12:54:15 +0000305 if (phy_interface_is_rgmii(phydev)) {
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000306 reg = phy_read(phydev,
Mario Six76f11d32018-01-15 11:08:24 +0100307 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000308 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
Mario Six76f11d32018-01-15 11:08:24 +0100309 (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) {
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000310 reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY);
311 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
312 reg &= ~MIIM_88E1111_TX_DELAY;
313 reg |= MIIM_88E1111_RX_DELAY;
314 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
315 reg &= ~MIIM_88E1111_RX_DELAY;
316 reg |= MIIM_88E1111_TX_DELAY;
317 }
318
319 phy_write(phydev,
Mario Six76f11d32018-01-15 11:08:24 +0100320 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000321
322 reg = phy_read(phydev,
Mario Six76f11d32018-01-15 11:08:24 +0100323 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000324
325 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
326
327 if (reg & MIIM_88E1111_HWCFG_FIBER_COPPER_RES)
328 reg |= MIIM_88E1111_HWCFG_MODE_FIBER_RGMII;
329 else
330 reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RGMII;
331
332 phy_write(phydev,
Mario Six76f11d32018-01-15 11:08:24 +0100333 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR, reg);
Andy Fleming9082eea2011-04-07 21:56:05 -0500334 }
335
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000336 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
337 reg = phy_read(phydev,
Mario Six76f11d32018-01-15 11:08:24 +0100338 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000339
340 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
341 reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK;
342 reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
343
344 phy_write(phydev, MDIO_DEVAD_NONE,
Mario Six76f11d32018-01-15 11:08:24 +0100345 MIIM_88E1111_PHY_EXT_SR, reg);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000346 }
347
348 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
349 reg = phy_read(phydev,
Mario Six76f11d32018-01-15 11:08:24 +0100350 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000351 reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY);
352 phy_write(phydev,
Mario Six76f11d32018-01-15 11:08:24 +0100353 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000354
355 reg = phy_read(phydev, MDIO_DEVAD_NONE,
Mario Six76f11d32018-01-15 11:08:24 +0100356 MIIM_88E1111_PHY_EXT_SR);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000357 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK |
358 MIIM_88E1111_HWCFG_FIBER_COPPER_RES);
359 reg |= 0x7 | MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
360 phy_write(phydev, MDIO_DEVAD_NONE,
Mario Six76f11d32018-01-15 11:08:24 +0100361 MIIM_88E1111_PHY_EXT_SR, reg);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000362
363 /* soft reset */
Stefan Roese3089c472016-02-10 07:06:05 +0100364 phy_reset(phydev);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000365
366 reg = phy_read(phydev, MDIO_DEVAD_NONE,
Mario Six76f11d32018-01-15 11:08:24 +0100367 MIIM_88E1111_PHY_EXT_SR);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000368 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK |
Mario Six76f11d32018-01-15 11:08:24 +0100369 MIIM_88E1111_HWCFG_FIBER_COPPER_RES);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000370 reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RTBI |
371 MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
372 phy_write(phydev, MDIO_DEVAD_NONE,
Mario Six76f11d32018-01-15 11:08:24 +0100373 MIIM_88E1111_PHY_EXT_SR, reg);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000374 }
375
376 /* soft reset */
Stefan Roese3089c472016-02-10 07:06:05 +0100377 phy_reset(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500378
Stefan Roese0ef02612022-03-31 11:43:06 +0200379 marvell_of_reg_init(phydev);
380
Andy Fleming9082eea2011-04-07 21:56:05 -0500381 genphy_config_aneg(phydev);
Stefan Roesea8c3eca2016-02-10 07:06:06 +0100382 genphy_restart_aneg(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500383
384 return 0;
385}
386
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200387/**
Clemens Gruber1c1f4f02020-02-24 20:52:20 +0100388 * m88e151x_phy_writebits - write bits to a register
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200389 */
Clemens Gruber1c1f4f02020-02-24 20:52:20 +0100390void m88e151x_phy_writebits(struct phy_device *phydev,
Mario Six76f11d32018-01-15 11:08:24 +0100391 u8 reg_num, u16 offset, u16 len, u16 data)
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200392{
393 u16 reg, mask;
394
395 if ((len + offset) >= 16)
396 mask = 0 - (1 << offset);
397 else
398 mask = (1 << (len + offset)) - (1 << offset);
399
400 reg = phy_read(phydev, MDIO_DEVAD_NONE, reg_num);
401
402 reg &= ~mask;
403 reg |= data << offset;
404
405 phy_write(phydev, MDIO_DEVAD_NONE, reg_num, reg);
406}
407
Clemens Gruber1c1f4f02020-02-24 20:52:20 +0100408static int m88e151x_config(struct phy_device *phydev)
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200409{
Phil Edworthy68e6eca2017-05-24 14:43:06 +0100410 u16 reg;
411
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200412 /*
413 * As per Marvell Release Notes - Alaska 88E1510/88E1518/88E1512
414 * /88E1514 Rev A0, Errata Section 3.1
415 */
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200416
417 /* EEE initialization */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600418 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00ff);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200419 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x214B);
420 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2144);
421 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x0C28);
422 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2146);
423 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xB233);
424 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x214D);
425 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xCC0C);
426 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2159);
Joe Hershberger93cc2952016-12-09 11:54:39 -0600427 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200428
429 /* SGMII-to-Copper mode initialization */
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200430 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200431 /* Select page 18 */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600432 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 18);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200433
434 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
Clemens Gruber1c1f4f02020-02-24 20:52:20 +0100435 m88e151x_phy_writebits(phydev, MIIM_88E151x_GENERAL_CTRL,
Joe Hershberger93cc2952016-12-09 11:54:39 -0600436 0, 3, MIIM_88E151x_MODE_SGMII);
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200437
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200438 /* PHY reset is necessary after changing MODE[2:0] */
Clemens Gruber1c1f4f02020-02-24 20:52:20 +0100439 m88e151x_phy_writebits(phydev, MIIM_88E151x_GENERAL_CTRL,
Joe Hershberger93cc2952016-12-09 11:54:39 -0600440 MIIM_88E151x_RESET_OFFS, 1, 1);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200441
442 /* Reset page selection */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600443 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200444
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200445 udelay(100);
446 }
447
Phil Edworthy68e6eca2017-05-24 14:43:06 +0100448 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
449 reg = phy_read(phydev, MDIO_DEVAD_NONE,
450 MIIM_88E1111_PHY_EXT_SR);
451
452 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
453 reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK;
454 reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
455
456 phy_write(phydev, MDIO_DEVAD_NONE,
457 MIIM_88E1111_PHY_EXT_SR, reg);
458 }
459
460 if (phy_interface_is_rgmii(phydev)) {
461 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, 2);
462
463 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR);
464 reg &= ~MIIM_88E151x_RGMII_RXTX_DELAY;
Mario Six431be622018-01-15 11:08:25 +0100465 if (phydev->interface == PHY_INTERFACE_MODE_RGMII ||
466 phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
Phil Edworthy68e6eca2017-05-24 14:43:06 +0100467 reg |= MIIM_88E151x_RGMII_RXTX_DELAY;
468 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
469 reg |= MIIM_88E151x_RGMII_RX_DELAY;
470 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
471 reg |= MIIM_88E151x_RGMII_TX_DELAY;
472 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR, reg);
473
474 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, 0);
475 }
476
477 /* soft reset */
478 phy_reset(phydev);
479
Stefan Roese0ef02612022-03-31 11:43:06 +0200480 marvell_of_reg_init(phydev);
481
Phil Edworthy68e6eca2017-05-24 14:43:06 +0100482 genphy_config_aneg(phydev);
483 genphy_restart_aneg(phydev);
484
485 return 0;
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200486}
487
Andy Fleming9082eea2011-04-07 21:56:05 -0500488/* Marvell 88E1118 */
489static int m88e1118_config(struct phy_device *phydev)
490{
491 /* Change Page Number */
492 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0002);
493 /* Delay RGMII TX and RX */
494 phy_write(phydev, MDIO_DEVAD_NONE, 0x15, 0x1070);
495 /* Change Page Number */
496 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0003);
497 /* Adjust LED control */
498 phy_write(phydev, MDIO_DEVAD_NONE, 0x10, 0x021e);
499 /* Change Page Number */
500 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
501
Stefan Roese0ef02612022-03-31 11:43:06 +0200502 marvell_of_reg_init(phydev);
503
Michal Simek1b008fd2016-05-18 14:46:28 +0200504 return genphy_config_aneg(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500505}
506
507static int m88e1118_startup(struct phy_device *phydev)
508{
Michal Simekb733c272016-05-18 12:46:12 +0200509 int ret;
510
Andy Fleming9082eea2011-04-07 21:56:05 -0500511 /* Change Page Number */
512 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
513
Michal Simekb733c272016-05-18 12:46:12 +0200514 ret = genphy_update_link(phydev);
515 if (ret)
516 return ret;
Andy Fleming9082eea2011-04-07 21:56:05 -0500517
Michal Simekb733c272016-05-18 12:46:12 +0200518 return m88e1xxx_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500519}
520
521/* Marvell 88E1121R */
522static int m88e1121_config(struct phy_device *phydev)
523{
524 int pg;
525
Stefan Roese0ef02612022-03-31 11:43:06 +0200526 marvell_of_reg_init(phydev);
527
Andy Fleming9082eea2011-04-07 21:56:05 -0500528 /* Configure the PHY */
529 genphy_config_aneg(phydev);
530
531 /* Switch the page to access the led register */
532 pg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE);
533 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE,
Mario Six76f11d32018-01-15 11:08:24 +0100534 MIIM_88E1121_PHY_LED_PAGE);
Andy Fleming9082eea2011-04-07 21:56:05 -0500535 /* Configure leds */
536 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_LED_CTRL,
Mario Six76f11d32018-01-15 11:08:24 +0100537 MIIM_88E1121_PHY_LED_DEF);
Andy Fleming9082eea2011-04-07 21:56:05 -0500538 /* Restore the page pointer */
539 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE, pg);
540
541 /* Disable IRQs and de-assert interrupt */
542 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_IRQ_EN, 0);
543 phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_IRQ_STATUS);
544
545 return 0;
546}
547
548/* Marvell 88E1145 */
549static int m88e1145_config(struct phy_device *phydev)
550{
551 int reg;
552
553 /* Errata E0, E1 */
554 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_PAGE, 0x001b);
555 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0x418f);
556 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_PAGE, 0x0016);
557 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0xa2da);
558
559 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_SCR,
Mario Six76f11d32018-01-15 11:08:24 +0100560 MIIM_88E1xxx_PHY_MDI_X_AUTO);
Andy Fleming9082eea2011-04-07 21:56:05 -0500561
562 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR);
563 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
564 reg |= MIIM_M88E1145_RGMII_RX_DELAY |
565 MIIM_M88E1145_RGMII_TX_DELAY;
566 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR, reg);
567
Stefan Roese0ef02612022-03-31 11:43:06 +0200568 marvell_of_reg_init(phydev);
569
Andy Fleming9082eea2011-04-07 21:56:05 -0500570 genphy_config_aneg(phydev);
571
York Sunef621da2017-06-06 09:22:40 -0700572 /* soft reset */
573 reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
574 reg |= BMCR_RESET;
575 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, reg);
Andy Fleming9082eea2011-04-07 21:56:05 -0500576
577 return 0;
578}
579
580static int m88e1145_startup(struct phy_device *phydev)
581{
Michal Simekb733c272016-05-18 12:46:12 +0200582 int ret;
583
584 ret = genphy_update_link(phydev);
585 if (ret)
586 return ret;
587
Andy Fleming9082eea2011-04-07 21:56:05 -0500588 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_LED_CONTROL,
Mario Six76f11d32018-01-15 11:08:24 +0100589 MIIM_88E1145_PHY_LED_DIRECT);
Michal Simekb733c272016-05-18 12:46:12 +0200590 return m88e1xxx_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500591}
592
593/* Marvell 88E1149S */
594static int m88e1149_config(struct phy_device *phydev)
595{
596 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1149_PHY_PAGE, 0x1f);
597 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x200c);
598 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1149_PHY_PAGE, 0x5);
599 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x0);
600 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
601
Stefan Roese0ef02612022-03-31 11:43:06 +0200602 marvell_of_reg_init(phydev);
603
Andy Fleming9082eea2011-04-07 21:56:05 -0500604 genphy_config_aneg(phydev);
605
606 phy_reset(phydev);
607
608 return 0;
609}
610
Stefan Roese01207942022-03-31 11:43:07 +0200611/* Marvell 88E1240 */
612static int m88e1240_config(struct phy_device *phydev)
613{
614 marvell_of_reg_init(phydev);
615
616 genphy_config_aneg(phydev);
617
618 return 0;
619}
620
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +0100621/* Marvell 88E1310 */
622static int m88e1310_config(struct phy_device *phydev)
623{
624 u16 reg;
625
626 /* LED link and activity */
627 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0003);
628 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_LED_CTRL);
629 reg = (reg & ~0xf) | 0x1;
630 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_LED_CTRL, reg);
631
632 /* Set LED2/INT to INT mode, low active */
633 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0003);
634 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_IRQ_EN);
635 reg = (reg & 0x77ff) | 0x0880;
636 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_IRQ_EN, reg);
637
638 /* Set RGMII delay */
639 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0002);
640 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_RGMII_CTRL);
641 reg |= 0x0030;
642 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_RGMII_CTRL, reg);
643
644 /* Ensure to return to page 0 */
645 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0000);
646
Stefan Roese0ef02612022-03-31 11:43:06 +0200647 marvell_of_reg_init(phydev);
648
Nathan Rossi08e64ce2016-06-03 23:16:17 +1000649 return genphy_config_aneg(phydev);
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +0100650}
Andy Fleming9082eea2011-04-07 21:56:05 -0500651
Dirk Eibachc52d4282017-01-11 16:00:46 +0100652static int m88e1680_config(struct phy_device *phydev)
653{
654 /*
655 * As per Marvell Release Notes - Alaska V 88E1680 Rev A2
656 * Errata Section 4.1
657 */
658 u16 reg;
659 int res;
660
661 /* Matrix LED mode (not neede if single LED mode is used */
662 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0004);
663 reg = phy_read(phydev, MDIO_DEVAD_NONE, 27);
664 reg |= (1 << 5);
665 phy_write(phydev, MDIO_DEVAD_NONE, 27, reg);
666
667 /* QSGMII TX amplitude change */
668 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00fd);
669 phy_write(phydev, MDIO_DEVAD_NONE, 8, 0x0b53);
670 phy_write(phydev, MDIO_DEVAD_NONE, 7, 0x200d);
671 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
672
673 /* EEE initialization */
674 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00ff);
675 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xb030);
676 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x215c);
677 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x00fc);
678 phy_write(phydev, MDIO_DEVAD_NONE, 24, 0x888c);
679 phy_write(phydev, MDIO_DEVAD_NONE, 25, 0x888c);
680 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
681 phy_write(phydev, MDIO_DEVAD_NONE, 0, 0x9140);
682
Stefan Roese0ef02612022-03-31 11:43:06 +0200683 marvell_of_reg_init(phydev);
684
Dirk Eibachc52d4282017-01-11 16:00:46 +0100685 res = genphy_config_aneg(phydev);
686 if (res < 0)
687 return res;
688
689 /* soft reset */
690 reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
691 reg |= BMCR_RESET;
692 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, reg);
693
694 return 0;
695}
696
Marek Vasut9010be92023-03-19 18:02:54 +0100697U_BOOT_PHY_DRIVER(m88e1011s) = {
Andy Fleming9082eea2011-04-07 21:56:05 -0500698 .name = "Marvell 88E1011S",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100699 .uid = MARVELL_PHY_ID_88E1101,
700 .mask = MARVELL_PHY_ID_MASK,
Andy Fleming9082eea2011-04-07 21:56:05 -0500701 .features = PHY_GBIT_FEATURES,
702 .config = &m88e1011s_config,
703 .startup = &m88e1011s_startup,
704 .shutdown = &genphy_shutdown,
705};
706
Marek Vasut9010be92023-03-19 18:02:54 +0100707U_BOOT_PHY_DRIVER(m88e1111s) = {
Andy Fleming9082eea2011-04-07 21:56:05 -0500708 .name = "Marvell 88E1111S",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100709 .uid = MARVELL_PHY_ID_88E1111,
710 .mask = MARVELL_PHY_ID_MASK,
Andy Fleming9082eea2011-04-07 21:56:05 -0500711 .features = PHY_GBIT_FEATURES,
712 .config = &m88e1111s_config,
713 .startup = &m88e1011s_startup,
714 .shutdown = &genphy_shutdown,
715};
716
Marek Vasut9010be92023-03-19 18:02:54 +0100717U_BOOT_PHY_DRIVER(m88e1118) = {
Andy Fleming9082eea2011-04-07 21:56:05 -0500718 .name = "Marvell 88E1118",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100719 .uid = MARVELL_PHY_ID_88E1118,
720 .mask = MARVELL_PHY_ID_MASK,
Andy Fleming9082eea2011-04-07 21:56:05 -0500721 .features = PHY_GBIT_FEATURES,
722 .config = &m88e1118_config,
723 .startup = &m88e1118_startup,
724 .shutdown = &genphy_shutdown,
725};
726
Marek Vasut9010be92023-03-19 18:02:54 +0100727U_BOOT_PHY_DRIVER(m88e1118r) = {
Michal Simekb4b81e82012-08-07 02:23:07 +0000728 .name = "Marvell 88E1118R",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100729 .uid = MARVELL_PHY_ID_88E1116R,
730 .mask = MARVELL_PHY_ID_MASK,
Michal Simekb4b81e82012-08-07 02:23:07 +0000731 .features = PHY_GBIT_FEATURES,
732 .config = &m88e1118_config,
733 .startup = &m88e1118_startup,
734 .shutdown = &genphy_shutdown,
735};
736
Marek Vasut9010be92023-03-19 18:02:54 +0100737U_BOOT_PHY_DRIVER(m88e1121r) = {
Andy Fleming9082eea2011-04-07 21:56:05 -0500738 .name = "Marvell 88E1121R",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100739 .uid = MARVELL_PHY_ID_88E1121R,
740 .mask = MARVELL_PHY_ID_MASK,
Andy Fleming9082eea2011-04-07 21:56:05 -0500741 .features = PHY_GBIT_FEATURES,
742 .config = &m88e1121_config,
743 .startup = &genphy_startup,
744 .shutdown = &genphy_shutdown,
745};
746
Marek Vasut9010be92023-03-19 18:02:54 +0100747U_BOOT_PHY_DRIVER(m88e1145) = {
Andy Fleming9082eea2011-04-07 21:56:05 -0500748 .name = "Marvell 88E1145",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100749 .uid = MARVELL_PHY_ID_88E1145,
750 .mask = MARVELL_PHY_ID_MASK,
Andy Fleming9082eea2011-04-07 21:56:05 -0500751 .features = PHY_GBIT_FEATURES,
752 .config = &m88e1145_config,
753 .startup = &m88e1145_startup,
754 .shutdown = &genphy_shutdown,
755};
756
Marek Vasut9010be92023-03-19 18:02:54 +0100757U_BOOT_PHY_DRIVER(m88e1149s) = {
Andy Fleming9082eea2011-04-07 21:56:05 -0500758 .name = "Marvell 88E1149S",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100759 .uid = 0x01410ca0,
760 .mask = MARVELL_PHY_ID_MASK,
Andy Fleming9082eea2011-04-07 21:56:05 -0500761 .features = PHY_GBIT_FEATURES,
762 .config = &m88e1149_config,
763 .startup = &m88e1011s_startup,
764 .shutdown = &genphy_shutdown,
765};
766
Marek Vasut9010be92023-03-19 18:02:54 +0100767U_BOOT_PHY_DRIVER(m88e1240) = {
Stefan Roese01207942022-03-31 11:43:07 +0200768 .name = "Marvell 88E1240",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100769 .uid = MARVELL_PHY_ID_88E1240,
770 .mask = MARVELL_PHY_ID_MASK,
Stefan Roese01207942022-03-31 11:43:07 +0200771 .features = PHY_GBIT_FEATURES,
772 .config = &m88e1240_config,
773 .startup = &m88e1011s_startup,
774 .shutdown = &genphy_shutdown,
775};
776
Marek Vasut9010be92023-03-19 18:02:54 +0100777U_BOOT_PHY_DRIVER(m88e151x) = {
Clemens Gruber1c1f4f02020-02-24 20:52:20 +0100778 .name = "Marvell 88E151x",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100779 .uid = MARVELL_PHY_ID_88E1510,
780 .mask = MARVELL_PHY_ID_MASK,
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200781 .features = PHY_GBIT_FEATURES,
Clemens Gruber1c1f4f02020-02-24 20:52:20 +0100782 .config = &m88e151x_config,
Michal Simek14151072012-10-15 14:03:00 +0200783 .startup = &m88e1011s_startup,
784 .shutdown = &genphy_shutdown,
Lukasz Majewskice27eb92017-10-30 22:57:53 +0100785 .readext = &m88e1xxx_phy_extread,
786 .writeext = &m88e1xxx_phy_extwrite,
Michal Simek14151072012-10-15 14:03:00 +0200787};
788
Marek Vasut9010be92023-03-19 18:02:54 +0100789U_BOOT_PHY_DRIVER(m88e1310) = {
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +0100790 .name = "Marvell 88E1310",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100791 .uid = MARVELL_PHY_ID_88E1318S,
792 .mask = MARVELL_PHY_ID_MASK,
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +0100793 .features = PHY_GBIT_FEATURES,
794 .config = &m88e1310_config,
795 .startup = &m88e1011s_startup,
796 .shutdown = &genphy_shutdown,
797};
798
Marek Vasut9010be92023-03-19 18:02:54 +0100799U_BOOT_PHY_DRIVER(m88e1680) = {
Dirk Eibachc52d4282017-01-11 16:00:46 +0100800 .name = "Marvell 88E1680",
Marek Vasutbf3dabb2023-03-19 18:08:06 +0100801 .uid = 0x01410ed0,
802 .mask = MARVELL_PHY_ID_MASK,
Dirk Eibachc52d4282017-01-11 16:00:46 +0100803 .features = PHY_GBIT_FEATURES,
804 .config = &m88e1680_config,
805 .startup = &genphy_startup,
806 .shutdown = &genphy_shutdown,
807};