xref: /openbmc/linux/drivers/net/phy/at803x.c (revision 24374927)
1a2443fd1SAndrew Lunn // SPDX-License-Identifier: GPL-2.0+
20ca7111aSMatus Ujhelyi /*
30ca7111aSMatus Ujhelyi  * drivers/net/phy/at803x.c
40ca7111aSMatus Ujhelyi  *
596c36712SMichael Walle  * Driver for Qualcomm Atheros AR803x 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>
156cb75767SMichael Walle #include <linux/ethtool_netlink.h>
162f664823SMichael Walle #include <linux/bitfield.h>
172f664823SMichael Walle #include <linux/regulator/of_regulator.h>
182f664823SMichael Walle #include <linux/regulator/driver.h>
192f664823SMichael Walle #include <linux/regulator/consumer.h>
20a593a2fcSAndy Shevchenko #include <linux/of.h>
21dc4d5fccSRobert Hancock #include <linux/phylink.h>
22dc4d5fccSRobert Hancock #include <linux/sfp.h>
232f664823SMichael Walle #include <dt-bindings/net/qca-ar803x.h>
240ca7111aSMatus Ujhelyi 
257dce80c2SOleksij Rempel #define AT803X_SPECIFIC_FUNCTION_CONTROL	0x10
267dce80c2SOleksij Rempel #define AT803X_SFC_ASSERT_CRS			BIT(11)
277dce80c2SOleksij Rempel #define AT803X_SFC_FORCE_LINK			BIT(10)
287dce80c2SOleksij Rempel #define AT803X_SFC_MDI_CROSSOVER_MODE_M		GENMASK(6, 5)
297dce80c2SOleksij Rempel #define AT803X_SFC_AUTOMATIC_CROSSOVER		0x3
307dce80c2SOleksij Rempel #define AT803X_SFC_MANUAL_MDIX			0x1
317dce80c2SOleksij Rempel #define AT803X_SFC_MANUAL_MDI			0x0
327dce80c2SOleksij Rempel #define AT803X_SFC_SQE_TEST			BIT(2)
337dce80c2SOleksij Rempel #define AT803X_SFC_POLARITY_REVERSAL		BIT(1)
347dce80c2SOleksij Rempel #define AT803X_SFC_DISABLE_JABBER		BIT(0)
357dce80c2SOleksij Rempel 
3606d5f344SRussell King #define AT803X_SPECIFIC_STATUS			0x11
379540cddaSLuo Jie #define AT803X_SS_SPEED_MASK			GENMASK(15, 14)
389540cddaSLuo Jie #define AT803X_SS_SPEED_1000			2
399540cddaSLuo Jie #define AT803X_SS_SPEED_100			1
409540cddaSLuo Jie #define AT803X_SS_SPEED_10			0
4106d5f344SRussell King #define AT803X_SS_DUPLEX			BIT(13)
4206d5f344SRussell King #define AT803X_SS_SPEED_DUPLEX_RESOLVED		BIT(11)
4306d5f344SRussell King #define AT803X_SS_MDIX				BIT(6)
4406d5f344SRussell King 
4579c7bc05SLuo Jie #define QCA808X_SS_SPEED_MASK			GENMASK(9, 7)
4679c7bc05SLuo Jie #define QCA808X_SS_SPEED_2500			4
4779c7bc05SLuo Jie 
480ca7111aSMatus Ujhelyi #define AT803X_INTR_ENABLE			0x12
49e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_AUTONEG_ERR		BIT(15)
50e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_SPEED_CHANGED	BIT(14)
51e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_DUPLEX_CHANGED	BIT(13)
52e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_PAGE_RECEIVED	BIT(12)
53e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_LINK_FAIL		BIT(11)
54e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_LINK_SUCCESS		BIT(10)
553265f421SRobert Hancock #define AT803X_INTR_ENABLE_LINK_FAIL_BX		BIT(8)
563265f421SRobert Hancock #define AT803X_INTR_ENABLE_LINK_SUCCESS_BX	BIT(7)
57e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE	BIT(5)
58e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_POLARITY_CHANGED	BIT(1)
59e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_WOL			BIT(0)
60e6e4a556SMartin Blumenstingl 
610ca7111aSMatus Ujhelyi #define AT803X_INTR_STATUS			0x13
62a46bd63bSMartin Blumenstingl 
6313a56b44SDaniel Mack #define AT803X_SMART_SPEED			0x14
64cde0f4f8SMichael Walle #define AT803X_SMART_SPEED_ENABLE		BIT(5)
65cde0f4f8SMichael Walle #define AT803X_SMART_SPEED_RETRY_LIMIT_MASK	GENMASK(4, 2)
66cde0f4f8SMichael Walle #define AT803X_SMART_SPEED_BYPASS_TIMER		BIT(1)
676cb75767SMichael Walle #define AT803X_CDT				0x16
686cb75767SMichael Walle #define AT803X_CDT_MDI_PAIR_MASK		GENMASK(9, 8)
696cb75767SMichael Walle #define AT803X_CDT_ENABLE_TEST			BIT(0)
706cb75767SMichael Walle #define AT803X_CDT_STATUS			0x1c
716cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_NORMAL		0
726cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_SHORT		1
736cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_OPEN		2
746cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_FAIL		3
756cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_MASK		GENMASK(9, 8)
766cb75767SMichael Walle #define AT803X_CDT_STATUS_DELTA_TIME_MASK	GENMASK(7, 0)
7713a56b44SDaniel Mack #define AT803X_LED_CONTROL			0x18
78a46bd63bSMartin Blumenstingl 
797beecaf7SLuo Jie #define AT803X_PHY_MMD3_WOL_CTRL		0x8012
807beecaf7SLuo Jie #define AT803X_WOL_EN				BIT(5)
810ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_0_15_OFFSET		0x804C
820ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_16_31_OFFSET	0x804B
830ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_32_47_OFFSET	0x804A
84f62265b5SZefir Kurtisi #define AT803X_REG_CHIP_CONFIG			0x1f
85f62265b5SZefir Kurtisi #define AT803X_BT_BX_REG_SEL			0x8000
86a46bd63bSMartin Blumenstingl 
871ca6d1b1SMugunthan V N #define AT803X_DEBUG_ADDR			0x1D
881ca6d1b1SMugunthan V N #define AT803X_DEBUG_DATA			0x1E
89a46bd63bSMartin Blumenstingl 
90f62265b5SZefir Kurtisi #define AT803X_MODE_CFG_MASK			0x0F
913265f421SRobert Hancock #define AT803X_MODE_CFG_BASET_RGMII		0x00
923265f421SRobert Hancock #define AT803X_MODE_CFG_BASET_SGMII		0x01
933265f421SRobert Hancock #define AT803X_MODE_CFG_BX1000_RGMII_50OHM	0x02
943265f421SRobert Hancock #define AT803X_MODE_CFG_BX1000_RGMII_75OHM	0x03
953265f421SRobert Hancock #define AT803X_MODE_CFG_BX1000_CONV_50OHM	0x04
963265f421SRobert Hancock #define AT803X_MODE_CFG_BX1000_CONV_75OHM	0x05
973265f421SRobert Hancock #define AT803X_MODE_CFG_FX100_RGMII_50OHM	0x06
983265f421SRobert Hancock #define AT803X_MODE_CFG_FX100_CONV_50OHM	0x07
993265f421SRobert Hancock #define AT803X_MODE_CFG_RGMII_AUTO_MDET		0x0B
1003265f421SRobert Hancock #define AT803X_MODE_CFG_FX100_RGMII_75OHM	0x0E
1013265f421SRobert Hancock #define AT803X_MODE_CFG_FX100_CONV_75OHM	0x0F
102f62265b5SZefir Kurtisi 
103f62265b5SZefir Kurtisi #define AT803X_PSSR				0x11	/*PHY-Specific Status Register*/
104f62265b5SZefir Kurtisi #define AT803X_PSSR_MR_AN_COMPLETE		0x0200
105f62265b5SZefir Kurtisi 
10667999555SAnsuel Smith #define AT803X_DEBUG_ANALOG_TEST_CTRL		0x00
1071ca83119SAnsuel Smith #define QCA8327_DEBUG_MANU_CTRL_EN		BIT(2)
1081ca83119SAnsuel Smith #define QCA8337_DEBUG_MANU_CTRL_EN		GENMASK(3, 2)
1092e5f9f28SMartin Blumenstingl #define AT803X_DEBUG_RX_CLK_DLY_EN		BIT(15)
110a46bd63bSMartin Blumenstingl 
11167999555SAnsuel Smith #define AT803X_DEBUG_SYSTEM_CTRL_MODE		0x05
1122e5f9f28SMartin Blumenstingl #define AT803X_DEBUG_TX_CLK_DLY_EN		BIT(8)
1130ca7111aSMatus Ujhelyi 
114ba3c01eeSAnsuel Smith #define AT803X_DEBUG_REG_HIB_CTRL		0x0b
115ba3c01eeSAnsuel Smith #define   AT803X_DEBUG_HIB_CTRL_SEL_RST_80U	BIT(10)
116ba3c01eeSAnsuel Smith #define   AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE	BIT(13)
1179ecf0401SWei Fang #define   AT803X_DEBUG_HIB_CTRL_PS_HIB_EN	BIT(15)
118ba3c01eeSAnsuel Smith 
119272833b9SAnsuel Smith #define AT803X_DEBUG_REG_3C			0x3C
120272833b9SAnsuel Smith 
12167999555SAnsuel Smith #define AT803X_DEBUG_REG_GREEN			0x3D
122ba3c01eeSAnsuel Smith #define   AT803X_DEBUG_GATE_CLK_IN1000		BIT(6)
123272833b9SAnsuel Smith 
1242f664823SMichael Walle #define AT803X_DEBUG_REG_1F			0x1F
1252f664823SMichael Walle #define AT803X_DEBUG_PLL_ON			BIT(2)
1262f664823SMichael Walle #define AT803X_DEBUG_RGMII_1V8			BIT(3)
1272f664823SMichael Walle 
128272833b9SAnsuel Smith #define MDIO_AZ_DEBUG				0x800D
129272833b9SAnsuel Smith 
1302f664823SMichael Walle /* AT803x supports either the XTAL input pad, an internal PLL or the
1312f664823SMichael Walle  * DSP as clock reference for the clock output pad. The XTAL reference
1322f664823SMichael Walle  * is only used for 25 MHz output, all other frequencies need the PLL.
1332f664823SMichael Walle  * The DSP as a clock reference is used in synchronous ethernet
1342f664823SMichael Walle  * applications.
1352f664823SMichael Walle  *
1362f664823SMichael Walle  * By default the PLL is only enabled if there is a link. Otherwise
1372f664823SMichael Walle  * the PHY will go into low power state and disabled the PLL. You can
1382f664823SMichael Walle  * set the PLL_ON bit (see debug register 0x1f) to keep the PLL always
1392f664823SMichael Walle  * enabled.
1402f664823SMichael Walle  */
1412f664823SMichael Walle #define AT803X_MMD7_CLK25M			0x8016
1422f664823SMichael Walle #define AT803X_CLK_OUT_MASK			GENMASK(4, 2)
1432f664823SMichael Walle #define AT803X_CLK_OUT_25MHZ_XTAL		0
1442f664823SMichael Walle #define AT803X_CLK_OUT_25MHZ_DSP		1
1452f664823SMichael Walle #define AT803X_CLK_OUT_50MHZ_PLL		2
1462f664823SMichael Walle #define AT803X_CLK_OUT_50MHZ_DSP		3
1472f664823SMichael Walle #define AT803X_CLK_OUT_62_5MHZ_PLL		4
1482f664823SMichael Walle #define AT803X_CLK_OUT_62_5MHZ_DSP		5
1492f664823SMichael Walle #define AT803X_CLK_OUT_125MHZ_PLL		6
1502f664823SMichael Walle #define AT803X_CLK_OUT_125MHZ_DSP		7
1512f664823SMichael Walle 
152428061f7SMichael Walle /* The AR8035 has another mask which is compatible with the AR8031/AR8033 mask
153428061f7SMichael Walle  * but doesn't support choosing between XTAL/PLL and DSP.
1542f664823SMichael Walle  */
1552f664823SMichael Walle #define AT8035_CLK_OUT_MASK			GENMASK(4, 3)
1562f664823SMichael Walle 
1572f664823SMichael Walle #define AT803X_CLK_OUT_STRENGTH_MASK		GENMASK(8, 7)
1582f664823SMichael Walle #define AT803X_CLK_OUT_STRENGTH_FULL		0
1592f664823SMichael Walle #define AT803X_CLK_OUT_STRENGTH_HALF		1
1602f664823SMichael Walle #define AT803X_CLK_OUT_STRENGTH_QUARTER		2
1612f664823SMichael Walle 
162cde0f4f8SMichael Walle #define AT803X_DEFAULT_DOWNSHIFT		5
163cde0f4f8SMichael Walle #define AT803X_MIN_DOWNSHIFT			2
164cde0f4f8SMichael Walle #define AT803X_MAX_DOWNSHIFT			9
165cde0f4f8SMichael Walle 
166390b4cadSRussell King #define AT803X_MMD3_SMARTEEE_CTL1		0x805b
167390b4cadSRussell King #define AT803X_MMD3_SMARTEEE_CTL2		0x805c
168390b4cadSRussell King #define AT803X_MMD3_SMARTEEE_CTL3		0x805d
169390b4cadSRussell King #define AT803X_MMD3_SMARTEEE_CTL3_LPI_EN	BIT(8)
170390b4cadSRussell King 
1717908d2ceSOleksij Rempel #define ATH9331_PHY_ID				0x004dd041
172bd8ca17fSDaniel Mack #define ATH8030_PHY_ID				0x004dd076
173bd8ca17fSDaniel Mack #define ATH8031_PHY_ID				0x004dd074
1745800091aSDavid Bauer #define ATH8032_PHY_ID				0x004dd023
175bd8ca17fSDaniel Mack #define ATH8035_PHY_ID				0x004dd072
1760465d8f8SMichael Walle #define AT8030_PHY_ID_MASK			0xffffffef
177bd8ca17fSDaniel Mack 
178daf61732SLuo Jie #define QCA8081_PHY_ID				0x004dd101
179daf61732SLuo Jie 
180b4df02b5SAnsuel Smith #define QCA8327_A_PHY_ID			0x004dd033
181b4df02b5SAnsuel Smith #define QCA8327_B_PHY_ID			0x004dd034
182272833b9SAnsuel Smith #define QCA8337_PHY_ID				0x004dd036
183fada2ce0SDavid Bauer #define QCA9561_PHY_ID				0x004dd042
184272833b9SAnsuel Smith #define QCA8K_PHY_ID_MASK			0xffffffff
185272833b9SAnsuel Smith 
186272833b9SAnsuel Smith #define QCA8K_DEVFLAGS_REVISION_MASK		GENMASK(2, 0)
187272833b9SAnsuel Smith 
188c329e5afSDavid Bauer #define AT803X_PAGE_FIBER			0
189c329e5afSDavid Bauer #define AT803X_PAGE_COPPER			1
190c329e5afSDavid Bauer 
191d0e13fd5SAnsuel Smith /* don't turn off internal PLL */
192d0e13fd5SAnsuel Smith #define AT803X_KEEP_PLL_ENABLED			BIT(0)
193d0e13fd5SAnsuel Smith #define AT803X_DISABLE_SMARTEEE			BIT(1)
194d0e13fd5SAnsuel Smith 
1959ecf0401SWei Fang /* disable hibernation mode */
1969ecf0401SWei Fang #define AT803X_DISABLE_HIBERNATION_MODE		BIT(2)
1979ecf0401SWei Fang 
1982acdd43fSLuo Jie /* ADC threshold */
1992acdd43fSLuo Jie #define QCA808X_PHY_DEBUG_ADC_THRESHOLD		0x2c80
2002acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_MASK		GENMASK(7, 0)
2012acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_80MV		0
2022acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_100MV		0xf0
2032acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_200MV		0x0f
2042acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_300MV		0xff
2052acdd43fSLuo Jie 
2062acdd43fSLuo Jie /* CLD control */
2072acdd43fSLuo Jie #define QCA808X_PHY_MMD3_ADDR_CLD_CTRL7		0x8007
2082acdd43fSLuo Jie #define QCA808X_8023AZ_AFE_CTRL_MASK		GENMASK(8, 4)
2092acdd43fSLuo Jie #define QCA808X_8023AZ_AFE_EN			0x90
2102acdd43fSLuo Jie 
2112acdd43fSLuo Jie /* AZ control */
2122acdd43fSLuo Jie #define QCA808X_PHY_MMD3_AZ_TRAINING_CTRL	0x8008
2132acdd43fSLuo Jie #define QCA808X_MMD3_AZ_TRAINING_VAL		0x1c32
2142acdd43fSLuo Jie 
2152acdd43fSLuo Jie #define QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB	0x8014
2162acdd43fSLuo Jie #define QCA808X_MSE_THRESHOLD_20DB_VALUE	0x529
2172acdd43fSLuo Jie 
2182acdd43fSLuo Jie #define QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB	0x800E
2192acdd43fSLuo Jie #define QCA808X_MSE_THRESHOLD_17DB_VALUE	0x341
2202acdd43fSLuo Jie 
2212acdd43fSLuo Jie #define QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB	0x801E
2222acdd43fSLuo Jie #define QCA808X_MSE_THRESHOLD_27DB_VALUE	0x419
2232acdd43fSLuo Jie 
2242acdd43fSLuo Jie #define QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB	0x8020
2252acdd43fSLuo Jie #define QCA808X_MSE_THRESHOLD_28DB_VALUE	0x341
2262acdd43fSLuo Jie 
2272acdd43fSLuo Jie #define QCA808X_PHY_MMD7_TOP_OPTION1		0x901c
2282acdd43fSLuo Jie #define QCA808X_TOP_OPTION1_DATA		0x0
2292acdd43fSLuo Jie 
2302acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_1		0xa100
2312acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_1_VALUE		0x9203
2322acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_2		0xa101
2332acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_2_VALUE		0x48ad
2342acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_3		0xa103
2352acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_3_VALUE		0x1698
2362acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_4		0xa105
2372acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_4_VALUE		0x8001
2382acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_5		0xa106
2392acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_5_VALUE		0x1111
2402acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_6		0xa011
2412acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_6_VALUE		0x5f85
2422acdd43fSLuo Jie 
2439d4dae29SLuo Jie /* master/slave seed config */
2449d4dae29SLuo Jie #define QCA808X_PHY_DEBUG_LOCAL_SEED		9
2459d4dae29SLuo Jie #define QCA808X_MASTER_SLAVE_SEED_ENABLE	BIT(1)
2469d4dae29SLuo Jie #define QCA808X_MASTER_SLAVE_SEED_CFG		GENMASK(12, 2)
2479d4dae29SLuo Jie #define QCA808X_MASTER_SLAVE_SEED_RANGE		0x32
2489d4dae29SLuo Jie 
2498c84d752SLuo Jie /* Hibernation yields lower power consumpiton in contrast with normal operation mode.
2508c84d752SLuo Jie  * when the copper cable is unplugged, the PHY enters into hibernation mode in about 10s.
2518c84d752SLuo Jie  */
2528c84d752SLuo Jie #define QCA808X_DBG_AN_TEST			0xb
2538c84d752SLuo Jie #define QCA808X_HIBERNATION_EN			BIT(15)
2548c84d752SLuo Jie 
2558c84d752SLuo Jie #define QCA808X_CDT_ENABLE_TEST			BIT(15)
2568c84d752SLuo Jie #define QCA808X_CDT_INTER_CHECK_DIS		BIT(13)
2578c84d752SLuo Jie #define QCA808X_CDT_LENGTH_UNIT			BIT(10)
2588c84d752SLuo Jie 
2598c84d752SLuo Jie #define QCA808X_MMD3_CDT_STATUS			0x8064
2608c84d752SLuo Jie #define QCA808X_MMD3_CDT_DIAG_PAIR_A		0x8065
2618c84d752SLuo Jie #define QCA808X_MMD3_CDT_DIAG_PAIR_B		0x8066
2628c84d752SLuo Jie #define QCA808X_MMD3_CDT_DIAG_PAIR_C		0x8067
2638c84d752SLuo Jie #define QCA808X_MMD3_CDT_DIAG_PAIR_D		0x8068
2648c84d752SLuo Jie #define QCA808X_CDT_DIAG_LENGTH			GENMASK(7, 0)
2658c84d752SLuo Jie 
2668c84d752SLuo Jie #define QCA808X_CDT_CODE_PAIR_A			GENMASK(15, 12)
2678c84d752SLuo Jie #define QCA808X_CDT_CODE_PAIR_B			GENMASK(11, 8)
2688c84d752SLuo Jie #define QCA808X_CDT_CODE_PAIR_C			GENMASK(7, 4)
2698c84d752SLuo Jie #define QCA808X_CDT_CODE_PAIR_D			GENMASK(3, 0)
2708c84d752SLuo Jie #define QCA808X_CDT_STATUS_STAT_FAIL		0
2718c84d752SLuo Jie #define QCA808X_CDT_STATUS_STAT_NORMAL		1
2728c84d752SLuo Jie #define QCA808X_CDT_STATUS_STAT_OPEN		2
2738c84d752SLuo Jie #define QCA808X_CDT_STATUS_STAT_SHORT		3
2748c84d752SLuo Jie 
275fea7cfb8SLuo Jie /* QCA808X 1G chip type */
276fea7cfb8SLuo Jie #define QCA808X_PHY_MMD7_CHIP_TYPE		0x901d
277fea7cfb8SLuo Jie #define QCA808X_PHY_CHIP_TYPE_1G		BIT(0)
278fea7cfb8SLuo Jie 
279723970afSLuo Jie #define QCA8081_PHY_SERDES_MMD1_FIFO_CTRL	0x9072
280723970afSLuo Jie #define QCA8081_PHY_FIFO_RSTN			BIT(11)
281723970afSLuo Jie 
282daf61732SLuo Jie MODULE_DESCRIPTION("Qualcomm Atheros AR803x and QCA808X PHY driver");
2830ca7111aSMatus Ujhelyi MODULE_AUTHOR("Matus Ujhelyi");
2840ca7111aSMatus Ujhelyi MODULE_LICENSE("GPL");
2850ca7111aSMatus Ujhelyi 
286272833b9SAnsuel Smith enum stat_access_type {
287272833b9SAnsuel Smith 	PHY,
288272833b9SAnsuel Smith 	MMD
289272833b9SAnsuel Smith };
290272833b9SAnsuel Smith 
291272833b9SAnsuel Smith struct at803x_hw_stat {
292272833b9SAnsuel Smith 	const char *string;
293272833b9SAnsuel Smith 	u8 reg;
294272833b9SAnsuel Smith 	u32 mask;
295272833b9SAnsuel Smith 	enum stat_access_type access_type;
296272833b9SAnsuel Smith };
297272833b9SAnsuel Smith 
298272833b9SAnsuel Smith static struct at803x_hw_stat at803x_hw_stats[] = {
299272833b9SAnsuel Smith 	{ "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
300272833b9SAnsuel Smith 	{ "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
301272833b9SAnsuel Smith 	{ "eee_wake_errors", 0x16, GENMASK(15, 0), MMD},
302272833b9SAnsuel Smith };
303272833b9SAnsuel Smith 
3042f664823SMichael Walle struct at803x_priv {
3052f664823SMichael Walle 	int flags;
3062f664823SMichael Walle 	u16 clk_25m_reg;
3072f664823SMichael Walle 	u16 clk_25m_mask;
308390b4cadSRussell King 	u8 smarteee_lpi_tw_1g;
309390b4cadSRussell King 	u8 smarteee_lpi_tw_100m;
3103265f421SRobert Hancock 	bool is_fiber;
3113265f421SRobert Hancock 	bool is_1000basex;
3122f664823SMichael Walle 	struct regulator_dev *vddio_rdev;
3132f664823SMichael Walle 	struct regulator_dev *vddh_rdev;
314272833b9SAnsuel Smith 	u64 stats[ARRAY_SIZE(at803x_hw_stats)];
3152f664823SMichael Walle };
3162f664823SMichael Walle 
31713a56b44SDaniel Mack struct at803x_context {
31813a56b44SDaniel Mack 	u16 bmcr;
31913a56b44SDaniel Mack 	u16 advertise;
32013a56b44SDaniel Mack 	u16 control1000;
32113a56b44SDaniel Mack 	u16 int_enable;
32213a56b44SDaniel Mack 	u16 smart_speed;
32313a56b44SDaniel Mack 	u16 led_control;
32413a56b44SDaniel Mack };
32513a56b44SDaniel Mack 
at803x_debug_reg_write(struct phy_device * phydev,u16 reg,u16 data)326272833b9SAnsuel Smith static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data)
327272833b9SAnsuel Smith {
328272833b9SAnsuel Smith 	int ret;
329272833b9SAnsuel Smith 
330272833b9SAnsuel Smith 	ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
331272833b9SAnsuel Smith 	if (ret < 0)
332272833b9SAnsuel Smith 		return ret;
333272833b9SAnsuel Smith 
334272833b9SAnsuel Smith 	return phy_write(phydev, AT803X_DEBUG_DATA, data);
335272833b9SAnsuel Smith }
336272833b9SAnsuel Smith 
at803x_debug_reg_read(struct phy_device * phydev,u16 reg)3372e5f9f28SMartin Blumenstingl static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
3382e5f9f28SMartin Blumenstingl {
3392e5f9f28SMartin Blumenstingl 	int ret;
3402e5f9f28SMartin Blumenstingl 
3412e5f9f28SMartin Blumenstingl 	ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
3422e5f9f28SMartin Blumenstingl 	if (ret < 0)
3432e5f9f28SMartin Blumenstingl 		return ret;
3442e5f9f28SMartin Blumenstingl 
3452e5f9f28SMartin Blumenstingl 	return phy_read(phydev, AT803X_DEBUG_DATA);
3462e5f9f28SMartin Blumenstingl }
3472e5f9f28SMartin Blumenstingl 
at803x_debug_reg_mask(struct phy_device * phydev,u16 reg,u16 clear,u16 set)3482e5f9f28SMartin Blumenstingl static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
3492e5f9f28SMartin Blumenstingl 				 u16 clear, u16 set)
3502e5f9f28SMartin Blumenstingl {
3512e5f9f28SMartin Blumenstingl 	u16 val;
3522e5f9f28SMartin Blumenstingl 	int ret;
3532e5f9f28SMartin Blumenstingl 
3542e5f9f28SMartin Blumenstingl 	ret = at803x_debug_reg_read(phydev, reg);
3552e5f9f28SMartin Blumenstingl 	if (ret < 0)
3562e5f9f28SMartin Blumenstingl 		return ret;
3572e5f9f28SMartin Blumenstingl 
3582e5f9f28SMartin Blumenstingl 	val = ret & 0xffff;
3592e5f9f28SMartin Blumenstingl 	val &= ~clear;
3602e5f9f28SMartin Blumenstingl 	val |= set;
3612e5f9f28SMartin Blumenstingl 
3622e5f9f28SMartin Blumenstingl 	return phy_write(phydev, AT803X_DEBUG_DATA, val);
3632e5f9f28SMartin Blumenstingl }
3642e5f9f28SMartin Blumenstingl 
at803x_write_page(struct phy_device * phydev,int page)365c329e5afSDavid Bauer static int at803x_write_page(struct phy_device *phydev, int page)
366c329e5afSDavid Bauer {
367c329e5afSDavid Bauer 	int mask;
368c329e5afSDavid Bauer 	int set;
369c329e5afSDavid Bauer 
370c329e5afSDavid Bauer 	if (page == AT803X_PAGE_COPPER) {
371c329e5afSDavid Bauer 		set = AT803X_BT_BX_REG_SEL;
372c329e5afSDavid Bauer 		mask = 0;
373c329e5afSDavid Bauer 	} else {
374c329e5afSDavid Bauer 		set = 0;
375c329e5afSDavid Bauer 		mask = AT803X_BT_BX_REG_SEL;
376c329e5afSDavid Bauer 	}
377c329e5afSDavid Bauer 
378c329e5afSDavid Bauer 	return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set);
379c329e5afSDavid Bauer }
380c329e5afSDavid Bauer 
at803x_read_page(struct phy_device * phydev)381c329e5afSDavid Bauer static int at803x_read_page(struct phy_device *phydev)
382c329e5afSDavid Bauer {
383c329e5afSDavid Bauer 	int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG);
384c329e5afSDavid Bauer 
385c329e5afSDavid Bauer 	if (ccr < 0)
386c329e5afSDavid Bauer 		return ccr;
387c329e5afSDavid Bauer 
388c329e5afSDavid Bauer 	if (ccr & AT803X_BT_BX_REG_SEL)
389c329e5afSDavid Bauer 		return AT803X_PAGE_COPPER;
390c329e5afSDavid Bauer 
391c329e5afSDavid Bauer 	return AT803X_PAGE_FIBER;
392c329e5afSDavid Bauer }
393c329e5afSDavid Bauer 
at803x_enable_rx_delay(struct phy_device * phydev)3946d4cd041SVinod Koul static int at803x_enable_rx_delay(struct phy_device *phydev)
3956d4cd041SVinod Koul {
39667999555SAnsuel Smith 	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0,
3976d4cd041SVinod Koul 				     AT803X_DEBUG_RX_CLK_DLY_EN);
3986d4cd041SVinod Koul }
3996d4cd041SVinod Koul 
at803x_enable_tx_delay(struct phy_device * phydev)4006d4cd041SVinod Koul static int at803x_enable_tx_delay(struct phy_device *phydev)
4016d4cd041SVinod Koul {
40267999555SAnsuel Smith 	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0,
4036d4cd041SVinod Koul 				     AT803X_DEBUG_TX_CLK_DLY_EN);
4046d4cd041SVinod Koul }
4056d4cd041SVinod Koul 
at803x_disable_rx_delay(struct phy_device * phydev)40643f2ebd5SVinod Koul static int at803x_disable_rx_delay(struct phy_device *phydev)
4072e5f9f28SMartin Blumenstingl {
40867999555SAnsuel Smith 	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
409cd28d1d6SVinod Koul 				     AT803X_DEBUG_RX_CLK_DLY_EN, 0);
4102e5f9f28SMartin Blumenstingl }
4112e5f9f28SMartin Blumenstingl 
at803x_disable_tx_delay(struct phy_device * phydev)41243f2ebd5SVinod Koul static int at803x_disable_tx_delay(struct phy_device *phydev)
4132e5f9f28SMartin Blumenstingl {
41467999555SAnsuel Smith 	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE,
415cd28d1d6SVinod Koul 				     AT803X_DEBUG_TX_CLK_DLY_EN, 0);
4162e5f9f28SMartin Blumenstingl }
4172e5f9f28SMartin Blumenstingl 
41813a56b44SDaniel Mack /* save relevant PHY registers to private copy */
at803x_context_save(struct phy_device * phydev,struct at803x_context * context)41913a56b44SDaniel Mack static void at803x_context_save(struct phy_device *phydev,
42013a56b44SDaniel Mack 				struct at803x_context *context)
42113a56b44SDaniel Mack {
42213a56b44SDaniel Mack 	context->bmcr = phy_read(phydev, MII_BMCR);
42313a56b44SDaniel Mack 	context->advertise = phy_read(phydev, MII_ADVERTISE);
42413a56b44SDaniel Mack 	context->control1000 = phy_read(phydev, MII_CTRL1000);
42513a56b44SDaniel Mack 	context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE);
42613a56b44SDaniel Mack 	context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED);
42713a56b44SDaniel Mack 	context->led_control = phy_read(phydev, AT803X_LED_CONTROL);
42813a56b44SDaniel Mack }
42913a56b44SDaniel Mack 
43013a56b44SDaniel Mack /* restore relevant PHY registers from private copy */
at803x_context_restore(struct phy_device * phydev,const struct at803x_context * context)43113a56b44SDaniel Mack static void at803x_context_restore(struct phy_device *phydev,
43213a56b44SDaniel Mack 				   const struct at803x_context *context)
43313a56b44SDaniel Mack {
43413a56b44SDaniel Mack 	phy_write(phydev, MII_BMCR, context->bmcr);
43513a56b44SDaniel Mack 	phy_write(phydev, MII_ADVERTISE, context->advertise);
43613a56b44SDaniel Mack 	phy_write(phydev, MII_CTRL1000, context->control1000);
43713a56b44SDaniel Mack 	phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable);
43813a56b44SDaniel Mack 	phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed);
43913a56b44SDaniel Mack 	phy_write(phydev, AT803X_LED_CONTROL, context->led_control);
44013a56b44SDaniel Mack }
44113a56b44SDaniel Mack 
at803x_set_wol(struct phy_device * phydev,struct ethtool_wolinfo * wol)442ea13c9eeSMugunthan V N static int at803x_set_wol(struct phy_device *phydev,
443ea13c9eeSMugunthan V N 			  struct ethtool_wolinfo *wol)
4440ca7111aSMatus Ujhelyi {
445d7cd5e06SViorel Suman 	int ret, irq_enabled;
446d7cd5e06SViorel Suman 
447d7cd5e06SViorel Suman 	if (wol->wolopts & WAKE_MAGIC) {
4480ca7111aSMatus Ujhelyi 		struct net_device *ndev = phydev->attached_dev;
4490ca7111aSMatus Ujhelyi 		const u8 *mac;
450c0f0b563SLuo Jie 		unsigned int i;
451edcb501eSColin Ian King 		static const unsigned int offsets[] = {
4520ca7111aSMatus Ujhelyi 			AT803X_LOC_MAC_ADDR_32_47_OFFSET,
4530ca7111aSMatus Ujhelyi 			AT803X_LOC_MAC_ADDR_16_31_OFFSET,
4540ca7111aSMatus Ujhelyi 			AT803X_LOC_MAC_ADDR_0_15_OFFSET,
4550ca7111aSMatus Ujhelyi 		};
4560ca7111aSMatus Ujhelyi 
4570ca7111aSMatus Ujhelyi 		if (!ndev)
458ea13c9eeSMugunthan V N 			return -ENODEV;
4590ca7111aSMatus Ujhelyi 
4600ca7111aSMatus Ujhelyi 		mac = (const u8 *) ndev->dev_addr;
4610ca7111aSMatus Ujhelyi 
4620ca7111aSMatus Ujhelyi 		if (!is_valid_ether_addr(mac))
463fc755687SDan Murphy 			return -EINVAL;
4640ca7111aSMatus Ujhelyi 
4650e021396SCarlo Caione 		for (i = 0; i < 3; i++)
466c0f0b563SLuo Jie 			phy_write_mmd(phydev, MDIO_MMD_PCS, offsets[i],
4670ca7111aSMatus Ujhelyi 				      mac[(i * 2) + 1] | (mac[(i * 2)] << 8));
468ea13c9eeSMugunthan V N 
469e58f3024SLi Yang 		/* Enable WOL function for 1588 */
470e58f3024SLi Yang 		if (phydev->drv->phy_id == ATH8031_PHY_ID) {
471e58f3024SLi Yang 			ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
472e58f3024SLi Yang 					     AT803X_PHY_MMD3_WOL_CTRL,
4737beecaf7SLuo Jie 					     0, AT803X_WOL_EN);
4747beecaf7SLuo Jie 			if (ret)
4757beecaf7SLuo Jie 				return ret;
476e58f3024SLi Yang 		}
4777beecaf7SLuo Jie 		/* Enable WOL interrupt */
4782d4284e8SLuo Jie 		ret = phy_modify(phydev, AT803X_INTR_ENABLE, 0, AT803X_INTR_ENABLE_WOL);
479ea13c9eeSMugunthan V N 		if (ret)
480ea13c9eeSMugunthan V N 			return ret;
481ea13c9eeSMugunthan V N 	} else {
482e58f3024SLi Yang 		/* Disable WoL function for 1588 */
483e58f3024SLi Yang 		if (phydev->drv->phy_id == ATH8031_PHY_ID) {
484e58f3024SLi Yang 			ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
485e58f3024SLi Yang 					     AT803X_PHY_MMD3_WOL_CTRL,
4867beecaf7SLuo Jie 					     AT803X_WOL_EN, 0);
4877beecaf7SLuo Jie 			if (ret)
4887beecaf7SLuo Jie 				return ret;
489e58f3024SLi Yang 		}
4907beecaf7SLuo Jie 		/* Disable WOL interrupt */
4912d4284e8SLuo Jie 		ret = phy_modify(phydev, AT803X_INTR_ENABLE, AT803X_INTR_ENABLE_WOL, 0);
492ea13c9eeSMugunthan V N 		if (ret)
493ea13c9eeSMugunthan V N 			return ret;
494ea13c9eeSMugunthan V N 	}
495ea13c9eeSMugunthan V N 
4967beecaf7SLuo Jie 	/* Clear WOL status */
4977beecaf7SLuo Jie 	ret = phy_read(phydev, AT803X_INTR_STATUS);
4987beecaf7SLuo Jie 	if (ret < 0)
499ea13c9eeSMugunthan V N 		return ret;
5007beecaf7SLuo Jie 
5017beecaf7SLuo Jie 	/* Check if there are other interrupts except for WOL triggered when PHY is
5027beecaf7SLuo Jie 	 * in interrupt mode, only the interrupts enabled by AT803X_INTR_ENABLE can
5037beecaf7SLuo Jie 	 * be passed up to the interrupt PIN.
5047beecaf7SLuo Jie 	 */
5057beecaf7SLuo Jie 	irq_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
5067beecaf7SLuo Jie 	if (irq_enabled < 0)
5077beecaf7SLuo Jie 		return irq_enabled;
5087beecaf7SLuo Jie 
5097beecaf7SLuo Jie 	irq_enabled &= ~AT803X_INTR_ENABLE_WOL;
5107beecaf7SLuo Jie 	if (ret & irq_enabled && !phy_polling_mode(phydev))
5117beecaf7SLuo Jie 		phy_trigger_machine(phydev);
5127beecaf7SLuo Jie 
5137beecaf7SLuo Jie 	return 0;
514ea13c9eeSMugunthan V N }
515ea13c9eeSMugunthan V N 
at803x_get_wol(struct phy_device * phydev,struct ethtool_wolinfo * wol)516ea13c9eeSMugunthan V N static void at803x_get_wol(struct phy_device *phydev,
517ea13c9eeSMugunthan V N 			   struct ethtool_wolinfo *wol)
518ea13c9eeSMugunthan V N {
519911e3a46SJiapeng Chong 	int value;
520ea13c9eeSMugunthan V N 
521ea13c9eeSMugunthan V N 	wol->supported = WAKE_MAGIC;
522ea13c9eeSMugunthan V N 	wol->wolopts = 0;
523ea13c9eeSMugunthan V N 
524e58f3024SLi Yang 	value = phy_read(phydev, AT803X_INTR_ENABLE);
5257beecaf7SLuo Jie 	if (value < 0)
5267beecaf7SLuo Jie 		return;
5277beecaf7SLuo Jie 
528e58f3024SLi Yang 	if (value & AT803X_INTR_ENABLE_WOL)
529ea13c9eeSMugunthan V N 		wol->wolopts |= WAKE_MAGIC;
5300ca7111aSMatus Ujhelyi }
5310ca7111aSMatus Ujhelyi 
at803x_get_sset_count(struct phy_device * phydev)532272833b9SAnsuel Smith static int at803x_get_sset_count(struct phy_device *phydev)
533272833b9SAnsuel Smith {
534272833b9SAnsuel Smith 	return ARRAY_SIZE(at803x_hw_stats);
535272833b9SAnsuel Smith }
536272833b9SAnsuel Smith 
at803x_get_strings(struct phy_device * phydev,u8 * data)537272833b9SAnsuel Smith static void at803x_get_strings(struct phy_device *phydev, u8 *data)
538272833b9SAnsuel Smith {
539272833b9SAnsuel Smith 	int i;
540272833b9SAnsuel Smith 
541272833b9SAnsuel Smith 	for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) {
542272833b9SAnsuel Smith 		strscpy(data + i * ETH_GSTRING_LEN,
543272833b9SAnsuel Smith 			at803x_hw_stats[i].string, ETH_GSTRING_LEN);
544272833b9SAnsuel Smith 	}
545272833b9SAnsuel Smith }
546272833b9SAnsuel Smith 
at803x_get_stat(struct phy_device * phydev,int i)547272833b9SAnsuel Smith static u64 at803x_get_stat(struct phy_device *phydev, int i)
548272833b9SAnsuel Smith {
549272833b9SAnsuel Smith 	struct at803x_hw_stat stat = at803x_hw_stats[i];
550272833b9SAnsuel Smith 	struct at803x_priv *priv = phydev->priv;
551272833b9SAnsuel Smith 	int val;
552272833b9SAnsuel Smith 	u64 ret;
553272833b9SAnsuel Smith 
554272833b9SAnsuel Smith 	if (stat.access_type == MMD)
555272833b9SAnsuel Smith 		val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg);
556272833b9SAnsuel Smith 	else
557272833b9SAnsuel Smith 		val = phy_read(phydev, stat.reg);
558272833b9SAnsuel Smith 
559272833b9SAnsuel Smith 	if (val < 0) {
560272833b9SAnsuel Smith 		ret = U64_MAX;
561272833b9SAnsuel Smith 	} else {
562272833b9SAnsuel Smith 		val = val & stat.mask;
563272833b9SAnsuel Smith 		priv->stats[i] += val;
564272833b9SAnsuel Smith 		ret = priv->stats[i];
565272833b9SAnsuel Smith 	}
566272833b9SAnsuel Smith 
567272833b9SAnsuel Smith 	return ret;
568272833b9SAnsuel Smith }
569272833b9SAnsuel Smith 
at803x_get_stats(struct phy_device * phydev,struct ethtool_stats * stats,u64 * data)570272833b9SAnsuel Smith static void at803x_get_stats(struct phy_device *phydev,
571272833b9SAnsuel Smith 			     struct ethtool_stats *stats, u64 *data)
572272833b9SAnsuel Smith {
573272833b9SAnsuel Smith 	int i;
574272833b9SAnsuel Smith 
575272833b9SAnsuel Smith 	for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++)
576272833b9SAnsuel Smith 		data[i] = at803x_get_stat(phydev, i);
577272833b9SAnsuel Smith }
578272833b9SAnsuel Smith 
at803x_suspend(struct phy_device * phydev)5796229ed1fSDaniel Mack static int at803x_suspend(struct phy_device *phydev)
5806229ed1fSDaniel Mack {
5816229ed1fSDaniel Mack 	int value;
5826229ed1fSDaniel Mack 	int wol_enabled;
5836229ed1fSDaniel Mack 
5846229ed1fSDaniel Mack 	value = phy_read(phydev, AT803X_INTR_ENABLE);
585e6e4a556SMartin Blumenstingl 	wol_enabled = value & AT803X_INTR_ENABLE_WOL;
5866229ed1fSDaniel Mack 
5876229ed1fSDaniel Mack 	if (wol_enabled)
588fea23fb5SRussell King 		value = BMCR_ISOLATE;
5896229ed1fSDaniel Mack 	else
590fea23fb5SRussell King 		value = BMCR_PDOWN;
5916229ed1fSDaniel Mack 
592fea23fb5SRussell King 	phy_modify(phydev, MII_BMCR, 0, value);
5936229ed1fSDaniel Mack 
5946229ed1fSDaniel Mack 	return 0;
5956229ed1fSDaniel Mack }
5966229ed1fSDaniel Mack 
at803x_resume(struct phy_device * phydev)5976229ed1fSDaniel Mack static int at803x_resume(struct phy_device *phydev)
5986229ed1fSDaniel Mack {
599f102852fSRussell King 	return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
6006229ed1fSDaniel Mack }
6016229ed1fSDaniel Mack 
at803x_rgmii_reg_set_voltage_sel(struct regulator_dev * rdev,unsigned int selector)6022f664823SMichael Walle static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
6032f664823SMichael Walle 					    unsigned int selector)
6042f664823SMichael Walle {
6052f664823SMichael Walle 	struct phy_device *phydev = rdev_get_drvdata(rdev);
6062f664823SMichael Walle 
6072f664823SMichael Walle 	if (selector)
6082f664823SMichael Walle 		return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
6092f664823SMichael Walle 					     0, AT803X_DEBUG_RGMII_1V8);
6102f664823SMichael Walle 	else
6112f664823SMichael Walle 		return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
6122f664823SMichael Walle 					     AT803X_DEBUG_RGMII_1V8, 0);
6132f664823SMichael Walle }
6142f664823SMichael Walle 
at803x_rgmii_reg_get_voltage_sel(struct regulator_dev * rdev)6152f664823SMichael Walle static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
6162f664823SMichael Walle {
6172f664823SMichael Walle 	struct phy_device *phydev = rdev_get_drvdata(rdev);
6182f664823SMichael Walle 	int val;
6192f664823SMichael Walle 
6202f664823SMichael Walle 	val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
6212f664823SMichael Walle 	if (val < 0)
6222f664823SMichael Walle 		return val;
6232f664823SMichael Walle 
6242f664823SMichael Walle 	return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
6252f664823SMichael Walle }
6262f664823SMichael Walle 
6273faaf539SRikard Falkeborn static const struct regulator_ops vddio_regulator_ops = {
6282f664823SMichael Walle 	.list_voltage = regulator_list_voltage_table,
6292f664823SMichael Walle 	.set_voltage_sel = at803x_rgmii_reg_set_voltage_sel,
6302f664823SMichael Walle 	.get_voltage_sel = at803x_rgmii_reg_get_voltage_sel,
6312f664823SMichael Walle };
6322f664823SMichael Walle 
6332f664823SMichael Walle static const unsigned int vddio_voltage_table[] = {
6342f664823SMichael Walle 	1500000,
6352f664823SMichael Walle 	1800000,
6362f664823SMichael Walle };
6372f664823SMichael Walle 
6382f664823SMichael Walle static const struct regulator_desc vddio_desc = {
6392f664823SMichael Walle 	.name = "vddio",
6402f664823SMichael Walle 	.of_match = of_match_ptr("vddio-regulator"),
6412f664823SMichael Walle 	.n_voltages = ARRAY_SIZE(vddio_voltage_table),
6422f664823SMichael Walle 	.volt_table = vddio_voltage_table,
6432f664823SMichael Walle 	.ops = &vddio_regulator_ops,
6442f664823SMichael Walle 	.type = REGULATOR_VOLTAGE,
6452f664823SMichael Walle 	.owner = THIS_MODULE,
6462f664823SMichael Walle };
6472f664823SMichael Walle 
6483faaf539SRikard Falkeborn static const struct regulator_ops vddh_regulator_ops = {
6492f664823SMichael Walle };
6502f664823SMichael Walle 
6512f664823SMichael Walle static const struct regulator_desc vddh_desc = {
6522f664823SMichael Walle 	.name = "vddh",
6532f664823SMichael Walle 	.of_match = of_match_ptr("vddh-regulator"),
6542f664823SMichael Walle 	.n_voltages = 1,
6552f664823SMichael Walle 	.fixed_uV = 2500000,
6562f664823SMichael Walle 	.ops = &vddh_regulator_ops,
6572f664823SMichael Walle 	.type = REGULATOR_VOLTAGE,
6582f664823SMichael Walle 	.owner = THIS_MODULE,
6592f664823SMichael Walle };
6602f664823SMichael Walle 
at8031_register_regulators(struct phy_device * phydev)6612f664823SMichael Walle static int at8031_register_regulators(struct phy_device *phydev)
6622f664823SMichael Walle {
6632f664823SMichael Walle 	struct at803x_priv *priv = phydev->priv;
6642f664823SMichael Walle 	struct device *dev = &phydev->mdio.dev;
6652f664823SMichael Walle 	struct regulator_config config = { };
6662f664823SMichael Walle 
6672f664823SMichael Walle 	config.dev = dev;
6682f664823SMichael Walle 	config.driver_data = phydev;
6692f664823SMichael Walle 
6702f664823SMichael Walle 	priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
6712f664823SMichael Walle 	if (IS_ERR(priv->vddio_rdev)) {
6722f664823SMichael Walle 		phydev_err(phydev, "failed to register VDDIO regulator\n");
6732f664823SMichael Walle 		return PTR_ERR(priv->vddio_rdev);
6742f664823SMichael Walle 	}
6752f664823SMichael Walle 
6762f664823SMichael Walle 	priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
6772f664823SMichael Walle 	if (IS_ERR(priv->vddh_rdev)) {
6782f664823SMichael Walle 		phydev_err(phydev, "failed to register VDDH regulator\n");
6792f664823SMichael Walle 		return PTR_ERR(priv->vddh_rdev);
6802f664823SMichael Walle 	}
6812f664823SMichael Walle 
6822f664823SMichael Walle 	return 0;
6832f664823SMichael Walle }
6842f664823SMichael Walle 
at803x_sfp_insert(void * upstream,const struct sfp_eeprom_id * id)685dc4d5fccSRobert Hancock static int at803x_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
686dc4d5fccSRobert Hancock {
687dc4d5fccSRobert Hancock 	struct phy_device *phydev = upstream;
688dc4d5fccSRobert Hancock 	__ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support);
689dc4d5fccSRobert Hancock 	__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
690fd580c98SRussell King 	DECLARE_PHY_INTERFACE_MASK(interfaces);
691dc4d5fccSRobert Hancock 	phy_interface_t iface;
692dc4d5fccSRobert Hancock 
693dc4d5fccSRobert Hancock 	linkmode_zero(phy_support);
694dc4d5fccSRobert Hancock 	phylink_set(phy_support, 1000baseX_Full);
695dc4d5fccSRobert Hancock 	phylink_set(phy_support, 1000baseT_Full);
696dc4d5fccSRobert Hancock 	phylink_set(phy_support, Autoneg);
697dc4d5fccSRobert Hancock 	phylink_set(phy_support, Pause);
698dc4d5fccSRobert Hancock 	phylink_set(phy_support, Asym_Pause);
699dc4d5fccSRobert Hancock 
700dc4d5fccSRobert Hancock 	linkmode_zero(sfp_support);
701fd580c98SRussell King 	sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
702dc4d5fccSRobert Hancock 	/* Some modules support 10G modes as well as others we support.
703dc4d5fccSRobert Hancock 	 * Mask out non-supported modes so the correct interface is picked.
704dc4d5fccSRobert Hancock 	 */
705dc4d5fccSRobert Hancock 	linkmode_and(sfp_support, phy_support, sfp_support);
706dc4d5fccSRobert Hancock 
707dc4d5fccSRobert Hancock 	if (linkmode_empty(sfp_support)) {
708dc4d5fccSRobert Hancock 		dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
709dc4d5fccSRobert Hancock 		return -EINVAL;
710dc4d5fccSRobert Hancock 	}
711dc4d5fccSRobert Hancock 
712dc4d5fccSRobert Hancock 	iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
713dc4d5fccSRobert Hancock 
714dc4d5fccSRobert Hancock 	/* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes
715dc4d5fccSRobert Hancock 	 * interface for use with SFP modules.
716dc4d5fccSRobert Hancock 	 * However, some copper modules detected as having a preferred SGMII
717dc4d5fccSRobert Hancock 	 * interface do default to and function in 1000Base-X mode, so just
718dc4d5fccSRobert Hancock 	 * print a warning and allow such modules, as they may have some chance
719dc4d5fccSRobert Hancock 	 * of working.
720dc4d5fccSRobert Hancock 	 */
721dc4d5fccSRobert Hancock 	if (iface == PHY_INTERFACE_MODE_SGMII)
722dc4d5fccSRobert Hancock 		dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n");
723dc4d5fccSRobert Hancock 	else if (iface != PHY_INTERFACE_MODE_1000BASEX)
724dc4d5fccSRobert Hancock 		return -EINVAL;
725dc4d5fccSRobert Hancock 
726dc4d5fccSRobert Hancock 	return 0;
727dc4d5fccSRobert Hancock }
728dc4d5fccSRobert Hancock 
729dc4d5fccSRobert Hancock static const struct sfp_upstream_ops at803x_sfp_ops = {
730dc4d5fccSRobert Hancock 	.attach = phy_sfp_attach,
731dc4d5fccSRobert Hancock 	.detach = phy_sfp_detach,
732dc4d5fccSRobert Hancock 	.module_insert = at803x_sfp_insert,
733dc4d5fccSRobert Hancock };
734dc4d5fccSRobert Hancock 
at803x_parse_dt(struct phy_device * phydev)7352f664823SMichael Walle static int at803x_parse_dt(struct phy_device *phydev)
7362f664823SMichael Walle {
7372f664823SMichael Walle 	struct device_node *node = phydev->mdio.dev.of_node;
7382f664823SMichael Walle 	struct at803x_priv *priv = phydev->priv;
739390b4cadSRussell King 	u32 freq, strength, tw;
7403f2edd30SAndrew Lunn 	unsigned int sel;
7412f664823SMichael Walle 	int ret;
7422f664823SMichael Walle 
7432f664823SMichael Walle 	if (!IS_ENABLED(CONFIG_OF_MDIO))
7442f664823SMichael Walle 		return 0;
7452f664823SMichael Walle 
746390b4cadSRussell King 	if (of_property_read_bool(node, "qca,disable-smarteee"))
747390b4cadSRussell King 		priv->flags |= AT803X_DISABLE_SMARTEEE;
748390b4cadSRussell King 
7499ecf0401SWei Fang 	if (of_property_read_bool(node, "qca,disable-hibernation-mode"))
7509ecf0401SWei Fang 		priv->flags |= AT803X_DISABLE_HIBERNATION_MODE;
7519ecf0401SWei Fang 
752390b4cadSRussell King 	if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) {
753390b4cadSRussell King 		if (!tw || tw > 255) {
754390b4cadSRussell King 			phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n");
755390b4cadSRussell King 			return -EINVAL;
756390b4cadSRussell King 		}
757390b4cadSRussell King 		priv->smarteee_lpi_tw_1g = tw;
758390b4cadSRussell King 	}
759390b4cadSRussell King 
760390b4cadSRussell King 	if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) {
761390b4cadSRussell King 		if (!tw || tw > 255) {
762390b4cadSRussell King 			phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n");
763390b4cadSRussell King 			return -EINVAL;
764390b4cadSRussell King 		}
765390b4cadSRussell King 		priv->smarteee_lpi_tw_100m = tw;
766390b4cadSRussell King 	}
767390b4cadSRussell King 
7682f664823SMichael Walle 	ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq);
7692f664823SMichael Walle 	if (!ret) {
7702f664823SMichael Walle 		switch (freq) {
7712f664823SMichael Walle 		case 25000000:
7722f664823SMichael Walle 			sel = AT803X_CLK_OUT_25MHZ_XTAL;
7732f664823SMichael Walle 			break;
7742f664823SMichael Walle 		case 50000000:
7752f664823SMichael Walle 			sel = AT803X_CLK_OUT_50MHZ_PLL;
7762f664823SMichael Walle 			break;
7772f664823SMichael Walle 		case 62500000:
7782f664823SMichael Walle 			sel = AT803X_CLK_OUT_62_5MHZ_PLL;
7792f664823SMichael Walle 			break;
7802f664823SMichael Walle 		case 125000000:
7812f664823SMichael Walle 			sel = AT803X_CLK_OUT_125MHZ_PLL;
7822f664823SMichael Walle 			break;
7832f664823SMichael Walle 		default:
7842f664823SMichael Walle 			phydev_err(phydev, "invalid qca,clk-out-frequency\n");
7852f664823SMichael Walle 			return -EINVAL;
7862f664823SMichael Walle 		}
7872f664823SMichael Walle 
7883f2edd30SAndrew Lunn 		priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel);
7893f2edd30SAndrew Lunn 		priv->clk_25m_mask |= AT803X_CLK_OUT_MASK;
7902f664823SMichael Walle 
7912f664823SMichael Walle 		/* Fixup for the AR8030/AR8035. This chip has another mask and
7922f664823SMichael Walle 		 * doesn't support the DSP reference. Eg. the lowest bit of the
7932f664823SMichael Walle 		 * mask. The upper two bits select the same frequencies. Mask
7942f664823SMichael Walle 		 * the lowest bit here.
7952f664823SMichael Walle 		 *
7962f664823SMichael Walle 		 * Warning:
7972f664823SMichael Walle 		 *   There was no datasheet for the AR8030 available so this is
7982f664823SMichael Walle 		 *   just a guess. But the AR8035 is listed as pin compatible
7992f664823SMichael Walle 		 *   to the AR8030 so there might be a good chance it works on
8002f664823SMichael Walle 		 *   the AR8030 too.
8012f664823SMichael Walle 		 */
8028887ca54SRussell King 		if (phydev->drv->phy_id == ATH8030_PHY_ID ||
8038887ca54SRussell King 		    phydev->drv->phy_id == ATH8035_PHY_ID) {
804b1f4c209SOleksij Rempel 			priv->clk_25m_reg &= AT8035_CLK_OUT_MASK;
805b1f4c209SOleksij Rempel 			priv->clk_25m_mask &= AT8035_CLK_OUT_MASK;
8062f664823SMichael Walle 		}
8072f664823SMichael Walle 	}
8082f664823SMichael Walle 
8092f664823SMichael Walle 	ret = of_property_read_u32(node, "qca,clk-out-strength", &strength);
8102f664823SMichael Walle 	if (!ret) {
8112f664823SMichael Walle 		priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK;
8122f664823SMichael Walle 		switch (strength) {
8132f664823SMichael Walle 		case AR803X_STRENGTH_FULL:
8142f664823SMichael Walle 			priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL;
8152f664823SMichael Walle 			break;
8162f664823SMichael Walle 		case AR803X_STRENGTH_HALF:
8172f664823SMichael Walle 			priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF;
8182f664823SMichael Walle 			break;
8192f664823SMichael Walle 		case AR803X_STRENGTH_QUARTER:
8202f664823SMichael Walle 			priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER;
8212f664823SMichael Walle 			break;
8222f664823SMichael Walle 		default:
8232f664823SMichael Walle 			phydev_err(phydev, "invalid qca,clk-out-strength\n");
8242f664823SMichael Walle 			return -EINVAL;
8252f664823SMichael Walle 		}
8262f664823SMichael Walle 	}
8272f664823SMichael Walle 
828428061f7SMichael Walle 	/* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping
829428061f7SMichael Walle 	 * options.
830428061f7SMichael Walle 	 */
8318887ca54SRussell King 	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
8322f664823SMichael Walle 		if (of_property_read_bool(node, "qca,keep-pll-enabled"))
8332f664823SMichael Walle 			priv->flags |= AT803X_KEEP_PLL_ENABLED;
8342f664823SMichael Walle 
8352f664823SMichael Walle 		ret = at8031_register_regulators(phydev);
8362f664823SMichael Walle 		if (ret < 0)
8372f664823SMichael Walle 			return ret;
8382f664823SMichael Walle 
839988e8d90SChristophe JAILLET 		ret = devm_regulator_get_enable_optional(&phydev->mdio.dev,
8402f664823SMichael Walle 							 "vddio");
841988e8d90SChristophe JAILLET 		if (ret) {
8422f664823SMichael Walle 			phydev_err(phydev, "failed to get VDDIO regulator\n");
843988e8d90SChristophe JAILLET 			return ret;
8442f664823SMichael Walle 		}
845dc4d5fccSRobert Hancock 
846dc4d5fccSRobert Hancock 		/* Only AR8031/8033 support 1000Base-X for SFP modules */
847dc4d5fccSRobert Hancock 		ret = phy_sfp_probe(phydev, &at803x_sfp_ops);
848dc4d5fccSRobert Hancock 		if (ret < 0)
849dc4d5fccSRobert Hancock 			return ret;
8502f664823SMichael Walle 	}
8512f664823SMichael Walle 
8522f664823SMichael Walle 	return 0;
8532f664823SMichael Walle }
8542f664823SMichael Walle 
at803x_probe(struct phy_device * phydev)8552f664823SMichael Walle static int at803x_probe(struct phy_device *phydev)
8562f664823SMichael Walle {
8572f664823SMichael Walle 	struct device *dev = &phydev->mdio.dev;
8582f664823SMichael Walle 	struct at803x_priv *priv;
859c329e5afSDavid Bauer 	int ret;
8602f664823SMichael Walle 
8612f664823SMichael Walle 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
8622f664823SMichael Walle 	if (!priv)
8632f664823SMichael Walle 		return -ENOMEM;
8642f664823SMichael Walle 
8652f664823SMichael Walle 	phydev->priv = priv;
8662f664823SMichael Walle 
867c329e5afSDavid Bauer 	ret = at803x_parse_dt(phydev);
868c329e5afSDavid Bauer 	if (ret)
869c329e5afSDavid Bauer 		return ret;
870c329e5afSDavid Bauer 
8713265f421SRobert Hancock 	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
8723265f421SRobert Hancock 		int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
8733265f421SRobert Hancock 		int mode_cfg;
8743265f421SRobert Hancock 
875988e8d90SChristophe JAILLET 		if (ccr < 0)
876988e8d90SChristophe JAILLET 			return ccr;
8773265f421SRobert Hancock 		mode_cfg = ccr & AT803X_MODE_CFG_MASK;
8783265f421SRobert Hancock 
8793265f421SRobert Hancock 		switch (mode_cfg) {
8803265f421SRobert Hancock 		case AT803X_MODE_CFG_BX1000_RGMII_50OHM:
8813265f421SRobert Hancock 		case AT803X_MODE_CFG_BX1000_RGMII_75OHM:
8823265f421SRobert Hancock 			priv->is_1000basex = true;
8833265f421SRobert Hancock 			fallthrough;
8843265f421SRobert Hancock 		case AT803X_MODE_CFG_FX100_RGMII_50OHM:
8853265f421SRobert Hancock 		case AT803X_MODE_CFG_FX100_RGMII_75OHM:
8863265f421SRobert Hancock 			priv->is_fiber = true;
8873265f421SRobert Hancock 			break;
8883265f421SRobert Hancock 		}
889d7cd5e06SViorel Suman 
890e58f3024SLi Yang 		/* Disable WoL in 1588 register which is enabled
891e58f3024SLi Yang 		 * by default
892e58f3024SLi Yang 		 */
893e58f3024SLi Yang 		ret = phy_modify_mmd(phydev, MDIO_MMD_PCS,
894e58f3024SLi Yang 				     AT803X_PHY_MMD3_WOL_CTRL,
895e58f3024SLi Yang 				     AT803X_WOL_EN, 0);
896e58f3024SLi Yang 		if (ret)
897988e8d90SChristophe JAILLET 			return ret;
898d7cd5e06SViorel Suman 	}
8993265f421SRobert Hancock 
9008f7e8762SMichael Walle 	return 0;
9012318ca8aSMichael Walle }
9022318ca8aSMichael Walle 
at803x_get_features(struct phy_device * phydev)903b856150cSDavid Bauer static int at803x_get_features(struct phy_device *phydev)
904b856150cSDavid Bauer {
9053265f421SRobert Hancock 	struct at803x_priv *priv = phydev->priv;
906b856150cSDavid Bauer 	int err;
907b856150cSDavid Bauer 
908b856150cSDavid Bauer 	err = genphy_read_abilities(phydev);
909b856150cSDavid Bauer 	if (err)
910b856150cSDavid Bauer 		return err;
911b856150cSDavid Bauer 
912f5621a01SVladimir Oltean 	if (phydev->drv->phy_id != ATH8031_PHY_ID)
913b856150cSDavid Bauer 		return 0;
914b856150cSDavid Bauer 
915b856150cSDavid Bauer 	/* AR8031/AR8033 have different status registers
916b856150cSDavid Bauer 	 * for copper and fiber operation. However, the
917b856150cSDavid Bauer 	 * extended status register is the same for both
918b856150cSDavid Bauer 	 * operation modes.
919b856150cSDavid Bauer 	 *
920b856150cSDavid Bauer 	 * As a result of that, ESTATUS_1000_XFULL is set
921b856150cSDavid Bauer 	 * to 1 even when operating in copper TP mode.
922b856150cSDavid Bauer 	 *
9233265f421SRobert Hancock 	 * Remove this mode from the supported link modes
9243265f421SRobert Hancock 	 * when not operating in 1000BaseX mode.
925b856150cSDavid Bauer 	 */
9263265f421SRobert Hancock 	if (!priv->is_1000basex)
927b856150cSDavid Bauer 		linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
928b856150cSDavid Bauer 				   phydev->supported);
9293265f421SRobert Hancock 
930b856150cSDavid Bauer 	return 0;
931b856150cSDavid Bauer }
932b856150cSDavid Bauer 
at803x_smarteee_config(struct phy_device * phydev)933390b4cadSRussell King static int at803x_smarteee_config(struct phy_device *phydev)
934390b4cadSRussell King {
935390b4cadSRussell King 	struct at803x_priv *priv = phydev->priv;
936390b4cadSRussell King 	u16 mask = 0, val = 0;
937390b4cadSRussell King 	int ret;
938390b4cadSRussell King 
939390b4cadSRussell King 	if (priv->flags & AT803X_DISABLE_SMARTEEE)
940390b4cadSRussell King 		return phy_modify_mmd(phydev, MDIO_MMD_PCS,
941390b4cadSRussell King 				      AT803X_MMD3_SMARTEEE_CTL3,
942390b4cadSRussell King 				      AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0);
943390b4cadSRussell King 
944390b4cadSRussell King 	if (priv->smarteee_lpi_tw_1g) {
945390b4cadSRussell King 		mask |= 0xff00;
946390b4cadSRussell King 		val |= priv->smarteee_lpi_tw_1g << 8;
947390b4cadSRussell King 	}
948390b4cadSRussell King 	if (priv->smarteee_lpi_tw_100m) {
949390b4cadSRussell King 		mask |= 0x00ff;
950390b4cadSRussell King 		val |= priv->smarteee_lpi_tw_100m;
951390b4cadSRussell King 	}
952390b4cadSRussell King 	if (!mask)
953390b4cadSRussell King 		return 0;
954390b4cadSRussell King 
955390b4cadSRussell King 	ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1,
956390b4cadSRussell King 			     mask, val);
957390b4cadSRussell King 	if (ret)
958390b4cadSRussell King 		return ret;
959390b4cadSRussell King 
960390b4cadSRussell King 	return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3,
961390b4cadSRussell King 			      AT803X_MMD3_SMARTEEE_CTL3_LPI_EN,
962390b4cadSRussell King 			      AT803X_MMD3_SMARTEEE_CTL3_LPI_EN);
963390b4cadSRussell King }
964390b4cadSRussell King 
at803x_clk_out_config(struct phy_device * phydev)9652f664823SMichael Walle static int at803x_clk_out_config(struct phy_device *phydev)
9662f664823SMichael Walle {
9672f664823SMichael Walle 	struct at803x_priv *priv = phydev->priv;
9682f664823SMichael Walle 
9692f664823SMichael Walle 	if (!priv->clk_25m_mask)
9702f664823SMichael Walle 		return 0;
9712f664823SMichael Walle 
972a45c1c10SRussell King 	return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M,
973a45c1c10SRussell King 			      priv->clk_25m_mask, priv->clk_25m_reg);
9742f664823SMichael Walle }
9752f664823SMichael Walle 
at8031_pll_config(struct phy_device * phydev)9762f664823SMichael Walle static int at8031_pll_config(struct phy_device *phydev)
9772f664823SMichael Walle {
9782f664823SMichael Walle 	struct at803x_priv *priv = phydev->priv;
9792f664823SMichael Walle 
9802f664823SMichael Walle 	/* The default after hardware reset is PLL OFF. After a soft reset, the
9812f664823SMichael Walle 	 * values are retained.
9822f664823SMichael Walle 	 */
9832f664823SMichael Walle 	if (priv->flags & AT803X_KEEP_PLL_ENABLED)
9842f664823SMichael Walle 		return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
9852f664823SMichael Walle 					     0, AT803X_DEBUG_PLL_ON);
9862f664823SMichael Walle 	else
9872f664823SMichael Walle 		return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
9882f664823SMichael Walle 					     AT803X_DEBUG_PLL_ON, 0);
9892f664823SMichael Walle }
9902f664823SMichael Walle 
at803x_hibernation_mode_config(struct phy_device * phydev)9919ecf0401SWei Fang static int at803x_hibernation_mode_config(struct phy_device *phydev)
9929ecf0401SWei Fang {
9939ecf0401SWei Fang 	struct at803x_priv *priv = phydev->priv;
9949ecf0401SWei Fang 
9959ecf0401SWei Fang 	/* The default after hardware reset is hibernation mode enabled. After
9969ecf0401SWei Fang 	 * software reset, the value is retained.
9979ecf0401SWei Fang 	 */
9989ecf0401SWei Fang 	if (!(priv->flags & AT803X_DISABLE_HIBERNATION_MODE))
9999ecf0401SWei Fang 		return 0;
10009ecf0401SWei Fang 
10019ecf0401SWei Fang 	return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
10029ecf0401SWei Fang 					 AT803X_DEBUG_HIB_CTRL_PS_HIB_EN, 0);
10039ecf0401SWei Fang }
10049ecf0401SWei Fang 
at803x_config_init(struct phy_device * phydev)10050ca7111aSMatus Ujhelyi static int at803x_config_init(struct phy_device *phydev)
10060ca7111aSMatus Ujhelyi {
10073265f421SRobert Hancock 	struct at803x_priv *priv = phydev->priv;
10081ca6d1b1SMugunthan V N 	int ret;
10090ca7111aSMatus Ujhelyi 
10104f3a00c7SRobert Hancock 	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
10114f3a00c7SRobert Hancock 		/* Some bootloaders leave the fiber page selected.
10123265f421SRobert Hancock 		 * Switch to the appropriate page (fiber or copper), as otherwise we
10133265f421SRobert Hancock 		 * read the PHY capabilities from the wrong page.
10144f3a00c7SRobert Hancock 		 */
10154f3a00c7SRobert Hancock 		phy_lock_mdio_bus(phydev);
10163265f421SRobert Hancock 		ret = at803x_write_page(phydev,
10173265f421SRobert Hancock 					priv->is_fiber ? AT803X_PAGE_FIBER :
10183265f421SRobert Hancock 							 AT803X_PAGE_COPPER);
10194f3a00c7SRobert Hancock 		phy_unlock_mdio_bus(phydev);
10204f3a00c7SRobert Hancock 		if (ret)
10214f3a00c7SRobert Hancock 			return ret;
10224f3a00c7SRobert Hancock 
10234f3a00c7SRobert Hancock 		ret = at8031_pll_config(phydev);
10244f3a00c7SRobert Hancock 		if (ret < 0)
10254f3a00c7SRobert Hancock 			return ret;
10264f3a00c7SRobert Hancock 	}
10274f3a00c7SRobert Hancock 
10286d4cd041SVinod Koul 	/* The RX and TX delay default is:
10296d4cd041SVinod Koul 	 *   after HW reset: RX delay enabled and TX delay disabled
10306d4cd041SVinod Koul 	 *   after SW reset: RX delay enabled, while TX delay retains the
10316d4cd041SVinod Koul 	 *   value before reset.
10326d4cd041SVinod Koul 	 */
1033bb0ce4c1SAndré Draszik 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
1034bb0ce4c1SAndré Draszik 	    phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
1035bb0ce4c1SAndré Draszik 		ret = at803x_enable_rx_delay(phydev);
1036bb0ce4c1SAndré Draszik 	else
1037cd28d1d6SVinod Koul 		ret = at803x_disable_rx_delay(phydev);
10382e5f9f28SMartin Blumenstingl 	if (ret < 0)
10391ca6d1b1SMugunthan V N 		return ret;
10406d4cd041SVinod Koul 
10416d4cd041SVinod Koul 	if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
1042bb0ce4c1SAndré Draszik 	    phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
10436d4cd041SVinod Koul 		ret = at803x_enable_tx_delay(phydev);
1044bb0ce4c1SAndré Draszik 	else
1045bb0ce4c1SAndré Draszik 		ret = at803x_disable_tx_delay(phydev);
10462f664823SMichael Walle 	if (ret < 0)
10476d4cd041SVinod Koul 		return ret;
10482f664823SMichael Walle 
1049390b4cadSRussell King 	ret = at803x_smarteee_config(phydev);
1050390b4cadSRussell King 	if (ret < 0)
1051390b4cadSRussell King 		return ret;
1052390b4cadSRussell King 
10532f664823SMichael Walle 	ret = at803x_clk_out_config(phydev);
10542f664823SMichael Walle 	if (ret < 0)
10552f664823SMichael Walle 		return ret;
10562f664823SMichael Walle 
10579ecf0401SWei Fang 	ret = at803x_hibernation_mode_config(phydev);
10589ecf0401SWei Fang 	if (ret < 0)
10599ecf0401SWei Fang 		return ret;
10609ecf0401SWei Fang 
10613c51fa5dSRussell King 	/* Ar803x extended next page bit is enabled by default. Cisco
10623c51fa5dSRussell King 	 * multigig switches read this bit and attempt to negotiate 10Gbps
10633c51fa5dSRussell King 	 * rates even if the next page bit is disabled. This is incorrect
10643c51fa5dSRussell King 	 * behaviour but we still need to accommodate it. XNP is only needed
10653c51fa5dSRussell King 	 * for 10Gbps support, so disable XNP.
10663c51fa5dSRussell King 	 */
10673c51fa5dSRussell King 	return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0);
10680ca7111aSMatus Ujhelyi }
10690ca7111aSMatus Ujhelyi 
at803x_ack_interrupt(struct phy_device * phydev)107077a99394SZhao Qiang static int at803x_ack_interrupt(struct phy_device *phydev)
107177a99394SZhao Qiang {
107277a99394SZhao Qiang 	int err;
107377a99394SZhao Qiang 
1074a46bd63bSMartin Blumenstingl 	err = phy_read(phydev, AT803X_INTR_STATUS);
107577a99394SZhao Qiang 
107677a99394SZhao Qiang 	return (err < 0) ? err : 0;
107777a99394SZhao Qiang }
107877a99394SZhao Qiang 
at803x_config_intr(struct phy_device * phydev)107977a99394SZhao Qiang static int at803x_config_intr(struct phy_device *phydev)
108077a99394SZhao Qiang {
10813265f421SRobert Hancock 	struct at803x_priv *priv = phydev->priv;
108277a99394SZhao Qiang 	int err;
108377a99394SZhao Qiang 	int value;
108477a99394SZhao Qiang 
1085a46bd63bSMartin Blumenstingl 	value = phy_read(phydev, AT803X_INTR_ENABLE);
108677a99394SZhao Qiang 
1087e6e4a556SMartin Blumenstingl 	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
1088a3417885SIoana Ciornei 		/* Clear any pending interrupts */
1089a3417885SIoana Ciornei 		err = at803x_ack_interrupt(phydev);
1090a3417885SIoana Ciornei 		if (err)
1091a3417885SIoana Ciornei 			return err;
1092a3417885SIoana Ciornei 
1093e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_AUTONEG_ERR;
1094e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_SPEED_CHANGED;
1095e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED;
1096e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_LINK_FAIL;
1097e6e4a556SMartin Blumenstingl 		value |= AT803X_INTR_ENABLE_LINK_SUCCESS;
10983265f421SRobert Hancock 		if (priv->is_fiber) {
10993265f421SRobert Hancock 			value |= AT803X_INTR_ENABLE_LINK_FAIL_BX;
11003265f421SRobert Hancock 			value |= AT803X_INTR_ENABLE_LINK_SUCCESS_BX;
11013265f421SRobert Hancock 		}
1102e6e4a556SMartin Blumenstingl 
1103e6e4a556SMartin Blumenstingl 		err = phy_write(phydev, AT803X_INTR_ENABLE, value);
1104a3417885SIoana Ciornei 	} else {
1105a46bd63bSMartin Blumenstingl 		err = phy_write(phydev, AT803X_INTR_ENABLE, 0);
1106a3417885SIoana Ciornei 		if (err)
1107a3417885SIoana Ciornei 			return err;
1108a3417885SIoana Ciornei 
1109a3417885SIoana Ciornei 		/* Clear any pending interrupts */
1110a3417885SIoana Ciornei 		err = at803x_ack_interrupt(phydev);
1111a3417885SIoana Ciornei 	}
111277a99394SZhao Qiang 
111377a99394SZhao Qiang 	return err;
111477a99394SZhao Qiang }
111577a99394SZhao Qiang 
at803x_handle_interrupt(struct phy_device * phydev)111629773097SIoana Ciornei static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev)
111729773097SIoana Ciornei {
111829773097SIoana Ciornei 	int irq_status, int_enabled;
111929773097SIoana Ciornei 
112029773097SIoana Ciornei 	irq_status = phy_read(phydev, AT803X_INTR_STATUS);
112129773097SIoana Ciornei 	if (irq_status < 0) {
112229773097SIoana Ciornei 		phy_error(phydev);
112329773097SIoana Ciornei 		return IRQ_NONE;
112429773097SIoana Ciornei 	}
112529773097SIoana Ciornei 
112629773097SIoana Ciornei 	/* Read the current enabled interrupts */
112729773097SIoana Ciornei 	int_enabled = phy_read(phydev, AT803X_INTR_ENABLE);
112829773097SIoana Ciornei 	if (int_enabled < 0) {
112929773097SIoana Ciornei 		phy_error(phydev);
113029773097SIoana Ciornei 		return IRQ_NONE;
113129773097SIoana Ciornei 	}
113229773097SIoana Ciornei 
113329773097SIoana Ciornei 	/* See if this was one of our enabled interrupts */
113429773097SIoana Ciornei 	if (!(irq_status & int_enabled))
113529773097SIoana Ciornei 		return IRQ_NONE;
113629773097SIoana Ciornei 
113729773097SIoana Ciornei 	phy_trigger_machine(phydev);
113829773097SIoana Ciornei 
113929773097SIoana Ciornei 	return IRQ_HANDLED;
114029773097SIoana Ciornei }
114129773097SIoana Ciornei 
at803x_link_change_notify(struct phy_device * phydev)114213a56b44SDaniel Mack static void at803x_link_change_notify(struct phy_device *phydev)
114313a56b44SDaniel Mack {
114413a56b44SDaniel Mack 	/*
114513a56b44SDaniel Mack 	 * Conduct a hardware reset for AT8030 every time a link loss is
114613a56b44SDaniel Mack 	 * signalled. This is necessary to circumvent a hardware bug that
114713a56b44SDaniel Mack 	 * occurs when the cable is unplugged while TX packets are pending
114813a56b44SDaniel Mack 	 * in the FIFO. In such cases, the FIFO enters an error mode it
114913a56b44SDaniel Mack 	 * cannot recover from by software.
115013a56b44SDaniel Mack 	 */
11516110ed2dSDavid Bauer 	if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) {
115213a56b44SDaniel Mack 		struct at803x_context context;
115313a56b44SDaniel Mack 
115413a56b44SDaniel Mack 		at803x_context_save(phydev, &context);
115513a56b44SDaniel Mack 
1156bafbdd52SSergei Shtylyov 		phy_device_reset(phydev, 1);
115713a56b44SDaniel Mack 		msleep(1);
1158bafbdd52SSergei Shtylyov 		phy_device_reset(phydev, 0);
1159d57019d1SSergei Shtylyov 		msleep(1);
116013a56b44SDaniel Mack 
116113a56b44SDaniel Mack 		at803x_context_restore(phydev, &context);
116213a56b44SDaniel Mack 
11635c5f626bSHeiner Kallweit 		phydev_dbg(phydev, "%s(): phy was reset\n", __func__);
116413a56b44SDaniel Mack 	}
116513a56b44SDaniel Mack }
116613a56b44SDaniel Mack 
at803x_read_specific_status(struct phy_device * phydev)116779c7bc05SLuo Jie static int at803x_read_specific_status(struct phy_device *phydev)
116806d5f344SRussell King {
116979c7bc05SLuo Jie 	int ss;
117006d5f344SRussell King 
117106d5f344SRussell King 	/* Read the AT8035 PHY-Specific Status register, which indicates the
117206d5f344SRussell King 	 * speed and duplex that the PHY is actually using, irrespective of
117306d5f344SRussell King 	 * whether we are in autoneg mode or not.
117406d5f344SRussell King 	 */
117506d5f344SRussell King 	ss = phy_read(phydev, AT803X_SPECIFIC_STATUS);
117606d5f344SRussell King 	if (ss < 0)
117706d5f344SRussell King 		return ss;
117806d5f344SRussell King 
117906d5f344SRussell King 	if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) {
118079c7bc05SLuo Jie 		int sfc, speed;
11817dce80c2SOleksij Rempel 
11827dce80c2SOleksij Rempel 		sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL);
11837dce80c2SOleksij Rempel 		if (sfc < 0)
11847dce80c2SOleksij Rempel 			return sfc;
11857dce80c2SOleksij Rempel 
118679c7bc05SLuo Jie 		/* qca8081 takes the different bits for speed value from at803x */
118779c7bc05SLuo Jie 		if (phydev->drv->phy_id == QCA8081_PHY_ID)
118879c7bc05SLuo Jie 			speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss);
118979c7bc05SLuo Jie 		else
119079c7bc05SLuo Jie 			speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss);
119179c7bc05SLuo Jie 
119279c7bc05SLuo Jie 		switch (speed) {
119306d5f344SRussell King 		case AT803X_SS_SPEED_10:
119406d5f344SRussell King 			phydev->speed = SPEED_10;
119506d5f344SRussell King 			break;
119606d5f344SRussell King 		case AT803X_SS_SPEED_100:
119706d5f344SRussell King 			phydev->speed = SPEED_100;
119806d5f344SRussell King 			break;
119906d5f344SRussell King 		case AT803X_SS_SPEED_1000:
120006d5f344SRussell King 			phydev->speed = SPEED_1000;
120106d5f344SRussell King 			break;
120279c7bc05SLuo Jie 		case QCA808X_SS_SPEED_2500:
120379c7bc05SLuo Jie 			phydev->speed = SPEED_2500;
120479c7bc05SLuo Jie 			break;
120506d5f344SRussell King 		}
120606d5f344SRussell King 		if (ss & AT803X_SS_DUPLEX)
120706d5f344SRussell King 			phydev->duplex = DUPLEX_FULL;
120806d5f344SRussell King 		else
120906d5f344SRussell King 			phydev->duplex = DUPLEX_HALF;
12107dce80c2SOleksij Rempel 
121106d5f344SRussell King 		if (ss & AT803X_SS_MDIX)
121206d5f344SRussell King 			phydev->mdix = ETH_TP_MDI_X;
121306d5f344SRussell King 		else
121406d5f344SRussell King 			phydev->mdix = ETH_TP_MDI;
12157dce80c2SOleksij Rempel 
12167dce80c2SOleksij Rempel 		switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) {
12177dce80c2SOleksij Rempel 		case AT803X_SFC_MANUAL_MDI:
12187dce80c2SOleksij Rempel 			phydev->mdix_ctrl = ETH_TP_MDI;
12197dce80c2SOleksij Rempel 			break;
12207dce80c2SOleksij Rempel 		case AT803X_SFC_MANUAL_MDIX:
12217dce80c2SOleksij Rempel 			phydev->mdix_ctrl = ETH_TP_MDI_X;
12227dce80c2SOleksij Rempel 			break;
12237dce80c2SOleksij Rempel 		case AT803X_SFC_AUTOMATIC_CROSSOVER:
12247dce80c2SOleksij Rempel 			phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
12257dce80c2SOleksij Rempel 			break;
12267dce80c2SOleksij Rempel 		}
122706d5f344SRussell King 	}
122806d5f344SRussell King 
122979c7bc05SLuo Jie 	return 0;
123079c7bc05SLuo Jie }
123179c7bc05SLuo Jie 
at803x_read_status(struct phy_device * phydev)123279c7bc05SLuo Jie static int at803x_read_status(struct phy_device *phydev)
123379c7bc05SLuo Jie {
12343265f421SRobert Hancock 	struct at803x_priv *priv = phydev->priv;
123579c7bc05SLuo Jie 	int err, old_link = phydev->link;
123679c7bc05SLuo Jie 
12373265f421SRobert Hancock 	if (priv->is_1000basex)
12383265f421SRobert Hancock 		return genphy_c37_read_status(phydev);
12393265f421SRobert Hancock 
124079c7bc05SLuo Jie 	/* Update the link, but return if there was an error */
124179c7bc05SLuo Jie 	err = genphy_update_link(phydev);
124279c7bc05SLuo Jie 	if (err)
124379c7bc05SLuo Jie 		return err;
124479c7bc05SLuo Jie 
124579c7bc05SLuo Jie 	/* why bother the PHY if nothing can have changed */
124679c7bc05SLuo Jie 	if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
124779c7bc05SLuo Jie 		return 0;
124879c7bc05SLuo Jie 
124979c7bc05SLuo Jie 	phydev->speed = SPEED_UNKNOWN;
125079c7bc05SLuo Jie 	phydev->duplex = DUPLEX_UNKNOWN;
125179c7bc05SLuo Jie 	phydev->pause = 0;
125279c7bc05SLuo Jie 	phydev->asym_pause = 0;
125379c7bc05SLuo Jie 
125479c7bc05SLuo Jie 	err = genphy_read_lpa(phydev);
125579c7bc05SLuo Jie 	if (err < 0)
125679c7bc05SLuo Jie 		return err;
125779c7bc05SLuo Jie 
125879c7bc05SLuo Jie 	err = at803x_read_specific_status(phydev);
125979c7bc05SLuo Jie 	if (err < 0)
126079c7bc05SLuo Jie 		return err;
126179c7bc05SLuo Jie 
126206d5f344SRussell King 	if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
126306d5f344SRussell King 		phy_resolve_aneg_pause(phydev);
126406d5f344SRussell King 
126506d5f344SRussell King 	return 0;
126606d5f344SRussell King }
126706d5f344SRussell King 
at803x_config_mdix(struct phy_device * phydev,u8 ctrl)12687dce80c2SOleksij Rempel static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl)
12697dce80c2SOleksij Rempel {
12707dce80c2SOleksij Rempel 	u16 val;
12717dce80c2SOleksij Rempel 
12727dce80c2SOleksij Rempel 	switch (ctrl) {
12737dce80c2SOleksij Rempel 	case ETH_TP_MDI:
12747dce80c2SOleksij Rempel 		val = AT803X_SFC_MANUAL_MDI;
12757dce80c2SOleksij Rempel 		break;
12767dce80c2SOleksij Rempel 	case ETH_TP_MDI_X:
12777dce80c2SOleksij Rempel 		val = AT803X_SFC_MANUAL_MDIX;
12787dce80c2SOleksij Rempel 		break;
12797dce80c2SOleksij Rempel 	case ETH_TP_MDI_AUTO:
12807dce80c2SOleksij Rempel 		val = AT803X_SFC_AUTOMATIC_CROSSOVER;
12817dce80c2SOleksij Rempel 		break;
12827dce80c2SOleksij Rempel 	default:
12837dce80c2SOleksij Rempel 		return 0;
12847dce80c2SOleksij Rempel 	}
12857dce80c2SOleksij Rempel 
12867dce80c2SOleksij Rempel 	return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL,
12877dce80c2SOleksij Rempel 			  AT803X_SFC_MDI_CROSSOVER_MODE_M,
12887dce80c2SOleksij Rempel 			  FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val));
12897dce80c2SOleksij Rempel }
12907dce80c2SOleksij Rempel 
at803x_config_aneg(struct phy_device * phydev)12917dce80c2SOleksij Rempel static int at803x_config_aneg(struct phy_device *phydev)
12927dce80c2SOleksij Rempel {
12933265f421SRobert Hancock 	struct at803x_priv *priv = phydev->priv;
12947dce80c2SOleksij Rempel 	int ret;
12957dce80c2SOleksij Rempel 
12967dce80c2SOleksij Rempel 	ret = at803x_config_mdix(phydev, phydev->mdix_ctrl);
12977dce80c2SOleksij Rempel 	if (ret < 0)
12987dce80c2SOleksij Rempel 		return ret;
12997dce80c2SOleksij Rempel 
13007dce80c2SOleksij Rempel 	/* Changes of the midx bits are disruptive to the normal operation;
13017dce80c2SOleksij Rempel 	 * therefore any changes to these registers must be followed by a
13027dce80c2SOleksij Rempel 	 * software reset to take effect.
13037dce80c2SOleksij Rempel 	 */
13047dce80c2SOleksij Rempel 	if (ret == 1) {
13057dce80c2SOleksij Rempel 		ret = genphy_soft_reset(phydev);
13067dce80c2SOleksij Rempel 		if (ret < 0)
13077dce80c2SOleksij Rempel 			return ret;
13087dce80c2SOleksij Rempel 	}
13097dce80c2SOleksij Rempel 
13103265f421SRobert Hancock 	if (priv->is_1000basex)
13113265f421SRobert Hancock 		return genphy_c37_config_aneg(phydev);
13123265f421SRobert Hancock 
1313f884d449SLuo Jie 	/* Do not restart auto-negotiation by setting ret to 0 defautly,
1314f884d449SLuo Jie 	 * when calling __genphy_config_aneg later.
1315f884d449SLuo Jie 	 */
1316f884d449SLuo Jie 	ret = 0;
1317f884d449SLuo Jie 
1318f884d449SLuo Jie 	if (phydev->drv->phy_id == QCA8081_PHY_ID) {
1319f884d449SLuo Jie 		int phy_ctrl = 0;
1320f884d449SLuo Jie 
1321f884d449SLuo Jie 		/* The reg MII_BMCR also needs to be configured for force mode, the
1322f884d449SLuo Jie 		 * genphy_config_aneg is also needed.
1323f884d449SLuo Jie 		 */
1324f884d449SLuo Jie 		if (phydev->autoneg == AUTONEG_DISABLE)
1325f884d449SLuo Jie 			genphy_c45_pma_setup_forced(phydev);
1326f884d449SLuo Jie 
1327f884d449SLuo Jie 		if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising))
1328f884d449SLuo Jie 			phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G;
1329f884d449SLuo Jie 
1330f884d449SLuo Jie 		ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
1331f884d449SLuo Jie 				MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl);
1332f884d449SLuo Jie 		if (ret < 0)
1333f884d449SLuo Jie 			return ret;
1334f884d449SLuo Jie 	}
1335f884d449SLuo Jie 
1336f884d449SLuo Jie 	return __genphy_config_aneg(phydev, ret);
13377dce80c2SOleksij Rempel }
13387dce80c2SOleksij Rempel 
at803x_get_downshift(struct phy_device * phydev,u8 * d)1339cde0f4f8SMichael Walle static int at803x_get_downshift(struct phy_device *phydev, u8 *d)
1340cde0f4f8SMichael Walle {
1341cde0f4f8SMichael Walle 	int val;
1342cde0f4f8SMichael Walle 
1343cde0f4f8SMichael Walle 	val = phy_read(phydev, AT803X_SMART_SPEED);
1344cde0f4f8SMichael Walle 	if (val < 0)
1345cde0f4f8SMichael Walle 		return val;
1346cde0f4f8SMichael Walle 
1347cde0f4f8SMichael Walle 	if (val & AT803X_SMART_SPEED_ENABLE)
1348cde0f4f8SMichael Walle 		*d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2;
1349cde0f4f8SMichael Walle 	else
1350cde0f4f8SMichael Walle 		*d = DOWNSHIFT_DEV_DISABLE;
1351cde0f4f8SMichael Walle 
1352cde0f4f8SMichael Walle 	return 0;
1353cde0f4f8SMichael Walle }
1354cde0f4f8SMichael Walle 
at803x_set_downshift(struct phy_device * phydev,u8 cnt)1355cde0f4f8SMichael Walle static int at803x_set_downshift(struct phy_device *phydev, u8 cnt)
1356cde0f4f8SMichael Walle {
1357cde0f4f8SMichael Walle 	u16 mask, set;
1358cde0f4f8SMichael Walle 	int ret;
1359cde0f4f8SMichael Walle 
1360cde0f4f8SMichael Walle 	switch (cnt) {
1361cde0f4f8SMichael Walle 	case DOWNSHIFT_DEV_DEFAULT_COUNT:
1362cde0f4f8SMichael Walle 		cnt = AT803X_DEFAULT_DOWNSHIFT;
1363cde0f4f8SMichael Walle 		fallthrough;
1364cde0f4f8SMichael Walle 	case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT:
1365cde0f4f8SMichael Walle 		set = AT803X_SMART_SPEED_ENABLE |
1366cde0f4f8SMichael Walle 		      AT803X_SMART_SPEED_BYPASS_TIMER |
1367cde0f4f8SMichael Walle 		      FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2);
1368cde0f4f8SMichael Walle 		mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK;
1369cde0f4f8SMichael Walle 		break;
1370cde0f4f8SMichael Walle 	case DOWNSHIFT_DEV_DISABLE:
1371cde0f4f8SMichael Walle 		set = 0;
1372cde0f4f8SMichael Walle 		mask = AT803X_SMART_SPEED_ENABLE |
1373cde0f4f8SMichael Walle 		       AT803X_SMART_SPEED_BYPASS_TIMER;
1374cde0f4f8SMichael Walle 		break;
1375cde0f4f8SMichael Walle 	default:
1376cde0f4f8SMichael Walle 		return -EINVAL;
1377cde0f4f8SMichael Walle 	}
1378cde0f4f8SMichael Walle 
1379cde0f4f8SMichael Walle 	ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set);
1380cde0f4f8SMichael Walle 
1381cde0f4f8SMichael Walle 	/* After changing the smart speed settings, we need to perform a
1382cde0f4f8SMichael Walle 	 * software reset, use phy_init_hw() to make sure we set the
1383cde0f4f8SMichael Walle 	 * reapply any values which might got lost during software reset.
1384cde0f4f8SMichael Walle 	 */
1385cde0f4f8SMichael Walle 	if (ret == 1)
1386cde0f4f8SMichael Walle 		ret = phy_init_hw(phydev);
1387cde0f4f8SMichael Walle 
1388cde0f4f8SMichael Walle 	return ret;
1389cde0f4f8SMichael Walle }
1390cde0f4f8SMichael Walle 
at803x_get_tunable(struct phy_device * phydev,struct ethtool_tunable * tuna,void * data)1391cde0f4f8SMichael Walle static int at803x_get_tunable(struct phy_device *phydev,
1392cde0f4f8SMichael Walle 			      struct ethtool_tunable *tuna, void *data)
1393cde0f4f8SMichael Walle {
1394cde0f4f8SMichael Walle 	switch (tuna->id) {
1395cde0f4f8SMichael Walle 	case ETHTOOL_PHY_DOWNSHIFT:
1396cde0f4f8SMichael Walle 		return at803x_get_downshift(phydev, data);
1397cde0f4f8SMichael Walle 	default:
1398cde0f4f8SMichael Walle 		return -EOPNOTSUPP;
1399cde0f4f8SMichael Walle 	}
1400cde0f4f8SMichael Walle }
1401cde0f4f8SMichael Walle 
at803x_set_tunable(struct phy_device * phydev,struct ethtool_tunable * tuna,const void * data)1402cde0f4f8SMichael Walle static int at803x_set_tunable(struct phy_device *phydev,
1403cde0f4f8SMichael Walle 			      struct ethtool_tunable *tuna, const void *data)
1404cde0f4f8SMichael Walle {
1405cde0f4f8SMichael Walle 	switch (tuna->id) {
1406cde0f4f8SMichael Walle 	case ETHTOOL_PHY_DOWNSHIFT:
1407cde0f4f8SMichael Walle 		return at803x_set_downshift(phydev, *(const u8 *)data);
1408cde0f4f8SMichael Walle 	default:
1409cde0f4f8SMichael Walle 		return -EOPNOTSUPP;
1410cde0f4f8SMichael Walle 	}
1411cde0f4f8SMichael Walle }
1412cde0f4f8SMichael Walle 
at803x_cable_test_result_trans(u16 status)14136cb75767SMichael Walle static int at803x_cable_test_result_trans(u16 status)
14146cb75767SMichael Walle {
14156cb75767SMichael Walle 	switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
14166cb75767SMichael Walle 	case AT803X_CDT_STATUS_STAT_NORMAL:
14176cb75767SMichael Walle 		return ETHTOOL_A_CABLE_RESULT_CODE_OK;
14186cb75767SMichael Walle 	case AT803X_CDT_STATUS_STAT_SHORT:
14196cb75767SMichael Walle 		return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
14206cb75767SMichael Walle 	case AT803X_CDT_STATUS_STAT_OPEN:
14216cb75767SMichael Walle 		return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
14226cb75767SMichael Walle 	case AT803X_CDT_STATUS_STAT_FAIL:
14236cb75767SMichael Walle 	default:
14246cb75767SMichael Walle 		return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
14256cb75767SMichael Walle 	}
14266cb75767SMichael Walle }
14276cb75767SMichael Walle 
at803x_cdt_test_failed(u16 status)14286cb75767SMichael Walle static bool at803x_cdt_test_failed(u16 status)
14296cb75767SMichael Walle {
14306cb75767SMichael Walle 	return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) ==
14316cb75767SMichael Walle 		AT803X_CDT_STATUS_STAT_FAIL;
14326cb75767SMichael Walle }
14336cb75767SMichael Walle 
at803x_cdt_fault_length_valid(u16 status)14346cb75767SMichael Walle static bool at803x_cdt_fault_length_valid(u16 status)
14356cb75767SMichael Walle {
14366cb75767SMichael Walle 	switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
14376cb75767SMichael Walle 	case AT803X_CDT_STATUS_STAT_OPEN:
14386cb75767SMichael Walle 	case AT803X_CDT_STATUS_STAT_SHORT:
14396cb75767SMichael Walle 		return true;
14406cb75767SMichael Walle 	}
14416cb75767SMichael Walle 	return false;
14426cb75767SMichael Walle }
14436cb75767SMichael Walle 
at803x_cdt_fault_length(u16 status)14446cb75767SMichael Walle static int at803x_cdt_fault_length(u16 status)
14456cb75767SMichael Walle {
14466cb75767SMichael Walle 	int dt;
14476cb75767SMichael Walle 
14486cb75767SMichael Walle 	/* According to the datasheet the distance to the fault is
14496cb75767SMichael Walle 	 * DELTA_TIME * 0.824 meters.
14506cb75767SMichael Walle 	 *
14516cb75767SMichael Walle 	 * The author suspect the correct formula is:
14526cb75767SMichael Walle 	 *
14536cb75767SMichael Walle 	 *   fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2
14546cb75767SMichael Walle 	 *
14556cb75767SMichael Walle 	 * where c is the speed of light, VF is the velocity factor of
14566cb75767SMichael Walle 	 * the twisted pair cable, 125MHz the counter frequency and
14576cb75767SMichael Walle 	 * we need to divide by 2 because the hardware will measure the
14586cb75767SMichael Walle 	 * round trip time to the fault and back to the PHY.
14596cb75767SMichael Walle 	 *
14606cb75767SMichael Walle 	 * With a VF of 0.69 we get the factor 0.824 mentioned in the
14616cb75767SMichael Walle 	 * datasheet.
14626cb75767SMichael Walle 	 */
14636cb75767SMichael Walle 	dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status);
14646cb75767SMichael Walle 
14656cb75767SMichael Walle 	return (dt * 824) / 10;
14666cb75767SMichael Walle }
14676cb75767SMichael Walle 
at803x_cdt_start(struct phy_device * phydev,int pair)14686cb75767SMichael Walle static int at803x_cdt_start(struct phy_device *phydev, int pair)
14696cb75767SMichael Walle {
14706cb75767SMichael Walle 	u16 cdt;
14716cb75767SMichael Walle 
14728c84d752SLuo Jie 	/* qca8081 takes the different bit 15 to enable CDT test */
14738c84d752SLuo Jie 	if (phydev->drv->phy_id == QCA8081_PHY_ID)
14748c84d752SLuo Jie 		cdt = QCA808X_CDT_ENABLE_TEST |
14758c84d752SLuo Jie 			QCA808X_CDT_LENGTH_UNIT |
14768c84d752SLuo Jie 			QCA808X_CDT_INTER_CHECK_DIS;
14778c84d752SLuo Jie 	else
14786cb75767SMichael Walle 		cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
14796cb75767SMichael Walle 			AT803X_CDT_ENABLE_TEST;
14806cb75767SMichael Walle 
14816cb75767SMichael Walle 	return phy_write(phydev, AT803X_CDT, cdt);
14826cb75767SMichael Walle }
14836cb75767SMichael Walle 
at803x_cdt_wait_for_completion(struct phy_device * phydev)14846cb75767SMichael Walle static int at803x_cdt_wait_for_completion(struct phy_device *phydev)
14856cb75767SMichael Walle {
14866cb75767SMichael Walle 	int val, ret;
14878c84d752SLuo Jie 	u16 cdt_en;
14888c84d752SLuo Jie 
14898c84d752SLuo Jie 	if (phydev->drv->phy_id == QCA8081_PHY_ID)
14908c84d752SLuo Jie 		cdt_en = QCA808X_CDT_ENABLE_TEST;
14918c84d752SLuo Jie 	else
14928c84d752SLuo Jie 		cdt_en = AT803X_CDT_ENABLE_TEST;
14936cb75767SMichael Walle 
14946cb75767SMichael Walle 	/* One test run takes about 25ms */
14956cb75767SMichael Walle 	ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
14968c84d752SLuo Jie 				    !(val & cdt_en),
14976cb75767SMichael Walle 				    30000, 100000, true);
14986cb75767SMichael Walle 
14996cb75767SMichael Walle 	return ret < 0 ? ret : 0;
15006cb75767SMichael Walle }
15016cb75767SMichael Walle 
at803x_cable_test_one_pair(struct phy_device * phydev,int pair)15026cb75767SMichael Walle static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair)
15036cb75767SMichael Walle {
15046cb75767SMichael Walle 	static const int ethtool_pair[] = {
15056cb75767SMichael Walle 		ETHTOOL_A_CABLE_PAIR_A,
15066cb75767SMichael Walle 		ETHTOOL_A_CABLE_PAIR_B,
15076cb75767SMichael Walle 		ETHTOOL_A_CABLE_PAIR_C,
15086cb75767SMichael Walle 		ETHTOOL_A_CABLE_PAIR_D,
15096cb75767SMichael Walle 	};
15106cb75767SMichael Walle 	int ret, val;
15116cb75767SMichael Walle 
15126cb75767SMichael Walle 	ret = at803x_cdt_start(phydev, pair);
15136cb75767SMichael Walle 	if (ret)
15146cb75767SMichael Walle 		return ret;
15156cb75767SMichael Walle 
15166cb75767SMichael Walle 	ret = at803x_cdt_wait_for_completion(phydev);
15176cb75767SMichael Walle 	if (ret)
15186cb75767SMichael Walle 		return ret;
15196cb75767SMichael Walle 
15206cb75767SMichael Walle 	val = phy_read(phydev, AT803X_CDT_STATUS);
15216cb75767SMichael Walle 	if (val < 0)
15226cb75767SMichael Walle 		return val;
15236cb75767SMichael Walle 
15246cb75767SMichael Walle 	if (at803x_cdt_test_failed(val))
15256cb75767SMichael Walle 		return 0;
15266cb75767SMichael Walle 
15276cb75767SMichael Walle 	ethnl_cable_test_result(phydev, ethtool_pair[pair],
15286cb75767SMichael Walle 				at803x_cable_test_result_trans(val));
15296cb75767SMichael Walle 
15306cb75767SMichael Walle 	if (at803x_cdt_fault_length_valid(val))
15316cb75767SMichael Walle 		ethnl_cable_test_fault_length(phydev, ethtool_pair[pair],
15326cb75767SMichael Walle 					      at803x_cdt_fault_length(val));
15336cb75767SMichael Walle 
15346cb75767SMichael Walle 	return 1;
15356cb75767SMichael Walle }
15366cb75767SMichael Walle 
at803x_cable_test_get_status(struct phy_device * phydev,bool * finished)15376cb75767SMichael Walle static int at803x_cable_test_get_status(struct phy_device *phydev,
15386cb75767SMichael Walle 					bool *finished)
15396cb75767SMichael Walle {
1540dc0f3ed1SOleksij Rempel 	unsigned long pair_mask;
15416cb75767SMichael Walle 	int retries = 20;
15426cb75767SMichael Walle 	int pair, ret;
15436cb75767SMichael Walle 
1544dc0f3ed1SOleksij Rempel 	if (phydev->phy_id == ATH9331_PHY_ID ||
1545fada2ce0SDavid Bauer 	    phydev->phy_id == ATH8032_PHY_ID ||
1546fada2ce0SDavid Bauer 	    phydev->phy_id == QCA9561_PHY_ID)
1547dc0f3ed1SOleksij Rempel 		pair_mask = 0x3;
1548dc0f3ed1SOleksij Rempel 	else
1549dc0f3ed1SOleksij Rempel 		pair_mask = 0xf;
1550dc0f3ed1SOleksij Rempel 
15516cb75767SMichael Walle 	*finished = false;
15526cb75767SMichael Walle 
15536cb75767SMichael Walle 	/* According to the datasheet the CDT can be performed when
15546cb75767SMichael Walle 	 * there is no link partner or when the link partner is
15556cb75767SMichael Walle 	 * auto-negotiating. Starting the test will restart the AN
15566cb75767SMichael Walle 	 * automatically. It seems that doing this repeatedly we will
15576cb75767SMichael Walle 	 * get a slot where our link partner won't disturb our
15586cb75767SMichael Walle 	 * measurement.
15596cb75767SMichael Walle 	 */
15606cb75767SMichael Walle 	while (pair_mask && retries--) {
15616cb75767SMichael Walle 		for_each_set_bit(pair, &pair_mask, 4) {
15626cb75767SMichael Walle 			ret = at803x_cable_test_one_pair(phydev, pair);
15636cb75767SMichael Walle 			if (ret < 0)
15646cb75767SMichael Walle 				return ret;
15656cb75767SMichael Walle 			if (ret)
15666cb75767SMichael Walle 				clear_bit(pair, &pair_mask);
15676cb75767SMichael Walle 		}
15686cb75767SMichael Walle 		if (pair_mask)
15696cb75767SMichael Walle 			msleep(250);
15706cb75767SMichael Walle 	}
15716cb75767SMichael Walle 
15726cb75767SMichael Walle 	*finished = true;
15736cb75767SMichael Walle 
15746cb75767SMichael Walle 	return 0;
15756cb75767SMichael Walle }
15766cb75767SMichael Walle 
at803x_cable_test_start(struct phy_device * phydev)15776cb75767SMichael Walle static int at803x_cable_test_start(struct phy_device *phydev)
15786cb75767SMichael Walle {
15796cb75767SMichael Walle 	/* Enable auto-negotiation, but advertise no capabilities, no link
15806cb75767SMichael Walle 	 * will be established. A restart of the auto-negotiation is not
15816cb75767SMichael Walle 	 * required, because the cable test will automatically break the link.
15826cb75767SMichael Walle 	 */
15836cb75767SMichael Walle 	phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
15846cb75767SMichael Walle 	phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
1585dc0f3ed1SOleksij Rempel 	if (phydev->phy_id != ATH9331_PHY_ID &&
1586fada2ce0SDavid Bauer 	    phydev->phy_id != ATH8032_PHY_ID &&
1587fada2ce0SDavid Bauer 	    phydev->phy_id != QCA9561_PHY_ID)
15886cb75767SMichael Walle 		phy_write(phydev, MII_CTRL1000, 0);
15896cb75767SMichael Walle 
15906cb75767SMichael Walle 	/* we do all the (time consuming) work later */
15916cb75767SMichael Walle 	return 0;
15926cb75767SMichael Walle }
15936cb75767SMichael Walle 
qca83xx_config_init(struct phy_device * phydev)1594272833b9SAnsuel Smith static int qca83xx_config_init(struct phy_device *phydev)
1595272833b9SAnsuel Smith {
1596272833b9SAnsuel Smith 	u8 switch_revision;
1597272833b9SAnsuel Smith 
1598272833b9SAnsuel Smith 	switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK;
1599272833b9SAnsuel Smith 
1600272833b9SAnsuel Smith 	switch (switch_revision) {
1601272833b9SAnsuel Smith 	case 1:
1602272833b9SAnsuel Smith 		/* For 100M waveform */
160367999555SAnsuel Smith 		at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea);
1604272833b9SAnsuel Smith 		/* Turn on Gigabit clock */
160567999555SAnsuel Smith 		at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0);
1606272833b9SAnsuel Smith 		break;
1607272833b9SAnsuel Smith 
1608272833b9SAnsuel Smith 	case 2:
1609272833b9SAnsuel Smith 		phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0);
1610272833b9SAnsuel Smith 		fallthrough;
1611272833b9SAnsuel Smith 	case 4:
1612272833b9SAnsuel Smith 		phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f);
161367999555SAnsuel Smith 		at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860);
161467999555SAnsuel Smith 		at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46);
1615272833b9SAnsuel Smith 		at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000);
1616272833b9SAnsuel Smith 		break;
1617272833b9SAnsuel Smith 	}
1618272833b9SAnsuel Smith 
16191ca83119SAnsuel Smith 	/* QCA8327 require DAC amplitude adjustment for 100m set to +6%.
16201ca83119SAnsuel Smith 	 * Disable on init and enable only with 100m speed following
16211ca83119SAnsuel Smith 	 * qca original source code.
16221ca83119SAnsuel Smith 	 */
16231ca83119SAnsuel Smith 	if (phydev->drv->phy_id == QCA8327_A_PHY_ID ||
16241ca83119SAnsuel Smith 	    phydev->drv->phy_id == QCA8327_B_PHY_ID)
162567999555SAnsuel Smith 		at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
16261ca83119SAnsuel Smith 				      QCA8327_DEBUG_MANU_CTRL_EN, 0);
16271ca83119SAnsuel Smith 
16289d1c29b4SAnsuel Smith 	/* Following original QCA sourcecode set port to prefer master */
16299d1c29b4SAnsuel Smith 	phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER);
16309d1c29b4SAnsuel Smith 
1631272833b9SAnsuel Smith 	return 0;
1632272833b9SAnsuel Smith }
1633272833b9SAnsuel Smith 
qca83xx_link_change_notify(struct phy_device * phydev)16341ca83119SAnsuel Smith static void qca83xx_link_change_notify(struct phy_device *phydev)
16351ca83119SAnsuel Smith {
16361ca83119SAnsuel Smith 	/* QCA8337 doesn't require DAC Amplitude adjustement */
16371ca83119SAnsuel Smith 	if (phydev->drv->phy_id == QCA8337_PHY_ID)
16381ca83119SAnsuel Smith 		return;
16391ca83119SAnsuel Smith 
16401ca83119SAnsuel Smith 	/* Set DAC Amplitude adjustment to +6% for 100m on link running */
16411ca83119SAnsuel Smith 	if (phydev->state == PHY_RUNNING) {
16421ca83119SAnsuel Smith 		if (phydev->speed == SPEED_100)
164367999555SAnsuel Smith 			at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
16441ca83119SAnsuel Smith 					      QCA8327_DEBUG_MANU_CTRL_EN,
16451ca83119SAnsuel Smith 					      QCA8327_DEBUG_MANU_CTRL_EN);
16461ca83119SAnsuel Smith 	} else {
16471ca83119SAnsuel Smith 		/* Reset DAC Amplitude adjustment */
164867999555SAnsuel Smith 		at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL,
16491ca83119SAnsuel Smith 				      QCA8327_DEBUG_MANU_CTRL_EN, 0);
16501ca83119SAnsuel Smith 	}
16511ca83119SAnsuel Smith }
16521ca83119SAnsuel Smith 
qca83xx_resume(struct phy_device * phydev)1653ba3c01eeSAnsuel Smith static int qca83xx_resume(struct phy_device *phydev)
1654ba3c01eeSAnsuel Smith {
1655ba3c01eeSAnsuel Smith 	int ret, val;
1656ba3c01eeSAnsuel Smith 
1657ba3c01eeSAnsuel Smith 	/* Skip reset if not suspended */
1658ba3c01eeSAnsuel Smith 	if (!phydev->suspended)
1659ba3c01eeSAnsuel Smith 		return 0;
1660ba3c01eeSAnsuel Smith 
1661ba3c01eeSAnsuel Smith 	/* Reinit the port, reset values set by suspend */
1662ba3c01eeSAnsuel Smith 	qca83xx_config_init(phydev);
1663ba3c01eeSAnsuel Smith 
1664ba3c01eeSAnsuel Smith 	/* Reset the port on port resume */
1665ba3c01eeSAnsuel Smith 	phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
1666ba3c01eeSAnsuel Smith 
1667ba3c01eeSAnsuel Smith 	/* On resume from suspend the switch execute a reset and
1668ba3c01eeSAnsuel Smith 	 * restart auto-negotiation. Wait for reset to complete.
1669ba3c01eeSAnsuel Smith 	 */
1670ba3c01eeSAnsuel Smith 	ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET),
1671ba3c01eeSAnsuel Smith 				    50000, 600000, true);
1672ba3c01eeSAnsuel Smith 	if (ret)
1673ba3c01eeSAnsuel Smith 		return ret;
1674ba3c01eeSAnsuel Smith 
1675ba3c01eeSAnsuel Smith 	msleep(1);
1676ba3c01eeSAnsuel Smith 
1677ba3c01eeSAnsuel Smith 	return 0;
1678ba3c01eeSAnsuel Smith }
1679ba3c01eeSAnsuel Smith 
qca83xx_suspend(struct phy_device * phydev)1680ba3c01eeSAnsuel Smith static int qca83xx_suspend(struct phy_device *phydev)
1681ba3c01eeSAnsuel Smith {
1682ba3c01eeSAnsuel Smith 	u16 mask = 0;
1683ba3c01eeSAnsuel Smith 
1684ba3c01eeSAnsuel Smith 	/* Only QCA8337 support actual suspend.
1685ba3c01eeSAnsuel Smith 	 * QCA8327 cause port unreliability when phy suspend
1686ba3c01eeSAnsuel Smith 	 * is set.
1687ba3c01eeSAnsuel Smith 	 */
1688ba3c01eeSAnsuel Smith 	if (phydev->drv->phy_id == QCA8337_PHY_ID) {
1689ba3c01eeSAnsuel Smith 		genphy_suspend(phydev);
1690ba3c01eeSAnsuel Smith 	} else {
1691ba3c01eeSAnsuel Smith 		mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX);
1692ba3c01eeSAnsuel Smith 		phy_modify(phydev, MII_BMCR, mask, 0);
1693ba3c01eeSAnsuel Smith 	}
1694ba3c01eeSAnsuel Smith 
169567999555SAnsuel Smith 	at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN,
1696ba3c01eeSAnsuel Smith 			      AT803X_DEBUG_GATE_CLK_IN1000, 0);
1697ba3c01eeSAnsuel Smith 
1698ba3c01eeSAnsuel Smith 	at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
1699ba3c01eeSAnsuel Smith 			      AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE |
1700ba3c01eeSAnsuel Smith 			      AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0);
1701ba3c01eeSAnsuel Smith 
1702ba3c01eeSAnsuel Smith 	return 0;
1703ba3c01eeSAnsuel Smith }
1704ba3c01eeSAnsuel Smith 
qca808x_phy_fast_retrain_config(struct phy_device * phydev)17052acdd43fSLuo Jie static int qca808x_phy_fast_retrain_config(struct phy_device *phydev)
17062acdd43fSLuo Jie {
17072acdd43fSLuo Jie 	int ret;
17082acdd43fSLuo Jie 
17092acdd43fSLuo Jie 	/* Enable fast retrain */
17102acdd43fSLuo Jie 	ret = genphy_c45_fast_retrain(phydev, true);
17112acdd43fSLuo Jie 	if (ret)
17122acdd43fSLuo Jie 		return ret;
17132acdd43fSLuo Jie 
17142acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_TOP_OPTION1,
17152acdd43fSLuo Jie 			QCA808X_TOP_OPTION1_DATA);
17162acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB,
17172acdd43fSLuo Jie 			QCA808X_MSE_THRESHOLD_20DB_VALUE);
17182acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB,
17192acdd43fSLuo Jie 			QCA808X_MSE_THRESHOLD_17DB_VALUE);
17202acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB,
17212acdd43fSLuo Jie 			QCA808X_MSE_THRESHOLD_27DB_VALUE);
17222acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB,
17232acdd43fSLuo Jie 			QCA808X_MSE_THRESHOLD_28DB_VALUE);
17242acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_1,
17252acdd43fSLuo Jie 			QCA808X_MMD3_DEBUG_1_VALUE);
17262acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_4,
17272acdd43fSLuo Jie 			QCA808X_MMD3_DEBUG_4_VALUE);
17282acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_5,
17292acdd43fSLuo Jie 			QCA808X_MMD3_DEBUG_5_VALUE);
17302acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_3,
17312acdd43fSLuo Jie 			QCA808X_MMD3_DEBUG_3_VALUE);
17322acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_6,
17332acdd43fSLuo Jie 			QCA808X_MMD3_DEBUG_6_VALUE);
17342acdd43fSLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_2,
17352acdd43fSLuo Jie 			QCA808X_MMD3_DEBUG_2_VALUE);
17362acdd43fSLuo Jie 
17372acdd43fSLuo Jie 	return 0;
17382acdd43fSLuo Jie }
17392acdd43fSLuo Jie 
qca808x_phy_ms_seed_enable(struct phy_device * phydev,bool enable)17409d4dae29SLuo Jie static int qca808x_phy_ms_seed_enable(struct phy_device *phydev, bool enable)
17419d4dae29SLuo Jie {
1742f3db55aeSLuo Jie 	u16 seed_value;
17439d4dae29SLuo Jie 
1744f3db55aeSLuo Jie 	if (!enable)
17459d4dae29SLuo Jie 		return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED,
1746f3db55aeSLuo Jie 				QCA808X_MASTER_SLAVE_SEED_ENABLE, 0);
1747f3db55aeSLuo Jie 
1748f3db55aeSLuo Jie 	seed_value = get_random_u32_below(QCA808X_MASTER_SLAVE_SEED_RANGE);
1749f3db55aeSLuo Jie 	return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED,
1750f3db55aeSLuo Jie 			QCA808X_MASTER_SLAVE_SEED_CFG | QCA808X_MASTER_SLAVE_SEED_ENABLE,
1751f3db55aeSLuo Jie 			FIELD_PREP(QCA808X_MASTER_SLAVE_SEED_CFG, seed_value) |
1752f3db55aeSLuo Jie 			QCA808X_MASTER_SLAVE_SEED_ENABLE);
17539d4dae29SLuo Jie }
17549d4dae29SLuo Jie 
qca808x_is_prefer_master(struct phy_device * phydev)17557cc32095SLuo Jie static bool qca808x_is_prefer_master(struct phy_device *phydev)
17567cc32095SLuo Jie {
17577cc32095SLuo Jie 	return (phydev->master_slave_get == MASTER_SLAVE_CFG_MASTER_FORCE) ||
17587cc32095SLuo Jie 		(phydev->master_slave_get == MASTER_SLAVE_CFG_MASTER_PREFERRED);
17597cc32095SLuo Jie }
17607cc32095SLuo Jie 
qca808x_has_fast_retrain_or_slave_seed(struct phy_device * phydev)1761df9401ffSLuo Jie static bool qca808x_has_fast_retrain_or_slave_seed(struct phy_device *phydev)
1762df9401ffSLuo Jie {
1763df9401ffSLuo Jie 	return linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported);
1764df9401ffSLuo Jie }
1765df9401ffSLuo Jie 
qca808x_config_init(struct phy_device * phydev)17662acdd43fSLuo Jie static int qca808x_config_init(struct phy_device *phydev)
17672acdd43fSLuo Jie {
17682acdd43fSLuo Jie 	int ret;
17692acdd43fSLuo Jie 
17702acdd43fSLuo Jie 	/* Active adc&vga on 802.3az for the link 1000M and 100M */
17712acdd43fSLuo Jie 	ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_ADDR_CLD_CTRL7,
17722acdd43fSLuo Jie 			QCA808X_8023AZ_AFE_CTRL_MASK, QCA808X_8023AZ_AFE_EN);
17732acdd43fSLuo Jie 	if (ret)
17742acdd43fSLuo Jie 		return ret;
17752acdd43fSLuo Jie 
17762acdd43fSLuo Jie 	/* Adjust the threshold on 802.3az for the link 1000M */
17772acdd43fSLuo Jie 	ret = phy_write_mmd(phydev, MDIO_MMD_PCS,
17782acdd43fSLuo Jie 			QCA808X_PHY_MMD3_AZ_TRAINING_CTRL, QCA808X_MMD3_AZ_TRAINING_VAL);
17792acdd43fSLuo Jie 	if (ret)
17802acdd43fSLuo Jie 		return ret;
17812acdd43fSLuo Jie 
1782df9401ffSLuo Jie 	if (qca808x_has_fast_retrain_or_slave_seed(phydev)) {
17832acdd43fSLuo Jie 		/* Config the fast retrain for the link 2500M */
17842acdd43fSLuo Jie 		ret = qca808x_phy_fast_retrain_config(phydev);
17852acdd43fSLuo Jie 		if (ret)
17862acdd43fSLuo Jie 			return ret;
17872acdd43fSLuo Jie 
17887cc32095SLuo Jie 		ret = genphy_read_master_slave(phydev);
17897cc32095SLuo Jie 		if (ret < 0)
17907cc32095SLuo Jie 			return ret;
17917cc32095SLuo Jie 
17927cc32095SLuo Jie 		if (!qca808x_is_prefer_master(phydev)) {
1793df9401ffSLuo Jie 			/* Enable seed and configure lower ramdom seed to make phy
1794df9401ffSLuo Jie 			 * linked as slave mode.
1795df9401ffSLuo Jie 			 */
17969d4dae29SLuo Jie 			ret = qca808x_phy_ms_seed_enable(phydev, true);
17979d4dae29SLuo Jie 			if (ret)
17989d4dae29SLuo Jie 				return ret;
17997cc32095SLuo Jie 		}
1800df9401ffSLuo Jie 	}
18019d4dae29SLuo Jie 
18022acdd43fSLuo Jie 	/* Configure adc threshold as 100mv for the link 10M */
18032acdd43fSLuo Jie 	return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD,
18042acdd43fSLuo Jie 			QCA808X_ADC_THRESHOLD_MASK, QCA808X_ADC_THRESHOLD_100MV);
18052acdd43fSLuo Jie }
18062acdd43fSLuo Jie 
qca808x_read_status(struct phy_device * phydev)180779c7bc05SLuo Jie static int qca808x_read_status(struct phy_device *phydev)
180879c7bc05SLuo Jie {
180979c7bc05SLuo Jie 	int ret;
181079c7bc05SLuo Jie 
181179c7bc05SLuo Jie 	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
181279c7bc05SLuo Jie 	if (ret < 0)
181379c7bc05SLuo Jie 		return ret;
181479c7bc05SLuo Jie 
181579c7bc05SLuo Jie 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising,
181679c7bc05SLuo Jie 			ret & MDIO_AN_10GBT_STAT_LP2_5G);
181779c7bc05SLuo Jie 
181879c7bc05SLuo Jie 	ret = genphy_read_status(phydev);
181979c7bc05SLuo Jie 	if (ret)
182079c7bc05SLuo Jie 		return ret;
182179c7bc05SLuo Jie 
182279c7bc05SLuo Jie 	ret = at803x_read_specific_status(phydev);
182379c7bc05SLuo Jie 	if (ret < 0)
182479c7bc05SLuo Jie 		return ret;
182579c7bc05SLuo Jie 
1826881cc731SJonathan McDowell 	if (phydev->link) {
1827881cc731SJonathan McDowell 		if (phydev->speed == SPEED_2500)
182879c7bc05SLuo Jie 			phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
182979c7bc05SLuo Jie 		else
1830881cc731SJonathan McDowell 			phydev->interface = PHY_INTERFACE_MODE_SGMII;
1831881cc731SJonathan McDowell 	} else {
18328bc1c543SLuo Jie 		/* generate seed as a lower random value to make PHY linked as SLAVE easily,
18337cc32095SLuo Jie 		 * except for master/slave configuration fault detected or the master mode
18347cc32095SLuo Jie 		 * preferred.
18357cc32095SLuo Jie 		 *
18368bc1c543SLuo Jie 		 * the reason for not putting this code into the function link_change_notify is
18378bc1c543SLuo Jie 		 * the corner case where the link partner is also the qca8081 PHY and the seed
18388bc1c543SLuo Jie 		 * value is configured as the same value, the link can't be up and no link change
18398bc1c543SLuo Jie 		 * occurs.
18408bc1c543SLuo Jie 		 */
1841df9401ffSLuo Jie 		if (qca808x_has_fast_retrain_or_slave_seed(phydev)) {
18427cc32095SLuo Jie 			if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR ||
18437cc32095SLuo Jie 					qca808x_is_prefer_master(phydev)) {
18448bc1c543SLuo Jie 				qca808x_phy_ms_seed_enable(phydev, false);
18458bc1c543SLuo Jie 			} else {
18468bc1c543SLuo Jie 				qca808x_phy_ms_seed_enable(phydev, true);
18478bc1c543SLuo Jie 			}
18488bc1c543SLuo Jie 		}
1849df9401ffSLuo Jie 	}
18508bc1c543SLuo Jie 
185179c7bc05SLuo Jie 	return 0;
185279c7bc05SLuo Jie }
185379c7bc05SLuo Jie 
qca808x_soft_reset(struct phy_device * phydev)18549d4dae29SLuo Jie static int qca808x_soft_reset(struct phy_device *phydev)
18559d4dae29SLuo Jie {
18569d4dae29SLuo Jie 	int ret;
18579d4dae29SLuo Jie 
18589d4dae29SLuo Jie 	ret = genphy_soft_reset(phydev);
18599d4dae29SLuo Jie 	if (ret < 0)
18609d4dae29SLuo Jie 		return ret;
18619d4dae29SLuo Jie 
1862df9401ffSLuo Jie 	if (qca808x_has_fast_retrain_or_slave_seed(phydev))
1863df9401ffSLuo Jie 		ret = qca808x_phy_ms_seed_enable(phydev, true);
1864df9401ffSLuo Jie 
1865df9401ffSLuo Jie 	return ret;
18669d4dae29SLuo Jie }
18679d4dae29SLuo Jie 
qca808x_cdt_fault_length_valid(int cdt_code)18688c84d752SLuo Jie static bool qca808x_cdt_fault_length_valid(int cdt_code)
18698c84d752SLuo Jie {
18708c84d752SLuo Jie 	switch (cdt_code) {
18718c84d752SLuo Jie 	case QCA808X_CDT_STATUS_STAT_SHORT:
18728c84d752SLuo Jie 	case QCA808X_CDT_STATUS_STAT_OPEN:
18738c84d752SLuo Jie 		return true;
18748c84d752SLuo Jie 	default:
18758c84d752SLuo Jie 		return false;
18768c84d752SLuo Jie 	}
18778c84d752SLuo Jie }
18788c84d752SLuo Jie 
qca808x_cable_test_result_trans(int cdt_code)18798c84d752SLuo Jie static int qca808x_cable_test_result_trans(int cdt_code)
18808c84d752SLuo Jie {
18818c84d752SLuo Jie 	switch (cdt_code) {
18828c84d752SLuo Jie 	case QCA808X_CDT_STATUS_STAT_NORMAL:
18838c84d752SLuo Jie 		return ETHTOOL_A_CABLE_RESULT_CODE_OK;
18848c84d752SLuo Jie 	case QCA808X_CDT_STATUS_STAT_SHORT:
18858c84d752SLuo Jie 		return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
18868c84d752SLuo Jie 	case QCA808X_CDT_STATUS_STAT_OPEN:
18878c84d752SLuo Jie 		return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
18888c84d752SLuo Jie 	case QCA808X_CDT_STATUS_STAT_FAIL:
18898c84d752SLuo Jie 	default:
18908c84d752SLuo Jie 		return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
18918c84d752SLuo Jie 	}
18928c84d752SLuo Jie }
18938c84d752SLuo Jie 
qca808x_cdt_fault_length(struct phy_device * phydev,int pair)18948c84d752SLuo Jie static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair)
18958c84d752SLuo Jie {
18968c84d752SLuo Jie 	int val;
18978c84d752SLuo Jie 	u32 cdt_length_reg = 0;
18988c84d752SLuo Jie 
18998c84d752SLuo Jie 	switch (pair) {
19008c84d752SLuo Jie 	case ETHTOOL_A_CABLE_PAIR_A:
19018c84d752SLuo Jie 		cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_A;
19028c84d752SLuo Jie 		break;
19038c84d752SLuo Jie 	case ETHTOOL_A_CABLE_PAIR_B:
19048c84d752SLuo Jie 		cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_B;
19058c84d752SLuo Jie 		break;
19068c84d752SLuo Jie 	case ETHTOOL_A_CABLE_PAIR_C:
19078c84d752SLuo Jie 		cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_C;
19088c84d752SLuo Jie 		break;
19098c84d752SLuo Jie 	case ETHTOOL_A_CABLE_PAIR_D:
19108c84d752SLuo Jie 		cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_D;
19118c84d752SLuo Jie 		break;
19128c84d752SLuo Jie 	default:
19138c84d752SLuo Jie 		return -EINVAL;
19148c84d752SLuo Jie 	}
19158c84d752SLuo Jie 
19168c84d752SLuo Jie 	val = phy_read_mmd(phydev, MDIO_MMD_PCS, cdt_length_reg);
19178c84d752SLuo Jie 	if (val < 0)
19188c84d752SLuo Jie 		return val;
19198c84d752SLuo Jie 
19208c84d752SLuo Jie 	return (FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val) * 824) / 10;
19218c84d752SLuo Jie }
19228c84d752SLuo Jie 
qca808x_cable_test_start(struct phy_device * phydev)19238c84d752SLuo Jie static int qca808x_cable_test_start(struct phy_device *phydev)
19248c84d752SLuo Jie {
19258c84d752SLuo Jie 	int ret;
19268c84d752SLuo Jie 
19278c84d752SLuo Jie 	/* perform CDT with the following configs:
19288c84d752SLuo Jie 	 * 1. disable hibernation.
19298c84d752SLuo Jie 	 * 2. force PHY working in MDI mode.
19308c84d752SLuo Jie 	 * 3. for PHY working in 1000BaseT.
19318c84d752SLuo Jie 	 * 4. configure the threshold.
19328c84d752SLuo Jie 	 */
19338c84d752SLuo Jie 
19348c84d752SLuo Jie 	ret = at803x_debug_reg_mask(phydev, QCA808X_DBG_AN_TEST, QCA808X_HIBERNATION_EN, 0);
19358c84d752SLuo Jie 	if (ret < 0)
19368c84d752SLuo Jie 		return ret;
19378c84d752SLuo Jie 
19388c84d752SLuo Jie 	ret = at803x_config_mdix(phydev, ETH_TP_MDI);
19398c84d752SLuo Jie 	if (ret < 0)
19408c84d752SLuo Jie 		return ret;
19418c84d752SLuo Jie 
19428c84d752SLuo Jie 	/* Force 1000base-T needs to configure PMA/PMD and MII_BMCR */
19438c84d752SLuo Jie 	phydev->duplex = DUPLEX_FULL;
19448c84d752SLuo Jie 	phydev->speed = SPEED_1000;
19458c84d752SLuo Jie 	ret = genphy_c45_pma_setup_forced(phydev);
19468c84d752SLuo Jie 	if (ret < 0)
19478c84d752SLuo Jie 		return ret;
19488c84d752SLuo Jie 
19498c84d752SLuo Jie 	ret = genphy_setup_forced(phydev);
19508c84d752SLuo Jie 	if (ret < 0)
19518c84d752SLuo Jie 		return ret;
19528c84d752SLuo Jie 
19538c84d752SLuo Jie 	/* configure the thresholds for open, short, pair ok test */
19548c84d752SLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8074, 0xc040);
19558c84d752SLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8076, 0xc040);
19568c84d752SLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8077, 0xa060);
19578c84d752SLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8078, 0xc050);
19588c84d752SLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807a, 0xc060);
19598c84d752SLuo Jie 	phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807e, 0xb060);
19608c84d752SLuo Jie 
19618c84d752SLuo Jie 	return 0;
19628c84d752SLuo Jie }
19638c84d752SLuo Jie 
qca808x_cable_test_get_status(struct phy_device * phydev,bool * finished)19648c84d752SLuo Jie static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished)
19658c84d752SLuo Jie {
19668c84d752SLuo Jie 	int ret, val;
19678c84d752SLuo Jie 	int pair_a, pair_b, pair_c, pair_d;
19688c84d752SLuo Jie 
19698c84d752SLuo Jie 	*finished = false;
19708c84d752SLuo Jie 
19718c84d752SLuo Jie 	ret = at803x_cdt_start(phydev, 0);
19728c84d752SLuo Jie 	if (ret)
19738c84d752SLuo Jie 		return ret;
19748c84d752SLuo Jie 
19758c84d752SLuo Jie 	ret = at803x_cdt_wait_for_completion(phydev);
19768c84d752SLuo Jie 	if (ret)
19778c84d752SLuo Jie 		return ret;
19788c84d752SLuo Jie 
19798c84d752SLuo Jie 	val = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA808X_MMD3_CDT_STATUS);
19808c84d752SLuo Jie 	if (val < 0)
19818c84d752SLuo Jie 		return val;
19828c84d752SLuo Jie 
19838c84d752SLuo Jie 	pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val);
19848c84d752SLuo Jie 	pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val);
19858c84d752SLuo Jie 	pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val);
19868c84d752SLuo Jie 	pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val);
19878c84d752SLuo Jie 
19888c84d752SLuo Jie 	ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
19898c84d752SLuo Jie 				qca808x_cable_test_result_trans(pair_a));
19908c84d752SLuo Jie 	ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
19918c84d752SLuo Jie 				qca808x_cable_test_result_trans(pair_b));
19928c84d752SLuo Jie 	ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
19938c84d752SLuo Jie 				qca808x_cable_test_result_trans(pair_c));
19948c84d752SLuo Jie 	ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
19958c84d752SLuo Jie 				qca808x_cable_test_result_trans(pair_d));
19968c84d752SLuo Jie 
19978c84d752SLuo Jie 	if (qca808x_cdt_fault_length_valid(pair_a))
19988c84d752SLuo Jie 		ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A,
19998c84d752SLuo Jie 				qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A));
20008c84d752SLuo Jie 	if (qca808x_cdt_fault_length_valid(pair_b))
20018c84d752SLuo Jie 		ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B,
20028c84d752SLuo Jie 				qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B));
20038c84d752SLuo Jie 	if (qca808x_cdt_fault_length_valid(pair_c))
20048c84d752SLuo Jie 		ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C,
20058c84d752SLuo Jie 				qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C));
20068c84d752SLuo Jie 	if (qca808x_cdt_fault_length_valid(pair_d))
20078c84d752SLuo Jie 		ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D,
20088c84d752SLuo Jie 				qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D));
20098c84d752SLuo Jie 
20108c84d752SLuo Jie 	*finished = true;
20118c84d752SLuo Jie 
20128c84d752SLuo Jie 	return 0;
20138c84d752SLuo Jie }
20148c84d752SLuo Jie 
qca808x_get_features(struct phy_device * phydev)20158b8bc13dSLuo Jie static int qca808x_get_features(struct phy_device *phydev)
20168b8bc13dSLuo Jie {
20178b8bc13dSLuo Jie 	int ret;
20188b8bc13dSLuo Jie 
20198b8bc13dSLuo Jie 	ret = genphy_c45_pma_read_abilities(phydev);
20208b8bc13dSLuo Jie 	if (ret)
20218b8bc13dSLuo Jie 		return ret;
20228b8bc13dSLuo Jie 
20238b8bc13dSLuo Jie 	/* The autoneg ability is not existed in bit3 of MMD7.1,
20248b8bc13dSLuo Jie 	 * but it is supported by qca808x PHY, so we add it here
20258b8bc13dSLuo Jie 	 * manually.
20268b8bc13dSLuo Jie 	 */
20278b8bc13dSLuo Jie 	linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported);
20288b8bc13dSLuo Jie 
2029fea7cfb8SLuo Jie 	/* As for the qca8081 1G version chip, the 2500baseT ability is also
2030fea7cfb8SLuo Jie 	 * existed in the bit0 of MMD1.21, we need to remove it manually if
2031fea7cfb8SLuo Jie 	 * it is the qca8081 1G chip according to the bit0 of MMD7.0x901d.
2032fea7cfb8SLuo Jie 	 */
2033fea7cfb8SLuo Jie 	ret = phy_read_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_CHIP_TYPE);
2034fea7cfb8SLuo Jie 	if (ret < 0)
2035fea7cfb8SLuo Jie 		return ret;
2036fea7cfb8SLuo Jie 
2037fea7cfb8SLuo Jie 	if (QCA808X_PHY_CHIP_TYPE_1G & ret)
2038fea7cfb8SLuo Jie 		linkmode_clear_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported);
2039fea7cfb8SLuo Jie 
20408b8bc13dSLuo Jie 	return 0;
20418b8bc13dSLuo Jie }
20428b8bc13dSLuo Jie 
qca808x_link_change_notify(struct phy_device * phydev)2043723970afSLuo Jie static void qca808x_link_change_notify(struct phy_device *phydev)
2044723970afSLuo Jie {
2045723970afSLuo Jie 	/* Assert interface sgmii fifo on link down, deassert it on link up,
2046723970afSLuo Jie 	 * the interface device address is always phy address added by 1.
2047723970afSLuo Jie 	 */
2048723970afSLuo Jie 	mdiobus_c45_modify_changed(phydev->mdio.bus, phydev->mdio.addr + 1,
2049723970afSLuo Jie 			MDIO_MMD_PMAPMD, QCA8081_PHY_SERDES_MMD1_FIFO_CTRL,
2050723970afSLuo Jie 			QCA8081_PHY_FIFO_RSTN, phydev->link ? QCA8081_PHY_FIFO_RSTN : 0);
2051723970afSLuo Jie }
2052723970afSLuo Jie 
2053317420abSMugunthan V N static struct phy_driver at803x_driver[] = {
2054317420abSMugunthan V N {
205596c36712SMichael Walle 	/* Qualcomm Atheros AR8035 */
20560465d8f8SMichael Walle 	PHY_ID_MATCH_EXACT(ATH8035_PHY_ID),
205796c36712SMichael Walle 	.name			= "Qualcomm Atheros AR8035",
20586cb75767SMichael Walle 	.flags			= PHY_POLL_CABLE_TEST,
20592f664823SMichael Walle 	.probe			= at803x_probe,
20607dce80c2SOleksij Rempel 	.config_aneg		= at803x_config_aneg,
20610ca7111aSMatus Ujhelyi 	.config_init		= at803x_config_init,
2062cde0f4f8SMichael Walle 	.soft_reset		= genphy_soft_reset,
2063ea13c9eeSMugunthan V N 	.set_wol		= at803x_set_wol,
2064ea13c9eeSMugunthan V N 	.get_wol		= at803x_get_wol,
20656229ed1fSDaniel Mack 	.suspend		= at803x_suspend,
20666229ed1fSDaniel Mack 	.resume			= at803x_resume,
2067dcdecdcfSHeiner Kallweit 	/* PHY_GBIT_FEATURES */
206806d5f344SRussell King 	.read_status		= at803x_read_status,
20690eae5982SMåns Rullgård 	.config_intr		= at803x_config_intr,
207029773097SIoana Ciornei 	.handle_interrupt	= at803x_handle_interrupt,
2071cde0f4f8SMichael Walle 	.get_tunable		= at803x_get_tunable,
2072cde0f4f8SMichael Walle 	.set_tunable		= at803x_set_tunable,
20736cb75767SMichael Walle 	.cable_test_start	= at803x_cable_test_start,
20746cb75767SMichael Walle 	.cable_test_get_status	= at803x_cable_test_get_status,
2075317420abSMugunthan V N }, {
207696c36712SMichael Walle 	/* Qualcomm Atheros AR8030 */
2077bd8ca17fSDaniel Mack 	.phy_id			= ATH8030_PHY_ID,
207896c36712SMichael Walle 	.name			= "Qualcomm Atheros AR8030",
20790465d8f8SMichael Walle 	.phy_id_mask		= AT8030_PHY_ID_MASK,
20802f664823SMichael Walle 	.probe			= at803x_probe,
20810ca7111aSMatus Ujhelyi 	.config_init		= at803x_config_init,
208213a56b44SDaniel Mack 	.link_change_notify	= at803x_link_change_notify,
2083ea13c9eeSMugunthan V N 	.set_wol		= at803x_set_wol,
2084ea13c9eeSMugunthan V N 	.get_wol		= at803x_get_wol,
20856229ed1fSDaniel Mack 	.suspend		= at803x_suspend,
20866229ed1fSDaniel Mack 	.resume			= at803x_resume,
2087dcdecdcfSHeiner Kallweit 	/* PHY_BASIC_FEATURES */
20880eae5982SMåns Rullgård 	.config_intr		= at803x_config_intr,
208929773097SIoana Ciornei 	.handle_interrupt	= at803x_handle_interrupt,
209005d7cce8SMugunthan V N }, {
209196c36712SMichael Walle 	/* Qualcomm Atheros AR8031/AR8033 */
20920465d8f8SMichael Walle 	PHY_ID_MATCH_EXACT(ATH8031_PHY_ID),
209396c36712SMichael Walle 	.name			= "Qualcomm Atheros AR8031/AR8033",
20946cb75767SMichael Walle 	.flags			= PHY_POLL_CABLE_TEST,
20952f664823SMichael Walle 	.probe			= at803x_probe,
209605d7cce8SMugunthan V N 	.config_init		= at803x_config_init,
209763477a5dSMichael Walle 	.config_aneg		= at803x_config_aneg,
2098cde0f4f8SMichael Walle 	.soft_reset		= genphy_soft_reset,
209905d7cce8SMugunthan V N 	.set_wol		= at803x_set_wol,
210005d7cce8SMugunthan V N 	.get_wol		= at803x_get_wol,
21016229ed1fSDaniel Mack 	.suspend		= at803x_suspend,
21026229ed1fSDaniel Mack 	.resume			= at803x_resume,
2103c329e5afSDavid Bauer 	.read_page		= at803x_read_page,
2104c329e5afSDavid Bauer 	.write_page		= at803x_write_page,
2105b856150cSDavid Bauer 	.get_features		= at803x_get_features,
210606d5f344SRussell King 	.read_status		= at803x_read_status,
2107*24374927SChristian Marangi 	.config_intr		= at803x_config_intr,
210829773097SIoana Ciornei 	.handle_interrupt	= at803x_handle_interrupt,
2109cde0f4f8SMichael Walle 	.get_tunable		= at803x_get_tunable,
2110cde0f4f8SMichael Walle 	.set_tunable		= at803x_set_tunable,
21116cb75767SMichael Walle 	.cable_test_start	= at803x_cable_test_start,
21126cb75767SMichael Walle 	.cable_test_get_status	= at803x_cable_test_get_status,
21137908d2ceSOleksij Rempel }, {
21145800091aSDavid Bauer 	/* Qualcomm Atheros AR8032 */
21155800091aSDavid Bauer 	PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
21165800091aSDavid Bauer 	.name			= "Qualcomm Atheros AR8032",
21175800091aSDavid Bauer 	.probe			= at803x_probe,
2118dc0f3ed1SOleksij Rempel 	.flags			= PHY_POLL_CABLE_TEST,
21195800091aSDavid Bauer 	.config_init		= at803x_config_init,
21205800091aSDavid Bauer 	.link_change_notify	= at803x_link_change_notify,
21215800091aSDavid Bauer 	.suspend		= at803x_suspend,
21225800091aSDavid Bauer 	.resume			= at803x_resume,
21235800091aSDavid Bauer 	/* PHY_BASIC_FEATURES */
21245800091aSDavid Bauer 	.config_intr		= at803x_config_intr,
212529773097SIoana Ciornei 	.handle_interrupt	= at803x_handle_interrupt,
2126dc0f3ed1SOleksij Rempel 	.cable_test_start	= at803x_cable_test_start,
2127dc0f3ed1SOleksij Rempel 	.cable_test_get_status	= at803x_cable_test_get_status,
21285800091aSDavid Bauer }, {
21297908d2ceSOleksij Rempel 	/* ATHEROS AR9331 */
21307908d2ceSOleksij Rempel 	PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
213196c36712SMichael Walle 	.name			= "Qualcomm Atheros AR9331 built-in PHY",
21329926de73SOleksij Rempel 	.probe			= at803x_probe,
21337908d2ceSOleksij Rempel 	.suspend		= at803x_suspend,
21347908d2ceSOleksij Rempel 	.resume			= at803x_resume,
2135dc0f3ed1SOleksij Rempel 	.flags			= PHY_POLL_CABLE_TEST,
21367908d2ceSOleksij Rempel 	/* PHY_BASIC_FEATURES */
2137*24374927SChristian Marangi 	.config_intr		= at803x_config_intr,
213829773097SIoana Ciornei 	.handle_interrupt	= at803x_handle_interrupt,
2139dc0f3ed1SOleksij Rempel 	.cable_test_start	= at803x_cable_test_start,
2140dc0f3ed1SOleksij Rempel 	.cable_test_get_status	= at803x_cable_test_get_status,
21417dce80c2SOleksij Rempel 	.read_status		= at803x_read_status,
21427dce80c2SOleksij Rempel 	.soft_reset		= genphy_soft_reset,
21437dce80c2SOleksij Rempel 	.config_aneg		= at803x_config_aneg,
2144272833b9SAnsuel Smith }, {
2145fada2ce0SDavid Bauer 	/* Qualcomm Atheros QCA9561 */
2146fada2ce0SDavid Bauer 	PHY_ID_MATCH_EXACT(QCA9561_PHY_ID),
2147fada2ce0SDavid Bauer 	.name			= "Qualcomm Atheros QCA9561 built-in PHY",
21489926de73SOleksij Rempel 	.probe			= at803x_probe,
2149fada2ce0SDavid Bauer 	.suspend		= at803x_suspend,
2150fada2ce0SDavid Bauer 	.resume			= at803x_resume,
2151fada2ce0SDavid Bauer 	.flags			= PHY_POLL_CABLE_TEST,
2152fada2ce0SDavid Bauer 	/* PHY_BASIC_FEATURES */
2153*24374927SChristian Marangi 	.config_intr		= at803x_config_intr,
2154fada2ce0SDavid Bauer 	.handle_interrupt	= at803x_handle_interrupt,
2155fada2ce0SDavid Bauer 	.cable_test_start	= at803x_cable_test_start,
2156fada2ce0SDavid Bauer 	.cable_test_get_status	= at803x_cable_test_get_status,
2157fada2ce0SDavid Bauer 	.read_status		= at803x_read_status,
2158fada2ce0SDavid Bauer 	.soft_reset		= genphy_soft_reset,
2159fada2ce0SDavid Bauer 	.config_aneg		= at803x_config_aneg,
2160fada2ce0SDavid Bauer }, {
2161272833b9SAnsuel Smith 	/* QCA8337 */
2162272833b9SAnsuel Smith 	.phy_id			= QCA8337_PHY_ID,
2163272833b9SAnsuel Smith 	.phy_id_mask		= QCA8K_PHY_ID_MASK,
2164d44fd860SAnsuel Smith 	.name			= "Qualcomm Atheros 8337 internal PHY",
2165272833b9SAnsuel Smith 	/* PHY_GBIT_FEATURES */
21661ca83119SAnsuel Smith 	.link_change_notify	= qca83xx_link_change_notify,
2167272833b9SAnsuel Smith 	.probe			= at803x_probe,
2168272833b9SAnsuel Smith 	.flags			= PHY_IS_INTERNAL,
2169272833b9SAnsuel Smith 	.config_init		= qca83xx_config_init,
2170272833b9SAnsuel Smith 	.soft_reset		= genphy_soft_reset,
2171272833b9SAnsuel Smith 	.get_sset_count		= at803x_get_sset_count,
2172272833b9SAnsuel Smith 	.get_strings		= at803x_get_strings,
2173272833b9SAnsuel Smith 	.get_stats		= at803x_get_stats,
2174ba3c01eeSAnsuel Smith 	.suspend		= qca83xx_suspend,
2175ba3c01eeSAnsuel Smith 	.resume			= qca83xx_resume,
21760ccf8511SAnsuel Smith }, {
2177b4df02b5SAnsuel Smith 	/* QCA8327-A from switch QCA8327-AL1A */
2178b4df02b5SAnsuel Smith 	.phy_id			= QCA8327_A_PHY_ID,
21790ccf8511SAnsuel Smith 	.phy_id_mask		= QCA8K_PHY_ID_MASK,
2180d44fd860SAnsuel Smith 	.name			= "Qualcomm Atheros 8327-A internal PHY",
2181b4df02b5SAnsuel Smith 	/* PHY_GBIT_FEATURES */
21821ca83119SAnsuel Smith 	.link_change_notify	= qca83xx_link_change_notify,
2183b4df02b5SAnsuel Smith 	.probe			= at803x_probe,
2184b4df02b5SAnsuel Smith 	.flags			= PHY_IS_INTERNAL,
2185b4df02b5SAnsuel Smith 	.config_init		= qca83xx_config_init,
2186b4df02b5SAnsuel Smith 	.soft_reset		= genphy_soft_reset,
2187b4df02b5SAnsuel Smith 	.get_sset_count		= at803x_get_sset_count,
2188b4df02b5SAnsuel Smith 	.get_strings		= at803x_get_strings,
2189b4df02b5SAnsuel Smith 	.get_stats		= at803x_get_stats,
2190ba3c01eeSAnsuel Smith 	.suspend		= qca83xx_suspend,
2191ba3c01eeSAnsuel Smith 	.resume			= qca83xx_resume,
2192b4df02b5SAnsuel Smith }, {
2193b4df02b5SAnsuel Smith 	/* QCA8327-B from switch QCA8327-BL1A */
2194b4df02b5SAnsuel Smith 	.phy_id			= QCA8327_B_PHY_ID,
2195b4df02b5SAnsuel Smith 	.phy_id_mask		= QCA8K_PHY_ID_MASK,
2196d44fd860SAnsuel Smith 	.name			= "Qualcomm Atheros 8327-B internal PHY",
21970ccf8511SAnsuel Smith 	/* PHY_GBIT_FEATURES */
21981ca83119SAnsuel Smith 	.link_change_notify	= qca83xx_link_change_notify,
21990ccf8511SAnsuel Smith 	.probe			= at803x_probe,
22000ccf8511SAnsuel Smith 	.flags			= PHY_IS_INTERNAL,
22010ccf8511SAnsuel Smith 	.config_init		= qca83xx_config_init,
22020ccf8511SAnsuel Smith 	.soft_reset		= genphy_soft_reset,
22030ccf8511SAnsuel Smith 	.get_sset_count		= at803x_get_sset_count,
22040ccf8511SAnsuel Smith 	.get_strings		= at803x_get_strings,
22050ccf8511SAnsuel Smith 	.get_stats		= at803x_get_stats,
2206ba3c01eeSAnsuel Smith 	.suspend		= qca83xx_suspend,
2207ba3c01eeSAnsuel Smith 	.resume			= qca83xx_resume,
2208daf61732SLuo Jie }, {
2209daf61732SLuo Jie 	/* Qualcomm QCA8081 */
2210daf61732SLuo Jie 	PHY_ID_MATCH_EXACT(QCA8081_PHY_ID),
2211daf61732SLuo Jie 	.name			= "Qualcomm QCA8081",
22128c84d752SLuo Jie 	.flags			= PHY_POLL_CABLE_TEST,
22139926de73SOleksij Rempel 	.probe			= at803x_probe,
2214daf61732SLuo Jie 	.config_intr		= at803x_config_intr,
2215daf61732SLuo Jie 	.handle_interrupt	= at803x_handle_interrupt,
2216daf61732SLuo Jie 	.get_tunable		= at803x_get_tunable,
2217daf61732SLuo Jie 	.set_tunable		= at803x_set_tunable,
2218daf61732SLuo Jie 	.set_wol		= at803x_set_wol,
2219daf61732SLuo Jie 	.get_wol		= at803x_get_wol,
22208b8bc13dSLuo Jie 	.get_features		= qca808x_get_features,
2221f884d449SLuo Jie 	.config_aneg		= at803x_config_aneg,
2222daf61732SLuo Jie 	.suspend		= genphy_suspend,
2223daf61732SLuo Jie 	.resume			= genphy_resume,
222479c7bc05SLuo Jie 	.read_status		= qca808x_read_status,
22252acdd43fSLuo Jie 	.config_init		= qca808x_config_init,
22269d4dae29SLuo Jie 	.soft_reset		= qca808x_soft_reset,
22278c84d752SLuo Jie 	.cable_test_start	= qca808x_cable_test_start,
22288c84d752SLuo Jie 	.cable_test_get_status	= qca808x_cable_test_get_status,
2229723970afSLuo Jie 	.link_change_notify	= qca808x_link_change_notify,
2230272833b9SAnsuel Smith }, };
22310ca7111aSMatus Ujhelyi 
223250fd7150SJohan Hovold module_phy_driver(at803x_driver);
22330ca7111aSMatus Ujhelyi 
22340ca7111aSMatus Ujhelyi static struct mdio_device_id __maybe_unused atheros_tbl[] = {
22350465d8f8SMichael Walle 	{ ATH8030_PHY_ID, AT8030_PHY_ID_MASK },
22360465d8f8SMichael Walle 	{ PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) },
22375800091aSDavid Bauer 	{ PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) },
22380465d8f8SMichael Walle 	{ PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) },
22397908d2ceSOleksij Rempel 	{ PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) },
22400ccf8511SAnsuel Smith 	{ PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) },
2241b4df02b5SAnsuel Smith 	{ PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) },
2242b4df02b5SAnsuel Smith 	{ PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) },
2243fada2ce0SDavid Bauer 	{ PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) },
2244daf61732SLuo Jie 	{ PHY_ID_MATCH_EXACT(QCA8081_PHY_ID) },
22450ca7111aSMatus Ujhelyi 	{ }
22460ca7111aSMatus Ujhelyi };
22470ca7111aSMatus Ujhelyi 
22480ca7111aSMatus Ujhelyi MODULE_DEVICE_TABLE(mdio, atheros_tbl);
2249