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 WACOM_HID_WD_TOUCH_RING_SETTING
:
122 wacom
->generic_has_leds
= true;
124 case HID_DG_CONTACTMAX
:
125 /* leave touch_max as is if predefined */
126 if (!features
->touch_max
) {
128 data
= kzalloc(2, GFP_KERNEL
);
131 data
[0] = field
->report
->id
;
132 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
133 data
, 2, WAC_CMD_RETRIES
);
135 features
->touch_max
= data
[1];
137 features
->touch_max
= 16;
138 hid_warn(hdev
, "wacom_feature_mapping: "
139 "could not get HID_DG_CONTACTMAX, "
140 "defaulting to %d\n",
141 features
->touch_max
);
146 case HID_DG_INPUTMODE
:
147 /* Ignore if value index is out of bounds. */
148 if (usage
->usage_index
>= field
->report_count
) {
149 dev_err(&hdev
->dev
, "HID_DG_INPUTMODE out of range\n");
153 hid_data
->inputmode
= field
->report
->id
;
154 hid_data
->inputmode_index
= usage
->usage_index
;
157 case HID_UP_DIGITIZER
:
158 if (field
->report
->id
== 0x0B &&
159 (field
->application
== WACOM_HID_G9_PEN
||
160 field
->application
== WACOM_HID_G11_PEN
)) {
161 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
162 wacom
->wacom_wac
.mode_value
= 0;
166 case WACOM_HID_WD_DATAMODE
:
167 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
168 wacom
->wacom_wac
.mode_value
= 2;
171 case WACOM_HID_UP_G9
:
172 case WACOM_HID_UP_G11
:
173 if (field
->report
->id
== 0x03 &&
174 (field
->application
== WACOM_HID_G9_TOUCHSCREEN
||
175 field
->application
== WACOM_HID_G11_TOUCHSCREEN
)) {
176 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
177 wacom
->wacom_wac
.mode_value
= 0;
180 case WACOM_HID_WD_OFFSETLEFT
:
181 case WACOM_HID_WD_OFFSETTOP
:
182 case WACOM_HID_WD_OFFSETRIGHT
:
183 case WACOM_HID_WD_OFFSETBOTTOM
:
185 n
= hid_report_len(field
->report
);
186 data
= hid_alloc_report_buf(field
->report
, GFP_KERNEL
);
189 data
[0] = field
->report
->id
;
190 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
191 data
, n
, WAC_CMD_RETRIES
);
193 ret
= hid_report_raw_event(hdev
, HID_FEATURE_REPORT
,
196 hid_warn(hdev
, "%s: could not retrieve sensor offsets\n",
203 if (hdev
->vendor
== USB_VENDOR_ID_WACOM
&&
204 hdev
->product
== 0x4200 /* Dell Canvas 27 */ &&
205 field
->application
== HID_UP_MSVENDOR
) {
206 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
207 wacom
->wacom_wac
.mode_value
= 2;
212 * Interface Descriptor of wacom devices can be incomplete and
213 * inconsistent so wacom_features table is used to store stylus
214 * device's packet lengths, various maximum values, and tablet
215 * resolution based on product ID's.
217 * For devices that contain 2 interfaces, wacom_features table is
218 * inaccurate for the touch interface. Since the Interface Descriptor
219 * for touch interfaces has pretty complete data, this function exists
220 * to query tablet for this missing information instead of hard coding in
221 * an additional table.
223 * A typical Interface Descriptor for a stylus will contain a
224 * boot mouse application collection that is not of interest and this
225 * function will ignore it.
227 * It also contains a digitizer application collection that also is not
228 * of interest since any information it contains would be duplicate
229 * of what is in wacom_features. Usually it defines a report of an array
230 * of bytes that could be used as max length of the stylus packet returned.
231 * If it happens to define a Digitizer-Stylus Physical Collection then
232 * the X and Y logical values contain valid data but it is ignored.
234 * A typical Interface Descriptor for a touch interface will contain a
235 * Digitizer-Finger Physical Collection which will define both logical
236 * X/Y maximum as well as the physical size of tablet. Since touch
237 * interfaces haven't supported pressure or distance, this is enough
238 * information to override invalid values in the wacom_features table.
240 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
241 * data. We deal with them after returning from this function.
243 static void wacom_usage_mapping(struct hid_device
*hdev
,
244 struct hid_field
*field
, struct hid_usage
*usage
)
246 struct wacom
*wacom
= hid_get_drvdata(hdev
);
247 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
248 bool finger
= WACOM_FINGER_FIELD(field
);
249 bool pen
= WACOM_PEN_FIELD(field
);
252 * Requiring Stylus Usage will ignore boot mouse
253 * X/Y values and some cases of invalid Digitizer X/Y
254 * values commonly reported.
257 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
259 features
->device_type
|= WACOM_DEVICETYPE_TOUCH
;
264 * Bamboo models do not support HID_DG_CONTACTMAX.
265 * And, Bamboo Pen only descriptor contains touch.
267 if (features
->type
> BAMBOO_PT
) {
268 /* ISDv4 touch devices at least supports one touch point */
269 if (finger
&& !features
->touch_max
)
270 features
->touch_max
= 1;
274 * ISDv4 devices which predate HID's adoption of the
275 * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its
276 * position instead. We can accurately detect if a
277 * usage with that value should be HID_DG_BARRELSWITCH2
278 * based on the surrounding usages, which have remained
279 * constant across generations.
281 if (features
->type
== HID_GENERIC
&&
282 usage
->hid
== 0x000D0000 &&
283 field
->application
== HID_DG_PEN
&&
284 field
->physical
== HID_DG_STYLUS
) {
285 int i
= usage
->usage_index
;
287 if (i
-4 >= 0 && i
+1 < field
->maxusage
&&
288 field
->usage
[i
-4].hid
== HID_DG_TIPSWITCH
&&
289 field
->usage
[i
-3].hid
== HID_DG_BARRELSWITCH
&&
290 field
->usage
[i
-2].hid
== HID_DG_ERASER
&&
291 field
->usage
[i
-1].hid
== HID_DG_INVERT
&&
292 field
->usage
[i
+1].hid
== HID_DG_INRANGE
) {
293 usage
->hid
= HID_DG_BARRELSWITCH2
;
297 /* 2nd-generation Intuos Pro Large has incorrect Y maximum */
298 if (hdev
->vendor
== USB_VENDOR_ID_WACOM
&&
299 hdev
->product
== 0x0358 &&
300 WACOM_PEN_FIELD(field
) &&
301 wacom_equivalent_usage(usage
->hid
) == HID_GD_Y
) {
302 field
->logical_maximum
= 43200;
305 switch (usage
->hid
) {
307 features
->x_max
= field
->logical_maximum
;
309 features
->x_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
;
318 features
->y_max
= field
->logical_maximum
;
320 features
->y_phy
= field
->physical_maximum
;
321 if ((features
->type
!= BAMBOO_PT
) &&
322 (features
->type
!= BAMBOO_TOUCH
)) {
323 features
->unit
= field
->unit
;
324 features
->unitExpo
= field
->unit_exponent
;
328 case HID_DG_TIPPRESSURE
:
330 features
->pressure_max
= field
->logical_maximum
;
334 if (features
->type
== HID_GENERIC
)
335 wacom_wac_usage_mapping(hdev
, field
, usage
);
338 static void wacom_post_parse_hid(struct hid_device
*hdev
,
339 struct wacom_features
*features
)
341 struct wacom
*wacom
= hid_get_drvdata(hdev
);
342 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
344 if (features
->type
== HID_GENERIC
) {
345 /* Any last-minute generic device setup */
346 if (wacom_wac
->has_mode_change
) {
347 if (wacom_wac
->is_direct_mode
)
348 features
->device_type
|= WACOM_DEVICETYPE_DIRECT
;
350 features
->device_type
&= ~WACOM_DEVICETYPE_DIRECT
;
353 if (features
->touch_max
> 1) {
354 if (features
->device_type
& WACOM_DEVICETYPE_DIRECT
)
355 input_mt_init_slots(wacom_wac
->touch_input
,
356 wacom_wac
->features
.touch_max
,
359 input_mt_init_slots(wacom_wac
->touch_input
,
360 wacom_wac
->features
.touch_max
,
366 static void wacom_parse_hid(struct hid_device
*hdev
,
367 struct wacom_features
*features
)
369 struct hid_report_enum
*rep_enum
;
370 struct hid_report
*hreport
;
373 /* check features first */
374 rep_enum
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
375 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
376 for (i
= 0; i
< hreport
->maxfield
; i
++) {
377 /* Ignore if report count is out of bounds. */
378 if (hreport
->field
[i
]->report_count
< 1)
381 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++) {
382 wacom_feature_mapping(hdev
, hreport
->field
[i
],
383 hreport
->field
[i
]->usage
+ j
);
388 /* now check the input usages */
389 rep_enum
= &hdev
->report_enum
[HID_INPUT_REPORT
];
390 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
392 if (!hreport
->maxfield
)
395 for (i
= 0; i
< hreport
->maxfield
; i
++)
396 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++)
397 wacom_usage_mapping(hdev
, hreport
->field
[i
],
398 hreport
->field
[i
]->usage
+ j
);
401 wacom_post_parse_hid(hdev
, features
);
404 static int wacom_hid_set_device_mode(struct hid_device
*hdev
)
406 struct wacom
*wacom
= hid_get_drvdata(hdev
);
407 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
408 struct hid_report
*r
;
409 struct hid_report_enum
*re
;
411 if (hid_data
->inputmode
< 0)
414 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
415 r
= re
->report_id_hash
[hid_data
->inputmode
];
417 r
->field
[0]->value
[hid_data
->inputmode_index
] = 2;
418 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
423 static int wacom_set_device_mode(struct hid_device
*hdev
,
424 struct wacom_wac
*wacom_wac
)
427 struct hid_report
*r
;
428 struct hid_report_enum
*re
;
430 int error
= -ENOMEM
, limit
= 0;
432 if (wacom_wac
->mode_report
< 0)
435 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
436 r
= re
->report_id_hash
[wacom_wac
->mode_report
];
440 rep_data
= hid_alloc_report_buf(r
, GFP_KERNEL
);
444 length
= hid_report_len(r
);
447 rep_data
[0] = wacom_wac
->mode_report
;
448 rep_data
[1] = wacom_wac
->mode_value
;
450 error
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
,
453 error
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
454 rep_data
, length
, 1);
455 } while (error
>= 0 &&
456 rep_data
[1] != wacom_wac
->mode_report
&&
457 limit
++ < WAC_MSG_RETRIES
);
461 return error
< 0 ? error
: 0;
464 static int wacom_bt_query_tablet_data(struct hid_device
*hdev
, u8 speed
,
465 struct wacom_features
*features
)
467 struct wacom
*wacom
= hid_get_drvdata(hdev
);
471 switch (features
->type
) {
475 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
479 rep_data
[0] = speed
== 0 ? 0x05 : 0x06;
482 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
,
486 wacom
->wacom_wac
.bt_high_speed
= speed
;
492 * Note that if the raw queries fail, it's not a hard failure
493 * and it is safe to continue
495 hid_warn(hdev
, "failed to poke device, command %d, err %d\n",
500 wacom
->wacom_wac
.bt_features
&= ~0x20;
502 wacom
->wacom_wac
.bt_features
|= 0x20;
505 rep_data
[1] = wacom
->wacom_wac
.bt_features
;
507 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
510 wacom
->wacom_wac
.bt_high_speed
= speed
;
518 * Switch the tablet into its most-capable mode. Wacom tablets are
519 * typically configured to power-up in a mode which sends mouse-like
520 * reports to the OS. To get absolute position, pressure data, etc.
521 * from the tablet, it is necessary to switch the tablet out of this
522 * mode and into one which sends the full range of tablet data.
524 static int _wacom_query_tablet_data(struct wacom
*wacom
)
526 struct hid_device
*hdev
= wacom
->hdev
;
527 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
528 struct wacom_features
*features
= &wacom_wac
->features
;
530 if (hdev
->bus
== BUS_BLUETOOTH
)
531 return wacom_bt_query_tablet_data(hdev
, 1, features
);
533 if (features
->type
!= HID_GENERIC
) {
534 if (features
->device_type
& WACOM_DEVICETYPE_TOUCH
) {
535 if (features
->type
> TABLETPC
) {
536 /* MT Tablet PC touch */
537 wacom_wac
->mode_report
= 3;
538 wacom_wac
->mode_value
= 4;
539 } else if (features
->type
== WACOM_24HDT
) {
540 wacom_wac
->mode_report
= 18;
541 wacom_wac
->mode_value
= 2;
542 } else if (features
->type
== WACOM_27QHDT
) {
543 wacom_wac
->mode_report
= 131;
544 wacom_wac
->mode_value
= 2;
545 } else if (features
->type
== BAMBOO_PAD
) {
546 wacom_wac
->mode_report
= 2;
547 wacom_wac
->mode_value
= 2;
549 } else if (features
->device_type
& WACOM_DEVICETYPE_PEN
) {
550 if (features
->type
<= BAMBOO_PT
) {
551 wacom_wac
->mode_report
= 2;
552 wacom_wac
->mode_value
= 2;
557 wacom_set_device_mode(hdev
, wacom_wac
);
559 if (features
->type
== HID_GENERIC
)
560 return wacom_hid_set_device_mode(hdev
);
565 static void wacom_retrieve_hid_descriptor(struct hid_device
*hdev
,
566 struct wacom_features
*features
)
568 struct wacom
*wacom
= hid_get_drvdata(hdev
);
569 struct usb_interface
*intf
= wacom
->intf
;
571 /* default features */
572 features
->x_fuzz
= 4;
573 features
->y_fuzz
= 4;
574 features
->pressure_fuzz
= 0;
575 features
->distance_fuzz
= 1;
576 features
->tilt_fuzz
= 1;
579 * The wireless device HID is basic and layout conflicts with
580 * other tablets (monitor and touch interface can look like pen).
581 * Skip the query for this type and modify defaults based on
584 if (features
->type
== WIRELESS
) {
585 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 0)
586 features
->device_type
= WACOM_DEVICETYPE_WL_MONITOR
;
588 features
->device_type
= WACOM_DEVICETYPE_NONE
;
592 wacom_parse_hid(hdev
, features
);
595 struct wacom_hdev_data
{
596 struct list_head list
;
598 struct hid_device
*dev
;
599 struct wacom_shared shared
;
602 static LIST_HEAD(wacom_udev_list
);
603 static DEFINE_MUTEX(wacom_udev_list_lock
);
605 static bool compare_device_paths(struct hid_device
*hdev_a
,
606 struct hid_device
*hdev_b
, char separator
)
608 int n1
= strrchr(hdev_a
->phys
, separator
) - hdev_a
->phys
;
609 int n2
= strrchr(hdev_b
->phys
, separator
) - hdev_b
->phys
;
611 if (n1
!= n2
|| n1
<= 0 || n2
<= 0)
614 return !strncmp(hdev_a
->phys
, hdev_b
->phys
, n1
);
617 static bool wacom_are_sibling(struct hid_device
*hdev
,
618 struct hid_device
*sibling
)
620 struct wacom
*wacom
= hid_get_drvdata(hdev
);
621 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
622 struct wacom
*sibling_wacom
= hid_get_drvdata(sibling
);
623 struct wacom_features
*sibling_features
= &sibling_wacom
->wacom_wac
.features
;
624 __u32 oVid
= features
->oVid
? features
->oVid
: hdev
->vendor
;
625 __u32 oPid
= features
->oPid
? features
->oPid
: hdev
->product
;
627 /* The defined oVid/oPid must match that of the sibling */
628 if (features
->oVid
!= HID_ANY_ID
&& sibling
->vendor
!= oVid
)
630 if (features
->oPid
!= HID_ANY_ID
&& sibling
->product
!= oPid
)
634 * Devices with the same VID/PID must share the same physical
635 * device path, while those with different VID/PID must share
636 * the same physical parent device path.
638 if (hdev
->vendor
== sibling
->vendor
&& hdev
->product
== sibling
->product
) {
639 if (!compare_device_paths(hdev
, sibling
, '/'))
642 if (!compare_device_paths(hdev
, sibling
, '.'))
646 /* Skip the remaining heuristics unless you are a HID_GENERIC device */
647 if (features
->type
!= HID_GENERIC
)
651 * Direct-input devices may not be siblings of indirect-input
654 if ((features
->device_type
& WACOM_DEVICETYPE_DIRECT
) &&
655 !(sibling_features
->device_type
& WACOM_DEVICETYPE_DIRECT
))
659 * Indirect-input devices may not be siblings of direct-input
662 if (!(features
->device_type
& WACOM_DEVICETYPE_DIRECT
) &&
663 (sibling_features
->device_type
& WACOM_DEVICETYPE_DIRECT
))
666 /* Pen devices may only be siblings of touch devices */
667 if ((features
->device_type
& WACOM_DEVICETYPE_PEN
) &&
668 !(sibling_features
->device_type
& WACOM_DEVICETYPE_TOUCH
))
671 /* Touch devices may only be siblings of pen devices */
672 if ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) &&
673 !(sibling_features
->device_type
& WACOM_DEVICETYPE_PEN
))
677 * No reason could be found for these two devices to NOT be
678 * siblings, so there's a good chance they ARE siblings
683 static struct wacom_hdev_data
*wacom_get_hdev_data(struct hid_device
*hdev
)
685 struct wacom_hdev_data
*data
;
687 /* Try to find an already-probed interface from the same device */
688 list_for_each_entry(data
, &wacom_udev_list
, list
) {
689 if (compare_device_paths(hdev
, data
->dev
, '/')) {
690 kref_get(&data
->kref
);
695 /* Fallback to finding devices that appear to be "siblings" */
696 list_for_each_entry(data
, &wacom_udev_list
, list
) {
697 if (wacom_are_sibling(hdev
, data
->dev
)) {
698 kref_get(&data
->kref
);
706 static void wacom_release_shared_data(struct kref
*kref
)
708 struct wacom_hdev_data
*data
=
709 container_of(kref
, struct wacom_hdev_data
, kref
);
711 mutex_lock(&wacom_udev_list_lock
);
712 list_del(&data
->list
);
713 mutex_unlock(&wacom_udev_list_lock
);
718 static void wacom_remove_shared_data(void *res
)
720 struct wacom
*wacom
= res
;
721 struct wacom_hdev_data
*data
;
722 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
724 if (wacom_wac
->shared
) {
725 data
= container_of(wacom_wac
->shared
, struct wacom_hdev_data
,
728 if (wacom_wac
->shared
->touch
== wacom
->hdev
)
729 wacom_wac
->shared
->touch
= NULL
;
730 else if (wacom_wac
->shared
->pen
== wacom
->hdev
)
731 wacom_wac
->shared
->pen
= NULL
;
733 kref_put(&data
->kref
, wacom_release_shared_data
);
734 wacom_wac
->shared
= NULL
;
738 static int wacom_add_shared_data(struct hid_device
*hdev
)
740 struct wacom
*wacom
= hid_get_drvdata(hdev
);
741 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
742 struct wacom_hdev_data
*data
;
745 mutex_lock(&wacom_udev_list_lock
);
747 data
= wacom_get_hdev_data(hdev
);
749 data
= kzalloc(sizeof(struct wacom_hdev_data
), GFP_KERNEL
);
755 kref_init(&data
->kref
);
757 list_add_tail(&data
->list
, &wacom_udev_list
);
760 wacom_wac
->shared
= &data
->shared
;
762 retval
= devm_add_action(&hdev
->dev
, wacom_remove_shared_data
, wacom
);
764 mutex_unlock(&wacom_udev_list_lock
);
765 wacom_remove_shared_data(wacom
);
769 if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
)
770 wacom_wac
->shared
->touch
= hdev
;
771 else if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_PEN
)
772 wacom_wac
->shared
->pen
= hdev
;
775 mutex_unlock(&wacom_udev_list_lock
);
779 static int wacom_led_control(struct wacom
*wacom
)
783 unsigned char report_id
= WAC_CMD_LED_CONTROL
;
786 if (!wacom
->led
.groups
)
789 if (wacom
->wacom_wac
.features
.type
== REMOTE
)
792 if (wacom
->wacom_wac
.pid
) { /* wireless connected */
793 report_id
= WAC_CMD_WL_LED_CONTROL
;
796 else if (wacom
->wacom_wac
.features
.type
== INTUOSP2_BT
) {
797 report_id
= WAC_CMD_WL_INTUOSP2
;
800 buf
= kzalloc(buf_size
, GFP_KERNEL
);
804 if (wacom
->wacom_wac
.features
.type
== HID_GENERIC
) {
805 buf
[0] = WAC_CMD_LED_CONTROL_GENERIC
;
806 buf
[1] = wacom
->led
.llv
;
807 buf
[2] = wacom
->led
.groups
[0].select
& 0x03;
809 } else if ((wacom
->wacom_wac
.features
.type
>= INTUOS5S
&&
810 wacom
->wacom_wac
.features
.type
<= INTUOSPL
)) {
812 * Touch Ring and crop mark LED luminance may take on
813 * one of four values:
814 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
816 int ring_led
= wacom
->led
.groups
[0].select
& 0x03;
817 int ring_lum
= (((wacom
->led
.llv
& 0x60) >> 5) - 1) & 0x03;
819 unsigned char led_bits
= (crop_lum
<< 4) | (ring_lum
<< 2) | (ring_led
);
822 if (wacom
->wacom_wac
.pid
) {
823 wacom_get_report(wacom
->hdev
, HID_FEATURE_REPORT
,
824 buf
, buf_size
, WAC_CMD_RETRIES
);
830 else if (wacom
->wacom_wac
.features
.type
== INTUOSP2_BT
) {
832 buf
[4] = 100; // Power Connection LED (ORANGE)
833 buf
[5] = 100; // BT Connection LED (BLUE)
834 buf
[6] = 100; // Paper Mode (RED?)
835 buf
[7] = 100; // Paper Mode (GREEN?)
836 buf
[8] = 100; // Paper Mode (BLUE?)
837 buf
[9] = wacom
->led
.llv
;
838 buf
[10] = wacom
->led
.groups
[0].select
& 0x03;
841 int led
= wacom
->led
.groups
[0].select
| 0x4;
843 if (wacom
->wacom_wac
.features
.type
== WACOM_21UX2
||
844 wacom
->wacom_wac
.features
.type
== WACOM_24HD
)
845 led
|= (wacom
->led
.groups
[1].select
<< 4) | 0x40;
849 buf
[2] = wacom
->led
.llv
;
850 buf
[3] = wacom
->led
.hlv
;
851 buf
[4] = wacom
->led
.img_lum
;
854 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, buf_size
,
861 static int wacom_led_putimage(struct wacom
*wacom
, int button_id
, u8 xfer_id
,
862 const unsigned len
, const void *img
)
866 const unsigned chunk_len
= len
/ 4; /* 4 chunks are needed to be sent */
868 buf
= kzalloc(chunk_len
+ 3 , GFP_KERNEL
);
872 /* Send 'start' command */
873 buf
[0] = WAC_CMD_ICON_START
;
875 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
881 buf
[1] = button_id
& 0x07;
882 for (i
= 0; i
< 4; i
++) {
884 memcpy(buf
+ 3, img
+ i
* chunk_len
, chunk_len
);
886 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
,
887 buf
, chunk_len
+ 3, WAC_CMD_RETRIES
);
893 buf
[0] = WAC_CMD_ICON_START
;
895 wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
903 static ssize_t
wacom_led_select_store(struct device
*dev
, int set_id
,
904 const char *buf
, size_t count
)
906 struct hid_device
*hdev
= to_hid_device(dev
);
907 struct wacom
*wacom
= hid_get_drvdata(hdev
);
911 err
= kstrtouint(buf
, 10, &id
);
915 mutex_lock(&wacom
->lock
);
917 wacom
->led
.groups
[set_id
].select
= id
& 0x3;
918 err
= wacom_led_control(wacom
);
920 mutex_unlock(&wacom
->lock
);
922 return err
< 0 ? err
: count
;
925 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
926 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
927 struct device_attribute *attr, const char *buf, size_t count) \
929 return wacom_led_select_store(dev, SET_ID, buf, count); \
931 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
932 struct device_attribute *attr, char *buf) \
934 struct hid_device *hdev = to_hid_device(dev);\
935 struct wacom *wacom = hid_get_drvdata(hdev); \
936 return scnprintf(buf, PAGE_SIZE, "%d\n", \
937 wacom->led.groups[SET_ID].select); \
939 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
940 wacom_led##SET_ID##_select_show, \
941 wacom_led##SET_ID##_select_store)
943 DEVICE_LED_SELECT_ATTR(0);
944 DEVICE_LED_SELECT_ATTR(1);
946 static ssize_t
wacom_luminance_store(struct wacom
*wacom
, u8
*dest
,
947 const char *buf
, size_t count
)
952 err
= kstrtouint(buf
, 10, &value
);
956 mutex_lock(&wacom
->lock
);
958 *dest
= value
& 0x7f;
959 err
= wacom_led_control(wacom
);
961 mutex_unlock(&wacom
->lock
);
963 return err
< 0 ? err
: count
;
966 #define DEVICE_LUMINANCE_ATTR(name, field) \
967 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
968 struct device_attribute *attr, const char *buf, size_t count) \
970 struct hid_device *hdev = to_hid_device(dev);\
971 struct wacom *wacom = hid_get_drvdata(hdev); \
973 return wacom_luminance_store(wacom, &wacom->led.field, \
976 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
977 struct device_attribute *attr, char *buf) \
979 struct wacom *wacom = dev_get_drvdata(dev); \
980 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
982 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
983 wacom_##name##_luminance_show, \
984 wacom_##name##_luminance_store)
986 DEVICE_LUMINANCE_ATTR(status0
, llv
);
987 DEVICE_LUMINANCE_ATTR(status1
, hlv
);
988 DEVICE_LUMINANCE_ATTR(buttons
, img_lum
);
990 static ssize_t
wacom_button_image_store(struct device
*dev
, int button_id
,
991 const char *buf
, size_t count
)
993 struct hid_device
*hdev
= to_hid_device(dev
);
994 struct wacom
*wacom
= hid_get_drvdata(hdev
);
999 if (hdev
->bus
== BUS_BLUETOOTH
) {
1001 xfer_id
= WAC_CMD_ICON_BT_XFER
;
1004 xfer_id
= WAC_CMD_ICON_XFER
;
1010 mutex_lock(&wacom
->lock
);
1012 err
= wacom_led_putimage(wacom
, button_id
, xfer_id
, len
, buf
);
1014 mutex_unlock(&wacom
->lock
);
1016 return err
< 0 ? err
: count
;
1019 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
1020 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
1021 struct device_attribute *attr, const char *buf, size_t count) \
1023 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
1025 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
1026 NULL, wacom_btnimg##BUTTON_ID##_store)
1028 DEVICE_BTNIMG_ATTR(0);
1029 DEVICE_BTNIMG_ATTR(1);
1030 DEVICE_BTNIMG_ATTR(2);
1031 DEVICE_BTNIMG_ATTR(3);
1032 DEVICE_BTNIMG_ATTR(4);
1033 DEVICE_BTNIMG_ATTR(5);
1034 DEVICE_BTNIMG_ATTR(6);
1035 DEVICE_BTNIMG_ATTR(7);
1037 static struct attribute
*cintiq_led_attrs
[] = {
1038 &dev_attr_status_led0_select
.attr
,
1039 &dev_attr_status_led1_select
.attr
,
1043 static struct attribute_group cintiq_led_attr_group
= {
1044 .name
= "wacom_led",
1045 .attrs
= cintiq_led_attrs
,
1048 static struct attribute
*intuos4_led_attrs
[] = {
1049 &dev_attr_status0_luminance
.attr
,
1050 &dev_attr_status1_luminance
.attr
,
1051 &dev_attr_status_led0_select
.attr
,
1052 &dev_attr_buttons_luminance
.attr
,
1053 &dev_attr_button0_rawimg
.attr
,
1054 &dev_attr_button1_rawimg
.attr
,
1055 &dev_attr_button2_rawimg
.attr
,
1056 &dev_attr_button3_rawimg
.attr
,
1057 &dev_attr_button4_rawimg
.attr
,
1058 &dev_attr_button5_rawimg
.attr
,
1059 &dev_attr_button6_rawimg
.attr
,
1060 &dev_attr_button7_rawimg
.attr
,
1064 static struct attribute_group intuos4_led_attr_group
= {
1065 .name
= "wacom_led",
1066 .attrs
= intuos4_led_attrs
,
1069 static struct attribute
*intuos5_led_attrs
[] = {
1070 &dev_attr_status0_luminance
.attr
,
1071 &dev_attr_status_led0_select
.attr
,
1075 static struct attribute_group intuos5_led_attr_group
= {
1076 .name
= "wacom_led",
1077 .attrs
= intuos5_led_attrs
,
1080 static struct attribute
*generic_led_attrs
[] = {
1081 &dev_attr_status0_luminance
.attr
,
1082 &dev_attr_status_led0_select
.attr
,
1086 static struct attribute_group generic_led_attr_group
= {
1087 .name
= "wacom_led",
1088 .attrs
= generic_led_attrs
,
1091 struct wacom_sysfs_group_devres
{
1092 struct attribute_group
*group
;
1093 struct kobject
*root
;
1096 static void wacom_devm_sysfs_group_release(struct device
*dev
, void *res
)
1098 struct wacom_sysfs_group_devres
*devres
= res
;
1099 struct kobject
*kobj
= devres
->root
;
1101 dev_dbg(dev
, "%s: dropping reference to %s\n",
1102 __func__
, devres
->group
->name
);
1103 sysfs_remove_group(kobj
, devres
->group
);
1106 static int __wacom_devm_sysfs_create_group(struct wacom
*wacom
,
1107 struct kobject
*root
,
1108 struct attribute_group
*group
)
1110 struct wacom_sysfs_group_devres
*devres
;
1113 devres
= devres_alloc(wacom_devm_sysfs_group_release
,
1114 sizeof(struct wacom_sysfs_group_devres
),
1119 devres
->group
= group
;
1120 devres
->root
= root
;
1122 error
= sysfs_create_group(devres
->root
, group
);
1124 devres_free(devres
);
1128 devres_add(&wacom
->hdev
->dev
, devres
);
1133 static int wacom_devm_sysfs_create_group(struct wacom
*wacom
,
1134 struct attribute_group
*group
)
1136 return __wacom_devm_sysfs_create_group(wacom
, &wacom
->hdev
->dev
.kobj
,
1140 enum led_brightness
wacom_leds_brightness_get(struct wacom_led
*led
)
1142 struct wacom
*wacom
= led
->wacom
;
1144 if (wacom
->led
.max_hlv
)
1145 return led
->hlv
* LED_FULL
/ wacom
->led
.max_hlv
;
1147 if (wacom
->led
.max_llv
)
1148 return led
->llv
* LED_FULL
/ wacom
->led
.max_llv
;
1150 /* device doesn't support brightness tuning */
1154 static enum led_brightness
__wacom_led_brightness_get(struct led_classdev
*cdev
)
1156 struct wacom_led
*led
= container_of(cdev
, struct wacom_led
, cdev
);
1157 struct wacom
*wacom
= led
->wacom
;
1159 if (wacom
->led
.groups
[led
->group
].select
!= led
->id
)
1162 return wacom_leds_brightness_get(led
);
1165 static int wacom_led_brightness_set(struct led_classdev
*cdev
,
1166 enum led_brightness brightness
)
1168 struct wacom_led
*led
= container_of(cdev
, struct wacom_led
, cdev
);
1169 struct wacom
*wacom
= led
->wacom
;
1172 mutex_lock(&wacom
->lock
);
1174 if (!wacom
->led
.groups
|| (brightness
== LED_OFF
&&
1175 wacom
->led
.groups
[led
->group
].select
!= led
->id
)) {
1180 led
->llv
= wacom
->led
.llv
= wacom
->led
.max_llv
* brightness
/ LED_FULL
;
1181 led
->hlv
= wacom
->led
.hlv
= wacom
->led
.max_hlv
* brightness
/ LED_FULL
;
1183 wacom
->led
.groups
[led
->group
].select
= led
->id
;
1185 error
= wacom_led_control(wacom
);
1188 mutex_unlock(&wacom
->lock
);
1193 static void wacom_led_readonly_brightness_set(struct led_classdev
*cdev
,
1194 enum led_brightness brightness
)
1198 static int wacom_led_register_one(struct device
*dev
, struct wacom
*wacom
,
1199 struct wacom_led
*led
, unsigned int group
,
1200 unsigned int id
, bool read_only
)
1205 name
= devm_kasprintf(dev
, GFP_KERNEL
,
1214 led
->trigger
.name
= name
;
1215 error
= devm_led_trigger_register(dev
, &led
->trigger
);
1217 hid_err(wacom
->hdev
,
1218 "failed to register LED trigger %s: %d\n",
1219 led
->cdev
.name
, error
);
1227 led
->llv
= wacom
->led
.llv
;
1228 led
->hlv
= wacom
->led
.hlv
;
1229 led
->cdev
.name
= name
;
1230 led
->cdev
.max_brightness
= LED_FULL
;
1231 led
->cdev
.flags
= LED_HW_PLUGGABLE
;
1232 led
->cdev
.brightness_get
= __wacom_led_brightness_get
;
1234 led
->cdev
.brightness_set_blocking
= wacom_led_brightness_set
;
1235 led
->cdev
.default_trigger
= led
->cdev
.name
;
1237 led
->cdev
.brightness_set
= wacom_led_readonly_brightness_set
;
1240 error
= devm_led_classdev_register(dev
, &led
->cdev
);
1242 hid_err(wacom
->hdev
,
1243 "failed to register LED %s: %d\n",
1244 led
->cdev
.name
, error
);
1245 led
->cdev
.name
= NULL
;
1252 static void wacom_led_groups_release_one(void *data
)
1254 struct wacom_group_leds
*group
= data
;
1256 devres_release_group(group
->dev
, group
);
1259 static int wacom_led_groups_alloc_and_register_one(struct device
*dev
,
1260 struct wacom
*wacom
,
1261 int group_id
, int count
,
1264 struct wacom_led
*leds
;
1267 if (group_id
>= wacom
->led
.count
|| count
<= 0)
1270 if (!devres_open_group(dev
, &wacom
->led
.groups
[group_id
], GFP_KERNEL
))
1273 leds
= devm_kzalloc(dev
, sizeof(struct wacom_led
) * count
, GFP_KERNEL
);
1279 wacom
->led
.groups
[group_id
].leds
= leds
;
1280 wacom
->led
.groups
[group_id
].count
= count
;
1282 for (i
= 0; i
< count
; i
++) {
1283 error
= wacom_led_register_one(dev
, wacom
, &leds
[i
],
1284 group_id
, i
, read_only
);
1289 wacom
->led
.groups
[group_id
].dev
= dev
;
1291 devres_close_group(dev
, &wacom
->led
.groups
[group_id
]);
1294 * There is a bug (?) in devm_led_classdev_register() in which its
1295 * increments the refcount of the parent. If the parent is an input
1296 * device, that means the ref count never reaches 0 when
1297 * devm_input_device_release() gets called.
1298 * This means that the LEDs are still there after disconnect.
1299 * Manually force the release of the group so that the leds are released
1300 * once we are done using them.
1302 error
= devm_add_action_or_reset(&wacom
->hdev
->dev
,
1303 wacom_led_groups_release_one
,
1304 &wacom
->led
.groups
[group_id
]);
1311 devres_release_group(dev
, &wacom
->led
.groups
[group_id
]);
1315 struct wacom_led
*wacom_led_find(struct wacom
*wacom
, unsigned int group_id
,
1318 struct wacom_group_leds
*group
;
1320 if (group_id
>= wacom
->led
.count
)
1323 group
= &wacom
->led
.groups
[group_id
];
1330 return &group
->leds
[id
];
1334 * wacom_led_next: gives the next available led with a wacom trigger.
1336 * returns the next available struct wacom_led which has its default trigger
1337 * or the current one if none is available.
1339 struct wacom_led
*wacom_led_next(struct wacom
*wacom
, struct wacom_led
*cur
)
1341 struct wacom_led
*next_led
;
1351 next_led
= wacom_led_find(wacom
, group
, ++next
);
1352 if (!next_led
|| next_led
== cur
)
1354 } while (next_led
->cdev
.trigger
!= &next_led
->trigger
);
1359 static void wacom_led_groups_release(void *data
)
1361 struct wacom
*wacom
= data
;
1363 wacom
->led
.groups
= NULL
;
1364 wacom
->led
.count
= 0;
1367 static int wacom_led_groups_allocate(struct wacom
*wacom
, int count
)
1369 struct device
*dev
= &wacom
->hdev
->dev
;
1370 struct wacom_group_leds
*groups
;
1373 groups
= devm_kzalloc(dev
, sizeof(struct wacom_group_leds
) * count
,
1378 error
= devm_add_action_or_reset(dev
, wacom_led_groups_release
, wacom
);
1382 wacom
->led
.groups
= groups
;
1383 wacom
->led
.count
= count
;
1388 static int wacom_leds_alloc_and_register(struct wacom
*wacom
, int group_count
,
1389 int led_per_group
, bool read_only
)
1394 if (!wacom
->wacom_wac
.pad_input
)
1397 dev
= &wacom
->wacom_wac
.pad_input
->dev
;
1399 error
= wacom_led_groups_allocate(wacom
, group_count
);
1403 for (i
= 0; i
< group_count
; i
++) {
1404 error
= wacom_led_groups_alloc_and_register_one(dev
, wacom
, i
,
1414 int wacom_initialize_leds(struct wacom
*wacom
)
1418 if (!(wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
))
1421 /* Initialize default values */
1422 switch (wacom
->wacom_wac
.features
.type
) {
1424 if (!wacom
->generic_has_leds
)
1426 wacom
->led
.llv
= 100;
1427 wacom
->led
.max_llv
= 100;
1429 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1431 hid_err(wacom
->hdev
,
1432 "cannot create leds err: %d\n", error
);
1436 error
= wacom_devm_sysfs_create_group(wacom
,
1437 &generic_led_attr_group
);
1444 wacom
->led
.llv
= 10;
1445 wacom
->led
.hlv
= 20;
1446 wacom
->led
.max_llv
= 127;
1447 wacom
->led
.max_hlv
= 127;
1448 wacom
->led
.img_lum
= 10;
1450 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1452 hid_err(wacom
->hdev
,
1453 "cannot create leds err: %d\n", error
);
1457 error
= wacom_devm_sysfs_create_group(wacom
,
1458 &intuos4_led_attr_group
);
1465 wacom
->led
.img_lum
= 0;
1467 error
= wacom_leds_alloc_and_register(wacom
, 2, 4, false);
1469 hid_err(wacom
->hdev
,
1470 "cannot create leds err: %d\n", error
);
1474 error
= wacom_devm_sysfs_create_group(wacom
,
1475 &cintiq_led_attr_group
);
1484 wacom
->led
.llv
= 32;
1485 wacom
->led
.max_llv
= 96;
1487 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1489 hid_err(wacom
->hdev
,
1490 "cannot create leds err: %d\n", error
);
1494 error
= wacom_devm_sysfs_create_group(wacom
,
1495 &intuos5_led_attr_group
);
1499 wacom
->led
.llv
= 50;
1500 wacom
->led
.max_llv
= 100;
1501 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1503 hid_err(wacom
->hdev
,
1504 "cannot create leds err: %d\n", error
);
1510 wacom
->led
.llv
= 255;
1511 wacom
->led
.max_llv
= 255;
1512 error
= wacom_led_groups_allocate(wacom
, 5);
1514 hid_err(wacom
->hdev
,
1515 "cannot create leds err: %d\n", error
);
1525 hid_err(wacom
->hdev
,
1526 "cannot create sysfs group err: %d\n", error
);
1533 static void wacom_init_work(struct work_struct
*work
)
1535 struct wacom
*wacom
= container_of(work
, struct wacom
, init_work
.work
);
1537 _wacom_query_tablet_data(wacom
);
1538 wacom_led_control(wacom
);
1541 static void wacom_query_tablet_data(struct wacom
*wacom
)
1543 schedule_delayed_work(&wacom
->init_work
, msecs_to_jiffies(1000));
1546 static enum power_supply_property wacom_battery_props
[] = {
1547 POWER_SUPPLY_PROP_MODEL_NAME
,
1548 POWER_SUPPLY_PROP_PRESENT
,
1549 POWER_SUPPLY_PROP_STATUS
,
1550 POWER_SUPPLY_PROP_SCOPE
,
1551 POWER_SUPPLY_PROP_CAPACITY
1554 static int wacom_battery_get_property(struct power_supply
*psy
,
1555 enum power_supply_property psp
,
1556 union power_supply_propval
*val
)
1558 struct wacom_battery
*battery
= power_supply_get_drvdata(psy
);
1562 case POWER_SUPPLY_PROP_MODEL_NAME
:
1563 val
->strval
= battery
->wacom
->wacom_wac
.name
;
1565 case POWER_SUPPLY_PROP_PRESENT
:
1566 val
->intval
= battery
->bat_connected
;
1568 case POWER_SUPPLY_PROP_SCOPE
:
1569 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
1571 case POWER_SUPPLY_PROP_CAPACITY
:
1572 val
->intval
= battery
->battery_capacity
;
1574 case POWER_SUPPLY_PROP_STATUS
:
1575 if (battery
->bat_status
!= WACOM_POWER_SUPPLY_STATUS_AUTO
)
1576 val
->intval
= battery
->bat_status
;
1577 else if (battery
->bat_charging
)
1578 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
1579 else if (battery
->battery_capacity
== 100 &&
1580 battery
->ps_connected
)
1581 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
1582 else if (battery
->ps_connected
)
1583 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1585 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
1595 static int __wacom_initialize_battery(struct wacom
*wacom
,
1596 struct wacom_battery
*battery
)
1598 static atomic_t battery_no
= ATOMIC_INIT(0);
1599 struct device
*dev
= &wacom
->hdev
->dev
;
1600 struct power_supply_config psy_cfg
= { .drv_data
= battery
, };
1601 struct power_supply
*ps_bat
;
1602 struct power_supply_desc
*bat_desc
= &battery
->bat_desc
;
1606 if (!devres_open_group(dev
, bat_desc
, GFP_KERNEL
))
1609 battery
->wacom
= wacom
;
1611 n
= atomic_inc_return(&battery_no
) - 1;
1613 bat_desc
->properties
= wacom_battery_props
;
1614 bat_desc
->num_properties
= ARRAY_SIZE(wacom_battery_props
);
1615 bat_desc
->get_property
= wacom_battery_get_property
;
1616 sprintf(battery
->bat_name
, "wacom_battery_%ld", n
);
1617 bat_desc
->name
= battery
->bat_name
;
1618 bat_desc
->type
= POWER_SUPPLY_TYPE_USB
;
1619 bat_desc
->use_for_apm
= 0;
1621 ps_bat
= devm_power_supply_register(dev
, bat_desc
, &psy_cfg
);
1622 if (IS_ERR(ps_bat
)) {
1623 error
= PTR_ERR(ps_bat
);
1627 power_supply_powers(ps_bat
, &wacom
->hdev
->dev
);
1629 battery
->battery
= ps_bat
;
1631 devres_close_group(dev
, bat_desc
);
1635 devres_release_group(dev
, bat_desc
);
1639 static int wacom_initialize_battery(struct wacom
*wacom
)
1641 if (wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
)
1642 return __wacom_initialize_battery(wacom
, &wacom
->battery
);
1647 static void wacom_destroy_battery(struct wacom
*wacom
)
1649 if (wacom
->battery
.battery
) {
1650 devres_release_group(&wacom
->hdev
->dev
,
1651 &wacom
->battery
.bat_desc
);
1652 wacom
->battery
.battery
= NULL
;
1656 static ssize_t
wacom_show_speed(struct device
*dev
,
1657 struct device_attribute
1660 struct hid_device
*hdev
= to_hid_device(dev
);
1661 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1663 return snprintf(buf
, PAGE_SIZE
, "%i\n", wacom
->wacom_wac
.bt_high_speed
);
1666 static ssize_t
wacom_store_speed(struct device
*dev
,
1667 struct device_attribute
*attr
,
1668 const char *buf
, size_t count
)
1670 struct hid_device
*hdev
= to_hid_device(dev
);
1671 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1674 if (kstrtou8(buf
, 0, &new_speed
))
1677 if (new_speed
!= 0 && new_speed
!= 1)
1680 wacom_bt_query_tablet_data(hdev
, new_speed
, &wacom
->wacom_wac
.features
);
1685 static DEVICE_ATTR(speed
, DEV_ATTR_RW_PERM
,
1686 wacom_show_speed
, wacom_store_speed
);
1689 static ssize_t
wacom_show_remote_mode(struct kobject
*kobj
,
1690 struct kobj_attribute
*kattr
,
1691 char *buf
, int index
)
1693 struct device
*dev
= kobj_to_dev(kobj
->parent
);
1694 struct hid_device
*hdev
= to_hid_device(dev
);
1695 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1698 mode
= wacom
->led
.groups
[index
].select
;
1699 return sprintf(buf
, "%d\n", mode
< 3 ? mode
: -1);
1702 #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1703 static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1704 struct kobj_attribute *kattr, char *buf) \
1706 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1708 static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1709 .attr = {.name = "remote_mode", \
1710 .mode = DEV_ATTR_RO_PERM}, \
1711 .show = wacom_show_remote##SET_ID##_mode, \
1713 static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1714 &remote##SET_ID##_mode_attr.attr, \
1717 static struct attribute_group remote##SET_ID##_serial_group = { \
1719 .attrs = remote##SET_ID##_serial_attrs, \
1722 DEVICE_EKR_ATTR_GROUP(0);
1723 DEVICE_EKR_ATTR_GROUP(1);
1724 DEVICE_EKR_ATTR_GROUP(2);
1725 DEVICE_EKR_ATTR_GROUP(3);
1726 DEVICE_EKR_ATTR_GROUP(4);
1728 static int wacom_remote_create_attr_group(struct wacom
*wacom
, __u32 serial
,
1732 struct wacom_remote
*remote
= wacom
->remote
;
1734 remote
->remotes
[index
].group
.name
= devm_kasprintf(&wacom
->hdev
->dev
,
1737 if (!remote
->remotes
[index
].group
.name
)
1740 error
= __wacom_devm_sysfs_create_group(wacom
, remote
->remote_dir
,
1741 &remote
->remotes
[index
].group
);
1743 remote
->remotes
[index
].group
.name
= NULL
;
1744 hid_err(wacom
->hdev
,
1745 "cannot create sysfs group err: %d\n", error
);
1752 static int wacom_cmd_unpair_remote(struct wacom
*wacom
, unsigned char selector
)
1754 const size_t buf_size
= 2;
1758 buf
= kzalloc(buf_size
, GFP_KERNEL
);
1762 buf
[0] = WAC_CMD_DELETE_PAIRING
;
1765 retval
= wacom_set_report(wacom
->hdev
, HID_OUTPUT_REPORT
, buf
,
1766 buf_size
, WAC_CMD_RETRIES
);
1772 static ssize_t
wacom_store_unpair_remote(struct kobject
*kobj
,
1773 struct kobj_attribute
*attr
,
1774 const char *buf
, size_t count
)
1776 unsigned char selector
= 0;
1777 struct device
*dev
= kobj_to_dev(kobj
->parent
);
1778 struct hid_device
*hdev
= to_hid_device(dev
);
1779 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1782 if (!strncmp(buf
, "*\n", 2)) {
1783 selector
= WAC_CMD_UNPAIR_ALL
;
1785 hid_info(wacom
->hdev
, "remote: unrecognized unpair code: %s\n",
1790 mutex_lock(&wacom
->lock
);
1792 err
= wacom_cmd_unpair_remote(wacom
, selector
);
1793 mutex_unlock(&wacom
->lock
);
1795 return err
< 0 ? err
: count
;
1798 static struct kobj_attribute unpair_remote_attr
= {
1799 .attr
= {.name
= "unpair_remote", .mode
= 0200},
1800 .store
= wacom_store_unpair_remote
,
1803 static const struct attribute
*remote_unpair_attrs
[] = {
1804 &unpair_remote_attr
.attr
,
1808 static void wacom_remotes_destroy(void *data
)
1810 struct wacom
*wacom
= data
;
1811 struct wacom_remote
*remote
= wacom
->remote
;
1816 kobject_put(remote
->remote_dir
);
1817 kfifo_free(&remote
->remote_fifo
);
1818 wacom
->remote
= NULL
;
1821 static int wacom_initialize_remotes(struct wacom
*wacom
)
1824 struct wacom_remote
*remote
;
1827 if (wacom
->wacom_wac
.features
.type
!= REMOTE
)
1830 remote
= devm_kzalloc(&wacom
->hdev
->dev
, sizeof(*wacom
->remote
),
1835 wacom
->remote
= remote
;
1837 spin_lock_init(&remote
->remote_lock
);
1839 error
= kfifo_alloc(&remote
->remote_fifo
,
1840 5 * sizeof(struct wacom_remote_data
),
1843 hid_err(wacom
->hdev
, "failed allocating remote_fifo\n");
1847 remote
->remotes
[0].group
= remote0_serial_group
;
1848 remote
->remotes
[1].group
= remote1_serial_group
;
1849 remote
->remotes
[2].group
= remote2_serial_group
;
1850 remote
->remotes
[3].group
= remote3_serial_group
;
1851 remote
->remotes
[4].group
= remote4_serial_group
;
1853 remote
->remote_dir
= kobject_create_and_add("wacom_remote",
1854 &wacom
->hdev
->dev
.kobj
);
1855 if (!remote
->remote_dir
)
1858 error
= sysfs_create_files(remote
->remote_dir
, remote_unpair_attrs
);
1861 hid_err(wacom
->hdev
,
1862 "cannot create sysfs group err: %d\n", error
);
1866 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
1867 wacom
->led
.groups
[i
].select
= WACOM_STATUS_UNKNOWN
;
1868 remote
->remotes
[i
].serial
= 0;
1871 error
= devm_add_action_or_reset(&wacom
->hdev
->dev
,
1872 wacom_remotes_destroy
, wacom
);
1879 static struct input_dev
*wacom_allocate_input(struct wacom
*wacom
)
1881 struct input_dev
*input_dev
;
1882 struct hid_device
*hdev
= wacom
->hdev
;
1883 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1885 input_dev
= devm_input_allocate_device(&hdev
->dev
);
1889 input_dev
->name
= wacom_wac
->features
.name
;
1890 input_dev
->phys
= hdev
->phys
;
1891 input_dev
->dev
.parent
= &hdev
->dev
;
1892 input_dev
->open
= wacom_open
;
1893 input_dev
->close
= wacom_close
;
1894 input_dev
->uniq
= hdev
->uniq
;
1895 input_dev
->id
.bustype
= hdev
->bus
;
1896 input_dev
->id
.vendor
= hdev
->vendor
;
1897 input_dev
->id
.product
= wacom_wac
->pid
? wacom_wac
->pid
: hdev
->product
;
1898 input_dev
->id
.version
= hdev
->version
;
1899 input_set_drvdata(input_dev
, wacom
);
1904 static int wacom_allocate_inputs(struct wacom
*wacom
)
1906 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1908 wacom_wac
->pen_input
= wacom_allocate_input(wacom
);
1909 wacom_wac
->touch_input
= wacom_allocate_input(wacom
);
1910 wacom_wac
->pad_input
= wacom_allocate_input(wacom
);
1911 if (!wacom_wac
->pen_input
||
1912 !wacom_wac
->touch_input
||
1913 !wacom_wac
->pad_input
)
1916 wacom_wac
->pen_input
->name
= wacom_wac
->pen_name
;
1917 wacom_wac
->touch_input
->name
= wacom_wac
->touch_name
;
1918 wacom_wac
->pad_input
->name
= wacom_wac
->pad_name
;
1923 static int wacom_register_inputs(struct wacom
*wacom
)
1925 struct input_dev
*pen_input_dev
, *touch_input_dev
, *pad_input_dev
;
1926 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1929 pen_input_dev
= wacom_wac
->pen_input
;
1930 touch_input_dev
= wacom_wac
->touch_input
;
1931 pad_input_dev
= wacom_wac
->pad_input
;
1933 if (!pen_input_dev
|| !touch_input_dev
|| !pad_input_dev
)
1936 error
= wacom_setup_pen_input_capabilities(pen_input_dev
, wacom_wac
);
1938 /* no pen in use on this interface */
1939 input_free_device(pen_input_dev
);
1940 wacom_wac
->pen_input
= NULL
;
1941 pen_input_dev
= NULL
;
1943 error
= input_register_device(pen_input_dev
);
1948 error
= wacom_setup_touch_input_capabilities(touch_input_dev
, wacom_wac
);
1950 /* no touch in use on this interface */
1951 input_free_device(touch_input_dev
);
1952 wacom_wac
->touch_input
= NULL
;
1953 touch_input_dev
= NULL
;
1955 error
= input_register_device(touch_input_dev
);
1960 error
= wacom_setup_pad_input_capabilities(pad_input_dev
, wacom_wac
);
1962 /* no pad in use on this interface */
1963 input_free_device(pad_input_dev
);
1964 wacom_wac
->pad_input
= NULL
;
1965 pad_input_dev
= NULL
;
1967 error
= input_register_device(pad_input_dev
);
1975 wacom_wac
->pad_input
= NULL
;
1976 wacom_wac
->touch_input
= NULL
;
1977 wacom_wac
->pen_input
= NULL
;
1982 * Not all devices report physical dimensions from HID.
1983 * Compute the default from hardcoded logical dimension
1984 * and resolution before driver overwrites them.
1986 static void wacom_set_default_phy(struct wacom_features
*features
)
1988 if (features
->x_resolution
) {
1989 features
->x_phy
= (features
->x_max
* 100) /
1990 features
->x_resolution
;
1991 features
->y_phy
= (features
->y_max
* 100) /
1992 features
->y_resolution
;
1996 static void wacom_calculate_res(struct wacom_features
*features
)
1998 /* set unit to "100th of a mm" for devices not reported by HID */
1999 if (!features
->unit
) {
2000 features
->unit
= 0x11;
2001 features
->unitExpo
= -3;
2004 features
->x_resolution
= wacom_calc_hid_res(features
->x_max
,
2007 features
->unitExpo
);
2008 features
->y_resolution
= wacom_calc_hid_res(features
->y_max
,
2011 features
->unitExpo
);
2014 void wacom_battery_work(struct work_struct
*work
)
2016 struct wacom
*wacom
= container_of(work
, struct wacom
, battery_work
);
2018 if ((wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
2019 !wacom
->battery
.battery
) {
2020 wacom_initialize_battery(wacom
);
2022 else if (!(wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
2023 wacom
->battery
.battery
) {
2024 wacom_destroy_battery(wacom
);
2028 static size_t wacom_compute_pktlen(struct hid_device
*hdev
)
2030 struct hid_report_enum
*report_enum
;
2031 struct hid_report
*report
;
2034 report_enum
= hdev
->report_enum
+ HID_INPUT_REPORT
;
2036 list_for_each_entry(report
, &report_enum
->report_list
, list
) {
2037 size_t report_size
= hid_report_len(report
);
2038 if (report_size
> size
)
2045 static void wacom_update_name(struct wacom
*wacom
, const char *suffix
)
2047 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2048 struct wacom_features
*features
= &wacom_wac
->features
;
2049 char name
[WACOM_NAME_MAX
];
2051 /* Generic devices name unspecified */
2052 if ((features
->type
== HID_GENERIC
) && !strcmp("Wacom HID", features
->name
)) {
2053 char *product_name
= wacom
->hdev
->name
;
2055 if (hid_is_using_ll_driver(wacom
->hdev
, &usb_hid_driver
)) {
2056 struct usb_interface
*intf
= to_usb_interface(wacom
->hdev
->dev
.parent
);
2057 struct usb_device
*dev
= interface_to_usbdev(intf
);
2058 product_name
= dev
->product
;
2061 if (wacom
->hdev
->bus
== BUS_I2C
) {
2062 snprintf(name
, sizeof(name
), "%s %X",
2063 features
->name
, wacom
->hdev
->product
);
2064 } else if (strstr(product_name
, "Wacom") ||
2065 strstr(product_name
, "wacom") ||
2066 strstr(product_name
, "WACOM")) {
2067 strlcpy(name
, product_name
, sizeof(name
));
2069 snprintf(name
, sizeof(name
), "Wacom %s", product_name
);
2072 /* strip out excess whitespaces */
2074 char *gap
= strstr(name
, " ");
2077 /* shift everything including the terminator */
2078 memmove(gap
, gap
+1, strlen(gap
));
2081 /* get rid of trailing whitespace */
2082 if (name
[strlen(name
)-1] == ' ')
2083 name
[strlen(name
)-1] = '\0';
2085 strlcpy(name
, features
->name
, sizeof(name
));
2088 snprintf(wacom_wac
->name
, sizeof(wacom_wac
->name
), "%s%s",
2091 /* Append the device type to the name */
2092 snprintf(wacom_wac
->pen_name
, sizeof(wacom_wac
->pen_name
),
2093 "%s%s Pen", name
, suffix
);
2094 snprintf(wacom_wac
->touch_name
, sizeof(wacom_wac
->touch_name
),
2095 "%s%s Finger", name
, suffix
);
2096 snprintf(wacom_wac
->pad_name
, sizeof(wacom_wac
->pad_name
),
2097 "%s%s Pad", name
, suffix
);
2100 static void wacom_release_resources(struct wacom
*wacom
)
2102 struct hid_device
*hdev
= wacom
->hdev
;
2104 if (!wacom
->resources
)
2107 devres_release_group(&hdev
->dev
, wacom
);
2109 wacom
->resources
= false;
2111 wacom
->wacom_wac
.pen_input
= NULL
;
2112 wacom
->wacom_wac
.touch_input
= NULL
;
2113 wacom
->wacom_wac
.pad_input
= NULL
;
2116 static void wacom_set_shared_values(struct wacom_wac
*wacom_wac
)
2118 if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
) {
2119 wacom_wac
->shared
->type
= wacom_wac
->features
.type
;
2120 wacom_wac
->shared
->touch_input
= wacom_wac
->touch_input
;
2123 if (wacom_wac
->has_mute_touch_switch
) {
2124 wacom_wac
->shared
->has_mute_touch_switch
= true;
2125 wacom_wac
->shared
->is_touch_on
= true;
2128 if (wacom_wac
->shared
->has_mute_touch_switch
&&
2129 wacom_wac
->shared
->touch_input
) {
2130 set_bit(EV_SW
, wacom_wac
->shared
->touch_input
->evbit
);
2131 input_set_capability(wacom_wac
->shared
->touch_input
, EV_SW
,
2136 static int wacom_parse_and_register(struct wacom
*wacom
, bool wireless
)
2138 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2139 struct wacom_features
*features
= &wacom_wac
->features
;
2140 struct hid_device
*hdev
= wacom
->hdev
;
2142 unsigned int connect_mask
= HID_CONNECT_HIDRAW
;
2144 features
->pktlen
= wacom_compute_pktlen(hdev
);
2145 if (features
->pktlen
> WACOM_PKGLEN_MAX
)
2148 if (!devres_open_group(&hdev
->dev
, wacom
, GFP_KERNEL
))
2151 wacom
->resources
= true;
2153 error
= wacom_allocate_inputs(wacom
);
2158 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
2159 * into debug mode for the touch part.
2160 * We ignore the other interfaces.
2162 if (features
->type
== BAMBOO_PAD
) {
2163 if (features
->pktlen
== WACOM_PKGLEN_PENABLED
) {
2164 features
->type
= HID_GENERIC
;
2165 } else if ((features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH
) &&
2166 (features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH_USB
)) {
2172 /* set the default size in case we do not get them from hid */
2173 wacom_set_default_phy(features
);
2175 /* Retrieve the physical and logical size for touch devices */
2176 wacom_retrieve_hid_descriptor(hdev
, features
);
2177 wacom_setup_device_quirks(wacom
);
2179 if (features
->device_type
== WACOM_DEVICETYPE_NONE
&&
2180 features
->type
!= WIRELESS
) {
2181 error
= features
->type
== HID_GENERIC
? -ENODEV
: 0;
2183 dev_warn(&hdev
->dev
, "Unknown device_type for '%s'. %s.",
2185 error
? "Ignoring" : "Assuming pen");
2190 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
2193 wacom_calculate_res(features
);
2195 wacom_update_name(wacom
, wireless
? " (WL)" : "");
2197 /* pen only Bamboo neither support touch nor pad */
2198 if ((features
->type
== BAMBOO_PEN
) &&
2199 ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) ||
2200 (features
->device_type
& WACOM_DEVICETYPE_PAD
))) {
2205 error
= wacom_add_shared_data(hdev
);
2209 if (!(features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
) &&
2210 (features
->quirks
& WACOM_QUIRK_BATTERY
)) {
2211 error
= wacom_initialize_battery(wacom
);
2216 error
= wacom_register_inputs(wacom
);
2220 if (wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
) {
2221 error
= wacom_initialize_leds(wacom
);
2225 error
= wacom_initialize_remotes(wacom
);
2230 if (features
->type
== HID_GENERIC
)
2231 connect_mask
|= HID_CONNECT_DRIVER
;
2233 /* Regular HID work starts now */
2234 error
= hid_hw_start(hdev
, connect_mask
);
2236 hid_err(hdev
, "hw start failed\n");
2241 /* Note that if query fails it is not a hard failure */
2242 wacom_query_tablet_data(wacom
);
2245 /* touch only Bamboo doesn't support pen */
2246 if ((features
->type
== BAMBOO_TOUCH
) &&
2247 (features
->device_type
& WACOM_DEVICETYPE_PEN
)) {
2248 cancel_delayed_work_sync(&wacom
->init_work
);
2249 _wacom_query_tablet_data(wacom
);
2254 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
2255 error
= hid_hw_open(hdev
);
2257 wacom_set_shared_values(wacom_wac
);
2258 devres_close_group(&hdev
->dev
, wacom
);
2265 wacom_release_resources(wacom
);
2269 static void wacom_wireless_work(struct work_struct
*work
)
2271 struct wacom
*wacom
= container_of(work
, struct wacom
, wireless_work
);
2272 struct usb_device
*usbdev
= wacom
->usbdev
;
2273 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2274 struct hid_device
*hdev1
, *hdev2
;
2275 struct wacom
*wacom1
, *wacom2
;
2276 struct wacom_wac
*wacom_wac1
, *wacom_wac2
;
2280 * Regardless if this is a disconnect or a new tablet,
2281 * remove any existing input and battery devices.
2284 wacom_destroy_battery(wacom
);
2286 /* Stylus interface */
2287 hdev1
= usb_get_intfdata(usbdev
->config
->interface
[1]);
2288 wacom1
= hid_get_drvdata(hdev1
);
2289 wacom_wac1
= &(wacom1
->wacom_wac
);
2290 wacom_release_resources(wacom1
);
2292 /* Touch interface */
2293 hdev2
= usb_get_intfdata(usbdev
->config
->interface
[2]);
2294 wacom2
= hid_get_drvdata(hdev2
);
2295 wacom_wac2
= &(wacom2
->wacom_wac
);
2296 wacom_release_resources(wacom2
);
2298 if (wacom_wac
->pid
== 0) {
2299 hid_info(wacom
->hdev
, "wireless tablet disconnected\n");
2301 const struct hid_device_id
*id
= wacom_ids
;
2303 hid_info(wacom
->hdev
, "wireless tablet connected with PID %x\n",
2307 if (id
->vendor
== USB_VENDOR_ID_WACOM
&&
2308 id
->product
== wacom_wac
->pid
)
2314 hid_info(wacom
->hdev
, "ignoring unknown PID.\n");
2318 /* Stylus interface */
2319 wacom_wac1
->features
=
2320 *((struct wacom_features
*)id
->driver_data
);
2322 wacom_wac1
->pid
= wacom_wac
->pid
;
2324 error
= wacom_parse_and_register(wacom1
, true);
2328 /* Touch interface */
2329 if (wacom_wac1
->features
.touch_max
||
2330 (wacom_wac1
->features
.type
>= INTUOSHT
&&
2331 wacom_wac1
->features
.type
<= BAMBOO_PT
)) {
2332 wacom_wac2
->features
=
2333 *((struct wacom_features
*)id
->driver_data
);
2334 wacom_wac2
->pid
= wacom_wac
->pid
;
2336 error
= wacom_parse_and_register(wacom2
, true);
2341 strlcpy(wacom_wac
->name
, wacom_wac1
->name
,
2342 sizeof(wacom_wac
->name
));
2343 error
= wacom_initialize_battery(wacom
);
2351 wacom_release_resources(wacom1
);
2352 wacom_release_resources(wacom2
);
2356 static void wacom_remote_destroy_one(struct wacom
*wacom
, unsigned int index
)
2358 struct wacom_remote
*remote
= wacom
->remote
;
2359 u32 serial
= remote
->remotes
[index
].serial
;
2361 unsigned long flags
;
2363 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
2364 if (remote
->remotes
[i
].serial
== serial
) {
2366 spin_lock_irqsave(&remote
->remote_lock
, flags
);
2367 remote
->remotes
[i
].registered
= false;
2368 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2370 if (remote
->remotes
[i
].battery
.battery
)
2371 devres_release_group(&wacom
->hdev
->dev
,
2372 &remote
->remotes
[i
].battery
.bat_desc
);
2374 if (remote
->remotes
[i
].group
.name
)
2375 devres_release_group(&wacom
->hdev
->dev
,
2376 &remote
->remotes
[i
]);
2378 remote
->remotes
[i
].serial
= 0;
2379 remote
->remotes
[i
].group
.name
= NULL
;
2380 remote
->remotes
[i
].battery
.battery
= NULL
;
2381 wacom
->led
.groups
[i
].select
= WACOM_STATUS_UNKNOWN
;
2386 static int wacom_remote_create_one(struct wacom
*wacom
, u32 serial
,
2389 struct wacom_remote
*remote
= wacom
->remote
;
2390 struct device
*dev
= &wacom
->hdev
->dev
;
2393 /* A remote can pair more than once with an EKR,
2394 * check to make sure this serial isn't already paired.
2396 for (k
= 0; k
< WACOM_MAX_REMOTES
; k
++) {
2397 if (remote
->remotes
[k
].serial
== serial
)
2401 if (k
< WACOM_MAX_REMOTES
) {
2402 remote
->remotes
[index
].serial
= serial
;
2406 if (!devres_open_group(dev
, &remote
->remotes
[index
], GFP_KERNEL
))
2409 error
= wacom_remote_create_attr_group(wacom
, serial
, index
);
2413 remote
->remotes
[index
].input
= wacom_allocate_input(wacom
);
2414 if (!remote
->remotes
[index
].input
) {
2418 remote
->remotes
[index
].input
->uniq
= remote
->remotes
[index
].group
.name
;
2419 remote
->remotes
[index
].input
->name
= wacom
->wacom_wac
.pad_name
;
2421 if (!remote
->remotes
[index
].input
->name
) {
2426 error
= wacom_setup_pad_input_capabilities(remote
->remotes
[index
].input
,
2431 remote
->remotes
[index
].serial
= serial
;
2433 error
= input_register_device(remote
->remotes
[index
].input
);
2437 error
= wacom_led_groups_alloc_and_register_one(
2438 &remote
->remotes
[index
].input
->dev
,
2439 wacom
, index
, 3, true);
2443 remote
->remotes
[index
].registered
= true;
2445 devres_close_group(dev
, &remote
->remotes
[index
]);
2449 devres_release_group(dev
, &remote
->remotes
[index
]);
2450 remote
->remotes
[index
].serial
= 0;
2454 static int wacom_remote_attach_battery(struct wacom
*wacom
, int index
)
2456 struct wacom_remote
*remote
= wacom
->remote
;
2459 if (!remote
->remotes
[index
].registered
)
2462 if (remote
->remotes
[index
].battery
.battery
)
2465 if (wacom
->led
.groups
[index
].select
== WACOM_STATUS_UNKNOWN
)
2468 error
= __wacom_initialize_battery(wacom
,
2469 &wacom
->remote
->remotes
[index
].battery
);
2476 static void wacom_remote_work(struct work_struct
*work
)
2478 struct wacom
*wacom
= container_of(work
, struct wacom
, remote_work
);
2479 struct wacom_remote
*remote
= wacom
->remote
;
2480 struct wacom_remote_data data
;
2481 unsigned long flags
;
2486 spin_lock_irqsave(&remote
->remote_lock
, flags
);
2488 count
= kfifo_out(&remote
->remote_fifo
, &data
, sizeof(data
));
2490 if (count
!= sizeof(data
)) {
2491 hid_err(wacom
->hdev
,
2492 "workitem triggered without status available\n");
2493 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2497 if (!kfifo_is_empty(&remote
->remote_fifo
))
2498 wacom_schedule_work(&wacom
->wacom_wac
, WACOM_WORKER_REMOTE
);
2500 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2502 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
2503 serial
= data
.remote
[i
].serial
;
2504 if (data
.remote
[i
].connected
) {
2506 if (remote
->remotes
[i
].serial
== serial
) {
2507 wacom_remote_attach_battery(wacom
, i
);
2511 if (remote
->remotes
[i
].serial
)
2512 wacom_remote_destroy_one(wacom
, i
);
2514 wacom_remote_create_one(wacom
, serial
, i
);
2516 } else if (remote
->remotes
[i
].serial
) {
2517 wacom_remote_destroy_one(wacom
, i
);
2522 static void wacom_mode_change_work(struct work_struct
*work
)
2524 struct wacom
*wacom
= container_of(work
, struct wacom
, mode_change_work
);
2525 struct wacom_shared
*shared
= wacom
->wacom_wac
.shared
;
2526 struct wacom
*wacom1
= NULL
;
2527 struct wacom
*wacom2
= NULL
;
2528 bool is_direct
= wacom
->wacom_wac
.is_direct_mode
;
2532 wacom1
= hid_get_drvdata(shared
->pen
);
2533 wacom_release_resources(wacom1
);
2534 hid_hw_stop(wacom1
->hdev
);
2535 wacom1
->wacom_wac
.has_mode_change
= true;
2536 wacom1
->wacom_wac
.is_direct_mode
= is_direct
;
2539 if (shared
->touch
) {
2540 wacom2
= hid_get_drvdata(shared
->touch
);
2541 wacom_release_resources(wacom2
);
2542 hid_hw_stop(wacom2
->hdev
);
2543 wacom2
->wacom_wac
.has_mode_change
= true;
2544 wacom2
->wacom_wac
.is_direct_mode
= is_direct
;
2548 error
= wacom_parse_and_register(wacom1
, false);
2554 error
= wacom_parse_and_register(wacom2
, false);
2562 static int wacom_probe(struct hid_device
*hdev
,
2563 const struct hid_device_id
*id
)
2565 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
2566 struct usb_device
*dev
= interface_to_usbdev(intf
);
2567 struct wacom
*wacom
;
2568 struct wacom_wac
*wacom_wac
;
2569 struct wacom_features
*features
;
2572 if (!id
->driver_data
)
2575 hdev
->quirks
|= HID_QUIRK_NO_INIT_REPORTS
;
2577 /* hid-core sets this quirk for the boot interface */
2578 hdev
->quirks
&= ~HID_QUIRK_NOGET
;
2580 wacom
= devm_kzalloc(&hdev
->dev
, sizeof(struct wacom
), GFP_KERNEL
);
2584 hid_set_drvdata(hdev
, wacom
);
2587 wacom_wac
= &wacom
->wacom_wac
;
2588 wacom_wac
->features
= *((struct wacom_features
*)id
->driver_data
);
2589 features
= &wacom_wac
->features
;
2591 if (features
->check_for_hid_type
&& features
->hid_type
!= hdev
->type
) {
2596 wacom_wac
->hid_data
.inputmode
= -1;
2597 wacom_wac
->mode_report
= -1;
2599 wacom
->usbdev
= dev
;
2601 mutex_init(&wacom
->lock
);
2602 INIT_DELAYED_WORK(&wacom
->init_work
, wacom_init_work
);
2603 INIT_WORK(&wacom
->wireless_work
, wacom_wireless_work
);
2604 INIT_WORK(&wacom
->battery_work
, wacom_battery_work
);
2605 INIT_WORK(&wacom
->remote_work
, wacom_remote_work
);
2606 INIT_WORK(&wacom
->mode_change_work
, wacom_mode_change_work
);
2608 /* ask for the report descriptor to be loaded by HID */
2609 error
= hid_parse(hdev
);
2611 hid_err(hdev
, "parse failed\n");
2615 error
= wacom_parse_and_register(wacom
, false);
2619 if (hdev
->bus
== BUS_BLUETOOTH
) {
2620 error
= device_create_file(&hdev
->dev
, &dev_attr_speed
);
2623 "can't create sysfs speed attribute err: %d\n",
2630 hid_set_drvdata(hdev
, NULL
);
2634 static void wacom_remove(struct hid_device
*hdev
)
2636 struct wacom
*wacom
= hid_get_drvdata(hdev
);
2637 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2638 struct wacom_features
*features
= &wacom_wac
->features
;
2640 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
2645 cancel_delayed_work_sync(&wacom
->init_work
);
2646 cancel_work_sync(&wacom
->wireless_work
);
2647 cancel_work_sync(&wacom
->battery_work
);
2648 cancel_work_sync(&wacom
->remote_work
);
2649 cancel_work_sync(&wacom
->mode_change_work
);
2650 if (hdev
->bus
== BUS_BLUETOOTH
)
2651 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
2653 /* make sure we don't trigger the LEDs */
2654 wacom_led_groups_release(wacom
);
2656 if (wacom
->wacom_wac
.features
.type
!= REMOTE
)
2657 wacom_release_resources(wacom
);
2659 hid_set_drvdata(hdev
, NULL
);
2663 static int wacom_resume(struct hid_device
*hdev
)
2665 struct wacom
*wacom
= hid_get_drvdata(hdev
);
2667 mutex_lock(&wacom
->lock
);
2669 /* switch to wacom mode first */
2670 _wacom_query_tablet_data(wacom
);
2671 wacom_led_control(wacom
);
2673 mutex_unlock(&wacom
->lock
);
2678 static int wacom_reset_resume(struct hid_device
*hdev
)
2680 return wacom_resume(hdev
);
2682 #endif /* CONFIG_PM */
2684 static struct hid_driver wacom_driver
= {
2686 .id_table
= wacom_ids
,
2687 .probe
= wacom_probe
,
2688 .remove
= wacom_remove
,
2689 .report
= wacom_wac_report
,
2691 .resume
= wacom_resume
,
2692 .reset_resume
= wacom_reset_resume
,
2694 .raw_event
= wacom_raw_event
,
2696 module_hid_driver(wacom_driver
);
2698 MODULE_VERSION(DRIVER_VERSION
);
2699 MODULE_AUTHOR(DRIVER_AUTHOR
);
2700 MODULE_DESCRIPTION(DRIVER_DESC
);
2701 MODULE_LICENSE("GPL");