blob: fb7cb9bdfbd5c4971cedeb064b8839ae3d09365a [file] [log] [blame]
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001/******************************************************************************
2 * usbtouchscreen.c
3 * Driver for USB Touchscreens, supporting those devices:
4 * - eGalax Touchkit
Daniel Ritz5d892662006-07-31 21:43:24 +02005 * includes eTurboTouch CT-410/510/700
6 * - 3M/Microtouch EX II series
Daniel Ritz1d3e2022006-03-29 22:41:07 +02007 * - ITM
8 * - PanJit TouchSet
Daniel Ritz5d892662006-07-31 21:43:24 +02009 * - eTurboTouch
10 * - Gunze AHL61
Holger Schurig24ced062006-11-17 22:50:15 +010011 * - DMC TSC-10/25
Ondrej Zarydf561fc2007-07-03 01:55:03 -040012 * - IRTOUCHSYSTEMS/UNITOP
Ondrej Zarya14a8402007-09-04 23:45:01 -040013 * - IdealTEK URTC1000
Daniel Ritz62aa3662008-01-17 12:01:18 -050014 * - General Touch
Jerrold Jones14e40202007-10-22 00:59:47 -040015 * - GoTop Super_Q2/GogoPen/PenPower tablets
Daniel Ritz1d3e2022006-03-29 22:41:07 +020016 *
Jerrold Jones14e40202007-10-22 00:59:47 -040017 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
Daniel Ritz1d3e2022006-03-29 22:41:07 +020018 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
19 *
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License as
22 * published by the Free Software Foundation; either version 2 of the
23 * License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful, but
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 *
34 * Driver is based on touchkitusb.c
35 * - ITM parts are from itmtouch.c
36 * - 3M parts are from mtouchusb.c
37 * - PanJit parts are from an unmerged driver by Lanslott Gish
Holger Schurig24ced062006-11-17 22:50:15 +010038 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
39 * driver from Marius Vollmer
Daniel Ritz1d3e2022006-03-29 22:41:07 +020040 *
41 *****************************************************************************/
42
43//#define DEBUG
44
Daniel Ritz1d3e2022006-03-29 22:41:07 +020045#include <linux/kernel.h>
46#include <linux/slab.h>
47#include <linux/input.h>
48#include <linux/module.h>
49#include <linux/init.h>
50#include <linux/usb.h>
David Brownellae0dadc2006-06-13 10:04:34 -070051#include <linux/usb/input.h>
Daniel Ritzec42d442008-07-03 10:45:37 -040052#include <linux/hid.h>
Daniel Ritz1d3e2022006-03-29 22:41:07 +020053
54
Daniel Ritz62aa3662008-01-17 12:01:18 -050055#define DRIVER_VERSION "v0.6"
Daniel Ritz1d3e2022006-03-29 22:41:07 +020056#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
57#define DRIVER_DESC "USB Touchscreen Driver"
58
59static int swap_xy;
60module_param(swap_xy, bool, 0644);
61MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
62
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -080063static int hwcalib_xy;
64module_param(hwcalib_xy, bool, 0644);
65MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
66
Daniel Ritz1d3e2022006-03-29 22:41:07 +020067/* device specifc data/functions */
68struct usbtouch_usb;
69struct usbtouch_device_info {
70 int min_xc, max_xc;
71 int min_yc, max_yc;
72 int min_press, max_press;
73 int rept_size;
Daniel Ritz1d3e2022006-03-29 22:41:07 +020074
David Howells7d12e782006-10-05 14:55:46 +010075 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
Daniel Ritz62aa3662008-01-17 12:01:18 -050076
77 /*
78 * used to get the packet len. possible return values:
79 * > 0: packet len
80 * = 0: skip one byte
81 * < 0: -return value more bytes needed
82 */
Daniel Ritz5d892662006-07-31 21:43:24 +020083 int (*get_pkt_len) (unsigned char *pkt, int len);
Daniel Ritz62aa3662008-01-17 12:01:18 -050084
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +010085 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
Daniel Ritz1d3e2022006-03-29 22:41:07 +020086 int (*init) (struct usbtouch_usb *usbtouch);
87};
88
Daniel Ritz1d3e2022006-03-29 22:41:07 +020089/* a usbtouch device */
90struct usbtouch_usb {
91 unsigned char *data;
92 dma_addr_t data_dma;
93 unsigned char *buffer;
94 int buf_len;
95 struct urb *irq;
96 struct usb_device *udev;
97 struct input_dev *input;
98 struct usbtouch_device_info *type;
99 char name[128];
100 char phys[64];
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100101
102 int x, y;
103 int touch, press;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200104};
105
Daniel Ritz5d892662006-07-31 21:43:24 +0200106
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200107/* device types */
108enum {
Daniel Ritzec42d442008-07-03 10:45:37 -0400109 DEVTYPE_IGNORE = -1,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200110 DEVTYPE_EGALAX,
111 DEVTYPE_PANJIT,
112 DEVTYPE_3M,
113 DEVTYPE_ITM,
Daniel Ritz5d892662006-07-31 21:43:24 +0200114 DEVTYPE_ETURBO,
115 DEVTYPE_GUNZE,
Holger Schurig24ced062006-11-17 22:50:15 +0100116 DEVTYPE_DMC_TSC10,
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400117 DEVTYPE_IRTOUCH,
Ondrej Zarya14a8402007-09-04 23:45:01 -0400118 DEVTYPE_IDEALTEK,
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400119 DEVTYPE_GENERAL_TOUCH,
Jerrold Jones14e40202007-10-22 00:59:47 -0400120 DEVTYPE_GOTOP,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200121};
122
Daniel Ritzec42d442008-07-03 10:45:37 -0400123#define USB_DEVICE_HID_CLASS(vend, prod) \
124 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
Daniel Ritz139ebe82009-02-28 12:50:54 -0800125 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
Daniel Ritzec42d442008-07-03 10:45:37 -0400126 | USB_DEVICE_ID_MATCH_DEVICE, \
127 .idVendor = (vend), \
128 .idProduct = (prod), \
129 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
130 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
131
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200132static struct usb_device_id usbtouch_devices[] = {
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400133#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritzec42d442008-07-03 10:45:37 -0400134 /* ignore the HID capable devices, handled by usbhid */
135 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
136 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
137
138 /* normal device IDs */
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200139 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz5d892662006-07-31 21:43:24 +0200140 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200141 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
142 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
143 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz5d892662006-07-31 21:43:24 +0200144 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
145 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200146#endif
147
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400148#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200149 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
150 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
151 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
152 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
153#endif
154
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400155#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200156 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
157#endif
158
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400159#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200160 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
161#endif
162
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400163#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz5d892662006-07-31 21:43:24 +0200164 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
165#endif
166
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400167#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritz5d892662006-07-31 21:43:24 +0200168 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
169#endif
170
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400171#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100172 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
173#endif
174
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400175#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
176 {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
177 {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
178#endif
179
Ondrej Zarya14a8402007-09-04 23:45:01 -0400180#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
181 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
182#endif
183
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400184#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
185 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
186#endif
187
Jerrold Jones14e40202007-10-22 00:59:47 -0400188#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
189 {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP},
190 {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP},
191 {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP},
192#endif
193
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200194 {}
195};
196
197
198/*****************************************************************************
199 * eGalax part
200 */
201
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400202#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200203
Daniel Ritz62aa3662008-01-17 12:01:18 -0500204#ifndef MULTI_PACKET
205#define MULTI_PACKET
206#endif
207
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200208#define EGALAX_PKT_TYPE_MASK 0xFE
209#define EGALAX_PKT_TYPE_REPT 0x80
210#define EGALAX_PKT_TYPE_DIAG 0x0A
211
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100212static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200213{
214 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
215 return 0;
216
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100217 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
218 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
219 dev->touch = pkt[0] & 0x01;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200220
221 return 1;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200222}
223
Daniel Ritz5d892662006-07-31 21:43:24 +0200224static int egalax_get_pkt_len(unsigned char *buf, int len)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200225{
226 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
227 case EGALAX_PKT_TYPE_REPT:
228 return 5;
229
230 case EGALAX_PKT_TYPE_DIAG:
Daniel Ritz5d892662006-07-31 21:43:24 +0200231 if (len < 2)
232 return -1;
233
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200234 return buf[1] + 2;
235 }
236
237 return 0;
238}
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200239#endif
240
241
242/*****************************************************************************
243 * PanJit Part
244 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400245#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100246static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200247{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100248 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
249 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
250 dev->touch = pkt[0] & 0x01;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200251
252 return 1;
253}
254#endif
255
256
257/*****************************************************************************
258 * 3M/Microtouch Part
259 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400260#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200261
262#define MTOUCHUSB_ASYNC_REPORT 1
263#define MTOUCHUSB_RESET 7
264#define MTOUCHUSB_REQ_CTRLLR_ID 10
265
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100266static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200267{
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -0800268 if (hwcalib_xy) {
269 dev->x = (pkt[4] << 8) | pkt[3];
270 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
271 } else {
272 dev->x = (pkt[8] << 8) | pkt[7];
273 dev->y = (pkt[10] << 8) | pkt[9];
274 }
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100275 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200276
277 return 1;
278}
279
280static int mtouch_init(struct usbtouch_usb *usbtouch)
281{
Daniel Ritz5d892662006-07-31 21:43:24 +0200282 int ret, i;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200283
284 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
285 MTOUCHUSB_RESET,
286 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
287 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
288 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400289 __func__, ret);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200290 if (ret < 0)
291 return ret;
Daniel Ritz5d892662006-07-31 21:43:24 +0200292 msleep(150);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200293
Daniel Ritz5d892662006-07-31 21:43:24 +0200294 for (i = 0; i < 3; i++) {
295 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
296 MTOUCHUSB_ASYNC_REPORT,
297 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
298 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
299 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400300 __func__, ret);
Daniel Ritz5d892662006-07-31 21:43:24 +0200301 if (ret >= 0)
302 break;
303 if (ret != -EPIPE)
304 return ret;
305 }
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200306
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -0800307 /* Default min/max xy are the raw values, override if using hw-calib */
308 if (hwcalib_xy) {
309 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
310 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
311 }
312
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200313 return 0;
314}
315#endif
316
317
318/*****************************************************************************
319 * ITM Part
320 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400321#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100322static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200323{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100324 int touch;
325 /*
326 * ITM devices report invalid x/y data if not touched.
327 * if the screen was touched before but is not touched any more
328 * report touch as 0 with the last valid x/y data once. then stop
329 * reporting data until touched again.
330 */
331 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200332
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100333 touch = ~pkt[7] & 0x20;
334 if (!touch) {
335 if (dev->touch) {
336 dev->touch = 0;
337 return 1;
338 }
339
340 return 0;
341 }
342
343 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
344 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
345 dev->touch = touch;
346
347 return 1;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200348}
349#endif
350
351
352/*****************************************************************************
Daniel Ritz5d892662006-07-31 21:43:24 +0200353 * eTurboTouch part
354 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400355#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz62aa3662008-01-17 12:01:18 -0500356#ifndef MULTI_PACKET
357#define MULTI_PACKET
358#endif
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100359static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz5d892662006-07-31 21:43:24 +0200360{
361 unsigned int shift;
362
363 /* packets should start with sync */
364 if (!(pkt[0] & 0x80))
365 return 0;
366
367 shift = (6 - (pkt[0] & 0x03));
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100368 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
369 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
370 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
Daniel Ritz5d892662006-07-31 21:43:24 +0200371
372 return 1;
373}
374
375static int eturbo_get_pkt_len(unsigned char *buf, int len)
376{
377 if (buf[0] & 0x80)
378 return 5;
379 if (buf[0] == 0x01)
380 return 3;
381 return 0;
382}
383#endif
384
385
386/*****************************************************************************
387 * Gunze part
388 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400389#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100390static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz5d892662006-07-31 21:43:24 +0200391{
392 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
393 return 0;
394
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100395 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
396 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
397 dev->touch = pkt[0] & 0x20;
Daniel Ritz5d892662006-07-31 21:43:24 +0200398
399 return 1;
400}
401#endif
402
403/*****************************************************************************
Holger Schurig24ced062006-11-17 22:50:15 +0100404 * DMC TSC-10/25 Part
405 *
406 * Documentation about the controller and it's protocol can be found at
407 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
408 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
409 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400410#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100411
412/* supported data rates. currently using 130 */
413#define TSC10_RATE_POINT 0x50
414#define TSC10_RATE_30 0x40
415#define TSC10_RATE_50 0x41
416#define TSC10_RATE_80 0x42
417#define TSC10_RATE_100 0x43
418#define TSC10_RATE_130 0x44
419#define TSC10_RATE_150 0x45
420
421/* commands */
422#define TSC10_CMD_RESET 0x55
423#define TSC10_CMD_RATE 0x05
424#define TSC10_CMD_DATA1 0x01
425
426static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
427{
428 struct usb_device *dev = usbtouch->udev;
Oliver Neukum76d057c2008-04-04 15:31:47 -0400429 int ret = -ENOMEM;
430 unsigned char *buf;
Holger Schurig24ced062006-11-17 22:50:15 +0100431
Oliver Neukum76d057c2008-04-04 15:31:47 -0400432 buf = kmalloc(2, GFP_KERNEL);
433 if (!buf)
434 goto err_nobuf;
Holger Schurig24ced062006-11-17 22:50:15 +0100435 /* reset */
436 buf[0] = buf[1] = 0xFF;
437 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
438 TSC10_CMD_RESET,
439 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
440 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
441 if (ret < 0)
Oliver Neukum76d057c2008-04-04 15:31:47 -0400442 goto err_out;
Nuno Lucas2ec6f242008-11-11 16:48:04 -0500443 if (buf[0] != 0x06) {
Oliver Neukum76d057c2008-04-04 15:31:47 -0400444 ret = -ENODEV;
445 goto err_out;
446 }
Holger Schurig24ced062006-11-17 22:50:15 +0100447
448 /* set coordinate output rate */
449 buf[0] = buf[1] = 0xFF;
450 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
451 TSC10_CMD_RATE,
452 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
453 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
454 if (ret < 0)
Oliver Neukum76d057c2008-04-04 15:31:47 -0400455 goto err_out;
Nuno Lucas2ec6f242008-11-11 16:48:04 -0500456 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
Oliver Neukum76d057c2008-04-04 15:31:47 -0400457 ret = -ENODEV;
458 goto err_out;
459 }
Holger Schurig24ced062006-11-17 22:50:15 +0100460
461 /* start sending data */
462 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
463 TSC10_CMD_DATA1,
464 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
465 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
Oliver Neukum76d057c2008-04-04 15:31:47 -0400466err_out:
467 kfree(buf);
468err_nobuf:
469 return ret;
Holger Schurig24ced062006-11-17 22:50:15 +0100470}
471
472
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100473static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Holger Schurig24ced062006-11-17 22:50:15 +0100474{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100475 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
476 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
477 dev->touch = pkt[0] & 0x01;
Holger Schurig24ced062006-11-17 22:50:15 +0100478
479 return 1;
480}
481#endif
482
483
484/*****************************************************************************
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400485 * IRTOUCH Part
486 */
487#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
488static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
489{
490 dev->x = (pkt[3] << 8) | pkt[2];
491 dev->y = (pkt[5] << 8) | pkt[4];
492 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
493
494 return 1;
495}
496#endif
497
498
499/*****************************************************************************
Ondrej Zarya14a8402007-09-04 23:45:01 -0400500 * IdealTEK URTC1000 Part
501 */
502#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
Daniel Ritz62aa3662008-01-17 12:01:18 -0500503#ifndef MULTI_PACKET
504#define MULTI_PACKET
505#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400506static int idealtek_get_pkt_len(unsigned char *buf, int len)
507{
508 if (buf[0] & 0x80)
509 return 5;
510 if (buf[0] == 0x01)
511 return len;
512 return 0;
513}
514
515static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
516{
517 switch (pkt[0] & 0x98) {
518 case 0x88:
519 /* touch data in IdealTEK mode */
520 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
521 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
522 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
523 return 1;
524
525 case 0x98:
526 /* touch data in MT emulation mode */
527 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
528 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
529 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
530 return 1;
531
532 default:
533 return 0;
534 }
535}
536#endif
537
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400538/*****************************************************************************
539 * General Touch Part
540 */
541#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
542static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
543{
544 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ;
545 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ;
546 dev->press = pkt[5] & 0xff;
547 dev->touch = pkt[0] & 0x01;
548
549 return 1;
550}
551#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400552
553/*****************************************************************************
Jerrold Jones14e40202007-10-22 00:59:47 -0400554 * GoTop Part
555 */
556#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
557static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
558{
559 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
560 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
561 dev->touch = pkt[0] & 0x01;
562 return 1;
563}
564#endif
565
566
567/*****************************************************************************
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200568 * the different device descriptors
569 */
Daniel Ritz62aa3662008-01-17 12:01:18 -0500570#ifdef MULTI_PACKET
571static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
572 unsigned char *pkt, int len);
573#endif
574
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200575static struct usbtouch_device_info usbtouch_dev_info[] = {
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400576#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200577 [DEVTYPE_EGALAX] = {
578 .min_xc = 0x0,
579 .max_xc = 0x07ff,
580 .min_yc = 0x0,
581 .max_yc = 0x07ff,
582 .rept_size = 16,
Daniel Ritz5d892662006-07-31 21:43:24 +0200583 .process_pkt = usbtouch_process_multi,
584 .get_pkt_len = egalax_get_pkt_len,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200585 .read_data = egalax_read_data,
586 },
587#endif
588
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400589#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200590 [DEVTYPE_PANJIT] = {
591 .min_xc = 0x0,
592 .max_xc = 0x0fff,
593 .min_yc = 0x0,
594 .max_yc = 0x0fff,
595 .rept_size = 8,
596 .read_data = panjit_read_data,
597 },
598#endif
599
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400600#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200601 [DEVTYPE_3M] = {
602 .min_xc = 0x0,
603 .max_xc = 0x4000,
604 .min_yc = 0x0,
605 .max_yc = 0x4000,
606 .rept_size = 11,
607 .read_data = mtouch_read_data,
608 .init = mtouch_init,
609 },
610#endif
611
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400612#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200613 [DEVTYPE_ITM] = {
614 .min_xc = 0x0,
615 .max_xc = 0x0fff,
616 .min_yc = 0x0,
617 .max_yc = 0x0fff,
618 .max_press = 0xff,
619 .rept_size = 8,
620 .read_data = itm_read_data,
621 },
622#endif
Daniel Ritz5d892662006-07-31 21:43:24 +0200623
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400624#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz5d892662006-07-31 21:43:24 +0200625 [DEVTYPE_ETURBO] = {
626 .min_xc = 0x0,
627 .max_xc = 0x07ff,
628 .min_yc = 0x0,
629 .max_yc = 0x07ff,
630 .rept_size = 8,
Daniel Ritz5d892662006-07-31 21:43:24 +0200631 .process_pkt = usbtouch_process_multi,
632 .get_pkt_len = eturbo_get_pkt_len,
633 .read_data = eturbo_read_data,
634 },
635#endif
636
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400637#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritz5d892662006-07-31 21:43:24 +0200638 [DEVTYPE_GUNZE] = {
639 .min_xc = 0x0,
640 .max_xc = 0x0fff,
641 .min_yc = 0x0,
642 .max_yc = 0x0fff,
643 .rept_size = 4,
644 .read_data = gunze_read_data,
645 },
646#endif
Holger Schurig24ced062006-11-17 22:50:15 +0100647
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400648#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100649 [DEVTYPE_DMC_TSC10] = {
650 .min_xc = 0x0,
651 .max_xc = 0x03ff,
652 .min_yc = 0x0,
653 .max_yc = 0x03ff,
654 .rept_size = 5,
655 .init = dmc_tsc10_init,
656 .read_data = dmc_tsc10_read_data,
657 },
658#endif
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400659
660#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
661 [DEVTYPE_IRTOUCH] = {
662 .min_xc = 0x0,
663 .max_xc = 0x0fff,
664 .min_yc = 0x0,
665 .max_yc = 0x0fff,
666 .rept_size = 8,
667 .read_data = irtouch_read_data,
668 },
669#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400670
671#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
672 [DEVTYPE_IDEALTEK] = {
673 .min_xc = 0x0,
674 .max_xc = 0x0fff,
675 .min_yc = 0x0,
676 .max_yc = 0x0fff,
677 .rept_size = 8,
Ondrej Zarya14a8402007-09-04 23:45:01 -0400678 .process_pkt = usbtouch_process_multi,
679 .get_pkt_len = idealtek_get_pkt_len,
680 .read_data = idealtek_read_data,
681 },
682#endif
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400683
684#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
685 [DEVTYPE_GENERAL_TOUCH] = {
686 .min_xc = 0x0,
687 .max_xc = 0x0500,
688 .min_yc = 0x0,
689 .max_yc = 0x0500,
690 .rept_size = 7,
691 .read_data = general_touch_read_data,
Jerrold Jones14e40202007-10-22 00:59:47 -0400692 },
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400693#endif
694
Jerrold Jones14e40202007-10-22 00:59:47 -0400695#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
696 [DEVTYPE_GOTOP] = {
697 .min_xc = 0x0,
698 .max_xc = 0x03ff,
699 .min_yc = 0x0,
700 .max_yc = 0x03ff,
701 .rept_size = 4,
702 .read_data = gotop_read_data,
703 },
704#endif
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200705};
706
707
708/*****************************************************************************
709 * Generic Part
710 */
711static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
David Howells7d12e782006-10-05 14:55:46 +0100712 unsigned char *pkt, int len)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200713{
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200714 struct usbtouch_device_info *type = usbtouch->type;
715
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100716 if (!type->read_data(usbtouch, pkt))
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200717 return;
718
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100719 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200720
721 if (swap_xy) {
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100722 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
723 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200724 } else {
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100725 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
726 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200727 }
728 if (type->max_press)
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100729 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200730 input_sync(usbtouch->input);
731}
732
733
Daniel Ritz5d892662006-07-31 21:43:24 +0200734#ifdef MULTI_PACKET
735static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
Daniel Ritz5d892662006-07-31 21:43:24 +0200736 unsigned char *pkt, int len)
737{
738 unsigned char *buffer;
739 int pkt_len, pos, buf_len, tmp;
740
741 /* process buffer */
742 if (unlikely(usbtouch->buf_len)) {
743 /* try to get size */
744 pkt_len = usbtouch->type->get_pkt_len(
745 usbtouch->buffer, usbtouch->buf_len);
746
747 /* drop? */
748 if (unlikely(!pkt_len))
749 goto out_flush_buf;
750
751 /* need to append -pkt_len bytes before able to get size */
752 if (unlikely(pkt_len < 0)) {
753 int append = -pkt_len;
754 if (unlikely(append > len))
755 append = len;
756 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
757 goto out_flush_buf;
758 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
759 usbtouch->buf_len += append;
760
761 pkt_len = usbtouch->type->get_pkt_len(
762 usbtouch->buffer, usbtouch->buf_len);
763 if (pkt_len < 0)
764 return;
765 }
766
767 /* append */
768 tmp = pkt_len - usbtouch->buf_len;
769 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
770 goto out_flush_buf;
771 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
David Howells7d12e782006-10-05 14:55:46 +0100772 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
Daniel Ritz5d892662006-07-31 21:43:24 +0200773
774 buffer = pkt + tmp;
775 buf_len = len - tmp;
776 } else {
777 buffer = pkt;
778 buf_len = len;
779 }
780
781 /* loop over the received packet, process */
782 pos = 0;
783 while (pos < buf_len) {
784 /* get packet len */
Daniel Ritz62aa3662008-01-17 12:01:18 -0500785 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
786 buf_len - pos);
Daniel Ritz5d892662006-07-31 21:43:24 +0200787
Daniel Ritz62aa3662008-01-17 12:01:18 -0500788 /* unknown packet: skip one byte */
789 if (unlikely(!pkt_len)) {
790 pos++;
791 continue;
792 }
Daniel Ritz5d892662006-07-31 21:43:24 +0200793
794 /* full packet: process */
795 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
David Howells7d12e782006-10-05 14:55:46 +0100796 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
Daniel Ritz5d892662006-07-31 21:43:24 +0200797 } else {
798 /* incomplete packet: save in buffer */
799 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
800 usbtouch->buf_len = buf_len - pos;
801 return;
802 }
803 pos += pkt_len;
804 }
805
806out_flush_buf:
807 usbtouch->buf_len = 0;
808 return;
809}
810#endif
811
812
David Howells7d12e782006-10-05 14:55:46 +0100813static void usbtouch_irq(struct urb *urb)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200814{
815 struct usbtouch_usb *usbtouch = urb->context;
816 int retval;
817
818 switch (urb->status) {
819 case 0:
820 /* success */
821 break;
Pete Zaitcev38e2bfc2006-09-18 22:49:02 -0700822 case -ETIME:
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200823 /* this urb is timing out */
824 dbg("%s - urb timed out - was the device unplugged?",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400825 __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200826 return;
827 case -ECONNRESET:
828 case -ENOENT:
829 case -ESHUTDOWN:
830 /* this urb is terminated, clean up */
831 dbg("%s - urb shutting down with status: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400832 __func__, urb->status);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200833 return;
834 default:
835 dbg("%s - nonzero urb status received: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400836 __func__, urb->status);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200837 goto exit;
838 }
839
David Howells7d12e782006-10-05 14:55:46 +0100840 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200841
842exit:
843 retval = usb_submit_urb(urb, GFP_ATOMIC);
844 if (retval)
845 err("%s - usb_submit_urb failed with result: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400846 __func__, retval);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200847}
848
849static int usbtouch_open(struct input_dev *input)
850{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400851 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200852
853 usbtouch->irq->dev = usbtouch->udev;
854
855 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
856 return -EIO;
857
858 return 0;
859}
860
861static void usbtouch_close(struct input_dev *input)
862{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400863 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200864
865 usb_kill_urb(usbtouch->irq);
866}
867
868
869static void usbtouch_free_buffers(struct usb_device *udev,
870 struct usbtouch_usb *usbtouch)
871{
Dmitry Torokhove37a97d2007-05-03 00:57:29 -0400872 usb_buffer_free(udev, usbtouch->type->rept_size,
873 usbtouch->data, usbtouch->data_dma);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200874 kfree(usbtouch->buffer);
875}
876
877
878static int usbtouch_probe(struct usb_interface *intf,
879 const struct usb_device_id *id)
880{
881 struct usbtouch_usb *usbtouch;
882 struct input_dev *input_dev;
883 struct usb_host_interface *interface;
884 struct usb_endpoint_descriptor *endpoint;
885 struct usb_device *udev = interface_to_usbdev(intf);
886 struct usbtouch_device_info *type;
Daniel Ritz5d892662006-07-31 21:43:24 +0200887 int err = -ENOMEM;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200888
Daniel Ritzec42d442008-07-03 10:45:37 -0400889 /* some devices are ignored */
890 if (id->driver_info == DEVTYPE_IGNORE)
891 return -ENODEV;
892
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200893 interface = intf->cur_altsetting;
894 endpoint = &interface->endpoint[0].desc;
895
896 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
897 input_dev = input_allocate_device();
898 if (!usbtouch || !input_dev)
899 goto out_free;
900
901 type = &usbtouch_dev_info[id->driver_info];
902 usbtouch->type = type;
903 if (!type->process_pkt)
904 type->process_pkt = usbtouch_process_pkt;
905
906 usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
Christoph Lametere94b1762006-12-06 20:33:17 -0800907 GFP_KERNEL, &usbtouch->data_dma);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200908 if (!usbtouch->data)
909 goto out_free;
910
Daniel Ritz62aa3662008-01-17 12:01:18 -0500911 if (type->get_pkt_len) {
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200912 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
913 if (!usbtouch->buffer)
914 goto out_free_buffers;
915 }
916
917 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
918 if (!usbtouch->irq) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400919 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200920 goto out_free_buffers;
921 }
922
923 usbtouch->udev = udev;
924 usbtouch->input = input_dev;
925
926 if (udev->manufacturer)
927 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
928
929 if (udev->product) {
930 if (udev->manufacturer)
931 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
932 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
933 }
934
935 if (!strlen(usbtouch->name))
936 snprintf(usbtouch->name, sizeof(usbtouch->name),
937 "USB Touchscreen %04x:%04x",
938 le16_to_cpu(udev->descriptor.idVendor),
939 le16_to_cpu(udev->descriptor.idProduct));
940
941 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
Vladimir Shebordaev7b6dff92007-09-06 21:32:16 -0400942 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200943
944 input_dev->name = usbtouch->name;
945 input_dev->phys = usbtouch->phys;
946 usb_to_input_id(udev, &input_dev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -0400947 input_dev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400948
949 input_set_drvdata(input_dev, usbtouch);
950
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200951 input_dev->open = usbtouch_open;
952 input_dev->close = usbtouch_close;
953
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700954 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
955 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200956 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
957 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
958 if (type->max_press)
959 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
960 type->max_press, 0, 0);
961
962 usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
Daniel Ritzd8fa59a2006-10-27 22:46:03 +0200963 usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress),
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200964 usbtouch->data, type->rept_size,
965 usbtouch_irq, usbtouch, endpoint->bInterval);
966
Daniel Ritz5d892662006-07-31 21:43:24 +0200967 usbtouch->irq->dev = usbtouch->udev;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200968 usbtouch->irq->transfer_dma = usbtouch->data_dma;
969 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
970
971 /* device specific init */
972 if (type->init) {
973 err = type->init(usbtouch);
974 if (err) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400975 dbg("%s - type->init() failed, err: %d", __func__, err);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200976 goto out_free_buffers;
977 }
978 }
979
980 err = input_register_device(usbtouch->input);
981 if (err) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400982 dbg("%s - input_register_device failed, err: %d", __func__, err);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200983 goto out_free_buffers;
984 }
985
986 usb_set_intfdata(intf, usbtouch);
987
988 return 0;
989
990out_free_buffers:
991 usbtouch_free_buffers(udev, usbtouch);
992out_free:
993 input_free_device(input_dev);
994 kfree(usbtouch);
Daniel Ritz5d892662006-07-31 21:43:24 +0200995 return err;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200996}
997
998static void usbtouch_disconnect(struct usb_interface *intf)
999{
1000 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1001
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001002 dbg("%s - called", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001003
1004 if (!usbtouch)
1005 return;
1006
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001007 dbg("%s - usbtouch is initialized, cleaning up", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001008 usb_set_intfdata(intf, NULL);
1009 usb_kill_urb(usbtouch->irq);
1010 input_unregister_device(usbtouch->input);
1011 usb_free_urb(usbtouch->irq);
1012 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1013 kfree(usbtouch);
1014}
1015
1016MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1017
1018static struct usb_driver usbtouch_driver = {
1019 .name = "usbtouchscreen",
1020 .probe = usbtouch_probe,
1021 .disconnect = usbtouch_disconnect,
1022 .id_table = usbtouch_devices,
1023};
1024
1025static int __init usbtouch_init(void)
1026{
1027 return usb_register(&usbtouch_driver);
1028}
1029
1030static void __exit usbtouch_cleanup(void)
1031{
1032 usb_deregister(&usbtouch_driver);
1033}
1034
1035module_init(usbtouch_init);
1036module_exit(usbtouch_cleanup);
1037
1038MODULE_AUTHOR(DRIVER_AUTHOR);
1039MODULE_DESCRIPTION(DRIVER_DESC);
1040MODULE_LICENSE("GPL");
1041
1042MODULE_ALIAS("touchkitusb");
1043MODULE_ALIAS("itmtouch");
1044MODULE_ALIAS("mtouchusb");