2 * drivers/net/phy/marvell.c
4 * Driver for Marvell PHYs
8 * Copyright (c) 2004 Freescale Semiconductor, Inc.
10 * Copyright (c) 2013 Michael Stapelberg <michael@stapelberg.de>
12 * 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.
18 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/errno.h>
21 #include <linux/unistd.h>
22 #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>
30 #include <linux/module.h>
31 #include <linux/mii.h>
32 #include <linux/ethtool.h>
33 #include <linux/phy.h>
34 #include <linux/marvell_phy.h>
39 #include <linux/uaccess.h>
41 #define MII_MARVELL_PHY_PAGE 22
43 #define MII_M1011_IEVENT 0x13
44 #define MII_M1011_IEVENT_CLEAR 0x0000
46 #define MII_M1011_IMASK 0x12
47 #define MII_M1011_IMASK_INIT 0x6400
48 #define MII_M1011_IMASK_CLEAR 0x0000
50 #define MII_M1011_PHY_SCR 0x10
51 #define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060
53 #define MII_M1145_PHY_EXT_SR 0x1b
54 #define MII_M1145_PHY_EXT_CR 0x14
55 #define MII_M1145_RGMII_RX_DELAY 0x0080
56 #define MII_M1145_RGMII_TX_DELAY 0x0002
57 #define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4
58 #define MII_M1145_HWCFG_MODE_MASK 0xf
59 #define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000
61 #define MII_M1145_HWCFG_MODE_SGMII_NO_CLK 0x4
62 #define MII_M1145_HWCFG_MODE_MASK 0xf
63 #define MII_M1145_HWCFG_FIBER_COPPER_AUTO 0x8000
65 #define MII_M1111_PHY_LED_CONTROL 0x18
66 #define MII_M1111_PHY_LED_DIRECT 0x4100
67 #define MII_M1111_PHY_LED_COMBINE 0x411c
68 #define MII_M1111_PHY_EXT_CR 0x14
69 #define MII_M1111_RX_DELAY 0x80
70 #define MII_M1111_TX_DELAY 0x2
71 #define MII_M1111_PHY_EXT_SR 0x1b
73 #define MII_M1111_HWCFG_MODE_MASK 0xf
74 #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
75 #define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3
76 #define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4
77 #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
78 #define MII_M1111_HWCFG_FIBER_COPPER_AUTO 0x8000
79 #define MII_M1111_HWCFG_FIBER_COPPER_RES 0x2000
81 #define MII_M1111_COPPER 0
82 #define MII_M1111_FIBER 1
84 #define MII_88E1121_PHY_MSCR_PAGE 2
85 #define MII_88E1121_PHY_MSCR_REG 21
86 #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
87 #define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
88 #define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4))
90 #define MII_88E1318S_PHY_MSCR1_REG 16
91 #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
93 /* Copper Specific Interrupt Enable Register */
94 #define MII_88E1318S_PHY_CSIER 0x12
95 /* WOL Event Interrupt Enable */
96 #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
98 /* LED Timer Control Register */
99 #define MII_88E1318S_PHY_LED_PAGE 0x03
100 #define MII_88E1318S_PHY_LED_TCR 0x12
101 #define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
102 #define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
103 #define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
105 /* Magic Packet MAC address registers */
106 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
107 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18
108 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19
110 #define MII_88E1318S_PHY_WOL_PAGE 0x11
111 #define MII_88E1318S_PHY_WOL_CTRL 0x10
112 #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12)
113 #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14)
115 #define MII_88E1121_PHY_LED_CTRL 16
116 #define MII_88E1121_PHY_LED_PAGE 3
117 #define MII_88E1121_PHY_LED_DEF 0x0030
119 #define MII_M1011_PHY_STATUS 0x11
120 #define MII_M1011_PHY_STATUS_1000 0x8000
121 #define MII_M1011_PHY_STATUS_100 0x4000
122 #define MII_M1011_PHY_STATUS_SPD_MASK 0xc000
123 #define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000
124 #define MII_M1011_PHY_STATUS_RESOLVED 0x0800
125 #define MII_M1011_PHY_STATUS_LINK 0x0400
127 #define MII_M1116R_CONTROL_REG_MAC 21
129 #define MII_88E3016_PHY_SPEC_CTRL 0x10
130 #define MII_88E3016_DISABLE_SCRAMBLER 0x0200
131 #define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030
133 MODULE_DESCRIPTION("Marvell PHY driver");
134 MODULE_AUTHOR("Andy Fleming");
135 MODULE_LICENSE("GPL");
137 static int marvell_ack_interrupt(struct phy_device
*phydev
)
141 /* Clear the interrupts by reading the reg */
142 err
= phy_read(phydev
, MII_M1011_IEVENT
);
150 static int marvell_config_intr(struct phy_device
*phydev
)
154 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
155 err
= phy_write(phydev
, MII_M1011_IMASK
, MII_M1011_IMASK_INIT
);
157 err
= phy_write(phydev
, MII_M1011_IMASK
, MII_M1011_IMASK_CLEAR
);
162 static int marvell_config_aneg(struct phy_device
*phydev
)
166 /* The Marvell PHY has an errata which requires
167 * that certain registers get written in order
168 * to restart autonegotiation */
169 err
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
174 err
= phy_write(phydev
, 0x1d, 0x1f);
178 err
= phy_write(phydev
, 0x1e, 0x200c);
182 err
= phy_write(phydev
, 0x1d, 0x5);
186 err
= phy_write(phydev
, 0x1e, 0);
190 err
= phy_write(phydev
, 0x1e, 0x100);
194 err
= phy_write(phydev
, MII_M1011_PHY_SCR
,
195 MII_M1011_PHY_SCR_AUTO_CROSS
);
199 err
= phy_write(phydev
, MII_M1111_PHY_LED_CONTROL
,
200 MII_M1111_PHY_LED_DIRECT
);
204 err
= genphy_config_aneg(phydev
);
208 if (phydev
->autoneg
!= AUTONEG_ENABLE
) {
212 * A write to speed/duplex bits (that is performed by
213 * genphy_config_aneg() call above) must be followed by
214 * a software reset. Otherwise, the write has no effect.
216 bmcr
= phy_read(phydev
, MII_BMCR
);
220 err
= phy_write(phydev
, MII_BMCR
, bmcr
| BMCR_RESET
);
228 #ifdef CONFIG_OF_MDIO
230 * Set and/or override some configuration registers based on the
231 * marvell,reg-init property stored in the of_node for the phydev.
233 * marvell,reg-init = <reg-page reg mask value>,...;
235 * There may be one or more sets of <reg-page reg mask value>:
237 * reg-page: which register bank to use.
239 * mask: if non-zero, ANDed with existing register value.
240 * value: ORed with the masked value and written to the regiser.
243 static int marvell_of_reg_init(struct phy_device
*phydev
)
246 int len
, i
, saved_page
, current_page
, page_changed
, ret
;
248 if (!phydev
->dev
.of_node
)
251 paddr
= of_get_property(phydev
->dev
.of_node
, "marvell,reg-init", &len
);
252 if (!paddr
|| len
< (4 * sizeof(*paddr
)))
255 saved_page
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
259 current_page
= saved_page
;
262 len
/= sizeof(*paddr
);
263 for (i
= 0; i
< len
- 3; i
+= 4) {
264 u16 reg_page
= be32_to_cpup(paddr
+ i
);
265 u16 reg
= be32_to_cpup(paddr
+ i
+ 1);
266 u16 mask
= be32_to_cpup(paddr
+ i
+ 2);
267 u16 val_bits
= be32_to_cpup(paddr
+ i
+ 3);
270 if (reg_page
!= current_page
) {
271 current_page
= reg_page
;
273 ret
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, reg_page
);
280 val
= phy_read(phydev
, reg
);
289 ret
= phy_write(phydev
, reg
, val
);
296 i
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, saved_page
);
303 static int marvell_of_reg_init(struct phy_device
*phydev
)
307 #endif /* CONFIG_OF_MDIO */
309 static int m88e1121_config_aneg(struct phy_device
*phydev
)
311 int err
, oldpage
, mscr
;
313 oldpage
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
315 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
316 MII_88E1121_PHY_MSCR_PAGE
);
320 if (phy_interface_is_rgmii(phydev
)) {
322 mscr
= phy_read(phydev
, MII_88E1121_PHY_MSCR_REG
) &
323 MII_88E1121_PHY_MSCR_DELAY_MASK
;
325 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
)
326 mscr
|= (MII_88E1121_PHY_MSCR_RX_DELAY
|
327 MII_88E1121_PHY_MSCR_TX_DELAY
);
328 else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
)
329 mscr
|= MII_88E1121_PHY_MSCR_RX_DELAY
;
330 else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
)
331 mscr
|= MII_88E1121_PHY_MSCR_TX_DELAY
;
333 err
= phy_write(phydev
, MII_88E1121_PHY_MSCR_REG
, mscr
);
338 phy_write(phydev
, MII_MARVELL_PHY_PAGE
, oldpage
);
340 err
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
344 err
= phy_write(phydev
, MII_M1011_PHY_SCR
,
345 MII_M1011_PHY_SCR_AUTO_CROSS
);
349 oldpage
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
351 phy_write(phydev
, MII_MARVELL_PHY_PAGE
, MII_88E1121_PHY_LED_PAGE
);
352 phy_write(phydev
, MII_88E1121_PHY_LED_CTRL
, MII_88E1121_PHY_LED_DEF
);
353 phy_write(phydev
, MII_MARVELL_PHY_PAGE
, oldpage
);
355 err
= genphy_config_aneg(phydev
);
360 static int m88e1318_config_aneg(struct phy_device
*phydev
)
362 int err
, oldpage
, mscr
;
364 oldpage
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
366 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
367 MII_88E1121_PHY_MSCR_PAGE
);
371 mscr
= phy_read(phydev
, MII_88E1318S_PHY_MSCR1_REG
);
372 mscr
|= MII_88E1318S_PHY_MSCR1_PAD_ODD
;
374 err
= phy_write(phydev
, MII_88E1318S_PHY_MSCR1_REG
, mscr
);
378 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, oldpage
);
382 return m88e1121_config_aneg(phydev
);
385 static int m88e1510_config_aneg(struct phy_device
*phydev
)
389 err
= m88e1318_config_aneg(phydev
);
393 return marvell_of_reg_init(phydev
);
396 static int m88e1116r_config_init(struct phy_device
*phydev
)
401 temp
= phy_read(phydev
, MII_BMCR
);
403 err
= phy_write(phydev
, MII_BMCR
, temp
);
409 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0);
413 temp
= phy_read(phydev
, MII_M1011_PHY_SCR
);
414 temp
|= (7 << 12); /* max number of gigabit attempts */
415 temp
|= (1 << 11); /* enable downshift */
416 temp
|= MII_M1011_PHY_SCR_AUTO_CROSS
;
417 err
= phy_write(phydev
, MII_M1011_PHY_SCR
, temp
);
421 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 2);
424 temp
= phy_read(phydev
, MII_M1116R_CONTROL_REG_MAC
);
427 err
= phy_write(phydev
, MII_M1116R_CONTROL_REG_MAC
, temp
);
430 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0);
434 temp
= phy_read(phydev
, MII_BMCR
);
436 err
= phy_write(phydev
, MII_BMCR
, temp
);
445 static int m88e3016_config_init(struct phy_device
*phydev
)
449 /* Enable Scrambler and Auto-Crossover */
450 reg
= phy_read(phydev
, MII_88E3016_PHY_SPEC_CTRL
);
454 reg
&= ~MII_88E3016_DISABLE_SCRAMBLER
;
455 reg
|= MII_88E3016_AUTO_MDIX_CROSSOVER
;
457 reg
= phy_write(phydev
, MII_88E3016_PHY_SPEC_CTRL
, reg
);
464 static int m88e1111_config_init(struct phy_device
*phydev
)
469 if (phy_interface_is_rgmii(phydev
)) {
471 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_CR
);
475 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
) {
476 temp
|= (MII_M1111_RX_DELAY
| MII_M1111_TX_DELAY
);
477 } else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
) {
478 temp
&= ~MII_M1111_TX_DELAY
;
479 temp
|= MII_M1111_RX_DELAY
;
480 } else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
) {
481 temp
&= ~MII_M1111_RX_DELAY
;
482 temp
|= MII_M1111_TX_DELAY
;
485 err
= phy_write(phydev
, MII_M1111_PHY_EXT_CR
, temp
);
489 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
493 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
);
495 if (temp
& MII_M1111_HWCFG_FIBER_COPPER_RES
)
496 temp
|= MII_M1111_HWCFG_MODE_FIBER_RGMII
;
498 temp
|= MII_M1111_HWCFG_MODE_COPPER_RGMII
;
500 err
= phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
505 if (phydev
->interface
== PHY_INTERFACE_MODE_SGMII
) {
506 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
510 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
);
511 temp
|= MII_M1111_HWCFG_MODE_SGMII_NO_CLK
;
512 temp
|= MII_M1111_HWCFG_FIBER_COPPER_AUTO
;
514 err
= phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
519 if (phydev
->interface
== PHY_INTERFACE_MODE_RTBI
) {
520 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_CR
);
523 temp
|= (MII_M1111_RX_DELAY
| MII_M1111_TX_DELAY
);
524 err
= phy_write(phydev
, MII_M1111_PHY_EXT_CR
, temp
);
528 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
531 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
| MII_M1111_HWCFG_FIBER_COPPER_RES
);
532 temp
|= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO
;
533 err
= phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
538 err
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
542 temp
= phy_read(phydev
, MII_BMCR
);
543 while (temp
& BMCR_RESET
);
545 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
548 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
| MII_M1111_HWCFG_FIBER_COPPER_RES
);
549 temp
|= MII_M1111_HWCFG_MODE_COPPER_RTBI
| MII_M1111_HWCFG_FIBER_COPPER_AUTO
;
550 err
= phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
555 err
= marvell_of_reg_init(phydev
);
559 return phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
562 static int m88e1118_config_aneg(struct phy_device
*phydev
)
566 err
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
570 err
= phy_write(phydev
, MII_M1011_PHY_SCR
,
571 MII_M1011_PHY_SCR_AUTO_CROSS
);
575 err
= genphy_config_aneg(phydev
);
579 static int m88e1118_config_init(struct phy_device
*phydev
)
584 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0002);
588 /* Enable 1000 Mbit */
589 err
= phy_write(phydev
, 0x15, 0x1070);
594 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0003);
598 /* Adjust LED Control */
599 if (phydev
->dev_flags
& MARVELL_PHY_M1118_DNS323_LEDS
)
600 err
= phy_write(phydev
, 0x10, 0x1100);
602 err
= phy_write(phydev
, 0x10, 0x021e);
606 err
= marvell_of_reg_init(phydev
);
611 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0);
615 return phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
618 static int m88e1149_config_init(struct phy_device
*phydev
)
623 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0002);
627 /* Enable 1000 Mbit */
628 err
= phy_write(phydev
, 0x15, 0x1048);
632 err
= marvell_of_reg_init(phydev
);
637 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0);
641 return phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
644 static int m88e1145_config_init(struct phy_device
*phydev
)
649 /* Take care of errata E0 & E1 */
650 err
= phy_write(phydev
, 0x1d, 0x001b);
654 err
= phy_write(phydev
, 0x1e, 0x418f);
658 err
= phy_write(phydev
, 0x1d, 0x0016);
662 err
= phy_write(phydev
, 0x1e, 0xa2da);
666 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
) {
667 int temp
= phy_read(phydev
, MII_M1145_PHY_EXT_CR
);
671 temp
|= (MII_M1145_RGMII_RX_DELAY
| MII_M1145_RGMII_TX_DELAY
);
673 err
= phy_write(phydev
, MII_M1145_PHY_EXT_CR
, temp
);
677 if (phydev
->dev_flags
& MARVELL_PHY_M1145_FLAGS_RESISTANCE
) {
678 err
= phy_write(phydev
, 0x1d, 0x0012);
682 temp
= phy_read(phydev
, 0x1e);
687 temp
|= 2 << 9; /* 36 ohm */
688 temp
|= 2 << 6; /* 39 ohm */
690 err
= phy_write(phydev
, 0x1e, temp
);
694 err
= phy_write(phydev
, 0x1d, 0x3);
698 err
= phy_write(phydev
, 0x1e, 0x8000);
704 if (phydev
->interface
== PHY_INTERFACE_MODE_SGMII
) {
705 temp
= phy_read(phydev
, MII_M1145_PHY_EXT_SR
);
709 temp
&= ~MII_M1145_HWCFG_MODE_MASK
;
710 temp
|= MII_M1145_HWCFG_MODE_SGMII_NO_CLK
;
711 temp
|= MII_M1145_HWCFG_FIBER_COPPER_AUTO
;
713 err
= phy_write(phydev
, MII_M1145_PHY_EXT_SR
, temp
);
718 err
= marvell_of_reg_init(phydev
);
725 /* marvell_read_status
727 * Generic status code does not detect Fiber correctly!
729 * Check the link, then figure out the current state
730 * by comparing what we advertise with what the link partner
731 * advertises. Start by checking the gigabit possibilities,
732 * then move on to 10/100.
734 static int marvell_read_status(struct phy_device
*phydev
)
741 /* Update the link, but return if there
743 err
= genphy_update_link(phydev
);
747 if (AUTONEG_ENABLE
== phydev
->autoneg
) {
748 status
= phy_read(phydev
, MII_M1011_PHY_STATUS
);
752 lpa
= phy_read(phydev
, MII_LPA
);
756 adv
= phy_read(phydev
, MII_ADVERTISE
);
762 if (status
& MII_M1011_PHY_STATUS_FULLDUPLEX
)
763 phydev
->duplex
= DUPLEX_FULL
;
765 phydev
->duplex
= DUPLEX_HALF
;
767 status
= status
& MII_M1011_PHY_STATUS_SPD_MASK
;
768 phydev
->pause
= phydev
->asym_pause
= 0;
771 case MII_M1011_PHY_STATUS_1000
:
772 phydev
->speed
= SPEED_1000
;
775 case MII_M1011_PHY_STATUS_100
:
776 phydev
->speed
= SPEED_100
;
780 phydev
->speed
= SPEED_10
;
784 if (phydev
->duplex
== DUPLEX_FULL
) {
785 phydev
->pause
= lpa
& LPA_PAUSE_CAP
? 1 : 0;
786 phydev
->asym_pause
= lpa
& LPA_PAUSE_ASYM
? 1 : 0;
789 int bmcr
= phy_read(phydev
, MII_BMCR
);
794 if (bmcr
& BMCR_FULLDPLX
)
795 phydev
->duplex
= DUPLEX_FULL
;
797 phydev
->duplex
= DUPLEX_HALF
;
799 if (bmcr
& BMCR_SPEED1000
)
800 phydev
->speed
= SPEED_1000
;
801 else if (bmcr
& BMCR_SPEED100
)
802 phydev
->speed
= SPEED_100
;
804 phydev
->speed
= SPEED_10
;
806 phydev
->pause
= phydev
->asym_pause
= 0;
812 static int marvell_aneg_done(struct phy_device
*phydev
)
814 int retval
= phy_read(phydev
, MII_M1011_PHY_STATUS
);
815 return (retval
< 0) ? retval
: (retval
& MII_M1011_PHY_STATUS_RESOLVED
);
818 static int m88e1121_did_interrupt(struct phy_device
*phydev
)
822 imask
= phy_read(phydev
, MII_M1011_IEVENT
);
824 if (imask
& MII_M1011_IMASK_INIT
)
830 static void m88e1318_get_wol(struct phy_device
*phydev
, struct ethtool_wolinfo
*wol
)
832 wol
->supported
= WAKE_MAGIC
;
835 if (phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
836 MII_88E1318S_PHY_WOL_PAGE
) < 0)
839 if (phy_read(phydev
, MII_88E1318S_PHY_WOL_CTRL
) &
840 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
)
841 wol
->wolopts
|= WAKE_MAGIC
;
843 if (phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x00) < 0)
847 static int m88e1318_set_wol(struct phy_device
*phydev
, struct ethtool_wolinfo
*wol
)
849 int err
, oldpage
, temp
;
851 oldpage
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
853 if (wol
->wolopts
& WAKE_MAGIC
) {
854 /* Explicitly switch to page 0x00, just to be sure */
855 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x00);
859 /* Enable the WOL interrupt */
860 temp
= phy_read(phydev
, MII_88E1318S_PHY_CSIER
);
861 temp
|= MII_88E1318S_PHY_CSIER_WOL_EIE
;
862 err
= phy_write(phydev
, MII_88E1318S_PHY_CSIER
, temp
);
866 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
867 MII_88E1318S_PHY_LED_PAGE
);
871 /* Setup LED[2] as interrupt pin (active low) */
872 temp
= phy_read(phydev
, MII_88E1318S_PHY_LED_TCR
);
873 temp
&= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT
;
874 temp
|= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE
;
875 temp
|= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW
;
876 err
= phy_write(phydev
, MII_88E1318S_PHY_LED_TCR
, temp
);
880 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
881 MII_88E1318S_PHY_WOL_PAGE
);
885 /* Store the device address for the magic packet */
886 err
= phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD2
,
887 ((phydev
->attached_dev
->dev_addr
[5] << 8) |
888 phydev
->attached_dev
->dev_addr
[4]));
891 err
= phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD1
,
892 ((phydev
->attached_dev
->dev_addr
[3] << 8) |
893 phydev
->attached_dev
->dev_addr
[2]));
896 err
= phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD0
,
897 ((phydev
->attached_dev
->dev_addr
[1] << 8) |
898 phydev
->attached_dev
->dev_addr
[0]));
902 /* Clear WOL status and enable magic packet matching */
903 temp
= phy_read(phydev
, MII_88E1318S_PHY_WOL_CTRL
);
904 temp
|= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS
;
905 temp
|= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
;
906 err
= phy_write(phydev
, MII_88E1318S_PHY_WOL_CTRL
, temp
);
910 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
911 MII_88E1318S_PHY_WOL_PAGE
);
915 /* Clear WOL status and disable magic packet matching */
916 temp
= phy_read(phydev
, MII_88E1318S_PHY_WOL_CTRL
);
917 temp
|= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS
;
918 temp
&= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
;
919 err
= phy_write(phydev
, MII_88E1318S_PHY_WOL_CTRL
, temp
);
924 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, oldpage
);
931 static struct phy_driver marvell_drivers
[] = {
933 .phy_id
= MARVELL_PHY_ID_88E1101
,
934 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
935 .name
= "Marvell 88E1101",
936 .features
= PHY_GBIT_FEATURES
,
937 .flags
= PHY_HAS_INTERRUPT
,
938 .config_aneg
= &marvell_config_aneg
,
939 .read_status
= &genphy_read_status
,
940 .ack_interrupt
= &marvell_ack_interrupt
,
941 .config_intr
= &marvell_config_intr
,
942 .resume
= &genphy_resume
,
943 .suspend
= &genphy_suspend
,
944 .driver
= { .owner
= THIS_MODULE
},
947 .phy_id
= MARVELL_PHY_ID_88E1112
,
948 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
949 .name
= "Marvell 88E1112",
950 .features
= PHY_GBIT_FEATURES
,
951 .flags
= PHY_HAS_INTERRUPT
,
952 .config_init
= &m88e1111_config_init
,
953 .config_aneg
= &marvell_config_aneg
,
954 .read_status
= &genphy_read_status
,
955 .ack_interrupt
= &marvell_ack_interrupt
,
956 .config_intr
= &marvell_config_intr
,
957 .resume
= &genphy_resume
,
958 .suspend
= &genphy_suspend
,
959 .driver
= { .owner
= THIS_MODULE
},
962 .phy_id
= MARVELL_PHY_ID_88E1111
,
963 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
964 .name
= "Marvell 88E1111",
965 .features
= PHY_GBIT_FEATURES
,
966 .flags
= PHY_HAS_INTERRUPT
,
967 .config_init
= &m88e1111_config_init
,
968 .config_aneg
= &marvell_config_aneg
,
969 .read_status
= &marvell_read_status
,
970 .ack_interrupt
= &marvell_ack_interrupt
,
971 .config_intr
= &marvell_config_intr
,
972 .resume
= &genphy_resume
,
973 .suspend
= &genphy_suspend
,
974 .driver
= { .owner
= THIS_MODULE
},
977 .phy_id
= MARVELL_PHY_ID_88E1118
,
978 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
979 .name
= "Marvell 88E1118",
980 .features
= PHY_GBIT_FEATURES
,
981 .flags
= PHY_HAS_INTERRUPT
,
982 .config_init
= &m88e1118_config_init
,
983 .config_aneg
= &m88e1118_config_aneg
,
984 .read_status
= &genphy_read_status
,
985 .ack_interrupt
= &marvell_ack_interrupt
,
986 .config_intr
= &marvell_config_intr
,
987 .resume
= &genphy_resume
,
988 .suspend
= &genphy_suspend
,
989 .driver
= {.owner
= THIS_MODULE
,},
992 .phy_id
= MARVELL_PHY_ID_88E1121R
,
993 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
994 .name
= "Marvell 88E1121R",
995 .features
= PHY_GBIT_FEATURES
,
996 .flags
= PHY_HAS_INTERRUPT
,
997 .config_aneg
= &m88e1121_config_aneg
,
998 .read_status
= &marvell_read_status
,
999 .ack_interrupt
= &marvell_ack_interrupt
,
1000 .config_intr
= &marvell_config_intr
,
1001 .did_interrupt
= &m88e1121_did_interrupt
,
1002 .resume
= &genphy_resume
,
1003 .suspend
= &genphy_suspend
,
1004 .driver
= { .owner
= THIS_MODULE
},
1007 .phy_id
= MARVELL_PHY_ID_88E1318S
,
1008 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1009 .name
= "Marvell 88E1318S",
1010 .features
= PHY_GBIT_FEATURES
,
1011 .flags
= PHY_HAS_INTERRUPT
,
1012 .config_aneg
= &m88e1318_config_aneg
,
1013 .read_status
= &marvell_read_status
,
1014 .ack_interrupt
= &marvell_ack_interrupt
,
1015 .config_intr
= &marvell_config_intr
,
1016 .did_interrupt
= &m88e1121_did_interrupt
,
1017 .get_wol
= &m88e1318_get_wol
,
1018 .set_wol
= &m88e1318_set_wol
,
1019 .resume
= &genphy_resume
,
1020 .suspend
= &genphy_suspend
,
1021 .driver
= { .owner
= THIS_MODULE
},
1024 .phy_id
= MARVELL_PHY_ID_88E1145
,
1025 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1026 .name
= "Marvell 88E1145",
1027 .features
= PHY_GBIT_FEATURES
,
1028 .flags
= PHY_HAS_INTERRUPT
,
1029 .config_init
= &m88e1145_config_init
,
1030 .config_aneg
= &marvell_config_aneg
,
1031 .read_status
= &genphy_read_status
,
1032 .ack_interrupt
= &marvell_ack_interrupt
,
1033 .config_intr
= &marvell_config_intr
,
1034 .resume
= &genphy_resume
,
1035 .suspend
= &genphy_suspend
,
1036 .driver
= { .owner
= THIS_MODULE
},
1039 .phy_id
= MARVELL_PHY_ID_88E1149R
,
1040 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1041 .name
= "Marvell 88E1149R",
1042 .features
= PHY_GBIT_FEATURES
,
1043 .flags
= PHY_HAS_INTERRUPT
,
1044 .config_init
= &m88e1149_config_init
,
1045 .config_aneg
= &m88e1118_config_aneg
,
1046 .read_status
= &genphy_read_status
,
1047 .ack_interrupt
= &marvell_ack_interrupt
,
1048 .config_intr
= &marvell_config_intr
,
1049 .resume
= &genphy_resume
,
1050 .suspend
= &genphy_suspend
,
1051 .driver
= { .owner
= THIS_MODULE
},
1054 .phy_id
= MARVELL_PHY_ID_88E1240
,
1055 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1056 .name
= "Marvell 88E1240",
1057 .features
= PHY_GBIT_FEATURES
,
1058 .flags
= PHY_HAS_INTERRUPT
,
1059 .config_init
= &m88e1111_config_init
,
1060 .config_aneg
= &marvell_config_aneg
,
1061 .read_status
= &genphy_read_status
,
1062 .ack_interrupt
= &marvell_ack_interrupt
,
1063 .config_intr
= &marvell_config_intr
,
1064 .resume
= &genphy_resume
,
1065 .suspend
= &genphy_suspend
,
1066 .driver
= { .owner
= THIS_MODULE
},
1069 .phy_id
= MARVELL_PHY_ID_88E1116R
,
1070 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1071 .name
= "Marvell 88E1116R",
1072 .features
= PHY_GBIT_FEATURES
,
1073 .flags
= PHY_HAS_INTERRUPT
,
1074 .config_init
= &m88e1116r_config_init
,
1075 .config_aneg
= &genphy_config_aneg
,
1076 .read_status
= &genphy_read_status
,
1077 .ack_interrupt
= &marvell_ack_interrupt
,
1078 .config_intr
= &marvell_config_intr
,
1079 .resume
= &genphy_resume
,
1080 .suspend
= &genphy_suspend
,
1081 .driver
= { .owner
= THIS_MODULE
},
1084 .phy_id
= MARVELL_PHY_ID_88E1510
,
1085 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1086 .name
= "Marvell 88E1510",
1087 .features
= PHY_GBIT_FEATURES
,
1088 .flags
= PHY_HAS_INTERRUPT
,
1089 .config_aneg
= &m88e1510_config_aneg
,
1090 .read_status
= &marvell_read_status
,
1091 .ack_interrupt
= &marvell_ack_interrupt
,
1092 .config_intr
= &marvell_config_intr
,
1093 .did_interrupt
= &m88e1121_did_interrupt
,
1094 .resume
= &genphy_resume
,
1095 .suspend
= &genphy_suspend
,
1096 .driver
= { .owner
= THIS_MODULE
},
1099 .phy_id
= MARVELL_PHY_ID_88E3016
,
1100 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1101 .name
= "Marvell 88E3016",
1102 .features
= PHY_BASIC_FEATURES
,
1103 .flags
= PHY_HAS_INTERRUPT
,
1104 .config_aneg
= &genphy_config_aneg
,
1105 .config_init
= &m88e3016_config_init
,
1106 .aneg_done
= &marvell_aneg_done
,
1107 .read_status
= &marvell_read_status
,
1108 .ack_interrupt
= &marvell_ack_interrupt
,
1109 .config_intr
= &marvell_config_intr
,
1110 .did_interrupt
= &m88e1121_did_interrupt
,
1111 .resume
= &genphy_resume
,
1112 .suspend
= &genphy_suspend
,
1113 .driver
= { .owner
= THIS_MODULE
},
1117 module_phy_driver(marvell_drivers
);
1119 static struct mdio_device_id __maybe_unused marvell_tbl
[] = {
1120 { MARVELL_PHY_ID_88E1101
, MARVELL_PHY_ID_MASK
},
1121 { MARVELL_PHY_ID_88E1112
, MARVELL_PHY_ID_MASK
},
1122 { MARVELL_PHY_ID_88E1111
, MARVELL_PHY_ID_MASK
},
1123 { MARVELL_PHY_ID_88E1118
, MARVELL_PHY_ID_MASK
},
1124 { MARVELL_PHY_ID_88E1121R
, MARVELL_PHY_ID_MASK
},
1125 { MARVELL_PHY_ID_88E1145
, MARVELL_PHY_ID_MASK
},
1126 { MARVELL_PHY_ID_88E1149R
, MARVELL_PHY_ID_MASK
},
1127 { MARVELL_PHY_ID_88E1240
, MARVELL_PHY_ID_MASK
},
1128 { MARVELL_PHY_ID_88E1318S
, MARVELL_PHY_ID_MASK
},
1129 { MARVELL_PHY_ID_88E1116R
, MARVELL_PHY_ID_MASK
},
1130 { MARVELL_PHY_ID_88E1510
, MARVELL_PHY_ID_MASK
},
1131 { MARVELL_PHY_ID_88E3016
, MARVELL_PHY_ID_MASK
},
1135 MODULE_DEVICE_TABLE(mdio
, marvell_tbl
);