Remove all inclusions of <linux/config.h>
[linux-3.10.git] / drivers / usb / input / usbtouchscreen.c
1 /******************************************************************************
2  * usbtouchscreen.c
3  * Driver for USB Touchscreens, supporting those devices:
4  *  - eGalax Touchkit
5  *    includes eTurboTouch CT-410/510/700
6  *  - 3M/Microtouch  EX II series
7  *  - ITM
8  *  - PanJit TouchSet
9  *  - eTurboTouch
10  *  - Gunze AHL61
11  *
12  * Copyright (C) 2004-2006 by Daniel Ritz <daniel.ritz@gmx.ch>
13  * Copyright (C) by Todd E. Johnson (mtouchusb.c)
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License as
17  * published by the Free Software Foundation; either version 2 of the
18  * License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23  * General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28  *
29  * Driver is based on touchkitusb.c
30  * - ITM parts are from itmtouch.c
31  * - 3M parts are from mtouchusb.c
32  * - PanJit parts are from an unmerged driver by Lanslott Gish
33  *
34  *****************************************************************************/
35
36 //#define DEBUG
37
38 #include <linux/kernel.h>
39 #include <linux/slab.h>
40 #include <linux/input.h>
41 #include <linux/module.h>
42 #include <linux/init.h>
43 #include <linux/usb.h>
44 #include <linux/usb/input.h>
45
46
47 #define DRIVER_VERSION          "v0.4"
48 #define DRIVER_AUTHOR           "Daniel Ritz <daniel.ritz@gmx.ch>"
49 #define DRIVER_DESC             "USB Touchscreen Driver"
50
51 static int swap_xy;
52 module_param(swap_xy, bool, 0644);
53 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
54
55 /* device specifc data/functions */
56 struct usbtouch_usb;
57 struct usbtouch_device_info {
58         int min_xc, max_xc;
59         int min_yc, max_yc;
60         int min_press, max_press;
61         int rept_size;
62         int flags;
63
64         void (*process_pkt) (struct usbtouch_usb *usbtouch, struct pt_regs *regs, unsigned char *pkt, int len);
65         int  (*get_pkt_len) (unsigned char *pkt, int len);
66         int  (*read_data)   (unsigned char *pkt, int *x, int *y, int *touch, int *press);
67         int  (*init)        (struct usbtouch_usb *usbtouch);
68 };
69
70 #define USBTOUCH_FLG_BUFFER     0x01
71
72
73 /* a usbtouch device */
74 struct usbtouch_usb {
75         unsigned char *data;
76         dma_addr_t data_dma;
77         unsigned char *buffer;
78         int buf_len;
79         struct urb *irq;
80         struct usb_device *udev;
81         struct input_dev *input;
82         struct usbtouch_device_info *type;
83         char name[128];
84         char phys[64];
85 };
86
87
88 #if defined(CONFIG_USB_TOUCHSCREEN_EGALAX) || defined(CONFIG_USB_TOUCHSCREEN_ETURBO)
89 #define MULTI_PACKET
90 #endif
91
92 #ifdef MULTI_PACKET
93 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
94                                    struct pt_regs *regs,
95                                    unsigned char *pkt, int len);
96 #endif
97
98 /* device types */
99 enum {
100         DEVTPYE_DUMMY = -1,
101         DEVTYPE_EGALAX,
102         DEVTYPE_PANJIT,
103         DEVTYPE_3M,
104         DEVTYPE_ITM,
105         DEVTYPE_ETURBO,
106         DEVTYPE_GUNZE,
107 };
108
109 static struct usb_device_id usbtouch_devices[] = {
110 #ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
111         {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
112         {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
113         {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
114         {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
115         {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
116         {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
117         {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
118 #endif
119
120 #ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
121         {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
122         {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
123         {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
124         {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
125 #endif
126
127 #ifdef CONFIG_USB_TOUCHSCREEN_3M
128         {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
129 #endif
130
131 #ifdef CONFIG_USB_TOUCHSCREEN_ITM
132         {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
133 #endif
134
135 #ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
136         {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
137 #endif
138
139 #ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
140         {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
141 #endif
142
143         {}
144 };
145
146
147 /*****************************************************************************
148  * eGalax part
149  */
150
151 #ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
152
153 #define EGALAX_PKT_TYPE_MASK            0xFE
154 #define EGALAX_PKT_TYPE_REPT            0x80
155 #define EGALAX_PKT_TYPE_DIAG            0x0A
156
157 static int egalax_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
158 {
159         if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
160                 return 0;
161
162         *x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
163         *y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
164         *touch = pkt[0] & 0x01;
165
166         return 1;
167 }
168
169 static int egalax_get_pkt_len(unsigned char *buf, int len)
170 {
171         switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
172         case EGALAX_PKT_TYPE_REPT:
173                 return 5;
174
175         case EGALAX_PKT_TYPE_DIAG:
176                 if (len < 2)
177                         return -1;
178
179                 return buf[1] + 2;
180         }
181
182         return 0;
183 }
184 #endif
185
186
187 /*****************************************************************************
188  * PanJit Part
189  */
190 #ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
191 static int panjit_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
192 {
193         *x = ((pkt[2] & 0x0F) << 8) | pkt[1];
194         *y = ((pkt[4] & 0x0F) << 8) | pkt[3];
195         *touch = pkt[0] & 0x01;
196
197         return 1;
198 }
199 #endif
200
201
202 /*****************************************************************************
203  * 3M/Microtouch Part
204  */
205 #ifdef CONFIG_USB_TOUCHSCREEN_3M
206
207 #define MTOUCHUSB_ASYNC_REPORT          1
208 #define MTOUCHUSB_RESET                 7
209 #define MTOUCHUSB_REQ_CTRLLR_ID         10
210
211 static int mtouch_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
212 {
213         *x = (pkt[8] << 8) | pkt[7];
214         *y = (pkt[10] << 8) | pkt[9];
215         *touch = (pkt[2] & 0x40) ? 1 : 0;
216
217         return 1;
218 }
219
220 static int mtouch_init(struct usbtouch_usb *usbtouch)
221 {
222         int ret, i;
223
224         ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
225                               MTOUCHUSB_RESET,
226                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
227                               1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
228         dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
229             __FUNCTION__, ret);
230         if (ret < 0)
231                 return ret;
232         msleep(150);
233
234         for (i = 0; i < 3; i++) {
235                 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
236                                       MTOUCHUSB_ASYNC_REPORT,
237                                       USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
238                                       1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
239                 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
240                     __FUNCTION__, ret);
241                 if (ret >= 0)
242                         break;
243                 if (ret != -EPIPE)
244                         return ret;
245         }
246
247         return 0;
248 }
249 #endif
250
251
252 /*****************************************************************************
253  * ITM Part
254  */
255 #ifdef CONFIG_USB_TOUCHSCREEN_ITM
256 static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
257 {
258         *x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
259         *y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
260         *press = ((pkt[2] & 0x1F) << 7) | (pkt[5] & 0x7F);
261         *touch = ~pkt[7] & 0x20;
262
263         return 1;
264 }
265 #endif
266
267
268 /*****************************************************************************
269  * eTurboTouch part
270  */
271 #ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
272 static int eturbo_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
273 {
274         unsigned int shift;
275
276         /* packets should start with sync */
277         if (!(pkt[0] & 0x80))
278                 return 0;
279
280         shift = (6 - (pkt[0] & 0x03));
281         *x = ((pkt[3] << 7) | pkt[4]) >> shift;
282         *y = ((pkt[1] << 7) | pkt[2]) >> shift;
283         *touch = (pkt[0] & 0x10) ? 1 : 0;
284
285         return 1;
286 }
287
288 static int eturbo_get_pkt_len(unsigned char *buf, int len)
289 {
290         if (buf[0] & 0x80)
291                 return 5;
292         if (buf[0] == 0x01)
293                 return 3;
294         return 0;
295 }
296 #endif
297
298
299 /*****************************************************************************
300  * Gunze part
301  */
302 #ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
303 static int gunze_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
304 {
305         if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
306                 return 0;
307
308         *x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
309         *y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
310         *touch = pkt[0] & 0x20;
311
312         return 1;
313 }
314 #endif
315
316 /*****************************************************************************
317  * the different device descriptors
318  */
319 static struct usbtouch_device_info usbtouch_dev_info[] = {
320 #ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
321         [DEVTYPE_EGALAX] = {
322                 .min_xc         = 0x0,
323                 .max_xc         = 0x07ff,
324                 .min_yc         = 0x0,
325                 .max_yc         = 0x07ff,
326                 .rept_size      = 16,
327                 .flags          = USBTOUCH_FLG_BUFFER,
328                 .process_pkt    = usbtouch_process_multi,
329                 .get_pkt_len    = egalax_get_pkt_len,
330                 .read_data      = egalax_read_data,
331         },
332 #endif
333
334 #ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
335         [DEVTYPE_PANJIT] = {
336                 .min_xc         = 0x0,
337                 .max_xc         = 0x0fff,
338                 .min_yc         = 0x0,
339                 .max_yc         = 0x0fff,
340                 .rept_size      = 8,
341                 .read_data      = panjit_read_data,
342         },
343 #endif
344
345 #ifdef CONFIG_USB_TOUCHSCREEN_3M
346         [DEVTYPE_3M] = {
347                 .min_xc         = 0x0,
348                 .max_xc         = 0x4000,
349                 .min_yc         = 0x0,
350                 .max_yc         = 0x4000,
351                 .rept_size      = 11,
352                 .read_data      = mtouch_read_data,
353                 .init           = mtouch_init,
354         },
355 #endif
356
357 #ifdef CONFIG_USB_TOUCHSCREEN_ITM
358         [DEVTYPE_ITM] = {
359                 .min_xc         = 0x0,
360                 .max_xc         = 0x0fff,
361                 .min_yc         = 0x0,
362                 .max_yc         = 0x0fff,
363                 .max_press      = 0xff,
364                 .rept_size      = 8,
365                 .read_data      = itm_read_data,
366         },
367 #endif
368
369 #ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
370         [DEVTYPE_ETURBO] = {
371                 .min_xc         = 0x0,
372                 .max_xc         = 0x07ff,
373                 .min_yc         = 0x0,
374                 .max_yc         = 0x07ff,
375                 .rept_size      = 8,
376                 .flags          = USBTOUCH_FLG_BUFFER,
377                 .process_pkt    = usbtouch_process_multi,
378                 .get_pkt_len    = eturbo_get_pkt_len,
379                 .read_data      = eturbo_read_data,
380         },
381 #endif
382
383 #ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
384         [DEVTYPE_GUNZE] = {
385                 .min_xc         = 0x0,
386                 .max_xc         = 0x0fff,
387                 .min_yc         = 0x0,
388                 .max_yc         = 0x0fff,
389                 .rept_size      = 4,
390                 .read_data      = gunze_read_data,
391         },
392 #endif
393 };
394
395
396 /*****************************************************************************
397  * Generic Part
398  */
399 static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
400                                  struct pt_regs *regs, unsigned char *pkt, int len)
401 {
402         int x, y, touch, press;
403         struct usbtouch_device_info *type = usbtouch->type;
404
405         if (!type->read_data(pkt, &x, &y, &touch, &press))
406                         return;
407
408         input_regs(usbtouch->input, regs);
409         input_report_key(usbtouch->input, BTN_TOUCH, touch);
410
411         if (swap_xy) {
412                 input_report_abs(usbtouch->input, ABS_X, y);
413                 input_report_abs(usbtouch->input, ABS_Y, x);
414         } else {
415                 input_report_abs(usbtouch->input, ABS_X, x);
416                 input_report_abs(usbtouch->input, ABS_Y, y);
417         }
418         if (type->max_press)
419                 input_report_abs(usbtouch->input, ABS_PRESSURE, press);
420         input_sync(usbtouch->input);
421 }
422
423
424 #ifdef MULTI_PACKET
425 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
426                                    struct pt_regs *regs,
427                                    unsigned char *pkt, int len)
428 {
429         unsigned char *buffer;
430         int pkt_len, pos, buf_len, tmp;
431
432         /* process buffer */
433         if (unlikely(usbtouch->buf_len)) {
434                 /* try to get size */
435                 pkt_len = usbtouch->type->get_pkt_len(
436                                 usbtouch->buffer, usbtouch->buf_len);
437
438                 /* drop? */
439                 if (unlikely(!pkt_len))
440                         goto out_flush_buf;
441
442                 /* need to append -pkt_len bytes before able to get size */
443                 if (unlikely(pkt_len < 0)) {
444                         int append = -pkt_len;
445                         if (unlikely(append > len))
446                                append = len;
447                         if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
448                                 goto out_flush_buf;
449                         memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
450                         usbtouch->buf_len += append;
451
452                         pkt_len = usbtouch->type->get_pkt_len(
453                                         usbtouch->buffer, usbtouch->buf_len);
454                         if (pkt_len < 0)
455                                 return;
456                 }
457
458                 /* append */
459                 tmp = pkt_len - usbtouch->buf_len;
460                 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
461                         goto out_flush_buf;
462                 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
463                 usbtouch_process_pkt(usbtouch, regs, usbtouch->buffer, pkt_len);
464
465                 buffer = pkt + tmp;
466                 buf_len = len - tmp;
467         } else {
468                 buffer = pkt;
469                 buf_len = len;
470         }
471
472         /* loop over the received packet, process */
473         pos = 0;
474         while (pos < buf_len) {
475                 /* get packet len */
476                 pkt_len = usbtouch->type->get_pkt_len(buffer + pos, len);
477
478                 /* unknown packet: drop everything */
479                 if (unlikely(!pkt_len))
480                         goto out_flush_buf;
481
482                 /* full packet: process */
483                 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
484                         usbtouch_process_pkt(usbtouch, regs, buffer + pos, pkt_len);
485                 } else {
486                         /* incomplete packet: save in buffer */
487                         memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
488                         usbtouch->buf_len = buf_len - pos;
489                         return;
490                 }
491                 pos += pkt_len;
492         }
493
494 out_flush_buf:
495         usbtouch->buf_len = 0;
496         return;
497 }
498 #endif
499
500
501 static void usbtouch_irq(struct urb *urb, struct pt_regs *regs)
502 {
503         struct usbtouch_usb *usbtouch = urb->context;
504         int retval;
505
506         switch (urb->status) {
507         case 0:
508                 /* success */
509                 break;
510         case -ETIME:
511                 /* this urb is timing out */
512                 dbg("%s - urb timed out - was the device unplugged?",
513                     __FUNCTION__);
514                 return;
515         case -ECONNRESET:
516         case -ENOENT:
517         case -ESHUTDOWN:
518                 /* this urb is terminated, clean up */
519                 dbg("%s - urb shutting down with status: %d",
520                     __FUNCTION__, urb->status);
521                 return;
522         default:
523                 dbg("%s - nonzero urb status received: %d",
524                     __FUNCTION__, urb->status);
525                 goto exit;
526         }
527
528         usbtouch->type->process_pkt(usbtouch, regs, usbtouch->data, urb->actual_length);
529
530 exit:
531         retval = usb_submit_urb(urb, GFP_ATOMIC);
532         if (retval)
533                 err("%s - usb_submit_urb failed with result: %d",
534                     __FUNCTION__, retval);
535 }
536
537 static int usbtouch_open(struct input_dev *input)
538 {
539         struct usbtouch_usb *usbtouch = input->private;
540
541         usbtouch->irq->dev = usbtouch->udev;
542
543         if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
544                 return -EIO;
545
546         return 0;
547 }
548
549 static void usbtouch_close(struct input_dev *input)
550 {
551         struct usbtouch_usb *usbtouch = input->private;
552
553         usb_kill_urb(usbtouch->irq);
554 }
555
556
557 static void usbtouch_free_buffers(struct usb_device *udev,
558                                   struct usbtouch_usb *usbtouch)
559 {
560         if (usbtouch->data)
561                 usb_buffer_free(udev, usbtouch->type->rept_size,
562                                 usbtouch->data, usbtouch->data_dma);
563         kfree(usbtouch->buffer);
564 }
565
566
567 static int usbtouch_probe(struct usb_interface *intf,
568                           const struct usb_device_id *id)
569 {
570         struct usbtouch_usb *usbtouch;
571         struct input_dev *input_dev;
572         struct usb_host_interface *interface;
573         struct usb_endpoint_descriptor *endpoint;
574         struct usb_device *udev = interface_to_usbdev(intf);
575         struct usbtouch_device_info *type;
576         int err = -ENOMEM;
577
578         interface = intf->cur_altsetting;
579         endpoint = &interface->endpoint[0].desc;
580
581         usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
582         input_dev = input_allocate_device();
583         if (!usbtouch || !input_dev)
584                 goto out_free;
585
586         type = &usbtouch_dev_info[id->driver_info];
587         usbtouch->type = type;
588         if (!type->process_pkt)
589                 type->process_pkt = usbtouch_process_pkt;
590
591         usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
592                                           SLAB_KERNEL, &usbtouch->data_dma);
593         if (!usbtouch->data)
594                 goto out_free;
595
596         if (type->flags & USBTOUCH_FLG_BUFFER) {
597                 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
598                 if (!usbtouch->buffer)
599                         goto out_free_buffers;
600         }
601
602         usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
603         if (!usbtouch->irq) {
604                 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __FUNCTION__);
605                 goto out_free_buffers;
606         }
607
608         usbtouch->udev = udev;
609         usbtouch->input = input_dev;
610
611         if (udev->manufacturer)
612                 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
613
614         if (udev->product) {
615                 if (udev->manufacturer)
616                         strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
617                 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
618         }
619
620         if (!strlen(usbtouch->name))
621                 snprintf(usbtouch->name, sizeof(usbtouch->name),
622                         "USB Touchscreen %04x:%04x",
623                          le16_to_cpu(udev->descriptor.idVendor),
624                          le16_to_cpu(udev->descriptor.idProduct));
625
626         usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
627         strlcpy(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
628
629         input_dev->name = usbtouch->name;
630         input_dev->phys = usbtouch->phys;
631         usb_to_input_id(udev, &input_dev->id);
632         input_dev->cdev.dev = &intf->dev;
633         input_dev->private = usbtouch;
634         input_dev->open = usbtouch_open;
635         input_dev->close = usbtouch_close;
636
637         input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
638         input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
639         input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
640         input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
641         if (type->max_press)
642                 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
643                                      type->max_press, 0, 0);
644
645         usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
646                          usb_rcvintpipe(usbtouch->udev, 0x81),
647                          usbtouch->data, type->rept_size,
648                          usbtouch_irq, usbtouch, endpoint->bInterval);
649
650         usbtouch->irq->dev = usbtouch->udev;
651         usbtouch->irq->transfer_dma = usbtouch->data_dma;
652         usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
653
654         /* device specific init */
655         if (type->init) {
656                 err = type->init(usbtouch);
657                 if (err) {
658                         dbg("%s - type->init() failed, err: %d", __FUNCTION__, err);
659                         goto out_free_buffers;
660                 }
661         }
662
663         err = input_register_device(usbtouch->input);
664         if (err) {
665                 dbg("%s - input_register_device failed, err: %d", __FUNCTION__, err);
666                 goto out_free_buffers;
667         }
668
669         usb_set_intfdata(intf, usbtouch);
670
671         return 0;
672
673 out_free_buffers:
674         usbtouch_free_buffers(udev, usbtouch);
675 out_free:
676         input_free_device(input_dev);
677         kfree(usbtouch);
678         return err;
679 }
680
681 static void usbtouch_disconnect(struct usb_interface *intf)
682 {
683         struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
684
685         dbg("%s - called", __FUNCTION__);
686
687         if (!usbtouch)
688                 return;
689
690         dbg("%s - usbtouch is initialized, cleaning up", __FUNCTION__);
691         usb_set_intfdata(intf, NULL);
692         usb_kill_urb(usbtouch->irq);
693         input_unregister_device(usbtouch->input);
694         usb_free_urb(usbtouch->irq);
695         usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
696         kfree(usbtouch);
697 }
698
699 MODULE_DEVICE_TABLE(usb, usbtouch_devices);
700
701 static struct usb_driver usbtouch_driver = {
702         .name           = "usbtouchscreen",
703         .probe          = usbtouch_probe,
704         .disconnect     = usbtouch_disconnect,
705         .id_table       = usbtouch_devices,
706 };
707
708 static int __init usbtouch_init(void)
709 {
710         return usb_register(&usbtouch_driver);
711 }
712
713 static void __exit usbtouch_cleanup(void)
714 {
715         usb_deregister(&usbtouch_driver);
716 }
717
718 module_init(usbtouch_init);
719 module_exit(usbtouch_cleanup);
720
721 MODULE_AUTHOR(DRIVER_AUTHOR);
722 MODULE_DESCRIPTION(DRIVER_DESC);
723 MODULE_LICENSE("GPL");
724
725 MODULE_ALIAS("touchkitusb");
726 MODULE_ALIAS("itmtouch");
727 MODULE_ALIAS("mtouchusb");