Input: wacom - handle Intuos 4 BT in wacom.ko
[deliverable/linux.git] / drivers / hid / wacom_sys.c
1 /*
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/hid.h>
17
18 #define WAC_MSG_RETRIES 5
19
20 #define WAC_CMD_LED_CONTROL 0x20
21 #define WAC_CMD_ICON_START 0x21
22 #define WAC_CMD_ICON_XFER 0x23
23 #define WAC_CMD_RETRIES 10
24
25 static int wacom_get_report(struct hid_device *hdev, u8 type, u8 id,
26 void *buf, size_t size, unsigned int retries)
27 {
28 int retval;
29
30 do {
31 retval = hid_hw_raw_request(hdev, id, buf, size, type,
32 HID_REQ_GET_REPORT);
33 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
34
35 return retval;
36 }
37
38 static int wacom_set_report(struct hid_device *hdev, u8 type, u8 id,
39 void *buf, size_t size, unsigned int retries)
40 {
41 int retval;
42
43 do {
44 retval = hid_hw_raw_request(hdev, id, buf, size, type,
45 HID_REQ_SET_REPORT);
46 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
47
48 return retval;
49 }
50
51 static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
52 u8 *raw_data, int size)
53 {
54 struct wacom *wacom = hid_get_drvdata(hdev);
55
56 if (size > WACOM_PKGLEN_MAX)
57 return 1;
58
59 memcpy(wacom->wacom_wac.data, raw_data, size);
60
61 wacom_wac_irq(&wacom->wacom_wac, size);
62
63 return 0;
64 }
65
66 static int wacom_open(struct input_dev *dev)
67 {
68 struct wacom *wacom = input_get_drvdata(dev);
69 int retval;
70
71 mutex_lock(&wacom->lock);
72 retval = hid_hw_open(wacom->hdev);
73 mutex_unlock(&wacom->lock);
74
75 return retval;
76 }
77
78 static void wacom_close(struct input_dev *dev)
79 {
80 struct wacom *wacom = input_get_drvdata(dev);
81
82 mutex_lock(&wacom->lock);
83 hid_hw_close(wacom->hdev);
84 mutex_unlock(&wacom->lock);
85 }
86
87 /*
88 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
89 */
90 static int wacom_calc_hid_res(int logical_extents, int physical_extents,
91 unsigned unit, int exponent)
92 {
93 struct hid_field field = {
94 .logical_maximum = logical_extents,
95 .physical_maximum = physical_extents,
96 .unit = unit,
97 .unit_exponent = exponent,
98 };
99
100 return hidinput_calc_abs_res(&field, ABS_X);
101 }
102
103 static void wacom_feature_mapping(struct hid_device *hdev,
104 struct hid_field *field, struct hid_usage *usage)
105 {
106 struct wacom *wacom = hid_get_drvdata(hdev);
107 struct wacom_features *features = &wacom->wacom_wac.features;
108
109 switch (usage->hid) {
110 case HID_DG_CONTACTMAX:
111 /* leave touch_max as is if predefined */
112 if (!features->touch_max)
113 features->touch_max = field->value[0];
114 break;
115 }
116 }
117
118 /*
119 * Interface Descriptor of wacom devices can be incomplete and
120 * inconsistent so wacom_features table is used to store stylus
121 * device's packet lengths, various maximum values, and tablet
122 * resolution based on product ID's.
123 *
124 * For devices that contain 2 interfaces, wacom_features table is
125 * inaccurate for the touch interface. Since the Interface Descriptor
126 * for touch interfaces has pretty complete data, this function exists
127 * to query tablet for this missing information instead of hard coding in
128 * an additional table.
129 *
130 * A typical Interface Descriptor for a stylus will contain a
131 * boot mouse application collection that is not of interest and this
132 * function will ignore it.
133 *
134 * It also contains a digitizer application collection that also is not
135 * of interest since any information it contains would be duplicate
136 * of what is in wacom_features. Usually it defines a report of an array
137 * of bytes that could be used as max length of the stylus packet returned.
138 * If it happens to define a Digitizer-Stylus Physical Collection then
139 * the X and Y logical values contain valid data but it is ignored.
140 *
141 * A typical Interface Descriptor for a touch interface will contain a
142 * Digitizer-Finger Physical Collection which will define both logical
143 * X/Y maximum as well as the physical size of tablet. Since touch
144 * interfaces haven't supported pressure or distance, this is enough
145 * information to override invalid values in the wacom_features table.
146 *
147 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
148 * data. We deal with them after returning from this function.
149 */
150 static void wacom_usage_mapping(struct hid_device *hdev,
151 struct hid_field *field, struct hid_usage *usage)
152 {
153 struct wacom *wacom = hid_get_drvdata(hdev);
154 struct wacom_features *features = &wacom->wacom_wac.features;
155 bool finger = (field->logical == HID_DG_FINGER) ||
156 (field->physical == HID_DG_FINGER);
157 bool pen = (field->logical == HID_DG_STYLUS) ||
158 (field->physical == HID_DG_STYLUS);
159
160 /*
161 * Requiring Stylus Usage will ignore boot mouse
162 * X/Y values and some cases of invalid Digitizer X/Y
163 * values commonly reported.
164 */
165 if (!pen && !finger)
166 return;
167
168 if (finger && !features->touch_max)
169 /* touch device at least supports one touch point */
170 features->touch_max = 1;
171
172 switch (usage->hid) {
173 case HID_GD_X:
174 features->x_max = field->logical_maximum;
175 if (finger) {
176 features->device_type = BTN_TOOL_FINGER;
177 features->x_phy = field->physical_maximum;
178 if (features->type != BAMBOO_PT) {
179 features->unit = field->unit;
180 features->unitExpo = field->unit_exponent;
181 }
182 } else {
183 features->device_type = BTN_TOOL_PEN;
184 }
185 break;
186 case HID_GD_Y:
187 features->y_max = field->logical_maximum;
188 if (finger) {
189 features->y_phy = field->physical_maximum;
190 if (features->type != BAMBOO_PT) {
191 features->unit = field->unit;
192 features->unitExpo = field->unit_exponent;
193 }
194 }
195 break;
196 case HID_DG_TIPPRESSURE:
197 if (pen)
198 features->pressure_max = field->logical_maximum;
199 break;
200 }
201 }
202
203 static void wacom_parse_hid(struct hid_device *hdev,
204 struct wacom_features *features)
205 {
206 struct hid_report_enum *rep_enum;
207 struct hid_report *hreport;
208 int i, j;
209
210 /* check features first */
211 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
212 list_for_each_entry(hreport, &rep_enum->report_list, list) {
213 for (i = 0; i < hreport->maxfield; i++) {
214 /* Ignore if report count is out of bounds. */
215 if (hreport->field[i]->report_count < 1)
216 continue;
217
218 for (j = 0; j < hreport->field[i]->maxusage; j++) {
219 wacom_feature_mapping(hdev, hreport->field[i],
220 hreport->field[i]->usage + j);
221 }
222 }
223 }
224
225 /* now check the input usages */
226 rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
227 list_for_each_entry(hreport, &rep_enum->report_list, list) {
228
229 if (!hreport->maxfield)
230 continue;
231
232 for (i = 0; i < hreport->maxfield; i++)
233 for (j = 0; j < hreport->field[i]->maxusage; j++)
234 wacom_usage_mapping(hdev, hreport->field[i],
235 hreport->field[i]->usage + j);
236 }
237 }
238
239 static int wacom_set_device_mode(struct hid_device *hdev, int report_id,
240 int length, int mode)
241 {
242 unsigned char *rep_data;
243 int error = -ENOMEM, limit = 0;
244
245 rep_data = kzalloc(length, GFP_KERNEL);
246 if (!rep_data)
247 return error;
248
249 do {
250 rep_data[0] = report_id;
251 rep_data[1] = mode;
252
253 error = wacom_set_report(hdev, HID_FEATURE_REPORT,
254 report_id, rep_data, length, 1);
255 if (error >= 0)
256 error = wacom_get_report(hdev, HID_FEATURE_REPORT,
257 report_id, rep_data, length, 1);
258 } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES);
259
260 kfree(rep_data);
261
262 return error < 0 ? error : 0;
263 }
264
265 static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
266 struct wacom_features *features)
267 {
268 struct wacom *wacom = hid_get_drvdata(hdev);
269 int ret;
270 u8 rep_data[2];
271
272 switch (features->type) {
273 case GRAPHIRE_BT:
274 rep_data[0] = 0x03;
275 rep_data[1] = 0x00;
276 ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
277 rep_data[0], rep_data, 2, 3);
278
279 if (ret >= 0) {
280 rep_data[0] = speed == 0 ? 0x05 : 0x06;
281 rep_data[1] = 0x00;
282
283 ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
284 rep_data[0], rep_data, 2, 3);
285
286 if (ret >= 0) {
287 wacom->wacom_wac.bt_high_speed = speed;
288 return 0;
289 }
290 }
291
292 /*
293 * Note that if the raw queries fail, it's not a hard failure
294 * and it is safe to continue
295 */
296 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
297 rep_data[0], ret);
298 break;
299 case INTUOS4WL:
300 if (speed == 1)
301 wacom->wacom_wac.bt_features &= ~0x20;
302 else
303 wacom->wacom_wac.bt_features |= 0x20;
304
305 rep_data[0] = 0x03;
306 rep_data[1] = wacom->wacom_wac.bt_features;
307
308 ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
309 rep_data[0], rep_data, 2, 1);
310 if (ret >= 0)
311 wacom->wacom_wac.bt_high_speed = speed;
312 break;
313 }
314
315 return 0;
316 }
317
318 /*
319 * Switch the tablet into its most-capable mode. Wacom tablets are
320 * typically configured to power-up in a mode which sends mouse-like
321 * reports to the OS. To get absolute position, pressure data, etc.
322 * from the tablet, it is necessary to switch the tablet out of this
323 * mode and into one which sends the full range of tablet data.
324 */
325 static int wacom_query_tablet_data(struct hid_device *hdev,
326 struct wacom_features *features)
327 {
328 if (hdev->bus == BUS_BLUETOOTH)
329 return wacom_bt_query_tablet_data(hdev, 1, features);
330
331 if (features->device_type == BTN_TOOL_FINGER) {
332 if (features->type > TABLETPC) {
333 /* MT Tablet PC touch */
334 return wacom_set_device_mode(hdev, 3, 4, 4);
335 }
336 else if (features->type == WACOM_24HDT || features->type == CINTIQ_HYBRID) {
337 return wacom_set_device_mode(hdev, 18, 3, 2);
338 }
339 } else if (features->device_type == BTN_TOOL_PEN) {
340 if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
341 return wacom_set_device_mode(hdev, 2, 2, 2);
342 }
343 }
344
345 return 0;
346 }
347
348 static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
349 struct wacom_features *features)
350 {
351 struct wacom *wacom = hid_get_drvdata(hdev);
352 struct usb_interface *intf = wacom->intf;
353
354 /* default features */
355 features->device_type = BTN_TOOL_PEN;
356 features->x_fuzz = 4;
357 features->y_fuzz = 4;
358 features->pressure_fuzz = 0;
359 features->distance_fuzz = 0;
360
361 /*
362 * The wireless device HID is basic and layout conflicts with
363 * other tablets (monitor and touch interface can look like pen).
364 * Skip the query for this type and modify defaults based on
365 * interface number.
366 */
367 if (features->type == WIRELESS) {
368 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
369 features->device_type = 0;
370 } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
371 features->device_type = BTN_TOOL_FINGER;
372 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
373 }
374 }
375
376 /* only devices that support touch need to retrieve the info */
377 if (features->type < BAMBOO_PT)
378 return;
379
380 wacom_parse_hid(hdev, features);
381 }
382
383 struct wacom_hdev_data {
384 struct list_head list;
385 struct kref kref;
386 struct hid_device *dev;
387 struct wacom_shared shared;
388 };
389
390 static LIST_HEAD(wacom_udev_list);
391 static DEFINE_MUTEX(wacom_udev_list_lock);
392
393 static bool wacom_are_sibling(struct hid_device *hdev,
394 struct hid_device *sibling)
395 {
396 struct wacom *wacom = hid_get_drvdata(hdev);
397 struct wacom_features *features = &wacom->wacom_wac.features;
398 int vid = features->oVid;
399 int pid = features->oPid;
400 int n1,n2;
401
402 if (vid == 0 && pid == 0) {
403 vid = hdev->vendor;
404 pid = hdev->product;
405 }
406
407 if (vid != sibling->vendor || pid != sibling->product)
408 return false;
409
410 /* Compare the physical path. */
411 n1 = strrchr(hdev->phys, '.') - hdev->phys;
412 n2 = strrchr(sibling->phys, '.') - sibling->phys;
413 if (n1 != n2 || n1 <= 0 || n2 <= 0)
414 return false;
415
416 return !strncmp(hdev->phys, sibling->phys, n1);
417 }
418
419 static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
420 {
421 struct wacom_hdev_data *data;
422
423 list_for_each_entry(data, &wacom_udev_list, list) {
424 if (wacom_are_sibling(hdev, data->dev)) {
425 kref_get(&data->kref);
426 return data;
427 }
428 }
429
430 return NULL;
431 }
432
433 static int wacom_add_shared_data(struct hid_device *hdev)
434 {
435 struct wacom *wacom = hid_get_drvdata(hdev);
436 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
437 struct wacom_hdev_data *data;
438 int retval = 0;
439
440 mutex_lock(&wacom_udev_list_lock);
441
442 data = wacom_get_hdev_data(hdev);
443 if (!data) {
444 data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
445 if (!data) {
446 retval = -ENOMEM;
447 goto out;
448 }
449
450 kref_init(&data->kref);
451 data->dev = hdev;
452 list_add_tail(&data->list, &wacom_udev_list);
453 }
454
455 wacom_wac->shared = &data->shared;
456
457 out:
458 mutex_unlock(&wacom_udev_list_lock);
459 return retval;
460 }
461
462 static void wacom_release_shared_data(struct kref *kref)
463 {
464 struct wacom_hdev_data *data =
465 container_of(kref, struct wacom_hdev_data, kref);
466
467 mutex_lock(&wacom_udev_list_lock);
468 list_del(&data->list);
469 mutex_unlock(&wacom_udev_list_lock);
470
471 kfree(data);
472 }
473
474 static void wacom_remove_shared_data(struct wacom_wac *wacom)
475 {
476 struct wacom_hdev_data *data;
477
478 if (wacom->shared) {
479 data = container_of(wacom->shared, struct wacom_hdev_data, shared);
480 kref_put(&data->kref, wacom_release_shared_data);
481 wacom->shared = NULL;
482 }
483 }
484
485 static int wacom_led_control(struct wacom *wacom)
486 {
487 unsigned char *buf;
488 int retval;
489
490 buf = kzalloc(9, GFP_KERNEL);
491 if (!buf)
492 return -ENOMEM;
493
494 if (wacom->wacom_wac.features.type >= INTUOS5S &&
495 wacom->wacom_wac.features.type <= INTUOSPL) {
496 /*
497 * Touch Ring and crop mark LED luminance may take on
498 * one of four values:
499 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
500 */
501 int ring_led = wacom->led.select[0] & 0x03;
502 int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
503 int crop_lum = 0;
504
505 buf[0] = WAC_CMD_LED_CONTROL;
506 buf[1] = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
507 }
508 else {
509 int led = wacom->led.select[0] | 0x4;
510
511 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
512 wacom->wacom_wac.features.type == WACOM_24HD)
513 led |= (wacom->led.select[1] << 4) | 0x40;
514
515 buf[0] = WAC_CMD_LED_CONTROL;
516 buf[1] = led;
517 buf[2] = wacom->led.llv;
518 buf[3] = wacom->led.hlv;
519 buf[4] = wacom->led.img_lum;
520 }
521
522 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
523 WAC_CMD_LED_CONTROL, buf, 9, WAC_CMD_RETRIES);
524 kfree(buf);
525
526 return retval;
527 }
528
529 static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
530 {
531 unsigned char *buf;
532 int i, retval;
533
534 buf = kzalloc(259, GFP_KERNEL);
535 if (!buf)
536 return -ENOMEM;
537
538 /* Send 'start' command */
539 buf[0] = WAC_CMD_ICON_START;
540 buf[1] = 1;
541 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
542 WAC_CMD_ICON_START, buf, 2, WAC_CMD_RETRIES);
543 if (retval < 0)
544 goto out;
545
546 buf[0] = WAC_CMD_ICON_XFER;
547 buf[1] = button_id & 0x07;
548 for (i = 0; i < 4; i++) {
549 buf[2] = i;
550 memcpy(buf + 3, img + i * 256, 256);
551
552 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
553 WAC_CMD_ICON_XFER,
554 buf, 259, WAC_CMD_RETRIES);
555 if (retval < 0)
556 break;
557 }
558
559 /* Send 'stop' */
560 buf[0] = WAC_CMD_ICON_START;
561 buf[1] = 0;
562 wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, WAC_CMD_ICON_START,
563 buf, 2, WAC_CMD_RETRIES);
564
565 out:
566 kfree(buf);
567 return retval;
568 }
569
570 static ssize_t wacom_led_select_store(struct device *dev, int set_id,
571 const char *buf, size_t count)
572 {
573 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
574 struct wacom *wacom = hid_get_drvdata(hdev);
575 unsigned int id;
576 int err;
577
578 err = kstrtouint(buf, 10, &id);
579 if (err)
580 return err;
581
582 mutex_lock(&wacom->lock);
583
584 wacom->led.select[set_id] = id & 0x3;
585 err = wacom_led_control(wacom);
586
587 mutex_unlock(&wacom->lock);
588
589 return err < 0 ? err : count;
590 }
591
592 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
593 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
594 struct device_attribute *attr, const char *buf, size_t count) \
595 { \
596 return wacom_led_select_store(dev, SET_ID, buf, count); \
597 } \
598 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
599 struct device_attribute *attr, char *buf) \
600 { \
601 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
602 struct wacom *wacom = hid_get_drvdata(hdev); \
603 return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
604 } \
605 static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
606 wacom_led##SET_ID##_select_show, \
607 wacom_led##SET_ID##_select_store)
608
609 DEVICE_LED_SELECT_ATTR(0);
610 DEVICE_LED_SELECT_ATTR(1);
611
612 static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
613 const char *buf, size_t count)
614 {
615 unsigned int value;
616 int err;
617
618 err = kstrtouint(buf, 10, &value);
619 if (err)
620 return err;
621
622 mutex_lock(&wacom->lock);
623
624 *dest = value & 0x7f;
625 err = wacom_led_control(wacom);
626
627 mutex_unlock(&wacom->lock);
628
629 return err < 0 ? err : count;
630 }
631
632 #define DEVICE_LUMINANCE_ATTR(name, field) \
633 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
634 struct device_attribute *attr, const char *buf, size_t count) \
635 { \
636 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
637 struct wacom *wacom = hid_get_drvdata(hdev); \
638 \
639 return wacom_luminance_store(wacom, &wacom->led.field, \
640 buf, count); \
641 } \
642 static DEVICE_ATTR(name##_luminance, S_IWUSR, \
643 NULL, wacom_##name##_luminance_store)
644
645 DEVICE_LUMINANCE_ATTR(status0, llv);
646 DEVICE_LUMINANCE_ATTR(status1, hlv);
647 DEVICE_LUMINANCE_ATTR(buttons, img_lum);
648
649 static ssize_t wacom_button_image_store(struct device *dev, int button_id,
650 const char *buf, size_t count)
651 {
652 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
653 struct wacom *wacom = hid_get_drvdata(hdev);
654 int err;
655
656 if (count != 1024)
657 return -EINVAL;
658
659 mutex_lock(&wacom->lock);
660
661 err = wacom_led_putimage(wacom, button_id, buf);
662
663 mutex_unlock(&wacom->lock);
664
665 return err < 0 ? err : count;
666 }
667
668 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
669 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
670 struct device_attribute *attr, const char *buf, size_t count) \
671 { \
672 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
673 } \
674 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
675 NULL, wacom_btnimg##BUTTON_ID##_store)
676
677 DEVICE_BTNIMG_ATTR(0);
678 DEVICE_BTNIMG_ATTR(1);
679 DEVICE_BTNIMG_ATTR(2);
680 DEVICE_BTNIMG_ATTR(3);
681 DEVICE_BTNIMG_ATTR(4);
682 DEVICE_BTNIMG_ATTR(5);
683 DEVICE_BTNIMG_ATTR(6);
684 DEVICE_BTNIMG_ATTR(7);
685
686 static struct attribute *cintiq_led_attrs[] = {
687 &dev_attr_status_led0_select.attr,
688 &dev_attr_status_led1_select.attr,
689 NULL
690 };
691
692 static struct attribute_group cintiq_led_attr_group = {
693 .name = "wacom_led",
694 .attrs = cintiq_led_attrs,
695 };
696
697 static struct attribute *intuos4_led_attrs[] = {
698 &dev_attr_status0_luminance.attr,
699 &dev_attr_status1_luminance.attr,
700 &dev_attr_status_led0_select.attr,
701 &dev_attr_buttons_luminance.attr,
702 &dev_attr_button0_rawimg.attr,
703 &dev_attr_button1_rawimg.attr,
704 &dev_attr_button2_rawimg.attr,
705 &dev_attr_button3_rawimg.attr,
706 &dev_attr_button4_rawimg.attr,
707 &dev_attr_button5_rawimg.attr,
708 &dev_attr_button6_rawimg.attr,
709 &dev_attr_button7_rawimg.attr,
710 NULL
711 };
712
713 static struct attribute_group intuos4_led_attr_group = {
714 .name = "wacom_led",
715 .attrs = intuos4_led_attrs,
716 };
717
718 static struct attribute *intuos5_led_attrs[] = {
719 &dev_attr_status0_luminance.attr,
720 &dev_attr_status_led0_select.attr,
721 NULL
722 };
723
724 static struct attribute_group intuos5_led_attr_group = {
725 .name = "wacom_led",
726 .attrs = intuos5_led_attrs,
727 };
728
729 static int wacom_initialize_leds(struct wacom *wacom)
730 {
731 int error;
732
733 /* Initialize default values */
734 switch (wacom->wacom_wac.features.type) {
735 case INTUOS4S:
736 case INTUOS4:
737 case INTUOS4WL:
738 case INTUOS4L:
739 wacom->led.select[0] = 0;
740 wacom->led.select[1] = 0;
741 wacom->led.llv = 10;
742 wacom->led.hlv = 20;
743 wacom->led.img_lum = 10;
744 error = sysfs_create_group(&wacom->hdev->dev.kobj,
745 &intuos4_led_attr_group);
746 break;
747
748 case WACOM_24HD:
749 case WACOM_21UX2:
750 wacom->led.select[0] = 0;
751 wacom->led.select[1] = 0;
752 wacom->led.llv = 0;
753 wacom->led.hlv = 0;
754 wacom->led.img_lum = 0;
755
756 error = sysfs_create_group(&wacom->hdev->dev.kobj,
757 &cintiq_led_attr_group);
758 break;
759
760 case INTUOS5S:
761 case INTUOS5:
762 case INTUOS5L:
763 case INTUOSPS:
764 case INTUOSPM:
765 case INTUOSPL:
766 if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) {
767 wacom->led.select[0] = 0;
768 wacom->led.select[1] = 0;
769 wacom->led.llv = 32;
770 wacom->led.hlv = 0;
771 wacom->led.img_lum = 0;
772
773 error = sysfs_create_group(&wacom->hdev->dev.kobj,
774 &intuos5_led_attr_group);
775 } else
776 return 0;
777 break;
778
779 default:
780 return 0;
781 }
782
783 if (error) {
784 hid_err(wacom->hdev,
785 "cannot create sysfs group err: %d\n", error);
786 return error;
787 }
788 wacom_led_control(wacom);
789 wacom->led_initialized = true;
790
791 return 0;
792 }
793
794 static void wacom_destroy_leds(struct wacom *wacom)
795 {
796 if (!wacom->led_initialized)
797 return;
798
799 wacom->led_initialized = false;
800
801 switch (wacom->wacom_wac.features.type) {
802 case INTUOS4S:
803 case INTUOS4:
804 case INTUOS4WL:
805 case INTUOS4L:
806 sysfs_remove_group(&wacom->hdev->dev.kobj,
807 &intuos4_led_attr_group);
808 break;
809
810 case WACOM_24HD:
811 case WACOM_21UX2:
812 sysfs_remove_group(&wacom->hdev->dev.kobj,
813 &cintiq_led_attr_group);
814 break;
815
816 case INTUOS5S:
817 case INTUOS5:
818 case INTUOS5L:
819 case INTUOSPS:
820 case INTUOSPM:
821 case INTUOSPL:
822 if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN)
823 sysfs_remove_group(&wacom->hdev->dev.kobj,
824 &intuos5_led_attr_group);
825 break;
826 }
827 }
828
829 static enum power_supply_property wacom_battery_props[] = {
830 POWER_SUPPLY_PROP_STATUS,
831 POWER_SUPPLY_PROP_SCOPE,
832 POWER_SUPPLY_PROP_CAPACITY
833 };
834
835 static enum power_supply_property wacom_ac_props[] = {
836 POWER_SUPPLY_PROP_PRESENT,
837 POWER_SUPPLY_PROP_ONLINE,
838 POWER_SUPPLY_PROP_SCOPE,
839 };
840
841 static int wacom_battery_get_property(struct power_supply *psy,
842 enum power_supply_property psp,
843 union power_supply_propval *val)
844 {
845 struct wacom *wacom = container_of(psy, struct wacom, battery);
846 int ret = 0;
847
848 switch (psp) {
849 case POWER_SUPPLY_PROP_SCOPE:
850 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
851 break;
852 case POWER_SUPPLY_PROP_CAPACITY:
853 val->intval =
854 wacom->wacom_wac.battery_capacity;
855 break;
856 case POWER_SUPPLY_PROP_STATUS:
857 if (wacom->wacom_wac.bat_charging)
858 val->intval = POWER_SUPPLY_STATUS_CHARGING;
859 else if (wacom->wacom_wac.battery_capacity == 100 &&
860 wacom->wacom_wac.ps_connected)
861 val->intval = POWER_SUPPLY_STATUS_FULL;
862 else
863 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
864 break;
865 default:
866 ret = -EINVAL;
867 break;
868 }
869
870 return ret;
871 }
872
873 static int wacom_ac_get_property(struct power_supply *psy,
874 enum power_supply_property psp,
875 union power_supply_propval *val)
876 {
877 struct wacom *wacom = container_of(psy, struct wacom, ac);
878 int ret = 0;
879
880 switch (psp) {
881 case POWER_SUPPLY_PROP_PRESENT:
882 /* fall through */
883 case POWER_SUPPLY_PROP_ONLINE:
884 val->intval = wacom->wacom_wac.ps_connected;
885 break;
886 case POWER_SUPPLY_PROP_SCOPE:
887 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
888 break;
889 default:
890 ret = -EINVAL;
891 break;
892 }
893 return ret;
894 }
895
896 static int wacom_initialize_battery(struct wacom *wacom)
897 {
898 static atomic_t battery_no = ATOMIC_INIT(0);
899 int error;
900 unsigned long n;
901
902 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
903 n = atomic_inc_return(&battery_no) - 1;
904
905 wacom->battery.properties = wacom_battery_props;
906 wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
907 wacom->battery.get_property = wacom_battery_get_property;
908 sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
909 wacom->battery.name = wacom->wacom_wac.bat_name;
910 wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
911 wacom->battery.use_for_apm = 0;
912
913 wacom->ac.properties = wacom_ac_props;
914 wacom->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
915 wacom->ac.get_property = wacom_ac_get_property;
916 sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
917 wacom->ac.name = wacom->wacom_wac.ac_name;
918 wacom->ac.type = POWER_SUPPLY_TYPE_MAINS;
919 wacom->ac.use_for_apm = 0;
920
921 error = power_supply_register(&wacom->hdev->dev,
922 &wacom->battery);
923 if (error)
924 return error;
925
926 power_supply_powers(&wacom->battery, &wacom->hdev->dev);
927
928 error = power_supply_register(&wacom->hdev->dev, &wacom->ac);
929 if (error) {
930 power_supply_unregister(&wacom->battery);
931 return error;
932 }
933
934 power_supply_powers(&wacom->ac, &wacom->hdev->dev);
935 }
936
937 return 0;
938 }
939
940 static void wacom_destroy_battery(struct wacom *wacom)
941 {
942 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
943 wacom->battery.dev) {
944 power_supply_unregister(&wacom->battery);
945 wacom->battery.dev = NULL;
946 power_supply_unregister(&wacom->ac);
947 wacom->ac.dev = NULL;
948 }
949 }
950
951 static ssize_t wacom_show_speed(struct device *dev,
952 struct device_attribute
953 *attr, char *buf)
954 {
955 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
956 struct wacom *wacom = hid_get_drvdata(hdev);
957
958 return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
959 }
960
961 static ssize_t wacom_store_speed(struct device *dev,
962 struct device_attribute *attr,
963 const char *buf, size_t count)
964 {
965 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
966 struct wacom *wacom = hid_get_drvdata(hdev);
967 u8 new_speed;
968
969 if (kstrtou8(buf, 0, &new_speed))
970 return -EINVAL;
971
972 if (new_speed != 0 && new_speed != 1)
973 return -EINVAL;
974
975 wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
976
977 return count;
978 }
979
980 static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
981 wacom_show_speed, wacom_store_speed);
982
983 static struct input_dev *wacom_allocate_input(struct wacom *wacom)
984 {
985 struct input_dev *input_dev;
986 struct hid_device *hdev = wacom->hdev;
987 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
988
989 input_dev = input_allocate_device();
990 if (!input_dev)
991 return NULL;
992
993 input_dev->name = wacom_wac->name;
994 input_dev->phys = hdev->phys;
995 input_dev->dev.parent = &hdev->dev;
996 input_dev->open = wacom_open;
997 input_dev->close = wacom_close;
998 input_dev->uniq = hdev->uniq;
999 input_dev->id.bustype = hdev->bus;
1000 input_dev->id.vendor = hdev->vendor;
1001 input_dev->id.product = hdev->product;
1002 input_dev->id.version = hdev->version;
1003 input_set_drvdata(input_dev, wacom);
1004
1005 return input_dev;
1006 }
1007
1008 static void wacom_unregister_inputs(struct wacom *wacom)
1009 {
1010 if (wacom->wacom_wac.input)
1011 input_unregister_device(wacom->wacom_wac.input);
1012 if (wacom->wacom_wac.pad_input)
1013 input_unregister_device(wacom->wacom_wac.pad_input);
1014 wacom->wacom_wac.input = NULL;
1015 wacom->wacom_wac.pad_input = NULL;
1016 }
1017
1018 static int wacom_register_inputs(struct wacom *wacom)
1019 {
1020 struct input_dev *input_dev, *pad_input_dev;
1021 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1022 int error;
1023
1024 input_dev = wacom_allocate_input(wacom);
1025 pad_input_dev = wacom_allocate_input(wacom);
1026 if (!input_dev || !pad_input_dev) {
1027 error = -ENOMEM;
1028 goto fail1;
1029 }
1030
1031 wacom_wac->input = input_dev;
1032 wacom_wac->pad_input = pad_input_dev;
1033 wacom_wac->pad_input->name = wacom_wac->pad_name;
1034
1035 error = wacom_setup_input_capabilities(input_dev, wacom_wac);
1036 if (error)
1037 goto fail2;
1038
1039 error = input_register_device(input_dev);
1040 if (error)
1041 goto fail2;
1042
1043 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
1044 if (error) {
1045 /* no pad in use on this interface */
1046 input_free_device(pad_input_dev);
1047 wacom_wac->pad_input = NULL;
1048 pad_input_dev = NULL;
1049 } else {
1050 error = input_register_device(pad_input_dev);
1051 if (error)
1052 goto fail3;
1053 }
1054
1055 return 0;
1056
1057 fail3:
1058 input_unregister_device(input_dev);
1059 input_dev = NULL;
1060 fail2:
1061 wacom_wac->input = NULL;
1062 wacom_wac->pad_input = NULL;
1063 fail1:
1064 if (input_dev)
1065 input_free_device(input_dev);
1066 if (pad_input_dev)
1067 input_free_device(pad_input_dev);
1068 return error;
1069 }
1070
1071 static void wacom_wireless_work(struct work_struct *work)
1072 {
1073 struct wacom *wacom = container_of(work, struct wacom, work);
1074 struct usb_device *usbdev = wacom->usbdev;
1075 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1076 struct hid_device *hdev1, *hdev2;
1077 struct wacom *wacom1, *wacom2;
1078 struct wacom_wac *wacom_wac1, *wacom_wac2;
1079 int error;
1080
1081 /*
1082 * Regardless if this is a disconnect or a new tablet,
1083 * remove any existing input and battery devices.
1084 */
1085
1086 wacom_destroy_battery(wacom);
1087
1088 /* Stylus interface */
1089 hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
1090 wacom1 = hid_get_drvdata(hdev1);
1091 wacom_wac1 = &(wacom1->wacom_wac);
1092 wacom_unregister_inputs(wacom1);
1093
1094 /* Touch interface */
1095 hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
1096 wacom2 = hid_get_drvdata(hdev2);
1097 wacom_wac2 = &(wacom2->wacom_wac);
1098 wacom_unregister_inputs(wacom2);
1099
1100 if (wacom_wac->pid == 0) {
1101 hid_info(wacom->hdev, "wireless tablet disconnected\n");
1102 wacom_wac1->shared->type = 0;
1103 } else {
1104 const struct hid_device_id *id = wacom_ids;
1105
1106 hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
1107 wacom_wac->pid);
1108
1109 while (id->bus) {
1110 if (id->vendor == USB_VENDOR_ID_WACOM &&
1111 id->product == wacom_wac->pid)
1112 break;
1113 id++;
1114 }
1115
1116 if (!id->bus) {
1117 hid_info(wacom->hdev, "ignoring unknown PID.\n");
1118 return;
1119 }
1120
1121 /* Stylus interface */
1122 wacom_wac1->features =
1123 *((struct wacom_features *)id->driver_data);
1124 wacom_wac1->features.device_type = BTN_TOOL_PEN;
1125 snprintf(wacom_wac1->name, WACOM_NAME_MAX, "%s (WL) Pen",
1126 wacom_wac1->features.name);
1127 snprintf(wacom_wac1->pad_name, WACOM_NAME_MAX, "%s (WL) Pad",
1128 wacom_wac1->features.name);
1129 wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max;
1130 wacom_wac1->shared->type = wacom_wac1->features.type;
1131 error = wacom_register_inputs(wacom1);
1132 if (error)
1133 goto fail;
1134
1135 /* Touch interface */
1136 if (wacom_wac1->features.touch_max ||
1137 wacom_wac1->features.type == INTUOSHT) {
1138 wacom_wac2->features =
1139 *((struct wacom_features *)id->driver_data);
1140 wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
1141 wacom_wac2->features.device_type = BTN_TOOL_FINGER;
1142 wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
1143 if (wacom_wac2->features.touch_max)
1144 snprintf(wacom_wac2->name, WACOM_NAME_MAX,
1145 "%s (WL) Finger",wacom_wac2->features.name);
1146 else
1147 snprintf(wacom_wac2->name, WACOM_NAME_MAX,
1148 "%s (WL) Pad",wacom_wac2->features.name);
1149 snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX,
1150 "%s (WL) Pad", wacom_wac2->features.name);
1151 error = wacom_register_inputs(wacom2);
1152 if (error)
1153 goto fail;
1154
1155 if (wacom_wac1->features.type == INTUOSHT &&
1156 wacom_wac1->features.touch_max)
1157 wacom_wac->shared->touch_input = wacom_wac2->input;
1158 }
1159
1160 error = wacom_initialize_battery(wacom);
1161 if (error)
1162 goto fail;
1163 }
1164
1165 return;
1166
1167 fail:
1168 wacom_unregister_inputs(wacom1);
1169 wacom_unregister_inputs(wacom2);
1170 return;
1171 }
1172
1173 /*
1174 * Not all devices report physical dimensions from HID.
1175 * Compute the default from hardcoded logical dimension
1176 * and resolution before driver overwrites them.
1177 */
1178 static void wacom_set_default_phy(struct wacom_features *features)
1179 {
1180 if (features->x_resolution) {
1181 features->x_phy = (features->x_max * 100) /
1182 features->x_resolution;
1183 features->y_phy = (features->y_max * 100) /
1184 features->y_resolution;
1185 }
1186 }
1187
1188 static void wacom_calculate_res(struct wacom_features *features)
1189 {
1190 features->x_resolution = wacom_calc_hid_res(features->x_max,
1191 features->x_phy,
1192 features->unit,
1193 features->unitExpo);
1194 features->y_resolution = wacom_calc_hid_res(features->y_max,
1195 features->y_phy,
1196 features->unit,
1197 features->unitExpo);
1198 }
1199
1200 static int wacom_hid_report_len(struct hid_report *report)
1201 {
1202 /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */
1203 return ((report->size - 1) >> 3) + 1 + (report->id > 0);
1204 }
1205
1206 static size_t wacom_compute_pktlen(struct hid_device *hdev)
1207 {
1208 struct hid_report_enum *report_enum;
1209 struct hid_report *report;
1210 size_t size = 0;
1211
1212 report_enum = hdev->report_enum + HID_INPUT_REPORT;
1213
1214 list_for_each_entry(report, &report_enum->report_list, list) {
1215 size_t report_size = wacom_hid_report_len(report);
1216 if (report_size > size)
1217 size = report_size;
1218 }
1219
1220 return size;
1221 }
1222
1223 static int wacom_probe(struct hid_device *hdev,
1224 const struct hid_device_id *id)
1225 {
1226 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
1227 struct usb_device *dev = interface_to_usbdev(intf);
1228 struct wacom *wacom;
1229 struct wacom_wac *wacom_wac;
1230 struct wacom_features *features;
1231 int error;
1232
1233 if (!id->driver_data)
1234 return -EINVAL;
1235
1236 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
1237 if (!wacom)
1238 return -ENOMEM;
1239
1240 hid_set_drvdata(hdev, wacom);
1241 wacom->hdev = hdev;
1242
1243 /* ask for the report descriptor to be loaded by HID */
1244 error = hid_parse(hdev);
1245 if (error) {
1246 hid_err(hdev, "parse failed\n");
1247 goto fail1;
1248 }
1249
1250 wacom_wac = &wacom->wacom_wac;
1251 wacom_wac->features = *((struct wacom_features *)id->driver_data);
1252 features = &wacom_wac->features;
1253 features->pktlen = wacom_compute_pktlen(hdev);
1254 if (features->pktlen > WACOM_PKGLEN_MAX) {
1255 error = -EINVAL;
1256 goto fail1;
1257 }
1258
1259 if (features->check_for_hid_type && features->hid_type != hdev->type) {
1260 error = -ENODEV;
1261 goto fail1;
1262 }
1263
1264 wacom->usbdev = dev;
1265 wacom->intf = intf;
1266 mutex_init(&wacom->lock);
1267 INIT_WORK(&wacom->work, wacom_wireless_work);
1268
1269 /* set the default size in case we do not get them from hid */
1270 wacom_set_default_phy(features);
1271
1272 /* Retrieve the physical and logical size for touch devices */
1273 wacom_retrieve_hid_descriptor(hdev, features);
1274
1275 /*
1276 * Intuos5 has no useful data about its touch interface in its
1277 * HID descriptor. If this is the touch interface (PacketSize
1278 * of WACOM_PKGLEN_BBTOUCH3), override the table values.
1279 */
1280 if (features->type >= INTUOS5S && features->type <= INTUOSHT) {
1281 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
1282 features->device_type = BTN_TOOL_FINGER;
1283
1284 features->x_max = 4096;
1285 features->y_max = 4096;
1286 } else {
1287 features->device_type = BTN_TOOL_PEN;
1288 }
1289 }
1290
1291 /*
1292 * Same thing for Bamboo 3rd gen.
1293 */
1294 if ((features->type == BAMBOO_PT) &&
1295 (features->pktlen == WACOM_PKGLEN_BBTOUCH3) &&
1296 (features->device_type == BTN_TOOL_PEN)) {
1297 features->device_type = BTN_TOOL_FINGER;
1298
1299 features->x_max = 4096;
1300 features->y_max = 4096;
1301 }
1302
1303 if (hdev->bus == BUS_BLUETOOTH)
1304 features->quirks |= WACOM_QUIRK_BATTERY;
1305
1306 wacom_setup_device_quirks(features);
1307
1308 /* set unit to "100th of a mm" for devices not reported by HID */
1309 if (!features->unit) {
1310 features->unit = 0x11;
1311 features->unitExpo = -3;
1312 }
1313 wacom_calculate_res(features);
1314
1315 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
1316 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1317 "%s Pad", features->name);
1318
1319 if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
1320 /* Append the device type to the name */
1321 if (features->device_type != BTN_TOOL_FINGER)
1322 strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
1323 else if (features->touch_max)
1324 strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
1325 else
1326 strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
1327
1328 error = wacom_add_shared_data(hdev);
1329 if (error)
1330 goto fail1;
1331 }
1332
1333 error = wacom_initialize_leds(wacom);
1334 if (error)
1335 goto fail2;
1336
1337 if (!(features->quirks & WACOM_QUIRK_MONITOR) &&
1338 (features->quirks & WACOM_QUIRK_BATTERY)) {
1339 error = wacom_initialize_battery(wacom);
1340 if (error)
1341 goto fail3;
1342 }
1343
1344 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
1345 error = wacom_register_inputs(wacom);
1346 if (error)
1347 goto fail4;
1348 }
1349
1350 if (hdev->bus == BUS_BLUETOOTH) {
1351 error = device_create_file(&hdev->dev, &dev_attr_speed);
1352 if (error)
1353 hid_warn(hdev,
1354 "can't create sysfs speed attribute err: %d\n",
1355 error);
1356 }
1357
1358 /* Note that if query fails it is not a hard failure */
1359 wacom_query_tablet_data(hdev, features);
1360
1361 /* Regular HID work starts now */
1362 error = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
1363 if (error) {
1364 hid_err(hdev, "hw start failed\n");
1365 goto fail5;
1366 }
1367
1368 if (features->quirks & WACOM_QUIRK_MONITOR)
1369 error = hid_hw_open(hdev);
1370
1371 if (wacom_wac->features.type == INTUOSHT && wacom_wac->features.touch_max) {
1372 if (wacom_wac->features.device_type == BTN_TOOL_FINGER)
1373 wacom_wac->shared->touch_input = wacom_wac->input;
1374 }
1375
1376 return 0;
1377
1378 fail5: if (hdev->bus == BUS_BLUETOOTH)
1379 device_remove_file(&hdev->dev, &dev_attr_speed);
1380 wacom_unregister_inputs(wacom);
1381 fail4: wacom_destroy_battery(wacom);
1382 fail3: wacom_destroy_leds(wacom);
1383 fail2: wacom_remove_shared_data(wacom_wac);
1384 fail1: kfree(wacom);
1385 hid_set_drvdata(hdev, NULL);
1386 return error;
1387 }
1388
1389 static void wacom_remove(struct hid_device *hdev)
1390 {
1391 struct wacom *wacom = hid_get_drvdata(hdev);
1392
1393 hid_hw_stop(hdev);
1394
1395 cancel_work_sync(&wacom->work);
1396 wacom_unregister_inputs(wacom);
1397 if (hdev->bus == BUS_BLUETOOTH)
1398 device_remove_file(&hdev->dev, &dev_attr_speed);
1399 wacom_destroy_battery(wacom);
1400 wacom_destroy_leds(wacom);
1401 wacom_remove_shared_data(&wacom->wacom_wac);
1402
1403 hid_set_drvdata(hdev, NULL);
1404 kfree(wacom);
1405 }
1406
1407 static int wacom_resume(struct hid_device *hdev)
1408 {
1409 struct wacom *wacom = hid_get_drvdata(hdev);
1410 struct wacom_features *features = &wacom->wacom_wac.features;
1411
1412 mutex_lock(&wacom->lock);
1413
1414 /* switch to wacom mode first */
1415 wacom_query_tablet_data(hdev, features);
1416 wacom_led_control(wacom);
1417
1418 mutex_unlock(&wacom->lock);
1419
1420 return 0;
1421 }
1422
1423 static int wacom_reset_resume(struct hid_device *hdev)
1424 {
1425 return wacom_resume(hdev);
1426 }
1427
1428 static struct hid_driver wacom_driver = {
1429 .name = "wacom",
1430 .id_table = wacom_ids,
1431 .probe = wacom_probe,
1432 .remove = wacom_remove,
1433 #ifdef CONFIG_PM
1434 .resume = wacom_resume,
1435 .reset_resume = wacom_reset_resume,
1436 #endif
1437 .raw_event = wacom_raw_event,
1438 };
1439 module_hid_driver(wacom_driver);
This page took 0.082154 seconds and 6 git commands to generate.