]>
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" |
3bea733a | 16 | |
545f4e99 PC |
17 | /* defines to get HID report descriptor */ |
18 | #define HID_DEVICET_HID (USB_TYPE_CLASS | 0x01) | |
19 | #define HID_DEVICET_REPORT (USB_TYPE_CLASS | 0x02) | |
20 | #define HID_USAGE_UNDEFINED 0x00 | |
21 | #define HID_USAGE_PAGE 0x05 | |
22 | #define HID_USAGE_PAGE_DIGITIZER 0x0d | |
23 | #define HID_USAGE_PAGE_DESKTOP 0x01 | |
24 | #define HID_USAGE 0x09 | |
25 | #define HID_USAGE_X 0x30 | |
26 | #define HID_USAGE_Y 0x31 | |
27 | #define HID_USAGE_X_TILT 0x3d | |
28 | #define HID_USAGE_Y_TILT 0x3e | |
29 | #define HID_USAGE_FINGER 0x22 | |
30 | #define HID_USAGE_STYLUS 0x20 | |
f393ee2b | 31 | #define HID_USAGE_CONTACTMAX 0x55 |
4134361a CB |
32 | #define HID_COLLECTION 0xa1 |
33 | #define HID_COLLECTION_LOGICAL 0x02 | |
34 | #define HID_COLLECTION_END 0xc0 | |
545f4e99 PC |
35 | |
36 | enum { | |
37 | WCM_UNDEFINED = 0, | |
38 | WCM_DESKTOP, | |
39 | WCM_DIGITIZER, | |
40 | }; | |
41 | ||
42 | struct hid_descriptor { | |
43 | struct usb_descriptor_header header; | |
44 | __le16 bcdHID; | |
45 | u8 bCountryCode; | |
46 | u8 bNumDescriptors; | |
47 | u8 bDescriptorType; | |
48 | __le16 wDescriptorLength; | |
49 | } __attribute__ ((packed)); | |
50 | ||
51 | /* defines to get/set USB message */ | |
3bea733a PC |
52 | #define USB_REQ_GET_REPORT 0x01 |
53 | #define USB_REQ_SET_REPORT 0x09 | |
5d7e7d47 | 54 | |
545f4e99 | 55 | #define WAC_HID_FEATURE_REPORT 0x03 |
a417ea44 | 56 | #define WAC_MSG_RETRIES 5 |
3bea733a | 57 | |
5d7e7d47 EH |
58 | #define WAC_CMD_LED_CONTROL 0x20 |
59 | #define WAC_CMD_ICON_START 0x21 | |
60 | #define WAC_CMD_ICON_XFER 0x23 | |
61 | #define WAC_CMD_RETRIES 10 | |
62 | ||
63 | static int wacom_get_report(struct usb_interface *intf, u8 type, u8 id, | |
64 | void *buf, size_t size, unsigned int retries) | |
3bea733a | 65 | { |
5d7e7d47 EH |
66 | struct usb_device *dev = interface_to_usbdev(intf); |
67 | int retval; | |
68 | ||
69 | do { | |
70 | retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
71 | USB_REQ_GET_REPORT, | |
6e8ec537 CB |
72 | USB_DIR_IN | USB_TYPE_CLASS | |
73 | USB_RECIP_INTERFACE, | |
5d7e7d47 EH |
74 | (type << 8) + id, |
75 | intf->altsetting[0].desc.bInterfaceNumber, | |
76 | buf, size, 100); | |
77 | } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries); | |
78 | ||
79 | return retval; | |
3bea733a PC |
80 | } |
81 | ||
5d7e7d47 EH |
82 | static int wacom_set_report(struct usb_interface *intf, u8 type, u8 id, |
83 | void *buf, size_t size, unsigned int retries) | |
3bea733a | 84 | { |
5d7e7d47 EH |
85 | struct usb_device *dev = interface_to_usbdev(intf); |
86 | int retval; | |
87 | ||
88 | do { | |
89 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | |
90 | USB_REQ_SET_REPORT, | |
91 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | |
92 | (type << 8) + id, | |
93 | intf->altsetting[0].desc.bInterfaceNumber, | |
94 | buf, size, 1000); | |
95 | } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries); | |
96 | ||
97 | return retval; | |
3bea733a PC |
98 | } |
99 | ||
54c9b226 | 100 | static void wacom_sys_irq(struct urb *urb) |
3bea733a PC |
101 | { |
102 | struct wacom *wacom = urb->context; | |
3bea733a PC |
103 | int retval; |
104 | ||
105 | switch (urb->status) { | |
106 | case 0: | |
107 | /* success */ | |
108 | break; | |
109 | case -ECONNRESET: | |
110 | case -ENOENT: | |
111 | case -ESHUTDOWN: | |
112 | /* this urb is terminated, clean up */ | |
ea3e6c59 | 113 | dbg("%s - urb shutting down with status: %d", __func__, urb->status); |
3bea733a PC |
114 | return; |
115 | default: | |
ea3e6c59 | 116 | dbg("%s - nonzero urb status received: %d", __func__, urb->status); |
3bea733a PC |
117 | goto exit; |
118 | } | |
119 | ||
95dd3b30 | 120 | wacom_wac_irq(&wacom->wacom_wac, urb->actual_length); |
3bea733a PC |
121 | |
122 | exit: | |
e7224094 | 123 | usb_mark_last_busy(wacom->usbdev); |
73a97f4f | 124 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
3bea733a PC |
125 | if (retval) |
126 | err ("%s - usb_submit_urb failed with result %d", | |
ea3e6c59 | 127 | __func__, retval); |
3bea733a PC |
128 | } |
129 | ||
3bea733a PC |
130 | static int wacom_open(struct input_dev *dev) |
131 | { | |
7791bdae | 132 | struct wacom *wacom = input_get_drvdata(dev); |
f6cd3783 | 133 | int retval = 0; |
3bea733a | 134 | |
f6cd3783 | 135 | if (usb_autopm_get_interface(wacom->intf) < 0) |
3bea733a | 136 | return -EIO; |
f6cd3783 DT |
137 | |
138 | mutex_lock(&wacom->lock); | |
e7224094 ON |
139 | |
140 | if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { | |
f6cd3783 DT |
141 | retval = -EIO; |
142 | goto out; | |
e7224094 ON |
143 | } |
144 | ||
51269fe8 | 145 | wacom->open = true; |
e7224094 | 146 | wacom->intf->needs_remote_wakeup = 1; |
3bea733a | 147 | |
f6cd3783 | 148 | out: |
e7224094 | 149 | mutex_unlock(&wacom->lock); |
62ecae09 | 150 | usb_autopm_put_interface(wacom->intf); |
f6cd3783 | 151 | return retval; |
3bea733a PC |
152 | } |
153 | ||
154 | static void wacom_close(struct input_dev *dev) | |
155 | { | |
7791bdae | 156 | struct wacom *wacom = input_get_drvdata(dev); |
62ecae09 DT |
157 | int autopm_error; |
158 | ||
159 | autopm_error = usb_autopm_get_interface(wacom->intf); | |
3bea733a | 160 | |
e7224094 | 161 | mutex_lock(&wacom->lock); |
3bea733a | 162 | usb_kill_urb(wacom->irq); |
51269fe8 | 163 | wacom->open = false; |
e7224094 ON |
164 | wacom->intf->needs_remote_wakeup = 0; |
165 | mutex_unlock(&wacom->lock); | |
f6cd3783 | 166 | |
62ecae09 DT |
167 | if (!autopm_error) |
168 | usb_autopm_put_interface(wacom->intf); | |
3bea733a PC |
169 | } |
170 | ||
16bf288c CB |
171 | /* |
172 | * Static values for max X/Y and resolution of Pen interface is stored in | |
173 | * features. This mean physical size of active area can be computed. | |
174 | * This is useful to do when Pen and Touch have same active area of tablet. | |
175 | * This means for Touch device, we only need to find max X/Y value and we | |
176 | * have enough information to compute resolution of touch. | |
177 | */ | |
178 | static void wacom_set_phy_from_res(struct wacom_features *features) | |
179 | { | |
180 | features->x_phy = (features->x_max * 100) / features->x_resolution; | |
181 | features->y_phy = (features->y_max * 100) / features->y_resolution; | |
182 | } | |
183 | ||
4134361a CB |
184 | static int wacom_parse_logical_collection(unsigned char *report, |
185 | struct wacom_features *features) | |
186 | { | |
187 | int length = 0; | |
188 | ||
189 | if (features->type == BAMBOO_PT) { | |
190 | ||
191 | /* Logical collection is only used by 3rd gen Bamboo Touch */ | |
192 | features->pktlen = WACOM_PKGLEN_BBTOUCH3; | |
8b4a0c1f | 193 | features->device_type = BTN_TOOL_FINGER; |
4134361a | 194 | |
16bf288c | 195 | wacom_set_phy_from_res(features); |
4134361a CB |
196 | |
197 | features->x_max = features->y_max = | |
198 | get_unaligned_le16(&report[10]); | |
199 | ||
200 | length = 11; | |
201 | } | |
202 | return length; | |
203 | } | |
204 | ||
f393ee2b PC |
205 | static void wacom_retrieve_report_data(struct usb_interface *intf, |
206 | struct wacom_features *features) | |
207 | { | |
208 | int result = 0; | |
209 | unsigned char *rep_data; | |
210 | ||
211 | rep_data = kmalloc(2, GFP_KERNEL); | |
212 | if (rep_data) { | |
213 | ||
214 | rep_data[0] = 12; | |
215 | result = wacom_get_report(intf, WAC_HID_FEATURE_REPORT, | |
61c91dd4 | 216 | rep_data[0], rep_data, 2, |
f393ee2b PC |
217 | WAC_MSG_RETRIES); |
218 | ||
219 | if (result >= 0 && rep_data[1] > 2) | |
220 | features->touch_max = rep_data[1]; | |
221 | ||
222 | kfree(rep_data); | |
223 | } | |
224 | } | |
225 | ||
428f8588 CB |
226 | /* |
227 | * Interface Descriptor of wacom devices can be incomplete and | |
228 | * inconsistent so wacom_features table is used to store stylus | |
229 | * device's packet lengths, various maximum values, and tablet | |
230 | * resolution based on product ID's. | |
231 | * | |
232 | * For devices that contain 2 interfaces, wacom_features table is | |
233 | * inaccurate for the touch interface. Since the Interface Descriptor | |
234 | * for touch interfaces has pretty complete data, this function exists | |
235 | * to query tablet for this missing information instead of hard coding in | |
236 | * an additional table. | |
237 | * | |
238 | * A typical Interface Descriptor for a stylus will contain a | |
239 | * boot mouse application collection that is not of interest and this | |
240 | * function will ignore it. | |
241 | * | |
242 | * It also contains a digitizer application collection that also is not | |
243 | * of interest since any information it contains would be duplicate | |
244 | * of what is in wacom_features. Usually it defines a report of an array | |
245 | * of bytes that could be used as max length of the stylus packet returned. | |
246 | * If it happens to define a Digitizer-Stylus Physical Collection then | |
247 | * the X and Y logical values contain valid data but it is ignored. | |
248 | * | |
249 | * A typical Interface Descriptor for a touch interface will contain a | |
250 | * Digitizer-Finger Physical Collection which will define both logical | |
251 | * X/Y maximum as well as the physical size of tablet. Since touch | |
252 | * interfaces haven't supported pressure or distance, this is enough | |
253 | * information to override invalid values in the wacom_features table. | |
4134361a CB |
254 | * |
255 | * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical | |
256 | * Collection. Instead they define a Logical Collection with a single | |
257 | * Logical Maximum for both X and Y. | |
ae584ca4 JG |
258 | * |
259 | * Intuos5 touch interface does not contain useful data. We deal with | |
260 | * this after returning from this function. | |
428f8588 CB |
261 | */ |
262 | static int wacom_parse_hid(struct usb_interface *intf, | |
263 | struct hid_descriptor *hid_desc, | |
ec67bbed | 264 | struct wacom_features *features) |
545f4e99 PC |
265 | { |
266 | struct usb_device *dev = interface_to_usbdev(intf); | |
ec67bbed PC |
267 | char limit = 0; |
268 | /* result has to be defined as int for some devices */ | |
269 | int result = 0; | |
545f4e99 PC |
270 | int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0; |
271 | unsigned char *report; | |
272 | ||
273 | report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL); | |
274 | if (!report) | |
275 | return -ENOMEM; | |
276 | ||
277 | /* retrive report descriptors */ | |
278 | do { | |
279 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
280 | USB_REQ_GET_DESCRIPTOR, | |
281 | USB_RECIP_INTERFACE | USB_DIR_IN, | |
282 | HID_DEVICET_REPORT << 8, | |
283 | intf->altsetting[0].desc.bInterfaceNumber, /* interface */ | |
284 | report, | |
285 | hid_desc->wDescriptorLength, | |
286 | 5000); /* 5 secs */ | |
a417ea44 | 287 | } while (result < 0 && limit++ < WAC_MSG_RETRIES); |
545f4e99 | 288 | |
384318ec | 289 | /* No need to parse the Descriptor. It isn't an error though */ |
545f4e99 PC |
290 | if (result < 0) |
291 | goto out; | |
292 | ||
293 | for (i = 0; i < hid_desc->wDescriptorLength; i++) { | |
294 | ||
295 | switch (report[i]) { | |
296 | case HID_USAGE_PAGE: | |
297 | switch (report[i + 1]) { | |
298 | case HID_USAGE_PAGE_DIGITIZER: | |
299 | usage = WCM_DIGITIZER; | |
300 | i++; | |
301 | break; | |
302 | ||
303 | case HID_USAGE_PAGE_DESKTOP: | |
304 | usage = WCM_DESKTOP; | |
305 | i++; | |
306 | break; | |
307 | } | |
308 | break; | |
309 | ||
310 | case HID_USAGE: | |
311 | switch (report[i + 1]) { | |
312 | case HID_USAGE_X: | |
313 | if (usage == WCM_DESKTOP) { | |
314 | if (finger) { | |
84eb5aa6 | 315 | features->device_type = BTN_TOOL_FINGER; |
ec67bbed PC |
316 | if (features->type == TABLETPC2FG) { |
317 | /* need to reset back */ | |
318 | features->pktlen = WACOM_PKGLEN_TPC2FG; | |
ec67bbed | 319 | } |
1963518b PC |
320 | |
321 | if (features->type == MTSCREEN) | |
322 | features->pktlen = WACOM_PKGLEN_MTOUCH; | |
323 | ||
4a88081e PC |
324 | if (features->type == BAMBOO_PT) { |
325 | /* need to reset back */ | |
326 | features->pktlen = WACOM_PKGLEN_BBTOUCH; | |
4a88081e PC |
327 | features->x_phy = |
328 | get_unaligned_le16(&report[i + 5]); | |
329 | features->x_max = | |
330 | get_unaligned_le16(&report[i + 8]); | |
331 | i += 15; | |
332 | } else { | |
333 | features->x_max = | |
334 | get_unaligned_le16(&report[i + 3]); | |
335 | features->x_phy = | |
336 | get_unaligned_le16(&report[i + 6]); | |
337 | features->unit = report[i + 9]; | |
338 | features->unitExpo = report[i + 11]; | |
339 | i += 12; | |
340 | } | |
545f4e99 | 341 | } else if (pen) { |
ec67bbed PC |
342 | /* penabled only accepts exact bytes of data */ |
343 | if (features->type == TABLETPC2FG) | |
57e413d9 | 344 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
ec67bbed | 345 | features->device_type = BTN_TOOL_PEN; |
545f4e99 | 346 | features->x_max = |
252f7769 | 347 | get_unaligned_le16(&report[i + 3]); |
545f4e99 PC |
348 | i += 4; |
349 | } | |
545f4e99 PC |
350 | } |
351 | break; | |
352 | ||
353 | case HID_USAGE_Y: | |
ec67bbed PC |
354 | if (usage == WCM_DESKTOP) { |
355 | if (finger) { | |
1963518b PC |
356 | int type = features->type; |
357 | ||
358 | if (type == TABLETPC2FG || type == MTSCREEN) { | |
ec67bbed | 359 | features->y_max = |
252f7769 | 360 | get_unaligned_le16(&report[i + 3]); |
ec67bbed | 361 | features->y_phy = |
252f7769 | 362 | get_unaligned_le16(&report[i + 6]); |
ec67bbed | 363 | i += 7; |
1963518b | 364 | } else if (type == BAMBOO_PT) { |
4a88081e PC |
365 | features->y_phy = |
366 | get_unaligned_le16(&report[i + 3]); | |
367 | features->y_max = | |
368 | get_unaligned_le16(&report[i + 6]); | |
369 | i += 12; | |
ec67bbed PC |
370 | } else { |
371 | features->y_max = | |
372 | features->x_max; | |
373 | features->y_phy = | |
252f7769 | 374 | get_unaligned_le16(&report[i + 3]); |
ec67bbed PC |
375 | i += 4; |
376 | } | |
377 | } else if (pen) { | |
ec67bbed | 378 | features->y_max = |
252f7769 | 379 | get_unaligned_le16(&report[i + 3]); |
ec67bbed PC |
380 | i += 4; |
381 | } | |
382 | } | |
545f4e99 PC |
383 | break; |
384 | ||
385 | case HID_USAGE_FINGER: | |
386 | finger = 1; | |
387 | i++; | |
388 | break; | |
389 | ||
428f8588 CB |
390 | /* |
391 | * Requiring Stylus Usage will ignore boot mouse | |
392 | * X/Y values and some cases of invalid Digitizer X/Y | |
393 | * values commonly reported. | |
394 | */ | |
545f4e99 PC |
395 | case HID_USAGE_STYLUS: |
396 | pen = 1; | |
397 | i++; | |
398 | break; | |
f393ee2b PC |
399 | |
400 | case HID_USAGE_CONTACTMAX: | |
1cecc5cc PC |
401 | /* leave touch_max as is if predefined */ |
402 | if (!features->touch_max) | |
403 | wacom_retrieve_report_data(intf, features); | |
f393ee2b PC |
404 | i++; |
405 | break; | |
545f4e99 PC |
406 | } |
407 | break; | |
408 | ||
4134361a | 409 | case HID_COLLECTION_END: |
ec67bbed | 410 | /* reset UsagePage and Finger */ |
545f4e99 PC |
411 | finger = usage = 0; |
412 | break; | |
4134361a CB |
413 | |
414 | case HID_COLLECTION: | |
415 | i++; | |
416 | switch (report[i]) { | |
417 | case HID_COLLECTION_LOGICAL: | |
418 | i += wacom_parse_logical_collection(&report[i], | |
419 | features); | |
420 | break; | |
421 | } | |
422 | break; | |
545f4e99 PC |
423 | } |
424 | } | |
425 | ||
545f4e99 | 426 | out: |
384318ec | 427 | result = 0; |
545f4e99 PC |
428 | kfree(report); |
429 | return result; | |
430 | } | |
431 | ||
ec67bbed | 432 | static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features) |
3b7307c2 DT |
433 | { |
434 | unsigned char *rep_data; | |
ec67bbed PC |
435 | int limit = 0, report_id = 2; |
436 | int error = -ENOMEM; | |
3b7307c2 | 437 | |
3b48c91c | 438 | rep_data = kmalloc(4, GFP_KERNEL); |
3b7307c2 | 439 | if (!rep_data) |
ec67bbed PC |
440 | return error; |
441 | ||
1963518b PC |
442 | /* ask to report Wacom data */ |
443 | if (features->device_type == BTN_TOOL_FINGER) { | |
444 | /* if it is an MT Tablet PC touch */ | |
445 | if (features->type == TABLETPC2FG || | |
446 | features->type == MTSCREEN) { | |
447 | do { | |
448 | rep_data[0] = 3; | |
449 | rep_data[1] = 4; | |
450 | rep_data[2] = 0; | |
451 | rep_data[3] = 0; | |
452 | report_id = 3; | |
453 | error = wacom_set_report(intf, | |
454 | WAC_HID_FEATURE_REPORT, | |
455 | report_id, | |
456 | rep_data, 4, 1); | |
457 | if (error >= 0) | |
458 | error = wacom_get_report(intf, | |
459 | WAC_HID_FEATURE_REPORT, | |
460 | report_id, | |
461 | rep_data, 4, 1); | |
462 | } while ((error < 0 || rep_data[1] != 4) && | |
463 | limit++ < WAC_MSG_RETRIES); | |
464 | } | |
6e8ec537 | 465 | } else if (features->type != TABLETPC && |
d3825d51 | 466 | features->type != WIRELESS && |
6e8ec537 | 467 | features->device_type == BTN_TOOL_PEN) { |
ec67bbed PC |
468 | do { |
469 | rep_data[0] = 2; | |
470 | rep_data[1] = 2; | |
5d7e7d47 EH |
471 | error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT, |
472 | report_id, rep_data, 2, 1); | |
ec67bbed | 473 | if (error >= 0) |
5d7e7d47 EH |
474 | error = wacom_get_report(intf, |
475 | WAC_HID_FEATURE_REPORT, | |
476 | report_id, rep_data, 2, 1); | |
a417ea44 | 477 | } while ((error < 0 || rep_data[1] != 2) && limit++ < WAC_MSG_RETRIES); |
ec67bbed | 478 | } |
3b7307c2 DT |
479 | |
480 | kfree(rep_data); | |
481 | ||
482 | return error < 0 ? error : 0; | |
483 | } | |
484 | ||
ec67bbed | 485 | static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, |
1963518b | 486 | struct wacom_features *features) |
ec67bbed PC |
487 | { |
488 | int error = 0; | |
489 | struct usb_host_interface *interface = intf->cur_altsetting; | |
490 | struct hid_descriptor *hid_desc; | |
491 | ||
fed87e65 | 492 | /* default features */ |
ec67bbed | 493 | features->device_type = BTN_TOOL_PEN; |
fed87e65 HR |
494 | features->x_fuzz = 4; |
495 | features->y_fuzz = 4; | |
496 | features->pressure_fuzz = 0; | |
497 | features->distance_fuzz = 0; | |
ec67bbed | 498 | |
d3825d51 CB |
499 | /* |
500 | * The wireless device HID is basic and layout conflicts with | |
501 | * other tablets (monitor and touch interface can look like pen). | |
502 | * Skip the query for this type and modify defaults based on | |
503 | * interface number. | |
504 | */ | |
505 | if (features->type == WIRELESS) { | |
506 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) { | |
507 | features->device_type = 0; | |
508 | } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) { | |
509 | features->device_type = BTN_TOOL_DOUBLETAP; | |
510 | features->pktlen = WACOM_PKGLEN_BBTOUCH3; | |
511 | } | |
512 | } | |
513 | ||
1963518b PC |
514 | /* only devices that support touch need to retrieve the info */ |
515 | if (features->type != TABLETPC && | |
516 | features->type != TABLETPC2FG && | |
517 | features->type != BAMBOO_PT && | |
518 | features->type != MTSCREEN) { | |
ec67bbed | 519 | goto out; |
1963518b | 520 | } |
ec67bbed | 521 | |
a882c932 DT |
522 | error = usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc); |
523 | if (error) { | |
524 | error = usb_get_extra_descriptor(&interface->endpoint[0], | |
525 | HID_DEVICET_REPORT, &hid_desc); | |
526 | if (error) { | |
eb71d1bb DT |
527 | dev_err(&intf->dev, |
528 | "can not retrieve extra class descriptor\n"); | |
ec67bbed PC |
529 | goto out; |
530 | } | |
531 | } | |
532 | error = wacom_parse_hid(intf, hid_desc, features); | |
533 | if (error) | |
534 | goto out; | |
535 | ||
ec67bbed PC |
536 | out: |
537 | return error; | |
538 | } | |
539 | ||
4492efff PC |
540 | struct wacom_usbdev_data { |
541 | struct list_head list; | |
542 | struct kref kref; | |
543 | struct usb_device *dev; | |
544 | struct wacom_shared shared; | |
545 | }; | |
546 | ||
547 | static LIST_HEAD(wacom_udev_list); | |
548 | static DEFINE_MUTEX(wacom_udev_list_lock); | |
549 | ||
550 | static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev) | |
551 | { | |
552 | struct wacom_usbdev_data *data; | |
553 | ||
554 | list_for_each_entry(data, &wacom_udev_list, list) { | |
555 | if (data->dev == dev) { | |
556 | kref_get(&data->kref); | |
557 | return data; | |
558 | } | |
559 | } | |
560 | ||
561 | return NULL; | |
562 | } | |
563 | ||
564 | static int wacom_add_shared_data(struct wacom_wac *wacom, | |
565 | struct usb_device *dev) | |
566 | { | |
567 | struct wacom_usbdev_data *data; | |
568 | int retval = 0; | |
569 | ||
570 | mutex_lock(&wacom_udev_list_lock); | |
571 | ||
572 | data = wacom_get_usbdev_data(dev); | |
573 | if (!data) { | |
574 | data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL); | |
575 | if (!data) { | |
576 | retval = -ENOMEM; | |
577 | goto out; | |
578 | } | |
579 | ||
580 | kref_init(&data->kref); | |
581 | data->dev = dev; | |
582 | list_add_tail(&data->list, &wacom_udev_list); | |
583 | } | |
584 | ||
585 | wacom->shared = &data->shared; | |
586 | ||
587 | out: | |
588 | mutex_unlock(&wacom_udev_list_lock); | |
589 | return retval; | |
590 | } | |
591 | ||
592 | static void wacom_release_shared_data(struct kref *kref) | |
593 | { | |
594 | struct wacom_usbdev_data *data = | |
595 | container_of(kref, struct wacom_usbdev_data, kref); | |
596 | ||
597 | mutex_lock(&wacom_udev_list_lock); | |
598 | list_del(&data->list); | |
599 | mutex_unlock(&wacom_udev_list_lock); | |
600 | ||
601 | kfree(data); | |
602 | } | |
603 | ||
604 | static void wacom_remove_shared_data(struct wacom_wac *wacom) | |
605 | { | |
606 | struct wacom_usbdev_data *data; | |
607 | ||
608 | if (wacom->shared) { | |
609 | data = container_of(wacom->shared, struct wacom_usbdev_data, shared); | |
610 | kref_put(&data->kref, wacom_release_shared_data); | |
611 | wacom->shared = NULL; | |
612 | } | |
613 | } | |
614 | ||
5d7e7d47 EH |
615 | static int wacom_led_control(struct wacom *wacom) |
616 | { | |
617 | unsigned char *buf; | |
9b5b95dd | 618 | int retval; |
5d7e7d47 EH |
619 | |
620 | buf = kzalloc(9, GFP_KERNEL); | |
621 | if (!buf) | |
622 | return -ENOMEM; | |
623 | ||
9b5b95dd JG |
624 | if (wacom->wacom_wac.features.type >= INTUOS5S && |
625 | wacom->wacom_wac.features.type <= INTUOS5L) { | |
626 | /* | |
627 | * Touch Ring and crop mark LED luminance may take on | |
628 | * one of four values: | |
629 | * 0 = Low; 1 = Medium; 2 = High; 3 = Off | |
630 | */ | |
631 | int ring_led = wacom->led.select[0] & 0x03; | |
632 | int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03; | |
633 | int crop_lum = 0; | |
634 | ||
635 | buf[0] = WAC_CMD_LED_CONTROL; | |
636 | buf[1] = (crop_lum << 4) | (ring_lum << 2) | (ring_led); | |
637 | } | |
638 | else { | |
639 | int led = wacom->led.select[0] | 0x4; | |
640 | ||
641 | if (wacom->wacom_wac.features.type == WACOM_21UX2 || | |
642 | wacom->wacom_wac.features.type == WACOM_24HD) | |
643 | led |= (wacom->led.select[1] << 4) | 0x40; | |
644 | ||
645 | buf[0] = WAC_CMD_LED_CONTROL; | |
646 | buf[1] = led; | |
647 | buf[2] = wacom->led.llv; | |
648 | buf[3] = wacom->led.hlv; | |
649 | buf[4] = wacom->led.img_lum; | |
650 | } | |
5d7e7d47 EH |
651 | |
652 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL, | |
653 | buf, 9, WAC_CMD_RETRIES); | |
654 | kfree(buf); | |
655 | ||
656 | return retval; | |
657 | } | |
658 | ||
659 | static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img) | |
660 | { | |
661 | unsigned char *buf; | |
662 | int i, retval; | |
663 | ||
664 | buf = kzalloc(259, GFP_KERNEL); | |
665 | if (!buf) | |
666 | return -ENOMEM; | |
667 | ||
668 | /* Send 'start' command */ | |
669 | buf[0] = WAC_CMD_ICON_START; | |
670 | buf[1] = 1; | |
671 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START, | |
672 | buf, 2, WAC_CMD_RETRIES); | |
673 | if (retval < 0) | |
674 | goto out; | |
675 | ||
676 | buf[0] = WAC_CMD_ICON_XFER; | |
677 | buf[1] = button_id & 0x07; | |
678 | for (i = 0; i < 4; i++) { | |
679 | buf[2] = i; | |
680 | memcpy(buf + 3, img + i * 256, 256); | |
681 | ||
682 | retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER, | |
683 | buf, 259, WAC_CMD_RETRIES); | |
684 | if (retval < 0) | |
685 | break; | |
686 | } | |
687 | ||
688 | /* Send 'stop' */ | |
689 | buf[0] = WAC_CMD_ICON_START; | |
690 | buf[1] = 0; | |
691 | wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START, | |
692 | buf, 2, WAC_CMD_RETRIES); | |
693 | ||
694 | out: | |
695 | kfree(buf); | |
696 | return retval; | |
697 | } | |
698 | ||
09e7d941 | 699 | static ssize_t wacom_led_select_store(struct device *dev, int set_id, |
5d7e7d47 EH |
700 | const char *buf, size_t count) |
701 | { | |
702 | struct wacom *wacom = dev_get_drvdata(dev); | |
703 | unsigned int id; | |
704 | int err; | |
705 | ||
706 | err = kstrtouint(buf, 10, &id); | |
707 | if (err) | |
708 | return err; | |
709 | ||
710 | mutex_lock(&wacom->lock); | |
711 | ||
09e7d941 | 712 | wacom->led.select[set_id] = id & 0x3; |
5d7e7d47 EH |
713 | err = wacom_led_control(wacom); |
714 | ||
715 | mutex_unlock(&wacom->lock); | |
716 | ||
717 | return err < 0 ? err : count; | |
718 | } | |
719 | ||
09e7d941 PC |
720 | #define DEVICE_LED_SELECT_ATTR(SET_ID) \ |
721 | static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \ | |
722 | struct device_attribute *attr, const char *buf, size_t count) \ | |
723 | { \ | |
724 | return wacom_led_select_store(dev, SET_ID, buf, count); \ | |
725 | } \ | |
04c59abd PC |
726 | static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ |
727 | struct device_attribute *attr, char *buf) \ | |
728 | { \ | |
729 | struct wacom *wacom = dev_get_drvdata(dev); \ | |
730 | return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \ | |
731 | } \ | |
732 | static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \ | |
733 | wacom_led##SET_ID##_select_show, \ | |
09e7d941 PC |
734 | wacom_led##SET_ID##_select_store) |
735 | ||
736 | DEVICE_LED_SELECT_ATTR(0); | |
737 | DEVICE_LED_SELECT_ATTR(1); | |
5d7e7d47 EH |
738 | |
739 | static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, | |
740 | const char *buf, size_t count) | |
741 | { | |
742 | unsigned int value; | |
743 | int err; | |
744 | ||
745 | err = kstrtouint(buf, 10, &value); | |
746 | if (err) | |
747 | return err; | |
748 | ||
749 | mutex_lock(&wacom->lock); | |
750 | ||
751 | *dest = value & 0x7f; | |
752 | err = wacom_led_control(wacom); | |
753 | ||
754 | mutex_unlock(&wacom->lock); | |
755 | ||
756 | return err < 0 ? err : count; | |
757 | } | |
758 | ||
759 | #define DEVICE_LUMINANCE_ATTR(name, field) \ | |
760 | static ssize_t wacom_##name##_luminance_store(struct device *dev, \ | |
761 | struct device_attribute *attr, const char *buf, size_t count) \ | |
762 | { \ | |
763 | struct wacom *wacom = dev_get_drvdata(dev); \ | |
764 | \ | |
765 | return wacom_luminance_store(wacom, &wacom->led.field, \ | |
766 | buf, count); \ | |
767 | } \ | |
768 | static DEVICE_ATTR(name##_luminance, S_IWUSR, \ | |
769 | NULL, wacom_##name##_luminance_store) | |
770 | ||
771 | DEVICE_LUMINANCE_ATTR(status0, llv); | |
772 | DEVICE_LUMINANCE_ATTR(status1, hlv); | |
773 | DEVICE_LUMINANCE_ATTR(buttons, img_lum); | |
774 | ||
775 | static ssize_t wacom_button_image_store(struct device *dev, int button_id, | |
776 | const char *buf, size_t count) | |
777 | { | |
778 | struct wacom *wacom = dev_get_drvdata(dev); | |
779 | int err; | |
780 | ||
781 | if (count != 1024) | |
782 | return -EINVAL; | |
783 | ||
784 | mutex_lock(&wacom->lock); | |
785 | ||
786 | err = wacom_led_putimage(wacom, button_id, buf); | |
787 | ||
788 | mutex_unlock(&wacom->lock); | |
789 | ||
790 | return err < 0 ? err : count; | |
791 | } | |
792 | ||
793 | #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \ | |
794 | static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \ | |
795 | struct device_attribute *attr, const char *buf, size_t count) \ | |
796 | { \ | |
797 | return wacom_button_image_store(dev, BUTTON_ID, buf, count); \ | |
798 | } \ | |
799 | static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \ | |
800 | NULL, wacom_btnimg##BUTTON_ID##_store) | |
801 | ||
802 | DEVICE_BTNIMG_ATTR(0); | |
803 | DEVICE_BTNIMG_ATTR(1); | |
804 | DEVICE_BTNIMG_ATTR(2); | |
805 | DEVICE_BTNIMG_ATTR(3); | |
806 | DEVICE_BTNIMG_ATTR(4); | |
807 | DEVICE_BTNIMG_ATTR(5); | |
808 | DEVICE_BTNIMG_ATTR(6); | |
809 | DEVICE_BTNIMG_ATTR(7); | |
810 | ||
09e7d941 PC |
811 | static struct attribute *cintiq_led_attrs[] = { |
812 | &dev_attr_status_led0_select.attr, | |
813 | &dev_attr_status_led1_select.attr, | |
814 | NULL | |
815 | }; | |
816 | ||
817 | static struct attribute_group cintiq_led_attr_group = { | |
818 | .name = "wacom_led", | |
819 | .attrs = cintiq_led_attrs, | |
820 | }; | |
821 | ||
822 | static struct attribute *intuos4_led_attrs[] = { | |
5d7e7d47 EH |
823 | &dev_attr_status0_luminance.attr, |
824 | &dev_attr_status1_luminance.attr, | |
09e7d941 | 825 | &dev_attr_status_led0_select.attr, |
5d7e7d47 EH |
826 | &dev_attr_buttons_luminance.attr, |
827 | &dev_attr_button0_rawimg.attr, | |
828 | &dev_attr_button1_rawimg.attr, | |
829 | &dev_attr_button2_rawimg.attr, | |
830 | &dev_attr_button3_rawimg.attr, | |
831 | &dev_attr_button4_rawimg.attr, | |
832 | &dev_attr_button5_rawimg.attr, | |
833 | &dev_attr_button6_rawimg.attr, | |
834 | &dev_attr_button7_rawimg.attr, | |
835 | NULL | |
836 | }; | |
837 | ||
09e7d941 | 838 | static struct attribute_group intuos4_led_attr_group = { |
5d7e7d47 | 839 | .name = "wacom_led", |
09e7d941 | 840 | .attrs = intuos4_led_attrs, |
5d7e7d47 EH |
841 | }; |
842 | ||
9b5b95dd JG |
843 | static struct attribute *intuos5_led_attrs[] = { |
844 | &dev_attr_status0_luminance.attr, | |
845 | &dev_attr_status_led0_select.attr, | |
846 | NULL | |
847 | }; | |
848 | ||
849 | static struct attribute_group intuos5_led_attr_group = { | |
850 | .name = "wacom_led", | |
851 | .attrs = intuos5_led_attrs, | |
852 | }; | |
853 | ||
5d7e7d47 EH |
854 | static int wacom_initialize_leds(struct wacom *wacom) |
855 | { | |
856 | int error; | |
857 | ||
09e7d941 PC |
858 | /* Initialize default values */ |
859 | switch (wacom->wacom_wac.features.type) { | |
860 | case INTUOS4: | |
861 | case INTUOS4L: | |
862 | wacom->led.select[0] = 0; | |
863 | wacom->led.select[1] = 0; | |
f4fa9a6d | 864 | wacom->led.llv = 10; |
5d7e7d47 EH |
865 | wacom->led.hlv = 20; |
866 | wacom->led.img_lum = 10; | |
09e7d941 PC |
867 | error = sysfs_create_group(&wacom->intf->dev.kobj, |
868 | &intuos4_led_attr_group); | |
869 | break; | |
870 | ||
246835fc | 871 | case WACOM_24HD: |
09e7d941 PC |
872 | case WACOM_21UX2: |
873 | wacom->led.select[0] = 0; | |
874 | wacom->led.select[1] = 0; | |
875 | wacom->led.llv = 0; | |
876 | wacom->led.hlv = 0; | |
877 | wacom->led.img_lum = 0; | |
5d7e7d47 EH |
878 | |
879 | error = sysfs_create_group(&wacom->intf->dev.kobj, | |
09e7d941 PC |
880 | &cintiq_led_attr_group); |
881 | break; | |
882 | ||
9b5b95dd JG |
883 | case INTUOS5S: |
884 | case INTUOS5: | |
885 | case INTUOS5L: | |
886 | wacom->led.select[0] = 0; | |
887 | wacom->led.select[1] = 0; | |
888 | wacom->led.llv = 32; | |
889 | wacom->led.hlv = 0; | |
890 | wacom->led.img_lum = 0; | |
891 | ||
892 | error = sysfs_create_group(&wacom->intf->dev.kobj, | |
893 | &intuos5_led_attr_group); | |
894 | break; | |
895 | ||
09e7d941 PC |
896 | default: |
897 | return 0; | |
5d7e7d47 EH |
898 | } |
899 | ||
09e7d941 PC |
900 | if (error) { |
901 | dev_err(&wacom->intf->dev, | |
902 | "cannot create sysfs group err: %d\n", error); | |
903 | return error; | |
904 | } | |
905 | wacom_led_control(wacom); | |
906 | ||
5d7e7d47 EH |
907 | return 0; |
908 | } | |
909 | ||
910 | static void wacom_destroy_leds(struct wacom *wacom) | |
911 | { | |
09e7d941 PC |
912 | switch (wacom->wacom_wac.features.type) { |
913 | case INTUOS4: | |
914 | case INTUOS4L: | |
5d7e7d47 | 915 | sysfs_remove_group(&wacom->intf->dev.kobj, |
09e7d941 PC |
916 | &intuos4_led_attr_group); |
917 | break; | |
918 | ||
246835fc | 919 | case WACOM_24HD: |
09e7d941 PC |
920 | case WACOM_21UX2: |
921 | sysfs_remove_group(&wacom->intf->dev.kobj, | |
922 | &cintiq_led_attr_group); | |
923 | break; | |
9b5b95dd JG |
924 | |
925 | case INTUOS5S: | |
926 | case INTUOS5: | |
927 | case INTUOS5L: | |
928 | sysfs_remove_group(&wacom->intf->dev.kobj, | |
929 | &intuos5_led_attr_group); | |
930 | break; | |
5d7e7d47 EH |
931 | } |
932 | } | |
933 | ||
a1d552cc CB |
934 | static enum power_supply_property wacom_battery_props[] = { |
935 | POWER_SUPPLY_PROP_CAPACITY | |
936 | }; | |
937 | ||
938 | static int wacom_battery_get_property(struct power_supply *psy, | |
939 | enum power_supply_property psp, | |
940 | union power_supply_propval *val) | |
941 | { | |
942 | struct wacom *wacom = container_of(psy, struct wacom, battery); | |
943 | int ret = 0; | |
944 | ||
945 | switch (psp) { | |
946 | case POWER_SUPPLY_PROP_CAPACITY: | |
947 | val->intval = | |
948 | wacom->wacom_wac.battery_capacity * 100 / 31; | |
949 | break; | |
950 | default: | |
951 | ret = -EINVAL; | |
952 | break; | |
953 | } | |
954 | ||
955 | return ret; | |
956 | } | |
957 | ||
958 | static int wacom_initialize_battery(struct wacom *wacom) | |
959 | { | |
960 | int error = 0; | |
961 | ||
962 | if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) { | |
963 | wacom->battery.properties = wacom_battery_props; | |
964 | wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props); | |
965 | wacom->battery.get_property = wacom_battery_get_property; | |
966 | wacom->battery.name = "wacom_battery"; | |
967 | wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY; | |
968 | wacom->battery.use_for_apm = 0; | |
969 | ||
970 | error = power_supply_register(&wacom->usbdev->dev, | |
971 | &wacom->battery); | |
972 | } | |
973 | ||
974 | return error; | |
975 | } | |
976 | ||
977 | static void wacom_destroy_battery(struct wacom *wacom) | |
978 | { | |
979 | if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) | |
980 | power_supply_unregister(&wacom->battery); | |
981 | } | |
982 | ||
3aac0ef1 CB |
983 | static int wacom_register_input(struct wacom *wacom) |
984 | { | |
985 | struct input_dev *input_dev; | |
986 | struct usb_interface *intf = wacom->intf; | |
987 | struct usb_device *dev = interface_to_usbdev(intf); | |
988 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); | |
989 | int error; | |
990 | ||
991 | input_dev = input_allocate_device(); | |
1963518b PC |
992 | if (!input_dev) { |
993 | error = -ENOMEM; | |
994 | goto fail1; | |
995 | } | |
3aac0ef1 CB |
996 | |
997 | input_dev->name = wacom_wac->name; | |
998 | input_dev->dev.parent = &intf->dev; | |
999 | input_dev->open = wacom_open; | |
1000 | input_dev->close = wacom_close; | |
1001 | usb_to_input_id(dev, &input_dev->id); | |
1002 | input_set_drvdata(input_dev, wacom); | |
1003 | ||
1004 | wacom_wac->input = input_dev; | |
1963518b PC |
1005 | error = wacom_setup_input_capabilities(input_dev, wacom_wac); |
1006 | if (error) | |
1007 | goto fail1; | |
3aac0ef1 CB |
1008 | |
1009 | error = input_register_device(input_dev); | |
1963518b PC |
1010 | if (error) |
1011 | goto fail2; | |
1012 | ||
1013 | return 0; | |
3aac0ef1 | 1014 | |
1963518b PC |
1015 | fail2: |
1016 | input_free_device(input_dev); | |
1017 | wacom_wac->input = NULL; | |
1018 | fail1: | |
3aac0ef1 CB |
1019 | return error; |
1020 | } | |
1021 | ||
16bf288c CB |
1022 | static void wacom_wireless_work(struct work_struct *work) |
1023 | { | |
1024 | struct wacom *wacom = container_of(work, struct wacom, work); | |
1025 | struct usb_device *usbdev = wacom->usbdev; | |
1026 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; | |
1027 | ||
1028 | /* | |
1029 | * Regardless if this is a disconnect or a new tablet, | |
1030 | * remove any existing input devices. | |
1031 | */ | |
1032 | ||
1033 | /* Stylus interface */ | |
1034 | wacom = usb_get_intfdata(usbdev->config->interface[1]); | |
1035 | if (wacom->wacom_wac.input) | |
1036 | input_unregister_device(wacom->wacom_wac.input); | |
0c9e300a | 1037 | wacom->wacom_wac.input = NULL; |
16bf288c CB |
1038 | |
1039 | /* Touch interface */ | |
1040 | wacom = usb_get_intfdata(usbdev->config->interface[2]); | |
1041 | if (wacom->wacom_wac.input) | |
1042 | input_unregister_device(wacom->wacom_wac.input); | |
0c9e300a | 1043 | wacom->wacom_wac.input = NULL; |
16bf288c CB |
1044 | |
1045 | if (wacom_wac->pid == 0) { | |
eb71d1bb | 1046 | dev_info(&wacom->intf->dev, "wireless tablet disconnected\n"); |
16bf288c CB |
1047 | } else { |
1048 | const struct usb_device_id *id = wacom_ids; | |
1049 | ||
eb71d1bb DT |
1050 | dev_info(&wacom->intf->dev, |
1051 | "wireless tablet connected with PID %x\n", | |
1052 | wacom_wac->pid); | |
16bf288c CB |
1053 | |
1054 | while (id->match_flags) { | |
1055 | if (id->idVendor == USB_VENDOR_ID_WACOM && | |
1056 | id->idProduct == wacom_wac->pid) | |
1057 | break; | |
1058 | id++; | |
1059 | } | |
1060 | ||
1061 | if (!id->match_flags) { | |
eb71d1bb DT |
1062 | dev_info(&wacom->intf->dev, |
1063 | "ignoring unknown PID.\n"); | |
16bf288c CB |
1064 | return; |
1065 | } | |
1066 | ||
1067 | /* Stylus interface */ | |
1068 | wacom = usb_get_intfdata(usbdev->config->interface[1]); | |
1069 | wacom_wac = &wacom->wacom_wac; | |
1070 | wacom_wac->features = | |
1071 | *((struct wacom_features *)id->driver_info); | |
1072 | wacom_wac->features.device_type = BTN_TOOL_PEN; | |
1073 | wacom_register_input(wacom); | |
1074 | ||
1075 | /* Touch interface */ | |
1076 | wacom = usb_get_intfdata(usbdev->config->interface[2]); | |
1077 | wacom_wac = &wacom->wacom_wac; | |
1078 | wacom_wac->features = | |
1079 | *((struct wacom_features *)id->driver_info); | |
1080 | wacom_wac->features.pktlen = WACOM_PKGLEN_BBTOUCH3; | |
1081 | wacom_wac->features.device_type = BTN_TOOL_FINGER; | |
1082 | wacom_set_phy_from_res(&wacom_wac->features); | |
1083 | wacom_wac->features.x_max = wacom_wac->features.y_max = 4096; | |
1084 | wacom_register_input(wacom); | |
1085 | } | |
1086 | } | |
1087 | ||
3bea733a PC |
1088 | static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) |
1089 | { | |
1090 | struct usb_device *dev = interface_to_usbdev(intf); | |
1091 | struct usb_endpoint_descriptor *endpoint; | |
1092 | struct wacom *wacom; | |
1093 | struct wacom_wac *wacom_wac; | |
e33da8a5 | 1094 | struct wacom_features *features; |
e33da8a5 | 1095 | int error; |
3bea733a | 1096 | |
e33da8a5 | 1097 | if (!id->driver_info) |
b036f6fb BB |
1098 | return -EINVAL; |
1099 | ||
3bea733a | 1100 | wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); |
f1823940 DC |
1101 | if (!wacom) |
1102 | return -ENOMEM; | |
e33da8a5 | 1103 | |
51269fe8 | 1104 | wacom_wac = &wacom->wacom_wac; |
e33da8a5 JC |
1105 | wacom_wac->features = *((struct wacom_features *)id->driver_info); |
1106 | features = &wacom_wac->features; | |
1107 | if (features->pktlen > WACOM_PKGLEN_MAX) { | |
1108 | error = -EINVAL; | |
3bea733a | 1109 | goto fail1; |
e33da8a5 | 1110 | } |
3bea733a | 1111 | |
997ea58e DM |
1112 | wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX, |
1113 | GFP_KERNEL, &wacom->data_dma); | |
e33da8a5 JC |
1114 | if (!wacom_wac->data) { |
1115 | error = -ENOMEM; | |
3bea733a | 1116 | goto fail1; |
e33da8a5 | 1117 | } |
3bea733a PC |
1118 | |
1119 | wacom->irq = usb_alloc_urb(0, GFP_KERNEL); | |
e33da8a5 JC |
1120 | if (!wacom->irq) { |
1121 | error = -ENOMEM; | |
3bea733a | 1122 | goto fail2; |
e33da8a5 | 1123 | } |
3bea733a PC |
1124 | |
1125 | wacom->usbdev = dev; | |
e7224094 ON |
1126 | wacom->intf = intf; |
1127 | mutex_init(&wacom->lock); | |
16bf288c | 1128 | INIT_WORK(&wacom->work, wacom_wireless_work); |
3bea733a PC |
1129 | usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); |
1130 | strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); | |
1131 | ||
545f4e99 PC |
1132 | endpoint = &intf->cur_altsetting->endpoint[0].desc; |
1133 | ||
f393ee2b | 1134 | /* Retrieve the physical and logical size for touch devices */ |
ec67bbed PC |
1135 | error = wacom_retrieve_hid_descriptor(intf, features); |
1136 | if (error) | |
4b6d4434 | 1137 | goto fail3; |
545f4e99 | 1138 | |
ae584ca4 JG |
1139 | /* |
1140 | * Intuos5 has no useful data about its touch interface in its | |
1141 | * HID descriptor. If this is the touch interface (wMaxPacketSize | |
1142 | * of WACOM_PKGLEN_BBTOUCH3), override the table values. | |
1143 | */ | |
1144 | if (features->type >= INTUOS5S && features->type <= INTUOS5L) { | |
1145 | if (endpoint->wMaxPacketSize == WACOM_PKGLEN_BBTOUCH3) { | |
1146 | features->device_type = BTN_TOOL_FINGER; | |
1147 | features->pktlen = WACOM_PKGLEN_BBTOUCH3; | |
1148 | ||
1149 | features->x_phy = | |
1150 | (features->x_max * 100) / features->x_resolution; | |
1151 | features->y_phy = | |
1152 | (features->y_max * 100) / features->y_resolution; | |
1153 | ||
1154 | features->x_max = 4096; | |
1155 | features->y_max = 4096; | |
1156 | } else { | |
1157 | features->device_type = BTN_TOOL_PEN; | |
1158 | } | |
1159 | } | |
1160 | ||
bc73dd39 HR |
1161 | wacom_setup_device_quirks(features); |
1162 | ||
49b764ae PC |
1163 | strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); |
1164 | ||
bc73dd39 | 1165 | if (features->quirks & WACOM_QUIRK_MULTI_INPUT) { |
49b764ae PC |
1166 | /* Append the device type to the name */ |
1167 | strlcat(wacom_wac->name, | |
1168 | features->device_type == BTN_TOOL_PEN ? | |
1169 | " Pen" : " Finger", | |
1170 | sizeof(wacom_wac->name)); | |
4492efff PC |
1171 | |
1172 | error = wacom_add_shared_data(wacom_wac, dev); | |
1173 | if (error) | |
1174 | goto fail3; | |
49b764ae PC |
1175 | } |
1176 | ||
3bea733a PC |
1177 | usb_fill_int_urb(wacom->irq, dev, |
1178 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), | |
ec67bbed | 1179 | wacom_wac->data, features->pktlen, |
8d32e3ae | 1180 | wacom_sys_irq, wacom, endpoint->bInterval); |
3bea733a PC |
1181 | wacom->irq->transfer_dma = wacom->data_dma; |
1182 | wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | |
1183 | ||
5d7e7d47 | 1184 | error = wacom_initialize_leds(wacom); |
5014186d | 1185 | if (error) |
4492efff | 1186 | goto fail4; |
3bea733a | 1187 | |
a1d552cc CB |
1188 | error = wacom_initialize_battery(wacom); |
1189 | if (error) | |
1190 | goto fail5; | |
1191 | ||
d3825d51 CB |
1192 | if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { |
1193 | error = wacom_register_input(wacom); | |
1194 | if (error) | |
a1d552cc | 1195 | goto fail6; |
d3825d51 | 1196 | } |
5d7e7d47 | 1197 | |
ec67bbed PC |
1198 | /* Note that if query fails it is not a hard failure */ |
1199 | wacom_query_tablet_data(intf, features); | |
3bea733a PC |
1200 | |
1201 | usb_set_intfdata(intf, wacom); | |
d3825d51 CB |
1202 | |
1203 | if (features->quirks & WACOM_QUIRK_MONITOR) { | |
1204 | if (usb_submit_urb(wacom->irq, GFP_KERNEL)) | |
1205 | goto fail5; | |
1206 | } | |
1207 | ||
3bea733a PC |
1208 | return 0; |
1209 | ||
a1d552cc | 1210 | fail6: wacom_destroy_battery(wacom); |
5d7e7d47 | 1211 | fail5: wacom_destroy_leds(wacom); |
4492efff | 1212 | fail4: wacom_remove_shared_data(wacom_wac); |
5014186d | 1213 | fail3: usb_free_urb(wacom->irq); |
997ea58e | 1214 | fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma); |
3aac0ef1 | 1215 | fail1: kfree(wacom); |
5014186d | 1216 | return error; |
3bea733a PC |
1217 | } |
1218 | ||
1219 | static void wacom_disconnect(struct usb_interface *intf) | |
1220 | { | |
e7224094 | 1221 | struct wacom *wacom = usb_get_intfdata(intf); |
3bea733a PC |
1222 | |
1223 | usb_set_intfdata(intf, NULL); | |
e7224094 ON |
1224 | |
1225 | usb_kill_urb(wacom->irq); | |
16bf288c | 1226 | cancel_work_sync(&wacom->work); |
d3825d51 CB |
1227 | if (wacom->wacom_wac.input) |
1228 | input_unregister_device(wacom->wacom_wac.input); | |
a1d552cc | 1229 | wacom_destroy_battery(wacom); |
5d7e7d47 | 1230 | wacom_destroy_leds(wacom); |
e7224094 | 1231 | usb_free_urb(wacom->irq); |
997ea58e | 1232 | usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX, |
51269fe8 DT |
1233 | wacom->wacom_wac.data, wacom->data_dma); |
1234 | wacom_remove_shared_data(&wacom->wacom_wac); | |
e7224094 ON |
1235 | kfree(wacom); |
1236 | } | |
1237 | ||
1238 | static int wacom_suspend(struct usb_interface *intf, pm_message_t message) | |
1239 | { | |
1240 | struct wacom *wacom = usb_get_intfdata(intf); | |
1241 | ||
1242 | mutex_lock(&wacom->lock); | |
1243 | usb_kill_urb(wacom->irq); | |
1244 | mutex_unlock(&wacom->lock); | |
1245 | ||
1246 | return 0; | |
1247 | } | |
1248 | ||
1249 | static int wacom_resume(struct usb_interface *intf) | |
1250 | { | |
1251 | struct wacom *wacom = usb_get_intfdata(intf); | |
51269fe8 | 1252 | struct wacom_features *features = &wacom->wacom_wac.features; |
5d7e7d47 | 1253 | int rv = 0; |
e7224094 ON |
1254 | |
1255 | mutex_lock(&wacom->lock); | |
38101475 PC |
1256 | |
1257 | /* switch to wacom mode first */ | |
1258 | wacom_query_tablet_data(intf, features); | |
5d7e7d47 | 1259 | wacom_led_control(wacom); |
38101475 | 1260 | |
d3825d51 CB |
1261 | if ((wacom->open || features->quirks & WACOM_QUIRK_MONITOR) |
1262 | && usb_submit_urb(wacom->irq, GFP_NOIO) < 0) | |
5d7e7d47 | 1263 | rv = -EIO; |
38101475 | 1264 | |
e7224094 ON |
1265 | mutex_unlock(&wacom->lock); |
1266 | ||
1267 | return rv; | |
1268 | } | |
1269 | ||
1270 | static int wacom_reset_resume(struct usb_interface *intf) | |
1271 | { | |
1272 | return wacom_resume(intf); | |
3bea733a PC |
1273 | } |
1274 | ||
1275 | static struct usb_driver wacom_driver = { | |
1276 | .name = "wacom", | |
b036f6fb | 1277 | .id_table = wacom_ids, |
3bea733a PC |
1278 | .probe = wacom_probe, |
1279 | .disconnect = wacom_disconnect, | |
e7224094 ON |
1280 | .suspend = wacom_suspend, |
1281 | .resume = wacom_resume, | |
1282 | .reset_resume = wacom_reset_resume, | |
1283 | .supports_autosuspend = 1, | |
3bea733a PC |
1284 | }; |
1285 | ||
08642e7c | 1286 | module_usb_driver(wacom_driver); |