0,0 → 1,126 |
/* |
* Input driver event debug module - dumps all events into syslog |
*/ |
|
/* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
*/ |
|
#include <linuxcomp.h> |
|
#include <linux/slab.h> |
#include <linux/module.h> |
#include <linux/input.h> |
#include <linux/init.h> |
#include <linux/device.h> |
|
//#define DEBUG_JOY |
|
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
MODULE_DESCRIPTION("Input driver joystick module"); |
MODULE_LICENSE("GPL"); |
|
static char joystick_name[] = "joystick"; |
static struct input_handler joystick_handler; |
|
static void joystick_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) |
{ |
#ifdef DEBUG_JOY |
printk(KERN_DEBUG "joystick.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", handle->dev->phys, type, code, value); |
#endif |
} |
|
static struct input_handle *joystick_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) |
{ |
struct input_handle *handle; |
|
/* Avoid tablets */ |
if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_TOUCH, dev->keybit)) |
return NULL; |
|
if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL))) |
return NULL; |
memset(handle, 0, sizeof(struct input_handle)); |
|
handle->dev = dev; |
handle->handler = handler; |
handle->name = joystick_name; |
|
input_open_device(handle); |
|
#ifdef DEBUG_JOY |
printk(KERN_DEBUG "joystick.c: Connected device: \"%s\", %s\n", dev->name, dev->phys); |
#endif |
|
return handle; |
} |
|
static void joystick_disconnect(struct input_handle *handle) |
{ |
#ifdef DEBUG_JOY |
printk(KERN_DEBUG "joystick.c: Disconnected device: %s\n", handle->dev->phys); |
#endif |
input_close_device(handle); |
|
kfree(handle); |
} |
|
/*static struct input_device_id joystick_ids[] = { |
{ .driver_info = 1 }, // Matches all devices |
{ }, // Terminating zero entry |
};*/ |
|
static struct input_device_id joystick_ids[] = { |
{ |
.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, |
.evbit = { BIT(EV_ABS) }, |
.absbit = { BIT(ABS_X) }, |
}, |
{ |
.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, |
.evbit = { BIT(EV_ABS) }, |
.absbit = { BIT(ABS_WHEEL) }, |
}, |
{ |
.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, |
.evbit = { BIT(EV_ABS) }, |
.absbit = { BIT(ABS_THROTTLE) }, |
}, |
{ }, /* Terminating entry */ |
}; |
|
MODULE_DEVICE_TABLE(input, joystick_ids); |
|
static struct input_handler joystick_handler = { |
.event = joystick_event, |
.connect = joystick_connect, |
.disconnect = joystick_disconnect, |
.name = "joystick", |
.id_table = joystick_ids, |
}; |
|
int __init joystick_init(void) |
{ |
input_register_handler(&joystick_handler); |
return 0; |
} |
|
void __exit joystick_exit(void) |
{ |
input_unregister_handler(&joystick_handler); |
} |
|
module_init(joystick_init); |
module_exit(joystick_exit); |