0001
0002
0003
0004
0005 #ifndef _INPUT_H
0006 #define _INPUT_H
0007
0008 #include <linux/time.h>
0009 #include <linux/list.h>
0010 #include <uapi/linux/input.h>
0011
0012 #define ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
0013 #define ABS_MT_LAST ABS_MT_TOOL_Y
0014
0015
0016
0017
0018
0019 #include <linux/device.h>
0020 #include <linux/fs.h>
0021 #include <linux/timer.h>
0022 #include <linux/mod_devicetable.h>
0023
0024 struct input_dev_poller;
0025
0026
0027
0028
0029
0030
0031
0032 struct input_value {
0033 __u16 type;
0034 __u16 code;
0035 __s32 value;
0036 };
0037
0038 enum input_clock_type {
0039 INPUT_CLK_REAL = 0,
0040 INPUT_CLK_MONO,
0041 INPUT_CLK_BOOT,
0042 INPUT_CLK_MAX
0043 };
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 struct input_dev {
0138 const char *name;
0139 const char *phys;
0140 const char *uniq;
0141 struct input_id id;
0142
0143 unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
0144
0145 unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
0146 unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
0147 unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
0148 unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
0149 unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
0150 unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
0151 unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
0152 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
0153 unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
0154
0155 unsigned int hint_events_per_packet;
0156
0157 unsigned int keycodemax;
0158 unsigned int keycodesize;
0159 void *keycode;
0160
0161 int (*setkeycode)(struct input_dev *dev,
0162 const struct input_keymap_entry *ke,
0163 unsigned int *old_keycode);
0164 int (*getkeycode)(struct input_dev *dev,
0165 struct input_keymap_entry *ke);
0166
0167 struct ff_device *ff;
0168
0169 struct input_dev_poller *poller;
0170
0171 unsigned int repeat_key;
0172 struct timer_list timer;
0173
0174 int rep[REP_CNT];
0175
0176 struct input_mt *mt;
0177
0178 struct input_absinfo *absinfo;
0179
0180 unsigned long key[BITS_TO_LONGS(KEY_CNT)];
0181 unsigned long led[BITS_TO_LONGS(LED_CNT)];
0182 unsigned long snd[BITS_TO_LONGS(SND_CNT)];
0183 unsigned long sw[BITS_TO_LONGS(SW_CNT)];
0184
0185 int (*open)(struct input_dev *dev);
0186 void (*close)(struct input_dev *dev);
0187 int (*flush)(struct input_dev *dev, struct file *file);
0188 int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
0189
0190 struct input_handle __rcu *grab;
0191
0192 spinlock_t event_lock;
0193 struct mutex mutex;
0194
0195 unsigned int users;
0196 bool going_away;
0197
0198 struct device dev;
0199
0200 struct list_head h_list;
0201 struct list_head node;
0202
0203 unsigned int num_vals;
0204 unsigned int max_vals;
0205 struct input_value *vals;
0206
0207 bool devres_managed;
0208
0209 ktime_t timestamp[INPUT_CLK_MAX];
0210
0211 bool inhibited;
0212 };
0213 #define to_input_dev(d) container_of(d, struct input_dev, dev)
0214
0215
0216
0217
0218
0219 #if EV_MAX != INPUT_DEVICE_ID_EV_MAX
0220 #error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
0221 #endif
0222
0223 #if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
0224 #error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
0225 #endif
0226
0227 #if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
0228 #error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
0229 #endif
0230
0231 #if REL_MAX != INPUT_DEVICE_ID_REL_MAX
0232 #error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
0233 #endif
0234
0235 #if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
0236 #error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
0237 #endif
0238
0239 #if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
0240 #error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
0241 #endif
0242
0243 #if LED_MAX != INPUT_DEVICE_ID_LED_MAX
0244 #error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
0245 #endif
0246
0247 #if SND_MAX != INPUT_DEVICE_ID_SND_MAX
0248 #error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
0249 #endif
0250
0251 #if FF_MAX != INPUT_DEVICE_ID_FF_MAX
0252 #error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
0253 #endif
0254
0255 #if SW_MAX != INPUT_DEVICE_ID_SW_MAX
0256 #error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
0257 #endif
0258
0259 #if INPUT_PROP_MAX != INPUT_DEVICE_ID_PROP_MAX
0260 #error "INPUT_PROP_MAX and INPUT_DEVICE_ID_PROP_MAX do not match"
0261 #endif
0262
0263 #define INPUT_DEVICE_ID_MATCH_DEVICE \
0264 (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
0265 #define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
0266 (INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)
0267
0268 struct input_handle;
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310 struct input_handler {
0311
0312 void *private;
0313
0314 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
0315 void (*events)(struct input_handle *handle,
0316 const struct input_value *vals, unsigned int count);
0317 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
0318 bool (*match)(struct input_handler *handler, struct input_dev *dev);
0319 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
0320 void (*disconnect)(struct input_handle *handle);
0321 void (*start)(struct input_handle *handle);
0322
0323 bool legacy_minors;
0324 int minor;
0325 const char *name;
0326
0327 const struct input_device_id *id_table;
0328
0329 struct list_head h_list;
0330 struct list_head node;
0331 };
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345 struct input_handle {
0346
0347 void *private;
0348
0349 int open;
0350 const char *name;
0351
0352 struct input_dev *dev;
0353 struct input_handler *handler;
0354
0355 struct list_head d_node;
0356 struct list_head h_node;
0357 };
0358
0359 struct input_dev __must_check *input_allocate_device(void);
0360 struct input_dev __must_check *devm_input_allocate_device(struct device *);
0361 void input_free_device(struct input_dev *dev);
0362
0363 static inline struct input_dev *input_get_device(struct input_dev *dev)
0364 {
0365 return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
0366 }
0367
0368 static inline void input_put_device(struct input_dev *dev)
0369 {
0370 if (dev)
0371 put_device(&dev->dev);
0372 }
0373
0374 static inline void *input_get_drvdata(struct input_dev *dev)
0375 {
0376 return dev_get_drvdata(&dev->dev);
0377 }
0378
0379 static inline void input_set_drvdata(struct input_dev *dev, void *data)
0380 {
0381 dev_set_drvdata(&dev->dev, data);
0382 }
0383
0384 int __must_check input_register_device(struct input_dev *);
0385 void input_unregister_device(struct input_dev *);
0386
0387 void input_reset_device(struct input_dev *);
0388
0389 int input_setup_polling(struct input_dev *dev,
0390 void (*poll_fn)(struct input_dev *dev));
0391 void input_set_poll_interval(struct input_dev *dev, unsigned int interval);
0392 void input_set_min_poll_interval(struct input_dev *dev, unsigned int interval);
0393 void input_set_max_poll_interval(struct input_dev *dev, unsigned int interval);
0394 int input_get_poll_interval(struct input_dev *dev);
0395
0396 int __must_check input_register_handler(struct input_handler *);
0397 void input_unregister_handler(struct input_handler *);
0398
0399 int __must_check input_get_new_minor(int legacy_base, unsigned int legacy_num,
0400 bool allow_dynamic);
0401 void input_free_minor(unsigned int minor);
0402
0403 int input_handler_for_each_handle(struct input_handler *, void *data,
0404 int (*fn)(struct input_handle *, void *));
0405
0406 int input_register_handle(struct input_handle *);
0407 void input_unregister_handle(struct input_handle *);
0408
0409 int input_grab_device(struct input_handle *);
0410 void input_release_device(struct input_handle *);
0411
0412 int input_open_device(struct input_handle *);
0413 void input_close_device(struct input_handle *);
0414
0415 int input_flush_device(struct input_handle *handle, struct file *file);
0416
0417 void input_set_timestamp(struct input_dev *dev, ktime_t timestamp);
0418 ktime_t *input_get_timestamp(struct input_dev *dev);
0419
0420 void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
0421 void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
0422
0423 static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
0424 {
0425 input_event(dev, EV_KEY, code, !!value);
0426 }
0427
0428 static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
0429 {
0430 input_event(dev, EV_REL, code, value);
0431 }
0432
0433 static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
0434 {
0435 input_event(dev, EV_ABS, code, value);
0436 }
0437
0438 static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
0439 {
0440 input_event(dev, EV_FF_STATUS, code, value);
0441 }
0442
0443 static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
0444 {
0445 input_event(dev, EV_SW, code, !!value);
0446 }
0447
0448 static inline void input_sync(struct input_dev *dev)
0449 {
0450 input_event(dev, EV_SYN, SYN_REPORT, 0);
0451 }
0452
0453 static inline void input_mt_sync(struct input_dev *dev)
0454 {
0455 input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
0456 }
0457
0458 void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470 static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
0471 {
0472 dev->hint_events_per_packet = n_events;
0473 }
0474
0475 void input_alloc_absinfo(struct input_dev *dev);
0476 void input_set_abs_params(struct input_dev *dev, unsigned int axis,
0477 int min, int max, int fuzz, int flat);
0478 void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
0479 const struct input_dev *src, unsigned int src_axis);
0480
0481 #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item) \
0482 static inline int input_abs_get_##_suffix(struct input_dev *dev, \
0483 unsigned int axis) \
0484 { \
0485 return dev->absinfo ? dev->absinfo[axis]._item : 0; \
0486 } \
0487 \
0488 static inline void input_abs_set_##_suffix(struct input_dev *dev, \
0489 unsigned int axis, int val) \
0490 { \
0491 input_alloc_absinfo(dev); \
0492 if (dev->absinfo) \
0493 dev->absinfo[axis]._item = val; \
0494 }
0495
0496 INPUT_GENERATE_ABS_ACCESSORS(val, value)
0497 INPUT_GENERATE_ABS_ACCESSORS(min, minimum)
0498 INPUT_GENERATE_ABS_ACCESSORS(max, maximum)
0499 INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
0500 INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
0501 INPUT_GENERATE_ABS_ACCESSORS(res, resolution)
0502
0503 int input_scancode_to_scalar(const struct input_keymap_entry *ke,
0504 unsigned int *scancode);
0505
0506 int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
0507 int input_set_keycode(struct input_dev *dev,
0508 const struct input_keymap_entry *ke);
0509
0510 bool input_match_device_id(const struct input_dev *dev,
0511 const struct input_device_id *id);
0512
0513 void input_enable_softrepeat(struct input_dev *dev, int delay, int period);
0514
0515 bool input_device_enabled(struct input_dev *dev);
0516
0517 extern struct class input_class;
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546 struct ff_device {
0547 int (*upload)(struct input_dev *dev, struct ff_effect *effect,
0548 struct ff_effect *old);
0549 int (*erase)(struct input_dev *dev, int effect_id);
0550
0551 int (*playback)(struct input_dev *dev, int effect_id, int value);
0552 void (*set_gain)(struct input_dev *dev, u16 gain);
0553 void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
0554
0555 void (*destroy)(struct ff_device *);
0556
0557 void *private;
0558
0559 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
0560
0561 struct mutex mutex;
0562
0563 int max_effects;
0564 struct ff_effect *effects;
0565 struct file *effect_owners[];
0566 };
0567
0568 int input_ff_create(struct input_dev *dev, unsigned int max_effects);
0569 void input_ff_destroy(struct input_dev *dev);
0570
0571 int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
0572
0573 int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
0574 int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
0575 int input_ff_flush(struct input_dev *dev, struct file *file);
0576
0577 int input_ff_create_memless(struct input_dev *dev, void *data,
0578 int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
0579
0580 #endif