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
);
170 static int wacom_parse_logical_collection(unsigned char *report
,
171 struct wacom_features
*features
)
175 if (features
->type
== BAMBOO_PT
) {
177 /* Logical collection is only used by 3rd gen Bamboo Touch */
178 features
->pktlen
= WACOM_PKGLEN_BBTOUCH3
;
179 features
->device_type
= BTN_TOOL_DOUBLETAP
;
182 * Stylus and Touch have same active area
183 * so compute physical size based on stylus
184 * data before its overwritten.
187 (features
->x_max
* features
->x_resolution
) / 100;
189 (features
->y_max
* features
->y_resolution
) / 100;
191 features
->x_max
= features
->y_max
=
192 get_unaligned_le16(&report
[10]);
200 * Interface Descriptor of wacom devices can be incomplete and
201 * inconsistent so wacom_features table is used to store stylus
202 * device's packet lengths, various maximum values, and tablet
203 * resolution based on product ID's.
205 * For devices that contain 2 interfaces, wacom_features table is
206 * inaccurate for the touch interface. Since the Interface Descriptor
207 * for touch interfaces has pretty complete data, this function exists
208 * to query tablet for this missing information instead of hard coding in
209 * an additional table.
211 * A typical Interface Descriptor for a stylus will contain a
212 * boot mouse application collection that is not of interest and this
213 * function will ignore it.
215 * It also contains a digitizer application collection that also is not
216 * of interest since any information it contains would be duplicate
217 * of what is in wacom_features. Usually it defines a report of an array
218 * of bytes that could be used as max length of the stylus packet returned.
219 * If it happens to define a Digitizer-Stylus Physical Collection then
220 * the X and Y logical values contain valid data but it is ignored.
222 * A typical Interface Descriptor for a touch interface will contain a
223 * Digitizer-Finger Physical Collection which will define both logical
224 * X/Y maximum as well as the physical size of tablet. Since touch
225 * interfaces haven't supported pressure or distance, this is enough
226 * information to override invalid values in the wacom_features table.
228 * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical
229 * Collection. Instead they define a Logical Collection with a single
230 * Logical Maximum for both X and Y.
232 static int wacom_parse_hid(struct usb_interface
*intf
,
233 struct hid_descriptor
*hid_desc
,
234 struct wacom_features
*features
)
236 struct usb_device
*dev
= interface_to_usbdev(intf
);
238 /* result has to be defined as int for some devices */
240 int i
= 0, usage
= WCM_UNDEFINED
, finger
= 0, pen
= 0;
241 unsigned char *report
;
243 report
= kzalloc(hid_desc
->wDescriptorLength
, GFP_KERNEL
);
247 /* retrive report descriptors */
249 result
= usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0),
250 USB_REQ_GET_DESCRIPTOR
,
251 USB_RECIP_INTERFACE
| USB_DIR_IN
,
252 HID_DEVICET_REPORT
<< 8,
253 intf
->altsetting
[0].desc
.bInterfaceNumber
, /* interface */
255 hid_desc
->wDescriptorLength
,
257 } while (result
< 0 && limit
++ < WAC_MSG_RETRIES
);
259 /* No need to parse the Descriptor. It isn't an error though */
263 for (i
= 0; i
< hid_desc
->wDescriptorLength
; i
++) {
267 switch (report
[i
+ 1]) {
268 case HID_USAGE_PAGE_DIGITIZER
:
269 usage
= WCM_DIGITIZER
;
273 case HID_USAGE_PAGE_DESKTOP
:
281 switch (report
[i
+ 1]) {
283 if (usage
== WCM_DESKTOP
) {
285 features
->device_type
= BTN_TOOL_FINGER
;
286 if (features
->type
== TABLETPC2FG
) {
287 /* need to reset back */
288 features
->pktlen
= WACOM_PKGLEN_TPC2FG
;
289 features
->device_type
= BTN_TOOL_DOUBLETAP
;
291 if (features
->type
== BAMBOO_PT
) {
292 /* need to reset back */
293 features
->pktlen
= WACOM_PKGLEN_BBTOUCH
;
294 features
->device_type
= BTN_TOOL_DOUBLETAP
;
296 get_unaligned_le16(&report
[i
+ 5]);
298 get_unaligned_le16(&report
[i
+ 8]);
302 get_unaligned_le16(&report
[i
+ 3]);
304 get_unaligned_le16(&report
[i
+ 6]);
305 features
->unit
= report
[i
+ 9];
306 features
->unitExpo
= report
[i
+ 11];
310 /* penabled only accepts exact bytes of data */
311 if (features
->type
== TABLETPC2FG
)
312 features
->pktlen
= WACOM_PKGLEN_GRAPHIRE
;
313 features
->device_type
= BTN_TOOL_PEN
;
315 get_unaligned_le16(&report
[i
+ 3]);
322 if (usage
== WCM_DESKTOP
) {
324 features
->device_type
= BTN_TOOL_FINGER
;
325 if (features
->type
== TABLETPC2FG
) {
326 /* need to reset back */
327 features
->pktlen
= WACOM_PKGLEN_TPC2FG
;
328 features
->device_type
= BTN_TOOL_DOUBLETAP
;
330 get_unaligned_le16(&report
[i
+ 3]);
332 get_unaligned_le16(&report
[i
+ 6]);
334 } else if (features
->type
== BAMBOO_PT
) {
335 /* need to reset back */
336 features
->pktlen
= WACOM_PKGLEN_BBTOUCH
;
337 features
->device_type
= BTN_TOOL_DOUBLETAP
;
339 get_unaligned_le16(&report
[i
+ 3]);
341 get_unaligned_le16(&report
[i
+ 6]);
347 get_unaligned_le16(&report
[i
+ 3]);
351 /* penabled only accepts exact bytes of data */
352 if (features
->type
== TABLETPC2FG
)
353 features
->pktlen
= WACOM_PKGLEN_GRAPHIRE
;
354 features
->device_type
= BTN_TOOL_PEN
;
356 get_unaligned_le16(&report
[i
+ 3]);
362 case HID_USAGE_FINGER
:
368 * Requiring Stylus Usage will ignore boot mouse
369 * X/Y values and some cases of invalid Digitizer X/Y
370 * values commonly reported.
372 case HID_USAGE_STYLUS
:
379 case HID_COLLECTION_END
:
380 /* reset UsagePage and Finger */
387 case HID_COLLECTION_LOGICAL
:
388 i
+= wacom_parse_logical_collection(&report
[i
],
402 static int wacom_query_tablet_data(struct usb_interface
*intf
, struct wacom_features
*features
)
404 unsigned char *rep_data
;
405 int limit
= 0, report_id
= 2;
408 rep_data
= kmalloc(4, GFP_KERNEL
);
412 /* ask to report tablet data if it is MT Tablet PC or
414 if (features
->type
== TABLETPC2FG
) {
421 error
= wacom_set_report(intf
, WAC_HID_FEATURE_REPORT
,
422 report_id
, rep_data
, 4, 1);
424 error
= wacom_get_report(intf
,
425 WAC_HID_FEATURE_REPORT
,
426 report_id
, rep_data
, 4, 1);
427 } while ((error
< 0 || rep_data
[1] != 4) && limit
++ < WAC_MSG_RETRIES
);
428 } else if (features
->type
!= TABLETPC
&&
429 features
->device_type
== BTN_TOOL_PEN
) {
433 error
= wacom_set_report(intf
, WAC_HID_FEATURE_REPORT
,
434 report_id
, rep_data
, 2, 1);
436 error
= wacom_get_report(intf
,
437 WAC_HID_FEATURE_REPORT
,
438 report_id
, rep_data
, 2, 1);
439 } while ((error
< 0 || rep_data
[1] != 2) && limit
++ < WAC_MSG_RETRIES
);
444 return error
< 0 ? error
: 0;
447 static int wacom_retrieve_hid_descriptor(struct usb_interface
*intf
,
448 struct wacom_features
*features
)
451 struct usb_host_interface
*interface
= intf
->cur_altsetting
;
452 struct hid_descriptor
*hid_desc
;
454 /* default features */
455 features
->device_type
= BTN_TOOL_PEN
;
456 features
->x_fuzz
= 4;
457 features
->y_fuzz
= 4;
458 features
->pressure_fuzz
= 0;
459 features
->distance_fuzz
= 0;
461 /* only Tablet PCs and Bamboo P&T need to retrieve the info */
462 if ((features
->type
!= TABLETPC
) && (features
->type
!= TABLETPC2FG
) &&
463 (features
->type
!= BAMBOO_PT
))
466 if (usb_get_extra_descriptor(interface
, HID_DEVICET_HID
, &hid_desc
)) {
467 if (usb_get_extra_descriptor(&interface
->endpoint
[0],
468 HID_DEVICET_REPORT
, &hid_desc
)) {
469 printk("wacom: can not retrieve extra class descriptor\n");
474 error
= wacom_parse_hid(intf
, hid_desc
, features
);
482 struct wacom_usbdev_data
{
483 struct list_head list
;
485 struct usb_device
*dev
;
486 struct wacom_shared shared
;
489 static LIST_HEAD(wacom_udev_list
);
490 static DEFINE_MUTEX(wacom_udev_list_lock
);
492 static struct wacom_usbdev_data
*wacom_get_usbdev_data(struct usb_device
*dev
)
494 struct wacom_usbdev_data
*data
;
496 list_for_each_entry(data
, &wacom_udev_list
, list
) {
497 if (data
->dev
== dev
) {
498 kref_get(&data
->kref
);
506 static int wacom_add_shared_data(struct wacom_wac
*wacom
,
507 struct usb_device
*dev
)
509 struct wacom_usbdev_data
*data
;
512 mutex_lock(&wacom_udev_list_lock
);
514 data
= wacom_get_usbdev_data(dev
);
516 data
= kzalloc(sizeof(struct wacom_usbdev_data
), GFP_KERNEL
);
522 kref_init(&data
->kref
);
524 list_add_tail(&data
->list
, &wacom_udev_list
);
527 wacom
->shared
= &data
->shared
;
530 mutex_unlock(&wacom_udev_list_lock
);
534 static void wacom_release_shared_data(struct kref
*kref
)
536 struct wacom_usbdev_data
*data
=
537 container_of(kref
, struct wacom_usbdev_data
, kref
);
539 mutex_lock(&wacom_udev_list_lock
);
540 list_del(&data
->list
);
541 mutex_unlock(&wacom_udev_list_lock
);
546 static void wacom_remove_shared_data(struct wacom_wac
*wacom
)
548 struct wacom_usbdev_data
*data
;
551 data
= container_of(wacom
->shared
, struct wacom_usbdev_data
, shared
);
552 kref_put(&data
->kref
, wacom_release_shared_data
);
553 wacom
->shared
= NULL
;
557 static int wacom_led_control(struct wacom
*wacom
)
562 buf
= kzalloc(9, GFP_KERNEL
);
566 if (wacom
->wacom_wac
.features
.type
== WACOM_21UX2
||
567 wacom
->wacom_wac
.features
.type
== WACOM_24HD
)
568 led
= (wacom
->led
.select
[1] << 4) | 0x40;
570 led
|= wacom
->led
.select
[0] | 0x4;
572 buf
[0] = WAC_CMD_LED_CONTROL
;
574 buf
[2] = wacom
->led
.llv
;
575 buf
[3] = wacom
->led
.hlv
;
576 buf
[4] = wacom
->led
.img_lum
;
578 retval
= wacom_set_report(wacom
->intf
, 0x03, WAC_CMD_LED_CONTROL
,
579 buf
, 9, WAC_CMD_RETRIES
);
585 static int wacom_led_putimage(struct wacom
*wacom
, int button_id
, const void *img
)
590 buf
= kzalloc(259, GFP_KERNEL
);
594 /* Send 'start' command */
595 buf
[0] = WAC_CMD_ICON_START
;
597 retval
= wacom_set_report(wacom
->intf
, 0x03, WAC_CMD_ICON_START
,
598 buf
, 2, WAC_CMD_RETRIES
);
602 buf
[0] = WAC_CMD_ICON_XFER
;
603 buf
[1] = button_id
& 0x07;
604 for (i
= 0; i
< 4; i
++) {
606 memcpy(buf
+ 3, img
+ i
* 256, 256);
608 retval
= wacom_set_report(wacom
->intf
, 0x03, WAC_CMD_ICON_XFER
,
609 buf
, 259, WAC_CMD_RETRIES
);
615 buf
[0] = WAC_CMD_ICON_START
;
617 wacom_set_report(wacom
->intf
, 0x03, WAC_CMD_ICON_START
,
618 buf
, 2, WAC_CMD_RETRIES
);
625 static ssize_t
wacom_led_select_store(struct device
*dev
, int set_id
,
626 const char *buf
, size_t count
)
628 struct wacom
*wacom
= dev_get_drvdata(dev
);
632 err
= kstrtouint(buf
, 10, &id
);
636 mutex_lock(&wacom
->lock
);
638 wacom
->led
.select
[set_id
] = id
& 0x3;
639 err
= wacom_led_control(wacom
);
641 mutex_unlock(&wacom
->lock
);
643 return err
< 0 ? err
: count
;
646 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
647 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
648 struct device_attribute *attr, const char *buf, size_t count) \
650 return wacom_led_select_store(dev, SET_ID, buf, count); \
652 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
653 struct device_attribute *attr, char *buf) \
655 struct wacom *wacom = dev_get_drvdata(dev); \
656 return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
658 static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
659 wacom_led##SET_ID##_select_show, \
660 wacom_led##SET_ID##_select_store)
662 DEVICE_LED_SELECT_ATTR(0);
663 DEVICE_LED_SELECT_ATTR(1);
665 static ssize_t
wacom_luminance_store(struct wacom
*wacom
, u8
*dest
,
666 const char *buf
, size_t count
)
671 err
= kstrtouint(buf
, 10, &value
);
675 mutex_lock(&wacom
->lock
);
677 *dest
= value
& 0x7f;
678 err
= wacom_led_control(wacom
);
680 mutex_unlock(&wacom
->lock
);
682 return err
< 0 ? err
: count
;
685 #define DEVICE_LUMINANCE_ATTR(name, field) \
686 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
687 struct device_attribute *attr, const char *buf, size_t count) \
689 struct wacom *wacom = dev_get_drvdata(dev); \
691 return wacom_luminance_store(wacom, &wacom->led.field, \
694 static DEVICE_ATTR(name##_luminance, S_IWUSR, \
695 NULL, wacom_##name##_luminance_store)
697 DEVICE_LUMINANCE_ATTR(status0
, llv
);
698 DEVICE_LUMINANCE_ATTR(status1
, hlv
);
699 DEVICE_LUMINANCE_ATTR(buttons
, img_lum
);
701 static ssize_t
wacom_button_image_store(struct device
*dev
, int button_id
,
702 const char *buf
, size_t count
)
704 struct wacom
*wacom
= dev_get_drvdata(dev
);
710 mutex_lock(&wacom
->lock
);
712 err
= wacom_led_putimage(wacom
, button_id
, buf
);
714 mutex_unlock(&wacom
->lock
);
716 return err
< 0 ? err
: count
;
719 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
720 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
721 struct device_attribute *attr, const char *buf, size_t count) \
723 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
725 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
726 NULL, wacom_btnimg##BUTTON_ID##_store)
728 DEVICE_BTNIMG_ATTR(0);
729 DEVICE_BTNIMG_ATTR(1);
730 DEVICE_BTNIMG_ATTR(2);
731 DEVICE_BTNIMG_ATTR(3);
732 DEVICE_BTNIMG_ATTR(4);
733 DEVICE_BTNIMG_ATTR(5);
734 DEVICE_BTNIMG_ATTR(6);
735 DEVICE_BTNIMG_ATTR(7);
737 static struct attribute
*cintiq_led_attrs
[] = {
738 &dev_attr_status_led0_select
.attr
,
739 &dev_attr_status_led1_select
.attr
,
743 static struct attribute_group cintiq_led_attr_group
= {
745 .attrs
= cintiq_led_attrs
,
748 static struct attribute
*intuos4_led_attrs
[] = {
749 &dev_attr_status0_luminance
.attr
,
750 &dev_attr_status1_luminance
.attr
,
751 &dev_attr_status_led0_select
.attr
,
752 &dev_attr_buttons_luminance
.attr
,
753 &dev_attr_button0_rawimg
.attr
,
754 &dev_attr_button1_rawimg
.attr
,
755 &dev_attr_button2_rawimg
.attr
,
756 &dev_attr_button3_rawimg
.attr
,
757 &dev_attr_button4_rawimg
.attr
,
758 &dev_attr_button5_rawimg
.attr
,
759 &dev_attr_button6_rawimg
.attr
,
760 &dev_attr_button7_rawimg
.attr
,
764 static struct attribute_group intuos4_led_attr_group
= {
766 .attrs
= intuos4_led_attrs
,
769 static int wacom_initialize_leds(struct wacom
*wacom
)
773 /* Initialize default values */
774 switch (wacom
->wacom_wac
.features
.type
) {
777 wacom
->led
.select
[0] = 0;
778 wacom
->led
.select
[1] = 0;
781 wacom
->led
.img_lum
= 10;
782 error
= sysfs_create_group(&wacom
->intf
->dev
.kobj
,
783 &intuos4_led_attr_group
);
788 wacom
->led
.select
[0] = 0;
789 wacom
->led
.select
[1] = 0;
792 wacom
->led
.img_lum
= 0;
794 error
= sysfs_create_group(&wacom
->intf
->dev
.kobj
,
795 &cintiq_led_attr_group
);
803 dev_err(&wacom
->intf
->dev
,
804 "cannot create sysfs group err: %d\n", error
);
807 wacom_led_control(wacom
);
812 static void wacom_destroy_leds(struct wacom
*wacom
)
814 switch (wacom
->wacom_wac
.features
.type
) {
817 sysfs_remove_group(&wacom
->intf
->dev
.kobj
,
818 &intuos4_led_attr_group
);
823 sysfs_remove_group(&wacom
->intf
->dev
.kobj
,
824 &cintiq_led_attr_group
);
829 static int wacom_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
831 struct usb_device
*dev
= interface_to_usbdev(intf
);
832 struct usb_endpoint_descriptor
*endpoint
;
834 struct wacom_wac
*wacom_wac
;
835 struct wacom_features
*features
;
836 struct input_dev
*input_dev
;
839 if (!id
->driver_info
)
842 wacom
= kzalloc(sizeof(struct wacom
), GFP_KERNEL
);
843 input_dev
= input_allocate_device();
844 if (!wacom
|| !input_dev
) {
849 wacom_wac
= &wacom
->wacom_wac
;
850 wacom_wac
->features
= *((struct wacom_features
*)id
->driver_info
);
851 features
= &wacom_wac
->features
;
852 if (features
->pktlen
> WACOM_PKGLEN_MAX
) {
857 wacom_wac
->data
= usb_alloc_coherent(dev
, WACOM_PKGLEN_MAX
,
858 GFP_KERNEL
, &wacom
->data_dma
);
859 if (!wacom_wac
->data
) {
864 wacom
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
872 mutex_init(&wacom
->lock
);
873 usb_make_path(dev
, wacom
->phys
, sizeof(wacom
->phys
));
874 strlcat(wacom
->phys
, "/input0", sizeof(wacom
->phys
));
876 wacom_wac
->input
= input_dev
;
878 endpoint
= &intf
->cur_altsetting
->endpoint
[0].desc
;
880 /* Retrieve the physical and logical size for OEM devices */
881 error
= wacom_retrieve_hid_descriptor(intf
, features
);
885 wacom_setup_device_quirks(features
);
887 strlcpy(wacom_wac
->name
, features
->name
, sizeof(wacom_wac
->name
));
889 if (features
->quirks
& WACOM_QUIRK_MULTI_INPUT
) {
890 /* Append the device type to the name */
891 strlcat(wacom_wac
->name
,
892 features
->device_type
== BTN_TOOL_PEN
?
894 sizeof(wacom_wac
->name
));
896 error
= wacom_add_shared_data(wacom_wac
, dev
);
901 input_dev
->name
= wacom_wac
->name
;
902 input_dev
->dev
.parent
= &intf
->dev
;
903 input_dev
->open
= wacom_open
;
904 input_dev
->close
= wacom_close
;
905 usb_to_input_id(dev
, &input_dev
->id
);
906 input_set_drvdata(input_dev
, wacom
);
908 wacom_setup_input_capabilities(input_dev
, wacom_wac
);
910 usb_fill_int_urb(wacom
->irq
, dev
,
911 usb_rcvintpipe(dev
, endpoint
->bEndpointAddress
),
912 wacom_wac
->data
, features
->pktlen
,
913 wacom_sys_irq
, wacom
, endpoint
->bInterval
);
914 wacom
->irq
->transfer_dma
= wacom
->data_dma
;
915 wacom
->irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
917 error
= wacom_initialize_leds(wacom
);
921 error
= input_register_device(input_dev
);
925 /* Note that if query fails it is not a hard failure */
926 wacom_query_tablet_data(intf
, features
);
928 usb_set_intfdata(intf
, wacom
);
931 fail5
: wacom_destroy_leds(wacom
);
932 fail4
: wacom_remove_shared_data(wacom_wac
);
933 fail3
: usb_free_urb(wacom
->irq
);
934 fail2
: usb_free_coherent(dev
, WACOM_PKGLEN_MAX
, wacom_wac
->data
, wacom
->data_dma
);
935 fail1
: input_free_device(input_dev
);
940 static void wacom_disconnect(struct usb_interface
*intf
)
942 struct wacom
*wacom
= usb_get_intfdata(intf
);
944 usb_set_intfdata(intf
, NULL
);
946 usb_kill_urb(wacom
->irq
);
947 input_unregister_device(wacom
->wacom_wac
.input
);
948 wacom_destroy_leds(wacom
);
949 usb_free_urb(wacom
->irq
);
950 usb_free_coherent(interface_to_usbdev(intf
), WACOM_PKGLEN_MAX
,
951 wacom
->wacom_wac
.data
, wacom
->data_dma
);
952 wacom_remove_shared_data(&wacom
->wacom_wac
);
956 static int wacom_suspend(struct usb_interface
*intf
, pm_message_t message
)
958 struct wacom
*wacom
= usb_get_intfdata(intf
);
960 mutex_lock(&wacom
->lock
);
961 usb_kill_urb(wacom
->irq
);
962 mutex_unlock(&wacom
->lock
);
967 static int wacom_resume(struct usb_interface
*intf
)
969 struct wacom
*wacom
= usb_get_intfdata(intf
);
970 struct wacom_features
*features
= &wacom
->wacom_wac
.features
;
973 mutex_lock(&wacom
->lock
);
975 /* switch to wacom mode first */
976 wacom_query_tablet_data(intf
, features
);
977 wacom_led_control(wacom
);
979 if (wacom
->open
&& usb_submit_urb(wacom
->irq
, GFP_NOIO
) < 0)
982 mutex_unlock(&wacom
->lock
);
987 static int wacom_reset_resume(struct usb_interface
*intf
)
989 return wacom_resume(intf
);
992 static struct usb_driver wacom_driver
= {
994 .id_table
= wacom_ids
,
995 .probe
= wacom_probe
,
996 .disconnect
= wacom_disconnect
,
997 .suspend
= wacom_suspend
,
998 .resume
= wacom_resume
,
999 .reset_resume
= wacom_reset_resume
,
1000 .supports_autosuspend
= 1,
1003 module_usb_driver(wacom_driver
);