blob: 84876077027fb6c89643b76f9938085efdcfab86 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __UINPUT_H_
2#define __UINPUT_H_
3/*
4 * User level driver support for input subsystem
5 *
6 * Heavily based on evdev.c by Vojtech Pavlik
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
23 *
24 * Changes/Revisions:
25 * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>)
26 * - added force feedback support
27 * - added UI_SET_PHYS
28 * 0.1 20/06/2002
29 * - first public version
30 */
31#ifdef __KERNEL__
32#define UINPUT_MINOR 223
33#define UINPUT_NAME "uinput"
34#define UINPUT_BUFFER_SIZE 16
35#define UINPUT_NUM_REQUESTS 16
36
37/* state flags => bit index for {set|clear|test}_bit ops */
38#define UIST_CREATED 0
39
40struct uinput_request {
41 int id;
42 int code; /* UI_FF_UPLOAD, UI_FF_ERASE */
43
44 int retval;
Dmitry Torokhov0048e602005-06-30 00:48:14 -050045 struct completion done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 union {
48 int effect_id;
49 struct ff_effect* effect;
50 } u;
51};
52
53struct uinput_device {
54 struct input_dev *dev;
55 unsigned long state;
56 wait_queue_head_t waitq;
57 unsigned char ready,
58 head,
59 tail;
60 struct input_event buff[UINPUT_BUFFER_SIZE];
61
62 struct uinput_request *requests[UINPUT_NUM_REQUESTS];
63 wait_queue_head_t requests_waitq;
Dmitry Torokhov0048e602005-06-30 00:48:14 -050064 spinlock_t requests_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66#endif /* __KERNEL__ */
67
68struct uinput_ff_upload {
69 int request_id;
70 int retval;
71 struct ff_effect effect;
72};
73
74struct uinput_ff_erase {
75 int request_id;
76 int retval;
77 int effect_id;
78};
79
80/* ioctl */
81#define UINPUT_IOCTL_BASE 'U'
82#define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1)
83#define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2)
84
85#define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int)
86#define UI_SET_KEYBIT _IOW(UINPUT_IOCTL_BASE, 101, int)
87#define UI_SET_RELBIT _IOW(UINPUT_IOCTL_BASE, 102, int)
88#define UI_SET_ABSBIT _IOW(UINPUT_IOCTL_BASE, 103, int)
89#define UI_SET_MSCBIT _IOW(UINPUT_IOCTL_BASE, 104, int)
90#define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int)
91#define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int)
92#define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int)
93#define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*)
94
95#define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
96#define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
97#define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase)
98#define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase)
99
100/* To write a force-feedback-capable driver, the upload_effect
101 * and erase_effect callbacks in input_dev must be implemented.
102 * The uinput driver will generate a fake input event when one of
103 * these callbacks are invoked. The userspace code then uses
104 * ioctls to retrieve additional parameters and send the return code.
105 * The callback blocks until this return code is sent.
106 *
107 * The described callback mechanism is only used if EV_FF is set.
108 * Otherwise, default implementations of upload_effect and erase_effect
109 * are used.
110 *
111 * To implement upload_effect():
112 * 1. Wait for an event with type==EV_UINPUT and code==UI_FF_UPLOAD.
113 * A request ID will be given in 'value'.
114 * 2. Allocate a uinput_ff_upload struct, fill in request_id with
115 * the 'value' from the EV_UINPUT event.
116 * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the
117 * uinput_ff_upload struct. It will be filled in with the
118 * ff_effect passed to upload_effect().
119 * 4. Perform the effect upload, and place the modified ff_effect
120 * and a return code back into the uinput_ff_upload struct.
121 * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the
122 * uinput_ff_upload_effect struct. This will complete execution
123 * of our upload_effect() handler.
124 *
125 * To implement erase_effect():
126 * 1. Wait for an event with type==EV_UINPUT and code==UI_FF_ERASE.
127 * A request ID will be given in 'value'.
128 * 2. Allocate a uinput_ff_erase struct, fill in request_id with
129 * the 'value' from the EV_UINPUT event.
130 * 3. Issue a UI_BEGIN_FF_ERASE ioctl, giving it the
131 * uinput_ff_erase struct. It will be filled in with the
132 * effect ID passed to erase_effect().
133 * 4. Perform the effect erasure, and place a return code back
134 * into the uinput_ff_erase struct.
135 * and a return code back into the uinput_ff_erase struct.
136 * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the
137 * uinput_ff_erase_effect struct. This will complete execution
138 * of our erase_effect() handler.
139 */
140
141/* This is the new event type, used only by uinput.
142 * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value'
143 * is the unique request ID. This number was picked
144 * arbitrarily, above EV_MAX (since the input system
145 * never sees it) but in the range of a 16-bit int.
146 */
147#define EV_UINPUT 0x0101
148#define UI_FF_UPLOAD 1
149#define UI_FF_ERASE 2
150
151#ifndef NBITS
152#define NBITS(x) ((((x)-1)/(sizeof(long)*8))+1)
153#endif /* NBITS */
154
155#define UINPUT_MAX_NAME_SIZE 80
156struct uinput_user_dev {
157 char name[UINPUT_MAX_NAME_SIZE];
158 struct input_id id;
159 int ff_effects_max;
160 int absmax[ABS_MAX + 1];
161 int absmin[ABS_MAX + 1];
162 int absfuzz[ABS_MAX + 1];
163 int absflat[ABS_MAX + 1];
164};
165#endif /* __UINPUT_H_ */
166