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;
104 switch (urb->status) {
111 /* this urb is terminated, clean up */
112 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
115 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
119 wacom_wac_irq(&wacom->wacom_wac, urb->actual_length);
122 usb_mark_last_busy(wacom->usbdev);
123 retval = usb_submit_urb(urb, GFP_ATOMIC);
125 err ("%s - usb_submit_urb failed with result %d",
129 static int wacom_open(struct input_dev *dev)
131 struct wacom *wacom = input_get_drvdata(dev);
134 if (usb_autopm_get_interface(wacom->intf) < 0)
137 mutex_lock(&wacom->lock);
139 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
145 wacom->intf->needs_remote_wakeup = 1;
148 mutex_unlock(&wacom->lock);
149 usb_autopm_put_interface(wacom->intf);
153 static void wacom_close(struct input_dev *dev)
155 struct wacom *wacom = input_get_drvdata(dev);
158 autopm_error = usb_autopm_get_interface(wacom->intf);
160 mutex_lock(&wacom->lock);
161 usb_kill_urb(wacom->irq);
163 wacom->intf->needs_remote_wakeup = 0;
164 mutex_unlock(&wacom->lock);
167 usb_autopm_put_interface(wacom->intf);
171 * Static values for max X/Y and resolution of Pen interface is stored in
172 * features. This mean physical size of active area can be computed.
173 * This is useful to do when Pen and Touch have same active area of tablet.
174 * This means for Touch device, we only need to find max X/Y value and we
175 * have enough information to compute resolution of touch.
177 static void wacom_set_phy_from_res(struct wacom_features *features)
179 features->x_phy = (features->x_max * 100) / features->x_resolution;
180 features->y_phy = (features->y_max * 100) / features->y_resolution;
183 static int wacom_parse_logical_collection(unsigned char *report,
184 struct wacom_features *features)
188 if (features->type == BAMBOO_PT) {
190 /* Logical collection is only used by 3rd gen Bamboo Touch */
191 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
192 features->device_type = BTN_TOOL_FINGER;
194 wacom_set_phy_from_res(features);
196 features->x_max = features->y_max =
197 get_unaligned_le16(&report[10]);
205 * Interface Descriptor of wacom devices can be incomplete and
206 * inconsistent so wacom_features table is used to store stylus
207 * device's packet lengths, various maximum values, and tablet
208 * resolution based on product ID's.
210 * For devices that contain 2 interfaces, wacom_features table is
211 * inaccurate for the touch interface. Since the Interface Descriptor
212 * for touch interfaces has pretty complete data, this function exists
213 * to query tablet for this missing information instead of hard coding in
214 * an additional table.
216 * A typical Interface Descriptor for a stylus will contain a
217 * boot mouse application collection that is not of interest and this
218 * function will ignore it.
220 * It also contains a digitizer application collection that also is not
221 * of interest since any information it contains would be duplicate
222 * of what is in wacom_features. Usually it defines a report of an array
223 * of bytes that could be used as max length of the stylus packet returned.
224 * If it happens to define a Digitizer-Stylus Physical Collection then
225 * the X and Y logical values contain valid data but it is ignored.
227 * A typical Interface Descriptor for a touch interface will contain a
228 * Digitizer-Finger Physical Collection which will define both logical
229 * X/Y maximum as well as the physical size of tablet. Since touch
230 * interfaces haven't supported pressure or distance, this is enough
231 * information to override invalid values in the wacom_features table.
233 * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical
234 * Collection. Instead they define a Logical Collection with a single
235 * Logical Maximum for both X and Y.
237 static int wacom_parse_hid(struct usb_interface *intf,
238 struct hid_descriptor *hid_desc,
239 struct wacom_features *features)
241 struct usb_device *dev = interface_to_usbdev(intf);
243 /* result has to be defined as int for some devices */
245 int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
246 unsigned char *report;
248 report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
252 /* retrive report descriptors */
254 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
255 USB_REQ_GET_DESCRIPTOR,
256 USB_RECIP_INTERFACE | USB_DIR_IN,
257 HID_DEVICET_REPORT << 8,
258 intf->altsetting[0].desc.bInterfaceNumber, /* interface */
260 hid_desc->wDescriptorLength,
262 } while (result < 0 && limit++ < WAC_MSG_RETRIES);
264 /* No need to parse the Descriptor. It isn't an error though */
268 for (i = 0; i < hid_desc->wDescriptorLength; i++) {
272 switch (report[i + 1]) {
273 case HID_USAGE_PAGE_DIGITIZER:
274 usage = WCM_DIGITIZER;
278 case HID_USAGE_PAGE_DESKTOP:
286 switch (report[i + 1]) {
288 if (usage == WCM_DESKTOP) {
290 features->device_type = BTN_TOOL_FINGER;
291 if (features->type == TABLETPC2FG) {
292 /* need to reset back */
293 features->pktlen = WACOM_PKGLEN_TPC2FG;
295 if (features->type == BAMBOO_PT) {
296 /* need to reset back */
297 features->pktlen = WACOM_PKGLEN_BBTOUCH;
299 get_unaligned_le16(&report[i + 5]);
301 get_unaligned_le16(&report[i + 8]);
305 get_unaligned_le16(&report[i + 3]);
307 get_unaligned_le16(&report[i + 6]);
308 features->unit = report[i + 9];
309 features->unitExpo = report[i + 11];
313 /* penabled only accepts exact bytes of data */
314 if (features->type == TABLETPC2FG)
315 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
316 features->device_type = BTN_TOOL_PEN;
318 get_unaligned_le16(&report[i + 3]);
325 if (usage == WCM_DESKTOP) {
327 features->device_type = BTN_TOOL_FINGER;
328 if (features->type == TABLETPC2FG) {
329 /* need to reset back */
330 features->pktlen = WACOM_PKGLEN_TPC2FG;
332 get_unaligned_le16(&report[i + 3]);
334 get_unaligned_le16(&report[i + 6]);
336 } else if (features->type == BAMBOO_PT) {
337 /* need to reset back */
338 features->pktlen = WACOM_PKGLEN_BBTOUCH;
340 get_unaligned_le16(&report[i + 3]);
342 get_unaligned_le16(&report[i + 6]);
348 get_unaligned_le16(&report[i + 3]);
352 /* penabled only accepts exact bytes of data */
353 if (features->type == TABLETPC2FG)
354 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
355 features->device_type = BTN_TOOL_PEN;
357 get_unaligned_le16(&report[i + 3]);
363 case HID_USAGE_FINGER:
369 * Requiring Stylus Usage will ignore boot mouse
370 * X/Y values and some cases of invalid Digitizer X/Y
371 * values commonly reported.
373 case HID_USAGE_STYLUS:
380 case HID_COLLECTION_END:
381 /* reset UsagePage and Finger */
388 case HID_COLLECTION_LOGICAL:
389 i += wacom_parse_logical_collection(&report[i],
403 static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
405 unsigned char *rep_data;
406 int limit = 0, report_id = 2;
409 rep_data = kmalloc(4, GFP_KERNEL);
413 /* ask to report tablet data if it is MT Tablet PC or
415 if (features->type == TABLETPC2FG) {
422 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
423 report_id, rep_data, 4, 1);
425 error = wacom_get_report(intf,
426 WAC_HID_FEATURE_REPORT,
427 report_id, rep_data, 4, 1);
428 } while ((error < 0 || rep_data[1] != 4) && limit++ < WAC_MSG_RETRIES);
429 } else if (features->type != TABLETPC &&
430 features->type != WIRELESS &&
431 features->device_type == BTN_TOOL_PEN) {
435 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
436 report_id, rep_data, 2, 1);
438 error = wacom_get_report(intf,
439 WAC_HID_FEATURE_REPORT,
440 report_id, rep_data, 2, 1);
441 } while ((error < 0 || rep_data[1] != 2) && limit++ < WAC_MSG_RETRIES);
446 return error < 0 ? error : 0;
449 static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
450 struct wacom_features *features)
453 struct usb_host_interface *interface = intf->cur_altsetting;
454 struct hid_descriptor *hid_desc;
456 /* default features */
457 features->device_type = BTN_TOOL_PEN;
458 features->x_fuzz = 4;
459 features->y_fuzz = 4;
460 features->pressure_fuzz = 0;
461 features->distance_fuzz = 0;
464 * The wireless device HID is basic and layout conflicts with
465 * other tablets (monitor and touch interface can look like pen).
466 * Skip the query for this type and modify defaults based on
469 if (features->type == WIRELESS) {
470 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
471 features->device_type = 0;
472 } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
473 features->device_type = BTN_TOOL_DOUBLETAP;
474 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
478 /* only Tablet PCs and Bamboo P&T need to retrieve the info */
479 if ((features->type != TABLETPC) && (features->type != TABLETPC2FG) &&
480 (features->type != BAMBOO_PT))
483 if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) {
484 if (usb_get_extra_descriptor(&interface->endpoint[0],
485 HID_DEVICET_REPORT, &hid_desc)) {
486 printk("wacom: can not retrieve extra class descriptor\n");
491 error = wacom_parse_hid(intf, hid_desc, features);
499 struct wacom_usbdev_data {
500 struct list_head list;
502 struct usb_device *dev;
503 struct wacom_shared shared;
506 static LIST_HEAD(wacom_udev_list);
507 static DEFINE_MUTEX(wacom_udev_list_lock);
509 static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev)
511 struct wacom_usbdev_data *data;
513 list_for_each_entry(data, &wacom_udev_list, list) {
514 if (data->dev == dev) {
515 kref_get(&data->kref);
523 static int wacom_add_shared_data(struct wacom_wac *wacom,
524 struct usb_device *dev)
526 struct wacom_usbdev_data *data;
529 mutex_lock(&wacom_udev_list_lock);
531 data = wacom_get_usbdev_data(dev);
533 data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL);
539 kref_init(&data->kref);
541 list_add_tail(&data->list, &wacom_udev_list);
544 wacom->shared = &data->shared;
547 mutex_unlock(&wacom_udev_list_lock);
551 static void wacom_release_shared_data(struct kref *kref)
553 struct wacom_usbdev_data *data =
554 container_of(kref, struct wacom_usbdev_data, kref);
556 mutex_lock(&wacom_udev_list_lock);
557 list_del(&data->list);
558 mutex_unlock(&wacom_udev_list_lock);
563 static void wacom_remove_shared_data(struct wacom_wac *wacom)
565 struct wacom_usbdev_data *data;
568 data = container_of(wacom->shared, struct wacom_usbdev_data, shared);
569 kref_put(&data->kref, wacom_release_shared_data);
570 wacom->shared = NULL;
574 static int wacom_led_control(struct wacom *wacom)
579 buf = kzalloc(9, GFP_KERNEL);
583 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
584 wacom->wacom_wac.features.type == WACOM_24HD)
585 led = (wacom->led.select[1] << 4) | 0x40;
587 led |= wacom->led.select[0] | 0x4;
589 buf[0] = WAC_CMD_LED_CONTROL;
591 buf[2] = wacom->led.llv;
592 buf[3] = wacom->led.hlv;
593 buf[4] = wacom->led.img_lum;
595 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL,
596 buf, 9, WAC_CMD_RETRIES);
602 static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
607 buf = kzalloc(259, GFP_KERNEL);
611 /* Send 'start' command */
612 buf[0] = WAC_CMD_ICON_START;
614 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
615 buf, 2, WAC_CMD_RETRIES);
619 buf[0] = WAC_CMD_ICON_XFER;
620 buf[1] = button_id & 0x07;
621 for (i = 0; i < 4; i++) {
623 memcpy(buf + 3, img + i * 256, 256);
625 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER,
626 buf, 259, WAC_CMD_RETRIES);
632 buf[0] = WAC_CMD_ICON_START;
634 wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
635 buf, 2, WAC_CMD_RETRIES);
642 static ssize_t wacom_led_select_store(struct device *dev, int set_id,
643 const char *buf, size_t count)
645 struct wacom *wacom = dev_get_drvdata(dev);
649 err = kstrtouint(buf, 10, &id);
653 mutex_lock(&wacom->lock);
655 wacom->led.select[set_id] = id & 0x3;
656 err = wacom_led_control(wacom);
658 mutex_unlock(&wacom->lock);
660 return err < 0 ? err : count;
663 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
664 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
665 struct device_attribute *attr, const char *buf, size_t count) \
667 return wacom_led_select_store(dev, SET_ID, buf, count); \
669 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
670 struct device_attribute *attr, char *buf) \
672 struct wacom *wacom = dev_get_drvdata(dev); \
673 return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
675 static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
676 wacom_led##SET_ID##_select_show, \
677 wacom_led##SET_ID##_select_store)
679 DEVICE_LED_SELECT_ATTR(0);
680 DEVICE_LED_SELECT_ATTR(1);
682 static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
683 const char *buf, size_t count)
688 err = kstrtouint(buf, 10, &value);
692 mutex_lock(&wacom->lock);
694 *dest = value & 0x7f;
695 err = wacom_led_control(wacom);
697 mutex_unlock(&wacom->lock);
699 return err < 0 ? err : count;
702 #define DEVICE_LUMINANCE_ATTR(name, field) \
703 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
704 struct device_attribute *attr, const char *buf, size_t count) \
706 struct wacom *wacom = dev_get_drvdata(dev); \
708 return wacom_luminance_store(wacom, &wacom->led.field, \
711 static DEVICE_ATTR(name##_luminance, S_IWUSR, \
712 NULL, wacom_##name##_luminance_store)
714 DEVICE_LUMINANCE_ATTR(status0, llv);
715 DEVICE_LUMINANCE_ATTR(status1, hlv);
716 DEVICE_LUMINANCE_ATTR(buttons, img_lum);
718 static ssize_t wacom_button_image_store(struct device *dev, int button_id,
719 const char *buf, size_t count)
721 struct wacom *wacom = dev_get_drvdata(dev);
727 mutex_lock(&wacom->lock);
729 err = wacom_led_putimage(wacom, button_id, buf);
731 mutex_unlock(&wacom->lock);
733 return err < 0 ? err : count;
736 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
737 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
738 struct device_attribute *attr, const char *buf, size_t count) \
740 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
742 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
743 NULL, wacom_btnimg##BUTTON_ID##_store)
745 DEVICE_BTNIMG_ATTR(0);
746 DEVICE_BTNIMG_ATTR(1);
747 DEVICE_BTNIMG_ATTR(2);
748 DEVICE_BTNIMG_ATTR(3);
749 DEVICE_BTNIMG_ATTR(4);
750 DEVICE_BTNIMG_ATTR(5);
751 DEVICE_BTNIMG_ATTR(6);
752 DEVICE_BTNIMG_ATTR(7);
754 static struct attribute *cintiq_led_attrs[] = {
755 &dev_attr_status_led0_select.attr,
756 &dev_attr_status_led1_select.attr,
760 static struct attribute_group cintiq_led_attr_group = {
762 .attrs = cintiq_led_attrs,
765 static struct attribute *intuos4_led_attrs[] = {
766 &dev_attr_status0_luminance.attr,
767 &dev_attr_status1_luminance.attr,
768 &dev_attr_status_led0_select.attr,
769 &dev_attr_buttons_luminance.attr,
770 &dev_attr_button0_rawimg.attr,
771 &dev_attr_button1_rawimg.attr,
772 &dev_attr_button2_rawimg.attr,
773 &dev_attr_button3_rawimg.attr,
774 &dev_attr_button4_rawimg.attr,
775 &dev_attr_button5_rawimg.attr,
776 &dev_attr_button6_rawimg.attr,
777 &dev_attr_button7_rawimg.attr,
781 static struct attribute_group intuos4_led_attr_group = {
783 .attrs = intuos4_led_attrs,
786 static int wacom_initialize_leds(struct wacom *wacom)
790 /* Initialize default values */
791 switch (wacom->wacom_wac.features.type) {
794 wacom->led.select[0] = 0;
795 wacom->led.select[1] = 0;
798 wacom->led.img_lum = 10;
799 error = sysfs_create_group(&wacom->intf->dev.kobj,
800 &intuos4_led_attr_group);
805 wacom->led.select[0] = 0;
806 wacom->led.select[1] = 0;
809 wacom->led.img_lum = 0;
811 error = sysfs_create_group(&wacom->intf->dev.kobj,
812 &cintiq_led_attr_group);
820 dev_err(&wacom->intf->dev,
821 "cannot create sysfs group err: %d\n", error);
824 wacom_led_control(wacom);
829 static void wacom_destroy_leds(struct wacom *wacom)
831 switch (wacom->wacom_wac.features.type) {
834 sysfs_remove_group(&wacom->intf->dev.kobj,
835 &intuos4_led_attr_group);
840 sysfs_remove_group(&wacom->intf->dev.kobj,
841 &cintiq_led_attr_group);
846 static enum power_supply_property wacom_battery_props[] = {
847 POWER_SUPPLY_PROP_CAPACITY
850 static int wacom_battery_get_property(struct power_supply *psy,
851 enum power_supply_property psp,
852 union power_supply_propval *val)
854 struct wacom *wacom = container_of(psy, struct wacom, battery);
858 case POWER_SUPPLY_PROP_CAPACITY:
860 wacom->wacom_wac.battery_capacity * 100 / 31;
870 static int wacom_initialize_battery(struct wacom *wacom)
874 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) {
875 wacom->battery.properties = wacom_battery_props;
876 wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
877 wacom->battery.get_property = wacom_battery_get_property;
878 wacom->battery.name = "wacom_battery";
879 wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
880 wacom->battery.use_for_apm = 0;
882 error = power_supply_register(&wacom->usbdev->dev,
889 static void wacom_destroy_battery(struct wacom *wacom)
891 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR)
892 power_supply_unregister(&wacom->battery);
895 static int wacom_register_input(struct wacom *wacom)
897 struct input_dev *input_dev;
898 struct usb_interface *intf = wacom->intf;
899 struct usb_device *dev = interface_to_usbdev(intf);
900 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
903 input_dev = input_allocate_device();
907 input_dev->name = wacom_wac->name;
908 input_dev->dev.parent = &intf->dev;
909 input_dev->open = wacom_open;
910 input_dev->close = wacom_close;
911 usb_to_input_id(dev, &input_dev->id);
912 input_set_drvdata(input_dev, wacom);
914 wacom_wac->input = input_dev;
915 wacom_setup_input_capabilities(input_dev, wacom_wac);
917 error = input_register_device(input_dev);
919 input_free_device(input_dev);
920 wacom_wac->input = NULL;
926 static void wacom_wireless_work(struct work_struct *work)
928 struct wacom *wacom = container_of(work, struct wacom, work);
929 struct usb_device *usbdev = wacom->usbdev;
930 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
933 * Regardless if this is a disconnect or a new tablet,
934 * remove any existing input devices.
937 /* Stylus interface */
938 wacom = usb_get_intfdata(usbdev->config->interface[1]);
939 if (wacom->wacom_wac.input)
940 input_unregister_device(wacom->wacom_wac.input);
941 wacom->wacom_wac.input = 0;
943 /* Touch interface */
944 wacom = usb_get_intfdata(usbdev->config->interface[2]);
945 if (wacom->wacom_wac.input)
946 input_unregister_device(wacom->wacom_wac.input);
947 wacom->wacom_wac.input = 0;
949 if (wacom_wac->pid == 0) {
950 printk(KERN_INFO "wacom: wireless tablet disconnected\n");
952 const struct usb_device_id *id = wacom_ids;
955 "wacom: wireless tablet connected with PID %x\n",
958 while (id->match_flags) {
959 if (id->idVendor == USB_VENDOR_ID_WACOM &&
960 id->idProduct == wacom_wac->pid)
965 if (!id->match_flags) {
967 "wacom: ignorning unknown PID.\n");
971 /* Stylus interface */
972 wacom = usb_get_intfdata(usbdev->config->interface[1]);
973 wacom_wac = &wacom->wacom_wac;
974 wacom_wac->features =
975 *((struct wacom_features *)id->driver_info);
976 wacom_wac->features.device_type = BTN_TOOL_PEN;
977 wacom_register_input(wacom);
979 /* Touch interface */
980 wacom = usb_get_intfdata(usbdev->config->interface[2]);
981 wacom_wac = &wacom->wacom_wac;
982 wacom_wac->features =
983 *((struct wacom_features *)id->driver_info);
984 wacom_wac->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
985 wacom_wac->features.device_type = BTN_TOOL_FINGER;
986 wacom_set_phy_from_res(&wacom_wac->features);
987 wacom_wac->features.x_max = wacom_wac->features.y_max = 4096;
988 wacom_register_input(wacom);
992 static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
994 struct usb_device *dev = interface_to_usbdev(intf);
995 struct usb_endpoint_descriptor *endpoint;
997 struct wacom_wac *wacom_wac;
998 struct wacom_features *features;
1001 if (!id->driver_info)
1004 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
1008 wacom_wac = &wacom->wacom_wac;
1009 wacom_wac->features = *((struct wacom_features *)id->driver_info);
1010 features = &wacom_wac->features;
1011 if (features->pktlen > WACOM_PKGLEN_MAX) {
1016 wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX,
1017 GFP_KERNEL, &wacom->data_dma);
1018 if (!wacom_wac->data) {
1023 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
1029 wacom->usbdev = dev;
1031 mutex_init(&wacom->lock);
1032 INIT_WORK(&wacom->work, wacom_wireless_work);
1033 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
1034 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
1036 endpoint = &intf->cur_altsetting->endpoint[0].desc;
1038 /* Retrieve the physical and logical size for OEM devices */
1039 error = wacom_retrieve_hid_descriptor(intf, features);
1043 wacom_setup_device_quirks(features);
1045 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
1047 if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
1048 /* Append the device type to the name */
1049 strlcat(wacom_wac->name,
1050 features->device_type == BTN_TOOL_PEN ?
1052 sizeof(wacom_wac->name));
1054 error = wacom_add_shared_data(wacom_wac, dev);
1059 usb_fill_int_urb(wacom->irq, dev,
1060 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
1061 wacom_wac->data, features->pktlen,
1062 wacom_sys_irq, wacom, endpoint->bInterval);
1063 wacom->irq->transfer_dma = wacom->data_dma;
1064 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1066 error = wacom_initialize_leds(wacom);
1070 error = wacom_initialize_battery(wacom);
1074 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
1075 error = wacom_register_input(wacom);
1080 /* Note that if query fails it is not a hard failure */
1081 wacom_query_tablet_data(intf, features);
1083 usb_set_intfdata(intf, wacom);
1085 if (features->quirks & WACOM_QUIRK_MONITOR) {
1086 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
1092 fail6: wacom_destroy_battery(wacom);
1093 fail5: wacom_destroy_leds(wacom);
1094 fail4: wacom_remove_shared_data(wacom_wac);
1095 fail3: usb_free_urb(wacom->irq);
1096 fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
1097 fail1: kfree(wacom);
1101 static void wacom_disconnect(struct usb_interface *intf)
1103 struct wacom *wacom = usb_get_intfdata(intf);
1105 usb_set_intfdata(intf, NULL);
1107 usb_kill_urb(wacom->irq);
1108 cancel_work_sync(&wacom->work);
1109 if (wacom->wacom_wac.input)
1110 input_unregister_device(wacom->wacom_wac.input);
1111 wacom_destroy_battery(wacom);
1112 wacom_destroy_leds(wacom);
1113 usb_free_urb(wacom->irq);
1114 usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
1115 wacom->wacom_wac.data, wacom->data_dma);
1116 wacom_remove_shared_data(&wacom->wacom_wac);
1120 static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
1122 struct wacom *wacom = usb_get_intfdata(intf);
1124 mutex_lock(&wacom->lock);
1125 usb_kill_urb(wacom->irq);
1126 mutex_unlock(&wacom->lock);
1131 static int wacom_resume(struct usb_interface *intf)
1133 struct wacom *wacom = usb_get_intfdata(intf);
1134 struct wacom_features *features = &wacom->wacom_wac.features;
1137 mutex_lock(&wacom->lock);
1139 /* switch to wacom mode first */
1140 wacom_query_tablet_data(intf, features);
1141 wacom_led_control(wacom);
1143 if ((wacom->open || features->quirks & WACOM_QUIRK_MONITOR)
1144 && usb_submit_urb(wacom->irq, GFP_NOIO) < 0)
1147 mutex_unlock(&wacom->lock);
1152 static int wacom_reset_resume(struct usb_interface *intf)
1154 return wacom_resume(intf);
1157 static struct usb_driver wacom_driver = {
1159 .id_table = wacom_ids,
1160 .probe = wacom_probe,
1161 .disconnect = wacom_disconnect,
1162 .suspend = wacom_suspend,
1163 .resume = wacom_resume,
1164 .reset_resume = wacom_reset_resume,
1165 .supports_autosuspend = 1,
1168 module_usb_driver(wacom_driver);