Commit cb6ecf6f7afece066265e243657b0ac28150a7b2

Authored by Henrik Rydberg
Committed by Dmitry Torokhov
1 parent 93fb84b50f

Input: add the ABS_MT_PRESSURE event

For pressure-based multi-touch devices, a direct way to send sensor
intensity data per finger is needed. This patch adds the ABS_MT_PRESSURE
event to the MT protocol.

Requested-by: Yoonyoung Shim <jy0922.shim@samsung.com>
Requested-by: Mika Kuoppala <mika.kuoppala@nokia.com>
Requested-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

Showing 2 changed files with 2 additions and 0 deletions Inline Diff

drivers/input/input.c
1 /* 1 /*
2 * The input core 2 * The input core
3 * 3 *
4 * Copyright (c) 1999-2002 Vojtech Pavlik 4 * Copyright (c) 1999-2002 Vojtech Pavlik
5 */ 5 */
6 6
7 /* 7 /*
8 * This program is free software; you can redistribute it and/or modify it 8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by 9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation. 10 * the Free Software Foundation.
11 */ 11 */
12 12
13 #include <linux/init.h> 13 #include <linux/init.h>
14 #include <linux/types.h> 14 #include <linux/types.h>
15 #include <linux/input.h> 15 #include <linux/input.h>
16 #include <linux/module.h> 16 #include <linux/module.h>
17 #include <linux/random.h> 17 #include <linux/random.h>
18 #include <linux/major.h> 18 #include <linux/major.h>
19 #include <linux/proc_fs.h> 19 #include <linux/proc_fs.h>
20 #include <linux/sched.h> 20 #include <linux/sched.h>
21 #include <linux/seq_file.h> 21 #include <linux/seq_file.h>
22 #include <linux/poll.h> 22 #include <linux/poll.h>
23 #include <linux/device.h> 23 #include <linux/device.h>
24 #include <linux/mutex.h> 24 #include <linux/mutex.h>
25 #include <linux/rcupdate.h> 25 #include <linux/rcupdate.h>
26 #include <linux/smp_lock.h> 26 #include <linux/smp_lock.h>
27 #include "input-compat.h" 27 #include "input-compat.h"
28 28
29 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 29 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
30 MODULE_DESCRIPTION("Input core"); 30 MODULE_DESCRIPTION("Input core");
31 MODULE_LICENSE("GPL"); 31 MODULE_LICENSE("GPL");
32 32
33 #define INPUT_DEVICES 256 33 #define INPUT_DEVICES 256
34 34
35 /* 35 /*
36 * EV_ABS events which should not be cached are listed here. 36 * EV_ABS events which should not be cached are listed here.
37 */ 37 */
38 static unsigned int input_abs_bypass_init_data[] __initdata = { 38 static unsigned int input_abs_bypass_init_data[] __initdata = {
39 ABS_MT_TOUCH_MAJOR, 39 ABS_MT_TOUCH_MAJOR,
40 ABS_MT_TOUCH_MINOR, 40 ABS_MT_TOUCH_MINOR,
41 ABS_MT_WIDTH_MAJOR, 41 ABS_MT_WIDTH_MAJOR,
42 ABS_MT_WIDTH_MINOR, 42 ABS_MT_WIDTH_MINOR,
43 ABS_MT_ORIENTATION, 43 ABS_MT_ORIENTATION,
44 ABS_MT_POSITION_X, 44 ABS_MT_POSITION_X,
45 ABS_MT_POSITION_Y, 45 ABS_MT_POSITION_Y,
46 ABS_MT_TOOL_TYPE, 46 ABS_MT_TOOL_TYPE,
47 ABS_MT_BLOB_ID, 47 ABS_MT_BLOB_ID,
48 ABS_MT_TRACKING_ID, 48 ABS_MT_TRACKING_ID,
49 ABS_MT_PRESSURE,
49 0 50 0
50 }; 51 };
51 static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)]; 52 static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)];
52 53
53 static LIST_HEAD(input_dev_list); 54 static LIST_HEAD(input_dev_list);
54 static LIST_HEAD(input_handler_list); 55 static LIST_HEAD(input_handler_list);
55 56
56 /* 57 /*
57 * input_mutex protects access to both input_dev_list and input_handler_list. 58 * input_mutex protects access to both input_dev_list and input_handler_list.
58 * This also causes input_[un]register_device and input_[un]register_handler 59 * This also causes input_[un]register_device and input_[un]register_handler
59 * be mutually exclusive which simplifies locking in drivers implementing 60 * be mutually exclusive which simplifies locking in drivers implementing
60 * input handlers. 61 * input handlers.
61 */ 62 */
62 static DEFINE_MUTEX(input_mutex); 63 static DEFINE_MUTEX(input_mutex);
63 64
64 static struct input_handler *input_table[8]; 65 static struct input_handler *input_table[8];
65 66
66 static inline int is_event_supported(unsigned int code, 67 static inline int is_event_supported(unsigned int code,
67 unsigned long *bm, unsigned int max) 68 unsigned long *bm, unsigned int max)
68 { 69 {
69 return code <= max && test_bit(code, bm); 70 return code <= max && test_bit(code, bm);
70 } 71 }
71 72
72 static int input_defuzz_abs_event(int value, int old_val, int fuzz) 73 static int input_defuzz_abs_event(int value, int old_val, int fuzz)
73 { 74 {
74 if (fuzz) { 75 if (fuzz) {
75 if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2) 76 if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2)
76 return old_val; 77 return old_val;
77 78
78 if (value > old_val - fuzz && value < old_val + fuzz) 79 if (value > old_val - fuzz && value < old_val + fuzz)
79 return (old_val * 3 + value) / 4; 80 return (old_val * 3 + value) / 4;
80 81
81 if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2) 82 if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2)
82 return (old_val + value) / 2; 83 return (old_val + value) / 2;
83 } 84 }
84 85
85 return value; 86 return value;
86 } 87 }
87 88
88 /* 89 /*
89 * Pass event through all open handles. This function is called with 90 * Pass event through all open handles. This function is called with
90 * dev->event_lock held and interrupts disabled. 91 * dev->event_lock held and interrupts disabled.
91 */ 92 */
92 static void input_pass_event(struct input_dev *dev, 93 static void input_pass_event(struct input_dev *dev,
93 unsigned int type, unsigned int code, int value) 94 unsigned int type, unsigned int code, int value)
94 { 95 {
95 struct input_handle *handle; 96 struct input_handle *handle;
96 97
97 rcu_read_lock(); 98 rcu_read_lock();
98 99
99 handle = rcu_dereference(dev->grab); 100 handle = rcu_dereference(dev->grab);
100 if (handle) 101 if (handle)
101 handle->handler->event(handle, type, code, value); 102 handle->handler->event(handle, type, code, value);
102 else 103 else
103 list_for_each_entry_rcu(handle, &dev->h_list, d_node) 104 list_for_each_entry_rcu(handle, &dev->h_list, d_node)
104 if (handle->open) 105 if (handle->open)
105 handle->handler->event(handle, 106 handle->handler->event(handle,
106 type, code, value); 107 type, code, value);
107 rcu_read_unlock(); 108 rcu_read_unlock();
108 } 109 }
109 110
110 /* 111 /*
111 * Generate software autorepeat event. Note that we take 112 * Generate software autorepeat event. Note that we take
112 * dev->event_lock here to avoid racing with input_event 113 * dev->event_lock here to avoid racing with input_event
113 * which may cause keys get "stuck". 114 * which may cause keys get "stuck".
114 */ 115 */
115 static void input_repeat_key(unsigned long data) 116 static void input_repeat_key(unsigned long data)
116 { 117 {
117 struct input_dev *dev = (void *) data; 118 struct input_dev *dev = (void *) data;
118 unsigned long flags; 119 unsigned long flags;
119 120
120 spin_lock_irqsave(&dev->event_lock, flags); 121 spin_lock_irqsave(&dev->event_lock, flags);
121 122
122 if (test_bit(dev->repeat_key, dev->key) && 123 if (test_bit(dev->repeat_key, dev->key) &&
123 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 124 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
124 125
125 input_pass_event(dev, EV_KEY, dev->repeat_key, 2); 126 input_pass_event(dev, EV_KEY, dev->repeat_key, 2);
126 127
127 if (dev->sync) { 128 if (dev->sync) {
128 /* 129 /*
129 * Only send SYN_REPORT if we are not in a middle 130 * Only send SYN_REPORT if we are not in a middle
130 * of driver parsing a new hardware packet. 131 * of driver parsing a new hardware packet.
131 * Otherwise assume that the driver will send 132 * Otherwise assume that the driver will send
132 * SYN_REPORT once it's done. 133 * SYN_REPORT once it's done.
133 */ 134 */
134 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 135 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
135 } 136 }
136 137
137 if (dev->rep[REP_PERIOD]) 138 if (dev->rep[REP_PERIOD])
138 mod_timer(&dev->timer, jiffies + 139 mod_timer(&dev->timer, jiffies +
139 msecs_to_jiffies(dev->rep[REP_PERIOD])); 140 msecs_to_jiffies(dev->rep[REP_PERIOD]));
140 } 141 }
141 142
142 spin_unlock_irqrestore(&dev->event_lock, flags); 143 spin_unlock_irqrestore(&dev->event_lock, flags);
143 } 144 }
144 145
145 static void input_start_autorepeat(struct input_dev *dev, int code) 146 static void input_start_autorepeat(struct input_dev *dev, int code)
146 { 147 {
147 if (test_bit(EV_REP, dev->evbit) && 148 if (test_bit(EV_REP, dev->evbit) &&
148 dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] && 149 dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] &&
149 dev->timer.data) { 150 dev->timer.data) {
150 dev->repeat_key = code; 151 dev->repeat_key = code;
151 mod_timer(&dev->timer, 152 mod_timer(&dev->timer,
152 jiffies + msecs_to_jiffies(dev->rep[REP_DELAY])); 153 jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
153 } 154 }
154 } 155 }
155 156
156 static void input_stop_autorepeat(struct input_dev *dev) 157 static void input_stop_autorepeat(struct input_dev *dev)
157 { 158 {
158 del_timer(&dev->timer); 159 del_timer(&dev->timer);
159 } 160 }
160 161
161 #define INPUT_IGNORE_EVENT 0 162 #define INPUT_IGNORE_EVENT 0
162 #define INPUT_PASS_TO_HANDLERS 1 163 #define INPUT_PASS_TO_HANDLERS 1
163 #define INPUT_PASS_TO_DEVICE 2 164 #define INPUT_PASS_TO_DEVICE 2
164 #define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 165 #define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
165 166
166 static void input_handle_event(struct input_dev *dev, 167 static void input_handle_event(struct input_dev *dev,
167 unsigned int type, unsigned int code, int value) 168 unsigned int type, unsigned int code, int value)
168 { 169 {
169 int disposition = INPUT_IGNORE_EVENT; 170 int disposition = INPUT_IGNORE_EVENT;
170 171
171 switch (type) { 172 switch (type) {
172 173
173 case EV_SYN: 174 case EV_SYN:
174 switch (code) { 175 switch (code) {
175 case SYN_CONFIG: 176 case SYN_CONFIG:
176 disposition = INPUT_PASS_TO_ALL; 177 disposition = INPUT_PASS_TO_ALL;
177 break; 178 break;
178 179
179 case SYN_REPORT: 180 case SYN_REPORT:
180 if (!dev->sync) { 181 if (!dev->sync) {
181 dev->sync = 1; 182 dev->sync = 1;
182 disposition = INPUT_PASS_TO_HANDLERS; 183 disposition = INPUT_PASS_TO_HANDLERS;
183 } 184 }
184 break; 185 break;
185 case SYN_MT_REPORT: 186 case SYN_MT_REPORT:
186 dev->sync = 0; 187 dev->sync = 0;
187 disposition = INPUT_PASS_TO_HANDLERS; 188 disposition = INPUT_PASS_TO_HANDLERS;
188 break; 189 break;
189 } 190 }
190 break; 191 break;
191 192
192 case EV_KEY: 193 case EV_KEY:
193 if (is_event_supported(code, dev->keybit, KEY_MAX) && 194 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
194 !!test_bit(code, dev->key) != value) { 195 !!test_bit(code, dev->key) != value) {
195 196
196 if (value != 2) { 197 if (value != 2) {
197 __change_bit(code, dev->key); 198 __change_bit(code, dev->key);
198 if (value) 199 if (value)
199 input_start_autorepeat(dev, code); 200 input_start_autorepeat(dev, code);
200 else 201 else
201 input_stop_autorepeat(dev); 202 input_stop_autorepeat(dev);
202 } 203 }
203 204
204 disposition = INPUT_PASS_TO_HANDLERS; 205 disposition = INPUT_PASS_TO_HANDLERS;
205 } 206 }
206 break; 207 break;
207 208
208 case EV_SW: 209 case EV_SW:
209 if (is_event_supported(code, dev->swbit, SW_MAX) && 210 if (is_event_supported(code, dev->swbit, SW_MAX) &&
210 !!test_bit(code, dev->sw) != value) { 211 !!test_bit(code, dev->sw) != value) {
211 212
212 __change_bit(code, dev->sw); 213 __change_bit(code, dev->sw);
213 disposition = INPUT_PASS_TO_HANDLERS; 214 disposition = INPUT_PASS_TO_HANDLERS;
214 } 215 }
215 break; 216 break;
216 217
217 case EV_ABS: 218 case EV_ABS:
218 if (is_event_supported(code, dev->absbit, ABS_MAX)) { 219 if (is_event_supported(code, dev->absbit, ABS_MAX)) {
219 220
220 if (test_bit(code, input_abs_bypass)) { 221 if (test_bit(code, input_abs_bypass)) {
221 disposition = INPUT_PASS_TO_HANDLERS; 222 disposition = INPUT_PASS_TO_HANDLERS;
222 break; 223 break;
223 } 224 }
224 225
225 value = input_defuzz_abs_event(value, 226 value = input_defuzz_abs_event(value,
226 dev->abs[code], dev->absfuzz[code]); 227 dev->abs[code], dev->absfuzz[code]);
227 228
228 if (dev->abs[code] != value) { 229 if (dev->abs[code] != value) {
229 dev->abs[code] = value; 230 dev->abs[code] = value;
230 disposition = INPUT_PASS_TO_HANDLERS; 231 disposition = INPUT_PASS_TO_HANDLERS;
231 } 232 }
232 } 233 }
233 break; 234 break;
234 235
235 case EV_REL: 236 case EV_REL:
236 if (is_event_supported(code, dev->relbit, REL_MAX) && value) 237 if (is_event_supported(code, dev->relbit, REL_MAX) && value)
237 disposition = INPUT_PASS_TO_HANDLERS; 238 disposition = INPUT_PASS_TO_HANDLERS;
238 239
239 break; 240 break;
240 241
241 case EV_MSC: 242 case EV_MSC:
242 if (is_event_supported(code, dev->mscbit, MSC_MAX)) 243 if (is_event_supported(code, dev->mscbit, MSC_MAX))
243 disposition = INPUT_PASS_TO_ALL; 244 disposition = INPUT_PASS_TO_ALL;
244 245
245 break; 246 break;
246 247
247 case EV_LED: 248 case EV_LED:
248 if (is_event_supported(code, dev->ledbit, LED_MAX) && 249 if (is_event_supported(code, dev->ledbit, LED_MAX) &&
249 !!test_bit(code, dev->led) != value) { 250 !!test_bit(code, dev->led) != value) {
250 251
251 __change_bit(code, dev->led); 252 __change_bit(code, dev->led);
252 disposition = INPUT_PASS_TO_ALL; 253 disposition = INPUT_PASS_TO_ALL;
253 } 254 }
254 break; 255 break;
255 256
256 case EV_SND: 257 case EV_SND:
257 if (is_event_supported(code, dev->sndbit, SND_MAX)) { 258 if (is_event_supported(code, dev->sndbit, SND_MAX)) {
258 259
259 if (!!test_bit(code, dev->snd) != !!value) 260 if (!!test_bit(code, dev->snd) != !!value)
260 __change_bit(code, dev->snd); 261 __change_bit(code, dev->snd);
261 disposition = INPUT_PASS_TO_ALL; 262 disposition = INPUT_PASS_TO_ALL;
262 } 263 }
263 break; 264 break;
264 265
265 case EV_REP: 266 case EV_REP:
266 if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) { 267 if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) {
267 dev->rep[code] = value; 268 dev->rep[code] = value;
268 disposition = INPUT_PASS_TO_ALL; 269 disposition = INPUT_PASS_TO_ALL;
269 } 270 }
270 break; 271 break;
271 272
272 case EV_FF: 273 case EV_FF:
273 if (value >= 0) 274 if (value >= 0)
274 disposition = INPUT_PASS_TO_ALL; 275 disposition = INPUT_PASS_TO_ALL;
275 break; 276 break;
276 277
277 case EV_PWR: 278 case EV_PWR:
278 disposition = INPUT_PASS_TO_ALL; 279 disposition = INPUT_PASS_TO_ALL;
279 break; 280 break;
280 } 281 }
281 282
282 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) 283 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
283 dev->sync = 0; 284 dev->sync = 0;
284 285
285 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 286 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
286 dev->event(dev, type, code, value); 287 dev->event(dev, type, code, value);
287 288
288 if (disposition & INPUT_PASS_TO_HANDLERS) 289 if (disposition & INPUT_PASS_TO_HANDLERS)
289 input_pass_event(dev, type, code, value); 290 input_pass_event(dev, type, code, value);
290 } 291 }
291 292
292 /** 293 /**
293 * input_event() - report new input event 294 * input_event() - report new input event
294 * @dev: device that generated the event 295 * @dev: device that generated the event
295 * @type: type of the event 296 * @type: type of the event
296 * @code: event code 297 * @code: event code
297 * @value: value of the event 298 * @value: value of the event
298 * 299 *
299 * This function should be used by drivers implementing various input 300 * This function should be used by drivers implementing various input
300 * devices to report input events. See also input_inject_event(). 301 * devices to report input events. See also input_inject_event().
301 * 302 *
302 * NOTE: input_event() may be safely used right after input device was 303 * NOTE: input_event() may be safely used right after input device was
303 * allocated with input_allocate_device(), even before it is registered 304 * allocated with input_allocate_device(), even before it is registered
304 * with input_register_device(), but the event will not reach any of the 305 * with input_register_device(), but the event will not reach any of the
305 * input handlers. Such early invocation of input_event() may be used 306 * input handlers. Such early invocation of input_event() may be used
306 * to 'seed' initial state of a switch or initial position of absolute 307 * to 'seed' initial state of a switch or initial position of absolute
307 * axis, etc. 308 * axis, etc.
308 */ 309 */
309 void input_event(struct input_dev *dev, 310 void input_event(struct input_dev *dev,
310 unsigned int type, unsigned int code, int value) 311 unsigned int type, unsigned int code, int value)
311 { 312 {
312 unsigned long flags; 313 unsigned long flags;
313 314
314 if (is_event_supported(type, dev->evbit, EV_MAX)) { 315 if (is_event_supported(type, dev->evbit, EV_MAX)) {
315 316
316 spin_lock_irqsave(&dev->event_lock, flags); 317 spin_lock_irqsave(&dev->event_lock, flags);
317 add_input_randomness(type, code, value); 318 add_input_randomness(type, code, value);
318 input_handle_event(dev, type, code, value); 319 input_handle_event(dev, type, code, value);
319 spin_unlock_irqrestore(&dev->event_lock, flags); 320 spin_unlock_irqrestore(&dev->event_lock, flags);
320 } 321 }
321 } 322 }
322 EXPORT_SYMBOL(input_event); 323 EXPORT_SYMBOL(input_event);
323 324
324 /** 325 /**
325 * input_inject_event() - send input event from input handler 326 * input_inject_event() - send input event from input handler
326 * @handle: input handle to send event through 327 * @handle: input handle to send event through
327 * @type: type of the event 328 * @type: type of the event
328 * @code: event code 329 * @code: event code
329 * @value: value of the event 330 * @value: value of the event
330 * 331 *
331 * Similar to input_event() but will ignore event if device is 332 * Similar to input_event() but will ignore event if device is
332 * "grabbed" and handle injecting event is not the one that owns 333 * "grabbed" and handle injecting event is not the one that owns
333 * the device. 334 * the device.
334 */ 335 */
335 void input_inject_event(struct input_handle *handle, 336 void input_inject_event(struct input_handle *handle,
336 unsigned int type, unsigned int code, int value) 337 unsigned int type, unsigned int code, int value)
337 { 338 {
338 struct input_dev *dev = handle->dev; 339 struct input_dev *dev = handle->dev;
339 struct input_handle *grab; 340 struct input_handle *grab;
340 unsigned long flags; 341 unsigned long flags;
341 342
342 if (is_event_supported(type, dev->evbit, EV_MAX)) { 343 if (is_event_supported(type, dev->evbit, EV_MAX)) {
343 spin_lock_irqsave(&dev->event_lock, flags); 344 spin_lock_irqsave(&dev->event_lock, flags);
344 345
345 rcu_read_lock(); 346 rcu_read_lock();
346 grab = rcu_dereference(dev->grab); 347 grab = rcu_dereference(dev->grab);
347 if (!grab || grab == handle) 348 if (!grab || grab == handle)
348 input_handle_event(dev, type, code, value); 349 input_handle_event(dev, type, code, value);
349 rcu_read_unlock(); 350 rcu_read_unlock();
350 351
351 spin_unlock_irqrestore(&dev->event_lock, flags); 352 spin_unlock_irqrestore(&dev->event_lock, flags);
352 } 353 }
353 } 354 }
354 EXPORT_SYMBOL(input_inject_event); 355 EXPORT_SYMBOL(input_inject_event);
355 356
356 /** 357 /**
357 * input_grab_device - grabs device for exclusive use 358 * input_grab_device - grabs device for exclusive use
358 * @handle: input handle that wants to own the device 359 * @handle: input handle that wants to own the device
359 * 360 *
360 * When a device is grabbed by an input handle all events generated by 361 * When a device is grabbed by an input handle all events generated by
361 * the device are delivered only to this handle. Also events injected 362 * the device are delivered only to this handle. Also events injected
362 * by other input handles are ignored while device is grabbed. 363 * by other input handles are ignored while device is grabbed.
363 */ 364 */
364 int input_grab_device(struct input_handle *handle) 365 int input_grab_device(struct input_handle *handle)
365 { 366 {
366 struct input_dev *dev = handle->dev; 367 struct input_dev *dev = handle->dev;
367 int retval; 368 int retval;
368 369
369 retval = mutex_lock_interruptible(&dev->mutex); 370 retval = mutex_lock_interruptible(&dev->mutex);
370 if (retval) 371 if (retval)
371 return retval; 372 return retval;
372 373
373 if (dev->grab) { 374 if (dev->grab) {
374 retval = -EBUSY; 375 retval = -EBUSY;
375 goto out; 376 goto out;
376 } 377 }
377 378
378 rcu_assign_pointer(dev->grab, handle); 379 rcu_assign_pointer(dev->grab, handle);
379 synchronize_rcu(); 380 synchronize_rcu();
380 381
381 out: 382 out:
382 mutex_unlock(&dev->mutex); 383 mutex_unlock(&dev->mutex);
383 return retval; 384 return retval;
384 } 385 }
385 EXPORT_SYMBOL(input_grab_device); 386 EXPORT_SYMBOL(input_grab_device);
386 387
387 static void __input_release_device(struct input_handle *handle) 388 static void __input_release_device(struct input_handle *handle)
388 { 389 {
389 struct input_dev *dev = handle->dev; 390 struct input_dev *dev = handle->dev;
390 391
391 if (dev->grab == handle) { 392 if (dev->grab == handle) {
392 rcu_assign_pointer(dev->grab, NULL); 393 rcu_assign_pointer(dev->grab, NULL);
393 /* Make sure input_pass_event() notices that grab is gone */ 394 /* Make sure input_pass_event() notices that grab is gone */
394 synchronize_rcu(); 395 synchronize_rcu();
395 396
396 list_for_each_entry(handle, &dev->h_list, d_node) 397 list_for_each_entry(handle, &dev->h_list, d_node)
397 if (handle->open && handle->handler->start) 398 if (handle->open && handle->handler->start)
398 handle->handler->start(handle); 399 handle->handler->start(handle);
399 } 400 }
400 } 401 }
401 402
402 /** 403 /**
403 * input_release_device - release previously grabbed device 404 * input_release_device - release previously grabbed device
404 * @handle: input handle that owns the device 405 * @handle: input handle that owns the device
405 * 406 *
406 * Releases previously grabbed device so that other input handles can 407 * Releases previously grabbed device so that other input handles can
407 * start receiving input events. Upon release all handlers attached 408 * start receiving input events. Upon release all handlers attached
408 * to the device have their start() method called so they have a change 409 * to the device have their start() method called so they have a change
409 * to synchronize device state with the rest of the system. 410 * to synchronize device state with the rest of the system.
410 */ 411 */
411 void input_release_device(struct input_handle *handle) 412 void input_release_device(struct input_handle *handle)
412 { 413 {
413 struct input_dev *dev = handle->dev; 414 struct input_dev *dev = handle->dev;
414 415
415 mutex_lock(&dev->mutex); 416 mutex_lock(&dev->mutex);
416 __input_release_device(handle); 417 __input_release_device(handle);
417 mutex_unlock(&dev->mutex); 418 mutex_unlock(&dev->mutex);
418 } 419 }
419 EXPORT_SYMBOL(input_release_device); 420 EXPORT_SYMBOL(input_release_device);
420 421
421 /** 422 /**
422 * input_open_device - open input device 423 * input_open_device - open input device
423 * @handle: handle through which device is being accessed 424 * @handle: handle through which device is being accessed
424 * 425 *
425 * This function should be called by input handlers when they 426 * This function should be called by input handlers when they
426 * want to start receive events from given input device. 427 * want to start receive events from given input device.
427 */ 428 */
428 int input_open_device(struct input_handle *handle) 429 int input_open_device(struct input_handle *handle)
429 { 430 {
430 struct input_dev *dev = handle->dev; 431 struct input_dev *dev = handle->dev;
431 int retval; 432 int retval;
432 433
433 retval = mutex_lock_interruptible(&dev->mutex); 434 retval = mutex_lock_interruptible(&dev->mutex);
434 if (retval) 435 if (retval)
435 return retval; 436 return retval;
436 437
437 if (dev->going_away) { 438 if (dev->going_away) {
438 retval = -ENODEV; 439 retval = -ENODEV;
439 goto out; 440 goto out;
440 } 441 }
441 442
442 handle->open++; 443 handle->open++;
443 444
444 if (!dev->users++ && dev->open) 445 if (!dev->users++ && dev->open)
445 retval = dev->open(dev); 446 retval = dev->open(dev);
446 447
447 if (retval) { 448 if (retval) {
448 dev->users--; 449 dev->users--;
449 if (!--handle->open) { 450 if (!--handle->open) {
450 /* 451 /*
451 * Make sure we are not delivering any more events 452 * Make sure we are not delivering any more events
452 * through this handle 453 * through this handle
453 */ 454 */
454 synchronize_rcu(); 455 synchronize_rcu();
455 } 456 }
456 } 457 }
457 458
458 out: 459 out:
459 mutex_unlock(&dev->mutex); 460 mutex_unlock(&dev->mutex);
460 return retval; 461 return retval;
461 } 462 }
462 EXPORT_SYMBOL(input_open_device); 463 EXPORT_SYMBOL(input_open_device);
463 464
464 int input_flush_device(struct input_handle *handle, struct file *file) 465 int input_flush_device(struct input_handle *handle, struct file *file)
465 { 466 {
466 struct input_dev *dev = handle->dev; 467 struct input_dev *dev = handle->dev;
467 int retval; 468 int retval;
468 469
469 retval = mutex_lock_interruptible(&dev->mutex); 470 retval = mutex_lock_interruptible(&dev->mutex);
470 if (retval) 471 if (retval)
471 return retval; 472 return retval;
472 473
473 if (dev->flush) 474 if (dev->flush)
474 retval = dev->flush(dev, file); 475 retval = dev->flush(dev, file);
475 476
476 mutex_unlock(&dev->mutex); 477 mutex_unlock(&dev->mutex);
477 return retval; 478 return retval;
478 } 479 }
479 EXPORT_SYMBOL(input_flush_device); 480 EXPORT_SYMBOL(input_flush_device);
480 481
481 /** 482 /**
482 * input_close_device - close input device 483 * input_close_device - close input device
483 * @handle: handle through which device is being accessed 484 * @handle: handle through which device is being accessed
484 * 485 *
485 * This function should be called by input handlers when they 486 * This function should be called by input handlers when they
486 * want to stop receive events from given input device. 487 * want to stop receive events from given input device.
487 */ 488 */
488 void input_close_device(struct input_handle *handle) 489 void input_close_device(struct input_handle *handle)
489 { 490 {
490 struct input_dev *dev = handle->dev; 491 struct input_dev *dev = handle->dev;
491 492
492 mutex_lock(&dev->mutex); 493 mutex_lock(&dev->mutex);
493 494
494 __input_release_device(handle); 495 __input_release_device(handle);
495 496
496 if (!--dev->users && dev->close) 497 if (!--dev->users && dev->close)
497 dev->close(dev); 498 dev->close(dev);
498 499
499 if (!--handle->open) { 500 if (!--handle->open) {
500 /* 501 /*
501 * synchronize_rcu() makes sure that input_pass_event() 502 * synchronize_rcu() makes sure that input_pass_event()
502 * completed and that no more input events are delivered 503 * completed and that no more input events are delivered
503 * through this handle 504 * through this handle
504 */ 505 */
505 synchronize_rcu(); 506 synchronize_rcu();
506 } 507 }
507 508
508 mutex_unlock(&dev->mutex); 509 mutex_unlock(&dev->mutex);
509 } 510 }
510 EXPORT_SYMBOL(input_close_device); 511 EXPORT_SYMBOL(input_close_device);
511 512
512 /* 513 /*
513 * Prepare device for unregistering 514 * Prepare device for unregistering
514 */ 515 */
515 static void input_disconnect_device(struct input_dev *dev) 516 static void input_disconnect_device(struct input_dev *dev)
516 { 517 {
517 struct input_handle *handle; 518 struct input_handle *handle;
518 int code; 519 int code;
519 520
520 /* 521 /*
521 * Mark device as going away. Note that we take dev->mutex here 522 * Mark device as going away. Note that we take dev->mutex here
522 * not to protect access to dev->going_away but rather to ensure 523 * not to protect access to dev->going_away but rather to ensure
523 * that there are no threads in the middle of input_open_device() 524 * that there are no threads in the middle of input_open_device()
524 */ 525 */
525 mutex_lock(&dev->mutex); 526 mutex_lock(&dev->mutex);
526 dev->going_away = true; 527 dev->going_away = true;
527 mutex_unlock(&dev->mutex); 528 mutex_unlock(&dev->mutex);
528 529
529 spin_lock_irq(&dev->event_lock); 530 spin_lock_irq(&dev->event_lock);
530 531
531 /* 532 /*
532 * Simulate keyup events for all pressed keys so that handlers 533 * Simulate keyup events for all pressed keys so that handlers
533 * are not left with "stuck" keys. The driver may continue 534 * are not left with "stuck" keys. The driver may continue
534 * generate events even after we done here but they will not 535 * generate events even after we done here but they will not
535 * reach any handlers. 536 * reach any handlers.
536 */ 537 */
537 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) { 538 if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
538 for (code = 0; code <= KEY_MAX; code++) { 539 for (code = 0; code <= KEY_MAX; code++) {
539 if (is_event_supported(code, dev->keybit, KEY_MAX) && 540 if (is_event_supported(code, dev->keybit, KEY_MAX) &&
540 __test_and_clear_bit(code, dev->key)) { 541 __test_and_clear_bit(code, dev->key)) {
541 input_pass_event(dev, EV_KEY, code, 0); 542 input_pass_event(dev, EV_KEY, code, 0);
542 } 543 }
543 } 544 }
544 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 545 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
545 } 546 }
546 547
547 list_for_each_entry(handle, &dev->h_list, d_node) 548 list_for_each_entry(handle, &dev->h_list, d_node)
548 handle->open = 0; 549 handle->open = 0;
549 550
550 spin_unlock_irq(&dev->event_lock); 551 spin_unlock_irq(&dev->event_lock);
551 } 552 }
552 553
553 static int input_fetch_keycode(struct input_dev *dev, int scancode) 554 static int input_fetch_keycode(struct input_dev *dev, int scancode)
554 { 555 {
555 switch (dev->keycodesize) { 556 switch (dev->keycodesize) {
556 case 1: 557 case 1:
557 return ((u8 *)dev->keycode)[scancode]; 558 return ((u8 *)dev->keycode)[scancode];
558 559
559 case 2: 560 case 2:
560 return ((u16 *)dev->keycode)[scancode]; 561 return ((u16 *)dev->keycode)[scancode];
561 562
562 default: 563 default:
563 return ((u32 *)dev->keycode)[scancode]; 564 return ((u32 *)dev->keycode)[scancode];
564 } 565 }
565 } 566 }
566 567
567 static int input_default_getkeycode(struct input_dev *dev, 568 static int input_default_getkeycode(struct input_dev *dev,
568 int scancode, int *keycode) 569 int scancode, int *keycode)
569 { 570 {
570 if (!dev->keycodesize) 571 if (!dev->keycodesize)
571 return -EINVAL; 572 return -EINVAL;
572 573
573 if (scancode >= dev->keycodemax) 574 if (scancode >= dev->keycodemax)
574 return -EINVAL; 575 return -EINVAL;
575 576
576 *keycode = input_fetch_keycode(dev, scancode); 577 *keycode = input_fetch_keycode(dev, scancode);
577 578
578 return 0; 579 return 0;
579 } 580 }
580 581
581 static int input_default_setkeycode(struct input_dev *dev, 582 static int input_default_setkeycode(struct input_dev *dev,
582 int scancode, int keycode) 583 int scancode, int keycode)
583 { 584 {
584 int old_keycode; 585 int old_keycode;
585 int i; 586 int i;
586 587
587 if (scancode >= dev->keycodemax) 588 if (scancode >= dev->keycodemax)
588 return -EINVAL; 589 return -EINVAL;
589 590
590 if (!dev->keycodesize) 591 if (!dev->keycodesize)
591 return -EINVAL; 592 return -EINVAL;
592 593
593 if (dev->keycodesize < sizeof(keycode) && (keycode >> (dev->keycodesize * 8))) 594 if (dev->keycodesize < sizeof(keycode) && (keycode >> (dev->keycodesize * 8)))
594 return -EINVAL; 595 return -EINVAL;
595 596
596 switch (dev->keycodesize) { 597 switch (dev->keycodesize) {
597 case 1: { 598 case 1: {
598 u8 *k = (u8 *)dev->keycode; 599 u8 *k = (u8 *)dev->keycode;
599 old_keycode = k[scancode]; 600 old_keycode = k[scancode];
600 k[scancode] = keycode; 601 k[scancode] = keycode;
601 break; 602 break;
602 } 603 }
603 case 2: { 604 case 2: {
604 u16 *k = (u16 *)dev->keycode; 605 u16 *k = (u16 *)dev->keycode;
605 old_keycode = k[scancode]; 606 old_keycode = k[scancode];
606 k[scancode] = keycode; 607 k[scancode] = keycode;
607 break; 608 break;
608 } 609 }
609 default: { 610 default: {
610 u32 *k = (u32 *)dev->keycode; 611 u32 *k = (u32 *)dev->keycode;
611 old_keycode = k[scancode]; 612 old_keycode = k[scancode];
612 k[scancode] = keycode; 613 k[scancode] = keycode;
613 break; 614 break;
614 } 615 }
615 } 616 }
616 617
617 clear_bit(old_keycode, dev->keybit); 618 clear_bit(old_keycode, dev->keybit);
618 set_bit(keycode, dev->keybit); 619 set_bit(keycode, dev->keybit);
619 620
620 for (i = 0; i < dev->keycodemax; i++) { 621 for (i = 0; i < dev->keycodemax; i++) {
621 if (input_fetch_keycode(dev, i) == old_keycode) { 622 if (input_fetch_keycode(dev, i) == old_keycode) {
622 set_bit(old_keycode, dev->keybit); 623 set_bit(old_keycode, dev->keybit);
623 break; /* Setting the bit twice is useless, so break */ 624 break; /* Setting the bit twice is useless, so break */
624 } 625 }
625 } 626 }
626 627
627 return 0; 628 return 0;
628 } 629 }
629 630
630 /** 631 /**
631 * input_get_keycode - retrieve keycode currently mapped to a given scancode 632 * input_get_keycode - retrieve keycode currently mapped to a given scancode
632 * @dev: input device which keymap is being queried 633 * @dev: input device which keymap is being queried
633 * @scancode: scancode (or its equivalent for device in question) for which 634 * @scancode: scancode (or its equivalent for device in question) for which
634 * keycode is needed 635 * keycode is needed
635 * @keycode: result 636 * @keycode: result
636 * 637 *
637 * This function should be called by anyone interested in retrieving current 638 * This function should be called by anyone interested in retrieving current
638 * keymap. Presently keyboard and evdev handlers use it. 639 * keymap. Presently keyboard and evdev handlers use it.
639 */ 640 */
640 int input_get_keycode(struct input_dev *dev, int scancode, int *keycode) 641 int input_get_keycode(struct input_dev *dev, int scancode, int *keycode)
641 { 642 {
642 if (scancode < 0) 643 if (scancode < 0)
643 return -EINVAL; 644 return -EINVAL;
644 645
645 return dev->getkeycode(dev, scancode, keycode); 646 return dev->getkeycode(dev, scancode, keycode);
646 } 647 }
647 EXPORT_SYMBOL(input_get_keycode); 648 EXPORT_SYMBOL(input_get_keycode);
648 649
649 /** 650 /**
650 * input_get_keycode - assign new keycode to a given scancode 651 * input_get_keycode - assign new keycode to a given scancode
651 * @dev: input device which keymap is being updated 652 * @dev: input device which keymap is being updated
652 * @scancode: scancode (or its equivalent for device in question) 653 * @scancode: scancode (or its equivalent for device in question)
653 * @keycode: new keycode to be assigned to the scancode 654 * @keycode: new keycode to be assigned to the scancode
654 * 655 *
655 * This function should be called by anyone needing to update current 656 * This function should be called by anyone needing to update current
656 * keymap. Presently keyboard and evdev handlers use it. 657 * keymap. Presently keyboard and evdev handlers use it.
657 */ 658 */
658 int input_set_keycode(struct input_dev *dev, int scancode, int keycode) 659 int input_set_keycode(struct input_dev *dev, int scancode, int keycode)
659 { 660 {
660 unsigned long flags; 661 unsigned long flags;
661 int old_keycode; 662 int old_keycode;
662 int retval; 663 int retval;
663 664
664 if (scancode < 0) 665 if (scancode < 0)
665 return -EINVAL; 666 return -EINVAL;
666 667
667 if (keycode < 0 || keycode > KEY_MAX) 668 if (keycode < 0 || keycode > KEY_MAX)
668 return -EINVAL; 669 return -EINVAL;
669 670
670 spin_lock_irqsave(&dev->event_lock, flags); 671 spin_lock_irqsave(&dev->event_lock, flags);
671 672
672 retval = dev->getkeycode(dev, scancode, &old_keycode); 673 retval = dev->getkeycode(dev, scancode, &old_keycode);
673 if (retval) 674 if (retval)
674 goto out; 675 goto out;
675 676
676 retval = dev->setkeycode(dev, scancode, keycode); 677 retval = dev->setkeycode(dev, scancode, keycode);
677 if (retval) 678 if (retval)
678 goto out; 679 goto out;
679 680
680 /* 681 /*
681 * Simulate keyup event if keycode is not present 682 * Simulate keyup event if keycode is not present
682 * in the keymap anymore 683 * in the keymap anymore
683 */ 684 */
684 if (test_bit(EV_KEY, dev->evbit) && 685 if (test_bit(EV_KEY, dev->evbit) &&
685 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && 686 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
686 __test_and_clear_bit(old_keycode, dev->key)) { 687 __test_and_clear_bit(old_keycode, dev->key)) {
687 688
688 input_pass_event(dev, EV_KEY, old_keycode, 0); 689 input_pass_event(dev, EV_KEY, old_keycode, 0);
689 if (dev->sync) 690 if (dev->sync)
690 input_pass_event(dev, EV_SYN, SYN_REPORT, 1); 691 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
691 } 692 }
692 693
693 out: 694 out:
694 spin_unlock_irqrestore(&dev->event_lock, flags); 695 spin_unlock_irqrestore(&dev->event_lock, flags);
695 696
696 return retval; 697 return retval;
697 } 698 }
698 EXPORT_SYMBOL(input_set_keycode); 699 EXPORT_SYMBOL(input_set_keycode);
699 700
700 #define MATCH_BIT(bit, max) \ 701 #define MATCH_BIT(bit, max) \
701 for (i = 0; i < BITS_TO_LONGS(max); i++) \ 702 for (i = 0; i < BITS_TO_LONGS(max); i++) \
702 if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \ 703 if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \
703 break; \ 704 break; \
704 if (i != BITS_TO_LONGS(max)) \ 705 if (i != BITS_TO_LONGS(max)) \
705 continue; 706 continue;
706 707
707 static const struct input_device_id *input_match_device(const struct input_device_id *id, 708 static const struct input_device_id *input_match_device(const struct input_device_id *id,
708 struct input_dev *dev) 709 struct input_dev *dev)
709 { 710 {
710 int i; 711 int i;
711 712
712 for (; id->flags || id->driver_info; id++) { 713 for (; id->flags || id->driver_info; id++) {
713 714
714 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) 715 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
715 if (id->bustype != dev->id.bustype) 716 if (id->bustype != dev->id.bustype)
716 continue; 717 continue;
717 718
718 if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR) 719 if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR)
719 if (id->vendor != dev->id.vendor) 720 if (id->vendor != dev->id.vendor)
720 continue; 721 continue;
721 722
722 if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT) 723 if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT)
723 if (id->product != dev->id.product) 724 if (id->product != dev->id.product)
724 continue; 725 continue;
725 726
726 if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION) 727 if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION)
727 if (id->version != dev->id.version) 728 if (id->version != dev->id.version)
728 continue; 729 continue;
729 730
730 MATCH_BIT(evbit, EV_MAX); 731 MATCH_BIT(evbit, EV_MAX);
731 MATCH_BIT(keybit, KEY_MAX); 732 MATCH_BIT(keybit, KEY_MAX);
732 MATCH_BIT(relbit, REL_MAX); 733 MATCH_BIT(relbit, REL_MAX);
733 MATCH_BIT(absbit, ABS_MAX); 734 MATCH_BIT(absbit, ABS_MAX);
734 MATCH_BIT(mscbit, MSC_MAX); 735 MATCH_BIT(mscbit, MSC_MAX);
735 MATCH_BIT(ledbit, LED_MAX); 736 MATCH_BIT(ledbit, LED_MAX);
736 MATCH_BIT(sndbit, SND_MAX); 737 MATCH_BIT(sndbit, SND_MAX);
737 MATCH_BIT(ffbit, FF_MAX); 738 MATCH_BIT(ffbit, FF_MAX);
738 MATCH_BIT(swbit, SW_MAX); 739 MATCH_BIT(swbit, SW_MAX);
739 740
740 return id; 741 return id;
741 } 742 }
742 743
743 return NULL; 744 return NULL;
744 } 745 }
745 746
746 static int input_attach_handler(struct input_dev *dev, struct input_handler *handler) 747 static int input_attach_handler(struct input_dev *dev, struct input_handler *handler)
747 { 748 {
748 const struct input_device_id *id; 749 const struct input_device_id *id;
749 int error; 750 int error;
750 751
751 if (handler->blacklist && input_match_device(handler->blacklist, dev)) 752 if (handler->blacklist && input_match_device(handler->blacklist, dev))
752 return -ENODEV; 753 return -ENODEV;
753 754
754 id = input_match_device(handler->id_table, dev); 755 id = input_match_device(handler->id_table, dev);
755 if (!id) 756 if (!id)
756 return -ENODEV; 757 return -ENODEV;
757 758
758 error = handler->connect(handler, dev, id); 759 error = handler->connect(handler, dev, id);
759 if (error && error != -ENODEV) 760 if (error && error != -ENODEV)
760 printk(KERN_ERR 761 printk(KERN_ERR
761 "input: failed to attach handler %s to device %s, " 762 "input: failed to attach handler %s to device %s, "
762 "error: %d\n", 763 "error: %d\n",
763 handler->name, kobject_name(&dev->dev.kobj), error); 764 handler->name, kobject_name(&dev->dev.kobj), error);
764 765
765 return error; 766 return error;
766 } 767 }
767 768
768 #ifdef CONFIG_COMPAT 769 #ifdef CONFIG_COMPAT
769 770
770 static int input_bits_to_string(char *buf, int buf_size, 771 static int input_bits_to_string(char *buf, int buf_size,
771 unsigned long bits, bool skip_empty) 772 unsigned long bits, bool skip_empty)
772 { 773 {
773 int len = 0; 774 int len = 0;
774 775
775 if (INPUT_COMPAT_TEST) { 776 if (INPUT_COMPAT_TEST) {
776 u32 dword = bits >> 32; 777 u32 dword = bits >> 32;
777 if (dword || !skip_empty) 778 if (dword || !skip_empty)
778 len += snprintf(buf, buf_size, "%x ", dword); 779 len += snprintf(buf, buf_size, "%x ", dword);
779 780
780 dword = bits & 0xffffffffUL; 781 dword = bits & 0xffffffffUL;
781 if (dword || !skip_empty || len) 782 if (dword || !skip_empty || len)
782 len += snprintf(buf + len, max(buf_size - len, 0), 783 len += snprintf(buf + len, max(buf_size - len, 0),
783 "%x", dword); 784 "%x", dword);
784 } else { 785 } else {
785 if (bits || !skip_empty) 786 if (bits || !skip_empty)
786 len += snprintf(buf, buf_size, "%lx", bits); 787 len += snprintf(buf, buf_size, "%lx", bits);
787 } 788 }
788 789
789 return len; 790 return len;
790 } 791 }
791 792
792 #else /* !CONFIG_COMPAT */ 793 #else /* !CONFIG_COMPAT */
793 794
794 static int input_bits_to_string(char *buf, int buf_size, 795 static int input_bits_to_string(char *buf, int buf_size,
795 unsigned long bits, bool skip_empty) 796 unsigned long bits, bool skip_empty)
796 { 797 {
797 return bits || !skip_empty ? 798 return bits || !skip_empty ?
798 snprintf(buf, buf_size, "%lx", bits) : 0; 799 snprintf(buf, buf_size, "%lx", bits) : 0;
799 } 800 }
800 801
801 #endif 802 #endif
802 803
803 #ifdef CONFIG_PROC_FS 804 #ifdef CONFIG_PROC_FS
804 805
805 static struct proc_dir_entry *proc_bus_input_dir; 806 static struct proc_dir_entry *proc_bus_input_dir;
806 static DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait); 807 static DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait);
807 static int input_devices_state; 808 static int input_devices_state;
808 809
809 static inline void input_wakeup_procfs_readers(void) 810 static inline void input_wakeup_procfs_readers(void)
810 { 811 {
811 input_devices_state++; 812 input_devices_state++;
812 wake_up(&input_devices_poll_wait); 813 wake_up(&input_devices_poll_wait);
813 } 814 }
814 815
815 static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait) 816 static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait)
816 { 817 {
817 poll_wait(file, &input_devices_poll_wait, wait); 818 poll_wait(file, &input_devices_poll_wait, wait);
818 if (file->f_version != input_devices_state) { 819 if (file->f_version != input_devices_state) {
819 file->f_version = input_devices_state; 820 file->f_version = input_devices_state;
820 return POLLIN | POLLRDNORM; 821 return POLLIN | POLLRDNORM;
821 } 822 }
822 823
823 return 0; 824 return 0;
824 } 825 }
825 826
826 union input_seq_state { 827 union input_seq_state {
827 struct { 828 struct {
828 unsigned short pos; 829 unsigned short pos;
829 bool mutex_acquired; 830 bool mutex_acquired;
830 }; 831 };
831 void *p; 832 void *p;
832 }; 833 };
833 834
834 static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos) 835 static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
835 { 836 {
836 union input_seq_state *state = (union input_seq_state *)&seq->private; 837 union input_seq_state *state = (union input_seq_state *)&seq->private;
837 int error; 838 int error;
838 839
839 /* We need to fit into seq->private pointer */ 840 /* We need to fit into seq->private pointer */
840 BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private)); 841 BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private));
841 842
842 error = mutex_lock_interruptible(&input_mutex); 843 error = mutex_lock_interruptible(&input_mutex);
843 if (error) { 844 if (error) {
844 state->mutex_acquired = false; 845 state->mutex_acquired = false;
845 return ERR_PTR(error); 846 return ERR_PTR(error);
846 } 847 }
847 848
848 state->mutex_acquired = true; 849 state->mutex_acquired = true;
849 850
850 return seq_list_start(&input_dev_list, *pos); 851 return seq_list_start(&input_dev_list, *pos);
851 } 852 }
852 853
853 static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos) 854 static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
854 { 855 {
855 return seq_list_next(v, &input_dev_list, pos); 856 return seq_list_next(v, &input_dev_list, pos);
856 } 857 }
857 858
858 static void input_seq_stop(struct seq_file *seq, void *v) 859 static void input_seq_stop(struct seq_file *seq, void *v)
859 { 860 {
860 union input_seq_state *state = (union input_seq_state *)&seq->private; 861 union input_seq_state *state = (union input_seq_state *)&seq->private;
861 862
862 if (state->mutex_acquired) 863 if (state->mutex_acquired)
863 mutex_unlock(&input_mutex); 864 mutex_unlock(&input_mutex);
864 } 865 }
865 866
866 static void input_seq_print_bitmap(struct seq_file *seq, const char *name, 867 static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
867 unsigned long *bitmap, int max) 868 unsigned long *bitmap, int max)
868 { 869 {
869 int i; 870 int i;
870 bool skip_empty = true; 871 bool skip_empty = true;
871 char buf[18]; 872 char buf[18];
872 873
873 seq_printf(seq, "B: %s=", name); 874 seq_printf(seq, "B: %s=", name);
874 875
875 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { 876 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
876 if (input_bits_to_string(buf, sizeof(buf), 877 if (input_bits_to_string(buf, sizeof(buf),
877 bitmap[i], skip_empty)) { 878 bitmap[i], skip_empty)) {
878 skip_empty = false; 879 skip_empty = false;
879 seq_printf(seq, "%s%s", buf, i > 0 ? " " : ""); 880 seq_printf(seq, "%s%s", buf, i > 0 ? " " : "");
880 } 881 }
881 } 882 }
882 883
883 /* 884 /*
884 * If no output was produced print a single 0. 885 * If no output was produced print a single 0.
885 */ 886 */
886 if (skip_empty) 887 if (skip_empty)
887 seq_puts(seq, "0"); 888 seq_puts(seq, "0");
888 889
889 seq_putc(seq, '\n'); 890 seq_putc(seq, '\n');
890 } 891 }
891 892
892 static int input_devices_seq_show(struct seq_file *seq, void *v) 893 static int input_devices_seq_show(struct seq_file *seq, void *v)
893 { 894 {
894 struct input_dev *dev = container_of(v, struct input_dev, node); 895 struct input_dev *dev = container_of(v, struct input_dev, node);
895 const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); 896 const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
896 struct input_handle *handle; 897 struct input_handle *handle;
897 898
898 seq_printf(seq, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n", 899 seq_printf(seq, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
899 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); 900 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
900 901
901 seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : ""); 902 seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
902 seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : ""); 903 seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : "");
903 seq_printf(seq, "S: Sysfs=%s\n", path ? path : ""); 904 seq_printf(seq, "S: Sysfs=%s\n", path ? path : "");
904 seq_printf(seq, "U: Uniq=%s\n", dev->uniq ? dev->uniq : ""); 905 seq_printf(seq, "U: Uniq=%s\n", dev->uniq ? dev->uniq : "");
905 seq_printf(seq, "H: Handlers="); 906 seq_printf(seq, "H: Handlers=");
906 907
907 list_for_each_entry(handle, &dev->h_list, d_node) 908 list_for_each_entry(handle, &dev->h_list, d_node)
908 seq_printf(seq, "%s ", handle->name); 909 seq_printf(seq, "%s ", handle->name);
909 seq_putc(seq, '\n'); 910 seq_putc(seq, '\n');
910 911
911 input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX); 912 input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX);
912 if (test_bit(EV_KEY, dev->evbit)) 913 if (test_bit(EV_KEY, dev->evbit))
913 input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX); 914 input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX);
914 if (test_bit(EV_REL, dev->evbit)) 915 if (test_bit(EV_REL, dev->evbit))
915 input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX); 916 input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX);
916 if (test_bit(EV_ABS, dev->evbit)) 917 if (test_bit(EV_ABS, dev->evbit))
917 input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX); 918 input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX);
918 if (test_bit(EV_MSC, dev->evbit)) 919 if (test_bit(EV_MSC, dev->evbit))
919 input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX); 920 input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX);
920 if (test_bit(EV_LED, dev->evbit)) 921 if (test_bit(EV_LED, dev->evbit))
921 input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX); 922 input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX);
922 if (test_bit(EV_SND, dev->evbit)) 923 if (test_bit(EV_SND, dev->evbit))
923 input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX); 924 input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX);
924 if (test_bit(EV_FF, dev->evbit)) 925 if (test_bit(EV_FF, dev->evbit))
925 input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX); 926 input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX);
926 if (test_bit(EV_SW, dev->evbit)) 927 if (test_bit(EV_SW, dev->evbit))
927 input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX); 928 input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX);
928 929
929 seq_putc(seq, '\n'); 930 seq_putc(seq, '\n');
930 931
931 kfree(path); 932 kfree(path);
932 return 0; 933 return 0;
933 } 934 }
934 935
935 static const struct seq_operations input_devices_seq_ops = { 936 static const struct seq_operations input_devices_seq_ops = {
936 .start = input_devices_seq_start, 937 .start = input_devices_seq_start,
937 .next = input_devices_seq_next, 938 .next = input_devices_seq_next,
938 .stop = input_seq_stop, 939 .stop = input_seq_stop,
939 .show = input_devices_seq_show, 940 .show = input_devices_seq_show,
940 }; 941 };
941 942
942 static int input_proc_devices_open(struct inode *inode, struct file *file) 943 static int input_proc_devices_open(struct inode *inode, struct file *file)
943 { 944 {
944 return seq_open(file, &input_devices_seq_ops); 945 return seq_open(file, &input_devices_seq_ops);
945 } 946 }
946 947
947 static const struct file_operations input_devices_fileops = { 948 static const struct file_operations input_devices_fileops = {
948 .owner = THIS_MODULE, 949 .owner = THIS_MODULE,
949 .open = input_proc_devices_open, 950 .open = input_proc_devices_open,
950 .poll = input_proc_devices_poll, 951 .poll = input_proc_devices_poll,
951 .read = seq_read, 952 .read = seq_read,
952 .llseek = seq_lseek, 953 .llseek = seq_lseek,
953 .release = seq_release, 954 .release = seq_release,
954 }; 955 };
955 956
956 static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos) 957 static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
957 { 958 {
958 union input_seq_state *state = (union input_seq_state *)&seq->private; 959 union input_seq_state *state = (union input_seq_state *)&seq->private;
959 int error; 960 int error;
960 961
961 /* We need to fit into seq->private pointer */ 962 /* We need to fit into seq->private pointer */
962 BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private)); 963 BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private));
963 964
964 error = mutex_lock_interruptible(&input_mutex); 965 error = mutex_lock_interruptible(&input_mutex);
965 if (error) { 966 if (error) {
966 state->mutex_acquired = false; 967 state->mutex_acquired = false;
967 return ERR_PTR(error); 968 return ERR_PTR(error);
968 } 969 }
969 970
970 state->mutex_acquired = true; 971 state->mutex_acquired = true;
971 state->pos = *pos; 972 state->pos = *pos;
972 973
973 return seq_list_start(&input_handler_list, *pos); 974 return seq_list_start(&input_handler_list, *pos);
974 } 975 }
975 976
976 static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos) 977 static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
977 { 978 {
978 union input_seq_state *state = (union input_seq_state *)&seq->private; 979 union input_seq_state *state = (union input_seq_state *)&seq->private;
979 980
980 state->pos = *pos + 1; 981 state->pos = *pos + 1;
981 return seq_list_next(v, &input_handler_list, pos); 982 return seq_list_next(v, &input_handler_list, pos);
982 } 983 }
983 984
984 static int input_handlers_seq_show(struct seq_file *seq, void *v) 985 static int input_handlers_seq_show(struct seq_file *seq, void *v)
985 { 986 {
986 struct input_handler *handler = container_of(v, struct input_handler, node); 987 struct input_handler *handler = container_of(v, struct input_handler, node);
987 union input_seq_state *state = (union input_seq_state *)&seq->private; 988 union input_seq_state *state = (union input_seq_state *)&seq->private;
988 989
989 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); 990 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name);
990 if (handler->fops) 991 if (handler->fops)
991 seq_printf(seq, " Minor=%d", handler->minor); 992 seq_printf(seq, " Minor=%d", handler->minor);
992 seq_putc(seq, '\n'); 993 seq_putc(seq, '\n');
993 994
994 return 0; 995 return 0;
995 } 996 }
996 997
997 static const struct seq_operations input_handlers_seq_ops = { 998 static const struct seq_operations input_handlers_seq_ops = {
998 .start = input_handlers_seq_start, 999 .start = input_handlers_seq_start,
999 .next = input_handlers_seq_next, 1000 .next = input_handlers_seq_next,
1000 .stop = input_seq_stop, 1001 .stop = input_seq_stop,
1001 .show = input_handlers_seq_show, 1002 .show = input_handlers_seq_show,
1002 }; 1003 };
1003 1004
1004 static int input_proc_handlers_open(struct inode *inode, struct file *file) 1005 static int input_proc_handlers_open(struct inode *inode, struct file *file)
1005 { 1006 {
1006 return seq_open(file, &input_handlers_seq_ops); 1007 return seq_open(file, &input_handlers_seq_ops);
1007 } 1008 }
1008 1009
1009 static const struct file_operations input_handlers_fileops = { 1010 static const struct file_operations input_handlers_fileops = {
1010 .owner = THIS_MODULE, 1011 .owner = THIS_MODULE,
1011 .open = input_proc_handlers_open, 1012 .open = input_proc_handlers_open,
1012 .read = seq_read, 1013 .read = seq_read,
1013 .llseek = seq_lseek, 1014 .llseek = seq_lseek,
1014 .release = seq_release, 1015 .release = seq_release,
1015 }; 1016 };
1016 1017
1017 static int __init input_proc_init(void) 1018 static int __init input_proc_init(void)
1018 { 1019 {
1019 struct proc_dir_entry *entry; 1020 struct proc_dir_entry *entry;
1020 1021
1021 proc_bus_input_dir = proc_mkdir("bus/input", NULL); 1022 proc_bus_input_dir = proc_mkdir("bus/input", NULL);
1022 if (!proc_bus_input_dir) 1023 if (!proc_bus_input_dir)
1023 return -ENOMEM; 1024 return -ENOMEM;
1024 1025
1025 entry = proc_create("devices", 0, proc_bus_input_dir, 1026 entry = proc_create("devices", 0, proc_bus_input_dir,
1026 &input_devices_fileops); 1027 &input_devices_fileops);
1027 if (!entry) 1028 if (!entry)
1028 goto fail1; 1029 goto fail1;
1029 1030
1030 entry = proc_create("handlers", 0, proc_bus_input_dir, 1031 entry = proc_create("handlers", 0, proc_bus_input_dir,
1031 &input_handlers_fileops); 1032 &input_handlers_fileops);
1032 if (!entry) 1033 if (!entry)
1033 goto fail2; 1034 goto fail2;
1034 1035
1035 return 0; 1036 return 0;
1036 1037
1037 fail2: remove_proc_entry("devices", proc_bus_input_dir); 1038 fail2: remove_proc_entry("devices", proc_bus_input_dir);
1038 fail1: remove_proc_entry("bus/input", NULL); 1039 fail1: remove_proc_entry("bus/input", NULL);
1039 return -ENOMEM; 1040 return -ENOMEM;
1040 } 1041 }
1041 1042
1042 static void input_proc_exit(void) 1043 static void input_proc_exit(void)
1043 { 1044 {
1044 remove_proc_entry("devices", proc_bus_input_dir); 1045 remove_proc_entry("devices", proc_bus_input_dir);
1045 remove_proc_entry("handlers", proc_bus_input_dir); 1046 remove_proc_entry("handlers", proc_bus_input_dir);
1046 remove_proc_entry("bus/input", NULL); 1047 remove_proc_entry("bus/input", NULL);
1047 } 1048 }
1048 1049
1049 #else /* !CONFIG_PROC_FS */ 1050 #else /* !CONFIG_PROC_FS */
1050 static inline void input_wakeup_procfs_readers(void) { } 1051 static inline void input_wakeup_procfs_readers(void) { }
1051 static inline int input_proc_init(void) { return 0; } 1052 static inline int input_proc_init(void) { return 0; }
1052 static inline void input_proc_exit(void) { } 1053 static inline void input_proc_exit(void) { }
1053 #endif 1054 #endif
1054 1055
1055 #define INPUT_DEV_STRING_ATTR_SHOW(name) \ 1056 #define INPUT_DEV_STRING_ATTR_SHOW(name) \
1056 static ssize_t input_dev_show_##name(struct device *dev, \ 1057 static ssize_t input_dev_show_##name(struct device *dev, \
1057 struct device_attribute *attr, \ 1058 struct device_attribute *attr, \
1058 char *buf) \ 1059 char *buf) \
1059 { \ 1060 { \
1060 struct input_dev *input_dev = to_input_dev(dev); \ 1061 struct input_dev *input_dev = to_input_dev(dev); \
1061 \ 1062 \
1062 return scnprintf(buf, PAGE_SIZE, "%s\n", \ 1063 return scnprintf(buf, PAGE_SIZE, "%s\n", \
1063 input_dev->name ? input_dev->name : ""); \ 1064 input_dev->name ? input_dev->name : ""); \
1064 } \ 1065 } \
1065 static DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL) 1066 static DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL)
1066 1067
1067 INPUT_DEV_STRING_ATTR_SHOW(name); 1068 INPUT_DEV_STRING_ATTR_SHOW(name);
1068 INPUT_DEV_STRING_ATTR_SHOW(phys); 1069 INPUT_DEV_STRING_ATTR_SHOW(phys);
1069 INPUT_DEV_STRING_ATTR_SHOW(uniq); 1070 INPUT_DEV_STRING_ATTR_SHOW(uniq);
1070 1071
1071 static int input_print_modalias_bits(char *buf, int size, 1072 static int input_print_modalias_bits(char *buf, int size,
1072 char name, unsigned long *bm, 1073 char name, unsigned long *bm,
1073 unsigned int min_bit, unsigned int max_bit) 1074 unsigned int min_bit, unsigned int max_bit)
1074 { 1075 {
1075 int len = 0, i; 1076 int len = 0, i;
1076 1077
1077 len += snprintf(buf, max(size, 0), "%c", name); 1078 len += snprintf(buf, max(size, 0), "%c", name);
1078 for (i = min_bit; i < max_bit; i++) 1079 for (i = min_bit; i < max_bit; i++)
1079 if (bm[BIT_WORD(i)] & BIT_MASK(i)) 1080 if (bm[BIT_WORD(i)] & BIT_MASK(i))
1080 len += snprintf(buf + len, max(size - len, 0), "%X,", i); 1081 len += snprintf(buf + len, max(size - len, 0), "%X,", i);
1081 return len; 1082 return len;
1082 } 1083 }
1083 1084
1084 static int input_print_modalias(char *buf, int size, struct input_dev *id, 1085 static int input_print_modalias(char *buf, int size, struct input_dev *id,
1085 int add_cr) 1086 int add_cr)
1086 { 1087 {
1087 int len; 1088 int len;
1088 1089
1089 len = snprintf(buf, max(size, 0), 1090 len = snprintf(buf, max(size, 0),
1090 "input:b%04Xv%04Xp%04Xe%04X-", 1091 "input:b%04Xv%04Xp%04Xe%04X-",
1091 id->id.bustype, id->id.vendor, 1092 id->id.bustype, id->id.vendor,
1092 id->id.product, id->id.version); 1093 id->id.product, id->id.version);
1093 1094
1094 len += input_print_modalias_bits(buf + len, size - len, 1095 len += input_print_modalias_bits(buf + len, size - len,
1095 'e', id->evbit, 0, EV_MAX); 1096 'e', id->evbit, 0, EV_MAX);
1096 len += input_print_modalias_bits(buf + len, size - len, 1097 len += input_print_modalias_bits(buf + len, size - len,
1097 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX); 1098 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX);
1098 len += input_print_modalias_bits(buf + len, size - len, 1099 len += input_print_modalias_bits(buf + len, size - len,
1099 'r', id->relbit, 0, REL_MAX); 1100 'r', id->relbit, 0, REL_MAX);
1100 len += input_print_modalias_bits(buf + len, size - len, 1101 len += input_print_modalias_bits(buf + len, size - len,
1101 'a', id->absbit, 0, ABS_MAX); 1102 'a', id->absbit, 0, ABS_MAX);
1102 len += input_print_modalias_bits(buf + len, size - len, 1103 len += input_print_modalias_bits(buf + len, size - len,
1103 'm', id->mscbit, 0, MSC_MAX); 1104 'm', id->mscbit, 0, MSC_MAX);
1104 len += input_print_modalias_bits(buf + len, size - len, 1105 len += input_print_modalias_bits(buf + len, size - len,
1105 'l', id->ledbit, 0, LED_MAX); 1106 'l', id->ledbit, 0, LED_MAX);
1106 len += input_print_modalias_bits(buf + len, size - len, 1107 len += input_print_modalias_bits(buf + len, size - len,
1107 's', id->sndbit, 0, SND_MAX); 1108 's', id->sndbit, 0, SND_MAX);
1108 len += input_print_modalias_bits(buf + len, size - len, 1109 len += input_print_modalias_bits(buf + len, size - len,
1109 'f', id->ffbit, 0, FF_MAX); 1110 'f', id->ffbit, 0, FF_MAX);
1110 len += input_print_modalias_bits(buf + len, size - len, 1111 len += input_print_modalias_bits(buf + len, size - len,
1111 'w', id->swbit, 0, SW_MAX); 1112 'w', id->swbit, 0, SW_MAX);
1112 1113
1113 if (add_cr) 1114 if (add_cr)
1114 len += snprintf(buf + len, max(size - len, 0), "\n"); 1115 len += snprintf(buf + len, max(size - len, 0), "\n");
1115 1116
1116 return len; 1117 return len;
1117 } 1118 }
1118 1119
1119 static ssize_t input_dev_show_modalias(struct device *dev, 1120 static ssize_t input_dev_show_modalias(struct device *dev,
1120 struct device_attribute *attr, 1121 struct device_attribute *attr,
1121 char *buf) 1122 char *buf)
1122 { 1123 {
1123 struct input_dev *id = to_input_dev(dev); 1124 struct input_dev *id = to_input_dev(dev);
1124 ssize_t len; 1125 ssize_t len;
1125 1126
1126 len = input_print_modalias(buf, PAGE_SIZE, id, 1); 1127 len = input_print_modalias(buf, PAGE_SIZE, id, 1);
1127 1128
1128 return min_t(int, len, PAGE_SIZE); 1129 return min_t(int, len, PAGE_SIZE);
1129 } 1130 }
1130 static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL); 1131 static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
1131 1132
1132 static struct attribute *input_dev_attrs[] = { 1133 static struct attribute *input_dev_attrs[] = {
1133 &dev_attr_name.attr, 1134 &dev_attr_name.attr,
1134 &dev_attr_phys.attr, 1135 &dev_attr_phys.attr,
1135 &dev_attr_uniq.attr, 1136 &dev_attr_uniq.attr,
1136 &dev_attr_modalias.attr, 1137 &dev_attr_modalias.attr,
1137 NULL 1138 NULL
1138 }; 1139 };
1139 1140
1140 static struct attribute_group input_dev_attr_group = { 1141 static struct attribute_group input_dev_attr_group = {
1141 .attrs = input_dev_attrs, 1142 .attrs = input_dev_attrs,
1142 }; 1143 };
1143 1144
1144 #define INPUT_DEV_ID_ATTR(name) \ 1145 #define INPUT_DEV_ID_ATTR(name) \
1145 static ssize_t input_dev_show_id_##name(struct device *dev, \ 1146 static ssize_t input_dev_show_id_##name(struct device *dev, \
1146 struct device_attribute *attr, \ 1147 struct device_attribute *attr, \
1147 char *buf) \ 1148 char *buf) \
1148 { \ 1149 { \
1149 struct input_dev *input_dev = to_input_dev(dev); \ 1150 struct input_dev *input_dev = to_input_dev(dev); \
1150 return scnprintf(buf, PAGE_SIZE, "%04x\n", input_dev->id.name); \ 1151 return scnprintf(buf, PAGE_SIZE, "%04x\n", input_dev->id.name); \
1151 } \ 1152 } \
1152 static DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL) 1153 static DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL)
1153 1154
1154 INPUT_DEV_ID_ATTR(bustype); 1155 INPUT_DEV_ID_ATTR(bustype);
1155 INPUT_DEV_ID_ATTR(vendor); 1156 INPUT_DEV_ID_ATTR(vendor);
1156 INPUT_DEV_ID_ATTR(product); 1157 INPUT_DEV_ID_ATTR(product);
1157 INPUT_DEV_ID_ATTR(version); 1158 INPUT_DEV_ID_ATTR(version);
1158 1159
1159 static struct attribute *input_dev_id_attrs[] = { 1160 static struct attribute *input_dev_id_attrs[] = {
1160 &dev_attr_bustype.attr, 1161 &dev_attr_bustype.attr,
1161 &dev_attr_vendor.attr, 1162 &dev_attr_vendor.attr,
1162 &dev_attr_product.attr, 1163 &dev_attr_product.attr,
1163 &dev_attr_version.attr, 1164 &dev_attr_version.attr,
1164 NULL 1165 NULL
1165 }; 1166 };
1166 1167
1167 static struct attribute_group input_dev_id_attr_group = { 1168 static struct attribute_group input_dev_id_attr_group = {
1168 .name = "id", 1169 .name = "id",
1169 .attrs = input_dev_id_attrs, 1170 .attrs = input_dev_id_attrs,
1170 }; 1171 };
1171 1172
1172 static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap, 1173 static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
1173 int max, int add_cr) 1174 int max, int add_cr)
1174 { 1175 {
1175 int i; 1176 int i;
1176 int len = 0; 1177 int len = 0;
1177 bool skip_empty = true; 1178 bool skip_empty = true;
1178 1179
1179 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) { 1180 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
1180 len += input_bits_to_string(buf + len, max(buf_size - len, 0), 1181 len += input_bits_to_string(buf + len, max(buf_size - len, 0),
1181 bitmap[i], skip_empty); 1182 bitmap[i], skip_empty);
1182 if (len) { 1183 if (len) {
1183 skip_empty = false; 1184 skip_empty = false;
1184 if (i > 0) 1185 if (i > 0)
1185 len += snprintf(buf + len, max(buf_size - len, 0), " "); 1186 len += snprintf(buf + len, max(buf_size - len, 0), " ");
1186 } 1187 }
1187 } 1188 }
1188 1189
1189 /* 1190 /*
1190 * If no output was produced print a single 0. 1191 * If no output was produced print a single 0.
1191 */ 1192 */
1192 if (len == 0) 1193 if (len == 0)
1193 len = snprintf(buf, buf_size, "%d", 0); 1194 len = snprintf(buf, buf_size, "%d", 0);
1194 1195
1195 if (add_cr) 1196 if (add_cr)
1196 len += snprintf(buf + len, max(buf_size - len, 0), "\n"); 1197 len += snprintf(buf + len, max(buf_size - len, 0), "\n");
1197 1198
1198 return len; 1199 return len;
1199 } 1200 }
1200 1201
1201 #define INPUT_DEV_CAP_ATTR(ev, bm) \ 1202 #define INPUT_DEV_CAP_ATTR(ev, bm) \
1202 static ssize_t input_dev_show_cap_##bm(struct device *dev, \ 1203 static ssize_t input_dev_show_cap_##bm(struct device *dev, \
1203 struct device_attribute *attr, \ 1204 struct device_attribute *attr, \
1204 char *buf) \ 1205 char *buf) \
1205 { \ 1206 { \
1206 struct input_dev *input_dev = to_input_dev(dev); \ 1207 struct input_dev *input_dev = to_input_dev(dev); \
1207 int len = input_print_bitmap(buf, PAGE_SIZE, \ 1208 int len = input_print_bitmap(buf, PAGE_SIZE, \
1208 input_dev->bm##bit, ev##_MAX, \ 1209 input_dev->bm##bit, ev##_MAX, \
1209 true); \ 1210 true); \
1210 return min_t(int, len, PAGE_SIZE); \ 1211 return min_t(int, len, PAGE_SIZE); \
1211 } \ 1212 } \
1212 static DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL) 1213 static DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL)
1213 1214
1214 INPUT_DEV_CAP_ATTR(EV, ev); 1215 INPUT_DEV_CAP_ATTR(EV, ev);
1215 INPUT_DEV_CAP_ATTR(KEY, key); 1216 INPUT_DEV_CAP_ATTR(KEY, key);
1216 INPUT_DEV_CAP_ATTR(REL, rel); 1217 INPUT_DEV_CAP_ATTR(REL, rel);
1217 INPUT_DEV_CAP_ATTR(ABS, abs); 1218 INPUT_DEV_CAP_ATTR(ABS, abs);
1218 INPUT_DEV_CAP_ATTR(MSC, msc); 1219 INPUT_DEV_CAP_ATTR(MSC, msc);
1219 INPUT_DEV_CAP_ATTR(LED, led); 1220 INPUT_DEV_CAP_ATTR(LED, led);
1220 INPUT_DEV_CAP_ATTR(SND, snd); 1221 INPUT_DEV_CAP_ATTR(SND, snd);
1221 INPUT_DEV_CAP_ATTR(FF, ff); 1222 INPUT_DEV_CAP_ATTR(FF, ff);
1222 INPUT_DEV_CAP_ATTR(SW, sw); 1223 INPUT_DEV_CAP_ATTR(SW, sw);
1223 1224
1224 static struct attribute *input_dev_caps_attrs[] = { 1225 static struct attribute *input_dev_caps_attrs[] = {
1225 &dev_attr_ev.attr, 1226 &dev_attr_ev.attr,
1226 &dev_attr_key.attr, 1227 &dev_attr_key.attr,
1227 &dev_attr_rel.attr, 1228 &dev_attr_rel.attr,
1228 &dev_attr_abs.attr, 1229 &dev_attr_abs.attr,
1229 &dev_attr_msc.attr, 1230 &dev_attr_msc.attr,
1230 &dev_attr_led.attr, 1231 &dev_attr_led.attr,
1231 &dev_attr_snd.attr, 1232 &dev_attr_snd.attr,
1232 &dev_attr_ff.attr, 1233 &dev_attr_ff.attr,
1233 &dev_attr_sw.attr, 1234 &dev_attr_sw.attr,
1234 NULL 1235 NULL
1235 }; 1236 };
1236 1237
1237 static struct attribute_group input_dev_caps_attr_group = { 1238 static struct attribute_group input_dev_caps_attr_group = {
1238 .name = "capabilities", 1239 .name = "capabilities",
1239 .attrs = input_dev_caps_attrs, 1240 .attrs = input_dev_caps_attrs,
1240 }; 1241 };
1241 1242
1242 static const struct attribute_group *input_dev_attr_groups[] = { 1243 static const struct attribute_group *input_dev_attr_groups[] = {
1243 &input_dev_attr_group, 1244 &input_dev_attr_group,
1244 &input_dev_id_attr_group, 1245 &input_dev_id_attr_group,
1245 &input_dev_caps_attr_group, 1246 &input_dev_caps_attr_group,
1246 NULL 1247 NULL
1247 }; 1248 };
1248 1249
1249 static void input_dev_release(struct device *device) 1250 static void input_dev_release(struct device *device)
1250 { 1251 {
1251 struct input_dev *dev = to_input_dev(device); 1252 struct input_dev *dev = to_input_dev(device);
1252 1253
1253 input_ff_destroy(dev); 1254 input_ff_destroy(dev);
1254 kfree(dev); 1255 kfree(dev);
1255 1256
1256 module_put(THIS_MODULE); 1257 module_put(THIS_MODULE);
1257 } 1258 }
1258 1259
1259 /* 1260 /*
1260 * Input uevent interface - loading event handlers based on 1261 * Input uevent interface - loading event handlers based on
1261 * device bitfields. 1262 * device bitfields.
1262 */ 1263 */
1263 static int input_add_uevent_bm_var(struct kobj_uevent_env *env, 1264 static int input_add_uevent_bm_var(struct kobj_uevent_env *env,
1264 const char *name, unsigned long *bitmap, int max) 1265 const char *name, unsigned long *bitmap, int max)
1265 { 1266 {
1266 int len; 1267 int len;
1267 1268
1268 if (add_uevent_var(env, "%s=", name)) 1269 if (add_uevent_var(env, "%s=", name))
1269 return -ENOMEM; 1270 return -ENOMEM;
1270 1271
1271 len = input_print_bitmap(&env->buf[env->buflen - 1], 1272 len = input_print_bitmap(&env->buf[env->buflen - 1],
1272 sizeof(env->buf) - env->buflen, 1273 sizeof(env->buf) - env->buflen,
1273 bitmap, max, false); 1274 bitmap, max, false);
1274 if (len >= (sizeof(env->buf) - env->buflen)) 1275 if (len >= (sizeof(env->buf) - env->buflen))
1275 return -ENOMEM; 1276 return -ENOMEM;
1276 1277
1277 env->buflen += len; 1278 env->buflen += len;
1278 return 0; 1279 return 0;
1279 } 1280 }
1280 1281
1281 static int input_add_uevent_modalias_var(struct kobj_uevent_env *env, 1282 static int input_add_uevent_modalias_var(struct kobj_uevent_env *env,
1282 struct input_dev *dev) 1283 struct input_dev *dev)
1283 { 1284 {
1284 int len; 1285 int len;
1285 1286
1286 if (add_uevent_var(env, "MODALIAS=")) 1287 if (add_uevent_var(env, "MODALIAS="))
1287 return -ENOMEM; 1288 return -ENOMEM;
1288 1289
1289 len = input_print_modalias(&env->buf[env->buflen - 1], 1290 len = input_print_modalias(&env->buf[env->buflen - 1],
1290 sizeof(env->buf) - env->buflen, 1291 sizeof(env->buf) - env->buflen,
1291 dev, 0); 1292 dev, 0);
1292 if (len >= (sizeof(env->buf) - env->buflen)) 1293 if (len >= (sizeof(env->buf) - env->buflen))
1293 return -ENOMEM; 1294 return -ENOMEM;
1294 1295
1295 env->buflen += len; 1296 env->buflen += len;
1296 return 0; 1297 return 0;
1297 } 1298 }
1298 1299
1299 #define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \ 1300 #define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \
1300 do { \ 1301 do { \
1301 int err = add_uevent_var(env, fmt, val); \ 1302 int err = add_uevent_var(env, fmt, val); \
1302 if (err) \ 1303 if (err) \
1303 return err; \ 1304 return err; \
1304 } while (0) 1305 } while (0)
1305 1306
1306 #define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max) \ 1307 #define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max) \
1307 do { \ 1308 do { \
1308 int err = input_add_uevent_bm_var(env, name, bm, max); \ 1309 int err = input_add_uevent_bm_var(env, name, bm, max); \
1309 if (err) \ 1310 if (err) \
1310 return err; \ 1311 return err; \
1311 } while (0) 1312 } while (0)
1312 1313
1313 #define INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev) \ 1314 #define INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev) \
1314 do { \ 1315 do { \
1315 int err = input_add_uevent_modalias_var(env, dev); \ 1316 int err = input_add_uevent_modalias_var(env, dev); \
1316 if (err) \ 1317 if (err) \
1317 return err; \ 1318 return err; \
1318 } while (0) 1319 } while (0)
1319 1320
1320 static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env) 1321 static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env)
1321 { 1322 {
1322 struct input_dev *dev = to_input_dev(device); 1323 struct input_dev *dev = to_input_dev(device);
1323 1324
1324 INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x", 1325 INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x",
1325 dev->id.bustype, dev->id.vendor, 1326 dev->id.bustype, dev->id.vendor,
1326 dev->id.product, dev->id.version); 1327 dev->id.product, dev->id.version);
1327 if (dev->name) 1328 if (dev->name)
1328 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name); 1329 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name);
1329 if (dev->phys) 1330 if (dev->phys)
1330 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys); 1331 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys);
1331 if (dev->uniq) 1332 if (dev->uniq)
1332 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq); 1333 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq);
1333 1334
1334 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX); 1335 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX);
1335 if (test_bit(EV_KEY, dev->evbit)) 1336 if (test_bit(EV_KEY, dev->evbit))
1336 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX); 1337 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX);
1337 if (test_bit(EV_REL, dev->evbit)) 1338 if (test_bit(EV_REL, dev->evbit))
1338 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX); 1339 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX);
1339 if (test_bit(EV_ABS, dev->evbit)) 1340 if (test_bit(EV_ABS, dev->evbit))
1340 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX); 1341 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX);
1341 if (test_bit(EV_MSC, dev->evbit)) 1342 if (test_bit(EV_MSC, dev->evbit))
1342 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX); 1343 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX);
1343 if (test_bit(EV_LED, dev->evbit)) 1344 if (test_bit(EV_LED, dev->evbit))
1344 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX); 1345 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX);
1345 if (test_bit(EV_SND, dev->evbit)) 1346 if (test_bit(EV_SND, dev->evbit))
1346 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX); 1347 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX);
1347 if (test_bit(EV_FF, dev->evbit)) 1348 if (test_bit(EV_FF, dev->evbit))
1348 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX); 1349 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX);
1349 if (test_bit(EV_SW, dev->evbit)) 1350 if (test_bit(EV_SW, dev->evbit))
1350 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX); 1351 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX);
1351 1352
1352 INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev); 1353 INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev);
1353 1354
1354 return 0; 1355 return 0;
1355 } 1356 }
1356 1357
1357 #define INPUT_DO_TOGGLE(dev, type, bits, on) \ 1358 #define INPUT_DO_TOGGLE(dev, type, bits, on) \
1358 do { \ 1359 do { \
1359 int i; \ 1360 int i; \
1360 bool active; \ 1361 bool active; \
1361 \ 1362 \
1362 if (!test_bit(EV_##type, dev->evbit)) \ 1363 if (!test_bit(EV_##type, dev->evbit)) \
1363 break; \ 1364 break; \
1364 \ 1365 \
1365 for (i = 0; i < type##_MAX; i++) { \ 1366 for (i = 0; i < type##_MAX; i++) { \
1366 if (!test_bit(i, dev->bits##bit)) \ 1367 if (!test_bit(i, dev->bits##bit)) \
1367 continue; \ 1368 continue; \
1368 \ 1369 \
1369 active = test_bit(i, dev->bits); \ 1370 active = test_bit(i, dev->bits); \
1370 if (!active && !on) \ 1371 if (!active && !on) \
1371 continue; \ 1372 continue; \
1372 \ 1373 \
1373 dev->event(dev, EV_##type, i, on ? active : 0); \ 1374 dev->event(dev, EV_##type, i, on ? active : 0); \
1374 } \ 1375 } \
1375 } while (0) 1376 } while (0)
1376 1377
1377 #ifdef CONFIG_PM 1378 #ifdef CONFIG_PM
1378 static void input_dev_reset(struct input_dev *dev, bool activate) 1379 static void input_dev_reset(struct input_dev *dev, bool activate)
1379 { 1380 {
1380 if (!dev->event) 1381 if (!dev->event)
1381 return; 1382 return;
1382 1383
1383 INPUT_DO_TOGGLE(dev, LED, led, activate); 1384 INPUT_DO_TOGGLE(dev, LED, led, activate);
1384 INPUT_DO_TOGGLE(dev, SND, snd, activate); 1385 INPUT_DO_TOGGLE(dev, SND, snd, activate);
1385 1386
1386 if (activate && test_bit(EV_REP, dev->evbit)) { 1387 if (activate && test_bit(EV_REP, dev->evbit)) {
1387 dev->event(dev, EV_REP, REP_PERIOD, dev->rep[REP_PERIOD]); 1388 dev->event(dev, EV_REP, REP_PERIOD, dev->rep[REP_PERIOD]);
1388 dev->event(dev, EV_REP, REP_DELAY, dev->rep[REP_DELAY]); 1389 dev->event(dev, EV_REP, REP_DELAY, dev->rep[REP_DELAY]);
1389 } 1390 }
1390 } 1391 }
1391 1392
1392 static int input_dev_suspend(struct device *dev) 1393 static int input_dev_suspend(struct device *dev)
1393 { 1394 {
1394 struct input_dev *input_dev = to_input_dev(dev); 1395 struct input_dev *input_dev = to_input_dev(dev);
1395 1396
1396 mutex_lock(&input_dev->mutex); 1397 mutex_lock(&input_dev->mutex);
1397 input_dev_reset(input_dev, false); 1398 input_dev_reset(input_dev, false);
1398 mutex_unlock(&input_dev->mutex); 1399 mutex_unlock(&input_dev->mutex);
1399 1400
1400 return 0; 1401 return 0;
1401 } 1402 }
1402 1403
1403 static int input_dev_resume(struct device *dev) 1404 static int input_dev_resume(struct device *dev)
1404 { 1405 {
1405 struct input_dev *input_dev = to_input_dev(dev); 1406 struct input_dev *input_dev = to_input_dev(dev);
1406 1407
1407 mutex_lock(&input_dev->mutex); 1408 mutex_lock(&input_dev->mutex);
1408 input_dev_reset(input_dev, true); 1409 input_dev_reset(input_dev, true);
1409 mutex_unlock(&input_dev->mutex); 1410 mutex_unlock(&input_dev->mutex);
1410 1411
1411 return 0; 1412 return 0;
1412 } 1413 }
1413 1414
1414 static const struct dev_pm_ops input_dev_pm_ops = { 1415 static const struct dev_pm_ops input_dev_pm_ops = {
1415 .suspend = input_dev_suspend, 1416 .suspend = input_dev_suspend,
1416 .resume = input_dev_resume, 1417 .resume = input_dev_resume,
1417 .poweroff = input_dev_suspend, 1418 .poweroff = input_dev_suspend,
1418 .restore = input_dev_resume, 1419 .restore = input_dev_resume,
1419 }; 1420 };
1420 #endif /* CONFIG_PM */ 1421 #endif /* CONFIG_PM */
1421 1422
1422 static struct device_type input_dev_type = { 1423 static struct device_type input_dev_type = {
1423 .groups = input_dev_attr_groups, 1424 .groups = input_dev_attr_groups,
1424 .release = input_dev_release, 1425 .release = input_dev_release,
1425 .uevent = input_dev_uevent, 1426 .uevent = input_dev_uevent,
1426 #ifdef CONFIG_PM 1427 #ifdef CONFIG_PM
1427 .pm = &input_dev_pm_ops, 1428 .pm = &input_dev_pm_ops,
1428 #endif 1429 #endif
1429 }; 1430 };
1430 1431
1431 static char *input_devnode(struct device *dev, mode_t *mode) 1432 static char *input_devnode(struct device *dev, mode_t *mode)
1432 { 1433 {
1433 return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev)); 1434 return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev));
1434 } 1435 }
1435 1436
1436 struct class input_class = { 1437 struct class input_class = {
1437 .name = "input", 1438 .name = "input",
1438 .devnode = input_devnode, 1439 .devnode = input_devnode,
1439 }; 1440 };
1440 EXPORT_SYMBOL_GPL(input_class); 1441 EXPORT_SYMBOL_GPL(input_class);
1441 1442
1442 /** 1443 /**
1443 * input_allocate_device - allocate memory for new input device 1444 * input_allocate_device - allocate memory for new input device
1444 * 1445 *
1445 * Returns prepared struct input_dev or NULL. 1446 * Returns prepared struct input_dev or NULL.
1446 * 1447 *
1447 * NOTE: Use input_free_device() to free devices that have not been 1448 * NOTE: Use input_free_device() to free devices that have not been
1448 * registered; input_unregister_device() should be used for already 1449 * registered; input_unregister_device() should be used for already
1449 * registered devices. 1450 * registered devices.
1450 */ 1451 */
1451 struct input_dev *input_allocate_device(void) 1452 struct input_dev *input_allocate_device(void)
1452 { 1453 {
1453 struct input_dev *dev; 1454 struct input_dev *dev;
1454 1455
1455 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL); 1456 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
1456 if (dev) { 1457 if (dev) {
1457 dev->dev.type = &input_dev_type; 1458 dev->dev.type = &input_dev_type;
1458 dev->dev.class = &input_class; 1459 dev->dev.class = &input_class;
1459 device_initialize(&dev->dev); 1460 device_initialize(&dev->dev);
1460 mutex_init(&dev->mutex); 1461 mutex_init(&dev->mutex);
1461 spin_lock_init(&dev->event_lock); 1462 spin_lock_init(&dev->event_lock);
1462 INIT_LIST_HEAD(&dev->h_list); 1463 INIT_LIST_HEAD(&dev->h_list);
1463 INIT_LIST_HEAD(&dev->node); 1464 INIT_LIST_HEAD(&dev->node);
1464 1465
1465 __module_get(THIS_MODULE); 1466 __module_get(THIS_MODULE);
1466 } 1467 }
1467 1468
1468 return dev; 1469 return dev;
1469 } 1470 }
1470 EXPORT_SYMBOL(input_allocate_device); 1471 EXPORT_SYMBOL(input_allocate_device);
1471 1472
1472 /** 1473 /**
1473 * input_free_device - free memory occupied by input_dev structure 1474 * input_free_device - free memory occupied by input_dev structure
1474 * @dev: input device to free 1475 * @dev: input device to free
1475 * 1476 *
1476 * This function should only be used if input_register_device() 1477 * This function should only be used if input_register_device()
1477 * was not called yet or if it failed. Once device was registered 1478 * was not called yet or if it failed. Once device was registered
1478 * use input_unregister_device() and memory will be freed once last 1479 * use input_unregister_device() and memory will be freed once last
1479 * reference to the device is dropped. 1480 * reference to the device is dropped.
1480 * 1481 *
1481 * Device should be allocated by input_allocate_device(). 1482 * Device should be allocated by input_allocate_device().
1482 * 1483 *
1483 * NOTE: If there are references to the input device then memory 1484 * NOTE: If there are references to the input device then memory
1484 * will not be freed until last reference is dropped. 1485 * will not be freed until last reference is dropped.
1485 */ 1486 */
1486 void input_free_device(struct input_dev *dev) 1487 void input_free_device(struct input_dev *dev)
1487 { 1488 {
1488 if (dev) 1489 if (dev)
1489 input_put_device(dev); 1490 input_put_device(dev);
1490 } 1491 }
1491 EXPORT_SYMBOL(input_free_device); 1492 EXPORT_SYMBOL(input_free_device);
1492 1493
1493 /** 1494 /**
1494 * input_set_capability - mark device as capable of a certain event 1495 * input_set_capability - mark device as capable of a certain event
1495 * @dev: device that is capable of emitting or accepting event 1496 * @dev: device that is capable of emitting or accepting event
1496 * @type: type of the event (EV_KEY, EV_REL, etc...) 1497 * @type: type of the event (EV_KEY, EV_REL, etc...)
1497 * @code: event code 1498 * @code: event code
1498 * 1499 *
1499 * In addition to setting up corresponding bit in appropriate capability 1500 * In addition to setting up corresponding bit in appropriate capability
1500 * bitmap the function also adjusts dev->evbit. 1501 * bitmap the function also adjusts dev->evbit.
1501 */ 1502 */
1502 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code) 1503 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code)
1503 { 1504 {
1504 switch (type) { 1505 switch (type) {
1505 case EV_KEY: 1506 case EV_KEY:
1506 __set_bit(code, dev->keybit); 1507 __set_bit(code, dev->keybit);
1507 break; 1508 break;
1508 1509
1509 case EV_REL: 1510 case EV_REL:
1510 __set_bit(code, dev->relbit); 1511 __set_bit(code, dev->relbit);
1511 break; 1512 break;
1512 1513
1513 case EV_ABS: 1514 case EV_ABS:
1514 __set_bit(code, dev->absbit); 1515 __set_bit(code, dev->absbit);
1515 break; 1516 break;
1516 1517
1517 case EV_MSC: 1518 case EV_MSC:
1518 __set_bit(code, dev->mscbit); 1519 __set_bit(code, dev->mscbit);
1519 break; 1520 break;
1520 1521
1521 case EV_SW: 1522 case EV_SW:
1522 __set_bit(code, dev->swbit); 1523 __set_bit(code, dev->swbit);
1523 break; 1524 break;
1524 1525
1525 case EV_LED: 1526 case EV_LED:
1526 __set_bit(code, dev->ledbit); 1527 __set_bit(code, dev->ledbit);
1527 break; 1528 break;
1528 1529
1529 case EV_SND: 1530 case EV_SND:
1530 __set_bit(code, dev->sndbit); 1531 __set_bit(code, dev->sndbit);
1531 break; 1532 break;
1532 1533
1533 case EV_FF: 1534 case EV_FF:
1534 __set_bit(code, dev->ffbit); 1535 __set_bit(code, dev->ffbit);
1535 break; 1536 break;
1536 1537
1537 case EV_PWR: 1538 case EV_PWR:
1538 /* do nothing */ 1539 /* do nothing */
1539 break; 1540 break;
1540 1541
1541 default: 1542 default:
1542 printk(KERN_ERR 1543 printk(KERN_ERR
1543 "input_set_capability: unknown type %u (code %u)\n", 1544 "input_set_capability: unknown type %u (code %u)\n",
1544 type, code); 1545 type, code);
1545 dump_stack(); 1546 dump_stack();
1546 return; 1547 return;
1547 } 1548 }
1548 1549
1549 __set_bit(type, dev->evbit); 1550 __set_bit(type, dev->evbit);
1550 } 1551 }
1551 EXPORT_SYMBOL(input_set_capability); 1552 EXPORT_SYMBOL(input_set_capability);
1552 1553
1553 /** 1554 /**
1554 * input_register_device - register device with input core 1555 * input_register_device - register device with input core
1555 * @dev: device to be registered 1556 * @dev: device to be registered
1556 * 1557 *
1557 * This function registers device with input core. The device must be 1558 * This function registers device with input core. The device must be
1558 * allocated with input_allocate_device() and all it's capabilities 1559 * allocated with input_allocate_device() and all it's capabilities
1559 * set up before registering. 1560 * set up before registering.
1560 * If function fails the device must be freed with input_free_device(). 1561 * If function fails the device must be freed with input_free_device().
1561 * Once device has been successfully registered it can be unregistered 1562 * Once device has been successfully registered it can be unregistered
1562 * with input_unregister_device(); input_free_device() should not be 1563 * with input_unregister_device(); input_free_device() should not be
1563 * called in this case. 1564 * called in this case.
1564 */ 1565 */
1565 int input_register_device(struct input_dev *dev) 1566 int input_register_device(struct input_dev *dev)
1566 { 1567 {
1567 static atomic_t input_no = ATOMIC_INIT(0); 1568 static atomic_t input_no = ATOMIC_INIT(0);
1568 struct input_handler *handler; 1569 struct input_handler *handler;
1569 const char *path; 1570 const char *path;
1570 int error; 1571 int error;
1571 1572
1572 __set_bit(EV_SYN, dev->evbit); 1573 __set_bit(EV_SYN, dev->evbit);
1573 1574
1574 /* 1575 /*
1575 * If delay and period are pre-set by the driver, then autorepeating 1576 * If delay and period are pre-set by the driver, then autorepeating
1576 * is handled by the driver itself and we don't do it in input.c. 1577 * is handled by the driver itself and we don't do it in input.c.
1577 */ 1578 */
1578 1579
1579 init_timer(&dev->timer); 1580 init_timer(&dev->timer);
1580 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { 1581 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
1581 dev->timer.data = (long) dev; 1582 dev->timer.data = (long) dev;
1582 dev->timer.function = input_repeat_key; 1583 dev->timer.function = input_repeat_key;
1583 dev->rep[REP_DELAY] = 250; 1584 dev->rep[REP_DELAY] = 250;
1584 dev->rep[REP_PERIOD] = 33; 1585 dev->rep[REP_PERIOD] = 33;
1585 } 1586 }
1586 1587
1587 if (!dev->getkeycode) 1588 if (!dev->getkeycode)
1588 dev->getkeycode = input_default_getkeycode; 1589 dev->getkeycode = input_default_getkeycode;
1589 1590
1590 if (!dev->setkeycode) 1591 if (!dev->setkeycode)
1591 dev->setkeycode = input_default_setkeycode; 1592 dev->setkeycode = input_default_setkeycode;
1592 1593
1593 dev_set_name(&dev->dev, "input%ld", 1594 dev_set_name(&dev->dev, "input%ld",
1594 (unsigned long) atomic_inc_return(&input_no) - 1); 1595 (unsigned long) atomic_inc_return(&input_no) - 1);
1595 1596
1596 error = device_add(&dev->dev); 1597 error = device_add(&dev->dev);
1597 if (error) 1598 if (error)
1598 return error; 1599 return error;
1599 1600
1600 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); 1601 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
1601 printk(KERN_INFO "input: %s as %s\n", 1602 printk(KERN_INFO "input: %s as %s\n",
1602 dev->name ? dev->name : "Unspecified device", path ? path : "N/A"); 1603 dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
1603 kfree(path); 1604 kfree(path);
1604 1605
1605 error = mutex_lock_interruptible(&input_mutex); 1606 error = mutex_lock_interruptible(&input_mutex);
1606 if (error) { 1607 if (error) {
1607 device_del(&dev->dev); 1608 device_del(&dev->dev);
1608 return error; 1609 return error;
1609 } 1610 }
1610 1611
1611 list_add_tail(&dev->node, &input_dev_list); 1612 list_add_tail(&dev->node, &input_dev_list);
1612 1613
1613 list_for_each_entry(handler, &input_handler_list, node) 1614 list_for_each_entry(handler, &input_handler_list, node)
1614 input_attach_handler(dev, handler); 1615 input_attach_handler(dev, handler);
1615 1616
1616 input_wakeup_procfs_readers(); 1617 input_wakeup_procfs_readers();
1617 1618
1618 mutex_unlock(&input_mutex); 1619 mutex_unlock(&input_mutex);
1619 1620
1620 return 0; 1621 return 0;
1621 } 1622 }
1622 EXPORT_SYMBOL(input_register_device); 1623 EXPORT_SYMBOL(input_register_device);
1623 1624
1624 /** 1625 /**
1625 * input_unregister_device - unregister previously registered device 1626 * input_unregister_device - unregister previously registered device
1626 * @dev: device to be unregistered 1627 * @dev: device to be unregistered
1627 * 1628 *
1628 * This function unregisters an input device. Once device is unregistered 1629 * This function unregisters an input device. Once device is unregistered
1629 * the caller should not try to access it as it may get freed at any moment. 1630 * the caller should not try to access it as it may get freed at any moment.
1630 */ 1631 */
1631 void input_unregister_device(struct input_dev *dev) 1632 void input_unregister_device(struct input_dev *dev)
1632 { 1633 {
1633 struct input_handle *handle, *next; 1634 struct input_handle *handle, *next;
1634 1635
1635 input_disconnect_device(dev); 1636 input_disconnect_device(dev);
1636 1637
1637 mutex_lock(&input_mutex); 1638 mutex_lock(&input_mutex);
1638 1639
1639 list_for_each_entry_safe(handle, next, &dev->h_list, d_node) 1640 list_for_each_entry_safe(handle, next, &dev->h_list, d_node)
1640 handle->handler->disconnect(handle); 1641 handle->handler->disconnect(handle);
1641 WARN_ON(!list_empty(&dev->h_list)); 1642 WARN_ON(!list_empty(&dev->h_list));
1642 1643
1643 del_timer_sync(&dev->timer); 1644 del_timer_sync(&dev->timer);
1644 list_del_init(&dev->node); 1645 list_del_init(&dev->node);
1645 1646
1646 input_wakeup_procfs_readers(); 1647 input_wakeup_procfs_readers();
1647 1648
1648 mutex_unlock(&input_mutex); 1649 mutex_unlock(&input_mutex);
1649 1650
1650 device_unregister(&dev->dev); 1651 device_unregister(&dev->dev);
1651 } 1652 }
1652 EXPORT_SYMBOL(input_unregister_device); 1653 EXPORT_SYMBOL(input_unregister_device);
1653 1654
1654 /** 1655 /**
1655 * input_register_handler - register a new input handler 1656 * input_register_handler - register a new input handler
1656 * @handler: handler to be registered 1657 * @handler: handler to be registered
1657 * 1658 *
1658 * This function registers a new input handler (interface) for input 1659 * This function registers a new input handler (interface) for input
1659 * devices in the system and attaches it to all input devices that 1660 * devices in the system and attaches it to all input devices that
1660 * are compatible with the handler. 1661 * are compatible with the handler.
1661 */ 1662 */
1662 int input_register_handler(struct input_handler *handler) 1663 int input_register_handler(struct input_handler *handler)
1663 { 1664 {
1664 struct input_dev *dev; 1665 struct input_dev *dev;
1665 int retval; 1666 int retval;
1666 1667
1667 retval = mutex_lock_interruptible(&input_mutex); 1668 retval = mutex_lock_interruptible(&input_mutex);
1668 if (retval) 1669 if (retval)
1669 return retval; 1670 return retval;
1670 1671
1671 INIT_LIST_HEAD(&handler->h_list); 1672 INIT_LIST_HEAD(&handler->h_list);
1672 1673
1673 if (handler->fops != NULL) { 1674 if (handler->fops != NULL) {
1674 if (input_table[handler->minor >> 5]) { 1675 if (input_table[handler->minor >> 5]) {
1675 retval = -EBUSY; 1676 retval = -EBUSY;
1676 goto out; 1677 goto out;
1677 } 1678 }
1678 input_table[handler->minor >> 5] = handler; 1679 input_table[handler->minor >> 5] = handler;
1679 } 1680 }
1680 1681
1681 list_add_tail(&handler->node, &input_handler_list); 1682 list_add_tail(&handler->node, &input_handler_list);
1682 1683
1683 list_for_each_entry(dev, &input_dev_list, node) 1684 list_for_each_entry(dev, &input_dev_list, node)
1684 input_attach_handler(dev, handler); 1685 input_attach_handler(dev, handler);
1685 1686
1686 input_wakeup_procfs_readers(); 1687 input_wakeup_procfs_readers();
1687 1688
1688 out: 1689 out:
1689 mutex_unlock(&input_mutex); 1690 mutex_unlock(&input_mutex);
1690 return retval; 1691 return retval;
1691 } 1692 }
1692 EXPORT_SYMBOL(input_register_handler); 1693 EXPORT_SYMBOL(input_register_handler);
1693 1694
1694 /** 1695 /**
1695 * input_unregister_handler - unregisters an input handler 1696 * input_unregister_handler - unregisters an input handler
1696 * @handler: handler to be unregistered 1697 * @handler: handler to be unregistered
1697 * 1698 *
1698 * This function disconnects a handler from its input devices and 1699 * This function disconnects a handler from its input devices and
1699 * removes it from lists of known handlers. 1700 * removes it from lists of known handlers.
1700 */ 1701 */
1701 void input_unregister_handler(struct input_handler *handler) 1702 void input_unregister_handler(struct input_handler *handler)
1702 { 1703 {
1703 struct input_handle *handle, *next; 1704 struct input_handle *handle, *next;
1704 1705
1705 mutex_lock(&input_mutex); 1706 mutex_lock(&input_mutex);
1706 1707
1707 list_for_each_entry_safe(handle, next, &handler->h_list, h_node) 1708 list_for_each_entry_safe(handle, next, &handler->h_list, h_node)
1708 handler->disconnect(handle); 1709 handler->disconnect(handle);
1709 WARN_ON(!list_empty(&handler->h_list)); 1710 WARN_ON(!list_empty(&handler->h_list));
1710 1711
1711 list_del_init(&handler->node); 1712 list_del_init(&handler->node);
1712 1713
1713 if (handler->fops != NULL) 1714 if (handler->fops != NULL)
1714 input_table[handler->minor >> 5] = NULL; 1715 input_table[handler->minor >> 5] = NULL;
1715 1716
1716 input_wakeup_procfs_readers(); 1717 input_wakeup_procfs_readers();
1717 1718
1718 mutex_unlock(&input_mutex); 1719 mutex_unlock(&input_mutex);
1719 } 1720 }
1720 EXPORT_SYMBOL(input_unregister_handler); 1721 EXPORT_SYMBOL(input_unregister_handler);
1721 1722
1722 /** 1723 /**
1723 * input_handler_for_each_handle - handle iterator 1724 * input_handler_for_each_handle - handle iterator
1724 * @handler: input handler to iterate 1725 * @handler: input handler to iterate
1725 * @data: data for the callback 1726 * @data: data for the callback
1726 * @fn: function to be called for each handle 1727 * @fn: function to be called for each handle
1727 * 1728 *
1728 * Iterate over @bus's list of devices, and call @fn for each, passing 1729 * Iterate over @bus's list of devices, and call @fn for each, passing
1729 * it @data and stop when @fn returns a non-zero value. The function is 1730 * it @data and stop when @fn returns a non-zero value. The function is
1730 * using RCU to traverse the list and therefore may be usind in atonic 1731 * using RCU to traverse the list and therefore may be usind in atonic
1731 * contexts. The @fn callback is invoked from RCU critical section and 1732 * contexts. The @fn callback is invoked from RCU critical section and
1732 * thus must not sleep. 1733 * thus must not sleep.
1733 */ 1734 */
1734 int input_handler_for_each_handle(struct input_handler *handler, void *data, 1735 int input_handler_for_each_handle(struct input_handler *handler, void *data,
1735 int (*fn)(struct input_handle *, void *)) 1736 int (*fn)(struct input_handle *, void *))
1736 { 1737 {
1737 struct input_handle *handle; 1738 struct input_handle *handle;
1738 int retval = 0; 1739 int retval = 0;
1739 1740
1740 rcu_read_lock(); 1741 rcu_read_lock();
1741 1742
1742 list_for_each_entry_rcu(handle, &handler->h_list, h_node) { 1743 list_for_each_entry_rcu(handle, &handler->h_list, h_node) {
1743 retval = fn(handle, data); 1744 retval = fn(handle, data);
1744 if (retval) 1745 if (retval)
1745 break; 1746 break;
1746 } 1747 }
1747 1748
1748 rcu_read_unlock(); 1749 rcu_read_unlock();
1749 1750
1750 return retval; 1751 return retval;
1751 } 1752 }
1752 EXPORT_SYMBOL(input_handler_for_each_handle); 1753 EXPORT_SYMBOL(input_handler_for_each_handle);
1753 1754
1754 /** 1755 /**
1755 * input_register_handle - register a new input handle 1756 * input_register_handle - register a new input handle
1756 * @handle: handle to register 1757 * @handle: handle to register
1757 * 1758 *
1758 * This function puts a new input handle onto device's 1759 * This function puts a new input handle onto device's
1759 * and handler's lists so that events can flow through 1760 * and handler's lists so that events can flow through
1760 * it once it is opened using input_open_device(). 1761 * it once it is opened using input_open_device().
1761 * 1762 *
1762 * This function is supposed to be called from handler's 1763 * This function is supposed to be called from handler's
1763 * connect() method. 1764 * connect() method.
1764 */ 1765 */
1765 int input_register_handle(struct input_handle *handle) 1766 int input_register_handle(struct input_handle *handle)
1766 { 1767 {
1767 struct input_handler *handler = handle->handler; 1768 struct input_handler *handler = handle->handler;
1768 struct input_dev *dev = handle->dev; 1769 struct input_dev *dev = handle->dev;
1769 int error; 1770 int error;
1770 1771
1771 /* 1772 /*
1772 * We take dev->mutex here to prevent race with 1773 * We take dev->mutex here to prevent race with
1773 * input_release_device(). 1774 * input_release_device().
1774 */ 1775 */
1775 error = mutex_lock_interruptible(&dev->mutex); 1776 error = mutex_lock_interruptible(&dev->mutex);
1776 if (error) 1777 if (error)
1777 return error; 1778 return error;
1778 list_add_tail_rcu(&handle->d_node, &dev->h_list); 1779 list_add_tail_rcu(&handle->d_node, &dev->h_list);
1779 mutex_unlock(&dev->mutex); 1780 mutex_unlock(&dev->mutex);
1780 1781
1781 /* 1782 /*
1782 * Since we are supposed to be called from ->connect() 1783 * Since we are supposed to be called from ->connect()
1783 * which is mutually exclusive with ->disconnect() 1784 * which is mutually exclusive with ->disconnect()
1784 * we can't be racing with input_unregister_handle() 1785 * we can't be racing with input_unregister_handle()
1785 * and so separate lock is not needed here. 1786 * and so separate lock is not needed here.
1786 */ 1787 */
1787 list_add_tail_rcu(&handle->h_node, &handler->h_list); 1788 list_add_tail_rcu(&handle->h_node, &handler->h_list);
1788 1789
1789 if (handler->start) 1790 if (handler->start)
1790 handler->start(handle); 1791 handler->start(handle);
1791 1792
1792 return 0; 1793 return 0;
1793 } 1794 }
1794 EXPORT_SYMBOL(input_register_handle); 1795 EXPORT_SYMBOL(input_register_handle);
1795 1796
1796 /** 1797 /**
1797 * input_unregister_handle - unregister an input handle 1798 * input_unregister_handle - unregister an input handle
1798 * @handle: handle to unregister 1799 * @handle: handle to unregister
1799 * 1800 *
1800 * This function removes input handle from device's 1801 * This function removes input handle from device's
1801 * and handler's lists. 1802 * and handler's lists.
1802 * 1803 *
1803 * This function is supposed to be called from handler's 1804 * This function is supposed to be called from handler's
1804 * disconnect() method. 1805 * disconnect() method.
1805 */ 1806 */
1806 void input_unregister_handle(struct input_handle *handle) 1807 void input_unregister_handle(struct input_handle *handle)
1807 { 1808 {
1808 struct input_dev *dev = handle->dev; 1809 struct input_dev *dev = handle->dev;
1809 1810
1810 list_del_rcu(&handle->h_node); 1811 list_del_rcu(&handle->h_node);
1811 1812
1812 /* 1813 /*
1813 * Take dev->mutex to prevent race with input_release_device(). 1814 * Take dev->mutex to prevent race with input_release_device().
1814 */ 1815 */
1815 mutex_lock(&dev->mutex); 1816 mutex_lock(&dev->mutex);
1816 list_del_rcu(&handle->d_node); 1817 list_del_rcu(&handle->d_node);
1817 mutex_unlock(&dev->mutex); 1818 mutex_unlock(&dev->mutex);
1818 1819
1819 synchronize_rcu(); 1820 synchronize_rcu();
1820 } 1821 }
1821 EXPORT_SYMBOL(input_unregister_handle); 1822 EXPORT_SYMBOL(input_unregister_handle);
1822 1823
1823 static int input_open_file(struct inode *inode, struct file *file) 1824 static int input_open_file(struct inode *inode, struct file *file)
1824 { 1825 {
1825 struct input_handler *handler; 1826 struct input_handler *handler;
1826 const struct file_operations *old_fops, *new_fops = NULL; 1827 const struct file_operations *old_fops, *new_fops = NULL;
1827 int err; 1828 int err;
1828 1829
1829 lock_kernel(); 1830 lock_kernel();
1830 /* No load-on-demand here? */ 1831 /* No load-on-demand here? */
1831 handler = input_table[iminor(inode) >> 5]; 1832 handler = input_table[iminor(inode) >> 5];
1832 if (!handler || !(new_fops = fops_get(handler->fops))) { 1833 if (!handler || !(new_fops = fops_get(handler->fops))) {
1833 err = -ENODEV; 1834 err = -ENODEV;
1834 goto out; 1835 goto out;
1835 } 1836 }
1836 1837
1837 /* 1838 /*
1838 * That's _really_ odd. Usually NULL ->open means "nothing special", 1839 * That's _really_ odd. Usually NULL ->open means "nothing special",
1839 * not "no device". Oh, well... 1840 * not "no device". Oh, well...
1840 */ 1841 */
1841 if (!new_fops->open) { 1842 if (!new_fops->open) {
1842 fops_put(new_fops); 1843 fops_put(new_fops);
1843 err = -ENODEV; 1844 err = -ENODEV;
1844 goto out; 1845 goto out;
1845 } 1846 }
1846 old_fops = file->f_op; 1847 old_fops = file->f_op;
1847 file->f_op = new_fops; 1848 file->f_op = new_fops;
1848 1849
1849 err = new_fops->open(inode, file); 1850 err = new_fops->open(inode, file);
1850 1851
1851 if (err) { 1852 if (err) {
1852 fops_put(file->f_op); 1853 fops_put(file->f_op);
1853 file->f_op = fops_get(old_fops); 1854 file->f_op = fops_get(old_fops);
1854 } 1855 }
1855 fops_put(old_fops); 1856 fops_put(old_fops);
1856 out: 1857 out:
1857 unlock_kernel(); 1858 unlock_kernel();
1858 return err; 1859 return err;
1859 } 1860 }
1860 1861
1861 static const struct file_operations input_fops = { 1862 static const struct file_operations input_fops = {
1862 .owner = THIS_MODULE, 1863 .owner = THIS_MODULE,
1863 .open = input_open_file, 1864 .open = input_open_file,
1864 }; 1865 };
1865 1866
1866 static void __init input_init_abs_bypass(void) 1867 static void __init input_init_abs_bypass(void)
1867 { 1868 {
1868 const unsigned int *p; 1869 const unsigned int *p;
1869 1870
1870 for (p = input_abs_bypass_init_data; *p; p++) 1871 for (p = input_abs_bypass_init_data; *p; p++)
1871 input_abs_bypass[BIT_WORD(*p)] |= BIT_MASK(*p); 1872 input_abs_bypass[BIT_WORD(*p)] |= BIT_MASK(*p);
1872 } 1873 }
1873 1874
1874 static int __init input_init(void) 1875 static int __init input_init(void)
1875 { 1876 {
1876 int err; 1877 int err;
1877 1878
1878 input_init_abs_bypass(); 1879 input_init_abs_bypass();
1879 1880
1880 err = class_register(&input_class); 1881 err = class_register(&input_class);
1881 if (err) { 1882 if (err) {
1882 printk(KERN_ERR "input: unable to register input_dev class\n"); 1883 printk(KERN_ERR "input: unable to register input_dev class\n");
1883 return err; 1884 return err;
1884 } 1885 }
1885 1886
1886 err = input_proc_init(); 1887 err = input_proc_init();
1887 if (err) 1888 if (err)
1888 goto fail1; 1889 goto fail1;
1889 1890
1890 err = register_chrdev(INPUT_MAJOR, "input", &input_fops); 1891 err = register_chrdev(INPUT_MAJOR, "input", &input_fops);
1891 if (err) { 1892 if (err) {
1892 printk(KERN_ERR "input: unable to register char major %d", INPUT_MAJOR); 1893 printk(KERN_ERR "input: unable to register char major %d", INPUT_MAJOR);
1893 goto fail2; 1894 goto fail2;
1894 } 1895 }
1895 1896
1896 return 0; 1897 return 0;
1897 1898
1898 fail2: input_proc_exit(); 1899 fail2: input_proc_exit();
1899 fail1: class_unregister(&input_class); 1900 fail1: class_unregister(&input_class);
1900 return err; 1901 return err;
1901 } 1902 }
1902 1903
1903 static void __exit input_exit(void) 1904 static void __exit input_exit(void)
1904 { 1905 {
1905 input_proc_exit(); 1906 input_proc_exit();
1906 unregister_chrdev(INPUT_MAJOR, "input"); 1907 unregister_chrdev(INPUT_MAJOR, "input");
1907 class_unregister(&input_class); 1908 class_unregister(&input_class);
1908 } 1909 }
1909 1910
1910 subsys_initcall(input_init); 1911 subsys_initcall(input_init);
1911 module_exit(input_exit); 1912 module_exit(input_exit);
1912 1913
include/linux/input.h
1 #ifndef _INPUT_H 1 #ifndef _INPUT_H
2 #define _INPUT_H 2 #define _INPUT_H
3 3
4 /* 4 /*
5 * Copyright (c) 1999-2002 Vojtech Pavlik 5 * Copyright (c) 1999-2002 Vojtech Pavlik
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by 8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation. 9 * the Free Software Foundation.
10 */ 10 */
11 11
12 #ifdef __KERNEL__ 12 #ifdef __KERNEL__
13 #include <linux/time.h> 13 #include <linux/time.h>
14 #include <linux/list.h> 14 #include <linux/list.h>
15 #else 15 #else
16 #include <sys/time.h> 16 #include <sys/time.h>
17 #include <sys/ioctl.h> 17 #include <sys/ioctl.h>
18 #include <sys/types.h> 18 #include <sys/types.h>
19 #include <linux/types.h> 19 #include <linux/types.h>
20 #endif 20 #endif
21 21
22 /* 22 /*
23 * The event structure itself 23 * The event structure itself
24 */ 24 */
25 25
26 struct input_event { 26 struct input_event {
27 struct timeval time; 27 struct timeval time;
28 __u16 type; 28 __u16 type;
29 __u16 code; 29 __u16 code;
30 __s32 value; 30 __s32 value;
31 }; 31 };
32 32
33 /* 33 /*
34 * Protocol version. 34 * Protocol version.
35 */ 35 */
36 36
37 #define EV_VERSION 0x010000 37 #define EV_VERSION 0x010000
38 38
39 /* 39 /*
40 * IOCTLs (0x00 - 0x7f) 40 * IOCTLs (0x00 - 0x7f)
41 */ 41 */
42 42
43 struct input_id { 43 struct input_id {
44 __u16 bustype; 44 __u16 bustype;
45 __u16 vendor; 45 __u16 vendor;
46 __u16 product; 46 __u16 product;
47 __u16 version; 47 __u16 version;
48 }; 48 };
49 49
50 struct input_absinfo { 50 struct input_absinfo {
51 __s32 value; 51 __s32 value;
52 __s32 minimum; 52 __s32 minimum;
53 __s32 maximum; 53 __s32 maximum;
54 __s32 fuzz; 54 __s32 fuzz;
55 __s32 flat; 55 __s32 flat;
56 __s32 resolution; 56 __s32 resolution;
57 }; 57 };
58 58
59 #define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ 59 #define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */
60 #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ 60 #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */
61 #define EVIOCGREP _IOR('E', 0x03, int[2]) /* get repeat settings */ 61 #define EVIOCGREP _IOR('E', 0x03, int[2]) /* get repeat settings */
62 #define EVIOCSREP _IOW('E', 0x03, int[2]) /* set repeat settings */ 62 #define EVIOCSREP _IOW('E', 0x03, int[2]) /* set repeat settings */
63 #define EVIOCGKEYCODE _IOR('E', 0x04, int[2]) /* get keycode */ 63 #define EVIOCGKEYCODE _IOR('E', 0x04, int[2]) /* get keycode */
64 #define EVIOCSKEYCODE _IOW('E', 0x04, int[2]) /* set keycode */ 64 #define EVIOCSKEYCODE _IOW('E', 0x04, int[2]) /* set keycode */
65 65
66 #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ 66 #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */
67 #define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */ 67 #define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */
68 #define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */ 68 #define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */
69 69
70 #define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global keystate */ 70 #define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global keystate */
71 #define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */ 71 #define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */
72 #define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */ 72 #define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */
73 #define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */ 73 #define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */
74 74
75 #define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */ 75 #define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */
76 #define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */ 76 #define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */
77 #define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */ 77 #define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */
78 78
79 #define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */ 79 #define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */
80 #define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */ 80 #define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */
81 #define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */ 81 #define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */
82 82
83 #define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */ 83 #define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */
84 84
85 /* 85 /*
86 * Event types 86 * Event types
87 */ 87 */
88 88
89 #define EV_SYN 0x00 89 #define EV_SYN 0x00
90 #define EV_KEY 0x01 90 #define EV_KEY 0x01
91 #define EV_REL 0x02 91 #define EV_REL 0x02
92 #define EV_ABS 0x03 92 #define EV_ABS 0x03
93 #define EV_MSC 0x04 93 #define EV_MSC 0x04
94 #define EV_SW 0x05 94 #define EV_SW 0x05
95 #define EV_LED 0x11 95 #define EV_LED 0x11
96 #define EV_SND 0x12 96 #define EV_SND 0x12
97 #define EV_REP 0x14 97 #define EV_REP 0x14
98 #define EV_FF 0x15 98 #define EV_FF 0x15
99 #define EV_PWR 0x16 99 #define EV_PWR 0x16
100 #define EV_FF_STATUS 0x17 100 #define EV_FF_STATUS 0x17
101 #define EV_MAX 0x1f 101 #define EV_MAX 0x1f
102 #define EV_CNT (EV_MAX+1) 102 #define EV_CNT (EV_MAX+1)
103 103
104 /* 104 /*
105 * Synchronization events. 105 * Synchronization events.
106 */ 106 */
107 107
108 #define SYN_REPORT 0 108 #define SYN_REPORT 0
109 #define SYN_CONFIG 1 109 #define SYN_CONFIG 1
110 #define SYN_MT_REPORT 2 110 #define SYN_MT_REPORT 2
111 111
112 /* 112 /*
113 * Keys and buttons 113 * Keys and buttons
114 * 114 *
115 * Most of the keys/buttons are modeled after USB HUT 1.12 115 * Most of the keys/buttons are modeled after USB HUT 1.12
116 * (see http://www.usb.org/developers/hidpage). 116 * (see http://www.usb.org/developers/hidpage).
117 * Abbreviations in the comments: 117 * Abbreviations in the comments:
118 * AC - Application Control 118 * AC - Application Control
119 * AL - Application Launch Button 119 * AL - Application Launch Button
120 * SC - System Control 120 * SC - System Control
121 */ 121 */
122 122
123 #define KEY_RESERVED 0 123 #define KEY_RESERVED 0
124 #define KEY_ESC 1 124 #define KEY_ESC 1
125 #define KEY_1 2 125 #define KEY_1 2
126 #define KEY_2 3 126 #define KEY_2 3
127 #define KEY_3 4 127 #define KEY_3 4
128 #define KEY_4 5 128 #define KEY_4 5
129 #define KEY_5 6 129 #define KEY_5 6
130 #define KEY_6 7 130 #define KEY_6 7
131 #define KEY_7 8 131 #define KEY_7 8
132 #define KEY_8 9 132 #define KEY_8 9
133 #define KEY_9 10 133 #define KEY_9 10
134 #define KEY_0 11 134 #define KEY_0 11
135 #define KEY_MINUS 12 135 #define KEY_MINUS 12
136 #define KEY_EQUAL 13 136 #define KEY_EQUAL 13
137 #define KEY_BACKSPACE 14 137 #define KEY_BACKSPACE 14
138 #define KEY_TAB 15 138 #define KEY_TAB 15
139 #define KEY_Q 16 139 #define KEY_Q 16
140 #define KEY_W 17 140 #define KEY_W 17
141 #define KEY_E 18 141 #define KEY_E 18
142 #define KEY_R 19 142 #define KEY_R 19
143 #define KEY_T 20 143 #define KEY_T 20
144 #define KEY_Y 21 144 #define KEY_Y 21
145 #define KEY_U 22 145 #define KEY_U 22
146 #define KEY_I 23 146 #define KEY_I 23
147 #define KEY_O 24 147 #define KEY_O 24
148 #define KEY_P 25 148 #define KEY_P 25
149 #define KEY_LEFTBRACE 26 149 #define KEY_LEFTBRACE 26
150 #define KEY_RIGHTBRACE 27 150 #define KEY_RIGHTBRACE 27
151 #define KEY_ENTER 28 151 #define KEY_ENTER 28
152 #define KEY_LEFTCTRL 29 152 #define KEY_LEFTCTRL 29
153 #define KEY_A 30 153 #define KEY_A 30
154 #define KEY_S 31 154 #define KEY_S 31
155 #define KEY_D 32 155 #define KEY_D 32
156 #define KEY_F 33 156 #define KEY_F 33
157 #define KEY_G 34 157 #define KEY_G 34
158 #define KEY_H 35 158 #define KEY_H 35
159 #define KEY_J 36 159 #define KEY_J 36
160 #define KEY_K 37 160 #define KEY_K 37
161 #define KEY_L 38 161 #define KEY_L 38
162 #define KEY_SEMICOLON 39 162 #define KEY_SEMICOLON 39
163 #define KEY_APOSTROPHE 40 163 #define KEY_APOSTROPHE 40
164 #define KEY_GRAVE 41 164 #define KEY_GRAVE 41
165 #define KEY_LEFTSHIFT 42 165 #define KEY_LEFTSHIFT 42
166 #define KEY_BACKSLASH 43 166 #define KEY_BACKSLASH 43
167 #define KEY_Z 44 167 #define KEY_Z 44
168 #define KEY_X 45 168 #define KEY_X 45
169 #define KEY_C 46 169 #define KEY_C 46
170 #define KEY_V 47 170 #define KEY_V 47
171 #define KEY_B 48 171 #define KEY_B 48
172 #define KEY_N 49 172 #define KEY_N 49
173 #define KEY_M 50 173 #define KEY_M 50
174 #define KEY_COMMA 51 174 #define KEY_COMMA 51
175 #define KEY_DOT 52 175 #define KEY_DOT 52
176 #define KEY_SLASH 53 176 #define KEY_SLASH 53
177 #define KEY_RIGHTSHIFT 54 177 #define KEY_RIGHTSHIFT 54
178 #define KEY_KPASTERISK 55 178 #define KEY_KPASTERISK 55
179 #define KEY_LEFTALT 56 179 #define KEY_LEFTALT 56
180 #define KEY_SPACE 57 180 #define KEY_SPACE 57
181 #define KEY_CAPSLOCK 58 181 #define KEY_CAPSLOCK 58
182 #define KEY_F1 59 182 #define KEY_F1 59
183 #define KEY_F2 60 183 #define KEY_F2 60
184 #define KEY_F3 61 184 #define KEY_F3 61
185 #define KEY_F4 62 185 #define KEY_F4 62
186 #define KEY_F5 63 186 #define KEY_F5 63
187 #define KEY_F6 64 187 #define KEY_F6 64
188 #define KEY_F7 65 188 #define KEY_F7 65
189 #define KEY_F8 66 189 #define KEY_F8 66
190 #define KEY_F9 67 190 #define KEY_F9 67
191 #define KEY_F10 68 191 #define KEY_F10 68
192 #define KEY_NUMLOCK 69 192 #define KEY_NUMLOCK 69
193 #define KEY_SCROLLLOCK 70 193 #define KEY_SCROLLLOCK 70
194 #define KEY_KP7 71 194 #define KEY_KP7 71
195 #define KEY_KP8 72 195 #define KEY_KP8 72
196 #define KEY_KP9 73 196 #define KEY_KP9 73
197 #define KEY_KPMINUS 74 197 #define KEY_KPMINUS 74
198 #define KEY_KP4 75 198 #define KEY_KP4 75
199 #define KEY_KP5 76 199 #define KEY_KP5 76
200 #define KEY_KP6 77 200 #define KEY_KP6 77
201 #define KEY_KPPLUS 78 201 #define KEY_KPPLUS 78
202 #define KEY_KP1 79 202 #define KEY_KP1 79
203 #define KEY_KP2 80 203 #define KEY_KP2 80
204 #define KEY_KP3 81 204 #define KEY_KP3 81
205 #define KEY_KP0 82 205 #define KEY_KP0 82
206 #define KEY_KPDOT 83 206 #define KEY_KPDOT 83
207 207
208 #define KEY_ZENKAKUHANKAKU 85 208 #define KEY_ZENKAKUHANKAKU 85
209 #define KEY_102ND 86 209 #define KEY_102ND 86
210 #define KEY_F11 87 210 #define KEY_F11 87
211 #define KEY_F12 88 211 #define KEY_F12 88
212 #define KEY_RO 89 212 #define KEY_RO 89
213 #define KEY_KATAKANA 90 213 #define KEY_KATAKANA 90
214 #define KEY_HIRAGANA 91 214 #define KEY_HIRAGANA 91
215 #define KEY_HENKAN 92 215 #define KEY_HENKAN 92
216 #define KEY_KATAKANAHIRAGANA 93 216 #define KEY_KATAKANAHIRAGANA 93
217 #define KEY_MUHENKAN 94 217 #define KEY_MUHENKAN 94
218 #define KEY_KPJPCOMMA 95 218 #define KEY_KPJPCOMMA 95
219 #define KEY_KPENTER 96 219 #define KEY_KPENTER 96
220 #define KEY_RIGHTCTRL 97 220 #define KEY_RIGHTCTRL 97
221 #define KEY_KPSLASH 98 221 #define KEY_KPSLASH 98
222 #define KEY_SYSRQ 99 222 #define KEY_SYSRQ 99
223 #define KEY_RIGHTALT 100 223 #define KEY_RIGHTALT 100
224 #define KEY_LINEFEED 101 224 #define KEY_LINEFEED 101
225 #define KEY_HOME 102 225 #define KEY_HOME 102
226 #define KEY_UP 103 226 #define KEY_UP 103
227 #define KEY_PAGEUP 104 227 #define KEY_PAGEUP 104
228 #define KEY_LEFT 105 228 #define KEY_LEFT 105
229 #define KEY_RIGHT 106 229 #define KEY_RIGHT 106
230 #define KEY_END 107 230 #define KEY_END 107
231 #define KEY_DOWN 108 231 #define KEY_DOWN 108
232 #define KEY_PAGEDOWN 109 232 #define KEY_PAGEDOWN 109
233 #define KEY_INSERT 110 233 #define KEY_INSERT 110
234 #define KEY_DELETE 111 234 #define KEY_DELETE 111
235 #define KEY_MACRO 112 235 #define KEY_MACRO 112
236 #define KEY_MUTE 113 236 #define KEY_MUTE 113
237 #define KEY_VOLUMEDOWN 114 237 #define KEY_VOLUMEDOWN 114
238 #define KEY_VOLUMEUP 115 238 #define KEY_VOLUMEUP 115
239 #define KEY_POWER 116 /* SC System Power Down */ 239 #define KEY_POWER 116 /* SC System Power Down */
240 #define KEY_KPEQUAL 117 240 #define KEY_KPEQUAL 117
241 #define KEY_KPPLUSMINUS 118 241 #define KEY_KPPLUSMINUS 118
242 #define KEY_PAUSE 119 242 #define KEY_PAUSE 119
243 #define KEY_SCALE 120 /* AL Compiz Scale (Expose) */ 243 #define KEY_SCALE 120 /* AL Compiz Scale (Expose) */
244 244
245 #define KEY_KPCOMMA 121 245 #define KEY_KPCOMMA 121
246 #define KEY_HANGEUL 122 246 #define KEY_HANGEUL 122
247 #define KEY_HANGUEL KEY_HANGEUL 247 #define KEY_HANGUEL KEY_HANGEUL
248 #define KEY_HANJA 123 248 #define KEY_HANJA 123
249 #define KEY_YEN 124 249 #define KEY_YEN 124
250 #define KEY_LEFTMETA 125 250 #define KEY_LEFTMETA 125
251 #define KEY_RIGHTMETA 126 251 #define KEY_RIGHTMETA 126
252 #define KEY_COMPOSE 127 252 #define KEY_COMPOSE 127
253 253
254 #define KEY_STOP 128 /* AC Stop */ 254 #define KEY_STOP 128 /* AC Stop */
255 #define KEY_AGAIN 129 255 #define KEY_AGAIN 129
256 #define KEY_PROPS 130 /* AC Properties */ 256 #define KEY_PROPS 130 /* AC Properties */
257 #define KEY_UNDO 131 /* AC Undo */ 257 #define KEY_UNDO 131 /* AC Undo */
258 #define KEY_FRONT 132 258 #define KEY_FRONT 132
259 #define KEY_COPY 133 /* AC Copy */ 259 #define KEY_COPY 133 /* AC Copy */
260 #define KEY_OPEN 134 /* AC Open */ 260 #define KEY_OPEN 134 /* AC Open */
261 #define KEY_PASTE 135 /* AC Paste */ 261 #define KEY_PASTE 135 /* AC Paste */
262 #define KEY_FIND 136 /* AC Search */ 262 #define KEY_FIND 136 /* AC Search */
263 #define KEY_CUT 137 /* AC Cut */ 263 #define KEY_CUT 137 /* AC Cut */
264 #define KEY_HELP 138 /* AL Integrated Help Center */ 264 #define KEY_HELP 138 /* AL Integrated Help Center */
265 #define KEY_MENU 139 /* Menu (show menu) */ 265 #define KEY_MENU 139 /* Menu (show menu) */
266 #define KEY_CALC 140 /* AL Calculator */ 266 #define KEY_CALC 140 /* AL Calculator */
267 #define KEY_SETUP 141 267 #define KEY_SETUP 141
268 #define KEY_SLEEP 142 /* SC System Sleep */ 268 #define KEY_SLEEP 142 /* SC System Sleep */
269 #define KEY_WAKEUP 143 /* System Wake Up */ 269 #define KEY_WAKEUP 143 /* System Wake Up */
270 #define KEY_FILE 144 /* AL Local Machine Browser */ 270 #define KEY_FILE 144 /* AL Local Machine Browser */
271 #define KEY_SENDFILE 145 271 #define KEY_SENDFILE 145
272 #define KEY_DELETEFILE 146 272 #define KEY_DELETEFILE 146
273 #define KEY_XFER 147 273 #define KEY_XFER 147
274 #define KEY_PROG1 148 274 #define KEY_PROG1 148
275 #define KEY_PROG2 149 275 #define KEY_PROG2 149
276 #define KEY_WWW 150 /* AL Internet Browser */ 276 #define KEY_WWW 150 /* AL Internet Browser */
277 #define KEY_MSDOS 151 277 #define KEY_MSDOS 151
278 #define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */ 278 #define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */
279 #define KEY_SCREENLOCK KEY_COFFEE 279 #define KEY_SCREENLOCK KEY_COFFEE
280 #define KEY_DIRECTION 153 280 #define KEY_DIRECTION 153
281 #define KEY_CYCLEWINDOWS 154 281 #define KEY_CYCLEWINDOWS 154
282 #define KEY_MAIL 155 282 #define KEY_MAIL 155
283 #define KEY_BOOKMARKS 156 /* AC Bookmarks */ 283 #define KEY_BOOKMARKS 156 /* AC Bookmarks */
284 #define KEY_COMPUTER 157 284 #define KEY_COMPUTER 157
285 #define KEY_BACK 158 /* AC Back */ 285 #define KEY_BACK 158 /* AC Back */
286 #define KEY_FORWARD 159 /* AC Forward */ 286 #define KEY_FORWARD 159 /* AC Forward */
287 #define KEY_CLOSECD 160 287 #define KEY_CLOSECD 160
288 #define KEY_EJECTCD 161 288 #define KEY_EJECTCD 161
289 #define KEY_EJECTCLOSECD 162 289 #define KEY_EJECTCLOSECD 162
290 #define KEY_NEXTSONG 163 290 #define KEY_NEXTSONG 163
291 #define KEY_PLAYPAUSE 164 291 #define KEY_PLAYPAUSE 164
292 #define KEY_PREVIOUSSONG 165 292 #define KEY_PREVIOUSSONG 165
293 #define KEY_STOPCD 166 293 #define KEY_STOPCD 166
294 #define KEY_RECORD 167 294 #define KEY_RECORD 167
295 #define KEY_REWIND 168 295 #define KEY_REWIND 168
296 #define KEY_PHONE 169 /* Media Select Telephone */ 296 #define KEY_PHONE 169 /* Media Select Telephone */
297 #define KEY_ISO 170 297 #define KEY_ISO 170
298 #define KEY_CONFIG 171 /* AL Consumer Control Configuration */ 298 #define KEY_CONFIG 171 /* AL Consumer Control Configuration */
299 #define KEY_HOMEPAGE 172 /* AC Home */ 299 #define KEY_HOMEPAGE 172 /* AC Home */
300 #define KEY_REFRESH 173 /* AC Refresh */ 300 #define KEY_REFRESH 173 /* AC Refresh */
301 #define KEY_EXIT 174 /* AC Exit */ 301 #define KEY_EXIT 174 /* AC Exit */
302 #define KEY_MOVE 175 302 #define KEY_MOVE 175
303 #define KEY_EDIT 176 303 #define KEY_EDIT 176
304 #define KEY_SCROLLUP 177 304 #define KEY_SCROLLUP 177
305 #define KEY_SCROLLDOWN 178 305 #define KEY_SCROLLDOWN 178
306 #define KEY_KPLEFTPAREN 179 306 #define KEY_KPLEFTPAREN 179
307 #define KEY_KPRIGHTPAREN 180 307 #define KEY_KPRIGHTPAREN 180
308 #define KEY_NEW 181 /* AC New */ 308 #define KEY_NEW 181 /* AC New */
309 #define KEY_REDO 182 /* AC Redo/Repeat */ 309 #define KEY_REDO 182 /* AC Redo/Repeat */
310 310
311 #define KEY_F13 183 311 #define KEY_F13 183
312 #define KEY_F14 184 312 #define KEY_F14 184
313 #define KEY_F15 185 313 #define KEY_F15 185
314 #define KEY_F16 186 314 #define KEY_F16 186
315 #define KEY_F17 187 315 #define KEY_F17 187
316 #define KEY_F18 188 316 #define KEY_F18 188
317 #define KEY_F19 189 317 #define KEY_F19 189
318 #define KEY_F20 190 318 #define KEY_F20 190
319 #define KEY_F21 191 319 #define KEY_F21 191
320 #define KEY_F22 192 320 #define KEY_F22 192
321 #define KEY_F23 193 321 #define KEY_F23 193
322 #define KEY_F24 194 322 #define KEY_F24 194
323 323
324 #define KEY_PLAYCD 200 324 #define KEY_PLAYCD 200
325 #define KEY_PAUSECD 201 325 #define KEY_PAUSECD 201
326 #define KEY_PROG3 202 326 #define KEY_PROG3 202
327 #define KEY_PROG4 203 327 #define KEY_PROG4 203
328 #define KEY_DASHBOARD 204 /* AL Dashboard */ 328 #define KEY_DASHBOARD 204 /* AL Dashboard */
329 #define KEY_SUSPEND 205 329 #define KEY_SUSPEND 205
330 #define KEY_CLOSE 206 /* AC Close */ 330 #define KEY_CLOSE 206 /* AC Close */
331 #define KEY_PLAY 207 331 #define KEY_PLAY 207
332 #define KEY_FASTFORWARD 208 332 #define KEY_FASTFORWARD 208
333 #define KEY_BASSBOOST 209 333 #define KEY_BASSBOOST 209
334 #define KEY_PRINT 210 /* AC Print */ 334 #define KEY_PRINT 210 /* AC Print */
335 #define KEY_HP 211 335 #define KEY_HP 211
336 #define KEY_CAMERA 212 336 #define KEY_CAMERA 212
337 #define KEY_SOUND 213 337 #define KEY_SOUND 213
338 #define KEY_QUESTION 214 338 #define KEY_QUESTION 214
339 #define KEY_EMAIL 215 339 #define KEY_EMAIL 215
340 #define KEY_CHAT 216 340 #define KEY_CHAT 216
341 #define KEY_SEARCH 217 341 #define KEY_SEARCH 217
342 #define KEY_CONNECT 218 342 #define KEY_CONNECT 218
343 #define KEY_FINANCE 219 /* AL Checkbook/Finance */ 343 #define KEY_FINANCE 219 /* AL Checkbook/Finance */
344 #define KEY_SPORT 220 344 #define KEY_SPORT 220
345 #define KEY_SHOP 221 345 #define KEY_SHOP 221
346 #define KEY_ALTERASE 222 346 #define KEY_ALTERASE 222
347 #define KEY_CANCEL 223 /* AC Cancel */ 347 #define KEY_CANCEL 223 /* AC Cancel */
348 #define KEY_BRIGHTNESSDOWN 224 348 #define KEY_BRIGHTNESSDOWN 224
349 #define KEY_BRIGHTNESSUP 225 349 #define KEY_BRIGHTNESSUP 225
350 #define KEY_MEDIA 226 350 #define KEY_MEDIA 226
351 351
352 #define KEY_SWITCHVIDEOMODE 227 /* Cycle between available video 352 #define KEY_SWITCHVIDEOMODE 227 /* Cycle between available video
353 outputs (Monitor/LCD/TV-out/etc) */ 353 outputs (Monitor/LCD/TV-out/etc) */
354 #define KEY_KBDILLUMTOGGLE 228 354 #define KEY_KBDILLUMTOGGLE 228
355 #define KEY_KBDILLUMDOWN 229 355 #define KEY_KBDILLUMDOWN 229
356 #define KEY_KBDILLUMUP 230 356 #define KEY_KBDILLUMUP 230
357 357
358 #define KEY_SEND 231 /* AC Send */ 358 #define KEY_SEND 231 /* AC Send */
359 #define KEY_REPLY 232 /* AC Reply */ 359 #define KEY_REPLY 232 /* AC Reply */
360 #define KEY_FORWARDMAIL 233 /* AC Forward Msg */ 360 #define KEY_FORWARDMAIL 233 /* AC Forward Msg */
361 #define KEY_SAVE 234 /* AC Save */ 361 #define KEY_SAVE 234 /* AC Save */
362 #define KEY_DOCUMENTS 235 362 #define KEY_DOCUMENTS 235
363 363
364 #define KEY_BATTERY 236 364 #define KEY_BATTERY 236
365 365
366 #define KEY_BLUETOOTH 237 366 #define KEY_BLUETOOTH 237
367 #define KEY_WLAN 238 367 #define KEY_WLAN 238
368 #define KEY_UWB 239 368 #define KEY_UWB 239
369 369
370 #define KEY_UNKNOWN 240 370 #define KEY_UNKNOWN 240
371 371
372 #define KEY_VIDEO_NEXT 241 /* drive next video source */ 372 #define KEY_VIDEO_NEXT 241 /* drive next video source */
373 #define KEY_VIDEO_PREV 242 /* drive previous video source */ 373 #define KEY_VIDEO_PREV 242 /* drive previous video source */
374 #define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */ 374 #define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */
375 #define KEY_BRIGHTNESS_ZERO 244 /* brightness off, use ambient */ 375 #define KEY_BRIGHTNESS_ZERO 244 /* brightness off, use ambient */
376 #define KEY_DISPLAY_OFF 245 /* display device to off state */ 376 #define KEY_DISPLAY_OFF 245 /* display device to off state */
377 377
378 #define KEY_WIMAX 246 378 #define KEY_WIMAX 246
379 379
380 /* Range 248 - 255 is reserved for special needs of AT keyboard driver */ 380 /* Range 248 - 255 is reserved for special needs of AT keyboard driver */
381 381
382 #define BTN_MISC 0x100 382 #define BTN_MISC 0x100
383 #define BTN_0 0x100 383 #define BTN_0 0x100
384 #define BTN_1 0x101 384 #define BTN_1 0x101
385 #define BTN_2 0x102 385 #define BTN_2 0x102
386 #define BTN_3 0x103 386 #define BTN_3 0x103
387 #define BTN_4 0x104 387 #define BTN_4 0x104
388 #define BTN_5 0x105 388 #define BTN_5 0x105
389 #define BTN_6 0x106 389 #define BTN_6 0x106
390 #define BTN_7 0x107 390 #define BTN_7 0x107
391 #define BTN_8 0x108 391 #define BTN_8 0x108
392 #define BTN_9 0x109 392 #define BTN_9 0x109
393 393
394 #define BTN_MOUSE 0x110 394 #define BTN_MOUSE 0x110
395 #define BTN_LEFT 0x110 395 #define BTN_LEFT 0x110
396 #define BTN_RIGHT 0x111 396 #define BTN_RIGHT 0x111
397 #define BTN_MIDDLE 0x112 397 #define BTN_MIDDLE 0x112
398 #define BTN_SIDE 0x113 398 #define BTN_SIDE 0x113
399 #define BTN_EXTRA 0x114 399 #define BTN_EXTRA 0x114
400 #define BTN_FORWARD 0x115 400 #define BTN_FORWARD 0x115
401 #define BTN_BACK 0x116 401 #define BTN_BACK 0x116
402 #define BTN_TASK 0x117 402 #define BTN_TASK 0x117
403 403
404 #define BTN_JOYSTICK 0x120 404 #define BTN_JOYSTICK 0x120
405 #define BTN_TRIGGER 0x120 405 #define BTN_TRIGGER 0x120
406 #define BTN_THUMB 0x121 406 #define BTN_THUMB 0x121
407 #define BTN_THUMB2 0x122 407 #define BTN_THUMB2 0x122
408 #define BTN_TOP 0x123 408 #define BTN_TOP 0x123
409 #define BTN_TOP2 0x124 409 #define BTN_TOP2 0x124
410 #define BTN_PINKIE 0x125 410 #define BTN_PINKIE 0x125
411 #define BTN_BASE 0x126 411 #define BTN_BASE 0x126
412 #define BTN_BASE2 0x127 412 #define BTN_BASE2 0x127
413 #define BTN_BASE3 0x128 413 #define BTN_BASE3 0x128
414 #define BTN_BASE4 0x129 414 #define BTN_BASE4 0x129
415 #define BTN_BASE5 0x12a 415 #define BTN_BASE5 0x12a
416 #define BTN_BASE6 0x12b 416 #define BTN_BASE6 0x12b
417 #define BTN_DEAD 0x12f 417 #define BTN_DEAD 0x12f
418 418
419 #define BTN_GAMEPAD 0x130 419 #define BTN_GAMEPAD 0x130
420 #define BTN_A 0x130 420 #define BTN_A 0x130
421 #define BTN_B 0x131 421 #define BTN_B 0x131
422 #define BTN_C 0x132 422 #define BTN_C 0x132
423 #define BTN_X 0x133 423 #define BTN_X 0x133
424 #define BTN_Y 0x134 424 #define BTN_Y 0x134
425 #define BTN_Z 0x135 425 #define BTN_Z 0x135
426 #define BTN_TL 0x136 426 #define BTN_TL 0x136
427 #define BTN_TR 0x137 427 #define BTN_TR 0x137
428 #define BTN_TL2 0x138 428 #define BTN_TL2 0x138
429 #define BTN_TR2 0x139 429 #define BTN_TR2 0x139
430 #define BTN_SELECT 0x13a 430 #define BTN_SELECT 0x13a
431 #define BTN_START 0x13b 431 #define BTN_START 0x13b
432 #define BTN_MODE 0x13c 432 #define BTN_MODE 0x13c
433 #define BTN_THUMBL 0x13d 433 #define BTN_THUMBL 0x13d
434 #define BTN_THUMBR 0x13e 434 #define BTN_THUMBR 0x13e
435 435
436 #define BTN_DIGI 0x140 436 #define BTN_DIGI 0x140
437 #define BTN_TOOL_PEN 0x140 437 #define BTN_TOOL_PEN 0x140
438 #define BTN_TOOL_RUBBER 0x141 438 #define BTN_TOOL_RUBBER 0x141
439 #define BTN_TOOL_BRUSH 0x142 439 #define BTN_TOOL_BRUSH 0x142
440 #define BTN_TOOL_PENCIL 0x143 440 #define BTN_TOOL_PENCIL 0x143
441 #define BTN_TOOL_AIRBRUSH 0x144 441 #define BTN_TOOL_AIRBRUSH 0x144
442 #define BTN_TOOL_FINGER 0x145 442 #define BTN_TOOL_FINGER 0x145
443 #define BTN_TOOL_MOUSE 0x146 443 #define BTN_TOOL_MOUSE 0x146
444 #define BTN_TOOL_LENS 0x147 444 #define BTN_TOOL_LENS 0x147
445 #define BTN_TOUCH 0x14a 445 #define BTN_TOUCH 0x14a
446 #define BTN_STYLUS 0x14b 446 #define BTN_STYLUS 0x14b
447 #define BTN_STYLUS2 0x14c 447 #define BTN_STYLUS2 0x14c
448 #define BTN_TOOL_DOUBLETAP 0x14d 448 #define BTN_TOOL_DOUBLETAP 0x14d
449 #define BTN_TOOL_TRIPLETAP 0x14e 449 #define BTN_TOOL_TRIPLETAP 0x14e
450 #define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ 450 #define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
451 451
452 #define BTN_WHEEL 0x150 452 #define BTN_WHEEL 0x150
453 #define BTN_GEAR_DOWN 0x150 453 #define BTN_GEAR_DOWN 0x150
454 #define BTN_GEAR_UP 0x151 454 #define BTN_GEAR_UP 0x151
455 455
456 #define KEY_OK 0x160 456 #define KEY_OK 0x160
457 #define KEY_SELECT 0x161 457 #define KEY_SELECT 0x161
458 #define KEY_GOTO 0x162 458 #define KEY_GOTO 0x162
459 #define KEY_CLEAR 0x163 459 #define KEY_CLEAR 0x163
460 #define KEY_POWER2 0x164 460 #define KEY_POWER2 0x164
461 #define KEY_OPTION 0x165 461 #define KEY_OPTION 0x165
462 #define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */ 462 #define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */
463 #define KEY_TIME 0x167 463 #define KEY_TIME 0x167
464 #define KEY_VENDOR 0x168 464 #define KEY_VENDOR 0x168
465 #define KEY_ARCHIVE 0x169 465 #define KEY_ARCHIVE 0x169
466 #define KEY_PROGRAM 0x16a /* Media Select Program Guide */ 466 #define KEY_PROGRAM 0x16a /* Media Select Program Guide */
467 #define KEY_CHANNEL 0x16b 467 #define KEY_CHANNEL 0x16b
468 #define KEY_FAVORITES 0x16c 468 #define KEY_FAVORITES 0x16c
469 #define KEY_EPG 0x16d 469 #define KEY_EPG 0x16d
470 #define KEY_PVR 0x16e /* Media Select Home */ 470 #define KEY_PVR 0x16e /* Media Select Home */
471 #define KEY_MHP 0x16f 471 #define KEY_MHP 0x16f
472 #define KEY_LANGUAGE 0x170 472 #define KEY_LANGUAGE 0x170
473 #define KEY_TITLE 0x171 473 #define KEY_TITLE 0x171
474 #define KEY_SUBTITLE 0x172 474 #define KEY_SUBTITLE 0x172
475 #define KEY_ANGLE 0x173 475 #define KEY_ANGLE 0x173
476 #define KEY_ZOOM 0x174 476 #define KEY_ZOOM 0x174
477 #define KEY_MODE 0x175 477 #define KEY_MODE 0x175
478 #define KEY_KEYBOARD 0x176 478 #define KEY_KEYBOARD 0x176
479 #define KEY_SCREEN 0x177 479 #define KEY_SCREEN 0x177
480 #define KEY_PC 0x178 /* Media Select Computer */ 480 #define KEY_PC 0x178 /* Media Select Computer */
481 #define KEY_TV 0x179 /* Media Select TV */ 481 #define KEY_TV 0x179 /* Media Select TV */
482 #define KEY_TV2 0x17a /* Media Select Cable */ 482 #define KEY_TV2 0x17a /* Media Select Cable */
483 #define KEY_VCR 0x17b /* Media Select VCR */ 483 #define KEY_VCR 0x17b /* Media Select VCR */
484 #define KEY_VCR2 0x17c /* VCR Plus */ 484 #define KEY_VCR2 0x17c /* VCR Plus */
485 #define KEY_SAT 0x17d /* Media Select Satellite */ 485 #define KEY_SAT 0x17d /* Media Select Satellite */
486 #define KEY_SAT2 0x17e 486 #define KEY_SAT2 0x17e
487 #define KEY_CD 0x17f /* Media Select CD */ 487 #define KEY_CD 0x17f /* Media Select CD */
488 #define KEY_TAPE 0x180 /* Media Select Tape */ 488 #define KEY_TAPE 0x180 /* Media Select Tape */
489 #define KEY_RADIO 0x181 489 #define KEY_RADIO 0x181
490 #define KEY_TUNER 0x182 /* Media Select Tuner */ 490 #define KEY_TUNER 0x182 /* Media Select Tuner */
491 #define KEY_PLAYER 0x183 491 #define KEY_PLAYER 0x183
492 #define KEY_TEXT 0x184 492 #define KEY_TEXT 0x184
493 #define KEY_DVD 0x185 /* Media Select DVD */ 493 #define KEY_DVD 0x185 /* Media Select DVD */
494 #define KEY_AUX 0x186 494 #define KEY_AUX 0x186
495 #define KEY_MP3 0x187 495 #define KEY_MP3 0x187
496 #define KEY_AUDIO 0x188 496 #define KEY_AUDIO 0x188
497 #define KEY_VIDEO 0x189 497 #define KEY_VIDEO 0x189
498 #define KEY_DIRECTORY 0x18a 498 #define KEY_DIRECTORY 0x18a
499 #define KEY_LIST 0x18b 499 #define KEY_LIST 0x18b
500 #define KEY_MEMO 0x18c /* Media Select Messages */ 500 #define KEY_MEMO 0x18c /* Media Select Messages */
501 #define KEY_CALENDAR 0x18d 501 #define KEY_CALENDAR 0x18d
502 #define KEY_RED 0x18e 502 #define KEY_RED 0x18e
503 #define KEY_GREEN 0x18f 503 #define KEY_GREEN 0x18f
504 #define KEY_YELLOW 0x190 504 #define KEY_YELLOW 0x190
505 #define KEY_BLUE 0x191 505 #define KEY_BLUE 0x191
506 #define KEY_CHANNELUP 0x192 /* Channel Increment */ 506 #define KEY_CHANNELUP 0x192 /* Channel Increment */
507 #define KEY_CHANNELDOWN 0x193 /* Channel Decrement */ 507 #define KEY_CHANNELDOWN 0x193 /* Channel Decrement */
508 #define KEY_FIRST 0x194 508 #define KEY_FIRST 0x194
509 #define KEY_LAST 0x195 /* Recall Last */ 509 #define KEY_LAST 0x195 /* Recall Last */
510 #define KEY_AB 0x196 510 #define KEY_AB 0x196
511 #define KEY_NEXT 0x197 511 #define KEY_NEXT 0x197
512 #define KEY_RESTART 0x198 512 #define KEY_RESTART 0x198
513 #define KEY_SLOW 0x199 513 #define KEY_SLOW 0x199
514 #define KEY_SHUFFLE 0x19a 514 #define KEY_SHUFFLE 0x19a
515 #define KEY_BREAK 0x19b 515 #define KEY_BREAK 0x19b
516 #define KEY_PREVIOUS 0x19c 516 #define KEY_PREVIOUS 0x19c
517 #define KEY_DIGITS 0x19d 517 #define KEY_DIGITS 0x19d
518 #define KEY_TEEN 0x19e 518 #define KEY_TEEN 0x19e
519 #define KEY_TWEN 0x19f 519 #define KEY_TWEN 0x19f
520 #define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */ 520 #define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */
521 #define KEY_GAMES 0x1a1 /* Media Select Games */ 521 #define KEY_GAMES 0x1a1 /* Media Select Games */
522 #define KEY_ZOOMIN 0x1a2 /* AC Zoom In */ 522 #define KEY_ZOOMIN 0x1a2 /* AC Zoom In */
523 #define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */ 523 #define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */
524 #define KEY_ZOOMRESET 0x1a4 /* AC Zoom */ 524 #define KEY_ZOOMRESET 0x1a4 /* AC Zoom */
525 #define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */ 525 #define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */
526 #define KEY_EDITOR 0x1a6 /* AL Text Editor */ 526 #define KEY_EDITOR 0x1a6 /* AL Text Editor */
527 #define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */ 527 #define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */
528 #define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */ 528 #define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */
529 #define KEY_PRESENTATION 0x1a9 /* AL Presentation App */ 529 #define KEY_PRESENTATION 0x1a9 /* AL Presentation App */
530 #define KEY_DATABASE 0x1aa /* AL Database App */ 530 #define KEY_DATABASE 0x1aa /* AL Database App */
531 #define KEY_NEWS 0x1ab /* AL Newsreader */ 531 #define KEY_NEWS 0x1ab /* AL Newsreader */
532 #define KEY_VOICEMAIL 0x1ac /* AL Voicemail */ 532 #define KEY_VOICEMAIL 0x1ac /* AL Voicemail */
533 #define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */ 533 #define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */
534 #define KEY_MESSENGER 0x1ae /* AL Instant Messaging */ 534 #define KEY_MESSENGER 0x1ae /* AL Instant Messaging */
535 #define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */ 535 #define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */
536 #define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */ 536 #define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */
537 #define KEY_LOGOFF 0x1b1 /* AL Logoff */ 537 #define KEY_LOGOFF 0x1b1 /* AL Logoff */
538 538
539 #define KEY_DOLLAR 0x1b2 539 #define KEY_DOLLAR 0x1b2
540 #define KEY_EURO 0x1b3 540 #define KEY_EURO 0x1b3
541 541
542 #define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */ 542 #define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */
543 #define KEY_FRAMEFORWARD 0x1b5 543 #define KEY_FRAMEFORWARD 0x1b5
544 #define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */ 544 #define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */
545 #define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */ 545 #define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */
546 546
547 #define KEY_DEL_EOL 0x1c0 547 #define KEY_DEL_EOL 0x1c0
548 #define KEY_DEL_EOS 0x1c1 548 #define KEY_DEL_EOS 0x1c1
549 #define KEY_INS_LINE 0x1c2 549 #define KEY_INS_LINE 0x1c2
550 #define KEY_DEL_LINE 0x1c3 550 #define KEY_DEL_LINE 0x1c3
551 551
552 #define KEY_FN 0x1d0 552 #define KEY_FN 0x1d0
553 #define KEY_FN_ESC 0x1d1 553 #define KEY_FN_ESC 0x1d1
554 #define KEY_FN_F1 0x1d2 554 #define KEY_FN_F1 0x1d2
555 #define KEY_FN_F2 0x1d3 555 #define KEY_FN_F2 0x1d3
556 #define KEY_FN_F3 0x1d4 556 #define KEY_FN_F3 0x1d4
557 #define KEY_FN_F4 0x1d5 557 #define KEY_FN_F4 0x1d5
558 #define KEY_FN_F5 0x1d6 558 #define KEY_FN_F5 0x1d6
559 #define KEY_FN_F6 0x1d7 559 #define KEY_FN_F6 0x1d7
560 #define KEY_FN_F7 0x1d8 560 #define KEY_FN_F7 0x1d8
561 #define KEY_FN_F8 0x1d9 561 #define KEY_FN_F8 0x1d9
562 #define KEY_FN_F9 0x1da 562 #define KEY_FN_F9 0x1da
563 #define KEY_FN_F10 0x1db 563 #define KEY_FN_F10 0x1db
564 #define KEY_FN_F11 0x1dc 564 #define KEY_FN_F11 0x1dc
565 #define KEY_FN_F12 0x1dd 565 #define KEY_FN_F12 0x1dd
566 #define KEY_FN_1 0x1de 566 #define KEY_FN_1 0x1de
567 #define KEY_FN_2 0x1df 567 #define KEY_FN_2 0x1df
568 #define KEY_FN_D 0x1e0 568 #define KEY_FN_D 0x1e0
569 #define KEY_FN_E 0x1e1 569 #define KEY_FN_E 0x1e1
570 #define KEY_FN_F 0x1e2 570 #define KEY_FN_F 0x1e2
571 #define KEY_FN_S 0x1e3 571 #define KEY_FN_S 0x1e3
572 #define KEY_FN_B 0x1e4 572 #define KEY_FN_B 0x1e4
573 573
574 #define KEY_BRL_DOT1 0x1f1 574 #define KEY_BRL_DOT1 0x1f1
575 #define KEY_BRL_DOT2 0x1f2 575 #define KEY_BRL_DOT2 0x1f2
576 #define KEY_BRL_DOT3 0x1f3 576 #define KEY_BRL_DOT3 0x1f3
577 #define KEY_BRL_DOT4 0x1f4 577 #define KEY_BRL_DOT4 0x1f4
578 #define KEY_BRL_DOT5 0x1f5 578 #define KEY_BRL_DOT5 0x1f5
579 #define KEY_BRL_DOT6 0x1f6 579 #define KEY_BRL_DOT6 0x1f6
580 #define KEY_BRL_DOT7 0x1f7 580 #define KEY_BRL_DOT7 0x1f7
581 #define KEY_BRL_DOT8 0x1f8 581 #define KEY_BRL_DOT8 0x1f8
582 #define KEY_BRL_DOT9 0x1f9 582 #define KEY_BRL_DOT9 0x1f9
583 #define KEY_BRL_DOT10 0x1fa 583 #define KEY_BRL_DOT10 0x1fa
584 584
585 #define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */ 585 #define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */
586 #define KEY_NUMERIC_1 0x201 /* and other keypads */ 586 #define KEY_NUMERIC_1 0x201 /* and other keypads */
587 #define KEY_NUMERIC_2 0x202 587 #define KEY_NUMERIC_2 0x202
588 #define KEY_NUMERIC_3 0x203 588 #define KEY_NUMERIC_3 0x203
589 #define KEY_NUMERIC_4 0x204 589 #define KEY_NUMERIC_4 0x204
590 #define KEY_NUMERIC_5 0x205 590 #define KEY_NUMERIC_5 0x205
591 #define KEY_NUMERIC_6 0x206 591 #define KEY_NUMERIC_6 0x206
592 #define KEY_NUMERIC_7 0x207 592 #define KEY_NUMERIC_7 0x207
593 #define KEY_NUMERIC_8 0x208 593 #define KEY_NUMERIC_8 0x208
594 #define KEY_NUMERIC_9 0x209 594 #define KEY_NUMERIC_9 0x209
595 #define KEY_NUMERIC_STAR 0x20a 595 #define KEY_NUMERIC_STAR 0x20a
596 #define KEY_NUMERIC_POUND 0x20b 596 #define KEY_NUMERIC_POUND 0x20b
597 597
598 #define KEY_CAMERA_FOCUS 0x210 598 #define KEY_CAMERA_FOCUS 0x210
599 599
600 /* We avoid low common keys in module aliases so they don't get huge. */ 600 /* We avoid low common keys in module aliases so they don't get huge. */
601 #define KEY_MIN_INTERESTING KEY_MUTE 601 #define KEY_MIN_INTERESTING KEY_MUTE
602 #define KEY_MAX 0x2ff 602 #define KEY_MAX 0x2ff
603 #define KEY_CNT (KEY_MAX+1) 603 #define KEY_CNT (KEY_MAX+1)
604 604
605 /* 605 /*
606 * Relative axes 606 * Relative axes
607 */ 607 */
608 608
609 #define REL_X 0x00 609 #define REL_X 0x00
610 #define REL_Y 0x01 610 #define REL_Y 0x01
611 #define REL_Z 0x02 611 #define REL_Z 0x02
612 #define REL_RX 0x03 612 #define REL_RX 0x03
613 #define REL_RY 0x04 613 #define REL_RY 0x04
614 #define REL_RZ 0x05 614 #define REL_RZ 0x05
615 #define REL_HWHEEL 0x06 615 #define REL_HWHEEL 0x06
616 #define REL_DIAL 0x07 616 #define REL_DIAL 0x07
617 #define REL_WHEEL 0x08 617 #define REL_WHEEL 0x08
618 #define REL_MISC 0x09 618 #define REL_MISC 0x09
619 #define REL_MAX 0x0f 619 #define REL_MAX 0x0f
620 #define REL_CNT (REL_MAX+1) 620 #define REL_CNT (REL_MAX+1)
621 621
622 /* 622 /*
623 * Absolute axes 623 * Absolute axes
624 */ 624 */
625 625
626 #define ABS_X 0x00 626 #define ABS_X 0x00
627 #define ABS_Y 0x01 627 #define ABS_Y 0x01
628 #define ABS_Z 0x02 628 #define ABS_Z 0x02
629 #define ABS_RX 0x03 629 #define ABS_RX 0x03
630 #define ABS_RY 0x04 630 #define ABS_RY 0x04
631 #define ABS_RZ 0x05 631 #define ABS_RZ 0x05
632 #define ABS_THROTTLE 0x06 632 #define ABS_THROTTLE 0x06
633 #define ABS_RUDDER 0x07 633 #define ABS_RUDDER 0x07
634 #define ABS_WHEEL 0x08 634 #define ABS_WHEEL 0x08
635 #define ABS_GAS 0x09 635 #define ABS_GAS 0x09
636 #define ABS_BRAKE 0x0a 636 #define ABS_BRAKE 0x0a
637 #define ABS_HAT0X 0x10 637 #define ABS_HAT0X 0x10
638 #define ABS_HAT0Y 0x11 638 #define ABS_HAT0Y 0x11
639 #define ABS_HAT1X 0x12 639 #define ABS_HAT1X 0x12
640 #define ABS_HAT1Y 0x13 640 #define ABS_HAT1Y 0x13
641 #define ABS_HAT2X 0x14 641 #define ABS_HAT2X 0x14
642 #define ABS_HAT2Y 0x15 642 #define ABS_HAT2Y 0x15
643 #define ABS_HAT3X 0x16 643 #define ABS_HAT3X 0x16
644 #define ABS_HAT3Y 0x17 644 #define ABS_HAT3Y 0x17
645 #define ABS_PRESSURE 0x18 645 #define ABS_PRESSURE 0x18
646 #define ABS_DISTANCE 0x19 646 #define ABS_DISTANCE 0x19
647 #define ABS_TILT_X 0x1a 647 #define ABS_TILT_X 0x1a
648 #define ABS_TILT_Y 0x1b 648 #define ABS_TILT_Y 0x1b
649 #define ABS_TOOL_WIDTH 0x1c 649 #define ABS_TOOL_WIDTH 0x1c
650 #define ABS_VOLUME 0x20 650 #define ABS_VOLUME 0x20
651 #define ABS_MISC 0x28 651 #define ABS_MISC 0x28
652 652
653 #define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ 653 #define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
654 #define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */ 654 #define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
655 #define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ 655 #define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
656 #define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ 656 #define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
657 #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ 657 #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
658 #define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */ 658 #define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
659 #define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */ 659 #define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
660 #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */ 660 #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
661 #define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ 661 #define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
662 #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ 662 #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
663 #define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
663 664
664 #define ABS_MAX 0x3f 665 #define ABS_MAX 0x3f
665 #define ABS_CNT (ABS_MAX+1) 666 #define ABS_CNT (ABS_MAX+1)
666 667
667 /* 668 /*
668 * Switch events 669 * Switch events
669 */ 670 */
670 671
671 #define SW_LID 0x00 /* set = lid shut */ 672 #define SW_LID 0x00 /* set = lid shut */
672 #define SW_TABLET_MODE 0x01 /* set = tablet mode */ 673 #define SW_TABLET_MODE 0x01 /* set = tablet mode */
673 #define SW_HEADPHONE_INSERT 0x02 /* set = inserted */ 674 #define SW_HEADPHONE_INSERT 0x02 /* set = inserted */
674 #define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any" 675 #define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any"
675 set = radio enabled */ 676 set = radio enabled */
676 #define SW_RADIO SW_RFKILL_ALL /* deprecated */ 677 #define SW_RADIO SW_RFKILL_ALL /* deprecated */
677 #define SW_MICROPHONE_INSERT 0x04 /* set = inserted */ 678 #define SW_MICROPHONE_INSERT 0x04 /* set = inserted */
678 #define SW_DOCK 0x05 /* set = plugged into dock */ 679 #define SW_DOCK 0x05 /* set = plugged into dock */
679 #define SW_LINEOUT_INSERT 0x06 /* set = inserted */ 680 #define SW_LINEOUT_INSERT 0x06 /* set = inserted */
680 #define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */ 681 #define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */
681 #define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */ 682 #define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */
682 #define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */ 683 #define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */
683 #define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */ 684 #define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */
684 #define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */ 685 #define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */
685 #define SW_MAX 0x0f 686 #define SW_MAX 0x0f
686 #define SW_CNT (SW_MAX+1) 687 #define SW_CNT (SW_MAX+1)
687 688
688 /* 689 /*
689 * Misc events 690 * Misc events
690 */ 691 */
691 692
692 #define MSC_SERIAL 0x00 693 #define MSC_SERIAL 0x00
693 #define MSC_PULSELED 0x01 694 #define MSC_PULSELED 0x01
694 #define MSC_GESTURE 0x02 695 #define MSC_GESTURE 0x02
695 #define MSC_RAW 0x03 696 #define MSC_RAW 0x03
696 #define MSC_SCAN 0x04 697 #define MSC_SCAN 0x04
697 #define MSC_MAX 0x07 698 #define MSC_MAX 0x07
698 #define MSC_CNT (MSC_MAX+1) 699 #define MSC_CNT (MSC_MAX+1)
699 700
700 /* 701 /*
701 * LEDs 702 * LEDs
702 */ 703 */
703 704
704 #define LED_NUML 0x00 705 #define LED_NUML 0x00
705 #define LED_CAPSL 0x01 706 #define LED_CAPSL 0x01
706 #define LED_SCROLLL 0x02 707 #define LED_SCROLLL 0x02
707 #define LED_COMPOSE 0x03 708 #define LED_COMPOSE 0x03
708 #define LED_KANA 0x04 709 #define LED_KANA 0x04
709 #define LED_SLEEP 0x05 710 #define LED_SLEEP 0x05
710 #define LED_SUSPEND 0x06 711 #define LED_SUSPEND 0x06
711 #define LED_MUTE 0x07 712 #define LED_MUTE 0x07
712 #define LED_MISC 0x08 713 #define LED_MISC 0x08
713 #define LED_MAIL 0x09 714 #define LED_MAIL 0x09
714 #define LED_CHARGING 0x0a 715 #define LED_CHARGING 0x0a
715 #define LED_MAX 0x0f 716 #define LED_MAX 0x0f
716 #define LED_CNT (LED_MAX+1) 717 #define LED_CNT (LED_MAX+1)
717 718
718 /* 719 /*
719 * Autorepeat values 720 * Autorepeat values
720 */ 721 */
721 722
722 #define REP_DELAY 0x00 723 #define REP_DELAY 0x00
723 #define REP_PERIOD 0x01 724 #define REP_PERIOD 0x01
724 #define REP_MAX 0x01 725 #define REP_MAX 0x01
725 726
726 /* 727 /*
727 * Sounds 728 * Sounds
728 */ 729 */
729 730
730 #define SND_CLICK 0x00 731 #define SND_CLICK 0x00
731 #define SND_BELL 0x01 732 #define SND_BELL 0x01
732 #define SND_TONE 0x02 733 #define SND_TONE 0x02
733 #define SND_MAX 0x07 734 #define SND_MAX 0x07
734 #define SND_CNT (SND_MAX+1) 735 #define SND_CNT (SND_MAX+1)
735 736
736 /* 737 /*
737 * IDs. 738 * IDs.
738 */ 739 */
739 740
740 #define ID_BUS 0 741 #define ID_BUS 0
741 #define ID_VENDOR 1 742 #define ID_VENDOR 1
742 #define ID_PRODUCT 2 743 #define ID_PRODUCT 2
743 #define ID_VERSION 3 744 #define ID_VERSION 3
744 745
745 #define BUS_PCI 0x01 746 #define BUS_PCI 0x01
746 #define BUS_ISAPNP 0x02 747 #define BUS_ISAPNP 0x02
747 #define BUS_USB 0x03 748 #define BUS_USB 0x03
748 #define BUS_HIL 0x04 749 #define BUS_HIL 0x04
749 #define BUS_BLUETOOTH 0x05 750 #define BUS_BLUETOOTH 0x05
750 #define BUS_VIRTUAL 0x06 751 #define BUS_VIRTUAL 0x06
751 752
752 #define BUS_ISA 0x10 753 #define BUS_ISA 0x10
753 #define BUS_I8042 0x11 754 #define BUS_I8042 0x11
754 #define BUS_XTKBD 0x12 755 #define BUS_XTKBD 0x12
755 #define BUS_RS232 0x13 756 #define BUS_RS232 0x13
756 #define BUS_GAMEPORT 0x14 757 #define BUS_GAMEPORT 0x14
757 #define BUS_PARPORT 0x15 758 #define BUS_PARPORT 0x15
758 #define BUS_AMIGA 0x16 759 #define BUS_AMIGA 0x16
759 #define BUS_ADB 0x17 760 #define BUS_ADB 0x17
760 #define BUS_I2C 0x18 761 #define BUS_I2C 0x18
761 #define BUS_HOST 0x19 762 #define BUS_HOST 0x19
762 #define BUS_GSC 0x1A 763 #define BUS_GSC 0x1A
763 #define BUS_ATARI 0x1B 764 #define BUS_ATARI 0x1B
764 765
765 /* 766 /*
766 * MT_TOOL types 767 * MT_TOOL types
767 */ 768 */
768 #define MT_TOOL_FINGER 0 769 #define MT_TOOL_FINGER 0
769 #define MT_TOOL_PEN 1 770 #define MT_TOOL_PEN 1
770 771
771 /* 772 /*
772 * Values describing the status of a force-feedback effect 773 * Values describing the status of a force-feedback effect
773 */ 774 */
774 #define FF_STATUS_STOPPED 0x00 775 #define FF_STATUS_STOPPED 0x00
775 #define FF_STATUS_PLAYING 0x01 776 #define FF_STATUS_PLAYING 0x01
776 #define FF_STATUS_MAX 0x01 777 #define FF_STATUS_MAX 0x01
777 778
778 /* 779 /*
779 * Structures used in ioctls to upload effects to a device 780 * Structures used in ioctls to upload effects to a device
780 * They are pieces of a bigger structure (called ff_effect) 781 * They are pieces of a bigger structure (called ff_effect)
781 */ 782 */
782 783
783 /* 784 /*
784 * All duration values are expressed in ms. Values above 32767 ms (0x7fff) 785 * All duration values are expressed in ms. Values above 32767 ms (0x7fff)
785 * should not be used and have unspecified results. 786 * should not be used and have unspecified results.
786 */ 787 */
787 788
788 /** 789 /**
789 * struct ff_replay - defines scheduling of the force-feedback effect 790 * struct ff_replay - defines scheduling of the force-feedback effect
790 * @length: duration of the effect 791 * @length: duration of the effect
791 * @delay: delay before effect should start playing 792 * @delay: delay before effect should start playing
792 */ 793 */
793 struct ff_replay { 794 struct ff_replay {
794 __u16 length; 795 __u16 length;
795 __u16 delay; 796 __u16 delay;
796 }; 797 };
797 798
798 /** 799 /**
799 * struct ff_trigger - defines what triggers the force-feedback effect 800 * struct ff_trigger - defines what triggers the force-feedback effect
800 * @button: number of the button triggering the effect 801 * @button: number of the button triggering the effect
801 * @interval: controls how soon the effect can be re-triggered 802 * @interval: controls how soon the effect can be re-triggered
802 */ 803 */
803 struct ff_trigger { 804 struct ff_trigger {
804 __u16 button; 805 __u16 button;
805 __u16 interval; 806 __u16 interval;
806 }; 807 };
807 808
808 /** 809 /**
809 * struct ff_envelope - generic force-feedback effect envelope 810 * struct ff_envelope - generic force-feedback effect envelope
810 * @attack_length: duration of the attack (ms) 811 * @attack_length: duration of the attack (ms)
811 * @attack_level: level at the beginning of the attack 812 * @attack_level: level at the beginning of the attack
812 * @fade_length: duration of fade (ms) 813 * @fade_length: duration of fade (ms)
813 * @fade_level: level at the end of fade 814 * @fade_level: level at the end of fade
814 * 815 *
815 * The @attack_level and @fade_level are absolute values; when applying 816 * The @attack_level and @fade_level are absolute values; when applying
816 * envelope force-feedback core will convert to positive/negative 817 * envelope force-feedback core will convert to positive/negative
817 * value based on polarity of the default level of the effect. 818 * value based on polarity of the default level of the effect.
818 * Valid range for the attack and fade levels is 0x0000 - 0x7fff 819 * Valid range for the attack and fade levels is 0x0000 - 0x7fff
819 */ 820 */
820 struct ff_envelope { 821 struct ff_envelope {
821 __u16 attack_length; 822 __u16 attack_length;
822 __u16 attack_level; 823 __u16 attack_level;
823 __u16 fade_length; 824 __u16 fade_length;
824 __u16 fade_level; 825 __u16 fade_level;
825 }; 826 };
826 827
827 /** 828 /**
828 * struct ff_constant_effect - defines parameters of a constant force-feedback effect 829 * struct ff_constant_effect - defines parameters of a constant force-feedback effect
829 * @level: strength of the effect; may be negative 830 * @level: strength of the effect; may be negative
830 * @envelope: envelope data 831 * @envelope: envelope data
831 */ 832 */
832 struct ff_constant_effect { 833 struct ff_constant_effect {
833 __s16 level; 834 __s16 level;
834 struct ff_envelope envelope; 835 struct ff_envelope envelope;
835 }; 836 };
836 837
837 /** 838 /**
838 * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect 839 * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
839 * @start_level: beginning strength of the effect; may be negative 840 * @start_level: beginning strength of the effect; may be negative
840 * @end_level: final strength of the effect; may be negative 841 * @end_level: final strength of the effect; may be negative
841 * @envelope: envelope data 842 * @envelope: envelope data
842 */ 843 */
843 struct ff_ramp_effect { 844 struct ff_ramp_effect {
844 __s16 start_level; 845 __s16 start_level;
845 __s16 end_level; 846 __s16 end_level;
846 struct ff_envelope envelope; 847 struct ff_envelope envelope;
847 }; 848 };
848 849
849 /** 850 /**
850 * struct ff_condition_effect - defines a spring or friction force-feedback effect 851 * struct ff_condition_effect - defines a spring or friction force-feedback effect
851 * @right_saturation: maximum level when joystick moved all way to the right 852 * @right_saturation: maximum level when joystick moved all way to the right
852 * @left_saturation: same for the left side 853 * @left_saturation: same for the left side
853 * @right_coeff: controls how fast the force grows when the joystick moves 854 * @right_coeff: controls how fast the force grows when the joystick moves
854 * to the right 855 * to the right
855 * @left_coeff: same for the left side 856 * @left_coeff: same for the left side
856 * @deadband: size of the dead zone, where no force is produced 857 * @deadband: size of the dead zone, where no force is produced
857 * @center: position of the dead zone 858 * @center: position of the dead zone
858 */ 859 */
859 struct ff_condition_effect { 860 struct ff_condition_effect {
860 __u16 right_saturation; 861 __u16 right_saturation;
861 __u16 left_saturation; 862 __u16 left_saturation;
862 863
863 __s16 right_coeff; 864 __s16 right_coeff;
864 __s16 left_coeff; 865 __s16 left_coeff;
865 866
866 __u16 deadband; 867 __u16 deadband;
867 __s16 center; 868 __s16 center;
868 }; 869 };
869 870
870 /** 871 /**
871 * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect 872 * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
872 * @waveform: kind of the effect (wave) 873 * @waveform: kind of the effect (wave)
873 * @period: period of the wave (ms) 874 * @period: period of the wave (ms)
874 * @magnitude: peak value 875 * @magnitude: peak value
875 * @offset: mean value of the wave (roughly) 876 * @offset: mean value of the wave (roughly)
876 * @phase: 'horizontal' shift 877 * @phase: 'horizontal' shift
877 * @envelope: envelope data 878 * @envelope: envelope data
878 * @custom_len: number of samples (FF_CUSTOM only) 879 * @custom_len: number of samples (FF_CUSTOM only)
879 * @custom_data: buffer of samples (FF_CUSTOM only) 880 * @custom_data: buffer of samples (FF_CUSTOM only)
880 * 881 *
881 * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP, 882 * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP,
882 * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined 883 * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined
883 * for the time being as no driver supports it yet. 884 * for the time being as no driver supports it yet.
884 * 885 *
885 * Note: the data pointed by custom_data is copied by the driver. 886 * Note: the data pointed by custom_data is copied by the driver.
886 * You can therefore dispose of the memory after the upload/update. 887 * You can therefore dispose of the memory after the upload/update.
887 */ 888 */
888 struct ff_periodic_effect { 889 struct ff_periodic_effect {
889 __u16 waveform; 890 __u16 waveform;
890 __u16 period; 891 __u16 period;
891 __s16 magnitude; 892 __s16 magnitude;
892 __s16 offset; 893 __s16 offset;
893 __u16 phase; 894 __u16 phase;
894 895
895 struct ff_envelope envelope; 896 struct ff_envelope envelope;
896 897
897 __u32 custom_len; 898 __u32 custom_len;
898 __s16 __user *custom_data; 899 __s16 __user *custom_data;
899 }; 900 };
900 901
901 /** 902 /**
902 * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect 903 * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
903 * @strong_magnitude: magnitude of the heavy motor 904 * @strong_magnitude: magnitude of the heavy motor
904 * @weak_magnitude: magnitude of the light one 905 * @weak_magnitude: magnitude of the light one
905 * 906 *
906 * Some rumble pads have two motors of different weight. Strong_magnitude 907 * Some rumble pads have two motors of different weight. Strong_magnitude
907 * represents the magnitude of the vibration generated by the heavy one. 908 * represents the magnitude of the vibration generated by the heavy one.
908 */ 909 */
909 struct ff_rumble_effect { 910 struct ff_rumble_effect {
910 __u16 strong_magnitude; 911 __u16 strong_magnitude;
911 __u16 weak_magnitude; 912 __u16 weak_magnitude;
912 }; 913 };
913 914
914 /** 915 /**
915 * struct ff_effect - defines force feedback effect 916 * struct ff_effect - defines force feedback effect
916 * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING, 917 * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING,
917 * FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM) 918 * FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM)
918 * @id: an unique id assigned to an effect 919 * @id: an unique id assigned to an effect
919 * @direction: direction of the effect 920 * @direction: direction of the effect
920 * @trigger: trigger conditions (struct ff_trigger) 921 * @trigger: trigger conditions (struct ff_trigger)
921 * @replay: scheduling of the effect (struct ff_replay) 922 * @replay: scheduling of the effect (struct ff_replay)
922 * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect, 923 * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect,
923 * ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further 924 * ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further
924 * defining effect parameters 925 * defining effect parameters
925 * 926 *
926 * This structure is sent through ioctl from the application to the driver. 927 * This structure is sent through ioctl from the application to the driver.
927 * To create a new effect application should set its @id to -1; the kernel 928 * To create a new effect application should set its @id to -1; the kernel
928 * will return assigned @id which can later be used to update or delete 929 * will return assigned @id which can later be used to update or delete
929 * this effect. 930 * this effect.
930 * 931 *
931 * Direction of the effect is encoded as follows: 932 * Direction of the effect is encoded as follows:
932 * 0 deg -> 0x0000 (down) 933 * 0 deg -> 0x0000 (down)
933 * 90 deg -> 0x4000 (left) 934 * 90 deg -> 0x4000 (left)
934 * 180 deg -> 0x8000 (up) 935 * 180 deg -> 0x8000 (up)
935 * 270 deg -> 0xC000 (right) 936 * 270 deg -> 0xC000 (right)
936 */ 937 */
937 struct ff_effect { 938 struct ff_effect {
938 __u16 type; 939 __u16 type;
939 __s16 id; 940 __s16 id;
940 __u16 direction; 941 __u16 direction;
941 struct ff_trigger trigger; 942 struct ff_trigger trigger;
942 struct ff_replay replay; 943 struct ff_replay replay;
943 944
944 union { 945 union {
945 struct ff_constant_effect constant; 946 struct ff_constant_effect constant;
946 struct ff_ramp_effect ramp; 947 struct ff_ramp_effect ramp;
947 struct ff_periodic_effect periodic; 948 struct ff_periodic_effect periodic;
948 struct ff_condition_effect condition[2]; /* One for each axis */ 949 struct ff_condition_effect condition[2]; /* One for each axis */
949 struct ff_rumble_effect rumble; 950 struct ff_rumble_effect rumble;
950 } u; 951 } u;
951 }; 952 };
952 953
953 /* 954 /*
954 * Force feedback effect types 955 * Force feedback effect types
955 */ 956 */
956 957
957 #define FF_RUMBLE 0x50 958 #define FF_RUMBLE 0x50
958 #define FF_PERIODIC 0x51 959 #define FF_PERIODIC 0x51
959 #define FF_CONSTANT 0x52 960 #define FF_CONSTANT 0x52
960 #define FF_SPRING 0x53 961 #define FF_SPRING 0x53
961 #define FF_FRICTION 0x54 962 #define FF_FRICTION 0x54
962 #define FF_DAMPER 0x55 963 #define FF_DAMPER 0x55
963 #define FF_INERTIA 0x56 964 #define FF_INERTIA 0x56
964 #define FF_RAMP 0x57 965 #define FF_RAMP 0x57
965 966
966 #define FF_EFFECT_MIN FF_RUMBLE 967 #define FF_EFFECT_MIN FF_RUMBLE
967 #define FF_EFFECT_MAX FF_RAMP 968 #define FF_EFFECT_MAX FF_RAMP
968 969
969 /* 970 /*
970 * Force feedback periodic effect types 971 * Force feedback periodic effect types
971 */ 972 */
972 973
973 #define FF_SQUARE 0x58 974 #define FF_SQUARE 0x58
974 #define FF_TRIANGLE 0x59 975 #define FF_TRIANGLE 0x59
975 #define FF_SINE 0x5a 976 #define FF_SINE 0x5a
976 #define FF_SAW_UP 0x5b 977 #define FF_SAW_UP 0x5b
977 #define FF_SAW_DOWN 0x5c 978 #define FF_SAW_DOWN 0x5c
978 #define FF_CUSTOM 0x5d 979 #define FF_CUSTOM 0x5d
979 980
980 #define FF_WAVEFORM_MIN FF_SQUARE 981 #define FF_WAVEFORM_MIN FF_SQUARE
981 #define FF_WAVEFORM_MAX FF_CUSTOM 982 #define FF_WAVEFORM_MAX FF_CUSTOM
982 983
983 /* 984 /*
984 * Set ff device properties 985 * Set ff device properties
985 */ 986 */
986 987
987 #define FF_GAIN 0x60 988 #define FF_GAIN 0x60
988 #define FF_AUTOCENTER 0x61 989 #define FF_AUTOCENTER 0x61
989 990
990 #define FF_MAX 0x7f 991 #define FF_MAX 0x7f
991 #define FF_CNT (FF_MAX+1) 992 #define FF_CNT (FF_MAX+1)
992 993
993 #ifdef __KERNEL__ 994 #ifdef __KERNEL__
994 995
995 /* 996 /*
996 * In-kernel definitions. 997 * In-kernel definitions.
997 */ 998 */
998 999
999 #include <linux/device.h> 1000 #include <linux/device.h>
1000 #include <linux/fs.h> 1001 #include <linux/fs.h>
1001 #include <linux/timer.h> 1002 #include <linux/timer.h>
1002 #include <linux/mod_devicetable.h> 1003 #include <linux/mod_devicetable.h>
1003 1004
1004 /** 1005 /**
1005 * struct input_dev - represents an input device 1006 * struct input_dev - represents an input device
1006 * @name: name of the device 1007 * @name: name of the device
1007 * @phys: physical path to the device in the system hierarchy 1008 * @phys: physical path to the device in the system hierarchy
1008 * @uniq: unique identification code for the device (if device has it) 1009 * @uniq: unique identification code for the device (if device has it)
1009 * @id: id of the device (struct input_id) 1010 * @id: id of the device (struct input_id)
1010 * @evbit: bitmap of types of events supported by the device (EV_KEY, 1011 * @evbit: bitmap of types of events supported by the device (EV_KEY,
1011 * EV_REL, etc.) 1012 * EV_REL, etc.)
1012 * @keybit: bitmap of keys/buttons this device has 1013 * @keybit: bitmap of keys/buttons this device has
1013 * @relbit: bitmap of relative axes for the device 1014 * @relbit: bitmap of relative axes for the device
1014 * @absbit: bitmap of absolute axes for the device 1015 * @absbit: bitmap of absolute axes for the device
1015 * @mscbit: bitmap of miscellaneous events supported by the device 1016 * @mscbit: bitmap of miscellaneous events supported by the device
1016 * @ledbit: bitmap of leds present on the device 1017 * @ledbit: bitmap of leds present on the device
1017 * @sndbit: bitmap of sound effects supported by the device 1018 * @sndbit: bitmap of sound effects supported by the device
1018 * @ffbit: bitmap of force feedback effects supported by the device 1019 * @ffbit: bitmap of force feedback effects supported by the device
1019 * @swbit: bitmap of switches present on the device 1020 * @swbit: bitmap of switches present on the device
1020 * @keycodemax: size of keycode table 1021 * @keycodemax: size of keycode table
1021 * @keycodesize: size of elements in keycode table 1022 * @keycodesize: size of elements in keycode table
1022 * @keycode: map of scancodes to keycodes for this device 1023 * @keycode: map of scancodes to keycodes for this device
1023 * @setkeycode: optional method to alter current keymap, used to implement 1024 * @setkeycode: optional method to alter current keymap, used to implement
1024 * sparse keymaps. If not supplied default mechanism will be used. 1025 * sparse keymaps. If not supplied default mechanism will be used.
1025 * The method is being called while holding event_lock and thus must 1026 * The method is being called while holding event_lock and thus must
1026 * not sleep 1027 * not sleep
1027 * @getkeycode: optional method to retrieve current keymap. If not supplied 1028 * @getkeycode: optional method to retrieve current keymap. If not supplied
1028 * default mechanism will be used. The method is being called while 1029 * default mechanism will be used. The method is being called while
1029 * holding event_lock and thus must not sleep 1030 * holding event_lock and thus must not sleep
1030 * @ff: force feedback structure associated with the device if device 1031 * @ff: force feedback structure associated with the device if device
1031 * supports force feedback effects 1032 * supports force feedback effects
1032 * @repeat_key: stores key code of the last key pressed; used to implement 1033 * @repeat_key: stores key code of the last key pressed; used to implement
1033 * software autorepeat 1034 * software autorepeat
1034 * @timer: timer for software autorepeat 1035 * @timer: timer for software autorepeat
1035 * @sync: set to 1 when there were no new events since last EV_SYNC 1036 * @sync: set to 1 when there were no new events since last EV_SYNC
1036 * @abs: current values for reports from absolute axes 1037 * @abs: current values for reports from absolute axes
1037 * @rep: current values for autorepeat parameters (delay, rate) 1038 * @rep: current values for autorepeat parameters (delay, rate)
1038 * @key: reflects current state of device's keys/buttons 1039 * @key: reflects current state of device's keys/buttons
1039 * @led: reflects current state of device's LEDs 1040 * @led: reflects current state of device's LEDs
1040 * @snd: reflects current state of sound effects 1041 * @snd: reflects current state of sound effects
1041 * @sw: reflects current state of device's switches 1042 * @sw: reflects current state of device's switches
1042 * @absmax: maximum values for events coming from absolute axes 1043 * @absmax: maximum values for events coming from absolute axes
1043 * @absmin: minimum values for events coming from absolute axes 1044 * @absmin: minimum values for events coming from absolute axes
1044 * @absfuzz: describes noisiness for axes 1045 * @absfuzz: describes noisiness for axes
1045 * @absflat: size of the center flat position (used by joydev) 1046 * @absflat: size of the center flat position (used by joydev)
1046 * @absres: resolution used for events coming form absolute axes 1047 * @absres: resolution used for events coming form absolute axes
1047 * @open: this method is called when the very first user calls 1048 * @open: this method is called when the very first user calls
1048 * input_open_device(). The driver must prepare the device 1049 * input_open_device(). The driver must prepare the device
1049 * to start generating events (start polling thread, 1050 * to start generating events (start polling thread,
1050 * request an IRQ, submit URB, etc.) 1051 * request an IRQ, submit URB, etc.)
1051 * @close: this method is called when the very last user calls 1052 * @close: this method is called when the very last user calls
1052 * input_close_device(). 1053 * input_close_device().
1053 * @flush: purges the device. Most commonly used to get rid of force 1054 * @flush: purges the device. Most commonly used to get rid of force
1054 * feedback effects loaded into the device when disconnecting 1055 * feedback effects loaded into the device when disconnecting
1055 * from it 1056 * from it
1056 * @event: event handler for events sent _to_ the device, like EV_LED 1057 * @event: event handler for events sent _to_ the device, like EV_LED
1057 * or EV_SND. The device is expected to carry out the requested 1058 * or EV_SND. The device is expected to carry out the requested
1058 * action (turn on a LED, play sound, etc.) The call is protected 1059 * action (turn on a LED, play sound, etc.) The call is protected
1059 * by @event_lock and must not sleep 1060 * by @event_lock and must not sleep
1060 * @grab: input handle that currently has the device grabbed (via 1061 * @grab: input handle that currently has the device grabbed (via
1061 * EVIOCGRAB ioctl). When a handle grabs a device it becomes sole 1062 * EVIOCGRAB ioctl). When a handle grabs a device it becomes sole
1062 * recipient for all input events coming from the device 1063 * recipient for all input events coming from the device
1063 * @event_lock: this spinlock is is taken when input core receives 1064 * @event_lock: this spinlock is is taken when input core receives
1064 * and processes a new event for the device (in input_event()). 1065 * and processes a new event for the device (in input_event()).
1065 * Code that accesses and/or modifies parameters of a device 1066 * Code that accesses and/or modifies parameters of a device
1066 * (such as keymap or absmin, absmax, absfuzz, etc.) after device 1067 * (such as keymap or absmin, absmax, absfuzz, etc.) after device
1067 * has been registered with input core must take this lock. 1068 * has been registered with input core must take this lock.
1068 * @mutex: serializes calls to open(), close() and flush() methods 1069 * @mutex: serializes calls to open(), close() and flush() methods
1069 * @users: stores number of users (input handlers) that opened this 1070 * @users: stores number of users (input handlers) that opened this
1070 * device. It is used by input_open_device() and input_close_device() 1071 * device. It is used by input_open_device() and input_close_device()
1071 * to make sure that dev->open() is only called when the first 1072 * to make sure that dev->open() is only called when the first
1072 * user opens device and dev->close() is called when the very 1073 * user opens device and dev->close() is called when the very
1073 * last user closes the device 1074 * last user closes the device
1074 * @going_away: marks devices that are in a middle of unregistering and 1075 * @going_away: marks devices that are in a middle of unregistering and
1075 * causes input_open_device*() fail with -ENODEV. 1076 * causes input_open_device*() fail with -ENODEV.
1076 * @dev: driver model's view of this device 1077 * @dev: driver model's view of this device
1077 * @h_list: list of input handles associated with the device. When 1078 * @h_list: list of input handles associated with the device. When
1078 * accessing the list dev->mutex must be held 1079 * accessing the list dev->mutex must be held
1079 * @node: used to place the device onto input_dev_list 1080 * @node: used to place the device onto input_dev_list
1080 */ 1081 */
1081 struct input_dev { 1082 struct input_dev {
1082 const char *name; 1083 const char *name;
1083 const char *phys; 1084 const char *phys;
1084 const char *uniq; 1085 const char *uniq;
1085 struct input_id id; 1086 struct input_id id;
1086 1087
1087 unsigned long evbit[BITS_TO_LONGS(EV_CNT)]; 1088 unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
1088 unsigned long keybit[BITS_TO_LONGS(KEY_CNT)]; 1089 unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
1089 unsigned long relbit[BITS_TO_LONGS(REL_CNT)]; 1090 unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
1090 unsigned long absbit[BITS_TO_LONGS(ABS_CNT)]; 1091 unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
1091 unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)]; 1092 unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
1092 unsigned long ledbit[BITS_TO_LONGS(LED_CNT)]; 1093 unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
1093 unsigned long sndbit[BITS_TO_LONGS(SND_CNT)]; 1094 unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
1094 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)]; 1095 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
1095 unsigned long swbit[BITS_TO_LONGS(SW_CNT)]; 1096 unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
1096 1097
1097 unsigned int keycodemax; 1098 unsigned int keycodemax;
1098 unsigned int keycodesize; 1099 unsigned int keycodesize;
1099 void *keycode; 1100 void *keycode;
1100 int (*setkeycode)(struct input_dev *dev, int scancode, int keycode); 1101 int (*setkeycode)(struct input_dev *dev, int scancode, int keycode);
1101 int (*getkeycode)(struct input_dev *dev, int scancode, int *keycode); 1102 int (*getkeycode)(struct input_dev *dev, int scancode, int *keycode);
1102 1103
1103 struct ff_device *ff; 1104 struct ff_device *ff;
1104 1105
1105 unsigned int repeat_key; 1106 unsigned int repeat_key;
1106 struct timer_list timer; 1107 struct timer_list timer;
1107 1108
1108 int sync; 1109 int sync;
1109 1110
1110 int abs[ABS_MAX + 1]; 1111 int abs[ABS_MAX + 1];
1111 int rep[REP_MAX + 1]; 1112 int rep[REP_MAX + 1];
1112 1113
1113 unsigned long key[BITS_TO_LONGS(KEY_CNT)]; 1114 unsigned long key[BITS_TO_LONGS(KEY_CNT)];
1114 unsigned long led[BITS_TO_LONGS(LED_CNT)]; 1115 unsigned long led[BITS_TO_LONGS(LED_CNT)];
1115 unsigned long snd[BITS_TO_LONGS(SND_CNT)]; 1116 unsigned long snd[BITS_TO_LONGS(SND_CNT)];
1116 unsigned long sw[BITS_TO_LONGS(SW_CNT)]; 1117 unsigned long sw[BITS_TO_LONGS(SW_CNT)];
1117 1118
1118 int absmax[ABS_MAX + 1]; 1119 int absmax[ABS_MAX + 1];
1119 int absmin[ABS_MAX + 1]; 1120 int absmin[ABS_MAX + 1];
1120 int absfuzz[ABS_MAX + 1]; 1121 int absfuzz[ABS_MAX + 1];
1121 int absflat[ABS_MAX + 1]; 1122 int absflat[ABS_MAX + 1];
1122 int absres[ABS_MAX + 1]; 1123 int absres[ABS_MAX + 1];
1123 1124
1124 int (*open)(struct input_dev *dev); 1125 int (*open)(struct input_dev *dev);
1125 void (*close)(struct input_dev *dev); 1126 void (*close)(struct input_dev *dev);
1126 int (*flush)(struct input_dev *dev, struct file *file); 1127 int (*flush)(struct input_dev *dev, struct file *file);
1127 int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); 1128 int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1128 1129
1129 struct input_handle *grab; 1130 struct input_handle *grab;
1130 1131
1131 spinlock_t event_lock; 1132 spinlock_t event_lock;
1132 struct mutex mutex; 1133 struct mutex mutex;
1133 1134
1134 unsigned int users; 1135 unsigned int users;
1135 bool going_away; 1136 bool going_away;
1136 1137
1137 struct device dev; 1138 struct device dev;
1138 1139
1139 struct list_head h_list; 1140 struct list_head h_list;
1140 struct list_head node; 1141 struct list_head node;
1141 }; 1142 };
1142 #define to_input_dev(d) container_of(d, struct input_dev, dev) 1143 #define to_input_dev(d) container_of(d, struct input_dev, dev)
1143 1144
1144 /* 1145 /*
1145 * Verify that we are in sync with input_device_id mod_devicetable.h #defines 1146 * Verify that we are in sync with input_device_id mod_devicetable.h #defines
1146 */ 1147 */
1147 1148
1148 #if EV_MAX != INPUT_DEVICE_ID_EV_MAX 1149 #if EV_MAX != INPUT_DEVICE_ID_EV_MAX
1149 #error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match" 1150 #error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
1150 #endif 1151 #endif
1151 1152
1152 #if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING 1153 #if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
1153 #error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match" 1154 #error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
1154 #endif 1155 #endif
1155 1156
1156 #if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX 1157 #if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
1157 #error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match" 1158 #error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
1158 #endif 1159 #endif
1159 1160
1160 #if REL_MAX != INPUT_DEVICE_ID_REL_MAX 1161 #if REL_MAX != INPUT_DEVICE_ID_REL_MAX
1161 #error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match" 1162 #error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
1162 #endif 1163 #endif
1163 1164
1164 #if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX 1165 #if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
1165 #error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match" 1166 #error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
1166 #endif 1167 #endif
1167 1168
1168 #if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX 1169 #if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
1169 #error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match" 1170 #error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
1170 #endif 1171 #endif
1171 1172
1172 #if LED_MAX != INPUT_DEVICE_ID_LED_MAX 1173 #if LED_MAX != INPUT_DEVICE_ID_LED_MAX
1173 #error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match" 1174 #error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
1174 #endif 1175 #endif
1175 1176
1176 #if SND_MAX != INPUT_DEVICE_ID_SND_MAX 1177 #if SND_MAX != INPUT_DEVICE_ID_SND_MAX
1177 #error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match" 1178 #error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
1178 #endif 1179 #endif
1179 1180
1180 #if FF_MAX != INPUT_DEVICE_ID_FF_MAX 1181 #if FF_MAX != INPUT_DEVICE_ID_FF_MAX
1181 #error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match" 1182 #error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
1182 #endif 1183 #endif
1183 1184
1184 #if SW_MAX != INPUT_DEVICE_ID_SW_MAX 1185 #if SW_MAX != INPUT_DEVICE_ID_SW_MAX
1185 #error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match" 1186 #error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
1186 #endif 1187 #endif
1187 1188
1188 #define INPUT_DEVICE_ID_MATCH_DEVICE \ 1189 #define INPUT_DEVICE_ID_MATCH_DEVICE \
1189 (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT) 1190 (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
1190 #define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \ 1191 #define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
1191 (INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION) 1192 (INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)
1192 1193
1193 struct input_handle; 1194 struct input_handle;
1194 1195
1195 /** 1196 /**
1196 * struct input_handler - implements one of interfaces for input devices 1197 * struct input_handler - implements one of interfaces for input devices
1197 * @private: driver-specific data 1198 * @private: driver-specific data
1198 * @event: event handler. This method is being called by input core with 1199 * @event: event handler. This method is being called by input core with
1199 * interrupts disabled and dev->event_lock spinlock held and so 1200 * interrupts disabled and dev->event_lock spinlock held and so
1200 * it may not sleep 1201 * it may not sleep
1201 * @connect: called when attaching a handler to an input device 1202 * @connect: called when attaching a handler to an input device
1202 * @disconnect: disconnects a handler from input device 1203 * @disconnect: disconnects a handler from input device
1203 * @start: starts handler for given handle. This function is called by 1204 * @start: starts handler for given handle. This function is called by
1204 * input core right after connect() method and also when a process 1205 * input core right after connect() method and also when a process
1205 * that "grabbed" a device releases it 1206 * that "grabbed" a device releases it
1206 * @fops: file operations this driver implements 1207 * @fops: file operations this driver implements
1207 * @minor: beginning of range of 32 minors for devices this driver 1208 * @minor: beginning of range of 32 minors for devices this driver
1208 * can provide 1209 * can provide
1209 * @name: name of the handler, to be shown in /proc/bus/input/handlers 1210 * @name: name of the handler, to be shown in /proc/bus/input/handlers
1210 * @id_table: pointer to a table of input_device_ids this driver can 1211 * @id_table: pointer to a table of input_device_ids this driver can
1211 * handle 1212 * handle
1212 * @blacklist: pointer to a table of input_device_ids this driver should 1213 * @blacklist: pointer to a table of input_device_ids this driver should
1213 * ignore even if they match @id_table 1214 * ignore even if they match @id_table
1214 * @h_list: list of input handles associated with the handler 1215 * @h_list: list of input handles associated with the handler
1215 * @node: for placing the driver onto input_handler_list 1216 * @node: for placing the driver onto input_handler_list
1216 * 1217 *
1217 * Input handlers attach to input devices and create input handles. There 1218 * Input handlers attach to input devices and create input handles. There
1218 * are likely several handlers attached to any given input device at the 1219 * are likely several handlers attached to any given input device at the
1219 * same time. All of them will get their copy of input event generated by 1220 * same time. All of them will get their copy of input event generated by
1220 * the device. 1221 * the device.
1221 * 1222 *
1222 * Note that input core serializes calls to connect() and disconnect() 1223 * Note that input core serializes calls to connect() and disconnect()
1223 * methods. 1224 * methods.
1224 */ 1225 */
1225 struct input_handler { 1226 struct input_handler {
1226 1227
1227 void *private; 1228 void *private;
1228 1229
1229 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value); 1230 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1230 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id); 1231 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
1231 void (*disconnect)(struct input_handle *handle); 1232 void (*disconnect)(struct input_handle *handle);
1232 void (*start)(struct input_handle *handle); 1233 void (*start)(struct input_handle *handle);
1233 1234
1234 const struct file_operations *fops; 1235 const struct file_operations *fops;
1235 int minor; 1236 int minor;
1236 const char *name; 1237 const char *name;
1237 1238
1238 const struct input_device_id *id_table; 1239 const struct input_device_id *id_table;
1239 const struct input_device_id *blacklist; 1240 const struct input_device_id *blacklist;
1240 1241
1241 struct list_head h_list; 1242 struct list_head h_list;
1242 struct list_head node; 1243 struct list_head node;
1243 }; 1244 };
1244 1245
1245 /** 1246 /**
1246 * struct input_handle - links input device with an input handler 1247 * struct input_handle - links input device with an input handler
1247 * @private: handler-specific data 1248 * @private: handler-specific data
1248 * @open: counter showing whether the handle is 'open', i.e. should deliver 1249 * @open: counter showing whether the handle is 'open', i.e. should deliver
1249 * events from its device 1250 * events from its device
1250 * @name: name given to the handle by handler that created it 1251 * @name: name given to the handle by handler that created it
1251 * @dev: input device the handle is attached to 1252 * @dev: input device the handle is attached to
1252 * @handler: handler that works with the device through this handle 1253 * @handler: handler that works with the device through this handle
1253 * @d_node: used to put the handle on device's list of attached handles 1254 * @d_node: used to put the handle on device's list of attached handles
1254 * @h_node: used to put the handle on handler's list of handles from which 1255 * @h_node: used to put the handle on handler's list of handles from which
1255 * it gets events 1256 * it gets events
1256 */ 1257 */
1257 struct input_handle { 1258 struct input_handle {
1258 1259
1259 void *private; 1260 void *private;
1260 1261
1261 int open; 1262 int open;
1262 const char *name; 1263 const char *name;
1263 1264
1264 struct input_dev *dev; 1265 struct input_dev *dev;
1265 struct input_handler *handler; 1266 struct input_handler *handler;
1266 1267
1267 struct list_head d_node; 1268 struct list_head d_node;
1268 struct list_head h_node; 1269 struct list_head h_node;
1269 }; 1270 };
1270 1271
1271 struct input_dev *input_allocate_device(void); 1272 struct input_dev *input_allocate_device(void);
1272 void input_free_device(struct input_dev *dev); 1273 void input_free_device(struct input_dev *dev);
1273 1274
1274 static inline struct input_dev *input_get_device(struct input_dev *dev) 1275 static inline struct input_dev *input_get_device(struct input_dev *dev)
1275 { 1276 {
1276 return dev ? to_input_dev(get_device(&dev->dev)) : NULL; 1277 return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
1277 } 1278 }
1278 1279
1279 static inline void input_put_device(struct input_dev *dev) 1280 static inline void input_put_device(struct input_dev *dev)
1280 { 1281 {
1281 if (dev) 1282 if (dev)
1282 put_device(&dev->dev); 1283 put_device(&dev->dev);
1283 } 1284 }
1284 1285
1285 static inline void *input_get_drvdata(struct input_dev *dev) 1286 static inline void *input_get_drvdata(struct input_dev *dev)
1286 { 1287 {
1287 return dev_get_drvdata(&dev->dev); 1288 return dev_get_drvdata(&dev->dev);
1288 } 1289 }
1289 1290
1290 static inline void input_set_drvdata(struct input_dev *dev, void *data) 1291 static inline void input_set_drvdata(struct input_dev *dev, void *data)
1291 { 1292 {
1292 dev_set_drvdata(&dev->dev, data); 1293 dev_set_drvdata(&dev->dev, data);
1293 } 1294 }
1294 1295
1295 int __must_check input_register_device(struct input_dev *); 1296 int __must_check input_register_device(struct input_dev *);
1296 void input_unregister_device(struct input_dev *); 1297 void input_unregister_device(struct input_dev *);
1297 1298
1298 int __must_check input_register_handler(struct input_handler *); 1299 int __must_check input_register_handler(struct input_handler *);
1299 void input_unregister_handler(struct input_handler *); 1300 void input_unregister_handler(struct input_handler *);
1300 1301
1301 int input_handler_for_each_handle(struct input_handler *, void *data, 1302 int input_handler_for_each_handle(struct input_handler *, void *data,
1302 int (*fn)(struct input_handle *, void *)); 1303 int (*fn)(struct input_handle *, void *));
1303 1304
1304 int input_register_handle(struct input_handle *); 1305 int input_register_handle(struct input_handle *);
1305 void input_unregister_handle(struct input_handle *); 1306 void input_unregister_handle(struct input_handle *);
1306 1307
1307 int input_grab_device(struct input_handle *); 1308 int input_grab_device(struct input_handle *);
1308 void input_release_device(struct input_handle *); 1309 void input_release_device(struct input_handle *);
1309 1310
1310 int input_open_device(struct input_handle *); 1311 int input_open_device(struct input_handle *);
1311 void input_close_device(struct input_handle *); 1312 void input_close_device(struct input_handle *);
1312 1313
1313 int input_flush_device(struct input_handle* handle, struct file* file); 1314 int input_flush_device(struct input_handle* handle, struct file* file);
1314 1315
1315 void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value); 1316 void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1316 void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value); 1317 void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1317 1318
1318 static inline void input_report_key(struct input_dev *dev, unsigned int code, int value) 1319 static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
1319 { 1320 {
1320 input_event(dev, EV_KEY, code, !!value); 1321 input_event(dev, EV_KEY, code, !!value);
1321 } 1322 }
1322 1323
1323 static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value) 1324 static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
1324 { 1325 {
1325 input_event(dev, EV_REL, code, value); 1326 input_event(dev, EV_REL, code, value);
1326 } 1327 }
1327 1328
1328 static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value) 1329 static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
1329 { 1330 {
1330 input_event(dev, EV_ABS, code, value); 1331 input_event(dev, EV_ABS, code, value);
1331 } 1332 }
1332 1333
1333 static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value) 1334 static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
1334 { 1335 {
1335 input_event(dev, EV_FF_STATUS, code, value); 1336 input_event(dev, EV_FF_STATUS, code, value);
1336 } 1337 }
1337 1338
1338 static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value) 1339 static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
1339 { 1340 {
1340 input_event(dev, EV_SW, code, !!value); 1341 input_event(dev, EV_SW, code, !!value);
1341 } 1342 }
1342 1343
1343 static inline void input_sync(struct input_dev *dev) 1344 static inline void input_sync(struct input_dev *dev)
1344 { 1345 {
1345 input_event(dev, EV_SYN, SYN_REPORT, 0); 1346 input_event(dev, EV_SYN, SYN_REPORT, 0);
1346 } 1347 }
1347 1348
1348 static inline void input_mt_sync(struct input_dev *dev) 1349 static inline void input_mt_sync(struct input_dev *dev)
1349 { 1350 {
1350 input_event(dev, EV_SYN, SYN_MT_REPORT, 0); 1351 input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
1351 } 1352 }
1352 1353
1353 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code); 1354 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
1354 1355
1355 static inline void input_set_abs_params(struct input_dev *dev, int axis, int min, int max, int fuzz, int flat) 1356 static inline void input_set_abs_params(struct input_dev *dev, int axis, int min, int max, int fuzz, int flat)
1356 { 1357 {
1357 dev->absmin[axis] = min; 1358 dev->absmin[axis] = min;
1358 dev->absmax[axis] = max; 1359 dev->absmax[axis] = max;
1359 dev->absfuzz[axis] = fuzz; 1360 dev->absfuzz[axis] = fuzz;
1360 dev->absflat[axis] = flat; 1361 dev->absflat[axis] = flat;
1361 1362
1362 dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis); 1363 dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
1363 } 1364 }
1364 1365
1365 int input_get_keycode(struct input_dev *dev, int scancode, int *keycode); 1366 int input_get_keycode(struct input_dev *dev, int scancode, int *keycode);
1366 int input_set_keycode(struct input_dev *dev, int scancode, int keycode); 1367 int input_set_keycode(struct input_dev *dev, int scancode, int keycode);
1367 1368
1368 extern struct class input_class; 1369 extern struct class input_class;
1369 1370
1370 /** 1371 /**
1371 * struct ff_device - force-feedback part of an input device 1372 * struct ff_device - force-feedback part of an input device
1372 * @upload: Called to upload an new effect into device 1373 * @upload: Called to upload an new effect into device
1373 * @erase: Called to erase an effect from device 1374 * @erase: Called to erase an effect from device
1374 * @playback: Called to request device to start playing specified effect 1375 * @playback: Called to request device to start playing specified effect
1375 * @set_gain: Called to set specified gain 1376 * @set_gain: Called to set specified gain
1376 * @set_autocenter: Called to auto-center device 1377 * @set_autocenter: Called to auto-center device
1377 * @destroy: called by input core when parent input device is being 1378 * @destroy: called by input core when parent input device is being
1378 * destroyed 1379 * destroyed
1379 * @private: driver-specific data, will be freed automatically 1380 * @private: driver-specific data, will be freed automatically
1380 * @ffbit: bitmap of force feedback capabilities truly supported by 1381 * @ffbit: bitmap of force feedback capabilities truly supported by
1381 * device (not emulated like ones in input_dev->ffbit) 1382 * device (not emulated like ones in input_dev->ffbit)
1382 * @mutex: mutex for serializing access to the device 1383 * @mutex: mutex for serializing access to the device
1383 * @max_effects: maximum number of effects supported by device 1384 * @max_effects: maximum number of effects supported by device
1384 * @effects: pointer to an array of effects currently loaded into device 1385 * @effects: pointer to an array of effects currently loaded into device
1385 * @effect_owners: array of effect owners; when file handle owning 1386 * @effect_owners: array of effect owners; when file handle owning
1386 * an effect gets closed the effect is automatically erased 1387 * an effect gets closed the effect is automatically erased
1387 * 1388 *
1388 * Every force-feedback device must implement upload() and playback() 1389 * Every force-feedback device must implement upload() and playback()
1389 * methods; erase() is optional. set_gain() and set_autocenter() need 1390 * methods; erase() is optional. set_gain() and set_autocenter() need
1390 * only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER 1391 * only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER
1391 * bits. 1392 * bits.
1392 * 1393 *
1393 * Note that playback(), set_gain() and set_autocenter() are called with 1394 * Note that playback(), set_gain() and set_autocenter() are called with
1394 * dev->event_lock spinlock held and interrupts off and thus may not 1395 * dev->event_lock spinlock held and interrupts off and thus may not
1395 * sleep. 1396 * sleep.
1396 */ 1397 */
1397 struct ff_device { 1398 struct ff_device {
1398 int (*upload)(struct input_dev *dev, struct ff_effect *effect, 1399 int (*upload)(struct input_dev *dev, struct ff_effect *effect,
1399 struct ff_effect *old); 1400 struct ff_effect *old);
1400 int (*erase)(struct input_dev *dev, int effect_id); 1401 int (*erase)(struct input_dev *dev, int effect_id);
1401 1402
1402 int (*playback)(struct input_dev *dev, int effect_id, int value); 1403 int (*playback)(struct input_dev *dev, int effect_id, int value);
1403 void (*set_gain)(struct input_dev *dev, u16 gain); 1404 void (*set_gain)(struct input_dev *dev, u16 gain);
1404 void (*set_autocenter)(struct input_dev *dev, u16 magnitude); 1405 void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
1405 1406
1406 void (*destroy)(struct ff_device *); 1407 void (*destroy)(struct ff_device *);
1407 1408
1408 void *private; 1409 void *private;
1409 1410
1410 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)]; 1411 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
1411 1412
1412 struct mutex mutex; 1413 struct mutex mutex;
1413 1414
1414 int max_effects; 1415 int max_effects;
1415 struct ff_effect *effects; 1416 struct ff_effect *effects;
1416 struct file *effect_owners[]; 1417 struct file *effect_owners[];
1417 }; 1418 };
1418 1419
1419 int input_ff_create(struct input_dev *dev, int max_effects); 1420 int input_ff_create(struct input_dev *dev, int max_effects);
1420 void input_ff_destroy(struct input_dev *dev); 1421 void input_ff_destroy(struct input_dev *dev);
1421 1422
1422 int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value); 1423 int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1423 1424
1424 int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file); 1425 int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
1425 int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file); 1426 int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
1426 1427
1427 int input_ff_create_memless(struct input_dev *dev, void *data, 1428 int input_ff_create_memless(struct input_dev *dev, void *data,
1428 int (*play_effect)(struct input_dev *, void *, struct ff_effect *)); 1429 int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
1429 1430
1430 #endif 1431 #endif
1431 #endif 1432 #endif
1432 1433