Subversion Repositories shark

Rev

Rev 547 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 mauro 1
/*
2
 *  Input driver event debug module - dumps all events into syslog
3
 */
4
 
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
 
21
#include <linuxcomp.h>
22
 
23
#include <linux/slab.h>
24
#include <linux/module.h>
25
#include <linux/input.h>
26
#include <linux/init.h>
27
#include <linux/device.h>
28
 
29
//#define DEBUG_JOY
30
 
31
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
32
MODULE_DESCRIPTION("Input driver joystick module");
33
MODULE_LICENSE("GPL");
34
 
35
static char joystick_name[] = "joystick";
36
static struct input_handler joystick_handler;
37
 
38
static void joystick_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
39
{
40
#ifdef DEBUG_JOY
41
        printk(KERN_DEBUG "joystick.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", handle->dev->phys, type, code, value);
42
#endif
43
}
44
 
45
static struct input_handle *joystick_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
46
{
47
        struct input_handle *handle;
48
 
49
        /* Avoid tablets */
50
        if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_TOUCH, dev->keybit))
51
                return NULL;
52
 
53
        if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))
54
                return NULL;
55
        memset(handle, 0, sizeof(struct input_handle));
56
 
57
        handle->dev = dev;
58
        handle->handler = handler;
59
        handle->name = joystick_name;
60
 
61
        input_open_device(handle);
62
 
63
#ifdef DEBUG_JOY
64
        printk(KERN_DEBUG "joystick.c: Connected device: \"%s\", %s\n", dev->name, dev->phys);
65
#endif
66
 
67
        return handle;
68
}
69
 
70
static void joystick_disconnect(struct input_handle *handle)
71
{
72
#ifdef DEBUG_JOY
73
        printk(KERN_DEBUG "joystick.c: Disconnected device: %s\n", handle->dev->phys);
74
#endif  
75
        input_close_device(handle);
76
 
77
        kfree(handle);
78
}
79
 
80
/*static struct input_device_id joystick_ids[] = {
81
        { .driver_info = 1 },   // Matches all devices
82
        { },                    // Terminating zero entry
83
};*/
84
 
85
static struct input_device_id joystick_ids[] = {
86
        {
87
                .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
88
                .evbit = { BIT(EV_ABS) },
89
                .absbit = { BIT(ABS_X) },
90
        },
91
        {
92
                .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
93
                .evbit = { BIT(EV_ABS) },
94
                .absbit = { BIT(ABS_WHEEL) },
95
        },
96
        {
97
                .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
98
                .evbit = { BIT(EV_ABS) },
99
                .absbit = { BIT(ABS_THROTTLE) },
100
        },
101
        { },    /* Terminating entry */
102
};
103
 
104
MODULE_DEVICE_TABLE(input, joystick_ids);
105
 
106
static struct input_handler joystick_handler = {
107
        .event =        joystick_event,
108
        .connect =      joystick_connect,
109
        .disconnect =   joystick_disconnect,
110
        .name =         "joystick",
111
        .id_table =     joystick_ids,
112
};
113
 
114
int __init joystick_init(void)
115
{
116
        input_register_handler(&joystick_handler);
117
        return 0;
118
}
119
 
120
void __exit joystick_exit(void)
121
{
122
        input_unregister_handler(&joystick_handler);
123
}
124
 
125
module_init(joystick_init);
126
module_exit(joystick_exit);