2 * Joystick device driver for the input driver suite.
4 * Copyright (c) 1999-2002 Vojtech Pavlik
5 * Copyright (c) 1999 Colin Van Dyke
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.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <asm/system.h>
17 #include <linux/delay.h>
18 #include <linux/errno.h>
19 #include <linux/joystick.h>
20 #include <linux/input.h>
21 #include <linux/kernel.h>
22 #include <linux/major.h>
23 #include <linux/sched.h>
24 #include <linux/slab.h>
26 #include <linux/miscdevice.h>
27 #include <linux/module.h>
28 #include <linux/poll.h>
29 #include <linux/init.h>
30 #include <linux/device.h>
31 #include <linux/module.h>
32 #include <linux/moduleparam.h>
34 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
35 MODULE_DESCRIPTION("Joystick device interfaces");
36 MODULE_SUPPORTED_DEVICE("input/js");
37 MODULE_LICENSE("GPL");
38 #define JOYDEV_MINOR_BASE 0
39 #define JOYDEV_MINORS 16
40 #define JOYDEV_BUFFER_SIZE 64
41 #define MAX_REMAP_SIZE 10
43 static int remap_array
[MAX_REMAP_SIZE
];
44 static int remap_count
= 0;
45 static int free_buttons
[MAX_REMAP_SIZE
];
50 struct input_handle handle
;
51 wait_queue_head_t wait
;
52 struct list_head client_list
;
53 spinlock_t client_lock
; /* protects client_list */
58 struct js_corr corr
[ABS_CNT
];
59 struct JS_DATA_SAVE_TYPE glue
;
62 __u16 keymap
[KEY_MAX
- BTN_MISC
+ 1];
63 __u16 keypam
[KEY_MAX
- BTN_MISC
+ 1];
69 struct joydev_client
{
70 struct js_event buffer
[JOYDEV_BUFFER_SIZE
];
74 spinlock_t buffer_lock
; /* protects access to buffer, head and tail */
75 struct fasync_struct
*fasync
;
76 struct joydev
*joydev
;
77 struct list_head node
;
80 static struct joydev
*joydev_table
[JOYDEV_MINORS
];
81 static DEFINE_MUTEX(joydev_table_mutex
);
83 module_param_array(remap_array
, int, &remap_count
, 0 );
84 MODULE_PARM_DESC( remap_array
, "remap axis to buttons\n" );
86 static int joydev_correct(int value
, struct js_corr
*corr
)
94 value
= value
> corr
->coef
[0] ? (value
< corr
->coef
[1] ? 0 :
95 ((corr
->coef
[3] * (value
- corr
->coef
[1])) >> 14)) :
96 ((corr
->coef
[2] * (value
- corr
->coef
[0])) >> 14);
103 return value
< -32767 ? -32767 : (value
> 32767 ? 32767 : value
);
106 static void joydev_pass_event(struct joydev_client
*client
,
107 struct js_event
*event
)
109 struct joydev
*joydev
= client
->joydev
;
112 * IRQs already disabled, just acquire the lock
114 spin_lock(&client
->buffer_lock
);
116 client
->buffer
[client
->head
] = *event
;
118 if (client
->startup
== joydev
->nabs
+ joydev
->nkey
) {
120 client
->head
&= JOYDEV_BUFFER_SIZE
- 1;
121 if (client
->tail
== client
->head
)
125 spin_unlock(&client
->buffer_lock
);
127 kill_fasync(&client
->fasync
, SIGIO
, POLL_IN
);
130 static void joydev_event(struct input_handle
*handle
,
131 unsigned int type
, unsigned int code
, int value
)
133 struct joydev
*joydev
= handle
->private;
134 struct joydev_client
*client
;
135 struct js_event event
;
138 if( remap_count
> 0 && remap_count
< MAX_REMAP_SIZE
){
139 for( i
= 0; i
< remap_count
; i
++ )
140 if( code
== remap_array
[i
] ){
142 code
= free_buttons
[i
];
151 if (code
< BTN_MISC
|| value
== 2)
153 event
.type
= JS_EVENT_BUTTON
;
154 event
.number
= joydev
->keymap
[code
- BTN_MISC
];
159 event
.type
= JS_EVENT_AXIS
;
160 event
.number
= joydev
->absmap
[code
];
161 event
.value
= joydev_correct(value
,
162 &joydev
->corr
[event
.number
]);
163 if (event
.value
== joydev
->abs
[event
.number
])
165 joydev
->abs
[event
.number
] = event
.value
;
172 event
.time
= jiffies_to_msecs(jiffies
);
175 list_for_each_entry_rcu(client
, &joydev
->client_list
, node
)
176 joydev_pass_event(client
, &event
);
179 wake_up_interruptible(&joydev
->wait
);
182 static int joydev_fasync(int fd
, struct file
*file
, int on
)
184 struct joydev_client
*client
= file
->private_data
;
186 return fasync_helper(fd
, file
, on
, &client
->fasync
);
189 static void joydev_free(struct device
*dev
)
191 struct joydev
*joydev
= container_of(dev
, struct joydev
, dev
);
193 input_put_device(joydev
->handle
.dev
);
197 static void joydev_attach_client(struct joydev
*joydev
,
198 struct joydev_client
*client
)
200 spin_lock(&joydev
->client_lock
);
201 list_add_tail_rcu(&client
->node
, &joydev
->client_list
);
202 spin_unlock(&joydev
->client_lock
);
205 static void joydev_detach_client(struct joydev
*joydev
,
206 struct joydev_client
*client
)
208 spin_lock(&joydev
->client_lock
);
209 list_del_rcu(&client
->node
);
210 spin_unlock(&joydev
->client_lock
);
214 static int joydev_open_device(struct joydev
*joydev
)
218 retval
= mutex_lock_interruptible(&joydev
->mutex
);
224 else if (!joydev
->open
++) {
225 retval
= input_open_device(&joydev
->handle
);
230 mutex_unlock(&joydev
->mutex
);
234 static void joydev_close_device(struct joydev
*joydev
)
236 mutex_lock(&joydev
->mutex
);
238 if (joydev
->exist
&& !--joydev
->open
)
239 input_close_device(&joydev
->handle
);
241 mutex_unlock(&joydev
->mutex
);
245 * Wake up users waiting for IO so they can disconnect from
248 static void joydev_hangup(struct joydev
*joydev
)
250 struct joydev_client
*client
;
252 spin_lock(&joydev
->client_lock
);
253 list_for_each_entry(client
, &joydev
->client_list
, node
)
254 kill_fasync(&client
->fasync
, SIGIO
, POLL_HUP
);
255 spin_unlock(&joydev
->client_lock
);
257 wake_up_interruptible(&joydev
->wait
);
260 static int joydev_release(struct inode
*inode
, struct file
*file
)
262 struct joydev_client
*client
= file
->private_data
;
263 struct joydev
*joydev
= client
->joydev
;
265 joydev_detach_client(joydev
, client
);
268 joydev_close_device(joydev
);
269 put_device(&joydev
->dev
);
274 static int joydev_open(struct inode
*inode
, struct file
*file
)
276 struct joydev_client
*client
;
277 struct joydev
*joydev
;
278 int i
= iminor(inode
) - JOYDEV_MINOR_BASE
;
281 if (i
>= JOYDEV_MINORS
)
284 error
= mutex_lock_interruptible(&joydev_table_mutex
);
287 joydev
= joydev_table
[i
];
289 get_device(&joydev
->dev
);
290 mutex_unlock(&joydev_table_mutex
);
295 client
= kzalloc(sizeof(struct joydev_client
), GFP_KERNEL
);
301 spin_lock_init(&client
->buffer_lock
);
302 client
->joydev
= joydev
;
303 joydev_attach_client(joydev
, client
);
305 error
= joydev_open_device(joydev
);
307 goto err_free_client
;
309 file
->private_data
= client
;
310 nonseekable_open(inode
, file
);
315 joydev_detach_client(joydev
, client
);
318 put_device(&joydev
->dev
);
322 static int joydev_generate_startup_event(struct joydev_client
*client
,
323 struct input_dev
*input
,
324 struct js_event
*event
)
326 struct joydev
*joydev
= client
->joydev
;
329 spin_lock_irq(&client
->buffer_lock
);
331 have_event
= client
->startup
< joydev
->nabs
+ joydev
->nkey
;
335 event
->time
= jiffies_to_msecs(jiffies
);
336 if (client
->startup
< joydev
->nkey
) {
337 event
->type
= JS_EVENT_BUTTON
| JS_EVENT_INIT
;
338 event
->number
= client
->startup
;
339 event
->value
= !!test_bit(joydev
->keypam
[event
->number
],
342 event
->type
= JS_EVENT_AXIS
| JS_EVENT_INIT
;
343 event
->number
= client
->startup
- joydev
->nkey
;
344 event
->value
= joydev
->abs
[event
->number
];
349 spin_unlock_irq(&client
->buffer_lock
);
354 static int joydev_fetch_next_event(struct joydev_client
*client
,
355 struct js_event
*event
)
359 spin_lock_irq(&client
->buffer_lock
);
361 have_event
= client
->head
!= client
->tail
;
363 *event
= client
->buffer
[client
->tail
++];
364 client
->tail
&= JOYDEV_BUFFER_SIZE
- 1;
367 spin_unlock_irq(&client
->buffer_lock
);
373 * Old joystick interface
375 static ssize_t
joydev_0x_read(struct joydev_client
*client
,
376 struct input_dev
*input
,
379 struct joydev
*joydev
= client
->joydev
;
380 struct JS_DATA_TYPE data
;
383 spin_lock_irq(&input
->event_lock
);
388 for (data
.buttons
= i
= 0; i
< 32 && i
< joydev
->nkey
; i
++)
390 test_bit(joydev
->keypam
[i
], input
->key
) ? (1 << i
) : 0;
391 data
.x
= (joydev
->abs
[0] / 256 + 128) >> joydev
->glue
.JS_CORR
.x
;
392 data
.y
= (joydev
->abs
[1] / 256 + 128) >> joydev
->glue
.JS_CORR
.y
;
395 * Reset reader's event queue
397 spin_lock(&client
->buffer_lock
);
399 client
->tail
= client
->head
;
400 spin_unlock(&client
->buffer_lock
);
402 spin_unlock_irq(&input
->event_lock
);
404 if (copy_to_user(buf
, &data
, sizeof(struct JS_DATA_TYPE
)))
407 return sizeof(struct JS_DATA_TYPE
);
410 static inline int joydev_data_pending(struct joydev_client
*client
)
412 struct joydev
*joydev
= client
->joydev
;
414 return client
->startup
< joydev
->nabs
+ joydev
->nkey
||
415 client
->head
!= client
->tail
;
418 static ssize_t
joydev_read(struct file
*file
, char __user
*buf
,
419 size_t count
, loff_t
*ppos
)
421 struct joydev_client
*client
= file
->private_data
;
422 struct joydev
*joydev
= client
->joydev
;
423 struct input_dev
*input
= joydev
->handle
.dev
;
424 struct js_event event
;
430 if (count
< sizeof(struct js_event
))
433 if (count
== sizeof(struct JS_DATA_TYPE
))
434 return joydev_0x_read(client
, input
, buf
);
436 if (!joydev_data_pending(client
) && (file
->f_flags
& O_NONBLOCK
))
439 retval
= wait_event_interruptible(joydev
->wait
,
440 !joydev
->exist
|| joydev_data_pending(client
));
447 while (retval
+ sizeof(struct js_event
) <= count
&&
448 joydev_generate_startup_event(client
, input
, &event
)) {
450 if (copy_to_user(buf
+ retval
, &event
, sizeof(struct js_event
)))
453 retval
+= sizeof(struct js_event
);
456 while (retval
+ sizeof(struct js_event
) <= count
&&
457 joydev_fetch_next_event(client
, &event
)) {
459 if (copy_to_user(buf
+ retval
, &event
, sizeof(struct js_event
)))
462 retval
+= sizeof(struct js_event
);
468 /* No kernel lock - fine */
469 static unsigned int joydev_poll(struct file
*file
, poll_table
*wait
)
471 struct joydev_client
*client
= file
->private_data
;
472 struct joydev
*joydev
= client
->joydev
;
474 poll_wait(file
, &joydev
->wait
, wait
);
475 return (joydev_data_pending(client
) ? (POLLIN
| POLLRDNORM
) : 0) |
476 (joydev
->exist
? 0 : (POLLHUP
| POLLERR
));
479 static int joydev_handle_JSIOCSAXMAP(struct joydev
*joydev
,
480 void __user
*argp
, size_t len
)
486 len
= min(len
, sizeof(joydev
->abspam
));
488 /* Validate the map. */
489 abspam
= kmalloc(len
, GFP_KERNEL
);
493 if (copy_from_user(abspam
, argp
, len
)) {
498 for (i
= 0; i
< joydev
->nabs
; i
++) {
499 if (abspam
[i
] > ABS_MAX
) {
505 memcpy(joydev
->abspam
, abspam
, len
);
507 for (i
= 0; i
< joydev
->nabs
; i
++)
508 joydev
->absmap
[joydev
->abspam
[i
]] = i
;
515 static int joydev_handle_JSIOCSBTNMAP(struct joydev
*joydev
,
516 void __user
*argp
, size_t len
)
522 len
= min(len
, sizeof(joydev
->keypam
));
524 /* Validate the map. */
525 keypam
= kmalloc(len
, GFP_KERNEL
);
529 if (copy_from_user(keypam
, argp
, len
)) {
534 for (i
= 0; i
< joydev
->nkey
; i
++) {
535 if (keypam
[i
] > KEY_MAX
|| keypam
[i
] < BTN_MISC
) {
541 memcpy(joydev
->keypam
, keypam
, len
);
543 for (i
= 0; i
< joydev
->nkey
; i
++)
544 joydev
->keymap
[keypam
[i
] - BTN_MISC
] = i
;
552 static int joydev_ioctl_common(struct joydev
*joydev
,
553 unsigned int cmd
, void __user
*argp
)
555 struct input_dev
*dev
= joydev
->handle
.dev
;
560 /* Process fixed-sized commands. */
564 return copy_from_user(&joydev
->glue
.JS_CORR
, argp
,
565 sizeof(joydev
->glue
.JS_CORR
)) ? -EFAULT
: 0;
568 return copy_to_user(argp
, &joydev
->glue
.JS_CORR
,
569 sizeof(joydev
->glue
.JS_CORR
)) ? -EFAULT
: 0;
572 return get_user(joydev
->glue
.JS_TIMEOUT
, (s32 __user
*) argp
);
575 return put_user(joydev
->glue
.JS_TIMEOUT
, (s32 __user
*) argp
);
578 return put_user(JS_VERSION
, (__u32 __user
*) argp
);
581 return put_user(joydev
->nabs
, (__u8 __user
*) argp
);
584 return put_user(joydev
->nkey
, (__u8 __user
*) argp
);
587 if (copy_from_user(joydev
->corr
, argp
,
588 sizeof(joydev
->corr
[0]) * joydev
->nabs
))
591 for (i
= 0; i
< joydev
->nabs
; i
++) {
592 int val
= input_abs_get_val(dev
, joydev
->abspam
[i
]);
593 joydev
->abs
[i
] = joydev_correct(val
, &joydev
->corr
[i
]);
598 return copy_to_user(argp
, joydev
->corr
,
599 sizeof(joydev
->corr
[0]) * joydev
->nabs
) ? -EFAULT
: 0;
604 * Process variable-sized commands (the axis and button map commands
605 * are considered variable-sized to decouple them from the values of
606 * ABS_MAX and KEY_MAX).
608 switch (cmd
& ~IOCSIZE_MASK
) {
610 case (JSIOCSAXMAP
& ~IOCSIZE_MASK
):
611 return joydev_handle_JSIOCSAXMAP(joydev
, argp
, _IOC_SIZE(cmd
));
613 case (JSIOCGAXMAP
& ~IOCSIZE_MASK
):
614 len
= min_t(size_t, _IOC_SIZE(cmd
), sizeof(joydev
->abspam
));
615 return copy_to_user(argp
, joydev
->abspam
, len
) ? -EFAULT
: len
;
617 case (JSIOCSBTNMAP
& ~IOCSIZE_MASK
):
618 return joydev_handle_JSIOCSBTNMAP(joydev
, argp
, _IOC_SIZE(cmd
));
620 case (JSIOCGBTNMAP
& ~IOCSIZE_MASK
):
621 len
= min_t(size_t, _IOC_SIZE(cmd
), sizeof(joydev
->keypam
));
622 return copy_to_user(argp
, joydev
->keypam
, len
) ? -EFAULT
: len
;
629 len
= min_t(size_t, _IOC_SIZE(cmd
), strlen(name
) + 1);
630 return copy_to_user(argp
, name
, len
) ? -EFAULT
: len
;
637 static long joydev_compat_ioctl(struct file
*file
,
638 unsigned int cmd
, unsigned long arg
)
640 struct joydev_client
*client
= file
->private_data
;
641 struct joydev
*joydev
= client
->joydev
;
642 void __user
*argp
= (void __user
*)arg
;
644 struct JS_DATA_SAVE_TYPE_32 ds32
;
647 retval
= mutex_lock_interruptible(&joydev
->mutex
);
651 if (!joydev
->exist
) {
658 case JS_SET_TIMELIMIT
:
659 retval
= get_user(tmp32
, (s32 __user
*) arg
);
661 joydev
->glue
.JS_TIMELIMIT
= tmp32
;
664 case JS_GET_TIMELIMIT
:
665 tmp32
= joydev
->glue
.JS_TIMELIMIT
;
666 retval
= put_user(tmp32
, (s32 __user
*) arg
);
670 retval
= copy_from_user(&ds32
, argp
,
671 sizeof(ds32
)) ? -EFAULT
: 0;
673 joydev
->glue
.JS_TIMEOUT
= ds32
.JS_TIMEOUT
;
674 joydev
->glue
.BUSY
= ds32
.BUSY
;
675 joydev
->glue
.JS_EXPIRETIME
= ds32
.JS_EXPIRETIME
;
676 joydev
->glue
.JS_TIMELIMIT
= ds32
.JS_TIMELIMIT
;
677 joydev
->glue
.JS_SAVE
= ds32
.JS_SAVE
;
678 joydev
->glue
.JS_CORR
= ds32
.JS_CORR
;
683 ds32
.JS_TIMEOUT
= joydev
->glue
.JS_TIMEOUT
;
684 ds32
.BUSY
= joydev
->glue
.BUSY
;
685 ds32
.JS_EXPIRETIME
= joydev
->glue
.JS_EXPIRETIME
;
686 ds32
.JS_TIMELIMIT
= joydev
->glue
.JS_TIMELIMIT
;
687 ds32
.JS_SAVE
= joydev
->glue
.JS_SAVE
;
688 ds32
.JS_CORR
= joydev
->glue
.JS_CORR
;
690 retval
= copy_to_user(argp
, &ds32
, sizeof(ds32
)) ? -EFAULT
: 0;
694 retval
= joydev_ioctl_common(joydev
, cmd
, argp
);
699 mutex_unlock(&joydev
->mutex
);
702 #endif /* CONFIG_COMPAT */
704 static long joydev_ioctl(struct file
*file
,
705 unsigned int cmd
, unsigned long arg
)
707 struct joydev_client
*client
= file
->private_data
;
708 struct joydev
*joydev
= client
->joydev
;
709 void __user
*argp
= (void __user
*)arg
;
712 retval
= mutex_lock_interruptible(&joydev
->mutex
);
716 if (!joydev
->exist
) {
723 case JS_SET_TIMELIMIT
:
724 retval
= get_user(joydev
->glue
.JS_TIMELIMIT
,
725 (long __user
*) arg
);
728 case JS_GET_TIMELIMIT
:
729 retval
= put_user(joydev
->glue
.JS_TIMELIMIT
,
730 (long __user
*) arg
);
734 retval
= copy_from_user(&joydev
->glue
, argp
,
735 sizeof(joydev
->glue
)) ? -EFAULT
: 0;
739 retval
= copy_to_user(argp
, &joydev
->glue
,
740 sizeof(joydev
->glue
)) ? -EFAULT
: 0;
744 retval
= joydev_ioctl_common(joydev
, cmd
, argp
);
748 mutex_unlock(&joydev
->mutex
);
752 static const struct file_operations joydev_fops
= {
753 .owner
= THIS_MODULE
,
757 .release
= joydev_release
,
758 .unlocked_ioctl
= joydev_ioctl
,
760 .compat_ioctl
= joydev_compat_ioctl
,
762 .fasync
= joydev_fasync
,
766 static int joydev_install_chrdev(struct joydev
*joydev
)
768 joydev_table
[joydev
->minor
] = joydev
;
772 static void joydev_remove_chrdev(struct joydev
*joydev
)
774 mutex_lock(&joydev_table_mutex
);
775 joydev_table
[joydev
->minor
] = NULL
;
776 mutex_unlock(&joydev_table_mutex
);
780 * Mark device non-existent. This disables writes, ioctls and
781 * prevents new users from opening the device. Already posted
782 * blocking reads will stay, however new ones will fail.
784 static void joydev_mark_dead(struct joydev
*joydev
)
786 mutex_lock(&joydev
->mutex
);
787 joydev
->exist
= false;
788 mutex_unlock(&joydev
->mutex
);
791 static void joydev_cleanup(struct joydev
*joydev
)
793 struct input_handle
*handle
= &joydev
->handle
;
795 joydev_mark_dead(joydev
);
796 joydev_hangup(joydev
);
797 joydev_remove_chrdev(joydev
);
799 /* joydev is marked dead so no one else accesses joydev->open */
801 input_close_device(handle
);
805 static bool joydev_match(struct input_handler
*handler
, struct input_dev
*dev
)
807 /* Avoid touchpads and touchscreens */
808 if (test_bit(EV_KEY
, dev
->evbit
) && test_bit(BTN_TOUCH
, dev
->keybit
))
811 /* Avoid tablets, digitisers and similar devices */
812 if (test_bit(EV_KEY
, dev
->evbit
) && test_bit(BTN_DIGI
, dev
->keybit
))
818 static int joydev_connect(struct input_handler
*handler
, struct input_dev
*dev
,
819 const struct input_device_id
*id
)
821 struct joydev
*joydev
;
822 int i
, j
= 0, t
, minor
;
825 for (minor
= 0; minor
< JOYDEV_MINORS
; minor
++)
826 if (!joydev_table
[minor
])
829 if (minor
== JOYDEV_MINORS
) {
830 pr_err("no more free joydev devices\n");
834 joydev
= kzalloc(sizeof(struct joydev
), GFP_KERNEL
);
838 INIT_LIST_HEAD(&joydev
->client_list
);
839 spin_lock_init(&joydev
->client_lock
);
840 mutex_init(&joydev
->mutex
);
841 init_waitqueue_head(&joydev
->wait
);
843 dev_set_name(&joydev
->dev
, "js%d", minor
);
844 joydev
->exist
= true;
845 joydev
->minor
= minor
;
847 joydev
->handle
.dev
= input_get_device(dev
);
848 joydev
->handle
.name
= dev_name(&joydev
->dev
);
849 joydev
->handle
.handler
= handler
;
850 joydev
->handle
.private = joydev
;
852 for (i
= 0; i
< ABS_CNT
; i
++)
853 if (test_bit(i
, dev
->absbit
)) {
854 joydev
->absmap
[i
] = joydev
->nabs
;
855 joydev
->abspam
[joydev
->nabs
] = i
;
859 for (i
= BTN_JOYSTICK
- BTN_MISC
; i
< KEY_MAX
- BTN_MISC
+ 1; i
++)
860 if (test_bit(i
+ BTN_MISC
, dev
->keybit
)) {
861 joydev
->keymap
[i
] = joydev
->nkey
;
862 joydev
->keypam
[joydev
->nkey
] = i
+ BTN_MISC
;
866 if( remap_count
> 0 && remap_count
< MAX_REMAP_SIZE
){
867 printk( "[joydev] axis remapping enabled\n" );
868 for( i
= 0; i
< remap_count
; i
++ ){
869 joydev
->keymap
[j
+ i
+ 1] = joydev
->nkey
;
870 joydev
->keypam
[joydev
->nkey
] = i
+ j
+ 1 + BTN_MISC
;
871 free_buttons
[i
] = j
+ i
+ 1 + BTN_MISC
;
875 for (i
= 0; i
< BTN_JOYSTICK
- BTN_MISC
; i
++)
876 if (test_bit(i
+ BTN_MISC
, dev
->keybit
)) {
877 joydev
->keymap
[i
] = joydev
->nkey
;
878 joydev
->keypam
[joydev
->nkey
] = i
+ BTN_MISC
;
882 for (i
= 0; i
< joydev
->nabs
; i
++) {
883 j
= joydev
->abspam
[i
];
884 if (input_abs_get_max(dev
, j
) == input_abs_get_min(dev
, j
)) {
885 joydev
->corr
[i
].type
= JS_CORR_NONE
;
886 joydev
->abs
[i
] = input_abs_get_val(dev
, j
);
889 joydev
->corr
[i
].type
= JS_CORR_BROKEN
;
890 joydev
->corr
[i
].prec
= input_abs_get_fuzz(dev
, j
);
892 t
= (input_abs_get_max(dev
, j
) + input_abs_get_min(dev
, j
)) / 2;
893 joydev
->corr
[i
].coef
[0] = t
- input_abs_get_flat(dev
, j
);
894 joydev
->corr
[i
].coef
[1] = t
+ input_abs_get_flat(dev
, j
);
896 t
= (input_abs_get_max(dev
, j
) - input_abs_get_min(dev
, j
)) / 2
897 - 2 * input_abs_get_flat(dev
, j
);
899 joydev
->corr
[i
].coef
[2] = (1 << 29) / t
;
900 joydev
->corr
[i
].coef
[3] = (1 << 29) / t
;
903 joydev_correct(input_abs_get_val(dev
, j
),
908 joydev
->dev
.devt
= MKDEV(INPUT_MAJOR
, JOYDEV_MINOR_BASE
+ minor
);
909 joydev
->dev
.class = &input_class
;
910 joydev
->dev
.parent
= &dev
->dev
;
911 joydev
->dev
.release
= joydev_free
;
912 device_initialize(&joydev
->dev
);
914 error
= input_register_handle(&joydev
->handle
);
916 goto err_free_joydev
;
918 error
= joydev_install_chrdev(joydev
);
920 goto err_unregister_handle
;
922 error
= device_add(&joydev
->dev
);
924 goto err_cleanup_joydev
;
929 joydev_cleanup(joydev
);
930 err_unregister_handle
:
931 input_unregister_handle(&joydev
->handle
);
933 put_device(&joydev
->dev
);
937 static void joydev_disconnect(struct input_handle
*handle
)
939 struct joydev
*joydev
= handle
->private;
941 device_del(&joydev
->dev
);
942 joydev_cleanup(joydev
);
943 input_unregister_handle(handle
);
944 put_device(&joydev
->dev
);
947 static const struct input_device_id joydev_ids
[] = {
949 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
|
950 INPUT_DEVICE_ID_MATCH_ABSBIT
,
951 .evbit
= { BIT_MASK(EV_ABS
) },
952 .absbit
= { BIT_MASK(ABS_X
) },
955 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
|
956 INPUT_DEVICE_ID_MATCH_ABSBIT
,
957 .evbit
= { BIT_MASK(EV_ABS
) },
958 .absbit
= { BIT_MASK(ABS_WHEEL
) },
961 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
|
962 INPUT_DEVICE_ID_MATCH_ABSBIT
,
963 .evbit
= { BIT_MASK(EV_ABS
) },
964 .absbit
= { BIT_MASK(ABS_THROTTLE
) },
967 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
|
968 INPUT_DEVICE_ID_MATCH_KEYBIT
,
969 .evbit
= { BIT_MASK(EV_KEY
) },
970 .keybit
= {[BIT_WORD(BTN_JOYSTICK
)] = BIT_MASK(BTN_JOYSTICK
) },
973 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
|
974 INPUT_DEVICE_ID_MATCH_KEYBIT
,
975 .evbit
= { BIT_MASK(EV_KEY
) },
976 .keybit
= { [BIT_WORD(BTN_GAMEPAD
)] = BIT_MASK(BTN_GAMEPAD
) },
979 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
|
980 INPUT_DEVICE_ID_MATCH_KEYBIT
,
981 .evbit
= { BIT_MASK(EV_KEY
) },
982 .keybit
= { [BIT_WORD(BTN_TRIGGER_HAPPY
)] = BIT_MASK(BTN_TRIGGER_HAPPY
) },
984 { } /* Terminating entry */
987 MODULE_DEVICE_TABLE(input
, joydev_ids
);
989 static struct input_handler joydev_handler
= {
990 .event
= joydev_event
,
991 .match
= joydev_match
,
992 .connect
= joydev_connect
,
993 .disconnect
= joydev_disconnect
,
994 .fops
= &joydev_fops
,
995 .minor
= JOYDEV_MINOR_BASE
,
997 .id_table
= joydev_ids
,
1000 static int __init
joydev_init(void)
1002 return input_register_handler(&joydev_handler
);
1005 static void __exit
joydev_exit(void)
1007 input_unregister_handler(&joydev_handler
);
1010 module_init(joydev_init
);
1011 module_exit(joydev_exit
);