Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB HID support for Linux |
| 3 | * |
| 4 | * Copyright (c) 1999 Andreas Gal |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
Jiri Kosina | b55fd23 | 2007-02-21 19:27:49 +0100 | [diff] [blame] | 7 | * Copyright (c) 2006-2007 Jiri Kosina |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the Free |
| 13 | * Software Foundation; either version 2 of the License, or (at your option) |
| 14 | * any later version. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/list.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/smp_lock.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <asm/unaligned.h> |
| 26 | #include <asm/byteorder.h> |
| 27 | #include <linux/input.h> |
| 28 | #include <linux/wait.h> |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/usb.h> |
| 31 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 32 | #include <linux/hid.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/hiddev.h> |
Jiri Kosina | c080d89 | 2007-01-25 11:43:31 +0100 | [diff] [blame] | 34 | #include <linux/hid-debug.h> |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 35 | #include <linux/hidraw.h> |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 36 | #include "usbhid.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Version Information |
| 40 | */ |
| 41 | |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 42 | #define DRIVER_VERSION "v2.6" |
Jiri Kosina | f142b3a | 2007-04-16 11:29:28 +0200 | [diff] [blame] | 43 | #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik, Jiri Kosina" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define DRIVER_DESC "USB HID core driver" |
| 45 | #define DRIVER_LICENSE "GPL" |
| 46 | |
| 47 | static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick", |
| 48 | "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"}; |
| 49 | /* |
| 50 | * Module parameters. |
| 51 | */ |
| 52 | |
| 53 | static unsigned int hid_mousepoll_interval; |
| 54 | module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644); |
| 55 | MODULE_PARM_DESC(mousepoll, "Polling interval of mice"); |
| 56 | |
Paul Walmsley | 876b927 | 2007-04-19 14:56:12 +0200 | [diff] [blame] | 57 | /* Quirks specified at module load time */ |
| 58 | static char *quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL }; |
| 59 | module_param_array_named(quirks, quirks_param, charp, NULL, 0444); |
| 60 | MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying " |
| 61 | " quirks=vendorID:productID:quirks" |
| 62 | " where vendorID, productID, and quirks are all in" |
| 63 | " 0x-prefixed hex"); |
Jiri Kosina | ea9a4a8 | 2007-06-19 14:09:14 +0200 | [diff] [blame] | 64 | static char *rdesc_quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL }; |
| 65 | module_param_array_named(rdesc_quirks, rdesc_quirks_param, charp, NULL, 0444); |
| 66 | MODULE_PARM_DESC(rdesc_quirks, "Add/modify report descriptor quirks by specifying " |
| 67 | " rdesc_quirks=vendorID:productID:rdesc_quirks" |
| 68 | " where vendorID, productID, and rdesc_quirks are all in" |
| 69 | " 0x-prefixed hex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 71 | * Input submission and I/O error handler. |
| 72 | */ |
| 73 | |
| 74 | static void hid_io_error(struct hid_device *hid); |
| 75 | |
| 76 | /* Start up the input URB */ |
| 77 | static int hid_start_in(struct hid_device *hid) |
| 78 | { |
| 79 | unsigned long flags; |
| 80 | int rc = 0; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 81 | struct usbhid_device *usbhid = hid->driver_data; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 82 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 83 | spin_lock_irqsave(&usbhid->inlock, flags); |
| 84 | if (hid->open > 0 && !test_bit(HID_SUSPENDED, &usbhid->iofl) && |
| 85 | !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) { |
| 86 | rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 87 | if (rc != 0) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 88 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 89 | } |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 90 | spin_unlock_irqrestore(&usbhid->inlock, flags); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 91 | return rc; |
| 92 | } |
| 93 | |
| 94 | /* I/O retry timer routine */ |
| 95 | static void hid_retry_timeout(unsigned long _hid) |
| 96 | { |
| 97 | struct hid_device *hid = (struct hid_device *) _hid; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 98 | struct usbhid_device *usbhid = hid->driver_data; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 99 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 100 | dev_dbg(&usbhid->intf->dev, "retrying intr urb\n"); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 101 | if (hid_start_in(hid)) |
| 102 | hid_io_error(hid); |
| 103 | } |
| 104 | |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 105 | /* Workqueue routine to reset the device or clear a halt */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 106 | static void hid_reset(struct work_struct *work) |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 107 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 108 | struct usbhid_device *usbhid = |
| 109 | container_of(work, struct usbhid_device, reset_work); |
| 110 | struct hid_device *hid = usbhid->hid; |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 111 | int rc_lock, rc = 0; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 112 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 113 | if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) { |
| 114 | dev_dbg(&usbhid->intf->dev, "clear halt\n"); |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 115 | rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 116 | clear_bit(HID_CLEAR_HALT, &usbhid->iofl); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 117 | hid_start_in(hid); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 118 | } |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 119 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 120 | else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) { |
| 121 | dev_dbg(&usbhid->intf->dev, "resetting device\n"); |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 122 | rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 123 | if (rc_lock >= 0) { |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 124 | rc = usb_reset_composite_device(hid_to_usb_dev(hid), usbhid->intf); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 125 | if (rc_lock) |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 126 | usb_unlock_device(hid_to_usb_dev(hid)); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 127 | } |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 128 | clear_bit(HID_RESET_PENDING, &usbhid->iofl); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 129 | } |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 130 | |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 131 | switch (rc) { |
| 132 | case 0: |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 133 | if (!test_bit(HID_IN_RUNNING, &usbhid->iofl)) |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 134 | hid_io_error(hid); |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 135 | break; |
| 136 | default: |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 137 | err_hid("can't reset device, %s-%s/input%d, status %d", |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 138 | hid_to_usb_dev(hid)->bus->bus_name, |
| 139 | hid_to_usb_dev(hid)->devpath, |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 140 | usbhid->ifnum, rc); |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 141 | /* FALLTHROUGH */ |
| 142 | case -EHOSTUNREACH: |
| 143 | case -ENODEV: |
| 144 | case -EINTR: |
| 145 | break; |
| 146 | } |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* Main I/O error handler */ |
| 150 | static void hid_io_error(struct hid_device *hid) |
| 151 | { |
| 152 | unsigned long flags; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 153 | struct usbhid_device *usbhid = hid->driver_data; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 154 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 155 | spin_lock_irqsave(&usbhid->inlock, flags); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 156 | |
| 157 | /* Stop when disconnected */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 158 | if (usb_get_intfdata(usbhid->intf) == NULL) |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 159 | goto done; |
| 160 | |
Alan Stern | 5e2a55f | 2007-03-20 19:03:31 +0100 | [diff] [blame] | 161 | /* If it has been a while since the last error, we'll assume |
| 162 | * this a brand new error and reset the retry timeout. */ |
| 163 | if (time_after(jiffies, usbhid->stop_retry + HZ/2)) |
| 164 | usbhid->retry_delay = 0; |
| 165 | |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 166 | /* When an error occurs, retry at increasing intervals */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 167 | if (usbhid->retry_delay == 0) { |
| 168 | usbhid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */ |
| 169 | usbhid->stop_retry = jiffies + msecs_to_jiffies(1000); |
| 170 | } else if (usbhid->retry_delay < 100) |
| 171 | usbhid->retry_delay *= 2; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 172 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 173 | if (time_after(jiffies, usbhid->stop_retry)) { |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 174 | |
| 175 | /* Retries failed, so do a port reset */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 176 | if (!test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) { |
| 177 | schedule_work(&usbhid->reset_work); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 178 | goto done; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 182 | mod_timer(&usbhid->io_retry, |
| 183 | jiffies + msecs_to_jiffies(usbhid->retry_delay)); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 184 | done: |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 185 | spin_unlock_irqrestore(&usbhid->inlock, flags); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | * Input interrupt completion handler. |
| 190 | */ |
| 191 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 192 | static void hid_irq_in(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | struct hid_device *hid = urb->context; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 195 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | int status; |
| 197 | |
| 198 | switch (urb->status) { |
| 199 | case 0: /* success */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 200 | usbhid->retry_delay = 0; |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 201 | hid_input_report(urb->context, HID_INPUT_REPORT, |
| 202 | urb->transfer_buffer, |
| 203 | urb->actual_length, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | break; |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 205 | case -EPIPE: /* stall */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 206 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
| 207 | set_bit(HID_CLEAR_HALT, &usbhid->iofl); |
| 208 | schedule_work(&usbhid->reset_work); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 209 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | case -ECONNRESET: /* unlink */ |
| 211 | case -ENOENT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | case -ESHUTDOWN: /* unplug */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 213 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | return; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 215 | case -EILSEQ: /* protocol error or unplug */ |
| 216 | case -EPROTO: /* protocol error or unplug */ |
Pete Zaitcev | 38e2bfc | 2006-09-18 22:49:02 -0700 | [diff] [blame] | 217 | case -ETIME: /* protocol error or unplug */ |
| 218 | case -ETIMEDOUT: /* Should never happen, but... */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 219 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 220 | hid_io_error(hid); |
| 221 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | default: /* error */ |
| 223 | warn("input irq status %d received", urb->status); |
| 224 | } |
| 225 | |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 226 | status = usb_submit_urb(urb, GFP_ATOMIC); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 227 | if (status) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 228 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 229 | if (status != -EPERM) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 230 | err_hid("can't resubmit intr, %s-%s/input%d, status %d", |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 231 | hid_to_usb_dev(hid)->bus->bus_name, |
| 232 | hid_to_usb_dev(hid)->devpath, |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 233 | usbhid->ifnum, status); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 234 | hid_io_error(hid); |
| 235 | } |
| 236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | static int hid_submit_out(struct hid_device *hid) |
| 240 | { |
| 241 | struct hid_report *report; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 242 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 244 | report = usbhid->out[usbhid->outtail]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 246 | hid_output_report(report, usbhid->outbuf); |
| 247 | usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 248 | usbhid->urbout->dev = hid_to_usb_dev(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 250 | dbg_hid("submitting out urb\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 252 | if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 253 | err_hid("usb_submit_urb(out) failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return -1; |
| 255 | } |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static int hid_submit_ctrl(struct hid_device *hid) |
| 261 | { |
| 262 | struct hid_report *report; |
| 263 | unsigned char dir; |
| 264 | int len; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 265 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 267 | report = usbhid->ctrl[usbhid->ctrltail].report; |
| 268 | dir = usbhid->ctrl[usbhid->ctrltail].dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); |
| 271 | if (dir == USB_DIR_OUT) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 272 | hid_output_report(report, usbhid->ctrlbuf); |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 273 | usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 274 | usbhid->urbctrl->transfer_buffer_length = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } else { |
| 276 | int maxpacket, padlen; |
| 277 | |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 278 | usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0); |
| 279 | maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if (maxpacket > 0) { |
Julia Lawall | 92c4a1b | 2008-02-15 13:53:11 +0100 | [diff] [blame^] | 281 | padlen = DIV_ROUND_UP(len, maxpacket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | padlen *= maxpacket; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 283 | if (padlen > usbhid->bufsize) |
| 284 | padlen = usbhid->bufsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } else |
| 286 | padlen = 0; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 287 | usbhid->urbctrl->transfer_buffer_length = padlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 289 | usbhid->urbctrl->dev = hid_to_usb_dev(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 291 | usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; |
| 292 | usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT; |
| 293 | usbhid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id); |
| 294 | usbhid->cr->wIndex = cpu_to_le16(usbhid->ifnum); |
| 295 | usbhid->cr->wLength = cpu_to_le16(len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 297 | dbg_hid("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u\n", |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 298 | usbhid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report", |
| 299 | usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 301 | if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 302 | err_hid("usb_submit_urb(ctrl) failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | return -1; |
| 304 | } |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * Output interrupt completion handler. |
| 311 | */ |
| 312 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 313 | static void hid_irq_out(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
| 315 | struct hid_device *hid = urb->context; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 316 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | unsigned long flags; |
| 318 | int unplug = 0; |
| 319 | |
| 320 | switch (urb->status) { |
| 321 | case 0: /* success */ |
Vojtech Pavlik | c4786ca | 2005-09-05 00:13:03 -0500 | [diff] [blame] | 322 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | case -ESHUTDOWN: /* unplug */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | unplug = 1; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 325 | case -EILSEQ: /* protocol error or unplug */ |
| 326 | case -EPROTO: /* protocol error or unplug */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | case -ECONNRESET: /* unlink */ |
| 328 | case -ENOENT: |
| 329 | break; |
| 330 | default: /* error */ |
| 331 | warn("output irq status %d received", urb->status); |
| 332 | } |
| 333 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 334 | spin_lock_irqsave(&usbhid->outlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | if (unplug) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 337 | usbhid->outtail = usbhid->outhead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | else |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 339 | usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 341 | if (usbhid->outhead != usbhid->outtail) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (hid_submit_out(hid)) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 343 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | wake_up(&hid->wait); |
| 345 | } |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 346 | spin_unlock_irqrestore(&usbhid->outlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 350 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); |
| 351 | spin_unlock_irqrestore(&usbhid->outlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | wake_up(&hid->wait); |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * Control pipe completion handler. |
| 357 | */ |
| 358 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 359 | static void hid_ctrl(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
| 361 | struct hid_device *hid = urb->context; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 362 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | unsigned long flags; |
| 364 | int unplug = 0; |
| 365 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 366 | spin_lock_irqsave(&usbhid->ctrllock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | switch (urb->status) { |
| 369 | case 0: /* success */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 370 | if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN) |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 371 | hid_input_report(urb->context, usbhid->ctrl[usbhid->ctrltail].report->type, |
| 372 | urb->transfer_buffer, urb->actual_length, 0); |
Vojtech Pavlik | c4786ca | 2005-09-05 00:13:03 -0500 | [diff] [blame] | 373 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | case -ESHUTDOWN: /* unplug */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | unplug = 1; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 376 | case -EILSEQ: /* protocol error or unplug */ |
| 377 | case -EPROTO: /* protocol error or unplug */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | case -ECONNRESET: /* unlink */ |
| 379 | case -ENOENT: |
| 380 | case -EPIPE: /* report not available */ |
| 381 | break; |
| 382 | default: /* error */ |
| 383 | warn("ctrl urb status %d received", urb->status); |
| 384 | } |
| 385 | |
| 386 | if (unplug) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 387 | usbhid->ctrltail = usbhid->ctrlhead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | else |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 389 | usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 391 | if (usbhid->ctrlhead != usbhid->ctrltail) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if (hid_submit_ctrl(hid)) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 393 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | wake_up(&hid->wait); |
| 395 | } |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 396 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | return; |
| 398 | } |
| 399 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 400 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); |
| 401 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | wake_up(&hid->wait); |
| 403 | } |
| 404 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 405 | void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
| 407 | int head; |
| 408 | unsigned long flags; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 409 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) |
| 412 | return; |
| 413 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 414 | if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 416 | spin_lock_irqsave(&usbhid->outlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 418 | if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) { |
| 419 | spin_unlock_irqrestore(&usbhid->outlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | warn("output queue full"); |
| 421 | return; |
| 422 | } |
| 423 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 424 | usbhid->out[usbhid->outhead] = report; |
| 425 | usbhid->outhead = head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 427 | if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | if (hid_submit_out(hid)) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 429 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 431 | spin_unlock_irqrestore(&usbhid->outlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | return; |
| 433 | } |
| 434 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 435 | spin_lock_irqsave(&usbhid->ctrllock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 437 | if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) { |
| 438 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | warn("control queue full"); |
| 440 | return; |
| 441 | } |
| 442 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 443 | usbhid->ctrl[usbhid->ctrlhead].report = report; |
| 444 | usbhid->ctrl[usbhid->ctrlhead].dir = dir; |
| 445 | usbhid->ctrlhead = head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 447 | if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | if (hid_submit_ctrl(hid)) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 449 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 451 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 454 | static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 455 | { |
Dmitry Torokhov | e071298 | 2007-05-09 10:17:31 +0200 | [diff] [blame] | 456 | struct hid_device *hid = input_get_drvdata(dev); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 457 | struct hid_field *field; |
| 458 | int offset; |
| 459 | |
| 460 | if (type == EV_FF) |
| 461 | return input_ff_event(dev, type, code, value); |
| 462 | |
| 463 | if (type != EV_LED) |
| 464 | return -1; |
| 465 | |
| 466 | if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) { |
| 467 | warn("event field not found"); |
| 468 | return -1; |
| 469 | } |
| 470 | |
| 471 | hid_set_field(field, offset, value); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 472 | usbhid_submit_report(hid, field->report, USB_DIR_OUT); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 473 | |
| 474 | return 0; |
| 475 | } |
| 476 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 477 | int usbhid_wait_io(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 479 | struct usbhid_device *usbhid = hid->driver_data; |
| 480 | |
| 481 | if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) && |
| 482 | !test_bit(HID_OUT_RUNNING, &usbhid->iofl)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | 10*HZ)) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 484 | dbg_hid("timeout waiting for ctrl or out queue to clear\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | return -1; |
| 486 | } |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
Vojtech Pavlik | 854561b | 2005-05-29 02:28:00 -0500 | [diff] [blame] | 491 | static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle) |
| 492 | { |
Vojtech Pavlik | 71387bd | 2005-05-29 02:28:14 -0500 | [diff] [blame] | 493 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
Vojtech Pavlik | 854561b | 2005-05-29 02:28:00 -0500 | [diff] [blame] | 494 | HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report, |
| 495 | ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 496 | } |
| 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | static int hid_get_class_descriptor(struct usb_device *dev, int ifnum, |
| 499 | unsigned char type, void *buf, int size) |
| 500 | { |
| 501 | int result, retries = 4; |
| 502 | |
Jiri Kosina | 43c7bf0 | 2007-01-26 12:58:24 +0100 | [diff] [blame] | 503 | memset(buf, 0, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | do { |
| 506 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 507 | USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN, |
| 508 | (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT); |
| 509 | retries--; |
| 510 | } while (result < size && retries); |
| 511 | return result; |
| 512 | } |
| 513 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 514 | int usbhid_open(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 516 | struct usbhid_device *usbhid = hid->driver_data; |
| 517 | int res; |
| 518 | |
| 519 | if (!hid->open++) { |
| 520 | res = usb_autopm_get_interface(usbhid->intf); |
| 521 | if (res < 0) { |
| 522 | hid->open--; |
| 523 | return -EIO; |
| 524 | } |
| 525 | } |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 526 | if (hid_start_in(hid)) |
| 527 | hid_io_error(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | return 0; |
| 529 | } |
| 530 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 531 | void usbhid_close(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 533 | struct usbhid_device *usbhid = hid->driver_data; |
| 534 | |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 535 | if (!--hid->open) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 536 | usb_kill_urb(usbhid->urbin); |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 537 | usb_autopm_put_interface(usbhid->intf); |
| 538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /* |
| 542 | * Initialize all reports |
| 543 | */ |
| 544 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 545 | void usbhid_init_reports(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | { |
| 547 | struct hid_report *report; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 548 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | int err, ret; |
| 550 | |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 551 | list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 552 | usbhid_submit_report(hid, report, USB_DIR_IN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 555 | usbhid_submit_report(hid, report, USB_DIR_IN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | err = 0; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 558 | ret = usbhid_wait_io(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | while (ret) { |
| 560 | err |= ret; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 561 | if (test_bit(HID_CTRL_RUNNING, &usbhid->iofl)) |
| 562 | usb_kill_urb(usbhid->urbctrl); |
| 563 | if (test_bit(HID_OUT_RUNNING, &usbhid->iofl)) |
| 564 | usb_kill_urb(usbhid->urbout); |
| 565 | ret = usbhid_wait_io(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | if (err) |
Olaf Hering | de289fd | 2006-01-06 12:45:28 +0100 | [diff] [blame] | 569 | warn("timeout initializing reports"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 572 | /* |
Pete Zaitcev | 713c8aa | 2007-04-06 14:33:18 +0200 | [diff] [blame] | 573 | * Reset LEDs which BIOS might have left on. For now, just NumLock (0x01). |
| 574 | */ |
| 575 | static int hid_find_field_early(struct hid_device *hid, unsigned int page, |
| 576 | unsigned int hid_code, struct hid_field **pfield) |
| 577 | { |
| 578 | struct hid_report *report; |
| 579 | struct hid_field *field; |
| 580 | struct hid_usage *usage; |
| 581 | int i, j; |
| 582 | |
| 583 | list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) { |
| 584 | for (i = 0; i < report->maxfield; i++) { |
| 585 | field = report->field[i]; |
| 586 | for (j = 0; j < field->maxusage; j++) { |
| 587 | usage = &field->usage[j]; |
| 588 | if ((usage->hid & HID_USAGE_PAGE) == page && |
| 589 | (usage->hid & 0xFFFF) == hid_code) { |
| 590 | *pfield = field; |
| 591 | return j; |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | return -1; |
| 597 | } |
| 598 | |
| 599 | static void usbhid_set_leds(struct hid_device *hid) |
| 600 | { |
| 601 | struct hid_field *field; |
| 602 | int offset; |
| 603 | |
| 604 | if ((offset = hid_find_field_early(hid, HID_UP_LED, 0x01, &field)) != -1) { |
| 605 | hid_set_field(field, offset, 0); |
| 606 | usbhid_submit_report(hid, field->report, USB_DIR_OUT); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | /* |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 611 | * Traverse the supplied list of reports and find the longest |
| 612 | */ |
| 613 | static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max) |
| 614 | { |
| 615 | struct hid_report *report; |
| 616 | int size; |
| 617 | |
| 618 | list_for_each_entry(report, &hid->report_enum[type].report_list, list) { |
| 619 | size = ((report->size - 1) >> 3) + 1; |
| 620 | if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered) |
| 621 | size++; |
| 622 | if (*max < size) |
| 623 | *max = size; |
| 624 | } |
| 625 | } |
| 626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) |
| 628 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 629 | struct usbhid_device *usbhid = hid->driver_data; |
| 630 | |
| 631 | if (!(usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->inbuf_dma))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | return -1; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 633 | if (!(usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->outbuf_dma))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return -1; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 635 | if (!(usbhid->cr = usb_buffer_alloc(dev, sizeof(*(usbhid->cr)), GFP_ATOMIC, &usbhid->cr_dma))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | return -1; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 637 | if (!(usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->ctrlbuf_dma))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | return -1; |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
Jiri Kosina | efc493f | 2007-05-14 09:54:30 +0200 | [diff] [blame] | 643 | static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count) |
| 644 | { |
| 645 | struct usbhid_device *usbhid = hid->driver_data; |
| 646 | struct usb_device *dev = hid_to_usb_dev(hid); |
| 647 | struct usb_interface *intf = usbhid->intf; |
| 648 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 649 | int ret; |
| 650 | |
| 651 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 652 | HID_REQ_SET_REPORT, |
| 653 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 654 | cpu_to_le16(((HID_OUTPUT_REPORT + 1) << 8) | *buf), |
| 655 | interface->desc.bInterfaceNumber, buf + 1, count - 1, |
| 656 | USB_CTRL_SET_TIMEOUT); |
| 657 | |
| 658 | /* count also the report id */ |
| 659 | if (ret > 0) |
| 660 | ret++; |
| 661 | |
| 662 | return ret; |
| 663 | } |
| 664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) |
| 666 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 667 | struct usbhid_device *usbhid = hid->driver_data; |
| 668 | |
Dmitry Torokhov | 6675c5b | 2007-05-03 01:04:52 -0400 | [diff] [blame] | 669 | usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma); |
| 670 | usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma); |
| 671 | usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma); |
| 672 | usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Vojtech Pavlik | 940824b | 2006-01-14 00:25:39 -0500 | [diff] [blame] | 675 | /* |
Geoff Levand | 4a1a4d8 | 2007-01-15 20:11:52 -0800 | [diff] [blame] | 676 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
| 677 | * to "operational". Without this, the ps3 controller will not report any |
| 678 | * events. |
| 679 | */ |
| 680 | static void hid_fixup_sony_ps3_controller(struct usb_device *dev, int ifnum) |
| 681 | { |
| 682 | int result; |
| 683 | char *buf = kmalloc(18, GFP_KERNEL); |
| 684 | |
| 685 | if (!buf) |
| 686 | return; |
| 687 | |
| 688 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 689 | HID_REQ_GET_REPORT, |
| 690 | USB_DIR_IN | USB_TYPE_CLASS | |
| 691 | USB_RECIP_INTERFACE, |
| 692 | (3 << 8) | 0xf2, ifnum, buf, 17, |
| 693 | USB_CTRL_GET_TIMEOUT); |
| 694 | |
| 695 | if (result < 0) |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 696 | err_hid("%s failed: %d\n", __func__, result); |
Geoff Levand | 4a1a4d8 | 2007-01-15 20:11:52 -0800 | [diff] [blame] | 697 | |
| 698 | kfree(buf); |
| 699 | } |
| 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | static struct hid_device *usb_hid_configure(struct usb_interface *intf) |
| 702 | { |
| 703 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 704 | struct usb_device *dev = interface_to_usbdev (intf); |
| 705 | struct hid_descriptor *hdesc; |
| 706 | struct hid_device *hid; |
Paul Walmsley | 2eb5dc3 | 2007-04-19 13:27:04 +0200 | [diff] [blame] | 707 | u32 quirks = 0; |
Paul Walmsley | 4cbe7d2 | 2007-03-20 19:23:16 +0100 | [diff] [blame] | 708 | unsigned rsize = 0; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 709 | char *rdesc; |
| 710 | int n, len, insize = 0; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 711 | struct usbhid_device *usbhid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Paul Walmsley | 2eb5dc3 | 2007-04-19 13:27:04 +0200 | [diff] [blame] | 713 | quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor), |
| 714 | le16_to_cpu(dev->descriptor.idProduct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Alan Stern | 0f28b55 | 2006-05-15 14:49:04 -0400 | [diff] [blame] | 716 | /* Many keyboards and mice don't like to be polled for reports, |
| 717 | * so we will always set the HID_QUIRK_NOGET flag for them. */ |
| 718 | if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) { |
| 719 | if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD || |
| 720 | interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE) |
| 721 | quirks |= HID_QUIRK_NOGET; |
| 722 | } |
| 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | if (quirks & HID_QUIRK_IGNORE) |
| 725 | return NULL; |
| 726 | |
Soeren Sonnenburg | a417a21 | 2007-02-05 10:06:01 +0100 | [diff] [blame] | 727 | if ((quirks & HID_QUIRK_IGNORE_MOUSE) && |
| 728 | (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)) |
| 729 | return NULL; |
| 730 | |
| 731 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 732 | if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && |
| 733 | (!interface->desc.bNumEndpoints || |
| 734 | usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 735 | dbg_hid("class descriptor not present\n"); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 736 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | for (n = 0; n < hdesc->bNumDescriptors; n++) |
| 740 | if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT) |
| 741 | rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength); |
| 742 | |
| 743 | if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 744 | dbg_hid("weird size of report descriptor (%u)\n", rsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | return NULL; |
| 746 | } |
| 747 | |
| 748 | if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 749 | dbg_hid("couldn't allocate rdesc memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | return NULL; |
| 751 | } |
| 752 | |
Vojtech Pavlik | 854561b | 2005-05-29 02:28:00 -0500 | [diff] [blame] | 753 | hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0); |
| 754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 756 | dbg_hid("reading report descriptor failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | kfree(rdesc); |
| 758 | return NULL; |
| 759 | } |
| 760 | |
Jiri Kosina | ea9a4a8 | 2007-06-19 14:09:14 +0200 | [diff] [blame] | 761 | usbhid_fixup_report_descriptor(le16_to_cpu(dev->descriptor.idVendor), |
| 762 | le16_to_cpu(dev->descriptor.idProduct), rdesc, |
| 763 | rsize, rdesc_quirks_param); |
Jiri Kosina | 66da876 | 2007-05-02 11:55:42 +0200 | [diff] [blame] | 764 | |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 765 | dbg_hid("report descriptor (size %u, read %d) = ", rsize, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | for (n = 0; n < rsize; n++) |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 767 | dbg_hid_line(" %02x", (unsigned char) rdesc[n]); |
| 768 | dbg_hid_line("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| 770 | if (!(hid = hid_parse_report(rdesc, n))) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 771 | dbg_hid("parsing report descriptor failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | kfree(rdesc); |
| 773 | return NULL; |
| 774 | } |
| 775 | |
| 776 | kfree(rdesc); |
| 777 | hid->quirks = quirks; |
| 778 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 779 | if (!(usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL))) |
Jesper Juhl | de1a7b0 | 2007-07-30 15:15:26 +0200 | [diff] [blame] | 780 | goto fail_no_usbhid; |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 781 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 782 | hid->driver_data = usbhid; |
| 783 | usbhid->hid = hid; |
| 784 | |
| 785 | usbhid->bufsize = HID_MIN_BUFFER_SIZE; |
| 786 | hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize); |
| 787 | hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize); |
| 788 | hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize); |
| 789 | |
| 790 | if (usbhid->bufsize > HID_MAX_BUFFER_SIZE) |
| 791 | usbhid->bufsize = HID_MAX_BUFFER_SIZE; |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 792 | |
| 793 | hid_find_max_report(hid, HID_INPUT_REPORT, &insize); |
| 794 | |
| 795 | if (insize > HID_MAX_BUFFER_SIZE) |
| 796 | insize = HID_MAX_BUFFER_SIZE; |
| 797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | if (hid_alloc_buffers(dev, hid)) { |
| 799 | hid_free_buffers(dev, hid); |
| 800 | goto fail; |
| 801 | } |
| 802 | |
| 803 | for (n = 0; n < interface->desc.bNumEndpoints; n++) { |
| 804 | |
| 805 | struct usb_endpoint_descriptor *endpoint; |
| 806 | int pipe; |
| 807 | int interval; |
| 808 | |
| 809 | endpoint = &interface->endpoint[n].desc; |
| 810 | if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */ |
| 811 | continue; |
| 812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | interval = endpoint->bInterval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | /* Change the polling interval of mice. */ |
| 816 | if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) |
| 817 | interval = hid_mousepoll_interval; |
Dmitry Torokhov | 05f091a | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 818 | |
Luiz Fernando N. Capitulino | 0f12aa0 | 2006-10-26 13:02:51 -0300 | [diff] [blame] | 819 | if (usb_endpoint_dir_in(endpoint)) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 820 | if (usbhid->urbin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | continue; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 822 | if (!(usbhid->urbin = usb_alloc_urb(0, GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | goto fail; |
| 824 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 825 | usb_fill_int_urb(usbhid->urbin, dev, pipe, usbhid->inbuf, insize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | hid_irq_in, hid, interval); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 827 | usbhid->urbin->transfer_dma = usbhid->inbuf_dma; |
| 828 | usbhid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | } else { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 830 | if (usbhid->urbout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | continue; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 832 | if (!(usbhid->urbout = usb_alloc_urb(0, GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | goto fail; |
| 834 | pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 835 | usb_fill_int_urb(usbhid->urbout, dev, pipe, usbhid->outbuf, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | hid_irq_out, hid, interval); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 837 | usbhid->urbout->transfer_dma = usbhid->outbuf_dma; |
| 838 | usbhid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 842 | if (!usbhid->urbin) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 843 | err_hid("couldn't find an input interrupt endpoint"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | goto fail; |
| 845 | } |
| 846 | |
| 847 | init_waitqueue_head(&hid->wait); |
| 848 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 849 | INIT_WORK(&usbhid->reset_work, hid_reset); |
| 850 | setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 851 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 852 | spin_lock_init(&usbhid->inlock); |
| 853 | spin_lock_init(&usbhid->outlock); |
| 854 | spin_lock_init(&usbhid->ctrllock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
| 856 | hid->version = le16_to_cpu(hdesc->bcdHID); |
| 857 | hid->country = hdesc->bCountryCode; |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 858 | hid->dev = &intf->dev; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 859 | usbhid->intf = intf; |
| 860 | usbhid->ifnum = interface->desc.bInterfaceNumber; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
| 862 | hid->name[0] = 0; |
| 863 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 864 | if (dev->manufacturer) |
| 865 | strlcpy(hid->name, dev->manufacturer, sizeof(hid->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 867 | if (dev->product) { |
| 868 | if (dev->manufacturer) |
| 869 | strlcat(hid->name, " ", sizeof(hid->name)); |
| 870 | strlcat(hid->name, dev->product, sizeof(hid->name)); |
| 871 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 873 | if (!strlen(hid->name)) |
| 874 | snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x", |
| 875 | le16_to_cpu(dev->descriptor.idVendor), |
| 876 | le16_to_cpu(dev->descriptor.idProduct)); |
| 877 | |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 878 | hid->bus = BUS_USB; |
Julien BLACHE | 9fa2ad5 | 2007-02-11 18:20:25 +0100 | [diff] [blame] | 879 | hid->vendor = le16_to_cpu(dev->descriptor.idVendor); |
| 880 | hid->product = le16_to_cpu(dev->descriptor.idProduct); |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 881 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 882 | usb_make_path(dev, hid->phys, sizeof(hid->phys)); |
| 883 | strlcat(hid->phys, "/input", sizeof(hid->phys)); |
| 884 | len = strlen(hid->phys); |
| 885 | if (len < sizeof(hid->phys) - 1) |
| 886 | snprintf(hid->phys + len, sizeof(hid->phys) - len, |
| 887 | "%d", intf->altsetting[0].desc.bInterfaceNumber); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
| 889 | if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) |
| 890 | hid->uniq[0] = 0; |
| 891 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 892 | usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); |
| 893 | if (!usbhid->urbctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | goto fail; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 895 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 896 | usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr, |
| 897 | usbhid->ctrlbuf, 1, hid_ctrl, hid); |
| 898 | usbhid->urbctrl->setup_dma = usbhid->cr_dma; |
| 899 | usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma; |
| 900 | usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 901 | hid->hidinput_input_event = usb_hidinput_input_event; |
Jiri Kosina | 7c37914 | 2007-01-24 11:54:19 +0100 | [diff] [blame] | 902 | hid->hid_open = usbhid_open; |
| 903 | hid->hid_close = usbhid_close; |
Jiri Kosina | aa938f7 | 2006-12-08 18:41:10 +0100 | [diff] [blame] | 904 | #ifdef CONFIG_USB_HIDDEV |
| 905 | hid->hiddev_hid_event = hiddev_hid_event; |
Jiri Kosina | aa8de2f | 2006-12-08 18:41:17 +0100 | [diff] [blame] | 906 | hid->hiddev_report_event = hiddev_report_event; |
Jiri Kosina | aa938f7 | 2006-12-08 18:41:10 +0100 | [diff] [blame] | 907 | #endif |
Jiri Kosina | efc493f | 2007-05-14 09:54:30 +0200 | [diff] [blame] | 908 | hid->hid_output_raw_report = usbhid_output_raw_report; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | return hid; |
| 910 | |
| 911 | fail: |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 912 | usb_free_urb(usbhid->urbin); |
| 913 | usb_free_urb(usbhid->urbout); |
| 914 | usb_free_urb(usbhid->urbctrl); |
Jiri Kosina | 22f675f | 2007-08-01 12:32:27 +0200 | [diff] [blame] | 915 | hid_free_buffers(dev, hid); |
Jiri Kosina | cda5ecf | 2007-07-30 15:40:06 +0200 | [diff] [blame] | 916 | kfree(usbhid); |
Jesper Juhl | de1a7b0 | 2007-07-30 15:15:26 +0200 | [diff] [blame] | 917 | fail_no_usbhid: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | hid_free_device(hid); |
| 919 | |
| 920 | return NULL; |
| 921 | } |
| 922 | |
| 923 | static void hid_disconnect(struct usb_interface *intf) |
| 924 | { |
| 925 | struct hid_device *hid = usb_get_intfdata (intf); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 926 | struct usbhid_device *usbhid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
| 928 | if (!hid) |
| 929 | return; |
| 930 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 931 | usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 933 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ |
| 934 | usb_set_intfdata(intf, NULL); |
| 935 | spin_unlock_irq(&usbhid->inlock); |
| 936 | usb_kill_urb(usbhid->urbin); |
| 937 | usb_kill_urb(usbhid->urbout); |
| 938 | usb_kill_urb(usbhid->urbctrl); |
| 939 | |
| 940 | del_timer_sync(&usbhid->io_retry); |
Alan Stern | 2fa45a4 | 2007-05-30 11:11:12 -0400 | [diff] [blame] | 941 | cancel_work_sync(&usbhid->reset_work); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | if (hid->claimed & HID_CLAIMED_INPUT) |
| 944 | hidinput_disconnect(hid); |
| 945 | if (hid->claimed & HID_CLAIMED_HIDDEV) |
| 946 | hiddev_disconnect(hid); |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 947 | if (hid->claimed & HID_CLAIMED_HIDRAW) |
| 948 | hidraw_disconnect(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 950 | usb_free_urb(usbhid->urbin); |
| 951 | usb_free_urb(usbhid->urbctrl); |
| 952 | usb_free_urb(usbhid->urbout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 954 | hid_free_buffers(hid_to_usb_dev(hid), hid); |
Jiri Kosina | 22f675f | 2007-08-01 12:32:27 +0200 | [diff] [blame] | 955 | kfree(usbhid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | hid_free_device(hid); |
| 957 | } |
| 958 | |
| 959 | static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 960 | { |
| 961 | struct hid_device *hid; |
| 962 | char path[64]; |
| 963 | int i; |
| 964 | char *c; |
| 965 | |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 966 | dbg_hid("HID probe called for ifnum %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | intf->altsetting->desc.bInterfaceNumber); |
| 968 | |
| 969 | if (!(hid = usb_hid_configure(intf))) |
Stelian Pop | 479f6ea | 2005-06-22 17:53:28 +0200 | [diff] [blame] | 970 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 972 | usbhid_init_reports(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | hid_dump_device(hid); |
Pete Zaitcev | 713c8aa | 2007-04-06 14:33:18 +0200 | [diff] [blame] | 974 | if (hid->quirks & HID_QUIRK_RESET_LEDS) |
| 975 | usbhid_set_leds(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
| 977 | if (!hidinput_connect(hid)) |
| 978 | hid->claimed |= HID_CLAIMED_INPUT; |
| 979 | if (!hiddev_connect(hid)) |
| 980 | hid->claimed |= HID_CLAIMED_HIDDEV; |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 981 | if (!hidraw_connect(hid)) |
| 982 | hid->claimed |= HID_CLAIMED_HIDRAW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | usb_set_intfdata(intf, hid); |
| 985 | |
| 986 | if (!hid->claimed) { |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 987 | printk ("HID device claimed by neither input, hiddev nor hidraw\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | hid_disconnect(intf); |
Stelian Pop | 479f6ea | 2005-06-22 17:53:28 +0200 | [diff] [blame] | 989 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Anssi Hannula | c414606 | 2007-01-11 16:51:16 +0200 | [diff] [blame] | 992 | if ((hid->claimed & HID_CLAIMED_INPUT)) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 993 | hid_ff_init(hid); |
| 994 | |
Geoff Levand | 4a1a4d8 | 2007-01-15 20:11:52 -0800 | [diff] [blame] | 995 | if (hid->quirks & HID_QUIRK_SONY_PS3_CONTROLLER) |
| 996 | hid_fixup_sony_ps3_controller(interface_to_usbdev(intf), |
| 997 | intf->cur_altsetting->desc.bInterfaceNumber); |
| 998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | printk(KERN_INFO); |
| 1000 | |
| 1001 | if (hid->claimed & HID_CLAIMED_INPUT) |
| 1002 | printk("input"); |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 1003 | if ((hid->claimed & HID_CLAIMED_INPUT) && ((hid->claimed & HID_CLAIMED_HIDDEV) || |
| 1004 | hid->claimed & HID_CLAIMED_HIDRAW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | printk(","); |
| 1006 | if (hid->claimed & HID_CLAIMED_HIDDEV) |
| 1007 | printk("hiddev%d", hid->minor); |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 1008 | if ((hid->claimed & HID_CLAIMED_INPUT) && (hid->claimed & HID_CLAIMED_HIDDEV) && |
| 1009 | (hid->claimed & HID_CLAIMED_HIDRAW)) |
| 1010 | printk(","); |
| 1011 | if (hid->claimed & HID_CLAIMED_HIDRAW) |
| 1012 | printk("hidraw%d", ((struct hidraw*)hid->hidraw)->minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
| 1014 | c = "Device"; |
| 1015 | for (i = 0; i < hid->maxcollection; i++) { |
| 1016 | if (hid->collection[i].type == HID_COLLECTION_APPLICATION && |
| 1017 | (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK && |
| 1018 | (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) { |
| 1019 | c = hid_types[hid->collection[i].usage & 0xffff]; |
| 1020 | break; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | usb_make_path(interface_to_usbdev(intf), path, 63); |
| 1025 | |
| 1026 | printk(": USB HID v%x.%02x %s [%s] on %s\n", |
| 1027 | hid->version >> 8, hid->version & 0xff, c, hid->name, path); |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 1032 | static int hid_suspend(struct usb_interface *intf, pm_message_t message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | { |
| 1034 | struct hid_device *hid = usb_get_intfdata (intf); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1035 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1037 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ |
| 1038 | set_bit(HID_SUSPENDED, &usbhid->iofl); |
| 1039 | spin_unlock_irq(&usbhid->inlock); |
| 1040 | del_timer(&usbhid->io_retry); |
| 1041 | usb_kill_urb(usbhid->urbin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | dev_dbg(&intf->dev, "suspend\n"); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | static int hid_resume(struct usb_interface *intf) |
| 1047 | { |
| 1048 | struct hid_device *hid = usb_get_intfdata (intf); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1049 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | int status; |
| 1051 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1052 | clear_bit(HID_SUSPENDED, &usbhid->iofl); |
| 1053 | usbhid->retry_delay = 0; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 1054 | status = hid_start_in(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | dev_dbg(&intf->dev, "resume status %d\n", status); |
| 1056 | return status; |
| 1057 | } |
| 1058 | |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1059 | /* Treat USB reset pretty much the same as suspend/resume */ |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1060 | static int hid_pre_reset(struct usb_interface *intf) |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1061 | { |
| 1062 | /* FIXME: What if the interface is already suspended? */ |
| 1063 | hid_suspend(intf, PMSG_ON); |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1064 | return 0; |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1067 | /* Same routine used for post_reset and reset_resume */ |
| 1068 | static int hid_post_reset(struct usb_interface *intf) |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1069 | { |
| 1070 | struct usb_device *dev = interface_to_usbdev (intf); |
| 1071 | |
| 1072 | hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0); |
| 1073 | /* FIXME: Any more reinitialization needed? */ |
| 1074 | |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1075 | return hid_resume(intf); |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1076 | } |
| 1077 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | static struct usb_device_id hid_usb_ids [] = { |
| 1079 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, |
| 1080 | .bInterfaceClass = USB_INTERFACE_CLASS_HID }, |
| 1081 | { } /* Terminating entry */ |
| 1082 | }; |
| 1083 | |
| 1084 | MODULE_DEVICE_TABLE (usb, hid_usb_ids); |
| 1085 | |
| 1086 | static struct usb_driver hid_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | .name = "usbhid", |
| 1088 | .probe = hid_probe, |
| 1089 | .disconnect = hid_disconnect, |
| 1090 | .suspend = hid_suspend, |
| 1091 | .resume = hid_resume, |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1092 | .reset_resume = hid_post_reset, |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1093 | .pre_reset = hid_pre_reset, |
| 1094 | .post_reset = hid_post_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | .id_table = hid_usb_ids, |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 1096 | .supports_autosuspend = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | }; |
| 1098 | |
| 1099 | static int __init hid_init(void) |
| 1100 | { |
| 1101 | int retval; |
Paul Walmsley | 876b927 | 2007-04-19 14:56:12 +0200 | [diff] [blame] | 1102 | retval = usbhid_quirks_init(quirks_param); |
| 1103 | if (retval) |
| 1104 | goto usbhid_quirks_init_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | retval = hiddev_init(); |
| 1106 | if (retval) |
| 1107 | goto hiddev_init_fail; |
| 1108 | retval = usb_register(&hid_driver); |
| 1109 | if (retval) |
| 1110 | goto usb_register_fail; |
| 1111 | info(DRIVER_VERSION ":" DRIVER_DESC); |
| 1112 | |
| 1113 | return 0; |
| 1114 | usb_register_fail: |
| 1115 | hiddev_exit(); |
| 1116 | hiddev_init_fail: |
Paul Walmsley | 876b927 | 2007-04-19 14:56:12 +0200 | [diff] [blame] | 1117 | usbhid_quirks_exit(); |
| 1118 | usbhid_quirks_init_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | return retval; |
| 1120 | } |
| 1121 | |
| 1122 | static void __exit hid_exit(void) |
| 1123 | { |
| 1124 | usb_deregister(&hid_driver); |
| 1125 | hiddev_exit(); |
Paul Walmsley | 876b927 | 2007-04-19 14:56:12 +0200 | [diff] [blame] | 1126 | usbhid_quirks_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | module_init(hid_init); |
| 1130 | module_exit(hid_exit); |
| 1131 | |
| 1132 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1133 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1134 | MODULE_LICENSE(DRIVER_LICENSE); |