[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / input / touchscreen / usbtouchscreen.c
blob68ece5801a58c63d5b0f9b183af8948582756210
1 /******************************************************************************
2 * usbtouchscreen.c
3 * Driver for USB Touchscreens, supporting those devices:
4 * - eGalax Touchkit
5 * includes eTurboTouch CT-410/510/700
6 * - 3M/Microtouch EX II series
7 * - ITM
8 * - PanJit TouchSet
9 * - eTurboTouch
10 * - Gunze AHL61
11 * - DMC TSC-10/25
12 * - IRTOUCHSYSTEMS/UNITOP
13 * - IdealTEK URTC1000
14 * - General Touch
15 * - GoTop Super_Q2/GogoPen/PenPower tablets
16 * - JASTEC USB touch controller/DigiTech DTR-02U
18 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
19 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License as
23 * published by the Free Software Foundation; either version 2 of the
24 * License, or (at your option) any later version.
26 * This program is distributed in the hope that it will be useful, but
27 * WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 * Driver is based on touchkitusb.c
36 * - ITM parts are from itmtouch.c
37 * - 3M parts are from mtouchusb.c
38 * - PanJit parts are from an unmerged driver by Lanslott Gish
39 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
40 * driver from Marius Vollmer
42 *****************************************************************************/
44 //#define DEBUG
46 #include <linux/kernel.h>
47 #include <linux/slab.h>
48 #include <linux/input.h>
49 #include <linux/module.h>
50 #include <linux/init.h>
51 #include <linux/usb.h>
52 #include <linux/usb/input.h>
53 #include <linux/hid.h>
56 #define DRIVER_VERSION "v0.6"
57 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
58 #define DRIVER_DESC "USB Touchscreen Driver"
60 static int swap_xy;
61 module_param(swap_xy, bool, 0644);
62 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
64 static int hwcalib_xy;
65 module_param(hwcalib_xy, bool, 0644);
66 MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
68 /* device specifc data/functions */
69 struct usbtouch_usb;
70 struct usbtouch_device_info {
71 int min_xc, max_xc;
72 int min_yc, max_yc;
73 int min_press, max_press;
74 int rept_size;
76 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
79 * used to get the packet len. possible return values:
80 * > 0: packet len
81 * = 0: skip one byte
82 * < 0: -return value more bytes needed
84 int (*get_pkt_len) (unsigned char *pkt, int len);
86 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
87 int (*init) (struct usbtouch_usb *usbtouch);
90 /* a usbtouch device */
91 struct usbtouch_usb {
92 unsigned char *data;
93 dma_addr_t data_dma;
94 unsigned char *buffer;
95 int buf_len;
96 struct urb *irq;
97 struct usb_device *udev;
98 struct input_dev *input;
99 struct usbtouch_device_info *type;
100 char name[128];
101 char phys[64];
103 int x, y;
104 int touch, press;
108 /* device types */
109 enum {
110 DEVTYPE_IGNORE = -1,
111 DEVTYPE_EGALAX,
112 DEVTYPE_PANJIT,
113 DEVTYPE_3M,
114 DEVTYPE_ITM,
115 DEVTYPE_ETURBO,
116 DEVTYPE_GUNZE,
117 DEVTYPE_DMC_TSC10,
118 DEVTYPE_IRTOUCH,
119 DEVTYPE_IDEALTEK,
120 DEVTYPE_GENERAL_TOUCH,
121 DEVTYPE_GOTOP,
122 DEVTYPE_JASTEC,
123 DEVTYPE_E2I,
126 #define USB_DEVICE_HID_CLASS(vend, prod) \
127 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
128 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
129 | USB_DEVICE_ID_MATCH_DEVICE, \
130 .idVendor = (vend), \
131 .idProduct = (prod), \
132 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
133 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
135 static struct usb_device_id usbtouch_devices[] = {
136 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
137 /* ignore the HID capable devices, handled by usbhid */
138 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
139 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
141 /* normal device IDs */
142 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
143 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
144 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
145 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
146 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
147 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
148 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
149 #endif
151 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
152 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
153 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
154 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
155 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
156 #endif
158 #ifdef CONFIG_TOUCHSCREEN_USB_3M
159 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
160 #endif
162 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
163 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
164 #endif
166 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
167 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
168 #endif
170 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
171 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
172 #endif
174 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
175 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
176 #endif
178 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
179 {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
180 {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
181 #endif
183 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
184 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
185 #endif
187 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
188 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
189 #endif
191 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
192 {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP},
193 {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP},
194 {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP},
195 #endif
197 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
198 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
199 #endif
201 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
202 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
203 #endif
208 /*****************************************************************************
209 * e2i Part
212 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
213 static int e2i_init(struct usbtouch_usb *usbtouch)
215 int ret;
217 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
218 0x01, 0x02, 0x0000, 0x0081,
219 NULL, 0, USB_CTRL_SET_TIMEOUT);
221 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
222 __func__, ret);
223 return ret;
226 static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
228 int tmp = (pkt[0] << 8) | pkt[1];
229 dev->x = (pkt[2] << 8) | pkt[3];
230 dev->y = (pkt[4] << 8) | pkt[5];
232 tmp = tmp - 0xA000;
233 dev->touch = (tmp > 0);
234 dev->press = (tmp > 0 ? tmp : 0);
236 return 1;
238 #endif
241 /*****************************************************************************
242 * eGalax part
245 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
247 #ifndef MULTI_PACKET
248 #define MULTI_PACKET
249 #endif
251 #define EGALAX_PKT_TYPE_MASK 0xFE
252 #define EGALAX_PKT_TYPE_REPT 0x80
253 #define EGALAX_PKT_TYPE_DIAG 0x0A
255 static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
257 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
258 return 0;
260 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
261 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
262 dev->touch = pkt[0] & 0x01;
264 return 1;
267 static int egalax_get_pkt_len(unsigned char *buf, int len)
269 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
270 case EGALAX_PKT_TYPE_REPT:
271 return 5;
273 case EGALAX_PKT_TYPE_DIAG:
274 if (len < 2)
275 return -1;
277 return buf[1] + 2;
280 return 0;
282 #endif
285 /*****************************************************************************
286 * PanJit Part
288 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
289 static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
291 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
292 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
293 dev->touch = pkt[0] & 0x01;
295 return 1;
297 #endif
300 /*****************************************************************************
301 * 3M/Microtouch Part
303 #ifdef CONFIG_TOUCHSCREEN_USB_3M
305 #define MTOUCHUSB_ASYNC_REPORT 1
306 #define MTOUCHUSB_RESET 7
307 #define MTOUCHUSB_REQ_CTRLLR_ID 10
309 static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
311 if (hwcalib_xy) {
312 dev->x = (pkt[4] << 8) | pkt[3];
313 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
314 } else {
315 dev->x = (pkt[8] << 8) | pkt[7];
316 dev->y = (pkt[10] << 8) | pkt[9];
318 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
320 return 1;
323 static int mtouch_init(struct usbtouch_usb *usbtouch)
325 int ret, i;
327 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
328 MTOUCHUSB_RESET,
329 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
330 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
331 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
332 __func__, ret);
333 if (ret < 0)
334 return ret;
335 msleep(150);
337 for (i = 0; i < 3; i++) {
338 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
339 MTOUCHUSB_ASYNC_REPORT,
340 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
341 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
342 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
343 __func__, ret);
344 if (ret >= 0)
345 break;
346 if (ret != -EPIPE)
347 return ret;
350 /* Default min/max xy are the raw values, override if using hw-calib */
351 if (hwcalib_xy) {
352 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
353 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
356 return 0;
358 #endif
361 /*****************************************************************************
362 * ITM Part
364 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
365 static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
367 int touch;
369 * ITM devices report invalid x/y data if not touched.
370 * if the screen was touched before but is not touched any more
371 * report touch as 0 with the last valid x/y data once. then stop
372 * reporting data until touched again.
374 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
376 touch = ~pkt[7] & 0x20;
377 if (!touch) {
378 if (dev->touch) {
379 dev->touch = 0;
380 return 1;
383 return 0;
386 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
387 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
388 dev->touch = touch;
390 return 1;
392 #endif
395 /*****************************************************************************
396 * eTurboTouch part
398 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
399 #ifndef MULTI_PACKET
400 #define MULTI_PACKET
401 #endif
402 static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
404 unsigned int shift;
406 /* packets should start with sync */
407 if (!(pkt[0] & 0x80))
408 return 0;
410 shift = (6 - (pkt[0] & 0x03));
411 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
412 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
413 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
415 return 1;
418 static int eturbo_get_pkt_len(unsigned char *buf, int len)
420 if (buf[0] & 0x80)
421 return 5;
422 if (buf[0] == 0x01)
423 return 3;
424 return 0;
426 #endif
429 /*****************************************************************************
430 * Gunze part
432 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
433 static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
435 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
436 return 0;
438 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
439 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
440 dev->touch = pkt[0] & 0x20;
442 return 1;
444 #endif
446 /*****************************************************************************
447 * DMC TSC-10/25 Part
449 * Documentation about the controller and it's protocol can be found at
450 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
451 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
453 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
455 /* supported data rates. currently using 130 */
456 #define TSC10_RATE_POINT 0x50
457 #define TSC10_RATE_30 0x40
458 #define TSC10_RATE_50 0x41
459 #define TSC10_RATE_80 0x42
460 #define TSC10_RATE_100 0x43
461 #define TSC10_RATE_130 0x44
462 #define TSC10_RATE_150 0x45
464 /* commands */
465 #define TSC10_CMD_RESET 0x55
466 #define TSC10_CMD_RATE 0x05
467 #define TSC10_CMD_DATA1 0x01
469 static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
471 struct usb_device *dev = usbtouch->udev;
472 int ret = -ENOMEM;
473 unsigned char *buf;
475 buf = kmalloc(2, GFP_KERNEL);
476 if (!buf)
477 goto err_nobuf;
478 /* reset */
479 buf[0] = buf[1] = 0xFF;
480 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
481 TSC10_CMD_RESET,
482 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
483 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
484 if (ret < 0)
485 goto err_out;
486 if (buf[0] != 0x06) {
487 ret = -ENODEV;
488 goto err_out;
491 /* set coordinate output rate */
492 buf[0] = buf[1] = 0xFF;
493 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
494 TSC10_CMD_RATE,
495 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
496 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
497 if (ret < 0)
498 goto err_out;
499 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
500 ret = -ENODEV;
501 goto err_out;
504 /* start sending data */
505 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
506 TSC10_CMD_DATA1,
507 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
508 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
509 err_out:
510 kfree(buf);
511 err_nobuf:
512 return ret;
516 static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
518 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
519 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
520 dev->touch = pkt[0] & 0x01;
522 return 1;
524 #endif
527 /*****************************************************************************
528 * IRTOUCH Part
530 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
531 static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
533 dev->x = (pkt[3] << 8) | pkt[2];
534 dev->y = (pkt[5] << 8) | pkt[4];
535 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
537 return 1;
539 #endif
542 /*****************************************************************************
543 * IdealTEK URTC1000 Part
545 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
546 #ifndef MULTI_PACKET
547 #define MULTI_PACKET
548 #endif
549 static int idealtek_get_pkt_len(unsigned char *buf, int len)
551 if (buf[0] & 0x80)
552 return 5;
553 if (buf[0] == 0x01)
554 return len;
555 return 0;
558 static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
560 switch (pkt[0] & 0x98) {
561 case 0x88:
562 /* touch data in IdealTEK mode */
563 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
564 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
565 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
566 return 1;
568 case 0x98:
569 /* touch data in MT emulation mode */
570 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
571 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
572 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
573 return 1;
575 default:
576 return 0;
579 #endif
581 /*****************************************************************************
582 * General Touch Part
584 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
585 static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
587 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ;
588 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ;
589 dev->press = pkt[5] & 0xff;
590 dev->touch = pkt[0] & 0x01;
592 return 1;
594 #endif
596 /*****************************************************************************
597 * GoTop Part
599 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
600 static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
602 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
603 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
604 dev->touch = pkt[0] & 0x01;
606 return 1;
608 #endif
610 /*****************************************************************************
611 * JASTEC Part
613 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
614 static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
616 dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
617 dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
618 dev->touch = (pkt[0] & 0x40) >> 6;
620 return 1;
622 #endif
625 /*****************************************************************************
626 * the different device descriptors
628 #ifdef MULTI_PACKET
629 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
630 unsigned char *pkt, int len);
631 #endif
633 static struct usbtouch_device_info usbtouch_dev_info[] = {
634 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
635 [DEVTYPE_EGALAX] = {
636 .min_xc = 0x0,
637 .max_xc = 0x07ff,
638 .min_yc = 0x0,
639 .max_yc = 0x07ff,
640 .rept_size = 16,
641 .process_pkt = usbtouch_process_multi,
642 .get_pkt_len = egalax_get_pkt_len,
643 .read_data = egalax_read_data,
645 #endif
647 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
648 [DEVTYPE_PANJIT] = {
649 .min_xc = 0x0,
650 .max_xc = 0x0fff,
651 .min_yc = 0x0,
652 .max_yc = 0x0fff,
653 .rept_size = 8,
654 .read_data = panjit_read_data,
656 #endif
658 #ifdef CONFIG_TOUCHSCREEN_USB_3M
659 [DEVTYPE_3M] = {
660 .min_xc = 0x0,
661 .max_xc = 0x4000,
662 .min_yc = 0x0,
663 .max_yc = 0x4000,
664 .rept_size = 11,
665 .read_data = mtouch_read_data,
666 .init = mtouch_init,
668 #endif
670 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
671 [DEVTYPE_ITM] = {
672 .min_xc = 0x0,
673 .max_xc = 0x0fff,
674 .min_yc = 0x0,
675 .max_yc = 0x0fff,
676 .max_press = 0xff,
677 .rept_size = 8,
678 .read_data = itm_read_data,
680 #endif
682 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
683 [DEVTYPE_ETURBO] = {
684 .min_xc = 0x0,
685 .max_xc = 0x07ff,
686 .min_yc = 0x0,
687 .max_yc = 0x07ff,
688 .rept_size = 8,
689 .process_pkt = usbtouch_process_multi,
690 .get_pkt_len = eturbo_get_pkt_len,
691 .read_data = eturbo_read_data,
693 #endif
695 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
696 [DEVTYPE_GUNZE] = {
697 .min_xc = 0x0,
698 .max_xc = 0x0fff,
699 .min_yc = 0x0,
700 .max_yc = 0x0fff,
701 .rept_size = 4,
702 .read_data = gunze_read_data,
704 #endif
706 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
707 [DEVTYPE_DMC_TSC10] = {
708 .min_xc = 0x0,
709 .max_xc = 0x03ff,
710 .min_yc = 0x0,
711 .max_yc = 0x03ff,
712 .rept_size = 5,
713 .init = dmc_tsc10_init,
714 .read_data = dmc_tsc10_read_data,
716 #endif
718 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
719 [DEVTYPE_IRTOUCH] = {
720 .min_xc = 0x0,
721 .max_xc = 0x0fff,
722 .min_yc = 0x0,
723 .max_yc = 0x0fff,
724 .rept_size = 8,
725 .read_data = irtouch_read_data,
727 #endif
729 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
730 [DEVTYPE_IDEALTEK] = {
731 .min_xc = 0x0,
732 .max_xc = 0x0fff,
733 .min_yc = 0x0,
734 .max_yc = 0x0fff,
735 .rept_size = 8,
736 .process_pkt = usbtouch_process_multi,
737 .get_pkt_len = idealtek_get_pkt_len,
738 .read_data = idealtek_read_data,
740 #endif
742 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
743 [DEVTYPE_GENERAL_TOUCH] = {
744 .min_xc = 0x0,
745 .max_xc = 0x0500,
746 .min_yc = 0x0,
747 .max_yc = 0x0500,
748 .rept_size = 7,
749 .read_data = general_touch_read_data,
751 #endif
753 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
754 [DEVTYPE_GOTOP] = {
755 .min_xc = 0x0,
756 .max_xc = 0x03ff,
757 .min_yc = 0x0,
758 .max_yc = 0x03ff,
759 .rept_size = 4,
760 .read_data = gotop_read_data,
762 #endif
764 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
765 [DEVTYPE_JASTEC] = {
766 .min_xc = 0x0,
767 .max_xc = 0x0fff,
768 .min_yc = 0x0,
769 .max_yc = 0x0fff,
770 .rept_size = 4,
771 .read_data = jastec_read_data,
773 #endif
775 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
776 [DEVTYPE_E2I] = {
777 .min_xc = 0x0,
778 .max_xc = 0x7fff,
779 .min_yc = 0x0,
780 .max_yc = 0x7fff,
781 .rept_size = 6,
782 .init = e2i_init,
783 .read_data = e2i_read_data,
785 #endif
789 /*****************************************************************************
790 * Generic Part
792 static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
793 unsigned char *pkt, int len)
795 struct usbtouch_device_info *type = usbtouch->type;
797 if (!type->read_data(usbtouch, pkt))
798 return;
800 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
802 if (swap_xy) {
803 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
804 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
805 } else {
806 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
807 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
809 if (type->max_press)
810 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
811 input_sync(usbtouch->input);
815 #ifdef MULTI_PACKET
816 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
817 unsigned char *pkt, int len)
819 unsigned char *buffer;
820 int pkt_len, pos, buf_len, tmp;
822 /* process buffer */
823 if (unlikely(usbtouch->buf_len)) {
824 /* try to get size */
825 pkt_len = usbtouch->type->get_pkt_len(
826 usbtouch->buffer, usbtouch->buf_len);
828 /* drop? */
829 if (unlikely(!pkt_len))
830 goto out_flush_buf;
832 /* need to append -pkt_len bytes before able to get size */
833 if (unlikely(pkt_len < 0)) {
834 int append = -pkt_len;
835 if (unlikely(append > len))
836 append = len;
837 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
838 goto out_flush_buf;
839 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
840 usbtouch->buf_len += append;
842 pkt_len = usbtouch->type->get_pkt_len(
843 usbtouch->buffer, usbtouch->buf_len);
844 if (pkt_len < 0)
845 return;
848 /* append */
849 tmp = pkt_len - usbtouch->buf_len;
850 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
851 goto out_flush_buf;
852 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
853 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
855 buffer = pkt + tmp;
856 buf_len = len - tmp;
857 } else {
858 buffer = pkt;
859 buf_len = len;
862 /* loop over the received packet, process */
863 pos = 0;
864 while (pos < buf_len) {
865 /* get packet len */
866 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
867 buf_len - pos);
869 /* unknown packet: skip one byte */
870 if (unlikely(!pkt_len)) {
871 pos++;
872 continue;
875 /* full packet: process */
876 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
877 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
878 } else {
879 /* incomplete packet: save in buffer */
880 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
881 usbtouch->buf_len = buf_len - pos;
882 return;
884 pos += pkt_len;
887 out_flush_buf:
888 usbtouch->buf_len = 0;
889 return;
891 #endif
894 static void usbtouch_irq(struct urb *urb)
896 struct usbtouch_usb *usbtouch = urb->context;
897 int retval;
899 switch (urb->status) {
900 case 0:
901 /* success */
902 break;
903 case -ETIME:
904 /* this urb is timing out */
905 dbg("%s - urb timed out - was the device unplugged?",
906 __func__);
907 return;
908 case -ECONNRESET:
909 case -ENOENT:
910 case -ESHUTDOWN:
911 /* this urb is terminated, clean up */
912 dbg("%s - urb shutting down with status: %d",
913 __func__, urb->status);
914 return;
915 default:
916 dbg("%s - nonzero urb status received: %d",
917 __func__, urb->status);
918 goto exit;
921 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
923 exit:
924 retval = usb_submit_urb(urb, GFP_ATOMIC);
925 if (retval)
926 err("%s - usb_submit_urb failed with result: %d",
927 __func__, retval);
930 static int usbtouch_open(struct input_dev *input)
932 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
934 usbtouch->irq->dev = usbtouch->udev;
936 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
937 return -EIO;
939 return 0;
942 static void usbtouch_close(struct input_dev *input)
944 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
946 usb_kill_urb(usbtouch->irq);
950 static void usbtouch_free_buffers(struct usb_device *udev,
951 struct usbtouch_usb *usbtouch)
953 usb_buffer_free(udev, usbtouch->type->rept_size,
954 usbtouch->data, usbtouch->data_dma);
955 kfree(usbtouch->buffer);
959 static int usbtouch_probe(struct usb_interface *intf,
960 const struct usb_device_id *id)
962 struct usbtouch_usb *usbtouch;
963 struct input_dev *input_dev;
964 struct usb_host_interface *interface;
965 struct usb_endpoint_descriptor *endpoint;
966 struct usb_device *udev = interface_to_usbdev(intf);
967 struct usbtouch_device_info *type;
968 int err = -ENOMEM;
970 /* some devices are ignored */
971 if (id->driver_info == DEVTYPE_IGNORE)
972 return -ENODEV;
974 interface = intf->cur_altsetting;
975 endpoint = &interface->endpoint[0].desc;
977 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
978 input_dev = input_allocate_device();
979 if (!usbtouch || !input_dev)
980 goto out_free;
982 type = &usbtouch_dev_info[id->driver_info];
983 usbtouch->type = type;
984 if (!type->process_pkt)
985 type->process_pkt = usbtouch_process_pkt;
987 usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
988 GFP_KERNEL, &usbtouch->data_dma);
989 if (!usbtouch->data)
990 goto out_free;
992 if (type->get_pkt_len) {
993 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
994 if (!usbtouch->buffer)
995 goto out_free_buffers;
998 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
999 if (!usbtouch->irq) {
1000 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
1001 goto out_free_buffers;
1004 usbtouch->udev = udev;
1005 usbtouch->input = input_dev;
1007 if (udev->manufacturer)
1008 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
1010 if (udev->product) {
1011 if (udev->manufacturer)
1012 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
1013 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
1016 if (!strlen(usbtouch->name))
1017 snprintf(usbtouch->name, sizeof(usbtouch->name),
1018 "USB Touchscreen %04x:%04x",
1019 le16_to_cpu(udev->descriptor.idVendor),
1020 le16_to_cpu(udev->descriptor.idProduct));
1022 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
1023 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
1025 input_dev->name = usbtouch->name;
1026 input_dev->phys = usbtouch->phys;
1027 usb_to_input_id(udev, &input_dev->id);
1028 input_dev->dev.parent = &intf->dev;
1030 input_set_drvdata(input_dev, usbtouch);
1032 input_dev->open = usbtouch_open;
1033 input_dev->close = usbtouch_close;
1035 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1036 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1037 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
1038 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
1039 if (type->max_press)
1040 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1041 type->max_press, 0, 0);
1043 usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
1044 usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress),
1045 usbtouch->data, type->rept_size,
1046 usbtouch_irq, usbtouch, endpoint->bInterval);
1048 usbtouch->irq->dev = usbtouch->udev;
1049 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1050 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1052 /* device specific init */
1053 if (type->init) {
1054 err = type->init(usbtouch);
1055 if (err) {
1056 dbg("%s - type->init() failed, err: %d", __func__, err);
1057 goto out_free_buffers;
1061 err = input_register_device(usbtouch->input);
1062 if (err) {
1063 dbg("%s - input_register_device failed, err: %d", __func__, err);
1064 goto out_free_buffers;
1067 usb_set_intfdata(intf, usbtouch);
1069 return 0;
1071 out_free_buffers:
1072 usbtouch_free_buffers(udev, usbtouch);
1073 out_free:
1074 input_free_device(input_dev);
1075 kfree(usbtouch);
1076 return err;
1079 static void usbtouch_disconnect(struct usb_interface *intf)
1081 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1083 dbg("%s - called", __func__);
1085 if (!usbtouch)
1086 return;
1088 dbg("%s - usbtouch is initialized, cleaning up", __func__);
1089 usb_set_intfdata(intf, NULL);
1090 usb_kill_urb(usbtouch->irq);
1091 input_unregister_device(usbtouch->input);
1092 usb_free_urb(usbtouch->irq);
1093 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1094 kfree(usbtouch);
1097 MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1099 static struct usb_driver usbtouch_driver = {
1100 .name = "usbtouchscreen",
1101 .probe = usbtouch_probe,
1102 .disconnect = usbtouch_disconnect,
1103 .id_table = usbtouch_devices,
1106 static int __init usbtouch_init(void)
1108 return usb_register(&usbtouch_driver);
1111 static void __exit usbtouch_cleanup(void)
1113 usb_deregister(&usbtouch_driver);
1116 module_init(usbtouch_init);
1117 module_exit(usbtouch_cleanup);
1119 MODULE_AUTHOR(DRIVER_AUTHOR);
1120 MODULE_DESCRIPTION(DRIVER_DESC);
1121 MODULE_LICENSE("GPL");
1123 MODULE_ALIAS("touchkitusb");
1124 MODULE_ALIAS("itmtouch");
1125 MODULE_ALIAS("mtouchusb");