Skip to contentSkip to conversation

net: mdio: Add mdio_free() and mdio_unregister() API

PATCH New Bin Meng 2 participants 9 messages Oct 8, 2015 – Oct 29, 2015 Network drivers

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH v2 1/4 net: mdio: Add mdio_free() and mdio_unregister() API

Currently there is no API to uninitialize mdio. Add two APIs for this.

---

Changes in v2: None

 common/miiphyutil.c | 19 +++++++++++++++++++
 include/miiphy.h    |  2 ++
 2 files changed, 21 insertions(+)
common/miiphyutil.c +19 -0
index c88c28a..e499b58 100644
@@ -152,6 +152,11 @@ struct mii_dev *mdio_alloc(void)
 	return bus;
 }
 
+void mdio_free(struct mii_dev *bus)
+{
+	free(bus);
+}
+
 int mdio_register(struct mii_dev *bus)
 {
 	if (!bus || !bus->name || !bus->read || !bus->write)
@@ -173,6 +178,20 @@ int mdio_register(struct mii_dev *bus)
 	return 0;
 }
 
+int mdio_unregister(struct mii_dev *bus)
+{
+	if (!bus)
+		return 0;
+
+	/* delete it from the list */
+	list_del(&bus->link);
+
+	if (current_mii == bus)
+		current_mii = NULL;
+
+	return 0;
+}
+
 void mdio_list_devices(void)
 {
 	struct list_head *entry;
include/miiphy.h +2 -0
index 088797e..af12274 100644
@@ -59,7 +59,9 @@ struct phy_device *mdio_phydev_for_ethname(const char *devname);
 void miiphy_listdev(void);
 
 struct mii_dev *mdio_alloc(void);
+void mdio_free(struct mii_dev *bus);
 int mdio_register(struct mii_dev *bus);
+int mdio_unregister(struct mii_dev *bus);
 void mdio_list_devices(void);
 
 #ifdef CONFIG_BITBANGMII
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH v2 2/4 net: designware: Add driver remove support

In designware_eth_probe(), some additional resources are allocated (eg: mdio, phy). We should free these in the driver remove phase. Add designware_eth_remove() to clean it up.

---

Changes in v2: None

 drivers/net/designware.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/designware.c +12 -0
index 6433896..a6c39c3 100644
@@ -613,6 +613,17 @@ static int designware_eth_probe(struct udevice *dev)
 	return ret;
 }
 
+static int designware_eth_remove(struct udevice *dev)
+{
+	struct dw_eth_dev *priv = dev_get_priv(dev);
+
+	free(priv->phydev);
+	mdio_unregister(priv->bus);
+	mdio_free(priv->bus);
+
+	return 0;
+}
+
 static const struct eth_ops designware_eth_ops = {
 	.start			= designware_eth_start,
 	.send			= designware_eth_send,
@@ -653,6 +664,7 @@ U_BOOT_DRIVER(eth_designware) = {
 	.ofdata_to_platdata = designware_eth_ofdata_to_platdata,
 	.bind	= designware_eth_bind,
 	.probe	= designware_eth_probe,
+	.remove	= designware_eth_remove,
 	.ops	= &designware_eth_ops,
 	.priv_auto_alloc_size = sizeof(struct dw_eth_dev),
 	.platdata_auto_alloc_size = sizeof(struct eth_pdata),
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH v2 2/4 net: designware: Add driver remove support

Quoted 6 lines · Bin Meng

In designware_eth_probe(), some additional resources are allocated (eg: mdio, phy). We should free these in the driver remove phase. Add designware_eth_remove() to clean it up.

Applied to u-boot-net/master, thanks!
-Joe

author
#3 lore raw

PATCH v2 3/4 net: pch_gbe: Add driver remove support

In reply to Bin Meng

In pch_gbe_probe(), some additional resources are allocated (eg: mdio, phy). We should free these in the driver remove phase. Add pch_gbe_remove() to clean it up.

---

Changes in v2: None

 drivers/net/pch_gbe.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/pch_gbe.c +12 -0
index 004fcf8..dfc0100 100644
@@ -452,6 +452,17 @@ int pch_gbe_probe(struct udevice *dev)
 	return pch_gbe_phy_init(dev);
 }
 
+int pch_gbe_remove(struct udevice *dev)
+{
+	struct pch_gbe_priv *priv = dev_get_priv(dev);
+
+	free(priv->phydev);
+	mdio_unregister(priv->bus);
+	mdio_free(priv->bus);
+
+	return 0;
+}
+
 static const struct eth_ops pch_gbe_ops = {
 	.start = pch_gbe_start,
 	.send = pch_gbe_send,
@@ -470,6 +481,7 @@ U_BOOT_DRIVER(eth_pch_gbe) = {
 	.id = UCLASS_ETH,
 	.of_match = pch_gbe_ids,
 	.probe = pch_gbe_probe,
+	.remove = pch_gbe_remove,
 	.ops = &pch_gbe_ops,
 	.priv_auto_alloc_size = sizeof(struct pch_gbe_priv),
 	.platdata_auto_alloc_size = sizeof(struct eth_pdata),
Signature · 1 line
1.8.2.1
author
#6 lore raw

PATCH v2 4/4 dm: core: Remove unnecessary codes in uclass_pre_remove_device()

In reply to Bin Meng

dev->uclass->uc_drv->per_device_auto_alloc_size is to be freed in device_free(), so is dev->seq. Remove these unnecessary codes.

---

Changes in v2:
- Drop the v1 patch: "dm: core: Remove the call to device_free()"

 drivers/core/uclass.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/core/uclass.c +0 -7
index e800c28..1af0947 100644
@@ -523,22 +523,15 @@ int uclass_post_probe_device(struct udevice *dev)
 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
 int uclass_pre_remove_device(struct udevice *dev)
 {
-	struct uclass_driver *uc_drv;
 	struct uclass *uc;
 	int ret;
 
 	uc = dev->uclass;
-	uc_drv = uc->uc_drv;
 	if (uc->uc_drv->pre_remove) {
 		ret = uc->uc_drv->pre_remove(dev);
 		if (ret)
 			return ret;
 	}
-	if (uc_drv->per_device_auto_alloc_size) {
-		free(dev->uclass_priv);
-		dev->uclass_priv = NULL;
-	}
-	dev->seq = -1;
 
 	return 0;
 }
Signature · 1 line
1.8.2.1