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 | efc7ce1 | 2008-10-17 15:01:15 +0200 | [diff] [blame] | 7 | * Copyright (c) 2006-2008 Jiri Kosina |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 8 | * Copyright (c) 2007-2008 Oliver Neukum |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the Free |
| 14 | * Software Foundation; either version 2 of the License, or (at your option) |
| 15 | * any later version. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/list.h> |
| 23 | #include <linux/mm.h> |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/smp_lock.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <asm/unaligned.h> |
| 28 | #include <asm/byteorder.h> |
| 29 | #include <linux/input.h> |
| 30 | #include <linux/wait.h> |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 31 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/usb.h> |
| 34 | |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 35 | #include <linux/hid.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/hiddev.h> |
Jiri Kosina | c080d89 | 2007-01-25 11:43:31 +0100 | [diff] [blame] | 37 | #include <linux/hid-debug.h> |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 38 | #include <linux/hidraw.h> |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 39 | #include "usbhid.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * Version Information |
| 43 | */ |
| 44 | |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 45 | #define DRIVER_VERSION "v2.6" |
Jiri Kosina | f142b3a4 | 2007-04-16 11:29:28 +0200 | [diff] [blame] | 46 | #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik, Jiri Kosina" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define DRIVER_DESC "USB HID core driver" |
| 48 | #define DRIVER_LICENSE "GPL" |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* |
| 51 | * Module parameters. |
| 52 | */ |
| 53 | |
| 54 | static unsigned int hid_mousepoll_interval; |
| 55 | module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644); |
| 56 | MODULE_PARM_DESC(mousepoll, "Polling interval of mice"); |
| 57 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 58 | static unsigned int ignoreled; |
| 59 | module_param_named(ignoreled, ignoreled, uint, 0644); |
| 60 | MODULE_PARM_DESC(ignoreled, "Autosuspend with active leds"); |
| 61 | |
Paul Walmsley | 876b927 | 2007-04-19 14:56:12 +0200 | [diff] [blame] | 62 | /* Quirks specified at module load time */ |
| 63 | static char *quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL }; |
| 64 | module_param_array_named(quirks, quirks_param, charp, NULL, 0444); |
| 65 | MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying " |
| 66 | " quirks=vendorID:productID:quirks" |
| 67 | " where vendorID, productID, and quirks are all in" |
| 68 | " 0x-prefixed hex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /* |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 70 | * Input submission and I/O error handler. |
| 71 | */ |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 72 | static DEFINE_MUTEX(hid_open_mut); |
| 73 | static struct workqueue_struct *resumption_waker; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 74 | |
| 75 | static void hid_io_error(struct hid_device *hid); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 76 | static int hid_submit_out(struct hid_device *hid); |
| 77 | static int hid_submit_ctrl(struct hid_device *hid); |
| 78 | static void hid_cancel_delayed_stuff(struct usbhid_device *usbhid); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 79 | |
| 80 | /* Start up the input URB */ |
| 81 | static int hid_start_in(struct hid_device *hid) |
| 82 | { |
| 83 | unsigned long flags; |
| 84 | int rc = 0; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 85 | struct usbhid_device *usbhid = hid->driver_data; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 86 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 87 | spin_lock_irqsave(&usbhid->lock, flags); |
| 88 | if (hid->open > 0 && |
Oliver Neukum | 69626f2 | 2008-03-31 16:27:30 +0200 | [diff] [blame] | 89 | !test_bit(HID_DISCONNECTED, &usbhid->iofl) && |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 90 | !test_bit(HID_REPORTED_IDLE, &usbhid->iofl) && |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 91 | !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) { |
| 92 | rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 93 | if (rc != 0) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 94 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 95 | } |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 96 | spin_unlock_irqrestore(&usbhid->lock, flags); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 97 | return rc; |
| 98 | } |
| 99 | |
| 100 | /* I/O retry timer routine */ |
| 101 | static void hid_retry_timeout(unsigned long _hid) |
| 102 | { |
| 103 | struct hid_device *hid = (struct hid_device *) _hid; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 104 | struct usbhid_device *usbhid = hid->driver_data; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 105 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 106 | dev_dbg(&usbhid->intf->dev, "retrying intr urb\n"); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 107 | if (hid_start_in(hid)) |
| 108 | hid_io_error(hid); |
| 109 | } |
| 110 | |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 111 | /* Workqueue routine to reset the device or clear a halt */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 112 | static void hid_reset(struct work_struct *work) |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 113 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 114 | struct usbhid_device *usbhid = |
| 115 | container_of(work, struct usbhid_device, reset_work); |
| 116 | struct hid_device *hid = usbhid->hid; |
Alan Stern | 011b15d | 2008-11-04 11:29:27 -0500 | [diff] [blame] | 117 | int rc = 0; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 118 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 119 | if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) { |
| 120 | dev_dbg(&usbhid->intf->dev, "clear halt\n"); |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 121 | rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 122 | clear_bit(HID_CLEAR_HALT, &usbhid->iofl); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 123 | hid_start_in(hid); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 124 | } |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 125 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 126 | else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) { |
| 127 | dev_dbg(&usbhid->intf->dev, "resetting device\n"); |
Alan Stern | 011b15d | 2008-11-04 11:29:27 -0500 | [diff] [blame] | 128 | rc = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf); |
| 129 | if (rc == 0) { |
Ming Lei | 742120c | 2008-06-18 22:00:29 +0800 | [diff] [blame] | 130 | rc = usb_reset_device(hid_to_usb_dev(hid)); |
Alan Stern | 011b15d | 2008-11-04 11:29:27 -0500 | [diff] [blame] | 131 | usb_unlock_device(hid_to_usb_dev(hid)); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 132 | } |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 133 | clear_bit(HID_RESET_PENDING, &usbhid->iofl); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 134 | } |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 135 | |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 136 | switch (rc) { |
| 137 | case 0: |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 138 | if (!test_bit(HID_IN_RUNNING, &usbhid->iofl)) |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 139 | hid_io_error(hid); |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 140 | break; |
| 141 | default: |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 142 | err_hid("can't reset device, %s-%s/input%d, status %d", |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 143 | hid_to_usb_dev(hid)->bus->bus_name, |
| 144 | hid_to_usb_dev(hid)->devpath, |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 145 | usbhid->ifnum, rc); |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 146 | /* FALLTHROUGH */ |
| 147 | case -EHOSTUNREACH: |
| 148 | case -ENODEV: |
| 149 | case -EINTR: |
| 150 | break; |
| 151 | } |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* Main I/O error handler */ |
| 155 | static void hid_io_error(struct hid_device *hid) |
| 156 | { |
| 157 | unsigned long flags; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 158 | struct usbhid_device *usbhid = hid->driver_data; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 159 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 160 | spin_lock_irqsave(&usbhid->lock, flags); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 161 | |
| 162 | /* Stop when disconnected */ |
Oliver Neukum | 69626f2 | 2008-03-31 16:27:30 +0200 | [diff] [blame] | 163 | if (test_bit(HID_DISCONNECTED, &usbhid->iofl)) |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 164 | goto done; |
| 165 | |
Alan Stern | 5e2a55f | 2007-03-20 19:03:31 +0100 | [diff] [blame] | 166 | /* If it has been a while since the last error, we'll assume |
| 167 | * this a brand new error and reset the retry timeout. */ |
| 168 | if (time_after(jiffies, usbhid->stop_retry + HZ/2)) |
| 169 | usbhid->retry_delay = 0; |
| 170 | |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 171 | /* When an error occurs, retry at increasing intervals */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 172 | if (usbhid->retry_delay == 0) { |
| 173 | usbhid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */ |
| 174 | usbhid->stop_retry = jiffies + msecs_to_jiffies(1000); |
| 175 | } else if (usbhid->retry_delay < 100) |
| 176 | usbhid->retry_delay *= 2; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 177 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 178 | if (time_after(jiffies, usbhid->stop_retry)) { |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 179 | |
| 180 | /* Retries failed, so do a port reset */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 181 | if (!test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) { |
| 182 | schedule_work(&usbhid->reset_work); |
Alan Stern | 6d8fc4d | 2006-10-18 12:35:24 -0400 | [diff] [blame] | 183 | goto done; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 187 | mod_timer(&usbhid->io_retry, |
| 188 | jiffies + msecs_to_jiffies(usbhid->retry_delay)); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 189 | done: |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 190 | spin_unlock_irqrestore(&usbhid->lock, flags); |
| 191 | } |
| 192 | |
| 193 | static void usbhid_mark_busy(struct usbhid_device *usbhid) |
| 194 | { |
| 195 | struct usb_interface *intf = usbhid->intf; |
| 196 | |
| 197 | usb_mark_last_busy(interface_to_usbdev(intf)); |
| 198 | } |
| 199 | |
| 200 | static int usbhid_restart_out_queue(struct usbhid_device *usbhid) |
| 201 | { |
| 202 | struct hid_device *hid = usb_get_intfdata(usbhid->intf); |
| 203 | int kicked; |
| 204 | |
| 205 | if (!hid) |
| 206 | return 0; |
| 207 | |
| 208 | if ((kicked = (usbhid->outhead != usbhid->outtail))) { |
| 209 | dbg("Kicking head %d tail %d", usbhid->outhead, usbhid->outtail); |
| 210 | if (hid_submit_out(hid)) { |
| 211 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); |
| 212 | wake_up(&usbhid->wait); |
| 213 | } |
| 214 | } |
| 215 | return kicked; |
| 216 | } |
| 217 | |
| 218 | static int usbhid_restart_ctrl_queue(struct usbhid_device *usbhid) |
| 219 | { |
| 220 | struct hid_device *hid = usb_get_intfdata(usbhid->intf); |
| 221 | int kicked; |
| 222 | |
| 223 | WARN_ON(hid == NULL); |
| 224 | if (!hid) |
| 225 | return 0; |
| 226 | |
| 227 | if ((kicked = (usbhid->ctrlhead != usbhid->ctrltail))) { |
| 228 | dbg("Kicking head %d tail %d", usbhid->ctrlhead, usbhid->ctrltail); |
| 229 | if (hid_submit_ctrl(hid)) { |
| 230 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); |
| 231 | wake_up(&usbhid->wait); |
| 232 | } |
| 233 | } |
| 234 | return kicked; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | * Input interrupt completion handler. |
| 239 | */ |
| 240 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 241 | static void hid_irq_in(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | struct hid_device *hid = urb->context; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 244 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | int status; |
| 246 | |
| 247 | switch (urb->status) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 248 | case 0: /* success */ |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 249 | usbhid_mark_busy(usbhid); |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 250 | usbhid->retry_delay = 0; |
| 251 | hid_input_report(urb->context, HID_INPUT_REPORT, |
| 252 | urb->transfer_buffer, |
| 253 | urb->actual_length, 1); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 254 | /* |
| 255 | * autosuspend refused while keys are pressed |
| 256 | * because most keyboards don't wake up when |
| 257 | * a key is released |
| 258 | */ |
| 259 | if (hid_check_keys_pressed(hid)) |
| 260 | set_bit(HID_KEYS_PRESSED, &usbhid->iofl); |
| 261 | else |
| 262 | clear_bit(HID_KEYS_PRESSED, &usbhid->iofl); |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 263 | break; |
| 264 | case -EPIPE: /* stall */ |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 265 | usbhid_mark_busy(usbhid); |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 266 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
| 267 | set_bit(HID_CLEAR_HALT, &usbhid->iofl); |
| 268 | schedule_work(&usbhid->reset_work); |
| 269 | return; |
| 270 | case -ECONNRESET: /* unlink */ |
| 271 | case -ENOENT: |
| 272 | case -ESHUTDOWN: /* unplug */ |
| 273 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
| 274 | return; |
| 275 | case -EILSEQ: /* protocol error or unplug */ |
| 276 | case -EPROTO: /* protocol error or unplug */ |
| 277 | case -ETIME: /* protocol error or unplug */ |
| 278 | case -ETIMEDOUT: /* Should never happen, but... */ |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 279 | usbhid_mark_busy(usbhid); |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 280 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
| 281 | hid_io_error(hid); |
| 282 | return; |
| 283 | default: /* error */ |
From: Greg Kroah-Hartman | 7d89fe1 | 2008-10-12 00:25:51 +0200 | [diff] [blame] | 284 | dev_warn(&urb->dev->dev, "input irq status %d " |
| 285 | "received\n", urb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 288 | status = usb_submit_urb(urb, GFP_ATOMIC); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 289 | if (status) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 290 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 291 | if (status != -EPERM) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 292 | err_hid("can't resubmit intr, %s-%s/input%d, status %d", |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 293 | hid_to_usb_dev(hid)->bus->bus_name, |
| 294 | hid_to_usb_dev(hid)->devpath, |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 295 | usbhid->ifnum, status); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 296 | hid_io_error(hid); |
| 297 | } |
| 298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | static int hid_submit_out(struct hid_device *hid) |
| 302 | { |
| 303 | struct hid_report *report; |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 304 | char *raw_report; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 305 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 307 | report = usbhid->out[usbhid->outtail].report; |
| 308 | raw_report = usbhid->out[usbhid->outtail].raw_report; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 310 | if (!test_bit(HID_REPORTED_IDLE, &usbhid->iofl)) { |
| 311 | usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); |
| 312 | usbhid->urbout->dev = hid_to_usb_dev(hid); |
| 313 | memcpy(usbhid->outbuf, raw_report, usbhid->urbout->transfer_buffer_length); |
| 314 | kfree(raw_report); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 316 | dbg_hid("submitting out urb\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 318 | if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) { |
| 319 | err_hid("usb_submit_urb(out) failed"); |
| 320 | return -1; |
| 321 | } |
| 322 | } else { |
| 323 | /* |
| 324 | * queue work to wake up the device. |
| 325 | * as the work queue is freezeable, this is safe |
| 326 | * with respect to STD and STR |
| 327 | */ |
| 328 | queue_work(resumption_waker, &usbhid->restart_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static int hid_submit_ctrl(struct hid_device *hid) |
| 335 | { |
| 336 | struct hid_report *report; |
| 337 | unsigned char dir; |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 338 | char *raw_report; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | int len; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 340 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 342 | report = usbhid->ctrl[usbhid->ctrltail].report; |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 343 | raw_report = usbhid->ctrl[usbhid->ctrltail].raw_report; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 344 | dir = usbhid->ctrl[usbhid->ctrltail].dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 346 | if (!test_bit(HID_REPORTED_IDLE, &usbhid->iofl)) { |
| 347 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); |
| 348 | if (dir == USB_DIR_OUT) { |
| 349 | usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); |
| 350 | usbhid->urbctrl->transfer_buffer_length = len; |
| 351 | memcpy(usbhid->ctrlbuf, raw_report, len); |
| 352 | kfree(raw_report); |
| 353 | } else { |
| 354 | int maxpacket, padlen; |
| 355 | |
| 356 | usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0); |
| 357 | maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0); |
| 358 | if (maxpacket > 0) { |
| 359 | padlen = DIV_ROUND_UP(len, maxpacket); |
| 360 | padlen *= maxpacket; |
| 361 | if (padlen > usbhid->bufsize) |
| 362 | padlen = usbhid->bufsize; |
| 363 | } else |
| 364 | padlen = 0; |
| 365 | usbhid->urbctrl->transfer_buffer_length = padlen; |
| 366 | } |
| 367 | usbhid->urbctrl->dev = hid_to_usb_dev(hid); |
| 368 | |
| 369 | usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; |
| 370 | usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT; |
| 371 | usbhid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id); |
| 372 | usbhid->cr->wIndex = cpu_to_le16(usbhid->ifnum); |
| 373 | usbhid->cr->wLength = cpu_to_le16(len); |
| 374 | |
| 375 | dbg_hid("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u\n", |
| 376 | usbhid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report", |
| 377 | usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength); |
| 378 | |
| 379 | if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) { |
| 380 | err_hid("usb_submit_urb(ctrl) failed"); |
| 381 | return -1; |
| 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } else { |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 384 | /* |
| 385 | * queue work to wake up the device. |
| 386 | * as the work queue is freezeable, this is safe |
| 387 | * with respect to STD and STR |
| 388 | */ |
| 389 | queue_work(resumption_waker, &usbhid->restart_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | /* |
| 396 | * Output interrupt completion handler. |
| 397 | */ |
| 398 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 399 | static void hid_irq_out(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
| 401 | struct hid_device *hid = urb->context; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 402 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | unsigned long flags; |
| 404 | int unplug = 0; |
| 405 | |
| 406 | switch (urb->status) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 407 | case 0: /* success */ |
| 408 | break; |
| 409 | case -ESHUTDOWN: /* unplug */ |
| 410 | unplug = 1; |
| 411 | case -EILSEQ: /* protocol error or unplug */ |
| 412 | case -EPROTO: /* protocol error or unplug */ |
| 413 | case -ECONNRESET: /* unlink */ |
| 414 | case -ENOENT: |
| 415 | break; |
| 416 | default: /* error */ |
From: Greg Kroah-Hartman | 7d89fe1 | 2008-10-12 00:25:51 +0200 | [diff] [blame] | 417 | dev_warn(&urb->dev->dev, "output irq status %d " |
| 418 | "received\n", urb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 421 | spin_lock_irqsave(&usbhid->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | if (unplug) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 424 | usbhid->outtail = usbhid->outhead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | else |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 426 | usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 428 | if (usbhid->outhead != usbhid->outtail) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | if (hid_submit_out(hid)) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 430 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); |
Jiri Slaby | 1d1bdd2 | 2008-03-19 21:55:04 +0100 | [diff] [blame] | 431 | wake_up(&usbhid->wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 433 | spin_unlock_irqrestore(&usbhid->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return; |
| 435 | } |
| 436 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 437 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 438 | spin_unlock_irqrestore(&usbhid->lock, flags); |
Jiri Slaby | 1d1bdd2 | 2008-03-19 21:55:04 +0100 | [diff] [blame] | 439 | wake_up(&usbhid->wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /* |
| 443 | * Control pipe completion handler. |
| 444 | */ |
| 445 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 446 | static void hid_ctrl(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
| 448 | struct hid_device *hid = urb->context; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 449 | struct usbhid_device *usbhid = hid->driver_data; |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 450 | int unplug = 0, status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 452 | spin_lock(&usbhid->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 454 | switch (status) { |
Jiri Slaby | 880d29f | 2008-06-18 23:55:41 +0200 | [diff] [blame] | 455 | case 0: /* success */ |
| 456 | if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN) |
| 457 | hid_input_report(urb->context, |
| 458 | usbhid->ctrl[usbhid->ctrltail].report->type, |
| 459 | urb->transfer_buffer, urb->actual_length, 0); |
| 460 | break; |
| 461 | case -ESHUTDOWN: /* unplug */ |
| 462 | unplug = 1; |
| 463 | case -EILSEQ: /* protocol error or unplug */ |
| 464 | case -EPROTO: /* protocol error or unplug */ |
| 465 | case -ECONNRESET: /* unlink */ |
| 466 | case -ENOENT: |
| 467 | case -EPIPE: /* report not available */ |
| 468 | break; |
| 469 | default: /* error */ |
From: Greg Kroah-Hartman | 7d89fe1 | 2008-10-12 00:25:51 +0200 | [diff] [blame] | 470 | dev_warn(&urb->dev->dev, "ctrl urb status %d " |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 471 | "received\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | if (unplug) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 475 | usbhid->ctrltail = usbhid->ctrlhead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | else |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 477 | usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1); |
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 | if (usbhid->ctrlhead != usbhid->ctrltail) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | if (hid_submit_ctrl(hid)) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 481 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); |
Jiri Slaby | 1d1bdd2 | 2008-03-19 21:55:04 +0100 | [diff] [blame] | 482 | wake_up(&usbhid->wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 484 | spin_unlock(&usbhid->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | return; |
| 486 | } |
| 487 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 488 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 489 | spin_unlock(&usbhid->lock); |
Jiri Slaby | 1d1bdd2 | 2008-03-19 21:55:04 +0100 | [diff] [blame] | 490 | wake_up(&usbhid->wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 493 | 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] | 494 | { |
| 495 | int head; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 496 | struct usbhid_device *usbhid = hid->driver_data; |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 497 | int len = ((report->size - 1) >> 3) + 1 + (report->id > 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) |
| 500 | return; |
| 501 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 502 | if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 503 | if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) { |
From: Greg Kroah-Hartman | 7d89fe1 | 2008-10-12 00:25:51 +0200 | [diff] [blame] | 504 | dev_warn(&hid->dev, "output queue full\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | return; |
| 506 | } |
| 507 | |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 508 | usbhid->out[usbhid->outhead].raw_report = kmalloc(len, GFP_ATOMIC); |
| 509 | if (!usbhid->out[usbhid->outhead].raw_report) { |
Greg Kroah-Hartman | 46fcaec | 2008-10-15 11:30:07 -0700 | [diff] [blame] | 510 | dev_warn(&hid->dev, "output queueing failed\n"); |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 511 | return; |
| 512 | } |
| 513 | hid_output_report(report, usbhid->out[usbhid->outhead].raw_report); |
| 514 | usbhid->out[usbhid->outhead].report = report; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 515 | usbhid->outhead = head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 517 | if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (hid_submit_out(hid)) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 519 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | return; |
| 521 | } |
| 522 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 523 | if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) { |
From: Greg Kroah-Hartman | 7d89fe1 | 2008-10-12 00:25:51 +0200 | [diff] [blame] | 524 | dev_warn(&hid->dev, "control queue full\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return; |
| 526 | } |
| 527 | |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 528 | if (dir == USB_DIR_OUT) { |
| 529 | usbhid->ctrl[usbhid->ctrlhead].raw_report = kmalloc(len, GFP_ATOMIC); |
| 530 | if (!usbhid->ctrl[usbhid->ctrlhead].raw_report) { |
Greg Kroah-Hartman | 46fcaec | 2008-10-15 11:30:07 -0700 | [diff] [blame] | 531 | dev_warn(&hid->dev, "control queueing failed\n"); |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 532 | return; |
| 533 | } |
| 534 | hid_output_report(report, usbhid->ctrl[usbhid->ctrlhead].raw_report); |
| 535 | } |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 536 | usbhid->ctrl[usbhid->ctrlhead].report = report; |
| 537 | usbhid->ctrl[usbhid->ctrlhead].dir = dir; |
| 538 | usbhid->ctrlhead = head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 540 | if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | if (hid_submit_ctrl(hid)) |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 542 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 543 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 545 | void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir) |
| 546 | { |
| 547 | struct usbhid_device *usbhid = hid->driver_data; |
| 548 | unsigned long flags; |
| 549 | |
| 550 | spin_lock_irqsave(&usbhid->lock, flags); |
| 551 | __usbhid_submit_report(hid, report, dir); |
| 552 | spin_unlock_irqrestore(&usbhid->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
Jiri Slaby | 606bd0a | 2008-07-04 23:06:45 +0200 | [diff] [blame] | 554 | EXPORT_SYMBOL_GPL(usbhid_submit_report); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Jiri Kosina | 229695e | 2006-12-08 18:40:53 +0100 | [diff] [blame] | 556 | 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] | 557 | { |
Dmitry Torokhov | e071298 | 2007-05-09 10:17:31 +0200 | [diff] [blame] | 558 | struct hid_device *hid = input_get_drvdata(dev); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 559 | struct usbhid_device *usbhid = hid->driver_data; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 560 | struct hid_field *field; |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 561 | unsigned long flags; |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 562 | int offset; |
| 563 | |
| 564 | if (type == EV_FF) |
| 565 | return input_ff_event(dev, type, code, value); |
| 566 | |
| 567 | if (type != EV_LED) |
| 568 | return -1; |
| 569 | |
| 570 | if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) { |
From: Greg Kroah-Hartman | 7d89fe1 | 2008-10-12 00:25:51 +0200 | [diff] [blame] | 571 | dev_warn(&dev->dev, "event field not found\n"); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 572 | return -1; |
| 573 | } |
| 574 | |
| 575 | hid_set_field(field, offset, value); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 576 | if (value) { |
| 577 | spin_lock_irqsave(&usbhid->lock, flags); |
| 578 | usbhid->ledcount++; |
| 579 | spin_unlock_irqrestore(&usbhid->lock, flags); |
| 580 | } else { |
| 581 | spin_lock_irqsave(&usbhid->lock, flags); |
| 582 | usbhid->ledcount--; |
| 583 | spin_unlock_irqrestore(&usbhid->lock, flags); |
| 584 | } |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 585 | usbhid_submit_report(hid, field->report, USB_DIR_OUT); |
Jiri Kosina | dde5845 | 2006-12-08 18:40:44 +0100 | [diff] [blame] | 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 590 | int usbhid_wait_io(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 592 | struct usbhid_device *usbhid = hid->driver_data; |
| 593 | |
Jiri Slaby | 1d1bdd2 | 2008-03-19 21:55:04 +0100 | [diff] [blame] | 594 | if (!wait_event_timeout(usbhid->wait, |
| 595 | (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) && |
| 596 | !test_bit(HID_OUT_RUNNING, &usbhid->iofl)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | 10*HZ)) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 598 | dbg_hid("timeout waiting for ctrl or out queue to clear\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | return -1; |
| 600 | } |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
Vojtech Pavlik | 854561b | 2005-05-29 02:28:00 -0500 | [diff] [blame] | 605 | static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle) |
| 606 | { |
Vojtech Pavlik | 71387bd | 2005-05-29 02:28:14 -0500 | [diff] [blame] | 607 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
Vojtech Pavlik | 854561b | 2005-05-29 02:28:00 -0500 | [diff] [blame] | 608 | HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report, |
| 609 | ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 610 | } |
| 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | static int hid_get_class_descriptor(struct usb_device *dev, int ifnum, |
| 613 | unsigned char type, void *buf, int size) |
| 614 | { |
| 615 | int result, retries = 4; |
| 616 | |
Jiri Kosina | 43c7bf0 | 2007-01-26 12:58:24 +0100 | [diff] [blame] | 617 | memset(buf, 0, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | do { |
| 620 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 621 | USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN, |
| 622 | (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT); |
| 623 | retries--; |
| 624 | } while (result < size && retries); |
| 625 | return result; |
| 626 | } |
| 627 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 628 | int usbhid_open(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | { |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 630 | struct usbhid_device *usbhid = hid->driver_data; |
| 631 | int res; |
| 632 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 633 | mutex_lock(&hid_open_mut); |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 634 | if (!hid->open++) { |
| 635 | res = usb_autopm_get_interface(usbhid->intf); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 636 | /* the device must be awake to reliable request remote wakeup */ |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 637 | if (res < 0) { |
| 638 | hid->open--; |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 639 | mutex_unlock(&hid_open_mut); |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 640 | return -EIO; |
| 641 | } |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 642 | usbhid->intf->needs_remote_wakeup = 1; |
| 643 | if (hid_start_in(hid)) |
| 644 | hid_io_error(hid); |
| 645 | |
| 646 | usb_autopm_put_interface(usbhid->intf); |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 647 | } |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 648 | mutex_unlock(&hid_open_mut); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return 0; |
| 650 | } |
| 651 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 652 | void usbhid_close(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 654 | struct usbhid_device *usbhid = hid->driver_data; |
| 655 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 656 | mutex_lock(&hid_open_mut); |
| 657 | |
| 658 | /* protecting hid->open to make sure we don't restart |
| 659 | * data acquistion due to a resumption we no longer |
| 660 | * care about |
| 661 | */ |
| 662 | spin_lock_irq(&usbhid->lock); |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 663 | if (!--hid->open) { |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 664 | spin_unlock_irq(&usbhid->lock); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 665 | usb_kill_urb(usbhid->urbin); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 666 | flush_scheduled_work(); |
| 667 | usbhid->intf->needs_remote_wakeup = 0; |
| 668 | } else { |
| 669 | spin_unlock_irq(&usbhid->lock); |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 670 | } |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 671 | mutex_unlock(&hid_open_mut); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /* |
| 675 | * Initialize all reports |
| 676 | */ |
| 677 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 678 | void usbhid_init_reports(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
| 680 | struct hid_report *report; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 681 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | int err, ret; |
| 683 | |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 684 | 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] | 685 | usbhid_submit_report(hid, report, USB_DIR_IN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | 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] | 688 | usbhid_submit_report(hid, report, USB_DIR_IN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | err = 0; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 691 | ret = usbhid_wait_io(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | while (ret) { |
| 693 | err |= ret; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 694 | if (test_bit(HID_CTRL_RUNNING, &usbhid->iofl)) |
| 695 | usb_kill_urb(usbhid->urbctrl); |
| 696 | if (test_bit(HID_OUT_RUNNING, &usbhid->iofl)) |
| 697 | usb_kill_urb(usbhid->urbout); |
| 698 | ret = usbhid_wait_io(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | if (err) |
From: Greg Kroah-Hartman | 7d89fe1 | 2008-10-12 00:25:51 +0200 | [diff] [blame] | 702 | dev_warn(&hid->dev, "timeout initializing reports\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 705 | /* |
Pete Zaitcev | 713c8aa | 2007-04-06 14:33:18 +0200 | [diff] [blame] | 706 | * Reset LEDs which BIOS might have left on. For now, just NumLock (0x01). |
| 707 | */ |
| 708 | static int hid_find_field_early(struct hid_device *hid, unsigned int page, |
| 709 | unsigned int hid_code, struct hid_field **pfield) |
| 710 | { |
| 711 | struct hid_report *report; |
| 712 | struct hid_field *field; |
| 713 | struct hid_usage *usage; |
| 714 | int i, j; |
| 715 | |
| 716 | list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) { |
| 717 | for (i = 0; i < report->maxfield; i++) { |
| 718 | field = report->field[i]; |
| 719 | for (j = 0; j < field->maxusage; j++) { |
| 720 | usage = &field->usage[j]; |
| 721 | if ((usage->hid & HID_USAGE_PAGE) == page && |
| 722 | (usage->hid & 0xFFFF) == hid_code) { |
| 723 | *pfield = field; |
| 724 | return j; |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | return -1; |
| 730 | } |
| 731 | |
Jiri Slaby | 6edfa8d | 2008-06-27 20:41:02 +0200 | [diff] [blame] | 732 | void usbhid_set_leds(struct hid_device *hid) |
Pete Zaitcev | 713c8aa | 2007-04-06 14:33:18 +0200 | [diff] [blame] | 733 | { |
| 734 | struct hid_field *field; |
| 735 | int offset; |
| 736 | |
| 737 | if ((offset = hid_find_field_early(hid, HID_UP_LED, 0x01, &field)) != -1) { |
| 738 | hid_set_field(field, offset, 0); |
| 739 | usbhid_submit_report(hid, field->report, USB_DIR_OUT); |
| 740 | } |
| 741 | } |
Jiri Slaby | 6edfa8d | 2008-06-27 20:41:02 +0200 | [diff] [blame] | 742 | EXPORT_SYMBOL_GPL(usbhid_set_leds); |
Pete Zaitcev | 713c8aa | 2007-04-06 14:33:18 +0200 | [diff] [blame] | 743 | |
| 744 | /* |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 745 | * Traverse the supplied list of reports and find the longest |
| 746 | */ |
Jiri Slaby | 282bfd4 | 2008-03-28 17:06:41 +0100 | [diff] [blame] | 747 | static void hid_find_max_report(struct hid_device *hid, unsigned int type, |
| 748 | unsigned int *max) |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 749 | { |
| 750 | struct hid_report *report; |
Jiri Slaby | 282bfd4 | 2008-03-28 17:06:41 +0100 | [diff] [blame] | 751 | unsigned int size; |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 752 | |
| 753 | list_for_each_entry(report, &hid->report_enum[type].report_list, list) { |
Jiri Kosina | efc7ce1 | 2008-10-17 15:01:15 +0200 | [diff] [blame] | 754 | size = ((report->size - 1) >> 3) + 1 + hid->report_enum[type].numbered; |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 755 | if (*max < size) |
| 756 | *max = size; |
| 757 | } |
| 758 | } |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) |
| 761 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 762 | struct usbhid_device *usbhid = hid->driver_data; |
| 763 | |
Jiri Slaby | 898089d | 2008-11-24 16:20:06 +0100 | [diff] [blame] | 764 | usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL, |
| 765 | &usbhid->inbuf_dma); |
| 766 | usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL, |
| 767 | &usbhid->outbuf_dma); |
| 768 | usbhid->cr = usb_buffer_alloc(dev, sizeof(*usbhid->cr), GFP_KERNEL, |
| 769 | &usbhid->cr_dma); |
| 770 | usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL, |
| 771 | &usbhid->ctrlbuf_dma); |
| 772 | if (!usbhid->inbuf || !usbhid->outbuf || !usbhid->cr || |
| 773 | !usbhid->ctrlbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | return -1; |
| 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
Jiri Kosina | efc493f | 2007-05-14 09:54:30 +0200 | [diff] [blame] | 779 | static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count) |
| 780 | { |
| 781 | struct usbhid_device *usbhid = hid->driver_data; |
| 782 | struct usb_device *dev = hid_to_usb_dev(hid); |
| 783 | struct usb_interface *intf = usbhid->intf; |
| 784 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 785 | int ret; |
| 786 | |
| 787 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 788 | HID_REQ_SET_REPORT, |
| 789 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
Al Viro | 01d7b36 | 2008-04-28 07:00:05 +0100 | [diff] [blame] | 790 | ((HID_OUTPUT_REPORT + 1) << 8) | *buf, |
Jiri Kosina | efc493f | 2007-05-14 09:54:30 +0200 | [diff] [blame] | 791 | interface->desc.bInterfaceNumber, buf + 1, count - 1, |
| 792 | USB_CTRL_SET_TIMEOUT); |
| 793 | |
| 794 | /* count also the report id */ |
| 795 | if (ret > 0) |
| 796 | ret++; |
| 797 | |
| 798 | return ret; |
| 799 | } |
| 800 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 801 | static void usbhid_restart_queues(struct usbhid_device *usbhid) |
| 802 | { |
| 803 | if (usbhid->urbout) |
| 804 | usbhid_restart_out_queue(usbhid); |
| 805 | usbhid_restart_ctrl_queue(usbhid); |
| 806 | } |
| 807 | |
| 808 | static void __usbhid_restart_queues(struct work_struct *work) |
| 809 | { |
| 810 | struct usbhid_device *usbhid = |
| 811 | container_of(work, struct usbhid_device, restart_work); |
| 812 | int r; |
| 813 | |
| 814 | r = usb_autopm_get_interface(usbhid->intf); |
| 815 | if (r < 0) |
| 816 | return; |
| 817 | usb_autopm_put_interface(usbhid->intf); |
| 818 | } |
| 819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) |
| 821 | { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 822 | struct usbhid_device *usbhid = hid->driver_data; |
| 823 | |
Dmitry Torokhov | 6675c5b | 2007-05-03 01:04:52 -0400 | [diff] [blame] | 824 | usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma); |
| 825 | usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma); |
| 826 | usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma); |
| 827 | usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 830 | static int usbhid_parse(struct hid_device *hid) |
| 831 | { |
| 832 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 834 | struct usb_device *dev = interface_to_usbdev (intf); |
| 835 | struct hid_descriptor *hdesc; |
Paul Walmsley | 2eb5dc3 | 2007-04-19 13:27:04 +0200 | [diff] [blame] | 836 | u32 quirks = 0; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 837 | unsigned int rsize = 0; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 838 | char *rdesc; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 839 | int ret, n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Paul Walmsley | 2eb5dc3 | 2007-04-19 13:27:04 +0200 | [diff] [blame] | 841 | quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor), |
| 842 | le16_to_cpu(dev->descriptor.idProduct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Alan Stern | 0f28b55 | 2006-05-15 14:49:04 -0400 | [diff] [blame] | 844 | /* Many keyboards and mice don't like to be polled for reports, |
| 845 | * so we will always set the HID_QUIRK_NOGET flag for them. */ |
| 846 | if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) { |
| 847 | if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD || |
| 848 | interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE) |
| 849 | quirks |= HID_QUIRK_NOGET; |
| 850 | } |
| 851 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 852 | if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && |
| 853 | (!interface->desc.bNumEndpoints || |
| 854 | usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 855 | dbg_hid("class descriptor not present\n"); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 856 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 859 | hid->version = le16_to_cpu(hdesc->bcdHID); |
| 860 | hid->country = hdesc->bCountryCode; |
| 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | for (n = 0; n < hdesc->bNumDescriptors; n++) |
| 863 | if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT) |
| 864 | rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength); |
| 865 | |
| 866 | if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 867 | dbg_hid("weird size of report descriptor (%u)\n", rsize); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 868 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 872 | dbg_hid("couldn't allocate rdesc memory\n"); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 873 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Vojtech Pavlik | 854561b | 2005-05-29 02:28:00 -0500 | [diff] [blame] | 876 | hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0); |
| 877 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 878 | ret = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, |
| 879 | HID_DT_REPORT, rdesc, rsize); |
| 880 | if (ret < 0) { |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 881 | dbg_hid("reading report descriptor failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | kfree(rdesc); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 883 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 886 | dbg_hid("report descriptor (size %u, read %d) = ", rsize, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | for (n = 0; n < rsize; n++) |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 888 | dbg_hid_line(" %02x", (unsigned char) rdesc[n]); |
| 889 | dbg_hid_line("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 891 | ret = hid_parse_report(hid, rdesc, rsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | kfree(rdesc); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 893 | if (ret) { |
| 894 | dbg_hid("parsing report descriptor failed\n"); |
| 895 | goto err; |
| 896 | } |
| 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | hid->quirks = quirks; |
| 899 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 900 | return 0; |
| 901 | err: |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | static int usbhid_start(struct hid_device *hid) |
| 906 | { |
| 907 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); |
| 908 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 909 | struct usb_device *dev = interface_to_usbdev(intf); |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 910 | struct usbhid_device *usbhid = hid->driver_data; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 911 | unsigned int n, insize = 0; |
| 912 | int ret; |
| 913 | |
Jiri Slaby | e3e14de | 2008-11-01 23:41:46 +0100 | [diff] [blame] | 914 | clear_bit(HID_DISCONNECTED, &usbhid->iofl); |
| 915 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 916 | usbhid->bufsize = HID_MIN_BUFFER_SIZE; |
| 917 | hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize); |
| 918 | hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize); |
| 919 | hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize); |
| 920 | |
| 921 | if (usbhid->bufsize > HID_MAX_BUFFER_SIZE) |
| 922 | usbhid->bufsize = HID_MAX_BUFFER_SIZE; |
Michael Haboustak | bf0964d | 2005-09-05 00:12:01 -0500 | [diff] [blame] | 923 | |
| 924 | hid_find_max_report(hid, HID_INPUT_REPORT, &insize); |
| 925 | |
| 926 | if (insize > HID_MAX_BUFFER_SIZE) |
| 927 | insize = HID_MAX_BUFFER_SIZE; |
| 928 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 929 | if (hid_alloc_buffers(dev, hid)) { |
| 930 | ret = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | goto fail; |
Pekka Sarnila | f345c37 | 2008-03-06 13:23:14 +0100 | [diff] [blame] | 932 | } |
| 933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | for (n = 0; n < interface->desc.bNumEndpoints; n++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | struct usb_endpoint_descriptor *endpoint; |
| 936 | int pipe; |
| 937 | int interval; |
| 938 | |
| 939 | endpoint = &interface->endpoint[n].desc; |
Jiri Slaby | 581a273 | 2008-11-24 16:20:08 +0100 | [diff] [blame] | 940 | if (!usb_endpoint_xfer_int(endpoint)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | continue; |
| 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | interval = endpoint->bInterval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Pekka Sarnila | f345c37 | 2008-03-06 13:23:14 +0100 | [diff] [blame] | 945 | /* Some vendors give fullspeed interval on highspeed devides */ |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 946 | if (hid->quirks & HID_QUIRK_FULLSPEED_INTERVAL && |
Pekka Sarnila | f345c37 | 2008-03-06 13:23:14 +0100 | [diff] [blame] | 947 | dev->speed == USB_SPEED_HIGH) { |
| 948 | interval = fls(endpoint->bInterval*8); |
| 949 | printk(KERN_INFO "%s: Fixing fullspeed to highspeed interval: %d -> %d\n", |
| 950 | hid->name, endpoint->bInterval, interval); |
| 951 | } |
| 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | /* Change the polling interval of mice. */ |
| 954 | if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) |
| 955 | interval = hid_mousepoll_interval; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 956 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 957 | ret = -ENOMEM; |
Luiz Fernando N. Capitulino | 0f12aa0 | 2006-10-26 13:02:51 -0300 | [diff] [blame] | 958 | if (usb_endpoint_dir_in(endpoint)) { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 959 | if (usbhid->urbin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | continue; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 961 | if (!(usbhid->urbin = usb_alloc_urb(0, GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | goto fail; |
| 963 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 964 | usb_fill_int_urb(usbhid->urbin, dev, pipe, usbhid->inbuf, insize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | hid_irq_in, hid, interval); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 966 | usbhid->urbin->transfer_dma = usbhid->inbuf_dma; |
| 967 | usbhid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } else { |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 969 | if (usbhid->urbout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | continue; |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 971 | if (!(usbhid->urbout = usb_alloc_urb(0, GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | goto fail; |
| 973 | pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 974 | usb_fill_int_urb(usbhid->urbout, dev, pipe, usbhid->outbuf, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | hid_irq_out, hid, interval); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 976 | usbhid->urbout->transfer_dma = usbhid->outbuf_dma; |
| 977 | usbhid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | |
Jiri Slaby | 1d1bdd2 | 2008-03-19 21:55:04 +0100 | [diff] [blame] | 981 | init_waitqueue_head(&usbhid->wait); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 982 | INIT_WORK(&usbhid->reset_work, hid_reset); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 983 | INIT_WORK(&usbhid->restart_work, __usbhid_restart_queues); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 984 | setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 985 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 986 | spin_lock_init(&usbhid->lock); |
| 987 | spin_lock_init(&usbhid->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 989 | usbhid->intf = intf; |
| 990 | usbhid->ifnum = interface->desc.bInterfaceNumber; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 992 | usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 993 | if (!usbhid->urbctrl) { |
| 994 | ret = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | goto fail; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 996 | } |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 997 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 998 | usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr, |
| 999 | usbhid->ctrlbuf, 1, hid_ctrl, hid); |
| 1000 | usbhid->urbctrl->setup_dma = usbhid->cr_dma; |
| 1001 | usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma; |
| 1002 | usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1003 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 1004 | usbhid_init_reports(hid); |
| 1005 | hid_dump_device(hid); |
| 1006 | |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1007 | set_bit(HID_STARTED, &usbhid->iofl); |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1008 | |
Alan Stern | 08ef08e | 2008-10-30 23:58:51 +0100 | [diff] [blame] | 1009 | /* Some keyboards don't work until their LEDs have been set. |
| 1010 | * Since BIOSes do set the LEDs, it must be safe for any device |
| 1011 | * that supports the keyboard boot protocol. |
| 1012 | */ |
| 1013 | if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT && |
| 1014 | interface->desc.bInterfaceProtocol == |
| 1015 | USB_INTERFACE_PROTOCOL_KEYBOARD) |
| 1016 | usbhid_set_leds(hid); |
| 1017 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1018 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
| 1020 | fail: |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1021 | usb_free_urb(usbhid->urbin); |
| 1022 | usb_free_urb(usbhid->urbout); |
| 1023 | usb_free_urb(usbhid->urbctrl); |
Jiri Slaby | e3e14de | 2008-11-01 23:41:46 +0100 | [diff] [blame] | 1024 | usbhid->urbin = NULL; |
| 1025 | usbhid->urbout = NULL; |
| 1026 | usbhid->urbctrl = NULL; |
Jiri Kosina | 22f675f | 2007-08-01 12:32:27 +0200 | [diff] [blame] | 1027 | hid_free_buffers(dev, hid); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1028 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1031 | static void usbhid_stop(struct hid_device *hid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | { |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1033 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1035 | if (WARN_ON(!usbhid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | return; |
| 1037 | |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1038 | clear_bit(HID_STARTED, &usbhid->iofl); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1039 | spin_lock_irq(&usbhid->lock); /* Sync with error handler */ |
Oliver Neukum | 69626f2 | 2008-03-31 16:27:30 +0200 | [diff] [blame] | 1040 | set_bit(HID_DISCONNECTED, &usbhid->iofl); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1041 | spin_unlock_irq(&usbhid->lock); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1042 | usb_kill_urb(usbhid->urbin); |
| 1043 | usb_kill_urb(usbhid->urbout); |
| 1044 | usb_kill_urb(usbhid->urbctrl); |
| 1045 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1046 | hid_cancel_delayed_stuff(usbhid); |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 1047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | if (hid->claimed & HID_CLAIMED_INPUT) |
| 1049 | hidinput_disconnect(hid); |
| 1050 | if (hid->claimed & HID_CLAIMED_HIDDEV) |
| 1051 | hiddev_disconnect(hid); |
Jiri Kosina | 86166b7 | 2007-05-14 09:57:40 +0200 | [diff] [blame] | 1052 | if (hid->claimed & HID_CLAIMED_HIDRAW) |
| 1053 | hidraw_disconnect(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1055 | hid->claimed = 0; |
| 1056 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1057 | usb_free_urb(usbhid->urbin); |
| 1058 | usb_free_urb(usbhid->urbctrl); |
| 1059 | usb_free_urb(usbhid->urbout); |
Jiri Slaby | e3e14de | 2008-11-01 23:41:46 +0100 | [diff] [blame] | 1060 | usbhid->urbin = NULL; /* don't mess up next start */ |
| 1061 | usbhid->urbctrl = NULL; |
| 1062 | usbhid->urbout = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 1064 | hid_free_buffers(hid_to_usb_dev(hid), hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1067 | static int usbhid_power(struct hid_device *hid, int lvl) |
| 1068 | { |
| 1069 | int r = 0; |
| 1070 | |
| 1071 | switch (lvl) { |
| 1072 | case PM_HINT_FULLON: |
| 1073 | r = usbhid_get_power(hid); |
| 1074 | break; |
| 1075 | case PM_HINT_NORMAL: |
| 1076 | usbhid_put_power(hid); |
| 1077 | break; |
| 1078 | } |
| 1079 | return r; |
| 1080 | } |
| 1081 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1082 | static struct hid_ll_driver usb_hid_driver = { |
| 1083 | .parse = usbhid_parse, |
| 1084 | .start = usbhid_start, |
| 1085 | .stop = usbhid_stop, |
| 1086 | .open = usbhid_open, |
| 1087 | .close = usbhid_close, |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1088 | .power = usbhid_power, |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1089 | .hidinput_input_event = usb_hidinput_input_event, |
| 1090 | }; |
| 1091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 1093 | { |
Jiri Slaby | 131d3a7a | 2008-11-14 12:03:47 +0100 | [diff] [blame] | 1094 | struct usb_host_interface *interface = intf->cur_altsetting; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1095 | struct usb_device *dev = interface_to_usbdev(intf); |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1096 | struct usbhid_device *usbhid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | struct hid_device *hid; |
Jiri Slaby | 131d3a7a | 2008-11-14 12:03:47 +0100 | [diff] [blame] | 1098 | unsigned int n, has_in = 0; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1099 | size_t len; |
| 1100 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
Jiri Kosina | 58037eb | 2007-05-30 15:07:13 +0200 | [diff] [blame] | 1102 | dbg_hid("HID probe called for ifnum %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | intf->altsetting->desc.bInterfaceNumber); |
| 1104 | |
Jiri Slaby | 131d3a7a | 2008-11-14 12:03:47 +0100 | [diff] [blame] | 1105 | for (n = 0; n < interface->desc.bNumEndpoints; n++) |
| 1106 | if (usb_endpoint_is_int_in(&interface->endpoint[n].desc)) |
| 1107 | has_in++; |
| 1108 | if (!has_in) { |
| 1109 | dev_err(&intf->dev, "couldn't find an input interrupt " |
| 1110 | "endpoint\n"); |
| 1111 | return -ENODEV; |
| 1112 | } |
| 1113 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1114 | hid = hid_allocate_device(); |
| 1115 | if (IS_ERR(hid)) |
| 1116 | return PTR_ERR(hid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
| 1118 | usb_set_intfdata(intf, hid); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1119 | hid->ll_driver = &usb_hid_driver; |
| 1120 | hid->hid_output_raw_report = usbhid_output_raw_report; |
Jiri Slaby | 76483cf | 2008-09-18 12:23:33 +0200 | [diff] [blame] | 1121 | hid->ff_init = hid_pidff_init; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1122 | #ifdef CONFIG_USB_HIDDEV |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 1123 | hid->hiddev_connect = hiddev_connect; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1124 | hid->hiddev_hid_event = hiddev_hid_event; |
| 1125 | hid->hiddev_report_event = hiddev_report_event; |
| 1126 | #endif |
| 1127 | hid->dev.parent = &intf->dev; |
| 1128 | hid->bus = BUS_USB; |
| 1129 | hid->vendor = le16_to_cpu(dev->descriptor.idVendor); |
| 1130 | hid->product = le16_to_cpu(dev->descriptor.idProduct); |
| 1131 | hid->name[0] = 0; |
Jiri Slaby | a73a637 | 2008-10-22 14:45:11 +0200 | [diff] [blame] | 1132 | if (intf->cur_altsetting->desc.bInterfaceProtocol == |
| 1133 | USB_INTERFACE_PROTOCOL_MOUSE) |
| 1134 | hid->type = HID_TYPE_USBMOUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1136 | if (dev->manufacturer) |
| 1137 | strlcpy(hid->name, dev->manufacturer, sizeof(hid->name)); |
| 1138 | |
| 1139 | if (dev->product) { |
| 1140 | if (dev->manufacturer) |
| 1141 | strlcat(hid->name, " ", sizeof(hid->name)); |
| 1142 | strlcat(hid->name, dev->product, sizeof(hid->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1145 | if (!strlen(hid->name)) |
| 1146 | snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x", |
| 1147 | le16_to_cpu(dev->descriptor.idVendor), |
| 1148 | le16_to_cpu(dev->descriptor.idProduct)); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1149 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1150 | usb_make_path(dev, hid->phys, sizeof(hid->phys)); |
| 1151 | strlcat(hid->phys, "/input", sizeof(hid->phys)); |
| 1152 | len = strlen(hid->phys); |
| 1153 | if (len < sizeof(hid->phys) - 1) |
| 1154 | snprintf(hid->phys + len, sizeof(hid->phys) - len, |
| 1155 | "%d", intf->altsetting[0].desc.bInterfaceNumber); |
Geoff Levand | 4a1a4d8 | 2007-01-15 20:11:52 -0800 | [diff] [blame] | 1156 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1157 | if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) |
| 1158 | hid->uniq[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1160 | usbhid = kzalloc(sizeof(*usbhid), GFP_KERNEL); |
| 1161 | if (usbhid == NULL) { |
| 1162 | ret = -ENOMEM; |
| 1163 | goto err; |
| 1164 | } |
| 1165 | |
| 1166 | hid->driver_data = usbhid; |
| 1167 | usbhid->hid = hid; |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1168 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1169 | ret = hid_add_device(hid); |
| 1170 | if (ret) { |
Jiri Slaby | d458a9d | 2008-05-16 11:49:20 +0200 | [diff] [blame] | 1171 | if (ret != -ENODEV) |
| 1172 | dev_err(&intf->dev, "can't add hid device: %d\n", ret); |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1173 | goto err_free; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1174 | } |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1175 | |
| 1176 | return 0; |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1177 | err_free: |
| 1178 | kfree(usbhid); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1179 | err: |
| 1180 | hid_destroy_device(hid); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1181 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1184 | static void hid_disconnect(struct usb_interface *intf) |
| 1185 | { |
| 1186 | struct hid_device *hid = usb_get_intfdata(intf); |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1187 | struct usbhid_device *usbhid; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1188 | |
| 1189 | if (WARN_ON(!hid)) |
| 1190 | return; |
| 1191 | |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1192 | usbhid = hid->driver_data; |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1193 | hid_destroy_device(hid); |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1194 | kfree(usbhid); |
Jiri Slaby | c500c97 | 2008-05-16 11:49:16 +0200 | [diff] [blame] | 1195 | } |
| 1196 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1197 | static void hid_cancel_delayed_stuff(struct usbhid_device *usbhid) |
| 1198 | { |
| 1199 | del_timer_sync(&usbhid->io_retry); |
| 1200 | cancel_work_sync(&usbhid->restart_work); |
| 1201 | cancel_work_sync(&usbhid->reset_work); |
| 1202 | } |
| 1203 | |
| 1204 | static void hid_cease_io(struct usbhid_device *usbhid) |
| 1205 | { |
| 1206 | del_timer(&usbhid->io_retry); |
| 1207 | usb_kill_urb(usbhid->urbin); |
| 1208 | usb_kill_urb(usbhid->urbctrl); |
| 1209 | usb_kill_urb(usbhid->urbout); |
| 1210 | flush_scheduled_work(); |
| 1211 | } |
| 1212 | |
Jiri Kosina | 0f6f140 | 2009-01-19 09:17:18 +0100 | [diff] [blame] | 1213 | #ifdef CONFIG_PM |
David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 1214 | static int hid_suspend(struct usb_interface *intf, pm_message_t message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | { |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1216 | struct hid_device *hid = usb_get_intfdata(intf); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1217 | struct usbhid_device *usbhid = hid->driver_data; |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1218 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1219 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1221 | if (udev->auto_pm) { |
| 1222 | spin_lock_irq(&usbhid->lock); /* Sync with error handler */ |
| 1223 | if (!test_bit(HID_RESET_PENDING, &usbhid->iofl) |
| 1224 | && !test_bit(HID_CLEAR_HALT, &usbhid->iofl) |
| 1225 | && !test_bit(HID_OUT_RUNNING, &usbhid->iofl) |
| 1226 | && !test_bit(HID_CTRL_RUNNING, &usbhid->iofl) |
| 1227 | && !test_bit(HID_KEYS_PRESSED, &usbhid->iofl) |
| 1228 | && (!usbhid->ledcount || ignoreled)) |
| 1229 | { |
| 1230 | set_bit(HID_REPORTED_IDLE, &usbhid->iofl); |
| 1231 | spin_unlock_irq(&usbhid->lock); |
| 1232 | } else { |
| 1233 | usbhid_mark_busy(usbhid); |
| 1234 | spin_unlock_irq(&usbhid->lock); |
| 1235 | return -EBUSY; |
| 1236 | } |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1237 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1238 | } else { |
| 1239 | spin_lock_irq(&usbhid->lock); |
| 1240 | set_bit(HID_REPORTED_IDLE, &usbhid->iofl); |
| 1241 | spin_unlock_irq(&usbhid->lock); |
| 1242 | if (usbhid_wait_io(hid) < 0) |
| 1243 | return -EIO; |
| 1244 | } |
| 1245 | |
| 1246 | if (!ignoreled && udev->auto_pm) { |
| 1247 | spin_lock_irq(&usbhid->lock); |
| 1248 | if (test_bit(HID_LED_ON, &usbhid->iofl)) { |
| 1249 | spin_unlock_irq(&usbhid->lock); |
| 1250 | usbhid_mark_busy(usbhid); |
| 1251 | return -EBUSY; |
| 1252 | } |
| 1253 | spin_unlock_irq(&usbhid->lock); |
| 1254 | } |
| 1255 | |
| 1256 | hid_cancel_delayed_stuff(usbhid); |
| 1257 | hid_cease_io(usbhid); |
| 1258 | |
| 1259 | if (udev->auto_pm && test_bit(HID_KEYS_PRESSED, &usbhid->iofl)) { |
| 1260 | /* lost race against keypresses */ |
| 1261 | status = hid_start_in(hid); |
| 1262 | if (status < 0) |
| 1263 | hid_io_error(hid); |
| 1264 | usbhid_mark_busy(usbhid); |
| 1265 | return -EBUSY; |
| 1266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | dev_dbg(&intf->dev, "suspend\n"); |
| 1268 | return 0; |
| 1269 | } |
| 1270 | |
| 1271 | static int hid_resume(struct usb_interface *intf) |
| 1272 | { |
| 1273 | struct hid_device *hid = usb_get_intfdata (intf); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1274 | struct usbhid_device *usbhid = hid->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | int status; |
| 1276 | |
Jiri Slaby | fde5be3 | 2008-11-23 12:03:20 +0100 | [diff] [blame] | 1277 | if (!test_bit(HID_STARTED, &usbhid->iofl)) |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1278 | return 0; |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 1279 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1280 | clear_bit(HID_REPORTED_IDLE, &usbhid->iofl); |
| 1281 | usbhid_mark_busy(usbhid); |
| 1282 | |
| 1283 | if (test_bit(HID_CLEAR_HALT, &usbhid->iofl) || |
| 1284 | test_bit(HID_RESET_PENDING, &usbhid->iofl)) |
| 1285 | schedule_work(&usbhid->reset_work); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 1286 | usbhid->retry_delay = 0; |
Alan Stern | aef4e26 | 2006-01-31 12:58:38 -0500 | [diff] [blame] | 1287 | status = hid_start_in(hid); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1288 | if (status < 0) |
| 1289 | hid_io_error(hid); |
| 1290 | usbhid_restart_queues(usbhid); |
| 1291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | dev_dbg(&intf->dev, "resume status %d\n", status); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1293 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Jiri Kosina | 0f6f140 | 2009-01-19 09:17:18 +0100 | [diff] [blame] | 1296 | #endif /* CONFIG_PM */ |
| 1297 | |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1298 | /* Treat USB reset pretty much the same as suspend/resume */ |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1299 | static int hid_pre_reset(struct usb_interface *intf) |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1300 | { |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1301 | struct hid_device *hid = usb_get_intfdata(intf); |
| 1302 | struct usbhid_device *usbhid = hid->driver_data; |
| 1303 | |
| 1304 | spin_lock_irq(&usbhid->lock); |
| 1305 | set_bit(HID_RESET_PENDING, &usbhid->iofl); |
| 1306 | spin_unlock_irq(&usbhid->lock); |
| 1307 | hid_cease_io(usbhid); |
| 1308 | |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1309 | return 0; |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1310 | } |
| 1311 | |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 1312 | /* Same routine used for post_reset and reset_resume */ |
| 1313 | static int hid_post_reset(struct usb_interface *intf) |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1314 | { |
| 1315 | struct usb_device *dev = interface_to_usbdev (intf); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1316 | struct hid_device *hid = usb_get_intfdata(intf); |
| 1317 | struct usbhid_device *usbhid = hid->driver_data; |
| 1318 | int status; |
| 1319 | |
| 1320 | spin_lock_irq(&usbhid->lock); |
| 1321 | clear_bit(HID_RESET_PENDING, &usbhid->iofl); |
| 1322 | spin_unlock_irq(&usbhid->lock); |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1323 | hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0); |
| 1324 | /* FIXME: Any more reinitialization needed? */ |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1325 | status = hid_start_in(hid); |
| 1326 | if (status < 0) |
| 1327 | hid_io_error(hid); |
| 1328 | usbhid_restart_queues(usbhid); |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1329 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1330 | return 0; |
| 1331 | } |
| 1332 | |
Oliver Neukum | 378a0ed | 2009-02-18 11:46:45 +0100 | [diff] [blame^] | 1333 | static int hid_reset_resume(struct usb_interface *intf) |
| 1334 | { |
| 1335 | struct hid_device *hid = usb_get_intfdata(intf); |
| 1336 | struct usbhid_device *usbhid = hid->driver_data; |
| 1337 | |
| 1338 | clear_bit(HID_REPORTED_IDLE, &usbhid->iofl); |
| 1339 | return hid_post_reset(intf); |
| 1340 | } |
| 1341 | |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1342 | int usbhid_get_power(struct hid_device *hid) |
| 1343 | { |
| 1344 | struct usbhid_device *usbhid = hid->driver_data; |
| 1345 | |
| 1346 | return usb_autopm_get_interface(usbhid->intf); |
| 1347 | } |
| 1348 | |
| 1349 | void usbhid_put_power(struct hid_device *hid) |
| 1350 | { |
| 1351 | struct usbhid_device *usbhid = hid->driver_data; |
| 1352 | |
| 1353 | usb_autopm_put_interface(usbhid->intf); |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1354 | } |
| 1355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | static struct usb_device_id hid_usb_ids [] = { |
| 1357 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, |
| 1358 | .bInterfaceClass = USB_INTERFACE_CLASS_HID }, |
| 1359 | { } /* Terminating entry */ |
| 1360 | }; |
| 1361 | |
| 1362 | MODULE_DEVICE_TABLE (usb, hid_usb_ids); |
| 1363 | |
| 1364 | static struct usb_driver hid_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | .name = "usbhid", |
| 1366 | .probe = hid_probe, |
| 1367 | .disconnect = hid_disconnect, |
Jiri Kosina | 0f6f140 | 2009-01-19 09:17:18 +0100 | [diff] [blame] | 1368 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | .suspend = hid_suspend, |
| 1370 | .resume = hid_resume, |
Oliver Neukum | 378a0ed | 2009-02-18 11:46:45 +0100 | [diff] [blame^] | 1371 | .reset_resume = hid_reset_resume, |
Jiri Kosina | 0f6f140 | 2009-01-19 09:17:18 +0100 | [diff] [blame] | 1372 | #endif |
Alan Stern | df9a1f4 | 2006-06-01 13:55:28 -0400 | [diff] [blame] | 1373 | .pre_reset = hid_pre_reset, |
| 1374 | .post_reset = hid_post_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | .id_table = hid_usb_ids, |
Oliver Neukum | 933e318 | 2007-07-11 14:48:58 +0200 | [diff] [blame] | 1376 | .supports_autosuspend = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | }; |
| 1378 | |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1379 | static const struct hid_device_id hid_usb_table[] = { |
| 1380 | { HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) }, |
| 1381 | { } |
| 1382 | }; |
| 1383 | |
| 1384 | static struct hid_driver hid_usb_driver = { |
| 1385 | .name = "generic-usb", |
| 1386 | .id_table = hid_usb_table, |
| 1387 | }; |
| 1388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | static int __init hid_init(void) |
| 1390 | { |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1391 | int retval = -ENOMEM; |
| 1392 | |
| 1393 | resumption_waker = create_freezeable_workqueue("usbhid_resumer"); |
| 1394 | if (!resumption_waker) |
| 1395 | goto no_queue; |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1396 | retval = hid_register_driver(&hid_usb_driver); |
| 1397 | if (retval) |
| 1398 | goto hid_register_fail; |
Paul Walmsley | 876b927 | 2007-04-19 14:56:12 +0200 | [diff] [blame] | 1399 | retval = usbhid_quirks_init(quirks_param); |
| 1400 | if (retval) |
| 1401 | goto usbhid_quirks_init_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | retval = hiddev_init(); |
| 1403 | if (retval) |
| 1404 | goto hiddev_init_fail; |
| 1405 | retval = usb_register(&hid_driver); |
| 1406 | if (retval) |
| 1407 | goto usb_register_fail; |
Greg Kroah-Hartman | ddbe324 | 2008-10-12 00:14:23 +0200 | [diff] [blame] | 1408 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 1409 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | |
| 1411 | return 0; |
| 1412 | usb_register_fail: |
| 1413 | hiddev_exit(); |
| 1414 | hiddev_init_fail: |
Paul Walmsley | 876b927 | 2007-04-19 14:56:12 +0200 | [diff] [blame] | 1415 | usbhid_quirks_exit(); |
| 1416 | usbhid_quirks_init_fail: |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1417 | hid_unregister_driver(&hid_usb_driver); |
| 1418 | hid_register_fail: |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1419 | destroy_workqueue(resumption_waker); |
| 1420 | no_queue: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | return retval; |
| 1422 | } |
| 1423 | |
| 1424 | static void __exit hid_exit(void) |
| 1425 | { |
| 1426 | usb_deregister(&hid_driver); |
| 1427 | hiddev_exit(); |
Paul Walmsley | 876b927 | 2007-04-19 14:56:12 +0200 | [diff] [blame] | 1428 | usbhid_quirks_exit(); |
Jiri Slaby | 85cdaf5 | 2008-05-16 11:49:15 +0200 | [diff] [blame] | 1429 | hid_unregister_driver(&hid_usb_driver); |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 1430 | destroy_workqueue(resumption_waker); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | module_init(hid_init); |
| 1434 | module_exit(hid_exit); |
| 1435 | |
| 1436 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1437 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1438 | MODULE_LICENSE(DRIVER_LICENSE); |