1 // SPDX-License-Identifier: GPL-2.0+
3 * drivers/net/phy/marvell.c
5 * Driver for Marvell PHYs
9 * Copyright (c) 2004 Freescale Semiconductor, Inc.
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/ctype.h>
16 #include <linux/errno.h>
17 #include <linux/unistd.h>
18 #include <linux/hwmon.h>
19 #include <linux/interrupt.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/skbuff.h>
25 #include <linux/spinlock.h>
27 #include <linux/module.h>
28 #include <linux/mii.h>
29 #include <linux/ethtool.h>
30 #include <linux/ethtool_netlink.h>
31 #include <linux/phy.h>
32 #include <linux/marvell_phy.h>
33 #include <linux/bitfield.h>
35 #include <linux/sfp.h>
39 #include <linux/uaccess.h>
41 #define MII_MARVELL_PHY_PAGE 22
42 #define MII_MARVELL_COPPER_PAGE 0x00
43 #define MII_MARVELL_FIBER_PAGE 0x01
44 #define MII_MARVELL_MSCR_PAGE 0x02
45 #define MII_MARVELL_LED_PAGE 0x03
46 #define MII_MARVELL_VCT5_PAGE 0x05
47 #define MII_MARVELL_MISC_TEST_PAGE 0x06
48 #define MII_MARVELL_VCT7_PAGE 0x07
49 #define MII_MARVELL_WOL_PAGE 0x11
50 #define MII_MARVELL_MODE_PAGE 0x12
52 #define MII_M1011_IEVENT 0x13
53 #define MII_M1011_IEVENT_CLEAR 0x0000
55 #define MII_M1011_IMASK 0x12
56 #define MII_M1011_IMASK_INIT 0x6400
57 #define MII_M1011_IMASK_CLEAR 0x0000
59 #define MII_M1011_PHY_SCR 0x10
60 #define MII_M1011_PHY_SCR_DOWNSHIFT_EN BIT(11)
61 #define MII_M1011_PHY_SCR_DOWNSHIFT_MASK GENMASK(14, 12)
62 #define MII_M1011_PHY_SCR_DOWNSHIFT_MAX 8
63 #define MII_M1011_PHY_SCR_MDI (0x0 << 5)
64 #define MII_M1011_PHY_SCR_MDI_X (0x1 << 5)
65 #define MII_M1011_PHY_SCR_AUTO_CROSS (0x3 << 5)
67 #define MII_M1011_PHY_SSR 0x11
68 #define MII_M1011_PHY_SSR_DOWNSHIFT BIT(5)
70 #define MII_M1111_PHY_LED_CONTROL 0x18
71 #define MII_M1111_PHY_LED_DIRECT 0x4100
72 #define MII_M1111_PHY_LED_COMBINE 0x411c
73 #define MII_M1111_PHY_EXT_CR 0x14
74 #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK GENMASK(11, 9)
75 #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_MAX 8
76 #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN BIT(8)
77 #define MII_M1111_RGMII_RX_DELAY BIT(7)
78 #define MII_M1111_RGMII_TX_DELAY BIT(1)
79 #define MII_M1111_PHY_EXT_SR 0x1b
81 #define MII_M1111_HWCFG_MODE_MASK 0xf
82 #define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3
83 #define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4
84 #define MII_M1111_HWCFG_MODE_RTBI 0x7
85 #define MII_M1111_HWCFG_MODE_COPPER_1000X_AN 0x8
86 #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9
87 #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb
88 #define MII_M1111_HWCFG_MODE_COPPER_1000X_NOAN 0xc
89 #define MII_M1111_HWCFG_SERIAL_AN_BYPASS BIT(12)
90 #define MII_M1111_HWCFG_FIBER_COPPER_RES BIT(13)
91 #define MII_M1111_HWCFG_FIBER_COPPER_AUTO BIT(15)
93 #define MII_88E1121_PHY_MSCR_REG 21
94 #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5)
95 #define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4)
96 #define MII_88E1121_PHY_MSCR_DELAY_MASK (BIT(5) | BIT(4))
98 #define MII_88E1121_MISC_TEST 0x1a
99 #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK 0x1f00
100 #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT 8
101 #define MII_88E1510_MISC_TEST_TEMP_IRQ_EN BIT(7)
102 #define MII_88E1510_MISC_TEST_TEMP_IRQ BIT(6)
103 #define MII_88E1121_MISC_TEST_TEMP_SENSOR_EN BIT(5)
104 #define MII_88E1121_MISC_TEST_TEMP_MASK 0x1f
106 #define MII_88E1510_TEMP_SENSOR 0x1b
107 #define MII_88E1510_TEMP_SENSOR_MASK 0xff
109 #define MII_88E1540_COPPER_CTRL3 0x1a
110 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK GENMASK(11, 10)
111 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS 0
112 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS 1
113 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS 2
114 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS 3
115 #define MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN BIT(9)
117 #define MII_88E6390_MISC_TEST 0x1b
118 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_SAMPLE_1S (0x0 << 14)
119 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE (0x1 << 14)
120 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_ONESHOT (0x2 << 14)
121 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_DISABLE (0x3 << 14)
122 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK (0x3 << 14)
123 #define MII_88E6393_MISC_TEST_SAMPLES_2048 (0x0 << 11)
124 #define MII_88E6393_MISC_TEST_SAMPLES_4096 (0x1 << 11)
125 #define MII_88E6393_MISC_TEST_SAMPLES_8192 (0x2 << 11)
126 #define MII_88E6393_MISC_TEST_SAMPLES_16384 (0x3 << 11)
127 #define MII_88E6393_MISC_TEST_SAMPLES_MASK (0x3 << 11)
128 #define MII_88E6393_MISC_TEST_RATE_2_3MS (0x5 << 8)
129 #define MII_88E6393_MISC_TEST_RATE_6_4MS (0x6 << 8)
130 #define MII_88E6393_MISC_TEST_RATE_11_9MS (0x7 << 8)
131 #define MII_88E6393_MISC_TEST_RATE_MASK (0x7 << 8)
133 #define MII_88E6390_TEMP_SENSOR 0x1c
134 #define MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK 0xff00
135 #define MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT 8
136 #define MII_88E6390_TEMP_SENSOR_MASK 0xff
137 #define MII_88E6390_TEMP_SENSOR_SAMPLES 10
139 #define MII_88E1318S_PHY_MSCR1_REG 16
140 #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6)
142 /* Copper Specific Interrupt Enable Register */
143 #define MII_88E1318S_PHY_CSIER 0x12
144 /* WOL Event Interrupt Enable */
145 #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
147 #define MII_88E1318S_PHY_LED_FUNC 0x10
148 #define MII_88E1318S_PHY_LED_FUNC_OFF (0x8)
149 #define MII_88E1318S_PHY_LED_FUNC_ON (0x9)
150 #define MII_88E1318S_PHY_LED_FUNC_HI_Z (0xa)
151 #define MII_88E1318S_PHY_LED_FUNC_BLINK (0xb)
152 #define MII_88E1318S_PHY_LED_TCR 0x12
153 #define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
154 #define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
155 #define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
157 /* Magic Packet MAC address registers */
158 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
159 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18
160 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19
162 #define MII_88E1318S_PHY_WOL_CTRL 0x10
163 #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12)
164 #define MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE BIT(13)
165 #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14)
167 #define MII_PHY_LED_CTRL 16
168 #define MII_88E1121_PHY_LED_DEF 0x0030
169 #define MII_88E1510_PHY_LED_DEF 0x1177
170 #define MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE 0x1040
172 #define MII_M1011_PHY_STATUS 0x11
173 #define MII_M1011_PHY_STATUS_1000 0x8000
174 #define MII_M1011_PHY_STATUS_100 0x4000
175 #define MII_M1011_PHY_STATUS_SPD_MASK 0xc000
176 #define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000
177 #define MII_M1011_PHY_STATUS_RESOLVED 0x0800
178 #define MII_M1011_PHY_STATUS_LINK 0x0400
180 #define MII_88E3016_PHY_SPEC_CTRL 0x10
181 #define MII_88E3016_DISABLE_SCRAMBLER 0x0200
182 #define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030
184 #define MII_88E1510_GEN_CTRL_REG_1 0x14
185 #define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7
186 #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII 0x0 /* RGMII to copper */
187 #define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */
188 /* RGMII to 1000BASE-X */
189 #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X 0x2
190 /* RGMII to 100BASE-FX */
191 #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX 0x3
193 #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII 0x4
194 #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */
196 #define MII_88E1510_MSCR_2 0x15
198 #define MII_VCT5_TX_RX_MDI0_COUPLING 0x10
199 #define MII_VCT5_TX_RX_MDI1_COUPLING 0x11
200 #define MII_VCT5_TX_RX_MDI2_COUPLING 0x12
201 #define MII_VCT5_TX_RX_MDI3_COUPLING 0x13
202 #define MII_VCT5_TX_RX_AMPLITUDE_MASK 0x7f00
203 #define MII_VCT5_TX_RX_AMPLITUDE_SHIFT 8
204 #define MII_VCT5_TX_RX_COUPLING_POSITIVE_REFLECTION BIT(15)
206 #define MII_VCT5_CTRL 0x17
207 #define MII_VCT5_CTRL_ENABLE BIT(15)
208 #define MII_VCT5_CTRL_COMPLETE BIT(14)
209 #define MII_VCT5_CTRL_TX_SAME_CHANNEL (0x0 << 11)
210 #define MII_VCT5_CTRL_TX0_CHANNEL (0x4 << 11)
211 #define MII_VCT5_CTRL_TX1_CHANNEL (0x5 << 11)
212 #define MII_VCT5_CTRL_TX2_CHANNEL (0x6 << 11)
213 #define MII_VCT5_CTRL_TX3_CHANNEL (0x7 << 11)
214 #define MII_VCT5_CTRL_SAMPLES_2 (0x0 << 8)
215 #define MII_VCT5_CTRL_SAMPLES_4 (0x1 << 8)
216 #define MII_VCT5_CTRL_SAMPLES_8 (0x2 << 8)
217 #define MII_VCT5_CTRL_SAMPLES_16 (0x3 << 8)
218 #define MII_VCT5_CTRL_SAMPLES_32 (0x4 << 8)
219 #define MII_VCT5_CTRL_SAMPLES_64 (0x5 << 8)
220 #define MII_VCT5_CTRL_SAMPLES_128 (0x6 << 8)
221 #define MII_VCT5_CTRL_SAMPLES_DEFAULT (0x6 << 8)
222 #define MII_VCT5_CTRL_SAMPLES_256 (0x7 << 8)
223 #define MII_VCT5_CTRL_SAMPLES_SHIFT 8
224 #define MII_VCT5_CTRL_MODE_MAXIMUM_PEEK (0x0 << 6)
225 #define MII_VCT5_CTRL_MODE_FIRST_LAST_PEEK (0x1 << 6)
226 #define MII_VCT5_CTRL_MODE_OFFSET (0x2 << 6)
227 #define MII_VCT5_CTRL_SAMPLE_POINT (0x3 << 6)
228 #define MII_VCT5_CTRL_PEEK_HYST_DEFAULT 3
230 #define MII_VCT5_SAMPLE_POINT_DISTANCE 0x18
231 #define MII_VCT5_SAMPLE_POINT_DISTANCE_MAX 511
232 #define MII_VCT5_TX_PULSE_CTRL 0x1c
233 #define MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN BIT(12)
234 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS (0x0 << 10)
235 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_96nS (0x1 << 10)
236 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_64nS (0x2 << 10)
237 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS (0x3 << 10)
238 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_SHIFT 10
239 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_1000mV (0x0 << 8)
240 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_750mV (0x1 << 8)
241 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_500mV (0x2 << 8)
242 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_250mV (0x3 << 8)
243 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_SHIFT 8
244 #define MII_VCT5_TX_PULSE_CTRL_MAX_AMP BIT(7)
245 #define MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV (0x6 << 0)
247 /* For TDR measurements less than 11 meters, a short pulse should be
250 #define TDR_SHORT_CABLE_LENGTH 11
252 #define MII_VCT7_PAIR_0_DISTANCE 0x10
253 #define MII_VCT7_PAIR_1_DISTANCE 0x11
254 #define MII_VCT7_PAIR_2_DISTANCE 0x12
255 #define MII_VCT7_PAIR_3_DISTANCE 0x13
257 #define MII_VCT7_RESULTS 0x14
258 #define MII_VCT7_RESULTS_PAIR3_MASK 0xf000
259 #define MII_VCT7_RESULTS_PAIR2_MASK 0x0f00
260 #define MII_VCT7_RESULTS_PAIR1_MASK 0x00f0
261 #define MII_VCT7_RESULTS_PAIR0_MASK 0x000f
262 #define MII_VCT7_RESULTS_PAIR3_SHIFT 12
263 #define MII_VCT7_RESULTS_PAIR2_SHIFT 8
264 #define MII_VCT7_RESULTS_PAIR1_SHIFT 4
265 #define MII_VCT7_RESULTS_PAIR0_SHIFT 0
266 #define MII_VCT7_RESULTS_INVALID 0
267 #define MII_VCT7_RESULTS_OK 1
268 #define MII_VCT7_RESULTS_OPEN 2
269 #define MII_VCT7_RESULTS_SAME_SHORT 3
270 #define MII_VCT7_RESULTS_CROSS_SHORT 4
271 #define MII_VCT7_RESULTS_BUSY 9
273 #define MII_VCT7_CTRL 0x15
274 #define MII_VCT7_CTRL_RUN_NOW BIT(15)
275 #define MII_VCT7_CTRL_RUN_ANEG BIT(14)
276 #define MII_VCT7_CTRL_DISABLE_CROSS BIT(13)
277 #define MII_VCT7_CTRL_RUN_AFTER_BREAK_LINK BIT(12)
278 #define MII_VCT7_CTRL_IN_PROGRESS BIT(11)
279 #define MII_VCT7_CTRL_METERS BIT(10)
280 #define MII_VCT7_CTRL_CENTIMETERS 0
282 #define MII_VCT_TXPINS 0x1A
283 #define MII_VCT_RXPINS 0x1B
284 #define MII_VCT_SR 0x1C
285 #define MII_VCT_TXPINS_ENVCT BIT(15)
286 #define MII_VCT_TXRXPINS_VCTTST GENMASK(14, 13)
287 #define MII_VCT_TXRXPINS_VCTTST_SHIFT 13
288 #define MII_VCT_TXRXPINS_VCTTST_OK 0
289 #define MII_VCT_TXRXPINS_VCTTST_SHORT 1
290 #define MII_VCT_TXRXPINS_VCTTST_OPEN 2
291 #define MII_VCT_TXRXPINS_VCTTST_FAIL 3
292 #define MII_VCT_TXRXPINS_AMPRFLN GENMASK(12, 8)
293 #define MII_VCT_TXRXPINS_AMPRFLN_SHIFT 8
294 #define MII_VCT_TXRXPINS_DISTRFLN GENMASK(7, 0)
295 #define MII_VCT_TXRXPINS_DISTRFLN_MAX 0xff
297 #define M88E3082_PAIR_A BIT(0)
298 #define M88E3082_PAIR_B BIT(1)
300 #define LPA_PAUSE_FIBER 0x180
301 #define LPA_PAUSE_ASYM_FIBER 0x100
303 #define NB_FIBER_STATS 1
304 #define NB_STAT_MAX 3
306 MODULE_DESCRIPTION("Marvell PHY driver");
307 MODULE_AUTHOR("Andy Fleming");
308 MODULE_LICENSE("GPL");
310 struct marvell_hw_stat {
317 static const struct marvell_hw_stat marvell_hw_stats[] = {
318 { "phy_receive_errors_copper", 0, 21, 16},
319 { "phy_idle_errors", 0, 10, 8 },
320 { "phy_receive_errors_fiber", 1, 21, 16},
323 static_assert(ARRAY_SIZE(marvell_hw_stats) <= NB_STAT_MAX);
325 /* "simple" stat list + corresponding marvell_get_*_simple functions are used
326 * on PHYs without a page register
328 struct marvell_hw_stat_simple {
334 static const struct marvell_hw_stat_simple marvell_hw_stats_simple[] = {
335 { "phy_receive_errors", 21, 16},
338 static_assert(ARRAY_SIZE(marvell_hw_stats_simple) <= NB_STAT_MAX);
346 struct marvell_priv {
347 u64 stats[NB_STAT_MAX];
349 struct device *hwmon_dev;
358 static int marvell_read_page(struct phy_device *phydev)
360 return __phy_read(phydev, MII_MARVELL_PHY_PAGE);
363 static int marvell_write_page(struct phy_device *phydev, int page)
365 return __phy_write(phydev, MII_MARVELL_PHY_PAGE, page);
368 static int marvell_set_page(struct phy_device *phydev, int page)
370 return phy_write(phydev, MII_MARVELL_PHY_PAGE, page);
373 static int marvell_ack_interrupt(struct phy_device *phydev)
377 /* Clear the interrupts by reading the reg */
378 err = phy_read(phydev, MII_M1011_IEVENT);
386 static int marvell_config_intr(struct phy_device *phydev)
390 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
391 err = marvell_ack_interrupt(phydev);
395 err = phy_write(phydev, MII_M1011_IMASK,
396 MII_M1011_IMASK_INIT);
398 err = phy_write(phydev, MII_M1011_IMASK,
399 MII_M1011_IMASK_CLEAR);
403 err = marvell_ack_interrupt(phydev);
409 static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev)
413 irq_status = phy_read(phydev, MII_M1011_IEVENT);
414 if (irq_status < 0) {
419 if (!(irq_status & MII_M1011_IMASK_INIT))
422 phy_trigger_machine(phydev);
427 static int marvell_set_polarity(struct phy_device *phydev, int polarity)
433 val = MII_M1011_PHY_SCR_MDI;
436 val = MII_M1011_PHY_SCR_MDI_X;
438 case ETH_TP_MDI_AUTO:
439 case ETH_TP_MDI_INVALID:
441 val = MII_M1011_PHY_SCR_AUTO_CROSS;
445 return phy_modify_changed(phydev, MII_M1011_PHY_SCR,
446 MII_M1011_PHY_SCR_AUTO_CROSS, val);
449 static int marvell_config_aneg(struct phy_device *phydev)
454 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
460 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
461 MII_M1111_PHY_LED_DIRECT);
465 err = genphy_config_aneg(phydev);
469 if (phydev->autoneg != AUTONEG_ENABLE || changed) {
470 /* A write to speed/duplex bits (that is performed by
471 * genphy_config_aneg() call above) must be followed by
472 * a software reset. Otherwise, the write has no effect.
474 err = genphy_soft_reset(phydev);
482 static int m88e1101_config_aneg(struct phy_device *phydev)
486 /* This Marvell PHY has an errata which requires
487 * that certain registers get written in order
488 * to restart autonegotiation
490 err = genphy_soft_reset(phydev);
494 err = phy_write(phydev, 0x1d, 0x1f);
498 err = phy_write(phydev, 0x1e, 0x200c);
502 err = phy_write(phydev, 0x1d, 0x5);
506 err = phy_write(phydev, 0x1e, 0);
510 err = phy_write(phydev, 0x1e, 0x100);
514 return marvell_config_aneg(phydev);
517 #if IS_ENABLED(CONFIG_OF_MDIO)
518 /* Set and/or override some configuration registers based on the
519 * marvell,reg-init property stored in the of_node for the phydev.
521 * marvell,reg-init = <reg-page reg mask value>,...;
523 * There may be one or more sets of <reg-page reg mask value>:
525 * reg-page: which register bank to use.
527 * mask: if non-zero, ANDed with existing register value.
528 * value: ORed with the masked value and written to the regiser.
531 static int marvell_of_reg_init(struct phy_device *phydev)
534 int len, i, saved_page, current_page, ret = 0;
536 if (!phydev->mdio.dev.of_node)
539 paddr = of_get_property(phydev->mdio.dev.of_node,
540 "marvell,reg-init", &len);
541 if (!paddr || len < (4 * sizeof(*paddr)))
544 saved_page = phy_save_page(phydev);
547 current_page = saved_page;
549 len /= sizeof(*paddr);
550 for (i = 0; i < len - 3; i += 4) {
551 u16 page = be32_to_cpup(paddr + i);
552 u16 reg = be32_to_cpup(paddr + i + 1);
553 u16 mask = be32_to_cpup(paddr + i + 2);
554 u16 val_bits = be32_to_cpup(paddr + i + 3);
557 if (page != current_page) {
559 ret = marvell_write_page(phydev, page);
566 val = __phy_read(phydev, reg);
575 ret = __phy_write(phydev, reg, val);
580 return phy_restore_page(phydev, saved_page, ret);
583 static int marvell_of_reg_init(struct phy_device *phydev)
587 #endif /* CONFIG_OF_MDIO */
589 static int m88e1121_config_aneg_rgmii_delays(struct phy_device *phydev)
593 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
594 mscr = MII_88E1121_PHY_MSCR_RX_DELAY |
595 MII_88E1121_PHY_MSCR_TX_DELAY;
596 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
597 mscr = MII_88E1121_PHY_MSCR_RX_DELAY;
598 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
599 mscr = MII_88E1121_PHY_MSCR_TX_DELAY;
603 return phy_modify_paged_changed(phydev, MII_MARVELL_MSCR_PAGE,
604 MII_88E1121_PHY_MSCR_REG,
605 MII_88E1121_PHY_MSCR_DELAY_MASK, mscr);
608 static int m88e1121_config_aneg(struct phy_device *phydev)
613 if (phy_interface_is_rgmii(phydev)) {
614 err = m88e1121_config_aneg_rgmii_delays(phydev);
621 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
627 err = genphy_config_aneg(phydev);
631 if (phydev->autoneg != AUTONEG_ENABLE || changed) {
632 /* A software reset is used to ensure a "commit" of the
635 err = genphy_soft_reset(phydev);
643 static int m88e1318_config_aneg(struct phy_device *phydev)
647 err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE,
648 MII_88E1318S_PHY_MSCR1_REG,
649 0, MII_88E1318S_PHY_MSCR1_PAD_ODD);
653 return m88e1121_config_aneg(phydev);
657 * linkmode_adv_to_fiber_adv_t
658 * @advertise: the linkmode advertisement settings
660 * A small helper function that translates linkmode advertisement
661 * settings to phy autonegotiation advertisements for the MII_ADV
662 * register for fiber link.
664 static inline u32 linkmode_adv_to_fiber_adv_t(unsigned long *advertise)
668 if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, advertise))
669 result |= ADVERTISE_1000XHALF;
670 if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, advertise))
671 result |= ADVERTISE_1000XFULL;
673 if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertise) &&
674 linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertise))
675 result |= ADVERTISE_1000XPSE_ASYM;
676 else if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertise))
677 result |= ADVERTISE_1000XPAUSE;
683 * marvell_config_aneg_fiber - restart auto-negotiation or write BMCR
684 * @phydev: target phy_device struct
686 * Description: If auto-negotiation is enabled, we configure the
687 * advertising, and then restart auto-negotiation. If it is not
688 * enabled, then we write the BMCR. Adapted for fiber link in
689 * some Marvell's devices.
691 static int marvell_config_aneg_fiber(struct phy_device *phydev)
697 if (phydev->autoneg != AUTONEG_ENABLE)
698 return genphy_setup_forced(phydev);
700 /* Only allow advertising what this PHY supports */
701 linkmode_and(phydev->advertising, phydev->advertising,
704 adv = linkmode_adv_to_fiber_adv_t(phydev->advertising);
706 /* Setup fiber advertisement */
707 err = phy_modify_changed(phydev, MII_ADVERTISE,
708 ADVERTISE_1000XHALF | ADVERTISE_1000XFULL |
709 ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM,
716 return genphy_check_and_restart_aneg(phydev, changed);
719 static int m88e1111_config_aneg(struct phy_device *phydev)
721 int extsr = phy_read(phydev, MII_M1111_PHY_EXT_SR);
727 /* If not using SGMII or copper 1000BaseX modes, use normal process.
728 * Steps below are only required for these modes.
730 if (phydev->interface != PHY_INTERFACE_MODE_SGMII &&
731 (extsr & MII_M1111_HWCFG_MODE_MASK) !=
732 MII_M1111_HWCFG_MODE_COPPER_1000X_AN)
733 return marvell_config_aneg(phydev);
735 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
739 /* Configure the copper link first */
740 err = marvell_config_aneg(phydev);
744 /* Then the fiber link */
745 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
749 if (phydev->interface == PHY_INTERFACE_MODE_SGMII)
750 /* Do not touch the fiber advertisement if we're in copper->sgmii mode.
751 * Just ensure that SGMII-side autonegotiation is enabled.
752 * If we switched from some other mode to SGMII it may not be.
754 err = genphy_check_and_restart_aneg(phydev, false);
756 err = marvell_config_aneg_fiber(phydev);
760 return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
763 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
767 static int m88e1510_config_aneg(struct phy_device *phydev)
771 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
775 /* Configure the copper link first */
776 err = m88e1318_config_aneg(phydev);
780 /* Do not touch the fiber page if we're in copper->sgmii mode */
781 if (phydev->interface == PHY_INTERFACE_MODE_SGMII)
784 /* Then the fiber link */
785 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
789 err = marvell_config_aneg_fiber(phydev);
793 return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
796 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
800 static void marvell_config_led(struct phy_device *phydev)
805 switch (MARVELL_PHY_FAMILY_ID(phydev->phy_id)) {
806 /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
807 case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1121R):
808 case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1318S):
809 def_config = MII_88E1121_PHY_LED_DEF;
811 /* Default PHY LED config:
812 * LED[0] .. 1000Mbps Link
813 * LED[1] .. 100Mbps Link
814 * LED[2] .. Blink, Activity
816 case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1510):
817 if (phydev->dev_flags & MARVELL_PHY_LED0_LINK_LED1_ACTIVE)
818 def_config = MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE;
820 def_config = MII_88E1510_PHY_LED_DEF;
826 err = phy_write_paged(phydev, MII_MARVELL_LED_PAGE, MII_PHY_LED_CTRL,
829 phydev_warn(phydev, "Fail to config marvell phy LED.\n");
832 static int marvell_config_init(struct phy_device *phydev)
834 /* Set default LED */
835 marvell_config_led(phydev);
837 /* Set registers from marvell,reg-init DT property */
838 return marvell_of_reg_init(phydev);
841 static int m88e3016_config_init(struct phy_device *phydev)
845 /* Enable Scrambler and Auto-Crossover */
846 ret = phy_modify(phydev, MII_88E3016_PHY_SPEC_CTRL,
847 MII_88E3016_DISABLE_SCRAMBLER,
848 MII_88E3016_AUTO_MDIX_CROSSOVER);
852 return marvell_config_init(phydev);
855 static int m88e1111_config_init_hwcfg_mode(struct phy_device *phydev,
857 int fibre_copper_auto)
859 if (fibre_copper_auto)
860 mode |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
862 return phy_modify(phydev, MII_M1111_PHY_EXT_SR,
863 MII_M1111_HWCFG_MODE_MASK |
864 MII_M1111_HWCFG_FIBER_COPPER_AUTO |
865 MII_M1111_HWCFG_FIBER_COPPER_RES,
869 static int m88e1111_config_init_rgmii_delays(struct phy_device *phydev)
873 switch (phydev->interface) {
874 case PHY_INTERFACE_MODE_RGMII_ID:
875 delay = MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY;
877 case PHY_INTERFACE_MODE_RGMII_RXID:
878 delay = MII_M1111_RGMII_RX_DELAY;
880 case PHY_INTERFACE_MODE_RGMII_TXID:
881 delay = MII_M1111_RGMII_TX_DELAY;
888 return phy_modify(phydev, MII_M1111_PHY_EXT_CR,
889 MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY,
893 static int m88e1111_config_init_rgmii(struct phy_device *phydev)
898 err = m88e1111_config_init_rgmii_delays(phydev);
902 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
906 temp &= ~(MII_M1111_HWCFG_MODE_MASK);
908 if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES)
909 temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII;
911 temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII;
913 return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp);
916 static int m88e1111_config_init_sgmii(struct phy_device *phydev)
920 err = m88e1111_config_init_hwcfg_mode(
922 MII_M1111_HWCFG_MODE_SGMII_NO_CLK,
923 MII_M1111_HWCFG_FIBER_COPPER_AUTO);
927 /* make sure copper is selected */
928 return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
931 static int m88e1111_config_init_rtbi(struct phy_device *phydev)
935 err = m88e1111_config_init_rgmii_delays(phydev);
939 err = m88e1111_config_init_hwcfg_mode(
941 MII_M1111_HWCFG_MODE_RTBI,
942 MII_M1111_HWCFG_FIBER_COPPER_AUTO);
947 err = genphy_soft_reset(phydev);
951 return m88e1111_config_init_hwcfg_mode(
953 MII_M1111_HWCFG_MODE_RTBI,
954 MII_M1111_HWCFG_FIBER_COPPER_AUTO);
957 static int m88e1111_config_init_1000basex(struct phy_device *phydev)
959 int extsr = phy_read(phydev, MII_M1111_PHY_EXT_SR);
965 /* If using copper mode, ensure 1000BaseX auto-negotiation is enabled.
966 * FIXME: this does not actually enable 1000BaseX auto-negotiation if
967 * it was previously disabled in the Fiber BMCR!
969 mode = extsr & MII_M1111_HWCFG_MODE_MASK;
970 if (mode == MII_M1111_HWCFG_MODE_COPPER_1000X_NOAN) {
971 err = phy_modify(phydev, MII_M1111_PHY_EXT_SR,
972 MII_M1111_HWCFG_MODE_MASK |
973 MII_M1111_HWCFG_SERIAL_AN_BYPASS,
974 MII_M1111_HWCFG_MODE_COPPER_1000X_AN |
975 MII_M1111_HWCFG_SERIAL_AN_BYPASS);
982 static int m88e1111_config_init(struct phy_device *phydev)
986 if (phy_interface_is_rgmii(phydev)) {
987 err = m88e1111_config_init_rgmii(phydev);
992 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
993 err = m88e1111_config_init_sgmii(phydev);
998 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
999 err = m88e1111_config_init_rtbi(phydev);
1004 if (phydev->interface == PHY_INTERFACE_MODE_1000BASEX) {
1005 err = m88e1111_config_init_1000basex(phydev);
1010 err = marvell_of_reg_init(phydev);
1014 err = genphy_soft_reset(phydev);
1018 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
1019 /* If the HWCFG_MODE was changed from another mode (such as
1020 * 1000BaseX) to SGMII, the state of the support bits may have
1021 * also changed now that the PHY has been reset.
1022 * Update the PHY abilities accordingly.
1024 err = genphy_read_abilities(phydev);
1025 linkmode_or(phydev->advertising, phydev->advertising,
1031 static int m88e1111_get_downshift(struct phy_device *phydev, u8 *data)
1033 int val, cnt, enable;
1035 val = phy_read(phydev, MII_M1111_PHY_EXT_CR);
1039 enable = FIELD_GET(MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN, val);
1040 cnt = FIELD_GET(MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK, val) + 1;
1042 *data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
1047 static int m88e1111_set_downshift(struct phy_device *phydev, u8 cnt)
1051 if (cnt > MII_M1111_PHY_EXT_CR_DOWNSHIFT_MAX)
1055 err = phy_clear_bits(phydev, MII_M1111_PHY_EXT_CR,
1056 MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN);
1058 val = MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN;
1059 val |= FIELD_PREP(MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK, cnt - 1);
1061 err = phy_modify(phydev, MII_M1111_PHY_EXT_CR,
1062 MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN |
1063 MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK,
1070 return genphy_soft_reset(phydev);
1073 static int m88e1111_get_tunable(struct phy_device *phydev,
1074 struct ethtool_tunable *tuna, void *data)
1077 case ETHTOOL_PHY_DOWNSHIFT:
1078 return m88e1111_get_downshift(phydev, data);
1084 static int m88e1111_set_tunable(struct phy_device *phydev,
1085 struct ethtool_tunable *tuna, const void *data)
1088 case ETHTOOL_PHY_DOWNSHIFT:
1089 return m88e1111_set_downshift(phydev, *(const u8 *)data);
1095 static int m88e1011_get_downshift(struct phy_device *phydev, u8 *data)
1097 int val, cnt, enable;
1099 val = phy_read(phydev, MII_M1011_PHY_SCR);
1103 enable = FIELD_GET(MII_M1011_PHY_SCR_DOWNSHIFT_EN, val);
1104 cnt = FIELD_GET(MII_M1011_PHY_SCR_DOWNSHIFT_MASK, val) + 1;
1106 *data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
1111 static int m88e1011_set_downshift(struct phy_device *phydev, u8 cnt)
1115 if (cnt > MII_M1011_PHY_SCR_DOWNSHIFT_MAX)
1119 err = phy_clear_bits(phydev, MII_M1011_PHY_SCR,
1120 MII_M1011_PHY_SCR_DOWNSHIFT_EN);
1122 val = MII_M1011_PHY_SCR_DOWNSHIFT_EN;
1123 val |= FIELD_PREP(MII_M1011_PHY_SCR_DOWNSHIFT_MASK, cnt - 1);
1125 err = phy_modify(phydev, MII_M1011_PHY_SCR,
1126 MII_M1011_PHY_SCR_DOWNSHIFT_EN |
1127 MII_M1011_PHY_SCR_DOWNSHIFT_MASK,
1134 return genphy_soft_reset(phydev);
1137 static int m88e1011_get_tunable(struct phy_device *phydev,
1138 struct ethtool_tunable *tuna, void *data)
1141 case ETHTOOL_PHY_DOWNSHIFT:
1142 return m88e1011_get_downshift(phydev, data);
1148 static int m88e1011_set_tunable(struct phy_device *phydev,
1149 struct ethtool_tunable *tuna, const void *data)
1152 case ETHTOOL_PHY_DOWNSHIFT:
1153 return m88e1011_set_downshift(phydev, *(const u8 *)data);
1159 static int m88e1112_config_init(struct phy_device *phydev)
1163 err = m88e1011_set_downshift(phydev, 3);
1167 return m88e1111_config_init(phydev);
1170 static int m88e1111gbe_config_init(struct phy_device *phydev)
1174 err = m88e1111_set_downshift(phydev, 3);
1178 return m88e1111_config_init(phydev);
1181 static int marvell_1011gbe_config_init(struct phy_device *phydev)
1185 err = m88e1011_set_downshift(phydev, 3);
1189 return marvell_config_init(phydev);
1191 static int m88e1116r_config_init(struct phy_device *phydev)
1195 err = genphy_soft_reset(phydev);
1201 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1205 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
1209 err = m88e1011_set_downshift(phydev, 8);
1213 if (phy_interface_is_rgmii(phydev)) {
1214 err = m88e1121_config_aneg_rgmii_delays(phydev);
1219 err = genphy_soft_reset(phydev);
1223 return marvell_config_init(phydev);
1226 static int m88e1318_config_init(struct phy_device *phydev)
1228 if (phy_interrupt_is_valid(phydev)) {
1229 int err = phy_modify_paged(
1230 phydev, MII_MARVELL_LED_PAGE,
1231 MII_88E1318S_PHY_LED_TCR,
1232 MII_88E1318S_PHY_LED_TCR_FORCE_INT,
1233 MII_88E1318S_PHY_LED_TCR_INTn_ENABLE |
1234 MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW);
1239 return marvell_config_init(phydev);
1242 static int m88e1510_config_init(struct phy_device *phydev)
1244 static const struct {
1255 /* As per Marvell Release Notes - Alaska 88E1510/88E1518/88E1512/
1256 * 88E1514 Rev A0, Errata Section 5.1:
1257 * If EEE is intended to be used, the following register writes
1258 * must be done once after every hardware reset.
1260 err = marvell_set_page(phydev, 0x00FF);
1264 for (i = 0; i < ARRAY_SIZE(errata_vals); ++i) {
1265 err = phy_write(phydev, 17, errata_vals[i].reg17);
1268 err = phy_write(phydev, 16, errata_vals[i].reg16);
1273 err = marvell_set_page(phydev, 0x00FB);
1276 err = phy_write(phydev, 07, 0xC00D);
1279 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1283 /* SGMII-to-Copper mode initialization */
1284 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
1285 /* Select page 18 */
1286 err = marvell_set_page(phydev, 18);
1290 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
1291 err = phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1,
1292 MII_88E1510_GEN_CTRL_REG_1_MODE_MASK,
1293 MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII);
1297 /* PHY reset is necessary after changing MODE[2:0] */
1298 err = phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1,
1299 MII_88E1510_GEN_CTRL_REG_1_RESET);
1303 /* Reset page selection */
1304 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1308 err = m88e1011_set_downshift(phydev, 3);
1312 return m88e1318_config_init(phydev);
1315 static int m88e1118_config_aneg(struct phy_device *phydev)
1319 err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
1323 err = genphy_config_aneg(phydev);
1327 return genphy_soft_reset(phydev);
1330 static int m88e1118_config_init(struct phy_device *phydev)
1335 /* Enable 1000 Mbit */
1336 err = phy_write_paged(phydev, MII_MARVELL_MSCR_PAGE,
1337 MII_88E1121_PHY_MSCR_REG, 0x1070);
1341 if (phy_interface_is_rgmii(phydev)) {
1342 err = m88e1121_config_aneg_rgmii_delays(phydev);
1347 /* Adjust LED Control */
1348 if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS)
1353 err = phy_write_paged(phydev, MII_MARVELL_LED_PAGE, 0x10, leds);
1357 err = marvell_of_reg_init(phydev);
1361 /* Reset page register */
1362 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1366 return genphy_soft_reset(phydev);
1369 static int m88e1149_config_init(struct phy_device *phydev)
1373 /* Change address */
1374 err = marvell_set_page(phydev, MII_MARVELL_MSCR_PAGE);
1378 /* Enable 1000 Mbit */
1379 err = phy_write(phydev, 0x15, 0x1048);
1383 err = marvell_of_reg_init(phydev);
1388 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1392 return genphy_soft_reset(phydev);
1395 static int m88e1145_config_init_rgmii(struct phy_device *phydev)
1399 err = m88e1111_config_init_rgmii_delays(phydev);
1403 if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) {
1404 err = phy_write(phydev, 0x1d, 0x0012);
1408 err = phy_modify(phydev, 0x1e, 0x0fc0,
1409 2 << 9 | /* 36 ohm */
1410 2 << 6); /* 39 ohm */
1414 err = phy_write(phydev, 0x1d, 0x3);
1418 err = phy_write(phydev, 0x1e, 0x8000);
1423 static int m88e1145_config_init_sgmii(struct phy_device *phydev)
1425 return m88e1111_config_init_hwcfg_mode(
1426 phydev, MII_M1111_HWCFG_MODE_SGMII_NO_CLK,
1427 MII_M1111_HWCFG_FIBER_COPPER_AUTO);
1430 static int m88e1145_config_init(struct phy_device *phydev)
1434 /* Take care of errata E0 & E1 */
1435 err = phy_write(phydev, 0x1d, 0x001b);
1439 err = phy_write(phydev, 0x1e, 0x418f);
1443 err = phy_write(phydev, 0x1d, 0x0016);
1447 err = phy_write(phydev, 0x1e, 0xa2da);
1451 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
1452 err = m88e1145_config_init_rgmii(phydev);
1457 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
1458 err = m88e1145_config_init_sgmii(phydev);
1462 err = m88e1111_set_downshift(phydev, 3);
1466 err = marvell_of_reg_init(phydev);
1473 static int m88e1540_get_fld(struct phy_device *phydev, u8 *msecs)
1477 val = phy_read(phydev, MII_88E1540_COPPER_CTRL3);
1481 if (!(val & MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN)) {
1482 *msecs = ETHTOOL_PHY_FAST_LINK_DOWN_OFF;
1486 val = FIELD_GET(MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val);
1489 case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS:
1492 case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS:
1495 case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS:
1498 case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS:
1508 static int m88e1540_set_fld(struct phy_device *phydev, const u8 *msecs)
1510 struct ethtool_keee eee;
1513 if (*msecs == ETHTOOL_PHY_FAST_LINK_DOWN_OFF)
1514 return phy_clear_bits(phydev, MII_88E1540_COPPER_CTRL3,
1515 MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN);
1517 /* According to the Marvell data sheet EEE must be disabled for
1518 * Fast Link Down detection to work properly
1520 ret = genphy_c45_ethtool_get_eee(phydev, &eee);
1521 if (!ret && eee.eee_enabled) {
1522 phydev_warn(phydev, "Fast Link Down detection requires EEE to be disabled!\n");
1527 val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS;
1528 else if (*msecs <= 15)
1529 val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS;
1530 else if (*msecs <= 30)
1531 val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS;
1533 val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS;
1535 val = FIELD_PREP(MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val);
1537 ret = phy_modify(phydev, MII_88E1540_COPPER_CTRL3,
1538 MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val);
1542 return phy_set_bits(phydev, MII_88E1540_COPPER_CTRL3,
1543 MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN);
1546 static int m88e1540_get_tunable(struct phy_device *phydev,
1547 struct ethtool_tunable *tuna, void *data)
1550 case ETHTOOL_PHY_FAST_LINK_DOWN:
1551 return m88e1540_get_fld(phydev, data);
1552 case ETHTOOL_PHY_DOWNSHIFT:
1553 return m88e1011_get_downshift(phydev, data);
1559 static int m88e1540_set_tunable(struct phy_device *phydev,
1560 struct ethtool_tunable *tuna, const void *data)
1563 case ETHTOOL_PHY_FAST_LINK_DOWN:
1564 return m88e1540_set_fld(phydev, data);
1565 case ETHTOOL_PHY_DOWNSHIFT:
1566 return m88e1011_set_downshift(phydev, *(const u8 *)data);
1572 /* The VOD can be out of specification on link up. Poke an
1573 * undocumented register, in an undocumented page, with a magic value
1576 static int m88e6390_errata(struct phy_device *phydev)
1580 err = phy_write(phydev, MII_BMCR,
1581 BMCR_ANENABLE | BMCR_SPEED1000 | BMCR_FULLDPLX);
1585 usleep_range(300, 400);
1587 err = phy_write_paged(phydev, 0xf8, 0x08, 0x36);
1591 return genphy_soft_reset(phydev);
1594 static int m88e6390_config_aneg(struct phy_device *phydev)
1598 err = m88e6390_errata(phydev);
1602 return m88e1510_config_aneg(phydev);
1606 * fiber_lpa_mod_linkmode_lpa_t
1607 * @advertising: the linkmode advertisement settings
1608 * @lpa: value of the MII_LPA register for fiber link
1610 * A small helper function that translates MII_LPA bits to linkmode LP
1611 * advertisement settings. Other bits in advertising are left
1614 static void fiber_lpa_mod_linkmode_lpa_t(unsigned long *advertising, u32 lpa)
1616 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
1617 advertising, lpa & LPA_1000XHALF);
1619 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
1620 advertising, lpa & LPA_1000XFULL);
1623 static int marvell_read_status_page_an(struct phy_device *phydev,
1624 int fiber, int status)
1629 if (!(status & MII_M1011_PHY_STATUS_RESOLVED)) {
1634 if (status & MII_M1011_PHY_STATUS_FULLDUPLEX)
1635 phydev->duplex = DUPLEX_FULL;
1637 phydev->duplex = DUPLEX_HALF;
1639 switch (status & MII_M1011_PHY_STATUS_SPD_MASK) {
1640 case MII_M1011_PHY_STATUS_1000:
1641 phydev->speed = SPEED_1000;
1644 case MII_M1011_PHY_STATUS_100:
1645 phydev->speed = SPEED_100;
1649 phydev->speed = SPEED_10;
1654 err = genphy_read_lpa(phydev);
1658 phy_resolve_aneg_pause(phydev);
1660 lpa = phy_read(phydev, MII_LPA);
1664 /* The fiber link is only 1000M capable */
1665 fiber_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa);
1667 if (phydev->duplex == DUPLEX_FULL) {
1668 if (!(lpa & LPA_PAUSE_FIBER)) {
1670 phydev->asym_pause = 0;
1671 } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) {
1673 phydev->asym_pause = 1;
1676 phydev->asym_pause = 0;
1684 /* marvell_read_status_page
1687 * Check the link, then figure out the current state
1688 * by comparing what we advertise with what the link partner
1689 * advertises. Start by checking the gigabit possibilities,
1690 * then move on to 10/100.
1692 static int marvell_read_status_page(struct phy_device *phydev, int page)
1698 status = phy_read(phydev, MII_M1011_PHY_STATUS);
1702 /* Use the generic register for copper link status,
1703 * and the PHY status register for fiber link status.
1705 if (page == MII_MARVELL_FIBER_PAGE) {
1706 phydev->link = !!(status & MII_M1011_PHY_STATUS_LINK);
1708 err = genphy_update_link(phydev);
1713 if (page == MII_MARVELL_FIBER_PAGE)
1718 linkmode_zero(phydev->lp_advertising);
1720 phydev->asym_pause = 0;
1721 phydev->speed = SPEED_UNKNOWN;
1722 phydev->duplex = DUPLEX_UNKNOWN;
1723 phydev->port = fiber ? PORT_FIBRE : PORT_TP;
1725 if (phydev->autoneg == AUTONEG_ENABLE)
1726 err = marvell_read_status_page_an(phydev, fiber, status);
1728 err = genphy_read_status_fixed(phydev);
1733 /* marvell_read_status
1735 * Some Marvell's phys have two modes: fiber and copper.
1736 * Both need status checked.
1738 * First, check the fiber link and status.
1739 * If the fiber link is down, check the copper link and status which
1740 * will be the default value if both link are down.
1742 static int marvell_read_status(struct phy_device *phydev)
1746 /* Check the fiber mode first */
1747 if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT,
1748 phydev->supported) &&
1749 phydev->interface != PHY_INTERFACE_MODE_SGMII) {
1750 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
1754 err = marvell_read_status_page(phydev, MII_MARVELL_FIBER_PAGE);
1758 /* If the fiber link is up, it is the selected and
1759 * used link. In this case, we need to stay in the
1760 * fiber page. Please to be careful about that, avoid
1761 * to restore Copper page in other functions which
1762 * could break the behaviour for some fiber phy like
1768 /* If fiber link is down, check and save copper mode state */
1769 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1774 return marvell_read_status_page(phydev, MII_MARVELL_COPPER_PAGE);
1777 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1783 * Some Marvell's phys have two modes: fiber and copper.
1784 * Both need to be suspended
1786 static int marvell_suspend(struct phy_device *phydev)
1790 /* Suspend the fiber mode first */
1791 if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT,
1792 phydev->supported)) {
1793 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
1797 /* With the page set, use the generic suspend */
1798 err = genphy_suspend(phydev);
1802 /* Then, the copper link */
1803 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1808 /* With the page set, use the generic suspend */
1809 return genphy_suspend(phydev);
1812 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1818 * Some Marvell's phys have two modes: fiber and copper.
1819 * Both need to be resumed
1821 static int marvell_resume(struct phy_device *phydev)
1825 /* Resume the fiber mode first */
1826 if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT,
1827 phydev->supported)) {
1828 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE);
1832 /* With the page set, use the generic resume */
1833 err = genphy_resume(phydev);
1837 /* Then, the copper link */
1838 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1843 /* With the page set, use the generic resume */
1844 return genphy_resume(phydev);
1847 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
1851 static int marvell_aneg_done(struct phy_device *phydev)
1853 int retval = phy_read(phydev, MII_M1011_PHY_STATUS);
1855 return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED);
1858 static void m88e1318_get_wol(struct phy_device *phydev,
1859 struct ethtool_wolinfo *wol)
1863 wol->supported = WAKE_MAGIC | WAKE_PHY;
1866 ret = phy_read_paged(phydev, MII_MARVELL_WOL_PAGE,
1867 MII_88E1318S_PHY_WOL_CTRL);
1871 if (ret & MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
1872 wol->wolopts |= WAKE_MAGIC;
1874 if (ret & MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE)
1875 wol->wolopts |= WAKE_PHY;
1878 static int m88e1318_set_wol(struct phy_device *phydev,
1879 struct ethtool_wolinfo *wol)
1881 int err = 0, oldpage;
1883 oldpage = phy_save_page(phydev);
1887 if (wol->wolopts & (WAKE_MAGIC | WAKE_PHY)) {
1888 /* Explicitly switch to page 0x00, just to be sure */
1889 err = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE);
1893 /* If WOL event happened once, the LED[2] interrupt pin
1894 * will not be cleared unless we reading the interrupt status
1895 * register. If interrupts are in use, the normal interrupt
1896 * handling will clear the WOL event. Clear the WOL event
1897 * before enabling it if !phy_interrupt_is_valid()
1899 if (!phy_interrupt_is_valid(phydev))
1900 __phy_read(phydev, MII_M1011_IEVENT);
1902 /* Enable the WOL interrupt */
1903 err = __phy_set_bits(phydev, MII_88E1318S_PHY_CSIER,
1904 MII_88E1318S_PHY_CSIER_WOL_EIE);
1908 err = marvell_write_page(phydev, MII_MARVELL_LED_PAGE);
1912 /* Setup LED[2] as interrupt pin (active low) */
1913 err = __phy_modify(phydev, MII_88E1318S_PHY_LED_TCR,
1914 MII_88E1318S_PHY_LED_TCR_FORCE_INT,
1915 MII_88E1318S_PHY_LED_TCR_INTn_ENABLE |
1916 MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW);
1921 if (wol->wolopts & WAKE_MAGIC) {
1922 err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE);
1926 /* Store the device address for the magic packet */
1927 err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2,
1928 ((phydev->attached_dev->dev_addr[5] << 8) |
1929 phydev->attached_dev->dev_addr[4]));
1932 err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1,
1933 ((phydev->attached_dev->dev_addr[3] << 8) |
1934 phydev->attached_dev->dev_addr[2]));
1937 err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0,
1938 ((phydev->attached_dev->dev_addr[1] << 8) |
1939 phydev->attached_dev->dev_addr[0]));
1943 /* Clear WOL status and enable magic packet matching */
1944 err = __phy_set_bits(phydev, MII_88E1318S_PHY_WOL_CTRL,
1945 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS |
1946 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE);
1950 err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE);
1954 /* Clear WOL status and disable magic packet matching */
1955 err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL,
1956 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE,
1957 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS);
1962 if (wol->wolopts & WAKE_PHY) {
1963 err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE);
1967 /* Clear WOL status and enable link up event */
1968 err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL, 0,
1969 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS |
1970 MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE);
1974 err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE);
1978 /* Clear WOL status and disable link up event */
1979 err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL,
1980 MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE,
1981 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS);
1987 return phy_restore_page(phydev, oldpage, err);
1990 static int marvell_get_sset_count(struct phy_device *phydev)
1992 if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT,
1994 return ARRAY_SIZE(marvell_hw_stats);
1996 return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS;
1999 static int marvell_get_sset_count_simple(struct phy_device *phydev)
2001 return ARRAY_SIZE(marvell_hw_stats_simple);
2004 static void marvell_get_strings(struct phy_device *phydev, u8 *data)
2006 int count = marvell_get_sset_count(phydev);
2009 for (i = 0; i < count; i++) {
2010 strscpy(data + i * ETH_GSTRING_LEN,
2011 marvell_hw_stats[i].string, ETH_GSTRING_LEN);
2015 static void marvell_get_strings_simple(struct phy_device *phydev, u8 *data)
2017 int count = marvell_get_sset_count_simple(phydev);
2020 for (i = 0; i < count; i++) {
2021 strscpy(data + i * ETH_GSTRING_LEN,
2022 marvell_hw_stats_simple[i].string, ETH_GSTRING_LEN);
2026 static u64 marvell_get_stat(struct phy_device *phydev, int i)
2028 struct marvell_hw_stat stat = marvell_hw_stats[i];
2029 struct marvell_priv *priv = phydev->priv;
2033 val = phy_read_paged(phydev, stat.page, stat.reg);
2037 val = val & ((1 << stat.bits) - 1);
2038 priv->stats[i] += val;
2039 ret = priv->stats[i];
2045 static u64 marvell_get_stat_simple(struct phy_device *phydev, int i)
2047 struct marvell_hw_stat_simple stat = marvell_hw_stats_simple[i];
2048 struct marvell_priv *priv = phydev->priv;
2052 val = phy_read(phydev, stat.reg);
2056 val = val & ((1 << stat.bits) - 1);
2057 priv->stats[i] += val;
2058 ret = priv->stats[i];
2064 static void marvell_get_stats(struct phy_device *phydev,
2065 struct ethtool_stats *stats, u64 *data)
2067 int count = marvell_get_sset_count(phydev);
2070 for (i = 0; i < count; i++)
2071 data[i] = marvell_get_stat(phydev, i);
2074 static void marvell_get_stats_simple(struct phy_device *phydev,
2075 struct ethtool_stats *stats, u64 *data)
2077 int count = marvell_get_sset_count_simple(phydev);
2080 for (i = 0; i < count; i++)
2081 data[i] = marvell_get_stat_simple(phydev, i);
2084 static int m88e1510_loopback(struct phy_device *phydev, bool enable)
2089 u16 bmcr_ctl, mscr2_ctl = 0;
2091 bmcr_ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
2093 err = phy_write(phydev, MII_BMCR, bmcr_ctl);
2097 if (phydev->speed == SPEED_1000)
2098 mscr2_ctl = BMCR_SPEED1000;
2099 else if (phydev->speed == SPEED_100)
2100 mscr2_ctl = BMCR_SPEED100;
2102 err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE,
2103 MII_88E1510_MSCR_2, BMCR_SPEED1000 |
2104 BMCR_SPEED100, mscr2_ctl);
2108 /* Need soft reset to have speed configuration takes effect */
2109 err = genphy_soft_reset(phydev);
2113 err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
2117 /* It takes some time for PHY device to switch
2118 * into/out-of loopback mode.
2124 err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0);
2128 return phy_config_aneg(phydev);
2132 static int marvell_vct5_wait_complete(struct phy_device *phydev)
2137 for (i = 0; i < 32; i++) {
2138 val = __phy_read(phydev, MII_VCT5_CTRL);
2142 if (val & MII_VCT5_CTRL_COMPLETE)
2146 phydev_err(phydev, "Timeout while waiting for cable test to finish\n");
2150 static int marvell_vct5_amplitude(struct phy_device *phydev, int pair)
2156 reg = MII_VCT5_TX_RX_MDI0_COUPLING + pair;
2157 val = __phy_read(phydev, reg);
2162 amplitude = (val & MII_VCT5_TX_RX_AMPLITUDE_MASK) >>
2163 MII_VCT5_TX_RX_AMPLITUDE_SHIFT;
2165 if (!(val & MII_VCT5_TX_RX_COUPLING_POSITIVE_REFLECTION))
2166 amplitude = -amplitude;
2168 return 1000 * amplitude / 128;
2171 static u32 marvell_vct5_distance2cm(int distance)
2173 return distance * 805 / 10;
2176 static u32 marvell_vct5_cm2distance(int cm)
2178 return cm * 10 / 805;
2181 static int marvell_vct5_amplitude_distance(struct phy_device *phydev,
2182 int distance, int pair)
2189 err = __phy_write(phydev, MII_VCT5_SAMPLE_POINT_DISTANCE,
2194 reg = MII_VCT5_CTRL_ENABLE |
2195 MII_VCT5_CTRL_TX_SAME_CHANNEL |
2196 MII_VCT5_CTRL_SAMPLES_DEFAULT |
2197 MII_VCT5_CTRL_SAMPLE_POINT |
2198 MII_VCT5_CTRL_PEEK_HYST_DEFAULT;
2199 err = __phy_write(phydev, MII_VCT5_CTRL, reg);
2203 err = marvell_vct5_wait_complete(phydev);
2207 for (i = 0; i < 4; i++) {
2208 if (pair != PHY_PAIR_ALL && i != pair)
2211 mV = marvell_vct5_amplitude(phydev, i);
2212 ethnl_cable_test_amplitude(phydev, i, mV);
2218 static int marvell_vct5_amplitude_graph(struct phy_device *phydev)
2220 struct marvell_priv *priv = phydev->priv;
2227 if (priv->first <= TDR_SHORT_CABLE_LENGTH)
2228 width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS;
2230 width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS;
2232 reg = MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV |
2233 MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN |
2234 MII_VCT5_TX_PULSE_CTRL_MAX_AMP | width;
2236 err = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE,
2237 MII_VCT5_TX_PULSE_CTRL, reg);
2241 /* Reading the TDR data is very MDIO heavy. We need to optimize
2242 * access to keep the time to a minimum. So lock the bus once,
2243 * and don't release it until complete. We can then avoid having
2244 * to change the page for every access, greatly speeding things
2247 page = phy_select_page(phydev, MII_MARVELL_VCT5_PAGE);
2251 for (distance = priv->first;
2252 distance <= priv->last;
2253 distance += priv->step) {
2254 err = marvell_vct5_amplitude_distance(phydev, distance,
2259 if (distance > TDR_SHORT_CABLE_LENGTH &&
2260 width == MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS) {
2261 width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS;
2262 reg = MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV |
2263 MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN |
2264 MII_VCT5_TX_PULSE_CTRL_MAX_AMP | width;
2265 err = __phy_write(phydev, MII_VCT5_TX_PULSE_CTRL, reg);
2272 return phy_restore_page(phydev, page, err);
2275 static int marvell_cable_test_start_common(struct phy_device *phydev)
2277 int bmcr, bmsr, ret;
2279 /* If auto-negotiation is enabled, but not complete, the cable
2280 * test never completes. So disable auto-neg.
2282 bmcr = phy_read(phydev, MII_BMCR);
2286 bmsr = phy_read(phydev, MII_BMSR);
2291 if (bmcr & BMCR_ANENABLE) {
2292 ret = phy_clear_bits(phydev, MII_BMCR, BMCR_ANENABLE);
2295 ret = genphy_soft_reset(phydev);
2300 /* If the link is up, allow it some time to go down */
2301 if (bmsr & BMSR_LSTATUS)
2307 static int marvell_vct7_cable_test_start(struct phy_device *phydev)
2309 struct marvell_priv *priv = phydev->priv;
2312 ret = marvell_cable_test_start_common(phydev);
2316 priv->cable_test_tdr = false;
2318 /* Reset the VCT5 API control to defaults, otherwise
2319 * VCT7 does not work correctly.
2321 ret = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE,
2323 MII_VCT5_CTRL_TX_SAME_CHANNEL |
2324 MII_VCT5_CTRL_SAMPLES_DEFAULT |
2325 MII_VCT5_CTRL_MODE_MAXIMUM_PEEK |
2326 MII_VCT5_CTRL_PEEK_HYST_DEFAULT);
2330 ret = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE,
2331 MII_VCT5_SAMPLE_POINT_DISTANCE, 0);
2335 return phy_write_paged(phydev, MII_MARVELL_VCT7_PAGE,
2337 MII_VCT7_CTRL_RUN_NOW |
2338 MII_VCT7_CTRL_CENTIMETERS);
2341 static int marvell_vct5_cable_test_tdr_start(struct phy_device *phydev,
2342 const struct phy_tdr_config *cfg)
2344 struct marvell_priv *priv = phydev->priv;
2347 priv->cable_test_tdr = true;
2348 priv->first = marvell_vct5_cm2distance(cfg->first);
2349 priv->last = marvell_vct5_cm2distance(cfg->last);
2350 priv->step = marvell_vct5_cm2distance(cfg->step);
2351 priv->pair = cfg->pair;
2353 if (priv->first > MII_VCT5_SAMPLE_POINT_DISTANCE_MAX)
2356 if (priv->last > MII_VCT5_SAMPLE_POINT_DISTANCE_MAX)
2360 ret = phy_write_paged(phydev, MII_MARVELL_VCT7_PAGE,
2365 ret = marvell_cable_test_start_common(phydev);
2369 ret = ethnl_cable_test_pulse(phydev, 1000);
2373 return ethnl_cable_test_step(phydev,
2374 marvell_vct5_distance2cm(priv->first),
2375 marvell_vct5_distance2cm(priv->last),
2376 marvell_vct5_distance2cm(priv->step));
2379 static int marvell_vct7_distance_to_length(int distance, bool meter)
2387 static bool marvell_vct7_distance_valid(int result)
2390 case MII_VCT7_RESULTS_OPEN:
2391 case MII_VCT7_RESULTS_SAME_SHORT:
2392 case MII_VCT7_RESULTS_CROSS_SHORT:
2398 static int marvell_vct7_report_length(struct phy_device *phydev,
2399 int pair, bool meter)
2404 ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE,
2405 MII_VCT7_PAIR_0_DISTANCE + pair);
2409 length = marvell_vct7_distance_to_length(ret, meter);
2411 ethnl_cable_test_fault_length(phydev, pair, length);
2416 static int marvell_vct7_cable_test_report_trans(int result)
2419 case MII_VCT7_RESULTS_OK:
2420 return ETHTOOL_A_CABLE_RESULT_CODE_OK;
2421 case MII_VCT7_RESULTS_OPEN:
2422 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
2423 case MII_VCT7_RESULTS_SAME_SHORT:
2424 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
2425 case MII_VCT7_RESULTS_CROSS_SHORT:
2426 return ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT;
2428 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
2432 static int marvell_vct7_cable_test_report(struct phy_device *phydev)
2434 int pair0, pair1, pair2, pair3;
2438 ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE,
2443 pair3 = (ret & MII_VCT7_RESULTS_PAIR3_MASK) >>
2444 MII_VCT7_RESULTS_PAIR3_SHIFT;
2445 pair2 = (ret & MII_VCT7_RESULTS_PAIR2_MASK) >>
2446 MII_VCT7_RESULTS_PAIR2_SHIFT;
2447 pair1 = (ret & MII_VCT7_RESULTS_PAIR1_MASK) >>
2448 MII_VCT7_RESULTS_PAIR1_SHIFT;
2449 pair0 = (ret & MII_VCT7_RESULTS_PAIR0_MASK) >>
2450 MII_VCT7_RESULTS_PAIR0_SHIFT;
2452 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
2453 marvell_vct7_cable_test_report_trans(pair0));
2454 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
2455 marvell_vct7_cable_test_report_trans(pair1));
2456 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
2457 marvell_vct7_cable_test_report_trans(pair2));
2458 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
2459 marvell_vct7_cable_test_report_trans(pair3));
2461 ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, MII_VCT7_CTRL);
2465 meter = ret & MII_VCT7_CTRL_METERS;
2467 if (marvell_vct7_distance_valid(pair0))
2468 marvell_vct7_report_length(phydev, 0, meter);
2469 if (marvell_vct7_distance_valid(pair1))
2470 marvell_vct7_report_length(phydev, 1, meter);
2471 if (marvell_vct7_distance_valid(pair2))
2472 marvell_vct7_report_length(phydev, 2, meter);
2473 if (marvell_vct7_distance_valid(pair3))
2474 marvell_vct7_report_length(phydev, 3, meter);
2479 static int marvell_vct7_cable_test_get_status(struct phy_device *phydev,
2482 struct marvell_priv *priv = phydev->priv;
2485 if (priv->cable_test_tdr) {
2486 ret = marvell_vct5_amplitude_graph(phydev);
2493 ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE,
2499 if (!(ret & MII_VCT7_CTRL_IN_PROGRESS)) {
2502 return marvell_vct7_cable_test_report(phydev);
2508 static int m88e3082_vct_cable_test_start(struct phy_device *phydev)
2510 struct marvell_priv *priv = phydev->priv;
2513 /* It needs some magic workarounds described in VCT manual for this PHY.
2515 ret = phy_write(phydev, 29, 0x0003);
2519 ret = phy_write(phydev, 30, 0x6440);
2523 if (priv->vct_phase == M88E3082_VCT_PHASE1) {
2524 ret = phy_write(phydev, 29, 0x000a);
2528 ret = phy_write(phydev, 30, 0x0002);
2533 ret = phy_write(phydev, MII_BMCR,
2534 BMCR_RESET | BMCR_SPEED100 | BMCR_FULLDPLX);
2538 ret = phy_write(phydev, MII_VCT_TXPINS, MII_VCT_TXPINS_ENVCT);
2542 ret = phy_write(phydev, 29, 0x0003);
2546 ret = phy_write(phydev, 30, 0x0);
2550 if (priv->vct_phase == M88E3082_VCT_OFF) {
2551 priv->vct_phase = M88E3082_VCT_PHASE1;
2557 ret = phy_write(phydev, 29, 0x000a);
2561 ret = phy_write(phydev, 30, 0x0);
2565 priv->vct_phase = M88E3082_VCT_PHASE2;
2570 static int m88e3082_vct_cable_test_report_trans(int result, u8 distance)
2573 case MII_VCT_TXRXPINS_VCTTST_OK:
2574 if (distance == MII_VCT_TXRXPINS_DISTRFLN_MAX)
2575 return ETHTOOL_A_CABLE_RESULT_CODE_OK;
2576 return ETHTOOL_A_CABLE_RESULT_CODE_IMPEDANCE_MISMATCH;
2577 case MII_VCT_TXRXPINS_VCTTST_SHORT:
2578 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
2579 case MII_VCT_TXRXPINS_VCTTST_OPEN:
2580 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
2582 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
2586 static u32 m88e3082_vct_distrfln_2_cm(u8 distrfln)
2591 /* Original function for meters: y = 0.7861x - 18.862 */
2592 return (7861 * distrfln - 188620) / 100;
2595 static int m88e3082_vct_cable_test_get_status(struct phy_device *phydev,
2598 u8 tx_vcttst_res, rx_vcttst_res, tx_distrfln, rx_distrfln;
2599 struct marvell_priv *priv = phydev->priv;
2600 int ret, tx_result, rx_result;
2601 bool done_phase = true;
2605 ret = phy_read(phydev, MII_VCT_TXPINS);
2608 else if (ret & MII_VCT_TXPINS_ENVCT)
2611 tx_distrfln = ret & MII_VCT_TXRXPINS_DISTRFLN;
2612 tx_vcttst_res = (ret & MII_VCT_TXRXPINS_VCTTST) >>
2613 MII_VCT_TXRXPINS_VCTTST_SHIFT;
2615 ret = phy_read(phydev, MII_VCT_RXPINS);
2619 rx_distrfln = ret & MII_VCT_TXRXPINS_DISTRFLN;
2620 rx_vcttst_res = (ret & MII_VCT_TXRXPINS_VCTTST) >>
2621 MII_VCT_TXRXPINS_VCTTST_SHIFT;
2625 switch (priv->vct_phase) {
2626 case M88E3082_VCT_PHASE1:
2627 tx_result = m88e3082_vct_cable_test_report_trans(tx_vcttst_res,
2629 rx_result = m88e3082_vct_cable_test_report_trans(rx_vcttst_res,
2632 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
2634 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
2637 if (tx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN) {
2639 priv->pair |= M88E3082_PAIR_A;
2640 } else if (tx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) {
2641 u8 pair = ETHTOOL_A_CABLE_PAIR_A;
2642 u32 cm = m88e3082_vct_distrfln_2_cm(tx_distrfln);
2644 ethnl_cable_test_fault_length(phydev, pair, cm);
2647 if (rx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN) {
2649 priv->pair |= M88E3082_PAIR_B;
2650 } else if (rx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) {
2651 u8 pair = ETHTOOL_A_CABLE_PAIR_B;
2652 u32 cm = m88e3082_vct_distrfln_2_cm(rx_distrfln);
2654 ethnl_cable_test_fault_length(phydev, pair, cm);
2658 case M88E3082_VCT_PHASE2:
2659 if (priv->pair & M88E3082_PAIR_A &&
2660 tx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN &&
2661 tx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) {
2662 u8 pair = ETHTOOL_A_CABLE_PAIR_A;
2663 u32 cm = m88e3082_vct_distrfln_2_cm(tx_distrfln);
2665 ethnl_cable_test_fault_length(phydev, pair, cm);
2667 if (priv->pair & M88E3082_PAIR_B &&
2668 rx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN &&
2669 rx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) {
2670 u8 pair = ETHTOOL_A_CABLE_PAIR_B;
2671 u32 cm = m88e3082_vct_distrfln_2_cm(rx_distrfln);
2673 ethnl_cable_test_fault_length(phydev, pair, cm);
2683 return m88e3082_vct_cable_test_start(phydev);
2686 priv->vct_phase = M88E3082_VCT_OFF;
2690 static int m88e1111_vct_cable_test_start(struct phy_device *phydev)
2694 ret = marvell_cable_test_start_common(phydev);
2698 /* It needs some magic workarounds described in VCT manual for this PHY.
2700 ret = phy_write(phydev, 29, 0x0018);
2704 ret = phy_write(phydev, 30, 0x00c2);
2708 ret = phy_write(phydev, 30, 0x00ca);
2712 ret = phy_write(phydev, 30, 0x00c2);
2716 ret = phy_write_paged(phydev, MII_MARVELL_COPPER_PAGE, MII_VCT_SR,
2717 MII_VCT_TXPINS_ENVCT);
2721 ret = phy_write(phydev, 29, 0x0018);
2725 ret = phy_write(phydev, 30, 0x0042);
2732 static u32 m88e1111_vct_distrfln_2_cm(u8 distrfln)
2737 /* Original function for meters: y = 0.8018x - 28.751 */
2738 return (8018 * distrfln - 287510) / 100;
2741 static int m88e1111_vct_cable_test_get_status(struct phy_device *phydev,
2744 u8 vcttst_res, distrfln;
2749 /* Each pair use one page: A-0, B-1, C-2, D-3 */
2750 for (u8 i = 0; i < 4; i++) {
2751 ret = phy_read_paged(phydev, i, MII_VCT_SR);
2754 else if (i == 0 && ret & MII_VCT_TXPINS_ENVCT)
2757 distrfln = ret & MII_VCT_TXRXPINS_DISTRFLN;
2758 vcttst_res = (ret & MII_VCT_TXRXPINS_VCTTST) >>
2759 MII_VCT_TXRXPINS_VCTTST_SHIFT;
2761 result = m88e3082_vct_cable_test_report_trans(vcttst_res,
2763 ethnl_cable_test_result(phydev, i, result);
2765 if (distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) {
2766 u32 cm = m88e1111_vct_distrfln_2_cm(distrfln);
2768 ethnl_cable_test_fault_length(phydev, i, cm);
2777 struct marvell_hwmon_ops {
2778 int (*config)(struct phy_device *phydev);
2779 int (*get_temp)(struct phy_device *phydev, long *temp);
2780 int (*get_temp_critical)(struct phy_device *phydev, long *temp);
2781 int (*set_temp_critical)(struct phy_device *phydev, long temp);
2782 int (*get_temp_alarm)(struct phy_device *phydev, long *alarm);
2785 static const struct marvell_hwmon_ops *
2786 to_marvell_hwmon_ops(const struct phy_device *phydev)
2788 return phydev->drv->driver_data;
2791 static int m88e1121_get_temp(struct phy_device *phydev, long *temp)
2799 oldpage = phy_select_page(phydev, MII_MARVELL_MISC_TEST_PAGE);
2803 /* Enable temperature sensor */
2804 ret = __phy_read(phydev, MII_88E1121_MISC_TEST);
2808 ret = __phy_write(phydev, MII_88E1121_MISC_TEST,
2809 ret | MII_88E1121_MISC_TEST_TEMP_SENSOR_EN);
2813 /* Wait for temperature to stabilize */
2814 usleep_range(10000, 12000);
2816 val = __phy_read(phydev, MII_88E1121_MISC_TEST);
2822 /* Disable temperature sensor */
2823 ret = __phy_write(phydev, MII_88E1121_MISC_TEST,
2824 ret & ~MII_88E1121_MISC_TEST_TEMP_SENSOR_EN);
2828 *temp = ((val & MII_88E1121_MISC_TEST_TEMP_MASK) - 5) * 5000;
2831 return phy_restore_page(phydev, oldpage, ret);
2834 static int m88e1510_get_temp(struct phy_device *phydev, long *temp)
2840 ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE,
2841 MII_88E1510_TEMP_SENSOR);
2845 *temp = ((ret & MII_88E1510_TEMP_SENSOR_MASK) - 25) * 1000;
2850 static int m88e1510_get_temp_critical(struct phy_device *phydev, long *temp)
2856 ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE,
2857 MII_88E1121_MISC_TEST);
2861 *temp = (((ret & MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) >>
2862 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT) * 5) - 25;
2869 static int m88e1510_set_temp_critical(struct phy_device *phydev, long temp)
2872 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
2874 return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE,
2875 MII_88E1121_MISC_TEST,
2876 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK,
2877 temp << MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT);
2880 static int m88e1510_get_temp_alarm(struct phy_device *phydev, long *alarm)
2886 ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE,
2887 MII_88E1121_MISC_TEST);
2891 *alarm = !!(ret & MII_88E1510_MISC_TEST_TEMP_IRQ);
2896 static int m88e6390_get_temp(struct phy_device *phydev, long *temp)
2905 oldpage = phy_select_page(phydev, MII_MARVELL_MISC_TEST_PAGE);
2909 /* Enable temperature sensor */
2910 ret = __phy_read(phydev, MII_88E6390_MISC_TEST);
2914 ret &= ~MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK;
2915 ret |= MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_SAMPLE_1S;
2917 ret = __phy_write(phydev, MII_88E6390_MISC_TEST, ret);
2921 /* Wait for temperature to stabilize */
2922 usleep_range(10000, 12000);
2924 /* Reading the temperature sense has an errata. You need to read
2925 * a number of times and take an average.
2927 for (i = 0; i < MII_88E6390_TEMP_SENSOR_SAMPLES; i++) {
2928 ret = __phy_read(phydev, MII_88E6390_TEMP_SENSOR);
2931 sum += ret & MII_88E6390_TEMP_SENSOR_MASK;
2934 sum /= MII_88E6390_TEMP_SENSOR_SAMPLES;
2935 *temp = (sum - 75) * 1000;
2937 /* Disable temperature sensor */
2938 ret = __phy_read(phydev, MII_88E6390_MISC_TEST);
2942 ret = ret & ~MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK;
2943 ret |= MII_88E6390_MISC_TEST_TEMP_SENSOR_DISABLE;
2945 ret = __phy_write(phydev, MII_88E6390_MISC_TEST, ret);
2948 phy_restore_page(phydev, oldpage, ret);
2953 static int m88e6393_get_temp(struct phy_device *phydev, long *temp)
2957 err = m88e1510_get_temp(phydev, temp);
2959 /* 88E1510 measures T + 25, while the PHY on 88E6393X switch
2960 * T + 75, so we have to subtract another 50
2967 static int m88e6393_get_temp_critical(struct phy_device *phydev, long *temp)
2973 ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE,
2974 MII_88E6390_TEMP_SENSOR);
2978 *temp = (((ret & MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK) >>
2979 MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT) - 75) * 1000;
2984 static int m88e6393_set_temp_critical(struct phy_device *phydev, long temp)
2986 temp = (temp / 1000) + 75;
2988 return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE,
2989 MII_88E6390_TEMP_SENSOR,
2990 MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK,
2991 temp << MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT);
2994 static int m88e6393_hwmon_config(struct phy_device *phydev)
2998 err = m88e6393_set_temp_critical(phydev, 100000);
3002 return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE,
3003 MII_88E6390_MISC_TEST,
3004 MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK |
3005 MII_88E6393_MISC_TEST_SAMPLES_MASK |
3006 MII_88E6393_MISC_TEST_RATE_MASK,
3007 MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE |
3008 MII_88E6393_MISC_TEST_SAMPLES_2048 |
3009 MII_88E6393_MISC_TEST_RATE_2_3MS);
3012 static int marvell_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
3013 u32 attr, int channel, long *temp)
3015 struct phy_device *phydev = dev_get_drvdata(dev);
3016 const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev);
3017 int err = -EOPNOTSUPP;
3020 case hwmon_temp_input:
3022 err = ops->get_temp(phydev, temp);
3024 case hwmon_temp_crit:
3025 if (ops->get_temp_critical)
3026 err = ops->get_temp_critical(phydev, temp);
3028 case hwmon_temp_max_alarm:
3029 if (ops->get_temp_alarm)
3030 err = ops->get_temp_alarm(phydev, temp);
3037 static int marvell_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
3038 u32 attr, int channel, long temp)
3040 struct phy_device *phydev = dev_get_drvdata(dev);
3041 const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev);
3042 int err = -EOPNOTSUPP;
3045 case hwmon_temp_crit:
3046 if (ops->set_temp_critical)
3047 err = ops->set_temp_critical(phydev, temp);
3054 static umode_t marvell_hwmon_is_visible(const void *data,
3055 enum hwmon_sensor_types type,
3056 u32 attr, int channel)
3058 const struct phy_device *phydev = data;
3059 const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev);
3061 if (type != hwmon_temp)
3065 case hwmon_temp_input:
3066 return ops->get_temp ? 0444 : 0;
3067 case hwmon_temp_max_alarm:
3068 return ops->get_temp_alarm ? 0444 : 0;
3069 case hwmon_temp_crit:
3070 return (ops->get_temp_critical ? 0444 : 0) |
3071 (ops->set_temp_critical ? 0200 : 0);
3077 static u32 marvell_hwmon_chip_config[] = {
3078 HWMON_C_REGISTER_TZ,
3082 static const struct hwmon_channel_info marvell_hwmon_chip = {
3084 .config = marvell_hwmon_chip_config,
3087 /* we can define HWMON_T_CRIT and HWMON_T_MAX_ALARM even though these are not
3088 * defined for all PHYs, because the hwmon code checks whether the attributes
3089 * exists via the .is_visible method
3091 static u32 marvell_hwmon_temp_config[] = {
3092 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM,
3096 static const struct hwmon_channel_info marvell_hwmon_temp = {
3098 .config = marvell_hwmon_temp_config,
3101 static const struct hwmon_channel_info * const marvell_hwmon_info[] = {
3102 &marvell_hwmon_chip,
3103 &marvell_hwmon_temp,
3107 static const struct hwmon_ops marvell_hwmon_hwmon_ops = {
3108 .is_visible = marvell_hwmon_is_visible,
3109 .read = marvell_hwmon_read,
3110 .write = marvell_hwmon_write,
3113 static const struct hwmon_chip_info marvell_hwmon_chip_info = {
3114 .ops = &marvell_hwmon_hwmon_ops,
3115 .info = marvell_hwmon_info,
3118 static int marvell_hwmon_name(struct phy_device *phydev)
3120 struct marvell_priv *priv = phydev->priv;
3121 struct device *dev = &phydev->mdio.dev;
3122 const char *devname = dev_name(dev);
3123 size_t len = strlen(devname);
3126 priv->hwmon_name = devm_kzalloc(dev, len, GFP_KERNEL);
3127 if (!priv->hwmon_name)
3130 for (i = j = 0; i < len && devname[i]; i++) {
3131 if (isalnum(devname[i]))
3132 priv->hwmon_name[j++] = devname[i];
3138 static int marvell_hwmon_probe(struct phy_device *phydev)
3140 const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev);
3141 struct marvell_priv *priv = phydev->priv;
3142 struct device *dev = &phydev->mdio.dev;
3148 err = marvell_hwmon_name(phydev);
3152 priv->hwmon_dev = devm_hwmon_device_register_with_info(
3153 dev, priv->hwmon_name, phydev, &marvell_hwmon_chip_info, NULL);
3154 if (IS_ERR(priv->hwmon_dev))
3155 return PTR_ERR(priv->hwmon_dev);
3158 err = ops->config(phydev);
3163 static const struct marvell_hwmon_ops m88e1121_hwmon_ops = {
3164 .get_temp = m88e1121_get_temp,
3167 static const struct marvell_hwmon_ops m88e1510_hwmon_ops = {
3168 .get_temp = m88e1510_get_temp,
3169 .get_temp_critical = m88e1510_get_temp_critical,
3170 .set_temp_critical = m88e1510_set_temp_critical,
3171 .get_temp_alarm = m88e1510_get_temp_alarm,
3174 static const struct marvell_hwmon_ops m88e6390_hwmon_ops = {
3175 .get_temp = m88e6390_get_temp,
3178 static const struct marvell_hwmon_ops m88e6393_hwmon_ops = {
3179 .config = m88e6393_hwmon_config,
3180 .get_temp = m88e6393_get_temp,
3181 .get_temp_critical = m88e6393_get_temp_critical,
3182 .set_temp_critical = m88e6393_set_temp_critical,
3183 .get_temp_alarm = m88e1510_get_temp_alarm,
3186 #define DEF_MARVELL_HWMON_OPS(s) (&(s))
3190 #define DEF_MARVELL_HWMON_OPS(s) NULL
3192 static int marvell_hwmon_probe(struct phy_device *phydev)
3198 static int m88e1318_led_brightness_set(struct phy_device *phydev,
3199 u8 index, enum led_brightness value)
3203 reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
3204 MII_88E1318S_PHY_LED_FUNC);
3212 reg &= ~(0xf << (4 * index));
3213 if (value == LED_OFF)
3214 reg |= MII_88E1318S_PHY_LED_FUNC_OFF << (4 * index);
3216 reg |= MII_88E1318S_PHY_LED_FUNC_ON << (4 * index);
3222 return phy_write_paged(phydev, MII_MARVELL_LED_PAGE,
3223 MII_88E1318S_PHY_LED_FUNC, reg);
3226 static int m88e1318_led_blink_set(struct phy_device *phydev, u8 index,
3227 unsigned long *delay_on,
3228 unsigned long *delay_off)
3232 reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
3233 MII_88E1318S_PHY_LED_FUNC);
3241 reg &= ~(0xf << (4 * index));
3242 reg |= MII_88E1318S_PHY_LED_FUNC_BLINK << (4 * index);
3243 /* Reset default is 84ms */
3245 *delay_off = 84 / 2;
3251 return phy_write_paged(phydev, MII_MARVELL_LED_PAGE,
3252 MII_88E1318S_PHY_LED_FUNC, reg);
3255 struct marvell_led_rules {
3257 unsigned long rules;
3260 static const struct marvell_led_rules marvell_led0[] = {
3263 .rules = BIT(TRIGGER_NETDEV_LINK),
3267 .rules = (BIT(TRIGGER_NETDEV_LINK) |
3268 BIT(TRIGGER_NETDEV_RX) |
3269 BIT(TRIGGER_NETDEV_TX)),
3273 .rules = (BIT(TRIGGER_NETDEV_RX) |
3274 BIT(TRIGGER_NETDEV_TX)),
3278 .rules = (BIT(TRIGGER_NETDEV_RX) |
3279 BIT(TRIGGER_NETDEV_TX)),
3283 .rules = BIT(TRIGGER_NETDEV_TX),
3287 .rules = BIT(TRIGGER_NETDEV_LINK),
3291 .rules = BIT(TRIGGER_NETDEV_LINK_1000),
3299 static const struct marvell_led_rules marvell_led1[] = {
3302 .rules = (BIT(TRIGGER_NETDEV_LINK) |
3303 BIT(TRIGGER_NETDEV_RX) |
3304 BIT(TRIGGER_NETDEV_TX)),
3308 .rules = (BIT(TRIGGER_NETDEV_LINK) |
3309 BIT(TRIGGER_NETDEV_RX)),
3313 .rules = (BIT(TRIGGER_NETDEV_RX) |
3314 BIT(TRIGGER_NETDEV_TX)),
3318 .rules = (BIT(TRIGGER_NETDEV_RX) |
3319 BIT(TRIGGER_NETDEV_TX)),
3323 .rules = (BIT(TRIGGER_NETDEV_LINK_100) |
3324 BIT(TRIGGER_NETDEV_LINK_1000)),
3328 .rules = BIT(TRIGGER_NETDEV_LINK_100),
3336 static const struct marvell_led_rules marvell_led2[] = {
3339 .rules = BIT(TRIGGER_NETDEV_LINK),
3343 .rules = (BIT(TRIGGER_NETDEV_LINK) |
3344 BIT(TRIGGER_NETDEV_RX) |
3345 BIT(TRIGGER_NETDEV_TX)),
3349 .rules = (BIT(TRIGGER_NETDEV_RX) |
3350 BIT(TRIGGER_NETDEV_TX)),
3354 .rules = (BIT(TRIGGER_NETDEV_RX) |
3355 BIT(TRIGGER_NETDEV_TX)),
3359 .rules = BIT(TRIGGER_NETDEV_TX),
3363 .rules = (BIT(TRIGGER_NETDEV_LINK_10) |
3364 BIT(TRIGGER_NETDEV_LINK_1000)),
3368 .rules = BIT(TRIGGER_NETDEV_LINK_10),
3376 static int marvell_find_led_mode(unsigned long rules,
3377 const struct marvell_led_rules *marvell_rules,
3383 for (i = 0; i < count; i++) {
3384 if (marvell_rules[i].rules == rules) {
3385 *mode = marvell_rules[i].mode;
3392 static int marvell_get_led_mode(u8 index, unsigned long rules, int *mode)
3398 ret = marvell_find_led_mode(rules, marvell_led0,
3399 ARRAY_SIZE(marvell_led0), mode);
3402 ret = marvell_find_led_mode(rules, marvell_led1,
3403 ARRAY_SIZE(marvell_led1), mode);
3406 ret = marvell_find_led_mode(rules, marvell_led2,
3407 ARRAY_SIZE(marvell_led2), mode);
3416 static int marvell_find_led_rules(unsigned long *rules,
3417 const struct marvell_led_rules *marvell_rules,
3423 for (i = 0; i < count; i++) {
3424 if (marvell_rules[i].mode == mode) {
3425 *rules = marvell_rules[i].rules;
3432 static int marvell_get_led_rules(u8 index, unsigned long *rules, int mode)
3438 ret = marvell_find_led_rules(rules, marvell_led0,
3439 ARRAY_SIZE(marvell_led0), mode);
3442 ret = marvell_find_led_rules(rules, marvell_led1,
3443 ARRAY_SIZE(marvell_led1), mode);
3446 ret = marvell_find_led_rules(rules, marvell_led2,
3447 ARRAY_SIZE(marvell_led2), mode);
3456 static int m88e1318_led_hw_is_supported(struct phy_device *phydev, u8 index,
3457 unsigned long rules)
3465 ret = marvell_get_led_mode(index, rules, &mode);
3474 static int m88e1318_led_hw_control_set(struct phy_device *phydev, u8 index,
3475 unsigned long rules)
3483 ret = marvell_get_led_mode(index, rules, &mode);
3492 reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
3493 MII_88E1318S_PHY_LED_FUNC);
3497 reg &= ~(0xf << (4 * index));
3498 reg |= mode << (4 * index);
3499 return phy_write_paged(phydev, MII_MARVELL_LED_PAGE,
3500 MII_88E1318S_PHY_LED_FUNC, reg);
3503 static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index,
3504 unsigned long *rules)
3511 reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
3512 MII_88E1318S_PHY_LED_FUNC);
3516 mode = (reg >> (4 * index)) & 0xf;
3518 return marvell_get_led_rules(index, rules, mode);
3521 static int marvell_probe(struct phy_device *phydev)
3523 struct marvell_priv *priv;
3525 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
3529 phydev->priv = priv;
3531 return marvell_hwmon_probe(phydev);
3534 static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
3536 DECLARE_PHY_INTERFACE_MASK(interfaces);
3537 struct phy_device *phydev = upstream;
3538 phy_interface_t interface;
3544 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported) = { 0, };
3546 dev = &phydev->mdio.dev;
3548 sfp_parse_support(phydev->sfp_bus, id, supported, interfaces);
3549 interface = sfp_select_interface(phydev->sfp_bus, supported);
3551 dev_info(dev, "%s SFP module inserted\n", phy_modes(interface));
3553 switch (interface) {
3554 case PHY_INTERFACE_MODE_1000BASEX:
3555 mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X;
3558 case PHY_INTERFACE_MODE_100BASEX:
3559 mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX;
3562 case PHY_INTERFACE_MODE_SGMII:
3563 mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII;
3567 dev_err(dev, "Incompatible SFP module inserted\n");
3572 oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE);
3576 ret = __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1,
3577 MII_88E1510_GEN_CTRL_REG_1_MODE_MASK, mode);
3581 ret = __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1,
3582 MII_88E1510_GEN_CTRL_REG_1_RESET);
3585 return phy_restore_page(phydev, oldpage, ret);
3588 static void m88e1510_sfp_remove(void *upstream)
3590 struct phy_device *phydev = upstream;
3594 oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE);
3598 ret = __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1,
3599 MII_88E1510_GEN_CTRL_REG_1_MODE_MASK,
3600 MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII);
3604 ret = __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1,
3605 MII_88E1510_GEN_CTRL_REG_1_RESET);
3608 phy_restore_page(phydev, oldpage, ret);
3611 static const struct sfp_upstream_ops m88e1510_sfp_ops = {
3612 .module_insert = m88e1510_sfp_insert,
3613 .module_remove = m88e1510_sfp_remove,
3614 .attach = phy_sfp_attach,
3615 .detach = phy_sfp_detach,
3616 .connect_phy = phy_sfp_connect_phy,
3617 .disconnect_phy = phy_sfp_disconnect_phy,
3620 static int m88e1510_probe(struct phy_device *phydev)
3624 err = marvell_probe(phydev);
3628 return phy_sfp_probe(phydev, &m88e1510_sfp_ops);
3631 static struct phy_driver marvell_drivers[] = {
3633 .phy_id = MARVELL_PHY_ID_88E1101,
3634 .phy_id_mask = MARVELL_PHY_ID_MASK,
3635 .name = "Marvell 88E1101",
3636 /* PHY_GBIT_FEATURES */
3637 .probe = marvell_probe,
3638 .config_init = marvell_config_init,
3639 .config_aneg = m88e1101_config_aneg,
3640 .config_intr = marvell_config_intr,
3641 .handle_interrupt = marvell_handle_interrupt,
3642 .resume = genphy_resume,
3643 .suspend = genphy_suspend,
3644 .read_page = marvell_read_page,
3645 .write_page = marvell_write_page,
3646 .get_sset_count = marvell_get_sset_count,
3647 .get_strings = marvell_get_strings,
3648 .get_stats = marvell_get_stats,
3651 .phy_id = MARVELL_PHY_ID_88E3082,
3652 .phy_id_mask = MARVELL_PHY_ID_MASK,
3653 .name = "Marvell 88E308X/88E609X Family",
3654 /* PHY_BASIC_FEATURES */
3655 .probe = marvell_probe,
3656 .config_init = marvell_config_init,
3657 .aneg_done = marvell_aneg_done,
3658 .read_status = marvell_read_status,
3659 .resume = genphy_resume,
3660 .suspend = genphy_suspend,
3661 .cable_test_start = m88e3082_vct_cable_test_start,
3662 .cable_test_get_status = m88e3082_vct_cable_test_get_status,
3665 .phy_id = MARVELL_PHY_ID_88E1112,
3666 .phy_id_mask = MARVELL_PHY_ID_MASK,
3667 .name = "Marvell 88E1112",
3668 /* PHY_GBIT_FEATURES */
3669 .probe = marvell_probe,
3670 .config_init = m88e1112_config_init,
3671 .config_aneg = marvell_config_aneg,
3672 .config_intr = marvell_config_intr,
3673 .handle_interrupt = marvell_handle_interrupt,
3674 .resume = genphy_resume,
3675 .suspend = genphy_suspend,
3676 .read_page = marvell_read_page,
3677 .write_page = marvell_write_page,
3678 .get_sset_count = marvell_get_sset_count,
3679 .get_strings = marvell_get_strings,
3680 .get_stats = marvell_get_stats,
3681 .get_tunable = m88e1011_get_tunable,
3682 .set_tunable = m88e1011_set_tunable,
3685 .phy_id = MARVELL_PHY_ID_88E1111,
3686 .phy_id_mask = MARVELL_PHY_ID_MASK,
3687 .name = "Marvell 88E1111",
3688 /* PHY_GBIT_FEATURES */
3689 .flags = PHY_POLL_CABLE_TEST,
3690 .probe = marvell_probe,
3691 .config_init = m88e1111gbe_config_init,
3692 .config_aneg = m88e1111_config_aneg,
3693 .read_status = marvell_read_status,
3694 .config_intr = marvell_config_intr,
3695 .handle_interrupt = marvell_handle_interrupt,
3696 .resume = genphy_resume,
3697 .suspend = genphy_suspend,
3698 .read_page = marvell_read_page,
3699 .write_page = marvell_write_page,
3700 .get_sset_count = marvell_get_sset_count,
3701 .get_strings = marvell_get_strings,
3702 .get_stats = marvell_get_stats,
3703 .get_tunable = m88e1111_get_tunable,
3704 .set_tunable = m88e1111_set_tunable,
3705 .cable_test_start = m88e1111_vct_cable_test_start,
3706 .cable_test_get_status = m88e1111_vct_cable_test_get_status,
3709 .phy_id = MARVELL_PHY_ID_88E1111_FINISAR,
3710 .phy_id_mask = MARVELL_PHY_ID_MASK,
3711 .name = "Marvell 88E1111 (Finisar)",
3712 /* PHY_GBIT_FEATURES */
3713 .probe = marvell_probe,
3714 .config_init = m88e1111gbe_config_init,
3715 .config_aneg = m88e1111_config_aneg,
3716 .read_status = marvell_read_status,
3717 .config_intr = marvell_config_intr,
3718 .handle_interrupt = marvell_handle_interrupt,
3719 .resume = genphy_resume,
3720 .suspend = genphy_suspend,
3721 .read_page = marvell_read_page,
3722 .write_page = marvell_write_page,
3723 .get_sset_count = marvell_get_sset_count,
3724 .get_strings = marvell_get_strings,
3725 .get_stats = marvell_get_stats,
3726 .get_tunable = m88e1111_get_tunable,
3727 .set_tunable = m88e1111_set_tunable,
3730 .phy_id = MARVELL_PHY_ID_88E1118,
3731 .phy_id_mask = MARVELL_PHY_ID_MASK,
3732 .name = "Marvell 88E1118",
3733 /* PHY_GBIT_FEATURES */
3734 .probe = marvell_probe,
3735 .config_init = m88e1118_config_init,
3736 .config_aneg = m88e1118_config_aneg,
3737 .config_intr = marvell_config_intr,
3738 .handle_interrupt = marvell_handle_interrupt,
3739 .resume = genphy_resume,
3740 .suspend = genphy_suspend,
3741 .read_page = marvell_read_page,
3742 .write_page = marvell_write_page,
3743 .get_sset_count = marvell_get_sset_count,
3744 .get_strings = marvell_get_strings,
3745 .get_stats = marvell_get_stats,
3748 .phy_id = MARVELL_PHY_ID_88E1121R,
3749 .phy_id_mask = MARVELL_PHY_ID_MASK,
3750 .name = "Marvell 88E1121R",
3751 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1121_hwmon_ops),
3752 /* PHY_GBIT_FEATURES */
3753 .probe = marvell_probe,
3754 .config_init = marvell_1011gbe_config_init,
3755 .config_aneg = m88e1121_config_aneg,
3756 .read_status = marvell_read_status,
3757 .config_intr = marvell_config_intr,
3758 .handle_interrupt = marvell_handle_interrupt,
3759 .resume = genphy_resume,
3760 .suspend = genphy_suspend,
3761 .read_page = marvell_read_page,
3762 .write_page = marvell_write_page,
3763 .get_sset_count = marvell_get_sset_count,
3764 .get_strings = marvell_get_strings,
3765 .get_stats = marvell_get_stats,
3766 .get_tunable = m88e1011_get_tunable,
3767 .set_tunable = m88e1011_set_tunable,
3770 .phy_id = MARVELL_PHY_ID_88E1318S,
3771 .phy_id_mask = MARVELL_PHY_ID_MASK,
3772 .name = "Marvell 88E1318S",
3773 /* PHY_GBIT_FEATURES */
3774 .probe = marvell_probe,
3775 .config_init = m88e1318_config_init,
3776 .config_aneg = m88e1318_config_aneg,
3777 .read_status = marvell_read_status,
3778 .config_intr = marvell_config_intr,
3779 .handle_interrupt = marvell_handle_interrupt,
3780 .get_wol = m88e1318_get_wol,
3781 .set_wol = m88e1318_set_wol,
3782 .resume = genphy_resume,
3783 .suspend = genphy_suspend,
3784 .read_page = marvell_read_page,
3785 .write_page = marvell_write_page,
3786 .get_sset_count = marvell_get_sset_count,
3787 .get_strings = marvell_get_strings,
3788 .get_stats = marvell_get_stats,
3789 .led_brightness_set = m88e1318_led_brightness_set,
3790 .led_blink_set = m88e1318_led_blink_set,
3791 .led_hw_is_supported = m88e1318_led_hw_is_supported,
3792 .led_hw_control_set = m88e1318_led_hw_control_set,
3793 .led_hw_control_get = m88e1318_led_hw_control_get,
3796 .phy_id = MARVELL_PHY_ID_88E1145,
3797 .phy_id_mask = MARVELL_PHY_ID_MASK,
3798 .name = "Marvell 88E1145",
3799 /* PHY_GBIT_FEATURES */
3800 .flags = PHY_POLL_CABLE_TEST,
3801 .probe = marvell_probe,
3802 .config_init = m88e1145_config_init,
3803 .config_aneg = m88e1101_config_aneg,
3804 .config_intr = marvell_config_intr,
3805 .handle_interrupt = marvell_handle_interrupt,
3806 .resume = genphy_resume,
3807 .suspend = genphy_suspend,
3808 .read_page = marvell_read_page,
3809 .write_page = marvell_write_page,
3810 .get_sset_count = marvell_get_sset_count,
3811 .get_strings = marvell_get_strings,
3812 .get_stats = marvell_get_stats,
3813 .get_tunable = m88e1111_get_tunable,
3814 .set_tunable = m88e1111_set_tunable,
3815 .cable_test_start = m88e1111_vct_cable_test_start,
3816 .cable_test_get_status = m88e1111_vct_cable_test_get_status,
3819 .phy_id = MARVELL_PHY_ID_88E1149R,
3820 .phy_id_mask = MARVELL_PHY_ID_MASK,
3821 .name = "Marvell 88E1149R",
3822 /* PHY_GBIT_FEATURES */
3823 .probe = marvell_probe,
3824 .config_init = m88e1149_config_init,
3825 .config_aneg = m88e1118_config_aneg,
3826 .config_intr = marvell_config_intr,
3827 .handle_interrupt = marvell_handle_interrupt,
3828 .resume = genphy_resume,
3829 .suspend = genphy_suspend,
3830 .read_page = marvell_read_page,
3831 .write_page = marvell_write_page,
3832 .get_sset_count = marvell_get_sset_count,
3833 .get_strings = marvell_get_strings,
3834 .get_stats = marvell_get_stats,
3837 .phy_id = MARVELL_PHY_ID_88E1240,
3838 .phy_id_mask = MARVELL_PHY_ID_MASK,
3839 .name = "Marvell 88E1240",
3840 /* PHY_GBIT_FEATURES */
3841 .probe = marvell_probe,
3842 .config_init = m88e1112_config_init,
3843 .config_aneg = marvell_config_aneg,
3844 .config_intr = marvell_config_intr,
3845 .handle_interrupt = marvell_handle_interrupt,
3846 .resume = genphy_resume,
3847 .suspend = genphy_suspend,
3848 .read_page = marvell_read_page,
3849 .write_page = marvell_write_page,
3850 .get_sset_count = marvell_get_sset_count,
3851 .get_strings = marvell_get_strings,
3852 .get_stats = marvell_get_stats,
3853 .get_tunable = m88e1011_get_tunable,
3854 .set_tunable = m88e1011_set_tunable,
3857 .phy_id = MARVELL_PHY_ID_88E1116R,
3858 .phy_id_mask = MARVELL_PHY_ID_MASK,
3859 .name = "Marvell 88E1116R",
3860 /* PHY_GBIT_FEATURES */
3861 .probe = marvell_probe,
3862 .config_init = m88e1116r_config_init,
3863 .config_intr = marvell_config_intr,
3864 .handle_interrupt = marvell_handle_interrupt,
3865 .resume = genphy_resume,
3866 .suspend = genphy_suspend,
3867 .read_page = marvell_read_page,
3868 .write_page = marvell_write_page,
3869 .get_sset_count = marvell_get_sset_count,
3870 .get_strings = marvell_get_strings,
3871 .get_stats = marvell_get_stats,
3872 .get_tunable = m88e1011_get_tunable,
3873 .set_tunable = m88e1011_set_tunable,
3876 .phy_id = MARVELL_PHY_ID_88E1510,
3877 .phy_id_mask = MARVELL_PHY_ID_MASK,
3878 .name = "Marvell 88E1510",
3879 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops),
3880 .features = PHY_GBIT_FIBRE_FEATURES,
3881 .flags = PHY_POLL_CABLE_TEST,
3882 .probe = m88e1510_probe,
3883 .config_init = m88e1510_config_init,
3884 .config_aneg = m88e1510_config_aneg,
3885 .read_status = marvell_read_status,
3886 .config_intr = marvell_config_intr,
3887 .handle_interrupt = marvell_handle_interrupt,
3888 .get_wol = m88e1318_get_wol,
3889 .set_wol = m88e1318_set_wol,
3890 .resume = marvell_resume,
3891 .suspend = marvell_suspend,
3892 .read_page = marvell_read_page,
3893 .write_page = marvell_write_page,
3894 .get_sset_count = marvell_get_sset_count,
3895 .get_strings = marvell_get_strings,
3896 .get_stats = marvell_get_stats,
3897 .set_loopback = m88e1510_loopback,
3898 .get_tunable = m88e1011_get_tunable,
3899 .set_tunable = m88e1011_set_tunable,
3900 .cable_test_start = marvell_vct7_cable_test_start,
3901 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
3902 .cable_test_get_status = marvell_vct7_cable_test_get_status,
3903 .led_brightness_set = m88e1318_led_brightness_set,
3904 .led_blink_set = m88e1318_led_blink_set,
3905 .led_hw_is_supported = m88e1318_led_hw_is_supported,
3906 .led_hw_control_set = m88e1318_led_hw_control_set,
3907 .led_hw_control_get = m88e1318_led_hw_control_get,
3910 .phy_id = MARVELL_PHY_ID_88E1540,
3911 .phy_id_mask = MARVELL_PHY_ID_MASK,
3912 .name = "Marvell 88E1540",
3913 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops),
3914 /* PHY_GBIT_FEATURES */
3915 .flags = PHY_POLL_CABLE_TEST,
3916 .probe = marvell_probe,
3917 .config_init = marvell_1011gbe_config_init,
3918 .config_aneg = m88e1510_config_aneg,
3919 .read_status = marvell_read_status,
3920 .config_intr = marvell_config_intr,
3921 .handle_interrupt = marvell_handle_interrupt,
3922 .resume = genphy_resume,
3923 .suspend = genphy_suspend,
3924 .read_page = marvell_read_page,
3925 .write_page = marvell_write_page,
3926 .get_sset_count = marvell_get_sset_count,
3927 .get_strings = marvell_get_strings,
3928 .get_stats = marvell_get_stats,
3929 .get_tunable = m88e1540_get_tunable,
3930 .set_tunable = m88e1540_set_tunable,
3931 .cable_test_start = marvell_vct7_cable_test_start,
3932 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
3933 .cable_test_get_status = marvell_vct7_cable_test_get_status,
3934 .led_brightness_set = m88e1318_led_brightness_set,
3935 .led_blink_set = m88e1318_led_blink_set,
3936 .led_hw_is_supported = m88e1318_led_hw_is_supported,
3937 .led_hw_control_set = m88e1318_led_hw_control_set,
3938 .led_hw_control_get = m88e1318_led_hw_control_get,
3941 .phy_id = MARVELL_PHY_ID_88E1545,
3942 .phy_id_mask = MARVELL_PHY_ID_MASK,
3943 .name = "Marvell 88E1545",
3944 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops),
3945 .probe = marvell_probe,
3946 /* PHY_GBIT_FEATURES */
3947 .flags = PHY_POLL_CABLE_TEST,
3948 .config_init = marvell_1011gbe_config_init,
3949 .config_aneg = m88e1510_config_aneg,
3950 .read_status = marvell_read_status,
3951 .config_intr = marvell_config_intr,
3952 .handle_interrupt = marvell_handle_interrupt,
3953 .resume = genphy_resume,
3954 .suspend = genphy_suspend,
3955 .read_page = marvell_read_page,
3956 .write_page = marvell_write_page,
3957 .get_sset_count = marvell_get_sset_count,
3958 .get_strings = marvell_get_strings,
3959 .get_stats = marvell_get_stats,
3960 .get_tunable = m88e1540_get_tunable,
3961 .set_tunable = m88e1540_set_tunable,
3962 .cable_test_start = marvell_vct7_cable_test_start,
3963 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
3964 .cable_test_get_status = marvell_vct7_cable_test_get_status,
3965 .led_brightness_set = m88e1318_led_brightness_set,
3966 .led_blink_set = m88e1318_led_blink_set,
3967 .led_hw_is_supported = m88e1318_led_hw_is_supported,
3968 .led_hw_control_set = m88e1318_led_hw_control_set,
3969 .led_hw_control_get = m88e1318_led_hw_control_get,
3972 .phy_id = MARVELL_PHY_ID_88E3016,
3973 .phy_id_mask = MARVELL_PHY_ID_MASK,
3974 .name = "Marvell 88E3016",
3975 /* PHY_BASIC_FEATURES */
3976 .probe = marvell_probe,
3977 .config_init = m88e3016_config_init,
3978 .aneg_done = marvell_aneg_done,
3979 .read_status = marvell_read_status,
3980 .config_intr = marvell_config_intr,
3981 .handle_interrupt = marvell_handle_interrupt,
3982 .resume = genphy_resume,
3983 .suspend = genphy_suspend,
3984 .read_page = marvell_read_page,
3985 .write_page = marvell_write_page,
3986 .get_sset_count = marvell_get_sset_count,
3987 .get_strings = marvell_get_strings,
3988 .get_stats = marvell_get_stats,
3991 .phy_id = MARVELL_PHY_ID_88E6250_FAMILY,
3992 .phy_id_mask = MARVELL_PHY_ID_MASK,
3993 .name = "Marvell 88E6250 Family",
3994 /* PHY_BASIC_FEATURES */
3995 .probe = marvell_probe,
3996 .aneg_done = marvell_aneg_done,
3997 .config_intr = marvell_config_intr,
3998 .handle_interrupt = marvell_handle_interrupt,
3999 .resume = genphy_resume,
4000 .suspend = genphy_suspend,
4001 .get_sset_count = marvell_get_sset_count_simple,
4002 .get_strings = marvell_get_strings_simple,
4003 .get_stats = marvell_get_stats_simple,
4006 .phy_id = MARVELL_PHY_ID_88E6341_FAMILY,
4007 .phy_id_mask = MARVELL_PHY_ID_MASK,
4008 .name = "Marvell 88E6341 Family",
4009 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops),
4010 /* PHY_GBIT_FEATURES */
4011 .flags = PHY_POLL_CABLE_TEST,
4012 .probe = marvell_probe,
4013 .config_init = marvell_1011gbe_config_init,
4014 .config_aneg = m88e6390_config_aneg,
4015 .read_status = marvell_read_status,
4016 .config_intr = marvell_config_intr,
4017 .handle_interrupt = marvell_handle_interrupt,
4018 .resume = genphy_resume,
4019 .suspend = genphy_suspend,
4020 .read_page = marvell_read_page,
4021 .write_page = marvell_write_page,
4022 .get_sset_count = marvell_get_sset_count,
4023 .get_strings = marvell_get_strings,
4024 .get_stats = marvell_get_stats,
4025 .get_tunable = m88e1540_get_tunable,
4026 .set_tunable = m88e1540_set_tunable,
4027 .cable_test_start = marvell_vct7_cable_test_start,
4028 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
4029 .cable_test_get_status = marvell_vct7_cable_test_get_status,
4032 .phy_id = MARVELL_PHY_ID_88E6390_FAMILY,
4033 .phy_id_mask = MARVELL_PHY_ID_MASK,
4034 .name = "Marvell 88E6390 Family",
4035 .driver_data = DEF_MARVELL_HWMON_OPS(m88e6390_hwmon_ops),
4036 /* PHY_GBIT_FEATURES */
4037 .flags = PHY_POLL_CABLE_TEST,
4038 .probe = marvell_probe,
4039 .config_init = marvell_1011gbe_config_init,
4040 .config_aneg = m88e6390_config_aneg,
4041 .read_status = marvell_read_status,
4042 .config_intr = marvell_config_intr,
4043 .handle_interrupt = marvell_handle_interrupt,
4044 .resume = genphy_resume,
4045 .suspend = genphy_suspend,
4046 .read_page = marvell_read_page,
4047 .write_page = marvell_write_page,
4048 .get_sset_count = marvell_get_sset_count,
4049 .get_strings = marvell_get_strings,
4050 .get_stats = marvell_get_stats,
4051 .get_tunable = m88e1540_get_tunable,
4052 .set_tunable = m88e1540_set_tunable,
4053 .cable_test_start = marvell_vct7_cable_test_start,
4054 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
4055 .cable_test_get_status = marvell_vct7_cable_test_get_status,
4058 .phy_id = MARVELL_PHY_ID_88E6393_FAMILY,
4059 .phy_id_mask = MARVELL_PHY_ID_MASK,
4060 .name = "Marvell 88E6393 Family",
4061 .driver_data = DEF_MARVELL_HWMON_OPS(m88e6393_hwmon_ops),
4062 /* PHY_GBIT_FEATURES */
4063 .flags = PHY_POLL_CABLE_TEST,
4064 .probe = marvell_probe,
4065 .config_init = marvell_1011gbe_config_init,
4066 .config_aneg = m88e1510_config_aneg,
4067 .read_status = marvell_read_status,
4068 .config_intr = marvell_config_intr,
4069 .handle_interrupt = marvell_handle_interrupt,
4070 .resume = genphy_resume,
4071 .suspend = genphy_suspend,
4072 .read_page = marvell_read_page,
4073 .write_page = marvell_write_page,
4074 .get_sset_count = marvell_get_sset_count,
4075 .get_strings = marvell_get_strings,
4076 .get_stats = marvell_get_stats,
4077 .get_tunable = m88e1540_get_tunable,
4078 .set_tunable = m88e1540_set_tunable,
4079 .cable_test_start = marvell_vct7_cable_test_start,
4080 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
4081 .cable_test_get_status = marvell_vct7_cable_test_get_status,
4084 .phy_id = MARVELL_PHY_ID_88E1340S,
4085 .phy_id_mask = MARVELL_PHY_ID_MASK,
4086 .name = "Marvell 88E1340S",
4087 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops),
4088 .probe = marvell_probe,
4089 /* PHY_GBIT_FEATURES */
4090 .config_init = marvell_1011gbe_config_init,
4091 .config_aneg = m88e1510_config_aneg,
4092 .read_status = marvell_read_status,
4093 .config_intr = marvell_config_intr,
4094 .handle_interrupt = marvell_handle_interrupt,
4095 .resume = genphy_resume,
4096 .suspend = genphy_suspend,
4097 .read_page = marvell_read_page,
4098 .write_page = marvell_write_page,
4099 .get_sset_count = marvell_get_sset_count,
4100 .get_strings = marvell_get_strings,
4101 .get_stats = marvell_get_stats,
4102 .get_tunable = m88e1540_get_tunable,
4103 .set_tunable = m88e1540_set_tunable,
4106 .phy_id = MARVELL_PHY_ID_88E1548P,
4107 .phy_id_mask = MARVELL_PHY_ID_MASK,
4108 .name = "Marvell 88E1548P",
4109 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops),
4110 .probe = marvell_probe,
4111 .features = PHY_GBIT_FIBRE_FEATURES,
4112 .config_init = marvell_1011gbe_config_init,
4113 .config_aneg = m88e1510_config_aneg,
4114 .read_status = marvell_read_status,
4115 .config_intr = marvell_config_intr,
4116 .handle_interrupt = marvell_handle_interrupt,
4117 .resume = genphy_resume,
4118 .suspend = genphy_suspend,
4119 .read_page = marvell_read_page,
4120 .write_page = marvell_write_page,
4121 .get_sset_count = marvell_get_sset_count,
4122 .get_strings = marvell_get_strings,
4123 .get_stats = marvell_get_stats,
4124 .get_tunable = m88e1540_get_tunable,
4125 .set_tunable = m88e1540_set_tunable,
4126 .led_brightness_set = m88e1318_led_brightness_set,
4127 .led_blink_set = m88e1318_led_blink_set,
4128 .led_hw_is_supported = m88e1318_led_hw_is_supported,
4129 .led_hw_control_set = m88e1318_led_hw_control_set,
4130 .led_hw_control_get = m88e1318_led_hw_control_get,
4134 module_phy_driver(marvell_drivers);
4136 static struct mdio_device_id __maybe_unused marvell_tbl[] = {
4137 { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK },
4138 { MARVELL_PHY_ID_88E3082, MARVELL_PHY_ID_MASK },
4139 { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK },
4140 { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK },
4141 { MARVELL_PHY_ID_88E1111_FINISAR, MARVELL_PHY_ID_MASK },
4142 { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK },
4143 { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK },
4144 { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK },
4145 { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK },
4146 { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK },
4147 { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK },
4148 { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK },
4149 { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK },
4150 { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK },
4151 { MARVELL_PHY_ID_88E1545, MARVELL_PHY_ID_MASK },
4152 { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK },
4153 { MARVELL_PHY_ID_88E6250_FAMILY, MARVELL_PHY_ID_MASK },
4154 { MARVELL_PHY_ID_88E6341_FAMILY, MARVELL_PHY_ID_MASK },
4155 { MARVELL_PHY_ID_88E6390_FAMILY, MARVELL_PHY_ID_MASK },
4156 { MARVELL_PHY_ID_88E6393_FAMILY, MARVELL_PHY_ID_MASK },
4157 { MARVELL_PHY_ID_88E1340S, MARVELL_PHY_ID_MASK },
4158 { MARVELL_PHY_ID_88E1548P, MARVELL_PHY_ID_MASK },
4162 MODULE_DEVICE_TABLE(mdio, marvell_tbl);