blob: b8624f27abf9a3540cbabd419f81b0494234fb61 [file] [log] [blame]
Ping Cheng3bea7332006-07-13 18:01:36 -07001/*
Dmitry Torokhov4104d132007-05-07 16:16:29 -04002 * drivers/input/tablet/wacom_sys.c
Ping Cheng3bea7332006-07-13 18:01:36 -07003 *
4 * USB Wacom Graphire and Wacom Intuos tablet support - system specific code
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
14#include "wacom.h"
15#include "wacom_wac.h"
16
Ping Cheng545f4e92008-11-24 11:44:27 -050017/* 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
33enum {
34 WCM_UNDEFINED = 0,
35 WCM_DESKTOP,
36 WCM_DIGITIZER,
37};
38
39struct 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 */
Ping Cheng3bea7332006-07-13 18:01:36 -070049#define USB_REQ_GET_REPORT 0x01
50#define USB_REQ_SET_REPORT 0x09
Ping Cheng545f4e92008-11-24 11:44:27 -050051#define WAC_HID_FEATURE_REPORT 0x03
Ping Cheng3bea7332006-07-13 18:01:36 -070052
53static 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
63static 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
73static struct input_dev * get_input_dev(struct wacom_combo *wcombo)
74{
75 return wcombo->wacom->dev;
76}
77
Adrian Bunk54c9b2262006-11-20 03:23:58 +010078static void wacom_sys_irq(struct urb *urb)
Ping Cheng3bea7332006-07-13 18:01:36 -070079{
80 struct wacom *wacom = urb->context;
81 struct wacom_combo wcombo;
82 int retval;
83
84 switch (urb->status) {
85 case 0:
86 /* success */
87 break;
88 case -ECONNRESET:
89 case -ENOENT:
90 case -ESHUTDOWN:
91 /* this urb is terminated, clean up */
Harvey Harrisonea3e6c52008-05-05 11:36:18 -040092 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
Ping Cheng3bea7332006-07-13 18:01:36 -070093 return;
94 default:
Harvey Harrisonea3e6c52008-05-05 11:36:18 -040095 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
Ping Cheng3bea7332006-07-13 18:01:36 -070096 goto exit;
97 }
98
99 wcombo.wacom = wacom;
100 wcombo.urb = urb;
Ping Cheng3bea7332006-07-13 18:01:36 -0700101
102 if (wacom_wac_irq(wacom->wacom_wac, (void *)&wcombo))
103 input_sync(get_input_dev(&wcombo));
104
105 exit:
Oliver Neukume7224092008-04-15 01:31:57 -0400106 usb_mark_last_busy(wacom->usbdev);
Ping Cheng3bea7332006-07-13 18:01:36 -0700107 retval = usb_submit_urb (urb, GFP_ATOMIC);
108 if (retval)
109 err ("%s - usb_submit_urb failed with result %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400110 __func__, retval);
Ping Cheng3bea7332006-07-13 18:01:36 -0700111}
112
113void wacom_report_key(void *wcombo, unsigned int key_type, int key_data)
114{
115 input_report_key(get_input_dev((struct wacom_combo *)wcombo), key_type, key_data);
Ping Cheng3bea7332006-07-13 18:01:36 -0700116}
117
118void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data)
119{
120 input_report_abs(get_input_dev((struct wacom_combo *)wcombo), abs_type, abs_data);
Ping Cheng3bea7332006-07-13 18:01:36 -0700121}
122
123void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data)
124{
125 input_report_rel(get_input_dev((struct wacom_combo *)wcombo), rel_type, rel_data);
Ping Cheng3bea7332006-07-13 18:01:36 -0700126}
127
128void wacom_input_event(void *wcombo, unsigned int type, unsigned int code, int value)
129{
130 input_event(get_input_dev((struct wacom_combo *)wcombo), type, code, value);
Ping Cheng3bea7332006-07-13 18:01:36 -0700131}
132
133__u16 wacom_be16_to_cpu(unsigned char *data)
134{
135 __u16 value;
136 value = be16_to_cpu(*(__be16 *) data);
137 return value;
138}
139
140__u16 wacom_le16_to_cpu(unsigned char *data)
141{
142 __u16 value;
Ping Cheng8d32e3a2006-09-26 13:34:47 -0700143 value = le16_to_cpu(*(__le16 *) data);
Ping Cheng3bea7332006-07-13 18:01:36 -0700144 return value;
145}
146
Ping Cheng3bea7332006-07-13 18:01:36 -0700147void wacom_input_sync(void *wcombo)
148{
149 input_sync(get_input_dev((struct wacom_combo *)wcombo));
Ping Cheng3bea7332006-07-13 18:01:36 -0700150}
151
152static int wacom_open(struct input_dev *dev)
153{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400154 struct wacom *wacom = input_get_drvdata(dev);
Ping Cheng3bea7332006-07-13 18:01:36 -0700155
Oliver Neukume7224092008-04-15 01:31:57 -0400156 mutex_lock(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -0700157
Oliver Neukume7224092008-04-15 01:31:57 -0400158 wacom->irq->dev = wacom->usbdev;
159
160 if (usb_autopm_get_interface(wacom->intf) < 0) {
161 mutex_unlock(&wacom->lock);
162 return -EIO;
163 }
164
165 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
166 usb_autopm_put_interface(wacom->intf);
167 mutex_unlock(&wacom->lock);
168 return -EIO;
169 }
170
171 wacom->open = 1;
172 wacom->intf->needs_remote_wakeup = 1;
173
174 mutex_unlock(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -0700175 return 0;
176}
177
178static void wacom_close(struct input_dev *dev)
179{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400180 struct wacom *wacom = input_get_drvdata(dev);
Ping Cheng3bea7332006-07-13 18:01:36 -0700181
Oliver Neukume7224092008-04-15 01:31:57 -0400182 mutex_lock(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -0700183 usb_kill_urb(wacom->irq);
Oliver Neukume7224092008-04-15 01:31:57 -0400184 wacom->open = 0;
185 wacom->intf->needs_remote_wakeup = 0;
186 mutex_unlock(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -0700187}
188
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400189void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
190{
Ping Cheng545f4e92008-11-24 11:44:27 -0500191 input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_1) |
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700192 BIT_MASK(BTN_5);
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400193 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
194}
195
Ping Cheng3bea7332006-07-13 18:01:36 -0700196void input_dev_g4(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
197{
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700198 input_dev->evbit[0] |= BIT_MASK(EV_MSC);
199 input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
200 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER);
Ping Cheng545f4e92008-11-24 11:44:27 -0500201 input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) |
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700202 BIT_MASK(BTN_4);
Ping Cheng3bea7332006-07-13 18:01:36 -0700203}
204
205void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
206{
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700207 input_dev->evbit[0] |= BIT_MASK(EV_REL);
208 input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);
Ping Cheng545f4e92008-11-24 11:44:27 -0500209 input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) |
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700210 BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
211 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
212 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_STYLUS2);
Ping Cheng3bea7332006-07-13 18:01:36 -0700213 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
214}
215
Ping Cheng8d32e3a2006-09-26 13:34:47 -0700216void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
Ping Cheng3bea7332006-07-13 18:01:36 -0700217{
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700218 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER);
Ping Cheng545f4e92008-11-24 11:44:27 -0500219 input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) |
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700220 BIT_MASK(BTN_1) | BIT_MASK(BTN_2) | BIT_MASK(BTN_3);
Ping Cheng071e0a22006-12-05 17:09:51 -0800221 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
Ping Cheng0e1763f2008-03-13 16:46:46 -0400222 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Ping Cheng8d32e3a2006-09-26 13:34:47 -0700223}
224
225void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
226{
Ping Cheng545f4e92008-11-24 11:44:27 -0500227 input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_4) |
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700228 BIT_MASK(BTN_5) | BIT_MASK(BTN_6) | BIT_MASK(BTN_7);
Ping Cheng071e0a22006-12-05 17:09:51 -0800229 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
Ping Cheng3bea7332006-07-13 18:01:36 -0700230}
231
Ping Cheng0e1763f2008-03-13 16:46:46 -0400232void input_dev_bee(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
233{
Ping Cheng545f4e92008-11-24 11:44:27 -0500234 input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_8) | BIT_MASK(BTN_9);
Ping Cheng0e1763f2008-03-13 16:46:46 -0400235}
236
Ping Cheng3bea7332006-07-13 18:01:36 -0700237void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
238{
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700239 input_dev->evbit[0] |= BIT_MASK(EV_MSC) | BIT_MASK(EV_REL);
240 input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
241 input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);
Ping Cheng545f4e92008-11-24 11:44:27 -0500242 input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) |
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700243 BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE) |
244 BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
245 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
246 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_TOOL_BRUSH) |
247 BIT_MASK(BTN_TOOL_PENCIL) | BIT_MASK(BTN_TOOL_AIRBRUSH) |
248 BIT_MASK(BTN_TOOL_LENS) | BIT_MASK(BTN_STYLUS2);
Ping Cheng3bea7332006-07-13 18:01:36 -0700249 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
250 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
251 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
252 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
253 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
254 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
255}
256
257void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
258{
Ping Cheng545f4e92008-11-24 11:44:27 -0500259 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_STYLUS2);
Ping Cheng3bea7332006-07-13 18:01:36 -0700260}
261
262void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
263{
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700264 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER);
Ping Cheng3bea7332006-07-13 18:01:36 -0700265}
266
Ping Cheng545f4e92008-11-24 11:44:27 -0500267static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc,
268 struct wacom_wac *wacom_wac)
269{
270 struct usb_device *dev = interface_to_usbdev(intf);
271 struct wacom_features *features = wacom_wac->features;
272 char limit = 0, result = 0;
273 int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
274 unsigned char *report;
275
276 report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
277 if (!report)
278 return -ENOMEM;
279
280 /* retrive report descriptors */
281 do {
282 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
283 USB_REQ_GET_DESCRIPTOR,
284 USB_RECIP_INTERFACE | USB_DIR_IN,
285 HID_DEVICET_REPORT << 8,
286 intf->altsetting[0].desc.bInterfaceNumber, /* interface */
287 report,
288 hid_desc->wDescriptorLength,
289 5000); /* 5 secs */
290 } while (result < 0 && limit++ < 5);
291
Ping Cheng384318e2009-04-28 07:49:54 -0700292 /* No need to parse the Descriptor. It isn't an error though */
Ping Cheng545f4e92008-11-24 11:44:27 -0500293 if (result < 0)
294 goto out;
295
296 for (i = 0; i < hid_desc->wDescriptorLength; i++) {
297
298 switch (report[i]) {
299 case HID_USAGE_PAGE:
300 switch (report[i + 1]) {
301 case HID_USAGE_PAGE_DIGITIZER:
302 usage = WCM_DIGITIZER;
303 i++;
304 break;
305
306 case HID_USAGE_PAGE_DESKTOP:
307 usage = WCM_DESKTOP;
308 i++;
309 break;
310 }
311 break;
312
313 case HID_USAGE:
314 switch (report[i + 1]) {
315 case HID_USAGE_X:
316 if (usage == WCM_DESKTOP) {
317 if (finger) {
318 features->touch_x_max =
319 features->touch_y_max =
320 wacom_le16_to_cpu(&report[i + 3]);
321 features->x_max =
322 wacom_le16_to_cpu(&report[i + 6]);
323 i += 7;
324 } else if (pen) {
325 features->x_max =
326 wacom_le16_to_cpu(&report[i + 3]);
327 i += 4;
328 }
329 } else if (usage == WCM_DIGITIZER) {
330 /* max pressure isn't reported
331 features->pressure_max = (unsigned short)
332 (report[i+4] << 8 | report[i + 3]);
333 */
334 features->pressure_max = 255;
335 i += 4;
336 }
337 break;
338
339 case HID_USAGE_Y:
340 if (usage == WCM_DESKTOP)
341 features->y_max =
342 wacom_le16_to_cpu(&report[i + 3]);
343 i += 4;
344 break;
345
346 case HID_USAGE_FINGER:
347 finger = 1;
348 i++;
349 break;
350
351 case HID_USAGE_STYLUS:
352 pen = 1;
353 i++;
354 break;
355
356 case HID_USAGE_UNDEFINED:
357 if (usage == WCM_DESKTOP && finger) /* capacity */
358 features->pressure_max =
359 wacom_le16_to_cpu(&report[i + 3]);
360 i += 4;
361 break;
362 }
363 break;
364
365 case HID_COLLECTION:
366 /* reset UsagePage ans Finger */
367 finger = usage = 0;
368 break;
369 }
370 }
371
Ping Cheng545f4e92008-11-24 11:44:27 -0500372 out:
Ping Cheng384318e2009-04-28 07:49:54 -0700373 result = 0;
Ping Cheng545f4e92008-11-24 11:44:27 -0500374 kfree(report);
375 return result;
376}
377
Ping Cheng3bea7332006-07-13 18:01:36 -0700378static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
379{
380 struct usb_device *dev = interface_to_usbdev(intf);
Ping Cheng545f4e92008-11-24 11:44:27 -0500381 struct usb_host_interface *interface = intf->cur_altsetting;
Ping Cheng3bea7332006-07-13 18:01:36 -0700382 struct usb_endpoint_descriptor *endpoint;
383 struct wacom *wacom;
384 struct wacom_wac *wacom_wac;
Ping Cheng545f4e92008-11-24 11:44:27 -0500385 struct wacom_features *features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700386 struct input_dev *input_dev;
Dmitry Torokhov50141862007-04-12 01:33:39 -0400387 int error = -ENOMEM;
Ping Cheng3bea7332006-07-13 18:01:36 -0700388 char rep_data[2], limit = 0;
Ping Cheng545f4e92008-11-24 11:44:27 -0500389 struct hid_descriptor *hid_desc;
Ping Cheng3bea7332006-07-13 18:01:36 -0700390
391 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
392 wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL);
393 input_dev = input_allocate_device();
394 if (!wacom || !input_dev || !wacom_wac)
395 goto fail1;
396
397 wacom_wac->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
398 if (!wacom_wac->data)
399 goto fail1;
400
401 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
402 if (!wacom->irq)
403 goto fail2;
404
405 wacom->usbdev = dev;
406 wacom->dev = input_dev;
Oliver Neukume7224092008-04-15 01:31:57 -0400407 wacom->intf = intf;
408 mutex_init(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -0700409 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
410 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
411
Ping Cheng545f4e92008-11-24 11:44:27 -0500412 wacom_wac->features = features = get_wacom_feature(id);
413 BUG_ON(features->pktlen > 10);
Ping Cheng3bea7332006-07-13 18:01:36 -0700414
415 input_dev->name = wacom_wac->features->name;
416 wacom->wacom_wac = wacom_wac;
417 usb_to_input_id(dev, &input_dev->id);
418
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -0400419 input_dev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400420
421 input_set_drvdata(input_dev, wacom);
422
Ping Cheng3bea7332006-07-13 18:01:36 -0700423 input_dev->open = wacom_open;
424 input_dev->close = wacom_close;
425
Ping Cheng545f4e92008-11-24 11:44:27 -0500426 endpoint = &intf->cur_altsetting->endpoint[0].desc;
427
Ping Cheng384318e2009-04-28 07:49:54 -0700428 /* Initialize touch_x_max and touch_y_max in case it is not defined */
429 if (wacom_wac->features->type == TABLETPC) {
430 features->touch_x_max = 1023;
431 features->touch_y_max = 1023;
432 } else {
433 features->touch_x_max = 0;
434 features->touch_y_max = 0;
435 }
436
Ping Cheng545f4e92008-11-24 11:44:27 -0500437 /* TabletPC need to retrieve the physical and logical maximum from report descriptor */
438 if (wacom_wac->features->type == TABLETPC) {
439 if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) {
440 if (usb_get_extra_descriptor(&interface->endpoint[0],
441 HID_DEVICET_REPORT, &hid_desc)) {
442 printk("wacom: can not retrive extra class descriptor\n");
443 goto fail2;
444 }
445 }
446 error = wacom_parse_hid(intf, hid_desc, wacom_wac);
447 if (error)
448 goto fail2;
449 }
450
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700451 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
452 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) |
453 BIT_MASK(BTN_TOUCH) | BIT_MASK(BTN_STYLUS);
Ping Cheng545f4e92008-11-24 11:44:27 -0500454 input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0);
455 input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0);
456 input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0);
457 if (features->type == TABLETPC) {
458 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_DOUBLETAP);
459 input_set_abs_params(input_dev, ABS_RX, 0, features->touch_x_max, 4, 0);
460 input_set_abs_params(input_dev, ABS_RY, 0, features->touch_y_max, 4, 0);
461 }
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700462 input_dev->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
Ping Cheng3bea7332006-07-13 18:01:36 -0700463
464 wacom_init_input_dev(input_dev, wacom_wac);
465
Ping Cheng3bea7332006-07-13 18:01:36 -0700466 usb_fill_int_urb(wacom->irq, dev,
467 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
468 wacom_wac->data, wacom_wac->features->pktlen,
Ping Cheng8d32e3a2006-09-26 13:34:47 -0700469 wacom_sys_irq, wacom, endpoint->bInterval);
Ping Cheng3bea7332006-07-13 18:01:36 -0700470 wacom->irq->transfer_dma = wacom->data_dma;
471 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
472
Dmitry Torokhov50141862007-04-12 01:33:39 -0400473 error = input_register_device(wacom->dev);
474 if (error)
475 goto fail3;
Ping Cheng3bea7332006-07-13 18:01:36 -0700476
Ping Cheng545f4e92008-11-24 11:44:27 -0500477 /*
478 * Ask the tablet to report tablet data if it is not a Tablet PC.
479 * Repeat until it succeeds
480 */
481 if (wacom_wac->features->type != TABLETPC) {
482 do {
483 rep_data[0] = 2;
484 rep_data[1] = 2;
485 error = usb_set_report(intf, WAC_HID_FEATURE_REPORT,
486 2, rep_data, 2);
487 if (error >= 0)
488 error = usb_get_report(intf,
489 WAC_HID_FEATURE_REPORT, 2,
490 rep_data, 2);
491 } while ((error < 0 || rep_data[1] != 2) && limit++ < 5);
492 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700493
494 usb_set_intfdata(intf, wacom);
495 return 0;
496
Dmitry Torokhov50141862007-04-12 01:33:39 -0400497 fail3: usb_free_urb(wacom->irq);
498 fail2: usb_buffer_free(dev, 10, wacom_wac->data, wacom->data_dma);
499 fail1: input_free_device(input_dev);
Ping Cheng3bea7332006-07-13 18:01:36 -0700500 kfree(wacom);
501 kfree(wacom_wac);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400502 return error;
Ping Cheng3bea7332006-07-13 18:01:36 -0700503}
504
505static void wacom_disconnect(struct usb_interface *intf)
506{
Oliver Neukume7224092008-04-15 01:31:57 -0400507 struct wacom *wacom = usb_get_intfdata(intf);
Ping Cheng3bea7332006-07-13 18:01:36 -0700508
509 usb_set_intfdata(intf, NULL);
Oliver Neukume7224092008-04-15 01:31:57 -0400510
511 usb_kill_urb(wacom->irq);
512 input_unregister_device(wacom->dev);
513 usb_free_urb(wacom->irq);
Ping Cheng545f4e92008-11-24 11:44:27 -0500514 usb_buffer_free(interface_to_usbdev(intf), 10,
515 wacom->wacom_wac->data, wacom->data_dma);
Oliver Neukume7224092008-04-15 01:31:57 -0400516 kfree(wacom->wacom_wac);
517 kfree(wacom);
518}
519
520static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
521{
522 struct wacom *wacom = usb_get_intfdata(intf);
523
524 mutex_lock(&wacom->lock);
525 usb_kill_urb(wacom->irq);
526 mutex_unlock(&wacom->lock);
527
528 return 0;
529}
530
531static int wacom_resume(struct usb_interface *intf)
532{
533 struct wacom *wacom = usb_get_intfdata(intf);
534 int rv;
535
536 mutex_lock(&wacom->lock);
537 if (wacom->open)
538 rv = usb_submit_urb(wacom->irq, GFP_NOIO);
539 else
540 rv = 0;
541 mutex_unlock(&wacom->lock);
542
543 return rv;
544}
545
546static int wacom_reset_resume(struct usb_interface *intf)
547{
548 return wacom_resume(intf);
Ping Cheng3bea7332006-07-13 18:01:36 -0700549}
550
551static struct usb_driver wacom_driver = {
552 .name = "wacom",
553 .probe = wacom_probe,
554 .disconnect = wacom_disconnect,
Oliver Neukume7224092008-04-15 01:31:57 -0400555 .suspend = wacom_suspend,
556 .resume = wacom_resume,
557 .reset_resume = wacom_reset_resume,
558 .supports_autosuspend = 1,
Ping Cheng3bea7332006-07-13 18:01:36 -0700559};
560
561static int __init wacom_init(void)
562{
563 int result;
564 wacom_driver.id_table = get_device_table();
565 result = usb_register(&wacom_driver);
566 if (result == 0)
Greg Kroah-Hartman899ef6e2008-08-18 13:21:04 -0700567 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
568 DRIVER_DESC "\n");
Ping Cheng3bea7332006-07-13 18:01:36 -0700569 return result;
570}
571
572static void __exit wacom_exit(void)
573{
574 usb_deregister(&wacom_driver);
575}
576
577module_init(wacom_init);
578module_exit(wacom_exit);