]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/input/serio/serio.c
Pull bsp-removal into release branch
[linux-2.6-omap-h63xx.git] / drivers / input / serio / serio.c
index f367695e69b5c78e35a66ca731369f3e67b0550f..2f76813c3a645c7d3d6a9e797df4525f19c6ac3d 100644 (file)
@@ -59,9 +59,7 @@ static DECLARE_MUTEX(serio_sem);
 
 static LIST_HEAD(serio_list);
 
-static struct bus_type serio_bus = {
-       .name = "serio",
-};
+static struct bus_type serio_bus;
 
 static void serio_add_port(struct serio *serio);
 static void serio_destroy_port(struct serio *serio);
@@ -269,14 +267,20 @@ static struct serio_event *serio_get_event(void)
        return event;
 }
 
-static void serio_handle_events(void)
+static void serio_handle_event(void)
 {
        struct serio_event *event;
        struct serio_driver *serio_drv;
 
        down(&serio_sem);
 
-       while ((event = serio_get_event())) {
+       /*
+        * Note that we handle only one event here to give swsusp
+        * a chance to freeze kseriod thread. Serio events should
+        * be pretty rare so we are not concerned about taking
+        * performance hit.
+        */
+       if ((event = serio_get_event())) {
 
                switch (event->type) {
                        case SERIO_REGISTER_PORT:
@@ -368,7 +372,7 @@ static struct serio *serio_get_pending_child(struct serio *parent)
 static int serio_thread(void *nothing)
 {
        do {
-               serio_handle_events();
+               serio_handle_event();
                wait_event_interruptible(serio_wait,
                        kthread_should_stop() || !list_empty(&serio_event_list));
                try_to_freeze();
@@ -389,6 +393,14 @@ static ssize_t serio_show_description(struct device *dev, struct device_attribut
        return sprintf(buf, "%s\n", serio->name);
 }
 
+static ssize_t serio_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct serio *serio = to_serio_port(dev);
+
+       return sprintf(buf, "serio:ty%02Xpr%02Xid%02Xex%02X\n",
+                       serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
+}
+
 static ssize_t serio_show_id_type(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct serio *serio = to_serio_port(dev);
@@ -487,6 +499,7 @@ static ssize_t serio_set_bind_mode(struct device *dev, struct device_attribute *
 
 static struct device_attribute serio_device_attrs[] = {
        __ATTR(description, S_IRUGO, serio_show_description, NULL),
+       __ATTR(modalias, S_IRUGO, serio_show_modalias, NULL),
        __ATTR(drvctl, S_IWUSR, NULL, serio_rebind_driver),
        __ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode),
        __ATTR_NULL
@@ -735,11 +748,15 @@ static int serio_driver_remove(struct device *dev)
        return 0;
 }
 
+static struct bus_type serio_bus = {
+       .name = "serio",
+       .probe = serio_driver_probe,
+       .remove = serio_driver_remove,
+};
+
 void __serio_register_driver(struct serio_driver *drv, struct module *owner)
 {
        drv->driver.bus = &serio_bus;
-       drv->driver.probe = serio_driver_probe;
-       drv->driver.remove = serio_driver_remove;
 
        serio_queue_event(drv, owner, SERIO_REGISTER_DRIVER);
 }
@@ -785,40 +802,41 @@ static int serio_bus_match(struct device *dev, struct device_driver *drv)
 
 #ifdef CONFIG_HOTPLUG
 
-#define PUT_ENVP(fmt, val)                                             \
-do {                                                                   \
-       envp[i++] = buffer;                                             \
-       length += snprintf(buffer, buffer_size - length, fmt, val);     \
-       if (buffer_size - length <= 0 || i >= num_envp)                 \
-               return -ENOMEM;                                         \
-       length++;                                                       \
-       buffer += length;                                               \
-} while (0)
-static int serio_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
+#define SERIO_ADD_UEVENT_VAR(fmt, val...)                              \
+       do {                                                            \
+               int err = add_uevent_var(envp, num_envp, &i,    \
+                                       buffer, buffer_size, &len,      \
+                                       fmt, val);                      \
+               if (err)                                                \
+                       return err;                                     \
+       } while (0)
+
+static int serio_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
 {
        struct serio *serio;
        int i = 0;
-       int length = 0;
+       int len = 0;
 
        if (!dev)
                return -ENODEV;
 
        serio = to_serio_port(dev);
 
-       PUT_ENVP("SERIO_TYPE=%02x", serio->id.type);
-       PUT_ENVP("SERIO_PROTO=%02x", serio->id.proto);
-       PUT_ENVP("SERIO_ID=%02x", serio->id.id);
-       PUT_ENVP("SERIO_EXTRA=%02x", serio->id.extra);
-
+       SERIO_ADD_UEVENT_VAR("SERIO_TYPE=%02x", serio->id.type);
+       SERIO_ADD_UEVENT_VAR("SERIO_PROTO=%02x", serio->id.proto);
+       SERIO_ADD_UEVENT_VAR("SERIO_ID=%02x", serio->id.id);
+       SERIO_ADD_UEVENT_VAR("SERIO_EXTRA=%02x", serio->id.extra);
+       SERIO_ADD_UEVENT_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
+                               serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
        envp[i] = NULL;
 
        return 0;
 }
-#undef PUT_ENVP
+#undef SERIO_ADD_UEVENT_VAR
 
 #else
 
-static int serio_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
+static int serio_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
 {
        return -ENODEV;
 }
@@ -892,7 +910,7 @@ static int __init serio_init(void)
        serio_bus.dev_attrs = serio_device_attrs;
        serio_bus.drv_attrs = serio_driver_attrs;
        serio_bus.match = serio_bus_match;
-       serio_bus.hotplug = serio_hotplug;
+       serio_bus.uevent = serio_uevent;
        serio_bus.resume = serio_resume;
        bus_register(&serio_bus);