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
== -EPIPE
) && --retries
);
43 static int wacom_set_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
44 size_t size
, unsigned int retries
)
49 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
51 } while ((retval
== -ETIMEDOUT
|| retval
== -EPIPE
) && --retries
);
56 static int wacom_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
57 u8
*raw_data
, int size
)
59 struct wacom
*wacom
= hid_get_drvdata(hdev
);
61 if (size
> WACOM_PKGLEN_MAX
)
64 memcpy(wacom
->wacom_wac
.data
, raw_data
, size
);
66 wacom_wac_irq(&wacom
->wacom_wac
, size
);
71 static int wacom_open(struct input_dev
*dev
)
73 struct wacom
*wacom
= input_get_drvdata(dev
);
75 return hid_hw_open(wacom
->hdev
);
78 static void wacom_close(struct input_dev
*dev
)
80 struct wacom
*wacom
= input_get_drvdata(dev
);
82 hid_hw_close(wacom
->hdev
);
86 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
88 static int wacom_calc_hid_res(int logical_extents
, int physical_extents
,
89 unsigned unit
, int exponent
)
91 struct hid_field field
= {
92 .logical_maximum
= logical_extents
,
93 .physical_maximum
= physical_extents
,
95 .unit_exponent
= exponent
,
98 return hidinput_calc_abs_res(&field
, ABS_X
);
101 static void wacom_feature_mapping(struct hid_device
*hdev
,
102 struct hid_field
*field
, struct hid_usage
*usage
)
104 struct wacom
*wacom
= hid_get_drvdata(hdev
);
105 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
106 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
110 switch (usage
->hid
) {
111 case HID_DG_CONTACTMAX
:
112 /* leave touch_max as is if predefined */
113 if (!features
->touch_max
) {
115 data
= kzalloc(2, GFP_KERNEL
);
118 data
[0] = field
->report
->id
;
119 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
122 features
->touch_max
= data
[1];
126 case HID_DG_INPUTMODE
:
127 /* Ignore if value index is out of bounds. */
128 if (usage
->usage_index
>= field
->report_count
) {
129 dev_err(&hdev
->dev
, "HID_DG_INPUTMODE out of range\n");
133 hid_data
->inputmode
= field
->report
->id
;
134 hid_data
->inputmode_index
= usage
->usage_index
;
140 * Interface Descriptor of wacom devices can be incomplete and
141 * inconsistent so wacom_features table is used to store stylus
142 * device's packet lengths, various maximum values, and tablet
143 * resolution based on product ID's.
145 * For devices that contain 2 interfaces, wacom_features table is
146 * inaccurate for the touch interface. Since the Interface Descriptor
147 * for touch interfaces has pretty complete data, this function exists
148 * to query tablet for this missing information instead of hard coding in
149 * an additional table.
151 * A typical Interface Descriptor for a stylus will contain a
152 * boot mouse application collection that is not of interest and this
153 * function will ignore it.
155 * It also contains a digitizer application collection that also is not
156 * of interest since any information it contains would be duplicate
157 * of what is in wacom_features. Usually it defines a report of an array
158 * of bytes that could be used as max length of the stylus packet returned.
159 * If it happens to define a Digitizer-Stylus Physical Collection then
160 * the X and Y logical values contain valid data but it is ignored.
162 * A typical Interface Descriptor for a touch interface will contain a
163 * Digitizer-Finger Physical Collection which will define both logical
164 * X/Y maximum as well as the physical size of tablet. Since touch
165 * interfaces haven't supported pressure or distance, this is enough
166 * information to override invalid values in the wacom_features table.
168 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
169 * data. We deal with them after returning from this function.
171 static void wacom_usage_mapping(struct hid_device
*hdev
,
172 struct hid_field
*field
, struct hid_usage
*usage
)
174 struct wacom
*wacom
= hid_get_drvdata(hdev
);
175 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
176 bool finger
= WACOM_FINGER_FIELD(field
);
177 bool pen
= WACOM_PEN_FIELD(field
);
180 * Requiring Stylus Usage will ignore boot mouse
181 * X/Y values and some cases of invalid Digitizer X/Y
182 * values commonly reported.
185 features
->device_type
= BTN_TOOL_PEN
;
187 features
->device_type
= BTN_TOOL_FINGER
;
192 * Bamboo models do not support HID_DG_CONTACTMAX.
193 * And, Bamboo Pen only descriptor contains touch.
195 if (features
->type
!= BAMBOO_PT
) {
196 /* ISDv4 touch devices at least supports one touch point */
197 if (finger
&& !features
->touch_max
)
198 features
->touch_max
= 1;
201 switch (usage
->hid
) {
203 features
->x_max
= field
->logical_maximum
;
205 features
->x_phy
= field
->physical_maximum
;
206 if (features
->type
!= BAMBOO_PT
) {
207 features
->unit
= field
->unit
;
208 features
->unitExpo
= field
->unit_exponent
;
213 features
->y_max
= field
->logical_maximum
;
215 features
->y_phy
= field
->physical_maximum
;
216 if (features
->type
!= BAMBOO_PT
) {
217 features
->unit
= field
->unit
;
218 features
->unitExpo
= field
->unit_exponent
;
222 case HID_DG_TIPPRESSURE
:
224 features
->pressure_max
= field
->logical_maximum
;
228 if (features
->type
== HID_GENERIC
)
229 wacom_wac_usage_mapping(hdev
, field
, usage
);
232 static void wacom_post_parse_hid(struct hid_device
*hdev
,
233 struct wacom_features
*features
)
235 struct wacom
*wacom
= hid_get_drvdata(hdev
);
236 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
238 if (features
->type
== HID_GENERIC
) {
239 /* Any last-minute generic device setup */
240 if (features
->touch_max
> 1) {
241 input_mt_init_slots(wacom_wac
->input
, wacom_wac
->features
.touch_max
,
247 static void wacom_parse_hid(struct hid_device
*hdev
,
248 struct wacom_features
*features
)
250 struct hid_report_enum
*rep_enum
;
251 struct hid_report
*hreport
;
254 /* check features first */
255 rep_enum
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
256 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
257 for (i
= 0; i
< hreport
->maxfield
; i
++) {
258 /* Ignore if report count is out of bounds. */
259 if (hreport
->field
[i
]->report_count
< 1)
262 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++) {
263 wacom_feature_mapping(hdev
, hreport
->field
[i
],
264 hreport
->field
[i
]->usage
+ j
);
269 /* now check the input usages */
270 rep_enum
= &hdev
->report_enum
[HID_INPUT_REPORT
];
271 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
273 if (!hreport
->maxfield
)
276 for (i
= 0; i
< hreport
->maxfield
; i
++)
277 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++)
278 wacom_usage_mapping(hdev
, hreport
->field
[i
],
279 hreport
->field
[i
]->usage
+ j
);
282 wacom_post_parse_hid(hdev
, features
);
285 static int wacom_hid_set_device_mode(struct hid_device
*hdev
)
287 struct wacom
*wacom
= hid_get_drvdata(hdev
);
288 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
289 struct hid_report
*r
;
290 struct hid_report_enum
*re
;
292 if (hid_data
->inputmode
< 0)
295 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
296 r
= re
->report_id_hash
[hid_data
->inputmode
];
298 r
->field
[0]->value
[hid_data
->inputmode_index
] = 2;
299 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
304 static int wacom_set_device_mode(struct hid_device
*hdev
, int report_id
,
305 int length
, int mode
)
307 unsigned char *rep_data
;
308 int error
= -ENOMEM
, limit
= 0;
310 rep_data
= kzalloc(length
, GFP_KERNEL
);
315 rep_data
[0] = report_id
;
318 error
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
,
321 error
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
322 rep_data
, length
, 1);
323 } while ((error
< 0 || rep_data
[1] != mode
) && limit
++ < WAC_MSG_RETRIES
);
327 return error
< 0 ? error
: 0;
330 static int wacom_bt_query_tablet_data(struct hid_device
*hdev
, u8 speed
,
331 struct wacom_features
*features
)
333 struct wacom
*wacom
= hid_get_drvdata(hdev
);
337 switch (features
->type
) {
341 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
345 rep_data
[0] = speed
== 0 ? 0x05 : 0x06;
348 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
,
352 wacom
->wacom_wac
.bt_high_speed
= speed
;
358 * Note that if the raw queries fail, it's not a hard failure
359 * and it is safe to continue
361 hid_warn(hdev
, "failed to poke device, command %d, err %d\n",
366 wacom
->wacom_wac
.bt_features
&= ~0x20;
368 wacom
->wacom_wac
.bt_features
|= 0x20;
371 rep_data
[1] = wacom
->wacom_wac
.bt_features
;
373 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
376 wacom
->wacom_wac
.bt_high_speed
= speed
;
384 * Switch the tablet into its most-capable mode. Wacom tablets are
385 * typically configured to power-up in a mode which sends mouse-like
386 * reports to the OS. To get absolute position, pressure data, etc.
387 * from the tablet, it is necessary to switch the tablet out of this
388 * mode and into one which sends the full range of tablet data.
390 static int wacom_query_tablet_data(struct hid_device
*hdev
,
391 struct wacom_features
*features
)
393 if (hdev
->bus
== BUS_BLUETOOTH
)
394 return wacom_bt_query_tablet_data(hdev
, 1, features
);
396 if (features
->type
== HID_GENERIC
)
397 return wacom_hid_set_device_mode(hdev
);
399 if (features
->device_type
== BTN_TOOL_FINGER
) {
400 if (features
->type
> TABLETPC
) {
401 /* MT Tablet PC touch */
402 return wacom_set_device_mode(hdev
, 3, 4, 4);
404 else if (features
->type
== WACOM_24HDT
|| features
->type
== CINTIQ_HYBRID
) {
405 return wacom_set_device_mode(hdev
, 18, 3, 2);
407 else if (features
->type
== WACOM_27QHDT
) {
408 return wacom_set_device_mode(hdev
, 131, 3, 2);
410 else if (features
->type
== BAMBOO_PAD
) {
411 return wacom_set_device_mode(hdev
, 2, 2, 2);
413 } else if (features
->device_type
== BTN_TOOL_PEN
) {
414 if (features
->type
<= BAMBOO_PT
&& features
->type
!= WIRELESS
) {
415 return wacom_set_device_mode(hdev
, 2, 2, 2);
422 static void wacom_retrieve_hid_descriptor(struct hid_device
*hdev
,
423 struct wacom_features
*features
)
425 struct wacom
*wacom
= hid_get_drvdata(hdev
);
426 struct usb_interface
*intf
= wacom
->intf
;
428 /* default features */
429 features
->x_fuzz
= 4;
430 features
->y_fuzz
= 4;
431 features
->pressure_fuzz
= 0;
432 features
->distance_fuzz
= 0;
435 * The wireless device HID is basic and layout conflicts with
436 * other tablets (monitor and touch interface can look like pen).
437 * Skip the query for this type and modify defaults based on
440 if (features
->type
== WIRELESS
) {
441 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 0) {
442 features
->device_type
= 0;
443 } else if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 2) {
444 features
->device_type
= BTN_TOOL_FINGER
;
445 features
->pktlen
= WACOM_PKGLEN_BBTOUCH3
;
449 wacom_parse_hid(hdev
, features
);
452 struct wacom_hdev_data
{
453 struct list_head list
;
455 struct hid_device
*dev
;
456 struct wacom_shared shared
;
459 static LIST_HEAD(wacom_udev_list
);
460 static DEFINE_MUTEX(wacom_udev_list_lock
);
462 static bool wacom_are_sibling(struct hid_device
*hdev
,
463 struct hid_device
*sibling
)
465 struct wacom
*wacom
= hid_get_drvdata(hdev
);
466 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
467 int vid
= features
->oVid
;
468 int pid
= features
->oPid
;
471 if (vid
== 0 && pid
== 0) {
476 if (vid
!= sibling
->vendor
|| pid
!= sibling
->product
)
479 /* Compare the physical path. */
480 n1
= strrchr(hdev
->phys
, '.') - hdev
->phys
;
481 n2
= strrchr(sibling
->phys
, '.') - sibling
->phys
;
482 if (n1
!= n2
|| n1
<= 0 || n2
<= 0)
485 return !strncmp(hdev
->phys
, sibling
->phys
, n1
);
488 static struct wacom_hdev_data
*wacom_get_hdev_data(struct hid_device
*hdev
)
490 struct wacom_hdev_data
*data
;
492 list_for_each_entry(data
, &wacom_udev_list
, list
) {
493 if (wacom_are_sibling(hdev
, data
->dev
)) {
494 kref_get(&data
->kref
);
502 static int wacom_add_shared_data(struct hid_device
*hdev
)
504 struct wacom
*wacom
= hid_get_drvdata(hdev
);
505 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
506 struct wacom_hdev_data
*data
;
509 mutex_lock(&wacom_udev_list_lock
);
511 data
= wacom_get_hdev_data(hdev
);
513 data
= kzalloc(sizeof(struct wacom_hdev_data
), GFP_KERNEL
);
519 kref_init(&data
->kref
);
521 list_add_tail(&data
->list
, &wacom_udev_list
);
524 wacom_wac
->shared
= &data
->shared
;
526 if (wacom_wac
->features
.device_type
== BTN_TOOL_FINGER
)
527 wacom_wac
->shared
->touch
= hdev
;
528 else if (wacom_wac
->features
.device_type
== BTN_TOOL_PEN
)
529 wacom_wac
->shared
->pen
= hdev
;
532 mutex_unlock(&wacom_udev_list_lock
);
536 static void wacom_release_shared_data(struct kref
*kref
)
538 struct wacom_hdev_data
*data
=
539 container_of(kref
, struct wacom_hdev_data
, kref
);
541 mutex_lock(&wacom_udev_list_lock
);
542 list_del(&data
->list
);
543 mutex_unlock(&wacom_udev_list_lock
);
548 static void wacom_remove_shared_data(struct wacom
*wacom
)
550 struct wacom_hdev_data
*data
;
551 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
553 if (wacom_wac
->shared
) {
554 data
= container_of(wacom_wac
->shared
, struct wacom_hdev_data
,
557 if (wacom_wac
->shared
->touch
== wacom
->hdev
)
558 wacom_wac
->shared
->touch
= NULL
;
559 else if (wacom_wac
->shared
->pen
== wacom
->hdev
)
560 wacom_wac
->shared
->pen
= NULL
;
562 kref_put(&data
->kref
, wacom_release_shared_data
);
563 wacom_wac
->shared
= NULL
;
567 static int wacom_led_control(struct wacom
*wacom
)
571 unsigned char report_id
= WAC_CMD_LED_CONTROL
;
574 if (wacom
->wacom_wac
.pid
) { /* wireless connected */
575 report_id
= WAC_CMD_WL_LED_CONTROL
;
578 buf
= kzalloc(buf_size
, GFP_KERNEL
);
582 if (wacom
->wacom_wac
.features
.type
>= INTUOS5S
&&
583 wacom
->wacom_wac
.features
.type
<= INTUOSPL
) {
585 * Touch Ring and crop mark LED luminance may take on
586 * one of four values:
587 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
589 int ring_led
= wacom
->led
.select
[0] & 0x03;
590 int ring_lum
= (((wacom
->led
.llv
& 0x60) >> 5) - 1) & 0x03;
592 unsigned char led_bits
= (crop_lum
<< 4) | (ring_lum
<< 2) | (ring_led
);
595 if (wacom
->wacom_wac
.pid
) {
596 wacom_get_report(wacom
->hdev
, HID_FEATURE_REPORT
,
597 buf
, buf_size
, WAC_CMD_RETRIES
);
604 int led
= wacom
->led
.select
[0] | 0x4;
606 if (wacom
->wacom_wac
.features
.type
== WACOM_21UX2
||
607 wacom
->wacom_wac
.features
.type
== WACOM_24HD
)
608 led
|= (wacom
->led
.select
[1] << 4) | 0x40;
612 buf
[2] = wacom
->led
.llv
;
613 buf
[3] = wacom
->led
.hlv
;
614 buf
[4] = wacom
->led
.img_lum
;
617 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, buf_size
,
624 static int wacom_led_putimage(struct wacom
*wacom
, int button_id
, u8 xfer_id
,
625 const unsigned len
, const void *img
)
629 const unsigned chunk_len
= len
/ 4; /* 4 chunks are needed to be sent */
631 buf
= kzalloc(chunk_len
+ 3 , GFP_KERNEL
);
635 /* Send 'start' command */
636 buf
[0] = WAC_CMD_ICON_START
;
638 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
644 buf
[1] = button_id
& 0x07;
645 for (i
= 0; i
< 4; i
++) {
647 memcpy(buf
+ 3, img
+ i
* chunk_len
, chunk_len
);
649 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
,
650 buf
, chunk_len
+ 3, WAC_CMD_RETRIES
);
656 buf
[0] = WAC_CMD_ICON_START
;
658 wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
666 static ssize_t
wacom_led_select_store(struct device
*dev
, int set_id
,
667 const char *buf
, size_t count
)
669 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
670 struct wacom
*wacom
= hid_get_drvdata(hdev
);
674 err
= kstrtouint(buf
, 10, &id
);
678 mutex_lock(&wacom
->lock
);
680 wacom
->led
.select
[set_id
] = id
& 0x3;
681 err
= wacom_led_control(wacom
);
683 mutex_unlock(&wacom
->lock
);
685 return err
< 0 ? err
: count
;
688 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
689 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
690 struct device_attribute *attr, const char *buf, size_t count) \
692 return wacom_led_select_store(dev, SET_ID, buf, count); \
694 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
695 struct device_attribute *attr, char *buf) \
697 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
698 struct wacom *wacom = hid_get_drvdata(hdev); \
699 return scnprintf(buf, PAGE_SIZE, "%d\n", \
700 wacom->led.select[SET_ID]); \
702 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
703 wacom_led##SET_ID##_select_show, \
704 wacom_led##SET_ID##_select_store)
706 DEVICE_LED_SELECT_ATTR(0);
707 DEVICE_LED_SELECT_ATTR(1);
709 static ssize_t
wacom_luminance_store(struct wacom
*wacom
, u8
*dest
,
710 const char *buf
, size_t count
)
715 err
= kstrtouint(buf
, 10, &value
);
719 mutex_lock(&wacom
->lock
);
721 *dest
= value
& 0x7f;
722 err
= wacom_led_control(wacom
);
724 mutex_unlock(&wacom
->lock
);
726 return err
< 0 ? err
: count
;
729 #define DEVICE_LUMINANCE_ATTR(name, field) \
730 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
731 struct device_attribute *attr, const char *buf, size_t count) \
733 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
734 struct wacom *wacom = hid_get_drvdata(hdev); \
736 return wacom_luminance_store(wacom, &wacom->led.field, \
739 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
740 struct device_attribute *attr, char *buf) \
742 struct wacom *wacom = dev_get_drvdata(dev); \
743 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
745 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
746 wacom_##name##_luminance_show, \
747 wacom_##name##_luminance_store)
749 DEVICE_LUMINANCE_ATTR(status0
, llv
);
750 DEVICE_LUMINANCE_ATTR(status1
, hlv
);
751 DEVICE_LUMINANCE_ATTR(buttons
, img_lum
);
753 static ssize_t
wacom_button_image_store(struct device
*dev
, int button_id
,
754 const char *buf
, size_t count
)
756 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
757 struct wacom
*wacom
= hid_get_drvdata(hdev
);
762 if (hdev
->bus
== BUS_BLUETOOTH
) {
764 xfer_id
= WAC_CMD_ICON_BT_XFER
;
767 xfer_id
= WAC_CMD_ICON_XFER
;
773 mutex_lock(&wacom
->lock
);
775 err
= wacom_led_putimage(wacom
, button_id
, xfer_id
, len
, buf
);
777 mutex_unlock(&wacom
->lock
);
779 return err
< 0 ? err
: count
;
782 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
783 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
784 struct device_attribute *attr, const char *buf, size_t count) \
786 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
788 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
789 NULL, wacom_btnimg##BUTTON_ID##_store)
791 DEVICE_BTNIMG_ATTR(0);
792 DEVICE_BTNIMG_ATTR(1);
793 DEVICE_BTNIMG_ATTR(2);
794 DEVICE_BTNIMG_ATTR(3);
795 DEVICE_BTNIMG_ATTR(4);
796 DEVICE_BTNIMG_ATTR(5);
797 DEVICE_BTNIMG_ATTR(6);
798 DEVICE_BTNIMG_ATTR(7);
800 static struct attribute
*cintiq_led_attrs
[] = {
801 &dev_attr_status_led0_select
.attr
,
802 &dev_attr_status_led1_select
.attr
,
806 static struct attribute_group cintiq_led_attr_group
= {
808 .attrs
= cintiq_led_attrs
,
811 static struct attribute
*intuos4_led_attrs
[] = {
812 &dev_attr_status0_luminance
.attr
,
813 &dev_attr_status1_luminance
.attr
,
814 &dev_attr_status_led0_select
.attr
,
815 &dev_attr_buttons_luminance
.attr
,
816 &dev_attr_button0_rawimg
.attr
,
817 &dev_attr_button1_rawimg
.attr
,
818 &dev_attr_button2_rawimg
.attr
,
819 &dev_attr_button3_rawimg
.attr
,
820 &dev_attr_button4_rawimg
.attr
,
821 &dev_attr_button5_rawimg
.attr
,
822 &dev_attr_button6_rawimg
.attr
,
823 &dev_attr_button7_rawimg
.attr
,
827 static struct attribute_group intuos4_led_attr_group
= {
829 .attrs
= intuos4_led_attrs
,
832 static struct attribute
*intuos5_led_attrs
[] = {
833 &dev_attr_status0_luminance
.attr
,
834 &dev_attr_status_led0_select
.attr
,
838 static struct attribute_group intuos5_led_attr_group
= {
840 .attrs
= intuos5_led_attrs
,
843 static int wacom_initialize_leds(struct wacom
*wacom
)
847 /* Initialize default values */
848 switch (wacom
->wacom_wac
.features
.type
) {
853 wacom
->led
.select
[0] = 0;
854 wacom
->led
.select
[1] = 0;
857 wacom
->led
.img_lum
= 10;
858 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
859 &intuos4_led_attr_group
);
864 wacom
->led
.select
[0] = 0;
865 wacom
->led
.select
[1] = 0;
868 wacom
->led
.img_lum
= 0;
870 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
871 &cintiq_led_attr_group
);
880 if (wacom
->wacom_wac
.features
.device_type
== BTN_TOOL_PEN
) {
881 wacom
->led
.select
[0] = 0;
882 wacom
->led
.select
[1] = 0;
885 wacom
->led
.img_lum
= 0;
887 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
888 &intuos5_led_attr_group
);
899 "cannot create sysfs group err: %d\n", error
);
902 wacom_led_control(wacom
);
903 wacom
->led_initialized
= true;
908 static void wacom_destroy_leds(struct wacom
*wacom
)
910 if (!wacom
->led_initialized
)
913 wacom
->led_initialized
= false;
915 switch (wacom
->wacom_wac
.features
.type
) {
920 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
921 &intuos4_led_attr_group
);
926 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
927 &cintiq_led_attr_group
);
936 if (wacom
->wacom_wac
.features
.device_type
== BTN_TOOL_PEN
)
937 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
938 &intuos5_led_attr_group
);
943 static enum power_supply_property wacom_battery_props
[] = {
944 POWER_SUPPLY_PROP_PRESENT
,
945 POWER_SUPPLY_PROP_STATUS
,
946 POWER_SUPPLY_PROP_SCOPE
,
947 POWER_SUPPLY_PROP_CAPACITY
950 static enum power_supply_property wacom_ac_props
[] = {
951 POWER_SUPPLY_PROP_PRESENT
,
952 POWER_SUPPLY_PROP_ONLINE
,
953 POWER_SUPPLY_PROP_SCOPE
,
956 static int wacom_battery_get_property(struct power_supply
*psy
,
957 enum power_supply_property psp
,
958 union power_supply_propval
*val
)
960 struct wacom
*wacom
= power_supply_get_drvdata(psy
);
964 case POWER_SUPPLY_PROP_PRESENT
:
965 val
->intval
= wacom
->wacom_wac
.bat_connected
;
967 case POWER_SUPPLY_PROP_SCOPE
:
968 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
970 case POWER_SUPPLY_PROP_CAPACITY
:
972 wacom
->wacom_wac
.battery_capacity
;
974 case POWER_SUPPLY_PROP_STATUS
:
975 if (wacom
->wacom_wac
.bat_charging
)
976 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
977 else if (wacom
->wacom_wac
.battery_capacity
== 100 &&
978 wacom
->wacom_wac
.ps_connected
)
979 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
980 else if (wacom
->wacom_wac
.ps_connected
)
981 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
983 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
993 static int wacom_ac_get_property(struct power_supply
*psy
,
994 enum power_supply_property psp
,
995 union power_supply_propval
*val
)
997 struct wacom
*wacom
= power_supply_get_drvdata(psy
);
1001 case POWER_SUPPLY_PROP_PRESENT
:
1003 case POWER_SUPPLY_PROP_ONLINE
:
1004 val
->intval
= wacom
->wacom_wac
.ps_connected
;
1006 case POWER_SUPPLY_PROP_SCOPE
:
1007 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
1016 static int wacom_initialize_battery(struct wacom
*wacom
)
1018 static atomic_t battery_no
= ATOMIC_INIT(0);
1019 struct power_supply_config psy_cfg
= { .drv_data
= wacom
, };
1022 if (wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) {
1023 struct power_supply_desc
*bat_desc
= &wacom
->battery_desc
;
1024 struct power_supply_desc
*ac_desc
= &wacom
->ac_desc
;
1025 n
= atomic_inc_return(&battery_no
) - 1;
1027 bat_desc
->properties
= wacom_battery_props
;
1028 bat_desc
->num_properties
= ARRAY_SIZE(wacom_battery_props
);
1029 bat_desc
->get_property
= wacom_battery_get_property
;
1030 sprintf(wacom
->wacom_wac
.bat_name
, "wacom_battery_%ld", n
);
1031 bat_desc
->name
= wacom
->wacom_wac
.bat_name
;
1032 bat_desc
->type
= POWER_SUPPLY_TYPE_BATTERY
;
1033 bat_desc
->use_for_apm
= 0;
1035 ac_desc
->properties
= wacom_ac_props
;
1036 ac_desc
->num_properties
= ARRAY_SIZE(wacom_ac_props
);
1037 ac_desc
->get_property
= wacom_ac_get_property
;
1038 sprintf(wacom
->wacom_wac
.ac_name
, "wacom_ac_%ld", n
);
1039 ac_desc
->name
= wacom
->wacom_wac
.ac_name
;
1040 ac_desc
->type
= POWER_SUPPLY_TYPE_MAINS
;
1041 ac_desc
->use_for_apm
= 0;
1043 wacom
->battery
= power_supply_register(&wacom
->hdev
->dev
,
1044 &wacom
->battery_desc
, &psy_cfg
);
1045 if (IS_ERR(wacom
->battery
))
1046 return PTR_ERR(wacom
->battery
);
1048 power_supply_powers(wacom
->battery
, &wacom
->hdev
->dev
);
1050 wacom
->ac
= power_supply_register(&wacom
->hdev
->dev
,
1053 if (IS_ERR(wacom
->ac
)) {
1054 power_supply_unregister(wacom
->battery
);
1055 return PTR_ERR(wacom
->ac
);
1058 power_supply_powers(wacom
->ac
, &wacom
->hdev
->dev
);
1064 static void wacom_destroy_battery(struct wacom
*wacom
)
1066 if (wacom
->battery
) {
1067 power_supply_unregister(wacom
->battery
);
1068 wacom
->battery
= NULL
;
1069 power_supply_unregister(wacom
->ac
);
1074 static ssize_t
wacom_show_speed(struct device
*dev
,
1075 struct device_attribute
1078 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1079 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1081 return snprintf(buf
, PAGE_SIZE
, "%i\n", wacom
->wacom_wac
.bt_high_speed
);
1084 static ssize_t
wacom_store_speed(struct device
*dev
,
1085 struct device_attribute
*attr
,
1086 const char *buf
, size_t count
)
1088 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1089 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1092 if (kstrtou8(buf
, 0, &new_speed
))
1095 if (new_speed
!= 0 && new_speed
!= 1)
1098 wacom_bt_query_tablet_data(hdev
, new_speed
, &wacom
->wacom_wac
.features
);
1103 static DEVICE_ATTR(speed
, DEV_ATTR_RW_PERM
,
1104 wacom_show_speed
, wacom_store_speed
);
1106 static struct input_dev
*wacom_allocate_input(struct wacom
*wacom
)
1108 struct input_dev
*input_dev
;
1109 struct hid_device
*hdev
= wacom
->hdev
;
1110 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1112 input_dev
= input_allocate_device();
1116 input_dev
->name
= wacom_wac
->name
;
1117 input_dev
->phys
= hdev
->phys
;
1118 input_dev
->dev
.parent
= &hdev
->dev
;
1119 input_dev
->open
= wacom_open
;
1120 input_dev
->close
= wacom_close
;
1121 input_dev
->uniq
= hdev
->uniq
;
1122 input_dev
->id
.bustype
= hdev
->bus
;
1123 input_dev
->id
.vendor
= hdev
->vendor
;
1124 input_dev
->id
.product
= wacom_wac
->pid
? wacom_wac
->pid
: hdev
->product
;
1125 input_dev
->id
.version
= hdev
->version
;
1126 input_set_drvdata(input_dev
, wacom
);
1131 static void wacom_free_inputs(struct wacom
*wacom
)
1133 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1135 if (wacom_wac
->input
)
1136 input_free_device(wacom_wac
->input
);
1137 if (wacom_wac
->pad_input
)
1138 input_free_device(wacom_wac
->pad_input
);
1139 wacom_wac
->input
= NULL
;
1140 wacom_wac
->pad_input
= NULL
;
1143 static int wacom_allocate_inputs(struct wacom
*wacom
)
1145 struct input_dev
*input_dev
, *pad_input_dev
;
1146 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1148 input_dev
= wacom_allocate_input(wacom
);
1149 pad_input_dev
= wacom_allocate_input(wacom
);
1150 if (!input_dev
|| !pad_input_dev
) {
1151 wacom_free_inputs(wacom
);
1155 wacom_wac
->input
= input_dev
;
1156 wacom_wac
->pad_input
= pad_input_dev
;
1157 wacom_wac
->pad_input
->name
= wacom_wac
->pad_name
;
1162 static void wacom_clean_inputs(struct wacom
*wacom
)
1164 if (wacom
->wacom_wac
.input
) {
1165 if (wacom
->wacom_wac
.input_registered
)
1166 input_unregister_device(wacom
->wacom_wac
.input
);
1168 input_free_device(wacom
->wacom_wac
.input
);
1170 if (wacom
->wacom_wac
.pad_input
) {
1171 if (wacom
->wacom_wac
.pad_registered
)
1172 input_unregister_device(wacom
->wacom_wac
.pad_input
);
1174 input_free_device(wacom
->wacom_wac
.pad_input
);
1176 wacom
->wacom_wac
.input
= NULL
;
1177 wacom
->wacom_wac
.pad_input
= NULL
;
1178 wacom_destroy_leds(wacom
);
1181 static int wacom_register_inputs(struct wacom
*wacom
)
1183 struct input_dev
*input_dev
, *pad_input_dev
;
1184 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1187 input_dev
= wacom_wac
->input
;
1188 pad_input_dev
= wacom_wac
->pad_input
;
1190 if (!input_dev
|| !pad_input_dev
)
1193 error
= wacom_setup_pentouch_input_capabilities(input_dev
, wacom_wac
);
1195 error
= input_register_device(input_dev
);
1198 wacom_wac
->input_registered
= true;
1201 error
= wacom_setup_pad_input_capabilities(pad_input_dev
, wacom_wac
);
1203 /* no pad in use on this interface */
1204 input_free_device(pad_input_dev
);
1205 wacom_wac
->pad_input
= NULL
;
1206 pad_input_dev
= NULL
;
1208 error
= input_register_device(pad_input_dev
);
1210 goto fail_register_pad_input
;
1211 wacom_wac
->pad_registered
= true;
1213 error
= wacom_initialize_leds(wacom
);
1221 input_unregister_device(pad_input_dev
);
1222 pad_input_dev
= NULL
;
1223 wacom_wac
->pad_registered
= false;
1224 fail_register_pad_input
:
1225 input_unregister_device(input_dev
);
1226 wacom_wac
->input
= NULL
;
1227 wacom_wac
->input_registered
= false;
1231 static void wacom_wireless_work(struct work_struct
*work
)
1233 struct wacom
*wacom
= container_of(work
, struct wacom
, work
);
1234 struct usb_device
*usbdev
= wacom
->usbdev
;
1235 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1236 struct hid_device
*hdev1
, *hdev2
;
1237 struct wacom
*wacom1
, *wacom2
;
1238 struct wacom_wac
*wacom_wac1
, *wacom_wac2
;
1242 * Regardless if this is a disconnect or a new tablet,
1243 * remove any existing input and battery devices.
1246 wacom_destroy_battery(wacom
);
1248 /* Stylus interface */
1249 hdev1
= usb_get_intfdata(usbdev
->config
->interface
[1]);
1250 wacom1
= hid_get_drvdata(hdev1
);
1251 wacom_wac1
= &(wacom1
->wacom_wac
);
1252 wacom_clean_inputs(wacom1
);
1254 /* Touch interface */
1255 hdev2
= usb_get_intfdata(usbdev
->config
->interface
[2]);
1256 wacom2
= hid_get_drvdata(hdev2
);
1257 wacom_wac2
= &(wacom2
->wacom_wac
);
1258 wacom_clean_inputs(wacom2
);
1260 if (wacom_wac
->pid
== 0) {
1261 hid_info(wacom
->hdev
, "wireless tablet disconnected\n");
1262 wacom_wac1
->shared
->type
= 0;
1264 const struct hid_device_id
*id
= wacom_ids
;
1266 hid_info(wacom
->hdev
, "wireless tablet connected with PID %x\n",
1270 if (id
->vendor
== USB_VENDOR_ID_WACOM
&&
1271 id
->product
== wacom_wac
->pid
)
1277 hid_info(wacom
->hdev
, "ignoring unknown PID.\n");
1281 /* Stylus interface */
1282 wacom_wac1
->features
=
1283 *((struct wacom_features
*)id
->driver_data
);
1284 wacom_wac1
->features
.device_type
= BTN_TOOL_PEN
;
1285 snprintf(wacom_wac1
->name
, WACOM_NAME_MAX
, "%s (WL) Pen",
1286 wacom_wac1
->features
.name
);
1287 snprintf(wacom_wac1
->pad_name
, WACOM_NAME_MAX
, "%s (WL) Pad",
1288 wacom_wac1
->features
.name
);
1289 wacom_wac1
->shared
->touch_max
= wacom_wac1
->features
.touch_max
;
1290 wacom_wac1
->shared
->type
= wacom_wac1
->features
.type
;
1291 wacom_wac1
->pid
= wacom_wac
->pid
;
1292 error
= wacom_allocate_inputs(wacom1
) ||
1293 wacom_register_inputs(wacom1
);
1297 /* Touch interface */
1298 if (wacom_wac1
->features
.touch_max
||
1299 wacom_wac1
->features
.type
== INTUOSHT
) {
1300 wacom_wac2
->features
=
1301 *((struct wacom_features
*)id
->driver_data
);
1302 wacom_wac2
->features
.pktlen
= WACOM_PKGLEN_BBTOUCH3
;
1303 wacom_wac2
->features
.device_type
= BTN_TOOL_FINGER
;
1304 wacom_wac2
->features
.x_max
= wacom_wac2
->features
.y_max
= 4096;
1305 if (wacom_wac2
->features
.touch_max
)
1306 snprintf(wacom_wac2
->name
, WACOM_NAME_MAX
,
1307 "%s (WL) Finger",wacom_wac2
->features
.name
);
1309 snprintf(wacom_wac2
->name
, WACOM_NAME_MAX
,
1310 "%s (WL) Pad",wacom_wac2
->features
.name
);
1311 snprintf(wacom_wac2
->pad_name
, WACOM_NAME_MAX
,
1312 "%s (WL) Pad", wacom_wac2
->features
.name
);
1313 wacom_wac2
->pid
= wacom_wac
->pid
;
1314 error
= wacom_allocate_inputs(wacom2
) ||
1315 wacom_register_inputs(wacom2
);
1319 if (wacom_wac1
->features
.type
== INTUOSHT
&&
1320 wacom_wac1
->features
.touch_max
)
1321 wacom_wac
->shared
->touch_input
= wacom_wac2
->input
;
1324 error
= wacom_initialize_battery(wacom
);
1332 wacom_clean_inputs(wacom1
);
1333 wacom_clean_inputs(wacom2
);
1337 void wacom_battery_work(struct work_struct
*work
)
1339 struct wacom
*wacom
= container_of(work
, struct wacom
, work
);
1341 if ((wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1343 wacom_initialize_battery(wacom
);
1345 else if (!(wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1347 wacom_destroy_battery(wacom
);
1352 * Not all devices report physical dimensions from HID.
1353 * Compute the default from hardcoded logical dimension
1354 * and resolution before driver overwrites them.
1356 static void wacom_set_default_phy(struct wacom_features
*features
)
1358 if (features
->x_resolution
) {
1359 features
->x_phy
= (features
->x_max
* 100) /
1360 features
->x_resolution
;
1361 features
->y_phy
= (features
->y_max
* 100) /
1362 features
->y_resolution
;
1366 static void wacom_calculate_res(struct wacom_features
*features
)
1368 /* set unit to "100th of a mm" for devices not reported by HID */
1369 if (!features
->unit
) {
1370 features
->unit
= 0x11;
1371 features
->unitExpo
= -3;
1374 features
->x_resolution
= wacom_calc_hid_res(features
->x_max
,
1377 features
->unitExpo
);
1378 features
->y_resolution
= wacom_calc_hid_res(features
->y_max
,
1381 features
->unitExpo
);
1384 static size_t wacom_compute_pktlen(struct hid_device
*hdev
)
1386 struct hid_report_enum
*report_enum
;
1387 struct hid_report
*report
;
1390 report_enum
= hdev
->report_enum
+ HID_INPUT_REPORT
;
1392 list_for_each_entry(report
, &report_enum
->report_list
, list
) {
1393 size_t report_size
= hid_report_len(report
);
1394 if (report_size
> size
)
1401 static void wacom_update_name(struct wacom
*wacom
)
1403 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1404 struct wacom_features
*features
= &wacom_wac
->features
;
1406 /* Generic devices name unspecified */
1407 if ((features
->type
== HID_GENERIC
) && !strcmp("Wacom HID", features
->name
)) {
1408 if (strstr(wacom
->hdev
->name
, "Wacom") ||
1409 strstr(wacom
->hdev
->name
, "wacom") ||
1410 strstr(wacom
->hdev
->name
, "WACOM")) {
1411 /* name is in HID descriptor, use it */
1412 strlcpy(wacom_wac
->name
, wacom
->hdev
->name
,
1413 sizeof(wacom_wac
->name
));
1415 /* strip out excess whitespaces */
1417 char *gap
= strstr(wacom_wac
->name
, " ");
1420 /* shift everything including the terminator */
1421 memmove(gap
, gap
+1, strlen(gap
));
1423 /* get rid of trailing whitespace */
1424 if (wacom_wac
->name
[strlen(wacom_wac
->name
)-1] == ' ')
1425 wacom_wac
->name
[strlen(wacom_wac
->name
)-1] = '\0';
1427 /* no meaningful name retrieved. use product ID */
1428 snprintf(wacom_wac
->name
, sizeof(wacom_wac
->name
),
1429 "%s %X", features
->name
, wacom
->hdev
->product
);
1432 strlcpy(wacom_wac
->name
, features
->name
, sizeof(wacom_wac
->name
));
1435 /* Append the device type to the name */
1436 snprintf(wacom_wac
->pad_name
, sizeof(wacom_wac
->pad_name
),
1437 "%s Pad", wacom_wac
->name
);
1439 if (features
->device_type
== BTN_TOOL_PEN
) {
1440 strlcat(wacom_wac
->name
, " Pen", WACOM_NAME_MAX
);
1442 else if (features
->device_type
== BTN_TOOL_FINGER
) {
1443 if (features
->touch_max
)
1444 strlcat(wacom_wac
->name
, " Finger", WACOM_NAME_MAX
);
1446 strlcat(wacom_wac
->name
, " Pad", WACOM_NAME_MAX
);
1450 static int wacom_probe(struct hid_device
*hdev
,
1451 const struct hid_device_id
*id
)
1453 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
1454 struct usb_device
*dev
= interface_to_usbdev(intf
);
1455 struct wacom
*wacom
;
1456 struct wacom_wac
*wacom_wac
;
1457 struct wacom_features
*features
;
1459 unsigned int connect_mask
= HID_CONNECT_HIDRAW
;
1461 if (!id
->driver_data
)
1464 hdev
->quirks
|= HID_QUIRK_NO_INIT_REPORTS
;
1466 /* hid-core sets this quirk for the boot interface */
1467 hdev
->quirks
&= ~HID_QUIRK_NOGET
;
1469 wacom
= kzalloc(sizeof(struct wacom
), GFP_KERNEL
);
1473 hid_set_drvdata(hdev
, wacom
);
1476 /* ask for the report descriptor to be loaded by HID */
1477 error
= hid_parse(hdev
);
1479 hid_err(hdev
, "parse failed\n");
1483 wacom_wac
= &wacom
->wacom_wac
;
1484 wacom_wac
->features
= *((struct wacom_features
*)id
->driver_data
);
1485 features
= &wacom_wac
->features
;
1486 features
->pktlen
= wacom_compute_pktlen(hdev
);
1487 if (features
->pktlen
> WACOM_PKGLEN_MAX
) {
1492 if (features
->check_for_hid_type
&& features
->hid_type
!= hdev
->type
) {
1497 wacom
->usbdev
= dev
;
1499 mutex_init(&wacom
->lock
);
1500 INIT_WORK(&wacom
->work
, wacom_wireless_work
);
1502 if (!(features
->quirks
& WACOM_QUIRK_NO_INPUT
)) {
1503 error
= wacom_allocate_inputs(wacom
);
1505 goto fail_allocate_inputs
;
1509 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
1510 * into debug mode for the touch part.
1511 * We ignore the other interfaces.
1513 if (features
->type
== BAMBOO_PAD
) {
1514 if (features
->pktlen
== WACOM_PKGLEN_PENABLED
) {
1515 features
->type
= HID_GENERIC
;
1516 } else if ((features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH
) &&
1517 (features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH_USB
)) {
1519 goto fail_shared_data
;
1523 /* set the default size in case we do not get them from hid */
1524 wacom_set_default_phy(features
);
1526 /* Retrieve the physical and logical size for touch devices */
1527 wacom_retrieve_hid_descriptor(hdev
, features
);
1528 wacom_setup_device_quirks(wacom
);
1530 if (!features
->device_type
&& features
->type
!= WIRELESS
) {
1531 error
= features
->type
== HID_GENERIC
? -ENODEV
: 0;
1533 dev_warn(&hdev
->dev
, "Unknown device_type for '%s'. %s.",
1535 error
? "Ignoring" : "Assuming pen");
1538 goto fail_shared_data
;
1540 features
->device_type
= BTN_TOOL_PEN
;
1543 wacom_calculate_res(features
);
1545 wacom_update_name(wacom
);
1547 error
= wacom_add_shared_data(hdev
);
1549 goto fail_shared_data
;
1551 if (!(features
->quirks
& WACOM_QUIRK_MONITOR
) &&
1552 (features
->quirks
& WACOM_QUIRK_BATTERY
)) {
1553 error
= wacom_initialize_battery(wacom
);
1558 if (!(features
->quirks
& WACOM_QUIRK_NO_INPUT
)) {
1559 error
= wacom_register_inputs(wacom
);
1561 goto fail_register_inputs
;
1564 if (hdev
->bus
== BUS_BLUETOOTH
) {
1565 error
= device_create_file(&hdev
->dev
, &dev_attr_speed
);
1568 "can't create sysfs speed attribute err: %d\n",
1572 if (features
->type
== HID_GENERIC
)
1573 connect_mask
|= HID_CONNECT_DRIVER
;
1575 /* Regular HID work starts now */
1576 error
= hid_hw_start(hdev
, connect_mask
);
1578 hid_err(hdev
, "hw start failed\n");
1582 /* Note that if query fails it is not a hard failure */
1583 wacom_query_tablet_data(hdev
, features
);
1585 if (features
->quirks
& WACOM_QUIRK_MONITOR
)
1586 error
= hid_hw_open(hdev
);
1588 if (wacom_wac
->features
.type
== INTUOSHT
&& wacom_wac
->features
.touch_max
) {
1589 if (wacom_wac
->features
.device_type
== BTN_TOOL_FINGER
)
1590 wacom_wac
->shared
->touch_input
= wacom_wac
->input
;
1596 if (hdev
->bus
== BUS_BLUETOOTH
)
1597 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
1598 fail_register_inputs
:
1599 wacom_clean_inputs(wacom
);
1600 wacom_destroy_battery(wacom
);
1602 wacom_remove_shared_data(wacom
);
1604 wacom_clean_inputs(wacom
);
1605 fail_allocate_inputs
:
1610 hid_set_drvdata(hdev
, NULL
);
1614 static void wacom_remove(struct hid_device
*hdev
)
1616 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1620 cancel_work_sync(&wacom
->work
);
1621 wacom_clean_inputs(wacom
);
1622 if (hdev
->bus
== BUS_BLUETOOTH
)
1623 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
1624 wacom_destroy_battery(wacom
);
1625 wacom_remove_shared_data(wacom
);
1627 hid_set_drvdata(hdev
, NULL
);
1632 static int wacom_resume(struct hid_device
*hdev
)
1634 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1635 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
1637 mutex_lock(&wacom
->lock
);
1639 /* switch to wacom mode first */
1640 wacom_query_tablet_data(hdev
, features
);
1641 wacom_led_control(wacom
);
1643 mutex_unlock(&wacom
->lock
);
1648 static int wacom_reset_resume(struct hid_device
*hdev
)
1650 return wacom_resume(hdev
);
1652 #endif /* CONFIG_PM */
1654 static struct hid_driver wacom_driver
= {
1656 .id_table
= wacom_ids
,
1657 .probe
= wacom_probe
,
1658 .remove
= wacom_remove
,
1659 .event
= wacom_wac_event
,
1660 .report
= wacom_wac_report
,
1662 .resume
= wacom_resume
,
1663 .reset_resume
= wacom_reset_resume
,
1665 .raw_event
= wacom_raw_event
,
1667 module_hid_driver(wacom_driver
);
1669 MODULE_VERSION(DRIVER_VERSION
);
1670 MODULE_AUTHOR(DRIVER_AUTHOR
);
1671 MODULE_DESCRIPTION(DRIVER_DESC
);
1672 MODULE_LICENSE(DRIVER_LICENSE
);