blob: efbbd31ff71ba1df73a07b2be1469d58768316ca [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 * Marvell PHY drivers
4 *
Andy Fleming60ca78b2011-04-07 21:56:05 -05005 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
Andy Fleming60ca78b2011-04-07 21:56:05 -05007 */
Andy Fleming60ca78b2011-04-07 21:56:05 -05008#include <common.h>
Simon Glassb3d61dd2016-07-05 17:10:12 -06009#include <errno.h>
Andy Fleming60ca78b2011-04-07 21:56:05 -050010#include <phy.h>
11
12#define PHY_AUTONEGOTIATE_TIMEOUT 5000
13
Phil Edworthy19d03be2017-05-24 14:43:06 +010014#define MII_MARVELL_PHY_PAGE 22
15
Andy Fleming60ca78b2011-04-07 21:56:05 -050016/* 88E1011 PHY Status Register */
17#define MIIM_88E1xxx_PHY_STATUS 0x11
18#define MIIM_88E1xxx_PHYSTAT_SPEED 0xc000
19#define MIIM_88E1xxx_PHYSTAT_GBIT 0x8000
20#define MIIM_88E1xxx_PHYSTAT_100 0x4000
21#define MIIM_88E1xxx_PHYSTAT_DUPLEX 0x2000
22#define MIIM_88E1xxx_PHYSTAT_SPDDONE 0x0800
23#define MIIM_88E1xxx_PHYSTAT_LINK 0x0400
24
25#define MIIM_88E1xxx_PHY_SCR 0x10
26#define MIIM_88E1xxx_PHY_MDI_X_AUTO 0x0060
27
28/* 88E1111 PHY LED Control Register */
29#define MIIM_88E1111_PHY_LED_CONTROL 24
30#define MIIM_88E1111_PHY_LED_DIRECT 0x4100
31#define MIIM_88E1111_PHY_LED_COMBINE 0x411C
32
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +000033/* 88E1111 Extended PHY Specific Control Register */
34#define MIIM_88E1111_PHY_EXT_CR 0x14
35#define MIIM_88E1111_RX_DELAY 0x80
36#define MIIM_88E1111_TX_DELAY 0x2
37
38/* 88E1111 Extended PHY Specific Status Register */
39#define MIIM_88E1111_PHY_EXT_SR 0x1b
40#define MIIM_88E1111_HWCFG_MODE_MASK 0xf
41#define MIIM_88E1111_HWCFG_MODE_COPPER_RGMII 0xb
42#define MIIM_88E1111_HWCFG_MODE_FIBER_RGMII 0x3
43#define MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK 0x4
44#define MIIM_88E1111_HWCFG_MODE_COPPER_RTBI 0x9
45#define MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO 0x8000
46#define MIIM_88E1111_HWCFG_FIBER_COPPER_RES 0x2000
47
48#define MIIM_88E1111_COPPER 0
49#define MIIM_88E1111_FIBER 1
50
Andy Fleming60ca78b2011-04-07 21:56:05 -050051/* 88E1118 PHY defines */
52#define MIIM_88E1118_PHY_PAGE 22
53#define MIIM_88E1118_PHY_LED_PAGE 3
54
55/* 88E1121 PHY LED Control Register */
56#define MIIM_88E1121_PHY_LED_CTRL 16
57#define MIIM_88E1121_PHY_LED_PAGE 3
58#define MIIM_88E1121_PHY_LED_DEF 0x0030
59
60/* 88E1121 PHY IRQ Enable/Status Register */
61#define MIIM_88E1121_PHY_IRQ_EN 18
62#define MIIM_88E1121_PHY_IRQ_STATUS 19
63
64#define MIIM_88E1121_PHY_PAGE 22
65
66/* 88E1145 Extended PHY Specific Control Register */
67#define MIIM_88E1145_PHY_EXT_CR 20
68#define MIIM_M88E1145_RGMII_RX_DELAY 0x0080
69#define MIIM_M88E1145_RGMII_TX_DELAY 0x0002
70
71#define MIIM_88E1145_PHY_LED_CONTROL 24
72#define MIIM_88E1145_PHY_LED_DIRECT 0x4100
73
74#define MIIM_88E1145_PHY_PAGE 29
75#define MIIM_88E1145_PHY_CAL_OV 30
76
77#define MIIM_88E1149_PHY_PAGE 29
78
Sebastian Hesselbarth1b3352f2012-12-04 09:31:59 +010079/* 88E1310 PHY defines */
80#define MIIM_88E1310_PHY_LED_CTRL 16
81#define MIIM_88E1310_PHY_IRQ_EN 18
82#define MIIM_88E1310_PHY_RGMII_CTRL 21
83#define MIIM_88E1310_PHY_PAGE 22
84
Joe Hershberger27a8e032016-12-09 11:54:39 -060085/* 88E151x PHY defines */
Phil Edworthy19d03be2017-05-24 14:43:06 +010086/* Page 2 registers */
87#define MIIM_88E151x_PHY_MSCR 21
88#define MIIM_88E151x_RGMII_RX_DELAY BIT(5)
89#define MIIM_88E151x_RGMII_TX_DELAY BIT(4)
90#define MIIM_88E151x_RGMII_RXTX_DELAY (BIT(5) | BIT(4))
Joe Hershberger27a8e032016-12-09 11:54:39 -060091/* Page 3 registers */
92#define MIIM_88E151x_LED_FUNC_CTRL 16
93#define MIIM_88E151x_LED_FLD_SZ 4
94#define MIIM_88E151x_LED0_OFFS (0 * MIIM_88E151x_LED_FLD_SZ)
95#define MIIM_88E151x_LED1_OFFS (1 * MIIM_88E151x_LED_FLD_SZ)
96#define MIIM_88E151x_LED0_ACT 3
97#define MIIM_88E151x_LED1_100_1000_LINK 6
98#define MIIM_88E151x_LED_TIMER_CTRL 18
99#define MIIM_88E151x_INT_EN_OFFS 7
100/* Page 18 registers */
101#define MIIM_88E151x_GENERAL_CTRL 20
102#define MIIM_88E151x_MODE_SGMII 1
103#define MIIM_88E151x_RESET_OFFS 15
104
Lukasz Majewski3857a162017-10-30 22:57:53 +0100105static int m88e1xxx_phy_extread(struct phy_device *phydev, int addr,
106 int devaddr, int regnum)
107{
108 int oldpage = phy_read(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE);
109 int val;
110
111 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, devaddr);
112 val = phy_read(phydev, MDIO_DEVAD_NONE, regnum);
113 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, oldpage);
114
115 return val;
116}
117
118static int m88e1xxx_phy_extwrite(struct phy_device *phydev, int addr,
119 int devaddr, int regnum, u16 val)
120{
121 int oldpage = phy_read(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE);
122
123 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, devaddr);
124 phy_write(phydev, MDIO_DEVAD_NONE, regnum, val);
125 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, oldpage);
126
127 return 0;
128}
129
Andy Fleming60ca78b2011-04-07 21:56:05 -0500130/* Marvell 88E1011S */
131static int m88e1011s_config(struct phy_device *phydev)
132{
133 /* Reset and configure the PHY */
134 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
135
136 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
137 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x200c);
138 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
139 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0);
140 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
141
142 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
143
144 genphy_config_aneg(phydev);
145
146 return 0;
147}
148
149/* Parse the 88E1011's status register for speed and duplex
150 * information
151 */
Michal Simekcf6677b2016-05-18 12:48:57 +0200152static int m88e1xxx_parse_status(struct phy_device *phydev)
Andy Fleming60ca78b2011-04-07 21:56:05 -0500153{
154 unsigned int speed;
155 unsigned int mii_reg;
156
157 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_STATUS);
158
159 if ((mii_reg & MIIM_88E1xxx_PHYSTAT_LINK) &&
Mario Six618d42b2018-01-15 11:08:24 +0100160 !(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) {
Andy Fleming60ca78b2011-04-07 21:56:05 -0500161 int i = 0;
162
163 puts("Waiting for PHY realtime link");
164 while (!(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) {
165 /* Timeout reached ? */
166 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
167 puts(" TIMEOUT !\n");
168 phydev->link = 0;
Michal Simekcf6677b2016-05-18 12:48:57 +0200169 return -ETIMEDOUT;
Andy Fleming60ca78b2011-04-07 21:56:05 -0500170 }
171
172 if ((i++ % 1000) == 0)
173 putc('.');
174 udelay(1000);
175 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE,
Mario Six618d42b2018-01-15 11:08:24 +0100176 MIIM_88E1xxx_PHY_STATUS);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500177 }
178 puts(" done\n");
Mario Six618d42b2018-01-15 11:08:24 +0100179 mdelay(500); /* another 500 ms (results in faster booting) */
Andy Fleming60ca78b2011-04-07 21:56:05 -0500180 } else {
181 if (mii_reg & MIIM_88E1xxx_PHYSTAT_LINK)
182 phydev->link = 1;
183 else
184 phydev->link = 0;
185 }
186
187 if (mii_reg & MIIM_88E1xxx_PHYSTAT_DUPLEX)
188 phydev->duplex = DUPLEX_FULL;
189 else
190 phydev->duplex = DUPLEX_HALF;
191
192 speed = mii_reg & MIIM_88E1xxx_PHYSTAT_SPEED;
193
194 switch (speed) {
195 case MIIM_88E1xxx_PHYSTAT_GBIT:
196 phydev->speed = SPEED_1000;
197 break;
198 case MIIM_88E1xxx_PHYSTAT_100:
199 phydev->speed = SPEED_100;
200 break;
201 default:
202 phydev->speed = SPEED_10;
203 break;
204 }
205
206 return 0;
207}
208
209static int m88e1011s_startup(struct phy_device *phydev)
210{
Michal Simek5ff89662016-05-18 12:46:12 +0200211 int ret;
Andy Fleming60ca78b2011-04-07 21:56:05 -0500212
Michal Simek5ff89662016-05-18 12:46:12 +0200213 ret = genphy_update_link(phydev);
214 if (ret)
215 return ret;
216
217 return m88e1xxx_parse_status(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500218}
219
220/* Marvell 88E1111S */
221static int m88e1111s_config(struct phy_device *phydev)
222{
223 int reg;
224
Phil Edworthye4c26ee2016-12-12 12:54:15 +0000225 if (phy_interface_is_rgmii(phydev)) {
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000226 reg = phy_read(phydev,
Mario Six618d42b2018-01-15 11:08:24 +0100227 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000228 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
Mario Six618d42b2018-01-15 11:08:24 +0100229 (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) {
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000230 reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY);
231 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
232 reg &= ~MIIM_88E1111_TX_DELAY;
233 reg |= MIIM_88E1111_RX_DELAY;
234 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
235 reg &= ~MIIM_88E1111_RX_DELAY;
236 reg |= MIIM_88E1111_TX_DELAY;
237 }
238
239 phy_write(phydev,
Mario Six618d42b2018-01-15 11:08:24 +0100240 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000241
242 reg = phy_read(phydev,
Mario Six618d42b2018-01-15 11:08:24 +0100243 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000244
245 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
246
247 if (reg & MIIM_88E1111_HWCFG_FIBER_COPPER_RES)
248 reg |= MIIM_88E1111_HWCFG_MODE_FIBER_RGMII;
249 else
250 reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RGMII;
251
252 phy_write(phydev,
Mario Six618d42b2018-01-15 11:08:24 +0100253 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR, reg);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000254 }
255
256 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
257 reg = phy_read(phydev,
Mario Six618d42b2018-01-15 11:08:24 +0100258 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000259
260 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
261 reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK;
262 reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
263
264 phy_write(phydev, MDIO_DEVAD_NONE,
Mario Six618d42b2018-01-15 11:08:24 +0100265 MIIM_88E1111_PHY_EXT_SR, reg);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000266 }
267
268 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
269 reg = phy_read(phydev,
Mario Six618d42b2018-01-15 11:08:24 +0100270 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000271 reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY);
272 phy_write(phydev,
Mario Six618d42b2018-01-15 11:08:24 +0100273 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000274
275 reg = phy_read(phydev, MDIO_DEVAD_NONE,
Mario Six618d42b2018-01-15 11:08:24 +0100276 MIIM_88E1111_PHY_EXT_SR);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000277 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK |
278 MIIM_88E1111_HWCFG_FIBER_COPPER_RES);
279 reg |= 0x7 | MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
280 phy_write(phydev, MDIO_DEVAD_NONE,
Mario Six618d42b2018-01-15 11:08:24 +0100281 MIIM_88E1111_PHY_EXT_SR, reg);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000282
283 /* soft reset */
Stefan Roesed1b52822016-02-10 07:06:05 +0100284 phy_reset(phydev);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000285
286 reg = phy_read(phydev, MDIO_DEVAD_NONE,
Mario Six618d42b2018-01-15 11:08:24 +0100287 MIIM_88E1111_PHY_EXT_SR);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000288 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK |
Mario Six618d42b2018-01-15 11:08:24 +0100289 MIIM_88E1111_HWCFG_FIBER_COPPER_RES);
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000290 reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RTBI |
291 MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
292 phy_write(phydev, MDIO_DEVAD_NONE,
Mario Six618d42b2018-01-15 11:08:24 +0100293 MIIM_88E1111_PHY_EXT_SR, reg);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500294 }
295
Zang Roy-R6191120ffbf32011-10-27 18:52:09 +0000296 /* soft reset */
Stefan Roesed1b52822016-02-10 07:06:05 +0100297 phy_reset(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500298
299 genphy_config_aneg(phydev);
Stefan Roeseeb06f022016-02-10 07:06:06 +0100300 genphy_restart_aneg(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500301
302 return 0;
303}
304
Hao Zhangf0c53a42014-10-30 18:59:43 +0200305/**
306 * m88e1518_phy_writebits - write bits to a register
307 */
308void m88e1518_phy_writebits(struct phy_device *phydev,
Mario Six618d42b2018-01-15 11:08:24 +0100309 u8 reg_num, u16 offset, u16 len, u16 data)
Hao Zhangf0c53a42014-10-30 18:59:43 +0200310{
311 u16 reg, mask;
312
313 if ((len + offset) >= 16)
314 mask = 0 - (1 << offset);
315 else
316 mask = (1 << (len + offset)) - (1 << offset);
317
318 reg = phy_read(phydev, MDIO_DEVAD_NONE, reg_num);
319
320 reg &= ~mask;
321 reg |= data << offset;
322
323 phy_write(phydev, MDIO_DEVAD_NONE, reg_num, reg);
324}
325
326static int m88e1518_config(struct phy_device *phydev)
327{
Phil Edworthy19d03be2017-05-24 14:43:06 +0100328 u16 reg;
329
Hao Zhangf0c53a42014-10-30 18:59:43 +0200330 /*
331 * As per Marvell Release Notes - Alaska 88E1510/88E1518/88E1512
332 * /88E1514 Rev A0, Errata Section 3.1
333 */
Clemens Gruberf10d89c2015-06-06 14:44:57 +0200334
335 /* EEE initialization */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600336 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00ff);
Clemens Gruberf10d89c2015-06-06 14:44:57 +0200337 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x214B);
338 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2144);
339 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x0C28);
340 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2146);
341 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xB233);
342 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x214D);
343 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xCC0C);
344 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2159);
Joe Hershberger27a8e032016-12-09 11:54:39 -0600345 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
Clemens Gruberf10d89c2015-06-06 14:44:57 +0200346
347 /* SGMII-to-Copper mode initialization */
Hao Zhangf0c53a42014-10-30 18:59:43 +0200348 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Clemens Gruberf10d89c2015-06-06 14:44:57 +0200349 /* Select page 18 */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600350 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 18);
Clemens Gruberf10d89c2015-06-06 14:44:57 +0200351
352 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600353 m88e1518_phy_writebits(phydev, MIIM_88E151x_GENERAL_CTRL,
354 0, 3, MIIM_88E151x_MODE_SGMII);
Hao Zhangf0c53a42014-10-30 18:59:43 +0200355
Clemens Gruberf10d89c2015-06-06 14:44:57 +0200356 /* PHY reset is necessary after changing MODE[2:0] */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600357 m88e1518_phy_writebits(phydev, MIIM_88E151x_GENERAL_CTRL,
358 MIIM_88E151x_RESET_OFFS, 1, 1);
Clemens Gruberf10d89c2015-06-06 14:44:57 +0200359
360 /* Reset page selection */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600361 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0);
Clemens Gruberf10d89c2015-06-06 14:44:57 +0200362
Hao Zhangf0c53a42014-10-30 18:59:43 +0200363 udelay(100);
364 }
365
Phil Edworthy19d03be2017-05-24 14:43:06 +0100366 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
367 reg = phy_read(phydev, MDIO_DEVAD_NONE,
368 MIIM_88E1111_PHY_EXT_SR);
369
370 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
371 reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK;
372 reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
373
374 phy_write(phydev, MDIO_DEVAD_NONE,
375 MIIM_88E1111_PHY_EXT_SR, reg);
376 }
377
378 if (phy_interface_is_rgmii(phydev)) {
379 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, 2);
380
381 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR);
382 reg &= ~MIIM_88E151x_RGMII_RXTX_DELAY;
Mario Sixc1de1312018-01-15 11:08:25 +0100383 if (phydev->interface == PHY_INTERFACE_MODE_RGMII ||
384 phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
Phil Edworthy19d03be2017-05-24 14:43:06 +0100385 reg |= MIIM_88E151x_RGMII_RXTX_DELAY;
386 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
387 reg |= MIIM_88E151x_RGMII_RX_DELAY;
388 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
389 reg |= MIIM_88E151x_RGMII_TX_DELAY;
390 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR, reg);
391
392 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, 0);
393 }
394
395 /* soft reset */
396 phy_reset(phydev);
397
398 genphy_config_aneg(phydev);
399 genphy_restart_aneg(phydev);
400
401 return 0;
Hao Zhangf0c53a42014-10-30 18:59:43 +0200402}
403
Clemens Gruber89be6512015-06-06 14:44:58 +0200404/* Marvell 88E1510 */
405static int m88e1510_config(struct phy_device *phydev)
406{
407 /* Select page 3 */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600408 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE,
409 MIIM_88E1118_PHY_LED_PAGE);
Clemens Gruber89be6512015-06-06 14:44:58 +0200410
411 /* Enable INTn output on LED[2] */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600412 m88e1518_phy_writebits(phydev, MIIM_88E151x_LED_TIMER_CTRL,
413 MIIM_88E151x_INT_EN_OFFS, 1, 1);
Clemens Gruber89be6512015-06-06 14:44:58 +0200414
415 /* Configure LEDs */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600416 /* LED[0]:0011 (ACT) */
417 m88e1518_phy_writebits(phydev, MIIM_88E151x_LED_FUNC_CTRL,
418 MIIM_88E151x_LED0_OFFS, MIIM_88E151x_LED_FLD_SZ,
419 MIIM_88E151x_LED0_ACT);
420 /* LED[1]:0110 (LINK 100/1000 Mbps) */
421 m88e1518_phy_writebits(phydev, MIIM_88E151x_LED_FUNC_CTRL,
422 MIIM_88E151x_LED1_OFFS, MIIM_88E151x_LED_FLD_SZ,
423 MIIM_88E151x_LED1_100_1000_LINK);
Clemens Gruber89be6512015-06-06 14:44:58 +0200424
425 /* Reset page selection */
Joe Hershberger27a8e032016-12-09 11:54:39 -0600426 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0);
Clemens Gruber89be6512015-06-06 14:44:58 +0200427
428 return m88e1518_config(phydev);
429}
430
Andy Fleming60ca78b2011-04-07 21:56:05 -0500431/* Marvell 88E1118 */
432static int m88e1118_config(struct phy_device *phydev)
433{
434 /* Change Page Number */
435 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0002);
436 /* Delay RGMII TX and RX */
437 phy_write(phydev, MDIO_DEVAD_NONE, 0x15, 0x1070);
438 /* Change Page Number */
439 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0003);
440 /* Adjust LED control */
441 phy_write(phydev, MDIO_DEVAD_NONE, 0x10, 0x021e);
442 /* Change Page Number */
443 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
444
Michal Simek0b567102016-05-18 14:46:28 +0200445 return genphy_config_aneg(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500446}
447
448static int m88e1118_startup(struct phy_device *phydev)
449{
Michal Simek5ff89662016-05-18 12:46:12 +0200450 int ret;
451
Andy Fleming60ca78b2011-04-07 21:56:05 -0500452 /* Change Page Number */
453 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
454
Michal Simek5ff89662016-05-18 12:46:12 +0200455 ret = genphy_update_link(phydev);
456 if (ret)
457 return ret;
Andy Fleming60ca78b2011-04-07 21:56:05 -0500458
Michal Simek5ff89662016-05-18 12:46:12 +0200459 return m88e1xxx_parse_status(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500460}
461
462/* Marvell 88E1121R */
463static int m88e1121_config(struct phy_device *phydev)
464{
465 int pg;
466
467 /* Configure the PHY */
468 genphy_config_aneg(phydev);
469
470 /* Switch the page to access the led register */
471 pg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE);
472 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE,
Mario Six618d42b2018-01-15 11:08:24 +0100473 MIIM_88E1121_PHY_LED_PAGE);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500474 /* Configure leds */
475 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_LED_CTRL,
Mario Six618d42b2018-01-15 11:08:24 +0100476 MIIM_88E1121_PHY_LED_DEF);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500477 /* Restore the page pointer */
478 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE, pg);
479
480 /* Disable IRQs and de-assert interrupt */
481 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_IRQ_EN, 0);
482 phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_IRQ_STATUS);
483
484 return 0;
485}
486
487/* Marvell 88E1145 */
488static int m88e1145_config(struct phy_device *phydev)
489{
490 int reg;
491
492 /* Errata E0, E1 */
493 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_PAGE, 0x001b);
494 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0x418f);
495 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_PAGE, 0x0016);
496 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0xa2da);
497
498 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_SCR,
Mario Six618d42b2018-01-15 11:08:24 +0100499 MIIM_88E1xxx_PHY_MDI_X_AUTO);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500500
501 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR);
502 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
503 reg |= MIIM_M88E1145_RGMII_RX_DELAY |
504 MIIM_M88E1145_RGMII_TX_DELAY;
505 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR, reg);
506
507 genphy_config_aneg(phydev);
508
York Sunbf94cfb2017-06-06 09:22:40 -0700509 /* soft reset */
510 reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
511 reg |= BMCR_RESET;
512 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, reg);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500513
514 return 0;
515}
516
517static int m88e1145_startup(struct phy_device *phydev)
518{
Michal Simek5ff89662016-05-18 12:46:12 +0200519 int ret;
520
521 ret = genphy_update_link(phydev);
522 if (ret)
523 return ret;
524
Andy Fleming60ca78b2011-04-07 21:56:05 -0500525 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_LED_CONTROL,
Mario Six618d42b2018-01-15 11:08:24 +0100526 MIIM_88E1145_PHY_LED_DIRECT);
Michal Simek5ff89662016-05-18 12:46:12 +0200527 return m88e1xxx_parse_status(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500528}
529
530/* Marvell 88E1149S */
531static int m88e1149_config(struct phy_device *phydev)
532{
533 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1149_PHY_PAGE, 0x1f);
534 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x200c);
535 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1149_PHY_PAGE, 0x5);
536 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x0);
537 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
538
539 genphy_config_aneg(phydev);
540
541 phy_reset(phydev);
542
543 return 0;
544}
545
Sebastian Hesselbarth1b3352f2012-12-04 09:31:59 +0100546/* Marvell 88E1310 */
547static int m88e1310_config(struct phy_device *phydev)
548{
549 u16 reg;
550
551 /* LED link and activity */
552 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0003);
553 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_LED_CTRL);
554 reg = (reg & ~0xf) | 0x1;
555 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_LED_CTRL, reg);
556
557 /* Set LED2/INT to INT mode, low active */
558 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0003);
559 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_IRQ_EN);
560 reg = (reg & 0x77ff) | 0x0880;
561 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_IRQ_EN, reg);
562
563 /* Set RGMII delay */
564 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0002);
565 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_RGMII_CTRL);
566 reg |= 0x0030;
567 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_RGMII_CTRL, reg);
568
569 /* Ensure to return to page 0 */
570 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0000);
571
Nathan Rossifcdcc552016-06-03 23:16:17 +1000572 return genphy_config_aneg(phydev);
Sebastian Hesselbarth1b3352f2012-12-04 09:31:59 +0100573}
Andy Fleming60ca78b2011-04-07 21:56:05 -0500574
Dirk Eibach4f96f3f2017-01-11 16:00:46 +0100575static int m88e1680_config(struct phy_device *phydev)
576{
577 /*
578 * As per Marvell Release Notes - Alaska V 88E1680 Rev A2
579 * Errata Section 4.1
580 */
581 u16 reg;
582 int res;
583
584 /* Matrix LED mode (not neede if single LED mode is used */
585 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0004);
586 reg = phy_read(phydev, MDIO_DEVAD_NONE, 27);
587 reg |= (1 << 5);
588 phy_write(phydev, MDIO_DEVAD_NONE, 27, reg);
589
590 /* QSGMII TX amplitude change */
591 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00fd);
592 phy_write(phydev, MDIO_DEVAD_NONE, 8, 0x0b53);
593 phy_write(phydev, MDIO_DEVAD_NONE, 7, 0x200d);
594 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
595
596 /* EEE initialization */
597 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00ff);
598 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xb030);
599 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x215c);
600 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x00fc);
601 phy_write(phydev, MDIO_DEVAD_NONE, 24, 0x888c);
602 phy_write(phydev, MDIO_DEVAD_NONE, 25, 0x888c);
603 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
604 phy_write(phydev, MDIO_DEVAD_NONE, 0, 0x9140);
605
606 res = genphy_config_aneg(phydev);
607 if (res < 0)
608 return res;
609
610 /* soft reset */
611 reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
612 reg |= BMCR_RESET;
613 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, reg);
614
615 return 0;
616}
617
Andy Fleming60ca78b2011-04-07 21:56:05 -0500618static struct phy_driver M88E1011S_driver = {
619 .name = "Marvell 88E1011S",
620 .uid = 0x1410c60,
621 .mask = 0xffffff0,
622 .features = PHY_GBIT_FEATURES,
623 .config = &m88e1011s_config,
624 .startup = &m88e1011s_startup,
625 .shutdown = &genphy_shutdown,
626};
627
628static struct phy_driver M88E1111S_driver = {
629 .name = "Marvell 88E1111S",
630 .uid = 0x1410cc0,
631 .mask = 0xffffff0,
632 .features = PHY_GBIT_FEATURES,
633 .config = &m88e1111s_config,
634 .startup = &m88e1011s_startup,
635 .shutdown = &genphy_shutdown,
636};
637
638static struct phy_driver M88E1118_driver = {
639 .name = "Marvell 88E1118",
640 .uid = 0x1410e10,
641 .mask = 0xffffff0,
642 .features = PHY_GBIT_FEATURES,
643 .config = &m88e1118_config,
644 .startup = &m88e1118_startup,
645 .shutdown = &genphy_shutdown,
646};
647
Michal Simek130aa522012-08-07 02:23:07 +0000648static struct phy_driver M88E1118R_driver = {
649 .name = "Marvell 88E1118R",
650 .uid = 0x1410e40,
651 .mask = 0xffffff0,
652 .features = PHY_GBIT_FEATURES,
653 .config = &m88e1118_config,
654 .startup = &m88e1118_startup,
655 .shutdown = &genphy_shutdown,
656};
657
Andy Fleming60ca78b2011-04-07 21:56:05 -0500658static struct phy_driver M88E1121R_driver = {
659 .name = "Marvell 88E1121R",
660 .uid = 0x1410cb0,
661 .mask = 0xffffff0,
662 .features = PHY_GBIT_FEATURES,
663 .config = &m88e1121_config,
664 .startup = &genphy_startup,
665 .shutdown = &genphy_shutdown,
666};
667
668static struct phy_driver M88E1145_driver = {
669 .name = "Marvell 88E1145",
670 .uid = 0x1410cd0,
671 .mask = 0xffffff0,
672 .features = PHY_GBIT_FEATURES,
673 .config = &m88e1145_config,
674 .startup = &m88e1145_startup,
675 .shutdown = &genphy_shutdown,
676};
677
678static struct phy_driver M88E1149S_driver = {
679 .name = "Marvell 88E1149S",
680 .uid = 0x1410ca0,
681 .mask = 0xffffff0,
682 .features = PHY_GBIT_FEATURES,
683 .config = &m88e1149_config,
684 .startup = &m88e1011s_startup,
685 .shutdown = &genphy_shutdown,
686};
687
Clemens Gruber89be6512015-06-06 14:44:58 +0200688static struct phy_driver M88E1510_driver = {
689 .name = "Marvell 88E1510",
690 .uid = 0x1410dd0,
Phil Edworthya19a3762016-12-12 12:54:13 +0000691 .mask = 0xfffffff,
Clemens Gruber89be6512015-06-06 14:44:58 +0200692 .features = PHY_GBIT_FEATURES,
693 .config = &m88e1510_config,
694 .startup = &m88e1011s_startup,
695 .shutdown = &genphy_shutdown,
Lukasz Majewski3857a162017-10-30 22:57:53 +0100696 .readext = &m88e1xxx_phy_extread,
697 .writeext = &m88e1xxx_phy_extwrite,
Clemens Gruber89be6512015-06-06 14:44:58 +0200698};
699
Phil Edworthy34836142016-12-12 12:54:14 +0000700/*
701 * This supports:
702 * 88E1518, uid 0x1410dd1
703 * 88E1512, uid 0x1410dd4
704 */
Michal Simek4d74cf12012-10-15 14:03:00 +0200705static struct phy_driver M88E1518_driver = {
706 .name = "Marvell 88E1518",
Phil Edworthy34836142016-12-12 12:54:14 +0000707 .uid = 0x1410dd0,
708 .mask = 0xffffffa,
Michal Simek4d74cf12012-10-15 14:03:00 +0200709 .features = PHY_GBIT_FEATURES,
Hao Zhangf0c53a42014-10-30 18:59:43 +0200710 .config = &m88e1518_config,
Michal Simek4d74cf12012-10-15 14:03:00 +0200711 .startup = &m88e1011s_startup,
712 .shutdown = &genphy_shutdown,
Lukasz Majewski3857a162017-10-30 22:57:53 +0100713 .readext = &m88e1xxx_phy_extread,
714 .writeext = &m88e1xxx_phy_extwrite,
Michal Simek4d74cf12012-10-15 14:03:00 +0200715};
716
Sebastian Hesselbarth1b3352f2012-12-04 09:31:59 +0100717static struct phy_driver M88E1310_driver = {
718 .name = "Marvell 88E1310",
719 .uid = 0x01410e90,
720 .mask = 0xffffff0,
721 .features = PHY_GBIT_FEATURES,
722 .config = &m88e1310_config,
723 .startup = &m88e1011s_startup,
724 .shutdown = &genphy_shutdown,
725};
726
Dirk Eibach4f96f3f2017-01-11 16:00:46 +0100727static struct phy_driver M88E1680_driver = {
728 .name = "Marvell 88E1680",
729 .uid = 0x1410ed0,
730 .mask = 0xffffff0,
731 .features = PHY_GBIT_FEATURES,
732 .config = &m88e1680_config,
733 .startup = &genphy_startup,
734 .shutdown = &genphy_shutdown,
735};
736
Andy Fleming60ca78b2011-04-07 21:56:05 -0500737int phy_marvell_init(void)
738{
Sebastian Hesselbarth1b3352f2012-12-04 09:31:59 +0100739 phy_register(&M88E1310_driver);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500740 phy_register(&M88E1149S_driver);
741 phy_register(&M88E1145_driver);
742 phy_register(&M88E1121R_driver);
743 phy_register(&M88E1118_driver);
Michal Simek130aa522012-08-07 02:23:07 +0000744 phy_register(&M88E1118R_driver);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500745 phy_register(&M88E1111S_driver);
746 phy_register(&M88E1011S_driver);
Clemens Gruber89be6512015-06-06 14:44:58 +0200747 phy_register(&M88E1510_driver);
Michal Simek4d74cf12012-10-15 14:03:00 +0200748 phy_register(&M88E1518_driver);
Dirk Eibach4f96f3f2017-01-11 16:00:46 +0100749 phy_register(&M88E1680_driver);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500750
751 return 0;
752}