155ab6ffaSArun Ramadoss // SPDX-License-Identifier: GPL-2.0 255ab6ffaSArun Ramadoss /* Microchip LAN937X switch driver main logic 355ab6ffaSArun Ramadoss * Copyright (C) 2019-2022 Microchip Technology Inc. 455ab6ffaSArun Ramadoss */ 555ab6ffaSArun Ramadoss #include <linux/kernel.h> 655ab6ffaSArun Ramadoss #include <linux/module.h> 755ab6ffaSArun Ramadoss #include <linux/iopoll.h> 855ab6ffaSArun Ramadoss #include <linux/phy.h> 955ab6ffaSArun Ramadoss #include <linux/of_net.h> 1055ab6ffaSArun Ramadoss #include <linux/if_bridge.h> 11ab882368SArun Ramadoss #include <linux/if_vlan.h> 1255ab6ffaSArun Ramadoss #include <linux/math.h> 1355ab6ffaSArun Ramadoss #include <net/dsa.h> 1455ab6ffaSArun Ramadoss #include <net/switchdev.h> 1555ab6ffaSArun Ramadoss 1655ab6ffaSArun Ramadoss #include "lan937x_reg.h" 1755ab6ffaSArun Ramadoss #include "ksz_common.h" 18e30f33a5SArun Ramadoss #include "ksz9477.h" 1955ab6ffaSArun Ramadoss #include "lan937x.h" 2055ab6ffaSArun Ramadoss 2155ab6ffaSArun Ramadoss static int lan937x_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set) 2255ab6ffaSArun Ramadoss { 23b8311f46SVladimir Oltean return regmap_update_bits(ksz_regmap_8(dev), addr, bits, set ? bits : 0); 2455ab6ffaSArun Ramadoss } 2555ab6ffaSArun Ramadoss 2655ab6ffaSArun Ramadoss static int lan937x_port_cfg(struct ksz_device *dev, int port, int offset, 2755ab6ffaSArun Ramadoss u8 bits, bool set) 2855ab6ffaSArun Ramadoss { 29b8311f46SVladimir Oltean return regmap_update_bits(ksz_regmap_8(dev), PORT_CTRL_ADDR(port, offset), 3055ab6ffaSArun Ramadoss bits, set ? bits : 0); 3155ab6ffaSArun Ramadoss } 3255ab6ffaSArun Ramadoss 33ffaf1de2SArun Ramadoss static int lan937x_enable_spi_indirect_access(struct ksz_device *dev) 34ffaf1de2SArun Ramadoss { 35ffaf1de2SArun Ramadoss u16 data16; 36ffaf1de2SArun Ramadoss int ret; 37ffaf1de2SArun Ramadoss 38ffaf1de2SArun Ramadoss /* Enable Phy access through SPI */ 39ffaf1de2SArun Ramadoss ret = lan937x_cfg(dev, REG_GLOBAL_CTRL_0, SW_PHY_REG_BLOCK, false); 40ffaf1de2SArun Ramadoss if (ret < 0) 41ffaf1de2SArun Ramadoss return ret; 42ffaf1de2SArun Ramadoss 43ffaf1de2SArun Ramadoss ret = ksz_read16(dev, REG_VPHY_SPECIAL_CTRL__2, &data16); 44ffaf1de2SArun Ramadoss if (ret < 0) 45ffaf1de2SArun Ramadoss return ret; 46ffaf1de2SArun Ramadoss 47ffaf1de2SArun Ramadoss /* Allow SPI access */ 48ffaf1de2SArun Ramadoss data16 |= VPHY_SPI_INDIRECT_ENABLE; 49ffaf1de2SArun Ramadoss 50ffaf1de2SArun Ramadoss return ksz_write16(dev, REG_VPHY_SPECIAL_CTRL__2, data16); 51ffaf1de2SArun Ramadoss } 52ffaf1de2SArun Ramadoss 53ffaf1de2SArun Ramadoss static int lan937x_vphy_ind_addr_wr(struct ksz_device *dev, int addr, int reg) 54ffaf1de2SArun Ramadoss { 55ffaf1de2SArun Ramadoss u16 addr_base = REG_PORT_T1_PHY_CTRL_BASE; 56ffaf1de2SArun Ramadoss u16 temp; 57ffaf1de2SArun Ramadoss 58*8d7330b3SLucas Stach if ((dev->info->chip_id == LAN9371_CHIP_ID || 59*8d7330b3SLucas Stach dev->info->chip_id == LAN9372_CHIP_ID) && addr == KSZ_PORT_4) 60*8d7330b3SLucas Stach addr_base = REG_PORT_TX_PHY_CTRL_BASE; 61*8d7330b3SLucas Stach 62ffaf1de2SArun Ramadoss /* get register address based on the logical port */ 63ffaf1de2SArun Ramadoss temp = PORT_CTRL_ADDR(addr, (addr_base + (reg << 2))); 64ffaf1de2SArun Ramadoss 65ffaf1de2SArun Ramadoss return ksz_write16(dev, REG_VPHY_IND_ADDR__2, temp); 66ffaf1de2SArun Ramadoss } 67ffaf1de2SArun Ramadoss 68ffaf1de2SArun Ramadoss static int lan937x_internal_phy_write(struct ksz_device *dev, int addr, int reg, 69ffaf1de2SArun Ramadoss u16 val) 70ffaf1de2SArun Ramadoss { 71ffaf1de2SArun Ramadoss unsigned int value; 72ffaf1de2SArun Ramadoss int ret; 73ffaf1de2SArun Ramadoss 74ffaf1de2SArun Ramadoss /* Check for internal phy port */ 75ffaf1de2SArun Ramadoss if (!dev->info->internal_phy[addr]) 76ffaf1de2SArun Ramadoss return -EOPNOTSUPP; 77ffaf1de2SArun Ramadoss 78ffaf1de2SArun Ramadoss ret = lan937x_vphy_ind_addr_wr(dev, addr, reg); 79ffaf1de2SArun Ramadoss if (ret < 0) 80ffaf1de2SArun Ramadoss return ret; 81ffaf1de2SArun Ramadoss 82ffaf1de2SArun Ramadoss /* Write the data to be written to the VPHY reg */ 83ffaf1de2SArun Ramadoss ret = ksz_write16(dev, REG_VPHY_IND_DATA__2, val); 84ffaf1de2SArun Ramadoss if (ret < 0) 85ffaf1de2SArun Ramadoss return ret; 86ffaf1de2SArun Ramadoss 87ffaf1de2SArun Ramadoss /* Write the Write En and Busy bit */ 88ffaf1de2SArun Ramadoss ret = ksz_write16(dev, REG_VPHY_IND_CTRL__2, 89ffaf1de2SArun Ramadoss (VPHY_IND_WRITE | VPHY_IND_BUSY)); 90ffaf1de2SArun Ramadoss if (ret < 0) 91ffaf1de2SArun Ramadoss return ret; 92ffaf1de2SArun Ramadoss 93b8311f46SVladimir Oltean ret = regmap_read_poll_timeout(ksz_regmap_16(dev), REG_VPHY_IND_CTRL__2, 94ffaf1de2SArun Ramadoss value, !(value & VPHY_IND_BUSY), 10, 95ffaf1de2SArun Ramadoss 1000); 96ffaf1de2SArun Ramadoss if (ret < 0) { 97ffaf1de2SArun Ramadoss dev_err(dev->dev, "Failed to write phy register\n"); 98ffaf1de2SArun Ramadoss return ret; 99ffaf1de2SArun Ramadoss } 100ffaf1de2SArun Ramadoss 101ffaf1de2SArun Ramadoss return 0; 102ffaf1de2SArun Ramadoss } 103ffaf1de2SArun Ramadoss 104ffaf1de2SArun Ramadoss static int lan937x_internal_phy_read(struct ksz_device *dev, int addr, int reg, 105ffaf1de2SArun Ramadoss u16 *val) 106ffaf1de2SArun Ramadoss { 107ffaf1de2SArun Ramadoss unsigned int value; 108ffaf1de2SArun Ramadoss int ret; 109ffaf1de2SArun Ramadoss 110ffaf1de2SArun Ramadoss /* Check for internal phy port, return 0xffff for non-existent phy */ 111ffaf1de2SArun Ramadoss if (!dev->info->internal_phy[addr]) 112ffaf1de2SArun Ramadoss return 0xffff; 113ffaf1de2SArun Ramadoss 114ffaf1de2SArun Ramadoss ret = lan937x_vphy_ind_addr_wr(dev, addr, reg); 115ffaf1de2SArun Ramadoss if (ret < 0) 116ffaf1de2SArun Ramadoss return ret; 117ffaf1de2SArun Ramadoss 118ffaf1de2SArun Ramadoss /* Write Read and Busy bit to start the transaction */ 119ffaf1de2SArun Ramadoss ret = ksz_write16(dev, REG_VPHY_IND_CTRL__2, VPHY_IND_BUSY); 120ffaf1de2SArun Ramadoss if (ret < 0) 121ffaf1de2SArun Ramadoss return ret; 122ffaf1de2SArun Ramadoss 123b8311f46SVladimir Oltean ret = regmap_read_poll_timeout(ksz_regmap_16(dev), REG_VPHY_IND_CTRL__2, 124ffaf1de2SArun Ramadoss value, !(value & VPHY_IND_BUSY), 10, 125ffaf1de2SArun Ramadoss 1000); 126ffaf1de2SArun Ramadoss if (ret < 0) { 127ffaf1de2SArun Ramadoss dev_err(dev->dev, "Failed to read phy register\n"); 128ffaf1de2SArun Ramadoss return ret; 129ffaf1de2SArun Ramadoss } 130ffaf1de2SArun Ramadoss 131ffaf1de2SArun Ramadoss /* Read the VPHY register which has the PHY data */ 132ffaf1de2SArun Ramadoss return ksz_read16(dev, REG_VPHY_IND_DATA__2, val); 133ffaf1de2SArun Ramadoss } 134ffaf1de2SArun Ramadoss 1358f420456SOleksij Rempel int lan937x_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data) 136ffaf1de2SArun Ramadoss { 1378f420456SOleksij Rempel return lan937x_internal_phy_read(dev, addr, reg, data); 138ffaf1de2SArun Ramadoss } 139ffaf1de2SArun Ramadoss 1408f420456SOleksij Rempel int lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) 141ffaf1de2SArun Ramadoss { 1428f420456SOleksij Rempel return lan937x_internal_phy_write(dev, addr, reg, val); 143ffaf1de2SArun Ramadoss } 144ffaf1de2SArun Ramadoss 14555ab6ffaSArun Ramadoss int lan937x_reset_switch(struct ksz_device *dev) 14655ab6ffaSArun Ramadoss { 14755ab6ffaSArun Ramadoss u32 data32; 14855ab6ffaSArun Ramadoss int ret; 14955ab6ffaSArun Ramadoss 15055ab6ffaSArun Ramadoss /* reset switch */ 15155ab6ffaSArun Ramadoss ret = lan937x_cfg(dev, REG_SW_OPERATION, SW_RESET, true); 15255ab6ffaSArun Ramadoss if (ret < 0) 15355ab6ffaSArun Ramadoss return ret; 15455ab6ffaSArun Ramadoss 15555ab6ffaSArun Ramadoss /* Enable Auto Aging */ 15655ab6ffaSArun Ramadoss ret = lan937x_cfg(dev, REG_SW_LUE_CTRL_1, SW_LINK_AUTO_AGING, true); 15755ab6ffaSArun Ramadoss if (ret < 0) 15855ab6ffaSArun Ramadoss return ret; 15955ab6ffaSArun Ramadoss 16055ab6ffaSArun Ramadoss /* disable interrupts */ 16155ab6ffaSArun Ramadoss ret = ksz_write32(dev, REG_SW_INT_MASK__4, SWITCH_INT_MASK); 16255ab6ffaSArun Ramadoss if (ret < 0) 16355ab6ffaSArun Ramadoss return ret; 16455ab6ffaSArun Ramadoss 165f3139362SArun Ramadoss ret = ksz_write32(dev, REG_SW_INT_STATUS__4, POR_READY_INT); 166f3139362SArun Ramadoss if (ret < 0) 167f3139362SArun Ramadoss return ret; 168f3139362SArun Ramadoss 16955ab6ffaSArun Ramadoss ret = ksz_write32(dev, REG_SW_PORT_INT_MASK__4, 0xFF); 17055ab6ffaSArun Ramadoss if (ret < 0) 17155ab6ffaSArun Ramadoss return ret; 17255ab6ffaSArun Ramadoss 17355ab6ffaSArun Ramadoss return ksz_read32(dev, REG_SW_PORT_INT_STATUS__4, &data32); 17455ab6ffaSArun Ramadoss } 17555ab6ffaSArun Ramadoss 17655ab6ffaSArun Ramadoss void lan937x_port_setup(struct ksz_device *dev, int port, bool cpu_port) 17755ab6ffaSArun Ramadoss { 1788560664fSArun Ramadoss const u32 *masks = dev->info->masks; 1798560664fSArun Ramadoss const u16 *regs = dev->info->regs; 18055ab6ffaSArun Ramadoss struct dsa_switch *ds = dev->ds; 18155ab6ffaSArun Ramadoss u8 member; 18255ab6ffaSArun Ramadoss 18355ab6ffaSArun Ramadoss /* enable tag tail for host port */ 18455ab6ffaSArun Ramadoss if (cpu_port) 18555ab6ffaSArun Ramadoss lan937x_port_cfg(dev, port, REG_PORT_CTRL_0, 18655ab6ffaSArun Ramadoss PORT_TAIL_TAG_ENABLE, true); 18755ab6ffaSArun Ramadoss 188e30f33a5SArun Ramadoss /* Enable the Port Queue split */ 189e30f33a5SArun Ramadoss ksz9477_port_queue_split(dev, port); 190e30f33a5SArun Ramadoss 19155ab6ffaSArun Ramadoss /* set back pressure for half duplex */ 19255ab6ffaSArun Ramadoss lan937x_port_cfg(dev, port, REG_PORT_MAC_CTRL_1, PORT_BACK_PRESSURE, 19355ab6ffaSArun Ramadoss true); 19455ab6ffaSArun Ramadoss 19555ab6ffaSArun Ramadoss /* enable 802.1p priority */ 19655ab6ffaSArun Ramadoss lan937x_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_PRIO_ENABLE, true); 19755ab6ffaSArun Ramadoss 19855ab6ffaSArun Ramadoss if (!dev->info->internal_phy[port]) 1998560664fSArun Ramadoss lan937x_port_cfg(dev, port, regs[P_XMII_CTRL_0], 2008560664fSArun Ramadoss masks[P_MII_TX_FLOW_CTRL] | 2018560664fSArun Ramadoss masks[P_MII_RX_FLOW_CTRL], 20255ab6ffaSArun Ramadoss true); 20355ab6ffaSArun Ramadoss 20455ab6ffaSArun Ramadoss if (cpu_port) 20555ab6ffaSArun Ramadoss member = dsa_user_ports(ds); 20655ab6ffaSArun Ramadoss else 20755ab6ffaSArun Ramadoss member = BIT(dsa_upstream_port(ds, port)); 20855ab6ffaSArun Ramadoss 20955ab6ffaSArun Ramadoss dev->dev_ops->cfg_port_member(dev, port, member); 21055ab6ffaSArun Ramadoss } 21155ab6ffaSArun Ramadoss 21255ab6ffaSArun Ramadoss void lan937x_config_cpu_port(struct dsa_switch *ds) 21355ab6ffaSArun Ramadoss { 21455ab6ffaSArun Ramadoss struct ksz_device *dev = ds->priv; 21555ab6ffaSArun Ramadoss struct dsa_port *dp; 21655ab6ffaSArun Ramadoss 21755ab6ffaSArun Ramadoss dsa_switch_for_each_cpu_port(dp, ds) { 21855ab6ffaSArun Ramadoss if (dev->info->cpu_ports & (1 << dp->index)) { 21955ab6ffaSArun Ramadoss dev->cpu_port = dp->index; 22055ab6ffaSArun Ramadoss 22155ab6ffaSArun Ramadoss /* enable cpu port */ 22255ab6ffaSArun Ramadoss lan937x_port_setup(dev, dp->index, true); 22355ab6ffaSArun Ramadoss } 22455ab6ffaSArun Ramadoss } 22555ab6ffaSArun Ramadoss 22655ab6ffaSArun Ramadoss dsa_switch_for_each_user_port(dp, ds) { 22755ab6ffaSArun Ramadoss ksz_port_stp_state_set(ds, dp->index, BR_STATE_DISABLED); 22855ab6ffaSArun Ramadoss } 22955ab6ffaSArun Ramadoss } 23055ab6ffaSArun Ramadoss 231ab882368SArun Ramadoss int lan937x_change_mtu(struct ksz_device *dev, int port, int new_mtu) 232ab882368SArun Ramadoss { 233ab882368SArun Ramadoss struct dsa_switch *ds = dev->ds; 234ab882368SArun Ramadoss int ret; 235ab882368SArun Ramadoss 236ab882368SArun Ramadoss new_mtu += VLAN_ETH_HLEN + ETH_FCS_LEN; 237ab882368SArun Ramadoss 238ab882368SArun Ramadoss if (dsa_is_cpu_port(ds, port)) 239ab882368SArun Ramadoss new_mtu += LAN937X_TAG_LEN; 240ab882368SArun Ramadoss 241ab882368SArun Ramadoss if (new_mtu >= FR_MIN_SIZE) 242ab882368SArun Ramadoss ret = lan937x_port_cfg(dev, port, REG_PORT_MAC_CTRL_0, 243ab882368SArun Ramadoss PORT_JUMBO_PACKET, true); 244ab882368SArun Ramadoss else 245ab882368SArun Ramadoss ret = lan937x_port_cfg(dev, port, REG_PORT_MAC_CTRL_0, 246ab882368SArun Ramadoss PORT_JUMBO_PACKET, false); 247ab882368SArun Ramadoss if (ret < 0) { 248ab882368SArun Ramadoss dev_err(ds->dev, "failed to enable jumbo\n"); 249ab882368SArun Ramadoss return ret; 250ab882368SArun Ramadoss } 251ab882368SArun Ramadoss 252ab882368SArun Ramadoss /* Write the frame size in PORT_MAX_FR_SIZE register */ 253e06999c3SRakesh Sankaranarayanan ret = ksz_pwrite16(dev, port, PORT_MAX_FR_SIZE, new_mtu); 254e06999c3SRakesh Sankaranarayanan if (ret) { 255e06999c3SRakesh Sankaranarayanan dev_err(ds->dev, "failed to update mtu for port %d\n", port); 256e06999c3SRakesh Sankaranarayanan return ret; 257e06999c3SRakesh Sankaranarayanan } 258ab882368SArun Ramadoss 259ab882368SArun Ramadoss return 0; 260ab882368SArun Ramadoss } 261ab882368SArun Ramadoss 2622c119d99SArun Ramadoss int lan937x_set_ageing_time(struct ksz_device *dev, unsigned int msecs) 2632c119d99SArun Ramadoss { 2642c119d99SArun Ramadoss u32 secs = msecs / 1000; 2652c119d99SArun Ramadoss u32 value; 2662c119d99SArun Ramadoss int ret; 2672c119d99SArun Ramadoss 2682c119d99SArun Ramadoss value = FIELD_GET(SW_AGE_PERIOD_7_0_M, secs); 2692c119d99SArun Ramadoss 2702c119d99SArun Ramadoss ret = ksz_write8(dev, REG_SW_AGE_PERIOD__1, value); 2712c119d99SArun Ramadoss if (ret < 0) 2722c119d99SArun Ramadoss return ret; 2732c119d99SArun Ramadoss 2742c119d99SArun Ramadoss value = FIELD_GET(SW_AGE_PERIOD_19_8_M, secs); 2752c119d99SArun Ramadoss 2762c119d99SArun Ramadoss return ksz_write16(dev, REG_SW_AGE_PERIOD__2, value); 2772c119d99SArun Ramadoss } 2782c119d99SArun Ramadoss 279b19ac41fSArun Ramadoss static void lan937x_set_tune_adj(struct ksz_device *dev, int port, 280b19ac41fSArun Ramadoss u16 reg, u8 val) 281b19ac41fSArun Ramadoss { 282b19ac41fSArun Ramadoss u16 data16; 283b19ac41fSArun Ramadoss 284b19ac41fSArun Ramadoss ksz_pread16(dev, port, reg, &data16); 285b19ac41fSArun Ramadoss 286b19ac41fSArun Ramadoss /* Update tune Adjust */ 287b19ac41fSArun Ramadoss data16 |= FIELD_PREP(PORT_TUNE_ADJ, val); 288b19ac41fSArun Ramadoss ksz_pwrite16(dev, port, reg, data16); 289b19ac41fSArun Ramadoss 290b19ac41fSArun Ramadoss /* write DLL reset to take effect */ 291b19ac41fSArun Ramadoss data16 |= PORT_DLL_RESET; 292b19ac41fSArun Ramadoss ksz_pwrite16(dev, port, reg, data16); 293b19ac41fSArun Ramadoss } 294b19ac41fSArun Ramadoss 295b19ac41fSArun Ramadoss static void lan937x_set_rgmii_tx_delay(struct ksz_device *dev, int port) 296b19ac41fSArun Ramadoss { 297b19ac41fSArun Ramadoss u8 val; 298b19ac41fSArun Ramadoss 299b19ac41fSArun Ramadoss /* Apply different codes based on the ports as per characterization 300b19ac41fSArun Ramadoss * results 301b19ac41fSArun Ramadoss */ 302b19ac41fSArun Ramadoss val = (port == LAN937X_RGMII_1_PORT) ? RGMII_1_TX_DELAY_2NS : 303b19ac41fSArun Ramadoss RGMII_2_TX_DELAY_2NS; 304b19ac41fSArun Ramadoss 305b19ac41fSArun Ramadoss lan937x_set_tune_adj(dev, port, REG_PORT_XMII_CTRL_5, val); 306b19ac41fSArun Ramadoss } 307b19ac41fSArun Ramadoss 308b19ac41fSArun Ramadoss static void lan937x_set_rgmii_rx_delay(struct ksz_device *dev, int port) 309b19ac41fSArun Ramadoss { 310b19ac41fSArun Ramadoss u8 val; 311b19ac41fSArun Ramadoss 312b19ac41fSArun Ramadoss val = (port == LAN937X_RGMII_1_PORT) ? RGMII_1_RX_DELAY_2NS : 313b19ac41fSArun Ramadoss RGMII_2_RX_DELAY_2NS; 314b19ac41fSArun Ramadoss 315b19ac41fSArun Ramadoss lan937x_set_tune_adj(dev, port, REG_PORT_XMII_CTRL_4, val); 316b19ac41fSArun Ramadoss } 317b19ac41fSArun Ramadoss 318c14e878dSArun Ramadoss void lan937x_phylink_get_caps(struct ksz_device *dev, int port, 319c14e878dSArun Ramadoss struct phylink_config *config) 320c14e878dSArun Ramadoss { 321c14e878dSArun Ramadoss config->mac_capabilities = MAC_100FD; 322c14e878dSArun Ramadoss 323c14e878dSArun Ramadoss if (dev->info->supports_rgmii[port]) { 324c14e878dSArun Ramadoss /* MII/RMII/RGMII ports */ 325c14e878dSArun Ramadoss config->mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE | 326c14e878dSArun Ramadoss MAC_100HD | MAC_10 | MAC_1000FD; 327c14e878dSArun Ramadoss } 328c14e878dSArun Ramadoss } 329c14e878dSArun Ramadoss 330b19ac41fSArun Ramadoss void lan937x_setup_rgmii_delay(struct ksz_device *dev, int port) 331b19ac41fSArun Ramadoss { 332b19ac41fSArun Ramadoss struct ksz_port *p = &dev->ports[port]; 333b19ac41fSArun Ramadoss 334b19ac41fSArun Ramadoss if (p->rgmii_tx_val) { 335b19ac41fSArun Ramadoss lan937x_set_rgmii_tx_delay(dev, port); 336b19ac41fSArun Ramadoss dev_info(dev->dev, "Applied rgmii tx delay for the port %d\n", 337b19ac41fSArun Ramadoss port); 338b19ac41fSArun Ramadoss } 339b19ac41fSArun Ramadoss 340b19ac41fSArun Ramadoss if (p->rgmii_rx_val) { 341b19ac41fSArun Ramadoss lan937x_set_rgmii_rx_delay(dev, port); 342b19ac41fSArun Ramadoss dev_info(dev->dev, "Applied rgmii rx delay for the port %d\n", 343b19ac41fSArun Ramadoss port); 344b19ac41fSArun Ramadoss } 345b19ac41fSArun Ramadoss } 346b19ac41fSArun Ramadoss 34771d7920fSArun Ramadoss int lan937x_tc_cbs_set_cinc(struct ksz_device *dev, int port, u32 val) 34871d7920fSArun Ramadoss { 34971d7920fSArun Ramadoss return ksz_pwrite32(dev, port, REG_PORT_MTI_CREDIT_INCREMENT, val); 35071d7920fSArun Ramadoss } 35171d7920fSArun Ramadoss 352c9cd961cSArun Ramadoss int lan937x_switch_init(struct ksz_device *dev) 353c9cd961cSArun Ramadoss { 354c9cd961cSArun Ramadoss dev->port_mask = (1 << dev->info->port_cnt) - 1; 355c9cd961cSArun Ramadoss 356c9cd961cSArun Ramadoss return 0; 357c9cd961cSArun Ramadoss } 358c9cd961cSArun Ramadoss 35955ab6ffaSArun Ramadoss int lan937x_setup(struct dsa_switch *ds) 36055ab6ffaSArun Ramadoss { 36155ab6ffaSArun Ramadoss struct ksz_device *dev = ds->priv; 362ffaf1de2SArun Ramadoss int ret; 363ffaf1de2SArun Ramadoss 364ffaf1de2SArun Ramadoss /* enable Indirect Access from SPI to the VPHY registers */ 365ffaf1de2SArun Ramadoss ret = lan937x_enable_spi_indirect_access(dev); 366ffaf1de2SArun Ramadoss if (ret < 0) { 367ffaf1de2SArun Ramadoss dev_err(dev->dev, "failed to enable spi indirect access"); 368ffaf1de2SArun Ramadoss return ret; 369ffaf1de2SArun Ramadoss } 37055ab6ffaSArun Ramadoss 37155ab6ffaSArun Ramadoss /* The VLAN aware is a global setting. Mixed vlan 37255ab6ffaSArun Ramadoss * filterings are not supported. 37355ab6ffaSArun Ramadoss */ 37455ab6ffaSArun Ramadoss ds->vlan_filtering_is_global = true; 37555ab6ffaSArun Ramadoss 37655ab6ffaSArun Ramadoss /* Enable aggressive back off for half duplex & UNH mode */ 37755ab6ffaSArun Ramadoss lan937x_cfg(dev, REG_SW_MAC_CTRL_0, 37855ab6ffaSArun Ramadoss (SW_PAUSE_UNH_MODE | SW_NEW_BACKOFF | SW_AGGR_BACKOFF), 37955ab6ffaSArun Ramadoss true); 38055ab6ffaSArun Ramadoss 38155ab6ffaSArun Ramadoss /* If NO_EXC_COLLISION_DROP bit is set, the switch will not drop 38255ab6ffaSArun Ramadoss * packets when 16 or more collisions occur 38355ab6ffaSArun Ramadoss */ 38455ab6ffaSArun Ramadoss lan937x_cfg(dev, REG_SW_MAC_CTRL_1, NO_EXC_COLLISION_DROP, true); 38555ab6ffaSArun Ramadoss 38655ab6ffaSArun Ramadoss /* enable global MIB counter freeze function */ 38755ab6ffaSArun Ramadoss lan937x_cfg(dev, REG_SW_MAC_CTRL_6, SW_MIB_COUNTER_FREEZE, true); 38855ab6ffaSArun Ramadoss 38955ab6ffaSArun Ramadoss /* disable CLK125 & CLK25, 1: disable, 0: enable */ 39055ab6ffaSArun Ramadoss lan937x_cfg(dev, REG_SW_GLOBAL_OUTPUT_CTRL__1, 39155ab6ffaSArun Ramadoss (SW_CLK125_ENB | SW_CLK25_ENB), true); 39255ab6ffaSArun Ramadoss 39355ab6ffaSArun Ramadoss return 0; 39455ab6ffaSArun Ramadoss } 39555ab6ffaSArun Ramadoss 396c9cd961cSArun Ramadoss void lan937x_teardown(struct dsa_switch *ds) 39755ab6ffaSArun Ramadoss { 39855ab6ffaSArun Ramadoss 39955ab6ffaSArun Ramadoss } 40055ab6ffaSArun Ramadoss 40155ab6ffaSArun Ramadoss void lan937x_switch_exit(struct ksz_device *dev) 40255ab6ffaSArun Ramadoss { 40355ab6ffaSArun Ramadoss lan937x_reset_switch(dev); 40455ab6ffaSArun Ramadoss } 40555ab6ffaSArun Ramadoss 40655ab6ffaSArun Ramadoss MODULE_AUTHOR("Arun Ramadoss <arun.ramadoss@microchip.com>"); 40755ab6ffaSArun Ramadoss MODULE_DESCRIPTION("Microchip LAN937x Series Switch DSA Driver"); 40855ab6ffaSArun Ramadoss MODULE_LICENSE("GPL"); 409