blob: ae7e1f1c59f039cce05e96dea3cf075782bd7dc8 [file] [log] [blame]
Andrew Lunna2443fd2019-01-21 19:05:50 +01001// SPDX-License-Identifier: GPL-2.0+
Matus Ujhelyi0ca71112012-10-14 19:07:16 +00002/*
3 * drivers/net/phy/at803x.c
4 *
Michael Walle96c36712019-11-06 23:36:16 +01005 * Driver for Qualcomm Atheros AR803x PHY
Matus Ujhelyi0ca71112012-10-14 19:07:16 +00006 *
7 * Author: Matus Ujhelyi <ujhelyi.m@gmail.com>
Matus Ujhelyi0ca71112012-10-14 19:07:16 +00008 */
9
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>
Michael Walle6cb75762020-05-13 22:38:07 +020015#include <linux/ethtool_netlink.h>
Daniel Mack13a56b42014-06-18 11:01:43 +020016#include <linux/of_gpio.h>
Michael Walle2f664822019-11-06 23:36:14 +010017#include <linux/bitfield.h>
Daniel Mack13a56b42014-06-18 11:01:43 +020018#include <linux/gpio/consumer.h>
Michael Walle2f664822019-11-06 23:36:14 +010019#include <linux/regulator/of_regulator.h>
20#include <linux/regulator/driver.h>
21#include <linux/regulator/consumer.h>
22#include <dt-bindings/net/qca-ar803x.h>
Matus Ujhelyi0ca71112012-10-14 19:07:16 +000023
Oleksij Rempel7dce80c2020-07-19 10:05:30 +020024#define AT803X_SPECIFIC_FUNCTION_CONTROL 0x10
25#define AT803X_SFC_ASSERT_CRS BIT(11)
26#define AT803X_SFC_FORCE_LINK BIT(10)
27#define AT803X_SFC_MDI_CROSSOVER_MODE_M GENMASK(6, 5)
28#define AT803X_SFC_AUTOMATIC_CROSSOVER 0x3
29#define AT803X_SFC_MANUAL_MDIX 0x1
30#define AT803X_SFC_MANUAL_MDI 0x0
31#define AT803X_SFC_SQE_TEST BIT(2)
32#define AT803X_SFC_POLARITY_REVERSAL BIT(1)
33#define AT803X_SFC_DISABLE_JABBER BIT(0)
34
Russell King06d5f342019-10-04 17:06:14 +010035#define AT803X_SPECIFIC_STATUS 0x11
36#define AT803X_SS_SPEED_MASK (3 << 14)
37#define AT803X_SS_SPEED_1000 (2 << 14)
38#define AT803X_SS_SPEED_100 (1 << 14)
39#define AT803X_SS_SPEED_10 (0 << 14)
40#define AT803X_SS_DUPLEX BIT(13)
41#define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11)
42#define AT803X_SS_MDIX BIT(6)
43
Matus Ujhelyi0ca71112012-10-14 19:07:16 +000044#define AT803X_INTR_ENABLE 0x12
Martin Blumenstingle6e4a552016-01-15 01:55:24 +010045#define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15)
46#define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14)
47#define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13)
48#define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12)
49#define AT803X_INTR_ENABLE_LINK_FAIL BIT(11)
50#define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10)
51#define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5)
52#define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1)
53#define AT803X_INTR_ENABLE_WOL BIT(0)
54
Matus Ujhelyi0ca71112012-10-14 19:07:16 +000055#define AT803X_INTR_STATUS 0x13
Martin Blumenstingla46bd632016-01-15 01:55:23 +010056
Daniel Mack13a56b42014-06-18 11:01:43 +020057#define AT803X_SMART_SPEED 0x14
Michael Wallecde0f4f2020-04-28 23:15:02 +020058#define AT803X_SMART_SPEED_ENABLE BIT(5)
59#define AT803X_SMART_SPEED_RETRY_LIMIT_MASK GENMASK(4, 2)
60#define AT803X_SMART_SPEED_BYPASS_TIMER BIT(1)
Michael Walle6cb75762020-05-13 22:38:07 +020061#define AT803X_CDT 0x16
62#define AT803X_CDT_MDI_PAIR_MASK GENMASK(9, 8)
63#define AT803X_CDT_ENABLE_TEST BIT(0)
64#define AT803X_CDT_STATUS 0x1c
65#define AT803X_CDT_STATUS_STAT_NORMAL 0
66#define AT803X_CDT_STATUS_STAT_SHORT 1
67#define AT803X_CDT_STATUS_STAT_OPEN 2
68#define AT803X_CDT_STATUS_STAT_FAIL 3
69#define AT803X_CDT_STATUS_STAT_MASK GENMASK(9, 8)
70#define AT803X_CDT_STATUS_DELTA_TIME_MASK GENMASK(7, 0)
Daniel Mack13a56b42014-06-18 11:01:43 +020071#define AT803X_LED_CONTROL 0x18
Martin Blumenstingla46bd632016-01-15 01:55:23 +010072
Matus Ujhelyi0ca71112012-10-14 19:07:16 +000073#define AT803X_DEVICE_ADDR 0x03
74#define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C
75#define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B
76#define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A
Zefir Kurtisif62265b2016-10-24 12:40:54 +020077#define AT803X_REG_CHIP_CONFIG 0x1f
78#define AT803X_BT_BX_REG_SEL 0x8000
Martin Blumenstingla46bd632016-01-15 01:55:23 +010079
Mugunthan V N1ca6d1b2013-06-03 20:10:06 +000080#define AT803X_DEBUG_ADDR 0x1D
81#define AT803X_DEBUG_DATA 0x1E
Martin Blumenstingla46bd632016-01-15 01:55:23 +010082
Zefir Kurtisif62265b2016-10-24 12:40:54 +020083#define AT803X_MODE_CFG_MASK 0x0F
84#define AT803X_MODE_CFG_SGMII 0x01
85
Ansuel Smithd0e13fd2021-05-14 23:00:14 +020086#define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/
87#define AT803X_PSSR_MR_AN_COMPLETE 0x0200
Zefir Kurtisif62265b2016-10-24 12:40:54 +020088
Martin Blumenstingl2e5f9f22016-01-15 01:55:22 +010089#define AT803X_DEBUG_REG_0 0x00
90#define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15)
Martin Blumenstingla46bd632016-01-15 01:55:23 +010091
Martin Blumenstingl2e5f9f22016-01-15 01:55:22 +010092#define AT803X_DEBUG_REG_5 0x05
93#define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8)
Matus Ujhelyi0ca71112012-10-14 19:07:16 +000094
Ansuel Smith272833b2021-05-14 23:00:15 +020095#define AT803X_DEBUG_REG_3C 0x3C
96
97#define AT803X_DEBUG_REG_3D 0x3D
98
Michael Walle2f664822019-11-06 23:36:14 +010099#define AT803X_DEBUG_REG_1F 0x1F
100#define AT803X_DEBUG_PLL_ON BIT(2)
101#define AT803X_DEBUG_RGMII_1V8 BIT(3)
102
Ansuel Smith272833b2021-05-14 23:00:15 +0200103#define MDIO_AZ_DEBUG 0x800D
104
Michael Walle2f664822019-11-06 23:36:14 +0100105/* AT803x supports either the XTAL input pad, an internal PLL or the
106 * DSP as clock reference for the clock output pad. The XTAL reference
107 * is only used for 25 MHz output, all other frequencies need the PLL.
108 * The DSP as a clock reference is used in synchronous ethernet
109 * applications.
110 *
111 * By default the PLL is only enabled if there is a link. Otherwise
112 * the PHY will go into low power state and disabled the PLL. You can
113 * set the PLL_ON bit (see debug register 0x1f) to keep the PLL always
114 * enabled.
115 */
116#define AT803X_MMD7_CLK25M 0x8016
117#define AT803X_CLK_OUT_MASK GENMASK(4, 2)
118#define AT803X_CLK_OUT_25MHZ_XTAL 0
119#define AT803X_CLK_OUT_25MHZ_DSP 1
120#define AT803X_CLK_OUT_50MHZ_PLL 2
121#define AT803X_CLK_OUT_50MHZ_DSP 3
122#define AT803X_CLK_OUT_62_5MHZ_PLL 4
123#define AT803X_CLK_OUT_62_5MHZ_DSP 5
124#define AT803X_CLK_OUT_125MHZ_PLL 6
125#define AT803X_CLK_OUT_125MHZ_DSP 7
126
Michael Walle428061f2019-11-06 23:36:15 +0100127/* The AR8035 has another mask which is compatible with the AR8031/AR8033 mask
128 * but doesn't support choosing between XTAL/PLL and DSP.
Michael Walle2f664822019-11-06 23:36:14 +0100129 */
130#define AT8035_CLK_OUT_MASK GENMASK(4, 3)
131
132#define AT803X_CLK_OUT_STRENGTH_MASK GENMASK(8, 7)
133#define AT803X_CLK_OUT_STRENGTH_FULL 0
134#define AT803X_CLK_OUT_STRENGTH_HALF 1
135#define AT803X_CLK_OUT_STRENGTH_QUARTER 2
136
Ansuel Smithd0e13fd2021-05-14 23:00:14 +0200137#define AT803X_DEFAULT_DOWNSHIFT 5
138#define AT803X_MIN_DOWNSHIFT 2
139#define AT803X_MAX_DOWNSHIFT 9
Michael Wallecde0f4f2020-04-28 23:15:02 +0200140
Russell King390b4ca2021-01-14 10:45:49 +0000141#define AT803X_MMD3_SMARTEEE_CTL1 0x805b
142#define AT803X_MMD3_SMARTEEE_CTL2 0x805c
143#define AT803X_MMD3_SMARTEEE_CTL3 0x805d
144#define AT803X_MMD3_SMARTEEE_CTL3_LPI_EN BIT(8)
145
Ansuel Smithd0e13fd2021-05-14 23:00:14 +0200146#define ATH9331_PHY_ID 0x004dd041
147#define ATH8030_PHY_ID 0x004dd076
148#define ATH8031_PHY_ID 0x004dd074
149#define ATH8032_PHY_ID 0x004dd023
150#define ATH8035_PHY_ID 0x004dd072
Michael Walle0465d8f2020-05-22 11:53:31 +0200151#define AT8030_PHY_ID_MASK 0xffffffef
Daniel Mackbd8ca172014-06-18 11:01:42 +0200152
Ansuel Smithb4df02b2021-09-19 18:28:15 +0200153#define QCA8327_A_PHY_ID 0x004dd033
154#define QCA8327_B_PHY_ID 0x004dd034
Ansuel Smith272833b2021-05-14 23:00:15 +0200155#define QCA8337_PHY_ID 0x004dd036
David Bauerfada2ce2021-10-06 00:54:01 +0200156#define QCA9561_PHY_ID 0x004dd042
Ansuel Smith272833b2021-05-14 23:00:15 +0200157#define QCA8K_PHY_ID_MASK 0xffffffff
158
159#define QCA8K_DEVFLAGS_REVISION_MASK GENMASK(2, 0)
160
Ansuel Smithd0e13fd2021-05-14 23:00:14 +0200161#define AT803X_PAGE_FIBER 0
162#define AT803X_PAGE_COPPER 1
163
164/* don't turn off internal PLL */
165#define AT803X_KEEP_PLL_ENABLED BIT(0)
166#define AT803X_DISABLE_SMARTEEE BIT(1)
David Bauerc329e5a2021-04-15 03:26:50 +0200167
Michael Walle96c36712019-11-06 23:36:16 +0100168MODULE_DESCRIPTION("Qualcomm Atheros AR803x PHY driver");
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000169MODULE_AUTHOR("Matus Ujhelyi");
170MODULE_LICENSE("GPL");
171
Ansuel Smith272833b2021-05-14 23:00:15 +0200172enum stat_access_type {
173 PHY,
174 MMD
175};
176
177struct at803x_hw_stat {
178 const char *string;
179 u8 reg;
180 u32 mask;
181 enum stat_access_type access_type;
182};
183
184static struct at803x_hw_stat at803x_hw_stats[] = {
185 { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
186 { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
187 { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
188};
189
Michael Walle2f664822019-11-06 23:36:14 +0100190struct at803x_priv {
191 int flags;
Michael Walle2f664822019-11-06 23:36:14 +0100192 u16 clk_25m_reg;
193 u16 clk_25m_mask;
Russell King390b4ca2021-01-14 10:45:49 +0000194 u8 smarteee_lpi_tw_1g;
195 u8 smarteee_lpi_tw_100m;
Michael Walle2f664822019-11-06 23:36:14 +0100196 struct regulator_dev *vddio_rdev;
197 struct regulator_dev *vddh_rdev;
198 struct regulator *vddio;
Ansuel Smith272833b2021-05-14 23:00:15 +0200199 u64 stats[ARRAY_SIZE(at803x_hw_stats)];
Michael Walle2f664822019-11-06 23:36:14 +0100200};
201
Daniel Mack13a56b42014-06-18 11:01:43 +0200202struct at803x_context {
203 u16 bmcr;
204 u16 advertise;
205 u16 control1000;
206 u16 int_enable;
207 u16 smart_speed;
208 u16 led_control;
209};
210
Ansuel Smith272833b2021-05-14 23:00:15 +0200211static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data)
212{
213 int ret;
214
215 ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
216 if (ret < 0)
217 return ret;
218
219 return phy_write(phydev, AT803X_DEBUG_DATA, data);
220}
221
Martin Blumenstingl2e5f9f22016-01-15 01:55:22 +0100222static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
223{
224 int ret;
225
226 ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
227 if (ret < 0)
228 return ret;
229
230 return phy_read(phydev, AT803X_DEBUG_DATA);
231}
232
233static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
234 u16 clear, u16 set)
235{
236 u16 val;
237 int ret;
238
239 ret = at803x_debug_reg_read(phydev, reg);
240 if (ret < 0)
241 return ret;
242
243 val = ret & 0xffff;
244 val &= ~clear;
245 val |= set;
246
247 return phy_write(phydev, AT803X_DEBUG_DATA, val);
248}
249
David Bauerc329e5a2021-04-15 03:26:50 +0200250static int at803x_write_page(struct phy_device *phydev, int page)
251{
252 int mask;
253 int set;
254
255 if (page == AT803X_PAGE_COPPER) {
256 set = AT803X_BT_BX_REG_SEL;
257 mask = 0;
258 } else {
259 set = 0;
260 mask = AT803X_BT_BX_REG_SEL;
261 }
262
263 return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set);
264}
265
266static int at803x_read_page(struct phy_device *phydev)
267{
268 int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG);
269
270 if (ccr < 0)
271 return ccr;
272
273 if (ccr & AT803X_BT_BX_REG_SEL)
274 return AT803X_PAGE_COPPER;
275
276 return AT803X_PAGE_FIBER;
277}
278
Vinod Koul6d4cd042019-02-21 15:53:15 +0530279static int at803x_enable_rx_delay(struct phy_device *phydev)
280{
281 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0,
282 AT803X_DEBUG_RX_CLK_DLY_EN);
283}
284
285static int at803x_enable_tx_delay(struct phy_device *phydev)
286{
287 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0,
288 AT803X_DEBUG_TX_CLK_DLY_EN);
289}
290
Vinod Koul43f2ebd2019-02-21 15:53:14 +0530291static int at803x_disable_rx_delay(struct phy_device *phydev)
Martin Blumenstingl2e5f9f22016-01-15 01:55:22 +0100292{
Vinod Koulcd28d1d2019-01-21 14:43:17 +0530293 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0,
294 AT803X_DEBUG_RX_CLK_DLY_EN, 0);
Martin Blumenstingl2e5f9f22016-01-15 01:55:22 +0100295}
296
Vinod Koul43f2ebd2019-02-21 15:53:14 +0530297static int at803x_disable_tx_delay(struct phy_device *phydev)
Martin Blumenstingl2e5f9f22016-01-15 01:55:22 +0100298{
Vinod Koulcd28d1d2019-01-21 14:43:17 +0530299 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
300 AT803X_DEBUG_TX_CLK_DLY_EN, 0);
Martin Blumenstingl2e5f9f22016-01-15 01:55:22 +0100301}
302
Daniel Mack13a56b42014-06-18 11:01:43 +0200303/* save relevant PHY registers to private copy */
304static void at803x_context_save(struct phy_device *phydev,
305 struct at803x_context *context)
306{
307 context->bmcr = phy_read(phydev, MII_BMCR);
308 context->advertise = phy_read(phydev, MII_ADVERTISE);
309 context->control1000 = phy_read(phydev, MII_CTRL1000);
310 context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE);
311 context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED);
312 context->led_control = phy_read(phydev, AT803X_LED_CONTROL);
313}
314
315/* restore relevant PHY registers from private copy */
316static void at803x_context_restore(struct phy_device *phydev,
317 const struct at803x_context *context)
318{
319 phy_write(phydev, MII_BMCR, context->bmcr);
320 phy_write(phydev, MII_ADVERTISE, context->advertise);
321 phy_write(phydev, MII_CTRL1000, context->control1000);
322 phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable);
323 phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed);
324 phy_write(phydev, AT803X_LED_CONTROL, context->led_control);
325}
326
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000327static int at803x_set_wol(struct phy_device *phydev,
328 struct ethtool_wolinfo *wol)
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000329{
330 struct net_device *ndev = phydev->attached_dev;
331 const u8 *mac;
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000332 int ret;
333 u32 value;
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000334 unsigned int i, offsets[] = {
335 AT803X_LOC_MAC_ADDR_32_47_OFFSET,
336 AT803X_LOC_MAC_ADDR_16_31_OFFSET,
337 AT803X_LOC_MAC_ADDR_0_15_OFFSET,
338 };
339
340 if (!ndev)
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000341 return -ENODEV;
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000342
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000343 if (wol->wolopts & WAKE_MAGIC) {
344 mac = (const u8 *) ndev->dev_addr;
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000345
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000346 if (!is_valid_ether_addr(mac))
Dan Murphyfc755682017-10-10 12:42:56 -0500347 return -EINVAL;
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000348
Carlo Caione0e021392019-01-25 12:35:10 +0000349 for (i = 0; i < 3; i++)
350 phy_write_mmd(phydev, AT803X_DEVICE_ADDR, offsets[i],
351 mac[(i * 2) + 1] | (mac[(i * 2)] << 8));
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000352
353 value = phy_read(phydev, AT803X_INTR_ENABLE);
Martin Blumenstingle6e4a552016-01-15 01:55:24 +0100354 value |= AT803X_INTR_ENABLE_WOL;
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000355 ret = phy_write(phydev, AT803X_INTR_ENABLE, value);
356 if (ret)
357 return ret;
358 value = phy_read(phydev, AT803X_INTR_STATUS);
359 } else {
360 value = phy_read(phydev, AT803X_INTR_ENABLE);
Martin Blumenstingle6e4a552016-01-15 01:55:24 +0100361 value &= (~AT803X_INTR_ENABLE_WOL);
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000362 ret = phy_write(phydev, AT803X_INTR_ENABLE, value);
363 if (ret)
364 return ret;
365 value = phy_read(phydev, AT803X_INTR_STATUS);
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000366 }
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000367
368 return ret;
369}
370
371static void at803x_get_wol(struct phy_device *phydev,
372 struct ethtool_wolinfo *wol)
373{
374 u32 value;
375
376 wol->supported = WAKE_MAGIC;
377 wol->wolopts = 0;
378
379 value = phy_read(phydev, AT803X_INTR_ENABLE);
Martin Blumenstingle6e4a552016-01-15 01:55:24 +0100380 if (value & AT803X_INTR_ENABLE_WOL)
Mugunthan V Nea13c9e2013-06-03 20:10:05 +0000381 wol->wolopts |= WAKE_MAGIC;
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000382}
383
Ansuel Smith272833b2021-05-14 23:00:15 +0200384static int at803x_get_sset_count(struct phy_device *phydev)
385{
386 return ARRAY_SIZE(at803x_hw_stats);
387}
388
389static void at803x_get_strings(struct phy_device *phydev, u8 *data)
390{
391 int i;
392
393 for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) {
394 strscpy(data + i * ETH_GSTRING_LEN,
395 at803x_hw_stats[i].string, ETH_GSTRING_LEN);
396 }
397}
398
399static u64 at803x_get_stat(struct phy_device *phydev, int i)
400{
401 struct at803x_hw_stat stat = at803x_hw_stats[i];
402 struct at803x_priv *priv = phydev->priv;
403 int val;
404 u64 ret;
405
406 if (stat.access_type == MMD)
407 val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg);
408 else
409 val = phy_read(phydev, stat.reg);
410
411 if (val < 0) {
412 ret = U64_MAX;
413 } else {
414 val = val & stat.mask;
415 priv->stats[i] += val;
416 ret = priv->stats[i];
417 }
418
419 return ret;
420}
421
422static void at803x_get_stats(struct phy_device *phydev,
423 struct ethtool_stats *stats, u64 *data)
424{
425 int i;
426
427 for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++)
428 data[i] = at803x_get_stat(phydev, i);
429}
430
Daniel Mack6229ed12013-09-21 16:53:02 +0200431static int at803x_suspend(struct phy_device *phydev)
432{
433 int value;
434 int wol_enabled;
435
Daniel Mack6229ed12013-09-21 16:53:02 +0200436 value = phy_read(phydev, AT803X_INTR_ENABLE);
Martin Blumenstingle6e4a552016-01-15 01:55:24 +0100437 wol_enabled = value & AT803X_INTR_ENABLE_WOL;
Daniel Mack6229ed12013-09-21 16:53:02 +0200438
Daniel Mack6229ed12013-09-21 16:53:02 +0200439 if (wol_enabled)
Russell Kingfea23fb2018-01-02 10:58:58 +0000440 value = BMCR_ISOLATE;
Daniel Mack6229ed12013-09-21 16:53:02 +0200441 else
Russell Kingfea23fb2018-01-02 10:58:58 +0000442 value = BMCR_PDOWN;
Daniel Mack6229ed12013-09-21 16:53:02 +0200443
Russell Kingfea23fb2018-01-02 10:58:58 +0000444 phy_modify(phydev, MII_BMCR, 0, value);
Daniel Mack6229ed12013-09-21 16:53:02 +0200445
446 return 0;
447}
448
449static int at803x_resume(struct phy_device *phydev)
450{
Russell Kingf1028522018-01-05 16:07:10 +0000451 return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
Daniel Mack6229ed12013-09-21 16:53:02 +0200452}
453
Michael Walle2f664822019-11-06 23:36:14 +0100454static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
455 unsigned int selector)
456{
457 struct phy_device *phydev = rdev_get_drvdata(rdev);
458
459 if (selector)
460 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
461 0, AT803X_DEBUG_RGMII_1V8);
462 else
463 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
464 AT803X_DEBUG_RGMII_1V8, 0);
465}
466
467static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
468{
469 struct phy_device *phydev = rdev_get_drvdata(rdev);
470 int val;
471
472 val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
473 if (val < 0)
474 return val;
475
476 return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
477}
478
Rikard Falkeborn3faaf532020-08-27 00:56:06 +0200479static const struct regulator_ops vddio_regulator_ops = {
Michael Walle2f664822019-11-06 23:36:14 +0100480 .list_voltage = regulator_list_voltage_table,
481 .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel,
482 .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel,
483};
484
485static const unsigned int vddio_voltage_table[] = {
486 1500000,
487 1800000,
488};
489
490static const struct regulator_desc vddio_desc = {
491 .name = "vddio",
492 .of_match = of_match_ptr("vddio-regulator"),
493 .n_voltages = ARRAY_SIZE(vddio_voltage_table),
494 .volt_table = vddio_voltage_table,
495 .ops = &vddio_regulator_ops,
496 .type = REGULATOR_VOLTAGE,
497 .owner = THIS_MODULE,
498};
499
Rikard Falkeborn3faaf532020-08-27 00:56:06 +0200500static const struct regulator_ops vddh_regulator_ops = {
Michael Walle2f664822019-11-06 23:36:14 +0100501};
502
503static const struct regulator_desc vddh_desc = {
504 .name = "vddh",
505 .of_match = of_match_ptr("vddh-regulator"),
506 .n_voltages = 1,
507 .fixed_uV = 2500000,
508 .ops = &vddh_regulator_ops,
509 .type = REGULATOR_VOLTAGE,
510 .owner = THIS_MODULE,
511};
512
513static int at8031_register_regulators(struct phy_device *phydev)
514{
515 struct at803x_priv *priv = phydev->priv;
516 struct device *dev = &phydev->mdio.dev;
517 struct regulator_config config = { };
518
519 config.dev = dev;
520 config.driver_data = phydev;
521
522 priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
523 if (IS_ERR(priv->vddio_rdev)) {
524 phydev_err(phydev, "failed to register VDDIO regulator\n");
525 return PTR_ERR(priv->vddio_rdev);
526 }
527
528 priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
529 if (IS_ERR(priv->vddh_rdev)) {
530 phydev_err(phydev, "failed to register VDDH regulator\n");
531 return PTR_ERR(priv->vddh_rdev);
532 }
533
534 return 0;
535}
536
Michael Walle2f664822019-11-06 23:36:14 +0100537static int at803x_parse_dt(struct phy_device *phydev)
538{
539 struct device_node *node = phydev->mdio.dev.of_node;
540 struct at803x_priv *priv = phydev->priv;
Russell King390b4ca2021-01-14 10:45:49 +0000541 u32 freq, strength, tw;
Andrew Lunn3f2edd32020-07-07 03:49:33 +0200542 unsigned int sel;
Michael Walle2f664822019-11-06 23:36:14 +0100543 int ret;
544
545 if (!IS_ENABLED(CONFIG_OF_MDIO))
546 return 0;
547
Russell King390b4ca2021-01-14 10:45:49 +0000548 if (of_property_read_bool(node, "qca,disable-smarteee"))
549 priv->flags |= AT803X_DISABLE_SMARTEEE;
550
551 if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) {
552 if (!tw || tw > 255) {
553 phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n");
554 return -EINVAL;
555 }
556 priv->smarteee_lpi_tw_1g = tw;
557 }
558
559 if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) {
560 if (!tw || tw > 255) {
561 phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n");
562 return -EINVAL;
563 }
564 priv->smarteee_lpi_tw_100m = tw;
565 }
566
Michael Walle2f664822019-11-06 23:36:14 +0100567 ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq);
568 if (!ret) {
Michael Walle2f664822019-11-06 23:36:14 +0100569 switch (freq) {
570 case 25000000:
571 sel = AT803X_CLK_OUT_25MHZ_XTAL;
572 break;
573 case 50000000:
574 sel = AT803X_CLK_OUT_50MHZ_PLL;
575 break;
576 case 62500000:
577 sel = AT803X_CLK_OUT_62_5MHZ_PLL;
578 break;
579 case 125000000:
580 sel = AT803X_CLK_OUT_125MHZ_PLL;
581 break;
582 default:
583 phydev_err(phydev, "invalid qca,clk-out-frequency\n");
584 return -EINVAL;
585 }
586
Andrew Lunn3f2edd32020-07-07 03:49:33 +0200587 priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel);
588 priv->clk_25m_mask |= AT803X_CLK_OUT_MASK;
Michael Walle2f664822019-11-06 23:36:14 +0100589
590 /* Fixup for the AR8030/AR8035. This chip has another mask and
591 * doesn't support the DSP reference. Eg. the lowest bit of the
592 * mask. The upper two bits select the same frequencies. Mask
593 * the lowest bit here.
594 *
595 * Warning:
596 * There was no datasheet for the AR8030 available so this is
597 * just a guess. But the AR8035 is listed as pin compatible
598 * to the AR8030 so there might be a good chance it works on
599 * the AR8030 too.
600 */
Russell King8887ca52021-07-20 14:33:49 +0100601 if (phydev->drv->phy_id == ATH8030_PHY_ID ||
602 phydev->drv->phy_id == ATH8035_PHY_ID) {
Oleksij Rempelb1f4c202020-04-01 11:57:32 +0200603 priv->clk_25m_reg &= AT8035_CLK_OUT_MASK;
604 priv->clk_25m_mask &= AT8035_CLK_OUT_MASK;
Michael Walle2f664822019-11-06 23:36:14 +0100605 }
606 }
607
608 ret = of_property_read_u32(node, "qca,clk-out-strength", &strength);
609 if (!ret) {
610 priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK;
611 switch (strength) {
612 case AR803X_STRENGTH_FULL:
613 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL;
614 break;
615 case AR803X_STRENGTH_HALF:
616 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF;
617 break;
618 case AR803X_STRENGTH_QUARTER:
619 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER;
620 break;
621 default:
622 phydev_err(phydev, "invalid qca,clk-out-strength\n");
623 return -EINVAL;
624 }
625 }
626
Michael Walle428061f2019-11-06 23:36:15 +0100627 /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping
628 * options.
629 */
Russell King8887ca52021-07-20 14:33:49 +0100630 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
Michael Walle2f664822019-11-06 23:36:14 +0100631 if (of_property_read_bool(node, "qca,keep-pll-enabled"))
632 priv->flags |= AT803X_KEEP_PLL_ENABLED;
633
634 ret = at8031_register_regulators(phydev);
635 if (ret < 0)
636 return ret;
637
638 priv->vddio = devm_regulator_get_optional(&phydev->mdio.dev,
639 "vddio");
640 if (IS_ERR(priv->vddio)) {
641 phydev_err(phydev, "failed to get VDDIO regulator\n");
642 return PTR_ERR(priv->vddio);
643 }
Michael Walle2f664822019-11-06 23:36:14 +0100644 }
645
646 return 0;
647}
648
649static int at803x_probe(struct phy_device *phydev)
650{
651 struct device *dev = &phydev->mdio.dev;
652 struct at803x_priv *priv;
David Bauerc329e5a2021-04-15 03:26:50 +0200653 int ret;
Michael Walle2f664822019-11-06 23:36:14 +0100654
655 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
656 if (!priv)
657 return -ENOMEM;
658
659 phydev->priv = priv;
660
David Bauerc329e5a2021-04-15 03:26:50 +0200661 ret = at803x_parse_dt(phydev);
662 if (ret)
663 return ret;
664
Michael Walle8f7e8762021-04-20 12:29:29 +0200665 if (priv->vddio) {
666 ret = regulator_enable(priv->vddio);
667 if (ret < 0)
668 return ret;
669 }
670
David Bauerc329e5a2021-04-15 03:26:50 +0200671 /* Some bootloaders leave the fiber page selected.
672 * Switch to the copper page, as otherwise we read
673 * the PHY capabilities from the fiber side.
674 */
Russell King8887ca52021-07-20 14:33:49 +0100675 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
Michael Walle8f7e8762021-04-20 12:29:29 +0200676 phy_lock_mdio_bus(phydev);
677 ret = at803x_write_page(phydev, AT803X_PAGE_COPPER);
678 phy_unlock_mdio_bus(phydev);
679 if (ret)
680 goto err;
David Bauerc329e5a2021-04-15 03:26:50 +0200681 }
682
Michael Walle8f7e8762021-04-20 12:29:29 +0200683 return 0;
684
685err:
686 if (priv->vddio)
687 regulator_disable(priv->vddio);
688
David Bauerc329e5a2021-04-15 03:26:50 +0200689 return ret;
Michael Walle2f664822019-11-06 23:36:14 +0100690}
691
Michael Walle2318ca82020-01-30 18:54:02 +0100692static void at803x_remove(struct phy_device *phydev)
693{
694 struct at803x_priv *priv = phydev->priv;
695
696 if (priv->vddio)
697 regulator_disable(priv->vddio);
698}
699
David Bauerb8561502021-06-27 12:16:07 +0200700static int at803x_get_features(struct phy_device *phydev)
701{
702 int err;
703
704 err = genphy_read_abilities(phydev);
705 if (err)
706 return err;
707
Vladimir Olteanf5621a02021-07-20 20:24:33 +0300708 if (phydev->drv->phy_id != ATH8031_PHY_ID)
David Bauerb8561502021-06-27 12:16:07 +0200709 return 0;
710
711 /* AR8031/AR8033 have different status registers
712 * for copper and fiber operation. However, the
713 * extended status register is the same for both
714 * operation modes.
715 *
716 * As a result of that, ESTATUS_1000_XFULL is set
717 * to 1 even when operating in copper TP mode.
718 *
719 * Remove this mode from the supported link modes,
720 * as this driver currently only supports copper
721 * operation.
722 */
723 linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
724 phydev->supported);
725 return 0;
726}
727
Russell King390b4ca2021-01-14 10:45:49 +0000728static int at803x_smarteee_config(struct phy_device *phydev)
729{
730 struct at803x_priv *priv = phydev->priv;
731 u16 mask = 0, val = 0;
732 int ret;
733
734 if (priv->flags & AT803X_DISABLE_SMARTEEE)
735 return phy_modify_mmd(phydev, MDIO_MMD_PCS,
736 AT803X_MMD3_SMARTEEE_CTL3,
737 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0);
738
739 if (priv->smarteee_lpi_tw_1g) {
740 mask |= 0xff00;
741 val |= priv->smarteee_lpi_tw_1g << 8;
742 }
743 if (priv->smarteee_lpi_tw_100m) {
744 mask |= 0x00ff;
745 val |= priv->smarteee_lpi_tw_100m;
746 }
747 if (!mask)
748 return 0;
749
750 ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1,
751 mask, val);
752 if (ret)
753 return ret;
754
755 return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3,
756 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN,
757 AT803X_MMD3_SMARTEEE_CTL3_LPI_EN);
758}
759
Michael Walle2f664822019-11-06 23:36:14 +0100760static int at803x_clk_out_config(struct phy_device *phydev)
761{
762 struct at803x_priv *priv = phydev->priv;
Michael Walle2f664822019-11-06 23:36:14 +0100763
764 if (!priv->clk_25m_mask)
765 return 0;
766
Russell Kinga45c1c12021-01-10 14:54:36 +0000767 return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M,
768 priv->clk_25m_mask, priv->clk_25m_reg);
Michael Walle2f664822019-11-06 23:36:14 +0100769}
770
771static int at8031_pll_config(struct phy_device *phydev)
772{
773 struct at803x_priv *priv = phydev->priv;
774
775 /* The default after hardware reset is PLL OFF. After a soft reset, the
776 * values are retained.
777 */
778 if (priv->flags & AT803X_KEEP_PLL_ENABLED)
779 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
780 0, AT803X_DEBUG_PLL_ON);
781 else
782 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
783 AT803X_DEBUG_PLL_ON, 0);
784}
785
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000786static int at803x_config_init(struct phy_device *phydev)
787{
Mugunthan V N1ca6d1b2013-06-03 20:10:06 +0000788 int ret;
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000789
Vinod Koul6d4cd042019-02-21 15:53:15 +0530790 /* The RX and TX delay default is:
791 * after HW reset: RX delay enabled and TX delay disabled
792 * after SW reset: RX delay enabled, while TX delay retains the
793 * value before reset.
Vinod Koul6d4cd042019-02-21 15:53:15 +0530794 */
Vinod Koul6d4cd042019-02-21 15:53:15 +0530795 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
André Draszikbb0ce4c2019-08-09 12:20:25 +0100796 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
Vinod Koul6d4cd042019-02-21 15:53:15 +0530797 ret = at803x_enable_rx_delay(phydev);
André Draszikbb0ce4c2019-08-09 12:20:25 +0100798 else
799 ret = at803x_disable_rx_delay(phydev);
800 if (ret < 0)
801 return ret;
Martin Blumenstingl2e5f9f22016-01-15 01:55:22 +0100802
Vinod Koul6d4cd042019-02-21 15:53:15 +0530803 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
André Draszikbb0ce4c2019-08-09 12:20:25 +0100804 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
Vinod Koul6d4cd042019-02-21 15:53:15 +0530805 ret = at803x_enable_tx_delay(phydev);
André Draszikbb0ce4c2019-08-09 12:20:25 +0100806 else
807 ret = at803x_disable_tx_delay(phydev);
Michael Walle2f664822019-11-06 23:36:14 +0100808 if (ret < 0)
809 return ret;
Mugunthan V N1ca6d1b2013-06-03 20:10:06 +0000810
Russell King390b4ca2021-01-14 10:45:49 +0000811 ret = at803x_smarteee_config(phydev);
812 if (ret < 0)
813 return ret;
814
Michael Walle2f664822019-11-06 23:36:14 +0100815 ret = at803x_clk_out_config(phydev);
816 if (ret < 0)
817 return ret;
818
Russell King8887ca52021-07-20 14:33:49 +0100819 if (phydev->drv->phy_id == ATH8031_PHY_ID) {
Michael Walle2f664822019-11-06 23:36:14 +0100820 ret = at8031_pll_config(phydev);
821 if (ret < 0)
822 return ret;
823 }
824
Russell King3c51fa52021-01-12 22:59:43 +0000825 /* Ar803x extended next page bit is enabled by default. Cisco
826 * multigig switches read this bit and attempt to negotiate 10Gbps
827 * rates even if the next page bit is disabled. This is incorrect
828 * behaviour but we still need to accommodate it. XNP is only needed
829 * for 10Gbps support, so disable XNP.
830 */
831 return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0);
Matus Ujhelyi0ca71112012-10-14 19:07:16 +0000832}
833
Zhao Qiang77a99392014-03-28 15:39:41 +0800834static int at803x_ack_interrupt(struct phy_device *phydev)
835{
836 int err;
837
Martin Blumenstingla46bd632016-01-15 01:55:23 +0100838 err = phy_read(phydev, AT803X_INTR_STATUS);
Zhao Qiang77a99392014-03-28 15:39:41 +0800839
840 return (err < 0) ? err : 0;
841}
842
843static int at803x_config_intr(struct phy_device *phydev)
844{
845 int err;
846 int value;
847
Martin Blumenstingla46bd632016-01-15 01:55:23 +0100848 value = phy_read(phydev, AT803X_INTR_ENABLE);
Zhao Qiang77a99392014-03-28 15:39:41 +0800849
Martin Blumenstingle6e4a552016-01-15 01:55:24 +0100850 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
Ioana Ciorneia3417882020-11-01 14:51:00 +0200851 /* Clear any pending interrupts */
852 err = at803x_ack_interrupt(phydev);
853 if (err)
854 return err;
855
Martin Blumenstingle6e4a552016-01-15 01:55:24 +0100856 value |= AT803X_INTR_ENABLE_AUTONEG_ERR;
857 value |= AT803X_INTR_ENABLE_SPEED_CHANGED;
858 value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED;
859 value |= AT803X_INTR_ENABLE_LINK_FAIL;
860 value |= AT803X_INTR_ENABLE_LINK_SUCCESS;
861
862 err = phy_write(phydev, AT803X_INTR_ENABLE, value);
Ioana Ciorneia3417882020-11-01 14:51:00 +0200863 } else {
Martin Blumenstingla46bd632016-01-15 01:55:23 +0100864 err = phy_write(phydev, AT803X_INTR_ENABLE, 0);
Ioana Ciorneia3417882020-11-01 14:51:00 +0200865 if (err)
866 return err;
867
868 /* Clear any pending interrupts */
869 err = at803x_ack_interrupt(phydev);
870 }
Zhao Qiang77a99392014-03-28 15:39:41 +0800871
872 return err;
873}
874
Ioana Ciornei29773092020-11-01 14:50:59 +0200875static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev)
876{
877 int irq_status, int_enabled;
878
879 irq_status = phy_read(phydev, AT803X_INTR_STATUS);
880 if (irq_status < 0) {
881 phy_error(phydev);
882 return IRQ_NONE;
883 }
884
885 /* Read the current enabled interrupts */
886 int_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
887 if (int_enabled < 0) {
888 phy_error(phydev);
889 return IRQ_NONE;
890 }
891
892 /* See if this was one of our enabled interrupts */
893 if (!(irq_status & int_enabled))
894 return IRQ_NONE;
895
896 phy_trigger_machine(phydev);
897
898 return IRQ_HANDLED;
899}
900
Daniel Mack13a56b42014-06-18 11:01:43 +0200901static void at803x_link_change_notify(struct phy_device *phydev)
902{
Daniel Mack13a56b42014-06-18 11:01:43 +0200903 /*
904 * Conduct a hardware reset for AT8030 every time a link loss is
905 * signalled. This is necessary to circumvent a hardware bug that
906 * occurs when the cable is unplugged while TX packets are pending
907 * in the FIFO. In such cases, the FIFO enters an error mode it
908 * cannot recover from by software.
909 */
David Bauer6110ed22019-04-17 23:59:22 +0200910 if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) {
Heiner Kallweit5c5f6262019-03-19 19:56:51 +0100911 struct at803x_context context;
Daniel Mack13a56b42014-06-18 11:01:43 +0200912
Heiner Kallweit5c5f6262019-03-19 19:56:51 +0100913 at803x_context_save(phydev, &context);
Daniel Mack13a56b42014-06-18 11:01:43 +0200914
Heiner Kallweit5c5f6262019-03-19 19:56:51 +0100915 phy_device_reset(phydev, 1);
916 msleep(1);
917 phy_device_reset(phydev, 0);
918 msleep(1);
Daniel Mack13a56b42014-06-18 11:01:43 +0200919
Heiner Kallweit5c5f6262019-03-19 19:56:51 +0100920 at803x_context_restore(phydev, &context);
Daniel Mack13a56b42014-06-18 11:01:43 +0200921
Heiner Kallweit5c5f6262019-03-19 19:56:51 +0100922 phydev_dbg(phydev, "%s(): phy was reset\n", __func__);
Daniel Mack13a56b42014-06-18 11:01:43 +0200923 }
924}
925
Russell King06d5f342019-10-04 17:06:14 +0100926static int at803x_read_status(struct phy_device *phydev)
927{
928 int ss, err, old_link = phydev->link;
929
930 /* Update the link, but return if there was an error */
931 err = genphy_update_link(phydev);
932 if (err)
933 return err;
934
935 /* why bother the PHY if nothing can have changed */
936 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
937 return 0;
938
939 phydev->speed = SPEED_UNKNOWN;
940 phydev->duplex = DUPLEX_UNKNOWN;
941 phydev->pause = 0;
942 phydev->asym_pause = 0;
943
944 err = genphy_read_lpa(phydev);
945 if (err < 0)
946 return err;
947
948 /* Read the AT8035 PHY-Specific Status register, which indicates the
949 * speed and duplex that the PHY is actually using, irrespective of
950 * whether we are in autoneg mode or not.
951 */
952 ss = phy_read(phydev, AT803X_SPECIFIC_STATUS);
953 if (ss < 0)
954 return ss;
955
956 if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) {
Oleksij Rempel7dce80c2020-07-19 10:05:30 +0200957 int sfc;
958
959 sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL);
960 if (sfc < 0)
961 return sfc;
962
Russell King06d5f342019-10-04 17:06:14 +0100963 switch (ss & AT803X_SS_SPEED_MASK) {
964 case AT803X_SS_SPEED_10:
965 phydev->speed = SPEED_10;
966 break;
967 case AT803X_SS_SPEED_100:
968 phydev->speed = SPEED_100;
969 break;
970 case AT803X_SS_SPEED_1000:
971 phydev->speed = SPEED_1000;
972 break;
973 }
974 if (ss & AT803X_SS_DUPLEX)
975 phydev->duplex = DUPLEX_FULL;
976 else
977 phydev->duplex = DUPLEX_HALF;
Oleksij Rempel7dce80c2020-07-19 10:05:30 +0200978
Russell King06d5f342019-10-04 17:06:14 +0100979 if (ss & AT803X_SS_MDIX)
980 phydev->mdix = ETH_TP_MDI_X;
981 else
982 phydev->mdix = ETH_TP_MDI;
Oleksij Rempel7dce80c2020-07-19 10:05:30 +0200983
984 switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) {
985 case AT803X_SFC_MANUAL_MDI:
986 phydev->mdix_ctrl = ETH_TP_MDI;
987 break;
988 case AT803X_SFC_MANUAL_MDIX:
989 phydev->mdix_ctrl = ETH_TP_MDI_X;
990 break;
991 case AT803X_SFC_AUTOMATIC_CROSSOVER:
992 phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
993 break;
994 }
Russell King06d5f342019-10-04 17:06:14 +0100995 }
996
997 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
998 phy_resolve_aneg_pause(phydev);
999
1000 return 0;
1001}
1002
Oleksij Rempel7dce80c2020-07-19 10:05:30 +02001003static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl)
1004{
1005 u16 val;
1006
1007 switch (ctrl) {
1008 case ETH_TP_MDI:
1009 val = AT803X_SFC_MANUAL_MDI;
1010 break;
1011 case ETH_TP_MDI_X:
1012 val = AT803X_SFC_MANUAL_MDIX;
1013 break;
1014 case ETH_TP_MDI_AUTO:
1015 val = AT803X_SFC_AUTOMATIC_CROSSOVER;
1016 break;
1017 default:
1018 return 0;
1019 }
1020
1021 return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL,
1022 AT803X_SFC_MDI_CROSSOVER_MODE_M,
1023 FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val));
1024}
1025
1026static int at803x_config_aneg(struct phy_device *phydev)
1027{
1028 int ret;
1029
1030 ret = at803x_config_mdix(phydev, phydev->mdix_ctrl);
1031 if (ret < 0)
1032 return ret;
1033
1034 /* Changes of the midx bits are disruptive to the normal operation;
1035 * therefore any changes to these registers must be followed by a
1036 * software reset to take effect.
1037 */
1038 if (ret == 1) {
1039 ret = genphy_soft_reset(phydev);
1040 if (ret < 0)
1041 return ret;
1042 }
1043
1044 return genphy_config_aneg(phydev);
1045}
1046
Michael Wallecde0f4f2020-04-28 23:15:02 +02001047static int at803x_get_downshift(struct phy_device *phydev, u8 *d)
1048{
1049 int val;
1050
1051 val = phy_read(phydev, AT803X_SMART_SPEED);
1052 if (val < 0)
1053 return val;
1054
1055 if (val & AT803X_SMART_SPEED_ENABLE)
1056 *d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2;
1057 else
1058 *d = DOWNSHIFT_DEV_DISABLE;
1059
1060 return 0;
1061}
1062
1063static int at803x_set_downshift(struct phy_device *phydev, u8 cnt)
1064{
1065 u16 mask, set;
1066 int ret;
1067
1068 switch (cnt) {
1069 case DOWNSHIFT_DEV_DEFAULT_COUNT:
1070 cnt = AT803X_DEFAULT_DOWNSHIFT;
1071 fallthrough;
1072 case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT:
1073 set = AT803X_SMART_SPEED_ENABLE |
1074 AT803X_SMART_SPEED_BYPASS_TIMER |
1075 FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2);
1076 mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK;
1077 break;
1078 case DOWNSHIFT_DEV_DISABLE:
1079 set = 0;
1080 mask = AT803X_SMART_SPEED_ENABLE |
1081 AT803X_SMART_SPEED_BYPASS_TIMER;
1082 break;
1083 default:
1084 return -EINVAL;
1085 }
1086
1087 ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set);
1088
1089 /* After changing the smart speed settings, we need to perform a
1090 * software reset, use phy_init_hw() to make sure we set the
1091 * reapply any values which might got lost during software reset.
1092 */
1093 if (ret == 1)
1094 ret = phy_init_hw(phydev);
1095
1096 return ret;
1097}
1098
1099static int at803x_get_tunable(struct phy_device *phydev,
1100 struct ethtool_tunable *tuna, void *data)
1101{
1102 switch (tuna->id) {
1103 case ETHTOOL_PHY_DOWNSHIFT:
1104 return at803x_get_downshift(phydev, data);
1105 default:
1106 return -EOPNOTSUPP;
1107 }
1108}
1109
1110static int at803x_set_tunable(struct phy_device *phydev,
1111 struct ethtool_tunable *tuna, const void *data)
1112{
1113 switch (tuna->id) {
1114 case ETHTOOL_PHY_DOWNSHIFT:
1115 return at803x_set_downshift(phydev, *(const u8 *)data);
1116 default:
1117 return -EOPNOTSUPP;
1118 }
1119}
1120
Michael Walle6cb75762020-05-13 22:38:07 +02001121static int at803x_cable_test_result_trans(u16 status)
1122{
1123 switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
1124 case AT803X_CDT_STATUS_STAT_NORMAL:
1125 return ETHTOOL_A_CABLE_RESULT_CODE_OK;
1126 case AT803X_CDT_STATUS_STAT_SHORT:
1127 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
1128 case AT803X_CDT_STATUS_STAT_OPEN:
1129 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
1130 case AT803X_CDT_STATUS_STAT_FAIL:
1131 default:
1132 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
1133 }
1134}
1135
1136static bool at803x_cdt_test_failed(u16 status)
1137{
1138 return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) ==
1139 AT803X_CDT_STATUS_STAT_FAIL;
1140}
1141
1142static bool at803x_cdt_fault_length_valid(u16 status)
1143{
1144 switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
1145 case AT803X_CDT_STATUS_STAT_OPEN:
1146 case AT803X_CDT_STATUS_STAT_SHORT:
1147 return true;
1148 }
1149 return false;
1150}
1151
1152static int at803x_cdt_fault_length(u16 status)
1153{
1154 int dt;
1155
1156 /* According to the datasheet the distance to the fault is
1157 * DELTA_TIME * 0.824 meters.
1158 *
1159 * The author suspect the correct formula is:
1160 *
1161 * fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2
1162 *
1163 * where c is the speed of light, VF is the velocity factor of
1164 * the twisted pair cable, 125MHz the counter frequency and
1165 * we need to divide by 2 because the hardware will measure the
1166 * round trip time to the fault and back to the PHY.
1167 *
1168 * With a VF of 0.69 we get the factor 0.824 mentioned in the
1169 * datasheet.
1170 */
1171 dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status);
1172
1173 return (dt * 824) / 10;
1174}
1175
1176static int at803x_cdt_start(struct phy_device *phydev, int pair)
1177{
1178 u16 cdt;
1179
1180 cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
1181 AT803X_CDT_ENABLE_TEST;
1182
1183 return phy_write(phydev, AT803X_CDT, cdt);
1184}
1185
1186static int at803x_cdt_wait_for_completion(struct phy_device *phydev)
1187{
1188 int val, ret;
1189
1190 /* One test run takes about 25ms */
1191 ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
1192 !(val & AT803X_CDT_ENABLE_TEST),
1193 30000, 100000, true);
1194
1195 return ret < 0 ? ret : 0;
1196}
1197
1198static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair)
1199{
1200 static const int ethtool_pair[] = {
1201 ETHTOOL_A_CABLE_PAIR_A,
1202 ETHTOOL_A_CABLE_PAIR_B,
1203 ETHTOOL_A_CABLE_PAIR_C,
1204 ETHTOOL_A_CABLE_PAIR_D,
1205 };
1206 int ret, val;
1207
1208 ret = at803x_cdt_start(phydev, pair);
1209 if (ret)
1210 return ret;
1211
1212 ret = at803x_cdt_wait_for_completion(phydev);
1213 if (ret)
1214 return ret;
1215
1216 val = phy_read(phydev, AT803X_CDT_STATUS);
1217 if (val < 0)
1218 return val;
1219
1220 if (at803x_cdt_test_failed(val))
1221 return 0;
1222
1223 ethnl_cable_test_result(phydev, ethtool_pair[pair],
1224 at803x_cable_test_result_trans(val));
1225
1226 if (at803x_cdt_fault_length_valid(val))
1227 ethnl_cable_test_fault_length(phydev, ethtool_pair[pair],
1228 at803x_cdt_fault_length(val));
1229
1230 return 1;
1231}
1232
1233static int at803x_cable_test_get_status(struct phy_device *phydev,
1234 bool *finished)
1235{
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001236 unsigned long pair_mask;
Michael Walle6cb75762020-05-13 22:38:07 +02001237 int retries = 20;
1238 int pair, ret;
1239
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001240 if (phydev->phy_id == ATH9331_PHY_ID ||
David Bauerfada2ce2021-10-06 00:54:01 +02001241 phydev->phy_id == ATH8032_PHY_ID ||
1242 phydev->phy_id == QCA9561_PHY_ID)
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001243 pair_mask = 0x3;
1244 else
1245 pair_mask = 0xf;
1246
Michael Walle6cb75762020-05-13 22:38:07 +02001247 *finished = false;
1248
1249 /* According to the datasheet the CDT can be performed when
1250 * there is no link partner or when the link partner is
1251 * auto-negotiating. Starting the test will restart the AN
1252 * automatically. It seems that doing this repeatedly we will
1253 * get a slot where our link partner won't disturb our
1254 * measurement.
1255 */
1256 while (pair_mask && retries--) {
1257 for_each_set_bit(pair, &pair_mask, 4) {
1258 ret = at803x_cable_test_one_pair(phydev, pair);
1259 if (ret < 0)
1260 return ret;
1261 if (ret)
1262 clear_bit(pair, &pair_mask);
1263 }
1264 if (pair_mask)
1265 msleep(250);
1266 }
1267
1268 *finished = true;
1269
1270 return 0;
1271}
1272
1273static int at803x_cable_test_start(struct phy_device *phydev)
1274{
1275 /* Enable auto-negotiation, but advertise no capabilities, no link
1276 * will be established. A restart of the auto-negotiation is not
1277 * required, because the cable test will automatically break the link.
1278 */
1279 phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
1280 phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001281 if (phydev->phy_id != ATH9331_PHY_ID &&
David Bauerfada2ce2021-10-06 00:54:01 +02001282 phydev->phy_id != ATH8032_PHY_ID &&
1283 phydev->phy_id != QCA9561_PHY_ID)
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001284 phy_write(phydev, MII_CTRL1000, 0);
Michael Walle6cb75762020-05-13 22:38:07 +02001285
1286 /* we do all the (time consuming) work later */
1287 return 0;
1288}
1289
Ansuel Smith272833b2021-05-14 23:00:15 +02001290static int qca83xx_config_init(struct phy_device *phydev)
1291{
1292 u8 switch_revision;
1293
1294 switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK;
1295
1296 switch (switch_revision) {
1297 case 1:
1298 /* For 100M waveform */
1299 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_0, 0x02ea);
1300 /* Turn on Gigabit clock */
1301 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3D, 0x68a0);
1302 break;
1303
1304 case 2:
1305 phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0);
1306 fallthrough;
1307 case 4:
1308 phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f);
1309 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3D, 0x6860);
1310 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_5, 0x2c46);
1311 at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000);
1312 break;
1313 }
1314
1315 return 0;
1316}
1317
Mugunthan V N317420a2013-06-03 20:10:04 +00001318static struct phy_driver at803x_driver[] = {
1319{
Michael Walle96c36712019-11-06 23:36:16 +01001320 /* Qualcomm Atheros AR8035 */
Michael Walle0465d8f2020-05-22 11:53:31 +02001321 PHY_ID_MATCH_EXACT(ATH8035_PHY_ID),
Michael Walle96c36712019-11-06 23:36:16 +01001322 .name = "Qualcomm Atheros AR8035",
Michael Walle6cb75762020-05-13 22:38:07 +02001323 .flags = PHY_POLL_CABLE_TEST,
Michael Walle2f664822019-11-06 23:36:14 +01001324 .probe = at803x_probe,
Michael Walle2318ca82020-01-30 18:54:02 +01001325 .remove = at803x_remove,
Oleksij Rempel7dce80c2020-07-19 10:05:30 +02001326 .config_aneg = at803x_config_aneg,
Daniel Mack13a56b42014-06-18 11:01:43 +02001327 .config_init = at803x_config_init,
Michael Wallecde0f4f2020-04-28 23:15:02 +02001328 .soft_reset = genphy_soft_reset,
Daniel Mack13a56b42014-06-18 11:01:43 +02001329 .set_wol = at803x_set_wol,
1330 .get_wol = at803x_get_wol,
1331 .suspend = at803x_suspend,
1332 .resume = at803x_resume,
Heiner Kallweitdcdecdc2019-04-12 20:47:03 +02001333 /* PHY_GBIT_FEATURES */
Russell King06d5f342019-10-04 17:06:14 +01001334 .read_status = at803x_read_status,
Måns Rullgård0eae5982015-11-12 17:40:20 +00001335 .config_intr = at803x_config_intr,
Ioana Ciornei29773092020-11-01 14:50:59 +02001336 .handle_interrupt = at803x_handle_interrupt,
Michael Wallecde0f4f2020-04-28 23:15:02 +02001337 .get_tunable = at803x_get_tunable,
1338 .set_tunable = at803x_set_tunable,
Michael Walle6cb75762020-05-13 22:38:07 +02001339 .cable_test_start = at803x_cable_test_start,
1340 .cable_test_get_status = at803x_cable_test_get_status,
Mugunthan V N317420a2013-06-03 20:10:04 +00001341}, {
Michael Walle96c36712019-11-06 23:36:16 +01001342 /* Qualcomm Atheros AR8030 */
Daniel Mack13a56b42014-06-18 11:01:43 +02001343 .phy_id = ATH8030_PHY_ID,
Michael Walle96c36712019-11-06 23:36:16 +01001344 .name = "Qualcomm Atheros AR8030",
Michael Walle0465d8f2020-05-22 11:53:31 +02001345 .phy_id_mask = AT8030_PHY_ID_MASK,
Michael Walle2f664822019-11-06 23:36:14 +01001346 .probe = at803x_probe,
Michael Walle2318ca82020-01-30 18:54:02 +01001347 .remove = at803x_remove,
Daniel Mack13a56b42014-06-18 11:01:43 +02001348 .config_init = at803x_config_init,
1349 .link_change_notify = at803x_link_change_notify,
1350 .set_wol = at803x_set_wol,
1351 .get_wol = at803x_get_wol,
1352 .suspend = at803x_suspend,
1353 .resume = at803x_resume,
Heiner Kallweitdcdecdc2019-04-12 20:47:03 +02001354 /* PHY_BASIC_FEATURES */
Måns Rullgård0eae5982015-11-12 17:40:20 +00001355 .config_intr = at803x_config_intr,
Ioana Ciornei29773092020-11-01 14:50:59 +02001356 .handle_interrupt = at803x_handle_interrupt,
Mugunthan V N05d7cce2013-06-03 20:10:07 +00001357}, {
Michael Walle96c36712019-11-06 23:36:16 +01001358 /* Qualcomm Atheros AR8031/AR8033 */
Michael Walle0465d8f2020-05-22 11:53:31 +02001359 PHY_ID_MATCH_EXACT(ATH8031_PHY_ID),
Michael Walle96c36712019-11-06 23:36:16 +01001360 .name = "Qualcomm Atheros AR8031/AR8033",
Michael Walle6cb75762020-05-13 22:38:07 +02001361 .flags = PHY_POLL_CABLE_TEST,
Michael Walle2f664822019-11-06 23:36:14 +01001362 .probe = at803x_probe,
Michael Walle2318ca82020-01-30 18:54:02 +01001363 .remove = at803x_remove,
Daniel Mack13a56b42014-06-18 11:01:43 +02001364 .config_init = at803x_config_init,
Michael Walle63477a52021-02-14 02:17:11 +01001365 .config_aneg = at803x_config_aneg,
Michael Wallecde0f4f2020-04-28 23:15:02 +02001366 .soft_reset = genphy_soft_reset,
Daniel Mack13a56b42014-06-18 11:01:43 +02001367 .set_wol = at803x_set_wol,
1368 .get_wol = at803x_get_wol,
1369 .suspend = at803x_suspend,
1370 .resume = at803x_resume,
David Bauerc329e5a2021-04-15 03:26:50 +02001371 .read_page = at803x_read_page,
1372 .write_page = at803x_write_page,
David Bauerb8561502021-06-27 12:16:07 +02001373 .get_features = at803x_get_features,
Russell King06d5f342019-10-04 17:06:14 +01001374 .read_status = at803x_read_status,
Daniel Mack13a56b42014-06-18 11:01:43 +02001375 .config_intr = &at803x_config_intr,
Ioana Ciornei29773092020-11-01 14:50:59 +02001376 .handle_interrupt = at803x_handle_interrupt,
Michael Wallecde0f4f2020-04-28 23:15:02 +02001377 .get_tunable = at803x_get_tunable,
1378 .set_tunable = at803x_set_tunable,
Michael Walle6cb75762020-05-13 22:38:07 +02001379 .cable_test_start = at803x_cable_test_start,
1380 .cable_test_get_status = at803x_cable_test_get_status,
Oleksij Rempel7908d2c2019-10-03 10:21:12 +02001381}, {
David Bauer58000912020-04-17 15:41:59 +02001382 /* Qualcomm Atheros AR8032 */
1383 PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
1384 .name = "Qualcomm Atheros AR8032",
1385 .probe = at803x_probe,
1386 .remove = at803x_remove,
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001387 .flags = PHY_POLL_CABLE_TEST,
David Bauer58000912020-04-17 15:41:59 +02001388 .config_init = at803x_config_init,
1389 .link_change_notify = at803x_link_change_notify,
1390 .set_wol = at803x_set_wol,
1391 .get_wol = at803x_get_wol,
1392 .suspend = at803x_suspend,
1393 .resume = at803x_resume,
1394 /* PHY_BASIC_FEATURES */
David Bauer58000912020-04-17 15:41:59 +02001395 .config_intr = at803x_config_intr,
Ioana Ciornei29773092020-11-01 14:50:59 +02001396 .handle_interrupt = at803x_handle_interrupt,
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001397 .cable_test_start = at803x_cable_test_start,
1398 .cable_test_get_status = at803x_cable_test_get_status,
David Bauer58000912020-04-17 15:41:59 +02001399}, {
Oleksij Rempel7908d2c2019-10-03 10:21:12 +02001400 /* ATHEROS AR9331 */
1401 PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
Michael Walle96c36712019-11-06 23:36:16 +01001402 .name = "Qualcomm Atheros AR9331 built-in PHY",
Oleksij Rempel7908d2c2019-10-03 10:21:12 +02001403 .suspend = at803x_suspend,
1404 .resume = at803x_resume,
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001405 .flags = PHY_POLL_CABLE_TEST,
Oleksij Rempel7908d2c2019-10-03 10:21:12 +02001406 /* PHY_BASIC_FEATURES */
Oleksij Rempel7908d2c2019-10-03 10:21:12 +02001407 .config_intr = &at803x_config_intr,
Ioana Ciornei29773092020-11-01 14:50:59 +02001408 .handle_interrupt = at803x_handle_interrupt,
Oleksij Rempeldc0f3ed2020-05-27 07:08:43 +02001409 .cable_test_start = at803x_cable_test_start,
1410 .cable_test_get_status = at803x_cable_test_get_status,
Oleksij Rempel7dce80c2020-07-19 10:05:30 +02001411 .read_status = at803x_read_status,
1412 .soft_reset = genphy_soft_reset,
1413 .config_aneg = at803x_config_aneg,
Ansuel Smith272833b2021-05-14 23:00:15 +02001414}, {
David Bauerfada2ce2021-10-06 00:54:01 +02001415 /* Qualcomm Atheros QCA9561 */
1416 PHY_ID_MATCH_EXACT(QCA9561_PHY_ID),
1417 .name = "Qualcomm Atheros QCA9561 built-in PHY",
1418 .suspend = at803x_suspend,
1419 .resume = at803x_resume,
1420 .flags = PHY_POLL_CABLE_TEST,
1421 /* PHY_BASIC_FEATURES */
1422 .config_intr = &at803x_config_intr,
1423 .handle_interrupt = at803x_handle_interrupt,
1424 .cable_test_start = at803x_cable_test_start,
1425 .cable_test_get_status = at803x_cable_test_get_status,
1426 .read_status = at803x_read_status,
1427 .soft_reset = genphy_soft_reset,
1428 .config_aneg = at803x_config_aneg,
1429}, {
Ansuel Smith272833b2021-05-14 23:00:15 +02001430 /* QCA8337 */
Ansuel Smithd44fd862021-09-19 18:28:17 +02001431 .phy_id = QCA8337_PHY_ID,
1432 .phy_id_mask = QCA8K_PHY_ID_MASK,
1433 .name = "Qualcomm Atheros 8337 internal PHY",
Ansuel Smith272833b2021-05-14 23:00:15 +02001434 /* PHY_GBIT_FEATURES */
Ansuel Smithd44fd862021-09-19 18:28:17 +02001435 .probe = at803x_probe,
1436 .flags = PHY_IS_INTERNAL,
1437 .config_init = qca83xx_config_init,
1438 .soft_reset = genphy_soft_reset,
1439 .get_sset_count = at803x_get_sset_count,
1440 .get_strings = at803x_get_strings,
1441 .get_stats = at803x_get_stats,
Ansuel Smith15b9df42021-09-19 18:28:16 +02001442 .suspend = genphy_suspend,
1443 .resume = genphy_resume,
Ansuel Smith0ccf8512021-09-14 14:33:45 +02001444}, {
Ansuel Smithb4df02b2021-09-19 18:28:15 +02001445 /* QCA8327-A from switch QCA8327-AL1A */
Ansuel Smithd44fd862021-09-19 18:28:17 +02001446 .phy_id = QCA8327_A_PHY_ID,
1447 .phy_id_mask = QCA8K_PHY_ID_MASK,
1448 .name = "Qualcomm Atheros 8327-A internal PHY",
Ansuel Smithb4df02b2021-09-19 18:28:15 +02001449 /* PHY_GBIT_FEATURES */
Ansuel Smithd44fd862021-09-19 18:28:17 +02001450 .probe = at803x_probe,
1451 .flags = PHY_IS_INTERNAL,
1452 .config_init = qca83xx_config_init,
1453 .soft_reset = genphy_soft_reset,
1454 .get_sset_count = at803x_get_sset_count,
1455 .get_strings = at803x_get_strings,
1456 .get_stats = at803x_get_stats,
Ansuel Smith15b9df42021-09-19 18:28:16 +02001457 .suspend = genphy_suspend,
1458 .resume = genphy_resume,
Ansuel Smithb4df02b2021-09-19 18:28:15 +02001459}, {
1460 /* QCA8327-B from switch QCA8327-BL1A */
Ansuel Smithd44fd862021-09-19 18:28:17 +02001461 .phy_id = QCA8327_B_PHY_ID,
1462 .phy_id_mask = QCA8K_PHY_ID_MASK,
1463 .name = "Qualcomm Atheros 8327-B internal PHY",
Ansuel Smith0ccf8512021-09-14 14:33:45 +02001464 /* PHY_GBIT_FEATURES */
Ansuel Smithd44fd862021-09-19 18:28:17 +02001465 .probe = at803x_probe,
1466 .flags = PHY_IS_INTERNAL,
1467 .config_init = qca83xx_config_init,
1468 .soft_reset = genphy_soft_reset,
1469 .get_sset_count = at803x_get_sset_count,
1470 .get_strings = at803x_get_strings,
1471 .get_stats = at803x_get_stats,
Ansuel Smith15b9df42021-09-19 18:28:16 +02001472 .suspend = genphy_suspend,
1473 .resume = genphy_resume,
Ansuel Smith272833b2021-05-14 23:00:15 +02001474}, };
Matus Ujhelyi0ca71112012-10-14 19:07:16 +00001475
Johan Hovold50fd7152014-11-11 19:45:59 +01001476module_phy_driver(at803x_driver);
Matus Ujhelyi0ca71112012-10-14 19:07:16 +00001477
1478static struct mdio_device_id __maybe_unused atheros_tbl[] = {
Michael Walle0465d8f2020-05-22 11:53:31 +02001479 { ATH8030_PHY_ID, AT8030_PHY_ID_MASK },
1480 { PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) },
David Bauer58000912020-04-17 15:41:59 +02001481 { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) },
Michael Walle0465d8f2020-05-22 11:53:31 +02001482 { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) },
Oleksij Rempel7908d2c2019-10-03 10:21:12 +02001483 { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) },
Ansuel Smith0ccf8512021-09-14 14:33:45 +02001484 { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) },
Ansuel Smithb4df02b2021-09-19 18:28:15 +02001485 { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) },
1486 { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) },
David Bauerfada2ce2021-10-06 00:54:01 +02001487 { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) },
Matus Ujhelyi0ca71112012-10-14 19:07:16 +00001488 { }
1489};
1490
1491MODULE_DEVICE_TABLE(mdio, atheros_tbl);