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
19 #define WAC_CMD_RETRIES 10
21 #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
22 #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
23 #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP)
25 static int wacom_get_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
26 size_t size
, unsigned int retries
)
31 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
33 } while ((retval
== -ETIMEDOUT
|| retval
== -EAGAIN
) && --retries
);
36 hid_err(hdev
, "wacom_get_report: ran out of retries "
37 "(last error = %d)\n", retval
);
42 static int wacom_set_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
43 size_t size
, unsigned int retries
)
48 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
50 } while ((retval
== -ETIMEDOUT
|| retval
== -EAGAIN
) && --retries
);
53 hid_err(hdev
, "wacom_set_report: ran out of retries "
54 "(last error = %d)\n", retval
);
59 static int wacom_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
60 u8
*raw_data
, int size
)
62 struct wacom
*wacom
= hid_get_drvdata(hdev
);
64 if (size
> WACOM_PKGLEN_MAX
)
67 memcpy(wacom
->wacom_wac
.data
, raw_data
, size
);
69 wacom_wac_irq(&wacom
->wacom_wac
, size
);
74 static int wacom_open(struct input_dev
*dev
)
76 struct wacom
*wacom
= input_get_drvdata(dev
);
78 return hid_hw_open(wacom
->hdev
);
81 static void wacom_close(struct input_dev
*dev
)
83 struct wacom
*wacom
= input_get_drvdata(dev
);
86 * wacom->hdev should never be null, but surprisingly, I had the case
87 * once while unplugging the Wacom Wireless Receiver.
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
;
115 unsigned int equivalent_usage
= wacom_equivalent_usage(usage
->hid
);
120 switch (equivalent_usage
) {
121 case HID_DG_CONTACTMAX
:
122 /* leave touch_max as is if predefined */
123 if (!features
->touch_max
) {
125 data
= kzalloc(2, GFP_KERNEL
);
128 data
[0] = field
->report
->id
;
129 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
130 data
, 2, WAC_CMD_RETRIES
);
132 features
->touch_max
= data
[1];
134 features
->touch_max
= 16;
135 hid_warn(hdev
, "wacom_feature_mapping: "
136 "could not get HID_DG_CONTACTMAX, "
137 "defaulting to %d\n",
138 features
->touch_max
);
143 case HID_DG_INPUTMODE
:
144 /* Ignore if value index is out of bounds. */
145 if (usage
->usage_index
>= field
->report_count
) {
146 dev_err(&hdev
->dev
, "HID_DG_INPUTMODE out of range\n");
150 hid_data
->inputmode
= field
->report
->id
;
151 hid_data
->inputmode_index
= usage
->usage_index
;
154 case HID_UP_DIGITIZER
:
155 if (field
->report
->id
== 0x0B &&
156 (field
->application
== WACOM_HID_G9_PEN
||
157 field
->application
== WACOM_HID_G11_PEN
)) {
158 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
159 wacom
->wacom_wac
.mode_value
= 0;
163 case WACOM_HID_WD_DATAMODE
:
164 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
165 wacom
->wacom_wac
.mode_value
= 2;
168 case WACOM_HID_UP_G9
:
169 case WACOM_HID_UP_G11
:
170 if (field
->report
->id
== 0x03 &&
171 (field
->application
== WACOM_HID_G9_TOUCHSCREEN
||
172 field
->application
== WACOM_HID_G11_TOUCHSCREEN
)) {
173 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
174 wacom
->wacom_wac
.mode_value
= 0;
177 case WACOM_HID_WD_OFFSETLEFT
:
178 case WACOM_HID_WD_OFFSETTOP
:
179 case WACOM_HID_WD_OFFSETRIGHT
:
180 case WACOM_HID_WD_OFFSETBOTTOM
:
182 n
= hid_report_len(field
->report
);
183 data
= hid_alloc_report_buf(field
->report
, GFP_KERNEL
);
186 data
[0] = field
->report
->id
;
187 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
188 data
, n
, WAC_CMD_RETRIES
);
190 ret
= hid_report_raw_event(hdev
, HID_FEATURE_REPORT
,
193 hid_warn(hdev
, "%s: could not retrieve sensor offsets\n",
202 * Interface Descriptor of wacom devices can be incomplete and
203 * inconsistent so wacom_features table is used to store stylus
204 * device's packet lengths, various maximum values, and tablet
205 * resolution based on product ID's.
207 * For devices that contain 2 interfaces, wacom_features table is
208 * inaccurate for the touch interface. Since the Interface Descriptor
209 * for touch interfaces has pretty complete data, this function exists
210 * to query tablet for this missing information instead of hard coding in
211 * an additional table.
213 * A typical Interface Descriptor for a stylus will contain a
214 * boot mouse application collection that is not of interest and this
215 * function will ignore it.
217 * It also contains a digitizer application collection that also is not
218 * of interest since any information it contains would be duplicate
219 * of what is in wacom_features. Usually it defines a report of an array
220 * of bytes that could be used as max length of the stylus packet returned.
221 * If it happens to define a Digitizer-Stylus Physical Collection then
222 * the X and Y logical values contain valid data but it is ignored.
224 * A typical Interface Descriptor for a touch interface will contain a
225 * Digitizer-Finger Physical Collection which will define both logical
226 * X/Y maximum as well as the physical size of tablet. Since touch
227 * interfaces haven't supported pressure or distance, this is enough
228 * information to override invalid values in the wacom_features table.
230 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
231 * data. We deal with them after returning from this function.
233 static void wacom_usage_mapping(struct hid_device
*hdev
,
234 struct hid_field
*field
, struct hid_usage
*usage
)
236 struct wacom
*wacom
= hid_get_drvdata(hdev
);
237 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
238 bool finger
= WACOM_FINGER_FIELD(field
);
239 bool pen
= WACOM_PEN_FIELD(field
);
242 * Requiring Stylus Usage will ignore boot mouse
243 * X/Y values and some cases of invalid Digitizer X/Y
244 * values commonly reported.
247 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
249 features
->device_type
|= WACOM_DEVICETYPE_TOUCH
;
254 * Bamboo models do not support HID_DG_CONTACTMAX.
255 * And, Bamboo Pen only descriptor contains touch.
257 if (features
->type
> BAMBOO_PT
) {
258 /* ISDv4 touch devices at least supports one touch point */
259 if (finger
&& !features
->touch_max
)
260 features
->touch_max
= 1;
264 * ISDv4 devices which predate HID's adoption of the
265 * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its
266 * position instead. We can accurately detect if a
267 * usage with that value should be HID_DG_BARRELSWITCH2
268 * based on the surrounding usages, which have remained
269 * constant across generations.
271 if (features
->type
== HID_GENERIC
&&
272 usage
->hid
== 0x000D0000 &&
273 field
->application
== HID_DG_PEN
&&
274 field
->physical
== HID_DG_STYLUS
) {
275 int i
= usage
->usage_index
;
277 if (i
-4 >= 0 && i
+1 < field
->maxusage
&&
278 field
->usage
[i
-4].hid
== HID_DG_TIPSWITCH
&&
279 field
->usage
[i
-3].hid
== HID_DG_BARRELSWITCH
&&
280 field
->usage
[i
-2].hid
== HID_DG_ERASER
&&
281 field
->usage
[i
-1].hid
== HID_DG_INVERT
&&
282 field
->usage
[i
+1].hid
== HID_DG_INRANGE
) {
283 usage
->hid
= HID_DG_BARRELSWITCH2
;
287 /* 2nd-generation Intuos Pro Large has incorrect Y maximum */
288 if (hdev
->vendor
== USB_VENDOR_ID_WACOM
&&
289 hdev
->product
== 0x0358 &&
290 WACOM_PEN_FIELD(field
) &&
291 wacom_equivalent_usage(usage
->hid
) == HID_GD_Y
) {
292 field
->logical_maximum
= 43200;
295 switch (usage
->hid
) {
297 features
->x_max
= field
->logical_maximum
;
299 features
->x_phy
= field
->physical_maximum
;
300 if ((features
->type
!= BAMBOO_PT
) &&
301 (features
->type
!= BAMBOO_TOUCH
)) {
302 features
->unit
= field
->unit
;
303 features
->unitExpo
= field
->unit_exponent
;
308 features
->y_max
= field
->logical_maximum
;
310 features
->y_phy
= field
->physical_maximum
;
311 if ((features
->type
!= BAMBOO_PT
) &&
312 (features
->type
!= BAMBOO_TOUCH
)) {
313 features
->unit
= field
->unit
;
314 features
->unitExpo
= field
->unit_exponent
;
318 case HID_DG_TIPPRESSURE
:
320 features
->pressure_max
= field
->logical_maximum
;
324 if (features
->type
== HID_GENERIC
)
325 wacom_wac_usage_mapping(hdev
, field
, usage
);
328 static void wacom_post_parse_hid(struct hid_device
*hdev
,
329 struct wacom_features
*features
)
331 struct wacom
*wacom
= hid_get_drvdata(hdev
);
332 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
334 if (features
->type
== HID_GENERIC
) {
335 /* Any last-minute generic device setup */
336 if (wacom_wac
->has_mode_change
) {
337 if (wacom_wac
->is_direct_mode
)
338 features
->device_type
|= WACOM_DEVICETYPE_DIRECT
;
340 features
->device_type
&= ~WACOM_DEVICETYPE_DIRECT
;
343 if (features
->touch_max
> 1) {
344 if (features
->device_type
& WACOM_DEVICETYPE_DIRECT
)
345 input_mt_init_slots(wacom_wac
->touch_input
,
346 wacom_wac
->features
.touch_max
,
349 input_mt_init_slots(wacom_wac
->touch_input
,
350 wacom_wac
->features
.touch_max
,
356 static void wacom_parse_hid(struct hid_device
*hdev
,
357 struct wacom_features
*features
)
359 struct hid_report_enum
*rep_enum
;
360 struct hid_report
*hreport
;
363 /* check features first */
364 rep_enum
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
365 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
366 for (i
= 0; i
< hreport
->maxfield
; i
++) {
367 /* Ignore if report count is out of bounds. */
368 if (hreport
->field
[i
]->report_count
< 1)
371 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++) {
372 wacom_feature_mapping(hdev
, hreport
->field
[i
],
373 hreport
->field
[i
]->usage
+ j
);
378 /* now check the input usages */
379 rep_enum
= &hdev
->report_enum
[HID_INPUT_REPORT
];
380 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
382 if (!hreport
->maxfield
)
385 for (i
= 0; i
< hreport
->maxfield
; i
++)
386 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++)
387 wacom_usage_mapping(hdev
, hreport
->field
[i
],
388 hreport
->field
[i
]->usage
+ j
);
391 wacom_post_parse_hid(hdev
, features
);
394 static int wacom_hid_set_device_mode(struct hid_device
*hdev
)
396 struct wacom
*wacom
= hid_get_drvdata(hdev
);
397 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
398 struct hid_report
*r
;
399 struct hid_report_enum
*re
;
401 if (hid_data
->inputmode
< 0)
404 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
405 r
= re
->report_id_hash
[hid_data
->inputmode
];
407 r
->field
[0]->value
[hid_data
->inputmode_index
] = 2;
408 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
413 static int wacom_set_device_mode(struct hid_device
*hdev
,
414 struct wacom_wac
*wacom_wac
)
417 struct hid_report
*r
;
418 struct hid_report_enum
*re
;
420 int error
= -ENOMEM
, limit
= 0;
422 if (wacom_wac
->mode_report
< 0)
425 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
426 r
= re
->report_id_hash
[wacom_wac
->mode_report
];
430 rep_data
= hid_alloc_report_buf(r
, GFP_KERNEL
);
434 length
= hid_report_len(r
);
437 rep_data
[0] = wacom_wac
->mode_report
;
438 rep_data
[1] = wacom_wac
->mode_value
;
440 error
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
,
443 error
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
444 rep_data
, length
, 1);
445 } while (error
>= 0 &&
446 rep_data
[1] != wacom_wac
->mode_report
&&
447 limit
++ < WAC_MSG_RETRIES
);
451 return error
< 0 ? error
: 0;
454 static int wacom_bt_query_tablet_data(struct hid_device
*hdev
, u8 speed
,
455 struct wacom_features
*features
)
457 struct wacom
*wacom
= hid_get_drvdata(hdev
);
461 switch (features
->type
) {
465 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
469 rep_data
[0] = speed
== 0 ? 0x05 : 0x06;
472 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
,
476 wacom
->wacom_wac
.bt_high_speed
= speed
;
482 * Note that if the raw queries fail, it's not a hard failure
483 * and it is safe to continue
485 hid_warn(hdev
, "failed to poke device, command %d, err %d\n",
490 wacom
->wacom_wac
.bt_features
&= ~0x20;
492 wacom
->wacom_wac
.bt_features
|= 0x20;
495 rep_data
[1] = wacom
->wacom_wac
.bt_features
;
497 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
500 wacom
->wacom_wac
.bt_high_speed
= speed
;
508 * Switch the tablet into its most-capable mode. Wacom tablets are
509 * typically configured to power-up in a mode which sends mouse-like
510 * reports to the OS. To get absolute position, pressure data, etc.
511 * from the tablet, it is necessary to switch the tablet out of this
512 * mode and into one which sends the full range of tablet data.
514 static int _wacom_query_tablet_data(struct wacom
*wacom
)
516 struct hid_device
*hdev
= wacom
->hdev
;
517 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
518 struct wacom_features
*features
= &wacom_wac
->features
;
520 if (hdev
->bus
== BUS_BLUETOOTH
)
521 return wacom_bt_query_tablet_data(hdev
, 1, features
);
523 if (features
->type
!= HID_GENERIC
) {
524 if (features
->device_type
& WACOM_DEVICETYPE_TOUCH
) {
525 if (features
->type
> TABLETPC
) {
526 /* MT Tablet PC touch */
527 wacom_wac
->mode_report
= 3;
528 wacom_wac
->mode_value
= 4;
529 } else if (features
->type
== WACOM_24HDT
) {
530 wacom_wac
->mode_report
= 18;
531 wacom_wac
->mode_value
= 2;
532 } else if (features
->type
== WACOM_27QHDT
) {
533 wacom_wac
->mode_report
= 131;
534 wacom_wac
->mode_value
= 2;
535 } else if (features
->type
== BAMBOO_PAD
) {
536 wacom_wac
->mode_report
= 2;
537 wacom_wac
->mode_value
= 2;
539 } else if (features
->device_type
& WACOM_DEVICETYPE_PEN
) {
540 if (features
->type
<= BAMBOO_PT
) {
541 wacom_wac
->mode_report
= 2;
542 wacom_wac
->mode_value
= 2;
547 wacom_set_device_mode(hdev
, wacom_wac
);
549 if (features
->type
== HID_GENERIC
)
550 return wacom_hid_set_device_mode(hdev
);
555 static void wacom_retrieve_hid_descriptor(struct hid_device
*hdev
,
556 struct wacom_features
*features
)
558 struct wacom
*wacom
= hid_get_drvdata(hdev
);
559 struct usb_interface
*intf
= wacom
->intf
;
561 /* default features */
562 features
->x_fuzz
= 4;
563 features
->y_fuzz
= 4;
564 features
->pressure_fuzz
= 0;
565 features
->distance_fuzz
= 1;
566 features
->tilt_fuzz
= 1;
569 * The wireless device HID is basic and layout conflicts with
570 * other tablets (monitor and touch interface can look like pen).
571 * Skip the query for this type and modify defaults based on
574 if (features
->type
== WIRELESS
) {
575 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 0)
576 features
->device_type
= WACOM_DEVICETYPE_WL_MONITOR
;
578 features
->device_type
= WACOM_DEVICETYPE_NONE
;
582 wacom_parse_hid(hdev
, features
);
585 struct wacom_hdev_data
{
586 struct list_head list
;
588 struct hid_device
*dev
;
589 struct wacom_shared shared
;
592 static LIST_HEAD(wacom_udev_list
);
593 static DEFINE_MUTEX(wacom_udev_list_lock
);
595 static bool compare_device_paths(struct hid_device
*hdev_a
,
596 struct hid_device
*hdev_b
, char separator
)
598 int n1
= strrchr(hdev_a
->phys
, separator
) - hdev_a
->phys
;
599 int n2
= strrchr(hdev_b
->phys
, separator
) - hdev_b
->phys
;
601 if (n1
!= n2
|| n1
<= 0 || n2
<= 0)
604 return !strncmp(hdev_a
->phys
, hdev_b
->phys
, n1
);
607 static bool wacom_are_sibling(struct hid_device
*hdev
,
608 struct hid_device
*sibling
)
610 struct wacom
*wacom
= hid_get_drvdata(hdev
);
611 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
612 struct wacom
*sibling_wacom
= hid_get_drvdata(sibling
);
613 struct wacom_features
*sibling_features
= &sibling_wacom
->wacom_wac
.features
;
614 __u32 oVid
= features
->oVid
? features
->oVid
: hdev
->vendor
;
615 __u32 oPid
= features
->oPid
? features
->oPid
: hdev
->product
;
617 /* The defined oVid/oPid must match that of the sibling */
618 if (features
->oVid
!= HID_ANY_ID
&& sibling
->vendor
!= oVid
)
620 if (features
->oPid
!= HID_ANY_ID
&& sibling
->product
!= oPid
)
624 * Devices with the same VID/PID must share the same physical
625 * device path, while those with different VID/PID must share
626 * the same physical parent device path.
628 if (hdev
->vendor
== sibling
->vendor
&& hdev
->product
== sibling
->product
) {
629 if (!compare_device_paths(hdev
, sibling
, '/'))
632 if (!compare_device_paths(hdev
, sibling
, '.'))
636 /* Skip the remaining heuristics unless you are a HID_GENERIC device */
637 if (features
->type
!= HID_GENERIC
)
641 * Direct-input devices may not be siblings of indirect-input
644 if ((features
->device_type
& WACOM_DEVICETYPE_DIRECT
) &&
645 !(sibling_features
->device_type
& WACOM_DEVICETYPE_DIRECT
))
649 * Indirect-input devices may not be siblings of direct-input
652 if (!(features
->device_type
& WACOM_DEVICETYPE_DIRECT
) &&
653 (sibling_features
->device_type
& WACOM_DEVICETYPE_DIRECT
))
656 /* Pen devices may only be siblings of touch devices */
657 if ((features
->device_type
& WACOM_DEVICETYPE_PEN
) &&
658 !(sibling_features
->device_type
& WACOM_DEVICETYPE_TOUCH
))
661 /* Touch devices may only be siblings of pen devices */
662 if ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) &&
663 !(sibling_features
->device_type
& WACOM_DEVICETYPE_PEN
))
667 * No reason could be found for these two devices to NOT be
668 * siblings, so there's a good chance they ARE siblings
673 static struct wacom_hdev_data
*wacom_get_hdev_data(struct hid_device
*hdev
)
675 struct wacom_hdev_data
*data
;
677 /* Try to find an already-probed interface from the same device */
678 list_for_each_entry(data
, &wacom_udev_list
, list
) {
679 if (compare_device_paths(hdev
, data
->dev
, '/')) {
680 kref_get(&data
->kref
);
685 /* Fallback to finding devices that appear to be "siblings" */
686 list_for_each_entry(data
, &wacom_udev_list
, list
) {
687 if (wacom_are_sibling(hdev
, data
->dev
)) {
688 kref_get(&data
->kref
);
696 static void wacom_release_shared_data(struct kref
*kref
)
698 struct wacom_hdev_data
*data
=
699 container_of(kref
, struct wacom_hdev_data
, kref
);
701 mutex_lock(&wacom_udev_list_lock
);
702 list_del(&data
->list
);
703 mutex_unlock(&wacom_udev_list_lock
);
708 static void wacom_remove_shared_data(void *res
)
710 struct wacom
*wacom
= res
;
711 struct wacom_hdev_data
*data
;
712 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
714 if (wacom_wac
->shared
) {
715 data
= container_of(wacom_wac
->shared
, struct wacom_hdev_data
,
718 if (wacom_wac
->shared
->touch
== wacom
->hdev
)
719 wacom_wac
->shared
->touch
= NULL
;
720 else if (wacom_wac
->shared
->pen
== wacom
->hdev
)
721 wacom_wac
->shared
->pen
= NULL
;
723 kref_put(&data
->kref
, wacom_release_shared_data
);
724 wacom_wac
->shared
= NULL
;
728 static int wacom_add_shared_data(struct hid_device
*hdev
)
730 struct wacom
*wacom
= hid_get_drvdata(hdev
);
731 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
732 struct wacom_hdev_data
*data
;
735 mutex_lock(&wacom_udev_list_lock
);
737 data
= wacom_get_hdev_data(hdev
);
739 data
= kzalloc(sizeof(struct wacom_hdev_data
), GFP_KERNEL
);
745 kref_init(&data
->kref
);
747 list_add_tail(&data
->list
, &wacom_udev_list
);
750 wacom_wac
->shared
= &data
->shared
;
752 retval
= devm_add_action(&hdev
->dev
, wacom_remove_shared_data
, wacom
);
754 mutex_unlock(&wacom_udev_list_lock
);
755 wacom_remove_shared_data(wacom
);
759 if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
)
760 wacom_wac
->shared
->touch
= hdev
;
761 else if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_PEN
)
762 wacom_wac
->shared
->pen
= hdev
;
765 mutex_unlock(&wacom_udev_list_lock
);
769 static int wacom_led_control(struct wacom
*wacom
)
773 unsigned char report_id
= WAC_CMD_LED_CONTROL
;
776 if (!wacom
->led
.groups
)
779 if (wacom
->wacom_wac
.features
.type
== REMOTE
)
782 if (wacom
->wacom_wac
.pid
) { /* wireless connected */
783 report_id
= WAC_CMD_WL_LED_CONTROL
;
786 else if (wacom
->wacom_wac
.features
.type
== INTUOSP2_BT
) {
787 report_id
= WAC_CMD_WL_INTUOSP2
;
790 buf
= kzalloc(buf_size
, GFP_KERNEL
);
794 if (wacom
->wacom_wac
.features
.type
== HID_GENERIC
) {
795 buf
[0] = WAC_CMD_LED_CONTROL_GENERIC
;
796 buf
[1] = wacom
->led
.llv
;
797 buf
[2] = wacom
->led
.groups
[0].select
& 0x03;
799 } else if ((wacom
->wacom_wac
.features
.type
>= INTUOS5S
&&
800 wacom
->wacom_wac
.features
.type
<= INTUOSPL
)) {
802 * Touch Ring and crop mark LED luminance may take on
803 * one of four values:
804 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
806 int ring_led
= wacom
->led
.groups
[0].select
& 0x03;
807 int ring_lum
= (((wacom
->led
.llv
& 0x60) >> 5) - 1) & 0x03;
809 unsigned char led_bits
= (crop_lum
<< 4) | (ring_lum
<< 2) | (ring_led
);
812 if (wacom
->wacom_wac
.pid
) {
813 wacom_get_report(wacom
->hdev
, HID_FEATURE_REPORT
,
814 buf
, buf_size
, WAC_CMD_RETRIES
);
820 else if (wacom
->wacom_wac
.features
.type
== INTUOSP2_BT
) {
822 buf
[4] = 100; // Power Connection LED (ORANGE)
823 buf
[5] = 100; // BT Connection LED (BLUE)
824 buf
[6] = 100; // Paper Mode (RED?)
825 buf
[7] = 100; // Paper Mode (GREEN?)
826 buf
[8] = 100; // Paper Mode (BLUE?)
827 buf
[9] = wacom
->led
.llv
;
828 buf
[10] = wacom
->led
.groups
[0].select
& 0x03;
831 int led
= wacom
->led
.groups
[0].select
| 0x4;
833 if (wacom
->wacom_wac
.features
.type
== WACOM_21UX2
||
834 wacom
->wacom_wac
.features
.type
== WACOM_24HD
)
835 led
|= (wacom
->led
.groups
[1].select
<< 4) | 0x40;
839 buf
[2] = wacom
->led
.llv
;
840 buf
[3] = wacom
->led
.hlv
;
841 buf
[4] = wacom
->led
.img_lum
;
844 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, buf_size
,
851 static int wacom_led_putimage(struct wacom
*wacom
, int button_id
, u8 xfer_id
,
852 const unsigned len
, const void *img
)
856 const unsigned chunk_len
= len
/ 4; /* 4 chunks are needed to be sent */
858 buf
= kzalloc(chunk_len
+ 3 , GFP_KERNEL
);
862 /* Send 'start' command */
863 buf
[0] = WAC_CMD_ICON_START
;
865 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
871 buf
[1] = button_id
& 0x07;
872 for (i
= 0; i
< 4; i
++) {
874 memcpy(buf
+ 3, img
+ i
* chunk_len
, chunk_len
);
876 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
,
877 buf
, chunk_len
+ 3, WAC_CMD_RETRIES
);
883 buf
[0] = WAC_CMD_ICON_START
;
885 wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
893 static ssize_t
wacom_led_select_store(struct device
*dev
, int set_id
,
894 const char *buf
, size_t count
)
896 struct hid_device
*hdev
= to_hid_device(dev
);
897 struct wacom
*wacom
= hid_get_drvdata(hdev
);
901 err
= kstrtouint(buf
, 10, &id
);
905 mutex_lock(&wacom
->lock
);
907 wacom
->led
.groups
[set_id
].select
= id
& 0x3;
908 err
= wacom_led_control(wacom
);
910 mutex_unlock(&wacom
->lock
);
912 return err
< 0 ? err
: count
;
915 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
916 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
917 struct device_attribute *attr, const char *buf, size_t count) \
919 return wacom_led_select_store(dev, SET_ID, buf, count); \
921 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
922 struct device_attribute *attr, char *buf) \
924 struct hid_device *hdev = to_hid_device(dev);\
925 struct wacom *wacom = hid_get_drvdata(hdev); \
926 return scnprintf(buf, PAGE_SIZE, "%d\n", \
927 wacom->led.groups[SET_ID].select); \
929 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
930 wacom_led##SET_ID##_select_show, \
931 wacom_led##SET_ID##_select_store)
933 DEVICE_LED_SELECT_ATTR(0);
934 DEVICE_LED_SELECT_ATTR(1);
936 static ssize_t
wacom_luminance_store(struct wacom
*wacom
, u8
*dest
,
937 const char *buf
, size_t count
)
942 err
= kstrtouint(buf
, 10, &value
);
946 mutex_lock(&wacom
->lock
);
948 *dest
= value
& 0x7f;
949 err
= wacom_led_control(wacom
);
951 mutex_unlock(&wacom
->lock
);
953 return err
< 0 ? err
: count
;
956 #define DEVICE_LUMINANCE_ATTR(name, field) \
957 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
958 struct device_attribute *attr, const char *buf, size_t count) \
960 struct hid_device *hdev = to_hid_device(dev);\
961 struct wacom *wacom = hid_get_drvdata(hdev); \
963 return wacom_luminance_store(wacom, &wacom->led.field, \
966 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
967 struct device_attribute *attr, char *buf) \
969 struct wacom *wacom = dev_get_drvdata(dev); \
970 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
972 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
973 wacom_##name##_luminance_show, \
974 wacom_##name##_luminance_store)
976 DEVICE_LUMINANCE_ATTR(status0
, llv
);
977 DEVICE_LUMINANCE_ATTR(status1
, hlv
);
978 DEVICE_LUMINANCE_ATTR(buttons
, img_lum
);
980 static ssize_t
wacom_button_image_store(struct device
*dev
, int button_id
,
981 const char *buf
, size_t count
)
983 struct hid_device
*hdev
= to_hid_device(dev
);
984 struct wacom
*wacom
= hid_get_drvdata(hdev
);
989 if (hdev
->bus
== BUS_BLUETOOTH
) {
991 xfer_id
= WAC_CMD_ICON_BT_XFER
;
994 xfer_id
= WAC_CMD_ICON_XFER
;
1000 mutex_lock(&wacom
->lock
);
1002 err
= wacom_led_putimage(wacom
, button_id
, xfer_id
, len
, buf
);
1004 mutex_unlock(&wacom
->lock
);
1006 return err
< 0 ? err
: count
;
1009 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
1010 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
1011 struct device_attribute *attr, const char *buf, size_t count) \
1013 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
1015 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
1016 NULL, wacom_btnimg##BUTTON_ID##_store)
1018 DEVICE_BTNIMG_ATTR(0);
1019 DEVICE_BTNIMG_ATTR(1);
1020 DEVICE_BTNIMG_ATTR(2);
1021 DEVICE_BTNIMG_ATTR(3);
1022 DEVICE_BTNIMG_ATTR(4);
1023 DEVICE_BTNIMG_ATTR(5);
1024 DEVICE_BTNIMG_ATTR(6);
1025 DEVICE_BTNIMG_ATTR(7);
1027 static struct attribute
*cintiq_led_attrs
[] = {
1028 &dev_attr_status_led0_select
.attr
,
1029 &dev_attr_status_led1_select
.attr
,
1033 static struct attribute_group cintiq_led_attr_group
= {
1034 .name
= "wacom_led",
1035 .attrs
= cintiq_led_attrs
,
1038 static struct attribute
*intuos4_led_attrs
[] = {
1039 &dev_attr_status0_luminance
.attr
,
1040 &dev_attr_status1_luminance
.attr
,
1041 &dev_attr_status_led0_select
.attr
,
1042 &dev_attr_buttons_luminance
.attr
,
1043 &dev_attr_button0_rawimg
.attr
,
1044 &dev_attr_button1_rawimg
.attr
,
1045 &dev_attr_button2_rawimg
.attr
,
1046 &dev_attr_button3_rawimg
.attr
,
1047 &dev_attr_button4_rawimg
.attr
,
1048 &dev_attr_button5_rawimg
.attr
,
1049 &dev_attr_button6_rawimg
.attr
,
1050 &dev_attr_button7_rawimg
.attr
,
1054 static struct attribute_group intuos4_led_attr_group
= {
1055 .name
= "wacom_led",
1056 .attrs
= intuos4_led_attrs
,
1059 static struct attribute
*intuos5_led_attrs
[] = {
1060 &dev_attr_status0_luminance
.attr
,
1061 &dev_attr_status_led0_select
.attr
,
1065 static struct attribute_group intuos5_led_attr_group
= {
1066 .name
= "wacom_led",
1067 .attrs
= intuos5_led_attrs
,
1070 static struct attribute
*generic_led_attrs
[] = {
1071 &dev_attr_status0_luminance
.attr
,
1072 &dev_attr_status_led0_select
.attr
,
1076 static struct attribute_group generic_led_attr_group
= {
1077 .name
= "wacom_led",
1078 .attrs
= generic_led_attrs
,
1081 struct wacom_sysfs_group_devres
{
1082 struct attribute_group
*group
;
1083 struct kobject
*root
;
1086 static void wacom_devm_sysfs_group_release(struct device
*dev
, void *res
)
1088 struct wacom_sysfs_group_devres
*devres
= res
;
1089 struct kobject
*kobj
= devres
->root
;
1091 dev_dbg(dev
, "%s: dropping reference to %s\n",
1092 __func__
, devres
->group
->name
);
1093 sysfs_remove_group(kobj
, devres
->group
);
1096 static int __wacom_devm_sysfs_create_group(struct wacom
*wacom
,
1097 struct kobject
*root
,
1098 struct attribute_group
*group
)
1100 struct wacom_sysfs_group_devres
*devres
;
1103 devres
= devres_alloc(wacom_devm_sysfs_group_release
,
1104 sizeof(struct wacom_sysfs_group_devres
),
1109 devres
->group
= group
;
1110 devres
->root
= root
;
1112 error
= sysfs_create_group(devres
->root
, group
);
1114 devres_free(devres
);
1118 devres_add(&wacom
->hdev
->dev
, devres
);
1123 static int wacom_devm_sysfs_create_group(struct wacom
*wacom
,
1124 struct attribute_group
*group
)
1126 return __wacom_devm_sysfs_create_group(wacom
, &wacom
->hdev
->dev
.kobj
,
1130 enum led_brightness
wacom_leds_brightness_get(struct wacom_led
*led
)
1132 struct wacom
*wacom
= led
->wacom
;
1134 if (wacom
->led
.max_hlv
)
1135 return led
->hlv
* LED_FULL
/ wacom
->led
.max_hlv
;
1137 if (wacom
->led
.max_llv
)
1138 return led
->llv
* LED_FULL
/ wacom
->led
.max_llv
;
1140 /* device doesn't support brightness tuning */
1144 static enum led_brightness
__wacom_led_brightness_get(struct led_classdev
*cdev
)
1146 struct wacom_led
*led
= container_of(cdev
, struct wacom_led
, cdev
);
1147 struct wacom
*wacom
= led
->wacom
;
1149 if (wacom
->led
.groups
[led
->group
].select
!= led
->id
)
1152 return wacom_leds_brightness_get(led
);
1155 static int wacom_led_brightness_set(struct led_classdev
*cdev
,
1156 enum led_brightness brightness
)
1158 struct wacom_led
*led
= container_of(cdev
, struct wacom_led
, cdev
);
1159 struct wacom
*wacom
= led
->wacom
;
1162 mutex_lock(&wacom
->lock
);
1164 if (!wacom
->led
.groups
|| (brightness
== LED_OFF
&&
1165 wacom
->led
.groups
[led
->group
].select
!= led
->id
)) {
1170 led
->llv
= wacom
->led
.llv
= wacom
->led
.max_llv
* brightness
/ LED_FULL
;
1171 led
->hlv
= wacom
->led
.hlv
= wacom
->led
.max_hlv
* brightness
/ LED_FULL
;
1173 wacom
->led
.groups
[led
->group
].select
= led
->id
;
1175 error
= wacom_led_control(wacom
);
1178 mutex_unlock(&wacom
->lock
);
1183 static void wacom_led_readonly_brightness_set(struct led_classdev
*cdev
,
1184 enum led_brightness brightness
)
1188 static int wacom_led_register_one(struct device
*dev
, struct wacom
*wacom
,
1189 struct wacom_led
*led
, unsigned int group
,
1190 unsigned int id
, bool read_only
)
1195 name
= devm_kasprintf(dev
, GFP_KERNEL
,
1204 led
->trigger
.name
= name
;
1205 error
= devm_led_trigger_register(dev
, &led
->trigger
);
1207 hid_err(wacom
->hdev
,
1208 "failed to register LED trigger %s: %d\n",
1209 led
->cdev
.name
, error
);
1217 led
->llv
= wacom
->led
.llv
;
1218 led
->hlv
= wacom
->led
.hlv
;
1219 led
->cdev
.name
= name
;
1220 led
->cdev
.max_brightness
= LED_FULL
;
1221 led
->cdev
.flags
= LED_HW_PLUGGABLE
;
1222 led
->cdev
.brightness_get
= __wacom_led_brightness_get
;
1224 led
->cdev
.brightness_set_blocking
= wacom_led_brightness_set
;
1225 led
->cdev
.default_trigger
= led
->cdev
.name
;
1227 led
->cdev
.brightness_set
= wacom_led_readonly_brightness_set
;
1230 error
= devm_led_classdev_register(dev
, &led
->cdev
);
1232 hid_err(wacom
->hdev
,
1233 "failed to register LED %s: %d\n",
1234 led
->cdev
.name
, error
);
1235 led
->cdev
.name
= NULL
;
1242 static void wacom_led_groups_release_one(void *data
)
1244 struct wacom_group_leds
*group
= data
;
1246 devres_release_group(group
->dev
, group
);
1249 static int wacom_led_groups_alloc_and_register_one(struct device
*dev
,
1250 struct wacom
*wacom
,
1251 int group_id
, int count
,
1254 struct wacom_led
*leds
;
1257 if (group_id
>= wacom
->led
.count
|| count
<= 0)
1260 if (!devres_open_group(dev
, &wacom
->led
.groups
[group_id
], GFP_KERNEL
))
1263 leds
= devm_kzalloc(dev
, sizeof(struct wacom_led
) * count
, GFP_KERNEL
);
1269 wacom
->led
.groups
[group_id
].leds
= leds
;
1270 wacom
->led
.groups
[group_id
].count
= count
;
1272 for (i
= 0; i
< count
; i
++) {
1273 error
= wacom_led_register_one(dev
, wacom
, &leds
[i
],
1274 group_id
, i
, read_only
);
1279 wacom
->led
.groups
[group_id
].dev
= dev
;
1281 devres_close_group(dev
, &wacom
->led
.groups
[group_id
]);
1284 * There is a bug (?) in devm_led_classdev_register() in which its
1285 * increments the refcount of the parent. If the parent is an input
1286 * device, that means the ref count never reaches 0 when
1287 * devm_input_device_release() gets called.
1288 * This means that the LEDs are still there after disconnect.
1289 * Manually force the release of the group so that the leds are released
1290 * once we are done using them.
1292 error
= devm_add_action_or_reset(&wacom
->hdev
->dev
,
1293 wacom_led_groups_release_one
,
1294 &wacom
->led
.groups
[group_id
]);
1301 devres_release_group(dev
, &wacom
->led
.groups
[group_id
]);
1305 struct wacom_led
*wacom_led_find(struct wacom
*wacom
, unsigned int group_id
,
1308 struct wacom_group_leds
*group
;
1310 if (group_id
>= wacom
->led
.count
)
1313 group
= &wacom
->led
.groups
[group_id
];
1320 return &group
->leds
[id
];
1324 * wacom_led_next: gives the next available led with a wacom trigger.
1326 * returns the next available struct wacom_led which has its default trigger
1327 * or the current one if none is available.
1329 struct wacom_led
*wacom_led_next(struct wacom
*wacom
, struct wacom_led
*cur
)
1331 struct wacom_led
*next_led
;
1341 next_led
= wacom_led_find(wacom
, group
, ++next
);
1342 if (!next_led
|| next_led
== cur
)
1344 } while (next_led
->cdev
.trigger
!= &next_led
->trigger
);
1349 static void wacom_led_groups_release(void *data
)
1351 struct wacom
*wacom
= data
;
1353 wacom
->led
.groups
= NULL
;
1354 wacom
->led
.count
= 0;
1357 static int wacom_led_groups_allocate(struct wacom
*wacom
, int count
)
1359 struct device
*dev
= &wacom
->hdev
->dev
;
1360 struct wacom_group_leds
*groups
;
1363 groups
= devm_kzalloc(dev
, sizeof(struct wacom_group_leds
) * count
,
1368 error
= devm_add_action_or_reset(dev
, wacom_led_groups_release
, wacom
);
1372 wacom
->led
.groups
= groups
;
1373 wacom
->led
.count
= count
;
1378 static int wacom_leds_alloc_and_register(struct wacom
*wacom
, int group_count
,
1379 int led_per_group
, bool read_only
)
1384 if (!wacom
->wacom_wac
.pad_input
)
1387 dev
= &wacom
->wacom_wac
.pad_input
->dev
;
1389 error
= wacom_led_groups_allocate(wacom
, group_count
);
1393 for (i
= 0; i
< group_count
; i
++) {
1394 error
= wacom_led_groups_alloc_and_register_one(dev
, wacom
, i
,
1404 int wacom_initialize_leds(struct wacom
*wacom
)
1408 if (!(wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
))
1411 /* Initialize default values */
1412 switch (wacom
->wacom_wac
.features
.type
) {
1414 if (!wacom
->generic_has_leds
)
1416 wacom
->led
.llv
= 100;
1417 wacom
->led
.max_llv
= 100;
1419 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1421 hid_err(wacom
->hdev
,
1422 "cannot create leds err: %d\n", error
);
1426 error
= wacom_devm_sysfs_create_group(wacom
,
1427 &generic_led_attr_group
);
1434 wacom
->led
.llv
= 10;
1435 wacom
->led
.hlv
= 20;
1436 wacom
->led
.max_llv
= 127;
1437 wacom
->led
.max_hlv
= 127;
1438 wacom
->led
.img_lum
= 10;
1440 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1442 hid_err(wacom
->hdev
,
1443 "cannot create leds err: %d\n", error
);
1447 error
= wacom_devm_sysfs_create_group(wacom
,
1448 &intuos4_led_attr_group
);
1455 wacom
->led
.img_lum
= 0;
1457 error
= wacom_leds_alloc_and_register(wacom
, 2, 4, false);
1459 hid_err(wacom
->hdev
,
1460 "cannot create leds err: %d\n", error
);
1464 error
= wacom_devm_sysfs_create_group(wacom
,
1465 &cintiq_led_attr_group
);
1474 wacom
->led
.llv
= 32;
1475 wacom
->led
.max_llv
= 96;
1477 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1479 hid_err(wacom
->hdev
,
1480 "cannot create leds err: %d\n", error
);
1484 error
= wacom_devm_sysfs_create_group(wacom
,
1485 &intuos5_led_attr_group
);
1489 wacom
->led
.llv
= 50;
1490 wacom
->led
.max_llv
= 100;
1491 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1493 hid_err(wacom
->hdev
,
1494 "cannot create leds err: %d\n", error
);
1500 wacom
->led
.llv
= 255;
1501 wacom
->led
.max_llv
= 255;
1502 error
= wacom_led_groups_allocate(wacom
, 5);
1504 hid_err(wacom
->hdev
,
1505 "cannot create leds err: %d\n", error
);
1515 hid_err(wacom
->hdev
,
1516 "cannot create sysfs group err: %d\n", error
);
1523 static void wacom_init_work(struct work_struct
*work
)
1525 struct wacom
*wacom
= container_of(work
, struct wacom
, init_work
.work
);
1527 _wacom_query_tablet_data(wacom
);
1528 wacom_led_control(wacom
);
1531 static void wacom_query_tablet_data(struct wacom
*wacom
)
1533 schedule_delayed_work(&wacom
->init_work
, msecs_to_jiffies(1000));
1536 static enum power_supply_property wacom_battery_props
[] = {
1537 POWER_SUPPLY_PROP_MODEL_NAME
,
1538 POWER_SUPPLY_PROP_PRESENT
,
1539 POWER_SUPPLY_PROP_STATUS
,
1540 POWER_SUPPLY_PROP_SCOPE
,
1541 POWER_SUPPLY_PROP_CAPACITY
1544 static int wacom_battery_get_property(struct power_supply
*psy
,
1545 enum power_supply_property psp
,
1546 union power_supply_propval
*val
)
1548 struct wacom_battery
*battery
= power_supply_get_drvdata(psy
);
1552 case POWER_SUPPLY_PROP_MODEL_NAME
:
1553 val
->strval
= battery
->wacom
->wacom_wac
.name
;
1555 case POWER_SUPPLY_PROP_PRESENT
:
1556 val
->intval
= battery
->bat_connected
;
1558 case POWER_SUPPLY_PROP_SCOPE
:
1559 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
1561 case POWER_SUPPLY_PROP_CAPACITY
:
1562 val
->intval
= battery
->battery_capacity
;
1564 case POWER_SUPPLY_PROP_STATUS
:
1565 if (battery
->bat_status
!= WACOM_POWER_SUPPLY_STATUS_AUTO
)
1566 val
->intval
= battery
->bat_status
;
1567 else if (battery
->bat_charging
)
1568 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
1569 else if (battery
->battery_capacity
== 100 &&
1570 battery
->ps_connected
)
1571 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
1572 else if (battery
->ps_connected
)
1573 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1575 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
1585 static int __wacom_initialize_battery(struct wacom
*wacom
,
1586 struct wacom_battery
*battery
)
1588 static atomic_t battery_no
= ATOMIC_INIT(0);
1589 struct device
*dev
= &wacom
->hdev
->dev
;
1590 struct power_supply_config psy_cfg
= { .drv_data
= battery
, };
1591 struct power_supply
*ps_bat
;
1592 struct power_supply_desc
*bat_desc
= &battery
->bat_desc
;
1596 if (!devres_open_group(dev
, bat_desc
, GFP_KERNEL
))
1599 battery
->wacom
= wacom
;
1601 n
= atomic_inc_return(&battery_no
) - 1;
1603 bat_desc
->properties
= wacom_battery_props
;
1604 bat_desc
->num_properties
= ARRAY_SIZE(wacom_battery_props
);
1605 bat_desc
->get_property
= wacom_battery_get_property
;
1606 sprintf(battery
->bat_name
, "wacom_battery_%ld", n
);
1607 bat_desc
->name
= battery
->bat_name
;
1608 bat_desc
->type
= POWER_SUPPLY_TYPE_USB
;
1609 bat_desc
->use_for_apm
= 0;
1611 ps_bat
= devm_power_supply_register(dev
, bat_desc
, &psy_cfg
);
1612 if (IS_ERR(ps_bat
)) {
1613 error
= PTR_ERR(ps_bat
);
1617 power_supply_powers(ps_bat
, &wacom
->hdev
->dev
);
1619 battery
->battery
= ps_bat
;
1621 devres_close_group(dev
, bat_desc
);
1625 devres_release_group(dev
, bat_desc
);
1629 static int wacom_initialize_battery(struct wacom
*wacom
)
1631 if (wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
)
1632 return __wacom_initialize_battery(wacom
, &wacom
->battery
);
1637 static void wacom_destroy_battery(struct wacom
*wacom
)
1639 if (wacom
->battery
.battery
) {
1640 devres_release_group(&wacom
->hdev
->dev
,
1641 &wacom
->battery
.bat_desc
);
1642 wacom
->battery
.battery
= NULL
;
1646 static ssize_t
wacom_show_speed(struct device
*dev
,
1647 struct device_attribute
1650 struct hid_device
*hdev
= to_hid_device(dev
);
1651 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1653 return snprintf(buf
, PAGE_SIZE
, "%i\n", wacom
->wacom_wac
.bt_high_speed
);
1656 static ssize_t
wacom_store_speed(struct device
*dev
,
1657 struct device_attribute
*attr
,
1658 const char *buf
, size_t count
)
1660 struct hid_device
*hdev
= to_hid_device(dev
);
1661 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1664 if (kstrtou8(buf
, 0, &new_speed
))
1667 if (new_speed
!= 0 && new_speed
!= 1)
1670 wacom_bt_query_tablet_data(hdev
, new_speed
, &wacom
->wacom_wac
.features
);
1675 static DEVICE_ATTR(speed
, DEV_ATTR_RW_PERM
,
1676 wacom_show_speed
, wacom_store_speed
);
1679 static ssize_t
wacom_show_remote_mode(struct kobject
*kobj
,
1680 struct kobj_attribute
*kattr
,
1681 char *buf
, int index
)
1683 struct device
*dev
= kobj_to_dev(kobj
->parent
);
1684 struct hid_device
*hdev
= to_hid_device(dev
);
1685 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1688 mode
= wacom
->led
.groups
[index
].select
;
1689 return sprintf(buf
, "%d\n", mode
< 3 ? mode
: -1);
1692 #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1693 static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1694 struct kobj_attribute *kattr, char *buf) \
1696 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1698 static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1699 .attr = {.name = "remote_mode", \
1700 .mode = DEV_ATTR_RO_PERM}, \
1701 .show = wacom_show_remote##SET_ID##_mode, \
1703 static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1704 &remote##SET_ID##_mode_attr.attr, \
1707 static struct attribute_group remote##SET_ID##_serial_group = { \
1709 .attrs = remote##SET_ID##_serial_attrs, \
1712 DEVICE_EKR_ATTR_GROUP(0);
1713 DEVICE_EKR_ATTR_GROUP(1);
1714 DEVICE_EKR_ATTR_GROUP(2);
1715 DEVICE_EKR_ATTR_GROUP(3);
1716 DEVICE_EKR_ATTR_GROUP(4);
1718 static int wacom_remote_create_attr_group(struct wacom
*wacom
, __u32 serial
,
1722 struct wacom_remote
*remote
= wacom
->remote
;
1724 remote
->remotes
[index
].group
.name
= devm_kasprintf(&wacom
->hdev
->dev
,
1727 if (!remote
->remotes
[index
].group
.name
)
1730 error
= __wacom_devm_sysfs_create_group(wacom
, remote
->remote_dir
,
1731 &remote
->remotes
[index
].group
);
1733 remote
->remotes
[index
].group
.name
= NULL
;
1734 hid_err(wacom
->hdev
,
1735 "cannot create sysfs group err: %d\n", error
);
1742 static int wacom_cmd_unpair_remote(struct wacom
*wacom
, unsigned char selector
)
1744 const size_t buf_size
= 2;
1748 buf
= kzalloc(buf_size
, GFP_KERNEL
);
1752 buf
[0] = WAC_CMD_DELETE_PAIRING
;
1755 retval
= wacom_set_report(wacom
->hdev
, HID_OUTPUT_REPORT
, buf
,
1756 buf_size
, WAC_CMD_RETRIES
);
1762 static ssize_t
wacom_store_unpair_remote(struct kobject
*kobj
,
1763 struct kobj_attribute
*attr
,
1764 const char *buf
, size_t count
)
1766 unsigned char selector
= 0;
1767 struct device
*dev
= kobj_to_dev(kobj
->parent
);
1768 struct hid_device
*hdev
= to_hid_device(dev
);
1769 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1772 if (!strncmp(buf
, "*\n", 2)) {
1773 selector
= WAC_CMD_UNPAIR_ALL
;
1775 hid_info(wacom
->hdev
, "remote: unrecognized unpair code: %s\n",
1780 mutex_lock(&wacom
->lock
);
1782 err
= wacom_cmd_unpair_remote(wacom
, selector
);
1783 mutex_unlock(&wacom
->lock
);
1785 return err
< 0 ? err
: count
;
1788 static struct kobj_attribute unpair_remote_attr
= {
1789 .attr
= {.name
= "unpair_remote", .mode
= 0200},
1790 .store
= wacom_store_unpair_remote
,
1793 static const struct attribute
*remote_unpair_attrs
[] = {
1794 &unpair_remote_attr
.attr
,
1798 static void wacom_remotes_destroy(void *data
)
1800 struct wacom
*wacom
= data
;
1801 struct wacom_remote
*remote
= wacom
->remote
;
1806 kobject_put(remote
->remote_dir
);
1807 kfifo_free(&remote
->remote_fifo
);
1808 wacom
->remote
= NULL
;
1811 static int wacom_initialize_remotes(struct wacom
*wacom
)
1814 struct wacom_remote
*remote
;
1817 if (wacom
->wacom_wac
.features
.type
!= REMOTE
)
1820 remote
= devm_kzalloc(&wacom
->hdev
->dev
, sizeof(*wacom
->remote
),
1825 wacom
->remote
= remote
;
1827 spin_lock_init(&remote
->remote_lock
);
1829 error
= kfifo_alloc(&remote
->remote_fifo
,
1830 5 * sizeof(struct wacom_remote_data
),
1833 hid_err(wacom
->hdev
, "failed allocating remote_fifo\n");
1837 remote
->remotes
[0].group
= remote0_serial_group
;
1838 remote
->remotes
[1].group
= remote1_serial_group
;
1839 remote
->remotes
[2].group
= remote2_serial_group
;
1840 remote
->remotes
[3].group
= remote3_serial_group
;
1841 remote
->remotes
[4].group
= remote4_serial_group
;
1843 remote
->remote_dir
= kobject_create_and_add("wacom_remote",
1844 &wacom
->hdev
->dev
.kobj
);
1845 if (!remote
->remote_dir
)
1848 error
= sysfs_create_files(remote
->remote_dir
, remote_unpair_attrs
);
1851 hid_err(wacom
->hdev
,
1852 "cannot create sysfs group err: %d\n", error
);
1856 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
1857 wacom
->led
.groups
[i
].select
= WACOM_STATUS_UNKNOWN
;
1858 remote
->remotes
[i
].serial
= 0;
1861 error
= devm_add_action_or_reset(&wacom
->hdev
->dev
,
1862 wacom_remotes_destroy
, wacom
);
1869 static struct input_dev
*wacom_allocate_input(struct wacom
*wacom
)
1871 struct input_dev
*input_dev
;
1872 struct hid_device
*hdev
= wacom
->hdev
;
1873 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1875 input_dev
= devm_input_allocate_device(&hdev
->dev
);
1879 input_dev
->name
= wacom_wac
->features
.name
;
1880 input_dev
->phys
= hdev
->phys
;
1881 input_dev
->dev
.parent
= &hdev
->dev
;
1882 input_dev
->open
= wacom_open
;
1883 input_dev
->close
= wacom_close
;
1884 input_dev
->uniq
= hdev
->uniq
;
1885 input_dev
->id
.bustype
= hdev
->bus
;
1886 input_dev
->id
.vendor
= hdev
->vendor
;
1887 input_dev
->id
.product
= wacom_wac
->pid
? wacom_wac
->pid
: hdev
->product
;
1888 input_dev
->id
.version
= hdev
->version
;
1889 input_set_drvdata(input_dev
, wacom
);
1894 static int wacom_allocate_inputs(struct wacom
*wacom
)
1896 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1898 wacom_wac
->pen_input
= wacom_allocate_input(wacom
);
1899 wacom_wac
->touch_input
= wacom_allocate_input(wacom
);
1900 wacom_wac
->pad_input
= wacom_allocate_input(wacom
);
1901 if (!wacom_wac
->pen_input
||
1902 !wacom_wac
->touch_input
||
1903 !wacom_wac
->pad_input
)
1906 wacom_wac
->pen_input
->name
= wacom_wac
->pen_name
;
1907 wacom_wac
->touch_input
->name
= wacom_wac
->touch_name
;
1908 wacom_wac
->pad_input
->name
= wacom_wac
->pad_name
;
1913 static int wacom_register_inputs(struct wacom
*wacom
)
1915 struct input_dev
*pen_input_dev
, *touch_input_dev
, *pad_input_dev
;
1916 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1919 pen_input_dev
= wacom_wac
->pen_input
;
1920 touch_input_dev
= wacom_wac
->touch_input
;
1921 pad_input_dev
= wacom_wac
->pad_input
;
1923 if (!pen_input_dev
|| !touch_input_dev
|| !pad_input_dev
)
1926 error
= wacom_setup_pen_input_capabilities(pen_input_dev
, wacom_wac
);
1928 /* no pen in use on this interface */
1929 input_free_device(pen_input_dev
);
1930 wacom_wac
->pen_input
= NULL
;
1931 pen_input_dev
= NULL
;
1933 error
= input_register_device(pen_input_dev
);
1938 error
= wacom_setup_touch_input_capabilities(touch_input_dev
, wacom_wac
);
1940 /* no touch in use on this interface */
1941 input_free_device(touch_input_dev
);
1942 wacom_wac
->touch_input
= NULL
;
1943 touch_input_dev
= NULL
;
1945 error
= input_register_device(touch_input_dev
);
1950 error
= wacom_setup_pad_input_capabilities(pad_input_dev
, wacom_wac
);
1952 /* no pad in use on this interface */
1953 input_free_device(pad_input_dev
);
1954 wacom_wac
->pad_input
= NULL
;
1955 pad_input_dev
= NULL
;
1957 error
= input_register_device(pad_input_dev
);
1965 wacom_wac
->pad_input
= NULL
;
1966 wacom_wac
->touch_input
= NULL
;
1967 wacom_wac
->pen_input
= NULL
;
1972 * Not all devices report physical dimensions from HID.
1973 * Compute the default from hardcoded logical dimension
1974 * and resolution before driver overwrites them.
1976 static void wacom_set_default_phy(struct wacom_features
*features
)
1978 if (features
->x_resolution
) {
1979 features
->x_phy
= (features
->x_max
* 100) /
1980 features
->x_resolution
;
1981 features
->y_phy
= (features
->y_max
* 100) /
1982 features
->y_resolution
;
1986 static void wacom_calculate_res(struct wacom_features
*features
)
1988 /* set unit to "100th of a mm" for devices not reported by HID */
1989 if (!features
->unit
) {
1990 features
->unit
= 0x11;
1991 features
->unitExpo
= -3;
1994 features
->x_resolution
= wacom_calc_hid_res(features
->x_max
,
1997 features
->unitExpo
);
1998 features
->y_resolution
= wacom_calc_hid_res(features
->y_max
,
2001 features
->unitExpo
);
2004 void wacom_battery_work(struct work_struct
*work
)
2006 struct wacom
*wacom
= container_of(work
, struct wacom
, battery_work
);
2008 if ((wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
2009 !wacom
->battery
.battery
) {
2010 wacom_initialize_battery(wacom
);
2012 else if (!(wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
2013 wacom
->battery
.battery
) {
2014 wacom_destroy_battery(wacom
);
2018 static size_t wacom_compute_pktlen(struct hid_device
*hdev
)
2020 struct hid_report_enum
*report_enum
;
2021 struct hid_report
*report
;
2024 report_enum
= hdev
->report_enum
+ HID_INPUT_REPORT
;
2026 list_for_each_entry(report
, &report_enum
->report_list
, list
) {
2027 size_t report_size
= hid_report_len(report
);
2028 if (report_size
> size
)
2035 static void wacom_update_name(struct wacom
*wacom
, const char *suffix
)
2037 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2038 struct wacom_features
*features
= &wacom_wac
->features
;
2039 char name
[WACOM_NAME_MAX
];
2041 /* Generic devices name unspecified */
2042 if ((features
->type
== HID_GENERIC
) && !strcmp("Wacom HID", features
->name
)) {
2043 char *product_name
= wacom
->hdev
->name
;
2045 if (hid_is_using_ll_driver(wacom
->hdev
, &usb_hid_driver
)) {
2046 struct usb_interface
*intf
= to_usb_interface(wacom
->hdev
->dev
.parent
);
2047 struct usb_device
*dev
= interface_to_usbdev(intf
);
2048 product_name
= dev
->product
;
2051 if (wacom
->hdev
->bus
== BUS_I2C
) {
2052 snprintf(name
, sizeof(name
), "%s %X",
2053 features
->name
, wacom
->hdev
->product
);
2054 } else if (strstr(product_name
, "Wacom") ||
2055 strstr(product_name
, "wacom") ||
2056 strstr(product_name
, "WACOM")) {
2057 strlcpy(name
, product_name
, sizeof(name
));
2059 snprintf(name
, sizeof(name
), "Wacom %s", product_name
);
2062 /* strip out excess whitespaces */
2064 char *gap
= strstr(name
, " ");
2067 /* shift everything including the terminator */
2068 memmove(gap
, gap
+1, strlen(gap
));
2071 /* get rid of trailing whitespace */
2072 if (name
[strlen(name
)-1] == ' ')
2073 name
[strlen(name
)-1] = '\0';
2075 strlcpy(name
, features
->name
, sizeof(name
));
2078 snprintf(wacom_wac
->name
, sizeof(wacom_wac
->name
), "%s%s",
2081 /* Append the device type to the name */
2082 snprintf(wacom_wac
->pen_name
, sizeof(wacom_wac
->pen_name
),
2083 "%s%s Pen", name
, suffix
);
2084 snprintf(wacom_wac
->touch_name
, sizeof(wacom_wac
->touch_name
),
2085 "%s%s Finger", name
, suffix
);
2086 snprintf(wacom_wac
->pad_name
, sizeof(wacom_wac
->pad_name
),
2087 "%s%s Pad", name
, suffix
);
2090 static void wacom_release_resources(struct wacom
*wacom
)
2092 struct hid_device
*hdev
= wacom
->hdev
;
2094 if (!wacom
->resources
)
2097 devres_release_group(&hdev
->dev
, wacom
);
2099 wacom
->resources
= false;
2101 wacom
->wacom_wac
.pen_input
= NULL
;
2102 wacom
->wacom_wac
.touch_input
= NULL
;
2103 wacom
->wacom_wac
.pad_input
= NULL
;
2106 static void wacom_set_shared_values(struct wacom_wac
*wacom_wac
)
2108 if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
) {
2109 wacom_wac
->shared
->type
= wacom_wac
->features
.type
;
2110 wacom_wac
->shared
->touch_input
= wacom_wac
->touch_input
;
2113 if (wacom_wac
->has_mute_touch_switch
) {
2114 wacom_wac
->shared
->has_mute_touch_switch
= true;
2115 wacom_wac
->shared
->is_touch_on
= true;
2118 if (wacom_wac
->shared
->has_mute_touch_switch
&&
2119 wacom_wac
->shared
->touch_input
) {
2120 set_bit(EV_SW
, wacom_wac
->shared
->touch_input
->evbit
);
2121 input_set_capability(wacom_wac
->shared
->touch_input
, EV_SW
,
2126 static int wacom_parse_and_register(struct wacom
*wacom
, bool wireless
)
2128 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2129 struct wacom_features
*features
= &wacom_wac
->features
;
2130 struct hid_device
*hdev
= wacom
->hdev
;
2132 unsigned int connect_mask
= HID_CONNECT_HIDRAW
;
2134 features
->pktlen
= wacom_compute_pktlen(hdev
);
2135 if (features
->pktlen
> WACOM_PKGLEN_MAX
)
2138 if (!devres_open_group(&hdev
->dev
, wacom
, GFP_KERNEL
))
2141 wacom
->resources
= true;
2143 error
= wacom_allocate_inputs(wacom
);
2148 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
2149 * into debug mode for the touch part.
2150 * We ignore the other interfaces.
2152 if (features
->type
== BAMBOO_PAD
) {
2153 if (features
->pktlen
== WACOM_PKGLEN_PENABLED
) {
2154 features
->type
= HID_GENERIC
;
2155 } else if ((features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH
) &&
2156 (features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH_USB
)) {
2162 /* set the default size in case we do not get them from hid */
2163 wacom_set_default_phy(features
);
2165 /* Retrieve the physical and logical size for touch devices */
2166 wacom_retrieve_hid_descriptor(hdev
, features
);
2167 wacom_setup_device_quirks(wacom
);
2169 if (features
->device_type
== WACOM_DEVICETYPE_NONE
&&
2170 features
->type
!= WIRELESS
) {
2171 error
= features
->type
== HID_GENERIC
? -ENODEV
: 0;
2173 dev_warn(&hdev
->dev
, "Unknown device_type for '%s'. %s.",
2175 error
? "Ignoring" : "Assuming pen");
2180 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
2183 wacom_calculate_res(features
);
2185 wacom_update_name(wacom
, wireless
? " (WL)" : "");
2187 /* pen only Bamboo neither support touch nor pad */
2188 if ((features
->type
== BAMBOO_PEN
) &&
2189 ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) ||
2190 (features
->device_type
& WACOM_DEVICETYPE_PAD
))) {
2195 error
= wacom_add_shared_data(hdev
);
2199 if (!(features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
) &&
2200 (features
->quirks
& WACOM_QUIRK_BATTERY
)) {
2201 error
= wacom_initialize_battery(wacom
);
2206 error
= wacom_register_inputs(wacom
);
2210 if (wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
) {
2211 error
= wacom_initialize_leds(wacom
);
2215 error
= wacom_initialize_remotes(wacom
);
2220 if (features
->type
== HID_GENERIC
)
2221 connect_mask
|= HID_CONNECT_DRIVER
;
2223 /* Regular HID work starts now */
2224 error
= hid_hw_start(hdev
, connect_mask
);
2226 hid_err(hdev
, "hw start failed\n");
2231 /* Note that if query fails it is not a hard failure */
2232 wacom_query_tablet_data(wacom
);
2235 /* touch only Bamboo doesn't support pen */
2236 if ((features
->type
== BAMBOO_TOUCH
) &&
2237 (features
->device_type
& WACOM_DEVICETYPE_PEN
)) {
2238 cancel_delayed_work_sync(&wacom
->init_work
);
2239 _wacom_query_tablet_data(wacom
);
2244 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
2245 error
= hid_hw_open(hdev
);
2247 wacom_set_shared_values(wacom_wac
);
2248 devres_close_group(&hdev
->dev
, wacom
);
2255 wacom_release_resources(wacom
);
2259 static void wacom_wireless_work(struct work_struct
*work
)
2261 struct wacom
*wacom
= container_of(work
, struct wacom
, wireless_work
);
2262 struct usb_device
*usbdev
= wacom
->usbdev
;
2263 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2264 struct hid_device
*hdev1
, *hdev2
;
2265 struct wacom
*wacom1
, *wacom2
;
2266 struct wacom_wac
*wacom_wac1
, *wacom_wac2
;
2270 * Regardless if this is a disconnect or a new tablet,
2271 * remove any existing input and battery devices.
2274 wacom_destroy_battery(wacom
);
2276 /* Stylus interface */
2277 hdev1
= usb_get_intfdata(usbdev
->config
->interface
[1]);
2278 wacom1
= hid_get_drvdata(hdev1
);
2279 wacom_wac1
= &(wacom1
->wacom_wac
);
2280 wacom_release_resources(wacom1
);
2282 /* Touch interface */
2283 hdev2
= usb_get_intfdata(usbdev
->config
->interface
[2]);
2284 wacom2
= hid_get_drvdata(hdev2
);
2285 wacom_wac2
= &(wacom2
->wacom_wac
);
2286 wacom_release_resources(wacom2
);
2288 if (wacom_wac
->pid
== 0) {
2289 hid_info(wacom
->hdev
, "wireless tablet disconnected\n");
2291 const struct hid_device_id
*id
= wacom_ids
;
2293 hid_info(wacom
->hdev
, "wireless tablet connected with PID %x\n",
2297 if (id
->vendor
== USB_VENDOR_ID_WACOM
&&
2298 id
->product
== wacom_wac
->pid
)
2304 hid_info(wacom
->hdev
, "ignoring unknown PID.\n");
2308 /* Stylus interface */
2309 wacom_wac1
->features
=
2310 *((struct wacom_features
*)id
->driver_data
);
2312 wacom_wac1
->pid
= wacom_wac
->pid
;
2314 error
= wacom_parse_and_register(wacom1
, true);
2318 /* Touch interface */
2319 if (wacom_wac1
->features
.touch_max
||
2320 (wacom_wac1
->features
.type
>= INTUOSHT
&&
2321 wacom_wac1
->features
.type
<= BAMBOO_PT
)) {
2322 wacom_wac2
->features
=
2323 *((struct wacom_features
*)id
->driver_data
);
2324 wacom_wac2
->pid
= wacom_wac
->pid
;
2326 error
= wacom_parse_and_register(wacom2
, true);
2331 strlcpy(wacom_wac
->name
, wacom_wac1
->name
,
2332 sizeof(wacom_wac
->name
));
2333 error
= wacom_initialize_battery(wacom
);
2341 wacom_release_resources(wacom1
);
2342 wacom_release_resources(wacom2
);
2346 static void wacom_remote_destroy_one(struct wacom
*wacom
, unsigned int index
)
2348 struct wacom_remote
*remote
= wacom
->remote
;
2349 u32 serial
= remote
->remotes
[index
].serial
;
2351 unsigned long flags
;
2353 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
2354 if (remote
->remotes
[i
].serial
== serial
) {
2356 spin_lock_irqsave(&remote
->remote_lock
, flags
);
2357 remote
->remotes
[i
].registered
= false;
2358 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2360 if (remote
->remotes
[i
].battery
.battery
)
2361 devres_release_group(&wacom
->hdev
->dev
,
2362 &remote
->remotes
[i
].battery
.bat_desc
);
2364 if (remote
->remotes
[i
].group
.name
)
2365 devres_release_group(&wacom
->hdev
->dev
,
2366 &remote
->remotes
[i
]);
2368 remote
->remotes
[i
].serial
= 0;
2369 remote
->remotes
[i
].group
.name
= NULL
;
2370 remote
->remotes
[i
].battery
.battery
= NULL
;
2371 wacom
->led
.groups
[i
].select
= WACOM_STATUS_UNKNOWN
;
2376 static int wacom_remote_create_one(struct wacom
*wacom
, u32 serial
,
2379 struct wacom_remote
*remote
= wacom
->remote
;
2380 struct device
*dev
= &wacom
->hdev
->dev
;
2383 /* A remote can pair more than once with an EKR,
2384 * check to make sure this serial isn't already paired.
2386 for (k
= 0; k
< WACOM_MAX_REMOTES
; k
++) {
2387 if (remote
->remotes
[k
].serial
== serial
)
2391 if (k
< WACOM_MAX_REMOTES
) {
2392 remote
->remotes
[index
].serial
= serial
;
2396 if (!devres_open_group(dev
, &remote
->remotes
[index
], GFP_KERNEL
))
2399 error
= wacom_remote_create_attr_group(wacom
, serial
, index
);
2403 remote
->remotes
[index
].input
= wacom_allocate_input(wacom
);
2404 if (!remote
->remotes
[index
].input
) {
2408 remote
->remotes
[index
].input
->uniq
= remote
->remotes
[index
].group
.name
;
2409 remote
->remotes
[index
].input
->name
= wacom
->wacom_wac
.pad_name
;
2411 if (!remote
->remotes
[index
].input
->name
) {
2416 error
= wacom_setup_pad_input_capabilities(remote
->remotes
[index
].input
,
2421 remote
->remotes
[index
].serial
= serial
;
2423 error
= input_register_device(remote
->remotes
[index
].input
);
2427 error
= wacom_led_groups_alloc_and_register_one(
2428 &remote
->remotes
[index
].input
->dev
,
2429 wacom
, index
, 3, true);
2433 remote
->remotes
[index
].registered
= true;
2435 devres_close_group(dev
, &remote
->remotes
[index
]);
2439 devres_release_group(dev
, &remote
->remotes
[index
]);
2440 remote
->remotes
[index
].serial
= 0;
2444 static int wacom_remote_attach_battery(struct wacom
*wacom
, int index
)
2446 struct wacom_remote
*remote
= wacom
->remote
;
2449 if (!remote
->remotes
[index
].registered
)
2452 if (remote
->remotes
[index
].battery
.battery
)
2455 if (wacom
->led
.groups
[index
].select
== WACOM_STATUS_UNKNOWN
)
2458 error
= __wacom_initialize_battery(wacom
,
2459 &wacom
->remote
->remotes
[index
].battery
);
2466 static void wacom_remote_work(struct work_struct
*work
)
2468 struct wacom
*wacom
= container_of(work
, struct wacom
, remote_work
);
2469 struct wacom_remote
*remote
= wacom
->remote
;
2470 struct wacom_remote_data data
;
2471 unsigned long flags
;
2476 spin_lock_irqsave(&remote
->remote_lock
, flags
);
2478 count
= kfifo_out(&remote
->remote_fifo
, &data
, sizeof(data
));
2480 if (count
!= sizeof(data
)) {
2481 hid_err(wacom
->hdev
,
2482 "workitem triggered without status available\n");
2483 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2487 if (!kfifo_is_empty(&remote
->remote_fifo
))
2488 wacom_schedule_work(&wacom
->wacom_wac
, WACOM_WORKER_REMOTE
);
2490 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2492 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
2493 serial
= data
.remote
[i
].serial
;
2494 if (data
.remote
[i
].connected
) {
2496 if (remote
->remotes
[i
].serial
== serial
) {
2497 wacom_remote_attach_battery(wacom
, i
);
2501 if (remote
->remotes
[i
].serial
)
2502 wacom_remote_destroy_one(wacom
, i
);
2504 wacom_remote_create_one(wacom
, serial
, i
);
2506 } else if (remote
->remotes
[i
].serial
) {
2507 wacom_remote_destroy_one(wacom
, i
);
2512 static void wacom_mode_change_work(struct work_struct
*work
)
2514 struct wacom
*wacom
= container_of(work
, struct wacom
, mode_change_work
);
2515 struct wacom_shared
*shared
= wacom
->wacom_wac
.shared
;
2516 struct wacom
*wacom1
= NULL
;
2517 struct wacom
*wacom2
= NULL
;
2518 bool is_direct
= wacom
->wacom_wac
.is_direct_mode
;
2522 wacom1
= hid_get_drvdata(shared
->pen
);
2523 wacom_release_resources(wacom1
);
2524 hid_hw_stop(wacom1
->hdev
);
2525 wacom1
->wacom_wac
.has_mode_change
= true;
2526 wacom1
->wacom_wac
.is_direct_mode
= is_direct
;
2529 if (shared
->touch
) {
2530 wacom2
= hid_get_drvdata(shared
->touch
);
2531 wacom_release_resources(wacom2
);
2532 hid_hw_stop(wacom2
->hdev
);
2533 wacom2
->wacom_wac
.has_mode_change
= true;
2534 wacom2
->wacom_wac
.is_direct_mode
= is_direct
;
2538 error
= wacom_parse_and_register(wacom1
, false);
2544 error
= wacom_parse_and_register(wacom2
, false);
2552 static int wacom_probe(struct hid_device
*hdev
,
2553 const struct hid_device_id
*id
)
2555 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
2556 struct usb_device
*dev
= interface_to_usbdev(intf
);
2557 struct wacom
*wacom
;
2558 struct wacom_wac
*wacom_wac
;
2559 struct wacom_features
*features
;
2562 if (!id
->driver_data
)
2565 hdev
->quirks
|= HID_QUIRK_NO_INIT_REPORTS
;
2567 /* hid-core sets this quirk for the boot interface */
2568 hdev
->quirks
&= ~HID_QUIRK_NOGET
;
2570 wacom
= devm_kzalloc(&hdev
->dev
, sizeof(struct wacom
), GFP_KERNEL
);
2574 hid_set_drvdata(hdev
, wacom
);
2577 wacom_wac
= &wacom
->wacom_wac
;
2578 wacom_wac
->features
= *((struct wacom_features
*)id
->driver_data
);
2579 features
= &wacom_wac
->features
;
2581 if (features
->check_for_hid_type
&& features
->hid_type
!= hdev
->type
) {
2586 wacom_wac
->hid_data
.inputmode
= -1;
2587 wacom_wac
->mode_report
= -1;
2589 wacom
->usbdev
= dev
;
2591 mutex_init(&wacom
->lock
);
2592 INIT_DELAYED_WORK(&wacom
->init_work
, wacom_init_work
);
2593 INIT_WORK(&wacom
->wireless_work
, wacom_wireless_work
);
2594 INIT_WORK(&wacom
->battery_work
, wacom_battery_work
);
2595 INIT_WORK(&wacom
->remote_work
, wacom_remote_work
);
2596 INIT_WORK(&wacom
->mode_change_work
, wacom_mode_change_work
);
2598 /* ask for the report descriptor to be loaded by HID */
2599 error
= hid_parse(hdev
);
2601 hid_err(hdev
, "parse failed\n");
2605 error
= wacom_parse_and_register(wacom
, false);
2609 if (hdev
->bus
== BUS_BLUETOOTH
) {
2610 error
= device_create_file(&hdev
->dev
, &dev_attr_speed
);
2613 "can't create sysfs speed attribute err: %d\n",
2620 hid_set_drvdata(hdev
, NULL
);
2624 static void wacom_remove(struct hid_device
*hdev
)
2626 struct wacom
*wacom
= hid_get_drvdata(hdev
);
2627 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2628 struct wacom_features
*features
= &wacom_wac
->features
;
2630 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
2635 cancel_delayed_work_sync(&wacom
->init_work
);
2636 cancel_work_sync(&wacom
->wireless_work
);
2637 cancel_work_sync(&wacom
->battery_work
);
2638 cancel_work_sync(&wacom
->remote_work
);
2639 cancel_work_sync(&wacom
->mode_change_work
);
2640 if (hdev
->bus
== BUS_BLUETOOTH
)
2641 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
2643 /* make sure we don't trigger the LEDs */
2644 wacom_led_groups_release(wacom
);
2646 if (wacom
->wacom_wac
.features
.type
!= REMOTE
)
2647 wacom_release_resources(wacom
);
2649 hid_set_drvdata(hdev
, NULL
);
2653 static int wacom_resume(struct hid_device
*hdev
)
2655 struct wacom
*wacom
= hid_get_drvdata(hdev
);
2657 mutex_lock(&wacom
->lock
);
2659 /* switch to wacom mode first */
2660 _wacom_query_tablet_data(wacom
);
2661 wacom_led_control(wacom
);
2663 mutex_unlock(&wacom
->lock
);
2668 static int wacom_reset_resume(struct hid_device
*hdev
)
2670 return wacom_resume(hdev
);
2672 #endif /* CONFIG_PM */
2674 static struct hid_driver wacom_driver
= {
2676 .id_table
= wacom_ids
,
2677 .probe
= wacom_probe
,
2678 .remove
= wacom_remove
,
2679 .report
= wacom_wac_report
,
2681 .resume
= wacom_resume
,
2682 .reset_resume
= wacom_reset_resume
,
2684 .raw_event
= wacom_raw_event
,
2686 module_hid_driver(wacom_driver
);
2688 MODULE_VERSION(DRIVER_VERSION
);
2689 MODULE_AUTHOR(DRIVER_AUTHOR
);
2690 MODULE_DESCRIPTION(DRIVER_DESC
);
2691 MODULE_LICENSE("GPL");