50 #include <linux/kernel.h>
51 #include <linux/slab.h>
52 #include <linux/input.h>
53 #include <linux/module.h>
57 #include <linux/hid.h>
60 #define DRIVER_VERSION "v0.6"
62 #define DRIVER_DESC "USB Touchscreen Driver"
68 static bool hwcalib_xy;
70 MODULE_PARM_DESC(hwcalib_xy,
"If set hw-calibrated X/Y are used if available");
147 #define USB_DEVICE_HID_CLASS(vend, prod) \
148 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
149 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
150 | USB_DEVICE_ID_MATCH_DEVICE, \
151 .idVendor = (vend), \
152 .idProduct = (prod), \
153 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
154 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
157 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
172 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
179 #ifdef CONFIG_TOUCHSCREEN_USB_3M
180 {USB_DEVICE(0x0596, 0x0001), .driver_info =
DEVTYPE_3M},
183 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
184 {USB_DEVICE(0x0403, 0xf9e9), .driver_info =
DEVTYPE_ITM},
185 {USB_DEVICE(0x16e3, 0xf9e9), .driver_info =
DEVTYPE_ITM},
188 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
192 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
196 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
200 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
205 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
209 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
213 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
219 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
223 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
224 {USB_DEVICE(0x1ac7, 0x0001), .driver_info =
DEVTYPE_E2I},
227 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
231 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
238 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
240 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
242 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
246 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
247 {USB_DEVICE(0x04e7, 0x0020), .driver_info =
DEVTYPE_ELO},
250 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
262 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
266 struct usb_device *
udev = interface_to_usbdev(usbtouch->
interface);
269 0x01, 0x02, 0x0000, 0x0081,
270 NULL, 0, USB_CTRL_SET_TIMEOUT);
273 "%s - usb_control_msg - E2I_RESET - bytes|err: %d\n",
280 int tmp = (pkt[0] << 8) | pkt[1];
281 dev->
x = (pkt[2] << 8) | pkt[3];
282 dev->
y = (pkt[4] << 8) | pkt[5];
285 dev->
touch = (tmp > 0);
286 dev->
press = (tmp > 0 ? tmp : 0);
297 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
303 #define EGALAX_PKT_TYPE_MASK 0xFE
304 #define EGALAX_PKT_TYPE_REPT 0x80
305 #define EGALAX_PKT_TYPE_DIAG 0x0A
311 struct usb_device *udev = interface_to_usbdev(usbtouch->
interface);
323 buf[0] = EGALAX_PKT_TYPE_DIAG;
327 for (i = 0; i < 3; i++) {
332 USB_CTRL_SET_TIMEOUT);
346 static int egalax_read_data(
struct usbtouch_usb *
dev,
unsigned char *pkt)
348 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
351 dev->
x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
352 dev->
y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
353 dev->
touch = pkt[0] & 0x01;
358 static int egalax_get_pkt_len(
unsigned char *buf,
int len)
360 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
361 case EGALAX_PKT_TYPE_REPT:
364 case EGALAX_PKT_TYPE_DIAG:
379 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
385 #define ETOUCH_PKT_TYPE_MASK 0xFE
386 #define ETOUCH_PKT_TYPE_REPT 0x80
387 #define ETOUCH_PKT_TYPE_REPT2 0xB0
388 #define ETOUCH_PKT_TYPE_DIAG 0x0A
390 static int etouch_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
392 if ((pkt[0] & ETOUCH_PKT_TYPE_MASK) != ETOUCH_PKT_TYPE_REPT &&
393 (pkt[0] & ETOUCH_PKT_TYPE_MASK) != ETOUCH_PKT_TYPE_REPT2)
396 dev->
x = ((pkt[1] & 0x1F) << 7) | (pkt[2] & 0x7F);
397 dev->
y = ((pkt[3] & 0x1F) << 7) | (pkt[4] & 0x7F);
398 dev->
touch = pkt[0] & 0x01;
403 static int etouch_get_pkt_len(
unsigned char *buf,
int len)
405 switch (buf[0] & ETOUCH_PKT_TYPE_MASK) {
406 case ETOUCH_PKT_TYPE_REPT:
407 case ETOUCH_PKT_TYPE_REPT2:
410 case ETOUCH_PKT_TYPE_DIAG:
424 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
425 static int panjit_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
427 dev->
x = ((pkt[2] & 0x0F) << 8) | pkt[1];
428 dev->
y = ((pkt[4] & 0x0F) << 8) | pkt[3];
429 dev->
touch = pkt[0] & 0x01;
439 #ifdef CONFIG_TOUCHSCREEN_USB_3M
441 #define MTOUCHUSB_ASYNC_REPORT 1
442 #define MTOUCHUSB_RESET 7
443 #define MTOUCHUSB_REQ_CTRLLR_ID 10
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;
462 struct usb_device *udev = interface_to_usbdev(usbtouch->
interface);
467 1, 0,
NULL, 0, USB_CTRL_SET_TIMEOUT);
469 "%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d\n",
475 for (i = 0; i < 3; i++) {
477 MTOUCHUSB_ASYNC_REPORT,
479 1, 1,
NULL, 0, USB_CTRL_SET_TIMEOUT);
481 "%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d\n",
491 input_set_abs_params(usbtouch->
input,
ABS_X, 0, 0xffff, 0, 0);
492 input_set_abs_params(usbtouch->
input,
ABS_Y, 0, 0xffff, 0, 0);
503 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
504 static int itm_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
513 dev->
press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
515 touch = ~pkt[7] & 0x20;
525 dev->
x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
526 dev->
y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
537 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
541 static int eturbo_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
546 if (!(pkt[0] & 0x80))
549 shift = (6 - (pkt[0] & 0x03));
550 dev->
x = ((pkt[3] << 7) | pkt[4]) >> shift;
551 dev->
y = ((pkt[1] << 7) | pkt[2]) >> shift;
552 dev->
touch = (pkt[0] & 0x10) ? 1 : 0;
557 static int eturbo_get_pkt_len(
unsigned char *buf,
int len)
571 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
572 static int gunze_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
574 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
577 dev->
x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
578 dev->
y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
579 dev->
touch = pkt[0] & 0x20;
592 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
595 #define TSC10_RATE_POINT 0x50
596 #define TSC10_RATE_30 0x40
597 #define TSC10_RATE_50 0x41
598 #define TSC10_RATE_80 0x42
599 #define TSC10_RATE_100 0x43
600 #define TSC10_RATE_130 0x44
601 #define TSC10_RATE_150 0x45
604 #define TSC10_CMD_RESET 0x55
605 #define TSC10_CMD_RATE 0x05
606 #define TSC10_CMD_DATA1 0x01
608 static int dmc_tsc10_init(
struct usbtouch_usb *usbtouch)
610 struct usb_device *dev = interface_to_usbdev(usbtouch->
interface);
618 buf[0] = buf[1] = 0xFF;
622 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
625 if (buf[0] != 0x06) {
631 buf[0] = buf[1] = 0xFF;
635 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
638 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
647 0, 0,
NULL, 0, USB_CTRL_SET_TIMEOUT);
655 static int dmc_tsc10_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
657 dev->
x = ((pkt[2] & 0x03) << 8) | pkt[1];
658 dev->
y = ((pkt[4] & 0x03) << 8) | pkt[3];
659 dev->
touch = pkt[0] & 0x01;
669 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
670 static int irtouch_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
672 dev->
x = (pkt[3] << 8) | pkt[2];
673 dev->
y = (pkt[5] << 8) | pkt[4];
674 dev->
touch = (pkt[1] & 0x03) ? 1 : 0;
683 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
684 static int tc45usb_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
686 dev->
x = ((pkt[2] & 0x0F) << 8) | pkt[1];
687 dev->
y = ((pkt[4] & 0x0F) << 8) | pkt[3];
688 dev->
touch = pkt[0] & 0x01;
697 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
701 static int idealtek_get_pkt_len(
unsigned char *buf,
int len)
710 static int idealtek_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
712 switch (pkt[0] & 0x98) {
715 dev->
x = (pkt[1] << 5) | (pkt[2] >> 2);
716 dev->
y = (pkt[3] << 5) | (pkt[4] >> 2);
717 dev->
touch = (pkt[0] & 0x40) ? 1 : 0;
722 dev->
x = (pkt[2] << 5) | (pkt[1] >> 2);
723 dev->
y = (pkt[4] << 5) | (pkt[3] >> 2);
724 dev->
touch = (pkt[0] & 0x40) ? 1 : 0;
736 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
737 static int general_touch_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
739 dev->
x = (pkt[2] << 8) | pkt[1];
740 dev->
y = (pkt[4] << 8) | pkt[3];
741 dev->
press = pkt[5] & 0xff;
742 dev->
touch = pkt[0] & 0x01;
751 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
752 static int gotop_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
754 dev->
x = ((pkt[1] & 0x38) << 4) | pkt[2];
755 dev->
y = ((pkt[1] & 0x07) << 7) | pkt[3];
756 dev->
touch = pkt[0] & 0x01;
765 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
766 static int jastec_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
768 dev->
x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
769 dev->
y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
770 dev->
touch = (pkt[0] & 0x40) >> 6;
779 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
780 static int zytronic_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
786 dev_dbg(&intf->dev,
"%s: Command response %d\n", __func__, pkt[1]);
790 dev->
x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
791 dev->
y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
793 dev_dbg(&intf->dev,
"%s: down %d,%d\n", __func__, dev->
x, dev->
y);
797 dev->
x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
798 dev->
y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
800 dev_dbg(&intf->dev,
"%s: up %d,%d\n", __func__, dev->
x, dev->
y);
804 dev_dbg(&intf->dev,
"%s: Unknown return %d\n", __func__, pkt[0]);
815 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
817 #define NEXIO_TIMEOUT 5000
818 #define NEXIO_BUFSIZE 1024
819 #define NEXIO_THRESHOLD 50
823 unsigned char *ack_buf;
826 struct nexio_touch_packet {
834 static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 };
835 static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f };
837 static void nexio_ack_complete(
struct urb *
urb)
843 struct nexio_priv *
priv;
850 priv = usbtouch->
priv;
852 priv->ack_buf =
kmemdup(nexio_ack_pkt,
sizeof(nexio_ack_pkt),
860 "%s - usb_alloc_urb failed: usbtouch->ack\n", __func__);
867 kfree(priv->ack_buf);
876 struct usb_device *dev = interface_to_usbdev(usbtouch->
interface);
877 struct usb_host_interface *
interface = usbtouch->
interface->cur_altsetting;
878 struct nexio_priv *priv = usbtouch->
priv;
883 int input_ep = 0, output_ep = 0;
886 for (i = 0; i <
interface->desc.bNumEndpoints; i++) {
888 usb_endpoint_dir_in(&
interface->endpoint[i].desc))
889 input_ep =
interface->endpoint[
i].desc.bEndpointAddress;
891 usb_endpoint_dir_out(&
interface->endpoint[i].desc))
892 output_ep =
interface->endpoint[
i].desc.bEndpointAddress;
894 if (!input_ep || !output_ep)
902 for (i = 0; i < 2; i++) {
904 buf, NEXIO_BUFSIZE, &actual_len,
911 memcpy(buf, nexio_init_pkt,
sizeof(nexio_init_pkt));
912 ret =
usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep),
913 buf,
sizeof(nexio_init_pkt), &actual_len,
919 for (i = 0; i < 3; i++) {
920 memset(buf, 0, NEXIO_BUFSIZE);
922 buf, NEXIO_BUFSIZE, &actual_len,
924 if (ret < 0 || actual_len < 1 || buf[1] != actual_len)
939 device_name, firmware_ver);
944 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep),
945 priv->ack_buf,
sizeof(nexio_ack_pkt),
946 nexio_ack_complete, usbtouch);
956 struct nexio_priv *priv = usbtouch->
priv;
960 kfree(priv->ack_buf);
964 static int nexio_read_data(
struct usbtouch_usb *usbtouch,
unsigned char *pkt)
966 struct nexio_touch_packet *
packet = (
void *) pkt;
967 struct nexio_priv *priv = usbtouch->
priv;
971 int x,
y, begin_x, begin_y, end_x, end_y,
w,
h,
ret;
974 if ((pkt[0] & 0xe0) != 0xe0)
985 if (!usbtouch->
type->max_xc) {
986 usbtouch->
type->max_xc = 2 * x_len;
988 0, usbtouch->
type->max_xc, 0, 0);
989 usbtouch->
type->max_yc = 2 * y_len;
991 0, usbtouch->
type->max_yc, 0, 0);
1000 begin_x = end_x = begin_y = end_y = -1;
1001 for (x = 0; x < x_len; x++) {
1002 if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) {
1006 if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) {
1008 for (y = x_len; y <
data_len; y++) {
1009 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
1010 begin_y = y - x_len;
1014 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
1015 end_y = y - 1 - x_len;
1016 w = end_x - begin_x;
1017 h = end_y - begin_y;
1020 input_report_abs(usbtouch->
input,
1022 input_report_abs(usbtouch->
input,
1024 input_report_abs(usbtouch->
input,
1026 input_report_abs(usbtouch->
input,
1028 input_report_abs(usbtouch->
input,
1030 input_mt_sync(usbtouch->
input);
1033 usbtouch->
x = 2 * begin_x +
w;
1034 usbtouch->
y = 2 * begin_y +
h;
1035 usbtouch->
touch = packet->flags & 0x01;
1036 begin_y = end_y = -1;
1040 begin_x = end_x = -1;
1053 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
1055 static int elo_read_data(
struct usbtouch_usb *dev,
unsigned char *pkt)
1057 dev->
x = (pkt[3] << 8) | pkt[2];
1058 dev->
y = (pkt[5] << 8) | pkt[4];
1059 dev->
touch = pkt[6] > 0;
1060 dev->
press = pkt[6];
1071 static void usbtouch_process_multi(
struct usbtouch_usb *usbtouch,
1072 unsigned char *pkt,
int len);
1076 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
1084 .read_data = elo_read_data,
1088 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
1095 .process_pkt = usbtouch_process_multi,
1096 .get_pkt_len = egalax_get_pkt_len,
1097 .read_data = egalax_read_data,
1098 .init = egalax_init,
1102 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
1109 .read_data = panjit_read_data,
1113 #ifdef CONFIG_TOUCHSCREEN_USB_3M
1120 .read_data = mtouch_read_data,
1121 .init = mtouch_init,
1125 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
1133 .read_data = itm_read_data,
1137 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
1144 .process_pkt = usbtouch_process_multi,
1145 .get_pkt_len = eturbo_get_pkt_len,
1146 .read_data = eturbo_read_data,
1150 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
1157 .read_data = gunze_read_data,
1161 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
1168 .init = dmc_tsc10_init,
1169 .read_data = dmc_tsc10_read_data,
1173 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
1180 .read_data = irtouch_read_data,
1184 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
1191 .process_pkt = usbtouch_process_multi,
1192 .get_pkt_len = idealtek_get_pkt_len,
1193 .read_data = idealtek_read_data,
1197 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1204 .read_data = general_touch_read_data,
1208 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
1215 .read_data = gotop_read_data,
1219 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
1226 .read_data = jastec_read_data,
1230 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
1238 .read_data = e2i_read_data,
1242 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1249 .read_data = zytronic_read_data,
1254 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1261 .read_data = tc45usb_read_data,
1265 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1269 .read_data = nexio_read_data,
1270 .alloc = nexio_alloc,
1275 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
1282 .process_pkt = usbtouch_process_multi,
1283 .get_pkt_len = etouch_get_pkt_len,
1284 .read_data = etouch_read_data,
1293 static void usbtouch_process_pkt(
struct usbtouch_usb *usbtouch,
1294 unsigned char *pkt,
int len)
1304 input_report_abs(usbtouch->
input,
ABS_X, usbtouch->
y);
1305 input_report_abs(usbtouch->
input,
ABS_Y, usbtouch->
x);
1307 input_report_abs(usbtouch->
input,
ABS_X, usbtouch->
x);
1308 input_report_abs(usbtouch->
input,
ABS_Y, usbtouch->
y);
1312 input_sync(usbtouch->
input);
1317 static void usbtouch_process_multi(
struct usbtouch_usb *usbtouch,
1318 unsigned char *pkt,
int len)
1326 pkt_len = usbtouch->
type->get_pkt_len(
1338 if (usbtouch->
buf_len + append >= usbtouch->
type->rept_size)
1343 pkt_len = usbtouch->
type->get_pkt_len(
1350 tmp = pkt_len - usbtouch->
buf_len;
1351 if (usbtouch->
buf_len + tmp >= usbtouch->
type->rept_size)
1354 usbtouch_process_pkt(usbtouch, usbtouch->
buffer, pkt_len);
1357 buf_len = len -
tmp;
1365 while (pos < buf_len) {
1367 pkt_len = usbtouch->
type->get_pkt_len(buffer + pos,
1377 if (
likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
1378 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
1395 static void usbtouch_irq(
struct urb *
urb)
1401 switch (urb->status) {
1408 "%s - urb timed out - was the device unplugged?\n",
1416 dev_dbg(dev,
"%s - urb shutting down with status: %d\n",
1417 __func__, urb->status);
1420 dev_dbg(dev,
"%s - nonzero urb status received: %d\n",
1421 __func__, urb->status);
1425 usbtouch->
type->process_pkt(usbtouch, usbtouch->
data, urb->actual_length);
1428 usb_mark_last_busy(interface_to_usbdev(usbtouch->
interface));
1431 dev_err(dev,
"%s - usb_submit_urb failed with result: %d\n",
1435 static int usbtouch_open(
struct input_dev *
input)
1437 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1440 usbtouch->
irq->dev = interface_to_usbdev(usbtouch->
interface);
1442 r = usb_autopm_get_interface(usbtouch->
interface) ? -
EIO : 0;
1446 if (!usbtouch->
type->irq_always) {
1453 usbtouch->
interface->needs_remote_wakeup = 1;
1455 usb_autopm_put_interface(usbtouch->
interface);
1460 static void usbtouch_close(
struct input_dev *input)
1462 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1465 if (!usbtouch->
type->irq_always)
1467 r = usb_autopm_get_interface(usbtouch->
interface);
1468 usbtouch->
interface->needs_remote_wakeup = 0;
1470 usb_autopm_put_interface(usbtouch->
interface);
1473 static int usbtouch_suspend
1476 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1485 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1486 struct input_dev *input = usbtouch->
input;
1490 if (input->users || usbtouch->
type->irq_always)
1497 static int usbtouch_reset_resume(
struct usb_interface *intf)
1499 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1500 struct input_dev *input = usbtouch->
input;
1504 if (usbtouch->
type->init) {
1505 err = usbtouch->
type->init(usbtouch);
1508 "%s - type->init() failed, err: %d\n",
1523 static void usbtouch_free_buffers(
struct usb_device *udev,
1532 usbtouch_get_input_endpoint(
struct usb_host_interface *
interface)
1536 for (i = 0; i < interface->desc.bNumEndpoints; i++)
1537 if (usb_endpoint_dir_in(&interface->endpoint[i].desc))
1538 return &interface->endpoint[
i].desc;
1547 struct input_dev *input_dev;
1549 struct usb_device *udev = interface_to_usbdev(intf);
1557 endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
1562 input_dev = input_allocate_device();
1563 if (!usbtouch || !input_dev)
1566 type = &usbtouch_dev_info[
id->driver_info];
1573 if (!usbtouch->
data)
1579 goto out_free_buffers;
1583 if (!usbtouch->
irq) {
1585 "%s - usb_alloc_urb failed: usbtouch->irq\n", __func__);
1586 goto out_free_buffers;
1590 usbtouch->
input = input_dev;
1592 if (udev->manufacturer)
1595 if (udev->product) {
1596 if (udev->manufacturer)
1603 "USB Touchscreen %04x:%04x",
1607 usb_make_path(udev, usbtouch->
phys,
sizeof(usbtouch->
phys));
1610 input_dev->name = usbtouch->
name;
1611 input_dev->phys = usbtouch->
phys;
1612 usb_to_input_id(udev, &input_dev->id);
1613 input_dev->dev.parent = &intf->dev;
1615 input_set_drvdata(input_dev, usbtouch);
1617 input_dev->open = usbtouch_open;
1618 input_dev->close = usbtouch_close;
1629 usb_fill_int_urb(usbtouch->
irq, udev,
1632 usbtouch_irq, usbtouch, endpoint->
bInterval);
1634 usb_fill_bulk_urb(usbtouch->
irq, udev,
1637 usbtouch_irq, usbtouch);
1641 usbtouch->
irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1645 err = type->
alloc(usbtouch);
1648 "%s - type->alloc() failed, err: %d\n",
1656 err = type->
init(usbtouch);
1659 "%s - type->init() failed, err: %d\n",
1665 err = input_register_device(usbtouch->
input);
1668 "%s - input_register_device failed, err: %d\n",
1673 usb_set_intfdata(intf, usbtouch);
1675 if (usbtouch->
type->irq_always) {
1677 usb_autopm_get_interface(intf);
1680 usb_autopm_put_interface(intf);
1682 "%s - usb_submit_urb failed with result: %d\n",
1684 goto out_unregister_input;
1690 out_unregister_input:
1691 input_unregister_device(input_dev);
1695 type->
exit(usbtouch);
1699 usbtouch_free_buffers(udev, usbtouch);
1701 input_free_device(input_dev);
1708 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1714 "%s - usbtouch is initialized, cleaning up\n", __func__);
1716 usb_set_intfdata(intf,
NULL);
1718 input_unregister_device(usbtouch->
input);
1720 if (usbtouch->
type->exit)
1721 usbtouch->
type->exit(usbtouch);
1722 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1728 static struct usb_driver usbtouch_driver = {
1729 .name =
"usbtouchscreen",
1730 .probe = usbtouch_probe,
1731 .disconnect = usbtouch_disconnect,
1732 .suspend = usbtouch_suspend,
1733 .resume = usbtouch_resume,
1734 .reset_resume = usbtouch_reset_resume,
1735 .id_table = usbtouch_devices,
1736 .supports_autosuspend = 1,