Andrew Lunn | a2443fd | 2019-01-21 19:05:50 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 2 | /* |
| 3 | * drivers/net/phy/at803x.c |
| 4 | * |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 5 | * Driver for Qualcomm Atheros AR803x PHY |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 6 | * |
| 7 | * Author: Matus Ujhelyi <ujhelyi.m@gmail.com> |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/phy.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/etherdevice.h> |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 15 | #include <linux/ethtool_netlink.h> |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 16 | #include <linux/of_gpio.h> |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 17 | #include <linux/bitfield.h> |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 18 | #include <linux/gpio/consumer.h> |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 19 | #include <linux/regulator/of_regulator.h> |
| 20 | #include <linux/regulator/driver.h> |
| 21 | #include <linux/regulator/consumer.h> |
| 22 | #include <dt-bindings/net/qca-ar803x.h> |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 23 | |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 24 | #define AT803X_SPECIFIC_FUNCTION_CONTROL 0x10 |
| 25 | #define AT803X_SFC_ASSERT_CRS BIT(11) |
| 26 | #define AT803X_SFC_FORCE_LINK BIT(10) |
| 27 | #define AT803X_SFC_MDI_CROSSOVER_MODE_M GENMASK(6, 5) |
| 28 | #define AT803X_SFC_AUTOMATIC_CROSSOVER 0x3 |
| 29 | #define AT803X_SFC_MANUAL_MDIX 0x1 |
| 30 | #define AT803X_SFC_MANUAL_MDI 0x0 |
| 31 | #define AT803X_SFC_SQE_TEST BIT(2) |
| 32 | #define AT803X_SFC_POLARITY_REVERSAL BIT(1) |
| 33 | #define AT803X_SFC_DISABLE_JABBER BIT(0) |
| 34 | |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 35 | #define AT803X_SPECIFIC_STATUS 0x11 |
Luo Jie | 9540cdd | 2021-10-24 16:27:28 +0800 | [diff] [blame] | 36 | #define AT803X_SS_SPEED_MASK GENMASK(15, 14) |
| 37 | #define AT803X_SS_SPEED_1000 2 |
| 38 | #define AT803X_SS_SPEED_100 1 |
| 39 | #define AT803X_SS_SPEED_10 0 |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 40 | #define AT803X_SS_DUPLEX BIT(13) |
| 41 | #define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11) |
| 42 | #define AT803X_SS_MDIX BIT(6) |
| 43 | |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 44 | #define QCA808X_SS_SPEED_MASK GENMASK(9, 7) |
| 45 | #define QCA808X_SS_SPEED_2500 4 |
| 46 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 47 | #define AT803X_INTR_ENABLE 0x12 |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 48 | #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15) |
| 49 | #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14) |
| 50 | #define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13) |
| 51 | #define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12) |
| 52 | #define AT803X_INTR_ENABLE_LINK_FAIL BIT(11) |
| 53 | #define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10) |
| 54 | #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5) |
| 55 | #define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1) |
| 56 | #define AT803X_INTR_ENABLE_WOL BIT(0) |
| 57 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 58 | #define AT803X_INTR_STATUS 0x13 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 59 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 60 | #define AT803X_SMART_SPEED 0x14 |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 61 | #define AT803X_SMART_SPEED_ENABLE BIT(5) |
| 62 | #define AT803X_SMART_SPEED_RETRY_LIMIT_MASK GENMASK(4, 2) |
| 63 | #define AT803X_SMART_SPEED_BYPASS_TIMER BIT(1) |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 64 | #define AT803X_CDT 0x16 |
| 65 | #define AT803X_CDT_MDI_PAIR_MASK GENMASK(9, 8) |
| 66 | #define AT803X_CDT_ENABLE_TEST BIT(0) |
| 67 | #define AT803X_CDT_STATUS 0x1c |
| 68 | #define AT803X_CDT_STATUS_STAT_NORMAL 0 |
| 69 | #define AT803X_CDT_STATUS_STAT_SHORT 1 |
| 70 | #define AT803X_CDT_STATUS_STAT_OPEN 2 |
| 71 | #define AT803X_CDT_STATUS_STAT_FAIL 3 |
| 72 | #define AT803X_CDT_STATUS_STAT_MASK GENMASK(9, 8) |
| 73 | #define AT803X_CDT_STATUS_DELTA_TIME_MASK GENMASK(7, 0) |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 74 | #define AT803X_LED_CONTROL 0x18 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 75 | |
Luo Jie | 7beecaf | 2021-10-24 16:27:27 +0800 | [diff] [blame] | 76 | #define AT803X_PHY_MMD3_WOL_CTRL 0x8012 |
| 77 | #define AT803X_WOL_EN BIT(5) |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 78 | #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C |
| 79 | #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B |
| 80 | #define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A |
Zefir Kurtisi | f62265b | 2016-10-24 12:40:54 +0200 | [diff] [blame] | 81 | #define AT803X_REG_CHIP_CONFIG 0x1f |
| 82 | #define AT803X_BT_BX_REG_SEL 0x8000 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 83 | |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 84 | #define AT803X_DEBUG_ADDR 0x1D |
| 85 | #define AT803X_DEBUG_DATA 0x1E |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 86 | |
Zefir Kurtisi | f62265b | 2016-10-24 12:40:54 +0200 | [diff] [blame] | 87 | #define AT803X_MODE_CFG_MASK 0x0F |
| 88 | #define AT803X_MODE_CFG_SGMII 0x01 |
| 89 | |
Ansuel Smith | d0e13fd | 2021-05-14 23:00:14 +0200 | [diff] [blame] | 90 | #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/ |
| 91 | #define AT803X_PSSR_MR_AN_COMPLETE 0x0200 |
Zefir Kurtisi | f62265b | 2016-10-24 12:40:54 +0200 | [diff] [blame] | 92 | |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 93 | #define AT803X_DEBUG_ANALOG_TEST_CTRL 0x00 |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 94 | #define QCA8327_DEBUG_MANU_CTRL_EN BIT(2) |
| 95 | #define QCA8337_DEBUG_MANU_CTRL_EN GENMASK(3, 2) |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 96 | #define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15) |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 97 | |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 98 | #define AT803X_DEBUG_SYSTEM_CTRL_MODE 0x05 |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 99 | #define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8) |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 100 | |
Ansuel Smith | ba3c01e | 2021-10-10 00:46:15 +0200 | [diff] [blame] | 101 | #define AT803X_DEBUG_REG_HIB_CTRL 0x0b |
| 102 | #define AT803X_DEBUG_HIB_CTRL_SEL_RST_80U BIT(10) |
| 103 | #define AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE BIT(13) |
| 104 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 105 | #define AT803X_DEBUG_REG_3C 0x3C |
| 106 | |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 107 | #define AT803X_DEBUG_REG_GREEN 0x3D |
Ansuel Smith | ba3c01e | 2021-10-10 00:46:15 +0200 | [diff] [blame] | 108 | #define AT803X_DEBUG_GATE_CLK_IN1000 BIT(6) |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 109 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 110 | #define AT803X_DEBUG_REG_1F 0x1F |
| 111 | #define AT803X_DEBUG_PLL_ON BIT(2) |
| 112 | #define AT803X_DEBUG_RGMII_1V8 BIT(3) |
| 113 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 114 | #define MDIO_AZ_DEBUG 0x800D |
| 115 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 116 | /* AT803x supports either the XTAL input pad, an internal PLL or the |
| 117 | * DSP as clock reference for the clock output pad. The XTAL reference |
| 118 | * is only used for 25 MHz output, all other frequencies need the PLL. |
| 119 | * The DSP as a clock reference is used in synchronous ethernet |
| 120 | * applications. |
| 121 | * |
| 122 | * By default the PLL is only enabled if there is a link. Otherwise |
| 123 | * the PHY will go into low power state and disabled the PLL. You can |
| 124 | * set the PLL_ON bit (see debug register 0x1f) to keep the PLL always |
| 125 | * enabled. |
| 126 | */ |
| 127 | #define AT803X_MMD7_CLK25M 0x8016 |
| 128 | #define AT803X_CLK_OUT_MASK GENMASK(4, 2) |
| 129 | #define AT803X_CLK_OUT_25MHZ_XTAL 0 |
| 130 | #define AT803X_CLK_OUT_25MHZ_DSP 1 |
| 131 | #define AT803X_CLK_OUT_50MHZ_PLL 2 |
| 132 | #define AT803X_CLK_OUT_50MHZ_DSP 3 |
| 133 | #define AT803X_CLK_OUT_62_5MHZ_PLL 4 |
| 134 | #define AT803X_CLK_OUT_62_5MHZ_DSP 5 |
| 135 | #define AT803X_CLK_OUT_125MHZ_PLL 6 |
| 136 | #define AT803X_CLK_OUT_125MHZ_DSP 7 |
| 137 | |
Michael Walle | 428061f | 2019-11-06 23:36:15 +0100 | [diff] [blame] | 138 | /* The AR8035 has another mask which is compatible with the AR8031/AR8033 mask |
| 139 | * but doesn't support choosing between XTAL/PLL and DSP. |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 140 | */ |
| 141 | #define AT8035_CLK_OUT_MASK GENMASK(4, 3) |
| 142 | |
| 143 | #define AT803X_CLK_OUT_STRENGTH_MASK GENMASK(8, 7) |
| 144 | #define AT803X_CLK_OUT_STRENGTH_FULL 0 |
| 145 | #define AT803X_CLK_OUT_STRENGTH_HALF 1 |
| 146 | #define AT803X_CLK_OUT_STRENGTH_QUARTER 2 |
| 147 | |
Ansuel Smith | d0e13fd | 2021-05-14 23:00:14 +0200 | [diff] [blame] | 148 | #define AT803X_DEFAULT_DOWNSHIFT 5 |
| 149 | #define AT803X_MIN_DOWNSHIFT 2 |
| 150 | #define AT803X_MAX_DOWNSHIFT 9 |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 151 | |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 152 | #define AT803X_MMD3_SMARTEEE_CTL1 0x805b |
| 153 | #define AT803X_MMD3_SMARTEEE_CTL2 0x805c |
| 154 | #define AT803X_MMD3_SMARTEEE_CTL3 0x805d |
| 155 | #define AT803X_MMD3_SMARTEEE_CTL3_LPI_EN BIT(8) |
| 156 | |
Ansuel Smith | d0e13fd | 2021-05-14 23:00:14 +0200 | [diff] [blame] | 157 | #define ATH9331_PHY_ID 0x004dd041 |
| 158 | #define ATH8030_PHY_ID 0x004dd076 |
| 159 | #define ATH8031_PHY_ID 0x004dd074 |
| 160 | #define ATH8032_PHY_ID 0x004dd023 |
| 161 | #define ATH8035_PHY_ID 0x004dd072 |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 162 | #define AT8030_PHY_ID_MASK 0xffffffef |
Daniel Mack | bd8ca17 | 2014-06-18 11:01:42 +0200 | [diff] [blame] | 163 | |
Luo Jie | daf6173 | 2021-10-24 16:27:29 +0800 | [diff] [blame] | 164 | #define QCA8081_PHY_ID 0x004dd101 |
| 165 | |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 166 | #define QCA8327_A_PHY_ID 0x004dd033 |
| 167 | #define QCA8327_B_PHY_ID 0x004dd034 |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 168 | #define QCA8337_PHY_ID 0x004dd036 |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame] | 169 | #define QCA9561_PHY_ID 0x004dd042 |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 170 | #define QCA8K_PHY_ID_MASK 0xffffffff |
| 171 | |
| 172 | #define QCA8K_DEVFLAGS_REVISION_MASK GENMASK(2, 0) |
| 173 | |
Ansuel Smith | d0e13fd | 2021-05-14 23:00:14 +0200 | [diff] [blame] | 174 | #define AT803X_PAGE_FIBER 0 |
| 175 | #define AT803X_PAGE_COPPER 1 |
| 176 | |
| 177 | /* don't turn off internal PLL */ |
| 178 | #define AT803X_KEEP_PLL_ENABLED BIT(0) |
| 179 | #define AT803X_DISABLE_SMARTEEE BIT(1) |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 180 | |
Luo Jie | 2acdd43f | 2021-10-24 16:27:35 +0800 | [diff] [blame] | 181 | /* ADC threshold */ |
| 182 | #define QCA808X_PHY_DEBUG_ADC_THRESHOLD 0x2c80 |
| 183 | #define QCA808X_ADC_THRESHOLD_MASK GENMASK(7, 0) |
| 184 | #define QCA808X_ADC_THRESHOLD_80MV 0 |
| 185 | #define QCA808X_ADC_THRESHOLD_100MV 0xf0 |
| 186 | #define QCA808X_ADC_THRESHOLD_200MV 0x0f |
| 187 | #define QCA808X_ADC_THRESHOLD_300MV 0xff |
| 188 | |
| 189 | /* CLD control */ |
| 190 | #define QCA808X_PHY_MMD3_ADDR_CLD_CTRL7 0x8007 |
| 191 | #define QCA808X_8023AZ_AFE_CTRL_MASK GENMASK(8, 4) |
| 192 | #define QCA808X_8023AZ_AFE_EN 0x90 |
| 193 | |
| 194 | /* AZ control */ |
| 195 | #define QCA808X_PHY_MMD3_AZ_TRAINING_CTRL 0x8008 |
| 196 | #define QCA808X_MMD3_AZ_TRAINING_VAL 0x1c32 |
| 197 | |
| 198 | #define QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB 0x8014 |
| 199 | #define QCA808X_MSE_THRESHOLD_20DB_VALUE 0x529 |
| 200 | |
| 201 | #define QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB 0x800E |
| 202 | #define QCA808X_MSE_THRESHOLD_17DB_VALUE 0x341 |
| 203 | |
| 204 | #define QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB 0x801E |
| 205 | #define QCA808X_MSE_THRESHOLD_27DB_VALUE 0x419 |
| 206 | |
| 207 | #define QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB 0x8020 |
| 208 | #define QCA808X_MSE_THRESHOLD_28DB_VALUE 0x341 |
| 209 | |
| 210 | #define QCA808X_PHY_MMD7_TOP_OPTION1 0x901c |
| 211 | #define QCA808X_TOP_OPTION1_DATA 0x0 |
| 212 | |
| 213 | #define QCA808X_PHY_MMD3_DEBUG_1 0xa100 |
| 214 | #define QCA808X_MMD3_DEBUG_1_VALUE 0x9203 |
| 215 | #define QCA808X_PHY_MMD3_DEBUG_2 0xa101 |
| 216 | #define QCA808X_MMD3_DEBUG_2_VALUE 0x48ad |
| 217 | #define QCA808X_PHY_MMD3_DEBUG_3 0xa103 |
| 218 | #define QCA808X_MMD3_DEBUG_3_VALUE 0x1698 |
| 219 | #define QCA808X_PHY_MMD3_DEBUG_4 0xa105 |
| 220 | #define QCA808X_MMD3_DEBUG_4_VALUE 0x8001 |
| 221 | #define QCA808X_PHY_MMD3_DEBUG_5 0xa106 |
| 222 | #define QCA808X_MMD3_DEBUG_5_VALUE 0x1111 |
| 223 | #define QCA808X_PHY_MMD3_DEBUG_6 0xa011 |
| 224 | #define QCA808X_MMD3_DEBUG_6_VALUE 0x5f85 |
| 225 | |
Luo Jie | 9d4dae2 | 2021-10-24 16:27:36 +0800 | [diff] [blame] | 226 | /* master/slave seed config */ |
| 227 | #define QCA808X_PHY_DEBUG_LOCAL_SEED 9 |
| 228 | #define QCA808X_MASTER_SLAVE_SEED_ENABLE BIT(1) |
| 229 | #define QCA808X_MASTER_SLAVE_SEED_CFG GENMASK(12, 2) |
| 230 | #define QCA808X_MASTER_SLAVE_SEED_RANGE 0x32 |
| 231 | |
Luo Jie | 8c84d75 | 2021-10-24 16:27:38 +0800 | [diff] [blame] | 232 | /* Hibernation yields lower power consumpiton in contrast with normal operation mode. |
| 233 | * when the copper cable is unplugged, the PHY enters into hibernation mode in about 10s. |
| 234 | */ |
| 235 | #define QCA808X_DBG_AN_TEST 0xb |
| 236 | #define QCA808X_HIBERNATION_EN BIT(15) |
| 237 | |
| 238 | #define QCA808X_CDT_ENABLE_TEST BIT(15) |
| 239 | #define QCA808X_CDT_INTER_CHECK_DIS BIT(13) |
| 240 | #define QCA808X_CDT_LENGTH_UNIT BIT(10) |
| 241 | |
| 242 | #define QCA808X_MMD3_CDT_STATUS 0x8064 |
| 243 | #define QCA808X_MMD3_CDT_DIAG_PAIR_A 0x8065 |
| 244 | #define QCA808X_MMD3_CDT_DIAG_PAIR_B 0x8066 |
| 245 | #define QCA808X_MMD3_CDT_DIAG_PAIR_C 0x8067 |
| 246 | #define QCA808X_MMD3_CDT_DIAG_PAIR_D 0x8068 |
| 247 | #define QCA808X_CDT_DIAG_LENGTH GENMASK(7, 0) |
| 248 | |
| 249 | #define QCA808X_CDT_CODE_PAIR_A GENMASK(15, 12) |
| 250 | #define QCA808X_CDT_CODE_PAIR_B GENMASK(11, 8) |
| 251 | #define QCA808X_CDT_CODE_PAIR_C GENMASK(7, 4) |
| 252 | #define QCA808X_CDT_CODE_PAIR_D GENMASK(3, 0) |
| 253 | #define QCA808X_CDT_STATUS_STAT_FAIL 0 |
| 254 | #define QCA808X_CDT_STATUS_STAT_NORMAL 1 |
| 255 | #define QCA808X_CDT_STATUS_STAT_OPEN 2 |
| 256 | #define QCA808X_CDT_STATUS_STAT_SHORT 3 |
| 257 | |
Luo Jie | daf6173 | 2021-10-24 16:27:29 +0800 | [diff] [blame] | 258 | MODULE_DESCRIPTION("Qualcomm Atheros AR803x and QCA808X PHY driver"); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 259 | MODULE_AUTHOR("Matus Ujhelyi"); |
| 260 | MODULE_LICENSE("GPL"); |
| 261 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 262 | enum stat_access_type { |
| 263 | PHY, |
| 264 | MMD |
| 265 | }; |
| 266 | |
| 267 | struct at803x_hw_stat { |
| 268 | const char *string; |
| 269 | u8 reg; |
| 270 | u32 mask; |
| 271 | enum stat_access_type access_type; |
| 272 | }; |
| 273 | |
| 274 | static struct at803x_hw_stat at803x_hw_stats[] = { |
| 275 | { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY}, |
| 276 | { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY}, |
| 277 | { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD}, |
| 278 | }; |
| 279 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 280 | struct at803x_priv { |
| 281 | int flags; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 282 | u16 clk_25m_reg; |
| 283 | u16 clk_25m_mask; |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 284 | u8 smarteee_lpi_tw_1g; |
| 285 | u8 smarteee_lpi_tw_100m; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 286 | struct regulator_dev *vddio_rdev; |
| 287 | struct regulator_dev *vddh_rdev; |
| 288 | struct regulator *vddio; |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 289 | u64 stats[ARRAY_SIZE(at803x_hw_stats)]; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 290 | }; |
| 291 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 292 | struct at803x_context { |
| 293 | u16 bmcr; |
| 294 | u16 advertise; |
| 295 | u16 control1000; |
| 296 | u16 int_enable; |
| 297 | u16 smart_speed; |
| 298 | u16 led_control; |
| 299 | }; |
| 300 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 301 | static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data) |
| 302 | { |
| 303 | int ret; |
| 304 | |
| 305 | ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); |
| 306 | if (ret < 0) |
| 307 | return ret; |
| 308 | |
| 309 | return phy_write(phydev, AT803X_DEBUG_DATA, data); |
| 310 | } |
| 311 | |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 312 | static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg) |
| 313 | { |
| 314 | int ret; |
| 315 | |
| 316 | ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); |
| 317 | if (ret < 0) |
| 318 | return ret; |
| 319 | |
| 320 | return phy_read(phydev, AT803X_DEBUG_DATA); |
| 321 | } |
| 322 | |
| 323 | static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg, |
| 324 | u16 clear, u16 set) |
| 325 | { |
| 326 | u16 val; |
| 327 | int ret; |
| 328 | |
| 329 | ret = at803x_debug_reg_read(phydev, reg); |
| 330 | if (ret < 0) |
| 331 | return ret; |
| 332 | |
| 333 | val = ret & 0xffff; |
| 334 | val &= ~clear; |
| 335 | val |= set; |
| 336 | |
| 337 | return phy_write(phydev, AT803X_DEBUG_DATA, val); |
| 338 | } |
| 339 | |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 340 | static int at803x_write_page(struct phy_device *phydev, int page) |
| 341 | { |
| 342 | int mask; |
| 343 | int set; |
| 344 | |
| 345 | if (page == AT803X_PAGE_COPPER) { |
| 346 | set = AT803X_BT_BX_REG_SEL; |
| 347 | mask = 0; |
| 348 | } else { |
| 349 | set = 0; |
| 350 | mask = AT803X_BT_BX_REG_SEL; |
| 351 | } |
| 352 | |
| 353 | return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set); |
| 354 | } |
| 355 | |
| 356 | static int at803x_read_page(struct phy_device *phydev) |
| 357 | { |
| 358 | int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG); |
| 359 | |
| 360 | if (ccr < 0) |
| 361 | return ccr; |
| 362 | |
| 363 | if (ccr & AT803X_BT_BX_REG_SEL) |
| 364 | return AT803X_PAGE_COPPER; |
| 365 | |
| 366 | return AT803X_PAGE_FIBER; |
| 367 | } |
| 368 | |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 369 | static int at803x_enable_rx_delay(struct phy_device *phydev) |
| 370 | { |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 371 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0, |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 372 | AT803X_DEBUG_RX_CLK_DLY_EN); |
| 373 | } |
| 374 | |
| 375 | static int at803x_enable_tx_delay(struct phy_device *phydev) |
| 376 | { |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 377 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0, |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 378 | AT803X_DEBUG_TX_CLK_DLY_EN); |
| 379 | } |
| 380 | |
Vinod Koul | 43f2ebd | 2019-02-21 15:53:14 +0530 | [diff] [blame] | 381 | static int at803x_disable_rx_delay(struct phy_device *phydev) |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 382 | { |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 383 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, |
Vinod Koul | cd28d1d | 2019-01-21 14:43:17 +0530 | [diff] [blame] | 384 | AT803X_DEBUG_RX_CLK_DLY_EN, 0); |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 385 | } |
| 386 | |
Vinod Koul | 43f2ebd | 2019-02-21 15:53:14 +0530 | [diff] [blame] | 387 | static int at803x_disable_tx_delay(struct phy_device *phydev) |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 388 | { |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 389 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, |
Vinod Koul | cd28d1d | 2019-01-21 14:43:17 +0530 | [diff] [blame] | 390 | AT803X_DEBUG_TX_CLK_DLY_EN, 0); |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 393 | /* save relevant PHY registers to private copy */ |
| 394 | static void at803x_context_save(struct phy_device *phydev, |
| 395 | struct at803x_context *context) |
| 396 | { |
| 397 | context->bmcr = phy_read(phydev, MII_BMCR); |
| 398 | context->advertise = phy_read(phydev, MII_ADVERTISE); |
| 399 | context->control1000 = phy_read(phydev, MII_CTRL1000); |
| 400 | context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE); |
| 401 | context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED); |
| 402 | context->led_control = phy_read(phydev, AT803X_LED_CONTROL); |
| 403 | } |
| 404 | |
| 405 | /* restore relevant PHY registers from private copy */ |
| 406 | static void at803x_context_restore(struct phy_device *phydev, |
| 407 | const struct at803x_context *context) |
| 408 | { |
| 409 | phy_write(phydev, MII_BMCR, context->bmcr); |
| 410 | phy_write(phydev, MII_ADVERTISE, context->advertise); |
| 411 | phy_write(phydev, MII_CTRL1000, context->control1000); |
| 412 | phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable); |
| 413 | phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed); |
| 414 | phy_write(phydev, AT803X_LED_CONTROL, context->led_control); |
| 415 | } |
| 416 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 417 | static int at803x_set_wol(struct phy_device *phydev, |
| 418 | struct ethtool_wolinfo *wol) |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 419 | { |
| 420 | struct net_device *ndev = phydev->attached_dev; |
| 421 | const u8 *mac; |
Luo Jie | 7beecaf | 2021-10-24 16:27:27 +0800 | [diff] [blame] | 422 | int ret, irq_enabled; |
Luo Jie | c0f0b56 | 2021-10-24 16:27:25 +0800 | [diff] [blame] | 423 | unsigned int i; |
Colin Ian King | edcb501 | 2022-01-09 23:17:16 +0000 | [diff] [blame] | 424 | static const unsigned int offsets[] = { |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 425 | AT803X_LOC_MAC_ADDR_32_47_OFFSET, |
| 426 | AT803X_LOC_MAC_ADDR_16_31_OFFSET, |
| 427 | AT803X_LOC_MAC_ADDR_0_15_OFFSET, |
| 428 | }; |
| 429 | |
| 430 | if (!ndev) |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 431 | return -ENODEV; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 432 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 433 | if (wol->wolopts & WAKE_MAGIC) { |
| 434 | mac = (const u8 *) ndev->dev_addr; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 435 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 436 | if (!is_valid_ether_addr(mac)) |
Dan Murphy | fc75568 | 2017-10-10 12:42:56 -0500 | [diff] [blame] | 437 | return -EINVAL; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 438 | |
Carlo Caione | 0e02139 | 2019-01-25 12:35:10 +0000 | [diff] [blame] | 439 | for (i = 0; i < 3; i++) |
Luo Jie | c0f0b56 | 2021-10-24 16:27:25 +0800 | [diff] [blame] | 440 | phy_write_mmd(phydev, MDIO_MMD_PCS, offsets[i], |
Carlo Caione | 0e02139 | 2019-01-25 12:35:10 +0000 | [diff] [blame] | 441 | mac[(i * 2) + 1] | (mac[(i * 2)] << 8)); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 442 | |
Luo Jie | 7beecaf | 2021-10-24 16:27:27 +0800 | [diff] [blame] | 443 | /* Enable WOL function */ |
| 444 | ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL, |
| 445 | 0, AT803X_WOL_EN); |
| 446 | if (ret) |
| 447 | return ret; |
| 448 | /* Enable WOL interrupt */ |
Luo Jie | 2d4284e | 2021-10-24 16:27:26 +0800 | [diff] [blame] | 449 | ret = phy_modify(phydev, AT803X_INTR_ENABLE, 0, AT803X_INTR_ENABLE_WOL); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 450 | if (ret) |
| 451 | return ret; |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 452 | } else { |
Luo Jie | 7beecaf | 2021-10-24 16:27:27 +0800 | [diff] [blame] | 453 | /* Disable WoL function */ |
| 454 | ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL, |
| 455 | AT803X_WOL_EN, 0); |
| 456 | if (ret) |
| 457 | return ret; |
| 458 | /* Disable WOL interrupt */ |
Luo Jie | 2d4284e | 2021-10-24 16:27:26 +0800 | [diff] [blame] | 459 | ret = phy_modify(phydev, AT803X_INTR_ENABLE, AT803X_INTR_ENABLE_WOL, 0); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 460 | if (ret) |
| 461 | return ret; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 462 | } |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 463 | |
Luo Jie | 7beecaf | 2021-10-24 16:27:27 +0800 | [diff] [blame] | 464 | /* Clear WOL status */ |
| 465 | ret = phy_read(phydev, AT803X_INTR_STATUS); |
| 466 | if (ret < 0) |
| 467 | return ret; |
| 468 | |
| 469 | /* Check if there are other interrupts except for WOL triggered when PHY is |
| 470 | * in interrupt mode, only the interrupts enabled by AT803X_INTR_ENABLE can |
| 471 | * be passed up to the interrupt PIN. |
| 472 | */ |
| 473 | irq_enabled = phy_read(phydev, AT803X_INTR_ENABLE); |
| 474 | if (irq_enabled < 0) |
| 475 | return irq_enabled; |
| 476 | |
| 477 | irq_enabled &= ~AT803X_INTR_ENABLE_WOL; |
| 478 | if (ret & irq_enabled && !phy_polling_mode(phydev)) |
| 479 | phy_trigger_machine(phydev); |
| 480 | |
| 481 | return 0; |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void at803x_get_wol(struct phy_device *phydev, |
| 485 | struct ethtool_wolinfo *wol) |
| 486 | { |
Jiapeng Chong | 911e3a4 | 2021-10-27 16:59:51 +0800 | [diff] [blame] | 487 | int value; |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 488 | |
| 489 | wol->supported = WAKE_MAGIC; |
| 490 | wol->wolopts = 0; |
| 491 | |
Luo Jie | 7beecaf | 2021-10-24 16:27:27 +0800 | [diff] [blame] | 492 | value = phy_read_mmd(phydev, MDIO_MMD_PCS, AT803X_PHY_MMD3_WOL_CTRL); |
| 493 | if (value < 0) |
| 494 | return; |
| 495 | |
| 496 | if (value & AT803X_WOL_EN) |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 497 | wol->wolopts |= WAKE_MAGIC; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 500 | static int at803x_get_sset_count(struct phy_device *phydev) |
| 501 | { |
| 502 | return ARRAY_SIZE(at803x_hw_stats); |
| 503 | } |
| 504 | |
| 505 | static void at803x_get_strings(struct phy_device *phydev, u8 *data) |
| 506 | { |
| 507 | int i; |
| 508 | |
| 509 | for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) { |
| 510 | strscpy(data + i * ETH_GSTRING_LEN, |
| 511 | at803x_hw_stats[i].string, ETH_GSTRING_LEN); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | static u64 at803x_get_stat(struct phy_device *phydev, int i) |
| 516 | { |
| 517 | struct at803x_hw_stat stat = at803x_hw_stats[i]; |
| 518 | struct at803x_priv *priv = phydev->priv; |
| 519 | int val; |
| 520 | u64 ret; |
| 521 | |
| 522 | if (stat.access_type == MMD) |
| 523 | val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg); |
| 524 | else |
| 525 | val = phy_read(phydev, stat.reg); |
| 526 | |
| 527 | if (val < 0) { |
| 528 | ret = U64_MAX; |
| 529 | } else { |
| 530 | val = val & stat.mask; |
| 531 | priv->stats[i] += val; |
| 532 | ret = priv->stats[i]; |
| 533 | } |
| 534 | |
| 535 | return ret; |
| 536 | } |
| 537 | |
| 538 | static void at803x_get_stats(struct phy_device *phydev, |
| 539 | struct ethtool_stats *stats, u64 *data) |
| 540 | { |
| 541 | int i; |
| 542 | |
| 543 | for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) |
| 544 | data[i] = at803x_get_stat(phydev, i); |
| 545 | } |
| 546 | |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 547 | static int at803x_suspend(struct phy_device *phydev) |
| 548 | { |
| 549 | int value; |
| 550 | int wol_enabled; |
| 551 | |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 552 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 553 | wol_enabled = value & AT803X_INTR_ENABLE_WOL; |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 554 | |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 555 | if (wol_enabled) |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 556 | value = BMCR_ISOLATE; |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 557 | else |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 558 | value = BMCR_PDOWN; |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 559 | |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 560 | phy_modify(phydev, MII_BMCR, 0, value); |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | static int at803x_resume(struct phy_device *phydev) |
| 566 | { |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 567 | return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0); |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 568 | } |
| 569 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 570 | static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev, |
| 571 | unsigned int selector) |
| 572 | { |
| 573 | struct phy_device *phydev = rdev_get_drvdata(rdev); |
| 574 | |
| 575 | if (selector) |
| 576 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, |
| 577 | 0, AT803X_DEBUG_RGMII_1V8); |
| 578 | else |
| 579 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, |
| 580 | AT803X_DEBUG_RGMII_1V8, 0); |
| 581 | } |
| 582 | |
| 583 | static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev) |
| 584 | { |
| 585 | struct phy_device *phydev = rdev_get_drvdata(rdev); |
| 586 | int val; |
| 587 | |
| 588 | val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F); |
| 589 | if (val < 0) |
| 590 | return val; |
| 591 | |
| 592 | return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0; |
| 593 | } |
| 594 | |
Rikard Falkeborn | 3faaf53 | 2020-08-27 00:56:06 +0200 | [diff] [blame] | 595 | static const struct regulator_ops vddio_regulator_ops = { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 596 | .list_voltage = regulator_list_voltage_table, |
| 597 | .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel, |
| 598 | .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel, |
| 599 | }; |
| 600 | |
| 601 | static const unsigned int vddio_voltage_table[] = { |
| 602 | 1500000, |
| 603 | 1800000, |
| 604 | }; |
| 605 | |
| 606 | static const struct regulator_desc vddio_desc = { |
| 607 | .name = "vddio", |
| 608 | .of_match = of_match_ptr("vddio-regulator"), |
| 609 | .n_voltages = ARRAY_SIZE(vddio_voltage_table), |
| 610 | .volt_table = vddio_voltage_table, |
| 611 | .ops = &vddio_regulator_ops, |
| 612 | .type = REGULATOR_VOLTAGE, |
| 613 | .owner = THIS_MODULE, |
| 614 | }; |
| 615 | |
Rikard Falkeborn | 3faaf53 | 2020-08-27 00:56:06 +0200 | [diff] [blame] | 616 | static const struct regulator_ops vddh_regulator_ops = { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 617 | }; |
| 618 | |
| 619 | static const struct regulator_desc vddh_desc = { |
| 620 | .name = "vddh", |
| 621 | .of_match = of_match_ptr("vddh-regulator"), |
| 622 | .n_voltages = 1, |
| 623 | .fixed_uV = 2500000, |
| 624 | .ops = &vddh_regulator_ops, |
| 625 | .type = REGULATOR_VOLTAGE, |
| 626 | .owner = THIS_MODULE, |
| 627 | }; |
| 628 | |
| 629 | static int at8031_register_regulators(struct phy_device *phydev) |
| 630 | { |
| 631 | struct at803x_priv *priv = phydev->priv; |
| 632 | struct device *dev = &phydev->mdio.dev; |
| 633 | struct regulator_config config = { }; |
| 634 | |
| 635 | config.dev = dev; |
| 636 | config.driver_data = phydev; |
| 637 | |
| 638 | priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config); |
| 639 | if (IS_ERR(priv->vddio_rdev)) { |
| 640 | phydev_err(phydev, "failed to register VDDIO regulator\n"); |
| 641 | return PTR_ERR(priv->vddio_rdev); |
| 642 | } |
| 643 | |
| 644 | priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config); |
| 645 | if (IS_ERR(priv->vddh_rdev)) { |
| 646 | phydev_err(phydev, "failed to register VDDH regulator\n"); |
| 647 | return PTR_ERR(priv->vddh_rdev); |
| 648 | } |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 653 | static int at803x_parse_dt(struct phy_device *phydev) |
| 654 | { |
| 655 | struct device_node *node = phydev->mdio.dev.of_node; |
| 656 | struct at803x_priv *priv = phydev->priv; |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 657 | u32 freq, strength, tw; |
Andrew Lunn | 3f2edd3 | 2020-07-07 03:49:33 +0200 | [diff] [blame] | 658 | unsigned int sel; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 659 | int ret; |
| 660 | |
| 661 | if (!IS_ENABLED(CONFIG_OF_MDIO)) |
| 662 | return 0; |
| 663 | |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 664 | if (of_property_read_bool(node, "qca,disable-smarteee")) |
| 665 | priv->flags |= AT803X_DISABLE_SMARTEEE; |
| 666 | |
| 667 | if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) { |
| 668 | if (!tw || tw > 255) { |
| 669 | phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n"); |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | priv->smarteee_lpi_tw_1g = tw; |
| 673 | } |
| 674 | |
| 675 | if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) { |
| 676 | if (!tw || tw > 255) { |
| 677 | phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n"); |
| 678 | return -EINVAL; |
| 679 | } |
| 680 | priv->smarteee_lpi_tw_100m = tw; |
| 681 | } |
| 682 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 683 | ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq); |
| 684 | if (!ret) { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 685 | switch (freq) { |
| 686 | case 25000000: |
| 687 | sel = AT803X_CLK_OUT_25MHZ_XTAL; |
| 688 | break; |
| 689 | case 50000000: |
| 690 | sel = AT803X_CLK_OUT_50MHZ_PLL; |
| 691 | break; |
| 692 | case 62500000: |
| 693 | sel = AT803X_CLK_OUT_62_5MHZ_PLL; |
| 694 | break; |
| 695 | case 125000000: |
| 696 | sel = AT803X_CLK_OUT_125MHZ_PLL; |
| 697 | break; |
| 698 | default: |
| 699 | phydev_err(phydev, "invalid qca,clk-out-frequency\n"); |
| 700 | return -EINVAL; |
| 701 | } |
| 702 | |
Andrew Lunn | 3f2edd3 | 2020-07-07 03:49:33 +0200 | [diff] [blame] | 703 | priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel); |
| 704 | priv->clk_25m_mask |= AT803X_CLK_OUT_MASK; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 705 | |
| 706 | /* Fixup for the AR8030/AR8035. This chip has another mask and |
| 707 | * doesn't support the DSP reference. Eg. the lowest bit of the |
| 708 | * mask. The upper two bits select the same frequencies. Mask |
| 709 | * the lowest bit here. |
| 710 | * |
| 711 | * Warning: |
| 712 | * There was no datasheet for the AR8030 available so this is |
| 713 | * just a guess. But the AR8035 is listed as pin compatible |
| 714 | * to the AR8030 so there might be a good chance it works on |
| 715 | * the AR8030 too. |
| 716 | */ |
Russell King | 8887ca5 | 2021-07-20 14:33:49 +0100 | [diff] [blame] | 717 | if (phydev->drv->phy_id == ATH8030_PHY_ID || |
| 718 | phydev->drv->phy_id == ATH8035_PHY_ID) { |
Oleksij Rempel | b1f4c20 | 2020-04-01 11:57:32 +0200 | [diff] [blame] | 719 | priv->clk_25m_reg &= AT8035_CLK_OUT_MASK; |
| 720 | priv->clk_25m_mask &= AT8035_CLK_OUT_MASK; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
| 724 | ret = of_property_read_u32(node, "qca,clk-out-strength", &strength); |
| 725 | if (!ret) { |
| 726 | priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK; |
| 727 | switch (strength) { |
| 728 | case AR803X_STRENGTH_FULL: |
| 729 | priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL; |
| 730 | break; |
| 731 | case AR803X_STRENGTH_HALF: |
| 732 | priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF; |
| 733 | break; |
| 734 | case AR803X_STRENGTH_QUARTER: |
| 735 | priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER; |
| 736 | break; |
| 737 | default: |
| 738 | phydev_err(phydev, "invalid qca,clk-out-strength\n"); |
| 739 | return -EINVAL; |
| 740 | } |
| 741 | } |
| 742 | |
Michael Walle | 428061f | 2019-11-06 23:36:15 +0100 | [diff] [blame] | 743 | /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping |
| 744 | * options. |
| 745 | */ |
Russell King | 8887ca5 | 2021-07-20 14:33:49 +0100 | [diff] [blame] | 746 | if (phydev->drv->phy_id == ATH8031_PHY_ID) { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 747 | if (of_property_read_bool(node, "qca,keep-pll-enabled")) |
| 748 | priv->flags |= AT803X_KEEP_PLL_ENABLED; |
| 749 | |
| 750 | ret = at8031_register_regulators(phydev); |
| 751 | if (ret < 0) |
| 752 | return ret; |
| 753 | |
| 754 | priv->vddio = devm_regulator_get_optional(&phydev->mdio.dev, |
| 755 | "vddio"); |
| 756 | if (IS_ERR(priv->vddio)) { |
| 757 | phydev_err(phydev, "failed to get VDDIO regulator\n"); |
| 758 | return PTR_ERR(priv->vddio); |
| 759 | } |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static int at803x_probe(struct phy_device *phydev) |
| 766 | { |
| 767 | struct device *dev = &phydev->mdio.dev; |
| 768 | struct at803x_priv *priv; |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 769 | int ret; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 770 | |
| 771 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 772 | if (!priv) |
| 773 | return -ENOMEM; |
| 774 | |
| 775 | phydev->priv = priv; |
| 776 | |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 777 | ret = at803x_parse_dt(phydev); |
| 778 | if (ret) |
| 779 | return ret; |
| 780 | |
Michael Walle | 8f7e876 | 2021-04-20 12:29:29 +0200 | [diff] [blame] | 781 | if (priv->vddio) { |
| 782 | ret = regulator_enable(priv->vddio); |
| 783 | if (ret < 0) |
| 784 | return ret; |
| 785 | } |
| 786 | |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 787 | /* Some bootloaders leave the fiber page selected. |
| 788 | * Switch to the copper page, as otherwise we read |
| 789 | * the PHY capabilities from the fiber side. |
| 790 | */ |
Russell King | 8887ca5 | 2021-07-20 14:33:49 +0100 | [diff] [blame] | 791 | if (phydev->drv->phy_id == ATH8031_PHY_ID) { |
Michael Walle | 8f7e876 | 2021-04-20 12:29:29 +0200 | [diff] [blame] | 792 | phy_lock_mdio_bus(phydev); |
| 793 | ret = at803x_write_page(phydev, AT803X_PAGE_COPPER); |
| 794 | phy_unlock_mdio_bus(phydev); |
| 795 | if (ret) |
| 796 | goto err; |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 797 | } |
| 798 | |
Michael Walle | 8f7e876 | 2021-04-20 12:29:29 +0200 | [diff] [blame] | 799 | return 0; |
| 800 | |
| 801 | err: |
| 802 | if (priv->vddio) |
| 803 | regulator_disable(priv->vddio); |
| 804 | |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 805 | return ret; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 806 | } |
| 807 | |
Michael Walle | 2318ca8 | 2020-01-30 18:54:02 +0100 | [diff] [blame] | 808 | static void at803x_remove(struct phy_device *phydev) |
| 809 | { |
| 810 | struct at803x_priv *priv = phydev->priv; |
| 811 | |
| 812 | if (priv->vddio) |
| 813 | regulator_disable(priv->vddio); |
| 814 | } |
| 815 | |
David Bauer | b856150 | 2021-06-27 12:16:07 +0200 | [diff] [blame] | 816 | static int at803x_get_features(struct phy_device *phydev) |
| 817 | { |
| 818 | int err; |
| 819 | |
| 820 | err = genphy_read_abilities(phydev); |
| 821 | if (err) |
| 822 | return err; |
| 823 | |
Luo Jie | 765c22a | 2021-10-24 16:27:31 +0800 | [diff] [blame] | 824 | if (phydev->drv->phy_id == QCA8081_PHY_ID) { |
| 825 | err = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_NG_EXTABLE); |
| 826 | if (err < 0) |
| 827 | return err; |
| 828 | |
| 829 | linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->supported, |
| 830 | err & MDIO_PMA_NG_EXTABLE_2_5GBT); |
| 831 | } |
| 832 | |
Vladimir Oltean | f5621a0 | 2021-07-20 20:24:33 +0300 | [diff] [blame] | 833 | if (phydev->drv->phy_id != ATH8031_PHY_ID) |
David Bauer | b856150 | 2021-06-27 12:16:07 +0200 | [diff] [blame] | 834 | return 0; |
| 835 | |
| 836 | /* AR8031/AR8033 have different status registers |
| 837 | * for copper and fiber operation. However, the |
| 838 | * extended status register is the same for both |
| 839 | * operation modes. |
| 840 | * |
| 841 | * As a result of that, ESTATUS_1000_XFULL is set |
| 842 | * to 1 even when operating in copper TP mode. |
| 843 | * |
| 844 | * Remove this mode from the supported link modes, |
| 845 | * as this driver currently only supports copper |
| 846 | * operation. |
| 847 | */ |
| 848 | linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, |
| 849 | phydev->supported); |
| 850 | return 0; |
| 851 | } |
| 852 | |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 853 | static int at803x_smarteee_config(struct phy_device *phydev) |
| 854 | { |
| 855 | struct at803x_priv *priv = phydev->priv; |
| 856 | u16 mask = 0, val = 0; |
| 857 | int ret; |
| 858 | |
| 859 | if (priv->flags & AT803X_DISABLE_SMARTEEE) |
| 860 | return phy_modify_mmd(phydev, MDIO_MMD_PCS, |
| 861 | AT803X_MMD3_SMARTEEE_CTL3, |
| 862 | AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0); |
| 863 | |
| 864 | if (priv->smarteee_lpi_tw_1g) { |
| 865 | mask |= 0xff00; |
| 866 | val |= priv->smarteee_lpi_tw_1g << 8; |
| 867 | } |
| 868 | if (priv->smarteee_lpi_tw_100m) { |
| 869 | mask |= 0x00ff; |
| 870 | val |= priv->smarteee_lpi_tw_100m; |
| 871 | } |
| 872 | if (!mask) |
| 873 | return 0; |
| 874 | |
| 875 | ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1, |
| 876 | mask, val); |
| 877 | if (ret) |
| 878 | return ret; |
| 879 | |
| 880 | return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3, |
| 881 | AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, |
| 882 | AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); |
| 883 | } |
| 884 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 885 | static int at803x_clk_out_config(struct phy_device *phydev) |
| 886 | { |
| 887 | struct at803x_priv *priv = phydev->priv; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 888 | |
| 889 | if (!priv->clk_25m_mask) |
| 890 | return 0; |
| 891 | |
Russell King | a45c1c1 | 2021-01-10 14:54:36 +0000 | [diff] [blame] | 892 | return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M, |
| 893 | priv->clk_25m_mask, priv->clk_25m_reg); |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | static int at8031_pll_config(struct phy_device *phydev) |
| 897 | { |
| 898 | struct at803x_priv *priv = phydev->priv; |
| 899 | |
| 900 | /* The default after hardware reset is PLL OFF. After a soft reset, the |
| 901 | * values are retained. |
| 902 | */ |
| 903 | if (priv->flags & AT803X_KEEP_PLL_ENABLED) |
| 904 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, |
| 905 | 0, AT803X_DEBUG_PLL_ON); |
| 906 | else |
| 907 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, |
| 908 | AT803X_DEBUG_PLL_ON, 0); |
| 909 | } |
| 910 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 911 | static int at803x_config_init(struct phy_device *phydev) |
| 912 | { |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 913 | int ret; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 914 | |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 915 | /* The RX and TX delay default is: |
| 916 | * after HW reset: RX delay enabled and TX delay disabled |
| 917 | * after SW reset: RX delay enabled, while TX delay retains the |
| 918 | * value before reset. |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 919 | */ |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 920 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
André Draszik | bb0ce4c | 2019-08-09 12:20:25 +0100 | [diff] [blame] | 921 | phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 922 | ret = at803x_enable_rx_delay(phydev); |
André Draszik | bb0ce4c | 2019-08-09 12:20:25 +0100 | [diff] [blame] | 923 | else |
| 924 | ret = at803x_disable_rx_delay(phydev); |
| 925 | if (ret < 0) |
| 926 | return ret; |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 927 | |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 928 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
André Draszik | bb0ce4c | 2019-08-09 12:20:25 +0100 | [diff] [blame] | 929 | phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 930 | ret = at803x_enable_tx_delay(phydev); |
André Draszik | bb0ce4c | 2019-08-09 12:20:25 +0100 | [diff] [blame] | 931 | else |
| 932 | ret = at803x_disable_tx_delay(phydev); |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 933 | if (ret < 0) |
| 934 | return ret; |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 935 | |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 936 | ret = at803x_smarteee_config(phydev); |
| 937 | if (ret < 0) |
| 938 | return ret; |
| 939 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 940 | ret = at803x_clk_out_config(phydev); |
| 941 | if (ret < 0) |
| 942 | return ret; |
| 943 | |
Russell King | 8887ca5 | 2021-07-20 14:33:49 +0100 | [diff] [blame] | 944 | if (phydev->drv->phy_id == ATH8031_PHY_ID) { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 945 | ret = at8031_pll_config(phydev); |
| 946 | if (ret < 0) |
| 947 | return ret; |
| 948 | } |
| 949 | |
Russell King | 3c51fa5 | 2021-01-12 22:59:43 +0000 | [diff] [blame] | 950 | /* Ar803x extended next page bit is enabled by default. Cisco |
| 951 | * multigig switches read this bit and attempt to negotiate 10Gbps |
| 952 | * rates even if the next page bit is disabled. This is incorrect |
| 953 | * behaviour but we still need to accommodate it. XNP is only needed |
| 954 | * for 10Gbps support, so disable XNP. |
| 955 | */ |
| 956 | return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 959 | static int at803x_ack_interrupt(struct phy_device *phydev) |
| 960 | { |
| 961 | int err; |
| 962 | |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 963 | err = phy_read(phydev, AT803X_INTR_STATUS); |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 964 | |
| 965 | return (err < 0) ? err : 0; |
| 966 | } |
| 967 | |
| 968 | static int at803x_config_intr(struct phy_device *phydev) |
| 969 | { |
| 970 | int err; |
| 971 | int value; |
| 972 | |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 973 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 974 | |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 975 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { |
Ioana Ciornei | a341788 | 2020-11-01 14:51:00 +0200 | [diff] [blame] | 976 | /* Clear any pending interrupts */ |
| 977 | err = at803x_ack_interrupt(phydev); |
| 978 | if (err) |
| 979 | return err; |
| 980 | |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 981 | value |= AT803X_INTR_ENABLE_AUTONEG_ERR; |
| 982 | value |= AT803X_INTR_ENABLE_SPEED_CHANGED; |
| 983 | value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED; |
| 984 | value |= AT803X_INTR_ENABLE_LINK_FAIL; |
| 985 | value |= AT803X_INTR_ENABLE_LINK_SUCCESS; |
| 986 | |
| 987 | err = phy_write(phydev, AT803X_INTR_ENABLE, value); |
Ioana Ciornei | a341788 | 2020-11-01 14:51:00 +0200 | [diff] [blame] | 988 | } else { |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 989 | err = phy_write(phydev, AT803X_INTR_ENABLE, 0); |
Ioana Ciornei | a341788 | 2020-11-01 14:51:00 +0200 | [diff] [blame] | 990 | if (err) |
| 991 | return err; |
| 992 | |
| 993 | /* Clear any pending interrupts */ |
| 994 | err = at803x_ack_interrupt(phydev); |
| 995 | } |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 996 | |
| 997 | return err; |
| 998 | } |
| 999 | |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1000 | static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev) |
| 1001 | { |
| 1002 | int irq_status, int_enabled; |
| 1003 | |
| 1004 | irq_status = phy_read(phydev, AT803X_INTR_STATUS); |
| 1005 | if (irq_status < 0) { |
| 1006 | phy_error(phydev); |
| 1007 | return IRQ_NONE; |
| 1008 | } |
| 1009 | |
| 1010 | /* Read the current enabled interrupts */ |
| 1011 | int_enabled = phy_read(phydev, AT803X_INTR_ENABLE); |
| 1012 | if (int_enabled < 0) { |
| 1013 | phy_error(phydev); |
| 1014 | return IRQ_NONE; |
| 1015 | } |
| 1016 | |
| 1017 | /* See if this was one of our enabled interrupts */ |
| 1018 | if (!(irq_status & int_enabled)) |
| 1019 | return IRQ_NONE; |
| 1020 | |
| 1021 | phy_trigger_machine(phydev); |
| 1022 | |
| 1023 | return IRQ_HANDLED; |
| 1024 | } |
| 1025 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1026 | static void at803x_link_change_notify(struct phy_device *phydev) |
| 1027 | { |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1028 | /* |
| 1029 | * Conduct a hardware reset for AT8030 every time a link loss is |
| 1030 | * signalled. This is necessary to circumvent a hardware bug that |
| 1031 | * occurs when the cable is unplugged while TX packets are pending |
| 1032 | * in the FIFO. In such cases, the FIFO enters an error mode it |
| 1033 | * cannot recover from by software. |
| 1034 | */ |
David Bauer | 6110ed2 | 2019-04-17 23:59:22 +0200 | [diff] [blame] | 1035 | if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) { |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 1036 | struct at803x_context context; |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1037 | |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 1038 | at803x_context_save(phydev, &context); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1039 | |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 1040 | phy_device_reset(phydev, 1); |
| 1041 | msleep(1); |
| 1042 | phy_device_reset(phydev, 0); |
| 1043 | msleep(1); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1044 | |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 1045 | at803x_context_restore(phydev, &context); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1046 | |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 1047 | phydev_dbg(phydev, "%s(): phy was reset\n", __func__); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 1051 | static int at803x_read_specific_status(struct phy_device *phydev) |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1052 | { |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 1053 | int ss; |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1054 | |
| 1055 | /* Read the AT8035 PHY-Specific Status register, which indicates the |
| 1056 | * speed and duplex that the PHY is actually using, irrespective of |
| 1057 | * whether we are in autoneg mode or not. |
| 1058 | */ |
| 1059 | ss = phy_read(phydev, AT803X_SPECIFIC_STATUS); |
| 1060 | if (ss < 0) |
| 1061 | return ss; |
| 1062 | |
| 1063 | if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) { |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 1064 | int sfc, speed; |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1065 | |
| 1066 | sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL); |
| 1067 | if (sfc < 0) |
| 1068 | return sfc; |
| 1069 | |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 1070 | /* qca8081 takes the different bits for speed value from at803x */ |
| 1071 | if (phydev->drv->phy_id == QCA8081_PHY_ID) |
| 1072 | speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss); |
| 1073 | else |
| 1074 | speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss); |
| 1075 | |
| 1076 | switch (speed) { |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1077 | case AT803X_SS_SPEED_10: |
| 1078 | phydev->speed = SPEED_10; |
| 1079 | break; |
| 1080 | case AT803X_SS_SPEED_100: |
| 1081 | phydev->speed = SPEED_100; |
| 1082 | break; |
| 1083 | case AT803X_SS_SPEED_1000: |
| 1084 | phydev->speed = SPEED_1000; |
| 1085 | break; |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 1086 | case QCA808X_SS_SPEED_2500: |
| 1087 | phydev->speed = SPEED_2500; |
| 1088 | break; |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1089 | } |
| 1090 | if (ss & AT803X_SS_DUPLEX) |
| 1091 | phydev->duplex = DUPLEX_FULL; |
| 1092 | else |
| 1093 | phydev->duplex = DUPLEX_HALF; |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1094 | |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1095 | if (ss & AT803X_SS_MDIX) |
| 1096 | phydev->mdix = ETH_TP_MDI_X; |
| 1097 | else |
| 1098 | phydev->mdix = ETH_TP_MDI; |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1099 | |
| 1100 | switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) { |
| 1101 | case AT803X_SFC_MANUAL_MDI: |
| 1102 | phydev->mdix_ctrl = ETH_TP_MDI; |
| 1103 | break; |
| 1104 | case AT803X_SFC_MANUAL_MDIX: |
| 1105 | phydev->mdix_ctrl = ETH_TP_MDI_X; |
| 1106 | break; |
| 1107 | case AT803X_SFC_AUTOMATIC_CROSSOVER: |
| 1108 | phydev->mdix_ctrl = ETH_TP_MDI_AUTO; |
| 1109 | break; |
| 1110 | } |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1111 | } |
| 1112 | |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 1113 | return 0; |
| 1114 | } |
| 1115 | |
| 1116 | static int at803x_read_status(struct phy_device *phydev) |
| 1117 | { |
| 1118 | int err, old_link = phydev->link; |
| 1119 | |
| 1120 | /* Update the link, but return if there was an error */ |
| 1121 | err = genphy_update_link(phydev); |
| 1122 | if (err) |
| 1123 | return err; |
| 1124 | |
| 1125 | /* why bother the PHY if nothing can have changed */ |
| 1126 | if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) |
| 1127 | return 0; |
| 1128 | |
| 1129 | phydev->speed = SPEED_UNKNOWN; |
| 1130 | phydev->duplex = DUPLEX_UNKNOWN; |
| 1131 | phydev->pause = 0; |
| 1132 | phydev->asym_pause = 0; |
| 1133 | |
| 1134 | err = genphy_read_lpa(phydev); |
| 1135 | if (err < 0) |
| 1136 | return err; |
| 1137 | |
| 1138 | err = at803x_read_specific_status(phydev); |
| 1139 | if (err < 0) |
| 1140 | return err; |
| 1141 | |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1142 | if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) |
| 1143 | phy_resolve_aneg_pause(phydev); |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1148 | static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl) |
| 1149 | { |
| 1150 | u16 val; |
| 1151 | |
| 1152 | switch (ctrl) { |
| 1153 | case ETH_TP_MDI: |
| 1154 | val = AT803X_SFC_MANUAL_MDI; |
| 1155 | break; |
| 1156 | case ETH_TP_MDI_X: |
| 1157 | val = AT803X_SFC_MANUAL_MDIX; |
| 1158 | break; |
| 1159 | case ETH_TP_MDI_AUTO: |
| 1160 | val = AT803X_SFC_AUTOMATIC_CROSSOVER; |
| 1161 | break; |
| 1162 | default: |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL, |
| 1167 | AT803X_SFC_MDI_CROSSOVER_MODE_M, |
| 1168 | FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val)); |
| 1169 | } |
| 1170 | |
| 1171 | static int at803x_config_aneg(struct phy_device *phydev) |
| 1172 | { |
| 1173 | int ret; |
| 1174 | |
| 1175 | ret = at803x_config_mdix(phydev, phydev->mdix_ctrl); |
| 1176 | if (ret < 0) |
| 1177 | return ret; |
| 1178 | |
| 1179 | /* Changes of the midx bits are disruptive to the normal operation; |
| 1180 | * therefore any changes to these registers must be followed by a |
| 1181 | * software reset to take effect. |
| 1182 | */ |
| 1183 | if (ret == 1) { |
| 1184 | ret = genphy_soft_reset(phydev); |
| 1185 | if (ret < 0) |
| 1186 | return ret; |
| 1187 | } |
| 1188 | |
Luo Jie | f884d44 | 2021-10-24 16:27:32 +0800 | [diff] [blame] | 1189 | /* Do not restart auto-negotiation by setting ret to 0 defautly, |
| 1190 | * when calling __genphy_config_aneg later. |
| 1191 | */ |
| 1192 | ret = 0; |
| 1193 | |
| 1194 | if (phydev->drv->phy_id == QCA8081_PHY_ID) { |
| 1195 | int phy_ctrl = 0; |
| 1196 | |
| 1197 | /* The reg MII_BMCR also needs to be configured for force mode, the |
| 1198 | * genphy_config_aneg is also needed. |
| 1199 | */ |
| 1200 | if (phydev->autoneg == AUTONEG_DISABLE) |
| 1201 | genphy_c45_pma_setup_forced(phydev); |
| 1202 | |
| 1203 | if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising)) |
| 1204 | phy_ctrl = MDIO_AN_10GBT_CTRL_ADV2_5G; |
| 1205 | |
| 1206 | ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL, |
| 1207 | MDIO_AN_10GBT_CTRL_ADV2_5G, phy_ctrl); |
| 1208 | if (ret < 0) |
| 1209 | return ret; |
| 1210 | } |
| 1211 | |
| 1212 | return __genphy_config_aneg(phydev, ret); |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1213 | } |
| 1214 | |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1215 | static int at803x_get_downshift(struct phy_device *phydev, u8 *d) |
| 1216 | { |
| 1217 | int val; |
| 1218 | |
| 1219 | val = phy_read(phydev, AT803X_SMART_SPEED); |
| 1220 | if (val < 0) |
| 1221 | return val; |
| 1222 | |
| 1223 | if (val & AT803X_SMART_SPEED_ENABLE) |
| 1224 | *d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2; |
| 1225 | else |
| 1226 | *d = DOWNSHIFT_DEV_DISABLE; |
| 1227 | |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | static int at803x_set_downshift(struct phy_device *phydev, u8 cnt) |
| 1232 | { |
| 1233 | u16 mask, set; |
| 1234 | int ret; |
| 1235 | |
| 1236 | switch (cnt) { |
| 1237 | case DOWNSHIFT_DEV_DEFAULT_COUNT: |
| 1238 | cnt = AT803X_DEFAULT_DOWNSHIFT; |
| 1239 | fallthrough; |
| 1240 | case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT: |
| 1241 | set = AT803X_SMART_SPEED_ENABLE | |
| 1242 | AT803X_SMART_SPEED_BYPASS_TIMER | |
| 1243 | FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2); |
| 1244 | mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK; |
| 1245 | break; |
| 1246 | case DOWNSHIFT_DEV_DISABLE: |
| 1247 | set = 0; |
| 1248 | mask = AT803X_SMART_SPEED_ENABLE | |
| 1249 | AT803X_SMART_SPEED_BYPASS_TIMER; |
| 1250 | break; |
| 1251 | default: |
| 1252 | return -EINVAL; |
| 1253 | } |
| 1254 | |
| 1255 | ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set); |
| 1256 | |
| 1257 | /* After changing the smart speed settings, we need to perform a |
| 1258 | * software reset, use phy_init_hw() to make sure we set the |
| 1259 | * reapply any values which might got lost during software reset. |
| 1260 | */ |
| 1261 | if (ret == 1) |
| 1262 | ret = phy_init_hw(phydev); |
| 1263 | |
| 1264 | return ret; |
| 1265 | } |
| 1266 | |
| 1267 | static int at803x_get_tunable(struct phy_device *phydev, |
| 1268 | struct ethtool_tunable *tuna, void *data) |
| 1269 | { |
| 1270 | switch (tuna->id) { |
| 1271 | case ETHTOOL_PHY_DOWNSHIFT: |
| 1272 | return at803x_get_downshift(phydev, data); |
| 1273 | default: |
| 1274 | return -EOPNOTSUPP; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | static int at803x_set_tunable(struct phy_device *phydev, |
| 1279 | struct ethtool_tunable *tuna, const void *data) |
| 1280 | { |
| 1281 | switch (tuna->id) { |
| 1282 | case ETHTOOL_PHY_DOWNSHIFT: |
| 1283 | return at803x_set_downshift(phydev, *(const u8 *)data); |
| 1284 | default: |
| 1285 | return -EOPNOTSUPP; |
| 1286 | } |
| 1287 | } |
| 1288 | |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1289 | static int at803x_cable_test_result_trans(u16 status) |
| 1290 | { |
| 1291 | switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) { |
| 1292 | case AT803X_CDT_STATUS_STAT_NORMAL: |
| 1293 | return ETHTOOL_A_CABLE_RESULT_CODE_OK; |
| 1294 | case AT803X_CDT_STATUS_STAT_SHORT: |
| 1295 | return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; |
| 1296 | case AT803X_CDT_STATUS_STAT_OPEN: |
| 1297 | return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; |
| 1298 | case AT803X_CDT_STATUS_STAT_FAIL: |
| 1299 | default: |
| 1300 | return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | static bool at803x_cdt_test_failed(u16 status) |
| 1305 | { |
| 1306 | return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) == |
| 1307 | AT803X_CDT_STATUS_STAT_FAIL; |
| 1308 | } |
| 1309 | |
| 1310 | static bool at803x_cdt_fault_length_valid(u16 status) |
| 1311 | { |
| 1312 | switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) { |
| 1313 | case AT803X_CDT_STATUS_STAT_OPEN: |
| 1314 | case AT803X_CDT_STATUS_STAT_SHORT: |
| 1315 | return true; |
| 1316 | } |
| 1317 | return false; |
| 1318 | } |
| 1319 | |
| 1320 | static int at803x_cdt_fault_length(u16 status) |
| 1321 | { |
| 1322 | int dt; |
| 1323 | |
| 1324 | /* According to the datasheet the distance to the fault is |
| 1325 | * DELTA_TIME * 0.824 meters. |
| 1326 | * |
| 1327 | * The author suspect the correct formula is: |
| 1328 | * |
| 1329 | * fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2 |
| 1330 | * |
| 1331 | * where c is the speed of light, VF is the velocity factor of |
| 1332 | * the twisted pair cable, 125MHz the counter frequency and |
| 1333 | * we need to divide by 2 because the hardware will measure the |
| 1334 | * round trip time to the fault and back to the PHY. |
| 1335 | * |
| 1336 | * With a VF of 0.69 we get the factor 0.824 mentioned in the |
| 1337 | * datasheet. |
| 1338 | */ |
| 1339 | dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status); |
| 1340 | |
| 1341 | return (dt * 824) / 10; |
| 1342 | } |
| 1343 | |
| 1344 | static int at803x_cdt_start(struct phy_device *phydev, int pair) |
| 1345 | { |
| 1346 | u16 cdt; |
| 1347 | |
Luo Jie | 8c84d75 | 2021-10-24 16:27:38 +0800 | [diff] [blame] | 1348 | /* qca8081 takes the different bit 15 to enable CDT test */ |
| 1349 | if (phydev->drv->phy_id == QCA8081_PHY_ID) |
| 1350 | cdt = QCA808X_CDT_ENABLE_TEST | |
| 1351 | QCA808X_CDT_LENGTH_UNIT | |
| 1352 | QCA808X_CDT_INTER_CHECK_DIS; |
| 1353 | else |
| 1354 | cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) | |
| 1355 | AT803X_CDT_ENABLE_TEST; |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1356 | |
| 1357 | return phy_write(phydev, AT803X_CDT, cdt); |
| 1358 | } |
| 1359 | |
| 1360 | static int at803x_cdt_wait_for_completion(struct phy_device *phydev) |
| 1361 | { |
| 1362 | int val, ret; |
Luo Jie | 8c84d75 | 2021-10-24 16:27:38 +0800 | [diff] [blame] | 1363 | u16 cdt_en; |
| 1364 | |
| 1365 | if (phydev->drv->phy_id == QCA8081_PHY_ID) |
| 1366 | cdt_en = QCA808X_CDT_ENABLE_TEST; |
| 1367 | else |
| 1368 | cdt_en = AT803X_CDT_ENABLE_TEST; |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1369 | |
| 1370 | /* One test run takes about 25ms */ |
| 1371 | ret = phy_read_poll_timeout(phydev, AT803X_CDT, val, |
Luo Jie | 8c84d75 | 2021-10-24 16:27:38 +0800 | [diff] [blame] | 1372 | !(val & cdt_en), |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1373 | 30000, 100000, true); |
| 1374 | |
| 1375 | return ret < 0 ? ret : 0; |
| 1376 | } |
| 1377 | |
| 1378 | static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair) |
| 1379 | { |
| 1380 | static const int ethtool_pair[] = { |
| 1381 | ETHTOOL_A_CABLE_PAIR_A, |
| 1382 | ETHTOOL_A_CABLE_PAIR_B, |
| 1383 | ETHTOOL_A_CABLE_PAIR_C, |
| 1384 | ETHTOOL_A_CABLE_PAIR_D, |
| 1385 | }; |
| 1386 | int ret, val; |
| 1387 | |
| 1388 | ret = at803x_cdt_start(phydev, pair); |
| 1389 | if (ret) |
| 1390 | return ret; |
| 1391 | |
| 1392 | ret = at803x_cdt_wait_for_completion(phydev); |
| 1393 | if (ret) |
| 1394 | return ret; |
| 1395 | |
| 1396 | val = phy_read(phydev, AT803X_CDT_STATUS); |
| 1397 | if (val < 0) |
| 1398 | return val; |
| 1399 | |
| 1400 | if (at803x_cdt_test_failed(val)) |
| 1401 | return 0; |
| 1402 | |
| 1403 | ethnl_cable_test_result(phydev, ethtool_pair[pair], |
| 1404 | at803x_cable_test_result_trans(val)); |
| 1405 | |
| 1406 | if (at803x_cdt_fault_length_valid(val)) |
| 1407 | ethnl_cable_test_fault_length(phydev, ethtool_pair[pair], |
| 1408 | at803x_cdt_fault_length(val)); |
| 1409 | |
| 1410 | return 1; |
| 1411 | } |
| 1412 | |
| 1413 | static int at803x_cable_test_get_status(struct phy_device *phydev, |
| 1414 | bool *finished) |
| 1415 | { |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1416 | unsigned long pair_mask; |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1417 | int retries = 20; |
| 1418 | int pair, ret; |
| 1419 | |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1420 | if (phydev->phy_id == ATH9331_PHY_ID || |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame] | 1421 | phydev->phy_id == ATH8032_PHY_ID || |
| 1422 | phydev->phy_id == QCA9561_PHY_ID) |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1423 | pair_mask = 0x3; |
| 1424 | else |
| 1425 | pair_mask = 0xf; |
| 1426 | |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1427 | *finished = false; |
| 1428 | |
| 1429 | /* According to the datasheet the CDT can be performed when |
| 1430 | * there is no link partner or when the link partner is |
| 1431 | * auto-negotiating. Starting the test will restart the AN |
| 1432 | * automatically. It seems that doing this repeatedly we will |
| 1433 | * get a slot where our link partner won't disturb our |
| 1434 | * measurement. |
| 1435 | */ |
| 1436 | while (pair_mask && retries--) { |
| 1437 | for_each_set_bit(pair, &pair_mask, 4) { |
| 1438 | ret = at803x_cable_test_one_pair(phydev, pair); |
| 1439 | if (ret < 0) |
| 1440 | return ret; |
| 1441 | if (ret) |
| 1442 | clear_bit(pair, &pair_mask); |
| 1443 | } |
| 1444 | if (pair_mask) |
| 1445 | msleep(250); |
| 1446 | } |
| 1447 | |
| 1448 | *finished = true; |
| 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | static int at803x_cable_test_start(struct phy_device *phydev) |
| 1454 | { |
| 1455 | /* Enable auto-negotiation, but advertise no capabilities, no link |
| 1456 | * will be established. A restart of the auto-negotiation is not |
| 1457 | * required, because the cable test will automatically break the link. |
| 1458 | */ |
| 1459 | phy_write(phydev, MII_BMCR, BMCR_ANENABLE); |
| 1460 | phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA); |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1461 | if (phydev->phy_id != ATH9331_PHY_ID && |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame] | 1462 | phydev->phy_id != ATH8032_PHY_ID && |
| 1463 | phydev->phy_id != QCA9561_PHY_ID) |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1464 | phy_write(phydev, MII_CTRL1000, 0); |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1465 | |
| 1466 | /* we do all the (time consuming) work later */ |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1470 | static int qca83xx_config_init(struct phy_device *phydev) |
| 1471 | { |
| 1472 | u8 switch_revision; |
| 1473 | |
| 1474 | switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK; |
| 1475 | |
| 1476 | switch (switch_revision) { |
| 1477 | case 1: |
| 1478 | /* For 100M waveform */ |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 1479 | at803x_debug_reg_write(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0x02ea); |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1480 | /* Turn on Gigabit clock */ |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 1481 | at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x68a0); |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1482 | break; |
| 1483 | |
| 1484 | case 2: |
| 1485 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0); |
| 1486 | fallthrough; |
| 1487 | case 4: |
| 1488 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f); |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 1489 | at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_GREEN, 0x6860); |
| 1490 | at803x_debug_reg_write(phydev, AT803X_DEBUG_SYSTEM_CTRL_MODE, 0x2c46); |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1491 | at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000); |
| 1492 | break; |
| 1493 | } |
| 1494 | |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 1495 | /* QCA8327 require DAC amplitude adjustment for 100m set to +6%. |
| 1496 | * Disable on init and enable only with 100m speed following |
| 1497 | * qca original source code. |
| 1498 | */ |
| 1499 | if (phydev->drv->phy_id == QCA8327_A_PHY_ID || |
| 1500 | phydev->drv->phy_id == QCA8327_B_PHY_ID) |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 1501 | at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 1502 | QCA8327_DEBUG_MANU_CTRL_EN, 0); |
| 1503 | |
Ansuel Smith | 9d1c29b | 2021-10-10 00:46:17 +0200 | [diff] [blame] | 1504 | /* Following original QCA sourcecode set port to prefer master */ |
| 1505 | phy_set_bits(phydev, MII_CTRL1000, CTL1000_PREFER_MASTER); |
| 1506 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1507 | return 0; |
| 1508 | } |
| 1509 | |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 1510 | static void qca83xx_link_change_notify(struct phy_device *phydev) |
| 1511 | { |
| 1512 | /* QCA8337 doesn't require DAC Amplitude adjustement */ |
| 1513 | if (phydev->drv->phy_id == QCA8337_PHY_ID) |
| 1514 | return; |
| 1515 | |
| 1516 | /* Set DAC Amplitude adjustment to +6% for 100m on link running */ |
| 1517 | if (phydev->state == PHY_RUNNING) { |
| 1518 | if (phydev->speed == SPEED_100) |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 1519 | at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 1520 | QCA8327_DEBUG_MANU_CTRL_EN, |
| 1521 | QCA8327_DEBUG_MANU_CTRL_EN); |
| 1522 | } else { |
| 1523 | /* Reset DAC Amplitude adjustment */ |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 1524 | at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 1525 | QCA8327_DEBUG_MANU_CTRL_EN, 0); |
| 1526 | } |
| 1527 | } |
| 1528 | |
Ansuel Smith | ba3c01e | 2021-10-10 00:46:15 +0200 | [diff] [blame] | 1529 | static int qca83xx_resume(struct phy_device *phydev) |
| 1530 | { |
| 1531 | int ret, val; |
| 1532 | |
| 1533 | /* Skip reset if not suspended */ |
| 1534 | if (!phydev->suspended) |
| 1535 | return 0; |
| 1536 | |
| 1537 | /* Reinit the port, reset values set by suspend */ |
| 1538 | qca83xx_config_init(phydev); |
| 1539 | |
| 1540 | /* Reset the port on port resume */ |
| 1541 | phy_set_bits(phydev, MII_BMCR, BMCR_RESET | BMCR_ANENABLE); |
| 1542 | |
| 1543 | /* On resume from suspend the switch execute a reset and |
| 1544 | * restart auto-negotiation. Wait for reset to complete. |
| 1545 | */ |
| 1546 | ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET), |
| 1547 | 50000, 600000, true); |
| 1548 | if (ret) |
| 1549 | return ret; |
| 1550 | |
| 1551 | msleep(1); |
| 1552 | |
| 1553 | return 0; |
| 1554 | } |
| 1555 | |
| 1556 | static int qca83xx_suspend(struct phy_device *phydev) |
| 1557 | { |
| 1558 | u16 mask = 0; |
| 1559 | |
| 1560 | /* Only QCA8337 support actual suspend. |
| 1561 | * QCA8327 cause port unreliability when phy suspend |
| 1562 | * is set. |
| 1563 | */ |
| 1564 | if (phydev->drv->phy_id == QCA8337_PHY_ID) { |
| 1565 | genphy_suspend(phydev); |
| 1566 | } else { |
| 1567 | mask |= ~(BMCR_SPEED1000 | BMCR_FULLDPLX); |
| 1568 | phy_modify(phydev, MII_BMCR, mask, 0); |
| 1569 | } |
| 1570 | |
Ansuel Smith | 6799955 | 2021-10-10 00:46:18 +0200 | [diff] [blame] | 1571 | at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_GREEN, |
Ansuel Smith | ba3c01e | 2021-10-10 00:46:15 +0200 | [diff] [blame] | 1572 | AT803X_DEBUG_GATE_CLK_IN1000, 0); |
| 1573 | |
| 1574 | at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL, |
| 1575 | AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE | |
| 1576 | AT803X_DEBUG_HIB_CTRL_SEL_RST_80U, 0); |
| 1577 | |
| 1578 | return 0; |
| 1579 | } |
| 1580 | |
Luo Jie | 2acdd43f | 2021-10-24 16:27:35 +0800 | [diff] [blame] | 1581 | static int qca808x_phy_fast_retrain_config(struct phy_device *phydev) |
| 1582 | { |
| 1583 | int ret; |
| 1584 | |
| 1585 | /* Enable fast retrain */ |
| 1586 | ret = genphy_c45_fast_retrain(phydev, true); |
| 1587 | if (ret) |
| 1588 | return ret; |
| 1589 | |
| 1590 | phy_write_mmd(phydev, MDIO_MMD_AN, QCA808X_PHY_MMD7_TOP_OPTION1, |
| 1591 | QCA808X_TOP_OPTION1_DATA); |
| 1592 | phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_20DB, |
| 1593 | QCA808X_MSE_THRESHOLD_20DB_VALUE); |
| 1594 | phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_17DB, |
| 1595 | QCA808X_MSE_THRESHOLD_17DB_VALUE); |
| 1596 | phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_27DB, |
| 1597 | QCA808X_MSE_THRESHOLD_27DB_VALUE); |
| 1598 | phy_write_mmd(phydev, MDIO_MMD_PMAPMD, QCA808X_PHY_MMD1_MSE_THRESHOLD_28DB, |
| 1599 | QCA808X_MSE_THRESHOLD_28DB_VALUE); |
| 1600 | phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_1, |
| 1601 | QCA808X_MMD3_DEBUG_1_VALUE); |
| 1602 | phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_4, |
| 1603 | QCA808X_MMD3_DEBUG_4_VALUE); |
| 1604 | phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_5, |
| 1605 | QCA808X_MMD3_DEBUG_5_VALUE); |
| 1606 | phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_3, |
| 1607 | QCA808X_MMD3_DEBUG_3_VALUE); |
| 1608 | phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_6, |
| 1609 | QCA808X_MMD3_DEBUG_6_VALUE); |
| 1610 | phy_write_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_DEBUG_2, |
| 1611 | QCA808X_MMD3_DEBUG_2_VALUE); |
| 1612 | |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
Luo Jie | 9d4dae2 | 2021-10-24 16:27:36 +0800 | [diff] [blame] | 1616 | static int qca808x_phy_ms_random_seed_set(struct phy_device *phydev) |
| 1617 | { |
| 1618 | u16 seed_value = (prandom_u32() % QCA808X_MASTER_SLAVE_SEED_RANGE); |
| 1619 | |
| 1620 | return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED, |
| 1621 | QCA808X_MASTER_SLAVE_SEED_CFG, |
| 1622 | FIELD_PREP(QCA808X_MASTER_SLAVE_SEED_CFG, seed_value)); |
| 1623 | } |
| 1624 | |
| 1625 | static int qca808x_phy_ms_seed_enable(struct phy_device *phydev, bool enable) |
| 1626 | { |
| 1627 | u16 seed_enable = 0; |
| 1628 | |
| 1629 | if (enable) |
| 1630 | seed_enable = QCA808X_MASTER_SLAVE_SEED_ENABLE; |
| 1631 | |
| 1632 | return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_LOCAL_SEED, |
| 1633 | QCA808X_MASTER_SLAVE_SEED_ENABLE, seed_enable); |
| 1634 | } |
| 1635 | |
Luo Jie | 2acdd43f | 2021-10-24 16:27:35 +0800 | [diff] [blame] | 1636 | static int qca808x_config_init(struct phy_device *phydev) |
| 1637 | { |
| 1638 | int ret; |
| 1639 | |
| 1640 | /* Active adc&vga on 802.3az for the link 1000M and 100M */ |
| 1641 | ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, QCA808X_PHY_MMD3_ADDR_CLD_CTRL7, |
| 1642 | QCA808X_8023AZ_AFE_CTRL_MASK, QCA808X_8023AZ_AFE_EN); |
| 1643 | if (ret) |
| 1644 | return ret; |
| 1645 | |
| 1646 | /* Adjust the threshold on 802.3az for the link 1000M */ |
| 1647 | ret = phy_write_mmd(phydev, MDIO_MMD_PCS, |
| 1648 | QCA808X_PHY_MMD3_AZ_TRAINING_CTRL, QCA808X_MMD3_AZ_TRAINING_VAL); |
| 1649 | if (ret) |
| 1650 | return ret; |
| 1651 | |
| 1652 | /* Config the fast retrain for the link 2500M */ |
| 1653 | ret = qca808x_phy_fast_retrain_config(phydev); |
| 1654 | if (ret) |
| 1655 | return ret; |
| 1656 | |
Luo Jie | 9d4dae2 | 2021-10-24 16:27:36 +0800 | [diff] [blame] | 1657 | /* Configure lower ramdom seed to make phy linked as slave mode */ |
| 1658 | ret = qca808x_phy_ms_random_seed_set(phydev); |
| 1659 | if (ret) |
| 1660 | return ret; |
| 1661 | |
| 1662 | /* Enable seed */ |
| 1663 | ret = qca808x_phy_ms_seed_enable(phydev, true); |
| 1664 | if (ret) |
| 1665 | return ret; |
| 1666 | |
Luo Jie | 2acdd43f | 2021-10-24 16:27:35 +0800 | [diff] [blame] | 1667 | /* Configure adc threshold as 100mv for the link 10M */ |
| 1668 | return at803x_debug_reg_mask(phydev, QCA808X_PHY_DEBUG_ADC_THRESHOLD, |
| 1669 | QCA808X_ADC_THRESHOLD_MASK, QCA808X_ADC_THRESHOLD_100MV); |
| 1670 | } |
| 1671 | |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 1672 | static int qca808x_read_status(struct phy_device *phydev) |
| 1673 | { |
| 1674 | int ret; |
| 1675 | |
| 1676 | ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT); |
| 1677 | if (ret < 0) |
| 1678 | return ret; |
| 1679 | |
| 1680 | linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising, |
| 1681 | ret & MDIO_AN_10GBT_STAT_LP2_5G); |
| 1682 | |
| 1683 | ret = genphy_read_status(phydev); |
| 1684 | if (ret) |
| 1685 | return ret; |
| 1686 | |
| 1687 | ret = at803x_read_specific_status(phydev); |
| 1688 | if (ret < 0) |
| 1689 | return ret; |
| 1690 | |
Jonathan McDowell | 881cc73 | 2022-01-31 13:56:41 +0000 | [diff] [blame] | 1691 | if (phydev->link) { |
| 1692 | if (phydev->speed == SPEED_2500) |
| 1693 | phydev->interface = PHY_INTERFACE_MODE_2500BASEX; |
| 1694 | else |
| 1695 | phydev->interface = PHY_INTERFACE_MODE_SGMII; |
| 1696 | } else { |
| 1697 | /* generate seed as a lower random value to make PHY linked as SLAVE easily, |
| 1698 | * except for master/slave configuration fault detected. |
| 1699 | * the reason for not putting this code into the function link_change_notify is |
| 1700 | * the corner case where the link partner is also the qca8081 PHY and the seed |
| 1701 | * value is configured as the same value, the link can't be up and no link change |
| 1702 | * occurs. |
| 1703 | */ |
Luo Jie | 8bc1c54 | 2021-10-24 16:27:37 +0800 | [diff] [blame] | 1704 | if (phydev->master_slave_state == MASTER_SLAVE_STATE_ERR) { |
| 1705 | qca808x_phy_ms_seed_enable(phydev, false); |
| 1706 | } else { |
| 1707 | qca808x_phy_ms_random_seed_set(phydev); |
| 1708 | qca808x_phy_ms_seed_enable(phydev, true); |
| 1709 | } |
| 1710 | } |
| 1711 | |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 1712 | return 0; |
| 1713 | } |
| 1714 | |
Luo Jie | 9d4dae2 | 2021-10-24 16:27:36 +0800 | [diff] [blame] | 1715 | static int qca808x_soft_reset(struct phy_device *phydev) |
| 1716 | { |
| 1717 | int ret; |
| 1718 | |
| 1719 | ret = genphy_soft_reset(phydev); |
| 1720 | if (ret < 0) |
| 1721 | return ret; |
| 1722 | |
| 1723 | return qca808x_phy_ms_seed_enable(phydev, true); |
| 1724 | } |
| 1725 | |
Luo Jie | 8c84d75 | 2021-10-24 16:27:38 +0800 | [diff] [blame] | 1726 | static bool qca808x_cdt_fault_length_valid(int cdt_code) |
| 1727 | { |
| 1728 | switch (cdt_code) { |
| 1729 | case QCA808X_CDT_STATUS_STAT_SHORT: |
| 1730 | case QCA808X_CDT_STATUS_STAT_OPEN: |
| 1731 | return true; |
| 1732 | default: |
| 1733 | return false; |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | static int qca808x_cable_test_result_trans(int cdt_code) |
| 1738 | { |
| 1739 | switch (cdt_code) { |
| 1740 | case QCA808X_CDT_STATUS_STAT_NORMAL: |
| 1741 | return ETHTOOL_A_CABLE_RESULT_CODE_OK; |
| 1742 | case QCA808X_CDT_STATUS_STAT_SHORT: |
| 1743 | return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; |
| 1744 | case QCA808X_CDT_STATUS_STAT_OPEN: |
| 1745 | return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; |
| 1746 | case QCA808X_CDT_STATUS_STAT_FAIL: |
| 1747 | default: |
| 1748 | return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair) |
| 1753 | { |
| 1754 | int val; |
| 1755 | u32 cdt_length_reg = 0; |
| 1756 | |
| 1757 | switch (pair) { |
| 1758 | case ETHTOOL_A_CABLE_PAIR_A: |
| 1759 | cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_A; |
| 1760 | break; |
| 1761 | case ETHTOOL_A_CABLE_PAIR_B: |
| 1762 | cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_B; |
| 1763 | break; |
| 1764 | case ETHTOOL_A_CABLE_PAIR_C: |
| 1765 | cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_C; |
| 1766 | break; |
| 1767 | case ETHTOOL_A_CABLE_PAIR_D: |
| 1768 | cdt_length_reg = QCA808X_MMD3_CDT_DIAG_PAIR_D; |
| 1769 | break; |
| 1770 | default: |
| 1771 | return -EINVAL; |
| 1772 | } |
| 1773 | |
| 1774 | val = phy_read_mmd(phydev, MDIO_MMD_PCS, cdt_length_reg); |
| 1775 | if (val < 0) |
| 1776 | return val; |
| 1777 | |
| 1778 | return (FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val) * 824) / 10; |
| 1779 | } |
| 1780 | |
| 1781 | static int qca808x_cable_test_start(struct phy_device *phydev) |
| 1782 | { |
| 1783 | int ret; |
| 1784 | |
| 1785 | /* perform CDT with the following configs: |
| 1786 | * 1. disable hibernation. |
| 1787 | * 2. force PHY working in MDI mode. |
| 1788 | * 3. for PHY working in 1000BaseT. |
| 1789 | * 4. configure the threshold. |
| 1790 | */ |
| 1791 | |
| 1792 | ret = at803x_debug_reg_mask(phydev, QCA808X_DBG_AN_TEST, QCA808X_HIBERNATION_EN, 0); |
| 1793 | if (ret < 0) |
| 1794 | return ret; |
| 1795 | |
| 1796 | ret = at803x_config_mdix(phydev, ETH_TP_MDI); |
| 1797 | if (ret < 0) |
| 1798 | return ret; |
| 1799 | |
| 1800 | /* Force 1000base-T needs to configure PMA/PMD and MII_BMCR */ |
| 1801 | phydev->duplex = DUPLEX_FULL; |
| 1802 | phydev->speed = SPEED_1000; |
| 1803 | ret = genphy_c45_pma_setup_forced(phydev); |
| 1804 | if (ret < 0) |
| 1805 | return ret; |
| 1806 | |
| 1807 | ret = genphy_setup_forced(phydev); |
| 1808 | if (ret < 0) |
| 1809 | return ret; |
| 1810 | |
| 1811 | /* configure the thresholds for open, short, pair ok test */ |
| 1812 | phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8074, 0xc040); |
| 1813 | phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8076, 0xc040); |
| 1814 | phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8077, 0xa060); |
| 1815 | phy_write_mmd(phydev, MDIO_MMD_PCS, 0x8078, 0xc050); |
| 1816 | phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807a, 0xc060); |
| 1817 | phy_write_mmd(phydev, MDIO_MMD_PCS, 0x807e, 0xb060); |
| 1818 | |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished) |
| 1823 | { |
| 1824 | int ret, val; |
| 1825 | int pair_a, pair_b, pair_c, pair_d; |
| 1826 | |
| 1827 | *finished = false; |
| 1828 | |
| 1829 | ret = at803x_cdt_start(phydev, 0); |
| 1830 | if (ret) |
| 1831 | return ret; |
| 1832 | |
| 1833 | ret = at803x_cdt_wait_for_completion(phydev); |
| 1834 | if (ret) |
| 1835 | return ret; |
| 1836 | |
| 1837 | val = phy_read_mmd(phydev, MDIO_MMD_PCS, QCA808X_MMD3_CDT_STATUS); |
| 1838 | if (val < 0) |
| 1839 | return val; |
| 1840 | |
| 1841 | pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val); |
| 1842 | pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val); |
| 1843 | pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val); |
| 1844 | pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val); |
| 1845 | |
| 1846 | ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A, |
| 1847 | qca808x_cable_test_result_trans(pair_a)); |
| 1848 | ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B, |
| 1849 | qca808x_cable_test_result_trans(pair_b)); |
| 1850 | ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C, |
| 1851 | qca808x_cable_test_result_trans(pair_c)); |
| 1852 | ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D, |
| 1853 | qca808x_cable_test_result_trans(pair_d)); |
| 1854 | |
| 1855 | if (qca808x_cdt_fault_length_valid(pair_a)) |
| 1856 | ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A, |
| 1857 | qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A)); |
| 1858 | if (qca808x_cdt_fault_length_valid(pair_b)) |
| 1859 | ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B, |
| 1860 | qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B)); |
| 1861 | if (qca808x_cdt_fault_length_valid(pair_c)) |
| 1862 | ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C, |
| 1863 | qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C)); |
| 1864 | if (qca808x_cdt_fault_length_valid(pair_d)) |
| 1865 | ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D, |
| 1866 | qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D)); |
| 1867 | |
| 1868 | *finished = true; |
| 1869 | |
| 1870 | return 0; |
| 1871 | } |
| 1872 | |
Mugunthan V N | 317420a | 2013-06-03 20:10:04 +0000 | [diff] [blame] | 1873 | static struct phy_driver at803x_driver[] = { |
| 1874 | { |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1875 | /* Qualcomm Atheros AR8035 */ |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 1876 | PHY_ID_MATCH_EXACT(ATH8035_PHY_ID), |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1877 | .name = "Qualcomm Atheros AR8035", |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1878 | .flags = PHY_POLL_CABLE_TEST, |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 1879 | .probe = at803x_probe, |
Michael Walle | 2318ca8 | 2020-01-30 18:54:02 +0100 | [diff] [blame] | 1880 | .remove = at803x_remove, |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1881 | .config_aneg = at803x_config_aneg, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1882 | .config_init = at803x_config_init, |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1883 | .soft_reset = genphy_soft_reset, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1884 | .set_wol = at803x_set_wol, |
| 1885 | .get_wol = at803x_get_wol, |
| 1886 | .suspend = at803x_suspend, |
| 1887 | .resume = at803x_resume, |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 1888 | /* PHY_GBIT_FEATURES */ |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1889 | .read_status = at803x_read_status, |
Måns Rullgård | 0eae598 | 2015-11-12 17:40:20 +0000 | [diff] [blame] | 1890 | .config_intr = at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1891 | .handle_interrupt = at803x_handle_interrupt, |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1892 | .get_tunable = at803x_get_tunable, |
| 1893 | .set_tunable = at803x_set_tunable, |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1894 | .cable_test_start = at803x_cable_test_start, |
| 1895 | .cable_test_get_status = at803x_cable_test_get_status, |
Mugunthan V N | 317420a | 2013-06-03 20:10:04 +0000 | [diff] [blame] | 1896 | }, { |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1897 | /* Qualcomm Atheros AR8030 */ |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1898 | .phy_id = ATH8030_PHY_ID, |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1899 | .name = "Qualcomm Atheros AR8030", |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 1900 | .phy_id_mask = AT8030_PHY_ID_MASK, |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 1901 | .probe = at803x_probe, |
Michael Walle | 2318ca8 | 2020-01-30 18:54:02 +0100 | [diff] [blame] | 1902 | .remove = at803x_remove, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1903 | .config_init = at803x_config_init, |
| 1904 | .link_change_notify = at803x_link_change_notify, |
| 1905 | .set_wol = at803x_set_wol, |
| 1906 | .get_wol = at803x_get_wol, |
| 1907 | .suspend = at803x_suspend, |
| 1908 | .resume = at803x_resume, |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 1909 | /* PHY_BASIC_FEATURES */ |
Måns Rullgård | 0eae598 | 2015-11-12 17:40:20 +0000 | [diff] [blame] | 1910 | .config_intr = at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1911 | .handle_interrupt = at803x_handle_interrupt, |
Mugunthan V N | 05d7cce | 2013-06-03 20:10:07 +0000 | [diff] [blame] | 1912 | }, { |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1913 | /* Qualcomm Atheros AR8031/AR8033 */ |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 1914 | PHY_ID_MATCH_EXACT(ATH8031_PHY_ID), |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1915 | .name = "Qualcomm Atheros AR8031/AR8033", |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1916 | .flags = PHY_POLL_CABLE_TEST, |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 1917 | .probe = at803x_probe, |
Michael Walle | 2318ca8 | 2020-01-30 18:54:02 +0100 | [diff] [blame] | 1918 | .remove = at803x_remove, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1919 | .config_init = at803x_config_init, |
Michael Walle | 63477a5 | 2021-02-14 02:17:11 +0100 | [diff] [blame] | 1920 | .config_aneg = at803x_config_aneg, |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1921 | .soft_reset = genphy_soft_reset, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1922 | .set_wol = at803x_set_wol, |
| 1923 | .get_wol = at803x_get_wol, |
| 1924 | .suspend = at803x_suspend, |
| 1925 | .resume = at803x_resume, |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 1926 | .read_page = at803x_read_page, |
| 1927 | .write_page = at803x_write_page, |
David Bauer | b856150 | 2021-06-27 12:16:07 +0200 | [diff] [blame] | 1928 | .get_features = at803x_get_features, |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1929 | .read_status = at803x_read_status, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1930 | .config_intr = &at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1931 | .handle_interrupt = at803x_handle_interrupt, |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1932 | .get_tunable = at803x_get_tunable, |
| 1933 | .set_tunable = at803x_set_tunable, |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1934 | .cable_test_start = at803x_cable_test_start, |
| 1935 | .cable_test_get_status = at803x_cable_test_get_status, |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1936 | }, { |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1937 | /* Qualcomm Atheros AR8032 */ |
| 1938 | PHY_ID_MATCH_EXACT(ATH8032_PHY_ID), |
| 1939 | .name = "Qualcomm Atheros AR8032", |
| 1940 | .probe = at803x_probe, |
| 1941 | .remove = at803x_remove, |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1942 | .flags = PHY_POLL_CABLE_TEST, |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1943 | .config_init = at803x_config_init, |
| 1944 | .link_change_notify = at803x_link_change_notify, |
| 1945 | .set_wol = at803x_set_wol, |
| 1946 | .get_wol = at803x_get_wol, |
| 1947 | .suspend = at803x_suspend, |
| 1948 | .resume = at803x_resume, |
| 1949 | /* PHY_BASIC_FEATURES */ |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1950 | .config_intr = at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1951 | .handle_interrupt = at803x_handle_interrupt, |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1952 | .cable_test_start = at803x_cable_test_start, |
| 1953 | .cable_test_get_status = at803x_cable_test_get_status, |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1954 | }, { |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1955 | /* ATHEROS AR9331 */ |
| 1956 | PHY_ID_MATCH_EXACT(ATH9331_PHY_ID), |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1957 | .name = "Qualcomm Atheros AR9331 built-in PHY", |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1958 | .suspend = at803x_suspend, |
| 1959 | .resume = at803x_resume, |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1960 | .flags = PHY_POLL_CABLE_TEST, |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1961 | /* PHY_BASIC_FEATURES */ |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1962 | .config_intr = &at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1963 | .handle_interrupt = at803x_handle_interrupt, |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1964 | .cable_test_start = at803x_cable_test_start, |
| 1965 | .cable_test_get_status = at803x_cable_test_get_status, |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1966 | .read_status = at803x_read_status, |
| 1967 | .soft_reset = genphy_soft_reset, |
| 1968 | .config_aneg = at803x_config_aneg, |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1969 | }, { |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame] | 1970 | /* Qualcomm Atheros QCA9561 */ |
| 1971 | PHY_ID_MATCH_EXACT(QCA9561_PHY_ID), |
| 1972 | .name = "Qualcomm Atheros QCA9561 built-in PHY", |
| 1973 | .suspend = at803x_suspend, |
| 1974 | .resume = at803x_resume, |
| 1975 | .flags = PHY_POLL_CABLE_TEST, |
| 1976 | /* PHY_BASIC_FEATURES */ |
| 1977 | .config_intr = &at803x_config_intr, |
| 1978 | .handle_interrupt = at803x_handle_interrupt, |
| 1979 | .cable_test_start = at803x_cable_test_start, |
| 1980 | .cable_test_get_status = at803x_cable_test_get_status, |
| 1981 | .read_status = at803x_read_status, |
| 1982 | .soft_reset = genphy_soft_reset, |
| 1983 | .config_aneg = at803x_config_aneg, |
| 1984 | }, { |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1985 | /* QCA8337 */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 1986 | .phy_id = QCA8337_PHY_ID, |
| 1987 | .phy_id_mask = QCA8K_PHY_ID_MASK, |
| 1988 | .name = "Qualcomm Atheros 8337 internal PHY", |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1989 | /* PHY_GBIT_FEATURES */ |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 1990 | .link_change_notify = qca83xx_link_change_notify, |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 1991 | .probe = at803x_probe, |
| 1992 | .flags = PHY_IS_INTERNAL, |
| 1993 | .config_init = qca83xx_config_init, |
| 1994 | .soft_reset = genphy_soft_reset, |
| 1995 | .get_sset_count = at803x_get_sset_count, |
| 1996 | .get_strings = at803x_get_strings, |
| 1997 | .get_stats = at803x_get_stats, |
Ansuel Smith | ba3c01e | 2021-10-10 00:46:15 +0200 | [diff] [blame] | 1998 | .suspend = qca83xx_suspend, |
| 1999 | .resume = qca83xx_resume, |
Ansuel Smith | 0ccf851 | 2021-09-14 14:33:45 +0200 | [diff] [blame] | 2000 | }, { |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 2001 | /* QCA8327-A from switch QCA8327-AL1A */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 2002 | .phy_id = QCA8327_A_PHY_ID, |
| 2003 | .phy_id_mask = QCA8K_PHY_ID_MASK, |
| 2004 | .name = "Qualcomm Atheros 8327-A internal PHY", |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 2005 | /* PHY_GBIT_FEATURES */ |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 2006 | .link_change_notify = qca83xx_link_change_notify, |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 2007 | .probe = at803x_probe, |
| 2008 | .flags = PHY_IS_INTERNAL, |
| 2009 | .config_init = qca83xx_config_init, |
| 2010 | .soft_reset = genphy_soft_reset, |
| 2011 | .get_sset_count = at803x_get_sset_count, |
| 2012 | .get_strings = at803x_get_strings, |
| 2013 | .get_stats = at803x_get_stats, |
Ansuel Smith | ba3c01e | 2021-10-10 00:46:15 +0200 | [diff] [blame] | 2014 | .suspend = qca83xx_suspend, |
| 2015 | .resume = qca83xx_resume, |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 2016 | }, { |
| 2017 | /* QCA8327-B from switch QCA8327-BL1A */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 2018 | .phy_id = QCA8327_B_PHY_ID, |
| 2019 | .phy_id_mask = QCA8K_PHY_ID_MASK, |
| 2020 | .name = "Qualcomm Atheros 8327-B internal PHY", |
Ansuel Smith | 0ccf851 | 2021-09-14 14:33:45 +0200 | [diff] [blame] | 2021 | /* PHY_GBIT_FEATURES */ |
Ansuel Smith | 1ca8311 | 2021-10-10 00:46:16 +0200 | [diff] [blame] | 2022 | .link_change_notify = qca83xx_link_change_notify, |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 2023 | .probe = at803x_probe, |
| 2024 | .flags = PHY_IS_INTERNAL, |
| 2025 | .config_init = qca83xx_config_init, |
| 2026 | .soft_reset = genphy_soft_reset, |
| 2027 | .get_sset_count = at803x_get_sset_count, |
| 2028 | .get_strings = at803x_get_strings, |
| 2029 | .get_stats = at803x_get_stats, |
Ansuel Smith | ba3c01e | 2021-10-10 00:46:15 +0200 | [diff] [blame] | 2030 | .suspend = qca83xx_suspend, |
| 2031 | .resume = qca83xx_resume, |
Luo Jie | daf6173 | 2021-10-24 16:27:29 +0800 | [diff] [blame] | 2032 | }, { |
| 2033 | /* Qualcomm QCA8081 */ |
| 2034 | PHY_ID_MATCH_EXACT(QCA8081_PHY_ID), |
| 2035 | .name = "Qualcomm QCA8081", |
Luo Jie | 8c84d75 | 2021-10-24 16:27:38 +0800 | [diff] [blame] | 2036 | .flags = PHY_POLL_CABLE_TEST, |
Luo Jie | daf6173 | 2021-10-24 16:27:29 +0800 | [diff] [blame] | 2037 | .config_intr = at803x_config_intr, |
| 2038 | .handle_interrupt = at803x_handle_interrupt, |
| 2039 | .get_tunable = at803x_get_tunable, |
| 2040 | .set_tunable = at803x_set_tunable, |
| 2041 | .set_wol = at803x_set_wol, |
| 2042 | .get_wol = at803x_get_wol, |
Luo Jie | 765c22a | 2021-10-24 16:27:31 +0800 | [diff] [blame] | 2043 | .get_features = at803x_get_features, |
Luo Jie | f884d44 | 2021-10-24 16:27:32 +0800 | [diff] [blame] | 2044 | .config_aneg = at803x_config_aneg, |
Luo Jie | daf6173 | 2021-10-24 16:27:29 +0800 | [diff] [blame] | 2045 | .suspend = genphy_suspend, |
| 2046 | .resume = genphy_resume, |
Luo Jie | 79c7bc0 | 2021-10-24 16:27:30 +0800 | [diff] [blame] | 2047 | .read_status = qca808x_read_status, |
Luo Jie | 2acdd43f | 2021-10-24 16:27:35 +0800 | [diff] [blame] | 2048 | .config_init = qca808x_config_init, |
Luo Jie | 9d4dae2 | 2021-10-24 16:27:36 +0800 | [diff] [blame] | 2049 | .soft_reset = qca808x_soft_reset, |
Luo Jie | 8c84d75 | 2021-10-24 16:27:38 +0800 | [diff] [blame] | 2050 | .cable_test_start = qca808x_cable_test_start, |
| 2051 | .cable_test_get_status = qca808x_cable_test_get_status, |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 2052 | }, }; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 2053 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 2054 | module_phy_driver(at803x_driver); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 2055 | |
| 2056 | static struct mdio_device_id __maybe_unused atheros_tbl[] = { |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 2057 | { ATH8030_PHY_ID, AT8030_PHY_ID_MASK }, |
| 2058 | { PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) }, |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 2059 | { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) }, |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 2060 | { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) }, |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 2061 | { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) }, |
Ansuel Smith | 0ccf851 | 2021-09-14 14:33:45 +0200 | [diff] [blame] | 2062 | { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) }, |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 2063 | { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) }, |
| 2064 | { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) }, |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame] | 2065 | { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) }, |
Luo Jie | daf6173 | 2021-10-24 16:27:29 +0800 | [diff] [blame] | 2066 | { PHY_ID_MATCH_EXACT(QCA8081_PHY_ID) }, |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 2067 | { } |
| 2068 | }; |
| 2069 | |
| 2070 | MODULE_DEVICE_TABLE(mdio, atheros_tbl); |