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