HID: remove Paul Walmsley's copyright from places where it shouldn't be
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / hid / hid-wacom.c
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) 2008 Jiri Slaby <jirislaby@gmail.com>
9 * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru>
10 * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net>
11 * Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu>
12 */
13
14 /*
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)
18 * any later version.
19 */
20
21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
23 #include <linux/device.h>
24 #include <linux/hid.h>
25 #include <linux/module.h>
26 #include <linux/leds.h>
27 #include <linux/slab.h>
28 #include <linux/power_supply.h>
29
30 #include "hid-ids.h"
31
32 #define PAD_DEVICE_ID 0x0F
33
34 #define WAC_CMD_LED_CONTROL 0x20
35
36 struct wacom_data {
37 __u16 tool;
38 __u16 butstate;
39 __u8 whlstate;
40 __u8 features;
41 __u32 id;
42 __u32 serial;
43 unsigned char high_speed;
44 __u8 battery_capacity;
45 __u8 power_raw;
46 __u8 ps_connected;
47 struct power_supply battery;
48 struct power_supply ac;
49 __u8 led_selector;
50 struct led_classdev *leds[4];
51 };
52
53 /*percent of battery capacity for Graphire
54 8th value means AC online and show 100% capacity */
55 static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
56 /*percent of battery capacity for Intuos4 WL, AC has a separate bit*/
57 static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
58
59 static enum power_supply_property wacom_battery_props[] = {
60 POWER_SUPPLY_PROP_PRESENT,
61 POWER_SUPPLY_PROP_CAPACITY,
62 POWER_SUPPLY_PROP_SCOPE,
63 };
64
65 static enum power_supply_property wacom_ac_props[] = {
66 POWER_SUPPLY_PROP_PRESENT,
67 POWER_SUPPLY_PROP_ONLINE,
68 POWER_SUPPLY_PROP_SCOPE,
69 };
70
71 static void wacom_leds_set_brightness(struct led_classdev *led_dev,
72 enum led_brightness value)
73 {
74 struct device *dev = led_dev->dev->parent;
75 struct hid_device *hdev;
76 struct wacom_data *wdata;
77 unsigned char *buf;
78 __u8 led = 0;
79 int i;
80
81 hdev = container_of(dev, struct hid_device, dev);
82 wdata = hid_get_drvdata(hdev);
83 for (i = 0; i < 4; ++i) {
84 if (wdata->leds[i] == led_dev)
85 wdata->led_selector = i;
86 }
87
88 led = wdata->led_selector | 0x04;
89 buf = kzalloc(9, GFP_KERNEL);
90 if (buf) {
91 buf[0] = WAC_CMD_LED_CONTROL;
92 buf[1] = led;
93 buf[2] = value;
94 hdev->hid_output_raw_report(hdev, buf, 9, HID_FEATURE_REPORT);
95 kfree(buf);
96 }
97
98 return;
99 }
100
101 static enum led_brightness wacom_leds_get_brightness(struct led_classdev *led_dev)
102 {
103 struct wacom_data *wdata;
104 struct device *dev = led_dev->dev->parent;
105 int value = 0;
106 int i;
107
108 wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev));
109
110 for (i = 0; i < 4; ++i) {
111 if (wdata->leds[i] == led_dev) {
112 value = wdata->leds[i]->brightness;
113 break;
114 }
115 }
116
117 return value;
118 }
119
120
121 static int wacom_initialize_leds(struct hid_device *hdev)
122 {
123 struct wacom_data *wdata = hid_get_drvdata(hdev);
124 struct led_classdev *led;
125 struct device *dev = &hdev->dev;
126 size_t namesz = strlen(dev_name(dev)) + 12;
127 char *name;
128 int i, ret;
129
130 wdata->led_selector = 0;
131
132 for (i = 0; i < 4; i++) {
133 led = kzalloc(sizeof(struct led_classdev) + namesz, GFP_KERNEL);
134 if (!led) {
135 hid_warn(hdev,
136 "can't allocate memory for LED selector\n");
137 ret = -ENOMEM;
138 goto err;
139 }
140
141 name = (void *)&led[1];
142 snprintf(name, namesz, "%s:selector:%d", dev_name(dev), i);
143 led->name = name;
144 led->brightness = 0;
145 led->max_brightness = 127;
146 led->brightness_get = wacom_leds_get_brightness;
147 led->brightness_set = wacom_leds_set_brightness;
148
149 wdata->leds[i] = led;
150
151 ret = led_classdev_register(dev, wdata->leds[i]);
152
153 if (ret) {
154 wdata->leds[i] = NULL;
155 kfree(led);
156 hid_warn(hdev, "can't register LED\n");
157 goto err;
158 }
159 }
160
161 err:
162 return ret;
163 }
164
165 static void wacom_destroy_leds(struct hid_device *hdev)
166 {
167 struct wacom_data *wdata = hid_get_drvdata(hdev);
168 struct led_classdev *led;
169 int i;
170
171 for (i = 0; i < 4; ++i) {
172 if (wdata->leds[i]) {
173 led = wdata->leds[i];
174 wdata->leds[i] = NULL;
175 led_classdev_unregister(led);
176 kfree(led);
177 }
178 }
179
180 }
181
182 static int wacom_battery_get_property(struct power_supply *psy,
183 enum power_supply_property psp,
184 union power_supply_propval *val)
185 {
186 struct wacom_data *wdata = container_of(psy,
187 struct wacom_data, battery);
188 int ret = 0;
189
190 switch (psp) {
191 case POWER_SUPPLY_PROP_PRESENT:
192 val->intval = 1;
193 break;
194 case POWER_SUPPLY_PROP_SCOPE:
195 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
196 break;
197 case POWER_SUPPLY_PROP_CAPACITY:
198 val->intval = wdata->battery_capacity;
199 break;
200 default:
201 ret = -EINVAL;
202 break;
203 }
204 return ret;
205 }
206
207 static int wacom_ac_get_property(struct power_supply *psy,
208 enum power_supply_property psp,
209 union power_supply_propval *val)
210 {
211 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
212 int ret = 0;
213
214 switch (psp) {
215 case POWER_SUPPLY_PROP_PRESENT:
216 /* fall through */
217 case POWER_SUPPLY_PROP_ONLINE:
218 val->intval = wdata->ps_connected;
219 break;
220 case POWER_SUPPLY_PROP_SCOPE:
221 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
222 break;
223 default:
224 ret = -EINVAL;
225 break;
226 }
227 return ret;
228 }
229
230 static void wacom_set_features(struct hid_device *hdev, u8 speed)
231 {
232 struct wacom_data *wdata = hid_get_drvdata(hdev);
233 int limit, ret;
234 __u8 rep_data[2];
235
236 switch (hdev->product) {
237 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
238 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
239 limit = 3;
240 do {
241 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
242 HID_FEATURE_REPORT);
243 } while (ret < 0 && limit-- > 0);
244
245 if (ret >= 0) {
246 if (speed == 0)
247 rep_data[0] = 0x05;
248 else
249 rep_data[0] = 0x06;
250
251 rep_data[1] = 0x00;
252 limit = 3;
253 do {
254 ret = hdev->hid_output_raw_report(hdev,
255 rep_data, 2, HID_FEATURE_REPORT);
256 } while (ret < 0 && limit-- > 0);
257
258 if (ret >= 0) {
259 wdata->high_speed = speed;
260 return;
261 }
262 }
263
264 /*
265 * Note that if the raw queries fail, it's not a hard failure
266 * and it is safe to continue
267 */
268 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
269 rep_data[0], ret);
270 break;
271 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
272 if (speed == 1)
273 wdata->features &= ~0x20;
274 else
275 wdata->features |= 0x20;
276
277 rep_data[0] = 0x03;
278 rep_data[1] = wdata->features;
279
280 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
281 HID_FEATURE_REPORT);
282 if (ret >= 0)
283 wdata->high_speed = speed;
284 break;
285 }
286
287 return;
288 }
289
290 static ssize_t wacom_show_speed(struct device *dev,
291 struct device_attribute
292 *attr, char *buf)
293 {
294 struct wacom_data *wdata = dev_get_drvdata(dev);
295
296 return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed);
297 }
298
299 static ssize_t wacom_store_speed(struct device *dev,
300 struct device_attribute *attr,
301 const char *buf, size_t count)
302 {
303 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
304 int new_speed;
305
306 if (sscanf(buf, "%1d", &new_speed ) != 1)
307 return -EINVAL;
308
309 if (new_speed == 0 || new_speed == 1) {
310 wacom_set_features(hdev, new_speed);
311 return strnlen(buf, PAGE_SIZE);
312 } else
313 return -EINVAL;
314 }
315
316 static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
317 wacom_show_speed, wacom_store_speed);
318
319 static int wacom_gr_parse_report(struct hid_device *hdev,
320 struct wacom_data *wdata,
321 struct input_dev *input, unsigned char *data)
322 {
323 int tool, x, y, rw;
324
325 tool = 0;
326 /* Get X & Y positions */
327 x = le16_to_cpu(*(__le16 *) &data[2]);
328 y = le16_to_cpu(*(__le16 *) &data[4]);
329
330 /* Get current tool identifier */
331 if (data[1] & 0x90) { /* If pen is in the in/active area */
332 switch ((data[1] >> 5) & 3) {
333 case 0: /* Pen */
334 tool = BTN_TOOL_PEN;
335 break;
336
337 case 1: /* Rubber */
338 tool = BTN_TOOL_RUBBER;
339 break;
340
341 case 2: /* Mouse with wheel */
342 case 3: /* Mouse without wheel */
343 tool = BTN_TOOL_MOUSE;
344 break;
345 }
346
347 /* Reset tool if out of active tablet area */
348 if (!(data[1] & 0x10))
349 tool = 0;
350 }
351
352 /* If tool changed, notify input subsystem */
353 if (wdata->tool != tool) {
354 if (wdata->tool) {
355 /* Completely reset old tool state */
356 if (wdata->tool == BTN_TOOL_MOUSE) {
357 input_report_key(input, BTN_LEFT, 0);
358 input_report_key(input, BTN_RIGHT, 0);
359 input_report_key(input, BTN_MIDDLE, 0);
360 input_report_abs(input, ABS_DISTANCE,
361 input_abs_get_max(input, ABS_DISTANCE));
362 } else {
363 input_report_key(input, BTN_TOUCH, 0);
364 input_report_key(input, BTN_STYLUS, 0);
365 input_report_key(input, BTN_STYLUS2, 0);
366 input_report_abs(input, ABS_PRESSURE, 0);
367 }
368 input_report_key(input, wdata->tool, 0);
369 input_sync(input);
370 }
371 wdata->tool = tool;
372 if (tool)
373 input_report_key(input, tool, 1);
374 }
375
376 if (tool) {
377 input_report_abs(input, ABS_X, x);
378 input_report_abs(input, ABS_Y, y);
379
380 switch ((data[1] >> 5) & 3) {
381 case 2: /* Mouse with wheel */
382 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
383 rw = (data[6] & 0x01) ? -1 :
384 (data[6] & 0x02) ? 1 : 0;
385 input_report_rel(input, REL_WHEEL, rw);
386 /* fall through */
387
388 case 3: /* Mouse without wheel */
389 input_report_key(input, BTN_LEFT, data[1] & 0x01);
390 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
391 /* Compute distance between mouse and tablet */
392 rw = 44 - (data[6] >> 2);
393 if (rw < 0)
394 rw = 0;
395 else if (rw > 31)
396 rw = 31;
397 input_report_abs(input, ABS_DISTANCE, rw);
398 break;
399
400 default:
401 input_report_abs(input, ABS_PRESSURE,
402 data[6] | (((__u16) (data[1] & 0x08)) << 5));
403 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
404 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
405 input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
406 break;
407 }
408
409 input_sync(input);
410 }
411
412 /* Report the state of the two buttons at the top of the tablet
413 * as two extra fingerpad keys (buttons 4 & 5). */
414 rw = data[7] & 0x03;
415 if (rw != wdata->butstate) {
416 wdata->butstate = rw;
417 input_report_key(input, BTN_0, rw & 0x02);
418 input_report_key(input, BTN_1, rw & 0x01);
419 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
420 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
421 input_sync(input);
422 }
423
424 /* Store current battery capacity and power supply state*/
425 rw = (data[7] >> 2 & 0x07);
426 if (rw != wdata->power_raw) {
427 wdata->power_raw = rw;
428 wdata->battery_capacity = batcap_gr[rw];
429 if (rw == 7)
430 wdata->ps_connected = 1;
431 else
432 wdata->ps_connected = 0;
433 }
434 return 1;
435 }
436
437 static void wacom_i4_parse_button_report(struct wacom_data *wdata,
438 struct input_dev *input, unsigned char *data)
439 {
440 __u16 new_butstate;
441 __u8 new_whlstate;
442 __u8 sync = 0;
443
444 new_whlstate = data[1];
445 if (new_whlstate != wdata->whlstate) {
446 wdata->whlstate = new_whlstate;
447 if (new_whlstate & 0x80) {
448 input_report_key(input, BTN_TOUCH, 1);
449 input_report_abs(input, ABS_WHEEL, (new_whlstate & 0x7f));
450 input_report_key(input, BTN_TOOL_FINGER, 1);
451 } else {
452 input_report_key(input, BTN_TOUCH, 0);
453 input_report_abs(input, ABS_WHEEL, 0);
454 input_report_key(input, BTN_TOOL_FINGER, 0);
455 }
456 sync = 1;
457 }
458
459 new_butstate = (data[3] << 1) | (data[2] & 0x01);
460 if (new_butstate != wdata->butstate) {
461 wdata->butstate = new_butstate;
462 input_report_key(input, BTN_0, new_butstate & 0x001);
463 input_report_key(input, BTN_1, new_butstate & 0x002);
464 input_report_key(input, BTN_2, new_butstate & 0x004);
465 input_report_key(input, BTN_3, new_butstate & 0x008);
466 input_report_key(input, BTN_4, new_butstate & 0x010);
467 input_report_key(input, BTN_5, new_butstate & 0x020);
468 input_report_key(input, BTN_6, new_butstate & 0x040);
469 input_report_key(input, BTN_7, new_butstate & 0x080);
470 input_report_key(input, BTN_8, new_butstate & 0x100);
471 input_report_key(input, BTN_TOOL_FINGER, 1);
472 sync = 1;
473 }
474
475 if (sync) {
476 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
477 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
478 input_sync(input);
479 }
480 }
481
482 static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
483 struct input_dev *input, unsigned char *data)
484 {
485 __u16 x, y, pressure;
486 __u8 distance;
487 __u8 tilt_x, tilt_y;
488
489 switch (data[1]) {
490 case 0x80: /* Out of proximity report */
491 input_report_key(input, BTN_TOUCH, 0);
492 input_report_abs(input, ABS_PRESSURE, 0);
493 input_report_key(input, BTN_STYLUS, 0);
494 input_report_key(input, BTN_STYLUS2, 0);
495 input_report_key(input, wdata->tool, 0);
496 input_report_abs(input, ABS_MISC, 0);
497 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
498 wdata->tool = 0;
499 input_sync(input);
500 break;
501 case 0xC2: /* Tool report */
502 wdata->id = ((data[2] << 4) | (data[3] >> 4) |
503 ((data[7] & 0x0f) << 20) |
504 ((data[8] & 0xf0) << 12));
505 wdata->serial = ((data[3] & 0x0f) << 28) +
506 (data[4] << 20) + (data[5] << 12) +
507 (data[6] << 4) + (data[7] >> 4);
508
509 switch (wdata->id) {
510 case 0x100802:
511 wdata->tool = BTN_TOOL_PEN;
512 break;
513 case 0x10080A:
514 wdata->tool = BTN_TOOL_RUBBER;
515 break;
516 }
517 break;
518 default: /* Position/pressure report */
519 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
520 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
521 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
522 | (data[1] & 0x01);
523 distance = (data[9] >> 2) & 0x3f;
524 tilt_x = ((data[7] << 1) & 0x7e) | (data[8] >> 7);
525 tilt_y = data[8] & 0x7f;
526
527 input_report_key(input, BTN_TOUCH, pressure > 1);
528
529 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
530 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
531 input_report_key(input, wdata->tool, 1);
532 input_report_abs(input, ABS_X, x);
533 input_report_abs(input, ABS_Y, y);
534 input_report_abs(input, ABS_PRESSURE, pressure);
535 input_report_abs(input, ABS_DISTANCE, distance);
536 input_report_abs(input, ABS_TILT_X, tilt_x);
537 input_report_abs(input, ABS_TILT_Y, tilt_y);
538 input_report_abs(input, ABS_MISC, wdata->id);
539 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
540 input_report_key(input, wdata->tool, 1);
541 input_sync(input);
542 break;
543 }
544
545 return;
546 }
547
548 static void wacom_i4_parse_report(struct hid_device *hdev,
549 struct wacom_data *wdata,
550 struct input_dev *input, unsigned char *data)
551 {
552 switch (data[0]) {
553 case 0x00: /* Empty report */
554 break;
555 case 0x02: /* Pen report */
556 wacom_i4_parse_pen_report(wdata, input, data);
557 break;
558 case 0x03: /* Features Report */
559 wdata->features = data[2];
560 break;
561 case 0x0C: /* Button report */
562 wacom_i4_parse_button_report(wdata, input, data);
563 break;
564 default:
565 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
566 break;
567 }
568 }
569
570 static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
571 u8 *raw_data, int size)
572 {
573 struct wacom_data *wdata = hid_get_drvdata(hdev);
574 struct hid_input *hidinput;
575 struct input_dev *input;
576 unsigned char *data = (unsigned char *) raw_data;
577 int i;
578 __u8 power_raw;
579
580 if (!(hdev->claimed & HID_CLAIMED_INPUT))
581 return 0;
582
583 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
584 input = hidinput->input;
585
586 switch (hdev->product) {
587 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
588 if (data[0] == 0x03) {
589 return wacom_gr_parse_report(hdev, wdata, input, data);
590 } else {
591 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
592 data[0], data[1], size);
593 return 0;
594 }
595 break;
596 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
597 i = 1;
598
599 switch (data[0]) {
600 case 0x04:
601 wacom_i4_parse_report(hdev, wdata, input, data + i);
602 i += 10;
603 /* fall through */
604 case 0x03:
605 wacom_i4_parse_report(hdev, wdata, input, data + i);
606 i += 10;
607 wacom_i4_parse_report(hdev, wdata, input, data + i);
608 power_raw = data[i+10];
609 if (power_raw != wdata->power_raw) {
610 wdata->power_raw = power_raw;
611 wdata->battery_capacity = batcap_i4[power_raw & 0x07];
612 wdata->ps_connected = power_raw & 0x08;
613 }
614
615 break;
616 default:
617 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
618 data[0], data[1], size);
619 return 0;
620 }
621 }
622 return 1;
623 }
624
625 static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
626 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
627 int *max)
628 {
629 struct input_dev *input = hi->input;
630
631 __set_bit(INPUT_PROP_POINTER, input->propbit);
632
633 /* Basics */
634 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
635
636 __set_bit(REL_WHEEL, input->relbit);
637
638 __set_bit(BTN_TOOL_PEN, input->keybit);
639 __set_bit(BTN_TOUCH, input->keybit);
640 __set_bit(BTN_STYLUS, input->keybit);
641 __set_bit(BTN_STYLUS2, input->keybit);
642 __set_bit(BTN_LEFT, input->keybit);
643 __set_bit(BTN_RIGHT, input->keybit);
644 __set_bit(BTN_MIDDLE, input->keybit);
645
646 /* Pad */
647 input_set_capability(input, EV_MSC, MSC_SERIAL);
648
649 __set_bit(BTN_0, input->keybit);
650 __set_bit(BTN_1, input->keybit);
651 __set_bit(BTN_TOOL_FINGER, input->keybit);
652
653 /* Distance, rubber and mouse */
654 __set_bit(BTN_TOOL_RUBBER, input->keybit);
655 __set_bit(BTN_TOOL_MOUSE, input->keybit);
656
657 switch (hdev->product) {
658 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
659 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
660 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
661 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
662 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
663 break;
664 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
665 __set_bit(ABS_WHEEL, input->absbit);
666 __set_bit(ABS_MISC, input->absbit);
667 __set_bit(BTN_2, input->keybit);
668 __set_bit(BTN_3, input->keybit);
669 __set_bit(BTN_4, input->keybit);
670 __set_bit(BTN_5, input->keybit);
671 __set_bit(BTN_6, input->keybit);
672 __set_bit(BTN_7, input->keybit);
673 __set_bit(BTN_8, input->keybit);
674 input_set_abs_params(input, ABS_WHEEL, 0, 71, 0, 0);
675 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
676 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
677 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
678 input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0);
679 input_set_abs_params(input, ABS_TILT_X, 0, 127, 0, 0);
680 input_set_abs_params(input, ABS_TILT_Y, 0, 127, 0, 0);
681 break;
682 }
683
684 return 0;
685 }
686
687 static int wacom_probe(struct hid_device *hdev,
688 const struct hid_device_id *id)
689 {
690 struct wacom_data *wdata;
691 int ret;
692
693 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
694 if (wdata == NULL) {
695 hid_err(hdev, "can't alloc wacom descriptor\n");
696 return -ENOMEM;
697 }
698
699 hid_set_drvdata(hdev, wdata);
700
701 /* Parse the HID report now */
702 ret = hid_parse(hdev);
703 if (ret) {
704 hid_err(hdev, "parse failed\n");
705 goto err_free;
706 }
707
708 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
709 if (ret) {
710 hid_err(hdev, "hw start failed\n");
711 goto err_free;
712 }
713
714 ret = device_create_file(&hdev->dev, &dev_attr_speed);
715 if (ret)
716 hid_warn(hdev,
717 "can't create sysfs speed attribute err: %d\n", ret);
718
719 wdata->features = 0;
720 wacom_set_features(hdev, 1);
721
722 if (hdev->product == USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) {
723 sprintf(hdev->name, "%s", "Wacom Intuos4 WL");
724 ret = wacom_initialize_leds(hdev);
725 if (ret) {
726 hid_warn(hdev,
727 "can't create led attribute, err: %d\n", ret);
728 goto destroy_leds;
729 }
730 }
731
732 wdata->battery.properties = wacom_battery_props;
733 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
734 wdata->battery.get_property = wacom_battery_get_property;
735 wdata->battery.name = "wacom_battery";
736 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
737 wdata->battery.use_for_apm = 0;
738
739
740 ret = power_supply_register(&hdev->dev, &wdata->battery);
741 if (ret) {
742 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
743 ret);
744 goto err_battery;
745 }
746
747 power_supply_powers(&wdata->battery, &hdev->dev);
748
749 wdata->ac.properties = wacom_ac_props;
750 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
751 wdata->ac.get_property = wacom_ac_get_property;
752 wdata->ac.name = "wacom_ac";
753 wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
754 wdata->ac.use_for_apm = 0;
755
756 ret = power_supply_register(&hdev->dev, &wdata->ac);
757 if (ret) {
758 hid_warn(hdev,
759 "can't create ac battery attribute, err: %d\n", ret);
760 goto err_ac;
761 }
762
763 power_supply_powers(&wdata->ac, &hdev->dev);
764 return 0;
765
766 err_ac:
767 power_supply_unregister(&wdata->battery);
768 err_battery:
769 device_remove_file(&hdev->dev, &dev_attr_speed);
770 hid_hw_stop(hdev);
771 destroy_leds:
772 wacom_destroy_leds(hdev);
773 err_free:
774 kfree(wdata);
775 return ret;
776 }
777
778 static void wacom_remove(struct hid_device *hdev)
779 {
780 struct wacom_data *wdata = hid_get_drvdata(hdev);
781
782 wacom_destroy_leds(hdev);
783 device_remove_file(&hdev->dev, &dev_attr_speed);
784 hid_hw_stop(hdev);
785
786 power_supply_unregister(&wdata->battery);
787 power_supply_unregister(&wdata->ac);
788 kfree(hid_get_drvdata(hdev));
789 }
790
791 static const struct hid_device_id wacom_devices[] = {
792 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
793 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
794
795 { }
796 };
797 MODULE_DEVICE_TABLE(hid, wacom_devices);
798
799 static struct hid_driver wacom_driver = {
800 .name = "wacom",
801 .id_table = wacom_devices,
802 .probe = wacom_probe,
803 .remove = wacom_remove,
804 .raw_event = wacom_raw_event,
805 .input_mapped = wacom_input_mapped,
806 };
807
808 static int __init wacom_init(void)
809 {
810 int ret;
811
812 ret = hid_register_driver(&wacom_driver);
813 if (ret)
814 pr_err("can't register wacom driver\n");
815 return ret;
816 }
817
818 static void __exit wacom_exit(void)
819 {
820 hid_unregister_driver(&wacom_driver);
821 }
822
823 module_init(wacom_init);
824 module_exit(wacom_exit);
825 MODULE_DESCRIPTION("Driver for Wacom Graphire Bluetooth and Wacom Intuos4 WL");
826 MODULE_LICENSE("GPL");