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