aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@insightbb.com>2007-05-01 00:24:54 -0400
committerDmitry Torokhov <dtor@insightbb.com>2007-05-01 00:24:54 -0400
commitbc95f3669f5e6f63cf0b84fe4922c3c6dd4aa775 (patch)
tree427fcf2a7287c16d4b5aa6cbf494d59579a6a8b1 /drivers/usb/input
parent3d29cdff999c37b3876082278a8134a0642a02cd (diff)
parentdc87c3985e9b442c60994308a96f887579addc39 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6
Conflicts: drivers/usb/input/Makefile drivers/usb/input/gtco.c
Diffstat (limited to 'drivers/usb/input')
-rw-r--r--drivers/usb/input/Kconfig145
-rw-r--r--drivers/usb/input/Makefile30
-rw-r--r--drivers/usb/input/gtco.c2
-rw-r--r--drivers/usb/input/hid-core.c1459
-rw-r--r--drivers/usb/input/hid-ff.c89
-rw-r--r--drivers/usb/input/hid-lgff.c150
-rw-r--r--drivers/usb/input/hid-pidff.c1331
-rw-r--r--drivers/usb/input/hid-plff.c129
-rw-r--r--drivers/usb/input/hid-tmff.c147
-rw-r--r--drivers/usb/input/hid-zpff.c111
-rw-r--r--drivers/usb/input/hiddev.c847
-rw-r--r--drivers/usb/input/usbhid.h87
-rw-r--r--drivers/usb/input/usbkbd.c360
-rw-r--r--drivers/usb/input/usbmouse.c243
-rw-r--r--drivers/usb/input/wacom_wac.c103
-rw-r--r--drivers/usb/input/wacom_wac.h1
16 files changed, 67 insertions, 5167 deletions
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 69a9f3b6d0a9..a792e42f58af 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -4,151 +4,6 @@
4comment "USB Input Devices" 4comment "USB Input Devices"
5 depends on USB 5 depends on USB
6 6
7config USB_HID
8 tristate "USB Human Interface Device (full HID) support"
9 default y
10 depends on USB && INPUT
11 select HID
12 ---help---
13 Say Y here if you want full HID support to connect USB keyboards,
14 mice, joysticks, graphic tablets, or any other HID based devices
15 to your computer via USB, as well as Uninterruptible Power Supply
16 (UPS) and monitor control devices.
17
18 You can't use this driver and the HIDBP (Boot Protocol) keyboard
19 and mouse drivers at the same time. More information is available:
20 <file:Documentation/input/input.txt>.
21
22 If unsure, say Y.
23
24 To compile this driver as a module, choose M here: the
25 module will be called usbhid.
26
27comment "Input core support is needed for USB HID input layer or HIDBP support"
28 depends on USB_HID && INPUT=n
29
30config USB_HIDINPUT_POWERBOOK
31 bool "Enable support for iBook/PowerBook special keys"
32 default n
33 depends on USB_HID
34 help
35 Say Y here if you want support for the special keys (Fn, Numlock) on
36 Apple iBooks and PowerBooks.
37
38 If unsure, say N.
39
40config HID_FF
41 bool "Force feedback support (EXPERIMENTAL)"
42 depends on USB_HID && EXPERIMENTAL
43 help
44 Say Y here is you want force feedback support for a few HID devices.
45 See below for a list of supported devices.
46
47 See <file:Documentation/input/ff.txt> for a description of the force
48 feedback API.
49
50 If unsure, say N.
51
52config HID_PID
53 bool "PID device support"
54 depends on HID_FF
55 help
56 Say Y here if you have a PID-compliant device and wish to enable force
57 feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such
58 devices.
59
60config LOGITECH_FF
61 bool "Logitech devices support"
62 depends on HID_FF
63 select INPUT_FF_MEMLESS if USB_HID
64 help
65 Say Y here if you have one of these devices:
66 - Logitech WingMan Cordless RumblePad
67 - Logitech WingMan Cordless RumblePad 2
68 - Logitech WingMan Force 3D
69 - Logitech Formula Force EX
70 - Logitech MOMO Force wheel
71
72 and if you want to enable force feedback for them.
73 Note: if you say N here, this device will still be supported, but without
74 force feedback.
75
76config PANTHERLORD_FF
77 bool "PantherLord USB/PS2 2in1 Adapter support"
78 depends on HID_FF
79 select INPUT_FF_MEMLESS if USB_HID
80 help
81 Say Y here if you have a PantherLord USB/PS2 2in1 Adapter and want
82 to enable force feedback support for it.
83
84config THRUSTMASTER_FF
85 bool "ThrustMaster FireStorm Dual Power 2 support (EXPERIMENTAL)"
86 depends on HID_FF && EXPERIMENTAL
87 select INPUT_FF_MEMLESS if USB_HID
88 help
89 Say Y here if you have a THRUSTMASTER FireStore Dual Power 2,
90 and want to enable force feedback support for it.
91 Note: if you say N here, this device will still be supported, but without
92 force feedback.
93
94config ZEROPLUS_FF
95 bool "Zeroplus based game controller support"
96 depends on HID_FF
97 select INPUT_FF_MEMLESS if USB_HID
98 help
99 Say Y here if you have a Zeroplus based game controller and want to
100 enable force feedback for it.
101
102config USB_HIDDEV
103 bool "/dev/hiddev raw HID device support"
104 depends on USB_HID
105 help
106 Say Y here if you want to support HID devices (from the USB
107 specification standpoint) that aren't strictly user interface
108 devices, like monitor controls and Uninterruptable Power Supplies.
109
110 This module supports these devices separately using a separate
111 event interface on /dev/usb/hiddevX (char 180:96 to 180:111).
112
113 If unsure, say Y.
114
115menu "USB HID Boot Protocol drivers"
116 depends on USB!=n && USB_HID!=y
117
118config USB_KBD
119 tristate "USB HIDBP Keyboard (simple Boot) support"
120 depends on USB && INPUT
121 ---help---
122 Say Y here only if you are absolutely sure that you don't want
123 to use the generic HID driver for your USB keyboard and prefer
124 to use the keyboard in its limited Boot Protocol mode instead.
125
126 This is almost certainly not what you want. This is mostly
127 useful for embedded applications or simple keyboards.
128
129 To compile this driver as a module, choose M here: the
130 module will be called usbkbd.
131
132 If even remotely unsure, say N.
133
134config USB_MOUSE
135 tristate "USB HIDBP Mouse (simple Boot) support"
136 depends on USB && INPUT
137 ---help---
138 Say Y here only if you are absolutely sure that you don't want
139 to use the generic HID driver for your USB mouse and prefer
140 to use the mouse in its limited Boot Protocol mode instead.
141
142 This is almost certainly not what you want. This is mostly
143 useful for embedded applications or simple mice.
144
145 To compile this driver as a module, choose M here: the
146 module will be called usbmouse.
147
148 If even remotely unsure, say N.
149
150endmenu
151
152config USB_AIPTEK 7config USB_AIPTEK
153 tristate "Aiptek 6000U/8000U tablet support" 8 tristate "Aiptek 6000U/8000U tablet support"
154 depends on USB && INPUT 9 depends on USB && INPUT
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
index f8c35b66c466..284a0734e0cd 100644
--- a/drivers/usb/input/Makefile
+++ b/drivers/usb/input/Makefile
@@ -4,40 +4,12 @@
4 4
5# Multipart objects. 5# Multipart objects.
6wacom-objs := wacom_wac.o wacom_sys.o 6wacom-objs := wacom_wac.o wacom_sys.o
7usbhid-objs := hid-core.o
8
9# Optional parts of multipart objects.
10
11ifeq ($(CONFIG_USB_HIDDEV),y)
12 usbhid-objs += hiddev.o
13endif
14ifeq ($(CONFIG_HID_PID),y)
15 usbhid-objs += hid-pidff.o
16endif
17ifeq ($(CONFIG_LOGITECH_FF),y)
18 usbhid-objs += hid-lgff.o
19endif
20ifeq ($(CONFIG_PANTHERLORD_FF),y)
21 usbhid-objs += hid-plff.o
22endif
23ifeq ($(CONFIG_THRUSTMASTER_FF),y)
24 usbhid-objs += hid-tmff.o
25endif
26ifeq ($(CONFIG_ZEROPLUS_FF),y)
27 usbhid-objs += hid-zpff.o
28endif
29ifeq ($(CONFIG_HID_FF),y)
30 usbhid-objs += hid-ff.o
31endif
32 7
33obj-$(CONFIG_USB_AIPTEK) += aiptek.o 8obj-$(CONFIG_USB_AIPTEK) += aiptek.o
34obj-$(CONFIG_USB_ATI_REMOTE) += ati_remote.o 9obj-$(CONFIG_USB_ATI_REMOTE) += ati_remote.o
35obj-$(CONFIG_USB_ATI_REMOTE2) += ati_remote2.o 10obj-$(CONFIG_USB_ATI_REMOTE2) += ati_remote2.o
36obj-$(CONFIG_USB_HID) += usbhid.o
37obj-$(CONFIG_USB_KBD) += usbkbd.o
38obj-$(CONFIG_USB_KBTAB) += kbtab.o 11obj-$(CONFIG_USB_KBTAB) += kbtab.o
39obj-$(CONFIG_USB_KEYSPAN_REMOTE) += keyspan_remote.o 12obj-$(CONFIG_USB_KEYSPAN_REMOTE) += keyspan_remote.o
40obj-$(CONFIG_USB_MOUSE) += usbmouse.o
41obj-$(CONFIG_USB_TOUCHSCREEN) += usbtouchscreen.o 13obj-$(CONFIG_USB_TOUCHSCREEN) += usbtouchscreen.o
42obj-$(CONFIG_USB_POWERMATE) += powermate.o 14obj-$(CONFIG_USB_POWERMATE) += powermate.o
43obj-$(CONFIG_USB_WACOM) += wacom.o 15obj-$(CONFIG_USB_WACOM) += wacom.o
@@ -45,7 +17,7 @@ obj-$(CONFIG_USB_ACECAD) += acecad.o
45obj-$(CONFIG_USB_YEALINK) += yealink.o 17obj-$(CONFIG_USB_YEALINK) += yealink.o
46obj-$(CONFIG_USB_XPAD) += xpad.o 18obj-$(CONFIG_USB_XPAD) += xpad.o
47obj-$(CONFIG_USB_APPLETOUCH) += appletouch.o 19obj-$(CONFIG_USB_APPLETOUCH) += appletouch.o
48obj-$(CONFIG_USB_GTCO) += gtco.o 20obj-$(CONFIG_USB_GTCO) += gtco.o
49 21
50ifeq ($(CONFIG_USB_DEBUG),y) 22ifeq ($(CONFIG_USB_DEBUG),y)
51EXTRA_CFLAGS += -DDEBUG 23EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/usb/input/gtco.c b/drivers/usb/input/gtco.c
index dbd207efb8f5..b2ca10f2fe0e 100644
--- a/drivers/usb/input/gtco.c
+++ b/drivers/usb/input/gtco.c
@@ -223,7 +223,7 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report,
223 __u32 oldval[TAG_GLOB_MAX]; 223 __u32 oldval[TAG_GLOB_MAX];
224 224
225 /* Debug stuff */ 225 /* Debug stuff */
226 char maintype='x'; 226 char maintype = 'x';
227 char globtype[12]; 227 char globtype[12];
228 int indent = 0; 228 int indent = 0;
229 char indentstr[10] = ""; 229 char indentstr[10] = "";
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
deleted file mode 100644
index 4d8ed3d71a15..000000000000
--- a/drivers/usb/input/hid-core.c
+++ /dev/null
@@ -1,1459 +0,0 @@
1/*
2 * USB HID support for Linux
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006 Jiri Kosina
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>
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
30#undef DEBUG
31#undef DEBUG_DATA
32
33#include <linux/usb.h>
34
35#include <linux/hid.h>
36#include <linux/hiddev.h>
37#include <linux/hid-debug.h>
38#include "usbhid.h"
39
40/*
41 * Version Information
42 */
43
44#define DRIVER_VERSION "v2.6"
45#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
46#define DRIVER_DESC "USB HID core driver"
47#define DRIVER_LICENSE "GPL"
48
49static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick",
50 "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"};
51/*
52 * Module parameters.
53 */
54
55static unsigned int hid_mousepoll_interval;
56module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
57MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
58
59/*
60 * Input submission and I/O error handler.
61 */
62
63static void hid_io_error(struct hid_device *hid);
64
65/* Start up the input URB */
66static int hid_start_in(struct hid_device *hid)
67{
68 unsigned long flags;
69 int rc = 0;
70 struct usbhid_device *usbhid = hid->driver_data;
71
72 spin_lock_irqsave(&usbhid->inlock, flags);
73 if (hid->open > 0 && !test_bit(HID_SUSPENDED, &usbhid->iofl) &&
74 !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) {
75 rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC);
76 if (rc != 0)
77 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
78 }
79 spin_unlock_irqrestore(&usbhid->inlock, flags);
80 return rc;
81}
82
83/* I/O retry timer routine */
84static void hid_retry_timeout(unsigned long _hid)
85{
86 struct hid_device *hid = (struct hid_device *) _hid;
87 struct usbhid_device *usbhid = hid->driver_data;
88
89 dev_dbg(&usbhid->intf->dev, "retrying intr urb\n");
90 if (hid_start_in(hid))
91 hid_io_error(hid);
92}
93
94/* Workqueue routine to reset the device or clear a halt */
95static void hid_reset(struct work_struct *work)
96{
97 struct usbhid_device *usbhid =
98 container_of(work, struct usbhid_device, reset_work);
99 struct hid_device *hid = usbhid->hid;
100 int rc_lock, rc = 0;
101
102 if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) {
103 dev_dbg(&usbhid->intf->dev, "clear halt\n");
104 rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe);
105 clear_bit(HID_CLEAR_HALT, &usbhid->iofl);
106 hid_start_in(hid);
107 }
108
109 else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) {
110 dev_dbg(&usbhid->intf->dev, "resetting device\n");
111 rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf);
112 if (rc_lock >= 0) {
113 rc = usb_reset_composite_device(hid_to_usb_dev(hid), usbhid->intf);
114 if (rc_lock)
115 usb_unlock_device(hid_to_usb_dev(hid));
116 }
117 clear_bit(HID_RESET_PENDING, &usbhid->iofl);
118 }
119
120 switch (rc) {
121 case 0:
122 if (!test_bit(HID_IN_RUNNING, &usbhid->iofl))
123 hid_io_error(hid);
124 break;
125 default:
126 err("can't reset device, %s-%s/input%d, status %d",
127 hid_to_usb_dev(hid)->bus->bus_name,
128 hid_to_usb_dev(hid)->devpath,
129 usbhid->ifnum, rc);
130 /* FALLTHROUGH */
131 case -EHOSTUNREACH:
132 case -ENODEV:
133 case -EINTR:
134 break;
135 }
136}
137
138/* Main I/O error handler */
139static void hid_io_error(struct hid_device *hid)
140{
141 unsigned long flags;
142 struct usbhid_device *usbhid = hid->driver_data;
143
144 spin_lock_irqsave(&usbhid->inlock, flags);
145
146 /* Stop when disconnected */
147 if (usb_get_intfdata(usbhid->intf) == NULL)
148 goto done;
149
150 /* When an error occurs, retry at increasing intervals */
151 if (usbhid->retry_delay == 0) {
152 usbhid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */
153 usbhid->stop_retry = jiffies + msecs_to_jiffies(1000);
154 } else if (usbhid->retry_delay < 100)
155 usbhid->retry_delay *= 2;
156
157 if (time_after(jiffies, usbhid->stop_retry)) {
158
159 /* Retries failed, so do a port reset */
160 if (!test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) {
161 schedule_work(&usbhid->reset_work);
162 goto done;
163 }
164 }
165
166 mod_timer(&usbhid->io_retry,
167 jiffies + msecs_to_jiffies(usbhid->retry_delay));
168done:
169 spin_unlock_irqrestore(&usbhid->inlock, flags);
170}
171
172/*
173 * Input interrupt completion handler.
174 */
175
176static void hid_irq_in(struct urb *urb)
177{
178 struct hid_device *hid = urb->context;
179 struct usbhid_device *usbhid = hid->driver_data;
180 int status;
181
182 switch (urb->status) {
183 case 0: /* success */
184 usbhid->retry_delay = 0;
185 hid_input_report(urb->context, HID_INPUT_REPORT,
186 urb->transfer_buffer,
187 urb->actual_length, 1);
188 break;
189 case -EPIPE: /* stall */
190 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
191 set_bit(HID_CLEAR_HALT, &usbhid->iofl);
192 schedule_work(&usbhid->reset_work);
193 return;
194 case -ECONNRESET: /* unlink */
195 case -ENOENT:
196 case -ESHUTDOWN: /* unplug */
197 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
198 return;
199 case -EILSEQ: /* protocol error or unplug */
200 case -EPROTO: /* protocol error or unplug */
201 case -ETIME: /* protocol error or unplug */
202 case -ETIMEDOUT: /* Should never happen, but... */
203 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
204 hid_io_error(hid);
205 return;
206 default: /* error */
207 warn("input irq status %d received", urb->status);
208 }
209
210 status = usb_submit_urb(urb, GFP_ATOMIC);
211 if (status) {
212 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
213 if (status != -EPERM) {
214 err("can't resubmit intr, %s-%s/input%d, status %d",
215 hid_to_usb_dev(hid)->bus->bus_name,
216 hid_to_usb_dev(hid)->devpath,
217 usbhid->ifnum, status);
218 hid_io_error(hid);
219 }
220 }
221}
222
223static int hid_submit_out(struct hid_device *hid)
224{
225 struct hid_report *report;
226 struct usbhid_device *usbhid = hid->driver_data;
227
228 report = usbhid->out[usbhid->outtail];
229
230 hid_output_report(report, usbhid->outbuf);
231 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
232 usbhid->urbout->dev = hid_to_usb_dev(hid);
233
234 dbg("submitting out urb");
235
236 if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) {
237 err("usb_submit_urb(out) failed");
238 return -1;
239 }
240
241 return 0;
242}
243
244static int hid_submit_ctrl(struct hid_device *hid)
245{
246 struct hid_report *report;
247 unsigned char dir;
248 int len;
249 struct usbhid_device *usbhid = hid->driver_data;
250
251 report = usbhid->ctrl[usbhid->ctrltail].report;
252 dir = usbhid->ctrl[usbhid->ctrltail].dir;
253
254 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
255 if (dir == USB_DIR_OUT) {
256 hid_output_report(report, usbhid->ctrlbuf);
257 usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0);
258 usbhid->urbctrl->transfer_buffer_length = len;
259 } else {
260 int maxpacket, padlen;
261
262 usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0);
263 maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0);
264 if (maxpacket > 0) {
265 padlen = (len + maxpacket - 1) / maxpacket;
266 padlen *= maxpacket;
267 if (padlen > usbhid->bufsize)
268 padlen = usbhid->bufsize;
269 } else
270 padlen = 0;
271 usbhid->urbctrl->transfer_buffer_length = padlen;
272 }
273 usbhid->urbctrl->dev = hid_to_usb_dev(hid);
274
275 usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
276 usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
277 usbhid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
278 usbhid->cr->wIndex = cpu_to_le16(usbhid->ifnum);
279 usbhid->cr->wLength = cpu_to_le16(len);
280
281 dbg("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u",
282 usbhid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report",
283 usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength);
284
285 if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) {
286 err("usb_submit_urb(ctrl) failed");
287 return -1;
288 }
289
290 return 0;
291}
292
293/*
294 * Output interrupt completion handler.
295 */
296
297static void hid_irq_out(struct urb *urb)
298{
299 struct hid_device *hid = urb->context;
300 struct usbhid_device *usbhid = hid->driver_data;
301 unsigned long flags;
302 int unplug = 0;
303
304 switch (urb->status) {
305 case 0: /* success */
306 break;
307 case -ESHUTDOWN: /* unplug */
308 unplug = 1;
309 case -EILSEQ: /* protocol error or unplug */
310 case -EPROTO: /* protocol error or unplug */
311 case -ECONNRESET: /* unlink */
312 case -ENOENT:
313 break;
314 default: /* error */
315 warn("output irq status %d received", urb->status);
316 }
317
318 spin_lock_irqsave(&usbhid->outlock, flags);
319
320 if (unplug)
321 usbhid->outtail = usbhid->outhead;
322 else
323 usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1);
324
325 if (usbhid->outhead != usbhid->outtail) {
326 if (hid_submit_out(hid)) {
327 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
328 wake_up(&hid->wait);
329 }
330 spin_unlock_irqrestore(&usbhid->outlock, flags);
331 return;
332 }
333
334 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
335 spin_unlock_irqrestore(&usbhid->outlock, flags);
336 wake_up(&hid->wait);
337}
338
339/*
340 * Control pipe completion handler.
341 */
342
343static void hid_ctrl(struct urb *urb)
344{
345 struct hid_device *hid = urb->context;
346 struct usbhid_device *usbhid = hid->driver_data;
347 unsigned long flags;
348 int unplug = 0;
349
350 spin_lock_irqsave(&usbhid->ctrllock, flags);
351
352 switch (urb->status) {
353 case 0: /* success */
354 if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN)
355 hid_input_report(urb->context, usbhid->ctrl[usbhid->ctrltail].report->type,
356 urb->transfer_buffer, urb->actual_length, 0);
357 break;
358 case -ESHUTDOWN: /* unplug */
359 unplug = 1;
360 case -EILSEQ: /* protocol error or unplug */
361 case -EPROTO: /* protocol error or unplug */
362 case -ECONNRESET: /* unlink */
363 case -ENOENT:
364 case -EPIPE: /* report not available */
365 break;
366 default: /* error */
367 warn("ctrl urb status %d received", urb->status);
368 }
369
370 if (unplug)
371 usbhid->ctrltail = usbhid->ctrlhead;
372 else
373 usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
374
375 if (usbhid->ctrlhead != usbhid->ctrltail) {
376 if (hid_submit_ctrl(hid)) {
377 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
378 wake_up(&hid->wait);
379 }
380 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
381 return;
382 }
383
384 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
385 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
386 wake_up(&hid->wait);
387}
388
389void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir)
390{
391 int head;
392 unsigned long flags;
393 struct usbhid_device *usbhid = hid->driver_data;
394
395 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
396 return;
397
398 if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
399
400 spin_lock_irqsave(&usbhid->outlock, flags);
401
402 if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) {
403 spin_unlock_irqrestore(&usbhid->outlock, flags);
404 warn("output queue full");
405 return;
406 }
407
408 usbhid->out[usbhid->outhead] = report;
409 usbhid->outhead = head;
410
411 if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl))
412 if (hid_submit_out(hid))
413 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
414
415 spin_unlock_irqrestore(&usbhid->outlock, flags);
416 return;
417 }
418
419 spin_lock_irqsave(&usbhid->ctrllock, flags);
420
421 if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) {
422 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
423 warn("control queue full");
424 return;
425 }
426
427 usbhid->ctrl[usbhid->ctrlhead].report = report;
428 usbhid->ctrl[usbhid->ctrlhead].dir = dir;
429 usbhid->ctrlhead = head;
430
431 if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl))
432 if (hid_submit_ctrl(hid))
433 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
434
435 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
436}
437
438static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
439{
440 struct hid_device *hid = dev->private;
441 struct hid_field *field;
442 int offset;
443
444 if (type == EV_FF)
445 return input_ff_event(dev, type, code, value);
446
447 if (type != EV_LED)
448 return -1;
449
450 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
451 warn("event field not found");
452 return -1;
453 }
454
455 hid_set_field(field, offset, value);
456 usbhid_submit_report(hid, field->report, USB_DIR_OUT);
457
458 return 0;
459}
460
461int usbhid_wait_io(struct hid_device *hid)
462{
463 struct usbhid_device *usbhid = hid->driver_data;
464
465 if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) &&
466 !test_bit(HID_OUT_RUNNING, &usbhid->iofl)),
467 10*HZ)) {
468 dbg("timeout waiting for ctrl or out queue to clear");
469 return -1;
470 }
471
472 return 0;
473}
474
475static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle)
476{
477 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
478 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report,
479 ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
480}
481
482static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
483 unsigned char type, void *buf, int size)
484{
485 int result, retries = 4;
486
487 memset(buf, 0, size);
488
489 do {
490 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
491 USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN,
492 (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT);
493 retries--;
494 } while (result < size && retries);
495 return result;
496}
497
498int usbhid_open(struct hid_device *hid)
499{
500 ++hid->open;
501 if (hid_start_in(hid))
502 hid_io_error(hid);
503 return 0;
504}
505
506void usbhid_close(struct hid_device *hid)
507{
508 struct usbhid_device *usbhid = hid->driver_data;
509
510 if (!--hid->open)
511 usb_kill_urb(usbhid->urbin);
512}
513
514#define USB_VENDOR_ID_PANJIT 0x134c
515
516#define USB_VENDOR_ID_TURBOX 0x062a
517#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
518
519/*
520 * Initialize all reports
521 */
522
523void usbhid_init_reports(struct hid_device *hid)
524{
525 struct hid_report *report;
526 struct usbhid_device *usbhid = hid->driver_data;
527 int err, ret;
528
529 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
530 usbhid_submit_report(hid, report, USB_DIR_IN);
531
532 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
533 usbhid_submit_report(hid, report, USB_DIR_IN);
534
535 err = 0;
536 ret = usbhid_wait_io(hid);
537 while (ret) {
538 err |= ret;
539 if (test_bit(HID_CTRL_RUNNING, &usbhid->iofl))
540 usb_kill_urb(usbhid->urbctrl);
541 if (test_bit(HID_OUT_RUNNING, &usbhid->iofl))
542 usb_kill_urb(usbhid->urbout);
543 ret = usbhid_wait_io(hid);
544 }
545
546 if (err)
547 warn("timeout initializing reports");
548}
549
550#define USB_VENDOR_ID_GTCO 0x078c
551#define USB_VENDOR_ID_GTCO_IPANEL_2 0x5543
552#define USB_DEVICE_ID_GTCO_90 0x0090
553#define USB_DEVICE_ID_GTCO_100 0x0100
554#define USB_DEVICE_ID_GTCO_101 0x0101
555#define USB_DEVICE_ID_GTCO_103 0x0103
556#define USB_DEVICE_ID_GTCO_104 0x0104
557#define USB_DEVICE_ID_GTCO_105 0x0105
558#define USB_DEVICE_ID_GTCO_106 0x0106
559#define USB_DEVICE_ID_GTCO_107 0x0107
560#define USB_DEVICE_ID_GTCO_108 0x0108
561#define USB_DEVICE_ID_GTCO_200 0x0200
562#define USB_DEVICE_ID_GTCO_201 0x0201
563#define USB_DEVICE_ID_GTCO_202 0x0202
564#define USB_DEVICE_ID_GTCO_203 0x0203
565#define USB_DEVICE_ID_GTCO_204 0x0204
566#define USB_DEVICE_ID_GTCO_205 0x0205
567#define USB_DEVICE_ID_GTCO_206 0x0206
568#define USB_DEVICE_ID_GTCO_207 0x0207
569#define USB_DEVICE_ID_GTCO_300 0x0300
570#define USB_DEVICE_ID_GTCO_301 0x0301
571#define USB_DEVICE_ID_GTCO_302 0x0302
572#define USB_DEVICE_ID_GTCO_303 0x0303
573#define USB_DEVICE_ID_GTCO_304 0x0304
574#define USB_DEVICE_ID_GTCO_305 0x0305
575#define USB_DEVICE_ID_GTCO_306 0x0306
576#define USB_DEVICE_ID_GTCO_307 0x0307
577#define USB_DEVICE_ID_GTCO_308 0x0308
578#define USB_DEVICE_ID_GTCO_309 0x0309
579#define USB_DEVICE_ID_GTCO_400 0x0400
580#define USB_DEVICE_ID_GTCO_401 0x0401
581#define USB_DEVICE_ID_GTCO_402 0x0402
582#define USB_DEVICE_ID_GTCO_403 0x0403
583#define USB_DEVICE_ID_GTCO_404 0x0404
584#define USB_DEVICE_ID_GTCO_405 0x0405
585#define USB_DEVICE_ID_GTCO_500 0x0500
586#define USB_DEVICE_ID_GTCO_501 0x0501
587#define USB_DEVICE_ID_GTCO_502 0x0502
588#define USB_DEVICE_ID_GTCO_503 0x0503
589#define USB_DEVICE_ID_GTCO_504 0x0504
590#define USB_DEVICE_ID_GTCO_1000 0x1000
591#define USB_DEVICE_ID_GTCO_1001 0x1001
592#define USB_DEVICE_ID_GTCO_1002 0x1002
593#define USB_DEVICE_ID_GTCO_1003 0x1003
594#define USB_DEVICE_ID_GTCO_1004 0x1004
595#define USB_DEVICE_ID_GTCO_1005 0x1005
596#define USB_DEVICE_ID_GTCO_1006 0x1006
597#define USB_DEVICE_ID_GTCO_8 0x0008
598#define USB_DEVICE_ID_GTCO_d 0x000d
599
600#define USB_VENDOR_ID_WACOM 0x056a
601
602#define USB_VENDOR_ID_ACECAD 0x0460
603#define USB_DEVICE_ID_ACECAD_FLAIR 0x0004
604#define USB_DEVICE_ID_ACECAD_302 0x0008
605
606#define USB_VENDOR_ID_KBGEAR 0x084e
607#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001
608
609#define USB_VENDOR_ID_AIPTEK 0x08ca
610#define USB_DEVICE_ID_AIPTEK_01 0x0001
611#define USB_DEVICE_ID_AIPTEK_10 0x0010
612#define USB_DEVICE_ID_AIPTEK_20 0x0020
613#define USB_DEVICE_ID_AIPTEK_21 0x0021
614#define USB_DEVICE_ID_AIPTEK_22 0x0022
615#define USB_DEVICE_ID_AIPTEK_23 0x0023
616#define USB_DEVICE_ID_AIPTEK_24 0x0024
617
618#define USB_VENDOR_ID_GRIFFIN 0x077d
619#define USB_DEVICE_ID_POWERMATE 0x0410
620#define USB_DEVICE_ID_SOUNDKNOB 0x04AA
621
622#define USB_VENDOR_ID_ATEN 0x0557
623#define USB_DEVICE_ID_ATEN_UC100KM 0x2004
624#define USB_DEVICE_ID_ATEN_CS124U 0x2202
625#define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204
626#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205
627#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208
628
629#define USB_VENDOR_ID_TOPMAX 0x0663
630#define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103
631
632#define USB_VENDOR_ID_HAPP 0x078b
633#define USB_DEVICE_ID_UGCI_DRIVING 0x0010
634#define USB_DEVICE_ID_UGCI_FLYING 0x0020
635#define USB_DEVICE_ID_UGCI_FIGHTING 0x0030
636
637#define USB_VENDOR_ID_MGE 0x0463
638#define USB_DEVICE_ID_MGE_UPS 0xffff
639#define USB_DEVICE_ID_MGE_UPS1 0x0001
640
641#define USB_VENDOR_ID_ONTRAK 0x0a07
642#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
643
644#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f
645#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100
646
647#define USB_VENDOR_ID_A4TECH 0x09da
648#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
649
650#define USB_VENDOR_ID_AASHIMA 0x06d6
651#define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025
652#define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026
653
654#define USB_VENDOR_ID_CYPRESS 0x04b4
655#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001
656#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500
657#define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417
658
659#define USB_VENDOR_ID_BERKSHIRE 0x0c98
660#define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140
661
662#define USB_VENDOR_ID_ALPS 0x0433
663#define USB_DEVICE_ID_IBM_GAMEPAD 0x1101
664
665#define USB_VENDOR_ID_SAITEK 0x06a3
666#define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17
667
668#define USB_VENDOR_ID_NEC 0x073e
669#define USB_DEVICE_ID_NEC_USB_GAME_PAD 0x0301
670
671#define USB_VENDOR_ID_CHIC 0x05fe
672#define USB_DEVICE_ID_CHIC_GAMEPAD 0x0014
673
674#define USB_VENDOR_ID_GLAB 0x06c2
675#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
676#define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039
677#define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040
678#define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044
679#define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045
680#define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051
681#define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053
682#define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058
683
684#define USB_VENDOR_ID_WISEGROUP 0x0925
685#define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101
686#define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104
687#define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201
688#define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866
689
690#define USB_VENDOR_ID_WISEGROUP_LTD 0x6677
691#define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802
692
693#define USB_VENDOR_ID_CODEMERCS 0x07c0
694#define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500
695#define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501
696#define USB_DEVICE_ID_CODEMERCS_IOW48 0x1502
697#define USB_DEVICE_ID_CODEMERCS_IOW28 0x1503
698
699#define USB_VENDOR_ID_DELORME 0x1163
700#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100
701#define USB_DEVICE_ID_DELORME_EM_LT20 0x0200
702
703#define USB_VENDOR_ID_MCC 0x09db
704#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076
705#define USB_DEVICE_ID_MCC_PMD1208LS 0x007a
706
707#define USB_VENDOR_ID_VERNIER 0x08f7
708#define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
709#define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
710#define USB_DEVICE_ID_VERNIER_SKIP 0x0003
711#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
712
713#define USB_VENDOR_ID_LD 0x0f11
714#define USB_DEVICE_ID_LD_CASSY 0x1000
715#define USB_DEVICE_ID_LD_POCKETCASSY 0x1010
716#define USB_DEVICE_ID_LD_MOBILECASSY 0x1020
717#define USB_DEVICE_ID_LD_JWM 0x1080
718#define USB_DEVICE_ID_LD_DMMP 0x1081
719#define USB_DEVICE_ID_LD_UMIP 0x1090
720#define USB_DEVICE_ID_LD_XRAY1 0x1100
721#define USB_DEVICE_ID_LD_XRAY2 0x1101
722#define USB_DEVICE_ID_LD_VIDEOCOM 0x1200
723#define USB_DEVICE_ID_LD_COM3LAB 0x2000
724#define USB_DEVICE_ID_LD_TELEPORT 0x2010
725#define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020
726#define USB_DEVICE_ID_LD_POWERCONTROL 0x2030
727#define USB_DEVICE_ID_LD_MACHINETEST 0x2040
728
729#define USB_VENDOR_ID_APPLE 0x05ac
730#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
731#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e
732#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f
733#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
734#define USB_DEVICE_ID_APPLE_GEYSER_ISO 0x0215
735#define USB_DEVICE_ID_APPLE_GEYSER_JIS 0x0216
736#define USB_DEVICE_ID_APPLE_GEYSER3_ANSI 0x0217
737#define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218
738#define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219
739#define USB_DEVICE_ID_APPLE_GEYSER4_ANSI 0x021a
740#define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b
741#define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c
742#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
743#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
744#define USB_DEVICE_ID_APPLE_IR 0x8240
745
746#define USB_VENDOR_ID_CHERRY 0x046a
747#define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023
748
749#define USB_VENDOR_ID_YEALINK 0x6993
750#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001
751
752#define USB_VENDOR_ID_ALCOR 0x058f
753#define USB_DEVICE_ID_ALCOR_USBRS232 0x9720
754
755#define USB_VENDOR_ID_SUN 0x0430
756#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
757
758#define USB_VENDOR_ID_AIRCABLE 0x16CA
759#define USB_DEVICE_ID_AIRCABLE1 0x1502
760
761#define USB_VENDOR_ID_LOGITECH 0x046d
762#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101
763
764#define USB_VENDOR_ID_IMATION 0x0718
765#define USB_DEVICE_ID_DISC_STAKKA 0xd000
766
767#define USB_VENDOR_ID_PANTHERLORD 0x0810
768#define USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK 0x0001
769
770#define USB_VENDOR_ID_SONY 0x054c
771#define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268
772
773/*
774 * Alphabetically sorted blacklist by quirk type.
775 */
776
777static const struct hid_blacklist {
778 __u16 idVendor;
779 __u16 idProduct;
780 unsigned quirks;
781} hid_blacklist[] = {
782
783 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE },
784 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE },
785 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE },
786 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21, HID_QUIRK_IGNORE },
787 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE },
788 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE },
789 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE },
790 { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE },
791 { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE },
792 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE },
793 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE },
794 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24, HID_QUIRK_IGNORE },
795 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE },
796 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE },
797 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE },
798 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE },
799 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE },
800 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE },
801 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE },
802 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
803 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
804 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE },
805 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT, HID_QUIRK_IGNORE },
806 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE },
807 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT, HID_QUIRK_IGNORE },
808 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE },
809 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL, HID_QUIRK_IGNORE },
810 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE },
811 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE },
812 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE },
813 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100, HID_QUIRK_IGNORE },
814 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101, HID_QUIRK_IGNORE },
815 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103, HID_QUIRK_IGNORE },
816 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104, HID_QUIRK_IGNORE },
817 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105, HID_QUIRK_IGNORE },
818 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106, HID_QUIRK_IGNORE },
819 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107, HID_QUIRK_IGNORE },
820 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108, HID_QUIRK_IGNORE },
821 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200, HID_QUIRK_IGNORE },
822 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201, HID_QUIRK_IGNORE },
823 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202, HID_QUIRK_IGNORE },
824 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203, HID_QUIRK_IGNORE },
825 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204, HID_QUIRK_IGNORE },
826 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205, HID_QUIRK_IGNORE },
827 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206, HID_QUIRK_IGNORE },
828 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207, HID_QUIRK_IGNORE },
829 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300, HID_QUIRK_IGNORE },
830 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301, HID_QUIRK_IGNORE },
831 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302, HID_QUIRK_IGNORE },
832 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303, HID_QUIRK_IGNORE },
833 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304, HID_QUIRK_IGNORE },
834 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305, HID_QUIRK_IGNORE },
835 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306, HID_QUIRK_IGNORE },
836 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307, HID_QUIRK_IGNORE },
837 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308, HID_QUIRK_IGNORE },
838 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309, HID_QUIRK_IGNORE },
839 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400, HID_QUIRK_IGNORE },
840 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401, HID_QUIRK_IGNORE },
841 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402, HID_QUIRK_IGNORE },
842 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403, HID_QUIRK_IGNORE },
843 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404, HID_QUIRK_IGNORE },
844 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405, HID_QUIRK_IGNORE },
845 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500, HID_QUIRK_IGNORE },
846 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501, HID_QUIRK_IGNORE },
847 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE },
848 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE },
849 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE },
850 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE },
851 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE },
852 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE },
853 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003, HID_QUIRK_IGNORE },
854 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
855 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
856 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
857 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_8, HID_QUIRK_IGNORE },
858 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_d, HID_QUIRK_IGNORE },
859 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE },
860 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
861 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
862 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE },
863 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY, HID_QUIRK_IGNORE },
864 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM, HID_QUIRK_IGNORE },
865 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP, HID_QUIRK_IGNORE },
866 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP, HID_QUIRK_IGNORE },
867 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1, HID_QUIRK_IGNORE },
868 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2, HID_QUIRK_IGNORE },
869 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM, HID_QUIRK_IGNORE },
870 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB, HID_QUIRK_IGNORE },
871 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT, HID_QUIRK_IGNORE },
872 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER, HID_QUIRK_IGNORE },
873 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL, HID_QUIRK_IGNORE },
874 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST, HID_QUIRK_IGNORE },
875 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE },
876 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE },
877 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE },
878 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE },
879 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE },
880 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20, HID_QUIRK_IGNORE },
881 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30, HID_QUIRK_IGNORE },
882 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE },
883 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108, HID_QUIRK_IGNORE },
884 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118, HID_QUIRK_IGNORE },
885 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE },
886 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE },
887 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE },
888 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE },
889 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO, HID_QUIRK_IGNORE },
890 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE },
891 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE },
892 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE },
893 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
894 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
895 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT, HID_QUIRK_IGNORE },
896 { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE },
897
898 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE },
899 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE },
900
901 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET },
902 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET },
903 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
904 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
905 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
906 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
907 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
908 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
909
910 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL },
911 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
912 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 },
913
914 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD },
915 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD },
916 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD },
917 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
918 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
919 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
920 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
921 { USB_VENDOR_ID_NEC, USB_DEVICE_ID_NEC_USB_GAME_PAD, HID_QUIRK_BADPAD },
922 { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
923 { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
924
925 { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION },
926
927 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
928 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
929 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
930 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
931 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
932 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
933 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
934 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
935 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
936 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
937 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
938 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
939 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
940
941 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IR, HID_QUIRK_IGNORE },
942
943 { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE },
944 { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE },
945 { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE },
946 { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE },
947
948 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
949
950 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_USB_RECEIVER, HID_QUIRK_BAD_RELATIVE_KEYS },
951
952 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS },
953
954 { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER },
955
956 { 0, 0 }
957};
958
959/*
960 * Traverse the supplied list of reports and find the longest
961 */
962static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max)
963{
964 struct hid_report *report;
965 int size;
966
967 list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
968 size = ((report->size - 1) >> 3) + 1;
969 if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered)
970 size++;
971 if (*max < size)
972 *max = size;
973 }
974}
975
976static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
977{
978 struct usbhid_device *usbhid = hid->driver_data;
979
980 if (!(usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->inbuf_dma)))
981 return -1;
982 if (!(usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->outbuf_dma)))
983 return -1;
984 if (!(usbhid->cr = usb_buffer_alloc(dev, sizeof(*(usbhid->cr)), GFP_ATOMIC, &usbhid->cr_dma)))
985 return -1;
986 if (!(usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->ctrlbuf_dma)))
987 return -1;
988
989 return 0;
990}
991
992static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
993{
994 struct usbhid_device *usbhid = hid->driver_data;
995
996 if (usbhid->inbuf)
997 usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma);
998 if (usbhid->outbuf)
999 usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma);
1000 if (usbhid->cr)
1001 usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma);
1002 if (usbhid->ctrlbuf)
1003 usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
1004}
1005
1006/*
1007 * Cherry Cymotion keyboard have an invalid HID report descriptor,
1008 * that needs fixing before we can parse it.
1009 */
1010
1011static void hid_fixup_cymotion_descriptor(char *rdesc, int rsize)
1012{
1013 if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
1014 info("Fixing up Cherry Cymotion report descriptor");
1015 rdesc[11] = rdesc[16] = 0xff;
1016 rdesc[12] = rdesc[17] = 0x03;
1017 }
1018}
1019
1020/*
1021 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
1022 * to "operational". Without this, the ps3 controller will not report any
1023 * events.
1024 */
1025static void hid_fixup_sony_ps3_controller(struct usb_device *dev, int ifnum)
1026{
1027 int result;
1028 char *buf = kmalloc(18, GFP_KERNEL);
1029
1030 if (!buf)
1031 return;
1032
1033 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
1034 HID_REQ_GET_REPORT,
1035 USB_DIR_IN | USB_TYPE_CLASS |
1036 USB_RECIP_INTERFACE,
1037 (3 << 8) | 0xf2, ifnum, buf, 17,
1038 USB_CTRL_GET_TIMEOUT);
1039
1040 if (result < 0)
1041 err("%s failed: %d\n", __func__, result);
1042
1043 kfree(buf);
1044}
1045
1046static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1047{
1048 struct usb_host_interface *interface = intf->cur_altsetting;
1049 struct usb_device *dev = interface_to_usbdev (intf);
1050 struct hid_descriptor *hdesc;
1051 struct hid_device *hid;
1052 unsigned quirks = 0, rsize = 0;
1053 char *rdesc;
1054 int n, len, insize = 0;
1055 struct usbhid_device *usbhid;
1056
1057 /* Ignore all Wacom devices */
1058 if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM)
1059 return NULL;
1060
1061 for (n = 0; hid_blacklist[n].idVendor; n++)
1062 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) &&
1063 (hid_blacklist[n].idProduct == le16_to_cpu(dev->descriptor.idProduct)))
1064 quirks = hid_blacklist[n].quirks;
1065
1066 /* Many keyboards and mice don't like to be polled for reports,
1067 * so we will always set the HID_QUIRK_NOGET flag for them. */
1068 if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
1069 if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||
1070 interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
1071 quirks |= HID_QUIRK_NOGET;
1072 }
1073
1074 if (quirks & HID_QUIRK_IGNORE)
1075 return NULL;
1076
1077 if ((quirks & HID_QUIRK_IGNORE_MOUSE) &&
1078 (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE))
1079 return NULL;
1080
1081
1082 if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&
1083 (!interface->desc.bNumEndpoints ||
1084 usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {
1085 dbg("class descriptor not present\n");
1086 return NULL;
1087 }
1088
1089 for (n = 0; n < hdesc->bNumDescriptors; n++)
1090 if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)
1091 rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
1092
1093 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
1094 dbg("weird size of report descriptor (%u)", rsize);
1095 return NULL;
1096 }
1097
1098 if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) {
1099 dbg("couldn't allocate rdesc memory");
1100 return NULL;
1101 }
1102
1103 hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
1104
1105 if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) {
1106 dbg("reading report descriptor failed");
1107 kfree(rdesc);
1108 return NULL;
1109 }
1110
1111 if ((quirks & HID_QUIRK_CYMOTION))
1112 hid_fixup_cymotion_descriptor(rdesc, rsize);
1113
1114#ifdef DEBUG_DATA
1115 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n);
1116 for (n = 0; n < rsize; n++)
1117 printk(" %02x", (unsigned char) rdesc[n]);
1118 printk("\n");
1119#endif
1120
1121 if (!(hid = hid_parse_report(rdesc, n))) {
1122 dbg("parsing report descriptor failed");
1123 kfree(rdesc);
1124 return NULL;
1125 }
1126
1127 kfree(rdesc);
1128 hid->quirks = quirks;
1129
1130 if (!(usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL)))
1131 goto fail;
1132
1133 hid->driver_data = usbhid;
1134 usbhid->hid = hid;
1135
1136 usbhid->bufsize = HID_MIN_BUFFER_SIZE;
1137 hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize);
1138 hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize);
1139 hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize);
1140
1141 if (usbhid->bufsize > HID_MAX_BUFFER_SIZE)
1142 usbhid->bufsize = HID_MAX_BUFFER_SIZE;
1143
1144 hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
1145
1146 if (insize > HID_MAX_BUFFER_SIZE)
1147 insize = HID_MAX_BUFFER_SIZE;
1148
1149 if (hid_alloc_buffers(dev, hid)) {
1150 hid_free_buffers(dev, hid);
1151 goto fail;
1152 }
1153
1154 for (n = 0; n < interface->desc.bNumEndpoints; n++) {
1155
1156 struct usb_endpoint_descriptor *endpoint;
1157 int pipe;
1158 int interval;
1159
1160 endpoint = &interface->endpoint[n].desc;
1161 if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */
1162 continue;
1163
1164 interval = endpoint->bInterval;
1165
1166 /* Change the polling interval of mice. */
1167 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
1168 interval = hid_mousepoll_interval;
1169
1170 if (usb_endpoint_dir_in(endpoint)) {
1171 if (usbhid->urbin)
1172 continue;
1173 if (!(usbhid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
1174 goto fail;
1175 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
1176 usb_fill_int_urb(usbhid->urbin, dev, pipe, usbhid->inbuf, insize,
1177 hid_irq_in, hid, interval);
1178 usbhid->urbin->transfer_dma = usbhid->inbuf_dma;
1179 usbhid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1180 } else {
1181 if (usbhid->urbout)
1182 continue;
1183 if (!(usbhid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
1184 goto fail;
1185 pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress);
1186 usb_fill_int_urb(usbhid->urbout, dev, pipe, usbhid->outbuf, 0,
1187 hid_irq_out, hid, interval);
1188 usbhid->urbout->transfer_dma = usbhid->outbuf_dma;
1189 usbhid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1190 }
1191 }
1192
1193 if (!usbhid->urbin) {
1194 err("couldn't find an input interrupt endpoint");
1195 goto fail;
1196 }
1197
1198 init_waitqueue_head(&hid->wait);
1199
1200 INIT_WORK(&usbhid->reset_work, hid_reset);
1201 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
1202
1203 spin_lock_init(&usbhid->inlock);
1204 spin_lock_init(&usbhid->outlock);
1205 spin_lock_init(&usbhid->ctrllock);
1206
1207 hid->version = le16_to_cpu(hdesc->bcdHID);
1208 hid->country = hdesc->bCountryCode;
1209 hid->dev = &intf->dev;
1210 usbhid->intf = intf;
1211 usbhid->ifnum = interface->desc.bInterfaceNumber;
1212
1213 hid->name[0] = 0;
1214
1215 if (dev->manufacturer)
1216 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
1217
1218 if (dev->product) {
1219 if (dev->manufacturer)
1220 strlcat(hid->name, " ", sizeof(hid->name));
1221 strlcat(hid->name, dev->product, sizeof(hid->name));
1222 }
1223
1224 if (!strlen(hid->name))
1225 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
1226 le16_to_cpu(dev->descriptor.idVendor),
1227 le16_to_cpu(dev->descriptor.idProduct));
1228
1229 hid->bus = BUS_USB;
1230 hid->vendor = dev->descriptor.idVendor;
1231 hid->product = dev->descriptor.idProduct;
1232
1233 usb_make_path(dev, hid->phys, sizeof(hid->phys));
1234 strlcat(hid->phys, "/input", sizeof(hid->phys));
1235 len = strlen(hid->phys);
1236 if (len < sizeof(hid->phys) - 1)
1237 snprintf(hid->phys + len, sizeof(hid->phys) - len,
1238 "%d", intf->altsetting[0].desc.bInterfaceNumber);
1239
1240 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
1241 hid->uniq[0] = 0;
1242
1243 usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
1244 if (!usbhid->urbctrl)
1245 goto fail;
1246
1247 usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr,
1248 usbhid->ctrlbuf, 1, hid_ctrl, hid);
1249 usbhid->urbctrl->setup_dma = usbhid->cr_dma;
1250 usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma;
1251 usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
1252 hid->hidinput_input_event = usb_hidinput_input_event;
1253 hid->hid_open = usbhid_open;
1254 hid->hid_close = usbhid_close;
1255#ifdef CONFIG_USB_HIDDEV
1256 hid->hiddev_hid_event = hiddev_hid_event;
1257 hid->hiddev_report_event = hiddev_report_event;
1258#endif
1259 return hid;
1260
1261fail:
1262 usb_free_urb(usbhid->urbin);
1263 usb_free_urb(usbhid->urbout);
1264 usb_free_urb(usbhid->urbctrl);
1265 hid_free_buffers(dev, hid);
1266 hid_free_device(hid);
1267
1268 return NULL;
1269}
1270
1271static void hid_disconnect(struct usb_interface *intf)
1272{
1273 struct hid_device *hid = usb_get_intfdata (intf);
1274 struct usbhid_device *usbhid;
1275
1276 if (!hid)
1277 return;
1278
1279 usbhid = hid->driver_data;
1280
1281 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
1282 usb_set_intfdata(intf, NULL);
1283 spin_unlock_irq(&usbhid->inlock);
1284 usb_kill_urb(usbhid->urbin);
1285 usb_kill_urb(usbhid->urbout);
1286 usb_kill_urb(usbhid->urbctrl);
1287
1288 del_timer_sync(&usbhid->io_retry);
1289 flush_scheduled_work();
1290
1291 if (hid->claimed & HID_CLAIMED_INPUT)
1292 hidinput_disconnect(hid);
1293 if (hid->claimed & HID_CLAIMED_HIDDEV)
1294 hiddev_disconnect(hid);
1295
1296 usb_free_urb(usbhid->urbin);
1297 usb_free_urb(usbhid->urbctrl);
1298 usb_free_urb(usbhid->urbout);
1299
1300 hid_free_buffers(hid_to_usb_dev(hid), hid);
1301 hid_free_device(hid);
1302}
1303
1304static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
1305{
1306 struct hid_device *hid;
1307 char path[64];
1308 int i;
1309 char *c;
1310
1311 dbg("HID probe called for ifnum %d",
1312 intf->altsetting->desc.bInterfaceNumber);
1313
1314 if (!(hid = usb_hid_configure(intf)))
1315 return -ENODEV;
1316
1317 usbhid_init_reports(hid);
1318 hid_dump_device(hid);
1319
1320 if (!hidinput_connect(hid))
1321 hid->claimed |= HID_CLAIMED_INPUT;
1322 if (!hiddev_connect(hid))
1323 hid->claimed |= HID_CLAIMED_HIDDEV;
1324
1325 usb_set_intfdata(intf, hid);
1326
1327 if (!hid->claimed) {
1328 printk ("HID device not claimed by input or hiddev\n");
1329 hid_disconnect(intf);
1330 return -ENODEV;
1331 }
1332
1333 if ((hid->claimed & HID_CLAIMED_INPUT))
1334 hid_ff_init(hid);
1335
1336 if (hid->quirks & HID_QUIRK_SONY_PS3_CONTROLLER)
1337 hid_fixup_sony_ps3_controller(interface_to_usbdev(intf),
1338 intf->cur_altsetting->desc.bInterfaceNumber);
1339
1340 printk(KERN_INFO);
1341
1342 if (hid->claimed & HID_CLAIMED_INPUT)
1343 printk("input");
1344 if (hid->claimed == (HID_CLAIMED_INPUT | HID_CLAIMED_HIDDEV))
1345 printk(",");
1346 if (hid->claimed & HID_CLAIMED_HIDDEV)
1347 printk("hiddev%d", hid->minor);
1348
1349 c = "Device";
1350 for (i = 0; i < hid->maxcollection; i++) {
1351 if (hid->collection[i].type == HID_COLLECTION_APPLICATION &&
1352 (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1353 (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) {
1354 c = hid_types[hid->collection[i].usage & 0xffff];
1355 break;
1356 }
1357 }
1358
1359 usb_make_path(interface_to_usbdev(intf), path, 63);
1360
1361 printk(": USB HID v%x.%02x %s [%s] on %s\n",
1362 hid->version >> 8, hid->version & 0xff, c, hid->name, path);
1363
1364 return 0;
1365}
1366
1367static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1368{
1369 struct hid_device *hid = usb_get_intfdata (intf);
1370 struct usbhid_device *usbhid = hid->driver_data;
1371
1372 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
1373 set_bit(HID_SUSPENDED, &usbhid->iofl);
1374 spin_unlock_irq(&usbhid->inlock);
1375 del_timer(&usbhid->io_retry);
1376 usb_kill_urb(usbhid->urbin);
1377 dev_dbg(&intf->dev, "suspend\n");
1378 return 0;
1379}
1380
1381static int hid_resume(struct usb_interface *intf)
1382{
1383 struct hid_device *hid = usb_get_intfdata (intf);
1384 struct usbhid_device *usbhid = hid->driver_data;
1385 int status;
1386
1387 clear_bit(HID_SUSPENDED, &usbhid->iofl);
1388 usbhid->retry_delay = 0;
1389 status = hid_start_in(hid);
1390 dev_dbg(&intf->dev, "resume status %d\n", status);
1391 return status;
1392}
1393
1394/* Treat USB reset pretty much the same as suspend/resume */
1395static void hid_pre_reset(struct usb_interface *intf)
1396{
1397 /* FIXME: What if the interface is already suspended? */
1398 hid_suspend(intf, PMSG_ON);
1399}
1400
1401static void hid_post_reset(struct usb_interface *intf)
1402{
1403 struct usb_device *dev = interface_to_usbdev (intf);
1404
1405 hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0);
1406 /* FIXME: Any more reinitialization needed? */
1407
1408 hid_resume(intf);
1409}
1410
1411static struct usb_device_id hid_usb_ids [] = {
1412 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
1413 .bInterfaceClass = USB_INTERFACE_CLASS_HID },
1414 { } /* Terminating entry */
1415};
1416
1417MODULE_DEVICE_TABLE (usb, hid_usb_ids);
1418
1419static struct usb_driver hid_driver = {
1420 .name = "usbhid",
1421 .probe = hid_probe,
1422 .disconnect = hid_disconnect,
1423 .suspend = hid_suspend,
1424 .resume = hid_resume,
1425 .pre_reset = hid_pre_reset,
1426 .post_reset = hid_post_reset,
1427 .id_table = hid_usb_ids,
1428};
1429
1430static int __init hid_init(void)
1431{
1432 int retval;
1433 retval = hiddev_init();
1434 if (retval)
1435 goto hiddev_init_fail;
1436 retval = usb_register(&hid_driver);
1437 if (retval)
1438 goto usb_register_fail;
1439 info(DRIVER_VERSION ":" DRIVER_DESC);
1440
1441 return 0;
1442usb_register_fail:
1443 hiddev_exit();
1444hiddev_init_fail:
1445 return retval;
1446}
1447
1448static void __exit hid_exit(void)
1449{
1450 usb_deregister(&hid_driver);
1451 hiddev_exit();
1452}
1453
1454module_init(hid_init);
1455module_exit(hid_exit);
1456
1457MODULE_AUTHOR(DRIVER_AUTHOR);
1458MODULE_DESCRIPTION(DRIVER_DESC);
1459MODULE_LICENSE(DRIVER_LICENSE);
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
deleted file mode 100644
index e431faaa6abc..000000000000
--- a/drivers/usb/input/hid-ff.c
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * $Id: hid-ff.c,v 1.2 2002/04/18 22:02:47 jdeneux Exp $
3 *
4 * Force feedback support for hid devices.
5 * Not all hid devices use the same protocol. For example, some use PID,
6 * other use their own proprietary procotol.
7 *
8 * Copyright (c) 2002-2004 Johann Deneux
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Should you need to contact me, the author, you can do so by
27 * e-mail - mail your message to <johann.deneux@it.uu.se>
28 */
29
30#include <linux/input.h>
31
32#undef DEBUG
33#include <linux/usb.h>
34
35#include <linux/hid.h>
36#include "usbhid.h"
37
38/*
39 * This table contains pointers to initializers. To add support for new
40 * devices, you need to add the USB vendor and product ids here.
41 */
42struct hid_ff_initializer {
43 u16 idVendor;
44 u16 idProduct;
45 int (*init)(struct hid_device*);
46};
47
48/*
49 * We try pidff when no other driver is found because PID is the
50 * standards compliant way of implementing force feedback in HID.
51 * pidff_init() will quickly abort if the device doesn't appear to
52 * be a PID device
53 */
54static struct hid_ff_initializer inits[] = {
55#ifdef CONFIG_LOGITECH_FF
56 { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */
57 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
58 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */
59 { 0x46d, 0xc294, hid_lgff_init }, /* Logitech Formula Force EX */
60 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */
61 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */
62#endif
63#ifdef CONFIG_PANTHERLORD_FF
64 { 0x810, 0x0001, hid_plff_init },
65#endif
66#ifdef CONFIG_THRUSTMASTER_FF
67 { 0x44f, 0xb304, hid_tmff_init },
68#endif
69#ifdef CONFIG_ZEROPLUS_FF
70 { 0xc12, 0x0005, hid_zpff_init },
71 { 0xc12, 0x0030, hid_zpff_init },
72#endif
73 { 0, 0, hid_pidff_init} /* Matches anything */
74};
75
76int hid_ff_init(struct hid_device* hid)
77{
78 struct hid_ff_initializer *init;
79 int vendor = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idVendor);
80 int product = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idProduct);
81
82 for (init = inits; init->idVendor; init++)
83 if (init->idVendor == vendor && init->idProduct == product)
84 break;
85
86 return init->init(hid);
87}
88EXPORT_SYMBOL_GPL(hid_ff_init);
89
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
deleted file mode 100644
index e6f3af3e66d1..000000000000
--- a/drivers/usb/input/hid-lgff.c
+++ /dev/null
@@ -1,150 +0,0 @@
1/*
2 * Force feedback support for hid-compliant for some of the devices from
3 * Logitech, namely:
4 * - WingMan Cordless RumblePad
5 * - WingMan Force 3D
6 *
7 * Copyright (c) 2002-2004 Johann Deneux
8 * Copyright (c) 2006 Anssi Hannula <anssi.hannula@gmail.com>
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Should you need to contact me, the author, you can do so by
27 * e-mail - mail your message to <johann.deneux@it.uu.se>
28 */
29
30#include <linux/input.h>
31#include <linux/usb.h>
32#include <linux/hid.h>
33#include "usbhid.h"
34
35struct dev_type {
36 u16 idVendor;
37 u16 idProduct;
38 const signed short *ff;
39};
40
41static const signed short ff_rumble[] = {
42 FF_RUMBLE,
43 -1
44};
45
46static const signed short ff_joystick[] = {
47 FF_CONSTANT,
48 -1
49};
50
51static const struct dev_type devices[] = {
52 { 0x046d, 0xc211, ff_rumble },
53 { 0x046d, 0xc219, ff_rumble },
54 { 0x046d, 0xc283, ff_joystick },
55 { 0x046d, 0xc294, ff_joystick },
56 { 0x046d, 0xc295, ff_joystick },
57 { 0x046d, 0xca03, ff_joystick },
58};
59
60static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
61{
62 struct hid_device *hid = dev->private;
63 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
64 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
65 int x, y;
66 unsigned int left, right;
67
68#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
69
70 switch (effect->type) {
71 case FF_CONSTANT:
72 x = effect->u.ramp.start_level + 0x7f; /* 0x7f is center */
73 y = effect->u.ramp.end_level + 0x7f;
74 CLAMP(x);
75 CLAMP(y);
76 report->field[0]->value[0] = 0x51;
77 report->field[0]->value[1] = 0x08;
78 report->field[0]->value[2] = x;
79 report->field[0]->value[3] = y;
80 dbg("(x, y)=(%04x, %04x)", x, y);
81 usbhid_submit_report(hid, report, USB_DIR_OUT);
82 break;
83
84 case FF_RUMBLE:
85 right = effect->u.rumble.strong_magnitude;
86 left = effect->u.rumble.weak_magnitude;
87 right = right * 0xff / 0xffff;
88 left = left * 0xff / 0xffff;
89 CLAMP(left);
90 CLAMP(right);
91 report->field[0]->value[0] = 0x42;
92 report->field[0]->value[1] = 0x00;
93 report->field[0]->value[2] = left;
94 report->field[0]->value[3] = right;
95 dbg("(left, right)=(%04x, %04x)", left, right);
96 usbhid_submit_report(hid, report, USB_DIR_OUT);
97 break;
98 }
99 return 0;
100}
101
102int hid_lgff_init(struct hid_device* hid)
103{
104 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
105 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
106 struct input_dev *dev = hidinput->input;
107 struct hid_report *report;
108 struct hid_field *field;
109 const signed short *ff_bits = ff_joystick;
110 int error;
111 int i;
112
113 /* Find the report to use */
114 if (list_empty(report_list)) {
115 err("No output report found");
116 return -1;
117 }
118
119 /* Check that the report looks ok */
120 report = list_entry(report_list->next, struct hid_report, list);
121 if (!report) {
122 err("NULL output report");
123 return -1;
124 }
125
126 field = report->field[0];
127 if (!field) {
128 err("NULL field");
129 return -1;
130 }
131
132 for (i = 0; i < ARRAY_SIZE(devices); i++) {
133 if (dev->id.vendor == devices[i].idVendor &&
134 dev->id.product == devices[i].idProduct) {
135 ff_bits = devices[i].ff;
136 break;
137 }
138 }
139
140 for (i = 0; ff_bits[i] >= 0; i++)
141 set_bit(ff_bits[i], dev->ffbit);
142
143 error = input_ff_create_memless(dev, NULL, hid_lgff_play);
144 if (error)
145 return error;
146
147 printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n");
148
149 return 0;
150}
diff --git a/drivers/usb/input/hid-pidff.c b/drivers/usb/input/hid-pidff.c
deleted file mode 100644
index f5a90e950e6b..000000000000
--- a/drivers/usb/input/hid-pidff.c
+++ /dev/null
@@ -1,1331 +0,0 @@
1/*
2 * Force feedback driver for USB HID PID compliant devices
3 *
4 * Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23/* #define DEBUG */
24
25#define debug(format, arg...) pr_debug("hid-pidff: " format "\n" , ## arg)
26
27#include <linux/input.h>
28#include <linux/usb.h>
29
30#include <linux/hid.h>
31
32#include "usbhid.h"
33
34#define PID_EFFECTS_MAX 64
35
36/* Report usage table used to put reports into an array */
37
38#define PID_SET_EFFECT 0
39#define PID_EFFECT_OPERATION 1
40#define PID_DEVICE_GAIN 2
41#define PID_POOL 3
42#define PID_BLOCK_LOAD 4
43#define PID_BLOCK_FREE 5
44#define PID_DEVICE_CONTROL 6
45#define PID_CREATE_NEW_EFFECT 7
46
47#define PID_REQUIRED_REPORTS 7
48
49#define PID_SET_ENVELOPE 8
50#define PID_SET_CONDITION 9
51#define PID_SET_PERIODIC 10
52#define PID_SET_CONSTANT 11
53#define PID_SET_RAMP 12
54static const u8 pidff_reports[] = {
55 0x21, 0x77, 0x7d, 0x7f, 0x89, 0x90, 0x96, 0xab,
56 0x5a, 0x5f, 0x6e, 0x73, 0x74
57};
58
59/* device_control is really 0x95, but 0x96 specified as it is the usage of
60the only field in that report */
61
62/* Value usage tables used to put fields and values into arrays */
63
64#define PID_EFFECT_BLOCK_INDEX 0
65
66#define PID_DURATION 1
67#define PID_GAIN 2
68#define PID_TRIGGER_BUTTON 3
69#define PID_TRIGGER_REPEAT_INT 4
70#define PID_DIRECTION_ENABLE 5
71#define PID_START_DELAY 6
72static const u8 pidff_set_effect[] = {
73 0x22, 0x50, 0x52, 0x53, 0x54, 0x56, 0xa7
74};
75
76#define PID_ATTACK_LEVEL 1
77#define PID_ATTACK_TIME 2
78#define PID_FADE_LEVEL 3
79#define PID_FADE_TIME 4
80static const u8 pidff_set_envelope[] = { 0x22, 0x5b, 0x5c, 0x5d, 0x5e };
81
82#define PID_PARAM_BLOCK_OFFSET 1
83#define PID_CP_OFFSET 2
84#define PID_POS_COEFFICIENT 3
85#define PID_NEG_COEFFICIENT 4
86#define PID_POS_SATURATION 5
87#define PID_NEG_SATURATION 6
88#define PID_DEAD_BAND 7
89static const u8 pidff_set_condition[] = {
90 0x22, 0x23, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65
91};
92
93#define PID_MAGNITUDE 1
94#define PID_OFFSET 2
95#define PID_PHASE 3
96#define PID_PERIOD 4
97static const u8 pidff_set_periodic[] = { 0x22, 0x70, 0x6f, 0x71, 0x72 };
98static const u8 pidff_set_constant[] = { 0x22, 0x70 };
99
100#define PID_RAMP_START 1
101#define PID_RAMP_END 2
102static const u8 pidff_set_ramp[] = { 0x22, 0x75, 0x76 };
103
104#define PID_RAM_POOL_AVAILABLE 1
105static const u8 pidff_block_load[] = { 0x22, 0xac };
106
107#define PID_LOOP_COUNT 1
108static const u8 pidff_effect_operation[] = { 0x22, 0x7c };
109
110static const u8 pidff_block_free[] = { 0x22 };
111
112#define PID_DEVICE_GAIN_FIELD 0
113static const u8 pidff_device_gain[] = { 0x7e };
114
115#define PID_RAM_POOL_SIZE 0
116#define PID_SIMULTANEOUS_MAX 1
117#define PID_DEVICE_MANAGED_POOL 2
118static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 };
119
120/* Special field key tables used to put special field keys into arrays */
121
122#define PID_ENABLE_ACTUATORS 0
123#define PID_RESET 1
124static const u8 pidff_device_control[] = { 0x97, 0x9a };
125
126#define PID_CONSTANT 0
127#define PID_RAMP 1
128#define PID_SQUARE 2
129#define PID_SINE 3
130#define PID_TRIANGLE 4
131#define PID_SAW_UP 5
132#define PID_SAW_DOWN 6
133#define PID_SPRING 7
134#define PID_DAMPER 8
135#define PID_INERTIA 9
136#define PID_FRICTION 10
137static const u8 pidff_effect_types[] = {
138 0x26, 0x27, 0x30, 0x31, 0x32, 0x33, 0x34,
139 0x40, 0x41, 0x42, 0x43
140};
141
142#define PID_BLOCK_LOAD_SUCCESS 0
143#define PID_BLOCK_LOAD_FULL 1
144static const u8 pidff_block_load_status[] = { 0x8c, 0x8d };
145
146#define PID_EFFECT_START 0
147#define PID_EFFECT_STOP 1
148static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b };
149
150struct pidff_usage {
151 struct hid_field *field;
152 s32 *value;
153};
154
155struct pidff_device {
156 struct hid_device *hid;
157
158 struct hid_report *reports[sizeof(pidff_reports)];
159
160 struct pidff_usage set_effect[sizeof(pidff_set_effect)];
161 struct pidff_usage set_envelope[sizeof(pidff_set_envelope)];
162 struct pidff_usage set_condition[sizeof(pidff_set_condition)];
163 struct pidff_usage set_periodic[sizeof(pidff_set_periodic)];
164 struct pidff_usage set_constant[sizeof(pidff_set_constant)];
165 struct pidff_usage set_ramp[sizeof(pidff_set_ramp)];
166
167 struct pidff_usage device_gain[sizeof(pidff_device_gain)];
168 struct pidff_usage block_load[sizeof(pidff_block_load)];
169 struct pidff_usage pool[sizeof(pidff_pool)];
170 struct pidff_usage effect_operation[sizeof(pidff_effect_operation)];
171 struct pidff_usage block_free[sizeof(pidff_block_free)];
172
173 /* Special field is a field that is not composed of
174 usage<->value pairs that pidff_usage values are */
175
176 /* Special field in create_new_effect */
177 struct hid_field *create_new_effect_type;
178
179 /* Special fields in set_effect */
180 struct hid_field *set_effect_type;
181 struct hid_field *effect_direction;
182
183 /* Special field in device_control */
184 struct hid_field *device_control;
185
186 /* Special field in block_load */
187 struct hid_field *block_load_status;
188
189 /* Special field in effect_operation */
190 struct hid_field *effect_operation_status;
191
192 int control_id[sizeof(pidff_device_control)];
193 int type_id[sizeof(pidff_effect_types)];
194 int status_id[sizeof(pidff_block_load_status)];
195 int operation_id[sizeof(pidff_effect_operation_status)];
196
197 int pid_id[PID_EFFECTS_MAX];
198};
199
200/*
201 * Scale an unsigned value with range 0..max for the given field
202 */
203static int pidff_rescale(int i, int max, struct hid_field *field)
204{
205 return i * (field->logical_maximum - field->logical_minimum) / max +
206 field->logical_minimum;
207}
208
209/*
210 * Scale a signed value in range -0x8000..0x7fff for the given field
211 */
212static int pidff_rescale_signed(int i, struct hid_field *field)
213{
214 return i == 0 ? 0 : i >
215 0 ? i * field->logical_maximum / 0x7fff : i *
216 field->logical_minimum / -0x8000;
217}
218
219static void pidff_set(struct pidff_usage *usage, u16 value)
220{
221 usage->value[0] = pidff_rescale(value, 0xffff, usage->field);
222 debug("calculated from %d to %d", value, usage->value[0]);
223}
224
225static void pidff_set_signed(struct pidff_usage *usage, s16 value)
226{
227 if (usage->field->logical_minimum < 0)
228 usage->value[0] = pidff_rescale_signed(value, usage->field);
229 else {
230 if (value < 0)
231 usage->value[0] =
232 pidff_rescale(-value, 0x8000, usage->field);
233 else
234 usage->value[0] =
235 pidff_rescale(value, 0x7fff, usage->field);
236 }
237 debug("calculated from %d to %d", value, usage->value[0]);
238}
239
240/*
241 * Send envelope report to the device
242 */
243static void pidff_set_envelope_report(struct pidff_device *pidff,
244 struct ff_envelope *envelope)
245{
246 pidff->set_envelope[PID_EFFECT_BLOCK_INDEX].value[0] =
247 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
248
249 pidff->set_envelope[PID_ATTACK_LEVEL].value[0] =
250 pidff_rescale(envelope->attack_level >
251 0x7fff ? 0x7fff : envelope->attack_level, 0x7fff,
252 pidff->set_envelope[PID_ATTACK_LEVEL].field);
253 pidff->set_envelope[PID_FADE_LEVEL].value[0] =
254 pidff_rescale(envelope->fade_level >
255 0x7fff ? 0x7fff : envelope->fade_level, 0x7fff,
256 pidff->set_envelope[PID_FADE_LEVEL].field);
257
258 pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length;
259 pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length;
260
261 debug("attack %u => %d", envelope->attack_level,
262 pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
263
264 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_ENVELOPE],
265 USB_DIR_OUT);
266}
267
268/*
269 * Test if the new envelope differs from old one
270 */
271static int pidff_needs_set_envelope(struct ff_envelope *envelope,
272 struct ff_envelope *old)
273{
274 return envelope->attack_level != old->attack_level ||
275 envelope->fade_level != old->fade_level ||
276 envelope->attack_length != old->attack_length ||
277 envelope->fade_length != old->fade_length;
278}
279
280/*
281 * Send constant force report to the device
282 */
283static void pidff_set_constant_force_report(struct pidff_device *pidff,
284 struct ff_effect *effect)
285{
286 pidff->set_constant[PID_EFFECT_BLOCK_INDEX].value[0] =
287 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
288 pidff_set_signed(&pidff->set_constant[PID_MAGNITUDE],
289 effect->u.constant.level);
290
291 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONSTANT],
292 USB_DIR_OUT);
293}
294
295/*
296 * Test if the constant parameters have changed between effects
297 */
298static int pidff_needs_set_constant(struct ff_effect *effect,
299 struct ff_effect *old)
300{
301 return effect->u.constant.level != old->u.constant.level;
302}
303
304/*
305 * Send set effect report to the device
306 */
307static void pidff_set_effect_report(struct pidff_device *pidff,
308 struct ff_effect *effect)
309{
310 pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
311 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
312 pidff->set_effect_type->value[0] =
313 pidff->create_new_effect_type->value[0];
314 pidff->set_effect[PID_DURATION].value[0] = effect->replay.length;
315 pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button;
316 pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] =
317 effect->trigger.interval;
318 pidff->set_effect[PID_GAIN].value[0] =
319 pidff->set_effect[PID_GAIN].field->logical_maximum;
320 pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1;
321 pidff->effect_direction->value[0] =
322 pidff_rescale(effect->direction, 0xffff,
323 pidff->effect_direction);
324 pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay;
325
326 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT],
327 USB_DIR_OUT);
328}
329
330/*
331 * Test if the values used in set_effect have changed
332 */
333static int pidff_needs_set_effect(struct ff_effect *effect,
334 struct ff_effect *old)
335{
336 return effect->replay.length != old->replay.length ||
337 effect->trigger.interval != old->trigger.interval ||
338 effect->trigger.button != old->trigger.button ||
339 effect->direction != old->direction ||
340 effect->replay.delay != old->replay.delay;
341}
342
343/*
344 * Send periodic effect report to the device
345 */
346static void pidff_set_periodic_report(struct pidff_device *pidff,
347 struct ff_effect *effect)
348{
349 pidff->set_periodic[PID_EFFECT_BLOCK_INDEX].value[0] =
350 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
351 pidff_set_signed(&pidff->set_periodic[PID_MAGNITUDE],
352 effect->u.periodic.magnitude);
353 pidff_set_signed(&pidff->set_periodic[PID_OFFSET],
354 effect->u.periodic.offset);
355 pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase);
356 pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period;
357
358 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_PERIODIC],
359 USB_DIR_OUT);
360
361}
362
363/*
364 * Test if periodic effect parameters have changed
365 */
366static int pidff_needs_set_periodic(struct ff_effect *effect,
367 struct ff_effect *old)
368{
369 return effect->u.periodic.magnitude != old->u.periodic.magnitude ||
370 effect->u.periodic.offset != old->u.periodic.offset ||
371 effect->u.periodic.phase != old->u.periodic.phase ||
372 effect->u.periodic.period != old->u.periodic.period;
373}
374
375/*
376 * Send condition effect reports to the device
377 */
378static void pidff_set_condition_report(struct pidff_device *pidff,
379 struct ff_effect *effect)
380{
381 int i;
382
383 pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] =
384 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
385
386 for (i = 0; i < 2; i++) {
387 pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i;
388 pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET],
389 effect->u.condition[i].center);
390 pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT],
391 effect->u.condition[i].right_coeff);
392 pidff_set_signed(&pidff->set_condition[PID_NEG_COEFFICIENT],
393 effect->u.condition[i].left_coeff);
394 pidff_set(&pidff->set_condition[PID_POS_SATURATION],
395 effect->u.condition[i].right_saturation);
396 pidff_set(&pidff->set_condition[PID_NEG_SATURATION],
397 effect->u.condition[i].left_saturation);
398 pidff_set(&pidff->set_condition[PID_DEAD_BAND],
399 effect->u.condition[i].deadband);
400 usbhid_wait_io(pidff->hid);
401 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION],
402 USB_DIR_OUT);
403 }
404}
405
406/*
407 * Test if condition effect parameters have changed
408 */
409static int pidff_needs_set_condition(struct ff_effect *effect,
410 struct ff_effect *old)
411{
412 int i;
413 int ret = 0;
414
415 for (i = 0; i < 2; i++) {
416 struct ff_condition_effect *cond = &effect->u.condition[i];
417 struct ff_condition_effect *old_cond = &old->u.condition[i];
418
419 ret |= cond->center != old_cond->center ||
420 cond->right_coeff != old_cond->right_coeff ||
421 cond->left_coeff != old_cond->left_coeff ||
422 cond->right_saturation != old_cond->right_saturation ||
423 cond->left_saturation != old_cond->left_saturation ||
424 cond->deadband != old_cond->deadband;
425 }
426
427 return ret;
428}
429
430/*
431 * Send ramp force report to the device
432 */
433static void pidff_set_ramp_force_report(struct pidff_device *pidff,
434 struct ff_effect *effect)
435{
436 pidff->set_ramp[PID_EFFECT_BLOCK_INDEX].value[0] =
437 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
438 pidff_set_signed(&pidff->set_ramp[PID_RAMP_START],
439 effect->u.ramp.start_level);
440 pidff_set_signed(&pidff->set_ramp[PID_RAMP_END],
441 effect->u.ramp.end_level);
442 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_RAMP],
443 USB_DIR_OUT);
444}
445
446/*
447 * Test if ramp force parameters have changed
448 */
449static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old)
450{
451 return effect->u.ramp.start_level != old->u.ramp.start_level ||
452 effect->u.ramp.end_level != old->u.ramp.end_level;
453}
454
455/*
456 * Send a request for effect upload to the device
457 *
458 * Returns 0 if device reported success, -ENOSPC if the device reported memory
459 * is full. Upon unknown response the function will retry for 60 times, if
460 * still unsuccessful -EIO is returned.
461 */
462static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum)
463{
464 int j;
465
466 pidff->create_new_effect_type->value[0] = efnum;
467 usbhid_submit_report(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT],
468 USB_DIR_OUT);
469 debug("create_new_effect sent, type: %d", efnum);
470
471 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
472 pidff->block_load_status->value[0] = 0;
473 usbhid_wait_io(pidff->hid);
474
475 for (j = 0; j < 60; j++) {
476 debug("pid_block_load requested");
477 usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_LOAD],
478 USB_DIR_IN);
479 usbhid_wait_io(pidff->hid);
480 if (pidff->block_load_status->value[0] ==
481 pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) {
482 debug("device reported free memory: %d bytes",
483 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
484 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
485 return 0;
486 }
487 if (pidff->block_load_status->value[0] ==
488 pidff->status_id[PID_BLOCK_LOAD_FULL]) {
489 debug("not enough memory free: %d bytes",
490 pidff->block_load[PID_RAM_POOL_AVAILABLE].value ?
491 pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1);
492 return -ENOSPC;
493 }
494 }
495 printk(KERN_ERR "hid-pidff: pid_block_load failed 60 times\n");
496 return -EIO;
497}
498
499/*
500 * Play the effect with PID id n times
501 */
502static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
503{
504 pidff->effect_operation[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
505
506 if (n == 0) {
507 pidff->effect_operation_status->value[0] =
508 pidff->operation_id[PID_EFFECT_STOP];
509 } else {
510 pidff->effect_operation_status->value[0] =
511 pidff->operation_id[PID_EFFECT_START];
512 pidff->effect_operation[PID_LOOP_COUNT].value[0] = n;
513 }
514
515 usbhid_wait_io(pidff->hid);
516 usbhid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION],
517 USB_DIR_OUT);
518}
519
520/**
521 * Play the effect with effect id @effect_id for @value times
522 */
523static int pidff_playback(struct input_dev *dev, int effect_id, int value)
524{
525 struct pidff_device *pidff = dev->ff->private;
526
527 pidff_playback_pid(pidff, pidff->pid_id[effect_id], value);
528
529 return 0;
530}
531
532/*
533 * Erase effect with PID id
534 */
535static void pidff_erase_pid(struct pidff_device *pidff, int pid_id)
536{
537 pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
538 usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_FREE],
539 USB_DIR_OUT);
540}
541
542/*
543 * Stop and erase effect with effect_id
544 */
545static int pidff_erase_effect(struct input_dev *dev, int effect_id)
546{
547 struct pidff_device *pidff = dev->ff->private;
548 int pid_id = pidff->pid_id[effect_id];
549
550 debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]);
551 pidff_playback_pid(pidff, pid_id, 0);
552 pidff_erase_pid(pidff, pid_id);
553
554 return 0;
555}
556
557/*
558 * Effect upload handler
559 */
560static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
561 struct ff_effect *old)
562{
563 struct pidff_device *pidff = dev->ff->private;
564 int type_id;
565 int error;
566
567 switch (effect->type) {
568 case FF_CONSTANT:
569 if (!old) {
570 error = pidff_request_effect_upload(pidff,
571 pidff->type_id[PID_CONSTANT]);
572 if (error)
573 return error;
574 }
575 if (!old || pidff_needs_set_effect(effect, old))
576 pidff_set_effect_report(pidff, effect);
577 if (!old || pidff_needs_set_constant(effect, old))
578 pidff_set_constant_force_report(pidff, effect);
579 if (!old ||
580 pidff_needs_set_envelope(&effect->u.constant.envelope,
581 &old->u.constant.envelope))
582 pidff_set_envelope_report(pidff,
583 &effect->u.constant.envelope);
584 break;
585
586 case FF_PERIODIC:
587 if (!old) {
588 switch (effect->u.periodic.waveform) {
589 case FF_SQUARE:
590 type_id = PID_SQUARE;
591 break;
592 case FF_TRIANGLE:
593 type_id = PID_TRIANGLE;
594 break;
595 case FF_SINE:
596 type_id = PID_SINE;
597 break;
598 case FF_SAW_UP:
599 type_id = PID_SAW_UP;
600 break;
601 case FF_SAW_DOWN:
602 type_id = PID_SAW_DOWN;
603 break;
604 default:
605 printk(KERN_ERR
606 "hid-pidff: invalid waveform\n");
607 return -EINVAL;
608 }
609
610 error = pidff_request_effect_upload(pidff,
611 pidff->type_id[type_id]);
612 if (error)
613 return error;
614 }
615 if (!old || pidff_needs_set_effect(effect, old))
616 pidff_set_effect_report(pidff, effect);
617 if (!old || pidff_needs_set_periodic(effect, old))
618 pidff_set_periodic_report(pidff, effect);
619 if (!old ||
620 pidff_needs_set_envelope(&effect->u.periodic.envelope,
621 &old->u.periodic.envelope))
622 pidff_set_envelope_report(pidff,
623 &effect->u.periodic.envelope);
624 break;
625
626 case FF_RAMP:
627 if (!old) {
628 error = pidff_request_effect_upload(pidff,
629 pidff->type_id[PID_RAMP]);
630 if (error)
631 return error;
632 }
633 if (!old || pidff_needs_set_effect(effect, old))
634 pidff_set_effect_report(pidff, effect);
635 if (!old || pidff_needs_set_ramp(effect, old))
636 pidff_set_ramp_force_report(pidff, effect);
637 if (!old ||
638 pidff_needs_set_envelope(&effect->u.ramp.envelope,
639 &old->u.ramp.envelope))
640 pidff_set_envelope_report(pidff,
641 &effect->u.ramp.envelope);
642 break;
643
644 case FF_SPRING:
645 if (!old) {
646 error = pidff_request_effect_upload(pidff,
647 pidff->type_id[PID_SPRING]);
648 if (error)
649 return error;
650 }
651 if (!old || pidff_needs_set_effect(effect, old))
652 pidff_set_effect_report(pidff, effect);
653 if (!old || pidff_needs_set_condition(effect, old))
654 pidff_set_condition_report(pidff, effect);
655 break;
656
657 case FF_FRICTION:
658 if (!old) {
659 error = pidff_request_effect_upload(pidff,
660 pidff->type_id[PID_FRICTION]);
661 if (error)
662 return error;
663 }
664 if (!old || pidff_needs_set_effect(effect, old))
665 pidff_set_effect_report(pidff, effect);
666 if (!old || pidff_needs_set_condition(effect, old))
667 pidff_set_condition_report(pidff, effect);
668 break;
669
670 case FF_DAMPER:
671 if (!old) {
672 error = pidff_request_effect_upload(pidff,
673 pidff->type_id[PID_DAMPER]);
674 if (error)
675 return error;
676 }
677 if (!old || pidff_needs_set_effect(effect, old))
678 pidff_set_effect_report(pidff, effect);
679 if (!old || pidff_needs_set_condition(effect, old))
680 pidff_set_condition_report(pidff, effect);
681 break;
682
683 case FF_INERTIA:
684 if (!old) {
685 error = pidff_request_effect_upload(pidff,
686 pidff->type_id[PID_INERTIA]);
687 if (error)
688 return error;
689 }
690 if (!old || pidff_needs_set_effect(effect, old))
691 pidff_set_effect_report(pidff, effect);
692 if (!old || pidff_needs_set_condition(effect, old))
693 pidff_set_condition_report(pidff, effect);
694 break;
695
696 default:
697 printk(KERN_ERR "hid-pidff: invalid type\n");
698 return -EINVAL;
699 }
700
701 if (!old)
702 pidff->pid_id[effect->id] =
703 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
704
705 debug("uploaded");
706
707 return 0;
708}
709
710/*
711 * set_gain() handler
712 */
713static void pidff_set_gain(struct input_dev *dev, u16 gain)
714{
715 struct pidff_device *pidff = dev->ff->private;
716
717 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
718 usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
719 USB_DIR_OUT);
720}
721
722static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
723{
724 struct hid_field *field =
725 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field;
726
727 if (!magnitude) {
728 pidff_playback_pid(pidff, field->logical_minimum, 0);
729 return;
730 }
731
732 pidff_playback_pid(pidff, field->logical_minimum, 1);
733
734 pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
735 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum;
736 pidff->set_effect_type->value[0] = pidff->type_id[PID_SPRING];
737 pidff->set_effect[PID_DURATION].value[0] = 0;
738 pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = 0;
739 pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0;
740 pidff_set(&pidff->set_effect[PID_GAIN], magnitude);
741 pidff->set_effect[PID_START_DELAY].value[0] = 0;
742
743 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT],
744 USB_DIR_OUT);
745}
746
747/*
748 * pidff_set_autocenter() handler
749 */
750static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude)
751{
752 struct pidff_device *pidff = dev->ff->private;
753
754 pidff_autocenter(pidff, magnitude);
755}
756
757/*
758 * Find fields from a report and fill a pidff_usage
759 */
760static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
761 struct hid_report *report, int count, int strict)
762{
763 int i, j, k, found;
764
765 for (k = 0; k < count; k++) {
766 found = 0;
767 for (i = 0; i < report->maxfield; i++) {
768 if (report->field[i]->maxusage !=
769 report->field[i]->report_count) {
770 debug("maxusage and report_count do not match, "
771 "skipping");
772 continue;
773 }
774 for (j = 0; j < report->field[i]->maxusage; j++) {
775 if (report->field[i]->usage[j].hid ==
776 (HID_UP_PID | table[k])) {
777 debug("found %d at %d->%d", k, i, j);
778 usage[k].field = report->field[i];
779 usage[k].value =
780 &report->field[i]->value[j];
781 found = 1;
782 break;
783 }
784 }
785 if (found)
786 break;
787 }
788 if (!found && strict) {
789 debug("failed to locate %d", k);
790 return -1;
791 }
792 }
793 return 0;
794}
795
796/*
797 * Return index into pidff_reports for the given usage
798 */
799static int pidff_check_usage(int usage)
800{
801 int i;
802
803 for (i = 0; i < sizeof(pidff_reports); i++)
804 if (usage == (HID_UP_PID | pidff_reports[i]))
805 return i;
806
807 return -1;
808}
809
810/*
811 * Find the reports and fill pidff->reports[]
812 * report_type specifies either OUTPUT or FEATURE reports
813 */
814static void pidff_find_reports(struct hid_device *hid, int report_type,
815 struct pidff_device *pidff)
816{
817 struct hid_report *report;
818 int i, ret;
819
820 list_for_each_entry(report,
821 &hid->report_enum[report_type].report_list, list) {
822 if (report->maxfield < 1)
823 continue;
824 ret = pidff_check_usage(report->field[0]->logical);
825 if (ret != -1) {
826 debug("found usage 0x%02x from field->logical",
827 pidff_reports[ret]);
828 pidff->reports[ret] = report;
829 continue;
830 }
831
832 /*
833 * Sometimes logical collections are stacked to indicate
834 * different usages for the report and the field, in which
835 * case we want the usage of the parent. However, Linux HID
836 * implementation hides this fact, so we have to dig it up
837 * ourselves
838 */
839 i = report->field[0]->usage[0].collection_index;
840 if (i <= 0 ||
841 hid->collection[i - 1].type != HID_COLLECTION_LOGICAL)
842 continue;
843 ret = pidff_check_usage(hid->collection[i - 1].usage);
844 if (ret != -1 && !pidff->reports[ret]) {
845 debug("found usage 0x%02x from collection array",
846 pidff_reports[ret]);
847 pidff->reports[ret] = report;
848 }
849 }
850}
851
852/*
853 * Test if the required reports have been found
854 */
855static int pidff_reports_ok(struct pidff_device *pidff)
856{
857 int i;
858
859 for (i = 0; i <= PID_REQUIRED_REPORTS; i++) {
860 if (!pidff->reports[i]) {
861 debug("%d missing", i);
862 return 0;
863 }
864 }
865
866 return 1;
867}
868
869/*
870 * Find a field with a specific usage within a report
871 */
872static struct hid_field *pidff_find_special_field(struct hid_report *report,
873 int usage, int enforce_min)
874{
875 int i;
876
877 for (i = 0; i < report->maxfield; i++) {
878 if (report->field[i]->logical == (HID_UP_PID | usage) &&
879 report->field[i]->report_count > 0) {
880 if (!enforce_min ||
881 report->field[i]->logical_minimum == 1)
882 return report->field[i];
883 else {
884 printk(KERN_ERR "hid-pidff: logical_minimum "
885 "is not 1 as it should be\n");
886 return NULL;
887 }
888 }
889 }
890 return NULL;
891}
892
893/*
894 * Fill a pidff->*_id struct table
895 */
896static int pidff_find_special_keys(int *keys, struct hid_field *fld,
897 const u8 *usagetable, int count)
898{
899
900 int i, j;
901 int found = 0;
902
903 for (i = 0; i < count; i++) {
904 for (j = 0; j < fld->maxusage; j++) {
905 if (fld->usage[j].hid == (HID_UP_PID | usagetable[i])) {
906 keys[i] = j + 1;
907 found++;
908 break;
909 }
910 }
911 }
912 return found;
913}
914
915#define PIDFF_FIND_SPECIAL_KEYS(keys, field, name) \
916 pidff_find_special_keys(pidff->keys, pidff->field, pidff_ ## name, \
917 sizeof(pidff_ ## name))
918
919/*
920 * Find and check the special fields
921 */
922static int pidff_find_special_fields(struct pidff_device *pidff)
923{
924 debug("finding special fields");
925
926 pidff->create_new_effect_type =
927 pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT],
928 0x25, 1);
929 pidff->set_effect_type =
930 pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
931 0x25, 1);
932 pidff->effect_direction =
933 pidff_find_special_field(pidff->reports[PID_SET_EFFECT],
934 0x57, 0);
935 pidff->device_control =
936 pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL],
937 0x96, 1);
938 pidff->block_load_status =
939 pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD],
940 0x8b, 1);
941 pidff->effect_operation_status =
942 pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION],
943 0x78, 1);
944
945 debug("search done");
946
947 if (!pidff->create_new_effect_type || !pidff->set_effect_type) {
948 printk(KERN_ERR "hid-pidff: effect lists not found\n");
949 return -1;
950 }
951
952 if (!pidff->effect_direction) {
953 printk(KERN_ERR "hid-pidff: direction field not found\n");
954 return -1;
955 }
956
957 if (!pidff->device_control) {
958 printk(KERN_ERR "hid-pidff: device control field not found\n");
959 return -1;
960 }
961
962 if (!pidff->block_load_status) {
963 printk(KERN_ERR
964 "hid-pidff: block load status field not found\n");
965 return -1;
966 }
967
968 if (!pidff->effect_operation_status) {
969 printk(KERN_ERR
970 "hid-pidff: effect operation field not found\n");
971 return -1;
972 }
973
974 pidff_find_special_keys(pidff->control_id, pidff->device_control,
975 pidff_device_control,
976 sizeof(pidff_device_control));
977
978 PIDFF_FIND_SPECIAL_KEYS(control_id, device_control, device_control);
979
980 if (!PIDFF_FIND_SPECIAL_KEYS(type_id, create_new_effect_type,
981 effect_types)) {
982 printk(KERN_ERR "hid-pidff: no effect types found\n");
983 return -1;
984 }
985
986 if (PIDFF_FIND_SPECIAL_KEYS(status_id, block_load_status,
987 block_load_status) !=
988 sizeof(pidff_block_load_status)) {
989 printk(KERN_ERR
990 "hidpidff: block load status identifiers not found\n");
991 return -1;
992 }
993
994 if (PIDFF_FIND_SPECIAL_KEYS(operation_id, effect_operation_status,
995 effect_operation_status) !=
996 sizeof(pidff_effect_operation_status)) {
997 printk(KERN_ERR
998 "hidpidff: effect operation identifiers not found\n");
999 return -1;
1000 }
1001
1002 return 0;
1003}
1004
1005/**
1006 * Find the implemented effect types
1007 */
1008static int pidff_find_effects(struct pidff_device *pidff,
1009 struct input_dev *dev)
1010{
1011 int i;
1012
1013 for (i = 0; i < sizeof(pidff_effect_types); i++) {
1014 int pidff_type = pidff->type_id[i];
1015 if (pidff->set_effect_type->usage[pidff_type].hid !=
1016 pidff->create_new_effect_type->usage[pidff_type].hid) {
1017 printk(KERN_ERR "hid-pidff: "
1018 "effect type number %d is invalid\n", i);
1019 return -1;
1020 }
1021 }
1022
1023 if (pidff->type_id[PID_CONSTANT])
1024 set_bit(FF_CONSTANT, dev->ffbit);
1025 if (pidff->type_id[PID_RAMP])
1026 set_bit(FF_RAMP, dev->ffbit);
1027 if (pidff->type_id[PID_SQUARE]) {
1028 set_bit(FF_SQUARE, dev->ffbit);
1029 set_bit(FF_PERIODIC, dev->ffbit);
1030 }
1031 if (pidff->type_id[PID_SINE]) {
1032 set_bit(FF_SINE, dev->ffbit);
1033 set_bit(FF_PERIODIC, dev->ffbit);
1034 }
1035 if (pidff->type_id[PID_TRIANGLE]) {
1036 set_bit(FF_TRIANGLE, dev->ffbit);
1037 set_bit(FF_PERIODIC, dev->ffbit);
1038 }
1039 if (pidff->type_id[PID_SAW_UP]) {
1040 set_bit(FF_SAW_UP, dev->ffbit);
1041 set_bit(FF_PERIODIC, dev->ffbit);
1042 }
1043 if (pidff->type_id[PID_SAW_DOWN]) {
1044 set_bit(FF_SAW_DOWN, dev->ffbit);
1045 set_bit(FF_PERIODIC, dev->ffbit);
1046 }
1047 if (pidff->type_id[PID_SPRING])
1048 set_bit(FF_SPRING, dev->ffbit);
1049 if (pidff->type_id[PID_DAMPER])
1050 set_bit(FF_DAMPER, dev->ffbit);
1051 if (pidff->type_id[PID_INERTIA])
1052 set_bit(FF_INERTIA, dev->ffbit);
1053 if (pidff->type_id[PID_FRICTION])
1054 set_bit(FF_FRICTION, dev->ffbit);
1055
1056 return 0;
1057
1058}
1059
1060#define PIDFF_FIND_FIELDS(name, report, strict) \
1061 pidff_find_fields(pidff->name, pidff_ ## name, \
1062 pidff->reports[report], \
1063 sizeof(pidff_ ## name), strict)
1064
1065/*
1066 * Fill and check the pidff_usages
1067 */
1068static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
1069{
1070 int envelope_ok = 0;
1071
1072 if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) {
1073 printk(KERN_ERR
1074 "hid-pidff: unknown set_effect report layout\n");
1075 return -ENODEV;
1076 }
1077
1078 PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0);
1079 if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) {
1080 printk(KERN_ERR
1081 "hid-pidff: unknown pid_block_load report layout\n");
1082 return -ENODEV;
1083 }
1084
1085 if (PIDFF_FIND_FIELDS(effect_operation, PID_EFFECT_OPERATION, 1)) {
1086 printk(KERN_ERR
1087 "hid-pidff: unknown effect_operation report layout\n");
1088 return -ENODEV;
1089 }
1090
1091 if (PIDFF_FIND_FIELDS(block_free, PID_BLOCK_FREE, 1)) {
1092 printk(KERN_ERR
1093 "hid-pidff: unknown pid_block_free report layout\n");
1094 return -ENODEV;
1095 }
1096
1097 if (!PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1))
1098 envelope_ok = 1;
1099
1100 if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev))
1101 return -ENODEV;
1102
1103 if (!envelope_ok) {
1104 if (test_and_clear_bit(FF_CONSTANT, dev->ffbit))
1105 printk(KERN_WARNING "hid-pidff: "
1106 "has constant effect but no envelope\n");
1107 if (test_and_clear_bit(FF_RAMP, dev->ffbit))
1108 printk(KERN_WARNING "hid-pidff: "
1109 "has ramp effect but no envelope\n");
1110
1111 if (test_and_clear_bit(FF_PERIODIC, dev->ffbit))
1112 printk(KERN_WARNING "hid-pidff: "
1113 "has periodic effect but no envelope\n");
1114 }
1115
1116 if (test_bit(FF_CONSTANT, dev->ffbit) &&
1117 PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1)) {
1118 printk(KERN_WARNING
1119 "hid-pidff: unknown constant effect layout\n");
1120 clear_bit(FF_CONSTANT, dev->ffbit);
1121 }
1122
1123 if (test_bit(FF_RAMP, dev->ffbit) &&
1124 PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1)) {
1125 printk(KERN_WARNING "hid-pidff: unknown ramp effect layout\n");
1126 clear_bit(FF_RAMP, dev->ffbit);
1127 }
1128
1129 if ((test_bit(FF_SPRING, dev->ffbit) ||
1130 test_bit(FF_DAMPER, dev->ffbit) ||
1131 test_bit(FF_FRICTION, dev->ffbit) ||
1132 test_bit(FF_INERTIA, dev->ffbit)) &&
1133 PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
1134 printk(KERN_WARNING
1135 "hid-pidff: unknown condition effect layout\n");
1136 clear_bit(FF_SPRING, dev->ffbit);
1137 clear_bit(FF_DAMPER, dev->ffbit);
1138 clear_bit(FF_FRICTION, dev->ffbit);
1139 clear_bit(FF_INERTIA, dev->ffbit);
1140 }
1141
1142 if (test_bit(FF_PERIODIC, dev->ffbit) &&
1143 PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1)) {
1144 printk(KERN_WARNING
1145 "hid-pidff: unknown periodic effect layout\n");
1146 clear_bit(FF_PERIODIC, dev->ffbit);
1147 }
1148
1149 PIDFF_FIND_FIELDS(pool, PID_POOL, 0);
1150
1151 if (!PIDFF_FIND_FIELDS(device_gain, PID_DEVICE_GAIN, 1))
1152 set_bit(FF_GAIN, dev->ffbit);
1153
1154 return 0;
1155}
1156
1157/*
1158 * Reset the device
1159 */
1160static void pidff_reset(struct pidff_device *pidff)
1161{
1162 struct hid_device *hid = pidff->hid;
1163 int i = 0;
1164
1165 pidff->device_control->value[0] = pidff->control_id[PID_RESET];
1166 /* We reset twice as sometimes hid_wait_io isn't waiting long enough */
1167 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1168 usbhid_wait_io(hid);
1169 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1170 usbhid_wait_io(hid);
1171
1172 pidff->device_control->value[0] =
1173 pidff->control_id[PID_ENABLE_ACTUATORS];
1174 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1175 usbhid_wait_io(hid);
1176
1177 /* pool report is sometimes messed up, refetch it */
1178 usbhid_submit_report(hid, pidff->reports[PID_POOL], USB_DIR_IN);
1179 usbhid_wait_io(hid);
1180
1181 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
1182 int sim_effects = pidff->pool[PID_SIMULTANEOUS_MAX].value[0];
1183 while (sim_effects < 2) {
1184 if (i++ > 20) {
1185 printk(KERN_WARNING "hid-pidff: device reports "
1186 "%d simultaneous effects\n",
1187 sim_effects);
1188 break;
1189 }
1190 debug("pid_pool requested again");
1191 usbhid_submit_report(hid, pidff->reports[PID_POOL],
1192 USB_DIR_IN);
1193 usbhid_wait_io(hid);
1194 }
1195 }
1196}
1197
1198/*
1199 * Test if autocenter modification is using the supported method
1200 */
1201static int pidff_check_autocenter(struct pidff_device *pidff,
1202 struct input_dev *dev)
1203{
1204 int error;
1205
1206 /*
1207 * Let's find out if autocenter modification is supported
1208 * Specification doesn't specify anything, so we request an
1209 * effect upload and cancel it immediately. If the approved
1210 * effect id was one above the minimum, then we assume the first
1211 * effect id is a built-in spring type effect used for autocenter
1212 */
1213
1214 error = pidff_request_effect_upload(pidff, 1);
1215 if (error) {
1216 printk(KERN_ERR "hid-pidff: upload request failed\n");
1217 return error;
1218 }
1219
1220 if (pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] ==
1221 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + 1) {
1222 pidff_autocenter(pidff, 0xffff);
1223 set_bit(FF_AUTOCENTER, dev->ffbit);
1224 } else {
1225 printk(KERN_NOTICE "hid-pidff: "
1226 "device has unknown autocenter control method\n");
1227 }
1228
1229 pidff_erase_pid(pidff,
1230 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]);
1231
1232 return 0;
1233
1234}
1235
1236/*
1237 * Check if the device is PID and initialize it
1238 */
1239int hid_pidff_init(struct hid_device *hid)
1240{
1241 struct pidff_device *pidff;
1242 struct hid_input *hidinput = list_entry(hid->inputs.next,
1243 struct hid_input, list);
1244 struct input_dev *dev = hidinput->input;
1245 struct ff_device *ff;
1246 int max_effects;
1247 int error;
1248
1249 debug("starting pid init");
1250
1251 if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) {
1252 debug("not a PID device, no output report");
1253 return -ENODEV;
1254 }
1255
1256 pidff = kzalloc(sizeof(*pidff), GFP_KERNEL);
1257 if (!pidff)
1258 return -ENOMEM;
1259
1260 pidff->hid = hid;
1261
1262 pidff_find_reports(hid, HID_OUTPUT_REPORT, pidff);
1263 pidff_find_reports(hid, HID_FEATURE_REPORT, pidff);
1264
1265 if (!pidff_reports_ok(pidff)) {
1266 debug("reports not ok, aborting");
1267 error = -ENODEV;
1268 goto fail;
1269 }
1270
1271 error = pidff_init_fields(pidff, dev);
1272 if (error)
1273 goto fail;
1274
1275 pidff_reset(pidff);
1276
1277 if (test_bit(FF_GAIN, dev->ffbit)) {
1278 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
1279 usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
1280 USB_DIR_OUT);
1281 }
1282
1283 error = pidff_check_autocenter(pidff, dev);
1284 if (error)
1285 goto fail;
1286
1287 max_effects =
1288 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_maximum -
1289 pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum +
1290 1;
1291 debug("max effects is %d", max_effects);
1292
1293 if (max_effects > PID_EFFECTS_MAX)
1294 max_effects = PID_EFFECTS_MAX;
1295
1296 if (pidff->pool[PID_SIMULTANEOUS_MAX].value)
1297 debug("max simultaneous effects is %d",
1298 pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
1299
1300 if (pidff->pool[PID_RAM_POOL_SIZE].value)
1301 debug("device memory size is %d bytes",
1302 pidff->pool[PID_RAM_POOL_SIZE].value[0]);
1303
1304 if (pidff->pool[PID_DEVICE_MANAGED_POOL].value &&
1305 pidff->pool[PID_DEVICE_MANAGED_POOL].value[0] == 0) {
1306 printk(KERN_NOTICE "hid-pidff: "
1307 "device does not support device managed pool\n");
1308 goto fail;
1309 }
1310
1311 error = input_ff_create(dev, max_effects);
1312 if (error)
1313 goto fail;
1314
1315 ff = dev->ff;
1316 ff->private = pidff;
1317 ff->upload = pidff_upload_effect;
1318 ff->erase = pidff_erase_effect;
1319 ff->set_gain = pidff_set_gain;
1320 ff->set_autocenter = pidff_set_autocenter;
1321 ff->playback = pidff_playback;
1322
1323 printk(KERN_INFO "Force feedback for USB HID PID devices by "
1324 "Anssi Hannula <anssi.hannula@gmail.com>\n");
1325
1326 return 0;
1327
1328 fail:
1329 kfree(pidff);
1330 return error;
1331}
diff --git a/drivers/usb/input/hid-plff.c b/drivers/usb/input/hid-plff.c
deleted file mode 100644
index 76d2e6e14db4..000000000000
--- a/drivers/usb/input/hid-plff.c
+++ /dev/null
@@ -1,129 +0,0 @@
1/*
2 * Force feedback support for PantherLord USB/PS2 2in1 Adapter devices
3 *
4 * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23
24/* #define DEBUG */
25
26#define debug(format, arg...) pr_debug("hid-plff: " format "\n" , ## arg)
27
28#include <linux/input.h>
29#include <linux/usb.h>
30#include <linux/hid.h>
31#include "usbhid.h"
32
33struct plff_device {
34 struct hid_report *report;
35};
36
37static int hid_plff_play(struct input_dev *dev, void *data,
38 struct ff_effect *effect)
39{
40 struct hid_device *hid = dev->private;
41 struct plff_device *plff = data;
42 int left, right;
43
44 left = effect->u.rumble.strong_magnitude;
45 right = effect->u.rumble.weak_magnitude;
46 debug("called with 0x%04x 0x%04x", left, right);
47
48 left = left * 0x7f / 0xffff;
49 right = right * 0x7f / 0xffff;
50
51 plff->report->field[0]->value[2] = left;
52 plff->report->field[0]->value[3] = right;
53 debug("running with 0x%02x 0x%02x", left, right);
54 usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
55
56 return 0;
57}
58
59int hid_plff_init(struct hid_device *hid)
60{
61 struct plff_device *plff;
62 struct hid_report *report;
63 struct hid_input *hidinput;
64 struct list_head *report_list =
65 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
66 struct list_head *report_ptr = report_list;
67 struct input_dev *dev;
68 int error;
69
70 /* The device contains 2 output reports (one for each
71 HID_QUIRK_MULTI_INPUT device), both containing 1 field, which
72 contains 4 ff00.0002 usages and 4 16bit absolute values.
73
74 The 2 input reports also contain a field which contains
75 8 ff00.0001 usages and 8 boolean values. Their meaning is
76 currently unknown. */
77
78 if (list_empty(report_list)) {
79 printk(KERN_ERR "hid-plff: no output reports found\n");
80 return -ENODEV;
81 }
82
83 list_for_each_entry(hidinput, &hid->inputs, list) {
84
85 report_ptr = report_ptr->next;
86
87 if (report_ptr == report_list) {
88 printk(KERN_ERR "hid-plff: required output report is missing\n");
89 return -ENODEV;
90 }
91
92 report = list_entry(report_ptr, struct hid_report, list);
93 if (report->maxfield < 1) {
94 printk(KERN_ERR "hid-plff: no fields in the report\n");
95 return -ENODEV;
96 }
97
98 if (report->field[0]->report_count < 4) {
99 printk(KERN_ERR "hid-plff: not enough values in the field\n");
100 return -ENODEV;
101 }
102
103 plff = kzalloc(sizeof(struct plff_device), GFP_KERNEL);
104 if (!plff)
105 return -ENOMEM;
106
107 dev = hidinput->input;
108
109 set_bit(FF_RUMBLE, dev->ffbit);
110
111 error = input_ff_create_memless(dev, plff, hid_plff_play);
112 if (error) {
113 kfree(plff);
114 return error;
115 }
116
117 plff->report = report;
118 plff->report->field[0]->value[0] = 0x00;
119 plff->report->field[0]->value[1] = 0x00;
120 plff->report->field[0]->value[2] = 0x00;
121 plff->report->field[0]->value[3] = 0x00;
122 usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
123 }
124
125 printk(KERN_INFO "hid-plff: Force feedback for PantherLord USB/PS2 "
126 "2in1 Adapters by Anssi Hannula <anssi.hannula@gmail.com>\n");
127
128 return 0;
129}
diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c
deleted file mode 100644
index ab67331620d0..000000000000
--- a/drivers/usb/input/hid-tmff.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/*
2 * Force feedback support for various HID compliant devices by ThrustMaster:
3 * ThrustMaster FireStorm Dual Power 2
4 * and possibly others whose device ids haven't been added.
5 *
6 * Modified to support ThrustMaster devices by Zinx Verituse
7 * on 2003-01-25 from the Logitech force feedback driver,
8 * which is by Johann Deneux.
9 *
10 * Copyright (c) 2003 Zinx Verituse <zinx@epicsol.org>
11 * Copyright (c) 2002 Johann Deneux
12 */
13
14/*
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30#include <linux/input.h>
31
32#undef DEBUG
33#include <linux/usb.h>
34
35#include <linux/hid.h>
36#include "usbhid.h"
37
38/* Usages for thrustmaster devices I know about */
39#define THRUSTMASTER_USAGE_RUMBLE_LR (HID_UP_GENDESK | 0xbb)
40
41
42struct tmff_device {
43 struct hid_report *report;
44 struct hid_field *rumble;
45};
46
47/* Changes values from 0 to 0xffff into values from minimum to maximum */
48static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum)
49{
50 int ret;
51
52 ret = (in * (maximum - minimum) / 0xffff) + minimum;
53 if (ret < minimum)
54 return minimum;
55 if (ret > maximum)
56 return maximum;
57 return ret;
58}
59
60static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
61{
62 struct hid_device *hid = dev->private;
63 struct tmff_device *tmff = data;
64 int left, right; /* Rumbling */
65
66 left = hid_tmff_scale(effect->u.rumble.weak_magnitude,
67 tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
68 right = hid_tmff_scale(effect->u.rumble.strong_magnitude,
69 tmff->rumble->logical_minimum, tmff->rumble->logical_maximum);
70
71 tmff->rumble->value[0] = left;
72 tmff->rumble->value[1] = right;
73 dbg("(left,right)=(%08x, %08x)", left, right);
74 usbhid_submit_report(hid, tmff->report, USB_DIR_OUT);
75
76 return 0;
77}
78
79int hid_tmff_init(struct hid_device *hid)
80{
81 struct tmff_device *tmff;
82 struct list_head *pos;
83 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
84 struct input_dev *input_dev = hidinput->input;
85 int error;
86
87 tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
88 if (!tmff)
89 return -ENOMEM;
90
91 /* Find the report to use */
92 __list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) {
93 struct hid_report *report = (struct hid_report *)pos;
94 int fieldnum;
95
96 for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) {
97 struct hid_field *field = report->field[fieldnum];
98
99 if (field->maxusage <= 0)
100 continue;
101
102 switch (field->usage[0].hid) {
103 case THRUSTMASTER_USAGE_RUMBLE_LR:
104 if (field->report_count < 2) {
105 warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR with report_count < 2");
106 continue;
107 }
108
109 if (field->logical_maximum == field->logical_minimum) {
110 warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR with logical_maximum == logical_minimum");
111 continue;
112 }
113
114 if (tmff->report && tmff->report != report) {
115 warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR in other report");
116 continue;
117 }
118
119 if (tmff->rumble && tmff->rumble != field) {
120 warn("ignoring duplicate THRUSTMASTER_USAGE_RUMBLE_LR");
121 continue;
122 }
123
124 tmff->report = report;
125 tmff->rumble = field;
126
127 set_bit(FF_RUMBLE, input_dev->ffbit);
128 break;
129
130 default:
131 warn("ignoring unknown output usage %08x", field->usage[0].hid);
132 continue;
133 }
134 }
135 }
136
137 error = input_ff_create_memless(input_dev, tmff, hid_tmff_play);
138 if (error) {
139 kfree(tmff);
140 return error;
141 }
142
143 info("Force feedback for ThrustMaster rumble pad devices by Zinx Verituse <zinx@epicsol.org>");
144
145 return 0;
146}
147
diff --git a/drivers/usb/input/hid-zpff.c b/drivers/usb/input/hid-zpff.c
deleted file mode 100644
index 7bd8238ca212..000000000000
--- a/drivers/usb/input/hid-zpff.c
+++ /dev/null
@@ -1,111 +0,0 @@
1/*
2 * Force feedback support for Zeroplus based devices
3 *
4 * Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23
24/* #define DEBUG */
25
26#define debug(format, arg...) pr_debug("hid-zpff: " format "\n" , ## arg)
27
28#include <linux/input.h>
29#include <linux/usb.h>
30#include <linux/hid.h>
31#include "usbhid.h"
32
33struct zpff_device {
34 struct hid_report *report;
35};
36
37static int hid_zpff_play(struct input_dev *dev, void *data,
38 struct ff_effect *effect)
39{
40 struct hid_device *hid = dev->private;
41 struct zpff_device *zpff = data;
42 int left, right;
43
44 /*
45 * The following is specified the other way around in the Zeroplus
46 * datasheet but the order below is correct for the XFX Executioner;
47 * however it is possible that the XFX Executioner is an exception
48 */
49
50 left = effect->u.rumble.strong_magnitude;
51 right = effect->u.rumble.weak_magnitude;
52 debug("called with 0x%04x 0x%04x", left, right);
53
54 left = left * 0x7f / 0xffff;
55 right = right * 0x7f / 0xffff;
56
57 zpff->report->field[2]->value[0] = left;
58 zpff->report->field[3]->value[0] = right;
59 debug("running with 0x%02x 0x%02x", left, right);
60 usbhid_submit_report(hid, zpff->report, USB_DIR_OUT);
61
62 return 0;
63}
64
65int hid_zpff_init(struct hid_device *hid)
66{
67 struct zpff_device *zpff;
68 struct hid_report *report;
69 struct hid_input *hidinput = list_entry(hid->inputs.next,
70 struct hid_input, list);
71 struct list_head *report_list =
72 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
73 struct input_dev *dev = hidinput->input;
74 int error;
75
76 if (list_empty(report_list)) {
77 printk(KERN_ERR "hid-zpff: no output report found\n");
78 return -ENODEV;
79 }
80
81 report = list_entry(report_list->next, struct hid_report, list);
82
83 if (report->maxfield < 4) {
84 printk(KERN_ERR "hid-zpff: not enough fields in report\n");
85 return -ENODEV;
86 }
87
88 zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
89 if (!zpff)
90 return -ENOMEM;
91
92 set_bit(FF_RUMBLE, dev->ffbit);
93
94 error = input_ff_create_memless(dev, zpff, hid_zpff_play);
95 if (error) {
96 kfree(zpff);
97 return error;
98 }
99
100 zpff->report = report;
101 zpff->report->field[0]->value[0] = 0x00;
102 zpff->report->field[1]->value[0] = 0x02;
103 zpff->report->field[2]->value[0] = 0x00;
104 zpff->report->field[3]->value[0] = 0x00;
105 usbhid_submit_report(hid, zpff->report, USB_DIR_OUT);
106
107 printk(KERN_INFO "Force feedback for Zeroplus based devices by "
108 "Anssi Hannula <anssi.hannula@gmail.com>\n");
109
110 return 0;
111}
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
deleted file mode 100644
index a8b3d66cd498..000000000000
--- a/drivers/usb/input/hiddev.c
+++ /dev/null
@@ -1,847 +0,0 @@
1/*
2 * Copyright (c) 2001 Paul Stewart
3 * Copyright (c) 2001 Vojtech Pavlik
4 *
5 * HID char devices, giving access to raw HID device events.
6 *
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to Paul Stewart <stewart@wetlogic.net>
26 */
27
28#include <linux/poll.h>
29#include <linux/slab.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/smp_lock.h>
33#include <linux/input.h>
34#include <linux/usb.h>
35#include <linux/hid.h>
36#include <linux/hiddev.h>
37#include "usbhid.h"
38
39#ifdef CONFIG_USB_DYNAMIC_MINORS
40#define HIDDEV_MINOR_BASE 0
41#define HIDDEV_MINORS 256
42#else
43#define HIDDEV_MINOR_BASE 96
44#define HIDDEV_MINORS 16
45#endif
46#define HIDDEV_BUFFER_SIZE 64
47
48struct hiddev {
49 int exist;
50 int open;
51 wait_queue_head_t wait;
52 struct hid_device *hid;
53 struct list_head list;
54};
55
56struct hiddev_list {
57 struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE];
58 int head;
59 int tail;
60 unsigned flags;
61 struct fasync_struct *fasync;
62 struct hiddev *hiddev;
63 struct list_head node;
64};
65
66static struct hiddev *hiddev_table[HIDDEV_MINORS];
67
68/*
69 * Find a report, given the report's type and ID. The ID can be specified
70 * indirectly by REPORT_ID_FIRST (which returns the first report of the given
71 * type) or by (REPORT_ID_NEXT | old_id), which returns the next report of the
72 * given type which follows old_id.
73 */
74static struct hid_report *
75hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
76{
77 unsigned int flags = rinfo->report_id & ~HID_REPORT_ID_MASK;
78 unsigned int rid = rinfo->report_id & HID_REPORT_ID_MASK;
79 struct hid_report_enum *report_enum;
80 struct hid_report *report;
81 struct list_head *list;
82
83 if (rinfo->report_type < HID_REPORT_TYPE_MIN ||
84 rinfo->report_type > HID_REPORT_TYPE_MAX)
85 return NULL;
86
87 report_enum = hid->report_enum +
88 (rinfo->report_type - HID_REPORT_TYPE_MIN);
89
90 switch (flags) {
91 case 0: /* Nothing to do -- report_id is already set correctly */
92 break;
93
94 case HID_REPORT_ID_FIRST:
95 if (list_empty(&report_enum->report_list))
96 return NULL;
97
98 list = report_enum->report_list.next;
99 report = list_entry(list, struct hid_report, list);
100 rinfo->report_id = report->id;
101 break;
102
103 case HID_REPORT_ID_NEXT:
104 report = report_enum->report_id_hash[rid];
105 if (!report)
106 return NULL;
107
108 list = report->list.next;
109 if (list == &report_enum->report_list)
110 return NULL;
111
112 report = list_entry(list, struct hid_report, list);
113 rinfo->report_id = report->id;
114 break;
115
116 default:
117 return NULL;
118 }
119
120 return report_enum->report_id_hash[rinfo->report_id];
121}
122
123/*
124 * Perform an exhaustive search of the report table for a usage, given its
125 * type and usage id.
126 */
127static struct hid_field *
128hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref)
129{
130 int i, j;
131 struct hid_report *report;
132 struct hid_report_enum *report_enum;
133 struct hid_field *field;
134
135 if (uref->report_type < HID_REPORT_TYPE_MIN ||
136 uref->report_type > HID_REPORT_TYPE_MAX)
137 return NULL;
138
139 report_enum = hid->report_enum +
140 (uref->report_type - HID_REPORT_TYPE_MIN);
141
142 list_for_each_entry(report, &report_enum->report_list, list) {
143 for (i = 0; i < report->maxfield; i++) {
144 field = report->field[i];
145 for (j = 0; j < field->maxusage; j++) {
146 if (field->usage[j].hid == uref->usage_code) {
147 uref->report_id = report->id;
148 uref->field_index = i;
149 uref->usage_index = j;
150 return field;
151 }
152 }
153 }
154 }
155
156 return NULL;
157}
158
159static void hiddev_send_event(struct hid_device *hid,
160 struct hiddev_usage_ref *uref)
161{
162 struct hiddev *hiddev = hid->hiddev;
163 struct hiddev_list *list;
164
165 list_for_each_entry(list, &hiddev->list, node) {
166 if (uref->field_index != HID_FIELD_INDEX_NONE ||
167 (list->flags & HIDDEV_FLAG_REPORT) != 0) {
168 list->buffer[list->head] = *uref;
169 list->head = (list->head + 1) &
170 (HIDDEV_BUFFER_SIZE - 1);
171 kill_fasync(&list->fasync, SIGIO, POLL_IN);
172 }
173 }
174
175 wake_up_interruptible(&hiddev->wait);
176}
177
178/*
179 * This is where hid.c calls into hiddev to pass an event that occurred over
180 * the interrupt pipe
181 */
182void hiddev_hid_event(struct hid_device *hid, struct hid_field *field,
183 struct hid_usage *usage, __s32 value)
184{
185 unsigned type = field->report_type;
186 struct hiddev_usage_ref uref;
187
188 uref.report_type =
189 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
190 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
191 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0));
192 uref.report_id = field->report->id;
193 uref.field_index = field->index;
194 uref.usage_index = (usage - field->usage);
195 uref.usage_code = usage->hid;
196 uref.value = value;
197
198 hiddev_send_event(hid, &uref);
199}
200EXPORT_SYMBOL_GPL(hiddev_hid_event);
201
202void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
203{
204 unsigned type = report->type;
205 struct hiddev_usage_ref uref;
206
207 memset(&uref, 0, sizeof(uref));
208 uref.report_type =
209 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
210 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
211 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0));
212 uref.report_id = report->id;
213 uref.field_index = HID_FIELD_INDEX_NONE;
214
215 hiddev_send_event(hid, &uref);
216}
217
218/*
219 * fasync file op
220 */
221static int hiddev_fasync(int fd, struct file *file, int on)
222{
223 int retval;
224 struct hiddev_list *list = file->private_data;
225
226 retval = fasync_helper(fd, file, on, &list->fasync);
227
228 return retval < 0 ? retval : 0;
229}
230
231
232/*
233 * release file op
234 */
235static int hiddev_release(struct inode * inode, struct file * file)
236{
237 struct hiddev_list *list = file->private_data;
238
239 hiddev_fasync(-1, file, 0);
240 list_del(&list->node);
241
242 if (!--list->hiddev->open) {
243 if (list->hiddev->exist)
244 usbhid_close(list->hiddev->hid);
245 else
246 kfree(list->hiddev);
247 }
248
249 kfree(list);
250
251 return 0;
252}
253
254/*
255 * open file op
256 */
257static int hiddev_open(struct inode *inode, struct file *file)
258{
259 struct hiddev_list *list;
260
261 int i = iminor(inode) - HIDDEV_MINOR_BASE;
262
263 if (i >= HIDDEV_MINORS || !hiddev_table[i])
264 return -ENODEV;
265
266 if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL)))
267 return -ENOMEM;
268
269 list->hiddev = hiddev_table[i];
270 list_add_tail(&list->node, &hiddev_table[i]->list);
271 file->private_data = list;
272
273 if (!list->hiddev->open++)
274 if (list->hiddev->exist)
275 usbhid_open(hiddev_table[i]->hid);
276
277 return 0;
278}
279
280/*
281 * "write" file op
282 */
283static ssize_t hiddev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
284{
285 return -EINVAL;
286}
287
288/*
289 * "read" file op
290 */
291static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
292{
293 DECLARE_WAITQUEUE(wait, current);
294 struct hiddev_list *list = file->private_data;
295 int event_size;
296 int retval = 0;
297
298 event_size = ((list->flags & HIDDEV_FLAG_UREF) != 0) ?
299 sizeof(struct hiddev_usage_ref) : sizeof(struct hiddev_event);
300
301 if (count < event_size)
302 return 0;
303
304 while (retval == 0) {
305 if (list->head == list->tail) {
306 add_wait_queue(&list->hiddev->wait, &wait);
307 set_current_state(TASK_INTERRUPTIBLE);
308
309 while (list->head == list->tail) {
310 if (file->f_flags & O_NONBLOCK) {
311 retval = -EAGAIN;
312 break;
313 }
314 if (signal_pending(current)) {
315 retval = -ERESTARTSYS;
316 break;
317 }
318 if (!list->hiddev->exist) {
319 retval = -EIO;
320 break;
321 }
322
323 schedule();
324 set_current_state(TASK_INTERRUPTIBLE);
325 }
326
327 set_current_state(TASK_RUNNING);
328 remove_wait_queue(&list->hiddev->wait, &wait);
329 }
330
331 if (retval)
332 return retval;
333
334
335 while (list->head != list->tail &&
336 retval + event_size <= count) {
337 if ((list->flags & HIDDEV_FLAG_UREF) == 0) {
338 if (list->buffer[list->tail].field_index !=
339 HID_FIELD_INDEX_NONE) {
340 struct hiddev_event event;
341 event.hid = list->buffer[list->tail].usage_code;
342 event.value = list->buffer[list->tail].value;
343 if (copy_to_user(buffer + retval, &event, sizeof(struct hiddev_event)))
344 return -EFAULT;
345 retval += sizeof(struct hiddev_event);
346 }
347 } else {
348 if (list->buffer[list->tail].field_index != HID_FIELD_INDEX_NONE ||
349 (list->flags & HIDDEV_FLAG_REPORT) != 0) {
350 if (copy_to_user(buffer + retval, list->buffer + list->tail, sizeof(struct hiddev_usage_ref)))
351 return -EFAULT;
352 retval += sizeof(struct hiddev_usage_ref);
353 }
354 }
355 list->tail = (list->tail + 1) & (HIDDEV_BUFFER_SIZE - 1);
356 }
357
358 }
359
360 return retval;
361}
362
363/*
364 * "poll" file op
365 * No kernel lock - fine
366 */
367static unsigned int hiddev_poll(struct file *file, poll_table *wait)
368{
369 struct hiddev_list *list = file->private_data;
370
371 poll_wait(file, &list->hiddev->wait, wait);
372 if (list->head != list->tail)
373 return POLLIN | POLLRDNORM;
374 if (!list->hiddev->exist)
375 return POLLERR | POLLHUP;
376 return 0;
377}
378
379/*
380 * "ioctl" file op
381 */
382static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
383{
384 struct hiddev_list *list = file->private_data;
385 struct hiddev *hiddev = list->hiddev;
386 struct hid_device *hid = hiddev->hid;
387 struct usb_device *dev = hid_to_usb_dev(hid);
388 struct hiddev_collection_info cinfo;
389 struct hiddev_report_info rinfo;
390 struct hiddev_field_info finfo;
391 struct hiddev_usage_ref_multi *uref_multi = NULL;
392 struct hiddev_usage_ref *uref;
393 struct hiddev_devinfo dinfo;
394 struct hid_report *report;
395 struct hid_field *field;
396 struct usbhid_device *usbhid = hid->driver_data;
397 void __user *user_arg = (void __user *)arg;
398 int i;
399
400 if (!hiddev->exist)
401 return -EIO;
402
403 switch (cmd) {
404
405 case HIDIOCGVERSION:
406 return put_user(HID_VERSION, (int __user *)arg);
407
408 case HIDIOCAPPLICATION:
409 if (arg < 0 || arg >= hid->maxapplication)
410 return -EINVAL;
411
412 for (i = 0; i < hid->maxcollection; i++)
413 if (hid->collection[i].type ==
414 HID_COLLECTION_APPLICATION && arg-- == 0)
415 break;
416
417 if (i == hid->maxcollection)
418 return -EINVAL;
419
420 return hid->collection[i].usage;
421
422 case HIDIOCGDEVINFO:
423 dinfo.bustype = BUS_USB;
424 dinfo.busnum = dev->bus->busnum;
425 dinfo.devnum = dev->devnum;
426 dinfo.ifnum = usbhid->ifnum;
427 dinfo.vendor = le16_to_cpu(dev->descriptor.idVendor);
428 dinfo.product = le16_to_cpu(dev->descriptor.idProduct);
429 dinfo.version = le16_to_cpu(dev->descriptor.bcdDevice);
430 dinfo.num_applications = hid->maxapplication;
431 if (copy_to_user(user_arg, &dinfo, sizeof(dinfo)))
432 return -EFAULT;
433
434 return 0;
435
436 case HIDIOCGFLAG:
437 if (put_user(list->flags, (int __user *)arg))
438 return -EFAULT;
439
440 return 0;
441
442 case HIDIOCSFLAG:
443 {
444 int newflags;
445 if (get_user(newflags, (int __user *)arg))
446 return -EFAULT;
447
448 if ((newflags & ~HIDDEV_FLAGS) != 0 ||
449 ((newflags & HIDDEV_FLAG_REPORT) != 0 &&
450 (newflags & HIDDEV_FLAG_UREF) == 0))
451 return -EINVAL;
452
453 list->flags = newflags;
454
455 return 0;
456 }
457
458 case HIDIOCGSTRING:
459 {
460 int idx, len;
461 char *buf;
462
463 if (get_user(idx, (int __user *)arg))
464 return -EFAULT;
465
466 if ((buf = kmalloc(HID_STRING_SIZE, GFP_KERNEL)) == NULL)
467 return -ENOMEM;
468
469 if ((len = usb_string(dev, idx, buf, HID_STRING_SIZE-1)) < 0) {
470 kfree(buf);
471 return -EINVAL;
472 }
473
474 if (copy_to_user(user_arg+sizeof(int), buf, len+1)) {
475 kfree(buf);
476 return -EFAULT;
477 }
478
479 kfree(buf);
480
481 return len;
482 }
483
484 case HIDIOCINITREPORT:
485 usbhid_init_reports(hid);
486
487 return 0;
488
489 case HIDIOCGREPORT:
490 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo)))
491 return -EFAULT;
492
493 if (rinfo.report_type == HID_REPORT_TYPE_OUTPUT)
494 return -EINVAL;
495
496 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
497 return -EINVAL;
498
499 usbhid_submit_report(hid, report, USB_DIR_IN);
500 usbhid_wait_io(hid);
501
502 return 0;
503
504 case HIDIOCSREPORT:
505 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo)))
506 return -EFAULT;
507
508 if (rinfo.report_type == HID_REPORT_TYPE_INPUT)
509 return -EINVAL;
510
511 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
512 return -EINVAL;
513
514 usbhid_submit_report(hid, report, USB_DIR_OUT);
515 usbhid_wait_io(hid);
516
517 return 0;
518
519 case HIDIOCGREPORTINFO:
520 if (copy_from_user(&rinfo, user_arg, sizeof(rinfo)))
521 return -EFAULT;
522
523 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
524 return -EINVAL;
525
526 rinfo.num_fields = report->maxfield;
527
528 if (copy_to_user(user_arg, &rinfo, sizeof(rinfo)))
529 return -EFAULT;
530
531 return 0;
532
533 case HIDIOCGFIELDINFO:
534 if (copy_from_user(&finfo, user_arg, sizeof(finfo)))
535 return -EFAULT;
536 rinfo.report_type = finfo.report_type;
537 rinfo.report_id = finfo.report_id;
538 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
539 return -EINVAL;
540
541 if (finfo.field_index >= report->maxfield)
542 return -EINVAL;
543
544 field = report->field[finfo.field_index];
545 memset(&finfo, 0, sizeof(finfo));
546 finfo.report_type = rinfo.report_type;
547 finfo.report_id = rinfo.report_id;
548 finfo.field_index = field->report_count - 1;
549 finfo.maxusage = field->maxusage;
550 finfo.flags = field->flags;
551 finfo.physical = field->physical;
552 finfo.logical = field->logical;
553 finfo.application = field->application;
554 finfo.logical_minimum = field->logical_minimum;
555 finfo.logical_maximum = field->logical_maximum;
556 finfo.physical_minimum = field->physical_minimum;
557 finfo.physical_maximum = field->physical_maximum;
558 finfo.unit_exponent = field->unit_exponent;
559 finfo.unit = field->unit;
560
561 if (copy_to_user(user_arg, &finfo, sizeof(finfo)))
562 return -EFAULT;
563
564 return 0;
565
566 case HIDIOCGUCODE:
567 uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL);
568 if (!uref_multi)
569 return -ENOMEM;
570 uref = &uref_multi->uref;
571 if (copy_from_user(uref, user_arg, sizeof(*uref)))
572 goto fault;
573
574 rinfo.report_type = uref->report_type;
575 rinfo.report_id = uref->report_id;
576 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
577 goto inval;
578
579 if (uref->field_index >= report->maxfield)
580 goto inval;
581
582 field = report->field[uref->field_index];
583 if (uref->usage_index >= field->maxusage)
584 goto inval;
585
586 uref->usage_code = field->usage[uref->usage_index].hid;
587
588 if (copy_to_user(user_arg, uref, sizeof(*uref)))
589 goto fault;
590
591 kfree(uref_multi);
592 return 0;
593
594 case HIDIOCGUSAGE:
595 case HIDIOCSUSAGE:
596 case HIDIOCGUSAGES:
597 case HIDIOCSUSAGES:
598 case HIDIOCGCOLLECTIONINDEX:
599 uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL);
600 if (!uref_multi)
601 return -ENOMEM;
602 uref = &uref_multi->uref;
603 if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) {
604 if (copy_from_user(uref_multi, user_arg,
605 sizeof(*uref_multi)))
606 goto fault;
607 } else {
608 if (copy_from_user(uref, user_arg, sizeof(*uref)))
609 goto fault;
610 }
611
612 if (cmd != HIDIOCGUSAGE &&
613 cmd != HIDIOCGUSAGES &&
614 uref->report_type == HID_REPORT_TYPE_INPUT)
615 goto inval;
616
617 if (uref->report_id == HID_REPORT_ID_UNKNOWN) {
618 field = hiddev_lookup_usage(hid, uref);
619 if (field == NULL)
620 goto inval;
621 } else {
622 rinfo.report_type = uref->report_type;
623 rinfo.report_id = uref->report_id;
624 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
625 goto inval;
626
627 if (uref->field_index >= report->maxfield)
628 goto inval;
629
630 field = report->field[uref->field_index];
631
632 if (cmd == HIDIOCGCOLLECTIONINDEX) {
633 if (uref->usage_index >= field->maxusage)
634 goto inval;
635 } else if (uref->usage_index >= field->report_count)
636 goto inval;
637
638 else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) &&
639 (uref_multi->num_values > HID_MAX_MULTI_USAGES ||
640 uref->usage_index + uref_multi->num_values > field->report_count))
641 goto inval;
642 }
643
644 switch (cmd) {
645 case HIDIOCGUSAGE:
646 uref->value = field->value[uref->usage_index];
647 if (copy_to_user(user_arg, uref, sizeof(*uref)))
648 goto fault;
649 goto goodreturn;
650
651 case HIDIOCSUSAGE:
652 field->value[uref->usage_index] = uref->value;
653 goto goodreturn;
654
655 case HIDIOCGCOLLECTIONINDEX:
656 kfree(uref_multi);
657 return field->usage[uref->usage_index].collection_index;
658 case HIDIOCGUSAGES:
659 for (i = 0; i < uref_multi->num_values; i++)
660 uref_multi->values[i] =
661 field->value[uref->usage_index + i];
662 if (copy_to_user(user_arg, uref_multi,
663 sizeof(*uref_multi)))
664 goto fault;
665 goto goodreturn;
666 case HIDIOCSUSAGES:
667 for (i = 0; i < uref_multi->num_values; i++)
668 field->value[uref->usage_index + i] =
669 uref_multi->values[i];
670 goto goodreturn;
671 }
672
673goodreturn:
674 kfree(uref_multi);
675 return 0;
676fault:
677 kfree(uref_multi);
678 return -EFAULT;
679inval:
680 kfree(uref_multi);
681 return -EINVAL;
682
683 case HIDIOCGCOLLECTIONINFO:
684 if (copy_from_user(&cinfo, user_arg, sizeof(cinfo)))
685 return -EFAULT;
686
687 if (cinfo.index >= hid->maxcollection)
688 return -EINVAL;
689
690 cinfo.type = hid->collection[cinfo.index].type;
691 cinfo.usage = hid->collection[cinfo.index].usage;
692 cinfo.level = hid->collection[cinfo.index].level;
693
694 if (copy_to_user(user_arg, &cinfo, sizeof(cinfo)))
695 return -EFAULT;
696 return 0;
697
698 default:
699
700 if (_IOC_TYPE(cmd) != 'H' || _IOC_DIR(cmd) != _IOC_READ)
701 return -EINVAL;
702
703 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGNAME(0))) {
704 int len;
705 if (!hid->name)
706 return 0;
707 len = strlen(hid->name) + 1;
708 if (len > _IOC_SIZE(cmd))
709 len = _IOC_SIZE(cmd);
710 return copy_to_user(user_arg, hid->name, len) ?
711 -EFAULT : len;
712 }
713
714 if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGPHYS(0))) {
715 int len;
716 if (!hid->phys)
717 return 0;
718 len = strlen(hid->phys) + 1;
719 if (len > _IOC_SIZE(cmd))
720 len = _IOC_SIZE(cmd);
721 return copy_to_user(user_arg, hid->phys, len) ?
722 -EFAULT : len;
723 }
724 }
725 return -EINVAL;
726}
727
728static const struct file_operations hiddev_fops = {
729 .owner = THIS_MODULE,
730 .read = hiddev_read,
731 .write = hiddev_write,
732 .poll = hiddev_poll,
733 .open = hiddev_open,
734 .release = hiddev_release,
735 .ioctl = hiddev_ioctl,
736 .fasync = hiddev_fasync,
737};
738
739static struct usb_class_driver hiddev_class = {
740 .name = "hiddev%d",
741 .fops = &hiddev_fops,
742 .minor_base = HIDDEV_MINOR_BASE,
743};
744
745/*
746 * This is where hid.c calls us to connect a hid device to the hiddev driver
747 */
748int hiddev_connect(struct hid_device *hid)
749{
750 struct hiddev *hiddev;
751 struct usbhid_device *usbhid = hid->driver_data;
752 int i;
753 int retval;
754
755 for (i = 0; i < hid->maxcollection; i++)
756 if (hid->collection[i].type ==
757 HID_COLLECTION_APPLICATION &&
758 !IS_INPUT_APPLICATION(hid->collection[i].usage))
759 break;
760
761 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0)
762 return -1;
763
764 if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
765 return -1;
766
767 retval = usb_register_dev(usbhid->intf, &hiddev_class);
768 if (retval) {
769 err("Not able to get a minor for this device.");
770 kfree(hiddev);
771 return -1;
772 }
773
774 init_waitqueue_head(&hiddev->wait);
775 INIT_LIST_HEAD(&hiddev->list);
776 hiddev->hid = hid;
777 hiddev->exist = 1;
778
779 hid->minor = usbhid->intf->minor;
780 hid->hiddev = hiddev;
781
782 hiddev_table[usbhid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
783
784 return 0;
785}
786
787/*
788 * This is where hid.c calls us to disconnect a hiddev device from the
789 * corresponding hid device (usually because the usb device has disconnected)
790 */
791static struct usb_class_driver hiddev_class;
792void hiddev_disconnect(struct hid_device *hid)
793{
794 struct hiddev *hiddev = hid->hiddev;
795 struct usbhid_device *usbhid = hid->driver_data;
796
797 hiddev->exist = 0;
798
799 hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL;
800 usb_deregister_dev(usbhid->intf, &hiddev_class);
801
802 if (hiddev->open) {
803 usbhid_close(hiddev->hid);
804 wake_up_interruptible(&hiddev->wait);
805 } else {
806 kfree(hiddev);
807 }
808}
809
810/* Currently this driver is a USB driver. It's not a conventional one in
811 * the sense that it doesn't probe at the USB level. Instead it waits to
812 * be connected by HID through the hiddev_connect / hiddev_disconnect
813 * routines. The reason to register as a USB device is to gain part of the
814 * minor number space from the USB major.
815 *
816 * In theory, should the HID code be generalized to more than one physical
817 * medium (say, IEEE 1384), this driver will probably need to register its
818 * own major number, and in doing so, no longer need to register with USB.
819 * At that point the probe routine and hiddev_driver struct below will no
820 * longer be useful.
821 */
822
823
824/* We never attach in this manner, and rely on HID to connect us. This
825 * is why there is no disconnect routine defined in the usb_driver either.
826 */
827static int hiddev_usbd_probe(struct usb_interface *intf,
828 const struct usb_device_id *hiddev_info)
829{
830 return -ENODEV;
831}
832
833
834static /* const */ struct usb_driver hiddev_driver = {
835 .name = "hiddev",
836 .probe = hiddev_usbd_probe,
837};
838
839int __init hiddev_init(void)
840{
841 return usb_register(&hiddev_driver);
842}
843
844void hiddev_exit(void)
845{
846 usb_deregister(&hiddev_driver);
847}
diff --git a/drivers/usb/input/usbhid.h b/drivers/usb/input/usbhid.h
deleted file mode 100644
index 0023f96d4294..000000000000
--- a/drivers/usb/input/usbhid.h
+++ /dev/null
@@ -1,87 +0,0 @@
1#ifndef __USBHID_H
2#define __USBHID_H
3
4/*
5 * Copyright (c) 1999 Andreas Gal
6 * Copyright (c) 2000-2001 Vojtech Pavlik
7 * Copyright (c) 2006 Jiri Kosina
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#include <linux/types.h>
28#include <linux/slab.h>
29#include <linux/list.h>
30#include <linux/timer.h>
31#include <linux/workqueue.h>
32#include <linux/input.h>
33
34/* API provided by hid-core.c for USB HID drivers */
35int usbhid_wait_io(struct hid_device* hid);
36void usbhid_close(struct hid_device *hid);
37int usbhid_open(struct hid_device *hid);
38void usbhid_init_reports(struct hid_device *hid);
39void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir);
40
41/*
42 * USB-specific HID struct, to be pointed to
43 * from struct hid_device->driver_data
44 */
45
46struct usbhid_device {
47 struct hid_device *hid; /* pointer to corresponding HID dev */
48
49 struct usb_interface *intf; /* USB interface */
50 int ifnum; /* USB interface number */
51
52 unsigned int bufsize; /* URB buffer size */
53
54 struct urb *urbin; /* Input URB */
55 char *inbuf; /* Input buffer */
56 dma_addr_t inbuf_dma; /* Input buffer dma */
57 spinlock_t inlock; /* Input fifo spinlock */
58
59 struct urb *urbctrl; /* Control URB */
60 struct usb_ctrlrequest *cr; /* Control request struct */
61 dma_addr_t cr_dma; /* Control request struct dma */
62 struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */
63 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
64 char *ctrlbuf; /* Control buffer */
65 dma_addr_t ctrlbuf_dma; /* Control buffer dma */
66 spinlock_t ctrllock; /* Control fifo spinlock */
67
68 struct urb *urbout; /* Output URB */
69 struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
70 unsigned char outhead, outtail; /* Output pipe fifo head & tail */
71 char *outbuf; /* Output buffer */
72 dma_addr_t outbuf_dma; /* Output buffer dma */
73 spinlock_t outlock; /* Output fifo spinlock */
74
75 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
76 struct timer_list io_retry; /* Retry timer */
77 unsigned long stop_retry; /* Time to give up, in jiffies */
78 unsigned int retry_delay; /* Delay length in ms */
79 struct work_struct reset_work; /* Task context for resets */
80
81};
82
83#define hid_to_usb_dev(hid_dev) \
84 container_of(hid_dev->dev->parent, struct usb_device, dev)
85
86#endif
87
diff --git a/drivers/usb/input/usbkbd.c b/drivers/usb/input/usbkbd.c
deleted file mode 100644
index 8505824848f6..000000000000
--- a/drivers/usb/input/usbkbd.c
+++ /dev/null
@@ -1,360 +0,0 @@
1/*
2 * $Id: usbkbd.c,v 1.27 2001/12/27 10:37:41 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik
5 *
6 * USB HIDBP Keyboard support
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27 */
28
29#include <linux/kernel.h>
30#include <linux/slab.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/usb/input.h>
34
35/*
36 * Version Information
37 */
38#define DRIVER_VERSION ""
39#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
40#define DRIVER_DESC "USB HID Boot Protocol keyboard driver"
41#define DRIVER_LICENSE "GPL"
42
43MODULE_AUTHOR(DRIVER_AUTHOR);
44MODULE_DESCRIPTION(DRIVER_DESC);
45MODULE_LICENSE(DRIVER_LICENSE);
46
47static unsigned char usb_kbd_keycode[256] = {
48 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
49 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
50 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
51 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
52 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
53 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
54 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
55 191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
56 115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0,
57 122,123, 90, 91, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
63 150,158,159,128,136,177,178,176,142,152,173,140
64};
65
66struct usb_kbd {
67 struct input_dev *dev;
68 struct usb_device *usbdev;
69 unsigned char old[8];
70 struct urb *irq, *led;
71 unsigned char newleds;
72 char name[128];
73 char phys[64];
74
75 unsigned char *new;
76 struct usb_ctrlrequest *cr;
77 unsigned char *leds;
78 dma_addr_t cr_dma;
79 dma_addr_t new_dma;
80 dma_addr_t leds_dma;
81};
82
83static void usb_kbd_irq(struct urb *urb)
84{
85 struct usb_kbd *kbd = urb->context;
86 int i;
87
88 switch (urb->status) {
89 case 0: /* success */
90 break;
91 case -ECONNRESET: /* unlink */
92 case -ENOENT:
93 case -ESHUTDOWN:
94 return;
95 /* -EPIPE: should clear the halt */
96 default: /* error */
97 goto resubmit;
98 }
99
100 for (i = 0; i < 8; i++)
101 input_report_key(kbd->dev, usb_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
102
103 for (i = 2; i < 8; i++) {
104
105 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == kbd->new + 8) {
106 if (usb_kbd_keycode[kbd->old[i]])
107 input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0);
108 else
109 info("Unknown key (scancode %#x) released.", kbd->old[i]);
110 }
111
112 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) {
113 if (usb_kbd_keycode[kbd->new[i]])
114 input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1);
115 else
116 info("Unknown key (scancode %#x) pressed.", kbd->new[i]);
117 }
118 }
119
120 input_sync(kbd->dev);
121
122 memcpy(kbd->old, kbd->new, 8);
123
124resubmit:
125 i = usb_submit_urb (urb, GFP_ATOMIC);
126 if (i)
127 err ("can't resubmit intr, %s-%s/input0, status %d",
128 kbd->usbdev->bus->bus_name,
129 kbd->usbdev->devpath, i);
130}
131
132static int usb_kbd_event(struct input_dev *dev, unsigned int type,
133 unsigned int code, int value)
134{
135 struct usb_kbd *kbd = dev->private;
136
137 if (type != EV_LED)
138 return -1;
139
140
141 kbd->newleds = (!!test_bit(LED_KANA, dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) |
142 (!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL, dev->led) << 1) |
143 (!!test_bit(LED_NUML, dev->led));
144
145 if (kbd->led->status == -EINPROGRESS)
146 return 0;
147
148 if (*(kbd->leds) == kbd->newleds)
149 return 0;
150
151 *(kbd->leds) = kbd->newleds;
152 kbd->led->dev = kbd->usbdev;
153 if (usb_submit_urb(kbd->led, GFP_ATOMIC))
154 err("usb_submit_urb(leds) failed");
155
156 return 0;
157}
158
159static void usb_kbd_led(struct urb *urb)
160{
161 struct usb_kbd *kbd = urb->context;
162
163 if (urb->status)
164 warn("led urb status %d received", urb->status);
165
166 if (*(kbd->leds) == kbd->newleds)
167 return;
168
169 *(kbd->leds) = kbd->newleds;
170 kbd->led->dev = kbd->usbdev;
171 if (usb_submit_urb(kbd->led, GFP_ATOMIC))
172 err("usb_submit_urb(leds) failed");
173}
174
175static int usb_kbd_open(struct input_dev *dev)
176{
177 struct usb_kbd *kbd = dev->private;
178
179 kbd->irq->dev = kbd->usbdev;
180 if (usb_submit_urb(kbd->irq, GFP_KERNEL))
181 return -EIO;
182
183 return 0;
184}
185
186static void usb_kbd_close(struct input_dev *dev)
187{
188 struct usb_kbd *kbd = dev->private;
189
190 usb_kill_urb(kbd->irq);
191}
192
193static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
194{
195 if (!(kbd->irq = usb_alloc_urb(0, GFP_KERNEL)))
196 return -1;
197 if (!(kbd->led = usb_alloc_urb(0, GFP_KERNEL)))
198 return -1;
199 if (!(kbd->new = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &kbd->new_dma)))
200 return -1;
201 if (!(kbd->cr = usb_buffer_alloc(dev, sizeof(struct usb_ctrlrequest), GFP_ATOMIC, &kbd->cr_dma)))
202 return -1;
203 if (!(kbd->leds = usb_buffer_alloc(dev, 1, GFP_ATOMIC, &kbd->leds_dma)))
204 return -1;
205
206 return 0;
207}
208
209static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
210{
211 usb_free_urb(kbd->irq);
212 usb_free_urb(kbd->led);
213 if (kbd->new)
214 usb_buffer_free(dev, 8, kbd->new, kbd->new_dma);
215 if (kbd->cr)
216 usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma);
217 if (kbd->leds)
218 usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma);
219}
220
221static int usb_kbd_probe(struct usb_interface *iface,
222 const struct usb_device_id *id)
223{
224 struct usb_device *dev = interface_to_usbdev(iface);
225 struct usb_host_interface *interface;
226 struct usb_endpoint_descriptor *endpoint;
227 struct usb_kbd *kbd;
228 struct input_dev *input_dev;
229 int i, pipe, maxp;
230
231 interface = iface->cur_altsetting;
232
233 if (interface->desc.bNumEndpoints != 1)
234 return -ENODEV;
235
236 endpoint = &interface->endpoint[0].desc;
237 if (!usb_endpoint_is_int_in(endpoint))
238 return -ENODEV;
239
240 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
241 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
242
243 kbd = kzalloc(sizeof(struct usb_kbd), GFP_KERNEL);
244 input_dev = input_allocate_device();
245 if (!kbd || !input_dev)
246 goto fail1;
247
248 if (usb_kbd_alloc_mem(dev, kbd))
249 goto fail2;
250
251 kbd->usbdev = dev;
252 kbd->dev = input_dev;
253
254 if (dev->manufacturer)
255 strlcpy(kbd->name, dev->manufacturer, sizeof(kbd->name));
256
257 if (dev->product) {
258 if (dev->manufacturer)
259 strlcat(kbd->name, " ", sizeof(kbd->name));
260 strlcat(kbd->name, dev->product, sizeof(kbd->name));
261 }
262
263 if (!strlen(kbd->name))
264 snprintf(kbd->name, sizeof(kbd->name),
265 "USB HIDBP Keyboard %04x:%04x",
266 le16_to_cpu(dev->descriptor.idVendor),
267 le16_to_cpu(dev->descriptor.idProduct));
268
269 usb_make_path(dev, kbd->phys, sizeof(kbd->phys));
270 strlcpy(kbd->phys, "/input0", sizeof(kbd->phys));
271
272 input_dev->name = kbd->name;
273 input_dev->phys = kbd->phys;
274 usb_to_input_id(dev, &input_dev->id);
275 input_dev->cdev.dev = &iface->dev;
276 input_dev->private = kbd;
277
278 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
279 input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA);
280
281 for (i = 0; i < 255; i++)
282 set_bit(usb_kbd_keycode[i], input_dev->keybit);
283 clear_bit(0, input_dev->keybit);
284
285 input_dev->event = usb_kbd_event;
286 input_dev->open = usb_kbd_open;
287 input_dev->close = usb_kbd_close;
288
289 usb_fill_int_urb(kbd->irq, dev, pipe,
290 kbd->new, (maxp > 8 ? 8 : maxp),
291 usb_kbd_irq, kbd, endpoint->bInterval);
292 kbd->irq->transfer_dma = kbd->new_dma;
293 kbd->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
294
295 kbd->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
296 kbd->cr->bRequest = 0x09;
297 kbd->cr->wValue = cpu_to_le16(0x200);
298 kbd->cr->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
299 kbd->cr->wLength = cpu_to_le16(1);
300
301 usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0),
302 (void *) kbd->cr, kbd->leds, 1,
303 usb_kbd_led, kbd);
304 kbd->led->setup_dma = kbd->cr_dma;
305 kbd->led->transfer_dma = kbd->leds_dma;
306 kbd->led->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
307
308 input_register_device(kbd->dev);
309
310 usb_set_intfdata(iface, kbd);
311 return 0;
312
313fail2: usb_kbd_free_mem(dev, kbd);
314fail1: input_free_device(input_dev);
315 kfree(kbd);
316 return -ENOMEM;
317}
318
319static void usb_kbd_disconnect(struct usb_interface *intf)
320{
321 struct usb_kbd *kbd = usb_get_intfdata (intf);
322
323 usb_set_intfdata(intf, NULL);
324 if (kbd) {
325 usb_kill_urb(kbd->irq);
326 input_unregister_device(kbd->dev);
327 usb_kbd_free_mem(interface_to_usbdev(intf), kbd);
328 kfree(kbd);
329 }
330}
331
332static struct usb_device_id usb_kbd_id_table [] = {
333 { USB_INTERFACE_INFO(3, 1, 1) },
334 { } /* Terminating entry */
335};
336
337MODULE_DEVICE_TABLE (usb, usb_kbd_id_table);
338
339static struct usb_driver usb_kbd_driver = {
340 .name = "usbkbd",
341 .probe = usb_kbd_probe,
342 .disconnect = usb_kbd_disconnect,
343 .id_table = usb_kbd_id_table,
344};
345
346static int __init usb_kbd_init(void)
347{
348 int result = usb_register(&usb_kbd_driver);
349 if (result == 0)
350 info(DRIVER_VERSION ":" DRIVER_DESC);
351 return result;
352}
353
354static void __exit usb_kbd_exit(void)
355{
356 usb_deregister(&usb_kbd_driver);
357}
358
359module_init(usb_kbd_init);
360module_exit(usb_kbd_exit);
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c
deleted file mode 100644
index 64a33e420cfb..000000000000
--- a/drivers/usb/input/usbmouse.c
+++ /dev/null
@@ -1,243 +0,0 @@
1/*
2 * $Id: usbmouse.c,v 1.15 2001/12/27 10:37:41 vojtech Exp $
3 *
4 * Copyright (c) 1999-2001 Vojtech Pavlik
5 *
6 * USB HIDBP Mouse support
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27 */
28
29#include <linux/kernel.h>
30#include <linux/slab.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/usb/input.h>
34
35/*
36 * Version Information
37 */
38#define DRIVER_VERSION "v1.6"
39#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
40#define DRIVER_DESC "USB HID Boot Protocol mouse driver"
41#define DRIVER_LICENSE "GPL"
42
43MODULE_AUTHOR(DRIVER_AUTHOR);
44MODULE_DESCRIPTION(DRIVER_DESC);
45MODULE_LICENSE(DRIVER_LICENSE);
46
47struct usb_mouse {
48 char name[128];
49 char phys[64];
50 struct usb_device *usbdev;
51 struct input_dev *dev;
52 struct urb *irq;
53
54 signed char *data;
55 dma_addr_t data_dma;
56};
57
58static void usb_mouse_irq(struct urb *urb)
59{
60 struct usb_mouse *mouse = urb->context;
61 signed char *data = mouse->data;
62 struct input_dev *dev = mouse->dev;
63 int status;
64
65 switch (urb->status) {
66 case 0: /* success */
67 break;
68 case -ECONNRESET: /* unlink */
69 case -ENOENT:
70 case -ESHUTDOWN:
71 return;
72 /* -EPIPE: should clear the halt */
73 default: /* error */
74 goto resubmit;
75 }
76
77 input_report_key(dev, BTN_LEFT, data[0] & 0x01);
78 input_report_key(dev, BTN_RIGHT, data[0] & 0x02);
79 input_report_key(dev, BTN_MIDDLE, data[0] & 0x04);
80 input_report_key(dev, BTN_SIDE, data[0] & 0x08);
81 input_report_key(dev, BTN_EXTRA, data[0] & 0x10);
82
83 input_report_rel(dev, REL_X, data[1]);
84 input_report_rel(dev, REL_Y, data[2]);
85 input_report_rel(dev, REL_WHEEL, data[3]);
86
87 input_sync(dev);
88resubmit:
89 status = usb_submit_urb (urb, GFP_ATOMIC);
90 if (status)
91 err ("can't resubmit intr, %s-%s/input0, status %d",
92 mouse->usbdev->bus->bus_name,
93 mouse->usbdev->devpath, status);
94}
95
96static int usb_mouse_open(struct input_dev *dev)
97{
98 struct usb_mouse *mouse = dev->private;
99
100 mouse->irq->dev = mouse->usbdev;
101 if (usb_submit_urb(mouse->irq, GFP_KERNEL))
102 return -EIO;
103
104 return 0;
105}
106
107static void usb_mouse_close(struct input_dev *dev)
108{
109 struct usb_mouse *mouse = dev->private;
110
111 usb_kill_urb(mouse->irq);
112}
113
114static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_id *id)
115{
116 struct usb_device *dev = interface_to_usbdev(intf);
117 struct usb_host_interface *interface;
118 struct usb_endpoint_descriptor *endpoint;
119 struct usb_mouse *mouse;
120 struct input_dev *input_dev;
121 int pipe, maxp;
122
123 interface = intf->cur_altsetting;
124
125 if (interface->desc.bNumEndpoints != 1)
126 return -ENODEV;
127
128 endpoint = &interface->endpoint[0].desc;
129 if (!usb_endpoint_is_int_in(endpoint))
130 return -ENODEV;
131
132 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
133 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
134
135 mouse = kzalloc(sizeof(struct usb_mouse), GFP_KERNEL);
136 input_dev = input_allocate_device();
137 if (!mouse || !input_dev)
138 goto fail1;
139
140 mouse->data = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &mouse->data_dma);
141 if (!mouse->data)
142 goto fail1;
143
144 mouse->irq = usb_alloc_urb(0, GFP_KERNEL);
145 if (!mouse->irq)
146 goto fail2;
147
148 mouse->usbdev = dev;
149 mouse->dev = input_dev;
150
151 if (dev->manufacturer)
152 strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name));
153
154 if (dev->product) {
155 if (dev->manufacturer)
156 strlcat(mouse->name, " ", sizeof(mouse->name));
157 strlcat(mouse->name, dev->product, sizeof(mouse->name));
158 }
159
160 if (!strlen(mouse->name))
161 snprintf(mouse->name, sizeof(mouse->name),
162 "USB HIDBP Mouse %04x:%04x",
163 le16_to_cpu(dev->descriptor.idVendor),
164 le16_to_cpu(dev->descriptor.idProduct));
165
166 usb_make_path(dev, mouse->phys, sizeof(mouse->phys));
167 strlcat(mouse->phys, "/input0", sizeof(mouse->phys));
168
169 input_dev->name = mouse->name;
170 input_dev->phys = mouse->phys;
171 usb_to_input_id(dev, &input_dev->id);
172 input_dev->cdev.dev = &intf->dev;
173
174 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
175 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
176 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
177 input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA);
178 input_dev->relbit[0] |= BIT(REL_WHEEL);
179
180 input_dev->private = mouse;
181 input_dev->open = usb_mouse_open;
182 input_dev->close = usb_mouse_close;
183
184 usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,
185 (maxp > 8 ? 8 : maxp),
186 usb_mouse_irq, mouse, endpoint->bInterval);
187 mouse->irq->transfer_dma = mouse->data_dma;
188 mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
189
190 input_register_device(mouse->dev);
191
192 usb_set_intfdata(intf, mouse);
193 return 0;
194
195fail2: usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
196fail1: input_free_device(input_dev);
197 kfree(mouse);
198 return -ENOMEM;
199}
200
201static void usb_mouse_disconnect(struct usb_interface *intf)
202{
203 struct usb_mouse *mouse = usb_get_intfdata (intf);
204
205 usb_set_intfdata(intf, NULL);
206 if (mouse) {
207 usb_kill_urb(mouse->irq);
208 input_unregister_device(mouse->dev);
209 usb_free_urb(mouse->irq);
210 usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma);
211 kfree(mouse);
212 }
213}
214
215static struct usb_device_id usb_mouse_id_table [] = {
216 { USB_INTERFACE_INFO(3, 1, 2) },
217 { } /* Terminating entry */
218};
219
220MODULE_DEVICE_TABLE (usb, usb_mouse_id_table);
221
222static struct usb_driver usb_mouse_driver = {
223 .name = "usbmouse",
224 .probe = usb_mouse_probe,
225 .disconnect = usb_mouse_disconnect,
226 .id_table = usb_mouse_id_table,
227};
228
229static int __init usb_mouse_init(void)
230{
231 int retval = usb_register(&usb_mouse_driver);
232 if (retval == 0)
233 info(DRIVER_VERSION ":" DRIVER_DESC);
234 return retval;
235}
236
237static void __exit usb_mouse_exit(void)
238{
239 usb_deregister(&usb_mouse_driver);
240}
241
242module_init(usb_mouse_init);
243module_exit(usb_mouse_exit);
diff --git a/drivers/usb/input/wacom_wac.c b/drivers/usb/input/wacom_wac.c
index 4142e36730fc..4f3e9bc7177d 100644
--- a/drivers/usb/input/wacom_wac.c
+++ b/drivers/usb/input/wacom_wac.c
@@ -163,7 +163,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
163 } 163 }
164 164
165 id = STYLUS_DEVICE_ID; 165 id = STYLUS_DEVICE_ID;
166 if (data[1] & 0x10) { /* in prox */ 166 if (data[1] & 0x80) { /* in prox */
167 167
168 switch ((data[1] >> 5) & 3) { 168 switch ((data[1] >> 5) & 3) {
169 169
@@ -196,9 +196,6 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
196 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f); 196 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f);
197 break; 197 break;
198 } 198 }
199 }
200
201 if (data[1] & 0x90) {
202 x = wacom_le16_to_cpu(&data[2]); 199 x = wacom_le16_to_cpu(&data[2]);
203 y = wacom_le16_to_cpu(&data[4]); 200 y = wacom_le16_to_cpu(&data[4]);
204 wacom_report_abs(wcombo, ABS_X, x); 201 wacom_report_abs(wcombo, ABS_X, x);
@@ -210,19 +207,28 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
210 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); 207 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04);
211 } 208 }
212 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ 209 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
213 }
214 else
215 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
216
217 if (data[1] & 0x10) /* only report prox-in when in area */
218 wacom_report_key(wcombo, wacom->tool[0], 1); 210 wacom_report_key(wcombo, wacom->tool[0], 1);
219 if (!(data[1] & 0x90)) /* report prox-out when physically out */ 211 } else if (!(data[1] & 0x90)) {
212 wacom_report_abs(wcombo, ABS_X, 0);
213 wacom_report_abs(wcombo, ABS_Y, 0);
214 if (wacom->tool[0] == BTN_TOOL_MOUSE) {
215 wacom_report_key(wcombo, BTN_LEFT, 0);
216 wacom_report_key(wcombo, BTN_RIGHT, 0);
217 wacom_report_abs(wcombo, ABS_DISTANCE, 0);
218 } else {
219 wacom_report_abs(wcombo, ABS_PRESSURE, 0);
220 wacom_report_key(wcombo, BTN_TOUCH, 0);
221 wacom_report_key(wcombo, BTN_STYLUS, 0);
222 wacom_report_key(wcombo, BTN_STYLUS2, 0);
223 }
224 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
220 wacom_report_key(wcombo, wacom->tool[0], 0); 225 wacom_report_key(wcombo, wacom->tool[0], 0);
221 wacom_input_sync(wcombo); 226 }
222 227
223 /* send pad data */ 228 /* send pad data */
224 if (wacom->features->type == WACOM_G4) { 229 if (wacom->features->type == WACOM_G4) {
225 if ( (wacom->serial[1] & 0xc0) != (data[7] & 0xf8) ) { 230 if (data[7] & 0xf8) {
231 wacom_input_sync(wcombo); /* sync last event */
226 wacom->id[1] = 1; 232 wacom->id[1] = 1;
227 wacom->serial[1] = (data[7] & 0xf8); 233 wacom->serial[1] = (data[7] & 0xf8);
228 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40)); 234 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
@@ -230,10 +236,15 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
230 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3); 236 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
231 wacom_report_rel(wcombo, REL_WHEEL, rw); 237 wacom_report_rel(wcombo, REL_WHEEL, rw);
232 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); 238 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
239 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID);
233 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 240 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
234 } else if (wacom->id[1]) { 241 } else if (wacom->id[1]) {
242 wacom_input_sync(wcombo); /* sync last event */
235 wacom->id[1] = 0; 243 wacom->id[1] = 0;
244 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
245 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
236 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0); 246 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
247 wacom_report_abs(wcombo, ABS_MISC, 0);
237 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 248 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
238 } 249 }
239 } 250 }
@@ -304,28 +315,35 @@ static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
304 default: /* Unknown tool */ 315 default: /* Unknown tool */
305 wacom->tool[idx] = BTN_TOOL_PEN; 316 wacom->tool[idx] = BTN_TOOL_PEN;
306 } 317 }
307 /* only large I3 support Lens Cursor */
308 if(!((wacom->tool[idx] == BTN_TOOL_LENS)
309 && ((wacom->features->type == INTUOS3)
310 || (wacom->features->type == INTUOS3S)))) {
311 wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */
312 wacom_report_key(wcombo, wacom->tool[idx], 1);
313 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
314 return 2;
315 }
316 return 1; 318 return 1;
317 } 319 }
318 320
319 /* Exit report */ 321 /* Exit report */
320 if ((data[1] & 0xfe) == 0x80) { 322 if ((data[1] & 0xfe) == 0x80) {
321 if(!((wacom->tool[idx] == BTN_TOOL_LENS) 323 wacom_report_abs(wcombo, ABS_X, 0);
322 && ((wacom->features->type == INTUOS3) 324 wacom_report_abs(wcombo, ABS_Y, 0);
323 || (wacom->features->type == INTUOS3S)))) { 325 wacom_report_abs(wcombo, ABS_DISTANCE, 0);
324 wacom_report_key(wcombo, wacom->tool[idx], 0); 326 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
325 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ 327 wacom_report_key(wcombo, BTN_LEFT, 0);
326 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]); 328 wacom_report_key(wcombo, BTN_MIDDLE, 0);
327 return 2; 329 wacom_report_key(wcombo, BTN_RIGHT, 0);
330 wacom_report_key(wcombo, BTN_SIDE, 0);
331 wacom_report_key(wcombo, BTN_EXTRA, 0);
332 wacom_report_abs(wcombo, ABS_THROTTLE, 0);
333 wacom_report_abs(wcombo, ABS_RZ, 0);
334 } else {
335 wacom_report_abs(wcombo, ABS_PRESSURE, 0);
336 wacom_report_abs(wcombo, ABS_TILT_X, 0);
337 wacom_report_abs(wcombo, ABS_TILT_Y, 0);
338 wacom_report_key(wcombo, BTN_STYLUS, 0);
339 wacom_report_key(wcombo, BTN_STYLUS2, 0);
340 wacom_report_key(wcombo, BTN_TOUCH, 0);
341 wacom_report_abs(wcombo, ABS_WHEEL, 0);
328 } 342 }
343 wacom_report_key(wcombo, wacom->tool[idx], 0);
344 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
345 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
346 return 2;
329 } 347 }
330 return 0; 348 return 0;
331} 349}
@@ -394,6 +412,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
394 wacom_report_key(wcombo, wacom->tool[1], 1); 412 wacom_report_key(wcombo, wacom->tool[1], 1);
395 else 413 else
396 wacom_report_key(wcombo, wacom->tool[1], 0); 414 wacom_report_key(wcombo, wacom->tool[1], 0);
415 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID);
397 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff); 416 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff);
398 return 1; 417 return 1;
399 } 418 }
@@ -403,6 +422,12 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
403 if (result) 422 if (result)
404 return result-1; 423 return result-1;
405 424
425 /* Only large I3 and I1 & I2 support Lense Cursor */
426 if((wacom->tool[idx] == BTN_TOOL_LENS)
427 && ((wacom->features->type == INTUOS3)
428 || (wacom->features->type == INTUOS3S)))
429 return 0;
430
406 /* Cintiq doesn't send data when RDY bit isn't set */ 431 /* Cintiq doesn't send data when RDY bit isn't set */
407 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40)) 432 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
408 return 0; 433 return 0;
@@ -554,11 +579,11 @@ static struct wacom_features wacom_features[] = {
554 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE }, 579 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE },
555 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE }, 580 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE },
556 { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE }, 581 { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE },
557 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 63, INTUOS }, 582 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 31, INTUOS },
558 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 583 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
559 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 63, INTUOS }, 584 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 31, INTUOS },
560 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 63, INTUOS }, 585 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 31, INTUOS },
561 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 63, INTUOS }, 586 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 31, INTUOS },
562 { "Wacom PL400", 8, 5408, 4056, 255, 0, PL }, 587 { "Wacom PL400", 8, 5408, 4056, 255, 0, PL },
563 { "Wacom PL500", 8, 6144, 4608, 255, 0, PL }, 588 { "Wacom PL500", 8, 6144, 4608, 255, 0, PL },
564 { "Wacom PL600", 8, 6126, 4604, 255, 0, PL }, 589 { "Wacom PL600", 8, 6126, 4604, 255, 0, PL },
@@ -571,11 +596,11 @@ static struct wacom_features wacom_features[] = {
571 { "Wacom DTF521", 8, 6282, 4762, 511, 0, PL }, 596 { "Wacom DTF521", 8, 6282, 4762, 511, 0, PL },
572 { "Wacom DTF720", 8, 6858, 5506, 511, 0, PL }, 597 { "Wacom DTF720", 8, 6858, 5506, 511, 0, PL },
573 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 0, PTU }, 598 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 0, PTU },
574 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 63, INTUOS }, 599 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 31, INTUOS },
575 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 600 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
576 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 63, INTUOS }, 601 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 31, INTUOS },
577 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 63, INTUOS }, 602 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 31, INTUOS },
578 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 63, INTUOS }, 603 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 31, INTUOS },
579 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 63, INTUOS3S }, 604 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 63, INTUOS3S },
580 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 63, INTUOS3 }, 605 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 63, INTUOS3 },
581 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 63, INTUOS3 }, 606 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 63, INTUOS3 },
@@ -584,7 +609,7 @@ static struct wacom_features wacom_features[] = {
584 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 }, 609 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 },
585 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S }, 610 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S },
586 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ }, 611 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ },
587 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 612 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
588 { } 613 { }
589}; 614};
590 615
diff --git a/drivers/usb/input/wacom_wac.h b/drivers/usb/input/wacom_wac.h
index a1d9ce007970..a23022287248 100644
--- a/drivers/usb/input/wacom_wac.h
+++ b/drivers/usb/input/wacom_wac.h
@@ -12,6 +12,7 @@
12#define STYLUS_DEVICE_ID 0x02 12#define STYLUS_DEVICE_ID 0x02
13#define CURSOR_DEVICE_ID 0x06 13#define CURSOR_DEVICE_ID 0x06
14#define ERASER_DEVICE_ID 0x0A 14#define ERASER_DEVICE_ID 0x0A
15#define PAD_DEVICE_ID 0x0F
15 16
16enum { 17enum {
17 PENPARTNER = 0, 18 PENPARTNER = 0,