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