blob: 901b2525993e54f77c219cac9b1d55e3431219e5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Joystick device driver for the input driver suite.
3 *
4 * Copyright (c) 1999-2002 Vojtech Pavlik
5 * Copyright (c) 1999 Colin Van Dyke
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <asm/io.h>
14#include <asm/system.h>
15#include <linux/delay.h>
16#include <linux/errno.h>
17#include <linux/joystick.h>
18#include <linux/input.h>
19#include <linux/kernel.h>
20#include <linux/major.h>
21#include <linux/slab.h>
22#include <linux/mm.h>
23#include <linux/miscdevice.h>
24#include <linux/module.h>
25#include <linux/poll.h>
26#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
30MODULE_DESCRIPTION("Joystick device interfaces");
31MODULE_SUPPORTED_DEVICE("input/js");
32MODULE_LICENSE("GPL");
33
34#define JOYDEV_MINOR_BASE 0
35#define JOYDEV_MINORS 16
36#define JOYDEV_BUFFER_SIZE 64
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038struct joydev {
39 int exist;
40 int open;
41 int minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 struct input_handle handle;
43 wait_queue_head_t wait;
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -040044 struct list_head client_list;
Dmitry Torokhovb1262072007-08-30 00:22:32 -040045 spinlock_t client_lock; /* protects client_list */
46 struct mutex mutex;
Dmitry Torokhov9657d752007-06-14 23:32:24 -040047 struct device dev;
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 struct js_corr corr[ABS_MAX + 1];
50 struct JS_DATA_SAVE_TYPE glue;
51 int nabs;
52 int nkey;
53 __u16 keymap[KEY_MAX - BTN_MISC + 1];
54 __u16 keypam[KEY_MAX - BTN_MISC + 1];
55 __u8 absmap[ABS_MAX + 1];
56 __u8 abspam[ABS_MAX + 1];
57 __s16 abs[ABS_MAX + 1];
58};
59
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -040060struct joydev_client {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 struct js_event buffer[JOYDEV_BUFFER_SIZE];
62 int head;
63 int tail;
64 int startup;
Dmitry Torokhovb1262072007-08-30 00:22:32 -040065 spinlock_t buffer_lock; /* protects access to buffer, head and tail */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 struct fasync_struct *fasync;
67 struct joydev *joydev;
68 struct list_head node;
69};
70
71static struct joydev *joydev_table[JOYDEV_MINORS];
Dmitry Torokhovb1262072007-08-30 00:22:32 -040072static DEFINE_MUTEX(joydev_table_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74static int joydev_correct(int value, struct js_corr *corr)
75{
76 switch (corr->type) {
Dmitry Torokhovb1262072007-08-30 00:22:32 -040077
78 case JS_CORR_NONE:
79 break;
80
81 case JS_CORR_BROKEN:
82 value = value > corr->coef[0] ? (value < corr->coef[1] ? 0 :
83 ((corr->coef[3] * (value - corr->coef[1])) >> 14)) :
84 ((corr->coef[2] * (value - corr->coef[0])) >> 14);
85 break;
86
87 default:
88 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -040091 return value < -32767 ? -32767 : (value > 32767 ? 32767 : value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Dmitry Torokhovb1262072007-08-30 00:22:32 -040094static void joydev_pass_event(struct joydev_client *client,
95 struct js_event *event)
96{
97 struct joydev *joydev = client->joydev;
98
99 /*
100 * IRQs already disabled, just acquire the lock
101 */
102 spin_lock(&client->buffer_lock);
103
104 client->buffer[client->head] = *event;
105
106 if (client->startup == joydev->nabs + joydev->nkey) {
107 client->head++;
108 client->head &= JOYDEV_BUFFER_SIZE - 1;
109 if (client->tail == client->head)
110 client->startup = 0;
111 }
112
113 spin_unlock(&client->buffer_lock);
114
115 kill_fasync(&client->fasync, SIGIO, POLL_IN);
116}
117
118static void joydev_event(struct input_handle *handle,
119 unsigned int type, unsigned int code, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
121 struct joydev *joydev = handle->private;
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400122 struct joydev_client *client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 struct js_event event;
124
125 switch (type) {
126
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400127 case EV_KEY:
128 if (code < BTN_MISC || value == 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400130 event.type = JS_EVENT_BUTTON;
131 event.number = joydev->keymap[code - BTN_MISC];
132 event.value = value;
133 break;
134
135 case EV_ABS:
136 event.type = JS_EVENT_AXIS;
137 event.number = joydev->absmap[code];
138 event.value = joydev_correct(value,
139 &joydev->corr[event.number]);
140 if (event.value == joydev->abs[event.number])
141 return;
142 joydev->abs[event.number] = event.value;
143 break;
144
145 default:
146 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148
Tobias Klauser6f5eacf2005-07-11 01:08:56 -0500149 event.time = jiffies_to_msecs(jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Dmitry Torokhov82ba56c2007-10-13 15:46:55 -0400151 rcu_read_lock();
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400152 list_for_each_entry_rcu(client, &joydev->client_list, node)
153 joydev_pass_event(client, &event);
Dmitry Torokhov82ba56c2007-10-13 15:46:55 -0400154 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 wake_up_interruptible(&joydev->wait);
157}
158
159static int joydev_fasync(int fd, struct file *file, int on)
160{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400161 struct joydev_client *client = file->private_data;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400162
Jonathan Corbet60aa4922009-02-01 14:52:56 -0700163 return fasync_helper(fd, file, on, &client->fasync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400166static void joydev_free(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400168 struct joydev *joydev = container_of(dev, struct joydev, dev);
169
Dmitry Torokhova7097ff2008-04-01 00:22:53 -0400170 input_put_device(joydev->handle.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 kfree(joydev);
172}
173
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400174static void joydev_attach_client(struct joydev *joydev,
175 struct joydev_client *client)
176{
177 spin_lock(&joydev->client_lock);
178 list_add_tail_rcu(&client->node, &joydev->client_list);
179 spin_unlock(&joydev->client_lock);
Dmitry Torokhov82ba56c2007-10-13 15:46:55 -0400180 synchronize_rcu();
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400181}
182
183static void joydev_detach_client(struct joydev *joydev,
184 struct joydev_client *client)
185{
186 spin_lock(&joydev->client_lock);
187 list_del_rcu(&client->node);
188 spin_unlock(&joydev->client_lock);
Dmitry Torokhov82ba56c2007-10-13 15:46:55 -0400189 synchronize_rcu();
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400190}
191
192static int joydev_open_device(struct joydev *joydev)
193{
194 int retval;
195
196 retval = mutex_lock_interruptible(&joydev->mutex);
197 if (retval)
198 return retval;
199
200 if (!joydev->exist)
201 retval = -ENODEV;
Oliver Neukum06445012007-10-12 14:18:40 -0400202 else if (!joydev->open++) {
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400203 retval = input_open_device(&joydev->handle);
Oliver Neukum06445012007-10-12 14:18:40 -0400204 if (retval)
205 joydev->open--;
206 }
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400207
208 mutex_unlock(&joydev->mutex);
209 return retval;
210}
211
212static void joydev_close_device(struct joydev *joydev)
213{
214 mutex_lock(&joydev->mutex);
215
216 if (joydev->exist && !--joydev->open)
217 input_close_device(&joydev->handle);
218
219 mutex_unlock(&joydev->mutex);
220}
221
222/*
223 * Wake up users waiting for IO so they can disconnect from
224 * dead device.
225 */
226static void joydev_hangup(struct joydev *joydev)
227{
228 struct joydev_client *client;
229
230 spin_lock(&joydev->client_lock);
231 list_for_each_entry(client, &joydev->client_list, node)
232 kill_fasync(&client->fasync, SIGIO, POLL_HUP);
233 spin_unlock(&joydev->client_lock);
234
235 wake_up_interruptible(&joydev->wait);
236}
237
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400238static int joydev_release(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400240 struct joydev_client *client = file->private_data;
241 struct joydev *joydev = client->joydev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400243 joydev_detach_client(joydev, client);
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400244 kfree(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400246 joydev_close_device(joydev);
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400247 put_device(&joydev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return 0;
250}
251
252static int joydev_open(struct inode *inode, struct file *file)
253{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400254 struct joydev_client *client;
255 struct joydev *joydev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 int i = iminor(inode) - JOYDEV_MINOR_BASE;
Dmitry Torokhovd542ed82007-04-12 01:30:15 -0400257 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400259 if (i >= JOYDEV_MINORS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return -ENODEV;
261
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400262 error = mutex_lock_interruptible(&joydev_table_mutex);
263 if (error)
264 return error;
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400265 joydev = joydev_table[i];
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400266 if (joydev)
267 get_device(&joydev->dev);
268 mutex_unlock(&joydev_table_mutex);
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400269
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400270 if (!joydev)
271 return -ENODEV;
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400272
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400273 client = kzalloc(sizeof(struct joydev_client), GFP_KERNEL);
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400274 if (!client) {
275 error = -ENOMEM;
276 goto err_put_joydev;
277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400279 spin_lock_init(&client->buffer_lock);
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400280 client->joydev = joydev;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400281 joydev_attach_client(joydev, client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400283 error = joydev_open_device(joydev);
284 if (error)
285 goto err_free_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400287 file->private_data = client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 return 0;
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400289
290 err_free_client:
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400291 joydev_detach_client(joydev, client);
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400292 kfree(client);
293 err_put_joydev:
294 put_device(&joydev->dev);
295 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400298static int joydev_generate_startup_event(struct joydev_client *client,
299 struct input_dev *input,
300 struct js_event *event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400302 struct joydev *joydev = client->joydev;
303 int have_event;
304
305 spin_lock_irq(&client->buffer_lock);
306
307 have_event = client->startup < joydev->nabs + joydev->nkey;
308
309 if (have_event) {
310
311 event->time = jiffies_to_msecs(jiffies);
312 if (client->startup < joydev->nkey) {
313 event->type = JS_EVENT_BUTTON | JS_EVENT_INIT;
314 event->number = client->startup;
315 event->value = !!test_bit(joydev->keypam[event->number],
316 input->key);
317 } else {
318 event->type = JS_EVENT_AXIS | JS_EVENT_INIT;
319 event->number = client->startup - joydev->nkey;
320 event->value = joydev->abs[event->number];
321 }
322 client->startup++;
323 }
324
325 spin_unlock_irq(&client->buffer_lock);
326
327 return have_event;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328}
329
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400330static int joydev_fetch_next_event(struct joydev_client *client,
331 struct js_event *event)
332{
333 int have_event;
334
335 spin_lock_irq(&client->buffer_lock);
336
337 have_event = client->head != client->tail;
338 if (have_event) {
339 *event = client->buffer[client->tail++];
340 client->tail &= JOYDEV_BUFFER_SIZE - 1;
341 }
342
343 spin_unlock_irq(&client->buffer_lock);
344
345 return have_event;
346}
347
348/*
349 * Old joystick interface
350 */
351static ssize_t joydev_0x_read(struct joydev_client *client,
352 struct input_dev *input,
353 char __user *buf)
354{
355 struct joydev *joydev = client->joydev;
356 struct JS_DATA_TYPE data;
357 int i;
358
359 spin_lock_irq(&input->event_lock);
360
361 /*
362 * Get device state
363 */
364 for (data.buttons = i = 0; i < 32 && i < joydev->nkey; i++)
365 data.buttons |=
366 test_bit(joydev->keypam[i], input->key) ? (1 << i) : 0;
367 data.x = (joydev->abs[0] / 256 + 128) >> joydev->glue.JS_CORR.x;
368 data.y = (joydev->abs[1] / 256 + 128) >> joydev->glue.JS_CORR.y;
369
370 /*
371 * Reset reader's event queue
372 */
373 spin_lock(&client->buffer_lock);
374 client->startup = 0;
375 client->tail = client->head;
376 spin_unlock(&client->buffer_lock);
377
378 spin_unlock_irq(&input->event_lock);
379
380 if (copy_to_user(buf, &data, sizeof(struct JS_DATA_TYPE)))
381 return -EFAULT;
382
383 return sizeof(struct JS_DATA_TYPE);
384}
385
386static inline int joydev_data_pending(struct joydev_client *client)
387{
388 struct joydev *joydev = client->joydev;
389
390 return client->startup < joydev->nabs + joydev->nkey ||
391 client->head != client->tail;
392}
393
394static ssize_t joydev_read(struct file *file, char __user *buf,
395 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400397 struct joydev_client *client = file->private_data;
398 struct joydev *joydev = client->joydev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 struct input_dev *input = joydev->handle.dev;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400400 struct js_event event;
401 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400403 if (!joydev->exist)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return -ENODEV;
405
406 if (count < sizeof(struct js_event))
407 return -EINVAL;
408
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400409 if (count == sizeof(struct JS_DATA_TYPE))
410 return joydev_0x_read(client, input, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400412 if (!joydev_data_pending(client) && (file->f_flags & O_NONBLOCK))
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400413 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400415 retval = wait_event_interruptible(joydev->wait,
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400416 !joydev->exist || joydev_data_pending(client));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 if (retval)
418 return retval;
419
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400420 if (!joydev->exist)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return -ENODEV;
422
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400423 while (retval + sizeof(struct js_event) <= count &&
424 joydev_generate_startup_event(client, input, &event)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 if (copy_to_user(buf + retval, &event, sizeof(struct js_event)))
427 return -EFAULT;
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 retval += sizeof(struct js_event);
430 }
431
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400432 while (retval + sizeof(struct js_event) <= count &&
433 joydev_fetch_next_event(client, &event)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400435 if (copy_to_user(buf + retval, &event, sizeof(struct js_event)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return -EFAULT;
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 retval += sizeof(struct js_event);
439 }
440
441 return retval;
442}
443
444/* No kernel lock - fine */
445static unsigned int joydev_poll(struct file *file, poll_table *wait)
446{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400447 struct joydev_client *client = file->private_data;
448 struct joydev *joydev = client->joydev;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400449
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400450 poll_wait(file, &joydev->wait, wait);
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400451 return (joydev_data_pending(client) ? (POLLIN | POLLRDNORM) : 0) |
452 (joydev->exist ? 0 : (POLLHUP | POLLERR));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
454
Stephen Kitt999b8742009-08-25 19:24:22 -0700455static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev,
456 void __user *argp, size_t len)
457{
458 __u8 *abspam;
459 int i;
460 int retval = 0;
461
462 len = min(len, sizeof(joydev->abspam));
463
464 /* Validate the map. */
465 abspam = kmalloc(len, GFP_KERNEL);
466 if (!abspam)
467 return -ENOMEM;
468
469 if (copy_from_user(abspam, argp, len)) {
470 retval = -EFAULT;
471 goto out;
472 }
473
474 for (i = 0; i < joydev->nabs; i++) {
475 if (abspam[i] > ABS_MAX) {
476 retval = -EINVAL;
477 goto out;
478 }
479 }
480
481 memcpy(joydev->abspam, abspam, len);
482
483 out:
484 kfree(abspam);
485 return retval;
486}
487
488static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev,
489 void __user *argp, size_t len)
490{
491 __u16 *keypam;
492 int i;
493 int retval = 0;
494
495 len = min(len, sizeof(joydev->keypam));
496
497 /* Validate the map. */
498 keypam = kmalloc(len, GFP_KERNEL);
499 if (!keypam)
500 return -ENOMEM;
501
502 if (copy_from_user(keypam, argp, len)) {
503 retval = -EFAULT;
504 goto out;
505 }
506
507 for (i = 0; i < joydev->nkey; i++) {
508 if (keypam[i] > KEY_MAX || keypam[i] < BTN_MISC) {
509 retval = -EINVAL;
510 goto out;
511 }
512 }
513
514 memcpy(joydev->keypam, keypam, len);
515
516 for (i = 0; i < joydev->nkey; i++)
517 joydev->keymap[keypam[i] - BTN_MISC] = i;
518
519 out:
520 kfree(keypam);
521 return retval;
522}
523
524
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400525static int joydev_ioctl_common(struct joydev *joydev,
526 unsigned int cmd, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 struct input_dev *dev = joydev->handle.dev;
Stephen Kittec8b4b72009-08-12 01:12:08 -0700529 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 int i, j;
Stephen Kittec8b4b72009-08-12 01:12:08 -0700531 const char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Stephen Kittec8b4b72009-08-12 01:12:08 -0700533 /* Process fixed-sized commands. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 switch (cmd) {
535
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400536 case JS_SET_CAL:
537 return copy_from_user(&joydev->glue.JS_CORR, argp,
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500538 sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400539
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400540 case JS_GET_CAL:
541 return copy_to_user(argp, &joydev->glue.JS_CORR,
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500542 sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400543
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400544 case JS_SET_TIMEOUT:
545 return get_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400546
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400547 case JS_GET_TIMEOUT:
548 return put_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400550 case JSIOCGVERSION:
551 return put_user(JS_VERSION, (__u32 __user *) argp);
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400552
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400553 case JSIOCGAXES:
554 return put_user(joydev->nabs, (__u8 __user *) argp);
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400555
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400556 case JSIOCGBUTTONS:
557 return put_user(joydev->nkey, (__u8 __user *) argp);
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400558
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400559 case JSIOCSCORR:
560 if (copy_from_user(joydev->corr, argp,
561 sizeof(joydev->corr[0]) * joydev->nabs))
562 return -EFAULT;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400563
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400564 for (i = 0; i < joydev->nabs; i++) {
565 j = joydev->abspam[i];
566 joydev->abs[i] = joydev_correct(dev->abs[j],
567 &joydev->corr[i]);
568 }
569 return 0;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400570
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400571 case JSIOCGCORR:
572 return copy_to_user(argp, joydev->corr,
573 sizeof(joydev->corr[0]) * joydev->nabs) ? -EFAULT : 0;
574
Stephen Kittec8b4b72009-08-12 01:12:08 -0700575 }
576
577 /*
578 * Process variable-sized commands (the axis and button map commands
579 * are considered variable-sized to decouple them from the values of
580 * ABS_MAX and KEY_MAX).
581 */
582 switch (cmd & ~IOCSIZE_MASK) {
583
584 case (JSIOCSAXMAP & ~IOCSIZE_MASK):
Stephen Kitt999b8742009-08-25 19:24:22 -0700585 return joydev_handle_JSIOCSAXMAP(joydev, argp, _IOC_SIZE(cmd));
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400586
Stephen Kittec8b4b72009-08-12 01:12:08 -0700587 case (JSIOCGAXMAP & ~IOCSIZE_MASK):
588 len = min_t(size_t, _IOC_SIZE(cmd), sizeof(joydev->abspam));
Stephen Kitt999b8742009-08-25 19:24:22 -0700589 return copy_to_user(argp, joydev->abspam, len) ? -EFAULT : len;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400590
Stephen Kittec8b4b72009-08-12 01:12:08 -0700591 case (JSIOCSBTNMAP & ~IOCSIZE_MASK):
Stephen Kitt999b8742009-08-25 19:24:22 -0700592 return joydev_handle_JSIOCSBTNMAP(joydev, argp, _IOC_SIZE(cmd));
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400593
Stephen Kittec8b4b72009-08-12 01:12:08 -0700594 case (JSIOCGBTNMAP & ~IOCSIZE_MASK):
595 len = min_t(size_t, _IOC_SIZE(cmd), sizeof(joydev->keypam));
Stephen Kitt999b8742009-08-25 19:24:22 -0700596 return copy_to_user(argp, joydev->keypam, len) ? -EFAULT : len;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400597
Stephen Kittec8b4b72009-08-12 01:12:08 -0700598 case JSIOCGNAME(0):
599 name = dev->name;
600 if (!name)
601 return 0;
Thadeu Lima de Souza Cascardo3d5cb602009-05-09 16:08:04 -0700602
Stephen Kittec8b4b72009-08-12 01:12:08 -0700603 len = min_t(size_t, _IOC_SIZE(cmd), strlen(name) + 1);
604 return copy_to_user(argp, name, len) ? -EFAULT : len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
Stephen Kittec8b4b72009-08-12 01:12:08 -0700606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 return -EINVAL;
608}
609
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500610#ifdef CONFIG_COMPAT
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400611static long joydev_compat_ioctl(struct file *file,
612 unsigned int cmd, unsigned long arg)
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500613{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400614 struct joydev_client *client = file->private_data;
615 struct joydev *joydev = client->joydev;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500616 void __user *argp = (void __user *)arg;
617 s32 tmp32;
618 struct JS_DATA_SAVE_TYPE_32 ds32;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400619 int retval;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500620
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400621 retval = mutex_lock_interruptible(&joydev->mutex);
622 if (retval)
623 return retval;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400624
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400625 if (!joydev->exist) {
626 retval = -ENODEV;
627 goto out;
628 }
629
630 switch (cmd) {
631
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500632 case JS_SET_TIMELIMIT:
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400633 retval = get_user(tmp32, (s32 __user *) arg);
634 if (retval == 0)
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500635 joydev->glue.JS_TIMELIMIT = tmp32;
636 break;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400637
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500638 case JS_GET_TIMELIMIT:
639 tmp32 = joydev->glue.JS_TIMELIMIT;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400640 retval = put_user(tmp32, (s32 __user *) arg);
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500641 break;
642
643 case JS_SET_ALL:
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400644 retval = copy_from_user(&ds32, argp,
645 sizeof(ds32)) ? -EFAULT : 0;
646 if (retval == 0) {
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500647 joydev->glue.JS_TIMEOUT = ds32.JS_TIMEOUT;
648 joydev->glue.BUSY = ds32.BUSY;
649 joydev->glue.JS_EXPIRETIME = ds32.JS_EXPIRETIME;
650 joydev->glue.JS_TIMELIMIT = ds32.JS_TIMELIMIT;
651 joydev->glue.JS_SAVE = ds32.JS_SAVE;
652 joydev->glue.JS_CORR = ds32.JS_CORR;
653 }
654 break;
655
656 case JS_GET_ALL:
657 ds32.JS_TIMEOUT = joydev->glue.JS_TIMEOUT;
658 ds32.BUSY = joydev->glue.BUSY;
659 ds32.JS_EXPIRETIME = joydev->glue.JS_EXPIRETIME;
660 ds32.JS_TIMELIMIT = joydev->glue.JS_TIMELIMIT;
661 ds32.JS_SAVE = joydev->glue.JS_SAVE;
662 ds32.JS_CORR = joydev->glue.JS_CORR;
663
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400664 retval = copy_to_user(argp, &ds32, sizeof(ds32)) ? -EFAULT : 0;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500665 break;
666
667 default:
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400668 retval = joydev_ioctl_common(joydev, cmd, argp);
669 break;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500670 }
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400671
672 out:
673 mutex_unlock(&joydev->mutex);
674 return retval;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500675}
676#endif /* CONFIG_COMPAT */
677
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400678static long joydev_ioctl(struct file *file,
679 unsigned int cmd, unsigned long arg)
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500680{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400681 struct joydev_client *client = file->private_data;
682 struct joydev *joydev = client->joydev;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500683 void __user *argp = (void __user *)arg;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400684 int retval;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500685
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400686 retval = mutex_lock_interruptible(&joydev->mutex);
687 if (retval)
688 return retval;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500689
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400690 if (!joydev->exist) {
691 retval = -ENODEV;
692 goto out;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500693 }
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400694
695 switch (cmd) {
696
697 case JS_SET_TIMELIMIT:
698 retval = get_user(joydev->glue.JS_TIMELIMIT,
699 (long __user *) arg);
700 break;
701
702 case JS_GET_TIMELIMIT:
703 retval = put_user(joydev->glue.JS_TIMELIMIT,
704 (long __user *) arg);
705 break;
706
707 case JS_SET_ALL:
708 retval = copy_from_user(&joydev->glue, argp,
709 sizeof(joydev->glue)) ? -EFAULT: 0;
710 break;
711
712 case JS_GET_ALL:
713 retval = copy_to_user(argp, &joydev->glue,
714 sizeof(joydev->glue)) ? -EFAULT : 0;
715 break;
716
717 default:
718 retval = joydev_ioctl_common(joydev, cmd, argp);
719 break;
720 }
721 out:
722 mutex_unlock(&joydev->mutex);
723 return retval;
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500724}
725
Dmitry Torokhov66e66112006-09-14 01:31:59 -0400726static const struct file_operations joydev_fops = {
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400727 .owner = THIS_MODULE,
728 .read = joydev_read,
729 .poll = joydev_poll,
730 .open = joydev_open,
731 .release = joydev_release,
732 .unlocked_ioctl = joydev_ioctl,
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500733#ifdef CONFIG_COMPAT
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400734 .compat_ioctl = joydev_compat_ioctl,
Jeremy Fitzhardinge024ac442005-05-29 02:26:31 -0500735#endif
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400736 .fasync = joydev_fasync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737};
738
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400739static int joydev_install_chrdev(struct joydev *joydev)
740{
741 joydev_table[joydev->minor] = joydev;
742 return 0;
743}
744
745static void joydev_remove_chrdev(struct joydev *joydev)
746{
747 mutex_lock(&joydev_table_mutex);
748 joydev_table[joydev->minor] = NULL;
749 mutex_unlock(&joydev_table_mutex);
750}
751
752/*
753 * Mark device non-existant. This disables writes, ioctls and
754 * prevents new users from opening the device. Already posted
755 * blocking reads will stay, however new ones will fail.
756 */
757static void joydev_mark_dead(struct joydev *joydev)
758{
759 mutex_lock(&joydev->mutex);
760 joydev->exist = 0;
761 mutex_unlock(&joydev->mutex);
762}
763
764static void joydev_cleanup(struct joydev *joydev)
765{
766 struct input_handle *handle = &joydev->handle;
767
768 joydev_mark_dead(joydev);
769 joydev_hangup(joydev);
770 joydev_remove_chrdev(joydev);
771
772 /* joydev is marked dead so noone else accesses joydev->open */
773 if (joydev->open)
774 input_close_device(handle);
775}
776
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400777static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
778 const struct input_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 struct joydev *joydev;
781 int i, j, t, minor;
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400782 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400784 for (minor = 0; minor < JOYDEV_MINORS; minor++)
785 if (!joydev_table[minor])
786 break;
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 if (minor == JOYDEV_MINORS) {
789 printk(KERN_ERR "joydev: no more free joydev devices\n");
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400790 return -ENFILE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
792
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400793 joydev = kzalloc(sizeof(struct joydev), GFP_KERNEL);
794 if (!joydev)
795 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400797 INIT_LIST_HEAD(&joydev->client_list);
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400798 spin_lock_init(&joydev->client_lock);
799 mutex_init(&joydev->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 init_waitqueue_head(&joydev->wait);
801
Thadeu Lima de Souza Cascardo3d5cb602009-05-09 16:08:04 -0700802 dev_set_name(&joydev->dev, "js%d", minor);
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400803 joydev->exist = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 joydev->minor = minor;
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 joydev->exist = 1;
Dmitry Torokhova7097ff2008-04-01 00:22:53 -0400807 joydev->handle.dev = input_get_device(dev);
Thadeu Lima de Souza Cascardo3d5cb602009-05-09 16:08:04 -0700808 joydev->handle.name = dev_name(&joydev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 joydev->handle.handler = handler;
810 joydev->handle.private = joydev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 for (i = 0; i < ABS_MAX + 1; i++)
813 if (test_bit(i, dev->absbit)) {
814 joydev->absmap[i] = joydev->nabs;
815 joydev->abspam[joydev->nabs] = i;
816 joydev->nabs++;
817 }
818
819 for (i = BTN_JOYSTICK - BTN_MISC; i < KEY_MAX - BTN_MISC + 1; i++)
820 if (test_bit(i + BTN_MISC, dev->keybit)) {
821 joydev->keymap[i] = joydev->nkey;
822 joydev->keypam[joydev->nkey] = i + BTN_MISC;
823 joydev->nkey++;
824 }
825
Vojtech Pavlikf24949e2005-05-28 02:11:49 -0500826 for (i = 0; i < BTN_JOYSTICK - BTN_MISC; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 if (test_bit(i + BTN_MISC, dev->keybit)) {
828 joydev->keymap[i] = joydev->nkey;
829 joydev->keypam[joydev->nkey] = i + BTN_MISC;
830 joydev->nkey++;
831 }
832
833 for (i = 0; i < joydev->nabs; i++) {
834 j = joydev->abspam[i];
835 if (dev->absmax[j] == dev->absmin[j]) {
836 joydev->corr[i].type = JS_CORR_NONE;
837 joydev->abs[i] = dev->abs[j];
838 continue;
839 }
840 joydev->corr[i].type = JS_CORR_BROKEN;
841 joydev->corr[i].prec = dev->absfuzz[j];
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400842 joydev->corr[i].coef[0] =
843 (dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j];
844 joydev->corr[i].coef[1] =
845 (dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400847 t = (dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j];
848 if (t) {
849 joydev->corr[i].coef[2] = (1 << 29) / t;
850 joydev->corr[i].coef[3] = (1 << 29) / t;
851
852 joydev->abs[i] = joydev_correct(dev->abs[j],
853 joydev->corr + i);
854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 }
856
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400857 joydev->dev.devt = MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor);
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400858 joydev->dev.class = &input_class;
859 joydev->dev.parent = &dev->dev;
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400860 joydev->dev.release = joydev_free;
861 device_initialize(&joydev->dev);
862
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400863 error = input_register_handle(&joydev->handle);
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400864 if (error)
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400865 goto err_free_joydev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400867 error = joydev_install_chrdev(joydev);
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400868 if (error)
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400869 goto err_unregister_handle;
870
871 error = device_add(&joydev->dev);
872 if (error)
873 goto err_cleanup_joydev;
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400874
875 return 0;
876
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400877 err_cleanup_joydev:
878 joydev_cleanup(joydev);
879 err_unregister_handle:
880 input_unregister_handle(&joydev->handle);
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400881 err_free_joydev:
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400882 put_device(&joydev->dev);
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400883 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
885
886static void joydev_disconnect(struct input_handle *handle)
887{
888 struct joydev *joydev = handle->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400890 device_del(&joydev->dev);
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400891 joydev_cleanup(joydev);
892 input_unregister_handle(handle);
Dmitry Torokhov9657d752007-06-14 23:32:24 -0400893 put_device(&joydev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
Dmitry Torokhov66e66112006-09-14 01:31:59 -0400896static const struct input_device_id joydev_blacklist[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 {
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400898 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
899 INPUT_DEVICE_ID_MATCH_KEYBIT,
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700900 .evbit = { BIT_MASK(EV_KEY) },
901 .keybit = { [BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH) },
Tim Coled07a9cb2009-05-07 17:08:42 -0700902 }, /* Avoid itouchpads and touchscreens */
903 {
904 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
905 INPUT_DEVICE_ID_MATCH_KEYBIT,
906 .evbit = { BIT_MASK(EV_KEY) },
907 .keybit = { [BIT_WORD(BTN_DIGI)] = BIT_MASK(BTN_DIGI) },
908 }, /* Avoid tablets, digitisers and similar devices */
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400909 { } /* Terminating entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910};
911
Dmitry Torokhov66e66112006-09-14 01:31:59 -0400912static const struct input_device_id joydev_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 {
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400914 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
915 INPUT_DEVICE_ID_MATCH_ABSBIT,
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700916 .evbit = { BIT_MASK(EV_ABS) },
917 .absbit = { BIT_MASK(ABS_X) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 },
919 {
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400920 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
921 INPUT_DEVICE_ID_MATCH_ABSBIT,
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700922 .evbit = { BIT_MASK(EV_ABS) },
923 .absbit = { BIT_MASK(ABS_WHEEL) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 },
925 {
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400926 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
927 INPUT_DEVICE_ID_MATCH_ABSBIT,
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700928 .evbit = { BIT_MASK(EV_ABS) },
929 .absbit = { BIT_MASK(ABS_THROTTLE) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 },
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400931 { } /* Terminating entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932};
933
934MODULE_DEVICE_TABLE(input, joydev_ids);
935
936static struct input_handler joydev_handler = {
Dmitry Torokhovb1262072007-08-30 00:22:32 -0400937 .event = joydev_event,
938 .connect = joydev_connect,
939 .disconnect = joydev_disconnect,
940 .fops = &joydev_fops,
941 .minor = JOYDEV_MINOR_BASE,
942 .name = "joydev",
943 .id_table = joydev_ids,
944 .blacklist = joydev_blacklist,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945};
946
947static int __init joydev_init(void)
948{
Dmitry Torokhov4263cf02006-09-14 01:32:39 -0400949 return input_register_handler(&joydev_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952static void __exit joydev_exit(void)
953{
954 input_unregister_handler(&joydev_handler);
955}
956
957module_init(joydev_init);
958module_exit(joydev_exit);