Pārlūkot izejas kodu

net: dsa: Provide a slave MII bus if needed

Mimic what net/dsa/dsa.c does and provide a slave MII bus by default
which will be created if the driver implements a phy_read method.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Florian Fainelli 9 gadi atpakaļ
vecāks
revīzija
1eb59443e7
1 mainītis faili ar 15 papildinājumiem un 0 dzēšanām
  1. 15 0
      net/dsa/dsa2.c

+ 15 - 0
net/dsa/dsa2.c

@@ -312,6 +312,18 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
 	if (err < 0)
 	if (err < 0)
 		return err;
 		return err;
 
 
+	if (!ds->slave_mii_bus && ds->drv->phy_read) {
+		ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
+		if (!ds->slave_mii_bus)
+			return -ENOMEM;
+
+		dsa_slave_mii_bus_init(ds);
+
+		err = mdiobus_register(ds->slave_mii_bus);
+		if (err < 0)
+			return err;
+	}
+
 	for (index = 0; index < DSA_MAX_PORTS; index++) {
 	for (index = 0; index < DSA_MAX_PORTS; index++) {
 		port = ds->ports[index].dn;
 		port = ds->ports[index].dn;
 		if (!port)
 		if (!port)
@@ -361,6 +373,9 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
 
 
 		dsa_user_port_unapply(port, index, ds);
 		dsa_user_port_unapply(port, index, ds);
 	}
 	}
+
+	if (ds->slave_mii_bus && ds->drv->phy_read)
+		mdiobus_unregister(ds->slave_mii_bus);
 }
 }
 
 
 static int dsa_dst_apply(struct dsa_switch_tree *dst)
 static int dsa_dst_apply(struct dsa_switch_tree *dst)