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>
54 #define DRIVER_VERSION "v0.6"
55 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
56 #define DRIVER_DESC "USB Touchscreen Driver"
59 module_param(swap_xy
, bool, 0644);
60 MODULE_PARM_DESC(swap_xy
, "If set X and Y axes are swapped.");
62 /* device specifc data/functions */
64 struct usbtouch_device_info
{
67 int min_press
, max_press
;
70 void (*process_pkt
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
, int len
);
73 * used to get the packet len. possible return values:
76 * < 0: -return value more bytes needed
78 int (*get_pkt_len
) (unsigned char *pkt
, int len
);
80 int (*read_data
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
);
81 int (*init
) (struct usbtouch_usb
*usbtouch
);
84 /* a usbtouch device */
88 unsigned char *buffer
;
91 struct usb_device
*udev
;
92 struct input_dev
*input
;
93 struct usbtouch_device_info
*type
;
114 DEVTYPE_GENERAL_TOUCH
,
118 static struct usb_device_id usbtouch_devices
[] = {
119 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
120 {USB_DEVICE(0x3823, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
121 {USB_DEVICE(0x3823, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
122 {USB_DEVICE(0x0123, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
123 {USB_DEVICE(0x0eef, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
124 {USB_DEVICE(0x0eef, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
125 {USB_DEVICE(0x1234, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
126 {USB_DEVICE(0x1234, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
129 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
130 {USB_DEVICE(0x134c, 0x0001), .driver_info
= DEVTYPE_PANJIT
},
131 {USB_DEVICE(0x134c, 0x0002), .driver_info
= DEVTYPE_PANJIT
},
132 {USB_DEVICE(0x134c, 0x0003), .driver_info
= DEVTYPE_PANJIT
},
133 {USB_DEVICE(0x134c, 0x0004), .driver_info
= DEVTYPE_PANJIT
},
136 #ifdef CONFIG_TOUCHSCREEN_USB_3M
137 {USB_DEVICE(0x0596, 0x0001), .driver_info
= DEVTYPE_3M
},
140 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
141 {USB_DEVICE(0x0403, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
144 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
145 {USB_DEVICE(0x1234, 0x5678), .driver_info
= DEVTYPE_ETURBO
},
148 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
149 {USB_DEVICE(0x0637, 0x0001), .driver_info
= DEVTYPE_GUNZE
},
152 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
153 {USB_DEVICE(0x0afa, 0x03e8), .driver_info
= DEVTYPE_DMC_TSC10
},
156 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
157 {USB_DEVICE(0x595a, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
158 {USB_DEVICE(0x6615, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
161 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
162 {USB_DEVICE(0x1391, 0x1000), .driver_info
= DEVTYPE_IDEALTEK
},
165 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
166 {USB_DEVICE(0x0dfc, 0x0001), .driver_info
= DEVTYPE_GENERAL_TOUCH
},
169 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
170 {USB_DEVICE(0x08f2, 0x007f), .driver_info
= DEVTYPE_GOTOP
},
171 {USB_DEVICE(0x08f2, 0x00ce), .driver_info
= DEVTYPE_GOTOP
},
172 {USB_DEVICE(0x08f2, 0x00f4), .driver_info
= DEVTYPE_GOTOP
},
179 /*****************************************************************************
183 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
189 #define EGALAX_PKT_TYPE_MASK 0xFE
190 #define EGALAX_PKT_TYPE_REPT 0x80
191 #define EGALAX_PKT_TYPE_DIAG 0x0A
193 static int egalax_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
195 if ((pkt
[0] & EGALAX_PKT_TYPE_MASK
) != EGALAX_PKT_TYPE_REPT
)
198 dev
->x
= ((pkt
[3] & 0x0F) << 7) | (pkt
[4] & 0x7F);
199 dev
->y
= ((pkt
[1] & 0x0F) << 7) | (pkt
[2] & 0x7F);
200 dev
->touch
= pkt
[0] & 0x01;
205 static int egalax_get_pkt_len(unsigned char *buf
, int len
)
207 switch (buf
[0] & EGALAX_PKT_TYPE_MASK
) {
208 case EGALAX_PKT_TYPE_REPT
:
211 case EGALAX_PKT_TYPE_DIAG
:
223 /*****************************************************************************
226 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
227 static int panjit_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
229 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
230 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
231 dev
->touch
= pkt
[0] & 0x01;
238 /*****************************************************************************
241 #ifdef CONFIG_TOUCHSCREEN_USB_3M
243 #define MTOUCHUSB_ASYNC_REPORT 1
244 #define MTOUCHUSB_RESET 7
245 #define MTOUCHUSB_REQ_CTRLLR_ID 10
247 static int mtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
249 dev
->x
= (pkt
[8] << 8) | pkt
[7];
250 dev
->y
= (pkt
[10] << 8) | pkt
[9];
251 dev
->touch
= (pkt
[2] & 0x40) ? 1 : 0;
256 static int mtouch_init(struct usbtouch_usb
*usbtouch
)
260 ret
= usb_control_msg(usbtouch
->udev
, usb_rcvctrlpipe(usbtouch
->udev
, 0),
262 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
263 1, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
264 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
270 for (i
= 0; i
< 3; i
++) {
271 ret
= usb_control_msg(usbtouch
->udev
, usb_rcvctrlpipe(usbtouch
->udev
, 0),
272 MTOUCHUSB_ASYNC_REPORT
,
273 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
274 1, 1, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
275 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
288 /*****************************************************************************
291 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
292 static int itm_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
296 * ITM devices report invalid x/y data if not touched.
297 * if the screen was touched before but is not touched any more
298 * report touch as 0 with the last valid x/y data once. then stop
299 * reporting data until touched again.
301 dev
->press
= ((pkt
[2] & 0x01) << 7) | (pkt
[5] & 0x7F);
303 touch
= ~pkt
[7] & 0x20;
313 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[3] & 0x7F);
314 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[4] & 0x7F);
322 /*****************************************************************************
325 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
329 static int eturbo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
333 /* packets should start with sync */
334 if (!(pkt
[0] & 0x80))
337 shift
= (6 - (pkt
[0] & 0x03));
338 dev
->x
= ((pkt
[3] << 7) | pkt
[4]) >> shift
;
339 dev
->y
= ((pkt
[1] << 7) | pkt
[2]) >> shift
;
340 dev
->touch
= (pkt
[0] & 0x10) ? 1 : 0;
345 static int eturbo_get_pkt_len(unsigned char *buf
, int len
)
356 /*****************************************************************************
359 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
360 static int gunze_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
362 if (!(pkt
[0] & 0x80) || ((pkt
[1] | pkt
[2] | pkt
[3]) & 0x80))
365 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[2] & 0x7F);
366 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[3] & 0x7F);
367 dev
->touch
= pkt
[0] & 0x20;
373 /*****************************************************************************
376 * Documentation about the controller and it's protocol can be found at
377 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
378 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
380 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
382 /* supported data rates. currently using 130 */
383 #define TSC10_RATE_POINT 0x50
384 #define TSC10_RATE_30 0x40
385 #define TSC10_RATE_50 0x41
386 #define TSC10_RATE_80 0x42
387 #define TSC10_RATE_100 0x43
388 #define TSC10_RATE_130 0x44
389 #define TSC10_RATE_150 0x45
392 #define TSC10_CMD_RESET 0x55
393 #define TSC10_CMD_RATE 0x05
394 #define TSC10_CMD_DATA1 0x01
396 static int dmc_tsc10_init(struct usbtouch_usb
*usbtouch
)
398 struct usb_device
*dev
= usbtouch
->udev
;
400 unsigned char buf
[2];
403 buf
[0] = buf
[1] = 0xFF;
404 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
406 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
407 0, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
410 if (buf
[0] != 0x06 || buf
[1] != 0x00)
413 /* set coordinate output rate */
414 buf
[0] = buf
[1] = 0xFF;
415 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
417 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
418 TSC10_RATE_150
, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
421 if ((buf
[0] != 0x06 || buf
[1] != 0x00) &&
422 (buf
[0] != 0x15 || buf
[1] != 0x01))
425 /* start sending data */
426 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
428 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
429 0, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
437 static int dmc_tsc10_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
439 dev
->x
= ((pkt
[2] & 0x03) << 8) | pkt
[1];
440 dev
->y
= ((pkt
[4] & 0x03) << 8) | pkt
[3];
441 dev
->touch
= pkt
[0] & 0x01;
448 /*****************************************************************************
451 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
452 static int irtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
454 dev
->x
= (pkt
[3] << 8) | pkt
[2];
455 dev
->y
= (pkt
[5] << 8) | pkt
[4];
456 dev
->touch
= (pkt
[1] & 0x03) ? 1 : 0;
463 /*****************************************************************************
464 * IdealTEK URTC1000 Part
466 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
470 static int idealtek_get_pkt_len(unsigned char *buf
, int len
)
479 static int idealtek_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
481 switch (pkt
[0] & 0x98) {
483 /* touch data in IdealTEK mode */
484 dev
->x
= (pkt
[1] << 5) | (pkt
[2] >> 2);
485 dev
->y
= (pkt
[3] << 5) | (pkt
[4] >> 2);
486 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
490 /* touch data in MT emulation mode */
491 dev
->x
= (pkt
[2] << 5) | (pkt
[1] >> 2);
492 dev
->y
= (pkt
[4] << 5) | (pkt
[3] >> 2);
493 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
502 /*****************************************************************************
505 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
506 static int general_touch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
508 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1] ;
509 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3] ;
510 dev
->press
= pkt
[5] & 0xff;
511 dev
->touch
= pkt
[0] & 0x01;
517 /*****************************************************************************
520 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
521 static int gotop_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
523 dev
->x
= ((pkt
[1] & 0x38) << 4) | pkt
[2];
524 dev
->y
= ((pkt
[1] & 0x07) << 7) | pkt
[3];
525 dev
->touch
= pkt
[0] & 0x01;
531 /*****************************************************************************
532 * the different device descriptors
535 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
536 unsigned char *pkt
, int len
);
539 static struct usbtouch_device_info usbtouch_dev_info
[] = {
540 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
547 .process_pkt
= usbtouch_process_multi
,
548 .get_pkt_len
= egalax_get_pkt_len
,
549 .read_data
= egalax_read_data
,
553 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
560 .read_data
= panjit_read_data
,
564 #ifdef CONFIG_TOUCHSCREEN_USB_3M
571 .read_data
= mtouch_read_data
,
576 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
584 .read_data
= itm_read_data
,
588 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
595 .process_pkt
= usbtouch_process_multi
,
596 .get_pkt_len
= eturbo_get_pkt_len
,
597 .read_data
= eturbo_read_data
,
601 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
608 .read_data
= gunze_read_data
,
612 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
613 [DEVTYPE_DMC_TSC10
] = {
619 .init
= dmc_tsc10_init
,
620 .read_data
= dmc_tsc10_read_data
,
624 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
625 [DEVTYPE_IRTOUCH
] = {
631 .read_data
= irtouch_read_data
,
635 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
636 [DEVTYPE_IDEALTEK
] = {
642 .process_pkt
= usbtouch_process_multi
,
643 .get_pkt_len
= idealtek_get_pkt_len
,
644 .read_data
= idealtek_read_data
,
648 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
649 [DEVTYPE_GENERAL_TOUCH
] = {
655 .read_data
= general_touch_read_data
,
659 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
666 .read_data
= gotop_read_data
,
672 /*****************************************************************************
675 static void usbtouch_process_pkt(struct usbtouch_usb
*usbtouch
,
676 unsigned char *pkt
, int len
)
678 struct usbtouch_device_info
*type
= usbtouch
->type
;
680 if (!type
->read_data(usbtouch
, pkt
))
683 input_report_key(usbtouch
->input
, BTN_TOUCH
, usbtouch
->touch
);
686 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->y
);
687 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->x
);
689 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->x
);
690 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->y
);
693 input_report_abs(usbtouch
->input
, ABS_PRESSURE
, usbtouch
->press
);
694 input_sync(usbtouch
->input
);
699 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
700 unsigned char *pkt
, int len
)
702 unsigned char *buffer
;
703 int pkt_len
, pos
, buf_len
, tmp
;
706 if (unlikely(usbtouch
->buf_len
)) {
707 /* try to get size */
708 pkt_len
= usbtouch
->type
->get_pkt_len(
709 usbtouch
->buffer
, usbtouch
->buf_len
);
712 if (unlikely(!pkt_len
))
715 /* need to append -pkt_len bytes before able to get size */
716 if (unlikely(pkt_len
< 0)) {
717 int append
= -pkt_len
;
718 if (unlikely(append
> len
))
720 if (usbtouch
->buf_len
+ append
>= usbtouch
->type
->rept_size
)
722 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, append
);
723 usbtouch
->buf_len
+= append
;
725 pkt_len
= usbtouch
->type
->get_pkt_len(
726 usbtouch
->buffer
, usbtouch
->buf_len
);
732 tmp
= pkt_len
- usbtouch
->buf_len
;
733 if (usbtouch
->buf_len
+ tmp
>= usbtouch
->type
->rept_size
)
735 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, tmp
);
736 usbtouch_process_pkt(usbtouch
, usbtouch
->buffer
, pkt_len
);
745 /* loop over the received packet, process */
747 while (pos
< buf_len
) {
749 pkt_len
= usbtouch
->type
->get_pkt_len(buffer
+ pos
,
752 /* unknown packet: skip one byte */
753 if (unlikely(!pkt_len
)) {
758 /* full packet: process */
759 if (likely((pkt_len
> 0) && (pkt_len
<= buf_len
- pos
))) {
760 usbtouch_process_pkt(usbtouch
, buffer
+ pos
, pkt_len
);
762 /* incomplete packet: save in buffer */
763 memcpy(usbtouch
->buffer
, buffer
+ pos
, buf_len
- pos
);
764 usbtouch
->buf_len
= buf_len
- pos
;
771 usbtouch
->buf_len
= 0;
777 static void usbtouch_irq(struct urb
*urb
)
779 struct usbtouch_usb
*usbtouch
= urb
->context
;
782 switch (urb
->status
) {
787 /* this urb is timing out */
788 dbg("%s - urb timed out - was the device unplugged?",
794 /* this urb is terminated, clean up */
795 dbg("%s - urb shutting down with status: %d",
796 __FUNCTION__
, urb
->status
);
799 dbg("%s - nonzero urb status received: %d",
800 __FUNCTION__
, urb
->status
);
804 usbtouch
->type
->process_pkt(usbtouch
, usbtouch
->data
, urb
->actual_length
);
807 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
809 err("%s - usb_submit_urb failed with result: %d",
810 __FUNCTION__
, retval
);
813 static int usbtouch_open(struct input_dev
*input
)
815 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
817 usbtouch
->irq
->dev
= usbtouch
->udev
;
819 if (usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
))
825 static void usbtouch_close(struct input_dev
*input
)
827 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
829 usb_kill_urb(usbtouch
->irq
);
833 static void usbtouch_free_buffers(struct usb_device
*udev
,
834 struct usbtouch_usb
*usbtouch
)
836 usb_buffer_free(udev
, usbtouch
->type
->rept_size
,
837 usbtouch
->data
, usbtouch
->data_dma
);
838 kfree(usbtouch
->buffer
);
842 static int usbtouch_probe(struct usb_interface
*intf
,
843 const struct usb_device_id
*id
)
845 struct usbtouch_usb
*usbtouch
;
846 struct input_dev
*input_dev
;
847 struct usb_host_interface
*interface
;
848 struct usb_endpoint_descriptor
*endpoint
;
849 struct usb_device
*udev
= interface_to_usbdev(intf
);
850 struct usbtouch_device_info
*type
;
853 interface
= intf
->cur_altsetting
;
854 endpoint
= &interface
->endpoint
[0].desc
;
856 usbtouch
= kzalloc(sizeof(struct usbtouch_usb
), GFP_KERNEL
);
857 input_dev
= input_allocate_device();
858 if (!usbtouch
|| !input_dev
)
861 type
= &usbtouch_dev_info
[id
->driver_info
];
862 usbtouch
->type
= type
;
863 if (!type
->process_pkt
)
864 type
->process_pkt
= usbtouch_process_pkt
;
866 usbtouch
->data
= usb_buffer_alloc(udev
, type
->rept_size
,
867 GFP_KERNEL
, &usbtouch
->data_dma
);
871 if (type
->get_pkt_len
) {
872 usbtouch
->buffer
= kmalloc(type
->rept_size
, GFP_KERNEL
);
873 if (!usbtouch
->buffer
)
874 goto out_free_buffers
;
877 usbtouch
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
878 if (!usbtouch
->irq
) {
879 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __FUNCTION__
);
880 goto out_free_buffers
;
883 usbtouch
->udev
= udev
;
884 usbtouch
->input
= input_dev
;
886 if (udev
->manufacturer
)
887 strlcpy(usbtouch
->name
, udev
->manufacturer
, sizeof(usbtouch
->name
));
890 if (udev
->manufacturer
)
891 strlcat(usbtouch
->name
, " ", sizeof(usbtouch
->name
));
892 strlcat(usbtouch
->name
, udev
->product
, sizeof(usbtouch
->name
));
895 if (!strlen(usbtouch
->name
))
896 snprintf(usbtouch
->name
, sizeof(usbtouch
->name
),
897 "USB Touchscreen %04x:%04x",
898 le16_to_cpu(udev
->descriptor
.idVendor
),
899 le16_to_cpu(udev
->descriptor
.idProduct
));
901 usb_make_path(udev
, usbtouch
->phys
, sizeof(usbtouch
->phys
));
902 strlcat(usbtouch
->phys
, "/input0", sizeof(usbtouch
->phys
));
904 input_dev
->name
= usbtouch
->name
;
905 input_dev
->phys
= usbtouch
->phys
;
906 usb_to_input_id(udev
, &input_dev
->id
);
907 input_dev
->dev
.parent
= &intf
->dev
;
909 input_set_drvdata(input_dev
, usbtouch
);
911 input_dev
->open
= usbtouch_open
;
912 input_dev
->close
= usbtouch_close
;
914 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
915 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
916 input_set_abs_params(input_dev
, ABS_X
, type
->min_xc
, type
->max_xc
, 0, 0);
917 input_set_abs_params(input_dev
, ABS_Y
, type
->min_yc
, type
->max_yc
, 0, 0);
919 input_set_abs_params(input_dev
, ABS_PRESSURE
, type
->min_press
,
920 type
->max_press
, 0, 0);
922 usb_fill_int_urb(usbtouch
->irq
, usbtouch
->udev
,
923 usb_rcvintpipe(usbtouch
->udev
, endpoint
->bEndpointAddress
),
924 usbtouch
->data
, type
->rept_size
,
925 usbtouch_irq
, usbtouch
, endpoint
->bInterval
);
927 usbtouch
->irq
->dev
= usbtouch
->udev
;
928 usbtouch
->irq
->transfer_dma
= usbtouch
->data_dma
;
929 usbtouch
->irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
931 /* device specific init */
933 err
= type
->init(usbtouch
);
935 dbg("%s - type->init() failed, err: %d", __FUNCTION__
, err
);
936 goto out_free_buffers
;
940 err
= input_register_device(usbtouch
->input
);
942 dbg("%s - input_register_device failed, err: %d", __FUNCTION__
, err
);
943 goto out_free_buffers
;
946 usb_set_intfdata(intf
, usbtouch
);
951 usbtouch_free_buffers(udev
, usbtouch
);
953 input_free_device(input_dev
);
958 static void usbtouch_disconnect(struct usb_interface
*intf
)
960 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
962 dbg("%s - called", __FUNCTION__
);
967 dbg("%s - usbtouch is initialized, cleaning up", __FUNCTION__
);
968 usb_set_intfdata(intf
, NULL
);
969 usb_kill_urb(usbtouch
->irq
);
970 input_unregister_device(usbtouch
->input
);
971 usb_free_urb(usbtouch
->irq
);
972 usbtouch_free_buffers(interface_to_usbdev(intf
), usbtouch
);
976 MODULE_DEVICE_TABLE(usb
, usbtouch_devices
);
978 static struct usb_driver usbtouch_driver
= {
979 .name
= "usbtouchscreen",
980 .probe
= usbtouch_probe
,
981 .disconnect
= usbtouch_disconnect
,
982 .id_table
= usbtouch_devices
,
985 static int __init
usbtouch_init(void)
987 return usb_register(&usbtouch_driver
);
990 static void __exit
usbtouch_cleanup(void)
992 usb_deregister(&usbtouch_driver
);
995 module_init(usbtouch_init
);
996 module_exit(usbtouch_cleanup
);
998 MODULE_AUTHOR(DRIVER_AUTHOR
);
999 MODULE_DESCRIPTION(DRIVER_DESC
);
1000 MODULE_LICENSE("GPL");
1002 MODULE_ALIAS("touchkitusb");
1003 MODULE_ALIAS("itmtouch");
1004 MODULE_ALIAS("mtouchusb");