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