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 * Copyright (C) 2004-2006 by Daniel Ritz <daniel.ritz@gmx.ch>
16 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of the
21 * License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 * Driver is based on touchkitusb.c
33 * - ITM parts are from itmtouch.c
34 * - 3M parts are from mtouchusb.c
35 * - PanJit parts are from an unmerged driver by Lanslott Gish
36 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
37 * driver from Marius Vollmer
39 *****************************************************************************/
43 #include <linux/kernel.h>
44 #include <linux/slab.h>
45 #include <linux/input.h>
46 #include <linux/module.h>
47 #include <linux/init.h>
48 #include <linux/usb.h>
49 #include <linux/usb/input.h>
52 #define DRIVER_VERSION "v0.5"
53 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
54 #define DRIVER_DESC "USB Touchscreen Driver"
57 module_param(swap_xy
, bool, 0644);
58 MODULE_PARM_DESC(swap_xy
, "If set X and Y axes are swapped.");
60 /* device specifc data/functions */
62 struct usbtouch_device_info
{
65 int min_press
, max_press
;
69 void (*process_pkt
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
, int len
);
70 int (*get_pkt_len
) (unsigned char *pkt
, int len
);
71 int (*read_data
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
);
72 int (*init
) (struct usbtouch_usb
*usbtouch
);
75 #define USBTOUCH_FLG_BUFFER 0x01
78 /* a usbtouch device */
82 unsigned char *buffer
;
85 struct usb_device
*udev
;
86 struct input_dev
*input
;
87 struct usbtouch_device_info
*type
;
96 #if defined(CONFIG_TOUCHSCREEN_USB_EGALAX) || defined(CONFIG_TOUCHSCREEN_USB_ETURBO) || defined(CONFIG_TOUCHSCREEN_USB_IDEALTEK)
101 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
102 unsigned char *pkt
, int len
);
117 DEVTYPE_GENERAL_TOUCH
,
120 static struct usb_device_id usbtouch_devices
[] = {
121 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
122 {USB_DEVICE(0x3823, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
123 {USB_DEVICE(0x3823, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
124 {USB_DEVICE(0x0123, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
125 {USB_DEVICE(0x0eef, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
126 {USB_DEVICE(0x0eef, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
127 {USB_DEVICE(0x1234, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
128 {USB_DEVICE(0x1234, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
131 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
132 {USB_DEVICE(0x134c, 0x0001), .driver_info
= DEVTYPE_PANJIT
},
133 {USB_DEVICE(0x134c, 0x0002), .driver_info
= DEVTYPE_PANJIT
},
134 {USB_DEVICE(0x134c, 0x0003), .driver_info
= DEVTYPE_PANJIT
},
135 {USB_DEVICE(0x134c, 0x0004), .driver_info
= DEVTYPE_PANJIT
},
138 #ifdef CONFIG_TOUCHSCREEN_USB_3M
139 {USB_DEVICE(0x0596, 0x0001), .driver_info
= DEVTYPE_3M
},
142 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
143 {USB_DEVICE(0x0403, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
146 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
147 {USB_DEVICE(0x1234, 0x5678), .driver_info
= DEVTYPE_ETURBO
},
150 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
151 {USB_DEVICE(0x0637, 0x0001), .driver_info
= DEVTYPE_GUNZE
},
154 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
155 {USB_DEVICE(0x0afa, 0x03e8), .driver_info
= DEVTYPE_DMC_TSC10
},
158 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
159 {USB_DEVICE(0x595a, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
160 {USB_DEVICE(0x6615, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
163 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
164 {USB_DEVICE(0x1391, 0x1000), .driver_info
= DEVTYPE_IDEALTEK
},
167 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
168 {USB_DEVICE(0x0dfc, 0x0001), .driver_info
= DEVTYPE_GENERAL_TOUCH
},
175 /*****************************************************************************
179 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
181 #define EGALAX_PKT_TYPE_MASK 0xFE
182 #define EGALAX_PKT_TYPE_REPT 0x80
183 #define EGALAX_PKT_TYPE_DIAG 0x0A
185 static int egalax_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
187 if ((pkt
[0] & EGALAX_PKT_TYPE_MASK
) != EGALAX_PKT_TYPE_REPT
)
190 dev
->x
= ((pkt
[3] & 0x0F) << 7) | (pkt
[4] & 0x7F);
191 dev
->y
= ((pkt
[1] & 0x0F) << 7) | (pkt
[2] & 0x7F);
192 dev
->touch
= pkt
[0] & 0x01;
197 static int egalax_get_pkt_len(unsigned char *buf
, int len
)
199 switch (buf
[0] & EGALAX_PKT_TYPE_MASK
) {
200 case EGALAX_PKT_TYPE_REPT
:
203 case EGALAX_PKT_TYPE_DIAG
:
215 /*****************************************************************************
218 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
219 static int panjit_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
221 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
222 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
223 dev
->touch
= pkt
[0] & 0x01;
230 /*****************************************************************************
233 #ifdef CONFIG_TOUCHSCREEN_USB_3M
235 #define MTOUCHUSB_ASYNC_REPORT 1
236 #define MTOUCHUSB_RESET 7
237 #define MTOUCHUSB_REQ_CTRLLR_ID 10
239 static int mtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
241 dev
->x
= (pkt
[8] << 8) | pkt
[7];
242 dev
->y
= (pkt
[10] << 8) | pkt
[9];
243 dev
->touch
= (pkt
[2] & 0x40) ? 1 : 0;
248 static int mtouch_init(struct usbtouch_usb
*usbtouch
)
252 ret
= usb_control_msg(usbtouch
->udev
, usb_rcvctrlpipe(usbtouch
->udev
, 0),
254 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
255 1, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
256 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
262 for (i
= 0; i
< 3; i
++) {
263 ret
= usb_control_msg(usbtouch
->udev
, usb_rcvctrlpipe(usbtouch
->udev
, 0),
264 MTOUCHUSB_ASYNC_REPORT
,
265 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
266 1, 1, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
267 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
280 /*****************************************************************************
283 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
284 static int itm_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
288 * ITM devices report invalid x/y data if not touched.
289 * if the screen was touched before but is not touched any more
290 * report touch as 0 with the last valid x/y data once. then stop
291 * reporting data until touched again.
293 dev
->press
= ((pkt
[2] & 0x01) << 7) | (pkt
[5] & 0x7F);
295 touch
= ~pkt
[7] & 0x20;
305 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[3] & 0x7F);
306 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[4] & 0x7F);
314 /*****************************************************************************
317 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
318 static int eturbo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
322 /* packets should start with sync */
323 if (!(pkt
[0] & 0x80))
326 shift
= (6 - (pkt
[0] & 0x03));
327 dev
->x
= ((pkt
[3] << 7) | pkt
[4]) >> shift
;
328 dev
->y
= ((pkt
[1] << 7) | pkt
[2]) >> shift
;
329 dev
->touch
= (pkt
[0] & 0x10) ? 1 : 0;
334 static int eturbo_get_pkt_len(unsigned char *buf
, int len
)
345 /*****************************************************************************
348 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
349 static int gunze_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
351 if (!(pkt
[0] & 0x80) || ((pkt
[1] | pkt
[2] | pkt
[3]) & 0x80))
354 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[2] & 0x7F);
355 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[3] & 0x7F);
356 dev
->touch
= pkt
[0] & 0x20;
362 /*****************************************************************************
365 * Documentation about the controller and it's protocol can be found at
366 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
367 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
369 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
371 /* supported data rates. currently using 130 */
372 #define TSC10_RATE_POINT 0x50
373 #define TSC10_RATE_30 0x40
374 #define TSC10_RATE_50 0x41
375 #define TSC10_RATE_80 0x42
376 #define TSC10_RATE_100 0x43
377 #define TSC10_RATE_130 0x44
378 #define TSC10_RATE_150 0x45
381 #define TSC10_CMD_RESET 0x55
382 #define TSC10_CMD_RATE 0x05
383 #define TSC10_CMD_DATA1 0x01
385 static int dmc_tsc10_init(struct usbtouch_usb
*usbtouch
)
387 struct usb_device
*dev
= usbtouch
->udev
;
389 unsigned char buf
[2];
392 buf
[0] = buf
[1] = 0xFF;
393 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
395 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
396 0, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
399 if (buf
[0] != 0x06 || buf
[1] != 0x00)
402 /* set coordinate output rate */
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 TSC10_RATE_150
, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
410 if ((buf
[0] != 0x06 || buf
[1] != 0x00) &&
411 (buf
[0] != 0x15 || buf
[1] != 0x01))
414 /* start sending data */
415 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
417 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
418 0, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
426 static int dmc_tsc10_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
428 dev
->x
= ((pkt
[2] & 0x03) << 8) | pkt
[1];
429 dev
->y
= ((pkt
[4] & 0x03) << 8) | pkt
[3];
430 dev
->touch
= pkt
[0] & 0x01;
437 /*****************************************************************************
440 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
441 static int irtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
443 dev
->x
= (pkt
[3] << 8) | pkt
[2];
444 dev
->y
= (pkt
[5] << 8) | pkt
[4];
445 dev
->touch
= (pkt
[1] & 0x03) ? 1 : 0;
452 /*****************************************************************************
453 * IdealTEK URTC1000 Part
455 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
456 static int idealtek_get_pkt_len(unsigned char *buf
, int len
)
465 static int idealtek_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
467 switch (pkt
[0] & 0x98) {
469 /* touch data in IdealTEK mode */
470 dev
->x
= (pkt
[1] << 5) | (pkt
[2] >> 2);
471 dev
->y
= (pkt
[3] << 5) | (pkt
[4] >> 2);
472 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
476 /* touch data in MT emulation mode */
477 dev
->x
= (pkt
[2] << 5) | (pkt
[1] >> 2);
478 dev
->y
= (pkt
[4] << 5) | (pkt
[3] >> 2);
479 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
488 /*****************************************************************************
491 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
492 static int general_touch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
494 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1] ;
495 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3] ;
496 dev
->press
= pkt
[5] & 0xff;
497 dev
->touch
= pkt
[0] & 0x01;
503 /*****************************************************************************
504 * the different device descriptors
506 static struct usbtouch_device_info usbtouch_dev_info
[] = {
507 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
514 .flags
= USBTOUCH_FLG_BUFFER
,
515 .process_pkt
= usbtouch_process_multi
,
516 .get_pkt_len
= egalax_get_pkt_len
,
517 .read_data
= egalax_read_data
,
521 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
528 .read_data
= panjit_read_data
,
532 #ifdef CONFIG_TOUCHSCREEN_USB_3M
539 .read_data
= mtouch_read_data
,
544 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
552 .read_data
= itm_read_data
,
556 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
563 .flags
= USBTOUCH_FLG_BUFFER
,
564 .process_pkt
= usbtouch_process_multi
,
565 .get_pkt_len
= eturbo_get_pkt_len
,
566 .read_data
= eturbo_read_data
,
570 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
577 .read_data
= gunze_read_data
,
581 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
582 [DEVTYPE_DMC_TSC10
] = {
588 .init
= dmc_tsc10_init
,
589 .read_data
= dmc_tsc10_read_data
,
593 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
594 [DEVTYPE_IRTOUCH
] = {
600 .read_data
= irtouch_read_data
,
604 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
605 [DEVTYPE_IDEALTEK
] = {
611 .flags
= USBTOUCH_FLG_BUFFER
,
612 .process_pkt
= usbtouch_process_multi
,
613 .get_pkt_len
= idealtek_get_pkt_len
,
614 .read_data
= idealtek_read_data
,
618 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
619 [DEVTYPE_GENERAL_TOUCH
] = {
625 .read_data
= general_touch_read_data
,
632 /*****************************************************************************
635 static void usbtouch_process_pkt(struct usbtouch_usb
*usbtouch
,
636 unsigned char *pkt
, int len
)
638 struct usbtouch_device_info
*type
= usbtouch
->type
;
640 if (!type
->read_data(usbtouch
, pkt
))
643 input_report_key(usbtouch
->input
, BTN_TOUCH
, usbtouch
->touch
);
646 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->y
);
647 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->x
);
649 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->x
);
650 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->y
);
653 input_report_abs(usbtouch
->input
, ABS_PRESSURE
, usbtouch
->press
);
654 input_sync(usbtouch
->input
);
659 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
660 unsigned char *pkt
, int len
)
662 unsigned char *buffer
;
663 int pkt_len
, pos
, buf_len
, tmp
;
666 if (unlikely(usbtouch
->buf_len
)) {
667 /* try to get size */
668 pkt_len
= usbtouch
->type
->get_pkt_len(
669 usbtouch
->buffer
, usbtouch
->buf_len
);
672 if (unlikely(!pkt_len
))
675 /* need to append -pkt_len bytes before able to get size */
676 if (unlikely(pkt_len
< 0)) {
677 int append
= -pkt_len
;
678 if (unlikely(append
> len
))
680 if (usbtouch
->buf_len
+ append
>= usbtouch
->type
->rept_size
)
682 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, append
);
683 usbtouch
->buf_len
+= append
;
685 pkt_len
= usbtouch
->type
->get_pkt_len(
686 usbtouch
->buffer
, usbtouch
->buf_len
);
692 tmp
= pkt_len
- usbtouch
->buf_len
;
693 if (usbtouch
->buf_len
+ tmp
>= usbtouch
->type
->rept_size
)
695 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, tmp
);
696 usbtouch_process_pkt(usbtouch
, usbtouch
->buffer
, pkt_len
);
705 /* loop over the received packet, process */
707 while (pos
< buf_len
) {
709 pkt_len
= usbtouch
->type
->get_pkt_len(buffer
+ pos
, len
);
711 /* unknown packet: drop everything */
712 if (unlikely(!pkt_len
))
715 /* full packet: process */
716 if (likely((pkt_len
> 0) && (pkt_len
<= buf_len
- pos
))) {
717 usbtouch_process_pkt(usbtouch
, buffer
+ pos
, pkt_len
);
719 /* incomplete packet: save in buffer */
720 memcpy(usbtouch
->buffer
, buffer
+ pos
, buf_len
- pos
);
721 usbtouch
->buf_len
= buf_len
- pos
;
728 usbtouch
->buf_len
= 0;
734 static void usbtouch_irq(struct urb
*urb
)
736 struct usbtouch_usb
*usbtouch
= urb
->context
;
739 switch (urb
->status
) {
744 /* this urb is timing out */
745 dbg("%s - urb timed out - was the device unplugged?",
751 /* this urb is terminated, clean up */
752 dbg("%s - urb shutting down with status: %d",
753 __FUNCTION__
, urb
->status
);
756 dbg("%s - nonzero urb status received: %d",
757 __FUNCTION__
, urb
->status
);
761 usbtouch
->type
->process_pkt(usbtouch
, usbtouch
->data
, urb
->actual_length
);
764 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
766 err("%s - usb_submit_urb failed with result: %d",
767 __FUNCTION__
, retval
);
770 static int usbtouch_open(struct input_dev
*input
)
772 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
774 usbtouch
->irq
->dev
= usbtouch
->udev
;
776 if (usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
))
782 static void usbtouch_close(struct input_dev
*input
)
784 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
786 usb_kill_urb(usbtouch
->irq
);
790 static void usbtouch_free_buffers(struct usb_device
*udev
,
791 struct usbtouch_usb
*usbtouch
)
793 usb_buffer_free(udev
, usbtouch
->type
->rept_size
,
794 usbtouch
->data
, usbtouch
->data_dma
);
795 kfree(usbtouch
->buffer
);
799 static int usbtouch_probe(struct usb_interface
*intf
,
800 const struct usb_device_id
*id
)
802 struct usbtouch_usb
*usbtouch
;
803 struct input_dev
*input_dev
;
804 struct usb_host_interface
*interface
;
805 struct usb_endpoint_descriptor
*endpoint
;
806 struct usb_device
*udev
= interface_to_usbdev(intf
);
807 struct usbtouch_device_info
*type
;
810 interface
= intf
->cur_altsetting
;
811 endpoint
= &interface
->endpoint
[0].desc
;
813 usbtouch
= kzalloc(sizeof(struct usbtouch_usb
), GFP_KERNEL
);
814 input_dev
= input_allocate_device();
815 if (!usbtouch
|| !input_dev
)
818 type
= &usbtouch_dev_info
[id
->driver_info
];
819 usbtouch
->type
= type
;
820 if (!type
->process_pkt
)
821 type
->process_pkt
= usbtouch_process_pkt
;
823 usbtouch
->data
= usb_buffer_alloc(udev
, type
->rept_size
,
824 GFP_KERNEL
, &usbtouch
->data_dma
);
828 if (type
->flags
& USBTOUCH_FLG_BUFFER
) {
829 usbtouch
->buffer
= kmalloc(type
->rept_size
, GFP_KERNEL
);
830 if (!usbtouch
->buffer
)
831 goto out_free_buffers
;
834 usbtouch
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
835 if (!usbtouch
->irq
) {
836 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __FUNCTION__
);
837 goto out_free_buffers
;
840 usbtouch
->udev
= udev
;
841 usbtouch
->input
= input_dev
;
843 if (udev
->manufacturer
)
844 strlcpy(usbtouch
->name
, udev
->manufacturer
, sizeof(usbtouch
->name
));
847 if (udev
->manufacturer
)
848 strlcat(usbtouch
->name
, " ", sizeof(usbtouch
->name
));
849 strlcat(usbtouch
->name
, udev
->product
, sizeof(usbtouch
->name
));
852 if (!strlen(usbtouch
->name
))
853 snprintf(usbtouch
->name
, sizeof(usbtouch
->name
),
854 "USB Touchscreen %04x:%04x",
855 le16_to_cpu(udev
->descriptor
.idVendor
),
856 le16_to_cpu(udev
->descriptor
.idProduct
));
858 usb_make_path(udev
, usbtouch
->phys
, sizeof(usbtouch
->phys
));
859 strlcat(usbtouch
->phys
, "/input0", sizeof(usbtouch
->phys
));
861 input_dev
->name
= usbtouch
->name
;
862 input_dev
->phys
= usbtouch
->phys
;
863 usb_to_input_id(udev
, &input_dev
->id
);
864 input_dev
->dev
.parent
= &intf
->dev
;
866 input_set_drvdata(input_dev
, usbtouch
);
868 input_dev
->open
= usbtouch_open
;
869 input_dev
->close
= usbtouch_close
;
871 input_dev
->evbit
[0] = BIT(EV_KEY
) | BIT(EV_ABS
);
872 input_dev
->keybit
[LONG(BTN_TOUCH
)] = BIT(BTN_TOUCH
);
873 input_set_abs_params(input_dev
, ABS_X
, type
->min_xc
, type
->max_xc
, 0, 0);
874 input_set_abs_params(input_dev
, ABS_Y
, type
->min_yc
, type
->max_yc
, 0, 0);
876 input_set_abs_params(input_dev
, ABS_PRESSURE
, type
->min_press
,
877 type
->max_press
, 0, 0);
879 usb_fill_int_urb(usbtouch
->irq
, usbtouch
->udev
,
880 usb_rcvintpipe(usbtouch
->udev
, endpoint
->bEndpointAddress
),
881 usbtouch
->data
, type
->rept_size
,
882 usbtouch_irq
, usbtouch
, endpoint
->bInterval
);
884 usbtouch
->irq
->dev
= usbtouch
->udev
;
885 usbtouch
->irq
->transfer_dma
= usbtouch
->data_dma
;
886 usbtouch
->irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
888 /* device specific init */
890 err
= type
->init(usbtouch
);
892 dbg("%s - type->init() failed, err: %d", __FUNCTION__
, err
);
893 goto out_free_buffers
;
897 err
= input_register_device(usbtouch
->input
);
899 dbg("%s - input_register_device failed, err: %d", __FUNCTION__
, err
);
900 goto out_free_buffers
;
903 usb_set_intfdata(intf
, usbtouch
);
908 usbtouch_free_buffers(udev
, usbtouch
);
910 input_free_device(input_dev
);
915 static void usbtouch_disconnect(struct usb_interface
*intf
)
917 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
919 dbg("%s - called", __FUNCTION__
);
924 dbg("%s - usbtouch is initialized, cleaning up", __FUNCTION__
);
925 usb_set_intfdata(intf
, NULL
);
926 usb_kill_urb(usbtouch
->irq
);
927 input_unregister_device(usbtouch
->input
);
928 usb_free_urb(usbtouch
->irq
);
929 usbtouch_free_buffers(interface_to_usbdev(intf
), usbtouch
);
933 MODULE_DEVICE_TABLE(usb
, usbtouch_devices
);
935 static struct usb_driver usbtouch_driver
= {
936 .name
= "usbtouchscreen",
937 .probe
= usbtouch_probe
,
938 .disconnect
= usbtouch_disconnect
,
939 .id_table
= usbtouch_devices
,
942 static int __init
usbtouch_init(void)
944 return usb_register(&usbtouch_driver
);
947 static void __exit
usbtouch_cleanup(void)
949 usb_deregister(&usbtouch_driver
);
952 module_init(usbtouch_init
);
953 module_exit(usbtouch_cleanup
);
955 MODULE_AUTHOR(DRIVER_AUTHOR
);
956 MODULE_DESCRIPTION(DRIVER_DESC
);
957 MODULE_LICENSE("GPL");
959 MODULE_ALIAS("touchkitusb");
960 MODULE_ALIAS("itmtouch");
961 MODULE_ALIAS("mtouchusb");