Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2 | /* |
Dmitry Torokhov | 4104d13 | 2007-05-07 16:16:29 -0400 | [diff] [blame] | 3 | * drivers/input/tablet/wacom_sys.c |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 4 | * |
Ping Cheng | 232f569 | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 5 | * USB Wacom tablet support - system specific code |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 11 | #include "wacom_wac.h" |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 12 | #include "wacom.h" |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 13 | #include <linux/input/mt.h> |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 14 | |
Ping Cheng | a417ea4 | 2011-08-16 00:17:56 -0700 | [diff] [blame] | 15 | #define WAC_MSG_RETRIES 5 |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 16 | #define WAC_CMD_RETRIES 10 |
| 17 | |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 18 | #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP) |
| 19 | #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 20 | #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP) |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 21 | |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 22 | static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf, |
| 23 | size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 24 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 25 | int retval; |
| 26 | |
| 27 | do { |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 28 | retval = hid_hw_raw_request(hdev, buf[0], buf, size, type, |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 29 | HID_REQ_GET_REPORT); |
Jason Gerecke | aef3156 | 2015-05-21 10:44:31 -0700 | [diff] [blame] | 30 | } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries); |
| 31 | |
| 32 | if (retval < 0) |
| 33 | hid_err(hdev, "wacom_get_report: ran out of retries " |
| 34 | "(last error = %d)\n", retval); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 35 | |
| 36 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 39 | static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf, |
| 40 | size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 41 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 42 | int retval; |
| 43 | |
| 44 | do { |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 45 | retval = hid_hw_raw_request(hdev, buf[0], buf, size, type, |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 46 | HID_REQ_SET_REPORT); |
Jason Gerecke | aef3156 | 2015-05-21 10:44:31 -0700 | [diff] [blame] | 47 | } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries); |
| 48 | |
| 49 | if (retval < 0) |
| 50 | hid_err(hdev, "wacom_set_report: ran out of retries " |
| 51 | "(last error = %d)\n", retval); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 52 | |
| 53 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Jason Gerecke | 8341720 | 2017-11-10 11:50:01 -0800 | [diff] [blame] | 56 | static void wacom_wac_queue_insert(struct hid_device *hdev, |
| 57 | struct kfifo_rec_ptr_2 *fifo, |
| 58 | u8 *raw_data, int size) |
| 59 | { |
| 60 | bool warned = false; |
| 61 | |
| 62 | while (kfifo_avail(fifo) < size) { |
| 63 | if (!warned) |
| 64 | hid_warn(hdev, "%s: kfifo has filled, starting to drop events\n", __func__); |
| 65 | warned = true; |
| 66 | |
| 67 | kfifo_skip(fifo); |
| 68 | } |
| 69 | |
| 70 | kfifo_in(fifo, raw_data, size); |
| 71 | } |
| 72 | |
| 73 | static void wacom_wac_queue_flush(struct hid_device *hdev, |
| 74 | struct kfifo_rec_ptr_2 *fifo) |
| 75 | { |
| 76 | while (!kfifo_is_empty(fifo)) { |
| 77 | u8 buf[WACOM_PKGLEN_MAX]; |
| 78 | int size; |
| 79 | int err; |
| 80 | |
| 81 | size = kfifo_out(fifo, buf, sizeof(buf)); |
| 82 | err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, false); |
| 83 | if (err) { |
| 84 | hid_warn(hdev, "%s: unable to flush event due to error %d\n", |
| 85 | __func__, err); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | static int wacom_wac_pen_serial_enforce(struct hid_device *hdev, |
Jason Gerecke | 073b50b | 2019-08-16 11:54:26 -0700 | [diff] [blame] | 91 | struct hid_report *report, u8 *raw_data, int report_size) |
Jason Gerecke | 8341720 | 2017-11-10 11:50:01 -0800 | [diff] [blame] | 92 | { |
| 93 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 94 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 95 | struct wacom_features *features = &wacom_wac->features; |
| 96 | bool flush = false; |
| 97 | bool insert = false; |
| 98 | int i, j; |
| 99 | |
| 100 | if (wacom_wac->serial[0] || !(features->quirks & WACOM_QUIRK_TOOLSERIAL)) |
| 101 | return 0; |
| 102 | |
| 103 | /* Queue events which have invalid tool type or serial number */ |
| 104 | for (i = 0; i < report->maxfield; i++) { |
| 105 | for (j = 0; j < report->field[i]->maxusage; j++) { |
| 106 | struct hid_field *field = report->field[i]; |
| 107 | struct hid_usage *usage = &field->usage[j]; |
| 108 | unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid); |
| 109 | unsigned int offset; |
| 110 | unsigned int size; |
| 111 | unsigned int value; |
| 112 | |
| 113 | if (equivalent_usage != HID_DG_INRANGE && |
| 114 | equivalent_usage != HID_DG_TOOLSERIALNUMBER && |
| 115 | equivalent_usage != WACOM_HID_WD_SERIALHI && |
| 116 | equivalent_usage != WACOM_HID_WD_TOOLTYPE) |
| 117 | continue; |
| 118 | |
| 119 | offset = field->report_offset; |
| 120 | size = field->report_size; |
| 121 | value = hid_field_extract(hdev, raw_data+1, offset + j * size, size); |
| 122 | |
| 123 | /* If we go out of range, we need to flush the queue ASAP */ |
| 124 | if (equivalent_usage == HID_DG_INRANGE) |
| 125 | value = !value; |
| 126 | |
| 127 | if (value) { |
| 128 | flush = true; |
| 129 | switch (equivalent_usage) { |
| 130 | case HID_DG_TOOLSERIALNUMBER: |
| 131 | wacom_wac->serial[0] = value; |
| 132 | break; |
| 133 | |
| 134 | case WACOM_HID_WD_SERIALHI: |
| 135 | wacom_wac->serial[0] |= ((__u64)value) << 32; |
| 136 | break; |
| 137 | |
| 138 | case WACOM_HID_WD_TOOLTYPE: |
| 139 | wacom_wac->id[0] = value; |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | else { |
| 144 | insert = true; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if (flush) |
Jason Gerecke | 179e8e4 | 2021-01-21 10:46:49 -0800 | [diff] [blame] | 150 | wacom_wac_queue_flush(hdev, wacom_wac->pen_fifo); |
Jason Gerecke | 8341720 | 2017-11-10 11:50:01 -0800 | [diff] [blame] | 151 | else if (insert) |
Jason Gerecke | 179e8e4 | 2021-01-21 10:46:49 -0800 | [diff] [blame] | 152 | wacom_wac_queue_insert(hdev, wacom_wac->pen_fifo, |
Jason Gerecke | 073b50b | 2019-08-16 11:54:26 -0700 | [diff] [blame] | 153 | raw_data, report_size); |
Jason Gerecke | 8341720 | 2017-11-10 11:50:01 -0800 | [diff] [blame] | 154 | |
| 155 | return insert && !flush; |
| 156 | } |
| 157 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 158 | static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 159 | u8 *raw_data, int size) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 160 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 161 | struct wacom *wacom = hid_get_drvdata(hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 162 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 163 | if (size > WACOM_PKGLEN_MAX) |
| 164 | return 1; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 165 | |
Jason Gerecke | 8341720 | 2017-11-10 11:50:01 -0800 | [diff] [blame] | 166 | if (wacom_wac_pen_serial_enforce(hdev, report, raw_data, size)) |
| 167 | return -1; |
| 168 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 169 | memcpy(wacom->wacom_wac.data, raw_data, size); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 170 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 171 | wacom_wac_irq(&wacom->wacom_wac, size); |
| 172 | |
| 173 | return 0; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 176 | static int wacom_open(struct input_dev *dev) |
| 177 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 178 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 179 | |
Benjamin Tissoires | dff6741 | 2014-12-01 11:52:40 -0500 | [diff] [blame] | 180 | return hid_hw_open(wacom->hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static void wacom_close(struct input_dev *dev) |
| 184 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 185 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 186 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 187 | /* |
| 188 | * wacom->hdev should never be null, but surprisingly, I had the case |
| 189 | * once while unplugging the Wacom Wireless Receiver. |
| 190 | */ |
| 191 | if (wacom->hdev) |
| 192 | hid_hw_close(wacom->hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 195 | /* |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 196 | * 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] | 197 | */ |
| 198 | static int wacom_calc_hid_res(int logical_extents, int physical_extents, |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 199 | unsigned unit, int exponent) |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 200 | { |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 201 | struct hid_field field = { |
| 202 | .logical_maximum = logical_extents, |
| 203 | .physical_maximum = physical_extents, |
| 204 | .unit = unit, |
| 205 | .unit_exponent = exponent, |
| 206 | }; |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 207 | |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 208 | return hidinput_calc_abs_res(&field, ABS_X); |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Jason Gerecke | 5783251 | 2018-06-25 13:24:35 -0700 | [diff] [blame] | 211 | static void wacom_hid_usage_quirk(struct hid_device *hdev, |
| 212 | struct hid_field *field, struct hid_usage *usage) |
| 213 | { |
| 214 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 215 | struct wacom_features *features = &wacom->wacom_wac.features; |
| 216 | unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid); |
| 217 | |
| 218 | /* |
| 219 | * The Dell Canvas 27 needs to be switched to its vendor-defined |
| 220 | * report to provide the best resolution. |
| 221 | */ |
| 222 | if (hdev->vendor == USB_VENDOR_ID_WACOM && |
| 223 | hdev->product == 0x4200 && |
| 224 | field->application == HID_UP_MSVENDOR) { |
| 225 | wacom->wacom_wac.mode_report = field->report->id; |
| 226 | wacom->wacom_wac.mode_value = 2; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * ISDv4 devices which predate HID's adoption of the |
| 231 | * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its |
| 232 | * position instead. We can accurately detect if a |
| 233 | * usage with that value should be HID_DG_BARRELSWITCH2 |
| 234 | * based on the surrounding usages, which have remained |
| 235 | * constant across generations. |
| 236 | */ |
| 237 | if (features->type == HID_GENERIC && |
| 238 | usage->hid == 0x000D0000 && |
| 239 | field->application == HID_DG_PEN && |
| 240 | field->physical == HID_DG_STYLUS) { |
| 241 | int i = usage->usage_index; |
| 242 | |
| 243 | if (i-4 >= 0 && i+1 < field->maxusage && |
| 244 | field->usage[i-4].hid == HID_DG_TIPSWITCH && |
| 245 | field->usage[i-3].hid == HID_DG_BARRELSWITCH && |
| 246 | field->usage[i-2].hid == HID_DG_ERASER && |
| 247 | field->usage[i-1].hid == HID_DG_INVERT && |
| 248 | field->usage[i+1].hid == HID_DG_INRANGE) { |
| 249 | usage->hid = HID_DG_BARRELSWITCH2; |
| 250 | } |
| 251 | } |
| 252 | |
Jason Gerecke | e9fe0d4 | 2019-01-24 11:09:44 -0800 | [diff] [blame] | 253 | /* |
| 254 | * Wacom's AES devices use different vendor-defined usages to |
| 255 | * report serial number information compared to their branded |
| 256 | * hardware. The usages are also sometimes ill-defined and do |
| 257 | * not have the correct logical min/max values set. Lets patch |
| 258 | * the descriptor to use the branded usage convention and fix |
| 259 | * the errors. |
| 260 | */ |
| 261 | if (usage->hid == WACOM_HID_WT_SERIALNUMBER && |
| 262 | field->report_size == 16 && |
| 263 | field->index + 2 < field->report->maxfield) { |
| 264 | struct hid_field *a = field->report->field[field->index + 1]; |
| 265 | struct hid_field *b = field->report->field[field->index + 2]; |
| 266 | |
| 267 | if (a->maxusage > 0 && |
| 268 | a->usage[0].hid == HID_DG_TOOLSERIALNUMBER && |
| 269 | a->report_size == 32 && |
| 270 | b->maxusage > 0 && |
| 271 | b->usage[0].hid == 0xFF000000 && |
| 272 | b->report_size == 8) { |
| 273 | features->quirks |= WACOM_QUIRK_AESPEN; |
| 274 | usage->hid = WACOM_HID_WD_TOOLTYPE; |
| 275 | field->logical_minimum = S16_MIN; |
| 276 | field->logical_maximum = S16_MAX; |
| 277 | a->logical_minimum = S32_MIN; |
| 278 | a->logical_maximum = S32_MAX; |
| 279 | b->usage[0].hid = WACOM_HID_WD_SERIALHI; |
| 280 | b->logical_minimum = 0; |
| 281 | b->logical_maximum = U8_MAX; |
| 282 | } |
| 283 | } |
| 284 | |
Jason Gerecke | 5783251 | 2018-06-25 13:24:35 -0700 | [diff] [blame] | 285 | /* 2nd-generation Intuos Pro Large has incorrect Y maximum */ |
| 286 | if (hdev->vendor == USB_VENDOR_ID_WACOM && |
| 287 | hdev->product == 0x0358 && |
| 288 | WACOM_PEN_FIELD(field) && |
| 289 | equivalent_usage == HID_GD_Y) { |
| 290 | field->logical_maximum = 43200; |
| 291 | } |
| 292 | } |
| 293 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 294 | static void wacom_feature_mapping(struct hid_device *hdev, |
| 295 | struct hid_field *field, struct hid_usage *usage) |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 296 | { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 297 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 298 | struct wacom_features *features = &wacom->wacom_wac.features; |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 299 | struct hid_data *hid_data = &wacom->wacom_wac.hid_data; |
Aaron Armstrong Skomra | ac2423c | 2017-01-25 12:08:40 -0800 | [diff] [blame] | 300 | unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid); |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 301 | u8 *data; |
| 302 | int ret; |
Aaron Ma | 3064a03 | 2018-02-03 23:57:15 +0800 | [diff] [blame] | 303 | u32 n; |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 304 | |
Jason Gerecke | 5783251 | 2018-06-25 13:24:35 -0700 | [diff] [blame] | 305 | wacom_hid_usage_quirk(hdev, field, usage); |
| 306 | |
Aaron Armstrong Skomra | ac2423c | 2017-01-25 12:08:40 -0800 | [diff] [blame] | 307 | switch (equivalent_usage) { |
Aaron Armstrong Skomra | d8e9806 | 2019-05-10 15:31:16 -0700 | [diff] [blame] | 308 | case WACOM_HID_WD_TOUCH_RING_SETTING: |
| 309 | wacom->generic_has_leds = true; |
| 310 | break; |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 311 | case HID_DG_CONTACTMAX: |
| 312 | /* leave touch_max as is if predefined */ |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 313 | if (!features->touch_max) { |
| 314 | /* read manually */ |
Aaron Armstrong Skomra | 184eccd | 2019-06-12 14:19:29 -0700 | [diff] [blame] | 315 | n = hid_report_len(field->report); |
| 316 | data = hid_alloc_report_buf(field->report, GFP_KERNEL); |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 317 | if (!data) |
| 318 | break; |
| 319 | data[0] = field->report->id; |
| 320 | ret = wacom_get_report(hdev, HID_FEATURE_REPORT, |
Aaron Armstrong Skomra | 184eccd | 2019-06-12 14:19:29 -0700 | [diff] [blame] | 321 | data, n, WAC_CMD_RETRIES); |
Jason Gerecke | 778fbf4 | 2020-04-01 14:23:29 -0700 | [diff] [blame] | 322 | if (ret == n && features->type == HID_GENERIC) { |
Aaron Armstrong Skomra | 184eccd | 2019-06-12 14:19:29 -0700 | [diff] [blame] | 323 | ret = hid_report_raw_event(hdev, |
| 324 | HID_FEATURE_REPORT, data, n, 0); |
Jason Gerecke | 778fbf4 | 2020-04-01 14:23:29 -0700 | [diff] [blame] | 325 | } else if (ret == 2 && features->type != HID_GENERIC) { |
| 326 | features->touch_max = data[1]; |
Jason Gerecke | 05e8fd9 | 2015-05-21 10:44:32 -0700 | [diff] [blame] | 327 | } else { |
| 328 | features->touch_max = 16; |
| 329 | hid_warn(hdev, "wacom_feature_mapping: " |
| 330 | "could not get HID_DG_CONTACTMAX, " |
| 331 | "defaulting to %d\n", |
| 332 | features->touch_max); |
| 333 | } |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 334 | kfree(data); |
| 335 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 336 | break; |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 337 | case HID_DG_INPUTMODE: |
| 338 | /* Ignore if value index is out of bounds. */ |
| 339 | if (usage->usage_index >= field->report_count) { |
| 340 | dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n"); |
| 341 | break; |
| 342 | } |
| 343 | |
| 344 | hid_data->inputmode = field->report->id; |
| 345 | hid_data->inputmode_index = usage->usage_index; |
| 346 | break; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 347 | |
| 348 | case HID_UP_DIGITIZER: |
| 349 | if (field->report->id == 0x0B && |
Jason Gerecke | 8de8228 | 2016-10-19 18:03:37 -0700 | [diff] [blame] | 350 | (field->application == WACOM_HID_G9_PEN || |
| 351 | field->application == WACOM_HID_G11_PEN)) { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 352 | wacom->wacom_wac.mode_report = field->report->id; |
| 353 | wacom->wacom_wac.mode_value = 0; |
| 354 | } |
| 355 | break; |
| 356 | |
Jason Gerecke | c9c0958 | 2016-10-19 18:03:43 -0700 | [diff] [blame] | 357 | case WACOM_HID_WD_DATAMODE: |
| 358 | wacom->wacom_wac.mode_report = field->report->id; |
| 359 | wacom->wacom_wac.mode_value = 2; |
| 360 | break; |
| 361 | |
Jason Gerecke | 8de8228 | 2016-10-19 18:03:37 -0700 | [diff] [blame] | 362 | case WACOM_HID_UP_G9: |
| 363 | case WACOM_HID_UP_G11: |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 364 | if (field->report->id == 0x03 && |
Jason Gerecke | 8de8228 | 2016-10-19 18:03:37 -0700 | [diff] [blame] | 365 | (field->application == WACOM_HID_G9_TOUCHSCREEN || |
| 366 | field->application == WACOM_HID_G11_TOUCHSCREEN)) { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 367 | wacom->wacom_wac.mode_report = field->report->id; |
| 368 | wacom->wacom_wac.mode_value = 0; |
| 369 | } |
| 370 | break; |
Jason Gerecke | 345857b | 2016-10-19 18:03:50 -0700 | [diff] [blame] | 371 | case WACOM_HID_WD_OFFSETLEFT: |
| 372 | case WACOM_HID_WD_OFFSETTOP: |
| 373 | case WACOM_HID_WD_OFFSETRIGHT: |
| 374 | case WACOM_HID_WD_OFFSETBOTTOM: |
| 375 | /* read manually */ |
| 376 | n = hid_report_len(field->report); |
| 377 | data = hid_alloc_report_buf(field->report, GFP_KERNEL); |
| 378 | if (!data) |
| 379 | break; |
| 380 | data[0] = field->report->id; |
| 381 | ret = wacom_get_report(hdev, HID_FEATURE_REPORT, |
| 382 | data, n, WAC_CMD_RETRIES); |
| 383 | if (ret == n) { |
| 384 | ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, |
| 385 | data, n, 0); |
| 386 | } else { |
| 387 | hid_warn(hdev, "%s: could not retrieve sensor offsets\n", |
| 388 | __func__); |
| 389 | } |
| 390 | kfree(data); |
| 391 | break; |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 395 | /* |
| 396 | * Interface Descriptor of wacom devices can be incomplete and |
| 397 | * inconsistent so wacom_features table is used to store stylus |
| 398 | * device's packet lengths, various maximum values, and tablet |
| 399 | * resolution based on product ID's. |
| 400 | * |
| 401 | * For devices that contain 2 interfaces, wacom_features table is |
| 402 | * inaccurate for the touch interface. Since the Interface Descriptor |
| 403 | * for touch interfaces has pretty complete data, this function exists |
| 404 | * to query tablet for this missing information instead of hard coding in |
| 405 | * an additional table. |
| 406 | * |
| 407 | * A typical Interface Descriptor for a stylus will contain a |
| 408 | * boot mouse application collection that is not of interest and this |
| 409 | * function will ignore it. |
| 410 | * |
| 411 | * It also contains a digitizer application collection that also is not |
| 412 | * of interest since any information it contains would be duplicate |
| 413 | * of what is in wacom_features. Usually it defines a report of an array |
| 414 | * of bytes that could be used as max length of the stylus packet returned. |
| 415 | * If it happens to define a Digitizer-Stylus Physical Collection then |
| 416 | * the X and Y logical values contain valid data but it is ignored. |
| 417 | * |
| 418 | * A typical Interface Descriptor for a touch interface will contain a |
| 419 | * Digitizer-Finger Physical Collection which will define both logical |
| 420 | * X/Y maximum as well as the physical size of tablet. Since touch |
| 421 | * interfaces haven't supported pressure or distance, this is enough |
| 422 | * information to override invalid values in the wacom_features table. |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 423 | * |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 424 | * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful |
| 425 | * data. We deal with them after returning from this function. |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 426 | */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 427 | static void wacom_usage_mapping(struct hid_device *hdev, |
| 428 | struct hid_field *field, struct hid_usage *usage) |
| 429 | { |
| 430 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 431 | struct wacom_features *features = &wacom->wacom_wac.features; |
Benjamin Tissoires | d97a552 | 2015-01-05 16:32:12 -0500 | [diff] [blame] | 432 | bool finger = WACOM_FINGER_FIELD(field); |
| 433 | bool pen = WACOM_PEN_FIELD(field); |
Ping Cheng | 418b573 | 2018-06-25 13:24:36 -0700 | [diff] [blame] | 434 | unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * Requiring Stylus Usage will ignore boot mouse |
| 438 | * X/Y values and some cases of invalid Digitizer X/Y |
| 439 | * values commonly reported. |
| 440 | */ |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 441 | if (pen) |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 442 | features->device_type |= WACOM_DEVICETYPE_PEN; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 443 | else if (finger) |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 444 | features->device_type |= WACOM_DEVICETYPE_TOUCH; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 445 | else |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 446 | return; |
| 447 | |
Jason Gerecke | 5783251 | 2018-06-25 13:24:35 -0700 | [diff] [blame] | 448 | wacom_hid_usage_quirk(hdev, field, usage); |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 449 | |
Ping Cheng | 418b573 | 2018-06-25 13:24:36 -0700 | [diff] [blame] | 450 | switch (equivalent_usage) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 451 | case HID_GD_X: |
| 452 | features->x_max = field->logical_maximum; |
| 453 | if (finger) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 454 | features->x_phy = field->physical_maximum; |
Ping Cheng | 3b164a0 | 2015-09-23 09:59:10 -0700 | [diff] [blame] | 455 | if ((features->type != BAMBOO_PT) && |
| 456 | (features->type != BAMBOO_TOUCH)) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 457 | features->unit = field->unit; |
| 458 | features->unitExpo = field->unit_exponent; |
| 459 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 460 | } |
| 461 | break; |
| 462 | case HID_GD_Y: |
| 463 | features->y_max = field->logical_maximum; |
| 464 | if (finger) { |
| 465 | features->y_phy = field->physical_maximum; |
Ping Cheng | 3b164a0 | 2015-09-23 09:59:10 -0700 | [diff] [blame] | 466 | if ((features->type != BAMBOO_PT) && |
| 467 | (features->type != BAMBOO_TOUCH)) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 468 | features->unit = field->unit; |
| 469 | features->unitExpo = field->unit_exponent; |
| 470 | } |
| 471 | } |
| 472 | break; |
| 473 | case HID_DG_TIPPRESSURE: |
| 474 | if (pen) |
| 475 | features->pressure_max = field->logical_maximum; |
| 476 | break; |
| 477 | } |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 478 | |
| 479 | if (features->type == HID_GENERIC) |
| 480 | wacom_wac_usage_mapping(hdev, field, usage); |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 483 | static void wacom_post_parse_hid(struct hid_device *hdev, |
| 484 | struct wacom_features *features) |
| 485 | { |
| 486 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 487 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 488 | |
| 489 | if (features->type == HID_GENERIC) { |
| 490 | /* Any last-minute generic device setup */ |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 491 | if (wacom_wac->has_mode_change) { |
| 492 | if (wacom_wac->is_direct_mode) |
| 493 | features->device_type |= WACOM_DEVICETYPE_DIRECT; |
| 494 | else |
| 495 | features->device_type &= ~WACOM_DEVICETYPE_DIRECT; |
| 496 | } |
| 497 | |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 498 | if (features->touch_max > 1) { |
Aaron Armstrong Skomra | ac2423c | 2017-01-25 12:08:40 -0800 | [diff] [blame] | 499 | if (features->device_type & WACOM_DEVICETYPE_DIRECT) |
| 500 | input_mt_init_slots(wacom_wac->touch_input, |
| 501 | wacom_wac->features.touch_max, |
| 502 | INPUT_MT_DIRECT); |
| 503 | else |
| 504 | input_mt_init_slots(wacom_wac->touch_input, |
| 505 | wacom_wac->features.touch_max, |
| 506 | INPUT_MT_POINTER); |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 511 | static void wacom_parse_hid(struct hid_device *hdev, |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 512 | struct wacom_features *features) |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 513 | { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 514 | struct hid_report_enum *rep_enum; |
| 515 | struct hid_report *hreport; |
| 516 | int i, j; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 517 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 518 | /* check features first */ |
| 519 | rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; |
| 520 | list_for_each_entry(hreport, &rep_enum->report_list, list) { |
| 521 | for (i = 0; i < hreport->maxfield; i++) { |
| 522 | /* Ignore if report count is out of bounds. */ |
| 523 | if (hreport->field[i]->report_count < 1) |
| 524 | continue; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 525 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 526 | for (j = 0; j < hreport->field[i]->maxusage; j++) { |
| 527 | wacom_feature_mapping(hdev, hreport->field[i], |
| 528 | hreport->field[i]->usage + j); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 529 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 533 | /* now check the input usages */ |
| 534 | rep_enum = &hdev->report_enum[HID_INPUT_REPORT]; |
| 535 | list_for_each_entry(hreport, &rep_enum->report_list, list) { |
| 536 | |
| 537 | if (!hreport->maxfield) |
| 538 | continue; |
| 539 | |
| 540 | for (i = 0; i < hreport->maxfield; i++) |
| 541 | for (j = 0; j < hreport->field[i]->maxusage; j++) |
| 542 | wacom_usage_mapping(hdev, hreport->field[i], |
| 543 | hreport->field[i]->usage + j); |
| 544 | } |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 545 | |
| 546 | wacom_post_parse_hid(hdev, features); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 547 | } |
| 548 | |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 549 | static int wacom_hid_set_device_mode(struct hid_device *hdev) |
| 550 | { |
| 551 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 552 | struct hid_data *hid_data = &wacom->wacom_wac.hid_data; |
| 553 | struct hid_report *r; |
| 554 | struct hid_report_enum *re; |
| 555 | |
| 556 | if (hid_data->inputmode < 0) |
| 557 | return 0; |
| 558 | |
| 559 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); |
| 560 | r = re->report_id_hash[hid_data->inputmode]; |
| 561 | if (r) { |
| 562 | r->field[0]->value[hid_data->inputmode_index] = 2; |
| 563 | hid_hw_request(hdev, r, HID_REQ_SET_REPORT); |
| 564 | } |
| 565 | return 0; |
| 566 | } |
| 567 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 568 | static int wacom_set_device_mode(struct hid_device *hdev, |
| 569 | struct wacom_wac *wacom_wac) |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 570 | { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 571 | u8 *rep_data; |
| 572 | struct hid_report *r; |
| 573 | struct hid_report_enum *re; |
Aaron Ma | 3064a03 | 2018-02-03 23:57:15 +0800 | [diff] [blame] | 574 | u32 length; |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 575 | int error = -ENOMEM, limit = 0; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 576 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 577 | if (wacom_wac->mode_report < 0) |
| 578 | return 0; |
| 579 | |
| 580 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); |
| 581 | r = re->report_id_hash[wacom_wac->mode_report]; |
| 582 | if (!r) |
| 583 | return -EINVAL; |
| 584 | |
| 585 | rep_data = hid_alloc_report_buf(r, GFP_KERNEL); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 586 | if (!rep_data) |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 587 | return -ENOMEM; |
| 588 | |
| 589 | length = hid_report_len(r); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 590 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 591 | do { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 592 | rep_data[0] = wacom_wac->mode_report; |
| 593 | rep_data[1] = wacom_wac->mode_value; |
Chris Bagwell | 9937c02 | 2013-01-23 19:37:34 -0800 | [diff] [blame] | 594 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 595 | error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, |
| 596 | length, 1); |
Benjamin Tissoires | 3cb8315 | 2014-07-24 12:47:47 -0700 | [diff] [blame] | 597 | if (error >= 0) |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 598 | error = wacom_get_report(hdev, HID_FEATURE_REPORT, |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 599 | rep_data, length, 1); |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 600 | } while (error >= 0 && |
| 601 | rep_data[1] != wacom_wac->mode_report && |
| 602 | limit++ < WAC_MSG_RETRIES); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 603 | |
| 604 | kfree(rep_data); |
| 605 | |
| 606 | return error < 0 ? error : 0; |
| 607 | } |
| 608 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 609 | static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed, |
| 610 | struct wacom_features *features) |
| 611 | { |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 612 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 613 | int ret; |
| 614 | u8 rep_data[2]; |
| 615 | |
| 616 | switch (features->type) { |
| 617 | case GRAPHIRE_BT: |
| 618 | rep_data[0] = 0x03; |
| 619 | rep_data[1] = 0x00; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 620 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2, |
| 621 | 3); |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 622 | |
| 623 | if (ret >= 0) { |
| 624 | rep_data[0] = speed == 0 ? 0x05 : 0x06; |
| 625 | rep_data[1] = 0x00; |
| 626 | |
| 627 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 628 | rep_data, 2, 3); |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 629 | |
| 630 | if (ret >= 0) { |
| 631 | wacom->wacom_wac.bt_high_speed = speed; |
| 632 | return 0; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | /* |
| 637 | * Note that if the raw queries fail, it's not a hard failure |
| 638 | * and it is safe to continue |
| 639 | */ |
| 640 | hid_warn(hdev, "failed to poke device, command %d, err %d\n", |
| 641 | rep_data[0], ret); |
| 642 | break; |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 643 | case INTUOS4WL: |
| 644 | if (speed == 1) |
| 645 | wacom->wacom_wac.bt_features &= ~0x20; |
| 646 | else |
| 647 | wacom->wacom_wac.bt_features |= 0x20; |
| 648 | |
| 649 | rep_data[0] = 0x03; |
| 650 | rep_data[1] = wacom->wacom_wac.bt_features; |
| 651 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 652 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2, |
| 653 | 1); |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 654 | if (ret >= 0) |
| 655 | wacom->wacom_wac.bt_high_speed = speed; |
| 656 | break; |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 659 | return 0; |
| 660 | } |
| 661 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 662 | /* |
| 663 | * Switch the tablet into its most-capable mode. Wacom tablets are |
| 664 | * typically configured to power-up in a mode which sends mouse-like |
| 665 | * reports to the OS. To get absolute position, pressure data, etc. |
| 666 | * from the tablet, it is necessary to switch the tablet out of this |
| 667 | * mode and into one which sends the full range of tablet data. |
| 668 | */ |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 669 | static int _wacom_query_tablet_data(struct wacom *wacom) |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 670 | { |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 671 | struct hid_device *hdev = wacom->hdev; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 672 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 673 | struct wacom_features *features = &wacom_wac->features; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 674 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 675 | if (hdev->bus == BUS_BLUETOOTH) |
| 676 | return wacom_bt_query_tablet_data(hdev, 1, features); |
| 677 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 678 | if (features->type != HID_GENERIC) { |
| 679 | if (features->device_type & WACOM_DEVICETYPE_TOUCH) { |
| 680 | if (features->type > TABLETPC) { |
| 681 | /* MT Tablet PC touch */ |
| 682 | wacom_wac->mode_report = 3; |
| 683 | wacom_wac->mode_value = 4; |
| 684 | } else if (features->type == WACOM_24HDT) { |
| 685 | wacom_wac->mode_report = 18; |
| 686 | wacom_wac->mode_value = 2; |
| 687 | } else if (features->type == WACOM_27QHDT) { |
| 688 | wacom_wac->mode_report = 131; |
| 689 | wacom_wac->mode_value = 2; |
| 690 | } else if (features->type == BAMBOO_PAD) { |
| 691 | wacom_wac->mode_report = 2; |
| 692 | wacom_wac->mode_value = 2; |
| 693 | } |
| 694 | } else if (features->device_type & WACOM_DEVICETYPE_PEN) { |
| 695 | if (features->type <= BAMBOO_PT) { |
| 696 | wacom_wac->mode_report = 2; |
| 697 | wacom_wac->mode_value = 2; |
| 698 | } |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 702 | wacom_set_device_mode(hdev, wacom_wac); |
| 703 | |
| 704 | if (features->type == HID_GENERIC) |
| 705 | return wacom_hid_set_device_mode(hdev); |
| 706 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 707 | return 0; |
| 708 | } |
| 709 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 710 | static void wacom_retrieve_hid_descriptor(struct hid_device *hdev, |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 711 | struct wacom_features *features) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 712 | { |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 713 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 714 | struct usb_interface *intf = wacom->intf; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 715 | |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 716 | /* default features */ |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 717 | features->x_fuzz = 4; |
| 718 | features->y_fuzz = 4; |
| 719 | features->pressure_fuzz = 0; |
Jason Gerecke | bef7e20 | 2016-04-22 14:30:53 -0700 | [diff] [blame] | 720 | features->distance_fuzz = 1; |
| 721 | features->tilt_fuzz = 1; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 722 | |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 723 | /* |
| 724 | * The wireless device HID is basic and layout conflicts with |
| 725 | * other tablets (monitor and touch interface can look like pen). |
| 726 | * Skip the query for this type and modify defaults based on |
| 727 | * interface number. |
| 728 | */ |
| 729 | if (features->type == WIRELESS) { |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 730 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 731 | features->device_type = WACOM_DEVICETYPE_WL_MONITOR; |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 732 | else |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 733 | features->device_type = WACOM_DEVICETYPE_NONE; |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 734 | return; |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 737 | wacom_parse_hid(hdev, features); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 738 | } |
| 739 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 740 | struct wacom_hdev_data { |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 741 | struct list_head list; |
| 742 | struct kref kref; |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 743 | struct hid_device *dev; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 744 | struct wacom_shared shared; |
| 745 | }; |
| 746 | |
| 747 | static LIST_HEAD(wacom_udev_list); |
| 748 | static DEFINE_MUTEX(wacom_udev_list_lock); |
| 749 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 750 | static bool wacom_are_sibling(struct hid_device *hdev, |
| 751 | struct hid_device *sibling) |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 752 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 753 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 754 | struct wacom_features *features = &wacom->wacom_wac.features; |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 755 | struct wacom *sibling_wacom = hid_get_drvdata(sibling); |
| 756 | struct wacom_features *sibling_features = &sibling_wacom->wacom_wac.features; |
| 757 | __u32 oVid = features->oVid ? features->oVid : hdev->vendor; |
| 758 | __u32 oPid = features->oPid ? features->oPid : hdev->product; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 759 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 760 | /* The defined oVid/oPid must match that of the sibling */ |
| 761 | if (features->oVid != HID_ANY_ID && sibling->vendor != oVid) |
| 762 | return false; |
| 763 | if (features->oPid != HID_ANY_ID && sibling->product != oPid) |
| 764 | return false; |
| 765 | |
| 766 | /* |
| 767 | * Devices with the same VID/PID must share the same physical |
| 768 | * device path, while those with different VID/PID must share |
| 769 | * the same physical parent device path. |
| 770 | */ |
| 771 | if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) { |
Daniel M. Lambea | 1a8861f | 2018-07-17 22:35:36 +0100 | [diff] [blame] | 772 | if (!hid_compare_device_paths(hdev, sibling, '/')) |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 773 | return false; |
| 774 | } else { |
Daniel M. Lambea | 1a8861f | 2018-07-17 22:35:36 +0100 | [diff] [blame] | 775 | if (!hid_compare_device_paths(hdev, sibling, '.')) |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 776 | return false; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 779 | /* Skip the remaining heuristics unless you are a HID_GENERIC device */ |
| 780 | if (features->type != HID_GENERIC) |
| 781 | return true; |
| 782 | |
| 783 | /* |
| 784 | * Direct-input devices may not be siblings of indirect-input |
| 785 | * devices. |
| 786 | */ |
| 787 | if ((features->device_type & WACOM_DEVICETYPE_DIRECT) && |
| 788 | !(sibling_features->device_type & WACOM_DEVICETYPE_DIRECT)) |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 789 | return false; |
| 790 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 791 | /* |
| 792 | * Indirect-input devices may not be siblings of direct-input |
| 793 | * devices. |
| 794 | */ |
| 795 | if (!(features->device_type & WACOM_DEVICETYPE_DIRECT) && |
| 796 | (sibling_features->device_type & WACOM_DEVICETYPE_DIRECT)) |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 797 | return false; |
| 798 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 799 | /* Pen devices may only be siblings of touch devices */ |
| 800 | if ((features->device_type & WACOM_DEVICETYPE_PEN) && |
| 801 | !(sibling_features->device_type & WACOM_DEVICETYPE_TOUCH)) |
| 802 | return false; |
| 803 | |
| 804 | /* Touch devices may only be siblings of pen devices */ |
| 805 | if ((features->device_type & WACOM_DEVICETYPE_TOUCH) && |
| 806 | !(sibling_features->device_type & WACOM_DEVICETYPE_PEN)) |
| 807 | return false; |
| 808 | |
| 809 | /* |
| 810 | * No reason could be found for these two devices to NOT be |
| 811 | * siblings, so there's a good chance they ARE siblings |
| 812 | */ |
| 813 | return true; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 816 | 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] | 817 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 818 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 819 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 820 | /* Try to find an already-probed interface from the same device */ |
| 821 | list_for_each_entry(data, &wacom_udev_list, list) { |
Daniel M. Lambea | 1a8861f | 2018-07-17 22:35:36 +0100 | [diff] [blame] | 822 | if (hid_compare_device_paths(hdev, data->dev, '/')) { |
Jason Gerecke | 2a5e597 | 2017-09-18 09:27:42 -0700 | [diff] [blame] | 823 | kref_get(&data->kref); |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 824 | return data; |
Jason Gerecke | 2a5e597 | 2017-09-18 09:27:42 -0700 | [diff] [blame] | 825 | } |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | /* Fallback to finding devices that appear to be "siblings" */ |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 829 | list_for_each_entry(data, &wacom_udev_list, list) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 830 | if (wacom_are_sibling(hdev, data->dev)) { |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 831 | kref_get(&data->kref); |
| 832 | return data; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | return NULL; |
| 837 | } |
| 838 | |
Benjamin Tissoires | 1c817c8 | 2016-07-13 18:05:59 +0200 | [diff] [blame] | 839 | static void wacom_release_shared_data(struct kref *kref) |
| 840 | { |
| 841 | struct wacom_hdev_data *data = |
| 842 | container_of(kref, struct wacom_hdev_data, kref); |
| 843 | |
| 844 | mutex_lock(&wacom_udev_list_lock); |
| 845 | list_del(&data->list); |
| 846 | mutex_unlock(&wacom_udev_list_lock); |
| 847 | |
| 848 | kfree(data); |
| 849 | } |
| 850 | |
| 851 | static void wacom_remove_shared_data(void *res) |
| 852 | { |
| 853 | struct wacom *wacom = res; |
| 854 | struct wacom_hdev_data *data; |
| 855 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 856 | |
| 857 | if (wacom_wac->shared) { |
| 858 | data = container_of(wacom_wac->shared, struct wacom_hdev_data, |
| 859 | shared); |
| 860 | |
| 861 | if (wacom_wac->shared->touch == wacom->hdev) |
| 862 | wacom_wac->shared->touch = NULL; |
| 863 | else if (wacom_wac->shared->pen == wacom->hdev) |
| 864 | wacom_wac->shared->pen = NULL; |
| 865 | |
| 866 | kref_put(&data->kref, wacom_release_shared_data); |
| 867 | wacom_wac->shared = NULL; |
| 868 | } |
| 869 | } |
| 870 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 871 | static int wacom_add_shared_data(struct hid_device *hdev) |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 872 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 873 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 874 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 875 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 876 | int retval = 0; |
| 877 | |
| 878 | mutex_lock(&wacom_udev_list_lock); |
| 879 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 880 | data = wacom_get_hdev_data(hdev); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 881 | if (!data) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 882 | data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 883 | if (!data) { |
| 884 | retval = -ENOMEM; |
| 885 | goto out; |
| 886 | } |
| 887 | |
| 888 | kref_init(&data->kref); |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 889 | data->dev = hdev; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 890 | list_add_tail(&data->list, &wacom_udev_list); |
| 891 | } |
| 892 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 893 | wacom_wac->shared = &data->shared; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 894 | |
Benjamin Tissoires | 1c817c8 | 2016-07-13 18:05:59 +0200 | [diff] [blame] | 895 | retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom); |
| 896 | if (retval) { |
| 897 | mutex_unlock(&wacom_udev_list_lock); |
| 898 | wacom_remove_shared_data(wacom); |
| 899 | return retval; |
| 900 | } |
| 901 | |
Jason Gerecke | a9ce785 | 2017-01-17 15:38:58 -0800 | [diff] [blame] | 902 | if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) |
| 903 | wacom_wac->shared->touch = hdev; |
| 904 | else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN) |
| 905 | wacom_wac->shared->pen = hdev; |
| 906 | |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 907 | out: |
| 908 | mutex_unlock(&wacom_udev_list_lock); |
| 909 | return retval; |
| 910 | } |
| 911 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 912 | static int wacom_led_control(struct wacom *wacom) |
| 913 | { |
| 914 | unsigned char *buf; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 915 | int retval; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 916 | unsigned char report_id = WAC_CMD_LED_CONTROL; |
| 917 | int buf_size = 9; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 918 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 919 | if (!wacom->led.groups) |
| 920 | return -ENOTSUPP; |
| 921 | |
Aaron Armstrong Skomra | 74aebed6 | 2017-08-28 14:15:39 -0700 | [diff] [blame] | 922 | if (wacom->wacom_wac.features.type == REMOTE) |
| 923 | return -ENOTSUPP; |
| 924 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 925 | if (wacom->wacom_wac.pid) { /* wireless connected */ |
| 926 | report_id = WAC_CMD_WL_LED_CONTROL; |
| 927 | buf_size = 13; |
| 928 | } |
Jason Gerecke | 4922cd2 | 2017-01-25 12:08:37 -0800 | [diff] [blame] | 929 | else if (wacom->wacom_wac.features.type == INTUOSP2_BT) { |
| 930 | report_id = WAC_CMD_WL_INTUOSP2; |
| 931 | buf_size = 51; |
| 932 | } |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 933 | buf = kzalloc(buf_size, GFP_KERNEL); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 934 | if (!buf) |
| 935 | return -ENOMEM; |
| 936 | |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 937 | if (wacom->wacom_wac.features.type == HID_GENERIC) { |
| 938 | buf[0] = WAC_CMD_LED_CONTROL_GENERIC; |
| 939 | buf[1] = wacom->led.llv; |
| 940 | buf[2] = wacom->led.groups[0].select & 0x03; |
| 941 | |
| 942 | } else if ((wacom->wacom_wac.features.type >= INTUOS5S && |
| 943 | wacom->wacom_wac.features.type <= INTUOSPL)) { |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 944 | /* |
| 945 | * Touch Ring and crop mark LED luminance may take on |
| 946 | * one of four values: |
| 947 | * 0 = Low; 1 = Medium; 2 = High; 3 = Off |
| 948 | */ |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 949 | int ring_led = wacom->led.groups[0].select & 0x03; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 950 | int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03; |
| 951 | int crop_lum = 0; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 952 | unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 953 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 954 | buf[0] = report_id; |
| 955 | if (wacom->wacom_wac.pid) { |
| 956 | wacom_get_report(wacom->hdev, HID_FEATURE_REPORT, |
| 957 | buf, buf_size, WAC_CMD_RETRIES); |
| 958 | buf[0] = report_id; |
| 959 | buf[4] = led_bits; |
| 960 | } else |
| 961 | buf[1] = led_bits; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 962 | } |
Jason Gerecke | 4922cd2 | 2017-01-25 12:08:37 -0800 | [diff] [blame] | 963 | else if (wacom->wacom_wac.features.type == INTUOSP2_BT) { |
| 964 | buf[0] = report_id; |
| 965 | buf[4] = 100; // Power Connection LED (ORANGE) |
| 966 | buf[5] = 100; // BT Connection LED (BLUE) |
| 967 | buf[6] = 100; // Paper Mode (RED?) |
| 968 | buf[7] = 100; // Paper Mode (GREEN?) |
| 969 | buf[8] = 100; // Paper Mode (BLUE?) |
| 970 | buf[9] = wacom->led.llv; |
| 971 | buf[10] = wacom->led.groups[0].select & 0x03; |
| 972 | } |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 973 | else { |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 974 | int led = wacom->led.groups[0].select | 0x4; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 975 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 976 | if (wacom->wacom_wac.features.type == WACOM_21UX2 || |
| 977 | wacom->wacom_wac.features.type == WACOM_24HD) |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 978 | led |= (wacom->led.groups[1].select << 4) | 0x40; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 979 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 980 | buf[0] = report_id; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 981 | buf[1] = led; |
| 982 | buf[2] = wacom->led.llv; |
| 983 | buf[3] = wacom->led.hlv; |
| 984 | buf[4] = wacom->led.img_lum; |
| 985 | } |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 986 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 987 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 988 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 989 | kfree(buf); |
| 990 | |
| 991 | return retval; |
| 992 | } |
| 993 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 994 | static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id, |
| 995 | const unsigned len, const void *img) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 996 | { |
| 997 | unsigned char *buf; |
| 998 | int i, retval; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 999 | 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] | 1000 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 1001 | buf = kzalloc(chunk_len + 3 , GFP_KERNEL); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1002 | if (!buf) |
| 1003 | return -ENOMEM; |
| 1004 | |
| 1005 | /* Send 'start' command */ |
| 1006 | buf[0] = WAC_CMD_ICON_START; |
| 1007 | buf[1] = 1; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 1008 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2, |
| 1009 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1010 | if (retval < 0) |
| 1011 | goto out; |
| 1012 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 1013 | buf[0] = xfer_id; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1014 | buf[1] = button_id & 0x07; |
| 1015 | for (i = 0; i < 4; i++) { |
| 1016 | buf[2] = i; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 1017 | memcpy(buf + 3, img + i * chunk_len, chunk_len); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1018 | |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 1019 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 1020 | buf, chunk_len + 3, WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1021 | if (retval < 0) |
| 1022 | break; |
| 1023 | } |
| 1024 | |
| 1025 | /* Send 'stop' */ |
| 1026 | buf[0] = WAC_CMD_ICON_START; |
| 1027 | buf[1] = 0; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 1028 | wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2, |
| 1029 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1030 | |
| 1031 | out: |
| 1032 | kfree(buf); |
| 1033 | return retval; |
| 1034 | } |
| 1035 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1036 | 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] | 1037 | const char *buf, size_t count) |
| 1038 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1039 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1040 | struct wacom *wacom = hid_get_drvdata(hdev); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1041 | unsigned int id; |
| 1042 | int err; |
| 1043 | |
| 1044 | err = kstrtouint(buf, 10, &id); |
| 1045 | if (err) |
| 1046 | return err; |
| 1047 | |
| 1048 | mutex_lock(&wacom->lock); |
| 1049 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1050 | wacom->led.groups[set_id].select = id & 0x3; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1051 | err = wacom_led_control(wacom); |
| 1052 | |
| 1053 | mutex_unlock(&wacom->lock); |
| 1054 | |
| 1055 | return err < 0 ? err : count; |
| 1056 | } |
| 1057 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1058 | #define DEVICE_LED_SELECT_ATTR(SET_ID) \ |
| 1059 | static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \ |
| 1060 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 1061 | { \ |
| 1062 | return wacom_led_select_store(dev, SET_ID, buf, count); \ |
| 1063 | } \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 1064 | static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ |
| 1065 | struct device_attribute *attr, char *buf) \ |
| 1066 | { \ |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1067 | struct hid_device *hdev = to_hid_device(dev);\ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1068 | struct wacom *wacom = hid_get_drvdata(hdev); \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 1069 | return scnprintf(buf, PAGE_SIZE, "%d\n", \ |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1070 | wacom->led.groups[SET_ID].select); \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 1071 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 1072 | static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 1073 | wacom_led##SET_ID##_select_show, \ |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1074 | wacom_led##SET_ID##_select_store) |
| 1075 | |
| 1076 | DEVICE_LED_SELECT_ATTR(0); |
| 1077 | DEVICE_LED_SELECT_ATTR(1); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1078 | |
| 1079 | static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, |
| 1080 | const char *buf, size_t count) |
| 1081 | { |
| 1082 | unsigned int value; |
| 1083 | int err; |
| 1084 | |
| 1085 | err = kstrtouint(buf, 10, &value); |
| 1086 | if (err) |
| 1087 | return err; |
| 1088 | |
| 1089 | mutex_lock(&wacom->lock); |
| 1090 | |
| 1091 | *dest = value & 0x7f; |
| 1092 | err = wacom_led_control(wacom); |
| 1093 | |
| 1094 | mutex_unlock(&wacom->lock); |
| 1095 | |
| 1096 | return err < 0 ? err : count; |
| 1097 | } |
| 1098 | |
| 1099 | #define DEVICE_LUMINANCE_ATTR(name, field) \ |
| 1100 | static ssize_t wacom_##name##_luminance_store(struct device *dev, \ |
| 1101 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 1102 | { \ |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1103 | struct hid_device *hdev = to_hid_device(dev);\ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1104 | struct wacom *wacom = hid_get_drvdata(hdev); \ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1105 | \ |
| 1106 | return wacom_luminance_store(wacom, &wacom->led.field, \ |
| 1107 | buf, count); \ |
| 1108 | } \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 1109 | static ssize_t wacom_##name##_luminance_show(struct device *dev, \ |
| 1110 | struct device_attribute *attr, char *buf) \ |
| 1111 | { \ |
| 1112 | struct wacom *wacom = dev_get_drvdata(dev); \ |
| 1113 | return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \ |
| 1114 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 1115 | static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 1116 | wacom_##name##_luminance_show, \ |
| 1117 | wacom_##name##_luminance_store) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1118 | |
| 1119 | DEVICE_LUMINANCE_ATTR(status0, llv); |
| 1120 | DEVICE_LUMINANCE_ATTR(status1, hlv); |
| 1121 | DEVICE_LUMINANCE_ATTR(buttons, img_lum); |
| 1122 | |
| 1123 | static ssize_t wacom_button_image_store(struct device *dev, int button_id, |
| 1124 | const char *buf, size_t count) |
| 1125 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1126 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1127 | struct wacom *wacom = hid_get_drvdata(hdev); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1128 | int err; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 1129 | unsigned len; |
| 1130 | u8 xfer_id; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1131 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 1132 | if (hdev->bus == BUS_BLUETOOTH) { |
| 1133 | len = 256; |
| 1134 | xfer_id = WAC_CMD_ICON_BT_XFER; |
| 1135 | } else { |
| 1136 | len = 1024; |
| 1137 | xfer_id = WAC_CMD_ICON_XFER; |
| 1138 | } |
| 1139 | |
| 1140 | if (count != len) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1141 | return -EINVAL; |
| 1142 | |
| 1143 | mutex_lock(&wacom->lock); |
| 1144 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 1145 | err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1146 | |
| 1147 | mutex_unlock(&wacom->lock); |
| 1148 | |
| 1149 | return err < 0 ? err : count; |
| 1150 | } |
| 1151 | |
| 1152 | #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \ |
| 1153 | static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \ |
| 1154 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 1155 | { \ |
| 1156 | return wacom_button_image_store(dev, BUTTON_ID, buf, count); \ |
| 1157 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 1158 | static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1159 | NULL, wacom_btnimg##BUTTON_ID##_store) |
| 1160 | |
| 1161 | DEVICE_BTNIMG_ATTR(0); |
| 1162 | DEVICE_BTNIMG_ATTR(1); |
| 1163 | DEVICE_BTNIMG_ATTR(2); |
| 1164 | DEVICE_BTNIMG_ATTR(3); |
| 1165 | DEVICE_BTNIMG_ATTR(4); |
| 1166 | DEVICE_BTNIMG_ATTR(5); |
| 1167 | DEVICE_BTNIMG_ATTR(6); |
| 1168 | DEVICE_BTNIMG_ATTR(7); |
| 1169 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1170 | static struct attribute *cintiq_led_attrs[] = { |
| 1171 | &dev_attr_status_led0_select.attr, |
| 1172 | &dev_attr_status_led1_select.attr, |
| 1173 | NULL |
| 1174 | }; |
| 1175 | |
Rikard Falkeborn | 2a6a35a | 2020-11-25 00:01:09 +0100 | [diff] [blame] | 1176 | static const struct attribute_group cintiq_led_attr_group = { |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1177 | .name = "wacom_led", |
| 1178 | .attrs = cintiq_led_attrs, |
| 1179 | }; |
| 1180 | |
| 1181 | static struct attribute *intuos4_led_attrs[] = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1182 | &dev_attr_status0_luminance.attr, |
| 1183 | &dev_attr_status1_luminance.attr, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1184 | &dev_attr_status_led0_select.attr, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1185 | &dev_attr_buttons_luminance.attr, |
| 1186 | &dev_attr_button0_rawimg.attr, |
| 1187 | &dev_attr_button1_rawimg.attr, |
| 1188 | &dev_attr_button2_rawimg.attr, |
| 1189 | &dev_attr_button3_rawimg.attr, |
| 1190 | &dev_attr_button4_rawimg.attr, |
| 1191 | &dev_attr_button5_rawimg.attr, |
| 1192 | &dev_attr_button6_rawimg.attr, |
| 1193 | &dev_attr_button7_rawimg.attr, |
| 1194 | NULL |
| 1195 | }; |
| 1196 | |
Rikard Falkeborn | 2a6a35a | 2020-11-25 00:01:09 +0100 | [diff] [blame] | 1197 | static const struct attribute_group intuos4_led_attr_group = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1198 | .name = "wacom_led", |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1199 | .attrs = intuos4_led_attrs, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1200 | }; |
| 1201 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1202 | static struct attribute *intuos5_led_attrs[] = { |
| 1203 | &dev_attr_status0_luminance.attr, |
| 1204 | &dev_attr_status_led0_select.attr, |
| 1205 | NULL |
| 1206 | }; |
| 1207 | |
Rikard Falkeborn | 2a6a35a | 2020-11-25 00:01:09 +0100 | [diff] [blame] | 1208 | static const struct attribute_group intuos5_led_attr_group = { |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1209 | .name = "wacom_led", |
| 1210 | .attrs = intuos5_led_attrs, |
| 1211 | }; |
| 1212 | |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 1213 | static struct attribute *generic_led_attrs[] = { |
| 1214 | &dev_attr_status0_luminance.attr, |
| 1215 | &dev_attr_status_led0_select.attr, |
| 1216 | NULL |
| 1217 | }; |
| 1218 | |
Rikard Falkeborn | 2a6a35a | 2020-11-25 00:01:09 +0100 | [diff] [blame] | 1219 | static const struct attribute_group generic_led_attr_group = { |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 1220 | .name = "wacom_led", |
| 1221 | .attrs = generic_led_attrs, |
| 1222 | }; |
| 1223 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1224 | struct wacom_sysfs_group_devres { |
Rikard Falkeborn | 2a6a35a | 2020-11-25 00:01:09 +0100 | [diff] [blame] | 1225 | const struct attribute_group *group; |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1226 | struct kobject *root; |
| 1227 | }; |
| 1228 | |
| 1229 | static void wacom_devm_sysfs_group_release(struct device *dev, void *res) |
| 1230 | { |
| 1231 | struct wacom_sysfs_group_devres *devres = res; |
| 1232 | struct kobject *kobj = devres->root; |
| 1233 | |
| 1234 | dev_dbg(dev, "%s: dropping reference to %s\n", |
| 1235 | __func__, devres->group->name); |
| 1236 | sysfs_remove_group(kobj, devres->group); |
| 1237 | } |
| 1238 | |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1239 | static int __wacom_devm_sysfs_create_group(struct wacom *wacom, |
| 1240 | struct kobject *root, |
Rikard Falkeborn | 2a6a35a | 2020-11-25 00:01:09 +0100 | [diff] [blame] | 1241 | const struct attribute_group *group) |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1242 | { |
| 1243 | struct wacom_sysfs_group_devres *devres; |
| 1244 | int error; |
| 1245 | |
| 1246 | devres = devres_alloc(wacom_devm_sysfs_group_release, |
| 1247 | sizeof(struct wacom_sysfs_group_devres), |
| 1248 | GFP_KERNEL); |
| 1249 | if (!devres) |
| 1250 | return -ENOMEM; |
| 1251 | |
| 1252 | devres->group = group; |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1253 | devres->root = root; |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1254 | |
| 1255 | error = sysfs_create_group(devres->root, group); |
Arvind Yadav | 097b8f6 | 2018-04-24 13:33:03 +0530 | [diff] [blame] | 1256 | if (error) { |
| 1257 | devres_free(devres); |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1258 | return error; |
Arvind Yadav | 097b8f6 | 2018-04-24 13:33:03 +0530 | [diff] [blame] | 1259 | } |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1260 | |
| 1261 | devres_add(&wacom->hdev->dev, devres); |
| 1262 | |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1266 | static int wacom_devm_sysfs_create_group(struct wacom *wacom, |
Rikard Falkeborn | 2a6a35a | 2020-11-25 00:01:09 +0100 | [diff] [blame] | 1267 | const struct attribute_group *group) |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1268 | { |
| 1269 | return __wacom_devm_sysfs_create_group(wacom, &wacom->hdev->dev.kobj, |
| 1270 | group); |
| 1271 | } |
| 1272 | |
Ping Cheng | 37309f4 | 2020-12-09 20:52:30 -0800 | [diff] [blame] | 1273 | static void wacom_devm_kfifo_release(struct device *dev, void *res) |
| 1274 | { |
| 1275 | struct kfifo_rec_ptr_2 *devres = res; |
| 1276 | |
| 1277 | kfifo_free(devres); |
| 1278 | } |
| 1279 | |
| 1280 | static int wacom_devm_kfifo_alloc(struct wacom *wacom) |
| 1281 | { |
| 1282 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
Jason Gerecke | 179e8e4 | 2021-01-21 10:46:49 -0800 | [diff] [blame] | 1283 | struct kfifo_rec_ptr_2 *pen_fifo; |
Ping Cheng | 37309f4 | 2020-12-09 20:52:30 -0800 | [diff] [blame] | 1284 | int error; |
| 1285 | |
| 1286 | pen_fifo = devres_alloc(wacom_devm_kfifo_release, |
| 1287 | sizeof(struct kfifo_rec_ptr_2), |
| 1288 | GFP_KERNEL); |
| 1289 | |
| 1290 | if (!pen_fifo) |
| 1291 | return -ENOMEM; |
| 1292 | |
| 1293 | error = kfifo_alloc(pen_fifo, WACOM_PKGLEN_MAX, GFP_KERNEL); |
| 1294 | if (error) { |
| 1295 | devres_free(pen_fifo); |
| 1296 | return error; |
| 1297 | } |
| 1298 | |
| 1299 | devres_add(&wacom->hdev->dev, pen_fifo); |
Jason Gerecke | 179e8e4 | 2021-01-21 10:46:49 -0800 | [diff] [blame] | 1300 | wacom_wac->pen_fifo = pen_fifo; |
Ping Cheng | 37309f4 | 2020-12-09 20:52:30 -0800 | [diff] [blame] | 1301 | |
| 1302 | return 0; |
| 1303 | } |
| 1304 | |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1305 | enum led_brightness wacom_leds_brightness_get(struct wacom_led *led) |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1306 | { |
| 1307 | struct wacom *wacom = led->wacom; |
| 1308 | |
| 1309 | if (wacom->led.max_hlv) |
| 1310 | return led->hlv * LED_FULL / wacom->led.max_hlv; |
| 1311 | |
| 1312 | if (wacom->led.max_llv) |
| 1313 | return led->llv * LED_FULL / wacom->led.max_llv; |
| 1314 | |
| 1315 | /* device doesn't support brightness tuning */ |
| 1316 | return LED_FULL; |
| 1317 | } |
| 1318 | |
| 1319 | static enum led_brightness __wacom_led_brightness_get(struct led_classdev *cdev) |
| 1320 | { |
| 1321 | struct wacom_led *led = container_of(cdev, struct wacom_led, cdev); |
| 1322 | struct wacom *wacom = led->wacom; |
| 1323 | |
| 1324 | if (wacom->led.groups[led->group].select != led->id) |
| 1325 | return LED_OFF; |
| 1326 | |
| 1327 | return wacom_leds_brightness_get(led); |
| 1328 | } |
| 1329 | |
| 1330 | static int wacom_led_brightness_set(struct led_classdev *cdev, |
| 1331 | enum led_brightness brightness) |
| 1332 | { |
| 1333 | struct wacom_led *led = container_of(cdev, struct wacom_led, cdev); |
| 1334 | struct wacom *wacom = led->wacom; |
| 1335 | int error; |
| 1336 | |
| 1337 | mutex_lock(&wacom->lock); |
| 1338 | |
| 1339 | if (!wacom->led.groups || (brightness == LED_OFF && |
| 1340 | wacom->led.groups[led->group].select != led->id)) { |
| 1341 | error = 0; |
| 1342 | goto out; |
| 1343 | } |
| 1344 | |
| 1345 | led->llv = wacom->led.llv = wacom->led.max_llv * brightness / LED_FULL; |
| 1346 | led->hlv = wacom->led.hlv = wacom->led.max_hlv * brightness / LED_FULL; |
| 1347 | |
| 1348 | wacom->led.groups[led->group].select = led->id; |
| 1349 | |
| 1350 | error = wacom_led_control(wacom); |
| 1351 | |
| 1352 | out: |
| 1353 | mutex_unlock(&wacom->lock); |
| 1354 | |
| 1355 | return error; |
| 1356 | } |
| 1357 | |
| 1358 | static void wacom_led_readonly_brightness_set(struct led_classdev *cdev, |
| 1359 | enum led_brightness brightness) |
| 1360 | { |
| 1361 | } |
| 1362 | |
| 1363 | static int wacom_led_register_one(struct device *dev, struct wacom *wacom, |
| 1364 | struct wacom_led *led, unsigned int group, |
| 1365 | unsigned int id, bool read_only) |
| 1366 | { |
| 1367 | int error; |
| 1368 | char *name; |
| 1369 | |
| 1370 | name = devm_kasprintf(dev, GFP_KERNEL, |
| 1371 | "%s::wacom-%d.%d", |
| 1372 | dev_name(dev), |
| 1373 | group, |
| 1374 | id); |
| 1375 | if (!name) |
| 1376 | return -ENOMEM; |
| 1377 | |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1378 | if (!read_only) { |
| 1379 | led->trigger.name = name; |
| 1380 | error = devm_led_trigger_register(dev, &led->trigger); |
| 1381 | if (error) { |
| 1382 | hid_err(wacom->hdev, |
| 1383 | "failed to register LED trigger %s: %d\n", |
| 1384 | led->cdev.name, error); |
| 1385 | return error; |
| 1386 | } |
| 1387 | } |
| 1388 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1389 | led->group = group; |
| 1390 | led->id = id; |
| 1391 | led->wacom = wacom; |
| 1392 | led->llv = wacom->led.llv; |
| 1393 | led->hlv = wacom->led.hlv; |
| 1394 | led->cdev.name = name; |
| 1395 | led->cdev.max_brightness = LED_FULL; |
| 1396 | led->cdev.flags = LED_HW_PLUGGABLE; |
| 1397 | led->cdev.brightness_get = __wacom_led_brightness_get; |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1398 | if (!read_only) { |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1399 | led->cdev.brightness_set_blocking = wacom_led_brightness_set; |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1400 | led->cdev.default_trigger = led->cdev.name; |
| 1401 | } else { |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1402 | led->cdev.brightness_set = wacom_led_readonly_brightness_set; |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1403 | } |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1404 | |
| 1405 | error = devm_led_classdev_register(dev, &led->cdev); |
| 1406 | if (error) { |
| 1407 | hid_err(wacom->hdev, |
| 1408 | "failed to register LED %s: %d\n", |
| 1409 | led->cdev.name, error); |
| 1410 | led->cdev.name = NULL; |
| 1411 | return error; |
| 1412 | } |
| 1413 | |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
Benjamin Tissoires | 589e506 | 2016-07-13 18:06:11 +0200 | [diff] [blame] | 1417 | static void wacom_led_groups_release_one(void *data) |
| 1418 | { |
| 1419 | struct wacom_group_leds *group = data; |
| 1420 | |
| 1421 | devres_release_group(group->dev, group); |
| 1422 | } |
| 1423 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1424 | static int wacom_led_groups_alloc_and_register_one(struct device *dev, |
| 1425 | struct wacom *wacom, |
| 1426 | int group_id, int count, |
| 1427 | bool read_only) |
| 1428 | { |
| 1429 | struct wacom_led *leds; |
| 1430 | int i, error; |
| 1431 | |
| 1432 | if (group_id >= wacom->led.count || count <= 0) |
| 1433 | return -EINVAL; |
| 1434 | |
| 1435 | if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL)) |
| 1436 | return -ENOMEM; |
| 1437 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 1438 | leds = devm_kcalloc(dev, count, sizeof(struct wacom_led), GFP_KERNEL); |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1439 | if (!leds) { |
| 1440 | error = -ENOMEM; |
| 1441 | goto err; |
| 1442 | } |
| 1443 | |
| 1444 | wacom->led.groups[group_id].leds = leds; |
| 1445 | wacom->led.groups[group_id].count = count; |
| 1446 | |
| 1447 | for (i = 0; i < count; i++) { |
| 1448 | error = wacom_led_register_one(dev, wacom, &leds[i], |
| 1449 | group_id, i, read_only); |
| 1450 | if (error) |
| 1451 | goto err; |
| 1452 | } |
| 1453 | |
Benjamin Tissoires | 589e506 | 2016-07-13 18:06:11 +0200 | [diff] [blame] | 1454 | wacom->led.groups[group_id].dev = dev; |
| 1455 | |
| 1456 | devres_close_group(dev, &wacom->led.groups[group_id]); |
| 1457 | |
| 1458 | /* |
| 1459 | * There is a bug (?) in devm_led_classdev_register() in which its |
| 1460 | * increments the refcount of the parent. If the parent is an input |
| 1461 | * device, that means the ref count never reaches 0 when |
| 1462 | * devm_input_device_release() gets called. |
| 1463 | * This means that the LEDs are still there after disconnect. |
| 1464 | * Manually force the release of the group so that the leds are released |
| 1465 | * once we are done using them. |
| 1466 | */ |
| 1467 | error = devm_add_action_or_reset(&wacom->hdev->dev, |
| 1468 | wacom_led_groups_release_one, |
| 1469 | &wacom->led.groups[group_id]); |
| 1470 | if (error) |
| 1471 | return error; |
| 1472 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1473 | return 0; |
| 1474 | |
| 1475 | err: |
| 1476 | devres_release_group(dev, &wacom->led.groups[group_id]); |
| 1477 | return error; |
| 1478 | } |
| 1479 | |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1480 | struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group_id, |
| 1481 | unsigned int id) |
| 1482 | { |
| 1483 | struct wacom_group_leds *group; |
| 1484 | |
| 1485 | if (group_id >= wacom->led.count) |
| 1486 | return NULL; |
| 1487 | |
| 1488 | group = &wacom->led.groups[group_id]; |
| 1489 | |
| 1490 | if (!group->leds) |
| 1491 | return NULL; |
| 1492 | |
| 1493 | id %= group->count; |
| 1494 | |
| 1495 | return &group->leds[id]; |
| 1496 | } |
| 1497 | |
| 1498 | /** |
| 1499 | * wacom_led_next: gives the next available led with a wacom trigger. |
| 1500 | * |
| 1501 | * returns the next available struct wacom_led which has its default trigger |
| 1502 | * or the current one if none is available. |
| 1503 | */ |
| 1504 | struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur) |
| 1505 | { |
| 1506 | struct wacom_led *next_led; |
| 1507 | int group, next; |
| 1508 | |
| 1509 | if (!wacom || !cur) |
| 1510 | return NULL; |
| 1511 | |
| 1512 | group = cur->group; |
| 1513 | next = cur->id; |
| 1514 | |
| 1515 | do { |
| 1516 | next_led = wacom_led_find(wacom, group, ++next); |
| 1517 | if (!next_led || next_led == cur) |
| 1518 | return next_led; |
| 1519 | } while (next_led->cdev.trigger != &next_led->trigger); |
| 1520 | |
| 1521 | return next_led; |
| 1522 | } |
| 1523 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1524 | static void wacom_led_groups_release(void *data) |
| 1525 | { |
| 1526 | struct wacom *wacom = data; |
| 1527 | |
| 1528 | wacom->led.groups = NULL; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1529 | wacom->led.count = 0; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | static int wacom_led_groups_allocate(struct wacom *wacom, int count) |
| 1533 | { |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1534 | struct device *dev = &wacom->hdev->dev; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1535 | struct wacom_group_leds *groups; |
| 1536 | int error; |
| 1537 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 1538 | groups = devm_kcalloc(dev, count, sizeof(struct wacom_group_leds), |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1539 | GFP_KERNEL); |
| 1540 | if (!groups) |
| 1541 | return -ENOMEM; |
| 1542 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1543 | error = devm_add_action_or_reset(dev, wacom_led_groups_release, wacom); |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1544 | if (error) |
| 1545 | return error; |
| 1546 | |
| 1547 | wacom->led.groups = groups; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1548 | wacom->led.count = count; |
| 1549 | |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
| 1553 | static int wacom_leds_alloc_and_register(struct wacom *wacom, int group_count, |
| 1554 | int led_per_group, bool read_only) |
| 1555 | { |
| 1556 | struct device *dev; |
| 1557 | int i, error; |
| 1558 | |
| 1559 | if (!wacom->wacom_wac.pad_input) |
| 1560 | return -EINVAL; |
| 1561 | |
| 1562 | dev = &wacom->wacom_wac.pad_input->dev; |
| 1563 | |
| 1564 | error = wacom_led_groups_allocate(wacom, group_count); |
| 1565 | if (error) |
| 1566 | return error; |
| 1567 | |
| 1568 | for (i = 0; i < group_count; i++) { |
| 1569 | error = wacom_led_groups_alloc_and_register_one(dev, wacom, i, |
| 1570 | led_per_group, |
| 1571 | read_only); |
| 1572 | if (error) |
| 1573 | return error; |
| 1574 | } |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1575 | |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 1579 | int wacom_initialize_leds(struct wacom *wacom) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1580 | { |
| 1581 | int error; |
| 1582 | |
Jason Gerecke | 862cf55 | 2015-06-15 18:01:43 -0700 | [diff] [blame] | 1583 | if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD)) |
| 1584 | return 0; |
| 1585 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1586 | /* Initialize default values */ |
| 1587 | switch (wacom->wacom_wac.features.type) { |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 1588 | case HID_GENERIC: |
| 1589 | if (!wacom->generic_has_leds) |
| 1590 | return 0; |
| 1591 | wacom->led.llv = 100; |
| 1592 | wacom->led.max_llv = 100; |
| 1593 | |
| 1594 | error = wacom_leds_alloc_and_register(wacom, 1, 4, false); |
| 1595 | if (error) { |
| 1596 | hid_err(wacom->hdev, |
| 1597 | "cannot create leds err: %d\n", error); |
| 1598 | return error; |
| 1599 | } |
| 1600 | |
| 1601 | error = wacom_devm_sysfs_create_group(wacom, |
| 1602 | &generic_led_attr_group); |
| 1603 | break; |
| 1604 | |
Jason Gerecke | a19fc98 | 2012-06-12 00:27:53 -0700 | [diff] [blame] | 1605 | case INTUOS4S: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1606 | case INTUOS4: |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 1607 | case INTUOS4WL: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1608 | case INTUOS4L: |
Ping Cheng | f4fa9a6 | 2011-10-04 23:49:42 -0700 | [diff] [blame] | 1609 | wacom->led.llv = 10; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1610 | wacom->led.hlv = 20; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1611 | wacom->led.max_llv = 127; |
| 1612 | wacom->led.max_hlv = 127; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1613 | wacom->led.img_lum = 10; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1614 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1615 | error = wacom_leds_alloc_and_register(wacom, 1, 4, false); |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1616 | if (error) { |
| 1617 | hid_err(wacom->hdev, |
| 1618 | "cannot create leds err: %d\n", error); |
| 1619 | return error; |
| 1620 | } |
| 1621 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1622 | error = wacom_devm_sysfs_create_group(wacom, |
| 1623 | &intuos4_led_attr_group); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1624 | break; |
| 1625 | |
Jason Gerecke | 246835f | 2011-12-12 00:12:04 -0800 | [diff] [blame] | 1626 | case WACOM_24HD: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1627 | case WACOM_21UX2: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1628 | wacom->led.llv = 0; |
| 1629 | wacom->led.hlv = 0; |
| 1630 | wacom->led.img_lum = 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1631 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1632 | error = wacom_leds_alloc_and_register(wacom, 2, 4, false); |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1633 | if (error) { |
| 1634 | hid_err(wacom->hdev, |
| 1635 | "cannot create leds err: %d\n", error); |
| 1636 | return error; |
| 1637 | } |
| 1638 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1639 | error = wacom_devm_sysfs_create_group(wacom, |
| 1640 | &cintiq_led_attr_group); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1641 | break; |
| 1642 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1643 | case INTUOS5S: |
| 1644 | case INTUOS5: |
| 1645 | case INTUOS5L: |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 1646 | case INTUOSPS: |
| 1647 | case INTUOSPM: |
| 1648 | case INTUOSPL: |
Jason Gerecke | 862cf55 | 2015-06-15 18:01:43 -0700 | [diff] [blame] | 1649 | wacom->led.llv = 32; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1650 | wacom->led.max_llv = 96; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1651 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1652 | error = wacom_leds_alloc_and_register(wacom, 1, 4, false); |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1653 | if (error) { |
| 1654 | hid_err(wacom->hdev, |
| 1655 | "cannot create leds err: %d\n", error); |
| 1656 | return error; |
| 1657 | } |
| 1658 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1659 | error = wacom_devm_sysfs_create_group(wacom, |
| 1660 | &intuos5_led_attr_group); |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1661 | break; |
| 1662 | |
Jason Gerecke | 4922cd2 | 2017-01-25 12:08:37 -0800 | [diff] [blame] | 1663 | case INTUOSP2_BT: |
| 1664 | wacom->led.llv = 50; |
| 1665 | wacom->led.max_llv = 100; |
| 1666 | error = wacom_leds_alloc_and_register(wacom, 1, 4, false); |
| 1667 | if (error) { |
| 1668 | hid_err(wacom->hdev, |
| 1669 | "cannot create leds err: %d\n", error); |
| 1670 | return error; |
| 1671 | } |
| 1672 | return 0; |
| 1673 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1674 | case REMOTE: |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1675 | wacom->led.llv = 255; |
| 1676 | wacom->led.max_llv = 255; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1677 | error = wacom_led_groups_allocate(wacom, 5); |
| 1678 | if (error) { |
| 1679 | hid_err(wacom->hdev, |
| 1680 | "cannot create leds err: %d\n", error); |
| 1681 | return error; |
| 1682 | } |
| 1683 | return 0; |
| 1684 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1685 | default: |
| 1686 | return 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1689 | if (error) { |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 1690 | hid_err(wacom->hdev, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1691 | "cannot create sysfs group err: %d\n", error); |
| 1692 | return error; |
| 1693 | } |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1694 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1695 | return 0; |
| 1696 | } |
| 1697 | |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 1698 | static void wacom_init_work(struct work_struct *work) |
| 1699 | { |
| 1700 | struct wacom *wacom = container_of(work, struct wacom, init_work.work); |
| 1701 | |
| 1702 | _wacom_query_tablet_data(wacom); |
| 1703 | wacom_led_control(wacom); |
| 1704 | } |
| 1705 | |
| 1706 | static void wacom_query_tablet_data(struct wacom *wacom) |
| 1707 | { |
| 1708 | schedule_delayed_work(&wacom->init_work, msecs_to_jiffies(1000)); |
| 1709 | } |
| 1710 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1711 | static enum power_supply_property wacom_battery_props[] = { |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 1712 | POWER_SUPPLY_PROP_MODEL_NAME, |
Jason Gerecke | 71fa641 | 2015-03-11 10:25:41 -0700 | [diff] [blame] | 1713 | POWER_SUPPLY_PROP_PRESENT, |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1714 | POWER_SUPPLY_PROP_STATUS, |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 1715 | POWER_SUPPLY_PROP_SCOPE, |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1716 | POWER_SUPPLY_PROP_CAPACITY |
| 1717 | }; |
| 1718 | |
| 1719 | static int wacom_battery_get_property(struct power_supply *psy, |
| 1720 | enum power_supply_property psp, |
| 1721 | union power_supply_propval *val) |
| 1722 | { |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1723 | struct wacom_battery *battery = power_supply_get_drvdata(psy); |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1724 | int ret = 0; |
| 1725 | |
| 1726 | switch (psp) { |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 1727 | case POWER_SUPPLY_PROP_MODEL_NAME: |
| 1728 | val->strval = battery->wacom->wacom_wac.name; |
| 1729 | break; |
Jason Gerecke | 71fa641 | 2015-03-11 10:25:41 -0700 | [diff] [blame] | 1730 | case POWER_SUPPLY_PROP_PRESENT: |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1731 | val->intval = battery->bat_connected; |
Jason Gerecke | 71fa641 | 2015-03-11 10:25:41 -0700 | [diff] [blame] | 1732 | break; |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 1733 | case POWER_SUPPLY_PROP_SCOPE: |
| 1734 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 1735 | break; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1736 | case POWER_SUPPLY_PROP_CAPACITY: |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1737 | val->intval = battery->battery_capacity; |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1738 | break; |
| 1739 | case POWER_SUPPLY_PROP_STATUS: |
Jason Gerecke | 16e4598 | 2017-04-28 09:25:33 -0700 | [diff] [blame] | 1740 | if (battery->bat_status != WACOM_POWER_SUPPLY_STATUS_AUTO) |
| 1741 | val->intval = battery->bat_status; |
| 1742 | else if (battery->bat_charging) |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1743 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1744 | else if (battery->battery_capacity == 100 && |
| 1745 | battery->ps_connected) |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1746 | val->intval = POWER_SUPPLY_STATUS_FULL; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1747 | else if (battery->ps_connected) |
Jason Gerecke | b0882cb | 2015-03-06 11:47:43 -0800 | [diff] [blame] | 1748 | val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1749 | else |
| 1750 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1751 | break; |
| 1752 | default: |
| 1753 | ret = -EINVAL; |
| 1754 | break; |
| 1755 | } |
| 1756 | |
| 1757 | return ret; |
| 1758 | } |
| 1759 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1760 | static int __wacom_initialize_battery(struct wacom *wacom, |
| 1761 | struct wacom_battery *battery) |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1762 | { |
Benjamin Tissoires | d70420b9 | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 1763 | static atomic_t battery_no = ATOMIC_INIT(0); |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1764 | struct device *dev = &wacom->hdev->dev; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1765 | struct power_supply_config psy_cfg = { .drv_data = battery, }; |
Benjamin Tissoires | 136ae5e | 2016-07-13 18:06:16 +0200 | [diff] [blame] | 1766 | struct power_supply *ps_bat; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1767 | struct power_supply_desc *bat_desc = &battery->bat_desc; |
Benjamin Tissoires | d70420b9 | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 1768 | unsigned long n; |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1769 | int error; |
| 1770 | |
| 1771 | if (!devres_open_group(dev, bat_desc, GFP_KERNEL)) |
| 1772 | return -ENOMEM; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1773 | |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 1774 | battery->wacom = wacom; |
| 1775 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1776 | n = atomic_inc_return(&battery_no) - 1; |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1777 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1778 | bat_desc->properties = wacom_battery_props; |
| 1779 | bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props); |
| 1780 | bat_desc->get_property = wacom_battery_get_property; |
| 1781 | sprintf(battery->bat_name, "wacom_battery_%ld", n); |
| 1782 | bat_desc->name = battery->bat_name; |
Benjamin Tissoires | 9698329 | 2016-07-13 18:06:15 +0200 | [diff] [blame] | 1783 | bat_desc->type = POWER_SUPPLY_TYPE_USB; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1784 | bat_desc->use_for_apm = 0; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1785 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1786 | ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg); |
| 1787 | if (IS_ERR(ps_bat)) { |
| 1788 | error = PTR_ERR(ps_bat); |
| 1789 | goto err; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1792 | power_supply_powers(ps_bat, &wacom->hdev->dev); |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1793 | |
| 1794 | battery->battery = ps_bat; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1795 | |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1796 | devres_close_group(dev, bat_desc); |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1797 | return 0; |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1798 | |
| 1799 | err: |
| 1800 | devres_release_group(dev, bat_desc); |
| 1801 | return error; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1804 | static int wacom_initialize_battery(struct wacom *wacom) |
| 1805 | { |
| 1806 | if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) |
| 1807 | return __wacom_initialize_battery(wacom, &wacom->battery); |
| 1808 | |
| 1809 | return 0; |
| 1810 | } |
| 1811 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1812 | static void wacom_destroy_battery(struct wacom *wacom) |
| 1813 | { |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1814 | if (wacom->battery.battery) { |
| 1815 | devres_release_group(&wacom->hdev->dev, |
| 1816 | &wacom->battery.bat_desc); |
| 1817 | wacom->battery.battery = NULL; |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1818 | } |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1821 | static ssize_t wacom_show_speed(struct device *dev, |
| 1822 | struct device_attribute |
| 1823 | *attr, char *buf) |
| 1824 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1825 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1826 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1827 | |
Jiapeng Chong | d883312 | 2021-02-02 16:19:00 +0800 | [diff] [blame^] | 1828 | return sysfs_emit(buf, "%i\n", wacom->wacom_wac.bt_high_speed); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | static ssize_t wacom_store_speed(struct device *dev, |
| 1832 | struct device_attribute *attr, |
| 1833 | const char *buf, size_t count) |
| 1834 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1835 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1836 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1837 | u8 new_speed; |
| 1838 | |
| 1839 | if (kstrtou8(buf, 0, &new_speed)) |
| 1840 | return -EINVAL; |
| 1841 | |
| 1842 | if (new_speed != 0 && new_speed != 1) |
| 1843 | return -EINVAL; |
| 1844 | |
| 1845 | wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features); |
| 1846 | |
| 1847 | return count; |
| 1848 | } |
| 1849 | |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 1850 | static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM, |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1851 | wacom_show_speed, wacom_store_speed); |
| 1852 | |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1853 | |
| 1854 | static ssize_t wacom_show_remote_mode(struct kobject *kobj, |
| 1855 | struct kobj_attribute *kattr, |
| 1856 | char *buf, int index) |
| 1857 | { |
Geliang Tang | 2cf8383 | 2015-12-27 17:25:24 +0800 | [diff] [blame] | 1858 | struct device *dev = kobj_to_dev(kobj->parent); |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1859 | struct hid_device *hdev = to_hid_device(dev); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1860 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1861 | u8 mode; |
| 1862 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1863 | mode = wacom->led.groups[index].select; |
Christos Gkekas | bc35f73 | 2017-07-08 20:25:48 +0100 | [diff] [blame] | 1864 | return sprintf(buf, "%d\n", mode < 3 ? mode : -1); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | #define DEVICE_EKR_ATTR_GROUP(SET_ID) \ |
| 1868 | static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \ |
| 1869 | struct kobj_attribute *kattr, char *buf) \ |
| 1870 | { \ |
| 1871 | return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \ |
| 1872 | } \ |
| 1873 | static struct kobj_attribute remote##SET_ID##_mode_attr = { \ |
| 1874 | .attr = {.name = "remote_mode", \ |
| 1875 | .mode = DEV_ATTR_RO_PERM}, \ |
| 1876 | .show = wacom_show_remote##SET_ID##_mode, \ |
| 1877 | }; \ |
| 1878 | static struct attribute *remote##SET_ID##_serial_attrs[] = { \ |
| 1879 | &remote##SET_ID##_mode_attr.attr, \ |
| 1880 | NULL \ |
| 1881 | }; \ |
Rikard Falkeborn | 2a6a35a | 2020-11-25 00:01:09 +0100 | [diff] [blame] | 1882 | static const struct attribute_group remote##SET_ID##_serial_group = { \ |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1883 | .name = NULL, \ |
| 1884 | .attrs = remote##SET_ID##_serial_attrs, \ |
| 1885 | } |
| 1886 | |
| 1887 | DEVICE_EKR_ATTR_GROUP(0); |
| 1888 | DEVICE_EKR_ATTR_GROUP(1); |
| 1889 | DEVICE_EKR_ATTR_GROUP(2); |
| 1890 | DEVICE_EKR_ATTR_GROUP(3); |
| 1891 | DEVICE_EKR_ATTR_GROUP(4); |
| 1892 | |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1893 | static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, |
| 1894 | int index) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1895 | { |
| 1896 | int error = 0; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1897 | struct wacom_remote *remote = wacom->remote; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1898 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1899 | remote->remotes[index].group.name = devm_kasprintf(&wacom->hdev->dev, |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1900 | GFP_KERNEL, |
| 1901 | "%d", serial); |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1902 | if (!remote->remotes[index].group.name) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1903 | return -ENOMEM; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1904 | |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1905 | error = __wacom_devm_sysfs_create_group(wacom, remote->remote_dir, |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1906 | &remote->remotes[index].group); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1907 | if (error) { |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1908 | remote->remotes[index].group.name = NULL; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1909 | hid_err(wacom->hdev, |
| 1910 | "cannot create sysfs group err: %d\n", error); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1911 | return error; |
| 1912 | } |
| 1913 | |
| 1914 | return 0; |
| 1915 | } |
| 1916 | |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1917 | static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) |
| 1918 | { |
| 1919 | const size_t buf_size = 2; |
| 1920 | unsigned char *buf; |
| 1921 | int retval; |
| 1922 | |
| 1923 | buf = kzalloc(buf_size, GFP_KERNEL); |
| 1924 | if (!buf) |
| 1925 | return -ENOMEM; |
| 1926 | |
| 1927 | buf[0] = WAC_CMD_DELETE_PAIRING; |
| 1928 | buf[1] = selector; |
| 1929 | |
| 1930 | retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf, |
| 1931 | buf_size, WAC_CMD_RETRIES); |
| 1932 | kfree(buf); |
| 1933 | |
| 1934 | return retval; |
| 1935 | } |
| 1936 | |
| 1937 | static ssize_t wacom_store_unpair_remote(struct kobject *kobj, |
| 1938 | struct kobj_attribute *attr, |
| 1939 | const char *buf, size_t count) |
| 1940 | { |
| 1941 | unsigned char selector = 0; |
Geliang Tang | 2cf8383 | 2015-12-27 17:25:24 +0800 | [diff] [blame] | 1942 | struct device *dev = kobj_to_dev(kobj->parent); |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1943 | struct hid_device *hdev = to_hid_device(dev); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1944 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1945 | int err; |
| 1946 | |
| 1947 | if (!strncmp(buf, "*\n", 2)) { |
| 1948 | selector = WAC_CMD_UNPAIR_ALL; |
| 1949 | } else { |
| 1950 | hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n", |
| 1951 | buf); |
| 1952 | return -1; |
| 1953 | } |
| 1954 | |
| 1955 | mutex_lock(&wacom->lock); |
| 1956 | |
| 1957 | err = wacom_cmd_unpair_remote(wacom, selector); |
| 1958 | mutex_unlock(&wacom->lock); |
| 1959 | |
| 1960 | return err < 0 ? err : count; |
| 1961 | } |
| 1962 | |
| 1963 | static struct kobj_attribute unpair_remote_attr = { |
| 1964 | .attr = {.name = "unpair_remote", .mode = 0200}, |
| 1965 | .store = wacom_store_unpair_remote, |
| 1966 | }; |
| 1967 | |
| 1968 | static const struct attribute *remote_unpair_attrs[] = { |
| 1969 | &unpair_remote_attr.attr, |
| 1970 | NULL |
| 1971 | }; |
| 1972 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1973 | static void wacom_remotes_destroy(void *data) |
| 1974 | { |
| 1975 | struct wacom *wacom = data; |
| 1976 | struct wacom_remote *remote = wacom->remote; |
| 1977 | |
| 1978 | if (!remote) |
| 1979 | return; |
| 1980 | |
| 1981 | kobject_put(remote->remote_dir); |
| 1982 | kfifo_free(&remote->remote_fifo); |
| 1983 | wacom->remote = NULL; |
| 1984 | } |
| 1985 | |
| 1986 | static int wacom_initialize_remotes(struct wacom *wacom) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1987 | { |
| 1988 | int error = 0; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1989 | struct wacom_remote *remote; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1990 | int i; |
| 1991 | |
| 1992 | if (wacom->wacom_wac.features.type != REMOTE) |
| 1993 | return 0; |
| 1994 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1995 | remote = devm_kzalloc(&wacom->hdev->dev, sizeof(*wacom->remote), |
| 1996 | GFP_KERNEL); |
| 1997 | if (!remote) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1998 | return -ENOMEM; |
| 1999 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2000 | wacom->remote = remote; |
| 2001 | |
| 2002 | spin_lock_init(&remote->remote_lock); |
| 2003 | |
| 2004 | error = kfifo_alloc(&remote->remote_fifo, |
| 2005 | 5 * sizeof(struct wacom_remote_data), |
| 2006 | GFP_KERNEL); |
| 2007 | if (error) { |
| 2008 | hid_err(wacom->hdev, "failed allocating remote_fifo\n"); |
| 2009 | return -ENOMEM; |
| 2010 | } |
| 2011 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2012 | remote->remotes[0].group = remote0_serial_group; |
| 2013 | remote->remotes[1].group = remote1_serial_group; |
| 2014 | remote->remotes[2].group = remote2_serial_group; |
| 2015 | remote->remotes[3].group = remote3_serial_group; |
| 2016 | remote->remotes[4].group = remote4_serial_group; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2017 | |
| 2018 | remote->remote_dir = kobject_create_and_add("wacom_remote", |
| 2019 | &wacom->hdev->dev.kobj); |
| 2020 | if (!remote->remote_dir) |
| 2021 | return -ENOMEM; |
| 2022 | |
| 2023 | error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 2024 | |
| 2025 | if (error) { |
| 2026 | hid_err(wacom->hdev, |
| 2027 | "cannot create sysfs group err: %d\n", error); |
| 2028 | return error; |
| 2029 | } |
| 2030 | |
| 2031 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 2032 | wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2033 | remote->remotes[i].serial = 0; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2036 | error = devm_add_action_or_reset(&wacom->hdev->dev, |
| 2037 | wacom_remotes_destroy, wacom); |
| 2038 | if (error) |
| 2039 | return error; |
| 2040 | |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 2041 | return 0; |
| 2042 | } |
| 2043 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2044 | static struct input_dev *wacom_allocate_input(struct wacom *wacom) |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 2045 | { |
| 2046 | struct input_dev *input_dev; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 2047 | struct hid_device *hdev = wacom->hdev; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 2048 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 2049 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 2050 | input_dev = devm_input_allocate_device(&hdev->dev); |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2051 | if (!input_dev) |
| 2052 | return NULL; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 2053 | |
Jason Gerecke | 2bdd163 | 2015-07-13 18:03:45 -0700 | [diff] [blame] | 2054 | input_dev->name = wacom_wac->features.name; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 2055 | input_dev->phys = hdev->phys; |
| 2056 | input_dev->dev.parent = &hdev->dev; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 2057 | input_dev->open = wacom_open; |
| 2058 | input_dev->close = wacom_close; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 2059 | input_dev->uniq = hdev->uniq; |
| 2060 | input_dev->id.bustype = hdev->bus; |
| 2061 | input_dev->id.vendor = hdev->vendor; |
Benjamin Tissoires | 12969e3 | 2014-09-11 13:14:04 -0400 | [diff] [blame] | 2062 | input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 2063 | input_dev->id.version = hdev->version; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 2064 | input_set_drvdata(input_dev, wacom); |
| 2065 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2066 | return input_dev; |
| 2067 | } |
| 2068 | |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 2069 | static int wacom_allocate_inputs(struct wacom *wacom) |
| 2070 | { |
| 2071 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
| 2072 | |
| 2073 | wacom_wac->pen_input = wacom_allocate_input(wacom); |
| 2074 | wacom_wac->touch_input = wacom_allocate_input(wacom); |
| 2075 | wacom_wac->pad_input = wacom_allocate_input(wacom); |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 2076 | if (!wacom_wac->pen_input || |
| 2077 | !wacom_wac->touch_input || |
| 2078 | !wacom_wac->pad_input) |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 2079 | return -ENOMEM; |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 2080 | |
Jason Gerecke | 2bdd163 | 2015-07-13 18:03:45 -0700 | [diff] [blame] | 2081 | wacom_wac->pen_input->name = wacom_wac->pen_name; |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 2082 | wacom_wac->touch_input->name = wacom_wac->touch_name; |
| 2083 | wacom_wac->pad_input->name = wacom_wac->pad_name; |
| 2084 | |
| 2085 | return 0; |
| 2086 | } |
| 2087 | |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 2088 | static int wacom_register_inputs(struct wacom *wacom) |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2089 | { |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2090 | struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2091 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
Jason Gerecke | 2636a3f | 2015-06-15 18:01:44 -0700 | [diff] [blame] | 2092 | int error = 0; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2093 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2094 | pen_input_dev = wacom_wac->pen_input; |
| 2095 | touch_input_dev = wacom_wac->touch_input; |
Benjamin Tissoires | 2546dac | 2014-09-23 12:08:06 -0400 | [diff] [blame] | 2096 | pad_input_dev = wacom_wac->pad_input; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2097 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2098 | if (!pen_input_dev || !touch_input_dev || !pad_input_dev) |
Benjamin Tissoires | 2546dac | 2014-09-23 12:08:06 -0400 | [diff] [blame] | 2099 | return -EINVAL; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2100 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2101 | error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac); |
| 2102 | if (error) { |
| 2103 | /* no pen in use on this interface */ |
| 2104 | input_free_device(pen_input_dev); |
| 2105 | wacom_wac->pen_input = NULL; |
| 2106 | pen_input_dev = NULL; |
| 2107 | } else { |
| 2108 | error = input_register_device(pen_input_dev); |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 2109 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 2110 | goto fail; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac); |
| 2114 | if (error) { |
| 2115 | /* no touch in use on this interface */ |
| 2116 | input_free_device(touch_input_dev); |
| 2117 | wacom_wac->touch_input = NULL; |
| 2118 | touch_input_dev = NULL; |
| 2119 | } else { |
| 2120 | error = input_register_device(touch_input_dev); |
| 2121 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 2122 | goto fail; |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 2123 | } |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 2124 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2125 | error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac); |
| 2126 | if (error) { |
| 2127 | /* no pad in use on this interface */ |
| 2128 | input_free_device(pad_input_dev); |
| 2129 | wacom_wac->pad_input = NULL; |
| 2130 | pad_input_dev = NULL; |
| 2131 | } else { |
| 2132 | error = input_register_device(pad_input_dev); |
| 2133 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 2134 | goto fail; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 2137 | return 0; |
| 2138 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 2139 | fail: |
| 2140 | wacom_wac->pad_input = NULL; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2141 | wacom_wac->touch_input = NULL; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2142 | wacom_wac->pen_input = NULL; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 2143 | return error; |
| 2144 | } |
| 2145 | |
Jason Gerecke | 0be0171 | 2015-08-05 15:44:53 -0700 | [diff] [blame] | 2146 | /* |
| 2147 | * Not all devices report physical dimensions from HID. |
| 2148 | * Compute the default from hardcoded logical dimension |
| 2149 | * and resolution before driver overwrites them. |
| 2150 | */ |
| 2151 | static void wacom_set_default_phy(struct wacom_features *features) |
| 2152 | { |
| 2153 | if (features->x_resolution) { |
| 2154 | features->x_phy = (features->x_max * 100) / |
| 2155 | features->x_resolution; |
| 2156 | features->y_phy = (features->y_max * 100) / |
| 2157 | features->y_resolution; |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | static void wacom_calculate_res(struct wacom_features *features) |
| 2162 | { |
| 2163 | /* set unit to "100th of a mm" for devices not reported by HID */ |
| 2164 | if (!features->unit) { |
| 2165 | features->unit = 0x11; |
| 2166 | features->unitExpo = -3; |
| 2167 | } |
| 2168 | |
| 2169 | features->x_resolution = wacom_calc_hid_res(features->x_max, |
| 2170 | features->x_phy, |
| 2171 | features->unit, |
| 2172 | features->unitExpo); |
| 2173 | features->y_resolution = wacom_calc_hid_res(features->y_max, |
| 2174 | features->y_phy, |
| 2175 | features->unit, |
| 2176 | features->unitExpo); |
| 2177 | } |
| 2178 | |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 2179 | void wacom_battery_work(struct work_struct *work) |
| 2180 | { |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2181 | struct wacom *wacom = container_of(work, struct wacom, battery_work); |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 2182 | |
| 2183 | if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 2184 | !wacom->battery.battery) { |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 2185 | wacom_initialize_battery(wacom); |
| 2186 | } |
| 2187 | else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 2188 | wacom->battery.battery) { |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 2189 | wacom_destroy_battery(wacom); |
| 2190 | } |
| 2191 | } |
| 2192 | |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 2193 | static size_t wacom_compute_pktlen(struct hid_device *hdev) |
| 2194 | { |
| 2195 | struct hid_report_enum *report_enum; |
| 2196 | struct hid_report *report; |
| 2197 | size_t size = 0; |
| 2198 | |
| 2199 | report_enum = hdev->report_enum + HID_INPUT_REPORT; |
| 2200 | |
| 2201 | list_for_each_entry(report, &report_enum->report_list, list) { |
Mathieu Magnaudet | dabb05c6 | 2014-11-27 16:02:36 +0100 | [diff] [blame] | 2202 | size_t report_size = hid_report_len(report); |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 2203 | if (report_size > size) |
| 2204 | size = report_size; |
| 2205 | } |
| 2206 | |
| 2207 | return size; |
| 2208 | } |
| 2209 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2210 | static void wacom_update_name(struct wacom *wacom, const char *suffix) |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2211 | { |
| 2212 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2213 | struct wacom_features *features = &wacom_wac->features; |
Jason Gerecke | 073b50b | 2019-08-16 11:54:26 -0700 | [diff] [blame] | 2214 | char name[WACOM_NAME_MAX - 20]; /* Leave some room for suffixes */ |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2215 | |
| 2216 | /* Generic devices name unspecified */ |
| 2217 | if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) { |
Jason Gerecke | 09dc28a | 2017-07-24 09:46:19 -0700 | [diff] [blame] | 2218 | char *product_name = wacom->hdev->name; |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2219 | |
Jason Gerecke | 09dc28a | 2017-07-24 09:46:19 -0700 | [diff] [blame] | 2220 | if (hid_is_using_ll_driver(wacom->hdev, &usb_hid_driver)) { |
| 2221 | struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent); |
| 2222 | struct usb_device *dev = interface_to_usbdev(intf); |
| 2223 | product_name = dev->product; |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2224 | } |
Jason Gerecke | 09dc28a | 2017-07-24 09:46:19 -0700 | [diff] [blame] | 2225 | |
| 2226 | if (wacom->hdev->bus == BUS_I2C) { |
| 2227 | snprintf(name, sizeof(name), "%s %X", |
| 2228 | features->name, wacom->hdev->product); |
| 2229 | } else if (strstr(product_name, "Wacom") || |
| 2230 | strstr(product_name, "wacom") || |
| 2231 | strstr(product_name, "WACOM")) { |
| 2232 | strlcpy(name, product_name, sizeof(name)); |
| 2233 | } else { |
| 2234 | snprintf(name, sizeof(name), "Wacom %s", product_name); |
| 2235 | } |
| 2236 | |
| 2237 | /* strip out excess whitespaces */ |
| 2238 | while (1) { |
| 2239 | char *gap = strstr(name, " "); |
| 2240 | if (gap == NULL) |
| 2241 | break; |
| 2242 | /* shift everything including the terminator */ |
| 2243 | memmove(gap, gap+1, strlen(gap)); |
| 2244 | } |
| 2245 | |
| 2246 | /* get rid of trailing whitespace */ |
| 2247 | if (name[strlen(name)-1] == ' ') |
| 2248 | name[strlen(name)-1] = '\0'; |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2249 | } else { |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 2250 | strlcpy(name, features->name, sizeof(name)); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 2253 | snprintf(wacom_wac->name, sizeof(wacom_wac->name), "%s%s", |
| 2254 | name, suffix); |
| 2255 | |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2256 | /* Append the device type to the name */ |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2257 | snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2258 | "%s%s Pen", name, suffix); |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2259 | snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2260 | "%s%s Finger", name, suffix); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2261 | snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2262 | "%s%s Pad", name, suffix); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2265 | static void wacom_release_resources(struct wacom *wacom) |
| 2266 | { |
| 2267 | struct hid_device *hdev = wacom->hdev; |
| 2268 | |
| 2269 | if (!wacom->resources) |
| 2270 | return; |
| 2271 | |
| 2272 | devres_release_group(&hdev->dev, wacom); |
| 2273 | |
| 2274 | wacom->resources = false; |
| 2275 | |
| 2276 | wacom->wacom_wac.pen_input = NULL; |
| 2277 | wacom->wacom_wac.touch_input = NULL; |
| 2278 | wacom->wacom_wac.pad_input = NULL; |
| 2279 | } |
| 2280 | |
Aaron Armstrong Skomra | d2ec58a | 2017-01-25 12:08:41 -0800 | [diff] [blame] | 2281 | static void wacom_set_shared_values(struct wacom_wac *wacom_wac) |
| 2282 | { |
| 2283 | if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) { |
| 2284 | wacom_wac->shared->type = wacom_wac->features.type; |
| 2285 | wacom_wac->shared->touch_input = wacom_wac->touch_input; |
| 2286 | } |
| 2287 | |
Ping Cheng | d793ff8 | 2017-02-14 21:27:45 -0800 | [diff] [blame] | 2288 | if (wacom_wac->has_mute_touch_switch) { |
Aaron Armstrong Skomra | d2ec58a | 2017-01-25 12:08:41 -0800 | [diff] [blame] | 2289 | wacom_wac->shared->has_mute_touch_switch = true; |
Ping Cheng | d793ff8 | 2017-02-14 21:27:45 -0800 | [diff] [blame] | 2290 | wacom_wac->shared->is_touch_on = true; |
| 2291 | } |
Aaron Armstrong Skomra | d2ec58a | 2017-01-25 12:08:41 -0800 | [diff] [blame] | 2292 | |
| 2293 | if (wacom_wac->shared->has_mute_touch_switch && |
| 2294 | wacom_wac->shared->touch_input) { |
| 2295 | set_bit(EV_SW, wacom_wac->shared->touch_input->evbit); |
| 2296 | input_set_capability(wacom_wac->shared->touch_input, EV_SW, |
| 2297 | SW_MUTE_DEVICE); |
| 2298 | } |
| 2299 | } |
| 2300 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2301 | static int wacom_parse_and_register(struct wacom *wacom, bool wireless) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2302 | { |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2303 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2304 | struct wacom_features *features = &wacom_wac->features; |
| 2305 | struct hid_device *hdev = wacom->hdev; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 2306 | int error; |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2307 | unsigned int connect_mask = HID_CONNECT_HIDRAW; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2308 | |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 2309 | features->pktlen = wacom_compute_pktlen(hdev); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2310 | if (features->pktlen > WACOM_PKGLEN_MAX) |
| 2311 | return -EINVAL; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2312 | |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2313 | if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL)) |
| 2314 | return -ENOMEM; |
| 2315 | |
| 2316 | wacom->resources = true; |
| 2317 | |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 2318 | error = wacom_allocate_inputs(wacom); |
| 2319 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2320 | goto fail; |
Benjamin Tissoires | 494078b | 2014-09-23 12:08:07 -0400 | [diff] [blame] | 2321 | |
Benjamin Tissoires | 8c97a76 | 2015-02-26 11:28:50 -0500 | [diff] [blame] | 2322 | /* |
| 2323 | * Bamboo Pad has a generic hid handling for the Pen, and we switch it |
| 2324 | * into debug mode for the touch part. |
| 2325 | * We ignore the other interfaces. |
| 2326 | */ |
| 2327 | if (features->type == BAMBOO_PAD) { |
| 2328 | if (features->pktlen == WACOM_PKGLEN_PENABLED) { |
| 2329 | features->type = HID_GENERIC; |
| 2330 | } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) && |
| 2331 | (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) { |
| 2332 | error = -ENODEV; |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2333 | goto fail; |
Benjamin Tissoires | 8c97a76 | 2015-02-26 11:28:50 -0500 | [diff] [blame] | 2334 | } |
| 2335 | } |
| 2336 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 2337 | /* set the default size in case we do not get them from hid */ |
| 2338 | wacom_set_default_phy(features); |
| 2339 | |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 2340 | /* Retrieve the physical and logical size for touch devices */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 2341 | wacom_retrieve_hid_descriptor(hdev, features); |
Ping Cheng | 42f4f27 | 2015-04-15 16:53:54 -0700 | [diff] [blame] | 2342 | wacom_setup_device_quirks(wacom); |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 2343 | |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 2344 | if (features->device_type == WACOM_DEVICETYPE_NONE && |
| 2345 | features->type != WIRELESS) { |
Jason Gerecke | 8e116d3 | 2015-04-30 17:51:55 -0700 | [diff] [blame] | 2346 | error = features->type == HID_GENERIC ? -ENODEV : 0; |
| 2347 | |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 2348 | dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.", |
Jason Gerecke | 8e116d3 | 2015-04-30 17:51:55 -0700 | [diff] [blame] | 2349 | hdev->name, |
| 2350 | error ? "Ignoring" : "Assuming pen"); |
| 2351 | |
| 2352 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2353 | goto fail; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 2354 | |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 2355 | features->device_type |= WACOM_DEVICETYPE_PEN; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 2358 | wacom_calculate_res(features); |
| 2359 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2360 | wacom_update_name(wacom, wireless ? " (WL)" : ""); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 2361 | |
Aaron Armstrong Skomra | 8b40735 | 2017-03-29 10:35:39 -0700 | [diff] [blame] | 2362 | /* pen only Bamboo neither support touch nor pad */ |
| 2363 | if ((features->type == BAMBOO_PEN) && |
| 2364 | ((features->device_type & WACOM_DEVICETYPE_TOUCH) || |
| 2365 | (features->device_type & WACOM_DEVICETYPE_PAD))) { |
| 2366 | error = -ENODEV; |
| 2367 | goto fail; |
| 2368 | } |
| 2369 | |
Jason Gerecke | a9ce785 | 2017-01-17 15:38:58 -0800 | [diff] [blame] | 2370 | error = wacom_add_shared_data(hdev); |
| 2371 | if (error) |
| 2372 | goto fail; |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 2373 | |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 2374 | if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) && |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2375 | (features->quirks & WACOM_QUIRK_BATTERY)) { |
| 2376 | error = wacom_initialize_battery(wacom); |
| 2377 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2378 | goto fail; |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 2381 | error = wacom_register_inputs(wacom); |
| 2382 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2383 | goto fail; |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2384 | |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2385 | if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD) { |
Benjamin Tissoires | 85d2c77 | 2016-07-13 18:05:51 +0200 | [diff] [blame] | 2386 | error = wacom_initialize_leds(wacom); |
| 2387 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2388 | goto fail; |
Benjamin Tissoires | 85d2c77 | 2016-07-13 18:05:51 +0200 | [diff] [blame] | 2389 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2390 | error = wacom_initialize_remotes(wacom); |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2391 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2392 | goto fail; |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2393 | } |
| 2394 | |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2395 | if (features->type == HID_GENERIC) |
| 2396 | connect_mask |= HID_CONNECT_DRIVER; |
| 2397 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2398 | /* Regular HID work starts now */ |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2399 | error = hid_hw_start(hdev, connect_mask); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2400 | if (error) { |
| 2401 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2402 | goto fail; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2405 | if (!wireless) { |
| 2406 | /* Note that if query fails it is not a hard failure */ |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 2407 | wacom_query_tablet_data(wacom); |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2408 | } |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 2409 | |
| 2410 | /* touch only Bamboo doesn't support pen */ |
| 2411 | if ((features->type == BAMBOO_TOUCH) && |
| 2412 | (features->device_type & WACOM_DEVICETYPE_PEN)) { |
Aaron Armstrong Skomra | 4d20c33 | 2017-03-29 11:41:28 -0700 | [diff] [blame] | 2413 | cancel_delayed_work_sync(&wacom->init_work); |
| 2414 | _wacom_query_tablet_data(wacom); |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 2415 | error = -ENODEV; |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2416 | goto fail_quirks; |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 2417 | } |
| 2418 | |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 2419 | if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2420 | error = hid_hw_open(hdev); |
| 2421 | |
Aaron Armstrong Skomra | d2ec58a | 2017-01-25 12:08:41 -0800 | [diff] [blame] | 2422 | wacom_set_shared_values(wacom_wac); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2423 | devres_close_group(&hdev->dev, wacom); |
| 2424 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2425 | return 0; |
| 2426 | |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2427 | fail_quirks: |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2428 | hid_hw_stop(hdev); |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2429 | fail: |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2430 | wacom_release_resources(wacom); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2431 | return error; |
| 2432 | } |
| 2433 | |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2434 | static void wacom_wireless_work(struct work_struct *work) |
| 2435 | { |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2436 | struct wacom *wacom = container_of(work, struct wacom, wireless_work); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2437 | struct usb_device *usbdev = wacom->usbdev; |
| 2438 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2439 | struct hid_device *hdev1, *hdev2; |
| 2440 | struct wacom *wacom1, *wacom2; |
| 2441 | struct wacom_wac *wacom_wac1, *wacom_wac2; |
| 2442 | int error; |
| 2443 | |
| 2444 | /* |
| 2445 | * Regardless if this is a disconnect or a new tablet, |
| 2446 | * remove any existing input and battery devices. |
| 2447 | */ |
| 2448 | |
| 2449 | wacom_destroy_battery(wacom); |
| 2450 | |
| 2451 | /* Stylus interface */ |
| 2452 | hdev1 = usb_get_intfdata(usbdev->config->interface[1]); |
| 2453 | wacom1 = hid_get_drvdata(hdev1); |
| 2454 | wacom_wac1 = &(wacom1->wacom_wac); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2455 | wacom_release_resources(wacom1); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2456 | |
| 2457 | /* Touch interface */ |
| 2458 | hdev2 = usb_get_intfdata(usbdev->config->interface[2]); |
| 2459 | wacom2 = hid_get_drvdata(hdev2); |
| 2460 | wacom_wac2 = &(wacom2->wacom_wac); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2461 | wacom_release_resources(wacom2); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2462 | |
| 2463 | if (wacom_wac->pid == 0) { |
| 2464 | hid_info(wacom->hdev, "wireless tablet disconnected\n"); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2465 | } else { |
| 2466 | const struct hid_device_id *id = wacom_ids; |
| 2467 | |
| 2468 | hid_info(wacom->hdev, "wireless tablet connected with PID %x\n", |
| 2469 | wacom_wac->pid); |
| 2470 | |
| 2471 | while (id->bus) { |
| 2472 | if (id->vendor == USB_VENDOR_ID_WACOM && |
| 2473 | id->product == wacom_wac->pid) |
| 2474 | break; |
| 2475 | id++; |
| 2476 | } |
| 2477 | |
| 2478 | if (!id->bus) { |
| 2479 | hid_info(wacom->hdev, "ignoring unknown PID.\n"); |
| 2480 | return; |
| 2481 | } |
| 2482 | |
| 2483 | /* Stylus interface */ |
| 2484 | wacom_wac1->features = |
| 2485 | *((struct wacom_features *)id->driver_data); |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2486 | |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2487 | wacom_wac1->pid = wacom_wac->pid; |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2488 | hid_hw_stop(hdev1); |
| 2489 | error = wacom_parse_and_register(wacom1, true); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2490 | if (error) |
| 2491 | goto fail; |
| 2492 | |
| 2493 | /* Touch interface */ |
| 2494 | if (wacom_wac1->features.touch_max || |
| 2495 | (wacom_wac1->features.type >= INTUOSHT && |
| 2496 | wacom_wac1->features.type <= BAMBOO_PT)) { |
| 2497 | wacom_wac2->features = |
| 2498 | *((struct wacom_features *)id->driver_data); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2499 | wacom_wac2->pid = wacom_wac->pid; |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2500 | hid_hw_stop(hdev2); |
| 2501 | error = wacom_parse_and_register(wacom2, true); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2502 | if (error) |
| 2503 | goto fail; |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2504 | } |
| 2505 | |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 2506 | strlcpy(wacom_wac->name, wacom_wac1->name, |
| 2507 | sizeof(wacom_wac->name)); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2508 | error = wacom_initialize_battery(wacom); |
| 2509 | if (error) |
| 2510 | goto fail; |
| 2511 | } |
| 2512 | |
| 2513 | return; |
| 2514 | |
| 2515 | fail: |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2516 | wacom_release_resources(wacom1); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2517 | wacom_release_resources(wacom2); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2518 | return; |
| 2519 | } |
| 2520 | |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2521 | static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index) |
| 2522 | { |
| 2523 | struct wacom_remote *remote = wacom->remote; |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2524 | u32 serial = remote->remotes[index].serial; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2525 | int i; |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2526 | unsigned long flags; |
| 2527 | |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2528 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2529 | if (remote->remotes[i].serial == serial) { |
Aaron Armstrong Skomra | 791ae27 | 2017-12-07 12:31:56 -0800 | [diff] [blame] | 2530 | |
| 2531 | spin_lock_irqsave(&remote->remote_lock, flags); |
| 2532 | remote->remotes[i].registered = false; |
| 2533 | spin_unlock_irqrestore(&remote->remote_lock, flags); |
| 2534 | |
| 2535 | if (remote->remotes[i].battery.battery) |
| 2536 | devres_release_group(&wacom->hdev->dev, |
| 2537 | &remote->remotes[i].battery.bat_desc); |
| 2538 | |
| 2539 | if (remote->remotes[i].group.name) |
| 2540 | devres_release_group(&wacom->hdev->dev, |
| 2541 | &remote->remotes[i]); |
| 2542 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2543 | remote->remotes[i].serial = 0; |
| 2544 | remote->remotes[i].group.name = NULL; |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2545 | remote->remotes[i].battery.battery = NULL; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2546 | wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; |
| 2547 | } |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | static int wacom_remote_create_one(struct wacom *wacom, u32 serial, |
| 2552 | unsigned int index) |
| 2553 | { |
| 2554 | struct wacom_remote *remote = wacom->remote; |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2555 | struct device *dev = &wacom->hdev->dev; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2556 | int error, k; |
| 2557 | |
| 2558 | /* A remote can pair more than once with an EKR, |
| 2559 | * check to make sure this serial isn't already paired. |
| 2560 | */ |
| 2561 | for (k = 0; k < WACOM_MAX_REMOTES; k++) { |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2562 | if (remote->remotes[k].serial == serial) |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2563 | break; |
| 2564 | } |
| 2565 | |
| 2566 | if (k < WACOM_MAX_REMOTES) { |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2567 | remote->remotes[index].serial = serial; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2568 | return 0; |
| 2569 | } |
| 2570 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2571 | if (!devres_open_group(dev, &remote->remotes[index], GFP_KERNEL)) |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2572 | return -ENOMEM; |
| 2573 | |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2574 | error = wacom_remote_create_attr_group(wacom, serial, index); |
| 2575 | if (error) |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2576 | goto fail; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2577 | |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2578 | remote->remotes[index].input = wacom_allocate_input(wacom); |
| 2579 | if (!remote->remotes[index].input) { |
| 2580 | error = -ENOMEM; |
| 2581 | goto fail; |
| 2582 | } |
| 2583 | remote->remotes[index].input->uniq = remote->remotes[index].group.name; |
| 2584 | remote->remotes[index].input->name = wacom->wacom_wac.pad_name; |
| 2585 | |
| 2586 | if (!remote->remotes[index].input->name) { |
| 2587 | error = -EINVAL; |
| 2588 | goto fail; |
| 2589 | } |
| 2590 | |
| 2591 | error = wacom_setup_pad_input_capabilities(remote->remotes[index].input, |
| 2592 | &wacom->wacom_wac); |
| 2593 | if (error) |
| 2594 | goto fail; |
| 2595 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2596 | remote->remotes[index].serial = serial; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2597 | |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2598 | error = input_register_device(remote->remotes[index].input); |
| 2599 | if (error) |
| 2600 | goto fail; |
| 2601 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 2602 | error = wacom_led_groups_alloc_and_register_one( |
| 2603 | &remote->remotes[index].input->dev, |
| 2604 | wacom, index, 3, true); |
| 2605 | if (error) |
| 2606 | goto fail; |
| 2607 | |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2608 | remote->remotes[index].registered = true; |
| 2609 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2610 | devres_close_group(dev, &remote->remotes[index]); |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2611 | return 0; |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2612 | |
| 2613 | fail: |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2614 | devres_release_group(dev, &remote->remotes[index]); |
| 2615 | remote->remotes[index].serial = 0; |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2616 | return error; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2617 | } |
| 2618 | |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2619 | static int wacom_remote_attach_battery(struct wacom *wacom, int index) |
| 2620 | { |
| 2621 | struct wacom_remote *remote = wacom->remote; |
| 2622 | int error; |
| 2623 | |
| 2624 | if (!remote->remotes[index].registered) |
| 2625 | return 0; |
| 2626 | |
| 2627 | if (remote->remotes[index].battery.battery) |
| 2628 | return 0; |
| 2629 | |
| 2630 | if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN) |
| 2631 | return 0; |
| 2632 | |
| 2633 | error = __wacom_initialize_battery(wacom, |
| 2634 | &wacom->remote->remotes[index].battery); |
| 2635 | if (error) |
| 2636 | return error; |
| 2637 | |
| 2638 | return 0; |
| 2639 | } |
| 2640 | |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2641 | static void wacom_remote_work(struct work_struct *work) |
| 2642 | { |
| 2643 | struct wacom *wacom = container_of(work, struct wacom, remote_work); |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2644 | struct wacom_remote *remote = wacom->remote; |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2645 | struct wacom_remote_data data; |
| 2646 | unsigned long flags; |
| 2647 | unsigned int count; |
| 2648 | u32 serial; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2649 | int i; |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2650 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2651 | spin_lock_irqsave(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2652 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2653 | count = kfifo_out(&remote->remote_fifo, &data, sizeof(data)); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2654 | |
| 2655 | if (count != sizeof(data)) { |
| 2656 | hid_err(wacom->hdev, |
| 2657 | "workitem triggered without status available\n"); |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2658 | spin_unlock_irqrestore(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2659 | return; |
| 2660 | } |
| 2661 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2662 | if (!kfifo_is_empty(&remote->remote_fifo)) |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2663 | wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_REMOTE); |
| 2664 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2665 | spin_unlock_irqrestore(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2666 | |
| 2667 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
| 2668 | serial = data.remote[i].serial; |
| 2669 | if (data.remote[i].connected) { |
| 2670 | |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2671 | if (remote->remotes[i].serial == serial) { |
| 2672 | wacom_remote_attach_battery(wacom, i); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2673 | continue; |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2674 | } |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2675 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2676 | if (remote->remotes[i].serial) |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2677 | wacom_remote_destroy_one(wacom, i); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2678 | |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2679 | wacom_remote_create_one(wacom, serial, i); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2680 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2681 | } else if (remote->remotes[i].serial) { |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2682 | wacom_remote_destroy_one(wacom, i); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2683 | } |
| 2684 | } |
| 2685 | } |
| 2686 | |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 2687 | static void wacom_mode_change_work(struct work_struct *work) |
| 2688 | { |
| 2689 | struct wacom *wacom = container_of(work, struct wacom, mode_change_work); |
| 2690 | struct wacom_shared *shared = wacom->wacom_wac.shared; |
| 2691 | struct wacom *wacom1 = NULL; |
| 2692 | struct wacom *wacom2 = NULL; |
| 2693 | bool is_direct = wacom->wacom_wac.is_direct_mode; |
| 2694 | int error = 0; |
| 2695 | |
| 2696 | if (shared->pen) { |
| 2697 | wacom1 = hid_get_drvdata(shared->pen); |
| 2698 | wacom_release_resources(wacom1); |
| 2699 | hid_hw_stop(wacom1->hdev); |
| 2700 | wacom1->wacom_wac.has_mode_change = true; |
| 2701 | wacom1->wacom_wac.is_direct_mode = is_direct; |
| 2702 | } |
| 2703 | |
| 2704 | if (shared->touch) { |
| 2705 | wacom2 = hid_get_drvdata(shared->touch); |
| 2706 | wacom_release_resources(wacom2); |
| 2707 | hid_hw_stop(wacom2->hdev); |
| 2708 | wacom2->wacom_wac.has_mode_change = true; |
| 2709 | wacom2->wacom_wac.is_direct_mode = is_direct; |
| 2710 | } |
| 2711 | |
| 2712 | if (wacom1) { |
| 2713 | error = wacom_parse_and_register(wacom1, false); |
| 2714 | if (error) |
| 2715 | return; |
| 2716 | } |
| 2717 | |
| 2718 | if (wacom2) { |
| 2719 | error = wacom_parse_and_register(wacom2, false); |
| 2720 | if (error) |
| 2721 | return; |
| 2722 | } |
| 2723 | |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2724 | return; |
| 2725 | } |
| 2726 | |
| 2727 | static int wacom_probe(struct hid_device *hdev, |
| 2728 | const struct hid_device_id *id) |
| 2729 | { |
| 2730 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 2731 | struct usb_device *dev = interface_to_usbdev(intf); |
| 2732 | struct wacom *wacom; |
| 2733 | struct wacom_wac *wacom_wac; |
| 2734 | struct wacom_features *features; |
| 2735 | int error; |
| 2736 | |
| 2737 | if (!id->driver_data) |
| 2738 | return -EINVAL; |
| 2739 | |
| 2740 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
| 2741 | |
| 2742 | /* hid-core sets this quirk for the boot interface */ |
| 2743 | hdev->quirks &= ~HID_QUIRK_NOGET; |
| 2744 | |
Benjamin Tissoires | 19b6433 | 2016-07-13 18:05:58 +0200 | [diff] [blame] | 2745 | wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2746 | if (!wacom) |
| 2747 | return -ENOMEM; |
| 2748 | |
| 2749 | hid_set_drvdata(hdev, wacom); |
| 2750 | wacom->hdev = hdev; |
| 2751 | |
| 2752 | wacom_wac = &wacom->wacom_wac; |
| 2753 | wacom_wac->features = *((struct wacom_features *)id->driver_data); |
| 2754 | features = &wacom_wac->features; |
| 2755 | |
Benjamin Tissoires | 362c571 | 2019-08-12 18:27:40 +0200 | [diff] [blame] | 2756 | if (features->check_for_hid_type && features->hid_type != hdev->type) |
| 2757 | return -ENODEV; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2758 | |
Ping Cheng | 37309f4 | 2020-12-09 20:52:30 -0800 | [diff] [blame] | 2759 | error = wacom_devm_kfifo_alloc(wacom); |
Jason Gerecke | 8341720 | 2017-11-10 11:50:01 -0800 | [diff] [blame] | 2760 | if (error) |
Benjamin Tissoires | 362c571 | 2019-08-12 18:27:40 +0200 | [diff] [blame] | 2761 | return error; |
Jason Gerecke | 8341720 | 2017-11-10 11:50:01 -0800 | [diff] [blame] | 2762 | |
Jason Gerecke | c6fa1ae | 2016-04-04 11:26:51 -0700 | [diff] [blame] | 2763 | wacom_wac->hid_data.inputmode = -1; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 2764 | wacom_wac->mode_report = -1; |
Jason Gerecke | c6fa1ae | 2016-04-04 11:26:51 -0700 | [diff] [blame] | 2765 | |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2766 | wacom->usbdev = dev; |
| 2767 | wacom->intf = intf; |
| 2768 | mutex_init(&wacom->lock); |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 2769 | INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work); |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2770 | INIT_WORK(&wacom->wireless_work, wacom_wireless_work); |
| 2771 | INIT_WORK(&wacom->battery_work, wacom_battery_work); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2772 | INIT_WORK(&wacom->remote_work, wacom_remote_work); |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 2773 | INIT_WORK(&wacom->mode_change_work, wacom_mode_change_work); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2774 | |
| 2775 | /* ask for the report descriptor to be loaded by HID */ |
| 2776 | error = hid_parse(hdev); |
| 2777 | if (error) { |
| 2778 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | 362c571 | 2019-08-12 18:27:40 +0200 | [diff] [blame] | 2779 | return error; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2780 | } |
| 2781 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2782 | error = wacom_parse_and_register(wacom, false); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2783 | if (error) |
Benjamin Tissoires | 362c571 | 2019-08-12 18:27:40 +0200 | [diff] [blame] | 2784 | return error; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2785 | |
| 2786 | if (hdev->bus == BUS_BLUETOOTH) { |
| 2787 | error = device_create_file(&hdev->dev, &dev_attr_speed); |
| 2788 | if (error) |
| 2789 | hid_warn(hdev, |
| 2790 | "can't create sysfs speed attribute err: %d\n", |
| 2791 | error); |
| 2792 | } |
| 2793 | |
| 2794 | return 0; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2797 | static void wacom_remove(struct hid_device *hdev) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2798 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2799 | struct wacom *wacom = hid_get_drvdata(hdev); |
Benjamin Tissoires | f620516 | 2016-02-12 17:27:45 +0100 | [diff] [blame] | 2800 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2801 | struct wacom_features *features = &wacom_wac->features; |
| 2802 | |
| 2803 | if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) |
| 2804 | hid_hw_close(hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2805 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2806 | hid_hw_stop(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2807 | |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 2808 | cancel_delayed_work_sync(&wacom->init_work); |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2809 | cancel_work_sync(&wacom->wireless_work); |
| 2810 | cancel_work_sync(&wacom->battery_work); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2811 | cancel_work_sync(&wacom->remote_work); |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 2812 | cancel_work_sync(&wacom->mode_change_work); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2813 | if (hdev->bus == BUS_BLUETOOTH) |
| 2814 | device_remove_file(&hdev->dev, &dev_attr_speed); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2815 | |
Benjamin Tissoires | c0265a94 | 2017-01-20 16:20:12 +0100 | [diff] [blame] | 2816 | /* make sure we don't trigger the LEDs */ |
| 2817 | wacom_led_groups_release(wacom); |
Aaron Armstrong Skomra | b6b1f19 | 2017-03-06 10:54:58 -0800 | [diff] [blame] | 2818 | |
| 2819 | if (wacom->wacom_wac.features.type != REMOTE) |
| 2820 | wacom_release_resources(wacom); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2821 | } |
| 2822 | |
Geert Uytterhoeven | 41a7458 | 2014-08-11 11:03:19 -0700 | [diff] [blame] | 2823 | #ifdef CONFIG_PM |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2824 | static int wacom_resume(struct hid_device *hdev) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2825 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2826 | struct wacom *wacom = hid_get_drvdata(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2827 | |
| 2828 | mutex_lock(&wacom->lock); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2829 | |
| 2830 | /* switch to wacom mode first */ |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 2831 | _wacom_query_tablet_data(wacom); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2832 | wacom_led_control(wacom); |
| 2833 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2834 | mutex_unlock(&wacom->lock); |
| 2835 | |
| 2836 | return 0; |
| 2837 | } |
| 2838 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2839 | static int wacom_reset_resume(struct hid_device *hdev) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2840 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2841 | return wacom_resume(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2842 | } |
Geert Uytterhoeven | 41a7458 | 2014-08-11 11:03:19 -0700 | [diff] [blame] | 2843 | #endif /* CONFIG_PM */ |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2844 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2845 | static struct hid_driver wacom_driver = { |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2846 | .name = "wacom", |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 2847 | .id_table = wacom_ids, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2848 | .probe = wacom_probe, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2849 | .remove = wacom_remove, |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2850 | .report = wacom_wac_report, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2851 | #ifdef CONFIG_PM |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2852 | .resume = wacom_resume, |
| 2853 | .reset_resume = wacom_reset_resume, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2854 | #endif |
| 2855 | .raw_event = wacom_raw_event, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2856 | }; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2857 | module_hid_driver(wacom_driver); |
Benjamin Tissoires | f2e0a7d | 2014-08-06 14:07:49 -0700 | [diff] [blame] | 2858 | |
| 2859 | MODULE_VERSION(DRIVER_VERSION); |
| 2860 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 2861 | MODULE_DESCRIPTION(DRIVER_DESC); |
Grant Grundler | 7021b60 | 2017-01-05 11:07:04 -0800 | [diff] [blame] | 2862 | MODULE_LICENSE("GPL"); |