usbtouchscreen.c 42 KB

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