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