1 // SPDX-License-Identifier: GPL-2.0+
3 * drivers/net/phy/at803x.c
5 * Driver for Qualcomm Atheros AR803x PHY
10 #include <linux/phy.h>
11 #include <linux/module.h>
12 #include <linux/string.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <linux/ethtool_netlink.h>
16 #include <linux/bitfield.h>
17 #include <linux/regulator/of_regulator.h>
18 #include <linux/regulator/driver.h>
19 #include <linux/regulator/consumer.h>
21 #include <linux/phylink.h>
22 #include <linux/sfp.h>
23 #include <dt-bindings/net/qca-ar803x.h>
25 #define AT803X_SPECIFIC_FUNCTION_CONTROL 0x10
26 #define AT803X_SFC_ASSERT_CRS BIT(11)
27 #define AT803X_SFC_FORCE_LINK BIT(10)
28 #define AT803X_SFC_MDI_CROSSOVER_MODE_M GENMASK(6, 5)
29 #define AT803X_SFC_AUTOMATIC_CROSSOVER 0x3
30 #define AT803X_SFC_MANUAL_MDIX 0x1
31 #define AT803X_SFC_MANUAL_MDI 0x0
32 #define AT803X_SFC_SQE_TEST BIT(2)
33 #define AT803X_SFC_POLARITY_REVERSAL BIT(1)
34 #define AT803X_SFC_DISABLE_JABBER BIT(0)
36 #define AT803X_SPECIFIC_STATUS 0x11
37 #define AT803X_SS_SPEED_MASK GENMASK(15, 14)
38 #define AT803X_SS_SPEED_1000 2
39 #define AT803X_SS_SPEED_100 1
40 #define AT803X_SS_SPEED_10 0
41 #define AT803X_SS_DUPLEX BIT(13)
42 #define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11)
43 #define AT803X_SS_MDIX BIT(6)
45 #define QCA808X_SS_SPEED_MASK GENMASK(9, 7)
46 #define QCA808X_SS_SPEED_2500 4
48 #define AT803X_INTR_ENABLE 0x12
49 #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15)
50 #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14)
51 #define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13)
52 #define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12)
53 #define AT803X_INTR_ENABLE_LINK_FAIL BIT(11)
54 #define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10)
55 #define AT803X_INTR_ENABLE_LINK_FAIL_BX BIT(8)
56 #define AT803X_INTR_ENABLE_LINK_SUCCESS_BX BIT(7)
57 #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5)
58 #define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1)
59 #define AT803X_INTR_ENABLE_WOL BIT(0)
61 #define AT803X_INTR_STATUS 0x13
63 #define AT803X_SMART_SPEED 0x14
64 #define AT803X_SMART_SPEED_ENABLE BIT(5)
65 #define AT803X_SMART_SPEED_RETRY_LIMIT_MASK GENMASK(4, 2)
66 #define AT803X_SMART_SPEED_BYPASS_TIMER BIT(1)
67 #define AT803X_CDT 0x16
68 #define AT803X_CDT_MDI_PAIR_MASK GENMASK(9, 8)
69 #define AT803X_CDT_ENABLE_TEST BIT(0)
70 #define AT803X_CDT_STATUS 0x1c
71 #define AT803X_CDT_STATUS_STAT_NORMAL 0
72 #define AT803X_CDT_STATUS_STAT_SHORT 1
73 #define AT803X_CDT_STATUS_STAT_OPEN 2
74 #define AT803X_CDT_STATUS_STAT_FAIL 3
75 #define AT803X_CDT_STATUS_STAT_MASK GENMASK(9, 8)
76 #define AT803X_CDT_STATUS_DELTA_TIME_MASK GENMASK(7, 0)
77 #define AT803X_LED_CONTROL 0x18
79 #define AT803X_PHY_MMD3_WOL_CTRL 0x8012
80 #define AT803X_WOL_EN BIT(5)
81 #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C
82 #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B
83 #define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A
84 #define AT803X_REG_CHIP_CONFIG 0x1f
85 #define AT803X_BT_BX_REG_SEL 0x8000
87 #define AT803X_DEBUG_ADDR 0x1D
88 #define AT803X_DEBUG_DATA 0x1E
90 #define AT803X_MODE_CFG_MASK 0x0F
91 #define AT803X_MODE_CFG_BASET_RGMII 0x00
92 #define AT803X_MODE_CFG_BASET_SGMII 0x01
93 #define AT803X_MODE_CFG_BX1000_RGMII_50OHM 0x02
94 #define AT803X_MODE_CFG_BX1000_RGMII_75OHM 0x03
95 #define AT803X_MODE_CFG_BX1000_CONV_50OHM 0x04
96 #define AT803X_MODE_CFG_BX1000_CONV_75OHM 0x05
97 #define AT803X_MODE_CFG_FX100_RGMII_50OHM 0x06
98 #define AT803X_MODE_CFG_FX100_CONV_50OHM 0x07
99 #define AT803X_MODE_CFG_RGMII_AUTO_MDET 0x0B
100 #define AT803X_MODE_CFG_FX100_RGMII_75OHM 0x0E
101 #define AT803X_MODE_CFG_FX100_CONV_75OHM 0x0F
103 #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/
104 #define AT803X_PSSR_MR_AN_COMPLETE 0x0200
106 #define AT803X_DEBUG_ANALOG_TEST_CTRL 0x00
107 #define QCA8327_DEBUG_MANU_CTRL_EN BIT(2)
108 #define QCA8337_DEBUG_MANU_CTRL_EN GENMASK(3, 2)
109 #define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15)
111 #define AT803X_DEBUG_SYSTEM_CTRL_MODE 0x05
112 #define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8)
114 #define AT803X_DEBUG_REG_HIB_CTRL 0x0b
115 #define AT803X_DEBUG_HIB_CTRL_SEL_RST_80U BIT(10)
116 #define AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE BIT(13)
117 #define AT803X_DEBUG_HIB_CTRL_PS_HIB_EN BIT(15)
119 #define AT803X_DEBUG_REG_3C 0x3C
121 #define AT803X_DEBUG_REG_GREEN 0x3D
122 #define AT803X_DEBUG_GATE_CLK_IN1000 BIT(6)
124 #define AT803X_DEBUG_REG_1F 0x1F
125 #define AT803X_DEBUG_PLL_ON BIT(2)
126 #define AT803X_DEBUG_RGMII_1V8 BIT(3)
128 #define MDIO_AZ_DEBUG 0x800D
130 /* AT803x supports either the XTAL input pad, an internal PLL or the
131 * DSP as clock reference for the clock output pad. The XTAL reference
132 * is only used for 25 MHz output, all other frequencies need the PLL.
133 * The DSP as a clock reference is used in synchronous ethernet
136 * By default the PLL is only enabled if there is a link. Otherwise
137 * the PHY will go into low power state and disabled the PLL. You can
138 * set the PLL_ON bit (see debug register 0x1f) to keep the PLL always
141 #define AT803X_MMD7_CLK25M 0x8016
142 #define AT803X_CLK_OUT_MASK GENMASK(4, 2)
143 #define AT803X_CLK_OUT_25MHZ_XTAL 0
144 #define AT803X_CLK_OUT_25MHZ_DSP 1
145 #define AT803X_CLK_OUT_50MHZ_PLL 2
146 #define AT803X_CLK_OUT_50MHZ_DSP 3
147 #define AT803X_CLK_OUT_62_5MHZ_PLL 4
148 #define AT803X_CLK_OUT_62_5MHZ_DSP 5
149 #define AT803X_CLK_OUT_125MHZ_PLL 6
150 #define AT803X_CLK_OUT_125MHZ_DSP 7
152 /* The AR8035 has another mask which is compatible with the AR8031/AR8033 mask
153 * but doesn't support choosing between XTAL/PLL and DSP.
155 #define AT8035_CLK_OUT_MASK GENMASK(4, 3)
157 #define AT803X_CLK_OUT_STRENGTH_MASK GENMASK(8, 7)
158 #define AT803X_CLK_OUT_STRENGTH_FULL 0
159 #define AT803X_CLK_OUT_STRENGTH_HALF 1
160 #define AT803X_CLK_OUT_STRENGTH_QUARTER 2
162 #define AT803X_DEFAULT_DOWNSHIFT 5
163 #define AT803X_MIN_DOWNSHIFT 2
164 #define AT803X_MAX_DOWNSHIFT 9
166 #define AT803X_MMD3_SMARTEEE_CTL1 0x805b
167 #define AT803X_MMD3_SMARTEEE_CTL2 0x805c
168 #define AT803X_MMD3_SMARTEEE_CTL3 0x805d
169 #define AT803X_MMD3_SMARTEEE_CTL3_LPI_EN BIT(8)
171 #define ATH9331_PHY_ID 0x004dd041
172 #define ATH8030_PHY_ID 0x004dd076
173 #define ATH8031_PHY_ID 0x004dd074
174 #define ATH8032_PHY_ID 0x004dd023
175 #define ATH8035_PHY_ID 0x004dd072
176 #define AT8030_PHY_ID_MASK 0xffffffef
178 #define QCA8081_PHY_ID 0x004dd101
180 #define QCA8327_A_PHY_ID 0x004dd033
181 #define QCA8327_B_PHY_ID 0x004dd034
182 #define QCA8337_PHY_ID 0x004dd036
183 #define QCA9561_PHY_ID 0x004dd042
184 #define QCA8K_PHY_ID_MASK 0xffffffff
186 #define QCA8K_DEVFLAGS_REVISION_MASK GENMASK(2, 0)
188 #define AT803X_PAGE_FIBER 0
189 #define AT803X_PAGE_COPPER 1
191 /* don't turn off internal PLL */
192 #define AT803X_KEEP_PLL_ENABLED BIT(0)
193 #define AT803X_DISABLE_SMARTEEE BIT(1)
195 /* disable hibernation mode */
196 #define AT803X_DISABLE_HIBERNATION_MODE BIT(2)
199 #define QCA808X_PHY_DEBUG_ADC_THRESHOLD 0x2c80
200 #define QCA808X_ADC_THRESHOLD_MASK GENMASK(7, 0)
201 #define QCA808X_ADC_THRESHOLD_80MV 0
202 #define QCA808X_ADC_THRESHOLD_100MV 0xf0
203 #define QCA808X_ADC_THRESHOLD_200MV 0x0f
204 #define QCA808X_ADC_THRESHOLD_300MV 0xff
207 #define QCA808X_PHY_MMD3_ADDR_CLD_CTRL7 0x8007
208 #define QCA808X_8023AZ_AFE_CTRL_MASK GENMASK(8, 4)
209 #define QCA808X_8023AZ_AFE_EN 0x90
212 #define QCA808X_PHY_MMD3_AZ_TRAINING_CTRL 0x8008
213 #define QCA808X_MMD3_AZ_TRAINING_VAL 0x1c32
215 #define QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB 0x8014
216 #define QCA808X_MSE_THRESHOLD_20DB_VALUE 0x529
218 #define QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB 0x800E
219 #define QCA808X_MSE_THRESHOLD_17DB_VALUE 0x341
221 #define QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB 0x801E
222 #define QCA808X_MSE_THRESHOLD_27DB_VALUE 0x419
224 #define QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB 0x8020
225 #define QCA808X_MSE_THRESHOLD_28DB_VALUE 0x341
227 #define QCA808X_PHY_MMD7_TOP_OPTION1 0x901c
228 #define QCA808X_TOP_OPTION1_DATA 0x0
230 #define QCA808X_PHY_MMD3_DEBUG_1 0xa100
231 #define QCA808X_MMD3_DEBUG_1_VALUE 0x9203
232 #define QCA808X_PHY_MMD3_DEBUG_2 0xa101
233 #define QCA808X_MMD3_DEBUG_2_VALUE 0x48ad
234 #define QCA808X_PHY_MMD3_DEBUG_3 0xa103
235 #define QCA808X_MMD3_DEBUG_3_VALUE 0x1698
236 #define QCA808X_PHY_MMD3_DEBUG_4 0xa105
237 #define QCA808X_MMD3_DEBUG_4_VALUE 0x8001
238 #define QCA808X_PHY_MMD3_DEBUG_5 0xa106
239 #define QCA808X_MMD3_DEBUG_5_VALUE 0x1111
240 #define QCA808X_PHY_MMD3_DEBUG_6 0xa011
241 #define QCA808X_MMD3_DEBUG_6_VALUE 0x5f85
243 /* master/slave seed config */
244 #define QCA808X_PHY_DEBUG_LOCAL_SEED 9
245 #define QCA808X_MASTER_SLAVE_SEED_ENABLE BIT(1)
246 #define QCA808X_MASTER_SLAVE_SEED_CFG GENMASK(12, 2)
247 #define QCA808X_MASTER_SLAVE_SEED_RANGE 0x32
249 /* Hibernation yields lower power consumpiton in contrast with normal operation mode.
250 * when the copper cable is unplugged, the PHY enters into hibernation mode in about 10s.
252 #define QCA808X_DBG_AN_TEST 0xb
253 #define QCA808X_HIBERNATION_EN BIT(15)
255 #define QCA808X_CDT_ENABLE_TEST BIT(15)
256 #define QCA808X_CDT_INTER_CHECK_DIS BIT(13)
257 #define QCA808X_CDT_LENGTH_UNIT BIT(10)
259 #define QCA808X_MMD3_CDT_STATUS 0x8064
260 #define QCA808X_MMD3_CDT_DIAG_PAIR_A 0x8065
261 #define QCA808X_MMD3_CDT_DIAG_PAIR_B 0x8066
262 #define QCA808X_MMD3_CDT_DIAG_PAIR_C 0x8067
263 #define QCA808X_MMD3_CDT_DIAG_PAIR_D 0x8068
264 #define QCA808X_CDT_DIAG_LENGTH GENMASK(7, 0)
266 #define QCA808X_CDT_CODE_PAIR_A GENMASK(15, 12)
267 #define QCA808X_CDT_CODE_PAIR_B GENMASK(11, 8)
268 #define QCA808X_CDT_CODE_PAIR_C GENMASK(7, 4)
269 #define QCA808X_CDT_CODE_PAIR_D GENMASK(3, 0)
270 #define QCA808X_CDT_STATUS_STAT_FAIL 0
271 #define QCA808X_CDT_STATUS_STAT_NORMAL 1
272 #define QCA808X_CDT_STATUS_STAT_OPEN 2
273 #define QCA808X_CDT_STATUS_STAT_SHORT 3
275 MODULE_DESCRIPTION("Qualcomm Atheros AR803x and QCA808X PHY driver");
276 MODULE_AUTHOR("Matus Ujhelyi");
277 MODULE_LICENSE("GPL");
279 enum stat_access_type {
284 struct at803x_hw_stat {
288 enum stat_access_type access_type;
291 static struct at803x_hw_stat at803x_hw_stats[] = {
292 { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
293 { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
294 { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
301 u8 smarteee_lpi_tw_1g;
302 u8 smarteee_lpi_tw_100m;
305 struct regulator_dev *vddio_rdev;
306 struct regulator_dev *vddh_rdev;
307 struct regulator *vddio;
308 u64 stats[ARRAY_SIZE(at803x_hw_stats)];
311 struct at803x_context {
320 static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data)
324 ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
328 return phy_write(phydev, AT803X_DEBUG_DATA, data);
331 static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
335 ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
339 return phy_read(phydev, AT803X_DEBUG_DATA);
342 static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
348 ret = at803x_debug_reg_read(phydev, reg);
356 return phy_write(phydev, AT803X_DEBUG_DATA, val);
359 static int at803x_write_page(struct phy_device *phydev, int page)
364 if (page == AT803X_PAGE_COPPER) {
365 set = AT803X_BT_BX_REG_SEL;
369 mask = AT803X_BT_BX_REG_SEL;
372 return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set);
375 static int at803x_read_page(struct phy_device *phydev)
377 int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG);
382 if (ccr & AT803X_BT_BX_REG_SEL)
383 return AT803X_PAGE_COPPER;
385 return AT803X_PAGE_FIBER;
388 static int at803x_enable_rx_delay(struct phy_device *phydev)
390 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0,
391 AT803X_DEBUG_RX_CLK_DLY_EN);
394 static int at803x_enable_tx_delay(struct phy_device *phydev)
396 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0,
397 AT803X_DEBUG_TX_CLK_DLY_EN);
400 static int at803x_disable_rx_delay(struct phy_device *phydev)
402 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
403 AT803X_DEBUG_RX_CLK_DLY_EN, 0);
406 static int at803x_disable_tx_delay(struct phy_device *phydev)
408 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE,
409 AT803X_DEBUG_TX_CLK_DLY_EN, 0);
412 /* save relevant PHY registers to private copy */
413 static void at803x_context_save(struct phy_device *phydev,
414 struct at803x_context *context)
416 context->bmcr = phy_read(phydev, MII_BMCR);
417 context->advertise = phy_read(phydev, MII_ADVERTISE);
418 context->control1000 = phy_read(phydev, MII_CTRL1000);
419 context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE);
420 context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED);
421 context->led_control = phy_read(phydev, AT803X_LED_CONTROL);
424 /* restore relevant PHY registers from private copy */
425 static void at803x_context_restore(struct phy_device *phydev,
426 const struct at803x_context *context)
428 phy_write(phydev, MII_BMCR, context->bmcr);
429 phy_write(phydev, MII_ADVERTISE, context->advertise);
430 phy_write(phydev, MII_CTRL1000, context->control1000);
431 phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable);
432 phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed);
433 phy_write(phydev, AT803X_LED_CONTROL, context->led_control);
436 static int at803x_set_wol(struct phy_device *phydev,
437 struct ethtool_wolinfo *wol)
439 int ret, irq_enabled;
441 if (wol->wolopts & WAKE_MAGIC) {
442 struct net_device *ndev = phydev->attached_dev;
445 static const unsigned int offsets[] = {
446 AT803X_LOC_MAC_ADDR_32_47_OFFSET,
447 AT803X_LOC_MAC_ADDR_16_31_OFFSET,
448 AT803X_LOC_MAC_ADDR_0_15_OFFSET,
454 mac = (const u8 *) ndev->dev_addr;
456 if (!is_valid_ether_addr(mac))
459 for (i = 0; i < 3; i++)
460 phy_write_mmd(phydev, MDIO_MMD_PCS, offsets[i],
461 mac[(i * 2) + 1] | (mac[(i * 2)] << 8));
463 /* Enable WOL function */
464 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL,
468 /* Enable WOL interrupt */
469 ret = phy_modify(phydev, AT803X_INTR_ENABLE, 0, AT803X_INTR_ENABLE_WOL);
473 /* Disable WoL function */
474 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL,
478 /* Disable WOL interrupt */
479 ret = phy_modify(phydev, AT803X_INTR_ENABLE, AT803X_INTR_ENABLE_WOL, 0);
484 /* Clear WOL status */
485 ret = phy_read(phydev, AT803X_INTR_STATUS);
489 /* Check if there are other interrupts except for WOL triggered when PHY is
490 * in interrupt mode, only the interrupts enabled by AT803X_INTR_ENABLE can
491 * be passed up to the interrupt PIN.
493 irq_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
497 irq_enabled &= ~AT803X_INTR_ENABLE_WOL;
498 if (ret & irq_enabled && !phy_polling_mode(phydev))
499 phy_trigger_machine(phydev);
504 static void at803x_get_wol(struct phy_device *phydev,
505 struct ethtool_wolinfo *wol)
509 wol->supported = WAKE_MAGIC;
512 value = phy_read_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL);
516 if (value & AT803X_WOL_EN)
517 wol->wolopts |= WAKE_MAGIC;
520 static int at803x_get_sset_count(struct phy_device *phydev)
522 return ARRAY_SIZE(at803x_hw_stats);
525 static void at803x_get_strings(struct phy_device *phydev, u8 *data)
529 for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) {
530 strscpy(data + i * ETH_GSTRING_LEN,
531 at803x_hw_stats[i].string, ETH_GSTRING_LEN);
535 static u64 at803x_get_stat(struct phy_device *phydev, int i)
537 struct at803x_hw_stat stat = at803x_hw_stats[i];
538 struct at803x_priv *priv = phydev->priv;
542 if (stat.access_type == MMD)
543 val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg);
545 val = phy_read(phydev, stat.reg);
550 val = val & stat.mask;
551 priv->stats[i] += val;
552 ret = priv->stats[i];
558 static void at803x_get_stats(struct phy_device *phydev,
559 struct ethtool_stats *stats, u64 *data)
563 for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++)
564 data[i] = at803x_get_stat(phydev, i);
567 static int at803x_suspend(struct phy_device *phydev)
572 value = phy_read(phydev, AT803X_INTR_ENABLE);
573 wol_enabled = value & AT803X_INTR_ENABLE_WOL;
576 value = BMCR_ISOLATE;
580 phy_modify(phydev, MII_BMCR, 0, value);
585 static int at803x_resume(struct phy_device *phydev)
587 return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
590 static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
591 unsigned int selector)
593 struct phy_device *phydev = rdev_get_drvdata(rdev);
596 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
597 0, AT803X_DEBUG_RGMII_1V8);
599 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
600 AT803X_DEBUG_RGMII_1V8, 0);
603 static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
605 struct phy_device *phydev = rdev_get_drvdata(rdev);
608 val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
612 return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
615 static const struct regulator_ops vddio_regulator_ops = {
616 .list_voltage = regulator_list_voltage_table,
617 .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel,
618 .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel,
621 static const unsigned int vddio_voltage_table[] = {
626 static const struct regulator_desc vddio_desc = {
628 .of_match = of_match_ptr("vddio-regulator"),
629 .n_voltages = ARRAY_SIZE(vddio_voltage_table),
630 .volt_table = vddio_voltage_table,
631 .ops = &vddio_regulator_ops,
632 .type = REGULATOR_VOLTAGE,
633 .owner = THIS_MODULE,
636 static const struct regulator_ops vddh_regulator_ops = {
639 static const struct regulator_desc vddh_desc = {
641 .of_match = of_match_ptr("vddh-regulator"),
644 .ops = &vddh_regulator_ops,
645 .type = REGULATOR_VOLTAGE,
646 .owner = THIS_MODULE,
649 static int at8031_register_regulators(struct phy_device *phydev)
651 struct at803x_priv *priv = phydev->priv;
652 struct device *dev = &phydev->mdio.dev;
653 struct regulator_config config = { };
656 config.driver_data = phydev;
658 priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
659 if (IS_ERR(priv->vddio_rdev)) {
660 phydev_err(phydev, "failed to register VDDIO regulator\n");
661 return PTR_ERR(priv->vddio_rdev);
664 priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
665 if (IS_ERR(priv->vddh_rdev)) {
666 phydev_err(phydev, "failed to register VDDH regulator\n");
667 return PTR_ERR(priv->vddh_rdev);
673 static int at803x_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
675 struct phy_device *phydev = upstream;
676 __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support);
677 __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
678 DECLARE_PHY_INTERFACE_MASK(interfaces);
679 phy_interface_t iface;
681 linkmode_zero(phy_support);
682 phylink_set(phy_support, 1000baseX_Full);
683 phylink_set(phy_support, 1000baseT_Full);
684 phylink_set(phy_support, Autoneg);
685 phylink_set(phy_support, Pause);
686 phylink_set(phy_support, Asym_Pause);
688 linkmode_zero(sfp_support);
689 sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
690 /* Some modules support 10G modes as well as others we support.
691 * Mask out non-supported modes so the correct interface is picked.
693 linkmode_and(sfp_support, phy_support, sfp_support);
695 if (linkmode_empty(sfp_support)) {
696 dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
700 iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
702 /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes
703 * interface for use with SFP modules.
704 * However, some copper modules detected as having a preferred SGMII
705 * interface do default to and function in 1000Base-X mode, so just
706 * print a warning and allow such modules, as they may have some chance
709 if (iface == PHY_INTERFACE_MODE_SGMII)
710 dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n");
711 else if (iface != PHY_INTERFACE_MODE_1000BASEX)
717 static const struct sfp_upstream_ops at803x_sfp_ops = {
718 .attach = phy_sfp_attach,
719 .detach = phy_sfp_detach,
720 .module_insert = at803x_sfp_insert,
723 static int at803x_parse_dt(struct phy_device *phydev)
725 struct device_node *node = phydev->mdio.dev.of_node;
726 struct at803x_priv *priv = phydev->priv;
727 u32 freq, strength, tw;
731 if (!IS_ENABLED(CONFIG_OF_MDIO))
734 if (of_property_read_bool(node, "qca,disable-smarteee"))
735 priv->flags |= AT803X_DISABLE_SMARTEEE;
737 if (of_property_read_bool(node, "qca,disable-hibernation-mode"))
738 priv->flags |= AT803X_DISABLE_HIBERNATION_MODE;
740 if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) {
741 if (!tw || tw > 255) {
742 phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n");
745 priv->smarteee_lpi_tw_1g = tw;
748 if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) {
749 if (!tw || tw > 255) {
750 phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n");
753 priv->smarteee_lpi_tw_100m = tw;
756 ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq);
760 sel = AT803X_CLK_OUT_25MHZ_XTAL;
763 sel = AT803X_CLK_OUT_50MHZ_PLL;
766 sel = AT803X_CLK_OUT_62_5MHZ_PLL;
769 sel = AT803X_CLK_OUT_125MHZ_PLL;
772 phydev_err(phydev, "invalid qca,clk-out-frequency\n");
776 priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel);
777 priv->clk_25m_mask |= AT803X_CLK_OUT_MASK;
779 /* Fixup for the AR8030/AR8035. This chip has another mask and
780 * doesn't support the DSP reference. Eg. the lowest bit of the
781 * mask. The upper two bits select the same frequencies. Mask
782 * the lowest bit here.
785 * There was no datasheet for the AR8030 available so this is
786 * just a guess. But the AR8035 is listed as pin compatible
787 * to the AR8030 so there might be a good chance it works on
790 if (phydev->drv->phy_id == ATH8030_PHY_ID ||
791 phydev->drv->phy_id == ATH8035_PHY_ID) {
792 priv->clk_25m_reg &= AT8035_CLK_OUT_MASK;
793 priv->clk_25m_mask &= AT8035_CLK_OUT_MASK;
797 ret = of_property_read_u32(node, "qca,clk-out-strength", &strength);
799 priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK;
801 case AR803X_STRENGTH_FULL:
802 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL;
804 case AR803X_STRENGTH_HALF:
805 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF;
807 case AR803X_STRENGTH_QUARTER:
808 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER;
811 phydev_err(phydev, "invalid qca,clk-out-strength\n");
816 /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping
819 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
820 if (of_property_read_bool(node, "qca,keep-pll-enabled"))
821 priv->flags |= AT803X_KEEP_PLL_ENABLED;
823 ret = at8031_register_regulators(phydev);
827 priv->vddio = devm_regulator_get_optional(&phydev->mdio.dev,
829 if (IS_ERR(priv->vddio)) {
830 phydev_err(phydev, "failed to get VDDIO regulator\n");
831 return PTR_ERR(priv->vddio);
834 /* Only AR8031/8033 support 1000Base-X for SFP modules */
835 ret = phy_sfp_probe(phydev, &at803x_sfp_ops);
843 static int at803x_probe(struct phy_device *phydev)
845 struct device *dev = &phydev->mdio.dev;
846 struct at803x_priv *priv;
849 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
855 ret = at803x_parse_dt(phydev);
860 ret = regulator_enable(priv->vddio);
865 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
866 int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
868 struct ethtool_wolinfo wol = {
876 mode_cfg = ccr & AT803X_MODE_CFG_MASK;
879 case AT803X_MODE_CFG_BX1000_RGMII_50OHM:
880 case AT803X_MODE_CFG_BX1000_RGMII_75OHM:
881 priv->is_1000basex = true;
883 case AT803X_MODE_CFG_FX100_RGMII_50OHM:
884 case AT803X_MODE_CFG_FX100_RGMII_75OHM:
885 priv->is_fiber = true;
889 /* Disable WOL by default */
890 ret = at803x_set_wol(phydev, &wol);
892 phydev_err(phydev, "failed to disable WOL on probe: %d\n", ret);
901 regulator_disable(priv->vddio);
906 static void at803x_remove(struct phy_device *phydev)
908 struct at803x_priv *priv = phydev->priv;
911 regulator_disable(priv->vddio);
914 static int at803x_get_features(struct phy_device *phydev)
916 struct at803x_priv *priv = phydev->priv;
919 err = genphy_read_abilities(phydev);
923 if (phydev->drv->phy_id == QCA8081_PHY_ID) {
924 err = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_NG_EXTABLE);
928 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported,
929 err & MDIO_PMA_NG_EXTABLE_2_5GBT);
932 if (phydev->drv->phy_id != ATH8031_PHY_ID)
935 /* AR8031/AR8033 have different status registers
936 * for copper and fiber operation. However, the
937 * extended status register is the same for both
940 * As a result of that, ESTATUS_1000_XFULL is set
941 * to 1 even when operating in copper TP mode.
943 * Remove this mode from the supported link modes
944 * when not operating in 1000BaseX mode.
946 if (!priv->is_1000basex)
947 linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
953 static int at803x_smarteee_config(struct phy_device *phydev)
955 struct at803x_priv *priv = phydev->priv;
956 u16 mask = 0, val = 0;
959 if (priv->flags & AT803X_DISABLE_SMARTEEE)
960 return phy_modify_mmd(phydev, MDIO_MMD_PCS,
961 AT803X_MMD3_SMARTEEE_CTL3,
962 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0);
964 if (priv->smarteee_lpi_tw_1g) {
966 val |= priv->smarteee_lpi_tw_1g << 8;
968 if (priv->smarteee_lpi_tw_100m) {
970 val |= priv->smarteee_lpi_tw_100m;
975 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1,
980 return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3,
981 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN,
982 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN);
985 static int at803x_clk_out_config(struct phy_device *phydev)
987 struct at803x_priv *priv = phydev->priv;
989 if (!priv->clk_25m_mask)
992 return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M,
993 priv->clk_25m_mask, priv->clk_25m_reg);
996 static int at8031_pll_config(struct phy_device *phydev)
998 struct at803x_priv *priv = phydev->priv;
1000 /* The default after hardware reset is PLL OFF. After a soft reset, the
1001 * values are retained.
1003 if (priv->flags & AT803X_KEEP_PLL_ENABLED)
1004 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
1005 0, AT803X_DEBUG_PLL_ON);
1007 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
1008 AT803X_DEBUG_PLL_ON, 0);
1011 static int at803x_hibernation_mode_config(struct phy_device *phydev)
1013 struct at803x_priv *priv = phydev->priv;
1015 /* The default after hardware reset is hibernation mode enabled. After
1016 * software reset, the value is retained.
1018 if (!(priv->flags & AT803X_DISABLE_HIBERNATION_MODE))
1021 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
1022 AT803X_DEBUG_HIB_CTRL_PS_HIB_EN, 0);
1025 static int at803x_config_init(struct phy_device *phydev)
1027 struct at803x_priv *priv = phydev->priv;
1030 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
1031 /* Some bootloaders leave the fiber page selected.
1032 * Switch to the appropriate page (fiber or copper), as otherwise we
1033 * read the PHY capabilities from the wrong page.
1035 phy_lock_mdio_bus(phydev);
1036 ret = at803x_write_page(phydev,
1037 priv->is_fiber ? AT803X_PAGE_FIBER :
1038 AT803X_PAGE_COPPER);
1039 phy_unlock_mdio_bus(phydev);
1043 ret = at8031_pll_config(phydev);
1048 /* The RX and TX delay default is:
1049 * after HW reset: RX delay enabled and TX delay disabled
1050 * after SW reset: RX delay enabled, while TX delay retains the
1051 * value before reset.
1053 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
1054 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
1055 ret = at803x_enable_rx_delay(phydev);
1057 ret = at803x_disable_rx_delay(phydev);
1061 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
1062 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
1063 ret = at803x_enable_tx_delay(phydev);
1065 ret = at803x_disable_tx_delay(phydev);
1069 ret = at803x_smarteee_config(phydev);
1073 ret = at803x_clk_out_config(phydev);
1077 ret = at803x_hibernation_mode_config(phydev);
1081 /* Ar803x extended next page bit is enabled by default. Cisco
1082 * multigig switches read this bit and attempt to negotiate 10Gbps
1083 * rates even if the next page bit is disabled. This is incorrect
1084 * behaviour but we still need to accommodate it. XNP is only needed
1085 * for 10Gbps support, so disable XNP.
1087 return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0);
1090 static int at803x_ack_interrupt(struct phy_device *phydev)
1094 err = phy_read(phydev, AT803X_INTR_STATUS);
1096 return (err < 0) ? err : 0;
1099 static int at803x_config_intr(struct phy_device *phydev)
1101 struct at803x_priv *priv = phydev->priv;
1105 value = phy_read(phydev, AT803X_INTR_ENABLE);
1107 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1108 /* Clear any pending interrupts */
1109 err = at803x_ack_interrupt(phydev);
1113 value |= AT803X_INTR_ENABLE_AUTONEG_ERR;
1114 value |= AT803X_INTR_ENABLE_SPEED_CHANGED;
1115 value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED;
1116 value |= AT803X_INTR_ENABLE_LINK_FAIL;
1117 value |= AT803X_INTR_ENABLE_LINK_SUCCESS;
1118 if (priv->is_fiber) {
1119 value |= AT803X_INTR_ENABLE_LINK_FAIL_BX;
1120 value |= AT803X_INTR_ENABLE_LINK_SUCCESS_BX;
1123 err = phy_write(phydev, AT803X_INTR_ENABLE, value);
1125 err = phy_write(phydev, AT803X_INTR_ENABLE, 0);
1129 /* Clear any pending interrupts */
1130 err = at803x_ack_interrupt(phydev);
1136 static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev)
1138 int irq_status, int_enabled;
1140 irq_status = phy_read(phydev, AT803X_INTR_STATUS);
1141 if (irq_status < 0) {
1146 /* Read the current enabled interrupts */
1147 int_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
1148 if (int_enabled < 0) {
1153 /* See if this was one of our enabled interrupts */
1154 if (!(irq_status & int_enabled))
1157 phy_trigger_machine(phydev);
1162 static void at803x_link_change_notify(struct phy_device *phydev)
1165 * Conduct a hardware reset for AT8030 every time a link loss is
1166 * signalled. This is necessary to circumvent a hardware bug that
1167 * occurs when the cable is unplugged while TX packets are pending
1168 * in the FIFO. In such cases, the FIFO enters an error mode it
1169 * cannot recover from by software.
1171 if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) {
1172 struct at803x_context context;
1174 at803x_context_save(phydev, &context);
1176 phy_device_reset(phydev, 1);
1178 phy_device_reset(phydev, 0);
1181 at803x_context_restore(phydev, &context);
1183 phydev_dbg(phydev, "%s(): phy was reset\n", __func__);
1187 static int at803x_read_specific_status(struct phy_device *phydev)
1191 /* Read the AT8035 PHY-Specific Status register, which indicates the
1192 * speed and duplex that the PHY is actually using, irrespective of
1193 * whether we are in autoneg mode or not.
1195 ss = phy_read(phydev, AT803X_SPECIFIC_STATUS);
1199 if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) {
1202 sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL);
1206 /* qca8081 takes the different bits for speed value from at803x */
1207 if (phydev->drv->phy_id == QCA8081_PHY_ID)
1208 speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss);
1210 speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss);
1213 case AT803X_SS_SPEED_10:
1214 phydev->speed = SPEED_10;
1216 case AT803X_SS_SPEED_100:
1217 phydev->speed = SPEED_100;
1219 case AT803X_SS_SPEED_1000:
1220 phydev->speed = SPEED_1000;
1222 case QCA808X_SS_SPEED_2500:
1223 phydev->speed = SPEED_2500;
1226 if (ss & AT803X_SS_DUPLEX)
1227 phydev->duplex = DUPLEX_FULL;
1229 phydev->duplex = DUPLEX_HALF;
1231 if (ss & AT803X_SS_MDIX)
1232 phydev->mdix = ETH_TP_MDI_X;
1234 phydev->mdix = ETH_TP_MDI;
1236 switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) {
1237 case AT803X_SFC_MANUAL_MDI:
1238 phydev->mdix_ctrl = ETH_TP_MDI;
1240 case AT803X_SFC_MANUAL_MDIX:
1241 phydev->mdix_ctrl = ETH_TP_MDI_X;
1243 case AT803X_SFC_AUTOMATIC_CROSSOVER:
1244 phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
1252 static int at803x_read_status(struct phy_device *phydev)
1254 struct at803x_priv *priv = phydev->priv;
1255 int err, old_link = phydev->link;
1257 if (priv->is_1000basex)
1258 return genphy_c37_read_status(phydev);
1260 /* Update the link, but return if there was an error */
1261 err = genphy_update_link(phydev);
1265 /* why bother the PHY if nothing can have changed */
1266 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
1269 phydev->speed = SPEED_UNKNOWN;
1270 phydev->duplex = DUPLEX_UNKNOWN;
1272 phydev->asym_pause = 0;
1274 err = genphy_read_lpa(phydev);
1278 err = at803x_read_specific_status(phydev);
1282 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
1283 phy_resolve_aneg_pause(phydev);
1288 static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl)
1294 val = AT803X_SFC_MANUAL_MDI;
1297 val = AT803X_SFC_MANUAL_MDIX;
1299 case ETH_TP_MDI_AUTO:
1300 val = AT803X_SFC_AUTOMATIC_CROSSOVER;
1306 return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL,
1307 AT803X_SFC_MDI_CROSSOVER_MODE_M,
1308 FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val));
1311 static int at803x_config_aneg(struct phy_device *phydev)
1313 struct at803x_priv *priv = phydev->priv;
1316 ret = at803x_config_mdix(phydev, phydev->mdix_ctrl);
1320 /* Changes of the midx bits are disruptive to the normal operation;
1321 * therefore any changes to these registers must be followed by a
1322 * software reset to take effect.
1325 ret = genphy_soft_reset(phydev);
1330 if (priv->is_1000basex)
1331 return genphy_c37_config_aneg(phydev);
1333 /* Do not restart auto-negotiation by setting ret to 0 defautly,
1334 * when calling __genphy_config_aneg later.
1338 if (phydev->drv->phy_id == QCA8081_PHY_ID) {
1341 /* The reg MII_BMCR also needs to be configured for force mode, the
1342 * genphy_config_aneg is also needed.
1344 if (phydev->autoneg == AUTONEG_DISABLE)
1345 genphy_c45_pma_setup_forced(phydev);
1347 if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising))
1348 phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G;
1350 ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
1351 MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl);
1356 return __genphy_config_aneg(phydev, ret);
1359 static int at803x_get_downshift(struct phy_device *phydev, u8 *d)
1363 val = phy_read(phydev, AT803X_SMART_SPEED);
1367 if (val & AT803X_SMART_SPEED_ENABLE)
1368 *d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2;
1370 *d = DOWNSHIFT_DEV_DISABLE;
1375 static int at803x_set_downshift(struct phy_device *phydev, u8 cnt)
1381 case DOWNSHIFT_DEV_DEFAULT_COUNT:
1382 cnt = AT803X_DEFAULT_DOWNSHIFT;
1384 case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT:
1385 set = AT803X_SMART_SPEED_ENABLE |
1386 AT803X_SMART_SPEED_BYPASS_TIMER |
1387 FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2);
1388 mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK;
1390 case DOWNSHIFT_DEV_DISABLE:
1392 mask = AT803X_SMART_SPEED_ENABLE |
1393 AT803X_SMART_SPEED_BYPASS_TIMER;
1399 ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set);
1401 /* After changing the smart speed settings, we need to perform a
1402 * software reset, use phy_init_hw() to make sure we set the
1403 * reapply any values which might got lost during software reset.
1406 ret = phy_init_hw(phydev);
1411 static int at803x_get_tunable(struct phy_device *phydev,
1412 struct ethtool_tunable *tuna, void *data)
1415 case ETHTOOL_PHY_DOWNSHIFT:
1416 return at803x_get_downshift(phydev, data);
1422 static int at803x_set_tunable(struct phy_device *phydev,
1423 struct ethtool_tunable *tuna, const void *data)
1426 case ETHTOOL_PHY_DOWNSHIFT:
1427 return at803x_set_downshift(phydev, *(const u8 *)data);
1433 static int at803x_cable_test_result_trans(u16 status)
1435 switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
1436 case AT803X_CDT_STATUS_STAT_NORMAL:
1437 return ETHTOOL_A_CABLE_RESULT_CODE_OK;
1438 case AT803X_CDT_STATUS_STAT_SHORT:
1439 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
1440 case AT803X_CDT_STATUS_STAT_OPEN:
1441 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
1442 case AT803X_CDT_STATUS_STAT_FAIL:
1444 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
1448 static bool at803x_cdt_test_failed(u16 status)
1450 return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) ==
1451 AT803X_CDT_STATUS_STAT_FAIL;
1454 static bool at803x_cdt_fault_length_valid(u16 status)
1456 switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
1457 case AT803X_CDT_STATUS_STAT_OPEN:
1458 case AT803X_CDT_STATUS_STAT_SHORT:
1464 static int at803x_cdt_fault_length(u16 status)
1468 /* According to the datasheet the distance to the fault is
1469 * DELTA_TIME * 0.824 meters.
1471 * The author suspect the correct formula is:
1473 * fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2
1475 * where c is the speed of light, VF is the velocity factor of
1476 * the twisted pair cable, 125MHz the counter frequency and
1477 * we need to divide by 2 because the hardware will measure the
1478 * round trip time to the fault and back to the PHY.
1480 * With a VF of 0.69 we get the factor 0.824 mentioned in the
1483 dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status);
1485 return (dt * 824) / 10;
1488 static int at803x_cdt_start(struct phy_device *phydev, int pair)
1492 /* qca8081 takes the different bit 15 to enable CDT test */
1493 if (phydev->drv->phy_id == QCA8081_PHY_ID)
1494 cdt = QCA808X_CDT_ENABLE_TEST |
1495 QCA808X_CDT_LENGTH_UNIT |
1496 QCA808X_CDT_INTER_CHECK_DIS;
1498 cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
1499 AT803X_CDT_ENABLE_TEST;
1501 return phy_write(phydev, AT803X_CDT, cdt);
1504 static int at803x_cdt_wait_for_completion(struct phy_device *phydev)
1509 if (phydev->drv->phy_id == QCA8081_PHY_ID)
1510 cdt_en = QCA808X_CDT_ENABLE_TEST;
1512 cdt_en = AT803X_CDT_ENABLE_TEST;
1514 /* One test run takes about 25ms */
1515 ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
1517 30000, 100000, true);
1519 return ret < 0 ? ret : 0;
1522 static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair)
1524 static const int ethtool_pair[] = {
1525 ETHTOOL_A_CABLE_PAIR_A,
1526 ETHTOOL_A_CABLE_PAIR_B,
1527 ETHTOOL_A_CABLE_PAIR_C,
1528 ETHTOOL_A_CABLE_PAIR_D,
1532 ret = at803x_cdt_start(phydev, pair);
1536 ret = at803x_cdt_wait_for_completion(phydev);
1540 val = phy_read(phydev, AT803X_CDT_STATUS);
1544 if (at803x_cdt_test_failed(val))
1547 ethnl_cable_test_result(phydev, ethtool_pair[pair],
1548 at803x_cable_test_result_trans(val));
1550 if (at803x_cdt_fault_length_valid(val))
1551 ethnl_cable_test_fault_length(phydev, ethtool_pair[pair],
1552 at803x_cdt_fault_length(val));
1557 static int at803x_cable_test_get_status(struct phy_device *phydev,
1560 unsigned long pair_mask;
1564 if (phydev->phy_id == ATH9331_PHY_ID ||
1565 phydev->phy_id == ATH8032_PHY_ID ||
1566 phydev->phy_id == QCA9561_PHY_ID)
1573 /* According to the datasheet the CDT can be performed when
1574 * there is no link partner or when the link partner is
1575 * auto-negotiating. Starting the test will restart the AN
1576 * automatically. It seems that doing this repeatedly we will
1577 * get a slot where our link partner won't disturb our
1580 while (pair_mask && retries--) {
1581 for_each_set_bit(pair, &pair_mask, 4) {
1582 ret = at803x_cable_test_one_pair(phydev, pair);
1586 clear_bit(pair, &pair_mask);
1597 static int at803x_cable_test_start(struct phy_device *phydev)
1599 /* Enable auto-negotiation, but advertise no capabilities, no link
1600 * will be established. A restart of the auto-negotiation is not
1601 * required, because the cable test will automatically break the link.
1603 phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
1604 phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
1605 if (phydev->phy_id != ATH9331_PHY_ID &&
1606 phydev->phy_id != ATH8032_PHY_ID &&
1607 phydev->phy_id != QCA9561_PHY_ID)
1608 phy_write(phydev, MII_CTRL1000, 0);
1610 /* we do all the (time consuming) work later */
1614 static int qca83xx_config_init(struct phy_device *phydev)
1618 switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK;
1620 switch (switch_revision) {
1622 /* For 100M waveform */
1623 at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea);
1624 /* Turn on Gigabit clock */
1625 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0);
1629 phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0);
1632 phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f);
1633 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860);
1634 at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46);
1635 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000);
1639 /* QCA8327 require DAC amplitude adjustment for 100m set to +6%.
1640 * Disable on init and enable only with 100m speed following
1641 * qca original source code.
1643 if (phydev->drv->phy_id == QCA8327_A_PHY_ID ||
1644 phydev->drv->phy_id == QCA8327_B_PHY_ID)
1645 at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
1646 QCA8327_DEBUG_MANU_CTRL_EN, 0);
1648 /* Following original QCA sourcecode set port to prefer master */
1649 phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER);
1654 static void qca83xx_link_change_notify(struct phy_device *phydev)
1656 /* QCA8337 doesn't require DAC Amplitude adjustement */
1657 if (phydev->drv->phy_id == QCA8337_PHY_ID)
1660 /* Set DAC Amplitude adjustment to +6% for 100m on link running */
1661 if (phydev->state == PHY_RUNNING) {
1662 if (phydev->speed == SPEED_100)
1663 at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
1664 QCA8327_DEBUG_MANU_CTRL_EN,
1665 QCA8327_DEBUG_MANU_CTRL_EN);
1667 /* Reset DAC Amplitude adjustment */
1668 at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
1669 QCA8327_DEBUG_MANU_CTRL_EN, 0);
1673 static int qca83xx_resume(struct phy_device *phydev)
1677 /* Skip reset if not suspended */
1678 if (!phydev->suspended)
1681 /* Reinit the port, reset values set by suspend */
1682 qca83xx_config_init(phydev);
1684 /* Reset the port on port resume */
1685 phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
1687 /* On resume from suspend the switch execute a reset and
1688 * restart auto-negotiation. Wait for reset to complete.
1690 ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET),
1691 50000, 600000, true);
1700 static int qca83xx_suspend(struct phy_device *phydev)
1704 /* Only QCA8337 support actual suspend.
1705 * QCA8327 cause port unreliability when phy suspend
1708 if (phydev->drv->phy_id == QCA8337_PHY_ID) {
1709 genphy_suspend(phydev);
1711 mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX);
1712 phy_modify(phydev, MII_BMCR, mask, 0);
1715 at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN,
1716 AT803X_DEBUG_GATE_CLK_IN1000, 0);
1718 at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
1719 AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE |
1720 AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0);
1725 static int qca808x_phy_fast_retrain_config(struct phy_device *phydev)
1729 /* Enable fast retrain */
1730 ret = genphy_c45_fast_retrain(phydev, true);
1734 phy_write_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_TOP_OPTION1,
1735 QCA808X_TOP_OPTION1_DATA);
1736 phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB,
1737 QCA808X_MSE_THRESHOLD_20DB_VALUE);
1738 phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB,
1739 QCA808X_MSE_THRESHOLD_17DB_VALUE);
1740 phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB,
1741 QCA808X_MSE_THRESHOLD_27DB_VALUE);
1742 phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB,
1743 QCA808X_MSE_THRESHOLD_28DB_VALUE);
1744 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_1,
1745 QCA808X_MMD3_DEBUG_1_VALUE);
1746 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_4,
1747 QCA808X_MMD3_DEBUG_4_VALUE);
1748 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_5,
1749 QCA808X_MMD3_DEBUG_5_VALUE);
1750 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_3,
1751 QCA808X_MMD3_DEBUG_3_VALUE);
1752 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_6,
1753 QCA808X_MMD3_DEBUG_6_VALUE);
1754 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_2,
1755 QCA808X_MMD3_DEBUG_2_VALUE);
1760 static int qca808x_phy_ms_random_seed_set(struct phy_device *phydev)
1762 u16 seed_value = get_random_u32_below(QCA808X_MASTER_SLAVE_SEED_RANGE);
1764 return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED,
1765 QCA808X_MASTER_SLAVE_SEED_CFG,
1766 FIELD_PREP(QCA808X_MASTER_SLAVE_SEED_CFG, seed_value));
1769 static int qca808x_phy_ms_seed_enable(struct phy_device *phydev, bool enable)
1771 u16 seed_enable = 0;
1774 seed_enable = QCA808X_MASTER_SLAVE_SEED_ENABLE;
1776 return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED,
1777 QCA808X_MASTER_SLAVE_SEED_ENABLE, seed_enable);
1780 static int qca808x_config_init(struct phy_device *phydev)
1784 /* Active adc&vga on 802.3az for the link 1000M and 100M */
1785 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_ADDR_CLD_CTRL7,
1786 QCA808X_8023AZ_AFE_CTRL_MASK, QCA808X_8023AZ_AFE_EN);
1790 /* Adjust the threshold on 802.3az for the link 1000M */
1791 ret = phy_write_mmd(phydev, MDIO_MMD_PCS,
1792 QCA808X_PHY_MMD3_AZ_TRAINING_CTRL, QCA808X_MMD3_AZ_TRAINING_VAL);
1796 /* Config the fast retrain for the link 2500M */
1797 ret = qca808x_phy_fast_retrain_config(phydev);
1801 /* Configure lower ramdom seed to make phy linked as slave mode */
1802 ret = qca808x_phy_ms_random_seed_set(phydev);
1807 ret = qca808x_phy_ms_seed_enable(phydev, true);
1811 /* Configure adc threshold as 100mv for the link 10M */
1812 return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD,
1813 QCA808X_ADC_THRESHOLD_MASK, QCA808X_ADC_THRESHOLD_100MV);
1816 static int qca808x_read_status(struct phy_device *phydev)
1820 ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
1824 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising,
1825 ret & MDIO_AN_10GBT_STAT_LP2_5G);
1827 ret = genphy_read_status(phydev);
1831 ret = at803x_read_specific_status(phydev);
1836 if (phydev->speed == SPEED_2500)
1837 phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
1839 phydev->interface = PHY_INTERFACE_MODE_SGMII;
1841 /* generate seed as a lower random value to make PHY linked as SLAVE easily,
1842 * except for master/slave configuration fault detected.
1843 * the reason for not putting this code into the function link_change_notify is
1844 * the corner case where the link partner is also the qca8081 PHY and the seed
1845 * value is configured as the same value, the link can't be up and no link change
1848 if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR) {
1849 qca808x_phy_ms_seed_enable(phydev, false);
1851 qca808x_phy_ms_random_seed_set(phydev);
1852 qca808x_phy_ms_seed_enable(phydev, true);
1859 static int qca808x_soft_reset(struct phy_device *phydev)
1863 ret = genphy_soft_reset(phydev);
1867 return qca808x_phy_ms_seed_enable(phydev, true);
1870 static bool qca808x_cdt_fault_length_valid(int cdt_code)
1873 case QCA808X_CDT_STATUS_STAT_SHORT:
1874 case QCA808X_CDT_STATUS_STAT_OPEN:
1881 static int qca808x_cable_test_result_trans(int cdt_code)
1884 case QCA808X_CDT_STATUS_STAT_NORMAL:
1885 return ETHTOOL_A_CABLE_RESULT_CODE_OK;
1886 case QCA808X_CDT_STATUS_STAT_SHORT:
1887 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
1888 case QCA808X_CDT_STATUS_STAT_OPEN:
1889 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
1890 case QCA808X_CDT_STATUS_STAT_FAIL:
1892 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
1896 static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair)
1899 u32 cdt_length_reg = 0;
1902 case ETHTOOL_A_CABLE_PAIR_A:
1903 cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_A;
1905 case ETHTOOL_A_CABLE_PAIR_B:
1906 cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_B;
1908 case ETHTOOL_A_CABLE_PAIR_C:
1909 cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_C;
1911 case ETHTOOL_A_CABLE_PAIR_D:
1912 cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_D;
1918 val = phy_read_mmd(phydev, MDIO_MMD_PCS, cdt_length_reg);
1922 return (FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val) * 824) / 10;
1925 static int qca808x_cable_test_start(struct phy_device *phydev)
1929 /* perform CDT with the following configs:
1930 * 1. disable hibernation.
1931 * 2. force PHY working in MDI mode.
1932 * 3. for PHY working in 1000BaseT.
1933 * 4. configure the threshold.
1936 ret = at803x_debug_reg_mask(phydev, QCA808X_DBG_AN_TEST, QCA808X_HIBERNATION_EN, 0);
1940 ret = at803x_config_mdix(phydev, ETH_TP_MDI);
1944 /* Force 1000base-T needs to configure PMA/PMD and MII_BMCR */
1945 phydev->duplex = DUPLEX_FULL;
1946 phydev->speed = SPEED_1000;
1947 ret = genphy_c45_pma_setup_forced(phydev);
1951 ret = genphy_setup_forced(phydev);
1955 /* configure the thresholds for open, short, pair ok test */
1956 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8074, 0xc040);
1957 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8076, 0xc040);
1958 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8077, 0xa060);
1959 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8078, 0xc050);
1960 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807a, 0xc060);
1961 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807e, 0xb060);
1966 static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished)
1969 int pair_a, pair_b, pair_c, pair_d;
1973 ret = at803x_cdt_start(phydev, 0);
1977 ret = at803x_cdt_wait_for_completion(phydev);
1981 val = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA808X_MMD3_CDT_STATUS);
1985 pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val);
1986 pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val);
1987 pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val);
1988 pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val);
1990 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
1991 qca808x_cable_test_result_trans(pair_a));
1992 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
1993 qca808x_cable_test_result_trans(pair_b));
1994 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
1995 qca808x_cable_test_result_trans(pair_c));
1996 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
1997 qca808x_cable_test_result_trans(pair_d));
1999 if (qca808x_cdt_fault_length_valid(pair_a))
2000 ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A,
2001 qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A));
2002 if (qca808x_cdt_fault_length_valid(pair_b))
2003 ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B,
2004 qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B));
2005 if (qca808x_cdt_fault_length_valid(pair_c))
2006 ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C,
2007 qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C));
2008 if (qca808x_cdt_fault_length_valid(pair_d))
2009 ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D,
2010 qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D));
2017 static struct phy_driver at803x_driver[] = {
2019 /* Qualcomm Atheros AR8035 */
2020 PHY_ID_MATCH_EXACT(ATH8035_PHY_ID),
2021 .name = "Qualcomm Atheros AR8035",
2022 .flags = PHY_POLL_CABLE_TEST,
2023 .probe = at803x_probe,
2024 .remove = at803x_remove,
2025 .config_aneg = at803x_config_aneg,
2026 .config_init = at803x_config_init,
2027 .soft_reset = genphy_soft_reset,
2028 .set_wol = at803x_set_wol,
2029 .get_wol = at803x_get_wol,
2030 .suspend = at803x_suspend,
2031 .resume = at803x_resume,
2032 /* PHY_GBIT_FEATURES */
2033 .read_status = at803x_read_status,
2034 .config_intr = at803x_config_intr,
2035 .handle_interrupt = at803x_handle_interrupt,
2036 .get_tunable = at803x_get_tunable,
2037 .set_tunable = at803x_set_tunable,
2038 .cable_test_start = at803x_cable_test_start,
2039 .cable_test_get_status = at803x_cable_test_get_status,
2041 /* Qualcomm Atheros AR8030 */
2042 .phy_id = ATH8030_PHY_ID,
2043 .name = "Qualcomm Atheros AR8030",
2044 .phy_id_mask = AT8030_PHY_ID_MASK,
2045 .probe = at803x_probe,
2046 .remove = at803x_remove,
2047 .config_init = at803x_config_init,
2048 .link_change_notify = at803x_link_change_notify,
2049 .set_wol = at803x_set_wol,
2050 .get_wol = at803x_get_wol,
2051 .suspend = at803x_suspend,
2052 .resume = at803x_resume,
2053 /* PHY_BASIC_FEATURES */
2054 .config_intr = at803x_config_intr,
2055 .handle_interrupt = at803x_handle_interrupt,
2057 /* Qualcomm Atheros AR8031/AR8033 */
2058 PHY_ID_MATCH_EXACT(ATH8031_PHY_ID),
2059 .name = "Qualcomm Atheros AR8031/AR8033",
2060 .flags = PHY_POLL_CABLE_TEST,
2061 .probe = at803x_probe,
2062 .remove = at803x_remove,
2063 .config_init = at803x_config_init,
2064 .config_aneg = at803x_config_aneg,
2065 .soft_reset = genphy_soft_reset,
2066 .set_wol = at803x_set_wol,
2067 .get_wol = at803x_get_wol,
2068 .suspend = at803x_suspend,
2069 .resume = at803x_resume,
2070 .read_page = at803x_read_page,
2071 .write_page = at803x_write_page,
2072 .get_features = at803x_get_features,
2073 .read_status = at803x_read_status,
2074 .config_intr = &at803x_config_intr,
2075 .handle_interrupt = at803x_handle_interrupt,
2076 .get_tunable = at803x_get_tunable,
2077 .set_tunable = at803x_set_tunable,
2078 .cable_test_start = at803x_cable_test_start,
2079 .cable_test_get_status = at803x_cable_test_get_status,
2081 /* Qualcomm Atheros AR8032 */
2082 PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
2083 .name = "Qualcomm Atheros AR8032",
2084 .probe = at803x_probe,
2085 .remove = at803x_remove,
2086 .flags = PHY_POLL_CABLE_TEST,
2087 .config_init = at803x_config_init,
2088 .link_change_notify = at803x_link_change_notify,
2089 .set_wol = at803x_set_wol,
2090 .get_wol = at803x_get_wol,
2091 .suspend = at803x_suspend,
2092 .resume = at803x_resume,
2093 /* PHY_BASIC_FEATURES */
2094 .config_intr = at803x_config_intr,
2095 .handle_interrupt = at803x_handle_interrupt,
2096 .cable_test_start = at803x_cable_test_start,
2097 .cable_test_get_status = at803x_cable_test_get_status,
2099 /* ATHEROS AR9331 */
2100 PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
2101 .name = "Qualcomm Atheros AR9331 built-in PHY",
2102 .probe = at803x_probe,
2103 .remove = at803x_remove,
2104 .suspend = at803x_suspend,
2105 .resume = at803x_resume,
2106 .flags = PHY_POLL_CABLE_TEST,
2107 /* PHY_BASIC_FEATURES */
2108 .config_intr = &at803x_config_intr,
2109 .handle_interrupt = at803x_handle_interrupt,
2110 .cable_test_start = at803x_cable_test_start,
2111 .cable_test_get_status = at803x_cable_test_get_status,
2112 .read_status = at803x_read_status,
2113 .soft_reset = genphy_soft_reset,
2114 .config_aneg = at803x_config_aneg,
2116 /* Qualcomm Atheros QCA9561 */
2117 PHY_ID_MATCH_EXACT(QCA9561_PHY_ID),
2118 .name = "Qualcomm Atheros QCA9561 built-in PHY",
2119 .probe = at803x_probe,
2120 .remove = at803x_remove,
2121 .suspend = at803x_suspend,
2122 .resume = at803x_resume,
2123 .flags = PHY_POLL_CABLE_TEST,
2124 /* PHY_BASIC_FEATURES */
2125 .config_intr = &at803x_config_intr,
2126 .handle_interrupt = at803x_handle_interrupt,
2127 .cable_test_start = at803x_cable_test_start,
2128 .cable_test_get_status = at803x_cable_test_get_status,
2129 .read_status = at803x_read_status,
2130 .soft_reset = genphy_soft_reset,
2131 .config_aneg = at803x_config_aneg,
2134 .phy_id = QCA8337_PHY_ID,
2135 .phy_id_mask = QCA8K_PHY_ID_MASK,
2136 .name = "Qualcomm Atheros 8337 internal PHY",
2137 /* PHY_GBIT_FEATURES */
2138 .link_change_notify = qca83xx_link_change_notify,
2139 .probe = at803x_probe,
2140 .flags = PHY_IS_INTERNAL,
2141 .config_init = qca83xx_config_init,
2142 .soft_reset = genphy_soft_reset,
2143 .get_sset_count = at803x_get_sset_count,
2144 .get_strings = at803x_get_strings,
2145 .get_stats = at803x_get_stats,
2146 .suspend = qca83xx_suspend,
2147 .resume = qca83xx_resume,
2149 /* QCA8327-A from switch QCA8327-AL1A */
2150 .phy_id = QCA8327_A_PHY_ID,
2151 .phy_id_mask = QCA8K_PHY_ID_MASK,
2152 .name = "Qualcomm Atheros 8327-A internal PHY",
2153 /* PHY_GBIT_FEATURES */
2154 .link_change_notify = qca83xx_link_change_notify,
2155 .probe = at803x_probe,
2156 .flags = PHY_IS_INTERNAL,
2157 .config_init = qca83xx_config_init,
2158 .soft_reset = genphy_soft_reset,
2159 .get_sset_count = at803x_get_sset_count,
2160 .get_strings = at803x_get_strings,
2161 .get_stats = at803x_get_stats,
2162 .suspend = qca83xx_suspend,
2163 .resume = qca83xx_resume,
2165 /* QCA8327-B from switch QCA8327-BL1A */
2166 .phy_id = QCA8327_B_PHY_ID,
2167 .phy_id_mask = QCA8K_PHY_ID_MASK,
2168 .name = "Qualcomm Atheros 8327-B internal PHY",
2169 /* PHY_GBIT_FEATURES */
2170 .link_change_notify = qca83xx_link_change_notify,
2171 .probe = at803x_probe,
2172 .flags = PHY_IS_INTERNAL,
2173 .config_init = qca83xx_config_init,
2174 .soft_reset = genphy_soft_reset,
2175 .get_sset_count = at803x_get_sset_count,
2176 .get_strings = at803x_get_strings,
2177 .get_stats = at803x_get_stats,
2178 .suspend = qca83xx_suspend,
2179 .resume = qca83xx_resume,
2181 /* Qualcomm QCA8081 */
2182 PHY_ID_MATCH_EXACT(QCA8081_PHY_ID),
2183 .name = "Qualcomm QCA8081",
2184 .flags = PHY_POLL_CABLE_TEST,
2185 .probe = at803x_probe,
2186 .remove = at803x_remove,
2187 .config_intr = at803x_config_intr,
2188 .handle_interrupt = at803x_handle_interrupt,
2189 .get_tunable = at803x_get_tunable,
2190 .set_tunable = at803x_set_tunable,
2191 .set_wol = at803x_set_wol,
2192 .get_wol = at803x_get_wol,
2193 .get_features = at803x_get_features,
2194 .config_aneg = at803x_config_aneg,
2195 .suspend = genphy_suspend,
2196 .resume = genphy_resume,
2197 .read_status = qca808x_read_status,
2198 .config_init = qca808x_config_init,
2199 .soft_reset = qca808x_soft_reset,
2200 .cable_test_start = qca808x_cable_test_start,
2201 .cable_test_get_status = qca808x_cable_test_get_status,
2204 module_phy_driver(at803x_driver);
2206 static struct mdio_device_id __maybe_unused atheros_tbl[] = {
2207 { ATH8030_PHY_ID, AT8030_PHY_ID_MASK },
2208 { PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) },
2209 { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) },
2210 { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) },
2211 { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) },
2212 { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) },
2213 { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) },
2214 { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) },
2215 { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) },
2216 { PHY_ID_MATCH_EXACT(QCA8081_PHY_ID) },
2220 MODULE_DEVICE_TABLE(mdio, atheros_tbl);