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