]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/net/phy/phy_device.c
phylib: Support phy module autoloading
[net-next-2.6.git] / drivers / net / phy / phy_device.c
index adbc0fded1305ecad1e44c22cd0fbb6f037d99b6..1a99bb2441064c5dae8014628bd718d033e752e6 100644 (file)
@@ -149,6 +149,7 @@ EXPORT_SYMBOL(phy_scan_fixups);
 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 = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -179,6 +180,17 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
        mutex_init(&dev->lock);
        INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
 
+       /* Request the appropriate module unconditionally; don't
+          bother trying to do so only if it isn't already loaded,
+          because that gets complicated. A hotplug event would have
+          done an unconditional modprobe anyway.
+          We don't do normal hotplug because it won't work for MDIO
+          -- because it relies on the device staying around for long
+          enough for the driver to get loaded. With MDIO, the NIC
+          driver will get bored and give up as soon as it finds that
+          there's no driver _already_ loaded. */
+       request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT, MDIO_ID_ARGS(phy_id));
+
        return dev;
 }
 EXPORT_SYMBOL(phy_device_create);
@@ -276,6 +288,22 @@ int phy_device_register(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(phy_device_register);
 
+/**
+ * phy_find_first - finds the first PHY device on the bus
+ * @bus: the target MII bus
+ */
+struct phy_device *phy_find_first(struct mii_bus *bus)
+{
+       int addr;
+
+       for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
+               if (bus->phy_map[addr])
+                       return bus->phy_map[addr];
+       }
+       return NULL;
+}
+EXPORT_SYMBOL(phy_find_first);
+
 /**
  * phy_prepare_link - prepares the PHY layer to monitor link status
  * @phydev: target phy_device struct