2 * drivers/input/tablet/wacom_sys.c
4 * USB Wacom tablet support - system specific code
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include "wacom_wac.h"
16 #include <linux/input/mt.h>
18 #define WAC_MSG_RETRIES 5
20 #define WAC_CMD_WL_LED_CONTROL 0x03
21 #define WAC_CMD_LED_CONTROL 0x20
22 #define WAC_CMD_ICON_START 0x21
23 #define WAC_CMD_ICON_XFER 0x23
24 #define WAC_CMD_ICON_BT_XFER 0x26
25 #define WAC_CMD_RETRIES 10
27 #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
28 #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
30 static int wacom_get_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
31 size_t size
, unsigned int retries
)
36 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
38 } while ((retval
== -ETIMEDOUT
|| retval
== -EAGAIN
) && --retries
);
41 hid_err(hdev
, "wacom_get_report: ran out of retries "
42 "(last error = %d)\n", retval
);
47 static int wacom_set_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
48 size_t size
, unsigned int retries
)
53 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
55 } while ((retval
== -ETIMEDOUT
|| retval
== -EAGAIN
) && --retries
);
58 hid_err(hdev
, "wacom_set_report: ran out of retries "
59 "(last error = %d)\n", retval
);
64 static int wacom_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
65 u8
*raw_data
, int size
)
67 struct wacom
*wacom
= hid_get_drvdata(hdev
);
69 if (size
> WACOM_PKGLEN_MAX
)
72 memcpy(wacom
->wacom_wac
.data
, raw_data
, size
);
74 wacom_wac_irq(&wacom
->wacom_wac
, size
);
79 static int wacom_open(struct input_dev
*dev
)
81 struct wacom
*wacom
= input_get_drvdata(dev
);
83 return hid_hw_open(wacom
->hdev
);
86 static void wacom_close(struct input_dev
*dev
)
88 struct wacom
*wacom
= input_get_drvdata(dev
);
90 hid_hw_close(wacom
->hdev
);
94 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
96 static int wacom_calc_hid_res(int logical_extents
, int physical_extents
,
97 unsigned unit
, int exponent
)
99 struct hid_field field
= {
100 .logical_maximum
= logical_extents
,
101 .physical_maximum
= physical_extents
,
103 .unit_exponent
= exponent
,
106 return hidinput_calc_abs_res(&field
, ABS_X
);
109 static void wacom_feature_mapping(struct hid_device
*hdev
,
110 struct hid_field
*field
, struct hid_usage
*usage
)
112 struct wacom
*wacom
= hid_get_drvdata(hdev
);
113 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
114 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
118 switch (usage
->hid
) {
119 case HID_DG_CONTACTMAX
:
120 /* leave touch_max as is if predefined */
121 if (!features
->touch_max
) {
123 data
= kzalloc(2, GFP_KERNEL
);
126 data
[0] = field
->report
->id
;
127 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
130 features
->touch_max
= data
[1];
134 case HID_DG_INPUTMODE
:
135 /* Ignore if value index is out of bounds. */
136 if (usage
->usage_index
>= field
->report_count
) {
137 dev_err(&hdev
->dev
, "HID_DG_INPUTMODE out of range\n");
141 hid_data
->inputmode
= field
->report
->id
;
142 hid_data
->inputmode_index
= usage
->usage_index
;
148 * Interface Descriptor of wacom devices can be incomplete and
149 * inconsistent so wacom_features table is used to store stylus
150 * device's packet lengths, various maximum values, and tablet
151 * resolution based on product ID's.
153 * For devices that contain 2 interfaces, wacom_features table is
154 * inaccurate for the touch interface. Since the Interface Descriptor
155 * for touch interfaces has pretty complete data, this function exists
156 * to query tablet for this missing information instead of hard coding in
157 * an additional table.
159 * A typical Interface Descriptor for a stylus will contain a
160 * boot mouse application collection that is not of interest and this
161 * function will ignore it.
163 * It also contains a digitizer application collection that also is not
164 * of interest since any information it contains would be duplicate
165 * of what is in wacom_features. Usually it defines a report of an array
166 * of bytes that could be used as max length of the stylus packet returned.
167 * If it happens to define a Digitizer-Stylus Physical Collection then
168 * the X and Y logical values contain valid data but it is ignored.
170 * A typical Interface Descriptor for a touch interface will contain a
171 * Digitizer-Finger Physical Collection which will define both logical
172 * X/Y maximum as well as the physical size of tablet. Since touch
173 * interfaces haven't supported pressure or distance, this is enough
174 * information to override invalid values in the wacom_features table.
176 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
177 * data. We deal with them after returning from this function.
179 static void wacom_usage_mapping(struct hid_device
*hdev
,
180 struct hid_field
*field
, struct hid_usage
*usage
)
182 struct wacom
*wacom
= hid_get_drvdata(hdev
);
183 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
184 bool finger
= WACOM_FINGER_FIELD(field
);
185 bool pen
= WACOM_PEN_FIELD(field
);
188 * Requiring Stylus Usage will ignore boot mouse
189 * X/Y values and some cases of invalid Digitizer X/Y
190 * values commonly reported.
193 features
->device_type
= BTN_TOOL_PEN
;
195 features
->device_type
= BTN_TOOL_FINGER
;
200 * Bamboo models do not support HID_DG_CONTACTMAX.
201 * And, Bamboo Pen only descriptor contains touch.
203 if (features
->type
!= BAMBOO_PT
) {
204 /* ISDv4 touch devices at least supports one touch point */
205 if (finger
&& !features
->touch_max
)
206 features
->touch_max
= 1;
209 switch (usage
->hid
) {
211 features
->x_max
= field
->logical_maximum
;
213 features
->x_phy
= field
->physical_maximum
;
214 if (features
->type
!= BAMBOO_PT
) {
215 features
->unit
= field
->unit
;
216 features
->unitExpo
= field
->unit_exponent
;
221 features
->y_max
= field
->logical_maximum
;
223 features
->y_phy
= field
->physical_maximum
;
224 if (features
->type
!= BAMBOO_PT
) {
225 features
->unit
= field
->unit
;
226 features
->unitExpo
= field
->unit_exponent
;
230 case HID_DG_TIPPRESSURE
:
232 features
->pressure_max
= field
->logical_maximum
;
236 if (features
->type
== HID_GENERIC
)
237 wacom_wac_usage_mapping(hdev
, field
, usage
);
240 static void wacom_post_parse_hid(struct hid_device
*hdev
,
241 struct wacom_features
*features
)
243 struct wacom
*wacom
= hid_get_drvdata(hdev
);
244 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
246 if (features
->type
== HID_GENERIC
) {
247 /* Any last-minute generic device setup */
248 if (features
->touch_max
> 1) {
249 input_mt_init_slots(wacom_wac
->input
, wacom_wac
->features
.touch_max
,
255 static void wacom_parse_hid(struct hid_device
*hdev
,
256 struct wacom_features
*features
)
258 struct hid_report_enum
*rep_enum
;
259 struct hid_report
*hreport
;
262 /* check features first */
263 rep_enum
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
264 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
265 for (i
= 0; i
< hreport
->maxfield
; i
++) {
266 /* Ignore if report count is out of bounds. */
267 if (hreport
->field
[i
]->report_count
< 1)
270 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++) {
271 wacom_feature_mapping(hdev
, hreport
->field
[i
],
272 hreport
->field
[i
]->usage
+ j
);
277 /* now check the input usages */
278 rep_enum
= &hdev
->report_enum
[HID_INPUT_REPORT
];
279 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
281 if (!hreport
->maxfield
)
284 for (i
= 0; i
< hreport
->maxfield
; i
++)
285 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++)
286 wacom_usage_mapping(hdev
, hreport
->field
[i
],
287 hreport
->field
[i
]->usage
+ j
);
290 wacom_post_parse_hid(hdev
, features
);
293 static int wacom_hid_set_device_mode(struct hid_device
*hdev
)
295 struct wacom
*wacom
= hid_get_drvdata(hdev
);
296 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
297 struct hid_report
*r
;
298 struct hid_report_enum
*re
;
300 if (hid_data
->inputmode
< 0)
303 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
304 r
= re
->report_id_hash
[hid_data
->inputmode
];
306 r
->field
[0]->value
[hid_data
->inputmode_index
] = 2;
307 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
312 static int wacom_set_device_mode(struct hid_device
*hdev
, int report_id
,
313 int length
, int mode
)
315 unsigned char *rep_data
;
316 int error
= -ENOMEM
, limit
= 0;
318 rep_data
= kzalloc(length
, GFP_KERNEL
);
323 rep_data
[0] = report_id
;
326 error
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
,
329 error
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
330 rep_data
, length
, 1);
331 } while ((error
< 0 || rep_data
[1] != mode
) && limit
++ < WAC_MSG_RETRIES
);
335 return error
< 0 ? error
: 0;
338 static int wacom_bt_query_tablet_data(struct hid_device
*hdev
, u8 speed
,
339 struct wacom_features
*features
)
341 struct wacom
*wacom
= hid_get_drvdata(hdev
);
345 switch (features
->type
) {
349 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
353 rep_data
[0] = speed
== 0 ? 0x05 : 0x06;
356 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
,
360 wacom
->wacom_wac
.bt_high_speed
= speed
;
366 * Note that if the raw queries fail, it's not a hard failure
367 * and it is safe to continue
369 hid_warn(hdev
, "failed to poke device, command %d, err %d\n",
374 wacom
->wacom_wac
.bt_features
&= ~0x20;
376 wacom
->wacom_wac
.bt_features
|= 0x20;
379 rep_data
[1] = wacom
->wacom_wac
.bt_features
;
381 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
384 wacom
->wacom_wac
.bt_high_speed
= speed
;
392 * Switch the tablet into its most-capable mode. Wacom tablets are
393 * typically configured to power-up in a mode which sends mouse-like
394 * reports to the OS. To get absolute position, pressure data, etc.
395 * from the tablet, it is necessary to switch the tablet out of this
396 * mode and into one which sends the full range of tablet data.
398 static int wacom_query_tablet_data(struct hid_device
*hdev
,
399 struct wacom_features
*features
)
401 if (hdev
->bus
== BUS_BLUETOOTH
)
402 return wacom_bt_query_tablet_data(hdev
, 1, features
);
404 if (features
->type
== HID_GENERIC
)
405 return wacom_hid_set_device_mode(hdev
);
407 if (features
->device_type
== BTN_TOOL_FINGER
) {
408 if (features
->type
> TABLETPC
) {
409 /* MT Tablet PC touch */
410 return wacom_set_device_mode(hdev
, 3, 4, 4);
412 else if (features
->type
== WACOM_24HDT
|| features
->type
== CINTIQ_HYBRID
) {
413 return wacom_set_device_mode(hdev
, 18, 3, 2);
415 else if (features
->type
== WACOM_27QHDT
) {
416 return wacom_set_device_mode(hdev
, 131, 3, 2);
418 else if (features
->type
== BAMBOO_PAD
) {
419 return wacom_set_device_mode(hdev
, 2, 2, 2);
421 } else if (features
->device_type
== BTN_TOOL_PEN
) {
422 if (features
->type
<= BAMBOO_PT
&& features
->type
!= WIRELESS
) {
423 return wacom_set_device_mode(hdev
, 2, 2, 2);
430 static void wacom_retrieve_hid_descriptor(struct hid_device
*hdev
,
431 struct wacom_features
*features
)
433 struct wacom
*wacom
= hid_get_drvdata(hdev
);
434 struct usb_interface
*intf
= wacom
->intf
;
436 /* default features */
437 features
->x_fuzz
= 4;
438 features
->y_fuzz
= 4;
439 features
->pressure_fuzz
= 0;
440 features
->distance_fuzz
= 0;
443 * The wireless device HID is basic and layout conflicts with
444 * other tablets (monitor and touch interface can look like pen).
445 * Skip the query for this type and modify defaults based on
448 if (features
->type
== WIRELESS
) {
449 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 0) {
450 features
->device_type
= 0;
451 } else if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 2) {
452 features
->device_type
= BTN_TOOL_FINGER
;
453 features
->pktlen
= WACOM_PKGLEN_BBTOUCH3
;
457 wacom_parse_hid(hdev
, features
);
460 struct wacom_hdev_data
{
461 struct list_head list
;
463 struct hid_device
*dev
;
464 struct wacom_shared shared
;
467 static LIST_HEAD(wacom_udev_list
);
468 static DEFINE_MUTEX(wacom_udev_list_lock
);
470 static bool wacom_are_sibling(struct hid_device
*hdev
,
471 struct hid_device
*sibling
)
473 struct wacom
*wacom
= hid_get_drvdata(hdev
);
474 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
475 int vid
= features
->oVid
;
476 int pid
= features
->oPid
;
479 if (vid
== 0 && pid
== 0) {
484 if (vid
!= sibling
->vendor
|| pid
!= sibling
->product
)
487 /* Compare the physical path. */
488 n1
= strrchr(hdev
->phys
, '.') - hdev
->phys
;
489 n2
= strrchr(sibling
->phys
, '.') - sibling
->phys
;
490 if (n1
!= n2
|| n1
<= 0 || n2
<= 0)
493 return !strncmp(hdev
->phys
, sibling
->phys
, n1
);
496 static struct wacom_hdev_data
*wacom_get_hdev_data(struct hid_device
*hdev
)
498 struct wacom_hdev_data
*data
;
500 list_for_each_entry(data
, &wacom_udev_list
, list
) {
501 if (wacom_are_sibling(hdev
, data
->dev
)) {
502 kref_get(&data
->kref
);
510 static int wacom_add_shared_data(struct hid_device
*hdev
)
512 struct wacom
*wacom
= hid_get_drvdata(hdev
);
513 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
514 struct wacom_hdev_data
*data
;
517 mutex_lock(&wacom_udev_list_lock
);
519 data
= wacom_get_hdev_data(hdev
);
521 data
= kzalloc(sizeof(struct wacom_hdev_data
), GFP_KERNEL
);
527 kref_init(&data
->kref
);
529 list_add_tail(&data
->list
, &wacom_udev_list
);
532 wacom_wac
->shared
= &data
->shared
;
534 if (wacom_wac
->features
.device_type
== BTN_TOOL_FINGER
)
535 wacom_wac
->shared
->touch
= hdev
;
536 else if (wacom_wac
->features
.device_type
== BTN_TOOL_PEN
)
537 wacom_wac
->shared
->pen
= hdev
;
540 mutex_unlock(&wacom_udev_list_lock
);
544 static void wacom_release_shared_data(struct kref
*kref
)
546 struct wacom_hdev_data
*data
=
547 container_of(kref
, struct wacom_hdev_data
, kref
);
549 mutex_lock(&wacom_udev_list_lock
);
550 list_del(&data
->list
);
551 mutex_unlock(&wacom_udev_list_lock
);
556 static void wacom_remove_shared_data(struct wacom
*wacom
)
558 struct wacom_hdev_data
*data
;
559 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
561 if (wacom_wac
->shared
) {
562 data
= container_of(wacom_wac
->shared
, struct wacom_hdev_data
,
565 if (wacom_wac
->shared
->touch
== wacom
->hdev
)
566 wacom_wac
->shared
->touch
= NULL
;
567 else if (wacom_wac
->shared
->pen
== wacom
->hdev
)
568 wacom_wac
->shared
->pen
= NULL
;
570 kref_put(&data
->kref
, wacom_release_shared_data
);
571 wacom_wac
->shared
= NULL
;
575 static int wacom_led_control(struct wacom
*wacom
)
579 unsigned char report_id
= WAC_CMD_LED_CONTROL
;
582 if (wacom
->wacom_wac
.pid
) { /* wireless connected */
583 report_id
= WAC_CMD_WL_LED_CONTROL
;
586 buf
= kzalloc(buf_size
, GFP_KERNEL
);
590 if (wacom
->wacom_wac
.features
.type
>= INTUOS5S
&&
591 wacom
->wacom_wac
.features
.type
<= INTUOSPL
) {
593 * Touch Ring and crop mark LED luminance may take on
594 * one of four values:
595 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
597 int ring_led
= wacom
->led
.select
[0] & 0x03;
598 int ring_lum
= (((wacom
->led
.llv
& 0x60) >> 5) - 1) & 0x03;
600 unsigned char led_bits
= (crop_lum
<< 4) | (ring_lum
<< 2) | (ring_led
);
603 if (wacom
->wacom_wac
.pid
) {
604 wacom_get_report(wacom
->hdev
, HID_FEATURE_REPORT
,
605 buf
, buf_size
, WAC_CMD_RETRIES
);
612 int led
= wacom
->led
.select
[0] | 0x4;
614 if (wacom
->wacom_wac
.features
.type
== WACOM_21UX2
||
615 wacom
->wacom_wac
.features
.type
== WACOM_24HD
)
616 led
|= (wacom
->led
.select
[1] << 4) | 0x40;
620 buf
[2] = wacom
->led
.llv
;
621 buf
[3] = wacom
->led
.hlv
;
622 buf
[4] = wacom
->led
.img_lum
;
625 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, buf_size
,
632 static int wacom_led_putimage(struct wacom
*wacom
, int button_id
, u8 xfer_id
,
633 const unsigned len
, const void *img
)
637 const unsigned chunk_len
= len
/ 4; /* 4 chunks are needed to be sent */
639 buf
= kzalloc(chunk_len
+ 3 , GFP_KERNEL
);
643 /* Send 'start' command */
644 buf
[0] = WAC_CMD_ICON_START
;
646 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
652 buf
[1] = button_id
& 0x07;
653 for (i
= 0; i
< 4; i
++) {
655 memcpy(buf
+ 3, img
+ i
* chunk_len
, chunk_len
);
657 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
,
658 buf
, chunk_len
+ 3, WAC_CMD_RETRIES
);
664 buf
[0] = WAC_CMD_ICON_START
;
666 wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
674 static ssize_t
wacom_led_select_store(struct device
*dev
, int set_id
,
675 const char *buf
, size_t count
)
677 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
678 struct wacom
*wacom
= hid_get_drvdata(hdev
);
682 err
= kstrtouint(buf
, 10, &id
);
686 mutex_lock(&wacom
->lock
);
688 wacom
->led
.select
[set_id
] = id
& 0x3;
689 err
= wacom_led_control(wacom
);
691 mutex_unlock(&wacom
->lock
);
693 return err
< 0 ? err
: count
;
696 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
697 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
698 struct device_attribute *attr, const char *buf, size_t count) \
700 return wacom_led_select_store(dev, SET_ID, buf, count); \
702 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
703 struct device_attribute *attr, char *buf) \
705 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
706 struct wacom *wacom = hid_get_drvdata(hdev); \
707 return scnprintf(buf, PAGE_SIZE, "%d\n", \
708 wacom->led.select[SET_ID]); \
710 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
711 wacom_led##SET_ID##_select_show, \
712 wacom_led##SET_ID##_select_store)
714 DEVICE_LED_SELECT_ATTR(0);
715 DEVICE_LED_SELECT_ATTR(1);
717 static ssize_t
wacom_luminance_store(struct wacom
*wacom
, u8
*dest
,
718 const char *buf
, size_t count
)
723 err
= kstrtouint(buf
, 10, &value
);
727 mutex_lock(&wacom
->lock
);
729 *dest
= value
& 0x7f;
730 err
= wacom_led_control(wacom
);
732 mutex_unlock(&wacom
->lock
);
734 return err
< 0 ? err
: count
;
737 #define DEVICE_LUMINANCE_ATTR(name, field) \
738 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
739 struct device_attribute *attr, const char *buf, size_t count) \
741 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
742 struct wacom *wacom = hid_get_drvdata(hdev); \
744 return wacom_luminance_store(wacom, &wacom->led.field, \
747 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
748 struct device_attribute *attr, char *buf) \
750 struct wacom *wacom = dev_get_drvdata(dev); \
751 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
753 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
754 wacom_##name##_luminance_show, \
755 wacom_##name##_luminance_store)
757 DEVICE_LUMINANCE_ATTR(status0
, llv
);
758 DEVICE_LUMINANCE_ATTR(status1
, hlv
);
759 DEVICE_LUMINANCE_ATTR(buttons
, img_lum
);
761 static ssize_t
wacom_button_image_store(struct device
*dev
, int button_id
,
762 const char *buf
, size_t count
)
764 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
765 struct wacom
*wacom
= hid_get_drvdata(hdev
);
770 if (hdev
->bus
== BUS_BLUETOOTH
) {
772 xfer_id
= WAC_CMD_ICON_BT_XFER
;
775 xfer_id
= WAC_CMD_ICON_XFER
;
781 mutex_lock(&wacom
->lock
);
783 err
= wacom_led_putimage(wacom
, button_id
, xfer_id
, len
, buf
);
785 mutex_unlock(&wacom
->lock
);
787 return err
< 0 ? err
: count
;
790 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
791 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
792 struct device_attribute *attr, const char *buf, size_t count) \
794 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
796 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
797 NULL, wacom_btnimg##BUTTON_ID##_store)
799 DEVICE_BTNIMG_ATTR(0);
800 DEVICE_BTNIMG_ATTR(1);
801 DEVICE_BTNIMG_ATTR(2);
802 DEVICE_BTNIMG_ATTR(3);
803 DEVICE_BTNIMG_ATTR(4);
804 DEVICE_BTNIMG_ATTR(5);
805 DEVICE_BTNIMG_ATTR(6);
806 DEVICE_BTNIMG_ATTR(7);
808 static struct attribute
*cintiq_led_attrs
[] = {
809 &dev_attr_status_led0_select
.attr
,
810 &dev_attr_status_led1_select
.attr
,
814 static struct attribute_group cintiq_led_attr_group
= {
816 .attrs
= cintiq_led_attrs
,
819 static struct attribute
*intuos4_led_attrs
[] = {
820 &dev_attr_status0_luminance
.attr
,
821 &dev_attr_status1_luminance
.attr
,
822 &dev_attr_status_led0_select
.attr
,
823 &dev_attr_buttons_luminance
.attr
,
824 &dev_attr_button0_rawimg
.attr
,
825 &dev_attr_button1_rawimg
.attr
,
826 &dev_attr_button2_rawimg
.attr
,
827 &dev_attr_button3_rawimg
.attr
,
828 &dev_attr_button4_rawimg
.attr
,
829 &dev_attr_button5_rawimg
.attr
,
830 &dev_attr_button6_rawimg
.attr
,
831 &dev_attr_button7_rawimg
.attr
,
835 static struct attribute_group intuos4_led_attr_group
= {
837 .attrs
= intuos4_led_attrs
,
840 static struct attribute
*intuos5_led_attrs
[] = {
841 &dev_attr_status0_luminance
.attr
,
842 &dev_attr_status_led0_select
.attr
,
846 static struct attribute_group intuos5_led_attr_group
= {
848 .attrs
= intuos5_led_attrs
,
851 static int wacom_initialize_leds(struct wacom
*wacom
)
855 /* Initialize default values */
856 switch (wacom
->wacom_wac
.features
.type
) {
861 wacom
->led
.select
[0] = 0;
862 wacom
->led
.select
[1] = 0;
865 wacom
->led
.img_lum
= 10;
866 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
867 &intuos4_led_attr_group
);
872 wacom
->led
.select
[0] = 0;
873 wacom
->led
.select
[1] = 0;
876 wacom
->led
.img_lum
= 0;
878 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
879 &cintiq_led_attr_group
);
888 if (wacom
->wacom_wac
.features
.device_type
== BTN_TOOL_PEN
) {
889 wacom
->led
.select
[0] = 0;
890 wacom
->led
.select
[1] = 0;
893 wacom
->led
.img_lum
= 0;
895 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
896 &intuos5_led_attr_group
);
907 "cannot create sysfs group err: %d\n", error
);
910 wacom_led_control(wacom
);
911 wacom
->led_initialized
= true;
916 static void wacom_destroy_leds(struct wacom
*wacom
)
918 if (!wacom
->led_initialized
)
921 wacom
->led_initialized
= false;
923 switch (wacom
->wacom_wac
.features
.type
) {
928 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
929 &intuos4_led_attr_group
);
934 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
935 &cintiq_led_attr_group
);
944 if (wacom
->wacom_wac
.features
.device_type
== BTN_TOOL_PEN
)
945 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
946 &intuos5_led_attr_group
);
951 static enum power_supply_property wacom_battery_props
[] = {
952 POWER_SUPPLY_PROP_PRESENT
,
953 POWER_SUPPLY_PROP_STATUS
,
954 POWER_SUPPLY_PROP_SCOPE
,
955 POWER_SUPPLY_PROP_CAPACITY
958 static enum power_supply_property wacom_ac_props
[] = {
959 POWER_SUPPLY_PROP_PRESENT
,
960 POWER_SUPPLY_PROP_ONLINE
,
961 POWER_SUPPLY_PROP_SCOPE
,
964 static int wacom_battery_get_property(struct power_supply
*psy
,
965 enum power_supply_property psp
,
966 union power_supply_propval
*val
)
968 struct wacom
*wacom
= power_supply_get_drvdata(psy
);
972 case POWER_SUPPLY_PROP_PRESENT
:
973 val
->intval
= wacom
->wacom_wac
.bat_connected
;
975 case POWER_SUPPLY_PROP_SCOPE
:
976 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
978 case POWER_SUPPLY_PROP_CAPACITY
:
980 wacom
->wacom_wac
.battery_capacity
;
982 case POWER_SUPPLY_PROP_STATUS
:
983 if (wacom
->wacom_wac
.bat_charging
)
984 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
985 else if (wacom
->wacom_wac
.battery_capacity
== 100 &&
986 wacom
->wacom_wac
.ps_connected
)
987 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
988 else if (wacom
->wacom_wac
.ps_connected
)
989 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
991 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
1001 static int wacom_ac_get_property(struct power_supply
*psy
,
1002 enum power_supply_property psp
,
1003 union power_supply_propval
*val
)
1005 struct wacom
*wacom
= power_supply_get_drvdata(psy
);
1009 case POWER_SUPPLY_PROP_PRESENT
:
1011 case POWER_SUPPLY_PROP_ONLINE
:
1012 val
->intval
= wacom
->wacom_wac
.ps_connected
;
1014 case POWER_SUPPLY_PROP_SCOPE
:
1015 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
1024 static int wacom_initialize_battery(struct wacom
*wacom
)
1026 static atomic_t battery_no
= ATOMIC_INIT(0);
1027 struct power_supply_config psy_cfg
= { .drv_data
= wacom
, };
1030 if (wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) {
1031 struct power_supply_desc
*bat_desc
= &wacom
->battery_desc
;
1032 struct power_supply_desc
*ac_desc
= &wacom
->ac_desc
;
1033 n
= atomic_inc_return(&battery_no
) - 1;
1035 bat_desc
->properties
= wacom_battery_props
;
1036 bat_desc
->num_properties
= ARRAY_SIZE(wacom_battery_props
);
1037 bat_desc
->get_property
= wacom_battery_get_property
;
1038 sprintf(wacom
->wacom_wac
.bat_name
, "wacom_battery_%ld", n
);
1039 bat_desc
->name
= wacom
->wacom_wac
.bat_name
;
1040 bat_desc
->type
= POWER_SUPPLY_TYPE_BATTERY
;
1041 bat_desc
->use_for_apm
= 0;
1043 ac_desc
->properties
= wacom_ac_props
;
1044 ac_desc
->num_properties
= ARRAY_SIZE(wacom_ac_props
);
1045 ac_desc
->get_property
= wacom_ac_get_property
;
1046 sprintf(wacom
->wacom_wac
.ac_name
, "wacom_ac_%ld", n
);
1047 ac_desc
->name
= wacom
->wacom_wac
.ac_name
;
1048 ac_desc
->type
= POWER_SUPPLY_TYPE_MAINS
;
1049 ac_desc
->use_for_apm
= 0;
1051 wacom
->battery
= power_supply_register(&wacom
->hdev
->dev
,
1052 &wacom
->battery_desc
, &psy_cfg
);
1053 if (IS_ERR(wacom
->battery
))
1054 return PTR_ERR(wacom
->battery
);
1056 power_supply_powers(wacom
->battery
, &wacom
->hdev
->dev
);
1058 wacom
->ac
= power_supply_register(&wacom
->hdev
->dev
,
1061 if (IS_ERR(wacom
->ac
)) {
1062 power_supply_unregister(wacom
->battery
);
1063 return PTR_ERR(wacom
->ac
);
1066 power_supply_powers(wacom
->ac
, &wacom
->hdev
->dev
);
1072 static void wacom_destroy_battery(struct wacom
*wacom
)
1074 if (wacom
->battery
) {
1075 power_supply_unregister(wacom
->battery
);
1076 wacom
->battery
= NULL
;
1077 power_supply_unregister(wacom
->ac
);
1082 static ssize_t
wacom_show_speed(struct device
*dev
,
1083 struct device_attribute
1086 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1087 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1089 return snprintf(buf
, PAGE_SIZE
, "%i\n", wacom
->wacom_wac
.bt_high_speed
);
1092 static ssize_t
wacom_store_speed(struct device
*dev
,
1093 struct device_attribute
*attr
,
1094 const char *buf
, size_t count
)
1096 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1097 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1100 if (kstrtou8(buf
, 0, &new_speed
))
1103 if (new_speed
!= 0 && new_speed
!= 1)
1106 wacom_bt_query_tablet_data(hdev
, new_speed
, &wacom
->wacom_wac
.features
);
1111 static DEVICE_ATTR(speed
, DEV_ATTR_RW_PERM
,
1112 wacom_show_speed
, wacom_store_speed
);
1114 static struct input_dev
*wacom_allocate_input(struct wacom
*wacom
)
1116 struct input_dev
*input_dev
;
1117 struct hid_device
*hdev
= wacom
->hdev
;
1118 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1120 input_dev
= input_allocate_device();
1124 input_dev
->name
= wacom_wac
->name
;
1125 input_dev
->phys
= hdev
->phys
;
1126 input_dev
->dev
.parent
= &hdev
->dev
;
1127 input_dev
->open
= wacom_open
;
1128 input_dev
->close
= wacom_close
;
1129 input_dev
->uniq
= hdev
->uniq
;
1130 input_dev
->id
.bustype
= hdev
->bus
;
1131 input_dev
->id
.vendor
= hdev
->vendor
;
1132 input_dev
->id
.product
= wacom_wac
->pid
? wacom_wac
->pid
: hdev
->product
;
1133 input_dev
->id
.version
= hdev
->version
;
1134 input_set_drvdata(input_dev
, wacom
);
1139 static void wacom_free_inputs(struct wacom
*wacom
)
1141 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1143 if (wacom_wac
->input
)
1144 input_free_device(wacom_wac
->input
);
1145 if (wacom_wac
->pad_input
)
1146 input_free_device(wacom_wac
->pad_input
);
1147 wacom_wac
->input
= NULL
;
1148 wacom_wac
->pad_input
= NULL
;
1151 static int wacom_allocate_inputs(struct wacom
*wacom
)
1153 struct input_dev
*input_dev
, *pad_input_dev
;
1154 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1156 input_dev
= wacom_allocate_input(wacom
);
1157 pad_input_dev
= wacom_allocate_input(wacom
);
1158 if (!input_dev
|| !pad_input_dev
) {
1159 wacom_free_inputs(wacom
);
1163 wacom_wac
->input
= input_dev
;
1164 wacom_wac
->pad_input
= pad_input_dev
;
1165 wacom_wac
->pad_input
->name
= wacom_wac
->pad_name
;
1170 static void wacom_clean_inputs(struct wacom
*wacom
)
1172 if (wacom
->wacom_wac
.input
) {
1173 if (wacom
->wacom_wac
.input_registered
)
1174 input_unregister_device(wacom
->wacom_wac
.input
);
1176 input_free_device(wacom
->wacom_wac
.input
);
1178 if (wacom
->wacom_wac
.pad_input
) {
1179 if (wacom
->wacom_wac
.pad_registered
)
1180 input_unregister_device(wacom
->wacom_wac
.pad_input
);
1182 input_free_device(wacom
->wacom_wac
.pad_input
);
1184 wacom
->wacom_wac
.input
= NULL
;
1185 wacom
->wacom_wac
.pad_input
= NULL
;
1186 wacom_destroy_leds(wacom
);
1189 static int wacom_register_inputs(struct wacom
*wacom
)
1191 struct input_dev
*input_dev
, *pad_input_dev
;
1192 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1195 input_dev
= wacom_wac
->input
;
1196 pad_input_dev
= wacom_wac
->pad_input
;
1198 if (!input_dev
|| !pad_input_dev
)
1201 error
= wacom_setup_pentouch_input_capabilities(input_dev
, wacom_wac
);
1203 error
= input_register_device(input_dev
);
1206 wacom_wac
->input_registered
= true;
1209 error
= wacom_setup_pad_input_capabilities(pad_input_dev
, wacom_wac
);
1211 /* no pad in use on this interface */
1212 input_free_device(pad_input_dev
);
1213 wacom_wac
->pad_input
= NULL
;
1214 pad_input_dev
= NULL
;
1216 error
= input_register_device(pad_input_dev
);
1218 goto fail_register_pad_input
;
1219 wacom_wac
->pad_registered
= true;
1221 error
= wacom_initialize_leds(wacom
);
1229 input_unregister_device(pad_input_dev
);
1230 pad_input_dev
= NULL
;
1231 wacom_wac
->pad_registered
= false;
1232 fail_register_pad_input
:
1233 input_unregister_device(input_dev
);
1234 wacom_wac
->input
= NULL
;
1235 wacom_wac
->input_registered
= false;
1239 static void wacom_wireless_work(struct work_struct
*work
)
1241 struct wacom
*wacom
= container_of(work
, struct wacom
, work
);
1242 struct usb_device
*usbdev
= wacom
->usbdev
;
1243 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1244 struct hid_device
*hdev1
, *hdev2
;
1245 struct wacom
*wacom1
, *wacom2
;
1246 struct wacom_wac
*wacom_wac1
, *wacom_wac2
;
1250 * Regardless if this is a disconnect or a new tablet,
1251 * remove any existing input and battery devices.
1254 wacom_destroy_battery(wacom
);
1256 /* Stylus interface */
1257 hdev1
= usb_get_intfdata(usbdev
->config
->interface
[1]);
1258 wacom1
= hid_get_drvdata(hdev1
);
1259 wacom_wac1
= &(wacom1
->wacom_wac
);
1260 wacom_clean_inputs(wacom1
);
1262 /* Touch interface */
1263 hdev2
= usb_get_intfdata(usbdev
->config
->interface
[2]);
1264 wacom2
= hid_get_drvdata(hdev2
);
1265 wacom_wac2
= &(wacom2
->wacom_wac
);
1266 wacom_clean_inputs(wacom2
);
1268 if (wacom_wac
->pid
== 0) {
1269 hid_info(wacom
->hdev
, "wireless tablet disconnected\n");
1270 wacom_wac1
->shared
->type
= 0;
1272 const struct hid_device_id
*id
= wacom_ids
;
1274 hid_info(wacom
->hdev
, "wireless tablet connected with PID %x\n",
1278 if (id
->vendor
== USB_VENDOR_ID_WACOM
&&
1279 id
->product
== wacom_wac
->pid
)
1285 hid_info(wacom
->hdev
, "ignoring unknown PID.\n");
1289 /* Stylus interface */
1290 wacom_wac1
->features
=
1291 *((struct wacom_features
*)id
->driver_data
);
1292 wacom_wac1
->features
.device_type
= BTN_TOOL_PEN
;
1293 snprintf(wacom_wac1
->name
, WACOM_NAME_MAX
, "%s (WL) Pen",
1294 wacom_wac1
->features
.name
);
1295 snprintf(wacom_wac1
->pad_name
, WACOM_NAME_MAX
, "%s (WL) Pad",
1296 wacom_wac1
->features
.name
);
1297 wacom_wac1
->shared
->touch_max
= wacom_wac1
->features
.touch_max
;
1298 wacom_wac1
->shared
->type
= wacom_wac1
->features
.type
;
1299 wacom_wac1
->pid
= wacom_wac
->pid
;
1300 error
= wacom_allocate_inputs(wacom1
) ||
1301 wacom_register_inputs(wacom1
);
1305 /* Touch interface */
1306 if (wacom_wac1
->features
.touch_max
||
1307 wacom_wac1
->features
.type
== INTUOSHT
) {
1308 wacom_wac2
->features
=
1309 *((struct wacom_features
*)id
->driver_data
);
1310 wacom_wac2
->features
.pktlen
= WACOM_PKGLEN_BBTOUCH3
;
1311 wacom_wac2
->features
.device_type
= BTN_TOOL_FINGER
;
1312 wacom_wac2
->features
.x_max
= wacom_wac2
->features
.y_max
= 4096;
1313 if (wacom_wac2
->features
.touch_max
)
1314 snprintf(wacom_wac2
->name
, WACOM_NAME_MAX
,
1315 "%s (WL) Finger",wacom_wac2
->features
.name
);
1317 snprintf(wacom_wac2
->name
, WACOM_NAME_MAX
,
1318 "%s (WL) Pad",wacom_wac2
->features
.name
);
1319 snprintf(wacom_wac2
->pad_name
, WACOM_NAME_MAX
,
1320 "%s (WL) Pad", wacom_wac2
->features
.name
);
1321 wacom_wac2
->pid
= wacom_wac
->pid
;
1322 error
= wacom_allocate_inputs(wacom2
) ||
1323 wacom_register_inputs(wacom2
);
1327 if (wacom_wac1
->features
.type
== INTUOSHT
&&
1328 wacom_wac1
->features
.touch_max
)
1329 wacom_wac
->shared
->touch_input
= wacom_wac2
->input
;
1332 error
= wacom_initialize_battery(wacom
);
1340 wacom_clean_inputs(wacom1
);
1341 wacom_clean_inputs(wacom2
);
1345 void wacom_battery_work(struct work_struct
*work
)
1347 struct wacom
*wacom
= container_of(work
, struct wacom
, work
);
1349 if ((wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1351 wacom_initialize_battery(wacom
);
1353 else if (!(wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1355 wacom_destroy_battery(wacom
);
1360 * Not all devices report physical dimensions from HID.
1361 * Compute the default from hardcoded logical dimension
1362 * and resolution before driver overwrites them.
1364 static void wacom_set_default_phy(struct wacom_features
*features
)
1366 if (features
->x_resolution
) {
1367 features
->x_phy
= (features
->x_max
* 100) /
1368 features
->x_resolution
;
1369 features
->y_phy
= (features
->y_max
* 100) /
1370 features
->y_resolution
;
1374 static void wacom_calculate_res(struct wacom_features
*features
)
1376 /* set unit to "100th of a mm" for devices not reported by HID */
1377 if (!features
->unit
) {
1378 features
->unit
= 0x11;
1379 features
->unitExpo
= -3;
1382 features
->x_resolution
= wacom_calc_hid_res(features
->x_max
,
1385 features
->unitExpo
);
1386 features
->y_resolution
= wacom_calc_hid_res(features
->y_max
,
1389 features
->unitExpo
);
1392 static size_t wacom_compute_pktlen(struct hid_device
*hdev
)
1394 struct hid_report_enum
*report_enum
;
1395 struct hid_report
*report
;
1398 report_enum
= hdev
->report_enum
+ HID_INPUT_REPORT
;
1400 list_for_each_entry(report
, &report_enum
->report_list
, list
) {
1401 size_t report_size
= hid_report_len(report
);
1402 if (report_size
> size
)
1409 static void wacom_update_name(struct wacom
*wacom
)
1411 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1412 struct wacom_features
*features
= &wacom_wac
->features
;
1414 /* Generic devices name unspecified */
1415 if ((features
->type
== HID_GENERIC
) && !strcmp("Wacom HID", features
->name
)) {
1416 if (strstr(wacom
->hdev
->name
, "Wacom") ||
1417 strstr(wacom
->hdev
->name
, "wacom") ||
1418 strstr(wacom
->hdev
->name
, "WACOM")) {
1419 /* name is in HID descriptor, use it */
1420 strlcpy(wacom_wac
->name
, wacom
->hdev
->name
,
1421 sizeof(wacom_wac
->name
));
1423 /* strip out excess whitespaces */
1425 char *gap
= strstr(wacom_wac
->name
, " ");
1428 /* shift everything including the terminator */
1429 memmove(gap
, gap
+1, strlen(gap
));
1431 /* get rid of trailing whitespace */
1432 if (wacom_wac
->name
[strlen(wacom_wac
->name
)-1] == ' ')
1433 wacom_wac
->name
[strlen(wacom_wac
->name
)-1] = '\0';
1435 /* no meaningful name retrieved. use product ID */
1436 snprintf(wacom_wac
->name
, sizeof(wacom_wac
->name
),
1437 "%s %X", features
->name
, wacom
->hdev
->product
);
1440 strlcpy(wacom_wac
->name
, features
->name
, sizeof(wacom_wac
->name
));
1443 /* Append the device type to the name */
1444 snprintf(wacom_wac
->pad_name
, sizeof(wacom_wac
->pad_name
),
1445 "%s Pad", wacom_wac
->name
);
1447 if (features
->device_type
== BTN_TOOL_PEN
) {
1448 strlcat(wacom_wac
->name
, " Pen", WACOM_NAME_MAX
);
1450 else if (features
->device_type
== BTN_TOOL_FINGER
) {
1451 if (features
->touch_max
)
1452 strlcat(wacom_wac
->name
, " Finger", WACOM_NAME_MAX
);
1454 strlcat(wacom_wac
->name
, " Pad", WACOM_NAME_MAX
);
1458 static int wacom_probe(struct hid_device
*hdev
,
1459 const struct hid_device_id
*id
)
1461 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
1462 struct usb_device
*dev
= interface_to_usbdev(intf
);
1463 struct wacom
*wacom
;
1464 struct wacom_wac
*wacom_wac
;
1465 struct wacom_features
*features
;
1467 unsigned int connect_mask
= HID_CONNECT_HIDRAW
;
1469 if (!id
->driver_data
)
1472 hdev
->quirks
|= HID_QUIRK_NO_INIT_REPORTS
;
1474 /* hid-core sets this quirk for the boot interface */
1475 hdev
->quirks
&= ~HID_QUIRK_NOGET
;
1477 wacom
= kzalloc(sizeof(struct wacom
), GFP_KERNEL
);
1481 hid_set_drvdata(hdev
, wacom
);
1484 /* ask for the report descriptor to be loaded by HID */
1485 error
= hid_parse(hdev
);
1487 hid_err(hdev
, "parse failed\n");
1491 wacom_wac
= &wacom
->wacom_wac
;
1492 wacom_wac
->features
= *((struct wacom_features
*)id
->driver_data
);
1493 features
= &wacom_wac
->features
;
1494 features
->pktlen
= wacom_compute_pktlen(hdev
);
1495 if (features
->pktlen
> WACOM_PKGLEN_MAX
) {
1500 if (features
->check_for_hid_type
&& features
->hid_type
!= hdev
->type
) {
1505 wacom
->usbdev
= dev
;
1507 mutex_init(&wacom
->lock
);
1508 INIT_WORK(&wacom
->work
, wacom_wireless_work
);
1510 if (!(features
->quirks
& WACOM_QUIRK_NO_INPUT
)) {
1511 error
= wacom_allocate_inputs(wacom
);
1513 goto fail_allocate_inputs
;
1517 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
1518 * into debug mode for the touch part.
1519 * We ignore the other interfaces.
1521 if (features
->type
== BAMBOO_PAD
) {
1522 if (features
->pktlen
== WACOM_PKGLEN_PENABLED
) {
1523 features
->type
= HID_GENERIC
;
1524 } else if ((features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH
) &&
1525 (features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH_USB
)) {
1527 goto fail_shared_data
;
1531 /* set the default size in case we do not get them from hid */
1532 wacom_set_default_phy(features
);
1534 /* Retrieve the physical and logical size for touch devices */
1535 wacom_retrieve_hid_descriptor(hdev
, features
);
1536 wacom_setup_device_quirks(wacom
);
1538 if (!features
->device_type
&& features
->type
!= WIRELESS
) {
1539 error
= features
->type
== HID_GENERIC
? -ENODEV
: 0;
1541 dev_warn(&hdev
->dev
, "Unknown device_type for '%s'. %s.",
1543 error
? "Ignoring" : "Assuming pen");
1546 goto fail_shared_data
;
1548 features
->device_type
= BTN_TOOL_PEN
;
1551 wacom_calculate_res(features
);
1553 wacom_update_name(wacom
);
1555 error
= wacom_add_shared_data(hdev
);
1557 goto fail_shared_data
;
1559 if (!(features
->quirks
& WACOM_QUIRK_MONITOR
) &&
1560 (features
->quirks
& WACOM_QUIRK_BATTERY
)) {
1561 error
= wacom_initialize_battery(wacom
);
1566 if (!(features
->quirks
& WACOM_QUIRK_NO_INPUT
)) {
1567 error
= wacom_register_inputs(wacom
);
1569 goto fail_register_inputs
;
1572 if (hdev
->bus
== BUS_BLUETOOTH
) {
1573 error
= device_create_file(&hdev
->dev
, &dev_attr_speed
);
1576 "can't create sysfs speed attribute err: %d\n",
1580 if (features
->type
== HID_GENERIC
)
1581 connect_mask
|= HID_CONNECT_DRIVER
;
1583 /* Regular HID work starts now */
1584 error
= hid_hw_start(hdev
, connect_mask
);
1586 hid_err(hdev
, "hw start failed\n");
1590 /* Note that if query fails it is not a hard failure */
1591 wacom_query_tablet_data(hdev
, features
);
1593 if (features
->quirks
& WACOM_QUIRK_MONITOR
)
1594 error
= hid_hw_open(hdev
);
1596 if (wacom_wac
->features
.type
== INTUOSHT
&& wacom_wac
->features
.touch_max
) {
1597 if (wacom_wac
->features
.device_type
== BTN_TOOL_FINGER
)
1598 wacom_wac
->shared
->touch_input
= wacom_wac
->input
;
1604 if (hdev
->bus
== BUS_BLUETOOTH
)
1605 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
1606 fail_register_inputs
:
1607 wacom_clean_inputs(wacom
);
1608 wacom_destroy_battery(wacom
);
1610 wacom_remove_shared_data(wacom
);
1612 wacom_clean_inputs(wacom
);
1613 fail_allocate_inputs
:
1618 hid_set_drvdata(hdev
, NULL
);
1622 static void wacom_remove(struct hid_device
*hdev
)
1624 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1628 cancel_work_sync(&wacom
->work
);
1629 wacom_clean_inputs(wacom
);
1630 if (hdev
->bus
== BUS_BLUETOOTH
)
1631 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
1632 wacom_destroy_battery(wacom
);
1633 wacom_remove_shared_data(wacom
);
1635 hid_set_drvdata(hdev
, NULL
);
1640 static int wacom_resume(struct hid_device
*hdev
)
1642 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1643 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
1645 mutex_lock(&wacom
->lock
);
1647 /* switch to wacom mode first */
1648 wacom_query_tablet_data(hdev
, features
);
1649 wacom_led_control(wacom
);
1651 mutex_unlock(&wacom
->lock
);
1656 static int wacom_reset_resume(struct hid_device
*hdev
)
1658 return wacom_resume(hdev
);
1660 #endif /* CONFIG_PM */
1662 static struct hid_driver wacom_driver
= {
1664 .id_table
= wacom_ids
,
1665 .probe
= wacom_probe
,
1666 .remove
= wacom_remove
,
1667 .event
= wacom_wac_event
,
1668 .report
= wacom_wac_report
,
1670 .resume
= wacom_resume
,
1671 .reset_resume
= wacom_reset_resume
,
1673 .raw_event
= wacom_raw_event
,
1675 module_hid_driver(wacom_driver
);
1677 MODULE_VERSION(DRIVER_VERSION
);
1678 MODULE_AUTHOR(DRIVER_AUTHOR
);
1679 MODULE_DESCRIPTION(DRIVER_DESC
);
1680 MODULE_LICENSE(DRIVER_LICENSE
);