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