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