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 | |
31 | #define HID_COLLECTION 0xc0 | |
32 | ||
33 | enum { | |
34 | WCM_UNDEFINED = 0, | |
35 | WCM_DESKTOP, | |
36 | WCM_DIGITIZER, | |
37 | }; | |
38 | ||
39 | struct hid_descriptor { | |
40 | struct usb_descriptor_header header; | |
41 | __le16 bcdHID; | |
42 | u8 bCountryCode; | |
43 | u8 bNumDescriptors; | |
44 | u8 bDescriptorType; | |
45 | __le16 wDescriptorLength; | |
46 | } __attribute__ ((packed)); | |
47 | ||
48 | /* defines to get/set USB message */ | |
3bea733a PC |
49 | #define USB_REQ_GET_REPORT 0x01 |
50 | #define USB_REQ_SET_REPORT 0x09 | |
545f4e99 | 51 | #define WAC_HID_FEATURE_REPORT 0x03 |
3bea733a PC |
52 | |
53 | static int usb_get_report(struct usb_interface *intf, unsigned char type, | |
54 | unsigned char id, void *buf, int size) | |
55 | { | |
56 | return usb_control_msg(interface_to_usbdev(intf), | |
57 | usb_rcvctrlpipe(interface_to_usbdev(intf), 0), | |
58 | USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE, | |
59 | (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber, | |
60 | buf, size, 100); | |
61 | } | |
62 | ||
63 | static int usb_set_report(struct usb_interface *intf, unsigned char type, | |
64 | unsigned char id, void *buf, int size) | |
65 | { | |
66 | return usb_control_msg(interface_to_usbdev(intf), | |
67 | usb_sndctrlpipe(interface_to_usbdev(intf), 0), | |
68 | USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE, | |
69 | (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber, | |
70 | buf, size, 1000); | |
71 | } | |
72 | ||
54c9b226 | 73 | static void wacom_sys_irq(struct urb *urb) |
3bea733a PC |
74 | { |
75 | struct wacom *wacom = urb->context; | |
3bea733a PC |
76 | int retval; |
77 | ||
78 | switch (urb->status) { | |
79 | case 0: | |
80 | /* success */ | |
81 | break; | |
82 | case -ECONNRESET: | |
83 | case -ENOENT: | |
84 | case -ESHUTDOWN: | |
85 | /* this urb is terminated, clean up */ | |
ea3e6c59 | 86 | dbg("%s - urb shutting down with status: %d", __func__, urb->status); |
3bea733a PC |
87 | return; |
88 | default: | |
ea3e6c59 | 89 | dbg("%s - nonzero urb status received: %d", __func__, urb->status); |
3bea733a PC |
90 | goto exit; |
91 | } | |
92 | ||
95dd3b30 | 93 | wacom_wac_irq(&wacom->wacom_wac, urb->actual_length); |
3bea733a PC |
94 | |
95 | exit: | |
e7224094 | 96 | usb_mark_last_busy(wacom->usbdev); |
73a97f4f | 97 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
3bea733a PC |
98 | if (retval) |
99 | err ("%s - usb_submit_urb failed with result %d", | |
ea3e6c59 | 100 | __func__, retval); |
3bea733a PC |
101 | } |
102 | ||
3bea733a PC |
103 | static int wacom_open(struct input_dev *dev) |
104 | { | |
7791bdae | 105 | struct wacom *wacom = input_get_drvdata(dev); |
3bea733a | 106 | |
e7224094 ON |
107 | mutex_lock(&wacom->lock); |
108 | ||
3bea733a | 109 | wacom->irq->dev = wacom->usbdev; |
e7224094 ON |
110 | |
111 | if (usb_autopm_get_interface(wacom->intf) < 0) { | |
112 | mutex_unlock(&wacom->lock); | |
3bea733a | 113 | return -EIO; |
e7224094 ON |
114 | } |
115 | ||
116 | if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { | |
117 | usb_autopm_put_interface(wacom->intf); | |
118 | mutex_unlock(&wacom->lock); | |
119 | return -EIO; | |
120 | } | |
121 | ||
51269fe8 | 122 | wacom->open = true; |
e7224094 | 123 | wacom->intf->needs_remote_wakeup = 1; |
3bea733a | 124 | |
e7224094 | 125 | mutex_unlock(&wacom->lock); |
3bea733a PC |
126 | return 0; |
127 | } | |
128 | ||
129 | static void wacom_close(struct input_dev *dev) | |
130 | { | |
7791bdae | 131 | struct wacom *wacom = input_get_drvdata(dev); |
3bea733a | 132 | |
e7224094 | 133 | mutex_lock(&wacom->lock); |
3bea733a | 134 | usb_kill_urb(wacom->irq); |
51269fe8 | 135 | wacom->open = false; |
e7224094 ON |
136 | wacom->intf->needs_remote_wakeup = 0; |
137 | mutex_unlock(&wacom->lock); | |
3bea733a PC |
138 | } |
139 | ||
545f4e99 | 140 | static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc, |
ec67bbed | 141 | struct wacom_features *features) |
545f4e99 PC |
142 | { |
143 | struct usb_device *dev = interface_to_usbdev(intf); | |
ec67bbed PC |
144 | char limit = 0; |
145 | /* result has to be defined as int for some devices */ | |
146 | int result = 0; | |
545f4e99 PC |
147 | int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0; |
148 | unsigned char *report; | |
149 | ||
150 | report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL); | |
151 | if (!report) | |
152 | return -ENOMEM; | |
153 | ||
154 | /* retrive report descriptors */ | |
155 | do { | |
156 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | |
157 | USB_REQ_GET_DESCRIPTOR, | |
158 | USB_RECIP_INTERFACE | USB_DIR_IN, | |
159 | HID_DEVICET_REPORT << 8, | |
160 | intf->altsetting[0].desc.bInterfaceNumber, /* interface */ | |
161 | report, | |
162 | hid_desc->wDescriptorLength, | |
163 | 5000); /* 5 secs */ | |
164 | } while (result < 0 && limit++ < 5); | |
165 | ||
384318ec | 166 | /* No need to parse the Descriptor. It isn't an error though */ |
545f4e99 PC |
167 | if (result < 0) |
168 | goto out; | |
169 | ||
170 | for (i = 0; i < hid_desc->wDescriptorLength; i++) { | |
171 | ||
172 | switch (report[i]) { | |
173 | case HID_USAGE_PAGE: | |
174 | switch (report[i + 1]) { | |
175 | case HID_USAGE_PAGE_DIGITIZER: | |
176 | usage = WCM_DIGITIZER; | |
177 | i++; | |
178 | break; | |
179 | ||
180 | case HID_USAGE_PAGE_DESKTOP: | |
181 | usage = WCM_DESKTOP; | |
182 | i++; | |
183 | break; | |
184 | } | |
185 | break; | |
186 | ||
187 | case HID_USAGE: | |
188 | switch (report[i + 1]) { | |
189 | case HID_USAGE_X: | |
190 | if (usage == WCM_DESKTOP) { | |
191 | if (finger) { | |
ec67bbed PC |
192 | features->device_type = BTN_TOOL_DOUBLETAP; |
193 | if (features->type == TABLETPC2FG) { | |
194 | /* need to reset back */ | |
195 | features->pktlen = WACOM_PKGLEN_TPC2FG; | |
196 | features->device_type = BTN_TOOL_TRIPLETAP; | |
197 | } | |
4a88081e PC |
198 | if (features->type == BAMBOO_PT) { |
199 | /* need to reset back */ | |
200 | features->pktlen = WACOM_PKGLEN_BBTOUCH; | |
201 | features->device_type = BTN_TOOL_TRIPLETAP; | |
202 | features->x_phy = | |
203 | get_unaligned_le16(&report[i + 5]); | |
204 | features->x_max = | |
205 | get_unaligned_le16(&report[i + 8]); | |
206 | i += 15; | |
207 | } else { | |
208 | features->x_max = | |
209 | get_unaligned_le16(&report[i + 3]); | |
210 | features->x_phy = | |
211 | get_unaligned_le16(&report[i + 6]); | |
212 | features->unit = report[i + 9]; | |
213 | features->unitExpo = report[i + 11]; | |
214 | i += 12; | |
215 | } | |
545f4e99 | 216 | } else if (pen) { |
ec67bbed PC |
217 | /* penabled only accepts exact bytes of data */ |
218 | if (features->type == TABLETPC2FG) | |
57e413d9 | 219 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
4a88081e PC |
220 | if (features->type == BAMBOO_PT) |
221 | features->pktlen = WACOM_PKGLEN_BBFUN; | |
ec67bbed | 222 | features->device_type = BTN_TOOL_PEN; |
545f4e99 | 223 | features->x_max = |
252f7769 | 224 | get_unaligned_le16(&report[i + 3]); |
545f4e99 PC |
225 | i += 4; |
226 | } | |
227 | } else if (usage == WCM_DIGITIZER) { | |
228 | /* max pressure isn't reported | |
229 | features->pressure_max = (unsigned short) | |
230 | (report[i+4] << 8 | report[i + 3]); | |
231 | */ | |
232 | features->pressure_max = 255; | |
233 | i += 4; | |
234 | } | |
235 | break; | |
236 | ||
237 | case HID_USAGE_Y: | |
ec67bbed PC |
238 | if (usage == WCM_DESKTOP) { |
239 | if (finger) { | |
240 | features->device_type = BTN_TOOL_DOUBLETAP; | |
241 | if (features->type == TABLETPC2FG) { | |
242 | /* need to reset back */ | |
243 | features->pktlen = WACOM_PKGLEN_TPC2FG; | |
244 | features->device_type = BTN_TOOL_TRIPLETAP; | |
245 | features->y_max = | |
252f7769 | 246 | get_unaligned_le16(&report[i + 3]); |
ec67bbed | 247 | features->y_phy = |
252f7769 | 248 | get_unaligned_le16(&report[i + 6]); |
ec67bbed | 249 | i += 7; |
4a88081e PC |
250 | } else if (features->type == BAMBOO_PT) { |
251 | /* need to reset back */ | |
252 | features->pktlen = WACOM_PKGLEN_BBTOUCH; | |
253 | features->device_type = BTN_TOOL_TRIPLETAP; | |
254 | features->y_phy = | |
255 | get_unaligned_le16(&report[i + 3]); | |
256 | features->y_max = | |
257 | get_unaligned_le16(&report[i + 6]); | |
258 | i += 12; | |
ec67bbed PC |
259 | } else { |
260 | features->y_max = | |
261 | features->x_max; | |
262 | features->y_phy = | |
252f7769 | 263 | get_unaligned_le16(&report[i + 3]); |
ec67bbed PC |
264 | i += 4; |
265 | } | |
266 | } else if (pen) { | |
267 | /* penabled only accepts exact bytes of data */ | |
268 | if (features->type == TABLETPC2FG) | |
57e413d9 | 269 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
4a88081e PC |
270 | if (features->type == BAMBOO_PT) |
271 | features->pktlen = WACOM_PKGLEN_BBFUN; | |
ec67bbed PC |
272 | features->device_type = BTN_TOOL_PEN; |
273 | features->y_max = | |
252f7769 | 274 | get_unaligned_le16(&report[i + 3]); |
ec67bbed PC |
275 | i += 4; |
276 | } | |
277 | } | |
545f4e99 PC |
278 | break; |
279 | ||
280 | case HID_USAGE_FINGER: | |
281 | finger = 1; | |
282 | i++; | |
283 | break; | |
284 | ||
285 | case HID_USAGE_STYLUS: | |
286 | pen = 1; | |
287 | i++; | |
288 | break; | |
289 | ||
290 | case HID_USAGE_UNDEFINED: | |
291 | if (usage == WCM_DESKTOP && finger) /* capacity */ | |
292 | features->pressure_max = | |
252f7769 | 293 | get_unaligned_le16(&report[i + 3]); |
545f4e99 PC |
294 | i += 4; |
295 | break; | |
296 | } | |
297 | break; | |
298 | ||
299 | case HID_COLLECTION: | |
ec67bbed | 300 | /* reset UsagePage and Finger */ |
545f4e99 PC |
301 | finger = usage = 0; |
302 | break; | |
303 | } | |
304 | } | |
305 | ||
545f4e99 | 306 | out: |
384318ec | 307 | result = 0; |
545f4e99 PC |
308 | kfree(report); |
309 | return result; | |
310 | } | |
311 | ||
ec67bbed | 312 | static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features) |
3b7307c2 DT |
313 | { |
314 | unsigned char *rep_data; | |
ec67bbed PC |
315 | int limit = 0, report_id = 2; |
316 | int error = -ENOMEM; | |
3b7307c2 DT |
317 | |
318 | rep_data = kmalloc(2, GFP_KERNEL); | |
319 | if (!rep_data) | |
ec67bbed PC |
320 | return error; |
321 | ||
322 | /* ask to report tablet data if it is 2FGT or not a Tablet PC */ | |
323 | if (features->device_type == BTN_TOOL_TRIPLETAP) { | |
324 | do { | |
325 | rep_data[0] = 3; | |
326 | rep_data[1] = 4; | |
327 | report_id = 3; | |
328 | error = usb_set_report(intf, WAC_HID_FEATURE_REPORT, | |
329 | report_id, rep_data, 2); | |
330 | if (error >= 0) | |
331 | error = usb_get_report(intf, | |
332 | WAC_HID_FEATURE_REPORT, report_id, | |
333 | rep_data, 3); | |
334 | } while ((error < 0 || rep_data[1] != 4) && limit++ < 5); | |
335 | } else if (features->type != TABLETPC && features->type != TABLETPC2FG) { | |
336 | do { | |
337 | rep_data[0] = 2; | |
338 | rep_data[1] = 2; | |
339 | error = usb_set_report(intf, WAC_HID_FEATURE_REPORT, | |
340 | report_id, rep_data, 2); | |
341 | if (error >= 0) | |
342 | error = usb_get_report(intf, | |
343 | WAC_HID_FEATURE_REPORT, report_id, | |
344 | rep_data, 2); | |
345 | } while ((error < 0 || rep_data[1] != 2) && limit++ < 5); | |
346 | } | |
3b7307c2 DT |
347 | |
348 | kfree(rep_data); | |
349 | ||
350 | return error < 0 ? error : 0; | |
351 | } | |
352 | ||
ec67bbed PC |
353 | static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, |
354 | struct wacom_features *features) | |
355 | { | |
356 | int error = 0; | |
357 | struct usb_host_interface *interface = intf->cur_altsetting; | |
358 | struct hid_descriptor *hid_desc; | |
359 | ||
fed87e65 | 360 | /* default features */ |
ec67bbed | 361 | features->device_type = BTN_TOOL_PEN; |
fed87e65 HR |
362 | features->x_fuzz = 4; |
363 | features->y_fuzz = 4; | |
364 | features->pressure_fuzz = 0; | |
365 | features->distance_fuzz = 0; | |
ec67bbed PC |
366 | |
367 | /* only Tablet PCs need to retrieve the info */ | |
4a88081e PC |
368 | if ((features->type != TABLETPC) && (features->type != TABLETPC2FG) && |
369 | (features->type != BAMBOO_PT)) | |
ec67bbed PC |
370 | goto out; |
371 | ||
372 | if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) { | |
373 | if (usb_get_extra_descriptor(&interface->endpoint[0], | |
374 | HID_DEVICET_REPORT, &hid_desc)) { | |
375 | printk("wacom: can not retrieve extra class descriptor\n"); | |
376 | error = 1; | |
377 | goto out; | |
378 | } | |
379 | } | |
380 | error = wacom_parse_hid(intf, hid_desc, features); | |
381 | if (error) | |
382 | goto out; | |
383 | ||
ec67bbed PC |
384 | out: |
385 | return error; | |
386 | } | |
387 | ||
4492efff PC |
388 | struct wacom_usbdev_data { |
389 | struct list_head list; | |
390 | struct kref kref; | |
391 | struct usb_device *dev; | |
392 | struct wacom_shared shared; | |
393 | }; | |
394 | ||
395 | static LIST_HEAD(wacom_udev_list); | |
396 | static DEFINE_MUTEX(wacom_udev_list_lock); | |
397 | ||
398 | static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev) | |
399 | { | |
400 | struct wacom_usbdev_data *data; | |
401 | ||
402 | list_for_each_entry(data, &wacom_udev_list, list) { | |
403 | if (data->dev == dev) { | |
404 | kref_get(&data->kref); | |
405 | return data; | |
406 | } | |
407 | } | |
408 | ||
409 | return NULL; | |
410 | } | |
411 | ||
412 | static int wacom_add_shared_data(struct wacom_wac *wacom, | |
413 | struct usb_device *dev) | |
414 | { | |
415 | struct wacom_usbdev_data *data; | |
416 | int retval = 0; | |
417 | ||
418 | mutex_lock(&wacom_udev_list_lock); | |
419 | ||
420 | data = wacom_get_usbdev_data(dev); | |
421 | if (!data) { | |
422 | data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL); | |
423 | if (!data) { | |
424 | retval = -ENOMEM; | |
425 | goto out; | |
426 | } | |
427 | ||
428 | kref_init(&data->kref); | |
429 | data->dev = dev; | |
430 | list_add_tail(&data->list, &wacom_udev_list); | |
431 | } | |
432 | ||
433 | wacom->shared = &data->shared; | |
434 | ||
435 | out: | |
436 | mutex_unlock(&wacom_udev_list_lock); | |
437 | return retval; | |
438 | } | |
439 | ||
440 | static void wacom_release_shared_data(struct kref *kref) | |
441 | { | |
442 | struct wacom_usbdev_data *data = | |
443 | container_of(kref, struct wacom_usbdev_data, kref); | |
444 | ||
445 | mutex_lock(&wacom_udev_list_lock); | |
446 | list_del(&data->list); | |
447 | mutex_unlock(&wacom_udev_list_lock); | |
448 | ||
449 | kfree(data); | |
450 | } | |
451 | ||
452 | static void wacom_remove_shared_data(struct wacom_wac *wacom) | |
453 | { | |
454 | struct wacom_usbdev_data *data; | |
455 | ||
456 | if (wacom->shared) { | |
457 | data = container_of(wacom->shared, struct wacom_usbdev_data, shared); | |
458 | kref_put(&data->kref, wacom_release_shared_data); | |
459 | wacom->shared = NULL; | |
460 | } | |
461 | } | |
462 | ||
3bea733a PC |
463 | static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) |
464 | { | |
465 | struct usb_device *dev = interface_to_usbdev(intf); | |
466 | struct usb_endpoint_descriptor *endpoint; | |
467 | struct wacom *wacom; | |
468 | struct wacom_wac *wacom_wac; | |
e33da8a5 | 469 | struct wacom_features *features; |
3bea733a | 470 | struct input_dev *input_dev; |
e33da8a5 | 471 | int error; |
3bea733a | 472 | |
e33da8a5 | 473 | if (!id->driver_info) |
b036f6fb BB |
474 | return -EINVAL; |
475 | ||
3bea733a | 476 | wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); |
3bea733a | 477 | input_dev = input_allocate_device(); |
51269fe8 | 478 | if (!wacom || !input_dev) { |
e33da8a5 JC |
479 | error = -ENOMEM; |
480 | goto fail1; | |
481 | } | |
482 | ||
51269fe8 | 483 | wacom_wac = &wacom->wacom_wac; |
e33da8a5 JC |
484 | wacom_wac->features = *((struct wacom_features *)id->driver_info); |
485 | features = &wacom_wac->features; | |
486 | if (features->pktlen > WACOM_PKGLEN_MAX) { | |
487 | error = -EINVAL; | |
3bea733a | 488 | goto fail1; |
e33da8a5 | 489 | } |
3bea733a | 490 | |
997ea58e DM |
491 | wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX, |
492 | GFP_KERNEL, &wacom->data_dma); | |
e33da8a5 JC |
493 | if (!wacom_wac->data) { |
494 | error = -ENOMEM; | |
3bea733a | 495 | goto fail1; |
e33da8a5 | 496 | } |
3bea733a PC |
497 | |
498 | wacom->irq = usb_alloc_urb(0, GFP_KERNEL); | |
e33da8a5 JC |
499 | if (!wacom->irq) { |
500 | error = -ENOMEM; | |
3bea733a | 501 | goto fail2; |
e33da8a5 | 502 | } |
3bea733a PC |
503 | |
504 | wacom->usbdev = dev; | |
e7224094 ON |
505 | wacom->intf = intf; |
506 | mutex_init(&wacom->lock); | |
3bea733a PC |
507 | usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); |
508 | strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); | |
509 | ||
8da23fc1 | 510 | wacom_wac->input = input_dev; |
3bea733a | 511 | |
545f4e99 PC |
512 | endpoint = &intf->cur_altsetting->endpoint[0].desc; |
513 | ||
ec67bbed PC |
514 | /* Retrieve the physical and logical size for OEM devices */ |
515 | error = wacom_retrieve_hid_descriptor(intf, features); | |
516 | if (error) | |
517 | goto fail2; | |
545f4e99 | 518 | |
bc73dd39 HR |
519 | wacom_setup_device_quirks(features); |
520 | ||
49b764ae PC |
521 | strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); |
522 | ||
bc73dd39 | 523 | if (features->quirks & WACOM_QUIRK_MULTI_INPUT) { |
49b764ae PC |
524 | /* Append the device type to the name */ |
525 | strlcat(wacom_wac->name, | |
526 | features->device_type == BTN_TOOL_PEN ? | |
527 | " Pen" : " Finger", | |
528 | sizeof(wacom_wac->name)); | |
4492efff PC |
529 | |
530 | error = wacom_add_shared_data(wacom_wac, dev); | |
531 | if (error) | |
532 | goto fail3; | |
49b764ae PC |
533 | } |
534 | ||
8da23fc1 DT |
535 | input_dev->name = wacom_wac->name; |
536 | input_dev->dev.parent = &intf->dev; | |
537 | input_dev->open = wacom_open; | |
538 | input_dev->close = wacom_close; | |
539 | usb_to_input_id(dev, &input_dev->id); | |
540 | input_set_drvdata(input_dev, wacom); | |
e33da8a5 | 541 | |
8da23fc1 | 542 | wacom_setup_input_capabilities(input_dev, wacom_wac); |
3bea733a | 543 | |
3bea733a PC |
544 | usb_fill_int_urb(wacom->irq, dev, |
545 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), | |
ec67bbed | 546 | wacom_wac->data, features->pktlen, |
8d32e3ae | 547 | wacom_sys_irq, wacom, endpoint->bInterval); |
3bea733a PC |
548 | wacom->irq->transfer_dma = wacom->data_dma; |
549 | wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | |
550 | ||
8da23fc1 | 551 | error = input_register_device(input_dev); |
5014186d | 552 | if (error) |
4492efff | 553 | goto fail4; |
3bea733a | 554 | |
ec67bbed PC |
555 | /* Note that if query fails it is not a hard failure */ |
556 | wacom_query_tablet_data(intf, features); | |
3bea733a PC |
557 | |
558 | usb_set_intfdata(intf, wacom); | |
559 | return 0; | |
560 | ||
4492efff | 561 | fail4: wacom_remove_shared_data(wacom_wac); |
5014186d | 562 | fail3: usb_free_urb(wacom->irq); |
997ea58e | 563 | fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma); |
5014186d | 564 | fail1: input_free_device(input_dev); |
3bea733a | 565 | kfree(wacom); |
5014186d | 566 | return error; |
3bea733a PC |
567 | } |
568 | ||
569 | static void wacom_disconnect(struct usb_interface *intf) | |
570 | { | |
e7224094 | 571 | struct wacom *wacom = usb_get_intfdata(intf); |
3bea733a PC |
572 | |
573 | usb_set_intfdata(intf, NULL); | |
e7224094 ON |
574 | |
575 | usb_kill_urb(wacom->irq); | |
8da23fc1 | 576 | input_unregister_device(wacom->wacom_wac.input); |
e7224094 | 577 | usb_free_urb(wacom->irq); |
997ea58e | 578 | usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX, |
51269fe8 DT |
579 | wacom->wacom_wac.data, wacom->data_dma); |
580 | wacom_remove_shared_data(&wacom->wacom_wac); | |
e7224094 ON |
581 | kfree(wacom); |
582 | } | |
583 | ||
584 | static int wacom_suspend(struct usb_interface *intf, pm_message_t message) | |
585 | { | |
586 | struct wacom *wacom = usb_get_intfdata(intf); | |
587 | ||
588 | mutex_lock(&wacom->lock); | |
589 | usb_kill_urb(wacom->irq); | |
590 | mutex_unlock(&wacom->lock); | |
591 | ||
592 | return 0; | |
593 | } | |
594 | ||
595 | static int wacom_resume(struct usb_interface *intf) | |
596 | { | |
597 | struct wacom *wacom = usb_get_intfdata(intf); | |
51269fe8 | 598 | struct wacom_features *features = &wacom->wacom_wac.features; |
e7224094 ON |
599 | int rv; |
600 | ||
601 | mutex_lock(&wacom->lock); | |
38101475 PC |
602 | |
603 | /* switch to wacom mode first */ | |
604 | wacom_query_tablet_data(intf, features); | |
605 | ||
606 | if (wacom->open) | |
e7224094 | 607 | rv = usb_submit_urb(wacom->irq, GFP_NOIO); |
38101475 | 608 | else |
e7224094 | 609 | rv = 0; |
38101475 | 610 | |
e7224094 ON |
611 | mutex_unlock(&wacom->lock); |
612 | ||
613 | return rv; | |
614 | } | |
615 | ||
616 | static int wacom_reset_resume(struct usb_interface *intf) | |
617 | { | |
618 | return wacom_resume(intf); | |
3bea733a PC |
619 | } |
620 | ||
621 | static struct usb_driver wacom_driver = { | |
622 | .name = "wacom", | |
b036f6fb | 623 | .id_table = wacom_ids, |
3bea733a PC |
624 | .probe = wacom_probe, |
625 | .disconnect = wacom_disconnect, | |
e7224094 ON |
626 | .suspend = wacom_suspend, |
627 | .resume = wacom_resume, | |
628 | .reset_resume = wacom_reset_resume, | |
629 | .supports_autosuspend = 1, | |
3bea733a PC |
630 | }; |
631 | ||
632 | static int __init wacom_init(void) | |
633 | { | |
634 | int result; | |
b036f6fb | 635 | |
3bea733a PC |
636 | result = usb_register(&wacom_driver); |
637 | if (result == 0) | |
899ef6e7 GKH |
638 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
639 | DRIVER_DESC "\n"); | |
3bea733a PC |
640 | return result; |
641 | } | |
642 | ||
643 | static void __exit wacom_exit(void) | |
644 | { | |
645 | usb_deregister(&wacom_driver); | |
646 | } | |
647 | ||
648 | module_init(wacom_init); | |
649 | module_exit(wacom_exit); |