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"
17 /* defines to get HID report descriptor */
18 #define HID_DEVICET_HID (USB_TYPE_CLASS | 0x01)
19 #define HID_DEVICET_REPORT (USB_TYPE_CLASS | 0x02)
20 #define HID_USAGE_UNDEFINED 0x00
21 #define HID_USAGE_PAGE 0x05
22 #define HID_USAGE_PAGE_DIGITIZER 0x0d
23 #define HID_USAGE_PAGE_DESKTOP 0x01
24 #define HID_USAGE 0x09
25 #define HID_USAGE_X 0x30
26 #define HID_USAGE_Y 0x31
27 #define HID_USAGE_X_TILT 0x3d
28 #define HID_USAGE_Y_TILT 0x3e
29 #define HID_USAGE_FINGER 0x22
30 #define HID_USAGE_STYLUS 0x20
31 #define HID_COLLECTION 0xa1
32 #define HID_COLLECTION_LOGICAL 0x02
33 #define HID_COLLECTION_END 0xc0
41 struct hid_descriptor {
42 struct usb_descriptor_header header;
47 __le16 wDescriptorLength;
48 } __attribute__ ((packed));
50 /* defines to get/set USB message */
51 #define USB_REQ_GET_REPORT 0x01
52 #define USB_REQ_SET_REPORT 0x09
54 #define WAC_HID_FEATURE_REPORT 0x03
55 #define WAC_MSG_RETRIES 5
57 #define WAC_CMD_LED_CONTROL 0x20
58 #define WAC_CMD_ICON_START 0x21
59 #define WAC_CMD_ICON_XFER 0x23
60 #define WAC_CMD_RETRIES 10
62 static int wacom_get_report(struct usb_interface *intf, u8 type, u8 id,
63 void *buf, size_t size, unsigned int retries)
65 struct usb_device *dev = interface_to_usbdev(intf);
69 retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
71 USB_DIR_IN | USB_TYPE_CLASS |
74 intf->altsetting[0].desc.bInterfaceNumber,
76 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
81 static int wacom_set_report(struct usb_interface *intf, u8 type, u8 id,
82 void *buf, size_t size, unsigned int retries)
84 struct usb_device *dev = interface_to_usbdev(intf);
88 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
90 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
92 intf->altsetting[0].desc.bInterfaceNumber,
94 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
99 static void wacom_sys_irq(struct urb *urb)
101 struct wacom *wacom = urb->context;
102 struct device *dev = &wacom->intf->dev;
105 switch (urb->status) {
112 /* this urb is terminated, clean up */
113 dev_dbg(dev, "%s - urb shutting down with status: %d\n",
114 __func__, urb->status);
117 dev_dbg(dev, "%s - nonzero urb status received: %d\n",
118 __func__, urb->status);
122 wacom_wac_irq(&wacom->wacom_wac, urb->actual_length);
125 usb_mark_last_busy(wacom->usbdev);
126 retval = usb_submit_urb(urb, GFP_ATOMIC);
128 dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
132 static int wacom_open(struct input_dev *dev)
134 struct wacom *wacom = input_get_drvdata(dev);
137 if (usb_autopm_get_interface(wacom->intf) < 0)
140 mutex_lock(&wacom->lock);
142 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
148 wacom->intf->needs_remote_wakeup = 1;
151 mutex_unlock(&wacom->lock);
152 usb_autopm_put_interface(wacom->intf);
156 static void wacom_close(struct input_dev *dev)
158 struct wacom *wacom = input_get_drvdata(dev);
161 autopm_error = usb_autopm_get_interface(wacom->intf);
163 mutex_lock(&wacom->lock);
164 usb_kill_urb(wacom->irq);
166 wacom->intf->needs_remote_wakeup = 0;
167 mutex_unlock(&wacom->lock);
170 usb_autopm_put_interface(wacom->intf);
174 * Static values for max X/Y and resolution of Pen interface is stored in
175 * features. This mean physical size of active area can be computed.
176 * This is useful to do when Pen and Touch have same active area of tablet.
177 * This means for Touch device, we only need to find max X/Y value and we
178 * have enough information to compute resolution of touch.
180 static void wacom_set_phy_from_res(struct wacom_features *features)
182 features->x_phy = (features->x_max * 100) / features->x_resolution;
183 features->y_phy = (features->y_max * 100) / features->y_resolution;
186 static int wacom_parse_logical_collection(unsigned char *report,
187 struct wacom_features *features)
191 if (features->type == BAMBOO_PT) {
193 /* Logical collection is only used by 3rd gen Bamboo Touch */
194 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
195 features->device_type = BTN_TOOL_FINGER;
197 wacom_set_phy_from_res(features);
199 features->x_max = features->y_max =
200 get_unaligned_le16(&report[10]);
208 * Interface Descriptor of wacom devices can be incomplete and
209 * inconsistent so wacom_features table is used to store stylus
210 * device's packet lengths, various maximum values, and tablet
211 * resolution based on product ID's.
213 * For devices that contain 2 interfaces, wacom_features table is
214 * inaccurate for the touch interface. Since the Interface Descriptor
215 * for touch interfaces has pretty complete data, this function exists
216 * to query tablet for this missing information instead of hard coding in
217 * an additional table.
219 * A typical Interface Descriptor for a stylus will contain a
220 * boot mouse application collection that is not of interest and this
221 * function will ignore it.
223 * It also contains a digitizer application collection that also is not
224 * of interest since any information it contains would be duplicate
225 * of what is in wacom_features. Usually it defines a report of an array
226 * of bytes that could be used as max length of the stylus packet returned.
227 * If it happens to define a Digitizer-Stylus Physical Collection then
228 * the X and Y logical values contain valid data but it is ignored.
230 * A typical Interface Descriptor for a touch interface will contain a
231 * Digitizer-Finger Physical Collection which will define both logical
232 * X/Y maximum as well as the physical size of tablet. Since touch
233 * interfaces haven't supported pressure or distance, this is enough
234 * information to override invalid values in the wacom_features table.
236 * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical
237 * Collection. Instead they define a Logical Collection with a single
238 * Logical Maximum for both X and Y.
240 static int wacom_parse_hid(struct usb_interface *intf,
241 struct hid_descriptor *hid_desc,
242 struct wacom_features *features)
244 struct usb_device *dev = interface_to_usbdev(intf);
246 /* result has to be defined as int for some devices */
248 int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
249 unsigned char *report;
251 report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
255 /* retrive report descriptors */
257 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
258 USB_REQ_GET_DESCRIPTOR,
259 USB_RECIP_INTERFACE | USB_DIR_IN,
260 HID_DEVICET_REPORT << 8,
261 intf->altsetting[0].desc.bInterfaceNumber, /* interface */
263 hid_desc->wDescriptorLength,
265 } while (result < 0 && limit++ < WAC_MSG_RETRIES);
267 /* No need to parse the Descriptor. It isn't an error though */
271 for (i = 0; i < hid_desc->wDescriptorLength; i++) {
275 switch (report[i + 1]) {
276 case HID_USAGE_PAGE_DIGITIZER:
277 usage = WCM_DIGITIZER;
281 case HID_USAGE_PAGE_DESKTOP:
289 switch (report[i + 1]) {
291 if (usage == WCM_DESKTOP) {
293 features->device_type = BTN_TOOL_FINGER;
294 if (features->type == TABLETPC2FG) {
295 /* need to reset back */
296 features->pktlen = WACOM_PKGLEN_TPC2FG;
298 if (features->type == BAMBOO_PT) {
299 /* need to reset back */
300 features->pktlen = WACOM_PKGLEN_BBTOUCH;
302 get_unaligned_le16(&report[i + 5]);
304 get_unaligned_le16(&report[i + 8]);
308 get_unaligned_le16(&report[i + 3]);
310 get_unaligned_le16(&report[i + 6]);
311 features->unit = report[i + 9];
312 features->unitExpo = report[i + 11];
316 /* penabled only accepts exact bytes of data */
317 if (features->type == TABLETPC2FG)
318 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
319 features->device_type = BTN_TOOL_PEN;
321 get_unaligned_le16(&report[i + 3]);
328 if (usage == WCM_DESKTOP) {
330 features->device_type = BTN_TOOL_FINGER;
331 if (features->type == TABLETPC2FG) {
332 /* need to reset back */
333 features->pktlen = WACOM_PKGLEN_TPC2FG;
335 get_unaligned_le16(&report[i + 3]);
337 get_unaligned_le16(&report[i + 6]);
339 } else if (features->type == BAMBOO_PT) {
340 /* need to reset back */
341 features->pktlen = WACOM_PKGLEN_BBTOUCH;
343 get_unaligned_le16(&report[i + 3]);
345 get_unaligned_le16(&report[i + 6]);
351 get_unaligned_le16(&report[i + 3]);
355 /* penabled only accepts exact bytes of data */
356 if (features->type == TABLETPC2FG)
357 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
358 features->device_type = BTN_TOOL_PEN;
360 get_unaligned_le16(&report[i + 3]);
366 case HID_USAGE_FINGER:
372 * Requiring Stylus Usage will ignore boot mouse
373 * X/Y values and some cases of invalid Digitizer X/Y
374 * values commonly reported.
376 case HID_USAGE_STYLUS:
383 case HID_COLLECTION_END:
384 /* reset UsagePage and Finger */
391 case HID_COLLECTION_LOGICAL:
392 i += wacom_parse_logical_collection(&report[i],
406 static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
408 unsigned char *rep_data;
409 int limit = 0, report_id = 2;
412 rep_data = kmalloc(4, GFP_KERNEL);
416 /* ask to report tablet data if it is MT Tablet PC or
418 if (features->type == TABLETPC2FG) {
425 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
426 report_id, rep_data, 4, 1);
428 error = wacom_get_report(intf,
429 WAC_HID_FEATURE_REPORT,
430 report_id, rep_data, 4, 1);
431 } while ((error < 0 || rep_data[1] != 4) && limit++ < WAC_MSG_RETRIES);
432 } else if (features->type != TABLETPC &&
433 features->type != WIRELESS &&
434 features->device_type == BTN_TOOL_PEN) {
438 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
439 report_id, rep_data, 2, 1);
441 error = wacom_get_report(intf,
442 WAC_HID_FEATURE_REPORT,
443 report_id, rep_data, 2, 1);
444 } while ((error < 0 || rep_data[1] != 2) && limit++ < WAC_MSG_RETRIES);
449 return error < 0 ? error : 0;
452 static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
453 struct wacom_features *features)
456 struct usb_host_interface *interface = intf->cur_altsetting;
457 struct hid_descriptor *hid_desc;
459 /* default features */
460 features->device_type = BTN_TOOL_PEN;
461 features->x_fuzz = 4;
462 features->y_fuzz = 4;
463 features->pressure_fuzz = 0;
464 features->distance_fuzz = 0;
467 * The wireless device HID is basic and layout conflicts with
468 * other tablets (monitor and touch interface can look like pen).
469 * Skip the query for this type and modify defaults based on
472 if (features->type == WIRELESS) {
473 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
474 features->device_type = 0;
475 } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
476 features->device_type = BTN_TOOL_DOUBLETAP;
477 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
481 /* only Tablet PCs and Bamboo P&T need to retrieve the info */
482 if ((features->type != TABLETPC) && (features->type != TABLETPC2FG) &&
483 (features->type != BAMBOO_PT))
486 if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) {
487 if (usb_get_extra_descriptor(&interface->endpoint[0],
488 HID_DEVICET_REPORT, &hid_desc)) {
489 printk("wacom: can not retrieve extra class descriptor\n");
494 error = wacom_parse_hid(intf, hid_desc, features);
502 struct wacom_usbdev_data {
503 struct list_head list;
505 struct usb_device *dev;
506 struct wacom_shared shared;
509 static LIST_HEAD(wacom_udev_list);
510 static DEFINE_MUTEX(wacom_udev_list_lock);
512 static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev)
514 struct wacom_usbdev_data *data;
516 list_for_each_entry(data, &wacom_udev_list, list) {
517 if (data->dev == dev) {
518 kref_get(&data->kref);
526 static int wacom_add_shared_data(struct wacom_wac *wacom,
527 struct usb_device *dev)
529 struct wacom_usbdev_data *data;
532 mutex_lock(&wacom_udev_list_lock);
534 data = wacom_get_usbdev_data(dev);
536 data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL);
542 kref_init(&data->kref);
544 list_add_tail(&data->list, &wacom_udev_list);
547 wacom->shared = &data->shared;
550 mutex_unlock(&wacom_udev_list_lock);
554 static void wacom_release_shared_data(struct kref *kref)
556 struct wacom_usbdev_data *data =
557 container_of(kref, struct wacom_usbdev_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_wac *wacom)
568 struct wacom_usbdev_data *data;
571 data = container_of(wacom->shared, struct wacom_usbdev_data, shared);
572 kref_put(&data->kref, wacom_release_shared_data);
573 wacom->shared = NULL;
577 static int wacom_led_control(struct wacom *wacom)
582 buf = kzalloc(9, GFP_KERNEL);
586 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
587 wacom->wacom_wac.features.type == WACOM_24HD)
588 led = (wacom->led.select[1] << 4) | 0x40;
590 led |= wacom->led.select[0] | 0x4;
592 buf[0] = WAC_CMD_LED_CONTROL;
594 buf[2] = wacom->led.llv;
595 buf[3] = wacom->led.hlv;
596 buf[4] = wacom->led.img_lum;
598 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL,
599 buf, 9, WAC_CMD_RETRIES);
605 static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
610 buf = kzalloc(259, GFP_KERNEL);
614 /* Send 'start' command */
615 buf[0] = WAC_CMD_ICON_START;
617 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
618 buf, 2, WAC_CMD_RETRIES);
622 buf[0] = WAC_CMD_ICON_XFER;
623 buf[1] = button_id & 0x07;
624 for (i = 0; i < 4; i++) {
626 memcpy(buf + 3, img + i * 256, 256);
628 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER,
629 buf, 259, WAC_CMD_RETRIES);
635 buf[0] = WAC_CMD_ICON_START;
637 wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
638 buf, 2, WAC_CMD_RETRIES);
645 static ssize_t wacom_led_select_store(struct device *dev, int set_id,
646 const char *buf, size_t count)
648 struct wacom *wacom = dev_get_drvdata(dev);
652 err = kstrtouint(buf, 10, &id);
656 mutex_lock(&wacom->lock);
658 wacom->led.select[set_id] = id & 0x3;
659 err = wacom_led_control(wacom);
661 mutex_unlock(&wacom->lock);
663 return err < 0 ? err : count;
666 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
667 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
668 struct device_attribute *attr, const char *buf, size_t count) \
670 return wacom_led_select_store(dev, SET_ID, buf, count); \
672 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
673 struct device_attribute *attr, char *buf) \
675 struct wacom *wacom = dev_get_drvdata(dev); \
676 return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
678 static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
679 wacom_led##SET_ID##_select_show, \
680 wacom_led##SET_ID##_select_store)
682 DEVICE_LED_SELECT_ATTR(0);
683 DEVICE_LED_SELECT_ATTR(1);
685 static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
686 const char *buf, size_t count)
691 err = kstrtouint(buf, 10, &value);
695 mutex_lock(&wacom->lock);
697 *dest = value & 0x7f;
698 err = wacom_led_control(wacom);
700 mutex_unlock(&wacom->lock);
702 return err < 0 ? err : count;
705 #define DEVICE_LUMINANCE_ATTR(name, field) \
706 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
707 struct device_attribute *attr, const char *buf, size_t count) \
709 struct wacom *wacom = dev_get_drvdata(dev); \
711 return wacom_luminance_store(wacom, &wacom->led.field, \
714 static DEVICE_ATTR(name##_luminance, S_IWUSR, \
715 NULL, wacom_##name##_luminance_store)
717 DEVICE_LUMINANCE_ATTR(status0, llv);
718 DEVICE_LUMINANCE_ATTR(status1, hlv);
719 DEVICE_LUMINANCE_ATTR(buttons, img_lum);
721 static ssize_t wacom_button_image_store(struct device *dev, int button_id,
722 const char *buf, size_t count)
724 struct wacom *wacom = dev_get_drvdata(dev);
730 mutex_lock(&wacom->lock);
732 err = wacom_led_putimage(wacom, button_id, buf);
734 mutex_unlock(&wacom->lock);
736 return err < 0 ? err : count;
739 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
740 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
741 struct device_attribute *attr, const char *buf, size_t count) \
743 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
745 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
746 NULL, wacom_btnimg##BUTTON_ID##_store)
748 DEVICE_BTNIMG_ATTR(0);
749 DEVICE_BTNIMG_ATTR(1);
750 DEVICE_BTNIMG_ATTR(2);
751 DEVICE_BTNIMG_ATTR(3);
752 DEVICE_BTNIMG_ATTR(4);
753 DEVICE_BTNIMG_ATTR(5);
754 DEVICE_BTNIMG_ATTR(6);
755 DEVICE_BTNIMG_ATTR(7);
757 static struct attribute *cintiq_led_attrs[] = {
758 &dev_attr_status_led0_select.attr,
759 &dev_attr_status_led1_select.attr,
763 static struct attribute_group cintiq_led_attr_group = {
765 .attrs = cintiq_led_attrs,
768 static struct attribute *intuos4_led_attrs[] = {
769 &dev_attr_status0_luminance.attr,
770 &dev_attr_status1_luminance.attr,
771 &dev_attr_status_led0_select.attr,
772 &dev_attr_buttons_luminance.attr,
773 &dev_attr_button0_rawimg.attr,
774 &dev_attr_button1_rawimg.attr,
775 &dev_attr_button2_rawimg.attr,
776 &dev_attr_button3_rawimg.attr,
777 &dev_attr_button4_rawimg.attr,
778 &dev_attr_button5_rawimg.attr,
779 &dev_attr_button6_rawimg.attr,
780 &dev_attr_button7_rawimg.attr,
784 static struct attribute_group intuos4_led_attr_group = {
786 .attrs = intuos4_led_attrs,
789 static int wacom_initialize_leds(struct wacom *wacom)
793 /* Initialize default values */
794 switch (wacom->wacom_wac.features.type) {
797 wacom->led.select[0] = 0;
798 wacom->led.select[1] = 0;
801 wacom->led.img_lum = 10;
802 error = sysfs_create_group(&wacom->intf->dev.kobj,
803 &intuos4_led_attr_group);
808 wacom->led.select[0] = 0;
809 wacom->led.select[1] = 0;
812 wacom->led.img_lum = 0;
814 error = sysfs_create_group(&wacom->intf->dev.kobj,
815 &cintiq_led_attr_group);
823 dev_err(&wacom->intf->dev,
824 "cannot create sysfs group err: %d\n", error);
827 wacom_led_control(wacom);
832 static void wacom_destroy_leds(struct wacom *wacom)
834 switch (wacom->wacom_wac.features.type) {
837 sysfs_remove_group(&wacom->intf->dev.kobj,
838 &intuos4_led_attr_group);
843 sysfs_remove_group(&wacom->intf->dev.kobj,
844 &cintiq_led_attr_group);
849 static enum power_supply_property wacom_battery_props[] = {
850 POWER_SUPPLY_PROP_CAPACITY
853 static int wacom_battery_get_property(struct power_supply *psy,
854 enum power_supply_property psp,
855 union power_supply_propval *val)
857 struct wacom *wacom = container_of(psy, struct wacom, battery);
861 case POWER_SUPPLY_PROP_CAPACITY:
863 wacom->wacom_wac.battery_capacity * 100 / 31;
873 static int wacom_initialize_battery(struct wacom *wacom)
877 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) {
878 wacom->battery.properties = wacom_battery_props;
879 wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
880 wacom->battery.get_property = wacom_battery_get_property;
881 wacom->battery.name = "wacom_battery";
882 wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
883 wacom->battery.use_for_apm = 0;
885 error = power_supply_register(&wacom->usbdev->dev,
892 static void wacom_destroy_battery(struct wacom *wacom)
894 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR)
895 power_supply_unregister(&wacom->battery);
898 static int wacom_register_input(struct wacom *wacom)
900 struct input_dev *input_dev;
901 struct usb_interface *intf = wacom->intf;
902 struct usb_device *dev = interface_to_usbdev(intf);
903 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
906 input_dev = input_allocate_device();
910 input_dev->name = wacom_wac->name;
911 input_dev->dev.parent = &intf->dev;
912 input_dev->open = wacom_open;
913 input_dev->close = wacom_close;
914 usb_to_input_id(dev, &input_dev->id);
915 input_set_drvdata(input_dev, wacom);
917 wacom_wac->input = input_dev;
918 wacom_setup_input_capabilities(input_dev, wacom_wac);
920 error = input_register_device(input_dev);
922 input_free_device(input_dev);
923 wacom_wac->input = NULL;
929 static void wacom_wireless_work(struct work_struct *work)
931 struct wacom *wacom = container_of(work, struct wacom, work);
932 struct usb_device *usbdev = wacom->usbdev;
933 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
936 * Regardless if this is a disconnect or a new tablet,
937 * remove any existing input devices.
940 /* Stylus interface */
941 wacom = usb_get_intfdata(usbdev->config->interface[1]);
942 if (wacom->wacom_wac.input)
943 input_unregister_device(wacom->wacom_wac.input);
944 wacom->wacom_wac.input = 0;
946 /* Touch interface */
947 wacom = usb_get_intfdata(usbdev->config->interface[2]);
948 if (wacom->wacom_wac.input)
949 input_unregister_device(wacom->wacom_wac.input);
950 wacom->wacom_wac.input = 0;
952 if (wacom_wac->pid == 0) {
953 printk(KERN_INFO "wacom: wireless tablet disconnected\n");
955 const struct usb_device_id *id = wacom_ids;
958 "wacom: wireless tablet connected with PID %x\n",
961 while (id->match_flags) {
962 if (id->idVendor == USB_VENDOR_ID_WACOM &&
963 id->idProduct == wacom_wac->pid)
968 if (!id->match_flags) {
970 "wacom: ignorning unknown PID.\n");
974 /* Stylus interface */
975 wacom = usb_get_intfdata(usbdev->config->interface[1]);
976 wacom_wac = &wacom->wacom_wac;
977 wacom_wac->features =
978 *((struct wacom_features *)id->driver_info);
979 wacom_wac->features.device_type = BTN_TOOL_PEN;
980 wacom_register_input(wacom);
982 /* Touch interface */
983 wacom = usb_get_intfdata(usbdev->config->interface[2]);
984 wacom_wac = &wacom->wacom_wac;
985 wacom_wac->features =
986 *((struct wacom_features *)id->driver_info);
987 wacom_wac->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
988 wacom_wac->features.device_type = BTN_TOOL_FINGER;
989 wacom_set_phy_from_res(&wacom_wac->features);
990 wacom_wac->features.x_max = wacom_wac->features.y_max = 4096;
991 wacom_register_input(wacom);
995 static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
997 struct usb_device *dev = interface_to_usbdev(intf);
998 struct usb_endpoint_descriptor *endpoint;
1000 struct wacom_wac *wacom_wac;
1001 struct wacom_features *features;
1004 if (!id->driver_info)
1007 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
1011 wacom_wac = &wacom->wacom_wac;
1012 wacom_wac->features = *((struct wacom_features *)id->driver_info);
1013 features = &wacom_wac->features;
1014 if (features->pktlen > WACOM_PKGLEN_MAX) {
1019 wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX,
1020 GFP_KERNEL, &wacom->data_dma);
1021 if (!wacom_wac->data) {
1026 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
1032 wacom->usbdev = dev;
1034 mutex_init(&wacom->lock);
1035 INIT_WORK(&wacom->work, wacom_wireless_work);
1036 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
1037 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
1039 endpoint = &intf->cur_altsetting->endpoint[0].desc;
1041 /* Retrieve the physical and logical size for OEM devices */
1042 error = wacom_retrieve_hid_descriptor(intf, features);
1046 wacom_setup_device_quirks(features);
1048 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
1050 if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
1051 /* Append the device type to the name */
1052 strlcat(wacom_wac->name,
1053 features->device_type == BTN_TOOL_PEN ?
1055 sizeof(wacom_wac->name));
1057 error = wacom_add_shared_data(wacom_wac, dev);
1062 usb_fill_int_urb(wacom->irq, dev,
1063 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
1064 wacom_wac->data, features->pktlen,
1065 wacom_sys_irq, wacom, endpoint->bInterval);
1066 wacom->irq->transfer_dma = wacom->data_dma;
1067 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1069 error = wacom_initialize_leds(wacom);
1073 error = wacom_initialize_battery(wacom);
1077 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
1078 error = wacom_register_input(wacom);
1083 /* Note that if query fails it is not a hard failure */
1084 wacom_query_tablet_data(intf, features);
1086 usb_set_intfdata(intf, wacom);
1088 if (features->quirks & WACOM_QUIRK_MONITOR) {
1089 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
1095 fail6: wacom_destroy_battery(wacom);
1096 fail5: wacom_destroy_leds(wacom);
1097 fail4: wacom_remove_shared_data(wacom_wac);
1098 fail3: usb_free_urb(wacom->irq);
1099 fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
1100 fail1: kfree(wacom);
1104 static void wacom_disconnect(struct usb_interface *intf)
1106 struct wacom *wacom = usb_get_intfdata(intf);
1108 usb_set_intfdata(intf, NULL);
1110 usb_kill_urb(wacom->irq);
1111 cancel_work_sync(&wacom->work);
1112 if (wacom->wacom_wac.input)
1113 input_unregister_device(wacom->wacom_wac.input);
1114 wacom_destroy_battery(wacom);
1115 wacom_destroy_leds(wacom);
1116 usb_free_urb(wacom->irq);
1117 usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
1118 wacom->wacom_wac.data, wacom->data_dma);
1119 wacom_remove_shared_data(&wacom->wacom_wac);
1123 static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
1125 struct wacom *wacom = usb_get_intfdata(intf);
1127 mutex_lock(&wacom->lock);
1128 usb_kill_urb(wacom->irq);
1129 mutex_unlock(&wacom->lock);
1134 static int wacom_resume(struct usb_interface *intf)
1136 struct wacom *wacom = usb_get_intfdata(intf);
1137 struct wacom_features *features = &wacom->wacom_wac.features;
1140 mutex_lock(&wacom->lock);
1142 /* switch to wacom mode first */
1143 wacom_query_tablet_data(intf, features);
1144 wacom_led_control(wacom);
1146 if ((wacom->open || features->quirks & WACOM_QUIRK_MONITOR)
1147 && usb_submit_urb(wacom->irq, GFP_NOIO) < 0)
1150 mutex_unlock(&wacom->lock);
1155 static int wacom_reset_resume(struct usb_interface *intf)
1157 return wacom_resume(intf);
1160 static struct usb_driver wacom_driver = {
1162 .id_table = wacom_ids,
1163 .probe = wacom_probe,
1164 .disconnect = wacom_disconnect,
1165 .suspend = wacom_suspend,
1166 .resume = wacom_resume,
1167 .reset_resume = wacom_reset_resume,
1168 .supports_autosuspend = 1,
1171 module_usb_driver(wacom_driver);