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