diff options
Diffstat (limited to 'drivers/input/input.c')
-rw-r--r-- | drivers/input/input.c | 141 |
1 files changed, 101 insertions, 40 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c index 3038c268917..9cb4b9a54f0 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -28,20 +28,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); | |||
28 | MODULE_DESCRIPTION("Input core"); | 28 | MODULE_DESCRIPTION("Input core"); |
29 | MODULE_LICENSE("GPL"); | 29 | MODULE_LICENSE("GPL"); |
30 | 30 | ||
31 | EXPORT_SYMBOL(input_allocate_device); | ||
32 | EXPORT_SYMBOL(input_register_device); | ||
33 | EXPORT_SYMBOL(input_unregister_device); | ||
34 | EXPORT_SYMBOL(input_register_handler); | ||
35 | EXPORT_SYMBOL(input_unregister_handler); | ||
36 | EXPORT_SYMBOL(input_grab_device); | ||
37 | EXPORT_SYMBOL(input_release_device); | ||
38 | EXPORT_SYMBOL(input_open_device); | ||
39 | EXPORT_SYMBOL(input_close_device); | ||
40 | EXPORT_SYMBOL(input_accept_process); | ||
41 | EXPORT_SYMBOL(input_flush_device); | ||
42 | EXPORT_SYMBOL(input_event); | ||
43 | EXPORT_SYMBOL_GPL(input_class); | ||
44 | |||
45 | #define INPUT_DEVICES 256 | 31 | #define INPUT_DEVICES 256 |
46 | 32 | ||
47 | static LIST_HEAD(input_dev_list); | 33 | static LIST_HEAD(input_dev_list); |
@@ -49,6 +35,16 @@ static LIST_HEAD(input_handler_list); | |||
49 | 35 | ||
50 | static struct input_handler *input_table[8]; | 36 | static struct input_handler *input_table[8]; |
51 | 37 | ||
38 | /** | ||
39 | * input_event() - report new input event | ||
40 | * @handle: device that generated the event | ||
41 | * @type: type of the event | ||
42 | * @code: event code | ||
43 | * @value: value of the event | ||
44 | * | ||
45 | * This function should be used by drivers implementing various input devices | ||
46 | * See also input_inject_event() | ||
47 | */ | ||
52 | void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 48 | void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
53 | { | 49 | { |
54 | struct input_handle *handle; | 50 | struct input_handle *handle; |
@@ -63,11 +59,13 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in | |||
63 | case EV_SYN: | 59 | case EV_SYN: |
64 | switch (code) { | 60 | switch (code) { |
65 | case SYN_CONFIG: | 61 | case SYN_CONFIG: |
66 | if (dev->event) dev->event(dev, type, code, value); | 62 | if (dev->event) |
63 | dev->event(dev, type, code, value); | ||
67 | break; | 64 | break; |
68 | 65 | ||
69 | case SYN_REPORT: | 66 | case SYN_REPORT: |
70 | if (dev->sync) return; | 67 | if (dev->sync) |
68 | return; | ||
71 | dev->sync = 1; | 69 | dev->sync = 1; |
72 | break; | 70 | break; |
73 | } | 71 | } |
@@ -136,7 +134,8 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in | |||
136 | if (code > MSC_MAX || !test_bit(code, dev->mscbit)) | 134 | if (code > MSC_MAX || !test_bit(code, dev->mscbit)) |
137 | return; | 135 | return; |
138 | 136 | ||
139 | if (dev->event) dev->event(dev, type, code, value); | 137 | if (dev->event) |
138 | dev->event(dev, type, code, value); | ||
140 | 139 | ||
141 | break; | 140 | break; |
142 | 141 | ||
@@ -146,7 +145,9 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in | |||
146 | return; | 145 | return; |
147 | 146 | ||
148 | change_bit(code, dev->led); | 147 | change_bit(code, dev->led); |
149 | if (dev->event) dev->event(dev, type, code, value); | 148 | |
149 | if (dev->event) | ||
150 | dev->event(dev, type, code, value); | ||
150 | 151 | ||
151 | break; | 152 | break; |
152 | 153 | ||
@@ -158,21 +159,25 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in | |||
158 | if (!!test_bit(code, dev->snd) != !!value) | 159 | if (!!test_bit(code, dev->snd) != !!value) |
159 | change_bit(code, dev->snd); | 160 | change_bit(code, dev->snd); |
160 | 161 | ||
161 | if (dev->event) dev->event(dev, type, code, value); | 162 | if (dev->event) |
163 | dev->event(dev, type, code, value); | ||
162 | 164 | ||
163 | break; | 165 | break; |
164 | 166 | ||
165 | case EV_REP: | 167 | case EV_REP: |
166 | 168 | ||
167 | if (code > REP_MAX || value < 0 || dev->rep[code] == value) return; | 169 | if (code > REP_MAX || value < 0 || dev->rep[code] == value) |
170 | return; | ||
168 | 171 | ||
169 | dev->rep[code] = value; | 172 | dev->rep[code] = value; |
170 | if (dev->event) dev->event(dev, type, code, value); | 173 | if (dev->event) |
174 | dev->event(dev, type, code, value); | ||
171 | 175 | ||
172 | break; | 176 | break; |
173 | 177 | ||
174 | case EV_FF: | 178 | case EV_FF: |
175 | if (dev->event) dev->event(dev, type, code, value); | 179 | if (dev->event) |
180 | dev->event(dev, type, code, value); | ||
176 | break; | 181 | break; |
177 | } | 182 | } |
178 | 183 | ||
@@ -186,6 +191,24 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in | |||
186 | if (handle->open) | 191 | if (handle->open) |
187 | handle->handler->event(handle, type, code, value); | 192 | handle->handler->event(handle, type, code, value); |
188 | } | 193 | } |
194 | EXPORT_SYMBOL(input_event); | ||
195 | |||
196 | /** | ||
197 | * input_inject_event() - send input event from input handler | ||
198 | * @handle: input handle to send event through | ||
199 | * @type: type of the event | ||
200 | * @code: event code | ||
201 | * @value: value of the event | ||
202 | * | ||
203 | * Similar to input_event() but will ignore event if device is "grabbed" and handle | ||
204 | * injecting event is not the one that owns the device. | ||
205 | */ | ||
206 | void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) | ||
207 | { | ||
208 | if (!handle->dev->grab || handle->dev->grab == handle) | ||
209 | input_event(handle->dev, type, code, value); | ||
210 | } | ||
211 | EXPORT_SYMBOL(input_inject_event); | ||
189 | 212 | ||
190 | static void input_repeat_key(unsigned long data) | 213 | static void input_repeat_key(unsigned long data) |
191 | { | 214 | { |
@@ -201,14 +224,6 @@ static void input_repeat_key(unsigned long data) | |||
201 | mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD])); | 224 | mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD])); |
202 | } | 225 | } |
203 | 226 | ||
204 | int input_accept_process(struct input_handle *handle, struct file *file) | ||
205 | { | ||
206 | if (handle->dev->accept) | ||
207 | return handle->dev->accept(handle->dev, file); | ||
208 | |||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | int input_grab_device(struct input_handle *handle) | 227 | int input_grab_device(struct input_handle *handle) |
213 | { | 228 | { |
214 | if (handle->dev->grab) | 229 | if (handle->dev->grab) |
@@ -217,12 +232,21 @@ int input_grab_device(struct input_handle *handle) | |||
217 | handle->dev->grab = handle; | 232 | handle->dev->grab = handle; |
218 | return 0; | 233 | return 0; |
219 | } | 234 | } |
235 | EXPORT_SYMBOL(input_grab_device); | ||
220 | 236 | ||
221 | void input_release_device(struct input_handle *handle) | 237 | void input_release_device(struct input_handle *handle) |
222 | { | 238 | { |
223 | if (handle->dev->grab == handle) | 239 | struct input_dev *dev = handle->dev; |
224 | handle->dev->grab = NULL; | 240 | |
241 | if (dev->grab == handle) { | ||
242 | dev->grab = NULL; | ||
243 | |||
244 | list_for_each_entry(handle, &dev->h_list, d_node) | ||
245 | if (handle->handler->start) | ||
246 | handle->handler->start(handle); | ||
247 | } | ||
225 | } | 248 | } |
249 | EXPORT_SYMBOL(input_release_device); | ||
226 | 250 | ||
227 | int input_open_device(struct input_handle *handle) | 251 | int input_open_device(struct input_handle *handle) |
228 | { | 252 | { |
@@ -245,6 +269,7 @@ int input_open_device(struct input_handle *handle) | |||
245 | 269 | ||
246 | return err; | 270 | return err; |
247 | } | 271 | } |
272 | EXPORT_SYMBOL(input_open_device); | ||
248 | 273 | ||
249 | int input_flush_device(struct input_handle* handle, struct file* file) | 274 | int input_flush_device(struct input_handle* handle, struct file* file) |
250 | { | 275 | { |
@@ -253,6 +278,7 @@ int input_flush_device(struct input_handle* handle, struct file* file) | |||
253 | 278 | ||
254 | return 0; | 279 | return 0; |
255 | } | 280 | } |
281 | EXPORT_SYMBOL(input_flush_device); | ||
256 | 282 | ||
257 | void input_close_device(struct input_handle *handle) | 283 | void input_close_device(struct input_handle *handle) |
258 | { | 284 | { |
@@ -268,6 +294,7 @@ void input_close_device(struct input_handle *handle) | |||
268 | 294 | ||
269 | mutex_unlock(&dev->mutex); | 295 | mutex_unlock(&dev->mutex); |
270 | } | 296 | } |
297 | EXPORT_SYMBOL(input_close_device); | ||
271 | 298 | ||
272 | static void input_link_handle(struct input_handle *handle) | 299 | static void input_link_handle(struct input_handle *handle) |
273 | { | 300 | { |
@@ -335,9 +362,11 @@ static inline void input_wakeup_procfs_readers(void) | |||
335 | static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait) | 362 | static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait) |
336 | { | 363 | { |
337 | int state = input_devices_state; | 364 | int state = input_devices_state; |
365 | |||
338 | poll_wait(file, &input_devices_poll_wait, wait); | 366 | poll_wait(file, &input_devices_poll_wait, wait); |
339 | if (state != input_devices_state) | 367 | if (state != input_devices_state) |
340 | return POLLIN | POLLRDNORM; | 368 | return POLLIN | POLLRDNORM; |
369 | |||
341 | return 0; | 370 | return 0; |
342 | } | 371 | } |
343 | 372 | ||
@@ -629,7 +658,7 @@ static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf) | |||
629 | 658 | ||
630 | len = input_print_modalias(buf, PAGE_SIZE, id, 1); | 659 | len = input_print_modalias(buf, PAGE_SIZE, id, 1); |
631 | 660 | ||
632 | return max_t(int, len, PAGE_SIZE); | 661 | return min_t(int, len, PAGE_SIZE); |
633 | } | 662 | } |
634 | static CLASS_DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL); | 663 | static CLASS_DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL); |
635 | 664 | ||
@@ -862,6 +891,7 @@ struct class input_class = { | |||
862 | .release = input_dev_release, | 891 | .release = input_dev_release, |
863 | .uevent = input_dev_uevent, | 892 | .uevent = input_dev_uevent, |
864 | }; | 893 | }; |
894 | EXPORT_SYMBOL_GPL(input_class); | ||
865 | 895 | ||
866 | struct input_dev *input_allocate_device(void) | 896 | struct input_dev *input_allocate_device(void) |
867 | { | 897 | { |
@@ -872,12 +902,27 @@ struct input_dev *input_allocate_device(void) | |||
872 | dev->dynalloc = 1; | 902 | dev->dynalloc = 1; |
873 | dev->cdev.class = &input_class; | 903 | dev->cdev.class = &input_class; |
874 | class_device_initialize(&dev->cdev); | 904 | class_device_initialize(&dev->cdev); |
905 | mutex_init(&dev->mutex); | ||
875 | INIT_LIST_HEAD(&dev->h_list); | 906 | INIT_LIST_HEAD(&dev->h_list); |
876 | INIT_LIST_HEAD(&dev->node); | 907 | INIT_LIST_HEAD(&dev->node); |
877 | } | 908 | } |
878 | 909 | ||
879 | return dev; | 910 | return dev; |
880 | } | 911 | } |
912 | EXPORT_SYMBOL(input_allocate_device); | ||
913 | |||
914 | void input_free_device(struct input_dev *dev) | ||
915 | { | ||
916 | if (dev) { | ||
917 | |||
918 | mutex_lock(&dev->mutex); | ||
919 | dev->name = dev->phys = dev->uniq = NULL; | ||
920 | mutex_unlock(&dev->mutex); | ||
921 | |||
922 | input_put_device(dev); | ||
923 | } | ||
924 | } | ||
925 | EXPORT_SYMBOL(input_free_device); | ||
881 | 926 | ||
882 | int input_register_device(struct input_dev *dev) | 927 | int input_register_device(struct input_dev *dev) |
883 | { | 928 | { |
@@ -895,7 +940,6 @@ int input_register_device(struct input_dev *dev) | |||
895 | return -EINVAL; | 940 | return -EINVAL; |
896 | } | 941 | } |
897 | 942 | ||
898 | mutex_init(&dev->mutex); | ||
899 | set_bit(EV_SYN, dev->evbit); | 943 | set_bit(EV_SYN, dev->evbit); |
900 | 944 | ||
901 | /* | 945 | /* |
@@ -944,8 +988,11 @@ int input_register_device(struct input_dev *dev) | |||
944 | list_for_each_entry(handler, &input_handler_list, node) | 988 | list_for_each_entry(handler, &input_handler_list, node) |
945 | if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) | 989 | if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) |
946 | if ((id = input_match_device(handler->id_table, dev))) | 990 | if ((id = input_match_device(handler->id_table, dev))) |
947 | if ((handle = handler->connect(handler, dev, id))) | 991 | if ((handle = handler->connect(handler, dev, id))) { |
948 | input_link_handle(handle); | 992 | input_link_handle(handle); |
993 | if (handler->start) | ||
994 | handler->start(handle); | ||
995 | } | ||
949 | 996 | ||
950 | input_wakeup_procfs_readers(); | 997 | input_wakeup_procfs_readers(); |
951 | 998 | ||
@@ -956,12 +1003,14 @@ int input_register_device(struct input_dev *dev) | |||
956 | fail1: class_device_del(&dev->cdev); | 1003 | fail1: class_device_del(&dev->cdev); |
957 | return error; | 1004 | return error; |
958 | } | 1005 | } |
1006 | EXPORT_SYMBOL(input_register_device); | ||
959 | 1007 | ||
960 | void input_unregister_device(struct input_dev *dev) | 1008 | void input_unregister_device(struct input_dev *dev) |
961 | { | 1009 | { |
962 | struct list_head * node, * next; | 1010 | struct list_head *node, *next; |
963 | 1011 | ||
964 | if (!dev) return; | 1012 | if (!dev) |
1013 | return; | ||
965 | 1014 | ||
966 | del_timer_sync(&dev->timer); | 1015 | del_timer_sync(&dev->timer); |
967 | 1016 | ||
@@ -977,10 +1026,16 @@ void input_unregister_device(struct input_dev *dev) | |||
977 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group); | 1026 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group); |
978 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group); | 1027 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group); |
979 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group); | 1028 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group); |
1029 | |||
1030 | mutex_lock(&dev->mutex); | ||
1031 | dev->name = dev->phys = dev->uniq = NULL; | ||
1032 | mutex_unlock(&dev->mutex); | ||
1033 | |||
980 | class_device_unregister(&dev->cdev); | 1034 | class_device_unregister(&dev->cdev); |
981 | 1035 | ||
982 | input_wakeup_procfs_readers(); | 1036 | input_wakeup_procfs_readers(); |
983 | } | 1037 | } |
1038 | EXPORT_SYMBOL(input_unregister_device); | ||
984 | 1039 | ||
985 | void input_register_handler(struct input_handler *handler) | 1040 | void input_register_handler(struct input_handler *handler) |
986 | { | 1041 | { |
@@ -988,7 +1043,8 @@ void input_register_handler(struct input_handler *handler) | |||
988 | struct input_handle *handle; | 1043 | struct input_handle *handle; |
989 | struct input_device_id *id; | 1044 | struct input_device_id *id; |
990 | 1045 | ||
991 | if (!handler) return; | 1046 | if (!handler) |
1047 | return; | ||
992 | 1048 | ||
993 | INIT_LIST_HEAD(&handler->h_list); | 1049 | INIT_LIST_HEAD(&handler->h_list); |
994 | 1050 | ||
@@ -1000,15 +1056,19 @@ void input_register_handler(struct input_handler *handler) | |||
1000 | list_for_each_entry(dev, &input_dev_list, node) | 1056 | list_for_each_entry(dev, &input_dev_list, node) |
1001 | if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) | 1057 | if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) |
1002 | if ((id = input_match_device(handler->id_table, dev))) | 1058 | if ((id = input_match_device(handler->id_table, dev))) |
1003 | if ((handle = handler->connect(handler, dev, id))) | 1059 | if ((handle = handler->connect(handler, dev, id))) { |
1004 | input_link_handle(handle); | 1060 | input_link_handle(handle); |
1061 | if (handler->start) | ||
1062 | handler->start(handle); | ||
1063 | } | ||
1005 | 1064 | ||
1006 | input_wakeup_procfs_readers(); | 1065 | input_wakeup_procfs_readers(); |
1007 | } | 1066 | } |
1067 | EXPORT_SYMBOL(input_register_handler); | ||
1008 | 1068 | ||
1009 | void input_unregister_handler(struct input_handler *handler) | 1069 | void input_unregister_handler(struct input_handler *handler) |
1010 | { | 1070 | { |
1011 | struct list_head * node, * next; | 1071 | struct list_head *node, *next; |
1012 | 1072 | ||
1013 | list_for_each_safe(node, next, &handler->h_list) { | 1073 | list_for_each_safe(node, next, &handler->h_list) { |
1014 | struct input_handle * handle = to_handle_h(node); | 1074 | struct input_handle * handle = to_handle_h(node); |
@@ -1024,6 +1084,7 @@ void input_unregister_handler(struct input_handler *handler) | |||
1024 | 1084 | ||
1025 | input_wakeup_procfs_readers(); | 1085 | input_wakeup_procfs_readers(); |
1026 | } | 1086 | } |
1087 | EXPORT_SYMBOL(input_unregister_handler); | ||
1027 | 1088 | ||
1028 | static int input_open_file(struct inode *inode, struct file *file) | 1089 | static int input_open_file(struct inode *inode, struct file *file) |
1029 | { | 1090 | { |