diff options
| author | Dmitry Torokhov <[email protected]> | 2023-05-01 15:20:08 -0700 | 
|---|---|---|
| committer | Dmitry Torokhov <[email protected]> | 2023-05-01 15:20:08 -0700 | 
| commit | 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e (patch) | |
| tree | d57f3a63479a07b4e0cece029886e76e04feb984 /drivers/net/dsa/mt7530.c | |
| parent | 5dc63e56a9cf8df0b59c234a505a1653f1bdf885 (diff) | |
| parent | 53bea86b5712c7491bb3dae12e271666df0a308c (diff) | |
Merge branch 'next' into for-linus
Prepare input updates for 6.4 merge window.
Diffstat (limited to 'drivers/net/dsa/mt7530.c')
| -rw-r--r-- | drivers/net/dsa/mt7530.c | 148 | 
1 files changed, 83 insertions, 65 deletions
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 908fa89444c9..a508402c4ecb 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -393,6 +393,24 @@ mt7530_fdb_write(struct mt7530_priv *priv, u16 vid,  		mt7530_write(priv, MT7530_ATA1 + (i * 4), reg[i]);  } +/* Set up switch core clock for MT7530 */ +static void mt7530_pll_setup(struct mt7530_priv *priv) +{ +	/* Disable PLL */ +	core_write(priv, CORE_GSWPLL_GRP1, 0); + +	/* Set core clock into 500Mhz */ +	core_write(priv, CORE_GSWPLL_GRP2, +		   RG_GSWPLL_POSDIV_500M(1) | +		   RG_GSWPLL_FBKDIV_500M(25)); + +	/* Enable PLL */ +	core_write(priv, CORE_GSWPLL_GRP1, +		   RG_GSWPLL_EN_PRE | +		   RG_GSWPLL_POSDIV_200M(2) | +		   RG_GSWPLL_FBKDIV_200M(32)); +} +  /* Setup TX circuit including relevant PAD and driving */  static int  mt7530_pad_clk_setup(struct dsa_switch *ds, phy_interface_t interface) @@ -453,21 +471,6 @@ mt7530_pad_clk_setup(struct dsa_switch *ds, phy_interface_t interface)  	core_clear(priv, CORE_TRGMII_GSW_CLK_CG,  		   REG_GSWCK_EN | REG_TRGMIICK_EN); -	/* Setup core clock for MT7530 */ -	/* Disable PLL */ -	core_write(priv, CORE_GSWPLL_GRP1, 0); - -	/* Set core clock into 500Mhz */ -	core_write(priv, CORE_GSWPLL_GRP2, -		   RG_GSWPLL_POSDIV_500M(1) | -		   RG_GSWPLL_FBKDIV_500M(25)); - -	/* Enable PLL */ -	core_write(priv, CORE_GSWPLL_GRP1, -		   RG_GSWPLL_EN_PRE | -		   RG_GSWPLL_POSDIV_200M(2) | -		   RG_GSWPLL_FBKDIV_200M(32)); -  	/* Setup the MT7530 TRGMII Tx Clock */  	core_write(priv, CORE_PLL_GROUP5, RG_LCDDS_PCW_NCPO1(ncpo1));  	core_write(priv, CORE_PLL_GROUP6, RG_LCDDS_PCW_NCPO0(0)); @@ -608,17 +611,29 @@ mt7530_mib_reset(struct dsa_switch *ds)  	mt7530_write(priv, MT7530_MIB_CCR, CCR_MIB_ACTIVATE);  } -static int mt7530_phy_read(struct mt7530_priv *priv, int port, int regnum) +static int mt7530_phy_read_c22(struct mt7530_priv *priv, int port, int regnum)  {  	return mdiobus_read_nested(priv->bus, port, regnum);  } -static int mt7530_phy_write(struct mt7530_priv *priv, int port, int regnum, -			    u16 val) +static int mt7530_phy_write_c22(struct mt7530_priv *priv, int port, int regnum, +				u16 val)  {  	return mdiobus_write_nested(priv->bus, port, regnum, val);  } +static int mt7530_phy_read_c45(struct mt7530_priv *priv, int port, +			       int devad, int regnum) +{ +	return mdiobus_c45_read_nested(priv->bus, port, devad, regnum); +} + +static int mt7530_phy_write_c45(struct mt7530_priv *priv, int port, int devad, +				int regnum, u16 val) +{ +	return mdiobus_c45_write_nested(priv->bus, port, devad, regnum, val); +} +  static int  mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad,  			int regnum) @@ -670,7 +685,7 @@ out:  static int  mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, -			 int regnum, u32 data) +			 int regnum, u16 data)  {  	struct mii_bus *bus = priv->bus;  	struct mt7530_dummy_poll p; @@ -793,55 +808,36 @@ out:  }  static int -mt7531_ind_phy_read(struct mt7530_priv *priv, int port, int regnum) +mt753x_phy_read_c22(struct mii_bus *bus, int port, int regnum)  { -	int devad; -	int ret; - -	if (regnum & MII_ADDR_C45) { -		devad = (regnum >> MII_DEVADDR_C45_SHIFT) & 0x1f; -		ret = mt7531_ind_c45_phy_read(priv, port, devad, -					      regnum & MII_REGADDR_C45_MASK); -	} else { -		ret = mt7531_ind_c22_phy_read(priv, port, regnum); -	} +	struct mt7530_priv *priv = bus->priv; -	return ret; +	return priv->info->phy_read_c22(priv, port, regnum);  }  static int -mt7531_ind_phy_write(struct mt7530_priv *priv, int port, int regnum, -		     u16 data) +mt753x_phy_read_c45(struct mii_bus *bus, int port, int devad, int regnum)  { -	int devad; -	int ret; - -	if (regnum & MII_ADDR_C45) { -		devad = (regnum >> MII_DEVADDR_C45_SHIFT) & 0x1f; -		ret = mt7531_ind_c45_phy_write(priv, port, devad, -					       regnum & MII_REGADDR_C45_MASK, -					       data); -	} else { -		ret = mt7531_ind_c22_phy_write(priv, port, regnum, data); -	} +	struct mt7530_priv *priv = bus->priv; -	return ret; +	return priv->info->phy_read_c45(priv, port, devad, regnum);  }  static int -mt753x_phy_read(struct mii_bus *bus, int port, int regnum) +mt753x_phy_write_c22(struct mii_bus *bus, int port, int regnum, u16 val)  {  	struct mt7530_priv *priv = bus->priv; -	return priv->info->phy_read(priv, port, regnum); +	return priv->info->phy_write_c22(priv, port, regnum, val);  }  static int -mt753x_phy_write(struct mii_bus *bus, int port, int regnum, u16 val) +mt753x_phy_write_c45(struct mii_bus *bus, int port, int devad, int regnum, +		     u16 val)  {  	struct mt7530_priv *priv = bus->priv; -	return priv->info->phy_write(priv, port, regnum, val); +	return priv->info->phy_write_c45(priv, port, devad, regnum, val);  }  static void @@ -1309,14 +1305,26 @@ mt7530_port_set_vlan_aware(struct dsa_switch *ds, int port)  		if (!priv->ports[port].pvid)  			mt7530_rmw(priv, MT7530_PVC_P(port), ACC_FRM_MASK,  				   MT7530_VLAN_ACC_TAGGED); -	} -	/* Set the port as a user port which is to be able to recognize VID -	 * from incoming packets before fetching entry within the VLAN table. -	 */ -	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK | PVC_EG_TAG_MASK, -		   VLAN_ATTR(MT7530_VLAN_USER) | -		   PVC_EG_TAG(MT7530_VLAN_EG_DISABLED)); +		/* Set the port as a user port which is to be able to recognize +		 * VID from incoming packets before fetching entry within the +		 * VLAN table. +		 */ +		mt7530_rmw(priv, MT7530_PVC_P(port), +			   VLAN_ATTR_MASK | PVC_EG_TAG_MASK, +			   VLAN_ATTR(MT7530_VLAN_USER) | +			   PVC_EG_TAG(MT7530_VLAN_EG_DISABLED)); +	} else { +		/* Also set CPU ports to the "user" VLAN port attribute, to +		 * allow VLAN classification, but keep the EG_TAG attribute as +		 * "consistent" (i.o.w. don't change its value) for packets +		 * received by the switch from the CPU, so that tagged packets +		 * are forwarded to user ports as tagged, and untagged as +		 * untagged. +		 */ +		mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK, +			   VLAN_ATTR(MT7530_VLAN_USER)); +	}  }  static void @@ -2086,8 +2094,10 @@ mt7530_setup_mdio(struct mt7530_priv *priv)  	bus->priv = priv;  	bus->name = KBUILD_MODNAME "-mii";  	snprintf(bus->id, MII_BUS_ID_SIZE, KBUILD_MODNAME "-%d", idx++); -	bus->read = mt753x_phy_read; -	bus->write = mt753x_phy_write; +	bus->read = mt753x_phy_read_c22; +	bus->write = mt753x_phy_write_c22; +	bus->read_c45 = mt753x_phy_read_c45; +	bus->write_c45 = mt753x_phy_write_c45;  	bus->parent = dev;  	bus->phy_mask = ~ds->phys_mii_mask; @@ -2189,6 +2199,8 @@ mt7530_setup(struct dsa_switch *ds)  		     SYS_CTRL_PHY_RST | SYS_CTRL_SW_RST |  		     SYS_CTRL_REG_RST); +	mt7530_pll_setup(priv); +  	/* Enable Port 6 only; P5 as GMAC5 which currently is not supported */  	val = mt7530_read(priv, MT7530_MHWTRAP);  	val &= ~MHWTRAP_P6_DIS & ~MHWTRAP_PHY_ACCESS; @@ -3182,8 +3194,10 @@ static const struct mt753x_info mt753x_table[] = {  		.id = ID_MT7621,  		.pcs_ops = &mt7530_pcs_ops,  		.sw_setup = mt7530_setup, -		.phy_read = mt7530_phy_read, -		.phy_write = mt7530_phy_write, +		.phy_read_c22 = mt7530_phy_read_c22, +		.phy_write_c22 = mt7530_phy_write_c22, +		.phy_read_c45 = mt7530_phy_read_c45, +		.phy_write_c45 = mt7530_phy_write_c45,  		.pad_setup = mt7530_pad_clk_setup,  		.mac_port_get_caps = mt7530_mac_port_get_caps,  		.mac_port_config = mt7530_mac_config, @@ -3192,8 +3206,10 @@ static const struct mt753x_info mt753x_table[] = {  		.id = ID_MT7530,  		.pcs_ops = &mt7530_pcs_ops,  		.sw_setup = mt7530_setup, -		.phy_read = mt7530_phy_read, -		.phy_write = mt7530_phy_write, +		.phy_read_c22 = mt7530_phy_read_c22, +		.phy_write_c22 = mt7530_phy_write_c22, +		.phy_read_c45 = mt7530_phy_read_c45, +		.phy_write_c45 = mt7530_phy_write_c45,  		.pad_setup = mt7530_pad_clk_setup,  		.mac_port_get_caps = mt7530_mac_port_get_caps,  		.mac_port_config = mt7530_mac_config, @@ -3202,8 +3218,10 @@ static const struct mt753x_info mt753x_table[] = {  		.id = ID_MT7531,  		.pcs_ops = &mt7531_pcs_ops,  		.sw_setup = mt7531_setup, -		.phy_read = mt7531_ind_phy_read, -		.phy_write = mt7531_ind_phy_write, +		.phy_read_c22 = mt7531_ind_c22_phy_read, +		.phy_write_c22 = mt7531_ind_c22_phy_write, +		.phy_read_c45 = mt7531_ind_c45_phy_read, +		.phy_write_c45 = mt7531_ind_c45_phy_write,  		.pad_setup = mt7531_pad_setup,  		.cpu_port_config = mt7531_cpu_port_config,  		.mac_port_get_caps = mt7531_mac_port_get_caps, @@ -3263,7 +3281,7 @@ mt7530_probe(struct mdio_device *mdiodev)  	 * properly.  	 */  	if (!priv->info->sw_setup || !priv->info->pad_setup || -	    !priv->info->phy_read || !priv->info->phy_write || +	    !priv->info->phy_read_c22 || !priv->info->phy_write_c22 ||  	    !priv->info->mac_port_get_caps ||  	    !priv->info->mac_port_config)  		return -EINVAL;  |