Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Broadcom Starfighter 2 DSA switch driver |
| 3 | * |
| 4 | * Copyright (C) 2014, Broadcom Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/list.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/of.h> |
| 18 | #include <linux/phy.h> |
| 19 | #include <linux/phy_fixed.h> |
| 20 | #include <linux/mii.h> |
| 21 | #include <linux/of.h> |
| 22 | #include <linux/of_irq.h> |
| 23 | #include <linux/of_address.h> |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 24 | #include <linux/of_net.h> |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 25 | #include <linux/of_mdio.h> |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 26 | #include <net/dsa.h> |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 27 | #include <linux/ethtool.h> |
Florian Fainelli | 12f460f | 2015-02-24 13:15:34 -0800 | [diff] [blame] | 28 | #include <linux/if_bridge.h> |
Florian Fainelli | aafc66f | 2015-06-10 18:08:01 -0700 | [diff] [blame] | 29 | #include <linux/brcmphy.h> |
Florian Fainelli | 680060d | 2015-10-23 11:38:07 -0700 | [diff] [blame] | 30 | #include <linux/etherdevice.h> |
| 31 | #include <net/switchdev.h> |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 32 | #include <linux/platform_data/b53.h> |
Florian Fainelli | 2399d61 | 2016-10-20 09:32:19 -0700 | [diff] [blame] | 33 | #include <linux/kexec.h> |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 34 | |
| 35 | #include "bcm_sf2.h" |
| 36 | #include "bcm_sf2_regs.h" |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 37 | #include "b53/b53_priv.h" |
| 38 | #include "b53/b53_regs.h" |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 39 | |
Andrew Lunn | 7b31436 | 2016-08-22 16:01:01 +0200 | [diff] [blame] | 40 | static enum dsa_tag_protocol bcm_sf2_sw_get_tag_protocol(struct dsa_switch *ds) |
| 41 | { |
| 42 | return DSA_TAG_PROTO_BRCM; |
| 43 | } |
| 44 | |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 45 | static void bcm_sf2_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 46 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 47 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 48 | unsigned int i; |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 49 | u32 reg; |
| 50 | |
| 51 | /* Enable the IMP Port to be in the same VLAN as the other ports |
| 52 | * on a per-port basis such that we only have Port i and IMP in |
| 53 | * the same VLAN. |
| 54 | */ |
| 55 | for (i = 0; i < priv->hw_params.num_ports; i++) { |
Andrew Lunn | 74c3e2a | 2016-04-13 02:40:44 +0200 | [diff] [blame] | 56 | if (!((1 << i) & ds->enabled_port_mask)) |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 57 | continue; |
| 58 | |
| 59 | reg = core_readl(priv, CORE_PORT_VLAN_CTL_PORT(i)); |
| 60 | reg |= (1 << cpu_port); |
| 61 | core_writel(priv, reg, CORE_PORT_VLAN_CTL_PORT(i)); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port) |
| 66 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 67 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 68 | u32 reg, val; |
| 69 | |
| 70 | /* Enable the port memories */ |
| 71 | reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL); |
| 72 | reg &= ~P_TXQ_PSM_VDD(port); |
| 73 | core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL); |
| 74 | |
| 75 | /* Enable Broadcast, Multicast, Unicast forwarding to IMP port */ |
| 76 | reg = core_readl(priv, CORE_IMP_CTL); |
| 77 | reg |= (RX_BCST_EN | RX_MCST_EN | RX_UCST_EN); |
| 78 | reg &= ~(RX_DIS | TX_DIS); |
| 79 | core_writel(priv, reg, CORE_IMP_CTL); |
| 80 | |
| 81 | /* Enable forwarding */ |
| 82 | core_writel(priv, SW_FWDG_EN, CORE_SWMODE); |
| 83 | |
| 84 | /* Enable IMP port in dumb mode */ |
| 85 | reg = core_readl(priv, CORE_SWITCH_CTRL); |
| 86 | reg |= MII_DUMB_FWDG_EN; |
| 87 | core_writel(priv, reg, CORE_SWITCH_CTRL); |
| 88 | |
| 89 | /* Resolve which bit controls the Broadcom tag */ |
| 90 | switch (port) { |
| 91 | case 8: |
| 92 | val = BRCM_HDR_EN_P8; |
| 93 | break; |
| 94 | case 7: |
| 95 | val = BRCM_HDR_EN_P7; |
| 96 | break; |
| 97 | case 5: |
| 98 | val = BRCM_HDR_EN_P5; |
| 99 | break; |
| 100 | default: |
| 101 | val = 0; |
| 102 | break; |
| 103 | } |
| 104 | |
| 105 | /* Enable Broadcom tags for IMP port */ |
| 106 | reg = core_readl(priv, CORE_BRCM_HDR_CTRL); |
| 107 | reg |= val; |
| 108 | core_writel(priv, reg, CORE_BRCM_HDR_CTRL); |
| 109 | |
| 110 | /* Enable reception Broadcom tag for CPU TX (switch RX) to |
| 111 | * allow us to tag outgoing frames |
| 112 | */ |
| 113 | reg = core_readl(priv, CORE_BRCM_HDR_RX_DIS); |
| 114 | reg &= ~(1 << port); |
| 115 | core_writel(priv, reg, CORE_BRCM_HDR_RX_DIS); |
| 116 | |
| 117 | /* Enable transmission of Broadcom tags from the switch (CPU RX) to |
| 118 | * allow delivering frames to the per-port net_devices |
| 119 | */ |
| 120 | reg = core_readl(priv, CORE_BRCM_HDR_TX_DIS); |
| 121 | reg &= ~(1 << port); |
| 122 | core_writel(priv, reg, CORE_BRCM_HDR_TX_DIS); |
| 123 | |
| 124 | /* Force link status for IMP port */ |
| 125 | reg = core_readl(priv, CORE_STS_OVERRIDE_IMP); |
| 126 | reg |= (MII_SW_OR | LINK_STS); |
| 127 | core_writel(priv, reg, CORE_STS_OVERRIDE_IMP); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 130 | static void bcm_sf2_eee_enable_set(struct dsa_switch *ds, int port, bool enable) |
| 131 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 132 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 133 | u32 reg; |
| 134 | |
| 135 | reg = core_readl(priv, CORE_EEE_EN_CTRL); |
| 136 | if (enable) |
| 137 | reg |= 1 << port; |
| 138 | else |
| 139 | reg &= ~(1 << port); |
| 140 | core_writel(priv, reg, CORE_EEE_EN_CTRL); |
| 141 | } |
| 142 | |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 143 | static void bcm_sf2_gphy_enable_set(struct dsa_switch *ds, bool enable) |
| 144 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 145 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 146 | u32 reg; |
| 147 | |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 148 | reg = reg_readl(priv, REG_SPHY_CNTRL); |
| 149 | if (enable) { |
| 150 | reg |= PHY_RESET; |
| 151 | reg &= ~(EXT_PWR_DOWN | IDDQ_BIAS | CK25_DIS); |
| 152 | reg_writel(priv, reg, REG_SPHY_CNTRL); |
| 153 | udelay(21); |
| 154 | reg = reg_readl(priv, REG_SPHY_CNTRL); |
| 155 | reg &= ~PHY_RESET; |
| 156 | } else { |
| 157 | reg |= EXT_PWR_DOWN | IDDQ_BIAS | PHY_RESET; |
| 158 | reg_writel(priv, reg, REG_SPHY_CNTRL); |
| 159 | mdelay(1); |
| 160 | reg |= CK25_DIS; |
| 161 | } |
| 162 | reg_writel(priv, reg, REG_SPHY_CNTRL); |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 163 | |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 164 | /* Use PHY-driven LED signaling */ |
| 165 | if (!enable) { |
| 166 | reg = reg_readl(priv, REG_LED_CNTRL(0)); |
| 167 | reg |= SPDLNK_SRC_SEL; |
| 168 | reg_writel(priv, reg, REG_LED_CNTRL(0)); |
| 169 | } |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 172 | static inline void bcm_sf2_port_intr_enable(struct bcm_sf2_priv *priv, |
| 173 | int port) |
| 174 | { |
| 175 | unsigned int off; |
| 176 | |
| 177 | switch (port) { |
| 178 | case 7: |
| 179 | off = P7_IRQ_OFF; |
| 180 | break; |
| 181 | case 0: |
| 182 | /* Port 0 interrupts are located on the first bank */ |
| 183 | intrl2_0_mask_clear(priv, P_IRQ_MASK(P0_IRQ_OFF)); |
| 184 | return; |
| 185 | default: |
| 186 | off = P_IRQ_OFF(port); |
| 187 | break; |
| 188 | } |
| 189 | |
| 190 | intrl2_1_mask_clear(priv, P_IRQ_MASK(off)); |
| 191 | } |
| 192 | |
| 193 | static inline void bcm_sf2_port_intr_disable(struct bcm_sf2_priv *priv, |
| 194 | int port) |
| 195 | { |
| 196 | unsigned int off; |
| 197 | |
| 198 | switch (port) { |
| 199 | case 7: |
| 200 | off = P7_IRQ_OFF; |
| 201 | break; |
| 202 | case 0: |
| 203 | /* Port 0 interrupts are located on the first bank */ |
| 204 | intrl2_0_mask_set(priv, P_IRQ_MASK(P0_IRQ_OFF)); |
| 205 | intrl2_0_writel(priv, P_IRQ_MASK(P0_IRQ_OFF), INTRL2_CPU_CLEAR); |
| 206 | return; |
| 207 | default: |
| 208 | off = P_IRQ_OFF(port); |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | intrl2_1_mask_set(priv, P_IRQ_MASK(off)); |
| 213 | intrl2_1_writel(priv, P_IRQ_MASK(off), INTRL2_CPU_CLEAR); |
| 214 | } |
| 215 | |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 216 | static int bcm_sf2_port_setup(struct dsa_switch *ds, int port, |
| 217 | struct phy_device *phy) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 218 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 219 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 220 | s8 cpu_port = ds->dst[ds->index].cpu_port; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 221 | u32 reg; |
| 222 | |
| 223 | /* Clear the memory power down */ |
| 224 | reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL); |
| 225 | reg &= ~P_TXQ_PSM_VDD(port); |
| 226 | core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL); |
| 227 | |
| 228 | /* Clear the Rx and Tx disable bits and set to no spanning tree */ |
| 229 | core_writel(priv, 0, CORE_G_PCTL_PORT(port)); |
| 230 | |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 231 | /* Re-enable the GPHY and re-apply workarounds */ |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 232 | if (priv->int_phy_mask & 1 << port && priv->hw_params.num_gphy == 1) { |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 233 | bcm_sf2_gphy_enable_set(ds, true); |
| 234 | if (phy) { |
| 235 | /* if phy_stop() has been called before, phy |
| 236 | * will be in halted state, and phy_start() |
| 237 | * will call resume. |
| 238 | * |
| 239 | * the resume path does not configure back |
| 240 | * autoneg settings, and since we hard reset |
| 241 | * the phy manually here, we need to reset the |
| 242 | * state machine also. |
| 243 | */ |
| 244 | phy->state = PHY_READY; |
| 245 | phy_init_hw(phy); |
| 246 | } |
| 247 | } |
| 248 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 249 | /* Enable MoCA port interrupts to get notified */ |
| 250 | if (port == priv->moca_port) |
| 251 | bcm_sf2_port_intr_enable(priv, port); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 252 | |
Florian Fainelli | 12f460f | 2015-02-24 13:15:34 -0800 | [diff] [blame] | 253 | /* Set this port, and only this one to be in the default VLAN, |
| 254 | * if member of a bridge, restore its membership prior to |
| 255 | * bringing down this port. |
| 256 | */ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 257 | reg = core_readl(priv, CORE_PORT_VLAN_CTL_PORT(port)); |
| 258 | reg &= ~PORT_VLAN_CTRL_MASK; |
| 259 | reg |= (1 << port); |
Florian Fainelli | 0215492 | 2016-09-10 12:39:03 -0700 | [diff] [blame] | 260 | reg |= priv->dev->ports[port].vlan_ctl_mask; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 261 | core_writel(priv, reg, CORE_PORT_VLAN_CTL_PORT(port)); |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 262 | |
| 263 | bcm_sf2_imp_vlan_setup(ds, cpu_port); |
| 264 | |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 265 | /* If EEE was enabled, restore it */ |
| 266 | if (priv->port_sts[port].eee.eee_enabled) |
| 267 | bcm_sf2_eee_enable_set(ds, port, true); |
| 268 | |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 269 | return 0; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 272 | static void bcm_sf2_port_disable(struct dsa_switch *ds, int port, |
| 273 | struct phy_device *phy) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 274 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 275 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 276 | u32 off, reg; |
| 277 | |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 278 | if (priv->wol_ports_mask & (1 << port)) |
| 279 | return; |
| 280 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 281 | if (port == priv->moca_port) |
| 282 | bcm_sf2_port_intr_disable(priv, port); |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 283 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 284 | if (priv->int_phy_mask & 1 << port && priv->hw_params.num_gphy == 1) |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 285 | bcm_sf2_gphy_enable_set(ds, false); |
| 286 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 287 | if (dsa_is_cpu_port(ds, port)) |
| 288 | off = CORE_IMP_CTL; |
| 289 | else |
| 290 | off = CORE_G_PCTL_PORT(port); |
| 291 | |
| 292 | reg = core_readl(priv, off); |
| 293 | reg |= RX_DIS | TX_DIS; |
| 294 | core_writel(priv, reg, off); |
| 295 | |
| 296 | /* Power down the port memory */ |
| 297 | reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL); |
| 298 | reg |= P_TXQ_PSM_VDD(port); |
| 299 | core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL); |
| 300 | } |
| 301 | |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 302 | /* Returns 0 if EEE was not enabled, or 1 otherwise |
| 303 | */ |
| 304 | static int bcm_sf2_eee_init(struct dsa_switch *ds, int port, |
| 305 | struct phy_device *phy) |
| 306 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 307 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 308 | struct ethtool_eee *p = &priv->port_sts[port].eee; |
| 309 | int ret; |
| 310 | |
| 311 | p->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_100baseT_Full); |
| 312 | |
| 313 | ret = phy_init_eee(phy, 0); |
| 314 | if (ret) |
| 315 | return 0; |
| 316 | |
| 317 | bcm_sf2_eee_enable_set(ds, port, true); |
| 318 | |
| 319 | return 1; |
| 320 | } |
| 321 | |
| 322 | static int bcm_sf2_sw_get_eee(struct dsa_switch *ds, int port, |
| 323 | struct ethtool_eee *e) |
| 324 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 325 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 326 | struct ethtool_eee *p = &priv->port_sts[port].eee; |
| 327 | u32 reg; |
| 328 | |
| 329 | reg = core_readl(priv, CORE_EEE_LPI_INDICATE); |
| 330 | e->eee_enabled = p->eee_enabled; |
| 331 | e->eee_active = !!(reg & (1 << port)); |
| 332 | |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | static int bcm_sf2_sw_set_eee(struct dsa_switch *ds, int port, |
| 337 | struct phy_device *phydev, |
| 338 | struct ethtool_eee *e) |
| 339 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 340 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 341 | struct ethtool_eee *p = &priv->port_sts[port].eee; |
| 342 | |
| 343 | p->eee_enabled = e->eee_enabled; |
| 344 | |
| 345 | if (!p->eee_enabled) { |
| 346 | bcm_sf2_eee_enable_set(ds, port, false); |
| 347 | } else { |
| 348 | p->eee_enabled = bcm_sf2_eee_init(ds, port, phydev); |
| 349 | if (!p->eee_enabled) |
| 350 | return -EOPNOTSUPP; |
| 351 | } |
| 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 356 | static int bcm_sf2_sw_indir_rw(struct bcm_sf2_priv *priv, int op, int addr, |
| 357 | int regnum, u16 val) |
| 358 | { |
| 359 | int ret = 0; |
| 360 | u32 reg; |
| 361 | |
| 362 | reg = reg_readl(priv, REG_SWITCH_CNTRL); |
| 363 | reg |= MDIO_MASTER_SEL; |
| 364 | reg_writel(priv, reg, REG_SWITCH_CNTRL); |
| 365 | |
| 366 | /* Page << 8 | offset */ |
| 367 | reg = 0x70; |
| 368 | reg <<= 2; |
| 369 | core_writel(priv, addr, reg); |
| 370 | |
| 371 | /* Page << 8 | offset */ |
| 372 | reg = 0x80 << 8 | regnum << 1; |
| 373 | reg <<= 2; |
| 374 | |
| 375 | if (op) |
| 376 | ret = core_readl(priv, reg); |
| 377 | else |
| 378 | core_writel(priv, val, reg); |
| 379 | |
| 380 | reg = reg_readl(priv, REG_SWITCH_CNTRL); |
| 381 | reg &= ~MDIO_MASTER_SEL; |
| 382 | reg_writel(priv, reg, REG_SWITCH_CNTRL); |
| 383 | |
| 384 | return ret & 0xffff; |
| 385 | } |
| 386 | |
| 387 | static int bcm_sf2_sw_mdio_read(struct mii_bus *bus, int addr, int regnum) |
| 388 | { |
| 389 | struct bcm_sf2_priv *priv = bus->priv; |
| 390 | |
| 391 | /* Intercept reads from Broadcom pseudo-PHY address, else, send |
| 392 | * them to our master MDIO bus controller |
| 393 | */ |
| 394 | if (addr == BRCM_PSEUDO_PHY_ADDR && priv->indir_phy_mask & BIT(addr)) |
| 395 | return bcm_sf2_sw_indir_rw(priv, 1, addr, regnum, 0); |
| 396 | else |
| 397 | return mdiobus_read(priv->master_mii_bus, addr, regnum); |
| 398 | } |
| 399 | |
| 400 | static int bcm_sf2_sw_mdio_write(struct mii_bus *bus, int addr, int regnum, |
| 401 | u16 val) |
| 402 | { |
| 403 | struct bcm_sf2_priv *priv = bus->priv; |
| 404 | |
| 405 | /* Intercept writes to the Broadcom pseudo-PHY address, else, |
| 406 | * send them to our master MDIO bus controller |
| 407 | */ |
| 408 | if (addr == BRCM_PSEUDO_PHY_ADDR && priv->indir_phy_mask & BIT(addr)) |
| 409 | bcm_sf2_sw_indir_rw(priv, 0, addr, regnum, val); |
| 410 | else |
| 411 | mdiobus_write(priv->master_mii_bus, addr, regnum, val); |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 416 | static irqreturn_t bcm_sf2_switch_0_isr(int irq, void *dev_id) |
| 417 | { |
| 418 | struct bcm_sf2_priv *priv = dev_id; |
| 419 | |
| 420 | priv->irq0_stat = intrl2_0_readl(priv, INTRL2_CPU_STATUS) & |
| 421 | ~priv->irq0_mask; |
| 422 | intrl2_0_writel(priv, priv->irq0_stat, INTRL2_CPU_CLEAR); |
| 423 | |
| 424 | return IRQ_HANDLED; |
| 425 | } |
| 426 | |
| 427 | static irqreturn_t bcm_sf2_switch_1_isr(int irq, void *dev_id) |
| 428 | { |
| 429 | struct bcm_sf2_priv *priv = dev_id; |
| 430 | |
| 431 | priv->irq1_stat = intrl2_1_readl(priv, INTRL2_CPU_STATUS) & |
| 432 | ~priv->irq1_mask; |
| 433 | intrl2_1_writel(priv, priv->irq1_stat, INTRL2_CPU_CLEAR); |
| 434 | |
| 435 | if (priv->irq1_stat & P_LINK_UP_IRQ(P7_IRQ_OFF)) |
| 436 | priv->port_sts[7].link = 1; |
| 437 | if (priv->irq1_stat & P_LINK_DOWN_IRQ(P7_IRQ_OFF)) |
| 438 | priv->port_sts[7].link = 0; |
| 439 | |
| 440 | return IRQ_HANDLED; |
| 441 | } |
| 442 | |
Florian Fainelli | 33f8461 | 2014-11-25 18:08:49 -0800 | [diff] [blame] | 443 | static int bcm_sf2_sw_rst(struct bcm_sf2_priv *priv) |
| 444 | { |
| 445 | unsigned int timeout = 1000; |
| 446 | u32 reg; |
| 447 | |
| 448 | reg = core_readl(priv, CORE_WATCHDOG_CTRL); |
| 449 | reg |= SOFTWARE_RESET | EN_CHIP_RST | EN_SW_RESET; |
| 450 | core_writel(priv, reg, CORE_WATCHDOG_CTRL); |
| 451 | |
| 452 | do { |
| 453 | reg = core_readl(priv, CORE_WATCHDOG_CTRL); |
| 454 | if (!(reg & SOFTWARE_RESET)) |
| 455 | break; |
| 456 | |
| 457 | usleep_range(1000, 2000); |
| 458 | } while (timeout-- > 0); |
| 459 | |
| 460 | if (timeout == 0) |
| 461 | return -ETIMEDOUT; |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 466 | static void bcm_sf2_intr_disable(struct bcm_sf2_priv *priv) |
| 467 | { |
Florian Fainelli | f01d598 | 2016-08-25 15:23:41 -0700 | [diff] [blame] | 468 | intrl2_0_mask_set(priv, 0xffffffff); |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 469 | intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR); |
Florian Fainelli | f01d598 | 2016-08-25 15:23:41 -0700 | [diff] [blame] | 470 | intrl2_1_mask_set(priv, 0xffffffff); |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 471 | intrl2_1_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR); |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 474 | static void bcm_sf2_identify_ports(struct bcm_sf2_priv *priv, |
| 475 | struct device_node *dn) |
| 476 | { |
| 477 | struct device_node *port; |
| 478 | const char *phy_mode_str; |
| 479 | int mode; |
| 480 | unsigned int port_num; |
| 481 | int ret; |
| 482 | |
| 483 | priv->moca_port = -1; |
| 484 | |
| 485 | for_each_available_child_of_node(dn, port) { |
| 486 | if (of_property_read_u32(port, "reg", &port_num)) |
| 487 | continue; |
| 488 | |
| 489 | /* Internal PHYs get assigned a specific 'phy-mode' property |
| 490 | * value: "internal" to help flag them before MDIO probing |
| 491 | * has completed, since they might be turned off at that |
| 492 | * time |
| 493 | */ |
| 494 | mode = of_get_phy_mode(port); |
| 495 | if (mode < 0) { |
| 496 | ret = of_property_read_string(port, "phy-mode", |
| 497 | &phy_mode_str); |
| 498 | if (ret < 0) |
| 499 | continue; |
| 500 | |
| 501 | if (!strcasecmp(phy_mode_str, "internal")) |
| 502 | priv->int_phy_mask |= 1 << port_num; |
| 503 | } |
| 504 | |
| 505 | if (mode == PHY_INTERFACE_MODE_MOCA) |
| 506 | priv->moca_port = port_num; |
| 507 | } |
| 508 | } |
| 509 | |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 510 | static int bcm_sf2_mdio_register(struct dsa_switch *ds) |
| 511 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 512 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 513 | struct device_node *dn; |
| 514 | static int index; |
| 515 | int err; |
| 516 | |
| 517 | /* Find our integrated MDIO bus node */ |
| 518 | dn = of_find_compatible_node(NULL, NULL, "brcm,unimac-mdio"); |
| 519 | priv->master_mii_bus = of_mdio_find_bus(dn); |
| 520 | if (!priv->master_mii_bus) |
| 521 | return -EPROBE_DEFER; |
| 522 | |
| 523 | get_device(&priv->master_mii_bus->dev); |
| 524 | priv->master_mii_dn = dn; |
| 525 | |
| 526 | priv->slave_mii_bus = devm_mdiobus_alloc(ds->dev); |
| 527 | if (!priv->slave_mii_bus) |
| 528 | return -ENOMEM; |
| 529 | |
| 530 | priv->slave_mii_bus->priv = priv; |
| 531 | priv->slave_mii_bus->name = "sf2 slave mii"; |
| 532 | priv->slave_mii_bus->read = bcm_sf2_sw_mdio_read; |
| 533 | priv->slave_mii_bus->write = bcm_sf2_sw_mdio_write; |
| 534 | snprintf(priv->slave_mii_bus->id, MII_BUS_ID_SIZE, "sf2-%d", |
| 535 | index++); |
| 536 | priv->slave_mii_bus->dev.of_node = dn; |
| 537 | |
| 538 | /* Include the pseudo-PHY address to divert reads towards our |
| 539 | * workaround. This is only required for 7445D0, since 7445E0 |
| 540 | * disconnects the internal switch pseudo-PHY such that we can use the |
| 541 | * regular SWITCH_MDIO master controller instead. |
| 542 | * |
| 543 | * Here we flag the pseudo PHY as needing special treatment and would |
| 544 | * otherwise make all other PHY read/writes go to the master MDIO bus |
| 545 | * controller that comes with this switch backed by the "mdio-unimac" |
| 546 | * driver. |
| 547 | */ |
| 548 | if (of_machine_is_compatible("brcm,bcm7445d0")) |
| 549 | priv->indir_phy_mask |= (1 << BRCM_PSEUDO_PHY_ADDR); |
| 550 | else |
| 551 | priv->indir_phy_mask = 0; |
| 552 | |
| 553 | ds->phys_mii_mask = priv->indir_phy_mask; |
| 554 | ds->slave_mii_bus = priv->slave_mii_bus; |
| 555 | priv->slave_mii_bus->parent = ds->dev->parent; |
| 556 | priv->slave_mii_bus->phy_mask = ~priv->indir_phy_mask; |
| 557 | |
| 558 | if (dn) |
| 559 | err = of_mdiobus_register(priv->slave_mii_bus, dn); |
| 560 | else |
| 561 | err = mdiobus_register(priv->slave_mii_bus); |
| 562 | |
| 563 | if (err) |
| 564 | of_node_put(dn); |
| 565 | |
| 566 | return err; |
| 567 | } |
| 568 | |
| 569 | static void bcm_sf2_mdio_unregister(struct bcm_sf2_priv *priv) |
| 570 | { |
| 571 | mdiobus_unregister(priv->slave_mii_bus); |
| 572 | if (priv->master_mii_dn) |
| 573 | of_node_put(priv->master_mii_dn); |
| 574 | } |
| 575 | |
Florian Fainelli | aa9aef7 | 2014-09-19 13:07:55 -0700 | [diff] [blame] | 576 | static u32 bcm_sf2_sw_get_phy_flags(struct dsa_switch *ds, int port) |
| 577 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 578 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | aa9aef7 | 2014-09-19 13:07:55 -0700 | [diff] [blame] | 579 | |
| 580 | /* The BCM7xxx PHY driver expects to find the integrated PHY revision |
| 581 | * in bits 15:8 and the patch level in bits 7:0 which is exactly what |
| 582 | * the REG_PHY_REVISION register layout is. |
| 583 | */ |
| 584 | |
| 585 | return priv->hw_params.gphy_rev; |
| 586 | } |
| 587 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 588 | static void bcm_sf2_sw_adjust_link(struct dsa_switch *ds, int port, |
| 589 | struct phy_device *phydev) |
| 590 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 591 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 592 | u32 id_mode_dis = 0, port_mode; |
| 593 | const char *str = NULL; |
| 594 | u32 reg; |
| 595 | |
| 596 | switch (phydev->interface) { |
| 597 | case PHY_INTERFACE_MODE_RGMII: |
| 598 | str = "RGMII (no delay)"; |
| 599 | id_mode_dis = 1; |
| 600 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 601 | if (!str) |
| 602 | str = "RGMII (TX delay)"; |
| 603 | port_mode = EXT_GPHY; |
| 604 | break; |
| 605 | case PHY_INTERFACE_MODE_MII: |
| 606 | str = "MII"; |
| 607 | port_mode = EXT_EPHY; |
| 608 | break; |
| 609 | case PHY_INTERFACE_MODE_REVMII: |
| 610 | str = "Reverse MII"; |
| 611 | port_mode = EXT_REVMII; |
| 612 | break; |
| 613 | default: |
Florian Fainelli | 7de1557 | 2014-09-24 17:05:19 -0700 | [diff] [blame] | 614 | /* All other PHYs: internal and MoCA */ |
| 615 | goto force_link; |
| 616 | } |
| 617 | |
| 618 | /* If the link is down, just disable the interface to conserve power */ |
| 619 | if (!phydev->link) { |
| 620 | reg = reg_readl(priv, REG_RGMII_CNTRL_P(port)); |
| 621 | reg &= ~RGMII_MODE_EN; |
| 622 | reg_writel(priv, reg, REG_RGMII_CNTRL_P(port)); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 623 | goto force_link; |
| 624 | } |
| 625 | |
| 626 | /* Clear id_mode_dis bit, and the existing port mode, but |
| 627 | * make sure we enable the RGMII block for data to pass |
| 628 | */ |
| 629 | reg = reg_readl(priv, REG_RGMII_CNTRL_P(port)); |
| 630 | reg &= ~ID_MODE_DIS; |
| 631 | reg &= ~(PORT_MODE_MASK << PORT_MODE_SHIFT); |
| 632 | reg &= ~(RX_PAUSE_EN | TX_PAUSE_EN); |
| 633 | |
| 634 | reg |= port_mode | RGMII_MODE_EN; |
| 635 | if (id_mode_dis) |
| 636 | reg |= ID_MODE_DIS; |
| 637 | |
| 638 | if (phydev->pause) { |
| 639 | if (phydev->asym_pause) |
| 640 | reg |= TX_PAUSE_EN; |
| 641 | reg |= RX_PAUSE_EN; |
| 642 | } |
| 643 | |
| 644 | reg_writel(priv, reg, REG_RGMII_CNTRL_P(port)); |
| 645 | |
| 646 | pr_info("Port %d configured for %s\n", port, str); |
| 647 | |
| 648 | force_link: |
| 649 | /* Force link settings detected from the PHY */ |
| 650 | reg = SW_OVERRIDE; |
| 651 | switch (phydev->speed) { |
| 652 | case SPEED_1000: |
| 653 | reg |= SPDSTS_1000 << SPEED_SHIFT; |
| 654 | break; |
| 655 | case SPEED_100: |
| 656 | reg |= SPDSTS_100 << SPEED_SHIFT; |
| 657 | break; |
| 658 | } |
| 659 | |
| 660 | if (phydev->link) |
| 661 | reg |= LINK_STS; |
| 662 | if (phydev->duplex == DUPLEX_FULL) |
| 663 | reg |= DUPLX_MODE; |
| 664 | |
| 665 | core_writel(priv, reg, CORE_STS_OVERRIDE_GMIIP_PORT(port)); |
| 666 | } |
| 667 | |
| 668 | static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port, |
| 669 | struct fixed_phy_status *status) |
| 670 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 671 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | d2eac98 | 2015-07-20 17:49:55 -0700 | [diff] [blame] | 672 | u32 duplex, pause; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 673 | u32 reg; |
| 674 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 675 | duplex = core_readl(priv, CORE_DUPSTS); |
| 676 | pause = core_readl(priv, CORE_PAUSESTS); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 677 | |
| 678 | status->link = 0; |
| 679 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 680 | /* MoCA port is special as we do not get link status from CORE_LNKSTS, |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 681 | * which means that we need to force the link at the port override |
| 682 | * level to get the data to flow. We do use what the interrupt handler |
| 683 | * did determine before. |
Florian Fainelli | 7855f67 | 2014-12-11 18:12:42 -0800 | [diff] [blame] | 684 | * |
| 685 | * For the other ports, we just force the link status, since this is |
| 686 | * a fixed PHY device. |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 687 | */ |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 688 | if (port == priv->moca_port) { |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 689 | status->link = priv->port_sts[port].link; |
Florian Fainelli | 4ab7f91 | 2015-05-15 12:38:01 -0700 | [diff] [blame] | 690 | /* For MoCA interfaces, also force a link down notification |
| 691 | * since some version of the user-space daemon (mocad) use |
| 692 | * cmd->autoneg to force the link, which messes up the PHY |
| 693 | * state machine and make it go in PHY_FORCING state instead. |
| 694 | */ |
| 695 | if (!status->link) |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 696 | netif_carrier_off(ds->ports[port].netdev); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 697 | status->duplex = 1; |
| 698 | } else { |
Florian Fainelli | 7855f67 | 2014-12-11 18:12:42 -0800 | [diff] [blame] | 699 | status->link = 1; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 700 | status->duplex = !!(duplex & (1 << port)); |
| 701 | } |
| 702 | |
Florian Fainelli | 7855f67 | 2014-12-11 18:12:42 -0800 | [diff] [blame] | 703 | reg = core_readl(priv, CORE_STS_OVERRIDE_GMIIP_PORT(port)); |
| 704 | reg |= SW_OVERRIDE; |
| 705 | if (status->link) |
| 706 | reg |= LINK_STS; |
| 707 | else |
| 708 | reg &= ~LINK_STS; |
| 709 | core_writel(priv, reg, CORE_STS_OVERRIDE_GMIIP_PORT(port)); |
| 710 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 711 | if ((pause & (1 << port)) && |
| 712 | (pause & (1 << (port + PAUSESTS_TX_PAUSE_SHIFT)))) { |
| 713 | status->asym_pause = 1; |
| 714 | status->pause = 1; |
| 715 | } |
| 716 | |
| 717 | if (pause & (1 << port)) |
| 718 | status->pause = 1; |
| 719 | } |
| 720 | |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 721 | static int bcm_sf2_sw_suspend(struct dsa_switch *ds) |
| 722 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 723 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 724 | unsigned int port; |
| 725 | |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 726 | bcm_sf2_intr_disable(priv); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 727 | |
| 728 | /* Disable all ports physically present including the IMP |
| 729 | * port, the other ones have already been disabled during |
| 730 | * bcm_sf2_sw_setup |
| 731 | */ |
| 732 | for (port = 0; port < DSA_MAX_PORTS; port++) { |
Andrew Lunn | 74c3e2a | 2016-04-13 02:40:44 +0200 | [diff] [blame] | 733 | if ((1 << port) & ds->enabled_port_mask || |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 734 | dsa_is_cpu_port(ds, port)) |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 735 | bcm_sf2_port_disable(ds, port, NULL); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 741 | static int bcm_sf2_sw_resume(struct dsa_switch *ds) |
| 742 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 743 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 744 | unsigned int port; |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 745 | int ret; |
| 746 | |
| 747 | ret = bcm_sf2_sw_rst(priv); |
| 748 | if (ret) { |
| 749 | pr_err("%s: failed to software reset switch\n", __func__); |
| 750 | return ret; |
| 751 | } |
| 752 | |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 753 | if (priv->hw_params.num_gphy == 1) |
| 754 | bcm_sf2_gphy_enable_set(ds, true); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 755 | |
| 756 | for (port = 0; port < DSA_MAX_PORTS; port++) { |
Andrew Lunn | 74c3e2a | 2016-04-13 02:40:44 +0200 | [diff] [blame] | 757 | if ((1 << port) & ds->enabled_port_mask) |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 758 | bcm_sf2_port_setup(ds, port, NULL); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 759 | else if (dsa_is_cpu_port(ds, port)) |
| 760 | bcm_sf2_imp_setup(ds, port); |
| 761 | } |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 766 | static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port, |
| 767 | struct ethtool_wolinfo *wol) |
| 768 | { |
| 769 | struct net_device *p = ds->dst[ds->index].master_netdev; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 770 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 771 | struct ethtool_wolinfo pwol; |
| 772 | |
| 773 | /* Get the parent device WoL settings */ |
| 774 | p->ethtool_ops->get_wol(p, &pwol); |
| 775 | |
| 776 | /* Advertise the parent device supported settings */ |
| 777 | wol->supported = pwol.supported; |
| 778 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 779 | |
| 780 | if (pwol.wolopts & WAKE_MAGICSECURE) |
| 781 | memcpy(&wol->sopass, pwol.sopass, sizeof(wol->sopass)); |
| 782 | |
| 783 | if (priv->wol_ports_mask & (1 << port)) |
| 784 | wol->wolopts = pwol.wolopts; |
| 785 | else |
| 786 | wol->wolopts = 0; |
| 787 | } |
| 788 | |
| 789 | static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port, |
| 790 | struct ethtool_wolinfo *wol) |
| 791 | { |
| 792 | struct net_device *p = ds->dst[ds->index].master_netdev; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 793 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 794 | s8 cpu_port = ds->dst[ds->index].cpu_port; |
| 795 | struct ethtool_wolinfo pwol; |
| 796 | |
| 797 | p->ethtool_ops->get_wol(p, &pwol); |
| 798 | if (wol->wolopts & ~pwol.supported) |
| 799 | return -EINVAL; |
| 800 | |
| 801 | if (wol->wolopts) |
| 802 | priv->wol_ports_mask |= (1 << port); |
| 803 | else |
| 804 | priv->wol_ports_mask &= ~(1 << port); |
| 805 | |
| 806 | /* If we have at least one port enabled, make sure the CPU port |
| 807 | * is also enabled. If the CPU port is the last one enabled, we disable |
| 808 | * it since this configuration does not make sense. |
| 809 | */ |
| 810 | if (priv->wol_ports_mask && priv->wol_ports_mask != (1 << cpu_port)) |
| 811 | priv->wol_ports_mask |= (1 << cpu_port); |
| 812 | else |
| 813 | priv->wol_ports_mask &= ~(1 << cpu_port); |
| 814 | |
| 815 | return p->ethtool_ops->set_wol(p, wol); |
| 816 | } |
| 817 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 818 | static int bcm_sf2_vlan_op_wait(struct bcm_sf2_priv *priv) |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 819 | { |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 820 | unsigned int timeout = 10; |
| 821 | u32 reg; |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 822 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 823 | do { |
| 824 | reg = core_readl(priv, CORE_ARLA_VTBL_RWCTRL); |
| 825 | if (!(reg & ARLA_VTBL_STDN)) |
| 826 | return 0; |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 827 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 828 | usleep_range(1000, 2000); |
| 829 | } while (timeout--); |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 830 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 831 | return -ETIMEDOUT; |
| 832 | } |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 833 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 834 | static int bcm_sf2_vlan_op(struct bcm_sf2_priv *priv, u8 op) |
| 835 | { |
| 836 | core_writel(priv, ARLA_VTBL_STDN | op, CORE_ARLA_VTBL_RWCTRL); |
| 837 | |
| 838 | return bcm_sf2_vlan_op_wait(priv); |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | static void bcm_sf2_sw_configure_vlan(struct dsa_switch *ds) |
| 842 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 843 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 844 | unsigned int port; |
| 845 | |
| 846 | /* Clear all VLANs */ |
| 847 | bcm_sf2_vlan_op(priv, ARLA_VTBL_CMD_CLEAR); |
| 848 | |
| 849 | for (port = 0; port < priv->hw_params.num_ports; port++) { |
| 850 | if (!((1 << port) & ds->enabled_port_mask)) |
| 851 | continue; |
| 852 | |
| 853 | core_writel(priv, 1, CORE_DEFAULT_1Q_TAG_P(port)); |
| 854 | } |
| 855 | } |
| 856 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 857 | static int bcm_sf2_sw_setup(struct dsa_switch *ds) |
| 858 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 859 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 860 | unsigned int port; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 861 | |
| 862 | /* Enable all valid ports and disable those unused */ |
| 863 | for (port = 0; port < priv->hw_params.num_ports; port++) { |
| 864 | /* IMP port receives special treatment */ |
| 865 | if ((1 << port) & ds->enabled_port_mask) |
| 866 | bcm_sf2_port_setup(ds, port, NULL); |
| 867 | else if (dsa_is_cpu_port(ds, port)) |
| 868 | bcm_sf2_imp_setup(ds, port); |
| 869 | else |
| 870 | bcm_sf2_port_disable(ds, port, NULL); |
| 871 | } |
| 872 | |
| 873 | bcm_sf2_sw_configure_vlan(ds); |
| 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 878 | /* The SWITCH_CORE register space is managed by b53 but operates on a page + |
| 879 | * register basis so we need to translate that into an address that the |
| 880 | * bus-glue understands. |
| 881 | */ |
| 882 | #define SF2_PAGE_REG_MKADDR(page, reg) ((page) << 10 | (reg) << 2) |
| 883 | |
| 884 | static int bcm_sf2_core_read8(struct b53_device *dev, u8 page, u8 reg, |
| 885 | u8 *val) |
| 886 | { |
| 887 | struct bcm_sf2_priv *priv = dev->priv; |
| 888 | |
| 889 | *val = core_readl(priv, SF2_PAGE_REG_MKADDR(page, reg)); |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | static int bcm_sf2_core_read16(struct b53_device *dev, u8 page, u8 reg, |
| 895 | u16 *val) |
| 896 | { |
| 897 | struct bcm_sf2_priv *priv = dev->priv; |
| 898 | |
| 899 | *val = core_readl(priv, SF2_PAGE_REG_MKADDR(page, reg)); |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | static int bcm_sf2_core_read32(struct b53_device *dev, u8 page, u8 reg, |
| 905 | u32 *val) |
| 906 | { |
| 907 | struct bcm_sf2_priv *priv = dev->priv; |
| 908 | |
| 909 | *val = core_readl(priv, SF2_PAGE_REG_MKADDR(page, reg)); |
| 910 | |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | static int bcm_sf2_core_read64(struct b53_device *dev, u8 page, u8 reg, |
| 915 | u64 *val) |
| 916 | { |
| 917 | struct bcm_sf2_priv *priv = dev->priv; |
| 918 | |
| 919 | *val = core_readq(priv, SF2_PAGE_REG_MKADDR(page, reg)); |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | static int bcm_sf2_core_write8(struct b53_device *dev, u8 page, u8 reg, |
| 925 | u8 value) |
| 926 | { |
| 927 | struct bcm_sf2_priv *priv = dev->priv; |
| 928 | |
| 929 | core_writel(priv, value, SF2_PAGE_REG_MKADDR(page, reg)); |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static int bcm_sf2_core_write16(struct b53_device *dev, u8 page, u8 reg, |
| 935 | u16 value) |
| 936 | { |
| 937 | struct bcm_sf2_priv *priv = dev->priv; |
| 938 | |
| 939 | core_writel(priv, value, SF2_PAGE_REG_MKADDR(page, reg)); |
| 940 | |
| 941 | return 0; |
| 942 | } |
| 943 | |
| 944 | static int bcm_sf2_core_write32(struct b53_device *dev, u8 page, u8 reg, |
| 945 | u32 value) |
| 946 | { |
| 947 | struct bcm_sf2_priv *priv = dev->priv; |
| 948 | |
| 949 | core_writel(priv, value, SF2_PAGE_REG_MKADDR(page, reg)); |
| 950 | |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | static int bcm_sf2_core_write64(struct b53_device *dev, u8 page, u8 reg, |
| 955 | u64 value) |
| 956 | { |
| 957 | struct bcm_sf2_priv *priv = dev->priv; |
| 958 | |
| 959 | core_writeq(priv, value, SF2_PAGE_REG_MKADDR(page, reg)); |
| 960 | |
| 961 | return 0; |
| 962 | } |
| 963 | |
Wei Yongjun | 0e26e5b | 2016-09-15 02:24:13 +0000 | [diff] [blame] | 964 | static struct b53_io_ops bcm_sf2_io_ops = { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 965 | .read8 = bcm_sf2_core_read8, |
| 966 | .read16 = bcm_sf2_core_read16, |
| 967 | .read32 = bcm_sf2_core_read32, |
| 968 | .read48 = bcm_sf2_core_read64, |
| 969 | .read64 = bcm_sf2_core_read64, |
| 970 | .write8 = bcm_sf2_core_write8, |
| 971 | .write16 = bcm_sf2_core_write16, |
| 972 | .write32 = bcm_sf2_core_write32, |
| 973 | .write48 = bcm_sf2_core_write64, |
| 974 | .write64 = bcm_sf2_core_write64, |
| 975 | }; |
| 976 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 977 | static int bcm_sf2_sw_probe(struct platform_device *pdev) |
| 978 | { |
| 979 | const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME; |
| 980 | struct device_node *dn = pdev->dev.of_node; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 981 | struct b53_platform_data *pdata; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 982 | struct bcm_sf2_priv *priv; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 983 | struct b53_device *dev; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 984 | struct dsa_switch *ds; |
| 985 | void __iomem **base; |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 986 | struct resource *r; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 987 | unsigned int i; |
| 988 | u32 reg, rev; |
| 989 | int ret; |
| 990 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 991 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 992 | if (!priv) |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 993 | return -ENOMEM; |
| 994 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 995 | dev = b53_switch_alloc(&pdev->dev, &bcm_sf2_io_ops, priv); |
| 996 | if (!dev) |
| 997 | return -ENOMEM; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 998 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 999 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1000 | if (!pdata) |
| 1001 | return -ENOMEM; |
| 1002 | |
| 1003 | /* Auto-detection using standard registers will not work, so |
| 1004 | * provide an indication of what kind of device we are for |
| 1005 | * b53_common to work with |
| 1006 | */ |
| 1007 | pdata->chip_id = BCM7445_DEVICE_ID; |
| 1008 | dev->pdata = pdata; |
| 1009 | |
| 1010 | priv->dev = dev; |
| 1011 | ds = dev->ds; |
| 1012 | |
| 1013 | /* Override the parts that are non-standard wrt. normal b53 devices */ |
| 1014 | ds->ops->get_tag_protocol = bcm_sf2_sw_get_tag_protocol; |
| 1015 | ds->ops->setup = bcm_sf2_sw_setup; |
| 1016 | ds->ops->get_phy_flags = bcm_sf2_sw_get_phy_flags; |
| 1017 | ds->ops->adjust_link = bcm_sf2_sw_adjust_link; |
| 1018 | ds->ops->fixed_link_update = bcm_sf2_sw_fixed_link_update; |
| 1019 | ds->ops->suspend = bcm_sf2_sw_suspend; |
| 1020 | ds->ops->resume = bcm_sf2_sw_resume; |
| 1021 | ds->ops->get_wol = bcm_sf2_sw_get_wol; |
| 1022 | ds->ops->set_wol = bcm_sf2_sw_set_wol; |
| 1023 | ds->ops->port_enable = bcm_sf2_port_setup; |
| 1024 | ds->ops->port_disable = bcm_sf2_port_disable; |
| 1025 | ds->ops->get_eee = bcm_sf2_sw_get_eee; |
| 1026 | ds->ops->set_eee = bcm_sf2_sw_set_eee; |
| 1027 | |
| 1028 | /* Avoid having DSA free our slave MDIO bus (checking for |
| 1029 | * ds->slave_mii_bus and ds->ops->phy_read being non-NULL) |
| 1030 | */ |
| 1031 | ds->ops->phy_read = NULL; |
| 1032 | |
| 1033 | dev_set_drvdata(&pdev->dev, priv); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1034 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1035 | spin_lock_init(&priv->indir_lock); |
| 1036 | mutex_init(&priv->stats_mutex); |
| 1037 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1038 | bcm_sf2_identify_ports(priv, dn->child); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1039 | |
| 1040 | priv->irq0 = irq_of_parse_and_map(dn, 0); |
| 1041 | priv->irq1 = irq_of_parse_and_map(dn, 1); |
| 1042 | |
| 1043 | base = &priv->core; |
| 1044 | for (i = 0; i < BCM_SF2_REGS_NUM; i++) { |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1045 | r = platform_get_resource(pdev, IORESOURCE_MEM, i); |
| 1046 | *base = devm_ioremap_resource(&pdev->dev, r); |
| 1047 | if (IS_ERR(*base)) { |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1048 | pr_err("unable to find register: %s\n", reg_names[i]); |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1049 | return PTR_ERR(*base); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1050 | } |
| 1051 | base++; |
| 1052 | } |
| 1053 | |
| 1054 | ret = bcm_sf2_sw_rst(priv); |
| 1055 | if (ret) { |
| 1056 | pr_err("unable to software reset switch: %d\n", ret); |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1057 | return ret; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | ret = bcm_sf2_mdio_register(ds); |
| 1061 | if (ret) { |
| 1062 | pr_err("failed to register MDIO bus\n"); |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1063 | return ret; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | /* Disable all interrupts and request them */ |
| 1067 | bcm_sf2_intr_disable(priv); |
| 1068 | |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1069 | ret = devm_request_irq(&pdev->dev, priv->irq0, bcm_sf2_switch_0_isr, 0, |
| 1070 | "switch_0", priv); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1071 | if (ret < 0) { |
| 1072 | pr_err("failed to request switch_0 IRQ\n"); |
Florian Fainelli | bb9c0fa | 2016-07-29 12:35:57 -0700 | [diff] [blame] | 1073 | goto out_mdio; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1076 | ret = devm_request_irq(&pdev->dev, priv->irq1, bcm_sf2_switch_1_isr, 0, |
| 1077 | "switch_1", priv); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1078 | if (ret < 0) { |
| 1079 | pr_err("failed to request switch_1 IRQ\n"); |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1080 | goto out_mdio; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | /* Reset the MIB counters */ |
| 1084 | reg = core_readl(priv, CORE_GMNCFGCFG); |
| 1085 | reg |= RST_MIB_CNT; |
| 1086 | core_writel(priv, reg, CORE_GMNCFGCFG); |
| 1087 | reg &= ~RST_MIB_CNT; |
| 1088 | core_writel(priv, reg, CORE_GMNCFGCFG); |
| 1089 | |
| 1090 | /* Get the maximum number of ports for this switch */ |
| 1091 | priv->hw_params.num_ports = core_readl(priv, CORE_IMP0_PRT_ID) + 1; |
| 1092 | if (priv->hw_params.num_ports > DSA_MAX_PORTS) |
| 1093 | priv->hw_params.num_ports = DSA_MAX_PORTS; |
| 1094 | |
| 1095 | /* Assume a single GPHY setup if we can't read that property */ |
| 1096 | if (of_property_read_u32(dn, "brcm,num-gphy", |
| 1097 | &priv->hw_params.num_gphy)) |
| 1098 | priv->hw_params.num_gphy = 1; |
| 1099 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1100 | rev = reg_readl(priv, REG_SWITCH_REVISION); |
| 1101 | priv->hw_params.top_rev = (rev >> SWITCH_TOP_REV_SHIFT) & |
| 1102 | SWITCH_TOP_REV_MASK; |
| 1103 | priv->hw_params.core_rev = (rev & SF2_REV_MASK); |
| 1104 | |
| 1105 | rev = reg_readl(priv, REG_PHY_REVISION); |
| 1106 | priv->hw_params.gphy_rev = rev & PHY_REVISION_MASK; |
| 1107 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1108 | ret = b53_switch_register(dev); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1109 | if (ret) |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1110 | goto out_mdio; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1111 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1112 | pr_info("Starfighter 2 top: %x.%02x, core: %x.%02x base: 0x%p, IRQs: %d, %d\n", |
| 1113 | priv->hw_params.top_rev >> 8, priv->hw_params.top_rev & 0xff, |
| 1114 | priv->hw_params.core_rev >> 8, priv->hw_params.core_rev & 0xff, |
| 1115 | priv->core, priv->irq0, priv->irq1); |
| 1116 | |
| 1117 | return 0; |
| 1118 | |
Florian Fainelli | bb9c0fa | 2016-07-29 12:35:57 -0700 | [diff] [blame] | 1119 | out_mdio: |
| 1120 | bcm_sf2_mdio_unregister(priv); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1121 | return ret; |
| 1122 | } |
| 1123 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1124 | static int bcm_sf2_sw_remove(struct platform_device *pdev) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1125 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1126 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1127 | |
| 1128 | /* Disable all ports and interrupts */ |
| 1129 | priv->wol_ports_mask = 0; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1130 | bcm_sf2_sw_suspend(priv->dev->ds); |
| 1131 | dsa_unregister_switch(priv->dev->ds); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1132 | bcm_sf2_mdio_unregister(priv); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1133 | |
| 1134 | return 0; |
| 1135 | } |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1136 | |
Florian Fainelli | 2399d61 | 2016-10-20 09:32:19 -0700 | [diff] [blame] | 1137 | static void bcm_sf2_sw_shutdown(struct platform_device *pdev) |
| 1138 | { |
| 1139 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
| 1140 | |
| 1141 | /* For a kernel about to be kexec'd we want to keep the GPHY on for a |
| 1142 | * successful MDIO bus scan to occur. If we did turn off the GPHY |
| 1143 | * before (e.g: port_disable), this will also power it back on. |
| 1144 | */ |
| 1145 | if (priv->hw_params.num_gphy == 1) |
| 1146 | bcm_sf2_gphy_enable_set(priv->dev->ds, kexec_in_progress); |
| 1147 | } |
| 1148 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1149 | #ifdef CONFIG_PM_SLEEP |
| 1150 | static int bcm_sf2_suspend(struct device *dev) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1151 | { |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1152 | struct platform_device *pdev = to_platform_device(dev); |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1153 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1154 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1155 | return dsa_switch_suspend(priv->dev->ds); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1156 | } |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1157 | |
| 1158 | static int bcm_sf2_resume(struct device *dev) |
| 1159 | { |
| 1160 | struct platform_device *pdev = to_platform_device(dev); |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1161 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1162 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1163 | return dsa_switch_resume(priv->dev->ds); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1164 | } |
| 1165 | #endif /* CONFIG_PM_SLEEP */ |
| 1166 | |
| 1167 | static SIMPLE_DEV_PM_OPS(bcm_sf2_pm_ops, |
| 1168 | bcm_sf2_suspend, bcm_sf2_resume); |
| 1169 | |
| 1170 | static const struct of_device_id bcm_sf2_of_match[] = { |
| 1171 | { .compatible = "brcm,bcm7445-switch-v4.0" }, |
| 1172 | { /* sentinel */ }, |
| 1173 | }; |
Javier Martinez Canillas | 0822b43 | 2016-10-17 11:05:46 -0300 | [diff] [blame] | 1174 | MODULE_DEVICE_TABLE(of, bcm_sf2_of_match); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1175 | |
| 1176 | static struct platform_driver bcm_sf2_driver = { |
| 1177 | .probe = bcm_sf2_sw_probe, |
| 1178 | .remove = bcm_sf2_sw_remove, |
Florian Fainelli | 2399d61 | 2016-10-20 09:32:19 -0700 | [diff] [blame] | 1179 | .shutdown = bcm_sf2_sw_shutdown, |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1180 | .driver = { |
| 1181 | .name = "brcm-sf2", |
| 1182 | .of_match_table = bcm_sf2_of_match, |
| 1183 | .pm = &bcm_sf2_pm_ops, |
| 1184 | }, |
| 1185 | }; |
| 1186 | module_platform_driver(bcm_sf2_driver); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1187 | |
| 1188 | MODULE_AUTHOR("Broadcom Corporation"); |
| 1189 | MODULE_DESCRIPTION("Driver for Broadcom Starfighter 2 ethernet switch chip"); |
| 1190 | MODULE_LICENSE("GPL"); |
| 1191 | MODULE_ALIAS("platform:brcm-sf2"); |