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> 1613a56b44SDaniel Mack #include <linux/of_gpio.h> 172f664823SMichael Walle #include <linux/bitfield.h> 1813a56b44SDaniel Mack #include <linux/gpio/consumer.h> 192f664823SMichael Walle #include <linux/regulator/of_regulator.h> 202f664823SMichael Walle #include <linux/regulator/driver.h> 212f664823SMichael Walle #include <linux/regulator/consumer.h> 22*dc4d5fccSRobert Hancock #include <linux/phylink.h> 23*dc4d5fccSRobert Hancock #include <linux/sfp.h> 242f664823SMichael Walle #include <dt-bindings/net/qca-ar803x.h> 250ca7111aSMatus Ujhelyi 267dce80c2SOleksij Rempel #define AT803X_SPECIFIC_FUNCTION_CONTROL 0x10 277dce80c2SOleksij Rempel #define AT803X_SFC_ASSERT_CRS BIT(11) 287dce80c2SOleksij Rempel #define AT803X_SFC_FORCE_LINK BIT(10) 297dce80c2SOleksij Rempel #define AT803X_SFC_MDI_CROSSOVER_MODE_M GENMASK(6, 5) 307dce80c2SOleksij Rempel #define AT803X_SFC_AUTOMATIC_CROSSOVER 0x3 317dce80c2SOleksij Rempel #define AT803X_SFC_MANUAL_MDIX 0x1 327dce80c2SOleksij Rempel #define AT803X_SFC_MANUAL_MDI 0x0 337dce80c2SOleksij Rempel #define AT803X_SFC_SQE_TEST BIT(2) 347dce80c2SOleksij Rempel #define AT803X_SFC_POLARITY_REVERSAL BIT(1) 357dce80c2SOleksij Rempel #define AT803X_SFC_DISABLE_JABBER BIT(0) 367dce80c2SOleksij Rempel 3706d5f344SRussell King #define AT803X_SPECIFIC_STATUS 0x11 389540cddaSLuo Jie #define AT803X_SS_SPEED_MASK GENMASK(15, 14) 399540cddaSLuo Jie #define AT803X_SS_SPEED_1000 2 409540cddaSLuo Jie #define AT803X_SS_SPEED_100 1 419540cddaSLuo Jie #define AT803X_SS_SPEED_10 0 4206d5f344SRussell King #define AT803X_SS_DUPLEX BIT(13) 4306d5f344SRussell King #define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11) 4406d5f344SRussell King #define AT803X_SS_MDIX BIT(6) 4506d5f344SRussell King 4679c7bc05SLuo Jie #define QCA808X_SS_SPEED_MASK GENMASK(9, 7) 4779c7bc05SLuo Jie #define QCA808X_SS_SPEED_2500 4 4879c7bc05SLuo Jie 490ca7111aSMatus Ujhelyi #define AT803X_INTR_ENABLE 0x12 50e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15) 51e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14) 52e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13) 53e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12) 54e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_LINK_FAIL BIT(11) 55e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10) 563265f421SRobert Hancock #define AT803X_INTR_ENABLE_LINK_FAIL_BX BIT(8) 573265f421SRobert Hancock #define AT803X_INTR_ENABLE_LINK_SUCCESS_BX BIT(7) 58e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5) 59e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1) 60e6e4a556SMartin Blumenstingl #define AT803X_INTR_ENABLE_WOL BIT(0) 61e6e4a556SMartin Blumenstingl 620ca7111aSMatus Ujhelyi #define AT803X_INTR_STATUS 0x13 63a46bd63bSMartin Blumenstingl 6413a56b44SDaniel Mack #define AT803X_SMART_SPEED 0x14 65cde0f4f8SMichael Walle #define AT803X_SMART_SPEED_ENABLE BIT(5) 66cde0f4f8SMichael Walle #define AT803X_SMART_SPEED_RETRY_LIMIT_MASK GENMASK(4, 2) 67cde0f4f8SMichael Walle #define AT803X_SMART_SPEED_BYPASS_TIMER BIT(1) 686cb75767SMichael Walle #define AT803X_CDT 0x16 696cb75767SMichael Walle #define AT803X_CDT_MDI_PAIR_MASK GENMASK(9, 8) 706cb75767SMichael Walle #define AT803X_CDT_ENABLE_TEST BIT(0) 716cb75767SMichael Walle #define AT803X_CDT_STATUS 0x1c 726cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_NORMAL 0 736cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_SHORT 1 746cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_OPEN 2 756cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_FAIL 3 766cb75767SMichael Walle #define AT803X_CDT_STATUS_STAT_MASK GENMASK(9, 8) 776cb75767SMichael Walle #define AT803X_CDT_STATUS_DELTA_TIME_MASK GENMASK(7, 0) 7813a56b44SDaniel Mack #define AT803X_LED_CONTROL 0x18 79a46bd63bSMartin Blumenstingl 807beecaf7SLuo Jie #define AT803X_PHY_MMD3_WOL_CTRL 0x8012 817beecaf7SLuo Jie #define AT803X_WOL_EN BIT(5) 820ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C 830ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B 840ca7111aSMatus Ujhelyi #define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A 85f62265b5SZefir Kurtisi #define AT803X_REG_CHIP_CONFIG 0x1f 86f62265b5SZefir Kurtisi #define AT803X_BT_BX_REG_SEL 0x8000 87a46bd63bSMartin Blumenstingl 881ca6d1b1SMugunthan V N #define AT803X_DEBUG_ADDR 0x1D 891ca6d1b1SMugunthan V N #define AT803X_DEBUG_DATA 0x1E 90a46bd63bSMartin Blumenstingl 91f62265b5SZefir Kurtisi #define AT803X_MODE_CFG_MASK 0x0F 923265f421SRobert Hancock #define AT803X_MODE_CFG_BASET_RGMII 0x00 933265f421SRobert Hancock #define AT803X_MODE_CFG_BASET_SGMII 0x01 943265f421SRobert Hancock #define AT803X_MODE_CFG_BX1000_RGMII_50OHM 0x02 953265f421SRobert Hancock #define AT803X_MODE_CFG_BX1000_RGMII_75OHM 0x03 963265f421SRobert Hancock #define AT803X_MODE_CFG_BX1000_CONV_50OHM 0x04 973265f421SRobert Hancock #define AT803X_MODE_CFG_BX1000_CONV_75OHM 0x05 983265f421SRobert Hancock #define AT803X_MODE_CFG_FX100_RGMII_50OHM 0x06 993265f421SRobert Hancock #define AT803X_MODE_CFG_FX100_CONV_50OHM 0x07 1003265f421SRobert Hancock #define AT803X_MODE_CFG_RGMII_AUTO_MDET 0x0B 1013265f421SRobert Hancock #define AT803X_MODE_CFG_FX100_RGMII_75OHM 0x0E 1023265f421SRobert Hancock #define AT803X_MODE_CFG_FX100_CONV_75OHM 0x0F 103f62265b5SZefir Kurtisi 104f62265b5SZefir Kurtisi #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/ 105f62265b5SZefir Kurtisi #define AT803X_PSSR_MR_AN_COMPLETE 0x0200 106f62265b5SZefir Kurtisi 10767999555SAnsuel Smith #define AT803X_DEBUG_ANALOG_TEST_CTRL 0x00 1081ca83119SAnsuel Smith #define QCA8327_DEBUG_MANU_CTRL_EN BIT(2) 1091ca83119SAnsuel Smith #define QCA8337_DEBUG_MANU_CTRL_EN GENMASK(3, 2) 1102e5f9f28SMartin Blumenstingl #define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15) 111a46bd63bSMartin Blumenstingl 11267999555SAnsuel Smith #define AT803X_DEBUG_SYSTEM_CTRL_MODE 0x05 1132e5f9f28SMartin Blumenstingl #define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8) 1140ca7111aSMatus Ujhelyi 115ba3c01eeSAnsuel Smith #define AT803X_DEBUG_REG_HIB_CTRL 0x0b 116ba3c01eeSAnsuel Smith #define AT803X_DEBUG_HIB_CTRL_SEL_RST_80U BIT(10) 117ba3c01eeSAnsuel Smith #define AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE BIT(13) 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 1952acdd43fSLuo Jie /* ADC threshold */ 1962acdd43fSLuo Jie #define QCA808X_PHY_DEBUG_ADC_THRESHOLD 0x2c80 1972acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_MASK GENMASK(7, 0) 1982acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_80MV 0 1992acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_100MV 0xf0 2002acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_200MV 0x0f 2012acdd43fSLuo Jie #define QCA808X_ADC_THRESHOLD_300MV 0xff 2022acdd43fSLuo Jie 2032acdd43fSLuo Jie /* CLD control */ 2042acdd43fSLuo Jie #define QCA808X_PHY_MMD3_ADDR_CLD_CTRL7 0x8007 2052acdd43fSLuo Jie #define QCA808X_8023AZ_AFE_CTRL_MASK GENMASK(8, 4) 2062acdd43fSLuo Jie #define QCA808X_8023AZ_AFE_EN 0x90 2072acdd43fSLuo Jie 2082acdd43fSLuo Jie /* AZ control */ 2092acdd43fSLuo Jie #define QCA808X_PHY_MMD3_AZ_TRAINING_CTRL 0x8008 2102acdd43fSLuo Jie #define QCA808X_MMD3_AZ_TRAINING_VAL 0x1c32 2112acdd43fSLuo Jie 2122acdd43fSLuo Jie #define QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB 0x8014 2132acdd43fSLuo Jie #define QCA808X_MSE_THRESHOLD_20DB_VALUE 0x529 2142acdd43fSLuo Jie 2152acdd43fSLuo Jie #define QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB 0x800E 2162acdd43fSLuo Jie #define QCA808X_MSE_THRESHOLD_17DB_VALUE 0x341 2172acdd43fSLuo Jie 2182acdd43fSLuo Jie #define QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB 0x801E 2192acdd43fSLuo Jie #define QCA808X_MSE_THRESHOLD_27DB_VALUE 0x419 2202acdd43fSLuo Jie 2212acdd43fSLuo Jie #define QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB 0x8020 2222acdd43fSLuo Jie #define QCA808X_MSE_THRESHOLD_28DB_VALUE 0x341 2232acdd43fSLuo Jie 2242acdd43fSLuo Jie #define QCA808X_PHY_MMD7_TOP_OPTION1 0x901c 2252acdd43fSLuo Jie #define QCA808X_TOP_OPTION1_DATA 0x0 2262acdd43fSLuo Jie 2272acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_1 0xa100 2282acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_1_VALUE 0x9203 2292acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_2 0xa101 2302acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_2_VALUE 0x48ad 2312acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_3 0xa103 2322acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_3_VALUE 0x1698 2332acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_4 0xa105 2342acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_4_VALUE 0x8001 2352acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_5 0xa106 2362acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_5_VALUE 0x1111 2372acdd43fSLuo Jie #define QCA808X_PHY_MMD3_DEBUG_6 0xa011 2382acdd43fSLuo Jie #define QCA808X_MMD3_DEBUG_6_VALUE 0x5f85 2392acdd43fSLuo Jie 2409d4dae29SLuo Jie /* master/slave seed config */ 2419d4dae29SLuo Jie #define QCA808X_PHY_DEBUG_LOCAL_SEED 9 2429d4dae29SLuo Jie #define QCA808X_MASTER_SLAVE_SEED_ENABLE BIT(1) 2439d4dae29SLuo Jie #define QCA808X_MASTER_SLAVE_SEED_CFG GENMASK(12, 2) 2449d4dae29SLuo Jie #define QCA808X_MASTER_SLAVE_SEED_RANGE 0x32 2459d4dae29SLuo Jie 2468c84d752SLuo Jie /* Hibernation yields lower power consumpiton in contrast with normal operation mode. 2478c84d752SLuo Jie * when the copper cable is unplugged, the PHY enters into hibernation mode in about 10s. 2488c84d752SLuo Jie */ 2498c84d752SLuo Jie #define QCA808X_DBG_AN_TEST 0xb 2508c84d752SLuo Jie #define QCA808X_HIBERNATION_EN BIT(15) 2518c84d752SLuo Jie 2528c84d752SLuo Jie #define QCA808X_CDT_ENABLE_TEST BIT(15) 2538c84d752SLuo Jie #define QCA808X_CDT_INTER_CHECK_DIS BIT(13) 2548c84d752SLuo Jie #define QCA808X_CDT_LENGTH_UNIT BIT(10) 2558c84d752SLuo Jie 2568c84d752SLuo Jie #define QCA808X_MMD3_CDT_STATUS 0x8064 2578c84d752SLuo Jie #define QCA808X_MMD3_CDT_DIAG_PAIR_A 0x8065 2588c84d752SLuo Jie #define QCA808X_MMD3_CDT_DIAG_PAIR_B 0x8066 2598c84d752SLuo Jie #define QCA808X_MMD3_CDT_DIAG_PAIR_C 0x8067 2608c84d752SLuo Jie #define QCA808X_MMD3_CDT_DIAG_PAIR_D 0x8068 2618c84d752SLuo Jie #define QCA808X_CDT_DIAG_LENGTH GENMASK(7, 0) 2628c84d752SLuo Jie 2638c84d752SLuo Jie #define QCA808X_CDT_CODE_PAIR_A GENMASK(15, 12) 2648c84d752SLuo Jie #define QCA808X_CDT_CODE_PAIR_B GENMASK(11, 8) 2658c84d752SLuo Jie #define QCA808X_CDT_CODE_PAIR_C GENMASK(7, 4) 2668c84d752SLuo Jie #define QCA808X_CDT_CODE_PAIR_D GENMASK(3, 0) 2678c84d752SLuo Jie #define QCA808X_CDT_STATUS_STAT_FAIL 0 2688c84d752SLuo Jie #define QCA808X_CDT_STATUS_STAT_NORMAL 1 2698c84d752SLuo Jie #define QCA808X_CDT_STATUS_STAT_OPEN 2 2708c84d752SLuo Jie #define QCA808X_CDT_STATUS_STAT_SHORT 3 2718c84d752SLuo Jie 272daf61732SLuo Jie MODULE_DESCRIPTION("Qualcomm Atheros AR803x and QCA808X PHY driver"); 2730ca7111aSMatus Ujhelyi MODULE_AUTHOR("Matus Ujhelyi"); 2740ca7111aSMatus Ujhelyi MODULE_LICENSE("GPL"); 2750ca7111aSMatus Ujhelyi 276272833b9SAnsuel Smith enum stat_access_type { 277272833b9SAnsuel Smith PHY, 278272833b9SAnsuel Smith MMD 279272833b9SAnsuel Smith }; 280272833b9SAnsuel Smith 281272833b9SAnsuel Smith struct at803x_hw_stat { 282272833b9SAnsuel Smith const char *string; 283272833b9SAnsuel Smith u8 reg; 284272833b9SAnsuel Smith u32 mask; 285272833b9SAnsuel Smith enum stat_access_type access_type; 286272833b9SAnsuel Smith }; 287272833b9SAnsuel Smith 288272833b9SAnsuel Smith static struct at803x_hw_stat at803x_hw_stats[] = { 289272833b9SAnsuel Smith { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY}, 290272833b9SAnsuel Smith { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY}, 291272833b9SAnsuel Smith { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD}, 292272833b9SAnsuel Smith }; 293272833b9SAnsuel Smith 2942f664823SMichael Walle struct at803x_priv { 2952f664823SMichael Walle int flags; 2962f664823SMichael Walle u16 clk_25m_reg; 2972f664823SMichael Walle u16 clk_25m_mask; 298390b4cadSRussell King u8 smarteee_lpi_tw_1g; 299390b4cadSRussell King u8 smarteee_lpi_tw_100m; 3003265f421SRobert Hancock bool is_fiber; 3013265f421SRobert Hancock bool is_1000basex; 3022f664823SMichael Walle struct regulator_dev *vddio_rdev; 3032f664823SMichael Walle struct regulator_dev *vddh_rdev; 3042f664823SMichael Walle struct regulator *vddio; 305272833b9SAnsuel Smith u64 stats[ARRAY_SIZE(at803x_hw_stats)]; 3062f664823SMichael Walle }; 3072f664823SMichael Walle 30813a56b44SDaniel Mack struct at803x_context { 30913a56b44SDaniel Mack u16 bmcr; 31013a56b44SDaniel Mack u16 advertise; 31113a56b44SDaniel Mack u16 control1000; 31213a56b44SDaniel Mack u16 int_enable; 31313a56b44SDaniel Mack u16 smart_speed; 31413a56b44SDaniel Mack u16 led_control; 31513a56b44SDaniel Mack }; 31613a56b44SDaniel Mack 317272833b9SAnsuel Smith static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data) 318272833b9SAnsuel Smith { 319272833b9SAnsuel Smith int ret; 320272833b9SAnsuel Smith 321272833b9SAnsuel Smith ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); 322272833b9SAnsuel Smith if (ret < 0) 323272833b9SAnsuel Smith return ret; 324272833b9SAnsuel Smith 325272833b9SAnsuel Smith return phy_write(phydev, AT803X_DEBUG_DATA, data); 326272833b9SAnsuel Smith } 327272833b9SAnsuel Smith 3282e5f9f28SMartin Blumenstingl static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg) 3292e5f9f28SMartin Blumenstingl { 3302e5f9f28SMartin Blumenstingl int ret; 3312e5f9f28SMartin Blumenstingl 3322e5f9f28SMartin Blumenstingl ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); 3332e5f9f28SMartin Blumenstingl if (ret < 0) 3342e5f9f28SMartin Blumenstingl return ret; 3352e5f9f28SMartin Blumenstingl 3362e5f9f28SMartin Blumenstingl return phy_read(phydev, AT803X_DEBUG_DATA); 3372e5f9f28SMartin Blumenstingl } 3382e5f9f28SMartin Blumenstingl 3392e5f9f28SMartin Blumenstingl static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg, 3402e5f9f28SMartin Blumenstingl u16 clear, u16 set) 3412e5f9f28SMartin Blumenstingl { 3422e5f9f28SMartin Blumenstingl u16 val; 3432e5f9f28SMartin Blumenstingl int ret; 3442e5f9f28SMartin Blumenstingl 3452e5f9f28SMartin Blumenstingl ret = at803x_debug_reg_read(phydev, reg); 3462e5f9f28SMartin Blumenstingl if (ret < 0) 3472e5f9f28SMartin Blumenstingl return ret; 3482e5f9f28SMartin Blumenstingl 3492e5f9f28SMartin Blumenstingl val = ret & 0xffff; 3502e5f9f28SMartin Blumenstingl val &= ~clear; 3512e5f9f28SMartin Blumenstingl val |= set; 3522e5f9f28SMartin Blumenstingl 3532e5f9f28SMartin Blumenstingl return phy_write(phydev, AT803X_DEBUG_DATA, val); 3542e5f9f28SMartin Blumenstingl } 3552e5f9f28SMartin Blumenstingl 356c329e5afSDavid Bauer static int at803x_write_page(struct phy_device *phydev, int page) 357c329e5afSDavid Bauer { 358c329e5afSDavid Bauer int mask; 359c329e5afSDavid Bauer int set; 360c329e5afSDavid Bauer 361c329e5afSDavid Bauer if (page == AT803X_PAGE_COPPER) { 362c329e5afSDavid Bauer set = AT803X_BT_BX_REG_SEL; 363c329e5afSDavid Bauer mask = 0; 364c329e5afSDavid Bauer } else { 365c329e5afSDavid Bauer set = 0; 366c329e5afSDavid Bauer mask = AT803X_BT_BX_REG_SEL; 367c329e5afSDavid Bauer } 368c329e5afSDavid Bauer 369c329e5afSDavid Bauer return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set); 370c329e5afSDavid Bauer } 371c329e5afSDavid Bauer 372c329e5afSDavid Bauer static int at803x_read_page(struct phy_device *phydev) 373c329e5afSDavid Bauer { 374c329e5afSDavid Bauer int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG); 375c329e5afSDavid Bauer 376c329e5afSDavid Bauer if (ccr < 0) 377c329e5afSDavid Bauer return ccr; 378c329e5afSDavid Bauer 379c329e5afSDavid Bauer if (ccr & AT803X_BT_BX_REG_SEL) 380c329e5afSDavid Bauer return AT803X_PAGE_COPPER; 381c329e5afSDavid Bauer 382c329e5afSDavid Bauer return AT803X_PAGE_FIBER; 383c329e5afSDavid Bauer } 384c329e5afSDavid Bauer 3856d4cd041SVinod Koul static int at803x_enable_rx_delay(struct phy_device *phydev) 3866d4cd041SVinod Koul { 38767999555SAnsuel Smith return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0, 3886d4cd041SVinod Koul AT803X_DEBUG_RX_CLK_DLY_EN); 3896d4cd041SVinod Koul } 3906d4cd041SVinod Koul 3916d4cd041SVinod Koul static int at803x_enable_tx_delay(struct phy_device *phydev) 3926d4cd041SVinod Koul { 39367999555SAnsuel Smith return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0, 3946d4cd041SVinod Koul AT803X_DEBUG_TX_CLK_DLY_EN); 3956d4cd041SVinod Koul } 3966d4cd041SVinod Koul 39743f2ebd5SVinod Koul static int at803x_disable_rx_delay(struct phy_device *phydev) 3982e5f9f28SMartin Blumenstingl { 39967999555SAnsuel Smith return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 400cd28d1d6SVinod Koul AT803X_DEBUG_RX_CLK_DLY_EN, 0); 4012e5f9f28SMartin Blumenstingl } 4022e5f9f28SMartin Blumenstingl 40343f2ebd5SVinod Koul static int at803x_disable_tx_delay(struct phy_device *phydev) 4042e5f9f28SMartin Blumenstingl { 40567999555SAnsuel Smith return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 406cd28d1d6SVinod Koul AT803X_DEBUG_TX_CLK_DLY_EN, 0); 4072e5f9f28SMartin Blumenstingl } 4082e5f9f28SMartin Blumenstingl 40913a56b44SDaniel Mack /* save relevant PHY registers to private copy */ 41013a56b44SDaniel Mack static void at803x_context_save(struct phy_device *phydev, 41113a56b44SDaniel Mack struct at803x_context *context) 41213a56b44SDaniel Mack { 41313a56b44SDaniel Mack context->bmcr = phy_read(phydev, MII_BMCR); 41413a56b44SDaniel Mack context->advertise = phy_read(phydev, MII_ADVERTISE); 41513a56b44SDaniel Mack context->control1000 = phy_read(phydev, MII_CTRL1000); 41613a56b44SDaniel Mack context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE); 41713a56b44SDaniel Mack context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED); 41813a56b44SDaniel Mack context->led_control = phy_read(phydev, AT803X_LED_CONTROL); 41913a56b44SDaniel Mack } 42013a56b44SDaniel Mack 42113a56b44SDaniel Mack /* restore relevant PHY registers from private copy */ 42213a56b44SDaniel Mack static void at803x_context_restore(struct phy_device *phydev, 42313a56b44SDaniel Mack const struct at803x_context *context) 42413a56b44SDaniel Mack { 42513a56b44SDaniel Mack phy_write(phydev, MII_BMCR, context->bmcr); 42613a56b44SDaniel Mack phy_write(phydev, MII_ADVERTISE, context->advertise); 42713a56b44SDaniel Mack phy_write(phydev, MII_CTRL1000, context->control1000); 42813a56b44SDaniel Mack phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable); 42913a56b44SDaniel Mack phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed); 43013a56b44SDaniel Mack phy_write(phydev, AT803X_LED_CONTROL, context->led_control); 43113a56b44SDaniel Mack } 43213a56b44SDaniel Mack 433ea13c9eeSMugunthan V N static int at803x_set_wol(struct phy_device *phydev, 434ea13c9eeSMugunthan V N struct ethtool_wolinfo *wol) 4350ca7111aSMatus Ujhelyi { 4360ca7111aSMatus Ujhelyi struct net_device *ndev = phydev->attached_dev; 4370ca7111aSMatus Ujhelyi const u8 *mac; 4387beecaf7SLuo Jie int ret, irq_enabled; 439c0f0b563SLuo Jie unsigned int i; 440edcb501eSColin Ian King static const unsigned int offsets[] = { 4410ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_32_47_OFFSET, 4420ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_16_31_OFFSET, 4430ca7111aSMatus Ujhelyi AT803X_LOC_MAC_ADDR_0_15_OFFSET, 4440ca7111aSMatus Ujhelyi }; 4450ca7111aSMatus Ujhelyi 4460ca7111aSMatus Ujhelyi if (!ndev) 447ea13c9eeSMugunthan V N return -ENODEV; 4480ca7111aSMatus Ujhelyi 449ea13c9eeSMugunthan V N if (wol->wolopts & WAKE_MAGIC) { 4500ca7111aSMatus Ujhelyi mac = (const u8 *) ndev->dev_addr; 4510ca7111aSMatus Ujhelyi 4520ca7111aSMatus Ujhelyi if (!is_valid_ether_addr(mac)) 453fc755687SDan Murphy return -EINVAL; 4540ca7111aSMatus Ujhelyi 4550e021396SCarlo Caione for (i = 0; i < 3; i++) 456c0f0b563SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, offsets[i], 4570ca7111aSMatus Ujhelyi mac[(i * 2) + 1] | (mac[(i * 2)] << 8)); 458ea13c9eeSMugunthan V N 4597beecaf7SLuo Jie /* Enable WOL function */ 4607beecaf7SLuo Jie ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL, 4617beecaf7SLuo Jie 0, AT803X_WOL_EN); 4627beecaf7SLuo Jie if (ret) 4637beecaf7SLuo Jie return ret; 4647beecaf7SLuo Jie /* Enable WOL interrupt */ 4652d4284e8SLuo Jie ret = phy_modify(phydev, AT803X_INTR_ENABLE, 0, AT803X_INTR_ENABLE_WOL); 466ea13c9eeSMugunthan V N if (ret) 467ea13c9eeSMugunthan V N return ret; 468ea13c9eeSMugunthan V N } else { 4697beecaf7SLuo Jie /* Disable WoL function */ 4707beecaf7SLuo Jie ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL, 4717beecaf7SLuo Jie AT803X_WOL_EN, 0); 4727beecaf7SLuo Jie if (ret) 4737beecaf7SLuo Jie return ret; 4747beecaf7SLuo Jie /* Disable WOL interrupt */ 4752d4284e8SLuo Jie ret = phy_modify(phydev, AT803X_INTR_ENABLE, AT803X_INTR_ENABLE_WOL, 0); 476ea13c9eeSMugunthan V N if (ret) 477ea13c9eeSMugunthan V N return ret; 478ea13c9eeSMugunthan V N } 479ea13c9eeSMugunthan V N 4807beecaf7SLuo Jie /* Clear WOL status */ 4817beecaf7SLuo Jie ret = phy_read(phydev, AT803X_INTR_STATUS); 4827beecaf7SLuo Jie if (ret < 0) 483ea13c9eeSMugunthan V N return ret; 4847beecaf7SLuo Jie 4857beecaf7SLuo Jie /* Check if there are other interrupts except for WOL triggered when PHY is 4867beecaf7SLuo Jie * in interrupt mode, only the interrupts enabled by AT803X_INTR_ENABLE can 4877beecaf7SLuo Jie * be passed up to the interrupt PIN. 4887beecaf7SLuo Jie */ 4897beecaf7SLuo Jie irq_enabled = phy_read(phydev, AT803X_INTR_ENABLE); 4907beecaf7SLuo Jie if (irq_enabled < 0) 4917beecaf7SLuo Jie return irq_enabled; 4927beecaf7SLuo Jie 4937beecaf7SLuo Jie irq_enabled &= ~AT803X_INTR_ENABLE_WOL; 4947beecaf7SLuo Jie if (ret & irq_enabled && !phy_polling_mode(phydev)) 4957beecaf7SLuo Jie phy_trigger_machine(phydev); 4967beecaf7SLuo Jie 4977beecaf7SLuo Jie return 0; 498ea13c9eeSMugunthan V N } 499ea13c9eeSMugunthan V N 500ea13c9eeSMugunthan V N static void at803x_get_wol(struct phy_device *phydev, 501ea13c9eeSMugunthan V N struct ethtool_wolinfo *wol) 502ea13c9eeSMugunthan V N { 503911e3a46SJiapeng Chong int value; 504ea13c9eeSMugunthan V N 505ea13c9eeSMugunthan V N wol->supported = WAKE_MAGIC; 506ea13c9eeSMugunthan V N wol->wolopts = 0; 507ea13c9eeSMugunthan V N 5087beecaf7SLuo Jie value = phy_read_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL); 5097beecaf7SLuo Jie if (value < 0) 5107beecaf7SLuo Jie return; 5117beecaf7SLuo Jie 5127beecaf7SLuo Jie if (value & AT803X_WOL_EN) 513ea13c9eeSMugunthan V N wol->wolopts |= WAKE_MAGIC; 5140ca7111aSMatus Ujhelyi } 5150ca7111aSMatus Ujhelyi 516272833b9SAnsuel Smith static int at803x_get_sset_count(struct phy_device *phydev) 517272833b9SAnsuel Smith { 518272833b9SAnsuel Smith return ARRAY_SIZE(at803x_hw_stats); 519272833b9SAnsuel Smith } 520272833b9SAnsuel Smith 521272833b9SAnsuel Smith static void at803x_get_strings(struct phy_device *phydev, u8 *data) 522272833b9SAnsuel Smith { 523272833b9SAnsuel Smith int i; 524272833b9SAnsuel Smith 525272833b9SAnsuel Smith for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) { 526272833b9SAnsuel Smith strscpy(data + i * ETH_GSTRING_LEN, 527272833b9SAnsuel Smith at803x_hw_stats[i].string, ETH_GSTRING_LEN); 528272833b9SAnsuel Smith } 529272833b9SAnsuel Smith } 530272833b9SAnsuel Smith 531272833b9SAnsuel Smith static u64 at803x_get_stat(struct phy_device *phydev, int i) 532272833b9SAnsuel Smith { 533272833b9SAnsuel Smith struct at803x_hw_stat stat = at803x_hw_stats[i]; 534272833b9SAnsuel Smith struct at803x_priv *priv = phydev->priv; 535272833b9SAnsuel Smith int val; 536272833b9SAnsuel Smith u64 ret; 537272833b9SAnsuel Smith 538272833b9SAnsuel Smith if (stat.access_type == MMD) 539272833b9SAnsuel Smith val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg); 540272833b9SAnsuel Smith else 541272833b9SAnsuel Smith val = phy_read(phydev, stat.reg); 542272833b9SAnsuel Smith 543272833b9SAnsuel Smith if (val < 0) { 544272833b9SAnsuel Smith ret = U64_MAX; 545272833b9SAnsuel Smith } else { 546272833b9SAnsuel Smith val = val & stat.mask; 547272833b9SAnsuel Smith priv->stats[i] += val; 548272833b9SAnsuel Smith ret = priv->stats[i]; 549272833b9SAnsuel Smith } 550272833b9SAnsuel Smith 551272833b9SAnsuel Smith return ret; 552272833b9SAnsuel Smith } 553272833b9SAnsuel Smith 554272833b9SAnsuel Smith static void at803x_get_stats(struct phy_device *phydev, 555272833b9SAnsuel Smith struct ethtool_stats *stats, u64 *data) 556272833b9SAnsuel Smith { 557272833b9SAnsuel Smith int i; 558272833b9SAnsuel Smith 559272833b9SAnsuel Smith for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) 560272833b9SAnsuel Smith data[i] = at803x_get_stat(phydev, i); 561272833b9SAnsuel Smith } 562272833b9SAnsuel Smith 5636229ed1fSDaniel Mack static int at803x_suspend(struct phy_device *phydev) 5646229ed1fSDaniel Mack { 5656229ed1fSDaniel Mack int value; 5666229ed1fSDaniel Mack int wol_enabled; 5676229ed1fSDaniel Mack 5686229ed1fSDaniel Mack value = phy_read(phydev, AT803X_INTR_ENABLE); 569e6e4a556SMartin Blumenstingl wol_enabled = value & AT803X_INTR_ENABLE_WOL; 5706229ed1fSDaniel Mack 5716229ed1fSDaniel Mack if (wol_enabled) 572fea23fb5SRussell King value = BMCR_ISOLATE; 5736229ed1fSDaniel Mack else 574fea23fb5SRussell King value = BMCR_PDOWN; 5756229ed1fSDaniel Mack 576fea23fb5SRussell King phy_modify(phydev, MII_BMCR, 0, value); 5776229ed1fSDaniel Mack 5786229ed1fSDaniel Mack return 0; 5796229ed1fSDaniel Mack } 5806229ed1fSDaniel Mack 5816229ed1fSDaniel Mack static int at803x_resume(struct phy_device *phydev) 5826229ed1fSDaniel Mack { 583f102852fSRussell King return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0); 5846229ed1fSDaniel Mack } 5856229ed1fSDaniel Mack 5862f664823SMichael Walle static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev, 5872f664823SMichael Walle unsigned int selector) 5882f664823SMichael Walle { 5892f664823SMichael Walle struct phy_device *phydev = rdev_get_drvdata(rdev); 5902f664823SMichael Walle 5912f664823SMichael Walle if (selector) 5922f664823SMichael Walle return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, 5932f664823SMichael Walle 0, AT803X_DEBUG_RGMII_1V8); 5942f664823SMichael Walle else 5952f664823SMichael Walle return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, 5962f664823SMichael Walle AT803X_DEBUG_RGMII_1V8, 0); 5972f664823SMichael Walle } 5982f664823SMichael Walle 5992f664823SMichael Walle static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev) 6002f664823SMichael Walle { 6012f664823SMichael Walle struct phy_device *phydev = rdev_get_drvdata(rdev); 6022f664823SMichael Walle int val; 6032f664823SMichael Walle 6042f664823SMichael Walle val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F); 6052f664823SMichael Walle if (val < 0) 6062f664823SMichael Walle return val; 6072f664823SMichael Walle 6082f664823SMichael Walle return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0; 6092f664823SMichael Walle } 6102f664823SMichael Walle 6113faaf539SRikard Falkeborn static const struct regulator_ops vddio_regulator_ops = { 6122f664823SMichael Walle .list_voltage = regulator_list_voltage_table, 6132f664823SMichael Walle .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel, 6142f664823SMichael Walle .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel, 6152f664823SMichael Walle }; 6162f664823SMichael Walle 6172f664823SMichael Walle static const unsigned int vddio_voltage_table[] = { 6182f664823SMichael Walle 1500000, 6192f664823SMichael Walle 1800000, 6202f664823SMichael Walle }; 6212f664823SMichael Walle 6222f664823SMichael Walle static const struct regulator_desc vddio_desc = { 6232f664823SMichael Walle .name = "vddio", 6242f664823SMichael Walle .of_match = of_match_ptr("vddio-regulator"), 6252f664823SMichael Walle .n_voltages = ARRAY_SIZE(vddio_voltage_table), 6262f664823SMichael Walle .volt_table = vddio_voltage_table, 6272f664823SMichael Walle .ops = &vddio_regulator_ops, 6282f664823SMichael Walle .type = REGULATOR_VOLTAGE, 6292f664823SMichael Walle .owner = THIS_MODULE, 6302f664823SMichael Walle }; 6312f664823SMichael Walle 6323faaf539SRikard Falkeborn static const struct regulator_ops vddh_regulator_ops = { 6332f664823SMichael Walle }; 6342f664823SMichael Walle 6352f664823SMichael Walle static const struct regulator_desc vddh_desc = { 6362f664823SMichael Walle .name = "vddh", 6372f664823SMichael Walle .of_match = of_match_ptr("vddh-regulator"), 6382f664823SMichael Walle .n_voltages = 1, 6392f664823SMichael Walle .fixed_uV = 2500000, 6402f664823SMichael Walle .ops = &vddh_regulator_ops, 6412f664823SMichael Walle .type = REGULATOR_VOLTAGE, 6422f664823SMichael Walle .owner = THIS_MODULE, 6432f664823SMichael Walle }; 6442f664823SMichael Walle 6452f664823SMichael Walle static int at8031_register_regulators(struct phy_device *phydev) 6462f664823SMichael Walle { 6472f664823SMichael Walle struct at803x_priv *priv = phydev->priv; 6482f664823SMichael Walle struct device *dev = &phydev->mdio.dev; 6492f664823SMichael Walle struct regulator_config config = { }; 6502f664823SMichael Walle 6512f664823SMichael Walle config.dev = dev; 6522f664823SMichael Walle config.driver_data = phydev; 6532f664823SMichael Walle 6542f664823SMichael Walle priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config); 6552f664823SMichael Walle if (IS_ERR(priv->vddio_rdev)) { 6562f664823SMichael Walle phydev_err(phydev, "failed to register VDDIO regulator\n"); 6572f664823SMichael Walle return PTR_ERR(priv->vddio_rdev); 6582f664823SMichael Walle } 6592f664823SMichael Walle 6602f664823SMichael Walle priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config); 6612f664823SMichael Walle if (IS_ERR(priv->vddh_rdev)) { 6622f664823SMichael Walle phydev_err(phydev, "failed to register VDDH regulator\n"); 6632f664823SMichael Walle return PTR_ERR(priv->vddh_rdev); 6642f664823SMichael Walle } 6652f664823SMichael Walle 6662f664823SMichael Walle return 0; 6672f664823SMichael Walle } 6682f664823SMichael Walle 669*dc4d5fccSRobert Hancock static int at803x_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) 670*dc4d5fccSRobert Hancock { 671*dc4d5fccSRobert Hancock struct phy_device *phydev = upstream; 672*dc4d5fccSRobert Hancock __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support); 673*dc4d5fccSRobert Hancock __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); 674*dc4d5fccSRobert Hancock phy_interface_t iface; 675*dc4d5fccSRobert Hancock 676*dc4d5fccSRobert Hancock linkmode_zero(phy_support); 677*dc4d5fccSRobert Hancock phylink_set(phy_support, 1000baseX_Full); 678*dc4d5fccSRobert Hancock phylink_set(phy_support, 1000baseT_Full); 679*dc4d5fccSRobert Hancock phylink_set(phy_support, Autoneg); 680*dc4d5fccSRobert Hancock phylink_set(phy_support, Pause); 681*dc4d5fccSRobert Hancock phylink_set(phy_support, Asym_Pause); 682*dc4d5fccSRobert Hancock 683*dc4d5fccSRobert Hancock linkmode_zero(sfp_support); 684*dc4d5fccSRobert Hancock sfp_parse_support(phydev->sfp_bus, id, sfp_support); 685*dc4d5fccSRobert Hancock /* Some modules support 10G modes as well as others we support. 686*dc4d5fccSRobert Hancock * Mask out non-supported modes so the correct interface is picked. 687*dc4d5fccSRobert Hancock */ 688*dc4d5fccSRobert Hancock linkmode_and(sfp_support, phy_support, sfp_support); 689*dc4d5fccSRobert Hancock 690*dc4d5fccSRobert Hancock if (linkmode_empty(sfp_support)) { 691*dc4d5fccSRobert Hancock dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n"); 692*dc4d5fccSRobert Hancock return -EINVAL; 693*dc4d5fccSRobert Hancock } 694*dc4d5fccSRobert Hancock 695*dc4d5fccSRobert Hancock iface = sfp_select_interface(phydev->sfp_bus, sfp_support); 696*dc4d5fccSRobert Hancock 697*dc4d5fccSRobert Hancock /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes 698*dc4d5fccSRobert Hancock * interface for use with SFP modules. 699*dc4d5fccSRobert Hancock * However, some copper modules detected as having a preferred SGMII 700*dc4d5fccSRobert Hancock * interface do default to and function in 1000Base-X mode, so just 701*dc4d5fccSRobert Hancock * print a warning and allow such modules, as they may have some chance 702*dc4d5fccSRobert Hancock * of working. 703*dc4d5fccSRobert Hancock */ 704*dc4d5fccSRobert Hancock if (iface == PHY_INTERFACE_MODE_SGMII) 705*dc4d5fccSRobert Hancock dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n"); 706*dc4d5fccSRobert Hancock else if (iface != PHY_INTERFACE_MODE_1000BASEX) 707*dc4d5fccSRobert Hancock return -EINVAL; 708*dc4d5fccSRobert Hancock 709*dc4d5fccSRobert Hancock return 0; 710*dc4d5fccSRobert Hancock } 711*dc4d5fccSRobert Hancock 712*dc4d5fccSRobert Hancock static const struct sfp_upstream_ops at803x_sfp_ops = { 713*dc4d5fccSRobert Hancock .attach = phy_sfp_attach, 714*dc4d5fccSRobert Hancock .detach = phy_sfp_detach, 715*dc4d5fccSRobert Hancock .module_insert = at803x_sfp_insert, 716*dc4d5fccSRobert Hancock }; 717*dc4d5fccSRobert Hancock 7182f664823SMichael Walle static int at803x_parse_dt(struct phy_device *phydev) 7192f664823SMichael Walle { 7202f664823SMichael Walle struct device_node *node = phydev->mdio.dev.of_node; 7212f664823SMichael Walle struct at803x_priv *priv = phydev->priv; 722390b4cadSRussell King u32 freq, strength, tw; 7233f2edd30SAndrew Lunn unsigned int sel; 7242f664823SMichael Walle int ret; 7252f664823SMichael Walle 7262f664823SMichael Walle if (!IS_ENABLED(CONFIG_OF_MDIO)) 7272f664823SMichael Walle return 0; 7282f664823SMichael Walle 729390b4cadSRussell King if (of_property_read_bool(node, "qca,disable-smarteee")) 730390b4cadSRussell King priv->flags |= AT803X_DISABLE_SMARTEEE; 731390b4cadSRussell King 732390b4cadSRussell King if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) { 733390b4cadSRussell King if (!tw || tw > 255) { 734390b4cadSRussell King phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n"); 735390b4cadSRussell King return -EINVAL; 736390b4cadSRussell King } 737390b4cadSRussell King priv->smarteee_lpi_tw_1g = tw; 738390b4cadSRussell King } 739390b4cadSRussell King 740390b4cadSRussell King if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) { 741390b4cadSRussell King if (!tw || tw > 255) { 742390b4cadSRussell King phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n"); 743390b4cadSRussell King return -EINVAL; 744390b4cadSRussell King } 745390b4cadSRussell King priv->smarteee_lpi_tw_100m = tw; 746390b4cadSRussell King } 747390b4cadSRussell King 7482f664823SMichael Walle ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq); 7492f664823SMichael Walle if (!ret) { 7502f664823SMichael Walle switch (freq) { 7512f664823SMichael Walle case 25000000: 7522f664823SMichael Walle sel = AT803X_CLK_OUT_25MHZ_XTAL; 7532f664823SMichael Walle break; 7542f664823SMichael Walle case 50000000: 7552f664823SMichael Walle sel = AT803X_CLK_OUT_50MHZ_PLL; 7562f664823SMichael Walle break; 7572f664823SMichael Walle case 62500000: 7582f664823SMichael Walle sel = AT803X_CLK_OUT_62_5MHZ_PLL; 7592f664823SMichael Walle break; 7602f664823SMichael Walle case 125000000: 7612f664823SMichael Walle sel = AT803X_CLK_OUT_125MHZ_PLL; 7622f664823SMichael Walle break; 7632f664823SMichael Walle default: 7642f664823SMichael Walle phydev_err(phydev, "invalid qca,clk-out-frequency\n"); 7652f664823SMichael Walle return -EINVAL; 7662f664823SMichael Walle } 7672f664823SMichael Walle 7683f2edd30SAndrew Lunn priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel); 7693f2edd30SAndrew Lunn priv->clk_25m_mask |= AT803X_CLK_OUT_MASK; 7702f664823SMichael Walle 7712f664823SMichael Walle /* Fixup for the AR8030/AR8035. This chip has another mask and 7722f664823SMichael Walle * doesn't support the DSP reference. Eg. the lowest bit of the 7732f664823SMichael Walle * mask. The upper two bits select the same frequencies. Mask 7742f664823SMichael Walle * the lowest bit here. 7752f664823SMichael Walle * 7762f664823SMichael Walle * Warning: 7772f664823SMichael Walle * There was no datasheet for the AR8030 available so this is 7782f664823SMichael Walle * just a guess. But the AR8035 is listed as pin compatible 7792f664823SMichael Walle * to the AR8030 so there might be a good chance it works on 7802f664823SMichael Walle * the AR8030 too. 7812f664823SMichael Walle */ 7828887ca54SRussell King if (phydev->drv->phy_id == ATH8030_PHY_ID || 7838887ca54SRussell King phydev->drv->phy_id == ATH8035_PHY_ID) { 784b1f4c209SOleksij Rempel priv->clk_25m_reg &= AT8035_CLK_OUT_MASK; 785b1f4c209SOleksij Rempel priv->clk_25m_mask &= AT8035_CLK_OUT_MASK; 7862f664823SMichael Walle } 7872f664823SMichael Walle } 7882f664823SMichael Walle 7892f664823SMichael Walle ret = of_property_read_u32(node, "qca,clk-out-strength", &strength); 7902f664823SMichael Walle if (!ret) { 7912f664823SMichael Walle priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK; 7922f664823SMichael Walle switch (strength) { 7932f664823SMichael Walle case AR803X_STRENGTH_FULL: 7942f664823SMichael Walle priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL; 7952f664823SMichael Walle break; 7962f664823SMichael Walle case AR803X_STRENGTH_HALF: 7972f664823SMichael Walle priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF; 7982f664823SMichael Walle break; 7992f664823SMichael Walle case AR803X_STRENGTH_QUARTER: 8002f664823SMichael Walle priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER; 8012f664823SMichael Walle break; 8022f664823SMichael Walle default: 8032f664823SMichael Walle phydev_err(phydev, "invalid qca,clk-out-strength\n"); 8042f664823SMichael Walle return -EINVAL; 8052f664823SMichael Walle } 8062f664823SMichael Walle } 8072f664823SMichael Walle 808428061f7SMichael Walle /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping 809428061f7SMichael Walle * options. 810428061f7SMichael Walle */ 8118887ca54SRussell King if (phydev->drv->phy_id == ATH8031_PHY_ID) { 8122f664823SMichael Walle if (of_property_read_bool(node, "qca,keep-pll-enabled")) 8132f664823SMichael Walle priv->flags |= AT803X_KEEP_PLL_ENABLED; 8142f664823SMichael Walle 8152f664823SMichael Walle ret = at8031_register_regulators(phydev); 8162f664823SMichael Walle if (ret < 0) 8172f664823SMichael Walle return ret; 8182f664823SMichael Walle 8192f664823SMichael Walle priv->vddio = devm_regulator_get_optional(&phydev->mdio.dev, 8202f664823SMichael Walle "vddio"); 8212f664823SMichael Walle if (IS_ERR(priv->vddio)) { 8222f664823SMichael Walle phydev_err(phydev, "failed to get VDDIO regulator\n"); 8232f664823SMichael Walle return PTR_ERR(priv->vddio); 8242f664823SMichael Walle } 825*dc4d5fccSRobert Hancock 826*dc4d5fccSRobert Hancock /* Only AR8031/8033 support 1000Base-X for SFP modules */ 827*dc4d5fccSRobert Hancock ret = phy_sfp_probe(phydev, &at803x_sfp_ops); 828*dc4d5fccSRobert Hancock if (ret < 0) 829*dc4d5fccSRobert Hancock return ret; 8302f664823SMichael Walle } 8312f664823SMichael Walle 8322f664823SMichael Walle return 0; 8332f664823SMichael Walle } 8342f664823SMichael Walle 8352f664823SMichael Walle static int at803x_probe(struct phy_device *phydev) 8362f664823SMichael Walle { 8372f664823SMichael Walle struct device *dev = &phydev->mdio.dev; 8382f664823SMichael Walle struct at803x_priv *priv; 839c329e5afSDavid Bauer int ret; 8402f664823SMichael Walle 8412f664823SMichael Walle priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 8422f664823SMichael Walle if (!priv) 8432f664823SMichael Walle return -ENOMEM; 8442f664823SMichael Walle 8452f664823SMichael Walle phydev->priv = priv; 8462f664823SMichael Walle 847c329e5afSDavid Bauer ret = at803x_parse_dt(phydev); 848c329e5afSDavid Bauer if (ret) 849c329e5afSDavid Bauer return ret; 850c329e5afSDavid Bauer 8518f7e8762SMichael Walle if (priv->vddio) { 8528f7e8762SMichael Walle ret = regulator_enable(priv->vddio); 8538f7e8762SMichael Walle if (ret < 0) 8548f7e8762SMichael Walle return ret; 8558f7e8762SMichael Walle } 8568f7e8762SMichael Walle 8573265f421SRobert Hancock if (phydev->drv->phy_id == ATH8031_PHY_ID) { 8583265f421SRobert Hancock int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG); 8593265f421SRobert Hancock int mode_cfg; 8603265f421SRobert Hancock 8613265f421SRobert Hancock if (ccr < 0) 8623265f421SRobert Hancock goto err; 8633265f421SRobert Hancock mode_cfg = ccr & AT803X_MODE_CFG_MASK; 8643265f421SRobert Hancock 8653265f421SRobert Hancock switch (mode_cfg) { 8663265f421SRobert Hancock case AT803X_MODE_CFG_BX1000_RGMII_50OHM: 8673265f421SRobert Hancock case AT803X_MODE_CFG_BX1000_RGMII_75OHM: 8683265f421SRobert Hancock priv->is_1000basex = true; 8693265f421SRobert Hancock fallthrough; 8703265f421SRobert Hancock case AT803X_MODE_CFG_FX100_RGMII_50OHM: 8713265f421SRobert Hancock case AT803X_MODE_CFG_FX100_RGMII_75OHM: 8723265f421SRobert Hancock priv->is_fiber = true; 8733265f421SRobert Hancock break; 8743265f421SRobert Hancock } 8753265f421SRobert Hancock } 8763265f421SRobert Hancock 8778f7e8762SMichael Walle return 0; 8783265f421SRobert Hancock 8793265f421SRobert Hancock err: 8803265f421SRobert Hancock if (priv->vddio) 8813265f421SRobert Hancock regulator_disable(priv->vddio); 8823265f421SRobert Hancock 8833265f421SRobert Hancock return ret; 8842f664823SMichael Walle } 8852f664823SMichael Walle 8862318ca8aSMichael Walle static void at803x_remove(struct phy_device *phydev) 8872318ca8aSMichael Walle { 8882318ca8aSMichael Walle struct at803x_priv *priv = phydev->priv; 8892318ca8aSMichael Walle 8902318ca8aSMichael Walle if (priv->vddio) 8912318ca8aSMichael Walle regulator_disable(priv->vddio); 8922318ca8aSMichael Walle } 8932318ca8aSMichael Walle 894b856150cSDavid Bauer static int at803x_get_features(struct phy_device *phydev) 895b856150cSDavid Bauer { 8963265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 897b856150cSDavid Bauer int err; 898b856150cSDavid Bauer 899b856150cSDavid Bauer err = genphy_read_abilities(phydev); 900b856150cSDavid Bauer if (err) 901b856150cSDavid Bauer return err; 902b856150cSDavid Bauer 903765c22aaSLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) { 904765c22aaSLuo Jie err = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_NG_EXTABLE); 905765c22aaSLuo Jie if (err < 0) 906765c22aaSLuo Jie return err; 907765c22aaSLuo Jie 908765c22aaSLuo Jie linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported, 909765c22aaSLuo Jie err & MDIO_PMA_NG_EXTABLE_2_5GBT); 910765c22aaSLuo Jie } 911765c22aaSLuo Jie 912f5621a01SVladimir Oltean if (phydev->drv->phy_id != ATH8031_PHY_ID) 913b856150cSDavid Bauer return 0; 914b856150cSDavid Bauer 915b856150cSDavid Bauer /* AR8031/AR8033 have different status registers 916b856150cSDavid Bauer * for copper and fiber operation. However, the 917b856150cSDavid Bauer * extended status register is the same for both 918b856150cSDavid Bauer * operation modes. 919b856150cSDavid Bauer * 920b856150cSDavid Bauer * As a result of that, ESTATUS_1000_XFULL is set 921b856150cSDavid Bauer * to 1 even when operating in copper TP mode. 922b856150cSDavid Bauer * 9233265f421SRobert Hancock * Remove this mode from the supported link modes 9243265f421SRobert Hancock * when not operating in 1000BaseX mode. 925b856150cSDavid Bauer */ 9263265f421SRobert Hancock if (!priv->is_1000basex) 927b856150cSDavid Bauer linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, 928b856150cSDavid Bauer phydev->supported); 9293265f421SRobert Hancock 930b856150cSDavid Bauer return 0; 931b856150cSDavid Bauer } 932b856150cSDavid Bauer 933390b4cadSRussell King static int at803x_smarteee_config(struct phy_device *phydev) 934390b4cadSRussell King { 935390b4cadSRussell King struct at803x_priv *priv = phydev->priv; 936390b4cadSRussell King u16 mask = 0, val = 0; 937390b4cadSRussell King int ret; 938390b4cadSRussell King 939390b4cadSRussell King if (priv->flags & AT803X_DISABLE_SMARTEEE) 940390b4cadSRussell King return phy_modify_mmd(phydev, MDIO_MMD_PCS, 941390b4cadSRussell King AT803X_MMD3_SMARTEEE_CTL3, 942390b4cadSRussell King AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0); 943390b4cadSRussell King 944390b4cadSRussell King if (priv->smarteee_lpi_tw_1g) { 945390b4cadSRussell King mask |= 0xff00; 946390b4cadSRussell King val |= priv->smarteee_lpi_tw_1g << 8; 947390b4cadSRussell King } 948390b4cadSRussell King if (priv->smarteee_lpi_tw_100m) { 949390b4cadSRussell King mask |= 0x00ff; 950390b4cadSRussell King val |= priv->smarteee_lpi_tw_100m; 951390b4cadSRussell King } 952390b4cadSRussell King if (!mask) 953390b4cadSRussell King return 0; 954390b4cadSRussell King 955390b4cadSRussell King ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1, 956390b4cadSRussell King mask, val); 957390b4cadSRussell King if (ret) 958390b4cadSRussell King return ret; 959390b4cadSRussell King 960390b4cadSRussell King return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3, 961390b4cadSRussell King AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 962390b4cadSRussell King AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); 963390b4cadSRussell King } 964390b4cadSRussell King 9652f664823SMichael Walle static int at803x_clk_out_config(struct phy_device *phydev) 9662f664823SMichael Walle { 9672f664823SMichael Walle struct at803x_priv *priv = phydev->priv; 9682f664823SMichael Walle 9692f664823SMichael Walle if (!priv->clk_25m_mask) 9702f664823SMichael Walle return 0; 9712f664823SMichael Walle 972a45c1c10SRussell King return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M, 973a45c1c10SRussell King priv->clk_25m_mask, priv->clk_25m_reg); 9742f664823SMichael Walle } 9752f664823SMichael Walle 9762f664823SMichael Walle static int at8031_pll_config(struct phy_device *phydev) 9772f664823SMichael Walle { 9782f664823SMichael Walle struct at803x_priv *priv = phydev->priv; 9792f664823SMichael Walle 9802f664823SMichael Walle /* The default after hardware reset is PLL OFF. After a soft reset, the 9812f664823SMichael Walle * values are retained. 9822f664823SMichael Walle */ 9832f664823SMichael Walle if (priv->flags & AT803X_KEEP_PLL_ENABLED) 9842f664823SMichael Walle return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, 9852f664823SMichael Walle 0, AT803X_DEBUG_PLL_ON); 9862f664823SMichael Walle else 9872f664823SMichael Walle return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, 9882f664823SMichael Walle AT803X_DEBUG_PLL_ON, 0); 9892f664823SMichael Walle } 9902f664823SMichael Walle 9910ca7111aSMatus Ujhelyi static int at803x_config_init(struct phy_device *phydev) 9920ca7111aSMatus Ujhelyi { 9933265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 9941ca6d1b1SMugunthan V N int ret; 9950ca7111aSMatus Ujhelyi 9964f3a00c7SRobert Hancock if (phydev->drv->phy_id == ATH8031_PHY_ID) { 9974f3a00c7SRobert Hancock /* Some bootloaders leave the fiber page selected. 9983265f421SRobert Hancock * Switch to the appropriate page (fiber or copper), as otherwise we 9993265f421SRobert Hancock * read the PHY capabilities from the wrong page. 10004f3a00c7SRobert Hancock */ 10014f3a00c7SRobert Hancock phy_lock_mdio_bus(phydev); 10023265f421SRobert Hancock ret = at803x_write_page(phydev, 10033265f421SRobert Hancock priv->is_fiber ? AT803X_PAGE_FIBER : 10043265f421SRobert Hancock AT803X_PAGE_COPPER); 10054f3a00c7SRobert Hancock phy_unlock_mdio_bus(phydev); 10064f3a00c7SRobert Hancock if (ret) 10074f3a00c7SRobert Hancock return ret; 10084f3a00c7SRobert Hancock 10094f3a00c7SRobert Hancock ret = at8031_pll_config(phydev); 10104f3a00c7SRobert Hancock if (ret < 0) 10114f3a00c7SRobert Hancock return ret; 10124f3a00c7SRobert Hancock } 10134f3a00c7SRobert Hancock 10146d4cd041SVinod Koul /* The RX and TX delay default is: 10156d4cd041SVinod Koul * after HW reset: RX delay enabled and TX delay disabled 10166d4cd041SVinod Koul * after SW reset: RX delay enabled, while TX delay retains the 10176d4cd041SVinod Koul * value before reset. 10186d4cd041SVinod Koul */ 1019bb0ce4c1SAndré Draszik if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || 1020bb0ce4c1SAndré Draszik phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) 1021bb0ce4c1SAndré Draszik ret = at803x_enable_rx_delay(phydev); 1022bb0ce4c1SAndré Draszik else 1023cd28d1d6SVinod Koul ret = at803x_disable_rx_delay(phydev); 10242e5f9f28SMartin Blumenstingl if (ret < 0) 10251ca6d1b1SMugunthan V N return ret; 10266d4cd041SVinod Koul 10276d4cd041SVinod Koul if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || 1028bb0ce4c1SAndré Draszik phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 10296d4cd041SVinod Koul ret = at803x_enable_tx_delay(phydev); 1030bb0ce4c1SAndré Draszik else 1031bb0ce4c1SAndré Draszik ret = at803x_disable_tx_delay(phydev); 10322f664823SMichael Walle if (ret < 0) 10336d4cd041SVinod Koul return ret; 10342f664823SMichael Walle 1035390b4cadSRussell King ret = at803x_smarteee_config(phydev); 1036390b4cadSRussell King if (ret < 0) 1037390b4cadSRussell King return ret; 1038390b4cadSRussell King 10392f664823SMichael Walle ret = at803x_clk_out_config(phydev); 10402f664823SMichael Walle if (ret < 0) 10412f664823SMichael Walle return ret; 10422f664823SMichael Walle 10433c51fa5dSRussell King /* Ar803x extended next page bit is enabled by default. Cisco 10443c51fa5dSRussell King * multigig switches read this bit and attempt to negotiate 10Gbps 10453c51fa5dSRussell King * rates even if the next page bit is disabled. This is incorrect 10463c51fa5dSRussell King * behaviour but we still need to accommodate it. XNP is only needed 10473c51fa5dSRussell King * for 10Gbps support, so disable XNP. 10483c51fa5dSRussell King */ 10493c51fa5dSRussell King return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0); 10500ca7111aSMatus Ujhelyi } 10510ca7111aSMatus Ujhelyi 105277a99394SZhao Qiang static int at803x_ack_interrupt(struct phy_device *phydev) 105377a99394SZhao Qiang { 105477a99394SZhao Qiang int err; 105577a99394SZhao Qiang 1056a46bd63bSMartin Blumenstingl err = phy_read(phydev, AT803X_INTR_STATUS); 105777a99394SZhao Qiang 105877a99394SZhao Qiang return (err < 0) ? err : 0; 105977a99394SZhao Qiang } 106077a99394SZhao Qiang 106177a99394SZhao Qiang static int at803x_config_intr(struct phy_device *phydev) 106277a99394SZhao Qiang { 10633265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 106477a99394SZhao Qiang int err; 106577a99394SZhao Qiang int value; 106677a99394SZhao Qiang 1067a46bd63bSMartin Blumenstingl value = phy_read(phydev, AT803X_INTR_ENABLE); 106877a99394SZhao Qiang 1069e6e4a556SMartin Blumenstingl if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { 1070a3417885SIoana Ciornei /* Clear any pending interrupts */ 1071a3417885SIoana Ciornei err = at803x_ack_interrupt(phydev); 1072a3417885SIoana Ciornei if (err) 1073a3417885SIoana Ciornei return err; 1074a3417885SIoana Ciornei 1075e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_AUTONEG_ERR; 1076e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_SPEED_CHANGED; 1077e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED; 1078e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_LINK_FAIL; 1079e6e4a556SMartin Blumenstingl value |= AT803X_INTR_ENABLE_LINK_SUCCESS; 10803265f421SRobert Hancock if (priv->is_fiber) { 10813265f421SRobert Hancock value |= AT803X_INTR_ENABLE_LINK_FAIL_BX; 10823265f421SRobert Hancock value |= AT803X_INTR_ENABLE_LINK_SUCCESS_BX; 10833265f421SRobert Hancock } 1084e6e4a556SMartin Blumenstingl 1085e6e4a556SMartin Blumenstingl err = phy_write(phydev, AT803X_INTR_ENABLE, value); 1086a3417885SIoana Ciornei } else { 1087a46bd63bSMartin Blumenstingl err = phy_write(phydev, AT803X_INTR_ENABLE, 0); 1088a3417885SIoana Ciornei if (err) 1089a3417885SIoana Ciornei return err; 1090a3417885SIoana Ciornei 1091a3417885SIoana Ciornei /* Clear any pending interrupts */ 1092a3417885SIoana Ciornei err = at803x_ack_interrupt(phydev); 1093a3417885SIoana Ciornei } 109477a99394SZhao Qiang 109577a99394SZhao Qiang return err; 109677a99394SZhao Qiang } 109777a99394SZhao Qiang 109829773097SIoana Ciornei static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev) 109929773097SIoana Ciornei { 110029773097SIoana Ciornei int irq_status, int_enabled; 110129773097SIoana Ciornei 110229773097SIoana Ciornei irq_status = phy_read(phydev, AT803X_INTR_STATUS); 110329773097SIoana Ciornei if (irq_status < 0) { 110429773097SIoana Ciornei phy_error(phydev); 110529773097SIoana Ciornei return IRQ_NONE; 110629773097SIoana Ciornei } 110729773097SIoana Ciornei 110829773097SIoana Ciornei /* Read the current enabled interrupts */ 110929773097SIoana Ciornei int_enabled = phy_read(phydev, AT803X_INTR_ENABLE); 111029773097SIoana Ciornei if (int_enabled < 0) { 111129773097SIoana Ciornei phy_error(phydev); 111229773097SIoana Ciornei return IRQ_NONE; 111329773097SIoana Ciornei } 111429773097SIoana Ciornei 111529773097SIoana Ciornei /* See if this was one of our enabled interrupts */ 111629773097SIoana Ciornei if (!(irq_status & int_enabled)) 111729773097SIoana Ciornei return IRQ_NONE; 111829773097SIoana Ciornei 111929773097SIoana Ciornei phy_trigger_machine(phydev); 112029773097SIoana Ciornei 112129773097SIoana Ciornei return IRQ_HANDLED; 112229773097SIoana Ciornei } 112329773097SIoana Ciornei 112413a56b44SDaniel Mack static void at803x_link_change_notify(struct phy_device *phydev) 112513a56b44SDaniel Mack { 112613a56b44SDaniel Mack /* 112713a56b44SDaniel Mack * Conduct a hardware reset for AT8030 every time a link loss is 112813a56b44SDaniel Mack * signalled. This is necessary to circumvent a hardware bug that 112913a56b44SDaniel Mack * occurs when the cable is unplugged while TX packets are pending 113013a56b44SDaniel Mack * in the FIFO. In such cases, the FIFO enters an error mode it 113113a56b44SDaniel Mack * cannot recover from by software. 113213a56b44SDaniel Mack */ 11336110ed2dSDavid Bauer if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) { 113413a56b44SDaniel Mack struct at803x_context context; 113513a56b44SDaniel Mack 113613a56b44SDaniel Mack at803x_context_save(phydev, &context); 113713a56b44SDaniel Mack 1138bafbdd52SSergei Shtylyov phy_device_reset(phydev, 1); 113913a56b44SDaniel Mack msleep(1); 1140bafbdd52SSergei Shtylyov phy_device_reset(phydev, 0); 1141d57019d1SSergei Shtylyov msleep(1); 114213a56b44SDaniel Mack 114313a56b44SDaniel Mack at803x_context_restore(phydev, &context); 114413a56b44SDaniel Mack 11455c5f626bSHeiner Kallweit phydev_dbg(phydev, "%s(): phy was reset\n", __func__); 114613a56b44SDaniel Mack } 114713a56b44SDaniel Mack } 114813a56b44SDaniel Mack 114979c7bc05SLuo Jie static int at803x_read_specific_status(struct phy_device *phydev) 115006d5f344SRussell King { 115179c7bc05SLuo Jie int ss; 115206d5f344SRussell King 115306d5f344SRussell King /* Read the AT8035 PHY-Specific Status register, which indicates the 115406d5f344SRussell King * speed and duplex that the PHY is actually using, irrespective of 115506d5f344SRussell King * whether we are in autoneg mode or not. 115606d5f344SRussell King */ 115706d5f344SRussell King ss = phy_read(phydev, AT803X_SPECIFIC_STATUS); 115806d5f344SRussell King if (ss < 0) 115906d5f344SRussell King return ss; 116006d5f344SRussell King 116106d5f344SRussell King if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) { 116279c7bc05SLuo Jie int sfc, speed; 11637dce80c2SOleksij Rempel 11647dce80c2SOleksij Rempel sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL); 11657dce80c2SOleksij Rempel if (sfc < 0) 11667dce80c2SOleksij Rempel return sfc; 11677dce80c2SOleksij Rempel 116879c7bc05SLuo Jie /* qca8081 takes the different bits for speed value from at803x */ 116979c7bc05SLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) 117079c7bc05SLuo Jie speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss); 117179c7bc05SLuo Jie else 117279c7bc05SLuo Jie speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss); 117379c7bc05SLuo Jie 117479c7bc05SLuo Jie switch (speed) { 117506d5f344SRussell King case AT803X_SS_SPEED_10: 117606d5f344SRussell King phydev->speed = SPEED_10; 117706d5f344SRussell King break; 117806d5f344SRussell King case AT803X_SS_SPEED_100: 117906d5f344SRussell King phydev->speed = SPEED_100; 118006d5f344SRussell King break; 118106d5f344SRussell King case AT803X_SS_SPEED_1000: 118206d5f344SRussell King phydev->speed = SPEED_1000; 118306d5f344SRussell King break; 118479c7bc05SLuo Jie case QCA808X_SS_SPEED_2500: 118579c7bc05SLuo Jie phydev->speed = SPEED_2500; 118679c7bc05SLuo Jie break; 118706d5f344SRussell King } 118806d5f344SRussell King if (ss & AT803X_SS_DUPLEX) 118906d5f344SRussell King phydev->duplex = DUPLEX_FULL; 119006d5f344SRussell King else 119106d5f344SRussell King phydev->duplex = DUPLEX_HALF; 11927dce80c2SOleksij Rempel 119306d5f344SRussell King if (ss & AT803X_SS_MDIX) 119406d5f344SRussell King phydev->mdix = ETH_TP_MDI_X; 119506d5f344SRussell King else 119606d5f344SRussell King phydev->mdix = ETH_TP_MDI; 11977dce80c2SOleksij Rempel 11987dce80c2SOleksij Rempel switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) { 11997dce80c2SOleksij Rempel case AT803X_SFC_MANUAL_MDI: 12007dce80c2SOleksij Rempel phydev->mdix_ctrl = ETH_TP_MDI; 12017dce80c2SOleksij Rempel break; 12027dce80c2SOleksij Rempel case AT803X_SFC_MANUAL_MDIX: 12037dce80c2SOleksij Rempel phydev->mdix_ctrl = ETH_TP_MDI_X; 12047dce80c2SOleksij Rempel break; 12057dce80c2SOleksij Rempel case AT803X_SFC_AUTOMATIC_CROSSOVER: 12067dce80c2SOleksij Rempel phydev->mdix_ctrl = ETH_TP_MDI_AUTO; 12077dce80c2SOleksij Rempel break; 12087dce80c2SOleksij Rempel } 120906d5f344SRussell King } 121006d5f344SRussell King 121179c7bc05SLuo Jie return 0; 121279c7bc05SLuo Jie } 121379c7bc05SLuo Jie 121479c7bc05SLuo Jie static int at803x_read_status(struct phy_device *phydev) 121579c7bc05SLuo Jie { 12163265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 121779c7bc05SLuo Jie int err, old_link = phydev->link; 121879c7bc05SLuo Jie 12193265f421SRobert Hancock if (priv->is_1000basex) 12203265f421SRobert Hancock return genphy_c37_read_status(phydev); 12213265f421SRobert Hancock 122279c7bc05SLuo Jie /* Update the link, but return if there was an error */ 122379c7bc05SLuo Jie err = genphy_update_link(phydev); 122479c7bc05SLuo Jie if (err) 122579c7bc05SLuo Jie return err; 122679c7bc05SLuo Jie 122779c7bc05SLuo Jie /* why bother the PHY if nothing can have changed */ 122879c7bc05SLuo Jie if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) 122979c7bc05SLuo Jie return 0; 123079c7bc05SLuo Jie 123179c7bc05SLuo Jie phydev->speed = SPEED_UNKNOWN; 123279c7bc05SLuo Jie phydev->duplex = DUPLEX_UNKNOWN; 123379c7bc05SLuo Jie phydev->pause = 0; 123479c7bc05SLuo Jie phydev->asym_pause = 0; 123579c7bc05SLuo Jie 123679c7bc05SLuo Jie err = genphy_read_lpa(phydev); 123779c7bc05SLuo Jie if (err < 0) 123879c7bc05SLuo Jie return err; 123979c7bc05SLuo Jie 124079c7bc05SLuo Jie err = at803x_read_specific_status(phydev); 124179c7bc05SLuo Jie if (err < 0) 124279c7bc05SLuo Jie return err; 124379c7bc05SLuo Jie 124406d5f344SRussell King if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) 124506d5f344SRussell King phy_resolve_aneg_pause(phydev); 124606d5f344SRussell King 124706d5f344SRussell King return 0; 124806d5f344SRussell King } 124906d5f344SRussell King 12507dce80c2SOleksij Rempel static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl) 12517dce80c2SOleksij Rempel { 12527dce80c2SOleksij Rempel u16 val; 12537dce80c2SOleksij Rempel 12547dce80c2SOleksij Rempel switch (ctrl) { 12557dce80c2SOleksij Rempel case ETH_TP_MDI: 12567dce80c2SOleksij Rempel val = AT803X_SFC_MANUAL_MDI; 12577dce80c2SOleksij Rempel break; 12587dce80c2SOleksij Rempel case ETH_TP_MDI_X: 12597dce80c2SOleksij Rempel val = AT803X_SFC_MANUAL_MDIX; 12607dce80c2SOleksij Rempel break; 12617dce80c2SOleksij Rempel case ETH_TP_MDI_AUTO: 12627dce80c2SOleksij Rempel val = AT803X_SFC_AUTOMATIC_CROSSOVER; 12637dce80c2SOleksij Rempel break; 12647dce80c2SOleksij Rempel default: 12657dce80c2SOleksij Rempel return 0; 12667dce80c2SOleksij Rempel } 12677dce80c2SOleksij Rempel 12687dce80c2SOleksij Rempel return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL, 12697dce80c2SOleksij Rempel AT803X_SFC_MDI_CROSSOVER_MODE_M, 12707dce80c2SOleksij Rempel FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val)); 12717dce80c2SOleksij Rempel } 12727dce80c2SOleksij Rempel 12737dce80c2SOleksij Rempel static int at803x_config_aneg(struct phy_device *phydev) 12747dce80c2SOleksij Rempel { 12753265f421SRobert Hancock struct at803x_priv *priv = phydev->priv; 12767dce80c2SOleksij Rempel int ret; 12777dce80c2SOleksij Rempel 12787dce80c2SOleksij Rempel ret = at803x_config_mdix(phydev, phydev->mdix_ctrl); 12797dce80c2SOleksij Rempel if (ret < 0) 12807dce80c2SOleksij Rempel return ret; 12817dce80c2SOleksij Rempel 12827dce80c2SOleksij Rempel /* Changes of the midx bits are disruptive to the normal operation; 12837dce80c2SOleksij Rempel * therefore any changes to these registers must be followed by a 12847dce80c2SOleksij Rempel * software reset to take effect. 12857dce80c2SOleksij Rempel */ 12867dce80c2SOleksij Rempel if (ret == 1) { 12877dce80c2SOleksij Rempel ret = genphy_soft_reset(phydev); 12887dce80c2SOleksij Rempel if (ret < 0) 12897dce80c2SOleksij Rempel return ret; 12907dce80c2SOleksij Rempel } 12917dce80c2SOleksij Rempel 12923265f421SRobert Hancock if (priv->is_1000basex) 12933265f421SRobert Hancock return genphy_c37_config_aneg(phydev); 12943265f421SRobert Hancock 1295f884d449SLuo Jie /* Do not restart auto-negotiation by setting ret to 0 defautly, 1296f884d449SLuo Jie * when calling __genphy_config_aneg later. 1297f884d449SLuo Jie */ 1298f884d449SLuo Jie ret = 0; 1299f884d449SLuo Jie 1300f884d449SLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) { 1301f884d449SLuo Jie int phy_ctrl = 0; 1302f884d449SLuo Jie 1303f884d449SLuo Jie /* The reg MII_BMCR also needs to be configured for force mode, the 1304f884d449SLuo Jie * genphy_config_aneg is also needed. 1305f884d449SLuo Jie */ 1306f884d449SLuo Jie if (phydev->autoneg == AUTONEG_DISABLE) 1307f884d449SLuo Jie genphy_c45_pma_setup_forced(phydev); 1308f884d449SLuo Jie 1309f884d449SLuo Jie if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising)) 1310f884d449SLuo Jie phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G; 1311f884d449SLuo Jie 1312f884d449SLuo Jie ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL, 1313f884d449SLuo Jie MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl); 1314f884d449SLuo Jie if (ret < 0) 1315f884d449SLuo Jie return ret; 1316f884d449SLuo Jie } 1317f884d449SLuo Jie 1318f884d449SLuo Jie return __genphy_config_aneg(phydev, ret); 13197dce80c2SOleksij Rempel } 13207dce80c2SOleksij Rempel 1321cde0f4f8SMichael Walle static int at803x_get_downshift(struct phy_device *phydev, u8 *d) 1322cde0f4f8SMichael Walle { 1323cde0f4f8SMichael Walle int val; 1324cde0f4f8SMichael Walle 1325cde0f4f8SMichael Walle val = phy_read(phydev, AT803X_SMART_SPEED); 1326cde0f4f8SMichael Walle if (val < 0) 1327cde0f4f8SMichael Walle return val; 1328cde0f4f8SMichael Walle 1329cde0f4f8SMichael Walle if (val & AT803X_SMART_SPEED_ENABLE) 1330cde0f4f8SMichael Walle *d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2; 1331cde0f4f8SMichael Walle else 1332cde0f4f8SMichael Walle *d = DOWNSHIFT_DEV_DISABLE; 1333cde0f4f8SMichael Walle 1334cde0f4f8SMichael Walle return 0; 1335cde0f4f8SMichael Walle } 1336cde0f4f8SMichael Walle 1337cde0f4f8SMichael Walle static int at803x_set_downshift(struct phy_device *phydev, u8 cnt) 1338cde0f4f8SMichael Walle { 1339cde0f4f8SMichael Walle u16 mask, set; 1340cde0f4f8SMichael Walle int ret; 1341cde0f4f8SMichael Walle 1342cde0f4f8SMichael Walle switch (cnt) { 1343cde0f4f8SMichael Walle case DOWNSHIFT_DEV_DEFAULT_COUNT: 1344cde0f4f8SMichael Walle cnt = AT803X_DEFAULT_DOWNSHIFT; 1345cde0f4f8SMichael Walle fallthrough; 1346cde0f4f8SMichael Walle case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT: 1347cde0f4f8SMichael Walle set = AT803X_SMART_SPEED_ENABLE | 1348cde0f4f8SMichael Walle AT803X_SMART_SPEED_BYPASS_TIMER | 1349cde0f4f8SMichael Walle FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2); 1350cde0f4f8SMichael Walle mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK; 1351cde0f4f8SMichael Walle break; 1352cde0f4f8SMichael Walle case DOWNSHIFT_DEV_DISABLE: 1353cde0f4f8SMichael Walle set = 0; 1354cde0f4f8SMichael Walle mask = AT803X_SMART_SPEED_ENABLE | 1355cde0f4f8SMichael Walle AT803X_SMART_SPEED_BYPASS_TIMER; 1356cde0f4f8SMichael Walle break; 1357cde0f4f8SMichael Walle default: 1358cde0f4f8SMichael Walle return -EINVAL; 1359cde0f4f8SMichael Walle } 1360cde0f4f8SMichael Walle 1361cde0f4f8SMichael Walle ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set); 1362cde0f4f8SMichael Walle 1363cde0f4f8SMichael Walle /* After changing the smart speed settings, we need to perform a 1364cde0f4f8SMichael Walle * software reset, use phy_init_hw() to make sure we set the 1365cde0f4f8SMichael Walle * reapply any values which might got lost during software reset. 1366cde0f4f8SMichael Walle */ 1367cde0f4f8SMichael Walle if (ret == 1) 1368cde0f4f8SMichael Walle ret = phy_init_hw(phydev); 1369cde0f4f8SMichael Walle 1370cde0f4f8SMichael Walle return ret; 1371cde0f4f8SMichael Walle } 1372cde0f4f8SMichael Walle 1373cde0f4f8SMichael Walle static int at803x_get_tunable(struct phy_device *phydev, 1374cde0f4f8SMichael Walle struct ethtool_tunable *tuna, void *data) 1375cde0f4f8SMichael Walle { 1376cde0f4f8SMichael Walle switch (tuna->id) { 1377cde0f4f8SMichael Walle case ETHTOOL_PHY_DOWNSHIFT: 1378cde0f4f8SMichael Walle return at803x_get_downshift(phydev, data); 1379cde0f4f8SMichael Walle default: 1380cde0f4f8SMichael Walle return -EOPNOTSUPP; 1381cde0f4f8SMichael Walle } 1382cde0f4f8SMichael Walle } 1383cde0f4f8SMichael Walle 1384cde0f4f8SMichael Walle static int at803x_set_tunable(struct phy_device *phydev, 1385cde0f4f8SMichael Walle struct ethtool_tunable *tuna, const void *data) 1386cde0f4f8SMichael Walle { 1387cde0f4f8SMichael Walle switch (tuna->id) { 1388cde0f4f8SMichael Walle case ETHTOOL_PHY_DOWNSHIFT: 1389cde0f4f8SMichael Walle return at803x_set_downshift(phydev, *(const u8 *)data); 1390cde0f4f8SMichael Walle default: 1391cde0f4f8SMichael Walle return -EOPNOTSUPP; 1392cde0f4f8SMichael Walle } 1393cde0f4f8SMichael Walle } 1394cde0f4f8SMichael Walle 13956cb75767SMichael Walle static int at803x_cable_test_result_trans(u16 status) 13966cb75767SMichael Walle { 13976cb75767SMichael Walle switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) { 13986cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_NORMAL: 13996cb75767SMichael Walle return ETHTOOL_A_CABLE_RESULT_CODE_OK; 14006cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_SHORT: 14016cb75767SMichael Walle return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 14026cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_OPEN: 14036cb75767SMichael Walle return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 14046cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_FAIL: 14056cb75767SMichael Walle default: 14066cb75767SMichael Walle return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 14076cb75767SMichael Walle } 14086cb75767SMichael Walle } 14096cb75767SMichael Walle 14106cb75767SMichael Walle static bool at803x_cdt_test_failed(u16 status) 14116cb75767SMichael Walle { 14126cb75767SMichael Walle return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) == 14136cb75767SMichael Walle AT803X_CDT_STATUS_STAT_FAIL; 14146cb75767SMichael Walle } 14156cb75767SMichael Walle 14166cb75767SMichael Walle static bool at803x_cdt_fault_length_valid(u16 status) 14176cb75767SMichael Walle { 14186cb75767SMichael Walle switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) { 14196cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_OPEN: 14206cb75767SMichael Walle case AT803X_CDT_STATUS_STAT_SHORT: 14216cb75767SMichael Walle return true; 14226cb75767SMichael Walle } 14236cb75767SMichael Walle return false; 14246cb75767SMichael Walle } 14256cb75767SMichael Walle 14266cb75767SMichael Walle static int at803x_cdt_fault_length(u16 status) 14276cb75767SMichael Walle { 14286cb75767SMichael Walle int dt; 14296cb75767SMichael Walle 14306cb75767SMichael Walle /* According to the datasheet the distance to the fault is 14316cb75767SMichael Walle * DELTA_TIME * 0.824 meters. 14326cb75767SMichael Walle * 14336cb75767SMichael Walle * The author suspect the correct formula is: 14346cb75767SMichael Walle * 14356cb75767SMichael Walle * fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2 14366cb75767SMichael Walle * 14376cb75767SMichael Walle * where c is the speed of light, VF is the velocity factor of 14386cb75767SMichael Walle * the twisted pair cable, 125MHz the counter frequency and 14396cb75767SMichael Walle * we need to divide by 2 because the hardware will measure the 14406cb75767SMichael Walle * round trip time to the fault and back to the PHY. 14416cb75767SMichael Walle * 14426cb75767SMichael Walle * With a VF of 0.69 we get the factor 0.824 mentioned in the 14436cb75767SMichael Walle * datasheet. 14446cb75767SMichael Walle */ 14456cb75767SMichael Walle dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status); 14466cb75767SMichael Walle 14476cb75767SMichael Walle return (dt * 824) / 10; 14486cb75767SMichael Walle } 14496cb75767SMichael Walle 14506cb75767SMichael Walle static int at803x_cdt_start(struct phy_device *phydev, int pair) 14516cb75767SMichael Walle { 14526cb75767SMichael Walle u16 cdt; 14536cb75767SMichael Walle 14548c84d752SLuo Jie /* qca8081 takes the different bit 15 to enable CDT test */ 14558c84d752SLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) 14568c84d752SLuo Jie cdt = QCA808X_CDT_ENABLE_TEST | 14578c84d752SLuo Jie QCA808X_CDT_LENGTH_UNIT | 14588c84d752SLuo Jie QCA808X_CDT_INTER_CHECK_DIS; 14598c84d752SLuo Jie else 14606cb75767SMichael Walle cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) | 14616cb75767SMichael Walle AT803X_CDT_ENABLE_TEST; 14626cb75767SMichael Walle 14636cb75767SMichael Walle return phy_write(phydev, AT803X_CDT, cdt); 14646cb75767SMichael Walle } 14656cb75767SMichael Walle 14666cb75767SMichael Walle static int at803x_cdt_wait_for_completion(struct phy_device *phydev) 14676cb75767SMichael Walle { 14686cb75767SMichael Walle int val, ret; 14698c84d752SLuo Jie u16 cdt_en; 14708c84d752SLuo Jie 14718c84d752SLuo Jie if (phydev->drv->phy_id == QCA8081_PHY_ID) 14728c84d752SLuo Jie cdt_en = QCA808X_CDT_ENABLE_TEST; 14738c84d752SLuo Jie else 14748c84d752SLuo Jie cdt_en = AT803X_CDT_ENABLE_TEST; 14756cb75767SMichael Walle 14766cb75767SMichael Walle /* One test run takes about 25ms */ 14776cb75767SMichael Walle ret = phy_read_poll_timeout(phydev, AT803X_CDT, val, 14788c84d752SLuo Jie !(val & cdt_en), 14796cb75767SMichael Walle 30000, 100000, true); 14806cb75767SMichael Walle 14816cb75767SMichael Walle return ret < 0 ? ret : 0; 14826cb75767SMichael Walle } 14836cb75767SMichael Walle 14846cb75767SMichael Walle static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair) 14856cb75767SMichael Walle { 14866cb75767SMichael Walle static const int ethtool_pair[] = { 14876cb75767SMichael Walle ETHTOOL_A_CABLE_PAIR_A, 14886cb75767SMichael Walle ETHTOOL_A_CABLE_PAIR_B, 14896cb75767SMichael Walle ETHTOOL_A_CABLE_PAIR_C, 14906cb75767SMichael Walle ETHTOOL_A_CABLE_PAIR_D, 14916cb75767SMichael Walle }; 14926cb75767SMichael Walle int ret, val; 14936cb75767SMichael Walle 14946cb75767SMichael Walle ret = at803x_cdt_start(phydev, pair); 14956cb75767SMichael Walle if (ret) 14966cb75767SMichael Walle return ret; 14976cb75767SMichael Walle 14986cb75767SMichael Walle ret = at803x_cdt_wait_for_completion(phydev); 14996cb75767SMichael Walle if (ret) 15006cb75767SMichael Walle return ret; 15016cb75767SMichael Walle 15026cb75767SMichael Walle val = phy_read(phydev, AT803X_CDT_STATUS); 15036cb75767SMichael Walle if (val < 0) 15046cb75767SMichael Walle return val; 15056cb75767SMichael Walle 15066cb75767SMichael Walle if (at803x_cdt_test_failed(val)) 15076cb75767SMichael Walle return 0; 15086cb75767SMichael Walle 15096cb75767SMichael Walle ethnl_cable_test_result(phydev, ethtool_pair[pair], 15106cb75767SMichael Walle at803x_cable_test_result_trans(val)); 15116cb75767SMichael Walle 15126cb75767SMichael Walle if (at803x_cdt_fault_length_valid(val)) 15136cb75767SMichael Walle ethnl_cable_test_fault_length(phydev, ethtool_pair[pair], 15146cb75767SMichael Walle at803x_cdt_fault_length(val)); 15156cb75767SMichael Walle 15166cb75767SMichael Walle return 1; 15176cb75767SMichael Walle } 15186cb75767SMichael Walle 15196cb75767SMichael Walle static int at803x_cable_test_get_status(struct phy_device *phydev, 15206cb75767SMichael Walle bool *finished) 15216cb75767SMichael Walle { 1522dc0f3ed1SOleksij Rempel unsigned long pair_mask; 15236cb75767SMichael Walle int retries = 20; 15246cb75767SMichael Walle int pair, ret; 15256cb75767SMichael Walle 1526dc0f3ed1SOleksij Rempel if (phydev->phy_id == ATH9331_PHY_ID || 1527fada2ce0SDavid Bauer phydev->phy_id == ATH8032_PHY_ID || 1528fada2ce0SDavid Bauer phydev->phy_id == QCA9561_PHY_ID) 1529dc0f3ed1SOleksij Rempel pair_mask = 0x3; 1530dc0f3ed1SOleksij Rempel else 1531dc0f3ed1SOleksij Rempel pair_mask = 0xf; 1532dc0f3ed1SOleksij Rempel 15336cb75767SMichael Walle *finished = false; 15346cb75767SMichael Walle 15356cb75767SMichael Walle /* According to the datasheet the CDT can be performed when 15366cb75767SMichael Walle * there is no link partner or when the link partner is 15376cb75767SMichael Walle * auto-negotiating. Starting the test will restart the AN 15386cb75767SMichael Walle * automatically. It seems that doing this repeatedly we will 15396cb75767SMichael Walle * get a slot where our link partner won't disturb our 15406cb75767SMichael Walle * measurement. 15416cb75767SMichael Walle */ 15426cb75767SMichael Walle while (pair_mask && retries--) { 15436cb75767SMichael Walle for_each_set_bit(pair, &pair_mask, 4) { 15446cb75767SMichael Walle ret = at803x_cable_test_one_pair(phydev, pair); 15456cb75767SMichael Walle if (ret < 0) 15466cb75767SMichael Walle return ret; 15476cb75767SMichael Walle if (ret) 15486cb75767SMichael Walle clear_bit(pair, &pair_mask); 15496cb75767SMichael Walle } 15506cb75767SMichael Walle if (pair_mask) 15516cb75767SMichael Walle msleep(250); 15526cb75767SMichael Walle } 15536cb75767SMichael Walle 15546cb75767SMichael Walle *finished = true; 15556cb75767SMichael Walle 15566cb75767SMichael Walle return 0; 15576cb75767SMichael Walle } 15586cb75767SMichael Walle 15596cb75767SMichael Walle static int at803x_cable_test_start(struct phy_device *phydev) 15606cb75767SMichael Walle { 15616cb75767SMichael Walle /* Enable auto-negotiation, but advertise no capabilities, no link 15626cb75767SMichael Walle * will be established. A restart of the auto-negotiation is not 15636cb75767SMichael Walle * required, because the cable test will automatically break the link. 15646cb75767SMichael Walle */ 15656cb75767SMichael Walle phy_write(phydev, MII_BMCR, BMCR_ANENABLE); 15666cb75767SMichael Walle phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA); 1567dc0f3ed1SOleksij Rempel if (phydev->phy_id != ATH9331_PHY_ID && 1568fada2ce0SDavid Bauer phydev->phy_id != ATH8032_PHY_ID && 1569fada2ce0SDavid Bauer phydev->phy_id != QCA9561_PHY_ID) 15706cb75767SMichael Walle phy_write(phydev, MII_CTRL1000, 0); 15716cb75767SMichael Walle 15726cb75767SMichael Walle /* we do all the (time consuming) work later */ 15736cb75767SMichael Walle return 0; 15746cb75767SMichael Walle } 15756cb75767SMichael Walle 1576272833b9SAnsuel Smith static int qca83xx_config_init(struct phy_device *phydev) 1577272833b9SAnsuel Smith { 1578272833b9SAnsuel Smith u8 switch_revision; 1579272833b9SAnsuel Smith 1580272833b9SAnsuel Smith switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK; 1581272833b9SAnsuel Smith 1582272833b9SAnsuel Smith switch (switch_revision) { 1583272833b9SAnsuel Smith case 1: 1584272833b9SAnsuel Smith /* For 100M waveform */ 158567999555SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea); 1586272833b9SAnsuel Smith /* Turn on Gigabit clock */ 158767999555SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0); 1588272833b9SAnsuel Smith break; 1589272833b9SAnsuel Smith 1590272833b9SAnsuel Smith case 2: 1591272833b9SAnsuel Smith phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0); 1592272833b9SAnsuel Smith fallthrough; 1593272833b9SAnsuel Smith case 4: 1594272833b9SAnsuel Smith phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f); 159567999555SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860); 159667999555SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46); 1597272833b9SAnsuel Smith at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000); 1598272833b9SAnsuel Smith break; 1599272833b9SAnsuel Smith } 1600272833b9SAnsuel Smith 16011ca83119SAnsuel Smith /* QCA8327 require DAC amplitude adjustment for 100m set to +6%. 16021ca83119SAnsuel Smith * Disable on init and enable only with 100m speed following 16031ca83119SAnsuel Smith * qca original source code. 16041ca83119SAnsuel Smith */ 16051ca83119SAnsuel Smith if (phydev->drv->phy_id == QCA8327_A_PHY_ID || 16061ca83119SAnsuel Smith phydev->drv->phy_id == QCA8327_B_PHY_ID) 160767999555SAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 16081ca83119SAnsuel Smith QCA8327_DEBUG_MANU_CTRL_EN, 0); 16091ca83119SAnsuel Smith 16109d1c29b4SAnsuel Smith /* Following original QCA sourcecode set port to prefer master */ 16119d1c29b4SAnsuel Smith phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER); 16129d1c29b4SAnsuel Smith 1613272833b9SAnsuel Smith return 0; 1614272833b9SAnsuel Smith } 1615272833b9SAnsuel Smith 16161ca83119SAnsuel Smith static void qca83xx_link_change_notify(struct phy_device *phydev) 16171ca83119SAnsuel Smith { 16181ca83119SAnsuel Smith /* QCA8337 doesn't require DAC Amplitude adjustement */ 16191ca83119SAnsuel Smith if (phydev->drv->phy_id == QCA8337_PHY_ID) 16201ca83119SAnsuel Smith return; 16211ca83119SAnsuel Smith 16221ca83119SAnsuel Smith /* Set DAC Amplitude adjustment to +6% for 100m on link running */ 16231ca83119SAnsuel Smith if (phydev->state == PHY_RUNNING) { 16241ca83119SAnsuel Smith if (phydev->speed == SPEED_100) 162567999555SAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 16261ca83119SAnsuel Smith QCA8327_DEBUG_MANU_CTRL_EN, 16271ca83119SAnsuel Smith QCA8327_DEBUG_MANU_CTRL_EN); 16281ca83119SAnsuel Smith } else { 16291ca83119SAnsuel Smith /* Reset DAC Amplitude adjustment */ 163067999555SAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 16311ca83119SAnsuel Smith QCA8327_DEBUG_MANU_CTRL_EN, 0); 16321ca83119SAnsuel Smith } 16331ca83119SAnsuel Smith } 16341ca83119SAnsuel Smith 1635ba3c01eeSAnsuel Smith static int qca83xx_resume(struct phy_device *phydev) 1636ba3c01eeSAnsuel Smith { 1637ba3c01eeSAnsuel Smith int ret, val; 1638ba3c01eeSAnsuel Smith 1639ba3c01eeSAnsuel Smith /* Skip reset if not suspended */ 1640ba3c01eeSAnsuel Smith if (!phydev->suspended) 1641ba3c01eeSAnsuel Smith return 0; 1642ba3c01eeSAnsuel Smith 1643ba3c01eeSAnsuel Smith /* Reinit the port, reset values set by suspend */ 1644ba3c01eeSAnsuel Smith qca83xx_config_init(phydev); 1645ba3c01eeSAnsuel Smith 1646ba3c01eeSAnsuel Smith /* Reset the port on port resume */ 1647ba3c01eeSAnsuel Smith phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE); 1648ba3c01eeSAnsuel Smith 1649ba3c01eeSAnsuel Smith /* On resume from suspend the switch execute a reset and 1650ba3c01eeSAnsuel Smith * restart auto-negotiation. Wait for reset to complete. 1651ba3c01eeSAnsuel Smith */ 1652ba3c01eeSAnsuel Smith ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET), 1653ba3c01eeSAnsuel Smith 50000, 600000, true); 1654ba3c01eeSAnsuel Smith if (ret) 1655ba3c01eeSAnsuel Smith return ret; 1656ba3c01eeSAnsuel Smith 1657ba3c01eeSAnsuel Smith msleep(1); 1658ba3c01eeSAnsuel Smith 1659ba3c01eeSAnsuel Smith return 0; 1660ba3c01eeSAnsuel Smith } 1661ba3c01eeSAnsuel Smith 1662ba3c01eeSAnsuel Smith static int qca83xx_suspend(struct phy_device *phydev) 1663ba3c01eeSAnsuel Smith { 1664ba3c01eeSAnsuel Smith u16 mask = 0; 1665ba3c01eeSAnsuel Smith 1666ba3c01eeSAnsuel Smith /* Only QCA8337 support actual suspend. 1667ba3c01eeSAnsuel Smith * QCA8327 cause port unreliability when phy suspend 1668ba3c01eeSAnsuel Smith * is set. 1669ba3c01eeSAnsuel Smith */ 1670ba3c01eeSAnsuel Smith if (phydev->drv->phy_id == QCA8337_PHY_ID) { 1671ba3c01eeSAnsuel Smith genphy_suspend(phydev); 1672ba3c01eeSAnsuel Smith } else { 1673ba3c01eeSAnsuel Smith mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX); 1674ba3c01eeSAnsuel Smith phy_modify(phydev, MII_BMCR, mask, 0); 1675ba3c01eeSAnsuel Smith } 1676ba3c01eeSAnsuel Smith 167767999555SAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN, 1678ba3c01eeSAnsuel Smith AT803X_DEBUG_GATE_CLK_IN1000, 0); 1679ba3c01eeSAnsuel Smith 1680ba3c01eeSAnsuel Smith at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL, 1681ba3c01eeSAnsuel Smith AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE | 1682ba3c01eeSAnsuel Smith AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0); 1683ba3c01eeSAnsuel Smith 1684ba3c01eeSAnsuel Smith return 0; 1685ba3c01eeSAnsuel Smith } 1686ba3c01eeSAnsuel Smith 16872acdd43fSLuo Jie static int qca808x_phy_fast_retrain_config(struct phy_device *phydev) 16882acdd43fSLuo Jie { 16892acdd43fSLuo Jie int ret; 16902acdd43fSLuo Jie 16912acdd43fSLuo Jie /* Enable fast retrain */ 16922acdd43fSLuo Jie ret = genphy_c45_fast_retrain(phydev, true); 16932acdd43fSLuo Jie if (ret) 16942acdd43fSLuo Jie return ret; 16952acdd43fSLuo Jie 16962acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_TOP_OPTION1, 16972acdd43fSLuo Jie QCA808X_TOP_OPTION1_DATA); 16982acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB, 16992acdd43fSLuo Jie QCA808X_MSE_THRESHOLD_20DB_VALUE); 17002acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB, 17012acdd43fSLuo Jie QCA808X_MSE_THRESHOLD_17DB_VALUE); 17022acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB, 17032acdd43fSLuo Jie QCA808X_MSE_THRESHOLD_27DB_VALUE); 17042acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB, 17052acdd43fSLuo Jie QCA808X_MSE_THRESHOLD_28DB_VALUE); 17062acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_1, 17072acdd43fSLuo Jie QCA808X_MMD3_DEBUG_1_VALUE); 17082acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_4, 17092acdd43fSLuo Jie QCA808X_MMD3_DEBUG_4_VALUE); 17102acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_5, 17112acdd43fSLuo Jie QCA808X_MMD3_DEBUG_5_VALUE); 17122acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_3, 17132acdd43fSLuo Jie QCA808X_MMD3_DEBUG_3_VALUE); 17142acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_6, 17152acdd43fSLuo Jie QCA808X_MMD3_DEBUG_6_VALUE); 17162acdd43fSLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_2, 17172acdd43fSLuo Jie QCA808X_MMD3_DEBUG_2_VALUE); 17182acdd43fSLuo Jie 17192acdd43fSLuo Jie return 0; 17202acdd43fSLuo Jie } 17212acdd43fSLuo Jie 17229d4dae29SLuo Jie static int qca808x_phy_ms_random_seed_set(struct phy_device *phydev) 17239d4dae29SLuo Jie { 17249d4dae29SLuo Jie u16 seed_value = (prandom_u32() % QCA808X_MASTER_SLAVE_SEED_RANGE); 17259d4dae29SLuo Jie 17269d4dae29SLuo Jie return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED, 17279d4dae29SLuo Jie QCA808X_MASTER_SLAVE_SEED_CFG, 17289d4dae29SLuo Jie FIELD_PREP(QCA808X_MASTER_SLAVE_SEED_CFG, seed_value)); 17299d4dae29SLuo Jie } 17309d4dae29SLuo Jie 17319d4dae29SLuo Jie static int qca808x_phy_ms_seed_enable(struct phy_device *phydev, bool enable) 17329d4dae29SLuo Jie { 17339d4dae29SLuo Jie u16 seed_enable = 0; 17349d4dae29SLuo Jie 17359d4dae29SLuo Jie if (enable) 17369d4dae29SLuo Jie seed_enable = QCA808X_MASTER_SLAVE_SEED_ENABLE; 17379d4dae29SLuo Jie 17389d4dae29SLuo Jie return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED, 17399d4dae29SLuo Jie QCA808X_MASTER_SLAVE_SEED_ENABLE, seed_enable); 17409d4dae29SLuo Jie } 17419d4dae29SLuo Jie 17422acdd43fSLuo Jie static int qca808x_config_init(struct phy_device *phydev) 17432acdd43fSLuo Jie { 17442acdd43fSLuo Jie int ret; 17452acdd43fSLuo Jie 17462acdd43fSLuo Jie /* Active adc&vga on 802.3az for the link 1000M and 100M */ 17472acdd43fSLuo Jie ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_ADDR_CLD_CTRL7, 17482acdd43fSLuo Jie QCA808X_8023AZ_AFE_CTRL_MASK, QCA808X_8023AZ_AFE_EN); 17492acdd43fSLuo Jie if (ret) 17502acdd43fSLuo Jie return ret; 17512acdd43fSLuo Jie 17522acdd43fSLuo Jie /* Adjust the threshold on 802.3az for the link 1000M */ 17532acdd43fSLuo Jie ret = phy_write_mmd(phydev, MDIO_MMD_PCS, 17542acdd43fSLuo Jie QCA808X_PHY_MMD3_AZ_TRAINING_CTRL, QCA808X_MMD3_AZ_TRAINING_VAL); 17552acdd43fSLuo Jie if (ret) 17562acdd43fSLuo Jie return ret; 17572acdd43fSLuo Jie 17582acdd43fSLuo Jie /* Config the fast retrain for the link 2500M */ 17592acdd43fSLuo Jie ret = qca808x_phy_fast_retrain_config(phydev); 17602acdd43fSLuo Jie if (ret) 17612acdd43fSLuo Jie return ret; 17622acdd43fSLuo Jie 17639d4dae29SLuo Jie /* Configure lower ramdom seed to make phy linked as slave mode */ 17649d4dae29SLuo Jie ret = qca808x_phy_ms_random_seed_set(phydev); 17659d4dae29SLuo Jie if (ret) 17669d4dae29SLuo Jie return ret; 17679d4dae29SLuo Jie 17689d4dae29SLuo Jie /* Enable seed */ 17699d4dae29SLuo Jie ret = qca808x_phy_ms_seed_enable(phydev, true); 17709d4dae29SLuo Jie if (ret) 17719d4dae29SLuo Jie return ret; 17729d4dae29SLuo Jie 17732acdd43fSLuo Jie /* Configure adc threshold as 100mv for the link 10M */ 17742acdd43fSLuo Jie return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD, 17752acdd43fSLuo Jie QCA808X_ADC_THRESHOLD_MASK, QCA808X_ADC_THRESHOLD_100MV); 17762acdd43fSLuo Jie } 17772acdd43fSLuo Jie 177879c7bc05SLuo Jie static int qca808x_read_status(struct phy_device *phydev) 177979c7bc05SLuo Jie { 178079c7bc05SLuo Jie int ret; 178179c7bc05SLuo Jie 178279c7bc05SLuo Jie ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT); 178379c7bc05SLuo Jie if (ret < 0) 178479c7bc05SLuo Jie return ret; 178579c7bc05SLuo Jie 178679c7bc05SLuo Jie linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising, 178779c7bc05SLuo Jie ret & MDIO_AN_10GBT_STAT_LP2_5G); 178879c7bc05SLuo Jie 178979c7bc05SLuo Jie ret = genphy_read_status(phydev); 179079c7bc05SLuo Jie if (ret) 179179c7bc05SLuo Jie return ret; 179279c7bc05SLuo Jie 179379c7bc05SLuo Jie ret = at803x_read_specific_status(phydev); 179479c7bc05SLuo Jie if (ret < 0) 179579c7bc05SLuo Jie return ret; 179679c7bc05SLuo Jie 179779c7bc05SLuo Jie if (phydev->link && phydev->speed == SPEED_2500) 179879c7bc05SLuo Jie phydev->interface = PHY_INTERFACE_MODE_2500BASEX; 179979c7bc05SLuo Jie else 180079c7bc05SLuo Jie phydev->interface = PHY_INTERFACE_MODE_SMII; 180179c7bc05SLuo Jie 18028bc1c543SLuo Jie /* generate seed as a lower random value to make PHY linked as SLAVE easily, 18038bc1c543SLuo Jie * except for master/slave configuration fault detected. 18048bc1c543SLuo Jie * the reason for not putting this code into the function link_change_notify is 18058bc1c543SLuo Jie * the corner case where the link partner is also the qca8081 PHY and the seed 18068bc1c543SLuo Jie * value is configured as the same value, the link can't be up and no link change 18078bc1c543SLuo Jie * occurs. 18088bc1c543SLuo Jie */ 18098bc1c543SLuo Jie if (!phydev->link) { 18108bc1c543SLuo Jie if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR) { 18118bc1c543SLuo Jie qca808x_phy_ms_seed_enable(phydev, false); 18128bc1c543SLuo Jie } else { 18138bc1c543SLuo Jie qca808x_phy_ms_random_seed_set(phydev); 18148bc1c543SLuo Jie qca808x_phy_ms_seed_enable(phydev, true); 18158bc1c543SLuo Jie } 18168bc1c543SLuo Jie } 18178bc1c543SLuo Jie 181879c7bc05SLuo Jie return 0; 181979c7bc05SLuo Jie } 182079c7bc05SLuo Jie 18219d4dae29SLuo Jie static int qca808x_soft_reset(struct phy_device *phydev) 18229d4dae29SLuo Jie { 18239d4dae29SLuo Jie int ret; 18249d4dae29SLuo Jie 18259d4dae29SLuo Jie ret = genphy_soft_reset(phydev); 18269d4dae29SLuo Jie if (ret < 0) 18279d4dae29SLuo Jie return ret; 18289d4dae29SLuo Jie 18299d4dae29SLuo Jie return qca808x_phy_ms_seed_enable(phydev, true); 18309d4dae29SLuo Jie } 18319d4dae29SLuo Jie 18328c84d752SLuo Jie static bool qca808x_cdt_fault_length_valid(int cdt_code) 18338c84d752SLuo Jie { 18348c84d752SLuo Jie switch (cdt_code) { 18358c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_SHORT: 18368c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_OPEN: 18378c84d752SLuo Jie return true; 18388c84d752SLuo Jie default: 18398c84d752SLuo Jie return false; 18408c84d752SLuo Jie } 18418c84d752SLuo Jie } 18428c84d752SLuo Jie 18438c84d752SLuo Jie static int qca808x_cable_test_result_trans(int cdt_code) 18448c84d752SLuo Jie { 18458c84d752SLuo Jie switch (cdt_code) { 18468c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_NORMAL: 18478c84d752SLuo Jie return ETHTOOL_A_CABLE_RESULT_CODE_OK; 18488c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_SHORT: 18498c84d752SLuo Jie return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 18508c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_OPEN: 18518c84d752SLuo Jie return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 18528c84d752SLuo Jie case QCA808X_CDT_STATUS_STAT_FAIL: 18538c84d752SLuo Jie default: 18548c84d752SLuo Jie return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 18558c84d752SLuo Jie } 18568c84d752SLuo Jie } 18578c84d752SLuo Jie 18588c84d752SLuo Jie static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair) 18598c84d752SLuo Jie { 18608c84d752SLuo Jie int val; 18618c84d752SLuo Jie u32 cdt_length_reg = 0; 18628c84d752SLuo Jie 18638c84d752SLuo Jie switch (pair) { 18648c84d752SLuo Jie case ETHTOOL_A_CABLE_PAIR_A: 18658c84d752SLuo Jie cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_A; 18668c84d752SLuo Jie break; 18678c84d752SLuo Jie case ETHTOOL_A_CABLE_PAIR_B: 18688c84d752SLuo Jie cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_B; 18698c84d752SLuo Jie break; 18708c84d752SLuo Jie case ETHTOOL_A_CABLE_PAIR_C: 18718c84d752SLuo Jie cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_C; 18728c84d752SLuo Jie break; 18738c84d752SLuo Jie case ETHTOOL_A_CABLE_PAIR_D: 18748c84d752SLuo Jie cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_D; 18758c84d752SLuo Jie break; 18768c84d752SLuo Jie default: 18778c84d752SLuo Jie return -EINVAL; 18788c84d752SLuo Jie } 18798c84d752SLuo Jie 18808c84d752SLuo Jie val = phy_read_mmd(phydev, MDIO_MMD_PCS, cdt_length_reg); 18818c84d752SLuo Jie if (val < 0) 18828c84d752SLuo Jie return val; 18838c84d752SLuo Jie 18848c84d752SLuo Jie return (FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val) * 824) / 10; 18858c84d752SLuo Jie } 18868c84d752SLuo Jie 18878c84d752SLuo Jie static int qca808x_cable_test_start(struct phy_device *phydev) 18888c84d752SLuo Jie { 18898c84d752SLuo Jie int ret; 18908c84d752SLuo Jie 18918c84d752SLuo Jie /* perform CDT with the following configs: 18928c84d752SLuo Jie * 1. disable hibernation. 18938c84d752SLuo Jie * 2. force PHY working in MDI mode. 18948c84d752SLuo Jie * 3. for PHY working in 1000BaseT. 18958c84d752SLuo Jie * 4. configure the threshold. 18968c84d752SLuo Jie */ 18978c84d752SLuo Jie 18988c84d752SLuo Jie ret = at803x_debug_reg_mask(phydev, QCA808X_DBG_AN_TEST, QCA808X_HIBERNATION_EN, 0); 18998c84d752SLuo Jie if (ret < 0) 19008c84d752SLuo Jie return ret; 19018c84d752SLuo Jie 19028c84d752SLuo Jie ret = at803x_config_mdix(phydev, ETH_TP_MDI); 19038c84d752SLuo Jie if (ret < 0) 19048c84d752SLuo Jie return ret; 19058c84d752SLuo Jie 19068c84d752SLuo Jie /* Force 1000base-T needs to configure PMA/PMD and MII_BMCR */ 19078c84d752SLuo Jie phydev->duplex = DUPLEX_FULL; 19088c84d752SLuo Jie phydev->speed = SPEED_1000; 19098c84d752SLuo Jie ret = genphy_c45_pma_setup_forced(phydev); 19108c84d752SLuo Jie if (ret < 0) 19118c84d752SLuo Jie return ret; 19128c84d752SLuo Jie 19138c84d752SLuo Jie ret = genphy_setup_forced(phydev); 19148c84d752SLuo Jie if (ret < 0) 19158c84d752SLuo Jie return ret; 19168c84d752SLuo Jie 19178c84d752SLuo Jie /* configure the thresholds for open, short, pair ok test */ 19188c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8074, 0xc040); 19198c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8076, 0xc040); 19208c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8077, 0xa060); 19218c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8078, 0xc050); 19228c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807a, 0xc060); 19238c84d752SLuo Jie phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807e, 0xb060); 19248c84d752SLuo Jie 19258c84d752SLuo Jie return 0; 19268c84d752SLuo Jie } 19278c84d752SLuo Jie 19288c84d752SLuo Jie static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished) 19298c84d752SLuo Jie { 19308c84d752SLuo Jie int ret, val; 19318c84d752SLuo Jie int pair_a, pair_b, pair_c, pair_d; 19328c84d752SLuo Jie 19338c84d752SLuo Jie *finished = false; 19348c84d752SLuo Jie 19358c84d752SLuo Jie ret = at803x_cdt_start(phydev, 0); 19368c84d752SLuo Jie if (ret) 19378c84d752SLuo Jie return ret; 19388c84d752SLuo Jie 19398c84d752SLuo Jie ret = at803x_cdt_wait_for_completion(phydev); 19408c84d752SLuo Jie if (ret) 19418c84d752SLuo Jie return ret; 19428c84d752SLuo Jie 19438c84d752SLuo Jie val = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA808X_MMD3_CDT_STATUS); 19448c84d752SLuo Jie if (val < 0) 19458c84d752SLuo Jie return val; 19468c84d752SLuo Jie 19478c84d752SLuo Jie pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val); 19488c84d752SLuo Jie pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val); 19498c84d752SLuo Jie pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val); 19508c84d752SLuo Jie pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val); 19518c84d752SLuo Jie 19528c84d752SLuo Jie ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A, 19538c84d752SLuo Jie qca808x_cable_test_result_trans(pair_a)); 19548c84d752SLuo Jie ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B, 19558c84d752SLuo Jie qca808x_cable_test_result_trans(pair_b)); 19568c84d752SLuo Jie ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C, 19578c84d752SLuo Jie qca808x_cable_test_result_trans(pair_c)); 19588c84d752SLuo Jie ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D, 19598c84d752SLuo Jie qca808x_cable_test_result_trans(pair_d)); 19608c84d752SLuo Jie 19618c84d752SLuo Jie if (qca808x_cdt_fault_length_valid(pair_a)) 19628c84d752SLuo Jie ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A, 19638c84d752SLuo Jie qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A)); 19648c84d752SLuo Jie if (qca808x_cdt_fault_length_valid(pair_b)) 19658c84d752SLuo Jie ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B, 19668c84d752SLuo Jie qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B)); 19678c84d752SLuo Jie if (qca808x_cdt_fault_length_valid(pair_c)) 19688c84d752SLuo Jie ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C, 19698c84d752SLuo Jie qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C)); 19708c84d752SLuo Jie if (qca808x_cdt_fault_length_valid(pair_d)) 19718c84d752SLuo Jie ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D, 19728c84d752SLuo Jie qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D)); 19738c84d752SLuo Jie 19748c84d752SLuo Jie *finished = true; 19758c84d752SLuo Jie 19768c84d752SLuo Jie return 0; 19778c84d752SLuo Jie } 19788c84d752SLuo Jie 1979317420abSMugunthan V N static struct phy_driver at803x_driver[] = { 1980317420abSMugunthan V N { 198196c36712SMichael Walle /* Qualcomm Atheros AR8035 */ 19820465d8f8SMichael Walle PHY_ID_MATCH_EXACT(ATH8035_PHY_ID), 198396c36712SMichael Walle .name = "Qualcomm Atheros AR8035", 19846cb75767SMichael Walle .flags = PHY_POLL_CABLE_TEST, 19852f664823SMichael Walle .probe = at803x_probe, 19862318ca8aSMichael Walle .remove = at803x_remove, 19877dce80c2SOleksij Rempel .config_aneg = at803x_config_aneg, 19880ca7111aSMatus Ujhelyi .config_init = at803x_config_init, 1989cde0f4f8SMichael Walle .soft_reset = genphy_soft_reset, 1990ea13c9eeSMugunthan V N .set_wol = at803x_set_wol, 1991ea13c9eeSMugunthan V N .get_wol = at803x_get_wol, 19926229ed1fSDaniel Mack .suspend = at803x_suspend, 19936229ed1fSDaniel Mack .resume = at803x_resume, 1994dcdecdcfSHeiner Kallweit /* PHY_GBIT_FEATURES */ 199506d5f344SRussell King .read_status = at803x_read_status, 19960eae5982SMåns Rullgård .config_intr = at803x_config_intr, 199729773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 1998cde0f4f8SMichael Walle .get_tunable = at803x_get_tunable, 1999cde0f4f8SMichael Walle .set_tunable = at803x_set_tunable, 20006cb75767SMichael Walle .cable_test_start = at803x_cable_test_start, 20016cb75767SMichael Walle .cable_test_get_status = at803x_cable_test_get_status, 2002317420abSMugunthan V N }, { 200396c36712SMichael Walle /* Qualcomm Atheros AR8030 */ 2004bd8ca17fSDaniel Mack .phy_id = ATH8030_PHY_ID, 200596c36712SMichael Walle .name = "Qualcomm Atheros AR8030", 20060465d8f8SMichael Walle .phy_id_mask = AT8030_PHY_ID_MASK, 20072f664823SMichael Walle .probe = at803x_probe, 20082318ca8aSMichael Walle .remove = at803x_remove, 20090ca7111aSMatus Ujhelyi .config_init = at803x_config_init, 201013a56b44SDaniel Mack .link_change_notify = at803x_link_change_notify, 2011ea13c9eeSMugunthan V N .set_wol = at803x_set_wol, 2012ea13c9eeSMugunthan V N .get_wol = at803x_get_wol, 20136229ed1fSDaniel Mack .suspend = at803x_suspend, 20146229ed1fSDaniel Mack .resume = at803x_resume, 2015dcdecdcfSHeiner Kallweit /* PHY_BASIC_FEATURES */ 20160eae5982SMåns Rullgård .config_intr = at803x_config_intr, 201729773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 201805d7cce8SMugunthan V N }, { 201996c36712SMichael Walle /* Qualcomm Atheros AR8031/AR8033 */ 20200465d8f8SMichael Walle PHY_ID_MATCH_EXACT(ATH8031_PHY_ID), 202196c36712SMichael Walle .name = "Qualcomm Atheros AR8031/AR8033", 20226cb75767SMichael Walle .flags = PHY_POLL_CABLE_TEST, 20232f664823SMichael Walle .probe = at803x_probe, 20242318ca8aSMichael Walle .remove = at803x_remove, 202505d7cce8SMugunthan V N .config_init = at803x_config_init, 202663477a5dSMichael Walle .config_aneg = at803x_config_aneg, 2027cde0f4f8SMichael Walle .soft_reset = genphy_soft_reset, 202805d7cce8SMugunthan V N .set_wol = at803x_set_wol, 202905d7cce8SMugunthan V N .get_wol = at803x_get_wol, 20306229ed1fSDaniel Mack .suspend = at803x_suspend, 20316229ed1fSDaniel Mack .resume = at803x_resume, 2032c329e5afSDavid Bauer .read_page = at803x_read_page, 2033c329e5afSDavid Bauer .write_page = at803x_write_page, 2034b856150cSDavid Bauer .get_features = at803x_get_features, 203506d5f344SRussell King .read_status = at803x_read_status, 203677a99394SZhao Qiang .config_intr = &at803x_config_intr, 203729773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 2038cde0f4f8SMichael Walle .get_tunable = at803x_get_tunable, 2039cde0f4f8SMichael Walle .set_tunable = at803x_set_tunable, 20406cb75767SMichael Walle .cable_test_start = at803x_cable_test_start, 20416cb75767SMichael Walle .cable_test_get_status = at803x_cable_test_get_status, 20427908d2ceSOleksij Rempel }, { 20435800091aSDavid Bauer /* Qualcomm Atheros AR8032 */ 20445800091aSDavid Bauer PHY_ID_MATCH_EXACT(ATH8032_PHY_ID), 20455800091aSDavid Bauer .name = "Qualcomm Atheros AR8032", 20465800091aSDavid Bauer .probe = at803x_probe, 20475800091aSDavid Bauer .remove = at803x_remove, 2048dc0f3ed1SOleksij Rempel .flags = PHY_POLL_CABLE_TEST, 20495800091aSDavid Bauer .config_init = at803x_config_init, 20505800091aSDavid Bauer .link_change_notify = at803x_link_change_notify, 20515800091aSDavid Bauer .set_wol = at803x_set_wol, 20525800091aSDavid Bauer .get_wol = at803x_get_wol, 20535800091aSDavid Bauer .suspend = at803x_suspend, 20545800091aSDavid Bauer .resume = at803x_resume, 20555800091aSDavid Bauer /* PHY_BASIC_FEATURES */ 20565800091aSDavid Bauer .config_intr = at803x_config_intr, 205729773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 2058dc0f3ed1SOleksij Rempel .cable_test_start = at803x_cable_test_start, 2059dc0f3ed1SOleksij Rempel .cable_test_get_status = at803x_cable_test_get_status, 20605800091aSDavid Bauer }, { 20617908d2ceSOleksij Rempel /* ATHEROS AR9331 */ 20627908d2ceSOleksij Rempel PHY_ID_MATCH_EXACT(ATH9331_PHY_ID), 206396c36712SMichael Walle .name = "Qualcomm Atheros AR9331 built-in PHY", 20647908d2ceSOleksij Rempel .suspend = at803x_suspend, 20657908d2ceSOleksij Rempel .resume = at803x_resume, 2066dc0f3ed1SOleksij Rempel .flags = PHY_POLL_CABLE_TEST, 20677908d2ceSOleksij Rempel /* PHY_BASIC_FEATURES */ 20687908d2ceSOleksij Rempel .config_intr = &at803x_config_intr, 206929773097SIoana Ciornei .handle_interrupt = at803x_handle_interrupt, 2070dc0f3ed1SOleksij Rempel .cable_test_start = at803x_cable_test_start, 2071dc0f3ed1SOleksij Rempel .cable_test_get_status = at803x_cable_test_get_status, 20727dce80c2SOleksij Rempel .read_status = at803x_read_status, 20737dce80c2SOleksij Rempel .soft_reset = genphy_soft_reset, 20747dce80c2SOleksij Rempel .config_aneg = at803x_config_aneg, 2075272833b9SAnsuel Smith }, { 2076fada2ce0SDavid Bauer /* Qualcomm Atheros QCA9561 */ 2077fada2ce0SDavid Bauer PHY_ID_MATCH_EXACT(QCA9561_PHY_ID), 2078fada2ce0SDavid Bauer .name = "Qualcomm Atheros QCA9561 built-in PHY", 2079fada2ce0SDavid Bauer .suspend = at803x_suspend, 2080fada2ce0SDavid Bauer .resume = at803x_resume, 2081fada2ce0SDavid Bauer .flags = PHY_POLL_CABLE_TEST, 2082fada2ce0SDavid Bauer /* PHY_BASIC_FEATURES */ 2083fada2ce0SDavid Bauer .config_intr = &at803x_config_intr, 2084fada2ce0SDavid Bauer .handle_interrupt = at803x_handle_interrupt, 2085fada2ce0SDavid Bauer .cable_test_start = at803x_cable_test_start, 2086fada2ce0SDavid Bauer .cable_test_get_status = at803x_cable_test_get_status, 2087fada2ce0SDavid Bauer .read_status = at803x_read_status, 2088fada2ce0SDavid Bauer .soft_reset = genphy_soft_reset, 2089fada2ce0SDavid Bauer .config_aneg = at803x_config_aneg, 2090fada2ce0SDavid Bauer }, { 2091272833b9SAnsuel Smith /* QCA8337 */ 2092272833b9SAnsuel Smith .phy_id = QCA8337_PHY_ID, 2093272833b9SAnsuel Smith .phy_id_mask = QCA8K_PHY_ID_MASK, 2094d44fd860SAnsuel Smith .name = "Qualcomm Atheros 8337 internal PHY", 2095272833b9SAnsuel Smith /* PHY_GBIT_FEATURES */ 20961ca83119SAnsuel Smith .link_change_notify = qca83xx_link_change_notify, 2097272833b9SAnsuel Smith .probe = at803x_probe, 2098272833b9SAnsuel Smith .flags = PHY_IS_INTERNAL, 2099272833b9SAnsuel Smith .config_init = qca83xx_config_init, 2100272833b9SAnsuel Smith .soft_reset = genphy_soft_reset, 2101272833b9SAnsuel Smith .get_sset_count = at803x_get_sset_count, 2102272833b9SAnsuel Smith .get_strings = at803x_get_strings, 2103272833b9SAnsuel Smith .get_stats = at803x_get_stats, 2104ba3c01eeSAnsuel Smith .suspend = qca83xx_suspend, 2105ba3c01eeSAnsuel Smith .resume = qca83xx_resume, 21060ccf8511SAnsuel Smith }, { 2107b4df02b5SAnsuel Smith /* QCA8327-A from switch QCA8327-AL1A */ 2108b4df02b5SAnsuel Smith .phy_id = QCA8327_A_PHY_ID, 21090ccf8511SAnsuel Smith .phy_id_mask = QCA8K_PHY_ID_MASK, 2110d44fd860SAnsuel Smith .name = "Qualcomm Atheros 8327-A internal PHY", 2111b4df02b5SAnsuel Smith /* PHY_GBIT_FEATURES */ 21121ca83119SAnsuel Smith .link_change_notify = qca83xx_link_change_notify, 2113b4df02b5SAnsuel Smith .probe = at803x_probe, 2114b4df02b5SAnsuel Smith .flags = PHY_IS_INTERNAL, 2115b4df02b5SAnsuel Smith .config_init = qca83xx_config_init, 2116b4df02b5SAnsuel Smith .soft_reset = genphy_soft_reset, 2117b4df02b5SAnsuel Smith .get_sset_count = at803x_get_sset_count, 2118b4df02b5SAnsuel Smith .get_strings = at803x_get_strings, 2119b4df02b5SAnsuel Smith .get_stats = at803x_get_stats, 2120ba3c01eeSAnsuel Smith .suspend = qca83xx_suspend, 2121ba3c01eeSAnsuel Smith .resume = qca83xx_resume, 2122b4df02b5SAnsuel Smith }, { 2123b4df02b5SAnsuel Smith /* QCA8327-B from switch QCA8327-BL1A */ 2124b4df02b5SAnsuel Smith .phy_id = QCA8327_B_PHY_ID, 2125b4df02b5SAnsuel Smith .phy_id_mask = QCA8K_PHY_ID_MASK, 2126d44fd860SAnsuel Smith .name = "Qualcomm Atheros 8327-B internal PHY", 21270ccf8511SAnsuel Smith /* PHY_GBIT_FEATURES */ 21281ca83119SAnsuel Smith .link_change_notify = qca83xx_link_change_notify, 21290ccf8511SAnsuel Smith .probe = at803x_probe, 21300ccf8511SAnsuel Smith .flags = PHY_IS_INTERNAL, 21310ccf8511SAnsuel Smith .config_init = qca83xx_config_init, 21320ccf8511SAnsuel Smith .soft_reset = genphy_soft_reset, 21330ccf8511SAnsuel Smith .get_sset_count = at803x_get_sset_count, 21340ccf8511SAnsuel Smith .get_strings = at803x_get_strings, 21350ccf8511SAnsuel Smith .get_stats = at803x_get_stats, 2136ba3c01eeSAnsuel Smith .suspend = qca83xx_suspend, 2137ba3c01eeSAnsuel Smith .resume = qca83xx_resume, 2138daf61732SLuo Jie }, { 2139daf61732SLuo Jie /* Qualcomm QCA8081 */ 2140daf61732SLuo Jie PHY_ID_MATCH_EXACT(QCA8081_PHY_ID), 2141daf61732SLuo Jie .name = "Qualcomm QCA8081", 21428c84d752SLuo Jie .flags = PHY_POLL_CABLE_TEST, 2143daf61732SLuo Jie .config_intr = at803x_config_intr, 2144daf61732SLuo Jie .handle_interrupt = at803x_handle_interrupt, 2145daf61732SLuo Jie .get_tunable = at803x_get_tunable, 2146daf61732SLuo Jie .set_tunable = at803x_set_tunable, 2147daf61732SLuo Jie .set_wol = at803x_set_wol, 2148daf61732SLuo Jie .get_wol = at803x_get_wol, 2149765c22aaSLuo Jie .get_features = at803x_get_features, 2150f884d449SLuo Jie .config_aneg = at803x_config_aneg, 2151daf61732SLuo Jie .suspend = genphy_suspend, 2152daf61732SLuo Jie .resume = genphy_resume, 215379c7bc05SLuo Jie .read_status = qca808x_read_status, 21542acdd43fSLuo Jie .config_init = qca808x_config_init, 21559d4dae29SLuo Jie .soft_reset = qca808x_soft_reset, 21568c84d752SLuo Jie .cable_test_start = qca808x_cable_test_start, 21578c84d752SLuo Jie .cable_test_get_status = qca808x_cable_test_get_status, 2158272833b9SAnsuel Smith }, }; 21590ca7111aSMatus Ujhelyi 216050fd7150SJohan Hovold module_phy_driver(at803x_driver); 21610ca7111aSMatus Ujhelyi 21620ca7111aSMatus Ujhelyi static struct mdio_device_id __maybe_unused atheros_tbl[] = { 21630465d8f8SMichael Walle { ATH8030_PHY_ID, AT8030_PHY_ID_MASK }, 21640465d8f8SMichael Walle { PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) }, 21655800091aSDavid Bauer { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) }, 21660465d8f8SMichael Walle { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) }, 21677908d2ceSOleksij Rempel { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) }, 21680ccf8511SAnsuel Smith { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) }, 2169b4df02b5SAnsuel Smith { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) }, 2170b4df02b5SAnsuel Smith { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) }, 2171fada2ce0SDavid Bauer { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) }, 2172daf61732SLuo Jie { PHY_ID_MATCH_EXACT(QCA8081_PHY_ID) }, 21730ca7111aSMatus Ujhelyi { } 21740ca7111aSMatus Ujhelyi }; 21750ca7111aSMatus Ujhelyi 21760ca7111aSMatus Ujhelyi MODULE_DEVICE_TABLE(mdio, atheros_tbl); 2177