blob: 5be6177554616f254cce0274ff399c7cbb4ceec0 [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
Jason Gerecke5866d9e2014-04-19 13:46:40 -070025#define HID_USAGE_X ((HID_USAGE_PAGE_DESKTOP << 16) | 0x30)
26#define HID_USAGE_Y ((HID_USAGE_PAGE_DESKTOP << 16) | 0x31)
27#define HID_USAGE_X_TILT ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x3d)
28#define HID_USAGE_Y_TILT ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x3e)
29#define HID_USAGE_FINGER ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x22)
30#define HID_USAGE_STYLUS ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x20)
31#define HID_USAGE_CONTACTMAX ((HID_USAGE_PAGE_DIGITIZER << 16) | 0x55)
Chris Bagwell41343612011-10-26 22:32:52 -070032#define HID_COLLECTION 0xa1
33#define HID_COLLECTION_LOGICAL 0x02
34#define HID_COLLECTION_END 0xc0
Ping Cheng545f4e92008-11-24 11:44:27 -050035
Ping Cheng545f4e92008-11-24 11:44:27 -050036struct hid_descriptor {
37 struct usb_descriptor_header header;
38 __le16 bcdHID;
39 u8 bCountryCode;
40 u8 bNumDescriptors;
41 u8 bDescriptorType;
42 __le16 wDescriptorLength;
43} __attribute__ ((packed));
44
45/* defines to get/set USB message */
Ping Cheng3bea7332006-07-13 18:01:36 -070046#define USB_REQ_GET_REPORT 0x01
47#define USB_REQ_SET_REPORT 0x09
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070048
Ping Cheng545f4e92008-11-24 11:44:27 -050049#define WAC_HID_FEATURE_REPORT 0x03
Ping Chenga417ea42011-08-16 00:17:56 -070050#define WAC_MSG_RETRIES 5
Ping Cheng3bea7332006-07-13 18:01:36 -070051
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070052#define WAC_CMD_LED_CONTROL 0x20
53#define WAC_CMD_ICON_START 0x21
54#define WAC_CMD_ICON_XFER 0x23
55#define WAC_CMD_RETRIES 10
56
57static int wacom_get_report(struct usb_interface *intf, u8 type, u8 id,
58 void *buf, size_t size, unsigned int retries)
Ping Cheng3bea7332006-07-13 18:01:36 -070059{
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070060 struct usb_device *dev = interface_to_usbdev(intf);
61 int retval;
62
63 do {
64 retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
65 USB_REQ_GET_REPORT,
Chris Bagwell6e8ec532011-10-26 22:24:22 -070066 USB_DIR_IN | USB_TYPE_CLASS |
67 USB_RECIP_INTERFACE,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070068 (type << 8) + id,
69 intf->altsetting[0].desc.bInterfaceNumber,
70 buf, size, 100);
71 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
72
73 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070074}
75
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070076static int wacom_set_report(struct usb_interface *intf, u8 type, u8 id,
77 void *buf, size_t size, unsigned int retries)
Ping Cheng3bea7332006-07-13 18:01:36 -070078{
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070079 struct usb_device *dev = interface_to_usbdev(intf);
80 int retval;
81
82 do {
83 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
84 USB_REQ_SET_REPORT,
85 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
86 (type << 8) + id,
87 intf->altsetting[0].desc.bInterfaceNumber,
88 buf, size, 1000);
89 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
90
91 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070092}
93
Adrian Bunk54c9b2262006-11-20 03:23:58 +010094static void wacom_sys_irq(struct urb *urb)
Ping Cheng3bea7332006-07-13 18:01:36 -070095{
96 struct wacom *wacom = urb->context;
Greg Kroah-Hartman65e78a202012-05-04 15:33:13 -070097 struct device *dev = &wacom->intf->dev;
Ping Cheng3bea7332006-07-13 18:01:36 -070098 int retval;
99
100 switch (urb->status) {
101 case 0:
102 /* success */
103 break;
104 case -ECONNRESET:
105 case -ENOENT:
106 case -ESHUTDOWN:
107 /* this urb is terminated, clean up */
Greg Kroah-Hartman3b6aee22012-05-01 21:24:28 -0700108 dev_dbg(dev, "%s - urb shutting down with status: %d\n",
109 __func__, urb->status);
Ping Cheng3bea7332006-07-13 18:01:36 -0700110 return;
111 default:
Greg Kroah-Hartman3b6aee22012-05-01 21:24:28 -0700112 dev_dbg(dev, "%s - nonzero urb status received: %d\n",
113 __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)
Greg Kroah-Hartman3b6aee22012-05-01 21:24:28 -0700123 dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
Greg Kroah-Hartmanb3169fe2012-04-25 14:48:44 -0700124 __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
Chris Bagwell16bf2882012-03-25 23:26:20 -0700168/*
Jason Gerecke115d5e12012-10-03 17:24:32 -0700169 * Calculate the resolution of the X or Y axis, given appropriate HID data.
170 * This function is little more than hidinput_calc_abs_res stripped down.
171 */
172static int wacom_calc_hid_res(int logical_extents, int physical_extents,
173 unsigned char unit, unsigned char exponent)
174{
175 int prev, unit_exponent;
176
177 /* Check if the extents are sane */
178 if (logical_extents <= 0 || physical_extents <= 0)
179 return 0;
180
181 /* Get signed value of nybble-sized twos-compliment exponent */
182 unit_exponent = exponent;
183 if (unit_exponent > 7)
184 unit_exponent -= 16;
185
186 /* Convert physical_extents to millimeters */
187 if (unit == 0x11) { /* If centimeters */
188 unit_exponent += 1;
189 } else if (unit == 0x13) { /* If inches */
190 prev = physical_extents;
191 physical_extents *= 254;
192 if (physical_extents < prev)
193 return 0;
194 unit_exponent -= 1;
195 } else {
196 return 0;
197 }
198
199 /* Apply negative unit exponent */
200 for (; unit_exponent < 0; unit_exponent++) {
201 prev = logical_extents;
202 logical_extents *= 10;
203 if (logical_extents < prev)
204 return 0;
205 }
206 /* Apply positive unit exponent */
207 for (; unit_exponent > 0; unit_exponent--) {
208 prev = physical_extents;
209 physical_extents *= 10;
210 if (physical_extents < prev)
211 return 0;
212 }
213
214 /* Calculate resolution */
215 return logical_extents / physical_extents;
216}
217
Chris Bagwell41343612011-10-26 22:32:52 -0700218static int wacom_parse_logical_collection(unsigned char *report,
219 struct wacom_features *features)
220{
221 int length = 0;
222
223 if (features->type == BAMBOO_PT) {
224
225 /* Logical collection is only used by 3rd gen Bamboo Touch */
226 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
Ping Cheng8b4a0c12012-01-31 00:07:33 -0800227 features->device_type = BTN_TOOL_FINGER;
Chris Bagwell41343612011-10-26 22:32:52 -0700228
Chris Bagwell41343612011-10-26 22:32:52 -0700229 features->x_max = features->y_max =
230 get_unaligned_le16(&report[10]);
231
232 length = 11;
233 }
234 return length;
235}
236
Ping Chengf393ee22012-04-29 21:09:17 -0700237static void wacom_retrieve_report_data(struct usb_interface *intf,
238 struct wacom_features *features)
239{
240 int result = 0;
241 unsigned char *rep_data;
242
243 rep_data = kmalloc(2, GFP_KERNEL);
244 if (rep_data) {
245
246 rep_data[0] = 12;
247 result = wacom_get_report(intf, WAC_HID_FEATURE_REPORT,
Ping Cheng61c91dd2012-06-28 16:46:27 -0700248 rep_data[0], rep_data, 2,
Ping Chengf393ee22012-04-29 21:09:17 -0700249 WAC_MSG_RETRIES);
250
251 if (result >= 0 && rep_data[1] > 2)
252 features->touch_max = rep_data[1];
253
254 kfree(rep_data);
255 }
256}
257
Chris Bagwell428f8582011-10-26 22:26:59 -0700258/*
259 * Interface Descriptor of wacom devices can be incomplete and
260 * inconsistent so wacom_features table is used to store stylus
261 * device's packet lengths, various maximum values, and tablet
262 * resolution based on product ID's.
263 *
264 * For devices that contain 2 interfaces, wacom_features table is
265 * inaccurate for the touch interface. Since the Interface Descriptor
266 * for touch interfaces has pretty complete data, this function exists
267 * to query tablet for this missing information instead of hard coding in
268 * an additional table.
269 *
270 * A typical Interface Descriptor for a stylus will contain a
271 * boot mouse application collection that is not of interest and this
272 * function will ignore it.
273 *
274 * It also contains a digitizer application collection that also is not
275 * of interest since any information it contains would be duplicate
276 * of what is in wacom_features. Usually it defines a report of an array
277 * of bytes that could be used as max length of the stylus packet returned.
278 * If it happens to define a Digitizer-Stylus Physical Collection then
279 * the X and Y logical values contain valid data but it is ignored.
280 *
281 * A typical Interface Descriptor for a touch interface will contain a
282 * Digitizer-Finger Physical Collection which will define both logical
283 * X/Y maximum as well as the physical size of tablet. Since touch
284 * interfaces haven't supported pressure or distance, this is enough
285 * information to override invalid values in the wacom_features table.
Chris Bagwell41343612011-10-26 22:32:52 -0700286 *
287 * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical
288 * Collection. Instead they define a Logical Collection with a single
289 * Logical Maximum for both X and Y.
Jason Gereckeae584ca2012-04-03 15:50:40 -0700290 *
291 * Intuos5 touch interface does not contain useful data. We deal with
292 * this after returning from this function.
Chris Bagwell428f8582011-10-26 22:26:59 -0700293 */
294static int wacom_parse_hid(struct usb_interface *intf,
295 struct hid_descriptor *hid_desc,
Ping Chengec67bbe2009-12-15 00:35:24 -0800296 struct wacom_features *features)
Ping Cheng545f4e92008-11-24 11:44:27 -0500297{
298 struct usb_device *dev = interface_to_usbdev(intf);
Ping Chengec67bbe2009-12-15 00:35:24 -0800299 char limit = 0;
300 /* result has to be defined as int for some devices */
Ping Cheng1d0d6df2013-11-25 18:43:45 -0800301 int result = 0, touch_max = 0;
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700302 int i = 0, page = 0, finger = 0, pen = 0;
Ping Cheng545f4e92008-11-24 11:44:27 -0500303 unsigned char *report;
304
305 report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
306 if (!report)
307 return -ENOMEM;
308
309 /* retrive report descriptors */
310 do {
311 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
312 USB_REQ_GET_DESCRIPTOR,
313 USB_RECIP_INTERFACE | USB_DIR_IN,
314 HID_DEVICET_REPORT << 8,
315 intf->altsetting[0].desc.bInterfaceNumber, /* interface */
316 report,
317 hid_desc->wDescriptorLength,
318 5000); /* 5 secs */
Ping Chenga417ea42011-08-16 00:17:56 -0700319 } while (result < 0 && limit++ < WAC_MSG_RETRIES);
Ping Cheng545f4e92008-11-24 11:44:27 -0500320
Ping Cheng384318e2009-04-28 07:49:54 -0700321 /* No need to parse the Descriptor. It isn't an error though */
Ping Cheng545f4e92008-11-24 11:44:27 -0500322 if (result < 0)
323 goto out;
324
325 for (i = 0; i < hid_desc->wDescriptorLength; i++) {
326
327 switch (report[i]) {
328 case HID_USAGE_PAGE:
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700329 page = report[i + 1];
330 i++;
Ping Cheng545f4e92008-11-24 11:44:27 -0500331 break;
332
333 case HID_USAGE:
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700334 switch (page << 16 | report[i + 1]) {
Ping Cheng545f4e92008-11-24 11:44:27 -0500335 case HID_USAGE_X:
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700336 if (finger) {
337 features->device_type = BTN_TOOL_FINGER;
338 /* touch device at least supports one touch point */
339 touch_max = 1;
340 switch (features->type) {
341 case TABLETPC2FG:
342 features->pktlen = WACOM_PKGLEN_TPC2FG;
343 break;
Ping Cheng3699dd72012-11-03 12:16:13 -0700344
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700345 case MTSCREEN:
346 case WACOM_24HDT:
347 features->pktlen = WACOM_PKGLEN_MTOUCH;
348 break;
Ping Cheng3699dd72012-11-03 12:16:13 -0700349
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700350 case MTTPC:
351 features->pktlen = WACOM_PKGLEN_MTTPC;
352 break;
Ping Cheng6afdc282012-11-03 12:16:15 -0700353
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700354 case BAMBOO_PT:
355 features->pktlen = WACOM_PKGLEN_BBTOUCH;
356 break;
Ping Cheng3699dd72012-11-03 12:16:13 -0700357
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700358 default:
359 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
360 break;
361 }
Ping Cheng19635182012-04-29 21:09:18 -0700362
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700363 switch (features->type) {
364 case BAMBOO_PT:
365 features->x_phy =
366 get_unaligned_le16(&report[i + 5]);
367 features->x_max =
368 get_unaligned_le16(&report[i + 8]);
369 i += 15;
370 break;
Ping Cheng3699dd72012-11-03 12:16:13 -0700371
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700372 case WACOM_24HDT:
Ping Cheng545f4e92008-11-24 11:44:27 -0500373 features->x_max =
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700374 get_unaligned_le16(&report[i + 3]);
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700375 features->x_phy =
376 get_unaligned_le16(&report[i + 8]);
377 features->unit = report[i - 1];
378 features->unitExpo = report[i - 3];
379 i += 12;
380 break;
381
382 default:
383 features->x_max =
384 get_unaligned_le16(&report[i + 3]);
385 features->x_phy =
386 get_unaligned_le16(&report[i + 6]);
387 features->unit = report[i + 9];
388 features->unitExpo = report[i + 11];
389 i += 12;
390 break;
Ping Cheng545f4e92008-11-24 11:44:27 -0500391 }
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700392 } else if (pen) {
393 /* penabled only accepts exact bytes of data */
394 if (features->type >= TABLETPC)
395 features->pktlen = WACOM_PKGLEN_GRAPHIRE;
396 features->device_type = BTN_TOOL_PEN;
397 features->x_max =
398 get_unaligned_le16(&report[i + 3]);
399 i += 4;
Ping Cheng545f4e92008-11-24 11:44:27 -0500400 }
401 break;
402
403 case HID_USAGE_Y:
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700404 if (finger) {
405 switch (features->type) {
406 case TABLETPC2FG:
407 case MTSCREEN:
408 case MTTPC:
Ping Chengec67bbe2009-12-15 00:35:24 -0800409 features->y_max =
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700410 get_unaligned_le16(&report[i + 3]);
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700411 features->y_phy =
412 get_unaligned_le16(&report[i + 6]);
413 i += 7;
414 break;
415
416 case WACOM_24HDT:
417 features->y_max =
418 get_unaligned_le16(&report[i + 3]);
419 features->y_phy =
420 get_unaligned_le16(&report[i - 2]);
421 i += 7;
422 break;
423
424 case BAMBOO_PT:
425 features->y_phy =
426 get_unaligned_le16(&report[i + 3]);
427 features->y_max =
428 get_unaligned_le16(&report[i + 6]);
429 i += 12;
430 break;
431
432 default:
433 features->y_max =
434 features->x_max;
435 features->y_phy =
436 get_unaligned_le16(&report[i + 3]);
Ping Chengec67bbe2009-12-15 00:35:24 -0800437 i += 4;
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700438 break;
Ping Chengec67bbe2009-12-15 00:35:24 -0800439 }
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700440 } else if (pen) {
441 features->y_max =
442 get_unaligned_le16(&report[i + 3]);
443 i += 4;
Ping Chengec67bbe2009-12-15 00:35:24 -0800444 }
Ping Cheng545f4e92008-11-24 11:44:27 -0500445 break;
446
447 case HID_USAGE_FINGER:
448 finger = 1;
449 i++;
450 break;
451
Chris Bagwell428f8582011-10-26 22:26:59 -0700452 /*
453 * Requiring Stylus Usage will ignore boot mouse
454 * X/Y values and some cases of invalid Digitizer X/Y
455 * values commonly reported.
456 */
Ping Cheng545f4e92008-11-24 11:44:27 -0500457 case HID_USAGE_STYLUS:
458 pen = 1;
459 i++;
460 break;
Ping Chengf393ee22012-04-29 21:09:17 -0700461
462 case HID_USAGE_CONTACTMAX:
Ping Cheng1cecc5c2012-06-28 16:47:30 -0700463 /* leave touch_max as is if predefined */
464 if (!features->touch_max)
465 wacom_retrieve_report_data(intf, features);
Ping Chengf393ee22012-04-29 21:09:17 -0700466 i++;
467 break;
Ping Cheng545f4e92008-11-24 11:44:27 -0500468 }
469 break;
470
Chris Bagwell41343612011-10-26 22:32:52 -0700471 case HID_COLLECTION_END:
Ping Chengec67bbe2009-12-15 00:35:24 -0800472 /* reset UsagePage and Finger */
Jason Gerecke5866d9e2014-04-19 13:46:40 -0700473 finger = page = 0;
Ping Cheng545f4e92008-11-24 11:44:27 -0500474 break;
Chris Bagwell41343612011-10-26 22:32:52 -0700475
476 case HID_COLLECTION:
477 i++;
478 switch (report[i]) {
479 case HID_COLLECTION_LOGICAL:
480 i += wacom_parse_logical_collection(&report[i],
481 features);
482 break;
483 }
484 break;
Ping Cheng545f4e92008-11-24 11:44:27 -0500485 }
486 }
487
Ping Cheng545f4e92008-11-24 11:44:27 -0500488 out:
Ping Cheng1d0d6df2013-11-25 18:43:45 -0800489 if (!features->touch_max && touch_max)
490 features->touch_max = touch_max;
Ping Cheng384318e2009-04-28 07:49:54 -0700491 result = 0;
Ping Cheng545f4e92008-11-24 11:44:27 -0500492 kfree(report);
493 return result;
494}
495
Jason Gereckefe494bc2012-10-03 17:25:35 -0700496static int wacom_set_device_mode(struct usb_interface *intf, int report_id, int length, int mode)
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700497{
498 unsigned char *rep_data;
Jason Gereckefe494bc2012-10-03 17:25:35 -0700499 int error = -ENOMEM, limit = 0;
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700500
Jason Gereckefe494bc2012-10-03 17:25:35 -0700501 rep_data = kzalloc(length, GFP_KERNEL);
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700502 if (!rep_data)
Ping Chengec67bbe2009-12-15 00:35:24 -0800503 return error;
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700504
Jason Gereckefe494bc2012-10-03 17:25:35 -0700505 do {
Chris Bagwell9937c022013-01-23 19:37:34 -0800506 rep_data[0] = report_id;
507 rep_data[1] = mode;
508
Jason Gereckefe494bc2012-10-03 17:25:35 -0700509 error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
510 report_id, rep_data, length, 1);
Jason Gereckefe494bc2012-10-03 17:25:35 -0700511 } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES);
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700512
513 kfree(rep_data);
514
515 return error < 0 ? error : 0;
516}
517
Jason Gereckefe494bc2012-10-03 17:25:35 -0700518/*
519 * Switch the tablet into its most-capable mode. Wacom tablets are
520 * typically configured to power-up in a mode which sends mouse-like
521 * reports to the OS. To get absolute position, pressure data, etc.
522 * from the tablet, it is necessary to switch the tablet out of this
523 * mode and into one which sends the full range of tablet data.
524 */
525static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
526{
527 if (features->device_type == BTN_TOOL_FINGER) {
528 if (features->type > TABLETPC) {
529 /* MT Tablet PC touch */
530 return wacom_set_device_mode(intf, 3, 4, 4);
531 }
Jason Gerecke36d3c512013-09-20 09:47:35 -0700532 else if (features->type == WACOM_24HDT || features->type == CINTIQ_HYBRID) {
Jason Gereckeb1e42792012-10-21 00:38:04 -0700533 return wacom_set_device_mode(intf, 18, 3, 2);
534 }
Jason Gereckefe494bc2012-10-03 17:25:35 -0700535 } else if (features->device_type == BTN_TOOL_PEN) {
536 if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
537 return wacom_set_device_mode(intf, 2, 2, 2);
538 }
539 }
540
541 return 0;
542}
543
Ping Chengec67bbe2009-12-15 00:35:24 -0800544static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
Ping Cheng19635182012-04-29 21:09:18 -0700545 struct wacom_features *features)
Ping Chengec67bbe2009-12-15 00:35:24 -0800546{
547 int error = 0;
548 struct usb_host_interface *interface = intf->cur_altsetting;
549 struct hid_descriptor *hid_desc;
550
Henrik Rydbergfed87e62010-09-05 12:25:11 -0700551 /* default features */
Ping Chengec67bbe2009-12-15 00:35:24 -0800552 features->device_type = BTN_TOOL_PEN;
Henrik Rydbergfed87e62010-09-05 12:25:11 -0700553 features->x_fuzz = 4;
554 features->y_fuzz = 4;
555 features->pressure_fuzz = 0;
556 features->distance_fuzz = 0;
Ping Chengec67bbe2009-12-15 00:35:24 -0800557
Chris Bagwelld3825d52012-03-25 23:26:11 -0700558 /*
559 * The wireless device HID is basic and layout conflicts with
560 * other tablets (monitor and touch interface can look like pen).
561 * Skip the query for this type and modify defaults based on
562 * interface number.
563 */
564 if (features->type == WIRELESS) {
565 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
566 features->device_type = 0;
567 } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
Ping Chengadad0042012-06-28 16:48:17 -0700568 features->device_type = BTN_TOOL_FINGER;
Chris Bagwelld3825d52012-03-25 23:26:11 -0700569 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
570 }
571 }
572
Ping Cheng19635182012-04-29 21:09:18 -0700573 /* only devices that support touch need to retrieve the info */
Ping Chengea2e6022012-06-12 00:14:12 -0700574 if (features->type < BAMBOO_PT) {
Ping Chengec67bbe2009-12-15 00:35:24 -0800575 goto out;
Ping Cheng19635182012-04-29 21:09:18 -0700576 }
Ping Chengec67bbe2009-12-15 00:35:24 -0800577
Dmitry Torokhova882c932012-05-02 00:13:38 -0700578 error = usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc);
579 if (error) {
580 error = usb_get_extra_descriptor(&interface->endpoint[0],
581 HID_DEVICET_REPORT, &hid_desc);
582 if (error) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700583 dev_err(&intf->dev,
584 "can not retrieve extra class descriptor\n");
Ping Chengec67bbe2009-12-15 00:35:24 -0800585 goto out;
586 }
587 }
588 error = wacom_parse_hid(intf, hid_desc, features);
Ping Chengec67bbe2009-12-15 00:35:24 -0800589
Ping Chengec67bbe2009-12-15 00:35:24 -0800590 out:
591 return error;
592}
593
Ping Cheng4492eff2010-03-19 22:18:15 -0700594struct wacom_usbdev_data {
595 struct list_head list;
596 struct kref kref;
597 struct usb_device *dev;
598 struct wacom_shared shared;
599};
600
601static LIST_HEAD(wacom_udev_list);
602static DEFINE_MUTEX(wacom_udev_list_lock);
603
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700604static struct usb_device *wacom_get_sibling(struct usb_device *dev, int vendor, int product)
605{
606 int port1;
607 struct usb_device *sibling;
608
609 if (vendor == 0 && product == 0)
610 return dev;
611
612 if (dev->parent == NULL)
613 return NULL;
614
615 usb_hub_for_each_child(dev->parent, port1, sibling) {
616 struct usb_device_descriptor *d;
617 if (sibling == NULL)
618 continue;
619
620 d = &sibling->descriptor;
621 if (d->idVendor == vendor && d->idProduct == product)
622 return sibling;
623 }
624
625 return NULL;
626}
627
Ping Cheng4492eff2010-03-19 22:18:15 -0700628static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev)
629{
630 struct wacom_usbdev_data *data;
631
632 list_for_each_entry(data, &wacom_udev_list, list) {
633 if (data->dev == dev) {
634 kref_get(&data->kref);
635 return data;
636 }
637 }
638
639 return NULL;
640}
641
642static int wacom_add_shared_data(struct wacom_wac *wacom,
643 struct usb_device *dev)
644{
645 struct wacom_usbdev_data *data;
646 int retval = 0;
647
648 mutex_lock(&wacom_udev_list_lock);
649
650 data = wacom_get_usbdev_data(dev);
651 if (!data) {
652 data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL);
653 if (!data) {
654 retval = -ENOMEM;
655 goto out;
656 }
657
658 kref_init(&data->kref);
659 data->dev = dev;
660 list_add_tail(&data->list, &wacom_udev_list);
661 }
662
663 wacom->shared = &data->shared;
664
665out:
666 mutex_unlock(&wacom_udev_list_lock);
667 return retval;
668}
669
670static void wacom_release_shared_data(struct kref *kref)
671{
672 struct wacom_usbdev_data *data =
673 container_of(kref, struct wacom_usbdev_data, kref);
674
675 mutex_lock(&wacom_udev_list_lock);
676 list_del(&data->list);
677 mutex_unlock(&wacom_udev_list_lock);
678
679 kfree(data);
680}
681
682static void wacom_remove_shared_data(struct wacom_wac *wacom)
683{
684 struct wacom_usbdev_data *data;
685
686 if (wacom->shared) {
687 data = container_of(wacom->shared, struct wacom_usbdev_data, shared);
688 kref_put(&data->kref, wacom_release_shared_data);
689 wacom->shared = NULL;
690 }
691}
692
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700693static int wacom_led_control(struct wacom *wacom)
694{
695 unsigned char *buf;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700696 int retval;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700697
698 buf = kzalloc(9, GFP_KERNEL);
699 if (!buf)
700 return -ENOMEM;
701
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700702 if (wacom->wacom_wac.features.type >= INTUOS5S &&
Ping Cheng9a35c412013-09-20 09:51:56 -0700703 wacom->wacom_wac.features.type <= INTUOSPL) {
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700704 /*
705 * Touch Ring and crop mark LED luminance may take on
706 * one of four values:
707 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
708 */
709 int ring_led = wacom->led.select[0] & 0x03;
710 int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
711 int crop_lum = 0;
Ping Cheng09e7d942011-10-04 23:51:14 -0700712
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700713 buf[0] = WAC_CMD_LED_CONTROL;
714 buf[1] = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
715 }
716 else {
717 int led = wacom->led.select[0] | 0x4;
Ping Cheng09e7d942011-10-04 23:51:14 -0700718
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700719 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
720 wacom->wacom_wac.features.type == WACOM_24HD)
721 led |= (wacom->led.select[1] << 4) | 0x40;
722
723 buf[0] = WAC_CMD_LED_CONTROL;
724 buf[1] = led;
725 buf[2] = wacom->led.llv;
726 buf[3] = wacom->led.hlv;
727 buf[4] = wacom->led.img_lum;
728 }
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700729
730 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL,
731 buf, 9, WAC_CMD_RETRIES);
732 kfree(buf);
733
734 return retval;
735}
736
737static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
738{
739 unsigned char *buf;
740 int i, retval;
741
742 buf = kzalloc(259, GFP_KERNEL);
743 if (!buf)
744 return -ENOMEM;
745
746 /* Send 'start' command */
747 buf[0] = WAC_CMD_ICON_START;
748 buf[1] = 1;
749 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
750 buf, 2, WAC_CMD_RETRIES);
751 if (retval < 0)
752 goto out;
753
754 buf[0] = WAC_CMD_ICON_XFER;
755 buf[1] = button_id & 0x07;
756 for (i = 0; i < 4; i++) {
757 buf[2] = i;
758 memcpy(buf + 3, img + i * 256, 256);
759
760 retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER,
761 buf, 259, WAC_CMD_RETRIES);
762 if (retval < 0)
763 break;
764 }
765
766 /* Send 'stop' */
767 buf[0] = WAC_CMD_ICON_START;
768 buf[1] = 0;
769 wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
770 buf, 2, WAC_CMD_RETRIES);
771
772out:
773 kfree(buf);
774 return retval;
775}
776
Ping Cheng09e7d942011-10-04 23:51:14 -0700777static ssize_t wacom_led_select_store(struct device *dev, int set_id,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700778 const char *buf, size_t count)
779{
780 struct wacom *wacom = dev_get_drvdata(dev);
781 unsigned int id;
782 int err;
783
784 err = kstrtouint(buf, 10, &id);
785 if (err)
786 return err;
787
788 mutex_lock(&wacom->lock);
789
Ping Cheng09e7d942011-10-04 23:51:14 -0700790 wacom->led.select[set_id] = id & 0x3;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700791 err = wacom_led_control(wacom);
792
793 mutex_unlock(&wacom->lock);
794
795 return err < 0 ? err : count;
796}
797
Ping Cheng09e7d942011-10-04 23:51:14 -0700798#define DEVICE_LED_SELECT_ATTR(SET_ID) \
799static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
800 struct device_attribute *attr, const char *buf, size_t count) \
801{ \
802 return wacom_led_select_store(dev, SET_ID, buf, count); \
803} \
Ping Cheng04c59ab2011-10-04 23:51:49 -0700804static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
805 struct device_attribute *attr, char *buf) \
806{ \
807 struct wacom *wacom = dev_get_drvdata(dev); \
808 return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
809} \
810static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
811 wacom_led##SET_ID##_select_show, \
Ping Cheng09e7d942011-10-04 23:51:14 -0700812 wacom_led##SET_ID##_select_store)
813
814DEVICE_LED_SELECT_ATTR(0);
815DEVICE_LED_SELECT_ATTR(1);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700816
817static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
818 const char *buf, size_t count)
819{
820 unsigned int value;
821 int err;
822
823 err = kstrtouint(buf, 10, &value);
824 if (err)
825 return err;
826
827 mutex_lock(&wacom->lock);
828
829 *dest = value & 0x7f;
830 err = wacom_led_control(wacom);
831
832 mutex_unlock(&wacom->lock);
833
834 return err < 0 ? err : count;
835}
836
837#define DEVICE_LUMINANCE_ATTR(name, field) \
838static ssize_t wacom_##name##_luminance_store(struct device *dev, \
839 struct device_attribute *attr, const char *buf, size_t count) \
840{ \
841 struct wacom *wacom = dev_get_drvdata(dev); \
842 \
843 return wacom_luminance_store(wacom, &wacom->led.field, \
844 buf, count); \
845} \
846static DEVICE_ATTR(name##_luminance, S_IWUSR, \
847 NULL, wacom_##name##_luminance_store)
848
849DEVICE_LUMINANCE_ATTR(status0, llv);
850DEVICE_LUMINANCE_ATTR(status1, hlv);
851DEVICE_LUMINANCE_ATTR(buttons, img_lum);
852
853static ssize_t wacom_button_image_store(struct device *dev, int button_id,
854 const char *buf, size_t count)
855{
856 struct wacom *wacom = dev_get_drvdata(dev);
857 int err;
858
859 if (count != 1024)
860 return -EINVAL;
861
862 mutex_lock(&wacom->lock);
863
864 err = wacom_led_putimage(wacom, button_id, buf);
865
866 mutex_unlock(&wacom->lock);
867
868 return err < 0 ? err : count;
869}
870
871#define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
872static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
873 struct device_attribute *attr, const char *buf, size_t count) \
874{ \
875 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
876} \
877static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
878 NULL, wacom_btnimg##BUTTON_ID##_store)
879
880DEVICE_BTNIMG_ATTR(0);
881DEVICE_BTNIMG_ATTR(1);
882DEVICE_BTNIMG_ATTR(2);
883DEVICE_BTNIMG_ATTR(3);
884DEVICE_BTNIMG_ATTR(4);
885DEVICE_BTNIMG_ATTR(5);
886DEVICE_BTNIMG_ATTR(6);
887DEVICE_BTNIMG_ATTR(7);
888
Ping Cheng09e7d942011-10-04 23:51:14 -0700889static struct attribute *cintiq_led_attrs[] = {
890 &dev_attr_status_led0_select.attr,
891 &dev_attr_status_led1_select.attr,
892 NULL
893};
894
895static struct attribute_group cintiq_led_attr_group = {
896 .name = "wacom_led",
897 .attrs = cintiq_led_attrs,
898};
899
900static struct attribute *intuos4_led_attrs[] = {
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700901 &dev_attr_status0_luminance.attr,
902 &dev_attr_status1_luminance.attr,
Ping Cheng09e7d942011-10-04 23:51:14 -0700903 &dev_attr_status_led0_select.attr,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700904 &dev_attr_buttons_luminance.attr,
905 &dev_attr_button0_rawimg.attr,
906 &dev_attr_button1_rawimg.attr,
907 &dev_attr_button2_rawimg.attr,
908 &dev_attr_button3_rawimg.attr,
909 &dev_attr_button4_rawimg.attr,
910 &dev_attr_button5_rawimg.attr,
911 &dev_attr_button6_rawimg.attr,
912 &dev_attr_button7_rawimg.attr,
913 NULL
914};
915
Ping Cheng09e7d942011-10-04 23:51:14 -0700916static struct attribute_group intuos4_led_attr_group = {
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700917 .name = "wacom_led",
Ping Cheng09e7d942011-10-04 23:51:14 -0700918 .attrs = intuos4_led_attrs,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700919};
920
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700921static struct attribute *intuos5_led_attrs[] = {
922 &dev_attr_status0_luminance.attr,
923 &dev_attr_status_led0_select.attr,
924 NULL
925};
926
927static struct attribute_group intuos5_led_attr_group = {
928 .name = "wacom_led",
929 .attrs = intuos5_led_attrs,
930};
931
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700932static int wacom_initialize_leds(struct wacom *wacom)
933{
934 int error;
935
Ping Cheng09e7d942011-10-04 23:51:14 -0700936 /* Initialize default values */
937 switch (wacom->wacom_wac.features.type) {
Jason Gereckea19fc982012-06-12 00:27:53 -0700938 case INTUOS4S:
Ping Cheng09e7d942011-10-04 23:51:14 -0700939 case INTUOS4:
940 case INTUOS4L:
941 wacom->led.select[0] = 0;
942 wacom->led.select[1] = 0;
Ping Chengf4fa9a62011-10-04 23:49:42 -0700943 wacom->led.llv = 10;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700944 wacom->led.hlv = 20;
945 wacom->led.img_lum = 10;
Ping Cheng09e7d942011-10-04 23:51:14 -0700946 error = sysfs_create_group(&wacom->intf->dev.kobj,
947 &intuos4_led_attr_group);
948 break;
949
Jason Gerecke246835f2011-12-12 00:12:04 -0800950 case WACOM_24HD:
Ping Cheng09e7d942011-10-04 23:51:14 -0700951 case WACOM_21UX2:
952 wacom->led.select[0] = 0;
953 wacom->led.select[1] = 0;
954 wacom->led.llv = 0;
955 wacom->led.hlv = 0;
956 wacom->led.img_lum = 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700957
958 error = sysfs_create_group(&wacom->intf->dev.kobj,
Ping Cheng09e7d942011-10-04 23:51:14 -0700959 &cintiq_led_attr_group);
960 break;
961
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700962 case INTUOS5S:
963 case INTUOS5:
964 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -0700965 case INTUOSPS:
966 case INTUOSPM:
967 case INTUOSPL:
Ping Chengc2b0c272013-09-20 09:50:14 -0700968 if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) {
969 wacom->led.select[0] = 0;
970 wacom->led.select[1] = 0;
971 wacom->led.llv = 32;
972 wacom->led.hlv = 0;
973 wacom->led.img_lum = 0;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700974
Ping Chengc2b0c272013-09-20 09:50:14 -0700975 error = sysfs_create_group(&wacom->intf->dev.kobj,
976 &intuos5_led_attr_group);
977 } else
978 return 0;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700979 break;
980
Ping Cheng09e7d942011-10-04 23:51:14 -0700981 default:
982 return 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700983 }
984
Ping Cheng09e7d942011-10-04 23:51:14 -0700985 if (error) {
986 dev_err(&wacom->intf->dev,
987 "cannot create sysfs group err: %d\n", error);
988 return error;
989 }
990 wacom_led_control(wacom);
991
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700992 return 0;
993}
994
995static void wacom_destroy_leds(struct wacom *wacom)
996{
Ping Cheng09e7d942011-10-04 23:51:14 -0700997 switch (wacom->wacom_wac.features.type) {
Jason Gereckea19fc982012-06-12 00:27:53 -0700998 case INTUOS4S:
Ping Cheng09e7d942011-10-04 23:51:14 -0700999 case INTUOS4:
1000 case INTUOS4L:
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001001 sysfs_remove_group(&wacom->intf->dev.kobj,
Ping Cheng09e7d942011-10-04 23:51:14 -07001002 &intuos4_led_attr_group);
1003 break;
1004
Jason Gerecke246835f2011-12-12 00:12:04 -08001005 case WACOM_24HD:
Ping Cheng09e7d942011-10-04 23:51:14 -07001006 case WACOM_21UX2:
1007 sysfs_remove_group(&wacom->intf->dev.kobj,
1008 &cintiq_led_attr_group);
1009 break;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -07001010
1011 case INTUOS5S:
1012 case INTUOS5:
1013 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07001014 case INTUOSPS:
1015 case INTUOSPM:
1016 case INTUOSPL:
Ping Chengc2b0c272013-09-20 09:50:14 -07001017 if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN)
1018 sysfs_remove_group(&wacom->intf->dev.kobj,
1019 &intuos5_led_attr_group);
Jason Gerecke9b5b95d2012-04-03 15:50:37 -07001020 break;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001021 }
1022}
1023
Chris Bagwella1d552c2012-03-25 23:26:30 -07001024static enum power_supply_property wacom_battery_props[] = {
Bastien Nocera6e2a6e82013-10-15 23:33:00 -07001025 POWER_SUPPLY_PROP_SCOPE,
Chris Bagwella1d552c2012-03-25 23:26:30 -07001026 POWER_SUPPLY_PROP_CAPACITY
1027};
1028
1029static int wacom_battery_get_property(struct power_supply *psy,
1030 enum power_supply_property psp,
1031 union power_supply_propval *val)
1032{
1033 struct wacom *wacom = container_of(psy, struct wacom, battery);
1034 int ret = 0;
1035
1036 switch (psp) {
Bastien Nocera6e2a6e82013-10-15 23:33:00 -07001037 case POWER_SUPPLY_PROP_SCOPE:
1038 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1039 break;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001040 case POWER_SUPPLY_PROP_CAPACITY:
1041 val->intval =
1042 wacom->wacom_wac.battery_capacity * 100 / 31;
1043 break;
1044 default:
1045 ret = -EINVAL;
1046 break;
1047 }
1048
1049 return ret;
1050}
1051
1052static int wacom_initialize_battery(struct wacom *wacom)
1053{
1054 int error = 0;
1055
1056 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) {
1057 wacom->battery.properties = wacom_battery_props;
1058 wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
1059 wacom->battery.get_property = wacom_battery_get_property;
1060 wacom->battery.name = "wacom_battery";
1061 wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
1062 wacom->battery.use_for_apm = 0;
1063
1064 error = power_supply_register(&wacom->usbdev->dev,
1065 &wacom->battery);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001066
1067 if (!error)
1068 power_supply_powers(&wacom->battery,
1069 &wacom->usbdev->dev);
Chris Bagwella1d552c2012-03-25 23:26:30 -07001070 }
1071
1072 return error;
1073}
1074
1075static void wacom_destroy_battery(struct wacom *wacom)
1076{
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001077 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR &&
1078 wacom->battery.dev) {
Chris Bagwella1d552c2012-03-25 23:26:30 -07001079 power_supply_unregister(&wacom->battery);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001080 wacom->battery.dev = NULL;
1081 }
Chris Bagwella1d552c2012-03-25 23:26:30 -07001082}
1083
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001084static int wacom_register_input(struct wacom *wacom)
1085{
1086 struct input_dev *input_dev;
1087 struct usb_interface *intf = wacom->intf;
1088 struct usb_device *dev = interface_to_usbdev(intf);
1089 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1090 int error;
1091
1092 input_dev = input_allocate_device();
Ping Cheng19635182012-04-29 21:09:18 -07001093 if (!input_dev) {
1094 error = -ENOMEM;
1095 goto fail1;
1096 }
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001097
1098 input_dev->name = wacom_wac->name;
1099 input_dev->dev.parent = &intf->dev;
1100 input_dev->open = wacom_open;
1101 input_dev->close = wacom_close;
1102 usb_to_input_id(dev, &input_dev->id);
1103 input_set_drvdata(input_dev, wacom);
1104
1105 wacom_wac->input = input_dev;
Ping Cheng19635182012-04-29 21:09:18 -07001106 error = wacom_setup_input_capabilities(input_dev, wacom_wac);
1107 if (error)
1108 goto fail1;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001109
1110 error = input_register_device(input_dev);
Ping Cheng19635182012-04-29 21:09:18 -07001111 if (error)
1112 goto fail2;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001113
Ping Cheng19635182012-04-29 21:09:18 -07001114 return 0;
1115
1116fail2:
1117 input_free_device(input_dev);
1118 wacom_wac->input = NULL;
1119fail1:
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001120 return error;
1121}
1122
Chris Bagwell16bf2882012-03-25 23:26:20 -07001123static void wacom_wireless_work(struct work_struct *work)
1124{
1125 struct wacom *wacom = container_of(work, struct wacom, work);
1126 struct usb_device *usbdev = wacom->usbdev;
1127 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001128 struct wacom *wacom1, *wacom2;
1129 struct wacom_wac *wacom_wac1, *wacom_wac2;
1130 int error;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001131
1132 /*
1133 * Regardless if this is a disconnect or a new tablet,
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001134 * remove any existing input and battery devices.
Chris Bagwell16bf2882012-03-25 23:26:20 -07001135 */
1136
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001137 wacom_destroy_battery(wacom);
1138
Chris Bagwell16bf2882012-03-25 23:26:20 -07001139 /* Stylus interface */
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001140 wacom1 = usb_get_intfdata(usbdev->config->interface[1]);
1141 wacom_wac1 = &(wacom1->wacom_wac);
1142 if (wacom_wac1->input)
1143 input_unregister_device(wacom_wac1->input);
1144 wacom_wac1->input = NULL;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001145
1146 /* Touch interface */
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001147 wacom2 = usb_get_intfdata(usbdev->config->interface[2]);
1148 wacom_wac2 = &(wacom2->wacom_wac);
1149 if (wacom_wac2->input)
1150 input_unregister_device(wacom_wac2->input);
1151 wacom_wac2->input = NULL;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001152
1153 if (wacom_wac->pid == 0) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -07001154 dev_info(&wacom->intf->dev, "wireless tablet disconnected\n");
Chris Bagwell16bf2882012-03-25 23:26:20 -07001155 } else {
1156 const struct usb_device_id *id = wacom_ids;
1157
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -07001158 dev_info(&wacom->intf->dev,
1159 "wireless tablet connected with PID %x\n",
1160 wacom_wac->pid);
Chris Bagwell16bf2882012-03-25 23:26:20 -07001161
1162 while (id->match_flags) {
1163 if (id->idVendor == USB_VENDOR_ID_WACOM &&
1164 id->idProduct == wacom_wac->pid)
1165 break;
1166 id++;
1167 }
1168
1169 if (!id->match_flags) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -07001170 dev_info(&wacom->intf->dev,
1171 "ignoring unknown PID.\n");
Chris Bagwell16bf2882012-03-25 23:26:20 -07001172 return;
1173 }
1174
1175 /* Stylus interface */
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001176 wacom_wac1->features =
Chris Bagwell16bf2882012-03-25 23:26:20 -07001177 *((struct wacom_features *)id->driver_info);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001178 wacom_wac1->features.device_type = BTN_TOOL_PEN;
Ping Cheng57bcfce2013-10-15 23:44:00 -07001179 snprintf(wacom_wac1->name, WACOM_NAME_MAX, "%s (WL) Pen",
1180 wacom_wac1->features.name);
Ping Cheng961794a2013-12-05 12:54:53 -08001181 wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max;
1182 wacom_wac1->shared->type = wacom_wac1->features.type;
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001183 error = wacom_register_input(wacom1);
1184 if (error)
Ping Cheng57bcfce2013-10-15 23:44:00 -07001185 goto fail;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001186
1187 /* Touch interface */
Ping Chengb5fd2a32013-11-25 18:44:55 -08001188 if (wacom_wac1->features.touch_max ||
1189 wacom_wac1->features.type == INTUOSHT) {
Ping Cheng57bcfce2013-10-15 23:44:00 -07001190 wacom_wac2->features =
1191 *((struct wacom_features *)id->driver_info);
1192 wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
1193 wacom_wac2->features.device_type = BTN_TOOL_FINGER;
1194 wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
1195 if (wacom_wac2->features.touch_max)
1196 snprintf(wacom_wac2->name, WACOM_NAME_MAX,
1197 "%s (WL) Finger",wacom_wac2->features.name);
1198 else
1199 snprintf(wacom_wac2->name, WACOM_NAME_MAX,
1200 "%s (WL) Pad",wacom_wac2->features.name);
1201 error = wacom_register_input(wacom2);
1202 if (error)
1203 goto fail;
Ping Cheng961794a2013-12-05 12:54:53 -08001204
1205 if (wacom_wac1->features.type == INTUOSHT &&
1206 wacom_wac1->features.touch_max)
1207 wacom_wac->shared->touch_input = wacom_wac2->input;
Ping Cheng57bcfce2013-10-15 23:44:00 -07001208 }
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001209
1210 error = wacom_initialize_battery(wacom);
1211 if (error)
Ping Cheng57bcfce2013-10-15 23:44:00 -07001212 goto fail;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001213 }
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001214
1215 return;
1216
Ping Cheng57bcfce2013-10-15 23:44:00 -07001217fail:
1218 if (wacom_wac2->input) {
1219 input_unregister_device(wacom_wac2->input);
1220 wacom_wac2->input = NULL;
1221 }
1222
1223 if (wacom_wac1->input) {
1224 input_unregister_device(wacom_wac1->input);
1225 wacom_wac1->input = NULL;
1226 }
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001227 return;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001228}
1229
Ping Cheng401d7d12013-07-28 00:38:54 -07001230/*
1231 * Not all devices report physical dimensions from HID.
1232 * Compute the default from hardcoded logical dimension
1233 * and resolution before driver overwrites them.
1234 */
1235static void wacom_set_default_phy(struct wacom_features *features)
1236{
1237 if (features->x_resolution) {
1238 features->x_phy = (features->x_max * 100) /
1239 features->x_resolution;
1240 features->y_phy = (features->y_max * 100) /
1241 features->y_resolution;
1242 }
1243}
1244
1245static void wacom_calculate_res(struct wacom_features *features)
1246{
1247 features->x_resolution = wacom_calc_hid_res(features->x_max,
1248 features->x_phy,
1249 features->unit,
1250 features->unitExpo);
1251 features->y_resolution = wacom_calc_hid_res(features->y_max,
1252 features->y_phy,
1253 features->unit,
1254 features->unitExpo);
1255}
1256
Ping Cheng3bea7332006-07-13 18:01:36 -07001257static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
1258{
1259 struct usb_device *dev = interface_to_usbdev(intf);
1260 struct usb_endpoint_descriptor *endpoint;
1261 struct wacom *wacom;
1262 struct wacom_wac *wacom_wac;
Jason Childse33da8a2010-02-17 22:38:31 -08001263 struct wacom_features *features;
Jason Childse33da8a2010-02-17 22:38:31 -08001264 int error;
Ping Cheng3bea7332006-07-13 18:01:36 -07001265
Jason Childse33da8a2010-02-17 22:38:31 -08001266 if (!id->driver_info)
Bastian Blankb036f6f2010-02-10 23:06:23 -08001267 return -EINVAL;
1268
Ping Cheng3bea7332006-07-13 18:01:36 -07001269 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
Dan Carpenterf1823942012-03-29 22:38:11 -07001270 if (!wacom)
1271 return -ENOMEM;
Ping Cheng3bea7332006-07-13 18:01:36 -07001272
Dmitry Torokhov51269fe2010-03-19 22:18:15 -07001273 wacom_wac = &wacom->wacom_wac;
Jason Childse33da8a2010-02-17 22:38:31 -08001274 wacom_wac->features = *((struct wacom_features *)id->driver_info);
1275 features = &wacom_wac->features;
1276 if (features->pktlen > WACOM_PKGLEN_MAX) {
1277 error = -EINVAL;
Ping Cheng3bea7332006-07-13 18:01:36 -07001278 goto fail1;
Jason Childse33da8a2010-02-17 22:38:31 -08001279 }
1280
Daniel Mack997ea582010-04-12 13:17:25 +02001281 wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX,
1282 GFP_KERNEL, &wacom->data_dma);
Jason Childse33da8a2010-02-17 22:38:31 -08001283 if (!wacom_wac->data) {
1284 error = -ENOMEM;
1285 goto fail1;
1286 }
Ping Cheng3bea7332006-07-13 18:01:36 -07001287
1288 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
Jason Childse33da8a2010-02-17 22:38:31 -08001289 if (!wacom->irq) {
1290 error = -ENOMEM;
Ping Cheng3bea7332006-07-13 18:01:36 -07001291 goto fail2;
Jason Childse33da8a2010-02-17 22:38:31 -08001292 }
Ping Cheng3bea7332006-07-13 18:01:36 -07001293
1294 wacom->usbdev = dev;
Oliver Neukume7224092008-04-15 01:31:57 -04001295 wacom->intf = intf;
1296 mutex_init(&wacom->lock);
Chris Bagwell16bf2882012-03-25 23:26:20 -07001297 INIT_WORK(&wacom->work, wacom_wireless_work);
Ping Cheng3bea7332006-07-13 18:01:36 -07001298 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
1299 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
1300
Ping Cheng545f4e92008-11-24 11:44:27 -05001301 endpoint = &intf->cur_altsetting->endpoint[0].desc;
1302
Ping Cheng401d7d12013-07-28 00:38:54 -07001303 /* set the default size in case we do not get them from hid */
1304 wacom_set_default_phy(features);
1305
Ping Chengf393ee22012-04-29 21:09:17 -07001306 /* Retrieve the physical and logical size for touch devices */
Ping Chengec67bbe2009-12-15 00:35:24 -08001307 error = wacom_retrieve_hid_descriptor(intf, features);
1308 if (error)
Alexander Strakh4b6d4432011-02-11 00:44:41 -08001309 goto fail3;
Ping Cheng545f4e92008-11-24 11:44:27 -05001310
Jason Gereckeae584ca2012-04-03 15:50:40 -07001311 /*
1312 * Intuos5 has no useful data about its touch interface in its
1313 * HID descriptor. If this is the touch interface (wMaxPacketSize
1314 * of WACOM_PKGLEN_BBTOUCH3), override the table values.
1315 */
Ping Chengb5fd2a32013-11-25 18:44:55 -08001316 if (features->type >= INTUOS5S && features->type <= INTUOSHT) {
Jason Gereckeae584ca2012-04-03 15:50:40 -07001317 if (endpoint->wMaxPacketSize == WACOM_PKGLEN_BBTOUCH3) {
1318 features->device_type = BTN_TOOL_FINGER;
1319 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
1320
Jason Gereckeae584ca2012-04-03 15:50:40 -07001321 features->x_max = 4096;
1322 features->y_max = 4096;
1323 } else {
1324 features->device_type = BTN_TOOL_PEN;
1325 }
1326 }
1327
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07001328 wacom_setup_device_quirks(features);
1329
Ping Cheng401d7d12013-07-28 00:38:54 -07001330 /* set unit to "100th of a mm" for devices not reported by HID */
1331 if (!features->unit) {
1332 features->unit = 0x11;
1333 features->unitExpo = 16 - 3;
1334 }
1335 wacom_calculate_res(features);
1336
Ping Cheng49b764a2010-02-20 00:53:49 -08001337 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
1338
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07001339 if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
Jason Gereckeaea2bf62012-10-21 00:38:03 -07001340 struct usb_device *other_dev;
1341
Ping Cheng49b764a2010-02-20 00:53:49 -08001342 /* Append the device type to the name */
Ping Cheng57bcfce2013-10-15 23:44:00 -07001343 if (features->device_type != BTN_TOOL_FINGER)
1344 strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
1345 else if (features->touch_max)
1346 strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
1347 else
1348 strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
Ping Cheng4492eff2010-03-19 22:18:15 -07001349
Jason Gereckeaea2bf62012-10-21 00:38:03 -07001350 other_dev = wacom_get_sibling(dev, features->oVid, features->oPid);
1351 if (other_dev == NULL || wacom_get_usbdev_data(other_dev) == NULL)
1352 other_dev = dev;
1353 error = wacom_add_shared_data(wacom_wac, other_dev);
Ping Cheng4492eff2010-03-19 22:18:15 -07001354 if (error)
1355 goto fail3;
Ping Cheng49b764a2010-02-20 00:53:49 -08001356 }
1357
Ping Cheng3bea7332006-07-13 18:01:36 -07001358 usb_fill_int_urb(wacom->irq, dev,
1359 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
Ping Chengec67bbe2009-12-15 00:35:24 -08001360 wacom_wac->data, features->pktlen,
Ping Cheng8d32e3a2006-09-26 13:34:47 -07001361 wacom_sys_irq, wacom, endpoint->bInterval);
Ping Cheng3bea7332006-07-13 18:01:36 -07001362 wacom->irq->transfer_dma = wacom->data_dma;
1363 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1364
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001365 error = wacom_initialize_leds(wacom);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001366 if (error)
Ping Cheng4492eff2010-03-19 22:18:15 -07001367 goto fail4;
Ping Cheng3bea7332006-07-13 18:01:36 -07001368
Chris Bagwelld3825d52012-03-25 23:26:11 -07001369 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
1370 error = wacom_register_input(wacom);
1371 if (error)
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001372 goto fail5;
Chris Bagwelld3825d52012-03-25 23:26:11 -07001373 }
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001374
Ping Chengec67bbe2009-12-15 00:35:24 -08001375 /* Note that if query fails it is not a hard failure */
1376 wacom_query_tablet_data(intf, features);
Ping Cheng3bea7332006-07-13 18:01:36 -07001377
1378 usb_set_intfdata(intf, wacom);
Chris Bagwelld3825d52012-03-25 23:26:11 -07001379
1380 if (features->quirks & WACOM_QUIRK_MONITOR) {
Wei Yongjund4879c92013-08-24 16:41:56 -07001381 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
1382 error = -EIO;
Chris Bagwelld3825d52012-03-25 23:26:11 -07001383 goto fail5;
Wei Yongjund4879c92013-08-24 16:41:56 -07001384 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07001385 }
Ping Cheng961794a2013-12-05 12:54:53 -08001386
1387 if (wacom_wac->features.type == INTUOSHT && wacom_wac->features.touch_max) {
1388 if (wacom_wac->features.device_type == BTN_TOOL_FINGER)
1389 wacom_wac->shared->touch_input = wacom_wac->input;
1390 }
1391
Ping Cheng3bea7332006-07-13 18:01:36 -07001392 return 0;
1393
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001394 fail5: wacom_destroy_leds(wacom);
Ping Cheng4492eff2010-03-19 22:18:15 -07001395 fail4: wacom_remove_shared_data(wacom_wac);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001396 fail3: usb_free_urb(wacom->irq);
Daniel Mack997ea582010-04-12 13:17:25 +02001397 fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001398 fail1: kfree(wacom);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001399 return error;
Ping Cheng3bea7332006-07-13 18:01:36 -07001400}
1401
1402static void wacom_disconnect(struct usb_interface *intf)
1403{
Oliver Neukume7224092008-04-15 01:31:57 -04001404 struct wacom *wacom = usb_get_intfdata(intf);
Ping Cheng3bea7332006-07-13 18:01:36 -07001405
1406 usb_set_intfdata(intf, NULL);
Oliver Neukume7224092008-04-15 01:31:57 -04001407
1408 usb_kill_urb(wacom->irq);
Chris Bagwell16bf2882012-03-25 23:26:20 -07001409 cancel_work_sync(&wacom->work);
Chris Bagwelld3825d52012-03-25 23:26:11 -07001410 if (wacom->wacom_wac.input)
1411 input_unregister_device(wacom->wacom_wac.input);
Chris Bagwella1d552c2012-03-25 23:26:30 -07001412 wacom_destroy_battery(wacom);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001413 wacom_destroy_leds(wacom);
Oliver Neukume7224092008-04-15 01:31:57 -04001414 usb_free_urb(wacom->irq);
Daniel Mack997ea582010-04-12 13:17:25 +02001415 usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
Dmitry Torokhov51269fe2010-03-19 22:18:15 -07001416 wacom->wacom_wac.data, wacom->data_dma);
1417 wacom_remove_shared_data(&wacom->wacom_wac);
Oliver Neukume7224092008-04-15 01:31:57 -04001418 kfree(wacom);
1419}
1420
1421static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
1422{
1423 struct wacom *wacom = usb_get_intfdata(intf);
1424
1425 mutex_lock(&wacom->lock);
1426 usb_kill_urb(wacom->irq);
1427 mutex_unlock(&wacom->lock);
1428
1429 return 0;
1430}
1431
1432static int wacom_resume(struct usb_interface *intf)
1433{
1434 struct wacom *wacom = usb_get_intfdata(intf);
Dmitry Torokhov51269fe2010-03-19 22:18:15 -07001435 struct wacom_features *features = &wacom->wacom_wac.features;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001436 int rv = 0;
Oliver Neukume7224092008-04-15 01:31:57 -04001437
1438 mutex_lock(&wacom->lock);
Ping Cheng38101472010-04-13 23:07:52 -07001439
1440 /* switch to wacom mode first */
1441 wacom_query_tablet_data(intf, features);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001442 wacom_led_control(wacom);
Ping Cheng38101472010-04-13 23:07:52 -07001443
Wei Yongjund4879c92013-08-24 16:41:56 -07001444 if ((wacom->open || (features->quirks & WACOM_QUIRK_MONITOR)) &&
1445 usb_submit_urb(wacom->irq, GFP_NOIO) < 0)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001446 rv = -EIO;
Ping Cheng38101472010-04-13 23:07:52 -07001447
Oliver Neukume7224092008-04-15 01:31:57 -04001448 mutex_unlock(&wacom->lock);
1449
1450 return rv;
1451}
1452
1453static int wacom_reset_resume(struct usb_interface *intf)
1454{
1455 return wacom_resume(intf);
Ping Cheng3bea7332006-07-13 18:01:36 -07001456}
1457
1458static struct usb_driver wacom_driver = {
1459 .name = "wacom",
Bastian Blankb036f6f2010-02-10 23:06:23 -08001460 .id_table = wacom_ids,
Ping Cheng3bea7332006-07-13 18:01:36 -07001461 .probe = wacom_probe,
1462 .disconnect = wacom_disconnect,
Oliver Neukume7224092008-04-15 01:31:57 -04001463 .suspend = wacom_suspend,
1464 .resume = wacom_resume,
1465 .reset_resume = wacom_reset_resume,
1466 .supports_autosuspend = 1,
Ping Cheng3bea7332006-07-13 18:01:36 -07001467};
1468
Greg Kroah-Hartman08642e72011-11-18 09:48:31 -08001469module_usb_driver(wacom_driver);