blob: be8f7e2a026f428f51200e395792dd715a612eeb [file] [log] [blame]
Ping Cheng3bea7332006-07-13 18:01:36 -07001/*
Dmitry Torokhov4104d132007-05-07 16:16:29 -04002 * drivers/input/tablet/wacom_sys.c
Ping Cheng3bea7332006-07-13 18:01:36 -07003 *
Ping Cheng232f5692009-12-15 00:35:24 -08004 * USB Wacom tablet support - system specific code
Ping Cheng3bea7332006-07-13 18:01:36 -07005 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
Ping Cheng3bea7332006-07-13 18:01:36 -070014#include "wacom_wac.h"
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070015#include "wacom.h"
Jason Gereckeb58ba1b2014-12-05 13:37:32 -080016#include <linux/input/mt.h>
Ping Cheng3bea7332006-07-13 18:01:36 -070017
Ping Chenga417ea42011-08-16 00:17:56 -070018#define WAC_MSG_RETRIES 5
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070019#define WAC_CMD_RETRIES 10
20
Ping Chenge0984bc2014-09-10 12:40:05 -070021#define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
22#define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
Aaron Skomra72b236d2015-08-20 16:05:17 -070023#define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP)
Ping Chenge0984bc2014-09-10 12:40:05 -070024
Ping Chengc64d8832014-09-10 12:41:04 -070025static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf,
26 size_t size, unsigned int retries)
Ping Cheng3bea7332006-07-13 18:01:36 -070027{
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070028 int retval;
29
30 do {
Ping Chengc64d8832014-09-10 12:41:04 -070031 retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
Benjamin Tissoires27b20a92014-07-24 12:56:22 -070032 HID_REQ_GET_REPORT);
Jason Gereckeaef31562015-05-21 10:44:31 -070033 } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
34
35 if (retval < 0)
36 hid_err(hdev, "wacom_get_report: ran out of retries "
37 "(last error = %d)\n", retval);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070038
39 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070040}
41
Przemo Firszt296b7372014-08-06 14:00:38 -070042static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf,
43 size_t size, unsigned int retries)
Ping Cheng3bea7332006-07-13 18:01:36 -070044{
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070045 int retval;
46
47 do {
Przemo Firszt296b7372014-08-06 14:00:38 -070048 retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
Benjamin Tissoires27b20a92014-07-24 12:56:22 -070049 HID_REQ_SET_REPORT);
Jason Gereckeaef31562015-05-21 10:44:31 -070050 } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
51
52 if (retval < 0)
53 hid_err(hdev, "wacom_set_report: ran out of retries "
54 "(last error = %d)\n", retval);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070055
56 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070057}
58
Benjamin Tissoires29b47392014-07-24 12:52:23 -070059static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
60 u8 *raw_data, int size)
Ping Cheng3bea7332006-07-13 18:01:36 -070061{
Benjamin Tissoires29b47392014-07-24 12:52:23 -070062 struct wacom *wacom = hid_get_drvdata(hdev);
Ping Cheng3bea7332006-07-13 18:01:36 -070063
Benjamin Tissoires29b47392014-07-24 12:52:23 -070064 if (size > WACOM_PKGLEN_MAX)
65 return 1;
Ping Cheng3bea7332006-07-13 18:01:36 -070066
Benjamin Tissoires29b47392014-07-24 12:52:23 -070067 memcpy(wacom->wacom_wac.data, raw_data, size);
Ping Cheng3bea7332006-07-13 18:01:36 -070068
Benjamin Tissoires29b47392014-07-24 12:52:23 -070069 wacom_wac_irq(&wacom->wacom_wac, size);
70
71 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -070072}
73
Ping Cheng3bea7332006-07-13 18:01:36 -070074static int wacom_open(struct input_dev *dev)
75{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -040076 struct wacom *wacom = input_get_drvdata(dev);
Ping Cheng3bea7332006-07-13 18:01:36 -070077
Benjamin Tissoiresdff67412014-12-01 11:52:40 -050078 return hid_hw_open(wacom->hdev);
Ping Cheng3bea7332006-07-13 18:01:36 -070079}
80
81static void wacom_close(struct input_dev *dev)
82{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -040083 struct wacom *wacom = input_get_drvdata(dev);
Ping Cheng3bea7332006-07-13 18:01:36 -070084
Benjamin Tissoires3dad1882016-07-13 18:05:54 +020085 /*
86 * wacom->hdev should never be null, but surprisingly, I had the case
87 * once while unplugging the Wacom Wireless Receiver.
88 */
89 if (wacom->hdev)
90 hid_hw_close(wacom->hdev);
Ping Cheng3bea7332006-07-13 18:01:36 -070091}
92
Chris Bagwell16bf2882012-03-25 23:26:20 -070093/*
Benjamin Tissoires198fdee2014-07-24 13:03:05 -070094 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
Jason Gerecke115d5e12012-10-03 17:24:32 -070095 */
96static int wacom_calc_hid_res(int logical_extents, int physical_extents,
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -070097 unsigned unit, int exponent)
Jason Gerecke115d5e12012-10-03 17:24:32 -070098{
Benjamin Tissoires198fdee2014-07-24 13:03:05 -070099 struct hid_field field = {
100 .logical_maximum = logical_extents,
101 .physical_maximum = physical_extents,
102 .unit = unit,
103 .unit_exponent = exponent,
104 };
Jason Gerecke115d5e12012-10-03 17:24:32 -0700105
Benjamin Tissoires198fdee2014-07-24 13:03:05 -0700106 return hidinput_calc_abs_res(&field, ABS_X);
Jason Gerecke115d5e12012-10-03 17:24:32 -0700107}
108
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700109static void wacom_feature_mapping(struct hid_device *hdev,
110 struct hid_field *field, struct hid_usage *usage)
Chris Bagwell41343612011-10-26 22:32:52 -0700111{
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700112 struct wacom *wacom = hid_get_drvdata(hdev);
113 struct wacom_features *features = &wacom->wacom_wac.features;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -0400114 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -0800115 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires8ffffd52014-09-16 16:56:39 -0400116 u8 *data;
117 int ret;
Jason Gerecke345857b2016-10-19 18:03:50 -0700118 int n;
Chris Bagwell41343612011-10-26 22:32:52 -0700119
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -0800120 switch (equivalent_usage) {
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700121 case HID_DG_CONTACTMAX:
122 /* leave touch_max as is if predefined */
Benjamin Tissoires8ffffd52014-09-16 16:56:39 -0400123 if (!features->touch_max) {
124 /* read manually */
125 data = kzalloc(2, GFP_KERNEL);
126 if (!data)
127 break;
128 data[0] = field->report->id;
129 ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
Jason Gerecke05e8fd92015-05-21 10:44:32 -0700130 data, 2, WAC_CMD_RETRIES);
131 if (ret == 2) {
Benjamin Tissoires8ffffd52014-09-16 16:56:39 -0400132 features->touch_max = data[1];
Jason Gerecke05e8fd92015-05-21 10:44:32 -0700133 } else {
134 features->touch_max = 16;
135 hid_warn(hdev, "wacom_feature_mapping: "
136 "could not get HID_DG_CONTACTMAX, "
137 "defaulting to %d\n",
138 features->touch_max);
139 }
Benjamin Tissoires8ffffd52014-09-16 16:56:39 -0400140 kfree(data);
141 }
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700142 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -0400143 case HID_DG_INPUTMODE:
144 /* Ignore if value index is out of bounds. */
145 if (usage->usage_index >= field->report_count) {
146 dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
147 break;
148 }
149
150 hid_data->inputmode = field->report->id;
151 hid_data->inputmode_index = usage->usage_index;
152 break;
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700153
154 case HID_UP_DIGITIZER:
155 if (field->report->id == 0x0B &&
Jason Gerecke8de82282016-10-19 18:03:37 -0700156 (field->application == WACOM_HID_G9_PEN ||
157 field->application == WACOM_HID_G11_PEN)) {
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700158 wacom->wacom_wac.mode_report = field->report->id;
159 wacom->wacom_wac.mode_value = 0;
160 }
161 break;
162
Jason Gereckec9c09582016-10-19 18:03:43 -0700163 case WACOM_HID_WD_DATAMODE:
164 wacom->wacom_wac.mode_report = field->report->id;
165 wacom->wacom_wac.mode_value = 2;
166 break;
167
Jason Gerecke8de82282016-10-19 18:03:37 -0700168 case WACOM_HID_UP_G9:
169 case WACOM_HID_UP_G11:
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700170 if (field->report->id == 0x03 &&
Jason Gerecke8de82282016-10-19 18:03:37 -0700171 (field->application == WACOM_HID_G9_TOUCHSCREEN ||
172 field->application == WACOM_HID_G11_TOUCHSCREEN)) {
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700173 wacom->wacom_wac.mode_report = field->report->id;
174 wacom->wacom_wac.mode_value = 0;
175 }
176 break;
Jason Gerecke345857b2016-10-19 18:03:50 -0700177 case WACOM_HID_WD_OFFSETLEFT:
178 case WACOM_HID_WD_OFFSETTOP:
179 case WACOM_HID_WD_OFFSETRIGHT:
180 case WACOM_HID_WD_OFFSETBOTTOM:
181 /* read manually */
182 n = hid_report_len(field->report);
183 data = hid_alloc_report_buf(field->report, GFP_KERNEL);
184 if (!data)
185 break;
186 data[0] = field->report->id;
187 ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
188 data, n, WAC_CMD_RETRIES);
189 if (ret == n) {
190 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT,
191 data, n, 0);
192 } else {
193 hid_warn(hdev, "%s: could not retrieve sensor offsets\n",
194 __func__);
195 }
196 kfree(data);
197 break;
Ping Chengf393ee22012-04-29 21:09:17 -0700198 }
199}
200
Chris Bagwell428f8582011-10-26 22:26:59 -0700201/*
202 * Interface Descriptor of wacom devices can be incomplete and
203 * inconsistent so wacom_features table is used to store stylus
204 * device's packet lengths, various maximum values, and tablet
205 * resolution based on product ID's.
206 *
207 * For devices that contain 2 interfaces, wacom_features table is
208 * inaccurate for the touch interface. Since the Interface Descriptor
209 * for touch interfaces has pretty complete data, this function exists
210 * to query tablet for this missing information instead of hard coding in
211 * an additional table.
212 *
213 * A typical Interface Descriptor for a stylus will contain a
214 * boot mouse application collection that is not of interest and this
215 * function will ignore it.
216 *
217 * It also contains a digitizer application collection that also is not
218 * of interest since any information it contains would be duplicate
219 * of what is in wacom_features. Usually it defines a report of an array
220 * of bytes that could be used as max length of the stylus packet returned.
221 * If it happens to define a Digitizer-Stylus Physical Collection then
222 * the X and Y logical values contain valid data but it is ignored.
223 *
224 * A typical Interface Descriptor for a touch interface will contain a
225 * Digitizer-Finger Physical Collection which will define both logical
226 * X/Y maximum as well as the physical size of tablet. Since touch
227 * interfaces haven't supported pressure or distance, this is enough
228 * information to override invalid values in the wacom_features table.
Chris Bagwell41343612011-10-26 22:32:52 -0700229 *
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700230 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
231 * data. We deal with them after returning from this function.
Chris Bagwell428f8582011-10-26 22:26:59 -0700232 */
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700233static void wacom_usage_mapping(struct hid_device *hdev,
234 struct hid_field *field, struct hid_usage *usage)
235{
236 struct wacom *wacom = hid_get_drvdata(hdev);
237 struct wacom_features *features = &wacom->wacom_wac.features;
Benjamin Tissoiresd97a5522015-01-05 16:32:12 -0500238 bool finger = WACOM_FINGER_FIELD(field);
239 bool pen = WACOM_PEN_FIELD(field);
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700240
241 /*
242 * Requiring Stylus Usage will ignore boot mouse
243 * X/Y values and some cases of invalid Digitizer X/Y
244 * values commonly reported.
245 */
Jason Gerecke042628a2015-04-30 17:51:54 -0700246 if (pen)
Jason Gereckeaa86b182015-06-15 18:01:42 -0700247 features->device_type |= WACOM_DEVICETYPE_PEN;
Jason Gerecke042628a2015-04-30 17:51:54 -0700248 else if (finger)
Jason Gereckeaa86b182015-06-15 18:01:42 -0700249 features->device_type |= WACOM_DEVICETYPE_TOUCH;
Jason Gerecke042628a2015-04-30 17:51:54 -0700250 else
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700251 return;
252
Ping Cheng30ebc1a2014-11-18 13:29:16 -0800253 /*
254 * Bamboo models do not support HID_DG_CONTACTMAX.
255 * And, Bamboo Pen only descriptor contains touch.
256 */
Ping Cheng3b164a02015-09-23 09:59:10 -0700257 if (features->type > BAMBOO_PT) {
Ping Cheng30ebc1a2014-11-18 13:29:16 -0800258 /* ISDv4 touch devices at least supports one touch point */
259 if (finger && !features->touch_max)
260 features->touch_max = 1;
261 }
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700262
Jason Gerecke6005a132016-10-19 18:03:40 -0700263 /*
264 * ISDv4 devices which predate HID's adoption of the
265 * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its
266 * position instead. We can accurately detect if a
267 * usage with that value should be HID_DG_BARRELSWITCH2
268 * based on the surrounding usages, which have remained
269 * constant across generations.
270 */
271 if (features->type == HID_GENERIC &&
272 usage->hid == 0x000D0000 &&
273 field->application == HID_DG_PEN &&
274 field->physical == HID_DG_STYLUS) {
275 int i = usage->usage_index;
276
277 if (i-4 >= 0 && i+1 < field->maxusage &&
278 field->usage[i-4].hid == HID_DG_TIPSWITCH &&
279 field->usage[i-3].hid == HID_DG_BARRELSWITCH &&
280 field->usage[i-2].hid == HID_DG_ERASER &&
281 field->usage[i-1].hid == HID_DG_INVERT &&
282 field->usage[i+1].hid == HID_DG_INRANGE) {
283 usage->hid = HID_DG_BARRELSWITCH2;
284 }
285 }
286
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700287 switch (usage->hid) {
288 case HID_GD_X:
289 features->x_max = field->logical_maximum;
290 if (finger) {
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700291 features->x_phy = field->physical_maximum;
Ping Cheng3b164a02015-09-23 09:59:10 -0700292 if ((features->type != BAMBOO_PT) &&
293 (features->type != BAMBOO_TOUCH)) {
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700294 features->unit = field->unit;
295 features->unitExpo = field->unit_exponent;
296 }
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700297 }
298 break;
299 case HID_GD_Y:
300 features->y_max = field->logical_maximum;
301 if (finger) {
302 features->y_phy = field->physical_maximum;
Ping Cheng3b164a02015-09-23 09:59:10 -0700303 if ((features->type != BAMBOO_PT) &&
304 (features->type != BAMBOO_TOUCH)) {
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700305 features->unit = field->unit;
306 features->unitExpo = field->unit_exponent;
307 }
308 }
309 break;
310 case HID_DG_TIPPRESSURE:
311 if (pen)
312 features->pressure_max = field->logical_maximum;
313 break;
314 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -0400315
316 if (features->type == HID_GENERIC)
317 wacom_wac_usage_mapping(hdev, field, usage);
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700318}
319
Jason Gereckeb58ba1b2014-12-05 13:37:32 -0800320static void wacom_post_parse_hid(struct hid_device *hdev,
321 struct wacom_features *features)
322{
323 struct wacom *wacom = hid_get_drvdata(hdev);
324 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
325
326 if (features->type == HID_GENERIC) {
327 /* Any last-minute generic device setup */
328 if (features->touch_max > 1) {
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -0800329 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
330 input_mt_init_slots(wacom_wac->touch_input,
331 wacom_wac->features.touch_max,
332 INPUT_MT_DIRECT);
333 else
334 input_mt_init_slots(wacom_wac->touch_input,
335 wacom_wac->features.touch_max,
336 INPUT_MT_POINTER);
Jason Gereckeb58ba1b2014-12-05 13:37:32 -0800337 }
338 }
339}
340
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700341static void wacom_parse_hid(struct hid_device *hdev,
Ping Chengec67bbe2009-12-15 00:35:24 -0800342 struct wacom_features *features)
Ping Cheng545f4e92008-11-24 11:44:27 -0500343{
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700344 struct hid_report_enum *rep_enum;
345 struct hid_report *hreport;
346 int i, j;
Ping Cheng545f4e92008-11-24 11:44:27 -0500347
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700348 /* check features first */
349 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
350 list_for_each_entry(hreport, &rep_enum->report_list, list) {
351 for (i = 0; i < hreport->maxfield; i++) {
352 /* Ignore if report count is out of bounds. */
353 if (hreport->field[i]->report_count < 1)
354 continue;
Ping Cheng545f4e92008-11-24 11:44:27 -0500355
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700356 for (j = 0; j < hreport->field[i]->maxusage; j++) {
357 wacom_feature_mapping(hdev, hreport->field[i],
358 hreport->field[i]->usage + j);
Ping Cheng545f4e92008-11-24 11:44:27 -0500359 }
Ping Cheng545f4e92008-11-24 11:44:27 -0500360 }
361 }
362
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700363 /* now check the input usages */
364 rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
365 list_for_each_entry(hreport, &rep_enum->report_list, list) {
366
367 if (!hreport->maxfield)
368 continue;
369
370 for (i = 0; i < hreport->maxfield; i++)
371 for (j = 0; j < hreport->field[i]->maxusage; j++)
372 wacom_usage_mapping(hdev, hreport->field[i],
373 hreport->field[i]->usage + j);
374 }
Jason Gereckeb58ba1b2014-12-05 13:37:32 -0800375
376 wacom_post_parse_hid(hdev, features);
Ping Cheng545f4e92008-11-24 11:44:27 -0500377}
378
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -0400379static int wacom_hid_set_device_mode(struct hid_device *hdev)
380{
381 struct wacom *wacom = hid_get_drvdata(hdev);
382 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
383 struct hid_report *r;
384 struct hid_report_enum *re;
385
386 if (hid_data->inputmode < 0)
387 return 0;
388
389 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
390 r = re->report_id_hash[hid_data->inputmode];
391 if (r) {
392 r->field[0]->value[hid_data->inputmode_index] = 2;
393 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
394 }
395 return 0;
396}
397
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700398static int wacom_set_device_mode(struct hid_device *hdev,
399 struct wacom_wac *wacom_wac)
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700400{
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700401 u8 *rep_data;
402 struct hid_report *r;
403 struct hid_report_enum *re;
404 int length;
Jason Gereckefe494bc2012-10-03 17:25:35 -0700405 int error = -ENOMEM, limit = 0;
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700406
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700407 if (wacom_wac->mode_report < 0)
408 return 0;
409
410 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
411 r = re->report_id_hash[wacom_wac->mode_report];
412 if (!r)
413 return -EINVAL;
414
415 rep_data = hid_alloc_report_buf(r, GFP_KERNEL);
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700416 if (!rep_data)
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700417 return -ENOMEM;
418
419 length = hid_report_len(r);
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700420
Jason Gereckefe494bc2012-10-03 17:25:35 -0700421 do {
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700422 rep_data[0] = wacom_wac->mode_report;
423 rep_data[1] = wacom_wac->mode_value;
Chris Bagwell9937c022013-01-23 19:37:34 -0800424
Przemo Firszt296b7372014-08-06 14:00:38 -0700425 error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data,
426 length, 1);
Benjamin Tissoires3cb83152014-07-24 12:47:47 -0700427 if (error >= 0)
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700428 error = wacom_get_report(hdev, HID_FEATURE_REPORT,
Ping Chengc64d8832014-09-10 12:41:04 -0700429 rep_data, length, 1);
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700430 } while (error >= 0 &&
431 rep_data[1] != wacom_wac->mode_report &&
432 limit++ < WAC_MSG_RETRIES);
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700433
434 kfree(rep_data);
435
436 return error < 0 ? error : 0;
437}
438
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -0700439static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
440 struct wacom_features *features)
441{
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700442 struct wacom *wacom = hid_get_drvdata(hdev);
443 int ret;
444 u8 rep_data[2];
445
446 switch (features->type) {
447 case GRAPHIRE_BT:
448 rep_data[0] = 0x03;
449 rep_data[1] = 0x00;
Przemo Firszt296b7372014-08-06 14:00:38 -0700450 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
451 3);
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700452
453 if (ret >= 0) {
454 rep_data[0] = speed == 0 ? 0x05 : 0x06;
455 rep_data[1] = 0x00;
456
457 ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
Przemo Firszt296b7372014-08-06 14:00:38 -0700458 rep_data, 2, 3);
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700459
460 if (ret >= 0) {
461 wacom->wacom_wac.bt_high_speed = speed;
462 return 0;
463 }
464 }
465
466 /*
467 * Note that if the raw queries fail, it's not a hard failure
468 * and it is safe to continue
469 */
470 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
471 rep_data[0], ret);
472 break;
Benjamin Tissoires81af7e62014-08-06 13:55:56 -0700473 case INTUOS4WL:
474 if (speed == 1)
475 wacom->wacom_wac.bt_features &= ~0x20;
476 else
477 wacom->wacom_wac.bt_features |= 0x20;
478
479 rep_data[0] = 0x03;
480 rep_data[1] = wacom->wacom_wac.bt_features;
481
Przemo Firszt296b7372014-08-06 14:00:38 -0700482 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
483 1);
Benjamin Tissoires81af7e62014-08-06 13:55:56 -0700484 if (ret >= 0)
485 wacom->wacom_wac.bt_high_speed = speed;
486 break;
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700487 }
488
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -0700489 return 0;
490}
491
Jason Gereckefe494bc2012-10-03 17:25:35 -0700492/*
493 * Switch the tablet into its most-capable mode. Wacom tablets are
494 * typically configured to power-up in a mode which sends mouse-like
495 * reports to the OS. To get absolute position, pressure data, etc.
496 * from the tablet, it is necessary to switch the tablet out of this
497 * mode and into one which sends the full range of tablet data.
498 */
Benjamin Tissoiresa544c612017-01-20 16:20:13 +0100499static int _wacom_query_tablet_data(struct wacom *wacom)
Jason Gereckefe494bc2012-10-03 17:25:35 -0700500{
Benjamin Tissoiresa544c612017-01-20 16:20:13 +0100501 struct hid_device *hdev = wacom->hdev;
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700502 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Benjamin Tissoiresa544c612017-01-20 16:20:13 +0100503 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700504
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -0700505 if (hdev->bus == BUS_BLUETOOTH)
506 return wacom_bt_query_tablet_data(hdev, 1, features);
507
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700508 if (features->type != HID_GENERIC) {
509 if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
510 if (features->type > TABLETPC) {
511 /* MT Tablet PC touch */
512 wacom_wac->mode_report = 3;
513 wacom_wac->mode_value = 4;
514 } else if (features->type == WACOM_24HDT) {
515 wacom_wac->mode_report = 18;
516 wacom_wac->mode_value = 2;
517 } else if (features->type == WACOM_27QHDT) {
518 wacom_wac->mode_report = 131;
519 wacom_wac->mode_value = 2;
520 } else if (features->type == BAMBOO_PAD) {
521 wacom_wac->mode_report = 2;
522 wacom_wac->mode_value = 2;
523 }
524 } else if (features->device_type & WACOM_DEVICETYPE_PEN) {
525 if (features->type <= BAMBOO_PT) {
526 wacom_wac->mode_report = 2;
527 wacom_wac->mode_value = 2;
528 }
Jason Gereckefe494bc2012-10-03 17:25:35 -0700529 }
530 }
531
Jason Gerecke326ea2a2016-04-04 11:26:52 -0700532 wacom_set_device_mode(hdev, wacom_wac);
533
534 if (features->type == HID_GENERIC)
535 return wacom_hid_set_device_mode(hdev);
536
Jason Gereckefe494bc2012-10-03 17:25:35 -0700537 return 0;
538}
539
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700540static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
Ping Cheng19635182012-04-29 21:09:18 -0700541 struct wacom_features *features)
Ping Chengec67bbe2009-12-15 00:35:24 -0800542{
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700543 struct wacom *wacom = hid_get_drvdata(hdev);
544 struct usb_interface *intf = wacom->intf;
Ping Chengec67bbe2009-12-15 00:35:24 -0800545
Henrik Rydbergfed87e62010-09-05 12:25:11 -0700546 /* default features */
Henrik Rydbergfed87e62010-09-05 12:25:11 -0700547 features->x_fuzz = 4;
548 features->y_fuzz = 4;
549 features->pressure_fuzz = 0;
Jason Gereckebef7e202016-04-22 14:30:53 -0700550 features->distance_fuzz = 1;
551 features->tilt_fuzz = 1;
Ping Chengec67bbe2009-12-15 00:35:24 -0800552
Chris Bagwelld3825d52012-03-25 23:26:11 -0700553 /*
554 * The wireless device HID is basic and layout conflicts with
555 * other tablets (monitor and touch interface can look like pen).
556 * Skip the query for this type and modify defaults based on
557 * interface number.
558 */
559 if (features->type == WIRELESS) {
Jason Gerecke3f14a632015-08-03 10:17:05 -0700560 if (intf->cur_altsetting->desc.bInterfaceNumber == 0)
Jason Gereckeccad85c2015-08-03 10:17:04 -0700561 features->device_type = WACOM_DEVICETYPE_WL_MONITOR;
Jason Gerecke3f14a632015-08-03 10:17:05 -0700562 else
Jason Gereckeaa86b182015-06-15 18:01:42 -0700563 features->device_type = WACOM_DEVICETYPE_NONE;
Jason Gerecke3f14a632015-08-03 10:17:05 -0700564 return;
Chris Bagwelld3825d52012-03-25 23:26:11 -0700565 }
566
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700567 wacom_parse_hid(hdev, features);
Ping Chengec67bbe2009-12-15 00:35:24 -0800568}
569
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700570struct wacom_hdev_data {
Ping Cheng4492eff2010-03-19 22:18:15 -0700571 struct list_head list;
572 struct kref kref;
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700573 struct hid_device *dev;
Ping Cheng4492eff2010-03-19 22:18:15 -0700574 struct wacom_shared shared;
575};
576
577static LIST_HEAD(wacom_udev_list);
578static DEFINE_MUTEX(wacom_udev_list_lock);
579
Jason Gerecke41372d52016-08-08 12:06:30 -0700580static bool compare_device_paths(struct hid_device *hdev_a,
581 struct hid_device *hdev_b, char separator)
582{
583 int n1 = strrchr(hdev_a->phys, separator) - hdev_a->phys;
584 int n2 = strrchr(hdev_b->phys, separator) - hdev_b->phys;
585
586 if (n1 != n2 || n1 <= 0 || n2 <= 0)
587 return false;
588
589 return !strncmp(hdev_a->phys, hdev_b->phys, n1);
590}
591
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700592static bool wacom_are_sibling(struct hid_device *hdev,
593 struct hid_device *sibling)
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700594{
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700595 struct wacom *wacom = hid_get_drvdata(hdev);
596 struct wacom_features *features = &wacom->wacom_wac.features;
Jason Gerecke41372d52016-08-08 12:06:30 -0700597 struct wacom *sibling_wacom = hid_get_drvdata(sibling);
598 struct wacom_features *sibling_features = &sibling_wacom->wacom_wac.features;
599 __u32 oVid = features->oVid ? features->oVid : hdev->vendor;
600 __u32 oPid = features->oPid ? features->oPid : hdev->product;
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700601
Jason Gerecke41372d52016-08-08 12:06:30 -0700602 /* The defined oVid/oPid must match that of the sibling */
603 if (features->oVid != HID_ANY_ID && sibling->vendor != oVid)
604 return false;
605 if (features->oPid != HID_ANY_ID && sibling->product != oPid)
606 return false;
607
608 /*
609 * Devices with the same VID/PID must share the same physical
610 * device path, while those with different VID/PID must share
611 * the same physical parent device path.
612 */
613 if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) {
614 if (!compare_device_paths(hdev, sibling, '/'))
615 return false;
616 } else {
617 if (!compare_device_paths(hdev, sibling, '.'))
618 return false;
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700619 }
620
Jason Gerecke41372d52016-08-08 12:06:30 -0700621 /* Skip the remaining heuristics unless you are a HID_GENERIC device */
622 if (features->type != HID_GENERIC)
623 return true;
624
625 /*
626 * Direct-input devices may not be siblings of indirect-input
627 * devices.
628 */
629 if ((features->device_type & WACOM_DEVICETYPE_DIRECT) &&
630 !(sibling_features->device_type & WACOM_DEVICETYPE_DIRECT))
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700631 return false;
632
Jason Gerecke41372d52016-08-08 12:06:30 -0700633 /*
634 * Indirect-input devices may not be siblings of direct-input
635 * devices.
636 */
637 if (!(features->device_type & WACOM_DEVICETYPE_DIRECT) &&
638 (sibling_features->device_type & WACOM_DEVICETYPE_DIRECT))
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700639 return false;
640
Jason Gerecke41372d52016-08-08 12:06:30 -0700641 /* Pen devices may only be siblings of touch devices */
642 if ((features->device_type & WACOM_DEVICETYPE_PEN) &&
643 !(sibling_features->device_type & WACOM_DEVICETYPE_TOUCH))
644 return false;
645
646 /* Touch devices may only be siblings of pen devices */
647 if ((features->device_type & WACOM_DEVICETYPE_TOUCH) &&
648 !(sibling_features->device_type & WACOM_DEVICETYPE_PEN))
649 return false;
650
651 /*
652 * No reason could be found for these two devices to NOT be
653 * siblings, so there's a good chance they ARE siblings
654 */
655 return true;
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700656}
657
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700658static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
Ping Cheng4492eff2010-03-19 22:18:15 -0700659{
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700660 struct wacom_hdev_data *data;
Ping Cheng4492eff2010-03-19 22:18:15 -0700661
Jason Gerecke41372d52016-08-08 12:06:30 -0700662 /* Try to find an already-probed interface from the same device */
663 list_for_each_entry(data, &wacom_udev_list, list) {
664 if (compare_device_paths(hdev, data->dev, '/'))
665 return data;
666 }
667
668 /* Fallback to finding devices that appear to be "siblings" */
Ping Cheng4492eff2010-03-19 22:18:15 -0700669 list_for_each_entry(data, &wacom_udev_list, list) {
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700670 if (wacom_are_sibling(hdev, data->dev)) {
Ping Cheng4492eff2010-03-19 22:18:15 -0700671 kref_get(&data->kref);
672 return data;
673 }
674 }
675
676 return NULL;
677}
678
Benjamin Tissoires1c817c82016-07-13 18:05:59 +0200679static void wacom_release_shared_data(struct kref *kref)
680{
681 struct wacom_hdev_data *data =
682 container_of(kref, struct wacom_hdev_data, kref);
683
684 mutex_lock(&wacom_udev_list_lock);
685 list_del(&data->list);
686 mutex_unlock(&wacom_udev_list_lock);
687
688 kfree(data);
689}
690
691static void wacom_remove_shared_data(void *res)
692{
693 struct wacom *wacom = res;
694 struct wacom_hdev_data *data;
695 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
696
697 if (wacom_wac->shared) {
698 data = container_of(wacom_wac->shared, struct wacom_hdev_data,
699 shared);
700
701 if (wacom_wac->shared->touch == wacom->hdev)
702 wacom_wac->shared->touch = NULL;
703 else if (wacom_wac->shared->pen == wacom->hdev)
704 wacom_wac->shared->pen = NULL;
705
706 kref_put(&data->kref, wacom_release_shared_data);
707 wacom_wac->shared = NULL;
708 }
709}
710
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700711static int wacom_add_shared_data(struct hid_device *hdev)
Ping Cheng4492eff2010-03-19 22:18:15 -0700712{
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700713 struct wacom *wacom = hid_get_drvdata(hdev);
714 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
715 struct wacom_hdev_data *data;
Ping Cheng4492eff2010-03-19 22:18:15 -0700716 int retval = 0;
717
718 mutex_lock(&wacom_udev_list_lock);
719
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700720 data = wacom_get_hdev_data(hdev);
Ping Cheng4492eff2010-03-19 22:18:15 -0700721 if (!data) {
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700722 data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
Ping Cheng4492eff2010-03-19 22:18:15 -0700723 if (!data) {
724 retval = -ENOMEM;
725 goto out;
726 }
727
728 kref_init(&data->kref);
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700729 data->dev = hdev;
Ping Cheng4492eff2010-03-19 22:18:15 -0700730 list_add_tail(&data->list, &wacom_udev_list);
731 }
732
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700733 wacom_wac->shared = &data->shared;
Ping Cheng4492eff2010-03-19 22:18:15 -0700734
Benjamin Tissoires1c817c82016-07-13 18:05:59 +0200735 retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom);
736 if (retval) {
737 mutex_unlock(&wacom_udev_list_lock);
738 wacom_remove_shared_data(wacom);
739 return retval;
740 }
741
Jason Gereckea9ce7852017-01-17 15:38:58 -0800742 if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
743 wacom_wac->shared->touch = hdev;
744 else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
745 wacom_wac->shared->pen = hdev;
746
Ping Cheng4492eff2010-03-19 22:18:15 -0700747out:
748 mutex_unlock(&wacom_udev_list_lock);
749 return retval;
750}
751
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700752static int wacom_led_control(struct wacom *wacom)
753{
754 unsigned char *buf;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700755 int retval;
Ping Cheng912ca212014-09-10 12:41:31 -0700756 unsigned char report_id = WAC_CMD_LED_CONTROL;
757 int buf_size = 9;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700758
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +0200759 if (!wacom->led.groups)
760 return -ENOTSUPP;
761
Ping Cheng912ca212014-09-10 12:41:31 -0700762 if (wacom->wacom_wac.pid) { /* wireless connected */
763 report_id = WAC_CMD_WL_LED_CONTROL;
764 buf_size = 13;
765 }
Jason Gerecke4922cd22017-01-25 12:08:37 -0800766 else if (wacom->wacom_wac.features.type == INTUOSP2_BT) {
767 report_id = WAC_CMD_WL_INTUOSP2;
768 buf_size = 51;
769 }
Ping Cheng912ca212014-09-10 12:41:31 -0700770 buf = kzalloc(buf_size, GFP_KERNEL);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700771 if (!buf)
772 return -ENOMEM;
773
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -0800774 if (wacom->wacom_wac.features.type == HID_GENERIC) {
775 buf[0] = WAC_CMD_LED_CONTROL_GENERIC;
776 buf[1] = wacom->led.llv;
777 buf[2] = wacom->led.groups[0].select & 0x03;
778
779 } else if ((wacom->wacom_wac.features.type >= INTUOS5S &&
780 wacom->wacom_wac.features.type <= INTUOSPL)) {
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700781 /*
782 * Touch Ring and crop mark LED luminance may take on
783 * one of four values:
784 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
785 */
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +0200786 int ring_led = wacom->led.groups[0].select & 0x03;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700787 int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
788 int crop_lum = 0;
Ping Cheng912ca212014-09-10 12:41:31 -0700789 unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
Ping Cheng09e7d942011-10-04 23:51:14 -0700790
Ping Cheng912ca212014-09-10 12:41:31 -0700791 buf[0] = report_id;
792 if (wacom->wacom_wac.pid) {
793 wacom_get_report(wacom->hdev, HID_FEATURE_REPORT,
794 buf, buf_size, WAC_CMD_RETRIES);
795 buf[0] = report_id;
796 buf[4] = led_bits;
797 } else
798 buf[1] = led_bits;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700799 }
Jason Gerecke4922cd22017-01-25 12:08:37 -0800800 else if (wacom->wacom_wac.features.type == INTUOSP2_BT) {
801 buf[0] = report_id;
802 buf[4] = 100; // Power Connection LED (ORANGE)
803 buf[5] = 100; // BT Connection LED (BLUE)
804 buf[6] = 100; // Paper Mode (RED?)
805 buf[7] = 100; // Paper Mode (GREEN?)
806 buf[8] = 100; // Paper Mode (BLUE?)
807 buf[9] = wacom->led.llv;
808 buf[10] = wacom->led.groups[0].select & 0x03;
809 }
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700810 else {
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +0200811 int led = wacom->led.groups[0].select | 0x4;
Ping Cheng09e7d942011-10-04 23:51:14 -0700812
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700813 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
814 wacom->wacom_wac.features.type == WACOM_24HD)
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +0200815 led |= (wacom->led.groups[1].select << 4) | 0x40;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700816
Ping Cheng912ca212014-09-10 12:41:31 -0700817 buf[0] = report_id;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700818 buf[1] = led;
819 buf[2] = wacom->led.llv;
820 buf[3] = wacom->led.hlv;
821 buf[4] = wacom->led.img_lum;
822 }
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700823
Ping Cheng912ca212014-09-10 12:41:31 -0700824 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size,
Przemo Firszt296b7372014-08-06 14:00:38 -0700825 WAC_CMD_RETRIES);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700826 kfree(buf);
827
828 return retval;
829}
830
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700831static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
832 const unsigned len, const void *img)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700833{
834 unsigned char *buf;
835 int i, retval;
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700836 const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700837
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700838 buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700839 if (!buf)
840 return -ENOMEM;
841
842 /* Send 'start' command */
843 buf[0] = WAC_CMD_ICON_START;
844 buf[1] = 1;
Przemo Firszt296b7372014-08-06 14:00:38 -0700845 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
846 WAC_CMD_RETRIES);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700847 if (retval < 0)
848 goto out;
849
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700850 buf[0] = xfer_id;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700851 buf[1] = button_id & 0x07;
852 for (i = 0; i < 4; i++) {
853 buf[2] = i;
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700854 memcpy(buf + 3, img + i * chunk_len, chunk_len);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700855
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700856 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
Przemo Firszt296b7372014-08-06 14:00:38 -0700857 buf, chunk_len + 3, WAC_CMD_RETRIES);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700858 if (retval < 0)
859 break;
860 }
861
862 /* Send 'stop' */
863 buf[0] = WAC_CMD_ICON_START;
864 buf[1] = 0;
Przemo Firszt296b7372014-08-06 14:00:38 -0700865 wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
866 WAC_CMD_RETRIES);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700867
868out:
869 kfree(buf);
870 return retval;
871}
872
Ping Cheng09e7d942011-10-04 23:51:14 -0700873static ssize_t wacom_led_select_store(struct device *dev, int set_id,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700874 const char *buf, size_t count)
875{
Geliang Tangee79a8f2015-12-27 17:25:21 +0800876 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoires29b47392014-07-24 12:52:23 -0700877 struct wacom *wacom = hid_get_drvdata(hdev);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700878 unsigned int id;
879 int err;
880
881 err = kstrtouint(buf, 10, &id);
882 if (err)
883 return err;
884
885 mutex_lock(&wacom->lock);
886
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +0200887 wacom->led.groups[set_id].select = id & 0x3;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700888 err = wacom_led_control(wacom);
889
890 mutex_unlock(&wacom->lock);
891
892 return err < 0 ? err : count;
893}
894
Ping Cheng09e7d942011-10-04 23:51:14 -0700895#define DEVICE_LED_SELECT_ATTR(SET_ID) \
896static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
897 struct device_attribute *attr, const char *buf, size_t count) \
898{ \
899 return wacom_led_select_store(dev, SET_ID, buf, count); \
900} \
Ping Cheng04c59ab2011-10-04 23:51:49 -0700901static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
902 struct device_attribute *attr, char *buf) \
903{ \
Geliang Tangee79a8f2015-12-27 17:25:21 +0800904 struct hid_device *hdev = to_hid_device(dev);\
Benjamin Tissoires29b47392014-07-24 12:52:23 -0700905 struct wacom *wacom = hid_get_drvdata(hdev); \
Ping Cheng37449ad2014-09-10 12:40:30 -0700906 return scnprintf(buf, PAGE_SIZE, "%d\n", \
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +0200907 wacom->led.groups[SET_ID].select); \
Ping Cheng04c59ab2011-10-04 23:51:49 -0700908} \
Ping Chenge0984bc2014-09-10 12:40:05 -0700909static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
Ping Cheng04c59ab2011-10-04 23:51:49 -0700910 wacom_led##SET_ID##_select_show, \
Ping Cheng09e7d942011-10-04 23:51:14 -0700911 wacom_led##SET_ID##_select_store)
912
913DEVICE_LED_SELECT_ATTR(0);
914DEVICE_LED_SELECT_ATTR(1);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700915
916static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
917 const char *buf, size_t count)
918{
919 unsigned int value;
920 int err;
921
922 err = kstrtouint(buf, 10, &value);
923 if (err)
924 return err;
925
926 mutex_lock(&wacom->lock);
927
928 *dest = value & 0x7f;
929 err = wacom_led_control(wacom);
930
931 mutex_unlock(&wacom->lock);
932
933 return err < 0 ? err : count;
934}
935
936#define DEVICE_LUMINANCE_ATTR(name, field) \
937static ssize_t wacom_##name##_luminance_store(struct device *dev, \
938 struct device_attribute *attr, const char *buf, size_t count) \
939{ \
Geliang Tangee79a8f2015-12-27 17:25:21 +0800940 struct hid_device *hdev = to_hid_device(dev);\
Benjamin Tissoires29b47392014-07-24 12:52:23 -0700941 struct wacom *wacom = hid_get_drvdata(hdev); \
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700942 \
943 return wacom_luminance_store(wacom, &wacom->led.field, \
944 buf, count); \
945} \
Ping Cheng37449ad2014-09-10 12:40:30 -0700946static ssize_t wacom_##name##_luminance_show(struct device *dev, \
947 struct device_attribute *attr, char *buf) \
948{ \
949 struct wacom *wacom = dev_get_drvdata(dev); \
950 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
951} \
Ping Chenge0984bc2014-09-10 12:40:05 -0700952static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
Ping Cheng37449ad2014-09-10 12:40:30 -0700953 wacom_##name##_luminance_show, \
954 wacom_##name##_luminance_store)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700955
956DEVICE_LUMINANCE_ATTR(status0, llv);
957DEVICE_LUMINANCE_ATTR(status1, hlv);
958DEVICE_LUMINANCE_ATTR(buttons, img_lum);
959
960static ssize_t wacom_button_image_store(struct device *dev, int button_id,
961 const char *buf, size_t count)
962{
Geliang Tangee79a8f2015-12-27 17:25:21 +0800963 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoires29b47392014-07-24 12:52:23 -0700964 struct wacom *wacom = hid_get_drvdata(hdev);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700965 int err;
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700966 unsigned len;
967 u8 xfer_id;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700968
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700969 if (hdev->bus == BUS_BLUETOOTH) {
970 len = 256;
971 xfer_id = WAC_CMD_ICON_BT_XFER;
972 } else {
973 len = 1024;
974 xfer_id = WAC_CMD_ICON_XFER;
975 }
976
977 if (count != len)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700978 return -EINVAL;
979
980 mutex_lock(&wacom->lock);
981
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700982 err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700983
984 mutex_unlock(&wacom->lock);
985
986 return err < 0 ? err : count;
987}
988
989#define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
990static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
991 struct device_attribute *attr, const char *buf, size_t count) \
992{ \
993 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
994} \
Ping Chenge0984bc2014-09-10 12:40:05 -0700995static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700996 NULL, wacom_btnimg##BUTTON_ID##_store)
997
998DEVICE_BTNIMG_ATTR(0);
999DEVICE_BTNIMG_ATTR(1);
1000DEVICE_BTNIMG_ATTR(2);
1001DEVICE_BTNIMG_ATTR(3);
1002DEVICE_BTNIMG_ATTR(4);
1003DEVICE_BTNIMG_ATTR(5);
1004DEVICE_BTNIMG_ATTR(6);
1005DEVICE_BTNIMG_ATTR(7);
1006
Ping Cheng09e7d942011-10-04 23:51:14 -07001007static struct attribute *cintiq_led_attrs[] = {
1008 &dev_attr_status_led0_select.attr,
1009 &dev_attr_status_led1_select.attr,
1010 NULL
1011};
1012
1013static struct attribute_group cintiq_led_attr_group = {
1014 .name = "wacom_led",
1015 .attrs = cintiq_led_attrs,
1016};
1017
1018static struct attribute *intuos4_led_attrs[] = {
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001019 &dev_attr_status0_luminance.attr,
1020 &dev_attr_status1_luminance.attr,
Ping Cheng09e7d942011-10-04 23:51:14 -07001021 &dev_attr_status_led0_select.attr,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001022 &dev_attr_buttons_luminance.attr,
1023 &dev_attr_button0_rawimg.attr,
1024 &dev_attr_button1_rawimg.attr,
1025 &dev_attr_button2_rawimg.attr,
1026 &dev_attr_button3_rawimg.attr,
1027 &dev_attr_button4_rawimg.attr,
1028 &dev_attr_button5_rawimg.attr,
1029 &dev_attr_button6_rawimg.attr,
1030 &dev_attr_button7_rawimg.attr,
1031 NULL
1032};
1033
Ping Cheng09e7d942011-10-04 23:51:14 -07001034static struct attribute_group intuos4_led_attr_group = {
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001035 .name = "wacom_led",
Ping Cheng09e7d942011-10-04 23:51:14 -07001036 .attrs = intuos4_led_attrs,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001037};
1038
Jason Gerecke9b5b95d2012-04-03 15:50:37 -07001039static struct attribute *intuos5_led_attrs[] = {
1040 &dev_attr_status0_luminance.attr,
1041 &dev_attr_status_led0_select.attr,
1042 NULL
1043};
1044
1045static struct attribute_group intuos5_led_attr_group = {
1046 .name = "wacom_led",
1047 .attrs = intuos5_led_attrs,
1048};
1049
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08001050static struct attribute *generic_led_attrs[] = {
1051 &dev_attr_status0_luminance.attr,
1052 &dev_attr_status_led0_select.attr,
1053 NULL
1054};
1055
1056static struct attribute_group generic_led_attr_group = {
1057 .name = "wacom_led",
1058 .attrs = generic_led_attrs,
1059};
1060
Benjamin Tissoires2df68a82016-07-13 18:05:56 +02001061struct wacom_sysfs_group_devres {
1062 struct attribute_group *group;
1063 struct kobject *root;
1064};
1065
1066static void wacom_devm_sysfs_group_release(struct device *dev, void *res)
1067{
1068 struct wacom_sysfs_group_devres *devres = res;
1069 struct kobject *kobj = devres->root;
1070
1071 dev_dbg(dev, "%s: dropping reference to %s\n",
1072 __func__, devres->group->name);
1073 sysfs_remove_group(kobj, devres->group);
1074}
1075
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02001076static int __wacom_devm_sysfs_create_group(struct wacom *wacom,
1077 struct kobject *root,
1078 struct attribute_group *group)
Benjamin Tissoires2df68a82016-07-13 18:05:56 +02001079{
1080 struct wacom_sysfs_group_devres *devres;
1081 int error;
1082
1083 devres = devres_alloc(wacom_devm_sysfs_group_release,
1084 sizeof(struct wacom_sysfs_group_devres),
1085 GFP_KERNEL);
1086 if (!devres)
1087 return -ENOMEM;
1088
1089 devres->group = group;
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02001090 devres->root = root;
Benjamin Tissoires2df68a82016-07-13 18:05:56 +02001091
1092 error = sysfs_create_group(devres->root, group);
1093 if (error)
1094 return error;
1095
1096 devres_add(&wacom->hdev->dev, devres);
1097
1098 return 0;
1099}
1100
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02001101static int wacom_devm_sysfs_create_group(struct wacom *wacom,
1102 struct attribute_group *group)
1103{
1104 return __wacom_devm_sysfs_create_group(wacom, &wacom->hdev->dev.kobj,
1105 group);
1106}
1107
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02001108enum led_brightness wacom_leds_brightness_get(struct wacom_led *led)
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001109{
1110 struct wacom *wacom = led->wacom;
1111
1112 if (wacom->led.max_hlv)
1113 return led->hlv * LED_FULL / wacom->led.max_hlv;
1114
1115 if (wacom->led.max_llv)
1116 return led->llv * LED_FULL / wacom->led.max_llv;
1117
1118 /* device doesn't support brightness tuning */
1119 return LED_FULL;
1120}
1121
1122static enum led_brightness __wacom_led_brightness_get(struct led_classdev *cdev)
1123{
1124 struct wacom_led *led = container_of(cdev, struct wacom_led, cdev);
1125 struct wacom *wacom = led->wacom;
1126
1127 if (wacom->led.groups[led->group].select != led->id)
1128 return LED_OFF;
1129
1130 return wacom_leds_brightness_get(led);
1131}
1132
1133static int wacom_led_brightness_set(struct led_classdev *cdev,
1134 enum led_brightness brightness)
1135{
1136 struct wacom_led *led = container_of(cdev, struct wacom_led, cdev);
1137 struct wacom *wacom = led->wacom;
1138 int error;
1139
1140 mutex_lock(&wacom->lock);
1141
1142 if (!wacom->led.groups || (brightness == LED_OFF &&
1143 wacom->led.groups[led->group].select != led->id)) {
1144 error = 0;
1145 goto out;
1146 }
1147
1148 led->llv = wacom->led.llv = wacom->led.max_llv * brightness / LED_FULL;
1149 led->hlv = wacom->led.hlv = wacom->led.max_hlv * brightness / LED_FULL;
1150
1151 wacom->led.groups[led->group].select = led->id;
1152
1153 error = wacom_led_control(wacom);
1154
1155out:
1156 mutex_unlock(&wacom->lock);
1157
1158 return error;
1159}
1160
1161static void wacom_led_readonly_brightness_set(struct led_classdev *cdev,
1162 enum led_brightness brightness)
1163{
1164}
1165
1166static int wacom_led_register_one(struct device *dev, struct wacom *wacom,
1167 struct wacom_led *led, unsigned int group,
1168 unsigned int id, bool read_only)
1169{
1170 int error;
1171 char *name;
1172
1173 name = devm_kasprintf(dev, GFP_KERNEL,
1174 "%s::wacom-%d.%d",
1175 dev_name(dev),
1176 group,
1177 id);
1178 if (!name)
1179 return -ENOMEM;
1180
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02001181 if (!read_only) {
1182 led->trigger.name = name;
1183 error = devm_led_trigger_register(dev, &led->trigger);
1184 if (error) {
1185 hid_err(wacom->hdev,
1186 "failed to register LED trigger %s: %d\n",
1187 led->cdev.name, error);
1188 return error;
1189 }
1190 }
1191
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001192 led->group = group;
1193 led->id = id;
1194 led->wacom = wacom;
1195 led->llv = wacom->led.llv;
1196 led->hlv = wacom->led.hlv;
1197 led->cdev.name = name;
1198 led->cdev.max_brightness = LED_FULL;
1199 led->cdev.flags = LED_HW_PLUGGABLE;
1200 led->cdev.brightness_get = __wacom_led_brightness_get;
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02001201 if (!read_only) {
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001202 led->cdev.brightness_set_blocking = wacom_led_brightness_set;
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02001203 led->cdev.default_trigger = led->cdev.name;
1204 } else {
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001205 led->cdev.brightness_set = wacom_led_readonly_brightness_set;
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02001206 }
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001207
1208 error = devm_led_classdev_register(dev, &led->cdev);
1209 if (error) {
1210 hid_err(wacom->hdev,
1211 "failed to register LED %s: %d\n",
1212 led->cdev.name, error);
1213 led->cdev.name = NULL;
1214 return error;
1215 }
1216
1217 return 0;
1218}
1219
Benjamin Tissoires589e5062016-07-13 18:06:11 +02001220static void wacom_led_groups_release_one(void *data)
1221{
1222 struct wacom_group_leds *group = data;
1223
1224 devres_release_group(group->dev, group);
1225}
1226
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001227static int wacom_led_groups_alloc_and_register_one(struct device *dev,
1228 struct wacom *wacom,
1229 int group_id, int count,
1230 bool read_only)
1231{
1232 struct wacom_led *leds;
1233 int i, error;
1234
1235 if (group_id >= wacom->led.count || count <= 0)
1236 return -EINVAL;
1237
1238 if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL))
1239 return -ENOMEM;
1240
1241 leds = devm_kzalloc(dev, sizeof(struct wacom_led) * count, GFP_KERNEL);
1242 if (!leds) {
1243 error = -ENOMEM;
1244 goto err;
1245 }
1246
1247 wacom->led.groups[group_id].leds = leds;
1248 wacom->led.groups[group_id].count = count;
1249
1250 for (i = 0; i < count; i++) {
1251 error = wacom_led_register_one(dev, wacom, &leds[i],
1252 group_id, i, read_only);
1253 if (error)
1254 goto err;
1255 }
1256
Benjamin Tissoires589e5062016-07-13 18:06:11 +02001257 wacom->led.groups[group_id].dev = dev;
1258
1259 devres_close_group(dev, &wacom->led.groups[group_id]);
1260
1261 /*
1262 * There is a bug (?) in devm_led_classdev_register() in which its
1263 * increments the refcount of the parent. If the parent is an input
1264 * device, that means the ref count never reaches 0 when
1265 * devm_input_device_release() gets called.
1266 * This means that the LEDs are still there after disconnect.
1267 * Manually force the release of the group so that the leds are released
1268 * once we are done using them.
1269 */
1270 error = devm_add_action_or_reset(&wacom->hdev->dev,
1271 wacom_led_groups_release_one,
1272 &wacom->led.groups[group_id]);
1273 if (error)
1274 return error;
1275
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001276 return 0;
1277
1278err:
1279 devres_release_group(dev, &wacom->led.groups[group_id]);
1280 return error;
1281}
1282
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02001283struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group_id,
1284 unsigned int id)
1285{
1286 struct wacom_group_leds *group;
1287
1288 if (group_id >= wacom->led.count)
1289 return NULL;
1290
1291 group = &wacom->led.groups[group_id];
1292
1293 if (!group->leds)
1294 return NULL;
1295
1296 id %= group->count;
1297
1298 return &group->leds[id];
1299}
1300
1301/**
1302 * wacom_led_next: gives the next available led with a wacom trigger.
1303 *
1304 * returns the next available struct wacom_led which has its default trigger
1305 * or the current one if none is available.
1306 */
1307struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur)
1308{
1309 struct wacom_led *next_led;
1310 int group, next;
1311
1312 if (!wacom || !cur)
1313 return NULL;
1314
1315 group = cur->group;
1316 next = cur->id;
1317
1318 do {
1319 next_led = wacom_led_find(wacom, group, ++next);
1320 if (!next_led || next_led == cur)
1321 return next_led;
1322 } while (next_led->cdev.trigger != &next_led->trigger);
1323
1324 return next_led;
1325}
1326
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001327static void wacom_led_groups_release(void *data)
1328{
1329 struct wacom *wacom = data;
1330
1331 wacom->led.groups = NULL;
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001332 wacom->led.count = 0;
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001333}
1334
1335static int wacom_led_groups_allocate(struct wacom *wacom, int count)
1336{
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001337 struct device *dev = &wacom->hdev->dev;
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001338 struct wacom_group_leds *groups;
1339 int error;
1340
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001341 groups = devm_kzalloc(dev, sizeof(struct wacom_group_leds) * count,
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001342 GFP_KERNEL);
1343 if (!groups)
1344 return -ENOMEM;
1345
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001346 error = devm_add_action_or_reset(dev, wacom_led_groups_release, wacom);
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001347 if (error)
1348 return error;
1349
1350 wacom->led.groups = groups;
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001351 wacom->led.count = count;
1352
1353 return 0;
1354}
1355
1356static int wacom_leds_alloc_and_register(struct wacom *wacom, int group_count,
1357 int led_per_group, bool read_only)
1358{
1359 struct device *dev;
1360 int i, error;
1361
1362 if (!wacom->wacom_wac.pad_input)
1363 return -EINVAL;
1364
1365 dev = &wacom->wacom_wac.pad_input->dev;
1366
1367 error = wacom_led_groups_allocate(wacom, group_count);
1368 if (error)
1369 return error;
1370
1371 for (i = 0; i < group_count; i++) {
1372 error = wacom_led_groups_alloc_and_register_one(dev, wacom, i,
1373 led_per_group,
1374 read_only);
1375 if (error)
1376 return error;
1377 }
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001378
1379 return 0;
1380}
1381
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08001382int wacom_initialize_leds(struct wacom *wacom)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001383{
1384 int error;
1385
Jason Gerecke862cf552015-06-15 18:01:43 -07001386 if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
1387 return 0;
1388
Ping Cheng09e7d942011-10-04 23:51:14 -07001389 /* Initialize default values */
1390 switch (wacom->wacom_wac.features.type) {
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08001391 case HID_GENERIC:
1392 if (!wacom->generic_has_leds)
1393 return 0;
1394 wacom->led.llv = 100;
1395 wacom->led.max_llv = 100;
1396
1397 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
1398 if (error) {
1399 hid_err(wacom->hdev,
1400 "cannot create leds err: %d\n", error);
1401 return error;
1402 }
1403
1404 error = wacom_devm_sysfs_create_group(wacom,
1405 &generic_led_attr_group);
1406 break;
1407
Jason Gereckea19fc982012-06-12 00:27:53 -07001408 case INTUOS4S:
Ping Cheng09e7d942011-10-04 23:51:14 -07001409 case INTUOS4:
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001410 case INTUOS4WL:
Ping Cheng09e7d942011-10-04 23:51:14 -07001411 case INTUOS4L:
Ping Chengf4fa9a62011-10-04 23:49:42 -07001412 wacom->led.llv = 10;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001413 wacom->led.hlv = 20;
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001414 wacom->led.max_llv = 127;
1415 wacom->led.max_hlv = 127;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001416 wacom->led.img_lum = 10;
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001417
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001418 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001419 if (error) {
1420 hid_err(wacom->hdev,
1421 "cannot create leds err: %d\n", error);
1422 return error;
1423 }
1424
Benjamin Tissoires2df68a82016-07-13 18:05:56 +02001425 error = wacom_devm_sysfs_create_group(wacom,
1426 &intuos4_led_attr_group);
Ping Cheng09e7d942011-10-04 23:51:14 -07001427 break;
1428
Jason Gerecke246835f2011-12-12 00:12:04 -08001429 case WACOM_24HD:
Ping Cheng09e7d942011-10-04 23:51:14 -07001430 case WACOM_21UX2:
Ping Cheng09e7d942011-10-04 23:51:14 -07001431 wacom->led.llv = 0;
1432 wacom->led.hlv = 0;
1433 wacom->led.img_lum = 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001434
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001435 error = wacom_leds_alloc_and_register(wacom, 2, 4, false);
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001436 if (error) {
1437 hid_err(wacom->hdev,
1438 "cannot create leds err: %d\n", error);
1439 return error;
1440 }
1441
Benjamin Tissoires2df68a82016-07-13 18:05:56 +02001442 error = wacom_devm_sysfs_create_group(wacom,
1443 &cintiq_led_attr_group);
Ping Cheng09e7d942011-10-04 23:51:14 -07001444 break;
1445
Jason Gerecke9b5b95d2012-04-03 15:50:37 -07001446 case INTUOS5S:
1447 case INTUOS5:
1448 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07001449 case INTUOSPS:
1450 case INTUOSPM:
1451 case INTUOSPL:
Jason Gerecke862cf552015-06-15 18:01:43 -07001452 wacom->led.llv = 32;
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001453 wacom->led.max_llv = 96;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -07001454
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001455 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001456 if (error) {
1457 hid_err(wacom->hdev,
1458 "cannot create leds err: %d\n", error);
1459 return error;
1460 }
1461
Benjamin Tissoires2df68a82016-07-13 18:05:56 +02001462 error = wacom_devm_sysfs_create_group(wacom,
1463 &intuos5_led_attr_group);
Jason Gerecke9b5b95d2012-04-03 15:50:37 -07001464 break;
1465
Jason Gerecke4922cd22017-01-25 12:08:37 -08001466 case INTUOSP2_BT:
1467 wacom->led.llv = 50;
1468 wacom->led.max_llv = 100;
1469 error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
1470 if (error) {
1471 hid_err(wacom->hdev,
1472 "cannot create leds err: %d\n", error);
1473 return error;
1474 }
1475 return 0;
1476
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001477 case REMOTE:
Benjamin Tissoires97f55412016-07-13 18:06:10 +02001478 wacom->led.llv = 255;
1479 wacom->led.max_llv = 255;
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001480 error = wacom_led_groups_allocate(wacom, 5);
1481 if (error) {
1482 hid_err(wacom->hdev,
1483 "cannot create leds err: %d\n", error);
1484 return error;
1485 }
1486 return 0;
1487
Ping Cheng09e7d942011-10-04 23:51:14 -07001488 default:
1489 return 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001490 }
1491
Ping Cheng09e7d942011-10-04 23:51:14 -07001492 if (error) {
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -07001493 hid_err(wacom->hdev,
Ping Cheng09e7d942011-10-04 23:51:14 -07001494 "cannot create sysfs group err: %d\n", error);
1495 return error;
1496 }
Ping Cheng09e7d942011-10-04 23:51:14 -07001497
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001498 return 0;
1499}
1500
Benjamin Tissoiresa544c612017-01-20 16:20:13 +01001501static void wacom_init_work(struct work_struct *work)
1502{
1503 struct wacom *wacom = container_of(work, struct wacom, init_work.work);
1504
1505 _wacom_query_tablet_data(wacom);
1506 wacom_led_control(wacom);
1507}
1508
1509static void wacom_query_tablet_data(struct wacom *wacom)
1510{
1511 schedule_delayed_work(&wacom->init_work, msecs_to_jiffies(1000));
1512}
1513
Chris Bagwella1d552c2012-03-25 23:26:30 -07001514static enum power_supply_property wacom_battery_props[] = {
Benjamin Tissoires99569532016-07-13 18:06:17 +02001515 POWER_SUPPLY_PROP_MODEL_NAME,
Jason Gerecke71fa6412015-03-11 10:25:41 -07001516 POWER_SUPPLY_PROP_PRESENT,
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07001517 POWER_SUPPLY_PROP_STATUS,
Bastien Nocera6e2a6e82013-10-15 23:33:00 -07001518 POWER_SUPPLY_PROP_SCOPE,
Chris Bagwella1d552c2012-03-25 23:26:30 -07001519 POWER_SUPPLY_PROP_CAPACITY
1520};
1521
1522static int wacom_battery_get_property(struct power_supply *psy,
1523 enum power_supply_property psp,
1524 union power_supply_propval *val)
1525{
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001526 struct wacom_battery *battery = power_supply_get_drvdata(psy);
Chris Bagwella1d552c2012-03-25 23:26:30 -07001527 int ret = 0;
1528
1529 switch (psp) {
Benjamin Tissoires99569532016-07-13 18:06:17 +02001530 case POWER_SUPPLY_PROP_MODEL_NAME:
1531 val->strval = battery->wacom->wacom_wac.name;
1532 break;
Jason Gerecke71fa6412015-03-11 10:25:41 -07001533 case POWER_SUPPLY_PROP_PRESENT:
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001534 val->intval = battery->bat_connected;
Jason Gerecke71fa6412015-03-11 10:25:41 -07001535 break;
Bastien Nocera6e2a6e82013-10-15 23:33:00 -07001536 case POWER_SUPPLY_PROP_SCOPE:
1537 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1538 break;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001539 case POWER_SUPPLY_PROP_CAPACITY:
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001540 val->intval = battery->battery_capacity;
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07001541 break;
1542 case POWER_SUPPLY_PROP_STATUS:
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001543 if (battery->bat_charging)
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07001544 val->intval = POWER_SUPPLY_STATUS_CHARGING;
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001545 else if (battery->battery_capacity == 100 &&
1546 battery->ps_connected)
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07001547 val->intval = POWER_SUPPLY_STATUS_FULL;
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001548 else if (battery->ps_connected)
Jason Gereckeb0882cb2015-03-06 11:47:43 -08001549 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07001550 else
1551 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001552 break;
1553 default:
1554 ret = -EINVAL;
1555 break;
1556 }
1557
1558 return ret;
1559}
1560
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001561static int __wacom_initialize_battery(struct wacom *wacom,
1562 struct wacom_battery *battery)
Chris Bagwella1d552c2012-03-25 23:26:30 -07001563{
Benjamin Tissoiresd70420b92014-07-25 17:31:51 -07001564 static atomic_t battery_no = ATOMIC_INIT(0);
Benjamin Tissoiresb189da92016-07-13 18:05:53 +02001565 struct device *dev = &wacom->hdev->dev;
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001566 struct power_supply_config psy_cfg = { .drv_data = battery, };
Benjamin Tissoires136ae5e2016-07-13 18:06:16 +02001567 struct power_supply *ps_bat;
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001568 struct power_supply_desc *bat_desc = &battery->bat_desc;
Benjamin Tissoiresd70420b92014-07-25 17:31:51 -07001569 unsigned long n;
Benjamin Tissoiresb189da92016-07-13 18:05:53 +02001570 int error;
1571
1572 if (!devres_open_group(dev, bat_desc, GFP_KERNEL))
1573 return -ENOMEM;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001574
Benjamin Tissoires99569532016-07-13 18:06:17 +02001575 battery->wacom = wacom;
1576
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001577 n = atomic_inc_return(&battery_no) - 1;
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001578
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001579 bat_desc->properties = wacom_battery_props;
1580 bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
1581 bat_desc->get_property = wacom_battery_get_property;
1582 sprintf(battery->bat_name, "wacom_battery_%ld", n);
1583 bat_desc->name = battery->bat_name;
Benjamin Tissoires96983292016-07-13 18:06:15 +02001584 bat_desc->type = POWER_SUPPLY_TYPE_USB;
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001585 bat_desc->use_for_apm = 0;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001586
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001587 ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg);
1588 if (IS_ERR(ps_bat)) {
1589 error = PTR_ERR(ps_bat);
1590 goto err;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001591 }
1592
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001593 power_supply_powers(ps_bat, &wacom->hdev->dev);
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001594
1595 battery->battery = ps_bat;
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001596
Benjamin Tissoiresb189da92016-07-13 18:05:53 +02001597 devres_close_group(dev, bat_desc);
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001598 return 0;
Benjamin Tissoiresb189da92016-07-13 18:05:53 +02001599
1600err:
1601 devres_release_group(dev, bat_desc);
1602 return error;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001603}
1604
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001605static int wacom_initialize_battery(struct wacom *wacom)
1606{
1607 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY)
1608 return __wacom_initialize_battery(wacom, &wacom->battery);
1609
1610 return 0;
1611}
1612
Chris Bagwella1d552c2012-03-25 23:26:30 -07001613static void wacom_destroy_battery(struct wacom *wacom)
1614{
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001615 if (wacom->battery.battery) {
1616 devres_release_group(&wacom->hdev->dev,
1617 &wacom->battery.bat_desc);
1618 wacom->battery.battery = NULL;
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001619 }
Chris Bagwella1d552c2012-03-25 23:26:30 -07001620}
1621
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001622static ssize_t wacom_show_speed(struct device *dev,
1623 struct device_attribute
1624 *attr, char *buf)
1625{
Geliang Tangee79a8f2015-12-27 17:25:21 +08001626 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001627 struct wacom *wacom = hid_get_drvdata(hdev);
1628
1629 return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
1630}
1631
1632static ssize_t wacom_store_speed(struct device *dev,
1633 struct device_attribute *attr,
1634 const char *buf, size_t count)
1635{
Geliang Tangee79a8f2015-12-27 17:25:21 +08001636 struct hid_device *hdev = to_hid_device(dev);
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001637 struct wacom *wacom = hid_get_drvdata(hdev);
1638 u8 new_speed;
1639
1640 if (kstrtou8(buf, 0, &new_speed))
1641 return -EINVAL;
1642
1643 if (new_speed != 0 && new_speed != 1)
1644 return -EINVAL;
1645
1646 wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
1647
1648 return count;
1649}
1650
Ping Chenge0984bc2014-09-10 12:40:05 -07001651static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM,
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001652 wacom_show_speed, wacom_store_speed);
1653
Aaron Skomra72b236d2015-08-20 16:05:17 -07001654
1655static ssize_t wacom_show_remote_mode(struct kobject *kobj,
1656 struct kobj_attribute *kattr,
1657 char *buf, int index)
1658{
Geliang Tang2cf83832015-12-27 17:25:24 +08001659 struct device *dev = kobj_to_dev(kobj->parent);
Geliang Tangee79a8f2015-12-27 17:25:21 +08001660 struct hid_device *hdev = to_hid_device(dev);
Aaron Skomra72b236d2015-08-20 16:05:17 -07001661 struct wacom *wacom = hid_get_drvdata(hdev);
1662 u8 mode;
1663
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001664 mode = wacom->led.groups[index].select;
Aaron Skomra72b236d2015-08-20 16:05:17 -07001665 if (mode >= 0 && mode < 3)
1666 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
1667 else
1668 return snprintf(buf, PAGE_SIZE, "%d\n", -1);
1669}
1670
1671#define DEVICE_EKR_ATTR_GROUP(SET_ID) \
1672static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
1673 struct kobj_attribute *kattr, char *buf) \
1674{ \
1675 return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
1676} \
1677static struct kobj_attribute remote##SET_ID##_mode_attr = { \
1678 .attr = {.name = "remote_mode", \
1679 .mode = DEV_ATTR_RO_PERM}, \
1680 .show = wacom_show_remote##SET_ID##_mode, \
1681}; \
1682static struct attribute *remote##SET_ID##_serial_attrs[] = { \
1683 &remote##SET_ID##_mode_attr.attr, \
1684 NULL \
1685}; \
1686static struct attribute_group remote##SET_ID##_serial_group = { \
1687 .name = NULL, \
1688 .attrs = remote##SET_ID##_serial_attrs, \
1689}
1690
1691DEVICE_EKR_ATTR_GROUP(0);
1692DEVICE_EKR_ATTR_GROUP(1);
1693DEVICE_EKR_ATTR_GROUP(2);
1694DEVICE_EKR_ATTR_GROUP(3);
1695DEVICE_EKR_ATTR_GROUP(4);
1696
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02001697static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial,
1698 int index)
Aaron Skomra72b236d2015-08-20 16:05:17 -07001699{
1700 int error = 0;
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02001701 struct wacom_remote *remote = wacom->remote;
Aaron Skomra72b236d2015-08-20 16:05:17 -07001702
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02001703 remote->remotes[index].group.name = devm_kasprintf(&wacom->hdev->dev,
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02001704 GFP_KERNEL,
1705 "%d", serial);
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02001706 if (!remote->remotes[index].group.name)
Aaron Skomra72b236d2015-08-20 16:05:17 -07001707 return -ENOMEM;
Aaron Skomra72b236d2015-08-20 16:05:17 -07001708
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02001709 error = __wacom_devm_sysfs_create_group(wacom, remote->remote_dir,
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02001710 &remote->remotes[index].group);
Aaron Skomra72b236d2015-08-20 16:05:17 -07001711 if (error) {
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02001712 remote->remotes[index].group.name = NULL;
Aaron Skomra72b236d2015-08-20 16:05:17 -07001713 hid_err(wacom->hdev,
1714 "cannot create sysfs group err: %d\n", error);
Aaron Skomra72b236d2015-08-20 16:05:17 -07001715 return error;
1716 }
1717
1718 return 0;
1719}
1720
Aaron Skomra72b236d2015-08-20 16:05:17 -07001721static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector)
1722{
1723 const size_t buf_size = 2;
1724 unsigned char *buf;
1725 int retval;
1726
1727 buf = kzalloc(buf_size, GFP_KERNEL);
1728 if (!buf)
1729 return -ENOMEM;
1730
1731 buf[0] = WAC_CMD_DELETE_PAIRING;
1732 buf[1] = selector;
1733
1734 retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf,
1735 buf_size, WAC_CMD_RETRIES);
1736 kfree(buf);
1737
1738 return retval;
1739}
1740
1741static ssize_t wacom_store_unpair_remote(struct kobject *kobj,
1742 struct kobj_attribute *attr,
1743 const char *buf, size_t count)
1744{
1745 unsigned char selector = 0;
Geliang Tang2cf83832015-12-27 17:25:24 +08001746 struct device *dev = kobj_to_dev(kobj->parent);
Geliang Tangee79a8f2015-12-27 17:25:21 +08001747 struct hid_device *hdev = to_hid_device(dev);
Aaron Skomra72b236d2015-08-20 16:05:17 -07001748 struct wacom *wacom = hid_get_drvdata(hdev);
1749 int err;
1750
1751 if (!strncmp(buf, "*\n", 2)) {
1752 selector = WAC_CMD_UNPAIR_ALL;
1753 } else {
1754 hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n",
1755 buf);
1756 return -1;
1757 }
1758
1759 mutex_lock(&wacom->lock);
1760
1761 err = wacom_cmd_unpair_remote(wacom, selector);
1762 mutex_unlock(&wacom->lock);
1763
1764 return err < 0 ? err : count;
1765}
1766
1767static struct kobj_attribute unpair_remote_attr = {
1768 .attr = {.name = "unpair_remote", .mode = 0200},
1769 .store = wacom_store_unpair_remote,
1770};
1771
1772static const struct attribute *remote_unpair_attrs[] = {
1773 &unpair_remote_attr.attr,
1774 NULL
1775};
1776
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02001777static void wacom_remotes_destroy(void *data)
1778{
1779 struct wacom *wacom = data;
1780 struct wacom_remote *remote = wacom->remote;
1781
1782 if (!remote)
1783 return;
1784
1785 kobject_put(remote->remote_dir);
1786 kfifo_free(&remote->remote_fifo);
1787 wacom->remote = NULL;
1788}
1789
1790static int wacom_initialize_remotes(struct wacom *wacom)
Aaron Skomra72b236d2015-08-20 16:05:17 -07001791{
1792 int error = 0;
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02001793 struct wacom_remote *remote;
Aaron Skomra72b236d2015-08-20 16:05:17 -07001794 int i;
1795
1796 if (wacom->wacom_wac.features.type != REMOTE)
1797 return 0;
1798
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02001799 remote = devm_kzalloc(&wacom->hdev->dev, sizeof(*wacom->remote),
1800 GFP_KERNEL);
1801 if (!remote)
Aaron Skomra72b236d2015-08-20 16:05:17 -07001802 return -ENOMEM;
1803
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02001804 wacom->remote = remote;
1805
1806 spin_lock_init(&remote->remote_lock);
1807
1808 error = kfifo_alloc(&remote->remote_fifo,
1809 5 * sizeof(struct wacom_remote_data),
1810 GFP_KERNEL);
1811 if (error) {
1812 hid_err(wacom->hdev, "failed allocating remote_fifo\n");
1813 return -ENOMEM;
1814 }
1815
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02001816 remote->remotes[0].group = remote0_serial_group;
1817 remote->remotes[1].group = remote1_serial_group;
1818 remote->remotes[2].group = remote2_serial_group;
1819 remote->remotes[3].group = remote3_serial_group;
1820 remote->remotes[4].group = remote4_serial_group;
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02001821
1822 remote->remote_dir = kobject_create_and_add("wacom_remote",
1823 &wacom->hdev->dev.kobj);
1824 if (!remote->remote_dir)
1825 return -ENOMEM;
1826
1827 error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs);
Aaron Skomra72b236d2015-08-20 16:05:17 -07001828
1829 if (error) {
1830 hid_err(wacom->hdev,
1831 "cannot create sysfs group err: %d\n", error);
1832 return error;
1833 }
1834
1835 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +02001836 wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02001837 remote->remotes[i].serial = 0;
Aaron Skomra72b236d2015-08-20 16:05:17 -07001838 }
1839
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02001840 error = devm_add_action_or_reset(&wacom->hdev->dev,
1841 wacom_remotes_destroy, wacom);
1842 if (error)
1843 return error;
1844
Aaron Skomra72b236d2015-08-20 16:05:17 -07001845 return 0;
1846}
1847
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001848static struct input_dev *wacom_allocate_input(struct wacom *wacom)
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001849{
1850 struct input_dev *input_dev;
Benjamin Tissoiresb6c79f22014-07-24 13:00:03 -07001851 struct hid_device *hdev = wacom->hdev;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001852 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001853
Benjamin Tissoires3dad1882016-07-13 18:05:54 +02001854 input_dev = devm_input_allocate_device(&hdev->dev);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001855 if (!input_dev)
1856 return NULL;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001857
Jason Gerecke2bdd1632015-07-13 18:03:45 -07001858 input_dev->name = wacom_wac->features.name;
Benjamin Tissoiresb6c79f22014-07-24 13:00:03 -07001859 input_dev->phys = hdev->phys;
1860 input_dev->dev.parent = &hdev->dev;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001861 input_dev->open = wacom_open;
1862 input_dev->close = wacom_close;
Benjamin Tissoiresb6c79f22014-07-24 13:00:03 -07001863 input_dev->uniq = hdev->uniq;
1864 input_dev->id.bustype = hdev->bus;
1865 input_dev->id.vendor = hdev->vendor;
Benjamin Tissoires12969e32014-09-11 13:14:04 -04001866 input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product;
Benjamin Tissoiresb6c79f22014-07-24 13:00:03 -07001867 input_dev->id.version = hdev->version;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001868 input_set_drvdata(input_dev, wacom);
1869
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001870 return input_dev;
1871}
1872
Jason Gerecked9f2d202015-07-13 18:03:44 -07001873static int wacom_allocate_inputs(struct wacom *wacom)
1874{
1875 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1876
1877 wacom_wac->pen_input = wacom_allocate_input(wacom);
1878 wacom_wac->touch_input = wacom_allocate_input(wacom);
1879 wacom_wac->pad_input = wacom_allocate_input(wacom);
Benjamin Tissoires3dad1882016-07-13 18:05:54 +02001880 if (!wacom_wac->pen_input ||
1881 !wacom_wac->touch_input ||
1882 !wacom_wac->pad_input)
Jason Gerecked9f2d202015-07-13 18:03:44 -07001883 return -ENOMEM;
Jason Gerecked9f2d202015-07-13 18:03:44 -07001884
Jason Gerecke2bdd1632015-07-13 18:03:45 -07001885 wacom_wac->pen_input->name = wacom_wac->pen_name;
Jason Gerecked9f2d202015-07-13 18:03:44 -07001886 wacom_wac->touch_input->name = wacom_wac->touch_name;
1887 wacom_wac->pad_input->name = wacom_wac->pad_name;
1888
1889 return 0;
1890}
1891
Benjamin Tissoires008f4d92014-07-24 12:51:26 -07001892static int wacom_register_inputs(struct wacom *wacom)
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001893{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001894 struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001895 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07001896 int error = 0;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001897
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001898 pen_input_dev = wacom_wac->pen_input;
1899 touch_input_dev = wacom_wac->touch_input;
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001900 pad_input_dev = wacom_wac->pad_input;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001901
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001902 if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001903 return -EINVAL;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001904
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001905 error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
1906 if (error) {
1907 /* no pen in use on this interface */
1908 input_free_device(pen_input_dev);
1909 wacom_wac->pen_input = NULL;
1910 pen_input_dev = NULL;
1911 } else {
1912 error = input_register_device(pen_input_dev);
Ping Cheng30ebc1a2014-11-18 13:29:16 -08001913 if (error)
Benjamin Tissoires3dad1882016-07-13 18:05:54 +02001914 goto fail;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001915 }
1916
1917 error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
1918 if (error) {
1919 /* no touch in use on this interface */
1920 input_free_device(touch_input_dev);
1921 wacom_wac->touch_input = NULL;
1922 touch_input_dev = NULL;
1923 } else {
1924 error = input_register_device(touch_input_dev);
1925 if (error)
Benjamin Tissoires3dad1882016-07-13 18:05:54 +02001926 goto fail;
Ping Cheng30ebc1a2014-11-18 13:29:16 -08001927 }
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001928
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001929 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
1930 if (error) {
1931 /* no pad in use on this interface */
1932 input_free_device(pad_input_dev);
1933 wacom_wac->pad_input = NULL;
1934 pad_input_dev = NULL;
1935 } else {
1936 error = input_register_device(pad_input_dev);
1937 if (error)
Benjamin Tissoires3dad1882016-07-13 18:05:54 +02001938 goto fail;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001939 }
1940
Ping Cheng19635182012-04-29 21:09:18 -07001941 return 0;
1942
Benjamin Tissoires3dad1882016-07-13 18:05:54 +02001943fail:
1944 wacom_wac->pad_input = NULL;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001945 wacom_wac->touch_input = NULL;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001946 wacom_wac->pen_input = NULL;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001947 return error;
1948}
1949
Jason Gerecke0be01712015-08-05 15:44:53 -07001950/*
1951 * Not all devices report physical dimensions from HID.
1952 * Compute the default from hardcoded logical dimension
1953 * and resolution before driver overwrites them.
1954 */
1955static void wacom_set_default_phy(struct wacom_features *features)
1956{
1957 if (features->x_resolution) {
1958 features->x_phy = (features->x_max * 100) /
1959 features->x_resolution;
1960 features->y_phy = (features->y_max * 100) /
1961 features->y_resolution;
1962 }
1963}
1964
1965static void wacom_calculate_res(struct wacom_features *features)
1966{
1967 /* set unit to "100th of a mm" for devices not reported by HID */
1968 if (!features->unit) {
1969 features->unit = 0x11;
1970 features->unitExpo = -3;
1971 }
1972
1973 features->x_resolution = wacom_calc_hid_res(features->x_max,
1974 features->x_phy,
1975 features->unit,
1976 features->unitExpo);
1977 features->y_resolution = wacom_calc_hid_res(features->y_max,
1978 features->y_phy,
1979 features->unit,
1980 features->unitExpo);
1981}
1982
Jason Gereckefce99572015-03-06 11:47:40 -08001983void wacom_battery_work(struct work_struct *work)
1984{
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02001985 struct wacom *wacom = container_of(work, struct wacom, battery_work);
Jason Gereckefce99572015-03-06 11:47:40 -08001986
1987 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001988 !wacom->battery.battery) {
Jason Gereckefce99572015-03-06 11:47:40 -08001989 wacom_initialize_battery(wacom);
1990 }
1991 else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02001992 wacom->battery.battery) {
Jason Gereckefce99572015-03-06 11:47:40 -08001993 wacom_destroy_battery(wacom);
1994 }
1995}
1996
Benjamin Tissoires01c846f2014-07-24 12:59:11 -07001997static size_t wacom_compute_pktlen(struct hid_device *hdev)
1998{
1999 struct hid_report_enum *report_enum;
2000 struct hid_report *report;
2001 size_t size = 0;
2002
2003 report_enum = hdev->report_enum + HID_INPUT_REPORT;
2004
2005 list_for_each_entry(report, &report_enum->report_list, list) {
Mathieu Magnaudetdabb05c62014-11-27 16:02:36 +01002006 size_t report_size = hid_report_len(report);
Benjamin Tissoires01c846f2014-07-24 12:59:11 -07002007 if (report_size > size)
2008 size = report_size;
2009 }
2010
2011 return size;
2012}
2013
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002014static void wacom_update_name(struct wacom *wacom, const char *suffix)
Ping Chengc24eab42015-04-24 15:32:51 -07002015{
2016 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2017 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke44b52502015-06-15 18:01:41 -07002018 char name[WACOM_NAME_MAX];
Ping Chengc24eab42015-04-24 15:32:51 -07002019
2020 /* Generic devices name unspecified */
2021 if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
2022 if (strstr(wacom->hdev->name, "Wacom") ||
2023 strstr(wacom->hdev->name, "wacom") ||
2024 strstr(wacom->hdev->name, "WACOM")) {
2025 /* name is in HID descriptor, use it */
Jason Gerecke44b52502015-06-15 18:01:41 -07002026 strlcpy(name, wacom->hdev->name, sizeof(name));
Ping Chengc24eab42015-04-24 15:32:51 -07002027
2028 /* strip out excess whitespaces */
2029 while (1) {
Jason Gerecke44b52502015-06-15 18:01:41 -07002030 char *gap = strstr(name, " ");
Ping Chengc24eab42015-04-24 15:32:51 -07002031 if (gap == NULL)
2032 break;
2033 /* shift everything including the terminator */
2034 memmove(gap, gap+1, strlen(gap));
2035 }
Jason Gereckef2209d42016-10-19 18:03:41 -07002036
2037 /* strip off excessive prefixing */
2038 if (strstr(name, "Wacom Co.,Ltd. Wacom ") == name) {
2039 int n = strlen(name);
2040 int x = strlen("Wacom Co.,Ltd. ");
2041 memmove(name, name+x, n-x+1);
2042 }
2043 if (strstr(name, "Wacom Co., Ltd. Wacom ") == name) {
2044 int n = strlen(name);
2045 int x = strlen("Wacom Co., Ltd. ");
2046 memmove(name, name+x, n-x+1);
2047 }
2048
Ping Chengc24eab42015-04-24 15:32:51 -07002049 /* get rid of trailing whitespace */
Jason Gerecke44b52502015-06-15 18:01:41 -07002050 if (name[strlen(name)-1] == ' ')
2051 name[strlen(name)-1] = '\0';
Ping Chengc24eab42015-04-24 15:32:51 -07002052 } else {
2053 /* no meaningful name retrieved. use product ID */
Jason Gerecke44b52502015-06-15 18:01:41 -07002054 snprintf(name, sizeof(name),
Ping Chengc24eab42015-04-24 15:32:51 -07002055 "%s %X", features->name, wacom->hdev->product);
2056 }
2057 } else {
Jason Gerecke44b52502015-06-15 18:01:41 -07002058 strlcpy(name, features->name, sizeof(name));
Ping Chengc24eab42015-04-24 15:32:51 -07002059 }
2060
Benjamin Tissoires99569532016-07-13 18:06:17 +02002061 snprintf(wacom_wac->name, sizeof(wacom_wac->name), "%s%s",
2062 name, suffix);
2063
Ping Chengc24eab42015-04-24 15:32:51 -07002064 /* Append the device type to the name */
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002065 snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002066 "%s%s Pen", name, suffix);
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002067 snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002068 "%s%s Finger", name, suffix);
Ping Chengc24eab42015-04-24 15:32:51 -07002069 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002070 "%s%s Pad", name, suffix);
Ping Chengc24eab42015-04-24 15:32:51 -07002071}
2072
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002073static void wacom_release_resources(struct wacom *wacom)
2074{
2075 struct hid_device *hdev = wacom->hdev;
2076
2077 if (!wacom->resources)
2078 return;
2079
2080 devres_release_group(&hdev->dev, wacom);
2081
2082 wacom->resources = false;
2083
2084 wacom->wacom_wac.pen_input = NULL;
2085 wacom->wacom_wac.touch_input = NULL;
2086 wacom->wacom_wac.pad_input = NULL;
2087}
2088
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002089static void wacom_set_shared_values(struct wacom_wac *wacom_wac)
2090{
2091 if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) {
2092 wacom_wac->shared->type = wacom_wac->features.type;
2093 wacom_wac->shared->touch_input = wacom_wac->touch_input;
2094 }
2095
2096 if (wacom_wac->has_mute_touch_switch)
2097 wacom_wac->shared->has_mute_touch_switch = true;
2098
2099 if (wacom_wac->shared->has_mute_touch_switch &&
2100 wacom_wac->shared->touch_input) {
2101 set_bit(EV_SW, wacom_wac->shared->touch_input->evbit);
2102 input_set_capability(wacom_wac->shared->touch_input, EV_SW,
2103 SW_MUTE_DEVICE);
2104 }
2105}
2106
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002107static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
Ping Cheng3bea7332006-07-13 18:01:36 -07002108{
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002109 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2110 struct wacom_features *features = &wacom_wac->features;
2111 struct hid_device *hdev = wacom->hdev;
Jason Childse33da8a2010-02-17 22:38:31 -08002112 int error;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002113 unsigned int connect_mask = HID_CONNECT_HIDRAW;
Ping Cheng3bea7332006-07-13 18:01:36 -07002114
Benjamin Tissoires01c846f2014-07-24 12:59:11 -07002115 features->pktlen = wacom_compute_pktlen(hdev);
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002116 if (features->pktlen > WACOM_PKGLEN_MAX)
2117 return -EINVAL;
Ping Cheng3bea7332006-07-13 18:01:36 -07002118
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002119 if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL))
2120 return -ENOMEM;
2121
2122 wacom->resources = true;
2123
Jason Gerecke3f14a632015-08-03 10:17:05 -07002124 error = wacom_allocate_inputs(wacom);
2125 if (error)
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002126 goto fail;
Benjamin Tissoires494078b2014-09-23 12:08:07 -04002127
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002128 /*
2129 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
2130 * into debug mode for the touch part.
2131 * We ignore the other interfaces.
2132 */
2133 if (features->type == BAMBOO_PAD) {
2134 if (features->pktlen == WACOM_PKGLEN_PENABLED) {
2135 features->type = HID_GENERIC;
2136 } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
2137 (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
2138 error = -ENODEV;
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002139 goto fail;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002140 }
2141 }
2142
Ping Cheng401d7d12013-07-28 00:38:54 -07002143 /* set the default size in case we do not get them from hid */
2144 wacom_set_default_phy(features);
2145
Ping Chengf393ee22012-04-29 21:09:17 -07002146 /* Retrieve the physical and logical size for touch devices */
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -07002147 wacom_retrieve_hid_descriptor(hdev, features);
Ping Cheng42f4f272015-04-15 16:53:54 -07002148 wacom_setup_device_quirks(wacom);
Jason Gerecke042628a2015-04-30 17:51:54 -07002149
Jason Gereckeaa86b182015-06-15 18:01:42 -07002150 if (features->device_type == WACOM_DEVICETYPE_NONE &&
2151 features->type != WIRELESS) {
Jason Gerecke8e116d32015-04-30 17:51:55 -07002152 error = features->type == HID_GENERIC ? -ENODEV : 0;
2153
Jason Gerecke042628a2015-04-30 17:51:54 -07002154 dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
Jason Gerecke8e116d32015-04-30 17:51:55 -07002155 hdev->name,
2156 error ? "Ignoring" : "Assuming pen");
2157
2158 if (error)
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002159 goto fail;
Jason Gerecke042628a2015-04-30 17:51:54 -07002160
Jason Gereckeaa86b182015-06-15 18:01:42 -07002161 features->device_type |= WACOM_DEVICETYPE_PEN;
Jason Gerecke042628a2015-04-30 17:51:54 -07002162 }
2163
Ping Cheng401d7d12013-07-28 00:38:54 -07002164 wacom_calculate_res(features);
2165
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002166 wacom_update_name(wacom, wireless ? " (WL)" : "");
Ping Cheng4492eff2010-03-19 22:18:15 -07002167
Jason Gereckea9ce7852017-01-17 15:38:58 -08002168 error = wacom_add_shared_data(hdev);
2169 if (error)
2170 goto fail;
Ping Cheng49b764a2010-02-20 00:53:49 -08002171
Jason Gereckeccad85c2015-08-03 10:17:04 -07002172 if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07002173 (features->quirks & WACOM_QUIRK_BATTERY)) {
2174 error = wacom_initialize_battery(wacom);
2175 if (error)
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002176 goto fail;
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07002177 }
2178
Jason Gerecke3f14a632015-08-03 10:17:05 -07002179 error = wacom_register_inputs(wacom);
2180 if (error)
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002181 goto fail;
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07002182
Benjamin Tissoiresb62f6462016-07-13 18:05:50 +02002183 if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD) {
Benjamin Tissoires85d2c772016-07-13 18:05:51 +02002184 error = wacom_initialize_leds(wacom);
2185 if (error)
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002186 goto fail;
Benjamin Tissoires85d2c772016-07-13 18:05:51 +02002187
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02002188 error = wacom_initialize_remotes(wacom);
Benjamin Tissoiresb62f6462016-07-13 18:05:50 +02002189 if (error)
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002190 goto fail;
Benjamin Tissoiresb62f6462016-07-13 18:05:50 +02002191 }
2192
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002193 if (features->type == HID_GENERIC)
2194 connect_mask |= HID_CONNECT_DRIVER;
2195
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002196 /* Regular HID work starts now */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002197 error = hid_hw_start(hdev, connect_mask);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002198 if (error) {
2199 hid_err(hdev, "hw start failed\n");
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002200 goto fail;
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002201 }
2202
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002203 if (!wireless) {
2204 /* Note that if query fails it is not a hard failure */
Benjamin Tissoiresa544c612017-01-20 16:20:13 +01002205 wacom_query_tablet_data(wacom);
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002206 }
Jason Gerecke86e88f02015-11-03 16:57:58 -08002207
2208 /* touch only Bamboo doesn't support pen */
2209 if ((features->type == BAMBOO_TOUCH) &&
2210 (features->device_type & WACOM_DEVICETYPE_PEN)) {
2211 error = -ENODEV;
Benjamin Tissoiresb62f6462016-07-13 18:05:50 +02002212 goto fail_quirks;
Jason Gerecke86e88f02015-11-03 16:57:58 -08002213 }
2214
2215 /* pen only Bamboo neither support touch nor pad */
2216 if ((features->type == BAMBOO_PEN) &&
2217 ((features->device_type & WACOM_DEVICETYPE_TOUCH) ||
2218 (features->device_type & WACOM_DEVICETYPE_PAD))) {
2219 error = -ENODEV;
Benjamin Tissoiresb62f6462016-07-13 18:05:50 +02002220 goto fail_quirks;
Jason Gerecke86e88f02015-11-03 16:57:58 -08002221 }
2222
Jason Gereckeccad85c2015-08-03 10:17:04 -07002223 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002224 error = hid_hw_open(hdev);
2225
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002226 wacom_set_shared_values(wacom_wac);
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002227 devres_close_group(&hdev->dev, wacom);
2228
Ping Cheng3bea7332006-07-13 18:01:36 -07002229 return 0;
2230
Benjamin Tissoiresb62f6462016-07-13 18:05:50 +02002231fail_quirks:
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002232 hid_hw_stop(hdev);
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002233fail:
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002234 wacom_release_resources(wacom);
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002235 return error;
2236}
2237
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002238static void wacom_wireless_work(struct work_struct *work)
2239{
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002240 struct wacom *wacom = container_of(work, struct wacom, wireless_work);
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002241 struct usb_device *usbdev = wacom->usbdev;
2242 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2243 struct hid_device *hdev1, *hdev2;
2244 struct wacom *wacom1, *wacom2;
2245 struct wacom_wac *wacom_wac1, *wacom_wac2;
2246 int error;
2247
2248 /*
2249 * Regardless if this is a disconnect or a new tablet,
2250 * remove any existing input and battery devices.
2251 */
2252
2253 wacom_destroy_battery(wacom);
2254
2255 /* Stylus interface */
2256 hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
2257 wacom1 = hid_get_drvdata(hdev1);
2258 wacom_wac1 = &(wacom1->wacom_wac);
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002259 wacom_release_resources(wacom1);
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002260
2261 /* Touch interface */
2262 hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
2263 wacom2 = hid_get_drvdata(hdev2);
2264 wacom_wac2 = &(wacom2->wacom_wac);
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002265 wacom_release_resources(wacom2);
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002266
2267 if (wacom_wac->pid == 0) {
2268 hid_info(wacom->hdev, "wireless tablet disconnected\n");
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002269 } else {
2270 const struct hid_device_id *id = wacom_ids;
2271
2272 hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
2273 wacom_wac->pid);
2274
2275 while (id->bus) {
2276 if (id->vendor == USB_VENDOR_ID_WACOM &&
2277 id->product == wacom_wac->pid)
2278 break;
2279 id++;
2280 }
2281
2282 if (!id->bus) {
2283 hid_info(wacom->hdev, "ignoring unknown PID.\n");
2284 return;
2285 }
2286
2287 /* Stylus interface */
2288 wacom_wac1->features =
2289 *((struct wacom_features *)id->driver_data);
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002290
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002291 wacom_wac1->pid = wacom_wac->pid;
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002292 hid_hw_stop(hdev1);
2293 error = wacom_parse_and_register(wacom1, true);
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002294 if (error)
2295 goto fail;
2296
2297 /* Touch interface */
2298 if (wacom_wac1->features.touch_max ||
2299 (wacom_wac1->features.type >= INTUOSHT &&
2300 wacom_wac1->features.type <= BAMBOO_PT)) {
2301 wacom_wac2->features =
2302 *((struct wacom_features *)id->driver_data);
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002303 wacom_wac2->pid = wacom_wac->pid;
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002304 hid_hw_stop(hdev2);
2305 error = wacom_parse_and_register(wacom2, true);
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002306 if (error)
2307 goto fail;
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002308 }
2309
Benjamin Tissoires99569532016-07-13 18:06:17 +02002310 strlcpy(wacom_wac->name, wacom_wac1->name,
2311 sizeof(wacom_wac->name));
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002312 error = wacom_initialize_battery(wacom);
2313 if (error)
2314 goto fail;
2315 }
2316
2317 return;
2318
2319fail:
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002320 wacom_release_resources(wacom1);
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002321 wacom_release_resources(wacom2);
Benjamin Tissoiresa2f091a2016-02-12 17:27:42 +01002322 return;
2323}
2324
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002325static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
2326{
2327 struct wacom_remote *remote = wacom->remote;
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002328 u32 serial = remote->remotes[index].serial;
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002329 int i;
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02002330 unsigned long flags;
2331
2332 spin_lock_irqsave(&remote->remote_lock, flags);
2333 remote->remotes[index].registered = false;
2334 spin_unlock_irqrestore(&remote->remote_lock, flags);
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002335
Benjamin Tissoires9f1015d42016-07-13 18:06:09 +02002336 if (remote->remotes[index].battery.battery)
2337 devres_release_group(&wacom->hdev->dev,
2338 &remote->remotes[index].battery.bat_desc);
2339
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002340 if (remote->remotes[index].group.name)
2341 devres_release_group(&wacom->hdev->dev,
2342 &remote->remotes[index]);
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002343
2344 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002345 if (remote->remotes[i].serial == serial) {
2346 remote->remotes[i].serial = 0;
2347 remote->remotes[i].group.name = NULL;
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02002348 remote->remotes[i].registered = false;
Benjamin Tissoires9f1015d42016-07-13 18:06:09 +02002349 remote->remotes[i].battery.battery = NULL;
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002350 wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
2351 }
2352 }
2353}
2354
2355static int wacom_remote_create_one(struct wacom *wacom, u32 serial,
2356 unsigned int index)
2357{
2358 struct wacom_remote *remote = wacom->remote;
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02002359 struct device *dev = &wacom->hdev->dev;
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002360 int error, k;
2361
2362 /* A remote can pair more than once with an EKR,
2363 * check to make sure this serial isn't already paired.
2364 */
2365 for (k = 0; k < WACOM_MAX_REMOTES; k++) {
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002366 if (remote->remotes[k].serial == serial)
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002367 break;
2368 }
2369
2370 if (k < WACOM_MAX_REMOTES) {
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002371 remote->remotes[index].serial = serial;
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002372 return 0;
2373 }
2374
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002375 if (!devres_open_group(dev, &remote->remotes[index], GFP_KERNEL))
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02002376 return -ENOMEM;
2377
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002378 error = wacom_remote_create_attr_group(wacom, serial, index);
2379 if (error)
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02002380 goto fail;
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002381
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02002382 remote->remotes[index].input = wacom_allocate_input(wacom);
2383 if (!remote->remotes[index].input) {
2384 error = -ENOMEM;
2385 goto fail;
2386 }
2387 remote->remotes[index].input->uniq = remote->remotes[index].group.name;
2388 remote->remotes[index].input->name = wacom->wacom_wac.pad_name;
2389
2390 if (!remote->remotes[index].input->name) {
2391 error = -EINVAL;
2392 goto fail;
2393 }
2394
2395 error = wacom_setup_pad_input_capabilities(remote->remotes[index].input,
2396 &wacom->wacom_wac);
2397 if (error)
2398 goto fail;
2399
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002400 remote->remotes[index].serial = serial;
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002401
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02002402 error = input_register_device(remote->remotes[index].input);
2403 if (error)
2404 goto fail;
2405
Benjamin Tissoires97f55412016-07-13 18:06:10 +02002406 error = wacom_led_groups_alloc_and_register_one(
2407 &remote->remotes[index].input->dev,
2408 wacom, index, 3, true);
2409 if (error)
2410 goto fail;
2411
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02002412 remote->remotes[index].registered = true;
2413
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002414 devres_close_group(dev, &remote->remotes[index]);
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002415 return 0;
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02002416
2417fail:
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002418 devres_release_group(dev, &remote->remotes[index]);
2419 remote->remotes[index].serial = 0;
Benjamin Tissoiresf9036bd2016-07-13 18:06:05 +02002420 return error;
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002421}
2422
Benjamin Tissoires9f1015d42016-07-13 18:06:09 +02002423static int wacom_remote_attach_battery(struct wacom *wacom, int index)
2424{
2425 struct wacom_remote *remote = wacom->remote;
2426 int error;
2427
2428 if (!remote->remotes[index].registered)
2429 return 0;
2430
2431 if (remote->remotes[index].battery.battery)
2432 return 0;
2433
2434 if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
2435 return 0;
2436
2437 error = __wacom_initialize_battery(wacom,
2438 &wacom->remote->remotes[index].battery);
2439 if (error)
2440 return error;
2441
2442 return 0;
2443}
2444
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002445static void wacom_remote_work(struct work_struct *work)
2446{
2447 struct wacom *wacom = container_of(work, struct wacom, remote_work);
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02002448 struct wacom_remote *remote = wacom->remote;
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002449 struct wacom_remote_data data;
2450 unsigned long flags;
2451 unsigned int count;
2452 u32 serial;
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002453 int i;
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002454
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02002455 spin_lock_irqsave(&remote->remote_lock, flags);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002456
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02002457 count = kfifo_out(&remote->remote_fifo, &data, sizeof(data));
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002458
2459 if (count != sizeof(data)) {
2460 hid_err(wacom->hdev,
2461 "workitem triggered without status available\n");
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02002462 spin_unlock_irqrestore(&remote->remote_lock, flags);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002463 return;
2464 }
2465
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02002466 if (!kfifo_is_empty(&remote->remote_fifo))
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002467 wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_REMOTE);
2468
Benjamin Tissoires83e6b402016-07-13 18:06:02 +02002469 spin_unlock_irqrestore(&remote->remote_lock, flags);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002470
2471 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
2472 serial = data.remote[i].serial;
2473 if (data.remote[i].connected) {
2474
Benjamin Tissoires9f1015d42016-07-13 18:06:09 +02002475 if (remote->remotes[i].serial == serial) {
2476 wacom_remote_attach_battery(wacom, i);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002477 continue;
Benjamin Tissoires9f1015d42016-07-13 18:06:09 +02002478 }
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002479
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002480 if (remote->remotes[i].serial)
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002481 wacom_remote_destroy_one(wacom, i);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002482
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002483 wacom_remote_create_one(wacom, serial, i);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002484
Benjamin Tissoirese7749f62016-07-13 18:06:06 +02002485 } else if (remote->remotes[i].serial) {
Benjamin Tissoires04bfa272016-07-13 18:06:04 +02002486 wacom_remote_destroy_one(wacom, i);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002487 }
2488 }
2489}
2490
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002491static int wacom_probe(struct hid_device *hdev,
2492 const struct hid_device_id *id)
2493{
2494 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
2495 struct usb_device *dev = interface_to_usbdev(intf);
2496 struct wacom *wacom;
2497 struct wacom_wac *wacom_wac;
2498 struct wacom_features *features;
2499 int error;
2500
2501 if (!id->driver_data)
2502 return -EINVAL;
2503
2504 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
2505
2506 /* hid-core sets this quirk for the boot interface */
2507 hdev->quirks &= ~HID_QUIRK_NOGET;
2508
Benjamin Tissoires19b64332016-07-13 18:05:58 +02002509 wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL);
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002510 if (!wacom)
2511 return -ENOMEM;
2512
2513 hid_set_drvdata(hdev, wacom);
2514 wacom->hdev = hdev;
2515
2516 wacom_wac = &wacom->wacom_wac;
2517 wacom_wac->features = *((struct wacom_features *)id->driver_data);
2518 features = &wacom_wac->features;
2519
2520 if (features->check_for_hid_type && features->hid_type != hdev->type) {
2521 error = -ENODEV;
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002522 goto fail;
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002523 }
2524
Jason Gereckec6fa1ae2016-04-04 11:26:51 -07002525 wacom_wac->hid_data.inputmode = -1;
Jason Gerecke326ea2a2016-04-04 11:26:52 -07002526 wacom_wac->mode_report = -1;
Jason Gereckec6fa1ae2016-04-04 11:26:51 -07002527
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002528 wacom->usbdev = dev;
2529 wacom->intf = intf;
2530 mutex_init(&wacom->lock);
Benjamin Tissoiresa544c612017-01-20 16:20:13 +01002531 INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work);
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002532 INIT_WORK(&wacom->wireless_work, wacom_wireless_work);
2533 INIT_WORK(&wacom->battery_work, wacom_battery_work);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002534 INIT_WORK(&wacom->remote_work, wacom_remote_work);
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002535
2536 /* ask for the report descriptor to be loaded by HID */
2537 error = hid_parse(hdev);
2538 if (error) {
2539 hid_err(hdev, "parse failed\n");
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002540 goto fail;
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002541 }
2542
Benjamin Tissoiresfd5f92b2016-02-12 17:27:43 +01002543 error = wacom_parse_and_register(wacom, false);
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002544 if (error)
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002545 goto fail;
Benjamin Tissoiresc58ac3a2016-02-12 17:27:41 +01002546
2547 if (hdev->bus == BUS_BLUETOOTH) {
2548 error = device_create_file(&hdev->dev, &dev_attr_speed);
2549 if (error)
2550 hid_warn(hdev,
2551 "can't create sysfs speed attribute err: %d\n",
2552 error);
2553 }
2554
2555 return 0;
2556
Benjamin Tissoires3888b0d2016-07-13 18:06:03 +02002557fail:
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002558 hid_set_drvdata(hdev, NULL);
Dmitry Torokhov50141862007-04-12 01:33:39 -04002559 return error;
Ping Cheng3bea7332006-07-13 18:01:36 -07002560}
2561
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002562static void wacom_remove(struct hid_device *hdev)
Ping Cheng3bea7332006-07-13 18:01:36 -07002563{
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002564 struct wacom *wacom = hid_get_drvdata(hdev);
Benjamin Tissoiresf6205162016-02-12 17:27:45 +01002565 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2566 struct wacom_features *features = &wacom_wac->features;
2567
2568 if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
2569 hid_hw_close(hdev);
Ping Cheng3bea7332006-07-13 18:01:36 -07002570
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002571 hid_hw_stop(hdev);
Oliver Neukume7224092008-04-15 01:31:57 -04002572
Benjamin Tissoiresa544c612017-01-20 16:20:13 +01002573 cancel_delayed_work_sync(&wacom->init_work);
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002574 cancel_work_sync(&wacom->wireless_work);
2575 cancel_work_sync(&wacom->battery_work);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002576 cancel_work_sync(&wacom->remote_work);
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07002577 if (hdev->bus == BUS_BLUETOOTH)
2578 device_remove_file(&hdev->dev, &dev_attr_speed);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002579
Benjamin Tissoiresc0265a942017-01-20 16:20:12 +01002580 /* make sure we don't trigger the LEDs */
2581 wacom_led_groups_release(wacom);
Benjamin Tissoires5b779fc2017-01-20 16:20:11 +01002582 wacom_release_resources(wacom);
2583
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002584 hid_set_drvdata(hdev, NULL);
Oliver Neukume7224092008-04-15 01:31:57 -04002585}
2586
Geert Uytterhoeven41a74582014-08-11 11:03:19 -07002587#ifdef CONFIG_PM
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002588static int wacom_resume(struct hid_device *hdev)
Oliver Neukume7224092008-04-15 01:31:57 -04002589{
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002590 struct wacom *wacom = hid_get_drvdata(hdev);
Oliver Neukume7224092008-04-15 01:31:57 -04002591
2592 mutex_lock(&wacom->lock);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002593
2594 /* switch to wacom mode first */
Benjamin Tissoiresa544c612017-01-20 16:20:13 +01002595 _wacom_query_tablet_data(wacom);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002596 wacom_led_control(wacom);
2597
Oliver Neukume7224092008-04-15 01:31:57 -04002598 mutex_unlock(&wacom->lock);
2599
2600 return 0;
2601}
2602
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002603static int wacom_reset_resume(struct hid_device *hdev)
Oliver Neukume7224092008-04-15 01:31:57 -04002604{
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002605 return wacom_resume(hdev);
Oliver Neukume7224092008-04-15 01:31:57 -04002606}
Geert Uytterhoeven41a74582014-08-11 11:03:19 -07002607#endif /* CONFIG_PM */
Oliver Neukume7224092008-04-15 01:31:57 -04002608
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002609static struct hid_driver wacom_driver = {
Ping Cheng3bea7332006-07-13 18:01:36 -07002610 .name = "wacom",
Bastian Blankb036f6f2010-02-10 23:06:23 -08002611 .id_table = wacom_ids,
Ping Cheng3bea7332006-07-13 18:01:36 -07002612 .probe = wacom_probe,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002613 .remove = wacom_remove,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002614 .report = wacom_wac_report,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002615#ifdef CONFIG_PM
Oliver Neukume7224092008-04-15 01:31:57 -04002616 .resume = wacom_resume,
2617 .reset_resume = wacom_reset_resume,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002618#endif
2619 .raw_event = wacom_raw_event,
Ping Cheng3bea7332006-07-13 18:01:36 -07002620};
Benjamin Tissoires29b47392014-07-24 12:52:23 -07002621module_hid_driver(wacom_driver);
Benjamin Tissoiresf2e0a7d2014-08-06 14:07:49 -07002622
2623MODULE_VERSION(DRIVER_VERSION);
2624MODULE_AUTHOR(DRIVER_AUTHOR);
2625MODULE_DESCRIPTION(DRIVER_DESC);
Grant Grundler7021b602017-01-05 11:07:04 -08002626MODULE_LICENSE("GPL");