public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dtor_core@ameritech.net>
To: Greg KH <greg@kroah.com>
Cc: LKML <linux-kernel@vger.kernel.org>, Patrick Mochel <mochel@osdl.org>
Subject: [PATCH 3/4] Driver core: add "driver" default attribute
Date: Tue, 12 Oct 2004 01:32:15 -0500	[thread overview]
Message-ID: <200410120132.18217.dtor_core@ameritech.net> (raw)
In-Reply-To: <200410120131.38330.dtor_core@ameritech.net>

#### AUTHOR dtor_core@ameritech.net
#### COMMENT START
### Comments for ChangeSet
Driver core: add "driver" default device attribute that produces
             name of the driver currently bound to the device and
             allows execution of bus-specific actions for device
             and driver via bus->rebind_helper()

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
### Comments for drivers/base/interface.c
Add "driver" default device attribute.
### Comments for include/linux/device.h
Add rebind_helper method to bus_type structure.
### Comments for drivers/input/serio/serio.c
Do not create "driver": attribute as driver core will create it for us;
install serio_rebind_driver as serio_bus's rebind_helper.
#### COMMENT END

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/10/11 00:39:53-05:00 dtor_core@ameritech.net 
#   Driver core: add "driver" default device attribute that produces
#                name of the driver currently bound to the device and
#                allows execution of bus-specific actions for device
#                and driver via bus->rebind_helper()
#   
#   Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
# 
# include/linux/device.h
#   2004/10/11 00:39:34-05:00 dtor_core@ameritech.net +2 -1
#   Add rebind_helper method to bus_type structure.
# 
# drivers/input/serio/serio.c
#   2004/10/11 00:39:34-05:00 dtor_core@ameritech.net +31 -36
#   Do not create "driver": attribute as driver core will create it for us;
#   install serio_rebind_driver as serio_bus's rebind_helper.
# 
# drivers/base/interface.c
#   2004/10/11 00:39:33-05:00 dtor_core@ameritech.net +30 -1
#   Add "driver" default device attribute.
# 
diff -Nru a/drivers/base/interface.c b/drivers/base/interface.c
--- a/drivers/base/interface.c	2004-10-12 01:29:06 -05:00
+++ b/drivers/base/interface.c	2004-10-12 01:29:06 -05:00
@@ -42,10 +42,39 @@
 	return n;
 }
 
-static DEVICE_ATTR(detach_state, 0644, detach_show, detach_store);
+/**
+ *	driver - controls device and driver binding.
+ *
+ *	Reading from the attribute gives name of driver that is bound to
+ *	the device or "(none)". Result of writing to the attribute depends
+ *	on the bus's rebind_helper implementation and can cause device to
+ *	be disconnected or be rebound to a specific driver.
+ */
+
+static ssize_t driver_show(struct device * dev, char * buf)
+{
+	return sprintf(buf, "%s\n", dev->driver ? dev->driver->name : "(none)");
+}
+
+static ssize_t driver_store(struct device * dev, const char * buf, size_t count)
+{
+	int retval = -ENOSYS;
+
+	if (dev->bus->rebind_helper)
+		retval = dev->bus->rebind_helper(dev, buf, count);
 
+	if (retval < 0)
+		return retval;
+
+	return count;
+}
+
+
+static DEVICE_ATTR(detach_state, 0644, detach_show, detach_store);
+static DEVICE_ATTR(driver, 0644, driver_show, driver_store);
 
 struct attribute * dev_default_attrs[] = {
 	&dev_attr_detach_state.attr,
+	&dev_attr_driver.attr,
 	NULL,
 };
diff -Nru a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
--- a/drivers/input/serio/serio.c	2004-10-12 01:29:06 -05:00
+++ b/drivers/input/serio/serio.c	2004-10-12 01:29:06 -05:00
@@ -246,41 +246,6 @@
 	return sprintf(buf, "%s\n", serio->name);
 }
 
