Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1 | /* |
Dmitry Torokhov | 4104d13 | 2007-05-07 16:16:29 -0400 | [diff] [blame] | 2 | * drivers/input/tablet/wacom_sys.c |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 3 | * |
Ping Cheng | 232f569 | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 4 | * USB Wacom tablet support - system specific code |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 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. |
| 12 | */ |
| 13 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 14 | #include "wacom_wac.h" |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 15 | #include "wacom.h" |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 16 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 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 0xc0 |
| 32 | |
| 33 | enum { |
| 34 | WCM_UNDEFINED = 0, |
| 35 | WCM_DESKTOP, |
| 36 | WCM_DIGITIZER, |
| 37 | }; |
| 38 | |
| 39 | struct hid_descriptor { |
| 40 | struct usb_descriptor_header header; |
| 41 | __le16 bcdHID; |
| 42 | u8 bCountryCode; |
| 43 | u8 bNumDescriptors; |
| 44 | u8 bDescriptorType; |
| 45 | __le16 wDescriptorLength; |
| 46 | } __attribute__ ((packed)); |
| 47 | |
| 48 | /* defines to get/set USB message */ |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 49 | #define USB_REQ_GET_REPORT 0x01 |
| 50 | #define USB_REQ_SET_REPORT 0x09 |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 51 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 52 | #define WAC_HID_FEATURE_REPORT 0x03 |
Ping Cheng | a417ea4 | 2011-08-16 00:17:56 -0700 | [diff] [blame] | 53 | #define WAC_MSG_RETRIES 5 |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 54 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 55 | #define WAC_CMD_LED_CONTROL 0x20 |
| 56 | #define WAC_CMD_ICON_START 0x21 |
| 57 | #define WAC_CMD_ICON_XFER 0x23 |
| 58 | #define WAC_CMD_RETRIES 10 |
| 59 | |
| 60 | static int wacom_get_report(struct usb_interface *intf, u8 type, u8 id, |
| 61 | void *buf, size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 62 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 63 | struct usb_device *dev = interface_to_usbdev(intf); |
| 64 | int retval; |
| 65 | |
| 66 | do { |
| 67 | retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 68 | USB_REQ_GET_REPORT, |
| 69 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 70 | (type << 8) + id, |
| 71 | intf->altsetting[0].desc.bInterfaceNumber, |
| 72 | buf, size, 100); |
| 73 | } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries); |
| 74 | |
| 75 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 78 | static int wacom_set_report(struct usb_interface *intf, u8 type, u8 id, |
| 79 | void *buf, size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 80 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 81 | struct usb_device *dev = interface_to_usbdev(intf); |
| 82 | int retval; |
| 83 | |
| 84 | do { |
| 85 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 86 | USB_REQ_SET_REPORT, |
| 87 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 88 | (type << 8) + id, |
| 89 | intf->altsetting[0].desc.bInterfaceNumber, |
| 90 | buf, size, 1000); |
| 91 | } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries); |
| 92 | |
| 93 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Adrian Bunk | 54c9b22 | 2006-11-20 03:23:58 +0100 | [diff] [blame] | 96 | static void wacom_sys_irq(struct urb *urb) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 97 | { |
| 98 | struct wacom *wacom = urb->context; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 99 | int retval; |
| 100 | |
| 101 | switch (urb->status) { |
| 102 | case 0: |
| 103 | /* success */ |
| 104 | break; |
| 105 | case -ECONNRESET: |
| 106 | case -ENOENT: |
| 107 | case -ESHUTDOWN: |
| 108 | /* this urb is terminated, clean up */ |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 109 | dbg("%s - urb shutting down with status: %d", __func__, urb->status); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 110 | return; |
| 111 | default: |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 112 | dbg("%s - nonzero urb status received: %d", __func__, urb->status); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 113 | goto exit; |
| 114 | } |
| 115 | |
Dmitry Torokhov | 95dd3b3 | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 116 | wacom_wac_irq(&wacom->wacom_wac, urb->actual_length); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 117 | |
| 118 | exit: |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 119 | usb_mark_last_busy(wacom->usbdev); |
Dmitry Torokhov | 73a97f4 | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 120 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 121 | if (retval) |
| 122 | err ("%s - usb_submit_urb failed with result %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 123 | __func__, retval); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 126 | static int wacom_open(struct input_dev *dev) |
| 127 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 128 | struct wacom *wacom = input_get_drvdata(dev); |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 129 | int retval = 0; |
| 130 | |
| 131 | if (usb_autopm_get_interface(wacom->intf) < 0) |
| 132 | return -EIO; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 133 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 134 | mutex_lock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 135 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 136 | if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 137 | retval = -EIO; |
| 138 | goto out; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 139 | } |
| 140 | |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 141 | wacom->open = true; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 142 | wacom->intf->needs_remote_wakeup = 1; |
| 143 | |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 144 | out: |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 145 | mutex_unlock(&wacom->lock); |
Dmitry Torokhov | 62ecae0 | 2010-10-10 14:24:16 -0700 | [diff] [blame] | 146 | usb_autopm_put_interface(wacom->intf); |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 147 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static void wacom_close(struct input_dev *dev) |
| 151 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 152 | struct wacom *wacom = input_get_drvdata(dev); |
Dmitry Torokhov | 62ecae0 | 2010-10-10 14:24:16 -0700 | [diff] [blame] | 153 | int autopm_error; |
| 154 | |
| 155 | autopm_error = usb_autopm_get_interface(wacom->intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 156 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 157 | mutex_lock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 158 | usb_kill_urb(wacom->irq); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 159 | wacom->open = false; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 160 | wacom->intf->needs_remote_wakeup = 0; |
| 161 | mutex_unlock(&wacom->lock); |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 162 | |
Dmitry Torokhov | 62ecae0 | 2010-10-10 14:24:16 -0700 | [diff] [blame] | 163 | if (!autopm_error) |
| 164 | usb_autopm_put_interface(wacom->intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 167 | static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc, |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 168 | struct wacom_features *features) |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 169 | { |
| 170 | struct usb_device *dev = interface_to_usbdev(intf); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 171 | char limit = 0; |
| 172 | /* result has to be defined as int for some devices */ |
| 173 | int result = 0; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 174 | int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0; |
| 175 | unsigned char *report; |
| 176 | |
| 177 | report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL); |
| 178 | if (!report) |
| 179 | return -ENOMEM; |
| 180 | |
| 181 | /* retrive report descriptors */ |
| 182 | do { |
| 183 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 184 | USB_REQ_GET_DESCRIPTOR, |
| 185 | USB_RECIP_INTERFACE | USB_DIR_IN, |
| 186 | HID_DEVICET_REPORT << 8, |
| 187 | intf->altsetting[0].desc.bInterfaceNumber, /* interface */ |
| 188 | report, |
| 189 | hid_desc->wDescriptorLength, |
| 190 | 5000); /* 5 secs */ |
Ping Cheng | a417ea4 | 2011-08-16 00:17:56 -0700 | [diff] [blame] | 191 | } while (result < 0 && limit++ < WAC_MSG_RETRIES); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 192 | |
Ping Cheng | 384318e | 2009-04-28 07:49:54 -0700 | [diff] [blame] | 193 | /* No need to parse the Descriptor. It isn't an error though */ |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 194 | if (result < 0) |
| 195 | goto out; |
| 196 | |
| 197 | for (i = 0; i < hid_desc->wDescriptorLength; i++) { |
| 198 | |
| 199 | switch (report[i]) { |
| 200 | case HID_USAGE_PAGE: |
| 201 | switch (report[i + 1]) { |
| 202 | case HID_USAGE_PAGE_DIGITIZER: |
| 203 | usage = WCM_DIGITIZER; |
| 204 | i++; |
| 205 | break; |
| 206 | |
| 207 | case HID_USAGE_PAGE_DESKTOP: |
| 208 | usage = WCM_DESKTOP; |
| 209 | i++; |
| 210 | break; |
| 211 | } |
| 212 | break; |
| 213 | |
| 214 | case HID_USAGE: |
| 215 | switch (report[i + 1]) { |
| 216 | case HID_USAGE_X: |
| 217 | if (usage == WCM_DESKTOP) { |
| 218 | if (finger) { |
Ping Cheng | 84eb5aa | 2011-03-12 20:35:18 -0800 | [diff] [blame] | 219 | features->device_type = BTN_TOOL_FINGER; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 220 | if (features->type == TABLETPC2FG) { |
| 221 | /* need to reset back */ |
| 222 | features->pktlen = WACOM_PKGLEN_TPC2FG; |
Ping Cheng | 84eb5aa | 2011-03-12 20:35:18 -0800 | [diff] [blame] | 223 | features->device_type = BTN_TOOL_DOUBLETAP; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 224 | } |
Ping Cheng | 4a88081 | 2010-09-05 12:25:40 -0700 | [diff] [blame] | 225 | if (features->type == BAMBOO_PT) { |
| 226 | /* need to reset back */ |
| 227 | features->pktlen = WACOM_PKGLEN_BBTOUCH; |
Ping Cheng | 84eb5aa | 2011-03-12 20:35:18 -0800 | [diff] [blame] | 228 | features->device_type = BTN_TOOL_DOUBLETAP; |
Ping Cheng | 4a88081 | 2010-09-05 12:25:40 -0700 | [diff] [blame] | 229 | features->x_phy = |
| 230 | get_unaligned_le16(&report[i + 5]); |
| 231 | features->x_max = |
| 232 | get_unaligned_le16(&report[i + 8]); |
| 233 | i += 15; |
| 234 | } else { |
| 235 | features->x_max = |
| 236 | get_unaligned_le16(&report[i + 3]); |
| 237 | features->x_phy = |
| 238 | get_unaligned_le16(&report[i + 6]); |
| 239 | features->unit = report[i + 9]; |
| 240 | features->unitExpo = report[i + 11]; |
| 241 | i += 12; |
| 242 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 243 | } else if (pen) { |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 244 | /* penabled only accepts exact bytes of data */ |
| 245 | if (features->type == TABLETPC2FG) |
Ping Cheng | 57e413d | 2010-03-01 23:50:24 -0800 | [diff] [blame] | 246 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
Ping Cheng | 4a88081 | 2010-09-05 12:25:40 -0700 | [diff] [blame] | 247 | if (features->type == BAMBOO_PT) |
| 248 | features->pktlen = WACOM_PKGLEN_BBFUN; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 249 | features->device_type = BTN_TOOL_PEN; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 250 | features->x_max = |
Dmitry Torokhov | 252f776 | 2010-03-19 22:33:38 -0700 | [diff] [blame] | 251 | get_unaligned_le16(&report[i + 3]); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 252 | i += 4; |
| 253 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 254 | } |
| 255 | break; |
| 256 | |
| 257 | case HID_USAGE_Y: |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 258 | if (usage == WCM_DESKTOP) { |
| 259 | if (finger) { |
Ping Cheng | 84eb5aa | 2011-03-12 20:35:18 -0800 | [diff] [blame] | 260 | features->device_type = BTN_TOOL_FINGER; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 261 | if (features->type == TABLETPC2FG) { |
| 262 | /* need to reset back */ |
| 263 | features->pktlen = WACOM_PKGLEN_TPC2FG; |
Ping Cheng | 84eb5aa | 2011-03-12 20:35:18 -0800 | [diff] [blame] | 264 | features->device_type = BTN_TOOL_DOUBLETAP; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 265 | features->y_max = |
Dmitry Torokhov | 252f776 | 2010-03-19 22:33:38 -0700 | [diff] [blame] | 266 | get_unaligned_le16(&report[i + 3]); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 267 | features->y_phy = |
Dmitry Torokhov | 252f776 | 2010-03-19 22:33:38 -0700 | [diff] [blame] | 268 | get_unaligned_le16(&report[i + 6]); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 269 | i += 7; |
Ping Cheng | 4a88081 | 2010-09-05 12:25:40 -0700 | [diff] [blame] | 270 | } else if (features->type == BAMBOO_PT) { |
| 271 | /* need to reset back */ |
| 272 | features->pktlen = WACOM_PKGLEN_BBTOUCH; |
Ping Cheng | 84eb5aa | 2011-03-12 20:35:18 -0800 | [diff] [blame] | 273 | features->device_type = BTN_TOOL_DOUBLETAP; |
Ping Cheng | 4a88081 | 2010-09-05 12:25:40 -0700 | [diff] [blame] | 274 | features->y_phy = |
| 275 | get_unaligned_le16(&report[i + 3]); |
| 276 | features->y_max = |
| 277 | get_unaligned_le16(&report[i + 6]); |
| 278 | i += 12; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 279 | } else { |
| 280 | features->y_max = |
| 281 | features->x_max; |
| 282 | features->y_phy = |
Dmitry Torokhov | 252f776 | 2010-03-19 22:33:38 -0700 | [diff] [blame] | 283 | get_unaligned_le16(&report[i + 3]); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 284 | i += 4; |
| 285 | } |
| 286 | } else if (pen) { |
| 287 | /* penabled only accepts exact bytes of data */ |
| 288 | if (features->type == TABLETPC2FG) |
Ping Cheng | 57e413d | 2010-03-01 23:50:24 -0800 | [diff] [blame] | 289 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
Ping Cheng | 4a88081 | 2010-09-05 12:25:40 -0700 | [diff] [blame] | 290 | if (features->type == BAMBOO_PT) |
| 291 | features->pktlen = WACOM_PKGLEN_BBFUN; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 292 | features->device_type = BTN_TOOL_PEN; |
| 293 | features->y_max = |
Dmitry Torokhov | 252f776 | 2010-03-19 22:33:38 -0700 | [diff] [blame] | 294 | get_unaligned_le16(&report[i + 3]); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 295 | i += 4; |
| 296 | } |
| 297 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 298 | break; |
| 299 | |
| 300 | case HID_USAGE_FINGER: |
| 301 | finger = 1; |
| 302 | i++; |
| 303 | break; |
| 304 | |
| 305 | case HID_USAGE_STYLUS: |
| 306 | pen = 1; |
| 307 | i++; |
| 308 | break; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 309 | } |
| 310 | break; |
| 311 | |
| 312 | case HID_COLLECTION: |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 313 | /* reset UsagePage and Finger */ |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 314 | finger = usage = 0; |
| 315 | break; |
| 316 | } |
| 317 | } |
| 318 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 319 | out: |
Ping Cheng | 384318e | 2009-04-28 07:49:54 -0700 | [diff] [blame] | 320 | result = 0; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 321 | kfree(report); |
| 322 | return result; |
| 323 | } |
| 324 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 325 | static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features) |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 326 | { |
| 327 | unsigned char *rep_data; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 328 | int limit = 0, report_id = 2; |
| 329 | int error = -ENOMEM; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 330 | |
Ping Cheng | 3b48c91 | 2011-08-16 00:17:57 -0700 | [diff] [blame] | 331 | rep_data = kmalloc(4, GFP_KERNEL); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 332 | if (!rep_data) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 333 | return error; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 334 | |
Ping Cheng | 3b48c91 | 2011-08-16 00:17:57 -0700 | [diff] [blame] | 335 | /* ask to report tablet data if it is MT Tablet PC or |
Chris Bagwell | 3dc9f40 | 2010-09-12 00:08:40 -0700 | [diff] [blame] | 336 | * not a Tablet PC */ |
| 337 | if (features->type == TABLETPC2FG) { |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 338 | do { |
| 339 | rep_data[0] = 3; |
| 340 | rep_data[1] = 4; |
Ping Cheng | 3b48c91 | 2011-08-16 00:17:57 -0700 | [diff] [blame] | 341 | rep_data[2] = 0; |
| 342 | rep_data[3] = 0; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 343 | report_id = 3; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 344 | error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT, |
| 345 | report_id, rep_data, 4, 1); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 346 | if (error >= 0) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 347 | error = wacom_get_report(intf, |
| 348 | WAC_HID_FEATURE_REPORT, |
| 349 | report_id, rep_data, 4, 1); |
Ping Cheng | a417ea4 | 2011-08-16 00:17:56 -0700 | [diff] [blame] | 350 | } while ((error < 0 || rep_data[1] != 4) && limit++ < WAC_MSG_RETRIES); |
Chris Bagwell | 3dc9f40 | 2010-09-12 00:08:40 -0700 | [diff] [blame] | 351 | } else if (features->type != TABLETPC) { |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 352 | do { |
| 353 | rep_data[0] = 2; |
| 354 | rep_data[1] = 2; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 355 | error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT, |
| 356 | report_id, rep_data, 2, 1); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 357 | if (error >= 0) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 358 | error = wacom_get_report(intf, |
| 359 | WAC_HID_FEATURE_REPORT, |
| 360 | report_id, rep_data, 2, 1); |
Ping Cheng | a417ea4 | 2011-08-16 00:17:56 -0700 | [diff] [blame] | 361 | } while ((error < 0 || rep_data[1] != 2) && limit++ < WAC_MSG_RETRIES); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 362 | } |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 363 | |
| 364 | kfree(rep_data); |
| 365 | |
| 366 | return error < 0 ? error : 0; |
| 367 | } |
| 368 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 369 | static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, |
| 370 | struct wacom_features *features) |
| 371 | { |
| 372 | int error = 0; |
| 373 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 374 | struct hid_descriptor *hid_desc; |
| 375 | |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 376 | /* default features */ |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 377 | features->device_type = BTN_TOOL_PEN; |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 378 | features->x_fuzz = 4; |
| 379 | features->y_fuzz = 4; |
| 380 | features->pressure_fuzz = 0; |
| 381 | features->distance_fuzz = 0; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 382 | |
Chris Bagwell | 3dc9f40 | 2010-09-12 00:08:40 -0700 | [diff] [blame] | 383 | /* only Tablet PCs and Bamboo P&T need to retrieve the info */ |
Ping Cheng | 4a88081 | 2010-09-05 12:25:40 -0700 | [diff] [blame] | 384 | if ((features->type != TABLETPC) && (features->type != TABLETPC2FG) && |
| 385 | (features->type != BAMBOO_PT)) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 386 | goto out; |
| 387 | |
| 388 | if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) { |
| 389 | if (usb_get_extra_descriptor(&interface->endpoint[0], |
| 390 | HID_DEVICET_REPORT, &hid_desc)) { |
| 391 | printk("wacom: can not retrieve extra class descriptor\n"); |
| 392 | error = 1; |
| 393 | goto out; |
| 394 | } |
| 395 | } |
| 396 | error = wacom_parse_hid(intf, hid_desc, features); |
| 397 | if (error) |
| 398 | goto out; |
| 399 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 400 | out: |
| 401 | return error; |
| 402 | } |
| 403 | |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 404 | struct wacom_usbdev_data { |
| 405 | struct list_head list; |
| 406 | struct kref kref; |
| 407 | struct usb_device *dev; |
| 408 | struct wacom_shared shared; |
| 409 | }; |
| 410 | |
| 411 | static LIST_HEAD(wacom_udev_list); |
| 412 | static DEFINE_MUTEX(wacom_udev_list_lock); |
| 413 | |
| 414 | static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev) |
| 415 | { |
| 416 | struct wacom_usbdev_data *data; |
| 417 | |
| 418 | list_for_each_entry(data, &wacom_udev_list, list) { |
| 419 | if (data->dev == dev) { |
| 420 | kref_get(&data->kref); |
| 421 | return data; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | return NULL; |
| 426 | } |
| 427 | |
| 428 | static int wacom_add_shared_data(struct wacom_wac *wacom, |
| 429 | struct usb_device *dev) |
| 430 | { |
| 431 | struct wacom_usbdev_data *data; |
| 432 | int retval = 0; |
| 433 | |
| 434 | mutex_lock(&wacom_udev_list_lock); |
| 435 | |
| 436 | data = wacom_get_usbdev_data(dev); |
| 437 | if (!data) { |
| 438 | data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL); |
| 439 | if (!data) { |
| 440 | retval = -ENOMEM; |
| 441 | goto out; |
| 442 | } |
| 443 | |
| 444 | kref_init(&data->kref); |
| 445 | data->dev = dev; |
| 446 | list_add_tail(&data->list, &wacom_udev_list); |
| 447 | } |
| 448 | |
| 449 | wacom->shared = &data->shared; |
| 450 | |
| 451 | out: |
| 452 | mutex_unlock(&wacom_udev_list_lock); |
| 453 | return retval; |
| 454 | } |
| 455 | |
| 456 | static void wacom_release_shared_data(struct kref *kref) |
| 457 | { |
| 458 | struct wacom_usbdev_data *data = |
| 459 | container_of(kref, struct wacom_usbdev_data, kref); |
| 460 | |
| 461 | mutex_lock(&wacom_udev_list_lock); |
| 462 | list_del(&data->list); |
| 463 | mutex_unlock(&wacom_udev_list_lock); |
| 464 | |
| 465 | kfree(data); |
| 466 | } |
| 467 | |
| 468 | static void wacom_remove_shared_data(struct wacom_wac *wacom) |
| 469 | { |
| 470 | struct wacom_usbdev_data *data; |
| 471 | |
| 472 | if (wacom->shared) { |
| 473 | data = container_of(wacom->shared, struct wacom_usbdev_data, shared); |
| 474 | kref_put(&data->kref, wacom_release_shared_data); |
| 475 | wacom->shared = NULL; |
| 476 | } |
| 477 | } |
| 478 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 479 | static int wacom_led_control(struct wacom *wacom) |
| 480 | { |
| 481 | unsigned char *buf; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 482 | int retval, led = 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 483 | |
| 484 | buf = kzalloc(9, GFP_KERNEL); |
| 485 | if (!buf) |
| 486 | return -ENOMEM; |
| 487 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 488 | if (wacom->wacom_wac.features.type == WACOM_21UX2) |
| 489 | led = (wacom->led.select[1] << 4) | 0x40; |
| 490 | |
| 491 | led |= wacom->led.select[0] | 0x4; |
| 492 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 493 | buf[0] = WAC_CMD_LED_CONTROL; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 494 | buf[1] = led; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 495 | buf[2] = wacom->led.llv; |
| 496 | buf[3] = wacom->led.hlv; |
| 497 | buf[4] = wacom->led.img_lum; |
| 498 | |
| 499 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL, |
| 500 | buf, 9, WAC_CMD_RETRIES); |
| 501 | kfree(buf); |
| 502 | |
| 503 | return retval; |
| 504 | } |
| 505 | |
| 506 | static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img) |
| 507 | { |
| 508 | unsigned char *buf; |
| 509 | int i, retval; |
| 510 | |
| 511 | buf = kzalloc(259, GFP_KERNEL); |
| 512 | if (!buf) |
| 513 | return -ENOMEM; |
| 514 | |
| 515 | /* Send 'start' command */ |
| 516 | buf[0] = WAC_CMD_ICON_START; |
| 517 | buf[1] = 1; |
| 518 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START, |
| 519 | buf, 2, WAC_CMD_RETRIES); |
| 520 | if (retval < 0) |
| 521 | goto out; |
| 522 | |
| 523 | buf[0] = WAC_CMD_ICON_XFER; |
| 524 | buf[1] = button_id & 0x07; |
| 525 | for (i = 0; i < 4; i++) { |
| 526 | buf[2] = i; |
| 527 | memcpy(buf + 3, img + i * 256, 256); |
| 528 | |
| 529 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER, |
| 530 | buf, 259, WAC_CMD_RETRIES); |
| 531 | if (retval < 0) |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | /* Send 'stop' */ |
| 536 | buf[0] = WAC_CMD_ICON_START; |
| 537 | buf[1] = 0; |
| 538 | wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START, |
| 539 | buf, 2, WAC_CMD_RETRIES); |
| 540 | |
| 541 | out: |
| 542 | kfree(buf); |
| 543 | return retval; |
| 544 | } |
| 545 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 546 | static ssize_t wacom_led_select_store(struct device *dev, int set_id, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 547 | const char *buf, size_t count) |
| 548 | { |
| 549 | struct wacom *wacom = dev_get_drvdata(dev); |
| 550 | unsigned int id; |
| 551 | int err; |
| 552 | |
| 553 | err = kstrtouint(buf, 10, &id); |
| 554 | if (err) |
| 555 | return err; |
| 556 | |
| 557 | mutex_lock(&wacom->lock); |
| 558 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 559 | wacom->led.select[set_id] = id & 0x3; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 560 | err = wacom_led_control(wacom); |
| 561 | |
| 562 | mutex_unlock(&wacom->lock); |
| 563 | |
| 564 | return err < 0 ? err : count; |
| 565 | } |
| 566 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 567 | #define DEVICE_LED_SELECT_ATTR(SET_ID) \ |
| 568 | static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \ |
| 569 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 570 | { \ |
| 571 | return wacom_led_select_store(dev, SET_ID, buf, count); \ |
| 572 | } \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 573 | static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ |
| 574 | struct device_attribute *attr, char *buf) \ |
| 575 | { \ |
| 576 | struct wacom *wacom = dev_get_drvdata(dev); \ |
| 577 | return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \ |
| 578 | } \ |
| 579 | static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \ |
| 580 | wacom_led##SET_ID##_select_show, \ |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 581 | wacom_led##SET_ID##_select_store) |
| 582 | |
| 583 | DEVICE_LED_SELECT_ATTR(0); |
| 584 | DEVICE_LED_SELECT_ATTR(1); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 585 | |
| 586 | static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, |
| 587 | const char *buf, size_t count) |
| 588 | { |
| 589 | unsigned int value; |
| 590 | int err; |
| 591 | |
| 592 | err = kstrtouint(buf, 10, &value); |
| 593 | if (err) |
| 594 | return err; |
| 595 | |
| 596 | mutex_lock(&wacom->lock); |
| 597 | |
| 598 | *dest = value & 0x7f; |
| 599 | err = wacom_led_control(wacom); |
| 600 | |
| 601 | mutex_unlock(&wacom->lock); |
| 602 | |
| 603 | return err < 0 ? err : count; |
| 604 | } |
| 605 | |
| 606 | #define DEVICE_LUMINANCE_ATTR(name, field) \ |
| 607 | static ssize_t wacom_##name##_luminance_store(struct device *dev, \ |
| 608 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 609 | { \ |
| 610 | struct wacom *wacom = dev_get_drvdata(dev); \ |
| 611 | \ |
| 612 | return wacom_luminance_store(wacom, &wacom->led.field, \ |
| 613 | buf, count); \ |
| 614 | } \ |
| 615 | static DEVICE_ATTR(name##_luminance, S_IWUSR, \ |
| 616 | NULL, wacom_##name##_luminance_store) |
| 617 | |
| 618 | DEVICE_LUMINANCE_ATTR(status0, llv); |
| 619 | DEVICE_LUMINANCE_ATTR(status1, hlv); |
| 620 | DEVICE_LUMINANCE_ATTR(buttons, img_lum); |
| 621 | |
| 622 | static ssize_t wacom_button_image_store(struct device *dev, int button_id, |
| 623 | const char *buf, size_t count) |
| 624 | { |
| 625 | struct wacom *wacom = dev_get_drvdata(dev); |
| 626 | int err; |
| 627 | |
| 628 | if (count != 1024) |
| 629 | return -EINVAL; |
| 630 | |
| 631 | mutex_lock(&wacom->lock); |
| 632 | |
| 633 | err = wacom_led_putimage(wacom, button_id, buf); |
| 634 | |
| 635 | mutex_unlock(&wacom->lock); |
| 636 | |
| 637 | return err < 0 ? err : count; |
| 638 | } |
| 639 | |
| 640 | #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \ |
| 641 | static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \ |
| 642 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 643 | { \ |
| 644 | return wacom_button_image_store(dev, BUTTON_ID, buf, count); \ |
| 645 | } \ |
| 646 | static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \ |
| 647 | NULL, wacom_btnimg##BUTTON_ID##_store) |
| 648 | |
| 649 | DEVICE_BTNIMG_ATTR(0); |
| 650 | DEVICE_BTNIMG_ATTR(1); |
| 651 | DEVICE_BTNIMG_ATTR(2); |
| 652 | DEVICE_BTNIMG_ATTR(3); |
| 653 | DEVICE_BTNIMG_ATTR(4); |
| 654 | DEVICE_BTNIMG_ATTR(5); |
| 655 | DEVICE_BTNIMG_ATTR(6); |
| 656 | DEVICE_BTNIMG_ATTR(7); |
| 657 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 658 | static struct attribute *cintiq_led_attrs[] = { |
| 659 | &dev_attr_status_led0_select.attr, |
| 660 | &dev_attr_status_led1_select.attr, |
| 661 | NULL |
| 662 | }; |
| 663 | |
| 664 | static struct attribute_group cintiq_led_attr_group = { |
| 665 | .name = "wacom_led", |
| 666 | .attrs = cintiq_led_attrs, |
| 667 | }; |
| 668 | |
| 669 | static struct attribute *intuos4_led_attrs[] = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 670 | &dev_attr_status0_luminance.attr, |
| 671 | &dev_attr_status1_luminance.attr, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 672 | &dev_attr_status_led0_select.attr, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 673 | &dev_attr_buttons_luminance.attr, |
| 674 | &dev_attr_button0_rawimg.attr, |
| 675 | &dev_attr_button1_rawimg.attr, |
| 676 | &dev_attr_button2_rawimg.attr, |
| 677 | &dev_attr_button3_rawimg.attr, |
| 678 | &dev_attr_button4_rawimg.attr, |
| 679 | &dev_attr_button5_rawimg.attr, |
| 680 | &dev_attr_button6_rawimg.attr, |
| 681 | &dev_attr_button7_rawimg.attr, |
| 682 | NULL |
| 683 | }; |
| 684 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 685 | static struct attribute_group intuos4_led_attr_group = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 686 | .name = "wacom_led", |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 687 | .attrs = intuos4_led_attrs, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 688 | }; |
| 689 | |
| 690 | static int wacom_initialize_leds(struct wacom *wacom) |
| 691 | { |
| 692 | int error; |
| 693 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 694 | /* Initialize default values */ |
| 695 | switch (wacom->wacom_wac.features.type) { |
| 696 | case INTUOS4: |
| 697 | case INTUOS4L: |
| 698 | wacom->led.select[0] = 0; |
| 699 | wacom->led.select[1] = 0; |
Ping Cheng | f4fa9a6 | 2011-10-04 23:49:42 -0700 | [diff] [blame] | 700 | wacom->led.llv = 10; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 701 | wacom->led.hlv = 20; |
| 702 | wacom->led.img_lum = 10; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 703 | error = sysfs_create_group(&wacom->intf->dev.kobj, |
| 704 | &intuos4_led_attr_group); |
| 705 | break; |
| 706 | |
| 707 | case WACOM_21UX2: |
| 708 | wacom->led.select[0] = 0; |
| 709 | wacom->led.select[1] = 0; |
| 710 | wacom->led.llv = 0; |
| 711 | wacom->led.hlv = 0; |
| 712 | wacom->led.img_lum = 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 713 | |
| 714 | error = sysfs_create_group(&wacom->intf->dev.kobj, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 715 | &cintiq_led_attr_group); |
| 716 | break; |
| 717 | |
| 718 | default: |
| 719 | return 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 722 | if (error) { |
| 723 | dev_err(&wacom->intf->dev, |
| 724 | "cannot create sysfs group err: %d\n", error); |
| 725 | return error; |
| 726 | } |
| 727 | wacom_led_control(wacom); |
| 728 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | static void wacom_destroy_leds(struct wacom *wacom) |
| 733 | { |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 734 | switch (wacom->wacom_wac.features.type) { |
| 735 | case INTUOS4: |
| 736 | case INTUOS4L: |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 737 | sysfs_remove_group(&wacom->intf->dev.kobj, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 738 | &intuos4_led_attr_group); |
| 739 | break; |
| 740 | |
| 741 | case WACOM_21UX2: |
| 742 | sysfs_remove_group(&wacom->intf->dev.kobj, |
| 743 | &cintiq_led_attr_group); |
| 744 | break; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 748 | static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 749 | { |
| 750 | struct usb_device *dev = interface_to_usbdev(intf); |
| 751 | struct usb_endpoint_descriptor *endpoint; |
| 752 | struct wacom *wacom; |
| 753 | struct wacom_wac *wacom_wac; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 754 | struct wacom_features *features; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 755 | struct input_dev *input_dev; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 756 | int error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 757 | |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 758 | if (!id->driver_info) |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 759 | return -EINVAL; |
| 760 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 761 | wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 762 | input_dev = input_allocate_device(); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 763 | if (!wacom || !input_dev) { |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 764 | error = -ENOMEM; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 765 | goto fail1; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 766 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 767 | |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 768 | wacom_wac = &wacom->wacom_wac; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 769 | wacom_wac->features = *((struct wacom_features *)id->driver_info); |
| 770 | features = &wacom_wac->features; |
| 771 | if (features->pktlen > WACOM_PKGLEN_MAX) { |
| 772 | error = -EINVAL; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 773 | goto fail1; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 774 | } |
| 775 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 776 | wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX, |
| 777 | GFP_KERNEL, &wacom->data_dma); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 778 | if (!wacom_wac->data) { |
| 779 | error = -ENOMEM; |
| 780 | goto fail1; |
| 781 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 782 | |
| 783 | wacom->irq = usb_alloc_urb(0, GFP_KERNEL); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 784 | if (!wacom->irq) { |
| 785 | error = -ENOMEM; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 786 | goto fail2; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 787 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 788 | |
| 789 | wacom->usbdev = dev; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 790 | wacom->intf = intf; |
| 791 | mutex_init(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 792 | usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); |
| 793 | strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); |
| 794 | |
Dmitry Torokhov | 8da23fc | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 795 | wacom_wac->input = input_dev; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 796 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 797 | endpoint = &intf->cur_altsetting->endpoint[0].desc; |
| 798 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 799 | /* Retrieve the physical and logical size for OEM devices */ |
| 800 | error = wacom_retrieve_hid_descriptor(intf, features); |
| 801 | if (error) |
Alexander Strakh | 4b6d443 | 2011-02-11 00:44:41 -0800 | [diff] [blame] | 802 | goto fail3; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 803 | |
Henrik Rydberg | bc73dd3 | 2010-09-05 12:26:16 -0700 | [diff] [blame] | 804 | wacom_setup_device_quirks(features); |
| 805 | |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 806 | strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); |
| 807 | |
Henrik Rydberg | bc73dd3 | 2010-09-05 12:26:16 -0700 | [diff] [blame] | 808 | if (features->quirks & WACOM_QUIRK_MULTI_INPUT) { |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 809 | /* Append the device type to the name */ |
| 810 | strlcat(wacom_wac->name, |
| 811 | features->device_type == BTN_TOOL_PEN ? |
| 812 | " Pen" : " Finger", |
| 813 | sizeof(wacom_wac->name)); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 814 | |
| 815 | error = wacom_add_shared_data(wacom_wac, dev); |
| 816 | if (error) |
| 817 | goto fail3; |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | input_dev->name = wacom_wac->name; |
Dmitry Torokhov | 8da23fc | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 821 | input_dev->dev.parent = &intf->dev; |
| 822 | input_dev->open = wacom_open; |
| 823 | input_dev->close = wacom_close; |
| 824 | usb_to_input_id(dev, &input_dev->id); |
| 825 | input_set_drvdata(input_dev, wacom); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 826 | |
Dmitry Torokhov | 8da23fc | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 827 | wacom_setup_input_capabilities(input_dev, wacom_wac); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 828 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 829 | usb_fill_int_urb(wacom->irq, dev, |
| 830 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 831 | wacom_wac->data, features->pktlen, |
Ping Cheng | 8d32e3a | 2006-09-26 13:34:47 -0700 | [diff] [blame] | 832 | wacom_sys_irq, wacom, endpoint->bInterval); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 833 | wacom->irq->transfer_dma = wacom->data_dma; |
| 834 | wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 835 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 836 | error = wacom_initialize_leds(wacom); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 837 | if (error) |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 838 | goto fail4; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 839 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 840 | error = input_register_device(input_dev); |
| 841 | if (error) |
| 842 | goto fail5; |
| 843 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 844 | /* Note that if query fails it is not a hard failure */ |
| 845 | wacom_query_tablet_data(intf, features); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 846 | |
| 847 | usb_set_intfdata(intf, wacom); |
| 848 | return 0; |
| 849 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 850 | fail5: wacom_destroy_leds(wacom); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 851 | fail4: wacom_remove_shared_data(wacom_wac); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 852 | fail3: usb_free_urb(wacom->irq); |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 853 | fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 854 | fail1: input_free_device(input_dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 855 | kfree(wacom); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 856 | return error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | static void wacom_disconnect(struct usb_interface *intf) |
| 860 | { |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 861 | struct wacom *wacom = usb_get_intfdata(intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 862 | |
| 863 | usb_set_intfdata(intf, NULL); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 864 | |
| 865 | usb_kill_urb(wacom->irq); |
Dmitry Torokhov | 8da23fc | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 866 | input_unregister_device(wacom->wacom_wac.input); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 867 | wacom_destroy_leds(wacom); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 868 | usb_free_urb(wacom->irq); |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 869 | usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX, |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 870 | wacom->wacom_wac.data, wacom->data_dma); |
| 871 | wacom_remove_shared_data(&wacom->wacom_wac); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 872 | kfree(wacom); |
| 873 | } |
| 874 | |
| 875 | static int wacom_suspend(struct usb_interface *intf, pm_message_t message) |
| 876 | { |
| 877 | struct wacom *wacom = usb_get_intfdata(intf); |
| 878 | |
| 879 | mutex_lock(&wacom->lock); |
| 880 | usb_kill_urb(wacom->irq); |
| 881 | mutex_unlock(&wacom->lock); |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int wacom_resume(struct usb_interface *intf) |
| 887 | { |
| 888 | struct wacom *wacom = usb_get_intfdata(intf); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 889 | struct wacom_features *features = &wacom->wacom_wac.features; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 890 | int rv = 0; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 891 | |
| 892 | mutex_lock(&wacom->lock); |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 893 | |
| 894 | /* switch to wacom mode first */ |
| 895 | wacom_query_tablet_data(intf, features); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 896 | wacom_led_control(wacom); |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 897 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 898 | if (wacom->open && usb_submit_urb(wacom->irq, GFP_NOIO) < 0) |
| 899 | rv = -EIO; |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 900 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 901 | mutex_unlock(&wacom->lock); |
| 902 | |
| 903 | return rv; |
| 904 | } |
| 905 | |
| 906 | static int wacom_reset_resume(struct usb_interface *intf) |
| 907 | { |
| 908 | return wacom_resume(intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static struct usb_driver wacom_driver = { |
| 912 | .name = "wacom", |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 913 | .id_table = wacom_ids, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 914 | .probe = wacom_probe, |
| 915 | .disconnect = wacom_disconnect, |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 916 | .suspend = wacom_suspend, |
| 917 | .resume = wacom_resume, |
| 918 | .reset_resume = wacom_reset_resume, |
| 919 | .supports_autosuspend = 1, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 920 | }; |
| 921 | |
| 922 | static int __init wacom_init(void) |
| 923 | { |
| 924 | int result; |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 925 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 926 | result = usb_register(&wacom_driver); |
| 927 | if (result == 0) |
Greg Kroah-Hartman | 899ef6e | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 928 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 929 | DRIVER_DESC "\n"); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 930 | return result; |
| 931 | } |
| 932 | |
| 933 | static void __exit wacom_exit(void) |
| 934 | { |
| 935 | usb_deregister(&wacom_driver); |
| 936 | } |
| 937 | |
| 938 | module_init(wacom_init); |
| 939 | module_exit(wacom_exit); |