2 * Bluetooth Wacom Tablet support
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 <jirislaby@gmail.com>
10 * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru>
11 * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net>
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the Free
17 * Software Foundation; either version 2 of the License, or (at your option)
21 #include <linux/device.h>
22 #include <linux/hid.h>
23 #include <linux/module.h>
29 unsigned char butstate
;
32 static int wacom_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
33 u8
*raw_data
, int size
)
35 struct wacom_data
*wdata
= hid_get_drvdata(hdev
);
36 struct hid_input
*hidinput
;
37 struct input_dev
*input
;
38 unsigned char *data
= (unsigned char *) raw_data
;
41 if (!(hdev
->claimed
& HID_CLAIMED_INPUT
))
45 hidinput
= list_entry(hdev
->inputs
.next
, struct hid_input
, list
);
46 input
= hidinput
->input
;
48 /* Check if this is a tablet report */
52 /* Get X & Y positions */
53 x
= le16_to_cpu(*(__le16
*) &data
[2]);
54 y
= le16_to_cpu(*(__le16
*) &data
[4]);
56 /* Get current tool identifier */
57 if (data
[1] & 0x90) { /* If pen is in the in/active area */
58 switch ((data
[1] >> 5) & 3) {
64 tool
= BTN_TOOL_RUBBER
;
67 case 2: /* Mouse with wheel */
68 case 3: /* Mouse without wheel */
69 tool
= BTN_TOOL_MOUSE
;
73 /* Reset tool if out of active tablet area */
74 if (!(data
[1] & 0x10))
78 /* If tool changed, notify input subsystem */
79 if (wdata
->tool
!= tool
) {
81 /* Completely reset old tool state */
82 if (wdata
->tool
== BTN_TOOL_MOUSE
) {
83 input_report_key(input
, BTN_LEFT
, 0);
84 input_report_key(input
, BTN_RIGHT
, 0);
85 input_report_key(input
, BTN_MIDDLE
, 0);
86 input_report_abs(input
, ABS_DISTANCE
,
87 input
->absmax
[ABS_DISTANCE
]);
89 input_report_key(input
, BTN_TOUCH
, 0);
90 input_report_key(input
, BTN_STYLUS
, 0);
91 input_report_key(input
, BTN_STYLUS2
, 0);
92 input_report_abs(input
, ABS_PRESSURE
, 0);
94 input_report_key(input
, wdata
->tool
, 0);
99 input_report_key(input
, tool
, 1);
103 input_report_abs(input
, ABS_X
, x
);
104 input_report_abs(input
, ABS_Y
, y
);
106 switch ((data
[1] >> 5) & 3) {
107 case 2: /* Mouse with wheel */
108 input_report_key(input
, BTN_MIDDLE
, data
[1] & 0x04);
109 rw
= (data
[6] & 0x01) ? -1 :
110 (data
[6] & 0x02) ? 1 : 0;
111 input_report_rel(input
, REL_WHEEL
, rw
);
114 case 3: /* Mouse without wheel */
115 input_report_key(input
, BTN_LEFT
, data
[1] & 0x01);
116 input_report_key(input
, BTN_RIGHT
, data
[1] & 0x02);
117 /* Compute distance between mouse and tablet */
118 rw
= 44 - (data
[6] >> 2);
123 input_report_abs(input
, ABS_DISTANCE
, rw
);
127 input_report_abs(input
, ABS_PRESSURE
,
128 data
[6] | (((__u16
) (data
[1] & 0x08)) << 5));
129 input_report_key(input
, BTN_TOUCH
, data
[1] & 0x01);
130 input_report_key(input
, BTN_STYLUS
, data
[1] & 0x02);
131 input_report_key(input
, BTN_STYLUS2
, (tool
== BTN_TOOL_PEN
) && data
[1] & 0x04);
138 /* Report the state of the two buttons at the top of the tablet
139 * as two extra fingerpad keys (buttons 4 & 5). */
141 if (rw
!= wdata
->butstate
) {
142 wdata
->butstate
= rw
;
143 input_report_key(input
, BTN_0
, rw
& 0x02);
144 input_report_key(input
, BTN_1
, rw
& 0x01);
145 input_event(input
, EV_MSC
, MSC_SERIAL
, 0xf0);
152 static int wacom_probe(struct hid_device
*hdev
,
153 const struct hid_device_id
*id
)
155 struct hid_input
*hidinput
;
156 struct input_dev
*input
;
157 struct wacom_data
*wdata
;
160 wdata
= kzalloc(sizeof(*wdata
), GFP_KERNEL
);
162 dev_err(&hdev
->dev
, "can't alloc wacom descriptor\n");
166 hid_set_drvdata(hdev
, wdata
);
168 ret
= hid_parse(hdev
);
170 dev_err(&hdev
->dev
, "parse failed\n");
174 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
176 dev_err(&hdev
->dev
, "hw start failed\n");
180 hidinput
= list_entry(hdev
->inputs
.next
, struct hid_input
, list
);
181 input
= hidinput
->input
;
184 input
->evbit
[0] |= BIT(EV_KEY
) | BIT(EV_ABS
) | BIT(EV_REL
);
185 input
->absbit
[0] |= BIT(ABS_X
) | BIT(ABS_Y
) |
186 BIT(ABS_PRESSURE
) | BIT(ABS_DISTANCE
);
187 input
->relbit
[0] |= BIT(REL_WHEEL
);
188 set_bit(BTN_TOOL_PEN
, input
->keybit
);
189 set_bit(BTN_TOUCH
, input
->keybit
);
190 set_bit(BTN_STYLUS
, input
->keybit
);
191 set_bit(BTN_STYLUS2
, input
->keybit
);
192 set_bit(BTN_LEFT
, input
->keybit
);
193 set_bit(BTN_RIGHT
, input
->keybit
);
194 set_bit(BTN_MIDDLE
, input
->keybit
);
197 input
->evbit
[0] |= BIT(EV_MSC
);
198 input
->mscbit
[0] |= BIT(MSC_SERIAL
);
200 /* Distance, rubber and mouse */
201 input
->absbit
[0] |= BIT(ABS_DISTANCE
);
202 set_bit(BTN_TOOL_RUBBER
, input
->keybit
);
203 set_bit(BTN_TOOL_MOUSE
, input
->keybit
);
205 input
->absmax
[ABS_PRESSURE
] = 511;
206 input
->absmax
[ABS_DISTANCE
] = 32;
208 input
->absmax
[ABS_X
] = 16704;
209 input
->absmax
[ABS_Y
] = 12064;
210 input
->absfuzz
[ABS_X
] = 4;
211 input
->absfuzz
[ABS_Y
] = 4;
219 static void wacom_remove(struct hid_device
*hdev
)
222 kfree(hid_get_drvdata(hdev
));
225 static const struct hid_device_id wacom_devices
[] = {
226 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM
, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH
) },
230 MODULE_DEVICE_TABLE(hid
, wacom_devices
);
232 static struct hid_driver wacom_driver
= {
234 .id_table
= wacom_devices
,
235 .probe
= wacom_probe
,
236 .remove
= wacom_remove
,
237 .raw_event
= wacom_raw_event
,
240 static int __init
wacom_init(void)
244 ret
= hid_register_driver(&wacom_driver
);
246 printk(KERN_ERR
"can't register wacom driver\n");
247 printk(KERN_ERR
"wacom driver registered\n");
251 static void __exit
wacom_exit(void)
253 hid_unregister_driver(&wacom_driver
);
256 module_init(wacom_init
);
257 module_exit(wacom_exit
);
258 MODULE_LICENSE("GPL");