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