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
;
126 switch (usage
->hid
) {
127 case HID_DG_CONTACTMAX
:
128 /* leave touch_max as is if predefined */
129 if (!features
->touch_max
) {
131 data
= kzalloc(2, GFP_KERNEL
);
134 data
[0] = field
->report
->id
;
135 ret
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
136 data
, 2, WAC_CMD_RETRIES
);
138 features
->touch_max
= data
[1];
140 features
->touch_max
= 16;
141 hid_warn(hdev
, "wacom_feature_mapping: "
142 "could not get HID_DG_CONTACTMAX, "
143 "defaulting to %d\n",
144 features
->touch_max
);
149 case HID_DG_INPUTMODE
:
150 /* Ignore if value index is out of bounds. */
151 if (usage
->usage_index
>= field
->report_count
) {
152 dev_err(&hdev
->dev
, "HID_DG_INPUTMODE out of range\n");
156 hid_data
->inputmode
= field
->report
->id
;
157 hid_data
->inputmode_index
= usage
->usage_index
;
160 case HID_UP_DIGITIZER
:
161 if (field
->report
->id
== 0x0B &&
162 (field
->application
== WACOM_HID_G9_PEN
||
163 field
->application
== WACOM_HID_G11_PEN
)) {
164 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
165 wacom
->wacom_wac
.mode_value
= 0;
169 case WACOM_HID_UP_G9
:
170 case WACOM_HID_UP_G11
:
171 if (field
->report
->id
== 0x03 &&
172 (field
->application
== WACOM_HID_G9_TOUCHSCREEN
||
173 field
->application
== WACOM_HID_G11_TOUCHSCREEN
)) {
174 wacom
->wacom_wac
.mode_report
= field
->report
->id
;
175 wacom
->wacom_wac
.mode_value
= 0;
182 * Interface Descriptor of wacom devices can be incomplete and
183 * inconsistent so wacom_features table is used to store stylus
184 * device's packet lengths, various maximum values, and tablet
185 * resolution based on product ID's.
187 * For devices that contain 2 interfaces, wacom_features table is
188 * inaccurate for the touch interface. Since the Interface Descriptor
189 * for touch interfaces has pretty complete data, this function exists
190 * to query tablet for this missing information instead of hard coding in
191 * an additional table.
193 * A typical Interface Descriptor for a stylus will contain a
194 * boot mouse application collection that is not of interest and this
195 * function will ignore it.
197 * It also contains a digitizer application collection that also is not
198 * of interest since any information it contains would be duplicate
199 * of what is in wacom_features. Usually it defines a report of an array
200 * of bytes that could be used as max length of the stylus packet returned.
201 * If it happens to define a Digitizer-Stylus Physical Collection then
202 * the X and Y logical values contain valid data but it is ignored.
204 * A typical Interface Descriptor for a touch interface will contain a
205 * Digitizer-Finger Physical Collection which will define both logical
206 * X/Y maximum as well as the physical size of tablet. Since touch
207 * interfaces haven't supported pressure or distance, this is enough
208 * information to override invalid values in the wacom_features table.
210 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
211 * data. We deal with them after returning from this function.
213 static void wacom_usage_mapping(struct hid_device
*hdev
,
214 struct hid_field
*field
, struct hid_usage
*usage
)
216 struct wacom
*wacom
= hid_get_drvdata(hdev
);
217 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
218 bool finger
= WACOM_FINGER_FIELD(field
);
219 bool pen
= WACOM_PEN_FIELD(field
);
222 * Requiring Stylus Usage will ignore boot mouse
223 * X/Y values and some cases of invalid Digitizer X/Y
224 * values commonly reported.
227 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
229 features
->device_type
|= WACOM_DEVICETYPE_TOUCH
;
234 * Bamboo models do not support HID_DG_CONTACTMAX.
235 * And, Bamboo Pen only descriptor contains touch.
237 if (features
->type
> BAMBOO_PT
) {
238 /* ISDv4 touch devices at least supports one touch point */
239 if (finger
&& !features
->touch_max
)
240 features
->touch_max
= 1;
244 * ISDv4 devices which predate HID's adoption of the
245 * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its
246 * position instead. We can accurately detect if a
247 * usage with that value should be HID_DG_BARRELSWITCH2
248 * based on the surrounding usages, which have remained
249 * constant across generations.
251 if (features
->type
== HID_GENERIC
&&
252 usage
->hid
== 0x000D0000 &&
253 field
->application
== HID_DG_PEN
&&
254 field
->physical
== HID_DG_STYLUS
) {
255 int i
= usage
->usage_index
;
257 if (i
-4 >= 0 && i
+1 < field
->maxusage
&&
258 field
->usage
[i
-4].hid
== HID_DG_TIPSWITCH
&&
259 field
->usage
[i
-3].hid
== HID_DG_BARRELSWITCH
&&
260 field
->usage
[i
-2].hid
== HID_DG_ERASER
&&
261 field
->usage
[i
-1].hid
== HID_DG_INVERT
&&
262 field
->usage
[i
+1].hid
== HID_DG_INRANGE
) {
263 usage
->hid
= HID_DG_BARRELSWITCH2
;
267 switch (usage
->hid
) {
269 features
->x_max
= field
->logical_maximum
;
271 features
->x_phy
= field
->physical_maximum
;
272 if ((features
->type
!= BAMBOO_PT
) &&
273 (features
->type
!= BAMBOO_TOUCH
)) {
274 features
->unit
= field
->unit
;
275 features
->unitExpo
= field
->unit_exponent
;
280 features
->y_max
= field
->logical_maximum
;
282 features
->y_phy
= field
->physical_maximum
;
283 if ((features
->type
!= BAMBOO_PT
) &&
284 (features
->type
!= BAMBOO_TOUCH
)) {
285 features
->unit
= field
->unit
;
286 features
->unitExpo
= field
->unit_exponent
;
290 case HID_DG_TIPPRESSURE
:
292 features
->pressure_max
= field
->logical_maximum
;
296 if (features
->type
== HID_GENERIC
)
297 wacom_wac_usage_mapping(hdev
, field
, usage
);
300 static void wacom_post_parse_hid(struct hid_device
*hdev
,
301 struct wacom_features
*features
)
303 struct wacom
*wacom
= hid_get_drvdata(hdev
);
304 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
306 if (features
->type
== HID_GENERIC
) {
307 /* Any last-minute generic device setup */
308 if (features
->touch_max
> 1) {
309 input_mt_init_slots(wacom_wac
->touch_input
, wacom_wac
->features
.touch_max
,
315 static void wacom_parse_hid(struct hid_device
*hdev
,
316 struct wacom_features
*features
)
318 struct hid_report_enum
*rep_enum
;
319 struct hid_report
*hreport
;
322 /* check features first */
323 rep_enum
= &hdev
->report_enum
[HID_FEATURE_REPORT
];
324 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
325 for (i
= 0; i
< hreport
->maxfield
; i
++) {
326 /* Ignore if report count is out of bounds. */
327 if (hreport
->field
[i
]->report_count
< 1)
330 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++) {
331 wacom_feature_mapping(hdev
, hreport
->field
[i
],
332 hreport
->field
[i
]->usage
+ j
);
337 /* now check the input usages */
338 rep_enum
= &hdev
->report_enum
[HID_INPUT_REPORT
];
339 list_for_each_entry(hreport
, &rep_enum
->report_list
, list
) {
341 if (!hreport
->maxfield
)
344 for (i
= 0; i
< hreport
->maxfield
; i
++)
345 for (j
= 0; j
< hreport
->field
[i
]->maxusage
; j
++)
346 wacom_usage_mapping(hdev
, hreport
->field
[i
],
347 hreport
->field
[i
]->usage
+ j
);
350 wacom_post_parse_hid(hdev
, features
);
353 static int wacom_hid_set_device_mode(struct hid_device
*hdev
)
355 struct wacom
*wacom
= hid_get_drvdata(hdev
);
356 struct hid_data
*hid_data
= &wacom
->wacom_wac
.hid_data
;
357 struct hid_report
*r
;
358 struct hid_report_enum
*re
;
360 if (hid_data
->inputmode
< 0)
363 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
364 r
= re
->report_id_hash
[hid_data
->inputmode
];
366 r
->field
[0]->value
[hid_data
->inputmode_index
] = 2;
367 hid_hw_request(hdev
, r
, HID_REQ_SET_REPORT
);
372 static int wacom_set_device_mode(struct hid_device
*hdev
,
373 struct wacom_wac
*wacom_wac
)
376 struct hid_report
*r
;
377 struct hid_report_enum
*re
;
379 int error
= -ENOMEM
, limit
= 0;
381 if (wacom_wac
->mode_report
< 0)
384 re
= &(hdev
->report_enum
[HID_FEATURE_REPORT
]);
385 r
= re
->report_id_hash
[wacom_wac
->mode_report
];
389 rep_data
= hid_alloc_report_buf(r
, GFP_KERNEL
);
393 length
= hid_report_len(r
);
396 rep_data
[0] = wacom_wac
->mode_report
;
397 rep_data
[1] = wacom_wac
->mode_value
;
399 error
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
,
402 error
= wacom_get_report(hdev
, HID_FEATURE_REPORT
,
403 rep_data
, length
, 1);
404 } while (error
>= 0 &&
405 rep_data
[1] != wacom_wac
->mode_report
&&
406 limit
++ < WAC_MSG_RETRIES
);
410 return error
< 0 ? error
: 0;
413 static int wacom_bt_query_tablet_data(struct hid_device
*hdev
, u8 speed
,
414 struct wacom_features
*features
)
416 struct wacom
*wacom
= hid_get_drvdata(hdev
);
420 switch (features
->type
) {
424 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
428 rep_data
[0] = speed
== 0 ? 0x05 : 0x06;
431 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
,
435 wacom
->wacom_wac
.bt_high_speed
= speed
;
441 * Note that if the raw queries fail, it's not a hard failure
442 * and it is safe to continue
444 hid_warn(hdev
, "failed to poke device, command %d, err %d\n",
449 wacom
->wacom_wac
.bt_features
&= ~0x20;
451 wacom
->wacom_wac
.bt_features
|= 0x20;
454 rep_data
[1] = wacom
->wacom_wac
.bt_features
;
456 ret
= wacom_set_report(hdev
, HID_FEATURE_REPORT
, rep_data
, 2,
459 wacom
->wacom_wac
.bt_high_speed
= speed
;
467 * Switch the tablet into its most-capable mode. Wacom tablets are
468 * typically configured to power-up in a mode which sends mouse-like
469 * reports to the OS. To get absolute position, pressure data, etc.
470 * from the tablet, it is necessary to switch the tablet out of this
471 * mode and into one which sends the full range of tablet data.
473 static int wacom_query_tablet_data(struct hid_device
*hdev
,
474 struct wacom_features
*features
)
476 struct wacom
*wacom
= hid_get_drvdata(hdev
);
477 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
479 if (hdev
->bus
== BUS_BLUETOOTH
)
480 return wacom_bt_query_tablet_data(hdev
, 1, features
);
482 if (features
->type
!= HID_GENERIC
) {
483 if (features
->device_type
& WACOM_DEVICETYPE_TOUCH
) {
484 if (features
->type
> TABLETPC
) {
485 /* MT Tablet PC touch */
486 wacom_wac
->mode_report
= 3;
487 wacom_wac
->mode_value
= 4;
488 } else if (features
->type
== WACOM_24HDT
) {
489 wacom_wac
->mode_report
= 18;
490 wacom_wac
->mode_value
= 2;
491 } else if (features
->type
== WACOM_27QHDT
) {
492 wacom_wac
->mode_report
= 131;
493 wacom_wac
->mode_value
= 2;
494 } else if (features
->type
== BAMBOO_PAD
) {
495 wacom_wac
->mode_report
= 2;
496 wacom_wac
->mode_value
= 2;
498 } else if (features
->device_type
& WACOM_DEVICETYPE_PEN
) {
499 if (features
->type
<= BAMBOO_PT
) {
500 wacom_wac
->mode_report
= 2;
501 wacom_wac
->mode_value
= 2;
506 wacom_set_device_mode(hdev
, wacom_wac
);
508 if (features
->type
== HID_GENERIC
)
509 return wacom_hid_set_device_mode(hdev
);
514 static void wacom_retrieve_hid_descriptor(struct hid_device
*hdev
,
515 struct wacom_features
*features
)
517 struct wacom
*wacom
= hid_get_drvdata(hdev
);
518 struct usb_interface
*intf
= wacom
->intf
;
520 /* default features */
521 features
->x_fuzz
= 4;
522 features
->y_fuzz
= 4;
523 features
->pressure_fuzz
= 0;
524 features
->distance_fuzz
= 1;
525 features
->tilt_fuzz
= 1;
528 * The wireless device HID is basic and layout conflicts with
529 * other tablets (monitor and touch interface can look like pen).
530 * Skip the query for this type and modify defaults based on
533 if (features
->type
== WIRELESS
) {
534 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
== 0)
535 features
->device_type
= WACOM_DEVICETYPE_WL_MONITOR
;
537 features
->device_type
= WACOM_DEVICETYPE_NONE
;
541 wacom_parse_hid(hdev
, features
);
544 struct wacom_hdev_data
{
545 struct list_head list
;
547 struct hid_device
*dev
;
548 struct wacom_shared shared
;
551 static LIST_HEAD(wacom_udev_list
);
552 static DEFINE_MUTEX(wacom_udev_list_lock
);
554 static bool compare_device_paths(struct hid_device
*hdev_a
,
555 struct hid_device
*hdev_b
, char separator
)
557 int n1
= strrchr(hdev_a
->phys
, separator
) - hdev_a
->phys
;
558 int n2
= strrchr(hdev_b
->phys
, separator
) - hdev_b
->phys
;
560 if (n1
!= n2
|| n1
<= 0 || n2
<= 0)
563 return !strncmp(hdev_a
->phys
, hdev_b
->phys
, n1
);
566 static bool wacom_are_sibling(struct hid_device
*hdev
,
567 struct hid_device
*sibling
)
569 struct wacom
*wacom
= hid_get_drvdata(hdev
);
570 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
571 struct wacom
*sibling_wacom
= hid_get_drvdata(sibling
);
572 struct wacom_features
*sibling_features
= &sibling_wacom
->wacom_wac
.features
;
573 __u32 oVid
= features
->oVid
? features
->oVid
: hdev
->vendor
;
574 __u32 oPid
= features
->oPid
? features
->oPid
: hdev
->product
;
576 /* The defined oVid/oPid must match that of the sibling */
577 if (features
->oVid
!= HID_ANY_ID
&& sibling
->vendor
!= oVid
)
579 if (features
->oPid
!= HID_ANY_ID
&& sibling
->product
!= oPid
)
583 * Devices with the same VID/PID must share the same physical
584 * device path, while those with different VID/PID must share
585 * the same physical parent device path.
587 if (hdev
->vendor
== sibling
->vendor
&& hdev
->product
== sibling
->product
) {
588 if (!compare_device_paths(hdev
, sibling
, '/'))
591 if (!compare_device_paths(hdev
, sibling
, '.'))
595 /* Skip the remaining heuristics unless you are a HID_GENERIC device */
596 if (features
->type
!= HID_GENERIC
)
600 * Direct-input devices may not be siblings of indirect-input
603 if ((features
->device_type
& WACOM_DEVICETYPE_DIRECT
) &&
604 !(sibling_features
->device_type
& WACOM_DEVICETYPE_DIRECT
))
608 * Indirect-input devices may not be siblings of direct-input
611 if (!(features
->device_type
& WACOM_DEVICETYPE_DIRECT
) &&
612 (sibling_features
->device_type
& WACOM_DEVICETYPE_DIRECT
))
615 /* Pen devices may only be siblings of touch devices */
616 if ((features
->device_type
& WACOM_DEVICETYPE_PEN
) &&
617 !(sibling_features
->device_type
& WACOM_DEVICETYPE_TOUCH
))
620 /* Touch devices may only be siblings of pen devices */
621 if ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) &&
622 !(sibling_features
->device_type
& WACOM_DEVICETYPE_PEN
))
626 * No reason could be found for these two devices to NOT be
627 * siblings, so there's a good chance they ARE siblings
632 static struct wacom_hdev_data
*wacom_get_hdev_data(struct hid_device
*hdev
)
634 struct wacom_hdev_data
*data
;
636 /* Try to find an already-probed interface from the same device */
637 list_for_each_entry(data
, &wacom_udev_list
, list
) {
638 if (compare_device_paths(hdev
, data
->dev
, '/'))
642 /* Fallback to finding devices that appear to be "siblings" */
643 list_for_each_entry(data
, &wacom_udev_list
, list
) {
644 if (wacom_are_sibling(hdev
, data
->dev
)) {
645 kref_get(&data
->kref
);
653 static void wacom_release_shared_data(struct kref
*kref
)
655 struct wacom_hdev_data
*data
=
656 container_of(kref
, struct wacom_hdev_data
, kref
);
658 mutex_lock(&wacom_udev_list_lock
);
659 list_del(&data
->list
);
660 mutex_unlock(&wacom_udev_list_lock
);
665 static void wacom_remove_shared_data(void *res
)
667 struct wacom
*wacom
= res
;
668 struct wacom_hdev_data
*data
;
669 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
671 if (wacom_wac
->shared
) {
672 data
= container_of(wacom_wac
->shared
, struct wacom_hdev_data
,
675 if (wacom_wac
->shared
->touch
== wacom
->hdev
)
676 wacom_wac
->shared
->touch
= NULL
;
677 else if (wacom_wac
->shared
->pen
== wacom
->hdev
)
678 wacom_wac
->shared
->pen
= NULL
;
680 kref_put(&data
->kref
, wacom_release_shared_data
);
681 wacom_wac
->shared
= NULL
;
685 static int wacom_add_shared_data(struct hid_device
*hdev
)
687 struct wacom
*wacom
= hid_get_drvdata(hdev
);
688 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
689 struct wacom_hdev_data
*data
;
692 mutex_lock(&wacom_udev_list_lock
);
694 data
= wacom_get_hdev_data(hdev
);
696 data
= kzalloc(sizeof(struct wacom_hdev_data
), GFP_KERNEL
);
702 kref_init(&data
->kref
);
704 list_add_tail(&data
->list
, &wacom_udev_list
);
707 wacom_wac
->shared
= &data
->shared
;
709 retval
= devm_add_action(&hdev
->dev
, wacom_remove_shared_data
, wacom
);
711 mutex_unlock(&wacom_udev_list_lock
);
712 wacom_remove_shared_data(wacom
);
716 if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
)
717 wacom_wac
->shared
->touch
= hdev
;
718 else if (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_PEN
)
719 wacom_wac
->shared
->pen
= hdev
;
722 mutex_unlock(&wacom_udev_list_lock
);
726 static int wacom_led_control(struct wacom
*wacom
)
730 unsigned char report_id
= WAC_CMD_LED_CONTROL
;
733 if (!hid_get_drvdata(wacom
->hdev
))
736 if (!wacom
->led
.groups
)
739 if (wacom
->wacom_wac
.pid
) { /* wireless connected */
740 report_id
= WAC_CMD_WL_LED_CONTROL
;
743 buf
= kzalloc(buf_size
, GFP_KERNEL
);
747 if (wacom
->wacom_wac
.features
.type
>= INTUOS5S
&&
748 wacom
->wacom_wac
.features
.type
<= INTUOSPL
) {
750 * Touch Ring and crop mark LED luminance may take on
751 * one of four values:
752 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
754 int ring_led
= wacom
->led
.groups
[0].select
& 0x03;
755 int ring_lum
= (((wacom
->led
.llv
& 0x60) >> 5) - 1) & 0x03;
757 unsigned char led_bits
= (crop_lum
<< 4) | (ring_lum
<< 2) | (ring_led
);
760 if (wacom
->wacom_wac
.pid
) {
761 wacom_get_report(wacom
->hdev
, HID_FEATURE_REPORT
,
762 buf
, buf_size
, WAC_CMD_RETRIES
);
769 int led
= wacom
->led
.groups
[0].select
| 0x4;
771 if (wacom
->wacom_wac
.features
.type
== WACOM_21UX2
||
772 wacom
->wacom_wac
.features
.type
== WACOM_24HD
)
773 led
|= (wacom
->led
.groups
[1].select
<< 4) | 0x40;
777 buf
[2] = wacom
->led
.llv
;
778 buf
[3] = wacom
->led
.hlv
;
779 buf
[4] = wacom
->led
.img_lum
;
782 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, buf_size
,
789 static int wacom_led_putimage(struct wacom
*wacom
, int button_id
, u8 xfer_id
,
790 const unsigned len
, const void *img
)
794 const unsigned chunk_len
= len
/ 4; /* 4 chunks are needed to be sent */
796 buf
= kzalloc(chunk_len
+ 3 , GFP_KERNEL
);
800 /* Send 'start' command */
801 buf
[0] = WAC_CMD_ICON_START
;
803 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
809 buf
[1] = button_id
& 0x07;
810 for (i
= 0; i
< 4; i
++) {
812 memcpy(buf
+ 3, img
+ i
* chunk_len
, chunk_len
);
814 retval
= wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
,
815 buf
, chunk_len
+ 3, WAC_CMD_RETRIES
);
821 buf
[0] = WAC_CMD_ICON_START
;
823 wacom_set_report(wacom
->hdev
, HID_FEATURE_REPORT
, buf
, 2,
831 static ssize_t
wacom_led_select_store(struct device
*dev
, int set_id
,
832 const char *buf
, size_t count
)
834 struct hid_device
*hdev
= to_hid_device(dev
);
835 struct wacom
*wacom
= hid_get_drvdata(hdev
);
839 err
= kstrtouint(buf
, 10, &id
);
843 mutex_lock(&wacom
->lock
);
845 wacom
->led
.groups
[set_id
].select
= id
& 0x3;
846 err
= wacom_led_control(wacom
);
848 mutex_unlock(&wacom
->lock
);
850 return err
< 0 ? err
: count
;
853 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
854 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
855 struct device_attribute *attr, const char *buf, size_t count) \
857 return wacom_led_select_store(dev, SET_ID, buf, count); \
859 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
860 struct device_attribute *attr, char *buf) \
862 struct hid_device *hdev = to_hid_device(dev);\
863 struct wacom *wacom = hid_get_drvdata(hdev); \
864 return scnprintf(buf, PAGE_SIZE, "%d\n", \
865 wacom->led.groups[SET_ID].select); \
867 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
868 wacom_led##SET_ID##_select_show, \
869 wacom_led##SET_ID##_select_store)
871 DEVICE_LED_SELECT_ATTR(0);
872 DEVICE_LED_SELECT_ATTR(1);
874 static ssize_t
wacom_luminance_store(struct wacom
*wacom
, u8
*dest
,
875 const char *buf
, size_t count
)
880 err
= kstrtouint(buf
, 10, &value
);
884 mutex_lock(&wacom
->lock
);
886 *dest
= value
& 0x7f;
887 err
= wacom_led_control(wacom
);
889 mutex_unlock(&wacom
->lock
);
891 return err
< 0 ? err
: count
;
894 #define DEVICE_LUMINANCE_ATTR(name, field) \
895 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
896 struct device_attribute *attr, const char *buf, size_t count) \
898 struct hid_device *hdev = to_hid_device(dev);\
899 struct wacom *wacom = hid_get_drvdata(hdev); \
901 return wacom_luminance_store(wacom, &wacom->led.field, \
904 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
905 struct device_attribute *attr, char *buf) \
907 struct wacom *wacom = dev_get_drvdata(dev); \
908 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
910 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
911 wacom_##name##_luminance_show, \
912 wacom_##name##_luminance_store)
914 DEVICE_LUMINANCE_ATTR(status0
, llv
);
915 DEVICE_LUMINANCE_ATTR(status1
, hlv
);
916 DEVICE_LUMINANCE_ATTR(buttons
, img_lum
);
918 static ssize_t
wacom_button_image_store(struct device
*dev
, int button_id
,
919 const char *buf
, size_t count
)
921 struct hid_device
*hdev
= to_hid_device(dev
);
922 struct wacom
*wacom
= hid_get_drvdata(hdev
);
927 if (hdev
->bus
== BUS_BLUETOOTH
) {
929 xfer_id
= WAC_CMD_ICON_BT_XFER
;
932 xfer_id
= WAC_CMD_ICON_XFER
;
938 mutex_lock(&wacom
->lock
);
940 err
= wacom_led_putimage(wacom
, button_id
, xfer_id
, len
, buf
);
942 mutex_unlock(&wacom
->lock
);
944 return err
< 0 ? err
: count
;
947 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
948 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
949 struct device_attribute *attr, const char *buf, size_t count) \
951 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
953 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
954 NULL, wacom_btnimg##BUTTON_ID##_store)
956 DEVICE_BTNIMG_ATTR(0);
957 DEVICE_BTNIMG_ATTR(1);
958 DEVICE_BTNIMG_ATTR(2);
959 DEVICE_BTNIMG_ATTR(3);
960 DEVICE_BTNIMG_ATTR(4);
961 DEVICE_BTNIMG_ATTR(5);
962 DEVICE_BTNIMG_ATTR(6);
963 DEVICE_BTNIMG_ATTR(7);
965 static struct attribute
*cintiq_led_attrs
[] = {
966 &dev_attr_status_led0_select
.attr
,
967 &dev_attr_status_led1_select
.attr
,
971 static struct attribute_group cintiq_led_attr_group
= {
973 .attrs
= cintiq_led_attrs
,
976 static struct attribute
*intuos4_led_attrs
[] = {
977 &dev_attr_status0_luminance
.attr
,
978 &dev_attr_status1_luminance
.attr
,
979 &dev_attr_status_led0_select
.attr
,
980 &dev_attr_buttons_luminance
.attr
,
981 &dev_attr_button0_rawimg
.attr
,
982 &dev_attr_button1_rawimg
.attr
,
983 &dev_attr_button2_rawimg
.attr
,
984 &dev_attr_button3_rawimg
.attr
,
985 &dev_attr_button4_rawimg
.attr
,
986 &dev_attr_button5_rawimg
.attr
,
987 &dev_attr_button6_rawimg
.attr
,
988 &dev_attr_button7_rawimg
.attr
,
992 static struct attribute_group intuos4_led_attr_group
= {
994 .attrs
= intuos4_led_attrs
,
997 static struct attribute
*intuos5_led_attrs
[] = {
998 &dev_attr_status0_luminance
.attr
,
999 &dev_attr_status_led0_select
.attr
,
1003 static struct attribute_group intuos5_led_attr_group
= {
1004 .name
= "wacom_led",
1005 .attrs
= intuos5_led_attrs
,
1008 struct wacom_sysfs_group_devres
{
1009 struct attribute_group
*group
;
1010 struct kobject
*root
;
1013 static void wacom_devm_sysfs_group_release(struct device
*dev
, void *res
)
1015 struct wacom_sysfs_group_devres
*devres
= res
;
1016 struct kobject
*kobj
= devres
->root
;
1018 dev_dbg(dev
, "%s: dropping reference to %s\n",
1019 __func__
, devres
->group
->name
);
1020 sysfs_remove_group(kobj
, devres
->group
);
1023 static int __wacom_devm_sysfs_create_group(struct wacom
*wacom
,
1024 struct kobject
*root
,
1025 struct attribute_group
*group
)
1027 struct wacom_sysfs_group_devres
*devres
;
1030 devres
= devres_alloc(wacom_devm_sysfs_group_release
,
1031 sizeof(struct wacom_sysfs_group_devres
),
1036 devres
->group
= group
;
1037 devres
->root
= root
;
1039 error
= sysfs_create_group(devres
->root
, group
);
1043 devres_add(&wacom
->hdev
->dev
, devres
);
1048 static int wacom_devm_sysfs_create_group(struct wacom
*wacom
,
1049 struct attribute_group
*group
)
1051 return __wacom_devm_sysfs_create_group(wacom
, &wacom
->hdev
->dev
.kobj
,
1055 enum led_brightness
wacom_leds_brightness_get(struct wacom_led
*led
)
1057 struct wacom
*wacom
= led
->wacom
;
1059 if (wacom
->led
.max_hlv
)
1060 return led
->hlv
* LED_FULL
/ wacom
->led
.max_hlv
;
1062 if (wacom
->led
.max_llv
)
1063 return led
->llv
* LED_FULL
/ wacom
->led
.max_llv
;
1065 /* device doesn't support brightness tuning */
1069 static enum led_brightness
__wacom_led_brightness_get(struct led_classdev
*cdev
)
1071 struct wacom_led
*led
= container_of(cdev
, struct wacom_led
, cdev
);
1072 struct wacom
*wacom
= led
->wacom
;
1074 if (wacom
->led
.groups
[led
->group
].select
!= led
->id
)
1077 return wacom_leds_brightness_get(led
);
1080 static int wacom_led_brightness_set(struct led_classdev
*cdev
,
1081 enum led_brightness brightness
)
1083 struct wacom_led
*led
= container_of(cdev
, struct wacom_led
, cdev
);
1084 struct wacom
*wacom
= led
->wacom
;
1087 mutex_lock(&wacom
->lock
);
1089 if (!wacom
->led
.groups
|| (brightness
== LED_OFF
&&
1090 wacom
->led
.groups
[led
->group
].select
!= led
->id
)) {
1095 led
->llv
= wacom
->led
.llv
= wacom
->led
.max_llv
* brightness
/ LED_FULL
;
1096 led
->hlv
= wacom
->led
.hlv
= wacom
->led
.max_hlv
* brightness
/ LED_FULL
;
1098 wacom
->led
.groups
[led
->group
].select
= led
->id
;
1100 error
= wacom_led_control(wacom
);
1103 mutex_unlock(&wacom
->lock
);
1108 static void wacom_led_readonly_brightness_set(struct led_classdev
*cdev
,
1109 enum led_brightness brightness
)
1113 static int wacom_led_register_one(struct device
*dev
, struct wacom
*wacom
,
1114 struct wacom_led
*led
, unsigned int group
,
1115 unsigned int id
, bool read_only
)
1120 name
= devm_kasprintf(dev
, GFP_KERNEL
,
1129 led
->trigger
.name
= name
;
1130 error
= devm_led_trigger_register(dev
, &led
->trigger
);
1132 hid_err(wacom
->hdev
,
1133 "failed to register LED trigger %s: %d\n",
1134 led
->cdev
.name
, error
);
1142 led
->llv
= wacom
->led
.llv
;
1143 led
->hlv
= wacom
->led
.hlv
;
1144 led
->cdev
.name
= name
;
1145 led
->cdev
.max_brightness
= LED_FULL
;
1146 led
->cdev
.flags
= LED_HW_PLUGGABLE
;
1147 led
->cdev
.brightness_get
= __wacom_led_brightness_get
;
1149 led
->cdev
.brightness_set_blocking
= wacom_led_brightness_set
;
1150 led
->cdev
.default_trigger
= led
->cdev
.name
;
1152 led
->cdev
.brightness_set
= wacom_led_readonly_brightness_set
;
1155 error
= devm_led_classdev_register(dev
, &led
->cdev
);
1157 hid_err(wacom
->hdev
,
1158 "failed to register LED %s: %d\n",
1159 led
->cdev
.name
, error
);
1160 led
->cdev
.name
= NULL
;
1167 static void wacom_led_groups_release_one(void *data
)
1169 struct wacom_group_leds
*group
= data
;
1171 devres_release_group(group
->dev
, group
);
1174 static int wacom_led_groups_alloc_and_register_one(struct device
*dev
,
1175 struct wacom
*wacom
,
1176 int group_id
, int count
,
1179 struct wacom_led
*leds
;
1182 if (group_id
>= wacom
->led
.count
|| count
<= 0)
1185 if (!devres_open_group(dev
, &wacom
->led
.groups
[group_id
], GFP_KERNEL
))
1188 leds
= devm_kzalloc(dev
, sizeof(struct wacom_led
) * count
, GFP_KERNEL
);
1194 wacom
->led
.groups
[group_id
].leds
= leds
;
1195 wacom
->led
.groups
[group_id
].count
= count
;
1197 for (i
= 0; i
< count
; i
++) {
1198 error
= wacom_led_register_one(dev
, wacom
, &leds
[i
],
1199 group_id
, i
, read_only
);
1204 wacom
->led
.groups
[group_id
].dev
= dev
;
1206 devres_close_group(dev
, &wacom
->led
.groups
[group_id
]);
1209 * There is a bug (?) in devm_led_classdev_register() in which its
1210 * increments the refcount of the parent. If the parent is an input
1211 * device, that means the ref count never reaches 0 when
1212 * devm_input_device_release() gets called.
1213 * This means that the LEDs are still there after disconnect.
1214 * Manually force the release of the group so that the leds are released
1215 * once we are done using them.
1217 error
= devm_add_action_or_reset(&wacom
->hdev
->dev
,
1218 wacom_led_groups_release_one
,
1219 &wacom
->led
.groups
[group_id
]);
1226 devres_release_group(dev
, &wacom
->led
.groups
[group_id
]);
1230 struct wacom_led
*wacom_led_find(struct wacom
*wacom
, unsigned int group_id
,
1233 struct wacom_group_leds
*group
;
1235 if (group_id
>= wacom
->led
.count
)
1238 group
= &wacom
->led
.groups
[group_id
];
1245 return &group
->leds
[id
];
1249 * wacom_led_next: gives the next available led with a wacom trigger.
1251 * returns the next available struct wacom_led which has its default trigger
1252 * or the current one if none is available.
1254 struct wacom_led
*wacom_led_next(struct wacom
*wacom
, struct wacom_led
*cur
)
1256 struct wacom_led
*next_led
;
1266 next_led
= wacom_led_find(wacom
, group
, ++next
);
1267 if (!next_led
|| next_led
== cur
)
1269 } while (next_led
->cdev
.trigger
!= &next_led
->trigger
);
1274 static void wacom_led_groups_release(void *data
)
1276 struct wacom
*wacom
= data
;
1278 wacom
->led
.groups
= NULL
;
1279 wacom
->led
.count
= 0;
1282 static int wacom_led_groups_allocate(struct wacom
*wacom
, int count
)
1284 struct device
*dev
= &wacom
->hdev
->dev
;
1285 struct wacom_group_leds
*groups
;
1288 groups
= devm_kzalloc(dev
, sizeof(struct wacom_group_leds
) * count
,
1293 error
= devm_add_action_or_reset(dev
, wacom_led_groups_release
, wacom
);
1297 wacom
->led
.groups
= groups
;
1298 wacom
->led
.count
= count
;
1303 static int wacom_leds_alloc_and_register(struct wacom
*wacom
, int group_count
,
1304 int led_per_group
, bool read_only
)
1309 if (!wacom
->wacom_wac
.pad_input
)
1312 dev
= &wacom
->wacom_wac
.pad_input
->dev
;
1314 error
= wacom_led_groups_allocate(wacom
, group_count
);
1318 for (i
= 0; i
< group_count
; i
++) {
1319 error
= wacom_led_groups_alloc_and_register_one(dev
, wacom
, i
,
1329 static int wacom_initialize_leds(struct wacom
*wacom
)
1333 if (!(wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
))
1336 /* Initialize default values */
1337 switch (wacom
->wacom_wac
.features
.type
) {
1342 wacom
->led
.llv
= 10;
1343 wacom
->led
.hlv
= 20;
1344 wacom
->led
.max_llv
= 127;
1345 wacom
->led
.max_hlv
= 127;
1346 wacom
->led
.img_lum
= 10;
1348 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1350 hid_err(wacom
->hdev
,
1351 "cannot create leds err: %d\n", error
);
1355 error
= wacom_devm_sysfs_create_group(wacom
,
1356 &intuos4_led_attr_group
);
1363 wacom
->led
.img_lum
= 0;
1365 error
= wacom_leds_alloc_and_register(wacom
, 2, 4, false);
1367 hid_err(wacom
->hdev
,
1368 "cannot create leds err: %d\n", error
);
1372 error
= wacom_devm_sysfs_create_group(wacom
,
1373 &cintiq_led_attr_group
);
1382 wacom
->led
.llv
= 32;
1383 wacom
->led
.max_llv
= 96;
1385 error
= wacom_leds_alloc_and_register(wacom
, 1, 4, false);
1387 hid_err(wacom
->hdev
,
1388 "cannot create leds err: %d\n", error
);
1392 error
= wacom_devm_sysfs_create_group(wacom
,
1393 &intuos5_led_attr_group
);
1397 wacom
->led
.llv
= 255;
1398 wacom
->led
.max_llv
= 255;
1399 error
= wacom_led_groups_allocate(wacom
, 5);
1401 hid_err(wacom
->hdev
,
1402 "cannot create leds err: %d\n", error
);
1412 hid_err(wacom
->hdev
,
1413 "cannot create sysfs group err: %d\n", error
);
1416 wacom_led_control(wacom
);
1421 static enum power_supply_property wacom_battery_props
[] = {
1422 POWER_SUPPLY_PROP_MODEL_NAME
,
1423 POWER_SUPPLY_PROP_PRESENT
,
1424 POWER_SUPPLY_PROP_STATUS
,
1425 POWER_SUPPLY_PROP_SCOPE
,
1426 POWER_SUPPLY_PROP_CAPACITY
1429 static int wacom_battery_get_property(struct power_supply
*psy
,
1430 enum power_supply_property psp
,
1431 union power_supply_propval
*val
)
1433 struct wacom_battery
*battery
= power_supply_get_drvdata(psy
);
1437 case POWER_SUPPLY_PROP_MODEL_NAME
:
1438 val
->strval
= battery
->wacom
->wacom_wac
.name
;
1440 case POWER_SUPPLY_PROP_PRESENT
:
1441 val
->intval
= battery
->bat_connected
;
1443 case POWER_SUPPLY_PROP_SCOPE
:
1444 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
1446 case POWER_SUPPLY_PROP_CAPACITY
:
1447 val
->intval
= battery
->battery_capacity
;
1449 case POWER_SUPPLY_PROP_STATUS
:
1450 if (battery
->bat_charging
)
1451 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
1452 else if (battery
->battery_capacity
== 100 &&
1453 battery
->ps_connected
)
1454 val
->intval
= POWER_SUPPLY_STATUS_FULL
;
1455 else if (battery
->ps_connected
)
1456 val
->intval
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1458 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
1468 static int __wacom_initialize_battery(struct wacom
*wacom
,
1469 struct wacom_battery
*battery
)
1471 static atomic_t battery_no
= ATOMIC_INIT(0);
1472 struct device
*dev
= &wacom
->hdev
->dev
;
1473 struct power_supply_config psy_cfg
= { .drv_data
= battery
, };
1474 struct power_supply
*ps_bat
;
1475 struct power_supply_desc
*bat_desc
= &battery
->bat_desc
;
1479 if (!devres_open_group(dev
, bat_desc
, GFP_KERNEL
))
1482 battery
->wacom
= wacom
;
1484 n
= atomic_inc_return(&battery_no
) - 1;
1486 bat_desc
->properties
= wacom_battery_props
;
1487 bat_desc
->num_properties
= ARRAY_SIZE(wacom_battery_props
);
1488 bat_desc
->get_property
= wacom_battery_get_property
;
1489 sprintf(battery
->bat_name
, "wacom_battery_%ld", n
);
1490 bat_desc
->name
= battery
->bat_name
;
1491 bat_desc
->type
= POWER_SUPPLY_TYPE_USB
;
1492 bat_desc
->use_for_apm
= 0;
1494 ps_bat
= devm_power_supply_register(dev
, bat_desc
, &psy_cfg
);
1495 if (IS_ERR(ps_bat
)) {
1496 error
= PTR_ERR(ps_bat
);
1500 power_supply_powers(ps_bat
, &wacom
->hdev
->dev
);
1502 battery
->battery
= ps_bat
;
1504 devres_close_group(dev
, bat_desc
);
1508 devres_release_group(dev
, bat_desc
);
1512 static int wacom_initialize_battery(struct wacom
*wacom
)
1514 if (wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
)
1515 return __wacom_initialize_battery(wacom
, &wacom
->battery
);
1520 static void wacom_destroy_battery(struct wacom
*wacom
)
1522 if (wacom
->battery
.battery
) {
1523 devres_release_group(&wacom
->hdev
->dev
,
1524 &wacom
->battery
.bat_desc
);
1525 wacom
->battery
.battery
= NULL
;
1529 static ssize_t
wacom_show_speed(struct device
*dev
,
1530 struct device_attribute
1533 struct hid_device
*hdev
= to_hid_device(dev
);
1534 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1536 return snprintf(buf
, PAGE_SIZE
, "%i\n", wacom
->wacom_wac
.bt_high_speed
);
1539 static ssize_t
wacom_store_speed(struct device
*dev
,
1540 struct device_attribute
*attr
,
1541 const char *buf
, size_t count
)
1543 struct hid_device
*hdev
= to_hid_device(dev
);
1544 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1547 if (kstrtou8(buf
, 0, &new_speed
))
1550 if (new_speed
!= 0 && new_speed
!= 1)
1553 wacom_bt_query_tablet_data(hdev
, new_speed
, &wacom
->wacom_wac
.features
);
1558 static DEVICE_ATTR(speed
, DEV_ATTR_RW_PERM
,
1559 wacom_show_speed
, wacom_store_speed
);
1562 static ssize_t
wacom_show_remote_mode(struct kobject
*kobj
,
1563 struct kobj_attribute
*kattr
,
1564 char *buf
, int index
)
1566 struct device
*dev
= kobj_to_dev(kobj
->parent
);
1567 struct hid_device
*hdev
= to_hid_device(dev
);
1568 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1571 mode
= wacom
->led
.groups
[index
].select
;
1572 if (mode
>= 0 && mode
< 3)
1573 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
1575 return snprintf(buf
, PAGE_SIZE
, "%d\n", -1);
1578 #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1579 static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1580 struct kobj_attribute *kattr, char *buf) \
1582 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1584 static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1585 .attr = {.name = "remote_mode", \
1586 .mode = DEV_ATTR_RO_PERM}, \
1587 .show = wacom_show_remote##SET_ID##_mode, \
1589 static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1590 &remote##SET_ID##_mode_attr.attr, \
1593 static struct attribute_group remote##SET_ID##_serial_group = { \
1595 .attrs = remote##SET_ID##_serial_attrs, \
1598 DEVICE_EKR_ATTR_GROUP(0);
1599 DEVICE_EKR_ATTR_GROUP(1);
1600 DEVICE_EKR_ATTR_GROUP(2);
1601 DEVICE_EKR_ATTR_GROUP(3);
1602 DEVICE_EKR_ATTR_GROUP(4);
1604 static int wacom_remote_create_attr_group(struct wacom
*wacom
, __u32 serial
,
1608 struct wacom_remote
*remote
= wacom
->remote
;
1610 remote
->remotes
[index
].group
.name
= devm_kasprintf(&wacom
->hdev
->dev
,
1613 if (!remote
->remotes
[index
].group
.name
)
1616 error
= __wacom_devm_sysfs_create_group(wacom
, remote
->remote_dir
,
1617 &remote
->remotes
[index
].group
);
1619 remote
->remotes
[index
].group
.name
= NULL
;
1620 hid_err(wacom
->hdev
,
1621 "cannot create sysfs group err: %d\n", error
);
1628 static int wacom_cmd_unpair_remote(struct wacom
*wacom
, unsigned char selector
)
1630 const size_t buf_size
= 2;
1634 buf
= kzalloc(buf_size
, GFP_KERNEL
);
1638 buf
[0] = WAC_CMD_DELETE_PAIRING
;
1641 retval
= wacom_set_report(wacom
->hdev
, HID_OUTPUT_REPORT
, buf
,
1642 buf_size
, WAC_CMD_RETRIES
);
1648 static ssize_t
wacom_store_unpair_remote(struct kobject
*kobj
,
1649 struct kobj_attribute
*attr
,
1650 const char *buf
, size_t count
)
1652 unsigned char selector
= 0;
1653 struct device
*dev
= kobj_to_dev(kobj
->parent
);
1654 struct hid_device
*hdev
= to_hid_device(dev
);
1655 struct wacom
*wacom
= hid_get_drvdata(hdev
);
1658 if (!strncmp(buf
, "*\n", 2)) {
1659 selector
= WAC_CMD_UNPAIR_ALL
;
1661 hid_info(wacom
->hdev
, "remote: unrecognized unpair code: %s\n",
1666 mutex_lock(&wacom
->lock
);
1668 err
= wacom_cmd_unpair_remote(wacom
, selector
);
1669 mutex_unlock(&wacom
->lock
);
1671 return err
< 0 ? err
: count
;
1674 static struct kobj_attribute unpair_remote_attr
= {
1675 .attr
= {.name
= "unpair_remote", .mode
= 0200},
1676 .store
= wacom_store_unpair_remote
,
1679 static const struct attribute
*remote_unpair_attrs
[] = {
1680 &unpair_remote_attr
.attr
,
1684 static void wacom_remotes_destroy(void *data
)
1686 struct wacom
*wacom
= data
;
1687 struct wacom_remote
*remote
= wacom
->remote
;
1692 kobject_put(remote
->remote_dir
);
1693 kfifo_free(&remote
->remote_fifo
);
1694 wacom
->remote
= NULL
;
1697 static int wacom_initialize_remotes(struct wacom
*wacom
)
1700 struct wacom_remote
*remote
;
1703 if (wacom
->wacom_wac
.features
.type
!= REMOTE
)
1706 remote
= devm_kzalloc(&wacom
->hdev
->dev
, sizeof(*wacom
->remote
),
1711 wacom
->remote
= remote
;
1713 spin_lock_init(&remote
->remote_lock
);
1715 error
= kfifo_alloc(&remote
->remote_fifo
,
1716 5 * sizeof(struct wacom_remote_data
),
1719 hid_err(wacom
->hdev
, "failed allocating remote_fifo\n");
1723 remote
->remotes
[0].group
= remote0_serial_group
;
1724 remote
->remotes
[1].group
= remote1_serial_group
;
1725 remote
->remotes
[2].group
= remote2_serial_group
;
1726 remote
->remotes
[3].group
= remote3_serial_group
;
1727 remote
->remotes
[4].group
= remote4_serial_group
;
1729 remote
->remote_dir
= kobject_create_and_add("wacom_remote",
1730 &wacom
->hdev
->dev
.kobj
);
1731 if (!remote
->remote_dir
)
1734 error
= sysfs_create_files(remote
->remote_dir
, remote_unpair_attrs
);
1737 hid_err(wacom
->hdev
,
1738 "cannot create sysfs group err: %d\n", error
);
1742 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
1743 wacom
->led
.groups
[i
].select
= WACOM_STATUS_UNKNOWN
;
1744 remote
->remotes
[i
].serial
= 0;
1747 error
= devm_add_action_or_reset(&wacom
->hdev
->dev
,
1748 wacom_remotes_destroy
, wacom
);
1755 static struct input_dev
*wacom_allocate_input(struct wacom
*wacom
)
1757 struct input_dev
*input_dev
;
1758 struct hid_device
*hdev
= wacom
->hdev
;
1759 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1761 input_dev
= devm_input_allocate_device(&hdev
->dev
);
1765 input_dev
->name
= wacom_wac
->features
.name
;
1766 input_dev
->phys
= hdev
->phys
;
1767 input_dev
->dev
.parent
= &hdev
->dev
;
1768 input_dev
->open
= wacom_open
;
1769 input_dev
->close
= wacom_close
;
1770 input_dev
->uniq
= hdev
->uniq
;
1771 input_dev
->id
.bustype
= hdev
->bus
;
1772 input_dev
->id
.vendor
= hdev
->vendor
;
1773 input_dev
->id
.product
= wacom_wac
->pid
? wacom_wac
->pid
: hdev
->product
;
1774 input_dev
->id
.version
= hdev
->version
;
1775 input_set_drvdata(input_dev
, wacom
);
1780 static int wacom_allocate_inputs(struct wacom
*wacom
)
1782 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1784 wacom_wac
->pen_input
= wacom_allocate_input(wacom
);
1785 wacom_wac
->touch_input
= wacom_allocate_input(wacom
);
1786 wacom_wac
->pad_input
= wacom_allocate_input(wacom
);
1787 if (!wacom_wac
->pen_input
||
1788 !wacom_wac
->touch_input
||
1789 !wacom_wac
->pad_input
)
1792 wacom_wac
->pen_input
->name
= wacom_wac
->pen_name
;
1793 wacom_wac
->touch_input
->name
= wacom_wac
->touch_name
;
1794 wacom_wac
->pad_input
->name
= wacom_wac
->pad_name
;
1799 static int wacom_register_inputs(struct wacom
*wacom
)
1801 struct input_dev
*pen_input_dev
, *touch_input_dev
, *pad_input_dev
;
1802 struct wacom_wac
*wacom_wac
= &(wacom
->wacom_wac
);
1805 pen_input_dev
= wacom_wac
->pen_input
;
1806 touch_input_dev
= wacom_wac
->touch_input
;
1807 pad_input_dev
= wacom_wac
->pad_input
;
1809 if (!pen_input_dev
|| !touch_input_dev
|| !pad_input_dev
)
1812 error
= wacom_setup_pen_input_capabilities(pen_input_dev
, wacom_wac
);
1814 /* no pen in use on this interface */
1815 input_free_device(pen_input_dev
);
1816 wacom_wac
->pen_input
= NULL
;
1817 pen_input_dev
= NULL
;
1819 error
= input_register_device(pen_input_dev
);
1824 error
= wacom_setup_touch_input_capabilities(touch_input_dev
, wacom_wac
);
1826 /* no touch in use on this interface */
1827 input_free_device(touch_input_dev
);
1828 wacom_wac
->touch_input
= NULL
;
1829 touch_input_dev
= NULL
;
1831 error
= input_register_device(touch_input_dev
);
1836 error
= wacom_setup_pad_input_capabilities(pad_input_dev
, wacom_wac
);
1838 /* no pad in use on this interface */
1839 input_free_device(pad_input_dev
);
1840 wacom_wac
->pad_input
= NULL
;
1841 pad_input_dev
= NULL
;
1843 error
= input_register_device(pad_input_dev
);
1851 wacom_wac
->pad_input
= NULL
;
1852 wacom_wac
->touch_input
= NULL
;
1853 wacom_wac
->pen_input
= NULL
;
1858 * Not all devices report physical dimensions from HID.
1859 * Compute the default from hardcoded logical dimension
1860 * and resolution before driver overwrites them.
1862 static void wacom_set_default_phy(struct wacom_features
*features
)
1864 if (features
->x_resolution
) {
1865 features
->x_phy
= (features
->x_max
* 100) /
1866 features
->x_resolution
;
1867 features
->y_phy
= (features
->y_max
* 100) /
1868 features
->y_resolution
;
1872 static void wacom_calculate_res(struct wacom_features
*features
)
1874 /* set unit to "100th of a mm" for devices not reported by HID */
1875 if (!features
->unit
) {
1876 features
->unit
= 0x11;
1877 features
->unitExpo
= -3;
1880 features
->x_resolution
= wacom_calc_hid_res(features
->x_max
,
1883 features
->unitExpo
);
1884 features
->y_resolution
= wacom_calc_hid_res(features
->y_max
,
1887 features
->unitExpo
);
1890 void wacom_battery_work(struct work_struct
*work
)
1892 struct wacom
*wacom
= container_of(work
, struct wacom
, battery_work
);
1894 if ((wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1895 !wacom
->battery
.battery
) {
1896 wacom_initialize_battery(wacom
);
1898 else if (!(wacom
->wacom_wac
.features
.quirks
& WACOM_QUIRK_BATTERY
) &&
1899 wacom
->battery
.battery
) {
1900 wacom_destroy_battery(wacom
);
1904 static size_t wacom_compute_pktlen(struct hid_device
*hdev
)
1906 struct hid_report_enum
*report_enum
;
1907 struct hid_report
*report
;
1910 report_enum
= hdev
->report_enum
+ HID_INPUT_REPORT
;
1912 list_for_each_entry(report
, &report_enum
->report_list
, list
) {
1913 size_t report_size
= hid_report_len(report
);
1914 if (report_size
> size
)
1921 static void wacom_update_name(struct wacom
*wacom
, const char *suffix
)
1923 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1924 struct wacom_features
*features
= &wacom_wac
->features
;
1925 char name
[WACOM_NAME_MAX
];
1927 /* Generic devices name unspecified */
1928 if ((features
->type
== HID_GENERIC
) && !strcmp("Wacom HID", features
->name
)) {
1929 if (strstr(wacom
->hdev
->name
, "Wacom") ||
1930 strstr(wacom
->hdev
->name
, "wacom") ||
1931 strstr(wacom
->hdev
->name
, "WACOM")) {
1932 /* name is in HID descriptor, use it */
1933 strlcpy(name
, wacom
->hdev
->name
, sizeof(name
));
1935 /* strip out excess whitespaces */
1937 char *gap
= strstr(name
, " ");
1940 /* shift everything including the terminator */
1941 memmove(gap
, gap
+1, strlen(gap
));
1943 /* get rid of trailing whitespace */
1944 if (name
[strlen(name
)-1] == ' ')
1945 name
[strlen(name
)-1] = '\0';
1947 /* no meaningful name retrieved. use product ID */
1948 snprintf(name
, sizeof(name
),
1949 "%s %X", features
->name
, wacom
->hdev
->product
);
1952 strlcpy(name
, features
->name
, sizeof(name
));
1955 snprintf(wacom_wac
->name
, sizeof(wacom_wac
->name
), "%s%s",
1958 /* Append the device type to the name */
1959 snprintf(wacom_wac
->pen_name
, sizeof(wacom_wac
->pen_name
),
1960 "%s%s Pen", name
, suffix
);
1961 snprintf(wacom_wac
->touch_name
, sizeof(wacom_wac
->touch_name
),
1962 "%s%s Finger", name
, suffix
);
1963 snprintf(wacom_wac
->pad_name
, sizeof(wacom_wac
->pad_name
),
1964 "%s%s Pad", name
, suffix
);
1967 static void wacom_release_resources(struct wacom
*wacom
)
1969 struct hid_device
*hdev
= wacom
->hdev
;
1971 if (!wacom
->resources
)
1974 devres_release_group(&hdev
->dev
, wacom
);
1976 wacom
->resources
= false;
1978 wacom
->wacom_wac
.pen_input
= NULL
;
1979 wacom
->wacom_wac
.touch_input
= NULL
;
1980 wacom
->wacom_wac
.pad_input
= NULL
;
1983 static int wacom_parse_and_register(struct wacom
*wacom
, bool wireless
)
1985 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
1986 struct wacom_features
*features
= &wacom_wac
->features
;
1987 struct hid_device
*hdev
= wacom
->hdev
;
1989 unsigned int connect_mask
= HID_CONNECT_HIDRAW
;
1991 features
->pktlen
= wacom_compute_pktlen(hdev
);
1992 if (features
->pktlen
> WACOM_PKGLEN_MAX
)
1995 if (!devres_open_group(&hdev
->dev
, wacom
, GFP_KERNEL
))
1998 wacom
->resources
= true;
2000 error
= wacom_allocate_inputs(wacom
);
2005 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
2006 * into debug mode for the touch part.
2007 * We ignore the other interfaces.
2009 if (features
->type
== BAMBOO_PAD
) {
2010 if (features
->pktlen
== WACOM_PKGLEN_PENABLED
) {
2011 features
->type
= HID_GENERIC
;
2012 } else if ((features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH
) &&
2013 (features
->pktlen
!= WACOM_PKGLEN_BPAD_TOUCH_USB
)) {
2019 /* set the default size in case we do not get them from hid */
2020 wacom_set_default_phy(features
);
2022 /* Retrieve the physical and logical size for touch devices */
2023 wacom_retrieve_hid_descriptor(hdev
, features
);
2024 wacom_setup_device_quirks(wacom
);
2026 if (features
->device_type
== WACOM_DEVICETYPE_NONE
&&
2027 features
->type
!= WIRELESS
) {
2028 error
= features
->type
== HID_GENERIC
? -ENODEV
: 0;
2030 dev_warn(&hdev
->dev
, "Unknown device_type for '%s'. %s.",
2032 error
? "Ignoring" : "Assuming pen");
2037 features
->device_type
|= WACOM_DEVICETYPE_PEN
;
2040 wacom_calculate_res(features
);
2042 wacom_update_name(wacom
, wireless
? " (WL)" : "");
2044 error
= wacom_add_shared_data(hdev
);
2048 if (!(features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
) &&
2049 (features
->quirks
& WACOM_QUIRK_BATTERY
)) {
2050 error
= wacom_initialize_battery(wacom
);
2055 error
= wacom_register_inputs(wacom
);
2059 if (wacom
->wacom_wac
.features
.device_type
& WACOM_DEVICETYPE_PAD
) {
2060 error
= wacom_initialize_leds(wacom
);
2064 error
= wacom_initialize_remotes(wacom
);
2069 if (features
->type
== HID_GENERIC
)
2070 connect_mask
|= HID_CONNECT_DRIVER
;
2072 /* Regular HID work starts now */
2073 error
= hid_hw_start(hdev
, connect_mask
);
2075 hid_err(hdev
, "hw start failed\n");
2080 /* Note that if query fails it is not a hard failure */
2081 wacom_query_tablet_data(hdev
, features
);
2084 /* touch only Bamboo doesn't support pen */
2085 if ((features
->type
== BAMBOO_TOUCH
) &&
2086 (features
->device_type
& WACOM_DEVICETYPE_PEN
)) {
2091 /* pen only Bamboo neither support touch nor pad */
2092 if ((features
->type
== BAMBOO_PEN
) &&
2093 ((features
->device_type
& WACOM_DEVICETYPE_TOUCH
) ||
2094 (features
->device_type
& WACOM_DEVICETYPE_PAD
))) {
2099 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
2100 error
= hid_hw_open(hdev
);
2102 if ((wacom_wac
->features
.type
== INTUOSHT
||
2103 wacom_wac
->features
.type
== INTUOSHT2
) &&
2104 (wacom_wac
->features
.device_type
& WACOM_DEVICETYPE_TOUCH
)) {
2105 wacom_wac
->shared
->type
= wacom_wac
->features
.type
;
2106 wacom_wac
->shared
->touch_input
= wacom_wac
->touch_input
;
2109 devres_close_group(&hdev
->dev
, wacom
);
2116 wacom_release_resources(wacom
);
2120 static void wacom_wireless_work(struct work_struct
*work
)
2122 struct wacom
*wacom
= container_of(work
, struct wacom
, wireless_work
);
2123 struct usb_device
*usbdev
= wacom
->usbdev
;
2124 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2125 struct hid_device
*hdev1
, *hdev2
;
2126 struct wacom
*wacom1
, *wacom2
;
2127 struct wacom_wac
*wacom_wac1
, *wacom_wac2
;
2131 * Regardless if this is a disconnect or a new tablet,
2132 * remove any existing input and battery devices.
2135 wacom_destroy_battery(wacom
);
2137 /* Stylus interface */
2138 hdev1
= usb_get_intfdata(usbdev
->config
->interface
[1]);
2139 wacom1
= hid_get_drvdata(hdev1
);
2140 wacom_wac1
= &(wacom1
->wacom_wac
);
2141 wacom_release_resources(wacom1
);
2143 /* Touch interface */
2144 hdev2
= usb_get_intfdata(usbdev
->config
->interface
[2]);
2145 wacom2
= hid_get_drvdata(hdev2
);
2146 wacom_wac2
= &(wacom2
->wacom_wac
);
2147 wacom_release_resources(wacom2
);
2149 if (wacom_wac
->pid
== 0) {
2150 hid_info(wacom
->hdev
, "wireless tablet disconnected\n");
2152 const struct hid_device_id
*id
= wacom_ids
;
2154 hid_info(wacom
->hdev
, "wireless tablet connected with PID %x\n",
2158 if (id
->vendor
== USB_VENDOR_ID_WACOM
&&
2159 id
->product
== wacom_wac
->pid
)
2165 hid_info(wacom
->hdev
, "ignoring unknown PID.\n");
2169 /* Stylus interface */
2170 wacom_wac1
->features
=
2171 *((struct wacom_features
*)id
->driver_data
);
2173 wacom_wac1
->pid
= wacom_wac
->pid
;
2175 error
= wacom_parse_and_register(wacom1
, true);
2179 /* Touch interface */
2180 if (wacom_wac1
->features
.touch_max
||
2181 (wacom_wac1
->features
.type
>= INTUOSHT
&&
2182 wacom_wac1
->features
.type
<= BAMBOO_PT
)) {
2183 wacom_wac2
->features
=
2184 *((struct wacom_features
*)id
->driver_data
);
2185 wacom_wac2
->pid
= wacom_wac
->pid
;
2187 error
= wacom_parse_and_register(wacom2
, true);
2192 strlcpy(wacom_wac
->name
, wacom_wac1
->name
,
2193 sizeof(wacom_wac
->name
));
2194 error
= wacom_initialize_battery(wacom
);
2202 wacom_release_resources(wacom1
);
2203 wacom_release_resources(wacom2
);
2207 static void wacom_remote_destroy_one(struct wacom
*wacom
, unsigned int index
)
2209 struct wacom_remote
*remote
= wacom
->remote
;
2210 u32 serial
= remote
->remotes
[index
].serial
;
2212 unsigned long flags
;
2214 spin_lock_irqsave(&remote
->remote_lock
, flags
);
2215 remote
->remotes
[index
].registered
= false;
2216 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2218 if (remote
->remotes
[index
].battery
.battery
)
2219 devres_release_group(&wacom
->hdev
->dev
,
2220 &remote
->remotes
[index
].battery
.bat_desc
);
2222 if (remote
->remotes
[index
].group
.name
)
2223 devres_release_group(&wacom
->hdev
->dev
,
2224 &remote
->remotes
[index
]);
2226 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
2227 if (remote
->remotes
[i
].serial
== serial
) {
2228 remote
->remotes
[i
].serial
= 0;
2229 remote
->remotes
[i
].group
.name
= NULL
;
2230 remote
->remotes
[i
].registered
= false;
2231 remote
->remotes
[i
].battery
.battery
= NULL
;
2232 wacom
->led
.groups
[i
].select
= WACOM_STATUS_UNKNOWN
;
2237 static int wacom_remote_create_one(struct wacom
*wacom
, u32 serial
,
2240 struct wacom_remote
*remote
= wacom
->remote
;
2241 struct device
*dev
= &wacom
->hdev
->dev
;
2244 /* A remote can pair more than once with an EKR,
2245 * check to make sure this serial isn't already paired.
2247 for (k
= 0; k
< WACOM_MAX_REMOTES
; k
++) {
2248 if (remote
->remotes
[k
].serial
== serial
)
2252 if (k
< WACOM_MAX_REMOTES
) {
2253 remote
->remotes
[index
].serial
= serial
;
2257 if (!devres_open_group(dev
, &remote
->remotes
[index
], GFP_KERNEL
))
2260 error
= wacom_remote_create_attr_group(wacom
, serial
, index
);
2264 remote
->remotes
[index
].input
= wacom_allocate_input(wacom
);
2265 if (!remote
->remotes
[index
].input
) {
2269 remote
->remotes
[index
].input
->uniq
= remote
->remotes
[index
].group
.name
;
2270 remote
->remotes
[index
].input
->name
= wacom
->wacom_wac
.pad_name
;
2272 if (!remote
->remotes
[index
].input
->name
) {
2277 error
= wacom_setup_pad_input_capabilities(remote
->remotes
[index
].input
,
2282 remote
->remotes
[index
].serial
= serial
;
2284 error
= input_register_device(remote
->remotes
[index
].input
);
2288 error
= wacom_led_groups_alloc_and_register_one(
2289 &remote
->remotes
[index
].input
->dev
,
2290 wacom
, index
, 3, true);
2294 remote
->remotes
[index
].registered
= true;
2296 devres_close_group(dev
, &remote
->remotes
[index
]);
2300 devres_release_group(dev
, &remote
->remotes
[index
]);
2301 remote
->remotes
[index
].serial
= 0;
2305 static int wacom_remote_attach_battery(struct wacom
*wacom
, int index
)
2307 struct wacom_remote
*remote
= wacom
->remote
;
2310 if (!remote
->remotes
[index
].registered
)
2313 if (remote
->remotes
[index
].battery
.battery
)
2316 if (wacom
->led
.groups
[index
].select
== WACOM_STATUS_UNKNOWN
)
2319 error
= __wacom_initialize_battery(wacom
,
2320 &wacom
->remote
->remotes
[index
].battery
);
2327 static void wacom_remote_work(struct work_struct
*work
)
2329 struct wacom
*wacom
= container_of(work
, struct wacom
, remote_work
);
2330 struct wacom_remote
*remote
= wacom
->remote
;
2331 struct wacom_remote_data data
;
2332 unsigned long flags
;
2337 spin_lock_irqsave(&remote
->remote_lock
, flags
);
2339 count
= kfifo_out(&remote
->remote_fifo
, &data
, sizeof(data
));
2341 if (count
!= sizeof(data
)) {
2342 hid_err(wacom
->hdev
,
2343 "workitem triggered without status available\n");
2344 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2348 if (!kfifo_is_empty(&remote
->remote_fifo
))
2349 wacom_schedule_work(&wacom
->wacom_wac
, WACOM_WORKER_REMOTE
);
2351 spin_unlock_irqrestore(&remote
->remote_lock
, flags
);
2353 for (i
= 0; i
< WACOM_MAX_REMOTES
; i
++) {
2354 serial
= data
.remote
[i
].serial
;
2355 if (data
.remote
[i
].connected
) {
2357 if (remote
->remotes
[i
].serial
== serial
) {
2358 wacom_remote_attach_battery(wacom
, i
);
2362 if (remote
->remotes
[i
].serial
)
2363 wacom_remote_destroy_one(wacom
, i
);
2365 wacom_remote_create_one(wacom
, serial
, i
);
2367 } else if (remote
->remotes
[i
].serial
) {
2368 wacom_remote_destroy_one(wacom
, i
);
2373 static int wacom_probe(struct hid_device
*hdev
,
2374 const struct hid_device_id
*id
)
2376 struct usb_interface
*intf
= to_usb_interface(hdev
->dev
.parent
);
2377 struct usb_device
*dev
= interface_to_usbdev(intf
);
2378 struct wacom
*wacom
;
2379 struct wacom_wac
*wacom_wac
;
2380 struct wacom_features
*features
;
2383 if (!id
->driver_data
)
2386 hdev
->quirks
|= HID_QUIRK_NO_INIT_REPORTS
;
2388 /* hid-core sets this quirk for the boot interface */
2389 hdev
->quirks
&= ~HID_QUIRK_NOGET
;
2391 wacom
= devm_kzalloc(&hdev
->dev
, sizeof(struct wacom
), GFP_KERNEL
);
2395 hid_set_drvdata(hdev
, wacom
);
2398 wacom_wac
= &wacom
->wacom_wac
;
2399 wacom_wac
->features
= *((struct wacom_features
*)id
->driver_data
);
2400 features
= &wacom_wac
->features
;
2402 if (features
->check_for_hid_type
&& features
->hid_type
!= hdev
->type
) {
2407 wacom_wac
->hid_data
.inputmode
= -1;
2408 wacom_wac
->mode_report
= -1;
2410 wacom
->usbdev
= dev
;
2412 mutex_init(&wacom
->lock
);
2413 INIT_WORK(&wacom
->wireless_work
, wacom_wireless_work
);
2414 INIT_WORK(&wacom
->battery_work
, wacom_battery_work
);
2415 INIT_WORK(&wacom
->remote_work
, wacom_remote_work
);
2417 /* ask for the report descriptor to be loaded by HID */
2418 error
= hid_parse(hdev
);
2420 hid_err(hdev
, "parse failed\n");
2424 error
= wacom_parse_and_register(wacom
, false);
2428 if (hdev
->bus
== BUS_BLUETOOTH
) {
2429 error
= device_create_file(&hdev
->dev
, &dev_attr_speed
);
2432 "can't create sysfs speed attribute err: %d\n",
2439 hid_set_drvdata(hdev
, NULL
);
2443 static void wacom_remove(struct hid_device
*hdev
)
2445 struct wacom
*wacom
= hid_get_drvdata(hdev
);
2446 struct wacom_wac
*wacom_wac
= &wacom
->wacom_wac
;
2447 struct wacom_features
*features
= &wacom_wac
->features
;
2449 if (features
->device_type
& WACOM_DEVICETYPE_WL_MONITOR
)
2454 cancel_work_sync(&wacom
->wireless_work
);
2455 cancel_work_sync(&wacom
->battery_work
);
2456 cancel_work_sync(&wacom
->remote_work
);
2457 if (hdev
->bus
== BUS_BLUETOOTH
)
2458 device_remove_file(&hdev
->dev
, &dev_attr_speed
);
2460 hid_set_drvdata(hdev
, NULL
);
2464 static int wacom_resume(struct hid_device
*hdev
)
2466 struct wacom
*wacom
= hid_get_drvdata(hdev
);
2467 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
2469 mutex_lock(&wacom
->lock
);
2471 /* switch to wacom mode first */
2472 wacom_query_tablet_data(hdev
, features
);
2473 wacom_led_control(wacom
);
2475 mutex_unlock(&wacom
->lock
);
2480 static int wacom_reset_resume(struct hid_device
*hdev
)
2482 return wacom_resume(hdev
);
2484 #endif /* CONFIG_PM */
2486 static struct hid_driver wacom_driver
= {
2488 .id_table
= wacom_ids
,
2489 .probe
= wacom_probe
,
2490 .remove
= wacom_remove
,
2491 .report
= wacom_wac_report
,
2493 .resume
= wacom_resume
,
2494 .reset_resume
= wacom_reset_resume
,
2496 .raw_event
= wacom_raw_event
,
2498 module_hid_driver(wacom_driver
);
2500 MODULE_VERSION(DRIVER_VERSION
);
2501 MODULE_AUTHOR(DRIVER_AUTHOR
);
2502 MODULE_DESCRIPTION(DRIVER_DESC
);
2503 MODULE_LICENSE(DRIVER_LICENSE
);