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;
159 * Interface Descriptor of wacom devices can be incomplete and
160 * inconsistent so wacom_features table is used to store stylus
161 * device's packet lengths, various maximum values, and tablet
162 * resolution based on product ID's.
164 * For devices that contain 2 interfaces, wacom_features table is
165 * inaccurate for the touch interface. Since the Interface Descriptor
166 * for touch interfaces has pretty complete data, this function exists
167 * to query tablet for this missing information instead of hard coding in
168 * an additional table.
170 * A typical Interface Descriptor for a stylus will contain a
171 * boot mouse application collection that is not of interest and this
172 * function will ignore it.
174 * It also contains a digitizer application collection that also is not
175 * of interest since any information it contains would be duplicate
176 * of what is in wacom_features. Usually it defines a report of an array
177 * of bytes that could be used as max length of the stylus packet returned.
178 * If it happens to define a Digitizer-Stylus Physical Collection then
179 * the X and Y logical values contain valid data but it is ignored.
181 * A typical Interface Descriptor for a touch interface will contain a
182 * Digitizer-Finger Physical Collection which will define both logical
183 * X/Y maximum as well as the physical size of tablet. Since touch
184 * interfaces haven't supported pressure or distance, this is enough
185 * information to override invalid values in the wacom_features table.
187 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
188 * data. We deal with them after returning from this function.
190 static void wacom_usage_mapping(struct hid_device *hdev,
191 struct hid_field *field, struct hid_usage *usage)
193 struct wacom *wacom = hid_get_drvdata(hdev);
194 struct wacom_features *features = &wacom->wacom_wac.features;
195 bool finger = WACOM_FINGER_FIELD(field);
196 bool pen = WACOM_PEN_FIELD(field);
199 * Requiring Stylus Usage will ignore boot mouse
200 * X/Y values and some cases of invalid Digitizer X/Y
201 * values commonly reported.
204 features->device_type |= WACOM_DEVICETYPE_PEN;
206 features->device_type |= WACOM_DEVICETYPE_TOUCH;
211 * Bamboo models do not support HID_DG_CONTACTMAX.
212 * And, Bamboo Pen only descriptor contains touch.
214 if (features->type != BAMBOO_PT) {
215 /* ISDv4 touch devices at least supports one touch point */
216 if (finger && !features->touch_max)
217 features->touch_max = 1;
220 switch (usage->hid) {
222 features->x_max = field->logical_maximum;
224 features->x_phy = field->physical_maximum;
225 if (features->type != BAMBOO_PT) {
226 features->unit = field->unit;
227 features->unitExpo = field->unit_exponent;
232 features->y_max = field->logical_maximum;
234 features->y_phy = field->physical_maximum;
235 if (features->type != BAMBOO_PT) {
236 features->unit = field->unit;
237 features->unitExpo = field->unit_exponent;
241 case HID_DG_TIPPRESSURE:
243 features->pressure_max = field->logical_maximum;
247 if (features->type == HID_GENERIC)
248 wacom_wac_usage_mapping(hdev, field, usage);
251 static void wacom_post_parse_hid(struct hid_device *hdev,
252 struct wacom_features *features)
254 struct wacom *wacom = hid_get_drvdata(hdev);
255 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
257 if (features->type == HID_GENERIC) {
258 /* Any last-minute generic device setup */
259 if (features->touch_max > 1) {
260 input_mt_init_slots(wacom_wac->touch_input, wacom_wac->features.touch_max,
266 static void wacom_parse_hid(struct hid_device *hdev,
267 struct wacom_features *features)
269 struct hid_report_enum *rep_enum;
270 struct hid_report *hreport;
273 /* check features first */
274 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
275 list_for_each_entry(hreport, &rep_enum->report_list, list) {
276 for (i = 0; i < hreport->maxfield; i++) {
277 /* Ignore if report count is out of bounds. */
278 if (hreport->field[i]->report_count < 1)
281 for (j = 0; j < hreport->field[i]->maxusage; j++) {
282 wacom_feature_mapping(hdev, hreport->field[i],
283 hreport->field[i]->usage + j);
288 /* now check the input usages */
289 rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
290 list_for_each_entry(hreport, &rep_enum->report_list, list) {
292 if (!hreport->maxfield)
295 for (i = 0; i < hreport->maxfield; i++)
296 for (j = 0; j < hreport->field[i]->maxusage; j++)
297 wacom_usage_mapping(hdev, hreport->field[i],
298 hreport->field[i]->usage + j);
301 wacom_post_parse_hid(hdev, features);
304 static int wacom_hid_set_device_mode(struct hid_device *hdev)
306 struct wacom *wacom = hid_get_drvdata(hdev);
307 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
308 struct hid_report *r;
309 struct hid_report_enum *re;
311 if (hid_data->inputmode < 0)
314 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
315 r = re->report_id_hash[hid_data->inputmode];
317 r->field[0]->value[hid_data->inputmode_index] = 2;
318 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
323 static int wacom_set_device_mode(struct hid_device *hdev, int report_id,
324 int length, int mode)
326 unsigned char *rep_data;
327 int error = -ENOMEM, limit = 0;
329 rep_data = kzalloc(length, GFP_KERNEL);
334 rep_data[0] = report_id;
337 error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data,
340 error = wacom_get_report(hdev, HID_FEATURE_REPORT,
341 rep_data, length, 1);
342 } while (error >= 0 && rep_data[1] != mode && limit++ < WAC_MSG_RETRIES);
346 return error < 0 ? error : 0;
349 static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
350 struct wacom_features *features)
352 struct wacom *wacom = hid_get_drvdata(hdev);
356 switch (features->type) {
360 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
364 rep_data[0] = speed == 0 ? 0x05 : 0x06;
367 ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
371 wacom->wacom_wac.bt_high_speed = speed;
377 * Note that if the raw queries fail, it's not a hard failure
378 * and it is safe to continue
380 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
385 wacom->wacom_wac.bt_features &= ~0x20;
387 wacom->wacom_wac.bt_features |= 0x20;
390 rep_data[1] = wacom->wacom_wac.bt_features;
392 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
395 wacom->wacom_wac.bt_high_speed = speed;
403 * Switch the tablet into its most-capable mode. Wacom tablets are
404 * typically configured to power-up in a mode which sends mouse-like
405 * reports to the OS. To get absolute position, pressure data, etc.
406 * from the tablet, it is necessary to switch the tablet out of this
407 * mode and into one which sends the full range of tablet data.
409 static int wacom_query_tablet_data(struct hid_device *hdev,
410 struct wacom_features *features)
412 if (hdev->bus == BUS_BLUETOOTH)
413 return wacom_bt_query_tablet_data(hdev, 1, features);
415 if (features->type == HID_GENERIC)
416 return wacom_hid_set_device_mode(hdev);
418 if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
419 if (features->type > TABLETPC) {
420 /* MT Tablet PC touch */
421 return wacom_set_device_mode(hdev, 3, 4, 4);
423 else if (features->type == WACOM_24HDT || features->type == CINTIQ_HYBRID) {
424 return wacom_set_device_mode(hdev, 18, 3, 2);
426 else if (features->type == WACOM_27QHDT) {
427 return wacom_set_device_mode(hdev, 131, 3, 2);
429 else if (features->type == BAMBOO_PAD) {
430 return wacom_set_device_mode(hdev, 2, 2, 2);
432 } else if (features->device_type & WACOM_DEVICETYPE_PEN) {
433 if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
434 return wacom_set_device_mode(hdev, 2, 2, 2);
441 static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
442 struct wacom_features *features)
444 struct wacom *wacom = hid_get_drvdata(hdev);
445 struct usb_interface *intf = wacom->intf;
447 /* default features */
448 features->x_fuzz = 4;
449 features->y_fuzz = 4;
450 features->pressure_fuzz = 0;
451 features->distance_fuzz = 0;
454 * The wireless device HID is basic and layout conflicts with
455 * other tablets (monitor and touch interface can look like pen).
456 * Skip the query for this type and modify defaults based on
459 if (features->type == WIRELESS) {
460 if (intf->cur_altsetting->desc.bInterfaceNumber == 0)
461 features->device_type = WACOM_DEVICETYPE_WL_MONITOR;
463 features->device_type = WACOM_DEVICETYPE_NONE;
467 wacom_parse_hid(hdev, features);
470 struct wacom_hdev_data {
471 struct list_head list;
473 struct hid_device *dev;
474 struct wacom_shared shared;
477 static LIST_HEAD(wacom_udev_list);
478 static DEFINE_MUTEX(wacom_udev_list_lock);
480 static bool wacom_are_sibling(struct hid_device *hdev,
481 struct hid_device *sibling)
483 struct wacom *wacom = hid_get_drvdata(hdev);
484 struct wacom_features *features = &wacom->wacom_wac.features;
485 int vid = features->oVid;
486 int pid = features->oPid;
489 if (vid == 0 && pid == 0) {
494 if (vid != sibling->vendor || pid != sibling->product)
497 /* Compare the physical path. */
498 n1 = strrchr(hdev->phys, '.') - hdev->phys;
499 n2 = strrchr(sibling->phys, '.') - sibling->phys;
500 if (n1 != n2 || n1 <= 0 || n2 <= 0)
503 return !strncmp(hdev->phys, sibling->phys, n1);
506 static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
508 struct wacom_hdev_data *data;
510 list_for_each_entry(data, &wacom_udev_list, list) {
511 if (wacom_are_sibling(hdev, data->dev)) {
512 kref_get(&data->kref);
520 static int wacom_add_shared_data(struct hid_device *hdev)
522 struct wacom *wacom = hid_get_drvdata(hdev);
523 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
524 struct wacom_hdev_data *data;
527 mutex_lock(&wacom_udev_list_lock);
529 data = wacom_get_hdev_data(hdev);
531 data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
537 kref_init(&data->kref);
539 list_add_tail(&data->list, &wacom_udev_list);
542 wacom_wac->shared = &data->shared;
544 if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
545 wacom_wac->shared->touch = hdev;
546 else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
547 wacom_wac->shared->pen = hdev;
550 mutex_unlock(&wacom_udev_list_lock);
554 static void wacom_release_shared_data(struct kref *kref)
556 struct wacom_hdev_data *data =
557 container_of(kref, struct wacom_hdev_data, kref);
559 mutex_lock(&wacom_udev_list_lock);
560 list_del(&data->list);
561 mutex_unlock(&wacom_udev_list_lock);
566 static void wacom_remove_shared_data(struct wacom *wacom)
568 struct wacom_hdev_data *data;
569 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
571 if (wacom_wac->shared) {
572 data = container_of(wacom_wac->shared, struct wacom_hdev_data,
575 if (wacom_wac->shared->touch == wacom->hdev)
576 wacom_wac->shared->touch = NULL;
577 else if (wacom_wac->shared->pen == wacom->hdev)
578 wacom_wac->shared->pen = NULL;
580 kref_put(&data->kref, wacom_release_shared_data);
581 wacom_wac->shared = NULL;
585 static int wacom_led_control(struct wacom *wacom)
589 unsigned char report_id = WAC_CMD_LED_CONTROL;
592 if (wacom->wacom_wac.pid) { /* wireless connected */
593 report_id = WAC_CMD_WL_LED_CONTROL;
596 buf = kzalloc(buf_size, GFP_KERNEL);
600 if (wacom->wacom_wac.features.type >= INTUOS5S &&
601 wacom->wacom_wac.features.type <= INTUOSPL) {
603 * Touch Ring and crop mark LED luminance may take on
604 * one of four values:
605 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
607 int ring_led = wacom->led.select[0] & 0x03;
608 int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
610 unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
613 if (wacom->wacom_wac.pid) {
614 wacom_get_report(wacom->hdev, HID_FEATURE_REPORT,
615 buf, buf_size, WAC_CMD_RETRIES);
622 int led = wacom->led.select[0] | 0x4;
624 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
625 wacom->wacom_wac.features.type == WACOM_24HD)
626 led |= (wacom->led.select[1] << 4) | 0x40;
630 buf[2] = wacom->led.llv;
631 buf[3] = wacom->led.hlv;
632 buf[4] = wacom->led.img_lum;
635 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size,
642 static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
643 const unsigned len, const void *img)
647 const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
649 buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
653 /* Send 'start' command */
654 buf[0] = WAC_CMD_ICON_START;
656 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
662 buf[1] = button_id & 0x07;
663 for (i = 0; i < 4; i++) {
665 memcpy(buf + 3, img + i * chunk_len, chunk_len);
667 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
668 buf, chunk_len + 3, WAC_CMD_RETRIES);
674 buf[0] = WAC_CMD_ICON_START;
676 wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
684 static ssize_t wacom_led_select_store(struct device *dev, int set_id,
685 const char *buf, size_t count)
687 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
688 struct wacom *wacom = hid_get_drvdata(hdev);
692 err = kstrtouint(buf, 10, &id);
696 mutex_lock(&wacom->lock);
698 wacom->led.select[set_id] = id & 0x3;
699 err = wacom_led_control(wacom);
701 mutex_unlock(&wacom->lock);
703 return err < 0 ? err : count;
706 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
707 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
708 struct device_attribute *attr, const char *buf, size_t count) \
710 return wacom_led_select_store(dev, SET_ID, buf, count); \
712 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
713 struct device_attribute *attr, char *buf) \
715 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
716 struct wacom *wacom = hid_get_drvdata(hdev); \
717 return scnprintf(buf, PAGE_SIZE, "%d\n", \
718 wacom->led.select[SET_ID]); \
720 static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
721 wacom_led##SET_ID##_select_show, \
722 wacom_led##SET_ID##_select_store)
724 DEVICE_LED_SELECT_ATTR(0);
725 DEVICE_LED_SELECT_ATTR(1);
727 static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
728 const char *buf, size_t count)
733 err = kstrtouint(buf, 10, &value);
737 mutex_lock(&wacom->lock);
739 *dest = value & 0x7f;
740 err = wacom_led_control(wacom);
742 mutex_unlock(&wacom->lock);
744 return err < 0 ? err : count;
747 #define DEVICE_LUMINANCE_ATTR(name, field) \
748 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
749 struct device_attribute *attr, const char *buf, size_t count) \
751 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
752 struct wacom *wacom = hid_get_drvdata(hdev); \
754 return wacom_luminance_store(wacom, &wacom->led.field, \
757 static ssize_t wacom_##name##_luminance_show(struct device *dev, \
758 struct device_attribute *attr, char *buf) \
760 struct wacom *wacom = dev_get_drvdata(dev); \
761 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
763 static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
764 wacom_##name##_luminance_show, \
765 wacom_##name##_luminance_store)
767 DEVICE_LUMINANCE_ATTR(status0, llv);
768 DEVICE_LUMINANCE_ATTR(status1, hlv);
769 DEVICE_LUMINANCE_ATTR(buttons, img_lum);
771 static ssize_t wacom_button_image_store(struct device *dev, int button_id,
772 const char *buf, size_t count)
774 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
775 struct wacom *wacom = hid_get_drvdata(hdev);
780 if (hdev->bus == BUS_BLUETOOTH) {
782 xfer_id = WAC_CMD_ICON_BT_XFER;
785 xfer_id = WAC_CMD_ICON_XFER;
791 mutex_lock(&wacom->lock);
793 err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
795 mutex_unlock(&wacom->lock);
797 return err < 0 ? err : count;
800 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
801 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
802 struct device_attribute *attr, const char *buf, size_t count) \
804 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
806 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
807 NULL, wacom_btnimg##BUTTON_ID##_store)
809 DEVICE_BTNIMG_ATTR(0);
810 DEVICE_BTNIMG_ATTR(1);
811 DEVICE_BTNIMG_ATTR(2);
812 DEVICE_BTNIMG_ATTR(3);
813 DEVICE_BTNIMG_ATTR(4);
814 DEVICE_BTNIMG_ATTR(5);
815 DEVICE_BTNIMG_ATTR(6);
816 DEVICE_BTNIMG_ATTR(7);
818 static struct attribute *cintiq_led_attrs[] = {
819 &dev_attr_status_led0_select.attr,
820 &dev_attr_status_led1_select.attr,
824 static struct attribute_group cintiq_led_attr_group = {
826 .attrs = cintiq_led_attrs,
829 static struct attribute *intuos4_led_attrs[] = {
830 &dev_attr_status0_luminance.attr,
831 &dev_attr_status1_luminance.attr,
832 &dev_attr_status_led0_select.attr,
833 &dev_attr_buttons_luminance.attr,
834 &dev_attr_button0_rawimg.attr,
835 &dev_attr_button1_rawimg.attr,
836 &dev_attr_button2_rawimg.attr,
837 &dev_attr_button3_rawimg.attr,
838 &dev_attr_button4_rawimg.attr,
839 &dev_attr_button5_rawimg.attr,
840 &dev_attr_button6_rawimg.attr,
841 &dev_attr_button7_rawimg.attr,
845 static struct attribute_group intuos4_led_attr_group = {
847 .attrs = intuos4_led_attrs,
850 static struct attribute *intuos5_led_attrs[] = {
851 &dev_attr_status0_luminance.attr,
852 &dev_attr_status_led0_select.attr,
856 static struct attribute_group intuos5_led_attr_group = {
858 .attrs = intuos5_led_attrs,
861 static int wacom_initialize_leds(struct wacom *wacom)
865 if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
868 /* Initialize default values */
869 switch (wacom->wacom_wac.features.type) {
874 wacom->led.select[0] = 0;
875 wacom->led.select[1] = 0;
878 wacom->led.img_lum = 10;
879 error = sysfs_create_group(&wacom->hdev->dev.kobj,
880 &intuos4_led_attr_group);
885 wacom->led.select[0] = 0;
886 wacom->led.select[1] = 0;
889 wacom->led.img_lum = 0;
891 error = sysfs_create_group(&wacom->hdev->dev.kobj,
892 &cintiq_led_attr_group);
901 wacom->led.select[0] = 0;
902 wacom->led.select[1] = 0;
905 wacom->led.img_lum = 0;
907 error = sysfs_create_group(&wacom->hdev->dev.kobj,
908 &intuos5_led_attr_group);
917 "cannot create sysfs group err: %d\n", error);
920 wacom_led_control(wacom);
921 wacom->led_initialized = true;
926 static void wacom_destroy_leds(struct wacom *wacom)
928 if (!wacom->led_initialized)
931 if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
934 wacom->led_initialized = false;
936 switch (wacom->wacom_wac.features.type) {
941 sysfs_remove_group(&wacom->hdev->dev.kobj,
942 &intuos4_led_attr_group);
947 sysfs_remove_group(&wacom->hdev->dev.kobj,
948 &cintiq_led_attr_group);
957 sysfs_remove_group(&wacom->hdev->dev.kobj,
958 &intuos5_led_attr_group);
963 static enum power_supply_property wacom_battery_props[] = {
964 POWER_SUPPLY_PROP_PRESENT,
965 POWER_SUPPLY_PROP_STATUS,
966 POWER_SUPPLY_PROP_SCOPE,
967 POWER_SUPPLY_PROP_CAPACITY
970 static enum power_supply_property wacom_ac_props[] = {
971 POWER_SUPPLY_PROP_PRESENT,
972 POWER_SUPPLY_PROP_ONLINE,
973 POWER_SUPPLY_PROP_SCOPE,
976 static int wacom_battery_get_property(struct power_supply *psy,
977 enum power_supply_property psp,
978 union power_supply_propval *val)
980 struct wacom *wacom = power_supply_get_drvdata(psy);
984 case POWER_SUPPLY_PROP_PRESENT:
985 val->intval = wacom->wacom_wac.bat_connected;
987 case POWER_SUPPLY_PROP_SCOPE:
988 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
990 case POWER_SUPPLY_PROP_CAPACITY:
992 wacom->wacom_wac.battery_capacity;
994 case POWER_SUPPLY_PROP_STATUS:
995 if (wacom->wacom_wac.bat_charging)
996 val->intval = POWER_SUPPLY_STATUS_CHARGING;
997 else if (wacom->wacom_wac.battery_capacity == 100 &&
998 wacom->wacom_wac.ps_connected)
999 val->intval = POWER_SUPPLY_STATUS_FULL;
1000 else if (wacom->wacom_wac.ps_connected)
1001 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
1003 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
1013 static int wacom_ac_get_property(struct power_supply *psy,
1014 enum power_supply_property psp,
1015 union power_supply_propval *val)
1017 struct wacom *wacom = power_supply_get_drvdata(psy);
1021 case POWER_SUPPLY_PROP_PRESENT:
1023 case POWER_SUPPLY_PROP_ONLINE:
1024 val->intval = wacom->wacom_wac.ps_connected;
1026 case POWER_SUPPLY_PROP_SCOPE:
1027 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1036 static int wacom_initialize_battery(struct wacom *wacom)
1038 static atomic_t battery_no = ATOMIC_INIT(0);
1039 struct power_supply_config psy_cfg = { .drv_data = wacom, };
1042 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
1043 struct power_supply_desc *bat_desc = &wacom->battery_desc;
1044 struct power_supply_desc *ac_desc = &wacom->ac_desc;
1045 n = atomic_inc_return(&battery_no) - 1;
1047 bat_desc->properties = wacom_battery_props;
1048 bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
1049 bat_desc->get_property = wacom_battery_get_property;
1050 sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
1051 bat_desc->name = wacom->wacom_wac.bat_name;
1052 bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;
1053 bat_desc->use_for_apm = 0;
1055 ac_desc->properties = wacom_ac_props;
1056 ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props);
1057 ac_desc->get_property = wacom_ac_get_property;
1058 sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
1059 ac_desc->name = wacom->wacom_wac.ac_name;
1060 ac_desc->type = POWER_SUPPLY_TYPE_MAINS;
1061 ac_desc->use_for_apm = 0;
1063 wacom->battery = power_supply_register(&wacom->hdev->dev,
1064 &wacom->battery_desc, &psy_cfg);
1065 if (IS_ERR(wacom->battery))
1066 return PTR_ERR(wacom->battery);
1068 power_supply_powers(wacom->battery, &wacom->hdev->dev);
1070 wacom->ac = power_supply_register(&wacom->hdev->dev,
1073 if (IS_ERR(wacom->ac)) {
1074 power_supply_unregister(wacom->battery);
1075 return PTR_ERR(wacom->ac);
1078 power_supply_powers(wacom->ac, &wacom->hdev->dev);
1084 static void wacom_destroy_battery(struct wacom *wacom)
1086 if (wacom->battery) {
1087 power_supply_unregister(wacom->battery);
1088 wacom->battery = NULL;
1089 power_supply_unregister(wacom->ac);
1094 static ssize_t wacom_show_speed(struct device *dev,
1095 struct device_attribute
1098 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1099 struct wacom *wacom = hid_get_drvdata(hdev);
1101 return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
1104 static ssize_t wacom_store_speed(struct device *dev,
1105 struct device_attribute *attr,
1106 const char *buf, size_t count)
1108 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1109 struct wacom *wacom = hid_get_drvdata(hdev);
1112 if (kstrtou8(buf, 0, &new_speed))
1115 if (new_speed != 0 && new_speed != 1)
1118 wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
1123 static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM,
1124 wacom_show_speed, wacom_store_speed);
1127 static ssize_t wacom_show_remote_mode(struct kobject *kobj,
1128 struct kobj_attribute *kattr,
1129 char *buf, int index)
1131 struct device *dev = container_of(kobj->parent, struct device, kobj);
1132 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1133 struct wacom *wacom = hid_get_drvdata(hdev);
1136 mode = wacom->led.select[index];
1137 if (mode >= 0 && mode < 3)
1138 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
1140 return snprintf(buf, PAGE_SIZE, "%d\n", -1);
1143 #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1144 static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1145 struct kobj_attribute *kattr, char *buf) \
1147 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1149 static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1150 .attr = {.name = "remote_mode", \
1151 .mode = DEV_ATTR_RO_PERM}, \
1152 .show = wacom_show_remote##SET_ID##_mode, \
1154 static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1155 &remote##SET_ID##_mode_attr.attr, \
1158 static struct attribute_group remote##SET_ID##_serial_group = { \
1160 .attrs = remote##SET_ID##_serial_attrs, \
1163 DEVICE_EKR_ATTR_GROUP(0);
1164 DEVICE_EKR_ATTR_GROUP(1);
1165 DEVICE_EKR_ATTR_GROUP(2);
1166 DEVICE_EKR_ATTR_GROUP(3);
1167 DEVICE_EKR_ATTR_GROUP(4);
1169 int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int index)
1173 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1175 wacom_wac->serial[index] = serial;
1177 buf = kzalloc(WAC_REMOTE_SERIAL_MAX_STRLEN, GFP_KERNEL);
1180 snprintf(buf, WAC_REMOTE_SERIAL_MAX_STRLEN, "%d", serial);
1181 wacom->remote_group[index].name = buf;
1183 error = sysfs_create_group(wacom->remote_dir,
1184 &wacom->remote_group[index]);
1186 hid_err(wacom->hdev,
1187 "cannot create sysfs group err: %d\n", error);
1188 kobject_put(wacom->remote_dir);
1195 void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial)
1197 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1203 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1204 if (wacom_wac->serial[i] == serial) {
1205 wacom_wac->serial[i] = 0;
1206 wacom->led.select[i] = WACOM_STATUS_UNKNOWN;
1207 if (wacom->remote_group[i].name) {
1208 sysfs_remove_group(wacom->remote_dir,
1209 &wacom->remote_group[i]);
1210 kfree(wacom->remote_group[i].name);
1211 wacom->remote_group[i].name = NULL;
1217 static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector)
1219 const size_t buf_size = 2;
1223 buf = kzalloc(buf_size, GFP_KERNEL);
1227 buf[0] = WAC_CMD_DELETE_PAIRING;
1230 retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf,
1231 buf_size, WAC_CMD_RETRIES);
1237 static ssize_t wacom_store_unpair_remote(struct kobject *kobj,
1238 struct kobj_attribute *attr,
1239 const char *buf, size_t count)
1241 unsigned char selector = 0;
1242 struct device *dev = container_of(kobj->parent, struct device, kobj);
1243 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1244 struct wacom *wacom = hid_get_drvdata(hdev);
1247 if (!strncmp(buf, "*\n", 2)) {
1248 selector = WAC_CMD_UNPAIR_ALL;
1250 hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n",
1255 mutex_lock(&wacom->lock);
1257 err = wacom_cmd_unpair_remote(wacom, selector);
1258 mutex_unlock(&wacom->lock);
1260 return err < 0 ? err : count;
1263 static struct kobj_attribute unpair_remote_attr = {
1264 .attr = {.name = "unpair_remote", .mode = 0200},
1265 .store = wacom_store_unpair_remote,
1268 static const struct attribute *remote_unpair_attrs[] = {
1269 &unpair_remote_attr.attr,
1273 static int wacom_initialize_remote(struct wacom *wacom)
1276 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1279 if (wacom->wacom_wac.features.type != REMOTE)
1282 wacom->remote_group[0] = remote0_serial_group;
1283 wacom->remote_group[1] = remote1_serial_group;
1284 wacom->remote_group[2] = remote2_serial_group;
1285 wacom->remote_group[3] = remote3_serial_group;
1286 wacom->remote_group[4] = remote4_serial_group;
1288 wacom->remote_dir = kobject_create_and_add("wacom_remote",
1289 &wacom->hdev->dev.kobj);
1290 if (!wacom->remote_dir)
1293 error = sysfs_create_files(wacom->remote_dir, remote_unpair_attrs);
1296 hid_err(wacom->hdev,
1297 "cannot create sysfs group err: %d\n", error);
1301 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1302 wacom->led.select[i] = WACOM_STATUS_UNKNOWN;
1303 wacom_wac->serial[i] = 0;
1309 static struct input_dev *wacom_allocate_input(struct wacom *wacom)
1311 struct input_dev *input_dev;
1312 struct hid_device *hdev = wacom->hdev;
1313 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1315 input_dev = input_allocate_device();
1319 input_dev->name = wacom_wac->features.name;
1320 input_dev->phys = hdev->phys;
1321 input_dev->dev.parent = &hdev->dev;
1322 input_dev->open = wacom_open;
1323 input_dev->close = wacom_close;
1324 input_dev->uniq = hdev->uniq;
1325 input_dev->id.bustype = hdev->bus;
1326 input_dev->id.vendor = hdev->vendor;
1327 input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product;
1328 input_dev->id.version = hdev->version;
1329 input_set_drvdata(input_dev, wacom);
1334 static void wacom_clean_inputs(struct wacom *wacom)
1336 if (wacom->wacom_wac.pen_input) {
1337 if (wacom->wacom_wac.pen_registered)
1338 input_unregister_device(wacom->wacom_wac.pen_input);
1340 input_free_device(wacom->wacom_wac.pen_input);
1342 if (wacom->wacom_wac.touch_input) {
1343 if (wacom->wacom_wac.touch_registered)
1344 input_unregister_device(wacom->wacom_wac.touch_input);
1346 input_free_device(wacom->wacom_wac.touch_input);
1348 if (wacom->wacom_wac.pad_input) {
1349 if (wacom->wacom_wac.pad_registered)
1350 input_unregister_device(wacom->wacom_wac.pad_input);
1352 input_free_device(wacom->wacom_wac.pad_input);
1354 if (wacom->remote_dir)
1355 kobject_put(wacom->remote_dir);
1356 wacom->wacom_wac.pen_input = NULL;
1357 wacom->wacom_wac.touch_input = NULL;
1358 wacom->wacom_wac.pad_input = NULL;
1359 wacom_destroy_leds(wacom);
1362 static int wacom_allocate_inputs(struct wacom *wacom)
1364 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1366 wacom_wac->pen_input = wacom_allocate_input(wacom);
1367 wacom_wac->touch_input = wacom_allocate_input(wacom);
1368 wacom_wac->pad_input = wacom_allocate_input(wacom);
1369 if (!wacom_wac->pen_input || !wacom_wac->touch_input || !wacom_wac->pad_input) {
1370 wacom_clean_inputs(wacom);
1374 wacom_wac->pen_input->name = wacom_wac->pen_name;
1375 wacom_wac->touch_input->name = wacom_wac->touch_name;
1376 wacom_wac->pad_input->name = wacom_wac->pad_name;
1381 static int wacom_register_inputs(struct wacom *wacom)
1383 struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
1384 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1387 pen_input_dev = wacom_wac->pen_input;
1388 touch_input_dev = wacom_wac->touch_input;
1389 pad_input_dev = wacom_wac->pad_input;
1391 if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
1394 error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
1396 /* no pen in use on this interface */
1397 input_free_device(pen_input_dev);
1398 wacom_wac->pen_input = NULL;
1399 pen_input_dev = NULL;
1401 error = input_register_device(pen_input_dev);
1403 goto fail_register_pen_input;
1404 wacom_wac->pen_registered = true;
1407 error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
1409 /* no touch in use on this interface */
1410 input_free_device(touch_input_dev);
1411 wacom_wac->touch_input = NULL;
1412 touch_input_dev = NULL;
1414 error = input_register_device(touch_input_dev);
1416 goto fail_register_touch_input;
1417 wacom_wac->touch_registered = true;
1420 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
1422 /* no pad in use on this interface */
1423 input_free_device(pad_input_dev);
1424 wacom_wac->pad_input = NULL;
1425 pad_input_dev = NULL;
1427 error = input_register_device(pad_input_dev);
1429 goto fail_register_pad_input;
1430 wacom_wac->pad_registered = true;
1432 error = wacom_initialize_leds(wacom);
1436 error = wacom_initialize_remote(wacom);
1444 wacom_destroy_leds(wacom);
1446 input_unregister_device(pad_input_dev);
1447 pad_input_dev = NULL;
1448 wacom_wac->pad_registered = false;
1449 fail_register_pad_input:
1450 input_unregister_device(touch_input_dev);
1451 wacom_wac->touch_input = NULL;
1452 wacom_wac->touch_registered = false;
1453 fail_register_touch_input:
1454 input_unregister_device(pen_input_dev);
1455 wacom_wac->pen_input = NULL;
1456 wacom_wac->pen_registered = false;
1457 fail_register_pen_input:
1461 static void wacom_wireless_work(struct work_struct *work)
1463 struct wacom *wacom = container_of(work, struct wacom, work);
1464 struct usb_device *usbdev = wacom->usbdev;
1465 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1466 struct hid_device *hdev1, *hdev2;
1467 struct wacom *wacom1, *wacom2;
1468 struct wacom_wac *wacom_wac1, *wacom_wac2;
1472 * Regardless if this is a disconnect or a new tablet,
1473 * remove any existing input and battery devices.
1476 wacom_destroy_battery(wacom);
1478 /* Stylus interface */
1479 hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
1480 wacom1 = hid_get_drvdata(hdev1);
1481 wacom_wac1 = &(wacom1->wacom_wac);
1482 wacom_clean_inputs(wacom1);
1484 /* Touch interface */
1485 hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
1486 wacom2 = hid_get_drvdata(hdev2);
1487 wacom_wac2 = &(wacom2->wacom_wac);
1488 wacom_clean_inputs(wacom2);
1490 if (wacom_wac->pid == 0) {
1491 hid_info(wacom->hdev, "wireless tablet disconnected\n");
1492 wacom_wac1->shared->type = 0;
1494 const struct hid_device_id *id = wacom_ids;
1496 hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
1500 if (id->vendor == USB_VENDOR_ID_WACOM &&
1501 id->product == wacom_wac->pid)
1507 hid_info(wacom->hdev, "ignoring unknown PID.\n");
1511 /* Stylus interface */
1512 wacom_wac1->features =
1513 *((struct wacom_features *)id->driver_data);
1514 wacom_wac1->features.device_type |= WACOM_DEVICETYPE_PEN;
1515 if (wacom_wac1->features.type != INTUOSHT &&
1516 wacom_wac1->features.type != BAMBOO_PT)
1517 wacom_wac1->features.device_type |= WACOM_DEVICETYPE_PAD;
1518 snprintf(wacom_wac1->pen_name, WACOM_NAME_MAX, "%s (WL) Pen",
1519 wacom_wac1->features.name);
1520 snprintf(wacom_wac1->pad_name, WACOM_NAME_MAX, "%s (WL) Pad",
1521 wacom_wac1->features.name);
1522 wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max;
1523 wacom_wac1->shared->type = wacom_wac1->features.type;
1524 wacom_wac1->pid = wacom_wac->pid;
1525 error = wacom_allocate_inputs(wacom1) ||
1526 wacom_register_inputs(wacom1);
1530 /* Touch interface */
1531 if (wacom_wac1->features.touch_max ||
1532 wacom_wac1->features.type == INTUOSHT) {
1533 wacom_wac2->features =
1534 *((struct wacom_features *)id->driver_data);
1535 wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
1536 wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
1537 snprintf(wacom_wac2->touch_name, WACOM_NAME_MAX,
1538 "%s (WL) Finger",wacom_wac2->features.name);
1539 snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX,
1540 "%s (WL) Pad",wacom_wac2->features.name);
1541 if (wacom_wac1->features.touch_max)
1542 wacom_wac2->features.device_type |= WACOM_DEVICETYPE_TOUCH;
1543 if (wacom_wac1->features.type == INTUOSHT ||
1544 wacom_wac1->features.type == BAMBOO_PT)
1545 wacom_wac2->features.device_type |= WACOM_DEVICETYPE_PAD;
1546 wacom_wac2->pid = wacom_wac->pid;
1547 error = wacom_allocate_inputs(wacom2) ||
1548 wacom_register_inputs(wacom2);
1552 if (wacom_wac1->features.type == INTUOSHT &&
1553 wacom_wac1->features.touch_max)
1554 wacom_wac->shared->touch_input = wacom_wac2->touch_input;
1557 error = wacom_initialize_battery(wacom);
1565 wacom_clean_inputs(wacom1);
1566 wacom_clean_inputs(wacom2);
1570 void wacom_battery_work(struct work_struct *work)
1572 struct wacom *wacom = container_of(work, struct wacom, work);
1574 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1576 wacom_initialize_battery(wacom);
1578 else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1580 wacom_destroy_battery(wacom);
1585 * Not all devices report physical dimensions from HID.
1586 * Compute the default from hardcoded logical dimension
1587 * and resolution before driver overwrites them.
1589 static void wacom_set_default_phy(struct wacom_features *features)
1591 if (features->x_resolution) {
1592 features->x_phy = (features->x_max * 100) /
1593 features->x_resolution;
1594 features->y_phy = (features->y_max * 100) /
1595 features->y_resolution;
1599 static void wacom_calculate_res(struct wacom_features *features)
1601 /* set unit to "100th of a mm" for devices not reported by HID */
1602 if (!features->unit) {
1603 features->unit = 0x11;
1604 features->unitExpo = -3;
1607 features->x_resolution = wacom_calc_hid_res(features->x_max,
1610 features->unitExpo);
1611 features->y_resolution = wacom_calc_hid_res(features->y_max,
1614 features->unitExpo);
1617 static size_t wacom_compute_pktlen(struct hid_device *hdev)
1619 struct hid_report_enum *report_enum;
1620 struct hid_report *report;
1623 report_enum = hdev->report_enum + HID_INPUT_REPORT;
1625 list_for_each_entry(report, &report_enum->report_list, list) {
1626 size_t report_size = hid_report_len(report);
1627 if (report_size > size)
1634 static void wacom_update_name(struct wacom *wacom)
1636 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1637 struct wacom_features *features = &wacom_wac->features;
1638 char name[WACOM_NAME_MAX];
1640 /* Generic devices name unspecified */
1641 if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
1642 if (strstr(wacom->hdev->name, "Wacom") ||
1643 strstr(wacom->hdev->name, "wacom") ||
1644 strstr(wacom->hdev->name, "WACOM")) {
1645 /* name is in HID descriptor, use it */
1646 strlcpy(name, wacom->hdev->name, sizeof(name));
1648 /* strip out excess whitespaces */
1650 char *gap = strstr(name, " ");
1653 /* shift everything including the terminator */
1654 memmove(gap, gap+1, strlen(gap));
1656 /* get rid of trailing whitespace */
1657 if (name[strlen(name)-1] == ' ')
1658 name[strlen(name)-1] = '\0';
1660 /* no meaningful name retrieved. use product ID */
1661 snprintf(name, sizeof(name),
1662 "%s %X", features->name, wacom->hdev->product);
1665 strlcpy(name, features->name, sizeof(name));
1668 /* Append the device type to the name */
1669 snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
1671 snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
1673 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1677 static int wacom_probe(struct hid_device *hdev,
1678 const struct hid_device_id *id)
1680 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
1681 struct usb_device *dev = interface_to_usbdev(intf);
1682 struct wacom *wacom;
1683 struct wacom_wac *wacom_wac;
1684 struct wacom_features *features;
1686 unsigned int connect_mask = HID_CONNECT_HIDRAW;
1688 if (!id->driver_data)
1691 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
1693 /* hid-core sets this quirk for the boot interface */
1694 hdev->quirks &= ~HID_QUIRK_NOGET;
1696 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
1700 hid_set_drvdata(hdev, wacom);
1703 /* ask for the report descriptor to be loaded by HID */
1704 error = hid_parse(hdev);
1706 hid_err(hdev, "parse failed\n");
1710 wacom_wac = &wacom->wacom_wac;
1711 wacom_wac->features = *((struct wacom_features *)id->driver_data);
1712 features = &wacom_wac->features;
1713 features->pktlen = wacom_compute_pktlen(hdev);
1714 if (features->pktlen > WACOM_PKGLEN_MAX) {
1719 if (features->check_for_hid_type && features->hid_type != hdev->type) {
1724 wacom->usbdev = dev;
1726 mutex_init(&wacom->lock);
1727 INIT_WORK(&wacom->work, wacom_wireless_work);
1729 error = wacom_allocate_inputs(wacom);
1731 goto fail_allocate_inputs;
1734 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
1735 * into debug mode for the touch part.
1736 * We ignore the other interfaces.
1738 if (features->type == BAMBOO_PAD) {
1739 if (features->pktlen == WACOM_PKGLEN_PENABLED) {
1740 features->type = HID_GENERIC;
1741 } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
1742 (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
1744 goto fail_shared_data;
1748 /* set the default size in case we do not get them from hid */
1749 wacom_set_default_phy(features);
1751 /* Retrieve the physical and logical size for touch devices */
1752 wacom_retrieve_hid_descriptor(hdev, features);
1753 wacom_setup_device_quirks(wacom);
1755 if (features->device_type == WACOM_DEVICETYPE_NONE &&
1756 features->type != WIRELESS) {
1757 error = features->type == HID_GENERIC ? -ENODEV : 0;
1759 dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
1761 error ? "Ignoring" : "Assuming pen");
1764 goto fail_shared_data;
1766 features->device_type |= WACOM_DEVICETYPE_PEN;
1769 wacom_calculate_res(features);
1771 wacom_update_name(wacom);
1773 error = wacom_add_shared_data(hdev);
1775 goto fail_shared_data;
1777 if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
1778 (features->quirks & WACOM_QUIRK_BATTERY)) {
1779 error = wacom_initialize_battery(wacom);
1784 error = wacom_register_inputs(wacom);
1786 goto fail_register_inputs;
1788 if (hdev->bus == BUS_BLUETOOTH) {
1789 error = device_create_file(&hdev->dev, &dev_attr_speed);
1792 "can't create sysfs speed attribute err: %d\n",
1796 if (features->type == HID_GENERIC)
1797 connect_mask |= HID_CONNECT_DRIVER;
1799 /* Regular HID work starts now */
1800 error = hid_hw_start(hdev, connect_mask);
1802 hid_err(hdev, "hw start failed\n");
1806 /* Note that if query fails it is not a hard failure */
1807 wacom_query_tablet_data(hdev, features);
1809 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
1810 error = hid_hw_open(hdev);
1812 if (wacom_wac->features.type == INTUOSHT &&
1813 wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) {
1814 wacom_wac->shared->touch_input = wacom_wac->touch_input;
1820 if (hdev->bus == BUS_BLUETOOTH)
1821 device_remove_file(&hdev->dev, &dev_attr_speed);
1822 fail_register_inputs:
1823 wacom_clean_inputs(wacom);
1824 wacom_destroy_battery(wacom);
1826 wacom_remove_shared_data(wacom);
1828 wacom_clean_inputs(wacom);
1829 fail_allocate_inputs:
1834 hid_set_drvdata(hdev, NULL);
1838 static void wacom_remove(struct hid_device *hdev)
1840 struct wacom *wacom = hid_get_drvdata(hdev);
1844 cancel_work_sync(&wacom->work);
1845 wacom_clean_inputs(wacom);
1846 if (hdev->bus == BUS_BLUETOOTH)
1847 device_remove_file(&hdev->dev, &dev_attr_speed);
1848 wacom_destroy_battery(wacom);
1849 wacom_remove_shared_data(wacom);
1851 hid_set_drvdata(hdev, NULL);
1856 static int wacom_resume(struct hid_device *hdev)
1858 struct wacom *wacom = hid_get_drvdata(hdev);
1859 struct wacom_features *features = &wacom->wacom_wac.features;
1861 mutex_lock(&wacom->lock);
1863 /* switch to wacom mode first */
1864 wacom_query_tablet_data(hdev, features);
1865 wacom_led_control(wacom);
1867 mutex_unlock(&wacom->lock);
1872 static int wacom_reset_resume(struct hid_device *hdev)
1874 return wacom_resume(hdev);
1876 #endif /* CONFIG_PM */
1878 static struct hid_driver wacom_driver = {
1880 .id_table = wacom_ids,
1881 .probe = wacom_probe,
1882 .remove = wacom_remove,
1883 .report = wacom_wac_report,
1885 .resume = wacom_resume,
1886 .reset_resume = wacom_reset_resume,
1888 .raw_event = wacom_raw_event,
1890 module_hid_driver(wacom_driver);
1892 MODULE_VERSION(DRIVER_VERSION);
1893 MODULE_AUTHOR(DRIVER_AUTHOR);
1894 MODULE_DESCRIPTION(DRIVER_DESC);
1895 MODULE_LICENSE(DRIVER_LICENSE);