blob: 0dde7ca1ae41572edf9e4265fdcfbcfa781dadc5 [file] [log] [blame]
Andy Fleming00db8182005-07-30 19:31:23 -04001/*
2 * drivers/net/phy/marvell.c
3 *
4 * Driver for Marvell PHYs
5 *
6 * Author: Andy Fleming
7 *
8 * Copyright (c) 2004 Freescale Semiconductor, Inc.
9 *
Michael Stapelberg3871c382013-03-11 13:56:45 +000010 * Copyright (c) 2013 Michael Stapelberg <michael@stapelberg.de>
11 *
Andy Fleming00db8182005-07-30 19:31:23 -040012 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 */
Andy Fleming00db8182005-07-30 19:31:23 -040018#include <linux/kernel.h>
Andy Fleming00db8182005-07-30 19:31:23 -040019#include <linux/string.h>
20#include <linux/errno.h>
21#include <linux/unistd.h>
Andy Fleming00db8182005-07-30 19:31:23 -040022#include <linux/interrupt.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/netdevice.h>
26#include <linux/etherdevice.h>
27#include <linux/skbuff.h>
28#include <linux/spinlock.h>
29#include <linux/mm.h>
30#include <linux/module.h>
Andy Fleming00db8182005-07-30 19:31:23 -040031#include <linux/mii.h>
32#include <linux/ethtool.h>
33#include <linux/phy.h>
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +100034#include <linux/marvell_phy.h>
David Daneycf41a512010-11-19 12:13:18 +000035#include <linux/of.h>
Andy Fleming00db8182005-07-30 19:31:23 -040036
Avinash Kumareea3b202013-09-30 09:36:44 +053037#include <linux/io.h>
Andy Fleming00db8182005-07-30 19:31:23 -040038#include <asm/irq.h>
Avinash Kumareea3b202013-09-30 09:36:44 +053039#include <linux/uaccess.h>
Andy Fleming00db8182005-07-30 19:31:23 -040040
David Daney27d916d2010-11-19 11:58:52 +000041#define MII_MARVELL_PHY_PAGE 22
42
Andy Fleming00db8182005-07-30 19:31:23 -040043#define MII_M1011_IEVENT 0x13
44#define MII_M1011_IEVENT_CLEAR 0x0000
45
46#define MII_M1011_IMASK 0x12
47#define MII_M1011_IMASK_INIT 0x6400
48#define MII_M1011_IMASK_CLEAR 0x0000
49
Andy Fleming76884672007-02-09 18:13:58 -060050#define MII_M1011_PHY_SCR 0x10
David Thomson239aa552015-07-10 16:28:25 +120051#define MII_M1011_PHY_SCR_MDI 0x0000
52#define MII_M1011_PHY_SCR_MDI_X 0x0020
Andy Fleming76884672007-02-09 18:13:58 -060053#define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060
54
Madalin Bucur07151bc2015-08-07 17:07:50 +080055#define MII_M1145_PHY_EXT_ADDR_PAGE 0x16
Viet Nga Daob0224172014-10-23 19:41:53 -070056#define MII_M1145_PHY_EXT_SR 0x1b
Andy Fleming76884672007-02-09 18:13:58 -060057#define MII_M1145_PHY_EXT_CR 0x14
58#define MII_M1145_RGMII_RX_DELAY 0x0080
59#define MII_M1145_RGMII_TX_DELAY 0x0002
Viet Nga Daob0224172014-10-23 19:41:53 -070060#define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4
61#define MII_M1145_HWCFG_MODE_MASK 0xf
62#define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000
Andy Fleming76884672007-02-09 18:13:58 -060063
Vince Bridgers99d881f2014-10-26 14:22:24 -050064#define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4
65#define MII_M1145_HWCFG_MODE_MASK 0xf
66#define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000
67
Andy Fleming76884672007-02-09 18:13:58 -060068#define MII_M1111_PHY_LED_CONTROL 0x18
69#define MII_M1111_PHY_LED_DIRECT 0x4100
70#define MII_M1111_PHY_LED_COMBINE 0x411c
Kim Phillips895ee682007-06-05 18:46:47 +080071#define MII_M1111_PHY_EXT_CR 0x14
72#define MII_M1111_RX_DELAY 0x80
73#define MII_M1111_TX_DELAY 0x2
74#define MII_M1111_PHY_EXT_SR 0x1b
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030075
76#define MII_M1111_HWCFG_MODE_MASK 0xf
77#define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
78#define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3
Kapil Juneja4117b5b2007-05-11 18:25:18 -050079#define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +000080#define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
Alexandr Smirnovbe937f12008-03-19 00:37:24 +030081#define MII_M1111_HWCFG_FIBER_COPPER_AUTO 0x8000
82#define MII_M1111_HWCFG_FIBER_COPPER_RES 0x2000
83
84#define MII_M1111_COPPER 0
85#define MII_M1111_FIBER 1
86
Cyril Chemparathyc477d042010-08-02 09:44:53 +000087#define MII_88E1121_PHY_MSCR_PAGE 2
88#define MII_88E1121_PHY_MSCR_REG 21
89#define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
90#define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
91#define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4))
92
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -070093#define MII_88E1318S_PHY_MSCR1_REG 16
94#define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -070095
Michael Stapelberg3871c382013-03-11 13:56:45 +000096/* Copper Specific Interrupt Enable Register */
97#define MII_88E1318S_PHY_CSIER 0x12
98/* WOL Event Interrupt Enable */
99#define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
100
101/* LED Timer Control Register */
102#define MII_88E1318S_PHY_LED_PAGE 0x03
103#define MII_88E1318S_PHY_LED_TCR 0x12
104#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
105#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
106#define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
107
108/* Magic Packet MAC address registers */
109#define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
110#define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18
111#define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19
112
113#define MII_88E1318S_PHY_WOL_PAGE 0x11
114#define MII_88E1318S_PHY_WOL_CTRL 0x10
115#define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12)
116#define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14)
117
Sergei Poselenov140bc922009-04-07 02:01:41 +0000118#define MII_88E1121_PHY_LED_CTRL 16
119#define MII_88E1121_PHY_LED_PAGE 3
120#define MII_88E1121_PHY_LED_DEF 0x0030
Sergei Poselenov140bc922009-04-07 02:01:41 +0000121
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300122#define MII_M1011_PHY_STATUS 0x11
123#define MII_M1011_PHY_STATUS_1000 0x8000
124#define MII_M1011_PHY_STATUS_100 0x4000
125#define MII_M1011_PHY_STATUS_SPD_MASK 0xc000
126#define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000
127#define MII_M1011_PHY_STATUS_RESOLVED 0x0800
128#define MII_M1011_PHY_STATUS_LINK 0x0400
129
Michal Simek3da09a52013-05-30 20:08:26 +0000130#define MII_M1116R_CONTROL_REG_MAC 21
131
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200132#define MII_88E3016_PHY_SPEC_CTRL 0x10
133#define MII_88E3016_DISABLE_SCRAMBLER 0x0200
134#define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030
Andy Fleming76884672007-02-09 18:13:58 -0600135
Stefan Roese930b37e2016-02-18 10:59:07 +0100136#define MII_88E1510_GEN_CTRL_REG_1 0x14
137#define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7
138#define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */
139#define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */
140
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200141#define LPA_FIBER_1000HALF 0x40
142#define LPA_FIBER_1000FULL 0x20
143
144#define LPA_PAUSE_FIBER 0x180
145#define LPA_PAUSE_ASYM_FIBER 0x100
146
147#define ADVERTISE_FIBER_1000HALF 0x40
148#define ADVERTISE_FIBER_1000FULL 0x20
149
150#define ADVERTISE_PAUSE_FIBER 0x180
151#define ADVERTISE_PAUSE_ASYM_FIBER 0x100
152
153#define REGISTER_LINK_STATUS 0x400
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200154#define NB_FIBER_STATS 1
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200155
Andy Fleming00db8182005-07-30 19:31:23 -0400156MODULE_DESCRIPTION("Marvell PHY driver");
157MODULE_AUTHOR("Andy Fleming");
158MODULE_LICENSE("GPL");
159
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100160struct marvell_hw_stat {
161 const char *string;
162 u8 page;
163 u8 reg;
164 u8 bits;
165};
166
167static struct marvell_hw_stat marvell_hw_stats[] = {
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200168 { "phy_receive_errors_copper", 0, 21, 16},
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100169 { "phy_idle_errors", 0, 10, 8 },
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +0200170 { "phy_receive_errors_fiber", 1, 21, 16},
Andrew Lunnd2fa47d2015-12-30 16:28:26 +0100171};
172
173struct marvell_priv {
174 u64 stats[ARRAY_SIZE(marvell_hw_stats)];
175};
176
Andy Fleming00db8182005-07-30 19:31:23 -0400177static int marvell_ack_interrupt(struct phy_device *phydev)
178{
179 int err;
180
181 /* Clear the interrupts by reading the reg */
182 err = phy_read(phydev, MII_M1011_IEVENT);
183
184 if (err < 0)
185 return err;
186
187 return 0;
188}
189
190static int marvell_config_intr(struct phy_device *phydev)
191{
192 int err;
193
Andy Fleming76884672007-02-09 18:13:58 -0600194 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
Andy Fleming00db8182005-07-30 19:31:23 -0400195 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
196 else
197 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
198
199 return err;
200}
201
David Thomson239aa552015-07-10 16:28:25 +1200202static int marvell_set_polarity(struct phy_device *phydev, int polarity)
203{
204 int reg;
205 int err;
206 int val;
207
208 /* get the current settings */
209 reg = phy_read(phydev, MII_M1011_PHY_SCR);
210 if (reg < 0)
211 return reg;
212
213 val = reg;
214 val &= ~MII_M1011_PHY_SCR_AUTO_CROSS;
215 switch (polarity) {
216 case ETH_TP_MDI:
217 val |= MII_M1011_PHY_SCR_MDI;
218 break;
219 case ETH_TP_MDI_X:
220 val |= MII_M1011_PHY_SCR_MDI_X;
221 break;
222 case ETH_TP_MDI_AUTO:
223 case ETH_TP_MDI_INVALID:
224 default:
225 val |= MII_M1011_PHY_SCR_AUTO_CROSS;
226 break;
227 }
228
229 if (val != reg) {
230 /* Set the new polarity value in the register */
231 err = phy_write(phydev, MII_M1011_PHY_SCR, val);
232 if (err)
233 return err;
234 }
235
236 return 0;
237}
238
Andy Fleming00db8182005-07-30 19:31:23 -0400239static int marvell_config_aneg(struct phy_device *phydev)
240{
241 int err;
242
243 /* The Marvell PHY has an errata which requires
244 * that certain registers get written in order
245 * to restart autonegotiation */
246 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
247
248 if (err < 0)
249 return err;
250
251 err = phy_write(phydev, 0x1d, 0x1f);
252 if (err < 0)
253 return err;
254
255 err = phy_write(phydev, 0x1e, 0x200c);
256 if (err < 0)
257 return err;
258
259 err = phy_write(phydev, 0x1d, 0x5);
260 if (err < 0)
261 return err;
262
263 err = phy_write(phydev, 0x1e, 0);
264 if (err < 0)
265 return err;
266
267 err = phy_write(phydev, 0x1e, 0x100);
268 if (err < 0)
269 return err;
270
David Thomson239aa552015-07-10 16:28:25 +1200271 err = marvell_set_polarity(phydev, phydev->mdix);
Andy Fleming76884672007-02-09 18:13:58 -0600272 if (err < 0)
273 return err;
274
275 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
276 MII_M1111_PHY_LED_DIRECT);
277 if (err < 0)
278 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400279
280 err = genphy_config_aneg(phydev);
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000281 if (err < 0)
282 return err;
Andy Fleming00db8182005-07-30 19:31:23 -0400283
Anton Vorontsov8ff44982009-09-09 16:01:30 +0000284 if (phydev->autoneg != AUTONEG_ENABLE) {
285 int bmcr;
286
287 /*
288 * A write to speed/duplex bits (that is performed by
289 * genphy_config_aneg() call above) must be followed by
290 * a software reset. Otherwise, the write has no effect.
291 */
292 bmcr = phy_read(phydev, MII_BMCR);
293 if (bmcr < 0)
294 return bmcr;
295
296 err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET);
297 if (err < 0)
298 return err;
299 }
300
301 return 0;
Andy Fleming00db8182005-07-30 19:31:23 -0400302}
303
Harini Katakam3ec0a0f2016-06-27 13:09:59 +0530304static int m88e1111_config_aneg(struct phy_device *phydev)
305{
306 int err;
307
308 /* The Marvell PHY has an errata which requires
309 * that certain registers get written in order
310 * to restart autonegotiation
311 */
312 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
313
314 err = marvell_set_polarity(phydev, phydev->mdix);
315 if (err < 0)
316 return err;
317
318 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
319 MII_M1111_PHY_LED_DIRECT);
320 if (err < 0)
321 return err;
322
323 err = genphy_config_aneg(phydev);
324 if (err < 0)
325 return err;
326
327 if (phydev->autoneg != AUTONEG_ENABLE) {
328 int bmcr;
329
330 /* A write to speed/duplex bits (that is performed by
331 * genphy_config_aneg() call above) must be followed by
332 * a software reset. Otherwise, the write has no effect.
333 */
334 bmcr = phy_read(phydev, MII_BMCR);
335 if (bmcr < 0)
336 return bmcr;
337
338 err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET);
339 if (err < 0)
340 return err;
341 }
342
343 return 0;
344}
345
David Daneycf41a512010-11-19 12:13:18 +0000346#ifdef CONFIG_OF_MDIO
347/*
348 * Set and/or override some configuration registers based on the
349 * marvell,reg-init property stored in the of_node for the phydev.
350 *
351 * marvell,reg-init = <reg-page reg mask value>,...;
352 *
353 * There may be one or more sets of <reg-page reg mask value>:
354 *
355 * reg-page: which register bank to use.
356 * reg: the register.
357 * mask: if non-zero, ANDed with existing register value.
358 * value: ORed with the masked value and written to the regiser.
359 *
360 */
361static int marvell_of_reg_init(struct phy_device *phydev)
362{
363 const __be32 *paddr;
364 int len, i, saved_page, current_page, page_changed, ret;
365
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100366 if (!phydev->mdio.dev.of_node)
David Daneycf41a512010-11-19 12:13:18 +0000367 return 0;
368
Andrew Lunne5a03bf2016-01-06 20:11:16 +0100369 paddr = of_get_property(phydev->mdio.dev.of_node,
370 "marvell,reg-init", &len);
David Daneycf41a512010-11-19 12:13:18 +0000371 if (!paddr || len < (4 * sizeof(*paddr)))
372 return 0;
373
374 saved_page = phy_read(phydev, MII_MARVELL_PHY_PAGE);
375 if (saved_page < 0)
376 return saved_page;
377 page_changed = 0;
378 current_page = saved_page;
379
380 ret = 0;
381 len /= sizeof(*paddr);
382 for (i = 0; i < len - 3; i += 4) {
383 u16 reg_page = be32_to_cpup(paddr + i);
384 u16 reg = be32_to_cpup(paddr + i + 1);
385 u16 mask = be32_to_cpup(paddr + i + 2);
386 u16 val_bits = be32_to_cpup(paddr + i + 3);
387 int val;
388
389 if (reg_page != current_page) {
390 current_page = reg_page;
391 page_changed = 1;
392 ret = phy_write(phydev, MII_MARVELL_PHY_PAGE, reg_page);
393 if (ret < 0)
394 goto err;
395 }
396
397 val = 0;
398 if (mask) {
399 val = phy_read(phydev, reg);
400 if (val < 0) {
401 ret = val;
402 goto err;
403 }
404 val &= mask;
405 }
406 val |= val_bits;
407
408 ret = phy_write(phydev, reg, val);
409 if (ret < 0)
410 goto err;
411
412 }
413err:
414 if (page_changed) {
415 i = phy_write(phydev, MII_MARVELL_PHY_PAGE, saved_page);
416 if (ret == 0)
417 ret = i;
418 }
419 return ret;
420}
421#else
422static int marvell_of_reg_init(struct phy_device *phydev)
423{
424 return 0;
425}
426#endif /* CONFIG_OF_MDIO */
427
Sergei Poselenov140bc922009-04-07 02:01:41 +0000428static int m88e1121_config_aneg(struct phy_device *phydev)
429{
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000430 int err, oldpage, mscr;
431
David Daney27d916d2010-11-19 11:58:52 +0000432 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000433
David Daney27d916d2010-11-19 11:58:52 +0000434 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000435 MII_88E1121_PHY_MSCR_PAGE);
436 if (err < 0)
437 return err;
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000438
Florian Fainelli32a64162015-05-26 12:19:59 -0700439 if (phy_interface_is_rgmii(phydev)) {
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000440
Arnaud Patardbe8c6482010-10-21 03:59:57 -0700441 mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) &
442 MII_88E1121_PHY_MSCR_DELAY_MASK;
443
444 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
445 mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY |
446 MII_88E1121_PHY_MSCR_TX_DELAY);
447 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
448 mscr |= MII_88E1121_PHY_MSCR_RX_DELAY;
449 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
450 mscr |= MII_88E1121_PHY_MSCR_TX_DELAY;
451
452 err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr);
453 if (err < 0)
454 return err;
455 }
Cyril Chemparathyc477d042010-08-02 09:44:53 +0000456
David Daney27d916d2010-11-19 11:58:52 +0000457 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000458
459 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
460 if (err < 0)
461 return err;
462
463 err = phy_write(phydev, MII_M1011_PHY_SCR,
464 MII_M1011_PHY_SCR_AUTO_CROSS);
465 if (err < 0)
466 return err;
467
Clemens Gruberfdecf362016-06-11 17:21:26 +0200468 return genphy_config_aneg(phydev);
Sergei Poselenov140bc922009-04-07 02:01:41 +0000469}
470
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700471static int m88e1318_config_aneg(struct phy_device *phydev)
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700472{
473 int err, oldpage, mscr;
474
David Daney27d916d2010-11-19 11:58:52 +0000475 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700476
David Daney27d916d2010-11-19 11:58:52 +0000477 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700478 MII_88E1121_PHY_MSCR_PAGE);
479 if (err < 0)
480 return err;
481
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700482 mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG);
483 mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD;
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700484
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -0700485 err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700486 if (err < 0)
487 return err;
488
David Daney27d916d2010-11-19 11:58:52 +0000489 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -0700490 if (err < 0)
491 return err;
492
493 return m88e1121_config_aneg(phydev);
494}
495
Michal Simek10e24caa2013-05-30 20:08:27 +0000496static int m88e1510_config_aneg(struct phy_device *phydev)
497{
498 int err;
499
500 err = m88e1318_config_aneg(phydev);
501 if (err < 0)
502 return err;
503
Clemens Gruber79be1a12016-02-15 23:46:45 +0100504 return 0;
505}
506
507static int marvell_config_init(struct phy_device *phydev)
508{
509 /* Set registers from marvell,reg-init DT property */
Michal Simek10e24caa2013-05-30 20:08:27 +0000510 return marvell_of_reg_init(phydev);
511}
512
Michal Simek3da09a52013-05-30 20:08:26 +0000513static int m88e1116r_config_init(struct phy_device *phydev)
514{
515 int temp;
516 int err;
517
518 temp = phy_read(phydev, MII_BMCR);
519 temp |= BMCR_RESET;
520 err = phy_write(phydev, MII_BMCR, temp);
521 if (err < 0)
522 return err;
523
524 mdelay(500);
525
526 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
527 if (err < 0)
528 return err;
529
530 temp = phy_read(phydev, MII_M1011_PHY_SCR);
531 temp |= (7 << 12); /* max number of gigabit attempts */
532 temp |= (1 << 11); /* enable downshift */
533 temp |= MII_M1011_PHY_SCR_AUTO_CROSS;
534 err = phy_write(phydev, MII_M1011_PHY_SCR, temp);
535 if (err < 0)
536 return err;
537
538 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 2);
539 if (err < 0)
540 return err;
541 temp = phy_read(phydev, MII_M1116R_CONTROL_REG_MAC);
542 temp |= (1 << 5);
543 temp |= (1 << 4);
544 err = phy_write(phydev, MII_M1116R_CONTROL_REG_MAC, temp);
545 if (err < 0)
546 return err;
547 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
548 if (err < 0)
549 return err;
550
551 temp = phy_read(phydev, MII_BMCR);
552 temp |= BMCR_RESET;
553 err = phy_write(phydev, MII_BMCR, temp);
554 if (err < 0)
555 return err;
556
557 mdelay(500);
558
Clemens Gruber79be1a12016-02-15 23:46:45 +0100559 return marvell_config_init(phydev);
Michal Simek3da09a52013-05-30 20:08:26 +0000560}
561
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200562static int m88e3016_config_init(struct phy_device *phydev)
563{
564 int reg;
565
566 /* Enable Scrambler and Auto-Crossover */
567 reg = phy_read(phydev, MII_88E3016_PHY_SPEC_CTRL);
568 if (reg < 0)
569 return reg;
570
571 reg &= ~MII_88E3016_DISABLE_SCRAMBLER;
572 reg |= MII_88E3016_AUTO_MDIX_CROSSOVER;
573
574 reg = phy_write(phydev, MII_88E3016_PHY_SPEC_CTRL, reg);
575 if (reg < 0)
576 return reg;
577
Clemens Gruber79be1a12016-02-15 23:46:45 +0100578 return marvell_config_init(phydev);
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +0200579}
580
Kim Phillips895ee682007-06-05 18:46:47 +0800581static int m88e1111_config_init(struct phy_device *phydev)
582{
583 int err;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300584 int temp;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300585
Florian Fainelli32a64162015-05-26 12:19:59 -0700586 if (phy_interface_is_rgmii(phydev)) {
Kim Phillips895ee682007-06-05 18:46:47 +0800587
Kim Phillips9daf5a72007-11-26 16:17:52 -0600588 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
589 if (temp < 0)
590 return temp;
591
Kim Phillips895ee682007-06-05 18:46:47 +0800592 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Kim Phillips895ee682007-06-05 18:46:47 +0800593 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
Kim Phillips9daf5a72007-11-26 16:17:52 -0600594 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
595 temp &= ~MII_M1111_TX_DELAY;
596 temp |= MII_M1111_RX_DELAY;
597 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
598 temp &= ~MII_M1111_RX_DELAY;
599 temp |= MII_M1111_TX_DELAY;
Kim Phillips895ee682007-06-05 18:46:47 +0800600 }
601
Kim Phillips9daf5a72007-11-26 16:17:52 -0600602 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
603 if (err < 0)
604 return err;
605
Kim Phillips895ee682007-06-05 18:46:47 +0800606 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
607 if (temp < 0)
608 return temp;
609
610 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300611
Wang Jian7239016d2008-07-16 21:46:20 +0800612 if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES)
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300613 temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII;
614 else
615 temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII;
Kim Phillips895ee682007-06-05 18:46:47 +0800616
617 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
618 if (err < 0)
619 return err;
620 }
621
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500622 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500623 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
624 if (temp < 0)
625 return temp;
626
627 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
628 temp |= MII_M1111_HWCFG_MODE_SGMII_NO_CLK;
Haiying Wang32d0c1e2009-06-02 04:04:13 +0000629 temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500630
631 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
632 if (err < 0)
633 return err;
Madalin Bucur07151bc2015-08-07 17:07:50 +0800634
635 /* make sure copper is selected */
636 err = phy_read(phydev, MII_M1145_PHY_EXT_ADDR_PAGE);
637 if (err < 0)
638 return err;
639
640 err = phy_write(phydev, MII_M1145_PHY_EXT_ADDR_PAGE,
641 err & (~0xff));
642 if (err < 0)
643 return err;
Kapil Juneja4117b5b2007-05-11 18:25:18 -0500644 }
645
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000646 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
647 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
648 if (temp < 0)
649 return temp;
650 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
651 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
652 if (err < 0)
653 return err;
654
655 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
656 if (temp < 0)
657 return temp;
658 temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
659 temp |= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
660 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
661 if (err < 0)
662 return err;
663
664 /* soft reset */
665 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
666 if (err < 0)
667 return err;
668 do
669 temp = phy_read(phydev, MII_BMCR);
670 while (temp & BMCR_RESET);
671
672 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
673 if (temp < 0)
674 return temp;
675 temp &= ~(MII_M1111_HWCFG_MODE_MASK | MII_M1111_HWCFG_FIBER_COPPER_RES);
676 temp |= MII_M1111_HWCFG_MODE_COPPER_RTBI | MII_M1111_HWCFG_FIBER_COPPER_AUTO;
677 err = phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
678 if (err < 0)
679 return err;
680 }
681
David Daneycf41a512010-11-19 12:13:18 +0000682 err = marvell_of_reg_init(phydev);
683 if (err < 0)
684 return err;
Liu Yu-B132015f8cbc12010-01-13 22:13:19 +0000685
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000686 return phy_write(phydev, MII_BMCR, BMCR_RESET);
Kim Phillips895ee682007-06-05 18:46:47 +0800687}
688
Clemens Gruberfdecf362016-06-11 17:21:26 +0200689static int m88e1121_config_init(struct phy_device *phydev)
690{
691 int err, oldpage;
692
693 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
694
695 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_88E1121_PHY_LED_PAGE);
696 if (err < 0)
697 return err;
698
699 /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
700 err = phy_write(phydev, MII_88E1121_PHY_LED_CTRL,
701 MII_88E1121_PHY_LED_DEF);
702 if (err < 0)
703 return err;
704
705 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
706
707 /* Set marvell,reg-init configuration from device tree */
708 return marvell_config_init(phydev);
709}
710
Clemens Gruber407353e2016-02-23 20:16:58 +0100711static int m88e1510_config_init(struct phy_device *phydev)
712{
713 int err;
714 int temp;
715
716 /* SGMII-to-Copper mode initialization */
717 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
718 /* Select page 18 */
719 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 18);
720 if (err < 0)
721 return err;
722
723 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
724 temp = phy_read(phydev, MII_88E1510_GEN_CTRL_REG_1);
725 temp &= ~MII_88E1510_GEN_CTRL_REG_1_MODE_MASK;
726 temp |= MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII;
727 err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
728 if (err < 0)
729 return err;
730
731 /* PHY reset is necessary after changing MODE[2:0] */
732 temp |= MII_88E1510_GEN_CTRL_REG_1_RESET;
733 err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
734 if (err < 0)
735 return err;
736
737 /* Reset page selection */
738 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0);
739 if (err < 0)
740 return err;
741 }
742
Clemens Gruberfdecf362016-06-11 17:21:26 +0200743 return m88e1121_config_init(phydev);
Clemens Gruber407353e2016-02-23 20:16:58 +0100744}
745
Ron Madrid605f1962008-11-06 09:05:26 +0000746static int m88e1118_config_aneg(struct phy_device *phydev)
747{
748 int err;
749
750 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
751 if (err < 0)
752 return err;
753
754 err = phy_write(phydev, MII_M1011_PHY_SCR,
755 MII_M1011_PHY_SCR_AUTO_CROSS);
756 if (err < 0)
757 return err;
758
759 err = genphy_config_aneg(phydev);
760 return 0;
761}
762
763static int m88e1118_config_init(struct phy_device *phydev)
764{
765 int err;
766
767 /* Change address */
David Daney27d916d2010-11-19 11:58:52 +0000768 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
Ron Madrid605f1962008-11-06 09:05:26 +0000769 if (err < 0)
770 return err;
771
772 /* Enable 1000 Mbit */
773 err = phy_write(phydev, 0x15, 0x1070);
774 if (err < 0)
775 return err;
776
777 /* Change address */
David Daney27d916d2010-11-19 11:58:52 +0000778 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0003);
Ron Madrid605f1962008-11-06 09:05:26 +0000779 if (err < 0)
780 return err;
781
782 /* Adjust LED Control */
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000783 if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS)
784 err = phy_write(phydev, 0x10, 0x1100);
785 else
786 err = phy_write(phydev, 0x10, 0x021e);
Ron Madrid605f1962008-11-06 09:05:26 +0000787 if (err < 0)
788 return err;
789
David Daneycf41a512010-11-19 12:13:18 +0000790 err = marvell_of_reg_init(phydev);
791 if (err < 0)
792 return err;
793
Ron Madrid605f1962008-11-06 09:05:26 +0000794 /* Reset address */
David Daney27d916d2010-11-19 11:58:52 +0000795 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
Ron Madrid605f1962008-11-06 09:05:26 +0000796 if (err < 0)
797 return err;
798
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000799 return phy_write(phydev, MII_BMCR, BMCR_RESET);
Ron Madrid605f1962008-11-06 09:05:26 +0000800}
801
David Daney90600732010-11-19 11:58:53 +0000802static int m88e1149_config_init(struct phy_device *phydev)
803{
804 int err;
805
806 /* Change address */
807 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0002);
808 if (err < 0)
809 return err;
810
811 /* Enable 1000 Mbit */
812 err = phy_write(phydev, 0x15, 0x1048);
813 if (err < 0)
814 return err;
815
David Daneycf41a512010-11-19 12:13:18 +0000816 err = marvell_of_reg_init(phydev);
817 if (err < 0)
818 return err;
819
David Daney90600732010-11-19 11:58:53 +0000820 /* Reset address */
821 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x0);
822 if (err < 0)
823 return err;
824
Srinivas Kandagatlacc90cb32012-04-02 06:25:24 +0000825 return phy_write(phydev, MII_BMCR, BMCR_RESET);
David Daney90600732010-11-19 11:58:53 +0000826}
827
Andy Fleming76884672007-02-09 18:13:58 -0600828static int m88e1145_config_init(struct phy_device *phydev)
829{
830 int err;
Viet Nga Daob0224172014-10-23 19:41:53 -0700831 int temp;
Andy Fleming76884672007-02-09 18:13:58 -0600832
833 /* Take care of errata E0 & E1 */
834 err = phy_write(phydev, 0x1d, 0x001b);
835 if (err < 0)
836 return err;
837
838 err = phy_write(phydev, 0x1e, 0x418f);
839 if (err < 0)
840 return err;
841
842 err = phy_write(phydev, 0x1d, 0x0016);
843 if (err < 0)
844 return err;
845
846 err = phy_write(phydev, 0x1e, 0xa2da);
847 if (err < 0)
848 return err;
849
Kim Phillips895ee682007-06-05 18:46:47 +0800850 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
Andy Fleming76884672007-02-09 18:13:58 -0600851 int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
852 if (temp < 0)
853 return temp;
854
855 temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY);
856
857 err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp);
858 if (err < 0)
859 return err;
860
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +1000861 if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) {
Andy Fleming76884672007-02-09 18:13:58 -0600862 err = phy_write(phydev, 0x1d, 0x0012);
863 if (err < 0)
864 return err;
865
866 temp = phy_read(phydev, 0x1e);
867 if (temp < 0)
868 return temp;
869
870 temp &= 0xf03f;
871 temp |= 2 << 9; /* 36 ohm */
872 temp |= 2 << 6; /* 39 ohm */
873
874 err = phy_write(phydev, 0x1e, temp);
875 if (err < 0)
876 return err;
877
878 err = phy_write(phydev, 0x1d, 0x3);
879 if (err < 0)
880 return err;
881
882 err = phy_write(phydev, 0x1e, 0x8000);
883 if (err < 0)
884 return err;
885 }
886 }
887
Viet Nga Daob0224172014-10-23 19:41:53 -0700888 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
889 temp = phy_read(phydev, MII_M1145_PHY_EXT_SR);
890 if (temp < 0)
891 return temp;
892
Vince Bridgers99d881f2014-10-26 14:22:24 -0500893 temp &= ~MII_M1145_HWCFG_MODE_MASK;
Viet Nga Daob0224172014-10-23 19:41:53 -0700894 temp |= MII_M1145_HWCFG_MODE_SGMII_NO_CLK;
895 temp |= MII_M1145_HWCFG_FIBER_COPPER_AUTO;
896
897 err = phy_write(phydev, MII_M1145_PHY_EXT_SR, temp);
898 if (err < 0)
899 return err;
900 }
901
David Daneycf41a512010-11-19 12:13:18 +0000902 err = marvell_of_reg_init(phydev);
903 if (err < 0)
904 return err;
905
Andy Fleming76884672007-02-09 18:13:58 -0600906 return 0;
907}
Andy Fleming00db8182005-07-30 19:31:23 -0400908
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200909/**
910 * fiber_lpa_to_ethtool_lpa_t
911 * @lpa: value of the MII_LPA register for fiber link
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300912 *
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200913 * A small helper function that translates MII_LPA
914 * bits to ethtool LP advertisement settings.
915 */
916static u32 fiber_lpa_to_ethtool_lpa_t(u32 lpa)
917{
918 u32 result = 0;
919
920 if (lpa & LPA_FIBER_1000HALF)
921 result |= ADVERTISED_1000baseT_Half;
922 if (lpa & LPA_FIBER_1000FULL)
923 result |= ADVERTISED_1000baseT_Full;
924
925 return result;
926}
927
928/**
929 * marvell_update_link - update link status in real time in @phydev
930 * @phydev: target phy_device struct
931 *
932 * Description: Update the value in phydev->link to reflect the
933 * current link value.
934 */
935static int marvell_update_link(struct phy_device *phydev, int fiber)
936{
937 int status;
938
939 /* Use the generic register for copper link, or specific
940 * register for fiber case */
941 if (fiber) {
942 status = phy_read(phydev, MII_M1011_PHY_STATUS);
943 if (status < 0)
944 return status;
945
946 if ((status & REGISTER_LINK_STATUS) == 0)
947 phydev->link = 0;
948 else
949 phydev->link = 1;
950 } else {
951 return genphy_update_link(phydev);
952 }
953
954 return 0;
955}
956
957/* marvell_read_status_page
958 *
Jeff Garzikf0c88f92008-03-25 23:53:24 -0400959 * Description:
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300960 * Check the link, then figure out the current state
961 * by comparing what we advertise with what the link partner
962 * advertises. Start by checking the gigabit possibilities,
963 * then move on to 10/100.
964 */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200965static int marvell_read_status_page(struct phy_device *phydev, int page)
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300966{
967 int adv;
968 int err;
969 int lpa;
Russell King357cd642015-09-24 00:07:17 +0100970 int lpagb;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300971 int status = 0;
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200972 int fiber;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300973
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200974 /* Detect and update the link, but return if there
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300975 * was an error */
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +0200976 if (page == MII_M1111_FIBER)
977 fiber = 1;
978 else
979 fiber = 0;
980
981 err = marvell_update_link(phydev, fiber);
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300982 if (err)
983 return err;
984
985 if (AUTONEG_ENABLE == phydev->autoneg) {
986 status = phy_read(phydev, MII_M1011_PHY_STATUS);
987 if (status < 0)
988 return status;
989
990 lpa = phy_read(phydev, MII_LPA);
991 if (lpa < 0)
992 return lpa;
993
Russell King357cd642015-09-24 00:07:17 +0100994 lpagb = phy_read(phydev, MII_STAT1000);
995 if (lpagb < 0)
996 return lpagb;
997
Alexandr Smirnovbe937f12008-03-19 00:37:24 +0300998 adv = phy_read(phydev, MII_ADVERTISE);
999 if (adv < 0)
1000 return adv;
1001
1002 lpa &= adv;
1003
1004 if (status & MII_M1011_PHY_STATUS_FULLDUPLEX)
1005 phydev->duplex = DUPLEX_FULL;
1006 else
1007 phydev->duplex = DUPLEX_HALF;
1008
1009 status = status & MII_M1011_PHY_STATUS_SPD_MASK;
1010 phydev->pause = phydev->asym_pause = 0;
1011
1012 switch (status) {
1013 case MII_M1011_PHY_STATUS_1000:
1014 phydev->speed = SPEED_1000;
1015 break;
1016
1017 case MII_M1011_PHY_STATUS_100:
1018 phydev->speed = SPEED_100;
1019 break;
1020
1021 default:
1022 phydev->speed = SPEED_10;
1023 break;
1024 }
1025
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001026 if (!fiber) {
1027 phydev->lp_advertising = mii_stat1000_to_ethtool_lpa_t(lpagb) |
1028 mii_lpa_to_ethtool_lpa_t(lpa);
1029
1030 if (phydev->duplex == DUPLEX_FULL) {
1031 phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0;
1032 phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0;
1033 }
1034 } else {
1035 /* The fiber link is only 1000M capable */
1036 phydev->lp_advertising = fiber_lpa_to_ethtool_lpa_t(lpa);
1037
1038 if (phydev->duplex == DUPLEX_FULL) {
1039 if (!(lpa & LPA_PAUSE_FIBER)) {
1040 phydev->pause = 0;
1041 phydev->asym_pause = 0;
1042 } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) {
1043 phydev->pause = 1;
1044 phydev->asym_pause = 1;
1045 } else {
1046 phydev->pause = 1;
1047 phydev->asym_pause = 0;
1048 }
1049 }
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001050 }
1051 } else {
1052 int bmcr = phy_read(phydev, MII_BMCR);
1053
1054 if (bmcr < 0)
1055 return bmcr;
1056
1057 if (bmcr & BMCR_FULLDPLX)
1058 phydev->duplex = DUPLEX_FULL;
1059 else
1060 phydev->duplex = DUPLEX_HALF;
1061
1062 if (bmcr & BMCR_SPEED1000)
1063 phydev->speed = SPEED_1000;
1064 else if (bmcr & BMCR_SPEED100)
1065 phydev->speed = SPEED_100;
1066 else
1067 phydev->speed = SPEED_10;
1068
1069 phydev->pause = phydev->asym_pause = 0;
Russell King357cd642015-09-24 00:07:17 +01001070 phydev->lp_advertising = 0;
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001071 }
1072
1073 return 0;
1074}
1075
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001076/* marvell_read_status
1077 *
1078 * Some Marvell's phys have two modes: fiber and copper.
1079 * Both need status checked.
1080 * Description:
1081 * First, check the fiber link and status.
1082 * If the fiber link is down, check the copper link and status which
1083 * will be the default value if both link are down.
1084 */
1085static int marvell_read_status(struct phy_device *phydev)
1086{
1087 int err;
1088
1089 /* Check the fiber mode first */
1090 if (phydev->supported & SUPPORTED_FIBRE) {
1091 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_FIBER);
1092 if (err < 0)
1093 goto error;
1094
1095 err = marvell_read_status_page(phydev, MII_M1111_FIBER);
1096 if (err < 0)
1097 goto error;
1098
1099 /* If the fiber link is up, it is the selected and used link.
1100 * In this case, we need to stay in the fiber page.
1101 * Please to be careful about that, avoid to restore Copper page
1102 * in other functions which could break the behaviour
1103 * for some fiber phy like 88E1512.
1104 * */
1105 if (phydev->link)
1106 return 0;
1107
1108 /* If fiber link is down, check and save copper mode state */
1109 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1110 if (err < 0)
1111 goto error;
1112 }
1113
1114 return marvell_read_status_page(phydev, MII_M1111_COPPER);
1115
1116error:
1117 phy_write(phydev, MII_MARVELL_PHY_PAGE, MII_M1111_COPPER);
1118 return err;
1119}
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001120static int marvell_aneg_done(struct phy_device *phydev)
1121{
1122 int retval = phy_read(phydev, MII_M1011_PHY_STATUS);
1123 return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED);
1124}
1125
Anatolij Gustschindcd07be2009-04-07 02:01:43 +00001126static int m88e1121_did_interrupt(struct phy_device *phydev)
1127{
1128 int imask;
1129
1130 imask = phy_read(phydev, MII_M1011_IEVENT);
1131
1132 if (imask & MII_M1011_IMASK_INIT)
1133 return 1;
1134
1135 return 0;
1136}
1137
Michael Stapelberg3871c382013-03-11 13:56:45 +00001138static void m88e1318_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
1139{
1140 wol->supported = WAKE_MAGIC;
1141 wol->wolopts = 0;
1142
1143 if (phy_write(phydev, MII_MARVELL_PHY_PAGE,
1144 MII_88E1318S_PHY_WOL_PAGE) < 0)
1145 return;
1146
1147 if (phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL) &
1148 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
1149 wol->wolopts |= WAKE_MAGIC;
1150
1151 if (phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00) < 0)
1152 return;
1153}
1154
1155static int m88e1318_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
1156{
1157 int err, oldpage, temp;
1158
1159 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
1160
1161 if (wol->wolopts & WAKE_MAGIC) {
1162 /* Explicitly switch to page 0x00, just to be sure */
1163 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, 0x00);
1164 if (err < 0)
1165 return err;
1166
1167 /* Enable the WOL interrupt */
1168 temp = phy_read(phydev, MII_88E1318S_PHY_CSIER);
1169 temp |= MII_88E1318S_PHY_CSIER_WOL_EIE;
1170 err = phy_write(phydev, MII_88E1318S_PHY_CSIER, temp);
1171 if (err < 0)
1172 return err;
1173
1174 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1175 MII_88E1318S_PHY_LED_PAGE);
1176 if (err < 0)
1177 return err;
1178
1179 /* Setup LED[2] as interrupt pin (active low) */
1180 temp = phy_read(phydev, MII_88E1318S_PHY_LED_TCR);
1181 temp &= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT;
1182 temp |= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE;
1183 temp |= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW;
1184 err = phy_write(phydev, MII_88E1318S_PHY_LED_TCR, temp);
1185 if (err < 0)
1186 return err;
1187
1188 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1189 MII_88E1318S_PHY_WOL_PAGE);
1190 if (err < 0)
1191 return err;
1192
1193 /* Store the device address for the magic packet */
1194 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2,
1195 ((phydev->attached_dev->dev_addr[5] << 8) |
1196 phydev->attached_dev->dev_addr[4]));
1197 if (err < 0)
1198 return err;
1199 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1,
1200 ((phydev->attached_dev->dev_addr[3] << 8) |
1201 phydev->attached_dev->dev_addr[2]));
1202 if (err < 0)
1203 return err;
1204 err = phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0,
1205 ((phydev->attached_dev->dev_addr[1] << 8) |
1206 phydev->attached_dev->dev_addr[0]));
1207 if (err < 0)
1208 return err;
1209
1210 /* Clear WOL status and enable magic packet matching */
1211 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
1212 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
1213 temp |= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
1214 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
1215 if (err < 0)
1216 return err;
1217 } else {
1218 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1219 MII_88E1318S_PHY_WOL_PAGE);
1220 if (err < 0)
1221 return err;
1222
1223 /* Clear WOL status and disable magic packet matching */
1224 temp = phy_read(phydev, MII_88E1318S_PHY_WOL_CTRL);
1225 temp |= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS;
1226 temp &= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE;
1227 err = phy_write(phydev, MII_88E1318S_PHY_WOL_CTRL, temp);
1228 if (err < 0)
1229 return err;
1230 }
1231
1232 err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
1233 if (err < 0)
1234 return err;
1235
1236 return 0;
1237}
1238
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001239static int marvell_get_sset_count(struct phy_device *phydev)
1240{
Charles-Antoine Couret2170fef2016-07-19 11:13:11 +02001241 if (phydev->supported & SUPPORTED_FIBRE)
1242 return ARRAY_SIZE(marvell_hw_stats);
1243 else
1244 return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001245}
1246
1247static void marvell_get_strings(struct phy_device *phydev, u8 *data)
1248{
1249 int i;
1250
1251 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) {
1252 memcpy(data + i * ETH_GSTRING_LEN,
1253 marvell_hw_stats[i].string, ETH_GSTRING_LEN);
1254 }
1255}
1256
1257#ifndef UINT64_MAX
1258#define UINT64_MAX (u64)(~((u64)0))
1259#endif
1260static u64 marvell_get_stat(struct phy_device *phydev, int i)
1261{
1262 struct marvell_hw_stat stat = marvell_hw_stats[i];
1263 struct marvell_priv *priv = phydev->priv;
Andrew Lunn321b4d42016-02-20 00:35:29 +01001264 int err, oldpage, val;
1265 u64 ret;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001266
1267 oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
1268 err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
1269 stat.page);
1270 if (err < 0)
1271 return UINT64_MAX;
1272
1273 val = phy_read(phydev, stat.reg);
1274 if (val < 0) {
Andrew Lunn321b4d42016-02-20 00:35:29 +01001275 ret = UINT64_MAX;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001276 } else {
1277 val = val & ((1 << stat.bits) - 1);
1278 priv->stats[i] += val;
Andrew Lunn321b4d42016-02-20 00:35:29 +01001279 ret = priv->stats[i];
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001280 }
1281
1282 phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
1283
Andrew Lunn321b4d42016-02-20 00:35:29 +01001284 return ret;
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001285}
1286
1287static void marvell_get_stats(struct phy_device *phydev,
1288 struct ethtool_stats *stats, u64 *data)
1289{
1290 int i;
1291
1292 for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++)
1293 data[i] = marvell_get_stat(phydev, i);
1294}
1295
1296static int marvell_probe(struct phy_device *phydev)
1297{
1298 struct marvell_priv *priv;
1299
Andrew Lunne5a03bf2016-01-06 20:11:16 +01001300 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001301 if (!priv)
1302 return -ENOMEM;
1303
1304 phydev->priv = priv;
1305
1306 return 0;
1307}
1308
Olof Johanssone5479232007-07-03 16:23:46 -05001309static struct phy_driver marvell_drivers[] = {
1310 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001311 .phy_id = MARVELL_PHY_ID_88E1101,
1312 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001313 .name = "Marvell 88E1101",
1314 .features = PHY_GBIT_FEATURES,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001315 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05001316 .flags = PHY_HAS_INTERRUPT,
Clemens Gruber79be1a12016-02-15 23:46:45 +01001317 .config_init = &marvell_config_init,
Olof Johanssone5479232007-07-03 16:23:46 -05001318 .config_aneg = &marvell_config_aneg,
1319 .read_status = &genphy_read_status,
1320 .ack_interrupt = &marvell_ack_interrupt,
1321 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001322 .resume = &genphy_resume,
1323 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001324 .get_sset_count = marvell_get_sset_count,
1325 .get_strings = marvell_get_strings,
1326 .get_stats = marvell_get_stats,
Olof Johanssone5479232007-07-03 16:23:46 -05001327 },
1328 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001329 .phy_id = MARVELL_PHY_ID_88E1112,
1330 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johansson85cfb532007-07-03 16:24:32 -05001331 .name = "Marvell 88E1112",
1332 .features = PHY_GBIT_FEATURES,
1333 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001334 .probe = marvell_probe,
Olof Johansson85cfb532007-07-03 16:24:32 -05001335 .config_init = &m88e1111_config_init,
1336 .config_aneg = &marvell_config_aneg,
1337 .read_status = &genphy_read_status,
1338 .ack_interrupt = &marvell_ack_interrupt,
1339 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001340 .resume = &genphy_resume,
1341 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001342 .get_sset_count = marvell_get_sset_count,
1343 .get_strings = marvell_get_strings,
1344 .get_stats = marvell_get_stats,
Olof Johansson85cfb532007-07-03 16:24:32 -05001345 },
1346 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001347 .phy_id = MARVELL_PHY_ID_88E1111,
1348 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001349 .name = "Marvell 88E1111",
1350 .features = PHY_GBIT_FEATURES,
1351 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001352 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05001353 .config_init = &m88e1111_config_init,
Harini Katakam3ec0a0f2016-06-27 13:09:59 +05301354 .config_aneg = &m88e1111_config_aneg,
Alexandr Smirnovbe937f12008-03-19 00:37:24 +03001355 .read_status = &marvell_read_status,
Olof Johanssone5479232007-07-03 16:23:46 -05001356 .ack_interrupt = &marvell_ack_interrupt,
1357 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001358 .resume = &genphy_resume,
1359 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001360 .get_sset_count = marvell_get_sset_count,
1361 .get_strings = marvell_get_strings,
1362 .get_stats = marvell_get_stats,
Olof Johanssone5479232007-07-03 16:23:46 -05001363 },
1364 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001365 .phy_id = MARVELL_PHY_ID_88E1118,
1366 .phy_id_mask = MARVELL_PHY_ID_MASK,
Ron Madrid605f1962008-11-06 09:05:26 +00001367 .name = "Marvell 88E1118",
1368 .features = PHY_GBIT_FEATURES,
1369 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001370 .probe = marvell_probe,
Ron Madrid605f1962008-11-06 09:05:26 +00001371 .config_init = &m88e1118_config_init,
1372 .config_aneg = &m88e1118_config_aneg,
1373 .read_status = &genphy_read_status,
1374 .ack_interrupt = &marvell_ack_interrupt,
1375 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001376 .resume = &genphy_resume,
1377 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001378 .get_sset_count = marvell_get_sset_count,
1379 .get_strings = marvell_get_strings,
1380 .get_stats = marvell_get_stats,
Ron Madrid605f1962008-11-06 09:05:26 +00001381 },
1382 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001383 .phy_id = MARVELL_PHY_ID_88E1121R,
1384 .phy_id_mask = MARVELL_PHY_ID_MASK,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001385 .name = "Marvell 88E1121R",
1386 .features = PHY_GBIT_FEATURES,
1387 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001388 .probe = marvell_probe,
Clemens Gruberfdecf362016-06-11 17:21:26 +02001389 .config_init = &m88e1121_config_init,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001390 .config_aneg = &m88e1121_config_aneg,
1391 .read_status = &marvell_read_status,
1392 .ack_interrupt = &marvell_ack_interrupt,
1393 .config_intr = &marvell_config_intr,
Anatolij Gustschindcd07be2009-04-07 02:01:43 +00001394 .did_interrupt = &m88e1121_did_interrupt,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001395 .resume = &genphy_resume,
1396 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001397 .get_sset_count = marvell_get_sset_count,
1398 .get_strings = marvell_get_strings,
1399 .get_stats = marvell_get_stats,
Sergei Poselenov140bc922009-04-07 02:01:41 +00001400 },
1401 {
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001402 .phy_id = MARVELL_PHY_ID_88E1318S,
Linus Torvalds6ba74012010-08-04 11:47:58 -07001403 .phy_id_mask = MARVELL_PHY_ID_MASK,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001404 .name = "Marvell 88E1318S",
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07001405 .features = PHY_GBIT_FEATURES,
1406 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001407 .probe = marvell_probe,
Clemens Gruberfdecf362016-06-11 17:21:26 +02001408 .config_init = &m88e1121_config_init,
Cyril Chemparathy337ac9d2010-10-29 13:50:25 -07001409 .config_aneg = &m88e1318_config_aneg,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07001410 .read_status = &marvell_read_status,
1411 .ack_interrupt = &marvell_ack_interrupt,
1412 .config_intr = &marvell_config_intr,
1413 .did_interrupt = &m88e1121_did_interrupt,
Michael Stapelberg3871c382013-03-11 13:56:45 +00001414 .get_wol = &m88e1318_get_wol,
1415 .set_wol = &m88e1318_set_wol,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001416 .resume = &genphy_resume,
1417 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001418 .get_sset_count = marvell_get_sset_count,
1419 .get_strings = marvell_get_strings,
1420 .get_stats = marvell_get_stats,
Cyril Chemparathy3ff1c252010-08-03 19:36:06 -07001421 },
1422 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001423 .phy_id = MARVELL_PHY_ID_88E1145,
1424 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssone5479232007-07-03 16:23:46 -05001425 .name = "Marvell 88E1145",
1426 .features = PHY_GBIT_FEATURES,
1427 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001428 .probe = marvell_probe,
Olof Johanssone5479232007-07-03 16:23:46 -05001429 .config_init = &m88e1145_config_init,
1430 .config_aneg = &marvell_config_aneg,
1431 .read_status = &genphy_read_status,
1432 .ack_interrupt = &marvell_ack_interrupt,
1433 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001434 .resume = &genphy_resume,
1435 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001436 .get_sset_count = marvell_get_sset_count,
1437 .get_strings = marvell_get_strings,
1438 .get_stats = marvell_get_stats,
Olof Johanssonac8c6352007-11-04 16:08:51 -06001439 },
1440 {
David Daney90600732010-11-19 11:58:53 +00001441 .phy_id = MARVELL_PHY_ID_88E1149R,
1442 .phy_id_mask = MARVELL_PHY_ID_MASK,
1443 .name = "Marvell 88E1149R",
1444 .features = PHY_GBIT_FEATURES,
1445 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001446 .probe = marvell_probe,
David Daney90600732010-11-19 11:58:53 +00001447 .config_init = &m88e1149_config_init,
1448 .config_aneg = &m88e1118_config_aneg,
1449 .read_status = &genphy_read_status,
1450 .ack_interrupt = &marvell_ack_interrupt,
1451 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001452 .resume = &genphy_resume,
1453 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001454 .get_sset_count = marvell_get_sset_count,
1455 .get_strings = marvell_get_strings,
1456 .get_stats = marvell_get_stats,
David Daney90600732010-11-19 11:58:53 +00001457 },
1458 {
Benjamin Herrenschmidt2f495c32010-06-21 13:20:46 +10001459 .phy_id = MARVELL_PHY_ID_88E1240,
1460 .phy_id_mask = MARVELL_PHY_ID_MASK,
Olof Johanssonac8c6352007-11-04 16:08:51 -06001461 .name = "Marvell 88E1240",
1462 .features = PHY_GBIT_FEATURES,
1463 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001464 .probe = marvell_probe,
Olof Johanssonac8c6352007-11-04 16:08:51 -06001465 .config_init = &m88e1111_config_init,
1466 .config_aneg = &marvell_config_aneg,
1467 .read_status = &genphy_read_status,
1468 .ack_interrupt = &marvell_ack_interrupt,
1469 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001470 .resume = &genphy_resume,
1471 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001472 .get_sset_count = marvell_get_sset_count,
1473 .get_strings = marvell_get_strings,
1474 .get_stats = marvell_get_stats,
Olof Johanssonac8c6352007-11-04 16:08:51 -06001475 },
Michal Simek3da09a52013-05-30 20:08:26 +00001476 {
1477 .phy_id = MARVELL_PHY_ID_88E1116R,
1478 .phy_id_mask = MARVELL_PHY_ID_MASK,
1479 .name = "Marvell 88E1116R",
1480 .features = PHY_GBIT_FEATURES,
1481 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001482 .probe = marvell_probe,
Michal Simek3da09a52013-05-30 20:08:26 +00001483 .config_init = &m88e1116r_config_init,
1484 .config_aneg = &genphy_config_aneg,
1485 .read_status = &genphy_read_status,
1486 .ack_interrupt = &marvell_ack_interrupt,
1487 .config_intr = &marvell_config_intr,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001488 .resume = &genphy_resume,
1489 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001490 .get_sset_count = marvell_get_sset_count,
1491 .get_strings = marvell_get_strings,
1492 .get_stats = marvell_get_stats,
Michal Simek3da09a52013-05-30 20:08:26 +00001493 },
Michal Simek10e24caa2013-05-30 20:08:27 +00001494 {
1495 .phy_id = MARVELL_PHY_ID_88E1510,
1496 .phy_id_mask = MARVELL_PHY_ID_MASK,
1497 .name = "Marvell 88E1510",
Charles-Antoine Couret6cfb3bc2016-07-19 11:13:10 +02001498 .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE,
Michal Simek10e24caa2013-05-30 20:08:27 +00001499 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001500 .probe = marvell_probe,
Stefan Roese930b37e2016-02-18 10:59:07 +01001501 .config_init = &m88e1510_config_init,
Michal Simek10e24caa2013-05-30 20:08:27 +00001502 .config_aneg = &m88e1510_config_aneg,
1503 .read_status = &marvell_read_status,
1504 .ack_interrupt = &marvell_ack_interrupt,
1505 .config_intr = &marvell_config_intr,
1506 .did_interrupt = &m88e1121_did_interrupt,
Sebastian Hesselbarth0898b442013-12-13 10:20:26 +01001507 .resume = &genphy_resume,
1508 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001509 .get_sset_count = marvell_get_sset_count,
1510 .get_strings = marvell_get_strings,
1511 .get_stats = marvell_get_stats,
Michal Simek10e24caa2013-05-30 20:08:27 +00001512 },
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001513 {
Andrew Lunn819ec8e2015-11-16 23:34:41 +01001514 .phy_id = MARVELL_PHY_ID_88E1540,
1515 .phy_id_mask = MARVELL_PHY_ID_MASK,
1516 .name = "Marvell 88E1540",
1517 .features = PHY_GBIT_FEATURES,
1518 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001519 .probe = marvell_probe,
Clemens Gruber79be1a12016-02-15 23:46:45 +01001520 .config_init = &marvell_config_init,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01001521 .config_aneg = &m88e1510_config_aneg,
1522 .read_status = &marvell_read_status,
1523 .ack_interrupt = &marvell_ack_interrupt,
1524 .config_intr = &marvell_config_intr,
1525 .did_interrupt = &m88e1121_did_interrupt,
1526 .resume = &genphy_resume,
1527 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001528 .get_sset_count = marvell_get_sset_count,
1529 .get_strings = marvell_get_strings,
1530 .get_stats = marvell_get_stats,
Andrew Lunn819ec8e2015-11-16 23:34:41 +01001531 },
1532 {
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001533 .phy_id = MARVELL_PHY_ID_88E3016,
1534 .phy_id_mask = MARVELL_PHY_ID_MASK,
1535 .name = "Marvell 88E3016",
1536 .features = PHY_BASIC_FEATURES,
1537 .flags = PHY_HAS_INTERRUPT,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001538 .probe = marvell_probe,
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001539 .config_aneg = &genphy_config_aneg,
1540 .config_init = &m88e3016_config_init,
1541 .aneg_done = &marvell_aneg_done,
1542 .read_status = &marvell_read_status,
1543 .ack_interrupt = &marvell_ack_interrupt,
1544 .config_intr = &marvell_config_intr,
1545 .did_interrupt = &m88e1121_did_interrupt,
1546 .resume = &genphy_resume,
1547 .suspend = &genphy_suspend,
Andrew Lunnd2fa47d2015-12-30 16:28:26 +01001548 .get_sset_count = marvell_get_sset_count,
1549 .get_strings = marvell_get_strings,
1550 .get_stats = marvell_get_stats,
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001551 },
Andy Fleming00db8182005-07-30 19:31:23 -04001552};
1553
Johan Hovold50fd7152014-11-11 19:45:59 +01001554module_phy_driver(marvell_drivers);
David Woodhouse4e4f10f2010-04-02 01:05:56 +00001555
Uwe Kleine-Königcf93c942010-10-03 23:43:32 +00001556static struct mdio_device_id __maybe_unused marvell_tbl[] = {
Michal Simekf5e1cab2013-05-30 20:08:25 +00001557 { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK },
1558 { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK },
1559 { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK },
1560 { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK },
1561 { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK },
1562 { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK },
1563 { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK },
1564 { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK },
1565 { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK },
Michal Simek3da09a52013-05-30 20:08:26 +00001566 { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK },
Michal Simek10e24caa2013-05-30 20:08:27 +00001567 { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK },
Andrew Lunn819ec8e2015-11-16 23:34:41 +01001568 { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK },
Sebastian Hesselbarth6b358ae2014-10-22 20:26:44 +02001569 { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK },
David Woodhouse4e4f10f2010-04-02 01:05:56 +00001570 { }
1571};
1572
1573MODULE_DEVICE_TABLE(mdio, marvell_tbl);