2 * drivers/input/tablet/wacom_sys.c
4 * USB Wacom tablet support - system specific code
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include "wacom_wac.h"
16 #include <linux/input/mt.h>
18 #define WAC_MSG_RETRIES 5
20 #define WAC_CMD_WL_LED_CONTROL 0x03
21 #define WAC_CMD_LED_CONTROL 0x20
22 #define WAC_CMD_ICON_START 0x21
23 #define WAC_CMD_ICON_XFER 0x23
24 #define WAC_CMD_ICON_BT_XFER 0x26
25 #define WAC_CMD_RETRIES 10
26 #define WAC_CMD_DELETE_PAIRING 0x20
27 #define WAC_CMD_UNPAIR_ALL 0xFF
28 #define WAC_REMOTE_SERIAL_MAX_STRLEN 9
30 #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
31 #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
32 #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP)
34 static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf,
35 size_t size, unsigned int retries)
40 retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
42 } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
45 hid_err(hdev, "wacom_get_report: ran out of retries "
46 "(last error = %d)\n", retval);
51 static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf,
52 size_t size, unsigned int retries)
57 retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
59 } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
62 hid_err(hdev, "wacom_set_report: ran out of retries "
63 "(last error = %d)\n", retval);
68 static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
69 u8 *raw_data, int size)
71 struct wacom *wacom = hid_get_drvdata(hdev);
73 if (size > WACOM_PKGLEN_MAX)
76 memcpy(wacom->wacom_wac.data, raw_data, size);
78 wacom_wac_irq(&wacom->wacom_wac, size);
83 static int wacom_open(struct input_dev *dev)
85 struct wacom *wacom = input_get_drvdata(dev);
87 return hid_hw_open(wacom->hdev);
90 static void wacom_close(struct input_dev *dev)
92 struct wacom *wacom = input_get_drvdata(dev);
94 hid_hw_close(wacom->hdev);
98 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
100 static int wacom_calc_hid_res(int logical_extents, int physical_extents,
101 unsigned unit, int exponent)
103 struct hid_field field = {
104 .logical_maximum = logical_extents,
105 .physical_maximum = physical_extents,
107 .unit_exponent = exponent,
110 return hidinput_calc_abs_res(&field, ABS_X);
113 static void wacom_feature_mapping(struct hid_device *hdev,
114 struct hid_field *field, struct hid_usage *usage)
116 struct wacom *wacom = hid_get_drvdata(hdev);
117 struct wacom_features *features = &wacom->wacom_wac.features;
118 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
122 switch (usage->hid) {
123 case HID_DG_CONTACTMAX:
124 /* leave touch_max as is if predefined */
125 if (!features->touch_max) {
127 data = kzalloc(2, GFP_KERNEL);
130 data[0] = field->report->id;
131 ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
132 data, 2, WAC_CMD_RETRIES);
134 features->touch_max = data[1];
136 features->touch_max = 16;
137 hid_warn(hdev, "wacom_feature_mapping: "
138 "could not get HID_DG_CONTACTMAX, "
139 "defaulting to %d\n",
140 features->touch_max);
145 case HID_DG_INPUTMODE:
146 /* Ignore if value index is out of bounds. */
147 if (usage->usage_index >= field->report_count) {
148 dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
152 hid_data->inputmode = field->report->id;
153 hid_data->inputmode_index = usage->usage_index;
156 case HID_UP_DIGITIZER:
157 if (field->report->id == 0x0B &&
158 (field->application == WACOM_G9_DIGITIZER ||
159 field->application == WACOM_G11_DIGITIZER)) {
160 wacom->wacom_wac.mode_report = field->report->id;
161 wacom->wacom_wac.mode_value = 0;
167 if (field->report->id == 0x03 &&
168 (field->application == WACOM_G9_TOUCHSCREEN ||
169 field->application == WACOM_G11_TOUCHSCREEN)) {
170 wacom->wacom_wac.mode_report = field->report->id;
171 wacom->wacom_wac.mode_value = 0;
178 * Interface Descriptor of wacom devices can be incomplete and
179 * inconsistent so wacom_features table is used to store stylus
180 * device's packet lengths, various maximum values, and tablet
181 * resolution based on product ID's.
183 * For devices that contain 2 interfaces, wacom_features table is
184 * inaccurate for the touch interface. Since the Interface Descriptor
185 * for touch interfaces has pretty complete data, this function exists
186 * to query tablet for this missing information instead of hard coding in
187 * an additional table.
189 * A typical Interface Descriptor for a stylus will contain a
190 * boot mouse application collection that is not of interest and this
191 * function will ignore it.
193 * It also contains a digitizer application collection that also is not
194 * of interest since any information it contains would be duplicate
195 * of what is in wacom_features. Usually it defines a report of an array
196 * of bytes that could be used as max length of the stylus packet returned.
197 * If it happens to define a Digitizer-Stylus Physical Collection then
198 * the X and Y logical values contain valid data but it is ignored.
200 * A typical Interface Descriptor for a touch interface will contain a
201 * Digitizer-Finger Physical Collection which will define both logical
202 * X/Y maximum as well as the physical size of tablet. Since touch
203 * interfaces haven't supported pressure or distance, this is enough
204 * information to override invalid values in the wacom_features table.
206 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
207 * data. We deal with them after returning from this function.
209 static void wacom_usage_mapping(struct hid_device *hdev,
210 struct hid_field *field, struct hid_usage *usage)
212 struct wacom *wacom = hid_get_drvdata(hdev);
213 struct wacom_features *features = &wacom->wacom_wac.features;
214 bool finger = WACOM_FINGER_FIELD(field);
215 bool pen = WACOM_PEN_FIELD(field);
218 * Requiring Stylus Usage will ignore boot mouse
219 * X/Y values and some cases of invalid Digitizer X/Y
220 * values commonly reported.
223 features->device_type |= WACOM_DEVICETYPE_PEN;
225 features->device_type |= WACOM_DEVICETYPE_TOUCH;
230 * Bamboo models do not support HID_DG_CONTACTMAX.
231 * And, Bamboo Pen only descriptor contains touch.
233 if (features->type > BAMBOO_PT) {
234 /* ISDv4 touch devices at least supports one touch point */
235 if (finger && !features->touch_max)
236 features->touch_max = 1;
239 switch (usage->hid) {
241 features->x_max = field->logical_maximum;
243 features->x_phy = field->physical_maximum;
244 if ((features->type != BAMBOO_PT) &&
245 (features->type != BAMBOO_TOUCH)) {
246 features->unit = field->unit;
247 features->unitExpo = field->unit_exponent;
252 features->y_max = field->logical_maximum;
254 features->y_phy = field->physical_maximum;
255 if ((features->type != BAMBOO_PT) &&
256 (features->type != BAMBOO_TOUCH)) {
257 features->unit = field->unit;
258 features->unitExpo = field->unit_exponent;
262 case HID_DG_TIPPRESSURE:
264 features->pressure_max = field->logical_maximum;
268 if (features->type == HID_GENERIC)
269 wacom_wac_usage_mapping(hdev, field, usage);
272 static void wacom_post_parse_hid(struct hid_device *hdev,
273 struct wacom_features *features)
275 struct wacom *wacom = hid_get_drvdata(hdev);
276 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
278 if (features->type == HID_GENERIC) {
279 /* Any last-minute generic device setup */
280 if (features->touch_max > 1) {
281 input_mt_init_slots(wacom_wac->touch_input, wacom_wac->features.touch_max,
287 static void wacom_parse_hid(struct hid_device *hdev,
288 struct wacom_features *features)
290 struct hid_report_enum *rep_enum;
291 struct hid_report *hreport;
294 /* check features first */
295 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
296 list_for_each_entry(hreport, &rep_enum->report_list, list) {
297 for (i = 0; i < hreport->maxfield; i++) {
298 /* Ignore if report count is out of bounds. */
299 if (hreport->field[i]->report_count < 1)
302 for (j = 0; j < hreport->field[i]->maxusage; j++) {
303 wacom_feature_mapping(hdev, hreport->field[i],
304 hreport->field[i]->usage + j);
309 /* now check the input usages */
310 rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
311 list_for_each_entry(hreport, &rep_enum->report_list, list) {
313 if (!hreport->maxfield)
316 for (i = 0; i < hreport->maxfield; i++)
317 for (j = 0; j < hreport->field[i]->maxusage; j++)
318 wacom_usage_mapping(hdev, hreport->field[i],
319 hreport->field[i]->usage + j);
322 wacom_post_parse_hid(hdev, features);
325 static int wacom_hid_set_device_mode(struct hid_device *hdev)
327 struct wacom *wacom = hid_get_drvdata(hdev);
328 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
329 struct hid_report *r;
330 struct hid_report_enum *re;
332 if (hid_data->inputmode < 0)
335 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
336 r = re->report_id_hash[hid_data->inputmode];
338 r->field[0]->value[hid_data->inputmode_index] = 2;
339 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
344 static int wacom_set_device_mode(struct hid_device *hdev,
345 struct wacom_wac *wacom_wac)
348 struct hid_report *r;
349 struct hid_report_enum *re;
351 int error = -ENOMEM, limit = 0;
353 if (wacom_wac->mode_report < 0)
356 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
357 r = re->report_id_hash[wacom_wac->mode_report];
361 rep_data = hid_alloc_report_buf(r, GFP_KERNEL);
365 length = hid_report_len(r);
368 rep_data[0] = wacom_wac->mode_report;
369 rep_data[1] = wacom_wac->mode_value;
371 error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data,
374 error = wacom_get_report(hdev, HID_FEATURE_REPORT,
375 rep_data, length, 1);
376 } while (error >= 0 &&
377 rep_data[1] != wacom_wac->mode_report &&
378 limit++ < WAC_MSG_RETRIES);
382 return error < 0 ? error : 0;
385 static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
386 struct wacom_features *features)
388 struct wacom *wacom = hid_get_drvdata(hdev);
392 switch (features->type) {
396 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
400 rep_data[0] = speed == 0 ? 0x05 : 0x06;
403 ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
407 wacom->wacom_wac.bt_high_speed = speed;
413 * Note that if the raw queries fail, it's not a hard failure
414 * and it is safe to continue
416 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
421 wacom->wacom_wac.bt_features &= ~0x20;
423 wacom->wacom_wac.bt_features |= 0x20;
426 rep_data[1] = wacom->wacom_wac.bt_features;
428 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
431 wacom->wacom_wac.bt_high_speed = speed;
439 * Switch the tablet into its most-capable mode. Wacom tablets are
440 * typically configured to power-up in a mode which sends mouse-like
441 * reports to the OS. To get absolute position, pressure data, etc.
442 * from the tablet, it is necessary to switch the tablet out of this
443 * mode and into one which sends the full range of tablet data.
445 static int wacom_query_tablet_data(struct hid_device *hdev,
446 struct wacom_features *features)
448 struct wacom *wacom = hid_get_drvdata(hdev);
449 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
451 if (hdev->bus == BUS_BLUETOOTH)
452 return wacom_bt_query_tablet_data(hdev, 1, features);
454 if (features->type != HID_GENERIC) {
455 if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
456 if (features->type > TABLETPC) {
457 /* MT Tablet PC touch */
458 wacom_wac->mode_report = 3;
459 wacom_wac->mode_value = 4;
460 } else if (features->type == WACOM_24HDT) {
461 wacom_wac->mode_report = 18;
462 wacom_wac->mode_value = 2;
463 } else if (features->type == WACOM_27QHDT) {
464 wacom_wac->mode_report = 131;
465 wacom_wac->mode_value = 2;
466 } else if (features->type == BAMBOO_PAD) {
467 wacom_wac->mode_report = 2;
468 wacom_wac->mode_value = 2;
470 } else if (features->device_type & WACOM_DEVICETYPE_PEN) {
471 if (features->type <= BAMBOO_PT) {
472 wacom_wac->mode_report = 2;
473 wacom_wac->mode_value = 2;
478 wacom_set_device_mode(hdev, wacom_wac);
480 if (features->type == HID_GENERIC)
481 return wacom_hid_set_device_mode(hdev);
486 static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
487 struct wacom_features *features)
489 struct wacom *wacom = hid_get_drvdata(hdev);
490 struct usb_interface *intf = wacom->intf;
492 /* default features */
493 features->x_fuzz = 4;
494 features->y_fuzz = 4;
495 features->pressure_fuzz = 0;
496 features->distance_fuzz = 0;
499 * The wireless device HID is basic and layout conflicts with
500 * other tablets (monitor and touch interface can look like pen).
501 * Skip the query for this type and modify defaults based on
504 if (features->type == WIRELESS) {
505 if (intf->cur_altsetting->desc.bInterfaceNumber == 0)
506 features->device_type = WACOM_DEVICETYPE_WL_MONITOR;
508 features->device_type = WACOM_DEVICETYPE_NONE;
512 wacom_parse_hid(hdev, features);
515 struct wacom_hdev_data {
516 struct list_head list;
518 struct hid_device *dev;
519 struct wacom_shared shared;
522 static LIST_HEAD(wacom_udev_list);
523 static DEFINE_MUTEX(wacom_udev_list_lock);
525 static bool wacom_are_sibling(struct hid_device *hdev,
526 struct hid_device *sibling)
528 struct wacom *wacom = hid_get_drvdata(hdev);
529 struct wacom_features *features = &wacom->wacom_wac.features;
530 int vid = features->oVid;
531 int pid = features->oPid;
534 if (vid == 0 && pid == 0) {
539 if (vid != sibling->vendor || pid != sibling->product)
542 /* Compare the physical path. */
543 n1 = strrchr(hdev->phys, '.') - hdev->phys;
544 n2 = strrchr(sibling->phys, '.') - sibling->phys;
545 if (n1 != n2 || n1 <= 0 || n2 <= 0)
548 return !strncmp(hdev->phys, sibling->phys, n1);
551 static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
553 struct wacom_hdev_data *data;
555 list_for_each_entry(data, &wacom_udev_list, list) {
556 if (wacom_are_sibling(hdev, data->dev)) {
557 kref_get(&data->kref);
565 static int wacom_add_shared_data(struct hid_device *hdev)
567 struct wacom *wacom = hid_get_drvdata(hdev);
568 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
569 struct wacom_hdev_data *data;
572 mutex_lock(&wacom_udev_list_lock);
574 data = wacom_get_hdev_data(hdev);
576 data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
582 kref_init(&data->kref);
584 list_add_tail(&data->list, &wacom_udev_list);
587 wacom_wac->shared = &data->shared;
589 if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
590 wacom_wac->shared->touch = hdev;
591 else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
592 wacom_wac->shared->pen = hdev;
595 mutex_unlock(&wacom_udev_list_lock);
599 static void wacom_release_shared_data(struct kref *kref)
601 struct wacom_hdev_data *data =
602 container_of(kref, struct wacom_hdev_data, kref);
604 mutex_lock(&wacom_udev_list_lock);
605 list_del(&data->list);
606 mutex_unlock(&wacom_udev_list_lock);
611 static void wacom_remove_shared_data(struct wacom *wacom)
613 struct wacom_hdev_data *data;
614 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
616 if (wacom_wac->shared) {
617 data = container_of(wacom_wac->shared, struct wacom_hdev_data,
620 if (wacom_wac->shared->touch == wacom->hdev)
621 wacom_wac->shared->touch = NULL;
622 else if (wacom_wac->shared->pen == wacom->hdev)
623 wacom_wac->shared->pen = NULL;
625 kref_put(&data->kref, wacom_release_shared_data);
626 wacom_wac->shared = NULL;
630 static int wacom_led_control(struct wacom *wacom)
634 unsigned char report_id = WAC_CMD_LED_CONTROL;
637 if (wacom->wacom_wac.pid) { /* wireless connected */
638 report_id = WAC_CMD_WL_LED_CONTROL;
641 buf = kzalloc(buf_size, GFP_KERNEL);
645 if (wacom->wacom_wac.features.type >= INTUOS5S &&
646 wacom->wacom_wac.features.type <= INTUOSPL) {
648 * Touch Ring and crop mark LED luminance may take on
649 * one of four values:
650 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
652 int ring_led = wacom->led.select[0] & 0x03;
653 int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
655 unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
658 if (wacom->wacom_wac.pid) {
659 wacom_get_report(wacom->hdev, HID_FEATURE_REPORT,
660 buf, buf_size, WAC_CMD_RETRIES);
667 int led = wacom->led.select[0] | 0x4;
669 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
670 wacom->wacom_wac.features.type == WACOM_24HD)
671 led |= (wacom->led.select[1] << 4) | 0x40;
675 buf[2] = wacom->led.llv;
676 buf[3] = wacom->led.hlv;
677 buf[4] = wacom->led.img_lum;
680 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size,
687 static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
688 const unsigned len, const void *img)
692 const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
694 buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
698 /* Send 'start' command */
699 buf[0] = WAC_CMD_ICON_START;
701 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
707 buf[1] = button_id & 0x07;
708 for (i = 0; i < 4; i++) {
710 memcpy(buf + 3, img + i * chunk_len, chunk_len);
712 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
713 buf, chunk_len + 3, WAC_CMD_RETRIES);
719 buf[0] = WAC_CMD_ICON_START;
721 wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
729 static ssize_t wacom_led_select_store(struct device *dev, int set_id,
730 const char *buf, size_t count)
732 struct hid_device *hdev = to_hid_device(dev);
733 struct wacom *wacom = hid_get_drvdata(hdev);
737 err = kstrtouint(buf, 10, &id);
741 mutex_lock(&wacom->lock);
743 wacom->led.select[set_id] = id & 0x3;
744 err = wacom_led_control(wacom);
746 mutex_unlock(&wacom->lock);
748 return err < 0 ? err : count;
751 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
752 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
753 struct device_attribute *attr, const char *buf, size_t count) \
755 return wacom_led_select_store(dev, SET_ID, buf, count); \
757 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
758 struct device_attribute *attr, char *buf) \
760 struct hid_device *hdev = to_hid_device(dev);\
761 struct wacom *wacom = hid_get_drvdata(hdev); \
762 return scnprintf(buf, PAGE_SIZE, "%d\n", \
763 wacom->led.select[SET_ID]); \
765 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
766 wacom_led##SET_ID##_select_show, \
767 wacom_led##SET_ID##_select_store)
769 DEVICE_LED_SELECT_ATTR(0);
770 DEVICE_LED_SELECT_ATTR(1);
772 static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
773 const char *buf, size_t count)
778 err = kstrtouint(buf, 10, &value);
782 mutex_lock(&wacom->lock);
784 *dest = value & 0x7f;
785 err = wacom_led_control(wacom);
787 mutex_unlock(&wacom->lock);
789 return err < 0 ? err : count;
792 #define DEVICE_LUMINANCE_ATTR(name, field) \
793 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
794 struct device_attribute *attr, const char *buf, size_t count) \
796 struct hid_device *hdev = to_hid_device(dev);\
797 struct wacom *wacom = hid_get_drvdata(hdev); \
799 return wacom_luminance_store(wacom, &wacom->led.field, \
802 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
803 struct device_attribute *attr, char *buf) \
805 struct wacom *wacom = dev_get_drvdata(dev); \
806 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
808 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
809 wacom_##name##_luminance_show, \
810 wacom_##name##_luminance_store)
812 DEVICE_LUMINANCE_ATTR(status0, llv);
813 DEVICE_LUMINANCE_ATTR(status1, hlv);
814 DEVICE_LUMINANCE_ATTR(buttons, img_lum);
816 static ssize_t wacom_button_image_store(struct device *dev, int button_id,
817 const char *buf, size_t count)
819 struct hid_device *hdev = to_hid_device(dev);
820 struct wacom *wacom = hid_get_drvdata(hdev);
825 if (hdev->bus == BUS_BLUETOOTH) {
827 xfer_id = WAC_CMD_ICON_BT_XFER;
830 xfer_id = WAC_CMD_ICON_XFER;
836 mutex_lock(&wacom->lock);
838 err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
840 mutex_unlock(&wacom->lock);
842 return err < 0 ? err : count;
845 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
846 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
847 struct device_attribute *attr, const char *buf, size_t count) \
849 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
851 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
852 NULL, wacom_btnimg##BUTTON_ID##_store)
854 DEVICE_BTNIMG_ATTR(0);
855 DEVICE_BTNIMG_ATTR(1);
856 DEVICE_BTNIMG_ATTR(2);
857 DEVICE_BTNIMG_ATTR(3);
858 DEVICE_BTNIMG_ATTR(4);
859 DEVICE_BTNIMG_ATTR(5);
860 DEVICE_BTNIMG_ATTR(6);
861 DEVICE_BTNIMG_ATTR(7);
863 static struct attribute *cintiq_led_attrs[] = {
864 &dev_attr_status_led0_select.attr,
865 &dev_attr_status_led1_select.attr,
869 static struct attribute_group cintiq_led_attr_group = {
871 .attrs = cintiq_led_attrs,
874 static struct attribute *intuos4_led_attrs[] = {
875 &dev_attr_status0_luminance.attr,
876 &dev_attr_status1_luminance.attr,
877 &dev_attr_status_led0_select.attr,
878 &dev_attr_buttons_luminance.attr,
879 &dev_attr_button0_rawimg.attr,
880 &dev_attr_button1_rawimg.attr,
881 &dev_attr_button2_rawimg.attr,
882 &dev_attr_button3_rawimg.attr,
883 &dev_attr_button4_rawimg.attr,
884 &dev_attr_button5_rawimg.attr,
885 &dev_attr_button6_rawimg.attr,
886 &dev_attr_button7_rawimg.attr,
890 static struct attribute_group intuos4_led_attr_group = {
892 .attrs = intuos4_led_attrs,
895 static struct attribute *intuos5_led_attrs[] = {
896 &dev_attr_status0_luminance.attr,
897 &dev_attr_status_led0_select.attr,
901 static struct attribute_group intuos5_led_attr_group = {
903 .attrs = intuos5_led_attrs,
906 static int wacom_initialize_leds(struct wacom *wacom)
910 if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
913 /* Initialize default values */
914 switch (wacom->wacom_wac.features.type) {
919 wacom->led.select[0] = 0;
920 wacom->led.select[1] = 0;
923 wacom->led.img_lum = 10;
924 error = sysfs_create_group(&wacom->hdev->dev.kobj,
925 &intuos4_led_attr_group);
930 wacom->led.select[0] = 0;
931 wacom->led.select[1] = 0;
934 wacom->led.img_lum = 0;
936 error = sysfs_create_group(&wacom->hdev->dev.kobj,
937 &cintiq_led_attr_group);
946 wacom->led.select[0] = 0;
947 wacom->led.select[1] = 0;
950 wacom->led.img_lum = 0;
952 error = sysfs_create_group(&wacom->hdev->dev.kobj,
953 &intuos5_led_attr_group);
962 "cannot create sysfs group err: %d\n", error);
965 wacom_led_control(wacom);
966 wacom->led_initialized = true;
971 static void wacom_destroy_leds(struct wacom *wacom)
973 if (!wacom->led_initialized)
976 if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
979 wacom->led_initialized = false;
981 switch (wacom->wacom_wac.features.type) {
986 sysfs_remove_group(&wacom->hdev->dev.kobj,
987 &intuos4_led_attr_group);
992 sysfs_remove_group(&wacom->hdev->dev.kobj,
993 &cintiq_led_attr_group);
1002 sysfs_remove_group(&wacom->hdev->dev.kobj,
1003 &intuos5_led_attr_group);
1008 static enum power_supply_property wacom_battery_props[] = {
1009 POWER_SUPPLY_PROP_PRESENT,
1010 POWER_SUPPLY_PROP_STATUS,
1011 POWER_SUPPLY_PROP_SCOPE,
1012 POWER_SUPPLY_PROP_CAPACITY
1015 static enum power_supply_property wacom_ac_props[] = {
1016 POWER_SUPPLY_PROP_PRESENT,
1017 POWER_SUPPLY_PROP_ONLINE,
1018 POWER_SUPPLY_PROP_SCOPE,
1021 static int wacom_battery_get_property(struct power_supply *psy,
1022 enum power_supply_property psp,
1023 union power_supply_propval *val)
1025 struct wacom *wacom = power_supply_get_drvdata(psy);
1029 case POWER_SUPPLY_PROP_PRESENT:
1030 val->intval = wacom->wacom_wac.bat_connected;
1032 case POWER_SUPPLY_PROP_SCOPE:
1033 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1035 case POWER_SUPPLY_PROP_CAPACITY:
1037 wacom->wacom_wac.battery_capacity;
1039 case POWER_SUPPLY_PROP_STATUS:
1040 if (wacom->wacom_wac.bat_charging)
1041 val->intval = POWER_SUPPLY_STATUS_CHARGING;
1042 else if (wacom->wacom_wac.battery_capacity == 100 &&
1043 wacom->wacom_wac.ps_connected)
1044 val->intval = POWER_SUPPLY_STATUS_FULL;
1045 else if (wacom->wacom_wac.ps_connected)
1046 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
1048 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
1058 static int wacom_ac_get_property(struct power_supply *psy,
1059 enum power_supply_property psp,
1060 union power_supply_propval *val)
1062 struct wacom *wacom = power_supply_get_drvdata(psy);
1066 case POWER_SUPPLY_PROP_PRESENT:
1068 case POWER_SUPPLY_PROP_ONLINE:
1069 val->intval = wacom->wacom_wac.ps_connected;
1071 case POWER_SUPPLY_PROP_SCOPE:
1072 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1081 static int wacom_initialize_battery(struct wacom *wacom)
1083 static atomic_t battery_no = ATOMIC_INIT(0);
1084 struct power_supply_config psy_cfg = { .drv_data = wacom, };
1087 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
1088 struct power_supply_desc *bat_desc = &wacom->battery_desc;
1089 struct power_supply_desc *ac_desc = &wacom->ac_desc;
1090 n = atomic_inc_return(&battery_no) - 1;
1092 bat_desc->properties = wacom_battery_props;
1093 bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
1094 bat_desc->get_property = wacom_battery_get_property;
1095 sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
1096 bat_desc->name = wacom->wacom_wac.bat_name;
1097 bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;
1098 bat_desc->use_for_apm = 0;
1100 ac_desc->properties = wacom_ac_props;
1101 ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props);
1102 ac_desc->get_property = wacom_ac_get_property;
1103 sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
1104 ac_desc->name = wacom->wacom_wac.ac_name;
1105 ac_desc->type = POWER_SUPPLY_TYPE_MAINS;
1106 ac_desc->use_for_apm = 0;
1108 wacom->battery = power_supply_register(&wacom->hdev->dev,
1109 &wacom->battery_desc, &psy_cfg);
1110 if (IS_ERR(wacom->battery))
1111 return PTR_ERR(wacom->battery);
1113 power_supply_powers(wacom->battery, &wacom->hdev->dev);
1115 wacom->ac = power_supply_register(&wacom->hdev->dev,
1118 if (IS_ERR(wacom->ac)) {
1119 power_supply_unregister(wacom->battery);
1120 return PTR_ERR(wacom->ac);
1123 power_supply_powers(wacom->ac, &wacom->hdev->dev);
1129 static void wacom_destroy_battery(struct wacom *wacom)
1131 if (wacom->battery) {
1132 power_supply_unregister(wacom->battery);
1133 wacom->battery = NULL;
1134 power_supply_unregister(wacom->ac);
1139 static ssize_t wacom_show_speed(struct device *dev,
1140 struct device_attribute
1143 struct hid_device *hdev = to_hid_device(dev);
1144 struct wacom *wacom = hid_get_drvdata(hdev);
1146 return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
1149 static ssize_t wacom_store_speed(struct device *dev,
1150 struct device_attribute *attr,
1151 const char *buf, size_t count)
1153 struct hid_device *hdev = to_hid_device(dev);
1154 struct wacom *wacom = hid_get_drvdata(hdev);
1157 if (kstrtou8(buf, 0, &new_speed))
1160 if (new_speed != 0 && new_speed != 1)
1163 wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
1168 static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM,
1169 wacom_show_speed, wacom_store_speed);
1172 static ssize_t wacom_show_remote_mode(struct kobject *kobj,
1173 struct kobj_attribute *kattr,
1174 char *buf, int index)
1176 struct device *dev = kobj_to_dev(kobj->parent);
1177 struct hid_device *hdev = to_hid_device(dev);
1178 struct wacom *wacom = hid_get_drvdata(hdev);
1181 mode = wacom->led.select[index];
1182 if (mode >= 0 && mode < 3)
1183 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
1185 return snprintf(buf, PAGE_SIZE, "%d\n", -1);
1188 #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1189 static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1190 struct kobj_attribute *kattr, char *buf) \
1192 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1194 static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1195 .attr = {.name = "remote_mode", \
1196 .mode = DEV_ATTR_RO_PERM}, \
1197 .show = wacom_show_remote##SET_ID##_mode, \
1199 static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1200 &remote##SET_ID##_mode_attr.attr, \
1203 static struct attribute_group remote##SET_ID##_serial_group = { \
1205 .attrs = remote##SET_ID##_serial_attrs, \
1208 DEVICE_EKR_ATTR_GROUP(0);
1209 DEVICE_EKR_ATTR_GROUP(1);
1210 DEVICE_EKR_ATTR_GROUP(2);
1211 DEVICE_EKR_ATTR_GROUP(3);
1212 DEVICE_EKR_ATTR_GROUP(4);
1214 int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int index)
1218 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1220 wacom_wac->serial[index] = serial;
1222 buf = kzalloc(WAC_REMOTE_SERIAL_MAX_STRLEN, GFP_KERNEL);
1225 snprintf(buf, WAC_REMOTE_SERIAL_MAX_STRLEN, "%d", serial);
1226 wacom->remote_group[index].name = buf;
1228 error = sysfs_create_group(wacom->remote_dir,
1229 &wacom->remote_group[index]);
1231 hid_err(wacom->hdev,
1232 "cannot create sysfs group err: %d\n", error);
1233 kobject_put(wacom->remote_dir);
1240 void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial)
1242 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1248 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1249 if (wacom_wac->serial[i] == serial) {
1250 wacom_wac->serial[i] = 0;
1251 wacom->led.select[i] = WACOM_STATUS_UNKNOWN;
1252 if (wacom->remote_group[i].name) {
1253 sysfs_remove_group(wacom->remote_dir,
1254 &wacom->remote_group[i]);
1255 kfree(wacom->remote_group[i].name);
1256 wacom->remote_group[i].name = NULL;
1262 static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector)
1264 const size_t buf_size = 2;
1268 buf = kzalloc(buf_size, GFP_KERNEL);
1272 buf[0] = WAC_CMD_DELETE_PAIRING;
1275 retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf,
1276 buf_size, WAC_CMD_RETRIES);
1282 static ssize_t wacom_store_unpair_remote(struct kobject *kobj,
1283 struct kobj_attribute *attr,
1284 const char *buf, size_t count)
1286 unsigned char selector = 0;
1287 struct device *dev = kobj_to_dev(kobj->parent);
1288 struct hid_device *hdev = to_hid_device(dev);
1289 struct wacom *wacom = hid_get_drvdata(hdev);
1292 if (!strncmp(buf, "*\n", 2)) {
1293 selector = WAC_CMD_UNPAIR_ALL;
1295 hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n",
1300 mutex_lock(&wacom->lock);
1302 err = wacom_cmd_unpair_remote(wacom, selector);
1303 mutex_unlock(&wacom->lock);
1305 return err < 0 ? err : count;
1308 static struct kobj_attribute unpair_remote_attr = {
1309 .attr = {.name = "unpair_remote", .mode = 0200},
1310 .store = wacom_store_unpair_remote,
1313 static const struct attribute *remote_unpair_attrs[] = {
1314 &unpair_remote_attr.attr,
1318 static int wacom_initialize_remote(struct wacom *wacom)
1321 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1324 if (wacom->wacom_wac.features.type != REMOTE)
1327 wacom->remote_group[0] = remote0_serial_group;
1328 wacom->remote_group[1] = remote1_serial_group;
1329 wacom->remote_group[2] = remote2_serial_group;
1330 wacom->remote_group[3] = remote3_serial_group;
1331 wacom->remote_group[4] = remote4_serial_group;
1333 wacom->remote_dir = kobject_create_and_add("wacom_remote",
1334 &wacom->hdev->dev.kobj);
1335 if (!wacom->remote_dir)
1338 error = sysfs_create_files(wacom->remote_dir, remote_unpair_attrs);
1341 hid_err(wacom->hdev,
1342 "cannot create sysfs group err: %d\n", error);
1346 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1347 wacom->led.select[i] = WACOM_STATUS_UNKNOWN;
1348 wacom_wac->serial[i] = 0;
1354 static struct input_dev *wacom_allocate_input(struct wacom *wacom)
1356 struct input_dev *input_dev;
1357 struct hid_device *hdev = wacom->hdev;
1358 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1360 input_dev = input_allocate_device();
1364 input_dev->name = wacom_wac->features.name;
1365 input_dev->phys = hdev->phys;
1366 input_dev->dev.parent = &hdev->dev;
1367 input_dev->open = wacom_open;
1368 input_dev->close = wacom_close;
1369 input_dev->uniq = hdev->uniq;
1370 input_dev->id.bustype = hdev->bus;
1371 input_dev->id.vendor = hdev->vendor;
1372 input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product;
1373 input_dev->id.version = hdev->version;
1374 input_set_drvdata(input_dev, wacom);
1379 static void wacom_clean_inputs(struct wacom *wacom)
1381 if (wacom->wacom_wac.pen_input) {
1382 if (wacom->wacom_wac.pen_registered)
1383 input_unregister_device(wacom->wacom_wac.pen_input);
1385 input_free_device(wacom->wacom_wac.pen_input);
1387 if (wacom->wacom_wac.touch_input) {
1388 if (wacom->wacom_wac.touch_registered)
1389 input_unregister_device(wacom->wacom_wac.touch_input);
1391 input_free_device(wacom->wacom_wac.touch_input);
1393 if (wacom->wacom_wac.pad_input) {
1394 if (wacom->wacom_wac.pad_registered)
1395 input_unregister_device(wacom->wacom_wac.pad_input);
1397 input_free_device(wacom->wacom_wac.pad_input);
1399 kobject_put(wacom->remote_dir);
1400 wacom->wacom_wac.pen_input = NULL;
1401 wacom->wacom_wac.touch_input = NULL;
1402 wacom->wacom_wac.pad_input = NULL;
1403 wacom->wacom_wac.pen_registered = false;
1404 wacom->wacom_wac.touch_registered = false;
1405 wacom->wacom_wac.pad_registered = false;
1406 wacom_destroy_leds(wacom);
1409 static int wacom_allocate_inputs(struct wacom *wacom)
1411 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1413 wacom_wac->pen_input = wacom_allocate_input(wacom);
1414 wacom_wac->touch_input = wacom_allocate_input(wacom);
1415 wacom_wac->pad_input = wacom_allocate_input(wacom);
1416 if (!wacom_wac->pen_input || !wacom_wac->touch_input || !wacom_wac->pad_input) {
1417 wacom_clean_inputs(wacom);
1421 wacom_wac->pen_input->name = wacom_wac->pen_name;
1422 wacom_wac->touch_input->name = wacom_wac->touch_name;
1423 wacom_wac->pad_input->name = wacom_wac->pad_name;
1428 static int wacom_register_inputs(struct wacom *wacom)
1430 struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
1431 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1434 pen_input_dev = wacom_wac->pen_input;
1435 touch_input_dev = wacom_wac->touch_input;
1436 pad_input_dev = wacom_wac->pad_input;
1438 if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
1441 error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
1443 /* no pen in use on this interface */
1444 input_free_device(pen_input_dev);
1445 wacom_wac->pen_input = NULL;
1446 pen_input_dev = NULL;
1448 error = input_register_device(pen_input_dev);
1450 goto fail_register_pen_input;
1451 wacom_wac->pen_registered = true;
1454 error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
1456 /* no touch in use on this interface */
1457 input_free_device(touch_input_dev);
1458 wacom_wac->touch_input = NULL;
1459 touch_input_dev = NULL;
1461 error = input_register_device(touch_input_dev);
1463 goto fail_register_touch_input;
1464 wacom_wac->touch_registered = true;
1467 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
1469 /* no pad in use on this interface */
1470 input_free_device(pad_input_dev);
1471 wacom_wac->pad_input = NULL;
1472 pad_input_dev = NULL;
1474 error = input_register_device(pad_input_dev);
1476 goto fail_register_pad_input;
1477 wacom_wac->pad_registered = true;
1479 error = wacom_initialize_leds(wacom);
1483 error = wacom_initialize_remote(wacom);
1491 wacom_destroy_leds(wacom);
1493 input_unregister_device(pad_input_dev);
1494 pad_input_dev = NULL;
1495 wacom_wac->pad_registered = false;
1496 fail_register_pad_input:
1497 if (touch_input_dev)
1498 input_unregister_device(touch_input_dev);
1499 wacom_wac->touch_input = NULL;
1500 wacom_wac->touch_registered = false;
1501 fail_register_touch_input:
1503 input_unregister_device(pen_input_dev);
1504 wacom_wac->pen_input = NULL;
1505 wacom_wac->pen_registered = false;
1506 fail_register_pen_input:
1511 * Not all devices report physical dimensions from HID.
1512 * Compute the default from hardcoded logical dimension
1513 * and resolution before driver overwrites them.
1515 static void wacom_set_default_phy(struct wacom_features *features)
1517 if (features->x_resolution) {
1518 features->x_phy = (features->x_max * 100) /
1519 features->x_resolution;
1520 features->y_phy = (features->y_max * 100) /
1521 features->y_resolution;
1525 static void wacom_calculate_res(struct wacom_features *features)
1527 /* set unit to "100th of a mm" for devices not reported by HID */
1528 if (!features->unit) {
1529 features->unit = 0x11;
1530 features->unitExpo = -3;
1533 features->x_resolution = wacom_calc_hid_res(features->x_max,
1536 features->unitExpo);
1537 features->y_resolution = wacom_calc_hid_res(features->y_max,
1540 features->unitExpo);
1543 void wacom_battery_work(struct work_struct *work)
1545 struct wacom *wacom = container_of(work, struct wacom, work);
1547 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1549 wacom_initialize_battery(wacom);
1551 else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1553 wacom_destroy_battery(wacom);
1557 static size_t wacom_compute_pktlen(struct hid_device *hdev)
1559 struct hid_report_enum *report_enum;
1560 struct hid_report *report;
1563 report_enum = hdev->report_enum + HID_INPUT_REPORT;
1565 list_for_each_entry(report, &report_enum->report_list, list) {
1566 size_t report_size = hid_report_len(report);
1567 if (report_size > size)
1574 static void wacom_update_name(struct wacom *wacom, const char *suffix)
1576 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1577 struct wacom_features *features = &wacom_wac->features;
1578 char name[WACOM_NAME_MAX];
1580 /* Generic devices name unspecified */
1581 if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
1582 if (strstr(wacom->hdev->name, "Wacom") ||
1583 strstr(wacom->hdev->name, "wacom") ||
1584 strstr(wacom->hdev->name, "WACOM")) {
1585 /* name is in HID descriptor, use it */
1586 strlcpy(name, wacom->hdev->name, sizeof(name));
1588 /* strip out excess whitespaces */
1590 char *gap = strstr(name, " ");
1593 /* shift everything including the terminator */
1594 memmove(gap, gap+1, strlen(gap));
1596 /* get rid of trailing whitespace */
1597 if (name[strlen(name)-1] == ' ')
1598 name[strlen(name)-1] = '\0';
1600 /* no meaningful name retrieved. use product ID */
1601 snprintf(name, sizeof(name),
1602 "%s %X", features->name, wacom->hdev->product);
1605 strlcpy(name, features->name, sizeof(name));
1608 /* Append the device type to the name */
1609 snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
1610 "%s%s Pen", name, suffix);
1611 snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
1612 "%s%s Finger", name, suffix);
1613 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1614 "%s%s Pad", name, suffix);
1617 static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
1619 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1620 struct wacom_features *features = &wacom_wac->features;
1621 struct hid_device *hdev = wacom->hdev;
1623 unsigned int connect_mask = HID_CONNECT_HIDRAW;
1625 features->pktlen = wacom_compute_pktlen(hdev);
1626 if (features->pktlen > WACOM_PKGLEN_MAX)
1629 error = wacom_allocate_inputs(wacom);
1634 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
1635 * into debug mode for the touch part.
1636 * We ignore the other interfaces.
1638 if (features->type == BAMBOO_PAD) {
1639 if (features->pktlen == WACOM_PKGLEN_PENABLED) {
1640 features->type = HID_GENERIC;
1641 } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
1642 (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
1644 goto fail_allocate_inputs;
1648 /* set the default size in case we do not get them from hid */
1649 wacom_set_default_phy(features);
1651 /* Retrieve the physical and logical size for touch devices */
1652 wacom_retrieve_hid_descriptor(hdev, features);
1653 wacom_setup_device_quirks(wacom);
1655 if (features->device_type == WACOM_DEVICETYPE_NONE &&
1656 features->type != WIRELESS) {
1657 error = features->type == HID_GENERIC ? -ENODEV : 0;
1659 dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
1661 error ? "Ignoring" : "Assuming pen");
1666 features->device_type |= WACOM_DEVICETYPE_PEN;
1669 wacom_calculate_res(features);
1671 wacom_update_name(wacom, wireless ? " (WL)" : "");
1673 error = wacom_add_shared_data(hdev);
1675 goto fail_shared_data;
1677 if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
1678 (features->quirks & WACOM_QUIRK_BATTERY)) {
1679 error = wacom_initialize_battery(wacom);
1684 error = wacom_register_inputs(wacom);
1686 goto fail_register_inputs;
1688 if (features->type == HID_GENERIC)
1689 connect_mask |= HID_CONNECT_DRIVER;
1691 /* Regular HID work starts now */
1692 error = hid_hw_start(hdev, connect_mask);
1694 hid_err(hdev, "hw start failed\n");
1699 /* Note that if query fails it is not a hard failure */
1700 wacom_query_tablet_data(hdev, features);
1703 /* touch only Bamboo doesn't support pen */
1704 if ((features->type == BAMBOO_TOUCH) &&
1705 (features->device_type & WACOM_DEVICETYPE_PEN)) {
1710 /* pen only Bamboo neither support touch nor pad */
1711 if ((features->type == BAMBOO_PEN) &&
1712 ((features->device_type & WACOM_DEVICETYPE_TOUCH) ||
1713 (features->device_type & WACOM_DEVICETYPE_PAD))) {
1718 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
1719 error = hid_hw_open(hdev);
1721 if ((wacom_wac->features.type == INTUOSHT ||
1722 wacom_wac->features.type == INTUOSHT2) &&
1723 (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)) {
1724 wacom_wac->shared->touch_input = wacom_wac->touch_input;
1731 fail_register_inputs:
1732 wacom_clean_inputs(wacom);
1733 wacom_destroy_battery(wacom);
1735 wacom_remove_shared_data(wacom);
1738 fail_allocate_inputs:
1739 wacom_clean_inputs(wacom);
1743 static void wacom_wireless_work(struct work_struct *work)
1745 struct wacom *wacom = container_of(work, struct wacom, work);
1746 struct usb_device *usbdev = wacom->usbdev;
1747 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1748 struct hid_device *hdev1, *hdev2;
1749 struct wacom *wacom1, *wacom2;
1750 struct wacom_wac *wacom_wac1, *wacom_wac2;
1754 * Regardless if this is a disconnect or a new tablet,
1755 * remove any existing input and battery devices.
1758 wacom_destroy_battery(wacom);
1760 /* Stylus interface */
1761 hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
1762 wacom1 = hid_get_drvdata(hdev1);
1763 wacom_wac1 = &(wacom1->wacom_wac);
1764 wacom_clean_inputs(wacom1);
1766 /* Touch interface */
1767 hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
1768 wacom2 = hid_get_drvdata(hdev2);
1769 wacom_wac2 = &(wacom2->wacom_wac);
1770 wacom_clean_inputs(wacom2);
1772 if (wacom_wac->pid == 0) {
1773 hid_info(wacom->hdev, "wireless tablet disconnected\n");
1774 wacom_wac1->shared->type = 0;
1776 const struct hid_device_id *id = wacom_ids;
1778 hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
1782 if (id->vendor == USB_VENDOR_ID_WACOM &&
1783 id->product == wacom_wac->pid)
1789 hid_info(wacom->hdev, "ignoring unknown PID.\n");
1793 /* Stylus interface */
1794 wacom_wac1->features =
1795 *((struct wacom_features *)id->driver_data);
1797 wacom_wac1->pid = wacom_wac->pid;
1799 error = wacom_parse_and_register(wacom1, true);
1803 /* Touch interface */
1804 if (wacom_wac1->features.touch_max ||
1805 (wacom_wac1->features.type >= INTUOSHT &&
1806 wacom_wac1->features.type <= BAMBOO_PT)) {
1807 wacom_wac2->features =
1808 *((struct wacom_features *)id->driver_data);
1809 wacom_wac2->pid = wacom_wac->pid;
1811 error = wacom_parse_and_register(wacom2, true);
1816 error = wacom_initialize_battery(wacom);
1824 wacom_clean_inputs(wacom1);
1825 wacom_clean_inputs(wacom2);
1829 static int wacom_probe(struct hid_device *hdev,
1830 const struct hid_device_id *id)
1832 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
1833 struct usb_device *dev = interface_to_usbdev(intf);
1834 struct wacom *wacom;
1835 struct wacom_wac *wacom_wac;
1836 struct wacom_features *features;
1839 if (!id->driver_data)
1842 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
1844 /* hid-core sets this quirk for the boot interface */
1845 hdev->quirks &= ~HID_QUIRK_NOGET;
1847 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
1851 hid_set_drvdata(hdev, wacom);
1854 wacom_wac = &wacom->wacom_wac;
1855 wacom_wac->features = *((struct wacom_features *)id->driver_data);
1856 features = &wacom_wac->features;
1858 if (features->check_for_hid_type && features->hid_type != hdev->type) {
1863 wacom_wac->hid_data.inputmode = -1;
1864 wacom_wac->mode_report = -1;
1866 wacom->usbdev = dev;
1868 mutex_init(&wacom->lock);
1869 INIT_WORK(&wacom->work, wacom_wireless_work);
1871 /* ask for the report descriptor to be loaded by HID */
1872 error = hid_parse(hdev);
1874 hid_err(hdev, "parse failed\n");
1878 error = wacom_parse_and_register(wacom, false);
1882 if (hdev->bus == BUS_BLUETOOTH) {
1883 error = device_create_file(&hdev->dev, &dev_attr_speed);
1886 "can't create sysfs speed attribute err: %d\n",
1895 hid_set_drvdata(hdev, NULL);
1899 static void wacom_remove(struct hid_device *hdev)
1901 struct wacom *wacom = hid_get_drvdata(hdev);
1902 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1903 struct wacom_features *features = &wacom_wac->features;
1905 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
1910 cancel_work_sync(&wacom->work);
1911 wacom_clean_inputs(wacom);
1912 if (hdev->bus == BUS_BLUETOOTH)
1913 device_remove_file(&hdev->dev, &dev_attr_speed);
1914 wacom_destroy_battery(wacom);
1915 wacom_remove_shared_data(wacom);
1917 hid_set_drvdata(hdev, NULL);
1922 static int wacom_resume(struct hid_device *hdev)
1924 struct wacom *wacom = hid_get_drvdata(hdev);
1925 struct wacom_features *features = &wacom->wacom_wac.features;
1927 mutex_lock(&wacom->lock);
1929 /* switch to wacom mode first */
1930 wacom_query_tablet_data(hdev, features);
1931 wacom_led_control(wacom);
1933 mutex_unlock(&wacom->lock);
1938 static int wacom_reset_resume(struct hid_device *hdev)
1940 return wacom_resume(hdev);
1942 #endif /* CONFIG_PM */
1944 static struct hid_driver wacom_driver = {
1946 .id_table = wacom_ids,
1947 .probe = wacom_probe,
1948 .remove = wacom_remove,
1949 .report = wacom_wac_report,
1951 .resume = wacom_resume,
1952 .reset_resume = wacom_reset_resume,
1954 .raw_event = wacom_raw_event,
1956 module_hid_driver(wacom_driver);
1958 MODULE_VERSION(DRIVER_VERSION);
1959 MODULE_AUTHOR(DRIVER_AUTHOR);
1960 MODULE_DESCRIPTION(DRIVER_DESC);
1961 MODULE_LICENSE(DRIVER_LICENSE);