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 <asm/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_CR 0x14
54 #define MII_M1145_RGMII_RX_DELAY 0x0080
55 #define MII_M1145_RGMII_TX_DELAY 0x0002
57 #define MII_M1111_PHY_LED_CONTROL 0x18
58 #define MII_M1111_PHY_LED_DIRECT 0x4100
59 #define MII_M1111_PHY_LED_COMBINE 0x411c
60 #define MII_M1111_PHY_EXT_CR 0x14
61 #define MII_M1111_RX_DELAY 0x80
62 #define MII_M1111_TX_DELAY 0x2
63 #define MII_M1111_PHY_EXT_SR 0x1b
65 #define MII_M1111_HWCFG_MODE_MASK 0xf
66 #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
67 #define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3
68 #define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4
69 #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
70 #define MII_M1111_HWCFG_FIBER_COPPER_AUTO 0x8000
71 #define MII_M1111_HWCFG_FIBER_COPPER_RES 0x2000
73 #define MII_M1111_COPPER 0
74 #define MII_M1111_FIBER 1
76 #define MII_88E1121_PHY_MSCR_PAGE 2
77 #define MII_88E1121_PHY_MSCR_REG 21
78 #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
79 #define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
80 #define MII_88E1121_PHY_MSCR_DELAY_MASK (~(0x3 << 4))
82 #define MII_88E1318S_PHY_MSCR1_REG 16
83 #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
85 /* Copper Specific Interrupt Enable Register */
86 #define MII_88E1318S_PHY_CSIER 0x12
87 /* WOL Event Interrupt Enable */
88 #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
90 /* LED Timer Control Register */
91 #define MII_88E1318S_PHY_LED_PAGE 0x03
92 #define MII_88E1318S_PHY_LED_TCR 0x12
93 #define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
94 #define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
95 #define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
97 /* Magic Packet MAC address registers */
98 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
99 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18
100 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19
102 #define MII_88E1318S_PHY_WOL_PAGE 0x11
103 #define MII_88E1318S_PHY_WOL_CTRL 0x10
104 #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12)
105 #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14)
107 #define MII_88E1121_PHY_LED_CTRL 16
108 #define MII_88E1121_PHY_LED_PAGE 3
109 #define MII_88E1121_PHY_LED_DEF 0x0030
111 #define MII_M1011_PHY_STATUS 0x11
112 #define MII_M1011_PHY_STATUS_1000 0x8000
113 #define MII_M1011_PHY_STATUS_100 0x4000
114 #define MII_M1011_PHY_STATUS_SPD_MASK 0xc000
115 #define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000
116 #define MII_M1011_PHY_STATUS_RESOLVED 0x0800
117 #define MII_M1011_PHY_STATUS_LINK 0x0400
119 #define MII_M1116R_CONTROL_REG_MAC 21
122 MODULE_DESCRIPTION("Marvell PHY driver");
123 MODULE_AUTHOR("Andy Fleming");
124 MODULE_LICENSE("GPL");
126 static int marvell_ack_interrupt(struct phy_device
*phydev
)
130 /* Clear the interrupts by reading the reg */
131 err
= phy_read(phydev
, MII_M1011_IEVENT
);
139 static int marvell_config_intr(struct phy_device
*phydev
)
143 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
144 err
= phy_write(phydev
, MII_M1011_IMASK
, MII_M1011_IMASK_INIT
);
146 err
= phy_write(phydev
, MII_M1011_IMASK
, MII_M1011_IMASK_CLEAR
);
151 static int marvell_config_aneg(struct phy_device
*phydev
)
155 /* The Marvell PHY has an errata which requires
156 * that certain registers get written in order
157 * to restart autonegotiation */
158 err
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
163 err
= phy_write(phydev
, 0x1d, 0x1f);
167 err
= phy_write(phydev
, 0x1e, 0x200c);
171 err
= phy_write(phydev
, 0x1d, 0x5);
175 err
= phy_write(phydev
, 0x1e, 0);
179 err
= phy_write(phydev
, 0x1e, 0x100);
183 err
= phy_write(phydev
, MII_M1011_PHY_SCR
,
184 MII_M1011_PHY_SCR_AUTO_CROSS
);
188 err
= phy_write(phydev
, MII_M1111_PHY_LED_CONTROL
,
189 MII_M1111_PHY_LED_DIRECT
);
193 err
= genphy_config_aneg(phydev
);
197 if (phydev
->autoneg
!= AUTONEG_ENABLE
) {
201 * A write to speed/duplex bits (that is performed by
202 * genphy_config_aneg() call above) must be followed by
203 * a software reset. Otherwise, the write has no effect.
205 bmcr
= phy_read(phydev
, MII_BMCR
);
209 err
= phy_write(phydev
, MII_BMCR
, bmcr
| BMCR_RESET
);
217 #ifdef CONFIG_OF_MDIO
219 * Set and/or override some configuration registers based on the
220 * marvell,reg-init property stored in the of_node for the phydev.
222 * marvell,reg-init = <reg-page reg mask value>,...;
224 * There may be one or more sets of <reg-page reg mask value>:
226 * reg-page: which register bank to use.
228 * mask: if non-zero, ANDed with existing register value.
229 * value: ORed with the masked value and written to the regiser.
232 static int marvell_of_reg_init(struct phy_device
*phydev
)
235 int len
, i
, saved_page
, current_page
, page_changed
, ret
;
237 if (!phydev
->dev
.of_node
)
240 paddr
= of_get_property(phydev
->dev
.of_node
, "marvell,reg-init", &len
);
241 if (!paddr
|| len
< (4 * sizeof(*paddr
)))
244 saved_page
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
248 current_page
= saved_page
;
251 len
/= sizeof(*paddr
);
252 for (i
= 0; i
< len
- 3; i
+= 4) {
253 u16 reg_page
= be32_to_cpup(paddr
+ i
);
254 u16 reg
= be32_to_cpup(paddr
+ i
+ 1);
255 u16 mask
= be32_to_cpup(paddr
+ i
+ 2);
256 u16 val_bits
= be32_to_cpup(paddr
+ i
+ 3);
259 if (reg_page
!= current_page
) {
260 current_page
= reg_page
;
262 ret
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, reg_page
);
269 val
= phy_read(phydev
, reg
);
278 ret
= phy_write(phydev
, reg
, val
);
285 i
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, saved_page
);
292 static int marvell_of_reg_init(struct phy_device
*phydev
)
296 #endif /* CONFIG_OF_MDIO */
298 static int m88e1121_config_aneg(struct phy_device
*phydev
)
300 int err
, oldpage
, mscr
;
302 oldpage
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
304 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
305 MII_88E1121_PHY_MSCR_PAGE
);
309 if ((phydev
->interface
== PHY_INTERFACE_MODE_RGMII
) ||
310 (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
) ||
311 (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
) ||
312 (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
)) {
314 mscr
= phy_read(phydev
, MII_88E1121_PHY_MSCR_REG
) &
315 MII_88E1121_PHY_MSCR_DELAY_MASK
;
317 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
)
318 mscr
|= (MII_88E1121_PHY_MSCR_RX_DELAY
|
319 MII_88E1121_PHY_MSCR_TX_DELAY
);
320 else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
)
321 mscr
|= MII_88E1121_PHY_MSCR_RX_DELAY
;
322 else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
)
323 mscr
|= MII_88E1121_PHY_MSCR_TX_DELAY
;
325 err
= phy_write(phydev
, MII_88E1121_PHY_MSCR_REG
, mscr
);
330 phy_write(phydev
, MII_MARVELL_PHY_PAGE
, oldpage
);
332 err
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
336 err
= phy_write(phydev
, MII_M1011_PHY_SCR
,
337 MII_M1011_PHY_SCR_AUTO_CROSS
);
341 oldpage
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
343 phy_write(phydev
, MII_MARVELL_PHY_PAGE
, MII_88E1121_PHY_LED_PAGE
);
344 phy_write(phydev
, MII_88E1121_PHY_LED_CTRL
, MII_88E1121_PHY_LED_DEF
);
345 phy_write(phydev
, MII_MARVELL_PHY_PAGE
, oldpage
);
347 err
= genphy_config_aneg(phydev
);
352 static int m88e1318_config_aneg(struct phy_device
*phydev
)
354 int err
, oldpage
, mscr
;
356 oldpage
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
358 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
359 MII_88E1121_PHY_MSCR_PAGE
);
363 mscr
= phy_read(phydev
, MII_88E1318S_PHY_MSCR1_REG
);
364 mscr
|= MII_88E1318S_PHY_MSCR1_PAD_ODD
;
366 err
= phy_write(phydev
, MII_88E1318S_PHY_MSCR1_REG
, mscr
);
370 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, oldpage
);
374 return m88e1121_config_aneg(phydev
);
377 static int m88e1510_config_aneg(struct phy_device
*phydev
)
381 err
= m88e1318_config_aneg(phydev
);
385 return marvell_of_reg_init(phydev
);
388 static int m88e1116r_config_init(struct phy_device
*phydev
)
393 temp
= phy_read(phydev
, MII_BMCR
);
395 err
= phy_write(phydev
, MII_BMCR
, temp
);
401 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0);
405 temp
= phy_read(phydev
, MII_M1011_PHY_SCR
);
406 temp
|= (7 << 12); /* max number of gigabit attempts */
407 temp
|= (1 << 11); /* enable downshift */
408 temp
|= MII_M1011_PHY_SCR_AUTO_CROSS
;
409 err
= phy_write(phydev
, MII_M1011_PHY_SCR
, temp
);
413 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 2);
416 temp
= phy_read(phydev
, MII_M1116R_CONTROL_REG_MAC
);
419 err
= phy_write(phydev
, MII_M1116R_CONTROL_REG_MAC
, temp
);
422 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0);
426 temp
= phy_read(phydev
, MII_BMCR
);
428 err
= phy_write(phydev
, MII_BMCR
, temp
);
437 static int m88e1111_config_init(struct phy_device
*phydev
)
442 if ((phydev
->interface
== PHY_INTERFACE_MODE_RGMII
) ||
443 (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
) ||
444 (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
) ||
445 (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
)) {
447 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_CR
);
451 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
) {
452 temp
|= (MII_M1111_RX_DELAY
| MII_M1111_TX_DELAY
);
453 } else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
) {
454 temp
&= ~MII_M1111_TX_DELAY
;
455 temp
|= MII_M1111_RX_DELAY
;
456 } else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
) {
457 temp
&= ~MII_M1111_RX_DELAY
;
458 temp
|= MII_M1111_TX_DELAY
;
461 err
= phy_write(phydev
, MII_M1111_PHY_EXT_CR
, temp
);
465 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
469 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
);
471 if (temp
& MII_M1111_HWCFG_FIBER_COPPER_RES
)
472 temp
|= MII_M1111_HWCFG_MODE_FIBER_RGMII
;
474 temp
|= MII_M1111_HWCFG_MODE_COPPER_RGMII
;
476 err
= phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
481 if (phydev
->interface
== PHY_INTERFACE_MODE_SGMII
) {
482 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
486 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
);
487 temp
|= MII_M1111_HWCFG_MODE_SGMII_NO_CLK
;
488 temp
|= MII_M1111_HWCFG_FIBER_COPPER_AUTO
;
490 err
= phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
495 if (phydev
->interface
== PHY_INTERFACE_MODE_RTBI
) {
496 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_CR
);
499 temp
|= (MII_M1111_RX_DELAY
| MII_M1111_TX_DELAY
);
500 err
= phy_write(phydev
, MII_M1111_PHY_EXT_CR
, temp
);
504 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
507 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
| MII_M1111_HWCFG_FIBER_COPPER_RES
);
508 temp
|= 0x7 | MII_M1111_HWCFG_FIBER_COPPER_AUTO
;
509 err
= phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
514 err
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
518 temp
= phy_read(phydev
, MII_BMCR
);
519 while (temp
& BMCR_RESET
);
521 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
524 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
| MII_M1111_HWCFG_FIBER_COPPER_RES
);
525 temp
|= MII_M1111_HWCFG_MODE_COPPER_RTBI
| MII_M1111_HWCFG_FIBER_COPPER_AUTO
;
526 err
= phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
531 err
= marvell_of_reg_init(phydev
);
535 return phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
538 static int m88e1118_config_aneg(struct phy_device
*phydev
)
542 err
= phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
546 err
= phy_write(phydev
, MII_M1011_PHY_SCR
,
547 MII_M1011_PHY_SCR_AUTO_CROSS
);
551 err
= genphy_config_aneg(phydev
);
555 static int m88e1118_config_init(struct phy_device
*phydev
)
560 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0002);
564 /* Enable 1000 Mbit */
565 err
= phy_write(phydev
, 0x15, 0x1070);
570 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0003);
574 /* Adjust LED Control */
575 if (phydev
->dev_flags
& MARVELL_PHY_M1118_DNS323_LEDS
)
576 err
= phy_write(phydev
, 0x10, 0x1100);
578 err
= phy_write(phydev
, 0x10, 0x021e);
582 err
= marvell_of_reg_init(phydev
);
587 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0);
591 return phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
594 static int m88e1149_config_init(struct phy_device
*phydev
)
599 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0002);
603 /* Enable 1000 Mbit */
604 err
= phy_write(phydev
, 0x15, 0x1048);
608 err
= marvell_of_reg_init(phydev
);
613 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x0);
617 return phy_write(phydev
, MII_BMCR
, BMCR_RESET
);
620 static int m88e1145_config_init(struct phy_device
*phydev
)
624 /* Take care of errata E0 & E1 */
625 err
= phy_write(phydev
, 0x1d, 0x001b);
629 err
= phy_write(phydev
, 0x1e, 0x418f);
633 err
= phy_write(phydev
, 0x1d, 0x0016);
637 err
= phy_write(phydev
, 0x1e, 0xa2da);
641 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
) {
642 int temp
= phy_read(phydev
, MII_M1145_PHY_EXT_CR
);
646 temp
|= (MII_M1145_RGMII_RX_DELAY
| MII_M1145_RGMII_TX_DELAY
);
648 err
= phy_write(phydev
, MII_M1145_PHY_EXT_CR
, temp
);
652 if (phydev
->dev_flags
& MARVELL_PHY_M1145_FLAGS_RESISTANCE
) {
653 err
= phy_write(phydev
, 0x1d, 0x0012);
657 temp
= phy_read(phydev
, 0x1e);
662 temp
|= 2 << 9; /* 36 ohm */
663 temp
|= 2 << 6; /* 39 ohm */
665 err
= phy_write(phydev
, 0x1e, temp
);
669 err
= phy_write(phydev
, 0x1d, 0x3);
673 err
= phy_write(phydev
, 0x1e, 0x8000);
679 err
= marvell_of_reg_init(phydev
);
686 /* marvell_read_status
688 * Generic status code does not detect Fiber correctly!
690 * Check the link, then figure out the current state
691 * by comparing what we advertise with what the link partner
692 * advertises. Start by checking the gigabit possibilities,
693 * then move on to 10/100.
695 static int marvell_read_status(struct phy_device
*phydev
)
702 /* Update the link, but return if there
704 err
= genphy_update_link(phydev
);
708 if (AUTONEG_ENABLE
== phydev
->autoneg
) {
709 status
= phy_read(phydev
, MII_M1011_PHY_STATUS
);
713 lpa
= phy_read(phydev
, MII_LPA
);
717 adv
= phy_read(phydev
, MII_ADVERTISE
);
723 if (status
& MII_M1011_PHY_STATUS_FULLDUPLEX
)
724 phydev
->duplex
= DUPLEX_FULL
;
726 phydev
->duplex
= DUPLEX_HALF
;
728 status
= status
& MII_M1011_PHY_STATUS_SPD_MASK
;
729 phydev
->pause
= phydev
->asym_pause
= 0;
732 case MII_M1011_PHY_STATUS_1000
:
733 phydev
->speed
= SPEED_1000
;
736 case MII_M1011_PHY_STATUS_100
:
737 phydev
->speed
= SPEED_100
;
741 phydev
->speed
= SPEED_10
;
745 if (phydev
->duplex
== DUPLEX_FULL
) {
746 phydev
->pause
= lpa
& LPA_PAUSE_CAP
? 1 : 0;
747 phydev
->asym_pause
= lpa
& LPA_PAUSE_ASYM
? 1 : 0;
750 int bmcr
= phy_read(phydev
, MII_BMCR
);
755 if (bmcr
& BMCR_FULLDPLX
)
756 phydev
->duplex
= DUPLEX_FULL
;
758 phydev
->duplex
= DUPLEX_HALF
;
760 if (bmcr
& BMCR_SPEED1000
)
761 phydev
->speed
= SPEED_1000
;
762 else if (bmcr
& BMCR_SPEED100
)
763 phydev
->speed
= SPEED_100
;
765 phydev
->speed
= SPEED_10
;
767 phydev
->pause
= phydev
->asym_pause
= 0;
773 static int m88e1121_did_interrupt(struct phy_device
*phydev
)
777 imask
= phy_read(phydev
, MII_M1011_IEVENT
);
779 if (imask
& MII_M1011_IMASK_INIT
)
785 static void m88e1318_get_wol(struct phy_device
*phydev
, struct ethtool_wolinfo
*wol
)
787 wol
->supported
= WAKE_MAGIC
;
790 if (phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
791 MII_88E1318S_PHY_WOL_PAGE
) < 0)
794 if (phy_read(phydev
, MII_88E1318S_PHY_WOL_CTRL
) &
795 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
)
796 wol
->wolopts
|= WAKE_MAGIC
;
798 if (phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x00) < 0)
802 static int m88e1318_set_wol(struct phy_device
*phydev
, struct ethtool_wolinfo
*wol
)
804 int err
, oldpage
, temp
;
806 oldpage
= phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
808 if (wol
->wolopts
& WAKE_MAGIC
) {
809 /* Explicitly switch to page 0x00, just to be sure */
810 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, 0x00);
814 /* Enable the WOL interrupt */
815 temp
= phy_read(phydev
, MII_88E1318S_PHY_CSIER
);
816 temp
|= MII_88E1318S_PHY_CSIER_WOL_EIE
;
817 err
= phy_write(phydev
, MII_88E1318S_PHY_CSIER
, temp
);
821 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
822 MII_88E1318S_PHY_LED_PAGE
);
826 /* Setup LED[2] as interrupt pin (active low) */
827 temp
= phy_read(phydev
, MII_88E1318S_PHY_LED_TCR
);
828 temp
&= ~MII_88E1318S_PHY_LED_TCR_FORCE_INT
;
829 temp
|= MII_88E1318S_PHY_LED_TCR_INTn_ENABLE
;
830 temp
|= MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW
;
831 err
= phy_write(phydev
, MII_88E1318S_PHY_LED_TCR
, temp
);
835 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
836 MII_88E1318S_PHY_WOL_PAGE
);
840 /* Store the device address for the magic packet */
841 err
= phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD2
,
842 ((phydev
->attached_dev
->dev_addr
[5] << 8) |
843 phydev
->attached_dev
->dev_addr
[4]));
846 err
= phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD1
,
847 ((phydev
->attached_dev
->dev_addr
[3] << 8) |
848 phydev
->attached_dev
->dev_addr
[2]));
851 err
= phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD0
,
852 ((phydev
->attached_dev
->dev_addr
[1] << 8) |
853 phydev
->attached_dev
->dev_addr
[0]));
857 /* Clear WOL status and enable magic packet matching */
858 temp
= phy_read(phydev
, MII_88E1318S_PHY_WOL_CTRL
);
859 temp
|= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS
;
860 temp
|= MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
;
861 err
= phy_write(phydev
, MII_88E1318S_PHY_WOL_CTRL
, temp
);
865 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
,
866 MII_88E1318S_PHY_WOL_PAGE
);
870 /* Clear WOL status and disable magic packet matching */
871 temp
= phy_read(phydev
, MII_88E1318S_PHY_WOL_CTRL
);
872 temp
|= MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS
;
873 temp
&= ~MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
;
874 err
= phy_write(phydev
, MII_88E1318S_PHY_WOL_CTRL
, temp
);
879 err
= phy_write(phydev
, MII_MARVELL_PHY_PAGE
, oldpage
);
886 static struct phy_driver marvell_drivers
[] = {
888 .phy_id
= MARVELL_PHY_ID_88E1101
,
889 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
890 .name
= "Marvell 88E1101",
891 .features
= PHY_GBIT_FEATURES
,
892 .flags
= PHY_HAS_INTERRUPT
,
893 .config_aneg
= &marvell_config_aneg
,
894 .read_status
= &genphy_read_status
,
895 .ack_interrupt
= &marvell_ack_interrupt
,
896 .config_intr
= &marvell_config_intr
,
897 .driver
= { .owner
= THIS_MODULE
},
900 .phy_id
= MARVELL_PHY_ID_88E1112
,
901 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
902 .name
= "Marvell 88E1112",
903 .features
= PHY_GBIT_FEATURES
,
904 .flags
= PHY_HAS_INTERRUPT
,
905 .config_init
= &m88e1111_config_init
,
906 .config_aneg
= &marvell_config_aneg
,
907 .read_status
= &genphy_read_status
,
908 .ack_interrupt
= &marvell_ack_interrupt
,
909 .config_intr
= &marvell_config_intr
,
910 .driver
= { .owner
= THIS_MODULE
},
913 .phy_id
= MARVELL_PHY_ID_88E1111
,
914 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
915 .name
= "Marvell 88E1111",
916 .features
= PHY_GBIT_FEATURES
,
917 .flags
= PHY_HAS_INTERRUPT
,
918 .config_init
= &m88e1111_config_init
,
919 .config_aneg
= &marvell_config_aneg
,
920 .read_status
= &marvell_read_status
,
921 .ack_interrupt
= &marvell_ack_interrupt
,
922 .config_intr
= &marvell_config_intr
,
923 .driver
= { .owner
= THIS_MODULE
},
926 .phy_id
= MARVELL_PHY_ID_88E1118
,
927 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
928 .name
= "Marvell 88E1118",
929 .features
= PHY_GBIT_FEATURES
,
930 .flags
= PHY_HAS_INTERRUPT
,
931 .config_init
= &m88e1118_config_init
,
932 .config_aneg
= &m88e1118_config_aneg
,
933 .read_status
= &genphy_read_status
,
934 .ack_interrupt
= &marvell_ack_interrupt
,
935 .config_intr
= &marvell_config_intr
,
936 .driver
= {.owner
= THIS_MODULE
,},
939 .phy_id
= MARVELL_PHY_ID_88E1121R
,
940 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
941 .name
= "Marvell 88E1121R",
942 .features
= PHY_GBIT_FEATURES
,
943 .flags
= PHY_HAS_INTERRUPT
,
944 .config_aneg
= &m88e1121_config_aneg
,
945 .read_status
= &marvell_read_status
,
946 .ack_interrupt
= &marvell_ack_interrupt
,
947 .config_intr
= &marvell_config_intr
,
948 .did_interrupt
= &m88e1121_did_interrupt
,
949 .driver
= { .owner
= THIS_MODULE
},
952 .phy_id
= MARVELL_PHY_ID_88E1318S
,
953 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
954 .name
= "Marvell 88E1318S",
955 .features
= PHY_GBIT_FEATURES
,
956 .flags
= PHY_HAS_INTERRUPT
,
957 .config_aneg
= &m88e1318_config_aneg
,
958 .read_status
= &marvell_read_status
,
959 .ack_interrupt
= &marvell_ack_interrupt
,
960 .config_intr
= &marvell_config_intr
,
961 .did_interrupt
= &m88e1121_did_interrupt
,
962 .get_wol
= &m88e1318_get_wol
,
963 .set_wol
= &m88e1318_set_wol
,
964 .driver
= { .owner
= THIS_MODULE
},
967 .phy_id
= MARVELL_PHY_ID_88E1145
,
968 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
969 .name
= "Marvell 88E1145",
970 .features
= PHY_GBIT_FEATURES
,
971 .flags
= PHY_HAS_INTERRUPT
,
972 .config_init
= &m88e1145_config_init
,
973 .config_aneg
= &marvell_config_aneg
,
974 .read_status
= &genphy_read_status
,
975 .ack_interrupt
= &marvell_ack_interrupt
,
976 .config_intr
= &marvell_config_intr
,
977 .driver
= { .owner
= THIS_MODULE
},
980 .phy_id
= MARVELL_PHY_ID_88E1149R
,
981 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
982 .name
= "Marvell 88E1149R",
983 .features
= PHY_GBIT_FEATURES
,
984 .flags
= PHY_HAS_INTERRUPT
,
985 .config_init
= &m88e1149_config_init
,
986 .config_aneg
= &m88e1118_config_aneg
,
987 .read_status
= &genphy_read_status
,
988 .ack_interrupt
= &marvell_ack_interrupt
,
989 .config_intr
= &marvell_config_intr
,
990 .driver
= { .owner
= THIS_MODULE
},
993 .phy_id
= MARVELL_PHY_ID_88E1240
,
994 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
995 .name
= "Marvell 88E1240",
996 .features
= PHY_GBIT_FEATURES
,
997 .flags
= PHY_HAS_INTERRUPT
,
998 .config_init
= &m88e1111_config_init
,
999 .config_aneg
= &marvell_config_aneg
,
1000 .read_status
= &genphy_read_status
,
1001 .ack_interrupt
= &marvell_ack_interrupt
,
1002 .config_intr
= &marvell_config_intr
,
1003 .driver
= { .owner
= THIS_MODULE
},
1006 .phy_id
= MARVELL_PHY_ID_88E1116R
,
1007 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1008 .name
= "Marvell 88E1116R",
1009 .features
= PHY_GBIT_FEATURES
,
1010 .flags
= PHY_HAS_INTERRUPT
,
1011 .config_init
= &m88e1116r_config_init
,
1012 .config_aneg
= &genphy_config_aneg
,
1013 .read_status
= &genphy_read_status
,
1014 .ack_interrupt
= &marvell_ack_interrupt
,
1015 .config_intr
= &marvell_config_intr
,
1016 .driver
= { .owner
= THIS_MODULE
},
1019 .phy_id
= MARVELL_PHY_ID_88E1510
,
1020 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1021 .name
= "Marvell 88E1510",
1022 .features
= PHY_GBIT_FEATURES
,
1023 .flags
= PHY_HAS_INTERRUPT
,
1024 .config_aneg
= &m88e1510_config_aneg
,
1025 .read_status
= &marvell_read_status
,
1026 .ack_interrupt
= &marvell_ack_interrupt
,
1027 .config_intr
= &marvell_config_intr
,
1028 .did_interrupt
= &m88e1121_did_interrupt
,
1029 .driver
= { .owner
= THIS_MODULE
},
1033 static int __init
marvell_init(void)
1035 return phy_drivers_register(marvell_drivers
,
1036 ARRAY_SIZE(marvell_drivers
));
1039 static void __exit
marvell_exit(void)
1041 phy_drivers_unregister(marvell_drivers
,
1042 ARRAY_SIZE(marvell_drivers
));
1045 module_init(marvell_init
);
1046 module_exit(marvell_exit
);
1048 static struct mdio_device_id __maybe_unused marvell_tbl
[] = {
1049 { MARVELL_PHY_ID_88E1101
, MARVELL_PHY_ID_MASK
},
1050 { MARVELL_PHY_ID_88E1112
, MARVELL_PHY_ID_MASK
},
1051 { MARVELL_PHY_ID_88E1111
, MARVELL_PHY_ID_MASK
},
1052 { MARVELL_PHY_ID_88E1118
, MARVELL_PHY_ID_MASK
},
1053 { MARVELL_PHY_ID_88E1121R
, MARVELL_PHY_ID_MASK
},
1054 { MARVELL_PHY_ID_88E1145
, MARVELL_PHY_ID_MASK
},
1055 { MARVELL_PHY_ID_88E1149R
, MARVELL_PHY_ID_MASK
},
1056 { MARVELL_PHY_ID_88E1240
, MARVELL_PHY_ID_MASK
},
1057 { MARVELL_PHY_ID_88E1318S
, MARVELL_PHY_ID_MASK
},
1058 { MARVELL_PHY_ID_88E1116R
, MARVELL_PHY_ID_MASK
},
1059 { MARVELL_PHY_ID_88E1510
, MARVELL_PHY_ID_MASK
},
1063 MODULE_DEVICE_TABLE(mdio
, marvell_tbl
);