aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/input.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/input.h')
-rw-r--r--include/linux/input.h166
1 files changed, 131 insertions, 35 deletions
diff --git a/include/linux/input.h b/include/linux/input.h
index 6fcc9101beeb..51af441f3a21 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -34,7 +34,7 @@ struct input_event {
34 * Protocol version. 34 * Protocol version.
35 */ 35 */
36 36
37#define EV_VERSION 0x010000 37#define EV_VERSION 0x010001
38 38
39/* 39/*
40 * IOCTLs (0x00 - 0x7f) 40 * IOCTLs (0x00 - 0x7f)
@@ -56,25 +56,50 @@ struct input_absinfo {
56 __s32 resolution; 56 __s32 resolution;
57}; 57};
58 58
59/**
60 * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
61 * @scancode: scancode represented in machine-endian form.
62 * @len: length of the scancode that resides in @scancode buffer.
63 * @index: index in the keymap, may be used instead of scancode
64 * @flags: allows to specify how kernel should handle the request. For
65 * example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel
66 * should perform lookup in keymap by @index instead of @scancode
67 * @keycode: key code assigned to this scancode
68 *
69 * The structure is used to retrieve and modify keymap data. Users have
70 * option of performing lookup either by @scancode itself or by @index
71 * in keymap entry. EVIOCGKEYCODE will also return scancode or index
72 * (depending on which element was used to perform lookup).
73 */
74struct input_keymap_entry {
75#define INPUT_KEYMAP_BY_INDEX (1 << 0)
76 __u8 flags;
77 __u8 len;
78 __u16 index;
79 __u32 keycode;
80 __u8 scancode[32];
81};
82
59#define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ 83#define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */
60#define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ 84#define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */
61#define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */ 85#define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */
62#define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */ 86#define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */
63#define EVIOCGKEYCODE _IOR('E', 0x04, unsigned int[2]) /* get keycode */ 87
64#define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */ 88#define EVIOCGKEYCODE _IOR('E', 0x04, struct input_keymap_entry) /* get keycode */
89#define EVIOCSKEYCODE _IOW('E', 0x04, struct input_keymap_entry) /* set keycode */
65 90
66#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ 91#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 */ 92#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 */ 93#define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */
69 94
70#define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global keystate */ 95#define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global key state */
71#define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */ 96#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 */ 97#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 */ 98#define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */
74 99
75#define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */ 100#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 */ 101#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 */ 102#define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */
78 103
79#define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */ 104#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 */ 105#define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */
@@ -691,9 +716,12 @@ struct input_absinfo {
691#define ABS_TILT_X 0x1a 716#define ABS_TILT_X 0x1a
692#define ABS_TILT_Y 0x1b 717#define ABS_TILT_Y 0x1b
693#define ABS_TOOL_WIDTH 0x1c 718#define ABS_TOOL_WIDTH 0x1c
719
694#define ABS_VOLUME 0x20 720#define ABS_VOLUME 0x20
721
695#define ABS_MISC 0x28 722#define ABS_MISC 0x28
696 723
724#define ABS_MT_SLOT 0x2f /* MT slot being modified */
697#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ 725#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
698#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */ 726#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
699#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ 727#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
@@ -706,6 +734,12 @@ struct input_absinfo {
706#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ 734#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
707#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ 735#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
708 736
737#ifdef __KERNEL__
738/* Implementation details, userspace should not care about these */
739#define ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
740#define ABS_MT_LAST ABS_MT_PRESSURE
741#endif
742
709#define ABS_MAX 0x3f 743#define ABS_MAX 0x3f
710#define ABS_CNT (ABS_MAX+1) 744#define ABS_CNT (ABS_MAX+1)
711 745
@@ -767,6 +801,7 @@ struct input_absinfo {
767#define REP_DELAY 0x00 801#define REP_DELAY 0x00
768#define REP_PERIOD 0x01 802#define REP_PERIOD 0x01
769#define REP_MAX 0x01 803#define REP_MAX 0x01
804#define REP_CNT (REP_MAX+1)
770 805
771/* 806/*
772 * Sounds 807 * Sounds
@@ -1048,6 +1083,14 @@ struct ff_effect {
1048#include <linux/mod_devicetable.h> 1083#include <linux/mod_devicetable.h>
1049 1084
1050/** 1085/**
1086 * struct input_mt_slot - represents the state of an input MT slot
1087 * @abs: holds current values of ABS_MT axes for this slot
1088 */
1089struct input_mt_slot {
1090 int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
1091};
1092
1093/**
1051 * struct input_dev - represents an input device 1094 * struct input_dev - represents an input device
1052 * @name: name of the device 1095 * @name: name of the device
1053 * @phys: physical path to the device in the system hierarchy 1096 * @phys: physical path to the device in the system hierarchy
@@ -1063,33 +1106,37 @@ struct ff_effect {
1063 * @sndbit: bitmap of sound effects supported by the device 1106 * @sndbit: bitmap of sound effects supported by the device
1064 * @ffbit: bitmap of force feedback effects supported by the device 1107 * @ffbit: bitmap of force feedback effects supported by the device
1065 * @swbit: bitmap of switches present on the device 1108 * @swbit: bitmap of switches present on the device
1109 * @hint_events_per_packet: average number of events generated by the
1110 * device in a packet (between EV_SYN/SYN_REPORT events). Used by
1111 * event handlers to estimate size of the buffer needed to hold
1112 * events.
1066 * @keycodemax: size of keycode table 1113 * @keycodemax: size of keycode table
1067 * @keycodesize: size of elements in keycode table 1114 * @keycodesize: size of elements in keycode table
1068 * @keycode: map of scancodes to keycodes for this device 1115 * @keycode: map of scancodes to keycodes for this device
1116 * @getkeycode: optional legacy method to retrieve current keymap.
1069 * @setkeycode: optional method to alter current keymap, used to implement 1117 * @setkeycode: optional method to alter current keymap, used to implement
1070 * sparse keymaps. If not supplied default mechanism will be used. 1118 * sparse keymaps. If not supplied default mechanism will be used.
1071 * The method is being called while holding event_lock and thus must 1119 * The method is being called while holding event_lock and thus must
1072 * not sleep 1120 * not sleep
1073 * @getkeycode: optional method to retrieve current keymap. If not supplied 1121 * @getkeycode_new: transition method
1074 * default mechanism will be used. The method is being called while 1122 * @setkeycode_new: transition method
1075 * holding event_lock and thus must not sleep
1076 * @ff: force feedback structure associated with the device if device 1123 * @ff: force feedback structure associated with the device if device
1077 * supports force feedback effects 1124 * supports force feedback effects
1078 * @repeat_key: stores key code of the last key pressed; used to implement 1125 * @repeat_key: stores key code of the last key pressed; used to implement
1079 * software autorepeat 1126 * software autorepeat
1080 * @timer: timer for software autorepeat 1127 * @timer: timer for software autorepeat
1081 * @sync: set to 1 when there were no new events since last EV_SYNC
1082 * @abs: current values for reports from absolute axes
1083 * @rep: current values for autorepeat parameters (delay, rate) 1128 * @rep: current values for autorepeat parameters (delay, rate)
1129 * @mt: pointer to array of struct input_mt_slot holding current values
1130 * of tracked contacts
1131 * @mtsize: number of MT slots the device uses
1132 * @slot: MT slot currently being transmitted
1133 * @absinfo: array of &struct absinfo elements holding information
1134 * about absolute axes (current value, min, max, flat, fuzz,
1135 * resolution)
1084 * @key: reflects current state of device's keys/buttons 1136 * @key: reflects current state of device's keys/buttons
1085 * @led: reflects current state of device's LEDs 1137 * @led: reflects current state of device's LEDs
1086 * @snd: reflects current state of sound effects 1138 * @snd: reflects current state of sound effects
1087 * @sw: reflects current state of device's switches 1139 * @sw: reflects current state of device's switches
1088 * @absmax: maximum values for events coming from absolute axes
1089 * @absmin: minimum values for events coming from absolute axes
1090 * @absfuzz: describes noisiness for axes
1091 * @absflat: size of the center flat position (used by joydev)
1092 * @absres: resolution used for events coming form absolute axes
1093 * @open: this method is called when the very first user calls 1140 * @open: this method is called when the very first user calls
1094 * input_open_device(). The driver must prepare the device 1141 * input_open_device(). The driver must prepare the device
1095 * to start generating events (start polling thread, 1142 * to start generating events (start polling thread,
@@ -1119,6 +1166,7 @@ struct ff_effect {
1119 * last user closes the device 1166 * last user closes the device
1120 * @going_away: marks devices that are in a middle of unregistering and 1167 * @going_away: marks devices that are in a middle of unregistering and
1121 * causes input_open_device*() fail with -ENODEV. 1168 * causes input_open_device*() fail with -ENODEV.
1169 * @sync: set to %true when there were no new events since last EV_SYN
1122 * @dev: driver model's view of this device 1170 * @dev: driver model's view of this device
1123 * @h_list: list of input handles associated with the device. When 1171 * @h_list: list of input handles associated with the device. When
1124 * accessing the list dev->mutex must be held 1172 * accessing the list dev->mutex must be held
@@ -1140,41 +1188,46 @@ struct input_dev {
1140 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)]; 1188 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
1141 unsigned long swbit[BITS_TO_LONGS(SW_CNT)]; 1189 unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
1142 1190
1191 unsigned int hint_events_per_packet;
1192
1143 unsigned int keycodemax; 1193 unsigned int keycodemax;
1144 unsigned int keycodesize; 1194 unsigned int keycodesize;
1145 void *keycode; 1195 void *keycode;
1196
1146 int (*setkeycode)(struct input_dev *dev, 1197 int (*setkeycode)(struct input_dev *dev,
1147 unsigned int scancode, unsigned int keycode); 1198 unsigned int scancode, unsigned int keycode);
1148 int (*getkeycode)(struct input_dev *dev, 1199 int (*getkeycode)(struct input_dev *dev,
1149 unsigned int scancode, unsigned int *keycode); 1200 unsigned int scancode, unsigned int *keycode);
1201 int (*setkeycode_new)(struct input_dev *dev,
1202 const struct input_keymap_entry *ke,
1203 unsigned int *old_keycode);
1204 int (*getkeycode_new)(struct input_dev *dev,
1205 struct input_keymap_entry *ke);
1150 1206
1151 struct ff_device *ff; 1207 struct ff_device *ff;
1152 1208
1153 unsigned int repeat_key; 1209 unsigned int repeat_key;
1154 struct timer_list timer; 1210 struct timer_list timer;
1155 1211
1156 int sync; 1212 int rep[REP_CNT];
1157 1213
1158 int abs[ABS_CNT]; 1214 struct input_mt_slot *mt;
1159 int rep[REP_MAX + 1]; 1215 int mtsize;
1216 int slot;
1217
1218 struct input_absinfo *absinfo;
1160 1219
1161 unsigned long key[BITS_TO_LONGS(KEY_CNT)]; 1220 unsigned long key[BITS_TO_LONGS(KEY_CNT)];
1162 unsigned long led[BITS_TO_LONGS(LED_CNT)]; 1221 unsigned long led[BITS_TO_LONGS(LED_CNT)];
1163 unsigned long snd[BITS_TO_LONGS(SND_CNT)]; 1222 unsigned long snd[BITS_TO_LONGS(SND_CNT)];
1164 unsigned long sw[BITS_TO_LONGS(SW_CNT)]; 1223 unsigned long sw[BITS_TO_LONGS(SW_CNT)];
1165 1224
1166 int absmax[ABS_CNT];
1167 int absmin[ABS_CNT];
1168 int absfuzz[ABS_CNT];
1169 int absflat[ABS_CNT];
1170 int absres[ABS_CNT];
1171
1172 int (*open)(struct input_dev *dev); 1225 int (*open)(struct input_dev *dev);
1173 void (*close)(struct input_dev *dev); 1226 void (*close)(struct input_dev *dev);
1174 int (*flush)(struct input_dev *dev, struct file *file); 1227 int (*flush)(struct input_dev *dev, struct file *file);
1175 int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); 1228 int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1176 1229
1177 struct input_handle *grab; 1230 struct input_handle __rcu *grab;
1178 1231
1179 spinlock_t event_lock; 1232 spinlock_t event_lock;
1180 struct mutex mutex; 1233 struct mutex mutex;
@@ -1182,6 +1235,8 @@ struct input_dev {
1182 unsigned int users; 1235 unsigned int users;
1183 bool going_away; 1236 bool going_away;
1184 1237
1238 bool sync;
1239
1185 struct device dev; 1240 struct device dev;
1186 1241
1187 struct list_head h_list; 1242 struct list_head h_list;
@@ -1406,22 +1461,60 @@ static inline void input_mt_sync(struct input_dev *dev)
1406 input_event(dev, EV_SYN, SYN_MT_REPORT, 0); 1461 input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
1407} 1462}
1408 1463
1464static inline void input_mt_slot(struct input_dev *dev, int slot)
1465{
1466 input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
1467}
1468
1409void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code); 1469void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
1410 1470
1411static inline void input_set_abs_params(struct input_dev *dev, int axis, int min, int max, int fuzz, int flat) 1471/**
1472 * input_set_events_per_packet - tell handlers about the driver event rate
1473 * @dev: the input device used by the driver
1474 * @n_events: the average number of events between calls to input_sync()
1475 *
1476 * If the event rate sent from a device is unusually large, use this
1477 * function to set the expected event rate. This will allow handlers
1478 * to set up an appropriate buffer size for the event stream, in order
1479 * to minimize information loss.
1480 */
1481static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
1412{ 1482{
1413 dev->absmin[axis] = min; 1483 dev->hint_events_per_packet = n_events;
1414 dev->absmax[axis] = max; 1484}
1415 dev->absfuzz[axis] = fuzz;
1416 dev->absflat[axis] = flat;
1417 1485
1418 dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis); 1486void input_alloc_absinfo(struct input_dev *dev);
1487void input_set_abs_params(struct input_dev *dev, unsigned int axis,
1488 int min, int max, int fuzz, int flat);
1489
1490#define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item) \
1491static inline int input_abs_get_##_suffix(struct input_dev *dev, \
1492 unsigned int axis) \
1493{ \
1494 return dev->absinfo ? dev->absinfo[axis]._item : 0; \
1495} \
1496 \
1497static inline void input_abs_set_##_suffix(struct input_dev *dev, \
1498 unsigned int axis, int val) \
1499{ \
1500 input_alloc_absinfo(dev); \
1501 if (dev->absinfo) \
1502 dev->absinfo[axis]._item = val; \
1419} 1503}
1420 1504
1421int input_get_keycode(struct input_dev *dev, 1505INPUT_GENERATE_ABS_ACCESSORS(val, value)
1422 unsigned int scancode, unsigned int *keycode); 1506INPUT_GENERATE_ABS_ACCESSORS(min, minimum)
1507INPUT_GENERATE_ABS_ACCESSORS(max, maximum)
1508INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
1509INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
1510INPUT_GENERATE_ABS_ACCESSORS(res, resolution)
1511
1512int input_scancode_to_scalar(const struct input_keymap_entry *ke,
1513 unsigned int *scancode);
1514
1515int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
1423int input_set_keycode(struct input_dev *dev, 1516int input_set_keycode(struct input_dev *dev,
1424 unsigned int scancode, unsigned int keycode); 1517 const struct input_keymap_entry *ke);
1425 1518
1426extern struct class input_class; 1519extern struct class input_class;
1427 1520
@@ -1485,5 +1578,8 @@ int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
1485int input_ff_create_memless(struct input_dev *dev, void *data, 1578int input_ff_create_memless(struct input_dev *dev, void *data,
1486 int (*play_effect)(struct input_dev *, void *, struct ff_effect *)); 1579 int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
1487 1580
1581int input_mt_create_slots(struct input_dev *dev, unsigned int num_slots);
1582void input_mt_destroy_slots(struct input_dev *dev);
1583
1488#endif 1584#endif
1489#endif 1585#endif