Merge branch 'master' of http://git.denx.de/u-boot-sunxi
[oweals/u-boot.git] / common / miiphyutil.c
index 74812e6e1b959a0edf78801e1c3dd77116b027c2..7e41957185072123a81468309081ec4586730867 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <miiphy.h>
 #include <phy.h>
 
@@ -113,6 +114,8 @@ void miiphy_register(const char *name,
        if (new_dev == NULL || ldev == NULL) {
                printf("miiphy_register: cannot allocate memory for '%s'\n",
                        name);
+               free(ldev);
+               mdio_free(new_dev);
                return;
        }
 
@@ -151,9 +154,14 @@ 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)
+       if (!bus || !bus->read || !bus->write)
                return -1;
 
        /* check if we have unique name */
@@ -172,6 +180,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;