1 /******************************************************************************
3 * Driver for USB Touchscreens, supporting those devices:
5 * includes eTurboTouch CT-410/510/700
6 * - 3M/Microtouch EX II series
12 * - IRTOUCHSYSTEMS/UNITOP
15 * - GoTop Super_Q2/GogoPen/PenPower tablets
16 * - JASTEC USB touch controller/DigiTech DTR-02U
17 * - Zytronic capacitive touchscreen
19 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
20 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License as
24 * published by the Free Software Foundation; either version 2 of the
25 * License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful, but
28 * WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 * Driver is based on touchkitusb.c
37 * - ITM parts are from itmtouch.c
38 * - 3M parts are from mtouchusb.c
39 * - PanJit parts are from an unmerged driver by Lanslott Gish
40 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
41 * driver from Marius Vollmer
43 *****************************************************************************/
47 #include <linux/kernel.h>
48 #include <linux/slab.h>
49 #include <linux/input.h>
50 #include <linux/module.h>
51 #include <linux/init.h>
52 #include <linux/usb.h>
53 #include <linux/usb/input.h>
54 #include <linux/hid.h>
57 #define DRIVER_VERSION "v0.6"
58 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
59 #define DRIVER_DESC "USB Touchscreen Driver"
62 module_param(swap_xy, bool, 0644);
63 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
65 static int hwcalib_xy;
66 module_param(hwcalib_xy, bool, 0644);
67 MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
69 /* device specifc data/functions */
71 struct usbtouch_device_info {
74 int min_press, max_press;
78 * Always service the USB devices irq not just when the input device is
79 * open. This is useful when devices have a watchdog which prevents us
80 * from periodically polling the device. Leave this unset unless your
81 * touchscreen device requires it, as it does consume more of the USB
86 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
89 * used to get the packet len. possible return values:
92 * < 0: -return value more bytes needed
94 int (*get_pkt_len) (unsigned char *pkt, int len);
96 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
97 int (*init) (struct usbtouch_usb *usbtouch);
100 /* a usbtouch device */
101 struct usbtouch_usb {
104 unsigned char *buffer;
107 struct usb_device *udev;
108 struct input_dev *input;
109 struct usbtouch_device_info *type;
130 DEVTYPE_GENERAL_TOUCH,
138 #define USB_DEVICE_HID_CLASS(vend, prod) \
139 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
140 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
141 | USB_DEVICE_ID_MATCH_DEVICE, \
142 .idVendor = (vend), \
143 .idProduct = (prod), \
144 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
145 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
147 static struct usb_device_id usbtouch_devices[] = {
148 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
149 /* ignore the HID capable devices, handled by usbhid */
150 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
151 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
153 /* normal device IDs */
154 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
155 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
156 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
157 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
158 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
159 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
160 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
163 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
164 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
165 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
166 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
167 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
170 #ifdef CONFIG_TOUCHSCREEN_USB_3M
171 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
174 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
175 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
178 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
179 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
182 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
183 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
186 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
187 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
190 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
191 {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
192 {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
195 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
196 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
199 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
200 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
203 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
204 {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP},
205 {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP},
206 {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP},
209 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
210 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
213 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
214 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
217 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
218 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
221 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
222 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH},
229 /*****************************************************************************
233 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
234 static int e2i_init(struct usbtouch_usb *usbtouch)
238 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
239 0x01, 0x02, 0x0000, 0x0081,
240 NULL, 0, USB_CTRL_SET_TIMEOUT);
242 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
247 static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
249 int tmp = (pkt[0] << 8) | pkt[1];
250 dev->x = (pkt[2] << 8) | pkt[3];
251 dev->y = (pkt[4] << 8) | pkt[5];
254 dev->touch = (tmp > 0);
255 dev->press = (tmp > 0 ? tmp : 0);
262 /*****************************************************************************
266 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
272 #define EGALAX_PKT_TYPE_MASK 0xFE
273 #define EGALAX_PKT_TYPE_REPT 0x80
274 #define EGALAX_PKT_TYPE_DIAG 0x0A
276 static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
278 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
281 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
282 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
283 dev->touch = pkt[0] & 0x01;
288 static int egalax_get_pkt_len(unsigned char *buf, int len)
290 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
291 case EGALAX_PKT_TYPE_REPT:
294 case EGALAX_PKT_TYPE_DIAG:
306 /*****************************************************************************
309 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
310 static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
312 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
313 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
314 dev->touch = pkt[0] & 0x01;
321 /*****************************************************************************
324 #ifdef CONFIG_TOUCHSCREEN_USB_3M
326 #define MTOUCHUSB_ASYNC_REPORT 1
327 #define MTOUCHUSB_RESET 7
328 #define MTOUCHUSB_REQ_CTRLLR_ID 10
330 static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
333 dev->x = (pkt[4] << 8) | pkt[3];
334 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
336 dev->x = (pkt[8] << 8) | pkt[7];
337 dev->y = (pkt[10] << 8) | pkt[9];
339 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
344 static int mtouch_init(struct usbtouch_usb *usbtouch)
348 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
350 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
351 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
352 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
358 for (i = 0; i < 3; i++) {
359 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
360 MTOUCHUSB_ASYNC_REPORT,
361 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
362 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
363 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
371 /* Default min/max xy are the raw values, override if using hw-calib */
373 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
374 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
382 /*****************************************************************************
385 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
386 static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
390 * ITM devices report invalid x/y data if not touched.
391 * if the screen was touched before but is not touched any more
392 * report touch as 0 with the last valid x/y data once. then stop
393 * reporting data until touched again.
395 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
397 touch = ~pkt[7] & 0x20;
407 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
408 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
416 /*****************************************************************************
419 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
423 static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
427 /* packets should start with sync */
428 if (!(pkt[0] & 0x80))
431 shift = (6 - (pkt[0] & 0x03));
432 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
433 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
434 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
439 static int eturbo_get_pkt_len(unsigned char *buf, int len)
450 /*****************************************************************************
453 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
454 static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
456 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
459 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
460 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
461 dev->touch = pkt[0] & 0x20;
467 /*****************************************************************************
470 * Documentation about the controller and it's protocol can be found at
471 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
472 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
474 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
476 /* supported data rates. currently using 130 */
477 #define TSC10_RATE_POINT 0x50
478 #define TSC10_RATE_30 0x40
479 #define TSC10_RATE_50 0x41
480 #define TSC10_RATE_80 0x42
481 #define TSC10_RATE_100 0x43
482 #define TSC10_RATE_130 0x44
483 #define TSC10_RATE_150 0x45
486 #define TSC10_CMD_RESET 0x55
487 #define TSC10_CMD_RATE 0x05
488 #define TSC10_CMD_DATA1 0x01
490 static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
492 struct usb_device *dev = usbtouch->udev;
496 buf = kmalloc(2, GFP_KERNEL);
500 buf[0] = buf[1] = 0xFF;
501 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
503 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
504 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
507 if (buf[0] != 0x06) {
512 /* set coordinate output rate */
513 buf[0] = buf[1] = 0xFF;
514 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
516 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
517 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
520 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
525 /* start sending data */
526 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
528 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
529 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
537 static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
539 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
540 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
541 dev->touch = pkt[0] & 0x01;
548 /*****************************************************************************
551 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
552 static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
554 dev->x = (pkt[3] << 8) | pkt[2];
555 dev->y = (pkt[5] << 8) | pkt[4];
556 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
562 /*****************************************************************************
565 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
566 static int tc5uh_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
568 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
569 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
570 dev->touch = pkt[0] & 0x01;
576 /*****************************************************************************
577 * IdealTEK URTC1000 Part
579 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
583 static int idealtek_get_pkt_len(unsigned char *buf, int len)
592 static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
594 switch (pkt[0] & 0x98) {
596 /* touch data in IdealTEK mode */
597 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
598 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
599 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
603 /* touch data in MT emulation mode */
604 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
605 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
606 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
615 /*****************************************************************************
618 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
619 static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
621 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ;
622 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ;
623 dev->press = pkt[5] & 0xff;
624 dev->touch = pkt[0] & 0x01;
630 /*****************************************************************************
633 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
634 static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
636 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
637 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
638 dev->touch = pkt[0] & 0x01;
644 /*****************************************************************************
647 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
648 static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
650 dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
651 dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
652 dev->touch = (pkt[0] & 0x40) >> 6;
658 /*****************************************************************************
661 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
662 static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
665 case 0x3A: /* command response */
666 dbg("%s: Command response %d", __func__, pkt[1]);
669 case 0xC0: /* down */
670 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
671 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
673 dbg("%s: down %d,%d", __func__, dev->x, dev->y);
677 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
678 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
680 dbg("%s: up %d,%d", __func__, dev->x, dev->y);
684 dbg("%s: Unknown return %d", __func__, pkt[0]);
692 /*****************************************************************************
693 * the different device descriptors
696 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
697 unsigned char *pkt, int len);
700 static struct usbtouch_device_info usbtouch_dev_info[] = {
701 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
708 .process_pkt = usbtouch_process_multi,
709 .get_pkt_len = egalax_get_pkt_len,
710 .read_data = egalax_read_data,
714 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
721 .read_data = panjit_read_data,
725 #ifdef CONFIG_TOUCHSCREEN_USB_3M
732 .read_data = mtouch_read_data,
737 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
745 .read_data = itm_read_data,
749 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
756 .process_pkt = usbtouch_process_multi,
757 .get_pkt_len = eturbo_get_pkt_len,
758 .read_data = eturbo_read_data,
762 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
769 .read_data = gunze_read_data,
773 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
774 [DEVTYPE_DMC_TSC10] = {
780 .init = dmc_tsc10_init,
781 .read_data = dmc_tsc10_read_data,
785 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
786 [DEVTYPE_IRTOUCH] = {
792 .read_data = irtouch_read_data,
796 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
797 [DEVTYPE_IDEALTEK] = {
803 .process_pkt = usbtouch_process_multi,
804 .get_pkt_len = idealtek_get_pkt_len,
805 .read_data = idealtek_read_data,
809 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
810 [DEVTYPE_GENERAL_TOUCH] = {
816 .read_data = general_touch_read_data,
820 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
827 .read_data = gotop_read_data,
831 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
838 .read_data = jastec_read_data,
842 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
850 .read_data = e2i_read_data,
854 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
855 [DEVTYPE_ZYTRONIC] = {
861 .read_data = zytronic_read_data,
866 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
873 .read_data = tc5uh_read_data,
879 /*****************************************************************************
882 static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
883 unsigned char *pkt, int len)
885 struct usbtouch_device_info *type = usbtouch->type;
887 if (!type->read_data(usbtouch, pkt))
890 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
893 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
894 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
896 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
897 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
900 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
901 input_sync(usbtouch->input);
906 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
907 unsigned char *pkt, int len)
909 unsigned char *buffer;
910 int pkt_len, pos, buf_len, tmp;
913 if (unlikely(usbtouch->buf_len)) {
914 /* try to get size */
915 pkt_len = usbtouch->type->get_pkt_len(
916 usbtouch->buffer, usbtouch->buf_len);
919 if (unlikely(!pkt_len))
922 /* need to append -pkt_len bytes before able to get size */
923 if (unlikely(pkt_len < 0)) {
924 int append = -pkt_len;
925 if (unlikely(append > len))
927 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
929 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
930 usbtouch->buf_len += append;
932 pkt_len = usbtouch->type->get_pkt_len(
933 usbtouch->buffer, usbtouch->buf_len);
939 tmp = pkt_len - usbtouch->buf_len;
940 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
942 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
943 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
952 /* loop over the received packet, process */
954 while (pos < buf_len) {
956 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
959 /* unknown packet: skip one byte */
960 if (unlikely(!pkt_len)) {
965 /* full packet: process */
966 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
967 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
969 /* incomplete packet: save in buffer */
970 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
971 usbtouch->buf_len = buf_len - pos;
978 usbtouch->buf_len = 0;
984 static void usbtouch_irq(struct urb *urb)
986 struct usbtouch_usb *usbtouch = urb->context;
989 switch (urb->status) {
994 /* this urb is timing out */
995 dbg("%s - urb timed out - was the device unplugged?",
1001 /* this urb is terminated, clean up */
1002 dbg("%s - urb shutting down with status: %d",
1003 __func__, urb->status);
1006 dbg("%s - nonzero urb status received: %d",
1007 __func__, urb->status);
1011 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
1014 retval = usb_submit_urb(urb, GFP_ATOMIC);
1016 err("%s - usb_submit_urb failed with result: %d",
1020 static int usbtouch_open(struct input_dev *input)
1022 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1024 usbtouch->irq->dev = usbtouch->udev;
1026 if (!usbtouch->type->irq_always) {
1027 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
1034 static void usbtouch_close(struct input_dev *input)
1036 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1038 if (!usbtouch->type->irq_always)
1039 usb_kill_urb(usbtouch->irq);
1043 static void usbtouch_free_buffers(struct usb_device *udev,
1044 struct usbtouch_usb *usbtouch)
1046 usb_buffer_free(udev, usbtouch->type->rept_size,
1047 usbtouch->data, usbtouch->data_dma);
1048 kfree(usbtouch->buffer);
1052 static int usbtouch_probe(struct usb_interface *intf,
1053 const struct usb_device_id *id)
1055 struct usbtouch_usb *usbtouch;
1056 struct input_dev *input_dev;
1057 struct usb_host_interface *interface;
1058 struct usb_endpoint_descriptor *endpoint;
1059 struct usb_device *udev = interface_to_usbdev(intf);
1060 struct usbtouch_device_info *type;
1063 /* some devices are ignored */
1064 if (id->driver_info == DEVTYPE_IGNORE)
1067 interface = intf->cur_altsetting;
1068 endpoint = &interface->endpoint[0].desc;
1070 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
1071 input_dev = input_allocate_device();
1072 if (!usbtouch || !input_dev)
1075 type = &usbtouch_dev_info[id->driver_info];
1076 usbtouch->type = type;
1077 if (!type->process_pkt)
1078 type->process_pkt = usbtouch_process_pkt;
1080 usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
1081 GFP_KERNEL, &usbtouch->data_dma);
1082 if (!usbtouch->data)
1085 if (type->get_pkt_len) {
1086 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
1087 if (!usbtouch->buffer)
1088 goto out_free_buffers;
1091 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
1092 if (!usbtouch->irq) {
1093 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
1094 goto out_free_buffers;
1097 usbtouch->udev = udev;
1098 usbtouch->input = input_dev;
1100 if (udev->manufacturer)
1101 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
1103 if (udev->product) {
1104 if (udev->manufacturer)
1105 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
1106 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
1109 if (!strlen(usbtouch->name))
1110 snprintf(usbtouch->name, sizeof(usbtouch->name),
1111 "USB Touchscreen %04x:%04x",
1112 le16_to_cpu(udev->descriptor.idVendor),
1113 le16_to_cpu(udev->descriptor.idProduct));
1115 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
1116 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
1118 input_dev->name = usbtouch->name;
1119 input_dev->phys = usbtouch->phys;
1120 usb_to_input_id(udev, &input_dev->id);
1121 input_dev->dev.parent = &intf->dev;
1123 input_set_drvdata(input_dev, usbtouch);
1125 input_dev->open = usbtouch_open;
1126 input_dev->close = usbtouch_close;
1128 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1129 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1130 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
1131 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
1132 if (type->max_press)
1133 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1134 type->max_press, 0, 0);
1136 usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
1137 usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress),
1138 usbtouch->data, type->rept_size,
1139 usbtouch_irq, usbtouch, endpoint->bInterval);
1141 usbtouch->irq->dev = usbtouch->udev;
1142 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1143 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1145 /* device specific init */
1147 err = type->init(usbtouch);
1149 dbg("%s - type->init() failed, err: %d", __func__, err);
1150 goto out_free_buffers;
1154 err = input_register_device(usbtouch->input);
1156 dbg("%s - input_register_device failed, err: %d", __func__, err);
1157 goto out_free_buffers;
1160 usb_set_intfdata(intf, usbtouch);
1162 if (usbtouch->type->irq_always)
1163 usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1168 usbtouch_free_buffers(udev, usbtouch);
1170 input_free_device(input_dev);
1175 static void usbtouch_disconnect(struct usb_interface *intf)
1177 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1179 dbg("%s - called", __func__);
1184 dbg("%s - usbtouch is initialized, cleaning up", __func__);
1185 usb_set_intfdata(intf, NULL);
1186 /* this will stop IO via close */
1187 input_unregister_device(usbtouch->input);
1188 usb_free_urb(usbtouch->irq);
1189 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1193 MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1195 static struct usb_driver usbtouch_driver = {
1196 .name = "usbtouchscreen",
1197 .probe = usbtouch_probe,
1198 .disconnect = usbtouch_disconnect,
1199 .id_table = usbtouch_devices,
1202 static int __init usbtouch_init(void)
1204 return usb_register(&usbtouch_driver);
1207 static void __exit usbtouch_cleanup(void)
1209 usb_deregister(&usbtouch_driver);
1212 module_init(usbtouch_init);
1213 module_exit(usbtouch_cleanup);
1215 MODULE_AUTHOR(DRIVER_AUTHOR);
1216 MODULE_DESCRIPTION(DRIVER_DESC);
1217 MODULE_LICENSE("GPL");
1219 MODULE_ALIAS("touchkitusb");
1220 MODULE_ALIAS("itmtouch");
1221 MODULE_ALIAS("mtouchusb");