static int ksz8_setup(struct dsa_switch *ds)
 {
        struct ksz_device *dev = ds->priv;
-       int i, ret = 0;
-
-       dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
-                                      dev->info->num_vlans, GFP_KERNEL);
-       if (!dev->vlan_cache)
-               return -ENOMEM;
-
-       ret = dev->dev_ops->reset(dev);
-       if (ret) {
-               dev_err(ds->dev, "failed to reset switch\n");
-               return ret;
-       }
+       int i;
 
        ksz_cfg(dev, S_REPLACE_VID_CTRL, SW_FLOW_CTRL, true);
 
                           UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP,
                           UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP);
 
-       dev->dev_ops->config_cpu_port(ds);
-
        ksz_cfg(dev, REG_SW_CTRL_2, MULTICAST_STORM_DISABLE, true);
 
        ksz_cfg(dev, S_REPLACE_VID_CTRL, SW_REPLACE_VID, false);
        for (i = 0; i < (dev->info->num_vlans / 4); i++)
                ksz8_r_vlan_entries(dev, i);
 
-       dev->dev_ops->enable_stp_addr(dev);
-
-       ksz_init_mib_timer(dev);
-
-       ds->configure_vlan_while_not_filtering = false;
-
        return ksz8_handle_global_errata(ds);
 }
 
 static const struct dsa_switch_ops ksz8_switch_ops = {
        .get_tag_protocol       = ksz_get_tag_protocol,
        .get_phy_flags          = ksz_get_phy_flags,
-       .setup                  = ksz8_setup,
+       .setup                  = ksz_setup,
        .phy_read               = ksz_phy_read16,
        .phy_write              = ksz_phy_write16,
        .phylink_get_caps       = ksz_phylink_get_caps,
 }
 
 static const struct ksz_dev_ops ksz8_dev_ops = {
+       .setup = ksz8_setup,
        .get_port_addr = ksz8_get_port_addr,
        .cfg_port_member = ksz8_cfg_port_member,
        .flush_dyn_mac_table = ksz8_flush_dyn_mac_table,
 
        struct ksz_device *dev = ds->priv;
        int ret = 0;
 
-       dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
-                                      dev->info->num_vlans, GFP_KERNEL);
-       if (!dev->vlan_cache)
-               return -ENOMEM;
-
-       ret = dev->dev_ops->reset(dev);
-       if (ret) {
-               dev_err(ds->dev, "failed to reset switch\n");
-               return ret;
-       }
-
        /* Required for port partitioning. */
        ksz9477_cfg32(dev, REG_SW_QM_CTRL__4, UNICAST_VLAN_BOUNDARY,
                      true);
        if (ret)
                return ret;
 
-       dev->dev_ops->config_cpu_port(ds);
-
        ksz_cfg(dev, REG_SW_MAC_CTRL_1, MULTICAST_STORM_DISABLE, true);
 
        /* queue based egress rate limit */
        /* start switch */
        ksz_cfg(dev, REG_SW_OPERATION, SW_START, true);
 
-       dev->dev_ops->enable_stp_addr(dev);
-
-       ksz_init_mib_timer(dev);
-
-       ds->configure_vlan_while_not_filtering = false;
-
        return 0;
 }
 
 static const struct dsa_switch_ops ksz9477_switch_ops = {
        .get_tag_protocol       = ksz_get_tag_protocol,
-       .setup                  = ksz9477_setup,
+       .setup                  = ksz_setup,
        .phy_read               = ksz_phy_read16,
        .phy_write              = ksz_phy_write16,
        .phylink_mac_link_down  = ksz_mac_link_down,
 }
 
 static const struct ksz_dev_ops ksz9477_dev_ops = {
+       .setup = ksz9477_setup,
        .get_port_addr = ksz9477_get_port_addr,
        .cfg_port_member = ksz9477_cfg_port_member,
        .flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
 
        dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port);
 }
 
+int ksz_setup(struct dsa_switch *ds)
+{
+       struct ksz_device *dev = ds->priv;
+       int ret;
+
+       dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
+                                      dev->info->num_vlans, GFP_KERNEL);
+       if (!dev->vlan_cache)
+               return -ENOMEM;
+
+       ret = dev->dev_ops->reset(dev);
+       if (ret) {
+               dev_err(ds->dev, "failed to reset switch\n");
+               return ret;
+       }
+
+       dev->dev_ops->config_cpu_port(ds);
+
+       dev->dev_ops->enable_stp_addr(dev);
+
+       ksz_init_mib_timer(dev);
+
+       ds->configure_vlan_while_not_filtering = false;
+
+       if (dev->dev_ops->setup) {
+               ret = dev->dev_ops->setup(ds);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ksz_setup);
+
 static void port_r_cnt(struct ksz_device *dev, int port)
 {
        struct ksz_port_mib *mib = &dev->ports[port].mib;
 
 };
 
 struct ksz_dev_ops {
+       int (*setup)(struct dsa_switch *ds);
        u32 (*get_port_addr)(int port, int offset);
        void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
        void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
 
 /* Common DSA access functions */
 
+int ksz_setup(struct dsa_switch *ds);
 int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg);
 int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val);
 u32 ksz_get_phy_flags(struct dsa_switch *ds, int port);