usbtouchscreen.c 40 KB

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