1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Copyright (c) 1999-2002 Vojtech Pavlik
41da177e4SLinus Torvalds */
5607ca46eSDavid Howells #ifndef _INPUT_H
6607ca46eSDavid Howells #define _INPUT_H
71da177e4SLinus Torvalds
81da177e4SLinus Torvalds #include <linux/time.h>
91da177e4SLinus Torvalds #include <linux/list.h>
10607ca46eSDavid Howells #include <uapi/linux/input.h>
1140d007e7SHenrik Rydberg /* Implementation details, userspace should not care about these */
1240d007e7SHenrik Rydberg #define ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
13cab7facaSHenrik Rydberg #define ABS_MT_LAST ABS_MT_TOOL_Y
141da177e4SLinus Torvalds
151da177e4SLinus Torvalds /*
161da177e4SLinus Torvalds * In-kernel definitions.
171da177e4SLinus Torvalds */
181da177e4SLinus Torvalds
19ddc5d341SDmitry Torokhov #include <linux/device.h>
201da177e4SLinus Torvalds #include <linux/fs.h>
211da177e4SLinus Torvalds #include <linux/timer.h>
22ddc5d341SDmitry Torokhov #include <linux/mod_devicetable.h>
231da177e4SLinus Torvalds
24e95656eaSDmitry Torokhov struct input_dev_poller;
25e95656eaSDmitry Torokhov
268006479cSDmitry Torokhov /**
274369c64cSHenrik Rydberg * struct input_value - input value representation
284369c64cSHenrik Rydberg * @type: type of value (EV_KEY, EV_ABS, etc)
294369c64cSHenrik Rydberg * @code: the value code
304369c64cSHenrik Rydberg * @value: the value
314369c64cSHenrik Rydberg */
324369c64cSHenrik Rydberg struct input_value {
334369c64cSHenrik Rydberg __u16 type;
344369c64cSHenrik Rydberg __u16 code;
354369c64cSHenrik Rydberg __s32 value;
364369c64cSHenrik Rydberg };
374369c64cSHenrik Rydberg
383b51c44bSAtif Niyaz enum input_clock_type {
393b51c44bSAtif Niyaz INPUT_CLK_REAL = 0,
403b51c44bSAtif Niyaz INPUT_CLK_MONO,
413b51c44bSAtif Niyaz INPUT_CLK_BOOT,
423b51c44bSAtif Niyaz INPUT_CLK_MAX
433b51c44bSAtif Niyaz };
443b51c44bSAtif Niyaz
454369c64cSHenrik Rydberg /**
468006479cSDmitry Torokhov * struct input_dev - represents an input device
478006479cSDmitry Torokhov * @name: name of the device
488006479cSDmitry Torokhov * @phys: physical path to the device in the system hierarchy
498006479cSDmitry Torokhov * @uniq: unique identification code for the device (if device has it)
508006479cSDmitry Torokhov * @id: id of the device (struct input_id)
5185b77200SHenrik Rydberg * @propbit: bitmap of device properties and quirks
528006479cSDmitry Torokhov * @evbit: bitmap of types of events supported by the device (EV_KEY,
538006479cSDmitry Torokhov * EV_REL, etc.)
548006479cSDmitry Torokhov * @keybit: bitmap of keys/buttons this device has
558006479cSDmitry Torokhov * @relbit: bitmap of relative axes for the device
568006479cSDmitry Torokhov * @absbit: bitmap of absolute axes for the device
578006479cSDmitry Torokhov * @mscbit: bitmap of miscellaneous events supported by the device
588006479cSDmitry Torokhov * @ledbit: bitmap of leds present on the device
598006479cSDmitry Torokhov * @sndbit: bitmap of sound effects supported by the device
608006479cSDmitry Torokhov * @ffbit: bitmap of force feedback effects supported by the device
618006479cSDmitry Torokhov * @swbit: bitmap of switches present on the device
6263a6404dSHenrik Rydberg * @hint_events_per_packet: average number of events generated by the
6363a6404dSHenrik Rydberg * device in a packet (between EV_SYN/SYN_REPORT events). Used by
6463a6404dSHenrik Rydberg * event handlers to estimate size of the buffer needed to hold
6563a6404dSHenrik Rydberg * events.
668006479cSDmitry Torokhov * @keycodemax: size of keycode table
678006479cSDmitry Torokhov * @keycodesize: size of elements in keycode table
688006479cSDmitry Torokhov * @keycode: map of scancodes to keycodes for this device
698613e4c2SMauro Carvalho Chehab * @getkeycode: optional legacy method to retrieve current keymap.
708006479cSDmitry Torokhov * @setkeycode: optional method to alter current keymap, used to implement
7166d2a595SDmitry Torokhov * sparse keymaps. If not supplied default mechanism will be used.
7266d2a595SDmitry Torokhov * The method is being called while holding event_lock and thus must
7366d2a595SDmitry Torokhov * not sleep
748006479cSDmitry Torokhov * @ff: force feedback structure associated with the device if device
758006479cSDmitry Torokhov * supports force feedback effects
76e95656eaSDmitry Torokhov * @poller: poller structure associated with the device if device is
77e95656eaSDmitry Torokhov * set up to use polling mode
788006479cSDmitry Torokhov * @repeat_key: stores key code of the last key pressed; used to implement
798006479cSDmitry Torokhov * software autorepeat
808006479cSDmitry Torokhov * @timer: timer for software autorepeat
818006479cSDmitry Torokhov * @rep: current values for autorepeat parameters (delay, rate)
828d18fba2SHenrik Rydberg * @mt: pointer to multitouch state
8386b17f76SDmitry Torokhov * @absinfo: array of &struct input_absinfo elements holding information
84d31b2865SDaniel Mack * about absolute axes (current value, min, max, flat, fuzz,
85d31b2865SDaniel Mack * resolution)
868006479cSDmitry Torokhov * @key: reflects current state of device's keys/buttons
878006479cSDmitry Torokhov * @led: reflects current state of device's LEDs
888006479cSDmitry Torokhov * @snd: reflects current state of sound effects
898006479cSDmitry Torokhov * @sw: reflects current state of device's switches
908006479cSDmitry Torokhov * @open: this method is called when the very first user calls
918006479cSDmitry Torokhov * input_open_device(). The driver must prepare the device
928006479cSDmitry Torokhov * to start generating events (start polling thread,
93a1816164SPatrik Fimml * request an IRQ, submit URB, etc.). The meaning of open() is
94a1816164SPatrik Fimml * to start providing events to the input core.
958006479cSDmitry Torokhov * @close: this method is called when the very last user calls
96a1816164SPatrik Fimml * input_close_device(). The meaning of close() is to stop
97a1816164SPatrik Fimml * providing events to the input core.
988006479cSDmitry Torokhov * @flush: purges the device. Most commonly used to get rid of force
998006479cSDmitry Torokhov * feedback effects loaded into the device when disconnecting
1008006479cSDmitry Torokhov * from it
1018006479cSDmitry Torokhov * @event: event handler for events sent _to_ the device, like EV_LED
1028006479cSDmitry Torokhov * or EV_SND. The device is expected to carry out the requested
1038006479cSDmitry Torokhov * action (turn on a LED, play sound, etc.) The call is protected
1048006479cSDmitry Torokhov * by @event_lock and must not sleep
1058006479cSDmitry Torokhov * @grab: input handle that currently has the device grabbed (via
1068006479cSDmitry Torokhov * EVIOCGRAB ioctl). When a handle grabs a device it becomes sole
1078006479cSDmitry Torokhov * recipient for all input events coming from the device
10883510e5fSMasanari Iida * @event_lock: this spinlock is taken when input core receives
1098006479cSDmitry Torokhov * and processes a new event for the device (in input_event()).
1108006479cSDmitry Torokhov * Code that accesses and/or modifies parameters of a device
1118006479cSDmitry Torokhov * (such as keymap or absmin, absmax, absfuzz, etc.) after device
1128006479cSDmitry Torokhov * has been registered with input core must take this lock.
1138006479cSDmitry Torokhov * @mutex: serializes calls to open(), close() and flush() methods
1148006479cSDmitry Torokhov * @users: stores number of users (input handlers) that opened this
1158006479cSDmitry Torokhov * device. It is used by input_open_device() and input_close_device()
1168006479cSDmitry Torokhov * to make sure that dev->open() is only called when the first
1178006479cSDmitry Torokhov * user opens device and dev->close() is called when the very
1188006479cSDmitry Torokhov * last user closes the device
1198006479cSDmitry Torokhov * @going_away: marks devices that are in a middle of unregistering and
1208006479cSDmitry Torokhov * causes input_open_device*() fail with -ENODEV.
1218006479cSDmitry Torokhov * @dev: driver model's view of this device
1228006479cSDmitry Torokhov * @h_list: list of input handles associated with the device. When
1238006479cSDmitry Torokhov * accessing the list dev->mutex must be held
1248006479cSDmitry Torokhov * @node: used to place the device onto input_dev_list
125800963fdSHenrik Rydberg * @num_vals: number of values queued in the current frame
126800963fdSHenrik Rydberg * @max_vals: maximum number of values queued in a frame
127800963fdSHenrik Rydberg * @vals: array of values queued in the current frame
1282be975c6SDmitry Torokhov * @devres_managed: indicates that devices is managed with devres framework
1292be975c6SDmitry Torokhov * and needs not be explicitly unregistered or freed.
1303b51c44bSAtif Niyaz * @timestamp: storage for a timestamp set by input_set_timestamp called
1313b51c44bSAtif Niyaz * by a driver
132a1816164SPatrik Fimml * @inhibited: indicates that the input device is inhibited. If that is
133a1816164SPatrik Fimml * the case then input core ignores any events generated by the device.
134a1816164SPatrik Fimml * Device's close() is called when it is being inhibited and its open()
135a1816164SPatrik Fimml * is called when it is being uninhibited.
1368006479cSDmitry Torokhov */
1371da177e4SLinus Torvalds struct input_dev {
1385b6271bdSDmitry Torokhov const char *name;
1395b6271bdSDmitry Torokhov const char *phys;
1405b6271bdSDmitry Torokhov const char *uniq;
1411da177e4SLinus Torvalds struct input_id id;
1421da177e4SLinus Torvalds
14385b77200SHenrik Rydberg unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
14485b77200SHenrik Rydberg
1457b19ada2SJiri Slaby unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
1467b19ada2SJiri Slaby unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
1477b19ada2SJiri Slaby unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
1487b19ada2SJiri Slaby unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
1497b19ada2SJiri Slaby unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
1507b19ada2SJiri Slaby unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
1517b19ada2SJiri Slaby unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
1527b19ada2SJiri Slaby unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
1537b19ada2SJiri Slaby unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
1541da177e4SLinus Torvalds
15563a6404dSHenrik Rydberg unsigned int hint_events_per_packet;
15663a6404dSHenrik Rydberg
1571da177e4SLinus Torvalds unsigned int keycodemax;
1581da177e4SLinus Torvalds unsigned int keycodesize;
1591da177e4SLinus Torvalds void *keycode;
1608613e4c2SMauro Carvalho Chehab
16158b93995SDmitry Torokhov int (*setkeycode)(struct input_dev *dev,
1628613e4c2SMauro Carvalho Chehab const struct input_keymap_entry *ke,
1638613e4c2SMauro Carvalho Chehab unsigned int *old_keycode);
164aebd636bSDmitry Torokhov int (*getkeycode)(struct input_dev *dev,
1658613e4c2SMauro Carvalho Chehab struct input_keymap_entry *ke);
1661da177e4SLinus Torvalds
167509ca1a9SAnssi Hannula struct ff_device *ff;
168509ca1a9SAnssi Hannula
169e95656eaSDmitry Torokhov struct input_dev_poller *poller;
170e95656eaSDmitry Torokhov
1711da177e4SLinus Torvalds unsigned int repeat_key;
1721da177e4SLinus Torvalds struct timer_list timer;
1731da177e4SLinus Torvalds
174d31b2865SDaniel Mack int rep[REP_CNT];
1751da177e4SLinus Torvalds
1768d18fba2SHenrik Rydberg struct input_mt *mt;
17740d007e7SHenrik Rydberg
178d31b2865SDaniel Mack struct input_absinfo *absinfo;
179d31b2865SDaniel Mack
1807b19ada2SJiri Slaby unsigned long key[BITS_TO_LONGS(KEY_CNT)];
1817b19ada2SJiri Slaby unsigned long led[BITS_TO_LONGS(LED_CNT)];
1827b19ada2SJiri Slaby unsigned long snd[BITS_TO_LONGS(SND_CNT)];
1837b19ada2SJiri Slaby unsigned long sw[BITS_TO_LONGS(SW_CNT)];
1841da177e4SLinus Torvalds
1851da177e4SLinus Torvalds int (*open)(struct input_dev *dev);
1861da177e4SLinus Torvalds void (*close)(struct input_dev *dev);
1871da177e4SLinus Torvalds int (*flush)(struct input_dev *dev, struct file *file);
1881da177e4SLinus Torvalds int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1891da177e4SLinus Torvalds
1902be85279SArnd Bergmann struct input_handle __rcu *grab;
1910fbf87caSDmitry Torokhov
1928006479cSDmitry Torokhov spinlock_t event_lock;
1938006479cSDmitry Torokhov struct mutex mutex;
1948006479cSDmitry Torokhov
1950fbf87caSDmitry Torokhov unsigned int users;
196ffd0db97SDmitry Torokhov bool going_away;
1970fbf87caSDmitry Torokhov
1989657d75cSDmitry Torokhov struct device dev;
1991da177e4SLinus Torvalds
2001da177e4SLinus Torvalds struct list_head h_list;
2011da177e4SLinus Torvalds struct list_head node;
2024369c64cSHenrik Rydberg
2034369c64cSHenrik Rydberg unsigned int num_vals;
2044369c64cSHenrik Rydberg unsigned int max_vals;
2054369c64cSHenrik Rydberg struct input_value *vals;
2062be975c6SDmitry Torokhov
2072be975c6SDmitry Torokhov bool devres_managed;
2083b51c44bSAtif Niyaz
2093b51c44bSAtif Niyaz ktime_t timestamp[INPUT_CLK_MAX];
210a1816164SPatrik Fimml
211a1816164SPatrik Fimml bool inhibited;
2121da177e4SLinus Torvalds };
2139657d75cSDmitry Torokhov #define to_input_dev(d) container_of(d, struct input_dev, dev)
2141da177e4SLinus Torvalds
215ddc5d341SDmitry Torokhov /*
216ddc5d341SDmitry Torokhov * Verify that we are in sync with input_device_id mod_devicetable.h #defines
217ddc5d341SDmitry Torokhov */
218ddc5d341SDmitry Torokhov
219ddc5d341SDmitry Torokhov #if EV_MAX != INPUT_DEVICE_ID_EV_MAX
220ddc5d341SDmitry Torokhov #error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
221ddc5d341SDmitry Torokhov #endif
222ddc5d341SDmitry Torokhov
223dc24f0e7SSam Ravnborg #if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
224dc24f0e7SSam Ravnborg #error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
225dc24f0e7SSam Ravnborg #endif
226dc24f0e7SSam Ravnborg
227ddc5d341SDmitry Torokhov #if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
228ddc5d341SDmitry Torokhov #error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
229ddc5d341SDmitry Torokhov #endif
230ddc5d341SDmitry Torokhov
231ddc5d341SDmitry Torokhov #if REL_MAX != INPUT_DEVICE_ID_REL_MAX
232ddc5d341SDmitry Torokhov #error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
233ddc5d341SDmitry Torokhov #endif
234ddc5d341SDmitry Torokhov
235ddc5d341SDmitry Torokhov #if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
236ddc5d341SDmitry Torokhov #error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
237ddc5d341SDmitry Torokhov #endif
238ddc5d341SDmitry Torokhov
239ddc5d341SDmitry Torokhov #if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
240ddc5d341SDmitry Torokhov #error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
241ddc5d341SDmitry Torokhov #endif
242ddc5d341SDmitry Torokhov
243ddc5d341SDmitry Torokhov #if LED_MAX != INPUT_DEVICE_ID_LED_MAX
244ddc5d341SDmitry Torokhov #error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
245ddc5d341SDmitry Torokhov #endif
246ddc5d341SDmitry Torokhov
247ddc5d341SDmitry Torokhov #if SND_MAX != INPUT_DEVICE_ID_SND_MAX
248ddc5d341SDmitry Torokhov #error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
249ddc5d341SDmitry Torokhov #endif
250ddc5d341SDmitry Torokhov
251ddc5d341SDmitry Torokhov #if FF_MAX != INPUT_DEVICE_ID_FF_MAX
252ddc5d341SDmitry Torokhov #error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
253ddc5d341SDmitry Torokhov #endif
254ddc5d341SDmitry Torokhov
255ddc5d341SDmitry Torokhov #if SW_MAX != INPUT_DEVICE_ID_SW_MAX
256ddc5d341SDmitry Torokhov #error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
257ddc5d341SDmitry Torokhov #endif
258ddc5d341SDmitry Torokhov
2598724ecb0SDmitry Torokhov #if INPUT_PROP_MAX != INPUT_DEVICE_ID_PROP_MAX
2608724ecb0SDmitry Torokhov #error "INPUT_PROP_MAX and INPUT_DEVICE_ID_PROP_MAX do not match"
2618724ecb0SDmitry Torokhov #endif
2628724ecb0SDmitry Torokhov
2631da177e4SLinus Torvalds #define INPUT_DEVICE_ID_MATCH_DEVICE \
2641da177e4SLinus Torvalds (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
2651da177e4SLinus Torvalds #define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
2661da177e4SLinus Torvalds (INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)
2671da177e4SLinus Torvalds
2681da177e4SLinus Torvalds struct input_handle;
2691da177e4SLinus Torvalds
270c7e8dc6eSDmitry Torokhov /**
271c7e8dc6eSDmitry Torokhov * struct input_handler - implements one of interfaces for input devices
272c7e8dc6eSDmitry Torokhov * @private: driver-specific data
2738006479cSDmitry Torokhov * @event: event handler. This method is being called by input core with
2748006479cSDmitry Torokhov * interrupts disabled and dev->event_lock spinlock held and so
2758006479cSDmitry Torokhov * it may not sleep
2764369c64cSHenrik Rydberg * @events: event sequence handler. This method is being called by
2774369c64cSHenrik Rydberg * input core with interrupts disabled and dev->event_lock
27814498e99SDmitry Torokhov * spinlock held and so it may not sleep. The method must return
27914498e99SDmitry Torokhov * number of events passed to it.
280ef7995f4SDmitry Torokhov * @filter: similar to @event; separates normal event handlers from
281ef7995f4SDmitry Torokhov * "filters".
2820b7024acSDmitry Torokhov * @match: called after comparing device's id with handler's id_table
2830b7024acSDmitry Torokhov * to perform fine-grained matching between device and handler
284c7e8dc6eSDmitry Torokhov * @connect: called when attaching a handler to an input device
285c7e8dc6eSDmitry Torokhov * @disconnect: disconnects a handler from input device
286c7e8dc6eSDmitry Torokhov * @start: starts handler for given handle. This function is called by
287c7e8dc6eSDmitry Torokhov * input core right after connect() method and also when a process
288c7e8dc6eSDmitry Torokhov * that "grabbed" a device releases it
289*57a06363SDmitry Torokhov * @passive_observer: set to %true by drivers only interested in observing
290*57a06363SDmitry Torokhov * data stream from devices if there are other users present. Such
291*57a06363SDmitry Torokhov * drivers will not result in starting underlying hardware device
292*57a06363SDmitry Torokhov * when input_open_device() is called for their handles
2937f8d4cadSDmitry Torokhov * @legacy_minors: set to %true by drivers using legacy minor ranges
2947f8d4cadSDmitry Torokhov * @minor: beginning of range of 32 legacy minors for devices this driver
295c7e8dc6eSDmitry Torokhov * can provide
296c7e8dc6eSDmitry Torokhov * @name: name of the handler, to be shown in /proc/bus/input/handlers
297c7e8dc6eSDmitry Torokhov * @id_table: pointer to a table of input_device_ids this driver can
298c7e8dc6eSDmitry Torokhov * handle
299c7e8dc6eSDmitry Torokhov * @h_list: list of input handles associated with the handler
300c7e8dc6eSDmitry Torokhov * @node: for placing the driver onto input_handler_list
3018006479cSDmitry Torokhov *
3028006479cSDmitry Torokhov * Input handlers attach to input devices and create input handles. There
3038006479cSDmitry Torokhov * are likely several handlers attached to any given input device at the
3048006479cSDmitry Torokhov * same time. All of them will get their copy of input event generated by
3058006479cSDmitry Torokhov * the device.
3068006479cSDmitry Torokhov *
307ef7995f4SDmitry Torokhov * The very same structure is used to implement input filters. Input core
308ef7995f4SDmitry Torokhov * allows filters to run first and will not pass event to regular handlers
309ef7995f4SDmitry Torokhov * if any of the filters indicate that the event should be filtered (by
310ef7995f4SDmitry Torokhov * returning %true from their filter() method).
311ef7995f4SDmitry Torokhov *
3128006479cSDmitry Torokhov * Note that input core serializes calls to connect() and disconnect()
3138006479cSDmitry Torokhov * methods.
314c7e8dc6eSDmitry Torokhov */
3151da177e4SLinus Torvalds struct input_handler {
3161da177e4SLinus Torvalds
3171da177e4SLinus Torvalds void *private;
3181da177e4SLinus Torvalds
3191da177e4SLinus Torvalds void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
32014498e99SDmitry Torokhov unsigned int (*events)(struct input_handle *handle,
32114498e99SDmitry Torokhov struct input_value *vals, unsigned int count);
322ef7995f4SDmitry Torokhov bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
3230b7024acSDmitry Torokhov bool (*match)(struct input_handler *handler, struct input_dev *dev);
3245b2a0826SDmitry Torokhov int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
3251da177e4SLinus Torvalds void (*disconnect)(struct input_handle *handle);
326c7e8dc6eSDmitry Torokhov void (*start)(struct input_handle *handle);
3271da177e4SLinus Torvalds
328*57a06363SDmitry Torokhov bool passive_observer;
3297f8d4cadSDmitry Torokhov bool legacy_minors;
3301da177e4SLinus Torvalds int minor;
33166e66118SDmitry Torokhov const char *name;
3321da177e4SLinus Torvalds
33366e66118SDmitry Torokhov const struct input_device_id *id_table;
3341da177e4SLinus Torvalds
3351da177e4SLinus Torvalds struct list_head h_list;
3361da177e4SLinus Torvalds struct list_head node;
3371da177e4SLinus Torvalds };
3381da177e4SLinus Torvalds
3398006479cSDmitry Torokhov /**
3408006479cSDmitry Torokhov * struct input_handle - links input device with an input handler
3418006479cSDmitry Torokhov * @private: handler-specific data
3428006479cSDmitry Torokhov * @open: counter showing whether the handle is 'open', i.e. should deliver
3438006479cSDmitry Torokhov * events from its device
3448006479cSDmitry Torokhov * @name: name given to the handle by handler that created it
3458006479cSDmitry Torokhov * @dev: input device the handle is attached to
3468006479cSDmitry Torokhov * @handler: handler that works with the device through this handle
3478006479cSDmitry Torokhov * @handle_events: event sequence handler. It is set up by the input core
3488006479cSDmitry Torokhov * according to event handling method specified in the @handler. See
3498006479cSDmitry Torokhov * input_handle_setup_event_handler().
3508006479cSDmitry Torokhov * This method is being called by the input core with interrupts disabled
3511da177e4SLinus Torvalds * and dev->event_lock spinlock held and so it may not sleep.
3521da177e4SLinus Torvalds * @d_node: used to put the handle on device's list of attached handles
3531da177e4SLinus Torvalds * @h_node: used to put the handle on handler's list of handles from which
3541da177e4SLinus Torvalds * it gets events
3551da177e4SLinus Torvalds */
35666e66118SDmitry Torokhov struct input_handle {
3571da177e4SLinus Torvalds void *private;
3581da177e4SLinus Torvalds
3591da177e4SLinus Torvalds int open;
3601da177e4SLinus Torvalds const char *name;
3611da177e4SLinus Torvalds
3621da177e4SLinus Torvalds struct input_dev *dev;
3631da177e4SLinus Torvalds struct input_handler *handler;
3641da177e4SLinus Torvalds
3652be975c6SDmitry Torokhov unsigned int (*handle_events)(struct input_handle *handle,
3662be975c6SDmitry Torokhov struct input_value *vals,
367f60d2b11SDmitry Torokhov unsigned int count);
368d19fbe8aSDmitry Torokhov
369d19fbe8aSDmitry Torokhov struct list_head d_node;
370d19fbe8aSDmitry Torokhov struct list_head h_node;
371a7097ff8SDmitry Torokhov };
372d19fbe8aSDmitry Torokhov
373d19fbe8aSDmitry Torokhov struct input_dev __must_check *input_allocate_device(void);
374d19fbe8aSDmitry Torokhov struct input_dev __must_check *devm_input_allocate_device(struct device *);
375d19fbe8aSDmitry Torokhov void input_free_device(struct input_dev *dev);
376a7097ff8SDmitry Torokhov
input_get_device(struct input_dev * dev)3779657d75cSDmitry Torokhov static inline struct input_dev *input_get_device(struct input_dev *dev)
378d19fbe8aSDmitry Torokhov {
379d19fbe8aSDmitry Torokhov return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
3803abccf36SDmitry Torokhov }
3813abccf36SDmitry Torokhov
input_put_device(struct input_dev * dev)3823797fec1SDmitry Torokhov static inline void input_put_device(struct input_dev *dev)
3833abccf36SDmitry Torokhov {
3843abccf36SDmitry Torokhov if (dev)
3853abccf36SDmitry Torokhov put_device(&dev->dev);
3863abccf36SDmitry Torokhov }
3873797fec1SDmitry Torokhov
input_get_drvdata(struct input_dev * dev)3883abccf36SDmitry Torokhov static inline void *input_get_drvdata(struct input_dev *dev)
3893abccf36SDmitry Torokhov {
390501cc54cSDmitry Torokhov return dev_get_drvdata(&dev->dev);
3911da177e4SLinus Torvalds }
3921da177e4SLinus Torvalds
input_set_drvdata(struct input_dev * dev,void * data)393b50b5216SDmitry Torokhov static inline void input_set_drvdata(struct input_dev *dev, void *data)
394b50b5216SDmitry Torokhov {
395e95656eaSDmitry Torokhov dev_set_drvdata(&dev->dev, data);
396e95656eaSDmitry Torokhov }
397e95656eaSDmitry Torokhov
398e95656eaSDmitry Torokhov int __must_check input_register_device(struct input_dev *);
399e95656eaSDmitry Torokhov void input_unregister_device(struct input_dev *);
400894616f7SDmitry Torokhov
401e95656eaSDmitry Torokhov void input_reset_device(struct input_dev *);
402501cc54cSDmitry Torokhov
4031da177e4SLinus Torvalds int input_setup_polling(struct input_dev *dev,
4041da177e4SLinus Torvalds void (*poll_fn)(struct input_dev *dev));
4057f8d4cadSDmitry Torokhov void input_set_poll_interval(struct input_dev *dev, unsigned int interval);
4067f8d4cadSDmitry Torokhov void input_set_min_poll_interval(struct input_dev *dev, unsigned int interval);
4077f8d4cadSDmitry Torokhov void input_set_max_poll_interval(struct input_dev *dev, unsigned int interval);
4087f8d4cadSDmitry Torokhov int input_get_poll_interval(struct input_dev *dev);
40966d2a595SDmitry Torokhov
41066d2a595SDmitry Torokhov int __must_check input_register_handler(struct input_handler *);
41166d2a595SDmitry Torokhov void input_unregister_handler(struct input_handler *);
4125b2a0826SDmitry Torokhov
4135b2a0826SDmitry Torokhov int __must_check input_get_new_minor(int legacy_base, unsigned int legacy_num,
4145b2a0826SDmitry Torokhov bool allow_dynamic);
4151da177e4SLinus Torvalds void input_free_minor(unsigned int minor);
4161da177e4SLinus Torvalds
4171da177e4SLinus Torvalds int input_handler_for_each_handle(struct input_handler *, void *data,
4181da177e4SLinus Torvalds int (*fn)(struct input_handle *, void *));
4191da177e4SLinus Torvalds
4201da177e4SLinus Torvalds int input_register_handle(struct input_handle *);
4211da177e4SLinus Torvalds void input_unregister_handle(struct input_handle *);
4221da177e4SLinus Torvalds
4233b51c44bSAtif Niyaz int input_grab_device(struct input_handle *);
4243b51c44bSAtif Niyaz void input_release_device(struct input_handle *);
4253b51c44bSAtif Niyaz
4261da177e4SLinus Torvalds int input_open_device(struct input_handle *);
4270e739d28SDmitry Torokhov void input_close_device(struct input_handle *);
4281da177e4SLinus Torvalds
4291da177e4SLinus Torvalds int input_flush_device(struct input_handle *handle, struct file *file);
4301da177e4SLinus Torvalds
4311da177e4SLinus Torvalds void input_set_timestamp(struct input_dev *dev, ktime_t timestamp);
4321da177e4SLinus Torvalds ktime_t *input_get_timestamp(struct input_dev *dev);
4331da177e4SLinus Torvalds
4341da177e4SLinus Torvalds void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
4351da177e4SLinus Torvalds void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
4361da177e4SLinus Torvalds
input_report_key(struct input_dev * dev,unsigned int code,int value)4371da177e4SLinus Torvalds static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
4381da177e4SLinus Torvalds {
4391da177e4SLinus Torvalds input_event(dev, EV_KEY, code, !!value);
4401da177e4SLinus Torvalds }
4411da177e4SLinus Torvalds
input_report_rel(struct input_dev * dev,unsigned int code,int value)4421da177e4SLinus Torvalds static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
4431da177e4SLinus Torvalds {
4441da177e4SLinus Torvalds input_event(dev, EV_REL, code, value);
4451da177e4SLinus Torvalds }
4461da177e4SLinus Torvalds
input_report_abs(struct input_dev * dev,unsigned int code,int value)4471da177e4SLinus Torvalds static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
4481da177e4SLinus Torvalds {
44931581066SRichard Purdie input_event(dev, EV_ABS, code, value);
45031581066SRichard Purdie }
45131581066SRichard Purdie
input_report_ff_status(struct input_dev * dev,unsigned int code,int value)45231581066SRichard Purdie static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
45331581066SRichard Purdie {
4541da177e4SLinus Torvalds input_event(dev, EV_FF_STATUS, code, value);
4551da177e4SLinus Torvalds }
4561da177e4SLinus Torvalds
input_report_switch(struct input_dev * dev,unsigned int code,int value)4571da177e4SLinus Torvalds static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
4581da177e4SLinus Torvalds {
4595e5ee686SHenrik Rydberg input_event(dev, EV_SW, code, !!value);
4605e5ee686SHenrik Rydberg }
4615e5ee686SHenrik Rydberg
input_sync(struct input_dev * dev)4625e5ee686SHenrik Rydberg static inline void input_sync(struct input_dev *dev)
4635e5ee686SHenrik Rydberg {
464534565f2SDmitry Torokhov input_event(dev, EV_SYN, SYN_REPORT, 0);
465534565f2SDmitry Torokhov }
46663a6404dSHenrik Rydberg
input_mt_sync(struct input_dev * dev)46763a6404dSHenrik Rydberg static inline void input_mt_sync(struct input_dev *dev)
46863a6404dSHenrik Rydberg {
46963a6404dSHenrik Rydberg input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
47063a6404dSHenrik Rydberg }
47163a6404dSHenrik Rydberg
47263a6404dSHenrik Rydberg void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
47363a6404dSHenrik Rydberg
47463a6404dSHenrik Rydberg /**
47563a6404dSHenrik Rydberg * input_set_events_per_packet - tell handlers about the driver event rate
47663a6404dSHenrik Rydberg * @dev: the input device used by the driver
47763a6404dSHenrik Rydberg * @n_events: the average number of events between calls to input_sync()
47863a6404dSHenrik Rydberg *
47963a6404dSHenrik Rydberg * If the event rate sent from a device is unusually large, use this
48063a6404dSHenrik Rydberg * function to set the expected event rate. This will allow handlers
481d31b2865SDaniel Mack * to set up an appropriate buffer size for the event stream, in order
482d31b2865SDaniel Mack * to minimize information loss.
483d31b2865SDaniel Mack */
input_set_events_per_packet(struct input_dev * dev,int n_events)484cb66b9baSHans de Goede static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
485cb66b9baSHans de Goede {
4861da177e4SLinus Torvalds dev->hint_events_per_packet = n_events;
4877957e9c4SDaniel Mack }
4887957e9c4SDaniel Mack
4897957e9c4SDaniel Mack void input_alloc_absinfo(struct input_dev *dev);
4907957e9c4SDaniel Mack void input_set_abs_params(struct input_dev *dev, unsigned int axis,
491d31b2865SDaniel Mack int min, int max, int fuzz, int flat);
4927957e9c4SDaniel Mack void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
4937957e9c4SDaniel Mack const struct input_dev *src, unsigned int src_axis);
4947957e9c4SDaniel Mack
4957957e9c4SDaniel Mack #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item) \
4967957e9c4SDaniel Mack static inline int input_abs_get_##_suffix(struct input_dev *dev, \
497d31b2865SDaniel Mack unsigned int axis) \
498d31b2865SDaniel Mack { \
499d31b2865SDaniel Mack return dev->absinfo ? dev->absinfo[axis]._item : 0; \
5007957e9c4SDaniel Mack } \
5017957e9c4SDaniel Mack \
502d31b2865SDaniel Mack static inline void input_abs_set_##_suffix(struct input_dev *dev, \
503d31b2865SDaniel Mack unsigned int axis, int val) \
504d31b2865SDaniel Mack { \
5057957e9c4SDaniel Mack input_alloc_absinfo(dev); \
5067957e9c4SDaniel Mack if (dev->absinfo) \
507d31b2865SDaniel Mack dev->absinfo[axis]._item = val; \
5087957e9c4SDaniel Mack }
5098613e4c2SMauro Carvalho Chehab
5108613e4c2SMauro Carvalho Chehab INPUT_GENERATE_ABS_ACCESSORS(val, value)
5118613e4c2SMauro Carvalho Chehab INPUT_GENERATE_ABS_ACCESSORS(min, minimum)
5128613e4c2SMauro Carvalho Chehab INPUT_GENERATE_ABS_ACCESSORS(max, maximum)
51358b93995SDmitry Torokhov INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
5148613e4c2SMauro Carvalho Chehab INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
515f4f37c8eSDmitry Torokhov INPUT_GENERATE_ABS_ACCESSORS(res, resolution)
51655dfce87SDmitry Torokhov
51755dfce87SDmitry Torokhov int input_scancode_to_scalar(const struct input_keymap_entry *ke,
51855dfce87SDmitry Torokhov unsigned int *scancode);
519027c71bbSPetri Gynther
520027c71bbSPetri Gynther int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
52139be39ceSAndrzej Pietrasiewicz int input_set_keycode(struct input_dev *dev,
52239be39ceSAndrzej Pietrasiewicz const struct input_keymap_entry *ke);
523a4735d40SRicardo B. Marliere
5241da177e4SLinus Torvalds bool input_match_device_id(const struct input_dev *dev,
525509ca1a9SAnssi Hannula const struct input_device_id *id);
526509ca1a9SAnssi Hannula
527509ca1a9SAnssi Hannula void input_enable_softrepeat(struct input_dev *dev, int delay, int period);
528509ca1a9SAnssi Hannula
529509ca1a9SAnssi Hannula bool input_device_enabled(struct input_dev *dev);
530509ca1a9SAnssi Hannula
531509ca1a9SAnssi Hannula extern const struct class input_class;
532509ca1a9SAnssi Hannula
533509ca1a9SAnssi Hannula /**
534509ca1a9SAnssi Hannula * struct ff_device - force-feedback part of an input device
535509ca1a9SAnssi Hannula * @upload: Called to upload an new effect into device
536509ca1a9SAnssi Hannula * @erase: Called to erase an effect from device
537509ca1a9SAnssi Hannula * @playback: Called to request device to start playing specified effect
538509ca1a9SAnssi Hannula * @set_gain: Called to set specified gain
539509ca1a9SAnssi Hannula * @set_autocenter: Called to auto-center device
540509ca1a9SAnssi Hannula * @destroy: called by input core when parent input device is being
5418006479cSDmitry Torokhov * destroyed
542509ca1a9SAnssi Hannula * @private: driver-specific data, will be freed automatically
543509ca1a9SAnssi Hannula * @ffbit: bitmap of force feedback capabilities truly supported by
544509ca1a9SAnssi Hannula * device (not emulated like ones in input_dev->ffbit)
545509ca1a9SAnssi Hannula * @mutex: mutex for serializing access to the device
546509ca1a9SAnssi Hannula * @max_effects: maximum number of effects supported by device
547bf3204cbSDmitry Torokhov * @effects: pointer to an array of effects currently loaded into device
548bf3204cbSDmitry Torokhov * @effect_owners: array of effect owners; when file handle owning
549bf3204cbSDmitry Torokhov * an effect gets closed the effect is automatically erased
550bf3204cbSDmitry Torokhov *
551509ca1a9SAnssi Hannula * Every force-feedback device must implement upload() and playback()
552509ca1a9SAnssi Hannula * methods; erase() is optional. set_gain() and set_autocenter() need
553509ca1a9SAnssi Hannula * only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER
554509ca1a9SAnssi Hannula * bits.
555509ca1a9SAnssi Hannula *
556509ca1a9SAnssi Hannula * Note that playback(), set_gain() and set_autocenter() are called with
557509ca1a9SAnssi Hannula * dev->event_lock spinlock held and interrupts off and thus may not
558509ca1a9SAnssi Hannula * sleep.
559509ca1a9SAnssi Hannula */
560509ca1a9SAnssi Hannula struct ff_device {
561509ca1a9SAnssi Hannula int (*upload)(struct input_dev *dev, struct ff_effect *effect,
562509ca1a9SAnssi Hannula struct ff_effect *old);
563509ca1a9SAnssi Hannula int (*erase)(struct input_dev *dev, int effect_id);
564509ca1a9SAnssi Hannula
5657b19ada2SJiri Slaby int (*playback)(struct input_dev *dev, int effect_id, int value);
566509ca1a9SAnssi Hannula void (*set_gain)(struct input_dev *dev, u16 gain);
567509ca1a9SAnssi Hannula void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
568509ca1a9SAnssi Hannula
569509ca1a9SAnssi Hannula void (*destroy)(struct ff_device *);
570509ca1a9SAnssi Hannula
571787650ccSKees Cook void *private;
572509ca1a9SAnssi Hannula
573509ca1a9SAnssi Hannula unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
57405be8b81SDan Carpenter
575509ca1a9SAnssi Hannula struct mutex mutex;
576509ca1a9SAnssi Hannula
577509ca1a9SAnssi Hannula int max_effects;
578509ca1a9SAnssi Hannula struct ff_effect *effects;
579509ca1a9SAnssi Hannula struct file *effect_owners[] __counted_by(max_effects);
580509ca1a9SAnssi Hannula };
581e8b95728SDmitry Torokhov
582509ca1a9SAnssi Hannula int input_ff_create(struct input_dev *dev, unsigned int max_effects);
5837d928a2bSAnssi Hannula void input_ff_destroy(struct input_dev *dev);
5847d928a2bSAnssi Hannula
5857d928a2bSAnssi Hannula int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
5861da177e4SLinus Torvalds
587 int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
588 int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
589 int input_ff_flush(struct input_dev *dev, struct file *file);
590
591 int input_ff_create_memless(struct input_dev *dev, void *data,
592 int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
593
594 #endif
595