[PATCH] sky2: msi enhancements.
[safe/jmp/linux-2.6] / drivers / net / phy / phy_device.c
index 33f7bdb..2a08b2b 100644 (file)
@@ -14,7 +14,6 @@
  * option) any later version.
  *
  */
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/string.h>
@@ -30,7 +29,6 @@
 #include <linux/spinlock.h>
 #include <linux/mm.h>
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/mii.h>
 #include <linux/ethtool.h>
 #include <linux/phy.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
 
+MODULE_DESCRIPTION("PHY library");
+MODULE_AUTHOR("Andy Fleming");
+MODULE_LICENSE("GPL");
+
 static struct phy_driver genphy_driver;
 extern int mdio_bus_init(void);
 extern void mdio_bus_exit(void);
 
+struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
+{
+       struct phy_device *dev;
+       /* We allocate the device, and initialize the
+        * default values */
+       dev = kcalloc(1, sizeof(*dev), GFP_KERNEL);
+
+       if (NULL == dev)
+               return (struct phy_device*) PTR_ERR((void*)-ENOMEM);
+
+       dev->speed = 0;
+       dev->duplex = -1;
+       dev->pause = dev->asym_pause = 0;
+       dev->link = 1;
+
+       dev->autoneg = AUTONEG_ENABLE;
+
+       dev->addr = addr;
+       dev->phy_id = phy_id;
+       dev->bus = bus;
+
+       dev->state = PHY_DOWN;
+
+       spin_lock_init(&dev->lock);
+
+       return dev;
+}
+EXPORT_SYMBOL(phy_device_create);
+
 /* get_phy_device
  *
  * description: Reads the ID registers of the PHY at addr on the
@@ -76,32 +107,11 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr)
        if (0xffffffff == phy_id)
                return NULL;
 
-       /* Otherwise, we allocate the device, and initialize the
-        * default values */
-       dev = kcalloc(1, sizeof(*dev), GFP_KERNEL);
-
-       if (NULL == dev)
-               return ERR_PTR(-ENOMEM);
-
-       dev->speed = 0;
-       dev->duplex = -1;
-       dev->pause = dev->asym_pause = 0;
-       dev->link = 1;
-
-       dev->autoneg = AUTONEG_ENABLE;
-
-       dev->addr = addr;
-       dev->phy_id = phy_id;
-       dev->bus = bus;
-
-       dev->state = PHY_DOWN;
-
-       spin_lock_init(&dev->lock);
+       dev = phy_device_create(bus, addr, phy_id);
 
        return dev;
 }
 
-#ifdef CONFIG_PHYCONTROL
 /* phy_prepare_link:
  *
  * description: Tells the PHY infrastructure to handle the
@@ -160,8 +170,6 @@ void phy_disconnect(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(phy_disconnect);
 
-#endif /* CONFIG_PHYCONTROL */
-
 /* phy_attach:
  *
  *   description: Called by drivers to attach to a particular PHY
@@ -204,11 +212,13 @@ struct phy_device *phy_attach(struct net_device *dev,
 
                err = d->driver->probe(d);
 
-               if (err < 0)
-                       return ERR_PTR(err);
+               if (err >= 0)
+                       err = device_bind_driver(d);
 
-               device_bind_driver(d);
                up_write(&d->bus->subsys.rwsem);
+
+               if (err)
+                       return ERR_PTR(err);
        }
 
        if (phydev->attached_dev) {
@@ -417,6 +427,7 @@ int genphy_update_link(struct phy_device *phydev)
 
        return 0;
 }
+EXPORT_SYMBOL(genphy_update_link);
 
 /* genphy_read_status
  *
@@ -514,7 +525,7 @@ EXPORT_SYMBOL(genphy_read_status);
 
 static int genphy_config_init(struct phy_device *phydev)
 {
-       u32 val;
+       int val;
        u32 features;
 
        /* For now, I'll claim that the generic driver supports