1
2
3
4
5#ifndef _INPUT_H
6#define _INPUT_H
7
8#include <linux/time.h>
9#include <linux/list.h>
10#include <uapi/linux/input.h>
11
12#define ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
13#define ABS_MT_LAST ABS_MT_TOOL_Y
14
15
16
17
18
19#include <linux/device.h>
20#include <linux/fs.h>
21#include <linux/timer.h>
22#include <linux/mod_devicetable.h>
23
24struct input_dev_poller;
25
26
27
28
29
30
31
32struct input_value {
33 __u16 type;
34 __u16 code;
35 __s32 value;
36};
37
38enum input_clock_type {
39 INPUT_CLK_REAL = 0,
40 INPUT_CLK_MONO,
41 INPUT_CLK_BOOT,
42 INPUT_CLK_MAX
43};
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137struct input_dev {
138 const char *name;
139 const char *phys;
140 const char *uniq;
141 struct input_id id;
142
143 unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
144
145 unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
146 unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
147 unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
148 unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
149 unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
150 unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
151 unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
152 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
153 unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
154
155 unsigned int hint_events_per_packet;
156
157 unsigned int keycodemax;
158 unsigned int keycodesize;
159 void *keycode;
160
161 int (*setkeycode)(struct input_dev *dev,
162 const struct input_keymap_entry *ke,
163 unsigned int *old_keycode);
164 int (*getkeycode)(struct input_dev *dev,
165 struct input_keymap_entry *ke);
166
167 struct ff_device *ff;
168
169 struct input_dev_poller *poller;
170
171 unsigned int repeat_key;
172 struct timer_list timer;
173
174 int rep[REP_CNT];
175
176 struct input_mt *mt;
177
178 struct input_absinfo *absinfo;
179
180 unsigned long key[BITS_TO_LONGS(KEY_CNT)];
181 unsigned long led[BITS_TO_LONGS(LED_CNT)];
182 unsigned long snd[BITS_TO_LONGS(SND_CNT)];
183 unsigned long sw[BITS_TO_LONGS(SW_CNT)];
184
185 int (*open)(struct input_dev *dev);
186 void (*close)(struct input_dev *dev);
187 int (*flush)(struct input_dev *dev, struct file *file);
188 int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
189
190 struct input_handle __rcu *grab;
191
192 spinlock_t event_lock;
193 struct mutex mutex;
194
195 unsigned int users;
196 bool going_away;
197
198 struct device dev;
199
200 struct list_head h_list;
201 struct list_head node;
202
203 unsigned int num_vals;
204 unsigned int max_vals;
205 struct input_value *vals;
206
207 bool devres_managed;
208
209 ktime_t timestamp[INPUT_CLK_MAX];
210
211 bool inhibited;
212};
213#define to_input_dev(d) container_of(d, struct input_dev, dev)
214
215
216
217
218
219#if EV_MAX != INPUT_DEVICE_ID_EV_MAX
220#error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
221#endif
222
223#if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
224#error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
225#endif
226
227#if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
228#error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
229#endif
230
231#if REL_MAX != INPUT_DEVICE_ID_REL_MAX
232#error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
233#endif
234
235#if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
236#error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
237#endif
238
239#if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
240#error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
241#endif
242
243#if LED_MAX != INPUT_DEVICE_ID_LED_MAX
244#error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
245#endif
246
247#if SND_MAX != INPUT_DEVICE_ID_SND_MAX
248#error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
249#endif
250
251#if FF_MAX != INPUT_DEVICE_ID_FF_MAX
252#error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
253#endif
254
255#if SW_MAX != INPUT_DEVICE_ID_SW_MAX
256#error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
257#endif
258
259#if INPUT_PROP_MAX != INPUT_DEVICE_ID_PROP_MAX
260#error "INPUT_PROP_MAX and INPUT_DEVICE_ID_PROP_MAX do not match"
261#endif
262
263#define INPUT_DEVICE_ID_MATCH_DEVICE \
264 (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
265#define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
266 (INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)
267
268struct input_handle;
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310struct input_handler {
311
312 void *private;
313
314 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
315 void (*events)(struct input_handle *handle,
316 const struct input_value *vals, unsigned int count);
317 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
318 bool (*match)(struct input_handler *handler, struct input_dev *dev);
319 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
320 void (*disconnect)(struct input_handle *handle);
321 void (*start)(struct input_handle *handle);
322
323 bool legacy_minors;
324 int minor;
325 const char *name;
326
327 const struct input_device_id *id_table;
328
329 struct list_head h_list;
330 struct list_head node;
331};
332
333
334
335
336
337
338
339
340
341
342
343
344
345struct input_handle {
346
347 void *private;
348
349 int open;
350 const char *name;
351
352 struct input_dev *dev;
353 struct input_handler *handler;
354
355 struct list_head d_node;
356 struct list_head h_node;
357};
358
359struct input_dev __must_check *input_allocate_device(void);
360struct input_dev __must_check *devm_input_allocate_device(struct device *);
361void input_free_device(struct input_dev *dev);
362
363static inline struct input_dev *input_get_device(struct input_dev *dev)
364{
365 return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
366}
367
368static inline void input_put_device(struct input_dev *dev)
369{
370 if (dev)
371 put_device(&dev->dev);
372}
373
374static inline void *input_get_drvdata(struct input_dev *dev)
375{
376 return dev_get_drvdata(&dev->dev);
377}
378
379static inline void input_set_drvdata(struct input_dev *dev, void *data)
380{
381 dev_set_drvdata(&dev->dev, data);
382}
383
384int __must_check input_register_device(struct input_dev *);
385void input_unregister_device(struct input_dev *);
386
387void input_reset_device(struct input_dev *);
388
389int input_setup_polling(struct input_dev *dev,
390 void (*poll_fn)(struct input_dev *dev));
391void input_set_poll_interval(struct input_dev *dev, unsigned int interval);
392void input_set_min_poll_interval(struct input_dev *dev, unsigned int interval);
393void input_set_max_poll_interval(struct input_dev *dev, unsigned int interval);
394int input_get_poll_interval(struct input_dev *dev);
395
396int __must_check input_register_handler(struct input_handler *);
397void input_unregister_handler(struct input_handler *);
398
399int __must_check input_get_new_minor(int legacy_base, unsigned int legacy_num,
400 bool allow_dynamic);
401void input_free_minor(unsigned int minor);
402
403int input_handler_for_each_handle(struct input_handler *, void *data,
404 int (*fn)(struct input_handle *, void *));
405
406int input_register_handle(struct input_handle *);
407void input_unregister_handle(struct input_handle *);
408
409int input_grab_device(struct input_handle *);
410void input_release_device(struct input_handle *);
411
412int input_open_device(struct input_handle *);
413void input_close_device(struct input_handle *);
414
415int input_flush_device(struct input_handle *handle, struct file *file);
416
417void input_set_timestamp(struct input_dev *dev, ktime_t timestamp);
418ktime_t *input_get_timestamp(struct input_dev *dev);
419
420void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
421void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
422
423static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
424{
425 input_event(dev, EV_KEY, code, !!value);
426}
427
428static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
429{
430 input_event(dev, EV_REL, code, value);
431}
432
433static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
434{
435 input_event(dev, EV_ABS, code, value);
436}
437
438static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
439{
440 input_event(dev, EV_FF_STATUS, code, value);
441}
442
443static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
444{
445 input_event(dev, EV_SW, code, !!value);
446}
447
448static inline void input_sync(struct input_dev *dev)
449{
450 input_event(dev, EV_SYN, SYN_REPORT, 0);
451}
452
453static inline void input_mt_sync(struct input_dev *dev)
454{
455 input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
456}
457
458void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
459
460
461
462
463
464
465
466
467
468
469
470static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
471{
472 dev->hint_events_per_packet = n_events;
473}
474
475void input_alloc_absinfo(struct input_dev *dev);
476void input_set_abs_params(struct input_dev *dev, unsigned int axis,
477 int min, int max, int fuzz, int flat);
478
479#define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item) \
480static inline int input_abs_get_##_suffix(struct input_dev *dev, \
481 unsigned int axis) \
482{ \
483 return dev->absinfo ? dev->absinfo[axis]._item : 0; \
484} \
485 \
486static inline void input_abs_set_##_suffix(struct input_dev *dev, \
487 unsigned int axis, int val) \
488{ \
489 input_alloc_absinfo(dev); \
490 if (dev->absinfo) \
491 dev->absinfo[axis]._item = val; \
492}
493
494INPUT_GENERATE_ABS_ACCESSORS(val, value)
495INPUT_GENERATE_ABS_ACCESSORS(min, minimum)
496INPUT_GENERATE_ABS_ACCESSORS(max, maximum)
497INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
498INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
499INPUT_GENERATE_ABS_ACCESSORS(res, resolution)
500
501int input_scancode_to_scalar(const struct input_keymap_entry *ke,
502 unsigned int *scancode);
503
504int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
505int input_set_keycode(struct input_dev *dev,
506 const struct input_keymap_entry *ke);
507
508bool input_match_device_id(const struct input_dev *dev,
509 const struct input_device_id *id);
510
511void input_enable_softrepeat(struct input_dev *dev, int delay, int period);
512
513bool input_device_enabled(struct input_dev *dev);
514
515extern struct class input_class;
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544struct ff_device {
545 int (*upload)(struct input_dev *dev, struct ff_effect *effect,
546 struct ff_effect *old);
547 int (*erase)(struct input_dev *dev, int effect_id);
548
549 int (*playback)(struct input_dev *dev, int effect_id, int value);
550 void (*set_gain)(struct input_dev *dev, u16 gain);
551 void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
552
553 void (*destroy)(struct ff_device *);
554
555 void *private;
556
557 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
558
559 struct mutex mutex;
560
561 int max_effects;
562 struct ff_effect *effects;
563 struct file *effect_owners[];
564};
565
566int input_ff_create(struct input_dev *dev, unsigned int max_effects);
567void input_ff_destroy(struct input_dev *dev);
568
569int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
570
571int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
572int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
573int input_ff_flush(struct input_dev *dev, struct file *file);
574
575int input_ff_create_memless(struct input_dev *dev, void *data,
576 int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
577
578#endif
579