xref: /OK3568_Linux_fs/kernel/include/linux/input.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 1999-2002 Vojtech Pavlik
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun #ifndef _INPUT_H
6*4882a593Smuzhiyun #define _INPUT_H
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <linux/time.h>
9*4882a593Smuzhiyun #include <linux/list.h>
10*4882a593Smuzhiyun #include <linux/android_kabi.h>
11*4882a593Smuzhiyun #include <uapi/linux/input.h>
12*4882a593Smuzhiyun /* Implementation details, userspace should not care about these */
13*4882a593Smuzhiyun #define ABS_MT_FIRST		ABS_MT_TOUCH_MAJOR
14*4882a593Smuzhiyun #define ABS_MT_LAST		ABS_MT_TOOL_Y
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun /*
17*4882a593Smuzhiyun  * In-kernel definitions.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <linux/device.h>
21*4882a593Smuzhiyun #include <linux/fs.h>
22*4882a593Smuzhiyun #include <linux/timer.h>
23*4882a593Smuzhiyun #include <linux/mod_devicetable.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun struct input_dev_poller;
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /**
28*4882a593Smuzhiyun  * struct input_value - input value representation
29*4882a593Smuzhiyun  * @type: type of value (EV_KEY, EV_ABS, etc)
30*4882a593Smuzhiyun  * @code: the value code
31*4882a593Smuzhiyun  * @value: the value
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun struct input_value {
34*4882a593Smuzhiyun 	__u16 type;
35*4882a593Smuzhiyun 	__u16 code;
36*4882a593Smuzhiyun 	__s32 value;
37*4882a593Smuzhiyun };
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun enum input_clock_type {
40*4882a593Smuzhiyun 	INPUT_CLK_REAL = 0,
41*4882a593Smuzhiyun 	INPUT_CLK_MONO,
42*4882a593Smuzhiyun 	INPUT_CLK_BOOT,
43*4882a593Smuzhiyun 	INPUT_CLK_MAX
44*4882a593Smuzhiyun };
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /**
47*4882a593Smuzhiyun  * struct input_dev - represents an input device
48*4882a593Smuzhiyun  * @name: name of the device
49*4882a593Smuzhiyun  * @phys: physical path to the device in the system hierarchy
50*4882a593Smuzhiyun  * @uniq: unique identification code for the device (if device has it)
51*4882a593Smuzhiyun  * @id: id of the device (struct input_id)
52*4882a593Smuzhiyun  * @propbit: bitmap of device properties and quirks
53*4882a593Smuzhiyun  * @evbit: bitmap of types of events supported by the device (EV_KEY,
54*4882a593Smuzhiyun  *	EV_REL, etc.)
55*4882a593Smuzhiyun  * @keybit: bitmap of keys/buttons this device has
56*4882a593Smuzhiyun  * @relbit: bitmap of relative axes for the device
57*4882a593Smuzhiyun  * @absbit: bitmap of absolute axes for the device
58*4882a593Smuzhiyun  * @mscbit: bitmap of miscellaneous events supported by the device
59*4882a593Smuzhiyun  * @ledbit: bitmap of leds present on the device
60*4882a593Smuzhiyun  * @sndbit: bitmap of sound effects supported by the device
61*4882a593Smuzhiyun  * @ffbit: bitmap of force feedback effects supported by the device
62*4882a593Smuzhiyun  * @swbit: bitmap of switches present on the device
63*4882a593Smuzhiyun  * @hint_events_per_packet: average number of events generated by the
64*4882a593Smuzhiyun  *	device in a packet (between EV_SYN/SYN_REPORT events). Used by
65*4882a593Smuzhiyun  *	event handlers to estimate size of the buffer needed to hold
66*4882a593Smuzhiyun  *	events.
67*4882a593Smuzhiyun  * @keycodemax: size of keycode table
68*4882a593Smuzhiyun  * @keycodesize: size of elements in keycode table
69*4882a593Smuzhiyun  * @keycode: map of scancodes to keycodes for this device
70*4882a593Smuzhiyun  * @getkeycode: optional legacy method to retrieve current keymap.
71*4882a593Smuzhiyun  * @setkeycode: optional method to alter current keymap, used to implement
72*4882a593Smuzhiyun  *	sparse keymaps. If not supplied default mechanism will be used.
73*4882a593Smuzhiyun  *	The method is being called while holding event_lock and thus must
74*4882a593Smuzhiyun  *	not sleep
75*4882a593Smuzhiyun  * @ff: force feedback structure associated with the device if device
76*4882a593Smuzhiyun  *	supports force feedback effects
77*4882a593Smuzhiyun  * @poller: poller structure associated with the device if device is
78*4882a593Smuzhiyun  *	set up to use polling mode
79*4882a593Smuzhiyun  * @repeat_key: stores key code of the last key pressed; used to implement
80*4882a593Smuzhiyun  *	software autorepeat
81*4882a593Smuzhiyun  * @timer: timer for software autorepeat
82*4882a593Smuzhiyun  * @rep: current values for autorepeat parameters (delay, rate)
83*4882a593Smuzhiyun  * @mt: pointer to multitouch state
84*4882a593Smuzhiyun  * @absinfo: array of &struct input_absinfo elements holding information
85*4882a593Smuzhiyun  *	about absolute axes (current value, min, max, flat, fuzz,
86*4882a593Smuzhiyun  *	resolution)
87*4882a593Smuzhiyun  * @key: reflects current state of device's keys/buttons
88*4882a593Smuzhiyun  * @led: reflects current state of device's LEDs
89*4882a593Smuzhiyun  * @snd: reflects current state of sound effects
90*4882a593Smuzhiyun  * @sw: reflects current state of device's switches
91*4882a593Smuzhiyun  * @open: this method is called when the very first user calls
92*4882a593Smuzhiyun  *	input_open_device(). The driver must prepare the device
93*4882a593Smuzhiyun  *	to start generating events (start polling thread,
94*4882a593Smuzhiyun  *	request an IRQ, submit URB, etc.)
95*4882a593Smuzhiyun  * @close: this method is called when the very last user calls
96*4882a593Smuzhiyun  *	input_close_device().
97*4882a593Smuzhiyun  * @flush: purges the device. Most commonly used to get rid of force
98*4882a593Smuzhiyun  *	feedback effects loaded into the device when disconnecting
99*4882a593Smuzhiyun  *	from it
100*4882a593Smuzhiyun  * @event: event handler for events sent _to_ the device, like EV_LED
101*4882a593Smuzhiyun  *	or EV_SND. The device is expected to carry out the requested
102*4882a593Smuzhiyun  *	action (turn on a LED, play sound, etc.) The call is protected
103*4882a593Smuzhiyun  *	by @event_lock and must not sleep
104*4882a593Smuzhiyun  * @grab: input handle that currently has the device grabbed (via
105*4882a593Smuzhiyun  *	EVIOCGRAB ioctl). When a handle grabs a device it becomes sole
106*4882a593Smuzhiyun  *	recipient for all input events coming from the device
107*4882a593Smuzhiyun  * @event_lock: this spinlock is taken when input core receives
108*4882a593Smuzhiyun  *	and processes a new event for the device (in input_event()).
109*4882a593Smuzhiyun  *	Code that accesses and/or modifies parameters of a device
110*4882a593Smuzhiyun  *	(such as keymap or absmin, absmax, absfuzz, etc.) after device
111*4882a593Smuzhiyun  *	has been registered with input core must take this lock.
112*4882a593Smuzhiyun  * @mutex: serializes calls to open(), close() and flush() methods
113*4882a593Smuzhiyun  * @users: stores number of users (input handlers) that opened this
114*4882a593Smuzhiyun  *	device. It is used by input_open_device() and input_close_device()
115*4882a593Smuzhiyun  *	to make sure that dev->open() is only called when the first
116*4882a593Smuzhiyun  *	user opens device and dev->close() is called when the very
117*4882a593Smuzhiyun  *	last user closes the device
118*4882a593Smuzhiyun  * @going_away: marks devices that are in a middle of unregistering and
119*4882a593Smuzhiyun  *	causes input_open_device*() fail with -ENODEV.
120*4882a593Smuzhiyun  * @dev: driver model's view of this device
121*4882a593Smuzhiyun  * @h_list: list of input handles associated with the device. When
122*4882a593Smuzhiyun  *	accessing the list dev->mutex must be held
123*4882a593Smuzhiyun  * @node: used to place the device onto input_dev_list
124*4882a593Smuzhiyun  * @num_vals: number of values queued in the current frame
125*4882a593Smuzhiyun  * @max_vals: maximum number of values queued in a frame
126*4882a593Smuzhiyun  * @vals: array of values queued in the current frame
127*4882a593Smuzhiyun  * @devres_managed: indicates that devices is managed with devres framework
128*4882a593Smuzhiyun  *	and needs not be explicitly unregistered or freed.
129*4882a593Smuzhiyun  * @timestamp: storage for a timestamp set by input_set_timestamp called
130*4882a593Smuzhiyun  *  by a driver
131*4882a593Smuzhiyun  */
132*4882a593Smuzhiyun struct input_dev {
133*4882a593Smuzhiyun 	const char *name;
134*4882a593Smuzhiyun 	const char *phys;
135*4882a593Smuzhiyun 	const char *uniq;
136*4882a593Smuzhiyun 	struct input_id id;
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
141*4882a593Smuzhiyun 	unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
142*4882a593Smuzhiyun 	unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
143*4882a593Smuzhiyun 	unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
144*4882a593Smuzhiyun 	unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
145*4882a593Smuzhiyun 	unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
146*4882a593Smuzhiyun 	unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
147*4882a593Smuzhiyun 	unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
148*4882a593Smuzhiyun 	unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun 	unsigned int hint_events_per_packet;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	unsigned int keycodemax;
153*4882a593Smuzhiyun 	unsigned int keycodesize;
154*4882a593Smuzhiyun 	void *keycode;
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 	int (*setkeycode)(struct input_dev *dev,
157*4882a593Smuzhiyun 			  const struct input_keymap_entry *ke,
158*4882a593Smuzhiyun 			  unsigned int *old_keycode);
159*4882a593Smuzhiyun 	int (*getkeycode)(struct input_dev *dev,
160*4882a593Smuzhiyun 			  struct input_keymap_entry *ke);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	struct ff_device *ff;
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 	struct input_dev_poller *poller;
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	unsigned int repeat_key;
167*4882a593Smuzhiyun 	struct timer_list timer;
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun 	int rep[REP_CNT];
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	struct input_mt *mt;
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	struct input_absinfo *absinfo;
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	unsigned long key[BITS_TO_LONGS(KEY_CNT)];
176*4882a593Smuzhiyun 	unsigned long led[BITS_TO_LONGS(LED_CNT)];
177*4882a593Smuzhiyun 	unsigned long snd[BITS_TO_LONGS(SND_CNT)];
178*4882a593Smuzhiyun 	unsigned long sw[BITS_TO_LONGS(SW_CNT)];
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	int (*open)(struct input_dev *dev);
181*4882a593Smuzhiyun 	void (*close)(struct input_dev *dev);
182*4882a593Smuzhiyun 	int (*flush)(struct input_dev *dev, struct file *file);
183*4882a593Smuzhiyun 	int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun 	struct input_handle __rcu *grab;
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun 	spinlock_t event_lock;
188*4882a593Smuzhiyun 	struct mutex mutex;
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun 	unsigned int users;
191*4882a593Smuzhiyun 	bool going_away;
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun 	struct device dev;
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	struct list_head	h_list;
196*4882a593Smuzhiyun 	struct list_head	node;
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	unsigned int num_vals;
199*4882a593Smuzhiyun 	unsigned int max_vals;
200*4882a593Smuzhiyun 	struct input_value *vals;
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	bool devres_managed;
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun 	ktime_t timestamp[INPUT_CLK_MAX];
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
207*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(2);
208*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(3);
209*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(4);
210*4882a593Smuzhiyun };
211*4882a593Smuzhiyun #define to_input_dev(d) container_of(d, struct input_dev, dev)
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun /*
214*4882a593Smuzhiyun  * Verify that we are in sync with input_device_id mod_devicetable.h #defines
215*4882a593Smuzhiyun  */
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun #if EV_MAX != INPUT_DEVICE_ID_EV_MAX
218*4882a593Smuzhiyun #error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"
219*4882a593Smuzhiyun #endif
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun #if KEY_MIN_INTERESTING != INPUT_DEVICE_ID_KEY_MIN_INTERESTING
222*4882a593Smuzhiyun #error "KEY_MIN_INTERESTING and INPUT_DEVICE_ID_KEY_MIN_INTERESTING do not match"
223*4882a593Smuzhiyun #endif
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun #if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX
226*4882a593Smuzhiyun #error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"
227*4882a593Smuzhiyun #endif
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun #if REL_MAX != INPUT_DEVICE_ID_REL_MAX
230*4882a593Smuzhiyun #error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"
231*4882a593Smuzhiyun #endif
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun #if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX
234*4882a593Smuzhiyun #error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"
235*4882a593Smuzhiyun #endif
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun #if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX
238*4882a593Smuzhiyun #error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"
239*4882a593Smuzhiyun #endif
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun #if LED_MAX != INPUT_DEVICE_ID_LED_MAX
242*4882a593Smuzhiyun #error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"
243*4882a593Smuzhiyun #endif
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun #if SND_MAX != INPUT_DEVICE_ID_SND_MAX
246*4882a593Smuzhiyun #error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"
247*4882a593Smuzhiyun #endif
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun #if FF_MAX != INPUT_DEVICE_ID_FF_MAX
250*4882a593Smuzhiyun #error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"
251*4882a593Smuzhiyun #endif
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun #if SW_MAX != INPUT_DEVICE_ID_SW_MAX
254*4882a593Smuzhiyun #error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"
255*4882a593Smuzhiyun #endif
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun #if INPUT_PROP_MAX != INPUT_DEVICE_ID_PROP_MAX
258*4882a593Smuzhiyun #error "INPUT_PROP_MAX and INPUT_DEVICE_ID_PROP_MAX do not match"
259*4882a593Smuzhiyun #endif
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun #define INPUT_DEVICE_ID_MATCH_DEVICE \
262*4882a593Smuzhiyun 	(INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)
263*4882a593Smuzhiyun #define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
264*4882a593Smuzhiyun 	(INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun struct input_handle;
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun /**
269*4882a593Smuzhiyun  * struct input_handler - implements one of interfaces for input devices
270*4882a593Smuzhiyun  * @private: driver-specific data
271*4882a593Smuzhiyun  * @event: event handler. This method is being called by input core with
272*4882a593Smuzhiyun  *	interrupts disabled and dev->event_lock spinlock held and so
273*4882a593Smuzhiyun  *	it may not sleep
274*4882a593Smuzhiyun  * @events: event sequence handler. This method is being called by
275*4882a593Smuzhiyun  *	input core with interrupts disabled and dev->event_lock
276*4882a593Smuzhiyun  *	spinlock held and so it may not sleep
277*4882a593Smuzhiyun  * @filter: similar to @event; separates normal event handlers from
278*4882a593Smuzhiyun  *	"filters".
279*4882a593Smuzhiyun  * @match: called after comparing device's id with handler's id_table
280*4882a593Smuzhiyun  *	to perform fine-grained matching between device and handler
281*4882a593Smuzhiyun  * @connect: called when attaching a handler to an input device
282*4882a593Smuzhiyun  * @disconnect: disconnects a handler from input device
283*4882a593Smuzhiyun  * @start: starts handler for given handle. This function is called by
284*4882a593Smuzhiyun  *	input core right after connect() method and also when a process
285*4882a593Smuzhiyun  *	that "grabbed" a device releases it
286*4882a593Smuzhiyun  * @legacy_minors: set to %true by drivers using legacy minor ranges
287*4882a593Smuzhiyun  * @minor: beginning of range of 32 legacy minors for devices this driver
288*4882a593Smuzhiyun  *	can provide
289*4882a593Smuzhiyun  * @name: name of the handler, to be shown in /proc/bus/input/handlers
290*4882a593Smuzhiyun  * @id_table: pointer to a table of input_device_ids this driver can
291*4882a593Smuzhiyun  *	handle
292*4882a593Smuzhiyun  * @h_list: list of input handles associated with the handler
293*4882a593Smuzhiyun  * @node: for placing the driver onto input_handler_list
294*4882a593Smuzhiyun  *
295*4882a593Smuzhiyun  * Input handlers attach to input devices and create input handles. There
296*4882a593Smuzhiyun  * are likely several handlers attached to any given input device at the
297*4882a593Smuzhiyun  * same time. All of them will get their copy of input event generated by
298*4882a593Smuzhiyun  * the device.
299*4882a593Smuzhiyun  *
300*4882a593Smuzhiyun  * The very same structure is used to implement input filters. Input core
301*4882a593Smuzhiyun  * allows filters to run first and will not pass event to regular handlers
302*4882a593Smuzhiyun  * if any of the filters indicate that the event should be filtered (by
303*4882a593Smuzhiyun  * returning %true from their filter() method).
304*4882a593Smuzhiyun  *
305*4882a593Smuzhiyun  * Note that input core serializes calls to connect() and disconnect()
306*4882a593Smuzhiyun  * methods.
307*4882a593Smuzhiyun  */
308*4882a593Smuzhiyun struct input_handler {
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 	void *private;
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 	void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
313*4882a593Smuzhiyun 	void (*events)(struct input_handle *handle,
314*4882a593Smuzhiyun 		       const struct input_value *vals, unsigned int count);
315*4882a593Smuzhiyun 	bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
316*4882a593Smuzhiyun 	bool (*match)(struct input_handler *handler, struct input_dev *dev);
317*4882a593Smuzhiyun 	int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
318*4882a593Smuzhiyun 	void (*disconnect)(struct input_handle *handle);
319*4882a593Smuzhiyun 	void (*start)(struct input_handle *handle);
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 	bool legacy_minors;
322*4882a593Smuzhiyun 	int minor;
323*4882a593Smuzhiyun 	const char *name;
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 	const struct input_device_id *id_table;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	struct list_head	h_list;
328*4882a593Smuzhiyun 	struct list_head	node;
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
331*4882a593Smuzhiyun };
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun /**
334*4882a593Smuzhiyun  * struct input_handle - links input device with an input handler
335*4882a593Smuzhiyun  * @private: handler-specific data
336*4882a593Smuzhiyun  * @open: counter showing whether the handle is 'open', i.e. should deliver
337*4882a593Smuzhiyun  *	events from its device
338*4882a593Smuzhiyun  * @name: name given to the handle by handler that created it
339*4882a593Smuzhiyun  * @dev: input device the handle is attached to
340*4882a593Smuzhiyun  * @handler: handler that works with the device through this handle
341*4882a593Smuzhiyun  * @d_node: used to put the handle on device's list of attached handles
342*4882a593Smuzhiyun  * @h_node: used to put the handle on handler's list of handles from which
343*4882a593Smuzhiyun  *	it gets events
344*4882a593Smuzhiyun  */
345*4882a593Smuzhiyun struct input_handle {
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun 	void *private;
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun 	int open;
350*4882a593Smuzhiyun 	const char *name;
351*4882a593Smuzhiyun 
352*4882a593Smuzhiyun 	struct input_dev *dev;
353*4882a593Smuzhiyun 	struct input_handler *handler;
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun 	struct list_head	d_node;
356*4882a593Smuzhiyun 	struct list_head	h_node;
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
359*4882a593Smuzhiyun };
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun struct input_dev __must_check *input_allocate_device(void);
362*4882a593Smuzhiyun struct input_dev __must_check *devm_input_allocate_device(struct device *);
363*4882a593Smuzhiyun void input_free_device(struct input_dev *dev);
364*4882a593Smuzhiyun 
input_get_device(struct input_dev * dev)365*4882a593Smuzhiyun static inline struct input_dev *input_get_device(struct input_dev *dev)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun 	return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun 
input_put_device(struct input_dev * dev)370*4882a593Smuzhiyun static inline void input_put_device(struct input_dev *dev)
371*4882a593Smuzhiyun {
372*4882a593Smuzhiyun 	if (dev)
373*4882a593Smuzhiyun 		put_device(&dev->dev);
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun 
input_get_drvdata(struct input_dev * dev)376*4882a593Smuzhiyun static inline void *input_get_drvdata(struct input_dev *dev)
377*4882a593Smuzhiyun {
378*4882a593Smuzhiyun 	return dev_get_drvdata(&dev->dev);
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun 
input_set_drvdata(struct input_dev * dev,void * data)381*4882a593Smuzhiyun static inline void input_set_drvdata(struct input_dev *dev, void *data)
382*4882a593Smuzhiyun {
383*4882a593Smuzhiyun 	dev_set_drvdata(&dev->dev, data);
384*4882a593Smuzhiyun }
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun int __must_check input_register_device(struct input_dev *);
387*4882a593Smuzhiyun void input_unregister_device(struct input_dev *);
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun void input_reset_device(struct input_dev *);
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun int input_setup_polling(struct input_dev *dev,
392*4882a593Smuzhiyun 			void (*poll_fn)(struct input_dev *dev));
393*4882a593Smuzhiyun void input_set_poll_interval(struct input_dev *dev, unsigned int interval);
394*4882a593Smuzhiyun void input_set_min_poll_interval(struct input_dev *dev, unsigned int interval);
395*4882a593Smuzhiyun void input_set_max_poll_interval(struct input_dev *dev, unsigned int interval);
396*4882a593Smuzhiyun int input_get_poll_interval(struct input_dev *dev);
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun int __must_check input_register_handler(struct input_handler *);
399*4882a593Smuzhiyun void input_unregister_handler(struct input_handler *);
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun int __must_check input_get_new_minor(int legacy_base, unsigned int legacy_num,
402*4882a593Smuzhiyun 				     bool allow_dynamic);
403*4882a593Smuzhiyun void input_free_minor(unsigned int minor);
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun int input_handler_for_each_handle(struct input_handler *, void *data,
406*4882a593Smuzhiyun 				  int (*fn)(struct input_handle *, void *));
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun int input_register_handle(struct input_handle *);
409*4882a593Smuzhiyun void input_unregister_handle(struct input_handle *);
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun int input_grab_device(struct input_handle *);
412*4882a593Smuzhiyun void input_release_device(struct input_handle *);
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun int input_open_device(struct input_handle *);
415*4882a593Smuzhiyun void input_close_device(struct input_handle *);
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun int input_flush_device(struct input_handle *handle, struct file *file);
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun void input_set_timestamp(struct input_dev *dev, ktime_t timestamp);
420*4882a593Smuzhiyun ktime_t *input_get_timestamp(struct input_dev *dev);
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
423*4882a593Smuzhiyun void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
424*4882a593Smuzhiyun 
input_report_key(struct input_dev * dev,unsigned int code,int value)425*4882a593Smuzhiyun static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
426*4882a593Smuzhiyun {
427*4882a593Smuzhiyun 	input_event(dev, EV_KEY, code, !!value);
428*4882a593Smuzhiyun }
429*4882a593Smuzhiyun 
input_report_rel(struct input_dev * dev,unsigned int code,int value)430*4882a593Smuzhiyun static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
431*4882a593Smuzhiyun {
432*4882a593Smuzhiyun 	input_event(dev, EV_REL, code, value);
433*4882a593Smuzhiyun }
434*4882a593Smuzhiyun 
input_report_abs(struct input_dev * dev,unsigned int code,int value)435*4882a593Smuzhiyun static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
436*4882a593Smuzhiyun {
437*4882a593Smuzhiyun 	input_event(dev, EV_ABS, code, value);
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun 
input_report_ff_status(struct input_dev * dev,unsigned int code,int value)440*4882a593Smuzhiyun static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
441*4882a593Smuzhiyun {
442*4882a593Smuzhiyun 	input_event(dev, EV_FF_STATUS, code, value);
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun 
input_report_switch(struct input_dev * dev,unsigned int code,int value)445*4882a593Smuzhiyun static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
446*4882a593Smuzhiyun {
447*4882a593Smuzhiyun 	input_event(dev, EV_SW, code, !!value);
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun 
input_sync(struct input_dev * dev)450*4882a593Smuzhiyun static inline void input_sync(struct input_dev *dev)
451*4882a593Smuzhiyun {
452*4882a593Smuzhiyun 	input_event(dev, EV_SYN, SYN_REPORT, 0);
453*4882a593Smuzhiyun }
454*4882a593Smuzhiyun 
input_mt_sync(struct input_dev * dev)455*4882a593Smuzhiyun static inline void input_mt_sync(struct input_dev *dev)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun 	input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun 
460*4882a593Smuzhiyun void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code);
461*4882a593Smuzhiyun 
462*4882a593Smuzhiyun /**
463*4882a593Smuzhiyun  * input_set_events_per_packet - tell handlers about the driver event rate
464*4882a593Smuzhiyun  * @dev: the input device used by the driver
465*4882a593Smuzhiyun  * @n_events: the average number of events between calls to input_sync()
466*4882a593Smuzhiyun  *
467*4882a593Smuzhiyun  * If the event rate sent from a device is unusually large, use this
468*4882a593Smuzhiyun  * function to set the expected event rate. This will allow handlers
469*4882a593Smuzhiyun  * to set up an appropriate buffer size for the event stream, in order
470*4882a593Smuzhiyun  * to minimize information loss.
471*4882a593Smuzhiyun  */
input_set_events_per_packet(struct input_dev * dev,int n_events)472*4882a593Smuzhiyun static inline void input_set_events_per_packet(struct input_dev *dev, int n_events)
473*4882a593Smuzhiyun {
474*4882a593Smuzhiyun 	dev->hint_events_per_packet = n_events;
475*4882a593Smuzhiyun }
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun void input_alloc_absinfo(struct input_dev *dev);
478*4882a593Smuzhiyun void input_set_abs_params(struct input_dev *dev, unsigned int axis,
479*4882a593Smuzhiyun 			  int min, int max, int fuzz, int flat);
480*4882a593Smuzhiyun 
481*4882a593Smuzhiyun #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)			\
482*4882a593Smuzhiyun static inline int input_abs_get_##_suffix(struct input_dev *dev,	\
483*4882a593Smuzhiyun 					  unsigned int axis)		\
484*4882a593Smuzhiyun {									\
485*4882a593Smuzhiyun 	return dev->absinfo ? dev->absinfo[axis]._item : 0;		\
486*4882a593Smuzhiyun }									\
487*4882a593Smuzhiyun 									\
488*4882a593Smuzhiyun static inline void input_abs_set_##_suffix(struct input_dev *dev,	\
489*4882a593Smuzhiyun 					   unsigned int axis, int val)	\
490*4882a593Smuzhiyun {									\
491*4882a593Smuzhiyun 	input_alloc_absinfo(dev);					\
492*4882a593Smuzhiyun 	if (dev->absinfo)						\
493*4882a593Smuzhiyun 		dev->absinfo[axis]._item = val;				\
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun INPUT_GENERATE_ABS_ACCESSORS(val, value)
497*4882a593Smuzhiyun INPUT_GENERATE_ABS_ACCESSORS(min, minimum)
498*4882a593Smuzhiyun INPUT_GENERATE_ABS_ACCESSORS(max, maximum)
499*4882a593Smuzhiyun INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
500*4882a593Smuzhiyun INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
501*4882a593Smuzhiyun INPUT_GENERATE_ABS_ACCESSORS(res, resolution)
502*4882a593Smuzhiyun 
503*4882a593Smuzhiyun int input_scancode_to_scalar(const struct input_keymap_entry *ke,
504*4882a593Smuzhiyun 			     unsigned int *scancode);
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);
507*4882a593Smuzhiyun int input_set_keycode(struct input_dev *dev,
508*4882a593Smuzhiyun 		      const struct input_keymap_entry *ke);
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun bool input_match_device_id(const struct input_dev *dev,
511*4882a593Smuzhiyun 			   const struct input_device_id *id);
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun void input_enable_softrepeat(struct input_dev *dev, int delay, int period);
514*4882a593Smuzhiyun 
515*4882a593Smuzhiyun extern struct class input_class;
516*4882a593Smuzhiyun 
517*4882a593Smuzhiyun /**
518*4882a593Smuzhiyun  * struct ff_device - force-feedback part of an input device
519*4882a593Smuzhiyun  * @upload: Called to upload an new effect into device
520*4882a593Smuzhiyun  * @erase: Called to erase an effect from device
521*4882a593Smuzhiyun  * @playback: Called to request device to start playing specified effect
522*4882a593Smuzhiyun  * @set_gain: Called to set specified gain
523*4882a593Smuzhiyun  * @set_autocenter: Called to auto-center device
524*4882a593Smuzhiyun  * @destroy: called by input core when parent input device is being
525*4882a593Smuzhiyun  *	destroyed
526*4882a593Smuzhiyun  * @private: driver-specific data, will be freed automatically
527*4882a593Smuzhiyun  * @ffbit: bitmap of force feedback capabilities truly supported by
528*4882a593Smuzhiyun  *	device (not emulated like ones in input_dev->ffbit)
529*4882a593Smuzhiyun  * @mutex: mutex for serializing access to the device
530*4882a593Smuzhiyun  * @max_effects: maximum number of effects supported by device
531*4882a593Smuzhiyun  * @effects: pointer to an array of effects currently loaded into device
532*4882a593Smuzhiyun  * @effect_owners: array of effect owners; when file handle owning
533*4882a593Smuzhiyun  *	an effect gets closed the effect is automatically erased
534*4882a593Smuzhiyun  *
535*4882a593Smuzhiyun  * Every force-feedback device must implement upload() and playback()
536*4882a593Smuzhiyun  * methods; erase() is optional. set_gain() and set_autocenter() need
537*4882a593Smuzhiyun  * only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER
538*4882a593Smuzhiyun  * bits.
539*4882a593Smuzhiyun  *
540*4882a593Smuzhiyun  * Note that playback(), set_gain() and set_autocenter() are called with
541*4882a593Smuzhiyun  * dev->event_lock spinlock held and interrupts off and thus may not
542*4882a593Smuzhiyun  * sleep.
543*4882a593Smuzhiyun  */
544*4882a593Smuzhiyun struct ff_device {
545*4882a593Smuzhiyun 	int (*upload)(struct input_dev *dev, struct ff_effect *effect,
546*4882a593Smuzhiyun 		      struct ff_effect *old);
547*4882a593Smuzhiyun 	int (*erase)(struct input_dev *dev, int effect_id);
548*4882a593Smuzhiyun 
549*4882a593Smuzhiyun 	int (*playback)(struct input_dev *dev, int effect_id, int value);
550*4882a593Smuzhiyun 	void (*set_gain)(struct input_dev *dev, u16 gain);
551*4882a593Smuzhiyun 	void (*set_autocenter)(struct input_dev *dev, u16 magnitude);
552*4882a593Smuzhiyun 
553*4882a593Smuzhiyun 	void (*destroy)(struct ff_device *);
554*4882a593Smuzhiyun 
555*4882a593Smuzhiyun 	void *private;
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
558*4882a593Smuzhiyun 
559*4882a593Smuzhiyun 	struct mutex mutex;
560*4882a593Smuzhiyun 
561*4882a593Smuzhiyun 	int max_effects;
562*4882a593Smuzhiyun 	struct ff_effect *effects;
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
565*4882a593Smuzhiyun 
566*4882a593Smuzhiyun 	struct file *effect_owners[];
567*4882a593Smuzhiyun };
568*4882a593Smuzhiyun 
569*4882a593Smuzhiyun int input_ff_create(struct input_dev *dev, unsigned int max_effects);
570*4882a593Smuzhiyun void input_ff_destroy(struct input_dev *dev);
571*4882a593Smuzhiyun 
572*4882a593Smuzhiyun int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
573*4882a593Smuzhiyun 
574*4882a593Smuzhiyun int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);
575*4882a593Smuzhiyun int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);
576*4882a593Smuzhiyun int input_ff_flush(struct input_dev *dev, struct file *file);
577*4882a593Smuzhiyun 
578*4882a593Smuzhiyun int input_ff_create_memless(struct input_dev *dev, void *data,
579*4882a593Smuzhiyun 		int (*play_effect)(struct input_dev *, void *, struct ff_effect *));
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun #endif
582