]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/input/input.c
Driver core: change add_uevent_var to use a struct
[linux-2.6-omap-h63xx.git] / drivers / input / input.c
index 915e9ab7cab0faad95ad5391b9493eb946bb1d7f..5dc361c954e2aa92a3632117bdd4575bc9f23382 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include <linux/init.h>
-#include <linux/smp_lock.h>
 #include <linux/input.h>
 #include <linux/module.h>
 #include <linux/random.h>
@@ -443,7 +442,7 @@ static int input_attach_handler(struct input_dev *dev, struct input_handler *han
                printk(KERN_ERR
                        "input: failed to attach handler %s to device %s, "
                        "error: %d\n",
-                       handler->name, kobject_name(&dev->cdev.kobj), error);
+                       handler->name, kobject_name(&dev->dev.kobj), error);
 
        return error;
 }
@@ -472,37 +471,16 @@ static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait)
        return 0;
 }
 
-static struct list_head *list_get_nth_element(struct list_head *list, loff_t *pos)
-{
-       struct list_head *node;
-       loff_t i = 0;
-
-       list_for_each(node, list)
-               if (i++ == *pos)
-                       return node;
-
-       return NULL;
-}
-
-static struct list_head *list_get_next_element(struct list_head *list, struct list_head *element, loff_t *pos)
-{
-       if (element->next == list)
-               return NULL;
-
-       ++(*pos);
-       return element->next;
-}
-
 static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
 {
        /* acquire lock here ... Yes, we do need locking, I knowi, I know... */
 
-       return list_get_nth_element(&input_dev_list, pos);
+       return seq_list_start(&input_dev_list, *pos);
 }
 
 static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
-       return list_get_next_element(&input_dev_list, v, pos);
+       return seq_list_next(v, &input_dev_list, pos);
 }
 
 static void input_devices_seq_stop(struct seq_file *seq, void *v)
@@ -528,7 +506,7 @@ static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
 static int input_devices_seq_show(struct seq_file *seq, void *v)
 {
        struct input_dev *dev = container_of(v, struct input_dev, node);
-       const char *path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
+       const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
        struct input_handle *handle;
 
        seq_printf(seq, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
@@ -593,13 +571,13 @@ static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
 {
        /* acquire lock here ... Yes, we do need locking, I knowi, I know... */
        seq->private = (void *)(unsigned long)*pos;
-       return list_get_nth_element(&input_handler_list, pos);
+       return seq_list_start(&input_handler_list, *pos);
 }
 
 static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
        seq->private = (void *)(unsigned long)(*pos + 1);
-       return list_get_next_element(&input_handler_list, v, pos);
+       return seq_list_next(v, &input_handler_list, pos);
 }
 
 static void input_handlers_seq_stop(struct seq_file *seq, void *v)
@@ -683,15 +661,17 @@ static inline int input_proc_init(void) { return 0; }
 static inline void input_proc_exit(void) { }
 #endif
 
-#define INPUT_DEV_STRING_ATTR_SHOW(name)                                       \
-static ssize_t input_dev_show_##name(struct class_device *dev, char *buf)      \
-{                                                                              \
-       struct input_dev *input_dev = to_input_dev(dev);                        \
-                                                                               \
-       return scnprintf(buf, PAGE_SIZE, "%s\n",                                \
-                        input_dev->name ? input_dev->name : "");               \
-}                                                                              \
-static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL);
+#define INPUT_DEV_STRING_ATTR_SHOW(name)                               \
+static ssize_t input_dev_show_##name(struct device *dev,               \
+                                    struct device_attribute *attr,     \
+                                    char *buf)                         \
+{                                                                      \
+       struct input_dev *input_dev = to_input_dev(dev);                \
+                                                                       \
+       return scnprintf(buf, PAGE_SIZE, "%s\n",                        \
+                        input_dev->name ? input_dev->name : "");       \
+}                                                                      \
+static DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL)
 
 INPUT_DEV_STRING_ATTR_SHOW(name);
 INPUT_DEV_STRING_ATTR_SHOW(phys);
@@ -745,7 +725,9 @@ static int input_print_modalias(char *buf, int size, struct input_dev *id,
        return len;
 }
 
-static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf)
+static ssize_t input_dev_show_modalias(struct device *dev,
+                                      struct device_attribute *attr,
+                                      char *buf)
 {
        struct input_dev *id = to_input_dev(dev);
        ssize_t len;
@@ -754,13 +736,13 @@ static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf)
 
        return min_t(int, len, PAGE_SIZE);
 }
-static CLASS_DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
+static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
 
 static struct attribute *input_dev_attrs[] = {
-       &class_device_attr_name.attr,
-       &class_device_attr_phys.attr,
-       &class_device_attr_uniq.attr,
-       &class_device_attr_modalias.attr,
+       &dev_attr_name.attr,
+       &dev_attr_phys.attr,
+       &dev_attr_uniq.attr,
+       &dev_attr_modalias.attr,
        NULL
 };
 
@@ -768,13 +750,15 @@ static struct attribute_group input_dev_attr_group = {
        .attrs  = input_dev_attrs,
 };
 
