Input: prepare for f_ops constness
[powerpc.git] / drivers / input / input.c
index 1a1654c..fe33ff3 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/random.h>
 #include <linux/major.h>
 #include <linux/proc_fs.h>
-#include <linux/kobject_uevent.h>
 #include <linux/interrupt.h>
 #include <linux/poll.h>
 #include <linux/device.h>
@@ -377,7 +376,7 @@ static int input_devices_read(char *buf, char **start, off_t pos, int count, int
 
        list_for_each_entry(dev, &input_dev_list, node) {
 
-               path = dev->dynalloc ? kobject_get_path(&dev->cdev.kobj, GFP_KERNEL) : NULL;
+               path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
 
                len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
                        dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
@@ -478,8 +477,8 @@ static int __init input_proc_init(void)
 
        entry->owner = THIS_MODULE;
        input_fileops = *entry->proc_fops;
+       input_fileops.poll = input_devices_poll;
        entry->proc_fops = &input_fileops;
-       entry->proc_fops->poll = input_devices_poll;
 
        entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL);
        if (!entry)
@@ -529,14 +528,53 @@ INPUT_DEV_STRING_ATTR_SHOW(name);
 INPUT_DEV_STRING_ATTR_SHOW(phys);
 INPUT_DEV_STRING_ATTR_SHOW(uniq);
 
+static int print_modalias_bits(char *buf, char prefix, unsigned long *arr,
+                              unsigned int min, unsigned int max)
+{
+       int len, i;
+
+       len = sprintf(buf, "%c", prefix);
+       for (i = min; i < max; i++)
+               if (arr[LONG(i)] & BIT(i))
+                       len += sprintf(buf+len, "%X,", i);
+       return len;
+}
+
+static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf)
+{
+       struct input_dev *id = to_input_dev(dev);
+       ssize_t len = 0;
+
+       len += sprintf(buf+len, "input:b%04Xv%04Xp%04Xe%04X-",
+                      id->id.bustype,
+                      id->id.vendor,
+                      id->id.product,
+                      id->id.version);
+
+       len += print_modalias_bits(buf+len, 'e', id->evbit, 0, EV_MAX);
+       len += print_modalias_bits(buf+len, 'k', id->keybit,
+                                  KEY_MIN_INTERESTING, KEY_MAX);
+       len += print_modalias_bits(buf+len, 'r', id->relbit, 0, REL_MAX);
+       len += print_modalias_bits(buf+len, 'a', id->absbit, 0, ABS_MAX);
+       len += print_modalias_bits(buf+len, 'm', id->mscbit, 0, MSC_MAX);
+       len += print_modalias_bits(buf+len, 'l', id->ledbit, 0, LED_MAX);
+       len += print_modalias_bits(buf+len, 's', id->sndbit, 0, SND_MAX);
+       len += print_modalias_bits(buf+len, 'f', id->ffbit, 0, FF_MAX);
+       len += print_modalias_bits(buf+len, 'w', id->swbit, 0, SW_MAX);
+       len += sprintf(buf+len, "\n");
+       return len;
+}
+static CLASS_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,
        NULL
 };
 
-static struct attribute_group input_dev_group = {
+static struct attribute_group input_dev_attr_group = {
        .attrs  = input_dev_attrs,
 };
 
@@ -611,10 +649,10 @@ static void input_dev_release(struct class_device *class_dev)
 }
 
 /*
- * Input hotplugging interface - loading event handlers based on
+ * Input uevent interface - loading event handlers based on
  * device bitfields.
  */
-static int input_add_hotplug_bm_var(char **envp, int num_envp, int *cur_index,
+static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index,
                                    char *buffer, int buffer_size, int *cur_len,
                                    const char *name, unsigned long *bitmap, int max)
 {
@@ -639,7 +677,7 @@ static int input_add_hotplug_bm_var(char **envp, int num_envp, int *cur_index,
 
 #define INPUT_ADD_HOTPLUG_VAR(fmt, val...)                             \
        do {                                                            \
-               int err = add_hotplug_env_var(envp, num_envp, &i,       \
+               int err = add_uevent_var(envp, num_envp, &i,    \
                                        buffer, buffer_size, &len,      \
                                        fmt, val);                      \
                if (err)                                                \
@@ -648,15 +686,15 @@ static int input_add_hotplug_bm_var(char **envp, int num_envp, int *cur_index,
 
 #define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max)                                \
        do {                                                            \
-               int err = input_add_hotplug_bm_var(envp, num_envp, &i,  \
+               int err = input_add_uevent_bm_var(envp, num_envp, &i,   \
                                        buffer, buffer_size, &len,      \
                                        name, bm, max);                 \
                if (err)                                                \
                        return err;                                     \
        } while (0)
 
-static int input_dev_hotplug(struct class_device *cdev, char **envp,
-                            int num_envp, char *buffer, int buffer_size)
+static int input_dev_uevent(struct class_device *cdev, char **envp,
+                           int num_envp, char *buffer, int buffer_size)
 {
        struct input_dev *dev = to_input_dev(cdev);
        int i = 0;
@@ -669,7 +707,7 @@ static int input_dev_hotplug(struct class_device *cdev, char **envp,
                INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name);
        if (dev->phys)
                INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys);
-       if (dev->phys)
+       if (dev->uniq)
                INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq);
 
        INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX);
@@ -698,7 +736,7 @@ static int input_dev_hotplug(struct class_device *cdev, char **envp,
 struct class input_class = {
        .name                   = "input",
        .release                = input_dev_release,
-       .hotplug                = input_dev_hotplug,
+       .uevent                 = input_dev_uevent,
 };
 
 struct input_dev *input_allocate_device(void)
@@ -717,39 +755,24 @@ struct input_dev *input_allocate_device(void)
        return dev;
 }
 
-static void input_register_classdevice(struct input_dev *dev)
+int input_register_device(struct input_dev *dev)
 {
        static atomic_t input_no = ATOMIC_INIT(0);
-       const char *path;
-
-       __module_get(THIS_MODULE);
-
-       dev->dev = dev->cdev.dev;
-
-       snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
-                "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
-
-       path = kobject_get_path(&dev->cdev.class->subsys.kset.kobj, GFP_KERNEL);
-       printk(KERN_INFO "input: %s as %s/%s\n",
-               dev->name ? dev->name : "Unspecified device",
-               path ? path : "", dev->cdev.class_id);
-       kfree(path);
-
-       class_device_add(&dev->cdev);
-       sysfs_create_group(&dev->cdev.kobj, &input_dev_group);
-       sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group);
-       sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
-}
-
-void input_register_device(struct input_dev *dev)
-{
        struct input_handle *handle;
        struct input_handler *handler;
        struct input_device_id *id;
+       const char *path;
+       int error;
 
-       set_bit(EV_SYN, dev->evbit);
+       if (!dev->dynalloc) {
+               printk(KERN_WARNING "input: device %s is statically allocated, will not register\n"
+                       "Please convert to input_allocate_device() or contact dtor_core@ameritech.net\n",
+                       dev->name ? dev->name : "<Unknown>");
+               return -EINVAL;
+       }
 
        init_MUTEX(&dev->sem);
+       set_bit(EV_SYN, dev->evbit);
 
        /*
         * If delay and period are pre-set by the driver, then autorepeating
@@ -767,8 +790,32 @@ void input_register_device(struct input_dev *dev)
        INIT_LIST_HEAD(&dev->h_list);
        list_add_tail(&dev->node, &input_dev_list);
 
-       if (dev->dynalloc)
-               input_register_classdevice(dev);
+       dev->cdev.class = &input_class;
+       snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
+                "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
+
+       error = class_device_add(&dev->cdev);
+       if (error)
+               return error;
+
+       error = sysfs_create_group(&dev->cdev.kobj, &input_dev_attr_group);
+       if (error)
+               goto fail1;
+
+       error = sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group);
+       if (error)
+               goto fail2;
+
+       error = sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
+       if (error)
+               goto fail3;
+
+       __module_get(THIS_MODULE);
+
+       path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
+       printk(KERN_INFO "input: %s as %s\n",
+               dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
+       kfree(path);
 
        list_for_each_entry(handler, &input_handler_list, node)
                if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
@@ -776,8 +823,14 @@ void input_register_device(struct input_dev *dev)
                                if ((handle = handler->connect(handler, dev, id)))
                                        input_link_handle(handle);
 
-
        input_wakeup_procfs_readers();
+
+       return 0;
+
+ fail3:        sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
+ fail2:        sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
+ fail1:        class_device_del(&dev->cdev);
+       return error;
 }
 
 void input_unregister_device(struct input_dev *dev)
@@ -797,11 +850,10 @@ void input_unregister_device(struct input_dev *dev)
 
        list_del_init(&dev->node);
 
-       if (dev->dynalloc) {
-               sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
-               sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
-               class_device_unregister(&dev->cdev);
-       }
+       sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
+       sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
+       sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
+       class_device_unregister(&dev->cdev);
 
        input_wakeup_procfs_readers();
 }