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 * - Elo TouchSystems 2700 IntelliTouch
20 * - EasyTouch USB Dual/Multi touch controller from Data Modul
22 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
23 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License as
27 * published by the Free Software Foundation; either version 2 of the
28 * License, or (at your option) any later version.
30 * This program is distributed in the hope that it will be useful, but
31 * WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 * General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39 * Driver is based on touchkitusb.c
40 * - ITM parts are from itmtouch.c
41 * - 3M parts are from mtouchusb.c
42 * - PanJit parts are from an unmerged driver by Lanslott Gish
43 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
44 * driver from Marius Vollmer
46 *****************************************************************************/
50 #include <linux/kernel.h>
51 #include <linux/slab.h>
52 #include <linux/input.h>
53 #include <linux/module.h>
54 #include <linux/usb.h>
55 #include <linux/usb/input.h>
56 #include <linux/hid.h>
57 #include <linux/mutex.h>
60 module_param(swap_xy
, bool, 0644);
61 MODULE_PARM_DESC(swap_xy
, "If set X and Y axes are swapped.");
63 static bool 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
;
76 * Always service the USB devices irq not just when the input device is
77 * open. This is useful when devices have a watchdog which prevents us
78 * from periodically polling the device. Leave this unset unless your
79 * touchscreen device requires it, as it does consume more of the USB
84 void (*process_pkt
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
, int len
);
87 * used to get the packet len. possible return values:
90 * < 0: -return value more bytes needed
92 int (*get_pkt_len
) (unsigned char *pkt
, int len
);
94 int (*read_data
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
);
95 int (*alloc
) (struct usbtouch_usb
*usbtouch
);
96 int (*init
) (struct usbtouch_usb
*usbtouch
);
97 void (*exit
) (struct usbtouch_usb
*usbtouch
);
100 /* a usbtouch device */
101 struct usbtouch_usb
{
105 unsigned char *buffer
;
108 struct usb_interface
*interface
;
109 struct input_dev
*input
;
110 struct usbtouch_device_info
*type
;
111 struct mutex pm_mutex
; /* serialize access to open/suspend */
133 DEVTYPE_IRTOUCH_HIRES
,
135 DEVTYPE_GENERAL_TOUCH
,
146 #define USB_DEVICE_HID_CLASS(vend, prod) \
147 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
148 | USB_DEVICE_ID_MATCH_DEVICE, \
149 .idVendor = (vend), \
150 .idProduct = (prod), \
151 .bInterfaceClass = USB_INTERFACE_CLASS_HID
153 static const struct usb_device_id usbtouch_devices
[] = {
154 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
155 /* ignore the HID capable devices, handled by usbhid */
156 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info
= DEVTYPE_IGNORE
},
157 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info
= DEVTYPE_IGNORE
},
159 /* normal device IDs */
160 {USB_DEVICE(0x3823, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
161 {USB_DEVICE(0x3823, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
162 {USB_DEVICE(0x0123, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
163 {USB_DEVICE(0x0eef, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
164 {USB_DEVICE(0x0eef, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
165 {USB_DEVICE(0x1234, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
166 {USB_DEVICE(0x1234, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
169 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
170 {USB_DEVICE(0x134c, 0x0001), .driver_info
= DEVTYPE_PANJIT
},
171 {USB_DEVICE(0x134c, 0x0002), .driver_info
= DEVTYPE_PANJIT
},
172 {USB_DEVICE(0x134c, 0x0003), .driver_info
= DEVTYPE_PANJIT
},
173 {USB_DEVICE(0x134c, 0x0004), .driver_info
= DEVTYPE_PANJIT
},
176 #ifdef CONFIG_TOUCHSCREEN_USB_3M
177 {USB_DEVICE(0x0596, 0x0001), .driver_info
= DEVTYPE_3M
},
180 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
181 {USB_DEVICE(0x0403, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
182 {USB_DEVICE(0x16e3, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
185 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
186 {USB_DEVICE(0x1234, 0x5678), .driver_info
= DEVTYPE_ETURBO
},
189 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
190 {USB_DEVICE(0x0637, 0x0001), .driver_info
= DEVTYPE_GUNZE
},
193 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
194 {USB_DEVICE(0x0afa, 0x03e8), .driver_info
= DEVTYPE_DMC_TSC10
},
197 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
198 {USB_DEVICE(0x595a, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
199 {USB_DEVICE(0x6615, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
200 {USB_DEVICE(0x6615, 0x0012), .driver_info
= DEVTYPE_IRTOUCH_HIRES
},
203 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
204 {USB_DEVICE(0x1391, 0x1000), .driver_info
= DEVTYPE_IDEALTEK
},
207 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
208 {USB_DEVICE(0x0dfc, 0x0001), .driver_info
= DEVTYPE_GENERAL_TOUCH
},
211 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
212 {USB_DEVICE(0x08f2, 0x007f), .driver_info
= DEVTYPE_GOTOP
},
213 {USB_DEVICE(0x08f2, 0x00ce), .driver_info
= DEVTYPE_GOTOP
},
214 {USB_DEVICE(0x08f2, 0x00f4), .driver_info
= DEVTYPE_GOTOP
},
217 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
218 {USB_DEVICE(0x0f92, 0x0001), .driver_info
= DEVTYPE_JASTEC
},
221 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
222 {USB_DEVICE(0x1ac7, 0x0001), .driver_info
= DEVTYPE_E2I
},
225 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
226 {USB_DEVICE(0x14c8, 0x0003), .driver_info
= DEVTYPE_ZYTRONIC
},
229 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
231 {USB_DEVICE(0x0664, 0x0309), .driver_info
= DEVTYPE_TC45USB
},
233 {USB_DEVICE(0x0664, 0x0306), .driver_info
= DEVTYPE_TC45USB
},
236 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
237 /* data interface only */
238 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
239 .driver_info
= DEVTYPE_NEXIO
},
240 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
241 .driver_info
= DEVTYPE_NEXIO
},
244 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
245 {USB_DEVICE(0x04e7, 0x0020), .driver_info
= DEVTYPE_ELO
},
248 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
249 {USB_DEVICE(0x7374, 0x0001), .driver_info
= DEVTYPE_ETOUCH
},
256 /*****************************************************************************
260 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
261 static int e2i_init(struct usbtouch_usb
*usbtouch
)
264 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
266 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
267 0x01, 0x02, 0x0000, 0x0081,
268 NULL
, 0, USB_CTRL_SET_TIMEOUT
);
270 dev_dbg(&usbtouch
->interface
->dev
,
271 "%s - usb_control_msg - E2I_RESET - bytes|err: %d\n",
276 static int e2i_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
278 int tmp
= (pkt
[0] << 8) | pkt
[1];
279 dev
->x
= (pkt
[2] << 8) | pkt
[3];
280 dev
->y
= (pkt
[4] << 8) | pkt
[5];
283 dev
->touch
= (tmp
> 0);
284 dev
->press
= (tmp
> 0 ? tmp
: 0);
291 /*****************************************************************************
295 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
301 #define EGALAX_PKT_TYPE_MASK 0xFE
302 #define EGALAX_PKT_TYPE_REPT 0x80
303 #define EGALAX_PKT_TYPE_DIAG 0x0A
305 static int egalax_init(struct usbtouch_usb
*usbtouch
)
309 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
312 * An eGalax diagnostic packet kicks the device into using the right
313 * protocol. We send a "check active" packet. The response will be
314 * read later and ignored.
317 buf
= kmalloc(3, GFP_KERNEL
);
321 buf
[0] = EGALAX_PKT_TYPE_DIAG
;
322 buf
[1] = 1; /* length */
323 buf
[2] = 'A'; /* command - check active */
325 for (i
= 0; i
< 3; i
++) {
326 ret
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
328 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
330 USB_CTRL_SET_TIMEOUT
);
344 static int egalax_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
346 if ((pkt
[0] & EGALAX_PKT_TYPE_MASK
) != EGALAX_PKT_TYPE_REPT
)
349 dev
->x
= ((pkt
[3] & 0x0F) << 7) | (pkt
[4] & 0x7F);
350 dev
->y
= ((pkt
[1] & 0x0F) << 7) | (pkt
[2] & 0x7F);
351 dev
->touch
= pkt
[0] & 0x01;
356 static int egalax_get_pkt_len(unsigned char *buf
, int len
)
358 switch (buf
[0] & EGALAX_PKT_TYPE_MASK
) {
359 case EGALAX_PKT_TYPE_REPT
:
362 case EGALAX_PKT_TYPE_DIAG
:
373 /*****************************************************************************
377 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
383 #define ETOUCH_PKT_TYPE_MASK 0xFE
384 #define ETOUCH_PKT_TYPE_REPT 0x80
385 #define ETOUCH_PKT_TYPE_REPT2 0xB0
386 #define ETOUCH_PKT_TYPE_DIAG 0x0A
388 static int etouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
390 if ((pkt
[0] & ETOUCH_PKT_TYPE_MASK
) != ETOUCH_PKT_TYPE_REPT
&&
391 (pkt
[0] & ETOUCH_PKT_TYPE_MASK
) != ETOUCH_PKT_TYPE_REPT2
)
394 dev
->x
= ((pkt
[1] & 0x1F) << 7) | (pkt
[2] & 0x7F);
395 dev
->y
= ((pkt
[3] & 0x1F) << 7) | (pkt
[4] & 0x7F);
396 dev
->touch
= pkt
[0] & 0x01;
401 static int etouch_get_pkt_len(unsigned char *buf
, int len
)
403 switch (buf
[0] & ETOUCH_PKT_TYPE_MASK
) {
404 case ETOUCH_PKT_TYPE_REPT
:
405 case ETOUCH_PKT_TYPE_REPT2
:
408 case ETOUCH_PKT_TYPE_DIAG
:
419 /*****************************************************************************
422 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
423 static int panjit_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
425 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
426 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
427 dev
->touch
= pkt
[0] & 0x01;
434 /*****************************************************************************
437 #ifdef CONFIG_TOUCHSCREEN_USB_3M
439 #define MTOUCHUSB_ASYNC_REPORT 1
440 #define MTOUCHUSB_RESET 7
441 #define MTOUCHUSB_REQ_CTRLLR_ID 10
443 #define MTOUCHUSB_REQ_CTRLLR_ID_LEN 16
445 static int mtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
448 dev
->x
= (pkt
[4] << 8) | pkt
[3];
449 dev
->y
= 0xffff - ((pkt
[6] << 8) | pkt
[5]);
451 dev
->x
= (pkt
[8] << 8) | pkt
[7];
452 dev
->y
= (pkt
[10] << 8) | pkt
[9];
454 dev
->touch
= (pkt
[2] & 0x40) ? 1 : 0;
464 static ssize_t
mtouch_firmware_rev_show(struct device
*dev
,
465 struct device_attribute
*attr
, char *output
)
467 struct usb_interface
*intf
= to_usb_interface(dev
);
468 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
469 struct mtouch_priv
*priv
= usbtouch
->priv
;
471 return scnprintf(output
, PAGE_SIZE
, "%1x.%1x\n",
472 priv
->fw_rev_major
, priv
->fw_rev_minor
);
474 static DEVICE_ATTR(firmware_rev
, 0444, mtouch_firmware_rev_show
, NULL
);
476 static struct attribute
*mtouch_attrs
[] = {
477 &dev_attr_firmware_rev
.attr
,
481 static const struct attribute_group mtouch_attr_group
= {
482 .attrs
= mtouch_attrs
,
485 static int mtouch_get_fw_revision(struct usbtouch_usb
*usbtouch
)
487 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
488 struct mtouch_priv
*priv
= usbtouch
->priv
;
492 buf
= kzalloc(MTOUCHUSB_REQ_CTRLLR_ID_LEN
, GFP_NOIO
);
496 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
497 MTOUCHUSB_REQ_CTRLLR_ID
,
498 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
499 0, 0, buf
, MTOUCHUSB_REQ_CTRLLR_ID_LEN
,
500 USB_CTRL_SET_TIMEOUT
);
501 if (ret
!= MTOUCHUSB_REQ_CTRLLR_ID_LEN
) {
502 dev_warn(&usbtouch
->interface
->dev
,
503 "Failed to read FW rev: %d\n", ret
);
504 ret
= ret
< 0 ? ret
: -EIO
;
508 priv
->fw_rev_major
= buf
[3];
509 priv
->fw_rev_minor
= buf
[4];
518 static int mtouch_alloc(struct usbtouch_usb
*usbtouch
)
522 usbtouch
->priv
= kmalloc(sizeof(struct mtouch_priv
), GFP_KERNEL
);
526 ret
= sysfs_create_group(&usbtouch
->interface
->dev
.kobj
,
529 kfree(usbtouch
->priv
);
530 usbtouch
->priv
= NULL
;
537 static int mtouch_init(struct usbtouch_usb
*usbtouch
)
540 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
542 ret
= mtouch_get_fw_revision(usbtouch
);
546 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
548 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
549 1, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
550 dev_dbg(&usbtouch
->interface
->dev
,
551 "%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d\n",
557 for (i
= 0; i
< 3; i
++) {
558 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
559 MTOUCHUSB_ASYNC_REPORT
,
560 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
561 1, 1, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
562 dev_dbg(&usbtouch
->interface
->dev
,
563 "%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d\n",
571 /* Default min/max xy are the raw values, override if using hw-calib */
573 input_set_abs_params(usbtouch
->input
, ABS_X
, 0, 0xffff, 0, 0);
574 input_set_abs_params(usbtouch
->input
, ABS_Y
, 0, 0xffff, 0, 0);
580 static void mtouch_exit(struct usbtouch_usb
*usbtouch
)
582 struct mtouch_priv
*priv
= usbtouch
->priv
;
584 sysfs_remove_group(&usbtouch
->interface
->dev
.kobj
, &mtouch_attr_group
);
590 /*****************************************************************************
593 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
594 static int itm_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
598 * ITM devices report invalid x/y data if not touched.
599 * if the screen was touched before but is not touched any more
600 * report touch as 0 with the last valid x/y data once. then stop
601 * reporting data until touched again.
603 dev
->press
= ((pkt
[2] & 0x01) << 7) | (pkt
[5] & 0x7F);
605 touch
= ~pkt
[7] & 0x20;
615 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[3] & 0x7F);
616 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[4] & 0x7F);
624 /*****************************************************************************
627 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
631 static int eturbo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
635 /* packets should start with sync */
636 if (!(pkt
[0] & 0x80))
639 shift
= (6 - (pkt
[0] & 0x03));
640 dev
->x
= ((pkt
[3] << 7) | pkt
[4]) >> shift
;
641 dev
->y
= ((pkt
[1] << 7) | pkt
[2]) >> shift
;
642 dev
->touch
= (pkt
[0] & 0x10) ? 1 : 0;
647 static int eturbo_get_pkt_len(unsigned char *buf
, int len
)
658 /*****************************************************************************
661 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
662 static int gunze_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
664 if (!(pkt
[0] & 0x80) || ((pkt
[1] | pkt
[2] | pkt
[3]) & 0x80))
667 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[2] & 0x7F);
668 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[3] & 0x7F);
669 dev
->touch
= pkt
[0] & 0x20;
675 /*****************************************************************************
678 * Documentation about the controller and it's protocol can be found at
679 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
680 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
682 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
684 /* supported data rates. currently using 130 */
685 #define TSC10_RATE_POINT 0x50
686 #define TSC10_RATE_30 0x40
687 #define TSC10_RATE_50 0x41
688 #define TSC10_RATE_80 0x42
689 #define TSC10_RATE_100 0x43
690 #define TSC10_RATE_130 0x44
691 #define TSC10_RATE_150 0x45
694 #define TSC10_CMD_RESET 0x55
695 #define TSC10_CMD_RATE 0x05
696 #define TSC10_CMD_DATA1 0x01
698 static int dmc_tsc10_init(struct usbtouch_usb
*usbtouch
)
700 struct usb_device
*dev
= interface_to_usbdev(usbtouch
->interface
);
704 buf
= kmalloc(2, GFP_NOIO
);
708 buf
[0] = buf
[1] = 0xFF;
709 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
711 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
712 0, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
715 if (buf
[0] != 0x06) {
720 /* TSC-25 data sheet specifies a delay after the RESET command */
723 /* set coordinate output rate */
724 buf
[0] = buf
[1] = 0xFF;
725 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
727 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
728 TSC10_RATE_150
, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
731 if ((buf
[0] != 0x06) && (buf
[0] != 0x15 || buf
[1] != 0x01)) {
736 /* start sending data */
737 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
739 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
740 0, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
748 static int dmc_tsc10_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
750 dev
->x
= ((pkt
[2] & 0x03) << 8) | pkt
[1];
751 dev
->y
= ((pkt
[4] & 0x03) << 8) | pkt
[3];
752 dev
->touch
= pkt
[0] & 0x01;
759 /*****************************************************************************
762 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
763 static int irtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
765 dev
->x
= (pkt
[3] << 8) | pkt
[2];
766 dev
->y
= (pkt
[5] << 8) | pkt
[4];
767 dev
->touch
= (pkt
[1] & 0x03) ? 1 : 0;
773 /*****************************************************************************
774 * ET&T TC5UH/TC4UM part
776 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
777 static int tc45usb_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
779 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
780 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
781 dev
->touch
= pkt
[0] & 0x01;
787 /*****************************************************************************
788 * IdealTEK URTC1000 Part
790 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
794 static int idealtek_get_pkt_len(unsigned char *buf
, int len
)
803 static int idealtek_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
805 switch (pkt
[0] & 0x98) {
807 /* touch data in IdealTEK mode */
808 dev
->x
= (pkt
[1] << 5) | (pkt
[2] >> 2);
809 dev
->y
= (pkt
[3] << 5) | (pkt
[4] >> 2);
810 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
814 /* touch data in MT emulation mode */
815 dev
->x
= (pkt
[2] << 5) | (pkt
[1] >> 2);
816 dev
->y
= (pkt
[4] << 5) | (pkt
[3] >> 2);
817 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
826 /*****************************************************************************
829 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
830 static int general_touch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
832 dev
->x
= (pkt
[2] << 8) | pkt
[1];
833 dev
->y
= (pkt
[4] << 8) | pkt
[3];
834 dev
->press
= pkt
[5] & 0xff;
835 dev
->touch
= pkt
[0] & 0x01;
841 /*****************************************************************************
844 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
845 static int gotop_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
847 dev
->x
= ((pkt
[1] & 0x38) << 4) | pkt
[2];
848 dev
->y
= ((pkt
[1] & 0x07) << 7) | pkt
[3];
849 dev
->touch
= pkt
[0] & 0x01;
855 /*****************************************************************************
858 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
859 static int jastec_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
861 dev
->x
= ((pkt
[0] & 0x3f) << 6) | (pkt
[2] & 0x3f);
862 dev
->y
= ((pkt
[1] & 0x3f) << 6) | (pkt
[3] & 0x3f);
863 dev
->touch
= (pkt
[0] & 0x40) >> 6;
869 /*****************************************************************************
872 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
873 static int zytronic_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
875 struct usb_interface
*intf
= dev
->interface
;
878 case 0x3A: /* command response */
879 dev_dbg(&intf
->dev
, "%s: Command response %d\n", __func__
, pkt
[1]);
882 case 0xC0: /* down */
883 dev
->x
= (pkt
[1] & 0x7f) | ((pkt
[2] & 0x07) << 7);
884 dev
->y
= (pkt
[3] & 0x7f) | ((pkt
[4] & 0x07) << 7);
886 dev_dbg(&intf
->dev
, "%s: down %d,%d\n", __func__
, dev
->x
, dev
->y
);
890 dev
->x
= (pkt
[1] & 0x7f) | ((pkt
[2] & 0x07) << 7);
891 dev
->y
= (pkt
[3] & 0x7f) | ((pkt
[4] & 0x07) << 7);
893 dev_dbg(&intf
->dev
, "%s: up %d,%d\n", __func__
, dev
->x
, dev
->y
);
897 dev_dbg(&intf
->dev
, "%s: Unknown return %d\n", __func__
, pkt
[0]);
905 /*****************************************************************************
908 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
910 #define NEXIO_TIMEOUT 5000
911 #define NEXIO_BUFSIZE 1024
912 #define NEXIO_THRESHOLD 50
916 unsigned char *ack_buf
;
919 struct nexio_touch_packet
{
920 u8 flags
; /* 0xe1 = touch, 0xe1 = release */
921 __be16 data_len
; /* total bytes of touch data */
922 __be16 x_len
; /* bytes for X axis */
923 __be16 y_len
; /* bytes for Y axis */
925 } __attribute__ ((packed
));
927 static unsigned char nexio_ack_pkt
[2] = { 0xaa, 0x02 };
928 static unsigned char nexio_init_pkt
[4] = { 0x82, 0x04, 0x0a, 0x0f };
930 static void nexio_ack_complete(struct urb
*urb
)
934 static int nexio_alloc(struct usbtouch_usb
*usbtouch
)
936 struct nexio_priv
*priv
;
939 usbtouch
->priv
= kmalloc(sizeof(struct nexio_priv
), GFP_KERNEL
);
943 priv
= usbtouch
->priv
;
945 priv
->ack_buf
= kmemdup(nexio_ack_pkt
, sizeof(nexio_ack_pkt
),
950 priv
->ack
= usb_alloc_urb(0, GFP_KERNEL
);
952 dev_dbg(&usbtouch
->interface
->dev
,
953 "%s - usb_alloc_urb failed: usbtouch->ack\n", __func__
);
960 kfree(priv
->ack_buf
);
967 static int nexio_init(struct usbtouch_usb
*usbtouch
)
969 struct usb_device
*dev
= interface_to_usbdev(usbtouch
->interface
);
970 struct usb_host_interface
*interface
= usbtouch
->interface
->cur_altsetting
;
971 struct nexio_priv
*priv
= usbtouch
->priv
;
975 char *firmware_ver
= NULL
, *device_name
= NULL
;
976 int input_ep
= 0, output_ep
= 0;
978 /* find first input and output endpoint */
979 for (i
= 0; i
< interface
->desc
.bNumEndpoints
; i
++) {
981 usb_endpoint_dir_in(&interface
->endpoint
[i
].desc
))
982 input_ep
= interface
->endpoint
[i
].desc
.bEndpointAddress
;
984 usb_endpoint_dir_out(&interface
->endpoint
[i
].desc
))
985 output_ep
= interface
->endpoint
[i
].desc
.bEndpointAddress
;
987 if (!input_ep
|| !output_ep
)
990 buf
= kmalloc(NEXIO_BUFSIZE
, GFP_NOIO
);
994 /* two empty reads */
995 for (i
= 0; i
< 2; i
++) {
996 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, input_ep
),
997 buf
, NEXIO_BUFSIZE
, &actual_len
,
1003 /* send init command */
1004 memcpy(buf
, nexio_init_pkt
, sizeof(nexio_init_pkt
));
1005 ret
= usb_bulk_msg(dev
, usb_sndbulkpipe(dev
, output_ep
),
1006 buf
, sizeof(nexio_init_pkt
), &actual_len
,
1012 for (i
= 0; i
< 3; i
++) {
1013 memset(buf
, 0, NEXIO_BUFSIZE
);
1014 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, input_ep
),
1015 buf
, NEXIO_BUFSIZE
, &actual_len
,
1017 if (ret
< 0 || actual_len
< 1 || buf
[1] != actual_len
)
1020 case 0x83: /* firmware version */
1022 firmware_ver
= kstrdup(&buf
[2], GFP_NOIO
);
1024 case 0x84: /* device name */
1026 device_name
= kstrdup(&buf
[2], GFP_NOIO
);
1031 printk(KERN_INFO
"Nexio device: %s, firmware version: %s\n",
1032 device_name
, firmware_ver
);
1034 kfree(firmware_ver
);
1037 usb_fill_bulk_urb(priv
->ack
, dev
, usb_sndbulkpipe(dev
, output_ep
),
1038 priv
->ack_buf
, sizeof(nexio_ack_pkt
),
1039 nexio_ack_complete
, usbtouch
);
1047 static void nexio_exit(struct usbtouch_usb
*usbtouch
)
1049 struct nexio_priv
*priv
= usbtouch
->priv
;
1051 usb_kill_urb(priv
->ack
);
1052 usb_free_urb(priv
->ack
);
1053 kfree(priv
->ack_buf
);
1057 static int nexio_read_data(struct usbtouch_usb
*usbtouch
, unsigned char *pkt
)
1059 struct nexio_touch_packet
*packet
= (void *) pkt
;
1060 struct nexio_priv
*priv
= usbtouch
->priv
;
1061 unsigned int data_len
= be16_to_cpu(packet
->data_len
);
1062 unsigned int x_len
= be16_to_cpu(packet
->x_len
);
1063 unsigned int y_len
= be16_to_cpu(packet
->y_len
);
1064 int x
, y
, begin_x
, begin_y
, end_x
, end_y
, w
, h
, ret
;
1066 /* got touch data? */
1067 if ((pkt
[0] & 0xe0) != 0xe0)
1070 if (data_len
> 0xff)
1076 ret
= usb_submit_urb(priv
->ack
, GFP_ATOMIC
);
1078 if (!usbtouch
->type
->max_xc
) {
1079 usbtouch
->type
->max_xc
= 2 * x_len
;
1080 input_set_abs_params(usbtouch
->input
, ABS_X
,
1081 0, usbtouch
->type
->max_xc
, 0, 0);
1082 usbtouch
->type
->max_yc
= 2 * y_len
;
1083 input_set_abs_params(usbtouch
->input
, ABS_Y
,
1084 0, usbtouch
->type
->max_yc
, 0, 0);
1087 * The device reports state of IR sensors on X and Y axes.
1088 * Each byte represents "darkness" percentage (0-100) of one element.
1089 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
1090 * This also means that there's a limited multi-touch capability but
1091 * it's disabled (and untested) here as there's no X driver for that.
1093 begin_x
= end_x
= begin_y
= end_y
= -1;
1094 for (x
= 0; x
< x_len
; x
++) {
1095 if (begin_x
== -1 && packet
->data
[x
] > NEXIO_THRESHOLD
) {
1099 if (end_x
== -1 && begin_x
!= -1 && packet
->data
[x
] < NEXIO_THRESHOLD
) {
1101 for (y
= x_len
; y
< data_len
; y
++) {
1102 if (begin_y
== -1 && packet
->data
[y
] > NEXIO_THRESHOLD
) {
1103 begin_y
= y
- x_len
;
1107 begin_y
!= -1 && packet
->data
[y
] < NEXIO_THRESHOLD
) {
1108 end_y
= y
- 1 - x_len
;
1109 w
= end_x
- begin_x
;
1110 h
= end_y
- begin_y
;
1113 input_report_abs(usbtouch
->input
,
1114 ABS_MT_TOUCH_MAJOR
, max(w
,h
));
1115 input_report_abs(usbtouch
->input
,
1116 ABS_MT_TOUCH_MINOR
, min(x
,h
));
1117 input_report_abs(usbtouch
->input
,
1118 ABS_MT_POSITION_X
, 2*begin_x
+w
);
1119 input_report_abs(usbtouch
->input
,
1120 ABS_MT_POSITION_Y
, 2*begin_y
+h
);
1121 input_report_abs(usbtouch
->input
,
1122 ABS_MT_ORIENTATION
, w
> h
);
1123 input_mt_sync(usbtouch
->input
);
1126 usbtouch
->x
= 2 * begin_x
+ w
;
1127 usbtouch
->y
= 2 * begin_y
+ h
;
1128 usbtouch
->touch
= packet
->flags
& 0x01;
1129 begin_y
= end_y
= -1;
1133 begin_x
= end_x
= -1;
1142 /*****************************************************************************
1146 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
1148 static int elo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
1150 dev
->x
= (pkt
[3] << 8) | pkt
[2];
1151 dev
->y
= (pkt
[5] << 8) | pkt
[4];
1152 dev
->touch
= pkt
[6] > 0;
1153 dev
->press
= pkt
[6];
1160 /*****************************************************************************
1161 * the different device descriptors
1164 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
1165 unsigned char *pkt
, int len
);
1168 static struct usbtouch_device_info usbtouch_dev_info
[] = {
1169 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
1177 .read_data
= elo_read_data
,
1181 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
1182 [DEVTYPE_EGALAX
] = {
1188 .process_pkt
= usbtouch_process_multi
,
1189 .get_pkt_len
= egalax_get_pkt_len
,
1190 .read_data
= egalax_read_data
,
1191 .init
= egalax_init
,
1195 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
1196 [DEVTYPE_PANJIT
] = {
1202 .read_data
= panjit_read_data
,
1206 #ifdef CONFIG_TOUCHSCREEN_USB_3M
1213 .read_data
= mtouch_read_data
,
1214 .alloc
= mtouch_alloc
,
1215 .init
= mtouch_init
,
1216 .exit
= mtouch_exit
,
1220 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
1228 .read_data
= itm_read_data
,
1232 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
1233 [DEVTYPE_ETURBO
] = {
1239 .process_pkt
= usbtouch_process_multi
,
1240 .get_pkt_len
= eturbo_get_pkt_len
,
1241 .read_data
= eturbo_read_data
,
1245 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
1252 .read_data
= gunze_read_data
,
1256 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
1257 [DEVTYPE_DMC_TSC10
] = {
1263 .init
= dmc_tsc10_init
,
1264 .read_data
= dmc_tsc10_read_data
,
1268 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
1269 [DEVTYPE_IRTOUCH
] = {
1275 .read_data
= irtouch_read_data
,
1278 [DEVTYPE_IRTOUCH_HIRES
] = {
1284 .read_data
= irtouch_read_data
,
1288 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
1289 [DEVTYPE_IDEALTEK
] = {
1295 .process_pkt
= usbtouch_process_multi
,
1296 .get_pkt_len
= idealtek_get_pkt_len
,
1297 .read_data
= idealtek_read_data
,
1301 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1302 [DEVTYPE_GENERAL_TOUCH
] = {
1308 .read_data
= general_touch_read_data
,
1312 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
1319 .read_data
= gotop_read_data
,
1323 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
1324 [DEVTYPE_JASTEC
] = {
1330 .read_data
= jastec_read_data
,
1334 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
1342 .read_data
= e2i_read_data
,
1346 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1347 [DEVTYPE_ZYTRONIC
] = {
1353 .read_data
= zytronic_read_data
,
1358 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1359 [DEVTYPE_TC45USB
] = {
1365 .read_data
= tc45usb_read_data
,
1369 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1373 .read_data
= nexio_read_data
,
1374 .alloc
= nexio_alloc
,
1379 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
1380 [DEVTYPE_ETOUCH
] = {
1386 .process_pkt
= usbtouch_process_multi
,
1387 .get_pkt_len
= etouch_get_pkt_len
,
1388 .read_data
= etouch_read_data
,
1394 /*****************************************************************************
1397 static void usbtouch_process_pkt(struct usbtouch_usb
*usbtouch
,
1398 unsigned char *pkt
, int len
)
1400 struct usbtouch_device_info
*type
= usbtouch
->type
;
1402 if (!type
->read_data(usbtouch
, pkt
))
1405 input_report_key(usbtouch
->input
, BTN_TOUCH
, usbtouch
->touch
);
1408 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->y
);
1409 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->x
);
1411 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->x
);
1412 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->y
);
1414 if (type
->max_press
)
1415 input_report_abs(usbtouch
->input
, ABS_PRESSURE
, usbtouch
->press
);
1416 input_sync(usbtouch
->input
);
1421 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
1422 unsigned char *pkt
, int len
)
1424 unsigned char *buffer
;
1425 int pkt_len
, pos
, buf_len
, tmp
;
1427 /* process buffer */
1428 if (unlikely(usbtouch
->buf_len
)) {
1429 /* try to get size */
1430 pkt_len
= usbtouch
->type
->get_pkt_len(
1431 usbtouch
->buffer
, usbtouch
->buf_len
);
1434 if (unlikely(!pkt_len
))
1437 /* need to append -pkt_len bytes before able to get size */
1438 if (unlikely(pkt_len
< 0)) {
1439 int append
= -pkt_len
;
1440 if (unlikely(append
> len
))
1442 if (usbtouch
->buf_len
+ append
>= usbtouch
->type
->rept_size
)
1444 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, append
);
1445 usbtouch
->buf_len
+= append
;
1447 pkt_len
= usbtouch
->type
->get_pkt_len(
1448 usbtouch
->buffer
, usbtouch
->buf_len
);
1454 tmp
= pkt_len
- usbtouch
->buf_len
;
1455 if (usbtouch
->buf_len
+ tmp
>= usbtouch
->type
->rept_size
)
1457 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, tmp
);
1458 usbtouch_process_pkt(usbtouch
, usbtouch
->buffer
, pkt_len
);
1461 buf_len
= len
- tmp
;
1467 /* loop over the received packet, process */
1469 while (pos
< buf_len
) {
1470 /* get packet len */
1471 pkt_len
= usbtouch
->type
->get_pkt_len(buffer
+ pos
,
1474 /* unknown packet: skip one byte */
1475 if (unlikely(!pkt_len
)) {
1480 /* full packet: process */
1481 if (likely((pkt_len
> 0) && (pkt_len
<= buf_len
- pos
))) {
1482 usbtouch_process_pkt(usbtouch
, buffer
+ pos
, pkt_len
);
1484 /* incomplete packet: save in buffer */
1485 memcpy(usbtouch
->buffer
, buffer
+ pos
, buf_len
- pos
);
1486 usbtouch
->buf_len
= buf_len
- pos
;
1493 usbtouch
->buf_len
= 0;
1499 static void usbtouch_irq(struct urb
*urb
)
1501 struct usbtouch_usb
*usbtouch
= urb
->context
;
1502 struct device
*dev
= &usbtouch
->interface
->dev
;
1505 switch (urb
->status
) {
1510 /* this urb is timing out */
1512 "%s - urb timed out - was the device unplugged?\n",
1519 /* this urb is terminated, clean up */
1520 dev_dbg(dev
, "%s - urb shutting down with status: %d\n",
1521 __func__
, urb
->status
);
1524 dev_dbg(dev
, "%s - nonzero urb status received: %d\n",
1525 __func__
, urb
->status
);
1529 usbtouch
->type
->process_pkt(usbtouch
, usbtouch
->data
, urb
->actual_length
);
1532 usb_mark_last_busy(interface_to_usbdev(usbtouch
->interface
));
1533 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
1535 dev_err(dev
, "%s - usb_submit_urb failed with result: %d\n",
1539 static int usbtouch_open(struct input_dev
*input
)
1541 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
1544 usbtouch
->irq
->dev
= interface_to_usbdev(usbtouch
->interface
);
1546 r
= usb_autopm_get_interface(usbtouch
->interface
) ? -EIO
: 0;
1550 mutex_lock(&usbtouch
->pm_mutex
);
1551 if (!usbtouch
->type
->irq_always
) {
1552 if (usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
)) {
1558 usbtouch
->interface
->needs_remote_wakeup
= 1;
1559 usbtouch
->is_open
= true;
1561 mutex_unlock(&usbtouch
->pm_mutex
);
1562 usb_autopm_put_interface(usbtouch
->interface
);
1567 static void usbtouch_close(struct input_dev
*input
)
1569 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
1572 mutex_lock(&usbtouch
->pm_mutex
);
1573 if (!usbtouch
->type
->irq_always
)
1574 usb_kill_urb(usbtouch
->irq
);
1575 usbtouch
->is_open
= false;
1576 mutex_unlock(&usbtouch
->pm_mutex
);
1578 r
= usb_autopm_get_interface(usbtouch
->interface
);
1579 usbtouch
->interface
->needs_remote_wakeup
= 0;
1581 usb_autopm_put_interface(usbtouch
->interface
);
1584 static int usbtouch_suspend
1585 (struct usb_interface
*intf
, pm_message_t message
)
1587 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1589 usb_kill_urb(usbtouch
->irq
);
1594 static int usbtouch_resume(struct usb_interface
*intf
)
1596 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1599 mutex_lock(&usbtouch
->pm_mutex
);
1600 if (usbtouch
->is_open
|| usbtouch
->type
->irq_always
)
1601 result
= usb_submit_urb(usbtouch
->irq
, GFP_NOIO
);
1602 mutex_unlock(&usbtouch
->pm_mutex
);
1607 static int usbtouch_reset_resume(struct usb_interface
*intf
)
1609 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1612 /* reinit the device */
1613 if (usbtouch
->type
->init
) {
1614 err
= usbtouch
->type
->init(usbtouch
);
1617 "%s - type->init() failed, err: %d\n",
1623 /* restart IO if needed */
1624 mutex_lock(&usbtouch
->pm_mutex
);
1625 if (usbtouch
->is_open
)
1626 err
= usb_submit_urb(usbtouch
->irq
, GFP_NOIO
);
1627 mutex_unlock(&usbtouch
->pm_mutex
);
1632 static void usbtouch_free_buffers(struct usb_device
*udev
,
1633 struct usbtouch_usb
*usbtouch
)
1635 usb_free_coherent(udev
, usbtouch
->data_size
,
1636 usbtouch
->data
, usbtouch
->data_dma
);
1637 kfree(usbtouch
->buffer
);
1640 static struct usb_endpoint_descriptor
*
1641 usbtouch_get_input_endpoint(struct usb_host_interface
*interface
)
1645 for (i
= 0; i
< interface
->desc
.bNumEndpoints
; i
++)
1646 if (usb_endpoint_dir_in(&interface
->endpoint
[i
].desc
))
1647 return &interface
->endpoint
[i
].desc
;
1652 static int usbtouch_probe(struct usb_interface
*intf
,
1653 const struct usb_device_id
*id
)
1655 struct usbtouch_usb
*usbtouch
;
1656 struct input_dev
*input_dev
;
1657 struct usb_endpoint_descriptor
*endpoint
;
1658 struct usb_device
*udev
= interface_to_usbdev(intf
);
1659 struct usbtouch_device_info
*type
;
1662 /* some devices are ignored */
1663 if (id
->driver_info
== DEVTYPE_IGNORE
)
1666 endpoint
= usbtouch_get_input_endpoint(intf
->cur_altsetting
);
1670 usbtouch
= kzalloc(sizeof(struct usbtouch_usb
), GFP_KERNEL
);
1671 input_dev
= input_allocate_device();
1672 if (!usbtouch
|| !input_dev
)
1675 type
= &usbtouch_dev_info
[id
->driver_info
];
1676 usbtouch
->type
= type
;
1677 if (!type
->process_pkt
)
1678 type
->process_pkt
= usbtouch_process_pkt
;
1680 usbtouch
->data_size
= type
->rept_size
;
1681 if (type
->get_pkt_len
) {
1683 * When dealing with variable-length packets we should
1684 * not request more than wMaxPacketSize bytes at once
1685 * as we do not know if there is more data coming or
1686 * we filled exactly wMaxPacketSize bytes and there is
1689 usbtouch
->data_size
= min(usbtouch
->data_size
,
1690 usb_endpoint_maxp(endpoint
));
1693 usbtouch
->data
= usb_alloc_coherent(udev
, usbtouch
->data_size
,
1694 GFP_KERNEL
, &usbtouch
->data_dma
);
1695 if (!usbtouch
->data
)
1698 if (type
->get_pkt_len
) {
1699 usbtouch
->buffer
= kmalloc(type
->rept_size
, GFP_KERNEL
);
1700 if (!usbtouch
->buffer
)
1701 goto out_free_buffers
;
1704 usbtouch
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
1705 if (!usbtouch
->irq
) {
1707 "%s - usb_alloc_urb failed: usbtouch->irq\n", __func__
);
1708 goto out_free_buffers
;
1711 usbtouch
->interface
= intf
;
1712 usbtouch
->input
= input_dev
;
1714 if (udev
->manufacturer
)
1715 strlcpy(usbtouch
->name
, udev
->manufacturer
, sizeof(usbtouch
->name
));
1717 if (udev
->product
) {
1718 if (udev
->manufacturer
)
1719 strlcat(usbtouch
->name
, " ", sizeof(usbtouch
->name
));
1720 strlcat(usbtouch
->name
, udev
->product
, sizeof(usbtouch
->name
));
1723 if (!strlen(usbtouch
->name
))
1724 snprintf(usbtouch
->name
, sizeof(usbtouch
->name
),
1725 "USB Touchscreen %04x:%04x",
1726 le16_to_cpu(udev
->descriptor
.idVendor
),
1727 le16_to_cpu(udev
->descriptor
.idProduct
));
1729 usb_make_path(udev
, usbtouch
->phys
, sizeof(usbtouch
->phys
));
1730 strlcat(usbtouch
->phys
, "/input0", sizeof(usbtouch
->phys
));
1732 input_dev
->name
= usbtouch
->name
;
1733 input_dev
->phys
= usbtouch
->phys
;
1734 usb_to_input_id(udev
, &input_dev
->id
);
1735 input_dev
->dev
.parent
= &intf
->dev
;
1737 input_set_drvdata(input_dev
, usbtouch
);
1739 input_dev
->open
= usbtouch_open
;
1740 input_dev
->close
= usbtouch_close
;
1742 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
1743 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
1744 input_set_abs_params(input_dev
, ABS_X
, type
->min_xc
, type
->max_xc
, 0, 0);
1745 input_set_abs_params(input_dev
, ABS_Y
, type
->min_yc
, type
->max_yc
, 0, 0);
1746 if (type
->max_press
)
1747 input_set_abs_params(input_dev
, ABS_PRESSURE
, type
->min_press
,
1748 type
->max_press
, 0, 0);
1750 if (usb_endpoint_type(endpoint
) == USB_ENDPOINT_XFER_INT
)
1751 usb_fill_int_urb(usbtouch
->irq
, udev
,
1752 usb_rcvintpipe(udev
, endpoint
->bEndpointAddress
),
1753 usbtouch
->data
, usbtouch
->data_size
,
1754 usbtouch_irq
, usbtouch
, endpoint
->bInterval
);
1756 usb_fill_bulk_urb(usbtouch
->irq
, udev
,
1757 usb_rcvbulkpipe(udev
, endpoint
->bEndpointAddress
),
1758 usbtouch
->data
, usbtouch
->data_size
,
1759 usbtouch_irq
, usbtouch
);
1761 usbtouch
->irq
->dev
= udev
;
1762 usbtouch
->irq
->transfer_dma
= usbtouch
->data_dma
;
1763 usbtouch
->irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1765 /* device specific allocations */
1767 err
= type
->alloc(usbtouch
);
1770 "%s - type->alloc() failed, err: %d\n",
1776 /* device specific initialisation*/
1778 err
= type
->init(usbtouch
);
1781 "%s - type->init() failed, err: %d\n",
1787 err
= input_register_device(usbtouch
->input
);
1790 "%s - input_register_device failed, err: %d\n",
1795 usb_set_intfdata(intf
, usbtouch
);
1797 if (usbtouch
->type
->irq_always
) {
1798 /* this can't fail */
1799 usb_autopm_get_interface(intf
);
1800 err
= usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
);
1802 usb_autopm_put_interface(intf
);
1804 "%s - usb_submit_urb failed with result: %d\n",
1806 goto out_unregister_input
;
1812 out_unregister_input
:
1813 input_unregister_device(input_dev
);
1817 type
->exit(usbtouch
);
1819 usb_free_urb(usbtouch
->irq
);
1821 usbtouch_free_buffers(udev
, usbtouch
);
1823 input_free_device(input_dev
);
1828 static void usbtouch_disconnect(struct usb_interface
*intf
)
1830 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1836 "%s - usbtouch is initialized, cleaning up\n", __func__
);
1838 usb_set_intfdata(intf
, NULL
);
1839 /* this will stop IO via close */
1840 input_unregister_device(usbtouch
->input
);
1841 usb_free_urb(usbtouch
->irq
);
1842 if (usbtouch
->type
->exit
)
1843 usbtouch
->type
->exit(usbtouch
);
1844 usbtouch_free_buffers(interface_to_usbdev(intf
), usbtouch
);
1848 MODULE_DEVICE_TABLE(usb
, usbtouch_devices
);
1850 static struct usb_driver usbtouch_driver
= {
1851 .name
= "usbtouchscreen",
1852 .probe
= usbtouch_probe
,
1853 .disconnect
= usbtouch_disconnect
,
1854 .suspend
= usbtouch_suspend
,
1855 .resume
= usbtouch_resume
,
1856 .reset_resume
= usbtouch_reset_resume
,
1857 .id_table
= usbtouch_devices
,
1858 .supports_autosuspend
= 1,
1861 module_usb_driver(usbtouch_driver
);
1863 MODULE_AUTHOR("Daniel Ritz <daniel.ritz@gmx.ch>");
1864 MODULE_DESCRIPTION("USB Touchscreen Driver");
1865 MODULE_LICENSE("GPL");
1867 MODULE_ALIAS("touchkitusb");
1868 MODULE_ALIAS("itmtouch");
1869 MODULE_ALIAS("mtouchusb");