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
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 *****************************************************************************/
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"
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 */
70 struct usbtouch_device_info
{
73 int min_press
, max_press
;
76 void (*process_pkt
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
, int len
);
79 * used to get the packet len. possible return values:
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 */
94 unsigned char *buffer
;
97 struct usb_device
*udev
;
98 struct input_dev
*input
;
99 struct usbtouch_device_info
*type
;
120 DEVTYPE_GENERAL_TOUCH
,
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
},
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
},
158 #ifdef CONFIG_TOUCHSCREEN_USB_3M
159 {USB_DEVICE(0x0596, 0x0001), .driver_info
= DEVTYPE_3M
},
162 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
163 {USB_DEVICE(0x0403, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
166 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
167 {USB_DEVICE(0x1234, 0x5678), .driver_info
= DEVTYPE_ETURBO
},
170 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
171 {USB_DEVICE(0x0637, 0x0001), .driver_info
= DEVTYPE_GUNZE
},
174 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
175 {USB_DEVICE(0x0afa, 0x03e8), .driver_info
= DEVTYPE_DMC_TSC10
},
178 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
179 {USB_DEVICE(0x595a, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
180 {USB_DEVICE(0x6615, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
183 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
184 {USB_DEVICE(0x1391, 0x1000), .driver_info
= DEVTYPE_IDEALTEK
},
187 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
188 {USB_DEVICE(0x0dfc, 0x0001), .driver_info
= DEVTYPE_GENERAL_TOUCH
},
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
},
197 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
198 {USB_DEVICE(0x0f92, 0x0001), .driver_info
= DEVTYPE_JASTEC
},
201 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
202 {USB_DEVICE(0x1ac7, 0x0001), .driver_info
= DEVTYPE_E2I
},
208 /*****************************************************************************
212 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
213 static int e2i_init(struct usbtouch_usb
*usbtouch
)
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",
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];
233 dev
->touch
= (tmp
> 0);
234 dev
->press
= (tmp
> 0 ? tmp
: 0);
241 /*****************************************************************************
245 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
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
)
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;
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
:
273 case EGALAX_PKT_TYPE_DIAG
:
285 /*****************************************************************************
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;
300 /*****************************************************************************
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
)
312 dev
->x
= (pkt
[4] << 8) | pkt
[3];
313 dev
->y
= 0xffff - ((pkt
[6] << 8) | pkt
[5]);
315 dev
->x
= (pkt
[8] << 8) | pkt
[7];
316 dev
->y
= (pkt
[10] << 8) | pkt
[9];
318 dev
->touch
= (pkt
[2] & 0x40) ? 1 : 0;
323 static int mtouch_init(struct usbtouch_usb
*usbtouch
)
327 ret
= usb_control_msg(usbtouch
->udev
, usb_rcvctrlpipe(usbtouch
->udev
, 0),
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",
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",
350 /* Default min/max xy are the raw values, override if using hw-calib */
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);
361 /*****************************************************************************
364 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
365 static int itm_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
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;
386 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[3] & 0x7F);
387 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[4] & 0x7F);
395 /*****************************************************************************
398 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
402 static int eturbo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
406 /* packets should start with sync */
407 if (!(pkt
[0] & 0x80))
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;
418 static int eturbo_get_pkt_len(unsigned char *buf
, int len
)
429 /*****************************************************************************
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))
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;
446 /*****************************************************************************
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
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
;
475 buf
= kmalloc(2, GFP_KERNEL
);
479 buf
[0] = buf
[1] = 0xFF;
480 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
482 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
483 0, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
486 if (buf
[0] != 0x06) {
491 /* set coordinate output rate */
492 buf
[0] = buf
[1] = 0xFF;
493 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
495 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
496 TSC10_RATE_150
, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
499 if ((buf
[0] != 0x06) && (buf
[0] != 0x15 || buf
[1] != 0x01)) {
504 /* start sending data */
505 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
507 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
508 0, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
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;
527 /*****************************************************************************
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;
542 /*****************************************************************************
543 * IdealTEK URTC1000 Part
545 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
549 static int idealtek_get_pkt_len(unsigned char *buf
, int len
)
558 static int idealtek_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
560 switch (pkt
[0] & 0x98) {
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;
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;
581 /*****************************************************************************
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;
596 /*****************************************************************************
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;
610 /*****************************************************************************
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;
625 /*****************************************************************************
626 * the different device descriptors
629 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
630 unsigned char *pkt
, int len
);
633 static struct usbtouch_device_info usbtouch_dev_info
[] = {
634 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
641 .process_pkt
= usbtouch_process_multi
,
642 .get_pkt_len
= egalax_get_pkt_len
,
643 .read_data
= egalax_read_data
,
647 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
654 .read_data
= panjit_read_data
,
658 #ifdef CONFIG_TOUCHSCREEN_USB_3M
665 .read_data
= mtouch_read_data
,
670 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
678 .read_data
= itm_read_data
,
682 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
689 .process_pkt
= usbtouch_process_multi
,
690 .get_pkt_len
= eturbo_get_pkt_len
,
691 .read_data
= eturbo_read_data
,
695 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
702 .read_data
= gunze_read_data
,
706 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
707 [DEVTYPE_DMC_TSC10
] = {
713 .init
= dmc_tsc10_init
,
714 .read_data
= dmc_tsc10_read_data
,
718 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
719 [DEVTYPE_IRTOUCH
] = {
725 .read_data
= irtouch_read_data
,
729 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
730 [DEVTYPE_IDEALTEK
] = {
736 .process_pkt
= usbtouch_process_multi
,
737 .get_pkt_len
= idealtek_get_pkt_len
,
738 .read_data
= idealtek_read_data
,
742 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
743 [DEVTYPE_GENERAL_TOUCH
] = {
749 .read_data
= general_touch_read_data
,
753 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
760 .read_data
= gotop_read_data
,
764 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
771 .read_data
= jastec_read_data
,
775 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
783 .read_data
= e2i_read_data
,
789 /*****************************************************************************
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
))
800 input_report_key(usbtouch
->input
, BTN_TOUCH
, usbtouch
->touch
);
803 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->y
);
804 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->x
);
806 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->x
);
807 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->y
);
810 input_report_abs(usbtouch
->input
, ABS_PRESSURE
, usbtouch
->press
);
811 input_sync(usbtouch
->input
);
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
;
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
);
829 if (unlikely(!pkt_len
))
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
))
837 if (usbtouch
->buf_len
+ append
>= usbtouch
->type
->rept_size
)
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
);
849 tmp
= pkt_len
- usbtouch
->buf_len
;
850 if (usbtouch
->buf_len
+ tmp
>= usbtouch
->type
->rept_size
)
852 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, tmp
);
853 usbtouch_process_pkt(usbtouch
, usbtouch
->buffer
, pkt_len
);
862 /* loop over the received packet, process */
864 while (pos
< buf_len
) {
866 pkt_len
= usbtouch
->type
->get_pkt_len(buffer
+ pos
,
869 /* unknown packet: skip one byte */
870 if (unlikely(!pkt_len
)) {
875 /* full packet: process */
876 if (likely((pkt_len
> 0) && (pkt_len
<= buf_len
- pos
))) {
877 usbtouch_process_pkt(usbtouch
, buffer
+ pos
, pkt_len
);
879 /* incomplete packet: save in buffer */
880 memcpy(usbtouch
->buffer
, buffer
+ pos
, buf_len
- pos
);
881 usbtouch
->buf_len
= buf_len
- pos
;
888 usbtouch
->buf_len
= 0;
894 static void usbtouch_irq(struct urb
*urb
)
896 struct usbtouch_usb
*usbtouch
= urb
->context
;
899 switch (urb
->status
) {
904 /* this urb is timing out */
905 dbg("%s - urb timed out - was the device unplugged?",
911 /* this urb is terminated, clean up */
912 dbg("%s - urb shutting down with status: %d",
913 __func__
, urb
->status
);
916 dbg("%s - nonzero urb status received: %d",
917 __func__
, urb
->status
);
921 usbtouch
->type
->process_pkt(usbtouch
, usbtouch
->data
, urb
->actual_length
);
924 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
926 err("%s - usb_submit_urb failed with result: %d",
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
))
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
;
970 /* some devices are ignored */
971 if (id
->driver_info
== DEVTYPE_IGNORE
)
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
)
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
);
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 */
1054 err
= type
->init(usbtouch
);
1056 dbg("%s - type->init() failed, err: %d", __func__
, err
);
1057 goto out_free_buffers
;
1061 err
= input_register_device(usbtouch
->input
);
1063 dbg("%s - input_register_device failed, err: %d", __func__
, err
);
1064 goto out_free_buffers
;
1067 usb_set_intfdata(intf
, usbtouch
);
1072 usbtouch_free_buffers(udev
, usbtouch
);
1074 input_free_device(input_dev
);
1079 static void usbtouch_disconnect(struct usb_interface
*intf
)
1081 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1083 dbg("%s - called", __func__
);
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
);
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");