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 275daf61732SLuo Jie MODULE_DESCRIPTION("Qualcomm Atheros AR803x and QCA808X PHY driver"); 2760ca7111aSMatus Ujhelyi MODULE_AUTHOR("Matus Ujhelyi"); 2770ca7111aSMatus Ujhelyi MODULE_LICENSE("GPL"); 2780ca7111aSMatus Ujhelyi 279272833b9SAnsuel Smith enum stat_access_type { 280272833b9SAnsuel Smith PHY, 281272833b9SAnsuel Smith MMD 282272833b9SAnsuel Smith }; 283272833b9SAnsuel Smith 284272833b9SAnsuel Smith struct at803x_hw_stat { 285272833b9SAnsuel Smith const char *string; 286272833b9SAnsuel Smith u8 reg; 287272833b9SAnsuel Smith u32 mask; 288272833b9SAnsuel Smith enum stat_access_type access_type; 289272833b9SAnsuel Smith }; 290272833b9SAnsuel Smith 291272833b9SAnsuel Smith static struct at803x_hw_stat at803x_hw_stats[] = { 292272833b9SAnsuel Smith { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY}, 293272833b9SAnsuel Smith { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY}, 294272833b9SAnsuel Smith { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD}, 295272833b9SAnsuel Smith }; 296272833b9SAnsuel Smith 2972f664823SMichael Walle struct at803x_priv { 2982f664823SMichael Walle int flags; 2992f664823SMichael Walle u16 clk_25m_reg; 3002f664823SMichael Walle u16 clk_25m_mask; 301390b4cadSRussell King u8 smarteee_lpi_tw_1g; 302390b4cadSRussell King u8 smarteee_lpi_tw_100m; 3033265f421SRobert Hancock bool is_fiber; 3043265f421SRobert Hancock bool is_1000basex; 3052f664823SMichael Walle struct regulator_dev *vddio_rdev; 3062f664823SMichael Walle struct regulator_dev *vddh_rdev; 307272833b9SAnsuel Smith u64 stats[ARRAY_SIZE(at803x_hw_stats)]; 3082f664823SMichael Walle }; 3092f664823SMichael Walle 31013a56b44SDaniel Mack struct at803x_context { 31113a56b44SDaniel Mack u16 bmcr; 31213a56b44SDaniel Mack u16 advertise; 31313a56b44SDaniel Mack u16 control1000; 31413a56b44SDaniel Mack u16 int_enable; 31513a56b44SDaniel Mack u16 smart_speed; 31613a56b44SDaniel Mack u16 led_control; 31713a56b44SDaniel Mack }; 31813a56b44SDaniel Mack 319272833b9SAnsuel Smith static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data) 320272833b9SAnsuel Smith { 321272833b9SAnsuel Smith int ret; 322272833b9SAnsuel Smith 323272833b9SAnsuel Smith ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); 324272833b9SAnsuel Smith if (ret < 0) 325272833b9SAnsuel Smith return ret; 326272833b9SAnsuel Smith 327272833b9SAnsuel Smith return phy_write(phydev, AT803X_DEBUG_DATA, data); 328272833b9SAnsuel Smith } 329272833b9SAnsuel Smith 3302e5f9f28SMartin Blumenstingl static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg) 3312e5f9f28SMartin Blumenstingl { 3322e5f9f28SMartin Blumenstingl int ret; 3332e5f9f28SMartin Blumenstingl 3342e5f9f28SMartin Blumenstingl ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); 3352e5f9f28SMartin Blumenstingl if (ret < 0) 3362e5f9f28SMartin Blumenstingl return ret; 3372e5f9f28SMartin Blumenstingl 3382e5f9f28SMartin Blumenstingl return phy_read(phydev, AT803X_DEBUG_DATA); 3392e5f9f28SMartin Blumenstingl } 3402e5f9f28SMartin Blumenstingl 3412e5f9f28SMartin Blumenstingl static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg, 3422e5f9f28SMartin Blumenstingl u16 clear, u16 set) 3432e5f9f28SMartin Blumenstingl { 3442e5f9f28SMartin Blumenstingl u16 val; 3452e5f9f28SMartin Blumenstingl int ret; 3462e5f9f28SMartin Blumenstingl 3472e5f9f28SMartin Blumenstingl ret = at803x_debug_reg_read(phydev, reg); 3482e5f9f28SMartin Blumenstingl if (ret < 0) 3492e5f9f28SMartin Blumenstingl return ret; 3502e5f9f28SMartin Blumenstingl 3512e5f9f28SMartin Blumenstingl val = ret & 0xffff; 3522e5f9f28SMartin Blumenstingl val &= ~clear; 3532e5f9f28SMartin Blumenstingl val |= set; 3542e5f9f28SMartin Blumenstingl 3552e5f9f28SMartin Blumenstingl return phy_write(phydev, AT803X_DEBUG_DATA, val); 3562e5f9f28SMartin Blumenstingl } 3572e5f9f28SMartin Blumenstingl 358c329e5afSDavid Bauer static int at803x_write_page(struct phy_device *phydev, int page) 359c329e5afSDavid Bauer { 360c329e5afSDavid Bauer int mask; 361c329e5afSDavid Bauer int set; 362c329e5afSDavid Bauer 363c329e5afSDavid Bauer if (page == AT803X_PAGE_COPPER) { 364c329e5afSDavid Bauer set = AT803X_BT_BX_REG_SEL; 365c329e5afSDavid Bauer mask = 0; 366c329e5afSDavid Bauer } else { 367c329e5afSDavid Bauer set = 0; 368c329e5afSDavid Bauer mask = AT803X_BT_BX_REG_SEL; 369c329e5afSDavid Bauer } 370c329e5afSDavid Bauer 371c329e5afSDavid Bauer return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set); 372c329e5afSDavid Bauer } 373c329e5afSDavid Bauer 374c329e5afSDavid Bauer static int at803x_read_page(struct phy_device *phydev) 375c329e5afSDavid Bauer { 376c329e5afSDavid Bauer int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG); 377c329e5afSDavid Bauer 378c329e5afSDavid Bauer if (ccr < 0) 379c329e5afSDavid Bauer return ccr; 380c329e5afSDavid Bauer 381c329e5afSDavid Bauer if (ccr & AT803X_BT_BX_REG_SEL) 382c329e5afSDavid Bauer return AT803X_PAGE_COPPER; 383c329e5afSDavid Bauer 384c329e5afSDavid Bauer return AT803X_PAGE_FIBER; 385c329e5afSDavid Bauer } 386c329e5afSDavid Bauer 3876d4cd041SVinod Koul static int at803x_enable_rx_delay(struct phy_device *phydev) 3886d4cd041SVinod Koul { 38967999555SAnsuel Smith return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0, 3906d4cd041SVinod Koul AT803X_DEBUG_RX_CLK_DLY_EN); 3916d4cd041SVinod Koul } 3926d4cd041SVinod Koul 3936d4cd041SVinod Koul static int at803x_enable_tx_delay(struct phy_device *phydev) 3946d4cd041SVinod Koul { 39567999555SAnsuel Smith return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0, 3966d4cd041SVinod Koul AT803X_DEBUG_TX_CLK_DLY_EN); 3976d4cd041SVinod Koul } 3986d4cd041SVinod Koul 39943f2ebd5SVinod Koul static int at803x_disable_rx_delay(struct phy_device *phydev) 4002e5f9f28SMartin Blumenstingl { 40167999555SAnsuel Smith return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 402cd28d1d6SVinod Koul AT803X_DEBUG_RX_CLK_DLY_EN, 0); 4032e5f9f28SMartin Blumenstingl } 4042e5f9f28SMartin Blumenstingl 40543f2ebd5SVinod Koul static int at803x_disable_tx_delay(struct phy_device *phydev) 4062e5f9f28SMartin Blumenstingl { 40767999555SAnsuel Smith return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 408cd28d1d6SVinod Koul AT803X_DEBUG_TX_CLK_DLY_EN, 0); 4092e5f9f28SMartin Blumenstingl } 4102e5f9f28SMartin Blumenstingl 41113a56b44SDaniel Mack /* save relevant PHY registers to private copy */ 41213a56b44SDaniel Mack static void at803x_context_save(struct phy_device *phydev, 41313a56b44SDaniel Mack struct at803x_context *context) 41413a56b44SDaniel Mack { 41513a56b44SDaniel Mack context->bmcr = phy_read(phydev, MII_BMCR); 41613a56b44SDaniel Mack context->advertise = phy_read(phydev, MII_ADVERTISE); 41713a56b44SDaniel Mack context->control1000 = phy_read(phydev, MII_CTRL1000); 41813a56b44SDaniel Mack context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE); 41913a56b44SDaniel Mack context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED); 42013a56b44SDaniel Mack context->led_control = phy_read(phydev, AT803X_LED_CONTROL); 42113a56b44SDaniel Mack } 42213a56b44SDaniel Mack 42313a56b44SDaniel Mack /* restore relevant PHY registers from private copy */ 42413a56b44SDaniel Mack static void at803x_context_restore(struct phy_device *phydev, 42513a56b44SDaniel Mack const struct at803x_context *context) 42613a56b44SDaniel Mack { 42713a56b44SDaniel Mack phy_write(phydev, MII_BMCR, context->bmcr); 42813a56b44SDaniel Mack phy_write(phydev, MII_ADVERTISE, context->advertise); 42913a56b44SDaniel Mack phy_write(phydev, MII_CTRL1000, context->control1000); 43013a56b44SDaniel Mack phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable); 43113a56b44SDaniel Mack phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed); 43213a56b44SDaniel Mack phy_write(phydev, AT803X_LED_CONTROL, context->led_control); 43313a56b44SDaniel Mack } 43413a56b44SDaniel Mack 435ea13c9eeSMugunthan V N static int at803x_set_wol(struct phy_device *phydev, 436ea13c9eeSMugunthan V N struct ethtool_wolinfo *wol) 4370ca7111aSMatus Ujhelyi { 438d7cd5e06SViorel Suman int ret, irq_enabled; 439d7cd5e06SViorel Suman 440d7cd5e06SViorel Suman if (wol->wolopts & WAKE_MAGIC) { 4410ca7111aSMatus Ujhelyi struct net_device *ndev = phydev->attached_dev; 4420ca7111aSMatus Ujhelyi const u8 *mac; 443c0f0b563SLuo Jie unsigned int i; 444edcb501eSColin Ian King static const unsigned int offsets[] = { 4450ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_32_47_OFFSET, 4460ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_16_31_OFFSET, 4470ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_0_15_OFFSET, 4480ca7111aSMatus Ujhelyi }; 4490ca7111aSMatus Ujhelyi 4500ca7111aSMatus Ujhelyi if (!ndev) 451ea13c9eeSMugunthan V N return -ENODEV; 4520ca7111aSMatus Ujhelyi 4530ca7111aSMatus Ujhelyi mac = (const u8 *) ndev->dev_addr; 4540ca7111aSMatus Ujhelyi 4550ca7111aSMatus Ujhelyi if (!is_valid_ether_addr(mac)) 456fc755687SDan Murphy return -EINVAL; 4570ca7111aSMatus Ujhelyi 4580e021396SCarlo Caione for (i = 0; i < 3; i++) 459c0f0b563SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, offsets[i], 4600ca7111aSMatus Ujhelyi mac[(i * 2) + 1] | (mac[(i * 2)] << 8)); 461ea13c9eeSMugunthan V N 462*e58f3024SLi Yang /* Enable WOL function for 1588 */ 463*e58f3024SLi Yang if (phydev->drv->phy_id == ATH8031_PHY_ID) { 464*e58f3024SLi Yang ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, 465*e58f3024SLi Yang AT803X_PHY_MMD3_WOL_CTRL, 4667beecaf7SLuo Jie 0, AT803X_WOL_EN); 4677beecaf7SLuo Jie if (ret) 4687beecaf7SLuo Jie return ret; 469*e58f3024SLi Yang } 4707beecaf7SLuo Jie /* Enable WOL interrupt */ 4712d4284e8SLuo Jie ret = phy_modify(phydev, AT803X_INTR_ENABLE, 0, AT803X_INTR_ENABLE_WOL); 472ea13c9eeSMugunthan V N if (ret) 473ea13c9eeSMugunthan V N return ret; 474ea13c9eeSMugunthan V N } else { 475*e58f3024SLi Yang /* Disable WoL function for 1588 */ 476*e58f3024SLi Yang if (phydev->drv->phy_id == ATH8031_PHY_ID) { 477*e58f3024SLi Yang ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, 478*e58f3024SLi Yang AT803X_PHY_MMD3_WOL_CTRL, 4797beecaf7SLuo Jie AT803X_WOL_EN, 0); 4807beecaf7SLuo Jie if (ret) 4817beecaf7SLuo Jie return ret; 482*e58f3024SLi Yang } 4837beecaf7SLuo Jie /* Disable WOL interrupt */ 4842d4284e8SLuo Jie ret = phy_modify(phydev, AT803X_INTR_ENABLE, AT803X_INTR_ENABLE_WOL, 0); 485ea13c9eeSMugunthan V N if (ret) 486ea13c9eeSMugunthan V N return ret; 487ea13c9eeSMugunthan V N } 488ea13c9eeSMugunthan V N 4897beecaf7SLuo Jie /* Clear WOL status */ 4907beecaf7SLuo Jie ret = phy_read(phydev, AT803X_INTR_STATUS); 4917beecaf7SLuo Jie if (ret < 0) 492ea13c9eeSMugunthan V N return ret; 4937beecaf7SLuo Jie 4947beecaf7SLuo Jie /* Check if there are other interrupts except for WOL triggered when PHY is 4957beecaf7SLuo Jie * in interrupt mode, only the interrupts enabled by AT803X_INTR_ENABLE can 4967beecaf7SLuo Jie * be passed up to the interrupt PIN. 4977beecaf7SLuo Jie */ 4987beecaf7SLuo Jie irq_enabled = phy_read(phydev, AT803X_INTR_ENABLE); 4997beecaf7SLuo Jie if (irq_enabled < 0) 5007beecaf7SLuo Jie return irq_enabled; 5017beecaf7SLuo Jie 5027beecaf7SLuo Jie irq_enabled &= ~AT803X_INTR_ENABLE_WOL; 5037beecaf7SLuo Jie if (ret & irq_enabled && !phy_polling_mode(phydev)) 5047beecaf7SLuo Jie phy_trigger_machine(phydev); 5057beecaf7SLuo Jie 5067beecaf7SLuo Jie return 0; 507ea13c9eeSMugunthan V N } 508ea13c9eeSMugunthan V N 509ea13c9eeSMugunthan V N static void at803x_get_wol(struct phy_device *phydev, 510ea13c9eeSMugunthan V N struct ethtool_wolinfo *wol) 511ea13c9eeSMugunthan V N { 512911e3a46SJiapeng Chong int value; 513ea13c9eeSMugunthan V N 514ea13c9eeSMugunthan V N wol->supported = WAKE_MAGIC; 515ea13c9eeSMugunthan V N wol->wolopts = 0; 516ea13c9eeSMugunthan V N 517*e58f3024SLi Yang value = phy_read(phydev, AT803X_INTR_ENABLE); 5187beecaf7SLuo Jie if (value < 0) 5197beecaf7SLuo Jie return; 5207beecaf7SLuo Jie 521*e58f3024SLi Yang if (value & AT803X_INTR_ENABLE_WOL) 522ea13c9eeSMugunthan V N wol->wolopts |= WAKE_MAGIC; 5230ca7111aSMatus Ujhelyi } 5240ca7111aSMatus Ujhelyi 525272833b9SAnsuel Smith static int at803x_get_sset_count(struct phy_device *phydev) 526272833b9SAnsuel Smith { 527272833b9SAnsuel Smith return ARRAY_SIZE(at803x_hw_stats); 528272833b9SAnsuel Smith } 529272833b9SAnsuel Smith 530272833b9SAnsuel Smith static void at803x_get_strings(struct phy_device *phydev, u8 *data) 531272833b9SAnsuel Smith { 532272833b9SAnsuel Smith int i; 533272833b9SAnsuel Smith 534272833b9SAnsuel Smith for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) { 535272833b9SAnsuel Smith strscpy(data + i * ETH_GSTRING_LEN, 536272833b9SAnsuel Smith at803x_hw_stats[i].string, ETH_GSTRING_LEN); 537272833b9SAnsuel Smith } 538272833b9SAnsuel Smith } 539272833b9SAnsuel Smith 540272833b9SAnsuel Smith static u64 at803x_get_stat(struct phy_device *phydev, int i) 541272833b9SAnsuel Smith { 542272833b9SAnsuel Smith struct at803x_hw_stat stat = at803x_hw_stats[i]; 543272833b9SAnsuel Smith struct at803x_priv *priv = phydev->priv; 544272833b9SAnsuel Smith int val; 545272833b9SAnsuel Smith u64 ret; 546272833b9SAnsuel Smith 547272833b9SAnsuel Smith if (stat.access_type == MMD) 548272833b9SAnsuel Smith val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg); 549272833b9SAnsuel Smith else 550272833b9SAnsuel Smith val = phy_read(phydev, stat.reg); 551272833b9SAnsuel Smith 552272833b9SAnsuel Smith if (val < 0) { 553272833b9SAnsuel Smith ret = U64_MAX; 554272833b9SAnsuel Smith } else { 555272833b9SAnsuel Smith val = val & stat.mask; 556272833b9SAnsuel Smith priv->stats[i] += val; 557272833b9SAnsuel Smith ret = priv->stats[i]; 558272833b9SAnsuel Smith } 559272833b9SAnsuel Smith 560272833b9SAnsuel Smith return ret; 561272833b9SAnsuel Smith } 562272833b9SAnsuel Smith 563272833b9SAnsuel Smith static void at803x_get_stats(struct phy_device *phydev, 564272833b9SAnsuel Smith struct ethtool_stats *stats, u64 *data) 565272833b9SAnsuel Smith { 566272833b9SAnsuel Smith int i; 567272833b9SAnsuel Smith 568272833b9SAnsuel Smith for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) 569272833b9SAnsuel Smith data[i] = at803x_get_stat(phydev, i); 570272833b9SAnsuel Smith } 571272833b9SAnsuel Smith 5726229ed1fSDaniel Mack static int at803x_suspend(struct phy_device *phydev) 5736229ed1fSDaniel Mack { 5746229ed1fSDaniel Mack int value; 5756229ed1fSDaniel Mack int wol_enabled; 5766229ed1fSDaniel Mack 5776229ed1fSDaniel Mack value = phy_read(phydev, AT803X_INTR_ENABLE); 578e6e4a556SMartin Blumenstingl wol_enabled = value & AT803X_INTR_ENABLE_WOL; 5796229ed1fSDaniel Mack 5806229ed1fSDaniel Mack if (wol_enabled) 581fea23fb5SRussell King value = BMCR_ISOLATE; 5826229ed1fSDaniel Mack else 583fea23fb5SRussell King value = BMCR_PDOWN; 5846229ed1fSDaniel Mack 585fea23fb5SRussell King phy_modify(phydev, MII_BMCR, 0, value); 5866229ed1fSDaniel Mack 5876229ed1fSDaniel Mack return 0; 5886229ed1fSDaniel Mack } 5896229ed1fSDaniel Mack 5906229ed1fSDaniel Mack static int at803x_resume(struct phy_device *phydev) 5916229ed1fSDaniel Mack { 592f102852fSRussell King return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0); 5936229ed1fSDaniel Mack } 5946229ed1fSDaniel Mack 5952f664823SMichael Walle static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev, 5962f664823SMichael Walle unsigned int selector) 5972f664823SMichael Walle { 5982f664823SMichael Walle struct phy_device *phydev = rdev_get_drvdata(rdev); 5992f664823SMichael Walle 6002f664823SMichael Walle if (selector) 6012f664823SMichael Walle return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, 6022f664823SMichael Walle 0, AT803X_DEBUG_RGMII_1V8); 6032f664823SMichael Walle else 6042f664823SMichael Walle return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, 6052f664823SMichael Walle AT803X_DEBUG_RGMII_1V8, 0); 6062f664823SMichael Walle } 6072f664823SMichael Walle 6082f664823SMichael Walle static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev) 6092f664823SMichael Walle { 6102f664823SMichael Walle struct phy_device *phydev = rdev_get_drvdata(rdev); 6112f664823SMichael Walle int val; 6122f664823SMichael Walle 6132f664823SMichael Walle val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F); 6142f664823SMichael Walle if (val < 0) 6152f664823SMichael Walle return val; 6162f664823SMichael Walle 6172f664823SMichael Walle return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0; 6182f664823SMichael Walle } 6192f664823SMichael Walle 6203faaf539SRikard Falkeborn static const struct regulator_ops vddio_regulator_ops = { 6212f664823SMichael Walle .list_voltage = regulator_list_voltage_table, 6222f664823SMichael Walle .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel, 6232f664823SMichael Walle .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel, 6242f664823SMichael Walle }; 6252f664823SMichael Walle 6262f664823SMichael Walle static const unsigned int vddio_voltage_table[] = { 6272f664823SMichael Walle 1500000, 6282f664823SMichael Walle 1800000, 6292f664823SMichael Walle }; 6302f664823SMichael Walle 6312f664823SMichael Walle static const struct regulator_desc vddio_desc = { 6322f664823SMichael Walle .name = "vddio", 6332f664823SMichael Walle .of_match = of_match_ptr("vddio-regulator"), 6342f664823SMichael Walle .n_voltages = ARRAY_SIZE(vddio_voltage_table), 6352f664823SMichael Walle .volt_table = vddio_voltage_table, 6362f664823SMichael Walle .ops = &vddio_regulator_ops, 6372f664823SMichael Walle .type = REGULATOR_VOLTAGE, 6382f664823SMichael Walle .owner = THIS_MODULE, 6392f664823SMichael Walle }; 6402f664823SMichael Walle 6413faaf539SRikard Falkeborn static const struct regulator_ops vddh_regulator_ops = { 6422f664823SMichael Walle }; 6432f664823SMichael Walle 6442f664823SMichael Walle static const struct regulator_desc vddh_desc = { 6452f664823SMichael Walle .name = "vddh", 6462f664823SMichael Walle .of_match = of_match_ptr("vddh-regulator"), 6472f664823SMichael Walle .n_voltages = 1, 6482f664823SMichael Walle .fixed_uV = 2500000, 6492f664823SMichael Walle .ops = &vddh_regulator_ops, 6502f664823SMichael Walle .type = REGULATOR_VOLTAGE, 6512f664823SMichael Walle .owner = THIS_MODULE, 6522f664823SMichael Walle }; 6532f664823SMichael Walle 6542f664823SMichael Walle static int at8031_register_regulators(struct phy_device *phydev) 6552f664823SMichael Walle { 6562f664823SMichael Walle struct at803x_priv *priv = phydev->priv; 6572f664823SMichael Walle struct device *dev = &phydev->mdio.dev; 6582f664823SMichael Walle struct regulator_config config = { }; 6592f664823SMichael Walle 6602f664823SMichael Walle config.dev = dev; 6612f664823SMichael Walle config.driver_data = phydev; 6622f664823SMichael Walle 6632f664823SMichael Walle priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config); 6642f664823SMichael Walle if (IS_ERR(priv->vddio_rdev)) { 6652f664823SMichael Walle phydev_err(phydev, "failed to register VDDIO regulator\n"); 6662f664823SMichael Walle return PTR_ERR(priv->vddio_rdev); 6672f664823SMichael Walle } 6682f664823SMichael Walle 6692f664823SMichael Walle priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config); 6702f664823SMichael Walle if (IS_ERR(priv->vddh_rdev)) { 6712f664823SMichael Walle phydev_err(phydev, "failed to register VDDH regulator\n"); 6722f664823SMichael Walle return PTR_ERR(priv->vddh_rdev); 6732f664823SMichael Walle } 6742f664823SMichael Walle 6752f664823SMichael Walle return 0; 6762f664823SMichael Walle } 6772f664823SMichael Walle 678dc4d5fccSRobert Hancock static int at803x_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) 679dc4d5fccSRobert Hancock { 680dc4d5fccSRobert Hancock struct phy_device *phydev = upstream; 681dc4d5fccSRobert Hancock __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support); 682dc4d5fccSRobert Hancock __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); 683fd580c98SRussell King DECLARE_PHY_INTERFACE_MASK(interfaces); 684dc4d5fccSRobert Hancock phy_interface_t iface; 685dc4d5fccSRobert Hancock 686dc4d5fccSRobert Hancock linkmode_zero(phy_support); 687dc4d5fccSRobert Hancock phylink_set(phy_support, 1000baseX_Full); 688dc4d5fccSRobert Hancock phylink_set(phy_support, 1000baseT_Full); 689dc4d5fccSRobert Hancock phylink_set(phy_support, Autoneg); 690dc4d5fccSRobert Hancock phylink_set(phy_support, Pause); 691dc4d5fccSRobert Hancock phylink_set(phy_support, Asym_Pause); 692dc4d5fccSRobert Hancock 693dc4d5fccSRobert Hancock linkmode_zero(sfp_support); 694fd580c98SRussell King sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces); 695dc4d5fccSRobert Hancock /* Some modules support 10G modes as well as others we support. 696dc4d5fccSRobert Hancock * Mask out non-supported modes so the correct interface is picked. 697dc4d5fccSRobert Hancock */ 698dc4d5fccSRobert Hancock linkmode_and(sfp_support, phy_support, sfp_support); 699dc4d5fccSRobert Hancock 700dc4d5fccSRobert Hancock if (linkmode_empty(sfp_support)) { 701dc4d5fccSRobert Hancock dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n"); 702dc4d5fccSRobert Hancock return -EINVAL; 703dc4d5fccSRobert Hancock } 704dc4d5fccSRobert Hancock 705dc4d5fccSRobert Hancock iface = sfp_select_interface(phydev->sfp_bus, sfp_support); 706dc4d5fccSRobert Hancock 707dc4d5fccSRobert Hancock /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes 708dc4d5fccSRobert Hancock * interface for use with SFP modules. 709dc4d5fccSRobert Hancock * However, some copper modules detected as having a preferred SGMII 710dc4d5fccSRobert Hancock * interface do default to and function in 1000Base-X mode, so just 711dc4d5fccSRobert Hancock * print a warning and allow such modules, as they may have some chance 712dc4d5fccSRobert Hancock * of working. 713dc4d5fccSRobert Hancock */ 714dc4d5fccSRobert Hancock if (iface == PHY_INTERFACE_MODE_SGMII) 715dc4d5fccSRobert Hancock dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n"); 716dc4d5fccSRobert Hancock else if (iface != PHY_INTERFACE_MODE_1000BASEX) 717dc4d5fccSRobert Hancock return -EINVAL; 718dc4d5fccSRobert Hancock 719dc4d5fccSRobert Hancock return 0; 720dc4d5fccSRobert Hancock } 721dc4d5fccSRobert Hancock 722dc4d5fccSRobert Hancock static const struct sfp_upstream_ops at803x_sfp_ops = { 723dc4d5fccSRobert Hancock .attach = phy_sfp_attach, 724dc4d5fccSRobert Hancock .detach = phy_sfp_detach, 725dc4d5fccSRobert Hancock .module_insert = at803x_sfp_insert, 726dc4d5fccSRobert Hancock }; 727dc4d5fccSRobert Hancock 7282f664823SMichael Walle static int at803x_parse_dt(struct phy_device *phydev) 7292f664823SMichael Walle { 7302f664823SMichael Walle struct device_node *node = phydev->mdio.dev.of_node; 7312f664823SMichael Walle struct at803x_priv *priv = phydev->priv; 732390b4cadSRussell King u32 freq, strength, tw; 7333f2edd30SAndrew Lunn unsigned int sel; 7342f664823SMichael Walle int ret; 7352f664823SMichael Walle 7362f664823SMichael Walle if (!IS_ENABLED(CONFIG_OF_MDIO)) 7372f664823SMichael Walle return 0; 7382f664823SMichael Walle 739390b4cadSRussell King if (of_property_read_bool(node, "qca,disable-smarteee")) 740390b4cadSRussell King priv->flags |= AT803X_DISABLE_SMARTEEE; 741390b4cadSRussell King 7429ecf0401SWei Fang if (of_property_read_bool(node, "qca,disable-hibernation-mode")) 7439ecf0401SWei Fang priv->flags |= AT803X_DISABLE_HIBERNATION_MODE; 7449ecf0401SWei Fang 745390b4cadSRussell King if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) { 746390b4cadSRussell King if (!tw || tw > 255) { 747390b4cadSRussell King phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n"); 748390b4cadSRussell King return -EINVAL; 749390b4cadSRussell King } 750390b4cadSRussell King priv->smarteee_lpi_tw_1g = tw; 751390b4cadSRussell King } 752390b4cadSRussell King 753390b4cadSRussell King if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) { 754390b4cadSRussell King if (!tw || tw > 255) { 755390b4cadSRussell King phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n"); 756390b4cadSRussell King return -EINVAL; 757390b4cadSRussell King } 758390b4cadSRussell King priv->smarteee_lpi_tw_100m = tw; 759390b4cadSRussell King } 760390b4cadSRussell King 7612f664823SMichael Walle ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq); 7622f664823SMichael Walle if (!ret) { 7632f664823SMichael Walle switch (freq) { 7642f664823SMichael Walle case 25000000: 7652f664823SMichael Walle sel = AT803X_CLK_OUT_25MHZ_XTAL; 7662f664823SMichael Walle break; 7672f664823SMichael Walle case 50000000: 7682f664823SMichael Walle sel = AT803X_CLK_OUT_50MHZ_PLL; 7692f664823SMichael Walle break; 7702f664823SMichael Walle case 62500000: 7712f664823SMichael Walle sel = AT803X_CLK_OUT_62_5MHZ_PLL; 7722f664823SMichael Walle break; 7732f664823SMichael Walle case 125000000: 7742f664823SMichael Walle sel = AT803X_CLK_OUT_125MHZ_PLL; 7752f664823SMichael Walle break; 7762f664823SMichael Walle default: 7772f664823SMichael Walle phydev_err(phydev, "invalid qca,clk-out-frequency\n"); 7782f664823SMichael Walle return -EINVAL; 7792f664823SMichael Walle } 7802f664823SMichael Walle 7813f2edd30SAndrew Lunn priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel); 7823f2edd30SAndrew Lunn priv->clk_25m_mask |= AT803X_CLK_OUT_MASK; 7832f664823SMichael Walle 7842f664823SMichael Walle /* Fixup for the AR8030/AR8035. This chip has another mask and 7852f664823SMichael Walle * doesn't support the DSP reference. Eg. the lowest bit of the 7862f664823SMichael Walle * mask. The upper two bits select the same frequencies. Mask 7872f664823SMichael Walle * the lowest bit here. 7882f664823SMichael Walle * 7892f664823SMichael Walle * Warning: 7902f664823SMichael Walle * There was no datasheet for the AR8030 available so this is 7912f664823SMichael Walle * just a guess. But the AR8035 is listed as pin compatible 7922f664823SMichael Walle * to the AR8030 so there might be a good chance it works on 7932f664823SMichael Walle * the AR8030 too. 7942f664823SMichael Walle */ 7958887ca54SRussell King if (phydev->drv->phy_id == ATH8030_PHY_ID || 7968887ca54SRussell King phydev->drv->phy_id == ATH8035_PHY_ID) { 797b1f4c209SOleksij Rempel priv->clk_25m_reg &= AT8035_CLK_OUT_MASK; 798b1f4c209SOleksij Rempel priv->clk_25m_mask &= AT8035_CLK_OUT_MASK; 7992f664823SMichael Walle } 8002f664823SMichael Walle } 8012f664823SMichael Walle 8022f664823SMichael Walle ret = of_property_read_u32(node, "qca,clk-out-strength", &strength); 8032f664823SMichael Walle if (!ret) { 8042f664823SMichael Walle priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK; 8052f664823SMichael Walle switch (strength) { 8062f664823SMichael Walle case AR803X_STRENGTH_FULL: 8072f664823SMichael Walle priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL; 8082f664823SMichael Walle break; 8092f664823SMichael Walle case AR803X_STRENGTH_HALF: 8102f664823SMichael Walle priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF; 8112f664823SMichael Walle break; 8122f664823SMichael Walle case AR803X_STRENGTH_QUARTER: 8132f664823SMichael Walle priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER; 8142f664823SMichael Walle break; 8152f664823SMichael Walle default: 8162f664823SMichael Walle phydev_err(phydev, "invalid qca,clk-out-strength\n"); 8172f664823SMichael Walle return -EINVAL; 8182f664823SMichael Walle } 8192f664823SMichael Walle } 8202f664823SMichael Walle 821428061f7SMichael Walle /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping 822428061f7SMichael Walle * options. 823428061f7SMichael Walle */ 8248887ca54SRussell King if (phydev->drv->phy_id == ATH8031_PHY_ID) { 8252f664823SMichael Walle if (of_property_read_bool(node, "qca,keep-pll-enabled")) 8262f664823SMichael Walle priv->flags |= AT803X_KEEP_PLL_ENABLED; 8272f664823SMichael Walle 8282f664823SMichael Walle ret = at8031_register_regulators(phydev); 8292f664823SMichael Walle if (ret < 0) 8302f664823SMichael Walle return ret; 8312f664823SMichael Walle 832988e8d90SChristophe JAILLET ret = devm_regulator_get_enable_optional(&phydev->mdio.dev, 8332f664823SMichael Walle "vddio"); 834988e8d90SChristophe JAILLET if (ret) { 8352f664823SMichael Walle phydev_err(phydev, "failed to get VDDIO regulator\n"); 836988e8d90SChristophe JAILLET return ret; 8372f664823SMichael Walle } 838dc4d5fccSRobert Hancock 839dc4d5fccSRobert Hancock /* Only AR8031/8033 support 1000Base-X for SFP modules */ 840dc4d5fccSRobert Hancock ret = phy_sfp_probe(phydev, &at803x_sfp_ops); 841dc4d5fccSRobert Hancock if (ret < 0) 842dc4d5fccSRobert Hancock return ret; 8432f664823SMichael Walle } 8442f664823SMichael Walle 8452f664823SMichael Walle return 0; 8462f664823SMichael Walle } 8472f664823SMichael Walle 8482f664823SMichael Walle static int at803x_probe(struct phy_device *phydev) 8492f664823SMichael Walle { 8502f664823SMichael Walle struct device *dev = &phydev->mdio.dev; 8512f664823SMichael Walle struct at803x_priv *priv; 852c329e5afSDavid Bauer int ret; 8532f664823SMichael Walle 8542f664823SMichael Walle priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 8552f664823SMichael Walle if (!priv) 8562f664823SMichael Walle return -ENOMEM; 8572f664823SMichael Walle 8582f664823SMichael Walle phydev->priv = priv; 8592f664823SMichael Walle 860c329e5afSDavid Bauer ret = at803x_parse_dt(phydev); 861c329e5afSDavid Bauer if (ret) 862c329e5afSDavid Bauer return ret; 863c329e5afSDavid Bauer 8643265f421SRobert Hancock if (phydev->drv->phy_id == ATH8031_PHY_ID) { 8653265f421SRobert Hancock int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG); 8663265f421SRobert Hancock int mode_cfg; 8673265f421SRobert Hancock 868988e8d90SChristophe JAILLET if (ccr < 0) 869988e8d90SChristophe JAILLET return ccr; 8703265f421SRobert Hancock mode_cfg = ccr & AT803X_MODE_CFG_MASK; 8713265f421SRobert Hancock 8723265f421SRobert Hancock switch (mode_cfg) { 8733265f421SRobert Hancock case AT803X_MODE_CFG_BX1000_RGMII_50OHM: 8743265f421SRobert Hancock case AT803X_MODE_CFG_BX1000_RGMII_75OHM: 8753265f421SRobert Hancock priv->is_1000basex = true; 8763265f421SRobert Hancock fallthrough; 8773265f421SRobert Hancock case AT803X_MODE_CFG_FX100_RGMII_50OHM: 8783265f421SRobert Hancock case AT803X_MODE_CFG_FX100_RGMII_75OHM: 8793265f421SRobert Hancock priv->is_fiber = true; 8803265f421SRobert Hancock break; 8813265f421SRobert Hancock } 882d7cd5e06SViorel Suman 883*e58f3024SLi Yang /* Disable WoL in 1588 register which is enabled 884*e58f3024SLi Yang * by default 885*e58f3024SLi Yang */ 886*e58f3024SLi Yang ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, 887*e58f3024SLi Yang AT803X_PHY_MMD3_WOL_CTRL, 888*e58f3024SLi Yang AT803X_WOL_EN, 0); 889*e58f3024SLi Yang if (ret) 890988e8d90SChristophe JAILLET return ret; 891d7cd5e06SViorel Suman } 8923265f421SRobert Hancock 8938f7e8762SMichael Walle return 0; 8942318ca8aSMichael Walle } 8952318ca8aSMichael Walle 896b856150cSDavid Bauer static int at803x_get_features(struct phy_device *phydev) 897b856150cSDavid Bauer { 8983265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 899b856150cSDavid Bauer int err; 900b856150cSDavid Bauer 901b856150cSDavid Bauer err = genphy_read_abilities(phydev); 902b856150cSDavid Bauer if (err) 903b856150cSDavid Bauer return err; 904b856150cSDavid Bauer 905765c22aaSLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) { 906765c22aaSLuo Jie err = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_NG_EXTABLE); 907765c22aaSLuo Jie if (err < 0) 908765c22aaSLuo Jie return err; 909765c22aaSLuo Jie 910765c22aaSLuo Jie linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported, 911765c22aaSLuo Jie err & MDIO_PMA_NG_EXTABLE_2_5GBT); 912765c22aaSLuo Jie } 913765c22aaSLuo Jie 914f5621a01SVladimir Oltean if (phydev->drv->phy_id != ATH8031_PHY_ID) 915b856150cSDavid Bauer return 0; 916b856150cSDavid Bauer 917b856150cSDavid Bauer /* AR8031/AR8033 have different status registers 918b856150cSDavid Bauer * for copper and fiber operation. However, the 919b856150cSDavid Bauer * extended status register is the same for both 920b856150cSDavid Bauer * operation modes. 921b856150cSDavid Bauer * 922b856150cSDavid Bauer * As a result of that, ESTATUS_1000_XFULL is set 923b856150cSDavid Bauer * to 1 even when operating in copper TP mode. 924b856150cSDavid Bauer * 9253265f421SRobert Hancock * Remove this mode from the supported link modes 9263265f421SRobert Hancock * when not operating in 1000BaseX mode. 927b856150cSDavid Bauer */ 9283265f421SRobert Hancock if (!priv->is_1000basex) 929b856150cSDavid Bauer linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, 930b856150cSDavid Bauer phydev->supported); 9313265f421SRobert Hancock 932b856150cSDavid Bauer return 0; 933b856150cSDavid Bauer } 934b856150cSDavid Bauer 935390b4cadSRussell King static int at803x_smarteee_config(struct phy_device *phydev) 936390b4cadSRussell King { 937390b4cadSRussell King struct at803x_priv *priv = phydev->priv; 938390b4cadSRussell King u16 mask = 0, val = 0; 939390b4cadSRussell King int ret; 940390b4cadSRussell King 941390b4cadSRussell King if (priv->flags & AT803X_DISABLE_SMARTEEE) 942390b4cadSRussell King return phy_modify_mmd(phydev, MDIO_MMD_PCS, 943390b4cadSRussell King AT803X_MMD3_SMARTEEE_CTL3, 944390b4cadSRussell King AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0); 945390b4cadSRussell King 946390b4cadSRussell King if (priv->smarteee_lpi_tw_1g) { 947390b4cadSRussell King mask |= 0xff00; 948390b4cadSRussell King val |= priv->smarteee_lpi_tw_1g << 8; 949390b4cadSRussell King } 950390b4cadSRussell King if (priv->smarteee_lpi_tw_100m) { 951390b4cadSRussell King mask |= 0x00ff; 952390b4cadSRussell King val |= priv->smarteee_lpi_tw_100m; 953390b4cadSRussell King } 954390b4cadSRussell King if (!mask) 955390b4cadSRussell King return 0; 956390b4cadSRussell King 957390b4cadSRussell King ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1, 958390b4cadSRussell King mask, val); 959390b4cadSRussell King if (ret) 960390b4cadSRussell King return ret; 961390b4cadSRussell King 962390b4cadSRussell King return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3, 963390b4cadSRussell King AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 964390b4cadSRussell King AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); 965390b4cadSRussell King } 966390b4cadSRussell King 9672f664823SMichael Walle static int at803x_clk_out_config(struct phy_device *phydev) 9682f664823SMichael Walle { 9692f664823SMichael Walle struct at803x_priv *priv = phydev->priv; 9702f664823SMichael Walle 9712f664823SMichael Walle if (!priv->clk_25m_mask) 9722f664823SMichael Walle return 0; 9732f664823SMichael Walle 974a45c1c10SRussell King return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M, 975a45c1c10SRussell King priv->clk_25m_mask, priv->clk_25m_reg); 9762f664823SMichael Walle } 9772f664823SMichael Walle 9782f664823SMichael Walle static int at8031_pll_config(struct phy_device *phydev) 9792f664823SMichael Walle { 9802f664823SMichael Walle struct at803x_priv *priv = phydev->priv; 9812f664823SMichael Walle 9822f664823SMichael Walle /* The default after hardware reset is PLL OFF. After a soft reset, the 9832f664823SMichael Walle * values are retained. 9842f664823SMichael Walle */ 9852f664823SMichael Walle if (priv->flags & AT803X_KEEP_PLL_ENABLED) 9862f664823SMichael Walle return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, 9872f664823SMichael Walle 0, AT803X_DEBUG_PLL_ON); 9882f664823SMichael Walle else 9892f664823SMichael Walle return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, 9902f664823SMichael Walle AT803X_DEBUG_PLL_ON, 0); 9912f664823SMichael Walle } 9922f664823SMichael Walle 9939ecf0401SWei Fang static int at803x_hibernation_mode_config(struct phy_device *phydev) 9949ecf0401SWei Fang { 9959ecf0401SWei Fang struct at803x_priv *priv = phydev->priv; 9969ecf0401SWei Fang 9979ecf0401SWei Fang /* The default after hardware reset is hibernation mode enabled. After 9989ecf0401SWei Fang * software reset, the value is retained. 9999ecf0401SWei Fang */ 10009ecf0401SWei Fang if (!(priv->flags & AT803X_DISABLE_HIBERNATION_MODE)) 10019ecf0401SWei Fang return 0; 10029ecf0401SWei Fang 10039ecf0401SWei Fang return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL, 10049ecf0401SWei Fang AT803X_DEBUG_HIB_CTRL_PS_HIB_EN, 0); 10059ecf0401SWei Fang } 10069ecf0401SWei Fang 10070ca7111aSMatus Ujhelyi static int at803x_config_init(struct phy_device *phydev) 10080ca7111aSMatus Ujhelyi { 10093265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 10101ca6d1b1SMugunthan V N int ret; 10110ca7111aSMatus Ujhelyi 10124f3a00c7SRobert Hancock if (phydev->drv->phy_id == ATH8031_PHY_ID) { 10134f3a00c7SRobert Hancock /* Some bootloaders leave the fiber page selected. 10143265f421SRobert Hancock * Switch to the appropriate page (fiber or copper), as otherwise we 10153265f421SRobert Hancock * read the PHY capabilities from the wrong page. 10164f3a00c7SRobert Hancock */ 10174f3a00c7SRobert Hancock phy_lock_mdio_bus(phydev); 10183265f421SRobert Hancock ret = at803x_write_page(phydev, 10193265f421SRobert Hancock priv->is_fiber ? AT803X_PAGE_FIBER : 10203265f421SRobert Hancock AT803X_PAGE_COPPER); 10214f3a00c7SRobert Hancock phy_unlock_mdio_bus(phydev); 10224f3a00c7SRobert Hancock if (ret) 10234f3a00c7SRobert Hancock return ret; 10244f3a00c7SRobert Hancock 10254f3a00c7SRobert Hancock ret = at8031_pll_config(phydev); 10264f3a00c7SRobert Hancock if (ret < 0) 10274f3a00c7SRobert Hancock return ret; 10284f3a00c7SRobert Hancock } 10294f3a00c7SRobert Hancock 10306d4cd041SVinod Koul /* The RX and TX delay default is: 10316d4cd041SVinod Koul * after HW reset: RX delay enabled and TX delay disabled 10326d4cd041SVinod Koul * after SW reset: RX delay enabled, while TX delay retains the 10336d4cd041SVinod Koul * value before reset. 10346d4cd041SVinod Koul */ 1035bb0ce4c1SAndré Draszik if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || 1036bb0ce4c1SAndré Draszik phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) 1037bb0ce4c1SAndré Draszik ret = at803x_enable_rx_delay(phydev); 1038bb0ce4c1SAndré Draszik else 1039cd28d1d6SVinod Koul ret = at803x_disable_rx_delay(phydev); 10402e5f9f28SMartin Blumenstingl if (ret < 0) 10411ca6d1b1SMugunthan V N return ret; 10426d4cd041SVinod Koul 10436d4cd041SVinod Koul if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || 1044bb0ce4c1SAndré Draszik phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 10456d4cd041SVinod Koul ret = at803x_enable_tx_delay(phydev); 1046bb0ce4c1SAndré Draszik else 1047bb0ce4c1SAndré Draszik ret = at803x_disable_tx_delay(phydev); 10482f664823SMichael Walle if (ret < 0) 10496d4cd041SVinod Koul return ret; 10502f664823SMichael Walle 1051390b4cadSRussell King ret = at803x_smarteee_config(phydev); 1052390b4cadSRussell King if (ret < 0) 1053390b4cadSRussell King return ret; 1054390b4cadSRussell King 10552f664823SMichael Walle ret = at803x_clk_out_config(phydev); 10562f664823SMichael Walle if (ret < 0) 10572f664823SMichael Walle return ret; 10582f664823SMichael Walle 10599ecf0401SWei Fang ret = at803x_hibernation_mode_config(phydev); 10609ecf0401SWei Fang if (ret < 0) 10619ecf0401SWei Fang return ret; 10629ecf0401SWei Fang 10633c51fa5dSRussell King /* Ar803x extended next page bit is enabled by default. Cisco 10643c51fa5dSRussell King * multigig switches read this bit and attempt to negotiate 10Gbps 10653c51fa5dSRussell King * rates even if the next page bit is disabled. This is incorrect 10663c51fa5dSRussell King * behaviour but we still need to accommodate it. XNP is only needed 10673c51fa5dSRussell King * for 10Gbps support, so disable XNP. 10683c51fa5dSRussell King */ 10693c51fa5dSRussell King return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0); 10700ca7111aSMatus Ujhelyi } 10710ca7111aSMatus Ujhelyi 107277a99394SZhao Qiang static int at803x_ack_interrupt(struct phy_device *phydev) 107377a99394SZhao Qiang { 107477a99394SZhao Qiang int err; 107577a99394SZhao Qiang 1076a46bd63bSMartin Blumenstingl err = phy_read(phydev, AT803X_INTR_STATUS); 107777a99394SZhao Qiang 107877a99394SZhao Qiang return (err < 0) ? err : 0; 107977a99394SZhao Qiang } 108077a99394SZhao Qiang 108177a99394SZhao Qiang static int at803x_config_intr(struct phy_device *phydev) 108277a99394SZhao Qiang { 10833265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 108477a99394SZhao Qiang int err; 108577a99394SZhao Qiang int value; 108677a99394SZhao Qiang 1087a46bd63bSMartin Blumenstingl value = phy_read(phydev, AT803X_INTR_ENABLE); 108877a99394SZhao Qiang 1089e6e4a556SMartin Blumenstingl if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { 1090a3417885SIoana Ciornei /* Clear any pending interrupts */ 1091a3417885SIoana Ciornei err = at803x_ack_interrupt(phydev); 1092a3417885SIoana Ciornei if (err) 1093a3417885SIoana Ciornei return err; 1094a3417885SIoana Ciornei 1095e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_AUTONEG_ERR; 1096e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_SPEED_CHANGED; 1097e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED; 1098e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_LINK_FAIL; 1099e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_LINK_SUCCESS; 11003265f421SRobert Hancock if (priv->is_fiber) { 11013265f421SRobert Hancock value |= AT803X_INTR_ENABLE_LINK_FAIL_BX; 11023265f421SRobert Hancock value |= AT803X_INTR_ENABLE_LINK_SUCCESS_BX; 11033265f421SRobert Hancock } 1104e6e4a556SMartin Blumenstingl 1105e6e4a556SMartin Blumenstingl err = phy_write(phydev, AT803X_INTR_ENABLE, value); 1106a3417885SIoana Ciornei } else { 1107a46bd63bSMartin Blumenstingl err = phy_write(phydev, AT803X_INTR_ENABLE, 0); 1108a3417885SIoana Ciornei if (err) 1109a3417885SIoana Ciornei return err; 1110a3417885SIoana Ciornei 1111a3417885SIoana Ciornei /* Clear any pending interrupts */ 1112a3417885SIoana Ciornei err = at803x_ack_interrupt(phydev); 1113a3417885SIoana Ciornei } 111477a99394SZhao Qiang 111577a99394SZhao Qiang return err; 111677a99394SZhao Qiang } 111777a99394SZhao Qiang 111829773097SIoana Ciornei static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev) 111929773097SIoana Ciornei { 112029773097SIoana Ciornei int irq_status, int_enabled; 112129773097SIoana Ciornei 112229773097SIoana Ciornei irq_status = phy_read(phydev, AT803X_INTR_STATUS); 112329773097SIoana Ciornei if (irq_status < 0) { 112429773097SIoana Ciornei phy_error(phydev); 112529773097SIoana Ciornei return IRQ_NONE; 112629773097SIoana Ciornei } 112729773097SIoana Ciornei 112829773097SIoana Ciornei /* Read the current enabled interrupts */ 112929773097SIoana Ciornei int_enabled = phy_read(phydev, AT803X_INTR_ENABLE); 113029773097SIoana Ciornei if (int_enabled < 0) { 113129773097SIoana Ciornei phy_error(phydev); 113229773097SIoana Ciornei return IRQ_NONE; 113329773097SIoana Ciornei } 113429773097SIoana Ciornei 113529773097SIoana Ciornei /* See if this was one of our enabled interrupts */ 113629773097SIoana Ciornei if (!(irq_status & int_enabled)) 113729773097SIoana Ciornei return IRQ_NONE; 113829773097SIoana Ciornei 113929773097SIoana Ciornei phy_trigger_machine(phydev); 114029773097SIoana Ciornei 114129773097SIoana Ciornei return IRQ_HANDLED; 114229773097SIoana Ciornei } 114329773097SIoana Ciornei 114413a56b44SDaniel Mack static void at803x_link_change_notify(struct phy_device *phydev) 114513a56b44SDaniel Mack { 114613a56b44SDaniel Mack /* 114713a56b44SDaniel Mack * Conduct a hardware reset for AT8030 every time a link loss is 114813a56b44SDaniel Mack * signalled. This is necessary to circumvent a hardware bug that 114913a56b44SDaniel Mack * occurs when the cable is unplugged while TX packets are pending 115013a56b44SDaniel Mack * in the FIFO. In such cases, the FIFO enters an error mode it 115113a56b44SDaniel Mack * cannot recover from by software. 115213a56b44SDaniel Mack */ 11536110ed2dSDavid Bauer if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) { 115413a56b44SDaniel Mack struct at803x_context context; 115513a56b44SDaniel Mack 115613a56b44SDaniel Mack at803x_context_save(phydev, &context); 115713a56b44SDaniel Mack 1158bafbdd52SSergei Shtylyov phy_device_reset(phydev, 1); 115913a56b44SDaniel Mack msleep(1); 1160bafbdd52SSergei Shtylyov phy_device_reset(phydev, 0); 1161d57019d1SSergei Shtylyov msleep(1); 116213a56b44SDaniel Mack 116313a56b44SDaniel Mack at803x_context_restore(phydev, &context); 116413a56b44SDaniel Mack 11655c5f626bSHeiner Kallweit phydev_dbg(phydev, "%s(): phy was reset\n", __func__); 116613a56b44SDaniel Mack } 116713a56b44SDaniel Mack } 116813a56b44SDaniel Mack 116979c7bc05SLuo Jie static int at803x_read_specific_status(struct phy_device *phydev) 117006d5f344SRussell King { 117179c7bc05SLuo Jie int ss; 117206d5f344SRussell King 117306d5f344SRussell King /* Read the AT8035 PHY-Specific Status register, which indicates the 117406d5f344SRussell King * speed and duplex that the PHY is actually using, irrespective of 117506d5f344SRussell King * whether we are in autoneg mode or not. 117606d5f344SRussell King */ 117706d5f344SRussell King ss = phy_read(phydev, AT803X_SPECIFIC_STATUS); 117806d5f344SRussell King if (ss < 0) 117906d5f344SRussell King return ss; 118006d5f344SRussell King 118106d5f344SRussell King if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) { 118279c7bc05SLuo Jie int sfc, speed; 11837dce80c2SOleksij Rempel 11847dce80c2SOleksij Rempel sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL); 11857dce80c2SOleksij Rempel if (sfc < 0) 11867dce80c2SOleksij Rempel return sfc; 11877dce80c2SOleksij Rempel 118879c7bc05SLuo Jie /* qca8081 takes the different bits for speed value from at803x */ 118979c7bc05SLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) 119079c7bc05SLuo Jie speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss); 119179c7bc05SLuo Jie else 119279c7bc05SLuo Jie speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss); 119379c7bc05SLuo Jie 119479c7bc05SLuo Jie switch (speed) { 119506d5f344SRussell King case AT803X_SS_SPEED_10: 119606d5f344SRussell King phydev->speed = SPEED_10; 119706d5f344SRussell King break; 119806d5f344SRussell King case AT803X_SS_SPEED_100: 119906d5f344SRussell King phydev->speed = SPEED_100; 120006d5f344SRussell King break; 120106d5f344SRussell King case AT803X_SS_SPEED_1000: 120206d5f344SRussell King phydev->speed = SPEED_1000; 120306d5f344SRussell King break; 120479c7bc05SLuo Jie case QCA808X_SS_SPEED_2500: 120579c7bc05SLuo Jie phydev->speed = SPEED_2500; 120679c7bc05SLuo Jie break; 120706d5f344SRussell King } 120806d5f344SRussell King if (ss & AT803X_SS_DUPLEX) 120906d5f344SRussell King phydev->duplex = DUPLEX_FULL; 121006d5f344SRussell King else 121106d5f344SRussell King phydev->duplex = DUPLEX_HALF; 12127dce80c2SOleksij Rempel 121306d5f344SRussell King if (ss & AT803X_SS_MDIX) 121406d5f344SRussell King phydev->mdix = ETH_TP_MDI_X; 121506d5f344SRussell King else 121606d5f344SRussell King phydev->mdix = ETH_TP_MDI; 12177dce80c2SOleksij Rempel 12187dce80c2SOleksij Rempel switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) { 12197dce80c2SOleksij Rempel case AT803X_SFC_MANUAL_MDI: 12207dce80c2SOleksij Rempel phydev->mdix_ctrl = ETH_TP_MDI; 12217dce80c2SOleksij Rempel break; 12227dce80c2SOleksij Rempel case AT803X_SFC_MANUAL_MDIX: 12237dce80c2SOleksij Rempel phydev->mdix_ctrl = ETH_TP_MDI_X; 12247dce80c2SOleksij Rempel break; 12257dce80c2SOleksij Rempel case AT803X_SFC_AUTOMATIC_CROSSOVER: 12267dce80c2SOleksij Rempel phydev->mdix_ctrl = ETH_TP_MDI_AUTO; 12277dce80c2SOleksij Rempel break; 12287dce80c2SOleksij Rempel } 122906d5f344SRussell King } 123006d5f344SRussell King 123179c7bc05SLuo Jie return 0; 123279c7bc05SLuo Jie } 123379c7bc05SLuo Jie 123479c7bc05SLuo Jie static int at803x_read_status(struct phy_device *phydev) 123579c7bc05SLuo Jie { 12363265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 123779c7bc05SLuo Jie int err, old_link = phydev->link; 123879c7bc05SLuo Jie 12393265f421SRobert Hancock if (priv->is_1000basex) 12403265f421SRobert Hancock return genphy_c37_read_status(phydev); 12413265f421SRobert Hancock 124279c7bc05SLuo Jie /* Update the link, but return if there was an error */ 124379c7bc05SLuo Jie err = genphy_update_link(phydev); 124479c7bc05SLuo Jie if (err) 124579c7bc05SLuo Jie return err; 124679c7bc05SLuo Jie 124779c7bc05SLuo Jie /* why bother the PHY if nothing can have changed */ 124879c7bc05SLuo Jie if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) 124979c7bc05SLuo Jie return 0; 125079c7bc05SLuo Jie 125179c7bc05SLuo Jie phydev->speed = SPEED_UNKNOWN; 125279c7bc05SLuo Jie phydev->duplex = DUPLEX_UNKNOWN; 125379c7bc05SLuo Jie phydev->pause = 0; 125479c7bc05SLuo Jie phydev->asym_pause = 0; 125579c7bc05SLuo Jie 125679c7bc05SLuo Jie err = genphy_read_lpa(phydev); 125779c7bc05SLuo Jie if (err < 0) 125879c7bc05SLuo Jie return err; 125979c7bc05SLuo Jie 126079c7bc05SLuo Jie err = at803x_read_specific_status(phydev); 126179c7bc05SLuo Jie if (err < 0) 126279c7bc05SLuo Jie return err; 126379c7bc05SLuo Jie 126406d5f344SRussell King if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) 126506d5f344SRussell King phy_resolve_aneg_pause(phydev); 126606d5f344SRussell King 126706d5f344SRussell King return 0; 126806d5f344SRussell King } 126906d5f344SRussell King 12707dce80c2SOleksij Rempel static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl) 12717dce80c2SOleksij Rempel { 12727dce80c2SOleksij Rempel u16 val; 12737dce80c2SOleksij Rempel 12747dce80c2SOleksij Rempel switch (ctrl) { 12757dce80c2SOleksij Rempel case ETH_TP_MDI: 12767dce80c2SOleksij Rempel val = AT803X_SFC_MANUAL_MDI; 12777dce80c2SOleksij Rempel break; 12787dce80c2SOleksij Rempel case ETH_TP_MDI_X: 12797dce80c2SOleksij Rempel val = AT803X_SFC_MANUAL_MDIX; 12807dce80c2SOleksij Rempel break; 12817dce80c2SOleksij Rempel case ETH_TP_MDI_AUTO: 12827dce80c2SOleksij Rempel val = AT803X_SFC_AUTOMATIC_CROSSOVER; 12837dce80c2SOleksij Rempel break; 12847dce80c2SOleksij Rempel default: 12857dce80c2SOleksij Rempel return 0; 12867dce80c2SOleksij Rempel } 12877dce80c2SOleksij Rempel 12887dce80c2SOleksij Rempel return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL, 12897dce80c2SOleksij Rempel AT803X_SFC_MDI_CROSSOVER_MODE_M, 12907dce80c2SOleksij Rempel FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val)); 12917dce80c2SOleksij Rempel } 12927dce80c2SOleksij Rempel 12937dce80c2SOleksij Rempel static int at803x_config_aneg(struct phy_device *phydev) 12947dce80c2SOleksij Rempel { 12953265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 12967dce80c2SOleksij Rempel int ret; 12977dce80c2SOleksij Rempel 12987dce80c2SOleksij Rempel ret = at803x_config_mdix(phydev, phydev->mdix_ctrl); 12997dce80c2SOleksij Rempel if (ret < 0) 13007dce80c2SOleksij Rempel return ret; 13017dce80c2SOleksij Rempel 13027dce80c2SOleksij Rempel /* Changes of the midx bits are disruptive to the normal operation; 13037dce80c2SOleksij Rempel * therefore any changes to these registers must be followed by a 13047dce80c2SOleksij Rempel * software reset to take effect. 13057dce80c2SOleksij Rempel */ 13067dce80c2SOleksij Rempel if (ret == 1) { 13077dce80c2SOleksij Rempel ret = genphy_soft_reset(phydev); 13087dce80c2SOleksij Rempel if (ret < 0) 13097dce80c2SOleksij Rempel return ret; 13107dce80c2SOleksij Rempel } 13117dce80c2SOleksij Rempel 13123265f421SRobert Hancock if (priv->is_1000basex) 13133265f421SRobert Hancock return genphy_c37_config_aneg(phydev); 13143265f421SRobert Hancock 1315f884d449SLuo Jie /* Do not restart auto-negotiation by setting ret to 0 defautly, 1316f884d449SLuo Jie * when calling __genphy_config_aneg later. 1317f884d449SLuo Jie */ 1318f884d449SLuo Jie ret = 0; 1319f884d449SLuo Jie 1320f884d449SLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) { 1321f884d449SLuo Jie int phy_ctrl = 0; 1322f884d449SLuo Jie 1323f884d449SLuo Jie /* The reg MII_BMCR also needs to be configured for force mode, the 1324f884d449SLuo Jie * genphy_config_aneg is also needed. 1325f884d449SLuo Jie */ 1326f884d449SLuo Jie if (phydev->autoneg == AUTONEG_DISABLE) 1327f884d449SLuo Jie genphy_c45_pma_setup_forced(phydev); 1328f884d449SLuo Jie 1329f884d449SLuo Jie if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising)) 1330f884d449SLuo Jie phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G; 1331f884d449SLuo Jie 1332f884d449SLuo Jie ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL, 1333f884d449SLuo Jie MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl); 1334f884d449SLuo Jie if (ret < 0) 1335f884d449SLuo Jie return ret; 1336f884d449SLuo Jie } 1337f884d449SLuo Jie 1338f884d449SLuo Jie return __genphy_config_aneg(phydev, ret); 13397dce80c2SOleksij Rempel } 13407dce80c2SOleksij Rempel 1341cde0f4f8SMichael Walle static int at803x_get_downshift(struct phy_device *phydev, u8 *d) 1342cde0f4f8SMichael Walle { 1343cde0f4f8SMichael Walle int val; 1344cde0f4f8SMichael Walle 1345cde0f4f8SMichael Walle val = phy_read(phydev, AT803X_SMART_SPEED); 1346cde0f4f8SMichael Walle if (val < 0) 1347cde0f4f8SMichael Walle return val; 1348cde0f4f8SMichael Walle 1349cde0f4f8SMichael Walle if (val & AT803X_SMART_SPEED_ENABLE) 1350cde0f4f8SMichael Walle *d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2; 1351cde0f4f8SMichael Walle else 1352cde0f4f8SMichael Walle *d = DOWNSHIFT_DEV_DISABLE; 1353cde0f4f8SMichael Walle 1354cde0f4f8SMichael Walle return 0; 1355cde0f4f8SMichael Walle } 1356cde0f4f8SMichael Walle 1357cde0f4f8SMichael Walle static int at803x_set_downshift(struct phy_device *phydev, u8 cnt) 1358cde0f4f8SMichael Walle { 1359cde0f4f8SMichael Walle u16 mask, set; 1360cde0f4f8SMichael Walle int ret; 1361cde0f4f8SMichael Walle 1362cde0f4f8SMichael Walle switch (cnt) { 1363cde0f4f8SMichael Walle case DOWNSHIFT_DEV_DEFAULT_COUNT: 1364cde0f4f8SMichael Walle cnt = AT803X_DEFAULT_DOWNSHIFT; 1365cde0f4f8SMichael Walle fallthrough; 1366cde0f4f8SMichael Walle case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT: 1367cde0f4f8SMichael Walle set = AT803X_SMART_SPEED_ENABLE | 1368cde0f4f8SMichael Walle AT803X_SMART_SPEED_BYPASS_TIMER | 1369cde0f4f8SMichael Walle FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2); 1370cde0f4f8SMichael Walle mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK; 1371cde0f4f8SMichael Walle break; 1372cde0f4f8SMichael Walle case DOWNSHIFT_DEV_DISABLE: 1373cde0f4f8SMichael Walle set = 0; 1374cde0f4f8SMichael Walle mask = AT803X_SMART_SPEED_ENABLE | 1375cde0f4f8SMichael Walle AT803X_SMART_SPEED_BYPASS_TIMER; 1376cde0f4f8SMichael Walle break; 1377cde0f4f8SMichael Walle default: 1378cde0f4f8SMichael Walle return -EINVAL; 1379cde0f4f8SMichael Walle } 1380cde0f4f8SMichael Walle 1381cde0f4f8SMichael Walle ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set); 1382cde0f4f8SMichael Walle 1383cde0f4f8SMichael Walle /* After changing the smart speed settings, we need to perform a 1384cde0f4f8SMichael Walle * software reset, use phy_init_hw() to make sure we set the 1385cde0f4f8SMichael Walle * reapply any values which might got lost during software reset. 1386cde0f4f8SMichael Walle */ 1387cde0f4f8SMichael Walle if (ret == 1) 1388cde0f4f8SMichael Walle ret = phy_init_hw(phydev); 1389cde0f4f8SMichael Walle 1390cde0f4f8SMichael Walle return ret; 1391cde0f4f8SMichael Walle } 1392cde0f4f8SMichael Walle 1393cde0f4f8SMichael Walle static int at803x_get_tunable(struct phy_device *phydev, 1394cde0f4f8SMichael Walle struct ethtool_tunable *tuna, void *data) 1395cde0f4f8SMichael Walle { 1396cde0f4f8SMichael Walle switch (tuna->id) { 1397cde0f4f8SMichael Walle case ETHTOOL_PHY_DOWNSHIFT: 1398cde0f4f8SMichael Walle return at803x_get_downshift(phydev, data); 1399cde0f4f8SMichael Walle default: 1400cde0f4f8SMichael Walle return -EOPNOTSUPP; 1401cde0f4f8SMichael Walle } 1402cde0f4f8SMichael Walle } 1403cde0f4f8SMichael Walle 1404cde0f4f8SMichael Walle static int at803x_set_tunable(struct phy_device *phydev, 1405cde0f4f8SMichael Walle struct ethtool_tunable *tuna, const void *data) 1406cde0f4f8SMichael Walle { 1407cde0f4f8SMichael Walle switch (tuna->id) { 1408cde0f4f8SMichael Walle case ETHTOOL_PHY_DOWNSHIFT: 1409cde0f4f8SMichael Walle return at803x_set_downshift(phydev, *(const u8 *)data); 1410cde0f4f8SMichael Walle default: 1411cde0f4f8SMichael Walle return -EOPNOTSUPP; 1412cde0f4f8SMichael Walle } 1413cde0f4f8SMichael Walle } 1414cde0f4f8SMichael Walle 14156cb75767SMichael Walle static int at803x_cable_test_result_trans(u16 status) 14166cb75767SMichael Walle { 14176cb75767SMichael Walle switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) { 14186cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_NORMAL: 14196cb75767SMichael Walle return ETHTOOL_A_CABLE_RESULT_CODE_OK; 14206cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_SHORT: 14216cb75767SMichael Walle return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 14226cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_OPEN: 14236cb75767SMichael Walle return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 14246cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_FAIL: 14256cb75767SMichael Walle default: 14266cb75767SMichael Walle return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 14276cb75767SMichael Walle } 14286cb75767SMichael Walle } 14296cb75767SMichael Walle 14306cb75767SMichael Walle static bool at803x_cdt_test_failed(u16 status) 14316cb75767SMichael Walle { 14326cb75767SMichael Walle return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) == 14336cb75767SMichael Walle AT803X_CDT_STATUS_STAT_FAIL; 14346cb75767SMichael Walle } 14356cb75767SMichael Walle 14366cb75767SMichael Walle static bool at803x_cdt_fault_length_valid(u16 status) 14376cb75767SMichael Walle { 14386cb75767SMichael Walle switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) { 14396cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_OPEN: 14406cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_SHORT: 14416cb75767SMichael Walle return true; 14426cb75767SMichael Walle } 14436cb75767SMichael Walle return false; 14446cb75767SMichael Walle } 14456cb75767SMichael Walle 14466cb75767SMichael Walle static int at803x_cdt_fault_length(u16 status) 14476cb75767SMichael Walle { 14486cb75767SMichael Walle int dt; 14496cb75767SMichael Walle 14506cb75767SMichael Walle /* According to the datasheet the distance to the fault is 14516cb75767SMichael Walle * DELTA_TIME * 0.824 meters. 14526cb75767SMichael Walle * 14536cb75767SMichael Walle * The author suspect the correct formula is: 14546cb75767SMichael Walle * 14556cb75767SMichael Walle * fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2 14566cb75767SMichael Walle * 14576cb75767SMichael Walle * where c is the speed of light, VF is the velocity factor of 14586cb75767SMichael Walle * the twisted pair cable, 125MHz the counter frequency and 14596cb75767SMichael Walle * we need to divide by 2 because the hardware will measure the 14606cb75767SMichael Walle * round trip time to the fault and back to the PHY. 14616cb75767SMichael Walle * 14626cb75767SMichael Walle * With a VF of 0.69 we get the factor 0.824 mentioned in the 14636cb75767SMichael Walle * datasheet. 14646cb75767SMichael Walle */ 14656cb75767SMichael Walle dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status); 14666cb75767SMichael Walle 14676cb75767SMichael Walle return (dt * 824) / 10; 14686cb75767SMichael Walle } 14696cb75767SMichael Walle 14706cb75767SMichael Walle static int at803x_cdt_start(struct phy_device *phydev, int pair) 14716cb75767SMichael Walle { 14726cb75767SMichael Walle u16 cdt; 14736cb75767SMichael Walle 14748c84d752SLuo Jie /* qca8081 takes the different bit 15 to enable CDT test */ 14758c84d752SLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) 14768c84d752SLuo Jie cdt = QCA808X_CDT_ENABLE_TEST | 14778c84d752SLuo Jie QCA808X_CDT_LENGTH_UNIT | 14788c84d752SLuo Jie QCA808X_CDT_INTER_CHECK_DIS; 14798c84d752SLuo Jie else 14806cb75767SMichael Walle cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) | 14816cb75767SMichael Walle AT803X_CDT_ENABLE_TEST; 14826cb75767SMichael Walle 14836cb75767SMichael Walle return phy_write(phydev, AT803X_CDT, cdt); 14846cb75767SMichael Walle } 14856cb75767SMichael Walle 14866cb75767SMichael Walle static int at803x_cdt_wait_for_completion(struct phy_device *phydev) 14876cb75767SMichael Walle { 14886cb75767SMichael Walle int val, ret; 14898c84d752SLuo Jie u16 cdt_en; 14908c84d752SLuo Jie 14918c84d752SLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) 14928c84d752SLuo Jie cdt_en = QCA808X_CDT_ENABLE_TEST; 14938c84d752SLuo Jie else 14948c84d752SLuo Jie cdt_en = AT803X_CDT_ENABLE_TEST; 14956cb75767SMichael Walle 14966cb75767SMichael Walle /* One test run takes about 25ms */ 14976cb75767SMichael Walle ret = phy_read_poll_timeout(phydev, AT803X_CDT, val, 14988c84d752SLuo Jie !(val & cdt_en), 14996cb75767SMichael Walle 30000, 100000, true); 15006cb75767SMichael Walle 15016cb75767SMichael Walle return ret < 0 ? ret : 0; 15026cb75767SMichael Walle } 15036cb75767SMichael Walle 15046cb75767SMichael Walle static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair) 15056cb75767SMichael Walle { 15066cb75767SMichael Walle static const int ethtool_pair[] = { 15076cb75767SMichael Walle ETHTOOL_A_CABLE_PAIR_A, 15086cb75767SMichael Walle ETHTOOL_A_CABLE_PAIR_B, 15096cb75767SMichael Walle ETHTOOL_A_CABLE_PAIR_C, 15106cb75767SMichael Walle ETHTOOL_A_CABLE_PAIR_D, 15116cb75767SMichael Walle }; 15126cb75767SMichael Walle int ret, val; 15136cb75767SMichael Walle 15146cb75767SMichael Walle ret = at803x_cdt_start(phydev, pair); 15156cb75767SMichael Walle if (ret) 15166cb75767SMichael Walle return ret; 15176cb75767SMichael Walle 15186cb75767SMichael Walle ret = at803x_cdt_wait_for_completion(phydev); 15196cb75767SMichael Walle if (ret) 15206cb75767SMichael Walle return ret; 15216cb75767SMichael Walle 15226cb75767SMichael Walle val = phy_read(phydev, AT803X_CDT_STATUS); 15236cb75767SMichael Walle if (val < 0) 15246cb75767SMichael Walle return val; 15256cb75767SMichael Walle 15266cb75767SMichael Walle if (at803x_cdt_test_failed(val)) 15276cb75767SMichael Walle return 0; 15286cb75767SMichael Walle 15296cb75767SMichael Walle ethnl_cable_test_result(phydev, ethtool_pair[pair], 15306cb75767SMichael Walle at803x_cable_test_result_trans(val)); 15316cb75767SMichael Walle 15326cb75767SMichael Walle if (at803x_cdt_fault_length_valid(val)) 15336cb75767SMichael Walle ethnl_cable_test_fault_length(phydev, ethtool_pair[pair], 15346cb75767SMichael Walle at803x_cdt_fault_length(val)); 15356cb75767SMichael Walle 15366cb75767SMichael Walle return 1; 15376cb75767SMichael Walle } 15386cb75767SMichael Walle 15396cb75767SMichael Walle static int at803x_cable_test_get_status(struct phy_device *phydev, 15406cb75767SMichael Walle bool *finished) 15416cb75767SMichael Walle { 1542dc0f3ed1SOleksij Rempel unsigned long pair_mask; 15436cb75767SMichael Walle int retries = 20; 15446cb75767SMichael Walle int pair, ret; 15456cb75767SMichael Walle 1546dc0f3ed1SOleksij Rempel if (phydev->phy_id == ATH9331_PHY_ID || 1547fada2ce0SDavid Bauer phydev->phy_id == ATH8032_PHY_ID || 1548fada2ce0SDavid Bauer phydev->phy_id == QCA9561_PHY_ID) 1549dc0f3ed1SOleksij Rempel pair_mask = 0x3; 1550dc0f3ed1SOleksij Rempel else 1551dc0f3ed1SOleksij Rempel pair_mask = 0xf; 1552dc0f3ed1SOleksij Rempel 15536cb75767SMichael Walle *finished = false; 15546cb75767SMichael Walle 15556cb75767SMichael Walle /* According to the datasheet the CDT can be performed when 15566cb75767SMichael Walle * there is no link partner or when the link partner is 15576cb75767SMichael Walle * auto-negotiating. Starting the test will restart the AN 15586cb75767SMichael Walle * automatically. It seems that doing this repeatedly we will 15596cb75767SMichael Walle * get a slot where our link partner won't disturb our 15606cb75767SMichael Walle * measurement. 15616cb75767SMichael Walle */ 15626cb75767SMichael Walle while (pair_mask && retries--) { 15636cb75767SMichael Walle for_each_set_bit(pair, &pair_mask, 4) { 15646cb75767SMichael Walle ret = at803x_cable_test_one_pair(phydev, pair); 15656cb75767SMichael Walle if (ret < 0) 15666cb75767SMichael Walle return ret; 15676cb75767SMichael Walle if (ret) 15686cb75767SMichael Walle clear_bit(pair, &pair_mask); 15696cb75767SMichael Walle } 15706cb75767SMichael Walle if (pair_mask) 15716cb75767SMichael Walle msleep(250); 15726cb75767SMichael Walle } 15736cb75767SMichael Walle 15746cb75767SMichael Walle *finished = true; 15756cb75767SMichael Walle 15766cb75767SMichael Walle return 0; 15776cb75767SMichael Walle } 15786cb75767SMichael Walle 15796cb75767SMichael Walle static int at803x_cable_test_start(struct phy_device *phydev) 15806cb75767SMichael Walle { 15816cb75767SMichael Walle /* Enable auto-negotiation, but advertise no capabilities, no link 15826cb75767SMichael Walle * will be established. A restart of the auto-negotiation is not 15836cb75767SMichael Walle * required, because the cable test will automatically break the link. 15846cb75767SMichael Walle */ 15856cb75767SMichael Walle phy_write(phydev, MII_BMCR, BMCR_ANENABLE); 15866cb75767SMichael Walle phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA); 1587dc0f3ed1SOleksij Rempel if (phydev->phy_id != ATH9331_PHY_ID && 1588fada2ce0SDavid Bauer phydev->phy_id != ATH8032_PHY_ID && 1589fada2ce0SDavid Bauer phydev->phy_id != QCA9561_PHY_ID) 15906cb75767SMichael Walle phy_write(phydev, MII_CTRL1000, 0); 15916cb75767SMichael Walle 15926cb75767SMichael Walle /* we do all the (time consuming) work later */ 15936cb75767SMichael Walle return 0; 15946cb75767SMichael Walle } 15956cb75767SMichael Walle 1596272833b9SAnsuel Smith static int qca83xx_config_init(struct phy_device *phydev) 1597272833b9SAnsuel Smith { 1598272833b9SAnsuel Smith u8 switch_revision; 1599272833b9SAnsuel Smith 1600272833b9SAnsuel Smith switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK; 1601272833b9SAnsuel Smith 1602272833b9SAnsuel Smith switch (switch_revision) { 1603272833b9SAnsuel Smith case 1: 1604272833b9SAnsuel Smith /* For 100M waveform */ 160567999555SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea); 1606272833b9SAnsuel Smith /* Turn on Gigabit clock */ 160767999555SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0); 1608272833b9SAnsuel Smith break; 1609272833b9SAnsuel Smith 1610272833b9SAnsuel Smith case 2: 1611272833b9SAnsuel Smith phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0); 1612272833b9SAnsuel Smith fallthrough; 1613272833b9SAnsuel Smith case 4: 1614272833b9SAnsuel Smith phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f); 161567999555SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860); 161667999555SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46); 1617272833b9SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000); 1618272833b9SAnsuel Smith break; 1619272833b9SAnsuel Smith } 1620272833b9SAnsuel Smith 16211ca83119SAnsuel Smith /* QCA8327 require DAC amplitude adjustment for 100m set to +6%. 16221ca83119SAnsuel Smith * Disable on init and enable only with 100m speed following 16231ca83119SAnsuel Smith * qca original source code. 16241ca83119SAnsuel Smith */ 16251ca83119SAnsuel Smith if (phydev->drv->phy_id == QCA8327_A_PHY_ID || 16261ca83119SAnsuel Smith phydev->drv->phy_id == QCA8327_B_PHY_ID) 162767999555SAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 16281ca83119SAnsuel Smith QCA8327_DEBUG_MANU_CTRL_EN, 0); 16291ca83119SAnsuel Smith 16309d1c29b4SAnsuel Smith /* Following original QCA sourcecode set port to prefer master */ 16319d1c29b4SAnsuel Smith phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER); 16329d1c29b4SAnsuel Smith 1633272833b9SAnsuel Smith return 0; 1634272833b9SAnsuel Smith } 1635272833b9SAnsuel Smith 16361ca83119SAnsuel Smith static void qca83xx_link_change_notify(struct phy_device *phydev) 16371ca83119SAnsuel Smith { 16381ca83119SAnsuel Smith /* QCA8337 doesn't require DAC Amplitude adjustement */ 16391ca83119SAnsuel Smith if (phydev->drv->phy_id == QCA8337_PHY_ID) 16401ca83119SAnsuel Smith return; 16411ca83119SAnsuel Smith 16421ca83119SAnsuel Smith /* Set DAC Amplitude adjustment to +6% for 100m on link running */ 16431ca83119SAnsuel Smith if (phydev->state == PHY_RUNNING) { 16441ca83119SAnsuel Smith if (phydev->speed == SPEED_100) 164567999555SAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 16461ca83119SAnsuel Smith QCA8327_DEBUG_MANU_CTRL_EN, 16471ca83119SAnsuel Smith QCA8327_DEBUG_MANU_CTRL_EN); 16481ca83119SAnsuel Smith } else { 16491ca83119SAnsuel Smith /* Reset DAC Amplitude adjustment */ 165067999555SAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 16511ca83119SAnsuel Smith QCA8327_DEBUG_MANU_CTRL_EN, 0); 16521ca83119SAnsuel Smith } 16531ca83119SAnsuel Smith } 16541ca83119SAnsuel Smith 1655ba3c01eeSAnsuel Smith static int qca83xx_resume(struct phy_device *phydev) 1656ba3c01eeSAnsuel Smith { 1657ba3c01eeSAnsuel Smith int ret, val; 1658ba3c01eeSAnsuel Smith 1659ba3c01eeSAnsuel Smith /* Skip reset if not suspended */ 1660ba3c01eeSAnsuel Smith if (!phydev->suspended) 1661ba3c01eeSAnsuel Smith return 0; 1662ba3c01eeSAnsuel Smith 1663ba3c01eeSAnsuel Smith /* Reinit the port, reset values set by suspend */ 1664ba3c01eeSAnsuel Smith qca83xx_config_init(phydev); 1665ba3c01eeSAnsuel Smith 1666ba3c01eeSAnsuel Smith /* Reset the port on port resume */ 1667ba3c01eeSAnsuel Smith phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE); 1668ba3c01eeSAnsuel Smith 1669ba3c01eeSAnsuel Smith /* On resume from suspend the switch execute a reset and 1670ba3c01eeSAnsuel Smith * restart auto-negotiation. Wait for reset to complete. 1671ba3c01eeSAnsuel Smith */ 1672ba3c01eeSAnsuel Smith ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET), 1673ba3c01eeSAnsuel Smith 50000, 600000, true); 1674ba3c01eeSAnsuel Smith if (ret) 1675ba3c01eeSAnsuel Smith return ret; 1676ba3c01eeSAnsuel Smith 1677ba3c01eeSAnsuel Smith msleep(1); 1678ba3c01eeSAnsuel Smith 1679ba3c01eeSAnsuel Smith return 0; 1680ba3c01eeSAnsuel Smith } 1681ba3c01eeSAnsuel Smith 1682ba3c01eeSAnsuel Smith static int qca83xx_suspend(struct phy_device *phydev) 1683ba3c01eeSAnsuel Smith { 1684ba3c01eeSAnsuel Smith u16 mask = 0; 1685ba3c01eeSAnsuel Smith 1686ba3c01eeSAnsuel Smith /* Only QCA8337 support actual suspend. 1687ba3c01eeSAnsuel Smith * QCA8327 cause port unreliability when phy suspend 1688ba3c01eeSAnsuel Smith * is set. 1689ba3c01eeSAnsuel Smith */ 1690ba3c01eeSAnsuel Smith if (phydev->drv->phy_id == QCA8337_PHY_ID) { 1691ba3c01eeSAnsuel Smith genphy_suspend(phydev); 1692ba3c01eeSAnsuel Smith } else { 1693ba3c01eeSAnsuel Smith mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX); 1694ba3c01eeSAnsuel Smith phy_modify(phydev, MII_BMCR, mask, 0); 1695ba3c01eeSAnsuel Smith } 1696ba3c01eeSAnsuel Smith 169767999555SAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN, 1698ba3c01eeSAnsuel Smith AT803X_DEBUG_GATE_CLK_IN1000, 0); 1699ba3c01eeSAnsuel Smith 1700ba3c01eeSAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL, 1701ba3c01eeSAnsuel Smith AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE | 1702ba3c01eeSAnsuel Smith AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0); 1703ba3c01eeSAnsuel Smith 1704ba3c01eeSAnsuel Smith return 0; 1705ba3c01eeSAnsuel Smith } 1706ba3c01eeSAnsuel Smith 17072acdd43fSLuo Jie static int qca808x_phy_fast_retrain_config(struct phy_device *phydev) 17082acdd43fSLuo Jie { 17092acdd43fSLuo Jie int ret; 17102acdd43fSLuo Jie 17112acdd43fSLuo Jie /* Enable fast retrain */ 17122acdd43fSLuo Jie ret = genphy_c45_fast_retrain(phydev, true); 17132acdd43fSLuo Jie if (ret) 17142acdd43fSLuo Jie return ret; 17152acdd43fSLuo Jie 17162acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_TOP_OPTION1, 17172acdd43fSLuo Jie QCA808X_TOP_OPTION1_DATA); 17182acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB, 17192acdd43fSLuo Jie QCA808X_MSE_THRESHOLD_20DB_VALUE); 17202acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB, 17212acdd43fSLuo Jie QCA808X_MSE_THRESHOLD_17DB_VALUE); 17222acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB, 17232acdd43fSLuo Jie QCA808X_MSE_THRESHOLD_27DB_VALUE); 17242acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB, 17252acdd43fSLuo Jie QCA808X_MSE_THRESHOLD_28DB_VALUE); 17262acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_1, 17272acdd43fSLuo Jie QCA808X_MMD3_DEBUG_1_VALUE); 17282acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_4, 17292acdd43fSLuo Jie QCA808X_MMD3_DEBUG_4_VALUE); 17302acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_5, 17312acdd43fSLuo Jie QCA808X_MMD3_DEBUG_5_VALUE); 17322acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_3, 17332acdd43fSLuo Jie QCA808X_MMD3_DEBUG_3_VALUE); 17342acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_6, 17352acdd43fSLuo Jie QCA808X_MMD3_DEBUG_6_VALUE); 17362acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_2, 17372acdd43fSLuo Jie QCA808X_MMD3_DEBUG_2_VALUE); 17382acdd43fSLuo Jie 17392acdd43fSLuo Jie return 0; 17402acdd43fSLuo Jie } 17412acdd43fSLuo Jie 17429d4dae29SLuo Jie static int qca808x_phy_ms_random_seed_set(struct phy_device *phydev) 17439d4dae29SLuo Jie { 17448032bf12SJason A. Donenfeld u16 seed_value = get_random_u32_below(QCA808X_MASTER_SLAVE_SEED_RANGE); 17459d4dae29SLuo Jie 17469d4dae29SLuo Jie return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED, 17479d4dae29SLuo Jie QCA808X_MASTER_SLAVE_SEED_CFG, 17489d4dae29SLuo Jie FIELD_PREP(QCA808X_MASTER_SLAVE_SEED_CFG, seed_value)); 17499d4dae29SLuo Jie } 17509d4dae29SLuo Jie 17519d4dae29SLuo Jie static int qca808x_phy_ms_seed_enable(struct phy_device *phydev, bool enable) 17529d4dae29SLuo Jie { 17539d4dae29SLuo Jie u16 seed_enable = 0; 17549d4dae29SLuo Jie 17559d4dae29SLuo Jie if (enable) 17569d4dae29SLuo Jie seed_enable = QCA808X_MASTER_SLAVE_SEED_ENABLE; 17579d4dae29SLuo Jie 17589d4dae29SLuo Jie return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED, 17599d4dae29SLuo Jie QCA808X_MASTER_SLAVE_SEED_ENABLE, seed_enable); 17609d4dae29SLuo Jie } 17619d4dae29SLuo Jie 17622acdd43fSLuo Jie static int qca808x_config_init(struct phy_device *phydev) 17632acdd43fSLuo Jie { 17642acdd43fSLuo Jie int ret; 17652acdd43fSLuo Jie 17662acdd43fSLuo Jie /* Active adc&vga on 802.3az for the link 1000M and 100M */ 17672acdd43fSLuo Jie ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_ADDR_CLD_CTRL7, 17682acdd43fSLuo Jie QCA808X_8023AZ_AFE_CTRL_MASK, QCA808X_8023AZ_AFE_EN); 17692acdd43fSLuo Jie if (ret) 17702acdd43fSLuo Jie return ret; 17712acdd43fSLuo Jie 17722acdd43fSLuo Jie /* Adjust the threshold on 802.3az for the link 1000M */ 17732acdd43fSLuo Jie ret = phy_write_mmd(phydev, MDIO_MMD_PCS, 17742acdd43fSLuo Jie QCA808X_PHY_MMD3_AZ_TRAINING_CTRL, QCA808X_MMD3_AZ_TRAINING_VAL); 17752acdd43fSLuo Jie if (ret) 17762acdd43fSLuo Jie return ret; 17772acdd43fSLuo Jie 17782acdd43fSLuo Jie /* Config the fast retrain for the link 2500M */ 17792acdd43fSLuo Jie ret = qca808x_phy_fast_retrain_config(phydev); 17802acdd43fSLuo Jie if (ret) 17812acdd43fSLuo Jie return ret; 17822acdd43fSLuo Jie 17839d4dae29SLuo Jie /* Configure lower ramdom seed to make phy linked as slave mode */ 17849d4dae29SLuo Jie ret = qca808x_phy_ms_random_seed_set(phydev); 17859d4dae29SLuo Jie if (ret) 17869d4dae29SLuo Jie return ret; 17879d4dae29SLuo Jie 17889d4dae29SLuo Jie /* Enable seed */ 17899d4dae29SLuo Jie ret = qca808x_phy_ms_seed_enable(phydev, true); 17909d4dae29SLuo Jie if (ret) 17919d4dae29SLuo Jie return ret; 17929d4dae29SLuo Jie 17932acdd43fSLuo Jie /* Configure adc threshold as 100mv for the link 10M */ 17942acdd43fSLuo Jie return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD, 17952acdd43fSLuo Jie QCA808X_ADC_THRESHOLD_MASK, QCA808X_ADC_THRESHOLD_100MV); 17962acdd43fSLuo Jie } 17972acdd43fSLuo Jie 179879c7bc05SLuo Jie static int qca808x_read_status(struct phy_device *phydev) 179979c7bc05SLuo Jie { 180079c7bc05SLuo Jie int ret; 180179c7bc05SLuo Jie 180279c7bc05SLuo Jie ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT); 180379c7bc05SLuo Jie if (ret < 0) 180479c7bc05SLuo Jie return ret; 180579c7bc05SLuo Jie 180679c7bc05SLuo Jie linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising, 180779c7bc05SLuo Jie ret & MDIO_AN_10GBT_STAT_LP2_5G); 180879c7bc05SLuo Jie 180979c7bc05SLuo Jie ret = genphy_read_status(phydev); 181079c7bc05SLuo Jie if (ret) 181179c7bc05SLuo Jie return ret; 181279c7bc05SLuo Jie 181379c7bc05SLuo Jie ret = at803x_read_specific_status(phydev); 181479c7bc05SLuo Jie if (ret < 0) 181579c7bc05SLuo Jie return ret; 181679c7bc05SLuo Jie 1817881cc731SJonathan McDowell if (phydev->link) { 1818881cc731SJonathan McDowell if (phydev->speed == SPEED_2500) 181979c7bc05SLuo Jie phydev->interface = PHY_INTERFACE_MODE_2500BASEX; 182079c7bc05SLuo Jie else 1821881cc731SJonathan McDowell phydev->interface = PHY_INTERFACE_MODE_SGMII; 1822881cc731SJonathan McDowell } else { 18238bc1c543SLuo Jie /* generate seed as a lower random value to make PHY linked as SLAVE easily, 18248bc1c543SLuo Jie * except for master/slave configuration fault detected. 18258bc1c543SLuo Jie * the reason for not putting this code into the function link_change_notify is 18268bc1c543SLuo Jie * the corner case where the link partner is also the qca8081 PHY and the seed 18278bc1c543SLuo Jie * value is configured as the same value, the link can't be up and no link change 18288bc1c543SLuo Jie * occurs. 18298bc1c543SLuo Jie */ 18308bc1c543SLuo Jie if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR) { 18318bc1c543SLuo Jie qca808x_phy_ms_seed_enable(phydev, false); 18328bc1c543SLuo Jie } else { 18338bc1c543SLuo Jie qca808x_phy_ms_random_seed_set(phydev); 18348bc1c543SLuo Jie qca808x_phy_ms_seed_enable(phydev, true); 18358bc1c543SLuo Jie } 18368bc1c543SLuo Jie } 18378bc1c543SLuo Jie 183879c7bc05SLuo Jie return 0; 183979c7bc05SLuo Jie } 184079c7bc05SLuo Jie 18419d4dae29SLuo Jie static int qca808x_soft_reset(struct phy_device *phydev) 18429d4dae29SLuo Jie { 18439d4dae29SLuo Jie int ret; 18449d4dae29SLuo Jie 18459d4dae29SLuo Jie ret = genphy_soft_reset(phydev); 18469d4dae29SLuo Jie if (ret < 0) 18479d4dae29SLuo Jie return ret; 18489d4dae29SLuo Jie 18499d4dae29SLuo Jie return qca808x_phy_ms_seed_enable(phydev, true); 18509d4dae29SLuo Jie } 18519d4dae29SLuo Jie 18528c84d752SLuo Jie static bool qca808x_cdt_fault_length_valid(int cdt_code) 18538c84d752SLuo Jie { 18548c84d752SLuo Jie switch (cdt_code) { 18558c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_SHORT: 18568c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_OPEN: 18578c84d752SLuo Jie return true; 18588c84d752SLuo Jie default: 18598c84d752SLuo Jie return false; 18608c84d752SLuo Jie } 18618c84d752SLuo Jie } 18628c84d752SLuo Jie 18638c84d752SLuo Jie static int qca808x_cable_test_result_trans(int cdt_code) 18648c84d752SLuo Jie { 18658c84d752SLuo Jie switch (cdt_code) { 18668c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_NORMAL: 18678c84d752SLuo Jie return ETHTOOL_A_CABLE_RESULT_CODE_OK; 18688c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_SHORT: 18698c84d752SLuo Jie return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 18708c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_OPEN: 18718c84d752SLuo Jie return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 18728c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_FAIL: 18738c84d752SLuo Jie default: 18748c84d752SLuo Jie return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 18758c84d752SLuo Jie } 18768c84d752SLuo Jie } 18778c84d752SLuo Jie 18788c84d752SLuo Jie static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair) 18798c84d752SLuo Jie { 18808c84d752SLuo Jie int val; 18818c84d752SLuo Jie u32 cdt_length_reg = 0; 18828c84d752SLuo Jie 18838c84d752SLuo Jie switch (pair) { 18848c84d752SLuo Jie case ETHTOOL_A_CABLE_PAIR_A: 18858c84d752SLuo Jie cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_A; 18868c84d752SLuo Jie break; 18878c84d752SLuo Jie case ETHTOOL_A_CABLE_PAIR_B: 18888c84d752SLuo Jie cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_B; 18898c84d752SLuo Jie break; 18908c84d752SLuo Jie case ETHTOOL_A_CABLE_PAIR_C: 18918c84d752SLuo Jie cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_C; 18928c84d752SLuo Jie break; 18938c84d752SLuo Jie case ETHTOOL_A_CABLE_PAIR_D: 18948c84d752SLuo Jie cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_D; 18958c84d752SLuo Jie break; 18968c84d752SLuo Jie default: 18978c84d752SLuo Jie return -EINVAL; 18988c84d752SLuo Jie } 18998c84d752SLuo Jie 19008c84d752SLuo Jie val = phy_read_mmd(phydev, MDIO_MMD_PCS, cdt_length_reg); 19018c84d752SLuo Jie if (val < 0) 19028c84d752SLuo Jie return val; 19038c84d752SLuo Jie 19048c84d752SLuo Jie return (FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val) * 824) / 10; 19058c84d752SLuo Jie } 19068c84d752SLuo Jie 19078c84d752SLuo Jie static int qca808x_cable_test_start(struct phy_device *phydev) 19088c84d752SLuo Jie { 19098c84d752SLuo Jie int ret; 19108c84d752SLuo Jie 19118c84d752SLuo Jie /* perform CDT with the following configs: 19128c84d752SLuo Jie * 1. disable hibernation. 19138c84d752SLuo Jie * 2. force PHY working in MDI mode. 19148c84d752SLuo Jie * 3. for PHY working in 1000BaseT. 19158c84d752SLuo Jie * 4. configure the threshold. 19168c84d752SLuo Jie */ 19178c84d752SLuo Jie 19188c84d752SLuo Jie ret = at803x_debug_reg_mask(phydev, QCA808X_DBG_AN_TEST, QCA808X_HIBERNATION_EN, 0); 19198c84d752SLuo Jie if (ret < 0) 19208c84d752SLuo Jie return ret; 19218c84d752SLuo Jie 19228c84d752SLuo Jie ret = at803x_config_mdix(phydev, ETH_TP_MDI); 19238c84d752SLuo Jie if (ret < 0) 19248c84d752SLuo Jie return ret; 19258c84d752SLuo Jie 19268c84d752SLuo Jie /* Force 1000base-T needs to configure PMA/PMD and MII_BMCR */ 19278c84d752SLuo Jie phydev->duplex = DUPLEX_FULL; 19288c84d752SLuo Jie phydev->speed = SPEED_1000; 19298c84d752SLuo Jie ret = genphy_c45_pma_setup_forced(phydev); 19308c84d752SLuo Jie if (ret < 0) 19318c84d752SLuo Jie return ret; 19328c84d752SLuo Jie 19338c84d752SLuo Jie ret = genphy_setup_forced(phydev); 19348c84d752SLuo Jie if (ret < 0) 19358c84d752SLuo Jie return ret; 19368c84d752SLuo Jie 19378c84d752SLuo Jie /* configure the thresholds for open, short, pair ok test */ 19388c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8074, 0xc040); 19398c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8076, 0xc040); 19408c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8077, 0xa060); 19418c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8078, 0xc050); 19428c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807a, 0xc060); 19438c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807e, 0xb060); 19448c84d752SLuo Jie 19458c84d752SLuo Jie return 0; 19468c84d752SLuo Jie } 19478c84d752SLuo Jie 19488c84d752SLuo Jie static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished) 19498c84d752SLuo Jie { 19508c84d752SLuo Jie int ret, val; 19518c84d752SLuo Jie int pair_a, pair_b, pair_c, pair_d; 19528c84d752SLuo Jie 19538c84d752SLuo Jie *finished = false; 19548c84d752SLuo Jie 19558c84d752SLuo Jie ret = at803x_cdt_start(phydev, 0); 19568c84d752SLuo Jie if (ret) 19578c84d752SLuo Jie return ret; 19588c84d752SLuo Jie 19598c84d752SLuo Jie ret = at803x_cdt_wait_for_completion(phydev); 19608c84d752SLuo Jie if (ret) 19618c84d752SLuo Jie return ret; 19628c84d752SLuo Jie 19638c84d752SLuo Jie val = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA808X_MMD3_CDT_STATUS); 19648c84d752SLuo Jie if (val < 0) 19658c84d752SLuo Jie return val; 19668c84d752SLuo Jie 19678c84d752SLuo Jie pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val); 19688c84d752SLuo Jie pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val); 19698c84d752SLuo Jie pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val); 19708c84d752SLuo Jie pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val); 19718c84d752SLuo Jie 19728c84d752SLuo Jie ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A, 19738c84d752SLuo Jie qca808x_cable_test_result_trans(pair_a)); 19748c84d752SLuo Jie ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B, 19758c84d752SLuo Jie qca808x_cable_test_result_trans(pair_b)); 19768c84d752SLuo Jie ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C, 19778c84d752SLuo Jie qca808x_cable_test_result_trans(pair_c)); 19788c84d752SLuo Jie ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D, 19798c84d752SLuo Jie qca808x_cable_test_result_trans(pair_d)); 19808c84d752SLuo Jie 19818c84d752SLuo Jie if (qca808x_cdt_fault_length_valid(pair_a)) 19828c84d752SLuo Jie ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A, 19838c84d752SLuo Jie qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A)); 19848c84d752SLuo Jie if (qca808x_cdt_fault_length_valid(pair_b)) 19858c84d752SLuo Jie ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B, 19868c84d752SLuo Jie qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B)); 19878c84d752SLuo Jie if (qca808x_cdt_fault_length_valid(pair_c)) 19888c84d752SLuo Jie ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C, 19898c84d752SLuo Jie qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C)); 19908c84d752SLuo Jie if (qca808x_cdt_fault_length_valid(pair_d)) 19918c84d752SLuo Jie ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D, 19928c84d752SLuo Jie qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D)); 19938c84d752SLuo Jie 19948c84d752SLuo Jie *finished = true; 19958c84d752SLuo Jie 19968c84d752SLuo Jie return 0; 19978c84d752SLuo Jie } 19988c84d752SLuo Jie 1999317420abSMugunthan V N static struct phy_driver at803x_driver[] = { 2000317420abSMugunthan V N { 200196c36712SMichael Walle /* Qualcomm Atheros AR8035 */ 20020465d8f8SMichael Walle PHY_ID_MATCH_EXACT(ATH8035_PHY_ID), 200396c36712SMichael Walle .name = "Qualcomm Atheros AR8035", 20046cb75767SMichael Walle .flags = PHY_POLL_CABLE_TEST, 20052f664823SMichael Walle .probe = at803x_probe, 20067dce80c2SOleksij Rempel .config_aneg = at803x_config_aneg, 20070ca7111aSMatus Ujhelyi .config_init = at803x_config_init, 2008cde0f4f8SMichael Walle .soft_reset = genphy_soft_reset, 2009ea13c9eeSMugunthan V N .set_wol = at803x_set_wol, 2010ea13c9eeSMugunthan V N .get_wol = at803x_get_wol, 20116229ed1fSDaniel Mack .suspend = at803x_suspend, 20126229ed1fSDaniel Mack .resume = at803x_resume, 2013dcdecdcfSHeiner Kallweit /* PHY_GBIT_FEATURES */ 201406d5f344SRussell King .read_status = at803x_read_status, 20150eae5982SMåns Rullgård .config_intr = at803x_config_intr, 201629773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 2017cde0f4f8SMichael Walle .get_tunable = at803x_get_tunable, 2018cde0f4f8SMichael Walle .set_tunable = at803x_set_tunable, 20196cb75767SMichael Walle .cable_test_start = at803x_cable_test_start, 20206cb75767SMichael Walle .cable_test_get_status = at803x_cable_test_get_status, 2021317420abSMugunthan V N }, { 202296c36712SMichael Walle /* Qualcomm Atheros AR8030 */ 2023bd8ca17fSDaniel Mack .phy_id = ATH8030_PHY_ID, 202496c36712SMichael Walle .name = "Qualcomm Atheros AR8030", 20250465d8f8SMichael Walle .phy_id_mask = AT8030_PHY_ID_MASK, 20262f664823SMichael Walle .probe = at803x_probe, 20270ca7111aSMatus Ujhelyi .config_init = at803x_config_init, 202813a56b44SDaniel Mack .link_change_notify = at803x_link_change_notify, 2029ea13c9eeSMugunthan V N .set_wol = at803x_set_wol, 2030ea13c9eeSMugunthan V N .get_wol = at803x_get_wol, 20316229ed1fSDaniel Mack .suspend = at803x_suspend, 20326229ed1fSDaniel Mack .resume = at803x_resume, 2033dcdecdcfSHeiner Kallweit /* PHY_BASIC_FEATURES */ 20340eae5982SMåns Rullgård .config_intr = at803x_config_intr, 203529773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 203605d7cce8SMugunthan V N }, { 203796c36712SMichael Walle /* Qualcomm Atheros AR8031/AR8033 */ 20380465d8f8SMichael Walle PHY_ID_MATCH_EXACT(ATH8031_PHY_ID), 203996c36712SMichael Walle .name = "Qualcomm Atheros AR8031/AR8033", 20406cb75767SMichael Walle .flags = PHY_POLL_CABLE_TEST, 20412f664823SMichael Walle .probe = at803x_probe, 204205d7cce8SMugunthan V N .config_init = at803x_config_init, 204363477a5dSMichael Walle .config_aneg = at803x_config_aneg, 2044cde0f4f8SMichael Walle .soft_reset = genphy_soft_reset, 204505d7cce8SMugunthan V N .set_wol = at803x_set_wol, 204605d7cce8SMugunthan V N .get_wol = at803x_get_wol, 20476229ed1fSDaniel Mack .suspend = at803x_suspend, 20486229ed1fSDaniel Mack .resume = at803x_resume, 2049c329e5afSDavid Bauer .read_page = at803x_read_page, 2050c329e5afSDavid Bauer .write_page = at803x_write_page, 2051b856150cSDavid Bauer .get_features = at803x_get_features, 205206d5f344SRussell King .read_status = at803x_read_status, 205377a99394SZhao Qiang .config_intr = &at803x_config_intr, 205429773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 2055cde0f4f8SMichael Walle .get_tunable = at803x_get_tunable, 2056cde0f4f8SMichael Walle .set_tunable = at803x_set_tunable, 20576cb75767SMichael Walle .cable_test_start = at803x_cable_test_start, 20586cb75767SMichael Walle .cable_test_get_status = at803x_cable_test_get_status, 20597908d2ceSOleksij Rempel }, { 20605800091aSDavid Bauer /* Qualcomm Atheros AR8032 */ 20615800091aSDavid Bauer PHY_ID_MATCH_EXACT(ATH8032_PHY_ID), 20625800091aSDavid Bauer .name = "Qualcomm Atheros AR8032", 20635800091aSDavid Bauer .probe = at803x_probe, 2064dc0f3ed1SOleksij Rempel .flags = PHY_POLL_CABLE_TEST, 20655800091aSDavid Bauer .config_init = at803x_config_init, 20665800091aSDavid Bauer .link_change_notify = at803x_link_change_notify, 20675800091aSDavid Bauer .set_wol = at803x_set_wol, 20685800091aSDavid Bauer .get_wol = at803x_get_wol, 20695800091aSDavid Bauer .suspend = at803x_suspend, 20705800091aSDavid Bauer .resume = at803x_resume, 20715800091aSDavid Bauer /* PHY_BASIC_FEATURES */ 20725800091aSDavid Bauer .config_intr = at803x_config_intr, 207329773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 2074dc0f3ed1SOleksij Rempel .cable_test_start = at803x_cable_test_start, 2075dc0f3ed1SOleksij Rempel .cable_test_get_status = at803x_cable_test_get_status, 20765800091aSDavid Bauer }, { 20777908d2ceSOleksij Rempel /* ATHEROS AR9331 */ 20787908d2ceSOleksij Rempel PHY_ID_MATCH_EXACT(ATH9331_PHY_ID), 207996c36712SMichael Walle .name = "Qualcomm Atheros AR9331 built-in PHY", 20809926de73SOleksij Rempel .probe = at803x_probe, 20817908d2ceSOleksij Rempel .suspend = at803x_suspend, 20827908d2ceSOleksij Rempel .resume = at803x_resume, 2083dc0f3ed1SOleksij Rempel .flags = PHY_POLL_CABLE_TEST, 20847908d2ceSOleksij Rempel /* PHY_BASIC_FEATURES */ 20857908d2ceSOleksij Rempel .config_intr = &at803x_config_intr, 208629773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 2087dc0f3ed1SOleksij Rempel .cable_test_start = at803x_cable_test_start, 2088dc0f3ed1SOleksij Rempel .cable_test_get_status = at803x_cable_test_get_status, 20897dce80c2SOleksij Rempel .read_status = at803x_read_status, 20907dce80c2SOleksij Rempel .soft_reset = genphy_soft_reset, 20917dce80c2SOleksij Rempel .config_aneg = at803x_config_aneg, 2092272833b9SAnsuel Smith }, { 2093fada2ce0SDavid Bauer /* Qualcomm Atheros QCA9561 */ 2094fada2ce0SDavid Bauer PHY_ID_MATCH_EXACT(QCA9561_PHY_ID), 2095fada2ce0SDavid Bauer .name = "Qualcomm Atheros QCA9561 built-in PHY", 20969926de73SOleksij Rempel .probe = at803x_probe, 2097fada2ce0SDavid Bauer .suspend = at803x_suspend, 2098fada2ce0SDavid Bauer .resume = at803x_resume, 2099fada2ce0SDavid Bauer .flags = PHY_POLL_CABLE_TEST, 2100fada2ce0SDavid Bauer /* PHY_BASIC_FEATURES */ 2101fada2ce0SDavid Bauer .config_intr = &at803x_config_intr, 2102fada2ce0SDavid Bauer .handle_interrupt = at803x_handle_interrupt, 2103fada2ce0SDavid Bauer .cable_test_start = at803x_cable_test_start, 2104fada2ce0SDavid Bauer .cable_test_get_status = at803x_cable_test_get_status, 2105fada2ce0SDavid Bauer .read_status = at803x_read_status, 2106fada2ce0SDavid Bauer .soft_reset = genphy_soft_reset, 2107fada2ce0SDavid Bauer .config_aneg = at803x_config_aneg, 2108fada2ce0SDavid Bauer }, { 2109272833b9SAnsuel Smith /* QCA8337 */ 2110272833b9SAnsuel Smith .phy_id = QCA8337_PHY_ID, 2111272833b9SAnsuel Smith .phy_id_mask = QCA8K_PHY_ID_MASK, 2112d44fd860SAnsuel Smith .name = "Qualcomm Atheros 8337 internal PHY", 2113272833b9SAnsuel Smith /* PHY_GBIT_FEATURES */ 21141ca83119SAnsuel Smith .link_change_notify = qca83xx_link_change_notify, 2115272833b9SAnsuel Smith .probe = at803x_probe, 2116272833b9SAnsuel Smith .flags = PHY_IS_INTERNAL, 2117272833b9SAnsuel Smith .config_init = qca83xx_config_init, 2118272833b9SAnsuel Smith .soft_reset = genphy_soft_reset, 2119272833b9SAnsuel Smith .get_sset_count = at803x_get_sset_count, 2120272833b9SAnsuel Smith .get_strings = at803x_get_strings, 2121272833b9SAnsuel Smith .get_stats = at803x_get_stats, 2122ba3c01eeSAnsuel Smith .suspend = qca83xx_suspend, 2123ba3c01eeSAnsuel Smith .resume = qca83xx_resume, 21240ccf8511SAnsuel Smith }, { 2125b4df02b5SAnsuel Smith /* QCA8327-A from switch QCA8327-AL1A */ 2126b4df02b5SAnsuel Smith .phy_id = QCA8327_A_PHY_ID, 21270ccf8511SAnsuel Smith .phy_id_mask = QCA8K_PHY_ID_MASK, 2128d44fd860SAnsuel Smith .name = "Qualcomm Atheros 8327-A internal PHY", 2129b4df02b5SAnsuel Smith /* PHY_GBIT_FEATURES */ 21301ca83119SAnsuel Smith .link_change_notify = qca83xx_link_change_notify, 2131b4df02b5SAnsuel Smith .probe = at803x_probe, 2132b4df02b5SAnsuel Smith .flags = PHY_IS_INTERNAL, 2133b4df02b5SAnsuel Smith .config_init = qca83xx_config_init, 2134b4df02b5SAnsuel Smith .soft_reset = genphy_soft_reset, 2135b4df02b5SAnsuel Smith .get_sset_count = at803x_get_sset_count, 2136b4df02b5SAnsuel Smith .get_strings = at803x_get_strings, 2137b4df02b5SAnsuel Smith .get_stats = at803x_get_stats, 2138ba3c01eeSAnsuel Smith .suspend = qca83xx_suspend, 2139ba3c01eeSAnsuel Smith .resume = qca83xx_resume, 2140b4df02b5SAnsuel Smith }, { 2141b4df02b5SAnsuel Smith /* QCA8327-B from switch QCA8327-BL1A */ 2142b4df02b5SAnsuel Smith .phy_id = QCA8327_B_PHY_ID, 2143b4df02b5SAnsuel Smith .phy_id_mask = QCA8K_PHY_ID_MASK, 2144d44fd860SAnsuel Smith .name = "Qualcomm Atheros 8327-B internal PHY", 21450ccf8511SAnsuel Smith /* PHY_GBIT_FEATURES */ 21461ca83119SAnsuel Smith .link_change_notify = qca83xx_link_change_notify, 21470ccf8511SAnsuel Smith .probe = at803x_probe, 21480ccf8511SAnsuel Smith .flags = PHY_IS_INTERNAL, 21490ccf8511SAnsuel Smith .config_init = qca83xx_config_init, 21500ccf8511SAnsuel Smith .soft_reset = genphy_soft_reset, 21510ccf8511SAnsuel Smith .get_sset_count = at803x_get_sset_count, 21520ccf8511SAnsuel Smith .get_strings = at803x_get_strings, 21530ccf8511SAnsuel Smith .get_stats = at803x_get_stats, 2154ba3c01eeSAnsuel Smith .suspend = qca83xx_suspend, 2155ba3c01eeSAnsuel Smith .resume = qca83xx_resume, 2156daf61732SLuo Jie }, { 2157daf61732SLuo Jie /* Qualcomm QCA8081 */ 2158daf61732SLuo Jie PHY_ID_MATCH_EXACT(QCA8081_PHY_ID), 2159daf61732SLuo Jie .name = "Qualcomm QCA8081", 21608c84d752SLuo Jie .flags = PHY_POLL_CABLE_TEST, 21619926de73SOleksij Rempel .probe = at803x_probe, 2162daf61732SLuo Jie .config_intr = at803x_config_intr, 2163daf61732SLuo Jie .handle_interrupt = at803x_handle_interrupt, 2164daf61732SLuo Jie .get_tunable = at803x_get_tunable, 2165daf61732SLuo Jie .set_tunable = at803x_set_tunable, 2166daf61732SLuo Jie .set_wol = at803x_set_wol, 2167daf61732SLuo Jie .get_wol = at803x_get_wol, 2168765c22aaSLuo Jie .get_features = at803x_get_features, 2169f884d449SLuo Jie .config_aneg = at803x_config_aneg, 2170daf61732SLuo Jie .suspend = genphy_suspend, 2171daf61732SLuo Jie .resume = genphy_resume, 217279c7bc05SLuo Jie .read_status = qca808x_read_status, 21732acdd43fSLuo Jie .config_init = qca808x_config_init, 21749d4dae29SLuo Jie .soft_reset = qca808x_soft_reset, 21758c84d752SLuo Jie .cable_test_start = qca808x_cable_test_start, 21768c84d752SLuo Jie .cable_test_get_status = qca808x_cable_test_get_status, 2177272833b9SAnsuel Smith }, }; 21780ca7111aSMatus Ujhelyi 217950fd7150SJohan Hovold module_phy_driver(at803x_driver); 21800ca7111aSMatus Ujhelyi 21810ca7111aSMatus Ujhelyi static struct mdio_device_id __maybe_unused atheros_tbl[] = { 21820465d8f8SMichael Walle { ATH8030_PHY_ID, AT8030_PHY_ID_MASK }, 21830465d8f8SMichael Walle { PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) }, 21845800091aSDavid Bauer { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) }, 21850465d8f8SMichael Walle { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) }, 21867908d2ceSOleksij Rempel { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) }, 21870ccf8511SAnsuel Smith { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) }, 2188b4df02b5SAnsuel Smith { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) }, 2189b4df02b5SAnsuel Smith { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) }, 2190fada2ce0SDavid Bauer { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) }, 2191daf61732SLuo Jie { PHY_ID_MATCH_EXACT(QCA8081_PHY_ID) }, 21920ca7111aSMatus Ujhelyi { } 21930ca7111aSMatus Ujhelyi }; 21940ca7111aSMatus Ujhelyi 21950ca7111aSMatus Ujhelyi MODULE_DEVICE_TABLE(mdio, atheros_tbl); 2196