1a2443fd1SAndrew Lunn // SPDX-License-Identifier: GPL-2.0+ 20ca7111aSMatus Ujhelyi /* 30ca7111aSMatus Ujhelyi * drivers/net/phy/at803x.c 40ca7111aSMatus Ujhelyi * 50ca7111aSMatus Ujhelyi * Driver for Atheros 803x PHY 60ca7111aSMatus Ujhelyi * 70ca7111aSMatus Ujhelyi * Author: Matus Ujhelyi <ujhelyi.m@gmail.com> 80ca7111aSMatus Ujhelyi */ 90ca7111aSMatus Ujhelyi 100ca7111aSMatus Ujhelyi #include <linux/phy.h> 110ca7111aSMatus Ujhelyi #include <linux/module.h> 120ca7111aSMatus Ujhelyi #include <linux/string.h> 130ca7111aSMatus Ujhelyi #include <linux/netdevice.h> 140ca7111aSMatus Ujhelyi #include <linux/etherdevice.h> 1513a56b44SDaniel Mack #include <linux/of_gpio.h> 1613a56b44SDaniel Mack #include <linux/gpio/consumer.h> 170ca7111aSMatus Ujhelyi 180ca7111aSMatus Ujhelyi #define AT803X_INTR_ENABLE 0x12 19e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15) 20e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14) 21e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13) 22e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12) 23e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_LINK_FAIL BIT(11) 24e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10) 25e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5) 26e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1) 27e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_WOL BIT(0) 28e6e4a556SMartin Blumenstingl 290ca7111aSMatus Ujhelyi #define AT803X_INTR_STATUS 0x13 30a46bd63bSMartin Blumenstingl 3113a56b44SDaniel Mack #define AT803X_SMART_SPEED 0x14 3213a56b44SDaniel Mack #define AT803X_LED_CONTROL 0x18 33a46bd63bSMartin Blumenstingl 340ca7111aSMatus Ujhelyi #define AT803X_DEVICE_ADDR 0x03 350ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C 360ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B 370ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A 38f62265b5SZefir Kurtisi #define AT803X_REG_CHIP_CONFIG 0x1f 39f62265b5SZefir Kurtisi #define AT803X_BT_BX_REG_SEL 0x8000 40a46bd63bSMartin Blumenstingl 411ca6d1b1SMugunthan V N #define AT803X_DEBUG_ADDR 0x1D 421ca6d1b1SMugunthan V N #define AT803X_DEBUG_DATA 0x1E 43a46bd63bSMartin Blumenstingl 44f62265b5SZefir Kurtisi #define AT803X_MODE_CFG_MASK 0x0F 45f62265b5SZefir Kurtisi #define AT803X_MODE_CFG_SGMII 0x01 46f62265b5SZefir Kurtisi 47f62265b5SZefir Kurtisi #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/ 48f62265b5SZefir Kurtisi #define AT803X_PSSR_MR_AN_COMPLETE 0x0200 49f62265b5SZefir Kurtisi 502e5f9f28SMartin Blumenstingl #define AT803X_DEBUG_REG_0 0x00 512e5f9f28SMartin Blumenstingl #define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15) 52a46bd63bSMartin Blumenstingl 532e5f9f28SMartin Blumenstingl #define AT803X_DEBUG_REG_5 0x05 542e5f9f28SMartin Blumenstingl #define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8) 550ca7111aSMatus Ujhelyi 567908d2ceSOleksij Rempel #define ATH9331_PHY_ID 0x004dd041 57bd8ca17fSDaniel Mack #define ATH8030_PHY_ID 0x004dd076 58bd8ca17fSDaniel Mack #define ATH8031_PHY_ID 0x004dd074 59bd8ca17fSDaniel Mack #define ATH8035_PHY_ID 0x004dd072 6058effd71SFabio Estevam #define AT803X_PHY_ID_MASK 0xffffffef 61bd8ca17fSDaniel Mack 620ca7111aSMatus Ujhelyi MODULE_DESCRIPTION("Atheros 803x PHY driver"); 630ca7111aSMatus Ujhelyi MODULE_AUTHOR("Matus Ujhelyi"); 640ca7111aSMatus Ujhelyi MODULE_LICENSE("GPL"); 650ca7111aSMatus Ujhelyi 6613a56b44SDaniel Mack struct at803x_priv { 6713a56b44SDaniel Mack bool phy_reset:1; 6813a56b44SDaniel Mack }; 6913a56b44SDaniel Mack 7013a56b44SDaniel Mack struct at803x_context { 7113a56b44SDaniel Mack u16 bmcr; 7213a56b44SDaniel Mack u16 advertise; 7313a56b44SDaniel Mack u16 control1000; 7413a56b44SDaniel Mack u16 int_enable; 7513a56b44SDaniel Mack u16 smart_speed; 7613a56b44SDaniel Mack u16 led_control; 7713a56b44SDaniel Mack }; 7813a56b44SDaniel Mack 792e5f9f28SMartin Blumenstingl static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg) 802e5f9f28SMartin Blumenstingl { 812e5f9f28SMartin Blumenstingl int ret; 822e5f9f28SMartin Blumenstingl 832e5f9f28SMartin Blumenstingl ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); 842e5f9f28SMartin Blumenstingl if (ret < 0) 852e5f9f28SMartin Blumenstingl return ret; 862e5f9f28SMartin Blumenstingl 872e5f9f28SMartin Blumenstingl return phy_read(phydev, AT803X_DEBUG_DATA); 882e5f9f28SMartin Blumenstingl } 892e5f9f28SMartin Blumenstingl 902e5f9f28SMartin Blumenstingl static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg, 912e5f9f28SMartin Blumenstingl u16 clear, u16 set) 922e5f9f28SMartin Blumenstingl { 932e5f9f28SMartin Blumenstingl u16 val; 942e5f9f28SMartin Blumenstingl int ret; 952e5f9f28SMartin Blumenstingl 962e5f9f28SMartin Blumenstingl ret = at803x_debug_reg_read(phydev, reg); 972e5f9f28SMartin Blumenstingl if (ret < 0) 982e5f9f28SMartin Blumenstingl return ret; 992e5f9f28SMartin Blumenstingl 1002e5f9f28SMartin Blumenstingl val = ret & 0xffff; 1012e5f9f28SMartin Blumenstingl val &= ~clear; 1022e5f9f28SMartin Blumenstingl val |= set; 1032e5f9f28SMartin Blumenstingl 1042e5f9f28SMartin Blumenstingl return phy_write(phydev, AT803X_DEBUG_DATA, val); 1052e5f9f28SMartin Blumenstingl } 1062e5f9f28SMartin Blumenstingl 1076d4cd041SVinod Koul static int at803x_enable_rx_delay(struct phy_device *phydev) 1086d4cd041SVinod Koul { 1096d4cd041SVinod Koul return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0, 1106d4cd041SVinod Koul AT803X_DEBUG_RX_CLK_DLY_EN); 1116d4cd041SVinod Koul } 1126d4cd041SVinod Koul 1136d4cd041SVinod Koul static int at803x_enable_tx_delay(struct phy_device *phydev) 1146d4cd041SVinod Koul { 1156d4cd041SVinod Koul return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0, 1166d4cd041SVinod Koul AT803X_DEBUG_TX_CLK_DLY_EN); 1176d4cd041SVinod Koul } 1186d4cd041SVinod Koul 11943f2ebd5SVinod Koul static int at803x_disable_rx_delay(struct phy_device *phydev) 1202e5f9f28SMartin Blumenstingl { 121cd28d1d6SVinod Koul return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 122cd28d1d6SVinod Koul AT803X_DEBUG_RX_CLK_DLY_EN, 0); 1232e5f9f28SMartin Blumenstingl } 1242e5f9f28SMartin Blumenstingl 12543f2ebd5SVinod Koul static int at803x_disable_tx_delay(struct phy_device *phydev) 1262e5f9f28SMartin Blumenstingl { 127cd28d1d6SVinod Koul return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 128cd28d1d6SVinod Koul AT803X_DEBUG_TX_CLK_DLY_EN, 0); 1292e5f9f28SMartin Blumenstingl } 1302e5f9f28SMartin Blumenstingl 13113a56b44SDaniel Mack /* save relevant PHY registers to private copy */ 13213a56b44SDaniel Mack static void at803x_context_save(struct phy_device *phydev, 13313a56b44SDaniel Mack struct at803x_context *context) 13413a56b44SDaniel Mack { 13513a56b44SDaniel Mack context->bmcr = phy_read(phydev, MII_BMCR); 13613a56b44SDaniel Mack context->advertise = phy_read(phydev, MII_ADVERTISE); 13713a56b44SDaniel Mack context->control1000 = phy_read(phydev, MII_CTRL1000); 13813a56b44SDaniel Mack context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE); 13913a56b44SDaniel Mack context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED); 14013a56b44SDaniel Mack context->led_control = phy_read(phydev, AT803X_LED_CONTROL); 14113a56b44SDaniel Mack } 14213a56b44SDaniel Mack 14313a56b44SDaniel Mack /* restore relevant PHY registers from private copy */ 14413a56b44SDaniel Mack static void at803x_context_restore(struct phy_device *phydev, 14513a56b44SDaniel Mack const struct at803x_context *context) 14613a56b44SDaniel Mack { 14713a56b44SDaniel Mack phy_write(phydev, MII_BMCR, context->bmcr); 14813a56b44SDaniel Mack phy_write(phydev, MII_ADVERTISE, context->advertise); 14913a56b44SDaniel Mack phy_write(phydev, MII_CTRL1000, context->control1000); 15013a56b44SDaniel Mack phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable); 15113a56b44SDaniel Mack phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed); 15213a56b44SDaniel Mack phy_write(phydev, AT803X_LED_CONTROL, context->led_control); 15313a56b44SDaniel Mack } 15413a56b44SDaniel Mack 155ea13c9eeSMugunthan V N static int at803x_set_wol(struct phy_device *phydev, 156ea13c9eeSMugunthan V N struct ethtool_wolinfo *wol) 1570ca7111aSMatus Ujhelyi { 1580ca7111aSMatus Ujhelyi struct net_device *ndev = phydev->attached_dev; 1590ca7111aSMatus Ujhelyi const u8 *mac; 160ea13c9eeSMugunthan V N int ret; 161ea13c9eeSMugunthan V N u32 value; 1620ca7111aSMatus Ujhelyi unsigned int i, offsets[] = { 1630ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_32_47_OFFSET, 1640ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_16_31_OFFSET, 1650ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_0_15_OFFSET, 1660ca7111aSMatus Ujhelyi }; 1670ca7111aSMatus Ujhelyi 1680ca7111aSMatus Ujhelyi if (!ndev) 169ea13c9eeSMugunthan V N return -ENODEV; 1700ca7111aSMatus Ujhelyi 171ea13c9eeSMugunthan V N if (wol->wolopts & WAKE_MAGIC) { 1720ca7111aSMatus Ujhelyi mac = (const u8 *) ndev->dev_addr; 1730ca7111aSMatus Ujhelyi 1740ca7111aSMatus Ujhelyi if (!is_valid_ether_addr(mac)) 175fc755687SDan Murphy return -EINVAL; 1760ca7111aSMatus Ujhelyi 1770e021396SCarlo Caione for (i = 0; i < 3; i++) 1780e021396SCarlo Caione phy_write_mmd(phydev, AT803X_DEVICE_ADDR, offsets[i], 1790ca7111aSMatus Ujhelyi mac[(i * 2) + 1] | (mac[(i * 2)] << 8)); 180ea13c9eeSMugunthan V N 181ea13c9eeSMugunthan V N value = phy_read(phydev, AT803X_INTR_ENABLE); 182e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_WOL; 183ea13c9eeSMugunthan V N ret = phy_write(phydev, AT803X_INTR_ENABLE, value); 184ea13c9eeSMugunthan V N if (ret) 185ea13c9eeSMugunthan V N return ret; 186ea13c9eeSMugunthan V N value = phy_read(phydev, AT803X_INTR_STATUS); 187ea13c9eeSMugunthan V N } else { 188ea13c9eeSMugunthan V N value = phy_read(phydev, AT803X_INTR_ENABLE); 189e6e4a556SMartin Blumenstingl value &= (~AT803X_INTR_ENABLE_WOL); 190ea13c9eeSMugunthan V N ret = phy_write(phydev, AT803X_INTR_ENABLE, value); 191ea13c9eeSMugunthan V N if (ret) 192ea13c9eeSMugunthan V N return ret; 193ea13c9eeSMugunthan V N value = phy_read(phydev, AT803X_INTR_STATUS); 194ea13c9eeSMugunthan V N } 195ea13c9eeSMugunthan V N 196ea13c9eeSMugunthan V N return ret; 197ea13c9eeSMugunthan V N } 198ea13c9eeSMugunthan V N 199ea13c9eeSMugunthan V N static void at803x_get_wol(struct phy_device *phydev, 200ea13c9eeSMugunthan V N struct ethtool_wolinfo *wol) 201ea13c9eeSMugunthan V N { 202ea13c9eeSMugunthan V N u32 value; 203ea13c9eeSMugunthan V N 204ea13c9eeSMugunthan V N wol->supported = WAKE_MAGIC; 205ea13c9eeSMugunthan V N wol->wolopts = 0; 206ea13c9eeSMugunthan V N 207ea13c9eeSMugunthan V N value = phy_read(phydev, AT803X_INTR_ENABLE); 208e6e4a556SMartin Blumenstingl if (value & AT803X_INTR_ENABLE_WOL) 209ea13c9eeSMugunthan V N wol->wolopts |= WAKE_MAGIC; 2100ca7111aSMatus Ujhelyi } 2110ca7111aSMatus Ujhelyi 2126229ed1fSDaniel Mack static int at803x_suspend(struct phy_device *phydev) 2136229ed1fSDaniel Mack { 2146229ed1fSDaniel Mack int value; 2156229ed1fSDaniel Mack int wol_enabled; 2166229ed1fSDaniel Mack 2176229ed1fSDaniel Mack value = phy_read(phydev, AT803X_INTR_ENABLE); 218e6e4a556SMartin Blumenstingl wol_enabled = value & AT803X_INTR_ENABLE_WOL; 2196229ed1fSDaniel Mack 2206229ed1fSDaniel Mack if (wol_enabled) 221fea23fb5SRussell King value = BMCR_ISOLATE; 2226229ed1fSDaniel Mack else 223fea23fb5SRussell King value = BMCR_PDOWN; 2246229ed1fSDaniel Mack 225fea23fb5SRussell King phy_modify(phydev, MII_BMCR, 0, value); 2266229ed1fSDaniel Mack 2276229ed1fSDaniel Mack return 0; 2286229ed1fSDaniel Mack } 2296229ed1fSDaniel Mack 2306229ed1fSDaniel Mack static int at803x_resume(struct phy_device *phydev) 2316229ed1fSDaniel Mack { 232f102852fSRussell King return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0); 2336229ed1fSDaniel Mack } 2346229ed1fSDaniel Mack 23513a56b44SDaniel Mack static int at803x_probe(struct phy_device *phydev) 23613a56b44SDaniel Mack { 237e5a03bfdSAndrew Lunn struct device *dev = &phydev->mdio.dev; 23813a56b44SDaniel Mack struct at803x_priv *priv; 23913a56b44SDaniel Mack 2408f2877caSFengguang Wu priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 24113a56b44SDaniel Mack if (!priv) 24213a56b44SDaniel Mack return -ENOMEM; 24313a56b44SDaniel Mack 24413a56b44SDaniel Mack phydev->priv = priv; 24513a56b44SDaniel Mack 24613a56b44SDaniel Mack return 0; 24713a56b44SDaniel Mack } 24813a56b44SDaniel Mack 2490ca7111aSMatus Ujhelyi static int at803x_config_init(struct phy_device *phydev) 2500ca7111aSMatus Ujhelyi { 2511ca6d1b1SMugunthan V N int ret; 2520ca7111aSMatus Ujhelyi 2536d4cd041SVinod Koul /* The RX and TX delay default is: 2546d4cd041SVinod Koul * after HW reset: RX delay enabled and TX delay disabled 2556d4cd041SVinod Koul * after SW reset: RX delay enabled, while TX delay retains the 2566d4cd041SVinod Koul * value before reset. 2576d4cd041SVinod Koul */ 258bb0ce4c1SAndré Draszik if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || 259bb0ce4c1SAndré Draszik phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) 260bb0ce4c1SAndré Draszik ret = at803x_enable_rx_delay(phydev); 261bb0ce4c1SAndré Draszik else 262cd28d1d6SVinod Koul ret = at803x_disable_rx_delay(phydev); 2632e5f9f28SMartin Blumenstingl if (ret < 0) 2641ca6d1b1SMugunthan V N return ret; 2656d4cd041SVinod Koul 2666d4cd041SVinod Koul if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || 267bb0ce4c1SAndré Draszik phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 2686d4cd041SVinod Koul ret = at803x_enable_tx_delay(phydev); 269bb0ce4c1SAndré Draszik else 270bb0ce4c1SAndré Draszik ret = at803x_disable_tx_delay(phydev); 2716d4cd041SVinod Koul 2726d4cd041SVinod Koul return ret; 2730ca7111aSMatus Ujhelyi } 2740ca7111aSMatus Ujhelyi 27577a99394SZhao Qiang static int at803x_ack_interrupt(struct phy_device *phydev) 27677a99394SZhao Qiang { 27777a99394SZhao Qiang int err; 27877a99394SZhao Qiang 279a46bd63bSMartin Blumenstingl err = phy_read(phydev, AT803X_INTR_STATUS); 28077a99394SZhao Qiang 28177a99394SZhao Qiang return (err < 0) ? err : 0; 28277a99394SZhao Qiang } 28377a99394SZhao Qiang 28477a99394SZhao Qiang static int at803x_config_intr(struct phy_device *phydev) 28577a99394SZhao Qiang { 28677a99394SZhao Qiang int err; 28777a99394SZhao Qiang int value; 28877a99394SZhao Qiang 289a46bd63bSMartin Blumenstingl value = phy_read(phydev, AT803X_INTR_ENABLE); 29077a99394SZhao Qiang 291e6e4a556SMartin Blumenstingl if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { 292e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_AUTONEG_ERR; 293e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_SPEED_CHANGED; 294e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED; 295e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_LINK_FAIL; 296e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_LINK_SUCCESS; 297e6e4a556SMartin Blumenstingl 298e6e4a556SMartin Blumenstingl err = phy_write(phydev, AT803X_INTR_ENABLE, value); 299e6e4a556SMartin Blumenstingl } 30077a99394SZhao Qiang else 301a46bd63bSMartin Blumenstingl err = phy_write(phydev, AT803X_INTR_ENABLE, 0); 30277a99394SZhao Qiang 30377a99394SZhao Qiang return err; 30477a99394SZhao Qiang } 30577a99394SZhao Qiang 30613a56b44SDaniel Mack static void at803x_link_change_notify(struct phy_device *phydev) 30713a56b44SDaniel Mack { 30813a56b44SDaniel Mack /* 30913a56b44SDaniel Mack * Conduct a hardware reset for AT8030 every time a link loss is 31013a56b44SDaniel Mack * signalled. This is necessary to circumvent a hardware bug that 31113a56b44SDaniel Mack * occurs when the cable is unplugged while TX packets are pending 31213a56b44SDaniel Mack * in the FIFO. In such cases, the FIFO enters an error mode it 31313a56b44SDaniel Mack * cannot recover from by software. 31413a56b44SDaniel Mack */ 3156110ed2dSDavid Bauer if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) { 31613a56b44SDaniel Mack struct at803x_context context; 31713a56b44SDaniel Mack 31813a56b44SDaniel Mack at803x_context_save(phydev, &context); 31913a56b44SDaniel Mack 320bafbdd52SSergei Shtylyov phy_device_reset(phydev, 1); 32113a56b44SDaniel Mack msleep(1); 322bafbdd52SSergei Shtylyov phy_device_reset(phydev, 0); 323d57019d1SSergei Shtylyov msleep(1); 32413a56b44SDaniel Mack 32513a56b44SDaniel Mack at803x_context_restore(phydev, &context); 32613a56b44SDaniel Mack 3275c5f626bSHeiner Kallweit phydev_dbg(phydev, "%s(): phy was reset\n", __func__); 32813a56b44SDaniel Mack } 32913a56b44SDaniel Mack } 33013a56b44SDaniel Mack 331f62265b5SZefir Kurtisi static int at803x_aneg_done(struct phy_device *phydev) 332f62265b5SZefir Kurtisi { 333f62265b5SZefir Kurtisi int ccr; 334f62265b5SZefir Kurtisi 335f62265b5SZefir Kurtisi int aneg_done = genphy_aneg_done(phydev); 336f62265b5SZefir Kurtisi if (aneg_done != BMSR_ANEGCOMPLETE) 337f62265b5SZefir Kurtisi return aneg_done; 338f62265b5SZefir Kurtisi 339f62265b5SZefir Kurtisi /* 340f62265b5SZefir Kurtisi * in SGMII mode, if copper side autoneg is successful, 341f62265b5SZefir Kurtisi * also check SGMII side autoneg result 342f62265b5SZefir Kurtisi */ 343f62265b5SZefir Kurtisi ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG); 344f62265b5SZefir Kurtisi if ((ccr & AT803X_MODE_CFG_MASK) != AT803X_MODE_CFG_SGMII) 345f62265b5SZefir Kurtisi return aneg_done; 346f62265b5SZefir Kurtisi 347f62265b5SZefir Kurtisi /* switch to SGMII/fiber page */ 348f62265b5SZefir Kurtisi phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr & ~AT803X_BT_BX_REG_SEL); 349f62265b5SZefir Kurtisi 350f62265b5SZefir Kurtisi /* check if the SGMII link is OK. */ 351f62265b5SZefir Kurtisi if (!(phy_read(phydev, AT803X_PSSR) & AT803X_PSSR_MR_AN_COMPLETE)) { 352ab2a605fSAndrew Lunn phydev_warn(phydev, "803x_aneg_done: SGMII link is not ok\n"); 353f62265b5SZefir Kurtisi aneg_done = 0; 354f62265b5SZefir Kurtisi } 355f62265b5SZefir Kurtisi /* switch back to copper page */ 356f62265b5SZefir Kurtisi phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr | AT803X_BT_BX_REG_SEL); 357f62265b5SZefir Kurtisi 358f62265b5SZefir Kurtisi return aneg_done; 359f62265b5SZefir Kurtisi } 360f62265b5SZefir Kurtisi 361317420abSMugunthan V N static struct phy_driver at803x_driver[] = { 362317420abSMugunthan V N { 3630ca7111aSMatus Ujhelyi /* ATHEROS 8035 */ 364bd8ca17fSDaniel Mack .phy_id = ATH8035_PHY_ID, 3650ca7111aSMatus Ujhelyi .name = "Atheros 8035 ethernet", 36658effd71SFabio Estevam .phy_id_mask = AT803X_PHY_ID_MASK, 36713a56b44SDaniel Mack .probe = at803x_probe, 3680ca7111aSMatus Ujhelyi .config_init = at803x_config_init, 369ea13c9eeSMugunthan V N .set_wol = at803x_set_wol, 370ea13c9eeSMugunthan V N .get_wol = at803x_get_wol, 3716229ed1fSDaniel Mack .suspend = at803x_suspend, 3726229ed1fSDaniel Mack .resume = at803x_resume, 373dcdecdcfSHeiner Kallweit /* PHY_GBIT_FEATURES */ 3740eae5982SMåns Rullgård .ack_interrupt = at803x_ack_interrupt, 3750eae5982SMåns Rullgård .config_intr = at803x_config_intr, 376317420abSMugunthan V N }, { 3770ca7111aSMatus Ujhelyi /* ATHEROS 8030 */ 378bd8ca17fSDaniel Mack .phy_id = ATH8030_PHY_ID, 3790ca7111aSMatus Ujhelyi .name = "Atheros 8030 ethernet", 38058effd71SFabio Estevam .phy_id_mask = AT803X_PHY_ID_MASK, 38113a56b44SDaniel Mack .probe = at803x_probe, 3820ca7111aSMatus Ujhelyi .config_init = at803x_config_init, 38313a56b44SDaniel Mack .link_change_notify = at803x_link_change_notify, 384ea13c9eeSMugunthan V N .set_wol = at803x_set_wol, 385ea13c9eeSMugunthan V N .get_wol = at803x_get_wol, 3866229ed1fSDaniel Mack .suspend = at803x_suspend, 3876229ed1fSDaniel Mack .resume = at803x_resume, 388dcdecdcfSHeiner Kallweit /* PHY_BASIC_FEATURES */ 3890eae5982SMåns Rullgård .ack_interrupt = at803x_ack_interrupt, 3900eae5982SMåns Rullgård .config_intr = at803x_config_intr, 39105d7cce8SMugunthan V N }, { 39205d7cce8SMugunthan V N /* ATHEROS 8031 */ 393bd8ca17fSDaniel Mack .phy_id = ATH8031_PHY_ID, 39405d7cce8SMugunthan V N .name = "Atheros 8031 ethernet", 39558effd71SFabio Estevam .phy_id_mask = AT803X_PHY_ID_MASK, 39613a56b44SDaniel Mack .probe = at803x_probe, 39705d7cce8SMugunthan V N .config_init = at803x_config_init, 39805d7cce8SMugunthan V N .set_wol = at803x_set_wol, 39905d7cce8SMugunthan V N .get_wol = at803x_get_wol, 4006229ed1fSDaniel Mack .suspend = at803x_suspend, 4016229ed1fSDaniel Mack .resume = at803x_resume, 402dcdecdcfSHeiner Kallweit /* PHY_GBIT_FEATURES */ 403f62265b5SZefir Kurtisi .aneg_done = at803x_aneg_done, 40477a99394SZhao Qiang .ack_interrupt = &at803x_ack_interrupt, 40577a99394SZhao Qiang .config_intr = &at803x_config_intr, 4067908d2ceSOleksij Rempel }, { 4077908d2ceSOleksij Rempel /* ATHEROS AR9331 */ 4087908d2ceSOleksij Rempel PHY_ID_MATCH_EXACT(ATH9331_PHY_ID), 4097908d2ceSOleksij Rempel .name = "Atheros AR9331 built-in PHY", 4107908d2ceSOleksij Rempel .config_init = at803x_config_init, 4117908d2ceSOleksij Rempel .suspend = at803x_suspend, 4127908d2ceSOleksij Rempel .resume = at803x_resume, 4137908d2ceSOleksij Rempel /* PHY_BASIC_FEATURES */ 4147908d2ceSOleksij Rempel .ack_interrupt = &at803x_ack_interrupt, 4157908d2ceSOleksij Rempel .config_intr = &at803x_config_intr, 416317420abSMugunthan V N } }; 4170ca7111aSMatus Ujhelyi 41850fd7150SJohan Hovold module_phy_driver(at803x_driver); 4190ca7111aSMatus Ujhelyi 4200ca7111aSMatus Ujhelyi static struct mdio_device_id __maybe_unused atheros_tbl[] = { 42158effd71SFabio Estevam { ATH8030_PHY_ID, AT803X_PHY_ID_MASK }, 42258effd71SFabio Estevam { ATH8031_PHY_ID, AT803X_PHY_ID_MASK }, 42358effd71SFabio Estevam { ATH8035_PHY_ID, AT803X_PHY_ID_MASK }, 4247908d2ceSOleksij Rempel { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) }, 4250ca7111aSMatus Ujhelyi { } 4260ca7111aSMatus Ujhelyi }; 4270ca7111aSMatus Ujhelyi 4280ca7111aSMatus Ujhelyi MODULE_DEVICE_TABLE(mdio, atheros_tbl); 429