Input: usbtouchscreen - implement basic suspend/resume
[deliverable/linux.git] / drivers / input / touchscreen / usbtouchscreen.c
CommitLineData
1d3e2023
DR
1/******************************************************************************
2 * usbtouchscreen.c
3 * Driver for USB Touchscreens, supporting those devices:
4 * - eGalax Touchkit
5d892665
DR
5 * includes eTurboTouch CT-410/510/700
6 * - 3M/Microtouch EX II series
1d3e2023
DR
7 * - ITM
8 * - PanJit TouchSet
5d892665
DR
9 * - eTurboTouch
10 * - Gunze AHL61
24ced062 11 * - DMC TSC-10/25
df561fcd 12 * - IRTOUCHSYSTEMS/UNITOP
a14a8401 13 * - IdealTEK URTC1000
62aa366d 14 * - General Touch
14e40206 15 * - GoTop Super_Q2/GogoPen/PenPower tablets
f7370699 16 * - JASTEC USB touch controller/DigiTech DTR-02U
2330ed18 17 * - Zytronic capacitive touchscreen
5197424c 18 * - NEXIO/iNexio
1d3e2023 19 *
14e40206 20 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
1d3e2023
DR
21 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
22 *
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License as
25 * published by the Free Software Foundation; either version 2 of the
26 * License, or (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *
37 * Driver is based on touchkitusb.c
38 * - ITM parts are from itmtouch.c
39 * - 3M parts are from mtouchusb.c
40 * - PanJit parts are from an unmerged driver by Lanslott Gish
24ced062
HS
41 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
42 * driver from Marius Vollmer
1d3e2023
DR
43 *
44 *****************************************************************************/
45
46//#define DEBUG
47
1d3e2023
DR
48#include <linux/kernel.h>
49#include <linux/slab.h>
50#include <linux/input.h>
51#include <linux/module.h>
52#include <linux/init.h>
53#include <linux/usb.h>
ae0dadcf 54#include <linux/usb/input.h>
ec42d448 55#include <linux/hid.h>
1d3e2023
DR
56
57
62aa366d 58#define DRIVER_VERSION "v0.6"
1d3e2023
DR
59#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
60#define DRIVER_DESC "USB Touchscreen Driver"
61
62static int swap_xy;
63module_param(swap_xy, bool, 0644);
64MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
65
c9cbf3d3
DS
66static int hwcalib_xy;
67module_param(hwcalib_xy, bool, 0644);
68MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
69
1d3e2023
DR
70/* device specifc data/functions */
71struct usbtouch_usb;
72struct usbtouch_device_info {
73 int min_xc, max_xc;
74 int min_yc, max_yc;
75 int min_press, max_press;
76 int rept_size;
1d3e2023 77
2330ed18
DS
78 /*
79 * Always service the USB devices irq not just when the input device is
80 * open. This is useful when devices have a watchdog which prevents us
81 * from periodically polling the device. Leave this unset unless your
82 * touchscreen device requires it, as it does consume more of the USB
83 * bandwidth.
84 */
85 bool irq_always;
86
7d12e780 87 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
62aa366d
DR
88
89 /*
90 * used to get the packet len. possible return values:
91 * > 0: packet len
92 * = 0: skip one byte
93 * < 0: -return value more bytes needed
94 */
5d892665 95 int (*get_pkt_len) (unsigned char *pkt, int len);
62aa366d 96
c9d8c2b3 97 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
1d3e2023 98 int (*init) (struct usbtouch_usb *usbtouch);
5197424c 99 void (*exit) (struct usbtouch_usb *usbtouch);
1d3e2023
DR
100};
101
1d3e2023
DR
102/* a usbtouch device */
103struct usbtouch_usb {
104 unsigned char *data;
105 dma_addr_t data_dma;
106 unsigned char *buffer;
107 int buf_len;
108 struct urb *irq;
fea4d14b 109 struct usb_interface *interface;
1d3e2023
DR
110 struct input_dev *input;
111 struct usbtouch_device_info *type;
112 char name[128];
113 char phys[64];
5197424c 114 void *priv;
c9d8c2b3
DR
115
116 int x, y;
117 int touch, press;
1d3e2023
DR
118};
119
5d892665 120
1d3e2023
DR
121/* device types */
122enum {
ec42d448 123 DEVTYPE_IGNORE = -1,
1d3e2023
DR
124 DEVTYPE_EGALAX,
125 DEVTYPE_PANJIT,
126 DEVTYPE_3M,
127 DEVTYPE_ITM,
5d892665
DR
128 DEVTYPE_ETURBO,
129 DEVTYPE_GUNZE,
24ced062 130 DEVTYPE_DMC_TSC10,
df561fcd 131 DEVTYPE_IRTOUCH,
a14a8401 132 DEVTYPE_IDEALTEK,
9d5657db 133 DEVTYPE_GENERAL_TOUCH,
14e40206 134 DEVTYPE_GOTOP,
f7370699 135 DEVTYPE_JASTEC,
9e3b2583 136 DEVTYPE_E2I,
2330ed18 137 DEVTYPE_ZYTRONIC,
38771bb4 138 DEVTYPE_TC45USB,
5197424c 139 DEVTYPE_NEXIO,
1d3e2023
DR
140};
141
ec42d448
DR
142#define USB_DEVICE_HID_CLASS(vend, prod) \
143 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
139ebe8d 144 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
ec42d448
DR
145 | USB_DEVICE_ID_MATCH_DEVICE, \
146 .idVendor = (vend), \
147 .idProduct = (prod), \
148 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
149 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
150
9cb3ce52 151static const struct usb_device_id usbtouch_devices[] = {
c6f8d706 152#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
ec42d448
DR
153 /* ignore the HID capable devices, handled by usbhid */
154 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
155 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
156
157 /* normal device IDs */
1d3e2023 158 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
5d892665 159 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
1d3e2023
DR
160 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
161 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
162 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
5d892665
DR
163 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
164 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
1d3e2023
DR
165#endif
166
c6f8d706 167#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
1d3e2023
DR
168 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
169 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
170 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
171 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
172#endif
173
c6f8d706 174#ifdef CONFIG_TOUCHSCREEN_USB_3M
1d3e2023
DR
175 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
176#endif
177
c6f8d706 178#ifdef CONFIG_TOUCHSCREEN_USB_ITM
1d3e2023
DR
179 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
180#endif
181
c6f8d706 182#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
5d892665
DR
183 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
184#endif
185
c6f8d706 186#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
5d892665
DR
187 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
188#endif
189
c6f8d706 190#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
24ced062
HS
191 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
192#endif
193
df561fcd
OZ
194#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
195 {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
196 {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
197#endif
198
a14a8401
OZ
199#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
200 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
201#endif
202
9d5657db
IF
203#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
204 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
205#endif
206
14e40206
JJ
207#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
208 {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP},
209 {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP},
210 {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP},
211#endif
212
f7370699
JP
213#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
214 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
215#endif
216
9e3b2583
FE
217#ifdef CONFIG_TOUCHSCREEN_USB_E2I
218 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
219#endif
2330ed18
DS
220
221#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
222 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
223#endif
224
38771bb4
225#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
226 /* TC5UH */
227 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC45USB},
228 /* TC4UM */
229 {USB_DEVICE(0x0664, 0x0306), .driver_info = DEVTYPE_TC45USB},
dbe1420b
230#endif
231
5197424c
OZ
232#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
233 /* data interface only */
234 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
235 .driver_info = DEVTYPE_NEXIO},
236 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
237 .driver_info = DEVTYPE_NEXIO},
238#endif
239
1d3e2023
DR
240 {}
241};
242
243
9e3b2583
FE
244/*****************************************************************************
245 * e2i Part
246 */
247
248#ifdef CONFIG_TOUCHSCREEN_USB_E2I
249static int e2i_init(struct usbtouch_usb *usbtouch)
250{
251 int ret;
fea4d14b 252 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
9e3b2583 253
fea4d14b 254 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
9e3b2583
FE
255 0x01, 0x02, 0x0000, 0x0081,
256 NULL, 0, USB_CTRL_SET_TIMEOUT);
257
258 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
259 __func__, ret);
260 return ret;
261}
262
263static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
264{
265 int tmp = (pkt[0] << 8) | pkt[1];
266 dev->x = (pkt[2] << 8) | pkt[3];
267 dev->y = (pkt[4] << 8) | pkt[5];
268
269 tmp = tmp - 0xA000;
270 dev->touch = (tmp > 0);
271 dev->press = (tmp > 0 ? tmp : 0);
272
273 return 1;
274}
275#endif
276
277
1d3e2023
DR
278/*****************************************************************************
279 * eGalax part
280 */
281
c6f8d706 282#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
1d3e2023 283
62aa366d
DR
284#ifndef MULTI_PACKET
285#define MULTI_PACKET
286#endif
287
1d3e2023
DR
288#define EGALAX_PKT_TYPE_MASK 0xFE
289#define EGALAX_PKT_TYPE_REPT 0x80
290#define EGALAX_PKT_TYPE_DIAG 0x0A
291
c9d8c2b3 292static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1d3e2023
DR
293{
294 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
295 return 0;
296
c9d8c2b3
DR
297 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
298 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
299 dev->touch = pkt[0] & 0x01;
1d3e2023
DR
300
301 return 1;
1d3e2023
DR
302}
303
5d892665 304static int egalax_get_pkt_len(unsigned char *buf, int len)
1d3e2023
DR
305{
306 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
307 case EGALAX_PKT_TYPE_REPT:
308 return 5;
309
310 case EGALAX_PKT_TYPE_DIAG:
5d892665
DR
311 if (len < 2)
312 return -1;
313
1d3e2023
DR
314 return buf[1] + 2;
315 }
316
317 return 0;
318}
1d3e2023
DR
319#endif
320
321
322/*****************************************************************************
323 * PanJit Part
324 */
c6f8d706 325#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
c9d8c2b3 326static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1d3e2023 327{
c9d8c2b3
DR
328 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
329 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
330 dev->touch = pkt[0] & 0x01;
1d3e2023
DR
331
332 return 1;
333}
334#endif
335
336
337/*****************************************************************************
338 * 3M/Microtouch Part
339 */
c6f8d706 340#ifdef CONFIG_TOUCHSCREEN_USB_3M
1d3e2023
DR
341
342#define MTOUCHUSB_ASYNC_REPORT 1
343#define MTOUCHUSB_RESET 7
344#define MTOUCHUSB_REQ_CTRLLR_ID 10
345
c9d8c2b3 346static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1d3e2023 347{
c9cbf3d3
DS
348 if (hwcalib_xy) {
349 dev->x = (pkt[4] << 8) | pkt[3];
350 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
351 } else {
352 dev->x = (pkt[8] << 8) | pkt[7];
353 dev->y = (pkt[10] << 8) | pkt[9];
354 }
c9d8c2b3 355 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
1d3e2023
DR
356
357 return 1;
358}
359
360static int mtouch_init(struct usbtouch_usb *usbtouch)
361{
5d892665 362 int ret, i;
fea4d14b 363 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
1d3e2023 364
fea4d14b 365 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1d3e2023
DR
366 MTOUCHUSB_RESET,
367 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
368 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
369 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
ea3e6c59 370 __func__, ret);
1d3e2023
DR
371 if (ret < 0)
372 return ret;
5d892665
DR
373 msleep(150);
374
375 for (i = 0; i < 3; i++) {
fea4d14b 376 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
5d892665
DR
377 MTOUCHUSB_ASYNC_REPORT,
378 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
379 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
380 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
ea3e6c59 381 __func__, ret);
5d892665
DR
382 if (ret >= 0)
383 break;
384 if (ret != -EPIPE)
385 return ret;
386 }
1d3e2023 387
c9cbf3d3
DS
388 /* Default min/max xy are the raw values, override if using hw-calib */
389 if (hwcalib_xy) {
390 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
391 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
392 }
393
1d3e2023
DR
394 return 0;
395}
396#endif
397
398
399/*****************************************************************************
400 * ITM Part
401 */
c6f8d706 402#ifdef CONFIG_TOUCHSCREEN_USB_ITM
c9d8c2b3 403static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1d3e2023 404{
c9d8c2b3
DR
405 int touch;
406 /*
407 * ITM devices report invalid x/y data if not touched.
408 * if the screen was touched before but is not touched any more
409 * report touch as 0 with the last valid x/y data once. then stop
410 * reporting data until touched again.
411 */
412 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
413
414 touch = ~pkt[7] & 0x20;
415 if (!touch) {
416 if (dev->touch) {
417 dev->touch = 0;
418 return 1;
419 }
420
421 return 0;
422 }
423
424 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
425 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
426 dev->touch = touch;
1d3e2023 427
c9d8c2b3 428 return 1;
1d3e2023
DR
429}
430#endif
431
432
5d892665
DR
433/*****************************************************************************
434 * eTurboTouch part
435 */
c6f8d706 436#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
62aa366d
DR
437#ifndef MULTI_PACKET
438#define MULTI_PACKET
439#endif
c9d8c2b3 440static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
5d892665
DR
441{
442 unsigned int shift;
443
444 /* packets should start with sync */
445 if (!(pkt[0] & 0x80))
446 return 0;
447
448 shift = (6 - (pkt[0] & 0x03));
c9d8c2b3
DR
449 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
450 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
451 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
5d892665
DR
452
453 return 1;
454}
455
456static int eturbo_get_pkt_len(unsigned char *buf, int len)
457{
458 if (buf[0] & 0x80)
459 return 5;
460 if (buf[0] == 0x01)
461 return 3;
462 return 0;
463}
464#endif
465
466
467/*****************************************************************************
468 * Gunze part
469 */
c6f8d706 470#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
c9d8c2b3 471static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
5d892665
DR
472{
473 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
474 return 0;
475
c9d8c2b3
DR
476 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
477 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
478 dev->touch = pkt[0] & 0x20;
5d892665
DR
479
480 return 1;
481}
482#endif
483
24ced062
HS
484/*****************************************************************************
485 * DMC TSC-10/25 Part
486 *
487 * Documentation about the controller and it's protocol can be found at
488 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
489 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
490 */
c6f8d706 491#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
24ced062
HS
492
493/* supported data rates. currently using 130 */
494#define TSC10_RATE_POINT 0x50
495#define TSC10_RATE_30 0x40
496#define TSC10_RATE_50 0x41
497#define TSC10_RATE_80 0x42
498#define TSC10_RATE_100 0x43
499#define TSC10_RATE_130 0x44
500#define TSC10_RATE_150 0x45
501
502/* commands */
503#define TSC10_CMD_RESET 0x55
504#define TSC10_CMD_RATE 0x05
505#define TSC10_CMD_DATA1 0x01
506
507static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
508{
fea4d14b 509 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
76d057ce
ON
510 int ret = -ENOMEM;
511 unsigned char *buf;
24ced062 512
76d057ce
ON
513 buf = kmalloc(2, GFP_KERNEL);
514 if (!buf)
515 goto err_nobuf;
24ced062
HS
516 /* reset */
517 buf[0] = buf[1] = 0xFF;
518 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
519 TSC10_CMD_RESET,
520 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
521 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
522 if (ret < 0)
76d057ce 523 goto err_out;
2ec6f246 524 if (buf[0] != 0x06) {
76d057ce
ON
525 ret = -ENODEV;
526 goto err_out;
527 }
24ced062
HS
528
529 /* set coordinate output rate */
530 buf[0] = buf[1] = 0xFF;
531 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
532 TSC10_CMD_RATE,
533 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
534 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
535 if (ret < 0)
76d057ce 536 goto err_out;
2ec6f246 537 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
76d057ce
ON
538 ret = -ENODEV;
539 goto err_out;
540 }
24ced062
HS
541
542 /* start sending data */
543 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
544 TSC10_CMD_DATA1,
545 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
546 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
76d057ce
ON
547err_out:
548 kfree(buf);
549err_nobuf:
550 return ret;
24ced062
HS
551}
552
553
c9d8c2b3 554static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
24ced062 555{
c9d8c2b3
DR
556 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
557 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
558 dev->touch = pkt[0] & 0x01;
24ced062
HS
559
560 return 1;
561}
562#endif
563
564
df561fcd
OZ
565/*****************************************************************************
566 * IRTOUCH Part
567 */
568#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
569static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
570{
571 dev->x = (pkt[3] << 8) | pkt[2];
572 dev->y = (pkt[5] << 8) | pkt[4];
573 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
574
575 return 1;
576}
577#endif
578
dbe1420b 579/*****************************************************************************
38771bb4 580 * ET&T TC5UH/TC4UM part
dbe1420b 581 */
38771bb4
582#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
583static int tc45usb_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
dbe1420b
584{
585 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
586 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
587 dev->touch = pkt[0] & 0x01;
588
589 return 1;
590}
591#endif
df561fcd 592
a14a8401
OZ
593/*****************************************************************************
594 * IdealTEK URTC1000 Part
595 */
596#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
62aa366d
DR
597#ifndef MULTI_PACKET
598#define MULTI_PACKET
599#endif
a14a8401
OZ
600static int idealtek_get_pkt_len(unsigned char *buf, int len)
601{
602 if (buf[0] & 0x80)
603 return 5;
604 if (buf[0] == 0x01)
605 return len;
606 return 0;
607}
608
609static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
610{
611 switch (pkt[0] & 0x98) {
612 case 0x88:
613 /* touch data in IdealTEK mode */
614 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
615 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
616 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
617 return 1;
618
619 case 0x98:
620 /* touch data in MT emulation mode */
621 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
622 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
623 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
624 return 1;
625
626 default:
627 return 0;
628 }
629}
630#endif
631
9d5657db
IF
632/*****************************************************************************
633 * General Touch Part
634 */
635#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
636static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
637{
eb083ba2
RY
638 dev->x = (pkt[2] << 8) | pkt[1];
639 dev->y = (pkt[4] << 8) | pkt[3];
9d5657db
IF
640 dev->press = pkt[5] & 0xff;
641 dev->touch = pkt[0] & 0x01;
642
643 return 1;
644}
645#endif
a14a8401 646
14e40206
JJ
647/*****************************************************************************
648 * GoTop Part
649 */
650#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
651static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
652{
653 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
654 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
655 dev->touch = pkt[0] & 0x01;
f7370699
JP
656
657 return 1;
658}
659#endif
660
661/*****************************************************************************
662 * JASTEC Part
663 */
664#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
665static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
666{
667 dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
668 dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
669 dev->touch = (pkt[0] & 0x40) >> 6;
670
14e40206
JJ
671 return 1;
672}
673#endif
674
2330ed18
DS
675/*****************************************************************************
676 * Zytronic Part
677 */
678#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
679static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
680{
681 switch (pkt[0]) {
682 case 0x3A: /* command response */
683 dbg("%s: Command response %d", __func__, pkt[1]);
684 break;
685
686 case 0xC0: /* down */
687 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
688 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
689 dev->touch = 1;
690 dbg("%s: down %d,%d", __func__, dev->x, dev->y);
691 return 1;
692
693 case 0x80: /* up */
694 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
695 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
696 dev->touch = 0;
697 dbg("%s: up %d,%d", __func__, dev->x, dev->y);
698 return 1;
699
700 default:
701 dbg("%s: Unknown return %d", __func__, pkt[0]);
702 break;
703 }
704
705 return 0;
706}
707#endif
14e40206 708
5197424c
OZ
709/*****************************************************************************
710 * NEXIO Part
711 */
712#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
713
714#define NEXIO_TIMEOUT 5000
715#define NEXIO_BUFSIZE 1024
716#define NEXIO_THRESHOLD 50
717
718struct nexio_priv {
719 struct urb *ack;
720 unsigned char *ack_buf;
721};
722
723struct nexio_touch_packet {
724 u8 flags; /* 0xe1 = touch, 0xe1 = release */
725 __be16 data_len; /* total bytes of touch data */
726 __be16 x_len; /* bytes for X axis */
727 __be16 y_len; /* bytes for Y axis */
728 u8 data[];
729} __attribute__ ((packed));
730
731static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 };
732static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f };
733
734static void nexio_ack_complete(struct urb *urb)
735{
736}
737
738static int nexio_init(struct usbtouch_usb *usbtouch)
739{
740 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
741 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
742 struct nexio_priv *priv;
743 int ret = -ENOMEM;
744 int actual_len, i;
745 unsigned char *buf;
746 char *firmware_ver = NULL, *device_name = NULL;
747 int input_ep = 0, output_ep = 0;
748
749 /* find first input and output endpoint */
750 for (i = 0; i < interface->desc.bNumEndpoints; i++) {
751 if (!input_ep &&
752 usb_endpoint_dir_in(&interface->endpoint[i].desc))
753 input_ep = interface->endpoint[i].desc.bEndpointAddress;
754 if (!output_ep &&
755 usb_endpoint_dir_out(&interface->endpoint[i].desc))
756 output_ep = interface->endpoint[i].desc.bEndpointAddress;
757 }
758 if (!input_ep || !output_ep)
759 return -ENXIO;
760
761 buf = kmalloc(NEXIO_BUFSIZE, GFP_KERNEL);
762 if (!buf)
763 goto out_buf;
764
765 /* two empty reads */
766 for (i = 0; i < 2; i++) {
767 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
768 buf, NEXIO_BUFSIZE, &actual_len,
769 NEXIO_TIMEOUT);
770 if (ret < 0)
771 goto out_buf;
772 }
773
774 /* send init command */
775 memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt));
776 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep),
777 buf, sizeof(nexio_init_pkt), &actual_len,
778 NEXIO_TIMEOUT);
779 if (ret < 0)
780 goto out_buf;
781
782 /* read replies */
783 for (i = 0; i < 3; i++) {
784 memset(buf, 0, NEXIO_BUFSIZE);
785 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
786 buf, NEXIO_BUFSIZE, &actual_len,
787 NEXIO_TIMEOUT);
788 if (ret < 0 || actual_len < 1 || buf[1] != actual_len)
789 continue;
790 switch (buf[0]) {
791 case 0x83: /* firmware version */
792 if (!firmware_ver)
793 firmware_ver = kstrdup(&buf[2], GFP_KERNEL);
794 break;
795 case 0x84: /* device name */
796 if (!device_name)
797 device_name = kstrdup(&buf[2], GFP_KERNEL);
798 break;
799 }
800 }
801
802 printk(KERN_INFO "Nexio device: %s, firmware version: %s\n",
803 device_name, firmware_ver);
804
805 kfree(firmware_ver);
806 kfree(device_name);
807
808 /* prepare ACK URB */
809 ret = -ENOMEM;
810
811 usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
812 if (!usbtouch->priv)
813 goto out_buf;
814
815 priv = usbtouch->priv;
816
641d446f
JL
817 priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt),
818 GFP_KERNEL);
5197424c
OZ
819 if (!priv->ack_buf)
820 goto err_priv;
821
5197424c
OZ
822 priv->ack = usb_alloc_urb(0, GFP_KERNEL);
823 if (!priv->ack) {
824 dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
825 goto err_ack_buf;
826 }
827
828 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep),
829 priv->ack_buf, sizeof(nexio_ack_pkt),
830 nexio_ack_complete, usbtouch);
831 ret = 0;
832 goto out_buf;
833
834err_ack_buf:
835 kfree(priv->ack_buf);
836err_priv:
837 kfree(priv);
838out_buf:
839 kfree(buf);
840 return ret;
841}
842
843static void nexio_exit(struct usbtouch_usb *usbtouch)
844{
845 struct nexio_priv *priv = usbtouch->priv;
846
847 usb_kill_urb(priv->ack);
848 usb_free_urb(priv->ack);
849 kfree(priv->ack_buf);
850 kfree(priv);
851}
852
853static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
854{
5197424c
OZ
855 struct nexio_touch_packet *packet = (void *) pkt;
856 struct nexio_priv *priv = usbtouch->priv;
4aa5bbec
DT
857 unsigned int data_len = be16_to_cpu(packet->data_len);
858 unsigned int x_len = be16_to_cpu(packet->x_len);
859 unsigned int y_len = be16_to_cpu(packet->y_len);
860 int x, y, begin_x, begin_y, end_x, end_y, w, h, ret;
5197424c
OZ
861
862 /* got touch data? */
863 if ((pkt[0] & 0xe0) != 0xe0)
864 return 0;
865
4aa5bbec
DT
866 if (data_len > 0xff)
867 data_len -= 0x100;
868 if (x_len > 0xff)
869 x_len -= 0x80;
388bbcad 870
5197424c
OZ
871 /* send ACK */
872 ret = usb_submit_urb(priv->ack, GFP_ATOMIC);
873
874 if (!usbtouch->type->max_xc) {
4aa5bbec
DT
875 usbtouch->type->max_xc = 2 * x_len;
876 input_set_abs_params(usbtouch->input, ABS_X,
877 0, usbtouch->type->max_xc, 0, 0);
878 usbtouch->type->max_yc = 2 * y_len;
879 input_set_abs_params(usbtouch->input, ABS_Y,
880 0, usbtouch->type->max_yc, 0, 0);
5197424c
OZ
881 }
882 /*
883 * The device reports state of IR sensors on X and Y axes.
884 * Each byte represents "darkness" percentage (0-100) of one element.
885 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
886 * This also means that there's a limited multi-touch capability but
887 * it's disabled (and untested) here as there's no X driver for that.
888 */
889 begin_x = end_x = begin_y = end_y = -1;
4aa5bbec 890 for (x = 0; x < x_len; x++) {
5197424c
OZ
891 if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) {
892 begin_x = x;
893 continue;
894 }
895 if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) {
896 end_x = x - 1;
4aa5bbec 897 for (y = x_len; y < data_len; y++) {
5197424c 898 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
4aa5bbec 899 begin_y = y - x_len;
5197424c
OZ
900 continue;
901 }
902 if (end_y == -1 &&
903 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
4aa5bbec 904 end_y = y - 1 - x_len;
5197424c
OZ
905 w = end_x - begin_x;
906 h = end_y - begin_y;
907#if 0
908 /* multi-touch */
909 input_report_abs(usbtouch->input,
910 ABS_MT_TOUCH_MAJOR, max(w,h));
911 input_report_abs(usbtouch->input,
912 ABS_MT_TOUCH_MINOR, min(x,h));
913 input_report_abs(usbtouch->input,
914 ABS_MT_POSITION_X, 2*begin_x+w);
915 input_report_abs(usbtouch->input,
916 ABS_MT_POSITION_Y, 2*begin_y+h);
917 input_report_abs(usbtouch->input,
918 ABS_MT_ORIENTATION, w > h);
919 input_mt_sync(usbtouch->input);
920#endif
921 /* single touch */
922 usbtouch->x = 2 * begin_x + w;
923 usbtouch->y = 2 * begin_y + h;
924 usbtouch->touch = packet->flags & 0x01;
925 begin_y = end_y = -1;
926 return 1;
927 }
928 }
929 begin_x = end_x = -1;
930 }
931
932 }
933 return 0;
934}
935#endif
936
937
1d3e2023
DR
938/*****************************************************************************
939 * the different device descriptors
940 */
62aa366d
DR
941#ifdef MULTI_PACKET
942static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
943 unsigned char *pkt, int len);
944#endif
945
1d3e2023 946static struct usbtouch_device_info usbtouch_dev_info[] = {
c6f8d706 947#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
1d3e2023
DR
948 [DEVTYPE_EGALAX] = {
949 .min_xc = 0x0,
950 .max_xc = 0x07ff,
951 .min_yc = 0x0,
952 .max_yc = 0x07ff,
953 .rept_size = 16,
5d892665
DR
954 .process_pkt = usbtouch_process_multi,
955 .get_pkt_len = egalax_get_pkt_len,
1d3e2023
DR
956 .read_data = egalax_read_data,
957 },
958#endif
959
c6f8d706 960#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
1d3e2023
DR
961 [DEVTYPE_PANJIT] = {
962 .min_xc = 0x0,
963 .max_xc = 0x0fff,
964 .min_yc = 0x0,
965 .max_yc = 0x0fff,
966 .rept_size = 8,
967 .read_data = panjit_read_data,
968 },
969#endif
970
c6f8d706 971#ifdef CONFIG_TOUCHSCREEN_USB_3M
1d3e2023
DR
972 [DEVTYPE_3M] = {
973 .min_xc = 0x0,
974 .max_xc = 0x4000,
975 .min_yc = 0x0,
976 .max_yc = 0x4000,
977 .rept_size = 11,
978 .read_data = mtouch_read_data,
979 .init = mtouch_init,
980 },
981#endif
982
c6f8d706 983#ifdef CONFIG_TOUCHSCREEN_USB_ITM
1d3e2023
DR
984 [DEVTYPE_ITM] = {
985 .min_xc = 0x0,
986 .max_xc = 0x0fff,
987 .min_yc = 0x0,
988 .max_yc = 0x0fff,
989 .max_press = 0xff,
990 .rept_size = 8,
991 .read_data = itm_read_data,
992 },
993#endif
5d892665 994
c6f8d706 995#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
5d892665
DR
996 [DEVTYPE_ETURBO] = {
997 .min_xc = 0x0,
998 .max_xc = 0x07ff,
999 .min_yc = 0x0,
1000 .max_yc = 0x07ff,
1001 .rept_size = 8,
5d892665
DR
1002 .process_pkt = usbtouch_process_multi,
1003 .get_pkt_len = eturbo_get_pkt_len,
1004 .read_data = eturbo_read_data,
1005 },
1006#endif
1007
c6f8d706 1008#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
5d892665
DR
1009 [DEVTYPE_GUNZE] = {
1010 .min_xc = 0x0,
1011 .max_xc = 0x0fff,
1012 .min_yc = 0x0,
1013 .max_yc = 0x0fff,
1014 .rept_size = 4,
1015 .read_data = gunze_read_data,
1016 },
1017#endif
24ced062 1018
c6f8d706 1019#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
24ced062
HS
1020 [DEVTYPE_DMC_TSC10] = {
1021 .min_xc = 0x0,
1022 .max_xc = 0x03ff,
1023 .min_yc = 0x0,
1024 .max_yc = 0x03ff,
1025 .rept_size = 5,
1026 .init = dmc_tsc10_init,
1027 .read_data = dmc_tsc10_read_data,
1028 },
1029#endif
df561fcd
OZ
1030
1031#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
1032 [DEVTYPE_IRTOUCH] = {
1033 .min_xc = 0x0,
1034 .max_xc = 0x0fff,
1035 .min_yc = 0x0,
1036 .max_yc = 0x0fff,
1037 .rept_size = 8,
1038 .read_data = irtouch_read_data,
1039 },
1040#endif
a14a8401
OZ
1041
1042#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
1043 [DEVTYPE_IDEALTEK] = {
1044 .min_xc = 0x0,
1045 .max_xc = 0x0fff,
1046 .min_yc = 0x0,
1047 .max_yc = 0x0fff,
1048 .rept_size = 8,
a14a8401
OZ
1049 .process_pkt = usbtouch_process_multi,
1050 .get_pkt_len = idealtek_get_pkt_len,
1051 .read_data = idealtek_read_data,
1052 },
1053#endif
9d5657db
IF
1054
1055#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1056 [DEVTYPE_GENERAL_TOUCH] = {
1057 .min_xc = 0x0,
eb083ba2 1058 .max_xc = 0x7fff,
9d5657db 1059 .min_yc = 0x0,
eb083ba2 1060 .max_yc = 0x7fff,
9d5657db
IF
1061 .rept_size = 7,
1062 .read_data = general_touch_read_data,
14e40206 1063 },
9d5657db
IF
1064#endif
1065
14e40206
JJ
1066#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
1067 [DEVTYPE_GOTOP] = {
1068 .min_xc = 0x0,
1069 .max_xc = 0x03ff,
1070 .min_yc = 0x0,
1071 .max_yc = 0x03ff,
1072 .rept_size = 4,
1073 .read_data = gotop_read_data,
1074 },
1075#endif
f7370699
JP
1076
1077#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
1078 [DEVTYPE_JASTEC] = {
1079 .min_xc = 0x0,
1080 .max_xc = 0x0fff,
1081 .min_yc = 0x0,
1082 .max_yc = 0x0fff,
1083 .rept_size = 4,
1084 .read_data = jastec_read_data,
1085 },
1086#endif
9e3b2583
FE
1087
1088#ifdef CONFIG_TOUCHSCREEN_USB_E2I
1089 [DEVTYPE_E2I] = {
1090 .min_xc = 0x0,
1091 .max_xc = 0x7fff,
1092 .min_yc = 0x0,
1093 .max_yc = 0x7fff,
1094 .rept_size = 6,
1095 .init = e2i_init,
1096 .read_data = e2i_read_data,
1097 },
1098#endif
2330ed18
DS
1099
1100#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1101 [DEVTYPE_ZYTRONIC] = {
1102 .min_xc = 0x0,
1103 .max_xc = 0x03ff,
1104 .min_yc = 0x0,
1105 .max_yc = 0x03ff,
1106 .rept_size = 5,
1107 .read_data = zytronic_read_data,
1108 .irq_always = true,
1109 },
1110#endif
dbe1420b 1111
38771bb4
1112#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1113 [DEVTYPE_TC45USB] = {
dbe1420b
1114 .min_xc = 0x0,
1115 .max_xc = 0x0fff,
1116 .min_yc = 0x0,
1117 .max_yc = 0x0fff,
1118 .rept_size = 5,
38771bb4 1119 .read_data = tc45usb_read_data,
dbe1420b
1120 },
1121#endif
5197424c
OZ
1122
1123#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1124 [DEVTYPE_NEXIO] = {
388bbcad 1125 .rept_size = 1024,
5197424c
OZ
1126 .irq_always = true,
1127 .read_data = nexio_read_data,
1128 .init = nexio_init,
1129 .exit = nexio_exit,
1130 },
1131#endif
1d3e2023
DR
1132};
1133
1134
1135/*****************************************************************************
1136 * Generic Part
1137 */
1138static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
7d12e780 1139 unsigned char *pkt, int len)
1d3e2023 1140{
1d3e2023
DR
1141 struct usbtouch_device_info *type = usbtouch->type;
1142
c9d8c2b3 1143 if (!type->read_data(usbtouch, pkt))
1d3e2023
DR
1144 return;
1145
c9d8c2b3 1146 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
1d3e2023
DR
1147
1148 if (swap_xy) {
c9d8c2b3
DR
1149 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
1150 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
1d3e2023 1151 } else {
c9d8c2b3
DR
1152 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
1153 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
1d3e2023
DR
1154 }
1155 if (type->max_press)
c9d8c2b3 1156 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
1d3e2023
DR
1157 input_sync(usbtouch->input);
1158}
1159
1160
5d892665
DR
1161#ifdef MULTI_PACKET
1162static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
5d892665
DR
1163 unsigned char *pkt, int len)
1164{
1165 unsigned char *buffer;
1166 int pkt_len, pos, buf_len, tmp;
1167
1168 /* process buffer */
1169 if (unlikely(usbtouch->buf_len)) {
1170 /* try to get size */
1171 pkt_len = usbtouch->type->get_pkt_len(
1172 usbtouch->buffer, usbtouch->buf_len);
1173
1174 /* drop? */
1175 if (unlikely(!pkt_len))
1176 goto out_flush_buf;
1177
1178 /* need to append -pkt_len bytes before able to get size */
1179 if (unlikely(pkt_len < 0)) {
1180 int append = -pkt_len;
1181 if (unlikely(append > len))
1182 append = len;
1183 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
1184 goto out_flush_buf;
1185 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
1186 usbtouch->buf_len += append;
1187
1188 pkt_len = usbtouch->type->get_pkt_len(
1189 usbtouch->buffer, usbtouch->buf_len);
1190 if (pkt_len < 0)
1191 return;
1192 }
1193
1194 /* append */
1195 tmp = pkt_len - usbtouch->buf_len;
1196 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
1197 goto out_flush_buf;
1198 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
7d12e780 1199 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
5d892665
DR
1200
1201 buffer = pkt + tmp;
1202 buf_len = len - tmp;
1203 } else {
1204 buffer = pkt;
1205 buf_len = len;
1206 }
1207
1208 /* loop over the received packet, process */
1209 pos = 0;
1210 while (pos < buf_len) {
1211 /* get packet len */
62aa366d
DR
1212 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
1213 buf_len - pos);
5d892665 1214
62aa366d
DR
1215 /* unknown packet: skip one byte */
1216 if (unlikely(!pkt_len)) {
1217 pos++;
1218 continue;
1219 }
5d892665
DR
1220
1221 /* full packet: process */
1222 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
7d12e780 1223 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
5d892665
DR
1224 } else {
1225 /* incomplete packet: save in buffer */
1226 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
1227 usbtouch->buf_len = buf_len - pos;
1228 return;
1229 }
1230 pos += pkt_len;
1231 }
1232
1233out_flush_buf:
1234 usbtouch->buf_len = 0;
1235 return;
1236}
1237#endif
1238
1239
7d12e780 1240static void usbtouch_irq(struct urb *urb)
1d3e2023
DR
1241{
1242 struct usbtouch_usb *usbtouch = urb->context;
1243 int retval;
1244
1245 switch (urb->status) {
1246 case 0:
1247 /* success */
1248 break;
38e2bfc9 1249 case -ETIME:
1d3e2023
DR
1250 /* this urb is timing out */
1251 dbg("%s - urb timed out - was the device unplugged?",
ea3e6c59 1252 __func__);
1d3e2023
DR
1253 return;
1254 case -ECONNRESET:
1255 case -ENOENT:
1256 case -ESHUTDOWN:
5197424c 1257 case -EPIPE:
1d3e2023
DR
1258 /* this urb is terminated, clean up */
1259 dbg("%s - urb shutting down with status: %d",
ea3e6c59 1260 __func__, urb->status);
1d3e2023
DR
1261 return;
1262 default:
1263 dbg("%s - nonzero urb status received: %d",
ea3e6c59 1264 __func__, urb->status);
1d3e2023
DR
1265 goto exit;
1266 }
1267
7d12e780 1268 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
1d3e2023
DR
1269
1270exit:
1271 retval = usb_submit_urb(urb, GFP_ATOMIC);
1272 if (retval)
1273 err("%s - usb_submit_urb failed with result: %d",
ea3e6c59 1274 __func__, retval);
1d3e2023
DR
1275}
1276
1277static int usbtouch_open(struct input_dev *input)
1278{
7791bdae 1279 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1d3e2023 1280
fea4d14b 1281 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
1d3e2023 1282
2330ed18
DS
1283 if (!usbtouch->type->irq_always) {
1284 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
1285 return -EIO;
1286 }
1d3e2023
DR
1287
1288 return 0;
1289}
1290
1291static void usbtouch_close(struct input_dev *input)
1292{
7791bdae 1293 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1d3e2023 1294
2330ed18
DS
1295 if (!usbtouch->type->irq_always)
1296 usb_kill_urb(usbtouch->irq);
1d3e2023
DR
1297}
1298
ed4299e1
ON
1299static int usbtouch_suspend
1300(struct usb_interface *intf, pm_message_t message)
1301{
1302 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1303
1304 usb_kill_urb(usbtouch->irq);
1305
1306 return 0;
1307}
1308
1309static int usbtouch_resume(struct usb_interface *intf)
1310{
1311 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1312 struct input_dev *input = usbtouch->input;
1313 int result = 0;
1314
1315 mutex_lock(&input->mutex);
1316 if (input->users || usbtouch->type->irq_always)
1317 result = usb_submit_urb(usbtouch->irq, GFP_NOIO);
1318 mutex_unlock(&input->mutex);
1319
1320 return result;
1321}
1d3e2023
DR
1322
1323static void usbtouch_free_buffers(struct usb_device *udev,
1324 struct usbtouch_usb *usbtouch)
1325{
997ea58e
DM
1326 usb_free_coherent(udev, usbtouch->type->rept_size,
1327 usbtouch->data, usbtouch->data_dma);
1d3e2023
DR
1328 kfree(usbtouch->buffer);
1329}
1330
f4a5e359
OZ
1331static struct usb_endpoint_descriptor *
1332usbtouch_get_input_endpoint(struct usb_host_interface *interface)
1333{
1334 int i;
1335
1336 for (i = 0; i < interface->desc.bNumEndpoints; i++)
1337 if (usb_endpoint_dir_in(&interface->endpoint[i].desc))
1338 return &interface->endpoint[i].desc;
1339
1340 return NULL;
1341}
1d3e2023
DR
1342
1343static int usbtouch_probe(struct usb_interface *intf,
1344 const struct usb_device_id *id)
1345{
1346 struct usbtouch_usb *usbtouch;
1347 struct input_dev *input_dev;
1d3e2023
DR
1348 struct usb_endpoint_descriptor *endpoint;
1349 struct usb_device *udev = interface_to_usbdev(intf);
1350 struct usbtouch_device_info *type;
5d892665 1351 int err = -ENOMEM;
ec42d448
DR
1352
1353 /* some devices are ignored */
1354 if (id->driver_info == DEVTYPE_IGNORE)
1355 return -ENODEV;
1d3e2023 1356
f4a5e359
OZ
1357 endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
1358 if (!endpoint)
1359 return -ENXIO;
1d3e2023
DR
1360
1361 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
1362 input_dev = input_allocate_device();
1363 if (!usbtouch || !input_dev)
1364 goto out_free;
1365
1366 type = &usbtouch_dev_info[id->driver_info];
1367 usbtouch->type = type;
1368 if (!type->process_pkt)
1369 type->process_pkt = usbtouch_process_pkt;
1370
997ea58e
DM
1371 usbtouch->data = usb_alloc_coherent(udev, type->rept_size,
1372 GFP_KERNEL, &usbtouch->data_dma);
1d3e2023
DR
1373 if (!usbtouch->data)
1374 goto out_free;
1375
62aa366d 1376 if (type->get_pkt_len) {
1d3e2023
DR
1377 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
1378 if (!usbtouch->buffer)
1379 goto out_free_buffers;
1380 }
1381
1382 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
1383 if (!usbtouch->irq) {
ea3e6c59 1384 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
1d3e2023
DR
1385 goto out_free_buffers;
1386 }
1387
fea4d14b 1388 usbtouch->interface = intf;
1d3e2023
DR
1389 usbtouch->input = input_dev;
1390
1391 if (udev->manufacturer)
1392 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
1393
1394 if (udev->product) {
1395 if (udev->manufacturer)
1396 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
1397 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
1398 }
1399
1400 if (!strlen(usbtouch->name))
1401 snprintf(usbtouch->name, sizeof(usbtouch->name),
1402 "USB Touchscreen %04x:%04x",
1403 le16_to_cpu(udev->descriptor.idVendor),
1404 le16_to_cpu(udev->descriptor.idProduct));
1405
1406 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
7b6dff98 1407 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
1d3e2023
DR
1408
1409 input_dev->name = usbtouch->name;
1410 input_dev->phys = usbtouch->phys;
1411 usb_to_input_id(udev, &input_dev->id);
c0f82d57 1412 input_dev->dev.parent = &intf->dev;
7791bdae
DT
1413
1414 input_set_drvdata(input_dev, usbtouch);
1415
1d3e2023
DR
1416 input_dev->open = usbtouch_open;
1417 input_dev->close = usbtouch_close;
1418
7b19ada2
JS
1419 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1420 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1d3e2023
DR
1421 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
1422 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
1423 if (type->max_press)
1424 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1425 type->max_press, 0, 0);
1426
5197424c
OZ
1427 if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT)
1428 usb_fill_int_urb(usbtouch->irq, udev,
fea4d14b 1429 usb_rcvintpipe(udev, endpoint->bEndpointAddress),
1d3e2023
DR
1430 usbtouch->data, type->rept_size,
1431 usbtouch_irq, usbtouch, endpoint->bInterval);
5197424c
OZ
1432 else
1433 usb_fill_bulk_urb(usbtouch->irq, udev,
1434 usb_rcvbulkpipe(udev, endpoint->bEndpointAddress),
1435 usbtouch->data, type->rept_size,
1436 usbtouch_irq, usbtouch);
1d3e2023 1437
fea4d14b 1438 usbtouch->irq->dev = udev;
1d3e2023
DR
1439 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1440 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1441
1442 /* device specific init */
1443 if (type->init) {
1444 err = type->init(usbtouch);
1445 if (err) {
ea3e6c59 1446 dbg("%s - type->init() failed, err: %d", __func__, err);
1e87a430 1447 goto out_free_urb;
1d3e2023
DR
1448 }
1449 }
1450
1451 err = input_register_device(usbtouch->input);
1452 if (err) {
ea3e6c59 1453 dbg("%s - input_register_device failed, err: %d", __func__, err);
5197424c 1454 goto out_do_exit;
1d3e2023
DR
1455 }
1456
1457 usb_set_intfdata(intf, usbtouch);
1458
1e87a430
OZ
1459 if (usbtouch->type->irq_always) {
1460 err = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1461 if (err) {
1462 err("%s - usb_submit_urb failed with result: %d",
1463 __func__, err);
1464 goto out_unregister_input;
1465 }
1466 }
2330ed18 1467
1d3e2023
DR
1468 return 0;
1469
1e87a430
OZ
1470out_unregister_input:
1471 input_unregister_device(input_dev);
1472 input_dev = NULL;
5197424c
OZ
1473out_do_exit:
1474 if (type->exit)
1475 type->exit(usbtouch);
1e87a430
OZ
1476out_free_urb:
1477 usb_free_urb(usbtouch->irq);
1d3e2023
DR
1478out_free_buffers:
1479 usbtouch_free_buffers(udev, usbtouch);
1480out_free:
1481 input_free_device(input_dev);
1482 kfree(usbtouch);
5d892665 1483 return err;
1d3e2023
DR
1484}
1485
1486static void usbtouch_disconnect(struct usb_interface *intf)
1487{
1488 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1489
ea3e6c59 1490 dbg("%s - called", __func__);
1d3e2023
DR
1491
1492 if (!usbtouch)
1493 return;
1494
ea3e6c59 1495 dbg("%s - usbtouch is initialized, cleaning up", __func__);
1d3e2023 1496 usb_set_intfdata(intf, NULL);
722232bc 1497 /* this will stop IO via close */
1d3e2023
DR
1498 input_unregister_device(usbtouch->input);
1499 usb_free_urb(usbtouch->irq);
5197424c
OZ
1500 if (usbtouch->type->exit)
1501 usbtouch->type->exit(usbtouch);
1d3e2023
DR
1502 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1503 kfree(usbtouch);
1504}
1505
1506MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1507
1508static struct usb_driver usbtouch_driver = {
1509 .name = "usbtouchscreen",
1510 .probe = usbtouch_probe,
1511 .disconnect = usbtouch_disconnect,
ed4299e1
ON
1512 .suspend = usbtouch_suspend,
1513 .resume = usbtouch_resume,
1d3e2023
DR
1514 .id_table = usbtouch_devices,
1515};
1516
1517static int __init usbtouch_init(void)
1518{
1519 return usb_register(&usbtouch_driver);
1520}
1521
1522static void __exit usbtouch_cleanup(void)
1523{
1524 usb_deregister(&usbtouch_driver);
1525}
1526
1527module_init(usbtouch_init);
1528module_exit(usbtouch_cleanup);
1529
1530MODULE_AUTHOR(DRIVER_AUTHOR);
1531MODULE_DESCRIPTION(DRIVER_DESC);
1532MODULE_LICENSE("GPL");
1533
1534MODULE_ALIAS("touchkitusb");
1535MODULE_ALIAS("itmtouch");
1536MODULE_ALIAS("mtouchusb");
This page took 0.380708 seconds and 5 git commands to generate.