[PATCH] Add bus_type probe, remove, shutdown methods.
authorRussell King <rmk@arm.linux.org.uk>
Thu, 5 Jan 2006 14:29:51 +0000 (14:29 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 13 Jan 2006 19:26:04 +0000 (11:26 -0800)
Add bus_type probe, remove and shutdown methods to replace the
corresponding methods in struct device_driver.  This matches
the way we handle the suspend/resume methods.

Since the bus methods override the device_driver methods, warn
if a device driver is registered whose methods will not be
called.

The long-term idea is to remove the device_driver methods entirely.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/base/dd.c
drivers/base/driver.c
drivers/base/power/shutdown.c
include/linux/device.h

index 2b905016664d9779439c4fa047507256b0cb2faf..730a9ce0a14a44d45c45fe34b15f1277157fe1d2 100644 (file)
@@ -78,7 +78,13 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
        pr_debug("%s: Matched Device %s with Driver %s\n",
                 drv->bus->name, dev->bus_id, drv->name);
        dev->driver = drv;
-       if (drv->probe) {
+       if (dev->bus->probe) {
+               ret = dev->bus->probe(dev);
+               if (ret) {
+                       dev->driver = NULL;
+                       goto ProbeFailed;
+               }
+       } else if (drv->probe) {
                ret = drv->probe(dev);
                if (ret) {
                        dev->driver = NULL;
@@ -203,7 +209,9 @@ static void __device_release_driver(struct device * dev)
                sysfs_remove_link(&dev->kobj, "driver");
                klist_remove(&dev->knode_driver);
 
-               if (drv->remove)
+               if (dev->bus->remove)
+                       dev->bus->remove(dev);
+               else if (drv->remove)
                        drv->remove(dev);
                dev->driver = NULL;
                put_driver(drv);
index 161f3a390d90651973a8a738446b3b7330950a09..b400314e1c62d46d9d2dc047cb76a08292b7f9ff 100644 (file)
@@ -171,6 +171,11 @@ static void klist_devices_put(struct klist_node *n)
  */
 int driver_register(struct device_driver * drv)
 {
+       if ((drv->bus->probe && drv->probe) ||
+           (drv->bus->remove && drv->remove) ||
+           (drv->bus->shutdown && drv->shutdown)) {
+               printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
+       }
        klist_init(&drv->klist_devices, klist_devices_get, klist_devices_put);
        init_completion(&drv->unloaded);
        return bus_add_driver(drv);
index f50a08be424b1c524122b19ba769342f38caf02b..a47bb74da72b930cfe9a69ad11105c6b978c3b6d 100644 (file)
@@ -40,7 +40,10 @@ void device_shutdown(void)
        down_write(&devices_subsys.rwsem);
        list_for_each_entry_reverse(dev, &devices_subsys.kset.list,
                                kobj.entry) {
-               if (dev->driver && dev->driver->shutdown) {
+               if (dev->bus && dev->bus->shutdown) {
+                       dev_dbg(dev, "shutdown\n");
+                       dev->bus->shutdown(dev);
+               } else if (dev->driver && dev->driver->shutdown) {
                        dev_dbg(dev, "shutdown\n");
                        dev->driver->shutdown(dev);
                }
index 0cdee78e5ce16f790142ae146f30d30927fe133a..58df18d9cd3ebe4f218d1d13d119293879a77088 100644 (file)
@@ -49,6 +49,9 @@ struct bus_type {
        int             (*match)(struct device * dev, struct device_driver * drv);
        int             (*uevent)(struct device *dev, char **envp,
                                  int num_envp, char *buffer, int buffer_size);
+       int             (*probe)(struct device * dev);
+       int             (*remove)(struct device * dev);
+       void            (*shutdown)(struct device * dev);
        int             (*suspend)(struct device * dev, pm_message_t state);
        int             (*resume)(struct device * dev);
 };