-#define INPUT_DEV_ID_ATTR(name)                                                        \
-static ssize_t input_dev_show_id_##name(struct class_device *dev, char *buf)   \
-{                                                                              \
-       struct input_dev *input_dev = to_input_dev(dev);                        \
-       return scnprintf(buf, PAGE_SIZE, "%04x\n", input_dev->id.name);         \
-}                                                                              \
-static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL);
+#define INPUT_DEV_ID_ATTR(name)                                                \
+static ssize_t input_dev_show_id_##name(struct device *dev,            \
+                                       struct device_attribute *attr,  \
+                                       char *buf)                      \
+{                                                                      \
+       struct input_dev *input_dev = to_input_dev(dev);                \
+       return scnprintf(buf, PAGE_SIZE, "%04x\n", input_dev->id.name); \
+}                                                                      \
+static DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL)
 
 INPUT_DEV_ID_ATTR(bustype);
 INPUT_DEV_ID_ATTR(vendor);
@@ -782,10 +766,10 @@ INPUT_DEV_ID_ATTR(product);
 INPUT_DEV_ID_ATTR(version);
 
 static struct attribute *input_dev_id_attrs[] = {
-       &class_device_attr_bustype.attr,
-       &class_device_attr_vendor.attr,
-       &class_device_attr_product.attr,
-       &class_device_attr_version.attr,
+       &dev_attr_bustype.attr,
+       &dev_attr_vendor.attr,
+       &dev_attr_product.attr,
+       &dev_attr_version.attr,
        NULL
 };
 
@@ -814,15 +798,17 @@ static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
        return len;
 }
 
-#define INPUT_DEV_CAP_ATTR(ev, bm)                                             \
-static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf)    \
-{                                                                              \
-       struct input_dev *input_dev = to_input_dev(dev);                        \
-       int len = input_print_bitmap(buf, PAGE_SIZE,                            \
-                                    input_dev->bm##bit, ev##_MAX, 1);          \
-       return min_t(int, len, PAGE_SIZE);                                      \
-}                                                                              \
-static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL);
+#define INPUT_DEV_CAP_ATTR(ev, bm)                                     \
+static ssize_t input_dev_show_cap_##bm(struct device *dev,             \
+                                      struct device_attribute *attr,   \
+                                      char *buf)                       \
+{                                                                      \
+       struct input_dev *input_dev = to_input_dev(dev);                \
+       int len = input_print_bitmap(buf, PAGE_SIZE,                    \
+                                    input_dev->bm##bit, ev##_MAX, 1);  \
+       return min_t(int, len, PAGE_SIZE);                              \
+}                                                                      \
+static DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL)
 
 INPUT_DEV_CAP_ATTR(EV, ev);
 INPUT_DEV_CAP_ATTR(KEY, key);
@@ -835,15 +821,15 @@ INPUT_DEV_CAP_ATTR(FF, ff);
 INPUT_DEV_CAP_ATTR(SW, sw);
 
 static struct attribute *input_dev_caps_attrs[] = {
-       &class_device_attr_ev.attr,
-       &class_device_attr_key.attr,
-       &class_device_attr_rel.attr,
-       &class_device_attr_abs.attr,
-       &class_device_attr_msc.attr,
-       &class_device_attr_led.attr,
-       &class_device_attr_snd.attr,
-       &class_device_attr_ff.attr,
-       &class_device_attr_sw.attr,
+       &dev_attr_ev.attr,
+       &dev_attr_key.attr,
+       &dev_attr_rel.attr,
+       &dev_attr_abs.attr,
+       &dev_attr_msc.attr,
+       &dev_attr_led.attr,
+       &dev_attr_snd.attr,
+       &dev_attr_ff.attr,
+       &dev_attr_sw.attr,
        NULL
 };
 
@@ -859,9 +845,9 @@ static struct attribute_group *input_dev_attr_groups[] = {
        NULL
 };
 
-static void input_dev_release(struct class_device *class_dev)
+static void input_dev_release(struct device *device)
 {
-       struct input_dev *dev = to_input_dev(class_dev);
+       struct input_dev *dev = to_input_dev(device);
 
        input_ff_destroy(dev);
        kfree(dev);
@@ -873,87 +859,66 @@ static void input_dev_release(struct class_device *class_dev)
  * Input uevent interface - loading event handlers based on
  * device bitfields.
  */
-static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index,
-                                  char *buffer, int buffer_size, int *cur_len,
+static int input_add_uevent_bm_var(struct kobj_uevent_env *env,
                                   const char *name, unsigned long *bitmap, int max)
 {
-       if (*cur_index >= num_envp - 1)
-               return -ENOMEM;
-
-       envp[*cur_index] = buffer + *cur_len;
+       int len;
 
-       *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0), name);
-       if (*cur_len >= buffer_size)
+       if (add_uevent_var(env, "%s=", name))
                return -ENOMEM;
 
