Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/phy/at803x.c |
| 3 | * |
| 4 | * Driver for Atheros 803x PHY |
| 5 | * |
| 6 | * Author: Matus Ujhelyi <ujhelyi.m@gmail.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/phy.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/netdevice.h> |
| 18 | #include <linux/etherdevice.h> |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 19 | #include <linux/of_gpio.h> |
| 20 | #include <linux/gpio/consumer.h> |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 21 | |
| 22 | #define AT803X_INTR_ENABLE 0x12 |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame^] | 23 | #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15) |
| 24 | #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14) |
| 25 | #define AT803X_INTR_ENABLE_DUPLEX_CHANGED BIT(13) |
| 26 | #define AT803X_INTR_ENABLE_PAGE_RECEIVED BIT(12) |
| 27 | #define AT803X_INTR_ENABLE_LINK_FAIL BIT(11) |
| 28 | #define AT803X_INTR_ENABLE_LINK_SUCCESS BIT(10) |
| 29 | #define AT803X_INTR_ENABLE_WIRESPEED_DOWNGRADE BIT(5) |
| 30 | #define AT803X_INTR_ENABLE_POLARITY_CHANGED BIT(1) |
| 31 | #define AT803X_INTR_ENABLE_WOL BIT(0) |
| 32 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 33 | #define AT803X_INTR_STATUS 0x13 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 34 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 35 | #define AT803X_SMART_SPEED 0x14 |
| 36 | #define AT803X_LED_CONTROL 0x18 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 37 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 38 | #define AT803X_DEVICE_ADDR 0x03 |
| 39 | #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C |
| 40 | #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B |
| 41 | #define AT803X_LOC_MAC_ADDR_32_47_OFFSET 0x804A |
| 42 | #define AT803X_MMD_ACCESS_CONTROL 0x0D |
| 43 | #define AT803X_MMD_ACCESS_CONTROL_DATA 0x0E |
| 44 | #define AT803X_FUNC_DATA 0x4003 |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 45 | |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 46 | #define AT803X_DEBUG_ADDR 0x1D |
| 47 | #define AT803X_DEBUG_DATA 0x1E |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 48 | |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 49 | #define AT803X_DEBUG_REG_0 0x00 |
| 50 | #define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15) |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 51 | |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 52 | #define AT803X_DEBUG_REG_5 0x05 |
| 53 | #define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8) |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 54 | |
Daniel Mack | bd8ca17 | 2014-06-18 11:01:42 +0200 | [diff] [blame] | 55 | #define ATH8030_PHY_ID 0x004dd076 |
| 56 | #define ATH8031_PHY_ID 0x004dd074 |
| 57 | #define ATH8035_PHY_ID 0x004dd072 |
| 58 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 59 | MODULE_DESCRIPTION("Atheros 803x PHY driver"); |
| 60 | MODULE_AUTHOR("Matus Ujhelyi"); |
| 61 | MODULE_LICENSE("GPL"); |
| 62 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 63 | struct at803x_priv { |
| 64 | bool phy_reset:1; |
| 65 | struct gpio_desc *gpiod_reset; |
| 66 | }; |
| 67 | |
| 68 | struct at803x_context { |
| 69 | u16 bmcr; |
| 70 | u16 advertise; |
| 71 | u16 control1000; |
| 72 | u16 int_enable; |
| 73 | u16 smart_speed; |
| 74 | u16 led_control; |
| 75 | }; |
| 76 | |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 77 | static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg) |
| 78 | { |
| 79 | int ret; |
| 80 | |
| 81 | ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg); |
| 82 | if (ret < 0) |
| 83 | return ret; |
| 84 | |
| 85 | return phy_read(phydev, AT803X_DEBUG_DATA); |
| 86 | } |
| 87 | |
| 88 | static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg, |
| 89 | u16 clear, u16 set) |
| 90 | { |
| 91 | u16 val; |
| 92 | int ret; |
| 93 | |
| 94 | ret = at803x_debug_reg_read(phydev, reg); |
| 95 | if (ret < 0) |
| 96 | return ret; |
| 97 | |
| 98 | val = ret & 0xffff; |
| 99 | val &= ~clear; |
| 100 | val |= set; |
| 101 | |
| 102 | return phy_write(phydev, AT803X_DEBUG_DATA, val); |
| 103 | } |
| 104 | |
| 105 | static inline int at803x_enable_rx_delay(struct phy_device *phydev) |
| 106 | { |
| 107 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0, |
| 108 | AT803X_DEBUG_RX_CLK_DLY_EN); |
| 109 | } |
| 110 | |
| 111 | static inline int at803x_enable_tx_delay(struct phy_device *phydev) |
| 112 | { |
| 113 | return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0, |
| 114 | AT803X_DEBUG_TX_CLK_DLY_EN); |
| 115 | } |
| 116 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 117 | /* save relevant PHY registers to private copy */ |
| 118 | static void at803x_context_save(struct phy_device *phydev, |
| 119 | struct at803x_context *context) |
| 120 | { |
| 121 | context->bmcr = phy_read(phydev, MII_BMCR); |
| 122 | context->advertise = phy_read(phydev, MII_ADVERTISE); |
| 123 | context->control1000 = phy_read(phydev, MII_CTRL1000); |
| 124 | context->int_enable = phy_read(phydev, AT803X_INTR_ENABLE); |
| 125 | context->smart_speed = phy_read(phydev, AT803X_SMART_SPEED); |
| 126 | context->led_control = phy_read(phydev, AT803X_LED_CONTROL); |
| 127 | } |
| 128 | |
| 129 | /* restore relevant PHY registers from private copy */ |
| 130 | static void at803x_context_restore(struct phy_device *phydev, |
| 131 | const struct at803x_context *context) |
| 132 | { |
| 133 | phy_write(phydev, MII_BMCR, context->bmcr); |
| 134 | phy_write(phydev, MII_ADVERTISE, context->advertise); |
| 135 | phy_write(phydev, MII_CTRL1000, context->control1000); |
| 136 | phy_write(phydev, AT803X_INTR_ENABLE, context->int_enable); |
| 137 | phy_write(phydev, AT803X_SMART_SPEED, context->smart_speed); |
| 138 | phy_write(phydev, AT803X_LED_CONTROL, context->led_control); |
| 139 | } |
| 140 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 141 | static int at803x_set_wol(struct phy_device *phydev, |
| 142 | struct ethtool_wolinfo *wol) |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 143 | { |
| 144 | struct net_device *ndev = phydev->attached_dev; |
| 145 | const u8 *mac; |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 146 | int ret; |
| 147 | u32 value; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 148 | unsigned int i, offsets[] = { |
| 149 | AT803X_LOC_MAC_ADDR_32_47_OFFSET, |
| 150 | AT803X_LOC_MAC_ADDR_16_31_OFFSET, |
| 151 | AT803X_LOC_MAC_ADDR_0_15_OFFSET, |
| 152 | }; |
| 153 | |
| 154 | if (!ndev) |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 155 | return -ENODEV; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 156 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 157 | if (wol->wolopts & WAKE_MAGIC) { |
| 158 | mac = (const u8 *) ndev->dev_addr; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 159 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 160 | if (!is_valid_ether_addr(mac)) |
| 161 | return -EFAULT; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 162 | |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 163 | for (i = 0; i < 3; i++) { |
| 164 | phy_write(phydev, AT803X_MMD_ACCESS_CONTROL, |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 165 | AT803X_DEVICE_ADDR); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 166 | phy_write(phydev, AT803X_MMD_ACCESS_CONTROL_DATA, |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 167 | offsets[i]); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 168 | phy_write(phydev, AT803X_MMD_ACCESS_CONTROL, |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 169 | AT803X_FUNC_DATA); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 170 | phy_write(phydev, AT803X_MMD_ACCESS_CONTROL_DATA, |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 171 | mac[(i * 2) + 1] | (mac[(i * 2)] << 8)); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame^] | 175 | value |= AT803X_INTR_ENABLE_WOL; |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 176 | ret = phy_write(phydev, AT803X_INTR_ENABLE, value); |
| 177 | if (ret) |
| 178 | return ret; |
| 179 | value = phy_read(phydev, AT803X_INTR_STATUS); |
| 180 | } else { |
| 181 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame^] | 182 | value &= (~AT803X_INTR_ENABLE_WOL); |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 183 | ret = phy_write(phydev, AT803X_INTR_ENABLE, value); |
| 184 | if (ret) |
| 185 | return ret; |
| 186 | value = phy_read(phydev, AT803X_INTR_STATUS); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 187 | } |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | |
| 192 | static void at803x_get_wol(struct phy_device *phydev, |
| 193 | struct ethtool_wolinfo *wol) |
| 194 | { |
| 195 | u32 value; |
| 196 | |
| 197 | wol->supported = WAKE_MAGIC; |
| 198 | wol->wolopts = 0; |
| 199 | |
| 200 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame^] | 201 | if (value & AT803X_INTR_ENABLE_WOL) |
Mugunthan V N | ea13c9e | 2013-06-03 20:10:05 +0000 | [diff] [blame] | 202 | wol->wolopts |= WAKE_MAGIC; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 205 | static int at803x_suspend(struct phy_device *phydev) |
| 206 | { |
| 207 | int value; |
| 208 | int wol_enabled; |
| 209 | |
| 210 | mutex_lock(&phydev->lock); |
| 211 | |
| 212 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame^] | 213 | wol_enabled = value & AT803X_INTR_ENABLE_WOL; |
Daniel Mack | 6229ed1 | 2013-09-21 16:53:02 +0200 | [diff] [blame] | 214 | |
| 215 | value = phy_read(phydev, MII_BMCR); |
| 216 | |
| 217 | if (wol_enabled) |
| 218 | value |= BMCR_ISOLATE; |
| 219 | else |
| 220 | value |= BMCR_PDOWN; |
| 221 | |
| 222 | phy_write(phydev, MII_BMCR, value); |
| 223 | |
| 224 | mutex_unlock(&phydev->lock); |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static int at803x_resume(struct phy_device *phydev) |
| 230 | { |
| 231 | int value; |
| 232 | |
| 233 | mutex_lock(&phydev->lock); |
| 234 | |
| 235 | value = phy_read(phydev, MII_BMCR); |
| 236 | value &= ~(BMCR_PDOWN | BMCR_ISOLATE); |
| 237 | phy_write(phydev, MII_BMCR, value); |
| 238 | |
| 239 | mutex_unlock(&phydev->lock); |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 244 | static int at803x_probe(struct phy_device *phydev) |
| 245 | { |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 246 | struct device *dev = &phydev->mdio.dev; |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 247 | struct at803x_priv *priv; |
Uwe Kleine-König | 687908c | 2015-03-31 22:08:45 +0200 | [diff] [blame] | 248 | struct gpio_desc *gpiod_reset; |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 249 | |
Fengguang Wu | 8f2877c | 2014-06-22 12:32:51 +0200 | [diff] [blame] | 250 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 251 | if (!priv) |
| 252 | return -ENOMEM; |
| 253 | |
Uwe Kleine-König | 687908c | 2015-03-31 22:08:45 +0200 | [diff] [blame] | 254 | gpiod_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); |
| 255 | if (IS_ERR(gpiod_reset)) |
| 256 | return PTR_ERR(gpiod_reset); |
| 257 | |
| 258 | priv->gpiod_reset = gpiod_reset; |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 259 | |
| 260 | phydev->priv = priv; |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 265 | static int at803x_config_init(struct phy_device *phydev) |
| 266 | { |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 267 | int ret; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 268 | |
Daniel Mack | 6ff01db | 2014-04-16 17:19:13 +0200 | [diff] [blame] | 269 | ret = genphy_config_init(phydev); |
| 270 | if (ret < 0) |
| 271 | return ret; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 272 | |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 273 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID || |
| 274 | phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { |
| 275 | ret = at803x_enable_rx_delay(phydev); |
| 276 | if (ret < 0) |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 277 | return ret; |
Martin Blumenstingl | 2e5f9f2 | 2016-01-15 01:55:22 +0100 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID || |
| 281 | phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { |
| 282 | ret = at803x_enable_tx_delay(phydev); |
| 283 | if (ret < 0) |
Mugunthan V N | 1ca6d1b | 2013-06-03 20:10:06 +0000 | [diff] [blame] | 284 | return ret; |
| 285 | } |
| 286 | |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 290 | static int at803x_ack_interrupt(struct phy_device *phydev) |
| 291 | { |
| 292 | int err; |
| 293 | |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 294 | err = phy_read(phydev, AT803X_INTR_STATUS); |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 295 | |
| 296 | return (err < 0) ? err : 0; |
| 297 | } |
| 298 | |
| 299 | static int at803x_config_intr(struct phy_device *phydev) |
| 300 | { |
| 301 | int err; |
| 302 | int value; |
| 303 | |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 304 | value = phy_read(phydev, AT803X_INTR_ENABLE); |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 305 | |
Martin Blumenstingl | e6e4a55 | 2016-01-15 01:55:24 +0100 | [diff] [blame^] | 306 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { |
| 307 | value |= AT803X_INTR_ENABLE_AUTONEG_ERR; |
| 308 | value |= AT803X_INTR_ENABLE_SPEED_CHANGED; |
| 309 | value |= AT803X_INTR_ENABLE_DUPLEX_CHANGED; |
| 310 | value |= AT803X_INTR_ENABLE_LINK_FAIL; |
| 311 | value |= AT803X_INTR_ENABLE_LINK_SUCCESS; |
| 312 | |
| 313 | err = phy_write(phydev, AT803X_INTR_ENABLE, value); |
| 314 | } |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 315 | else |
Martin Blumenstingl | a46bd63 | 2016-01-15 01:55:23 +0100 | [diff] [blame] | 316 | err = phy_write(phydev, AT803X_INTR_ENABLE, 0); |
Zhao Qiang | 77a9939 | 2014-03-28 15:39:41 +0800 | [diff] [blame] | 317 | |
| 318 | return err; |
| 319 | } |
| 320 | |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 321 | static void at803x_link_change_notify(struct phy_device *phydev) |
| 322 | { |
| 323 | struct at803x_priv *priv = phydev->priv; |
| 324 | |
| 325 | /* |
| 326 | * Conduct a hardware reset for AT8030 every time a link loss is |
| 327 | * signalled. This is necessary to circumvent a hardware bug that |
| 328 | * occurs when the cable is unplugged while TX packets are pending |
| 329 | * in the FIFO. In such cases, the FIFO enters an error mode it |
| 330 | * cannot recover from by software. |
| 331 | */ |
| 332 | if (phydev->drv->phy_id == ATH8030_PHY_ID) { |
| 333 | if (phydev->state == PHY_NOLINK) { |
| 334 | if (priv->gpiod_reset && !priv->phy_reset) { |
| 335 | struct at803x_context context; |
| 336 | |
| 337 | at803x_context_save(phydev, &context); |
| 338 | |
| 339 | gpiod_set_value(priv->gpiod_reset, 0); |
| 340 | msleep(1); |
| 341 | gpiod_set_value(priv->gpiod_reset, 1); |
| 342 | msleep(1); |
| 343 | |
| 344 | at803x_context_restore(phydev, &context); |
| 345 | |
Andrew Lunn | 72ba48b | 2016-01-06 20:11:09 +0100 | [diff] [blame] | 346 | phydev_dbg(phydev, "%s(): phy was reset\n", |
| 347 | __func__); |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 348 | priv->phy_reset = true; |
| 349 | } |
| 350 | } else { |
| 351 | priv->phy_reset = false; |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
Mugunthan V N | 317420a | 2013-06-03 20:10:04 +0000 | [diff] [blame] | 356 | static struct phy_driver at803x_driver[] = { |
| 357 | { |
| 358 | /* ATHEROS 8035 */ |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 359 | .phy_id = ATH8035_PHY_ID, |
| 360 | .name = "Atheros 8035 ethernet", |
| 361 | .phy_id_mask = 0xffffffef, |
| 362 | .probe = at803x_probe, |
| 363 | .config_init = at803x_config_init, |
| 364 | .link_change_notify = at803x_link_change_notify, |
| 365 | .set_wol = at803x_set_wol, |
| 366 | .get_wol = at803x_get_wol, |
| 367 | .suspend = at803x_suspend, |
| 368 | .resume = at803x_resume, |
| 369 | .features = PHY_GBIT_FEATURES, |
| 370 | .flags = PHY_HAS_INTERRUPT, |
| 371 | .config_aneg = genphy_config_aneg, |
| 372 | .read_status = genphy_read_status, |
Måns Rullgård | 0eae598 | 2015-11-12 17:40:20 +0000 | [diff] [blame] | 373 | .ack_interrupt = at803x_ack_interrupt, |
| 374 | .config_intr = at803x_config_intr, |
Mugunthan V N | 317420a | 2013-06-03 20:10:04 +0000 | [diff] [blame] | 375 | }, { |
| 376 | /* ATHEROS 8030 */ |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 377 | .phy_id = ATH8030_PHY_ID, |
| 378 | .name = "Atheros 8030 ethernet", |
| 379 | .phy_id_mask = 0xffffffef, |
| 380 | .probe = at803x_probe, |
| 381 | .config_init = at803x_config_init, |
| 382 | .link_change_notify = at803x_link_change_notify, |
| 383 | .set_wol = at803x_set_wol, |
| 384 | .get_wol = at803x_get_wol, |
| 385 | .suspend = at803x_suspend, |
| 386 | .resume = at803x_resume, |
Martin Blumenstingl | e15bb4c | 2016-01-15 01:55:21 +0100 | [diff] [blame] | 387 | .features = PHY_BASIC_FEATURES, |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 388 | .flags = PHY_HAS_INTERRUPT, |
| 389 | .config_aneg = genphy_config_aneg, |
| 390 | .read_status = genphy_read_status, |
Måns Rullgård | 0eae598 | 2015-11-12 17:40:20 +0000 | [diff] [blame] | 391 | .ack_interrupt = at803x_ack_interrupt, |
| 392 | .config_intr = at803x_config_intr, |
Mugunthan V N | 05d7cce | 2013-06-03 20:10:07 +0000 | [diff] [blame] | 393 | }, { |
| 394 | /* ATHEROS 8031 */ |
Daniel Mack | 13a56b4 | 2014-06-18 11:01:43 +0200 | [diff] [blame] | 395 | .phy_id = ATH8031_PHY_ID, |
| 396 | .name = "Atheros 8031 ethernet", |
| 397 | .phy_id_mask = 0xffffffef, |
| 398 | .probe = at803x_probe, |
| 399 | .config_init = at803x_config_init, |
| 400 | .link_change_notify = at803x_link_change_notify, |
| 401 | .set_wol = at803x_set_wol, |
| 402 | .get_wol = at803x_get_wol, |
| 403 | .suspend = at803x_suspend, |
| 404 | .resume = at803x_resume, |
| 405 | .features = PHY_GBIT_FEATURES, |
| 406 | .flags = PHY_HAS_INTERRUPT, |
| 407 | .config_aneg = genphy_config_aneg, |
| 408 | .read_status = genphy_read_status, |
| 409 | .ack_interrupt = &at803x_ack_interrupt, |
| 410 | .config_intr = &at803x_config_intr, |
Mugunthan V N | 317420a | 2013-06-03 20:10:04 +0000 | [diff] [blame] | 411 | } }; |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 412 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 413 | module_phy_driver(at803x_driver); |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 414 | |
| 415 | static struct mdio_device_id __maybe_unused atheros_tbl[] = { |
Daniel Mack | bd8ca17 | 2014-06-18 11:01:42 +0200 | [diff] [blame] | 416 | { ATH8030_PHY_ID, 0xffffffef }, |
| 417 | { ATH8031_PHY_ID, 0xffffffef }, |
| 418 | { ATH8035_PHY_ID, 0xffffffef }, |
Matus Ujhelyi | 0ca7111 | 2012-10-14 19:07:16 +0000 | [diff] [blame] | 419 | { } |
| 420 | }; |
| 421 | |
| 422 | MODULE_DEVICE_TABLE(mdio, atheros_tbl); |