blob: baeab83deb6469c5abb22ac61ee07f73b0dfedfe [file] [log] [blame]
David Howells607ca462012-10-13 10:46:48 +01001/*
2 * User level driver support for input subsystem
3 *
4 * Heavily based on evdev.c by Vojtech Pavlik
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
21 *
22 * Changes/Revisions:
Benjamin Tissoirese3480a62014-01-30 17:20:24 -080023 * 0.4 01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
24 * - add UI_GET_SYSNAME ioctl
David Howells607ca462012-10-13 10:46:48 +010025 * 0.3 24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>)
26 * - update ff support for the changes in kernel interface
27 * - add UINPUT_VERSION
28 * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>)
29 * - added force feedback support
30 * - added UI_SET_PHYS
31 * 0.1 20/06/2002
32 * - first public version
33 */
34#ifndef _UAPI__UINPUT_H_
35#define _UAPI__UINPUT_H_
36
37#include <linux/types.h>
38#include <linux/input.h>
39
Benjamin Tissoirese3480a62014-01-30 17:20:24 -080040#define UINPUT_VERSION 4
David Howells607ca462012-10-13 10:46:48 +010041
42
43struct uinput_ff_upload {
44 __u32 request_id;
45 __s32 retval;
46 struct ff_effect effect;
47 struct ff_effect old;
48};
49
50struct uinput_ff_erase {
51 __u32 request_id;
52 __s32 retval;
53 __u32 effect_id;
54};
55
56/* ioctl */
57#define UINPUT_IOCTL_BASE 'U'
58#define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1)
59#define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2)
60
61#define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int)
62#define UI_SET_KEYBIT _IOW(UINPUT_IOCTL_BASE, 101, int)
63#define UI_SET_RELBIT _IOW(UINPUT_IOCTL_BASE, 102, int)
64#define UI_SET_ABSBIT _IOW(UINPUT_IOCTL_BASE, 103, int)
65#define UI_SET_MSCBIT _IOW(UINPUT_IOCTL_BASE, 104, int)
66#define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int)
67#define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int)
68#define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int)
69#define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*)
70#define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int)
71#define UI_SET_PROPBIT _IOW(UINPUT_IOCTL_BASE, 110, int)
72
73#define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
74#define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
75#define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase)
76#define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase)
77
Benjamin Tissoirese3480a62014-01-30 17:20:24 -080078/**
79 * UI_GET_SYSNAME - get the sysfs name of the created uinput device
80 *
81 * @return the sysfs name of the created virtual input device.
82 * The complete sysfs path is then /sys/devices/virtual/input/--NAME--
83 * Usually, it is in the form "inputN"
84 */
85#define UI_GET_SYSNAME(len) _IOC(_IOC_READ, UINPUT_IOCTL_BASE, 300, len)
86
David Herrmannba4e9a62014-07-20 17:27:09 -070087/**
88 * UI_GET_VERSION - Return version of uinput protocol
89 *
90 * This writes uinput protocol version implemented by the kernel into
91 * the integer pointed to by the ioctl argument. The protocol version
92 * is hard-coded in the kernel and is independent of the uinput device.
93 */
94#define UI_GET_VERSION _IOR(UINPUT_IOCTL_BASE, 301, unsigned int)
95
David Howells607ca462012-10-13 10:46:48 +010096/*
97 * To write a force-feedback-capable driver, the upload_effect
98 * and erase_effect callbacks in input_dev must be implemented.
99 * The uinput driver will generate a fake input event when one of
100 * these callbacks are invoked. The userspace code then uses
101 * ioctls to retrieve additional parameters and send the return code.
102 * The callback blocks until this return code is sent.
103 *
104 * The described callback mechanism is only used if ff_effects_max
105 * is set.
106 *
107 * To implement upload_effect():
108 * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_UPLOAD.
109 * A request ID will be given in 'value'.
110 * 2. Allocate a uinput_ff_upload struct, fill in request_id with
111 * the 'value' from the EV_UINPUT event.
112 * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the
113 * uinput_ff_upload struct. It will be filled in with the
114 * ff_effects passed to upload_effect().
115 * 4. Perform the effect upload, and place a return code back into
116 the uinput_ff_upload struct.
117 * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the
118 * uinput_ff_upload_effect struct. This will complete execution
119 * of our upload_effect() handler.
120 *
121 * To implement erase_effect():
122 * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_ERASE.
123 * A request ID will be given in 'value'.
124 * 2. Allocate a uinput_ff_erase struct, fill in request_id with
125 * the 'value' from the EV_UINPUT event.
126 * 3. Issue a UI_BEGIN_FF_ERASE ioctl, giving it the
127 * uinput_ff_erase struct. It will be filled in with the
128 * effect ID passed to erase_effect().
129 * 4. Perform the effect erasure, and place a return code back
130 * into the uinput_ff_erase struct.
131 * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the
132 * uinput_ff_erase_effect struct. This will complete execution
133 * of our erase_effect() handler.
134 */
135
136/*
137 * This is the new event type, used only by uinput.
138 * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value'
139 * is the unique request ID. This number was picked
140 * arbitrarily, above EV_MAX (since the input system
141 * never sees it) but in the range of a 16-bit int.
142 */
143#define EV_UINPUT 0x0101
144#define UI_FF_UPLOAD 1
145#define UI_FF_ERASE 2
146
147#define UINPUT_MAX_NAME_SIZE 80
148struct uinput_user_dev {
149 char name[UINPUT_MAX_NAME_SIZE];
150 struct input_id id;
151 __u32 ff_effects_max;
152 __s32 absmax[ABS_CNT];
153 __s32 absmin[ABS_CNT];
154 __s32 absfuzz[ABS_CNT];
155 __s32 absflat[ABS_CNT];
156};
157#endif /* _UAPI__UINPUT_H_ */