-       *cur_len += input_print_bitmap(buffer + *cur_len,
-                                       max(buffer_size - *cur_len, 0),
-                                       bitmap, max, 0) + 1;
-       if (*cur_len > buffer_size)
+       len = input_print_bitmap(&env->buf[env->buflen - 1],
+                                sizeof(env->buf) - env->buflen,
+                                bitmap, max, 0);
+       if (len >= (sizeof(env->buf) - env->buflen))
                return -ENOMEM;
 
-       (*cur_index)++;
+       env->buflen += len;
        return 0;
 }
 
-static int input_add_uevent_modalias_var(char **envp, int num_envp, int *cur_index,
-                                        char *buffer, int buffer_size, int *cur_len,
+static int input_add_uevent_modalias_var(struct kobj_uevent_env *env,
                                         struct input_dev *dev)
 {
-       if (*cur_index >= num_envp - 1)
-               return -ENOMEM;
-
-       envp[*cur_index] = buffer + *cur_len;
+       int len;
 
-       *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0),
-                            "MODALIAS=");
-       if (*cur_len >= buffer_size)
+       if (add_uevent_var(env, "MODALIAS="))
                return -ENOMEM;
 
-       *cur_len += input_print_modalias(buffer + *cur_len,
-                                        max(buffer_size - *cur_len, 0),
-                                        dev, 0) + 1;
-       if (*cur_len > buffer_size)
+       len = input_print_modalias(&env->buf[env->buflen - 1],
+                                  sizeof(env->buf) - env->buflen,
+                                  dev, 0);
+       if (len >= (sizeof(env->buf) - env->buflen))
                return -ENOMEM;
 
-       (*cur_index)++;
+       env->buflen += len;
        return 0;
 }
 
 #define INPUT_ADD_HOTPLUG_VAR(fmt, val...)                             \
        do {                                                            \
-               int err = add_uevent_var(envp, num_envp, &i,            \
-                                       buffer, buffer_size, &len,      \
-                                       fmt, val);                      \
+               int err = add_uevent_var(env, fmt, val);                \
                if (err)                                                \
                        return err;                                     \
        } while (0)
 
 #define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max)                                \
        do {                                                            \
-               int err = input_add_uevent_bm_var(envp, num_envp, &i,   \
-                                       buffer, buffer_size, &len,      \
-                                       name, bm, max);                 \
+               int err = input_add_uevent_bm_var(env, name, bm, max);  \
                if (err)                                                \
                        return err;                                     \
        } while (0)
 
 #define INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev)                            \
        do {                                                            \
-               int err = input_add_uevent_modalias_var(envp,           \
-                                       num_envp, &i,                   \
-                                       buffer, buffer_size, &len,      \
-                                       dev);                           \
+               int err = input_add_uevent_modalias_var(env, dev);      \
                if (err)                                                \
                        return err;                                     \
        } while (0)
 
-static int input_dev_uevent(struct class_device *cdev, char **envp,
-                           int num_envp, char *buffer, int buffer_size)
+static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env)
 {
-       struct input_dev *dev = to_input_dev(cdev);
-       int i = 0;
-       int len = 0;
+       struct input_dev *dev = to_input_dev(device);
 
        INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x",
                                dev->id.bustype, dev->id.vendor,
@@ -985,14 +950,17 @@ static int input_dev_uevent(struct class_device *cdev, char **envp,
 
        INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev);
 
-       envp[i] = NULL;
        return 0;
 }
 
+static struct device_type input_dev_type = {
+       .groups         = input_dev_attr_groups,
+       .release        = input_dev_release,
+       .uevent         = input_dev_uevent,
+};
+
 struct class input_class = {
-       .name                   = "input",
-       .release                = input_dev_release,
-       .uevent                 = input_dev_uevent,
+       .name           = "input",
 };
 EXPORT_SYMBOL_GPL(input_class);
 
@@ -1011,9 +979,9 @@ struct input_dev *input_allocate_device(void)
 
        dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
        if (dev) {
-               dev->cdev.class = &input_class;
-               dev->cdev.groups = input_dev_attr_groups;
-               class_device_initialize(&dev->cdev);
+               dev->dev.type = &input_dev_type;
+               dev->dev.class = &input_class;
+               device_initialize(&dev->dev);
                mutex_init(&dev->mutex);
                INIT_LIST_HEAD(&dev->h_list);
                INIT_LIST_HEAD(&dev->node);
@@ -1132,17 +1100,17 @@ int input_register_device(struct input_dev *dev)
 
        list_add_tail(&dev->node, &input_dev_list);
 
-       snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
+       snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id),
                 "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
 
-       if (!dev->cdev.dev)
-               dev->cdev.dev = dev->dev.parent;
+       if (dev->cdev.dev)
+               dev->dev.parent = dev->cdev.dev;
 
-       error = class_device_add(&dev->cdev);
+       error = device_add(&dev->dev);
        if (error)
                return error;
 
-       path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
+       path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
        printk(KERN_INFO "input: %s as %s\n",
                dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
        kfree(path);
@@ -1174,7 +1142,7 @@ void input_unregister_device(struct input_dev *dev)
 
        list_del_init(&dev->node);
 
-       class_device_unregister(&dev->cdev);
+       device_unregister(&dev->dev);
 
        input_wakeup_procfs_readers();
 }