2 * HID driver for some a4tech "special" devices
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
19 #include <linux/device.h>
20 #include <linux/input.h>
21 #include <linux/hid.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
27 #define A4_2WHEEL_MOUSE_HACK_7 0x01
28 #define A4_2WHEEL_MOUSE_HACK_B8 0x02
32 unsigned int hw_wheel
;
36 static int a4_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
37 struct hid_field
*field
, struct hid_usage
*usage
,
38 unsigned long **bit
, int *max
)
40 struct a4tech_sc
*a4
= hid_get_drvdata(hdev
);
42 if (usage
->type
== EV_REL
&& usage
->code
== REL_WHEEL
)
43 set_bit(REL_HWHEEL
, *bit
);
45 if ((a4
->quirks
& A4_2WHEEL_MOUSE_HACK_7
) && usage
->hid
== 0x00090007)
51 static int a4_event(struct hid_device
*hdev
, struct hid_field
*field
,
52 struct hid_usage
*usage
, __s32 value
)
54 struct a4tech_sc
*a4
= hid_get_drvdata(hdev
);
55 struct input_dev
*input
;
57 if (!(hdev
->claimed
& HID_CLAIMED_INPUT
) || !field
->hidinput
||
61 input
= field
->hidinput
->input
;
63 if (a4
->quirks
& A4_2WHEEL_MOUSE_HACK_B8
) {
64 if (usage
->type
== EV_REL
&& usage
->code
== REL_WHEEL
) {
65 a4
->delayed_value
= value
;
69 if (usage
->hid
== 0x000100b8) {
70 input_event(input
, EV_REL
, value
? REL_HWHEEL
:
71 REL_WHEEL
, a4
->delayed_value
);
76 if ((a4
->quirks
& A4_2WHEEL_MOUSE_HACK_7
) && usage
->hid
== 0x00090007) {
77 a4
->hw_wheel
= !!value
;
81 if (usage
->code
== REL_WHEEL
&& a4
->hw_wheel
) {
82 input_event(input
, usage
->type
, REL_HWHEEL
, value
);
89 static int a4_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
94 a4
= kzalloc(sizeof(*a4
), GFP_KERNEL
);
96 dev_err(&hdev
->dev
, "can't alloc device descriptor\n");
101 a4
->quirks
= id
->driver_data
;
103 hid_set_drvdata(hdev
, a4
);
105 ret
= hid_parse(hdev
);
107 dev_err(&hdev
->dev
, "parse failed\n");
111 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
113 dev_err(&hdev
->dev
, "hw start failed\n");
123 static void a4_remove(struct hid_device
*hdev
)
125 struct a4tech_sc
*a4
= hid_get_drvdata(hdev
);
131 static const struct hid_device_id a4_devices
[] = {
132 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH
, USB_DEVICE_ID_A4TECH_WCP32PU
),
133 .driver_data
= A4_2WHEEL_MOUSE_HACK_7
},
134 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH
, USB_DEVICE_ID_A4TECH_X5_005D
),
135 .driver_data
= A4_2WHEEL_MOUSE_HACK_B8
},
138 MODULE_DEVICE_TABLE(hid
, a4_devices
);
140 static struct hid_driver a4_driver
= {
142 .id_table
= a4_devices
,
143 .input_mapped
= a4_input_mapped
,
149 static int __init
a4_init(void)
151 return hid_register_driver(&a4_driver
);
154 static void __exit
a4_exit(void)
156 hid_unregister_driver(&a4_driver
);
159 module_init(a4_init
);
160 module_exit(a4_exit
);
161 MODULE_LICENSE("GPL");