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
17 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
18 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License as
22 * published by the Free Software Foundation; either version 2 of the
23 * License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful, but
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 * Driver is based on touchkitusb.c
35 * - ITM parts are from itmtouch.c
36 * - 3M parts are from mtouchusb.c
37 * - PanJit parts are from an unmerged driver by Lanslott Gish
38 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
39 * driver from Marius Vollmer
41 *****************************************************************************/
45 #include <linux/kernel.h>
46 #include <linux/slab.h>
47 #include <linux/input.h>
48 #include <linux/module.h>
49 #include <linux/init.h>
50 #include <linux/usb.h>
51 #include <linux/usb/input.h>
52 #include <linux/hid.h>
55 #define DRIVER_VERSION "v0.6"
56 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
57 #define DRIVER_DESC "USB Touchscreen Driver"
60 module_param(swap_xy
, bool, 0644);
61 MODULE_PARM_DESC(swap_xy
, "If set X and Y axes are swapped.");
63 static int hwcalib_xy
;
64 module_param(hwcalib_xy
, bool, 0644);
65 MODULE_PARM_DESC(hwcalib_xy
, "If set hw-calibrated X/Y are used if available");
67 /* device specifc data/functions */
69 struct usbtouch_device_info
{
72 int min_press
, max_press
;
75 void (*process_pkt
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
, int len
);
78 * used to get the packet len. possible return values:
81 * < 0: -return value more bytes needed
83 int (*get_pkt_len
) (unsigned char *pkt
, int len
);
85 int (*read_data
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
);
86 int (*init
) (struct usbtouch_usb
*usbtouch
);
89 /* a usbtouch device */
93 unsigned char *buffer
;
96 struct usb_device
*udev
;
97 struct input_dev
*input
;
98 struct usbtouch_device_info
*type
;
119 DEVTYPE_GENERAL_TOUCH
,
123 #define USB_DEVICE_HID_CLASS(vend, prod) \
124 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
125 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
126 | USB_DEVICE_ID_MATCH_DEVICE, \
127 .idVendor = (vend), \
128 .idProduct = (prod), \
129 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
130 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
132 static struct usb_device_id usbtouch_devices
[] = {
133 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
134 /* ignore the HID capable devices, handled by usbhid */
135 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info
= DEVTYPE_IGNORE
},
136 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info
= DEVTYPE_IGNORE
},
138 /* normal device IDs */
139 {USB_DEVICE(0x3823, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
140 {USB_DEVICE(0x3823, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
141 {USB_DEVICE(0x0123, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
142 {USB_DEVICE(0x0eef, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
143 {USB_DEVICE(0x0eef, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
144 {USB_DEVICE(0x1234, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
145 {USB_DEVICE(0x1234, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
148 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
149 {USB_DEVICE(0x134c, 0x0001), .driver_info
= DEVTYPE_PANJIT
},
150 {USB_DEVICE(0x134c, 0x0002), .driver_info
= DEVTYPE_PANJIT
},
151 {USB_DEVICE(0x134c, 0x0003), .driver_info
= DEVTYPE_PANJIT
},
152 {USB_DEVICE(0x134c, 0x0004), .driver_info
= DEVTYPE_PANJIT
},
155 #ifdef CONFIG_TOUCHSCREEN_USB_3M
156 {USB_DEVICE(0x0596, 0x0001), .driver_info
= DEVTYPE_3M
},
159 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
160 {USB_DEVICE(0x0403, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
163 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
164 {USB_DEVICE(0x1234, 0x5678), .driver_info
= DEVTYPE_ETURBO
},
167 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
168 {USB_DEVICE(0x0637, 0x0001), .driver_info
= DEVTYPE_GUNZE
},
171 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
172 {USB_DEVICE(0x0afa, 0x03e8), .driver_info
= DEVTYPE_DMC_TSC10
},
175 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
176 {USB_DEVICE(0x595a, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
177 {USB_DEVICE(0x6615, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
180 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
181 {USB_DEVICE(0x1391, 0x1000), .driver_info
= DEVTYPE_IDEALTEK
},
184 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
185 {USB_DEVICE(0x0dfc, 0x0001), .driver_info
= DEVTYPE_GENERAL_TOUCH
},
188 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
189 {USB_DEVICE(0x08f2, 0x007f), .driver_info
= DEVTYPE_GOTOP
},
190 {USB_DEVICE(0x08f2, 0x00ce), .driver_info
= DEVTYPE_GOTOP
},
191 {USB_DEVICE(0x08f2, 0x00f4), .driver_info
= DEVTYPE_GOTOP
},
198 /*****************************************************************************
202 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
208 #define EGALAX_PKT_TYPE_MASK 0xFE
209 #define EGALAX_PKT_TYPE_REPT 0x80
210 #define EGALAX_PKT_TYPE_DIAG 0x0A
212 static int egalax_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
214 if ((pkt
[0] & EGALAX_PKT_TYPE_MASK
) != EGALAX_PKT_TYPE_REPT
)
217 dev
->x
= ((pkt
[3] & 0x0F) << 7) | (pkt
[4] & 0x7F);
218 dev
->y
= ((pkt
[1] & 0x0F) << 7) | (pkt
[2] & 0x7F);
219 dev
->touch
= pkt
[0] & 0x01;
224 static int egalax_get_pkt_len(unsigned char *buf
, int len
)
226 switch (buf
[0] & EGALAX_PKT_TYPE_MASK
) {
227 case EGALAX_PKT_TYPE_REPT
:
230 case EGALAX_PKT_TYPE_DIAG
:
242 /*****************************************************************************
245 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
246 static int panjit_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
248 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
249 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
250 dev
->touch
= pkt
[0] & 0x01;
257 /*****************************************************************************
260 #ifdef CONFIG_TOUCHSCREEN_USB_3M
262 #define MTOUCHUSB_ASYNC_REPORT 1
263 #define MTOUCHUSB_RESET 7
264 #define MTOUCHUSB_REQ_CTRLLR_ID 10
266 static int mtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
269 dev
->x
= (pkt
[4] << 8) | pkt
[3];
270 dev
->y
= 0xffff - ((pkt
[6] << 8) | pkt
[5]);
272 dev
->x
= (pkt
[8] << 8) | pkt
[7];
273 dev
->y
= (pkt
[10] << 8) | pkt
[9];
275 dev
->touch
= (pkt
[2] & 0x40) ? 1 : 0;
280 static int mtouch_init(struct usbtouch_usb
*usbtouch
)
284 ret
= usb_control_msg(usbtouch
->udev
, usb_rcvctrlpipe(usbtouch
->udev
, 0),
286 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
287 1, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
288 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
294 for (i
= 0; i
< 3; i
++) {
295 ret
= usb_control_msg(usbtouch
->udev
, usb_rcvctrlpipe(usbtouch
->udev
, 0),
296 MTOUCHUSB_ASYNC_REPORT
,
297 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
298 1, 1, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
299 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
307 /* Default min/max xy are the raw values, override if using hw-calib */
309 input_set_abs_params(usbtouch
->input
, ABS_X
, 0, 0xffff, 0, 0);
310 input_set_abs_params(usbtouch
->input
, ABS_Y
, 0, 0xffff, 0, 0);
318 /*****************************************************************************
321 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
322 static int itm_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
326 * ITM devices report invalid x/y data if not touched.
327 * if the screen was touched before but is not touched any more
328 * report touch as 0 with the last valid x/y data once. then stop
329 * reporting data until touched again.
331 dev
->press
= ((pkt
[2] & 0x01) << 7) | (pkt
[5] & 0x7F);
333 touch
= ~pkt
[7] & 0x20;
343 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[3] & 0x7F);
344 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[4] & 0x7F);
352 /*****************************************************************************
355 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
359 static int eturbo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
363 /* packets should start with sync */
364 if (!(pkt
[0] & 0x80))
367 shift
= (6 - (pkt
[0] & 0x03));
368 dev
->x
= ((pkt
[3] << 7) | pkt
[4]) >> shift
;
369 dev
->y
= ((pkt
[1] << 7) | pkt
[2]) >> shift
;
370 dev
->touch
= (pkt
[0] & 0x10) ? 1 : 0;
375 static int eturbo_get_pkt_len(unsigned char *buf
, int len
)
386 /*****************************************************************************
389 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
390 static int gunze_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
392 if (!(pkt
[0] & 0x80) || ((pkt
[1] | pkt
[2] | pkt
[3]) & 0x80))
395 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[2] & 0x7F);
396 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[3] & 0x7F);
397 dev
->touch
= pkt
[0] & 0x20;
403 /*****************************************************************************
406 * Documentation about the controller and it's protocol can be found at
407 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
408 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
410 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
412 /* supported data rates. currently using 130 */
413 #define TSC10_RATE_POINT 0x50
414 #define TSC10_RATE_30 0x40
415 #define TSC10_RATE_50 0x41
416 #define TSC10_RATE_80 0x42
417 #define TSC10_RATE_100 0x43
418 #define TSC10_RATE_130 0x44
419 #define TSC10_RATE_150 0x45
422 #define TSC10_CMD_RESET 0x55
423 #define TSC10_CMD_RATE 0x05
424 #define TSC10_CMD_DATA1 0x01
426 static int dmc_tsc10_init(struct usbtouch_usb
*usbtouch
)
428 struct usb_device
*dev
= usbtouch
->udev
;
432 buf
= kmalloc(2, GFP_KERNEL
);
436 buf
[0] = buf
[1] = 0xFF;
437 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
439 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
440 0, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
443 if (buf
[0] != 0x06) {
448 /* set coordinate output rate */
449 buf
[0] = buf
[1] = 0xFF;
450 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
452 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
453 TSC10_RATE_150
, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
456 if ((buf
[0] != 0x06) && (buf
[0] != 0x15 || buf
[1] != 0x01)) {
461 /* start sending data */
462 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
464 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
465 0, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
473 static int dmc_tsc10_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
475 dev
->x
= ((pkt
[2] & 0x03) << 8) | pkt
[1];
476 dev
->y
= ((pkt
[4] & 0x03) << 8) | pkt
[3];
477 dev
->touch
= pkt
[0] & 0x01;
484 /*****************************************************************************
487 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
488 static int irtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
490 dev
->x
= (pkt
[3] << 8) | pkt
[2];
491 dev
->y
= (pkt
[5] << 8) | pkt
[4];
492 dev
->touch
= (pkt
[1] & 0x03) ? 1 : 0;
499 /*****************************************************************************
500 * IdealTEK URTC1000 Part
502 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
506 static int idealtek_get_pkt_len(unsigned char *buf
, int len
)
515 static int idealtek_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
517 switch (pkt
[0] & 0x98) {
519 /* touch data in IdealTEK mode */
520 dev
->x
= (pkt
[1] << 5) | (pkt
[2] >> 2);
521 dev
->y
= (pkt
[3] << 5) | (pkt
[4] >> 2);
522 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
526 /* touch data in MT emulation mode */
527 dev
->x
= (pkt
[2] << 5) | (pkt
[1] >> 2);
528 dev
->y
= (pkt
[4] << 5) | (pkt
[3] >> 2);
529 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
538 /*****************************************************************************
541 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
542 static int general_touch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
544 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1] ;
545 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3] ;
546 dev
->press
= pkt
[5] & 0xff;
547 dev
->touch
= pkt
[0] & 0x01;
553 /*****************************************************************************
556 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
557 static int gotop_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
559 dev
->x
= ((pkt
[1] & 0x38) << 4) | pkt
[2];
560 dev
->y
= ((pkt
[1] & 0x07) << 7) | pkt
[3];
561 dev
->touch
= pkt
[0] & 0x01;
567 /*****************************************************************************
568 * the different device descriptors
571 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
572 unsigned char *pkt
, int len
);
575 static struct usbtouch_device_info usbtouch_dev_info
[] = {
576 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
583 .process_pkt
= usbtouch_process_multi
,
584 .get_pkt_len
= egalax_get_pkt_len
,
585 .read_data
= egalax_read_data
,
589 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
596 .read_data
= panjit_read_data
,
600 #ifdef CONFIG_TOUCHSCREEN_USB_3M
607 .read_data
= mtouch_read_data
,
612 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
620 .read_data
= itm_read_data
,
624 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
631 .process_pkt
= usbtouch_process_multi
,
632 .get_pkt_len
= eturbo_get_pkt_len
,
633 .read_data
= eturbo_read_data
,
637 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
644 .read_data
= gunze_read_data
,
648 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
649 [DEVTYPE_DMC_TSC10
] = {
655 .init
= dmc_tsc10_init
,
656 .read_data
= dmc_tsc10_read_data
,
660 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
661 [DEVTYPE_IRTOUCH
] = {
667 .read_data
= irtouch_read_data
,
671 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
672 [DEVTYPE_IDEALTEK
] = {
678 .process_pkt
= usbtouch_process_multi
,
679 .get_pkt_len
= idealtek_get_pkt_len
,
680 .read_data
= idealtek_read_data
,
684 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
685 [DEVTYPE_GENERAL_TOUCH
] = {
691 .read_data
= general_touch_read_data
,
695 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
702 .read_data
= gotop_read_data
,
708 /*****************************************************************************
711 static void usbtouch_process_pkt(struct usbtouch_usb
*usbtouch
,
712 unsigned char *pkt
, int len
)
714 struct usbtouch_device_info
*type
= usbtouch
->type
;
716 if (!type
->read_data(usbtouch
, pkt
))
719 input_report_key(usbtouch
->input
, BTN_TOUCH
, usbtouch
->touch
);
722 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->y
);
723 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->x
);
725 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->x
);
726 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->y
);
729 input_report_abs(usbtouch
->input
, ABS_PRESSURE
, usbtouch
->press
);
730 input_sync(usbtouch
->input
);
735 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
736 unsigned char *pkt
, int len
)
738 unsigned char *buffer
;
739 int pkt_len
, pos
, buf_len
, tmp
;
742 if (unlikely(usbtouch
->buf_len
)) {
743 /* try to get size */
744 pkt_len
= usbtouch
->type
->get_pkt_len(
745 usbtouch
->buffer
, usbtouch
->buf_len
);
748 if (unlikely(!pkt_len
))
751 /* need to append -pkt_len bytes before able to get size */
752 if (unlikely(pkt_len
< 0)) {
753 int append
= -pkt_len
;
754 if (unlikely(append
> len
))
756 if (usbtouch
->buf_len
+ append
>= usbtouch
->type
->rept_size
)
758 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, append
);
759 usbtouch
->buf_len
+= append
;
761 pkt_len
= usbtouch
->type
->get_pkt_len(
762 usbtouch
->buffer
, usbtouch
->buf_len
);
768 tmp
= pkt_len
- usbtouch
->buf_len
;
769 if (usbtouch
->buf_len
+ tmp
>= usbtouch
->type
->rept_size
)
771 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, tmp
);
772 usbtouch_process_pkt(usbtouch
, usbtouch
->buffer
, pkt_len
);
781 /* loop over the received packet, process */
783 while (pos
< buf_len
) {
785 pkt_len
= usbtouch
->type
->get_pkt_len(buffer
+ pos
,
788 /* unknown packet: skip one byte */
789 if (unlikely(!pkt_len
)) {
794 /* full packet: process */
795 if (likely((pkt_len
> 0) && (pkt_len
<= buf_len
- pos
))) {
796 usbtouch_process_pkt(usbtouch
, buffer
+ pos
, pkt_len
);
798 /* incomplete packet: save in buffer */
799 memcpy(usbtouch
->buffer
, buffer
+ pos
, buf_len
- pos
);
800 usbtouch
->buf_len
= buf_len
- pos
;
807 usbtouch
->buf_len
= 0;
813 static void usbtouch_irq(struct urb
*urb
)
815 struct usbtouch_usb
*usbtouch
= urb
->context
;
818 switch (urb
->status
) {
823 /* this urb is timing out */
824 dbg("%s - urb timed out - was the device unplugged?",
830 /* this urb is terminated, clean up */
831 dbg("%s - urb shutting down with status: %d",
832 __func__
, urb
->status
);
835 dbg("%s - nonzero urb status received: %d",
836 __func__
, urb
->status
);
840 usbtouch
->type
->process_pkt(usbtouch
, usbtouch
->data
, urb
->actual_length
);
843 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
845 err("%s - usb_submit_urb failed with result: %d",
849 static int usbtouch_open(struct input_dev
*input
)
851 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
853 usbtouch
->irq
->dev
= usbtouch
->udev
;
855 if (usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
))
861 static void usbtouch_close(struct input_dev
*input
)
863 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
865 usb_kill_urb(usbtouch
->irq
);
869 static void usbtouch_free_buffers(struct usb_device
*udev
,
870 struct usbtouch_usb
*usbtouch
)
872 usb_buffer_free(udev
, usbtouch
->type
->rept_size
,
873 usbtouch
->data
, usbtouch
->data_dma
);
874 kfree(usbtouch
->buffer
);
878 static int usbtouch_probe(struct usb_interface
*intf
,
879 const struct usb_device_id
*id
)
881 struct usbtouch_usb
*usbtouch
;
882 struct input_dev
*input_dev
;
883 struct usb_host_interface
*interface
;
884 struct usb_endpoint_descriptor
*endpoint
;
885 struct usb_device
*udev
= interface_to_usbdev(intf
);
886 struct usbtouch_device_info
*type
;
889 /* some devices are ignored */
890 if (id
->driver_info
== DEVTYPE_IGNORE
)
893 interface
= intf
->cur_altsetting
;
894 endpoint
= &interface
->endpoint
[0].desc
;
896 usbtouch
= kzalloc(sizeof(struct usbtouch_usb
), GFP_KERNEL
);
897 input_dev
= input_allocate_device();
898 if (!usbtouch
|| !input_dev
)
901 type
= &usbtouch_dev_info
[id
->driver_info
];
902 usbtouch
->type
= type
;
903 if (!type
->process_pkt
)
904 type
->process_pkt
= usbtouch_process_pkt
;
906 usbtouch
->data
= usb_buffer_alloc(udev
, type
->rept_size
,
907 GFP_KERNEL
, &usbtouch
->data_dma
);
911 if (type
->get_pkt_len
) {
912 usbtouch
->buffer
= kmalloc(type
->rept_size
, GFP_KERNEL
);
913 if (!usbtouch
->buffer
)
914 goto out_free_buffers
;
917 usbtouch
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
918 if (!usbtouch
->irq
) {
919 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__
);
920 goto out_free_buffers
;
923 usbtouch
->udev
= udev
;
924 usbtouch
->input
= input_dev
;
926 if (udev
->manufacturer
)
927 strlcpy(usbtouch
->name
, udev
->manufacturer
, sizeof(usbtouch
->name
));
930 if (udev
->manufacturer
)
931 strlcat(usbtouch
->name
, " ", sizeof(usbtouch
->name
));
932 strlcat(usbtouch
->name
, udev
->product
, sizeof(usbtouch
->name
));
935 if (!strlen(usbtouch
->name
))
936 snprintf(usbtouch
->name
, sizeof(usbtouch
->name
),
937 "USB Touchscreen %04x:%04x",
938 le16_to_cpu(udev
->descriptor
.idVendor
),
939 le16_to_cpu(udev
->descriptor
.idProduct
));
941 usb_make_path(udev
, usbtouch
->phys
, sizeof(usbtouch
->phys
));
942 strlcat(usbtouch
->phys
, "/input0", sizeof(usbtouch
->phys
));
944 input_dev
->name
= usbtouch
->name
;
945 input_dev
->phys
= usbtouch
->phys
;
946 usb_to_input_id(udev
, &input_dev
->id
);
947 input_dev
->dev
.parent
= &intf
->dev
;
949 input_set_drvdata(input_dev
, usbtouch
);
951 input_dev
->open
= usbtouch_open
;
952 input_dev
->close
= usbtouch_close
;
954 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
955 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
956 input_set_abs_params(input_dev
, ABS_X
, type
->min_xc
, type
->max_xc
, 0, 0);
957 input_set_abs_params(input_dev
, ABS_Y
, type
->min_yc
, type
->max_yc
, 0, 0);
959 input_set_abs_params(input_dev
, ABS_PRESSURE
, type
->min_press
,
960 type
->max_press
, 0, 0);
962 usb_fill_int_urb(usbtouch
->irq
, usbtouch
->udev
,
963 usb_rcvintpipe(usbtouch
->udev
, endpoint
->bEndpointAddress
),
964 usbtouch
->data
, type
->rept_size
,
965 usbtouch_irq
, usbtouch
, endpoint
->bInterval
);
967 usbtouch
->irq
->dev
= usbtouch
->udev
;
968 usbtouch
->irq
->transfer_dma
= usbtouch
->data_dma
;
969 usbtouch
->irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
971 /* device specific init */
973 err
= type
->init(usbtouch
);
975 dbg("%s - type->init() failed, err: %d", __func__
, err
);
976 goto out_free_buffers
;
980 err
= input_register_device(usbtouch
->input
);
982 dbg("%s - input_register_device failed, err: %d", __func__
, err
);
983 goto out_free_buffers
;
986 usb_set_intfdata(intf
, usbtouch
);
991 usbtouch_free_buffers(udev
, usbtouch
);
993 input_free_device(input_dev
);
998 static void usbtouch_disconnect(struct usb_interface
*intf
)
1000 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1002 dbg("%s - called", __func__
);
1007 dbg("%s - usbtouch is initialized, cleaning up", __func__
);
1008 usb_set_intfdata(intf
, NULL
);
1009 usb_kill_urb(usbtouch
->irq
);
1010 input_unregister_device(usbtouch
->input
);
1011 usb_free_urb(usbtouch
->irq
);
1012 usbtouch_free_buffers(interface_to_usbdev(intf
), usbtouch
);
1016 MODULE_DEVICE_TABLE(usb
, usbtouch_devices
);
1018 static struct usb_driver usbtouch_driver
= {
1019 .name
= "usbtouchscreen",
1020 .probe
= usbtouch_probe
,
1021 .disconnect
= usbtouch_disconnect
,
1022 .id_table
= usbtouch_devices
,
1025 static int __init
usbtouch_init(void)
1027 return usb_register(&usbtouch_driver
);
1030 static void __exit
usbtouch_cleanup(void)
1032 usb_deregister(&usbtouch_driver
);
1035 module_init(usbtouch_init
);
1036 module_exit(usbtouch_cleanup
);
1038 MODULE_AUTHOR(DRIVER_AUTHOR
);
1039 MODULE_DESCRIPTION(DRIVER_DESC
);
1040 MODULE_LICENSE("GPL");
1042 MODULE_ALIAS("touchkitusb");
1043 MODULE_ALIAS("itmtouch");
1044 MODULE_ALIAS("mtouchusb");