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
29 #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
30 #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
31 #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP)
33 static int wacom_get_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
34 size_t size
, unsigned int retries
)
39 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
41 } while ((retval
== -ETIMEDOUT
|| retval
== -EAGAIN
) && --retries
);
44 hid_err(hdev
, "wacom_get_report: ran out of retries "
45 "(last error = %d)\n", retval
);
50 static int wacom_set_report(struct hid_device
*hdev
, u8 type
, u8
*buf
,
51 size_t size
, unsigned int retries
)
56 retval
= hid_hw_raw_request(hdev
, buf
[0], buf
, size
, type
,
58 } while ((retval
== -ETIMEDOUT
|| retval
== -EAGAIN
) && --retries
);
61 hid_err(hdev
, "wacom_set_report: ran out of retries "
62 "(last error = %d)\n", retval
);
67 static int wacom_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
68 u8
*raw_data
, int size
)
70 struct wacom
*wacom
= hid_get_drvdata(hdev
);
72 if (size
> WACOM_PKGLEN_MAX
)
75 memcpy(wacom
->wacom_wac
.data
, raw_data
, size
);
77 wacom_wac_irq(&wacom
->wacom_wac
, size
);
82 static int wacom_open(struct input_dev
*dev
)
84 struct wacom
*wacom
= input_get_drvdata(dev
);
86 return hid_hw_open(wacom
->hdev
);
89 static void wacom_close(struct input_dev
*dev
)
91 struct wacom
*wacom
= input_get_drvdata(dev
);
94 * wacom->hdev should never be null, but surprisingly, I had the case
95 * once while unplugging the Wacom Wireless Receiver.
98 hid_hw_close(wacom
->hdev
);
102 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
104 static int wacom_calc_hid_res(int logical_extents
, int physical_extents
,
105 unsigned unit
, int exponent
)
107 struct hid_field field
= {
108 .logical_maximum
= logical_extents
,
109 .physical_maximum
= physical_extents
,
111 .unit_exponent
= exponent
,
114 return hidinput_calc_abs_res(&field
, ABS_X
);
117 static void wacom_feature_mapping(struct hid_device
*hdev
,
118 struct hid_field
*field
, struct hid_usage
*usage
)
120 struct wacom
*wacom
= hid_get_drvdata(hdev
);
121 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
122 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
127 switch (usage
->hid
) {
128 case HID_DG_CONTACTMAX
:
129 /* leave touch_max as is if predefined */
130 if (!features
->touch_max
) {
132 data
= kzalloc(2, GFP_KERNEL
);
135 data
[0] = field
->report
->id
;
136 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
137 data
, 2, WAC_CMD_RETRIES
);
139 features
->touch_max
= data
[1];
141 features
->touch_max
= 16;
142 hid_warn(hdev
, "wacom_feature_mapping: "
143 "could not get HID_DG_CONTACTMAX, "
144 "defaulting to %d\n",
145 features
->touch_max
);
150 case HID_DG_INPUTMODE
:
151 /* Ignore if value index is out of bounds. */
152 if (usage
->usage_index
>= field
->report_count
) {
153 dev_err(&hdev
->dev
, "HID_DG_INPUTMODE out of range\n");
157 hid_data
->inputmode
= field
->report
->id
;
158 hid_data
->inputmode_index
= usage
->usage_index
;
161 case HID_UP_DIGITIZER
:
162 if (field
->report
->id
== 0x0B &&
163 (field
->application
== WACOM_HID_G9_PEN
||
164 field
->application
== WACOM_HID_G11_PEN
)) {
165 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
166 wacom
->wacom_wac
.mode_value
= 0;
170 case WACOM_HID_WD_DATAMODE
:
171 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
172 wacom
->wacom_wac
.mode_value
= 2;
175 case WACOM_HID_UP_G9
:
176 case WACOM_HID_UP_G11
:
177 if (field
->report
->id
== 0x03 &&
178 (field
->application
== WACOM_HID_G9_TOUCHSCREEN
||
179 field
->application
== WACOM_HID_G11_TOUCHSCREEN
)) {
180 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
181 wacom
->wacom_wac
.mode_value
= 0;
184 case WACOM_HID_WD_OFFSETLEFT
:
185 case WACOM_HID_WD_OFFSETTOP
:
186 case WACOM_HID_WD_OFFSETRIGHT
:
187 case WACOM_HID_WD_OFFSETBOTTOM
:
189 n
= hid_report_len(field
->report
);
190 data
= hid_alloc_report_buf(field
->report
, GFP_KERNEL
);
193 data
[0] = field
->report
->id
;
194 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
195 data
, n
, WAC_CMD_RETRIES
);
197 ret
= hid_report_raw_event(hdev
, HID_FEATURE_REPORT
,
200 hid_warn(hdev
, "%s: could not retrieve sensor offsets\n",
209 * Interface Descriptor of wacom devices can be incomplete and
210 * inconsistent so wacom_features table is used to store stylus
211 * device's packet lengths, various maximum values, and tablet
212 * resolution based on product ID's.
214 * For devices that contain 2 interfaces, wacom_features table is
215 * inaccurate for the touch interface. Since the Interface Descriptor
216 * for touch interfaces has pretty complete data, this function exists
217 * to query tablet for this missing information instead of hard coding in
218 * an additional table.
220 * A typical Interface Descriptor for a stylus will contain a
221 * boot mouse application collection that is not of interest and this
222 * function will ignore it.
224 * It also contains a digitizer application collection that also is not
225 * of interest since any information it contains would be duplicate
226 * of what is in wacom_features. Usually it defines a report of an array
227 * of bytes that could be used as max length of the stylus packet returned.
228 * If it happens to define a Digitizer-Stylus Physical Collection then
229 * the X and Y logical values contain valid data but it is ignored.
231 * A typical Interface Descriptor for a touch interface will contain a
232 * Digitizer-Finger Physical Collection which will define both logical
233 * X/Y maximum as well as the physical size of tablet. Since touch
234 * interfaces haven't supported pressure or distance, this is enough
235 * information to override invalid values in the wacom_features table.
237 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
238 * data. We deal with them after returning from this function.
240 static void wacom_usage_mapping(struct hid_device
*hdev
,
241 struct hid_field
*field
, struct hid_usage
*usage
)
243 struct wacom
*wacom
= hid_get_drvdata(hdev
);
244 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
245 bool finger
= WACOM_FINGER_FIELD(field
);
246 bool pen
= WACOM_PEN_FIELD(field
);
249 * Requiring Stylus Usage will ignore boot mouse
250 * X/Y values and some cases of invalid Digitizer X/Y
251 * values commonly reported.
254 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
256 features
->device_type
|= WACOM_DEVICETYPE_TOUCH
;
261 * Bamboo models do not support HID_DG_CONTACTMAX.
262 * And, Bamboo Pen only descriptor contains touch.
264 if (features
->type
> BAMBOO_PT
) {
265 /* ISDv4 touch devices at least supports one touch point */
266 if (finger
&& !features
->touch_max
)
267 features
->touch_max
= 1;
271 * ISDv4 devices which predate HID's adoption of the
272 * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its
273 * position instead. We can accurately detect if a
274 * usage with that value should be HID_DG_BARRELSWITCH2
275 * based on the surrounding usages, which have remained
276 * constant across generations.
278 if (features
->type
== HID_GENERIC
&&
279 usage
->hid
== 0x000D0000 &&
280 field
->application
== HID_DG_PEN
&&
281 field
->physical
== HID_DG_STYLUS
) {
282 int i
= usage
->usage_index
;
284 if (i
-4 >= 0 && i
+1 < field
->maxusage
&&
285 field
->usage
[i
-4].hid
== HID_DG_TIPSWITCH
&&
286 field
->usage
[i
-3].hid
== HID_DG_BARRELSWITCH
&&
287 field
->usage
[i
-2].hid
== HID_DG_ERASER
&&
288 field
->usage
[i
-1].hid
== HID_DG_INVERT
&&
289 field
->usage
[i
+1].hid
== HID_DG_INRANGE
) {
290 usage
->hid
= HID_DG_BARRELSWITCH2
;
294 switch (usage
->hid
) {
296 features
->x_max
= field
->logical_maximum
;
298 features
->x_phy
= field
->physical_maximum
;
299 if ((features
->type
!= BAMBOO_PT
) &&
300 (features
->type
!= BAMBOO_TOUCH
)) {
301 features
->unit
= field
->unit
;
302 features
->unitExpo
= field
->unit_exponent
;
307 features
->y_max
= field
->logical_maximum
;
309 features
->y_phy
= field
->physical_maximum
;
310 if ((features
->type
!= BAMBOO_PT
) &&
311 (features
->type
!= BAMBOO_TOUCH
)) {
312 features
->unit
= field
->unit
;
313 features
->unitExpo
= field
->unit_exponent
;
317 case HID_DG_TIPPRESSURE
:
319 features
->pressure_max
= field
->logical_maximum
;
323 if (features
->type
== HID_GENERIC
)
324 wacom_wac_usage_mapping(hdev
, field
, usage
);
327 static void wacom_post_parse_hid(struct hid_device
*hdev
,
328 struct wacom_features
*features
)
330 struct wacom
*wacom
= hid_get_drvdata(hdev
);
331 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
333 if (features
->type
== HID_GENERIC
) {
334 /* Any last-minute generic device setup */
335 if (features
->touch_max
> 1) {
336 input_mt_init_slots(wacom_wac
->touch_input
, wacom_wac
->features
.touch_max
,
342 static void wacom_parse_hid(struct hid_device
*hdev
,
343 struct wacom_features
*features
)
345 struct hid_report_enum
*rep_enum
;
346 struct hid_report
*hreport
;
349 /* check features first */
350 rep_enum
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
351 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
352 for (i
= 0; i
< hreport
->maxfield
; i
++) {
353 /* Ignore if report count is out of bounds. */
354 if (hreport
->field
[i
]->report_count
< 1)
357 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++) {
358 wacom_feature_mapping(hdev
, hreport
->field
[i
],
359 hreport
->field
[i
]->usage
+ j
);
364 /* now check the input usages */
365 rep_enum
= &hdev
->report_enum
[HID_INPUT_REPORT
];
366 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
368 if (!hreport
->maxfield
)
371 for (i
= 0; i
< hreport
->maxfield
; i
++)
372 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++)
373 wacom_usage_mapping(hdev
, hreport
->field
[i
],
374 hreport
->field
[i
]->usage
+ j
);
377 wacom_post_parse_hid(hdev
, features
);
380 static int wacom_hid_set_device_mode(struct hid_device
*hdev
)
382 struct wacom
*wacom
= hid_get_drvdata(hdev
);
383 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
384 struct hid_report
*r
;
385 struct hid_report_enum
*re
;
387 if (hid_data
->inputmode
< 0)
390 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
391 r
= re
->report_id_hash
[hid_data
->inputmode
];
393 r
->field
[0]->value
[hid_data
->inputmode_index
] = 2;
394 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
399 static int wacom_set_device_mode(struct hid_device
*hdev
,
400 struct wacom_wac
*wacom_wac
)
403 struct hid_report
*r
;
404 struct hid_report_enum
*re
;
406 int error
= -ENOMEM
, limit
= 0;
408 if (wacom_wac
->mode_report
< 0)
411 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
412 r
= re
->report_id_hash
[wacom_wac
->mode_report
];
416 rep_data
= hid_alloc_report_buf(r
, GFP_KERNEL
);
420 length
= hid_report_len(r
);
423 rep_data
[0] = wacom_wac
->mode_report
;
424 rep_data
[1] = wacom_wac
->mode_value
;
426 error
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
,
429 error
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
430 rep_data
, length
, 1);
431 } while (error
>= 0 &&
432 rep_data
[1] != wacom_wac
->mode_report
&&
433 limit
++ < WAC_MSG_RETRIES
);
437 return error
< 0 ? error
: 0;
440 static int wacom_bt_query_tablet_data(struct hid_device
*hdev
, u8 speed
,
441 struct wacom_features
*features
)
443 struct wacom
*wacom
= hid_get_drvdata(hdev
);
447 switch (features
->type
) {
451 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
455 rep_data
[0] = speed
== 0 ? 0x05 : 0x06;
458 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
,
462 wacom
->wacom_wac
.bt_high_speed
= speed
;
468 * Note that if the raw queries fail, it's not a hard failure
469 * and it is safe to continue
471 hid_warn(hdev
, "failed to poke device, command %d, err %d\n",
476 wacom
->wacom_wac
.bt_features
&= ~0x20;
478 wacom
->wacom_wac
.bt_features
|= 0x20;
481 rep_data
[1] = wacom
->wacom_wac
.bt_features
;
483 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
486 wacom
->wacom_wac
.bt_high_speed
= speed
;
494 * Switch the tablet into its most-capable mode. Wacom tablets are
495 * typically configured to power-up in a mode which sends mouse-like
496 * reports to the OS. To get absolute position, pressure data, etc.
497 * from the tablet, it is necessary to switch the tablet out of this
498 * mode and into one which sends the full range of tablet data.
500 static int wacom_query_tablet_data(struct hid_device
*hdev
,
501 struct wacom_features
*features
)
503 struct wacom
*wacom
= hid_get_drvdata(hdev
);
504 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
506 if (hdev
->bus
== BUS_BLUETOOTH
)
507 return wacom_bt_query_tablet_data(hdev
, 1, features
);
509 if (features
->type
!= HID_GENERIC
) {
510 if (features
->device_type
& WACOM_DEVICETYPE_TOUCH
) {
511 if (features
->type
> TABLETPC
) {
512 /* MT Tablet PC touch */
513 wacom_wac
->mode_report
= 3;
514 wacom_wac
->mode_value
= 4;
515 } else if (features
->type
== WACOM_24HDT
) {
516 wacom_wac
->mode_report
= 18;
517 wacom_wac
->mode_value
= 2;
518 } else if (features
->type
== WACOM_27QHDT
) {
519 wacom_wac
->mode_report
= 131;
520 wacom_wac
->mode_value
= 2;
521 } else if (features
->type
== BAMBOO_PAD
) {
522 wacom_wac
->mode_report
= 2;
523 wacom_wac
->mode_value
= 2;
525 } else if (features
->device_type
& WACOM_DEVICETYPE_PEN
) {
526 if (features
->type
<= BAMBOO_PT
) {
527 wacom_wac
->mode_report
= 2;
528 wacom_wac
->mode_value
= 2;
533 wacom_set_device_mode(hdev
, wacom_wac
);
535 if (features
->type
== HID_GENERIC
)
536 return wacom_hid_set_device_mode(hdev
);
541 static void wacom_retrieve_hid_descriptor(struct hid_device
*hdev
,
542 struct wacom_features
*features
)
544 struct wacom
*wacom
= hid_get_drvdata(hdev
);
545 struct usb_interface
*intf
= wacom
->intf
;
547 /* default features */
548 features
->x_fuzz
= 4;
549 features
->y_fuzz
= 4;
550 features
->pressure_fuzz
= 0;
551 features
->distance_fuzz
= 1;
552 features
->tilt_fuzz
= 1;
555 * The wireless device HID is basic and layout conflicts with
556 * other tablets (monitor and touch interface can look like pen).
557 * Skip the query for this type and modify defaults based on
560 if (features
->type
== WIRELESS
) {
561 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 0)
562 features
->device_type
= WACOM_DEVICETYPE_WL_MONITOR
;
564 features
->device_type
= WACOM_DEVICETYPE_NONE
;
568 wacom_parse_hid(hdev
, features
);
571 struct wacom_hdev_data
{
572 struct list_head list
;
574 struct hid_device
*dev
;
575 struct wacom_shared shared
;
578 static LIST_HEAD(wacom_udev_list
);
579 static DEFINE_MUTEX(wacom_udev_list_lock
);
581 static bool compare_device_paths(struct hid_device
*hdev_a
,
582 struct hid_device
*hdev_b
, char separator
)
584 int n1
= strrchr(hdev_a
->phys
, separator
) - hdev_a
->phys
;
585 int n2
= strrchr(hdev_b
->phys
, separator
) - hdev_b
->phys
;
587 if (n1
!= n2
|| n1
<= 0 || n2
<= 0)
590 return !strncmp(hdev_a
->phys
, hdev_b
->phys
, n1
);
593 static bool wacom_are_sibling(struct hid_device
*hdev
,
594 struct hid_device
*sibling
)
596 struct wacom
*wacom
= hid_get_drvdata(hdev
);
597 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
598 struct wacom
*sibling_wacom
= hid_get_drvdata(sibling
);
599 struct wacom_features
*sibling_features
= &sibling_wacom
->wacom_wac
.features
;
600 __u32 oVid
= features
->oVid
? features
->oVid
: hdev
->vendor
;
601 __u32 oPid
= features
->oPid
? features
->oPid
: hdev
->product
;
603 /* The defined oVid/oPid must match that of the sibling */
604 if (features
->oVid
!= HID_ANY_ID
&& sibling
->vendor
!= oVid
)
606 if (features
->oPid
!= HID_ANY_ID
&& sibling
->product
!= oPid
)
610 * Devices with the same VID/PID must share the same physical
611 * device path, while those with different VID/PID must share
612 * the same physical parent device path.
614 if (hdev
->vendor
== sibling
->vendor
&& hdev
->product
== sibling
->product
) {
615 if (!compare_device_paths(hdev
, sibling
, '/'))
618 if (!compare_device_paths(hdev
, sibling
, '.'))
622 /* Skip the remaining heuristics unless you are a HID_GENERIC device */
623 if (features
->type
!= HID_GENERIC
)
627 * Direct-input devices may not be siblings of indirect-input
630 if ((features
->device_type
& WACOM_DEVICETYPE_DIRECT
) &&
631 !(sibling_features
->device_type
& WACOM_DEVICETYPE_DIRECT
))
635 * Indirect-input devices may not be siblings of direct-input
638 if (!(features
->device_type
& WACOM_DEVICETYPE_DIRECT
) &&
639 (sibling_features
->device_type
& WACOM_DEVICETYPE_DIRECT
))
642 /* Pen devices may only be siblings of touch devices */
643 if ((features
->device_type
& WACOM_DEVICETYPE_PEN
) &&
644 !(sibling_features
->device_type
& WACOM_DEVICETYPE_TOUCH
))
647 /* Touch devices may only be siblings of pen devices */
648 if ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) &&
649 !(sibling_features
->device_type
& WACOM_DEVICETYPE_PEN
))
653 * No reason could be found for these two devices to NOT be
654 * siblings, so there's a good chance they ARE siblings
659 static struct wacom_hdev_data
*wacom_get_hdev_data(struct hid_device
*hdev
)
661 struct wacom_hdev_data
*data
;
663 /* Try to find an already-probed interface from the same device */
664 list_for_each_entry(data
, &wacom_udev_list
, list
) {
665 if (compare_device_paths(hdev
, data
->dev
, '/'))
669 /* Fallback to finding devices that appear to be "siblings" */
670 list_for_each_entry(data
, &wacom_udev_list
, list
) {
671 if (wacom_are_sibling(hdev
, data
->dev
)) {
672 kref_get(&data
->kref
);
680 static void wacom_release_shared_data(struct kref
*kref
)
682 struct wacom_hdev_data
*data
=
683 container_of(kref
, struct wacom_hdev_data
, kref
);
685 mutex_lock(&wacom_udev_list_lock
);
686 list_del(&data
->list
);
687 mutex_unlock(&wacom_udev_list_lock
);
692 static void wacom_remove_shared_data(void *res
)
694 struct wacom
*wacom
= res
;
695 struct wacom_hdev_data
*data
;
696 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
698 if (wacom_wac
->shared
) {
699 data
= container_of(wacom_wac
->shared
, struct wacom_hdev_data
,
702 if (wacom_wac
->shared
->touch
== wacom
->hdev
)
703 wacom_wac
->shared
->touch
= NULL
;
704 else if (wacom_wac
->shared
->pen
== wacom
->hdev
)
705 wacom_wac
->shared
->pen
= NULL
;
707 kref_put(&data
->kref
, wacom_release_shared_data
);
708 wacom_wac
->shared
= NULL
;
712 static int wacom_add_shared_data(struct hid_device
*hdev
)
714 struct wacom
*wacom
= hid_get_drvdata(hdev
);
715 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
716 struct wacom_hdev_data
*data
;
719 mutex_lock(&wacom_udev_list_lock
);
721 data
= wacom_get_hdev_data(hdev
);
723 data
= kzalloc(sizeof(struct wacom_hdev_data
), GFP_KERNEL
);
729 kref_init(&data
->kref
);
731 list_add_tail(&data
->list
, &wacom_udev_list
);
734 wacom_wac
->shared
= &data
->shared
;
736 retval
= devm_add_action(&hdev
->dev
, wacom_remove_shared_data
, wacom
);
738 mutex_unlock(&wacom_udev_list_lock
);
739 wacom_remove_shared_data(wacom
);
743 if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
)
744 wacom_wac
->shared
->touch
= hdev
;
745 else if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_PEN
)
746 wacom_wac
->shared
->pen
= hdev
;
749 mutex_unlock(&wacom_udev_list_lock
);
753 static int wacom_led_control(struct wacom
*wacom
)
757 unsigned char report_id
= WAC_CMD_LED_CONTROL
;
760 if (!hid_get_drvdata(wacom
->hdev
))
763 if (!wacom
->led
.groups
)
766 if (wacom
->wacom_wac
.pid
) { /* wireless connected */
767 report_id
= WAC_CMD_WL_LED_CONTROL
;
770 buf
= kzalloc(buf_size
, GFP_KERNEL
);
774 if (wacom
->wacom_wac
.features
.type
>= INTUOS5S
&&
775 wacom
->wacom_wac
.features
.type
<= INTUOSPL
) {
777 * Touch Ring and crop mark LED luminance may take on
778 * one of four values:
779 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
781 int ring_led
= wacom
->led
.groups
[0].select
& 0x03;
782 int ring_lum
= (((wacom
->led
.llv
& 0x60) >> 5) - 1) & 0x03;
784 unsigned char led_bits
= (crop_lum
<< 4) | (ring_lum
<< 2) | (ring_led
);
787 if (wacom
->wacom_wac
.pid
) {
788 wacom_get_report(wacom
->hdev
, HID_FEATURE_REPORT
,
789 buf
, buf_size
, WAC_CMD_RETRIES
);
796 int led
= wacom
->led
.groups
[0].select
| 0x4;
798 if (wacom
->wacom_wac
.features
.type
== WACOM_21UX2
||
799 wacom
->wacom_wac
.features
.type
== WACOM_24HD
)
800 led
|= (wacom
->led
.groups
[1].select
<< 4) | 0x40;
804 buf
[2] = wacom
->led
.llv
;
805 buf
[3] = wacom
->led
.hlv
;
806 buf
[4] = wacom
->led
.img_lum
;
809 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, buf_size
,
816 static int wacom_led_putimage(struct wacom
*wacom
, int button_id
, u8 xfer_id
,
817 const unsigned len
, const void *img
)
821 const unsigned chunk_len
= len
/ 4; /* 4 chunks are needed to be sent */
823 buf
= kzalloc(chunk_len
+ 3 , GFP_KERNEL
);
827 /* Send 'start' command */
828 buf
[0] = WAC_CMD_ICON_START
;
830 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
836 buf
[1] = button_id
& 0x07;
837 for (i
= 0; i
< 4; i
++) {
839 memcpy(buf
+ 3, img
+ i
* chunk_len
, chunk_len
);
841 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
,
842 buf
, chunk_len
+ 3, WAC_CMD_RETRIES
);
848 buf
[0] = WAC_CMD_ICON_START
;
850 wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
858 static ssize_t
wacom_led_select_store(struct device
*dev
, int set_id
,
859 const char *buf
, size_t count
)
861 struct hid_device
*hdev
= to_hid_device(dev
);
862 struct wacom
*wacom
= hid_get_drvdata(hdev
);
866 err
= kstrtouint(buf
, 10, &id
);
870 mutex_lock(&wacom
->lock
);
872 wacom
->led
.groups
[set_id
].select
= id
& 0x3;
873 err
= wacom_led_control(wacom
);
875 mutex_unlock(&wacom
->lock
);
877 return err
< 0 ? err
: count
;
880 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
881 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
882 struct device_attribute *attr, const char *buf, size_t count) \
884 return wacom_led_select_store(dev, SET_ID, buf, count); \
886 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
887 struct device_attribute *attr, char *buf) \
889 struct hid_device *hdev = to_hid_device(dev);\
890 struct wacom *wacom = hid_get_drvdata(hdev); \
891 return scnprintf(buf, PAGE_SIZE, "%d\n", \
892 wacom->led.groups[SET_ID].select); \
894 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
895 wacom_led##SET_ID##_select_show, \
896 wacom_led##SET_ID##_select_store)
898 DEVICE_LED_SELECT_ATTR(0);
899 DEVICE_LED_SELECT_ATTR(1);
901 static ssize_t
wacom_luminance_store(struct wacom
*wacom
, u8
*dest
,
902 const char *buf
, size_t count
)
907 err
= kstrtouint(buf
, 10, &value
);
911 mutex_lock(&wacom
->lock
);
913 *dest
= value
& 0x7f;
914 err
= wacom_led_control(wacom
);
916 mutex_unlock(&wacom
->lock
);
918 return err
< 0 ? err
: count
;
921 #define DEVICE_LUMINANCE_ATTR(name, field) \
922 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
923 struct device_attribute *attr, const char *buf, size_t count) \
925 struct hid_device *hdev = to_hid_device(dev);\
926 struct wacom *wacom = hid_get_drvdata(hdev); \
928 return wacom_luminance_store(wacom, &wacom->led.field, \
931 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
932 struct device_attribute *attr, char *buf) \
934 struct wacom *wacom = dev_get_drvdata(dev); \
935 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
937 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
938 wacom_##name##_luminance_show, \
939 wacom_##name##_luminance_store)
941 DEVICE_LUMINANCE_ATTR(status0
, llv
);
942 DEVICE_LUMINANCE_ATTR(status1
, hlv
);
943 DEVICE_LUMINANCE_ATTR(buttons
, img_lum
);
945 static ssize_t
wacom_button_image_store(struct device
*dev
, int button_id
,
946 const char *buf
, size_t count
)
948 struct hid_device
*hdev
= to_hid_device(dev
);
949 struct wacom
*wacom
= hid_get_drvdata(hdev
);
954 if (hdev
->bus
== BUS_BLUETOOTH
) {
956 xfer_id
= WAC_CMD_ICON_BT_XFER
;
959 xfer_id
= WAC_CMD_ICON_XFER
;
965 mutex_lock(&wacom
->lock
);
967 err
= wacom_led_putimage(wacom
, button_id
, xfer_id
, len
, buf
);
969 mutex_unlock(&wacom
->lock
);
971 return err
< 0 ? err
: count
;
974 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
975 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
976 struct device_attribute *attr, const char *buf, size_t count) \
978 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
980 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
981 NULL, wacom_btnimg##BUTTON_ID##_store)
983 DEVICE_BTNIMG_ATTR(0);
984 DEVICE_BTNIMG_ATTR(1);
985 DEVICE_BTNIMG_ATTR(2);
986 DEVICE_BTNIMG_ATTR(3);
987 DEVICE_BTNIMG_ATTR(4);
988 DEVICE_BTNIMG_ATTR(5);
989 DEVICE_BTNIMG_ATTR(6);
990 DEVICE_BTNIMG_ATTR(7);
992 static struct attribute
*cintiq_led_attrs
[] = {
993 &dev_attr_status_led0_select
.attr
,
994 &dev_attr_status_led1_select
.attr
,
998 static struct attribute_group cintiq_led_attr_group
= {
1000 .attrs
= cintiq_led_attrs
,
1003 static struct attribute
*intuos4_led_attrs
[] = {
1004 &dev_attr_status0_luminance
.attr
,
1005 &dev_attr_status1_luminance
.attr
,
1006 &dev_attr_status_led0_select
.attr
,
1007 &dev_attr_buttons_luminance
.attr
,
1008 &dev_attr_button0_rawimg
.attr
,
1009 &dev_attr_button1_rawimg
.attr
,
1010 &dev_attr_button2_rawimg
.attr
,
1011 &dev_attr_button3_rawimg
.attr
,
1012 &dev_attr_button4_rawimg
.attr
,
1013 &dev_attr_button5_rawimg
.attr
,
1014 &dev_attr_button6_rawimg
.attr
,
1015 &dev_attr_button7_rawimg
.attr
,
1019 static struct attribute_group intuos4_led_attr_group
= {
1020 .name
= "wacom_led",
1021 .attrs
= intuos4_led_attrs
,
1024 static struct attribute
*intuos5_led_attrs
[] = {
1025 &dev_attr_status0_luminance
.attr
,
1026 &dev_attr_status_led0_select
.attr
,
1030 static struct attribute_group intuos5_led_attr_group
= {
1031 .name
= "wacom_led",
1032 .attrs
= intuos5_led_attrs
,
1035 struct wacom_sysfs_group_devres
{
1036 struct attribute_group
*group
;
1037 struct kobject
*root
;
1040 static void wacom_devm_sysfs_group_release(struct device
*dev
, void *res
)
1042 struct wacom_sysfs_group_devres
*devres
= res
;
1043 struct kobject
*kobj
= devres
->root
;
1045 dev_dbg(dev
, "%s: dropping reference to %s\n",
1046 __func__
, devres
->group
->name
);
1047 sysfs_remove_group(kobj
, devres
->group
);
1050 static int __wacom_devm_sysfs_create_group(struct wacom
*wacom
,
1051 struct kobject
*root
,
1052 struct attribute_group
*group
)
1054 struct wacom_sysfs_group_devres
*devres
;
1057 devres
= devres_alloc(wacom_devm_sysfs_group_release
,
1058 sizeof(struct wacom_sysfs_group_devres
),
1063 devres
->group
= group
;
1064 devres
->root
= root
;
1066 error
= sysfs_create_group(devres
->root
, group
);
1070 devres_add(&wacom
->hdev
->dev
, devres
);
1075 static int wacom_devm_sysfs_create_group(struct wacom
*wacom
,
1076 struct attribute_group
*group
)
1078 return __wacom_devm_sysfs_create_group(wacom
, &wacom
->hdev
->dev
.kobj
,
1082 enum led_brightness
wacom_leds_brightness_get(struct wacom_led
*led
)
1084 struct wacom
*wacom
= led
->wacom
;
1086 if (wacom
->led
.max_hlv
)
1087 return led
->hlv
* LED_FULL
/ wacom
->led
.max_hlv
;
1089 if (wacom
->led
.max_llv
)
1090 return led
->llv
* LED_FULL
/ wacom
->led
.max_llv
;
1092 /* device doesn't support brightness tuning */
1096 static enum led_brightness
__wacom_led_brightness_get(struct led_classdev
*cdev
)
1098 struct wacom_led
*led
= container_of(cdev
, struct wacom_led
, cdev
);
1099 struct wacom
*wacom
= led
->wacom
;
1101 if (wacom
->led
.groups
[led
->group
].select
!= led
->id
)
1104 return wacom_leds_brightness_get(led
);
1107 static int wacom_led_brightness_set(struct led_classdev
*cdev
,
1108 enum led_brightness brightness
)
1110 struct wacom_led
*led
= container_of(cdev
, struct wacom_led
, cdev
);
1111 struct wacom
*wacom
= led
->wacom
;
1114 mutex_lock(&wacom
->lock
);
1116 if (!wacom
->led
.groups
|| (brightness
== LED_OFF
&&
1117 wacom
->led
.groups
[led
->group
].select
!= led
->id
)) {
1122 led
->llv
= wacom
->led
.llv
= wacom
->led
.max_llv
* brightness
/ LED_FULL
;
1123 led
->hlv
= wacom
->led
.hlv
= wacom
->led
.max_hlv
* brightness
/ LED_FULL
;
1125 wacom
->led
.groups
[led
->group
].select
= led
->id
;
1127 error
= wacom_led_control(wacom
);
1130 mutex_unlock(&wacom
->lock
);
1135 static void wacom_led_readonly_brightness_set(struct led_classdev
*cdev
,
1136 enum led_brightness brightness
)
1140 static int wacom_led_register_one(struct device
*dev
, struct wacom
*wacom
,
1141 struct wacom_led
*led
, unsigned int group
,
1142 unsigned int id
, bool read_only
)
1147 name
= devm_kasprintf(dev
, GFP_KERNEL
,
1156 led
->trigger
.name
= name
;
1157 error
= devm_led_trigger_register(dev
, &led
->trigger
);
1159 hid_err(wacom
->hdev
,
1160 "failed to register LED trigger %s: %d\n",
1161 led
->cdev
.name
, error
);
1169 led
->llv
= wacom
->led
.llv
;
1170 led
->hlv
= wacom
->led
.hlv
;
1171 led
->cdev
.name
= name
;
1172 led
->cdev
.max_brightness
= LED_FULL
;
1173 led
->cdev
.flags
= LED_HW_PLUGGABLE
;
1174 led
->cdev
.brightness_get
= __wacom_led_brightness_get
;
1176 led
->cdev
.brightness_set_blocking
= wacom_led_brightness_set
;
1177 led
->cdev
.default_trigger
= led
->cdev
.name
;
1179 led
->cdev
.brightness_set
= wacom_led_readonly_brightness_set
;
1182 error
= devm_led_classdev_register(dev
, &led
->cdev
);
1184 hid_err(wacom
->hdev
,
1185 "failed to register LED %s: %d\n",
1186 led
->cdev
.name
, error
);
1187 led
->cdev
.name
= NULL
;
1194 static void wacom_led_groups_release_one(void *data
)
1196 struct wacom_group_leds
*group
= data
;
1198 devres_release_group(group
->dev
, group
);
1201 static int wacom_led_groups_alloc_and_register_one(struct device
*dev
,
1202 struct wacom
*wacom
,
1203 int group_id
, int count
,
1206 struct wacom_led
*leds
;
1209 if (group_id
>= wacom
->led
.count
|| count
<= 0)
1212 if (!devres_open_group(dev
, &wacom
->led
.groups
[group_id
], GFP_KERNEL
))
1215 leds
= devm_kzalloc(dev
, sizeof(struct wacom_led
) * count
, GFP_KERNEL
);
1221 wacom
->led
.groups
[group_id
].leds
= leds
;
1222 wacom
->led
.groups
[group_id
].count
= count
;
1224 for (i
= 0; i
< count
; i
++) {
1225 error
= wacom_led_register_one(dev
, wacom
, &leds
[i
],
1226 group_id
, i
, read_only
);
1231 wacom
->led
.groups
[group_id
].dev
= dev
;
1233 devres_close_group(dev
, &wacom
->led
.groups
[group_id
]);
1236 * There is a bug (?) in devm_led_classdev_register() in which its
1237 * increments the refcount of the parent. If the parent is an input
1238 * device, that means the ref count never reaches 0 when
1239 * devm_input_device_release() gets called.
1240 * This means that the LEDs are still there after disconnect.
1241 * Manually force the release of the group so that the leds are released
1242 * once we are done using them.
1244 error
= devm_add_action_or_reset(&wacom
->hdev
->dev
,
1245 wacom_led_groups_release_one
,
1246 &wacom
->led
.groups
[group_id
]);
1253 devres_release_group(dev
, &wacom
->led
.groups
[group_id
]);
1257 struct wacom_led
*wacom_led_find(struct wacom
*wacom
, unsigned int group_id
,
1260 struct wacom_group_leds
*group
;
1262 if (group_id
>= wacom
->led
.count
)
1265 group
= &wacom
->led
.groups
[group_id
];
1272 return &group
->leds
[id
];
1276 * wacom_led_next: gives the next available led with a wacom trigger.
1278 * returns the next available struct wacom_led which has its default trigger
1279 * or the current one if none is available.
1281 struct wacom_led
*wacom_led_next(struct wacom
*wacom
, struct wacom_led
*cur
)
1283 struct wacom_led
*next_led
;
1293 next_led
= wacom_led_find(wacom
, group
, ++next
);
1294 if (!next_led
|| next_led
== cur
)
1296 } while (next_led
->cdev
.trigger
!= &next_led
->trigger
);
1301 static void wacom_led_groups_release(void *data
)
1303 struct wacom
*wacom
= data
;
1305 wacom
->led
.groups
= NULL
;
1306 wacom
->led
.count
= 0;
1309 static int wacom_led_groups_allocate(struct wacom
*wacom
, int count
)
1311 struct device
*dev
= &wacom
->hdev
->dev
;
1312 struct wacom_group_leds
*groups
;
1315 groups
= devm_kzalloc(dev
, sizeof(struct wacom_group_leds
) * count
,
1320 error
= devm_add_action_or_reset(dev
, wacom_led_groups_release
, wacom
);
1324 wacom
->led
.groups
= groups
;
1325 wacom
->led
.count
= count
;
1330 static int wacom_leds_alloc_and_register(struct wacom
*wacom
, int group_count
,
1331 int led_per_group
, bool read_only
)
1336 if (!wacom
->wacom_wac
.pad_input
)
1339 dev
= &wacom
->wacom_wac
.pad_input
->dev
;
1341 error
= wacom_led_groups_allocate(wacom
, group_count
);
1345 for (i
= 0; i
< group_count
; i
++) {
1346 error
= wacom_led_groups_alloc_and_register_one(dev
, wacom
, i
,
1356 static int wacom_initialize_leds(struct wacom
*wacom
)
1360 if (!(wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
))
1363 /* Initialize default values */
1364 switch (wacom
->wacom_wac
.features
.type
) {
1369 wacom
->led
.llv
= 10;
1370 wacom
->led
.hlv
= 20;
1371 wacom
->led
.max_llv
= 127;
1372 wacom
->led
.max_hlv
= 127;
1373 wacom
->led
.img_lum
= 10;
1375 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1377 hid_err(wacom
->hdev
,
1378 "cannot create leds err: %d\n", error
);
1382 error
= wacom_devm_sysfs_create_group(wacom
,
1383 &intuos4_led_attr_group
);
1390 wacom
->led
.img_lum
= 0;
1392 error
= wacom_leds_alloc_and_register(wacom
, 2, 4, false);
1394 hid_err(wacom
->hdev
,
1395 "cannot create leds err: %d\n", error
);
1399 error
= wacom_devm_sysfs_create_group(wacom
,
1400 &cintiq_led_attr_group
);
1409 wacom
->led
.llv
= 32;
1410 wacom
->led
.max_llv
= 96;
1412 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1414 hid_err(wacom
->hdev
,
1415 "cannot create leds err: %d\n", error
);
1419 error
= wacom_devm_sysfs_create_group(wacom
,
1420 &intuos5_led_attr_group
);
1424 wacom
->led
.llv
= 255;
1425 wacom
->led
.max_llv
= 255;
1426 error
= wacom_led_groups_allocate(wacom
, 5);
1428 hid_err(wacom
->hdev
,
1429 "cannot create leds err: %d\n", error
);
1439 hid_err(wacom
->hdev
,
1440 "cannot create sysfs group err: %d\n", error
);
1443 wacom_led_control(wacom
);
1448 static enum power_supply_property wacom_battery_props
[] = {
1449 POWER_SUPPLY_PROP_MODEL_NAME
,
1450 POWER_SUPPLY_PROP_PRESENT
,
1451 POWER_SUPPLY_PROP_STATUS
,
1452 POWER_SUPPLY_PROP_SCOPE
,
1453 POWER_SUPPLY_PROP_CAPACITY
1456 static int wacom_battery_get_property(struct power_supply
*psy
,
1457 enum power_supply_property psp
,
1458 union power_supply_propval
*val
)
1460 struct wacom_battery
*battery
= power_supply_get_drvdata(psy
);
1464 case POWER_SUPPLY_PROP_MODEL_NAME
:
1465 val
->strval
= battery
->wacom
->wacom_wac
.name
;
1467 case POWER_SUPPLY_PROP_PRESENT
:
1468 val
->intval
= battery
->bat_connected
;
1470 case POWER_SUPPLY_PROP_SCOPE
:
1471 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
1473 case POWER_SUPPLY_PROP_CAPACITY
:
1474 val
->intval
= battery
->battery_capacity
;
1476 case POWER_SUPPLY_PROP_STATUS
:
1477 if (battery
->bat_charging
)
1478 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
1479 else if (battery
->battery_capacity
== 100 &&
1480 battery
->ps_connected
)
1481 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
1482 else if (battery
->ps_connected
)
1483 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1485 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
1495 static int __wacom_initialize_battery(struct wacom
*wacom
,
1496 struct wacom_battery
*battery
)
1498 static atomic_t battery_no
= ATOMIC_INIT(0);
1499 struct device
*dev
= &wacom
->hdev
->dev
;
1500 struct power_supply_config psy_cfg
= { .drv_data
= battery
, };
1501 struct power_supply
*ps_bat
;
1502 struct power_supply_desc
*bat_desc
= &battery
->bat_desc
;
1506 if (!devres_open_group(dev
, bat_desc
, GFP_KERNEL
))
1509 battery
->wacom
= wacom
;
1511 n
= atomic_inc_return(&battery_no
) - 1;
1513 bat_desc
->properties
= wacom_battery_props
;
1514 bat_desc
->num_properties
= ARRAY_SIZE(wacom_battery_props
);
1515 bat_desc
->get_property
= wacom_battery_get_property
;
1516 sprintf(battery
->bat_name
, "wacom_battery_%ld", n
);
1517 bat_desc
->name
= battery
->bat_name
;
1518 bat_desc
->type
= POWER_SUPPLY_TYPE_USB
;
1519 bat_desc
->use_for_apm
= 0;
1521 ps_bat
= devm_power_supply_register(dev
, bat_desc
, &psy_cfg
);
1522 if (IS_ERR(ps_bat
)) {
1523 error
= PTR_ERR(ps_bat
);
1527 power_supply_powers(ps_bat
, &wacom
->hdev
->dev
);
1529 battery
->battery
= ps_bat
;
1531 devres_close_group(dev
, bat_desc
);
1535 devres_release_group(dev
, bat_desc
);
1539 static int wacom_initialize_battery(struct wacom
*wacom
)
1541 if (wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
)
1542 return __wacom_initialize_battery(wacom
, &wacom
->battery
);
1547 static void wacom_destroy_battery(struct wacom
*wacom
)
1549 if (wacom
->battery
.battery
) {
1550 devres_release_group(&wacom
->hdev
->dev
,
1551 &wacom
->battery
.bat_desc
);
1552 wacom
->battery
.battery
= NULL
;
1556 static ssize_t
wacom_show_speed(struct device
*dev
,
1557 struct device_attribute
1560 struct hid_device
*hdev
= to_hid_device(dev
);
1561 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1563 return snprintf(buf
, PAGE_SIZE
, "%i\n", wacom
->wacom_wac
.bt_high_speed
);
1566 static ssize_t
wacom_store_speed(struct device
*dev
,
1567 struct device_attribute
*attr
,
1568 const char *buf
, size_t count
)
1570 struct hid_device
*hdev
= to_hid_device(dev
);
1571 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1574 if (kstrtou8(buf
, 0, &new_speed
))
1577 if (new_speed
!= 0 && new_speed
!= 1)
1580 wacom_bt_query_tablet_data(hdev
, new_speed
, &wacom
->wacom_wac
.features
);
1585 static DEVICE_ATTR(speed
, DEV_ATTR_RW_PERM
,
1586 wacom_show_speed
, wacom_store_speed
);
1589 static ssize_t
wacom_show_remote_mode(struct kobject
*kobj
,
1590 struct kobj_attribute
*kattr
,
1591 char *buf
, int index
)
1593 struct device
*dev
= kobj_to_dev(kobj
->parent
);
1594 struct hid_device
*hdev
= to_hid_device(dev
);
1595 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1598 mode
= wacom
->led
.groups
[index
].select
;
1599 if (mode
>= 0 && mode
< 3)
1600 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
1602 return snprintf(buf
, PAGE_SIZE
, "%d\n", -1);
1605 #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1606 static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1607 struct kobj_attribute *kattr, char *buf) \
1609 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1611 static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1612 .attr = {.name = "remote_mode", \
1613 .mode = DEV_ATTR_RO_PERM}, \
1614 .show = wacom_show_remote##SET_ID##_mode, \
1616 static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1617 &remote##SET_ID##_mode_attr.attr, \
1620 static struct attribute_group remote##SET_ID##_serial_group = { \
1622 .attrs = remote##SET_ID##_serial_attrs, \
1625 DEVICE_EKR_ATTR_GROUP(0);
1626 DEVICE_EKR_ATTR_GROUP(1);
1627 DEVICE_EKR_ATTR_GROUP(2);
1628 DEVICE_EKR_ATTR_GROUP(3);
1629 DEVICE_EKR_ATTR_GROUP(4);
1631 static int wacom_remote_create_attr_group(struct wacom
*wacom
, __u32 serial
,
1635 struct wacom_remote
*remote
= wacom
->remote
;
1637 remote
->remotes
[index
].group
.name
= devm_kasprintf(&wacom
->hdev
->dev
,
1640 if (!remote
->remotes
[index
].group
.name
)
1643 error
= __wacom_devm_sysfs_create_group(wacom
, remote
->remote_dir
,
1644 &remote
->remotes
[index
].group
);
1646 remote
->remotes
[index
].group
.name
= NULL
;
1647 hid_err(wacom
->hdev
,
1648 "cannot create sysfs group err: %d\n", error
);
1655 static int wacom_cmd_unpair_remote(struct wacom
*wacom
, unsigned char selector
)
1657 const size_t buf_size
= 2;
1661 buf
= kzalloc(buf_size
, GFP_KERNEL
);
1665 buf
[0] = WAC_CMD_DELETE_PAIRING
;
1668 retval
= wacom_set_report(wacom
->hdev
, HID_OUTPUT_REPORT
, buf
,
1669 buf_size
, WAC_CMD_RETRIES
);
1675 static ssize_t
wacom_store_unpair_remote(struct kobject
*kobj
,
1676 struct kobj_attribute
*attr
,
1677 const char *buf
, size_t count
)
1679 unsigned char selector
= 0;
1680 struct device
*dev
= kobj_to_dev(kobj
->parent
);
1681 struct hid_device
*hdev
= to_hid_device(dev
);
1682 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1685 if (!strncmp(buf
, "*\n", 2)) {
1686 selector
= WAC_CMD_UNPAIR_ALL
;
1688 hid_info(wacom
->hdev
, "remote: unrecognized unpair code: %s\n",
1693 mutex_lock(&wacom
->lock
);
1695 err
= wacom_cmd_unpair_remote(wacom
, selector
);
1696 mutex_unlock(&wacom
->lock
);
1698 return err
< 0 ? err
: count
;
1701 static struct kobj_attribute unpair_remote_attr
= {
1702 .attr
= {.name
= "unpair_remote", .mode
= 0200},
1703 .store
= wacom_store_unpair_remote
,
1706 static const struct attribute
*remote_unpair_attrs
[] = {
1707 &unpair_remote_attr
.attr
,
1711 static void wacom_remotes_destroy(void *data
)
1713 struct wacom
*wacom
= data
;
1714 struct wacom_remote
*remote
= wacom
->remote
;
1719 kobject_put(remote
->remote_dir
);
1720 kfifo_free(&remote
->remote_fifo
);
1721 wacom
->remote
= NULL
;
1724 static int wacom_initialize_remotes(struct wacom
*wacom
)
1727 struct wacom_remote
*remote
;
1730 if (wacom
->wacom_wac
.features
.type
!= REMOTE
)
1733 remote
= devm_kzalloc(&wacom
->hdev
->dev
, sizeof(*wacom
->remote
),
1738 wacom
->remote
= remote
;
1740 spin_lock_init(&remote
->remote_lock
);
1742 error
= kfifo_alloc(&remote
->remote_fifo
,
1743 5 * sizeof(struct wacom_remote_data
),
1746 hid_err(wacom
->hdev
, "failed allocating remote_fifo\n");
1750 remote
->remotes
[0].group
= remote0_serial_group
;
1751 remote
->remotes
[1].group
= remote1_serial_group
;
1752 remote
->remotes
[2].group
= remote2_serial_group
;
1753 remote
->remotes
[3].group
= remote3_serial_group
;
1754 remote
->remotes
[4].group
= remote4_serial_group
;
1756 remote
->remote_dir
= kobject_create_and_add("wacom_remote",
1757 &wacom
->hdev
->dev
.kobj
);
1758 if (!remote
->remote_dir
)
1761 error
= sysfs_create_files(remote
->remote_dir
, remote_unpair_attrs
);
1764 hid_err(wacom
->hdev
,
1765 "cannot create sysfs group err: %d\n", error
);
1769 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
1770 wacom
->led
.groups
[i
].select
= WACOM_STATUS_UNKNOWN
;
1771 remote
->remotes
[i
].serial
= 0;
1774 error
= devm_add_action_or_reset(&wacom
->hdev
->dev
,
1775 wacom_remotes_destroy
, wacom
);
1782 static struct input_dev
*wacom_allocate_input(struct wacom
*wacom
)
1784 struct input_dev
*input_dev
;
1785 struct hid_device
*hdev
= wacom
->hdev
;
1786 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1788 input_dev
= devm_input_allocate_device(&hdev
->dev
);
1792 input_dev
->name
= wacom_wac
->features
.name
;
1793 input_dev
->phys
= hdev
->phys
;
1794 input_dev
->dev
.parent
= &hdev
->dev
;
1795 input_dev
->open
= wacom_open
;
1796 input_dev
->close
= wacom_close
;
1797 input_dev
->uniq
= hdev
->uniq
;
1798 input_dev
->id
.bustype
= hdev
->bus
;
1799 input_dev
->id
.vendor
= hdev
->vendor
;
1800 input_dev
->id
.product
= wacom_wac
->pid
? wacom_wac
->pid
: hdev
->product
;
1801 input_dev
->id
.version
= hdev
->version
;
1802 input_set_drvdata(input_dev
, wacom
);
1807 static int wacom_allocate_inputs(struct wacom
*wacom
)
1809 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1811 wacom_wac
->pen_input
= wacom_allocate_input(wacom
);
1812 wacom_wac
->touch_input
= wacom_allocate_input(wacom
);
1813 wacom_wac
->pad_input
= wacom_allocate_input(wacom
);
1814 if (!wacom_wac
->pen_input
||
1815 !wacom_wac
->touch_input
||
1816 !wacom_wac
->pad_input
)
1819 wacom_wac
->pen_input
->name
= wacom_wac
->pen_name
;
1820 wacom_wac
->touch_input
->name
= wacom_wac
->touch_name
;
1821 wacom_wac
->pad_input
->name
= wacom_wac
->pad_name
;
1826 static int wacom_register_inputs(struct wacom
*wacom
)
1828 struct input_dev
*pen_input_dev
, *touch_input_dev
, *pad_input_dev
;
1829 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1832 pen_input_dev
= wacom_wac
->pen_input
;
1833 touch_input_dev
= wacom_wac
->touch_input
;
1834 pad_input_dev
= wacom_wac
->pad_input
;
1836 if (!pen_input_dev
|| !touch_input_dev
|| !pad_input_dev
)
1839 error
= wacom_setup_pen_input_capabilities(pen_input_dev
, wacom_wac
);
1841 /* no pen in use on this interface */
1842 input_free_device(pen_input_dev
);
1843 wacom_wac
->pen_input
= NULL
;
1844 pen_input_dev
= NULL
;
1846 error
= input_register_device(pen_input_dev
);
1851 error
= wacom_setup_touch_input_capabilities(touch_input_dev
, wacom_wac
);
1853 /* no touch in use on this interface */
1854 input_free_device(touch_input_dev
);
1855 wacom_wac
->touch_input
= NULL
;
1856 touch_input_dev
= NULL
;
1858 error
= input_register_device(touch_input_dev
);
1863 error
= wacom_setup_pad_input_capabilities(pad_input_dev
, wacom_wac
);
1865 /* no pad in use on this interface */
1866 input_free_device(pad_input_dev
);
1867 wacom_wac
->pad_input
= NULL
;
1868 pad_input_dev
= NULL
;
1870 error
= input_register_device(pad_input_dev
);
1878 wacom_wac
->pad_input
= NULL
;
1879 wacom_wac
->touch_input
= NULL
;
1880 wacom_wac
->pen_input
= NULL
;
1885 * Not all devices report physical dimensions from HID.
1886 * Compute the default from hardcoded logical dimension
1887 * and resolution before driver overwrites them.
1889 static void wacom_set_default_phy(struct wacom_features
*features
)
1891 if (features
->x_resolution
) {
1892 features
->x_phy
= (features
->x_max
* 100) /
1893 features
->x_resolution
;
1894 features
->y_phy
= (features
->y_max
* 100) /
1895 features
->y_resolution
;
1899 static void wacom_calculate_res(struct wacom_features
*features
)
1901 /* set unit to "100th of a mm" for devices not reported by HID */
1902 if (!features
->unit
) {
1903 features
->unit
= 0x11;
1904 features
->unitExpo
= -3;
1907 features
->x_resolution
= wacom_calc_hid_res(features
->x_max
,
1910 features
->unitExpo
);
1911 features
->y_resolution
= wacom_calc_hid_res(features
->y_max
,
1914 features
->unitExpo
);
1917 void wacom_battery_work(struct work_struct
*work
)
1919 struct wacom
*wacom
= container_of(work
, struct wacom
, battery_work
);
1921 if ((wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1922 !wacom
->battery
.battery
) {
1923 wacom_initialize_battery(wacom
);
1925 else if (!(wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1926 wacom
->battery
.battery
) {
1927 wacom_destroy_battery(wacom
);
1931 static size_t wacom_compute_pktlen(struct hid_device
*hdev
)
1933 struct hid_report_enum
*report_enum
;
1934 struct hid_report
*report
;
1937 report_enum
= hdev
->report_enum
+ HID_INPUT_REPORT
;
1939 list_for_each_entry(report
, &report_enum
->report_list
, list
) {
1940 size_t report_size
= hid_report_len(report
);
1941 if (report_size
> size
)
1948 static void wacom_update_name(struct wacom
*wacom
, const char *suffix
)
1950 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1951 struct wacom_features
*features
= &wacom_wac
->features
;
1952 char name
[WACOM_NAME_MAX
];
1954 /* Generic devices name unspecified */
1955 if ((features
->type
== HID_GENERIC
) && !strcmp("Wacom HID", features
->name
)) {
1956 if (strstr(wacom
->hdev
->name
, "Wacom") ||
1957 strstr(wacom
->hdev
->name
, "wacom") ||
1958 strstr(wacom
->hdev
->name
, "WACOM")) {
1959 /* name is in HID descriptor, use it */
1960 strlcpy(name
, wacom
->hdev
->name
, sizeof(name
));
1962 /* strip out excess whitespaces */
1964 char *gap
= strstr(name
, " ");
1967 /* shift everything including the terminator */
1968 memmove(gap
, gap
+1, strlen(gap
));
1971 /* strip off excessive prefixing */
1972 if (strstr(name
, "Wacom Co.,Ltd. Wacom ") == name
) {
1973 int n
= strlen(name
);
1974 int x
= strlen("Wacom Co.,Ltd. ");
1975 memmove(name
, name
+x
, n
-x
+1);
1977 if (strstr(name
, "Wacom Co., Ltd. Wacom ") == name
) {
1978 int n
= strlen(name
);
1979 int x
= strlen("Wacom Co., Ltd. ");
1980 memmove(name
, name
+x
, n
-x
+1);
1983 /* get rid of trailing whitespace */
1984 if (name
[strlen(name
)-1] == ' ')
1985 name
[strlen(name
)-1] = '\0';
1987 /* no meaningful name retrieved. use product ID */
1988 snprintf(name
, sizeof(name
),
1989 "%s %X", features
->name
, wacom
->hdev
->product
);
1992 strlcpy(name
, features
->name
, sizeof(name
));
1995 snprintf(wacom_wac
->name
, sizeof(wacom_wac
->name
), "%s%s",
1998 /* Append the device type to the name */
1999 snprintf(wacom_wac
->pen_name
, sizeof(wacom_wac
->pen_name
),
2000 "%s%s Pen", name
, suffix
);
2001 snprintf(wacom_wac
->touch_name
, sizeof(wacom_wac
->touch_name
),
2002 "%s%s Finger", name
, suffix
);
2003 snprintf(wacom_wac
->pad_name
, sizeof(wacom_wac
->pad_name
),
2004 "%s%s Pad", name
, suffix
);
2007 static void wacom_release_resources(struct wacom
*wacom
)
2009 struct hid_device
*hdev
= wacom
->hdev
;
2011 if (!wacom
->resources
)
2014 devres_release_group(&hdev
->dev
, wacom
);
2016 wacom
->resources
= false;
2018 wacom
->wacom_wac
.pen_input
= NULL
;
2019 wacom
->wacom_wac
.touch_input
= NULL
;
2020 wacom
->wacom_wac
.pad_input
= NULL
;
2023 static int wacom_parse_and_register(struct wacom
*wacom
, bool wireless
)
2025 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2026 struct wacom_features
*features
= &wacom_wac
->features
;
2027 struct hid_device
*hdev
= wacom
->hdev
;
2029 unsigned int connect_mask
= HID_CONNECT_HIDRAW
;
2031 features
->pktlen
= wacom_compute_pktlen(hdev
);
2032 if (features
->pktlen
> WACOM_PKGLEN_MAX
)
2035 if (!devres_open_group(&hdev
->dev
, wacom
, GFP_KERNEL
))
2038 wacom
->resources
= true;
2040 error
= wacom_allocate_inputs(wacom
);
2045 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
2046 * into debug mode for the touch part.
2047 * We ignore the other interfaces.
2049 if (features
->type
== BAMBOO_PAD
) {
2050 if (features
->pktlen
== WACOM_PKGLEN_PENABLED
) {
2051 features
->type
= HID_GENERIC
;
2052 } else if ((features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH
) &&
2053 (features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH_USB
)) {
2059 /* set the default size in case we do not get them from hid */
2060 wacom_set_default_phy(features
);
2062 /* Retrieve the physical and logical size for touch devices */
2063 wacom_retrieve_hid_descriptor(hdev
, features
);
2064 wacom_setup_device_quirks(wacom
);
2066 if (features
->device_type
== WACOM_DEVICETYPE_NONE
&&
2067 features
->type
!= WIRELESS
) {
2068 error
= features
->type
== HID_GENERIC
? -ENODEV
: 0;
2070 dev_warn(&hdev
->dev
, "Unknown device_type for '%s'. %s.",
2072 error
? "Ignoring" : "Assuming pen");
2077 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
2080 wacom_calculate_res(features
);
2082 wacom_update_name(wacom
, wireless
? " (WL)" : "");
2084 error
= wacom_add_shared_data(hdev
);
2088 if (!(features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
) &&
2089 (features
->quirks
& WACOM_QUIRK_BATTERY
)) {
2090 error
= wacom_initialize_battery(wacom
);
2095 error
= wacom_register_inputs(wacom
);
2099 if (wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
) {
2100 error
= wacom_initialize_leds(wacom
);
2104 error
= wacom_initialize_remotes(wacom
);
2109 if (features
->type
== HID_GENERIC
)
2110 connect_mask
|= HID_CONNECT_DRIVER
;
2112 /* Regular HID work starts now */
2113 error
= hid_hw_start(hdev
, connect_mask
);
2115 hid_err(hdev
, "hw start failed\n");
2120 /* Note that if query fails it is not a hard failure */
2121 wacom_query_tablet_data(hdev
, features
);
2124 /* touch only Bamboo doesn't support pen */
2125 if ((features
->type
== BAMBOO_TOUCH
) &&
2126 (features
->device_type
& WACOM_DEVICETYPE_PEN
)) {
2131 /* pen only Bamboo neither support touch nor pad */
2132 if ((features
->type
== BAMBOO_PEN
) &&
2133 ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) ||
2134 (features
->device_type
& WACOM_DEVICETYPE_PAD
))) {
2139 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
2140 error
= hid_hw_open(hdev
);
2142 if ((wacom_wac
->features
.type
== INTUOSHT
||
2143 wacom_wac
->features
.type
== INTUOSHT2
) &&
2144 (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
)) {
2145 wacom_wac
->shared
->type
= wacom_wac
->features
.type
;
2146 wacom_wac
->shared
->touch_input
= wacom_wac
->touch_input
;
2149 devres_close_group(&hdev
->dev
, wacom
);
2156 wacom_release_resources(wacom
);
2160 static void wacom_wireless_work(struct work_struct
*work
)
2162 struct wacom
*wacom
= container_of(work
, struct wacom
, wireless_work
);
2163 struct usb_device
*usbdev
= wacom
->usbdev
;
2164 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2165 struct hid_device
*hdev1
, *hdev2
;
2166 struct wacom
*wacom1
, *wacom2
;
2167 struct wacom_wac
*wacom_wac1
, *wacom_wac2
;
2171 * Regardless if this is a disconnect or a new tablet,
2172 * remove any existing input and battery devices.
2175 wacom_destroy_battery(wacom
);
2177 /* Stylus interface */
2178 hdev1
= usb_get_intfdata(usbdev
->config
->interface
[1]);
2179 wacom1
= hid_get_drvdata(hdev1
);
2180 wacom_wac1
= &(wacom1
->wacom_wac
);
2181 wacom_release_resources(wacom1
);
2183 /* Touch interface */
2184 hdev2
= usb_get_intfdata(usbdev
->config
->interface
[2]);
2185 wacom2
= hid_get_drvdata(hdev2
);
2186 wacom_wac2
= &(wacom2
->wacom_wac
);
2187 wacom_release_resources(wacom2
);
2189 if (wacom_wac
->pid
== 0) {
2190 hid_info(wacom
->hdev
, "wireless tablet disconnected\n");
2192 const struct hid_device_id
*id
= wacom_ids
;
2194 hid_info(wacom
->hdev
, "wireless tablet connected with PID %x\n",
2198 if (id
->vendor
== USB_VENDOR_ID_WACOM
&&
2199 id
->product
== wacom_wac
->pid
)
2205 hid_info(wacom
->hdev
, "ignoring unknown PID.\n");
2209 /* Stylus interface */
2210 wacom_wac1
->features
=
2211 *((struct wacom_features
*)id
->driver_data
);
2213 wacom_wac1
->pid
= wacom_wac
->pid
;
2215 error
= wacom_parse_and_register(wacom1
, true);
2219 /* Touch interface */
2220 if (wacom_wac1
->features
.touch_max
||
2221 (wacom_wac1
->features
.type
>= INTUOSHT
&&
2222 wacom_wac1
->features
.type
<= BAMBOO_PT
)) {
2223 wacom_wac2
->features
=
2224 *((struct wacom_features
*)id
->driver_data
);
2225 wacom_wac2
->pid
= wacom_wac
->pid
;
2227 error
= wacom_parse_and_register(wacom2
, true);
2232 strlcpy(wacom_wac
->name
, wacom_wac1
->name
,
2233 sizeof(wacom_wac
->name
));
2234 error
= wacom_initialize_battery(wacom
);
2242 wacom_release_resources(wacom1
);
2243 wacom_release_resources(wacom2
);
2247 static void wacom_remote_destroy_one(struct wacom
*wacom
, unsigned int index
)
2249 struct wacom_remote
*remote
= wacom
->remote
;
2250 u32 serial
= remote
->remotes
[index
].serial
;
2252 unsigned long flags
;
2254 spin_lock_irqsave(&remote
->remote_lock
, flags
);
2255 remote
->remotes
[index
].registered
= false;
2256 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2258 if (remote
->remotes
[index
].battery
.battery
)
2259 devres_release_group(&wacom
->hdev
->dev
,
2260 &remote
->remotes
[index
].battery
.bat_desc
);
2262 if (remote
->remotes
[index
].group
.name
)
2263 devres_release_group(&wacom
->hdev
->dev
,
2264 &remote
->remotes
[index
]);
2266 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
2267 if (remote
->remotes
[i
].serial
== serial
) {
2268 remote
->remotes
[i
].serial
= 0;
2269 remote
->remotes
[i
].group
.name
= NULL
;
2270 remote
->remotes
[i
].registered
= false;
2271 remote
->remotes
[i
].battery
.battery
= NULL
;
2272 wacom
->led
.groups
[i
].select
= WACOM_STATUS_UNKNOWN
;
2277 static int wacom_remote_create_one(struct wacom
*wacom
, u32 serial
,
2280 struct wacom_remote
*remote
= wacom
->remote
;
2281 struct device
*dev
= &wacom
->hdev
->dev
;
2284 /* A remote can pair more than once with an EKR,
2285 * check to make sure this serial isn't already paired.
2287 for (k
= 0; k
< WACOM_MAX_REMOTES
; k
++) {
2288 if (remote
->remotes
[k
].serial
== serial
)
2292 if (k
< WACOM_MAX_REMOTES
) {
2293 remote
->remotes
[index
].serial
= serial
;
2297 if (!devres_open_group(dev
, &remote
->remotes
[index
], GFP_KERNEL
))
2300 error
= wacom_remote_create_attr_group(wacom
, serial
, index
);
2304 remote
->remotes
[index
].input
= wacom_allocate_input(wacom
);
2305 if (!remote
->remotes
[index
].input
) {
2309 remote
->remotes
[index
].input
->uniq
= remote
->remotes
[index
].group
.name
;
2310 remote
->remotes
[index
].input
->name
= wacom
->wacom_wac
.pad_name
;
2312 if (!remote
->remotes
[index
].input
->name
) {
2317 error
= wacom_setup_pad_input_capabilities(remote
->remotes
[index
].input
,
2322 remote
->remotes
[index
].serial
= serial
;
2324 error
= input_register_device(remote
->remotes
[index
].input
);
2328 error
= wacom_led_groups_alloc_and_register_one(
2329 &remote
->remotes
[index
].input
->dev
,
2330 wacom
, index
, 3, true);
2334 remote
->remotes
[index
].registered
= true;
2336 devres_close_group(dev
, &remote
->remotes
[index
]);
2340 devres_release_group(dev
, &remote
->remotes
[index
]);
2341 remote
->remotes
[index
].serial
= 0;
2345 static int wacom_remote_attach_battery(struct wacom
*wacom
, int index
)
2347 struct wacom_remote
*remote
= wacom
->remote
;
2350 if (!remote
->remotes
[index
].registered
)
2353 if (remote
->remotes
[index
].battery
.battery
)
2356 if (wacom
->led
.groups
[index
].select
== WACOM_STATUS_UNKNOWN
)
2359 error
= __wacom_initialize_battery(wacom
,
2360 &wacom
->remote
->remotes
[index
].battery
);
2367 static void wacom_remote_work(struct work_struct
*work
)
2369 struct wacom
*wacom
= container_of(work
, struct wacom
, remote_work
);
2370 struct wacom_remote
*remote
= wacom
->remote
;
2371 struct wacom_remote_data data
;
2372 unsigned long flags
;
2377 spin_lock_irqsave(&remote
->remote_lock
, flags
);
2379 count
= kfifo_out(&remote
->remote_fifo
, &data
, sizeof(data
));
2381 if (count
!= sizeof(data
)) {
2382 hid_err(wacom
->hdev
,
2383 "workitem triggered without status available\n");
2384 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2388 if (!kfifo_is_empty(&remote
->remote_fifo
))
2389 wacom_schedule_work(&wacom
->wacom_wac
, WACOM_WORKER_REMOTE
);
2391 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2393 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
2394 serial
= data
.remote
[i
].serial
;
2395 if (data
.remote
[i
].connected
) {
2397 if (remote
->remotes
[i
].serial
== serial
) {
2398 wacom_remote_attach_battery(wacom
, i
);
2402 if (remote
->remotes
[i
].serial
)
2403 wacom_remote_destroy_one(wacom
, i
);
2405 wacom_remote_create_one(wacom
, serial
, i
);
2407 } else if (remote
->remotes
[i
].serial
) {
2408 wacom_remote_destroy_one(wacom
, i
);
2413 static int wacom_probe(struct hid_device
*hdev
,
2414 const struct hid_device_id
*id
)
2416 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
2417 struct usb_device
*dev
= interface_to_usbdev(intf
);
2418 struct wacom
*wacom
;
2419 struct wacom_wac
*wacom_wac
;
2420 struct wacom_features
*features
;
2423 if (!id
->driver_data
)
2426 hdev
->quirks
|= HID_QUIRK_NO_INIT_REPORTS
;
2428 /* hid-core sets this quirk for the boot interface */
2429 hdev
->quirks
&= ~HID_QUIRK_NOGET
;
2431 wacom
= devm_kzalloc(&hdev
->dev
, sizeof(struct wacom
), GFP_KERNEL
);
2435 hid_set_drvdata(hdev
, wacom
);
2438 wacom_wac
= &wacom
->wacom_wac
;
2439 wacom_wac
->features
= *((struct wacom_features
*)id
->driver_data
);
2440 features
= &wacom_wac
->features
;
2442 if (features
->check_for_hid_type
&& features
->hid_type
!= hdev
->type
) {
2447 wacom_wac
->hid_data
.inputmode
= -1;
2448 wacom_wac
->mode_report
= -1;
2450 wacom
->usbdev
= dev
;
2452 mutex_init(&wacom
->lock
);
2453 INIT_WORK(&wacom
->wireless_work
, wacom_wireless_work
);
2454 INIT_WORK(&wacom
->battery_work
, wacom_battery_work
);
2455 INIT_WORK(&wacom
->remote_work
, wacom_remote_work
);
2457 /* ask for the report descriptor to be loaded by HID */
2458 error
= hid_parse(hdev
);
2460 hid_err(hdev
, "parse failed\n");
2464 error
= wacom_parse_and_register(wacom
, false);
2468 if (hdev
->bus
== BUS_BLUETOOTH
) {
2469 error
= device_create_file(&hdev
->dev
, &dev_attr_speed
);
2472 "can't create sysfs speed attribute err: %d\n",
2479 hid_set_drvdata(hdev
, NULL
);
2483 static void wacom_remove(struct hid_device
*hdev
)
2485 struct wacom
*wacom
= hid_get_drvdata(hdev
);
2486 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2487 struct wacom_features
*features
= &wacom_wac
->features
;
2489 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
2494 cancel_work_sync(&wacom
->wireless_work
);
2495 cancel_work_sync(&wacom
->battery_work
);
2496 cancel_work_sync(&wacom
->remote_work
);
2497 if (hdev
->bus
== BUS_BLUETOOTH
)
2498 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
2500 hid_set_drvdata(hdev
, NULL
);
2504 static int wacom_resume(struct hid_device
*hdev
)
2506 struct wacom
*wacom
= hid_get_drvdata(hdev
);
2507 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
2509 mutex_lock(&wacom
->lock
);
2511 /* switch to wacom mode first */
2512 wacom_query_tablet_data(hdev
, features
);
2513 wacom_led_control(wacom
);
2515 mutex_unlock(&wacom
->lock
);
2520 static int wacom_reset_resume(struct hid_device
*hdev
)
2522 return wacom_resume(hdev
);
2524 #endif /* CONFIG_PM */
2526 static struct hid_driver wacom_driver
= {
2528 .id_table
= wacom_ids
,
2529 .probe
= wacom_probe
,
2530 .remove
= wacom_remove
,
2531 .report
= wacom_wac_report
,
2533 .resume
= wacom_resume
,
2534 .reset_resume
= wacom_reset_resume
,
2536 .raw_event
= wacom_raw_event
,
2538 module_hid_driver(wacom_driver
);
2540 MODULE_VERSION(DRIVER_VERSION
);
2541 MODULE_AUTHOR(DRIVER_AUTHOR
);
2542 MODULE_DESCRIPTION(DRIVER_DESC
);
2543 MODULE_LICENSE(DRIVER_LICENSE
);