treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / phy / at803x.c
blobaee62610bade557525f13241aa6bd38fb812eeec
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * drivers/net/phy/at803x.c
5 * Driver for Qualcomm Atheros AR803x PHY
7 * Author: Matus Ujhelyi <ujhelyi.m@gmail.com>
8 */
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/of_gpio.h>
16 #include <linux/bitfield.h>
17 #include <linux/gpio/consumer.h>
18 #include <linux/regulator/of_regulator.h>
19 #include <linux/regulator/driver.h>
20 #include <linux/regulator/consumer.h>
21 #include <dt-bindings/net/qca-ar803x.h>
23 #define AT803X_SPECIFIC_STATUS 0x11
24 #define AT803X_SS_SPEED_MASK (3 << 14)
25 #define AT803X_SS_SPEED_1000 (2 << 14)
26 #define AT803X_SS_SPEED_100 (1 << 14)
27 #define AT803X_SS_SPEED_10 (0 << 14)
28 #define AT803X_SS_DUPLEX BIT(13)
29 #define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11)
30 #define AT803X_SS_MDIX BIT(6)
32 #define AT803X_INTR_ENABLE 0x12
33 #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15)
34 #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14)
35 #define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13)
36 #define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12)
37 #define AT803X_INTR_ENABLE_LINK_FAIL BIT(11)
38 #define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10)
39 #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5)
40 #define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1)
41 #define AT803X_INTR_ENABLE_WOL BIT(0)
43 #define AT803X_INTR_STATUS 0x13
45 #define AT803X_SMART_SPEED 0x14
46 #define AT803X_LED_CONTROL 0x18
48 #define AT803X_DEVICE_ADDR 0x03
49 #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C
50 #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B
51 #define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A
52 #define AT803X_REG_CHIP_CONFIG 0x1f
53 #define AT803X_BT_BX_REG_SEL 0x8000
55 #define AT803X_DEBUG_ADDR 0x1D
56 #define AT803X_DEBUG_DATA 0x1E
58 #define AT803X_MODE_CFG_MASK 0x0F
59 #define AT803X_MODE_CFG_SGMII 0x01
61 #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/
62 #define AT803X_PSSR_MR_AN_COMPLETE 0x0200
64 #define AT803X_DEBUG_REG_0 0x00
65 #define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15)
67 #define AT803X_DEBUG_REG_5 0x05
68 #define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8)
70 #define AT803X_DEBUG_REG_1F 0x1F
71 #define AT803X_DEBUG_PLL_ON BIT(2)
72 #define AT803X_DEBUG_RGMII_1V8 BIT(3)
74 /* AT803x supports either the XTAL input pad, an internal PLL or the
75 * DSP as clock reference for the clock output pad. The XTAL reference
76 * is only used for 25 MHz output, all other frequencies need the PLL.
77 * The DSP as a clock reference is used in synchronous ethernet
78 * applications.
80 * By default the PLL is only enabled if there is a link. Otherwise
81 * the PHY will go into low power state and disabled the PLL. You can
82 * set the PLL_ON bit (see debug register 0x1f) to keep the PLL always
83 * enabled.
85 #define AT803X_MMD7_CLK25M 0x8016
86 #define AT803X_CLK_OUT_MASK GENMASK(4, 2)
87 #define AT803X_CLK_OUT_25MHZ_XTAL 0
88 #define AT803X_CLK_OUT_25MHZ_DSP 1
89 #define AT803X_CLK_OUT_50MHZ_PLL 2
90 #define AT803X_CLK_OUT_50MHZ_DSP 3
91 #define AT803X_CLK_OUT_62_5MHZ_PLL 4
92 #define AT803X_CLK_OUT_62_5MHZ_DSP 5
93 #define AT803X_CLK_OUT_125MHZ_PLL 6
94 #define AT803X_CLK_OUT_125MHZ_DSP 7
96 /* The AR8035 has another mask which is compatible with the AR8031/AR8033 mask
97 * but doesn't support choosing between XTAL/PLL and DSP.
99 #define AT8035_CLK_OUT_MASK GENMASK(4, 3)
101 #define AT803X_CLK_OUT_STRENGTH_MASK GENMASK(8, 7)
102 #define AT803X_CLK_OUT_STRENGTH_FULL 0
103 #define AT803X_CLK_OUT_STRENGTH_HALF 1
104 #define AT803X_CLK_OUT_STRENGTH_QUARTER 2
106 #define ATH9331_PHY_ID 0x004dd041
107 #define ATH8030_PHY_ID 0x004dd076
108 #define ATH8031_PHY_ID 0x004dd074
109 #define ATH8035_PHY_ID 0x004dd072
110 #define AT803X_PHY_ID_MASK 0xffffffef
112 MODULE_DESCRIPTION("Qualcomm Atheros AR803x PHY driver");
113 MODULE_AUTHOR("Matus Ujhelyi");
114 MODULE_LICENSE("GPL");
116 struct at803x_priv {
117 int flags;
118 #define AT803X_KEEP_PLL_ENABLED BIT(0) /* don't turn off internal PLL */
119 u16 clk_25m_reg;
120 u16 clk_25m_mask;
121 struct regulator_dev *vddio_rdev;
122 struct regulator_dev *vddh_rdev;
123 struct regulator *vddio;
126 struct at803x_context {
127 u16 bmcr;
128 u16 advertise;
129 u16 control1000;
130 u16 int_enable;
131 u16 smart_speed;
132 u16 led_control;
135 static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
137 int ret;
139 ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
140 if (ret < 0)
141 return ret;
143 return phy_read(phydev, AT803X_DEBUG_DATA);
146 static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
147 u16 clear, u16 set)
149 u16 val;
150 int ret;
152 ret = at803x_debug_reg_read(phydev, reg);
153 if (ret < 0)
154 return ret;
156 val = ret & 0xffff;
157 val &= ~clear;
158 val |= set;
160 return phy_write(phydev, AT803X_DEBUG_DATA, val);
163 static int at803x_enable_rx_delay(struct phy_device *phydev)
165 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0,
166 AT803X_DEBUG_RX_CLK_DLY_EN);
169 static int at803x_enable_tx_delay(struct phy_device *phydev)
171 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0,
172 AT803X_DEBUG_TX_CLK_DLY_EN);
175 static int at803x_disable_rx_delay(struct phy_device *phydev)
177 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0,
178 AT803X_DEBUG_RX_CLK_DLY_EN, 0);
181 static int at803x_disable_tx_delay(struct phy_device *phydev)
183 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
184 AT803X_DEBUG_TX_CLK_DLY_EN, 0);
187 /* save relevant PHY registers to private copy */
188 static void at803x_context_save(struct phy_device *phydev,
189 struct at803x_context *context)
191 context->bmcr = phy_read(phydev, MII_BMCR);
192 context->advertise = phy_read(phydev, MII_ADVERTISE);
193 context->control1000 = phy_read(phydev, MII_CTRL1000);
194 context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE);
195 context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED);
196 context->led_control = phy_read(phydev, AT803X_LED_CONTROL);
199 /* restore relevant PHY registers from private copy */
200 static void at803x_context_restore(struct phy_device *phydev,
201 const struct at803x_context *context)
203 phy_write(phydev, MII_BMCR, context->bmcr);
204 phy_write(phydev, MII_ADVERTISE, context->advertise);
205 phy_write(phydev, MII_CTRL1000, context->control1000);
206 phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable);
207 phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed);
208 phy_write(phydev, AT803X_LED_CONTROL, context->led_control);
211 static int at803x_set_wol(struct phy_device *phydev,
212 struct ethtool_wolinfo *wol)
214 struct net_device *ndev = phydev->attached_dev;
215 const u8 *mac;
216 int ret;
217 u32 value;
218 unsigned int i, offsets[] = {
219 AT803X_LOC_MAC_ADDR_32_47_OFFSET,
220 AT803X_LOC_MAC_ADDR_16_31_OFFSET,
221 AT803X_LOC_MAC_ADDR_0_15_OFFSET,
224 if (!ndev)
225 return -ENODEV;
227 if (wol->wolopts & WAKE_MAGIC) {
228 mac = (const u8 *) ndev->dev_addr;
230 if (!is_valid_ether_addr(mac))
231 return -EINVAL;
233 for (i = 0; i < 3; i++)
234 phy_write_mmd(phydev, AT803X_DEVICE_ADDR, offsets[i],
235 mac[(i * 2) + 1] | (mac[(i * 2)] << 8));
237 value = phy_read(phydev, AT803X_INTR_ENABLE);
238 value |= AT803X_INTR_ENABLE_WOL;
239 ret = phy_write(phydev, AT803X_INTR_ENABLE, value);
240 if (ret)
241 return ret;
242 value = phy_read(phydev, AT803X_INTR_STATUS);
243 } else {
244 value = phy_read(phydev, AT803X_INTR_ENABLE);
245 value &= (~AT803X_INTR_ENABLE_WOL);
246 ret = phy_write(phydev, AT803X_INTR_ENABLE, value);
247 if (ret)
248 return ret;
249 value = phy_read(phydev, AT803X_INTR_STATUS);
252 return ret;
255 static void at803x_get_wol(struct phy_device *phydev,
256 struct ethtool_wolinfo *wol)
258 u32 value;
260 wol->supported = WAKE_MAGIC;
261 wol->wolopts = 0;
263 value = phy_read(phydev, AT803X_INTR_ENABLE);
264 if (value & AT803X_INTR_ENABLE_WOL)
265 wol->wolopts |= WAKE_MAGIC;
268 static int at803x_suspend(struct phy_device *phydev)
270 int value;
271 int wol_enabled;
273 value = phy_read(phydev, AT803X_INTR_ENABLE);
274 wol_enabled = value & AT803X_INTR_ENABLE_WOL;
276 if (wol_enabled)
277 value = BMCR_ISOLATE;
278 else
279 value = BMCR_PDOWN;
281 phy_modify(phydev, MII_BMCR, 0, value);
283 return 0;
286 static int at803x_resume(struct phy_device *phydev)
288 return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
291 static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
292 unsigned int selector)
294 struct phy_device *phydev = rdev_get_drvdata(rdev);
296 if (selector)
297 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
298 0, AT803X_DEBUG_RGMII_1V8);
299 else
300 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
301 AT803X_DEBUG_RGMII_1V8, 0);
304 static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
306 struct phy_device *phydev = rdev_get_drvdata(rdev);
307 int val;
309 val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
310 if (val < 0)
311 return val;
313 return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
316 static struct regulator_ops vddio_regulator_ops = {
317 .list_voltage = regulator_list_voltage_table,
318 .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel,
319 .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel,
322 static const unsigned int vddio_voltage_table[] = {
323 1500000,
324 1800000,
327 static const struct regulator_desc vddio_desc = {
328 .name = "vddio",
329 .of_match = of_match_ptr("vddio-regulator"),
330 .n_voltages = ARRAY_SIZE(vddio_voltage_table),
331 .volt_table = vddio_voltage_table,
332 .ops = &vddio_regulator_ops,
333 .type = REGULATOR_VOLTAGE,
334 .owner = THIS_MODULE,
337 static struct regulator_ops vddh_regulator_ops = {
340 static const struct regulator_desc vddh_desc = {
341 .name = "vddh",
342 .of_match = of_match_ptr("vddh-regulator"),
343 .n_voltages = 1,
344 .fixed_uV = 2500000,
345 .ops = &vddh_regulator_ops,
346 .type = REGULATOR_VOLTAGE,
347 .owner = THIS_MODULE,
350 static int at8031_register_regulators(struct phy_device *phydev)
352 struct at803x_priv *priv = phydev->priv;
353 struct device *dev = &phydev->mdio.dev;
354 struct regulator_config config = { };
356 config.dev = dev;
357 config.driver_data = phydev;
359 priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
360 if (IS_ERR(priv->vddio_rdev)) {
361 phydev_err(phydev, "failed to register VDDIO regulator\n");
362 return PTR_ERR(priv->vddio_rdev);
365 priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
366 if (IS_ERR(priv->vddh_rdev)) {
367 phydev_err(phydev, "failed to register VDDH regulator\n");
368 return PTR_ERR(priv->vddh_rdev);
371 return 0;
374 static bool at803x_match_phy_id(struct phy_device *phydev, u32 phy_id)
376 return (phydev->phy_id & phydev->drv->phy_id_mask)
377 == (phy_id & phydev->drv->phy_id_mask);
380 static int at803x_parse_dt(struct phy_device *phydev)
382 struct device_node *node = phydev->mdio.dev.of_node;
383 struct at803x_priv *priv = phydev->priv;
384 unsigned int sel, mask;
385 u32 freq, strength;
386 int ret;
388 if (!IS_ENABLED(CONFIG_OF_MDIO))
389 return 0;
391 ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq);
392 if (!ret) {
393 mask = AT803X_CLK_OUT_MASK;
394 switch (freq) {
395 case 25000000:
396 sel = AT803X_CLK_OUT_25MHZ_XTAL;
397 break;
398 case 50000000:
399 sel = AT803X_CLK_OUT_50MHZ_PLL;
400 break;
401 case 62500000:
402 sel = AT803X_CLK_OUT_62_5MHZ_PLL;
403 break;
404 case 125000000:
405 sel = AT803X_CLK_OUT_125MHZ_PLL;
406 break;
407 default:
408 phydev_err(phydev, "invalid qca,clk-out-frequency\n");
409 return -EINVAL;
412 priv->clk_25m_reg |= FIELD_PREP(mask, sel);
413 priv->clk_25m_mask |= mask;
415 /* Fixup for the AR8030/AR8035. This chip has another mask and
416 * doesn't support the DSP reference. Eg. the lowest bit of the
417 * mask. The upper two bits select the same frequencies. Mask
418 * the lowest bit here.
420 * Warning:
421 * There was no datasheet for the AR8030 available so this is
422 * just a guess. But the AR8035 is listed as pin compatible
423 * to the AR8030 so there might be a good chance it works on
424 * the AR8030 too.
426 if (at803x_match_phy_id(phydev, ATH8030_PHY_ID) ||
427 at803x_match_phy_id(phydev, ATH8035_PHY_ID)) {
428 priv->clk_25m_reg &= ~AT8035_CLK_OUT_MASK;
429 priv->clk_25m_mask &= ~AT8035_CLK_OUT_MASK;
433 ret = of_property_read_u32(node, "qca,clk-out-strength", &strength);
434 if (!ret) {
435 priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK;
436 switch (strength) {
437 case AR803X_STRENGTH_FULL:
438 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL;
439 break;
440 case AR803X_STRENGTH_HALF:
441 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF;
442 break;
443 case AR803X_STRENGTH_QUARTER:
444 priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER;
445 break;
446 default:
447 phydev_err(phydev, "invalid qca,clk-out-strength\n");
448 return -EINVAL;
452 /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping
453 * options.
455 if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
456 if (of_property_read_bool(node, "qca,keep-pll-enabled"))
457 priv->flags |= AT803X_KEEP_PLL_ENABLED;
459 ret = at8031_register_regulators(phydev);
460 if (ret < 0)
461 return ret;
463 priv->vddio = devm_regulator_get_optional(&phydev->mdio.dev,
464 "vddio");
465 if (IS_ERR(priv->vddio)) {
466 phydev_err(phydev, "failed to get VDDIO regulator\n");
467 return PTR_ERR(priv->vddio);
470 ret = regulator_enable(priv->vddio);
471 if (ret < 0)
472 return ret;
475 return 0;
478 static int at803x_probe(struct phy_device *phydev)
480 struct device *dev = &phydev->mdio.dev;
481 struct at803x_priv *priv;
483 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
484 if (!priv)
485 return -ENOMEM;
487 phydev->priv = priv;
489 return at803x_parse_dt(phydev);
492 static int at803x_clk_out_config(struct phy_device *phydev)
494 struct at803x_priv *priv = phydev->priv;
495 int val;
497 if (!priv->clk_25m_mask)
498 return 0;
500 val = phy_read_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M);
501 if (val < 0)
502 return val;
504 val &= ~priv->clk_25m_mask;
505 val |= priv->clk_25m_reg;
507 return phy_write_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M, val);
510 static int at8031_pll_config(struct phy_device *phydev)
512 struct at803x_priv *priv = phydev->priv;
514 /* The default after hardware reset is PLL OFF. After a soft reset, the
515 * values are retained.
517 if (priv->flags & AT803X_KEEP_PLL_ENABLED)
518 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
519 0, AT803X_DEBUG_PLL_ON);
520 else
521 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
522 AT803X_DEBUG_PLL_ON, 0);
525 static int at803x_config_init(struct phy_device *phydev)
527 int ret;
529 /* The RX and TX delay default is:
530 * after HW reset: RX delay enabled and TX delay disabled
531 * after SW reset: RX delay enabled, while TX delay retains the
532 * value before reset.
534 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
535 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
536 ret = at803x_enable_rx_delay(phydev);
537 else
538 ret = at803x_disable_rx_delay(phydev);
539 if (ret < 0)
540 return ret;
542 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
543 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
544 ret = at803x_enable_tx_delay(phydev);
545 else
546 ret = at803x_disable_tx_delay(phydev);
547 if (ret < 0)
548 return ret;
550 ret = at803x_clk_out_config(phydev);
551 if (ret < 0)
552 return ret;
554 if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
555 ret = at8031_pll_config(phydev);
556 if (ret < 0)
557 return ret;
560 return 0;
563 static int at803x_ack_interrupt(struct phy_device *phydev)
565 int err;
567 err = phy_read(phydev, AT803X_INTR_STATUS);
569 return (err < 0) ? err : 0;
572 static int at803x_config_intr(struct phy_device *phydev)
574 int err;
575 int value;
577 value = phy_read(phydev, AT803X_INTR_ENABLE);
579 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
580 value |= AT803X_INTR_ENABLE_AUTONEG_ERR;
581 value |= AT803X_INTR_ENABLE_SPEED_CHANGED;
582 value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED;
583 value |= AT803X_INTR_ENABLE_LINK_FAIL;
584 value |= AT803X_INTR_ENABLE_LINK_SUCCESS;
586 err = phy_write(phydev, AT803X_INTR_ENABLE, value);
588 else
589 err = phy_write(phydev, AT803X_INTR_ENABLE, 0);
591 return err;
594 static void at803x_link_change_notify(struct phy_device *phydev)
597 * Conduct a hardware reset for AT8030 every time a link loss is
598 * signalled. This is necessary to circumvent a hardware bug that
599 * occurs when the cable is unplugged while TX packets are pending
600 * in the FIFO. In such cases, the FIFO enters an error mode it
601 * cannot recover from by software.
603 if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) {
604 struct at803x_context context;
606 at803x_context_save(phydev, &context);
608 phy_device_reset(phydev, 1);
609 msleep(1);
610 phy_device_reset(phydev, 0);
611 msleep(1);
613 at803x_context_restore(phydev, &context);
615 phydev_dbg(phydev, "%s(): phy was reset\n", __func__);
619 static int at803x_aneg_done(struct phy_device *phydev)
621 int ccr;
623 int aneg_done = genphy_aneg_done(phydev);
624 if (aneg_done != BMSR_ANEGCOMPLETE)
625 return aneg_done;
628 * in SGMII mode, if copper side autoneg is successful,
629 * also check SGMII side autoneg result
631 ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
632 if ((ccr & AT803X_MODE_CFG_MASK) != AT803X_MODE_CFG_SGMII)
633 return aneg_done;
635 /* switch to SGMII/fiber page */
636 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr & ~AT803X_BT_BX_REG_SEL);
638 /* check if the SGMII link is OK. */
639 if (!(phy_read(phydev, AT803X_PSSR) & AT803X_PSSR_MR_AN_COMPLETE)) {
640 phydev_warn(phydev, "803x_aneg_done: SGMII link is not ok\n");
641 aneg_done = 0;
643 /* switch back to copper page */
644 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr | AT803X_BT_BX_REG_SEL);
646 return aneg_done;
649 static int at803x_read_status(struct phy_device *phydev)
651 int ss, err, old_link = phydev->link;
653 /* Update the link, but return if there was an error */
654 err = genphy_update_link(phydev);
655 if (err)
656 return err;
658 /* why bother the PHY if nothing can have changed */
659 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
660 return 0;
662 phydev->speed = SPEED_UNKNOWN;
663 phydev->duplex = DUPLEX_UNKNOWN;
664 phydev->pause = 0;
665 phydev->asym_pause = 0;
667 err = genphy_read_lpa(phydev);
668 if (err < 0)
669 return err;
671 /* Read the AT8035 PHY-Specific Status register, which indicates the
672 * speed and duplex that the PHY is actually using, irrespective of
673 * whether we are in autoneg mode or not.
675 ss = phy_read(phydev, AT803X_SPECIFIC_STATUS);
676 if (ss < 0)
677 return ss;
679 if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) {
680 switch (ss & AT803X_SS_SPEED_MASK) {
681 case AT803X_SS_SPEED_10:
682 phydev->speed = SPEED_10;
683 break;
684 case AT803X_SS_SPEED_100:
685 phydev->speed = SPEED_100;
686 break;
687 case AT803X_SS_SPEED_1000:
688 phydev->speed = SPEED_1000;
689 break;
691 if (ss & AT803X_SS_DUPLEX)
692 phydev->duplex = DUPLEX_FULL;
693 else
694 phydev->duplex = DUPLEX_HALF;
695 if (ss & AT803X_SS_MDIX)
696 phydev->mdix = ETH_TP_MDI_X;
697 else
698 phydev->mdix = ETH_TP_MDI;
701 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
702 phy_resolve_aneg_pause(phydev);
704 return 0;
707 static struct phy_driver at803x_driver[] = {
709 /* Qualcomm Atheros AR8035 */
710 .phy_id = ATH8035_PHY_ID,
711 .name = "Qualcomm Atheros AR8035",
712 .phy_id_mask = AT803X_PHY_ID_MASK,
713 .probe = at803x_probe,
714 .config_init = at803x_config_init,
715 .set_wol = at803x_set_wol,
716 .get_wol = at803x_get_wol,
717 .suspend = at803x_suspend,
718 .resume = at803x_resume,
719 /* PHY_GBIT_FEATURES */
720 .read_status = at803x_read_status,
721 .ack_interrupt = at803x_ack_interrupt,
722 .config_intr = at803x_config_intr,
723 }, {
724 /* Qualcomm Atheros AR8030 */
725 .phy_id = ATH8030_PHY_ID,
726 .name = "Qualcomm Atheros AR8030",
727 .phy_id_mask = AT803X_PHY_ID_MASK,
728 .probe = at803x_probe,
729 .config_init = at803x_config_init,
730 .link_change_notify = at803x_link_change_notify,
731 .set_wol = at803x_set_wol,
732 .get_wol = at803x_get_wol,
733 .suspend = at803x_suspend,
734 .resume = at803x_resume,
735 /* PHY_BASIC_FEATURES */
736 .ack_interrupt = at803x_ack_interrupt,
737 .config_intr = at803x_config_intr,
738 }, {
739 /* Qualcomm Atheros AR8031/AR8033 */
740 .phy_id = ATH8031_PHY_ID,
741 .name = "Qualcomm Atheros AR8031/AR8033",
742 .phy_id_mask = AT803X_PHY_ID_MASK,
743 .probe = at803x_probe,
744 .config_init = at803x_config_init,
745 .set_wol = at803x_set_wol,
746 .get_wol = at803x_get_wol,
747 .suspend = at803x_suspend,
748 .resume = at803x_resume,
749 /* PHY_GBIT_FEATURES */
750 .read_status = at803x_read_status,
751 .aneg_done = at803x_aneg_done,
752 .ack_interrupt = &at803x_ack_interrupt,
753 .config_intr = &at803x_config_intr,
754 }, {
755 /* ATHEROS AR9331 */
756 PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
757 .name = "Qualcomm Atheros AR9331 built-in PHY",
758 .suspend = at803x_suspend,
759 .resume = at803x_resume,
760 /* PHY_BASIC_FEATURES */
761 .ack_interrupt = &at803x_ack_interrupt,
762 .config_intr = &at803x_config_intr,
763 } };
765 module_phy_driver(at803x_driver);
767 static struct mdio_device_id __maybe_unused atheros_tbl[] = {
768 { ATH8030_PHY_ID, AT803X_PHY_ID_MASK },
769 { ATH8031_PHY_ID, AT803X_PHY_ID_MASK },
770 { ATH8035_PHY_ID, AT803X_PHY_ID_MASK },
771 { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) },
775 MODULE_DEVICE_TABLE(mdio, atheros_tbl);