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
26 #define WAC_CMD_DELETE_PAIRING 0x20
27 #define WAC_CMD_UNPAIR_ALL 0xFF
28 #define WAC_REMOTE_SERIAL_MAX_STRLEN 9
30 #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
31 #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
32 #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP)
34 static int wacom_get_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
35 size_t size
, unsigned int retries
)
40 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
42 } while ((retval
== -ETIMEDOUT
|| retval
== -EAGAIN
) && --retries
);
45 hid_err(hdev
, "wacom_get_report: ran out of retries "
46 "(last error = %d)\n", retval
);
51 static int wacom_set_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
52 size_t size
, unsigned int retries
)
57 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
59 } while ((retval
== -ETIMEDOUT
|| retval
== -EAGAIN
) && --retries
);
62 hid_err(hdev
, "wacom_set_report: ran out of retries "
63 "(last error = %d)\n", retval
);
68 static int wacom_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
69 u8
*raw_data
, int size
)
71 struct wacom
*wacom
= hid_get_drvdata(hdev
);
73 if (size
> WACOM_PKGLEN_MAX
)
76 memcpy(wacom
->wacom_wac
.data
, raw_data
, size
);
78 wacom_wac_irq(&wacom
->wacom_wac
, size
);
83 static int wacom_open(struct input_dev
*dev
)
85 struct wacom
*wacom
= input_get_drvdata(dev
);
87 return hid_hw_open(wacom
->hdev
);
90 static void wacom_close(struct input_dev
*dev
)
92 struct wacom
*wacom
= input_get_drvdata(dev
);
94 hid_hw_close(wacom
->hdev
);
98 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
100 static int wacom_calc_hid_res(int logical_extents
, int physical_extents
,
101 unsigned unit
, int exponent
)
103 struct hid_field field
= {
104 .logical_maximum
= logical_extents
,
105 .physical_maximum
= physical_extents
,
107 .unit_exponent
= exponent
,
110 return hidinput_calc_abs_res(&field
, ABS_X
);
113 static void wacom_feature_mapping(struct hid_device
*hdev
,
114 struct hid_field
*field
, struct hid_usage
*usage
)
116 struct wacom
*wacom
= hid_get_drvdata(hdev
);
117 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
118 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
122 switch (usage
->hid
) {
123 case HID_DG_CONTACTMAX
:
124 /* leave touch_max as is if predefined */
125 if (!features
->touch_max
) {
127 data
= kzalloc(2, GFP_KERNEL
);
130 data
[0] = field
->report
->id
;
131 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
132 data
, 2, WAC_CMD_RETRIES
);
134 features
->touch_max
= data
[1];
136 features
->touch_max
= 16;
137 hid_warn(hdev
, "wacom_feature_mapping: "
138 "could not get HID_DG_CONTACTMAX, "
139 "defaulting to %d\n",
140 features
->touch_max
);
145 case HID_DG_INPUTMODE
:
146 /* Ignore if value index is out of bounds. */
147 if (usage
->usage_index
>= field
->report_count
) {
148 dev_err(&hdev
->dev
, "HID_DG_INPUTMODE out of range\n");
152 hid_data
->inputmode
= field
->report
->id
;
153 hid_data
->inputmode_index
= usage
->usage_index
;
159 * Interface Descriptor of wacom devices can be incomplete and
160 * inconsistent so wacom_features table is used to store stylus
161 * device's packet lengths, various maximum values, and tablet
162 * resolution based on product ID's.
164 * For devices that contain 2 interfaces, wacom_features table is
165 * inaccurate for the touch interface. Since the Interface Descriptor
166 * for touch interfaces has pretty complete data, this function exists
167 * to query tablet for this missing information instead of hard coding in
168 * an additional table.
170 * A typical Interface Descriptor for a stylus will contain a
171 * boot mouse application collection that is not of interest and this
172 * function will ignore it.
174 * It also contains a digitizer application collection that also is not
175 * of interest since any information it contains would be duplicate
176 * of what is in wacom_features. Usually it defines a report of an array
177 * of bytes that could be used as max length of the stylus packet returned.
178 * If it happens to define a Digitizer-Stylus Physical Collection then
179 * the X and Y logical values contain valid data but it is ignored.
181 * A typical Interface Descriptor for a touch interface will contain a
182 * Digitizer-Finger Physical Collection which will define both logical
183 * X/Y maximum as well as the physical size of tablet. Since touch
184 * interfaces haven't supported pressure or distance, this is enough
185 * information to override invalid values in the wacom_features table.
187 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
188 * data. We deal with them after returning from this function.
190 static void wacom_usage_mapping(struct hid_device
*hdev
,
191 struct hid_field
*field
, struct hid_usage
*usage
)
193 struct wacom
*wacom
= hid_get_drvdata(hdev
);
194 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
195 bool finger
= WACOM_FINGER_FIELD(field
);
196 bool pen
= WACOM_PEN_FIELD(field
);
199 * Requiring Stylus Usage will ignore boot mouse
200 * X/Y values and some cases of invalid Digitizer X/Y
201 * values commonly reported.
204 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
206 features
->device_type
|= WACOM_DEVICETYPE_TOUCH
;
211 * Bamboo models do not support HID_DG_CONTACTMAX.
212 * And, Bamboo Pen only descriptor contains touch.
214 if (features
->type
> BAMBOO_PT
) {
215 /* ISDv4 touch devices at least supports one touch point */
216 if (finger
&& !features
->touch_max
)
217 features
->touch_max
= 1;
220 switch (usage
->hid
) {
222 features
->x_max
= field
->logical_maximum
;
224 features
->x_phy
= field
->physical_maximum
;
225 if ((features
->type
!= BAMBOO_PT
) &&
226 (features
->type
!= BAMBOO_TOUCH
)) {
227 features
->unit
= field
->unit
;
228 features
->unitExpo
= field
->unit_exponent
;
233 features
->y_max
= field
->logical_maximum
;
235 features
->y_phy
= field
->physical_maximum
;
236 if ((features
->type
!= BAMBOO_PT
) &&
237 (features
->type
!= BAMBOO_TOUCH
)) {
238 features
->unit
= field
->unit
;
239 features
->unitExpo
= field
->unit_exponent
;
243 case HID_DG_TIPPRESSURE
:
245 features
->pressure_max
= field
->logical_maximum
;
249 if (features
->type
== HID_GENERIC
)
250 wacom_wac_usage_mapping(hdev
, field
, usage
);
253 static void wacom_post_parse_hid(struct hid_device
*hdev
,
254 struct wacom_features
*features
)
256 struct wacom
*wacom
= hid_get_drvdata(hdev
);
257 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
259 if (features
->type
== HID_GENERIC
) {
260 /* Any last-minute generic device setup */
261 if (features
->touch_max
> 1) {
262 input_mt_init_slots(wacom_wac
->touch_input
, wacom_wac
->features
.touch_max
,
268 static void wacom_parse_hid(struct hid_device
*hdev
,
269 struct wacom_features
*features
)
271 struct hid_report_enum
*rep_enum
;
272 struct hid_report
*hreport
;
275 /* check features first */
276 rep_enum
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
277 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
278 for (i
= 0; i
< hreport
->maxfield
; i
++) {
279 /* Ignore if report count is out of bounds. */
280 if (hreport
->field
[i
]->report_count
< 1)
283 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++) {
284 wacom_feature_mapping(hdev
, hreport
->field
[i
],
285 hreport
->field
[i
]->usage
+ j
);
290 /* now check the input usages */
291 rep_enum
= &hdev
->report_enum
[HID_INPUT_REPORT
];
292 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
294 if (!hreport
->maxfield
)
297 for (i
= 0; i
< hreport
->maxfield
; i
++)
298 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++)
299 wacom_usage_mapping(hdev
, hreport
->field
[i
],
300 hreport
->field
[i
]->usage
+ j
);
303 wacom_post_parse_hid(hdev
, features
);
306 static int wacom_hid_set_device_mode(struct hid_device
*hdev
)
308 struct wacom
*wacom
= hid_get_drvdata(hdev
);
309 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
310 struct hid_report
*r
;
311 struct hid_report_enum
*re
;
313 if (hid_data
->inputmode
< 0)
316 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
317 r
= re
->report_id_hash
[hid_data
->inputmode
];
319 r
->field
[0]->value
[hid_data
->inputmode_index
] = 2;
320 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
325 static int wacom_set_device_mode(struct hid_device
*hdev
, int report_id
,
326 int length
, int mode
)
328 unsigned char *rep_data
;
329 int error
= -ENOMEM
, limit
= 0;
331 rep_data
= kzalloc(length
, GFP_KERNEL
);
336 rep_data
[0] = report_id
;
339 error
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
,
342 error
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
343 rep_data
, length
, 1);
344 } while (error
>= 0 && rep_data
[1] != mode
&& limit
++ < WAC_MSG_RETRIES
);
348 return error
< 0 ? error
: 0;
351 static int wacom_bt_query_tablet_data(struct hid_device
*hdev
, u8 speed
,
352 struct wacom_features
*features
)
354 struct wacom
*wacom
= hid_get_drvdata(hdev
);
358 switch (features
->type
) {
362 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
366 rep_data
[0] = speed
== 0 ? 0x05 : 0x06;
369 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
,
373 wacom
->wacom_wac
.bt_high_speed
= speed
;
379 * Note that if the raw queries fail, it's not a hard failure
380 * and it is safe to continue
382 hid_warn(hdev
, "failed to poke device, command %d, err %d\n",
387 wacom
->wacom_wac
.bt_features
&= ~0x20;
389 wacom
->wacom_wac
.bt_features
|= 0x20;
392 rep_data
[1] = wacom
->wacom_wac
.bt_features
;
394 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
397 wacom
->wacom_wac
.bt_high_speed
= speed
;
405 * Switch the tablet into its most-capable mode. Wacom tablets are
406 * typically configured to power-up in a mode which sends mouse-like
407 * reports to the OS. To get absolute position, pressure data, etc.
408 * from the tablet, it is necessary to switch the tablet out of this
409 * mode and into one which sends the full range of tablet data.
411 static int wacom_query_tablet_data(struct hid_device
*hdev
,
412 struct wacom_features
*features
)
414 if (hdev
->bus
== BUS_BLUETOOTH
)
415 return wacom_bt_query_tablet_data(hdev
, 1, features
);
417 if (features
->type
== HID_GENERIC
)
418 return wacom_hid_set_device_mode(hdev
);
420 if (features
->device_type
& WACOM_DEVICETYPE_TOUCH
) {
421 if (features
->type
> TABLETPC
) {
422 /* MT Tablet PC touch */
423 return wacom_set_device_mode(hdev
, 3, 4, 4);
425 else if (features
->type
== WACOM_24HDT
) {
426 return wacom_set_device_mode(hdev
, 18, 3, 2);
428 else if (features
->type
== WACOM_27QHDT
) {
429 return wacom_set_device_mode(hdev
, 131, 3, 2);
431 else if (features
->type
== BAMBOO_PAD
) {
432 return wacom_set_device_mode(hdev
, 2, 2, 2);
434 } else if (features
->device_type
& WACOM_DEVICETYPE_PEN
) {
435 if (features
->type
<= BAMBOO_PT
) {
436 return wacom_set_device_mode(hdev
, 2, 2, 2);
443 static void wacom_retrieve_hid_descriptor(struct hid_device
*hdev
,
444 struct wacom_features
*features
)
446 struct wacom
*wacom
= hid_get_drvdata(hdev
);
447 struct usb_interface
*intf
= wacom
->intf
;
449 /* default features */
450 features
->x_fuzz
= 4;
451 features
->y_fuzz
= 4;
452 features
->pressure_fuzz
= 0;
453 features
->distance_fuzz
= 0;
456 * The wireless device HID is basic and layout conflicts with
457 * other tablets (monitor and touch interface can look like pen).
458 * Skip the query for this type and modify defaults based on
461 if (features
->type
== WIRELESS
) {
462 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 0)
463 features
->device_type
= WACOM_DEVICETYPE_WL_MONITOR
;
465 features
->device_type
= WACOM_DEVICETYPE_NONE
;
469 wacom_parse_hid(hdev
, features
);
472 struct wacom_hdev_data
{
473 struct list_head list
;
475 struct hid_device
*dev
;
476 struct wacom_shared shared
;
479 static LIST_HEAD(wacom_udev_list
);
480 static DEFINE_MUTEX(wacom_udev_list_lock
);
482 static bool wacom_are_sibling(struct hid_device
*hdev
,
483 struct hid_device
*sibling
)
485 struct wacom
*wacom
= hid_get_drvdata(hdev
);
486 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
487 int vid
= features
->oVid
;
488 int pid
= features
->oPid
;
491 if (vid
== 0 && pid
== 0) {
496 if (vid
!= sibling
->vendor
|| pid
!= sibling
->product
)
499 /* Compare the physical path. */
500 n1
= strrchr(hdev
->phys
, '.') - hdev
->phys
;
501 n2
= strrchr(sibling
->phys
, '.') - sibling
->phys
;
502 if (n1
!= n2
|| n1
<= 0 || n2
<= 0)
505 return !strncmp(hdev
->phys
, sibling
->phys
, n1
);
508 static struct wacom_hdev_data
*wacom_get_hdev_data(struct hid_device
*hdev
)
510 struct wacom_hdev_data
*data
;
512 list_for_each_entry(data
, &wacom_udev_list
, list
) {
513 if (wacom_are_sibling(hdev
, data
->dev
)) {
514 kref_get(&data
->kref
);
522 static int wacom_add_shared_data(struct hid_device
*hdev
)
524 struct wacom
*wacom
= hid_get_drvdata(hdev
);
525 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
526 struct wacom_hdev_data
*data
;
529 mutex_lock(&wacom_udev_list_lock
);
531 data
= wacom_get_hdev_data(hdev
);
533 data
= kzalloc(sizeof(struct wacom_hdev_data
), GFP_KERNEL
);
539 kref_init(&data
->kref
);
541 list_add_tail(&data
->list
, &wacom_udev_list
);
544 wacom_wac
->shared
= &data
->shared
;
546 if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
)
547 wacom_wac
->shared
->touch
= hdev
;
548 else if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_PEN
)
549 wacom_wac
->shared
->pen
= hdev
;
552 mutex_unlock(&wacom_udev_list_lock
);
556 static void wacom_release_shared_data(struct kref
*kref
)
558 struct wacom_hdev_data
*data
=
559 container_of(kref
, struct wacom_hdev_data
, kref
);
561 mutex_lock(&wacom_udev_list_lock
);
562 list_del(&data
->list
);
563 mutex_unlock(&wacom_udev_list_lock
);
568 static void wacom_remove_shared_data(struct wacom
*wacom
)
570 struct wacom_hdev_data
*data
;
571 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
573 if (wacom_wac
->shared
) {
574 data
= container_of(wacom_wac
->shared
, struct wacom_hdev_data
,
577 if (wacom_wac
->shared
->touch
== wacom
->hdev
)
578 wacom_wac
->shared
->touch
= NULL
;
579 else if (wacom_wac
->shared
->pen
== wacom
->hdev
)
580 wacom_wac
->shared
->pen
= NULL
;
582 kref_put(&data
->kref
, wacom_release_shared_data
);
583 wacom_wac
->shared
= NULL
;
587 static int wacom_led_control(struct wacom
*wacom
)
591 unsigned char report_id
= WAC_CMD_LED_CONTROL
;
594 if (wacom
->wacom_wac
.pid
) { /* wireless connected */
595 report_id
= WAC_CMD_WL_LED_CONTROL
;
598 buf
= kzalloc(buf_size
, GFP_KERNEL
);
602 if (wacom
->wacom_wac
.features
.type
>= INTUOS5S
&&
603 wacom
->wacom_wac
.features
.type
<= INTUOSPL
) {
605 * Touch Ring and crop mark LED luminance may take on
606 * one of four values:
607 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
609 int ring_led
= wacom
->led
.select
[0] & 0x03;
610 int ring_lum
= (((wacom
->led
.llv
& 0x60) >> 5) - 1) & 0x03;
612 unsigned char led_bits
= (crop_lum
<< 4) | (ring_lum
<< 2) | (ring_led
);
615 if (wacom
->wacom_wac
.pid
) {
616 wacom_get_report(wacom
->hdev
, HID_FEATURE_REPORT
,
617 buf
, buf_size
, WAC_CMD_RETRIES
);
624 int led
= wacom
->led
.select
[0] | 0x4;
626 if (wacom
->wacom_wac
.features
.type
== WACOM_21UX2
||
627 wacom
->wacom_wac
.features
.type
== WACOM_24HD
)
628 led
|= (wacom
->led
.select
[1] << 4) | 0x40;
632 buf
[2] = wacom
->led
.llv
;
633 buf
[3] = wacom
->led
.hlv
;
634 buf
[4] = wacom
->led
.img_lum
;
637 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, buf_size
,
644 static int wacom_led_putimage(struct wacom
*wacom
, int button_id
, u8 xfer_id
,
645 const unsigned len
, const void *img
)
649 const unsigned chunk_len
= len
/ 4; /* 4 chunks are needed to be sent */
651 buf
= kzalloc(chunk_len
+ 3 , GFP_KERNEL
);
655 /* Send 'start' command */
656 buf
[0] = WAC_CMD_ICON_START
;
658 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
664 buf
[1] = button_id
& 0x07;
665 for (i
= 0; i
< 4; i
++) {
667 memcpy(buf
+ 3, img
+ i
* chunk_len
, chunk_len
);
669 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
,
670 buf
, chunk_len
+ 3, WAC_CMD_RETRIES
);
676 buf
[0] = WAC_CMD_ICON_START
;
678 wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
686 static ssize_t
wacom_led_select_store(struct device
*dev
, int set_id
,
687 const char *buf
, size_t count
)
689 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
690 struct wacom
*wacom
= hid_get_drvdata(hdev
);
694 err
= kstrtouint(buf
, 10, &id
);
698 mutex_lock(&wacom
->lock
);
700 wacom
->led
.select
[set_id
] = id
& 0x3;
701 err
= wacom_led_control(wacom
);
703 mutex_unlock(&wacom
->lock
);
705 return err
< 0 ? err
: count
;
708 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
709 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
710 struct device_attribute *attr, const char *buf, size_t count) \
712 return wacom_led_select_store(dev, SET_ID, buf, count); \
714 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
715 struct device_attribute *attr, char *buf) \
717 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
718 struct wacom *wacom = hid_get_drvdata(hdev); \
719 return scnprintf(buf, PAGE_SIZE, "%d\n", \
720 wacom->led.select[SET_ID]); \
722 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
723 wacom_led##SET_ID##_select_show, \
724 wacom_led##SET_ID##_select_store)
726 DEVICE_LED_SELECT_ATTR(0);
727 DEVICE_LED_SELECT_ATTR(1);
729 static ssize_t
wacom_luminance_store(struct wacom
*wacom
, u8
*dest
,
730 const char *buf
, size_t count
)
735 err
= kstrtouint(buf
, 10, &value
);
739 mutex_lock(&wacom
->lock
);
741 *dest
= value
& 0x7f;
742 err
= wacom_led_control(wacom
);
744 mutex_unlock(&wacom
->lock
);
746 return err
< 0 ? err
: count
;
749 #define DEVICE_LUMINANCE_ATTR(name, field) \
750 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
751 struct device_attribute *attr, const char *buf, size_t count) \
753 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
754 struct wacom *wacom = hid_get_drvdata(hdev); \
756 return wacom_luminance_store(wacom, &wacom->led.field, \
759 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
760 struct device_attribute *attr, char *buf) \
762 struct wacom *wacom = dev_get_drvdata(dev); \
763 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
765 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
766 wacom_##name##_luminance_show, \
767 wacom_##name##_luminance_store)
769 DEVICE_LUMINANCE_ATTR(status0
, llv
);
770 DEVICE_LUMINANCE_ATTR(status1
, hlv
);
771 DEVICE_LUMINANCE_ATTR(buttons
, img_lum
);
773 static ssize_t
wacom_button_image_store(struct device
*dev
, int button_id
,
774 const char *buf
, size_t count
)
776 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
777 struct wacom
*wacom
= hid_get_drvdata(hdev
);
782 if (hdev
->bus
== BUS_BLUETOOTH
) {
784 xfer_id
= WAC_CMD_ICON_BT_XFER
;
787 xfer_id
= WAC_CMD_ICON_XFER
;
793 mutex_lock(&wacom
->lock
);
795 err
= wacom_led_putimage(wacom
, button_id
, xfer_id
, len
, buf
);
797 mutex_unlock(&wacom
->lock
);
799 return err
< 0 ? err
: count
;
802 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
803 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
804 struct device_attribute *attr, const char *buf, size_t count) \
806 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
808 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
809 NULL, wacom_btnimg##BUTTON_ID##_store)
811 DEVICE_BTNIMG_ATTR(0);
812 DEVICE_BTNIMG_ATTR(1);
813 DEVICE_BTNIMG_ATTR(2);
814 DEVICE_BTNIMG_ATTR(3);
815 DEVICE_BTNIMG_ATTR(4);
816 DEVICE_BTNIMG_ATTR(5);
817 DEVICE_BTNIMG_ATTR(6);
818 DEVICE_BTNIMG_ATTR(7);
820 static struct attribute
*cintiq_led_attrs
[] = {
821 &dev_attr_status_led0_select
.attr
,
822 &dev_attr_status_led1_select
.attr
,
826 static struct attribute_group cintiq_led_attr_group
= {
828 .attrs
= cintiq_led_attrs
,
831 static struct attribute
*intuos4_led_attrs
[] = {
832 &dev_attr_status0_luminance
.attr
,
833 &dev_attr_status1_luminance
.attr
,
834 &dev_attr_status_led0_select
.attr
,
835 &dev_attr_buttons_luminance
.attr
,
836 &dev_attr_button0_rawimg
.attr
,
837 &dev_attr_button1_rawimg
.attr
,
838 &dev_attr_button2_rawimg
.attr
,
839 &dev_attr_button3_rawimg
.attr
,
840 &dev_attr_button4_rawimg
.attr
,
841 &dev_attr_button5_rawimg
.attr
,
842 &dev_attr_button6_rawimg
.attr
,
843 &dev_attr_button7_rawimg
.attr
,
847 static struct attribute_group intuos4_led_attr_group
= {
849 .attrs
= intuos4_led_attrs
,
852 static struct attribute
*intuos5_led_attrs
[] = {
853 &dev_attr_status0_luminance
.attr
,
854 &dev_attr_status_led0_select
.attr
,
858 static struct attribute_group intuos5_led_attr_group
= {
860 .attrs
= intuos5_led_attrs
,
863 static int wacom_initialize_leds(struct wacom
*wacom
)
867 if (!(wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
))
870 /* Initialize default values */
871 switch (wacom
->wacom_wac
.features
.type
) {
876 wacom
->led
.select
[0] = 0;
877 wacom
->led
.select
[1] = 0;
880 wacom
->led
.img_lum
= 10;
881 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
882 &intuos4_led_attr_group
);
887 wacom
->led
.select
[0] = 0;
888 wacom
->led
.select
[1] = 0;
891 wacom
->led
.img_lum
= 0;
893 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
894 &cintiq_led_attr_group
);
903 wacom
->led
.select
[0] = 0;
904 wacom
->led
.select
[1] = 0;
907 wacom
->led
.img_lum
= 0;
909 error
= sysfs_create_group(&wacom
->hdev
->dev
.kobj
,
910 &intuos5_led_attr_group
);
919 "cannot create sysfs group err: %d\n", error
);
922 wacom_led_control(wacom
);
923 wacom
->led_initialized
= true;
928 static void wacom_destroy_leds(struct wacom
*wacom
)
930 if (!wacom
->led_initialized
)
933 if (!(wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
))
936 wacom
->led_initialized
= false;
938 switch (wacom
->wacom_wac
.features
.type
) {
943 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
944 &intuos4_led_attr_group
);
949 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
950 &cintiq_led_attr_group
);
959 sysfs_remove_group(&wacom
->hdev
->dev
.kobj
,
960 &intuos5_led_attr_group
);
965 static enum power_supply_property wacom_battery_props
[] = {
966 POWER_SUPPLY_PROP_PRESENT
,
967 POWER_SUPPLY_PROP_STATUS
,
968 POWER_SUPPLY_PROP_SCOPE
,
969 POWER_SUPPLY_PROP_CAPACITY
972 static enum power_supply_property wacom_ac_props
[] = {
973 POWER_SUPPLY_PROP_PRESENT
,
974 POWER_SUPPLY_PROP_ONLINE
,
975 POWER_SUPPLY_PROP_SCOPE
,
978 static int wacom_battery_get_property(struct power_supply
*psy
,
979 enum power_supply_property psp
,
980 union power_supply_propval
*val
)
982 struct wacom
*wacom
= power_supply_get_drvdata(psy
);
986 case POWER_SUPPLY_PROP_PRESENT
:
987 val
->intval
= wacom
->wacom_wac
.bat_connected
;
989 case POWER_SUPPLY_PROP_SCOPE
:
990 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
992 case POWER_SUPPLY_PROP_CAPACITY
:
994 wacom
->wacom_wac
.battery_capacity
;
996 case POWER_SUPPLY_PROP_STATUS
:
997 if (wacom
->wacom_wac
.bat_charging
)
998 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
999 else if (wacom
->wacom_wac
.battery_capacity
== 100 &&
1000 wacom
->wacom_wac
.ps_connected
)
1001 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
1002 else if (wacom
->wacom_wac
.ps_connected
)
1003 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1005 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
1015 static int wacom_ac_get_property(struct power_supply
*psy
,
1016 enum power_supply_property psp
,
1017 union power_supply_propval
*val
)
1019 struct wacom
*wacom
= power_supply_get_drvdata(psy
);
1023 case POWER_SUPPLY_PROP_PRESENT
:
1025 case POWER_SUPPLY_PROP_ONLINE
:
1026 val
->intval
= wacom
->wacom_wac
.ps_connected
;
1028 case POWER_SUPPLY_PROP_SCOPE
:
1029 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
1038 static int wacom_initialize_battery(struct wacom
*wacom
)
1040 static atomic_t battery_no
= ATOMIC_INIT(0);
1041 struct power_supply_config psy_cfg
= { .drv_data
= wacom
, };
1044 if (wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) {
1045 struct power_supply_desc
*bat_desc
= &wacom
->battery_desc
;
1046 struct power_supply_desc
*ac_desc
= &wacom
->ac_desc
;
1047 n
= atomic_inc_return(&battery_no
) - 1;
1049 bat_desc
->properties
= wacom_battery_props
;
1050 bat_desc
->num_properties
= ARRAY_SIZE(wacom_battery_props
);
1051 bat_desc
->get_property
= wacom_battery_get_property
;
1052 sprintf(wacom
->wacom_wac
.bat_name
, "wacom_battery_%ld", n
);
1053 bat_desc
->name
= wacom
->wacom_wac
.bat_name
;
1054 bat_desc
->type
= POWER_SUPPLY_TYPE_BATTERY
;
1055 bat_desc
->use_for_apm
= 0;
1057 ac_desc
->properties
= wacom_ac_props
;
1058 ac_desc
->num_properties
= ARRAY_SIZE(wacom_ac_props
);
1059 ac_desc
->get_property
= wacom_ac_get_property
;
1060 sprintf(wacom
->wacom_wac
.ac_name
, "wacom_ac_%ld", n
);
1061 ac_desc
->name
= wacom
->wacom_wac
.ac_name
;
1062 ac_desc
->type
= POWER_SUPPLY_TYPE_MAINS
;
1063 ac_desc
->use_for_apm
= 0;
1065 wacom
->battery
= power_supply_register(&wacom
->hdev
->dev
,
1066 &wacom
->battery_desc
, &psy_cfg
);
1067 if (IS_ERR(wacom
->battery
))
1068 return PTR_ERR(wacom
->battery
);
1070 power_supply_powers(wacom
->battery
, &wacom
->hdev
->dev
);
1072 wacom
->ac
= power_supply_register(&wacom
->hdev
->dev
,
1075 if (IS_ERR(wacom
->ac
)) {
1076 power_supply_unregister(wacom
->battery
);
1077 return PTR_ERR(wacom
->ac
);
1080 power_supply_powers(wacom
->ac
, &wacom
->hdev
->dev
);
1086 static void wacom_destroy_battery(struct wacom
*wacom
)
1088 if (wacom
->battery
) {
1089 power_supply_unregister(wacom
->battery
);
1090 wacom
->battery
= NULL
;
1091 power_supply_unregister(wacom
->ac
);
1096 static ssize_t
wacom_show_speed(struct device
*dev
,
1097 struct device_attribute
1100 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1101 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1103 return snprintf(buf
, PAGE_SIZE
, "%i\n", wacom
->wacom_wac
.bt_high_speed
);
1106 static ssize_t
wacom_store_speed(struct device
*dev
,
1107 struct device_attribute
*attr
,
1108 const char *buf
, size_t count
)
1110 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1111 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1114 if (kstrtou8(buf
, 0, &new_speed
))
1117 if (new_speed
!= 0 && new_speed
!= 1)
1120 wacom_bt_query_tablet_data(hdev
, new_speed
, &wacom
->wacom_wac
.features
);
1125 static DEVICE_ATTR(speed
, DEV_ATTR_RW_PERM
,
1126 wacom_show_speed
, wacom_store_speed
);
1129 static ssize_t
wacom_show_remote_mode(struct kobject
*kobj
,
1130 struct kobj_attribute
*kattr
,
1131 char *buf
, int index
)
1133 struct device
*dev
= container_of(kobj
->parent
, struct device
, kobj
);
1134 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1135 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1138 mode
= wacom
->led
.select
[index
];
1139 if (mode
>= 0 && mode
< 3)
1140 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
1142 return snprintf(buf
, PAGE_SIZE
, "%d\n", -1);
1145 #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1146 static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1147 struct kobj_attribute *kattr, char *buf) \
1149 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1151 static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1152 .attr = {.name = "remote_mode", \
1153 .mode = DEV_ATTR_RO_PERM}, \
1154 .show = wacom_show_remote##SET_ID##_mode, \
1156 static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1157 &remote##SET_ID##_mode_attr.attr, \
1160 static struct attribute_group remote##SET_ID##_serial_group = { \
1162 .attrs = remote##SET_ID##_serial_attrs, \
1165 DEVICE_EKR_ATTR_GROUP(0);
1166 DEVICE_EKR_ATTR_GROUP(1);
1167 DEVICE_EKR_ATTR_GROUP(2);
1168 DEVICE_EKR_ATTR_GROUP(3);
1169 DEVICE_EKR_ATTR_GROUP(4);
1171 int wacom_remote_create_attr_group(struct wacom
*wacom
, __u32 serial
, int index
)
1175 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1177 wacom_wac
->serial
[index
] = serial
;
1179 buf
= kzalloc(WAC_REMOTE_SERIAL_MAX_STRLEN
, GFP_KERNEL
);
1182 snprintf(buf
, WAC_REMOTE_SERIAL_MAX_STRLEN
, "%d", serial
);
1183 wacom
->remote_group
[index
].name
= buf
;
1185 error
= sysfs_create_group(wacom
->remote_dir
,
1186 &wacom
->remote_group
[index
]);
1188 hid_err(wacom
->hdev
,
1189 "cannot create sysfs group err: %d\n", error
);
1190 kobject_put(wacom
->remote_dir
);
1197 void wacom_remote_destroy_attr_group(struct wacom
*wacom
, __u32 serial
)
1199 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1205 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
1206 if (wacom_wac
->serial
[i
] == serial
) {
1207 wacom_wac
->serial
[i
] = 0;
1208 wacom
->led
.select
[i
] = WACOM_STATUS_UNKNOWN
;
1209 if (wacom
->remote_group
[i
].name
) {
1210 sysfs_remove_group(wacom
->remote_dir
,
1211 &wacom
->remote_group
[i
]);
1212 kfree(wacom
->remote_group
[i
].name
);
1213 wacom
->remote_group
[i
].name
= NULL
;
1219 static int wacom_cmd_unpair_remote(struct wacom
*wacom
, unsigned char selector
)
1221 const size_t buf_size
= 2;
1225 buf
= kzalloc(buf_size
, GFP_KERNEL
);
1229 buf
[0] = WAC_CMD_DELETE_PAIRING
;
1232 retval
= wacom_set_report(wacom
->hdev
, HID_OUTPUT_REPORT
, buf
,
1233 buf_size
, WAC_CMD_RETRIES
);
1239 static ssize_t
wacom_store_unpair_remote(struct kobject
*kobj
,
1240 struct kobj_attribute
*attr
,
1241 const char *buf
, size_t count
)
1243 unsigned char selector
= 0;
1244 struct device
*dev
= container_of(kobj
->parent
, struct device
, kobj
);
1245 struct hid_device
*hdev
= container_of(dev
, struct hid_device
, dev
);
1246 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1249 if (!strncmp(buf
, "*\n", 2)) {
1250 selector
= WAC_CMD_UNPAIR_ALL
;
1252 hid_info(wacom
->hdev
, "remote: unrecognized unpair code: %s\n",
1257 mutex_lock(&wacom
->lock
);
1259 err
= wacom_cmd_unpair_remote(wacom
, selector
);
1260 mutex_unlock(&wacom
->lock
);
1262 return err
< 0 ? err
: count
;
1265 static struct kobj_attribute unpair_remote_attr
= {
1266 .attr
= {.name
= "unpair_remote", .mode
= 0200},
1267 .store
= wacom_store_unpair_remote
,
1270 static const struct attribute
*remote_unpair_attrs
[] = {
1271 &unpair_remote_attr
.attr
,
1275 static int wacom_initialize_remote(struct wacom
*wacom
)
1278 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1281 if (wacom
->wacom_wac
.features
.type
!= REMOTE
)
1284 wacom
->remote_group
[0] = remote0_serial_group
;
1285 wacom
->remote_group
[1] = remote1_serial_group
;
1286 wacom
->remote_group
[2] = remote2_serial_group
;
1287 wacom
->remote_group
[3] = remote3_serial_group
;
1288 wacom
->remote_group
[4] = remote4_serial_group
;
1290 wacom
->remote_dir
= kobject_create_and_add("wacom_remote",
1291 &wacom
->hdev
->dev
.kobj
);
1292 if (!wacom
->remote_dir
)
1295 error
= sysfs_create_files(wacom
->remote_dir
, remote_unpair_attrs
);
1298 hid_err(wacom
->hdev
,
1299 "cannot create sysfs group err: %d\n", error
);
1303 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
1304 wacom
->led
.select
[i
] = WACOM_STATUS_UNKNOWN
;
1305 wacom_wac
->serial
[i
] = 0;
1311 static struct input_dev
*wacom_allocate_input(struct wacom
*wacom
)
1313 struct input_dev
*input_dev
;
1314 struct hid_device
*hdev
= wacom
->hdev
;
1315 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1317 input_dev
= input_allocate_device();
1321 input_dev
->name
= wacom_wac
->features
.name
;
1322 input_dev
->phys
= hdev
->phys
;
1323 input_dev
->dev
.parent
= &hdev
->dev
;
1324 input_dev
->open
= wacom_open
;
1325 input_dev
->close
= wacom_close
;
1326 input_dev
->uniq
= hdev
->uniq
;
1327 input_dev
->id
.bustype
= hdev
->bus
;
1328 input_dev
->id
.vendor
= hdev
->vendor
;
1329 input_dev
->id
.product
= wacom_wac
->pid
? wacom_wac
->pid
: hdev
->product
;
1330 input_dev
->id
.version
= hdev
->version
;
1331 input_set_drvdata(input_dev
, wacom
);
1336 static void wacom_clean_inputs(struct wacom
*wacom
)
1338 if (wacom
->wacom_wac
.pen_input
) {
1339 if (wacom
->wacom_wac
.pen_registered
)
1340 input_unregister_device(wacom
->wacom_wac
.pen_input
);
1342 input_free_device(wacom
->wacom_wac
.pen_input
);
1344 if (wacom
->wacom_wac
.touch_input
) {
1345 if (wacom
->wacom_wac
.touch_registered
)
1346 input_unregister_device(wacom
->wacom_wac
.touch_input
);
1348 input_free_device(wacom
->wacom_wac
.touch_input
);
1350 if (wacom
->wacom_wac
.pad_input
) {
1351 if (wacom
->wacom_wac
.pad_registered
)
1352 input_unregister_device(wacom
->wacom_wac
.pad_input
);
1354 input_free_device(wacom
->wacom_wac
.pad_input
);
1356 if (wacom
->remote_dir
)
1357 kobject_put(wacom
->remote_dir
);
1358 wacom
->wacom_wac
.pen_input
= NULL
;
1359 wacom
->wacom_wac
.touch_input
= NULL
;
1360 wacom
->wacom_wac
.pad_input
= NULL
;
1361 wacom_destroy_leds(wacom
);
1364 static int wacom_allocate_inputs(struct wacom
*wacom
)
1366 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1368 wacom_wac
->pen_input
= wacom_allocate_input(wacom
);
1369 wacom_wac
->touch_input
= wacom_allocate_input(wacom
);
1370 wacom_wac
->pad_input
= wacom_allocate_input(wacom
);
1371 if (!wacom_wac
->pen_input
|| !wacom_wac
->touch_input
|| !wacom_wac
->pad_input
) {
1372 wacom_clean_inputs(wacom
);
1376 wacom_wac
->pen_input
->name
= wacom_wac
->pen_name
;
1377 wacom_wac
->touch_input
->name
= wacom_wac
->touch_name
;
1378 wacom_wac
->pad_input
->name
= wacom_wac
->pad_name
;
1383 static int wacom_register_inputs(struct wacom
*wacom
)
1385 struct input_dev
*pen_input_dev
, *touch_input_dev
, *pad_input_dev
;
1386 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1389 pen_input_dev
= wacom_wac
->pen_input
;
1390 touch_input_dev
= wacom_wac
->touch_input
;
1391 pad_input_dev
= wacom_wac
->pad_input
;
1393 if (!pen_input_dev
|| !touch_input_dev
|| !pad_input_dev
)
1396 error
= wacom_setup_pen_input_capabilities(pen_input_dev
, wacom_wac
);
1398 /* no pen in use on this interface */
1399 input_free_device(pen_input_dev
);
1400 wacom_wac
->pen_input
= NULL
;
1401 pen_input_dev
= NULL
;
1403 error
= input_register_device(pen_input_dev
);
1405 goto fail_register_pen_input
;
1406 wacom_wac
->pen_registered
= true;
1409 error
= wacom_setup_touch_input_capabilities(touch_input_dev
, wacom_wac
);
1411 /* no touch in use on this interface */
1412 input_free_device(touch_input_dev
);
1413 wacom_wac
->touch_input
= NULL
;
1414 touch_input_dev
= NULL
;
1416 error
= input_register_device(touch_input_dev
);
1418 goto fail_register_touch_input
;
1419 wacom_wac
->touch_registered
= true;
1422 error
= wacom_setup_pad_input_capabilities(pad_input_dev
, wacom_wac
);
1424 /* no pad in use on this interface */
1425 input_free_device(pad_input_dev
);
1426 wacom_wac
->pad_input
= NULL
;
1427 pad_input_dev
= NULL
;
1429 error
= input_register_device(pad_input_dev
);
1431 goto fail_register_pad_input
;
1432 wacom_wac
->pad_registered
= true;
1434 error
= wacom_initialize_leds(wacom
);
1438 error
= wacom_initialize_remote(wacom
);
1446 wacom_destroy_leds(wacom
);
1448 input_unregister_device(pad_input_dev
);
1449 pad_input_dev
= NULL
;
1450 wacom_wac
->pad_registered
= false;
1451 fail_register_pad_input
:
1452 if (touch_input_dev
)
1453 input_unregister_device(touch_input_dev
);
1454 wacom_wac
->touch_input
= NULL
;
1455 wacom_wac
->touch_registered
= false;
1456 fail_register_touch_input
:
1458 input_unregister_device(pen_input_dev
);
1459 wacom_wac
->pen_input
= NULL
;
1460 wacom_wac
->pen_registered
= false;
1461 fail_register_pen_input
:
1466 * Not all devices report physical dimensions from HID.
1467 * Compute the default from hardcoded logical dimension
1468 * and resolution before driver overwrites them.
1470 static void wacom_set_default_phy(struct wacom_features
*features
)
1472 if (features
->x_resolution
) {
1473 features
->x_phy
= (features
->x_max
* 100) /
1474 features
->x_resolution
;
1475 features
->y_phy
= (features
->y_max
* 100) /
1476 features
->y_resolution
;
1480 static void wacom_calculate_res(struct wacom_features
*features
)
1482 /* set unit to "100th of a mm" for devices not reported by HID */
1483 if (!features
->unit
) {
1484 features
->unit
= 0x11;
1485 features
->unitExpo
= -3;
1488 features
->x_resolution
= wacom_calc_hid_res(features
->x_max
,
1491 features
->unitExpo
);
1492 features
->y_resolution
= wacom_calc_hid_res(features
->y_max
,
1495 features
->unitExpo
);
1498 static void wacom_wireless_work(struct work_struct
*work
)
1500 struct wacom
*wacom
= container_of(work
, struct wacom
, work
);
1501 struct usb_device
*usbdev
= wacom
->usbdev
;
1502 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1503 struct hid_device
*hdev1
, *hdev2
;
1504 struct wacom
*wacom1
, *wacom2
;
1505 struct wacom_wac
*wacom_wac1
, *wacom_wac2
;
1509 * Regardless if this is a disconnect or a new tablet,
1510 * remove any existing input and battery devices.
1513 wacom_destroy_battery(wacom
);
1515 /* Stylus interface */
1516 hdev1
= usb_get_intfdata(usbdev
->config
->interface
[1]);
1517 wacom1
= hid_get_drvdata(hdev1
);
1518 wacom_wac1
= &(wacom1
->wacom_wac
);
1519 wacom_clean_inputs(wacom1
);
1521 /* Touch interface */
1522 hdev2
= usb_get_intfdata(usbdev
->config
->interface
[2]);
1523 wacom2
= hid_get_drvdata(hdev2
);
1524 wacom_wac2
= &(wacom2
->wacom_wac
);
1525 wacom_clean_inputs(wacom2
);
1527 if (wacom_wac
->pid
== 0) {
1528 hid_info(wacom
->hdev
, "wireless tablet disconnected\n");
1529 wacom_wac1
->shared
->type
= 0;
1531 const struct hid_device_id
*id
= wacom_ids
;
1533 hid_info(wacom
->hdev
, "wireless tablet connected with PID %x\n",
1537 if (id
->vendor
== USB_VENDOR_ID_WACOM
&&
1538 id
->product
== wacom_wac
->pid
)
1544 hid_info(wacom
->hdev
, "ignoring unknown PID.\n");
1548 /* Stylus interface */
1549 wacom_wac1
->features
=
1550 *((struct wacom_features
*)id
->driver_data
);
1551 wacom_wac1
->features
.device_type
|= WACOM_DEVICETYPE_PEN
;
1552 wacom_set_default_phy(&wacom_wac1
->features
);
1553 wacom_calculate_res(&wacom_wac1
->features
);
1554 snprintf(wacom_wac1
->pen_name
, WACOM_NAME_MAX
, "%s (WL) Pen",
1555 wacom_wac1
->features
.name
);
1556 if (wacom_wac1
->features
.type
< BAMBOO_PEN
||
1557 wacom_wac1
->features
.type
> BAMBOO_PT
) {
1558 snprintf(wacom_wac1
->pad_name
, WACOM_NAME_MAX
, "%s (WL) Pad",
1559 wacom_wac1
->features
.name
);
1560 wacom_wac1
->features
.device_type
|= WACOM_DEVICETYPE_PAD
;
1562 wacom_wac1
->shared
->touch_max
= wacom_wac1
->features
.touch_max
;
1563 wacom_wac1
->shared
->type
= wacom_wac1
->features
.type
;
1564 wacom_wac1
->pid
= wacom_wac
->pid
;
1565 error
= wacom_allocate_inputs(wacom1
) ||
1566 wacom_register_inputs(wacom1
);
1570 /* Touch interface */
1571 if (wacom_wac1
->features
.touch_max
||
1572 (wacom_wac1
->features
.type
>= INTUOSHT
&&
1573 wacom_wac1
->features
.type
<= BAMBOO_PT
)) {
1574 wacom_wac2
->features
=
1575 *((struct wacom_features
*)id
->driver_data
);
1576 wacom_wac2
->features
.pktlen
= WACOM_PKGLEN_BBTOUCH3
;
1577 wacom_set_default_phy(&wacom_wac2
->features
);
1578 wacom_wac2
->features
.x_max
= wacom_wac2
->features
.y_max
= 4096;
1579 wacom_calculate_res(&wacom_wac2
->features
);
1580 snprintf(wacom_wac2
->touch_name
, WACOM_NAME_MAX
,
1581 "%s (WL) Finger",wacom_wac2
->features
.name
);
1582 if (wacom_wac1
->features
.touch_max
)
1583 wacom_wac2
->features
.device_type
|= WACOM_DEVICETYPE_TOUCH
;
1584 if (wacom_wac1
->features
.type
>= INTUOSHT
&&
1585 wacom_wac1
->features
.type
<= BAMBOO_PT
) {
1586 snprintf(wacom_wac2
->pad_name
, WACOM_NAME_MAX
,
1587 "%s (WL) Pad",wacom_wac2
->features
.name
);
1588 wacom_wac2
->features
.device_type
|= WACOM_DEVICETYPE_PAD
;
1590 wacom_wac2
->pid
= wacom_wac
->pid
;
1591 error
= wacom_allocate_inputs(wacom2
) ||
1592 wacom_register_inputs(wacom2
);
1596 if ((wacom_wac1
->features
.type
== INTUOSHT
||
1597 wacom_wac1
->features
.type
== INTUOSHT2
) &&
1598 wacom_wac1
->features
.touch_max
)
1599 wacom_wac
->shared
->touch_input
= wacom_wac2
->touch_input
;
1602 error
= wacom_initialize_battery(wacom
);
1610 wacom_clean_inputs(wacom1
);
1611 wacom_clean_inputs(wacom2
);
1615 void wacom_battery_work(struct work_struct
*work
)
1617 struct wacom
*wacom
= container_of(work
, struct wacom
, work
);
1619 if ((wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1621 wacom_initialize_battery(wacom
);
1623 else if (!(wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1625 wacom_destroy_battery(wacom
);
1629 static size_t wacom_compute_pktlen(struct hid_device
*hdev
)
1631 struct hid_report_enum
*report_enum
;
1632 struct hid_report
*report
;
1635 report_enum
= hdev
->report_enum
+ HID_INPUT_REPORT
;
1637 list_for_each_entry(report
, &report_enum
->report_list
, list
) {
1638 size_t report_size
= hid_report_len(report
);
1639 if (report_size
> size
)
1646 static void wacom_update_name(struct wacom
*wacom
)
1648 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1649 struct wacom_features
*features
= &wacom_wac
->features
;
1650 char name
[WACOM_NAME_MAX
];
1652 /* Generic devices name unspecified */
1653 if ((features
->type
== HID_GENERIC
) && !strcmp("Wacom HID", features
->name
)) {
1654 if (strstr(wacom
->hdev
->name
, "Wacom") ||
1655 strstr(wacom
->hdev
->name
, "wacom") ||
1656 strstr(wacom
->hdev
->name
, "WACOM")) {
1657 /* name is in HID descriptor, use it */
1658 strlcpy(name
, wacom
->hdev
->name
, sizeof(name
));
1660 /* strip out excess whitespaces */
1662 char *gap
= strstr(name
, " ");
1665 /* shift everything including the terminator */
1666 memmove(gap
, gap
+1, strlen(gap
));
1668 /* get rid of trailing whitespace */
1669 if (name
[strlen(name
)-1] == ' ')
1670 name
[strlen(name
)-1] = '\0';
1672 /* no meaningful name retrieved. use product ID */
1673 snprintf(name
, sizeof(name
),
1674 "%s %X", features
->name
, wacom
->hdev
->product
);
1677 strlcpy(name
, features
->name
, sizeof(name
));
1680 /* Append the device type to the name */
1681 snprintf(wacom_wac
->pen_name
, sizeof(wacom_wac
->pen_name
),
1683 snprintf(wacom_wac
->touch_name
, sizeof(wacom_wac
->touch_name
),
1685 snprintf(wacom_wac
->pad_name
, sizeof(wacom_wac
->pad_name
),
1689 static int wacom_probe(struct hid_device
*hdev
,
1690 const struct hid_device_id
*id
)
1692 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
1693 struct usb_device
*dev
= interface_to_usbdev(intf
);
1694 struct wacom
*wacom
;
1695 struct wacom_wac
*wacom_wac
;
1696 struct wacom_features
*features
;
1698 unsigned int connect_mask
= HID_CONNECT_HIDRAW
;
1700 if (!id
->driver_data
)
1703 hdev
->quirks
|= HID_QUIRK_NO_INIT_REPORTS
;
1705 /* hid-core sets this quirk for the boot interface */
1706 hdev
->quirks
&= ~HID_QUIRK_NOGET
;
1708 wacom
= kzalloc(sizeof(struct wacom
), GFP_KERNEL
);
1712 hid_set_drvdata(hdev
, wacom
);
1715 /* ask for the report descriptor to be loaded by HID */
1716 error
= hid_parse(hdev
);
1718 hid_err(hdev
, "parse failed\n");
1722 wacom_wac
= &wacom
->wacom_wac
;
1723 wacom_wac
->features
= *((struct wacom_features
*)id
->driver_data
);
1724 features
= &wacom_wac
->features
;
1725 features
->pktlen
= wacom_compute_pktlen(hdev
);
1726 if (features
->pktlen
> WACOM_PKGLEN_MAX
) {
1731 if (features
->check_for_hid_type
&& features
->hid_type
!= hdev
->type
) {
1736 wacom
->usbdev
= dev
;
1738 mutex_init(&wacom
->lock
);
1739 INIT_WORK(&wacom
->work
, wacom_wireless_work
);
1741 error
= wacom_allocate_inputs(wacom
);
1743 goto fail_allocate_inputs
;
1746 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
1747 * into debug mode for the touch part.
1748 * We ignore the other interfaces.
1750 if (features
->type
== BAMBOO_PAD
) {
1751 if (features
->pktlen
== WACOM_PKGLEN_PENABLED
) {
1752 features
->type
= HID_GENERIC
;
1753 } else if ((features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH
) &&
1754 (features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH_USB
)) {
1756 goto fail_shared_data
;
1760 /* set the default size in case we do not get them from hid */
1761 wacom_set_default_phy(features
);
1763 /* Retrieve the physical and logical size for touch devices */
1764 wacom_retrieve_hid_descriptor(hdev
, features
);
1765 wacom_setup_device_quirks(wacom
);
1767 if (features
->device_type
== WACOM_DEVICETYPE_NONE
&&
1768 features
->type
!= WIRELESS
) {
1769 error
= features
->type
== HID_GENERIC
? -ENODEV
: 0;
1771 dev_warn(&hdev
->dev
, "Unknown device_type for '%s'. %s.",
1773 error
? "Ignoring" : "Assuming pen");
1776 goto fail_shared_data
;
1778 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
1781 wacom_calculate_res(features
);
1783 wacom_update_name(wacom
);
1785 error
= wacom_add_shared_data(hdev
);
1787 goto fail_shared_data
;
1789 if (!(features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
) &&
1790 (features
->quirks
& WACOM_QUIRK_BATTERY
)) {
1791 error
= wacom_initialize_battery(wacom
);
1796 error
= wacom_register_inputs(wacom
);
1798 goto fail_register_inputs
;
1800 if (hdev
->bus
== BUS_BLUETOOTH
) {
1801 error
= device_create_file(&hdev
->dev
, &dev_attr_speed
);
1804 "can't create sysfs speed attribute err: %d\n",
1808 if (features
->type
== HID_GENERIC
)
1809 connect_mask
|= HID_CONNECT_DRIVER
;
1811 /* Regular HID work starts now */
1812 error
= hid_hw_start(hdev
, connect_mask
);
1814 hid_err(hdev
, "hw start failed\n");
1818 /* Note that if query fails it is not a hard failure */
1819 wacom_query_tablet_data(hdev
, features
);
1821 /* touch only Bamboo doesn't support pen */
1822 if ((features
->type
== BAMBOO_TOUCH
) &&
1823 (features
->device_type
& WACOM_DEVICETYPE_PEN
)) {
1828 /* pen only Bamboo neither support touch nor pad */
1829 if ((features
->type
== BAMBOO_PEN
) &&
1830 ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) ||
1831 (features
->device_type
& WACOM_DEVICETYPE_PAD
))) {
1836 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
1837 error
= hid_hw_open(hdev
);
1839 if ((wacom_wac
->features
.type
== INTUOSHT
||
1840 wacom_wac
->features
.type
== INTUOSHT2
) &&
1841 (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
)) {
1842 wacom_wac
->shared
->touch_input
= wacom_wac
->touch_input
;
1848 if (hdev
->bus
== BUS_BLUETOOTH
)
1849 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
1850 fail_register_inputs
:
1851 wacom_clean_inputs(wacom
);
1852 wacom_destroy_battery(wacom
);
1854 wacom_remove_shared_data(wacom
);
1856 wacom_clean_inputs(wacom
);
1857 fail_allocate_inputs
:
1862 hid_set_drvdata(hdev
, NULL
);
1866 static void wacom_remove(struct hid_device
*hdev
)
1868 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1872 cancel_work_sync(&wacom
->work
);
1873 wacom_clean_inputs(wacom
);
1874 if (hdev
->bus
== BUS_BLUETOOTH
)
1875 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
1876 wacom_destroy_battery(wacom
);
1877 wacom_remove_shared_data(wacom
);
1879 hid_set_drvdata(hdev
, NULL
);
1884 static int wacom_resume(struct hid_device
*hdev
)
1886 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1887 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
1889 mutex_lock(&wacom
->lock
);
1891 /* switch to wacom mode first */
1892 wacom_query_tablet_data(hdev
, features
);
1893 wacom_led_control(wacom
);
1895 mutex_unlock(&wacom
->lock
);
1900 static int wacom_reset_resume(struct hid_device
*hdev
)
1902 return wacom_resume(hdev
);
1904 #endif /* CONFIG_PM */
1906 static struct hid_driver wacom_driver
= {
1908 .id_table
= wacom_ids
,
1909 .probe
= wacom_probe
,
1910 .remove
= wacom_remove
,
1911 .report
= wacom_wac_report
,
1913 .resume
= wacom_resume
,
1914 .reset_resume
= wacom_reset_resume
,
1916 .raw_event
= wacom_raw_event
,
1918 module_hid_driver(wacom_driver
);
1920 MODULE_VERSION(DRIVER_VERSION
);
1921 MODULE_AUTHOR(DRIVER_AUTHOR
);
1922 MODULE_DESCRIPTION(DRIVER_DESC
);
1923 MODULE_LICENSE(DRIVER_LICENSE
);