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