aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@insightbb.com>2007-05-07 16:38:49 -0400
committerDmitry Torokhov <dtor@insightbb.com>2007-05-08 01:41:29 -0400
commitd05e84e6cb21cca16987813fd3c271ebaed4233d (patch)
tree791dfc4d1df50d522b5938c36f2915a89f6386c8 /drivers/input/touchscreen
parent4104d13fe0194736393d97c88ee045fb689c783b (diff)
Input: move USB touchscreens under drivers/input/touchscreen
This will allow concentrating all input devices in one place in {menu|x|q}config. Signed-off-by: Dmitry Torokhov <dtor@mail.ru> Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r--drivers/input/touchscreen/Kconfig60
-rw-r--r--drivers/input/touchscreen/Makefile17
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c839
3 files changed, 905 insertions, 11 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 971618059a6f..5e640aeb03cd 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -1,5 +1,5 @@
1# 1#
2# Mouse driver configuration 2# Touchscreen driver configuration
3# 3#
4menuconfig INPUT_TOUCHSCREEN 4menuconfig INPUT_TOUCHSCREEN
5 bool "Touchscreens" 5 bool "Touchscreens"
@@ -44,9 +44,9 @@ config TOUCHSCREEN_BITSY
44config TOUCHSCREEN_CORGI 44config TOUCHSCREEN_CORGI
45 tristate "SharpSL (Corgi and Spitz series) touchscreen driver" 45 tristate "SharpSL (Corgi and Spitz series) touchscreen driver"
46 depends on PXA_SHARPSL 46 depends on PXA_SHARPSL
47 default y 47 default y
48 help 48 help
49 Say Y here to enable the driver for the touchscreen on the 49 Say Y here to enable the driver for the touchscreen on the
50 Sharp SL-C7xx and SL-Cxx00 series of PDAs. 50 Sharp SL-C7xx and SL-Cxx00 series of PDAs.
51 51
52 If unsure, say N. 52 If unsure, say N.
@@ -164,4 +164,58 @@ config TOUCHSCREEN_UCB1400
164 To compile this driver as a module, choose M here: the 164 To compile this driver as a module, choose M here: the
165 module will be called ucb1400_ts. 165 module will be called ucb1400_ts.
166 166
167config TOUCHSCREEN_USB_COMPOSITE
168 tristate "USB Touchscreen Driver"
169 select USB
170 help
171 USB Touchscreen driver for:
172 - eGalax Touchkit USB (also includes eTurboTouch CT-410/510/700)
173 - PanJit TouchSet USB
174 - 3M MicroTouch USB (EX II series)
175 - ITM
176 - some other eTurboTouch
177 - Gunze AHL61
178 - DMC TSC-10/25
179
180 Have a look at <http://linux.chapter7.ch/touchkit/> for
181 a usage description and the required user-space stuff.
182
183 To compile this driver as a module, choose M here: the
184 module will be called usbtouchscreen.
185
186config TOUCHSCREEN_USB_EGALAX
187 default y
188 bool "eGalax, eTurboTouch CT-410/510/700 device support" if EMBEDDED
189 depends on TOUCHSCREEN_USB_COMPOSITE
190
191config TOUCHSCREEN_USB_PANJIT
192 default y
193 bool "PanJit device support" if EMBEDDED
194 depends on TOUCHSCREEN_USB_COMPOSITE
195
196config TOUCHSCREEN_USB_3M
197 default y
198 bool "3M/Microtouch EX II series device support" if EMBEDDED
199 depends on TOUCHSCREEN_USB_COMPOSITE
200
201config TOUCHSCREEN_USB_ITM
202 default y
203 bool "ITM device support" if EMBEDDED
204 depends on TOUCHSCREEN_USB_COMPOSITE
205
206config TOUCHSCREEN_USB_ETURBO
207 default y
208 bool "eTurboTouch (non-eGalax compatible) device support" if EMBEDDED
209 depends on TOUCHSCREEN_USB_COMPOSITE
210
211config TOUCHSCREEN_USB_GUNZE
212 default y
213 bool "Gunze AHL61 device support" if EMBEDDED
214 depends on TOUCHSCREEN_USB_COMPOSITE
215
216config TOUCHSCREEN_USB_DMC_TSC10
217 default y
218 bool "DMC TSC-10/25 device support" if EMBEDDED
219 depends on TOUCHSCREEN_USB_COMPOSITE
220
167endif 221endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 30e6e2217a15..2f86d6ad06d3 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -1,17 +1,18 @@
1# 1#
2# Makefile for the mouse drivers. 2# Makefile for the touchscreen drivers.
3# 3#
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o 7obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o
8obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o 8obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
9obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o 9obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o
10obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o 10obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
11obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o 11obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
12obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o 12obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
13obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o 13obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
14obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o 14obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o
15obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o
15obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o 16obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
16obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 17obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
17obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 18obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
new file mode 100644
index 000000000000..8e18e6c64777
--- /dev/null
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -0,0 +1,839 @@
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 * - DMC TSC-10/25
12 *
13 * Copyright (C) 2004-2006 by Daniel Ritz <daniel.ritz@gmx.ch>
14 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of the
19 * License, or (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *
30 * Driver is based on touchkitusb.c
31 * - ITM parts are from itmtouch.c
32 * - 3M parts are from mtouchusb.c
33 * - PanJit parts are from an unmerged driver by Lanslott Gish
34 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
35 * driver from Marius Vollmer
36 *
37 *****************************************************************************/
38
39//#define DEBUG
40
41#include <linux/kernel.h>
42#include <linux/slab.h>
43#include <linux/input.h>
44#include <linux/module.h>
45#include <linux/init.h>
46#include <linux/usb.h>
47#include <linux/usb/input.h>
48
49
50#define DRIVER_VERSION "v0.5"
51#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
52#define DRIVER_DESC "USB Touchscreen Driver"
53
54static int swap_xy;
55module_param(swap_xy, bool, 0644);
56MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
57
58/* device specifc data/functions */
59struct usbtouch_usb;
60struct usbtouch_device_info {
61 int min_xc, max_xc;
62 int min_yc, max_yc;
63 int min_press, max_press;
64 int rept_size;
65 int flags;
66
67 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
68 int (*get_pkt_len) (unsigned char *pkt, int len);
69 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
70 int (*init) (struct usbtouch_usb *usbtouch);
71};
72
73#define USBTOUCH_FLG_BUFFER 0x01
74
75
76/* a usbtouch device */
77struct usbtouch_usb {
78 unsigned char *data;
79 dma_addr_t data_dma;
80 unsigned char *buffer;
81 int buf_len;
82 struct urb *irq;
83 struct usb_device *udev;
84 struct input_dev *input;
85 struct usbtouch_device_info *type;
86 char name[128];
87 char phys[64];
88
89 int x, y;
90 int touch, press;
91};
92
93
94#if defined(CONFIG_USB_TOUCHSCREEN_EGALAX) || defined(CONFIG_USB_TOUCHSCREEN_ETURBO)
95#define MULTI_PACKET
96#endif
97
98#ifdef MULTI_PACKET
99static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
100 unsigned char *pkt, int len);
101#endif
102
103/* device types */
104enum {
105 DEVTPYE_DUMMY = -1,
106 DEVTYPE_EGALAX,
107 DEVTYPE_PANJIT,
108 DEVTYPE_3M,
109 DEVTYPE_ITM,
110 DEVTYPE_ETURBO,
111 DEVTYPE_GUNZE,
112 DEVTYPE_DMC_TSC10,
113};
114
115static struct usb_device_id usbtouch_devices[] = {
116#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
117 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
118 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
119 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
120 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
121 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
122 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
123 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
124#endif
125
126#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
127 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
128 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
129 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
130 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
131#endif
132
133#ifdef CONFIG_USB_TOUCHSCREEN_3M
134 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
135#endif
136
137#ifdef CONFIG_USB_TOUCHSCREEN_ITM
138 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
139#endif
140
141#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
142 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
143#endif
144
145#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
146 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
147#endif
148
149#ifdef CONFIG_USB_TOUCHSCREEN_DMC_TSC10
150 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
151#endif
152
153 {}
154};
155
156
157/*****************************************************************************
158 * eGalax part
159 */
160
161#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
162
163#define EGALAX_PKT_TYPE_MASK 0xFE
164#define EGALAX_PKT_TYPE_REPT 0x80
165#define EGALAX_PKT_TYPE_DIAG 0x0A
166
167static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
168{
169 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
170 return 0;
171
172 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
173 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
174 dev->touch = pkt[0] & 0x01;
175
176 return 1;
177}
178
179static int egalax_get_pkt_len(unsigned char *buf, int len)
180{
181 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
182 case EGALAX_PKT_TYPE_REPT:
183 return 5;
184
185 case EGALAX_PKT_TYPE_DIAG:
186 if (len < 2)
187 return -1;
188
189 return buf[1] + 2;
190 }
191
192 return 0;
193}
194#endif
195
196
197/*****************************************************************************
198 * PanJit Part
199 */
200#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
201static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
202{
203 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
204 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
205 dev->touch = pkt[0] & 0x01;
206
207 return 1;
208}
209#endif
210
211
212/*****************************************************************************
213 * 3M/Microtouch Part
214 */
215#ifdef CONFIG_USB_TOUCHSCREEN_3M
216
217#define MTOUCHUSB_ASYNC_REPORT 1
218#define MTOUCHUSB_RESET 7
219#define MTOUCHUSB_REQ_CTRLLR_ID 10
220
221static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
222{
223 dev->x = (pkt[8] << 8) | pkt[7];
224 dev->y = (pkt[10] << 8) | pkt[9];
225 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
226
227 return 1;
228}
229
230static int mtouch_init(struct usbtouch_usb *usbtouch)
231{
232 int ret, i;
233
234 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
235 MTOUCHUSB_RESET,
236 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
237 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
238 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
239 __FUNCTION__, ret);
240 if (ret < 0)
241 return ret;
242 msleep(150);
243
244 for (i = 0; i < 3; i++) {
245 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
246 MTOUCHUSB_ASYNC_REPORT,
247 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
248 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
249 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
250 __FUNCTION__, ret);
251 if (ret >= 0)
252 break;
253 if (ret != -EPIPE)
254 return ret;
255 }
256
257 return 0;
258}
259#endif
260
261
262/*****************************************************************************
263 * ITM Part
264 */
265#ifdef CONFIG_USB_TOUCHSCREEN_ITM
266static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
267{
268 int touch;
269 /*
270 * ITM devices report invalid x/y data if not touched.
271 * if the screen was touched before but is not touched any more
272 * report touch as 0 with the last valid x/y data once. then stop
273 * reporting data until touched again.
274 */
275 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
276
277 touch = ~pkt[7] & 0x20;
278 if (!touch) {
279 if (dev->touch) {
280 dev->touch = 0;
281 return 1;
282 }
283
284 return 0;
285 }
286
287 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
288 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
289 dev->touch = touch;
290
291 return 1;
292}
293#endif
294
295
296/*****************************************************************************
297 * eTurboTouch part
298 */
299#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
300static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
301{
302 unsigned int shift;
303
304 /* packets should start with sync */
305 if (!(pkt[0] & 0x80))
306 return 0;
307
308 shift = (6 - (pkt[0] & 0x03));
309 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
310 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
311 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
312
313 return 1;
314}
315
316static int eturbo_get_pkt_len(unsigned char *buf, int len)
317{
318 if (buf[0] & 0x80)
319 return 5;
320 if (buf[0] == 0x01)
321 return 3;
322 return 0;
323}
324#endif
325
326
327/*****************************************************************************
328 * Gunze part
329 */
330#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
331static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
332{
333 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
334 return 0;
335
336 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
337 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
338 dev->touch = pkt[0] & 0x20;
339
340 return 1;
341}
342#endif
343
344/*****************************************************************************
345 * DMC TSC-10/25 Part
346 *
347 * Documentation about the controller and it's protocol can be found at
348 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
349 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
350 */
351#ifdef CONFIG_USB_TOUCHSCREEN_DMC_TSC10
352
353/* supported data rates. currently using 130 */
354#define TSC10_RATE_POINT 0x50
355#define TSC10_RATE_30 0x40
356#define TSC10_RATE_50 0x41
357#define TSC10_RATE_80 0x42
358#define TSC10_RATE_100 0x43
359#define TSC10_RATE_130 0x44
360#define TSC10_RATE_150 0x45
361
362/* commands */
363#define TSC10_CMD_RESET 0x55
364#define TSC10_CMD_RATE 0x05
365#define TSC10_CMD_DATA1 0x01
366
367static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
368{
369 struct usb_device *dev = usbtouch->udev;
370 int ret;
371 unsigned char buf[2];
372
373 /* reset */
374 buf[0] = buf[1] = 0xFF;
375 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
376 TSC10_CMD_RESET,
377 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
378 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
379 if (ret < 0)
380 return ret;
381 if (buf[0] != 0x06 || buf[1] != 0x00)
382 return -ENODEV;
383
384 /* set coordinate output rate */
385 buf[0] = buf[1] = 0xFF;
386 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
387 TSC10_CMD_RATE,
388 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
389 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
390 if (ret < 0)
391 return ret;
392 if (buf[0] != 0x06 || buf[1] != 0x00)
393 return -ENODEV;
394
395 /* start sending data */
396 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
397 TSC10_CMD_DATA1,
398 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
399 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
400 if (ret < 0)
401 return ret;
402
403 return 0;
404}
405
406
407static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
408{
409 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
410 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
411 dev->touch = pkt[0] & 0x01;
412
413 return 1;
414}
415#endif
416
417
418/*****************************************************************************
419 * the different device descriptors
420 */
421static struct usbtouch_device_info usbtouch_dev_info[] = {
422#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
423 [DEVTYPE_EGALAX] = {
424 .min_xc = 0x0,
425 .max_xc = 0x07ff,
426 .min_yc = 0x0,
427 .max_yc = 0x07ff,
428 .rept_size = 16,
429 .flags = USBTOUCH_FLG_BUFFER,
430 .process_pkt = usbtouch_process_multi,
431 .get_pkt_len = egalax_get_pkt_len,
432 .read_data = egalax_read_data,
433 },
434#endif
435
436#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
437 [DEVTYPE_PANJIT] = {
438 .min_xc = 0x0,
439 .max_xc = 0x0fff,
440 .min_yc = 0x0,
441 .max_yc = 0x0fff,
442 .rept_size = 8,
443 .read_data = panjit_read_data,
444 },
445#endif
446
447#ifdef CONFIG_USB_TOUCHSCREEN_3M
448 [DEVTYPE_3M] = {
449 .min_xc = 0x0,
450 .max_xc = 0x4000,
451 .min_yc = 0x0,
452 .max_yc = 0x4000,
453 .rept_size = 11,
454 .read_data = mtouch_read_data,
455 .init = mtouch_init,
456 },
457#endif
458
459#ifdef CONFIG_USB_TOUCHSCREEN_ITM
460 [DEVTYPE_ITM] = {
461 .min_xc = 0x0,
462 .max_xc = 0x0fff,
463 .min_yc = 0x0,
464 .max_yc = 0x0fff,
465 .max_press = 0xff,
466 .rept_size = 8,
467 .read_data = itm_read_data,
468 },
469#endif
470
471#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
472 [DEVTYPE_ETURBO] = {
473 .min_xc = 0x0,
474 .max_xc = 0x07ff,
475 .min_yc = 0x0,
476 .max_yc = 0x07ff,
477 .rept_size = 8,
478 .flags = USBTOUCH_FLG_BUFFER,
479 .process_pkt = usbtouch_process_multi,
480 .get_pkt_len = eturbo_get_pkt_len,
481 .read_data = eturbo_read_data,
482 },
483#endif
484
485#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
486 [DEVTYPE_GUNZE] = {
487 .min_xc = 0x0,
488 .max_xc = 0x0fff,
489 .min_yc = 0x0,
490 .max_yc = 0x0fff,
491 .rept_size = 4,
492 .read_data = gunze_read_data,
493 },
494#endif
495
496#ifdef CONFIG_USB_TOUCHSCREEN_DMC_TSC10
497 [DEVTYPE_DMC_TSC10] = {
498 .min_xc = 0x0,
499 .max_xc = 0x03ff,
500 .min_yc = 0x0,
501 .max_yc = 0x03ff,
502 .rept_size = 5,
503 .init = dmc_tsc10_init,
504 .read_data = dmc_tsc10_read_data,
505 },
506#endif
507};
508
509
510/*****************************************************************************
511 * Generic Part
512 */
513static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
514 unsigned char *pkt, int len)
515{
516 struct usbtouch_device_info *type = usbtouch->type;
517
518 if (!type->read_data(usbtouch, pkt))
519 return;
520
521 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
522
523 if (swap_xy) {
524 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
525 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
526 } else {
527 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
528 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
529 }
530 if (type->max_press)
531 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
532 input_sync(usbtouch->input);
533}
534
535
536#ifdef MULTI_PACKET
537static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
538 unsigned char *pkt, int len)
539{
540 unsigned char *buffer;
541 int pkt_len, pos, buf_len, tmp;
542
543 /* process buffer */
544 if (unlikely(usbtouch->buf_len)) {
545 /* try to get size */
546 pkt_len = usbtouch->type->get_pkt_len(
547 usbtouch->buffer, usbtouch->buf_len);
548
549 /* drop? */
550 if (unlikely(!pkt_len))
551 goto out_flush_buf;
552
553 /* need to append -pkt_len bytes before able to get size */
554 if (unlikely(pkt_len < 0)) {
555 int append = -pkt_len;
556 if (unlikely(append > len))
557 append = len;
558 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
559 goto out_flush_buf;
560 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
561 usbtouch->buf_len += append;
562
563 pkt_len = usbtouch->type->get_pkt_len(
564 usbtouch->buffer, usbtouch->buf_len);
565 if (pkt_len < 0)
566 return;
567 }
568
569 /* append */
570 tmp = pkt_len - usbtouch->buf_len;
571 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
572 goto out_flush_buf;
573 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
574 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
575
576 buffer = pkt + tmp;
577 buf_len = len - tmp;
578 } else {
579 buffer = pkt;
580 buf_len = len;
581 }
582
583 /* loop over the received packet, process */
584 pos = 0;
585 while (pos < buf_len) {
586 /* get packet len */
587 pkt_len = usbtouch->type->get_pkt_len(buffer + pos, len);
588
589 /* unknown packet: drop everything */
590 if (unlikely(!pkt_len))
591 goto out_flush_buf;
592
593 /* full packet: process */
594 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
595 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
596 } else {
597 /* incomplete packet: save in buffer */
598 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
599 usbtouch->buf_len = buf_len - pos;
600 return;
601 }
602 pos += pkt_len;
603 }
604
605out_flush_buf:
606 usbtouch->buf_len = 0;
607 return;
608}
609#endif
610
611
612static void usbtouch_irq(struct urb *urb)
613{
614 struct usbtouch_usb *usbtouch = urb->context;
615 int retval;
616
617 switch (urb->status) {
618 case 0:
619 /* success */
620 break;
621 case -ETIME:
622 /* this urb is timing out */
623 dbg("%s - urb timed out - was the device unplugged?",
624 __FUNCTION__);
625 return;
626 case -ECONNRESET:
627 case -ENOENT:
628 case -ESHUTDOWN:
629 /* this urb is terminated, clean up */
630 dbg("%s - urb shutting down with status: %d",
631 __FUNCTION__, urb->status);
632 return;
633 default:
634 dbg("%s - nonzero urb status received: %d",
635 __FUNCTION__, urb->status);
636 goto exit;
637 }
638
639 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
640
641exit:
642 retval = usb_submit_urb(urb, GFP_ATOMIC);
643 if (retval)
644 err("%s - usb_submit_urb failed with result: %d",
645 __FUNCTION__, retval);
646}
647
648static int usbtouch_open(struct input_dev *input)
649{
650 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
651
652 usbtouch->irq->dev = usbtouch->udev;
653
654 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
655 return -EIO;
656
657 return 0;
658}
659
660static void usbtouch_close(struct input_dev *input)
661{
662 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
663
664 usb_kill_urb(usbtouch->irq);
665}
666
667
668static void usbtouch_free_buffers(struct usb_device *udev,
669 struct usbtouch_usb *usbtouch)
670{
671 usb_buffer_free(udev, usbtouch->type->rept_size,
672 usbtouch->data, usbtouch->data_dma);
673 kfree(usbtouch->buffer);
674}
675
676
677static int usbtouch_probe(struct usb_interface *intf,
678 const struct usb_device_id *id)
679{
680 struct usbtouch_usb *usbtouch;
681 struct input_dev *input_dev;
682 struct usb_host_interface *interface;
683 struct usb_endpoint_descriptor *endpoint;
684 struct usb_device *udev = interface_to_usbdev(intf);
685 struct usbtouch_device_info *type;
686 int err = -ENOMEM;
687
688 interface = intf->cur_altsetting;
689 endpoint = &interface->endpoint[0].desc;
690
691 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
692 input_dev = input_allocate_device();
693 if (!usbtouch || !input_dev)
694 goto out_free;
695
696 type = &usbtouch_dev_info[id->driver_info];
697 usbtouch->type = type;
698 if (!type->process_pkt)
699 type->process_pkt = usbtouch_process_pkt;
700
701 usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
702 GFP_KERNEL, &usbtouch->data_dma);
703 if (!usbtouch->data)
704 goto out_free;
705
706 if (type->flags & USBTOUCH_FLG_BUFFER) {
707 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
708 if (!usbtouch->buffer)
709 goto out_free_buffers;
710 }
711
712 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
713 if (!usbtouch->irq) {
714 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __FUNCTION__);
715 goto out_free_buffers;
716 }
717
718 usbtouch->udev = udev;
719 usbtouch->input = input_dev;
720
721 if (udev->manufacturer)
722 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
723
724 if (udev->product) {
725 if (udev->manufacturer)
726 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
727 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
728 }
729
730 if (!strlen(usbtouch->name))
731 snprintf(usbtouch->name, sizeof(usbtouch->name),
732 "USB Touchscreen %04x:%04x",
733 le16_to_cpu(udev->descriptor.idVendor),
734 le16_to_cpu(udev->descriptor.idProduct));
735
736 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
737 strlcpy(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
738
739 input_dev->name = usbtouch->name;
740 input_dev->phys = usbtouch->phys;
741 usb_to_input_id(udev, &input_dev->id);
742 input_dev->dev.parent = &intf->dev;
743
744 input_set_drvdata(input_dev, usbtouch);
745
746 input_dev->open = usbtouch_open;
747 input_dev->close = usbtouch_close;
748
749 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
750 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
751 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
752 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
753 if (type->max_press)
754 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
755 type->max_press, 0, 0);
756
757 usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
758 usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress),
759 usbtouch->data, type->rept_size,
760 usbtouch_irq, usbtouch, endpoint->bInterval);
761
762 usbtouch->irq->dev = usbtouch->udev;
763 usbtouch->irq->transfer_dma = usbtouch->data_dma;
764 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
765
766 /* device specific init */
767 if (type->init) {
768 err = type->init(usbtouch);
769 if (err) {
770 dbg("%s - type->init() failed, err: %d", __FUNCTION__, err);
771 goto out_free_buffers;
772 }
773 }
774
775 err = input_register_device(usbtouch->input);
776 if (err) {
777 dbg("%s - input_register_device failed, err: %d", __FUNCTION__, err);
778 goto out_free_buffers;
779 }
780
781 usb_set_intfdata(intf, usbtouch);
782
783 return 0;
784
785out_free_buffers:
786 usbtouch_free_buffers(udev, usbtouch);
787out_free:
788 input_free_device(input_dev);
789 kfree(usbtouch);
790 return err;
791}
792
793static void usbtouch_disconnect(struct usb_interface *intf)
794{
795 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
796
797 dbg("%s - called", __FUNCTION__);
798
799 if (!usbtouch)
800 return;
801
802 dbg("%s - usbtouch is initialized, cleaning up", __FUNCTION__);
803 usb_set_intfdata(intf, NULL);
804 usb_kill_urb(usbtouch->irq);
805 input_unregister_device(usbtouch->input);
806 usb_free_urb(usbtouch->irq);
807 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
808 kfree(usbtouch);
809}
810
811MODULE_DEVICE_TABLE(usb, usbtouch_devices);
812
813static struct usb_driver usbtouch_driver = {
814 .name = "usbtouchscreen",
815 .probe = usbtouch_probe,
816 .disconnect = usbtouch_disconnect,
817 .id_table = usbtouch_devices,
818};
819
820static int __init usbtouch_init(void)
821{
822 return usb_register(&usbtouch_driver);
823}
824
825static void __exit usbtouch_cleanup(void)
826{
827 usb_deregister(&usbtouch_driver);
828}
829
830module_init(usbtouch_init);
831module_exit(usbtouch_cleanup);
832
833MODULE_AUTHOR(DRIVER_AUTHOR);
834MODULE_DESCRIPTION(DRIVER_DESC);
835MODULE_LICENSE("GPL");
836
837MODULE_ALIAS("touchkitusb");
838MODULE_ALIAS("itmtouch");
839MODULE_ALIAS("mtouchusb");