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 |
| 36 | #define AT803X_SS_SPEED_MASK (3 << 14) |
| 37 | #define AT803X_SS_SPEED_1000 (2 << 14) |
| 38 | #define AT803X_SS_SPEED_100 (1 << 14) |
| 39 | #define AT803X_SS_SPEED_10 (0 << 14) |
| 40 | #define AT803X_SS_DUPLEX BIT(13) |
| 41 | #define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11) |
| 42 | #define AT803X_SS_MDIX BIT(6) |
| 43 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 44 | #define AT803X_INTR_ENABLE 0x12 |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 45 | #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15) |
| 46 | #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14) |
| 47 | #define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13) |
| 48 | #define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12) |
| 49 | #define AT803X_INTR_ENABLE_LINK_FAIL BIT(11) |
| 50 | #define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10) |
| 51 | #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5) |
| 52 | #define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1) |
| 53 | #define AT803X_INTR_ENABLE_WOL BIT(0) |
| 54 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 55 | #define AT803X_INTR_STATUS 0x13 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 56 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 57 | #define AT803X_SMART_SPEED 0x14 |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 58 | #define AT803X_SMART_SPEED_ENABLE BIT(5) |
| 59 | #define AT803X_SMART_SPEED_RETRY_LIMIT_MASK GENMASK(4, 2) |
| 60 | #define AT803X_SMART_SPEED_BYPASS_TIMER BIT(1) |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 61 | #define AT803X_CDT 0x16 |
| 62 | #define AT803X_CDT_MDI_PAIR_MASK GENMASK(9, 8) |
| 63 | #define AT803X_CDT_ENABLE_TEST BIT(0) |
| 64 | #define AT803X_CDT_STATUS 0x1c |
| 65 | #define AT803X_CDT_STATUS_STAT_NORMAL 0 |
| 66 | #define AT803X_CDT_STATUS_STAT_SHORT 1 |
| 67 | #define AT803X_CDT_STATUS_STAT_OPEN 2 |
| 68 | #define AT803X_CDT_STATUS_STAT_FAIL 3 |
| 69 | #define AT803X_CDT_STATUS_STAT_MASK GENMASK(9, 8) |
| 70 | #define AT803X_CDT_STATUS_DELTA_TIME_MASK GENMASK(7, 0) |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 71 | #define AT803X_LED_CONTROL 0x18 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 72 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 73 | #define AT803X_DEVICE_ADDR 0x03 |
| 74 | #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C |
| 75 | #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B |
| 76 | #define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A |
Zefir Kurtisi | f62265b | 2016-10-24 12:40:54 +0200 | [diff] [blame] | 77 | #define AT803X_REG_CHIP_CONFIG 0x1f |
| 78 | #define AT803X_BT_BX_REG_SEL 0x8000 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 79 | |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 80 | #define AT803X_DEBUG_ADDR 0x1D |
| 81 | #define AT803X_DEBUG_DATA 0x1E |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 82 | |
Zefir Kurtisi | f62265b | 2016-10-24 12:40:54 +0200 | [diff] [blame] | 83 | #define AT803X_MODE_CFG_MASK 0x0F |
| 84 | #define AT803X_MODE_CFG_SGMII 0x01 |
| 85 | |
Ansuel Smith | d0e13fd | 2021-05-14 23:00:14 +0200 | [diff] [blame] | 86 | #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/ |
| 87 | #define AT803X_PSSR_MR_AN_COMPLETE 0x0200 |
Zefir Kurtisi | f62265b | 2016-10-24 12:40:54 +0200 | [diff] [blame] | 88 | |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 89 | #define AT803X_DEBUG_REG_0 0x00 |
| 90 | #define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15) |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 91 | |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 92 | #define AT803X_DEBUG_REG_5 0x05 |
| 93 | #define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8) |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 94 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 95 | #define AT803X_DEBUG_REG_3C 0x3C |
| 96 | |
| 97 | #define AT803X_DEBUG_REG_3D 0x3D |
| 98 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 99 | #define AT803X_DEBUG_REG_1F 0x1F |
| 100 | #define AT803X_DEBUG_PLL_ON BIT(2) |
| 101 | #define AT803X_DEBUG_RGMII_1V8 BIT(3) |
| 102 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 103 | #define MDIO_AZ_DEBUG 0x800D |
| 104 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 105 | /* AT803x supports either the XTAL input pad, an internal PLL or the |
| 106 | * DSP as clock reference for the clock output pad. The XTAL reference |
| 107 | * is only used for 25 MHz output, all other frequencies need the PLL. |
| 108 | * The DSP as a clock reference is used in synchronous ethernet |
| 109 | * applications. |
| 110 | * |
| 111 | * By default the PLL is only enabled if there is a link. Otherwise |
| 112 | * the PHY will go into low power state and disabled the PLL. You can |
| 113 | * set the PLL_ON bit (see debug register 0x1f) to keep the PLL always |
| 114 | * enabled. |
| 115 | */ |
| 116 | #define AT803X_MMD7_CLK25M 0x8016 |
| 117 | #define AT803X_CLK_OUT_MASK GENMASK(4, 2) |
| 118 | #define AT803X_CLK_OUT_25MHZ_XTAL 0 |
| 119 | #define AT803X_CLK_OUT_25MHZ_DSP 1 |
| 120 | #define AT803X_CLK_OUT_50MHZ_PLL 2 |
| 121 | #define AT803X_CLK_OUT_50MHZ_DSP 3 |
| 122 | #define AT803X_CLK_OUT_62_5MHZ_PLL 4 |
| 123 | #define AT803X_CLK_OUT_62_5MHZ_DSP 5 |
| 124 | #define AT803X_CLK_OUT_125MHZ_PLL 6 |
| 125 | #define AT803X_CLK_OUT_125MHZ_DSP 7 |
| 126 | |
Michael Walle | 428061f | 2019-11-06 23:36:15 +0100 | [diff] [blame] | 127 | /* The AR8035 has another mask which is compatible with the AR8031/AR8033 mask |
| 128 | * but doesn't support choosing between XTAL/PLL and DSP. |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 129 | */ |
| 130 | #define AT8035_CLK_OUT_MASK GENMASK(4, 3) |
| 131 | |
| 132 | #define AT803X_CLK_OUT_STRENGTH_MASK GENMASK(8, 7) |
| 133 | #define AT803X_CLK_OUT_STRENGTH_FULL 0 |
| 134 | #define AT803X_CLK_OUT_STRENGTH_HALF 1 |
| 135 | #define AT803X_CLK_OUT_STRENGTH_QUARTER 2 |
| 136 | |
Ansuel Smith | d0e13fd | 2021-05-14 23:00:14 +0200 | [diff] [blame] | 137 | #define AT803X_DEFAULT_DOWNSHIFT 5 |
| 138 | #define AT803X_MIN_DOWNSHIFT 2 |
| 139 | #define AT803X_MAX_DOWNSHIFT 9 |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 140 | |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 141 | #define AT803X_MMD3_SMARTEEE_CTL1 0x805b |
| 142 | #define AT803X_MMD3_SMARTEEE_CTL2 0x805c |
| 143 | #define AT803X_MMD3_SMARTEEE_CTL3 0x805d |
| 144 | #define AT803X_MMD3_SMARTEEE_CTL3_LPI_EN BIT(8) |
| 145 | |
Ansuel Smith | d0e13fd | 2021-05-14 23:00:14 +0200 | [diff] [blame] | 146 | #define ATH9331_PHY_ID 0x004dd041 |
| 147 | #define ATH8030_PHY_ID 0x004dd076 |
| 148 | #define ATH8031_PHY_ID 0x004dd074 |
| 149 | #define ATH8032_PHY_ID 0x004dd023 |
| 150 | #define ATH8035_PHY_ID 0x004dd072 |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 151 | #define AT8030_PHY_ID_MASK 0xffffffef |
Daniel Mack | bd8ca17 | 2014-06-18 11:01:42 +0200 | [diff] [blame] | 152 | |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 153 | #define QCA8327_A_PHY_ID 0x004dd033 |
| 154 | #define QCA8327_B_PHY_ID 0x004dd034 |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 155 | #define QCA8337_PHY_ID 0x004dd036 |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame^] | 156 | #define QCA9561_PHY_ID 0x004dd042 |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 157 | #define QCA8K_PHY_ID_MASK 0xffffffff |
| 158 | |
| 159 | #define QCA8K_DEVFLAGS_REVISION_MASK GENMASK(2, 0) |
| 160 | |
Ansuel Smith | d0e13fd | 2021-05-14 23:00:14 +0200 | [diff] [blame] | 161 | #define AT803X_PAGE_FIBER 0 |
| 162 | #define AT803X_PAGE_COPPER 1 |
| 163 | |
| 164 | /* don't turn off internal PLL */ |
| 165 | #define AT803X_KEEP_PLL_ENABLED BIT(0) |
| 166 | #define AT803X_DISABLE_SMARTEEE BIT(1) |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 167 | |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 168 | MODULE_DESCRIPTION("Qualcomm Atheros AR803x PHY driver"); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 169 | MODULE_AUTHOR("Matus Ujhelyi"); |
| 170 | MODULE_LICENSE("GPL"); |
| 171 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 172 | enum stat_access_type { |
| 173 | PHY, |
| 174 | MMD |
| 175 | }; |
| 176 | |
| 177 | struct at803x_hw_stat { |
| 178 | const char *string; |
| 179 | u8 reg; |
| 180 | u32 mask; |
| 181 | enum stat_access_type access_type; |
| 182 | }; |
| 183 | |
| 184 | static struct at803x_hw_stat at803x_hw_stats[] = { |
| 185 | { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY}, |
| 186 | { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY}, |
| 187 | { "eee_wake_errors", 0x16, GENMASK(15, 0), MMD}, |
| 188 | }; |
| 189 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 190 | struct at803x_priv { |
| 191 | int flags; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 192 | u16 clk_25m_reg; |
| 193 | u16 clk_25m_mask; |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 194 | u8 smarteee_lpi_tw_1g; |
| 195 | u8 smarteee_lpi_tw_100m; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 196 | struct regulator_dev *vddio_rdev; |
| 197 | struct regulator_dev *vddh_rdev; |
| 198 | struct regulator *vddio; |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 199 | u64 stats[ARRAY_SIZE(at803x_hw_stats)]; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 200 | }; |
| 201 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 202 | struct at803x_context { |
| 203 | u16 bmcr; |
| 204 | u16 advertise; |
| 205 | u16 control1000; |
| 206 | u16 int_enable; |
| 207 | u16 smart_speed; |
| 208 | u16 led_control; |
| 209 | }; |
| 210 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 211 | static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data) |
| 212 | { |
| 213 | int ret; |
| 214 | |
| 215 | ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); |
| 216 | if (ret < 0) |
| 217 | return ret; |
| 218 | |
| 219 | return phy_write(phydev, AT803X_DEBUG_DATA, data); |
| 220 | } |
| 221 | |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 222 | static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg) |
| 223 | { |
| 224 | int ret; |
| 225 | |
| 226 | ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); |
| 227 | if (ret < 0) |
| 228 | return ret; |
| 229 | |
| 230 | return phy_read(phydev, AT803X_DEBUG_DATA); |
| 231 | } |
| 232 | |
| 233 | static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg, |
| 234 | u16 clear, u16 set) |
| 235 | { |
| 236 | u16 val; |
| 237 | int ret; |
| 238 | |
| 239 | ret = at803x_debug_reg_read(phydev, reg); |
| 240 | if (ret < 0) |
| 241 | return ret; |
| 242 | |
| 243 | val = ret & 0xffff; |
| 244 | val &= ~clear; |
| 245 | val |= set; |
| 246 | |
| 247 | return phy_write(phydev, AT803X_DEBUG_DATA, val); |
| 248 | } |
| 249 | |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 250 | static int at803x_write_page(struct phy_device *phydev, int page) |
| 251 | { |
| 252 | int mask; |
| 253 | int set; |
| 254 | |
| 255 | if (page == AT803X_PAGE_COPPER) { |
| 256 | set = AT803X_BT_BX_REG_SEL; |
| 257 | mask = 0; |
| 258 | } else { |
| 259 | set = 0; |
| 260 | mask = AT803X_BT_BX_REG_SEL; |
| 261 | } |
| 262 | |
| 263 | return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set); |
| 264 | } |
| 265 | |
| 266 | static int at803x_read_page(struct phy_device *phydev) |
| 267 | { |
| 268 | int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG); |
| 269 | |
| 270 | if (ccr < 0) |
| 271 | return ccr; |
| 272 | |
| 273 | if (ccr & AT803X_BT_BX_REG_SEL) |
| 274 | return AT803X_PAGE_COPPER; |
| 275 | |
| 276 | return AT803X_PAGE_FIBER; |
| 277 | } |
| 278 | |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 279 | static int at803x_enable_rx_delay(struct phy_device *phydev) |
| 280 | { |
| 281 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0, |
| 282 | AT803X_DEBUG_RX_CLK_DLY_EN); |
| 283 | } |
| 284 | |
| 285 | static int at803x_enable_tx_delay(struct phy_device *phydev) |
| 286 | { |
| 287 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0, |
| 288 | AT803X_DEBUG_TX_CLK_DLY_EN); |
| 289 | } |
| 290 | |
Vinod Koul | 43f2ebd | 2019-02-21 15:53:14 +0530 | [diff] [blame] | 291 | static int at803x_disable_rx_delay(struct phy_device *phydev) |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 292 | { |
Vinod Koul | cd28d1d | 2019-01-21 14:43:17 +0530 | [diff] [blame] | 293 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, |
| 294 | AT803X_DEBUG_RX_CLK_DLY_EN, 0); |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Vinod Koul | 43f2ebd | 2019-02-21 15:53:14 +0530 | [diff] [blame] | 297 | static int at803x_disable_tx_delay(struct phy_device *phydev) |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 298 | { |
Vinod Koul | cd28d1d | 2019-01-21 14:43:17 +0530 | [diff] [blame] | 299 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, |
| 300 | AT803X_DEBUG_TX_CLK_DLY_EN, 0); |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 303 | /* save relevant PHY registers to private copy */ |
| 304 | static void at803x_context_save(struct phy_device *phydev, |
| 305 | struct at803x_context *context) |
| 306 | { |
| 307 | context->bmcr = phy_read(phydev, MII_BMCR); |
| 308 | context->advertise = phy_read(phydev, MII_ADVERTISE); |
| 309 | context->control1000 = phy_read(phydev, MII_CTRL1000); |
| 310 | context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE); |
| 311 | context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED); |
| 312 | context->led_control = phy_read(phydev, AT803X_LED_CONTROL); |
| 313 | } |
| 314 | |
| 315 | /* restore relevant PHY registers from private copy */ |
| 316 | static void at803x_context_restore(struct phy_device *phydev, |
| 317 | const struct at803x_context *context) |
| 318 | { |
| 319 | phy_write(phydev, MII_BMCR, context->bmcr); |
| 320 | phy_write(phydev, MII_ADVERTISE, context->advertise); |
| 321 | phy_write(phydev, MII_CTRL1000, context->control1000); |
| 322 | phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable); |
| 323 | phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed); |
| 324 | phy_write(phydev, AT803X_LED_CONTROL, context->led_control); |
| 325 | } |
| 326 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 327 | static int at803x_set_wol(struct phy_device *phydev, |
| 328 | struct ethtool_wolinfo *wol) |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 329 | { |
| 330 | struct net_device *ndev = phydev->attached_dev; |
| 331 | const u8 *mac; |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 332 | int ret; |
| 333 | u32 value; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 334 | unsigned int i, offsets[] = { |
| 335 | AT803X_LOC_MAC_ADDR_32_47_OFFSET, |
| 336 | AT803X_LOC_MAC_ADDR_16_31_OFFSET, |
| 337 | AT803X_LOC_MAC_ADDR_0_15_OFFSET, |
| 338 | }; |
| 339 | |
| 340 | if (!ndev) |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 341 | return -ENODEV; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 342 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 343 | if (wol->wolopts & WAKE_MAGIC) { |
| 344 | mac = (const u8 *) ndev->dev_addr; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 345 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 346 | if (!is_valid_ether_addr(mac)) |
Dan Murphy | fc75568 | 2017-10-10 12:42:56 -0500 | [diff] [blame] | 347 | return -EINVAL; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 348 | |
Carlo Caione | 0e02139 | 2019-01-25 12:35:10 +0000 | [diff] [blame] | 349 | for (i = 0; i < 3; i++) |
| 350 | phy_write_mmd(phydev, AT803X_DEVICE_ADDR, offsets[i], |
| 351 | mac[(i * 2) + 1] | (mac[(i * 2)] << 8)); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 352 | |
| 353 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 354 | value |= AT803X_INTR_ENABLE_WOL; |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 355 | ret = phy_write(phydev, AT803X_INTR_ENABLE, value); |
| 356 | if (ret) |
| 357 | return ret; |
| 358 | value = phy_read(phydev, AT803X_INTR_STATUS); |
| 359 | } else { |
| 360 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 361 | value &= (~AT803X_INTR_ENABLE_WOL); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 362 | ret = phy_write(phydev, AT803X_INTR_ENABLE, value); |
| 363 | if (ret) |
| 364 | return ret; |
| 365 | value = phy_read(phydev, AT803X_INTR_STATUS); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 366 | } |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 367 | |
| 368 | return ret; |
| 369 | } |
| 370 | |
| 371 | static void at803x_get_wol(struct phy_device *phydev, |
| 372 | struct ethtool_wolinfo *wol) |
| 373 | { |
| 374 | u32 value; |
| 375 | |
| 376 | wol->supported = WAKE_MAGIC; |
| 377 | wol->wolopts = 0; |
| 378 | |
| 379 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 380 | if (value & AT803X_INTR_ENABLE_WOL) |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 381 | wol->wolopts |= WAKE_MAGIC; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 384 | static int at803x_get_sset_count(struct phy_device *phydev) |
| 385 | { |
| 386 | return ARRAY_SIZE(at803x_hw_stats); |
| 387 | } |
| 388 | |
| 389 | static void at803x_get_strings(struct phy_device *phydev, u8 *data) |
| 390 | { |
| 391 | int i; |
| 392 | |
| 393 | for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) { |
| 394 | strscpy(data + i * ETH_GSTRING_LEN, |
| 395 | at803x_hw_stats[i].string, ETH_GSTRING_LEN); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | static u64 at803x_get_stat(struct phy_device *phydev, int i) |
| 400 | { |
| 401 | struct at803x_hw_stat stat = at803x_hw_stats[i]; |
| 402 | struct at803x_priv *priv = phydev->priv; |
| 403 | int val; |
| 404 | u64 ret; |
| 405 | |
| 406 | if (stat.access_type == MMD) |
| 407 | val = phy_read_mmd(phydev, MDIO_MMD_PCS, stat.reg); |
| 408 | else |
| 409 | val = phy_read(phydev, stat.reg); |
| 410 | |
| 411 | if (val < 0) { |
| 412 | ret = U64_MAX; |
| 413 | } else { |
| 414 | val = val & stat.mask; |
| 415 | priv->stats[i] += val; |
| 416 | ret = priv->stats[i]; |
| 417 | } |
| 418 | |
| 419 | return ret; |
| 420 | } |
| 421 | |
| 422 | static void at803x_get_stats(struct phy_device *phydev, |
| 423 | struct ethtool_stats *stats, u64 *data) |
| 424 | { |
| 425 | int i; |
| 426 | |
| 427 | for (i = 0; i < ARRAY_SIZE(at803x_hw_stats); i++) |
| 428 | data[i] = at803x_get_stat(phydev, i); |
| 429 | } |
| 430 | |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 431 | static int at803x_suspend(struct phy_device *phydev) |
| 432 | { |
| 433 | int value; |
| 434 | int wol_enabled; |
| 435 | |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 436 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 437 | wol_enabled = value & AT803X_INTR_ENABLE_WOL; |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 438 | |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 439 | if (wol_enabled) |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 440 | value = BMCR_ISOLATE; |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 441 | else |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 442 | value = BMCR_PDOWN; |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 443 | |
Russell King | fea23fb | 2018-01-02 10:58:58 +0000 | [diff] [blame] | 444 | phy_modify(phydev, MII_BMCR, 0, value); |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static int at803x_resume(struct phy_device *phydev) |
| 450 | { |
Russell King | f102852 | 2018-01-05 16:07:10 +0000 | [diff] [blame] | 451 | return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0); |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 452 | } |
| 453 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 454 | static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev, |
| 455 | unsigned int selector) |
| 456 | { |
| 457 | struct phy_device *phydev = rdev_get_drvdata(rdev); |
| 458 | |
| 459 | if (selector) |
| 460 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, |
| 461 | 0, AT803X_DEBUG_RGMII_1V8); |
| 462 | else |
| 463 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, |
| 464 | AT803X_DEBUG_RGMII_1V8, 0); |
| 465 | } |
| 466 | |
| 467 | static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev) |
| 468 | { |
| 469 | struct phy_device *phydev = rdev_get_drvdata(rdev); |
| 470 | int val; |
| 471 | |
| 472 | val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F); |
| 473 | if (val < 0) |
| 474 | return val; |
| 475 | |
| 476 | return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0; |
| 477 | } |
| 478 | |
Rikard Falkeborn | 3faaf53 | 2020-08-27 00:56:06 +0200 | [diff] [blame] | 479 | static const struct regulator_ops vddio_regulator_ops = { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 480 | .list_voltage = regulator_list_voltage_table, |
| 481 | .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel, |
| 482 | .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel, |
| 483 | }; |
| 484 | |
| 485 | static const unsigned int vddio_voltage_table[] = { |
| 486 | 1500000, |
| 487 | 1800000, |
| 488 | }; |
| 489 | |
| 490 | static const struct regulator_desc vddio_desc = { |
| 491 | .name = "vddio", |
| 492 | .of_match = of_match_ptr("vddio-regulator"), |
| 493 | .n_voltages = ARRAY_SIZE(vddio_voltage_table), |
| 494 | .volt_table = vddio_voltage_table, |
| 495 | .ops = &vddio_regulator_ops, |
| 496 | .type = REGULATOR_VOLTAGE, |
| 497 | .owner = THIS_MODULE, |
| 498 | }; |
| 499 | |
Rikard Falkeborn | 3faaf53 | 2020-08-27 00:56:06 +0200 | [diff] [blame] | 500 | static const struct regulator_ops vddh_regulator_ops = { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | static const struct regulator_desc vddh_desc = { |
| 504 | .name = "vddh", |
| 505 | .of_match = of_match_ptr("vddh-regulator"), |
| 506 | .n_voltages = 1, |
| 507 | .fixed_uV = 2500000, |
| 508 | .ops = &vddh_regulator_ops, |
| 509 | .type = REGULATOR_VOLTAGE, |
| 510 | .owner = THIS_MODULE, |
| 511 | }; |
| 512 | |
| 513 | static int at8031_register_regulators(struct phy_device *phydev) |
| 514 | { |
| 515 | struct at803x_priv *priv = phydev->priv; |
| 516 | struct device *dev = &phydev->mdio.dev; |
| 517 | struct regulator_config config = { }; |
| 518 | |
| 519 | config.dev = dev; |
| 520 | config.driver_data = phydev; |
| 521 | |
| 522 | priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config); |
| 523 | if (IS_ERR(priv->vddio_rdev)) { |
| 524 | phydev_err(phydev, "failed to register VDDIO regulator\n"); |
| 525 | return PTR_ERR(priv->vddio_rdev); |
| 526 | } |
| 527 | |
| 528 | priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config); |
| 529 | if (IS_ERR(priv->vddh_rdev)) { |
| 530 | phydev_err(phydev, "failed to register VDDH regulator\n"); |
| 531 | return PTR_ERR(priv->vddh_rdev); |
| 532 | } |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 537 | static int at803x_parse_dt(struct phy_device *phydev) |
| 538 | { |
| 539 | struct device_node *node = phydev->mdio.dev.of_node; |
| 540 | struct at803x_priv *priv = phydev->priv; |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 541 | u32 freq, strength, tw; |
Andrew Lunn | 3f2edd3 | 2020-07-07 03:49:33 +0200 | [diff] [blame] | 542 | unsigned int sel; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 543 | int ret; |
| 544 | |
| 545 | if (!IS_ENABLED(CONFIG_OF_MDIO)) |
| 546 | return 0; |
| 547 | |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 548 | if (of_property_read_bool(node, "qca,disable-smarteee")) |
| 549 | priv->flags |= AT803X_DISABLE_SMARTEEE; |
| 550 | |
| 551 | if (!of_property_read_u32(node, "qca,smarteee-tw-us-1g", &tw)) { |
| 552 | if (!tw || tw > 255) { |
| 553 | phydev_err(phydev, "invalid qca,smarteee-tw-us-1g\n"); |
| 554 | return -EINVAL; |
| 555 | } |
| 556 | priv->smarteee_lpi_tw_1g = tw; |
| 557 | } |
| 558 | |
| 559 | if (!of_property_read_u32(node, "qca,smarteee-tw-us-100m", &tw)) { |
| 560 | if (!tw || tw > 255) { |
| 561 | phydev_err(phydev, "invalid qca,smarteee-tw-us-100m\n"); |
| 562 | return -EINVAL; |
| 563 | } |
| 564 | priv->smarteee_lpi_tw_100m = tw; |
| 565 | } |
| 566 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 567 | ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq); |
| 568 | if (!ret) { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 569 | switch (freq) { |
| 570 | case 25000000: |
| 571 | sel = AT803X_CLK_OUT_25MHZ_XTAL; |
| 572 | break; |
| 573 | case 50000000: |
| 574 | sel = AT803X_CLK_OUT_50MHZ_PLL; |
| 575 | break; |
| 576 | case 62500000: |
| 577 | sel = AT803X_CLK_OUT_62_5MHZ_PLL; |
| 578 | break; |
| 579 | case 125000000: |
| 580 | sel = AT803X_CLK_OUT_125MHZ_PLL; |
| 581 | break; |
| 582 | default: |
| 583 | phydev_err(phydev, "invalid qca,clk-out-frequency\n"); |
| 584 | return -EINVAL; |
| 585 | } |
| 586 | |
Andrew Lunn | 3f2edd3 | 2020-07-07 03:49:33 +0200 | [diff] [blame] | 587 | priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel); |
| 588 | priv->clk_25m_mask |= AT803X_CLK_OUT_MASK; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 589 | |
| 590 | /* Fixup for the AR8030/AR8035. This chip has another mask and |
| 591 | * doesn't support the DSP reference. Eg. the lowest bit of the |
| 592 | * mask. The upper two bits select the same frequencies. Mask |
| 593 | * the lowest bit here. |
| 594 | * |
| 595 | * Warning: |
| 596 | * There was no datasheet for the AR8030 available so this is |
| 597 | * just a guess. But the AR8035 is listed as pin compatible |
| 598 | * to the AR8030 so there might be a good chance it works on |
| 599 | * the AR8030 too. |
| 600 | */ |
Russell King | 8887ca5 | 2021-07-20 14:33:49 +0100 | [diff] [blame] | 601 | if (phydev->drv->phy_id == ATH8030_PHY_ID || |
| 602 | phydev->drv->phy_id == ATH8035_PHY_ID) { |
Oleksij Rempel | b1f4c20 | 2020-04-01 11:57:32 +0200 | [diff] [blame] | 603 | priv->clk_25m_reg &= AT8035_CLK_OUT_MASK; |
| 604 | priv->clk_25m_mask &= AT8035_CLK_OUT_MASK; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
| 608 | ret = of_property_read_u32(node, "qca,clk-out-strength", &strength); |
| 609 | if (!ret) { |
| 610 | priv->clk_25m_mask |= AT803X_CLK_OUT_STRENGTH_MASK; |
| 611 | switch (strength) { |
| 612 | case AR803X_STRENGTH_FULL: |
| 613 | priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_FULL; |
| 614 | break; |
| 615 | case AR803X_STRENGTH_HALF: |
| 616 | priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_HALF; |
| 617 | break; |
| 618 | case AR803X_STRENGTH_QUARTER: |
| 619 | priv->clk_25m_reg |= AT803X_CLK_OUT_STRENGTH_QUARTER; |
| 620 | break; |
| 621 | default: |
| 622 | phydev_err(phydev, "invalid qca,clk-out-strength\n"); |
| 623 | return -EINVAL; |
| 624 | } |
| 625 | } |
| 626 | |
Michael Walle | 428061f | 2019-11-06 23:36:15 +0100 | [diff] [blame] | 627 | /* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping |
| 628 | * options. |
| 629 | */ |
Russell King | 8887ca5 | 2021-07-20 14:33:49 +0100 | [diff] [blame] | 630 | if (phydev->drv->phy_id == ATH8031_PHY_ID) { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 631 | if (of_property_read_bool(node, "qca,keep-pll-enabled")) |
| 632 | priv->flags |= AT803X_KEEP_PLL_ENABLED; |
| 633 | |
| 634 | ret = at8031_register_regulators(phydev); |
| 635 | if (ret < 0) |
| 636 | return ret; |
| 637 | |
| 638 | priv->vddio = devm_regulator_get_optional(&phydev->mdio.dev, |
| 639 | "vddio"); |
| 640 | if (IS_ERR(priv->vddio)) { |
| 641 | phydev_err(phydev, "failed to get VDDIO regulator\n"); |
| 642 | return PTR_ERR(priv->vddio); |
| 643 | } |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | static int at803x_probe(struct phy_device *phydev) |
| 650 | { |
| 651 | struct device *dev = &phydev->mdio.dev; |
| 652 | struct at803x_priv *priv; |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 653 | int ret; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 654 | |
| 655 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 656 | if (!priv) |
| 657 | return -ENOMEM; |
| 658 | |
| 659 | phydev->priv = priv; |
| 660 | |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 661 | ret = at803x_parse_dt(phydev); |
| 662 | if (ret) |
| 663 | return ret; |
| 664 | |
Michael Walle | 8f7e876 | 2021-04-20 12:29:29 +0200 | [diff] [blame] | 665 | if (priv->vddio) { |
| 666 | ret = regulator_enable(priv->vddio); |
| 667 | if (ret < 0) |
| 668 | return ret; |
| 669 | } |
| 670 | |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 671 | /* Some bootloaders leave the fiber page selected. |
| 672 | * Switch to the copper page, as otherwise we read |
| 673 | * the PHY capabilities from the fiber side. |
| 674 | */ |
Russell King | 8887ca5 | 2021-07-20 14:33:49 +0100 | [diff] [blame] | 675 | if (phydev->drv->phy_id == ATH8031_PHY_ID) { |
Michael Walle | 8f7e876 | 2021-04-20 12:29:29 +0200 | [diff] [blame] | 676 | phy_lock_mdio_bus(phydev); |
| 677 | ret = at803x_write_page(phydev, AT803X_PAGE_COPPER); |
| 678 | phy_unlock_mdio_bus(phydev); |
| 679 | if (ret) |
| 680 | goto err; |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 681 | } |
| 682 | |
Michael Walle | 8f7e876 | 2021-04-20 12:29:29 +0200 | [diff] [blame] | 683 | return 0; |
| 684 | |
| 685 | err: |
| 686 | if (priv->vddio) |
| 687 | regulator_disable(priv->vddio); |
| 688 | |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 689 | return ret; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 690 | } |
| 691 | |
Michael Walle | 2318ca8 | 2020-01-30 18:54:02 +0100 | [diff] [blame] | 692 | static void at803x_remove(struct phy_device *phydev) |
| 693 | { |
| 694 | struct at803x_priv *priv = phydev->priv; |
| 695 | |
| 696 | if (priv->vddio) |
| 697 | regulator_disable(priv->vddio); |
| 698 | } |
| 699 | |
David Bauer | b856150 | 2021-06-27 12:16:07 +0200 | [diff] [blame] | 700 | static int at803x_get_features(struct phy_device *phydev) |
| 701 | { |
| 702 | int err; |
| 703 | |
| 704 | err = genphy_read_abilities(phydev); |
| 705 | if (err) |
| 706 | return err; |
| 707 | |
Vladimir Oltean | f5621a0 | 2021-07-20 20:24:33 +0300 | [diff] [blame] | 708 | if (phydev->drv->phy_id != ATH8031_PHY_ID) |
David Bauer | b856150 | 2021-06-27 12:16:07 +0200 | [diff] [blame] | 709 | return 0; |
| 710 | |
| 711 | /* AR8031/AR8033 have different status registers |
| 712 | * for copper and fiber operation. However, the |
| 713 | * extended status register is the same for both |
| 714 | * operation modes. |
| 715 | * |
| 716 | * As a result of that, ESTATUS_1000_XFULL is set |
| 717 | * to 1 even when operating in copper TP mode. |
| 718 | * |
| 719 | * Remove this mode from the supported link modes, |
| 720 | * as this driver currently only supports copper |
| 721 | * operation. |
| 722 | */ |
| 723 | linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, |
| 724 | phydev->supported); |
| 725 | return 0; |
| 726 | } |
| 727 | |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 728 | static int at803x_smarteee_config(struct phy_device *phydev) |
| 729 | { |
| 730 | struct at803x_priv *priv = phydev->priv; |
| 731 | u16 mask = 0, val = 0; |
| 732 | int ret; |
| 733 | |
| 734 | if (priv->flags & AT803X_DISABLE_SMARTEEE) |
| 735 | return phy_modify_mmd(phydev, MDIO_MMD_PCS, |
| 736 | AT803X_MMD3_SMARTEEE_CTL3, |
| 737 | AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0); |
| 738 | |
| 739 | if (priv->smarteee_lpi_tw_1g) { |
| 740 | mask |= 0xff00; |
| 741 | val |= priv->smarteee_lpi_tw_1g << 8; |
| 742 | } |
| 743 | if (priv->smarteee_lpi_tw_100m) { |
| 744 | mask |= 0x00ff; |
| 745 | val |= priv->smarteee_lpi_tw_100m; |
| 746 | } |
| 747 | if (!mask) |
| 748 | return 0; |
| 749 | |
| 750 | ret = phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL1, |
| 751 | mask, val); |
| 752 | if (ret) |
| 753 | return ret; |
| 754 | |
| 755 | return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3, |
| 756 | AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, |
| 757 | AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); |
| 758 | } |
| 759 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 760 | static int at803x_clk_out_config(struct phy_device *phydev) |
| 761 | { |
| 762 | struct at803x_priv *priv = phydev->priv; |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 763 | |
| 764 | if (!priv->clk_25m_mask) |
| 765 | return 0; |
| 766 | |
Russell King | a45c1c1 | 2021-01-10 14:54:36 +0000 | [diff] [blame] | 767 | return phy_modify_mmd(phydev, MDIO_MMD_AN, AT803X_MMD7_CLK25M, |
| 768 | priv->clk_25m_mask, priv->clk_25m_reg); |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | static int at8031_pll_config(struct phy_device *phydev) |
| 772 | { |
| 773 | struct at803x_priv *priv = phydev->priv; |
| 774 | |
| 775 | /* The default after hardware reset is PLL OFF. After a soft reset, the |
| 776 | * values are retained. |
| 777 | */ |
| 778 | if (priv->flags & AT803X_KEEP_PLL_ENABLED) |
| 779 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, |
| 780 | 0, AT803X_DEBUG_PLL_ON); |
| 781 | else |
| 782 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F, |
| 783 | AT803X_DEBUG_PLL_ON, 0); |
| 784 | } |
| 785 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 786 | static int at803x_config_init(struct phy_device *phydev) |
| 787 | { |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 788 | int ret; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 789 | |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 790 | /* The RX and TX delay default is: |
| 791 | * after HW reset: RX delay enabled and TX delay disabled |
| 792 | * after SW reset: RX delay enabled, while TX delay retains the |
| 793 | * value before reset. |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 794 | */ |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 795 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
André Draszik | bb0ce4c | 2019-08-09 12:20:25 +0100 | [diff] [blame] | 796 | phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 797 | ret = at803x_enable_rx_delay(phydev); |
André Draszik | bb0ce4c | 2019-08-09 12:20:25 +0100 | [diff] [blame] | 798 | else |
| 799 | ret = at803x_disable_rx_delay(phydev); |
| 800 | if (ret < 0) |
| 801 | return ret; |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 802 | |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 803 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
André Draszik | bb0ce4c | 2019-08-09 12:20:25 +0100 | [diff] [blame] | 804 | phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
Vinod Koul | 6d4cd04 | 2019-02-21 15:53:15 +0530 | [diff] [blame] | 805 | ret = at803x_enable_tx_delay(phydev); |
André Draszik | bb0ce4c | 2019-08-09 12:20:25 +0100 | [diff] [blame] | 806 | else |
| 807 | ret = at803x_disable_tx_delay(phydev); |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 808 | if (ret < 0) |
| 809 | return ret; |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 810 | |
Russell King | 390b4ca | 2021-01-14 10:45:49 +0000 | [diff] [blame] | 811 | ret = at803x_smarteee_config(phydev); |
| 812 | if (ret < 0) |
| 813 | return ret; |
| 814 | |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 815 | ret = at803x_clk_out_config(phydev); |
| 816 | if (ret < 0) |
| 817 | return ret; |
| 818 | |
Russell King | 8887ca5 | 2021-07-20 14:33:49 +0100 | [diff] [blame] | 819 | if (phydev->drv->phy_id == ATH8031_PHY_ID) { |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 820 | ret = at8031_pll_config(phydev); |
| 821 | if (ret < 0) |
| 822 | return ret; |
| 823 | } |
| 824 | |
Russell King | 3c51fa5 | 2021-01-12 22:59:43 +0000 | [diff] [blame] | 825 | /* Ar803x extended next page bit is enabled by default. Cisco |
| 826 | * multigig switches read this bit and attempt to negotiate 10Gbps |
| 827 | * rates even if the next page bit is disabled. This is incorrect |
| 828 | * behaviour but we still need to accommodate it. XNP is only needed |
| 829 | * for 10Gbps support, so disable XNP. |
| 830 | */ |
| 831 | return phy_modify(phydev, MII_ADVERTISE, MDIO_AN_CTRL1_XNP, 0); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 834 | static int at803x_ack_interrupt(struct phy_device *phydev) |
| 835 | { |
| 836 | int err; |
| 837 | |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 838 | err = phy_read(phydev, AT803X_INTR_STATUS); |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 839 | |
| 840 | return (err < 0) ? err : 0; |
| 841 | } |
| 842 | |
| 843 | static int at803x_config_intr(struct phy_device *phydev) |
| 844 | { |
| 845 | int err; |
| 846 | int value; |
| 847 | |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 848 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 849 | |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 850 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { |
Ioana Ciornei | a341788 | 2020-11-01 14:51:00 +0200 | [diff] [blame] | 851 | /* Clear any pending interrupts */ |
| 852 | err = at803x_ack_interrupt(phydev); |
| 853 | if (err) |
| 854 | return err; |
| 855 | |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame] | 856 | value |= AT803X_INTR_ENABLE_AUTONEG_ERR; |
| 857 | value |= AT803X_INTR_ENABLE_SPEED_CHANGED; |
| 858 | value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED; |
| 859 | value |= AT803X_INTR_ENABLE_LINK_FAIL; |
| 860 | value |= AT803X_INTR_ENABLE_LINK_SUCCESS; |
| 861 | |
| 862 | err = phy_write(phydev, AT803X_INTR_ENABLE, value); |
Ioana Ciornei | a341788 | 2020-11-01 14:51:00 +0200 | [diff] [blame] | 863 | } else { |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 864 | err = phy_write(phydev, AT803X_INTR_ENABLE, 0); |
Ioana Ciornei | a341788 | 2020-11-01 14:51:00 +0200 | [diff] [blame] | 865 | if (err) |
| 866 | return err; |
| 867 | |
| 868 | /* Clear any pending interrupts */ |
| 869 | err = at803x_ack_interrupt(phydev); |
| 870 | } |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 871 | |
| 872 | return err; |
| 873 | } |
| 874 | |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 875 | static irqreturn_t at803x_handle_interrupt(struct phy_device *phydev) |
| 876 | { |
| 877 | int irq_status, int_enabled; |
| 878 | |
| 879 | irq_status = phy_read(phydev, AT803X_INTR_STATUS); |
| 880 | if (irq_status < 0) { |
| 881 | phy_error(phydev); |
| 882 | return IRQ_NONE; |
| 883 | } |
| 884 | |
| 885 | /* Read the current enabled interrupts */ |
| 886 | int_enabled = phy_read(phydev, AT803X_INTR_ENABLE); |
| 887 | if (int_enabled < 0) { |
| 888 | phy_error(phydev); |
| 889 | return IRQ_NONE; |
| 890 | } |
| 891 | |
| 892 | /* See if this was one of our enabled interrupts */ |
| 893 | if (!(irq_status & int_enabled)) |
| 894 | return IRQ_NONE; |
| 895 | |
| 896 | phy_trigger_machine(phydev); |
| 897 | |
| 898 | return IRQ_HANDLED; |
| 899 | } |
| 900 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 901 | static void at803x_link_change_notify(struct phy_device *phydev) |
| 902 | { |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 903 | /* |
| 904 | * Conduct a hardware reset for AT8030 every time a link loss is |
| 905 | * signalled. This is necessary to circumvent a hardware bug that |
| 906 | * occurs when the cable is unplugged while TX packets are pending |
| 907 | * in the FIFO. In such cases, the FIFO enters an error mode it |
| 908 | * cannot recover from by software. |
| 909 | */ |
David Bauer | 6110ed2 | 2019-04-17 23:59:22 +0200 | [diff] [blame] | 910 | if (phydev->state == PHY_NOLINK && phydev->mdio.reset_gpio) { |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 911 | struct at803x_context context; |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 912 | |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 913 | at803x_context_save(phydev, &context); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 914 | |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 915 | phy_device_reset(phydev, 1); |
| 916 | msleep(1); |
| 917 | phy_device_reset(phydev, 0); |
| 918 | msleep(1); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 919 | |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 920 | at803x_context_restore(phydev, &context); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 921 | |
Heiner Kallweit | 5c5f626 | 2019-03-19 19:56:51 +0100 | [diff] [blame] | 922 | phydev_dbg(phydev, "%s(): phy was reset\n", __func__); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 926 | static int at803x_read_status(struct phy_device *phydev) |
| 927 | { |
| 928 | int ss, err, old_link = phydev->link; |
| 929 | |
| 930 | /* Update the link, but return if there was an error */ |
| 931 | err = genphy_update_link(phydev); |
| 932 | if (err) |
| 933 | return err; |
| 934 | |
| 935 | /* why bother the PHY if nothing can have changed */ |
| 936 | if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) |
| 937 | return 0; |
| 938 | |
| 939 | phydev->speed = SPEED_UNKNOWN; |
| 940 | phydev->duplex = DUPLEX_UNKNOWN; |
| 941 | phydev->pause = 0; |
| 942 | phydev->asym_pause = 0; |
| 943 | |
| 944 | err = genphy_read_lpa(phydev); |
| 945 | if (err < 0) |
| 946 | return err; |
| 947 | |
| 948 | /* Read the AT8035 PHY-Specific Status register, which indicates the |
| 949 | * speed and duplex that the PHY is actually using, irrespective of |
| 950 | * whether we are in autoneg mode or not. |
| 951 | */ |
| 952 | ss = phy_read(phydev, AT803X_SPECIFIC_STATUS); |
| 953 | if (ss < 0) |
| 954 | return ss; |
| 955 | |
| 956 | if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) { |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 957 | int sfc; |
| 958 | |
| 959 | sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL); |
| 960 | if (sfc < 0) |
| 961 | return sfc; |
| 962 | |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 963 | switch (ss & AT803X_SS_SPEED_MASK) { |
| 964 | case AT803X_SS_SPEED_10: |
| 965 | phydev->speed = SPEED_10; |
| 966 | break; |
| 967 | case AT803X_SS_SPEED_100: |
| 968 | phydev->speed = SPEED_100; |
| 969 | break; |
| 970 | case AT803X_SS_SPEED_1000: |
| 971 | phydev->speed = SPEED_1000; |
| 972 | break; |
| 973 | } |
| 974 | if (ss & AT803X_SS_DUPLEX) |
| 975 | phydev->duplex = DUPLEX_FULL; |
| 976 | else |
| 977 | phydev->duplex = DUPLEX_HALF; |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 978 | |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 979 | if (ss & AT803X_SS_MDIX) |
| 980 | phydev->mdix = ETH_TP_MDI_X; |
| 981 | else |
| 982 | phydev->mdix = ETH_TP_MDI; |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 983 | |
| 984 | switch (FIELD_GET(AT803X_SFC_MDI_CROSSOVER_MODE_M, sfc)) { |
| 985 | case AT803X_SFC_MANUAL_MDI: |
| 986 | phydev->mdix_ctrl = ETH_TP_MDI; |
| 987 | break; |
| 988 | case AT803X_SFC_MANUAL_MDIX: |
| 989 | phydev->mdix_ctrl = ETH_TP_MDI_X; |
| 990 | break; |
| 991 | case AT803X_SFC_AUTOMATIC_CROSSOVER: |
| 992 | phydev->mdix_ctrl = ETH_TP_MDI_AUTO; |
| 993 | break; |
| 994 | } |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) |
| 998 | phy_resolve_aneg_pause(phydev); |
| 999 | |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1003 | static int at803x_config_mdix(struct phy_device *phydev, u8 ctrl) |
| 1004 | { |
| 1005 | u16 val; |
| 1006 | |
| 1007 | switch (ctrl) { |
| 1008 | case ETH_TP_MDI: |
| 1009 | val = AT803X_SFC_MANUAL_MDI; |
| 1010 | break; |
| 1011 | case ETH_TP_MDI_X: |
| 1012 | val = AT803X_SFC_MANUAL_MDIX; |
| 1013 | break; |
| 1014 | case ETH_TP_MDI_AUTO: |
| 1015 | val = AT803X_SFC_AUTOMATIC_CROSSOVER; |
| 1016 | break; |
| 1017 | default: |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
| 1021 | return phy_modify_changed(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL, |
| 1022 | AT803X_SFC_MDI_CROSSOVER_MODE_M, |
| 1023 | FIELD_PREP(AT803X_SFC_MDI_CROSSOVER_MODE_M, val)); |
| 1024 | } |
| 1025 | |
| 1026 | static int at803x_config_aneg(struct phy_device *phydev) |
| 1027 | { |
| 1028 | int ret; |
| 1029 | |
| 1030 | ret = at803x_config_mdix(phydev, phydev->mdix_ctrl); |
| 1031 | if (ret < 0) |
| 1032 | return ret; |
| 1033 | |
| 1034 | /* Changes of the midx bits are disruptive to the normal operation; |
| 1035 | * therefore any changes to these registers must be followed by a |
| 1036 | * software reset to take effect. |
| 1037 | */ |
| 1038 | if (ret == 1) { |
| 1039 | ret = genphy_soft_reset(phydev); |
| 1040 | if (ret < 0) |
| 1041 | return ret; |
| 1042 | } |
| 1043 | |
| 1044 | return genphy_config_aneg(phydev); |
| 1045 | } |
| 1046 | |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1047 | static int at803x_get_downshift(struct phy_device *phydev, u8 *d) |
| 1048 | { |
| 1049 | int val; |
| 1050 | |
| 1051 | val = phy_read(phydev, AT803X_SMART_SPEED); |
| 1052 | if (val < 0) |
| 1053 | return val; |
| 1054 | |
| 1055 | if (val & AT803X_SMART_SPEED_ENABLE) |
| 1056 | *d = FIELD_GET(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, val) + 2; |
| 1057 | else |
| 1058 | *d = DOWNSHIFT_DEV_DISABLE; |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static int at803x_set_downshift(struct phy_device *phydev, u8 cnt) |
| 1064 | { |
| 1065 | u16 mask, set; |
| 1066 | int ret; |
| 1067 | |
| 1068 | switch (cnt) { |
| 1069 | case DOWNSHIFT_DEV_DEFAULT_COUNT: |
| 1070 | cnt = AT803X_DEFAULT_DOWNSHIFT; |
| 1071 | fallthrough; |
| 1072 | case AT803X_MIN_DOWNSHIFT ... AT803X_MAX_DOWNSHIFT: |
| 1073 | set = AT803X_SMART_SPEED_ENABLE | |
| 1074 | AT803X_SMART_SPEED_BYPASS_TIMER | |
| 1075 | FIELD_PREP(AT803X_SMART_SPEED_RETRY_LIMIT_MASK, cnt - 2); |
| 1076 | mask = AT803X_SMART_SPEED_RETRY_LIMIT_MASK; |
| 1077 | break; |
| 1078 | case DOWNSHIFT_DEV_DISABLE: |
| 1079 | set = 0; |
| 1080 | mask = AT803X_SMART_SPEED_ENABLE | |
| 1081 | AT803X_SMART_SPEED_BYPASS_TIMER; |
| 1082 | break; |
| 1083 | default: |
| 1084 | return -EINVAL; |
| 1085 | } |
| 1086 | |
| 1087 | ret = phy_modify_changed(phydev, AT803X_SMART_SPEED, mask, set); |
| 1088 | |
| 1089 | /* After changing the smart speed settings, we need to perform a |
| 1090 | * software reset, use phy_init_hw() to make sure we set the |
| 1091 | * reapply any values which might got lost during software reset. |
| 1092 | */ |
| 1093 | if (ret == 1) |
| 1094 | ret = phy_init_hw(phydev); |
| 1095 | |
| 1096 | return ret; |
| 1097 | } |
| 1098 | |
| 1099 | static int at803x_get_tunable(struct phy_device *phydev, |
| 1100 | struct ethtool_tunable *tuna, void *data) |
| 1101 | { |
| 1102 | switch (tuna->id) { |
| 1103 | case ETHTOOL_PHY_DOWNSHIFT: |
| 1104 | return at803x_get_downshift(phydev, data); |
| 1105 | default: |
| 1106 | return -EOPNOTSUPP; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | static int at803x_set_tunable(struct phy_device *phydev, |
| 1111 | struct ethtool_tunable *tuna, const void *data) |
| 1112 | { |
| 1113 | switch (tuna->id) { |
| 1114 | case ETHTOOL_PHY_DOWNSHIFT: |
| 1115 | return at803x_set_downshift(phydev, *(const u8 *)data); |
| 1116 | default: |
| 1117 | return -EOPNOTSUPP; |
| 1118 | } |
| 1119 | } |
| 1120 | |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1121 | static int at803x_cable_test_result_trans(u16 status) |
| 1122 | { |
| 1123 | switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) { |
| 1124 | case AT803X_CDT_STATUS_STAT_NORMAL: |
| 1125 | return ETHTOOL_A_CABLE_RESULT_CODE_OK; |
| 1126 | case AT803X_CDT_STATUS_STAT_SHORT: |
| 1127 | return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; |
| 1128 | case AT803X_CDT_STATUS_STAT_OPEN: |
| 1129 | return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; |
| 1130 | case AT803X_CDT_STATUS_STAT_FAIL: |
| 1131 | default: |
| 1132 | return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | static bool at803x_cdt_test_failed(u16 status) |
| 1137 | { |
| 1138 | return FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status) == |
| 1139 | AT803X_CDT_STATUS_STAT_FAIL; |
| 1140 | } |
| 1141 | |
| 1142 | static bool at803x_cdt_fault_length_valid(u16 status) |
| 1143 | { |
| 1144 | switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) { |
| 1145 | case AT803X_CDT_STATUS_STAT_OPEN: |
| 1146 | case AT803X_CDT_STATUS_STAT_SHORT: |
| 1147 | return true; |
| 1148 | } |
| 1149 | return false; |
| 1150 | } |
| 1151 | |
| 1152 | static int at803x_cdt_fault_length(u16 status) |
| 1153 | { |
| 1154 | int dt; |
| 1155 | |
| 1156 | /* According to the datasheet the distance to the fault is |
| 1157 | * DELTA_TIME * 0.824 meters. |
| 1158 | * |
| 1159 | * The author suspect the correct formula is: |
| 1160 | * |
| 1161 | * fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2 |
| 1162 | * |
| 1163 | * where c is the speed of light, VF is the velocity factor of |
| 1164 | * the twisted pair cable, 125MHz the counter frequency and |
| 1165 | * we need to divide by 2 because the hardware will measure the |
| 1166 | * round trip time to the fault and back to the PHY. |
| 1167 | * |
| 1168 | * With a VF of 0.69 we get the factor 0.824 mentioned in the |
| 1169 | * datasheet. |
| 1170 | */ |
| 1171 | dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status); |
| 1172 | |
| 1173 | return (dt * 824) / 10; |
| 1174 | } |
| 1175 | |
| 1176 | static int at803x_cdt_start(struct phy_device *phydev, int pair) |
| 1177 | { |
| 1178 | u16 cdt; |
| 1179 | |
| 1180 | cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) | |
| 1181 | AT803X_CDT_ENABLE_TEST; |
| 1182 | |
| 1183 | return phy_write(phydev, AT803X_CDT, cdt); |
| 1184 | } |
| 1185 | |
| 1186 | static int at803x_cdt_wait_for_completion(struct phy_device *phydev) |
| 1187 | { |
| 1188 | int val, ret; |
| 1189 | |
| 1190 | /* One test run takes about 25ms */ |
| 1191 | ret = phy_read_poll_timeout(phydev, AT803X_CDT, val, |
| 1192 | !(val & AT803X_CDT_ENABLE_TEST), |
| 1193 | 30000, 100000, true); |
| 1194 | |
| 1195 | return ret < 0 ? ret : 0; |
| 1196 | } |
| 1197 | |
| 1198 | static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair) |
| 1199 | { |
| 1200 | static const int ethtool_pair[] = { |
| 1201 | ETHTOOL_A_CABLE_PAIR_A, |
| 1202 | ETHTOOL_A_CABLE_PAIR_B, |
| 1203 | ETHTOOL_A_CABLE_PAIR_C, |
| 1204 | ETHTOOL_A_CABLE_PAIR_D, |
| 1205 | }; |
| 1206 | int ret, val; |
| 1207 | |
| 1208 | ret = at803x_cdt_start(phydev, pair); |
| 1209 | if (ret) |
| 1210 | return ret; |
| 1211 | |
| 1212 | ret = at803x_cdt_wait_for_completion(phydev); |
| 1213 | if (ret) |
| 1214 | return ret; |
| 1215 | |
| 1216 | val = phy_read(phydev, AT803X_CDT_STATUS); |
| 1217 | if (val < 0) |
| 1218 | return val; |
| 1219 | |
| 1220 | if (at803x_cdt_test_failed(val)) |
| 1221 | return 0; |
| 1222 | |
| 1223 | ethnl_cable_test_result(phydev, ethtool_pair[pair], |
| 1224 | at803x_cable_test_result_trans(val)); |
| 1225 | |
| 1226 | if (at803x_cdt_fault_length_valid(val)) |
| 1227 | ethnl_cable_test_fault_length(phydev, ethtool_pair[pair], |
| 1228 | at803x_cdt_fault_length(val)); |
| 1229 | |
| 1230 | return 1; |
| 1231 | } |
| 1232 | |
| 1233 | static int at803x_cable_test_get_status(struct phy_device *phydev, |
| 1234 | bool *finished) |
| 1235 | { |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1236 | unsigned long pair_mask; |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1237 | int retries = 20; |
| 1238 | int pair, ret; |
| 1239 | |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1240 | if (phydev->phy_id == ATH9331_PHY_ID || |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame^] | 1241 | phydev->phy_id == ATH8032_PHY_ID || |
| 1242 | phydev->phy_id == QCA9561_PHY_ID) |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1243 | pair_mask = 0x3; |
| 1244 | else |
| 1245 | pair_mask = 0xf; |
| 1246 | |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1247 | *finished = false; |
| 1248 | |
| 1249 | /* According to the datasheet the CDT can be performed when |
| 1250 | * there is no link partner or when the link partner is |
| 1251 | * auto-negotiating. Starting the test will restart the AN |
| 1252 | * automatically. It seems that doing this repeatedly we will |
| 1253 | * get a slot where our link partner won't disturb our |
| 1254 | * measurement. |
| 1255 | */ |
| 1256 | while (pair_mask && retries--) { |
| 1257 | for_each_set_bit(pair, &pair_mask, 4) { |
| 1258 | ret = at803x_cable_test_one_pair(phydev, pair); |
| 1259 | if (ret < 0) |
| 1260 | return ret; |
| 1261 | if (ret) |
| 1262 | clear_bit(pair, &pair_mask); |
| 1263 | } |
| 1264 | if (pair_mask) |
| 1265 | msleep(250); |
| 1266 | } |
| 1267 | |
| 1268 | *finished = true; |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | static int at803x_cable_test_start(struct phy_device *phydev) |
| 1274 | { |
| 1275 | /* Enable auto-negotiation, but advertise no capabilities, no link |
| 1276 | * will be established. A restart of the auto-negotiation is not |
| 1277 | * required, because the cable test will automatically break the link. |
| 1278 | */ |
| 1279 | phy_write(phydev, MII_BMCR, BMCR_ANENABLE); |
| 1280 | phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA); |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1281 | if (phydev->phy_id != ATH9331_PHY_ID && |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame^] | 1282 | phydev->phy_id != ATH8032_PHY_ID && |
| 1283 | phydev->phy_id != QCA9561_PHY_ID) |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1284 | phy_write(phydev, MII_CTRL1000, 0); |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1285 | |
| 1286 | /* we do all the (time consuming) work later */ |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1290 | static int qca83xx_config_init(struct phy_device *phydev) |
| 1291 | { |
| 1292 | u8 switch_revision; |
| 1293 | |
| 1294 | switch_revision = phydev->dev_flags & QCA8K_DEVFLAGS_REVISION_MASK; |
| 1295 | |
| 1296 | switch (switch_revision) { |
| 1297 | case 1: |
| 1298 | /* For 100M waveform */ |
| 1299 | at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_0, 0x02ea); |
| 1300 | /* Turn on Gigabit clock */ |
| 1301 | at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3D, 0x68a0); |
| 1302 | break; |
| 1303 | |
| 1304 | case 2: |
| 1305 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0x0); |
| 1306 | fallthrough; |
| 1307 | case 4: |
| 1308 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_AZ_DEBUG, 0x803f); |
| 1309 | at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3D, 0x6860); |
| 1310 | at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_5, 0x2c46); |
| 1311 | at803x_debug_reg_write(phydev, AT803X_DEBUG_REG_3C, 0x6000); |
| 1312 | break; |
| 1313 | } |
| 1314 | |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
Mugunthan V N | 317420a | 2013-06-03 20:10:04 +0000 | [diff] [blame] | 1318 | static struct phy_driver at803x_driver[] = { |
| 1319 | { |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1320 | /* Qualcomm Atheros AR8035 */ |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 1321 | PHY_ID_MATCH_EXACT(ATH8035_PHY_ID), |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1322 | .name = "Qualcomm Atheros AR8035", |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1323 | .flags = PHY_POLL_CABLE_TEST, |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 1324 | .probe = at803x_probe, |
Michael Walle | 2318ca8 | 2020-01-30 18:54:02 +0100 | [diff] [blame] | 1325 | .remove = at803x_remove, |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1326 | .config_aneg = at803x_config_aneg, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1327 | .config_init = at803x_config_init, |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1328 | .soft_reset = genphy_soft_reset, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1329 | .set_wol = at803x_set_wol, |
| 1330 | .get_wol = at803x_get_wol, |
| 1331 | .suspend = at803x_suspend, |
| 1332 | .resume = at803x_resume, |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 1333 | /* PHY_GBIT_FEATURES */ |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1334 | .read_status = at803x_read_status, |
Måns Rullgård | 0eae598 | 2015-11-12 17:40:20 +0000 | [diff] [blame] | 1335 | .config_intr = at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1336 | .handle_interrupt = at803x_handle_interrupt, |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1337 | .get_tunable = at803x_get_tunable, |
| 1338 | .set_tunable = at803x_set_tunable, |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1339 | .cable_test_start = at803x_cable_test_start, |
| 1340 | .cable_test_get_status = at803x_cable_test_get_status, |
Mugunthan V N | 317420a | 2013-06-03 20:10:04 +0000 | [diff] [blame] | 1341 | }, { |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1342 | /* Qualcomm Atheros AR8030 */ |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1343 | .phy_id = ATH8030_PHY_ID, |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1344 | .name = "Qualcomm Atheros AR8030", |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 1345 | .phy_id_mask = AT8030_PHY_ID_MASK, |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 1346 | .probe = at803x_probe, |
Michael Walle | 2318ca8 | 2020-01-30 18:54:02 +0100 | [diff] [blame] | 1347 | .remove = at803x_remove, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1348 | .config_init = at803x_config_init, |
| 1349 | .link_change_notify = at803x_link_change_notify, |
| 1350 | .set_wol = at803x_set_wol, |
| 1351 | .get_wol = at803x_get_wol, |
| 1352 | .suspend = at803x_suspend, |
| 1353 | .resume = at803x_resume, |
Heiner Kallweit | dcdecdc | 2019-04-12 20:47:03 +0200 | [diff] [blame] | 1354 | /* PHY_BASIC_FEATURES */ |
Måns Rullgård | 0eae598 | 2015-11-12 17:40:20 +0000 | [diff] [blame] | 1355 | .config_intr = at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1356 | .handle_interrupt = at803x_handle_interrupt, |
Mugunthan V N | 05d7cce | 2013-06-03 20:10:07 +0000 | [diff] [blame] | 1357 | }, { |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1358 | /* Qualcomm Atheros AR8031/AR8033 */ |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 1359 | PHY_ID_MATCH_EXACT(ATH8031_PHY_ID), |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1360 | .name = "Qualcomm Atheros AR8031/AR8033", |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1361 | .flags = PHY_POLL_CABLE_TEST, |
Michael Walle | 2f66482 | 2019-11-06 23:36:14 +0100 | [diff] [blame] | 1362 | .probe = at803x_probe, |
Michael Walle | 2318ca8 | 2020-01-30 18:54:02 +0100 | [diff] [blame] | 1363 | .remove = at803x_remove, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1364 | .config_init = at803x_config_init, |
Michael Walle | 63477a5 | 2021-02-14 02:17:11 +0100 | [diff] [blame] | 1365 | .config_aneg = at803x_config_aneg, |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1366 | .soft_reset = genphy_soft_reset, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1367 | .set_wol = at803x_set_wol, |
| 1368 | .get_wol = at803x_get_wol, |
| 1369 | .suspend = at803x_suspend, |
| 1370 | .resume = at803x_resume, |
David Bauer | c329e5a | 2021-04-15 03:26:50 +0200 | [diff] [blame] | 1371 | .read_page = at803x_read_page, |
| 1372 | .write_page = at803x_write_page, |
David Bauer | b856150 | 2021-06-27 12:16:07 +0200 | [diff] [blame] | 1373 | .get_features = at803x_get_features, |
Russell King | 06d5f34 | 2019-10-04 17:06:14 +0100 | [diff] [blame] | 1374 | .read_status = at803x_read_status, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 1375 | .config_intr = &at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1376 | .handle_interrupt = at803x_handle_interrupt, |
Michael Walle | cde0f4f | 2020-04-28 23:15:02 +0200 | [diff] [blame] | 1377 | .get_tunable = at803x_get_tunable, |
| 1378 | .set_tunable = at803x_set_tunable, |
Michael Walle | 6cb7576 | 2020-05-13 22:38:07 +0200 | [diff] [blame] | 1379 | .cable_test_start = at803x_cable_test_start, |
| 1380 | .cable_test_get_status = at803x_cable_test_get_status, |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1381 | }, { |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1382 | /* Qualcomm Atheros AR8032 */ |
| 1383 | PHY_ID_MATCH_EXACT(ATH8032_PHY_ID), |
| 1384 | .name = "Qualcomm Atheros AR8032", |
| 1385 | .probe = at803x_probe, |
| 1386 | .remove = at803x_remove, |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1387 | .flags = PHY_POLL_CABLE_TEST, |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1388 | .config_init = at803x_config_init, |
| 1389 | .link_change_notify = at803x_link_change_notify, |
| 1390 | .set_wol = at803x_set_wol, |
| 1391 | .get_wol = at803x_get_wol, |
| 1392 | .suspend = at803x_suspend, |
| 1393 | .resume = at803x_resume, |
| 1394 | /* PHY_BASIC_FEATURES */ |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1395 | .config_intr = at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1396 | .handle_interrupt = at803x_handle_interrupt, |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1397 | .cable_test_start = at803x_cable_test_start, |
| 1398 | .cable_test_get_status = at803x_cable_test_get_status, |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1399 | }, { |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1400 | /* ATHEROS AR9331 */ |
| 1401 | PHY_ID_MATCH_EXACT(ATH9331_PHY_ID), |
Michael Walle | 96c3671 | 2019-11-06 23:36:16 +0100 | [diff] [blame] | 1402 | .name = "Qualcomm Atheros AR9331 built-in PHY", |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1403 | .suspend = at803x_suspend, |
| 1404 | .resume = at803x_resume, |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1405 | .flags = PHY_POLL_CABLE_TEST, |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1406 | /* PHY_BASIC_FEATURES */ |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1407 | .config_intr = &at803x_config_intr, |
Ioana Ciornei | 2977309 | 2020-11-01 14:50:59 +0200 | [diff] [blame] | 1408 | .handle_interrupt = at803x_handle_interrupt, |
Oleksij Rempel | dc0f3ed | 2020-05-27 07:08:43 +0200 | [diff] [blame] | 1409 | .cable_test_start = at803x_cable_test_start, |
| 1410 | .cable_test_get_status = at803x_cable_test_get_status, |
Oleksij Rempel | 7dce80c | 2020-07-19 10:05:30 +0200 | [diff] [blame] | 1411 | .read_status = at803x_read_status, |
| 1412 | .soft_reset = genphy_soft_reset, |
| 1413 | .config_aneg = at803x_config_aneg, |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1414 | }, { |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame^] | 1415 | /* Qualcomm Atheros QCA9561 */ |
| 1416 | PHY_ID_MATCH_EXACT(QCA9561_PHY_ID), |
| 1417 | .name = "Qualcomm Atheros QCA9561 built-in PHY", |
| 1418 | .suspend = at803x_suspend, |
| 1419 | .resume = at803x_resume, |
| 1420 | .flags = PHY_POLL_CABLE_TEST, |
| 1421 | /* PHY_BASIC_FEATURES */ |
| 1422 | .config_intr = &at803x_config_intr, |
| 1423 | .handle_interrupt = at803x_handle_interrupt, |
| 1424 | .cable_test_start = at803x_cable_test_start, |
| 1425 | .cable_test_get_status = at803x_cable_test_get_status, |
| 1426 | .read_status = at803x_read_status, |
| 1427 | .soft_reset = genphy_soft_reset, |
| 1428 | .config_aneg = at803x_config_aneg, |
| 1429 | }, { |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1430 | /* QCA8337 */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 1431 | .phy_id = QCA8337_PHY_ID, |
| 1432 | .phy_id_mask = QCA8K_PHY_ID_MASK, |
| 1433 | .name = "Qualcomm Atheros 8337 internal PHY", |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1434 | /* PHY_GBIT_FEATURES */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 1435 | .probe = at803x_probe, |
| 1436 | .flags = PHY_IS_INTERNAL, |
| 1437 | .config_init = qca83xx_config_init, |
| 1438 | .soft_reset = genphy_soft_reset, |
| 1439 | .get_sset_count = at803x_get_sset_count, |
| 1440 | .get_strings = at803x_get_strings, |
| 1441 | .get_stats = at803x_get_stats, |
Ansuel Smith | 15b9df4 | 2021-09-19 18:28:16 +0200 | [diff] [blame] | 1442 | .suspend = genphy_suspend, |
| 1443 | .resume = genphy_resume, |
Ansuel Smith | 0ccf851 | 2021-09-14 14:33:45 +0200 | [diff] [blame] | 1444 | }, { |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 1445 | /* QCA8327-A from switch QCA8327-AL1A */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 1446 | .phy_id = QCA8327_A_PHY_ID, |
| 1447 | .phy_id_mask = QCA8K_PHY_ID_MASK, |
| 1448 | .name = "Qualcomm Atheros 8327-A internal PHY", |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 1449 | /* PHY_GBIT_FEATURES */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 1450 | .probe = at803x_probe, |
| 1451 | .flags = PHY_IS_INTERNAL, |
| 1452 | .config_init = qca83xx_config_init, |
| 1453 | .soft_reset = genphy_soft_reset, |
| 1454 | .get_sset_count = at803x_get_sset_count, |
| 1455 | .get_strings = at803x_get_strings, |
| 1456 | .get_stats = at803x_get_stats, |
Ansuel Smith | 15b9df4 | 2021-09-19 18:28:16 +0200 | [diff] [blame] | 1457 | .suspend = genphy_suspend, |
| 1458 | .resume = genphy_resume, |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 1459 | }, { |
| 1460 | /* QCA8327-B from switch QCA8327-BL1A */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 1461 | .phy_id = QCA8327_B_PHY_ID, |
| 1462 | .phy_id_mask = QCA8K_PHY_ID_MASK, |
| 1463 | .name = "Qualcomm Atheros 8327-B internal PHY", |
Ansuel Smith | 0ccf851 | 2021-09-14 14:33:45 +0200 | [diff] [blame] | 1464 | /* PHY_GBIT_FEATURES */ |
Ansuel Smith | d44fd86 | 2021-09-19 18:28:17 +0200 | [diff] [blame] | 1465 | .probe = at803x_probe, |
| 1466 | .flags = PHY_IS_INTERNAL, |
| 1467 | .config_init = qca83xx_config_init, |
| 1468 | .soft_reset = genphy_soft_reset, |
| 1469 | .get_sset_count = at803x_get_sset_count, |
| 1470 | .get_strings = at803x_get_strings, |
| 1471 | .get_stats = at803x_get_stats, |
Ansuel Smith | 15b9df4 | 2021-09-19 18:28:16 +0200 | [diff] [blame] | 1472 | .suspend = genphy_suspend, |
| 1473 | .resume = genphy_resume, |
Ansuel Smith | 272833b | 2021-05-14 23:00:15 +0200 | [diff] [blame] | 1474 | }, }; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 1475 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 1476 | module_phy_driver(at803x_driver); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 1477 | |
| 1478 | static struct mdio_device_id __maybe_unused atheros_tbl[] = { |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 1479 | { ATH8030_PHY_ID, AT8030_PHY_ID_MASK }, |
| 1480 | { PHY_ID_MATCH_EXACT(ATH8031_PHY_ID) }, |
David Bauer | 5800091 | 2020-04-17 15:41:59 +0200 | [diff] [blame] | 1481 | { PHY_ID_MATCH_EXACT(ATH8032_PHY_ID) }, |
Michael Walle | 0465d8f | 2020-05-22 11:53:31 +0200 | [diff] [blame] | 1482 | { PHY_ID_MATCH_EXACT(ATH8035_PHY_ID) }, |
Oleksij Rempel | 7908d2c | 2019-10-03 10:21:12 +0200 | [diff] [blame] | 1483 | { PHY_ID_MATCH_EXACT(ATH9331_PHY_ID) }, |
Ansuel Smith | 0ccf851 | 2021-09-14 14:33:45 +0200 | [diff] [blame] | 1484 | { PHY_ID_MATCH_EXACT(QCA8337_PHY_ID) }, |
Ansuel Smith | b4df02b | 2021-09-19 18:28:15 +0200 | [diff] [blame] | 1485 | { PHY_ID_MATCH_EXACT(QCA8327_A_PHY_ID) }, |
| 1486 | { PHY_ID_MATCH_EXACT(QCA8327_B_PHY_ID) }, |
David Bauer | fada2ce | 2021-10-06 00:54:01 +0200 | [diff] [blame^] | 1487 | { PHY_ID_MATCH_EXACT(QCA9561_PHY_ID) }, |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 1488 | { } |
| 1489 | }; |
| 1490 | |
| 1491 | MODULE_DEVICE_TABLE(mdio, atheros_tbl); |