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 |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 25 | #define HID_USAGE_X ((HID_USAGE_PAGE_DESKTOP << 16) | 0x30) |
| 26 | #define HID_USAGE_Y ((HID_USAGE_PAGE_DESKTOP << 16) | 0x31) |
Jason Gerecke | e9fc413 | 2014-04-19 13:49:37 -0700 | [diff] [blame] | 27 | #define HID_USAGE_PRESSURE ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x30) |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 28 | #define HID_USAGE_X_TILT ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x3d) |
| 29 | #define HID_USAGE_Y_TILT ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x3e) |
| 30 | #define HID_USAGE_FINGER ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x22) |
| 31 | #define HID_USAGE_STYLUS ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x20) |
| 32 | #define HID_USAGE_CONTACTMAX ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x55) |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 33 | #define HID_COLLECTION 0xa1 |
| 34 | #define HID_COLLECTION_LOGICAL 0x02 |
| 35 | #define HID_COLLECTION_END 0xc0 |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 36 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 37 | struct hid_descriptor { |
| 38 | struct usb_descriptor_header header; |
| 39 | __le16 bcdHID; |
| 40 | u8 bCountryCode; |
| 41 | u8 bNumDescriptors; |
| 42 | u8 bDescriptorType; |
| 43 | __le16 wDescriptorLength; |
| 44 | } __attribute__ ((packed)); |
| 45 | |
| 46 | /* defines to get/set USB message */ |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 47 | #define USB_REQ_GET_REPORT 0x01 |
| 48 | #define USB_REQ_SET_REPORT 0x09 |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 49 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 50 | #define WAC_HID_FEATURE_REPORT 0x03 |
Ping Cheng | a417ea4 | 2011-08-16 00:17:56 -0700 | [diff] [blame] | 51 | #define WAC_MSG_RETRIES 5 |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 52 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 53 | #define WAC_CMD_LED_CONTROL 0x20 |
| 54 | #define WAC_CMD_ICON_START 0x21 |
| 55 | #define WAC_CMD_ICON_XFER 0x23 |
| 56 | #define WAC_CMD_RETRIES 10 |
| 57 | |
| 58 | static int wacom_get_report(struct usb_interface *intf, u8 type, u8 id, |
| 59 | void *buf, size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 60 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 61 | struct usb_device *dev = interface_to_usbdev(intf); |
| 62 | int retval; |
| 63 | |
| 64 | do { |
| 65 | retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 66 | USB_REQ_GET_REPORT, |
Chris Bagwell | 6e8ec53 | 2011-10-26 22:24:22 -0700 | [diff] [blame] | 67 | USB_DIR_IN | USB_TYPE_CLASS | |
| 68 | USB_RECIP_INTERFACE, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 69 | (type << 8) + id, |
| 70 | intf->altsetting[0].desc.bInterfaceNumber, |
| 71 | buf, size, 100); |
| 72 | } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries); |
| 73 | |
| 74 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 77 | static int wacom_set_report(struct usb_interface *intf, u8 type, u8 id, |
| 78 | void *buf, size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 79 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 80 | struct usb_device *dev = interface_to_usbdev(intf); |
| 81 | int retval; |
| 82 | |
| 83 | do { |
| 84 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 85 | USB_REQ_SET_REPORT, |
| 86 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 87 | (type << 8) + id, |
| 88 | intf->altsetting[0].desc.bInterfaceNumber, |
| 89 | buf, size, 1000); |
| 90 | } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries); |
| 91 | |
| 92 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Adrian Bunk | 54c9b226 | 2006-11-20 03:23:58 +0100 | [diff] [blame] | 95 | static void wacom_sys_irq(struct urb *urb) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 96 | { |
| 97 | struct wacom *wacom = urb->context; |
Greg Kroah-Hartman | 65e78a20 | 2012-05-04 15:33:13 -0700 | [diff] [blame] | 98 | struct device *dev = &wacom->intf->dev; |
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 */ |
Greg Kroah-Hartman | 3b6aee2 | 2012-05-01 21:24:28 -0700 | [diff] [blame] | 109 | dev_dbg(dev, "%s - urb shutting down with status: %d\n", |
| 110 | __func__, urb->status); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 111 | return; |
| 112 | default: |
Greg Kroah-Hartman | 3b6aee2 | 2012-05-01 21:24:28 -0700 | [diff] [blame] | 113 | dev_dbg(dev, "%s - nonzero urb status received: %d\n", |
| 114 | __func__, urb->status); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 115 | goto exit; |
| 116 | } |
| 117 | |
Dmitry Torokhov | 95dd3b3 | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 118 | wacom_wac_irq(&wacom->wacom_wac, urb->actual_length); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 119 | |
| 120 | exit: |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 121 | usb_mark_last_busy(wacom->usbdev); |
Dmitry Torokhov | 73a97f4 | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 122 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 123 | if (retval) |
Greg Kroah-Hartman | 3b6aee2 | 2012-05-01 21:24:28 -0700 | [diff] [blame] | 124 | dev_err(dev, "%s - usb_submit_urb failed with result %d\n", |
Greg Kroah-Hartman | b3169fe | 2012-04-25 14:48:44 -0700 | [diff] [blame] | 125 | __func__, retval); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 128 | static int wacom_open(struct input_dev *dev) |
| 129 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 130 | struct wacom *wacom = input_get_drvdata(dev); |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 131 | int retval = 0; |
| 132 | |
| 133 | if (usb_autopm_get_interface(wacom->intf) < 0) |
| 134 | return -EIO; |
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 | mutex_lock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 137 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 138 | if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 139 | retval = -EIO; |
| 140 | goto out; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 143 | wacom->open = true; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 144 | wacom->intf->needs_remote_wakeup = 1; |
| 145 | |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 146 | out: |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 147 | mutex_unlock(&wacom->lock); |
Dmitry Torokhov | 62ecae0 | 2010-10-10 14:24:16 -0700 | [diff] [blame] | 148 | usb_autopm_put_interface(wacom->intf); |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 149 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static void wacom_close(struct input_dev *dev) |
| 153 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 154 | struct wacom *wacom = input_get_drvdata(dev); |
Dmitry Torokhov | 62ecae0 | 2010-10-10 14:24:16 -0700 | [diff] [blame] | 155 | int autopm_error; |
| 156 | |
| 157 | autopm_error = usb_autopm_get_interface(wacom->intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 158 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 159 | mutex_lock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 160 | usb_kill_urb(wacom->irq); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 161 | wacom->open = false; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 162 | wacom->intf->needs_remote_wakeup = 0; |
| 163 | mutex_unlock(&wacom->lock); |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 164 | |
Dmitry Torokhov | 62ecae0 | 2010-10-10 14:24:16 -0700 | [diff] [blame] | 165 | if (!autopm_error) |
| 166 | usb_autopm_put_interface(wacom->intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 169 | /* |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 170 | * Calculate the resolution of the X or Y axis, given appropriate HID data. |
| 171 | * This function is little more than hidinput_calc_abs_res stripped down. |
| 172 | */ |
| 173 | static int wacom_calc_hid_res(int logical_extents, int physical_extents, |
| 174 | unsigned char unit, unsigned char exponent) |
| 175 | { |
| 176 | int prev, unit_exponent; |
| 177 | |
| 178 | /* Check if the extents are sane */ |
| 179 | if (logical_extents <= 0 || physical_extents <= 0) |
| 180 | return 0; |
| 181 | |
| 182 | /* Get signed value of nybble-sized twos-compliment exponent */ |
| 183 | unit_exponent = exponent; |
| 184 | if (unit_exponent > 7) |
| 185 | unit_exponent -= 16; |
| 186 | |
| 187 | /* Convert physical_extents to millimeters */ |
| 188 | if (unit == 0x11) { /* If centimeters */ |
| 189 | unit_exponent += 1; |
| 190 | } else if (unit == 0x13) { /* If inches */ |
| 191 | prev = physical_extents; |
| 192 | physical_extents *= 254; |
| 193 | if (physical_extents < prev) |
| 194 | return 0; |
| 195 | unit_exponent -= 1; |
| 196 | } else { |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | /* Apply negative unit exponent */ |
| 201 | for (; unit_exponent < 0; unit_exponent++) { |
| 202 | prev = logical_extents; |
| 203 | logical_extents *= 10; |
| 204 | if (logical_extents < prev) |
| 205 | return 0; |
| 206 | } |
| 207 | /* Apply positive unit exponent */ |
| 208 | for (; unit_exponent > 0; unit_exponent--) { |
| 209 | prev = physical_extents; |
| 210 | physical_extents *= 10; |
| 211 | if (physical_extents < prev) |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | /* Calculate resolution */ |
| 216 | return logical_extents / physical_extents; |
| 217 | } |
| 218 | |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 219 | static int wacom_parse_logical_collection(unsigned char *report, |
| 220 | struct wacom_features *features) |
| 221 | { |
| 222 | int length = 0; |
| 223 | |
| 224 | if (features->type == BAMBOO_PT) { |
| 225 | |
| 226 | /* Logical collection is only used by 3rd gen Bamboo Touch */ |
| 227 | features->pktlen = WACOM_PKGLEN_BBTOUCH3; |
Ping Cheng | 8b4a0c1f | 2012-01-31 00:07:33 -0800 | [diff] [blame] | 228 | features->device_type = BTN_TOOL_FINGER; |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 229 | |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 230 | features->x_max = features->y_max = |
| 231 | get_unaligned_le16(&report[10]); |
| 232 | |
| 233 | length = 11; |
| 234 | } |
| 235 | return length; |
| 236 | } |
| 237 | |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 238 | static void wacom_retrieve_report_data(struct usb_interface *intf, |
| 239 | struct wacom_features *features) |
| 240 | { |
| 241 | int result = 0; |
| 242 | unsigned char *rep_data; |
| 243 | |
| 244 | rep_data = kmalloc(2, GFP_KERNEL); |
| 245 | if (rep_data) { |
| 246 | |
| 247 | rep_data[0] = 12; |
| 248 | result = wacom_get_report(intf, WAC_HID_FEATURE_REPORT, |
Ping Cheng | 61c91dd | 2012-06-28 16:46:27 -0700 | [diff] [blame] | 249 | rep_data[0], rep_data, 2, |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 250 | WAC_MSG_RETRIES); |
| 251 | |
| 252 | if (result >= 0 && rep_data[1] > 2) |
| 253 | features->touch_max = rep_data[1]; |
| 254 | |
| 255 | kfree(rep_data); |
| 256 | } |
| 257 | } |
| 258 | |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 259 | /* |
| 260 | * Interface Descriptor of wacom devices can be incomplete and |
| 261 | * inconsistent so wacom_features table is used to store stylus |
| 262 | * device's packet lengths, various maximum values, and tablet |
| 263 | * resolution based on product ID's. |
| 264 | * |
| 265 | * For devices that contain 2 interfaces, wacom_features table is |
| 266 | * inaccurate for the touch interface. Since the Interface Descriptor |
| 267 | * for touch interfaces has pretty complete data, this function exists |
| 268 | * to query tablet for this missing information instead of hard coding in |
| 269 | * an additional table. |
| 270 | * |
| 271 | * A typical Interface Descriptor for a stylus will contain a |
| 272 | * boot mouse application collection that is not of interest and this |
| 273 | * function will ignore it. |
| 274 | * |
| 275 | * It also contains a digitizer application collection that also is not |
| 276 | * of interest since any information it contains would be duplicate |
| 277 | * of what is in wacom_features. Usually it defines a report of an array |
| 278 | * of bytes that could be used as max length of the stylus packet returned. |
| 279 | * If it happens to define a Digitizer-Stylus Physical Collection then |
| 280 | * the X and Y logical values contain valid data but it is ignored. |
| 281 | * |
| 282 | * A typical Interface Descriptor for a touch interface will contain a |
| 283 | * Digitizer-Finger Physical Collection which will define both logical |
| 284 | * X/Y maximum as well as the physical size of tablet. Since touch |
| 285 | * interfaces haven't supported pressure or distance, this is enough |
| 286 | * information to override invalid values in the wacom_features table. |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 287 | * |
| 288 | * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical |
| 289 | * Collection. Instead they define a Logical Collection with a single |
| 290 | * Logical Maximum for both X and Y. |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 291 | * |
| 292 | * Intuos5 touch interface does not contain useful data. We deal with |
| 293 | * this after returning from this function. |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 294 | */ |
| 295 | static int wacom_parse_hid(struct usb_interface *intf, |
| 296 | struct hid_descriptor *hid_desc, |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 297 | struct wacom_features *features) |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 298 | { |
| 299 | struct usb_device *dev = interface_to_usbdev(intf); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 300 | char limit = 0; |
| 301 | /* result has to be defined as int for some devices */ |
Ping Cheng | 1d0d6df | 2013-11-25 18:43:45 -0800 | [diff] [blame] | 302 | int result = 0, touch_max = 0; |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 303 | int i = 0, page = 0, finger = 0, pen = 0; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 304 | unsigned char *report; |
| 305 | |
| 306 | report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL); |
| 307 | if (!report) |
| 308 | return -ENOMEM; |
| 309 | |
| 310 | /* retrive report descriptors */ |
| 311 | do { |
| 312 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 313 | USB_REQ_GET_DESCRIPTOR, |
| 314 | USB_RECIP_INTERFACE | USB_DIR_IN, |
| 315 | HID_DEVICET_REPORT << 8, |
| 316 | intf->altsetting[0].desc.bInterfaceNumber, /* interface */ |
| 317 | report, |
| 318 | hid_desc->wDescriptorLength, |
| 319 | 5000); /* 5 secs */ |
Ping Cheng | a417ea4 | 2011-08-16 00:17:56 -0700 | [diff] [blame] | 320 | } while (result < 0 && limit++ < WAC_MSG_RETRIES); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 321 | |
Ping Cheng | 384318e | 2009-04-28 07:49:54 -0700 | [diff] [blame] | 322 | /* No need to parse the Descriptor. It isn't an error though */ |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 323 | if (result < 0) |
| 324 | goto out; |
| 325 | |
| 326 | for (i = 0; i < hid_desc->wDescriptorLength; i++) { |
| 327 | |
| 328 | switch (report[i]) { |
| 329 | case HID_USAGE_PAGE: |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 330 | page = report[i + 1]; |
| 331 | i++; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 332 | break; |
| 333 | |
| 334 | case HID_USAGE: |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 335 | switch (page << 16 | report[i + 1]) { |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 336 | case HID_USAGE_X: |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 337 | if (finger) { |
| 338 | features->device_type = BTN_TOOL_FINGER; |
| 339 | /* touch device at least supports one touch point */ |
| 340 | touch_max = 1; |
| 341 | switch (features->type) { |
| 342 | case TABLETPC2FG: |
| 343 | features->pktlen = WACOM_PKGLEN_TPC2FG; |
| 344 | break; |
Ping Cheng | 3699dd7 | 2012-11-03 12:16:13 -0700 | [diff] [blame] | 345 | |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 346 | case MTSCREEN: |
| 347 | case WACOM_24HDT: |
| 348 | features->pktlen = WACOM_PKGLEN_MTOUCH; |
| 349 | break; |
Ping Cheng | 3699dd7 | 2012-11-03 12:16:13 -0700 | [diff] [blame] | 350 | |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 351 | case MTTPC: |
Jason Gerecke | d51ddb2 | 2014-05-14 17:14:29 -0700 | [diff] [blame] | 352 | case MTTPC_B: |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 353 | features->pktlen = WACOM_PKGLEN_MTTPC; |
| 354 | break; |
Ping Cheng | 6afdc28 | 2012-11-03 12:16:15 -0700 | [diff] [blame] | 355 | |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 356 | case BAMBOO_PT: |
| 357 | features->pktlen = WACOM_PKGLEN_BBTOUCH; |
| 358 | break; |
Ping Cheng | 3699dd7 | 2012-11-03 12:16:13 -0700 | [diff] [blame] | 359 | |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 360 | default: |
| 361 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
| 362 | break; |
| 363 | } |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 364 | |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 365 | switch (features->type) { |
| 366 | case BAMBOO_PT: |
| 367 | features->x_phy = |
| 368 | get_unaligned_le16(&report[i + 5]); |
| 369 | features->x_max = |
| 370 | get_unaligned_le16(&report[i + 8]); |
| 371 | i += 15; |
| 372 | break; |
Ping Cheng | 3699dd7 | 2012-11-03 12:16:13 -0700 | [diff] [blame] | 373 | |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 374 | case WACOM_24HDT: |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 375 | features->x_max = |
Dmitry Torokhov | 252f776 | 2010-03-19 22:33:38 -0700 | [diff] [blame] | 376 | get_unaligned_le16(&report[i + 3]); |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 377 | features->x_phy = |
| 378 | get_unaligned_le16(&report[i + 8]); |
| 379 | features->unit = report[i - 1]; |
| 380 | features->unitExpo = report[i - 3]; |
| 381 | i += 12; |
| 382 | break; |
| 383 | |
Jason Gerecke | d51ddb2 | 2014-05-14 17:14:29 -0700 | [diff] [blame] | 384 | case MTTPC_B: |
| 385 | features->x_max = |
| 386 | get_unaligned_le16(&report[i + 3]); |
| 387 | features->x_phy = |
| 388 | get_unaligned_le16(&report[i + 6]); |
| 389 | features->unit = report[i - 5]; |
| 390 | features->unitExpo = report[i - 3]; |
| 391 | i += 9; |
| 392 | break; |
| 393 | |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 394 | default: |
| 395 | features->x_max = |
| 396 | get_unaligned_le16(&report[i + 3]); |
| 397 | features->x_phy = |
| 398 | get_unaligned_le16(&report[i + 6]); |
| 399 | features->unit = report[i + 9]; |
| 400 | features->unitExpo = report[i + 11]; |
| 401 | i += 12; |
| 402 | break; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 403 | } |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 404 | } else if (pen) { |
| 405 | /* penabled only accepts exact bytes of data */ |
| 406 | if (features->type >= TABLETPC) |
| 407 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
| 408 | features->device_type = BTN_TOOL_PEN; |
| 409 | features->x_max = |
| 410 | get_unaligned_le16(&report[i + 3]); |
| 411 | i += 4; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 412 | } |
| 413 | break; |
| 414 | |
| 415 | case HID_USAGE_Y: |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 416 | if (finger) { |
| 417 | switch (features->type) { |
| 418 | case TABLETPC2FG: |
| 419 | case MTSCREEN: |
| 420 | case MTTPC: |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 421 | features->y_max = |
Dmitry Torokhov | 252f776 | 2010-03-19 22:33:38 -0700 | [diff] [blame] | 422 | get_unaligned_le16(&report[i + 3]); |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 423 | features->y_phy = |
| 424 | get_unaligned_le16(&report[i + 6]); |
| 425 | i += 7; |
| 426 | break; |
| 427 | |
| 428 | case WACOM_24HDT: |
| 429 | features->y_max = |
| 430 | get_unaligned_le16(&report[i + 3]); |
| 431 | features->y_phy = |
| 432 | get_unaligned_le16(&report[i - 2]); |
| 433 | i += 7; |
| 434 | break; |
| 435 | |
| 436 | case BAMBOO_PT: |
| 437 | features->y_phy = |
| 438 | get_unaligned_le16(&report[i + 3]); |
| 439 | features->y_max = |
| 440 | get_unaligned_le16(&report[i + 6]); |
| 441 | i += 12; |
| 442 | break; |
| 443 | |
Jason Gerecke | d51ddb2 | 2014-05-14 17:14:29 -0700 | [diff] [blame] | 444 | case MTTPC_B: |
| 445 | features->y_max = |
| 446 | get_unaligned_le16(&report[i + 3]); |
| 447 | features->y_phy = |
| 448 | get_unaligned_le16(&report[i + 6]); |
| 449 | i += 9; |
| 450 | break; |
| 451 | |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 452 | default: |
| 453 | features->y_max = |
| 454 | features->x_max; |
| 455 | features->y_phy = |
| 456 | get_unaligned_le16(&report[i + 3]); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 457 | i += 4; |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 458 | break; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 459 | } |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 460 | } else if (pen) { |
| 461 | features->y_max = |
| 462 | get_unaligned_le16(&report[i + 3]); |
| 463 | i += 4; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 464 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 465 | break; |
| 466 | |
| 467 | case HID_USAGE_FINGER: |
| 468 | finger = 1; |
| 469 | i++; |
| 470 | break; |
| 471 | |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 472 | /* |
| 473 | * Requiring Stylus Usage will ignore boot mouse |
| 474 | * X/Y values and some cases of invalid Digitizer X/Y |
| 475 | * values commonly reported. |
| 476 | */ |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 477 | case HID_USAGE_STYLUS: |
| 478 | pen = 1; |
| 479 | i++; |
| 480 | break; |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 481 | |
| 482 | case HID_USAGE_CONTACTMAX: |
Ping Cheng | 1cecc5c | 2012-06-28 16:47:30 -0700 | [diff] [blame] | 483 | /* leave touch_max as is if predefined */ |
| 484 | if (!features->touch_max) |
| 485 | wacom_retrieve_report_data(intf, features); |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 486 | i++; |
| 487 | break; |
Jason Gerecke | e9fc413 | 2014-04-19 13:49:37 -0700 | [diff] [blame] | 488 | |
| 489 | case HID_USAGE_PRESSURE: |
| 490 | if (pen) { |
| 491 | features->pressure_max = |
| 492 | get_unaligned_le16(&report[i + 3]); |
| 493 | i += 4; |
| 494 | } |
| 495 | break; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 496 | } |
| 497 | break; |
| 498 | |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 499 | case HID_COLLECTION_END: |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 500 | /* reset UsagePage and Finger */ |
Jason Gerecke | 5866d9e | 2014-04-19 13:46:40 -0700 | [diff] [blame] | 501 | finger = page = 0; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 502 | break; |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 503 | |
| 504 | case HID_COLLECTION: |
| 505 | i++; |
| 506 | switch (report[i]) { |
| 507 | case HID_COLLECTION_LOGICAL: |
| 508 | i += wacom_parse_logical_collection(&report[i], |
| 509 | features); |
| 510 | break; |
| 511 | } |
| 512 | break; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 516 | out: |
Ping Cheng | 1d0d6df | 2013-11-25 18:43:45 -0800 | [diff] [blame] | 517 | if (!features->touch_max && touch_max) |
| 518 | features->touch_max = touch_max; |
Ping Cheng | 384318e | 2009-04-28 07:49:54 -0700 | [diff] [blame] | 519 | result = 0; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 520 | kfree(report); |
| 521 | return result; |
| 522 | } |
| 523 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 524 | static int wacom_set_device_mode(struct usb_interface *intf, int report_id, int length, int mode) |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 525 | { |
| 526 | unsigned char *rep_data; |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 527 | int error = -ENOMEM, limit = 0; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 528 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 529 | rep_data = kzalloc(length, GFP_KERNEL); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 530 | if (!rep_data) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 531 | return error; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 532 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 533 | do { |
Chris Bagwell | 9937c02 | 2013-01-23 19:37:34 -0800 | [diff] [blame] | 534 | rep_data[0] = report_id; |
| 535 | rep_data[1] = mode; |
| 536 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 537 | error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT, |
| 538 | report_id, rep_data, length, 1); |
Benjamin Tissoires | 3cb8315 | 2014-07-24 12:47:47 -0700 | [diff] [blame] | 539 | if (error >= 0) |
| 540 | error = wacom_get_report(intf, WAC_HID_FEATURE_REPORT, |
| 541 | report_id, rep_data, length, 1); |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 542 | } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 543 | |
| 544 | kfree(rep_data); |
| 545 | |
| 546 | return error < 0 ? error : 0; |
| 547 | } |
| 548 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 549 | /* |
| 550 | * Switch the tablet into its most-capable mode. Wacom tablets are |
| 551 | * typically configured to power-up in a mode which sends mouse-like |
| 552 | * reports to the OS. To get absolute position, pressure data, etc. |
| 553 | * from the tablet, it is necessary to switch the tablet out of this |
| 554 | * mode and into one which sends the full range of tablet data. |
| 555 | */ |
| 556 | static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features) |
| 557 | { |
| 558 | if (features->device_type == BTN_TOOL_FINGER) { |
| 559 | if (features->type > TABLETPC) { |
| 560 | /* MT Tablet PC touch */ |
| 561 | return wacom_set_device_mode(intf, 3, 4, 4); |
| 562 | } |
Jason Gerecke | 36d3c51 | 2013-09-20 09:47:35 -0700 | [diff] [blame] | 563 | else if (features->type == WACOM_24HDT || features->type == CINTIQ_HYBRID) { |
Jason Gerecke | b1e4279 | 2012-10-21 00:38:04 -0700 | [diff] [blame] | 564 | return wacom_set_device_mode(intf, 18, 3, 2); |
| 565 | } |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 566 | } else if (features->device_type == BTN_TOOL_PEN) { |
| 567 | if (features->type <= BAMBOO_PT && features->type != WIRELESS) { |
| 568 | return wacom_set_device_mode(intf, 2, 2, 2); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 575 | static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 576 | struct wacom_features *features) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 577 | { |
| 578 | int error = 0; |
| 579 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 580 | struct hid_descriptor *hid_desc; |
| 581 | |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 582 | /* default features */ |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 583 | features->device_type = BTN_TOOL_PEN; |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 584 | features->x_fuzz = 4; |
| 585 | features->y_fuzz = 4; |
| 586 | features->pressure_fuzz = 0; |
| 587 | features->distance_fuzz = 0; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 588 | |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 589 | /* |
| 590 | * The wireless device HID is basic and layout conflicts with |
| 591 | * other tablets (monitor and touch interface can look like pen). |
| 592 | * Skip the query for this type and modify defaults based on |
| 593 | * interface number. |
| 594 | */ |
| 595 | if (features->type == WIRELESS) { |
| 596 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) { |
| 597 | features->device_type = 0; |
| 598 | } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) { |
Ping Cheng | adad004 | 2012-06-28 16:48:17 -0700 | [diff] [blame] | 599 | features->device_type = BTN_TOOL_FINGER; |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 600 | features->pktlen = WACOM_PKGLEN_BBTOUCH3; |
| 601 | } |
| 602 | } |
| 603 | |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 604 | /* only devices that support touch need to retrieve the info */ |
Ping Cheng | ea2e602 | 2012-06-12 00:14:12 -0700 | [diff] [blame] | 605 | if (features->type < BAMBOO_PT) { |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 606 | goto out; |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 607 | } |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 608 | |
Dmitry Torokhov | a882c93 | 2012-05-02 00:13:38 -0700 | [diff] [blame] | 609 | error = usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc); |
| 610 | if (error) { |
| 611 | error = usb_get_extra_descriptor(&interface->endpoint[0], |
| 612 | HID_DEVICET_REPORT, &hid_desc); |
| 613 | if (error) { |
Dmitry Torokhov | eb71d1b | 2012-05-02 00:13:38 -0700 | [diff] [blame] | 614 | dev_err(&intf->dev, |
| 615 | "can not retrieve extra class descriptor\n"); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 616 | goto out; |
| 617 | } |
| 618 | } |
| 619 | error = wacom_parse_hid(intf, hid_desc, features); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 620 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 621 | out: |
| 622 | return error; |
| 623 | } |
| 624 | |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 625 | struct wacom_usbdev_data { |
| 626 | struct list_head list; |
| 627 | struct kref kref; |
| 628 | struct usb_device *dev; |
| 629 | struct wacom_shared shared; |
| 630 | }; |
| 631 | |
| 632 | static LIST_HEAD(wacom_udev_list); |
| 633 | static DEFINE_MUTEX(wacom_udev_list_lock); |
| 634 | |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 635 | static struct usb_device *wacom_get_sibling(struct usb_device *dev, int vendor, int product) |
| 636 | { |
| 637 | int port1; |
| 638 | struct usb_device *sibling; |
| 639 | |
| 640 | if (vendor == 0 && product == 0) |
| 641 | return dev; |
| 642 | |
| 643 | if (dev->parent == NULL) |
| 644 | return NULL; |
| 645 | |
| 646 | usb_hub_for_each_child(dev->parent, port1, sibling) { |
| 647 | struct usb_device_descriptor *d; |
| 648 | if (sibling == NULL) |
| 649 | continue; |
| 650 | |
| 651 | d = &sibling->descriptor; |
| 652 | if (d->idVendor == vendor && d->idProduct == product) |
| 653 | return sibling; |
| 654 | } |
| 655 | |
| 656 | return NULL; |
| 657 | } |
| 658 | |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 659 | static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev) |
| 660 | { |
| 661 | struct wacom_usbdev_data *data; |
| 662 | |
| 663 | list_for_each_entry(data, &wacom_udev_list, list) { |
| 664 | if (data->dev == dev) { |
| 665 | kref_get(&data->kref); |
| 666 | return data; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | return NULL; |
| 671 | } |
| 672 | |
| 673 | static int wacom_add_shared_data(struct wacom_wac *wacom, |
| 674 | struct usb_device *dev) |
| 675 | { |
| 676 | struct wacom_usbdev_data *data; |
| 677 | int retval = 0; |
| 678 | |
| 679 | mutex_lock(&wacom_udev_list_lock); |
| 680 | |
| 681 | data = wacom_get_usbdev_data(dev); |
| 682 | if (!data) { |
| 683 | data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL); |
| 684 | if (!data) { |
| 685 | retval = -ENOMEM; |
| 686 | goto out; |
| 687 | } |
| 688 | |
| 689 | kref_init(&data->kref); |
| 690 | data->dev = dev; |
| 691 | list_add_tail(&data->list, &wacom_udev_list); |
| 692 | } |
| 693 | |
| 694 | wacom->shared = &data->shared; |
| 695 | |
| 696 | out: |
| 697 | mutex_unlock(&wacom_udev_list_lock); |
| 698 | return retval; |
| 699 | } |
| 700 | |
| 701 | static void wacom_release_shared_data(struct kref *kref) |
| 702 | { |
| 703 | struct wacom_usbdev_data *data = |
| 704 | container_of(kref, struct wacom_usbdev_data, kref); |
| 705 | |
| 706 | mutex_lock(&wacom_udev_list_lock); |
| 707 | list_del(&data->list); |
| 708 | mutex_unlock(&wacom_udev_list_lock); |
| 709 | |
| 710 | kfree(data); |
| 711 | } |
| 712 | |
| 713 | static void wacom_remove_shared_data(struct wacom_wac *wacom) |
| 714 | { |
| 715 | struct wacom_usbdev_data *data; |
| 716 | |
| 717 | if (wacom->shared) { |
| 718 | data = container_of(wacom->shared, struct wacom_usbdev_data, shared); |
| 719 | kref_put(&data->kref, wacom_release_shared_data); |
| 720 | wacom->shared = NULL; |
| 721 | } |
| 722 | } |
| 723 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 724 | static int wacom_led_control(struct wacom *wacom) |
| 725 | { |
| 726 | unsigned char *buf; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 727 | int retval; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 728 | |
| 729 | buf = kzalloc(9, GFP_KERNEL); |
| 730 | if (!buf) |
| 731 | return -ENOMEM; |
| 732 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 733 | if (wacom->wacom_wac.features.type >= INTUOS5S && |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 734 | wacom->wacom_wac.features.type <= INTUOSPL) { |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 735 | /* |
| 736 | * Touch Ring and crop mark LED luminance may take on |
| 737 | * one of four values: |
| 738 | * 0 = Low; 1 = Medium; 2 = High; 3 = Off |
| 739 | */ |
| 740 | int ring_led = wacom->led.select[0] & 0x03; |
| 741 | int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03; |
| 742 | int crop_lum = 0; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 743 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 744 | buf[0] = WAC_CMD_LED_CONTROL; |
| 745 | buf[1] = (crop_lum << 4) | (ring_lum << 2) | (ring_led); |
| 746 | } |
| 747 | else { |
| 748 | int led = wacom->led.select[0] | 0x4; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 749 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 750 | if (wacom->wacom_wac.features.type == WACOM_21UX2 || |
| 751 | wacom->wacom_wac.features.type == WACOM_24HD) |
| 752 | led |= (wacom->led.select[1] << 4) | 0x40; |
| 753 | |
| 754 | buf[0] = WAC_CMD_LED_CONTROL; |
| 755 | buf[1] = led; |
| 756 | buf[2] = wacom->led.llv; |
| 757 | buf[3] = wacom->led.hlv; |
| 758 | buf[4] = wacom->led.img_lum; |
| 759 | } |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 760 | |
| 761 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL, |
| 762 | buf, 9, WAC_CMD_RETRIES); |
| 763 | kfree(buf); |
| 764 | |
| 765 | return retval; |
| 766 | } |
| 767 | |
| 768 | static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img) |
| 769 | { |
| 770 | unsigned char *buf; |
| 771 | int i, retval; |
| 772 | |
| 773 | buf = kzalloc(259, GFP_KERNEL); |
| 774 | if (!buf) |
| 775 | return -ENOMEM; |
| 776 | |
| 777 | /* Send 'start' command */ |
| 778 | buf[0] = WAC_CMD_ICON_START; |
| 779 | buf[1] = 1; |
| 780 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START, |
| 781 | buf, 2, WAC_CMD_RETRIES); |
| 782 | if (retval < 0) |
| 783 | goto out; |
| 784 | |
| 785 | buf[0] = WAC_CMD_ICON_XFER; |
| 786 | buf[1] = button_id & 0x07; |
| 787 | for (i = 0; i < 4; i++) { |
| 788 | buf[2] = i; |
| 789 | memcpy(buf + 3, img + i * 256, 256); |
| 790 | |
| 791 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER, |
| 792 | buf, 259, WAC_CMD_RETRIES); |
| 793 | if (retval < 0) |
| 794 | break; |
| 795 | } |
| 796 | |
| 797 | /* Send 'stop' */ |
| 798 | buf[0] = WAC_CMD_ICON_START; |
| 799 | buf[1] = 0; |
| 800 | wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START, |
| 801 | buf, 2, WAC_CMD_RETRIES); |
| 802 | |
| 803 | out: |
| 804 | kfree(buf); |
| 805 | return retval; |
| 806 | } |
| 807 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 808 | 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] | 809 | const char *buf, size_t count) |
| 810 | { |
| 811 | struct wacom *wacom = dev_get_drvdata(dev); |
| 812 | unsigned int id; |
| 813 | int err; |
| 814 | |
| 815 | err = kstrtouint(buf, 10, &id); |
| 816 | if (err) |
| 817 | return err; |
| 818 | |
| 819 | mutex_lock(&wacom->lock); |
| 820 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 821 | wacom->led.select[set_id] = id & 0x3; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 822 | err = wacom_led_control(wacom); |
| 823 | |
| 824 | mutex_unlock(&wacom->lock); |
| 825 | |
| 826 | return err < 0 ? err : count; |
| 827 | } |
| 828 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 829 | #define DEVICE_LED_SELECT_ATTR(SET_ID) \ |
| 830 | static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \ |
| 831 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 832 | { \ |
| 833 | return wacom_led_select_store(dev, SET_ID, buf, count); \ |
| 834 | } \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 835 | static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ |
| 836 | struct device_attribute *attr, char *buf) \ |
| 837 | { \ |
| 838 | struct wacom *wacom = dev_get_drvdata(dev); \ |
| 839 | return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \ |
| 840 | } \ |
| 841 | static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \ |
| 842 | wacom_led##SET_ID##_select_show, \ |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 843 | wacom_led##SET_ID##_select_store) |
| 844 | |
| 845 | DEVICE_LED_SELECT_ATTR(0); |
| 846 | DEVICE_LED_SELECT_ATTR(1); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 847 | |
| 848 | static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, |
| 849 | const char *buf, size_t count) |
| 850 | { |
| 851 | unsigned int value; |
| 852 | int err; |
| 853 | |
| 854 | err = kstrtouint(buf, 10, &value); |
| 855 | if (err) |
| 856 | return err; |
| 857 | |
| 858 | mutex_lock(&wacom->lock); |
| 859 | |
| 860 | *dest = value & 0x7f; |
| 861 | err = wacom_led_control(wacom); |
| 862 | |
| 863 | mutex_unlock(&wacom->lock); |
| 864 | |
| 865 | return err < 0 ? err : count; |
| 866 | } |
| 867 | |
| 868 | #define DEVICE_LUMINANCE_ATTR(name, field) \ |
| 869 | static ssize_t wacom_##name##_luminance_store(struct device *dev, \ |
| 870 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 871 | { \ |
| 872 | struct wacom *wacom = dev_get_drvdata(dev); \ |
| 873 | \ |
| 874 | return wacom_luminance_store(wacom, &wacom->led.field, \ |
| 875 | buf, count); \ |
| 876 | } \ |
| 877 | static DEVICE_ATTR(name##_luminance, S_IWUSR, \ |
| 878 | NULL, wacom_##name##_luminance_store) |
| 879 | |
| 880 | DEVICE_LUMINANCE_ATTR(status0, llv); |
| 881 | DEVICE_LUMINANCE_ATTR(status1, hlv); |
| 882 | DEVICE_LUMINANCE_ATTR(buttons, img_lum); |
| 883 | |
| 884 | static ssize_t wacom_button_image_store(struct device *dev, int button_id, |
| 885 | const char *buf, size_t count) |
| 886 | { |
| 887 | struct wacom *wacom = dev_get_drvdata(dev); |
| 888 | int err; |
| 889 | |
| 890 | if (count != 1024) |
| 891 | return -EINVAL; |
| 892 | |
| 893 | mutex_lock(&wacom->lock); |
| 894 | |
| 895 | err = wacom_led_putimage(wacom, button_id, buf); |
| 896 | |
| 897 | mutex_unlock(&wacom->lock); |
| 898 | |
| 899 | return err < 0 ? err : count; |
| 900 | } |
| 901 | |
| 902 | #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \ |
| 903 | static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \ |
| 904 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 905 | { \ |
| 906 | return wacom_button_image_store(dev, BUTTON_ID, buf, count); \ |
| 907 | } \ |
| 908 | static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \ |
| 909 | NULL, wacom_btnimg##BUTTON_ID##_store) |
| 910 | |
| 911 | DEVICE_BTNIMG_ATTR(0); |
| 912 | DEVICE_BTNIMG_ATTR(1); |
| 913 | DEVICE_BTNIMG_ATTR(2); |
| 914 | DEVICE_BTNIMG_ATTR(3); |
| 915 | DEVICE_BTNIMG_ATTR(4); |
| 916 | DEVICE_BTNIMG_ATTR(5); |
| 917 | DEVICE_BTNIMG_ATTR(6); |
| 918 | DEVICE_BTNIMG_ATTR(7); |
| 919 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 920 | static struct attribute *cintiq_led_attrs[] = { |
| 921 | &dev_attr_status_led0_select.attr, |
| 922 | &dev_attr_status_led1_select.attr, |
| 923 | NULL |
| 924 | }; |
| 925 | |
| 926 | static struct attribute_group cintiq_led_attr_group = { |
| 927 | .name = "wacom_led", |
| 928 | .attrs = cintiq_led_attrs, |
| 929 | }; |
| 930 | |
| 931 | static struct attribute *intuos4_led_attrs[] = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 932 | &dev_attr_status0_luminance.attr, |
| 933 | &dev_attr_status1_luminance.attr, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 934 | &dev_attr_status_led0_select.attr, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 935 | &dev_attr_buttons_luminance.attr, |
| 936 | &dev_attr_button0_rawimg.attr, |
| 937 | &dev_attr_button1_rawimg.attr, |
| 938 | &dev_attr_button2_rawimg.attr, |
| 939 | &dev_attr_button3_rawimg.attr, |
| 940 | &dev_attr_button4_rawimg.attr, |
| 941 | &dev_attr_button5_rawimg.attr, |
| 942 | &dev_attr_button6_rawimg.attr, |
| 943 | &dev_attr_button7_rawimg.attr, |
| 944 | NULL |
| 945 | }; |
| 946 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 947 | static struct attribute_group intuos4_led_attr_group = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 948 | .name = "wacom_led", |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 949 | .attrs = intuos4_led_attrs, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 950 | }; |
| 951 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 952 | static struct attribute *intuos5_led_attrs[] = { |
| 953 | &dev_attr_status0_luminance.attr, |
| 954 | &dev_attr_status_led0_select.attr, |
| 955 | NULL |
| 956 | }; |
| 957 | |
| 958 | static struct attribute_group intuos5_led_attr_group = { |
| 959 | .name = "wacom_led", |
| 960 | .attrs = intuos5_led_attrs, |
| 961 | }; |
| 962 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 963 | static int wacom_initialize_leds(struct wacom *wacom) |
| 964 | { |
| 965 | int error; |
| 966 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 967 | /* Initialize default values */ |
| 968 | switch (wacom->wacom_wac.features.type) { |
Jason Gerecke | a19fc98 | 2012-06-12 00:27:53 -0700 | [diff] [blame] | 969 | case INTUOS4S: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 970 | case INTUOS4: |
| 971 | case INTUOS4L: |
| 972 | wacom->led.select[0] = 0; |
| 973 | wacom->led.select[1] = 0; |
Ping Cheng | f4fa9a6 | 2011-10-04 23:49:42 -0700 | [diff] [blame] | 974 | wacom->led.llv = 10; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 975 | wacom->led.hlv = 20; |
| 976 | wacom->led.img_lum = 10; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 977 | error = sysfs_create_group(&wacom->intf->dev.kobj, |
| 978 | &intuos4_led_attr_group); |
| 979 | break; |
| 980 | |
Jason Gerecke | 246835f | 2011-12-12 00:12:04 -0800 | [diff] [blame] | 981 | case WACOM_24HD: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 982 | case WACOM_21UX2: |
| 983 | wacom->led.select[0] = 0; |
| 984 | wacom->led.select[1] = 0; |
| 985 | wacom->led.llv = 0; |
| 986 | wacom->led.hlv = 0; |
| 987 | wacom->led.img_lum = 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 988 | |
| 989 | error = sysfs_create_group(&wacom->intf->dev.kobj, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 990 | &cintiq_led_attr_group); |
| 991 | break; |
| 992 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 993 | case INTUOS5S: |
| 994 | case INTUOS5: |
| 995 | case INTUOS5L: |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 996 | case INTUOSPS: |
| 997 | case INTUOSPM: |
| 998 | case INTUOSPL: |
Ping Cheng | c2b0c27 | 2013-09-20 09:50:14 -0700 | [diff] [blame] | 999 | if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) { |
| 1000 | wacom->led.select[0] = 0; |
| 1001 | wacom->led.select[1] = 0; |
| 1002 | wacom->led.llv = 32; |
| 1003 | wacom->led.hlv = 0; |
| 1004 | wacom->led.img_lum = 0; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1005 | |
Ping Cheng | c2b0c27 | 2013-09-20 09:50:14 -0700 | [diff] [blame] | 1006 | error = sysfs_create_group(&wacom->intf->dev.kobj, |
| 1007 | &intuos5_led_attr_group); |
| 1008 | } else |
| 1009 | return 0; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1010 | break; |
| 1011 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1012 | default: |
| 1013 | return 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1016 | if (error) { |
| 1017 | dev_err(&wacom->intf->dev, |
| 1018 | "cannot create sysfs group err: %d\n", error); |
| 1019 | return error; |
| 1020 | } |
| 1021 | wacom_led_control(wacom); |
| 1022 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | static void wacom_destroy_leds(struct wacom *wacom) |
| 1027 | { |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1028 | switch (wacom->wacom_wac.features.type) { |
Jason Gerecke | a19fc98 | 2012-06-12 00:27:53 -0700 | [diff] [blame] | 1029 | case INTUOS4S: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1030 | case INTUOS4: |
| 1031 | case INTUOS4L: |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1032 | sysfs_remove_group(&wacom->intf->dev.kobj, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1033 | &intuos4_led_attr_group); |
| 1034 | break; |
| 1035 | |
Jason Gerecke | 246835f | 2011-12-12 00:12:04 -0800 | [diff] [blame] | 1036 | case WACOM_24HD: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1037 | case WACOM_21UX2: |
| 1038 | sysfs_remove_group(&wacom->intf->dev.kobj, |
| 1039 | &cintiq_led_attr_group); |
| 1040 | break; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1041 | |
| 1042 | case INTUOS5S: |
| 1043 | case INTUOS5: |
| 1044 | case INTUOS5L: |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 1045 | case INTUOSPS: |
| 1046 | case INTUOSPM: |
| 1047 | case INTUOSPL: |
Ping Cheng | c2b0c27 | 2013-09-20 09:50:14 -0700 | [diff] [blame] | 1048 | if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) |
| 1049 | sysfs_remove_group(&wacom->intf->dev.kobj, |
| 1050 | &intuos5_led_attr_group); |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1051 | break; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1055 | static enum power_supply_property wacom_battery_props[] = { |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 1056 | POWER_SUPPLY_PROP_SCOPE, |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1057 | POWER_SUPPLY_PROP_CAPACITY |
| 1058 | }; |
| 1059 | |
| 1060 | static int wacom_battery_get_property(struct power_supply *psy, |
| 1061 | enum power_supply_property psp, |
| 1062 | union power_supply_propval *val) |
| 1063 | { |
| 1064 | struct wacom *wacom = container_of(psy, struct wacom, battery); |
| 1065 | int ret = 0; |
| 1066 | |
| 1067 | switch (psp) { |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 1068 | case POWER_SUPPLY_PROP_SCOPE: |
| 1069 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 1070 | break; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1071 | case POWER_SUPPLY_PROP_CAPACITY: |
| 1072 | val->intval = |
| 1073 | wacom->wacom_wac.battery_capacity * 100 / 31; |
| 1074 | break; |
| 1075 | default: |
| 1076 | ret = -EINVAL; |
| 1077 | break; |
| 1078 | } |
| 1079 | |
| 1080 | return ret; |
| 1081 | } |
| 1082 | |
| 1083 | static int wacom_initialize_battery(struct wacom *wacom) |
| 1084 | { |
| 1085 | int error = 0; |
| 1086 | |
| 1087 | if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) { |
| 1088 | wacom->battery.properties = wacom_battery_props; |
| 1089 | wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props); |
| 1090 | wacom->battery.get_property = wacom_battery_get_property; |
| 1091 | wacom->battery.name = "wacom_battery"; |
| 1092 | wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY; |
| 1093 | wacom->battery.use_for_apm = 0; |
| 1094 | |
| 1095 | error = power_supply_register(&wacom->usbdev->dev, |
| 1096 | &wacom->battery); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1097 | |
| 1098 | if (!error) |
| 1099 | power_supply_powers(&wacom->battery, |
| 1100 | &wacom->usbdev->dev); |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | return error; |
| 1104 | } |
| 1105 | |
| 1106 | static void wacom_destroy_battery(struct wacom *wacom) |
| 1107 | { |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1108 | if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR && |
| 1109 | wacom->battery.dev) { |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1110 | power_supply_unregister(&wacom->battery); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1111 | wacom->battery.dev = NULL; |
| 1112 | } |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1115 | static int wacom_register_input(struct wacom *wacom) |
| 1116 | { |
| 1117 | struct input_dev *input_dev; |
| 1118 | struct usb_interface *intf = wacom->intf; |
| 1119 | struct usb_device *dev = interface_to_usbdev(intf); |
| 1120 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
| 1121 | int error; |
| 1122 | |
| 1123 | input_dev = input_allocate_device(); |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1124 | if (!input_dev) { |
| 1125 | error = -ENOMEM; |
| 1126 | goto fail1; |
| 1127 | } |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1128 | |
| 1129 | input_dev->name = wacom_wac->name; |
Benjamin Tissoires | 7097d4c | 2014-07-24 12:48:06 -0700 | [diff] [blame^] | 1130 | input_dev->phys = wacom->phys; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1131 | input_dev->dev.parent = &intf->dev; |
| 1132 | input_dev->open = wacom_open; |
| 1133 | input_dev->close = wacom_close; |
| 1134 | usb_to_input_id(dev, &input_dev->id); |
| 1135 | input_set_drvdata(input_dev, wacom); |
| 1136 | |
| 1137 | wacom_wac->input = input_dev; |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1138 | error = wacom_setup_input_capabilities(input_dev, wacom_wac); |
| 1139 | if (error) |
| 1140 | goto fail1; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1141 | |
| 1142 | error = input_register_device(input_dev); |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1143 | if (error) |
| 1144 | goto fail2; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1145 | |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1146 | return 0; |
| 1147 | |
| 1148 | fail2: |
| 1149 | input_free_device(input_dev); |
| 1150 | wacom_wac->input = NULL; |
| 1151 | fail1: |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1152 | return error; |
| 1153 | } |
| 1154 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1155 | static void wacom_wireless_work(struct work_struct *work) |
| 1156 | { |
| 1157 | struct wacom *wacom = container_of(work, struct wacom, work); |
| 1158 | struct usb_device *usbdev = wacom->usbdev; |
| 1159 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1160 | struct wacom *wacom1, *wacom2; |
| 1161 | struct wacom_wac *wacom_wac1, *wacom_wac2; |
| 1162 | int error; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1163 | |
| 1164 | /* |
| 1165 | * Regardless if this is a disconnect or a new tablet, |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1166 | * remove any existing input and battery devices. |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1167 | */ |
| 1168 | |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1169 | wacom_destroy_battery(wacom); |
| 1170 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1171 | /* Stylus interface */ |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1172 | wacom1 = usb_get_intfdata(usbdev->config->interface[1]); |
| 1173 | wacom_wac1 = &(wacom1->wacom_wac); |
| 1174 | if (wacom_wac1->input) |
| 1175 | input_unregister_device(wacom_wac1->input); |
| 1176 | wacom_wac1->input = NULL; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1177 | |
| 1178 | /* Touch interface */ |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1179 | wacom2 = usb_get_intfdata(usbdev->config->interface[2]); |
| 1180 | wacom_wac2 = &(wacom2->wacom_wac); |
| 1181 | if (wacom_wac2->input) |
| 1182 | input_unregister_device(wacom_wac2->input); |
| 1183 | wacom_wac2->input = NULL; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1184 | |
| 1185 | if (wacom_wac->pid == 0) { |
Dmitry Torokhov | eb71d1b | 2012-05-02 00:13:38 -0700 | [diff] [blame] | 1186 | dev_info(&wacom->intf->dev, "wireless tablet disconnected\n"); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1187 | } else { |
| 1188 | const struct usb_device_id *id = wacom_ids; |
| 1189 | |
Dmitry Torokhov | eb71d1b | 2012-05-02 00:13:38 -0700 | [diff] [blame] | 1190 | dev_info(&wacom->intf->dev, |
| 1191 | "wireless tablet connected with PID %x\n", |
| 1192 | wacom_wac->pid); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1193 | |
| 1194 | while (id->match_flags) { |
| 1195 | if (id->idVendor == USB_VENDOR_ID_WACOM && |
| 1196 | id->idProduct == wacom_wac->pid) |
| 1197 | break; |
| 1198 | id++; |
| 1199 | } |
| 1200 | |
| 1201 | if (!id->match_flags) { |
Dmitry Torokhov | eb71d1b | 2012-05-02 00:13:38 -0700 | [diff] [blame] | 1202 | dev_info(&wacom->intf->dev, |
| 1203 | "ignoring unknown PID.\n"); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1204 | return; |
| 1205 | } |
| 1206 | |
| 1207 | /* Stylus interface */ |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1208 | wacom_wac1->features = |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1209 | *((struct wacom_features *)id->driver_info); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1210 | wacom_wac1->features.device_type = BTN_TOOL_PEN; |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1211 | snprintf(wacom_wac1->name, WACOM_NAME_MAX, "%s (WL) Pen", |
| 1212 | wacom_wac1->features.name); |
Ping Cheng | 961794a | 2013-12-05 12:54:53 -0800 | [diff] [blame] | 1213 | wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max; |
| 1214 | wacom_wac1->shared->type = wacom_wac1->features.type; |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1215 | error = wacom_register_input(wacom1); |
| 1216 | if (error) |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1217 | goto fail; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1218 | |
| 1219 | /* Touch interface */ |
Ping Cheng | b5fd2a3 | 2013-11-25 18:44:55 -0800 | [diff] [blame] | 1220 | if (wacom_wac1->features.touch_max || |
| 1221 | wacom_wac1->features.type == INTUOSHT) { |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1222 | wacom_wac2->features = |
| 1223 | *((struct wacom_features *)id->driver_info); |
| 1224 | wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3; |
| 1225 | wacom_wac2->features.device_type = BTN_TOOL_FINGER; |
| 1226 | wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096; |
| 1227 | if (wacom_wac2->features.touch_max) |
| 1228 | snprintf(wacom_wac2->name, WACOM_NAME_MAX, |
| 1229 | "%s (WL) Finger",wacom_wac2->features.name); |
| 1230 | else |
| 1231 | snprintf(wacom_wac2->name, WACOM_NAME_MAX, |
| 1232 | "%s (WL) Pad",wacom_wac2->features.name); |
| 1233 | error = wacom_register_input(wacom2); |
| 1234 | if (error) |
| 1235 | goto fail; |
Ping Cheng | 961794a | 2013-12-05 12:54:53 -0800 | [diff] [blame] | 1236 | |
| 1237 | if (wacom_wac1->features.type == INTUOSHT && |
| 1238 | wacom_wac1->features.touch_max) |
| 1239 | wacom_wac->shared->touch_input = wacom_wac2->input; |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1240 | } |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1241 | |
| 1242 | error = wacom_initialize_battery(wacom); |
| 1243 | if (error) |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1244 | goto fail; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1245 | } |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1246 | |
| 1247 | return; |
| 1248 | |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1249 | fail: |
| 1250 | if (wacom_wac2->input) { |
| 1251 | input_unregister_device(wacom_wac2->input); |
| 1252 | wacom_wac2->input = NULL; |
| 1253 | } |
| 1254 | |
| 1255 | if (wacom_wac1->input) { |
| 1256 | input_unregister_device(wacom_wac1->input); |
| 1257 | wacom_wac1->input = NULL; |
| 1258 | } |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1259 | return; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1262 | /* |
| 1263 | * Not all devices report physical dimensions from HID. |
| 1264 | * Compute the default from hardcoded logical dimension |
| 1265 | * and resolution before driver overwrites them. |
| 1266 | */ |
| 1267 | static void wacom_set_default_phy(struct wacom_features *features) |
| 1268 | { |
| 1269 | if (features->x_resolution) { |
| 1270 | features->x_phy = (features->x_max * 100) / |
| 1271 | features->x_resolution; |
| 1272 | features->y_phy = (features->y_max * 100) / |
| 1273 | features->y_resolution; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | static void wacom_calculate_res(struct wacom_features *features) |
| 1278 | { |
| 1279 | features->x_resolution = wacom_calc_hid_res(features->x_max, |
| 1280 | features->x_phy, |
| 1281 | features->unit, |
| 1282 | features->unitExpo); |
| 1283 | features->y_resolution = wacom_calc_hid_res(features->y_max, |
| 1284 | features->y_phy, |
| 1285 | features->unit, |
| 1286 | features->unitExpo); |
| 1287 | } |
| 1288 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1289 | static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 1290 | { |
| 1291 | struct usb_device *dev = interface_to_usbdev(intf); |
| 1292 | struct usb_endpoint_descriptor *endpoint; |
| 1293 | struct wacom *wacom; |
| 1294 | struct wacom_wac *wacom_wac; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1295 | struct wacom_features *features; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1296 | int error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1297 | |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1298 | if (!id->driver_info) |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 1299 | return -EINVAL; |
| 1300 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1301 | wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); |
Dan Carpenter | f182394 | 2012-03-29 22:38:11 -0700 | [diff] [blame] | 1302 | if (!wacom) |
| 1303 | return -ENOMEM; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1304 | |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1305 | wacom_wac = &wacom->wacom_wac; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1306 | wacom_wac->features = *((struct wacom_features *)id->driver_info); |
| 1307 | features = &wacom_wac->features; |
| 1308 | if (features->pktlen > WACOM_PKGLEN_MAX) { |
| 1309 | error = -EINVAL; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1310 | goto fail1; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1313 | wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX, |
| 1314 | GFP_KERNEL, &wacom->data_dma); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1315 | if (!wacom_wac->data) { |
| 1316 | error = -ENOMEM; |
| 1317 | goto fail1; |
| 1318 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1319 | |
| 1320 | wacom->irq = usb_alloc_urb(0, GFP_KERNEL); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1321 | if (!wacom->irq) { |
| 1322 | error = -ENOMEM; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1323 | goto fail2; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1324 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1325 | |
| 1326 | wacom->usbdev = dev; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1327 | wacom->intf = intf; |
| 1328 | mutex_init(&wacom->lock); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1329 | INIT_WORK(&wacom->work, wacom_wireless_work); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1330 | usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); |
| 1331 | strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); |
| 1332 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 1333 | endpoint = &intf->cur_altsetting->endpoint[0].desc; |
| 1334 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1335 | /* set the default size in case we do not get them from hid */ |
| 1336 | wacom_set_default_phy(features); |
| 1337 | |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 1338 | /* Retrieve the physical and logical size for touch devices */ |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 1339 | error = wacom_retrieve_hid_descriptor(intf, features); |
| 1340 | if (error) |
Alexander Strakh | 4b6d443 | 2011-02-11 00:44:41 -0800 | [diff] [blame] | 1341 | goto fail3; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 1342 | |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 1343 | /* |
| 1344 | * Intuos5 has no useful data about its touch interface in its |
| 1345 | * HID descriptor. If this is the touch interface (wMaxPacketSize |
| 1346 | * of WACOM_PKGLEN_BBTOUCH3), override the table values. |
| 1347 | */ |
Ping Cheng | b5fd2a3 | 2013-11-25 18:44:55 -0800 | [diff] [blame] | 1348 | if (features->type >= INTUOS5S && features->type <= INTUOSHT) { |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 1349 | if (endpoint->wMaxPacketSize == WACOM_PKGLEN_BBTOUCH3) { |
| 1350 | features->device_type = BTN_TOOL_FINGER; |
| 1351 | features->pktlen = WACOM_PKGLEN_BBTOUCH3; |
| 1352 | |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 1353 | features->x_max = 4096; |
| 1354 | features->y_max = 4096; |
| 1355 | } else { |
| 1356 | features->device_type = BTN_TOOL_PEN; |
| 1357 | } |
| 1358 | } |
| 1359 | |
Henrik Rydberg | bc73dd3 | 2010-09-05 12:26:16 -0700 | [diff] [blame] | 1360 | wacom_setup_device_quirks(features); |
| 1361 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1362 | /* set unit to "100th of a mm" for devices not reported by HID */ |
| 1363 | if (!features->unit) { |
| 1364 | features->unit = 0x11; |
| 1365 | features->unitExpo = 16 - 3; |
| 1366 | } |
| 1367 | wacom_calculate_res(features); |
| 1368 | |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 1369 | strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); |
| 1370 | |
Henrik Rydberg | bc73dd3 | 2010-09-05 12:26:16 -0700 | [diff] [blame] | 1371 | if (features->quirks & WACOM_QUIRK_MULTI_INPUT) { |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 1372 | struct usb_device *other_dev; |
| 1373 | |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 1374 | /* Append the device type to the name */ |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1375 | if (features->device_type != BTN_TOOL_FINGER) |
| 1376 | strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX); |
| 1377 | else if (features->touch_max) |
| 1378 | strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX); |
| 1379 | else |
| 1380 | strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1381 | |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 1382 | other_dev = wacom_get_sibling(dev, features->oVid, features->oPid); |
| 1383 | if (other_dev == NULL || wacom_get_usbdev_data(other_dev) == NULL) |
| 1384 | other_dev = dev; |
| 1385 | error = wacom_add_shared_data(wacom_wac, other_dev); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1386 | if (error) |
| 1387 | goto fail3; |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 1388 | } |
| 1389 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1390 | usb_fill_int_urb(wacom->irq, dev, |
| 1391 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 1392 | wacom_wac->data, features->pktlen, |
Ping Cheng | 8d32e3a | 2006-09-26 13:34:47 -0700 | [diff] [blame] | 1393 | wacom_sys_irq, wacom, endpoint->bInterval); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1394 | wacom->irq->transfer_dma = wacom->data_dma; |
| 1395 | wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 1396 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1397 | error = wacom_initialize_leds(wacom); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 1398 | if (error) |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1399 | goto fail4; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1400 | |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1401 | if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { |
| 1402 | error = wacom_register_input(wacom); |
| 1403 | if (error) |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1404 | goto fail5; |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1405 | } |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1406 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 1407 | /* Note that if query fails it is not a hard failure */ |
| 1408 | wacom_query_tablet_data(intf, features); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1409 | |
| 1410 | usb_set_intfdata(intf, wacom); |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1411 | |
| 1412 | if (features->quirks & WACOM_QUIRK_MONITOR) { |
Wei Yongjun | d4879c9 | 2013-08-24 16:41:56 -0700 | [diff] [blame] | 1413 | if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { |
| 1414 | error = -EIO; |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1415 | goto fail5; |
Wei Yongjun | d4879c9 | 2013-08-24 16:41:56 -0700 | [diff] [blame] | 1416 | } |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1417 | } |
Ping Cheng | 961794a | 2013-12-05 12:54:53 -0800 | [diff] [blame] | 1418 | |
| 1419 | if (wacom_wac->features.type == INTUOSHT && wacom_wac->features.touch_max) { |
| 1420 | if (wacom_wac->features.device_type == BTN_TOOL_FINGER) |
| 1421 | wacom_wac->shared->touch_input = wacom_wac->input; |
| 1422 | } |
| 1423 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1424 | return 0; |
| 1425 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1426 | fail5: wacom_destroy_leds(wacom); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1427 | fail4: wacom_remove_shared_data(wacom_wac); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 1428 | fail3: usb_free_urb(wacom->irq); |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1429 | fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma); |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1430 | fail1: kfree(wacom); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 1431 | return error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | static void wacom_disconnect(struct usb_interface *intf) |
| 1435 | { |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1436 | struct wacom *wacom = usb_get_intfdata(intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1437 | |
| 1438 | usb_set_intfdata(intf, NULL); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1439 | |
| 1440 | usb_kill_urb(wacom->irq); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1441 | cancel_work_sync(&wacom->work); |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1442 | if (wacom->wacom_wac.input) |
| 1443 | input_unregister_device(wacom->wacom_wac.input); |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1444 | wacom_destroy_battery(wacom); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1445 | wacom_destroy_leds(wacom); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1446 | usb_free_urb(wacom->irq); |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1447 | usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX, |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1448 | wacom->wacom_wac.data, wacom->data_dma); |
| 1449 | wacom_remove_shared_data(&wacom->wacom_wac); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1450 | kfree(wacom); |
| 1451 | } |
| 1452 | |
| 1453 | static int wacom_suspend(struct usb_interface *intf, pm_message_t message) |
| 1454 | { |
| 1455 | struct wacom *wacom = usb_get_intfdata(intf); |
| 1456 | |
| 1457 | mutex_lock(&wacom->lock); |
| 1458 | usb_kill_urb(wacom->irq); |
| 1459 | mutex_unlock(&wacom->lock); |
| 1460 | |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | static int wacom_resume(struct usb_interface *intf) |
| 1465 | { |
| 1466 | struct wacom *wacom = usb_get_intfdata(intf); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1467 | struct wacom_features *features = &wacom->wacom_wac.features; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1468 | int rv = 0; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1469 | |
| 1470 | mutex_lock(&wacom->lock); |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 1471 | |
| 1472 | /* switch to wacom mode first */ |
| 1473 | wacom_query_tablet_data(intf, features); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1474 | wacom_led_control(wacom); |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 1475 | |
Wei Yongjun | d4879c9 | 2013-08-24 16:41:56 -0700 | [diff] [blame] | 1476 | if ((wacom->open || (features->quirks & WACOM_QUIRK_MONITOR)) && |
| 1477 | usb_submit_urb(wacom->irq, GFP_NOIO) < 0) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1478 | rv = -EIO; |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 1479 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1480 | mutex_unlock(&wacom->lock); |
| 1481 | |
| 1482 | return rv; |
| 1483 | } |
| 1484 | |
| 1485 | static int wacom_reset_resume(struct usb_interface *intf) |
| 1486 | { |
| 1487 | return wacom_resume(intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | static struct usb_driver wacom_driver = { |
| 1491 | .name = "wacom", |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 1492 | .id_table = wacom_ids, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1493 | .probe = wacom_probe, |
| 1494 | .disconnect = wacom_disconnect, |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1495 | .suspend = wacom_suspend, |
| 1496 | .resume = wacom_resume, |
| 1497 | .reset_resume = wacom_reset_resume, |
| 1498 | .supports_autosuspend = 1, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1499 | }; |
| 1500 | |
Greg Kroah-Hartman | 08642e7 | 2011-11-18 09:48:31 -0800 | [diff] [blame] | 1501 | module_usb_driver(wacom_driver); |