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