blob: c3eebf593ab642741b28b163c02bcd439f1a0324 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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:
23 * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>)
24 * - added force feedback support
25 * - added UI_SET_PHYS
26 * 0.1 20/06/2002
27 * - first public version
28 */
29#include <linux/poll.h>
30#include <linux/slab.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/input.h>
34#include <linux/smp_lock.h>
35#include <linux/fs.h>
36#include <linux/miscdevice.h>
37#include <linux/uinput.h>
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
40{
41 struct uinput_device *udev;
42
43 udev = dev->private;
44
45 udev->buff[udev->head].type = type;
46 udev->buff[udev->head].code = code;
47 udev->buff[udev->head].value = value;
48 do_gettimeofday(&udev->buff[udev->head].time);
49 udev->head = (udev->head + 1) % UINPUT_BUFFER_SIZE;
50
51 wake_up_interruptible(&udev->waitq);
52
53 return 0;
54}
55
Dmitry Torokhov0048e602005-06-30 00:48:14 -050056static int uinput_request_alloc_id(struct uinput_device *udev, struct uinput_request *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
58 /* Atomically allocate an ID for the given request. Returns 0 on success. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 int id;
Dmitry Torokhov152c12f2005-06-30 00:47:50 -050060 int err = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Dmitry Torokhov0048e602005-06-30 00:48:14 -050062 spin_lock(&udev->requests_lock);
Dmitry Torokhov152c12f2005-06-30 00:47:50 -050063
64 for (id = 0; id < UINPUT_NUM_REQUESTS; id++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 if (!udev->requests[id]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 request->id = id;
Dmitry Torokhov0048e602005-06-30 00:48:14 -050067 udev->requests[id] = request;
Dmitry Torokhov152c12f2005-06-30 00:47:50 -050068 err = 0;
69 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 }
Dmitry Torokhov152c12f2005-06-30 00:47:50 -050071
Dmitry Torokhov0048e602005-06-30 00:48:14 -050072 spin_unlock(&udev->requests_lock);
Dmitry Torokhov152c12f2005-06-30 00:47:50 -050073 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
76static struct uinput_request* uinput_request_find(struct uinput_device *udev, int id)
77{
78 /* Find an input request, by ID. Returns NULL if the ID isn't valid. */
79 if (id >= UINPUT_NUM_REQUESTS || id < 0)
80 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return udev->requests[id];
82}
83
Dmitry Torokhov0048e602005-06-30 00:48:14 -050084static inline int uinput_request_reserve_slot(struct uinput_device *udev, struct uinput_request *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Dmitry Torokhov0048e602005-06-30 00:48:14 -050086 /* Allocate slot. If none are available right away, wait. */
87 return wait_event_interruptible(udev->requests_waitq,
88 !uinput_request_alloc_id(udev, request));
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Dmitry Torokhov0048e602005-06-30 00:48:14 -050091static void uinput_request_done(struct uinput_device *udev, struct uinput_request *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Dmitry Torokhov0048e602005-06-30 00:48:14 -050093 complete(&request->done);
94
95 /* Mark slot as available */
96 udev->requests[request->id] = NULL;
97 wake_up_interruptible(&udev->requests_waitq);
98}
99
100static int uinput_request_submit(struct input_dev *dev, struct uinput_request *request)
101{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 int retval;
103
104 /* Tell our userspace app about this new request by queueing an input event */
105 uinput_dev_event(dev, EV_UINPUT, request->code, request->id);
106
107 /* Wait for the request to complete */
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500108 retval = wait_for_completion_interruptible(&request->done);
109 if (!retval)
110 retval = request->retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500112 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
115static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect)
116{
117 struct uinput_request request;
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500118 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 if (!test_bit(EV_FF, dev->evbit))
121 return -ENOSYS;
122
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500123 request.id = -1;
124 init_completion(&request.done);
125 request.code = UI_FF_UPLOAD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 request.u.effect = effect;
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500127
128 retval = uinput_request_reserve_slot(dev->private, &request);
129 if (!retval)
130 retval = uinput_request_submit(dev, &request);
131
132 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
135static int uinput_dev_erase_effect(struct input_dev *dev, int effect_id)
136{
137 struct uinput_request request;
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500138 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 if (!test_bit(EV_FF, dev->evbit))
141 return -ENOSYS;
142
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500143 request.id = -1;
144 init_completion(&request.done);
145 request.code = UI_FF_ERASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 request.u.effect_id = effect_id;
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500147
148 retval = uinput_request_reserve_slot(dev->private, &request);
149 if (!retval)
150 retval = uinput_request_submit(dev, &request);
151
152 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
155static int uinput_create_device(struct uinput_device *udev)
156{
157 if (!udev->dev->name) {
158 printk(KERN_DEBUG "%s: write device info first\n", UINPUT_NAME);
159 return -EINVAL;
160 }
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 udev->dev->event = uinput_dev_event;
163 udev->dev->upload_effect = uinput_dev_upload_effect;
164 udev->dev->erase_effect = uinput_dev_erase_effect;
165 udev->dev->private = udev;
166
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500167 init_waitqueue_head(&udev->waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 input_register_device(udev->dev);
170
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500171 set_bit(UIST_CREATED, &udev->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 return 0;
174}
175
176static int uinput_destroy_device(struct uinput_device *udev)
177{
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500178 if (!test_bit(UIST_CREATED, &udev->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 printk(KERN_WARNING "%s: create the device first\n", UINPUT_NAME);
180 return -EINVAL;
181 }
182
183 input_unregister_device(udev->dev);
184
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500185 clear_bit(UIST_CREATED, &udev->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 return 0;
188}
189
190static int uinput_open(struct inode *inode, struct file *file)
191{
192 struct uinput_device *newdev;
193 struct input_dev *newinput;
194
195 newdev = kmalloc(sizeof(struct uinput_device), GFP_KERNEL);
196 if (!newdev)
197 goto error;
198 memset(newdev, 0, sizeof(struct uinput_device));
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500199 spin_lock_init(&newdev->requests_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 init_waitqueue_head(&newdev->requests_waitq);
201
202 newinput = kmalloc(sizeof(struct input_dev), GFP_KERNEL);
203 if (!newinput)
204 goto cleanup;
205 memset(newinput, 0, sizeof(struct input_dev));
206
207 newdev->dev = newinput;
208
209 file->private_data = newdev;
210
211 return 0;
212cleanup:
213 kfree(newdev);
214error:
215 return -ENOMEM;
216}
217
218static int uinput_validate_absbits(struct input_dev *dev)
219{
220 unsigned int cnt;
221 int retval = 0;
222
223 for (cnt = 0; cnt < ABS_MAX + 1; cnt++) {
224 if (!test_bit(cnt, dev->absbit))
225 continue;
226
227 if ((dev->absmax[cnt] <= dev->absmin[cnt])) {
228 printk(KERN_DEBUG
229 "%s: invalid abs[%02x] min:%d max:%d\n",
230 UINPUT_NAME, cnt,
231 dev->absmin[cnt], dev->absmax[cnt]);
232 retval = -EINVAL;
233 break;
234 }
235
236 if (dev->absflat[cnt] > (dev->absmax[cnt] - dev->absmin[cnt])) {
237 printk(KERN_DEBUG
238 "%s: absflat[%02x] out of range: %d "
239 "(min:%d/max:%d)\n",
240 UINPUT_NAME, cnt, dev->absflat[cnt],
241 dev->absmin[cnt], dev->absmax[cnt]);
242 retval = -EINVAL;
243 break;
244 }
245 }
246 return retval;
247}
248
249static int uinput_alloc_device(struct file *file, const char __user *buffer, size_t count)
250{
251 struct uinput_user_dev *user_dev;
252 struct input_dev *dev;
253 struct uinput_device *udev;
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500254 int size;
255 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 retval = count;
258
259 udev = file->private_data;
260 dev = udev->dev;
261
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500262 user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if (!user_dev) {
264 retval = -ENOMEM;
265 goto exit;
266 }
267
268 if (copy_from_user(user_dev, buffer, sizeof(struct uinput_user_dev))) {
269 retval = -EFAULT;
270 goto exit;
271 }
272
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500273 if (dev->name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 kfree(dev->name);
275
276 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1;
277 dev->name = kmalloc(size, GFP_KERNEL);
278 if (!dev->name) {
279 retval = -ENOMEM;
280 goto exit;
281 }
282
283 strlcpy(dev->name, user_dev->name, size);
284 dev->id.bustype = user_dev->id.bustype;
285 dev->id.vendor = user_dev->id.vendor;
286 dev->id.product = user_dev->id.product;
287 dev->id.version = user_dev->id.version;
288 dev->ff_effects_max = user_dev->ff_effects_max;
289
290 size = sizeof(int) * (ABS_MAX + 1);
291 memcpy(dev->absmax, user_dev->absmax, size);
292 memcpy(dev->absmin, user_dev->absmin, size);
293 memcpy(dev->absfuzz, user_dev->absfuzz, size);
294 memcpy(dev->absflat, user_dev->absflat, size);
295
296 /* check if absmin/absmax/absfuzz/absflat are filled as
297 * told in Documentation/input/input-programming.txt */
298 if (test_bit(EV_ABS, dev->evbit)) {
Ian Campbellb6cbf3e2005-06-01 02:39:25 -0500299 int err = uinput_validate_absbits(dev);
300 if (err < 0) {
301 retval = err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 kfree(dev->name);
Ian Campbellb6cbf3e2005-06-01 02:39:25 -0500303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
305
306exit:
307 kfree(user_dev);
308 return retval;
309}
310
311static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
312{
313 struct uinput_device *udev = file->private_data;
314
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500315 if (test_bit(UIST_CREATED, &udev->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 struct input_event ev;
317
318 if (copy_from_user(&ev, buffer, sizeof(struct input_event)))
319 return -EFAULT;
320 input_event(udev->dev, ev.type, ev.code, ev.value);
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500321 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 count = uinput_alloc_device(file, buffer, count);
323
324 return count;
325}
326
327static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
328{
329 struct uinput_device *udev = file->private_data;
330 int retval = 0;
331
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500332 if (!test_bit(UIST_CREATED, &udev->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 return -ENODEV;
334
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500335 if (udev->head == udev->tail && (file->f_flags & O_NONBLOCK))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return -EAGAIN;
337
338 retval = wait_event_interruptible(udev->waitq,
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500339 udev->head != udev->tail || !test_bit(UIST_CREATED, &udev->state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (retval)
341 return retval;
342
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500343 if (!test_bit(UIST_CREATED, &udev->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return -ENODEV;
345
346 while ((udev->head != udev->tail) &&
347 (retval + sizeof(struct input_event) <= count)) {
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500348 if (copy_to_user(buffer + retval, &udev->buff[udev->tail], sizeof(struct input_event)))
349 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE;
351 retval += sizeof(struct input_event);
352 }
353
354 return retval;
355}
356
357static unsigned int uinput_poll(struct file *file, poll_table *wait)
358{
359 struct uinput_device *udev = file->private_data;
360
361 poll_wait(file, &udev->waitq, wait);
362
363 if (udev->head != udev->tail)
364 return POLLIN | POLLRDNORM;
365
366 return 0;
367}
368
369static int uinput_burn_device(struct uinput_device *udev)
370{
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500371 if (test_bit(UIST_CREATED, &udev->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 uinput_destroy_device(udev);
373
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500374 if (udev->dev->name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 kfree(udev->dev->name);
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500376 if (udev->dev->phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 kfree(udev->dev->phys);
378
379 kfree(udev->dev);
380 kfree(udev);
381
382 return 0;
383}
384
385static int uinput_close(struct inode *inode, struct file *file)
386{
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500387 uinput_burn_device(file->private_data);
388 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
391static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
392{
393 int retval = 0;
394 struct uinput_device *udev;
395 void __user *p = (void __user *)arg;
396 struct uinput_ff_upload ff_up;
397 struct uinput_ff_erase ff_erase;
398 struct uinput_request *req;
399 int length;
400
401 udev = file->private_data;
402
403 /* device attributes can not be changed after the device is created */
404 switch (cmd) {
405 case UI_SET_EVBIT:
406 case UI_SET_KEYBIT:
407 case UI_SET_RELBIT:
408 case UI_SET_ABSBIT:
409 case UI_SET_MSCBIT:
410 case UI_SET_LEDBIT:
411 case UI_SET_SNDBIT:
412 case UI_SET_FFBIT:
413 case UI_SET_PHYS:
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500414 if (test_bit(UIST_CREATED, &udev->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return -EINVAL;
416 }
417
418 switch (cmd) {
419 case UI_DEV_CREATE:
420 retval = uinput_create_device(udev);
421 break;
422
423 case UI_DEV_DESTROY:
424 retval = uinput_destroy_device(udev);
425 break;
426
427 case UI_SET_EVBIT:
428 if (arg > EV_MAX) {
429 retval = -EINVAL;
430 break;
431 }
432 set_bit(arg, udev->dev->evbit);
433 break;
434
435 case UI_SET_KEYBIT:
436 if (arg > KEY_MAX) {
437 retval = -EINVAL;
438 break;
439 }
440 set_bit(arg, udev->dev->keybit);
441 break;
442
443 case UI_SET_RELBIT:
444 if (arg > REL_MAX) {
445 retval = -EINVAL;
446 break;
447 }
448 set_bit(arg, udev->dev->relbit);
449 break;
450
451 case UI_SET_ABSBIT:
452 if (arg > ABS_MAX) {
453 retval = -EINVAL;
454 break;
455 }
456 set_bit(arg, udev->dev->absbit);
457 break;
458
459 case UI_SET_MSCBIT:
460 if (arg > MSC_MAX) {
461 retval = -EINVAL;
462 break;
463 }
464 set_bit(arg, udev->dev->mscbit);
465 break;
466
467 case UI_SET_LEDBIT:
468 if (arg > LED_MAX) {
469 retval = -EINVAL;
470 break;
471 }
472 set_bit(arg, udev->dev->ledbit);
473 break;
474
475 case UI_SET_SNDBIT:
476 if (arg > SND_MAX) {
477 retval = -EINVAL;
478 break;
479 }
480 set_bit(arg, udev->dev->sndbit);
481 break;
482
483 case UI_SET_FFBIT:
484 if (arg > FF_MAX) {
485 retval = -EINVAL;
486 break;
487 }
488 set_bit(arg, udev->dev->ffbit);
489 break;
490
491 case UI_SET_PHYS:
492 length = strnlen_user(p, 1024);
493 if (length <= 0) {
494 retval = -EFAULT;
495 break;
496 }
497 if (NULL != udev->dev->phys)
498 kfree(udev->dev->phys);
499 udev->dev->phys = kmalloc(length, GFP_KERNEL);
500 if (!udev->dev->phys) {
501 retval = -ENOMEM;
502 break;
503 }
504 if (copy_from_user(udev->dev->phys, p, length)) {
505 retval = -EFAULT;
506 kfree(udev->dev->phys);
507 udev->dev->phys = NULL;
508 break;
509 }
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500510 udev->dev->phys[length - 1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 break;
512
513 case UI_BEGIN_FF_UPLOAD:
514 if (copy_from_user(&ff_up, p, sizeof(ff_up))) {
515 retval = -EFAULT;
516 break;
517 }
518 req = uinput_request_find(udev, ff_up.request_id);
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500519 if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 retval = -EINVAL;
521 break;
522 }
523 ff_up.retval = 0;
524 memcpy(&ff_up.effect, req->u.effect, sizeof(struct ff_effect));
525 if (copy_to_user(p, &ff_up, sizeof(ff_up))) {
526 retval = -EFAULT;
527 break;
528 }
529 break;
530
531 case UI_BEGIN_FF_ERASE:
532 if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
533 retval = -EFAULT;
534 break;
535 }
536 req = uinput_request_find(udev, ff_erase.request_id);
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500537 if (!(req && req->code == UI_FF_ERASE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 retval = -EINVAL;
539 break;
540 }
541 ff_erase.retval = 0;
542 ff_erase.effect_id = req->u.effect_id;
543 if (copy_to_user(p, &ff_erase, sizeof(ff_erase))) {
544 retval = -EFAULT;
545 break;
546 }
547 break;
548
549 case UI_END_FF_UPLOAD:
550 if (copy_from_user(&ff_up, p, sizeof(ff_up))) {
551 retval = -EFAULT;
552 break;
553 }
554 req = uinput_request_find(udev, ff_up.request_id);
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500555 if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 retval = -EINVAL;
557 break;
558 }
559 req->retval = ff_up.retval;
560 memcpy(req->u.effect, &ff_up.effect, sizeof(struct ff_effect));
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500561 uinput_request_done(udev, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 break;
563
564 case UI_END_FF_ERASE:
565 if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) {
566 retval = -EFAULT;
567 break;
568 }
569 req = uinput_request_find(udev, ff_erase.request_id);
Dmitry Torokhov152c12f2005-06-30 00:47:50 -0500570 if (!(req && req->code == UI_FF_ERASE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 retval = -EINVAL;
572 break;
573 }
574 req->retval = ff_erase.retval;
Dmitry Torokhov0048e602005-06-30 00:48:14 -0500575 uinput_request_done(udev, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 break;
577
578 default:
579 retval = -EINVAL;
580 }
581 return retval;
582}
583
584static struct file_operations uinput_fops = {
585 .owner = THIS_MODULE,
586 .open = uinput_open,
587 .release = uinput_close,
588 .read = uinput_read,
589 .write = uinput_write,
590 .poll = uinput_poll,
591 .ioctl = uinput_ioctl,
592};
593
594static struct miscdevice uinput_misc = {
595 .fops = &uinput_fops,
596 .minor = UINPUT_MINOR,
597 .name = UINPUT_NAME,
598};
599
600static int __init uinput_init(void)
601{
602 return misc_register(&uinput_misc);
603}
604
605static void __exit uinput_exit(void)
606{
607 misc_deregister(&uinput_misc);
608}
609
610MODULE_AUTHOR("Aristeu Sergio Rozanski Filho");
611MODULE_DESCRIPTION("User level driver support for input subsystem");
612MODULE_LICENSE("GPL");
613
614module_init(uinput_init);
615module_exit(uinput_exit);
616