Merge branch 'master' of git://git.denx.de/u-boot-atmel
[oweals/u-boot.git] / common / miiphyutil.c
index 74812e6e1b959a0edf78801e1c3dd77116b027c2..08aa854efe49bdea3ff3b1e4b948165ed93f21c6 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <miiphy.h>
 #include <phy.h>
 
@@ -64,77 +65,6 @@ void miiphy_init(void)
        current_mii = NULL;
 }
 
-static int legacy_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
-{
-       unsigned short val;
-       int ret;
-       struct legacy_mii_dev *ldev = bus->priv;
-
-       ret = ldev->read(bus->name, addr, reg, &val);
-
-       return ret ? -1 : (int)val;
-}
-
-static int legacy_miiphy_write(struct mii_dev *bus, int addr, int devad,
-                               int reg, u16 val)
-{
-       struct legacy_mii_dev *ldev = bus->priv;
-
-       return ldev->write(bus->name, addr, reg, val);
-}
-
-/*****************************************************************************
- *
- * Register read and write MII access routines for the device <name>.
- * This API is now deprecated. Please use mdio_alloc and mdio_register, instead.
- */
-void miiphy_register(const char *name,
-                     int (*read)(const char *devname, unsigned char addr,
-                                  unsigned char reg, unsigned short *value),
-                     int (*write)(const char *devname, unsigned char addr,
-                                   unsigned char reg, unsigned short value))
-{
-       struct mii_dev *new_dev;
-       struct legacy_mii_dev *ldev;
-
-       BUG_ON(strlen(name) >= MDIO_NAME_LEN);
-
-       /* check if we have unique name */
-       new_dev = miiphy_get_dev_by_name(name);
-       if (new_dev) {
-               printf("miiphy_register: non unique device name '%s'\n", name);
-               return;
-       }
-
-       /* allocate memory */
-       new_dev = mdio_alloc();
-       ldev = malloc(sizeof(*ldev));
-
-       if (new_dev == NULL || ldev == NULL) {
-               printf("miiphy_register: cannot allocate memory for '%s'\n",
-                       name);
-               return;
-       }
-
-       /* initalize mii_dev struct fields */
-       new_dev->read = legacy_miiphy_read;
-       new_dev->write = legacy_miiphy_write;
-       strncpy(new_dev->name, name, MDIO_NAME_LEN);
-       new_dev->name[MDIO_NAME_LEN - 1] = 0;
-       ldev->read = read;
-       ldev->write = write;
-       new_dev->priv = ldev;
-
-       debug("miiphy_register: added '%s', read=0x%08lx, write=0x%08lx\n",
-              new_dev->name, ldev->read, ldev->write);
-
-       /* add it to the list */
-       list_add_tail(&new_dev->link, &mii_devs);
-
-       if (!current_mii)
-               current_mii = new_dev;
-}
-
 struct mii_dev *mdio_alloc(void)
 {
        struct mii_dev *bus;
@@ -151,9 +81,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 +107,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;