blob: 4f354737a8332ad20879bcf91acfde270f96ed5e [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 *
Ping Cheng232f5692009-12-15 00:35:24 -08004 * USB Wacom tablet support - system specific code
Ping Cheng3bea7332006-07-13 18:01:36 -07005 */
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
Ping Cheng3bea7332006-07-13 18:01:36 -070014#include "wacom_wac.h"
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070015#include "wacom.h"
Ping Cheng3bea7332006-07-13 18:01:36 -070016
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
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070051
Ping Cheng545f4e92008-11-24 11:44:27 -050052#define WAC_HID_FEATURE_REPORT 0x03
Ping Chenga417ea42011-08-16 00:17:56 -070053#define WAC_MSG_RETRIES 5
Ping Cheng3bea7332006-07-13 18:01:36 -070054
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070055#define WAC_CMD_LED_CONTROL 0x20
56#define WAC_CMD_ICON_START 0x21
57#define WAC_CMD_ICON_XFER 0x23
58#define WAC_CMD_RETRIES 10
59
60static int wacom_get_report(struct usb_interface *intf, u8 type, u8 id,
61 void *buf, size_t size, unsigned int retries)
Ping Cheng3bea7332006-07-13 18:01:36 -070062{
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070063 struct usb_device *dev = interface_to_usbdev(intf);
64 int retval;
65
66 do {
67 retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
68 USB_REQ_GET_REPORT,
Chris Bagwell6e8ec532011-10-26 22:24:22 -070069 USB_DIR_IN | USB_TYPE_CLASS |
70 USB_RECIP_INTERFACE,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070071 (type << 8) + id,
72 intf->altsetting[0].desc.bInterfaceNumber,
73 buf, size, 100);
74 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
75
76 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070077}
78
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070079static int wacom_set_report(struct usb_interface *intf, u8 type, u8 id,
80 void *buf, size_t size, unsigned int retries)
Ping Cheng3bea7332006-07-13 18:01:36 -070081{
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070082 struct usb_device *dev = interface_to_usbdev(intf);
83 int retval;
84
85 do {
86 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
87 USB_REQ_SET_REPORT,
88 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
89 (type << 8) + id,
90 intf->altsetting[0].desc.bInterfaceNumber,
91 buf, size, 1000);
92 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
93
94 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070095}
96
Adrian Bunk54c9b2262006-11-20 03:23:58 +010097static void wacom_sys_irq(struct urb *urb)
Ping Cheng3bea7332006-07-13 18:01:36 -070098{
99 struct wacom *wacom = urb->context;
Ping Cheng3bea7332006-07-13 18:01:36 -0700100 int retval;
101
102 switch (urb->status) {
103 case 0:
104 /* success */
105 break;
106 case -ECONNRESET:
107 case -ENOENT:
108 case -ESHUTDOWN:
109 /* this urb is terminated, clean up */
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400110 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
Ping Cheng3bea7332006-07-13 18:01:36 -0700111 return;
112 default:
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400113 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
Ping Cheng3bea7332006-07-13 18:01:36 -0700114 goto exit;
115 }
116
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700117 wacom_wac_irq(&wacom->wacom_wac, urb->actual_length);
Ping Cheng3bea7332006-07-13 18:01:36 -0700118
119 exit:
Oliver Neukume7224092008-04-15 01:31:57 -0400120 usb_mark_last_busy(wacom->usbdev);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700121 retval = usb_submit_urb(urb, GFP_ATOMIC);
Ping Cheng3bea7332006-07-13 18:01:36 -0700122 if (retval)
123 err ("%s - usb_submit_urb failed with result %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400124 __func__, retval);
Ping Cheng3bea7332006-07-13 18:01:36 -0700125}
126
Ping Cheng3bea7332006-07-13 18:01:36 -0700127static int wacom_open(struct input_dev *dev)
128{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400129 struct wacom *wacom = input_get_drvdata(dev);
Dmitry Torokhovf6cd3782010-10-04 21:46:11 -0700130 int retval = 0;
131
132 if (usb_autopm_get_interface(wacom->intf) < 0)
133 return -EIO;
Ping Cheng3bea7332006-07-13 18:01:36 -0700134
Oliver Neukume7224092008-04-15 01:31:57 -0400135 mutex_lock(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -0700136
Oliver Neukume7224092008-04-15 01:31:57 -0400137 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
Dmitry Torokhovf6cd3782010-10-04 21:46:11 -0700138 retval = -EIO;
139 goto out;
Oliver Neukume7224092008-04-15 01:31:57 -0400140 }
141
Dmitry Torokhov51269fe2010-03-19 22:18:15 -0700142 wacom->open = true;
Oliver Neukume7224092008-04-15 01:31:57 -0400143 wacom->intf->needs_remote_wakeup = 1;
144
Dmitry Torokhovf6cd3782010-10-04 21:46:11 -0700145out:
Oliver Neukume7224092008-04-15 01:31:57 -0400146 mutex_unlock(&wacom->lock);
Dmitry Torokhov62ecae02010-10-10 14:24:16 -0700147 usb_autopm_put_interface(wacom->intf);
Dmitry Torokhovf6cd3782010-10-04 21:46:11 -0700148 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -0700149}
150
151static void wacom_close(struct input_dev *dev)
152{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400153 struct wacom *wacom = input_get_drvdata(dev);
Dmitry Torokhov62ecae02010-10-10 14:24:16 -0700154 int autopm_error;
155
156 autopm_error = usb_autopm_get_interface(wacom->intf);
Ping Cheng3bea7332006-07-13 18:01:36 -0700157
Oliver Neukume7224092008-04-15 01:31:57 -0400158 mutex_lock(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -0700159 usb_kill_urb(wacom->irq);
Dmitry Torokhov51269fe2010-03-19 22:18:15 -0700160 wacom->open = false;
Oliver Neukume7224092008-04-15 01:31:57 -0400161 wacom->intf->needs_remote_wakeup = 0;
162 mutex_unlock(&wacom->lock);
Dmitry Torokhovf6cd3782010-10-04 21:46:11 -0700163
Dmitry Torokhov62ecae02010-10-10 14:24:16 -0700164 if (!autopm_error)
165 usb_autopm_put_interface(wacom->intf);
Ping Cheng3bea7332006-07-13 18:01:36 -0700166}
167
Ping Cheng545f4e92008-11-24 11:44:27 -0500168static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc,
Ping Chengec67bbe2009-12-15 00:35:24 -0800169 struct wacom_features *features)
Ping Cheng545f4e92008-11-24 11:44:27 -0500170{
171 struct usb_device *dev = interface_to_usbdev(intf);
Ping Chengec67bbe2009-12-15 00:35:24 -0800172 char limit = 0;
173 /* result has to be defined as int for some devices */
174 int result = 0;
Ping Cheng545f4e92008-11-24 11:44:27 -0500175 int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
176 unsigned char *report;
177
178 report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
179 if (!report)
180 return -ENOMEM;
181
182 /* retrive report descriptors */
183 do {
184 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
185 USB_REQ_GET_DESCRIPTOR,
186 USB_RECIP_INTERFACE | USB_DIR_IN,
187 HID_DEVICET_REPORT << 8,
188 intf->altsetting[0].desc.bInterfaceNumber, /* interface */
189 report,
190 hid_desc->wDescriptorLength,
191 5000); /* 5 secs */
Ping Chenga417ea42011-08-16 00:17:56 -0700192 } while (result < 0 && limit++ < WAC_MSG_RETRIES);
Ping Cheng545f4e92008-11-24 11:44:27 -0500193
Ping Cheng384318e2009-04-28 07:49:54 -0700194 /* No need to parse the Descriptor. It isn't an error though */
Ping Cheng545f4e92008-11-24 11:44:27 -0500195 if (result < 0)
196 goto out;
197
198 for (i = 0; i < hid_desc->wDescriptorLength; i++) {
199
200 switch (report[i]) {
201 case HID_USAGE_PAGE:
202 switch (report[i + 1]) {
203 case HID_USAGE_PAGE_DIGITIZER:
204 usage = WCM_DIGITIZER;
205 i++;
206 break;
207
208 case HID_USAGE_PAGE_DESKTOP:
209 usage = WCM_DESKTOP;
210 i++;
211 break;
212 }
213 break;
214
215 case HID_USAGE:
216 switch (report[i + 1]) {
217 case HID_USAGE_X:
218 if (usage == WCM_DESKTOP) {
219 if (finger) {
Ping Cheng84eb5aa2011-03-12 20:35:18 -0800220 features->device_type = BTN_TOOL_FINGER;
Ping Chengec67bbe2009-12-15 00:35:24 -0800221 if (features->type == TABLETPC2FG) {
222 /* need to reset back */
223 features->pktlen = WACOM_PKGLEN_TPC2FG;
Ping Cheng84eb5aa2011-03-12 20:35:18 -0800224 features->device_type = BTN_TOOL_DOUBLETAP;
Ping Chengec67bbe2009-12-15 00:35:24 -0800225 }
Ping Cheng4a880812010-09-05 12:25:40 -0700226 if (features->type == BAMBOO_PT) {
227 /* need to reset back */
228 features->pktlen = WACOM_PKGLEN_BBTOUCH;
Ping Cheng84eb5aa2011-03-12 20:35:18 -0800229 features->device_type = BTN_TOOL_DOUBLETAP;
Ping Cheng4a880812010-09-05 12:25:40 -0700230 features->x_phy =
231 get_unaligned_le16(&report[i + 5]);
232 features->x_max =
233 get_unaligned_le16(&report[i + 8]);
234 i += 15;
235 } else {
236 features->x_max =
237 get_unaligned_le16(&report[i + 3]);
238 features->x_phy =
239 get_unaligned_le16(&report[i + 6]);
240 features->unit = report[i + 9];
241 features->unitExpo = report[i + 11];
242 i += 12;
243 }
Ping Cheng545f4e92008-11-24 11:44:27 -0500244 } else if (pen) {
Ping Chengec67bbe2009-12-15 00:35:24 -0800245 /* penabled only accepts exact bytes of data */
246 if (features->type == TABLETPC2FG)
Ping Cheng57e413d2010-03-01 23:50:24 -0800247 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
Ping Cheng4a880812010-09-05 12:25:40 -0700248 if (features->type == BAMBOO_PT)
249 features->pktlen = WACOM_PKGLEN_BBFUN;
Ping Chengec67bbe2009-12-15 00:35:24 -0800250 features->device_type = BTN_TOOL_PEN;
Ping Cheng545f4e92008-11-24 11:44:27 -0500251 features->x_max =
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700252 get_unaligned_le16(&report[i + 3]);
Ping Cheng545f4e92008-11-24 11:44:27 -0500253 i += 4;
254 }
255 } else if (usage == WCM_DIGITIZER) {
256 /* max pressure isn't reported
257 features->pressure_max = (unsigned short)
258 (report[i+4] << 8 | report[i + 3]);
259 */
260 features->pressure_max = 255;
261 i += 4;
262 }
263 break;
264
265 case HID_USAGE_Y:
Ping Chengec67bbe2009-12-15 00:35:24 -0800266 if (usage == WCM_DESKTOP) {
267 if (finger) {
Ping Cheng84eb5aa2011-03-12 20:35:18 -0800268 features->device_type = BTN_TOOL_FINGER;
Ping Chengec67bbe2009-12-15 00:35:24 -0800269 if (features->type == TABLETPC2FG) {
270 /* need to reset back */
271 features->pktlen = WACOM_PKGLEN_TPC2FG;
Ping Cheng84eb5aa2011-03-12 20:35:18 -0800272 features->device_type = BTN_TOOL_DOUBLETAP;
Ping Chengec67bbe2009-12-15 00:35:24 -0800273 features->y_max =
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700274 get_unaligned_le16(&report[i + 3]);
Ping Chengec67bbe2009-12-15 00:35:24 -0800275 features->y_phy =
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700276 get_unaligned_le16(&report[i + 6]);
Ping Chengec67bbe2009-12-15 00:35:24 -0800277 i += 7;
Ping Cheng4a880812010-09-05 12:25:40 -0700278 } else if (features->type == BAMBOO_PT) {
279 /* need to reset back */
280 features->pktlen = WACOM_PKGLEN_BBTOUCH;
Ping Cheng84eb5aa2011-03-12 20:35:18 -0800281 features->device_type = BTN_TOOL_DOUBLETAP;
Ping Cheng4a880812010-09-05 12:25:40 -0700282 features->y_phy =
283 get_unaligned_le16(&report[i + 3]);
284 features->y_max =
285 get_unaligned_le16(&report[i + 6]);
286 i += 12;
Ping Chengec67bbe2009-12-15 00:35:24 -0800287 } else {
288 features->y_max =
289 features->x_max;
290 features->y_phy =
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700291 get_unaligned_le16(&report[i + 3]);
Ping Chengec67bbe2009-12-15 00:35:24 -0800292 i += 4;
293 }
294 } else if (pen) {
295 /* penabled only accepts exact bytes of data */
296 if (features->type == TABLETPC2FG)
Ping Cheng57e413d2010-03-01 23:50:24 -0800297 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
Ping Cheng4a880812010-09-05 12:25:40 -0700298 if (features->type == BAMBOO_PT)
299 features->pktlen = WACOM_PKGLEN_BBFUN;
Ping Chengec67bbe2009-12-15 00:35:24 -0800300 features->device_type = BTN_TOOL_PEN;
301 features->y_max =
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700302 get_unaligned_le16(&report[i + 3]);
Ping Chengec67bbe2009-12-15 00:35:24 -0800303 i += 4;
304 }
305 }
Ping Cheng545f4e92008-11-24 11:44:27 -0500306 break;
307
308 case HID_USAGE_FINGER:
309 finger = 1;
310 i++;
311 break;
312
313 case HID_USAGE_STYLUS:
314 pen = 1;
315 i++;
316 break;
317
318 case HID_USAGE_UNDEFINED:
319 if (usage == WCM_DESKTOP && finger) /* capacity */
320 features->pressure_max =
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700321 get_unaligned_le16(&report[i + 3]);
Ping Cheng545f4e92008-11-24 11:44:27 -0500322 i += 4;
323 break;
324 }
325 break;
326
327 case HID_COLLECTION:
Ping Chengec67bbe2009-12-15 00:35:24 -0800328 /* reset UsagePage and Finger */
Ping Cheng545f4e92008-11-24 11:44:27 -0500329 finger = usage = 0;
330 break;
331 }
332 }
333
Ping Cheng545f4e92008-11-24 11:44:27 -0500334 out:
Ping Cheng384318e2009-04-28 07:49:54 -0700335 result = 0;
Ping Cheng545f4e92008-11-24 11:44:27 -0500336 kfree(report);
337 return result;
338}
339
Ping Chengec67bbe2009-12-15 00:35:24 -0800340static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700341{
342 unsigned char *rep_data;
Ping Chengec67bbe2009-12-15 00:35:24 -0800343 int limit = 0, report_id = 2;
344 int error = -ENOMEM;
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700345
Ping Cheng3b48c912011-08-16 00:17:57 -0700346 rep_data = kmalloc(4, GFP_KERNEL);
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700347 if (!rep_data)
Ping Chengec67bbe2009-12-15 00:35:24 -0800348 return error;
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700349
Ping Cheng3b48c912011-08-16 00:17:57 -0700350 /* ask to report tablet data if it is MT Tablet PC or
Chris Bagwell3dc9f402010-09-12 00:08:40 -0700351 * not a Tablet PC */
352 if (features->type == TABLETPC2FG) {
Ping Chengec67bbe2009-12-15 00:35:24 -0800353 do {
354 rep_data[0] = 3;
355 rep_data[1] = 4;
Ping Cheng3b48c912011-08-16 00:17:57 -0700356 rep_data[2] = 0;
357 rep_data[3] = 0;
Ping Chengec67bbe2009-12-15 00:35:24 -0800358 report_id = 3;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700359 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
360 report_id, rep_data, 4, 1);
Ping Chengec67bbe2009-12-15 00:35:24 -0800361 if (error >= 0)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700362 error = wacom_get_report(intf,
363 WAC_HID_FEATURE_REPORT,
364 report_id, rep_data, 4, 1);
Ping Chenga417ea42011-08-16 00:17:56 -0700365 } while ((error < 0 || rep_data[1] != 4) && limit++ < WAC_MSG_RETRIES);
Chris Bagwell6e8ec532011-10-26 22:24:22 -0700366 } else if (features->type != TABLETPC &&
367 features->device_type == BTN_TOOL_PEN) {
Ping Chengec67bbe2009-12-15 00:35:24 -0800368 do {
369 rep_data[0] = 2;
370 rep_data[1] = 2;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700371 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
372 report_id, rep_data, 2, 1);
Ping Chengec67bbe2009-12-15 00:35:24 -0800373 if (error >= 0)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700374 error = wacom_get_report(intf,
375 WAC_HID_FEATURE_REPORT,
376 report_id, rep_data, 2, 1);
Ping Chenga417ea42011-08-16 00:17:56 -0700377 } while ((error < 0 || rep_data[1] != 2) && limit++ < WAC_MSG_RETRIES);
Ping Chengec67bbe2009-12-15 00:35:24 -0800378 }
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700379
380 kfree(rep_data);
381
382 return error < 0 ? error : 0;
383}
384
Ping Chengec67bbe2009-12-15 00:35:24 -0800385static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
386 struct wacom_features *features)
387{
388 int error = 0;
389 struct usb_host_interface *interface = intf->cur_altsetting;
390 struct hid_descriptor *hid_desc;
391
Henrik Rydbergfed87e62010-09-05 12:25:11 -0700392 /* default features */
Ping Chengec67bbe2009-12-15 00:35:24 -0800393 features->device_type = BTN_TOOL_PEN;
Henrik Rydbergfed87e62010-09-05 12:25:11 -0700394 features->x_fuzz = 4;
395 features->y_fuzz = 4;
396 features->pressure_fuzz = 0;
397 features->distance_fuzz = 0;
Ping Chengec67bbe2009-12-15 00:35:24 -0800398
Chris Bagwell3dc9f402010-09-12 00:08:40 -0700399 /* only Tablet PCs and Bamboo P&T need to retrieve the info */
Ping Cheng4a880812010-09-05 12:25:40 -0700400 if ((features->type != TABLETPC) && (features->type != TABLETPC2FG) &&
401 (features->type != BAMBOO_PT))
Ping Chengec67bbe2009-12-15 00:35:24 -0800402 goto out;
403
404 if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) {
405 if (usb_get_extra_descriptor(&interface->endpoint[0],
406 HID_DEVICET_REPORT, &hid_desc)) {
407 printk("wacom: can not retrieve extra class descriptor\n");
408 error = 1;
409 goto out;
410 }
411 }
412 error = wacom_parse_hid(intf, hid_desc, features);
413 if (error)
414 goto out;
415
Ping Chengec67bbe2009-12-15 00:35:24 -0800416 out:
417 return error;
418}
419
Ping Cheng4492eff2010-03-19 22:18:15 -0700420struct wacom_usbdev_data {
421 struct list_head list;
422 struct kref kref;
423 struct usb_device *dev;
424 struct wacom_shared shared;
425};
426
427static LIST_HEAD(wacom_udev_list);
428static DEFINE_MUTEX(wacom_udev_list_lock);
429
430static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev)
431{
432 struct wacom_usbdev_data *data;
433
434 list_for_each_entry(data, &wacom_udev_list, list) {
435 if (data->dev == dev) {
436 kref_get(&data->kref);
437 return data;
438 }
439 }
440
441 return NULL;
442}
443
444static int wacom_add_shared_data(struct wacom_wac *wacom,
445 struct usb_device *dev)
446{
447 struct wacom_usbdev_data *data;
448 int retval = 0;
449
450 mutex_lock(&wacom_udev_list_lock);
451
452 data = wacom_get_usbdev_data(dev);
453 if (!data) {
454 data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL);
455 if (!data) {
456 retval = -ENOMEM;
457 goto out;
458 }
459
460 kref_init(&data->kref);
461 data->dev = dev;
462 list_add_tail(&data->list, &wacom_udev_list);
463 }
464
465 wacom->shared = &data->shared;
466
467out:
468 mutex_unlock(&wacom_udev_list_lock);
469 return retval;
470}
471
472static void wacom_release_shared_data(struct kref *kref)
473{
474 struct wacom_usbdev_data *data =
475 container_of(kref, struct wacom_usbdev_data, kref);
476
477 mutex_lock(&wacom_udev_list_lock);
478 list_del(&data->list);
479 mutex_unlock(&wacom_udev_list_lock);
480
481 kfree(data);
482}
483
484static void wacom_remove_shared_data(struct wacom_wac *wacom)
485{
486 struct wacom_usbdev_data *data;
487
488 if (wacom->shared) {
489 data = container_of(wacom->shared, struct wacom_usbdev_data, shared);
490 kref_put(&data->kref, wacom_release_shared_data);
491 wacom->shared = NULL;
492 }
493}
494
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700495static int wacom_led_control(struct wacom *wacom)
496{
497 unsigned char *buf;
Ping Cheng09e7d942011-10-04 23:51:14 -0700498 int retval, led = 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700499
500 buf = kzalloc(9, GFP_KERNEL);
501 if (!buf)
502 return -ENOMEM;
503
Ping Cheng09e7d942011-10-04 23:51:14 -0700504 if (wacom->wacom_wac.features.type == WACOM_21UX2)
505 led = (wacom->led.select[1] << 4) | 0x40;
506
507 led |= wacom->led.select[0] | 0x4;
508
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700509 buf[0] = WAC_CMD_LED_CONTROL;
Ping Cheng09e7d942011-10-04 23:51:14 -0700510 buf[1] = led;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700511 buf[2] = wacom->led.llv;
512 buf[3] = wacom->led.hlv;
513 buf[4] = wacom->led.img_lum;
514
515 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL,
516 buf, 9, WAC_CMD_RETRIES);
517 kfree(buf);
518
519 return retval;
520}
521
522static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
523{
524 unsigned char *buf;
525 int i, retval;
526
527 buf = kzalloc(259, GFP_KERNEL);
528 if (!buf)
529 return -ENOMEM;
530
531 /* Send 'start' command */
532 buf[0] = WAC_CMD_ICON_START;
533 buf[1] = 1;
534 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
535 buf, 2, WAC_CMD_RETRIES);
536 if (retval < 0)
537 goto out;
538
539 buf[0] = WAC_CMD_ICON_XFER;
540 buf[1] = button_id & 0x07;
541 for (i = 0; i < 4; i++) {
542 buf[2] = i;
543 memcpy(buf + 3, img + i * 256, 256);
544
545 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER,
546 buf, 259, WAC_CMD_RETRIES);
547 if (retval < 0)
548 break;
549 }
550
551 /* Send 'stop' */
552 buf[0] = WAC_CMD_ICON_START;
553 buf[1] = 0;
554 wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
555 buf, 2, WAC_CMD_RETRIES);
556
557out:
558 kfree(buf);
559 return retval;
560}
561
Ping Cheng09e7d942011-10-04 23:51:14 -0700562static ssize_t wacom_led_select_store(struct device *dev, int set_id,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700563 const char *buf, size_t count)
564{
565 struct wacom *wacom = dev_get_drvdata(dev);
566 unsigned int id;
567 int err;
568
569 err = kstrtouint(buf, 10, &id);
570 if (err)
571 return err;
572
573 mutex_lock(&wacom->lock);
574
Ping Cheng09e7d942011-10-04 23:51:14 -0700575 wacom->led.select[set_id] = id & 0x3;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700576 err = wacom_led_control(wacom);
577
578 mutex_unlock(&wacom->lock);
579
580 return err < 0 ? err : count;
581}
582
Ping Cheng09e7d942011-10-04 23:51:14 -0700583#define DEVICE_LED_SELECT_ATTR(SET_ID) \
584static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
585 struct device_attribute *attr, const char *buf, size_t count) \
586{ \
587 return wacom_led_select_store(dev, SET_ID, buf, count); \
588} \
Ping Cheng04c59ab2011-10-04 23:51:49 -0700589static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
590 struct device_attribute *attr, char *buf) \
591{ \
592 struct wacom *wacom = dev_get_drvdata(dev); \
593 return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
594} \
595static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
596 wacom_led##SET_ID##_select_show, \
Ping Cheng09e7d942011-10-04 23:51:14 -0700597 wacom_led##SET_ID##_select_store)
598
599DEVICE_LED_SELECT_ATTR(0);
600DEVICE_LED_SELECT_ATTR(1);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700601
602static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
603 const char *buf, size_t count)
604{
605 unsigned int value;
606 int err;
607
608 err = kstrtouint(buf, 10, &value);
609 if (err)
610 return err;
611
612 mutex_lock(&wacom->lock);
613
614 *dest = value & 0x7f;
615 err = wacom_led_control(wacom);
616
617 mutex_unlock(&wacom->lock);
618
619 return err < 0 ? err : count;
620}
621
622#define DEVICE_LUMINANCE_ATTR(name, field) \
623static ssize_t wacom_##name##_luminance_store(struct device *dev, \
624 struct device_attribute *attr, const char *buf, size_t count) \
625{ \
626 struct wacom *wacom = dev_get_drvdata(dev); \
627 \
628 return wacom_luminance_store(wacom, &wacom->led.field, \
629 buf, count); \
630} \
631static DEVICE_ATTR(name##_luminance, S_IWUSR, \
632 NULL, wacom_##name##_luminance_store)
633
634DEVICE_LUMINANCE_ATTR(status0, llv);
635DEVICE_LUMINANCE_ATTR(status1, hlv);
636DEVICE_LUMINANCE_ATTR(buttons, img_lum);
637
638static ssize_t wacom_button_image_store(struct device *dev, int button_id,
639 const char *buf, size_t count)
640{
641 struct wacom *wacom = dev_get_drvdata(dev);
642 int err;
643
644 if (count != 1024)
645 return -EINVAL;
646
647 mutex_lock(&wacom->lock);
648
649 err = wacom_led_putimage(wacom, button_id, buf);
650
651 mutex_unlock(&wacom->lock);
652
653 return err < 0 ? err : count;
654}
655
656#define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
657static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
658 struct device_attribute *attr, const char *buf, size_t count) \
659{ \
660 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
661} \
662static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
663 NULL, wacom_btnimg##BUTTON_ID##_store)
664
665DEVICE_BTNIMG_ATTR(0);
666DEVICE_BTNIMG_ATTR(1);
667DEVICE_BTNIMG_ATTR(2);
668DEVICE_BTNIMG_ATTR(3);
669DEVICE_BTNIMG_ATTR(4);
670DEVICE_BTNIMG_ATTR(5);
671DEVICE_BTNIMG_ATTR(6);
672DEVICE_BTNIMG_ATTR(7);
673
Ping Cheng09e7d942011-10-04 23:51:14 -0700674static struct attribute *cintiq_led_attrs[] = {
675 &dev_attr_status_led0_select.attr,
676 &dev_attr_status_led1_select.attr,
677 NULL
678};
679
680static struct attribute_group cintiq_led_attr_group = {
681 .name = "wacom_led",
682 .attrs = cintiq_led_attrs,
683};
684
685static struct attribute *intuos4_led_attrs[] = {
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700686 &dev_attr_status0_luminance.attr,
687 &dev_attr_status1_luminance.attr,
Ping Cheng09e7d942011-10-04 23:51:14 -0700688 &dev_attr_status_led0_select.attr,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700689 &dev_attr_buttons_luminance.attr,
690 &dev_attr_button0_rawimg.attr,
691 &dev_attr_button1_rawimg.attr,
692 &dev_attr_button2_rawimg.attr,
693 &dev_attr_button3_rawimg.attr,
694 &dev_attr_button4_rawimg.attr,
695 &dev_attr_button5_rawimg.attr,
696 &dev_attr_button6_rawimg.attr,
697 &dev_attr_button7_rawimg.attr,
698 NULL
699};
700
Ping Cheng09e7d942011-10-04 23:51:14 -0700701static struct attribute_group intuos4_led_attr_group = {
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700702 .name = "wacom_led",
Ping Cheng09e7d942011-10-04 23:51:14 -0700703 .attrs = intuos4_led_attrs,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700704};
705
706static int wacom_initialize_leds(struct wacom *wacom)
707{
708 int error;
709
Ping Cheng09e7d942011-10-04 23:51:14 -0700710 /* Initialize default values */
711 switch (wacom->wacom_wac.features.type) {
712 case INTUOS4:
713 case INTUOS4L:
714 wacom->led.select[0] = 0;
715 wacom->led.select[1] = 0;
Ping Chengf4fa9a62011-10-04 23:49:42 -0700716 wacom->led.llv = 10;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700717 wacom->led.hlv = 20;
718 wacom->led.img_lum = 10;
Ping Cheng09e7d942011-10-04 23:51:14 -0700719 error = sysfs_create_group(&wacom->intf->dev.kobj,
720 &intuos4_led_attr_group);
721 break;
722
723 case WACOM_21UX2:
724 wacom->led.select[0] = 0;
725 wacom->led.select[1] = 0;
726 wacom->led.llv = 0;
727 wacom->led.hlv = 0;
728 wacom->led.img_lum = 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700729
730 error = sysfs_create_group(&wacom->intf->dev.kobj,
Ping Cheng09e7d942011-10-04 23:51:14 -0700731 &cintiq_led_attr_group);
732 break;
733
734 default:
735 return 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700736 }
737
Ping Cheng09e7d942011-10-04 23:51:14 -0700738 if (error) {
739 dev_err(&wacom->intf->dev,
740 "cannot create sysfs group err: %d\n", error);
741 return error;
742 }
743 wacom_led_control(wacom);
744
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700745 return 0;
746}
747
748static void wacom_destroy_leds(struct wacom *wacom)
749{
Ping Cheng09e7d942011-10-04 23:51:14 -0700750 switch (wacom->wacom_wac.features.type) {
751 case INTUOS4:
752 case INTUOS4L:
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700753 sysfs_remove_group(&wacom->intf->dev.kobj,
Ping Cheng09e7d942011-10-04 23:51:14 -0700754 &intuos4_led_attr_group);
755 break;
756
757 case WACOM_21UX2:
758 sysfs_remove_group(&wacom->intf->dev.kobj,
759 &cintiq_led_attr_group);
760 break;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700761 }
762}
763
Ping Cheng3bea7332006-07-13 18:01:36 -0700764static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
765{
766 struct usb_device *dev = interface_to_usbdev(intf);
767 struct usb_endpoint_descriptor *endpoint;
768 struct wacom *wacom;
769 struct wacom_wac *wacom_wac;
Jason Childse33da8a2010-02-17 22:38:31 -0800770 struct wacom_features *features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700771 struct input_dev *input_dev;
Jason Childse33da8a2010-02-17 22:38:31 -0800772 int error;
Ping Cheng3bea7332006-07-13 18:01:36 -0700773
Jason Childse33da8a2010-02-17 22:38:31 -0800774 if (!id->driver_info)
Bastian Blankb036f6f2010-02-10 23:06:23 -0800775 return -EINVAL;
776
Ping Cheng3bea7332006-07-13 18:01:36 -0700777 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
Ping Cheng3bea7332006-07-13 18:01:36 -0700778 input_dev = input_allocate_device();
Dmitry Torokhov51269fe2010-03-19 22:18:15 -0700779 if (!wacom || !input_dev) {
Jason Childse33da8a2010-02-17 22:38:31 -0800780 error = -ENOMEM;
Ping Cheng3bea7332006-07-13 18:01:36 -0700781 goto fail1;
Jason Childse33da8a2010-02-17 22:38:31 -0800782 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700783
Dmitry Torokhov51269fe2010-03-19 22:18:15 -0700784 wacom_wac = &wacom->wacom_wac;
Jason Childse33da8a2010-02-17 22:38:31 -0800785 wacom_wac->features = *((struct wacom_features *)id->driver_info);
786 features = &wacom_wac->features;
787 if (features->pktlen > WACOM_PKGLEN_MAX) {
788 error = -EINVAL;
Ping Cheng3bea7332006-07-13 18:01:36 -0700789 goto fail1;
Jason Childse33da8a2010-02-17 22:38:31 -0800790 }
791
Daniel Mack997ea582010-04-12 13:17:25 +0200792 wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX,
793 GFP_KERNEL, &wacom->data_dma);
Jason Childse33da8a2010-02-17 22:38:31 -0800794 if (!wacom_wac->data) {
795 error = -ENOMEM;
796 goto fail1;
797 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700798
799 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
Jason Childse33da8a2010-02-17 22:38:31 -0800800 if (!wacom->irq) {
801 error = -ENOMEM;
Ping Cheng3bea7332006-07-13 18:01:36 -0700802 goto fail2;
Jason Childse33da8a2010-02-17 22:38:31 -0800803 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700804
805 wacom->usbdev = dev;
Oliver Neukume7224092008-04-15 01:31:57 -0400806 wacom->intf = intf;
807 mutex_init(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -0700808 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
809 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
810
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700811 wacom_wac->input = input_dev;
Ping Cheng3bea7332006-07-13 18:01:36 -0700812
Ping Cheng545f4e92008-11-24 11:44:27 -0500813 endpoint = &intf->cur_altsetting->endpoint[0].desc;
814
Ping Chengec67bbe2009-12-15 00:35:24 -0800815 /* Retrieve the physical and logical size for OEM devices */
816 error = wacom_retrieve_hid_descriptor(intf, features);
817 if (error)
Alexander Strakh4b6d4432011-02-11 00:44:41 -0800818 goto fail3;
Ping Cheng545f4e92008-11-24 11:44:27 -0500819
Henrik Rydbergbc73dd32010-09-05 12:26:16 -0700820 wacom_setup_device_quirks(features);
821
Ping Cheng49b764a2010-02-20 00:53:49 -0800822 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
823
Henrik Rydbergbc73dd32010-09-05 12:26:16 -0700824 if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
Ping Cheng49b764a2010-02-20 00:53:49 -0800825 /* Append the device type to the name */
826 strlcat(wacom_wac->name,
827 features->device_type == BTN_TOOL_PEN ?
828 " Pen" : " Finger",
829 sizeof(wacom_wac->name));
Ping Cheng4492eff2010-03-19 22:18:15 -0700830
831 error = wacom_add_shared_data(wacom_wac, dev);
832 if (error)
833 goto fail3;
Ping Cheng49b764a2010-02-20 00:53:49 -0800834 }
835
836 input_dev->name = wacom_wac->name;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700837 input_dev->dev.parent = &intf->dev;
838 input_dev->open = wacom_open;
839 input_dev->close = wacom_close;
840 usb_to_input_id(dev, &input_dev->id);
841 input_set_drvdata(input_dev, wacom);
Jason Childse33da8a2010-02-17 22:38:31 -0800842
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700843 wacom_setup_input_capabilities(input_dev, wacom_wac);
Ping Cheng3bea7332006-07-13 18:01:36 -0700844
Ping Cheng3bea7332006-07-13 18:01:36 -0700845 usb_fill_int_urb(wacom->irq, dev,
846 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
Ping Chengec67bbe2009-12-15 00:35:24 -0800847 wacom_wac->data, features->pktlen,
Ping Cheng8d32e3a2006-09-26 13:34:47 -0700848 wacom_sys_irq, wacom, endpoint->bInterval);
Ping Cheng3bea7332006-07-13 18:01:36 -0700849 wacom->irq->transfer_dma = wacom->data_dma;
850 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
851
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700852 error = wacom_initialize_leds(wacom);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400853 if (error)
Ping Cheng4492eff2010-03-19 22:18:15 -0700854 goto fail4;
Ping Cheng3bea7332006-07-13 18:01:36 -0700855
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700856 error = input_register_device(input_dev);
857 if (error)
858 goto fail5;
859
Ping Chengec67bbe2009-12-15 00:35:24 -0800860 /* Note that if query fails it is not a hard failure */
861 wacom_query_tablet_data(intf, features);
Ping Cheng3bea7332006-07-13 18:01:36 -0700862
863 usb_set_intfdata(intf, wacom);
864 return 0;
865
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700866 fail5: wacom_destroy_leds(wacom);
Ping Cheng4492eff2010-03-19 22:18:15 -0700867 fail4: wacom_remove_shared_data(wacom_wac);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400868 fail3: usb_free_urb(wacom->irq);
Daniel Mack997ea582010-04-12 13:17:25 +0200869 fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400870 fail1: input_free_device(input_dev);
Ping Cheng3bea7332006-07-13 18:01:36 -0700871 kfree(wacom);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400872 return error;
Ping Cheng3bea7332006-07-13 18:01:36 -0700873}
874
875static void wacom_disconnect(struct usb_interface *intf)
876{
Oliver Neukume7224092008-04-15 01:31:57 -0400877 struct wacom *wacom = usb_get_intfdata(intf);
Ping Cheng3bea7332006-07-13 18:01:36 -0700878
879 usb_set_intfdata(intf, NULL);
Oliver Neukume7224092008-04-15 01:31:57 -0400880
881 usb_kill_urb(wacom->irq);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700882 input_unregister_device(wacom->wacom_wac.input);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700883 wacom_destroy_leds(wacom);
Oliver Neukume7224092008-04-15 01:31:57 -0400884 usb_free_urb(wacom->irq);
Daniel Mack997ea582010-04-12 13:17:25 +0200885 usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
Dmitry Torokhov51269fe2010-03-19 22:18:15 -0700886 wacom->wacom_wac.data, wacom->data_dma);
887 wacom_remove_shared_data(&wacom->wacom_wac);
Oliver Neukume7224092008-04-15 01:31:57 -0400888 kfree(wacom);
889}
890
891static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
892{
893 struct wacom *wacom = usb_get_intfdata(intf);
894
895 mutex_lock(&wacom->lock);
896 usb_kill_urb(wacom->irq);
897 mutex_unlock(&wacom->lock);
898
899 return 0;
900}
901
902static int wacom_resume(struct usb_interface *intf)
903{
904 struct wacom *wacom = usb_get_intfdata(intf);
Dmitry Torokhov51269fe2010-03-19 22:18:15 -0700905 struct wacom_features *features = &wacom->wacom_wac.features;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700906 int rv = 0;
Oliver Neukume7224092008-04-15 01:31:57 -0400907
908 mutex_lock(&wacom->lock);
Ping Cheng38101472010-04-13 23:07:52 -0700909
910 /* switch to wacom mode first */
911 wacom_query_tablet_data(intf, features);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700912 wacom_led_control(wacom);
Ping Cheng38101472010-04-13 23:07:52 -0700913
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700914 if (wacom->open && usb_submit_urb(wacom->irq, GFP_NOIO) < 0)
915 rv = -EIO;
Ping Cheng38101472010-04-13 23:07:52 -0700916
Oliver Neukume7224092008-04-15 01:31:57 -0400917 mutex_unlock(&wacom->lock);
918
919 return rv;
920}
921
922static int wacom_reset_resume(struct usb_interface *intf)
923{
924 return wacom_resume(intf);
Ping Cheng3bea7332006-07-13 18:01:36 -0700925}
926
927static struct usb_driver wacom_driver = {
928 .name = "wacom",
Bastian Blankb036f6f2010-02-10 23:06:23 -0800929 .id_table = wacom_ids,
Ping Cheng3bea7332006-07-13 18:01:36 -0700930 .probe = wacom_probe,
931 .disconnect = wacom_disconnect,
Oliver Neukume7224092008-04-15 01:31:57 -0400932 .suspend = wacom_suspend,
933 .resume = wacom_resume,
934 .reset_resume = wacom_reset_resume,
935 .supports_autosuspend = 1,
Ping Cheng3bea7332006-07-13 18:01:36 -0700936};
937
938static int __init wacom_init(void)
939{
940 int result;
Bastian Blankb036f6f2010-02-10 23:06:23 -0800941
Ping Cheng3bea7332006-07-13 18:01:36 -0700942 result = usb_register(&wacom_driver);
943 if (result == 0)
Greg Kroah-Hartman899ef6e2008-08-18 13:21:04 -0700944 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
945 DRIVER_DESC "\n");
Ping Cheng3bea7332006-07-13 18:01:36 -0700946 return result;
947}
948
949static void __exit wacom_exit(void)
950{
951 usb_deregister(&wacom_driver);
952}
953
954module_init(wacom_init);
955module_exit(wacom_exit);