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