blob: 8041922a02dc6ff533536dd5c96a0df3cfdd0438 [file] [log] [blame]
Andy Fleming9082eea2011-04-07 21:56:05 -05001/*
2 * Marvell PHY drivers
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Andy Fleming9082eea2011-04-07 21:56:05 -05005 *
6 * Copyright 2010-2011 Freescale Semiconductor, Inc.
7 * author Andy Fleming
Andy Fleming9082eea2011-04-07 21:56:05 -05008 */
9#include <config.h>
10#include <common.h>
Simon Glassfbfa1ab2016-07-05 17:10:12 -060011#include <errno.h>
Andy Fleming9082eea2011-04-07 21:56:05 -050012#include <phy.h>
13
14#define PHY_AUTONEGOTIATE_TIMEOUT 5000
15
Phil Edworthy68e6eca2017-05-24 14:43:06 +010016#define MII_MARVELL_PHY_PAGE 22
17
Andy Fleming9082eea2011-04-07 21:56:05 -050018/* 88E1011 PHY Status Register */
19#define MIIM_88E1xxx_PHY_STATUS 0x11
20#define MIIM_88E1xxx_PHYSTAT_SPEED 0xc000
21#define MIIM_88E1xxx_PHYSTAT_GBIT 0x8000
22#define MIIM_88E1xxx_PHYSTAT_100 0x4000
23#define MIIM_88E1xxx_PHYSTAT_DUPLEX 0x2000
24#define MIIM_88E1xxx_PHYSTAT_SPDDONE 0x0800
25#define MIIM_88E1xxx_PHYSTAT_LINK 0x0400
26
27#define MIIM_88E1xxx_PHY_SCR 0x10
28#define MIIM_88E1xxx_PHY_MDI_X_AUTO 0x0060
29
30/* 88E1111 PHY LED Control Register */
31#define MIIM_88E1111_PHY_LED_CONTROL 24
32#define MIIM_88E1111_PHY_LED_DIRECT 0x4100
33#define MIIM_88E1111_PHY_LED_COMBINE 0x411C
34
Zang Roy-R61911fa12a082011-10-27 18:52:09 +000035/* 88E1111 Extended PHY Specific Control Register */
36#define MIIM_88E1111_PHY_EXT_CR 0x14
37#define MIIM_88E1111_RX_DELAY 0x80
38#define MIIM_88E1111_TX_DELAY 0x2
39
40/* 88E1111 Extended PHY Specific Status Register */
41#define MIIM_88E1111_PHY_EXT_SR 0x1b
42#define MIIM_88E1111_HWCFG_MODE_MASK 0xf
43#define MIIM_88E1111_HWCFG_MODE_COPPER_RGMII 0xb
44#define MIIM_88E1111_HWCFG_MODE_FIBER_RGMII 0x3
45#define MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK 0x4
46#define MIIM_88E1111_HWCFG_MODE_COPPER_RTBI 0x9
47#define MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO 0x8000
48#define MIIM_88E1111_HWCFG_FIBER_COPPER_RES 0x2000
49
50#define MIIM_88E1111_COPPER 0
51#define MIIM_88E1111_FIBER 1
52
Andy Fleming9082eea2011-04-07 21:56:05 -050053/* 88E1118 PHY defines */
54#define MIIM_88E1118_PHY_PAGE 22
55#define MIIM_88E1118_PHY_LED_PAGE 3
56
57/* 88E1121 PHY LED Control Register */
58#define MIIM_88E1121_PHY_LED_CTRL 16
59#define MIIM_88E1121_PHY_LED_PAGE 3
60#define MIIM_88E1121_PHY_LED_DEF 0x0030
61
62/* 88E1121 PHY IRQ Enable/Status Register */
63#define MIIM_88E1121_PHY_IRQ_EN 18
64#define MIIM_88E1121_PHY_IRQ_STATUS 19
65
66#define MIIM_88E1121_PHY_PAGE 22
67
68/* 88E1145 Extended PHY Specific Control Register */
69#define MIIM_88E1145_PHY_EXT_CR 20
70#define MIIM_M88E1145_RGMII_RX_DELAY 0x0080
71#define MIIM_M88E1145_RGMII_TX_DELAY 0x0002
72
73#define MIIM_88E1145_PHY_LED_CONTROL 24
74#define MIIM_88E1145_PHY_LED_DIRECT 0x4100
75
76#define MIIM_88E1145_PHY_PAGE 29
77#define MIIM_88E1145_PHY_CAL_OV 30
78
79#define MIIM_88E1149_PHY_PAGE 29
80
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +010081/* 88E1310 PHY defines */
82#define MIIM_88E1310_PHY_LED_CTRL 16
83#define MIIM_88E1310_PHY_IRQ_EN 18
84#define MIIM_88E1310_PHY_RGMII_CTRL 21
85#define MIIM_88E1310_PHY_PAGE 22
86
Joe Hershberger93cc2952016-12-09 11:54:39 -060087/* 88E151x PHY defines */
Phil Edworthy68e6eca2017-05-24 14:43:06 +010088/* Page 2 registers */
89#define MIIM_88E151x_PHY_MSCR 21
90#define MIIM_88E151x_RGMII_RX_DELAY BIT(5)
91#define MIIM_88E151x_RGMII_TX_DELAY BIT(4)
92#define MIIM_88E151x_RGMII_RXTX_DELAY (BIT(5) | BIT(4))
Joe Hershberger93cc2952016-12-09 11:54:39 -060093/* Page 3 registers */
94#define MIIM_88E151x_LED_FUNC_CTRL 16
95#define MIIM_88E151x_LED_FLD_SZ 4
96#define MIIM_88E151x_LED0_OFFS (0 * MIIM_88E151x_LED_FLD_SZ)
97#define MIIM_88E151x_LED1_OFFS (1 * MIIM_88E151x_LED_FLD_SZ)
98#define MIIM_88E151x_LED0_ACT 3
99#define MIIM_88E151x_LED1_100_1000_LINK 6
100#define MIIM_88E151x_LED_TIMER_CTRL 18
101#define MIIM_88E151x_INT_EN_OFFS 7
102/* Page 18 registers */
103#define MIIM_88E151x_GENERAL_CTRL 20
104#define MIIM_88E151x_MODE_SGMII 1
105#define MIIM_88E151x_RESET_OFFS 15
106
Andy Fleming9082eea2011-04-07 21:56:05 -0500107/* Marvell 88E1011S */
108static int m88e1011s_config(struct phy_device *phydev)
109{
110 /* Reset and configure the PHY */
111 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
112
113 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
114 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x200c);
115 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
116 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0);
117 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
118
119 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
120
121 genphy_config_aneg(phydev);
122
123 return 0;
124}
125
126/* Parse the 88E1011's status register for speed and duplex
127 * information
128 */
Michal Simekef5e8212016-05-18 12:48:57 +0200129static int m88e1xxx_parse_status(struct phy_device *phydev)
Andy Fleming9082eea2011-04-07 21:56:05 -0500130{
131 unsigned int speed;
132 unsigned int mii_reg;
133
134 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_STATUS);
135
136 if ((mii_reg & MIIM_88E1xxx_PHYSTAT_LINK) &&
137 !(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) {
138 int i = 0;
139
140 puts("Waiting for PHY realtime link");
141 while (!(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) {
142 /* Timeout reached ? */
143 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
144 puts(" TIMEOUT !\n");
145 phydev->link = 0;
Michal Simekef5e8212016-05-18 12:48:57 +0200146 return -ETIMEDOUT;
Andy Fleming9082eea2011-04-07 21:56:05 -0500147 }
148
149 if ((i++ % 1000) == 0)
150 putc('.');
151 udelay(1000);
152 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE,
153 MIIM_88E1xxx_PHY_STATUS);
154 }
155 puts(" done\n");
156 udelay(500000); /* another 500 ms (results in faster booting) */
157 } else {
158 if (mii_reg & MIIM_88E1xxx_PHYSTAT_LINK)
159 phydev->link = 1;
160 else
161 phydev->link = 0;
162 }
163
164 if (mii_reg & MIIM_88E1xxx_PHYSTAT_DUPLEX)
165 phydev->duplex = DUPLEX_FULL;
166 else
167 phydev->duplex = DUPLEX_HALF;
168
169 speed = mii_reg & MIIM_88E1xxx_PHYSTAT_SPEED;
170
171 switch (speed) {
172 case MIIM_88E1xxx_PHYSTAT_GBIT:
173 phydev->speed = SPEED_1000;
174 break;
175 case MIIM_88E1xxx_PHYSTAT_100:
176 phydev->speed = SPEED_100;
177 break;
178 default:
179 phydev->speed = SPEED_10;
180 break;
181 }
182
183 return 0;
184}
185
186static int m88e1011s_startup(struct phy_device *phydev)
187{
Michal Simekb733c272016-05-18 12:46:12 +0200188 int ret;
Andy Fleming9082eea2011-04-07 21:56:05 -0500189
Michal Simekb733c272016-05-18 12:46:12 +0200190 ret = genphy_update_link(phydev);
191 if (ret)
192 return ret;
193
194 return m88e1xxx_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500195}
196
197/* Marvell 88E1111S */
198static int m88e1111s_config(struct phy_device *phydev)
199{
200 int reg;
201
Phil Edworthy24d98cb2016-12-12 12:54:15 +0000202 if (phy_interface_is_rgmii(phydev)) {
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000203 reg = phy_read(phydev,
204 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR);
205 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
206 (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) {
207 reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY);
208 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
209 reg &= ~MIIM_88E1111_TX_DELAY;
210 reg |= MIIM_88E1111_RX_DELAY;
211 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
212 reg &= ~MIIM_88E1111_RX_DELAY;
213 reg |= MIIM_88E1111_TX_DELAY;
214 }
215
216 phy_write(phydev,
217 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg);
218
219 reg = phy_read(phydev,
220 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR);
221
222 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
223
224 if (reg & MIIM_88E1111_HWCFG_FIBER_COPPER_RES)
225 reg |= MIIM_88E1111_HWCFG_MODE_FIBER_RGMII;
226 else
227 reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RGMII;
228
229 phy_write(phydev,
230 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR, reg);
Andy Fleming9082eea2011-04-07 21:56:05 -0500231 }
232
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000233 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
234 reg = phy_read(phydev,
235 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR);
236
237 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
238 reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK;
239 reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
240
241 phy_write(phydev, MDIO_DEVAD_NONE,
242 MIIM_88E1111_PHY_EXT_SR, reg);
243 }
244
245 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
246 reg = phy_read(phydev,
247 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR);
248 reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY);
249 phy_write(phydev,
250 MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg);
251
252 reg = phy_read(phydev, MDIO_DEVAD_NONE,
253 MIIM_88E1111_PHY_EXT_SR);
254 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK |
255 MIIM_88E1111_HWCFG_FIBER_COPPER_RES);
256 reg |= 0x7 | MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
257 phy_write(phydev, MDIO_DEVAD_NONE,
258 MIIM_88E1111_PHY_EXT_SR, reg);
259
260 /* soft reset */
Stefan Roese3089c472016-02-10 07:06:05 +0100261 phy_reset(phydev);
Zang Roy-R61911fa12a082011-10-27 18:52:09 +0000262
263 reg = phy_read(phydev, MDIO_DEVAD_NONE,
264 MIIM_88E1111_PHY_EXT_SR);
265 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK |
266 MIIM_88E1111_HWCFG_FIBER_COPPER_RES);
267 reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RTBI |
268 MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
269 phy_write(phydev, MDIO_DEVAD_NONE,
270 MIIM_88E1111_PHY_EXT_SR, reg);
271 }
272
273 /* soft reset */
Stefan Roese3089c472016-02-10 07:06:05 +0100274 phy_reset(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500275
276 genphy_config_aneg(phydev);
Stefan Roesea8c3eca2016-02-10 07:06:06 +0100277 genphy_restart_aneg(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500278
279 return 0;
280}
281
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200282/**
283 * m88e1518_phy_writebits - write bits to a register
284 */
285void m88e1518_phy_writebits(struct phy_device *phydev,
286 u8 reg_num, u16 offset, u16 len, u16 data)
287{
288 u16 reg, mask;
289
290 if ((len + offset) >= 16)
291 mask = 0 - (1 << offset);
292 else
293 mask = (1 << (len + offset)) - (1 << offset);
294
295 reg = phy_read(phydev, MDIO_DEVAD_NONE, reg_num);
296
297 reg &= ~mask;
298 reg |= data << offset;
299
300 phy_write(phydev, MDIO_DEVAD_NONE, reg_num, reg);
301}
302
303static int m88e1518_config(struct phy_device *phydev)
304{
Phil Edworthy68e6eca2017-05-24 14:43:06 +0100305 u16 reg;
306
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200307 /*
308 * As per Marvell Release Notes - Alaska 88E1510/88E1518/88E1512
309 * /88E1514 Rev A0, Errata Section 3.1
310 */
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200311
312 /* EEE initialization */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600313 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00ff);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200314 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x214B);
315 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2144);
316 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0x0C28);
317 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2146);
318 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xB233);
319 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x214D);
320 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xCC0C);
321 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x2159);
Joe Hershberger93cc2952016-12-09 11:54:39 -0600322 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200323
324 /* SGMII-to-Copper mode initialization */
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200325 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200326 /* Select page 18 */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600327 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 18);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200328
329 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600330 m88e1518_phy_writebits(phydev, MIIM_88E151x_GENERAL_CTRL,
331 0, 3, MIIM_88E151x_MODE_SGMII);
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200332
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200333 /* PHY reset is necessary after changing MODE[2:0] */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600334 m88e1518_phy_writebits(phydev, MIIM_88E151x_GENERAL_CTRL,
335 MIIM_88E151x_RESET_OFFS, 1, 1);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200336
337 /* Reset page selection */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600338 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0);
Clemens Gruber90a94ef2015-06-06 14:44:57 +0200339
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200340 udelay(100);
341 }
342
Phil Edworthy68e6eca2017-05-24 14:43:06 +0100343 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
344 reg = phy_read(phydev, MDIO_DEVAD_NONE,
345 MIIM_88E1111_PHY_EXT_SR);
346
347 reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
348 reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK;
349 reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
350
351 phy_write(phydev, MDIO_DEVAD_NONE,
352 MIIM_88E1111_PHY_EXT_SR, reg);
353 }
354
355 if (phy_interface_is_rgmii(phydev)) {
356 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, 2);
357
358 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR);
359 reg &= ~MIIM_88E151x_RGMII_RXTX_DELAY;
360 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
361 reg |= MIIM_88E151x_RGMII_RXTX_DELAY;
362 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
363 reg |= MIIM_88E151x_RGMII_RX_DELAY;
364 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
365 reg |= MIIM_88E151x_RGMII_TX_DELAY;
366 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR, reg);
367
368 phy_write(phydev, MDIO_DEVAD_NONE, MII_MARVELL_PHY_PAGE, 0);
369 }
370
371 /* soft reset */
372 phy_reset(phydev);
373
374 genphy_config_aneg(phydev);
375 genphy_restart_aneg(phydev);
376
377 return 0;
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200378}
379
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200380/* Marvell 88E1510 */
381static int m88e1510_config(struct phy_device *phydev)
382{
383 /* Select page 3 */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600384 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE,
385 MIIM_88E1118_PHY_LED_PAGE);
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200386
387 /* Enable INTn output on LED[2] */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600388 m88e1518_phy_writebits(phydev, MIIM_88E151x_LED_TIMER_CTRL,
389 MIIM_88E151x_INT_EN_OFFS, 1, 1);
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200390
391 /* Configure LEDs */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600392 /* LED[0]:0011 (ACT) */
393 m88e1518_phy_writebits(phydev, MIIM_88E151x_LED_FUNC_CTRL,
394 MIIM_88E151x_LED0_OFFS, MIIM_88E151x_LED_FLD_SZ,
395 MIIM_88E151x_LED0_ACT);
396 /* LED[1]:0110 (LINK 100/1000 Mbps) */
397 m88e1518_phy_writebits(phydev, MIIM_88E151x_LED_FUNC_CTRL,
398 MIIM_88E151x_LED1_OFFS, MIIM_88E151x_LED_FLD_SZ,
399 MIIM_88E151x_LED1_100_1000_LINK);
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200400
401 /* Reset page selection */
Joe Hershberger93cc2952016-12-09 11:54:39 -0600402 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0);
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200403
404 return m88e1518_config(phydev);
405}
406
Andy Fleming9082eea2011-04-07 21:56:05 -0500407/* Marvell 88E1118 */
408static int m88e1118_config(struct phy_device *phydev)
409{
410 /* Change Page Number */
411 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0002);
412 /* Delay RGMII TX and RX */
413 phy_write(phydev, MDIO_DEVAD_NONE, 0x15, 0x1070);
414 /* Change Page Number */
415 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0003);
416 /* Adjust LED control */
417 phy_write(phydev, MDIO_DEVAD_NONE, 0x10, 0x021e);
418 /* Change Page Number */
419 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
420
Michal Simek1b008fd2016-05-18 14:46:28 +0200421 return genphy_config_aneg(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500422}
423
424static int m88e1118_startup(struct phy_device *phydev)
425{
Michal Simekb733c272016-05-18 12:46:12 +0200426 int ret;
427
Andy Fleming9082eea2011-04-07 21:56:05 -0500428 /* Change Page Number */
429 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
430
Michal Simekb733c272016-05-18 12:46:12 +0200431 ret = genphy_update_link(phydev);
432 if (ret)
433 return ret;
Andy Fleming9082eea2011-04-07 21:56:05 -0500434
Michal Simekb733c272016-05-18 12:46:12 +0200435 return m88e1xxx_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500436}
437
438/* Marvell 88E1121R */
439static int m88e1121_config(struct phy_device *phydev)
440{
441 int pg;
442
443 /* Configure the PHY */
444 genphy_config_aneg(phydev);
445
446 /* Switch the page to access the led register */
447 pg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE);
448 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE,
449 MIIM_88E1121_PHY_LED_PAGE);
450 /* Configure leds */
451 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_LED_CTRL,
452 MIIM_88E1121_PHY_LED_DEF);
453 /* Restore the page pointer */
454 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE, pg);
455
456 /* Disable IRQs and de-assert interrupt */
457 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_IRQ_EN, 0);
458 phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_IRQ_STATUS);
459
460 return 0;
461}
462
463/* Marvell 88E1145 */
464static int m88e1145_config(struct phy_device *phydev)
465{
466 int reg;
467
468 /* Errata E0, E1 */
469 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_PAGE, 0x001b);
470 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0x418f);
471 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_PAGE, 0x0016);
472 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0xa2da);
473
474 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_SCR,
475 MIIM_88E1xxx_PHY_MDI_X_AUTO);
476
477 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR);
478 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
479 reg |= MIIM_M88E1145_RGMII_RX_DELAY |
480 MIIM_M88E1145_RGMII_TX_DELAY;
481 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR, reg);
482
483 genphy_config_aneg(phydev);
484
485 phy_reset(phydev);
486
487 return 0;
488}
489
490static int m88e1145_startup(struct phy_device *phydev)
491{
Michal Simekb733c272016-05-18 12:46:12 +0200492 int ret;
493
494 ret = genphy_update_link(phydev);
495 if (ret)
496 return ret;
497
Andy Fleming9082eea2011-04-07 21:56:05 -0500498 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_LED_CONTROL,
499 MIIM_88E1145_PHY_LED_DIRECT);
Michal Simekb733c272016-05-18 12:46:12 +0200500 return m88e1xxx_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500501}
502
503/* Marvell 88E1149S */
504static int m88e1149_config(struct phy_device *phydev)
505{
506 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1149_PHY_PAGE, 0x1f);
507 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x200c);
508 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1149_PHY_PAGE, 0x5);
509 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x0);
510 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
511
512 genphy_config_aneg(phydev);
513
514 phy_reset(phydev);
515
516 return 0;
517}
518
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +0100519/* Marvell 88E1310 */
520static int m88e1310_config(struct phy_device *phydev)
521{
522 u16 reg;
523
524 /* LED link and activity */
525 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0003);
526 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_LED_CTRL);
527 reg = (reg & ~0xf) | 0x1;
528 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_LED_CTRL, reg);
529
530 /* Set LED2/INT to INT mode, low active */
531 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0003);
532 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_IRQ_EN);
533 reg = (reg & 0x77ff) | 0x0880;
534 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_IRQ_EN, reg);
535
536 /* Set RGMII delay */
537 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0002);
538 reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_RGMII_CTRL);
539 reg |= 0x0030;
540 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_RGMII_CTRL, reg);
541
542 /* Ensure to return to page 0 */
543 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1310_PHY_PAGE, 0x0000);
544
Nathan Rossi08e64ce2016-06-03 23:16:17 +1000545 return genphy_config_aneg(phydev);
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +0100546}
Andy Fleming9082eea2011-04-07 21:56:05 -0500547
Dirk Eibachc52d4282017-01-11 16:00:46 +0100548static int m88e1680_config(struct phy_device *phydev)
549{
550 /*
551 * As per Marvell Release Notes - Alaska V 88E1680 Rev A2
552 * Errata Section 4.1
553 */
554 u16 reg;
555 int res;
556
557 /* Matrix LED mode (not neede if single LED mode is used */
558 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0004);
559 reg = phy_read(phydev, MDIO_DEVAD_NONE, 27);
560 reg |= (1 << 5);
561 phy_write(phydev, MDIO_DEVAD_NONE, 27, reg);
562
563 /* QSGMII TX amplitude change */
564 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00fd);
565 phy_write(phydev, MDIO_DEVAD_NONE, 8, 0x0b53);
566 phy_write(phydev, MDIO_DEVAD_NONE, 7, 0x200d);
567 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
568
569 /* EEE initialization */
570 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x00ff);
571 phy_write(phydev, MDIO_DEVAD_NONE, 17, 0xb030);
572 phy_write(phydev, MDIO_DEVAD_NONE, 16, 0x215c);
573 phy_write(phydev, MDIO_DEVAD_NONE, 22, 0x00fc);
574 phy_write(phydev, MDIO_DEVAD_NONE, 24, 0x888c);
575 phy_write(phydev, MDIO_DEVAD_NONE, 25, 0x888c);
576 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1118_PHY_PAGE, 0x0000);
577 phy_write(phydev, MDIO_DEVAD_NONE, 0, 0x9140);
578
579 res = genphy_config_aneg(phydev);
580 if (res < 0)
581 return res;
582
583 /* soft reset */
584 reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
585 reg |= BMCR_RESET;
586 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, reg);
587
588 return 0;
589}
590
Andy Fleming9082eea2011-04-07 21:56:05 -0500591static struct phy_driver M88E1011S_driver = {
592 .name = "Marvell 88E1011S",
593 .uid = 0x1410c60,
594 .mask = 0xffffff0,
595 .features = PHY_GBIT_FEATURES,
596 .config = &m88e1011s_config,
597 .startup = &m88e1011s_startup,
598 .shutdown = &genphy_shutdown,
599};
600
601static struct phy_driver M88E1111S_driver = {
602 .name = "Marvell 88E1111S",
603 .uid = 0x1410cc0,
604 .mask = 0xffffff0,
605 .features = PHY_GBIT_FEATURES,
606 .config = &m88e1111s_config,
607 .startup = &m88e1011s_startup,
608 .shutdown = &genphy_shutdown,
609};
610
611static struct phy_driver M88E1118_driver = {
612 .name = "Marvell 88E1118",
613 .uid = 0x1410e10,
614 .mask = 0xffffff0,
615 .features = PHY_GBIT_FEATURES,
616 .config = &m88e1118_config,
617 .startup = &m88e1118_startup,
618 .shutdown = &genphy_shutdown,
619};
620
Michal Simekb4b81e82012-08-07 02:23:07 +0000621static struct phy_driver M88E1118R_driver = {
622 .name = "Marvell 88E1118R",
623 .uid = 0x1410e40,
624 .mask = 0xffffff0,
625 .features = PHY_GBIT_FEATURES,
626 .config = &m88e1118_config,
627 .startup = &m88e1118_startup,
628 .shutdown = &genphy_shutdown,
629};
630
Andy Fleming9082eea2011-04-07 21:56:05 -0500631static struct phy_driver M88E1121R_driver = {
632 .name = "Marvell 88E1121R",
633 .uid = 0x1410cb0,
634 .mask = 0xffffff0,
635 .features = PHY_GBIT_FEATURES,
636 .config = &m88e1121_config,
637 .startup = &genphy_startup,
638 .shutdown = &genphy_shutdown,
639};
640
641static struct phy_driver M88E1145_driver = {
642 .name = "Marvell 88E1145",
643 .uid = 0x1410cd0,
644 .mask = 0xffffff0,
645 .features = PHY_GBIT_FEATURES,
646 .config = &m88e1145_config,
647 .startup = &m88e1145_startup,
648 .shutdown = &genphy_shutdown,
649};
650
651static struct phy_driver M88E1149S_driver = {
652 .name = "Marvell 88E1149S",
653 .uid = 0x1410ca0,
654 .mask = 0xffffff0,
655 .features = PHY_GBIT_FEATURES,
656 .config = &m88e1149_config,
657 .startup = &m88e1011s_startup,
658 .shutdown = &genphy_shutdown,
659};
660
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200661static struct phy_driver M88E1510_driver = {
662 .name = "Marvell 88E1510",
663 .uid = 0x1410dd0,
Phil Edworthy83cfbeb2016-12-12 12:54:13 +0000664 .mask = 0xfffffff,
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200665 .features = PHY_GBIT_FEATURES,
666 .config = &m88e1510_config,
667 .startup = &m88e1011s_startup,
668 .shutdown = &genphy_shutdown,
669};
670
Phil Edworthy998640b2016-12-12 12:54:14 +0000671/*
672 * This supports:
673 * 88E1518, uid 0x1410dd1
674 * 88E1512, uid 0x1410dd4
675 */
Michal Simek14151072012-10-15 14:03:00 +0200676static struct phy_driver M88E1518_driver = {
677 .name = "Marvell 88E1518",
Phil Edworthy998640b2016-12-12 12:54:14 +0000678 .uid = 0x1410dd0,
679 .mask = 0xffffffa,
Michal Simek14151072012-10-15 14:03:00 +0200680 .features = PHY_GBIT_FEATURES,
Hao Zhang35fa0dd2014-10-30 18:59:43 +0200681 .config = &m88e1518_config,
Michal Simek14151072012-10-15 14:03:00 +0200682 .startup = &m88e1011s_startup,
683 .shutdown = &genphy_shutdown,
684};
685
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +0100686static struct phy_driver M88E1310_driver = {
687 .name = "Marvell 88E1310",
688 .uid = 0x01410e90,
689 .mask = 0xffffff0,
690 .features = PHY_GBIT_FEATURES,
691 .config = &m88e1310_config,
692 .startup = &m88e1011s_startup,
693 .shutdown = &genphy_shutdown,
694};
695
Dirk Eibachc52d4282017-01-11 16:00:46 +0100696static struct phy_driver M88E1680_driver = {
697 .name = "Marvell 88E1680",
698 .uid = 0x1410ed0,
699 .mask = 0xffffff0,
700 .features = PHY_GBIT_FEATURES,
701 .config = &m88e1680_config,
702 .startup = &genphy_startup,
703 .shutdown = &genphy_shutdown,
704};
705
Andy Fleming9082eea2011-04-07 21:56:05 -0500706int phy_marvell_init(void)
707{
Sebastian Hesselbarthaeceec02012-12-04 09:31:59 +0100708 phy_register(&M88E1310_driver);
Andy Fleming9082eea2011-04-07 21:56:05 -0500709 phy_register(&M88E1149S_driver);
710 phy_register(&M88E1145_driver);
711 phy_register(&M88E1121R_driver);
712 phy_register(&M88E1118_driver);
Michal Simekb4b81e82012-08-07 02:23:07 +0000713 phy_register(&M88E1118R_driver);
Andy Fleming9082eea2011-04-07 21:56:05 -0500714 phy_register(&M88E1111S_driver);
715 phy_register(&M88E1011S_driver);
Clemens Gruber8396d0a2015-06-06 14:44:58 +0200716 phy_register(&M88E1510_driver);
Michal Simek14151072012-10-15 14:03:00 +0200717 phy_register(&M88E1518_driver);
Dirk Eibachc52d4282017-01-11 16:00:46 +0100718 phy_register(&M88E1680_driver);
Andy Fleming9082eea2011-04-07 21:56:05 -0500719
720 return 0;
721}