Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Microsemi VSC85xx PHYs |
| 3 | * |
| 4 | * Author: Nagaraju Lakkaraju |
| 5 | * License: Dual MIT/GPL |
| 6 | * Copyright (c) 2016 Microsemi Corporation |
| 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/mdio.h> |
| 12 | #include <linux/mii.h> |
| 13 | #include <linux/phy.h> |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 14 | #include <linux/of.h> |
Raju Lakkaraju | 0a55c12 | 2016-10-05 14:19:27 +0530 | [diff] [blame] | 15 | #include <linux/netdevice.h> |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 16 | |
| 17 | enum rgmii_rx_clock_delay { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 18 | RGMII_RX_CLK_DELAY_0_2_NS = 0, |
| 19 | RGMII_RX_CLK_DELAY_0_8_NS = 1, |
| 20 | RGMII_RX_CLK_DELAY_1_1_NS = 2, |
| 21 | RGMII_RX_CLK_DELAY_1_7_NS = 3, |
| 22 | RGMII_RX_CLK_DELAY_2_0_NS = 4, |
| 23 | RGMII_RX_CLK_DELAY_2_3_NS = 5, |
| 24 | RGMII_RX_CLK_DELAY_2_6_NS = 6, |
| 25 | RGMII_RX_CLK_DELAY_3_4_NS = 7 |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 26 | }; |
| 27 | |
Raju Lakkaraju | 1a21101 | 2016-09-19 15:33:54 +0530 | [diff] [blame] | 28 | /* Microsemi VSC85xx PHY registers */ |
| 29 | /* IEEE 802. Std Registers */ |
| 30 | #define MSCC_PHY_EXT_PHY_CNTL_1 23 |
| 31 | #define MAC_IF_SELECTION_MASK 0x1800 |
| 32 | #define MAC_IF_SELECTION_GMII 0 |
| 33 | #define MAC_IF_SELECTION_RMII 1 |
| 34 | #define MAC_IF_SELECTION_RGMII 2 |
| 35 | #define MAC_IF_SELECTION_POS 11 |
| 36 | #define FAR_END_LOOPBACK_MODE_MASK 0x0008 |
| 37 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 38 | #define MII_VSC85XX_INT_MASK 25 |
| 39 | #define MII_VSC85XX_INT_MASK_MASK 0xa000 |
Raju Lakkaraju | 0a55c12 | 2016-10-05 14:19:27 +0530 | [diff] [blame] | 40 | #define MII_VSC85XX_INT_MASK_WOL 0x0040 |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 41 | #define MII_VSC85XX_INT_STATUS 26 |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 42 | |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 43 | #define MSCC_PHY_WOL_MAC_CONTROL 27 |
| 44 | #define EDGE_RATE_CNTL_POS 5 |
| 45 | #define EDGE_RATE_CNTL_MASK 0x00E0 |
| 46 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 47 | #define MSCC_EXT_PAGE_ACCESS 31 |
| 48 | #define MSCC_PHY_PAGE_STANDARD 0x0000 /* Standard registers */ |
| 49 | #define MSCC_PHY_PAGE_EXTENDED_2 0x0002 /* Extended reg - page 2 */ |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 50 | |
| 51 | /* Extended Page 2 Registers */ |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 52 | #define MSCC_PHY_RGMII_CNTL 20 |
| 53 | #define RGMII_RX_CLK_DELAY_MASK 0x0070 |
| 54 | #define RGMII_RX_CLK_DELAY_POS 4 |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 55 | |
Raju Lakkaraju | 0a55c12 | 2016-10-05 14:19:27 +0530 | [diff] [blame] | 56 | #define MSCC_PHY_WOL_LOWER_MAC_ADDR 21 |
| 57 | #define MSCC_PHY_WOL_MID_MAC_ADDR 22 |
| 58 | #define MSCC_PHY_WOL_UPPER_MAC_ADDR 23 |
| 59 | #define MSCC_PHY_WOL_LOWER_PASSWD 24 |
| 60 | #define MSCC_PHY_WOL_MID_PASSWD 25 |
| 61 | #define MSCC_PHY_WOL_UPPER_PASSWD 26 |
| 62 | |
| 63 | #define MSCC_PHY_WOL_MAC_CONTROL 27 |
| 64 | #define SECURE_ON_ENABLE 0x8000 |
| 65 | #define SECURE_ON_PASSWD_LEN_4 0x4000 |
| 66 | |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 67 | /* Microsemi PHY ID's */ |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 68 | #define PHY_ID_VSC8531 0x00070570 |
| 69 | #define PHY_ID_VSC8541 0x00070770 |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 70 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 71 | #define MSCC_VDDMAC_1500 1500 |
| 72 | #define MSCC_VDDMAC_1800 1800 |
| 73 | #define MSCC_VDDMAC_2500 2500 |
| 74 | #define MSCC_VDDMAC_3300 3300 |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 75 | |
| 76 | struct vsc8531_private { |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 77 | int rate_magic; |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 78 | }; |
| 79 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 80 | #ifdef CONFIG_OF_MDIO |
| 81 | struct vsc8531_edge_rate_table { |
| 82 | u16 vddmac; |
| 83 | u8 slowdown[8]; |
| 84 | }; |
| 85 | |
| 86 | static const struct vsc8531_edge_rate_table edge_table[] = { |
| 87 | {MSCC_VDDMAC_3300, { 0, 2, 4, 7, 10, 17, 29, 53} }, |
| 88 | {MSCC_VDDMAC_2500, { 0, 3, 6, 10, 14, 23, 37, 63} }, |
| 89 | {MSCC_VDDMAC_1800, { 0, 5, 9, 16, 23, 35, 52, 76} }, |
| 90 | {MSCC_VDDMAC_1500, { 0, 6, 14, 21, 29, 42, 58, 77} }, |
| 91 | }; |
| 92 | #endif /* CONFIG_OF_MDIO */ |
| 93 | |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 94 | static int vsc85xx_phy_page_set(struct phy_device *phydev, u8 page) |
| 95 | { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 96 | int rc; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 97 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 98 | rc = phy_write(phydev, MSCC_EXT_PAGE_ACCESS, page); |
| 99 | return rc; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 100 | } |
| 101 | |
Raju Lakkaraju | 0a55c12 | 2016-10-05 14:19:27 +0530 | [diff] [blame] | 102 | static int vsc85xx_wol_set(struct phy_device *phydev, |
| 103 | struct ethtool_wolinfo *wol) |
| 104 | { |
| 105 | int rc; |
| 106 | u16 reg_val; |
| 107 | u8 i; |
| 108 | u16 pwd[3] = {0, 0, 0}; |
| 109 | struct ethtool_wolinfo *wol_conf = wol; |
| 110 | u8 *mac_addr = phydev->attached_dev->dev_addr; |
| 111 | |
| 112 | mutex_lock(&phydev->lock); |
| 113 | rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED_2); |
| 114 | if (rc != 0) |
| 115 | goto out_unlock; |
| 116 | |
| 117 | if (wol->wolopts & WAKE_MAGIC) { |
| 118 | /* Store the device address for the magic packet */ |
| 119 | for (i = 0; i < ARRAY_SIZE(pwd); i++) |
| 120 | pwd[i] = mac_addr[5 - (i * 2 + 1)] << 8 | |
| 121 | mac_addr[5 - i * 2]; |
| 122 | phy_write(phydev, MSCC_PHY_WOL_LOWER_MAC_ADDR, pwd[0]); |
| 123 | phy_write(phydev, MSCC_PHY_WOL_MID_MAC_ADDR, pwd[1]); |
| 124 | phy_write(phydev, MSCC_PHY_WOL_UPPER_MAC_ADDR, pwd[2]); |
| 125 | } else { |
| 126 | phy_write(phydev, MSCC_PHY_WOL_LOWER_MAC_ADDR, 0); |
| 127 | phy_write(phydev, MSCC_PHY_WOL_MID_MAC_ADDR, 0); |
| 128 | phy_write(phydev, MSCC_PHY_WOL_UPPER_MAC_ADDR, 0); |
| 129 | } |
| 130 | |
| 131 | if (wol_conf->wolopts & WAKE_MAGICSECURE) { |
| 132 | for (i = 0; i < ARRAY_SIZE(pwd); i++) |
| 133 | pwd[i] = wol_conf->sopass[5 - (i * 2 + 1)] << 8 | |
| 134 | wol_conf->sopass[5 - i * 2]; |
| 135 | phy_write(phydev, MSCC_PHY_WOL_LOWER_PASSWD, pwd[0]); |
| 136 | phy_write(phydev, MSCC_PHY_WOL_MID_PASSWD, pwd[1]); |
| 137 | phy_write(phydev, MSCC_PHY_WOL_UPPER_PASSWD, pwd[2]); |
| 138 | } else { |
| 139 | phy_write(phydev, MSCC_PHY_WOL_LOWER_PASSWD, 0); |
| 140 | phy_write(phydev, MSCC_PHY_WOL_MID_PASSWD, 0); |
| 141 | phy_write(phydev, MSCC_PHY_WOL_UPPER_PASSWD, 0); |
| 142 | } |
| 143 | |
| 144 | reg_val = phy_read(phydev, MSCC_PHY_WOL_MAC_CONTROL); |
| 145 | if (wol_conf->wolopts & WAKE_MAGICSECURE) |
| 146 | reg_val |= SECURE_ON_ENABLE; |
| 147 | else |
| 148 | reg_val &= ~SECURE_ON_ENABLE; |
| 149 | phy_write(phydev, MSCC_PHY_WOL_MAC_CONTROL, reg_val); |
| 150 | |
| 151 | rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_STANDARD); |
| 152 | if (rc != 0) |
| 153 | goto out_unlock; |
| 154 | |
| 155 | if (wol->wolopts & WAKE_MAGIC) { |
| 156 | /* Enable the WOL interrupt */ |
| 157 | reg_val = phy_read(phydev, MII_VSC85XX_INT_MASK); |
| 158 | reg_val |= MII_VSC85XX_INT_MASK_WOL; |
| 159 | rc = phy_write(phydev, MII_VSC85XX_INT_MASK, reg_val); |
| 160 | if (rc != 0) |
| 161 | goto out_unlock; |
| 162 | } else { |
| 163 | /* Disable the WOL interrupt */ |
| 164 | reg_val = phy_read(phydev, MII_VSC85XX_INT_MASK); |
| 165 | reg_val &= (~MII_VSC85XX_INT_MASK_WOL); |
| 166 | rc = phy_write(phydev, MII_VSC85XX_INT_MASK, reg_val); |
| 167 | if (rc != 0) |
| 168 | goto out_unlock; |
| 169 | } |
| 170 | /* Clear WOL iterrupt status */ |
| 171 | reg_val = phy_read(phydev, MII_VSC85XX_INT_STATUS); |
| 172 | |
| 173 | out_unlock: |
| 174 | mutex_unlock(&phydev->lock); |
| 175 | |
| 176 | return rc; |
| 177 | } |
| 178 | |
| 179 | static void vsc85xx_wol_get(struct phy_device *phydev, |
| 180 | struct ethtool_wolinfo *wol) |
| 181 | { |
| 182 | int rc; |
| 183 | u16 reg_val; |
| 184 | u8 i; |
| 185 | u16 pwd[3] = {0, 0, 0}; |
| 186 | struct ethtool_wolinfo *wol_conf = wol; |
| 187 | |
| 188 | mutex_lock(&phydev->lock); |
| 189 | rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED_2); |
| 190 | if (rc != 0) |
| 191 | goto out_unlock; |
| 192 | |
| 193 | reg_val = phy_read(phydev, MSCC_PHY_WOL_MAC_CONTROL); |
| 194 | if (reg_val & SECURE_ON_ENABLE) |
| 195 | wol_conf->wolopts |= WAKE_MAGICSECURE; |
| 196 | if (wol_conf->wolopts & WAKE_MAGICSECURE) { |
| 197 | pwd[0] = phy_read(phydev, MSCC_PHY_WOL_LOWER_PASSWD); |
| 198 | pwd[1] = phy_read(phydev, MSCC_PHY_WOL_MID_PASSWD); |
| 199 | pwd[2] = phy_read(phydev, MSCC_PHY_WOL_UPPER_PASSWD); |
| 200 | for (i = 0; i < ARRAY_SIZE(pwd); i++) { |
| 201 | wol_conf->sopass[5 - i * 2] = pwd[i] & 0x00ff; |
| 202 | wol_conf->sopass[5 - (i * 2 + 1)] = (pwd[i] & 0xff00) |
| 203 | >> 8; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_STANDARD); |
| 208 | |
| 209 | out_unlock: |
| 210 | mutex_unlock(&phydev->lock); |
| 211 | } |
| 212 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 213 | #ifdef CONFIG_OF_MDIO |
| 214 | static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev) |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 215 | { |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 216 | u8 sd; |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 217 | u16 vdd; |
| 218 | int rc, i, j; |
| 219 | struct device *dev = &phydev->mdio.dev; |
| 220 | struct device_node *of_node = dev->of_node; |
| 221 | u8 sd_array_size = ARRAY_SIZE(edge_table[0].slowdown); |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 222 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 223 | if (!of_node) |
| 224 | return -ENODEV; |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 225 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 226 | rc = of_property_read_u16(of_node, "vsc8531,vddmac", &vdd); |
| 227 | if (rc != 0) |
| 228 | vdd = MSCC_VDDMAC_3300; |
| 229 | |
| 230 | rc = of_property_read_u8(of_node, "vsc8531,edge-slowdown", &sd); |
| 231 | if (rc != 0) |
| 232 | sd = 0; |
| 233 | |
| 234 | for (i = 0; i < ARRAY_SIZE(edge_table); i++) |
| 235 | if (edge_table[i].vddmac == vdd) |
| 236 | for (j = 0; j < sd_array_size; j++) |
| 237 | if (edge_table[i].slowdown[j] == sd) |
| 238 | return (sd_array_size - j - 1); |
| 239 | |
| 240 | return -EINVAL; |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 241 | } |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 242 | #else |
| 243 | static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev) |
| 244 | { |
| 245 | return 0; |
| 246 | } |
| 247 | #endif /* CONFIG_OF_MDIO */ |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 248 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 249 | static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev, u8 edge_rate) |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 250 | { |
| 251 | int rc; |
| 252 | u16 reg_val; |
| 253 | |
| 254 | mutex_lock(&phydev->lock); |
| 255 | rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED_2); |
| 256 | if (rc != 0) |
| 257 | goto out_unlock; |
| 258 | reg_val = phy_read(phydev, MSCC_PHY_WOL_MAC_CONTROL); |
| 259 | reg_val &= ~(EDGE_RATE_CNTL_MASK); |
| 260 | reg_val |= (edge_rate << EDGE_RATE_CNTL_POS); |
| 261 | rc = phy_write(phydev, MSCC_PHY_WOL_MAC_CONTROL, reg_val); |
| 262 | if (rc != 0) |
| 263 | goto out_unlock; |
| 264 | rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_STANDARD); |
| 265 | |
| 266 | out_unlock: |
| 267 | mutex_unlock(&phydev->lock); |
| 268 | |
| 269 | return rc; |
| 270 | } |
| 271 | |
Raju Lakkaraju | 1a21101 | 2016-09-19 15:33:54 +0530 | [diff] [blame] | 272 | static int vsc85xx_mac_if_set(struct phy_device *phydev, |
| 273 | phy_interface_t interface) |
| 274 | { |
| 275 | int rc; |
| 276 | u16 reg_val; |
| 277 | |
| 278 | mutex_lock(&phydev->lock); |
| 279 | reg_val = phy_read(phydev, MSCC_PHY_EXT_PHY_CNTL_1); |
| 280 | reg_val &= ~(MAC_IF_SELECTION_MASK); |
| 281 | switch (interface) { |
| 282 | case PHY_INTERFACE_MODE_RGMII: |
| 283 | reg_val |= (MAC_IF_SELECTION_RGMII << MAC_IF_SELECTION_POS); |
| 284 | break; |
| 285 | case PHY_INTERFACE_MODE_RMII: |
| 286 | reg_val |= (MAC_IF_SELECTION_RMII << MAC_IF_SELECTION_POS); |
| 287 | break; |
| 288 | case PHY_INTERFACE_MODE_MII: |
| 289 | case PHY_INTERFACE_MODE_GMII: |
| 290 | reg_val |= (MAC_IF_SELECTION_GMII << MAC_IF_SELECTION_POS); |
| 291 | break; |
| 292 | default: |
| 293 | rc = -EINVAL; |
| 294 | goto out_unlock; |
| 295 | } |
| 296 | rc = phy_write(phydev, MSCC_PHY_EXT_PHY_CNTL_1, reg_val); |
| 297 | if (rc != 0) |
| 298 | goto out_unlock; |
| 299 | |
| 300 | rc = genphy_soft_reset(phydev); |
| 301 | |
| 302 | out_unlock: |
| 303 | mutex_unlock(&phydev->lock); |
| 304 | |
| 305 | return rc; |
| 306 | } |
| 307 | |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 308 | static int vsc85xx_default_config(struct phy_device *phydev) |
| 309 | { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 310 | int rc; |
| 311 | u16 reg_val; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 312 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 313 | mutex_lock(&phydev->lock); |
| 314 | rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED_2); |
| 315 | if (rc != 0) |
| 316 | goto out_unlock; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 317 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 318 | reg_val = phy_read(phydev, MSCC_PHY_RGMII_CNTL); |
| 319 | reg_val &= ~(RGMII_RX_CLK_DELAY_MASK); |
| 320 | reg_val |= (RGMII_RX_CLK_DELAY_1_1_NS << RGMII_RX_CLK_DELAY_POS); |
| 321 | phy_write(phydev, MSCC_PHY_RGMII_CNTL, reg_val); |
| 322 | rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_STANDARD); |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 323 | |
| 324 | out_unlock: |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 325 | mutex_unlock(&phydev->lock); |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 326 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 327 | return rc; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static int vsc85xx_config_init(struct phy_device *phydev) |
| 331 | { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 332 | int rc; |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 333 | struct vsc8531_private *vsc8531 = phydev->priv; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 334 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 335 | rc = vsc85xx_default_config(phydev); |
| 336 | if (rc) |
| 337 | return rc; |
Raju Lakkaraju | 1a21101 | 2016-09-19 15:33:54 +0530 | [diff] [blame] | 338 | |
| 339 | rc = vsc85xx_mac_if_set(phydev, phydev->interface); |
| 340 | if (rc) |
| 341 | return rc; |
| 342 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 343 | rc = vsc85xx_edge_rate_cntl_set(phydev, vsc8531->rate_magic); |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 344 | if (rc) |
| 345 | return rc; |
| 346 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 347 | rc = genphy_config_init(phydev); |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 348 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 349 | return rc; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static int vsc85xx_ack_interrupt(struct phy_device *phydev) |
| 353 | { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 354 | int rc = 0; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 355 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 356 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) |
| 357 | rc = phy_read(phydev, MII_VSC85XX_INT_STATUS); |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 358 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 359 | return (rc < 0) ? rc : 0; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static int vsc85xx_config_intr(struct phy_device *phydev) |
| 363 | { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 364 | int rc; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 365 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 366 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { |
| 367 | rc = phy_write(phydev, MII_VSC85XX_INT_MASK, |
| 368 | MII_VSC85XX_INT_MASK_MASK); |
| 369 | } else { |
| 370 | rc = phy_write(phydev, MII_VSC85XX_INT_MASK, 0); |
| 371 | if (rc < 0) |
| 372 | return rc; |
| 373 | rc = phy_read(phydev, MII_VSC85XX_INT_STATUS); |
| 374 | } |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 375 | |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 376 | return rc; |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 377 | } |
| 378 | |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 379 | static int vsc85xx_probe(struct phy_device *phydev) |
| 380 | { |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 381 | int rate_magic; |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 382 | struct vsc8531_private *vsc8531; |
| 383 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 384 | rate_magic = vsc85xx_edge_rate_magic_get(phydev); |
| 385 | if (rate_magic < 0) |
| 386 | return rate_magic; |
| 387 | |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 388 | vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); |
| 389 | if (!vsc8531) |
| 390 | return -ENOMEM; |
| 391 | |
| 392 | phydev->priv = vsc8531; |
| 393 | |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 394 | vsc8531->rate_magic = rate_magic; |
| 395 | |
Raju Lakkaraju | a4cc96d | 2016-10-03 12:53:13 +0530 | [diff] [blame] | 396 | return 0; |
| 397 | } |
| 398 | |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 399 | /* Microsemi VSC85xx PHYs */ |
| 400 | static struct phy_driver vsc85xx_driver[] = { |
| 401 | { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 402 | .phy_id = PHY_ID_VSC8531, |
| 403 | .name = "Microsemi VSC8531", |
| 404 | .phy_id_mask = 0xfffffff0, |
| 405 | .features = PHY_GBIT_FEATURES, |
| 406 | .flags = PHY_HAS_INTERRUPT, |
| 407 | .soft_reset = &genphy_soft_reset, |
| 408 | .config_init = &vsc85xx_config_init, |
| 409 | .config_aneg = &genphy_config_aneg, |
| 410 | .aneg_done = &genphy_aneg_done, |
| 411 | .read_status = &genphy_read_status, |
| 412 | .ack_interrupt = &vsc85xx_ack_interrupt, |
| 413 | .config_intr = &vsc85xx_config_intr, |
| 414 | .suspend = &genphy_suspend, |
| 415 | .resume = &genphy_resume, |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 416 | .probe = &vsc85xx_probe, |
| 417 | .set_wol = &vsc85xx_wol_set, |
| 418 | .get_wol = &vsc85xx_wol_get, |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 419 | }, |
| 420 | { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 421 | .phy_id = PHY_ID_VSC8541, |
| 422 | .name = "Microsemi VSC8541 SyncE", |
| 423 | .phy_id_mask = 0xfffffff0, |
| 424 | .features = PHY_GBIT_FEATURES, |
| 425 | .flags = PHY_HAS_INTERRUPT, |
| 426 | .soft_reset = &genphy_soft_reset, |
| 427 | .config_init = &vsc85xx_config_init, |
| 428 | .config_aneg = &genphy_config_aneg, |
| 429 | .aneg_done = &genphy_aneg_done, |
| 430 | .read_status = &genphy_read_status, |
| 431 | .ack_interrupt = &vsc85xx_ack_interrupt, |
| 432 | .config_intr = &vsc85xx_config_intr, |
| 433 | .suspend = &genphy_suspend, |
| 434 | .resume = &genphy_resume, |
Allan W. Nielsen | 4f58e6d | 2016-10-12 15:47:51 +0200 | [diff] [blame^] | 435 | .probe = &vsc85xx_probe, |
| 436 | .set_wol = &vsc85xx_wol_set, |
| 437 | .get_wol = &vsc85xx_wol_get, |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | }; |
| 441 | |
| 442 | module_phy_driver(vsc85xx_driver); |
| 443 | |
| 444 | static struct mdio_device_id __maybe_unused vsc85xx_tbl[] = { |
Raju Lakkaraju | 4ffd03f | 2016-09-08 14:09:31 +0530 | [diff] [blame] | 445 | { PHY_ID_VSC8531, 0xfffffff0, }, |
| 446 | { PHY_ID_VSC8541, 0xfffffff0, }, |
| 447 | { } |
Raju Lakkaraju | d50736a | 2016-08-05 17:54:21 +0530 | [diff] [blame] | 448 | }; |
| 449 | |
| 450 | MODULE_DEVICE_TABLE(mdio, vsc85xx_tbl); |
| 451 | |
| 452 | MODULE_DESCRIPTION("Microsemi VSC85xx PHY driver"); |
| 453 | MODULE_AUTHOR("Nagaraju Lakkaraju"); |
| 454 | MODULE_LICENSE("Dual MIT/GPL"); |