-static ssize_t serio_show_driver(struct device *dev, char *buf)
-{
-	return sprintf(buf, "%s\n", dev->driver ? dev->driver->name : "(none)");
-}
-
-static ssize_t serio_rebind_driver(struct device *dev, const char *buf, size_t count)
-{
-	struct serio *serio = to_serio_port(dev);
-	struct device_driver *drv;
-	int retval;
-
-	retval = down_interruptible(&serio_sem);
-	if (retval)
-		return retval;
-
-	retval = count;
-	if (!strncmp(buf, "none", count)) {
-		serio_disconnect_port(serio);
-	} else if (!strncmp(buf, "reconnect", count)) {
-		serio_reconnect_port(serio);
-	} else if (!strncmp(buf, "rescan", count)) {
-		serio_disconnect_port(serio);
-		serio_connect_port(serio, NULL);
-	} else if ((drv = driver_find(buf, &serio_bus)) != NULL) {
-		serio_disconnect_port(serio);
-		serio_connect_port(serio, to_serio_driver(drv));
-		put_driver(drv);
-	} else {
-		retval = -EINVAL;
-	}
-
-	up(&serio_sem);
-
-	return retval;
-}
 
 static ssize_t serio_show_bind_mode(struct device *dev, char *buf)
 {
@@ -307,7 +272,6 @@
 
 static struct device_attribute serio_device_attrs[] = {
 	__ATTR(description, S_IRUGO, serio_show_description, NULL),
-	__ATTR(driver, S_IWUSR | S_IRUGO, serio_show_driver, serio_rebind_driver),
 	__ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode),
 	__ATTR_NULL
 };
@@ -596,6 +560,36 @@
 	up(&serio_sem);
 }
 
+static int serio_rebind_driver(struct device *dev, const char *buf, size_t count)
+{
+	struct serio *serio = to_serio_port(dev);
+	struct device_driver *drv;
+	int retval;
+
+	retval = down_interruptible(&serio_sem);
+	if (retval)
+		return retval;
+
+	if (!strncmp(buf, "none", count)) {
+		serio_disconnect_port(serio);
+	} else if (!strncmp(buf, "reconnect", count)) {
+		serio_reconnect_port(serio);
+	} else if (!strncmp(buf, "rescan", count)) {
+		serio_disconnect_port(serio);
+		serio_connect_port(serio, NULL);
+	} else if ((drv = driver_find(buf, &serio_bus)) != NULL) {
+		serio_disconnect_port(serio);
+		serio_connect_port(serio, to_serio_driver(drv));
+		put_driver(drv);
+	} else {
+		retval = -EINVAL;
+	}
+
+	up(&serio_sem);
+
+	return retval;
+}
+
 static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
 {
 	down(&serio->drv_sem);
@@ -660,6 +654,7 @@
 
 	serio_bus.dev_attrs = serio_device_attrs;
 	serio_bus.drv_attrs = serio_driver_attrs;
+	serio_bus.rebind_helper = serio_rebind_driver;
 	bus_register(&serio_bus);
 
 	return 0;
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h	2004-10-12 01:29:06 -05:00
+++ b/include/linux/device.h	2004-10-12 01:29:06 -05:00
@@ -59,7 +59,8 @@
 	struct driver_attribute	* drv_attrs;
 
 	int		(*match)(struct device * dev, struct device_driver * drv);
-	int		(*hotplug) (struct device *dev, char **envp, 
+	int		(*rebind_helper)(struct device * dev, const char * buf, size_t count);
+	int		(*hotplug) (struct device *dev, char **envp,
 				    int num_envp, char *buffer, int buffer_size);
 	int		(*suspend)(struct device * dev, u32 state);
 	int		(*resume)(struct device * dev);

  reply	other threads:[~2004-10-12  6:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-07  4:54 Driver core change request Dmitry Torokhov
2004-10-07 21:40 ` Greg KH
2004-10-08  2:59   ` Dmitry Torokhov
2004-10-08 21:48     ` Greg KH
2004-10-12  6:29       ` Dmitry Torokhov
2004-10-12  6:31         ` [PATCH 1/4] Driver core: export device_attach Dmitry Torokhov
2004-10-12  6:31           ` [PATCH 2/4] Driver core: add driver_probe_device Dmitry Torokhov
2004-10-12  6:32             ` Dmitry Torokhov [this message]
2004-10-12  6:33               ` [PATCH 4/4] Driver core: add "bind_mode" default attribute Dmitry Torokhov
2004-10-29 16:37             ` [PATCH 2/4] Driver core: add driver_probe_device Greg KH
2004-10-29 18:24               ` Dmitry Torokhov
2004-10-29 18:32                 ` Greg KH
2004-10-29 16:37           ` [PATCH 1/4] Driver core: export device_attach Greg KH
2004-10-21  7:05         ` Driver core change request Dmitry Torokhov
2004-10-21 14:50           ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200410120132.18217.dtor_core@ameritech.net \
    --to=dtor_core@ameritech.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mochel@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox