aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-12 21:56:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-12 21:56:03 -0400
commit8bbbfa70549bd84f29ff331d0ac051897ccbbd72 (patch)
tree306640629d368960428326201098a881d7fd724f /drivers
parentbd81ccea8558daab570d70d2c23746413f26cecf (diff)
parent0cc8d6a9d23d6662da91eeb6bb8e7d1c559850f0 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
Pull input layer updates from Dmitry Torokhov: "2nd round of updates for the input subsystem. With it input core no longer limits number of character devices per event handler (such as evdev) to 32, but switches to dynamic minors once legacy range is exhausted. This should get multi-seat installations that currently run our of event devices very quickly. You will also get an update for Wacom driver and a couple of driver fixes." * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: Input: extend the number of event (and other) devices Input: mousedev - mark mousedev interfaces as non-seekable Input: mousedev - rename mixdev_open to opened_by_mixdev Input: mousedev - reformat structure initializers Input: mousedev - factor out psaux code to reduce #ifdefery Input: samsung-keypad - add clk_prepare and clk_unprepare Input: atmel_mxt_ts - simplify mxt_dump_message Input: wacom - clean up wacom_query_tablet_data Input: wacom - introduce wacom_fix_phy_from_hid Input: wacom - allow any multi-input Intuos device to set prox Input: wacom - report correct touch contact size for I5/Bamboo
Diffstat (limited to 'drivers')
-rw-r--r--drivers/input/evdev.c99
-rw-r--r--drivers/input/input.c114
-rw-r--r--drivers/input/joydev.c88
-rw-r--r--drivers/input/keyboard/samsung-keypad.c11
-rw-r--r--drivers/input/mousedev.c224
-rw-r--r--drivers/input/tablet/wacom_sys.c145
-rw-r--r--drivers/input/tablet/wacom_wac.c30
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c6
8 files changed, 375 insertions, 342 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 118d0300f1fb..6ae2ac47c9c8 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -23,11 +23,11 @@
23#include <linux/input/mt.h> 23#include <linux/input/mt.h>
24#include <linux/major.h> 24#include <linux/major.h>
25#include <linux/device.h> 25#include <linux/device.h>
26#include <linux/cdev.h>
26#include "input-compat.h" 27#include "input-compat.h"
27 28
28struct evdev { 29struct evdev {
29 int open; 30 int open;
30 int minor;
31 struct input_handle handle; 31 struct input_handle handle;
32 wait_queue_head_t wait; 32 wait_queue_head_t wait;
33 struct evdev_client __rcu *grab; 33 struct evdev_client __rcu *grab;
@@ -35,6 +35,7 @@ struct evdev {
35 spinlock_t client_lock; /* protects client_list */ 35 spinlock_t client_lock; /* protects client_list */
36 struct mutex mutex; 36 struct mutex mutex;
37 struct device dev; 37 struct device dev;
38 struct cdev cdev;
38 bool exist; 39 bool exist;
39}; 40};
40 41
@@ -51,9 +52,6 @@ struct evdev_client {
51 struct input_event buffer[]; 52 struct input_event buffer[];
52}; 53};
53 54
54static struct evdev *evdev_table[EVDEV_MINORS];
55static DEFINE_MUTEX(evdev_table_mutex);
56
57static void __pass_event(struct evdev_client *client, 55static void __pass_event(struct evdev_client *client,
58 const struct input_event *event) 56 const struct input_event *event)
59{ 57{
@@ -310,35 +308,16 @@ static unsigned int evdev_compute_buffer_size(struct input_dev *dev)
310 308
311static int evdev_open(struct inode *inode, struct file *file) 309static int evdev_open(struct inode *inode, struct file *file)
312{ 310{
313 struct evdev *evdev; 311 struct evdev *evdev = container_of(inode->i_cdev, struct evdev, cdev);
312 unsigned int bufsize = evdev_compute_buffer_size(evdev->handle.dev);
314 struct evdev_client *client; 313 struct evdev_client *client;
315 int i = iminor(inode) - EVDEV_MINOR_BASE;
316 unsigned int bufsize;
317 int error; 314 int error;
318 315
319 if (i >= EVDEV_MINORS)
320 return -ENODEV;
321
322 error = mutex_lock_interruptible(&evdev_table_mutex);
323 if (error)
324 return error;
325 evdev = evdev_table[i];
326 if (evdev)
327 get_device(&evdev->dev);
328 mutex_unlock(&evdev_table_mutex);
329
330 if (!evdev)
331 return -ENODEV;
332
333 bufsize = evdev_compute_buffer_size(evdev->handle.dev);
334
335 client = kzalloc(sizeof(struct evdev_client) + 316 client = kzalloc(sizeof(struct evdev_client) +
336 bufsize * sizeof(struct input_event), 317 bufsize * sizeof(struct input_event),
337 GFP_KERNEL); 318 GFP_KERNEL);
338 if (!client) { 319 if (!client)
339 error = -ENOMEM; 320 return -ENOMEM;
340 goto err_put_evdev;
341 }
342 321
343 client->bufsize = bufsize; 322 client->bufsize = bufsize;
344 spin_lock_init(&client->buffer_lock); 323 spin_lock_init(&client->buffer_lock);
@@ -352,13 +331,12 @@ static int evdev_open(struct inode *inode, struct file *file)
352 file->private_data = client; 331 file->private_data = client;
353 nonseekable_open(inode, file); 332 nonseekable_open(inode, file);
354 333
334 get_device(&evdev->dev);
355 return 0; 335 return 0;
356 336
357 err_free_client: 337 err_free_client:
358 evdev_detach_client(evdev, client); 338 evdev_detach_client(evdev, client);
359 kfree(client); 339 kfree(client);
360 err_put_evdev:
361 put_device(&evdev->dev);
362 return error; 340 return error;
363} 341}
364 342
@@ -942,26 +920,6 @@ static const struct file_operations evdev_fops = {
942 .llseek = no_llseek, 920 .llseek = no_llseek,
943}; 921};
944 922
945static int evdev_install_chrdev(struct evdev *evdev)
946{
947 /*
948 * No need to do any locking here as calls to connect and
949 * disconnect are serialized by the input core
950 */
951 evdev_table[evdev->minor] = evdev;
952 return 0;
953}
954
955static void evdev_remove_chrdev(struct evdev *evdev)
956{
957 /*
958 * Lock evdev table to prevent race with evdev_open()
959 */
960 mutex_lock(&evdev_table_mutex);
961 evdev_table[evdev->minor] = NULL;
962 mutex_unlock(&evdev_table_mutex);
963}
964
965/* 923/*
966 * Mark device non-existent. This disables writes, ioctls and 924 * Mark device non-existent. This disables writes, ioctls and
967 * prevents new users from opening the device. Already posted 925 * prevents new users from opening the device. Already posted
@@ -980,7 +938,8 @@ static void evdev_cleanup(struct evdev *evdev)
980 938
981 evdev_mark_dead(evdev); 939 evdev_mark_dead(evdev);
982 evdev_hangup(evdev); 940 evdev_hangup(evdev);
983 evdev_remove_chrdev(evdev); 941
942 cdev_del(&evdev->cdev);
984 943
985 /* evdev is marked dead so no one else accesses evdev->open */ 944 /* evdev is marked dead so no one else accesses evdev->open */
986 if (evdev->open) { 945 if (evdev->open) {
@@ -991,43 +950,47 @@ static void evdev_cleanup(struct evdev *evdev)
991 950
992/* 951/*
993 * Create new evdev device. Note that input core serializes calls 952 * Create new evdev device. Note that input core serializes calls
994 * to connect and disconnect so we don't need to lock evdev_table here. 953 * to connect and disconnect.
995 */ 954 */
996static int evdev_connect(struct input_handler *handler, struct input_dev *dev, 955static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
997 const struct input_device_id *id) 956 const struct input_device_id *id)
998{ 957{
999 struct evdev *evdev; 958 struct evdev *evdev;
1000 int minor; 959 int minor;
960 int dev_no;
1001 int error; 961 int error;
1002 962
1003 for (minor = 0; minor < EVDEV_MINORS; minor++) 963 minor = input_get_new_minor(EVDEV_MINOR_BASE, EVDEV_MINORS, true);
1004 if (!evdev_table[minor]) 964 if (minor < 0) {
1005 break; 965 error = minor;
1006 966 pr_err("failed to reserve new minor: %d\n", error);
1007 if (minor == EVDEV_MINORS) { 967 return error;
1008 pr_err("no more free evdev devices\n");
1009 return -ENFILE;
1010 } 968 }
1011 969
1012 evdev = kzalloc(sizeof(struct evdev), GFP_KERNEL); 970 evdev = kzalloc(sizeof(struct evdev), GFP_KERNEL);
1013 if (!evdev) 971 if (!evdev) {
1014 return -ENOMEM; 972 error = -ENOMEM;
973 goto err_free_minor;
974 }
1015 975
1016 INIT_LIST_HEAD(&evdev->client_list); 976 INIT_LIST_HEAD(&evdev->client_list);
1017 spin_lock_init(&evdev->client_lock); 977 spin_lock_init(&evdev->client_lock);
1018 mutex_init(&evdev->mutex); 978 mutex_init(&evdev->mutex);
1019 init_waitqueue_head(&evdev->wait); 979 init_waitqueue_head(&evdev->wait);
1020
1021 dev_set_name(&evdev->dev, "event%d", minor);
1022 evdev->exist = true; 980 evdev->exist = true;
1023 evdev->minor = minor; 981
982 dev_no = minor;
983 /* Normalize device number if it falls into legacy range */
984 if (dev_no < EVDEV_MINOR_BASE + EVDEV_MINORS)
985 dev_no -= EVDEV_MINOR_BASE;
986 dev_set_name(&evdev->dev, "event%d", dev_no);
1024 987
1025 evdev->handle.dev = input_get_device(dev); 988 evdev->handle.dev = input_get_device(dev);
1026 evdev->handle.name = dev_name(&evdev->dev); 989 evdev->handle.name = dev_name(&evdev->dev);
1027 evdev->handle.handler = handler; 990 evdev->handle.handler = handler;
1028 evdev->handle.private = evdev; 991 evdev->handle.private = evdev;
1029 992
1030 evdev->dev.devt = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor); 993 evdev->dev.devt = MKDEV(INPUT_MAJOR, minor);
1031 evdev->dev.class = &input_class; 994 evdev->dev.class = &input_class;
1032 evdev->dev.parent = &dev->dev; 995 evdev->dev.parent = &dev->dev;
1033 evdev->dev.release = evdev_free; 996 evdev->dev.release = evdev_free;
@@ -1037,7 +1000,8 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
1037 if (error) 1000 if (error)
1038 goto err_free_evdev; 1001 goto err_free_evdev;
1039 1002
1040 error = evdev_install_chrdev(evdev); 1003 cdev_init(&evdev->cdev, &evdev_fops);
1004 error = cdev_add(&evdev->cdev, evdev->dev.devt, 1);
1041 if (error) 1005 if (error)
1042 goto err_unregister_handle; 1006 goto err_unregister_handle;
1043 1007
@@ -1053,6 +1017,8 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
1053 input_unregister_handle(&evdev->handle); 1017 input_unregister_handle(&evdev->handle);
1054 err_free_evdev: 1018 err_free_evdev:
1055 put_device(&evdev->dev); 1019 put_device(&evdev->dev);
1020 err_free_minor:
1021 input_free_minor(minor);
1056 return error; 1022 return error;
1057} 1023}
1058 1024
@@ -1062,6 +1028,7 @@ static void evdev_disconnect(struct input_handle *handle)
1062 1028
1063 device_del(&evdev->dev); 1029 device_del(&evdev->dev);
1064 evdev_cleanup(evdev); 1030 evdev_cleanup(evdev);
1031 input_free_minor(MINOR(evdev->dev.devt));
1065 input_unregister_handle(handle); 1032 input_unregister_handle(handle);
1066 put_device(&evdev->dev); 1033 put_device(&evdev->dev);
1067} 1034}
@@ -1078,7 +1045,7 @@ static struct input_handler evdev_handler = {
1078 .events = evdev_events, 1045 .events = evdev_events,
1079 .connect = evdev_connect, 1046 .connect = evdev_connect,
1080 .disconnect = evdev_disconnect, 1047 .disconnect = evdev_disconnect,
1081 .fops = &evdev_fops, 1048 .legacy_minors = true,
1082 .minor = EVDEV_MINOR_BASE, 1049 .minor = EVDEV_MINOR_BASE,
1083 .name = "evdev", 1050 .name = "evdev",
1084 .id_table = evdev_ids, 1051 .id_table = evdev_ids,
diff --git a/drivers/input/input.c b/drivers/input/input.c
index ace3f7c4226d..53a0ddee7872 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/idr.h>
17#include <linux/input/mt.h> 18#include <linux/input/mt.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
@@ -32,7 +33,9 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
32MODULE_DESCRIPTION("Input core"); 33MODULE_DESCRIPTION("Input core");
33MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
34 35
35#define INPUT_DEVICES 256 36#define INPUT_MAX_CHAR_DEVICES 1024
37#define INPUT_FIRST_DYNAMIC_DEV 256
38static DEFINE_IDA(input_ida);
36 39
37static LIST_HEAD(input_dev_list); 40static LIST_HEAD(input_dev_list);
38static LIST_HEAD(input_handler_list); 41static LIST_HEAD(input_handler_list);
@@ -45,8 +48,6 @@ static LIST_HEAD(input_handler_list);
45 */ 48 */
46static DEFINE_MUTEX(input_mutex); 49static DEFINE_MUTEX(input_mutex);
47 50
48static struct input_handler *input_table[8];
49
50static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 }; 51static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };
51 52
52static inline int is_event_supported(unsigned int code, 53static inline int is_event_supported(unsigned int code,
@@ -1218,7 +1219,7 @@ static int input_handlers_seq_show(struct seq_file *seq, void *v)
1218 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); 1219 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name);
1219 if (handler->filter) 1220 if (handler->filter)
1220 seq_puts(seq, " (filter)"); 1221 seq_puts(seq, " (filter)");
1221 if (handler->fops) 1222 if (handler->legacy_minors)
1222 seq_printf(seq, " Minor=%d", handler->minor); 1223 seq_printf(seq, " Minor=%d", handler->minor);
1223 seq_putc(seq, '\n'); 1224 seq_putc(seq, '\n');
1224 1225
@@ -2016,22 +2017,14 @@ EXPORT_SYMBOL(input_unregister_device);
2016int input_register_handler(struct input_handler *handler) 2017int input_register_handler(struct input_handler *handler)
2017{ 2018{
2018 struct input_dev *dev; 2019 struct input_dev *dev;
2019 int retval; 2020 int error;
2020 2021
2021 retval = mutex_lock_interruptible(&input_mutex); 2022 error = mutex_lock_interruptible(&input_mutex);
2022 if (retval) 2023 if (error)
2023 return retval; 2024 return error;
2024 2025
2025 INIT_LIST_HEAD(&handler->h_list); 2026 INIT_LIST_HEAD(&handler->h_list);
2026 2027
2027 if (handler->fops != NULL) {
2028 if (input_table[handler->minor >> 5]) {
2029 retval = -EBUSY;
2030 goto out;
2031 }
2032 input_table[handler->minor >> 5] = handler;
2033 }
2034
2035 list_add_tail(&handler->node, &input_handler_list); 2028 list_add_tail(&handler->node, &input_handler_list);
2036 2029
2037 list_for_each_entry(dev, &input_dev_list, node) 2030 list_for_each_entry(dev, &input_dev_list, node)
@@ -2039,9 +2032,8 @@ int input_register_handler(struct input_handler *handler)
2039 2032
2040 input_wakeup_procfs_readers(); 2033 input_wakeup_procfs_readers();
2041 2034
2042 out:
2043 mutex_unlock(&input_mutex); 2035 mutex_unlock(&input_mutex);
2044 return retval; 2036 return 0;
2045} 2037}
2046EXPORT_SYMBOL(input_register_handler); 2038EXPORT_SYMBOL(input_register_handler);
2047 2039
@@ -2064,9 +2056,6 @@ void input_unregister_handler(struct input_handler *handler)
2064 2056
2065 list_del_init(&handler->node); 2057 list_del_init(&handler->node);
2066 2058
2067 if (handler->fops != NULL)
2068 input_table[handler->minor >> 5] = NULL;
2069
2070 input_wakeup_procfs_readers(); 2059 input_wakeup_procfs_readers();
2071 2060
2072 mutex_unlock(&input_mutex); 2061 mutex_unlock(&input_mutex);
@@ -2183,51 +2172,52 @@ void input_unregister_handle(struct input_handle *handle)
2183} 2172}
2184EXPORT_SYMBOL(input_unregister_handle); 2173EXPORT_SYMBOL(input_unregister_handle);
2185 2174
2186static int input_open_file(struct inode *inode, struct file *file) 2175/**
2176 * input_get_new_minor - allocates a new input minor number
2177 * @legacy_base: beginning or the legacy range to be searched
2178 * @legacy_num: size of legacy range
2179 * @allow_dynamic: whether we can also take ID from the dynamic range
2180 *
2181 * This function allocates a new device minor for from input major namespace.
2182 * Caller can request legacy minor by specifying @legacy_base and @legacy_num
2183 * parameters and whether ID can be allocated from dynamic range if there are
2184 * no free IDs in legacy range.
2185 */
2186int input_get_new_minor(int legacy_base, unsigned int legacy_num,
2187 bool allow_dynamic)
2187{ 2188{
2188 struct input_handler *handler;
2189 const struct file_operations *old_fops, *new_fops = NULL;
2190 int err;
2191
2192 err = mutex_lock_interruptible(&input_mutex);
2193 if (err)
2194 return err;
2195
2196 /* No load-on-demand here? */
2197 handler = input_table[iminor(inode) >> 5];
2198 if (handler)
2199 new_fops = fops_get(handler->fops);
2200
2201 mutex_unlock(&input_mutex);
2202
2203 /* 2189 /*
2204 * That's _really_ odd. Usually NULL ->open means "nothing special", 2190 * This function should be called from input handler's ->connect()
2205 * not "no device". Oh, well... 2191 * methods, which are serialized with input_mutex, so no additional
2192 * locking is needed here.
2206 */ 2193 */
2207 if (!new_fops || !new_fops->open) { 2194 if (legacy_base >= 0) {
2208 fops_put(new_fops); 2195 int minor = ida_simple_get(&input_ida,
2209 err = -ENODEV; 2196 legacy_base,
2210 goto out; 2197 legacy_base + legacy_num,
2198 GFP_KERNEL);
2199 if (minor >= 0 || !allow_dynamic)
2200 return minor;
2211 } 2201 }
2212 2202
2213 old_fops = file->f_op; 2203 return ida_simple_get(&input_ida,
2214 file->f_op = new_fops; 2204 INPUT_FIRST_DYNAMIC_DEV, INPUT_MAX_CHAR_DEVICES,
2215 2205 GFP_KERNEL);
2216 err = new_fops->open(inode, file);
2217 if (err) {
2218 fops_put(file->f_op);
2219 file->f_op = fops_get(old_fops);
2220 }
2221 fops_put(old_fops);
2222out:
2223 return err;
2224} 2206}
2207EXPORT_SYMBOL(input_get_new_minor);
2225 2208
2226static const struct file_operations input_fops = { 2209/**
2227 .owner = THIS_MODULE, 2210 * input_free_minor - release previously allocated minor
2228 .open = input_open_file, 2211 * @minor: minor to be released
2229 .llseek = noop_llseek, 2212 *
2230}; 2213 * This function releases previously allocated input minor so that it can be
2214 * reused later.
2215 */
2216void input_free_minor(unsigned int minor)
2217{
2218 ida_simple_remove(&input_ida, minor);
2219}
2220EXPORT_SYMBOL(input_free_minor);
2231 2221
2232static int __init input_init(void) 2222static int __init input_init(void)
2233{ 2223{
@@ -2243,7 +2233,8 @@ static int __init input_init(void)
2243 if (err) 2233 if (err)
2244 goto fail1; 2234 goto fail1;
2245 2235
2246 err = register_chrdev(INPUT_MAJOR, "input", &input_fops); 2236 err = register_chrdev_region(MKDEV(INPUT_MAJOR, 0),
2237 INPUT_MAX_CHAR_DEVICES, "input");
2247 if (err) { 2238 if (err) {
2248 pr_err("unable to register char major %d", INPUT_MAJOR); 2239 pr_err("unable to register char major %d", INPUT_MAJOR);
2249 goto fail2; 2240 goto fail2;
@@ -2259,7 +2250,8 @@ static int __init input_init(void)
2259static void __exit input_exit(void) 2250static void __exit input_exit(void)
2260{ 2251{
2261 input_proc_exit(); 2252 input_proc_exit();
2262 unregister_chrdev(INPUT_MAJOR, "input"); 2253 unregister_chrdev_region(MKDEV(INPUT_MAJOR, 0),
2254 INPUT_MAX_CHAR_DEVICES);
2263 class_unregister(&input_class); 2255 class_unregister(&input_class);
2264} 2256}
2265 2257
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 78f323ea1e4b..b62b5891f399 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -27,6 +27,7 @@
27#include <linux/poll.h> 27#include <linux/poll.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/device.h> 29#include <linux/device.h>
30#include <linux/cdev.h>
30 31
31MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 32MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
32MODULE_DESCRIPTION("Joystick device interfaces"); 33MODULE_DESCRIPTION("Joystick device interfaces");
@@ -39,13 +40,13 @@ MODULE_LICENSE("GPL");
39 40
40struct joydev { 41struct joydev {
41 int open; 42 int open;
42 int minor;
43 struct input_handle handle; 43 struct input_handle handle;
44 wait_queue_head_t wait; 44 wait_queue_head_t wait;
45 struct list_head client_list; 45 struct list_head client_list;
46 spinlock_t client_lock; /* protects client_list */ 46 spinlock_t client_lock; /* protects client_list */
47 struct mutex mutex; 47 struct mutex mutex;
48 struct device dev; 48 struct device dev;
49 struct cdev cdev;
49 bool exist; 50 bool exist;
50 51
51 struct js_corr corr[ABS_CNT]; 52 struct js_corr corr[ABS_CNT];
@@ -70,9 +71,6 @@ struct joydev_client {
70 struct list_head node; 71 struct list_head node;
71}; 72};
72 73
73static struct joydev *joydev_table[JOYDEV_MINORS];
74static DEFINE_MUTEX(joydev_table_mutex);
75
76static int joydev_correct(int value, struct js_corr *corr) 74static int joydev_correct(int value, struct js_corr *corr)
77{ 75{
78 switch (corr->type) { 76 switch (corr->type) {
@@ -252,30 +250,14 @@ static int joydev_release(struct inode *inode, struct file *file)
252 250
253static int joydev_open(struct inode *inode, struct file *file) 251static int joydev_open(struct inode *inode, struct file *file)
254{ 252{
253 struct joydev *joydev =
254 container_of(inode->i_cdev, struct joydev, cdev);
255 struct joydev_client *client; 255 struct joydev_client *client;
256 struct joydev *joydev;
257 int i = iminor(inode) - JOYDEV_MINOR_BASE;
258 int error; 256 int error;
259 257
260 if (i >= JOYDEV_MINORS)
261 return -ENODEV;
262
263 error = mutex_lock_interruptible(&joydev_table_mutex);
264 if (error)
265 return error;
266 joydev = joydev_table[i];
267 if (joydev)
268 get_device(&joydev->dev);
269 mutex_unlock(&joydev_table_mutex);
270
271 if (!joydev)
272 return -ENODEV;
273
274 client = kzalloc(sizeof(struct joydev_client), GFP_KERNEL); 258 client = kzalloc(sizeof(struct joydev_client), GFP_KERNEL);
275 if (!client) { 259 if (!client)
276 error = -ENOMEM; 260 return -ENOMEM;
277 goto err_put_joydev;
278 }
279 261
280 spin_lock_init(&client->buffer_lock); 262 spin_lock_init(&client->buffer_lock);
281 client->joydev = joydev; 263 client->joydev = joydev;
@@ -288,13 +270,12 @@ static int joydev_open(struct inode *inode, struct file *file)
288 file->private_data = client; 270 file->private_data = client;
289 nonseekable_open(inode, file); 271 nonseekable_open(inode, file);
290 272
273 get_device(&joydev->dev);
291 return 0; 274 return 0;
292 275
293 err_free_client: 276 err_free_client:
294 joydev_detach_client(joydev, client); 277 joydev_detach_client(joydev, client);
295 kfree(client); 278 kfree(client);
296 err_put_joydev:
297 put_device(&joydev->dev);
298 return error; 279 return error;
299} 280}
300 281
@@ -742,19 +723,6 @@ static const struct file_operations joydev_fops = {
742 .llseek = no_llseek, 723 .llseek = no_llseek,
743}; 724};
744 725
745static int joydev_install_chrdev(struct joydev *joydev)
746{
747 joydev_table[joydev->minor] = joydev;
748 return 0;
749}
750
751static void joydev_remove_chrdev(struct joydev *joydev)
752{
753 mutex_lock(&joydev_table_mutex);
754 joydev_table[joydev->minor] = NULL;
755 mutex_unlock(&joydev_table_mutex);
756}
757
758/* 726/*
759 * Mark device non-existent. This disables writes, ioctls and 727 * Mark device non-existent. This disables writes, ioctls and
760 * prevents new users from opening the device. Already posted 728 * prevents new users from opening the device. Already posted
@@ -773,7 +741,8 @@ static void joydev_cleanup(struct joydev *joydev)
773 741
774 joydev_mark_dead(joydev); 742 joydev_mark_dead(joydev);
775 joydev_hangup(joydev); 743 joydev_hangup(joydev);
776 joydev_remove_chrdev(joydev); 744
745 cdev_del(&joydev->cdev);
777 746
778 /* joydev is marked dead so no one else accesses joydev->open */ 747 /* joydev is marked dead so no one else accesses joydev->open */
779 if (joydev->open) 748 if (joydev->open)
@@ -798,30 +767,33 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
798 const struct input_device_id *id) 767 const struct input_device_id *id)
799{ 768{
800 struct joydev *joydev; 769 struct joydev *joydev;
801 int i, j, t, minor; 770 int i, j, t, minor, dev_no;
802 int error; 771 int error;
803 772
804 for (minor = 0; minor < JOYDEV_MINORS; minor++) 773 minor = input_get_new_minor(JOYDEV_MINOR_BASE, JOYDEV_MINORS, true);
805 if (!joydev_table[minor]) 774 if (minor < 0) {
806 break; 775 error = minor;
807 776 pr_err("failed to reserve new minor: %d\n", error);
808 if (minor == JOYDEV_MINORS) { 777 return error;
809 pr_err("no more free joydev devices\n");
810 return -ENFILE;
811 } 778 }
812 779
813 joydev = kzalloc(sizeof(struct joydev), GFP_KERNEL); 780 joydev = kzalloc(sizeof(struct joydev), GFP_KERNEL);
814 if (!joydev) 781 if (!joydev) {
815 return -ENOMEM; 782 error = -ENOMEM;
783 goto err_free_minor;
784 }
816 785
817 INIT_LIST_HEAD(&joydev->client_list); 786 INIT_LIST_HEAD(&joydev->client_list);
818 spin_lock_init(&joydev->client_lock); 787 spin_lock_init(&joydev->client_lock);
819 mutex_init(&joydev->mutex); 788 mutex_init(&joydev->mutex);
820 init_waitqueue_head(&joydev->wait); 789 init_waitqueue_head(&joydev->wait);
821
822 dev_set_name(&joydev->dev, "js%d", minor);
823 joydev->exist = true; 790 joydev->exist = true;
824 joydev->minor = minor; 791
792 dev_no = minor;
793 /* Normalize device number if it falls into legacy range */
794 if (dev_no < JOYDEV_MINOR_BASE + JOYDEV_MINORS)
795 dev_no -= JOYDEV_MINOR_BASE;
796 dev_set_name(&joydev->dev, "js%d", dev_no);
825 797
826 joydev->handle.dev = input_get_device(dev); 798 joydev->handle.dev = input_get_device(dev);
827 joydev->handle.name = dev_name(&joydev->dev); 799 joydev->handle.name = dev_name(&joydev->dev);
@@ -875,7 +847,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
875 } 847 }
876 } 848 }
877 849
878 joydev->dev.devt = MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor); 850 joydev->dev.devt = MKDEV(INPUT_MAJOR, minor);
879 joydev->dev.class = &input_class; 851 joydev->dev.class = &input_class;
880 joydev->dev.parent = &dev->dev; 852 joydev->dev.parent = &dev->dev;
881 joydev->dev.release = joydev_free; 853 joydev->dev.release = joydev_free;
@@ -885,7 +857,8 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
885 if (error) 857 if (error)
886 goto err_free_joydev; 858 goto err_free_joydev;
887 859
888 error = joydev_install_chrdev(joydev); 860 cdev_init(&joydev->cdev, &joydev_fops);
861 error = cdev_add(&joydev->cdev, joydev->dev.devt, 1);
889 if (error) 862 if (error)
890 goto err_unregister_handle; 863 goto err_unregister_handle;
891 864
@@ -901,6 +874,8 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
901 input_unregister_handle(&joydev->handle); 874 input_unregister_handle(&joydev->handle);
902 err_free_joydev: 875 err_free_joydev:
903 put_device(&joydev->dev); 876 put_device(&joydev->dev);
877 err_free_minor:
878 input_free_minor(minor);
904 return error; 879 return error;
905} 880}
906 881
@@ -910,6 +885,7 @@ static void joydev_disconnect(struct input_handle *handle)
910 885
911 device_del(&joydev->dev); 886 device_del(&joydev->dev);
912 joydev_cleanup(joydev); 887 joydev_cleanup(joydev);
888 input_free_minor(MINOR(joydev->dev.devt));
913 input_unregister_handle(handle); 889 input_unregister_handle(handle);
914 put_device(&joydev->dev); 890 put_device(&joydev->dev);
915} 891}
@@ -961,7 +937,7 @@ static struct input_handler joydev_handler = {
961 .match = joydev_match, 937 .match = joydev_match,
962 .connect = joydev_connect, 938 .connect = joydev_connect,
963 .disconnect = joydev_disconnect, 939 .disconnect = joydev_disconnect,
964 .fops = &joydev_fops, 940 .legacy_minors = true,
965 .minor = JOYDEV_MINOR_BASE, 941 .minor = JOYDEV_MINOR_BASE,
966 .name = "joydev", 942 .name = "joydev",
967 .id_table = joydev_ids, 943 .id_table = joydev_ids,
diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c
index 277e26dc910e..9d7a111486f7 100644
--- a/drivers/input/keyboard/samsung-keypad.c
+++ b/drivers/input/keyboard/samsung-keypad.c
@@ -431,6 +431,12 @@ static int __devinit samsung_keypad_probe(struct platform_device *pdev)
431 goto err_unmap_base; 431 goto err_unmap_base;
432 } 432 }
433 433
434 error = clk_prepare(keypad->clk);
435 if (error) {
436 dev_err(&pdev->dev, "keypad clock prepare failed\n");
437 goto err_put_clk;
438 }
439
434 keypad->input_dev = input_dev; 440 keypad->input_dev = input_dev;
435 keypad->pdev = pdev; 441 keypad->pdev = pdev;
436 keypad->row_shift = row_shift; 442 keypad->row_shift = row_shift;
@@ -461,7 +467,7 @@ static int __devinit samsung_keypad_probe(struct platform_device *pdev)
461 keypad->keycodes, input_dev); 467 keypad->keycodes, input_dev);
462 if (error) { 468 if (error) {
463 dev_err(&pdev->dev, "failed to build keymap\n"); 469 dev_err(&pdev->dev, "failed to build keymap\n");
464 goto err_put_clk; 470 goto err_unprepare_clk;
465 } 471 }
466 472
467 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 473 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
@@ -503,6 +509,8 @@ err_free_irq:
503 pm_runtime_disable(&pdev->dev); 509 pm_runtime_disable(&pdev->dev);
504 device_init_wakeup(&pdev->dev, 0); 510 device_init_wakeup(&pdev->dev, 0);
505 platform_set_drvdata(pdev, NULL); 511 platform_set_drvdata(pdev, NULL);
512err_unprepare_clk:
513 clk_unprepare(keypad->clk);
506err_put_clk: 514err_put_clk:
507 clk_put(keypad->clk); 515 clk_put(keypad->clk);
508 samsung_keypad_dt_gpio_free(keypad); 516 samsung_keypad_dt_gpio_free(keypad);
@@ -531,6 +539,7 @@ static int __devexit samsung_keypad_remove(struct platform_device *pdev)
531 */ 539 */
532 free_irq(keypad->irq, keypad); 540 free_irq(keypad->irq, keypad);
533 541
542 clk_unprepare(keypad->clk);
534 clk_put(keypad->clk); 543 clk_put(keypad->clk);
535 samsung_keypad_dt_gpio_free(keypad); 544 samsung_keypad_dt_gpio_free(keypad);
536 545
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 964e43d81e29..a1b4c37956b2 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -24,10 +24,8 @@
24#include <linux/random.h> 24#include <linux/random.h>
25#include <linux/major.h> 25#include <linux/major.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/cdev.h>
27#include <linux/kernel.h> 28#include <linux/kernel.h>
28#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
29#include <linux/miscdevice.h>
30#endif
31 29
32MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 30MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
33MODULE_DESCRIPTION("Mouse (ExplorerPS/2) device interfaces"); 31MODULE_DESCRIPTION("Mouse (ExplorerPS/2) device interfaces");
@@ -61,17 +59,18 @@ struct mousedev_hw_data {
61 59
62struct mousedev { 60struct mousedev {
63 int open; 61 int open;
64 int minor;
65 struct input_handle handle; 62 struct input_handle handle;
66 wait_queue_head_t wait; 63 wait_queue_head_t wait;
67 struct list_head client_list; 64 struct list_head client_list;
68 spinlock_t client_lock; /* protects client_list */ 65 spinlock_t client_lock; /* protects client_list */
69 struct mutex mutex; 66 struct mutex mutex;
70 struct device dev; 67 struct device dev;
68 struct cdev cdev;
71 bool exist; 69 bool exist;
70 bool is_mixdev;
72 71
73 struct list_head mixdev_node; 72 struct list_head mixdev_node;
74 int mixdev_open; 73 bool opened_by_mixdev;
75 74
76 struct mousedev_hw_data packet; 75 struct mousedev_hw_data packet;
77 unsigned int pkt_count; 76 unsigned int pkt_count;
@@ -114,10 +113,6 @@ struct mousedev_client {
114static unsigned char mousedev_imps_seq[] = { 0xf3, 200, 0xf3, 100, 0xf3, 80 }; 113static unsigned char mousedev_imps_seq[] = { 0xf3, 200, 0xf3, 100, 0xf3, 80 };
115static unsigned char mousedev_imex_seq[] = { 0xf3, 200, 0xf3, 200, 0xf3, 80 }; 114static unsigned char mousedev_imex_seq[] = { 0xf3, 200, 0xf3, 200, 0xf3, 80 };
116 115
117static struct input_handler mousedev_handler;
118
119static struct mousedev *mousedev_table[MOUSEDEV_MINORS];
120static DEFINE_MUTEX(mousedev_table_mutex);
121static struct mousedev *mousedev_mix; 116static struct mousedev *mousedev_mix;
122static LIST_HEAD(mousedev_mix_list); 117static LIST_HEAD(mousedev_mix_list);
123 118
@@ -433,7 +428,7 @@ static int mousedev_open_device(struct mousedev *mousedev)
433 if (retval) 428 if (retval)
434 return retval; 429 return retval;
435 430
436 if (mousedev->minor == MOUSEDEV_MIX) 431 if (mousedev->is_mixdev)
437 mixdev_open_devices(); 432 mixdev_open_devices();
438 else if (!mousedev->exist) 433 else if (!mousedev->exist)
439 retval = -ENODEV; 434 retval = -ENODEV;
@@ -451,7 +446,7 @@ static void mousedev_close_device(struct mousedev *mousedev)
451{ 446{
452 mutex_lock(&mousedev->mutex); 447 mutex_lock(&mousedev->mutex);
453 448
454 if (mousedev->minor == MOUSEDEV_MIX) 449 if (mousedev->is_mixdev)
455 mixdev_close_devices(); 450 mixdev_close_devices();
456 else if (mousedev->exist && !--mousedev->open) 451 else if (mousedev->exist && !--mousedev->open)
457 input_close_device(&mousedev->handle); 452 input_close_device(&mousedev->handle);
@@ -472,11 +467,11 @@ static void mixdev_open_devices(void)
472 return; 467 return;
473 468
474 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { 469 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
475 if (!mousedev->mixdev_open) { 470 if (!mousedev->opened_by_mixdev) {
476 if (mousedev_open_device(mousedev)) 471 if (mousedev_open_device(mousedev))
477 continue; 472 continue;
478 473
479 mousedev->mixdev_open = 1; 474 mousedev->opened_by_mixdev = true;
480 } 475 }
481 } 476 }
482} 477}
@@ -494,8 +489,8 @@ static void mixdev_close_devices(void)
494 return; 489 return;
495 490
496 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { 491 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
497 if (mousedev->mixdev_open) { 492 if (mousedev->opened_by_mixdev) {
498 mousedev->mixdev_open = 0; 493 mousedev->opened_by_mixdev = false;
499 mousedev_close_device(mousedev); 494 mousedev_close_device(mousedev);
500 } 495 }
501 } 496 }
@@ -538,35 +533,17 @@ static int mousedev_open(struct inode *inode, struct file *file)
538 struct mousedev_client *client; 533 struct mousedev_client *client;
539 struct mousedev *mousedev; 534 struct mousedev *mousedev;
540 int error; 535 int error;
541 int i;
542 536
543#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 537#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
544 if (imajor(inode) == MISC_MAJOR) 538 if (imajor(inode) == MISC_MAJOR)
545 i = MOUSEDEV_MIX; 539 mousedev = mousedev_mix;
546 else 540 else
547#endif 541#endif
548 i = iminor(inode) - MOUSEDEV_MINOR_BASE; 542 mousedev = container_of(inode->i_cdev, struct mousedev, cdev);
549
550 if (i >= MOUSEDEV_MINORS)
551 return -ENODEV;
552
553 error = mutex_lock_interruptible(&mousedev_table_mutex);
554 if (error)
555 return error;
556
557 mousedev = mousedev_table[i];
558 if (mousedev)
559 get_device(&mousedev->dev);
560 mutex_unlock(&mousedev_table_mutex);
561
562 if (!mousedev)
563 return -ENODEV;
564 543
565 client = kzalloc(sizeof(struct mousedev_client), GFP_KERNEL); 544 client = kzalloc(sizeof(struct mousedev_client), GFP_KERNEL);
566 if (!client) { 545 if (!client)
567 error = -ENOMEM; 546 return -ENOMEM;
568 goto err_put_mousedev;
569 }
570 547
571 spin_lock_init(&client->packet_lock); 548 spin_lock_init(&client->packet_lock);
572 client->pos_x = xres / 2; 549 client->pos_x = xres / 2;
@@ -579,13 +556,14 @@ static int mousedev_open(struct inode *inode, struct file *file)
579 goto err_free_client; 556 goto err_free_client;
580 557
581 file->private_data = client; 558 file->private_data = client;
559 nonseekable_open(inode, file);
560
561 get_device(&mousedev->dev);
582 return 0; 562 return 0;
583 563
584 err_free_client: 564 err_free_client:
585 mousedev_detach_client(mousedev, client); 565 mousedev_detach_client(mousedev, client);
586 kfree(client); 566 kfree(client);
587 err_put_mousedev:
588 put_device(&mousedev->dev);
589 return error; 567 return error;
590} 568}
591 569
@@ -785,29 +763,16 @@ static unsigned int mousedev_poll(struct file *file, poll_table *wait)
785} 763}
786 764
787static const struct file_operations mousedev_fops = { 765static const struct file_operations mousedev_fops = {
788 .owner = THIS_MODULE, 766 .owner = THIS_MODULE,
789 .read = mousedev_read, 767 .read = mousedev_read,
790 .write = mousedev_write, 768 .write = mousedev_write,
791 .poll = mousedev_poll, 769 .poll = mousedev_poll,
792 .open = mousedev_open, 770 .open = mousedev_open,
793 .release = mousedev_release, 771 .release = mousedev_release,
794 .fasync = mousedev_fasync, 772 .fasync = mousedev_fasync,
795 .llseek = noop_llseek, 773 .llseek = noop_llseek,
796}; 774};
797 775
798static int mousedev_install_chrdev(struct mousedev *mousedev)
799{
800 mousedev_table[mousedev->minor] = mousedev;
801 return 0;
802}
803
804static void mousedev_remove_chrdev(struct mousedev *mousedev)
805{
806 mutex_lock(&mousedev_table_mutex);
807 mousedev_table[mousedev->minor] = NULL;
808 mutex_unlock(&mousedev_table_mutex);
809}
810
811/* 776/*
812 * Mark device non-existent. This disables writes, ioctls and 777 * Mark device non-existent. This disables writes, ioctls and
813 * prevents new users from opening the device. Already posted 778 * prevents new users from opening the device. Already posted
@@ -842,24 +807,50 @@ static void mousedev_cleanup(struct mousedev *mousedev)
842 807
843 mousedev_mark_dead(mousedev); 808 mousedev_mark_dead(mousedev);
844 mousedev_hangup(mousedev); 809 mousedev_hangup(mousedev);
845 mousedev_remove_chrdev(mousedev); 810
811 cdev_del(&mousedev->cdev);
846 812
847 /* mousedev is marked dead so no one else accesses mousedev->open */ 813 /* mousedev is marked dead so no one else accesses mousedev->open */
848 if (mousedev->open) 814 if (mousedev->open)
849 input_close_device(handle); 815 input_close_device(handle);
850} 816}
851 817
818static int mousedev_reserve_minor(bool mixdev)
819{
820 int minor;
821
822 if (mixdev) {
823 minor = input_get_new_minor(MOUSEDEV_MIX, 1, false);
824 if (minor < 0)
825 pr_err("failed to reserve mixdev minor: %d\n", minor);
826 } else {
827 minor = input_get_new_minor(MOUSEDEV_MINOR_BASE,
828 MOUSEDEV_MINORS, true);
829 if (minor < 0)
830 pr_err("failed to reserve new minor: %d\n", minor);
831 }
832
833 return minor;
834}
835
852static struct mousedev *mousedev_create(struct input_dev *dev, 836static struct mousedev *mousedev_create(struct input_dev *dev,
853 struct input_handler *handler, 837 struct input_handler *handler,
854 int minor) 838 bool mixdev)
855{ 839{
856 struct mousedev *mousedev; 840 struct mousedev *mousedev;
841 int minor;
857 int error; 842 int error;
858 843
844 minor = mousedev_reserve_minor(mixdev);
845 if (minor < 0) {
846 error = minor;
847 goto err_out;
848 }
849
859 mousedev = kzalloc(sizeof(struct mousedev), GFP_KERNEL); 850 mousedev = kzalloc(sizeof(struct mousedev), GFP_KERNEL);
860 if (!mousedev) { 851 if (!mousedev) {
861 error = -ENOMEM; 852 error = -ENOMEM;
862 goto err_out; 853 goto err_free_minor;
863 } 854 }
864 855
865 INIT_LIST_HEAD(&mousedev->client_list); 856 INIT_LIST_HEAD(&mousedev->client_list);
@@ -867,16 +858,21 @@ static struct mousedev *mousedev_create(struct input_dev *dev,
867 spin_lock_init(&mousedev->client_lock); 858 spin_lock_init(&mousedev->client_lock);
868 mutex_init(&mousedev->mutex); 859 mutex_init(&mousedev->mutex);
869 lockdep_set_subclass(&mousedev->mutex, 860 lockdep_set_subclass(&mousedev->mutex,
870 minor == MOUSEDEV_MIX ? SINGLE_DEPTH_NESTING : 0); 861 mixdev ? SINGLE_DEPTH_NESTING : 0);
871 init_waitqueue_head(&mousedev->wait); 862 init_waitqueue_head(&mousedev->wait);
872 863
873 if (minor == MOUSEDEV_MIX) 864 if (mixdev) {
874 dev_set_name(&mousedev->dev, "mice"); 865 dev_set_name(&mousedev->dev, "mice");
875 else 866 } else {
876 dev_set_name(&mousedev->dev, "mouse%d", minor); 867 int dev_no = minor;
868 /* Normalize device number if it falls into legacy range */
869 if (dev_no < MOUSEDEV_MINOR_BASE + MOUSEDEV_MINORS)
870 dev_no -= MOUSEDEV_MINOR_BASE;
871 dev_set_name(&mousedev->dev, "mouse%d", dev_no);
872 }
877 873
878 mousedev->minor = minor;
879 mousedev->exist = true; 874 mousedev->exist = true;
875 mousedev->is_mixdev = mixdev;
880 mousedev->handle.dev = input_get_device(dev); 876 mousedev->handle.dev = input_get_device(dev);
881 mousedev->handle.name = dev_name(&mousedev->dev); 877 mousedev->handle.name = dev_name(&mousedev->dev);
882 mousedev->handle.handler = handler; 878 mousedev->handle.handler = handler;
@@ -885,17 +881,18 @@ static struct mousedev *mousedev_create(struct input_dev *dev,
885 mousedev->dev.class = &input_class; 881 mousedev->dev.class = &input_class;
886 if (dev) 882 if (dev)
887 mousedev->dev.parent = &dev->dev; 883 mousedev->dev.parent = &dev->dev;
888 mousedev->dev.devt = MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor); 884 mousedev->dev.devt = MKDEV(INPUT_MAJOR, minor);
889 mousedev->dev.release = mousedev_free; 885 mousedev->dev.release = mousedev_free;
890 device_initialize(&mousedev->dev); 886 device_initialize(&mousedev->dev);
891 887
892 if (minor != MOUSEDEV_MIX) { 888 if (!mixdev) {
893 error = input_register_handle(&mousedev->handle); 889 error = input_register_handle(&mousedev->handle);
894 if (error) 890 if (error)
895 goto err_free_mousedev; 891 goto err_free_mousedev;
896 } 892 }
897 893
898 error = mousedev_install_chrdev(mousedev); 894 cdev_init(&mousedev->cdev, &mousedev_fops);
895 error = cdev_add(&mousedev->cdev, mousedev->dev.devt, 1);
899 if (error) 896 if (error)
900 goto err_unregister_handle; 897 goto err_unregister_handle;
901 898
@@ -908,10 +905,12 @@ static struct mousedev *mousedev_create(struct input_dev *dev,
908 err_cleanup_mousedev: 905 err_cleanup_mousedev:
909 mousedev_cleanup(mousedev); 906 mousedev_cleanup(mousedev);
910 err_unregister_handle: 907 err_unregister_handle:
911 if (minor != MOUSEDEV_MIX) 908 if (!mixdev)
912 input_unregister_handle(&mousedev->handle); 909 input_unregister_handle(&mousedev->handle);
913 err_free_mousedev: 910 err_free_mousedev:
914 put_device(&mousedev->dev); 911 put_device(&mousedev->dev);
912 err_free_minor:
913 input_free_minor(minor);
915 err_out: 914 err_out:
916 return ERR_PTR(error); 915 return ERR_PTR(error);
917} 916}
@@ -920,7 +919,8 @@ static void mousedev_destroy(struct mousedev *mousedev)
920{ 919{
921 device_del(&mousedev->dev); 920 device_del(&mousedev->dev);
922 mousedev_cleanup(mousedev); 921 mousedev_cleanup(mousedev);
923 if (mousedev->minor != MOUSEDEV_MIX) 922 input_free_minor(MINOR(mousedev->dev.devt));
923 if (!mousedev->is_mixdev)
924 input_unregister_handle(&mousedev->handle); 924 input_unregister_handle(&mousedev->handle);
925 put_device(&mousedev->dev); 925 put_device(&mousedev->dev);
926} 926}
@@ -938,7 +938,7 @@ static int mixdev_add_device(struct mousedev *mousedev)
938 if (retval) 938 if (retval)
939 goto out; 939 goto out;
940 940
941 mousedev->mixdev_open = 1; 941 mousedev->opened_by_mixdev = true;
942 } 942 }
943 943
944 get_device(&mousedev->dev); 944 get_device(&mousedev->dev);
@@ -953,8 +953,8 @@ static void mixdev_remove_device(struct mousedev *mousedev)
953{ 953{
954 mutex_lock(&mousedev_mix->mutex); 954 mutex_lock(&mousedev_mix->mutex);
955 955
956 if (mousedev->mixdev_open) { 956 if (mousedev->opened_by_mixdev) {
957 mousedev->mixdev_open = 0; 957 mousedev->opened_by_mixdev = false;
958 mousedev_close_device(mousedev); 958 mousedev_close_device(mousedev);
959 } 959 }
960 960
@@ -969,19 +969,9 @@ static int mousedev_connect(struct input_handler *handler,
969 const struct input_device_id *id) 969 const struct input_device_id *id)
970{ 970{
971 struct mousedev *mousedev; 971 struct mousedev *mousedev;
972 int minor;
973 int error; 972 int error;
974 973
975 for (minor = 0; minor < MOUSEDEV_MINORS; minor++) 974 mousedev = mousedev_create(dev, handler, false);
976 if (!mousedev_table[minor])
977 break;
978
979 if (minor == MOUSEDEV_MINORS) {
980 pr_err("no more free mousedev devices\n");
981 return -ENFILE;
982 }
983
984 mousedev = mousedev_create(dev, handler, minor);
985 if (IS_ERR(mousedev)) 975 if (IS_ERR(mousedev))
986 return PTR_ERR(mousedev); 976 return PTR_ERR(mousedev);
987 977
@@ -1054,27 +1044,53 @@ static const struct input_device_id mousedev_ids[] = {
1054MODULE_DEVICE_TABLE(input, mousedev_ids); 1044MODULE_DEVICE_TABLE(input, mousedev_ids);
1055 1045
1056static struct input_handler mousedev_handler = { 1046static struct input_handler mousedev_handler = {
1057 .event = mousedev_event, 1047 .event = mousedev_event,
1058 .connect = mousedev_connect, 1048 .connect = mousedev_connect,
1059 .disconnect = mousedev_disconnect, 1049 .disconnect = mousedev_disconnect,
1060 .fops = &mousedev_fops, 1050 .legacy_minors = true,
1061 .minor = MOUSEDEV_MINOR_BASE, 1051 .minor = MOUSEDEV_MINOR_BASE,
1062 .name = "mousedev", 1052 .name = "mousedev",
1063 .id_table = mousedev_ids, 1053 .id_table = mousedev_ids,
1064}; 1054};
1065 1055
1066#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 1056#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
1057#include <linux/miscdevice.h>
1058
1067static struct miscdevice psaux_mouse = { 1059static struct miscdevice psaux_mouse = {
1068 PSMOUSE_MINOR, "psaux", &mousedev_fops 1060 .minor = PSMOUSE_MINOR,
1061 .name = "psaux",
1062 .fops = &mousedev_fops,
1069}; 1063};
1070static int psaux_registered; 1064
1065static bool psaux_registered;
1066
1067static void __init mousedev_psaux_register(void)
1068{
1069 int error;
1070
1071 error = misc_register(&psaux_mouse);
1072 if (error)
1073 pr_warn("could not register psaux device, error: %d\n",
1074 error);
1075 else
1076 psaux_registered = true;
1077}
1078
1079static void __exit mousedev_psaux_unregister(void)
1080{
1081 if (psaux_registered)
1082 misc_deregister(&psaux_mouse);
1083}
1084#else
1085static inline void mousedev_psaux_register(void) { }
1086static inline void mousedev_psaux_unregister(void) { }
1071#endif 1087#endif
1072 1088
1073static int __init mousedev_init(void) 1089static int __init mousedev_init(void)
1074{ 1090{
1075 int error; 1091 int error;
1076 1092
1077 mousedev_mix = mousedev_create(NULL, &mousedev_handler, MOUSEDEV_MIX); 1093 mousedev_mix = mousedev_create(NULL, &mousedev_handler, true);
1078 if (IS_ERR(mousedev_mix)) 1094 if (IS_ERR(mousedev_mix))
1079 return PTR_ERR(mousedev_mix); 1095 return PTR_ERR(mousedev_mix);
1080 1096
@@ -1084,14 +1100,7 @@ static int __init mousedev_init(void)
1084 return error; 1100 return error;
1085 } 1101 }
1086 1102
1087#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 1103 mousedev_psaux_register();
1088 error = misc_register(&psaux_mouse);
1089 if (error)
1090 pr_warn("could not register psaux device, error: %d\n",
1091 error);
1092 else
1093 psaux_registered = 1;
1094#endif
1095 1104
1096 pr_info("PS/2 mouse device common for all mice\n"); 1105 pr_info("PS/2 mouse device common for all mice\n");
1097 1106
@@ -1100,10 +1109,7 @@ static int __init mousedev_init(void)
1100 1109
1101static void __exit mousedev_exit(void) 1110static void __exit mousedev_exit(void)
1102{ 1111{
1103#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 1112 mousedev_psaux_unregister();
1104 if (psaux_registered)
1105 misc_deregister(&psaux_mouse);
1106#endif
1107 input_unregister_handler(&mousedev_handler); 1113 input_unregister_handler(&mousedev_handler);
1108 mousedev_destroy(mousedev_mix); 1114 mousedev_destroy(mousedev_mix);
1109} 1115}
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 0d3219f29744..9edf9806cff9 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -172,6 +172,76 @@ static void wacom_close(struct input_dev *dev)
172} 172}
173 173
174/* 174/*
175 * Calculate the resolution of the X or Y axis, given appropriate HID data.
176 * This function is little more than hidinput_calc_abs_res stripped down.
177 */
178static int wacom_calc_hid_res(int logical_extents, int physical_extents,
179 unsigned char unit, unsigned char exponent)
180{
181 int prev, unit_exponent;
182
183 /* Check if the extents are sane */
184 if (logical_extents <= 0 || physical_extents <= 0)
185 return 0;
186
187 /* Get signed value of nybble-sized twos-compliment exponent */
188 unit_exponent = exponent;
189 if (unit_exponent > 7)
190 unit_exponent -= 16;
191
192 /* Convert physical_extents to millimeters */
193 if (unit == 0x11) { /* If centimeters */
194 unit_exponent += 1;
195 } else if (unit == 0x13) { /* If inches */
196 prev = physical_extents;
197 physical_extents *= 254;
198 if (physical_extents < prev)
199 return 0;
200 unit_exponent -= 1;
201 } else {
202 return 0;
203 }
204
205 /* Apply negative unit exponent */
206 for (; unit_exponent < 0; unit_exponent++) {
207 prev = logical_extents;
208 logical_extents *= 10;
209 if (logical_extents < prev)
210 return 0;
211 }
212 /* Apply positive unit exponent */
213 for (; unit_exponent > 0; unit_exponent--) {
214 prev = physical_extents;
215 physical_extents *= 10;
216 if (physical_extents < prev)
217 return 0;
218 }
219
220 /* Calculate resolution */
221 return logical_extents / physical_extents;
222}
223
224/*
225 * The physical dimension specified by the HID descriptor is likely not in
226 * the "100th of a mm" units expected by wacom_calculate_touch_res. This
227 * function adjusts the value of [xy]_phy based on the unit and exponent
228 * provided by the HID descriptor. If an error occurs durring conversion
229 * (e.g. from the unit being left unspecified) [xy]_phy is not modified.
230 */
231static void wacom_fix_phy_from_hid(struct wacom_features *features)
232{
233 int xres = wacom_calc_hid_res(features->x_max, features->x_phy,
234 features->unit, features->unitExpo);
235 int yres = wacom_calc_hid_res(features->y_max, features->y_phy,
236 features->unit, features->unitExpo);
237
238 if (xres > 0 && yres > 0) {
239 features->x_phy = (100 * features->x_max) / xres;
240 features->y_phy = (100 * features->y_max) / yres;
241 }
242}
243
244/*
175 * Static values for max X/Y and resolution of Pen interface is stored in 245 * Static values for max X/Y and resolution of Pen interface is stored in
176 * features. This mean physical size of active area can be computed. 246 * features. This mean physical size of active area can be computed.
177 * This is useful to do when Pen and Touch have same active area of tablet. 247 * This is useful to do when Pen and Touch have same active area of tablet.
@@ -432,56 +502,52 @@ static int wacom_parse_hid(struct usb_interface *intf,
432 return result; 502 return result;
433} 503}
434 504
435static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features) 505static int wacom_set_device_mode(struct usb_interface *intf, int report_id, int length, int mode)
436{ 506{
437 unsigned char *rep_data; 507 unsigned char *rep_data;
438 int limit = 0, report_id = 2; 508 int error = -ENOMEM, limit = 0;
439 int error = -ENOMEM;
440 509
441 rep_data = kmalloc(4, GFP_KERNEL); 510 rep_data = kzalloc(length, GFP_KERNEL);
442 if (!rep_data) 511 if (!rep_data)
443 return error; 512 return error;
444 513
445 /* ask to report Wacom data */ 514 rep_data[0] = report_id;
515 rep_data[1] = mode;
516
517 do {
518 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
519 report_id, rep_data, length, 1);
520 if (error >= 0)
521 error = wacom_get_report(intf, WAC_HID_FEATURE_REPORT,
522 report_id, rep_data, length, 1);
523 } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES);
524
525 kfree(rep_data);
526
527 return error < 0 ? error : 0;
528}
529
530/*
531 * Switch the tablet into its most-capable mode. Wacom tablets are
532 * typically configured to power-up in a mode which sends mouse-like
533 * reports to the OS. To get absolute position, pressure data, etc.
534 * from the tablet, it is necessary to switch the tablet out of this
535 * mode and into one which sends the full range of tablet data.
536 */
537static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
538{
446 if (features->device_type == BTN_TOOL_FINGER) { 539 if (features->device_type == BTN_TOOL_FINGER) {
447 /* if it is an MT Tablet PC touch */
448 if (features->type > TABLETPC) { 540 if (features->type > TABLETPC) {
449 do { 541 /* MT Tablet PC touch */
450 rep_data[0] = 3; 542 return wacom_set_device_mode(intf, 3, 4, 4);
451 rep_data[1] = 4; 543 }
452 rep_data[2] = 0; 544 } else if (features->device_type == BTN_TOOL_PEN) {
453 rep_data[3] = 0; 545 if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
454 report_id = 3; 546 return wacom_set_device_mode(intf, 2, 2, 2);
455 error = wacom_set_report(intf,
456 WAC_HID_FEATURE_REPORT,
457 report_id,
458 rep_data, 4, 1);
459 if (error >= 0)
460 error = wacom_get_report(intf,
461 WAC_HID_FEATURE_REPORT,
462 report_id,
463 rep_data, 4, 1);
464 } while ((error < 0 || rep_data[1] != 4) &&
465 limit++ < WAC_MSG_RETRIES);
466 } 547 }
467 } else if (features->type <= BAMBOO_PT &&
468 features->type != WIRELESS &&
469 features->device_type == BTN_TOOL_PEN) {
470 do {
471 rep_data[0] = 2;
472 rep_data[1] = 2;
473 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
474 report_id, rep_data, 2, 1);
475 if (error >= 0)
476 error = wacom_get_report(intf,
477 WAC_HID_FEATURE_REPORT,
478 report_id, rep_data, 2, 1);
479 } while ((error < 0 || rep_data[1] != 2) && limit++ < WAC_MSG_RETRIES);
480 } 548 }
481 549
482 kfree(rep_data); 550 return 0;
483
484 return error < 0 ? error : 0;
485} 551}
486 552
487static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, 553static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
@@ -531,6 +597,7 @@ static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
531 error = wacom_parse_hid(intf, hid_desc, features); 597 error = wacom_parse_hid(intf, hid_desc, features);
532 if (error) 598 if (error)
533 goto out; 599 goto out;
600 wacom_fix_phy_from_hid(features);
534 601
535 out: 602 out:
536 return error; 603 return error;
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 08b462b6c0d8..c3468c8dbd89 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -25,6 +25,11 @@
25#define WACOM_INTUOS_RES 100 25#define WACOM_INTUOS_RES 100
26#define WACOM_INTUOS3_RES 200 26#define WACOM_INTUOS3_RES 200
27 27
28/* Scale factor relating reported contact size to logical contact area.
29 * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
30 */
31#define WACOM_CONTACT_AREA_SCALE 2607
32
28static int wacom_penpartner_irq(struct wacom_wac *wacom) 33static int wacom_penpartner_irq(struct wacom_wac *wacom)
29{ 34{
30 unsigned char *data = wacom->data; 35 unsigned char *data = wacom->data;
@@ -326,7 +331,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
326 331
327 /* Enter report */ 332 /* Enter report */
328 if ((data[1] & 0xfc) == 0xc0) { 333 if ((data[1] & 0xfc) == 0xc0) {
329 if (features->type >= INTUOS5S && features->type <= INTUOS5L) 334 if (features->quirks == WACOM_QUIRK_MULTI_INPUT)
330 wacom->shared->stylus_in_proximity = true; 335 wacom->shared->stylus_in_proximity = true;
331 336
332 /* serial number of the tool */ 337 /* serial number of the tool */
@@ -414,7 +419,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
414 419
415 /* Exit report */ 420 /* Exit report */
416 if ((data[1] & 0xfe) == 0x80) { 421 if ((data[1] & 0xfe) == 0x80) {
417 if (features->type >= INTUOS5S && features->type <= INTUOS5L) 422 if (features->quirks == WACOM_QUIRK_MULTI_INPUT)
418 wacom->shared->stylus_in_proximity = false; 423 wacom->shared->stylus_in_proximity = false;
419 424
420 /* 425 /*
@@ -1043,11 +1048,19 @@ static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
1043 if (touch) { 1048 if (touch) {
1044 int x = (data[2] << 4) | (data[4] >> 4); 1049 int x = (data[2] << 4) | (data[4] >> 4);
1045 int y = (data[3] << 4) | (data[4] & 0x0f); 1050 int y = (data[3] << 4) | (data[4] & 0x0f);
1046 int w = data[6]; 1051 int a = data[5];
1052
1053 // "a" is a scaled-down area which we assume is roughly
1054 // circular and which can be described as: a=(pi*r^2)/C.
1055 int x_res = input_abs_get_res(input, ABS_X);
1056 int y_res = input_abs_get_res(input, ABS_Y);
1057 int width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
1058 int height = width * y_res / x_res;
1047 1059
1048 input_report_abs(input, ABS_MT_POSITION_X, x); 1060 input_report_abs(input, ABS_MT_POSITION_X, x);
1049 input_report_abs(input, ABS_MT_POSITION_Y, y); 1061 input_report_abs(input, ABS_MT_POSITION_Y, y);
1050 input_report_abs(input, ABS_MT_TOUCH_MAJOR, w); 1062 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
1063 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
1051 } 1064 }
1052} 1065}
1053 1066
@@ -1533,7 +1546,9 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
1533 input_mt_init_slots(input_dev, features->touch_max, 0); 1546 input_mt_init_slots(input_dev, features->touch_max, 0);
1534 1547
1535 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 1548 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1536 0, 255, 0, 0); 1549 0, features->x_max, 0, 0);
1550 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
1551 0, features->y_max, 0, 0);
1537 1552
1538 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 1553 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
1539 0, features->x_max, 1554 0, features->x_max,
@@ -1641,7 +1656,10 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
1641 1656
1642 input_set_abs_params(input_dev, 1657 input_set_abs_params(input_dev,
1643 ABS_MT_TOUCH_MAJOR, 1658 ABS_MT_TOUCH_MAJOR,
1644 0, 255, 0, 0); 1659 0, features->x_max, 0, 0);
1660 input_set_abs_params(input_dev,
1661 ABS_MT_TOUCH_MINOR,
1662 0, features->y_max, 0, 0);
1645 } 1663 }
1646 1664
1647 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 1665 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index e92615d0b1b0..1df2396af008 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -320,10 +320,8 @@ static bool mxt_object_writable(unsigned int type)
320static void mxt_dump_message(struct device *dev, 320static void mxt_dump_message(struct device *dev,
321 struct mxt_message *message) 321 struct mxt_message *message)
322{ 322{
323 dev_dbg(dev, "reportid: %u\tmessage: %02x %02x %02x %02x %02x %02x %02x\n", 323 dev_dbg(dev, "reportid: %u\tmessage: %*ph\n",
324 message->reportid, message->message[0], message->message[1], 324 message->reportid, 7, message->message);
325 message->message[2], message->message[3], message->message[4],
326 message->message[5], message->message[6]);
327} 325}
328 326
329static int mxt_check_bootloader(struct i2c_client *client, 327static int mxt_check_bootloader(struct i2c_client *client,