aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/usbtouchscreen.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/touchscreen/usbtouchscreen.c')
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c425
1 files changed, 401 insertions, 24 deletions
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 68ece5801a58..99330bbdbac7 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -14,6 +14,8 @@
14 * - General Touch 14 * - General Touch
15 * - GoTop Super_Q2/GogoPen/PenPower tablets 15 * - GoTop Super_Q2/GogoPen/PenPower tablets
16 * - JASTEC USB touch controller/DigiTech DTR-02U 16 * - JASTEC USB touch controller/DigiTech DTR-02U
17 * - Zytronic capacitive touchscreen
18 * - NEXIO/iNexio
17 * 19 *
18 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch> 20 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
19 * Copyright (C) by Todd E. Johnson (mtouchusb.c) 21 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
@@ -73,6 +75,15 @@ struct usbtouch_device_info {
73 int min_press, max_press; 75 int min_press, max_press;
74 int rept_size; 76 int rept_size;
75 77
78 /*
79 * Always service the USB devices irq not just when the input device is
80 * open. This is useful when devices have a watchdog which prevents us
81 * from periodically polling the device. Leave this unset unless your
82 * touchscreen device requires it, as it does consume more of the USB
83 * bandwidth.
84 */
85 bool irq_always;
86
76 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len); 87 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
77 88
78 /* 89 /*
@@ -85,6 +96,7 @@ struct usbtouch_device_info {
85 96
86 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt); 97 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
87 int (*init) (struct usbtouch_usb *usbtouch); 98 int (*init) (struct usbtouch_usb *usbtouch);
99 void (*exit) (struct usbtouch_usb *usbtouch);
88}; 100};
89 101
90/* a usbtouch device */ 102/* a usbtouch device */
@@ -94,11 +106,12 @@ struct usbtouch_usb {
94 unsigned char *buffer; 106 unsigned char *buffer;
95 int buf_len; 107 int buf_len;
96 struct urb *irq; 108 struct urb *irq;
97 struct usb_device *udev; 109 struct usb_interface *interface;
98 struct input_dev *input; 110 struct input_dev *input;
99 struct usbtouch_device_info *type; 111 struct usbtouch_device_info *type;
100 char name[128]; 112 char name[128];
101 char phys[64]; 113 char phys[64];
114 void *priv;
102 115
103 int x, y; 116 int x, y;
104 int touch, press; 117 int touch, press;
@@ -121,6 +134,9 @@ enum {
121 DEVTYPE_GOTOP, 134 DEVTYPE_GOTOP,
122 DEVTYPE_JASTEC, 135 DEVTYPE_JASTEC,
123 DEVTYPE_E2I, 136 DEVTYPE_E2I,
137 DEVTYPE_ZYTRONIC,
138 DEVTYPE_TC5UH,
139 DEVTYPE_NEXIO,
124}; 140};
125 141
126#define USB_DEVICE_HID_CLASS(vend, prod) \ 142#define USB_DEVICE_HID_CLASS(vend, prod) \
@@ -132,7 +148,7 @@ enum {
132 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \ 148 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
133 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE 149 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
134 150
135static struct usb_device_id usbtouch_devices[] = { 151static const struct usb_device_id usbtouch_devices[] = {
136#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX 152#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
137 /* ignore the HID capable devices, handled by usbhid */ 153 /* ignore the HID capable devices, handled by usbhid */
138 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE}, 154 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
@@ -201,6 +217,23 @@ static struct usb_device_id usbtouch_devices[] = {
201#ifdef CONFIG_TOUCHSCREEN_USB_E2I 217#ifdef CONFIG_TOUCHSCREEN_USB_E2I
202 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I}, 218 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
203#endif 219#endif
220
221#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
222 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
223#endif
224
225#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
226 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH},
227#endif
228
229#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
230 /* data interface only */
231 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
232 .driver_info = DEVTYPE_NEXIO},
233 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
234 .driver_info = DEVTYPE_NEXIO},
235#endif
236
204 {} 237 {}
205}; 238};
206 239
@@ -213,8 +246,9 @@ static struct usb_device_id usbtouch_devices[] = {
213static int e2i_init(struct usbtouch_usb *usbtouch) 246static int e2i_init(struct usbtouch_usb *usbtouch)
214{ 247{
215 int ret; 248 int ret;
249 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
216 250
217 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0), 251 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
218 0x01, 0x02, 0x0000, 0x0081, 252 0x01, 0x02, 0x0000, 0x0081,
219 NULL, 0, USB_CTRL_SET_TIMEOUT); 253 NULL, 0, USB_CTRL_SET_TIMEOUT);
220 254
@@ -323,8 +357,9 @@ static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
323static int mtouch_init(struct usbtouch_usb *usbtouch) 357static int mtouch_init(struct usbtouch_usb *usbtouch)
324{ 358{
325 int ret, i; 359 int ret, i;
360 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
326 361
327 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0), 362 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
328 MTOUCHUSB_RESET, 363 MTOUCHUSB_RESET,
329 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 364 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
330 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 365 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
@@ -335,7 +370,7 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
335 msleep(150); 370 msleep(150);
336 371
337 for (i = 0; i < 3; i++) { 372 for (i = 0; i < 3; i++) {
338 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0), 373 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
339 MTOUCHUSB_ASYNC_REPORT, 374 MTOUCHUSB_ASYNC_REPORT,
340 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 375 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
341 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); 376 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
@@ -468,7 +503,7 @@ static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
468 503
469static int dmc_tsc10_init(struct usbtouch_usb *usbtouch) 504static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
470{ 505{
471 struct usb_device *dev = usbtouch->udev; 506 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
472 int ret = -ENOMEM; 507 int ret = -ENOMEM;
473 unsigned char *buf; 508 unsigned char *buf;
474 509
@@ -538,6 +573,19 @@ static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
538} 573}
539#endif 574#endif
540 575
576/*****************************************************************************
577 * ET&T TC5UH part
578 */
579#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
580static int tc5uh_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
581{
582 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
583 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
584 dev->touch = pkt[0] & 0x01;
585
586 return 1;
587}
588#endif
541 589
542/***************************************************************************** 590/*****************************************************************************
543 * IdealTEK URTC1000 Part 591 * IdealTEK URTC1000 Part
@@ -584,8 +632,8 @@ static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
584#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH 632#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
585static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) 633static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
586{ 634{
587 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ; 635 dev->x = (pkt[2] << 8) | pkt[1];
588 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ; 636 dev->y = (pkt[4] << 8) | pkt[3];
589 dev->press = pkt[5] & 0xff; 637 dev->press = pkt[5] & 0xff;
590 dev->touch = pkt[0] & 0x01; 638 dev->touch = pkt[0] & 0x01;
591 639
@@ -621,6 +669,262 @@ static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
621} 669}
622#endif 670#endif
623 671
672/*****************************************************************************
673 * Zytronic Part
674 */
675#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
676static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
677{
678 switch (pkt[0]) {
679 case 0x3A: /* command response */
680 dbg("%s: Command response %d", __func__, pkt[1]);
681 break;
682
683 case 0xC0: /* down */
684 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
685 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
686 dev->touch = 1;
687 dbg("%s: down %d,%d", __func__, dev->x, dev->y);
688 return 1;
689
690 case 0x80: /* up */
691 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
692 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
693 dev->touch = 0;
694 dbg("%s: up %d,%d", __func__, dev->x, dev->y);
695 return 1;
696
697 default:
698 dbg("%s: Unknown return %d", __func__, pkt[0]);
699 break;
700 }
701
702 return 0;
703}
704#endif
705
706/*****************************************************************************
707 * NEXIO Part
708 */
709#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
710
711#define NEXIO_TIMEOUT 5000
712#define NEXIO_BUFSIZE 1024
713#define NEXIO_THRESHOLD 50
714
715struct nexio_priv {
716 struct urb *ack;
717 unsigned char *ack_buf;
718};
719
720struct nexio_touch_packet {
721 u8 flags; /* 0xe1 = touch, 0xe1 = release */
722 __be16 data_len; /* total bytes of touch data */
723 __be16 x_len; /* bytes for X axis */
724 __be16 y_len; /* bytes for Y axis */
725 u8 data[];
726} __attribute__ ((packed));
727
728static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 };
729static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f };
730
731static void nexio_ack_complete(struct urb *urb)
732{
733}
734
735static int nexio_init(struct usbtouch_usb *usbtouch)
736{
737 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
738 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
739 struct nexio_priv *priv;
740 int ret = -ENOMEM;
741 int actual_len, i;
742 unsigned char *buf;
743 char *firmware_ver = NULL, *device_name = NULL;
744 int input_ep = 0, output_ep = 0;
745
746 /* find first input and output endpoint */
747 for (i = 0; i < interface->desc.bNumEndpoints; i++) {
748 if (!input_ep &&
749 usb_endpoint_dir_in(&interface->endpoint[i].desc))
750 input_ep = interface->endpoint[i].desc.bEndpointAddress;
751 if (!output_ep &&
752 usb_endpoint_dir_out(&interface->endpoint[i].desc))
753 output_ep = interface->endpoint[i].desc.bEndpointAddress;
754 }
755 if (!input_ep || !output_ep)
756 return -ENXIO;
757
758 buf = kmalloc(NEXIO_BUFSIZE, GFP_KERNEL);
759 if (!buf)
760 goto out_buf;
761
762 /* two empty reads */
763 for (i = 0; i < 2; i++) {
764 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
765 buf, NEXIO_BUFSIZE, &actual_len,
766 NEXIO_TIMEOUT);
767 if (ret < 0)
768 goto out_buf;
769 }
770
771 /* send init command */
772 memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt));
773 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep),
774 buf, sizeof(nexio_init_pkt), &actual_len,
775 NEXIO_TIMEOUT);
776 if (ret < 0)
777 goto out_buf;
778
779 /* read replies */
780 for (i = 0; i < 3; i++) {
781 memset(buf, 0, NEXIO_BUFSIZE);
782 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
783 buf, NEXIO_BUFSIZE, &actual_len,
784 NEXIO_TIMEOUT);
785 if (ret < 0 || actual_len < 1 || buf[1] != actual_len)
786 continue;
787 switch (buf[0]) {
788 case 0x83: /* firmware version */
789 if (!firmware_ver)
790 firmware_ver = kstrdup(&buf[2], GFP_KERNEL);
791 break;
792 case 0x84: /* device name */
793 if (!device_name)
794 device_name = kstrdup(&buf[2], GFP_KERNEL);
795 break;
796 }
797 }
798
799 printk(KERN_INFO "Nexio device: %s, firmware version: %s\n",
800 device_name, firmware_ver);
801
802 kfree(firmware_ver);
803 kfree(device_name);
804
805 /* prepare ACK URB */
806 ret = -ENOMEM;
807
808 usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
809 if (!usbtouch->priv)
810 goto out_buf;
811
812 priv = usbtouch->priv;
813
814 priv->ack_buf = kmalloc(sizeof(nexio_ack_pkt), GFP_KERNEL);
815 if (!priv->ack_buf)
816 goto err_priv;
817
818 memcpy(priv->ack_buf, nexio_ack_pkt, sizeof(nexio_ack_pkt));
819
820 priv->ack = usb_alloc_urb(0, GFP_KERNEL);
821 if (!priv->ack) {
822 dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
823 goto err_ack_buf;
824 }
825
826 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep),
827 priv->ack_buf, sizeof(nexio_ack_pkt),
828 nexio_ack_complete, usbtouch);
829 ret = 0;
830 goto out_buf;
831
832err_ack_buf:
833 kfree(priv->ack_buf);
834err_priv:
835 kfree(priv);
836out_buf:
837 kfree(buf);
838 return ret;
839}
840
841static void nexio_exit(struct usbtouch_usb *usbtouch)
842{
843 struct nexio_priv *priv = usbtouch->priv;
844
845 usb_kill_urb(priv->ack);
846 usb_free_urb(priv->ack);
847 kfree(priv->ack_buf);
848 kfree(priv);
849}
850
851static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
852{
853 int x, y, begin_x, begin_y, end_x, end_y, w, h, ret;
854 struct nexio_touch_packet *packet = (void *) pkt;
855 struct nexio_priv *priv = usbtouch->priv;
856
857 /* got touch data? */
858 if ((pkt[0] & 0xe0) != 0xe0)
859 return 0;
860
861 /* send ACK */
862 ret = usb_submit_urb(priv->ack, GFP_ATOMIC);
863
864 if (!usbtouch->type->max_xc) {
865 usbtouch->type->max_xc = 2 * be16_to_cpu(packet->x_len);
866 input_set_abs_params(usbtouch->input, ABS_X, 0,
867 2 * be16_to_cpu(packet->x_len), 0, 0);
868 usbtouch->type->max_yc = 2 * be16_to_cpu(packet->y_len);
869 input_set_abs_params(usbtouch->input, ABS_Y, 0,
870 2 * be16_to_cpu(packet->y_len), 0, 0);
871 }
872 /*
873 * The device reports state of IR sensors on X and Y axes.
874 * Each byte represents "darkness" percentage (0-100) of one element.
875 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
876 * This also means that there's a limited multi-touch capability but
877 * it's disabled (and untested) here as there's no X driver for that.
878 */
879 begin_x = end_x = begin_y = end_y = -1;
880 for (x = 0; x < be16_to_cpu(packet->x_len); x++) {
881 if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) {
882 begin_x = x;
883 continue;
884 }
885 if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) {
886 end_x = x - 1;
887 for (y = be16_to_cpu(packet->x_len);
888 y < be16_to_cpu(packet->data_len); y++) {
889 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
890 begin_y = y - be16_to_cpu(packet->x_len);
891 continue;
892 }
893 if (end_y == -1 &&
894 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
895 end_y = y - 1 - be16_to_cpu(packet->x_len);
896 w = end_x - begin_x;
897 h = end_y - begin_y;
898#if 0
899 /* multi-touch */
900 input_report_abs(usbtouch->input,
901 ABS_MT_TOUCH_MAJOR, max(w,h));
902 input_report_abs(usbtouch->input,
903 ABS_MT_TOUCH_MINOR, min(x,h));
904 input_report_abs(usbtouch->input,
905 ABS_MT_POSITION_X, 2*begin_x+w);
906 input_report_abs(usbtouch->input,
907 ABS_MT_POSITION_Y, 2*begin_y+h);
908 input_report_abs(usbtouch->input,
909 ABS_MT_ORIENTATION, w > h);
910 input_mt_sync(usbtouch->input);
911#endif
912 /* single touch */
913 usbtouch->x = 2 * begin_x + w;
914 usbtouch->y = 2 * begin_y + h;
915 usbtouch->touch = packet->flags & 0x01;
916 begin_y = end_y = -1;
917 return 1;
918 }
919 }
920 begin_x = end_x = -1;
921 }
922
923 }
924 return 0;
925}
926#endif
927
624 928
625/***************************************************************************** 929/*****************************************************************************
626 * the different device descriptors 930 * the different device descriptors
@@ -742,9 +1046,9 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
742#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH 1046#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
743 [DEVTYPE_GENERAL_TOUCH] = { 1047 [DEVTYPE_GENERAL_TOUCH] = {
744 .min_xc = 0x0, 1048 .min_xc = 0x0,
745 .max_xc = 0x0500, 1049 .max_xc = 0x7fff,
746 .min_yc = 0x0, 1050 .min_yc = 0x0,
747 .max_yc = 0x0500, 1051 .max_yc = 0x7fff,
748 .rept_size = 7, 1052 .rept_size = 7,
749 .read_data = general_touch_read_data, 1053 .read_data = general_touch_read_data,
750 }, 1054 },
@@ -783,6 +1087,39 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
783 .read_data = e2i_read_data, 1087 .read_data = e2i_read_data,
784 }, 1088 },
785#endif 1089#endif
1090
1091#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1092 [DEVTYPE_ZYTRONIC] = {
1093 .min_xc = 0x0,
1094 .max_xc = 0x03ff,
1095 .min_yc = 0x0,
1096 .max_yc = 0x03ff,
1097 .rept_size = 5,
1098 .read_data = zytronic_read_data,
1099 .irq_always = true,
1100 },
1101#endif
1102
1103#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
1104 [DEVTYPE_TC5UH] = {
1105 .min_xc = 0x0,
1106 .max_xc = 0x0fff,
1107 .min_yc = 0x0,
1108 .max_yc = 0x0fff,
1109 .rept_size = 5,
1110 .read_data = tc5uh_read_data,
1111 },
1112#endif
1113
1114#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1115 [DEVTYPE_NEXIO] = {
1116 .rept_size = 128,
1117 .irq_always = true,
1118 .read_data = nexio_read_data,
1119 .init = nexio_init,
1120 .exit = nexio_exit,
1121 },
1122#endif
786}; 1123};
787 1124
788 1125
@@ -908,6 +1245,7 @@ static void usbtouch_irq(struct urb *urb)
908 case -ECONNRESET: 1245 case -ECONNRESET:
909 case -ENOENT: 1246 case -ENOENT:
910 case -ESHUTDOWN: 1247 case -ESHUTDOWN:
1248 case -EPIPE:
911 /* this urb is terminated, clean up */ 1249 /* this urb is terminated, clean up */
912 dbg("%s - urb shutting down with status: %d", 1250 dbg("%s - urb shutting down with status: %d",
913 __func__, urb->status); 1251 __func__, urb->status);
@@ -931,10 +1269,12 @@ static int usbtouch_open(struct input_dev *input)
931{ 1269{
932 struct usbtouch_usb *usbtouch = input_get_drvdata(input); 1270 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
933 1271
934 usbtouch->irq->dev = usbtouch->udev; 1272 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
935 1273
936 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) 1274 if (!usbtouch->type->irq_always) {
937 return -EIO; 1275 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
1276 return -EIO;
1277 }
938 1278
939 return 0; 1279 return 0;
940} 1280}
@@ -943,7 +1283,8 @@ static void usbtouch_close(struct input_dev *input)
943{ 1283{
944 struct usbtouch_usb *usbtouch = input_get_drvdata(input); 1284 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
945 1285
946 usb_kill_urb(usbtouch->irq); 1286 if (!usbtouch->type->irq_always)
1287 usb_kill_urb(usbtouch->irq);
947} 1288}
948 1289
949 1290
@@ -955,13 +1296,23 @@ static void usbtouch_free_buffers(struct usb_device *udev,
955 kfree(usbtouch->buffer); 1296 kfree(usbtouch->buffer);
956} 1297}
957 1298
1299static struct usb_endpoint_descriptor *
1300usbtouch_get_input_endpoint(struct usb_host_interface *interface)
1301{
1302 int i;
1303
1304 for (i = 0; i < interface->desc.bNumEndpoints; i++)
1305 if (usb_endpoint_dir_in(&interface->endpoint[i].desc))
1306 return &interface->endpoint[i].desc;
1307
1308 return NULL;
1309}
958 1310
959static int usbtouch_probe(struct usb_interface *intf, 1311static int usbtouch_probe(struct usb_interface *intf,
960 const struct usb_device_id *id) 1312 const struct usb_device_id *id)
961{ 1313{
962 struct usbtouch_usb *usbtouch; 1314 struct usbtouch_usb *usbtouch;
963 struct input_dev *input_dev; 1315 struct input_dev *input_dev;
964 struct usb_host_interface *interface;
965 struct usb_endpoint_descriptor *endpoint; 1316 struct usb_endpoint_descriptor *endpoint;
966 struct usb_device *udev = interface_to_usbdev(intf); 1317 struct usb_device *udev = interface_to_usbdev(intf);
967 struct usbtouch_device_info *type; 1318 struct usbtouch_device_info *type;
@@ -971,8 +1322,9 @@ static int usbtouch_probe(struct usb_interface *intf,
971 if (id->driver_info == DEVTYPE_IGNORE) 1322 if (id->driver_info == DEVTYPE_IGNORE)
972 return -ENODEV; 1323 return -ENODEV;
973 1324
974 interface = intf->cur_altsetting; 1325 endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
975 endpoint = &interface->endpoint[0].desc; 1326 if (!endpoint)
1327 return -ENXIO;
976 1328
977 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL); 1329 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
978 input_dev = input_allocate_device(); 1330 input_dev = input_allocate_device();
@@ -1001,7 +1353,7 @@ static int usbtouch_probe(struct usb_interface *intf,
1001 goto out_free_buffers; 1353 goto out_free_buffers;
1002 } 1354 }
1003 1355
1004 usbtouch->udev = udev; 1356 usbtouch->interface = intf;
1005 usbtouch->input = input_dev; 1357 usbtouch->input = input_dev;
1006 1358
1007 if (udev->manufacturer) 1359 if (udev->manufacturer)
@@ -1040,12 +1392,18 @@ static int usbtouch_probe(struct usb_interface *intf,
1040 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press, 1392 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1041 type->max_press, 0, 0); 1393 type->max_press, 0, 0);
1042 1394
1043 usb_fill_int_urb(usbtouch->irq, usbtouch->udev, 1395 if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT)
1044 usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress), 1396 usb_fill_int_urb(usbtouch->irq, udev,
1397 usb_rcvintpipe(udev, endpoint->bEndpointAddress),
1045 usbtouch->data, type->rept_size, 1398 usbtouch->data, type->rept_size,
1046 usbtouch_irq, usbtouch, endpoint->bInterval); 1399 usbtouch_irq, usbtouch, endpoint->bInterval);
1400 else
1401 usb_fill_bulk_urb(usbtouch->irq, udev,
1402 usb_rcvbulkpipe(udev, endpoint->bEndpointAddress),
1403 usbtouch->data, type->rept_size,
1404 usbtouch_irq, usbtouch);
1047 1405
1048 usbtouch->irq->dev = usbtouch->udev; 1406 usbtouch->irq->dev = udev;
1049 usbtouch->irq->transfer_dma = usbtouch->data_dma; 1407 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1050 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1408 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1051 1409
@@ -1054,20 +1412,37 @@ static int usbtouch_probe(struct usb_interface *intf,
1054 err = type->init(usbtouch); 1412 err = type->init(usbtouch);
1055 if (err) { 1413 if (err) {
1056 dbg("%s - type->init() failed, err: %d", __func__, err); 1414 dbg("%s - type->init() failed, err: %d", __func__, err);
1057 goto out_free_buffers; 1415 goto out_free_urb;
1058 } 1416 }
1059 } 1417 }
1060 1418
1061 err = input_register_device(usbtouch->input); 1419 err = input_register_device(usbtouch->input);
1062 if (err) { 1420 if (err) {
1063 dbg("%s - input_register_device failed, err: %d", __func__, err); 1421 dbg("%s - input_register_device failed, err: %d", __func__, err);
1064 goto out_free_buffers; 1422 goto out_do_exit;
1065 } 1423 }
1066 1424
1067 usb_set_intfdata(intf, usbtouch); 1425 usb_set_intfdata(intf, usbtouch);
1068 1426
1427 if (usbtouch->type->irq_always) {
1428 err = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1429 if (err) {
1430 err("%s - usb_submit_urb failed with result: %d",
1431 __func__, err);
1432 goto out_unregister_input;
1433 }
1434 }
1435
1069 return 0; 1436 return 0;
1070 1437
1438out_unregister_input:
1439 input_unregister_device(input_dev);
1440 input_dev = NULL;
1441out_do_exit:
1442 if (type->exit)
1443 type->exit(usbtouch);
1444out_free_urb:
1445 usb_free_urb(usbtouch->irq);
1071out_free_buffers: 1446out_free_buffers:
1072 usbtouch_free_buffers(udev, usbtouch); 1447 usbtouch_free_buffers(udev, usbtouch);
1073out_free: 1448out_free:
@@ -1087,9 +1462,11 @@ static void usbtouch_disconnect(struct usb_interface *intf)
1087 1462
1088 dbg("%s - usbtouch is initialized, cleaning up", __func__); 1463 dbg("%s - usbtouch is initialized, cleaning up", __func__);
1089 usb_set_intfdata(intf, NULL); 1464 usb_set_intfdata(intf, NULL);
1090 usb_kill_urb(usbtouch->irq); 1465 /* this will stop IO via close */
1091 input_unregister_device(usbtouch->input); 1466 input_unregister_device(usbtouch->input);
1092 usb_free_urb(usbtouch->irq); 1467 usb_free_urb(usbtouch->irq);
1468 if (usbtouch->type->exit)
1469 usbtouch->type->exit(usbtouch);
1093 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch); 1470 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1094 kfree(usbtouch); 1471 kfree(usbtouch);
1095} 1472}