Commit | Line | Data |
---|---|---|
1d3e2023 DR |
1 | /****************************************************************************** |
2 | * usbtouchscreen.c | |
3 | * Driver for USB Touchscreens, supporting those devices: | |
4 | * - eGalax Touchkit | |
5d892665 DR |
5 | * includes eTurboTouch CT-410/510/700 |
6 | * - 3M/Microtouch EX II series | |
1d3e2023 DR |
7 | * - ITM |
8 | * - PanJit TouchSet | |
5d892665 DR |
9 | * - eTurboTouch |
10 | * - Gunze AHL61 | |
24ced062 | 11 | * - DMC TSC-10/25 |
df561fcd | 12 | * - IRTOUCHSYSTEMS/UNITOP |
a14a8401 | 13 | * - IdealTEK URTC1000 |
62aa366d | 14 | * - General Touch |
14e40206 | 15 | * - GoTop Super_Q2/GogoPen/PenPower tablets |
f7370699 | 16 | * - JASTEC USB touch controller/DigiTech DTR-02U |
2330ed18 | 17 | * - Zytronic capacitive touchscreen |
5197424c | 18 | * - NEXIO/iNexio |
d2cc817a | 19 | * - Elo TouchSystems 2700 IntelliTouch |
aa87512f | 20 | * - EasyTouch USB Dual/Multi touch controller from Data Modul |
1d3e2023 | 21 | * |
14e40206 | 22 | * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch> |
1d3e2023 DR |
23 | * Copyright (C) by Todd E. Johnson (mtouchusb.c) |
24 | * | |
25 | * This program is free software; you can redistribute it and/or | |
26 | * modify it under the terms of the GNU General Public License as | |
27 | * published by the Free Software Foundation; either version 2 of the | |
28 | * License, or (at your option) any later version. | |
29 | * | |
30 | * This program is distributed in the hope that it will be useful, but | |
31 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
33 | * General Public License for more details. | |
34 | * | |
35 | * You should have received a copy of the GNU General Public License | |
36 | * along with this program; if not, write to the Free Software | |
37 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
38 | * | |
39 | * Driver is based on touchkitusb.c | |
40 | * - ITM parts are from itmtouch.c | |
41 | * - 3M parts are from mtouchusb.c | |
42 | * - PanJit parts are from an unmerged driver by Lanslott Gish | |
24ced062 HS |
43 | * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged |
44 | * driver from Marius Vollmer | |
1d3e2023 DR |
45 | * |
46 | *****************************************************************************/ | |
47 | ||
48 | //#define DEBUG | |
49 | ||
1d3e2023 DR |
50 | #include <linux/kernel.h> |
51 | #include <linux/slab.h> | |
52 | #include <linux/input.h> | |
53 | #include <linux/module.h> | |
54 | #include <linux/init.h> | |
55 | #include <linux/usb.h> | |
ae0dadcf | 56 | #include <linux/usb/input.h> |
ec42d448 | 57 | #include <linux/hid.h> |
1d3e2023 DR |
58 | |
59 | ||
62aa366d | 60 | #define DRIVER_VERSION "v0.6" |
1d3e2023 DR |
61 | #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>" |
62 | #define DRIVER_DESC "USB Touchscreen Driver" | |
63 | ||
90ab5ee9 | 64 | static bool swap_xy; |
1d3e2023 DR |
65 | module_param(swap_xy, bool, 0644); |
66 | MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped."); | |
67 | ||
90ab5ee9 | 68 | static bool hwcalib_xy; |
c9cbf3d3 DS |
69 | module_param(hwcalib_xy, bool, 0644); |
70 | MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available"); | |
71 | ||
1d3e2023 DR |
72 | /* device specifc data/functions */ |
73 | struct usbtouch_usb; | |
74 | struct usbtouch_device_info { | |
75 | int min_xc, max_xc; | |
76 | int min_yc, max_yc; | |
77 | int min_press, max_press; | |
78 | int rept_size; | |
1d3e2023 | 79 | |
2330ed18 DS |
80 | /* |
81 | * Always service the USB devices irq not just when the input device is | |
82 | * open. This is useful when devices have a watchdog which prevents us | |
83 | * from periodically polling the device. Leave this unset unless your | |
84 | * touchscreen device requires it, as it does consume more of the USB | |
85 | * bandwidth. | |
86 | */ | |
87 | bool irq_always; | |
88 | ||
7d12e780 | 89 | void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len); |
62aa366d DR |
90 | |
91 | /* | |
92 | * used to get the packet len. possible return values: | |
93 | * > 0: packet len | |
94 | * = 0: skip one byte | |
95 | * < 0: -return value more bytes needed | |
96 | */ | |
5d892665 | 97 | int (*get_pkt_len) (unsigned char *pkt, int len); |
62aa366d | 98 | |
c9d8c2b3 | 99 | int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt); |
a8aef622 | 100 | int (*alloc) (struct usbtouch_usb *usbtouch); |
1d3e2023 | 101 | int (*init) (struct usbtouch_usb *usbtouch); |
5197424c | 102 | void (*exit) (struct usbtouch_usb *usbtouch); |
1d3e2023 DR |
103 | }; |
104 | ||
1d3e2023 DR |
105 | /* a usbtouch device */ |
106 | struct usbtouch_usb { | |
107 | unsigned char *data; | |
108 | dma_addr_t data_dma; | |
4ef38351 | 109 | int data_size; |
1d3e2023 DR |
110 | unsigned char *buffer; |
111 | int buf_len; | |
112 | struct urb *irq; | |
fea4d14b | 113 | struct usb_interface *interface; |
1d3e2023 DR |
114 | struct input_dev *input; |
115 | struct usbtouch_device_info *type; | |
116 | char name[128]; | |
117 | char phys[64]; | |
5197424c | 118 | void *priv; |
c9d8c2b3 DR |
119 | |
120 | int x, y; | |
121 | int touch, press; | |
1d3e2023 DR |
122 | }; |
123 | ||
5d892665 | 124 | |
1d3e2023 DR |
125 | /* device types */ |
126 | enum { | |
ec42d448 | 127 | DEVTYPE_IGNORE = -1, |
1d3e2023 DR |
128 | DEVTYPE_EGALAX, |
129 | DEVTYPE_PANJIT, | |
130 | DEVTYPE_3M, | |
131 | DEVTYPE_ITM, | |
5d892665 DR |
132 | DEVTYPE_ETURBO, |
133 | DEVTYPE_GUNZE, | |
24ced062 | 134 | DEVTYPE_DMC_TSC10, |
df561fcd | 135 | DEVTYPE_IRTOUCH, |
a14a8401 | 136 | DEVTYPE_IDEALTEK, |
9d5657db | 137 | DEVTYPE_GENERAL_TOUCH, |
14e40206 | 138 | DEVTYPE_GOTOP, |
f7370699 | 139 | DEVTYPE_JASTEC, |
9e3b2583 | 140 | DEVTYPE_E2I, |
2330ed18 | 141 | DEVTYPE_ZYTRONIC, |
38771bb4 | 142 | DEVTYPE_TC45USB, |
5197424c | 143 | DEVTYPE_NEXIO, |
d2cc817a | 144 | DEVTYPE_ELO, |
aa87512f | 145 | DEVTYPE_ETOUCH, |
1d3e2023 DR |
146 | }; |
147 | ||
ec42d448 DR |
148 | #define USB_DEVICE_HID_CLASS(vend, prod) \ |
149 | .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \ | |
150 | | USB_DEVICE_ID_MATCH_DEVICE, \ | |
151 | .idVendor = (vend), \ | |
152 | .idProduct = (prod), \ | |
ae2aa3a5 | 153 | .bInterfaceClass = USB_INTERFACE_CLASS_HID |
ec42d448 | 154 | |
9cb3ce52 | 155 | static const struct usb_device_id usbtouch_devices[] = { |
c6f8d706 | 156 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
ec42d448 DR |
157 | /* ignore the HID capable devices, handled by usbhid */ |
158 | {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE}, | |
159 | {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE}, | |
160 | ||
161 | /* normal device IDs */ | |
1d3e2023 | 162 | {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
5d892665 | 163 | {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX}, |
1d3e2023 DR |
164 | {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
165 | {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX}, | |
166 | {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX}, | |
5d892665 DR |
167 | {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
168 | {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX}, | |
1d3e2023 DR |
169 | #endif |
170 | ||
c6f8d706 | 171 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
1d3e2023 DR |
172 | {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT}, |
173 | {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT}, | |
174 | {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT}, | |
175 | {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT}, | |
176 | #endif | |
177 | ||
c6f8d706 | 178 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
1d3e2023 DR |
179 | {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M}, |
180 | #endif | |
181 | ||
c6f8d706 | 182 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
1d3e2023 | 183 | {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM}, |
09910509 | 184 | {USB_DEVICE(0x16e3, 0xf9e9), .driver_info = DEVTYPE_ITM}, |
1d3e2023 DR |
185 | #endif |
186 | ||
c6f8d706 | 187 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
5d892665 DR |
188 | {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO}, |
189 | #endif | |
190 | ||
c6f8d706 | 191 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
5d892665 DR |
192 | {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE}, |
193 | #endif | |
194 | ||
c6f8d706 | 195 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
24ced062 HS |
196 | {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10}, |
197 | #endif | |
198 | ||
df561fcd OZ |
199 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH |
200 | {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, | |
201 | {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, | |
202 | #endif | |
203 | ||
a14a8401 OZ |
204 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK |
205 | {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK}, | |
206 | #endif | |
207 | ||
9d5657db IF |
208 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH |
209 | {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH}, | |
210 | #endif | |
211 | ||
14e40206 JJ |
212 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP |
213 | {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP}, | |
214 | {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP}, | |
215 | {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP}, | |
216 | #endif | |
217 | ||
f7370699 JP |
218 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC |
219 | {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC}, | |
220 | #endif | |
221 | ||
9e3b2583 FE |
222 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I |
223 | {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I}, | |
224 | #endif | |
2330ed18 DS |
225 | |
226 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC | |
227 | {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC}, | |
228 | #endif | |
229 | ||
38771bb4 PŠ |
230 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB |
231 | /* TC5UH */ | |
232 | {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC45USB}, | |
233 | /* TC4UM */ | |
234 | {USB_DEVICE(0x0664, 0x0306), .driver_info = DEVTYPE_TC45USB}, | |
dbe1420b PŠ |
235 | #endif |
236 | ||
5197424c OZ |
237 | #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO |
238 | /* data interface only */ | |
239 | {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00), | |
240 | .driver_info = DEVTYPE_NEXIO}, | |
241 | {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00), | |
242 | .driver_info = DEVTYPE_NEXIO}, | |
243 | #endif | |
244 | ||
d2cc817a MG |
245 | #ifdef CONFIG_TOUCHSCREEN_USB_ELO |
246 | {USB_DEVICE(0x04e7, 0x0020), .driver_info = DEVTYPE_ELO}, | |
247 | #endif | |
248 | ||
aa87512f AV |
249 | #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH |
250 | {USB_DEVICE(0x7374, 0x0001), .driver_info = DEVTYPE_ETOUCH}, | |
251 | #endif | |
252 | ||
1d3e2023 DR |
253 | {} |
254 | }; | |
255 | ||
256 | ||
9e3b2583 FE |
257 | /***************************************************************************** |
258 | * e2i Part | |
259 | */ | |
260 | ||
261 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I | |
262 | static int e2i_init(struct usbtouch_usb *usbtouch) | |
263 | { | |
264 | int ret; | |
fea4d14b | 265 | struct usb_device *udev = interface_to_usbdev(usbtouch->interface); |
9e3b2583 | 266 | |
fea4d14b | 267 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
9e3b2583 FE |
268 | 0x01, 0x02, 0x0000, 0x0081, |
269 | NULL, 0, USB_CTRL_SET_TIMEOUT); | |
270 | ||
0a5ebc88 | 271 | dev_dbg(&usbtouch->interface->dev, |
b741ab9d GKH |
272 | "%s - usb_control_msg - E2I_RESET - bytes|err: %d\n", |
273 | __func__, ret); | |
9e3b2583 FE |
274 | return ret; |
275 | } | |
276 | ||
277 | static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
278 | { | |
279 | int tmp = (pkt[0] << 8) | pkt[1]; | |
280 | dev->x = (pkt[2] << 8) | pkt[3]; | |
281 | dev->y = (pkt[4] << 8) | pkt[5]; | |
282 | ||
283 | tmp = tmp - 0xA000; | |
284 | dev->touch = (tmp > 0); | |
285 | dev->press = (tmp > 0 ? tmp : 0); | |
286 | ||
287 | return 1; | |
288 | } | |
289 | #endif | |
290 | ||
291 | ||
1d3e2023 DR |
292 | /***************************************************************************** |
293 | * eGalax part | |
294 | */ | |
295 | ||
c6f8d706 | 296 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
1d3e2023 | 297 | |
62aa366d DR |
298 | #ifndef MULTI_PACKET |
299 | #define MULTI_PACKET | |
300 | #endif | |
301 | ||
1d3e2023 DR |
302 | #define EGALAX_PKT_TYPE_MASK 0xFE |
303 | #define EGALAX_PKT_TYPE_REPT 0x80 | |
304 | #define EGALAX_PKT_TYPE_DIAG 0x0A | |
305 | ||
037a833e FB |
306 | static int egalax_init(struct usbtouch_usb *usbtouch) |
307 | { | |
308 | int ret, i; | |
309 | unsigned char *buf; | |
310 | struct usb_device *udev = interface_to_usbdev(usbtouch->interface); | |
311 | ||
312 | /* | |
313 | * An eGalax diagnostic packet kicks the device into using the right | |
314 | * protocol. We send a "check active" packet. The response will be | |
315 | * read later and ignored. | |
316 | */ | |
317 | ||
318 | buf = kmalloc(3, GFP_KERNEL); | |
319 | if (!buf) | |
320 | return -ENOMEM; | |
321 | ||
322 | buf[0] = EGALAX_PKT_TYPE_DIAG; | |
323 | buf[1] = 1; /* length */ | |
324 | buf[2] = 'A'; /* command - check active */ | |
325 | ||
326 | for (i = 0; i < 3; i++) { | |
327 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | |
328 | 0, | |
329 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
330 | 0, 0, buf, 3, | |
331 | USB_CTRL_SET_TIMEOUT); | |
332 | if (ret >= 0) { | |
333 | ret = 0; | |
334 | break; | |
335 | } | |
336 | if (ret != -EPIPE) | |
337 | break; | |
338 | } | |
339 | ||
340 | kfree(buf); | |
341 | ||
342 | return ret; | |
343 | } | |
344 | ||
c9d8c2b3 | 345 | static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
1d3e2023 DR |
346 | { |
347 | if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT) | |
348 | return 0; | |
349 | ||
c9d8c2b3 DR |
350 | dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F); |
351 | dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F); | |
352 | dev->touch = pkt[0] & 0x01; | |
1d3e2023 DR |
353 | |
354 | return 1; | |
1d3e2023 DR |
355 | } |
356 | ||
5d892665 | 357 | static int egalax_get_pkt_len(unsigned char *buf, int len) |
1d3e2023 DR |
358 | { |
359 | switch (buf[0] & EGALAX_PKT_TYPE_MASK) { | |
360 | case EGALAX_PKT_TYPE_REPT: | |
361 | return 5; | |
362 | ||
363 | case EGALAX_PKT_TYPE_DIAG: | |
5d892665 DR |
364 | if (len < 2) |
365 | return -1; | |
366 | ||
1d3e2023 DR |
367 | return buf[1] + 2; |
368 | } | |
369 | ||
370 | return 0; | |
371 | } | |
1d3e2023 DR |
372 | #endif |
373 | ||
aa87512f AV |
374 | /***************************************************************************** |
375 | * EasyTouch part | |
376 | */ | |
377 | ||
378 | #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH | |
379 | ||
380 | #ifndef MULTI_PACKET | |
381 | #define MULTI_PACKET | |
382 | #endif | |
383 | ||
384 | #define ETOUCH_PKT_TYPE_MASK 0xFE | |
385 | #define ETOUCH_PKT_TYPE_REPT 0x80 | |
386 | #define ETOUCH_PKT_TYPE_REPT2 0xB0 | |
387 | #define ETOUCH_PKT_TYPE_DIAG 0x0A | |
388 | ||
389 | static int etouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
390 | { | |
391 | if ((pkt[0] & ETOUCH_PKT_TYPE_MASK) != ETOUCH_PKT_TYPE_REPT && | |
392 | (pkt[0] & ETOUCH_PKT_TYPE_MASK) != ETOUCH_PKT_TYPE_REPT2) | |
393 | return 0; | |
394 | ||
395 | dev->x = ((pkt[1] & 0x1F) << 7) | (pkt[2] & 0x7F); | |
396 | dev->y = ((pkt[3] & 0x1F) << 7) | (pkt[4] & 0x7F); | |
397 | dev->touch = pkt[0] & 0x01; | |
398 | ||
399 | return 1; | |
400 | } | |
401 | ||
402 | static int etouch_get_pkt_len(unsigned char *buf, int len) | |
403 | { | |
404 | switch (buf[0] & ETOUCH_PKT_TYPE_MASK) { | |
405 | case ETOUCH_PKT_TYPE_REPT: | |
406 | case ETOUCH_PKT_TYPE_REPT2: | |
407 | return 5; | |
408 | ||
409 | case ETOUCH_PKT_TYPE_DIAG: | |
410 | if (len < 2) | |
411 | return -1; | |
412 | ||
413 | return buf[1] + 2; | |
414 | } | |
415 | ||
416 | return 0; | |
417 | } | |
418 | #endif | |
1d3e2023 DR |
419 | |
420 | /***************************************************************************** | |
421 | * PanJit Part | |
422 | */ | |
c6f8d706 | 423 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
c9d8c2b3 | 424 | static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
1d3e2023 | 425 | { |
c9d8c2b3 DR |
426 | dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1]; |
427 | dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3]; | |
428 | dev->touch = pkt[0] & 0x01; | |
1d3e2023 DR |
429 | |
430 | return 1; | |
431 | } | |
432 | #endif | |
433 | ||
434 | ||
435 | /***************************************************************************** | |
436 | * 3M/Microtouch Part | |
437 | */ | |
c6f8d706 | 438 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
1d3e2023 DR |
439 | |
440 | #define MTOUCHUSB_ASYNC_REPORT 1 | |
441 | #define MTOUCHUSB_RESET 7 | |
442 | #define MTOUCHUSB_REQ_CTRLLR_ID 10 | |
443 | ||
c9d8c2b3 | 444 | static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
1d3e2023 | 445 | { |
c9cbf3d3 DS |
446 | if (hwcalib_xy) { |
447 | dev->x = (pkt[4] << 8) | pkt[3]; | |
448 | dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]); | |
449 | } else { | |
450 | dev->x = (pkt[8] << 8) | pkt[7]; | |
451 | dev->y = (pkt[10] << 8) | pkt[9]; | |
452 | } | |
c9d8c2b3 | 453 | dev->touch = (pkt[2] & 0x40) ? 1 : 0; |
1d3e2023 DR |
454 | |
455 | return 1; | |
456 | } | |
457 | ||
458 | static int mtouch_init(struct usbtouch_usb *usbtouch) | |
459 | { | |
5d892665 | 460 | int ret, i; |
fea4d14b | 461 | struct usb_device *udev = interface_to_usbdev(usbtouch->interface); |
1d3e2023 | 462 | |
fea4d14b | 463 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
1d3e2023 DR |
464 | MTOUCHUSB_RESET, |
465 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
466 | 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); | |
0a5ebc88 | 467 | dev_dbg(&usbtouch->interface->dev, |
b741ab9d GKH |
468 | "%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d\n", |
469 | __func__, ret); | |
1d3e2023 DR |
470 | if (ret < 0) |
471 | return ret; | |
5d892665 DR |
472 | msleep(150); |
473 | ||
474 | for (i = 0; i < 3; i++) { | |
fea4d14b | 475 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
5d892665 DR |
476 | MTOUCHUSB_ASYNC_REPORT, |
477 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
478 | 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); | |
0a5ebc88 | 479 | dev_dbg(&usbtouch->interface->dev, |
b741ab9d GKH |
480 | "%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d\n", |
481 | __func__, ret); | |
5d892665 DR |
482 | if (ret >= 0) |
483 | break; | |
484 | if (ret != -EPIPE) | |
485 | return ret; | |
486 | } | |
1d3e2023 | 487 | |
c9cbf3d3 DS |
488 | /* Default min/max xy are the raw values, override if using hw-calib */ |
489 | if (hwcalib_xy) { | |
490 | input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0); | |
491 | input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0); | |
492 | } | |
493 | ||
1d3e2023 DR |
494 | return 0; |
495 | } | |
496 | #endif | |
497 | ||
498 | ||
499 | /***************************************************************************** | |
500 | * ITM Part | |
501 | */ | |
c6f8d706 | 502 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
c9d8c2b3 | 503 | static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
1d3e2023 | 504 | { |
c9d8c2b3 DR |
505 | int touch; |
506 | /* | |
507 | * ITM devices report invalid x/y data if not touched. | |
508 | * if the screen was touched before but is not touched any more | |
509 | * report touch as 0 with the last valid x/y data once. then stop | |
510 | * reporting data until touched again. | |
511 | */ | |
512 | dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F); | |
513 | ||
514 | touch = ~pkt[7] & 0x20; | |
515 | if (!touch) { | |
516 | if (dev->touch) { | |
517 | dev->touch = 0; | |
518 | return 1; | |
519 | } | |
520 | ||
521 | return 0; | |
522 | } | |
523 | ||
524 | dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F); | |
525 | dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F); | |
526 | dev->touch = touch; | |
1d3e2023 | 527 | |
c9d8c2b3 | 528 | return 1; |
1d3e2023 DR |
529 | } |
530 | #endif | |
531 | ||
532 | ||
5d892665 DR |
533 | /***************************************************************************** |
534 | * eTurboTouch part | |
535 | */ | |
c6f8d706 | 536 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
62aa366d DR |
537 | #ifndef MULTI_PACKET |
538 | #define MULTI_PACKET | |
539 | #endif | |
c9d8c2b3 | 540 | static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
5d892665 DR |
541 | { |
542 | unsigned int shift; | |
543 | ||
544 | /* packets should start with sync */ | |
545 | if (!(pkt[0] & 0x80)) | |
546 | return 0; | |
547 | ||
548 | shift = (6 - (pkt[0] & 0x03)); | |
c9d8c2b3 DR |
549 | dev->x = ((pkt[3] << 7) | pkt[4]) >> shift; |
550 | dev->y = ((pkt[1] << 7) | pkt[2]) >> shift; | |
551 | dev->touch = (pkt[0] & 0x10) ? 1 : 0; | |
5d892665 DR |
552 | |
553 | return 1; | |
554 | } | |
555 | ||
556 | static int eturbo_get_pkt_len(unsigned char *buf, int len) | |
557 | { | |
558 | if (buf[0] & 0x80) | |
559 | return 5; | |
560 | if (buf[0] == 0x01) | |
561 | return 3; | |
562 | return 0; | |
563 | } | |
564 | #endif | |
565 | ||
566 | ||
567 | /***************************************************************************** | |
568 | * Gunze part | |
569 | */ | |
c6f8d706 | 570 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
c9d8c2b3 | 571 | static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
5d892665 DR |
572 | { |
573 | if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80)) | |
574 | return 0; | |
575 | ||
c9d8c2b3 DR |
576 | dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F); |
577 | dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F); | |
578 | dev->touch = pkt[0] & 0x20; | |
5d892665 DR |
579 | |
580 | return 1; | |
581 | } | |
582 | #endif | |
583 | ||
24ced062 HS |
584 | /***************************************************************************** |
585 | * DMC TSC-10/25 Part | |
586 | * | |
587 | * Documentation about the controller and it's protocol can be found at | |
588 | * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf | |
589 | * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf | |
590 | */ | |
c6f8d706 | 591 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
24ced062 HS |
592 | |
593 | /* supported data rates. currently using 130 */ | |
594 | #define TSC10_RATE_POINT 0x50 | |
595 | #define TSC10_RATE_30 0x40 | |
596 | #define TSC10_RATE_50 0x41 | |
597 | #define TSC10_RATE_80 0x42 | |
598 | #define TSC10_RATE_100 0x43 | |
599 | #define TSC10_RATE_130 0x44 | |
600 | #define TSC10_RATE_150 0x45 | |
601 | ||
602 | /* commands */ | |
603 | #define TSC10_CMD_RESET 0x55 | |
604 | #define TSC10_CMD_RATE 0x05 | |
605 | #define TSC10_CMD_DATA1 0x01 | |
606 | ||
607 | static int dmc_tsc10_init(struct usbtouch_usb *usbtouch) | |
608 | { | |
fea4d14b | 609 | struct usb_device *dev = interface_to_usbdev(usbtouch->interface); |
76d057ce ON |
610 | int ret = -ENOMEM; |
611 | unsigned char *buf; | |
24ced062 | 612 | |
a8aef622 | 613 | buf = kmalloc(2, GFP_NOIO); |
76d057ce ON |
614 | if (!buf) |
615 | goto err_nobuf; | |
24ced062 HS |
616 | /* reset */ |
617 | buf[0] = buf[1] = 0xFF; | |
618 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), | |
619 | TSC10_CMD_RESET, | |
620 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
621 | 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT); | |
622 | if (ret < 0) | |
76d057ce | 623 | goto err_out; |
2ec6f246 | 624 | if (buf[0] != 0x06) { |
76d057ce ON |
625 | ret = -ENODEV; |
626 | goto err_out; | |
627 | } | |
24ced062 HS |
628 | |
629 | /* set coordinate output rate */ | |
630 | buf[0] = buf[1] = 0xFF; | |
631 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), | |
632 | TSC10_CMD_RATE, | |
633 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
634 | TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT); | |
635 | if (ret < 0) | |
76d057ce | 636 | goto err_out; |
2ec6f246 | 637 | if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) { |
76d057ce ON |
638 | ret = -ENODEV; |
639 | goto err_out; | |
640 | } | |
24ced062 HS |
641 | |
642 | /* start sending data */ | |
643 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), | |
644 | TSC10_CMD_DATA1, | |
645 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
646 | 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); | |
76d057ce ON |
647 | err_out: |
648 | kfree(buf); | |
649 | err_nobuf: | |
650 | return ret; | |
24ced062 HS |
651 | } |
652 | ||
653 | ||
c9d8c2b3 | 654 | static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
24ced062 | 655 | { |
c9d8c2b3 DR |
656 | dev->x = ((pkt[2] & 0x03) << 8) | pkt[1]; |
657 | dev->y = ((pkt[4] & 0x03) << 8) | pkt[3]; | |
658 | dev->touch = pkt[0] & 0x01; | |
24ced062 HS |
659 | |
660 | return 1; | |
661 | } | |
662 | #endif | |
663 | ||
664 | ||
df561fcd OZ |
665 | /***************************************************************************** |
666 | * IRTOUCH Part | |
667 | */ | |
668 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH | |
669 | static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
670 | { | |
671 | dev->x = (pkt[3] << 8) | pkt[2]; | |
672 | dev->y = (pkt[5] << 8) | pkt[4]; | |
673 | dev->touch = (pkt[1] & 0x03) ? 1 : 0; | |
674 | ||
675 | return 1; | |
676 | } | |
677 | #endif | |
678 | ||
dbe1420b | 679 | /***************************************************************************** |
38771bb4 | 680 | * ET&T TC5UH/TC4UM part |
dbe1420b | 681 | */ |
38771bb4 PŠ |
682 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB |
683 | static int tc45usb_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
dbe1420b PŠ |
684 | { |
685 | dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1]; | |
686 | dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3]; | |
687 | dev->touch = pkt[0] & 0x01; | |
688 | ||
689 | return 1; | |
690 | } | |
691 | #endif | |
df561fcd | 692 | |
a14a8401 OZ |
693 | /***************************************************************************** |
694 | * IdealTEK URTC1000 Part | |
695 | */ | |
696 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK | |
62aa366d DR |
697 | #ifndef MULTI_PACKET |
698 | #define MULTI_PACKET | |
699 | #endif | |
a14a8401 OZ |
700 | static int idealtek_get_pkt_len(unsigned char *buf, int len) |
701 | { | |
702 | if (buf[0] & 0x80) | |
703 | return 5; | |
704 | if (buf[0] == 0x01) | |
705 | return len; | |
706 | return 0; | |
707 | } | |
708 | ||
709 | static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
710 | { | |
711 | switch (pkt[0] & 0x98) { | |
712 | case 0x88: | |
713 | /* touch data in IdealTEK mode */ | |
714 | dev->x = (pkt[1] << 5) | (pkt[2] >> 2); | |
715 | dev->y = (pkt[3] << 5) | (pkt[4] >> 2); | |
716 | dev->touch = (pkt[0] & 0x40) ? 1 : 0; | |
717 | return 1; | |
718 | ||
719 | case 0x98: | |
720 | /* touch data in MT emulation mode */ | |
721 | dev->x = (pkt[2] << 5) | (pkt[1] >> 2); | |
722 | dev->y = (pkt[4] << 5) | (pkt[3] >> 2); | |
723 | dev->touch = (pkt[0] & 0x40) ? 1 : 0; | |
724 | return 1; | |
725 | ||
726 | default: | |
727 | return 0; | |
728 | } | |
729 | } | |
730 | #endif | |
731 | ||
9d5657db IF |
732 | /***************************************************************************** |
733 | * General Touch Part | |
734 | */ | |
735 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH | |
736 | static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
737 | { | |
eb083ba2 RY |
738 | dev->x = (pkt[2] << 8) | pkt[1]; |
739 | dev->y = (pkt[4] << 8) | pkt[3]; | |
9d5657db IF |
740 | dev->press = pkt[5] & 0xff; |
741 | dev->touch = pkt[0] & 0x01; | |
742 | ||
743 | return 1; | |
744 | } | |
745 | #endif | |
a14a8401 | 746 | |
14e40206 JJ |
747 | /***************************************************************************** |
748 | * GoTop Part | |
749 | */ | |
750 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP | |
751 | static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
752 | { | |
753 | dev->x = ((pkt[1] & 0x38) << 4) | pkt[2]; | |
754 | dev->y = ((pkt[1] & 0x07) << 7) | pkt[3]; | |
755 | dev->touch = pkt[0] & 0x01; | |
f7370699 JP |
756 | |
757 | return 1; | |
758 | } | |
759 | #endif | |
760 | ||
761 | /***************************************************************************** | |
762 | * JASTEC Part | |
763 | */ | |
764 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC | |
765 | static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
766 | { | |
767 | dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f); | |
768 | dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f); | |
769 | dev->touch = (pkt[0] & 0x40) >> 6; | |
770 | ||
14e40206 JJ |
771 | return 1; |
772 | } | |
773 | #endif | |
774 | ||
2330ed18 DS |
775 | /***************************************************************************** |
776 | * Zytronic Part | |
777 | */ | |
778 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC | |
779 | static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
780 | { | |
0a5ebc88 | 781 | struct usb_interface *intf = dev->interface; |
b741ab9d | 782 | |
2330ed18 DS |
783 | switch (pkt[0]) { |
784 | case 0x3A: /* command response */ | |
0a5ebc88 | 785 | dev_dbg(&intf->dev, "%s: Command response %d\n", __func__, pkt[1]); |
2330ed18 DS |
786 | break; |
787 | ||
788 | case 0xC0: /* down */ | |
789 | dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7); | |
790 | dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7); | |
791 | dev->touch = 1; | |
0a5ebc88 | 792 | dev_dbg(&intf->dev, "%s: down %d,%d\n", __func__, dev->x, dev->y); |
2330ed18 DS |
793 | return 1; |
794 | ||
795 | case 0x80: /* up */ | |
796 | dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7); | |
797 | dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7); | |
798 | dev->touch = 0; | |
0a5ebc88 | 799 | dev_dbg(&intf->dev, "%s: up %d,%d\n", __func__, dev->x, dev->y); |
2330ed18 DS |
800 | return 1; |
801 | ||
802 | default: | |
0a5ebc88 | 803 | dev_dbg(&intf->dev, "%s: Unknown return %d\n", __func__, pkt[0]); |
2330ed18 DS |
804 | break; |
805 | } | |
806 | ||
807 | return 0; | |
808 | } | |
809 | #endif | |
14e40206 | 810 | |
5197424c OZ |
811 | /***************************************************************************** |
812 | * NEXIO Part | |
813 | */ | |
814 | #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO | |
815 | ||
816 | #define NEXIO_TIMEOUT 5000 | |
817 | #define NEXIO_BUFSIZE 1024 | |
818 | #define NEXIO_THRESHOLD 50 | |
819 | ||
820 | struct nexio_priv { | |
821 | struct urb *ack; | |
822 | unsigned char *ack_buf; | |
823 | }; | |
824 | ||
825 | struct nexio_touch_packet { | |
826 | u8 flags; /* 0xe1 = touch, 0xe1 = release */ | |
827 | __be16 data_len; /* total bytes of touch data */ | |
828 | __be16 x_len; /* bytes for X axis */ | |
829 | __be16 y_len; /* bytes for Y axis */ | |
830 | u8 data[]; | |
831 | } __attribute__ ((packed)); | |
832 | ||
833 | static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 }; | |
834 | static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f }; | |
835 | ||
836 | static void nexio_ack_complete(struct urb *urb) | |
837 | { | |
838 | } | |
839 | ||
a8aef622 ON |
840 | static int nexio_alloc(struct usbtouch_usb *usbtouch) |
841 | { | |
842 | struct nexio_priv *priv; | |
843 | int ret = -ENOMEM; | |
844 | ||
845 | usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL); | |
846 | if (!usbtouch->priv) | |
847 | goto out_buf; | |
848 | ||
849 | priv = usbtouch->priv; | |
850 | ||
851 | priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt), | |
852 | GFP_KERNEL); | |
853 | if (!priv->ack_buf) | |
854 | goto err_priv; | |
855 | ||
856 | priv->ack = usb_alloc_urb(0, GFP_KERNEL); | |
857 | if (!priv->ack) { | |
0a5ebc88 | 858 | dev_dbg(&usbtouch->interface->dev, |
b741ab9d | 859 | "%s - usb_alloc_urb failed: usbtouch->ack\n", __func__); |
a8aef622 ON |
860 | goto err_ack_buf; |
861 | } | |
862 | ||
863 | return 0; | |
864 | ||
865 | err_ack_buf: | |
866 | kfree(priv->ack_buf); | |
867 | err_priv: | |
868 | kfree(priv); | |
869 | out_buf: | |
870 | return ret; | |
871 | } | |
872 | ||
5197424c OZ |
873 | static int nexio_init(struct usbtouch_usb *usbtouch) |
874 | { | |
875 | struct usb_device *dev = interface_to_usbdev(usbtouch->interface); | |
876 | struct usb_host_interface *interface = usbtouch->interface->cur_altsetting; | |
a8aef622 | 877 | struct nexio_priv *priv = usbtouch->priv; |
5197424c OZ |
878 | int ret = -ENOMEM; |
879 | int actual_len, i; | |
880 | unsigned char *buf; | |
881 | char *firmware_ver = NULL, *device_name = NULL; | |
882 | int input_ep = 0, output_ep = 0; | |
883 | ||
884 | /* find first input and output endpoint */ | |
885 | for (i = 0; i < interface->desc.bNumEndpoints; i++) { | |
886 | if (!input_ep && | |
887 | usb_endpoint_dir_in(&interface->endpoint[i].desc)) | |
888 | input_ep = interface->endpoint[i].desc.bEndpointAddress; | |
889 | if (!output_ep && | |
890 | usb_endpoint_dir_out(&interface->endpoint[i].desc)) | |
891 | output_ep = interface->endpoint[i].desc.bEndpointAddress; | |
892 | } | |
893 | if (!input_ep || !output_ep) | |
894 | return -ENXIO; | |
895 | ||
a8aef622 | 896 | buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO); |
5197424c OZ |
897 | if (!buf) |
898 | goto out_buf; | |
899 | ||
900 | /* two empty reads */ | |
901 | for (i = 0; i < 2; i++) { | |
902 | ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep), | |
903 | buf, NEXIO_BUFSIZE, &actual_len, | |
904 | NEXIO_TIMEOUT); | |
905 | if (ret < 0) | |
906 | goto out_buf; | |
907 | } | |
908 | ||
909 | /* send init command */ | |
910 | memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt)); | |
911 | ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep), | |
912 | buf, sizeof(nexio_init_pkt), &actual_len, | |
913 | NEXIO_TIMEOUT); | |
914 | if (ret < 0) | |
915 | goto out_buf; | |
916 | ||
917 | /* read replies */ | |
918 | for (i = 0; i < 3; i++) { | |
919 | memset(buf, 0, NEXIO_BUFSIZE); | |
920 | ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep), | |
921 | buf, NEXIO_BUFSIZE, &actual_len, | |
922 | NEXIO_TIMEOUT); | |
923 | if (ret < 0 || actual_len < 1 || buf[1] != actual_len) | |
924 | continue; | |
925 | switch (buf[0]) { | |
926 | case 0x83: /* firmware version */ | |
927 | if (!firmware_ver) | |
a8aef622 | 928 | firmware_ver = kstrdup(&buf[2], GFP_NOIO); |
5197424c OZ |
929 | break; |
930 | case 0x84: /* device name */ | |
931 | if (!device_name) | |
a8aef622 | 932 | device_name = kstrdup(&buf[2], GFP_NOIO); |
5197424c OZ |
933 | break; |
934 | } | |
935 | } | |
936 | ||
937 | printk(KERN_INFO "Nexio device: %s, firmware version: %s\n", | |
938 | device_name, firmware_ver); | |
939 | ||
940 | kfree(firmware_ver); | |
941 | kfree(device_name); | |
942 | ||
5197424c OZ |
943 | usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep), |
944 | priv->ack_buf, sizeof(nexio_ack_pkt), | |
945 | nexio_ack_complete, usbtouch); | |
946 | ret = 0; | |
5197424c | 947 | |
5197424c OZ |
948 | out_buf: |
949 | kfree(buf); | |
950 | return ret; | |
951 | } | |
952 | ||
953 | static void nexio_exit(struct usbtouch_usb *usbtouch) | |
954 | { | |
955 | struct nexio_priv *priv = usbtouch->priv; | |
956 | ||
957 | usb_kill_urb(priv->ack); | |
958 | usb_free_urb(priv->ack); | |
959 | kfree(priv->ack_buf); | |
960 | kfree(priv); | |
961 | } | |
962 | ||
963 | static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt) | |
964 | { | |
5197424c OZ |
965 | struct nexio_touch_packet *packet = (void *) pkt; |
966 | struct nexio_priv *priv = usbtouch->priv; | |
4aa5bbec DT |
967 | unsigned int data_len = be16_to_cpu(packet->data_len); |
968 | unsigned int x_len = be16_to_cpu(packet->x_len); | |
969 | unsigned int y_len = be16_to_cpu(packet->y_len); | |
970 | int x, y, begin_x, begin_y, end_x, end_y, w, h, ret; | |
5197424c OZ |
971 | |
972 | /* got touch data? */ | |
973 | if ((pkt[0] & 0xe0) != 0xe0) | |
974 | return 0; | |
975 | ||
4aa5bbec DT |
976 | if (data_len > 0xff) |
977 | data_len -= 0x100; | |
978 | if (x_len > 0xff) | |
979 | x_len -= 0x80; | |
388bbcad | 980 | |
5197424c OZ |
981 | /* send ACK */ |
982 | ret = usb_submit_urb(priv->ack, GFP_ATOMIC); | |
983 | ||
984 | if (!usbtouch->type->max_xc) { | |
4aa5bbec DT |
985 | usbtouch->type->max_xc = 2 * x_len; |
986 | input_set_abs_params(usbtouch->input, ABS_X, | |
987 | 0, usbtouch->type->max_xc, 0, 0); | |
988 | usbtouch->type->max_yc = 2 * y_len; | |
989 | input_set_abs_params(usbtouch->input, ABS_Y, | |
990 | 0, usbtouch->type->max_yc, 0, 0); | |
5197424c OZ |
991 | } |
992 | /* | |
993 | * The device reports state of IR sensors on X and Y axes. | |
994 | * Each byte represents "darkness" percentage (0-100) of one element. | |
995 | * 17" touchscreen reports only 64 x 52 bytes so the resolution is low. | |
996 | * This also means that there's a limited multi-touch capability but | |
997 | * it's disabled (and untested) here as there's no X driver for that. | |
998 | */ | |
999 | begin_x = end_x = begin_y = end_y = -1; | |
4aa5bbec | 1000 | for (x = 0; x < x_len; x++) { |
5197424c OZ |
1001 | if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) { |
1002 | begin_x = x; | |
1003 | continue; | |
1004 | } | |
1005 | if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) { | |
1006 | end_x = x - 1; | |
4aa5bbec | 1007 | for (y = x_len; y < data_len; y++) { |
5197424c | 1008 | if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) { |
4aa5bbec | 1009 | begin_y = y - x_len; |
5197424c OZ |
1010 | continue; |
1011 | } | |
1012 | if (end_y == -1 && | |
1013 | begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) { | |
4aa5bbec | 1014 | end_y = y - 1 - x_len; |
5197424c OZ |
1015 | w = end_x - begin_x; |
1016 | h = end_y - begin_y; | |
1017 | #if 0 | |
1018 | /* multi-touch */ | |
1019 | input_report_abs(usbtouch->input, | |
1020 | ABS_MT_TOUCH_MAJOR, max(w,h)); | |
1021 | input_report_abs(usbtouch->input, | |
1022 | ABS_MT_TOUCH_MINOR, min(x,h)); | |
1023 | input_report_abs(usbtouch->input, | |
1024 | ABS_MT_POSITION_X, 2*begin_x+w); | |
1025 | input_report_abs(usbtouch->input, | |
1026 | ABS_MT_POSITION_Y, 2*begin_y+h); | |
1027 | input_report_abs(usbtouch->input, | |
1028 | ABS_MT_ORIENTATION, w > h); | |
1029 | input_mt_sync(usbtouch->input); | |
1030 | #endif | |
1031 | /* single touch */ | |
1032 | usbtouch->x = 2 * begin_x + w; | |
1033 | usbtouch->y = 2 * begin_y + h; | |
1034 | usbtouch->touch = packet->flags & 0x01; | |
1035 | begin_y = end_y = -1; | |
1036 | return 1; | |
1037 | } | |
1038 | } | |
1039 | begin_x = end_x = -1; | |
1040 | } | |
1041 | ||
1042 | } | |
1043 | return 0; | |
1044 | } | |
1045 | #endif | |
1046 | ||
1047 | ||
d2cc817a MG |
1048 | /***************************************************************************** |
1049 | * ELO part | |
1050 | */ | |
1051 | ||
1052 | #ifdef CONFIG_TOUCHSCREEN_USB_ELO | |
1053 | ||
1054 | static int elo_read_data(struct usbtouch_usb *dev, unsigned char *pkt) | |
1055 | { | |
1056 | dev->x = (pkt[3] << 8) | pkt[2]; | |
1057 | dev->y = (pkt[5] << 8) | pkt[4]; | |
1058 | dev->touch = pkt[6] > 0; | |
1059 | dev->press = pkt[6]; | |
1060 | ||
1061 | return 1; | |
1062 | } | |
1063 | #endif | |
1064 | ||
1065 | ||
1d3e2023 DR |
1066 | /***************************************************************************** |
1067 | * the different device descriptors | |
1068 | */ | |
62aa366d DR |
1069 | #ifdef MULTI_PACKET |
1070 | static void usbtouch_process_multi(struct usbtouch_usb *usbtouch, | |
1071 | unsigned char *pkt, int len); | |
1072 | #endif | |
1073 | ||
1d3e2023 | 1074 | static struct usbtouch_device_info usbtouch_dev_info[] = { |
d2cc817a MG |
1075 | #ifdef CONFIG_TOUCHSCREEN_USB_ELO |
1076 | [DEVTYPE_ELO] = { | |
1077 | .min_xc = 0x0, | |
1078 | .max_xc = 0x0fff, | |
1079 | .min_yc = 0x0, | |
1080 | .max_yc = 0x0fff, | |
1081 | .max_press = 0xff, | |
1082 | .rept_size = 8, | |
1083 | .read_data = elo_read_data, | |
1084 | }, | |
1085 | #endif | |
1086 | ||
c6f8d706 | 1087 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
1d3e2023 DR |
1088 | [DEVTYPE_EGALAX] = { |
1089 | .min_xc = 0x0, | |
1090 | .max_xc = 0x07ff, | |
1091 | .min_yc = 0x0, | |
1092 | .max_yc = 0x07ff, | |
1093 | .rept_size = 16, | |
5d892665 DR |
1094 | .process_pkt = usbtouch_process_multi, |
1095 | .get_pkt_len = egalax_get_pkt_len, | |
1d3e2023 | 1096 | .read_data = egalax_read_data, |
037a833e | 1097 | .init = egalax_init, |
1d3e2023 DR |
1098 | }, |
1099 | #endif | |
1100 | ||
c6f8d706 | 1101 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
1d3e2023 DR |
1102 | [DEVTYPE_PANJIT] = { |
1103 | .min_xc = 0x0, | |
1104 | .max_xc = 0x0fff, | |
1105 | .min_yc = 0x0, | |
1106 | .max_yc = 0x0fff, | |
1107 | .rept_size = 8, | |
1108 | .read_data = panjit_read_data, | |
1109 | }, | |
1110 | #endif | |
1111 | ||
c6f8d706 | 1112 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
1d3e2023 DR |
1113 | [DEVTYPE_3M] = { |
1114 | .min_xc = 0x0, | |
1115 | .max_xc = 0x4000, | |
1116 | .min_yc = 0x0, | |
1117 | .max_yc = 0x4000, | |
1118 | .rept_size = 11, | |
1119 | .read_data = mtouch_read_data, | |
1120 | .init = mtouch_init, | |
1121 | }, | |
1122 | #endif | |
1123 | ||
c6f8d706 | 1124 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
1d3e2023 DR |
1125 | [DEVTYPE_ITM] = { |
1126 | .min_xc = 0x0, | |
1127 | .max_xc = 0x0fff, | |
1128 | .min_yc = 0x0, | |
1129 | .max_yc = 0x0fff, | |
1130 | .max_press = 0xff, | |
1131 | .rept_size = 8, | |
1132 | .read_data = itm_read_data, | |
1133 | }, | |
1134 | #endif | |
5d892665 | 1135 | |
c6f8d706 | 1136 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
5d892665 DR |
1137 | [DEVTYPE_ETURBO] = { |
1138 | .min_xc = 0x0, | |
1139 | .max_xc = 0x07ff, | |
1140 | .min_yc = 0x0, | |
1141 | .max_yc = 0x07ff, | |
1142 | .rept_size = 8, | |
5d892665 DR |
1143 | .process_pkt = usbtouch_process_multi, |
1144 | .get_pkt_len = eturbo_get_pkt_len, | |
1145 | .read_data = eturbo_read_data, | |
1146 | }, | |
1147 | #endif | |
1148 | ||
c6f8d706 | 1149 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
5d892665 DR |
1150 | [DEVTYPE_GUNZE] = { |
1151 | .min_xc = 0x0, | |
1152 | .max_xc = 0x0fff, | |
1153 | .min_yc = 0x0, | |
1154 | .max_yc = 0x0fff, | |
1155 | .rept_size = 4, | |
1156 | .read_data = gunze_read_data, | |
1157 | }, | |
1158 | #endif | |
24ced062 | 1159 | |
c6f8d706 | 1160 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
24ced062 HS |
1161 | [DEVTYPE_DMC_TSC10] = { |
1162 | .min_xc = 0x0, | |
1163 | .max_xc = 0x03ff, | |
1164 | .min_yc = 0x0, | |
1165 | .max_yc = 0x03ff, | |
1166 | .rept_size = 5, | |
1167 | .init = dmc_tsc10_init, | |
1168 | .read_data = dmc_tsc10_read_data, | |
1169 | }, | |
1170 | #endif | |
df561fcd OZ |
1171 | |
1172 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH | |
1173 | [DEVTYPE_IRTOUCH] = { | |
1174 | .min_xc = 0x0, | |
1175 | .max_xc = 0x0fff, | |
1176 | .min_yc = 0x0, | |
1177 | .max_yc = 0x0fff, | |
1178 | .rept_size = 8, | |
1179 | .read_data = irtouch_read_data, | |
1180 | }, | |
1181 | #endif | |
a14a8401 OZ |
1182 | |
1183 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK | |
1184 | [DEVTYPE_IDEALTEK] = { | |
1185 | .min_xc = 0x0, | |
1186 | .max_xc = 0x0fff, | |
1187 | .min_yc = 0x0, | |
1188 | .max_yc = 0x0fff, | |
1189 | .rept_size = 8, | |
a14a8401 OZ |
1190 | .process_pkt = usbtouch_process_multi, |
1191 | .get_pkt_len = idealtek_get_pkt_len, | |
1192 | .read_data = idealtek_read_data, | |
1193 | }, | |
1194 | #endif | |
9d5657db IF |
1195 | |
1196 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH | |
1197 | [DEVTYPE_GENERAL_TOUCH] = { | |
1198 | .min_xc = 0x0, | |
eb083ba2 | 1199 | .max_xc = 0x7fff, |
9d5657db | 1200 | .min_yc = 0x0, |
eb083ba2 | 1201 | .max_yc = 0x7fff, |
9d5657db IF |
1202 | .rept_size = 7, |
1203 | .read_data = general_touch_read_data, | |
14e40206 | 1204 | }, |
9d5657db IF |
1205 | #endif |
1206 | ||
14e40206 JJ |
1207 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP |
1208 | [DEVTYPE_GOTOP] = { | |
1209 | .min_xc = 0x0, | |
1210 | .max_xc = 0x03ff, | |
1211 | .min_yc = 0x0, | |
1212 | .max_yc = 0x03ff, | |
1213 | .rept_size = 4, | |
1214 | .read_data = gotop_read_data, | |
1215 | }, | |
1216 | #endif | |
f7370699 JP |
1217 | |
1218 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC | |
1219 | [DEVTYPE_JASTEC] = { | |
1220 | .min_xc = 0x0, | |
1221 | .max_xc = 0x0fff, | |
1222 | .min_yc = 0x0, | |
1223 | .max_yc = 0x0fff, | |
1224 | .rept_size = 4, | |
1225 | .read_data = jastec_read_data, | |
1226 | }, | |
1227 | #endif | |
9e3b2583 FE |
1228 | |
1229 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I | |
1230 | [DEVTYPE_E2I] = { | |
1231 | .min_xc = 0x0, | |
1232 | .max_xc = 0x7fff, | |
1233 | .min_yc = 0x0, | |
1234 | .max_yc = 0x7fff, | |
1235 | .rept_size = 6, | |
1236 | .init = e2i_init, | |
1237 | .read_data = e2i_read_data, | |
1238 | }, | |
1239 | #endif | |
2330ed18 DS |
1240 | |
1241 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC | |
1242 | [DEVTYPE_ZYTRONIC] = { | |
1243 | .min_xc = 0x0, | |
1244 | .max_xc = 0x03ff, | |
1245 | .min_yc = 0x0, | |
1246 | .max_yc = 0x03ff, | |
1247 | .rept_size = 5, | |
1248 | .read_data = zytronic_read_data, | |
1249 | .irq_always = true, | |
1250 | }, | |
1251 | #endif | |
dbe1420b | 1252 | |
38771bb4 PŠ |
1253 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB |
1254 | [DEVTYPE_TC45USB] = { | |
dbe1420b PŠ |
1255 | .min_xc = 0x0, |
1256 | .max_xc = 0x0fff, | |
1257 | .min_yc = 0x0, | |
1258 | .max_yc = 0x0fff, | |
1259 | .rept_size = 5, | |
38771bb4 | 1260 | .read_data = tc45usb_read_data, |
dbe1420b PŠ |
1261 | }, |
1262 | #endif | |
5197424c OZ |
1263 | |
1264 | #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO | |
1265 | [DEVTYPE_NEXIO] = { | |
388bbcad | 1266 | .rept_size = 1024, |
5197424c OZ |
1267 | .irq_always = true, |
1268 | .read_data = nexio_read_data, | |
a8aef622 | 1269 | .alloc = nexio_alloc, |
5197424c OZ |
1270 | .init = nexio_init, |
1271 | .exit = nexio_exit, | |
1272 | }, | |
1273 | #endif | |
aa87512f AV |
1274 | #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH |
1275 | [DEVTYPE_ETOUCH] = { | |
1276 | .min_xc = 0x0, | |
1277 | .max_xc = 0x07ff, | |
1278 | .min_yc = 0x0, | |
1279 | .max_yc = 0x07ff, | |
1280 | .rept_size = 16, | |
1281 | .process_pkt = usbtouch_process_multi, | |
1282 | .get_pkt_len = etouch_get_pkt_len, | |
1283 | .read_data = etouch_read_data, | |
1284 | }, | |
1285 | #endif | |
1d3e2023 DR |
1286 | }; |
1287 | ||
1288 | ||
1289 | /***************************************************************************** | |
1290 | * Generic Part | |
1291 | */ | |
1292 | static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch, | |
7d12e780 | 1293 | unsigned char *pkt, int len) |
1d3e2023 | 1294 | { |
1d3e2023 DR |
1295 | struct usbtouch_device_info *type = usbtouch->type; |
1296 | ||
c9d8c2b3 | 1297 | if (!type->read_data(usbtouch, pkt)) |
1d3e2023 DR |
1298 | return; |
1299 | ||
c9d8c2b3 | 1300 | input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch); |
1d3e2023 DR |
1301 | |
1302 | if (swap_xy) { | |
c9d8c2b3 DR |
1303 | input_report_abs(usbtouch->input, ABS_X, usbtouch->y); |
1304 | input_report_abs(usbtouch->input, ABS_Y, usbtouch->x); | |
1d3e2023 | 1305 | } else { |
c9d8c2b3 DR |
1306 | input_report_abs(usbtouch->input, ABS_X, usbtouch->x); |
1307 | input_report_abs(usbtouch->input, ABS_Y, usbtouch->y); | |
1d3e2023 DR |
1308 | } |
1309 | if (type->max_press) | |
c9d8c2b3 | 1310 | input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press); |
1d3e2023 DR |
1311 | input_sync(usbtouch->input); |
1312 | } | |
1313 | ||
1314 | ||
5d892665 DR |
1315 | #ifdef MULTI_PACKET |
1316 | static void usbtouch_process_multi(struct usbtouch_usb *usbtouch, | |
5d892665 DR |
1317 | unsigned char *pkt, int len) |
1318 | { | |
1319 | unsigned char *buffer; | |
1320 | int pkt_len, pos, buf_len, tmp; | |
1321 | ||
1322 | /* process buffer */ | |
1323 | if (unlikely(usbtouch->buf_len)) { | |
1324 | /* try to get size */ | |
1325 | pkt_len = usbtouch->type->get_pkt_len( | |
1326 | usbtouch->buffer, usbtouch->buf_len); | |
1327 | ||
1328 | /* drop? */ | |
1329 | if (unlikely(!pkt_len)) | |
1330 | goto out_flush_buf; | |
1331 | ||
1332 | /* need to append -pkt_len bytes before able to get size */ | |
1333 | if (unlikely(pkt_len < 0)) { | |
1334 | int append = -pkt_len; | |
1335 | if (unlikely(append > len)) | |
1336 | append = len; | |
1337 | if (usbtouch->buf_len + append >= usbtouch->type->rept_size) | |
1338 | goto out_flush_buf; | |
1339 | memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append); | |
1340 | usbtouch->buf_len += append; | |
1341 | ||
1342 | pkt_len = usbtouch->type->get_pkt_len( | |
1343 | usbtouch->buffer, usbtouch->buf_len); | |
1344 | if (pkt_len < 0) | |
1345 | return; | |
1346 | } | |
1347 | ||
1348 | /* append */ | |
1349 | tmp = pkt_len - usbtouch->buf_len; | |
1350 | if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size) | |
1351 | goto out_flush_buf; | |
1352 | memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp); | |
7d12e780 | 1353 | usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len); |
5d892665 DR |
1354 | |
1355 | buffer = pkt + tmp; | |
1356 | buf_len = len - tmp; | |
1357 | } else { | |
1358 | buffer = pkt; | |
1359 | buf_len = len; | |
1360 | } | |
1361 | ||
1362 | /* loop over the received packet, process */ | |
1363 | pos = 0; | |
1364 | while (pos < buf_len) { | |
1365 | /* get packet len */ | |
62aa366d DR |
1366 | pkt_len = usbtouch->type->get_pkt_len(buffer + pos, |
1367 | buf_len - pos); | |
5d892665 | 1368 | |
62aa366d DR |
1369 | /* unknown packet: skip one byte */ |
1370 | if (unlikely(!pkt_len)) { | |
1371 | pos++; | |
1372 | continue; | |
1373 | } | |
5d892665 DR |
1374 | |
1375 | /* full packet: process */ | |
1376 | if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) { | |
7d12e780 | 1377 | usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len); |
5d892665 DR |
1378 | } else { |
1379 | /* incomplete packet: save in buffer */ | |
1380 | memcpy(usbtouch->buffer, buffer + pos, buf_len - pos); | |
1381 | usbtouch->buf_len = buf_len - pos; | |
1382 | return; | |
1383 | } | |
1384 | pos += pkt_len; | |
1385 | } | |
1386 | ||
1387 | out_flush_buf: | |
1388 | usbtouch->buf_len = 0; | |
1389 | return; | |
1390 | } | |
1391 | #endif | |
1392 | ||
1393 | ||
7d12e780 | 1394 | static void usbtouch_irq(struct urb *urb) |
1d3e2023 DR |
1395 | { |
1396 | struct usbtouch_usb *usbtouch = urb->context; | |
0a5ebc88 | 1397 | struct device *dev = &usbtouch->interface->dev; |
1d3e2023 DR |
1398 | int retval; |
1399 | ||
1400 | switch (urb->status) { | |
1401 | case 0: | |
1402 | /* success */ | |
1403 | break; | |
38e2bfc9 | 1404 | case -ETIME: |
1d3e2023 | 1405 | /* this urb is timing out */ |
b741ab9d GKH |
1406 | dev_dbg(dev, |
1407 | "%s - urb timed out - was the device unplugged?\n", | |
1408 | __func__); | |
1d3e2023 DR |
1409 | return; |
1410 | case -ECONNRESET: | |
1411 | case -ENOENT: | |
1412 | case -ESHUTDOWN: | |
5197424c | 1413 | case -EPIPE: |
1d3e2023 | 1414 | /* this urb is terminated, clean up */ |
b741ab9d GKH |
1415 | dev_dbg(dev, "%s - urb shutting down with status: %d\n", |
1416 | __func__, urb->status); | |
1d3e2023 DR |
1417 | return; |
1418 | default: | |
b741ab9d GKH |
1419 | dev_dbg(dev, "%s - nonzero urb status received: %d\n", |
1420 | __func__, urb->status); | |
1d3e2023 DR |
1421 | goto exit; |
1422 | } | |
1423 | ||
7d12e780 | 1424 | usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length); |
1d3e2023 DR |
1425 | |
1426 | exit: | |
5d9efc59 | 1427 | usb_mark_last_busy(interface_to_usbdev(usbtouch->interface)); |
1d3e2023 DR |
1428 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
1429 | if (retval) | |
0a5ebc88 | 1430 | dev_err(dev, "%s - usb_submit_urb failed with result: %d\n", |
e27ad0fe | 1431 | __func__, retval); |
1d3e2023 DR |
1432 | } |
1433 | ||
1434 | static int usbtouch_open(struct input_dev *input) | |
1435 | { | |
7791bdae | 1436 | struct usbtouch_usb *usbtouch = input_get_drvdata(input); |
5d9efc59 | 1437 | int r; |
1d3e2023 | 1438 | |
fea4d14b | 1439 | usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface); |
1d3e2023 | 1440 | |
5d9efc59 ON |
1441 | r = usb_autopm_get_interface(usbtouch->interface) ? -EIO : 0; |
1442 | if (r < 0) | |
1443 | goto out; | |
1444 | ||
2330ed18 | 1445 | if (!usbtouch->type->irq_always) { |
5d9efc59 ON |
1446 | if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) { |
1447 | r = -EIO; | |
1448 | goto out_put; | |
1449 | } | |
2330ed18 | 1450 | } |
1d3e2023 | 1451 | |
5d9efc59 ON |
1452 | usbtouch->interface->needs_remote_wakeup = 1; |
1453 | out_put: | |
1454 | usb_autopm_put_interface(usbtouch->interface); | |
1455 | out: | |
1456 | return r; | |
1d3e2023 DR |
1457 | } |
1458 | ||
1459 | static void usbtouch_close(struct input_dev *input) | |
1460 | { | |
7791bdae | 1461 | struct usbtouch_usb *usbtouch = input_get_drvdata(input); |
5d9efc59 | 1462 | int r; |
1d3e2023 | 1463 | |
2330ed18 DS |
1464 | if (!usbtouch->type->irq_always) |
1465 | usb_kill_urb(usbtouch->irq); | |
5d9efc59 ON |
1466 | r = usb_autopm_get_interface(usbtouch->interface); |
1467 | usbtouch->interface->needs_remote_wakeup = 0; | |
1468 | if (!r) | |
1469 | usb_autopm_put_interface(usbtouch->interface); | |
1d3e2023 DR |
1470 | } |
1471 | ||
ed4299e1 ON |
1472 | static int usbtouch_suspend |
1473 | (struct usb_interface *intf, pm_message_t message) | |
1474 | { | |
1475 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); | |
1476 | ||
1477 | usb_kill_urb(usbtouch->irq); | |
1478 | ||
1479 | return 0; | |
1480 | } | |
1481 | ||
1482 | static int usbtouch_resume(struct usb_interface *intf) | |
1483 | { | |
1484 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); | |
1485 | struct input_dev *input = usbtouch->input; | |
1486 | int result = 0; | |
1487 | ||
1488 | mutex_lock(&input->mutex); | |
1489 | if (input->users || usbtouch->type->irq_always) | |
1490 | result = usb_submit_urb(usbtouch->irq, GFP_NOIO); | |
1491 | mutex_unlock(&input->mutex); | |
1492 | ||
1493 | return result; | |
1494 | } | |
1d3e2023 | 1495 | |
a8aef622 ON |
1496 | static int usbtouch_reset_resume(struct usb_interface *intf) |
1497 | { | |
1498 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); | |
1499 | struct input_dev *input = usbtouch->input; | |
1500 | int err = 0; | |
1501 | ||
1502 | /* reinit the device */ | |
1503 | if (usbtouch->type->init) { | |
1504 | err = usbtouch->type->init(usbtouch); | |
1505 | if (err) { | |
0a5ebc88 | 1506 | dev_dbg(&intf->dev, |
b741ab9d GKH |
1507 | "%s - type->init() failed, err: %d\n", |
1508 | __func__, err); | |
a8aef622 ON |
1509 | return err; |
1510 | } | |
1511 | } | |
1512 | ||
1513 | /* restart IO if needed */ | |
1514 | mutex_lock(&input->mutex); | |
1515 | if (input->users) | |
1516 | err = usb_submit_urb(usbtouch->irq, GFP_NOIO); | |
1517 | mutex_unlock(&input->mutex); | |
1518 | ||
1519 | return err; | |
1520 | } | |
1521 | ||
1d3e2023 DR |
1522 | static void usbtouch_free_buffers(struct usb_device *udev, |
1523 | struct usbtouch_usb *usbtouch) | |
1524 | { | |
4ef38351 | 1525 | usb_free_coherent(udev, usbtouch->data_size, |
997ea58e | 1526 | usbtouch->data, usbtouch->data_dma); |
1d3e2023 DR |
1527 | kfree(usbtouch->buffer); |
1528 | } | |
1529 | ||
f4a5e359 OZ |
1530 | static struct usb_endpoint_descriptor * |
1531 | usbtouch_get_input_endpoint(struct usb_host_interface *interface) | |
1532 | { | |
1533 | int i; | |
1534 | ||
1535 | for (i = 0; i < interface->desc.bNumEndpoints; i++) | |
1536 | if (usb_endpoint_dir_in(&interface->endpoint[i].desc)) | |
1537 | return &interface->endpoint[i].desc; | |
1538 | ||
1539 | return NULL; | |
1540 | } | |
1d3e2023 DR |
1541 | |
1542 | static int usbtouch_probe(struct usb_interface *intf, | |
1543 | const struct usb_device_id *id) | |
1544 | { | |
1545 | struct usbtouch_usb *usbtouch; | |
1546 | struct input_dev *input_dev; | |
1d3e2023 DR |
1547 | struct usb_endpoint_descriptor *endpoint; |
1548 | struct usb_device *udev = interface_to_usbdev(intf); | |
1549 | struct usbtouch_device_info *type; | |
5d892665 | 1550 | int err = -ENOMEM; |
ec42d448 DR |
1551 | |
1552 | /* some devices are ignored */ | |
1553 | if (id->driver_info == DEVTYPE_IGNORE) | |
1554 | return -ENODEV; | |
1d3e2023 | 1555 | |
f4a5e359 OZ |
1556 | endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting); |
1557 | if (!endpoint) | |
1558 | return -ENXIO; | |
1d3e2023 DR |
1559 | |
1560 | usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL); | |
1561 | input_dev = input_allocate_device(); | |
1562 | if (!usbtouch || !input_dev) | |
1563 | goto out_free; | |
1564 | ||
1565 | type = &usbtouch_dev_info[id->driver_info]; | |
1566 | usbtouch->type = type; | |
1567 | if (!type->process_pkt) | |
1568 | type->process_pkt = usbtouch_process_pkt; | |
1569 | ||
4ef38351 CE |
1570 | usbtouch->data_size = type->rept_size; |
1571 | if (type->get_pkt_len) { | |
1572 | /* | |
1573 | * When dealing with variable-length packets we should | |
1574 | * not request more than wMaxPacketSize bytes at once | |
1575 | * as we do not know if there is more data coming or | |
1576 | * we filled exactly wMaxPacketSize bytes and there is | |
1577 | * nothing else. | |
1578 | */ | |
1579 | usbtouch->data_size = min(usbtouch->data_size, | |
1580 | usb_endpoint_maxp(endpoint)); | |
1581 | } | |
1582 | ||
1583 | usbtouch->data = usb_alloc_coherent(udev, usbtouch->data_size, | |
997ea58e | 1584 | GFP_KERNEL, &usbtouch->data_dma); |
1d3e2023 DR |
1585 | if (!usbtouch->data) |
1586 | goto out_free; | |
1587 | ||
62aa366d | 1588 | if (type->get_pkt_len) { |
1d3e2023 DR |
1589 | usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL); |
1590 | if (!usbtouch->buffer) | |
1591 | goto out_free_buffers; | |
1592 | } | |
1593 | ||
1594 | usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL); | |
1595 | if (!usbtouch->irq) { | |
b741ab9d GKH |
1596 | dev_dbg(&intf->dev, |
1597 | "%s - usb_alloc_urb failed: usbtouch->irq\n", __func__); | |
1d3e2023 DR |
1598 | goto out_free_buffers; |
1599 | } | |
1600 | ||
fea4d14b | 1601 | usbtouch->interface = intf; |
1d3e2023 DR |
1602 | usbtouch->input = input_dev; |
1603 | ||
1604 | if (udev->manufacturer) | |
1605 | strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name)); | |
1606 | ||
1607 | if (udev->product) { | |
1608 | if (udev->manufacturer) | |
1609 | strlcat(usbtouch->name, " ", sizeof(usbtouch->name)); | |
1610 | strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name)); | |
1611 | } | |
1612 | ||
1613 | if (!strlen(usbtouch->name)) | |
1614 | snprintf(usbtouch->name, sizeof(usbtouch->name), | |
1615 | "USB Touchscreen %04x:%04x", | |
1616 | le16_to_cpu(udev->descriptor.idVendor), | |
1617 | le16_to_cpu(udev->descriptor.idProduct)); | |
1618 | ||
1619 | usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys)); | |
7b6dff98 | 1620 | strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys)); |
1d3e2023 DR |
1621 | |
1622 | input_dev->name = usbtouch->name; | |
1623 | input_dev->phys = usbtouch->phys; | |
1624 | usb_to_input_id(udev, &input_dev->id); | |
c0f82d57 | 1625 | input_dev->dev.parent = &intf->dev; |
7791bdae DT |
1626 | |
1627 | input_set_drvdata(input_dev, usbtouch); | |
1628 | ||
1d3e2023 DR |
1629 | input_dev->open = usbtouch_open; |
1630 | input_dev->close = usbtouch_close; | |
1631 | ||
7b19ada2 JS |
1632 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
1633 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | |
1d3e2023 DR |
1634 | input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0); |
1635 | input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0); | |
1636 | if (type->max_press) | |
1637 | input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press, | |
1638 | type->max_press, 0, 0); | |
1639 | ||
5197424c OZ |
1640 | if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT) |
1641 | usb_fill_int_urb(usbtouch->irq, udev, | |
fea4d14b | 1642 | usb_rcvintpipe(udev, endpoint->bEndpointAddress), |
4ef38351 | 1643 | usbtouch->data, usbtouch->data_size, |
1d3e2023 | 1644 | usbtouch_irq, usbtouch, endpoint->bInterval); |
5197424c OZ |
1645 | else |
1646 | usb_fill_bulk_urb(usbtouch->irq, udev, | |
1647 | usb_rcvbulkpipe(udev, endpoint->bEndpointAddress), | |
4ef38351 | 1648 | usbtouch->data, usbtouch->data_size, |
5197424c | 1649 | usbtouch_irq, usbtouch); |
1d3e2023 | 1650 | |
fea4d14b | 1651 | usbtouch->irq->dev = udev; |
1d3e2023 DR |
1652 | usbtouch->irq->transfer_dma = usbtouch->data_dma; |
1653 | usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | |
1654 | ||
a8aef622 ON |
1655 | /* device specific allocations */ |
1656 | if (type->alloc) { | |
1657 | err = type->alloc(usbtouch); | |
1658 | if (err) { | |
b741ab9d GKH |
1659 | dev_dbg(&intf->dev, |
1660 | "%s - type->alloc() failed, err: %d\n", | |
1661 | __func__, err); | |
a8aef622 ON |
1662 | goto out_free_urb; |
1663 | } | |
1664 | } | |
1665 | ||
1666 | /* device specific initialisation*/ | |
1d3e2023 DR |
1667 | if (type->init) { |
1668 | err = type->init(usbtouch); | |
1669 | if (err) { | |
b741ab9d GKH |
1670 | dev_dbg(&intf->dev, |
1671 | "%s - type->init() failed, err: %d\n", | |
1672 | __func__, err); | |
a8aef622 | 1673 | goto out_do_exit; |
1d3e2023 DR |
1674 | } |
1675 | } | |
1676 | ||
1677 | err = input_register_device(usbtouch->input); | |
1678 | if (err) { | |
b741ab9d GKH |
1679 | dev_dbg(&intf->dev, |
1680 | "%s - input_register_device failed, err: %d\n", | |
1681 | __func__, err); | |
5197424c | 1682 | goto out_do_exit; |
1d3e2023 DR |
1683 | } |
1684 | ||
1685 | usb_set_intfdata(intf, usbtouch); | |
1686 | ||
1e87a430 | 1687 | if (usbtouch->type->irq_always) { |
5d9efc59 ON |
1688 | /* this can't fail */ |
1689 | usb_autopm_get_interface(intf); | |
1e87a430 OZ |
1690 | err = usb_submit_urb(usbtouch->irq, GFP_KERNEL); |
1691 | if (err) { | |
5d9efc59 | 1692 | usb_autopm_put_interface(intf); |
0a5ebc88 | 1693 | dev_err(&intf->dev, |
e27ad0fe GKH |
1694 | "%s - usb_submit_urb failed with result: %d\n", |
1695 | __func__, err); | |
1e87a430 OZ |
1696 | goto out_unregister_input; |
1697 | } | |
1698 | } | |
2330ed18 | 1699 | |
1d3e2023 DR |
1700 | return 0; |
1701 | ||
1e87a430 OZ |
1702 | out_unregister_input: |
1703 | input_unregister_device(input_dev); | |
1704 | input_dev = NULL; | |
5197424c OZ |
1705 | out_do_exit: |
1706 | if (type->exit) | |
1707 | type->exit(usbtouch); | |
1e87a430 OZ |
1708 | out_free_urb: |
1709 | usb_free_urb(usbtouch->irq); | |
1d3e2023 DR |
1710 | out_free_buffers: |
1711 | usbtouch_free_buffers(udev, usbtouch); | |
1712 | out_free: | |
1713 | input_free_device(input_dev); | |
1714 | kfree(usbtouch); | |
5d892665 | 1715 | return err; |
1d3e2023 DR |
1716 | } |
1717 | ||
1718 | static void usbtouch_disconnect(struct usb_interface *intf) | |
1719 | { | |
1720 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); | |
1721 | ||
1d3e2023 DR |
1722 | if (!usbtouch) |
1723 | return; | |
1724 | ||
0a5ebc88 | 1725 | dev_dbg(&intf->dev, |
b741ab9d GKH |
1726 | "%s - usbtouch is initialized, cleaning up\n", __func__); |
1727 | ||
1d3e2023 | 1728 | usb_set_intfdata(intf, NULL); |
722232bc | 1729 | /* this will stop IO via close */ |
1d3e2023 DR |
1730 | input_unregister_device(usbtouch->input); |
1731 | usb_free_urb(usbtouch->irq); | |
5197424c OZ |
1732 | if (usbtouch->type->exit) |
1733 | usbtouch->type->exit(usbtouch); | |
1d3e2023 DR |
1734 | usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch); |
1735 | kfree(usbtouch); | |
1736 | } | |
1737 | ||
1738 | MODULE_DEVICE_TABLE(usb, usbtouch_devices); | |
1739 | ||
1740 | static struct usb_driver usbtouch_driver = { | |
1741 | .name = "usbtouchscreen", | |
1742 | .probe = usbtouch_probe, | |
1743 | .disconnect = usbtouch_disconnect, | |
ed4299e1 ON |
1744 | .suspend = usbtouch_suspend, |
1745 | .resume = usbtouch_resume, | |
a8aef622 | 1746 | .reset_resume = usbtouch_reset_resume, |
1d3e2023 | 1747 | .id_table = usbtouch_devices, |
5d9efc59 | 1748 | .supports_autosuspend = 1, |
1d3e2023 DR |
1749 | }; |
1750 | ||
08642e7c | 1751 | module_usb_driver(usbtouch_driver); |
1d3e2023 DR |
1752 | |
1753 | MODULE_AUTHOR(DRIVER_AUTHOR); | |
1754 | MODULE_DESCRIPTION(DRIVER_DESC); | |
1755 | MODULE_LICENSE("GPL"); | |
1756 | ||
1757 | MODULE_ALIAS("touchkitusb"); | |
1758 | MODULE_ALIAS("itmtouch"); | |
1759 | MODULE_ALIAS("mtouchusb"); |