Skip to content

Commit

Permalink
net: dsa: Make mdio bus optional
Browse files Browse the repository at this point in the history
The switch may want to instantiate its own MDIO bus. Only do it
centrally if the switch has not already created one, and the read op
is implemented.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Andrew Lunn authored and David S. Miller committed Jun 4, 2016
1 parent 39a7f2a commit e755e49
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions net/dsa/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,18 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
if (ret < 0)
goto out;

ds->slave_mii_bus = devm_mdiobus_alloc(parent);
if (ds->slave_mii_bus == NULL) {
ret = -ENOMEM;
goto out;
}
dsa_slave_mii_bus_init(ds);

ret = mdiobus_register(ds->slave_mii_bus);
if (ret < 0)
goto out;
if (!ds->slave_mii_bus && drv->phy_read) {
ds->slave_mii_bus = devm_mdiobus_alloc(parent);
if (!ds->slave_mii_bus) {
ret = -ENOMEM;
goto out;
}
dsa_slave_mii_bus_init(ds);

ret = mdiobus_register(ds->slave_mii_bus);
if (ret < 0)
goto out;
}

/*
* Create network devices for physical switch ports.
Expand Down Expand Up @@ -493,7 +494,8 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
dsa_cpu_dsa_destroy(ds->ports[port].dn);
}

mdiobus_unregister(ds->slave_mii_bus);
if (ds->slave_mii_bus && ds->drv->phy_read)
mdiobus_unregister(ds->slave_mii_bus);
}

#ifdef CONFIG_PM_SLEEP
Expand Down

0 comments on commit e755e49

Please sign in to comment.