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) 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>
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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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>
32 #define PAD_DEVICE_ID 0x0F
34 #define WAC_CMD_LED_CONTROL 0x20
35 #define WAC_CMD_ICON_START_STOP 0x21
36 #define WAC_CMD_ICON_TRANSFER 0x26
45 unsigned char high_speed
;
46 __u8 battery_capacity
;
49 struct power_supply battery
;
50 struct power_supply ac
;
52 struct led_classdev
*leds
[4];
55 /*percent of battery capacity for Graphire
56 8th value means AC online and show 100% capacity */
57 static unsigned short batcap_gr
[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
58 /*percent of battery capacity for Intuos4 WL, AC has a separate bit*/
59 static unsigned short batcap_i4
[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
61 static enum power_supply_property wacom_battery_props
[] = {
62 POWER_SUPPLY_PROP_PRESENT
,
63 POWER_SUPPLY_PROP_CAPACITY
,
64 POWER_SUPPLY_PROP_SCOPE
,
67 static enum power_supply_property wacom_ac_props
[] = {
68 POWER_SUPPLY_PROP_PRESENT
,
69 POWER_SUPPLY_PROP_ONLINE
,
70 POWER_SUPPLY_PROP_SCOPE
,
73 static void wacom_scramble(__u8
*image
)
84 for (x
= 0; x
< 32; x
++) {
85 for (y
= 0; y
< 8; y
++)
86 buf
[(8 * x
) + (7 - y
)] = image
[(8 * x
) + y
];
89 /* Change 76543210 into GECA6420 as required by Intuos4 WL
92 for (x
= 0; x
< 4; x
++) {
93 for (y
= 0; y
< 4; y
++) {
94 for (z
= 0; z
< 8; z
++) {
98 i
= (x
<< 6) + (y
<< 4) + z
;
101 for (w
= 0; w
< 8; w
++) {
109 i
= (x
<< 6) + (y
<< 4) + (z
<< 1);
111 image
[i
+1] = (0xFF00 & r
) >> 8;
117 static void wacom_set_image(struct hid_device
*hdev
, const char *image
,
124 for (i
= 0; i
< 256; i
++)
127 rep_data
[0] = WAC_CMD_ICON_START_STOP
;
129 ret
= hdev
->hid_output_raw_report(hdev
, rep_data
, 2,
134 rep_data
[0] = WAC_CMD_ICON_TRANSFER
;
135 rep_data
[1] = icon_no
& 0x07;
139 for (i
= 0; i
< 4; i
++) {
140 for (j
= 0; j
< 64; j
++)
141 rep_data
[j
+ 3] = p
[(i
<< 6) + j
];
144 ret
= hdev
->hid_output_raw_report(hdev
, rep_data
, 67,
148 rep_data
[0] = WAC_CMD_ICON_START_STOP
;
151 ret
= hdev
->hid_output_raw_report(hdev
, rep_data
, 2,
158 static void wacom_leds_set_brightness(struct led_classdev
*led_dev
,
159 enum led_brightness value
)
161 struct device
*dev
= led_dev
->dev
->parent
;
162 struct hid_device
*hdev
;
163 struct wacom_data
*wdata
;
168 hdev
= container_of(dev
, struct hid_device
, dev
);
169 wdata
= hid_get_drvdata(hdev
);
170 for (i
= 0; i
< 4; ++i
) {
171 if (wdata
->leds
[i
] == led_dev
)
172 wdata
->led_selector
= i
;
175 led
= wdata
->led_selector
| 0x04;
176 buf
= kzalloc(9, GFP_KERNEL
);
178 buf
[0] = WAC_CMD_LED_CONTROL
;
182 /* use fixed brightness for OLEDs */
184 hdev
->hid_output_raw_report(hdev
, buf
, 9, HID_FEATURE_REPORT
);
191 static enum led_brightness
wacom_leds_get_brightness(struct led_classdev
*led_dev
)
193 struct wacom_data
*wdata
;
194 struct device
*dev
= led_dev
->dev
->parent
;
198 wdata
= hid_get_drvdata(container_of(dev
, struct hid_device
, dev
));
200 for (i
= 0; i
< 4; ++i
) {
201 if (wdata
->leds
[i
] == led_dev
) {
202 value
= wdata
->leds
[i
]->brightness
;
211 static int wacom_initialize_leds(struct hid_device
*hdev
)
213 struct wacom_data
*wdata
= hid_get_drvdata(hdev
);
214 struct led_classdev
*led
;
215 struct device
*dev
= &hdev
->dev
;
216 size_t namesz
= strlen(dev_name(dev
)) + 12;
220 wdata
->led_selector
= 0;
222 for (i
= 0; i
< 4; i
++) {
223 led
= kzalloc(sizeof(struct led_classdev
) + namesz
, GFP_KERNEL
);
226 "can't allocate memory for LED selector\n");
231 name
= (void *)&led
[1];
232 snprintf(name
, namesz
, "%s:selector:%d", dev_name(dev
), i
);
235 led
->max_brightness
= 127;
236 led
->brightness_get
= wacom_leds_get_brightness
;
237 led
->brightness_set
= wacom_leds_set_brightness
;
239 wdata
->leds
[i
] = led
;
241 ret
= led_classdev_register(dev
, wdata
->leds
[i
]);
244 wdata
->leds
[i
] = NULL
;
246 hid_warn(hdev
, "can't register LED\n");
255 static void wacom_destroy_leds(struct hid_device
*hdev
)
257 struct wacom_data
*wdata
= hid_get_drvdata(hdev
);
258 struct led_classdev
*led
;
261 for (i
= 0; i
< 4; ++i
) {
262 if (wdata
->leds
[i
]) {
263 led
= wdata
->leds
[i
];
264 wdata
->leds
[i
] = NULL
;
265 led_classdev_unregister(led
);
272 static int wacom_battery_get_property(struct power_supply
*psy
,
273 enum power_supply_property psp
,
274 union power_supply_propval
*val
)
276 struct wacom_data
*wdata
= container_of(psy
,
277 struct wacom_data
, battery
);
281 case POWER_SUPPLY_PROP_PRESENT
:
284 case POWER_SUPPLY_PROP_SCOPE
:
285 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
287 case POWER_SUPPLY_PROP_CAPACITY
:
288 val
->intval
= wdata
->battery_capacity
;
297 static int wacom_ac_get_property(struct power_supply
*psy
,
298 enum power_supply_property psp
,
299 union power_supply_propval
*val
)
301 struct wacom_data
*wdata
= container_of(psy
, struct wacom_data
, ac
);
305 case POWER_SUPPLY_PROP_PRESENT
:
307 case POWER_SUPPLY_PROP_ONLINE
:
308 val
->intval
= wdata
->ps_connected
;
310 case POWER_SUPPLY_PROP_SCOPE
:
311 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
320 static void wacom_set_features(struct hid_device
*hdev
, u8 speed
)
322 struct wacom_data
*wdata
= hid_get_drvdata(hdev
);
326 switch (hdev
->product
) {
327 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH
:
328 rep_data
[0] = 0x03 ; rep_data
[1] = 0x00;
331 ret
= hdev
->hid_output_raw_report(hdev
, rep_data
, 2,
333 } while (ret
< 0 && limit
-- > 0);
344 ret
= hdev
->hid_output_raw_report(hdev
,
345 rep_data
, 2, HID_FEATURE_REPORT
);
346 } while (ret
< 0 && limit
-- > 0);
349 wdata
->high_speed
= speed
;
355 * Note that if the raw queries fail, it's not a hard failure
356 * and it is safe to continue
358 hid_warn(hdev
, "failed to poke device, command %d, err %d\n",
361 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH
:
363 wdata
->features
&= ~0x20;
365 wdata
->features
|= 0x20;
368 rep_data
[1] = wdata
->features
;
370 ret
= hdev
->hid_output_raw_report(hdev
, rep_data
, 2,
373 wdata
->high_speed
= speed
;
380 static ssize_t
wacom_show_speed(struct device
*dev
,
381 struct device_attribute
384 struct wacom_data
*wdata
= dev_get_drvdata(dev
);
386 return snprintf(buf
, PAGE_SIZE
, "%i\n", wdata
->high_speed
);
389 static ssize_t
wacom_store_speed(struct device
*dev
,
390 struct device_attribute
*attr
,
391 const char *buf
, size_t count
)
393 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
396 if (sscanf(buf
, "%1d", &new_speed
) != 1)
399 if (new_speed
== 0 || new_speed
== 1) {
400 wacom_set_features(hdev
, new_speed
);
401 return strnlen(buf
, PAGE_SIZE
);
406 static DEVICE_ATTR(speed
, S_IRUGO
| S_IWUSR
| S_IWGRP
,
407 wacom_show_speed
, wacom_store_speed
);
409 #define WACOM_STORE(OLED_ID) \
410 static ssize_t wacom_oled##OLED_ID##_store(struct device *dev, \
411 struct device_attribute *attr, \
412 const char *buf, size_t count) \
414 struct hid_device *hdev = container_of(dev, struct hid_device, \
420 wacom_set_image(hdev, buf, OLED_ID); \
425 static DEVICE_ATTR(oled##OLED_ID##_img, S_IWUSR | S_IWGRP, NULL, \
426 wacom_oled##OLED_ID##_store)
437 static int wacom_gr_parse_report(struct hid_device
*hdev
,
438 struct wacom_data
*wdata
,
439 struct input_dev
*input
, unsigned char *data
)
444 /* Get X & Y positions */
445 x
= le16_to_cpu(*(__le16
*) &data
[2]);
446 y
= le16_to_cpu(*(__le16
*) &data
[4]);
448 /* Get current tool identifier */
449 if (data
[1] & 0x90) { /* If pen is in the in/active area */
450 switch ((data
[1] >> 5) & 3) {
456 tool
= BTN_TOOL_RUBBER
;
459 case 2: /* Mouse with wheel */
460 case 3: /* Mouse without wheel */
461 tool
= BTN_TOOL_MOUSE
;
465 /* Reset tool if out of active tablet area */
466 if (!(data
[1] & 0x10))
470 /* If tool changed, notify input subsystem */
471 if (wdata
->tool
!= tool
) {
473 /* Completely reset old tool state */
474 if (wdata
->tool
== BTN_TOOL_MOUSE
) {
475 input_report_key(input
, BTN_LEFT
, 0);
476 input_report_key(input
, BTN_RIGHT
, 0);
477 input_report_key(input
, BTN_MIDDLE
, 0);
478 input_report_abs(input
, ABS_DISTANCE
,
479 input_abs_get_max(input
, ABS_DISTANCE
));
481 input_report_key(input
, BTN_TOUCH
, 0);
482 input_report_key(input
, BTN_STYLUS
, 0);
483 input_report_key(input
, BTN_STYLUS2
, 0);
484 input_report_abs(input
, ABS_PRESSURE
, 0);
486 input_report_key(input
, wdata
->tool
, 0);
491 input_report_key(input
, tool
, 1);
495 input_report_abs(input
, ABS_X
, x
);
496 input_report_abs(input
, ABS_Y
, y
);
498 switch ((data
[1] >> 5) & 3) {
499 case 2: /* Mouse with wheel */
500 input_report_key(input
, BTN_MIDDLE
, data
[1] & 0x04);
501 rw
= (data
[6] & 0x01) ? -1 :
502 (data
[6] & 0x02) ? 1 : 0;
503 input_report_rel(input
, REL_WHEEL
, rw
);
506 case 3: /* Mouse without wheel */
507 input_report_key(input
, BTN_LEFT
, data
[1] & 0x01);
508 input_report_key(input
, BTN_RIGHT
, data
[1] & 0x02);
509 /* Compute distance between mouse and tablet */
510 rw
= 44 - (data
[6] >> 2);
515 input_report_abs(input
, ABS_DISTANCE
, rw
);
519 input_report_abs(input
, ABS_PRESSURE
,
520 data
[6] | (((__u16
) (data
[1] & 0x08)) << 5));
521 input_report_key(input
, BTN_TOUCH
, data
[1] & 0x01);
522 input_report_key(input
, BTN_STYLUS
, data
[1] & 0x02);
523 input_report_key(input
, BTN_STYLUS2
, (tool
== BTN_TOOL_PEN
) && data
[1] & 0x04);
530 /* Report the state of the two buttons at the top of the tablet
531 * as two extra fingerpad keys (buttons 4 & 5). */
533 if (rw
!= wdata
->butstate
) {
534 wdata
->butstate
= rw
;
535 input_report_key(input
, BTN_0
, rw
& 0x02);
536 input_report_key(input
, BTN_1
, rw
& 0x01);
537 input_report_key(input
, BTN_TOOL_FINGER
, 0xf0);
538 input_event(input
, EV_MSC
, MSC_SERIAL
, 0xf0);
542 /* Store current battery capacity and power supply state*/
543 rw
= (data
[7] >> 2 & 0x07);
544 if (rw
!= wdata
->power_raw
) {
545 wdata
->power_raw
= rw
;
546 wdata
->battery_capacity
= batcap_gr
[rw
];
548 wdata
->ps_connected
= 1;
550 wdata
->ps_connected
= 0;
555 static void wacom_i4_parse_button_report(struct wacom_data
*wdata
,
556 struct input_dev
*input
, unsigned char *data
)
562 new_whlstate
= data
[1];
563 if (new_whlstate
!= wdata
->whlstate
) {
564 wdata
->whlstate
= new_whlstate
;
565 if (new_whlstate
& 0x80) {
566 input_report_key(input
, BTN_TOUCH
, 1);
567 input_report_abs(input
, ABS_WHEEL
, (new_whlstate
& 0x7f));
568 input_report_key(input
, BTN_TOOL_FINGER
, 1);
570 input_report_key(input
, BTN_TOUCH
, 0);
571 input_report_abs(input
, ABS_WHEEL
, 0);
572 input_report_key(input
, BTN_TOOL_FINGER
, 0);
577 new_butstate
= (data
[3] << 1) | (data
[2] & 0x01);
578 if (new_butstate
!= wdata
->butstate
) {
579 wdata
->butstate
= new_butstate
;
580 input_report_key(input
, BTN_0
, new_butstate
& 0x001);
581 input_report_key(input
, BTN_1
, new_butstate
& 0x002);
582 input_report_key(input
, BTN_2
, new_butstate
& 0x004);
583 input_report_key(input
, BTN_3
, new_butstate
& 0x008);
584 input_report_key(input
, BTN_4
, new_butstate
& 0x010);
585 input_report_key(input
, BTN_5
, new_butstate
& 0x020);
586 input_report_key(input
, BTN_6
, new_butstate
& 0x040);
587 input_report_key(input
, BTN_7
, new_butstate
& 0x080);
588 input_report_key(input
, BTN_8
, new_butstate
& 0x100);
589 input_report_key(input
, BTN_TOOL_FINGER
, 1);
594 input_report_abs(input
, ABS_MISC
, PAD_DEVICE_ID
);
595 input_event(input
, EV_MSC
, MSC_SERIAL
, 0xffffffff);
600 static void wacom_i4_parse_pen_report(struct wacom_data
*wdata
,
601 struct input_dev
*input
, unsigned char *data
)
603 __u16 x
, y
, pressure
;
608 case 0x80: /* Out of proximity report */
609 input_report_key(input
, BTN_TOUCH
, 0);
610 input_report_abs(input
, ABS_PRESSURE
, 0);
611 input_report_key(input
, BTN_STYLUS
, 0);
612 input_report_key(input
, BTN_STYLUS2
, 0);
613 input_report_key(input
, wdata
->tool
, 0);
614 input_report_abs(input
, ABS_MISC
, 0);
615 input_event(input
, EV_MSC
, MSC_SERIAL
, wdata
->serial
);
619 case 0xC2: /* Tool report */
620 wdata
->id
= ((data
[2] << 4) | (data
[3] >> 4) |
621 ((data
[7] & 0x0f) << 20) |
622 ((data
[8] & 0xf0) << 12));
623 wdata
->serial
= ((data
[3] & 0x0f) << 28) +
624 (data
[4] << 20) + (data
[5] << 12) +
625 (data
[6] << 4) + (data
[7] >> 4);
629 wdata
->tool
= BTN_TOOL_PEN
;
632 wdata
->tool
= BTN_TOOL_RUBBER
;
636 default: /* Position/pressure report */
637 x
= data
[2] << 9 | data
[3] << 1 | ((data
[9] & 0x02) >> 1);
638 y
= data
[4] << 9 | data
[5] << 1 | (data
[9] & 0x01);
639 pressure
= (data
[6] << 3) | ((data
[7] & 0xC0) >> 5)
641 distance
= (data
[9] >> 2) & 0x3f;
642 tilt_x
= ((data
[7] << 1) & 0x7e) | (data
[8] >> 7);
643 tilt_y
= data
[8] & 0x7f;
645 input_report_key(input
, BTN_TOUCH
, pressure
> 1);
647 input_report_key(input
, BTN_STYLUS
, data
[1] & 0x02);
648 input_report_key(input
, BTN_STYLUS2
, data
[1] & 0x04);
649 input_report_key(input
, wdata
->tool
, 1);
650 input_report_abs(input
, ABS_X
, x
);
651 input_report_abs(input
, ABS_Y
, y
);
652 input_report_abs(input
, ABS_PRESSURE
, pressure
);
653 input_report_abs(input
, ABS_DISTANCE
, distance
);
654 input_report_abs(input
, ABS_TILT_X
, tilt_x
);
655 input_report_abs(input
, ABS_TILT_Y
, tilt_y
);
656 input_report_abs(input
, ABS_MISC
, wdata
->id
);
657 input_event(input
, EV_MSC
, MSC_SERIAL
, wdata
->serial
);
658 input_report_key(input
, wdata
->tool
, 1);
666 static void wacom_i4_parse_report(struct hid_device
*hdev
,
667 struct wacom_data
*wdata
,
668 struct input_dev
*input
, unsigned char *data
)
671 case 0x00: /* Empty report */
673 case 0x02: /* Pen report */
674 wacom_i4_parse_pen_report(wdata
, input
, data
);
676 case 0x03: /* Features Report */
677 wdata
->features
= data
[2];
679 case 0x0C: /* Button report */
680 wacom_i4_parse_button_report(wdata
, input
, data
);
683 hid_err(hdev
, "Unknown report: %d,%d\n", data
[0], data
[1]);
688 static int wacom_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
689 u8
*raw_data
, int size
)
691 struct wacom_data
*wdata
= hid_get_drvdata(hdev
);
692 struct hid_input
*hidinput
;
693 struct input_dev
*input
;
694 unsigned char *data
= (unsigned char *) raw_data
;
698 if (!(hdev
->claimed
& HID_CLAIMED_INPUT
))
701 hidinput
= list_entry(hdev
->inputs
.next
, struct hid_input
, list
);
702 input
= hidinput
->input
;
704 switch (hdev
->product
) {
705 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH
:
706 if (data
[0] == 0x03) {
707 return wacom_gr_parse_report(hdev
, wdata
, input
, data
);
709 hid_err(hdev
, "Unknown report: %d,%d size:%d\n",
710 data
[0], data
[1], size
);
714 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH
:
719 wacom_i4_parse_report(hdev
, wdata
, input
, data
+ i
);
723 wacom_i4_parse_report(hdev
, wdata
, input
, data
+ i
);
725 wacom_i4_parse_report(hdev
, wdata
, input
, data
+ i
);
726 power_raw
= data
[i
+10];
727 if (power_raw
!= wdata
->power_raw
) {
728 wdata
->power_raw
= power_raw
;
729 wdata
->battery_capacity
= batcap_i4
[power_raw
& 0x07];
730 wdata
->ps_connected
= power_raw
& 0x08;
735 hid_err(hdev
, "Unknown report: %d,%d size:%d\n",
736 data
[0], data
[1], size
);
743 static int wacom_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
744 struct hid_field
*field
, struct hid_usage
*usage
, unsigned long **bit
,
747 struct input_dev
*input
= hi
->input
;
749 __set_bit(INPUT_PROP_POINTER
, input
->propbit
);
752 input
->evbit
[0] |= BIT(EV_KEY
) | BIT(EV_ABS
) | BIT(EV_REL
);
754 __set_bit(REL_WHEEL
, input
->relbit
);
756 __set_bit(BTN_TOOL_PEN
, input
->keybit
);
757 __set_bit(BTN_TOUCH
, input
->keybit
);
758 __set_bit(BTN_STYLUS
, input
->keybit
);
759 __set_bit(BTN_STYLUS2
, input
->keybit
);
760 __set_bit(BTN_LEFT
, input
->keybit
);
761 __set_bit(BTN_RIGHT
, input
->keybit
);
762 __set_bit(BTN_MIDDLE
, input
->keybit
);
765 input_set_capability(input
, EV_MSC
, MSC_SERIAL
);
767 __set_bit(BTN_0
, input
->keybit
);
768 __set_bit(BTN_1
, input
->keybit
);
769 __set_bit(BTN_TOOL_FINGER
, input
->keybit
);
771 /* Distance, rubber and mouse */
772 __set_bit(BTN_TOOL_RUBBER
, input
->keybit
);
773 __set_bit(BTN_TOOL_MOUSE
, input
->keybit
);
775 switch (hdev
->product
) {
776 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH
:
777 input_set_abs_params(input
, ABS_X
, 0, 16704, 4, 0);
778 input_set_abs_params(input
, ABS_Y
, 0, 12064, 4, 0);
779 input_set_abs_params(input
, ABS_PRESSURE
, 0, 511, 0, 0);
780 input_set_abs_params(input
, ABS_DISTANCE
, 0, 32, 0, 0);
782 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH
:
783 __set_bit(ABS_WHEEL
, input
->absbit
);
784 __set_bit(ABS_MISC
, input
->absbit
);
785 __set_bit(BTN_2
, input
->keybit
);
786 __set_bit(BTN_3
, input
->keybit
);
787 __set_bit(BTN_4
, input
->keybit
);
788 __set_bit(BTN_5
, input
->keybit
);
789 __set_bit(BTN_6
, input
->keybit
);
790 __set_bit(BTN_7
, input
->keybit
);
791 __set_bit(BTN_8
, input
->keybit
);
792 input_set_abs_params(input
, ABS_WHEEL
, 0, 71, 0, 0);
793 input_set_abs_params(input
, ABS_X
, 0, 40640, 4, 0);
794 input_set_abs_params(input
, ABS_Y
, 0, 25400, 4, 0);
795 input_set_abs_params(input
, ABS_PRESSURE
, 0, 2047, 0, 0);
796 input_set_abs_params(input
, ABS_DISTANCE
, 0, 63, 0, 0);
797 input_set_abs_params(input
, ABS_TILT_X
, 0, 127, 0, 0);
798 input_set_abs_params(input
, ABS_TILT_Y
, 0, 127, 0, 0);
805 static int wacom_probe(struct hid_device
*hdev
,
806 const struct hid_device_id
*id
)
808 struct wacom_data
*wdata
;
811 wdata
= kzalloc(sizeof(*wdata
), GFP_KERNEL
);
813 hid_err(hdev
, "can't alloc wacom descriptor\n");
817 hid_set_drvdata(hdev
, wdata
);
819 /* Parse the HID report now */
820 ret
= hid_parse(hdev
);
822 hid_err(hdev
, "parse failed\n");
826 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
828 hid_err(hdev
, "hw start failed\n");
832 ret
= device_create_file(&hdev
->dev
, &dev_attr_speed
);
835 "can't create sysfs speed attribute err: %d\n", ret
);
837 #define OLED_INIT(OLED_ID) \
839 ret = device_create_file(&hdev->dev, \
840 &dev_attr_oled##OLED_ID##_img); \
843 "can't create sysfs oled attribute, err: %d\n", ret);\
856 wacom_set_features(hdev
, 1);
858 if (hdev
->product
== USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH
) {
859 sprintf(hdev
->name
, "%s", "Wacom Intuos4 WL");
860 ret
= wacom_initialize_leds(hdev
);
863 "can't create led attribute, err: %d\n", ret
);
866 wdata
->battery
.properties
= wacom_battery_props
;
867 wdata
->battery
.num_properties
= ARRAY_SIZE(wacom_battery_props
);
868 wdata
->battery
.get_property
= wacom_battery_get_property
;
869 wdata
->battery
.name
= "wacom_battery";
870 wdata
->battery
.type
= POWER_SUPPLY_TYPE_BATTERY
;
871 wdata
->battery
.use_for_apm
= 0;
874 ret
= power_supply_register(&hdev
->dev
, &wdata
->battery
);
876 hid_err(hdev
, "can't create sysfs battery attribute, err: %d\n",
881 power_supply_powers(&wdata
->battery
, &hdev
->dev
);
883 wdata
->ac
.properties
= wacom_ac_props
;
884 wdata
->ac
.num_properties
= ARRAY_SIZE(wacom_ac_props
);
885 wdata
->ac
.get_property
= wacom_ac_get_property
;
886 wdata
->ac
.name
= "wacom_ac";
887 wdata
->ac
.type
= POWER_SUPPLY_TYPE_MAINS
;
888 wdata
->ac
.use_for_apm
= 0;
890 ret
= power_supply_register(&hdev
->dev
, &wdata
->ac
);
893 "can't create ac battery attribute, err: %d\n", ret
);
897 power_supply_powers(&wdata
->ac
, &hdev
->dev
);
901 power_supply_unregister(&wdata
->battery
);
903 wacom_destroy_leds(hdev
);
904 device_remove_file(&hdev
->dev
, &dev_attr_oled0_img
);
905 device_remove_file(&hdev
->dev
, &dev_attr_oled1_img
);
906 device_remove_file(&hdev
->dev
, &dev_attr_oled2_img
);
907 device_remove_file(&hdev
->dev
, &dev_attr_oled3_img
);
908 device_remove_file(&hdev
->dev
, &dev_attr_oled4_img
);
909 device_remove_file(&hdev
->dev
, &dev_attr_oled5_img
);
910 device_remove_file(&hdev
->dev
, &dev_attr_oled6_img
);
911 device_remove_file(&hdev
->dev
, &dev_attr_oled7_img
);
912 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
919 static void wacom_remove(struct hid_device
*hdev
)
921 struct wacom_data
*wdata
= hid_get_drvdata(hdev
);
923 wacom_destroy_leds(hdev
);
924 device_remove_file(&hdev
->dev
, &dev_attr_oled0_img
);
925 device_remove_file(&hdev
->dev
, &dev_attr_oled1_img
);
926 device_remove_file(&hdev
->dev
, &dev_attr_oled2_img
);
927 device_remove_file(&hdev
->dev
, &dev_attr_oled3_img
);
928 device_remove_file(&hdev
->dev
, &dev_attr_oled4_img
);
929 device_remove_file(&hdev
->dev
, &dev_attr_oled5_img
);
930 device_remove_file(&hdev
->dev
, &dev_attr_oled6_img
);
931 device_remove_file(&hdev
->dev
, &dev_attr_oled7_img
);
932 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
935 power_supply_unregister(&wdata
->battery
);
936 power_supply_unregister(&wdata
->ac
);
937 kfree(hid_get_drvdata(hdev
));
940 static const struct hid_device_id wacom_devices
[] = {
941 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM
, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH
) },
942 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM
, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH
) },
946 MODULE_DEVICE_TABLE(hid
, wacom_devices
);
948 static struct hid_driver wacom_driver
= {
950 .id_table
= wacom_devices
,
951 .probe
= wacom_probe
,
952 .remove
= wacom_remove
,
953 .raw_event
= wacom_raw_event
,
954 .input_mapped
= wacom_input_mapped
,
956 module_hid_driver(wacom_driver
);
958 MODULE_DESCRIPTION("Driver for Wacom Graphire Bluetooth and Wacom Intuos4 WL");
959 MODULE_LICENSE("GPL");