Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * mtouchusb.c -- Driver for Microtouch (Now 3M) USB Touchscreens |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation; either version 2 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 | * |
| 18 | * Based upon original work by Radoslaw Garbacz (usb-support@ite.pl) |
| 19 | * (http://freshmeat.net/projects/3mtouchscreendriver) |
| 20 | * |
| 21 | * History |
| 22 | * |
| 23 | * 0.3 & 0.4 2002 (TEJ) tejohnson@yahoo.com |
| 24 | * Updated to 2.4.18, then 2.4.19 |
| 25 | * Old version still relied on stealing a minor |
| 26 | * |
| 27 | * 0.5 02/26/2004 (TEJ) tejohnson@yahoo.com |
| 28 | * Complete rewrite using Linux Input in 2.6.3 |
| 29 | * Unfortunately no calibration support at this time |
| 30 | * |
| 31 | * 1.4 04/25/2004 (TEJ) tejohnson@yahoo.com |
| 32 | * Changed reset from standard USB dev reset to vendor reset |
| 33 | * Changed data sent to host from compensated to raw coordinates |
| 34 | * Eliminated vendor/product module params |
Steven Cole | 093cf72 | 2005-05-03 19:07:24 -0600 | [diff] [blame] | 35 | * Performed multiple successful tests with an EXII-5010UC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * |
| 37 | * 1.5 02/27/2005 ddstreet@ieee.org |
| 38 | * Added module parameter to select raw or hw-calibrated coordinate reporting |
| 39 | * |
| 40 | *****************************************************************************/ |
| 41 | |
| 42 | #include <linux/config.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/kernel.h> |
| 44 | #include <linux/slab.h> |
| 45 | #include <linux/input.h> |
| 46 | #include <linux/module.h> |
| 47 | #include <linux/init.h> |
| 48 | #include <linux/usb.h> |
Dmitry Torokhov | 16a334c | 2005-06-30 00:49:08 -0500 | [diff] [blame] | 49 | #include <linux/usb_input.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define MTOUCHUSB_MIN_XC 0x0 |
| 52 | #define MTOUCHUSB_MAX_RAW_XC 0x4000 |
| 53 | #define MTOUCHUSB_MAX_CALIB_XC 0xffff |
| 54 | #define MTOUCHUSB_XC_FUZZ 0x0 |
| 55 | #define MTOUCHUSB_XC_FLAT 0x0 |
| 56 | #define MTOUCHUSB_MIN_YC 0x0 |
| 57 | #define MTOUCHUSB_MAX_RAW_YC 0x4000 |
| 58 | #define MTOUCHUSB_MAX_CALIB_YC 0xffff |
| 59 | #define MTOUCHUSB_YC_FUZZ 0x0 |
| 60 | #define MTOUCHUSB_YC_FLAT 0x0 |
| 61 | |
| 62 | #define MTOUCHUSB_ASYNC_REPORT 1 |
| 63 | #define MTOUCHUSB_RESET 7 |
| 64 | #define MTOUCHUSB_REPORT_DATA_SIZE 11 |
| 65 | #define MTOUCHUSB_REQ_CTRLLR_ID 10 |
| 66 | |
| 67 | #define MTOUCHUSB_GET_RAW_XC(data) (data[8]<<8 | data[7]) |
| 68 | #define MTOUCHUSB_GET_CALIB_XC(data) (data[4]<<8 | data[3]) |
| 69 | #define MTOUCHUSB_GET_RAW_YC(data) (data[10]<<8 | data[9]) |
| 70 | #define MTOUCHUSB_GET_CALIB_YC(data) (data[6]<<8 | data[5]) |
| 71 | #define MTOUCHUSB_GET_XC(data) (raw_coordinates ? \ |
| 72 | MTOUCHUSB_GET_RAW_XC(data) : \ |
| 73 | MTOUCHUSB_GET_CALIB_XC(data)) |
| 74 | #define MTOUCHUSB_GET_YC(data) (raw_coordinates ? \ |
| 75 | MTOUCHUSB_GET_RAW_YC(data) : \ |
| 76 | MTOUCHUSB_GET_CALIB_YC(data)) |
| 77 | #define MTOUCHUSB_GET_TOUCHED(data) ((data[2] & 0x40) ? 1:0) |
| 78 | |
| 79 | #define DRIVER_VERSION "v1.5" |
| 80 | #define DRIVER_AUTHOR "Todd E. Johnson, tejohnson@yahoo.com" |
| 81 | #define DRIVER_DESC "3M USB Touchscreen Driver" |
| 82 | #define DRIVER_LICENSE "GPL" |
| 83 | |
| 84 | static int raw_coordinates = 1; |
| 85 | |
| 86 | module_param(raw_coordinates, bool, S_IRUGO | S_IWUSR); |
| 87 | MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)"); |
| 88 | |
| 89 | struct mtouch_usb { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 90 | unsigned char *data; |
| 91 | dma_addr_t data_dma; |
| 92 | struct urb *irq; |
| 93 | struct usb_device *udev; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 94 | struct input_dev *input; |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 95 | char name[128]; |
| 96 | char phys[64]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 99 | static struct usb_device_id mtouchusb_devices[] = { |
| 100 | { USB_DEVICE(0x0596, 0x0001) }, |
| 101 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs) |
| 105 | { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 106 | struct mtouch_usb *mtouch = urb->context; |
| 107 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 109 | switch (urb->status) { |
| 110 | case 0: |
| 111 | /* success */ |
| 112 | break; |
| 113 | case -ETIMEDOUT: |
| 114 | /* this urb is timing out */ |
| 115 | dbg("%s - urb timed out - was the device unplugged?", |
| 116 | __FUNCTION__); |
| 117 | return; |
| 118 | case -ECONNRESET: |
| 119 | case -ENOENT: |
| 120 | case -ESHUTDOWN: |
| 121 | /* this urb is terminated, clean up */ |
| 122 | dbg("%s - urb shutting down with status: %d", |
| 123 | __FUNCTION__, urb->status); |
| 124 | return; |
| 125 | default: |
| 126 | dbg("%s - nonzero urb status received: %d", |
| 127 | __FUNCTION__, urb->status); |
| 128 | goto exit; |
| 129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 131 | input_regs(mtouch->input, regs); |
| 132 | input_report_key(mtouch->input, BTN_TOUCH, |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 133 | MTOUCHUSB_GET_TOUCHED(mtouch->data)); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 134 | input_report_abs(mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data)); |
| 135 | input_report_abs(mtouch->input, ABS_Y, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC) |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 137 | - MTOUCHUSB_GET_YC(mtouch->data)); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 138 | input_sync(mtouch->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | exit: |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 141 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
| 142 | if (retval) |
| 143 | err("%s - usb_submit_urb failed with result: %d", |
| 144 | __FUNCTION__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 147 | static int mtouchusb_open(struct input_dev *input) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 149 | struct mtouch_usb *mtouch = input->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 151 | mtouch->irq->dev = mtouch->udev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Dmitry Torokhov | 65cde54 | 2005-05-29 02:29:38 -0500 | [diff] [blame] | 153 | if (usb_submit_urb(mtouch->irq, GFP_ATOMIC)) |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 154 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 156 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 159 | static void mtouchusb_close(struct input_dev *input) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 161 | struct mtouch_usb *mtouch = input->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Dmitry Torokhov | 65cde54 | 2005-05-29 02:29:38 -0500 | [diff] [blame] | 163 | usb_kill_urb(mtouch->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) |
| 167 | { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 168 | dbg("%s - called", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 170 | mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE, |
| 171 | SLAB_ATOMIC, &mtouch->data_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 173 | if (!mtouch->data) |
| 174 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 176 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) |
| 180 | { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 181 | dbg("%s - called", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 183 | if (mtouch->data) |
| 184 | usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE, |
| 185 | mtouch->data, mtouch->data_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 189 | { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 190 | struct mtouch_usb *mtouch; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 191 | struct input_dev *input_dev; |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 192 | struct usb_host_interface *interface; |
| 193 | struct usb_endpoint_descriptor *endpoint; |
| 194 | struct usb_device *udev = interface_to_usbdev(intf); |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 195 | int nRet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 197 | dbg("%s - called", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 199 | dbg("%s - setting interface", __FUNCTION__); |
| 200 | interface = intf->cur_altsetting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 202 | dbg("%s - setting endpoint", __FUNCTION__); |
| 203 | endpoint = &interface->endpoint[0].desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 205 | mtouch = kzalloc(sizeof(struct mtouch_usb), GFP_KERNEL); |
| 206 | input_dev = input_allocate_device(); |
| 207 | if (!mtouch || !input_dev) { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 208 | err("%s - Out of memory.", __FUNCTION__); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 209 | goto fail1; |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 212 | dbg("%s - allocating buffers", __FUNCTION__); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 213 | if (mtouchusb_alloc_buffers(udev, mtouch)) |
| 214 | goto fail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 216 | mtouch->udev = udev; |
| 217 | mtouch->input = input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | if (udev->manufacturer) |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 220 | strlcpy(mtouch->name, udev->manufacturer, sizeof(mtouch->name)); |
| 221 | |
| 222 | if (udev->product) { |
| 223 | if (udev->manufacturer) |
| 224 | strlcat(mtouch->name, " ", sizeof(mtouch->name)); |
| 225 | strlcat(mtouch->name, udev->product, sizeof(mtouch->name)); |
| 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 228 | if (!strlen(mtouch->name)) |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 229 | snprintf(mtouch->name, sizeof(mtouch->name), |
| 230 | "USB Touchscreen %04x:%04x", |
| 231 | le16_to_cpu(udev->descriptor.idVendor), |
| 232 | le16_to_cpu(udev->descriptor.idProduct)); |
| 233 | |
| 234 | usb_make_path(udev, mtouch->phys, sizeof(mtouch->phys)); |
| 235 | strlcpy(mtouch->phys, "/input0", sizeof(mtouch->phys)); |
| 236 | |
| 237 | input_dev->name = mtouch->name; |
| 238 | input_dev->phys = mtouch->phys; |
| 239 | usb_to_input_id(udev, &input_dev->id); |
| 240 | input_dev->cdev.dev = &intf->dev; |
| 241 | input_dev->private = mtouch; |
| 242 | |
| 243 | input_dev->open = mtouchusb_open; |
| 244 | input_dev->close = mtouchusb_close; |
| 245 | |
| 246 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
| 247 | input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); |
| 248 | input_set_abs_params(input_dev, ABS_X, MTOUCHUSB_MIN_XC, |
| 249 | raw_coordinates ? MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC, |
| 250 | MTOUCHUSB_XC_FUZZ, MTOUCHUSB_XC_FLAT); |
| 251 | input_set_abs_params(input_dev, ABS_Y, MTOUCHUSB_MIN_YC, |
| 252 | raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC, |
| 253 | MTOUCHUSB_YC_FUZZ, MTOUCHUSB_YC_FLAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 255 | nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), |
| 256 | MTOUCHUSB_RESET, |
| 257 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 258 | 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 259 | dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d", |
| 260 | __FUNCTION__, nRet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 262 | dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__); |
| 263 | mtouch->irq = usb_alloc_urb(0, GFP_KERNEL); |
| 264 | if (!mtouch->irq) { |
| 265 | dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 266 | goto fail2; |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 267 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 269 | dbg("%s - usb_fill_int_urb", __FUNCTION__); |
| 270 | usb_fill_int_urb(mtouch->irq, mtouch->udev, |
| 271 | usb_rcvintpipe(mtouch->udev, 0x81), |
| 272 | mtouch->data, MTOUCHUSB_REPORT_DATA_SIZE, |
| 273 | mtouchusb_irq, mtouch, endpoint->bInterval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 275 | dbg("%s - input_register_device", __FUNCTION__); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 276 | input_register_device(mtouch->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 278 | nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), |
| 279 | MTOUCHUSB_ASYNC_REPORT, |
| 280 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 281 | 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 282 | dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", |
| 283 | __FUNCTION__, nRet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 285 | usb_set_intfdata(intf, mtouch); |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 286 | return 0; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 287 | |
| 288 | fail2: mtouchusb_free_buffers(udev, mtouch); |
| 289 | fail1: input_free_device(input_dev); |
| 290 | kfree(mtouch); |
| 291 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static void mtouchusb_disconnect(struct usb_interface *intf) |
| 295 | { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 296 | struct mtouch_usb *mtouch = usb_get_intfdata(intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 298 | dbg("%s - called", __FUNCTION__); |
| 299 | usb_set_intfdata(intf, NULL); |
| 300 | if (mtouch) { |
| 301 | dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__); |
| 302 | usb_kill_urb(mtouch->irq); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 303 | input_unregister_device(mtouch->input); |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 304 | usb_free_urb(mtouch->irq); |
| 305 | mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch); |
| 306 | kfree(mtouch); |
| 307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 310 | MODULE_DEVICE_TABLE(usb, mtouchusb_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | static struct usb_driver mtouchusb_driver = { |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 313 | .name = "mtouchusb", |
| 314 | .probe = mtouchusb_probe, |
| 315 | .disconnect = mtouchusb_disconnect, |
| 316 | .id_table = mtouchusb_devices, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | }; |
| 318 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 319 | static int __init mtouchusb_init(void) |
| 320 | { |
| 321 | dbg("%s - called", __FUNCTION__); |
| 322 | return usb_register(&mtouchusb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 325 | static void __exit mtouchusb_cleanup(void) |
| 326 | { |
| 327 | dbg("%s - called", __FUNCTION__); |
| 328 | usb_deregister(&mtouchusb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | module_init(mtouchusb_init); |
| 332 | module_exit(mtouchusb_cleanup); |
| 333 | |
Dmitry Torokhov | 8baf9ed | 2005-05-29 02:29:08 -0500 | [diff] [blame] | 334 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 335 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | MODULE_LICENSE("GPL"); |