blob: 3038c975e417c2e4c58fb13e5e9f815d87445f25 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001/*
2 * drivers/input/tablet/wacom_sys.c
3 *
4 * USB Wacom tablet support - system specific code
5 */
6
7/*
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.
12 */
13
14#include "wacom_wac.h"
15#include "wacom.h"
16#include <linux/input/mt.h>
17
18#define WAC_MSG_RETRIES 5
19#define WAC_CMD_RETRIES 10
20
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)
24
25static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf,
26 size_t size, unsigned int retries)
27{
28 int retval;
29
30 do {
31 retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
32 HID_REQ_GET_REPORT);
33 } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
34
35 if (retval < 0)
36 hid_err(hdev, "wacom_get_report: ran out of retries "
37 "(last error = %d)\n", retval);
38
39 return retval;
40}
41
42static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf,
43 size_t size, unsigned int retries)
44{
45 int retval;
46
47 do {
48 retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
49 HID_REQ_SET_REPORT);
50 } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
51
52 if (retval < 0)
53 hid_err(hdev, "wacom_set_report: ran out of retries "
54 "(last error = %d)\n", retval);
55
56 return retval;
57}
58
59static void wacom_wac_queue_insert(struct hid_device *hdev,
60 struct kfifo_rec_ptr_2 *fifo,
61 u8 *raw_data, int size)
62{
63 bool warned = false;
64
65 while (kfifo_avail(fifo) < size) {
66 if (!warned)
67 hid_warn(hdev, "%s: kfifo has filled, starting to drop events\n", __func__);
68 warned = true;
69
70 kfifo_skip(fifo);
71 }
72
73 kfifo_in(fifo, raw_data, size);
74}
75
76static void wacom_wac_queue_flush(struct hid_device *hdev,
77 struct kfifo_rec_ptr_2 *fifo)
78{
79 while (!kfifo_is_empty(fifo)) {
80 u8 buf[WACOM_PKGLEN_MAX];
81 int size;
82 int err;
83
84 size = kfifo_out(fifo, buf, sizeof(buf));
85 err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, false);
86 if (err) {
87 hid_warn(hdev, "%s: unable to flush event due to error %d\n",
88 __func__, err);
89 }
90 }
91}
92
93static int wacom_wac_pen_serial_enforce(struct hid_device *hdev,
94 struct hid_report *report, u8 *raw_data, int report_size)
95{
96 struct wacom *wacom = hid_get_drvdata(hdev);
97 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
98 struct wacom_features *features = &wacom_wac->features;
99 bool flush = false;
100 bool insert = false;
101 int i, j;
102
103 if (wacom_wac->serial[0] || !(features->quirks & WACOM_QUIRK_TOOLSERIAL))
104 return 0;
105
106 /* Queue events which have invalid tool type or serial number */
107 for (i = 0; i < report->maxfield; i++) {
108 for (j = 0; j < report->field[i]->maxusage; j++) {
109 struct hid_field *field = report->field[i];
110 struct hid_usage *usage = &field->usage[j];
111 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
112 unsigned int offset;
113 unsigned int size;
114 unsigned int value;
115
116 if (equivalent_usage != HID_DG_INRANGE &&
117 equivalent_usage != HID_DG_TOOLSERIALNUMBER &&
118 equivalent_usage != WACOM_HID_WD_SERIALHI &&
119 equivalent_usage != WACOM_HID_WD_TOOLTYPE)
120 continue;
121
122 offset = field->report_offset;
123 size = field->report_size;
124 value = hid_field_extract(hdev, raw_data+1, offset + j * size, size);
125
126 /* If we go out of range, we need to flush the queue ASAP */
127 if (equivalent_usage == HID_DG_INRANGE)
128 value = !value;
129
130 if (value) {
131 flush = true;
132 switch (equivalent_usage) {
133 case HID_DG_TOOLSERIALNUMBER:
134 wacom_wac->serial[0] = value;
135 break;
136
137 case WACOM_HID_WD_SERIALHI:
138 wacom_wac->serial[0] |= ((__u64)value) << 32;
139 break;
140
141 case WACOM_HID_WD_TOOLTYPE:
142 wacom_wac->id[0] = value;
143 break;
144 }
145 }
146 else {
147 insert = true;
148 }
149 }
150 }
151
152 if (flush)
153 wacom_wac_queue_flush(hdev, &wacom_wac->pen_fifo);
154 else if (insert)
155 wacom_wac_queue_insert(hdev, &wacom_wac->pen_fifo,
156 raw_data, report_size);
157
158 return insert && !flush;
159}
160
161static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
162 u8 *raw_data, int size)
163{
164 struct wacom *wacom = hid_get_drvdata(hdev);
165
166 if (size > WACOM_PKGLEN_MAX)
167 return 1;
168
169 if (wacom_wac_pen_serial_enforce(hdev, report, raw_data, size))
170 return -1;
171
172 memcpy(wacom->wacom_wac.data, raw_data, size);
173
174 wacom_wac_irq(&wacom->wacom_wac, size);
175
176 return 0;
177}
178
179static int wacom_open(struct input_dev *dev)
180{
181 struct wacom *wacom = input_get_drvdata(dev);
182
183 return hid_hw_open(wacom->hdev);
184}
185
186static void wacom_close(struct input_dev *dev)
187{
188 struct wacom *wacom = input_get_drvdata(dev);
189
190 /*
191 * wacom->hdev should never be null, but surprisingly, I had the case
192 * once while unplugging the Wacom Wireless Receiver.
193 */
194 if (wacom->hdev)
195 hid_hw_close(wacom->hdev);
196}
197
198/*
199 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
200 */
201static int wacom_calc_hid_res(int logical_extents, int physical_extents,
202 unsigned unit, int exponent)
203{
204 struct hid_field field = {
205 .logical_maximum = logical_extents,
206 .physical_maximum = physical_extents,
207 .unit = unit,
208 .unit_exponent = exponent,
209 };
210
211 return hidinput_calc_abs_res(&field, ABS_X);
212}
213
214static void wacom_hid_usage_quirk(struct hid_device *hdev,
215 struct hid_field *field, struct hid_usage *usage)
216{
217 struct wacom *wacom = hid_get_drvdata(hdev);
218 struct wacom_features *features = &wacom->wacom_wac.features;
219 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
220
221 /*
222 * The Dell Canvas 27 needs to be switched to its vendor-defined
223 * report to provide the best resolution.
224 */
225 if (hdev->vendor == USB_VENDOR_ID_WACOM &&
226 hdev->product == 0x4200 &&
227 field->application == HID_UP_MSVENDOR) {
228 wacom->wacom_wac.mode_report = field->report->id;
229 wacom->wacom_wac.mode_value = 2;
230 }
231
232 /*
233 * ISDv4 devices which predate HID's adoption of the
234 * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its
235 * position instead. We can accurately detect if a
236 * usage with that value should be HID_DG_BARRELSWITCH2
237 * based on the surrounding usages, which have remained
238 * constant across generations.
239 */
240 if (features->type == HID_GENERIC &&
241 usage->hid == 0x000D0000 &&
242 field->application == HID_DG_PEN &&
243 field->physical == HID_DG_STYLUS) {
244 int i = usage->usage_index;
245
246 if (i-4 >= 0 && i+1 < field->maxusage &&
247 field->usage[i-4].hid == HID_DG_TIPSWITCH &&
248 field->usage[i-3].hid == HID_DG_BARRELSWITCH &&
249 field->usage[i-2].hid == HID_DG_ERASER &&
250 field->usage[i-1].hid == HID_DG_INVERT &&
251 field->usage[i+1].hid == HID_DG_INRANGE) {
252 usage->hid = HID_DG_BARRELSWITCH2;
253 }
254 }
255
256 /* 2nd-generation Intuos Pro Large has incorrect Y maximum */
257 if (hdev->vendor == USB_VENDOR_ID_WACOM &&
258 hdev->product == 0x0358 &&
259 WACOM_PEN_FIELD(field) &&
260 equivalent_usage == HID_GD_Y) {
261 field->logical_maximum = 43200;
262 }
263}
264
265static void wacom_feature_mapping(struct hid_device *hdev,
266 struct hid_field *field, struct hid_usage *usage)
267{
268 struct wacom *wacom = hid_get_drvdata(hdev);
269 struct wacom_features *features = &wacom->wacom_wac.features;
270 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
271 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
272 u8 *data;
273 int ret;
274 u32 n;
275
276 wacom_hid_usage_quirk(hdev, field, usage);
277
278 switch (equivalent_usage) {
279 case WACOM_HID_WD_TOUCH_RING_SETTING:
280 wacom->generic_has_leds = true;
281 break;
282 case HID_DG_CONTACTMAX:
283 /* leave touch_max as is if predefined */
284 if (!features->touch_max) {
285 /* read manually */
286 n = hid_report_len(field->report);
287 data = hid_alloc_report_buf(field->report, GFP_KERNEL);
288 if (!data)
289 break;
290 data[0] = field->report->id;
291 ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
292 data, n, WAC_CMD_RETRIES);
293 if (ret == n) {
294 ret = hid_report_raw_event(hdev,
295 HID_FEATURE_REPORT, data, n, 0);
296 } else {
297 features->touch_max = 16;
298 hid_warn(hdev, "wacom_feature_mapping: "
299 "could not get HID_DG_CONTACTMAX, "
300 "defaulting to %d\n",
301 features->touch_max);
302 }
303 kfree(data);
304 }
305 break;
306 case HID_DG_INPUTMODE:
307 /* Ignore if value index is out of bounds. */
308 if (usage->usage_index >= field->report_count) {
309 dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
310 break;
311 }
312
313 hid_data->inputmode = field->report->id;
314 hid_data->inputmode_index = usage->usage_index;
315 break;
316
317 case HID_UP_DIGITIZER:
318 if (field->report->id == 0x0B &&
319 (field->application == WACOM_HID_G9_PEN ||
320 field->application == WACOM_HID_G11_PEN)) {
321 wacom->wacom_wac.mode_report = field->report->id;
322 wacom->wacom_wac.mode_value = 0;
323 }
324 break;
325
326 case WACOM_HID_WD_DATAMODE:
327 wacom->wacom_wac.mode_report = field->report->id;
328 wacom->wacom_wac.mode_value = 2;
329 break;
330
331 case WACOM_HID_UP_G9:
332 case WACOM_HID_UP_G11:
333 if (field->report->id == 0x03 &&
334 (field->application == WACOM_HID_G9_TOUCHSCREEN ||
335 field->application == WACOM_HID_G11_TOUCHSCREEN)) {
336 wacom->wacom_wac.mode_report = field->report->id;
337 wacom->wacom_wac.mode_value = 0;
338 }
339 break;
340 case WACOM_HID_WD_OFFSETLEFT:
341 case WACOM_HID_WD_OFFSETTOP:
342 case WACOM_HID_WD_OFFSETRIGHT:
343 case WACOM_HID_WD_OFFSETBOTTOM:
344 /* read manually */
345 n = hid_report_len(field->report);
346 data = hid_alloc_report_buf(field->report, GFP_KERNEL);
347 if (!data)
348 break;
349 data[0] = field->report->id;
350 ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
351 data, n, WAC_CMD_RETRIES);
352 if (ret == n) {
353 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT,
354 data, n, 0);
355 } else {
356 hid_warn(hdev, "%s: could not retrieve sensor offsets\n",
357 __func__);
358 }
359 kfree(data);
360 break;
361 }
362}
363
364/*
365 * Interface Descriptor of wacom devices can be incomplete and
366 * inconsistent so wacom_features table is used to store stylus
367 * device's packet lengths, various maximum values, and tablet
368 * resolution based on product ID's.
369 *
370 * For devices that contain 2 interfaces, wacom_features table is
371 * inaccurate for the touch interface. Since the Interface Descriptor
372 * for touch interfaces has pretty complete data, this function exists
373 * to query tablet for this missing information instead of hard coding in
374 * an additional table.
375 *
376 * A typical Interface Descriptor for a stylus will contain a
377 * boot mouse application collection that is not of interest and this
378 * function will ignore it.
379 *
380 * It also contains a digitizer application collection that also is not
381 * of interest since any information it contains would be duplicate
382 * of what is in wacom_features. Usually it defines a report of an array
383 * of bytes that could be used as max length of the stylus packet returned.
384 * If it happens to define a Digitizer-Stylus Physical Collection then
385 * the X and Y logical values contain valid data but it is ignored.
386 *
387 * A typical Interface Descriptor for a touch interface will contain a
388 * Digitizer-Finger Physical Collection which will define both logical
389 * X/Y maximum as well as the physical size of tablet. Since touch
390 * interfaces haven't supported pressure or distance, this is enough
391 * information to override invalid values in the wacom_features table.
392 *
393 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
394 * data. We deal with them after returning from this function.
395 */
396static void wacom_usage_mapping(struct hid_device *hdev,
397 struct hid_field *field, struct hid_usage *usage)
398{
399 struct wacom *wacom = hid_get_drvdata(hdev);
400 struct wacom_features *features = &wacom->wacom_wac.features;
401 bool finger = WACOM_FINGER_FIELD(field);
402 bool pen = WACOM_PEN_FIELD(field);
403 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
404
405 /*
406 * Requiring Stylus Usage will ignore boot mouse
407 * X/Y values and some cases of invalid Digitizer X/Y
408 * values commonly reported.
409 */
410 if (pen)
411 features->device_type |= WACOM_DEVICETYPE_PEN;
412 else if (finger)
413 features->device_type |= WACOM_DEVICETYPE_TOUCH;
414 else
415 return;
416
417 wacom_hid_usage_quirk(hdev, field, usage);
418
419 switch (equivalent_usage) {
420 case HID_GD_X:
421 features->x_max = field->logical_maximum;
422 if (finger) {
423 features->x_phy = field->physical_maximum;
424 if ((features->type != BAMBOO_PT) &&
425 (features->type != BAMBOO_TOUCH)) {
426 features->unit = field->unit;
427 features->unitExpo = field->unit_exponent;
428 }
429 }
430 break;
431 case HID_GD_Y:
432 features->y_max = field->logical_maximum;
433 if (finger) {
434 features->y_phy = field->physical_maximum;
435 if ((features->type != BAMBOO_PT) &&
436 (features->type != BAMBOO_TOUCH)) {
437 features->unit = field->unit;
438 features->unitExpo = field->unit_exponent;
439 }
440 }
441 break;
442 case HID_DG_TIPPRESSURE:
443 if (pen)
444 features->pressure_max = field->logical_maximum;
445 break;
446 }
447
448 if (features->type == HID_GENERIC)
449 wacom_wac_usage_mapping(hdev, field, usage);
450}
451
452static void wacom_post_parse_hid(struct hid_device *hdev,
453 struct wacom_features *features)
454{
455 struct wacom *wacom = hid_get_drvdata(hdev);
456 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
457
458 if (features->type == HID_GENERIC) {
459 /* Any last-minute generic device setup */
460 if (wacom_wac->has_mode_change) {
461 if (wacom_wac->is_direct_mode)
462 features->device_type |= WACOM_DEVICETYPE_DIRECT;
463 else
464 features->device_type &= ~WACOM_DEVICETYPE_DIRECT;
465 }
466
467 if (features->touch_max > 1) {
468 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
469 input_mt_init_slots(wacom_wac->touch_input,
470 wacom_wac->features.touch_max,
471 INPUT_MT_DIRECT);
472 else
473 input_mt_init_slots(wacom_wac->touch_input,
474 wacom_wac->features.touch_max,
475 INPUT_MT_POINTER);
476 }
477 }
478}
479
480static void wacom_parse_hid(struct hid_device *hdev,
481 struct wacom_features *features)
482{
483 struct hid_report_enum *rep_enum;
484 struct hid_report *hreport;
485 int i, j;
486
487 /* check features first */
488 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
489 list_for_each_entry(hreport, &rep_enum->report_list, list) {
490 for (i = 0; i < hreport->maxfield; i++) {
491 /* Ignore if report count is out of bounds. */
492 if (hreport->field[i]->report_count < 1)
493 continue;
494
495 for (j = 0; j < hreport->field[i]->maxusage; j++) {
496 wacom_feature_mapping(hdev, hreport->field[i],
497 hreport->field[i]->usage + j);
498 }
499 }
500 }
501
502 /* now check the input usages */
503 rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
504 list_for_each_entry(hreport, &rep_enum->report_list, list) {
505
506 if (!hreport->maxfield)
507 continue;
508
509 for (i = 0; i < hreport->maxfield; i++)
510 for (j = 0; j < hreport->field[i]->maxusage; j++)
511 wacom_usage_mapping(hdev, hreport->field[i],
512 hreport->field[i]->usage + j);
513 }
514
515 wacom_post_parse_hid(hdev, features);
516}
517
518static int wacom_hid_set_device_mode(struct hid_device *hdev)
519{
520 struct wacom *wacom = hid_get_drvdata(hdev);
521 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
522 struct hid_report *r;
523 struct hid_report_enum *re;
524
525 if (hid_data->inputmode < 0)
526 return 0;
527
528 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
529 r = re->report_id_hash[hid_data->inputmode];
530 if (r) {
531 r->field[0]->value[hid_data->inputmode_index] = 2;
532 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
533 }
534 return 0;
535}
536
537static int wacom_set_device_mode(struct hid_device *hdev,
538 struct wacom_wac *wacom_wac)
539{
540 u8 *rep_data;
541 struct hid_report *r;
542 struct hid_report_enum *re;
543 u32 length;
544 int error = -ENOMEM, limit = 0;
545
546 if (wacom_wac->mode_report < 0)
547 return 0;
548
549 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
550 r = re->report_id_hash[wacom_wac->mode_report];
551 if (!r)
552 return -EINVAL;
553
554 rep_data = hid_alloc_report_buf(r, GFP_KERNEL);
555 if (!rep_data)
556 return -ENOMEM;
557
558 length = hid_report_len(r);
559
560 do {
561 rep_data[0] = wacom_wac->mode_report;
562 rep_data[1] = wacom_wac->mode_value;
563
564 error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data,
565 length, 1);
566 if (error >= 0)
567 error = wacom_get_report(hdev, HID_FEATURE_REPORT,
568 rep_data, length, 1);
569 } while (error >= 0 &&
570 rep_data[1] != wacom_wac->mode_report &&
571 limit++ < WAC_MSG_RETRIES);
572
573 kfree(rep_data);
574
575 return error < 0 ? error : 0;
576}
577
578static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
579 struct wacom_features *features)
580{
581 struct wacom *wacom = hid_get_drvdata(hdev);
582 int ret;
583 u8 rep_data[2];
584
585 switch (features->type) {
586 case GRAPHIRE_BT:
587 rep_data[0] = 0x03;
588 rep_data[1] = 0x00;
589 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
590 3);
591
592 if (ret >= 0) {
593 rep_data[0] = speed == 0 ? 0x05 : 0x06;
594 rep_data[1] = 0x00;
595
596 ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
597 rep_data, 2, 3);
598
599 if (ret >= 0) {
600 wacom->wacom_wac.bt_high_speed = speed;
601 return 0;
602 }
603 }
604
605 /*
606 * Note that if the raw queries fail, it's not a hard failure
607 * and it is safe to continue
608 */
609 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
610 rep_data[0], ret);
611 break;
612 case INTUOS4WL:
613 if (speed == 1)
614 wacom->wacom_wac.bt_features &= ~0x20;
615 else
616 wacom->wacom_wac.bt_features |= 0x20;
617
618 rep_data[0] = 0x03;
619 rep_data[1] = wacom->wacom_wac.bt_features;
620
621 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
622 1);
623 if (ret >= 0)
624 wacom->wacom_wac.bt_high_speed = speed;
625 break;
626 }
627
628 return 0;
629}
630
631/*
632 * Switch the tablet into its most-capable mode. Wacom tablets are
633 * typically configured to power-up in a mode which sends mouse-like
634 * reports to the OS. To get absolute position, pressure data, etc.
635 * from the tablet, it is necessary to switch the tablet out of this
636 * mode and into one which sends the full range of tablet data.
637 */
638static int _wacom_query_tablet_data(struct wacom *wacom)
639{
640 struct hid_device *hdev = wacom->hdev;
641 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
642 struct wacom_features *features = &wacom_wac->features;
643
644 if (hdev->bus == BUS_BLUETOOTH)
645 return wacom_bt_query_tablet_data(hdev, 1, features);
646
647 if (features->type != HID_GENERIC) {
648 if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
649 if (features->type > TABLETPC) {
650 /* MT Tablet PC touch */
651 wacom_wac->mode_report = 3;
652 wacom_wac->mode_value = 4;
653 } else if (features->type == WACOM_24HDT) {
654 wacom_wac->mode_report = 18;
655 wacom_wac->mode_value = 2;
656 } else if (features->type == WACOM_27QHDT) {
657 wacom_wac->mode_report = 131;
658 wacom_wac->mode_value = 2;
659 } else if (features->type == BAMBOO_PAD) {
660 wacom_wac->mode_report = 2;
661 wacom_wac->mode_value = 2;
662 }
663 } else if (features->device_type & WACOM_DEVICETYPE_PEN) {
664 if (features->type <= BAMBOO_PT) {
665 wacom_wac->mode_report = 2;
666 wacom_wac->mode_value = 2;
667 }
668 }
669 }
670
671 wacom_set_device_mode(hdev, wacom_wac);
672
673 if (features->type == HID_GENERIC)
674 return wacom_hid_set_device_mode(hdev);
675
676 return 0;
677}
678
679static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
680 struct wacom_features *features)
681{
682 struct wacom *wacom = hid_get_drvdata(hdev);
683 struct usb_interface *intf = wacom->intf;
684
685 /* default features */
686 features->x_fuzz = 4;
687 features->y_fuzz = 4;
688 features->pressure_fuzz = 0;
689 features->distance_fuzz = 1;
690 features->tilt_fuzz = 1;
691
692 /*
693 * The wireless device HID is basic and layout conflicts with
694 * other tablets (monitor and touch interface can look like pen).
695 * Skip the query for this type and modify defaults based on
696 * interface number.
697 */
698 if (features->type == WIRELESS) {
699 if (intf->cur_altsetting->desc.bInterfaceNumber == 0)
700 features->device_type = WACOM_DEVICETYPE_WL_MONITOR;
701 else
702 features->device_type = WACOM_DEVICETYPE_NONE;
703 return;
704 }
705
706 wacom_parse_hid(hdev, features);
707}
708
709struct wacom_hdev_data {
710 struct list_head list;
711 struct kref kref;
712 struct hid_device *dev;
713 struct wacom_shared shared;
714};
715
716static LIST_HEAD(wacom_udev_list);
717static DEFINE_MUTEX(wacom_udev_list_lock);
718
719static bool wacom_are_sibling(struct hid_device *hdev,
720 struct hid_device *sibling)
721{
722 struct wacom *wacom = hid_get_drvdata(hdev);
723 struct wacom_features *features = &wacom->wacom_wac.features;
724 struct wacom *sibling_wacom = hid_get_drvdata(sibling);
725 struct wacom_features *sibling_features = &sibling_wacom->wacom_wac.features;
726 __u32 oVid = features->oVid ? features->oVid : hdev->vendor;
727 __u32 oPid = features->oPid ? features->oPid : hdev->product;
728
729 /* The defined oVid/oPid must match that of the sibling */
730 if (features->oVid != HID_ANY_ID && sibling->vendor != oVid)
731 return false;
732 if (features->oPid != HID_ANY_ID && sibling->product != oPid)
733 return false;
734
735 /*
736 * Devices with the same VID/PID must share the same physical
737 * device path, while those with different VID/PID must share
738 * the same physical parent device path.
739 */
740 if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) {
741 if (!hid_compare_device_paths(hdev, sibling, '/'))
742 return false;
743 } else {
744 if (!hid_compare_device_paths(hdev, sibling, '.'))
745 return false;
746 }
747
748 /* Skip the remaining heuristics unless you are a HID_GENERIC device */
749 if (features->type != HID_GENERIC)
750 return true;
751
752 /*
753 * Direct-input devices may not be siblings of indirect-input
754 * devices.
755 */
756 if ((features->device_type & WACOM_DEVICETYPE_DIRECT) &&
757 !(sibling_features->device_type & WACOM_DEVICETYPE_DIRECT))
758 return false;
759
760 /*
761 * Indirect-input devices may not be siblings of direct-input
762 * devices.
763 */
764 if (!(features->device_type & WACOM_DEVICETYPE_DIRECT) &&
765 (sibling_features->device_type & WACOM_DEVICETYPE_DIRECT))
766 return false;
767
768 /* Pen devices may only be siblings of touch devices */
769 if ((features->device_type & WACOM_DEVICETYPE_PEN) &&
770 !(sibling_features->device_type & WACOM_DEVICETYPE_TOUCH))
771 return false;
772
773 /* Touch devices may only be siblings of pen devices */
774 if ((features->device_type & WACOM_DEVICETYPE_TOUCH) &&
775 !(sibling_features->device_type & WACOM_DEVICETYPE_PEN))
776 return false;
777
778 /*
779 * No reason could be found for these two devices to NOT be
780 * siblings, so there's a good chance they ARE siblings
781 */
782 return true;
783}
784
785static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
786{
787 struct wacom_hdev_data *data;
788
789 /* Try to find an already-probed interface from the same device */
790 list_for_each_entry(data, &wacom_udev_list, list) {
791 if (hid_compare_device_paths(hdev, data->dev, '/')) {
792 kref_get(&data->kref);
793 return data;
794 }
795 }
796
797 /* Fallback to finding devices that appear to be "siblings" */
798 list_for_each_entry(data, &wacom_udev_list, list) {
799 if (wacom_are_sibling(hdev, data->dev)) {
800 kref_get(&data->kref);
801 return data;
802 }
803 }
804
805 return NULL;
806}
807
808static void wacom_release_shared_data(struct kref *kref)
809{
810 struct wacom_hdev_data *data =
811 container_of(kref, struct wacom_hdev_data, kref);
812
813 mutex_lock(&wacom_udev_list_lock);
814 list_del(&data->list);
815 mutex_unlock(&wacom_udev_list_lock);
816
817 kfree(data);
818}
819
820static void wacom_remove_shared_data(void *res)
821{
822 struct wacom *wacom = res;
823 struct wacom_hdev_data *data;
824 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
825
826 if (wacom_wac->shared) {
827 data = container_of(wacom_wac->shared, struct wacom_hdev_data,
828 shared);
829
830 if (wacom_wac->shared->touch == wacom->hdev)
831 wacom_wac->shared->touch = NULL;
832 else if (wacom_wac->shared->pen == wacom->hdev)
833 wacom_wac->shared->pen = NULL;
834
835 kref_put(&data->kref, wacom_release_shared_data);
836 wacom_wac->shared = NULL;
837 }
838}
839
840static int wacom_add_shared_data(struct hid_device *hdev)
841{
842 struct wacom *wacom = hid_get_drvdata(hdev);
843 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
844 struct wacom_hdev_data *data;
845 int retval = 0;
846
847 mutex_lock(&wacom_udev_list_lock);
848
849 data = wacom_get_hdev_data(hdev);
850 if (!data) {
851 data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
852 if (!data) {
853 retval = -ENOMEM;
854 goto out;
855 }
856
857 kref_init(&data->kref);
858 data->dev = hdev;
859 list_add_tail(&data->list, &wacom_udev_list);
860 }
861
862 wacom_wac->shared = &data->shared;
863
864 retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom);
865 if (retval) {
866 mutex_unlock(&wacom_udev_list_lock);
867 wacom_remove_shared_data(wacom);
868 return retval;
869 }
870
871 if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
872 wacom_wac->shared->touch = hdev;
873 else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
874 wacom_wac->shared->pen = hdev;
875
876out:
877 mutex_unlock(&wacom_udev_list_lock);
878 return retval;
879}
880
881static int wacom_led_control(struct wacom *wacom)
882{
883 unsigned char *buf;
884 int retval;
885 unsigned char report_id = WAC_CMD_LED_CONTROL;
886 int buf_size = 9;
887
888 if (!wacom->led.groups)
889 return -ENOTSUPP;
890
891 if (wacom->wacom_wac.features.type == REMOTE)
892 return -ENOTSUPP;
893
894 if (wacom->wacom_wac.pid) { /* wireless connected */
895 report_id = WAC_CMD_WL_LED_CONTROL;
896 buf_size = 13;
897 }
898 else if (wacom->wacom_wac.features.type == INTUOSP2_BT) {
899 report_id = WAC_CMD_WL_INTUOSP2;
900 buf_size = 51;
901 }
902 buf = kzalloc(buf_size, GFP_KERNEL);
903 if (!buf)
904 return -ENOMEM;
905
906 if (wacom->wacom_wac.features.type == HID_GENERIC) {
907 buf[0] = WAC_CMD_LED_CONTROL_GENERIC;
908 buf[1] = wacom->led.llv;
909 buf[2] = wacom->led.groups[0].select & 0x03;
910
911 } else if ((wacom->wacom_wac.features.type >= INTUOS5S &&
912 wacom->wacom_wac.features.type <= INTUOSPL)) {
913 /*
914 * Touch Ring and crop mark LED luminance may take on
915 * one of four values:
916 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
917 */
918 int ring_led = wacom->led.groups[0].select & 0x03;
919 int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
920 int crop_lum = 0;
921 unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
922
923 buf[0] = report_id;
924 if (wacom->wacom_wac.pid) {
925 wacom_get_report(wacom->hdev, HID_FEATURE_REPORT,
926 buf, buf_size, WAC_CMD_RETRIES);
927 buf[0] = report_id;
928 buf[4] = led_bits;
929 } else
930 buf[1] = led_bits;
931 }
932 else if (wacom->wacom_wac.features.type == INTUOSP2_BT) {
933 buf[0] = report_id;
934 buf[4] = 100; // Power Connection LED (ORANGE)
935 buf[5] = 100; // BT Connection LED (BLUE)
936 buf[6] = 100; // Paper Mode (RED?)
937 buf[7] = 100; // Paper Mode (GREEN?)
938 buf[8] = 100; // Paper Mode (BLUE?)
939 buf[9] = wacom->led.llv;
940 buf[10] = wacom->led.groups[0].select & 0x03;
941 }
942 else {
943 int led = wacom->led.groups[0].select | 0x4;
944
945 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
946 wacom->wacom_wac.features.type == WACOM_24HD)
947 led |= (wacom->led.groups[1].select << 4) | 0x40;
948
949 buf[0] = report_id;
950 buf[1] = led;
951 buf[2] = wacom->led.llv;
952 buf[3] = wacom->led.hlv;
953 buf[4] = wacom->led.img_lum;
954 }
955
956 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size,
957 WAC_CMD_RETRIES);
958 kfree(buf);
959
960 return retval;
961}
962
963static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
964 const unsigned len, const void *img)
965{
966 unsigned char *buf;
967 int i, retval;
968 const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
969
970 buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
971 if (!buf)
972 return -ENOMEM;
973
974 /* Send 'start' command */
975 buf[0] = WAC_CMD_ICON_START;
976 buf[1] = 1;
977 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
978 WAC_CMD_RETRIES);
979 if (retval < 0)
980 goto out;
981
982 buf[0] = xfer_id;
983 buf[1] = button_id & 0x07;
984 for (i = 0; i < 4; i++) {
985 buf[2] = i;
986 memcpy(buf + 3, img + i * chunk_len, chunk_len);
987
988 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
989 buf, chunk_len + 3, WAC_CMD_RETRIES);
990 if (retval < 0)
991 break;
992 }
993
994 /* Send 'stop' */
995 buf[0] = WAC_CMD_ICON_START;
996 buf[1] = 0;
997 wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
998 WAC_CMD_RETRIES);
999
1000out:
1001 kfree(buf);
1002 return retval;
1003}
1004
1005static ssize_t wacom_led_select_store(struct device *dev, int set_id,
1006 const char *buf, size_t count)
1007{
1008 struct hid_device *hdev = to_hid_device(dev);
1009 struct wacom *wacom = hid_get_drvdata(hdev);
1010 unsigned int id;
1011 int err;
1012
1013 err = kstrtouint(buf, 10, &id);
1014 if (err)
1015 return err;
1016
1017 mutex_lock(&wacom->lock);
1018
1019 wacom->led.groups[set_id].select = id & 0x3;
1020 err = wacom_led_control(wacom);
1021
1022 mutex_unlock(&wacom->lock);
1023
1024 return err < 0 ? err : count;
1025}
1026
1027#define DEVICE_LED_SELECT_ATTR(SET_ID) \
1028static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
1029 struct device_attribute *attr, const char *buf, size_t count) \
1030{ \
1031 return wacom_led_select_store(dev, SET_ID, buf, count); \
1032} \
1033static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
1034 struct device_attribute *attr, char *buf) \
1035{ \
1036 struct hid_device *hdev = to_hid_device(dev);\
1037 struct wacom *wacom = hid_get_drvdata(hdev); \
1038 return scnprintf(buf, PAGE_SIZE, "%d\n", \
1039 wacom->led.groups[SET_ID].select); \
1040} \
1041static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
1042 wacom_led##SET_ID##_select_show, \
1043 wacom_led##SET_ID##_select_store)
1044
1045DEVICE_LED_SELECT_ATTR(0);
1046DEVICE_LED_SELECT_ATTR(1);
1047
1048static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
1049 const char *buf, size_t count)
1050{
1051 unsigned int value;
1052 int err;
1053
1054 err = kstrtouint(buf, 10, &value);
1055 if (err)
1056 return err;
1057
1058 mutex_lock(&wacom->lock);
1059
1060 *dest = value & 0x7f;
1061 err = wacom_led_control(wacom);
1062
1063 mutex_unlock(&wacom->lock);
1064
1065 return err < 0 ? err : count;
1066}
1067
1068#define DEVICE_LUMINANCE_ATTR(name, field) \
1069static ssize_t wacom_##name##_luminance_store(struct device *dev, \
1070 struct device_attribute *attr, const char *buf, size_t count) \
1071{ \
1072 struct hid_device *hdev = to_hid_device(dev);\
1073 struct wacom *wacom = hid_get_drvdata(hdev); \
1074 \
1075 return wacom_luminance_store(wacom, &wacom->led.field, \
1076 buf, count); \
1077} \
1078static ssize_t wacom_##name##_luminance_show(struct device *dev, \
1079 struct device_attribute *attr, char *buf) \
1080{ \
1081 struct wacom *wacom = dev_get_drvdata(dev); \
1082 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
1083} \
1084static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
1085 wacom_##name##_luminance_show, \
1086 wacom_##name##_luminance_store)
1087
1088DEVICE_LUMINANCE_ATTR(status0, llv);
1089DEVICE_LUMINANCE_ATTR(status1, hlv);
1090DEVICE_LUMINANCE_ATTR(buttons, img_lum);
1091
1092static ssize_t wacom_button_image_store(struct device *dev, int button_id,
1093 const char *buf, size_t count)
1094{
1095 struct hid_device *hdev = to_hid_device(dev);
1096 struct wacom *wacom = hid_get_drvdata(hdev);
1097 int err;
1098 unsigned len;
1099 u8 xfer_id;
1100
1101 if (hdev->bus == BUS_BLUETOOTH) {
1102 len = 256;
1103 xfer_id = WAC_CMD_ICON_BT_XFER;
1104 } else {
1105 len = 1024;
1106 xfer_id = WAC_CMD_ICON_XFER;
1107 }
1108
1109 if (count != len)
1110 return -EINVAL;
1111
1112 mutex_lock(&wacom->lock);
1113
1114 err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
1115
1116 mutex_unlock(&wacom->lock);
1117
1118 return err < 0 ? err : count;
1119}
1120
1121#define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
1122static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
1123 struct device_attribute *attr, const char *buf, size_t count) \
1124{ \
1125 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
1126} \
1127static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
1128 NULL, wacom_btnimg##BUTTON_ID##_store)
1129
1130DEVICE_BTNIMG_ATTR(0);
1131DEVICE_BTNIMG_ATTR(1);
1132DEVICE_BTNIMG_ATTR(2);
1133DEVICE_BTNIMG_ATTR(3);
1134DEVICE_BTNIMG_ATTR(4);
1135DEVICE_BTNIMG_ATTR(5);
1136DEVICE_BTNIMG_ATTR(6);
1137DEVICE_BTNIMG_ATTR(7);
1138
1139static struct attribute *cintiq_led_attrs[] = {
1140 &dev_attr_status_led0_select.attr,
1141 &dev_attr_status_led1_select.attr,
1142 NULL
1143};
1144
1145static struct attribute_group cintiq_led_attr_group = {
1146 .name = "wacom_led",
1147 .attrs = cintiq_led_attrs,
1148};
1149
1150static struct attribute *intuos4_led_attrs[] = {
1151 &dev_attr_status0_luminance.attr,
1152 &dev_attr_status1_luminance.attr,
1153 &dev_attr_status_led0_select.attr,
1154 &dev_attr_buttons_luminance.attr,
1155 &dev_attr_button0_rawimg.attr,
1156 &dev_attr_button1_rawimg.attr,
1157 &dev_attr_button2_rawimg.attr,
1158 &dev_attr_button3_rawimg.attr,
1159 &dev_attr_button4_rawimg.attr,
1160 &dev_attr_button5_rawimg.attr,
1161 &dev_attr_button6_rawimg.attr,
1162 &dev_attr_button7_rawimg.attr,
1163 NULL
1164};
1165
1166static struct attribute_group intuos4_led_attr_group = {
1167 .name = "wacom_led",
1168 .attrs = intuos4_led_attrs,
1169};
1170
1171static struct attribute *intuos5_led_attrs[] = {
1172 &dev_attr_status0_luminance.attr,
1173 &dev_attr_status_led0_select.attr,
1174 NULL
1175};
1176
1177static struct attribute_group intuos5_led_attr_group = {
1178 .name = "wacom_led",
1179 .attrs = intuos5_led_attrs,
1180};
1181
1182static struct attribute *generic_led_attrs[] = {
1183 &dev_attr_status0_luminance.attr,
1184 &dev_attr_status_led0_select.attr,
1185 NULL
1186};
1187
1188static struct attribute_group generic_led_attr_group = {
1189 .name = "wacom_led",
1190 .attrs = generic_led_attrs,
1191};
1192
1193struct wacom_sysfs_group_devres {
1194 struct attribute_group *group;
1195 struct kobject *root;
1196};
1197
1198static void wacom_devm_sysfs_group_release(struct device *dev, void *res)
1199{
1200 struct wacom_sysfs_group_devres *devres = res;
1201 struct kobject *kobj = devres->root;
1202
1203 dev_dbg(dev, "%s: dropping reference to %s\n",
1204 __func__, devres->group->name);
1205 sysfs_remove_group(kobj, devres->group);
1206}
1207
1208static int __wacom_devm_sysfs_create_group(struct wacom *wacom,
1209 struct kobject *root,
1210 struct attribute_group *group)
1211{
1212 struct wacom_sysfs_group_devres *devres;
1213 int error;
1214
1215 devres = devres_alloc(wacom_devm_sysfs_group_release,
1216 sizeof(struct wacom_sysfs_group_devres),
1217 GFP_KERNEL);
1218 if (!devres)
1219 return -ENOMEM;
1220
1221 devres->group = group;
1222 devres->root = root;
1223
1224 error = sysfs_create_group(devres->root, group);
1225 if (error) {
1226 devres_free(devres);
1227 return error;
1228 }
1229
1230 devres_add(&wacom->hdev->dev, devres);
1231
1232 return 0;
1233}
1234
1235static int wacom_devm_sysfs_create_group(struct wacom *wacom,
1236 struct attribute_group *group)
1237{
1238 return __wacom_devm_sysfs_create_group(wacom, &wacom->hdev->dev.kobj,
1239 group);
1240}
1241
1242enum led_brightness wacom_leds_brightness_get(struct wacom_led *led)
1243{
1244 struct wacom *wacom = led->wacom;
1245
1246 if (wacom->led.max_hlv)
1247 return led->hlv * LED_FULL / wacom->led.max_hlv;
1248
1249 if (wacom->led.max_llv)
1250 return led->llv * LED_FULL / wacom->led.max_llv;
1251
1252 /* device doesn't support brightness tuning */
1253 return LED_FULL;
1254}
1255
1256static enum led_brightness __wacom_led_brightness_get(struct led_classdev *cdev)
1257{
1258 struct wacom_led *led = container_of(cdev, struct wacom_led, cdev);
1259 struct wacom *wacom = led->wacom;
1260
1261 if (wacom->led.groups[led->group].select != led->id)
1262 return LED_OFF;
1263
1264 return wacom_leds_brightness_get(led);
1265}
1266
1267static int wacom_led_brightness_set(struct led_classdev *cdev,
1268 enum led_brightness brightness)
1269{
1270 struct wacom_led *led = container_of(cdev, struct wacom_led, cdev);
1271 struct wacom *wacom = led->wacom;
1272 int error;
1273
1274 mutex_lock(&wacom->lock);
1275
1276 if (!wacom->led.groups || (brightness == LED_OFF &&
1277 wacom->led.groups[led->group].select != led->id)) {
1278 error = 0;
1279 goto out;
1280 }
1281
1282 led->llv = wacom->led.llv = wacom->led.max_llv * brightness / LED_FULL;
1283 led->hlv = wacom->led.hlv = wacom->led.max_hlv * brightness / LED_FULL;
1284
1285 wacom->led.groups[led->group].select = led->id;
1286
1287 error = wacom_led_control(wacom);
1288
1289out:
1290 mutex_unlock(&wacom->lock);
1291
1292 return error;
1293}
1294
1295static void wacom_led_readonly_brightness_set(struct led_classdev *cdev,
1296 enum led_brightness brightness)
1297{
1298}
1299
1300static int wacom_led_register_one(struct device *dev, struct wacom *wacom,
1301 struct wacom_led *led, unsigned int group,
1302 unsigned int id, bool read_only)
1303{
1304 int error;
1305 char *name;
1306
1307 name = devm_kasprintf(dev, GFP_KERNEL,
1308 "%s::wacom-%d.%d",
1309 dev_name(dev),
1310 group,
1311 id);
1312 if (!name)
1313 return -ENOMEM;
1314
1315 if (!read_only) {
1316 led->trigger.name = name;
1317 error = devm_led_trigger_register(dev, &led->trigger);
1318 if (error) {
1319 hid_err(wacom->hdev,
1320 "failed to register LED trigger %s: %d\n",
1321 led->cdev.name, error);
1322 return error;
1323 }
1324 }
1325
1326 led->group = group;
1327 led->id = id;
1328 led->wacom = wacom;
1329 led->llv = wacom->led.llv;
1330 led->hlv = wacom->led.hlv;
1331 led->cdev.name = name;
1332 led->cdev.max_brightness = LED_FULL;
1333 led->cdev.flags = LED_HW_PLUGGABLE;
1334 led->cdev.brightness_get = __wacom_led_brightness_get;
1335 if (!read_only) {
1336 led->cdev.brightness_set_blocking = wacom_led_brightness_set;
1337 led->cdev.default_trigger = led->cdev.name;
1338 } else {
1339 led->cdev.brightness_set = wacom_led_readonly_brightness_set;
1340 }
1341
1342 error = devm_led_classdev_register(dev, &led->cdev);
1343 if (error) {
1344 hid_err(wacom->hdev,
1345 "failed to register LED %s: %d\n",
1346 led->cdev.name, error);
1347 led->cdev.name = NULL;
1348 return error;
1349 }
1350
1351 return 0;
1352}
1353
1354static void wacom_led_groups_release_one(void *data)
1355{
1356 struct wacom_group_leds *group = data;
1357
1358 devres_release_group(group->dev, group);
1359}
1360
1361static int wacom_led_groups_alloc_and_register_one(struct device *dev,
1362 struct wacom *wacom,
1363 int group_id, int count,
1364 bool read_only)
1365{
1366 struct wacom_led *leds;
1367 int i, error;
1368
1369 if (group_id >= wacom->led.count || count <= 0)
1370 return -EINVAL;
1371
1372 if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL))
1373 return -ENOMEM;
1374
1375 leds = devm_kcalloc(dev, count, sizeof(struct wacom_led), GFP_KERNEL);
1376 if (!leds) {
1377 error = -ENOMEM;
1378 goto err;
1379 }
1380
1381 wacom->led.groups[group_id].leds = leds;
1382 wacom->led.groups[group_id].count = count;
1383
1384 for (i = 0; i < count; i++) {
1385 error = wacom_led_register_one(dev, wacom, &leds[i],
1386 group_id, i, read_only);
1387 if (error)
1388 goto err;
1389 }
1390
1391 wacom->led.groups[group_id].dev = dev;
1392
1393 devres_close_group(dev, &wacom->led.groups[group_id]);
1394
1395 /*
1396 * There is a bug (?) in devm_led_classdev_register() in which its
1397 * increments the refcount of the parent. If the parent is an input
1398 * device, that means the ref count never reaches 0 when
1399 * devm_input_device_release() gets called.
1400 * This means that the LEDs are still there after disconnect.
1401 * Manually force the release of the group so that the leds are released
1402 * once we are done using them.
1403 */
1404 error = devm_add_action_or_reset(&wacom->hdev->dev,
1405 wacom_led_groups_release_one,
1406 &wacom->led.groups[group_id]);
1407 if (error)
1408 return error;
1409
1410 return 0;
1411
1412err:
1413 devres_release_group(dev, &wacom->led.groups[group_id]);
1414 return error;
1415}
1416
1417struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group_id,
1418 unsigned int id)
1419{
1420 struct wacom_group_leds *group;
1421
1422 if (group_id >= wacom->led.count)
1423 return NULL;
1424
1425 group = &wacom->led.groups[group_id];
1426
1427 if (!group->leds)
1428 return NULL;
1429
1430 id %= group->count;
1431
1432 return &group->leds[id];
1433}
1434
1435/**
1436 * wacom_led_next: gives the next available led with a wacom trigger.
1437 *
1438 * returns the next available struct wacom_led which has its default trigger
1439 * or the current one if none is available.
1440 */
1441struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur)
1442{
1443 struct wacom_led *next_led;
1444 int group, next;
1445
1446 if (!wacom || !cur)
1447 return NULL;
1448
1449 group = cur->group;
1450 next = cur->id;
1451
1452 do {
1453 next_led = wacom_led_find(wacom, group, ++next);
1454 if (!next_led || next_led == cur)
1455 return next_led;
1456 } while (next_led->cdev.trigger != &next_led->trigger);
1457
1458 return next_led;
1459}
1460
1461static void wacom_led_groups_release(void *data)
1462{
1463 struct wacom *wacom = data;
1464
1465 wacom->led.groups = NULL;
1466 wacom->led.count = 0;
1467}
1468
1469static int wacom_led_groups_allocate(struct wacom *wacom, int count)
1470{
1471 struct device *dev = &wacom->hdev->dev;
1472 struct wacom_group_leds *groups;
1473 int error;
1474
1475 groups = devm_kcalloc(dev, count, sizeof(struct wacom_group_leds),
1476 GFP_KERNEL);
1477 if (!groups)
1478 return -ENOMEM;
1479
1480 error = devm_add_action_or_reset(dev, wacom_led_groups_release, wacom);
1481 if (error)
1482 return error;
1483
1484 wacom->led.groups = groups;
1485 wacom->led.count = count;
1486
1487 return 0;
1488}
1489
1490static int wacom_leds_alloc_and_register(struct wacom *wacom, int group_count,
1491 int led_per_group, bool read_only)
1492{
1493 struct device *dev;
1494 int i, error;
1495
1496 if (!wacom->wacom_wac.pad_input)
1497 return -EINVAL;
1498
1499 dev = &wacom->wacom_wac.pad_input->dev;
1500
1501 error = wacom_led_groups_allocate(wacom, group_count);
1502 if (error)
1503 return error;
1504
1505 for (i = 0; i < group_count; i++) {
1506 error = wacom_led_groups_alloc_and_register_one(dev, wacom, i,
1507 led_per_group,
1508 read_only);
1509 if (error)
1510 return error;
1511 }
1512
1513 return 0;
1514}
1515
1516int wacom_initialize_leds(struct wacom *wacom)
1517{
1518 int error;
1519
1520 if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
1521 return 0;
1522
1523 /* Initialize default values */
1524 switch (wacom->wacom_wac.features.type) {
1525 case HID_GENERIC:
1526 if (!wacom->generic_has_leds)
1527 return 0;
1528 wacom->led.llv = 100;
1529 wacom->led.max_llv = 100;
1530
1531 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
1532 if (error) {
1533 hid_err(wacom->hdev,
1534 "cannot create leds err: %d\n", error);
1535 return error;
1536 }
1537
1538 error = wacom_devm_sysfs_create_group(wacom,
1539 &generic_led_attr_group);
1540 break;
1541
1542 case INTUOS4S:
1543 case INTUOS4:
1544 case INTUOS4WL:
1545 case INTUOS4L:
1546 wacom->led.llv = 10;
1547 wacom->led.hlv = 20;
1548 wacom->led.max_llv = 127;
1549 wacom->led.max_hlv = 127;
1550 wacom->led.img_lum = 10;
1551
1552 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
1553 if (error) {
1554 hid_err(wacom->hdev,
1555 "cannot create leds err: %d\n", error);
1556 return error;
1557 }
1558
1559 error = wacom_devm_sysfs_create_group(wacom,
1560 &intuos4_led_attr_group);
1561 break;
1562
1563 case WACOM_24HD:
1564 case WACOM_21UX2:
1565 wacom->led.llv = 0;
1566 wacom->led.hlv = 0;
1567 wacom->led.img_lum = 0;
1568
1569 error = wacom_leds_alloc_and_register(wacom, 2, 4, false);
1570 if (error) {
1571 hid_err(wacom->hdev,
1572 "cannot create leds err: %d\n", error);
1573 return error;
1574 }
1575
1576 error = wacom_devm_sysfs_create_group(wacom,
1577 &cintiq_led_attr_group);
1578 break;
1579
1580 case INTUOS5S:
1581 case INTUOS5:
1582 case INTUOS5L:
1583 case INTUOSPS:
1584 case INTUOSPM:
1585 case INTUOSPL:
1586 wacom->led.llv = 32;
1587 wacom->led.max_llv = 96;
1588
1589 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
1590 if (error) {
1591 hid_err(wacom->hdev,
1592 "cannot create leds err: %d\n", error);
1593 return error;
1594 }
1595
1596 error = wacom_devm_sysfs_create_group(wacom,
1597 &intuos5_led_attr_group);
1598 break;
1599
1600 case INTUOSP2_BT:
1601 wacom->led.llv = 50;
1602 wacom->led.max_llv = 100;
1603 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
1604 if (error) {
1605 hid_err(wacom->hdev,
1606 "cannot create leds err: %d\n", error);
1607 return error;
1608 }
1609 return 0;
1610
1611 case REMOTE:
1612 wacom->led.llv = 255;
1613 wacom->led.max_llv = 255;
1614 error = wacom_led_groups_allocate(wacom, 5);
1615 if (error) {
1616 hid_err(wacom->hdev,
1617 "cannot create leds err: %d\n", error);
1618 return error;
1619 }
1620 return 0;
1621
1622 default:
1623 return 0;
1624 }
1625
1626 if (error) {
1627 hid_err(wacom->hdev,
1628 "cannot create sysfs group err: %d\n", error);
1629 return error;
1630 }
1631
1632 return 0;
1633}
1634
1635static void wacom_init_work(struct work_struct *work)
1636{
1637 struct wacom *wacom = container_of(work, struct wacom, init_work.work);
1638
1639 _wacom_query_tablet_data(wacom);
1640 wacom_led_control(wacom);
1641}
1642
1643static void wacom_query_tablet_data(struct wacom *wacom)
1644{
1645 schedule_delayed_work(&wacom->init_work, msecs_to_jiffies(1000));
1646}
1647
1648static enum power_supply_property wacom_battery_props[] = {
1649 POWER_SUPPLY_PROP_MODEL_NAME,
1650 POWER_SUPPLY_PROP_PRESENT,
1651 POWER_SUPPLY_PROP_STATUS,
1652 POWER_SUPPLY_PROP_SCOPE,
1653 POWER_SUPPLY_PROP_CAPACITY
1654};
1655
1656static int wacom_battery_get_property(struct power_supply *psy,
1657 enum power_supply_property psp,
1658 union power_supply_propval *val)
1659{
1660 struct wacom_battery *battery = power_supply_get_drvdata(psy);
1661 int ret = 0;
1662
1663 switch (psp) {
1664 case POWER_SUPPLY_PROP_MODEL_NAME:
1665 val->strval = battery->wacom->wacom_wac.name;
1666 break;
1667 case POWER_SUPPLY_PROP_PRESENT:
1668 val->intval = battery->bat_connected;
1669 break;
1670 case POWER_SUPPLY_PROP_SCOPE:
1671 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1672 break;
1673 case POWER_SUPPLY_PROP_CAPACITY:
1674 val->intval = battery->battery_capacity;
1675 break;
1676 case POWER_SUPPLY_PROP_STATUS:
1677 if (battery->bat_status != WACOM_POWER_SUPPLY_STATUS_AUTO)
1678 val->intval = battery->bat_status;
1679 else if (battery->bat_charging)
1680 val->intval = POWER_SUPPLY_STATUS_CHARGING;
1681 else if (battery->battery_capacity == 100 &&
1682 battery->ps_connected)
1683 val->intval = POWER_SUPPLY_STATUS_FULL;
1684 else if (battery->ps_connected)
1685 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
1686 else
1687 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
1688 break;
1689 default:
1690 ret = -EINVAL;
1691 break;
1692 }
1693
1694 return ret;
1695}
1696
1697static int __wacom_initialize_battery(struct wacom *wacom,
1698 struct wacom_battery *battery)
1699{
1700 static atomic_t battery_no = ATOMIC_INIT(0);
1701 struct device *dev = &wacom->hdev->dev;
1702 struct power_supply_config psy_cfg = { .drv_data = battery, };
1703 struct power_supply *ps_bat;
1704 struct power_supply_desc *bat_desc = &battery->bat_desc;
1705 unsigned long n;
1706 int error;
1707
1708 if (!devres_open_group(dev, bat_desc, GFP_KERNEL))
1709 return -ENOMEM;
1710
1711 battery->wacom = wacom;
1712
1713 n = atomic_inc_return(&battery_no) - 1;
1714
1715 bat_desc->properties = wacom_battery_props;
1716 bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
1717 bat_desc->get_property = wacom_battery_get_property;
1718 sprintf(battery->bat_name, "wacom_battery_%ld", n);
1719 bat_desc->name = battery->bat_name;
1720 bat_desc->type = POWER_SUPPLY_TYPE_USB;
1721 bat_desc->use_for_apm = 0;
1722
1723 ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg);
1724 if (IS_ERR(ps_bat)) {
1725 error = PTR_ERR(ps_bat);
1726 goto err;
1727 }
1728
1729 power_supply_powers(ps_bat, &wacom->hdev->dev);
1730
1731 battery->battery = ps_bat;
1732
1733 devres_close_group(dev, bat_desc);
1734 return 0;
1735
1736err:
1737 devres_release_group(dev, bat_desc);
1738 return error;
1739}
1740
1741static int wacom_initialize_battery(struct wacom *wacom)
1742{
1743 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY)
1744 return __wacom_initialize_battery(wacom, &wacom->battery);
1745
1746 return 0;
1747}
1748
1749static void wacom_destroy_battery(struct wacom *wacom)
1750{
1751 if (wacom->battery.battery) {
1752 devres_release_group(&wacom->hdev->dev,
1753 &wacom->battery.bat_desc);
1754 wacom->battery.battery = NULL;
1755 }
1756}
1757
1758static ssize_t wacom_show_speed(struct device *dev,
1759 struct device_attribute
1760 *attr, char *buf)
1761{
1762 struct hid_device *hdev = to_hid_device(dev);
1763 struct wacom *wacom = hid_get_drvdata(hdev);
1764
1765 return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
1766}
1767
1768static ssize_t wacom_store_speed(struct device *dev,
1769 struct device_attribute *attr,
1770 const char *buf, size_t count)
1771{
1772 struct hid_device *hdev = to_hid_device(dev);
1773 struct wacom *wacom = hid_get_drvdata(hdev);
1774 u8 new_speed;
1775
1776 if (kstrtou8(buf, 0, &new_speed))
1777 return -EINVAL;
1778
1779 if (new_speed != 0 && new_speed != 1)
1780 return -EINVAL;
1781
1782 wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
1783
1784 return count;
1785}
1786
1787static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM,
1788 wacom_show_speed, wacom_store_speed);
1789
1790
1791static ssize_t wacom_show_remote_mode(struct kobject *kobj,
1792 struct kobj_attribute *kattr,
1793 char *buf, int index)
1794{
1795 struct device *dev = kobj_to_dev(kobj->parent);
1796 struct hid_device *hdev = to_hid_device(dev);
1797 struct wacom *wacom = hid_get_drvdata(hdev);
1798 u8 mode;
1799
1800 mode = wacom->led.groups[index].select;
1801 return sprintf(buf, "%d\n", mode < 3 ? mode : -1);
1802}
1803
1804#define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1805static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1806 struct kobj_attribute *kattr, char *buf) \
1807{ \
1808 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1809} \
1810static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1811 .attr = {.name = "remote_mode", \
1812 .mode = DEV_ATTR_RO_PERM}, \
1813 .show = wacom_show_remote##SET_ID##_mode, \
1814}; \
1815static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1816 &remote##SET_ID##_mode_attr.attr, \
1817 NULL \
1818}; \
1819static struct attribute_group remote##SET_ID##_serial_group = { \
1820 .name = NULL, \
1821 .attrs = remote##SET_ID##_serial_attrs, \
1822}
1823
1824DEVICE_EKR_ATTR_GROUP(0);
1825DEVICE_EKR_ATTR_GROUP(1);
1826DEVICE_EKR_ATTR_GROUP(2);
1827DEVICE_EKR_ATTR_GROUP(3);
1828DEVICE_EKR_ATTR_GROUP(4);
1829
1830static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial,
1831 int index)
1832{
1833 int error = 0;
1834 struct wacom_remote *remote = wacom->remote;
1835
1836 remote->remotes[index].group.name = devm_kasprintf(&wacom->hdev->dev,
1837 GFP_KERNEL,
1838 "%d", serial);
1839 if (!remote->remotes[index].group.name)
1840 return -ENOMEM;
1841
1842 error = __wacom_devm_sysfs_create_group(wacom, remote->remote_dir,
1843 &remote->remotes[index].group);
1844 if (error) {
1845 remote->remotes[index].group.name = NULL;
1846 hid_err(wacom->hdev,
1847 "cannot create sysfs group err: %d\n", error);
1848 return error;
1849 }
1850
1851 return 0;
1852}
1853
1854static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector)
1855{
1856 const size_t buf_size = 2;
1857 unsigned char *buf;
1858 int retval;
1859
1860 buf = kzalloc(buf_size, GFP_KERNEL);
1861 if (!buf)
1862 return -ENOMEM;
1863
1864 buf[0] = WAC_CMD_DELETE_PAIRING;
1865 buf[1] = selector;
1866
1867 retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf,
1868 buf_size, WAC_CMD_RETRIES);
1869 kfree(buf);
1870
1871 return retval;
1872}
1873
1874static ssize_t wacom_store_unpair_remote(struct kobject *kobj,
1875 struct kobj_attribute *attr,
1876 const char *buf, size_t count)
1877{
1878 unsigned char selector = 0;
1879 struct device *dev = kobj_to_dev(kobj->parent);
1880 struct hid_device *hdev = to_hid_device(dev);
1881 struct wacom *wacom = hid_get_drvdata(hdev);
1882 int err;
1883
1884 if (!strncmp(buf, "*\n", 2)) {
1885 selector = WAC_CMD_UNPAIR_ALL;
1886 } else {
1887 hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n",
1888 buf);
1889 return -1;
1890 }
1891
1892 mutex_lock(&wacom->lock);
1893
1894 err = wacom_cmd_unpair_remote(wacom, selector);
1895 mutex_unlock(&wacom->lock);
1896
1897 return err < 0 ? err : count;
1898}
1899
1900static struct kobj_attribute unpair_remote_attr = {
1901 .attr = {.name = "unpair_remote", .mode = 0200},
1902 .store = wacom_store_unpair_remote,
1903};
1904
1905static const struct attribute *remote_unpair_attrs[] = {
1906 &unpair_remote_attr.attr,
1907 NULL
1908};
1909
1910static void wacom_remotes_destroy(void *data)
1911{
1912 struct wacom *wacom = data;
1913 struct wacom_remote *remote = wacom->remote;
1914
1915 if (!remote)
1916 return;
1917
1918 kobject_put(remote->remote_dir);
1919 kfifo_free(&remote->remote_fifo);
1920 wacom->remote = NULL;
1921}
1922
1923static int wacom_initialize_remotes(struct wacom *wacom)
1924{
1925 int error = 0;
1926 struct wacom_remote *remote;
1927 int i;
1928
1929 if (wacom->wacom_wac.features.type != REMOTE)
1930 return 0;
1931
1932 remote = devm_kzalloc(&wacom->hdev->dev, sizeof(*wacom->remote),
1933 GFP_KERNEL);
1934 if (!remote)
1935 return -ENOMEM;
1936
1937 wacom->remote = remote;
1938
1939 spin_lock_init(&remote->remote_lock);
1940
1941 error = kfifo_alloc(&remote->remote_fifo,
1942 5 * sizeof(struct wacom_remote_data),
1943 GFP_KERNEL);
1944 if (error) {
1945 hid_err(wacom->hdev, "failed allocating remote_fifo\n");
1946 return -ENOMEM;
1947 }
1948
1949 remote->remotes[0].group = remote0_serial_group;
1950 remote->remotes[1].group = remote1_serial_group;
1951 remote->remotes[2].group = remote2_serial_group;
1952 remote->remotes[3].group = remote3_serial_group;
1953 remote->remotes[4].group = remote4_serial_group;
1954
1955 remote->remote_dir = kobject_create_and_add("wacom_remote",
1956 &wacom->hdev->dev.kobj);
1957 if (!remote->remote_dir)
1958 return -ENOMEM;
1959
1960 error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs);
1961
1962 if (error) {
1963 hid_err(wacom->hdev,
1964 "cannot create sysfs group err: %d\n", error);
1965 return error;
1966 }
1967
1968 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1969 wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
1970 remote->remotes[i].serial = 0;
1971 }
1972
1973 error = devm_add_action_or_reset(&wacom->hdev->dev,
1974 wacom_remotes_destroy, wacom);
1975 if (error)
1976 return error;
1977
1978 return 0;
1979}
1980
1981static struct input_dev *wacom_allocate_input(struct wacom *wacom)
1982{
1983 struct input_dev *input_dev;
1984 struct hid_device *hdev = wacom->hdev;
1985 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1986
1987 input_dev = devm_input_allocate_device(&hdev->dev);
1988 if (!input_dev)
1989 return NULL;
1990
1991 input_dev->name = wacom_wac->features.name;
1992 input_dev->phys = hdev->phys;
1993 input_dev->dev.parent = &hdev->dev;
1994 input_dev->open = wacom_open;
1995 input_dev->close = wacom_close;
1996 input_dev->uniq = hdev->uniq;
1997 input_dev->id.bustype = hdev->bus;
1998 input_dev->id.vendor = hdev->vendor;
1999 input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product;
2000 input_dev->id.version = hdev->version;
2001 input_set_drvdata(input_dev, wacom);
2002
2003 return input_dev;
2004}
2005
2006static int wacom_allocate_inputs(struct wacom *wacom)
2007{
2008 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
2009
2010 wacom_wac->pen_input = wacom_allocate_input(wacom);
2011 wacom_wac->touch_input = wacom_allocate_input(wacom);
2012 wacom_wac->pad_input = wacom_allocate_input(wacom);
2013 if (!wacom_wac->pen_input ||
2014 !wacom_wac->touch_input ||
2015 !wacom_wac->pad_input)
2016 return -ENOMEM;
2017
2018 wacom_wac->pen_input->name = wacom_wac->pen_name;
2019 wacom_wac->touch_input->name = wacom_wac->touch_name;
2020 wacom_wac->pad_input->name = wacom_wac->pad_name;
2021
2022 return 0;
2023}
2024
2025static int wacom_register_inputs(struct wacom *wacom)
2026{
2027 struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
2028 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
2029 int error = 0;
2030
2031 pen_input_dev = wacom_wac->pen_input;
2032 touch_input_dev = wacom_wac->touch_input;
2033 pad_input_dev = wacom_wac->pad_input;
2034
2035 if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
2036 return -EINVAL;
2037
2038 error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
2039 if (error) {
2040 /* no pen in use on this interface */
2041 input_free_device(pen_input_dev);
2042 wacom_wac->pen_input = NULL;
2043 pen_input_dev = NULL;
2044 } else {
2045 error = input_register_device(pen_input_dev);
2046 if (error)
2047 goto fail;
2048 }
2049
2050 error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
2051 if (error) {
2052 /* no touch in use on this interface */
2053 input_free_device(touch_input_dev);
2054 wacom_wac->touch_input = NULL;
2055 touch_input_dev = NULL;
2056 } else {
2057 error = input_register_device(touch_input_dev);
2058 if (error)
2059 goto fail;
2060 }
2061
2062 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
2063 if (error) {
2064 /* no pad in use on this interface */
2065 input_free_device(pad_input_dev);
2066 wacom_wac->pad_input = NULL;
2067 pad_input_dev = NULL;
2068 } else {
2069 error = input_register_device(pad_input_dev);
2070 if (error)
2071 goto fail;
2072 }
2073
2074 return 0;
2075
2076fail:
2077 wacom_wac->pad_input = NULL;
2078 wacom_wac->touch_input = NULL;
2079 wacom_wac->pen_input = NULL;
2080 return error;
2081}
2082
2083/*
2084 * Not all devices report physical dimensions from HID.
2085 * Compute the default from hardcoded logical dimension
2086 * and resolution before driver overwrites them.
2087 */
2088static void wacom_set_default_phy(struct wacom_features *features)
2089{
2090 if (features->x_resolution) {
2091 features->x_phy = (features->x_max * 100) /
2092 features->x_resolution;
2093 features->y_phy = (features->y_max * 100) /
2094 features->y_resolution;
2095 }
2096}
2097
2098static void wacom_calculate_res(struct wacom_features *features)
2099{
2100 /* set unit to "100th of a mm" for devices not reported by HID */
2101 if (!features->unit) {
2102 features->unit = 0x11;
2103 features->unitExpo = -3;
2104 }
2105
2106 features->x_resolution = wacom_calc_hid_res(features->x_max,
2107 features->x_phy,
2108 features->unit,
2109 features->unitExpo);
2110 features->y_resolution = wacom_calc_hid_res(features->y_max,
2111 features->y_phy,
2112 features->unit,
2113 features->unitExpo);
2114}
2115
2116void wacom_battery_work(struct work_struct *work)
2117{
2118 struct wacom *wacom = container_of(work, struct wacom, battery_work);
2119
2120 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
2121 !wacom->battery.battery) {
2122 wacom_initialize_battery(wacom);
2123 }
2124 else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
2125 wacom->battery.battery) {
2126 wacom_destroy_battery(wacom);
2127 }
2128}
2129
2130static size_t wacom_compute_pktlen(struct hid_device *hdev)
2131{
2132 struct hid_report_enum *report_enum;
2133 struct hid_report *report;
2134 size_t size = 0;
2135
2136 report_enum = hdev->report_enum + HID_INPUT_REPORT;
2137
2138 list_for_each_entry(report, &report_enum->report_list, list) {
2139 size_t report_size = hid_report_len(report);
2140 if (report_size > size)
2141 size = report_size;
2142 }
2143
2144 return size;
2145}
2146
2147static void wacom_update_name(struct wacom *wacom, const char *suffix)
2148{
2149 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2150 struct wacom_features *features = &wacom_wac->features;
2151 char name[WACOM_NAME_MAX - 20]; /* Leave some room for suffixes */
2152
2153 /* Generic devices name unspecified */
2154 if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
2155 char *product_name = wacom->hdev->name;
2156
2157 if (hid_is_using_ll_driver(wacom->hdev, &usb_hid_driver)) {
2158 struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent);
2159 struct usb_device *dev = interface_to_usbdev(intf);
2160 product_name = dev->product;
2161 }
2162
2163 if (wacom->hdev->bus == BUS_I2C) {
2164 snprintf(name, sizeof(name), "%s %X",
2165 features->name, wacom->hdev->product);
2166 } else if (strstr(product_name, "Wacom") ||
2167 strstr(product_name, "wacom") ||
2168 strstr(product_name, "WACOM")) {
2169 strlcpy(name, product_name, sizeof(name));
2170 } else {
2171 snprintf(name, sizeof(name), "Wacom %s", product_name);
2172 }
2173
2174 /* strip out excess whitespaces */
2175 while (1) {
2176 char *gap = strstr(name, " ");
2177 if (gap == NULL)
2178 break;
2179 /* shift everything including the terminator */
2180 memmove(gap, gap+1, strlen(gap));
2181 }
2182
2183 /* get rid of trailing whitespace */
2184 if (name[strlen(name)-1] == ' ')
2185 name[strlen(name)-1] = '\0';
2186 } else {
2187 strlcpy(name, features->name, sizeof(name));
2188 }
2189
2190 snprintf(wacom_wac->name, sizeof(wacom_wac->name), "%s%s",
2191 name, suffix);
2192
2193 /* Append the device type to the name */
2194 snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
2195 "%s%s Pen", name, suffix);
2196 snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
2197 "%s%s Finger", name, suffix);
2198 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
2199 "%s%s Pad", name, suffix);
2200}
2201
2202static void wacom_release_resources(struct wacom *wacom)
2203{
2204 struct hid_device *hdev = wacom->hdev;
2205
2206 if (!wacom->resources)
2207 return;
2208
2209 devres_release_group(&hdev->dev, wacom);
2210
2211 wacom->resources = false;
2212
2213 wacom->wacom_wac.pen_input = NULL;
2214 wacom->wacom_wac.touch_input = NULL;
2215 wacom->wacom_wac.pad_input = NULL;
2216}
2217
2218static void wacom_set_shared_values(struct wacom_wac *wacom_wac)
2219{
2220 if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) {
2221 wacom_wac->shared->type = wacom_wac->features.type;
2222 wacom_wac->shared->touch_input = wacom_wac->touch_input;
2223 }
2224
2225 if (wacom_wac->has_mute_touch_switch) {
2226 wacom_wac->shared->has_mute_touch_switch = true;
2227 wacom_wac->shared->is_touch_on = true;
2228 }
2229
2230 if (wacom_wac->shared->has_mute_touch_switch &&
2231 wacom_wac->shared->touch_input) {
2232 set_bit(EV_SW, wacom_wac->shared->touch_input->evbit);
2233 input_set_capability(wacom_wac->shared->touch_input, EV_SW,
2234 SW_MUTE_DEVICE);
2235 }
2236}
2237
2238static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
2239{
2240 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2241 struct wacom_features *features = &wacom_wac->features;
2242 struct hid_device *hdev = wacom->hdev;
2243 int error;
2244 unsigned int connect_mask = HID_CONNECT_HIDRAW;
2245
2246 features->pktlen = wacom_compute_pktlen(hdev);
2247 if (features->pktlen > WACOM_PKGLEN_MAX)
2248 return -EINVAL;
2249
2250 if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL))
2251 return -ENOMEM;
2252
2253 wacom->resources = true;
2254
2255 error = wacom_allocate_inputs(wacom);
2256 if (error)
2257 goto fail;
2258
2259 /*
2260 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
2261 * into debug mode for the touch part.
2262 * We ignore the other interfaces.
2263 */
2264 if (features->type == BAMBOO_PAD) {
2265 if (features->pktlen == WACOM_PKGLEN_PENABLED) {
2266 features->type = HID_GENERIC;
2267 } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
2268 (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
2269 error = -ENODEV;
2270 goto fail;
2271 }
2272 }
2273
2274 /* set the default size in case we do not get them from hid */
2275 wacom_set_default_phy(features);
2276
2277 /* Retrieve the physical and logical size for touch devices */
2278 wacom_retrieve_hid_descriptor(hdev, features);
2279 wacom_setup_device_quirks(wacom);
2280
2281 if (features->device_type == WACOM_DEVICETYPE_NONE &&
2282 features->type != WIRELESS) {
2283 error = features->type == HID_GENERIC ? -ENODEV : 0;
2284
2285 dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
2286 hdev->name,
2287 error ? "Ignoring" : "Assuming pen");
2288
2289 if (error)
2290 goto fail;
2291
2292 features->device_type |= WACOM_DEVICETYPE_PEN;
2293 }
2294
2295 wacom_calculate_res(features);
2296
2297 wacom_update_name(wacom, wireless ? " (WL)" : "");
2298
2299 /* pen only Bamboo neither support touch nor pad */
2300 if ((features->type == BAMBOO_PEN) &&
2301 ((features->device_type & WACOM_DEVICETYPE_TOUCH) ||
2302 (features->device_type & WACOM_DEVICETYPE_PAD))) {
2303 error = -ENODEV;
2304 goto fail;
2305 }
2306
2307 error = wacom_add_shared_data(hdev);
2308 if (error)
2309 goto fail;
2310
2311 if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
2312 (features->quirks & WACOM_QUIRK_BATTERY)) {
2313 error = wacom_initialize_battery(wacom);
2314 if (error)
2315 goto fail;
2316 }
2317
2318 error = wacom_register_inputs(wacom);
2319 if (error)
2320 goto fail;
2321
2322 if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD) {
2323 error = wacom_initialize_leds(wacom);
2324 if (error)
2325 goto fail;
2326
2327 error = wacom_initialize_remotes(wacom);
2328 if (error)
2329 goto fail;
2330 }
2331
2332 if (features->type == HID_GENERIC)
2333 connect_mask |= HID_CONNECT_DRIVER;
2334
2335 /* Regular HID work starts now */
2336 error = hid_hw_start(hdev, connect_mask);
2337 if (error) {
2338 hid_err(hdev, "hw start failed\n");
2339 goto fail;
2340 }
2341
2342 if (!wireless) {
2343 /* Note that if query fails it is not a hard failure */
2344 wacom_query_tablet_data(wacom);
2345 }
2346
2347 /* touch only Bamboo doesn't support pen */
2348 if ((features->type == BAMBOO_TOUCH) &&
2349 (features->device_type & WACOM_DEVICETYPE_PEN)) {
2350 cancel_delayed_work_sync(&wacom->init_work);
2351 _wacom_query_tablet_data(wacom);
2352 error = -ENODEV;
2353 goto fail_quirks;
2354 }
2355
2356 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
2357 error = hid_hw_open(hdev);
2358
2359 wacom_set_shared_values(wacom_wac);
2360 devres_close_group(&hdev->dev, wacom);
2361
2362 return 0;
2363
2364fail_quirks:
2365 hid_hw_stop(hdev);
2366fail:
2367 wacom_release_resources(wacom);
2368 return error;
2369}
2370
2371static void wacom_wireless_work(struct work_struct *work)
2372{
2373 struct wacom *wacom = container_of(work, struct wacom, wireless_work);
2374 struct usb_device *usbdev = wacom->usbdev;
2375 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2376 struct hid_device *hdev1, *hdev2;
2377 struct wacom *wacom1, *wacom2;
2378 struct wacom_wac *wacom_wac1, *wacom_wac2;
2379 int error;
2380
2381 /*
2382 * Regardless if this is a disconnect or a new tablet,
2383 * remove any existing input and battery devices.
2384 */
2385
2386 wacom_destroy_battery(wacom);
2387
2388 /* Stylus interface */
2389 hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
2390 wacom1 = hid_get_drvdata(hdev1);
2391 wacom_wac1 = &(wacom1->wacom_wac);
2392 wacom_release_resources(wacom1);
2393
2394 /* Touch interface */
2395 hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
2396 wacom2 = hid_get_drvdata(hdev2);
2397 wacom_wac2 = &(wacom2->wacom_wac);
2398 wacom_release_resources(wacom2);
2399
2400 if (wacom_wac->pid == 0) {
2401 hid_info(wacom->hdev, "wireless tablet disconnected\n");
2402 } else {
2403 const struct hid_device_id *id = wacom_ids;
2404
2405 hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
2406 wacom_wac->pid);
2407
2408 while (id->bus) {
2409 if (id->vendor == USB_VENDOR_ID_WACOM &&
2410 id->product == wacom_wac->pid)
2411 break;
2412 id++;
2413 }
2414
2415 if (!id->bus) {
2416 hid_info(wacom->hdev, "ignoring unknown PID.\n");
2417 return;
2418 }
2419
2420 /* Stylus interface */
2421 wacom_wac1->features =
2422 *((struct wacom_features *)id->driver_data);
2423
2424 wacom_wac1->pid = wacom_wac->pid;
2425 hid_hw_stop(hdev1);
2426 error = wacom_parse_and_register(wacom1, true);
2427 if (error)
2428 goto fail;
2429
2430 /* Touch interface */
2431 if (wacom_wac1->features.touch_max ||
2432 (wacom_wac1->features.type >= INTUOSHT &&
2433 wacom_wac1->features.type <= BAMBOO_PT)) {
2434 wacom_wac2->features =
2435 *((struct wacom_features *)id->driver_data);
2436 wacom_wac2->pid = wacom_wac->pid;
2437 hid_hw_stop(hdev2);
2438 error = wacom_parse_and_register(wacom2, true);
2439 if (error)
2440 goto fail;
2441 }
2442
2443 strlcpy(wacom_wac->name, wacom_wac1->name,
2444 sizeof(wacom_wac->name));
2445 error = wacom_initialize_battery(wacom);
2446 if (error)
2447 goto fail;
2448 }
2449
2450 return;
2451
2452fail:
2453 wacom_release_resources(wacom1);
2454 wacom_release_resources(wacom2);
2455 return;
2456}
2457
2458static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
2459{
2460 struct wacom_remote *remote = wacom->remote;
2461 u32 serial = remote->remotes[index].serial;
2462 int i;
2463 unsigned long flags;
2464
2465 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
2466 if (remote->remotes[i].serial == serial) {
2467
2468 spin_lock_irqsave(&remote->remote_lock, flags);
2469 remote->remotes[i].registered = false;
2470 spin_unlock_irqrestore(&remote->remote_lock, flags);
2471
2472 if (remote->remotes[i].battery.battery)
2473 devres_release_group(&wacom->hdev->dev,
2474 &remote->remotes[i].battery.bat_desc);
2475
2476 if (remote->remotes[i].group.name)
2477 devres_release_group(&wacom->hdev->dev,
2478 &remote->remotes[i]);
2479
2480 remote->remotes[i].serial = 0;
2481 remote->remotes[i].group.name = NULL;
2482 remote->remotes[i].battery.battery = NULL;
2483 wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
2484 }
2485 }
2486}
2487
2488static int wacom_remote_create_one(struct wacom *wacom, u32 serial,
2489 unsigned int index)
2490{
2491 struct wacom_remote *remote = wacom->remote;
2492 struct device *dev = &wacom->hdev->dev;
2493 int error, k;
2494
2495 /* A remote can pair more than once with an EKR,
2496 * check to make sure this serial isn't already paired.
2497 */
2498 for (k = 0; k < WACOM_MAX_REMOTES; k++) {
2499 if (remote->remotes[k].serial == serial)
2500 break;
2501 }
2502
2503 if (k < WACOM_MAX_REMOTES) {
2504 remote->remotes[index].serial = serial;
2505 return 0;
2506 }
2507
2508 if (!devres_open_group(dev, &remote->remotes[index], GFP_KERNEL))
2509 return -ENOMEM;
2510
2511 error = wacom_remote_create_attr_group(wacom, serial, index);
2512 if (error)
2513 goto fail;
2514
2515 remote->remotes[index].input = wacom_allocate_input(wacom);
2516 if (!remote->remotes[index].input) {
2517 error = -ENOMEM;
2518 goto fail;
2519 }
2520 remote->remotes[index].input->uniq = remote->remotes[index].group.name;
2521 remote->remotes[index].input->name = wacom->wacom_wac.pad_name;
2522
2523 if (!remote->remotes[index].input->name) {
2524 error = -EINVAL;
2525 goto fail;
2526 }
2527
2528 error = wacom_setup_pad_input_capabilities(remote->remotes[index].input,
2529 &wacom->wacom_wac);
2530 if (error)
2531 goto fail;
2532
2533 remote->remotes[index].serial = serial;
2534
2535 error = input_register_device(remote->remotes[index].input);
2536 if (error)
2537 goto fail;
2538
2539 error = wacom_led_groups_alloc_and_register_one(
2540 &remote->remotes[index].input->dev,
2541 wacom, index, 3, true);
2542 if (error)
2543 goto fail;
2544
2545 remote->remotes[index].registered = true;
2546
2547 devres_close_group(dev, &remote->remotes[index]);
2548 return 0;
2549
2550fail:
2551 devres_release_group(dev, &remote->remotes[index]);
2552 remote->remotes[index].serial = 0;
2553 return error;
2554}
2555
2556static int wacom_remote_attach_battery(struct wacom *wacom, int index)
2557{
2558 struct wacom_remote *remote = wacom->remote;
2559 int error;
2560
2561 if (!remote->remotes[index].registered)
2562 return 0;
2563
2564 if (remote->remotes[index].battery.battery)
2565 return 0;
2566
2567 if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
2568 return 0;
2569
2570 error = __wacom_initialize_battery(wacom,
2571 &wacom->remote->remotes[index].battery);
2572 if (error)
2573 return error;
2574
2575 return 0;
2576}
2577
2578static void wacom_remote_work(struct work_struct *work)
2579{
2580 struct wacom *wacom = container_of(work, struct wacom, remote_work);
2581 struct wacom_remote *remote = wacom->remote;
2582 struct wacom_remote_data data;
2583 unsigned long flags;
2584 unsigned int count;
2585 u32 serial;
2586 int i;
2587
2588 spin_lock_irqsave(&remote->remote_lock, flags);
2589
2590 count = kfifo_out(&remote->remote_fifo, &data, sizeof(data));
2591
2592 if (count != sizeof(data)) {
2593 hid_err(wacom->hdev,
2594 "workitem triggered without status available\n");
2595 spin_unlock_irqrestore(&remote->remote_lock, flags);
2596 return;
2597 }
2598
2599 if (!kfifo_is_empty(&remote->remote_fifo))
2600 wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_REMOTE);
2601
2602 spin_unlock_irqrestore(&remote->remote_lock, flags);
2603
2604 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
2605 serial = data.remote[i].serial;
2606 if (data.remote[i].connected) {
2607
2608 if (remote->remotes[i].serial == serial) {
2609 wacom_remote_attach_battery(wacom, i);
2610 continue;
2611 }
2612
2613 if (remote->remotes[i].serial)
2614 wacom_remote_destroy_one(wacom, i);
2615
2616 wacom_remote_create_one(wacom, serial, i);
2617
2618 } else if (remote->remotes[i].serial) {
2619 wacom_remote_destroy_one(wacom, i);
2620 }
2621 }
2622}
2623
2624static void wacom_mode_change_work(struct work_struct *work)
2625{
2626 struct wacom *wacom = container_of(work, struct wacom, mode_change_work);
2627 struct wacom_shared *shared = wacom->wacom_wac.shared;
2628 struct wacom *wacom1 = NULL;
2629 struct wacom *wacom2 = NULL;
2630 bool is_direct = wacom->wacom_wac.is_direct_mode;
2631 int error = 0;
2632
2633 if (shared->pen) {
2634 wacom1 = hid_get_drvdata(shared->pen);
2635 wacom_release_resources(wacom1);
2636 hid_hw_stop(wacom1->hdev);
2637 wacom1->wacom_wac.has_mode_change = true;
2638 wacom1->wacom_wac.is_direct_mode = is_direct;
2639 }
2640
2641 if (shared->touch) {
2642 wacom2 = hid_get_drvdata(shared->touch);
2643 wacom_release_resources(wacom2);
2644 hid_hw_stop(wacom2->hdev);
2645 wacom2->wacom_wac.has_mode_change = true;
2646 wacom2->wacom_wac.is_direct_mode = is_direct;
2647 }
2648
2649 if (wacom1) {
2650 error = wacom_parse_and_register(wacom1, false);
2651 if (error)
2652 return;
2653 }
2654
2655 if (wacom2) {
2656 error = wacom_parse_and_register(wacom2, false);
2657 if (error)
2658 return;
2659 }
2660
2661 return;
2662}
2663
2664static int wacom_probe(struct hid_device *hdev,
2665 const struct hid_device_id *id)
2666{
2667 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
2668 struct usb_device *dev = interface_to_usbdev(intf);
2669 struct wacom *wacom;
2670 struct wacom_wac *wacom_wac;
2671 struct wacom_features *features;
2672 int error;
2673
2674 if (!id->driver_data)
2675 return -EINVAL;
2676
2677 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
2678
2679 /* hid-core sets this quirk for the boot interface */
2680 hdev->quirks &= ~HID_QUIRK_NOGET;
2681
2682 wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL);
2683 if (!wacom)
2684 return -ENOMEM;
2685
2686 hid_set_drvdata(hdev, wacom);
2687 wacom->hdev = hdev;
2688
2689 wacom_wac = &wacom->wacom_wac;
2690 wacom_wac->features = *((struct wacom_features *)id->driver_data);
2691 features = &wacom_wac->features;
2692
2693 if (features->check_for_hid_type && features->hid_type != hdev->type) {
2694 error = -ENODEV;
2695 goto fail;
2696 }
2697
2698 error = kfifo_alloc(&wacom_wac->pen_fifo, WACOM_PKGLEN_MAX, GFP_KERNEL);
2699 if (error)
2700 goto fail;
2701
2702 wacom_wac->hid_data.inputmode = -1;
2703 wacom_wac->mode_report = -1;
2704
2705 wacom->usbdev = dev;
2706 wacom->intf = intf;
2707 mutex_init(&wacom->lock);
2708 INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work);
2709 INIT_WORK(&wacom->wireless_work, wacom_wireless_work);
2710 INIT_WORK(&wacom->battery_work, wacom_battery_work);
2711 INIT_WORK(&wacom->remote_work, wacom_remote_work);
2712 INIT_WORK(&wacom->mode_change_work, wacom_mode_change_work);
2713
2714 /* ask for the report descriptor to be loaded by HID */
2715 error = hid_parse(hdev);
2716 if (error) {
2717 hid_err(hdev, "parse failed\n");
2718 goto fail;
2719 }
2720
2721 error = wacom_parse_and_register(wacom, false);
2722 if (error)
2723 goto fail;
2724
2725 if (hdev->bus == BUS_BLUETOOTH) {
2726 error = device_create_file(&hdev->dev, &dev_attr_speed);
2727 if (error)
2728 hid_warn(hdev,
2729 "can't create sysfs speed attribute err: %d\n",
2730 error);
2731 }
2732
2733 return 0;
2734
2735fail:
2736 hid_set_drvdata(hdev, NULL);
2737 return error;
2738}
2739
2740static void wacom_remove(struct hid_device *hdev)
2741{
2742 struct wacom *wacom = hid_get_drvdata(hdev);
2743 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2744 struct wacom_features *features = &wacom_wac->features;
2745
2746 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
2747 hid_hw_close(hdev);
2748
2749 hid_hw_stop(hdev);
2750
2751 cancel_delayed_work_sync(&wacom->init_work);
2752 cancel_work_sync(&wacom->wireless_work);
2753 cancel_work_sync(&wacom->battery_work);
2754 cancel_work_sync(&wacom->remote_work);
2755 cancel_work_sync(&wacom->mode_change_work);
2756 if (hdev->bus == BUS_BLUETOOTH)
2757 device_remove_file(&hdev->dev, &dev_attr_speed);
2758
2759 /* make sure we don't trigger the LEDs */
2760 wacom_led_groups_release(wacom);
2761
2762 if (wacom->wacom_wac.features.type != REMOTE)
2763 wacom_release_resources(wacom);
2764
2765 kfifo_free(&wacom_wac->pen_fifo);
2766
2767 hid_set_drvdata(hdev, NULL);
2768}
2769
2770#ifdef CONFIG_PM
2771static int wacom_resume(struct hid_device *hdev)
2772{
2773 struct wacom *wacom = hid_get_drvdata(hdev);
2774
2775 mutex_lock(&wacom->lock);
2776
2777 /* switch to wacom mode first */
2778 _wacom_query_tablet_data(wacom);
2779 wacom_led_control(wacom);
2780
2781 mutex_unlock(&wacom->lock);
2782
2783 return 0;
2784}
2785
2786static int wacom_reset_resume(struct hid_device *hdev)
2787{
2788 return wacom_resume(hdev);
2789}
2790#endif /* CONFIG_PM */
2791
2792static struct hid_driver wacom_driver = {
2793 .name = "wacom",
2794 .id_table = wacom_ids,
2795 .probe = wacom_probe,
2796 .remove = wacom_remove,
2797 .report = wacom_wac_report,
2798#ifdef CONFIG_PM
2799 .resume = wacom_resume,
2800 .reset_resume = wacom_reset_resume,
2801#endif
2802 .raw_event = wacom_raw_event,
2803};
2804module_hid_driver(wacom_driver);
2805
2806MODULE_VERSION(DRIVER_VERSION);
2807MODULE_AUTHOR(DRIVER_AUTHOR);
2808MODULE_DESCRIPTION(DRIVER_DESC);
2809MODULE_LICENSE("GPL");