Commit 82e7b22f authored by David S. Miller's avatar David S. Miller

Merge branch 'user_mii_bus-cleanup-part-one'

Vladimir Oltean says:

====================
ds->user_mii_bus cleanup (part 1)

There are some drivers which assign ds->user_mii_bus when they
don't really need its specific functionality, aka non-OF based
dsa_user_phy_connect(). There was some confusion regarding the
fact that yes, this is why ds->user_mii_bus really exists, so
I've started a cleanup series which aims to eliminate the usage
of ds->user_mii_bus from drivers when there is nothing to gain
from it.

Today's drivers are lantiq_gswip, qca8k and bcm_sf2. The work is
not done here, but a "part 2" may or may not come, depending on
other priorities.

All patches were only compile-tested.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 94e2557d 45f62ca5
...@@ -621,8 +621,6 @@ static int bcm_sf2_mdio_register(struct dsa_switch *ds) ...@@ -621,8 +621,6 @@ static int bcm_sf2_mdio_register(struct dsa_switch *ds)
goto err_of_node_put; goto err_of_node_put;
} }
priv->master_mii_dn = dn;
priv->user_mii_bus = mdiobus_alloc(); priv->user_mii_bus = mdiobus_alloc();
if (!priv->user_mii_bus) { if (!priv->user_mii_bus) {
err = -ENOMEM; err = -ENOMEM;
...@@ -635,7 +633,6 @@ static int bcm_sf2_mdio_register(struct dsa_switch *ds) ...@@ -635,7 +633,6 @@ static int bcm_sf2_mdio_register(struct dsa_switch *ds)
priv->user_mii_bus->write = bcm_sf2_sw_mdio_write; priv->user_mii_bus->write = bcm_sf2_sw_mdio_write;
snprintf(priv->user_mii_bus->id, MII_BUS_ID_SIZE, "sf2-%d", snprintf(priv->user_mii_bus->id, MII_BUS_ID_SIZE, "sf2-%d",
index++); index++);
priv->user_mii_bus->dev.of_node = dn;
/* Include the pseudo-PHY address to divert reads towards our /* Include the pseudo-PHY address to divert reads towards our
* workaround. This is only required for 7445D0, since 7445E0 * workaround. This is only required for 7445D0, since 7445E0
...@@ -683,9 +680,11 @@ static int bcm_sf2_mdio_register(struct dsa_switch *ds) ...@@ -683,9 +680,11 @@ static int bcm_sf2_mdio_register(struct dsa_switch *ds)
} }
err = mdiobus_register(priv->user_mii_bus); err = mdiobus_register(priv->user_mii_bus);
if (err && dn) if (err)
goto err_free_user_mii_bus; goto err_free_user_mii_bus;
of_node_put(dn);
return 0; return 0;
err_free_user_mii_bus: err_free_user_mii_bus:
......
...@@ -107,7 +107,6 @@ struct bcm_sf2_priv { ...@@ -107,7 +107,6 @@ struct bcm_sf2_priv {
/* Master and slave MDIO bus controller */ /* Master and slave MDIO bus controller */
unsigned int indir_phy_mask; unsigned int indir_phy_mask;
struct device_node *master_mii_dn;
struct mii_bus *user_mii_bus; struct mii_bus *user_mii_bus;
struct mii_bus *master_mii_bus; struct mii_bus *master_mii_bus;
......
...@@ -505,27 +505,34 @@ static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg) ...@@ -505,27 +505,34 @@ static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg)
return gswip_mdio_r(priv, GSWIP_MDIO_READ); return gswip_mdio_r(priv, GSWIP_MDIO_READ);
} }
static int gswip_mdio(struct gswip_priv *priv, struct device_node *mdio_np) static int gswip_mdio(struct gswip_priv *priv)
{ {
struct dsa_switch *ds = priv->ds; struct device_node *mdio_np, *switch_np = priv->dev->of_node;
int err; struct device *dev = priv->dev;
struct mii_bus *bus;
int err = 0;
ds->user_mii_bus = mdiobus_alloc(); mdio_np = of_get_compatible_child(switch_np, "lantiq,xrx200-mdio");
if (!ds->user_mii_bus) if (!of_device_is_available(mdio_np))
return -ENOMEM; goto out_put_node;
bus = devm_mdiobus_alloc(dev);
if (!bus) {
err = -ENOMEM;
goto out_put_node;
}
ds->user_mii_bus->priv = priv; bus->priv = priv;
ds->user_mii_bus->read = gswip_mdio_rd; bus->read = gswip_mdio_rd;
ds->user_mii_bus->write = gswip_mdio_wr; bus->write = gswip_mdio_wr;
ds->user_mii_bus->name = "lantiq,xrx200-mdio"; bus->name = "lantiq,xrx200-mdio";
snprintf(ds->user_mii_bus->id, MII_BUS_ID_SIZE, "%s-mii", snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(priv->dev));
dev_name(priv->dev)); bus->parent = priv->dev;
ds->user_mii_bus->parent = priv->dev;
ds->user_mii_bus->phy_mask = ~ds->phys_mii_mask;
err = of_mdiobus_register(ds->user_mii_bus, mdio_np); err = devm_of_mdiobus_register(dev, bus, mdio_np);
if (err)
mdiobus_free(ds->user_mii_bus); out_put_node:
of_node_put(mdio_np);
return err; return err;
} }
...@@ -2094,9 +2101,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv, ...@@ -2094,9 +2101,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
static int gswip_probe(struct platform_device *pdev) static int gswip_probe(struct platform_device *pdev)
{ {
struct gswip_priv *priv; struct device_node *np, *gphy_fw_np;
struct device_node *np, *mdio_np, *gphy_fw_np;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct gswip_priv *priv;
int err; int err;
int i; int i;
u32 version; u32 version;
...@@ -2163,19 +2170,16 @@ static int gswip_probe(struct platform_device *pdev) ...@@ -2163,19 +2170,16 @@ static int gswip_probe(struct platform_device *pdev)
} }
/* bring up the mdio bus */ /* bring up the mdio bus */
mdio_np = of_get_compatible_child(dev->of_node, "lantiq,xrx200-mdio"); err = gswip_mdio(priv);
if (mdio_np) {
err = gswip_mdio(priv, mdio_np);
if (err) { if (err) {
dev_err(dev, "mdio probe failed\n"); dev_err(dev, "mdio probe failed\n");
goto put_mdio_node; goto gphy_fw_remove;
}
} }
err = dsa_register_switch(priv->ds); err = dsa_register_switch(priv->ds);
if (err) { if (err) {
dev_err(dev, "dsa switch register failed: %i\n", err); dev_err(dev, "dsa switch register failed: %i\n", err);
goto mdio_bus; goto gphy_fw_remove;
} }
if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) { if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) {
dev_err(dev, "wrong CPU port defined, HW only supports port: %i", dev_err(dev, "wrong CPU port defined, HW only supports port: %i",
...@@ -2194,13 +2198,7 @@ static int gswip_probe(struct platform_device *pdev) ...@@ -2194,13 +2198,7 @@ static int gswip_probe(struct platform_device *pdev)
disable_switch: disable_switch:
gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB);
dsa_unregister_switch(priv->ds); dsa_unregister_switch(priv->ds);
mdio_bus: gphy_fw_remove:
if (mdio_np) {
mdiobus_unregister(priv->ds->user_mii_bus);
mdiobus_free(priv->ds->user_mii_bus);
}
put_mdio_node:
of_node_put(mdio_np);
for (i = 0; i < priv->num_gphy_fw; i++) for (i = 0; i < priv->num_gphy_fw; i++)
gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
return err; return err;
...@@ -2219,12 +2217,6 @@ static void gswip_remove(struct platform_device *pdev) ...@@ -2219,12 +2217,6 @@ static void gswip_remove(struct platform_device *pdev)
dsa_unregister_switch(priv->ds); dsa_unregister_switch(priv->ds);
if (priv->ds->user_mii_bus) {
mdiobus_unregister(priv->ds->user_mii_bus);
of_node_put(priv->ds->user_mii_bus->dev.of_node);
mdiobus_free(priv->ds->user_mii_bus);
}
for (i = 0; i < priv->num_gphy_fw; i++) for (i = 0; i < priv->num_gphy_fw; i++)
gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
} }
......
...@@ -947,36 +947,49 @@ static int ...@@ -947,36 +947,49 @@ static int
qca8k_mdio_register(struct qca8k_priv *priv) qca8k_mdio_register(struct qca8k_priv *priv)
{ {
struct dsa_switch *ds = priv->ds; struct dsa_switch *ds = priv->ds;
struct device *dev = ds->dev;
struct device_node *mdio; struct device_node *mdio;
struct mii_bus *bus; struct mii_bus *bus;
int err = 0;
bus = devm_mdiobus_alloc(ds->dev); mdio = of_get_child_by_name(dev->of_node, "mdio");
if (!bus) if (mdio && !of_device_is_available(mdio))
return -ENOMEM; goto out;
bus = devm_mdiobus_alloc(dev);
if (!bus) {
err = -ENOMEM;
goto out_put_node;
}
priv->internal_mdio_bus = bus;
bus->priv = (void *)priv; bus->priv = (void *)priv;
snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d.%d", snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d.%d",
ds->dst->index, ds->index); ds->dst->index, ds->index);
bus->parent = ds->dev; bus->parent = dev;
bus->phy_mask = ~ds->phys_mii_mask;
ds->user_mii_bus = bus;
/* Check if the devicetree declare the port:phy mapping */ if (mdio) {
mdio = of_get_child_by_name(priv->dev->of_node, "mdio"); /* Check if the device tree declares the port:phy mapping */
if (of_device_is_available(mdio)) {
bus->name = "qca8k user mii"; bus->name = "qca8k user mii";
bus->read = qca8k_internal_mdio_read; bus->read = qca8k_internal_mdio_read;
bus->write = qca8k_internal_mdio_write; bus->write = qca8k_internal_mdio_write;
return devm_of_mdiobus_register(priv->dev, bus, mdio); } else {
} /* If a mapping can't be found, the legacy mapping is used,
* using qca8k_port_to_phy()
/* If a mapping can't be found the legacy mapping is used,
* using the qca8k_port_to_phy function
*/ */
ds->user_mii_bus = bus;
bus->phy_mask = ~ds->phys_mii_mask;
bus->name = "qca8k-legacy user mii"; bus->name = "qca8k-legacy user mii";
bus->read = qca8k_legacy_mdio_read; bus->read = qca8k_legacy_mdio_read;
bus->write = qca8k_legacy_mdio_write; bus->write = qca8k_legacy_mdio_write;
return devm_mdiobus_register(priv->dev, bus); }
err = devm_of_mdiobus_register(dev, bus, mdio);
out_put_node:
of_node_put(mdio);
out:
return err;
} }
static int static int
......
...@@ -366,7 +366,6 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p ...@@ -366,7 +366,6 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p
{ {
struct fwnode_handle *led = NULL, *leds = NULL; struct fwnode_handle *led = NULL, *leds = NULL;
struct led_init_data init_data = { }; struct led_init_data init_data = { };
struct dsa_switch *ds = priv->ds;
enum led_default_state state; enum led_default_state state;
struct qca8k_led *port_led; struct qca8k_led *port_led;
int led_num, led_index; int led_num, led_index;
...@@ -429,7 +428,8 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p ...@@ -429,7 +428,8 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p
init_data.default_label = ":port"; init_data.default_label = ":port";
init_data.fwnode = led; init_data.fwnode = led;
init_data.devname_mandatory = true; init_data.devname_mandatory = true;
init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d", ds->user_mii_bus->id, init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d",
priv->internal_mdio_bus->id,
port_num); port_num);
if (!init_data.devicename) if (!init_data.devicename)
return -ENOMEM; return -ENOMEM;
......
...@@ -454,6 +454,7 @@ struct qca8k_priv { ...@@ -454,6 +454,7 @@ struct qca8k_priv {
struct qca8k_ports_config ports_config; struct qca8k_ports_config ports_config;
struct regmap *regmap; struct regmap *regmap;
struct mii_bus *bus; struct mii_bus *bus;
struct mii_bus *internal_mdio_bus;
struct dsa_switch *ds; struct dsa_switch *ds;
struct mutex reg_mutex; struct mutex reg_mutex;
struct device *dev; struct device *dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment