From afdce75f1eaebcf358b7594ba7969aade105c3b0 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 22 Jun 2005 16:09:05 -0700 Subject: [PATCH] driver core: Add the ability to bind drivers to devices from userspace This adds a single file, "bind", to the sysfs directory of every driver registered with the driver core. To bind a device to a driver, write the bus id of the device you wish to bind to that specific driver to the "bind" file (remember to not add a trailing \n). If that bus id matches a device on that bus, and it does not currently have a driver bound to it, the probe sequence will be initiated with that driver and device. Note, this requires that the driver itself be willing and able to accept that device (usually through a device id type table). This patch does not make it possible to override the driver's id table. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'drivers/base/bus.c') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index fa41ee90a53a..7e17488271a8 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -160,6 +160,30 @@ static ssize_t driver_unbind(struct device_driver *drv, } static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); +/* + * Manually attach a device to a driver. + * Note: the driver must want to bind to the device, + * it is not possible to override the driver's id table. + */ +static ssize_t driver_bind(struct device_driver *drv, + const char *buf, size_t count) +{ + struct bus_type *bus = get_bus(drv->bus); + struct device *dev; + int err = -ENODEV; + + dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); + if ((dev) && + (dev->driver == NULL)) { + down(&dev->sem); + err = driver_probe_device(drv, dev); + up(&dev->sem); + put_device(dev); + } + return err; +} +static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); + static struct device * next_device(struct klist_iter * i) { @@ -425,6 +449,7 @@ int bus_add_driver(struct device_driver * drv) driver_add_attrs(bus, drv); driver_create_file(drv, &driver_attr_unbind); + driver_create_file(drv, &driver_attr_bind); } return error; } @@ -442,6 +467,7 @@ int bus_add_driver(struct device_driver * drv) void bus_remove_driver(struct device_driver * drv) { if (drv->bus) { + driver_remove_file(drv, &driver_attr_bind); driver_remove_file(drv, &driver_attr_unbind); driver_remove_attrs(drv->bus, drv); klist_remove(&drv->knode_bus); -- cgit v1.2.1