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 /* QCA808X 1G chip type */
276 #define QCA808X_PHY_MMD7_CHIP_TYPE 0x901d
277 #define QCA808X_PHY_CHIP_TYPE_1G BIT(0)
279 #define QCA8081_PHY_SERDES_MMD1_FIFO_CTRL 0x9072
280 #define QCA8081_PHY_FIFO_RSTN BIT(11)
282 MODULE_DESCRIPTION("Qualcomm Atheros AR803x and QCA808X PHY driver");
283 MODULE_AUTHOR("Matus Ujhelyi");
284 MODULE_LICENSE("GPL");
286 enum stat_access_type {
291 struct at803x_hw_stat {
295 enum stat_access_type access_type;
298 static struct at803x_hw_stat at803x_hw_stats[] = {
299 { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
300 { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
301 { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
308 u8 smarteee_lpi_tw_1g;
309 u8 smarteee_lpi_tw_100m;
312 struct regulator_dev *vddio_rdev;
313 struct regulator_dev *vddh_rdev;
314 u64 stats[ARRAY_SIZE(at803x_hw_stats)];
317 struct at803x_context {
326 static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data)
330 ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
334 return phy_write(phydev, AT803X_DEBUG_DATA, data);
337 static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
341 ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
345 return phy_read(phydev, AT803X_DEBUG_DATA);
348 static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
354 ret = at803x_debug_reg_read(phydev, reg);
362 return phy_write(phydev, AT803X_DEBUG_DATA, val);
365 static int at803x_write_page(struct phy_device *phydev, int page)
370 if (page == AT803X_PAGE_COPPER) {
371 set = AT803X_BT_BX_REG_SEL;
375 mask = AT803X_BT_BX_REG_SEL;
378 return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set);
381 static int at803x_read_page(struct phy_device *phydev)
383 int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG);
388 if (ccr & AT803X_BT_BX_REG_SEL)
389 return AT803X_PAGE_COPPER;
391 return AT803X_PAGE_FIBER;
394 static int at803x_enable_rx_delay(struct phy_device *phydev)
396 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0,
397 AT803X_DEBUG_RX_CLK_DLY_EN);
400 static int at803x_enable_tx_delay(struct phy_device *phydev)
402 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0,
403 AT803X_DEBUG_TX_CLK_DLY_EN);
406 static int at803x_disable_rx_delay(struct phy_device *phydev)
408 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
409 AT803X_DEBUG_RX_CLK_DLY_EN, 0);
412 static int at803x_disable_tx_delay(struct phy_device *phydev)
414 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE,
415 AT803X_DEBUG_TX_CLK_DLY_EN, 0);
418 /* save relevant PHY registers to private copy */
419 static void at803x_context_save(struct phy_device *phydev,
420 struct at803x_context *context)
422 context->bmcr = phy_read(phydev, MII_BMCR);
423 context->advertise = phy_read(phydev, MII_ADVERTISE);
424 context->control1000 = phy_read(phydev, MII_CTRL1000);
425 context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE);
426 context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED);
427 context->led_control = phy_read(phydev, AT803X_LED_CONTROL);
430 /* restore relevant PHY registers from private copy */
431 static void at803x_context_restore(struct phy_device *phydev,
432 const struct at803x_context *context)
434 phy_write(phydev, MII_BMCR, context->bmcr);
435 phy_write(phydev, MII_ADVERTISE, context->advertise);
436 phy_write(phydev, MII_CTRL1000, context->control1000);
437 phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable);
438 phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed);
439 phy_write(phydev, AT803X_LED_CONTROL, context->led_control);
442 static int at803x_set_wol(struct phy_device *phydev,
443 struct ethtool_wolinfo *wol)
445 int ret, irq_enabled;
447 if (wol->wolopts & WAKE_MAGIC) {
448 struct net_device *ndev = phydev->attached_dev;
451 static const unsigned int offsets[] = {
452 AT803X_LOC_MAC_ADDR_32_47_OFFSET,
453 AT803X_LOC_MAC_ADDR_16_31_OFFSET,
454 AT803X_LOC_MAC_ADDR_0_15_OFFSET,
460 mac = (const u8 *) ndev->dev_addr;
462 if (!is_valid_ether_addr(mac))
465 for (i = 0; i < 3; i++)
466 phy_write_mmd(phydev, MDIO_MMD_PCS, offsets[i],
467 mac[(i * 2) + 1] | (mac[(i * 2)] << 8));
469 /* Enable WOL function for 1588 */
470 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
471 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
472 AT803X_PHY_MMD3_WOL_CTRL,
477 /* Enable WOL interrupt */
478 ret = phy_modify(phydev, AT803X_INTR_ENABLE, 0, AT803X_INTR_ENABLE_WOL);
482 /* Disable WoL function for 1588 */
483 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
484 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
485 AT803X_PHY_MMD3_WOL_CTRL,
490 /* Disable WOL interrupt */
491 ret = phy_modify(phydev, AT803X_INTR_ENABLE, AT803X_INTR_ENABLE_WOL, 0);
496 /* Clear WOL status */
497 ret = phy_read(phydev, AT803X_INTR_STATUS);
501 /* Check if there are other interrupts except for WOL triggered when PHY is
502 * in interrupt mode, only the interrupts enabled by AT803X_INTR_ENABLE can
503 * be passed up to the interrupt PIN.
505 irq_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
509 irq_enabled &= ~AT803X_INTR_ENABLE_WOL;
510 if (ret & irq_enabled && !phy_polling_mode(phydev))
511 phy_trigger_machine(phydev);
516 static void at803x_get_wol(struct phy_device *phydev,
517 struct ethtool_wolinfo *wol)
521 wol->supported = WAKE_MAGIC;
524 value = phy_read(phydev, AT803X_INTR_ENABLE);
528 if (value & AT803X_INTR_ENABLE_WOL)
529 wol->wolopts |= WAKE_MAGIC;
532 static int at803x_get_sset_count(struct phy_device *phydev)
534 return ARRAY_SIZE(at803x_hw_stats);
537 static void at803x_get_strings(struct phy_device *phydev, u8 *data)
541 for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) {
542 strscpy(data + i * ETH_GSTRING_LEN,
543 at803x_hw_stats[i].string, ETH_GSTRING_LEN);
547 static u64 at803x_get_stat(struct phy_device *phydev, int i)
549 struct at803x_hw_stat stat = at803x_hw_stats[i];
550 struct at803x_priv *priv = phydev->priv;
554 if (stat.access_type == MMD)
555 val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg);
557 val = phy_read(phydev, stat.reg);
562 val = val & stat.mask;
563 priv->stats[i] += val;
564 ret = priv->stats[i];
570 static void at803x_get_stats(struct phy_device *phydev,
571 struct ethtool_stats *stats, u64 *data)
575 for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++)
576 data[i] = at803x_get_stat(phydev, i);
579 static int at803x_suspend(struct phy_device *phydev)
584 value = phy_read(phydev, AT803X_INTR_ENABLE);
585 wol_enabled = value & AT803X_INTR_ENABLE_WOL;
588 value = BMCR_ISOLATE;
592 phy_modify(phydev, MII_BMCR, 0, value);
597 static int at803x_resume(struct phy_device *phydev)
599 return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
602 static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
603 unsigned int selector)
605 struct phy_device *phydev = rdev_get_drvdata(rdev);
608 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
609 0, AT803X_DEBUG_RGMII_1V8);
611 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
612 AT803X_DEBUG_RGMII_1V8, 0);
615 static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
617 struct phy_device *phydev = rdev_get_drvdata(rdev);
620 val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
624 return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
627 static const struct regulator_ops vddio_regulator_ops = {
628 .list_voltage = regulator_list_voltage_table,
629 .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel,
630 .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel,
633 static const unsigned int vddio_voltage_table[] = {
638 static const struct regulator_desc vddio_desc = {
640 .of_match = of_match_ptr("vddio-regulator"),
641 .n_voltages = ARRAY_SIZE(vddio_voltage_table),
642 .volt_table = vddio_voltage_table,
643 .ops = &vddio_regulator_ops,
644 .type = REGULATOR_VOLTAGE,
645 .owner = THIS_MODULE,
648 static const struct regulator_ops vddh_regulator_ops = {
651 static const struct regulator_desc vddh_desc = {
653 .of_match = of_match_ptr("vddh-regulator"),
656 .ops = &vddh_regulator_ops,
657 .type = REGULATOR_VOLTAGE,
658 .owner = THIS_MODULE,
661 static int at8031_register_regulators(struct phy_device *phydev)
663 struct at803x_priv *priv = phydev->priv;
664 struct device *dev = &phydev->mdio.dev;
665 struct regulator_config config = { };
668 config.driver_data = phydev;
670 priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
671 if (IS_ERR(priv->vddio_rdev)) {
672 phydev_err(phydev, "failed to register VDDIO regulator\n");
673 return PTR_ERR(priv->vddio_rdev);
676 priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
677 if (IS_ERR(priv->vddh_rdev)) {
678 phydev_err(phydev, "failed to register VDDH regulator\n");
679 return PTR_ERR(priv->vddh_rdev);
685 static int at803x_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
687 struct phy_device *phydev = upstream;
688 __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support);
689 __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
690 DECLARE_PHY_INTERFACE_MASK(interfaces);
691 phy_interface_t iface;
693 linkmode_zero(phy_support);
694 phylink_set(phy_support, 1000baseX_Full);
695 phylink_set(phy_support, 1000baseT_Full);
696 phylink_set(phy_support, Autoneg);
697 phylink_set(phy_support, Pause);
698 phylink_set(phy_support, Asym_Pause);
700 linkmode_zero(sfp_support);
701 sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
702 /* Some modules support 10G modes as well as others we support.
703 * Mask out non-supported modes so the correct interface is picked.
705 linkmode_and(sfp_support, phy_support, sfp_support);
707 if (linkmode_empty(sfp_support)) {
708 dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
712 iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
714 /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes
715 * interface for use with SFP modules.
716 * However, some copper modules detected as having a preferred SGMII
717 * interface do default to and function in 1000Base-X mode, so just
718 * print a warning and allow such modules, as they may have some chance
721 if (iface == PHY_INTERFACE_MODE_SGMII)
722 dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n");
723 else if (iface != PHY_INTERFACE_MODE_1000BASEX)
729 static const struct sfp_upstream_ops at803x_sfp_ops = {
730 .attach = phy_sfp_attach,
731 .detach = phy_sfp_detach,
732 .module_insert = at803x_sfp_insert,
735 static int at803x_parse_dt(struct phy_device *phydev)
737 struct device_node *node = phydev->mdio.dev.of_node;
738 struct at803x_priv *priv = phydev->priv;
739 u32 freq, strength, tw;
743 if (!IS_ENABLED(CONFIG_OF_MDIO))
746 if (of_property_read_bool(node, "qca,disable-smarteee"))
747 priv->flags |= AT803X_DISABLE_SMARTEEE;
749 if (of_property_read_bool(node, "qca,disable-hibernation-mode"))
750 priv->flags |= AT803X_DISABLE_HIBERNATION_MODE;
752 if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) {
753 if (!tw || tw > 255) {
754 phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n");
757 priv->smarteee_lpi_tw_1g = tw;
760 if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) {
761 if (!tw || tw > 255) {
762 phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n");
765 priv->smarteee_lpi_tw_100m = tw;
768 ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq);
772 sel = AT803X_CLK_OUT_25MHZ_XTAL;
775 sel = AT803X_CLK_OUT_50MHZ_PLL;
778 sel = AT803X_CLK_OUT_62_5MHZ_PLL;
781 sel = AT803X_CLK_OUT_125MHZ_PLL;
784 phydev_err(phydev, "invalid qca,clk-out-frequency\n");
788 priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel);
789 priv->clk_25m_mask |= AT803X_CLK_OUT_MASK;
791 /* Fixup for the AR8030/AR8035. This chip has another mask and
792 * doesn't support the DSP reference. Eg. the lowest bit of the
793 * mask. The upper two bits select the same frequencies. Mask
794 * the lowest bit here.
797 * There was no datasheet for the AR8030 available so this is
798 * just a guess. But the AR8035 is listed as pin compatible
799 * to the AR8030 so there might be a good chance it works on
802 if (phydev->drv->phy_id == ATH8030_PHY_ID ||
803 phydev->drv->phy_id == ATH8035_PHY_ID) {
804 priv->clk_25m_reg &= AT8035_CLK_OUT_MASK;
805 priv->clk_25m_mask &= AT8035_CLK_OUT_MASK;
809 ret = of_property_read_u32(node, "qca,clk-out-strength", &strength);
811 priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK;
813 case AR803X_STRENGTH_FULL:
814 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL;
816 case AR803X_STRENGTH_HALF:
817 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF;
819 case AR803X_STRENGTH_QUARTER:
820 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER;
823 phydev_err(phydev, "invalid qca,clk-out-strength\n");
828 /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping
831 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
832 if (of_property_read_bool(node, "qca,keep-pll-enabled"))
833 priv->flags |= AT803X_KEEP_PLL_ENABLED;
835 ret = at8031_register_regulators(phydev);
839 ret = devm_regulator_get_enable_optional(&phydev->mdio.dev,
842 phydev_err(phydev, "failed to get VDDIO regulator\n");
846 /* Only AR8031/8033 support 1000Base-X for SFP modules */
847 ret = phy_sfp_probe(phydev, &at803x_sfp_ops);
855 static int at803x_probe(struct phy_device *phydev)
857 struct device *dev = &phydev->mdio.dev;
858 struct at803x_priv *priv;
861 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
867 ret = at803x_parse_dt(phydev);
871 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
872 int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
877 mode_cfg = ccr & AT803X_MODE_CFG_MASK;
880 case AT803X_MODE_CFG_BX1000_RGMII_50OHM:
881 case AT803X_MODE_CFG_BX1000_RGMII_75OHM:
882 priv->is_1000basex = true;
884 case AT803X_MODE_CFG_FX100_RGMII_50OHM:
885 case AT803X_MODE_CFG_FX100_RGMII_75OHM:
886 priv->is_fiber = true;
890 /* Disable WoL in 1588 register which is enabled
893 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
894 AT803X_PHY_MMD3_WOL_CTRL,
903 static int at803x_get_features(struct phy_device *phydev)
905 struct at803x_priv *priv = phydev->priv;
908 err = genphy_read_abilities(phydev);
912 if (phydev->drv->phy_id != ATH8031_PHY_ID)
915 /* AR8031/AR8033 have different status registers
916 * for copper and fiber operation. However, the
917 * extended status register is the same for both
920 * As a result of that, ESTATUS_1000_XFULL is set
921 * to 1 even when operating in copper TP mode.
923 * Remove this mode from the supported link modes
924 * when not operating in 1000BaseX mode.
926 if (!priv->is_1000basex)
927 linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
933 static int at803x_smarteee_config(struct phy_device *phydev)
935 struct at803x_priv *priv = phydev->priv;
936 u16 mask = 0, val = 0;
939 if (priv->flags & AT803X_DISABLE_SMARTEEE)
940 return phy_modify_mmd(phydev, MDIO_MMD_PCS,
941 AT803X_MMD3_SMARTEEE_CTL3,
942 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0);
944 if (priv->smarteee_lpi_tw_1g) {
946 val |= priv->smarteee_lpi_tw_1g << 8;
948 if (priv->smarteee_lpi_tw_100m) {
950 val |= priv->smarteee_lpi_tw_100m;
955 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1,
960 return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3,
961 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN,
962 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN);
965 static int at803x_clk_out_config(struct phy_device *phydev)
967 struct at803x_priv *priv = phydev->priv;
969 if (!priv->clk_25m_mask)
972 return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M,
973 priv->clk_25m_mask, priv->clk_25m_reg);
976 static int at8031_pll_config(struct phy_device *phydev)
978 struct at803x_priv *priv = phydev->priv;
980 /* The default after hardware reset is PLL OFF. After a soft reset, the
981 * values are retained.
983 if (priv->flags & AT803X_KEEP_PLL_ENABLED)
984 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
985 0, AT803X_DEBUG_PLL_ON);
987 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
988 AT803X_DEBUG_PLL_ON, 0);
991 static int at803x_hibernation_mode_config(struct phy_device *phydev)
993 struct at803x_priv *priv = phydev->priv;
995 /* The default after hardware reset is hibernation mode enabled. After
996 * software reset, the value is retained.
998 if (!(priv->flags & AT803X_DISABLE_HIBERNATION_MODE))
1001 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
1002 AT803X_DEBUG_HIB_CTRL_PS_HIB_EN, 0);
1005 static int at803x_config_init(struct phy_device *phydev)
1007 struct at803x_priv *priv = phydev->priv;
1010 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
1011 /* Some bootloaders leave the fiber page selected.
1012 * Switch to the appropriate page (fiber or copper), as otherwise we
1013 * read the PHY capabilities from the wrong page.
1015 phy_lock_mdio_bus(phydev);
1016 ret = at803x_write_page(phydev,
1017 priv->is_fiber ? AT803X_PAGE_FIBER :
1018 AT803X_PAGE_COPPER);
1019 phy_unlock_mdio_bus(phydev);
1023 ret = at8031_pll_config(phydev);
1028 /* The RX and TX delay default is:
1029 * after HW reset: RX delay enabled and TX delay disabled
1030 * after SW reset: RX delay enabled, while TX delay retains the
1031 * value before reset.
1033 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
1034 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
1035 ret = at803x_enable_rx_delay(phydev);
1037 ret = at803x_disable_rx_delay(phydev);
1041 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
1042 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
1043 ret = at803x_enable_tx_delay(phydev);
1045 ret = at803x_disable_tx_delay(phydev);
1049 ret = at803x_smarteee_config(phydev);
1053 ret = at803x_clk_out_config(phydev);
1057 ret = at803x_hibernation_mode_config(phydev);
1061 /* Ar803x extended next page bit is enabled by default. Cisco
1062 * multigig switches read this bit and attempt to negotiate 10Gbps
1063 * rates even if the next page bit is disabled. This is incorrect
1064 * behaviour but we still need to accommodate it. XNP is only needed
1065 * for 10Gbps support, so disable XNP.
1067 return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0);
1070 static int at803x_ack_interrupt(struct phy_device *phydev)
1074 err = phy_read(phydev, AT803X_INTR_STATUS);
1076 return (err < 0) ? err : 0;
1079 static int at803x_config_intr(struct phy_device *phydev)
1081 struct at803x_priv *priv = phydev->priv;
1085 value = phy_read(phydev, AT803X_INTR_ENABLE);
1087 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1088 /* Clear any pending interrupts */
1089 err = at803x_ack_interrupt(phydev);
1093 value |= AT803X_INTR_ENABLE_AUTONEG_ERR;
1094 value |= AT803X_INTR_ENABLE_SPEED_CHANGED;
1095 value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED;
1096 value |= AT803X_INTR_ENABLE_LINK_FAIL;
1097 value |= AT803X_INTR_ENABLE_LINK_SUCCESS;
1098 if (priv->is_fiber) {
1099 value |= AT803X_INTR_ENABLE_LINK_FAIL_BX;
1100 value |= AT803X_INTR_ENABLE_LINK_SUCCESS_BX;
1103 err = phy_write(phydev, AT803X_INTR_ENABLE, value);
1105 err = phy_write(phydev, AT803X_INTR_ENABLE, 0);
1109 /* Clear any pending interrupts */
1110 err = at803x_ack_interrupt(phydev);
1116 static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev)
1118 int irq_status, int_enabled;
1120 irq_status = phy_read(phydev, AT803X_INTR_STATUS);
1121 if (irq_status < 0) {
1126 /* Read the current enabled interrupts */
1127 int_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
1128 if (int_enabled < 0) {
1133 /* See if this was one of our enabled interrupts */
1134 if (!(irq_status & int_enabled))
1137 phy_trigger_machine(phydev);
1142 static void at803x_link_change_notify(struct phy_device *phydev)
1145 * Conduct a hardware reset for AT8030 every time a link loss is
1146 * signalled. This is necessary to circumvent a hardware bug that
1147 * occurs when the cable is unplugged while TX packets are pending
1148 * in the FIFO. In such cases, the FIFO enters an error mode it
1149 * cannot recover from by software.
1151 if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) {
1152 struct at803x_context context;
1154 at803x_context_save(phydev, &context);
1156 phy_device_reset(phydev, 1);
1158 phy_device_reset(phydev, 0);
1161 at803x_context_restore(phydev, &context);
1163 phydev_dbg(phydev, "%s(): phy was reset\n", __func__);
1167 static int at803x_read_specific_status(struct phy_device *phydev)
1171 /* Read the AT8035 PHY-Specific Status register, which indicates the
1172 * speed and duplex that the PHY is actually using, irrespective of
1173 * whether we are in autoneg mode or not.
1175 ss = phy_read(phydev, AT803X_SPECIFIC_STATUS);
1179 if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) {
1182 sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL);
1186 /* qca8081 takes the different bits for speed value from at803x */
1187 if (phydev->drv->phy_id == QCA8081_PHY_ID)
1188 speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss);
1190 speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss);
1193 case AT803X_SS_SPEED_10:
1194 phydev->speed = SPEED_10;
1196 case AT803X_SS_SPEED_100:
1197 phydev->speed = SPEED_100;
1199 case AT803X_SS_SPEED_1000:
1200 phydev->speed = SPEED_1000;
1202 case QCA808X_SS_SPEED_2500:
1203 phydev->speed = SPEED_2500;
1206 if (ss & AT803X_SS_DUPLEX)
1207 phydev->duplex = DUPLEX_FULL;
1209 phydev->duplex = DUPLEX_HALF;
1211 if (ss & AT803X_SS_MDIX)
1212 phydev->mdix = ETH_TP_MDI_X;
1214 phydev->mdix = ETH_TP_MDI;
1216 switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) {
1217 case AT803X_SFC_MANUAL_MDI:
1218 phydev->mdix_ctrl = ETH_TP_MDI;
1220 case AT803X_SFC_MANUAL_MDIX:
1221 phydev->mdix_ctrl = ETH_TP_MDI_X;
1223 case AT803X_SFC_AUTOMATIC_CROSSOVER:
1224 phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
1232 static int at803x_read_status(struct phy_device *phydev)
1234 struct at803x_priv *priv = phydev->priv;
1235 int err, old_link = phydev->link;
1237 if (priv->is_1000basex)
1238 return genphy_c37_read_status(phydev);
1240 /* Update the link, but return if there was an error */
1241 err = genphy_update_link(phydev);
1245 /* why bother the PHY if nothing can have changed */
1246 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
1249 phydev->speed = SPEED_UNKNOWN;
1250 phydev->duplex = DUPLEX_UNKNOWN;
1252 phydev->asym_pause = 0;
1254 err = genphy_read_lpa(phydev);
1258 err = at803x_read_specific_status(phydev);
1262 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
1263 phy_resolve_aneg_pause(phydev);
1268 static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl)
1274 val = AT803X_SFC_MANUAL_MDI;
1277 val = AT803X_SFC_MANUAL_MDIX;
1279 case ETH_TP_MDI_AUTO:
1280 val = AT803X_SFC_AUTOMATIC_CROSSOVER;
1286 return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL,
1287 AT803X_SFC_MDI_CROSSOVER_MODE_M,
1288 FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val));
1291 static int at803x_config_aneg(struct phy_device *phydev)
1293 struct at803x_priv *priv = phydev->priv;
1296 ret = at803x_config_mdix(phydev, phydev->mdix_ctrl);
1300 /* Changes of the midx bits are disruptive to the normal operation;
1301 * therefore any changes to these registers must be followed by a
1302 * software reset to take effect.
1305 ret = genphy_soft_reset(phydev);
1310 if (priv->is_1000basex)
1311 return genphy_c37_config_aneg(phydev);
1313 /* Do not restart auto-negotiation by setting ret to 0 defautly,
1314 * when calling __genphy_config_aneg later.
1318 if (phydev->drv->phy_id == QCA8081_PHY_ID) {
1321 /* The reg MII_BMCR also needs to be configured for force mode, the
1322 * genphy_config_aneg is also needed.
1324 if (phydev->autoneg == AUTONEG_DISABLE)
1325 genphy_c45_pma_setup_forced(phydev);
1327 if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising))
1328 phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G;
1330 ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
1331 MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl);
1336 return __genphy_config_aneg(phydev, ret);
1339 static int at803x_get_downshift(struct phy_device *phydev, u8 *d)
1343 val = phy_read(phydev, AT803X_SMART_SPEED);
1347 if (val & AT803X_SMART_SPEED_ENABLE)
1348 *d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2;
1350 *d = DOWNSHIFT_DEV_DISABLE;
1355 static int at803x_set_downshift(struct phy_device *phydev, u8 cnt)
1361 case DOWNSHIFT_DEV_DEFAULT_COUNT:
1362 cnt = AT803X_DEFAULT_DOWNSHIFT;
1364 case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT:
1365 set = AT803X_SMART_SPEED_ENABLE |
1366 AT803X_SMART_SPEED_BYPASS_TIMER |
1367 FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2);
1368 mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK;
1370 case DOWNSHIFT_DEV_DISABLE:
1372 mask = AT803X_SMART_SPEED_ENABLE |
1373 AT803X_SMART_SPEED_BYPASS_TIMER;
1379 ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set);
1381 /* After changing the smart speed settings, we need to perform a
1382 * software reset, use phy_init_hw() to make sure we set the
1383 * reapply any values which might got lost during software reset.
1386 ret = phy_init_hw(phydev);
1391 static int at803x_get_tunable(struct phy_device *phydev,
1392 struct ethtool_tunable *tuna, void *data)
1395 case ETHTOOL_PHY_DOWNSHIFT:
1396 return at803x_get_downshift(phydev, data);
1402 static int at803x_set_tunable(struct phy_device *phydev,
1403 struct ethtool_tunable *tuna, const void *data)
1406 case ETHTOOL_PHY_DOWNSHIFT:
1407 return at803x_set_downshift(phydev, *(const u8 *)data);
1413 static int at803x_cable_test_result_trans(u16 status)
1415 switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
1416 case AT803X_CDT_STATUS_STAT_NORMAL:
1417 return ETHTOOL_A_CABLE_RESULT_CODE_OK;
1418 case AT803X_CDT_STATUS_STAT_SHORT:
1419 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
1420 case AT803X_CDT_STATUS_STAT_OPEN:
1421 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
1422 case AT803X_CDT_STATUS_STAT_FAIL:
1424 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
1428 static bool at803x_cdt_test_failed(u16 status)
1430 return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) ==
1431 AT803X_CDT_STATUS_STAT_FAIL;
1434 static bool at803x_cdt_fault_length_valid(u16 status)
1436 switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
1437 case AT803X_CDT_STATUS_STAT_OPEN:
1438 case AT803X_CDT_STATUS_STAT_SHORT:
1444 static int at803x_cdt_fault_length(u16 status)
1448 /* According to the datasheet the distance to the fault is
1449 * DELTA_TIME * 0.824 meters.
1451 * The author suspect the correct formula is:
1453 * fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2
1455 * where c is the speed of light, VF is the velocity factor of
1456 * the twisted pair cable, 125MHz the counter frequency and
1457 * we need to divide by 2 because the hardware will measure the
1458 * round trip time to the fault and back to the PHY.
1460 * With a VF of 0.69 we get the factor 0.824 mentioned in the
1463 dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status);
1465 return (dt * 824) / 10;
1468 static int at803x_cdt_start(struct phy_device *phydev, int pair)
1472 /* qca8081 takes the different bit 15 to enable CDT test */
1473 if (phydev->drv->phy_id == QCA8081_PHY_ID)
1474 cdt = QCA808X_CDT_ENABLE_TEST |
1475 QCA808X_CDT_LENGTH_UNIT |
1476 QCA808X_CDT_INTER_CHECK_DIS;
1478 cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
1479 AT803X_CDT_ENABLE_TEST;
1481 return phy_write(phydev, AT803X_CDT, cdt);
1484 static int at803x_cdt_wait_for_completion(struct phy_device *phydev)
1489 if (phydev->drv->phy_id == QCA8081_PHY_ID)
1490 cdt_en = QCA808X_CDT_ENABLE_TEST;
1492 cdt_en = AT803X_CDT_ENABLE_TEST;
1494 /* One test run takes about 25ms */
1495 ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
1497 30000, 100000, true);
1499 return ret < 0 ? ret : 0;
1502 static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair)
1504 static const int ethtool_pair[] = {
1505 ETHTOOL_A_CABLE_PAIR_A,
1506 ETHTOOL_A_CABLE_PAIR_B,
1507 ETHTOOL_A_CABLE_PAIR_C,
1508 ETHTOOL_A_CABLE_PAIR_D,
1512 ret = at803x_cdt_start(phydev, pair);
1516 ret = at803x_cdt_wait_for_completion(phydev);
1520 val = phy_read(phydev, AT803X_CDT_STATUS);
1524 if (at803x_cdt_test_failed(val))
1527 ethnl_cable_test_result(phydev, ethtool_pair[pair],
1528 at803x_cable_test_result_trans(val));
1530 if (at803x_cdt_fault_length_valid(val))
1531 ethnl_cable_test_fault_length(phydev, ethtool_pair[pair],
1532 at803x_cdt_fault_length(val));
1537 static int at803x_cable_test_get_status(struct phy_device *phydev,
1540 unsigned long pair_mask;
1544 if (phydev->phy_id == ATH9331_PHY_ID ||
1545 phydev->phy_id == ATH8032_PHY_ID ||
1546 phydev->phy_id == QCA9561_PHY_ID)
1553 /* According to the datasheet the CDT can be performed when
1554 * there is no link partner or when the link partner is
1555 * auto-negotiating. Starting the test will restart the AN
1556 * automatically. It seems that doing this repeatedly we will
1557 * get a slot where our link partner won't disturb our
1560 while (pair_mask && retries--) {
1561 for_each_set_bit(pair, &pair_mask, 4) {
1562 ret = at803x_cable_test_one_pair(phydev, pair);
1566 clear_bit(pair, &pair_mask);
1577 static int at803x_cable_test_start(struct phy_device *phydev)
1579 /* Enable auto-negotiation, but advertise no capabilities, no link
1580 * will be established. A restart of the auto-negotiation is not
1581 * required, because the cable test will automatically break the link.
1583 phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
1584 phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
1585 if (phydev->phy_id != ATH9331_PHY_ID &&
1586 phydev->phy_id != ATH8032_PHY_ID &&
1587 phydev->phy_id != QCA9561_PHY_ID)
1588 phy_write(phydev, MII_CTRL1000, 0);
1590 /* we do all the (time consuming) work later */
1594 static int qca83xx_config_init(struct phy_device *phydev)
1598 switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK;
1600 switch (switch_revision) {
1602 /* For 100M waveform */
1603 at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea);
1604 /* Turn on Gigabit clock */
1605 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0);
1609 phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0);
1612 phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f);
1613 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860);
1614 at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46);
1615 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000);
1619 /* QCA8327 require DAC amplitude adjustment for 100m set to +6%.
1620 * Disable on init and enable only with 100m speed following
1621 * qca original source code.
1623 if (phydev->drv->phy_id == QCA8327_A_PHY_ID ||
1624 phydev->drv->phy_id == QCA8327_B_PHY_ID)
1625 at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
1626 QCA8327_DEBUG_MANU_CTRL_EN, 0);
1628 /* Following original QCA sourcecode set port to prefer master */
1629 phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER);
1634 static void qca83xx_link_change_notify(struct phy_device *phydev)
1636 /* QCA8337 doesn't require DAC Amplitude adjustement */
1637 if (phydev->drv->phy_id == QCA8337_PHY_ID)
1640 /* Set DAC Amplitude adjustment to +6% for 100m on link running */
1641 if (phydev->state == PHY_RUNNING) {
1642 if (phydev->speed == SPEED_100)
1643 at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
1644 QCA8327_DEBUG_MANU_CTRL_EN,
1645 QCA8327_DEBUG_MANU_CTRL_EN);
1647 /* Reset DAC Amplitude adjustment */
1648 at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
1649 QCA8327_DEBUG_MANU_CTRL_EN, 0);
1653 static int qca83xx_resume(struct phy_device *phydev)
1657 /* Skip reset if not suspended */
1658 if (!phydev->suspended)
1661 /* Reinit the port, reset values set by suspend */
1662 qca83xx_config_init(phydev);
1664 /* Reset the port on port resume */
1665 phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
1667 /* On resume from suspend the switch execute a reset and
1668 * restart auto-negotiation. Wait for reset to complete.
1670 ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET),
1671 50000, 600000, true);
1680 static int qca83xx_suspend(struct phy_device *phydev)
1684 /* Only QCA8337 support actual suspend.
1685 * QCA8327 cause port unreliability when phy suspend
1688 if (phydev->drv->phy_id == QCA8337_PHY_ID) {
1689 genphy_suspend(phydev);
1691 mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX);
1692 phy_modify(phydev, MII_BMCR, mask, 0);
1695 at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN,
1696 AT803X_DEBUG_GATE_CLK_IN1000, 0);
1698 at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
1699 AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE |
1700 AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0);
1705 static int qca808x_phy_fast_retrain_config(struct phy_device *phydev)
1709 /* Enable fast retrain */
1710 ret = genphy_c45_fast_retrain(phydev, true);
1714 phy_write_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_TOP_OPTION1,
1715 QCA808X_TOP_OPTION1_DATA);
1716 phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB,
1717 QCA808X_MSE_THRESHOLD_20DB_VALUE);
1718 phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB,
1719 QCA808X_MSE_THRESHOLD_17DB_VALUE);
1720 phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB,
1721 QCA808X_MSE_THRESHOLD_27DB_VALUE);
1722 phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB,
1723 QCA808X_MSE_THRESHOLD_28DB_VALUE);
1724 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_1,
1725 QCA808X_MMD3_DEBUG_1_VALUE);
1726 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_4,
1727 QCA808X_MMD3_DEBUG_4_VALUE);
1728 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_5,
1729 QCA808X_MMD3_DEBUG_5_VALUE);
1730 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_3,
1731 QCA808X_MMD3_DEBUG_3_VALUE);
1732 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_6,
1733 QCA808X_MMD3_DEBUG_6_VALUE);
1734 phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_2,
1735 QCA808X_MMD3_DEBUG_2_VALUE);
1740 static int qca808x_phy_ms_seed_enable(struct phy_device *phydev, bool enable)
1745 return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED,
1746 QCA808X_MASTER_SLAVE_SEED_ENABLE, 0);
1748 seed_value = get_random_u32_below(QCA808X_MASTER_SLAVE_SEED_RANGE);
1749 return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED,
1750 QCA808X_MASTER_SLAVE_SEED_CFG | QCA808X_MASTER_SLAVE_SEED_ENABLE,
1751 FIELD_PREP(QCA808X_MASTER_SLAVE_SEED_CFG, seed_value) |
1752 QCA808X_MASTER_SLAVE_SEED_ENABLE);
1755 static bool qca808x_is_prefer_master(struct phy_device *phydev)
1757 return (phydev->master_slave_get == MASTER_SLAVE_CFG_MASTER_FORCE) ||
1758 (phydev->master_slave_get == MASTER_SLAVE_CFG_MASTER_PREFERRED);
1761 static bool qca808x_has_fast_retrain_or_slave_seed(struct phy_device *phydev)
1763 return linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported);
1766 static int qca808x_config_init(struct phy_device *phydev)
1770 /* Active adc&vga on 802.3az for the link 1000M and 100M */
1771 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_ADDR_CLD_CTRL7,
1772 QCA808X_8023AZ_AFE_CTRL_MASK, QCA808X_8023AZ_AFE_EN);
1776 /* Adjust the threshold on 802.3az for the link 1000M */
1777 ret = phy_write_mmd(phydev, MDIO_MMD_PCS,
1778 QCA808X_PHY_MMD3_AZ_TRAINING_CTRL, QCA808X_MMD3_AZ_TRAINING_VAL);
1782 if (qca808x_has_fast_retrain_or_slave_seed(phydev)) {
1783 /* Config the fast retrain for the link 2500M */
1784 ret = qca808x_phy_fast_retrain_config(phydev);
1788 ret = genphy_read_master_slave(phydev);
1792 if (!qca808x_is_prefer_master(phydev)) {
1793 /* Enable seed and configure lower ramdom seed to make phy
1794 * linked as slave mode.
1796 ret = qca808x_phy_ms_seed_enable(phydev, true);
1802 /* Configure adc threshold as 100mv for the link 10M */
1803 return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD,
1804 QCA808X_ADC_THRESHOLD_MASK, QCA808X_ADC_THRESHOLD_100MV);
1807 static int qca808x_read_status(struct phy_device *phydev)
1811 ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
1815 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising,
1816 ret & MDIO_AN_10GBT_STAT_LP2_5G);
1818 ret = genphy_read_status(phydev);
1822 ret = at803x_read_specific_status(phydev);
1827 if (phydev->speed == SPEED_2500)
1828 phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
1830 phydev->interface = PHY_INTERFACE_MODE_SGMII;
1832 /* generate seed as a lower random value to make PHY linked as SLAVE easily,
1833 * except for master/slave configuration fault detected or the master mode
1836 * the reason for not putting this code into the function link_change_notify is
1837 * the corner case where the link partner is also the qca8081 PHY and the seed
1838 * value is configured as the same value, the link can't be up and no link change
1841 if (qca808x_has_fast_retrain_or_slave_seed(phydev)) {
1842 if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR ||
1843 qca808x_is_prefer_master(phydev)) {
1844 qca808x_phy_ms_seed_enable(phydev, false);
1846 qca808x_phy_ms_seed_enable(phydev, true);
1854 static int qca808x_soft_reset(struct phy_device *phydev)
1858 ret = genphy_soft_reset(phydev);
1862 if (qca808x_has_fast_retrain_or_slave_seed(phydev))
1863 ret = qca808x_phy_ms_seed_enable(phydev, true);
1868 static bool qca808x_cdt_fault_length_valid(int cdt_code)
1871 case QCA808X_CDT_STATUS_STAT_SHORT:
1872 case QCA808X_CDT_STATUS_STAT_OPEN:
1879 static int qca808x_cable_test_result_trans(int cdt_code)
1882 case QCA808X_CDT_STATUS_STAT_NORMAL:
1883 return ETHTOOL_A_CABLE_RESULT_CODE_OK;
1884 case QCA808X_CDT_STATUS_STAT_SHORT:
1885 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
1886 case QCA808X_CDT_STATUS_STAT_OPEN:
1887 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
1888 case QCA808X_CDT_STATUS_STAT_FAIL:
1890 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
1894 static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair)
1897 u32 cdt_length_reg = 0;
1900 case ETHTOOL_A_CABLE_PAIR_A:
1901 cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_A;
1903 case ETHTOOL_A_CABLE_PAIR_B:
1904 cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_B;
1906 case ETHTOOL_A_CABLE_PAIR_C:
1907 cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_C;
1909 case ETHTOOL_A_CABLE_PAIR_D:
1910 cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_D;
1916 val = phy_read_mmd(phydev, MDIO_MMD_PCS, cdt_length_reg);
1920 return (FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val) * 824) / 10;
1923 static int qca808x_cable_test_start(struct phy_device *phydev)
1927 /* perform CDT with the following configs:
1928 * 1. disable hibernation.
1929 * 2. force PHY working in MDI mode.
1930 * 3. for PHY working in 1000BaseT.
1931 * 4. configure the threshold.
1934 ret = at803x_debug_reg_mask(phydev, QCA808X_DBG_AN_TEST, QCA808X_HIBERNATION_EN, 0);
1938 ret = at803x_config_mdix(phydev, ETH_TP_MDI);
1942 /* Force 1000base-T needs to configure PMA/PMD and MII_BMCR */
1943 phydev->duplex = DUPLEX_FULL;
1944 phydev->speed = SPEED_1000;
1945 ret = genphy_c45_pma_setup_forced(phydev);
1949 ret = genphy_setup_forced(phydev);
1953 /* configure the thresholds for open, short, pair ok test */
1954 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8074, 0xc040);
1955 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8076, 0xc040);
1956 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8077, 0xa060);
1957 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8078, 0xc050);
1958 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807a, 0xc060);
1959 phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807e, 0xb060);
1964 static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished)
1967 int pair_a, pair_b, pair_c, pair_d;
1971 ret = at803x_cdt_start(phydev, 0);
1975 ret = at803x_cdt_wait_for_completion(phydev);
1979 val = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA808X_MMD3_CDT_STATUS);
1983 pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val);
1984 pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val);
1985 pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val);
1986 pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val);
1988 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
1989 qca808x_cable_test_result_trans(pair_a));
1990 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
1991 qca808x_cable_test_result_trans(pair_b));
1992 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
1993 qca808x_cable_test_result_trans(pair_c));
1994 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
1995 qca808x_cable_test_result_trans(pair_d));
1997 if (qca808x_cdt_fault_length_valid(pair_a))
1998 ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A,
1999 qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A));
2000 if (qca808x_cdt_fault_length_valid(pair_b))
2001 ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B,
2002 qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B));
2003 if (qca808x_cdt_fault_length_valid(pair_c))
2004 ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C,
2005 qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C));
2006 if (qca808x_cdt_fault_length_valid(pair_d))
2007 ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D,
2008 qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D));
2015 static int qca808x_get_features(struct phy_device *phydev)
2019 ret = genphy_c45_pma_read_abilities(phydev);
2023 /* The autoneg ability is not existed in bit3 of MMD7.1,
2024 * but it is supported by qca808x PHY, so we add it here
2027 linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported);
2029 /* As for the qca8081 1G version chip, the 2500baseT ability is also
2030 * existed in the bit0 of MMD1.21, we need to remove it manually if
2031 * it is the qca8081 1G chip according to the bit0 of MMD7.0x901d.
2033 ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_CHIP_TYPE);
2037 if (QCA808X_PHY_CHIP_TYPE_1G & ret)
2038 linkmode_clear_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported);
2043 static void qca808x_link_change_notify(struct phy_device *phydev)
2045 /* Assert interface sgmii fifo on link down, deassert it on link up,
2046 * the interface device address is always phy address added by 1.
2048 mdiobus_c45_modify_changed(phydev->mdio.bus, phydev->mdio.addr + 1,
2049 MDIO_MMD_PMAPMD, QCA8081_PHY_SERDES_MMD1_FIFO_CTRL,
2050 QCA8081_PHY_FIFO_RSTN, phydev->link ? QCA8081_PHY_FIFO_RSTN : 0);
2053 static struct phy_driver at803x_driver[] = {
2055 /* Qualcomm Atheros AR8035 */
2056 PHY_ID_MATCH_EXACT(ATH8035_PHY_ID),
2057 .name = "Qualcomm Atheros AR8035",
2058 .flags = PHY_POLL_CABLE_TEST,
2059 .probe = at803x_probe,
2060 .config_aneg = at803x_config_aneg,
2061 .config_init = at803x_config_init,
2062 .soft_reset = genphy_soft_reset,
2063 .set_wol = at803x_set_wol,
2064 .get_wol = at803x_get_wol,
2065 .suspend = at803x_suspend,
2066 .resume = at803x_resume,
2067 /* PHY_GBIT_FEATURES */
2068 .read_status = at803x_read_status,
2069 .config_intr = at803x_config_intr,
2070 .handle_interrupt = at803x_handle_interrupt,
2071 .get_tunable = at803x_get_tunable,
2072 .set_tunable = at803x_set_tunable,
2073 .cable_test_start = at803x_cable_test_start,
2074 .cable_test_get_status = at803x_cable_test_get_status,
2076 /* Qualcomm Atheros AR8030 */
2077 .phy_id = ATH8030_PHY_ID,
2078 .name = "Qualcomm Atheros AR8030",
2079 .phy_id_mask = AT8030_PHY_ID_MASK,
2080 .probe = at803x_probe,
2081 .config_init = at803x_config_init,
2082 .link_change_notify = at803x_link_change_notify,
2083 .set_wol = at803x_set_wol,
2084 .get_wol = at803x_get_wol,
2085 .suspend = at803x_suspend,
2086 .resume = at803x_resume,
2087 /* PHY_BASIC_FEATURES */
2088 .config_intr = at803x_config_intr,
2089 .handle_interrupt = at803x_handle_interrupt,
2091 /* Qualcomm Atheros AR8031/AR8033 */
2092 PHY_ID_MATCH_EXACT(ATH8031_PHY_ID),
2093 .name = "Qualcomm Atheros AR8031/AR8033",
2094 .flags = PHY_POLL_CABLE_TEST,
2095 .probe = at803x_probe,
2096 .config_init = at803x_config_init,
2097 .config_aneg = at803x_config_aneg,
2098 .soft_reset = genphy_soft_reset,
2099 .set_wol = at803x_set_wol,
2100 .get_wol = at803x_get_wol,
2101 .suspend = at803x_suspend,
2102 .resume = at803x_resume,
2103 .read_page = at803x_read_page,
2104 .write_page = at803x_write_page,
2105 .get_features = at803x_get_features,
2106 .read_status = at803x_read_status,
2107 .config_intr = &at803x_config_intr,
2108 .handle_interrupt = at803x_handle_interrupt,
2109 .get_tunable = at803x_get_tunable,
2110 .set_tunable = at803x_set_tunable,
2111 .cable_test_start = at803x_cable_test_start,
2112 .cable_test_get_status = at803x_cable_test_get_status,
2114 /* Qualcomm Atheros AR8032 */
2115 PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
2116 .name = "Qualcomm Atheros AR8032",
2117 .probe = at803x_probe,
2118 .flags = PHY_POLL_CABLE_TEST,
2119 .config_init = at803x_config_init,
2120 .link_change_notify = at803x_link_change_notify,
2121 .suspend = at803x_suspend,
2122 .resume = at803x_resume,
2123 /* PHY_BASIC_FEATURES */
2124 .config_intr = at803x_config_intr,
2125 .handle_interrupt = at803x_handle_interrupt,
2126 .cable_test_start = at803x_cable_test_start,
2127 .cable_test_get_status = at803x_cable_test_get_status,
2129 /* ATHEROS AR9331 */
2130 PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
2131 .name = "Qualcomm Atheros AR9331 built-in PHY",
2132 .probe = at803x_probe,
2133 .suspend = at803x_suspend,
2134 .resume = at803x_resume,
2135 .flags = PHY_POLL_CABLE_TEST,
2136 /* PHY_BASIC_FEATURES */
2137 .config_intr = &at803x_config_intr,
2138 .handle_interrupt = at803x_handle_interrupt,
2139 .cable_test_start = at803x_cable_test_start,
2140 .cable_test_get_status = at803x_cable_test_get_status,
2141 .read_status = at803x_read_status,
2142 .soft_reset = genphy_soft_reset,
2143 .config_aneg = at803x_config_aneg,
2145 /* Qualcomm Atheros QCA9561 */
2146 PHY_ID_MATCH_EXACT(QCA9561_PHY_ID),
2147 .name = "Qualcomm Atheros QCA9561 built-in PHY",
2148 .probe = at803x_probe,
2149 .suspend = at803x_suspend,
2150 .resume = at803x_resume,
2151 .flags = PHY_POLL_CABLE_TEST,
2152 /* PHY_BASIC_FEATURES */
2153 .config_intr = &at803x_config_intr,
2154 .handle_interrupt = at803x_handle_interrupt,
2155 .cable_test_start = at803x_cable_test_start,
2156 .cable_test_get_status = at803x_cable_test_get_status,
2157 .read_status = at803x_read_status,
2158 .soft_reset = genphy_soft_reset,
2159 .config_aneg = at803x_config_aneg,
2162 .phy_id = QCA8337_PHY_ID,
2163 .phy_id_mask = QCA8K_PHY_ID_MASK,
2164 .name = "Qualcomm Atheros 8337 internal PHY",
2165 /* PHY_GBIT_FEATURES */
2166 .link_change_notify = qca83xx_link_change_notify,
2167 .probe = at803x_probe,
2168 .flags = PHY_IS_INTERNAL,
2169 .config_init = qca83xx_config_init,
2170 .soft_reset = genphy_soft_reset,
2171 .get_sset_count = at803x_get_sset_count,
2172 .get_strings = at803x_get_strings,
2173 .get_stats = at803x_get_stats,
2174 .suspend = qca83xx_suspend,
2175 .resume = qca83xx_resume,
2177 /* QCA8327-A from switch QCA8327-AL1A */
2178 .phy_id = QCA8327_A_PHY_ID,
2179 .phy_id_mask = QCA8K_PHY_ID_MASK,
2180 .name = "Qualcomm Atheros 8327-A internal PHY",
2181 /* PHY_GBIT_FEATURES */
2182 .link_change_notify = qca83xx_link_change_notify,
2183 .probe = at803x_probe,
2184 .flags = PHY_IS_INTERNAL,
2185 .config_init = qca83xx_config_init,
2186 .soft_reset = genphy_soft_reset,
2187 .get_sset_count = at803x_get_sset_count,
2188 .get_strings = at803x_get_strings,
2189 .get_stats = at803x_get_stats,
2190 .suspend = qca83xx_suspend,
2191 .resume = qca83xx_resume,
2193 /* QCA8327-B from switch QCA8327-BL1A */
2194 .phy_id = QCA8327_B_PHY_ID,
2195 .phy_id_mask = QCA8K_PHY_ID_MASK,
2196 .name = "Qualcomm Atheros 8327-B internal PHY",
2197 /* PHY_GBIT_FEATURES */
2198 .link_change_notify = qca83xx_link_change_notify,
2199 .probe = at803x_probe,
2200 .flags = PHY_IS_INTERNAL,
2201 .config_init = qca83xx_config_init,
2202 .soft_reset = genphy_soft_reset,
2203 .get_sset_count = at803x_get_sset_count,
2204 .get_strings = at803x_get_strings,
2205 .get_stats = at803x_get_stats,
2206 .suspend = qca83xx_suspend,
2207 .resume = qca83xx_resume,
2209 /* Qualcomm QCA8081 */
2210 PHY_ID_MATCH_EXACT(QCA8081_PHY_ID),
2211 .name = "Qualcomm QCA8081",
2212 .flags = PHY_POLL_CABLE_TEST,
2213 .probe = at803x_probe,
2214 .config_intr = at803x_config_intr,
2215 .handle_interrupt = at803x_handle_interrupt,
2216 .get_tunable = at803x_get_tunable,
2217 .set_tunable = at803x_set_tunable,
2218 .set_wol = at803x_set_wol,
2219 .get_wol = at803x_get_wol,
2220 .get_features = qca808x_get_features,
2221 .config_aneg = at803x_config_aneg,
2222 .suspend = genphy_suspend,
2223 .resume = genphy_resume,
2224 .read_status = qca808x_read_status,
2225 .config_init = qca808x_config_init,
2226 .soft_reset = qca808x_soft_reset,
2227 .cable_test_start = qca808x_cable_test_start,
2228 .cable_test_get_status = qca808x_cable_test_get_status,
2229 .link_change_notify = qca808x_link_change_notify,
2232 module_phy_driver(at803x_driver);
2234 static struct mdio_device_id __maybe_unused atheros_tbl[] = {
2235 { ATH8030_PHY_ID, AT8030_PHY_ID_MASK },
2236 { PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) },
2237 { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) },
2238 { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) },
2239 { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) },
2240 { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) },
2241 { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) },
2242 { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) },
2243 { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) },
2244 { PHY_ID_MATCH_EXACT(QCA8081_PHY_ID) },
2248 MODULE_DEVICE_TABLE(mdio, atheros_tbl);