xref: /openbmc/linux/drivers/net/phy/at803x.c (revision 43f2ebd5)
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 
56bd8ca17fSDaniel Mack #define ATH8030_PHY_ID 0x004dd076
57bd8ca17fSDaniel Mack #define ATH8031_PHY_ID 0x004dd074
58bd8ca17fSDaniel Mack #define ATH8035_PHY_ID 0x004dd072
5958effd71SFabio Estevam #define AT803X_PHY_ID_MASK			0xffffffef
60bd8ca17fSDaniel Mack 
610ca7111aSMatus Ujhelyi MODULE_DESCRIPTION("Atheros 803x PHY driver");
620ca7111aSMatus Ujhelyi MODULE_AUTHOR("Matus Ujhelyi");
630ca7111aSMatus Ujhelyi MODULE_LICENSE("GPL");
640ca7111aSMatus Ujhelyi 
6513a56b44SDaniel Mack struct at803x_priv {
6613a56b44SDaniel Mack 	bool phy_reset:1;
6713a56b44SDaniel Mack };
6813a56b44SDaniel Mack 
6913a56b44SDaniel Mack struct at803x_context {
7013a56b44SDaniel Mack 	u16 bmcr;
7113a56b44SDaniel Mack 	u16 advertise;
7213a56b44SDaniel Mack 	u16 control1000;
7313a56b44SDaniel Mack 	u16 int_enable;
7413a56b44SDaniel Mack 	u16 smart_speed;
7513a56b44SDaniel Mack 	u16 led_control;
7613a56b44SDaniel Mack };
7713a56b44SDaniel Mack 
782e5f9f28SMartin Blumenstingl static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
792e5f9f28SMartin Blumenstingl {
802e5f9f28SMartin Blumenstingl 	int ret;
812e5f9f28SMartin Blumenstingl 
822e5f9f28SMartin Blumenstingl 	ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
832e5f9f28SMartin Blumenstingl 	if (ret < 0)
842e5f9f28SMartin Blumenstingl 		return ret;
852e5f9f28SMartin Blumenstingl 
862e5f9f28SMartin Blumenstingl 	return phy_read(phydev, AT803X_DEBUG_DATA);
872e5f9f28SMartin Blumenstingl }
882e5f9f28SMartin Blumenstingl 
892e5f9f28SMartin Blumenstingl static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
902e5f9f28SMartin Blumenstingl 				 u16 clear, u16 set)
912e5f9f28SMartin Blumenstingl {
922e5f9f28SMartin Blumenstingl 	u16 val;
932e5f9f28SMartin Blumenstingl 	int ret;
942e5f9f28SMartin Blumenstingl 
952e5f9f28SMartin Blumenstingl 	ret = at803x_debug_reg_read(phydev, reg);
962e5f9f28SMartin Blumenstingl 	if (ret < 0)
972e5f9f28SMartin Blumenstingl 		return ret;
982e5f9f28SMartin Blumenstingl 
992e5f9f28SMartin Blumenstingl 	val = ret & 0xffff;
1002e5f9f28SMartin Blumenstingl 	val &= ~clear;
1012e5f9f28SMartin Blumenstingl 	val |= set;
1022e5f9f28SMartin Blumenstingl 
1032e5f9f28SMartin Blumenstingl 	return phy_write(phydev, AT803X_DEBUG_DATA, val);
1042e5f9f28SMartin Blumenstingl }
1052e5f9f28SMartin Blumenstingl 
10643f2ebd5SVinod Koul static int at803x_disable_rx_delay(struct phy_device *phydev)
1072e5f9f28SMartin Blumenstingl {
108cd28d1d6SVinod Koul 	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0,
109cd28d1d6SVinod Koul 				     AT803X_DEBUG_RX_CLK_DLY_EN, 0);
1102e5f9f28SMartin Blumenstingl }
1112e5f9f28SMartin Blumenstingl 
11243f2ebd5SVinod Koul static int at803x_disable_tx_delay(struct phy_device *phydev)
1132e5f9f28SMartin Blumenstingl {
114cd28d1d6SVinod Koul 	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
115cd28d1d6SVinod Koul 				     AT803X_DEBUG_TX_CLK_DLY_EN, 0);
1162e5f9f28SMartin Blumenstingl }
1172e5f9f28SMartin Blumenstingl 
11813a56b44SDaniel Mack /* save relevant PHY registers to private copy */
11913a56b44SDaniel Mack static void at803x_context_save(struct phy_device *phydev,
12013a56b44SDaniel Mack 				struct at803x_context *context)
12113a56b44SDaniel Mack {
12213a56b44SDaniel Mack 	context->bmcr = phy_read(phydev, MII_BMCR);
12313a56b44SDaniel Mack 	context->advertise = phy_read(phydev, MII_ADVERTISE);
12413a56b44SDaniel Mack 	context->control1000 = phy_read(phydev, MII_CTRL1000);
12513a56b44SDaniel Mack 	context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE);
12613a56b44SDaniel Mack 	context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED);
12713a56b44SDaniel Mack 	context->led_control = phy_read(phydev, AT803X_LED_CONTROL);
12813a56b44SDaniel Mack }
12913a56b44SDaniel Mack 
13013a56b44SDaniel Mack /* restore relevant PHY registers from private copy */
13113a56b44SDaniel Mack static void at803x_context_restore(struct phy_device *phydev,
13213a56b44SDaniel Mack 				   const struct at803x_context *context)
13313a56b44SDaniel Mack {
13413a56b44SDaniel Mack 	phy_write(phydev, MII_BMCR, context->bmcr);
13513a56b44SDaniel Mack 	phy_write(phydev, MII_ADVERTISE, context->advertise);
13613a56b44SDaniel Mack 	phy_write(phydev, MII_CTRL1000, context->control1000);
13713a56b44SDaniel Mack 	phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable);
13813a56b44SDaniel Mack 	phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed);
13913a56b44SDaniel Mack 	phy_write(phydev, AT803X_LED_CONTROL, context->led_control);
14013a56b44SDaniel Mack }
14113a56b44SDaniel Mack 
142ea13c9eeSMugunthan V N static int at803x_set_wol(struct phy_device *phydev,
143ea13c9eeSMugunthan V N 			  struct ethtool_wolinfo *wol)
1440ca7111aSMatus Ujhelyi {
1450ca7111aSMatus Ujhelyi 	struct net_device *ndev = phydev->attached_dev;
1460ca7111aSMatus Ujhelyi 	const u8 *mac;
147ea13c9eeSMugunthan V N 	int ret;
148ea13c9eeSMugunthan V N 	u32 value;
1490ca7111aSMatus Ujhelyi 	unsigned int i, offsets[] = {
1500ca7111aSMatus Ujhelyi 		AT803X_LOC_MAC_ADDR_32_47_OFFSET,
1510ca7111aSMatus Ujhelyi 		AT803X_LOC_MAC_ADDR_16_31_OFFSET,
1520ca7111aSMatus Ujhelyi 		AT803X_LOC_MAC_ADDR_0_15_OFFSET,
1530ca7111aSMatus Ujhelyi 	};
1540ca7111aSMatus Ujhelyi 
1550ca7111aSMatus Ujhelyi 	if (!ndev)
156ea13c9eeSMugunthan V N 		return -ENODEV;
1570ca7111aSMatus Ujhelyi 
158ea13c9eeSMugunthan V N 	if (wol->wolopts & WAKE_MAGIC) {
1590ca7111aSMatus Ujhelyi 		mac = (const u8 *) ndev->dev_addr;
1600ca7111aSMatus Ujhelyi 
1610ca7111aSMatus Ujhelyi 		if (!is_valid_ether_addr(mac))
162fc755687SDan Murphy 			return -EINVAL;
1630ca7111aSMatus Ujhelyi 
1640e021396SCarlo Caione 		for (i = 0; i < 3; i++)
1650e021396SCarlo Caione 			phy_write_mmd(phydev, AT803X_DEVICE_ADDR, offsets[i],
1660ca7111aSMatus Ujhelyi 				      mac[(i * 2) + 1] | (mac[(i * 2)] << 8));
167ea13c9eeSMugunthan V N 
168ea13c9eeSMugunthan V N 		value = phy_read(phydev, AT803X_INTR_ENABLE);
169e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_WOL;
170ea13c9eeSMugunthan V N 		ret = phy_write(phydev, AT803X_INTR_ENABLE, value);
171ea13c9eeSMugunthan V N 		if (ret)
172ea13c9eeSMugunthan V N 			return ret;
173ea13c9eeSMugunthan V N 		value = phy_read(phydev, AT803X_INTR_STATUS);
174ea13c9eeSMugunthan V N 	} else {
175ea13c9eeSMugunthan V N 		value = phy_read(phydev, AT803X_INTR_ENABLE);
176e6e4a556SMartin Blumenstingl 		value &= (~AT803X_INTR_ENABLE_WOL);
177ea13c9eeSMugunthan V N 		ret = phy_write(phydev, AT803X_INTR_ENABLE, value);
178ea13c9eeSMugunthan V N 		if (ret)
179ea13c9eeSMugunthan V N 			return ret;
180ea13c9eeSMugunthan V N 		value = phy_read(phydev, AT803X_INTR_STATUS);
181ea13c9eeSMugunthan V N 	}
182ea13c9eeSMugunthan V N 
183ea13c9eeSMugunthan V N 	return ret;
184ea13c9eeSMugunthan V N }
185ea13c9eeSMugunthan V N 
186ea13c9eeSMugunthan V N static void at803x_get_wol(struct phy_device *phydev,
187ea13c9eeSMugunthan V N 			   struct ethtool_wolinfo *wol)
188ea13c9eeSMugunthan V N {
189ea13c9eeSMugunthan V N 	u32 value;
190ea13c9eeSMugunthan V N 
191ea13c9eeSMugunthan V N 	wol->supported = WAKE_MAGIC;
192ea13c9eeSMugunthan V N 	wol->wolopts = 0;
193ea13c9eeSMugunthan V N 
194ea13c9eeSMugunthan V N 	value = phy_read(phydev, AT803X_INTR_ENABLE);
195e6e4a556SMartin Blumenstingl 	if (value & AT803X_INTR_ENABLE_WOL)
196ea13c9eeSMugunthan V N 		wol->wolopts |= WAKE_MAGIC;
1970ca7111aSMatus Ujhelyi }
1980ca7111aSMatus Ujhelyi 
1996229ed1fSDaniel Mack static int at803x_suspend(struct phy_device *phydev)
2006229ed1fSDaniel Mack {
2016229ed1fSDaniel Mack 	int value;
2026229ed1fSDaniel Mack 	int wol_enabled;
2036229ed1fSDaniel Mack 
2046229ed1fSDaniel Mack 	value = phy_read(phydev, AT803X_INTR_ENABLE);
205e6e4a556SMartin Blumenstingl 	wol_enabled = value & AT803X_INTR_ENABLE_WOL;
2066229ed1fSDaniel Mack 
2076229ed1fSDaniel Mack 	if (wol_enabled)
208fea23fb5SRussell King 		value = BMCR_ISOLATE;
2096229ed1fSDaniel Mack 	else
210fea23fb5SRussell King 		value = BMCR_PDOWN;
2116229ed1fSDaniel Mack 
212fea23fb5SRussell King 	phy_modify(phydev, MII_BMCR, 0, value);
2136229ed1fSDaniel Mack 
2146229ed1fSDaniel Mack 	return 0;
2156229ed1fSDaniel Mack }
2166229ed1fSDaniel Mack 
2176229ed1fSDaniel Mack static int at803x_resume(struct phy_device *phydev)
2186229ed1fSDaniel Mack {
219f102852fSRussell King 	return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
2206229ed1fSDaniel Mack }
2216229ed1fSDaniel Mack 
22213a56b44SDaniel Mack static int at803x_probe(struct phy_device *phydev)
22313a56b44SDaniel Mack {
224e5a03bfdSAndrew Lunn 	struct device *dev = &phydev->mdio.dev;
22513a56b44SDaniel Mack 	struct at803x_priv *priv;
22613a56b44SDaniel Mack 
2278f2877caSFengguang Wu 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
22813a56b44SDaniel Mack 	if (!priv)
22913a56b44SDaniel Mack 		return -ENOMEM;
23013a56b44SDaniel Mack 
23113a56b44SDaniel Mack 	phydev->priv = priv;
23213a56b44SDaniel Mack 
23313a56b44SDaniel Mack 	return 0;
23413a56b44SDaniel Mack }
23513a56b44SDaniel Mack 
2360ca7111aSMatus Ujhelyi static int at803x_config_init(struct phy_device *phydev)
2370ca7111aSMatus Ujhelyi {
2381ca6d1b1SMugunthan V N 	int ret;
2390ca7111aSMatus Ujhelyi 
2406ff01dbbSDaniel Mack 	ret = genphy_config_init(phydev);
2416ff01dbbSDaniel Mack 	if (ret < 0)
2426ff01dbbSDaniel Mack 		return ret;
2430ca7111aSMatus Ujhelyi 
2442e5f9f28SMartin Blumenstingl 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
245cd28d1d6SVinod Koul 			phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
246cd28d1d6SVinod Koul 			phydev->interface == PHY_INTERFACE_MODE_RGMII) {
247cd28d1d6SVinod Koul 		ret = at803x_disable_rx_delay(phydev);
2482e5f9f28SMartin Blumenstingl 		if (ret < 0)
2491ca6d1b1SMugunthan V N 			return ret;
2502e5f9f28SMartin Blumenstingl 	}
2512e5f9f28SMartin Blumenstingl 
2522e5f9f28SMartin Blumenstingl 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
253cd28d1d6SVinod Koul 			phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
254cd28d1d6SVinod Koul 			phydev->interface == PHY_INTERFACE_MODE_RGMII) {
255cd28d1d6SVinod Koul 		ret = at803x_disable_tx_delay(phydev);
2562e5f9f28SMartin Blumenstingl 		if (ret < 0)
2571ca6d1b1SMugunthan V N 			return ret;
2581ca6d1b1SMugunthan V N 	}
2591ca6d1b1SMugunthan V N 
2600ca7111aSMatus Ujhelyi 	return 0;
2610ca7111aSMatus Ujhelyi }
2620ca7111aSMatus Ujhelyi 
26377a99394SZhao Qiang static int at803x_ack_interrupt(struct phy_device *phydev)
26477a99394SZhao Qiang {
26577a99394SZhao Qiang 	int err;
26677a99394SZhao Qiang 
267a46bd63bSMartin Blumenstingl 	err = phy_read(phydev, AT803X_INTR_STATUS);
26877a99394SZhao Qiang 
26977a99394SZhao Qiang 	return (err < 0) ? err : 0;
27077a99394SZhao Qiang }
27177a99394SZhao Qiang 
27277a99394SZhao Qiang static int at803x_config_intr(struct phy_device *phydev)
27377a99394SZhao Qiang {
27477a99394SZhao Qiang 	int err;
27577a99394SZhao Qiang 	int value;
27677a99394SZhao Qiang 
277a46bd63bSMartin Blumenstingl 	value = phy_read(phydev, AT803X_INTR_ENABLE);
27877a99394SZhao Qiang 
279e6e4a556SMartin Blumenstingl 	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
280e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_AUTONEG_ERR;
281e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_SPEED_CHANGED;
282e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED;
283e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_LINK_FAIL;
284e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_LINK_SUCCESS;
285e6e4a556SMartin Blumenstingl 
286e6e4a556SMartin Blumenstingl 		err = phy_write(phydev, AT803X_INTR_ENABLE, value);
287e6e4a556SMartin Blumenstingl 	}
28877a99394SZhao Qiang 	else
289a46bd63bSMartin Blumenstingl 		err = phy_write(phydev, AT803X_INTR_ENABLE, 0);
29077a99394SZhao Qiang 
29177a99394SZhao Qiang 	return err;
29277a99394SZhao Qiang }
29377a99394SZhao Qiang 
29413a56b44SDaniel Mack static void at803x_link_change_notify(struct phy_device *phydev)
29513a56b44SDaniel Mack {
29613a56b44SDaniel Mack 	struct at803x_priv *priv = phydev->priv;
29713a56b44SDaniel Mack 
29813a56b44SDaniel Mack 	/*
29913a56b44SDaniel Mack 	 * Conduct a hardware reset for AT8030 every time a link loss is
30013a56b44SDaniel Mack 	 * signalled. This is necessary to circumvent a hardware bug that
30113a56b44SDaniel Mack 	 * occurs when the cable is unplugged while TX packets are pending
30213a56b44SDaniel Mack 	 * in the FIFO. In such cases, the FIFO enters an error mode it
30313a56b44SDaniel Mack 	 * cannot recover from by software.
30413a56b44SDaniel Mack 	 */
30513a56b44SDaniel Mack 	if (phydev->state == PHY_NOLINK) {
306bafbdd52SSergei Shtylyov 		if (phydev->mdio.reset && !priv->phy_reset) {
30713a56b44SDaniel Mack 			struct at803x_context context;
30813a56b44SDaniel Mack 
30913a56b44SDaniel Mack 			at803x_context_save(phydev, &context);
31013a56b44SDaniel Mack 
311bafbdd52SSergei Shtylyov 			phy_device_reset(phydev, 1);
31213a56b44SDaniel Mack 			msleep(1);
313bafbdd52SSergei Shtylyov 			phy_device_reset(phydev, 0);
314d57019d1SSergei Shtylyov 			msleep(1);
31513a56b44SDaniel Mack 
31613a56b44SDaniel Mack 			at803x_context_restore(phydev, &context);
31713a56b44SDaniel Mack 
31872ba48beSAndrew Lunn 			phydev_dbg(phydev, "%s(): phy was reset\n",
31913a56b44SDaniel Mack 				   __func__);
32013a56b44SDaniel Mack 			priv->phy_reset = true;
32113a56b44SDaniel Mack 		}
32213a56b44SDaniel Mack 	} else {
32313a56b44SDaniel Mack 		priv->phy_reset = false;
32413a56b44SDaniel Mack 	}
32513a56b44SDaniel Mack }
32613a56b44SDaniel Mack 
327f62265b5SZefir Kurtisi static int at803x_aneg_done(struct phy_device *phydev)
328f62265b5SZefir Kurtisi {
329f62265b5SZefir Kurtisi 	int ccr;
330f62265b5SZefir Kurtisi 
331f62265b5SZefir Kurtisi 	int aneg_done = genphy_aneg_done(phydev);
332f62265b5SZefir Kurtisi 	if (aneg_done != BMSR_ANEGCOMPLETE)
333f62265b5SZefir Kurtisi 		return aneg_done;
334f62265b5SZefir Kurtisi 
335f62265b5SZefir Kurtisi 	/*
336f62265b5SZefir Kurtisi 	 * in SGMII mode, if copper side autoneg is successful,
337f62265b5SZefir Kurtisi 	 * also check SGMII side autoneg result
338f62265b5SZefir Kurtisi 	 */
339f62265b5SZefir Kurtisi 	ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
340f62265b5SZefir Kurtisi 	if ((ccr & AT803X_MODE_CFG_MASK) != AT803X_MODE_CFG_SGMII)
341f62265b5SZefir Kurtisi 		return aneg_done;
342f62265b5SZefir Kurtisi 
343f62265b5SZefir Kurtisi 	/* switch to SGMII/fiber page */
344f62265b5SZefir Kurtisi 	phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr & ~AT803X_BT_BX_REG_SEL);
345f62265b5SZefir Kurtisi 
346f62265b5SZefir Kurtisi 	/* check if the SGMII link is OK. */
347f62265b5SZefir Kurtisi 	if (!(phy_read(phydev, AT803X_PSSR) & AT803X_PSSR_MR_AN_COMPLETE)) {
348ab2a605fSAndrew Lunn 		phydev_warn(phydev, "803x_aneg_done: SGMII link is not ok\n");
349f62265b5SZefir Kurtisi 		aneg_done = 0;
350f62265b5SZefir Kurtisi 	}
351f62265b5SZefir Kurtisi 	/* switch back to copper page */
352f62265b5SZefir Kurtisi 	phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr | AT803X_BT_BX_REG_SEL);
353f62265b5SZefir Kurtisi 
354f62265b5SZefir Kurtisi 	return aneg_done;
355f62265b5SZefir Kurtisi }
356f62265b5SZefir Kurtisi 
357317420abSMugunthan V N static struct phy_driver at803x_driver[] = {
358317420abSMugunthan V N {
3590ca7111aSMatus Ujhelyi 	/* ATHEROS 8035 */
360bd8ca17fSDaniel Mack 	.phy_id			= ATH8035_PHY_ID,
3610ca7111aSMatus Ujhelyi 	.name			= "Atheros 8035 ethernet",
36258effd71SFabio Estevam 	.phy_id_mask		= AT803X_PHY_ID_MASK,
36313a56b44SDaniel Mack 	.probe			= at803x_probe,
3640ca7111aSMatus Ujhelyi 	.config_init		= at803x_config_init,
365ea13c9eeSMugunthan V N 	.set_wol		= at803x_set_wol,
366ea13c9eeSMugunthan V N 	.get_wol		= at803x_get_wol,
3676229ed1fSDaniel Mack 	.suspend		= at803x_suspend,
3686229ed1fSDaniel Mack 	.resume			= at803x_resume,
3690ca7111aSMatus Ujhelyi 	.features		= PHY_GBIT_FEATURES,
3700eae5982SMåns Rullgård 	.ack_interrupt		= at803x_ack_interrupt,
3710eae5982SMåns Rullgård 	.config_intr		= at803x_config_intr,
372317420abSMugunthan V N }, {
3730ca7111aSMatus Ujhelyi 	/* ATHEROS 8030 */
374bd8ca17fSDaniel Mack 	.phy_id			= ATH8030_PHY_ID,
3750ca7111aSMatus Ujhelyi 	.name			= "Atheros 8030 ethernet",
37658effd71SFabio Estevam 	.phy_id_mask		= AT803X_PHY_ID_MASK,
37713a56b44SDaniel Mack 	.probe			= at803x_probe,
3780ca7111aSMatus Ujhelyi 	.config_init		= at803x_config_init,
37913a56b44SDaniel Mack 	.link_change_notify	= at803x_link_change_notify,
380ea13c9eeSMugunthan V N 	.set_wol		= at803x_set_wol,
381ea13c9eeSMugunthan V N 	.get_wol		= at803x_get_wol,
3826229ed1fSDaniel Mack 	.suspend		= at803x_suspend,
3836229ed1fSDaniel Mack 	.resume			= at803x_resume,
384e15bb4c6SMartin Blumenstingl 	.features		= PHY_BASIC_FEATURES,
3850eae5982SMåns Rullgård 	.ack_interrupt		= at803x_ack_interrupt,
3860eae5982SMåns Rullgård 	.config_intr		= at803x_config_intr,
38705d7cce8SMugunthan V N }, {
38805d7cce8SMugunthan V N 	/* ATHEROS 8031 */
389bd8ca17fSDaniel Mack 	.phy_id			= ATH8031_PHY_ID,
39005d7cce8SMugunthan V N 	.name			= "Atheros 8031 ethernet",
39158effd71SFabio Estevam 	.phy_id_mask		= AT803X_PHY_ID_MASK,
39213a56b44SDaniel Mack 	.probe			= at803x_probe,
39305d7cce8SMugunthan V N 	.config_init		= at803x_config_init,
39405d7cce8SMugunthan V N 	.set_wol		= at803x_set_wol,
39505d7cce8SMugunthan V N 	.get_wol		= at803x_get_wol,
3966229ed1fSDaniel Mack 	.suspend		= at803x_suspend,
3976229ed1fSDaniel Mack 	.resume			= at803x_resume,
39805d7cce8SMugunthan V N 	.features		= PHY_GBIT_FEATURES,
399f62265b5SZefir Kurtisi 	.aneg_done		= at803x_aneg_done,
40077a99394SZhao Qiang 	.ack_interrupt		= &at803x_ack_interrupt,
40177a99394SZhao Qiang 	.config_intr		= &at803x_config_intr,
402317420abSMugunthan V N } };
4030ca7111aSMatus Ujhelyi 
40450fd7150SJohan Hovold module_phy_driver(at803x_driver);
4050ca7111aSMatus Ujhelyi 
4060ca7111aSMatus Ujhelyi static struct mdio_device_id __maybe_unused atheros_tbl[] = {
40758effd71SFabio Estevam 	{ ATH8030_PHY_ID, AT803X_PHY_ID_MASK },
40858effd71SFabio Estevam 	{ ATH8031_PHY_ID, AT803X_PHY_ID_MASK },
40958effd71SFabio Estevam 	{ ATH8035_PHY_ID, AT803X_PHY_ID_MASK },
4100ca7111aSMatus Ujhelyi 	{ }
4110ca7111aSMatus Ujhelyi };
4120ca7111aSMatus Ujhelyi 
4130ca7111aSMatus Ujhelyi MODULE_DEVICE_TABLE(mdio, atheros_tbl);
414