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/ctype.h>
21 #include <linux/errno.h>
22 #include <linux/unistd.h>
23 #include <linux/hwmon.h>
24 #include <linux/interrupt.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/netdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/skbuff.h>
30 #include <linux/spinlock.h>
32 #include <linux/module.h>
33 #include <linux/mii.h>
34 #include <linux/ethtool.h>
35 #include <linux/phy.h>
36 #include <linux/marvell_phy.h>
41 #include <linux/uaccess.h>
43 #define MII_MARVELL_PHY_PAGE 22
44 #define MII_MARVELL_COPPER_PAGE 0x00
45 #define MII_MARVELL_FIBER_PAGE 0x01
46 #define MII_MARVELL_MSCR_PAGE 0x02
47 #define MII_MARVELL_LED_PAGE 0x03
48 #define MII_MARVELL_MISC_TEST_PAGE 0x06
49 #define MII_MARVELL_WOL_PAGE 0x11
51 #define MII_M1011_IEVENT 0x13
52 #define MII_M1011_IEVENT_CLEAR 0x0000
54 #define MII_M1011_IMASK 0x12
55 #define MII_M1011_IMASK_INIT 0x6400
56 #define MII_M1011_IMASK_CLEAR 0x0000
58 #define MII_M1011_PHY_SCR 0x10
59 #define MII_M1011_PHY_SCR_DOWNSHIFT_EN BIT(11)
60 #define MII_M1011_PHY_SCR_DOWNSHIFT_SHIFT 12
61 #define MII_M1011_PHY_SRC_DOWNSHIFT_MASK 0x7800
62 #define MII_M1011_PHY_SCR_MDI (0x0 << 5)
63 #define MII_M1011_PHY_SCR_MDI_X (0x1 << 5)
64 #define MII_M1011_PHY_SCR_AUTO_CROSS (0x3 << 5)
66 #define MII_M1111_PHY_LED_CONTROL 0x18
67 #define MII_M1111_PHY_LED_DIRECT 0x4100
68 #define MII_M1111_PHY_LED_COMBINE 0x411c
69 #define MII_M1111_PHY_EXT_CR 0x14
70 #define MII_M1111_RGMII_RX_DELAY BIT(7)
71 #define MII_M1111_RGMII_TX_DELAY BIT(1)
72 #define MII_M1111_PHY_EXT_SR 0x1b
74 #define MII_M1111_HWCFG_MODE_MASK 0xf
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_RTBI 0x7
78 #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
79 #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
80 #define MII_M1111_HWCFG_FIBER_COPPER_RES BIT(13)
81 #define MII_M1111_HWCFG_FIBER_COPPER_AUTO BIT(15)
83 #define MII_88E1121_PHY_MSCR_REG 21
84 #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
85 #define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
86 #define MII_88E1121_PHY_MSCR_DELAY_MASK (BIT(5) | BIT(4))
88 #define MII_88E1121_MISC_TEST 0x1a
89 #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK 0x1f00
90 #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT 8
91 #define MII_88E1510_MISC_TEST_TEMP_IRQ_EN BIT(7)
92 #define MII_88E1510_MISC_TEST_TEMP_IRQ BIT(6)
93 #define MII_88E1121_MISC_TEST_TEMP_SENSOR_EN BIT(5)
94 #define MII_88E1121_MISC_TEST_TEMP_MASK 0x1f
96 #define MII_88E1510_TEMP_SENSOR 0x1b
97 #define MII_88E1510_TEMP_SENSOR_MASK 0xff
99 #define MII_88E1318S_PHY_MSCR1_REG 16
100 #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
102 /* Copper Specific Interrupt Enable Register */
103 #define MII_88E1318S_PHY_CSIER 0x12
104 /* WOL Event Interrupt Enable */
105 #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
107 /* LED Timer Control Register */
108 #define MII_88E1318S_PHY_LED_TCR 0x12
109 #define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
110 #define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
111 #define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
113 /* Magic Packet MAC address registers */
114 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
115 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18
116 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19
118 #define MII_88E1318S_PHY_WOL_CTRL 0x10
119 #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12)
120 #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14)
122 #define MII_88E1121_PHY_LED_CTRL 16
123 #define MII_88E1121_PHY_LED_DEF 0x0030
125 #define MII_M1011_PHY_STATUS 0x11
126 #define MII_M1011_PHY_STATUS_1000 0x8000
127 #define MII_M1011_PHY_STATUS_100 0x4000
128 #define MII_M1011_PHY_STATUS_SPD_MASK 0xc000
129 #define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000
130 #define MII_M1011_PHY_STATUS_RESOLVED 0x0800
131 #define MII_M1011_PHY_STATUS_LINK 0x0400
133 #define MII_88E3016_PHY_SPEC_CTRL 0x10
134 #define MII_88E3016_DISABLE_SCRAMBLER 0x0200
135 #define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030
137 #define MII_88E1510_GEN_CTRL_REG_1 0x14
138 #define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7
139 #define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */
140 #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */
142 #define LPA_FIBER_1000HALF 0x40
143 #define LPA_FIBER_1000FULL 0x20
145 #define LPA_PAUSE_FIBER 0x180
146 #define LPA_PAUSE_ASYM_FIBER 0x100
148 #define ADVERTISE_FIBER_1000HALF 0x40
149 #define ADVERTISE_FIBER_1000FULL 0x20
151 #define ADVERTISE_PAUSE_FIBER 0x180
152 #define ADVERTISE_PAUSE_ASYM_FIBER 0x100
154 #define REGISTER_LINK_STATUS 0x400
155 #define NB_FIBER_STATS 1
157 MODULE_DESCRIPTION("Marvell PHY driver");
158 MODULE_AUTHOR("Andy Fleming");
159 MODULE_LICENSE("GPL");
161 struct marvell_hw_stat
{
168 static struct marvell_hw_stat marvell_hw_stats
[] = {
169 { "phy_receive_errors_copper", 0, 21, 16},
170 { "phy_idle_errors", 0, 10, 8 },
171 { "phy_receive_errors_fiber", 1, 21, 16},
174 struct marvell_priv
{
175 u64 stats
[ARRAY_SIZE(marvell_hw_stats
)];
177 struct device
*hwmon_dev
;
180 static int marvell_read_page(struct phy_device
*phydev
)
182 return __phy_read(phydev
, MII_MARVELL_PHY_PAGE
);
185 static int marvell_write_page(struct phy_device
*phydev
, int page
)
187 return __phy_write(phydev
, MII_MARVELL_PHY_PAGE
, page
);
190 static int marvell_set_page(struct phy_device
*phydev
, int page
)
192 return phy_write(phydev
, MII_MARVELL_PHY_PAGE
, page
);
195 static int marvell_ack_interrupt(struct phy_device
*phydev
)
199 /* Clear the interrupts by reading the reg */
200 err
= phy_read(phydev
, MII_M1011_IEVENT
);
208 static int marvell_config_intr(struct phy_device
*phydev
)
212 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
)
213 err
= phy_write(phydev
, MII_M1011_IMASK
,
214 MII_M1011_IMASK_INIT
);
216 err
= phy_write(phydev
, MII_M1011_IMASK
,
217 MII_M1011_IMASK_CLEAR
);
222 static int marvell_set_polarity(struct phy_device
*phydev
, int polarity
)
228 /* get the current settings */
229 reg
= phy_read(phydev
, MII_M1011_PHY_SCR
);
234 val
&= ~MII_M1011_PHY_SCR_AUTO_CROSS
;
237 val
|= MII_M1011_PHY_SCR_MDI
;
240 val
|= MII_M1011_PHY_SCR_MDI_X
;
242 case ETH_TP_MDI_AUTO
:
243 case ETH_TP_MDI_INVALID
:
245 val
|= MII_M1011_PHY_SCR_AUTO_CROSS
;
250 /* Set the new polarity value in the register */
251 err
= phy_write(phydev
, MII_M1011_PHY_SCR
, val
);
259 static int marvell_set_downshift(struct phy_device
*phydev
, bool enable
,
264 reg
= phy_read(phydev
, MII_M1011_PHY_SCR
);
268 reg
&= MII_M1011_PHY_SRC_DOWNSHIFT_MASK
;
269 reg
|= ((retries
- 1) << MII_M1011_PHY_SCR_DOWNSHIFT_SHIFT
);
271 reg
|= MII_M1011_PHY_SCR_DOWNSHIFT_EN
;
273 return phy_write(phydev
, MII_M1011_PHY_SCR
, reg
);
276 static int marvell_config_aneg(struct phy_device
*phydev
)
280 err
= marvell_set_polarity(phydev
, phydev
->mdix_ctrl
);
284 err
= phy_write(phydev
, MII_M1111_PHY_LED_CONTROL
,
285 MII_M1111_PHY_LED_DIRECT
);
289 err
= genphy_config_aneg(phydev
);
293 if (phydev
->autoneg
!= AUTONEG_ENABLE
) {
294 /* A write to speed/duplex bits (that is performed by
295 * genphy_config_aneg() call above) must be followed by
296 * a software reset. Otherwise, the write has no effect.
298 err
= genphy_soft_reset(phydev
);
306 static int m88e1101_config_aneg(struct phy_device
*phydev
)
310 /* This Marvell PHY has an errata which requires
311 * that certain registers get written in order
312 * to restart autonegotiation
314 err
= genphy_soft_reset(phydev
);
318 err
= phy_write(phydev
, 0x1d, 0x1f);
322 err
= phy_write(phydev
, 0x1e, 0x200c);
326 err
= phy_write(phydev
, 0x1d, 0x5);
330 err
= phy_write(phydev
, 0x1e, 0);
334 err
= phy_write(phydev
, 0x1e, 0x100);
338 return marvell_config_aneg(phydev
);
341 static int m88e1111_config_aneg(struct phy_device
*phydev
)
345 /* The Marvell PHY has an errata which requires
346 * that certain registers get written in order
347 * to restart autonegotiation
349 err
= genphy_soft_reset(phydev
);
351 err
= marvell_set_polarity(phydev
, phydev
->mdix_ctrl
);
355 err
= phy_write(phydev
, MII_M1111_PHY_LED_CONTROL
,
356 MII_M1111_PHY_LED_DIRECT
);
360 err
= genphy_config_aneg(phydev
);
364 if (phydev
->autoneg
!= AUTONEG_ENABLE
) {
365 /* A write to speed/duplex bits (that is performed by
366 * genphy_config_aneg() call above) must be followed by
367 * a software reset. Otherwise, the write has no effect.
369 err
= genphy_soft_reset(phydev
);
377 #ifdef CONFIG_OF_MDIO
378 /* Set and/or override some configuration registers based on the
379 * marvell,reg-init property stored in the of_node for the phydev.
381 * marvell,reg-init = <reg-page reg mask value>,...;
383 * There may be one or more sets of <reg-page reg mask value>:
385 * reg-page: which register bank to use.
387 * mask: if non-zero, ANDed with existing register value.
388 * value: ORed with the masked value and written to the regiser.
391 static int marvell_of_reg_init(struct phy_device
*phydev
)
394 int len
, i
, saved_page
, current_page
, ret
= 0;
396 if (!phydev
->mdio
.dev
.of_node
)
399 paddr
= of_get_property(phydev
->mdio
.dev
.of_node
,
400 "marvell,reg-init", &len
);
401 if (!paddr
|| len
< (4 * sizeof(*paddr
)))
404 saved_page
= phy_save_page(phydev
);
407 current_page
= saved_page
;
409 len
/= sizeof(*paddr
);
410 for (i
= 0; i
< len
- 3; i
+= 4) {
411 u16 page
= be32_to_cpup(paddr
+ i
);
412 u16 reg
= be32_to_cpup(paddr
+ i
+ 1);
413 u16 mask
= be32_to_cpup(paddr
+ i
+ 2);
414 u16 val_bits
= be32_to_cpup(paddr
+ i
+ 3);
417 if (page
!= current_page
) {
419 ret
= marvell_write_page(phydev
, page
);
426 val
= __phy_read(phydev
, reg
);
435 ret
= __phy_write(phydev
, reg
, val
);
440 return phy_restore_page(phydev
, saved_page
, ret
);
443 static int marvell_of_reg_init(struct phy_device
*phydev
)
447 #endif /* CONFIG_OF_MDIO */
449 static int m88e1121_config_aneg_rgmii_delays(struct phy_device
*phydev
)
453 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
)
454 mscr
= MII_88E1121_PHY_MSCR_RX_DELAY
|
455 MII_88E1121_PHY_MSCR_TX_DELAY
;
456 else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
)
457 mscr
= MII_88E1121_PHY_MSCR_RX_DELAY
;
458 else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
)
459 mscr
= MII_88E1121_PHY_MSCR_TX_DELAY
;
463 return phy_modify_paged(phydev
, MII_MARVELL_MSCR_PAGE
,
464 MII_88E1121_PHY_MSCR_REG
,
465 MII_88E1121_PHY_MSCR_DELAY_MASK
, mscr
);
468 static int m88e1121_config_aneg(struct phy_device
*phydev
)
472 if (phy_interface_is_rgmii(phydev
)) {
473 err
= m88e1121_config_aneg_rgmii_delays(phydev
);
478 err
= genphy_soft_reset(phydev
);
482 err
= marvell_set_polarity(phydev
, phydev
->mdix_ctrl
);
486 return genphy_config_aneg(phydev
);
489 static int m88e1318_config_aneg(struct phy_device
*phydev
)
493 err
= phy_modify_paged(phydev
, MII_MARVELL_MSCR_PAGE
,
494 MII_88E1318S_PHY_MSCR1_REG
,
495 0, MII_88E1318S_PHY_MSCR1_PAD_ODD
);
499 return m88e1121_config_aneg(phydev
);
503 * ethtool_adv_to_fiber_adv_t
504 * @ethadv: the ethtool advertisement settings
506 * A small helper function that translates ethtool advertisement
507 * settings to phy autonegotiation advertisements for the
508 * MII_ADV register for fiber link.
510 static inline u32
ethtool_adv_to_fiber_adv_t(u32 ethadv
)
514 if (ethadv
& ADVERTISED_1000baseT_Half
)
515 result
|= ADVERTISE_FIBER_1000HALF
;
516 if (ethadv
& ADVERTISED_1000baseT_Full
)
517 result
|= ADVERTISE_FIBER_1000FULL
;
519 if ((ethadv
& ADVERTISE_PAUSE_ASYM
) && (ethadv
& ADVERTISE_PAUSE_CAP
))
520 result
|= LPA_PAUSE_ASYM_FIBER
;
521 else if (ethadv
& ADVERTISE_PAUSE_CAP
)
522 result
|= (ADVERTISE_PAUSE_FIBER
523 & (~ADVERTISE_PAUSE_ASYM_FIBER
));
529 * marvell_config_aneg_fiber - restart auto-negotiation or write BMCR
530 * @phydev: target phy_device struct
532 * Description: If auto-negotiation is enabled, we configure the
533 * advertising, and then restart auto-negotiation. If it is not
534 * enabled, then we write the BMCR. Adapted for fiber link in
535 * some Marvell's devices.
537 static int marvell_config_aneg_fiber(struct phy_device
*phydev
)
544 if (phydev
->autoneg
!= AUTONEG_ENABLE
)
545 return genphy_setup_forced(phydev
);
547 /* Only allow advertising what this PHY supports */
548 phydev
->advertising
&= phydev
->supported
;
549 advertise
= phydev
->advertising
;
551 /* Setup fiber advertisement */
552 adv
= phy_read(phydev
, MII_ADVERTISE
);
557 adv
&= ~(ADVERTISE_FIBER_1000HALF
| ADVERTISE_FIBER_1000FULL
559 adv
|= ethtool_adv_to_fiber_adv_t(advertise
);
562 err
= phy_write(phydev
, MII_ADVERTISE
, adv
);
570 /* Advertisement hasn't changed, but maybe aneg was never on to
571 * begin with? Or maybe phy was isolated?
573 int ctl
= phy_read(phydev
, MII_BMCR
);
578 if (!(ctl
& BMCR_ANENABLE
) || (ctl
& BMCR_ISOLATE
))
579 changed
= 1; /* do restart aneg */
582 /* Only restart aneg if we are advertising something different
583 * than we were before.
586 changed
= genphy_restart_aneg(phydev
);
591 static int m88e1510_config_aneg(struct phy_device
*phydev
)
595 err
= marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
599 /* Configure the copper link first */
600 err
= m88e1318_config_aneg(phydev
);
604 /* Do not touch the fiber page if we're in copper->sgmii mode */
605 if (phydev
->interface
== PHY_INTERFACE_MODE_SGMII
)
608 /* Then the fiber link */
609 err
= marvell_set_page(phydev
, MII_MARVELL_FIBER_PAGE
);
613 err
= marvell_config_aneg_fiber(phydev
);
617 return marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
620 marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
624 static int marvell_config_init(struct phy_device
*phydev
)
626 /* Set registers from marvell,reg-init DT property */
627 return marvell_of_reg_init(phydev
);
630 static int m88e1116r_config_init(struct phy_device
*phydev
)
634 err
= genphy_soft_reset(phydev
);
640 err
= marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
644 err
= marvell_set_polarity(phydev
, phydev
->mdix_ctrl
);
648 err
= marvell_set_downshift(phydev
, true, 8);
652 if (phy_interface_is_rgmii(phydev
)) {
653 err
= m88e1121_config_aneg_rgmii_delays(phydev
);
658 err
= genphy_soft_reset(phydev
);
662 return marvell_config_init(phydev
);
665 static int m88e3016_config_init(struct phy_device
*phydev
)
669 /* Enable Scrambler and Auto-Crossover */
670 ret
= phy_modify(phydev
, MII_88E3016_PHY_SPEC_CTRL
,
671 MII_88E3016_DISABLE_SCRAMBLER
,
672 MII_88E3016_AUTO_MDIX_CROSSOVER
);
676 return marvell_config_init(phydev
);
679 static int m88e1111_config_init_hwcfg_mode(struct phy_device
*phydev
,
681 int fibre_copper_auto
)
683 if (fibre_copper_auto
)
684 mode
|= MII_M1111_HWCFG_FIBER_COPPER_AUTO
;
686 return phy_modify(phydev
, MII_M1111_PHY_EXT_SR
,
687 MII_M1111_HWCFG_MODE_MASK
|
688 MII_M1111_HWCFG_FIBER_COPPER_AUTO
|
689 MII_M1111_HWCFG_FIBER_COPPER_RES
,
693 static int m88e1111_config_init_rgmii_delays(struct phy_device
*phydev
)
697 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
) {
698 delay
= MII_M1111_RGMII_RX_DELAY
| MII_M1111_RGMII_TX_DELAY
;
699 } else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_RXID
) {
700 delay
= MII_M1111_RGMII_RX_DELAY
;
701 } else if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_TXID
) {
702 delay
= MII_M1111_RGMII_TX_DELAY
;
707 return phy_modify(phydev
, MII_M1111_PHY_EXT_CR
,
708 MII_M1111_RGMII_RX_DELAY
| MII_M1111_RGMII_TX_DELAY
,
712 static int m88e1111_config_init_rgmii(struct phy_device
*phydev
)
717 err
= m88e1111_config_init_rgmii_delays(phydev
);
721 temp
= phy_read(phydev
, MII_M1111_PHY_EXT_SR
);
725 temp
&= ~(MII_M1111_HWCFG_MODE_MASK
);
727 if (temp
& MII_M1111_HWCFG_FIBER_COPPER_RES
)
728 temp
|= MII_M1111_HWCFG_MODE_FIBER_RGMII
;
730 temp
|= MII_M1111_HWCFG_MODE_COPPER_RGMII
;
732 return phy_write(phydev
, MII_M1111_PHY_EXT_SR
, temp
);
735 static int m88e1111_config_init_sgmii(struct phy_device
*phydev
)
739 err
= m88e1111_config_init_hwcfg_mode(
741 MII_M1111_HWCFG_MODE_SGMII_NO_CLK
,
742 MII_M1111_HWCFG_FIBER_COPPER_AUTO
);
746 /* make sure copper is selected */
747 return marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
750 static int m88e1111_config_init_rtbi(struct phy_device
*phydev
)
754 err
= m88e1111_config_init_rgmii_delays(phydev
);
758 err
= m88e1111_config_init_hwcfg_mode(
760 MII_M1111_HWCFG_MODE_RTBI
,
761 MII_M1111_HWCFG_FIBER_COPPER_AUTO
);
766 err
= genphy_soft_reset(phydev
);
770 return m88e1111_config_init_hwcfg_mode(
772 MII_M1111_HWCFG_MODE_RTBI
,
773 MII_M1111_HWCFG_FIBER_COPPER_AUTO
);
776 static int m88e1111_config_init(struct phy_device
*phydev
)
780 if (phy_interface_is_rgmii(phydev
)) {
781 err
= m88e1111_config_init_rgmii(phydev
);
786 if (phydev
->interface
== PHY_INTERFACE_MODE_SGMII
) {
787 err
= m88e1111_config_init_sgmii(phydev
);
792 if (phydev
->interface
== PHY_INTERFACE_MODE_RTBI
) {
793 err
= m88e1111_config_init_rtbi(phydev
);
798 err
= marvell_of_reg_init(phydev
);
802 return genphy_soft_reset(phydev
);
805 static int m88e1121_config_init(struct phy_device
*phydev
)
809 /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
810 err
= phy_write_paged(phydev
, MII_MARVELL_LED_PAGE
,
811 MII_88E1121_PHY_LED_CTRL
,
812 MII_88E1121_PHY_LED_DEF
);
816 /* Set marvell,reg-init configuration from device tree */
817 return marvell_config_init(phydev
);
820 static int m88e1510_config_init(struct phy_device
*phydev
)
824 /* SGMII-to-Copper mode initialization */
825 if (phydev
->interface
== PHY_INTERFACE_MODE_SGMII
) {
829 err
= marvell_set_page(phydev
, 18);
833 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
834 err
= phy_modify(phydev
, MII_88E1510_GEN_CTRL_REG_1
,
835 MII_88E1510_GEN_CTRL_REG_1_MODE_MASK
,
836 MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII
);
840 /* PHY reset is necessary after changing MODE[2:0] */
841 err
= phy_modify(phydev
, MII_88E1510_GEN_CTRL_REG_1
, 0,
842 MII_88E1510_GEN_CTRL_REG_1_RESET
);
846 /* Reset page selection */
847 err
= marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
851 /* There appears to be a bug in the 88e1512 when used in
852 * SGMII to copper mode, where the AN advertisment register
853 * clears the pause bits each time a negotiation occurs.
854 * This means we can never be truely sure what was advertised,
855 * so disable Pause support.
857 pause
= SUPPORTED_Pause
| SUPPORTED_Asym_Pause
;
858 phydev
->supported
&= ~pause
;
859 phydev
->advertising
&= ~pause
;
862 return m88e1121_config_init(phydev
);
865 static int m88e1118_config_aneg(struct phy_device
*phydev
)
869 err
= genphy_soft_reset(phydev
);
873 err
= marvell_set_polarity(phydev
, phydev
->mdix_ctrl
);
877 err
= genphy_config_aneg(phydev
);
881 static int m88e1118_config_init(struct phy_device
*phydev
)
886 err
= marvell_set_page(phydev
, MII_MARVELL_MSCR_PAGE
);
890 /* Enable 1000 Mbit */
891 err
= phy_write(phydev
, 0x15, 0x1070);
896 err
= marvell_set_page(phydev
, MII_MARVELL_LED_PAGE
);
900 /* Adjust LED Control */
901 if (phydev
->dev_flags
& MARVELL_PHY_M1118_DNS323_LEDS
)
902 err
= phy_write(phydev
, 0x10, 0x1100);
904 err
= phy_write(phydev
, 0x10, 0x021e);
908 err
= marvell_of_reg_init(phydev
);
913 err
= marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
917 return genphy_soft_reset(phydev
);
920 static int m88e1149_config_init(struct phy_device
*phydev
)
925 err
= marvell_set_page(phydev
, MII_MARVELL_MSCR_PAGE
);
929 /* Enable 1000 Mbit */
930 err
= phy_write(phydev
, 0x15, 0x1048);
934 err
= marvell_of_reg_init(phydev
);
939 err
= marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
943 return genphy_soft_reset(phydev
);
946 static int m88e1145_config_init_rgmii(struct phy_device
*phydev
)
950 err
= m88e1111_config_init_rgmii_delays(phydev
);
954 if (phydev
->dev_flags
& MARVELL_PHY_M1145_FLAGS_RESISTANCE
) {
955 err
= phy_write(phydev
, 0x1d, 0x0012);
959 err
= phy_modify(phydev
, 0x1e, 0x0fc0,
960 2 << 9 | /* 36 ohm */
961 2 << 6); /* 39 ohm */
965 err
= phy_write(phydev
, 0x1d, 0x3);
969 err
= phy_write(phydev
, 0x1e, 0x8000);
974 static int m88e1145_config_init_sgmii(struct phy_device
*phydev
)
976 return m88e1111_config_init_hwcfg_mode(
977 phydev
, MII_M1111_HWCFG_MODE_SGMII_NO_CLK
,
978 MII_M1111_HWCFG_FIBER_COPPER_AUTO
);
981 static int m88e1145_config_init(struct phy_device
*phydev
)
985 /* Take care of errata E0 & E1 */
986 err
= phy_write(phydev
, 0x1d, 0x001b);
990 err
= phy_write(phydev
, 0x1e, 0x418f);
994 err
= phy_write(phydev
, 0x1d, 0x0016);
998 err
= phy_write(phydev
, 0x1e, 0xa2da);
1002 if (phydev
->interface
== PHY_INTERFACE_MODE_RGMII_ID
) {
1003 err
= m88e1145_config_init_rgmii(phydev
);
1008 if (phydev
->interface
== PHY_INTERFACE_MODE_SGMII
) {
1009 err
= m88e1145_config_init_sgmii(phydev
);
1014 err
= marvell_of_reg_init(phydev
);
1022 * fiber_lpa_to_ethtool_lpa_t
1023 * @lpa: value of the MII_LPA register for fiber link
1025 * A small helper function that translates MII_LPA
1026 * bits to ethtool LP advertisement settings.
1028 static u32
fiber_lpa_to_ethtool_lpa_t(u32 lpa
)
1032 if (lpa
& LPA_FIBER_1000HALF
)
1033 result
|= ADVERTISED_1000baseT_Half
;
1034 if (lpa
& LPA_FIBER_1000FULL
)
1035 result
|= ADVERTISED_1000baseT_Full
;
1041 * marvell_update_link - update link status in real time in @phydev
1042 * @phydev: target phy_device struct
1044 * Description: Update the value in phydev->link to reflect the
1045 * current link value.
1047 static int marvell_update_link(struct phy_device
*phydev
, int fiber
)
1051 /* Use the generic register for copper link, or specific
1052 * register for fiber case
1055 status
= phy_read(phydev
, MII_M1011_PHY_STATUS
);
1059 if ((status
& REGISTER_LINK_STATUS
) == 0)
1064 return genphy_update_link(phydev
);
1070 static int marvell_read_status_page_an(struct phy_device
*phydev
,
1077 status
= phy_read(phydev
, MII_M1011_PHY_STATUS
);
1081 lpa
= phy_read(phydev
, MII_LPA
);
1085 lpagb
= phy_read(phydev
, MII_STAT1000
);
1089 if (status
& MII_M1011_PHY_STATUS_FULLDUPLEX
)
1090 phydev
->duplex
= DUPLEX_FULL
;
1092 phydev
->duplex
= DUPLEX_HALF
;
1094 status
= status
& MII_M1011_PHY_STATUS_SPD_MASK
;
1096 phydev
->asym_pause
= 0;
1099 case MII_M1011_PHY_STATUS_1000
:
1100 phydev
->speed
= SPEED_1000
;
1103 case MII_M1011_PHY_STATUS_100
:
1104 phydev
->speed
= SPEED_100
;
1108 phydev
->speed
= SPEED_10
;
1113 phydev
->lp_advertising
=
1114 mii_stat1000_to_ethtool_lpa_t(lpagb
) |
1115 mii_lpa_to_ethtool_lpa_t(lpa
);
1117 if (phydev
->duplex
== DUPLEX_FULL
) {
1118 phydev
->pause
= lpa
& LPA_PAUSE_CAP
? 1 : 0;
1119 phydev
->asym_pause
= lpa
& LPA_PAUSE_ASYM
? 1 : 0;
1122 /* The fiber link is only 1000M capable */
1123 phydev
->lp_advertising
= fiber_lpa_to_ethtool_lpa_t(lpa
);
1125 if (phydev
->duplex
== DUPLEX_FULL
) {
1126 if (!(lpa
& LPA_PAUSE_FIBER
)) {
1128 phydev
->asym_pause
= 0;
1129 } else if ((lpa
& LPA_PAUSE_ASYM_FIBER
)) {
1131 phydev
->asym_pause
= 1;
1134 phydev
->asym_pause
= 0;
1141 static int marvell_read_status_page_fixed(struct phy_device
*phydev
)
1143 int bmcr
= phy_read(phydev
, MII_BMCR
);
1148 if (bmcr
& BMCR_FULLDPLX
)
1149 phydev
->duplex
= DUPLEX_FULL
;
1151 phydev
->duplex
= DUPLEX_HALF
;
1153 if (bmcr
& BMCR_SPEED1000
)
1154 phydev
->speed
= SPEED_1000
;
1155 else if (bmcr
& BMCR_SPEED100
)
1156 phydev
->speed
= SPEED_100
;
1158 phydev
->speed
= SPEED_10
;
1161 phydev
->asym_pause
= 0;
1162 phydev
->lp_advertising
= 0;
1167 /* marvell_read_status_page
1170 * Check the link, then figure out the current state
1171 * by comparing what we advertise with what the link partner
1172 * advertises. Start by checking the gigabit possibilities,
1173 * then move on to 10/100.
1175 static int marvell_read_status_page(struct phy_device
*phydev
, int page
)
1180 /* Detect and update the link, but return if there
1183 if (page
== MII_MARVELL_FIBER_PAGE
)
1188 err
= marvell_update_link(phydev
, fiber
);
1192 if (phydev
->autoneg
== AUTONEG_ENABLE
)
1193 err
= marvell_read_status_page_an(phydev
, fiber
);
1195 err
= marvell_read_status_page_fixed(phydev
);
1200 /* marvell_read_status
1202 * Some Marvell's phys have two modes: fiber and copper.
1203 * Both need status checked.
1205 * First, check the fiber link and status.
1206 * If the fiber link is down, check the copper link and status which
1207 * will be the default value if both link are down.
1209 static int marvell_read_status(struct phy_device
*phydev
)
1213 /* Check the fiber mode first */
1214 if (phydev
->supported
& SUPPORTED_FIBRE
&&
1215 phydev
->interface
!= PHY_INTERFACE_MODE_SGMII
) {
1216 err
= marvell_set_page(phydev
, MII_MARVELL_FIBER_PAGE
);
1220 err
= marvell_read_status_page(phydev
, MII_MARVELL_FIBER_PAGE
);
1224 /* If the fiber link is up, it is the selected and
1225 * used link. In this case, we need to stay in the
1226 * fiber page. Please to be careful about that, avoid
1227 * to restore Copper page in other functions which
1228 * could break the behaviour for some fiber phy like
1234 /* If fiber link is down, check and save copper mode state */
1235 err
= marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
1240 return marvell_read_status_page(phydev
, MII_MARVELL_COPPER_PAGE
);
1243 marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
1249 * Some Marvell's phys have two modes: fiber and copper.
1250 * Both need to be suspended
1252 static int marvell_suspend(struct phy_device
*phydev
)
1256 /* Suspend the fiber mode first */
1257 if (!(phydev
->supported
& SUPPORTED_FIBRE
)) {
1258 err
= marvell_set_page(phydev
, MII_MARVELL_FIBER_PAGE
);
1262 /* With the page set, use the generic suspend */
1263 err
= genphy_suspend(phydev
);
1267 /* Then, the copper link */
1268 err
= marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
1273 /* With the page set, use the generic suspend */
1274 return genphy_suspend(phydev
);
1277 marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
1283 * Some Marvell's phys have two modes: fiber and copper.
1284 * Both need to be resumed
1286 static int marvell_resume(struct phy_device
*phydev
)
1290 /* Resume the fiber mode first */
1291 if (!(phydev
->supported
& SUPPORTED_FIBRE
)) {
1292 err
= marvell_set_page(phydev
, MII_MARVELL_FIBER_PAGE
);
1296 /* With the page set, use the generic resume */
1297 err
= genphy_resume(phydev
);
1301 /* Then, the copper link */
1302 err
= marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
1307 /* With the page set, use the generic resume */
1308 return genphy_resume(phydev
);
1311 marvell_set_page(phydev
, MII_MARVELL_COPPER_PAGE
);
1315 static int marvell_aneg_done(struct phy_device
*phydev
)
1317 int retval
= phy_read(phydev
, MII_M1011_PHY_STATUS
);
1319 return (retval
< 0) ? retval
: (retval
& MII_M1011_PHY_STATUS_RESOLVED
);
1322 static int m88e1121_did_interrupt(struct phy_device
*phydev
)
1326 imask
= phy_read(phydev
, MII_M1011_IEVENT
);
1328 if (imask
& MII_M1011_IMASK_INIT
)
1334 static void m88e1318_get_wol(struct phy_device
*phydev
,
1335 struct ethtool_wolinfo
*wol
)
1337 int oldpage
, ret
= 0;
1339 wol
->supported
= WAKE_MAGIC
;
1342 oldpage
= phy_select_page(phydev
, MII_MARVELL_WOL_PAGE
);
1346 ret
= __phy_read(phydev
, MII_88E1318S_PHY_WOL_CTRL
);
1347 if (ret
& MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
)
1348 wol
->wolopts
|= WAKE_MAGIC
;
1351 phy_restore_page(phydev
, oldpage
, ret
);
1354 static int m88e1318_set_wol(struct phy_device
*phydev
,
1355 struct ethtool_wolinfo
*wol
)
1357 int err
= 0, oldpage
;
1359 oldpage
= phy_save_page(phydev
);
1363 if (wol
->wolopts
& WAKE_MAGIC
) {
1364 /* Explicitly switch to page 0x00, just to be sure */
1365 err
= marvell_write_page(phydev
, MII_MARVELL_COPPER_PAGE
);
1369 /* Enable the WOL interrupt */
1370 err
= __phy_modify(phydev
, MII_88E1318S_PHY_CSIER
, 0,
1371 MII_88E1318S_PHY_CSIER_WOL_EIE
);
1375 err
= marvell_write_page(phydev
, MII_MARVELL_LED_PAGE
);
1379 /* Setup LED[2] as interrupt pin (active low) */
1380 err
= __phy_modify(phydev
, MII_88E1318S_PHY_LED_TCR
,
1381 MII_88E1318S_PHY_LED_TCR_FORCE_INT
,
1382 MII_88E1318S_PHY_LED_TCR_INTn_ENABLE
|
1383 MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW
);
1387 err
= marvell_write_page(phydev
, MII_MARVELL_WOL_PAGE
);
1391 /* Store the device address for the magic packet */
1392 err
= __phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD2
,
1393 ((phydev
->attached_dev
->dev_addr
[5] << 8) |
1394 phydev
->attached_dev
->dev_addr
[4]));
1397 err
= __phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD1
,
1398 ((phydev
->attached_dev
->dev_addr
[3] << 8) |
1399 phydev
->attached_dev
->dev_addr
[2]));
1402 err
= __phy_write(phydev
, MII_88E1318S_PHY_MAGIC_PACKET_WORD0
,
1403 ((phydev
->attached_dev
->dev_addr
[1] << 8) |
1404 phydev
->attached_dev
->dev_addr
[0]));
1408 /* Clear WOL status and enable magic packet matching */
1409 err
= __phy_modify(phydev
, MII_88E1318S_PHY_WOL_CTRL
, 0,
1410 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS
|
1411 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
);
1415 err
= marvell_write_page(phydev
, MII_MARVELL_WOL_PAGE
);
1419 /* Clear WOL status and disable magic packet matching */
1420 err
= __phy_modify(phydev
, MII_88E1318S_PHY_WOL_CTRL
,
1421 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE
,
1422 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS
);
1428 return phy_restore_page(phydev
, oldpage
, err
);
1431 static int marvell_get_sset_count(struct phy_device
*phydev
)
1433 if (phydev
->supported
& SUPPORTED_FIBRE
)
1434 return ARRAY_SIZE(marvell_hw_stats
);
1436 return ARRAY_SIZE(marvell_hw_stats
) - NB_FIBER_STATS
;
1439 static void marvell_get_strings(struct phy_device
*phydev
, u8
*data
)
1443 for (i
= 0; i
< ARRAY_SIZE(marvell_hw_stats
); i
++) {
1444 memcpy(data
+ i
* ETH_GSTRING_LEN
,
1445 marvell_hw_stats
[i
].string
, ETH_GSTRING_LEN
);
1450 #define UINT64_MAX (u64)(~((u64)0))
1452 static u64
marvell_get_stat(struct phy_device
*phydev
, int i
)
1454 struct marvell_hw_stat stat
= marvell_hw_stats
[i
];
1455 struct marvell_priv
*priv
= phydev
->priv
;
1459 val
= phy_read_paged(phydev
, stat
.page
, stat
.reg
);
1463 val
= val
& ((1 << stat
.bits
) - 1);
1464 priv
->stats
[i
] += val
;
1465 ret
= priv
->stats
[i
];
1471 static void marvell_get_stats(struct phy_device
*phydev
,
1472 struct ethtool_stats
*stats
, u64
*data
)
1476 for (i
= 0; i
< ARRAY_SIZE(marvell_hw_stats
); i
++)
1477 data
[i
] = marvell_get_stat(phydev
, i
);
1481 static int m88e1121_get_temp(struct phy_device
*phydev
, long *temp
)
1489 oldpage
= phy_select_page(phydev
, MII_MARVELL_MISC_TEST_PAGE
);
1493 /* Enable temperature sensor */
1494 ret
= __phy_read(phydev
, MII_88E1121_MISC_TEST
);
1498 ret
= __phy_write(phydev
, MII_88E1121_MISC_TEST
,
1499 ret
| MII_88E1121_MISC_TEST_TEMP_SENSOR_EN
);
1503 /* Wait for temperature to stabilize */
1504 usleep_range(10000, 12000);
1506 val
= __phy_read(phydev
, MII_88E1121_MISC_TEST
);
1512 /* Disable temperature sensor */
1513 ret
= __phy_write(phydev
, MII_88E1121_MISC_TEST
,
1514 ret
& ~MII_88E1121_MISC_TEST_TEMP_SENSOR_EN
);
1518 *temp
= ((val
& MII_88E1121_MISC_TEST_TEMP_MASK
) - 5) * 5000;
1521 return phy_restore_page(phydev
, oldpage
, ret
);
1524 static int m88e1121_hwmon_read(struct device
*dev
,
1525 enum hwmon_sensor_types type
,
1526 u32 attr
, int channel
, long *temp
)
1528 struct phy_device
*phydev
= dev_get_drvdata(dev
);
1532 case hwmon_temp_input
:
1533 err
= m88e1121_get_temp(phydev
, temp
);
1542 static umode_t
m88e1121_hwmon_is_visible(const void *data
,
1543 enum hwmon_sensor_types type
,
1544 u32 attr
, int channel
)
1546 if (type
!= hwmon_temp
)
1550 case hwmon_temp_input
:
1557 static u32 m88e1121_hwmon_chip_config
[] = {
1558 HWMON_C_REGISTER_TZ
,
1562 static const struct hwmon_channel_info m88e1121_hwmon_chip
= {
1564 .config
= m88e1121_hwmon_chip_config
,
1567 static u32 m88e1121_hwmon_temp_config
[] = {
1572 static const struct hwmon_channel_info m88e1121_hwmon_temp
= {
1574 .config
= m88e1121_hwmon_temp_config
,
1577 static const struct hwmon_channel_info
*m88e1121_hwmon_info
[] = {
1578 &m88e1121_hwmon_chip
,
1579 &m88e1121_hwmon_temp
,
1583 static const struct hwmon_ops m88e1121_hwmon_hwmon_ops
= {
1584 .is_visible
= m88e1121_hwmon_is_visible
,
1585 .read
= m88e1121_hwmon_read
,
1588 static const struct hwmon_chip_info m88e1121_hwmon_chip_info
= {
1589 .ops
= &m88e1121_hwmon_hwmon_ops
,
1590 .info
= m88e1121_hwmon_info
,
1593 static int m88e1510_get_temp(struct phy_device
*phydev
, long *temp
)
1599 ret
= phy_read_paged(phydev
, MII_MARVELL_MISC_TEST_PAGE
,
1600 MII_88E1510_TEMP_SENSOR
);
1604 *temp
= ((ret
& MII_88E1510_TEMP_SENSOR_MASK
) - 25) * 1000;
1609 static int m88e1510_get_temp_critical(struct phy_device
*phydev
, long *temp
)
1615 ret
= phy_read_paged(phydev
, MII_MARVELL_MISC_TEST_PAGE
,
1616 MII_88E1121_MISC_TEST
);
1620 *temp
= (((ret
& MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK
) >>
1621 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT
) * 5) - 25;
1628 static int m88e1510_set_temp_critical(struct phy_device
*phydev
, long temp
)
1631 temp
= clamp_val(DIV_ROUND_CLOSEST(temp
, 5) + 5, 0, 0x1f);
1633 return phy_modify_paged(phydev
, MII_MARVELL_MISC_TEST_PAGE
,
1634 MII_88E1121_MISC_TEST
,
1635 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK
,
1636 temp
<< MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT
);
1639 static int m88e1510_get_temp_alarm(struct phy_device
*phydev
, long *alarm
)
1645 ret
= phy_read_paged(phydev
, MII_MARVELL_MISC_TEST_PAGE
,
1646 MII_88E1121_MISC_TEST
);
1650 *alarm
= !!(ret
& MII_88E1510_MISC_TEST_TEMP_IRQ
);
1655 static int m88e1510_hwmon_read(struct device
*dev
,
1656 enum hwmon_sensor_types type
,
1657 u32 attr
, int channel
, long *temp
)
1659 struct phy_device
*phydev
= dev_get_drvdata(dev
);
1663 case hwmon_temp_input
:
1664 err
= m88e1510_get_temp(phydev
, temp
);
1666 case hwmon_temp_crit
:
1667 err
= m88e1510_get_temp_critical(phydev
, temp
);
1669 case hwmon_temp_max_alarm
:
1670 err
= m88e1510_get_temp_alarm(phydev
, temp
);
1679 static int m88e1510_hwmon_write(struct device
*dev
,
1680 enum hwmon_sensor_types type
,
1681 u32 attr
, int channel
, long temp
)
1683 struct phy_device
*phydev
= dev_get_drvdata(dev
);
1687 case hwmon_temp_crit
:
1688 err
= m88e1510_set_temp_critical(phydev
, temp
);
1696 static umode_t
m88e1510_hwmon_is_visible(const void *data
,
1697 enum hwmon_sensor_types type
,
1698 u32 attr
, int channel
)
1700 if (type
!= hwmon_temp
)
1704 case hwmon_temp_input
:
1705 case hwmon_temp_max_alarm
:
1707 case hwmon_temp_crit
:
1714 static u32 m88e1510_hwmon_temp_config
[] = {
1715 HWMON_T_INPUT
| HWMON_T_CRIT
| HWMON_T_MAX_ALARM
,
1719 static const struct hwmon_channel_info m88e1510_hwmon_temp
= {
1721 .config
= m88e1510_hwmon_temp_config
,
1724 static const struct hwmon_channel_info
*m88e1510_hwmon_info
[] = {
1725 &m88e1121_hwmon_chip
,
1726 &m88e1510_hwmon_temp
,
1730 static const struct hwmon_ops m88e1510_hwmon_hwmon_ops
= {
1731 .is_visible
= m88e1510_hwmon_is_visible
,
1732 .read
= m88e1510_hwmon_read
,
1733 .write
= m88e1510_hwmon_write
,
1736 static const struct hwmon_chip_info m88e1510_hwmon_chip_info
= {
1737 .ops
= &m88e1510_hwmon_hwmon_ops
,
1738 .info
= m88e1510_hwmon_info
,
1741 static int marvell_hwmon_name(struct phy_device
*phydev
)
1743 struct marvell_priv
*priv
= phydev
->priv
;
1744 struct device
*dev
= &phydev
->mdio
.dev
;
1745 const char *devname
= dev_name(dev
);
1746 size_t len
= strlen(devname
);
1749 priv
->hwmon_name
= devm_kzalloc(dev
, len
, GFP_KERNEL
);
1750 if (!priv
->hwmon_name
)
1753 for (i
= j
= 0; i
< len
&& devname
[i
]; i
++) {
1754 if (isalnum(devname
[i
]))
1755 priv
->hwmon_name
[j
++] = devname
[i
];
1761 static int marvell_hwmon_probe(struct phy_device
*phydev
,
1762 const struct hwmon_chip_info
*chip
)
1764 struct marvell_priv
*priv
= phydev
->priv
;
1765 struct device
*dev
= &phydev
->mdio
.dev
;
1768 err
= marvell_hwmon_name(phydev
);
1772 priv
->hwmon_dev
= devm_hwmon_device_register_with_info(
1773 dev
, priv
->hwmon_name
, phydev
, chip
, NULL
);
1775 return PTR_ERR_OR_ZERO(priv
->hwmon_dev
);
1778 static int m88e1121_hwmon_probe(struct phy_device
*phydev
)
1780 return marvell_hwmon_probe(phydev
, &m88e1121_hwmon_chip_info
);
1783 static int m88e1510_hwmon_probe(struct phy_device
*phydev
)
1785 return marvell_hwmon_probe(phydev
, &m88e1510_hwmon_chip_info
);
1788 static int m88e1121_hwmon_probe(struct phy_device
*phydev
)
1793 static int m88e1510_hwmon_probe(struct phy_device
*phydev
)
1799 static int marvell_probe(struct phy_device
*phydev
)
1801 struct marvell_priv
*priv
;
1803 priv
= devm_kzalloc(&phydev
->mdio
.dev
, sizeof(*priv
), GFP_KERNEL
);
1807 phydev
->priv
= priv
;
1812 static int m88e1121_probe(struct phy_device
*phydev
)
1816 err
= marvell_probe(phydev
);
1820 return m88e1121_hwmon_probe(phydev
);
1823 static int m88e1510_probe(struct phy_device
*phydev
)
1827 err
= marvell_probe(phydev
);
1831 return m88e1510_hwmon_probe(phydev
);
1834 static struct phy_driver marvell_drivers
[] = {
1836 .phy_id
= MARVELL_PHY_ID_88E1101
,
1837 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1838 .name
= "Marvell 88E1101",
1839 .features
= PHY_GBIT_FEATURES
,
1840 .flags
= PHY_HAS_INTERRUPT
,
1841 .probe
= marvell_probe
,
1842 .config_init
= &marvell_config_init
,
1843 .config_aneg
= &m88e1101_config_aneg
,
1844 .ack_interrupt
= &marvell_ack_interrupt
,
1845 .config_intr
= &marvell_config_intr
,
1846 .resume
= &genphy_resume
,
1847 .suspend
= &genphy_suspend
,
1848 .read_page
= marvell_read_page
,
1849 .write_page
= marvell_write_page
,
1850 .get_sset_count
= marvell_get_sset_count
,
1851 .get_strings
= marvell_get_strings
,
1852 .get_stats
= marvell_get_stats
,
1855 .phy_id
= MARVELL_PHY_ID_88E1112
,
1856 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1857 .name
= "Marvell 88E1112",
1858 .features
= PHY_GBIT_FEATURES
,
1859 .flags
= PHY_HAS_INTERRUPT
,
1860 .probe
= marvell_probe
,
1861 .config_init
= &m88e1111_config_init
,
1862 .config_aneg
= &marvell_config_aneg
,
1863 .ack_interrupt
= &marvell_ack_interrupt
,
1864 .config_intr
= &marvell_config_intr
,
1865 .resume
= &genphy_resume
,
1866 .suspend
= &genphy_suspend
,
1867 .read_page
= marvell_read_page
,
1868 .write_page
= marvell_write_page
,
1869 .get_sset_count
= marvell_get_sset_count
,
1870 .get_strings
= marvell_get_strings
,
1871 .get_stats
= marvell_get_stats
,
1874 .phy_id
= MARVELL_PHY_ID_88E1111
,
1875 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1876 .name
= "Marvell 88E1111",
1877 .features
= PHY_GBIT_FEATURES
,
1878 .flags
= PHY_HAS_INTERRUPT
,
1879 .probe
= marvell_probe
,
1880 .config_init
= &m88e1111_config_init
,
1881 .config_aneg
= &m88e1111_config_aneg
,
1882 .read_status
= &marvell_read_status
,
1883 .ack_interrupt
= &marvell_ack_interrupt
,
1884 .config_intr
= &marvell_config_intr
,
1885 .resume
= &genphy_resume
,
1886 .suspend
= &genphy_suspend
,
1887 .read_page
= marvell_read_page
,
1888 .write_page
= marvell_write_page
,
1889 .get_sset_count
= marvell_get_sset_count
,
1890 .get_strings
= marvell_get_strings
,
1891 .get_stats
= marvell_get_stats
,
1894 .phy_id
= MARVELL_PHY_ID_88E1118
,
1895 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1896 .name
= "Marvell 88E1118",
1897 .features
= PHY_GBIT_FEATURES
,
1898 .flags
= PHY_HAS_INTERRUPT
,
1899 .probe
= marvell_probe
,
1900 .config_init
= &m88e1118_config_init
,
1901 .config_aneg
= &m88e1118_config_aneg
,
1902 .ack_interrupt
= &marvell_ack_interrupt
,
1903 .config_intr
= &marvell_config_intr
,
1904 .resume
= &genphy_resume
,
1905 .suspend
= &genphy_suspend
,
1906 .read_page
= marvell_read_page
,
1907 .write_page
= marvell_write_page
,
1908 .get_sset_count
= marvell_get_sset_count
,
1909 .get_strings
= marvell_get_strings
,
1910 .get_stats
= marvell_get_stats
,
1913 .phy_id
= MARVELL_PHY_ID_88E1121R
,
1914 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1915 .name
= "Marvell 88E1121R",
1916 .features
= PHY_GBIT_FEATURES
,
1917 .flags
= PHY_HAS_INTERRUPT
,
1918 .probe
= &m88e1121_probe
,
1919 .config_init
= &m88e1121_config_init
,
1920 .config_aneg
= &m88e1121_config_aneg
,
1921 .read_status
= &marvell_read_status
,
1922 .ack_interrupt
= &marvell_ack_interrupt
,
1923 .config_intr
= &marvell_config_intr
,
1924 .did_interrupt
= &m88e1121_did_interrupt
,
1925 .resume
= &genphy_resume
,
1926 .suspend
= &genphy_suspend
,
1927 .read_page
= marvell_read_page
,
1928 .write_page
= marvell_write_page
,
1929 .get_sset_count
= marvell_get_sset_count
,
1930 .get_strings
= marvell_get_strings
,
1931 .get_stats
= marvell_get_stats
,
1934 .phy_id
= MARVELL_PHY_ID_88E1318S
,
1935 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1936 .name
= "Marvell 88E1318S",
1937 .features
= PHY_GBIT_FEATURES
,
1938 .flags
= PHY_HAS_INTERRUPT
,
1939 .probe
= marvell_probe
,
1940 .config_init
= &m88e1121_config_init
,
1941 .config_aneg
= &m88e1318_config_aneg
,
1942 .read_status
= &marvell_read_status
,
1943 .ack_interrupt
= &marvell_ack_interrupt
,
1944 .config_intr
= &marvell_config_intr
,
1945 .did_interrupt
= &m88e1121_did_interrupt
,
1946 .get_wol
= &m88e1318_get_wol
,
1947 .set_wol
= &m88e1318_set_wol
,
1948 .resume
= &genphy_resume
,
1949 .suspend
= &genphy_suspend
,
1950 .read_page
= marvell_read_page
,
1951 .write_page
= marvell_write_page
,
1952 .get_sset_count
= marvell_get_sset_count
,
1953 .get_strings
= marvell_get_strings
,
1954 .get_stats
= marvell_get_stats
,
1957 .phy_id
= MARVELL_PHY_ID_88E1145
,
1958 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1959 .name
= "Marvell 88E1145",
1960 .features
= PHY_GBIT_FEATURES
,
1961 .flags
= PHY_HAS_INTERRUPT
,
1962 .probe
= marvell_probe
,
1963 .config_init
= &m88e1145_config_init
,
1964 .config_aneg
= &m88e1101_config_aneg
,
1965 .read_status
= &genphy_read_status
,
1966 .ack_interrupt
= &marvell_ack_interrupt
,
1967 .config_intr
= &marvell_config_intr
,
1968 .resume
= &genphy_resume
,
1969 .suspend
= &genphy_suspend
,
1970 .read_page
= marvell_read_page
,
1971 .write_page
= marvell_write_page
,
1972 .get_sset_count
= marvell_get_sset_count
,
1973 .get_strings
= marvell_get_strings
,
1974 .get_stats
= marvell_get_stats
,
1977 .phy_id
= MARVELL_PHY_ID_88E1149R
,
1978 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1979 .name
= "Marvell 88E1149R",
1980 .features
= PHY_GBIT_FEATURES
,
1981 .flags
= PHY_HAS_INTERRUPT
,
1982 .probe
= marvell_probe
,
1983 .config_init
= &m88e1149_config_init
,
1984 .config_aneg
= &m88e1118_config_aneg
,
1985 .ack_interrupt
= &marvell_ack_interrupt
,
1986 .config_intr
= &marvell_config_intr
,
1987 .resume
= &genphy_resume
,
1988 .suspend
= &genphy_suspend
,
1989 .read_page
= marvell_read_page
,
1990 .write_page
= marvell_write_page
,
1991 .get_sset_count
= marvell_get_sset_count
,
1992 .get_strings
= marvell_get_strings
,
1993 .get_stats
= marvell_get_stats
,
1996 .phy_id
= MARVELL_PHY_ID_88E1240
,
1997 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
1998 .name
= "Marvell 88E1240",
1999 .features
= PHY_GBIT_FEATURES
,
2000 .flags
= PHY_HAS_INTERRUPT
,
2001 .probe
= marvell_probe
,
2002 .config_init
= &m88e1111_config_init
,
2003 .config_aneg
= &marvell_config_aneg
,
2004 .ack_interrupt
= &marvell_ack_interrupt
,
2005 .config_intr
= &marvell_config_intr
,
2006 .resume
= &genphy_resume
,
2007 .suspend
= &genphy_suspend
,
2008 .read_page
= marvell_read_page
,
2009 .write_page
= marvell_write_page
,
2010 .get_sset_count
= marvell_get_sset_count
,
2011 .get_strings
= marvell_get_strings
,
2012 .get_stats
= marvell_get_stats
,
2015 .phy_id
= MARVELL_PHY_ID_88E1116R
,
2016 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
2017 .name
= "Marvell 88E1116R",
2018 .features
= PHY_GBIT_FEATURES
,
2019 .flags
= PHY_HAS_INTERRUPT
,
2020 .probe
= marvell_probe
,
2021 .config_init
= &m88e1116r_config_init
,
2022 .ack_interrupt
= &marvell_ack_interrupt
,
2023 .config_intr
= &marvell_config_intr
,
2024 .resume
= &genphy_resume
,
2025 .suspend
= &genphy_suspend
,
2026 .read_page
= marvell_read_page
,
2027 .write_page
= marvell_write_page
,
2028 .get_sset_count
= marvell_get_sset_count
,
2029 .get_strings
= marvell_get_strings
,
2030 .get_stats
= marvell_get_stats
,
2033 .phy_id
= MARVELL_PHY_ID_88E1510
,
2034 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
2035 .name
= "Marvell 88E1510",
2036 .features
= PHY_GBIT_FEATURES
| SUPPORTED_FIBRE
,
2037 .flags
= PHY_HAS_INTERRUPT
,
2038 .probe
= &m88e1510_probe
,
2039 .config_init
= &m88e1510_config_init
,
2040 .config_aneg
= &m88e1510_config_aneg
,
2041 .read_status
= &marvell_read_status
,
2042 .ack_interrupt
= &marvell_ack_interrupt
,
2043 .config_intr
= &marvell_config_intr
,
2044 .did_interrupt
= &m88e1121_did_interrupt
,
2045 .get_wol
= &m88e1318_get_wol
,
2046 .set_wol
= &m88e1318_set_wol
,
2047 .resume
= &marvell_resume
,
2048 .suspend
= &marvell_suspend
,
2049 .read_page
= marvell_read_page
,
2050 .write_page
= marvell_write_page
,
2051 .get_sset_count
= marvell_get_sset_count
,
2052 .get_strings
= marvell_get_strings
,
2053 .get_stats
= marvell_get_stats
,
2054 .set_loopback
= genphy_loopback
,
2057 .phy_id
= MARVELL_PHY_ID_88E1540
,
2058 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
2059 .name
= "Marvell 88E1540",
2060 .features
= PHY_GBIT_FEATURES
,
2061 .flags
= PHY_HAS_INTERRUPT
,
2062 .probe
= m88e1510_probe
,
2063 .config_init
= &marvell_config_init
,
2064 .config_aneg
= &m88e1510_config_aneg
,
2065 .read_status
= &marvell_read_status
,
2066 .ack_interrupt
= &marvell_ack_interrupt
,
2067 .config_intr
= &marvell_config_intr
,
2068 .did_interrupt
= &m88e1121_did_interrupt
,
2069 .resume
= &genphy_resume
,
2070 .suspend
= &genphy_suspend
,
2071 .read_page
= marvell_read_page
,
2072 .write_page
= marvell_write_page
,
2073 .get_sset_count
= marvell_get_sset_count
,
2074 .get_strings
= marvell_get_strings
,
2075 .get_stats
= marvell_get_stats
,
2078 .phy_id
= MARVELL_PHY_ID_88E1545
,
2079 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
2080 .name
= "Marvell 88E1545",
2081 .probe
= m88e1510_probe
,
2082 .features
= PHY_GBIT_FEATURES
,
2083 .flags
= PHY_HAS_INTERRUPT
,
2084 .config_init
= &marvell_config_init
,
2085 .config_aneg
= &m88e1510_config_aneg
,
2086 .read_status
= &marvell_read_status
,
2087 .ack_interrupt
= &marvell_ack_interrupt
,
2088 .config_intr
= &marvell_config_intr
,
2089 .did_interrupt
= &m88e1121_did_interrupt
,
2090 .resume
= &genphy_resume
,
2091 .suspend
= &genphy_suspend
,
2092 .read_page
= marvell_read_page
,
2093 .write_page
= marvell_write_page
,
2094 .get_sset_count
= marvell_get_sset_count
,
2095 .get_strings
= marvell_get_strings
,
2096 .get_stats
= marvell_get_stats
,
2099 .phy_id
= MARVELL_PHY_ID_88E3016
,
2100 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
2101 .name
= "Marvell 88E3016",
2102 .features
= PHY_BASIC_FEATURES
,
2103 .flags
= PHY_HAS_INTERRUPT
,
2104 .probe
= marvell_probe
,
2105 .config_init
= &m88e3016_config_init
,
2106 .aneg_done
= &marvell_aneg_done
,
2107 .read_status
= &marvell_read_status
,
2108 .ack_interrupt
= &marvell_ack_interrupt
,
2109 .config_intr
= &marvell_config_intr
,
2110 .did_interrupt
= &m88e1121_did_interrupt
,
2111 .resume
= &genphy_resume
,
2112 .suspend
= &genphy_suspend
,
2113 .read_page
= marvell_read_page
,
2114 .write_page
= marvell_write_page
,
2115 .get_sset_count
= marvell_get_sset_count
,
2116 .get_strings
= marvell_get_strings
,
2117 .get_stats
= marvell_get_stats
,
2120 .phy_id
= MARVELL_PHY_ID_88E6390
,
2121 .phy_id_mask
= MARVELL_PHY_ID_MASK
,
2122 .name
= "Marvell 88E6390",
2123 .features
= PHY_GBIT_FEATURES
,
2124 .flags
= PHY_HAS_INTERRUPT
,
2125 .probe
= m88e1510_probe
,
2126 .config_init
= &marvell_config_init
,
2127 .config_aneg
= &m88e1510_config_aneg
,
2128 .read_status
= &marvell_read_status
,
2129 .ack_interrupt
= &marvell_ack_interrupt
,
2130 .config_intr
= &marvell_config_intr
,
2131 .did_interrupt
= &m88e1121_did_interrupt
,
2132 .resume
= &genphy_resume
,
2133 .suspend
= &genphy_suspend
,
2134 .read_page
= marvell_read_page
,
2135 .write_page
= marvell_write_page
,
2136 .get_sset_count
= marvell_get_sset_count
,
2137 .get_strings
= marvell_get_strings
,
2138 .get_stats
= marvell_get_stats
,
2142 module_phy_driver(marvell_drivers
);
2144 static struct mdio_device_id __maybe_unused marvell_tbl
[] = {
2145 { MARVELL_PHY_ID_88E1101
, MARVELL_PHY_ID_MASK
},
2146 { MARVELL_PHY_ID_88E1112
, MARVELL_PHY_ID_MASK
},
2147 { MARVELL_PHY_ID_88E1111
, MARVELL_PHY_ID_MASK
},
2148 { MARVELL_PHY_ID_88E1118
, MARVELL_PHY_ID_MASK
},
2149 { MARVELL_PHY_ID_88E1121R
, MARVELL_PHY_ID_MASK
},
2150 { MARVELL_PHY_ID_88E1145
, MARVELL_PHY_ID_MASK
},
2151 { MARVELL_PHY_ID_88E1149R
, MARVELL_PHY_ID_MASK
},
2152 { MARVELL_PHY_ID_88E1240
, MARVELL_PHY_ID_MASK
},
2153 { MARVELL_PHY_ID_88E1318S
, MARVELL_PHY_ID_MASK
},
2154 { MARVELL_PHY_ID_88E1116R
, MARVELL_PHY_ID_MASK
},
2155 { MARVELL_PHY_ID_88E1510
, MARVELL_PHY_ID_MASK
},
2156 { MARVELL_PHY_ID_88E1540
, MARVELL_PHY_ID_MASK
},
2157 { MARVELL_PHY_ID_88E1545
, MARVELL_PHY_ID_MASK
},
2158 { MARVELL_PHY_ID_88E3016
, MARVELL_PHY_ID_MASK
},
2159 { MARVELL_PHY_ID_88E6390
, MARVELL_PHY_ID_MASK
},
2163 MODULE_DEVICE_TABLE(mdio
, marvell_tbl
);