Commit | Line | Data |
---|---|---|
ca2dcd40 BN |
1 | /* |
2 | * Bluetooth Wacom Tablet support | |
3 | * | |
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> | |
78761ff9 | 12 | * Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu> |
ca2dcd40 BN |
13 | */ |
14 | ||
15 | /* | |
16 | * This program is free software; you can redistribute it and/or modify it | |
17 | * under the terms of the GNU General Public License as published by the Free | |
18 | * Software Foundation; either version 2 of the License, or (at your option) | |
19 | * any later version. | |
20 | */ | |
21 | ||
4291ee30 JP |
22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
23 | ||
ca2dcd40 BN |
24 | #include <linux/device.h> |
25 | #include <linux/hid.h> | |
26 | #include <linux/module.h> | |
5a0e3ad6 | 27 | #include <linux/slab.h> |
59d2334a PF |
28 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
29 | #include <linux/power_supply.h> | |
30 | #endif | |
ca2dcd40 BN |
31 | |
32 | #include "hid-ids.h" | |
33 | ||
6245bde2 PF |
34 | #define PAD_DEVICE_ID 0x0F |
35 | ||
ca2dcd40 BN |
36 | struct wacom_data { |
37 | __u16 tool; | |
6245bde2 | 38 | __u16 butstate; |
7e503a37 | 39 | __u8 whlstate; |
78761ff9 | 40 | __u8 features; |
2470900b PF |
41 | __u32 id; |
42 | __u32 serial; | |
20a3ce7e | 43 | unsigned char high_speed; |
59d2334a PF |
44 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
45 | int battery_capacity; | |
46 | struct power_supply battery; | |
47 | struct power_supply ac; | |
48 | #endif | |
ca2dcd40 BN |
49 | }; |
50 | ||
59d2334a PF |
51 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
52 | /*percent of battery capacity, 0 means AC online*/ | |
53 | static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 }; | |
54 | ||
55 | static enum power_supply_property wacom_battery_props[] = { | |
56 | POWER_SUPPLY_PROP_PRESENT, | |
73db8813 JF |
57 | POWER_SUPPLY_PROP_CAPACITY, |
58 | POWER_SUPPLY_PROP_SCOPE, | |
59d2334a PF |
59 | }; |
60 | ||
61 | static enum power_supply_property wacom_ac_props[] = { | |
62 | POWER_SUPPLY_PROP_PRESENT, | |
73db8813 JF |
63 | POWER_SUPPLY_PROP_ONLINE, |
64 | POWER_SUPPLY_PROP_SCOPE, | |
59d2334a PF |
65 | }; |
66 | ||
67 | static int wacom_battery_get_property(struct power_supply *psy, | |
68 | enum power_supply_property psp, | |
69 | union power_supply_propval *val) | |
70 | { | |
71 | struct wacom_data *wdata = container_of(psy, | |
72 | struct wacom_data, battery); | |
73 | int power_state = batcap[wdata->battery_capacity]; | |
74 | int ret = 0; | |
75 | ||
76 | switch (psp) { | |
77 | case POWER_SUPPLY_PROP_PRESENT: | |
78 | val->intval = 1; | |
79 | break; | |
73db8813 JF |
80 | case POWER_SUPPLY_PROP_SCOPE: |
81 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; | |
82 | break; | |
59d2334a PF |
83 | case POWER_SUPPLY_PROP_CAPACITY: |
84 | /* show 100% battery capacity when charging */ | |
85 | if (power_state == 0) | |
86 | val->intval = 100; | |
87 | else | |
88 | val->intval = power_state; | |
89 | break; | |
90 | default: | |
91 | ret = -EINVAL; | |
92 | break; | |
93 | } | |
94 | return ret; | |
95 | } | |
96 | ||
97 | static int wacom_ac_get_property(struct power_supply *psy, | |
98 | enum power_supply_property psp, | |
99 | union power_supply_propval *val) | |
100 | { | |
101 | struct wacom_data *wdata = container_of(psy, struct wacom_data, ac); | |
102 | int power_state = batcap[wdata->battery_capacity]; | |
103 | int ret = 0; | |
104 | ||
105 | switch (psp) { | |
106 | case POWER_SUPPLY_PROP_PRESENT: | |
107 | /* fall through */ | |
108 | case POWER_SUPPLY_PROP_ONLINE: | |
109 | if (power_state == 0) | |
110 | val->intval = 1; | |
111 | else | |
112 | val->intval = 0; | |
113 | break; | |
73db8813 JF |
114 | case POWER_SUPPLY_PROP_SCOPE: |
115 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; | |
116 | break; | |
59d2334a PF |
117 | default: |
118 | ret = -EINVAL; | |
119 | break; | |
120 | } | |
121 | return ret; | |
122 | } | |
123 | #endif | |
124 | ||
78761ff9 PF |
125 | static void wacom_set_features(struct hid_device *hdev) |
126 | { | |
127 | int ret; | |
128 | __u8 rep_data[2]; | |
129 | ||
130 | /*set high speed, tablet mode*/ | |
131 | rep_data[0] = 0x03; | |
132 | rep_data[1] = 0x20; | |
133 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, | |
134 | HID_FEATURE_REPORT); | |
135 | return; | |
136 | } | |
137 | ||
06c7c313 PF |
138 | static void wacom_poke(struct hid_device *hdev, u8 speed) |
139 | { | |
20a3ce7e | 140 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
06c7c313 PF |
141 | int limit, ret; |
142 | char rep_data[2]; | |
143 | ||
144 | rep_data[0] = 0x03 ; rep_data[1] = 0x00; | |
145 | limit = 3; | |
146 | do { | |
147 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, | |
148 | HID_FEATURE_REPORT); | |
149 | } while (ret < 0 && limit-- > 0); | |
150 | ||
151 | if (ret >= 0) { | |
152 | if (speed == 0) | |
153 | rep_data[0] = 0x05; | |
154 | else | |
155 | rep_data[0] = 0x06; | |
156 | ||
157 | rep_data[1] = 0x00; | |
158 | limit = 3; | |
159 | do { | |
160 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, | |
161 | HID_FEATURE_REPORT); | |
162 | } while (ret < 0 && limit-- > 0); | |
163 | ||
20a3ce7e PF |
164 | if (ret >= 0) { |
165 | wdata->high_speed = speed; | |
06c7c313 | 166 | return; |
20a3ce7e | 167 | } |
06c7c313 PF |
168 | } |
169 | ||
170 | /* | |
171 | * Note that if the raw queries fail, it's not a hard failure and it | |
172 | * is safe to continue | |
173 | */ | |
4291ee30 JP |
174 | hid_warn(hdev, "failed to poke device, command %d, err %d\n", |
175 | rep_data[0], ret); | |
06c7c313 PF |
176 | return; |
177 | } | |
178 | ||
20a3ce7e PF |
179 | static ssize_t wacom_show_speed(struct device *dev, |
180 | struct device_attribute | |
181 | *attr, char *buf) | |
182 | { | |
183 | struct wacom_data *wdata = dev_get_drvdata(dev); | |
184 | ||
185 | return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed); | |
186 | } | |
187 | ||
188 | static ssize_t wacom_store_speed(struct device *dev, | |
189 | struct device_attribute *attr, | |
190 | const char *buf, size_t count) | |
191 | { | |
192 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | |
193 | int new_speed; | |
194 | ||
195 | if (sscanf(buf, "%1d", &new_speed ) != 1) | |
196 | return -EINVAL; | |
197 | ||
198 | if (new_speed == 0 || new_speed == 1) { | |
199 | wacom_poke(hdev, new_speed); | |
200 | return strnlen(buf, PAGE_SIZE); | |
201 | } else | |
202 | return -EINVAL; | |
203 | } | |
204 | ||
edd2126a | 205 | static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP, |
20a3ce7e PF |
206 | wacom_show_speed, wacom_store_speed); |
207 | ||
f6b7efc1 PF |
208 | static int wacom_gr_parse_report(struct hid_device *hdev, |
209 | struct wacom_data *wdata, | |
210 | struct input_dev *input, unsigned char *data) | |
ca2dcd40 | 211 | { |
ca2dcd40 BN |
212 | int tool, x, y, rw; |
213 | ||
ca2dcd40 | 214 | tool = 0; |
ca2dcd40 BN |
215 | /* Get X & Y positions */ |
216 | x = le16_to_cpu(*(__le16 *) &data[2]); | |
217 | y = le16_to_cpu(*(__le16 *) &data[4]); | |
218 | ||
219 | /* Get current tool identifier */ | |
220 | if (data[1] & 0x90) { /* If pen is in the in/active area */ | |
221 | switch ((data[1] >> 5) & 3) { | |
222 | case 0: /* Pen */ | |
223 | tool = BTN_TOOL_PEN; | |
224 | break; | |
225 | ||
226 | case 1: /* Rubber */ | |
227 | tool = BTN_TOOL_RUBBER; | |
228 | break; | |
229 | ||
230 | case 2: /* Mouse with wheel */ | |
231 | case 3: /* Mouse without wheel */ | |
232 | tool = BTN_TOOL_MOUSE; | |
233 | break; | |
234 | } | |
235 | ||
236 | /* Reset tool if out of active tablet area */ | |
237 | if (!(data[1] & 0x10)) | |
238 | tool = 0; | |
239 | } | |
240 | ||
241 | /* If tool changed, notify input subsystem */ | |
242 | if (wdata->tool != tool) { | |
243 | if (wdata->tool) { | |
244 | /* Completely reset old tool state */ | |
245 | if (wdata->tool == BTN_TOOL_MOUSE) { | |
246 | input_report_key(input, BTN_LEFT, 0); | |
247 | input_report_key(input, BTN_RIGHT, 0); | |
248 | input_report_key(input, BTN_MIDDLE, 0); | |
249 | input_report_abs(input, ABS_DISTANCE, | |
987a6c02 | 250 | input_abs_get_max(input, ABS_DISTANCE)); |
ca2dcd40 BN |
251 | } else { |
252 | input_report_key(input, BTN_TOUCH, 0); | |
253 | input_report_key(input, BTN_STYLUS, 0); | |
254 | input_report_key(input, BTN_STYLUS2, 0); | |
255 | input_report_abs(input, ABS_PRESSURE, 0); | |
256 | } | |
257 | input_report_key(input, wdata->tool, 0); | |
258 | input_sync(input); | |
259 | } | |
260 | wdata->tool = tool; | |
261 | if (tool) | |
262 | input_report_key(input, tool, 1); | |
263 | } | |
264 | ||
265 | if (tool) { | |
266 | input_report_abs(input, ABS_X, x); | |
267 | input_report_abs(input, ABS_Y, y); | |
268 | ||
269 | switch ((data[1] >> 5) & 3) { | |
270 | case 2: /* Mouse with wheel */ | |
271 | input_report_key(input, BTN_MIDDLE, data[1] & 0x04); | |
272 | rw = (data[6] & 0x01) ? -1 : | |
273 | (data[6] & 0x02) ? 1 : 0; | |
274 | input_report_rel(input, REL_WHEEL, rw); | |
275 | /* fall through */ | |
276 | ||
277 | case 3: /* Mouse without wheel */ | |
278 | input_report_key(input, BTN_LEFT, data[1] & 0x01); | |
279 | input_report_key(input, BTN_RIGHT, data[1] & 0x02); | |
280 | /* Compute distance between mouse and tablet */ | |
281 | rw = 44 - (data[6] >> 2); | |
282 | if (rw < 0) | |
283 | rw = 0; | |
284 | else if (rw > 31) | |
285 | rw = 31; | |
286 | input_report_abs(input, ABS_DISTANCE, rw); | |
287 | break; | |
288 | ||
289 | default: | |
290 | input_report_abs(input, ABS_PRESSURE, | |
291 | data[6] | (((__u16) (data[1] & 0x08)) << 5)); | |
292 | input_report_key(input, BTN_TOUCH, data[1] & 0x01); | |
293 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); | |
294 | input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04); | |
295 | break; | |
296 | } | |
297 | ||
298 | input_sync(input); | |
299 | } | |
300 | ||
301 | /* Report the state of the two buttons at the top of the tablet | |
302 | * as two extra fingerpad keys (buttons 4 & 5). */ | |
303 | rw = data[7] & 0x03; | |
304 | if (rw != wdata->butstate) { | |
305 | wdata->butstate = rw; | |
306 | input_report_key(input, BTN_0, rw & 0x02); | |
307 | input_report_key(input, BTN_1, rw & 0x01); | |
0e253fdb | 308 | input_report_key(input, BTN_TOOL_FINGER, 0xf0); |
ca2dcd40 BN |
309 | input_event(input, EV_MSC, MSC_SERIAL, 0xf0); |
310 | input_sync(input); | |
311 | } | |
312 | ||
59d2334a PF |
313 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
314 | /* Store current battery capacity */ | |
315 | rw = (data[7] >> 2 & 0x07); | |
316 | if (rw != wdata->battery_capacity) | |
317 | wdata->battery_capacity = rw; | |
318 | #endif | |
ca2dcd40 BN |
319 | return 1; |
320 | } | |
78761ff9 | 321 | |
6245bde2 PF |
322 | static void wacom_i4_parse_button_report(struct wacom_data *wdata, |
323 | struct input_dev *input, unsigned char *data) | |
324 | { | |
325 | __u16 new_butstate; | |
7e503a37 PF |
326 | __u8 new_whlstate; |
327 | __u8 sync = 0; | |
328 | ||
329 | new_whlstate = data[1]; | |
330 | if (new_whlstate != wdata->whlstate) { | |
331 | wdata->whlstate = new_whlstate; | |
332 | if (new_whlstate & 0x80) { | |
333 | input_report_key(input, BTN_TOUCH, 1); | |
334 | input_report_abs(input, ABS_WHEEL, (new_whlstate & 0x7f)); | |
335 | input_report_key(input, BTN_TOOL_FINGER, 1); | |
336 | } else { | |
337 | input_report_key(input, BTN_TOUCH, 0); | |
338 | input_report_abs(input, ABS_WHEEL, 0); | |
339 | input_report_key(input, BTN_TOOL_FINGER, 0); | |
340 | } | |
341 | sync = 1; | |
342 | } | |
6245bde2 PF |
343 | |
344 | new_butstate = (data[3] << 1) | (data[2] & 0x01); | |
345 | if (new_butstate != wdata->butstate) { | |
346 | wdata->butstate = new_butstate; | |
347 | input_report_key(input, BTN_0, new_butstate & 0x001); | |
348 | input_report_key(input, BTN_1, new_butstate & 0x002); | |
349 | input_report_key(input, BTN_2, new_butstate & 0x004); | |
350 | input_report_key(input, BTN_3, new_butstate & 0x008); | |
351 | input_report_key(input, BTN_4, new_butstate & 0x010); | |
352 | input_report_key(input, BTN_5, new_butstate & 0x020); | |
353 | input_report_key(input, BTN_6, new_butstate & 0x040); | |
354 | input_report_key(input, BTN_7, new_butstate & 0x080); | |
355 | input_report_key(input, BTN_8, new_butstate & 0x100); | |
356 | input_report_key(input, BTN_TOOL_FINGER, 1); | |
7e503a37 PF |
357 | sync = 1; |
358 | } | |
359 | ||
360 | if (sync) { | |
6245bde2 PF |
361 | input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); |
362 | input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff); | |
363 | input_sync(input); | |
364 | } | |
365 | } | |
366 | ||
78761ff9 PF |
367 | static void wacom_i4_parse_pen_report(struct wacom_data *wdata, |
368 | struct input_dev *input, unsigned char *data) | |
369 | { | |
370 | __u16 x, y, pressure; | |
e0829e9c | 371 | __u8 distance; |
78761ff9 PF |
372 | |
373 | switch (data[1]) { | |
374 | case 0x80: /* Out of proximity report */ | |
78761ff9 PF |
375 | input_report_key(input, BTN_TOUCH, 0); |
376 | input_report_abs(input, ABS_PRESSURE, 0); | |
693f45bb PF |
377 | input_report_key(input, BTN_STYLUS, 0); |
378 | input_report_key(input, BTN_STYLUS2, 0); | |
78761ff9 | 379 | input_report_key(input, wdata->tool, 0); |
2470900b PF |
380 | input_report_abs(input, ABS_MISC, 0); |
381 | input_event(input, EV_MSC, MSC_SERIAL, wdata->serial); | |
32db737f | 382 | wdata->tool = 0; |
78761ff9 PF |
383 | input_sync(input); |
384 | break; | |
385 | case 0xC2: /* Tool report */ | |
2470900b | 386 | wdata->id = ((data[2] << 4) | (data[3] >> 4) | |
78761ff9 | 387 | ((data[7] & 0x0f) << 20) | |
2470900b PF |
388 | ((data[8] & 0xf0) << 12)); |
389 | wdata->serial = ((data[3] & 0x0f) << 28) + | |
390 | (data[4] << 20) + (data[5] << 12) + | |
391 | (data[6] << 4) + (data[7] >> 4); | |
78761ff9 | 392 | |
2470900b PF |
393 | switch (wdata->id) { |
394 | case 0x100802: | |
78761ff9 PF |
395 | wdata->tool = BTN_TOOL_PEN; |
396 | break; | |
2470900b | 397 | case 0x10080A: |
78761ff9 PF |
398 | wdata->tool = BTN_TOOL_RUBBER; |
399 | break; | |
400 | } | |
401 | break; | |
402 | default: /* Position/pressure report */ | |
403 | x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1); | |
404 | y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01); | |
405 | pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | |
406 | | (data[1] & 0x01); | |
e0829e9c | 407 | distance = (data[9] >> 2) & 0x3f; |
78761ff9 PF |
408 | |
409 | input_report_key(input, BTN_TOUCH, pressure > 1); | |
410 | ||
411 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); | |
412 | input_report_key(input, BTN_STYLUS2, data[1] & 0x04); | |
413 | input_report_key(input, wdata->tool, 1); | |
414 | input_report_abs(input, ABS_X, x); | |
415 | input_report_abs(input, ABS_Y, y); | |
416 | input_report_abs(input, ABS_PRESSURE, pressure); | |
e0829e9c | 417 | input_report_abs(input, ABS_DISTANCE, distance); |
2470900b PF |
418 | input_report_abs(input, ABS_MISC, wdata->id); |
419 | input_event(input, EV_MSC, MSC_SERIAL, wdata->serial); | |
420 | input_report_key(input, wdata->tool, 1); | |
78761ff9 PF |
421 | input_sync(input); |
422 | break; | |
423 | } | |
424 | ||
425 | return; | |
426 | } | |
427 | ||
428 | static void wacom_i4_parse_report(struct hid_device *hdev, | |
429 | struct wacom_data *wdata, | |
430 | struct input_dev *input, unsigned char *data) | |
431 | { | |
432 | switch (data[0]) { | |
433 | case 0x00: /* Empty report */ | |
434 | break; | |
435 | case 0x02: /* Pen report */ | |
436 | wacom_i4_parse_pen_report(wdata, input, data); | |
437 | break; | |
438 | case 0x03: /* Features Report */ | |
439 | wdata->features = data[2]; | |
440 | break; | |
441 | case 0x0C: /* Button report */ | |
6245bde2 | 442 | wacom_i4_parse_button_report(wdata, input, data); |
78761ff9 PF |
443 | break; |
444 | default: | |
445 | hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]); | |
446 | break; | |
447 | } | |
448 | } | |
449 | ||
f6b7efc1 PF |
450 | static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, |
451 | u8 *raw_data, int size) | |
452 | { | |
453 | struct wacom_data *wdata = hid_get_drvdata(hdev); | |
454 | struct hid_input *hidinput; | |
455 | struct input_dev *input; | |
456 | unsigned char *data = (unsigned char *) raw_data; | |
78761ff9 | 457 | int i; |
f6b7efc1 PF |
458 | |
459 | if (!(hdev->claimed & HID_CLAIMED_INPUT)) | |
460 | return 0; | |
461 | ||
462 | hidinput = list_entry(hdev->inputs.next, struct hid_input, list); | |
463 | input = hidinput->input; | |
464 | ||
465 | /* Check if this is a tablet report */ | |
466 | if (data[0] != 0x03) | |
467 | return 0; | |
468 | ||
78761ff9 PF |
469 | switch (hdev->product) { |
470 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: | |
471 | return wacom_gr_parse_report(hdev, wdata, input, data); | |
472 | break; | |
473 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: | |
474 | i = 1; | |
475 | ||
476 | switch (data[0]) { | |
477 | case 0x04: | |
478 | wacom_i4_parse_report(hdev, wdata, input, data + i); | |
479 | i += 10; | |
480 | /* fall through */ | |
481 | case 0x03: | |
482 | wacom_i4_parse_report(hdev, wdata, input, data + i); | |
483 | i += 10; | |
484 | wacom_i4_parse_report(hdev, wdata, input, data + i); | |
485 | break; | |
486 | default: | |
487 | hid_err(hdev, "Unknown report: %d,%d size:%d\n", | |
488 | data[0], data[1], size); | |
489 | return 0; | |
490 | } | |
491 | } | |
492 | return 1; | |
f6b7efc1 | 493 | } |
ca2dcd40 | 494 | |
3797ef6b DH |
495 | static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
496 | struct hid_field *field, struct hid_usage *usage, unsigned long **bit, | |
497 | int *max) | |
498 | { | |
499 | struct input_dev *input = hi->input; | |
500 | ||
f6f12427 JK |
501 | __set_bit(INPUT_PROP_POINTER, input->propbit); |
502 | ||
3797ef6b DH |
503 | /* Basics */ |
504 | input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL); | |
505 | ||
506 | __set_bit(REL_WHEEL, input->relbit); | |
507 | ||
508 | __set_bit(BTN_TOOL_PEN, input->keybit); | |
509 | __set_bit(BTN_TOUCH, input->keybit); | |
510 | __set_bit(BTN_STYLUS, input->keybit); | |
511 | __set_bit(BTN_STYLUS2, input->keybit); | |
512 | __set_bit(BTN_LEFT, input->keybit); | |
513 | __set_bit(BTN_RIGHT, input->keybit); | |
514 | __set_bit(BTN_MIDDLE, input->keybit); | |
515 | ||
516 | /* Pad */ | |
9a911da8 | 517 | input_set_capability(input, EV_MSC, MSC_SERIAL); |
3797ef6b DH |
518 | |
519 | __set_bit(BTN_0, input->keybit); | |
520 | __set_bit(BTN_1, input->keybit); | |
521 | __set_bit(BTN_TOOL_FINGER, input->keybit); | |
522 | ||
523 | /* Distance, rubber and mouse */ | |
524 | __set_bit(BTN_TOOL_RUBBER, input->keybit); | |
525 | __set_bit(BTN_TOOL_MOUSE, input->keybit); | |
526 | ||
78761ff9 PF |
527 | switch (hdev->product) { |
528 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: | |
529 | input_set_abs_params(input, ABS_X, 0, 16704, 4, 0); | |
530 | input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0); | |
531 | input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0); | |
532 | input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0); | |
533 | break; | |
534 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: | |
7e503a37 | 535 | __set_bit(ABS_WHEEL, input->absbit); |
2c653e6b | 536 | __set_bit(ABS_MISC, input->absbit); |
6245bde2 PF |
537 | __set_bit(BTN_2, input->keybit); |
538 | __set_bit(BTN_3, input->keybit); | |
539 | __set_bit(BTN_4, input->keybit); | |
540 | __set_bit(BTN_5, input->keybit); | |
541 | __set_bit(BTN_6, input->keybit); | |
542 | __set_bit(BTN_7, input->keybit); | |
543 | __set_bit(BTN_8, input->keybit); | |
7e503a37 | 544 | input_set_abs_params(input, ABS_WHEEL, 0, 71, 0, 0); |
78761ff9 PF |
545 | input_set_abs_params(input, ABS_X, 0, 40640, 4, 0); |
546 | input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0); | |
547 | input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0); | |
e0829e9c | 548 | input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0); |
78761ff9 PF |
549 | break; |
550 | } | |
3797ef6b DH |
551 | |
552 | return 0; | |
553 | } | |
554 | ||
ca2dcd40 BN |
555 | static int wacom_probe(struct hid_device *hdev, |
556 | const struct hid_device_id *id) | |
557 | { | |
ca2dcd40 BN |
558 | struct wacom_data *wdata; |
559 | int ret; | |
560 | ||
561 | wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); | |
562 | if (wdata == NULL) { | |
4291ee30 | 563 | hid_err(hdev, "can't alloc wacom descriptor\n"); |
ca2dcd40 BN |
564 | return -ENOMEM; |
565 | } | |
566 | ||
567 | hid_set_drvdata(hdev, wdata); | |
568 | ||
46a709b9 | 569 | /* Parse the HID report now */ |
ca2dcd40 BN |
570 | ret = hid_parse(hdev); |
571 | if (ret) { | |
4291ee30 | 572 | hid_err(hdev, "parse failed\n"); |
ca2dcd40 BN |
573 | goto err_free; |
574 | } | |
575 | ||
576 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | |
577 | if (ret) { | |
4291ee30 | 578 | hid_err(hdev, "hw start failed\n"); |
ca2dcd40 BN |
579 | goto err_free; |
580 | } | |
581 | ||
20a3ce7e PF |
582 | ret = device_create_file(&hdev->dev, &dev_attr_speed); |
583 | if (ret) | |
4291ee30 JP |
584 | hid_warn(hdev, |
585 | "can't create sysfs speed attribute err: %d\n", ret); | |
342f31e8 | 586 | |
78761ff9 PF |
587 | switch (hdev->product) { |
588 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: | |
589 | /* Set Wacom mode 2 with high reporting speed */ | |
590 | wacom_poke(hdev, 1); | |
591 | break; | |
592 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: | |
a72c5ddb | 593 | sprintf(hdev->name, "%s", "Wacom Intuos4 WL"); |
78761ff9 PF |
594 | wdata->features = 0; |
595 | wacom_set_features(hdev); | |
596 | break; | |
597 | } | |
46a709b9 | 598 | |
59d2334a PF |
599 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
600 | wdata->battery.properties = wacom_battery_props; | |
601 | wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props); | |
602 | wdata->battery.get_property = wacom_battery_get_property; | |
603 | wdata->battery.name = "wacom_battery"; | |
604 | wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY; | |
605 | wdata->battery.use_for_apm = 0; | |
46a709b9 | 606 | |
35b4c01e | 607 | |
59d2334a PF |
608 | ret = power_supply_register(&hdev->dev, &wdata->battery); |
609 | if (ret) { | |
4291ee30 JP |
610 | hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n", |
611 | ret); | |
dde58cfc | 612 | goto err_battery; |
59d2334a PF |
613 | } |
614 | ||
d7cb3dbd PF |
615 | power_supply_powers(&wdata->battery, &hdev->dev); |
616 | ||
59d2334a PF |
617 | wdata->ac.properties = wacom_ac_props; |
618 | wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props); | |
619 | wdata->ac.get_property = wacom_ac_get_property; | |
620 | wdata->ac.name = "wacom_ac"; | |
621 | wdata->ac.type = POWER_SUPPLY_TYPE_MAINS; | |
622 | wdata->ac.use_for_apm = 0; | |
623 | ||
624 | ret = power_supply_register(&hdev->dev, &wdata->ac); | |
625 | if (ret) { | |
4291ee30 JP |
626 | hid_warn(hdev, |
627 | "can't create ac battery attribute, err: %d\n", ret); | |
dde58cfc | 628 | goto err_ac; |
59d2334a | 629 | } |
d7cb3dbd PF |
630 | |
631 | power_supply_powers(&wdata->ac, &hdev->dev); | |
59d2334a | 632 | #endif |
ca2dcd40 | 633 | return 0; |
987a6c02 | 634 | |
dde58cfc DH |
635 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
636 | err_ac: | |
637 | power_supply_unregister(&wdata->battery); | |
638 | err_battery: | |
639 | device_remove_file(&hdev->dev, &dev_attr_speed); | |
640 | hid_hw_stop(hdev); | |
641 | #endif | |
ca2dcd40 BN |
642 | err_free: |
643 | kfree(wdata); | |
644 | return ret; | |
645 | } | |
646 | ||
647 | static void wacom_remove(struct hid_device *hdev) | |
648 | { | |
59d2334a PF |
649 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
650 | struct wacom_data *wdata = hid_get_drvdata(hdev); | |
651 | #endif | |
9086617e | 652 | device_remove_file(&hdev->dev, &dev_attr_speed); |
ca2dcd40 | 653 | hid_hw_stop(hdev); |
59d2334a PF |
654 | |
655 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY | |
656 | power_supply_unregister(&wdata->battery); | |
657 | power_supply_unregister(&wdata->ac); | |
658 | #endif | |
ca2dcd40 BN |
659 | kfree(hid_get_drvdata(hdev)); |
660 | } | |
661 | ||
662 | static const struct hid_device_id wacom_devices[] = { | |
663 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, | |
78761ff9 | 664 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) }, |
d5e0a06f | 665 | |
ca2dcd40 BN |
666 | { } |
667 | }; | |
668 | MODULE_DEVICE_TABLE(hid, wacom_devices); | |
669 | ||
670 | static struct hid_driver wacom_driver = { | |
671 | .name = "wacom", | |
672 | .id_table = wacom_devices, | |
673 | .probe = wacom_probe, | |
674 | .remove = wacom_remove, | |
675 | .raw_event = wacom_raw_event, | |
3797ef6b | 676 | .input_mapped = wacom_input_mapped, |
ca2dcd40 BN |
677 | }; |
678 | ||
a24f423b | 679 | static int __init wacom_init(void) |
ca2dcd40 BN |
680 | { |
681 | int ret; | |
682 | ||
683 | ret = hid_register_driver(&wacom_driver); | |
684 | if (ret) | |
4291ee30 | 685 | pr_err("can't register wacom driver\n"); |
ca2dcd40 BN |
686 | return ret; |
687 | } | |
688 | ||
a24f423b | 689 | static void __exit wacom_exit(void) |
ca2dcd40 BN |
690 | { |
691 | hid_unregister_driver(&wacom_driver); | |
692 | } | |
693 | ||
694 | module_init(wacom_init); | |
695 | module_exit(wacom_exit); | |
696 | MODULE_LICENSE("GPL"); | |
697 |