xref: /linux-6.15/include/linux/input.h (revision e95656ea)
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 
24*e95656eaSDmitry Torokhov struct input_dev_poller;
25*e95656eaSDmitry 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
76*e95656eaSDmitry Torokhov  * @poller: poller structure associated with the device if device is
77*e95656eaSDmitry 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,
938006479cSDmitry Torokhov  *	request an IRQ, submit URB, etc.)
948006479cSDmitry Torokhov  * @close: this method is called when the very last user calls
958006479cSDmitry Torokhov  *	input_close_device().
968006479cSDmitry Torokhov  * @flush: purges the device. Most commonly used to get rid of force
978006479cSDmitry Torokhov  *	feedback effects loaded into the device when disconnecting
988006479cSDmitry Torokhov  *	from it
998006479cSDmitry Torokhov  * @event: event handler for events sent _to_ the device, like EV_LED
1008006479cSDmitry Torokhov  *	or EV_SND. The device is expected to carry out the requested
1018006479cSDmitry Torokhov  *	action (turn on a LED, play sound, etc.) The call is protected
1028006479cSDmitry Torokhov  *	by @event_lock and must not sleep
1038006479cSDmitry Torokhov  * @grab: input handle that currently has the device grabbed (via
1048006479cSDmitry Torokhov  *	EVIOCGRAB ioctl). When a handle grabs a device it becomes sole
1058006479cSDmitry Torokhov  *	recipient for all input events coming from the device
10683510e5fSMasanari Iida  * @event_lock: this spinlock is taken when input core receives
1078006479cSDmitry Torokhov  *	and processes a new event for the device (in input_event()).
1088006479cSDmitry Torokhov  *	Code that accesses and/or modifies parameters of a device
1098006479cSDmitry Torokhov  *	(such as keymap or absmin, absmax, absfuzz, etc.) after device
1108006479cSDmitry Torokhov  *	has been registered with input core must take this lock.
1118006479cSDmitry Torokhov  * @mutex: serializes calls to open(), close() and flush() methods
1128006479cSDmitry Torokhov  * @users: stores number of users (input handlers) that opened this
1138006479cSDmitry Torokhov  *	device. It is used by input_open_device() and input_close_device()
1148006479cSDmitry Torokhov  *	to make sure that dev->open() is only called when the first
1158006479cSDmitry Torokhov  *	user opens device and dev->close() is called when the very
1168006479cSDmitry Torokhov  *	last user closes the device
1178006479cSDmitry Torokhov  * @going_away: marks devices that are in a middle of unregistering and
1188006479cSDmitry Torokhov  *	causes input_open_device*() fail with -ENODEV.
1198006479cSDmitry Torokhov  * @dev: driver model's view of this device
1208006479cSDmitry Torokhov  * @h_list: list of input handles associated with the device. When
1218006479cSDmitry Torokhov  *	accessing the list dev->mutex must be held
1228006479cSDmitry Torokhov  * @node: used to place the device onto input_dev_list
123800963fdSHenrik Rydberg  * @num_vals: number of values queued in the current frame
124800963fdSHenrik Rydberg  * @max_vals: maximum number of values queued in a frame
125800963fdSHenrik Rydberg  * @vals: array of values queued in the current frame
1262be975c6SDmitry Torokhov  * @devres_managed: indicates that devices is managed with devres framework
1272be975c6SDmitry Torokhov  *	and needs not be explicitly unregistered or freed.
1283b51c44bSAtif Niyaz  * @timestamp: storage for a timestamp set by input_set_timestamp called
1293b51c44bSAtif Niyaz  *  by a driver
1308006479cSDmitry Torokhov  */
1311da177e4SLinus Torvalds struct input_dev {
1325b6271bdSDmitry Torokhov 	const char *name;
1335b6271bdSDmitry Torokhov 	const char *phys;
1345b6271bdSDmitry Torokhov 	const char *uniq;
1351da177e4SLinus Torvalds 	struct input_id id;
1361da177e4SLinus Torvalds 
13785b77200SHenrik Rydberg 	unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
13885b77200SHenrik Rydberg 
1397b19ada2SJiri Slaby 	unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
1407b19ada2SJiri Slaby 	unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
1417b19ada2SJiri Slaby 	unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
1427b19ada2SJiri Slaby 	unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
1437b19ada2SJiri Slaby 	unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
1447b19ada2SJiri Slaby 	unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
1457b19ada2SJiri Slaby 	unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
1467b19ada2SJiri Slaby 	unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
1477b19ada2SJiri Slaby 	unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
1481da177e4SLinus Torvalds 
14963a6404dSHenrik Rydberg 	unsigned int hint_events_per_packet;
15063a6404dSHenrik Rydberg 
1511da177e4SLinus Torvalds 	unsigned int keycodemax;
1521da177e4SLinus Torvalds 	unsigned int keycodesize;
1531da177e4SLinus Torvalds 	void *keycode;
1548613e4c2SMauro Carvalho Chehab 
15558b93995SDmitry Torokhov 	int (*setkeycode)(struct input_dev *dev,
1568613e4c2SMauro Carvalho Chehab 			  const struct input_keymap_entry *ke,
1578613e4c2SMauro Carvalho Chehab 			  unsigned int *old_keycode);
158aebd636bSDmitry Torokhov 	int (*getkeycode)(struct input_dev *dev,
1598613e4c2SMauro Carvalho Chehab 			  struct input_keymap_entry *ke);
1601da177e4SLinus Torvalds 
161509ca1a9SAnssi Hannula 	struct ff_device *ff;
162509ca1a9SAnssi Hannula 
163*e95656eaSDmitry Torokhov 	struct input_dev_poller *poller;
164*e95656eaSDmitry Torokhov 
1651da177e4SLinus Torvalds 	unsigned int repeat_key;
1661da177e4SLinus Torvalds 	struct timer_list timer;
1671da177e4SLinus Torvalds 
168d31b2865SDaniel Mack 	int rep[REP_CNT];
1691da177e4SLinus Torvalds 
1708d18fba2SHenrik Rydberg 	struct input_mt *mt;
17140d007e7SHenrik Rydberg 
172d31b2865SDaniel Mack 	struct input_absinfo *absinfo;
173d31b2865SDaniel Mack 
1747b19ada2SJiri Slaby 	unsigned long key[BITS_TO_LONGS(KEY_CNT)];
1757b19ada2SJiri Slaby 	unsigned long led[BITS_TO_LONGS(LED_CNT)];
1767b19ada2SJiri Slaby 	unsigned long snd[BITS_TO_LONGS(SND_CNT)];
1777b19ada2SJiri Slaby 	unsigned long sw[BITS_TO_LONGS(SW_CNT)];
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds 	int (*open)(struct input_dev *dev);
1801da177e4SLinus Torvalds 	void (*close)(struct input_dev *dev);
1811da177e4SLinus Torvalds 	int (*flush)(struct input_dev *dev, struct file *file);
1821da177e4SLinus Torvalds 	int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
1831da177e4SLinus Torvalds 
1842be85279SArnd Bergmann 	struct input_handle __rcu *grab;
1850fbf87caSDmitry Torokhov 
1868006479cSDmitry Torokhov 	spinlock_t event_lock;
1878006479cSDmitry Torokhov 	struct mutex mutex;
1888006479cSDmitry Torokhov 
1890fbf87caSDmitry Torokhov 	unsigned int users;
190ffd0db97SDmitry Torokhov 	bool going_away;
1910fbf87caSDmitry Torokhov 
1929657d75cSDmitry Torokhov 	struct device dev;
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds 	struct list_head	h_list;
1951da177e4SLinus Torvalds 	struct list_head	node;
1964369c64cSHenrik Rydberg 
1974369c64cSHenrik Rydberg 	unsigned int num_vals;
1984369c64cSHenrik Rydberg 	unsigned int max_vals;
1994369c64cSHenrik Rydberg 	struct input_value *vals;
2002be975c6SDmitry Torokhov 
2012be975c6SDmitry Torokhov 	bool devres_managed;
2023b51c44bSAtif Niyaz 
2033b51c44bSAtif Niyaz 	ktime_t timestamp[INPUT_CLK_MAX];
2041da177e4SLinus Torvalds };
2059657d75cSDmitry Torokhov #define to_input_dev(d) container_of(d, struct input_dev, dev)
2061da177e4SLinus Torvalds 
207ddc5d341SDmitry Torokhov /*
208ddc5d341SDmitry Torokhov  * Verify that we are in sync with input_device_id mod_devicetable.h #defines
209ddc5d341SDmitry Torokhov  */
210ddc5d341SDmitry Torokhov 
211ddc5d341SDmitry Torokhov #if EV_MAX != INPUT_DEVICE_ID_EV_MAX
212ddc5d341SDmitry Torokhov #error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
213ddc5d341SDmitry Torokhov #endif
214ddc5d341SDmitry Torokhov 
215dc24f0e7SSam Ravnborg #if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
216dc24f0e7SSam Ravnborg #error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
217dc24f0e7SSam Ravnborg #endif
218dc24f0e7SSam Ravnborg 
219ddc5d341SDmitry Torokhov #if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
220ddc5d341SDmitry Torokhov #error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
221ddc5d341SDmitry Torokhov #endif
222ddc5d341SDmitry Torokhov 
223ddc5d341SDmitry Torokhov #if REL_MAX != INPUT_DEVICE_ID_REL_MAX
224ddc5d341SDmitry Torokhov #error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
225ddc5d341SDmitry Torokhov #endif
226ddc5d341SDmitry Torokhov 
227ddc5d341SDmitry Torokhov #if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
228ddc5d341SDmitry Torokhov #error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
229ddc5d341SDmitry Torokhov #endif
230ddc5d341SDmitry Torokhov 
231ddc5d341SDmitry Torokhov #if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
232ddc5d341SDmitry Torokhov #error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
233ddc5d341SDmitry Torokhov #endif
234ddc5d341SDmitry Torokhov 
235ddc5d341SDmitry Torokhov #if LED_MAX != INPUT_DEVICE_ID_LED_MAX
236ddc5d341SDmitry Torokhov #error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
237ddc5d341SDmitry Torokhov #endif
238ddc5d341SDmitry Torokhov 
239ddc5d341SDmitry Torokhov #if SND_MAX != INPUT_DEVICE_ID_SND_MAX
240ddc5d341SDmitry Torokhov #error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
241ddc5d341SDmitry Torokhov #endif
242ddc5d341SDmitry Torokhov 
243ddc5d341SDmitry Torokhov #if FF_MAX != INPUT_DEVICE_ID_FF_MAX
244ddc5d341SDmitry Torokhov #error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
245ddc5d341SDmitry Torokhov #endif
246ddc5d341SDmitry Torokhov 
247ddc5d341SDmitry Torokhov #if SW_MAX != INPUT_DEVICE_ID_SW_MAX
248ddc5d341SDmitry Torokhov #error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
249ddc5d341SDmitry Torokhov #endif
250ddc5d341SDmitry Torokhov 
2518724ecb0SDmitry Torokhov #if INPUT_PROP_MAX != INPUT_DEVICE_ID_PROP_MAX
2528724ecb0SDmitry Torokhov #error "INPUT_PROP_MAX and INPUT_DEVICE_ID_PROP_MAX do not match"
2538724ecb0SDmitry Torokhov #endif
2548724ecb0SDmitry Torokhov 
2551da177e4SLinus Torvalds #define INPUT_DEVICE_ID_MATCH_DEVICE \
2561da177e4SLinus Torvalds 	(INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
2571da177e4SLinus Torvalds #define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
2581da177e4SLinus Torvalds 	(INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds struct input_handle;
2611da177e4SLinus Torvalds 
262c7e8dc6eSDmitry Torokhov /**
263c7e8dc6eSDmitry Torokhov  * struct input_handler - implements one of interfaces for input devices
264c7e8dc6eSDmitry Torokhov  * @private: driver-specific data
2658006479cSDmitry Torokhov  * @event: event handler. This method is being called by input core with
2668006479cSDmitry Torokhov  *	interrupts disabled and dev->event_lock spinlock held and so
2678006479cSDmitry Torokhov  *	it may not sleep
2684369c64cSHenrik Rydberg  * @events: event sequence handler. This method is being called by
2694369c64cSHenrik Rydberg  *	input core with interrupts disabled and dev->event_lock
2704369c64cSHenrik Rydberg  *	spinlock held and so it may not sleep
271ef7995f4SDmitry Torokhov  * @filter: similar to @event; separates normal event handlers from
272ef7995f4SDmitry Torokhov  *	"filters".
2730b7024acSDmitry Torokhov  * @match: called after comparing device's id with handler's id_table
2740b7024acSDmitry Torokhov  *	to perform fine-grained matching between device and handler
275c7e8dc6eSDmitry Torokhov  * @connect: called when attaching a handler to an input device
276c7e8dc6eSDmitry Torokhov  * @disconnect: disconnects a handler from input device
277c7e8dc6eSDmitry Torokhov  * @start: starts handler for given handle. This function is called by
278c7e8dc6eSDmitry Torokhov  *	input core right after connect() method and also when a process
279c7e8dc6eSDmitry Torokhov  *	that "grabbed" a device releases it
2807f8d4cadSDmitry Torokhov  * @legacy_minors: set to %true by drivers using legacy minor ranges
2817f8d4cadSDmitry Torokhov  * @minor: beginning of range of 32 legacy minors for devices this driver
282c7e8dc6eSDmitry Torokhov  *	can provide
283c7e8dc6eSDmitry Torokhov  * @name: name of the handler, to be shown in /proc/bus/input/handlers
284c7e8dc6eSDmitry Torokhov  * @id_table: pointer to a table of input_device_ids this driver can
285c7e8dc6eSDmitry Torokhov  *	handle
286c7e8dc6eSDmitry Torokhov  * @h_list: list of input handles associated with the handler
287c7e8dc6eSDmitry Torokhov  * @node: for placing the driver onto input_handler_list
2888006479cSDmitry Torokhov  *
2898006479cSDmitry Torokhov  * Input handlers attach to input devices and create input handles. There
2908006479cSDmitry Torokhov  * are likely several handlers attached to any given input device at the
2918006479cSDmitry Torokhov  * same time. All of them will get their copy of input event generated by
2928006479cSDmitry Torokhov  * the device.
2938006479cSDmitry Torokhov  *
294ef7995f4SDmitry Torokhov  * The very same structure is used to implement input filters. Input core
295ef7995f4SDmitry Torokhov  * allows filters to run first and will not pass event to regular handlers
296ef7995f4SDmitry Torokhov  * if any of the filters indicate that the event should be filtered (by
297ef7995f4SDmitry Torokhov  * returning %true from their filter() method).
298ef7995f4SDmitry Torokhov  *
2998006479cSDmitry Torokhov  * Note that input core serializes calls to connect() and disconnect()
3008006479cSDmitry Torokhov  * methods.
301c7e8dc6eSDmitry Torokhov  */
3021da177e4SLinus Torvalds struct input_handler {
3031da177e4SLinus Torvalds 
3041da177e4SLinus Torvalds 	void *private;
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds 	void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
3074369c64cSHenrik Rydberg 	void (*events)(struct input_handle *handle,
3084369c64cSHenrik Rydberg 		       const struct input_value *vals, unsigned int count);
309ef7995f4SDmitry Torokhov 	bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
3100b7024acSDmitry Torokhov 	bool (*match)(struct input_handler *handler, struct input_dev *dev);
3115b2a0826SDmitry Torokhov 	int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
3121da177e4SLinus Torvalds 	void (*disconnect)(struct input_handle *handle);
313c7e8dc6eSDmitry Torokhov 	void (*start)(struct input_handle *handle);
3141da177e4SLinus Torvalds 
3157f8d4cadSDmitry Torokhov 	bool legacy_minors;
3161da177e4SLinus Torvalds 	int minor;
31766e66118SDmitry Torokhov 	const char *name;
3181da177e4SLinus Torvalds 
31966e66118SDmitry Torokhov 	const struct input_device_id *id_table;
3201da177e4SLinus Torvalds 
3211da177e4SLinus Torvalds 	struct list_head	h_list;
3221da177e4SLinus Torvalds 	struct list_head	node;
3231da177e4SLinus Torvalds };
3241da177e4SLinus Torvalds 
3258006479cSDmitry Torokhov /**
3268006479cSDmitry Torokhov  * struct input_handle - links input device with an input handler
3278006479cSDmitry Torokhov  * @private: handler-specific data
3288006479cSDmitry Torokhov  * @open: counter showing whether the handle is 'open', i.e. should deliver
3298006479cSDmitry Torokhov  *	events from its device
3308006479cSDmitry Torokhov  * @name: name given to the handle by handler that created it
3318006479cSDmitry Torokhov  * @dev: input device the handle is attached to
3328006479cSDmitry Torokhov  * @handler: handler that works with the device through this handle
3338006479cSDmitry Torokhov  * @d_node: used to put the handle on device's list of attached handles
3348006479cSDmitry Torokhov  * @h_node: used to put the handle on handler's list of handles from which
3358006479cSDmitry Torokhov  *	it gets events
3368006479cSDmitry Torokhov  */
3371da177e4SLinus Torvalds struct input_handle {
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds 	void *private;
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds 	int open;
34266e66118SDmitry Torokhov 	const char *name;
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds 	struct input_dev *dev;
3451da177e4SLinus Torvalds 	struct input_handler *handler;
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds 	struct list_head	d_node;
3481da177e4SLinus Torvalds 	struct list_head	h_node;
3491da177e4SLinus Torvalds };
3501da177e4SLinus Torvalds 
3512be975c6SDmitry Torokhov struct input_dev __must_check *input_allocate_device(void);
3522be975c6SDmitry Torokhov struct input_dev __must_check *devm_input_allocate_device(struct device *);
353f60d2b11SDmitry Torokhov void input_free_device(struct input_dev *dev);
354d19fbe8aSDmitry Torokhov 
355d19fbe8aSDmitry Torokhov static inline struct input_dev *input_get_device(struct input_dev *dev)
356d19fbe8aSDmitry Torokhov {
357a7097ff8SDmitry Torokhov 	return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
358d19fbe8aSDmitry Torokhov }
359d19fbe8aSDmitry Torokhov 
360d19fbe8aSDmitry Torokhov static inline void input_put_device(struct input_dev *dev)
361d19fbe8aSDmitry Torokhov {
362a7097ff8SDmitry Torokhov 	if (dev)
3639657d75cSDmitry Torokhov 		put_device(&dev->dev);
364d19fbe8aSDmitry Torokhov }
365d19fbe8aSDmitry Torokhov 
3663abccf36SDmitry Torokhov static inline void *input_get_drvdata(struct input_dev *dev)
3673abccf36SDmitry Torokhov {
3683797fec1SDmitry Torokhov 	return dev_get_drvdata(&dev->dev);
3693abccf36SDmitry Torokhov }
3703abccf36SDmitry Torokhov 
3713abccf36SDmitry Torokhov static inline void input_set_drvdata(struct input_dev *dev, void *data)
3723abccf36SDmitry Torokhov {
3733797fec1SDmitry Torokhov 	dev_set_drvdata(&dev->dev, data);
3743abccf36SDmitry Torokhov }
3753abccf36SDmitry Torokhov 
376501cc54cSDmitry Torokhov int __must_check input_register_device(struct input_dev *);
3771da177e4SLinus Torvalds void input_unregister_device(struct input_dev *);
3781da177e4SLinus Torvalds 
379b50b5216SDmitry Torokhov void input_reset_device(struct input_dev *);
380b50b5216SDmitry Torokhov 
381*e95656eaSDmitry Torokhov int input_setup_polling(struct input_dev *dev,
382*e95656eaSDmitry Torokhov 			void (*poll_fn)(struct input_dev *dev));
383*e95656eaSDmitry Torokhov void input_set_poll_interval(struct input_dev *dev, unsigned int interval);
384*e95656eaSDmitry Torokhov void input_set_min_poll_interval(struct input_dev *dev, unsigned int interval);
385*e95656eaSDmitry Torokhov void input_set_max_poll_interval(struct input_dev *dev, unsigned int interval);
386*e95656eaSDmitry Torokhov 
387501cc54cSDmitry Torokhov int __must_check input_register_handler(struct input_handler *);
3881da177e4SLinus Torvalds void input_unregister_handler(struct input_handler *);
3891da177e4SLinus Torvalds 
3907f8d4cadSDmitry Torokhov int __must_check input_get_new_minor(int legacy_base, unsigned int legacy_num,
3917f8d4cadSDmitry Torokhov 				     bool allow_dynamic);
3927f8d4cadSDmitry Torokhov void input_free_minor(unsigned int minor);
3937f8d4cadSDmitry Torokhov 
39466d2a595SDmitry Torokhov int input_handler_for_each_handle(struct input_handler *, void *data,
39566d2a595SDmitry Torokhov 				  int (*fn)(struct input_handle *, void *));
39666d2a595SDmitry Torokhov 
3975b2a0826SDmitry Torokhov int input_register_handle(struct input_handle *);
3985b2a0826SDmitry Torokhov void input_unregister_handle(struct input_handle *);
3995b2a0826SDmitry Torokhov 
4001da177e4SLinus Torvalds int input_grab_device(struct input_handle *);
4011da177e4SLinus Torvalds void input_release_device(struct input_handle *);
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds int input_open_device(struct input_handle *);
4041da177e4SLinus Torvalds void input_close_device(struct input_handle *);
4051da177e4SLinus Torvalds 
4061da177e4SLinus Torvalds int input_flush_device(struct input_handle *handle, struct file *file);
4071da177e4SLinus Torvalds 
4083b51c44bSAtif Niyaz void input_set_timestamp(struct input_dev *dev, ktime_t timestamp);
4093b51c44bSAtif Niyaz ktime_t *input_get_timestamp(struct input_dev *dev);
4103b51c44bSAtif Niyaz 
4111da177e4SLinus Torvalds void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
4120e739d28SDmitry Torokhov void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
4151da177e4SLinus Torvalds {
4161da177e4SLinus Torvalds 	input_event(dev, EV_KEY, code, !!value);
4171da177e4SLinus Torvalds }
4181da177e4SLinus Torvalds 
4191da177e4SLinus Torvalds static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
4201da177e4SLinus Torvalds {
4211da177e4SLinus Torvalds 	input_event(dev, EV_REL, code, value);
4221da177e4SLinus Torvalds }
4231da177e4SLinus Torvalds 
4241da177e4SLinus Torvalds static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
4251da177e4SLinus Torvalds {
4261da177e4SLinus Torvalds 	input_event(dev, EV_ABS, code, value);
4271da177e4SLinus Torvalds }
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
4301da177e4SLinus Torvalds {
4311da177e4SLinus Torvalds 	input_event(dev, EV_FF_STATUS, code, value);
4321da177e4SLinus Torvalds }
4331da177e4SLinus Torvalds 
43431581066SRichard Purdie static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
43531581066SRichard Purdie {
43631581066SRichard Purdie 	input_event(dev, EV_SW, code, !!value);
43731581066SRichard Purdie }
43831581066SRichard Purdie 
4391da177e4SLinus Torvalds static inline void input_sync(struct input_dev *dev)
4401da177e4SLinus Torvalds {
4411da177e4SLinus Torvalds 	input_event(dev, EV_SYN, SYN_REPORT, 0);
4421da177e4SLinus Torvalds }
4431da177e4SLinus Torvalds 
4445e5ee686SHenrik Rydberg static inline void input_mt_sync(struct input_dev *dev)
4455e5ee686SHenrik Rydberg {
4465e5ee686SHenrik Rydberg 	input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
4475e5ee686SHenrik Rydberg }
4485e5ee686SHenrik Rydberg 
449534565f2SDmitry Torokhov void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
450534565f2SDmitry Torokhov 
45163a6404dSHenrik Rydberg /**
45263a6404dSHenrik Rydberg  * input_set_events_per_packet - tell handlers about the driver event rate
45363a6404dSHenrik Rydberg  * @dev: the input device used by the driver
45463a6404dSHenrik Rydberg  * @n_events: the average number of events between calls to input_sync()
45563a6404dSHenrik Rydberg  *
45663a6404dSHenrik Rydberg  * If the event rate sent from a device is unusually large, use this
45763a6404dSHenrik Rydberg  * function to set the expected event rate. This will allow handlers
45863a6404dSHenrik Rydberg  * to set up an appropriate buffer size for the event stream, in order
45963a6404dSHenrik Rydberg  * to minimize information loss.
46063a6404dSHenrik Rydberg  */
46163a6404dSHenrik Rydberg static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
46263a6404dSHenrik Rydberg {
46363a6404dSHenrik Rydberg 	dev->hint_events_per_packet = n_events;
46463a6404dSHenrik Rydberg }
46563a6404dSHenrik Rydberg 
466d31b2865SDaniel Mack void input_alloc_absinfo(struct input_dev *dev);
467d31b2865SDaniel Mack void input_set_abs_params(struct input_dev *dev, unsigned int axis,
468d31b2865SDaniel Mack 			  int min, int max, int fuzz, int flat);
4691da177e4SLinus Torvalds 
4707957e9c4SDaniel Mack #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)			\
4717957e9c4SDaniel Mack static inline int input_abs_get_##_suffix(struct input_dev *dev,	\
4727957e9c4SDaniel Mack 					  unsigned int axis)		\
4737957e9c4SDaniel Mack {									\
474d31b2865SDaniel Mack 	return dev->absinfo ? dev->absinfo[axis]._item : 0;		\
4757957e9c4SDaniel Mack }									\
4767957e9c4SDaniel Mack 									\
4777957e9c4SDaniel Mack static inline void input_abs_set_##_suffix(struct input_dev *dev,	\
4787957e9c4SDaniel Mack 					   unsigned int axis, int val)	\
4797957e9c4SDaniel Mack {									\
480d31b2865SDaniel Mack 	input_alloc_absinfo(dev);					\
481d31b2865SDaniel Mack 	if (dev->absinfo)						\
482d31b2865SDaniel Mack 		dev->absinfo[axis]._item = val;				\
4837957e9c4SDaniel Mack }
4847957e9c4SDaniel Mack 
485d31b2865SDaniel Mack INPUT_GENERATE_ABS_ACCESSORS(val, value)
486d31b2865SDaniel Mack INPUT_GENERATE_ABS_ACCESSORS(min, minimum)
487d31b2865SDaniel Mack INPUT_GENERATE_ABS_ACCESSORS(max, maximum)
4887957e9c4SDaniel Mack INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
4897957e9c4SDaniel Mack INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
490d31b2865SDaniel Mack INPUT_GENERATE_ABS_ACCESSORS(res, resolution)
4917957e9c4SDaniel Mack 
4928613e4c2SMauro Carvalho Chehab int input_scancode_to_scalar(const struct input_keymap_entry *ke,
4938613e4c2SMauro Carvalho Chehab 			     unsigned int *scancode);
4948613e4c2SMauro Carvalho Chehab 
4958613e4c2SMauro Carvalho Chehab int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
49658b93995SDmitry Torokhov int input_set_keycode(struct input_dev *dev,
4978613e4c2SMauro Carvalho Chehab 		      const struct input_keymap_entry *ke);
498f4f37c8eSDmitry Torokhov 
49955dfce87SDmitry Torokhov bool input_match_device_id(const struct input_dev *dev,
50055dfce87SDmitry Torokhov 			   const struct input_device_id *id);
50155dfce87SDmitry Torokhov 
502027c71bbSPetri Gynther void input_enable_softrepeat(struct input_dev *dev, int delay, int period);
503027c71bbSPetri Gynther 
504ea9f240bSGreg Kroah-Hartman extern struct class input_class;
5051da177e4SLinus Torvalds 
506509ca1a9SAnssi Hannula /**
507509ca1a9SAnssi Hannula  * struct ff_device - force-feedback part of an input device
508509ca1a9SAnssi Hannula  * @upload: Called to upload an new effect into device
509509ca1a9SAnssi Hannula  * @erase: Called to erase an effect from device
510509ca1a9SAnssi Hannula  * @playback: Called to request device to start playing specified effect
511509ca1a9SAnssi Hannula  * @set_gain: Called to set specified gain
512509ca1a9SAnssi Hannula  * @set_autocenter: Called to auto-center device
513509ca1a9SAnssi Hannula  * @destroy: called by input core when parent input device is being
514509ca1a9SAnssi Hannula  *	destroyed
515509ca1a9SAnssi Hannula  * @private: driver-specific data, will be freed automatically
516509ca1a9SAnssi Hannula  * @ffbit: bitmap of force feedback capabilities truly supported by
517509ca1a9SAnssi Hannula  *	device (not emulated like ones in input_dev->ffbit)
518509ca1a9SAnssi Hannula  * @mutex: mutex for serializing access to the device
519509ca1a9SAnssi Hannula  * @max_effects: maximum number of effects supported by device
520509ca1a9SAnssi Hannula  * @effects: pointer to an array of effects currently loaded into device
521509ca1a9SAnssi Hannula  * @effect_owners: array of effect owners; when file handle owning
5228006479cSDmitry Torokhov  *	an effect gets closed the effect is automatically erased
523509ca1a9SAnssi Hannula  *
524509ca1a9SAnssi Hannula  * Every force-feedback device must implement upload() and playback()
525509ca1a9SAnssi Hannula  * methods; erase() is optional. set_gain() and set_autocenter() need
526509ca1a9SAnssi Hannula  * only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER
527509ca1a9SAnssi Hannula  * bits.
528bf3204cbSDmitry Torokhov  *
529bf3204cbSDmitry Torokhov  * Note that playback(), set_gain() and set_autocenter() are called with
530bf3204cbSDmitry Torokhov  * dev->event_lock spinlock held and interrupts off and thus may not
531bf3204cbSDmitry Torokhov  * sleep.
532509ca1a9SAnssi Hannula  */
533509ca1a9SAnssi Hannula struct ff_device {
534509ca1a9SAnssi Hannula 	int (*upload)(struct input_dev *dev, struct ff_effect *effect,
535509ca1a9SAnssi Hannula 		      struct ff_effect *old);
536509ca1a9SAnssi Hannula 	int (*erase)(struct input_dev *dev, int effect_id);
537509ca1a9SAnssi Hannula 
538509ca1a9SAnssi Hannula 	int (*playback)(struct input_dev *dev, int effect_id, int value);
539509ca1a9SAnssi Hannula 	void (*set_gain)(struct input_dev *dev, u16 gain);
540509ca1a9SAnssi Hannula 	void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
541509ca1a9SAnssi Hannula 
542509ca1a9SAnssi Hannula 	void (*destroy)(struct ff_device *);
543509ca1a9SAnssi Hannula 
544509ca1a9SAnssi Hannula 	void *private;
545509ca1a9SAnssi Hannula 
5467b19ada2SJiri Slaby 	unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
547509ca1a9SAnssi Hannula 
548509ca1a9SAnssi Hannula 	struct mutex mutex;
549509ca1a9SAnssi Hannula 
550509ca1a9SAnssi Hannula 	int max_effects;
551509ca1a9SAnssi Hannula 	struct ff_effect *effects;
552509ca1a9SAnssi Hannula 	struct file *effect_owners[];
553509ca1a9SAnssi Hannula };
554509ca1a9SAnssi Hannula 
55505be8b81SDan Carpenter int input_ff_create(struct input_dev *dev, unsigned int max_effects);
556509ca1a9SAnssi Hannula void input_ff_destroy(struct input_dev *dev);
557509ca1a9SAnssi Hannula 
558509ca1a9SAnssi Hannula int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
559509ca1a9SAnssi Hannula 
560509ca1a9SAnssi Hannula int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
561509ca1a9SAnssi Hannula int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
562e8b95728SDmitry Torokhov int input_ff_flush(struct input_dev *dev, struct file *file);
563509ca1a9SAnssi Hannula 
5647d928a2bSAnssi Hannula int input_ff_create_memless(struct input_dev *dev, void *data,
5657d928a2bSAnssi Hannula 		int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
5667d928a2bSAnssi Hannula 
5671da177e4SLinus Torvalds #endif
568