aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2010-02-25 11:39:16 -0500
committerJiri Kosina <jkosina@suse.cz>2010-02-25 11:39:16 -0500
commit14ef2b0c026558d37662e5e095d59c64597d5769 (patch)
tree230c09cc65bc94384c687fed87e6ada954f80609 /drivers/hid
parent57ab12e418ec4fe24c11788bb1bbdabb29d05679 (diff)
parent71b38bd4c1cc4f2b653064357e4efab77dfd711d (diff)
Merge branches 'upstream', 'raw_report_modifications' and 'apple_magic_mouse' into for-linus
Conflicts: drivers/hid/Kconfig
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/Kconfig9
-rw-r--r--drivers/hid/Makefile1
-rw-r--r--drivers/hid/hid-core.c5
-rw-r--r--drivers/hid/hid-ids.h1
-rw-r--r--drivers/hid/hid-magicmouse.c449
-rw-r--r--drivers/hid/hid-sony.c21
-rw-r--r--drivers/hid/hid-wacom.c28
-rw-r--r--drivers/hid/hidraw.c2
-rw-r--r--drivers/hid/usbhid/hid-core.c5
9 files changed, 515 insertions, 6 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 2b93d7f647ee..71d4c0703629 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -197,6 +197,15 @@ config LOGIG940_FF
197 Say Y here if you want to enable force feedback support for Logitech 197 Say Y here if you want to enable force feedback support for Logitech
198 Flight System G940 devices. 198 Flight System G940 devices.
199 199
200config HID_MAGICMOUSE
201 tristate "Apple MagicMouse multi-touch support"
202 depends on BT_HIDP
203 ---help---
204 Support for the Apple Magic Mouse multi-touch.
205
206 Say Y here if you want support for the multi-touch features of the
207 Apple Wireless "Magic" Mouse.
208
200config HID_MICROSOFT 209config HID_MICROSOFT
201 tristate "Microsoft" if EMBEDDED 210 tristate "Microsoft" if EMBEDDED
202 depends on USB_HID 211 depends on USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 03051694d546..0b2618f092ca 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
35obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o 35obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o
36obj-$(CONFIG_HID_KYE) += hid-kye.o 36obj-$(CONFIG_HID_KYE) += hid-kye.o
37obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o 37obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o
38obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o
38obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o 39obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o
39obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o 40obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o
40obj-$(CONFIG_HID_MOSART) += hid-mosart.o 41obj-$(CONFIG_HID_MOSART) += hid-mosart.o
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index da97195474ff..368fbb0c4ca6 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -51,7 +51,7 @@ EXPORT_SYMBOL_GPL(hid_debug);
51 * Register a new report for a device. 51 * Register a new report for a device.
52 */ 52 */
53 53
54static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id) 54struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
55{ 55{
56 struct hid_report_enum *report_enum = device->report_enum + type; 56 struct hid_report_enum *report_enum = device->report_enum + type;
57 struct hid_report *report; 57 struct hid_report *report;
@@ -75,6 +75,7 @@ static struct hid_report *hid_register_report(struct hid_device *device, unsigne
75 75
76 return report; 76 return report;
77} 77}
78EXPORT_SYMBOL_GPL(hid_register_report);
78 79
79/* 80/*
80 * Register a new field for this report. 81 * Register a new field for this report.
@@ -1255,6 +1256,7 @@ static const struct hid_device_id hid_blacklist[] = {
1255 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, 1256 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
1256 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, 1257 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1257 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, 1258 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1259 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1258 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 1260 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1259 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 1261 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1260 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 1262 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
@@ -1346,6 +1348,7 @@ static const struct hid_device_id hid_blacklist[] = {
1346 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) }, 1348 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
1347 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, 1349 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1348 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1350 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1351 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1349 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, 1352 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1350 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) }, 1353 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
1351 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, 1354 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index ab370f1c4b6e..72c05f90553c 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -59,6 +59,7 @@
59 59
60#define USB_VENDOR_ID_APPLE 0x05ac 60#define USB_VENDOR_ID_APPLE 0x05ac
61#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 61#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
62#define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
62#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e 63#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e
63#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f 64#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f
64#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214 65#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
new file mode 100644
index 000000000000..4a3a94f2b10c
--- /dev/null
+++ b/drivers/hid/hid-magicmouse.c
@@ -0,0 +1,449 @@
1/*
2 * Apple "Magic" Wireless Mouse driver
3 *
4 * Copyright (c) 2010 Michael Poole <mdpoole@troilus.org>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 */
13
14#include <linux/device.h>
15#include <linux/hid.h>
16#include <linux/module.h>
17#include <linux/usb.h>
18
19#include "hid-ids.h"
20
21static bool emulate_3button = true;
22module_param(emulate_3button, bool, 0644);
23MODULE_PARM_DESC(emulate_3button, "Emulate a middle button");
24
25static int middle_button_start = -350;
26static int middle_button_stop = +350;
27
28static bool emulate_scroll_wheel = true;
29module_param(emulate_scroll_wheel, bool, 0644);
30MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
31
32static bool report_touches = true;
33module_param(report_touches, bool, 0644);
34MODULE_PARM_DESC(report_touches, "Emit touch records (otherwise, only use them for emulation)");
35
36static bool report_undeciphered;
37module_param(report_undeciphered, bool, 0644);
38MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
39
40#define TOUCH_REPORT_ID 0x29
41/* These definitions are not precise, but they're close enough. (Bits
42 * 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem
43 * to be some kind of bit mask -- 0x20 may be a near-field reading,
44 * and 0x40 is actual contact, and 0x10 may be a start/stop or change
45 * indication.)
46 */
47#define TOUCH_STATE_MASK 0xf0
48#define TOUCH_STATE_NONE 0x00
49#define TOUCH_STATE_START 0x30
50#define TOUCH_STATE_DRAG 0x40
51
52/**
53 * struct magicmouse_sc - Tracks Magic Mouse-specific data.
54 * @input: Input device through which we report events.
55 * @quirks: Currently unused.
56 * @last_timestamp: Timestamp from most recent (18-bit) touch report
57 * (units of milliseconds over short windows, but seems to
58 * increase faster when there are no touches).
59 * @delta_time: 18-bit difference between the two most recent touch
60 * reports from the mouse.
61 * @ntouches: Number of touches in most recent touch report.
62 * @scroll_accel: Number of consecutive scroll motions.
63 * @scroll_jiffies: Time of last scroll motion.
64 * @touches: Most recent data for a touch, indexed by tracking ID.
65 * @tracking_ids: Mapping of current touch input data to @touches.
66 */
67struct magicmouse_sc {
68 struct input_dev *input;
69 unsigned long quirks;
70
71 int last_timestamp;
72 int delta_time;
73 int ntouches;
74 int scroll_accel;
75 unsigned long scroll_jiffies;
76
77 struct {
78 short x;
79 short y;
80 short scroll_y;
81 u8 size;
82 } touches[16];
83 int tracking_ids[16];
84};
85
86static int magicmouse_firm_touch(struct magicmouse_sc *msc)
87{
88 int touch = -1;
89 int ii;
90
91 /* If there is only one "firm" touch, set touch to its
92 * tracking ID.
93 */
94 for (ii = 0; ii < msc->ntouches; ii++) {
95 int idx = msc->tracking_ids[ii];
96 if (msc->touches[idx].size < 8) {
97 /* Ignore this touch. */
98 } else if (touch >= 0) {
99 touch = -1;
100 break;
101 } else {
102 touch = idx;
103 }
104 }
105
106 return touch;
107}
108
109static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state)
110{
111 int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 |
112 test_bit(BTN_RIGHT, msc->input->key) << 1 |
113 test_bit(BTN_MIDDLE, msc->input->key) << 2;
114
115 if (emulate_3button) {
116 int id;
117
118 /* If some button was pressed before, keep it held
119 * down. Otherwise, if there's exactly one firm
120 * touch, use that to override the mouse's guess.
121 */
122 if (state == 0) {
123 /* The button was released. */
124 } else if (last_state != 0) {
125 state = last_state;
126 } else if ((id = magicmouse_firm_touch(msc)) >= 0) {
127 int x = msc->touches[id].x;
128 if (x < middle_button_start)
129 state = 1;
130 else if (x > middle_button_stop)
131 state = 2;
132 else
133 state = 4;
134 } /* else: we keep the mouse's guess */
135
136 input_report_key(msc->input, BTN_MIDDLE, state & 4);
137 }
138
139 input_report_key(msc->input, BTN_LEFT, state & 1);
140 input_report_key(msc->input, BTN_RIGHT, state & 2);
141
142 if (state != last_state)
143 msc->scroll_accel = 0;
144}
145
146static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
147{
148 struct input_dev *input = msc->input;
149 __s32 x_y = tdata[0] << 8 | tdata[1] << 16 | tdata[2] << 24;
150 int misc = tdata[5] | tdata[6] << 8;
151 int id = (misc >> 6) & 15;
152 int x = x_y << 12 >> 20;
153 int y = -(x_y >> 20);
154
155 /* Store tracking ID and other fields. */
156 msc->tracking_ids[raw_id] = id;
157 msc->touches[id].x = x;
158 msc->touches[id].y = y;
159 msc->touches[id].size = misc & 63;
160
161 /* If requested, emulate a scroll wheel by detecting small
162 * vertical touch motions along the middle of the mouse.
163 */
164 if (emulate_scroll_wheel &&
165 middle_button_start < x && x < middle_button_stop) {
166 static const int accel_profile[] = {
167 256, 228, 192, 160, 128, 96, 64, 32,
168 };
169 unsigned long now = jiffies;
170 int step = msc->touches[id].scroll_y - y;
171
172 /* Reset acceleration after half a second. */
173 if (time_after(now, msc->scroll_jiffies + HZ / 2))
174 msc->scroll_accel = 0;
175
176 /* Calculate and apply the scroll motion. */
177 switch (tdata[7] & TOUCH_STATE_MASK) {
178 case TOUCH_STATE_START:
179 msc->touches[id].scroll_y = y;
180 msc->scroll_accel = min_t(int, msc->scroll_accel + 1,
181 ARRAY_SIZE(accel_profile) - 1);
182 break;
183 case TOUCH_STATE_DRAG:
184 step = step / accel_profile[msc->scroll_accel];
185 if (step != 0) {
186 msc->touches[id].scroll_y = y;
187 msc->scroll_jiffies = now;
188 input_report_rel(input, REL_WHEEL, step);
189 }
190 break;
191 }
192 }
193
194 /* Generate the input events for this touch. */
195 if (report_touches) {
196 int orientation = (misc >> 10) - 32;
197
198 input_report_abs(input, ABS_MT_TRACKING_ID, id);
199 input_report_abs(input, ABS_MT_TOUCH_MAJOR, tdata[3]);
200 input_report_abs(input, ABS_MT_TOUCH_MINOR, tdata[4]);
201 input_report_abs(input, ABS_MT_ORIENTATION, orientation);
202 input_report_abs(input, ABS_MT_POSITION_X, x);
203 input_report_abs(input, ABS_MT_POSITION_Y, y);
204
205 if (report_undeciphered)
206 input_event(input, EV_MSC, MSC_RAW, tdata[7]);
207
208 input_mt_sync(input);
209 }
210}
211
212static int magicmouse_raw_event(struct hid_device *hdev,
213 struct hid_report *report, u8 *data, int size)
214{
215 struct magicmouse_sc *msc = hid_get_drvdata(hdev);
216 struct input_dev *input = msc->input;
217 int x, y, ts, ii, clicks;
218
219 switch (data[0]) {
220 case 0x10:
221 if (size != 6)
222 return 0;
223 x = (__s16)(data[2] | data[3] << 8);
224 y = (__s16)(data[4] | data[5] << 8);
225 clicks = data[1];
226 break;
227 case TOUCH_REPORT_ID:
228 /* Expect six bytes of prefix, and N*8 bytes of touch data. */
229 if (size < 6 || ((size - 6) % 8) != 0)
230 return 0;
231 ts = data[3] >> 6 | data[4] << 2 | data[5] << 10;
232 msc->delta_time = (ts - msc->last_timestamp) & 0x3ffff;
233 msc->last_timestamp = ts;
234 msc->ntouches = (size - 6) / 8;
235 for (ii = 0; ii < msc->ntouches; ii++)
236 magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
237 /* When emulating three-button mode, it is important
238 * to have the current touch information before
239 * generating a click event.
240 */
241 x = (signed char)data[1];
242 y = (signed char)data[2];
243 clicks = data[3];
244 break;
245 case 0x20: /* Theoretically battery status (0-100), but I have
246 * never seen it -- maybe it is only upon request.
247 */
248 case 0x60: /* Unknown, maybe laser on/off. */
249 case 0x61: /* Laser reflection status change.
250 * data[1]: 0 = spotted, 1 = lost
251 */
252 default:
253 return 0;
254 }
255
256 magicmouse_emit_buttons(msc, clicks & 3);
257 input_report_rel(input, REL_X, x);
258 input_report_rel(input, REL_Y, y);
259 input_sync(input);
260 return 1;
261}
262
263static int magicmouse_input_open(struct input_dev *dev)
264{
265 struct hid_device *hid = input_get_drvdata(dev);
266
267 return hid->ll_driver->open(hid);
268}
269
270static void magicmouse_input_close(struct input_dev *dev)
271{
272 struct hid_device *hid = input_get_drvdata(dev);
273
274 hid->ll_driver->close(hid);
275}
276
277static void magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev)
278{
279 input_set_drvdata(input, hdev);
280 input->event = hdev->ll_driver->hidinput_input_event;
281 input->open = magicmouse_input_open;
282 input->close = magicmouse_input_close;
283
284 input->name = hdev->name;
285 input->phys = hdev->phys;
286 input->uniq = hdev->uniq;
287 input->id.bustype = hdev->bus;
288 input->id.vendor = hdev->vendor;
289 input->id.product = hdev->product;
290 input->id.version = hdev->version;
291 input->dev.parent = hdev->dev.parent;
292
293 __set_bit(EV_KEY, input->evbit);
294 __set_bit(BTN_LEFT, input->keybit);
295 __set_bit(BTN_RIGHT, input->keybit);
296 if (emulate_3button)
297 __set_bit(BTN_MIDDLE, input->keybit);
298 __set_bit(BTN_TOOL_FINGER, input->keybit);
299
300 __set_bit(EV_REL, input->evbit);
301 __set_bit(REL_X, input->relbit);
302 __set_bit(REL_Y, input->relbit);
303 if (emulate_scroll_wheel)
304 __set_bit(REL_WHEEL, input->relbit);
305
306 if (report_touches) {
307 __set_bit(EV_ABS, input->evbit);
308
309 input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15, 0, 0);
310 input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 4, 0);
311 input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 4, 0);
312 input_set_abs_params(input, ABS_MT_ORIENTATION, -32, 31, 1, 0);
313 input_set_abs_params(input, ABS_MT_POSITION_X, -1100, 1358,
314 4, 0);
315 /* Note: Touch Y position from the device is inverted relative
316 * to how pointer motion is reported (and relative to how USB
317 * HID recommends the coordinates work). This driver keeps
318 * the origin at the same position, and just uses the additive
319 * inverse of the reported Y.
320 */
321 input_set_abs_params(input, ABS_MT_POSITION_Y, -1589, 2047,
322 4, 0);
323 }
324
325 if (report_undeciphered) {
326 __set_bit(EV_MSC, input->evbit);
327 __set_bit(MSC_RAW, input->mscbit);
328 }
329}
330
331static int magicmouse_probe(struct hid_device *hdev,
332 const struct hid_device_id *id)
333{
334 __u8 feature_1[] = { 0xd7, 0x01 };
335 __u8 feature_2[] = { 0xf8, 0x01, 0x32 };
336 struct input_dev *input;
337 struct magicmouse_sc *msc;
338 struct hid_report *report;
339 int ret;
340
341 msc = kzalloc(sizeof(*msc), GFP_KERNEL);
342 if (msc == NULL) {
343 dev_err(&hdev->dev, "can't alloc magicmouse descriptor\n");
344 return -ENOMEM;
345 }
346
347 msc->quirks = id->driver_data;
348 hid_set_drvdata(hdev, msc);
349
350 ret = hid_parse(hdev);
351 if (ret) {
352 dev_err(&hdev->dev, "magicmouse hid parse failed\n");
353 goto err_free;
354 }
355
356 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
357 if (ret) {
358 dev_err(&hdev->dev, "magicmouse hw start failed\n");
359 goto err_free;
360 }
361
362 report = hid_register_report(hdev, HID_INPUT_REPORT, TOUCH_REPORT_ID);
363 if (!report) {
364 dev_err(&hdev->dev, "unable to register touch report\n");
365 ret = -ENOMEM;
366 goto err_stop_hw;
367 }
368 report->size = 6;
369
370 ret = hdev->hid_output_raw_report(hdev, feature_1, sizeof(feature_1),
371 HID_FEATURE_REPORT);
372 if (ret != sizeof(feature_1)) {
373 dev_err(&hdev->dev, "unable to request touch data (1:%d)\n",
374 ret);
375 goto err_stop_hw;
376 }
377 ret = hdev->hid_output_raw_report(hdev, feature_2,
378 sizeof(feature_2), HID_FEATURE_REPORT);
379 if (ret != sizeof(feature_2)) {
380 dev_err(&hdev->dev, "unable to request touch data (2:%d)\n",
381 ret);
382 goto err_stop_hw;
383 }
384
385 input = input_allocate_device();
386 if (!input) {
387 dev_err(&hdev->dev, "can't alloc input device\n");
388 ret = -ENOMEM;
389 goto err_stop_hw;
390 }
391 magicmouse_setup_input(input, hdev);
392
393 ret = input_register_device(input);
394 if (ret) {
395 dev_err(&hdev->dev, "input device registration failed\n");
396 goto err_input;
397 }
398 msc->input = input;
399
400 return 0;
401err_input:
402 input_free_device(input);
403err_stop_hw:
404 hid_hw_stop(hdev);
405err_free:
406 kfree(msc);
407 return ret;
408}
409
410static void magicmouse_remove(struct hid_device *hdev)
411{
412 hid_hw_stop(hdev);
413 kfree(hid_get_drvdata(hdev));
414}
415
416static const struct hid_device_id magic_mice[] = {
417 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE),
418 .driver_data = 0 },
419 { }
420};
421MODULE_DEVICE_TABLE(hid, magic_mice);
422
423static struct hid_driver magicmouse_driver = {
424 .name = "magicmouse",
425 .id_table = magic_mice,
426 .probe = magicmouse_probe,
427 .remove = magicmouse_remove,
428 .raw_event = magicmouse_raw_event,
429};
430
431static int __init magicmouse_init(void)
432{
433 int ret;
434
435 ret = hid_register_driver(&magicmouse_driver);
436 if (ret)
437 printk(KERN_ERR "can't register magicmouse driver\n");
438
439 return ret;
440}
441
442static void __exit magicmouse_exit(void)
443{
444 hid_unregister_driver(&magicmouse_driver);
445}
446
447module_init(magicmouse_init);
448module_exit(magicmouse_exit);
449MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 96d723ea5131..9bf00d77d92b 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -48,7 +48,7 @@ static void sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
48 * to "operational". Without this, the ps3 controller will not report any 48 * to "operational". Without this, the ps3 controller will not report any
49 * events. 49 * events.
50 */ 50 */
51static int sony_set_operational(struct hid_device *hdev) 51static int sony_set_operational_usb(struct hid_device *hdev)
52{ 52{
53 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 53 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
54 struct usb_device *dev = interface_to_usbdev(intf); 54 struct usb_device *dev = interface_to_usbdev(intf);
@@ -73,6 +73,12 @@ static int sony_set_operational(struct hid_device *hdev)
73 return ret; 73 return ret;
74} 74}
75 75
76static int sony_set_operational_bt(struct hid_device *hdev)
77{
78 unsigned char buf[] = { 0x53, 0xf4, 0x42, 0x03, 0x00, 0x00 };
79 return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
80}
81
76static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) 82static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
77{ 83{
78 int ret; 84 int ret;
@@ -101,7 +107,17 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
101 goto err_free; 107 goto err_free;
102 } 108 }
103 109
104 ret = sony_set_operational(hdev); 110 switch (hdev->bus) {
111 case BUS_USB:
112 ret = sony_set_operational_usb(hdev);
113 break;
114 case BUS_BLUETOOTH:
115 ret = sony_set_operational_bt(hdev);
116 break;
117 default:
118 ret = 0;
119 }
120
105 if (ret < 0) 121 if (ret < 0)
106 goto err_stop; 122 goto err_stop;
107 123
@@ -121,6 +137,7 @@ static void sony_remove(struct hid_device *hdev)
121 137
122static const struct hid_device_id sony_devices[] = { 138static const struct hid_device_id sony_devices[] = {
123 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 139 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
140 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
124 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE), 141 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
125 .driver_data = VAIO_RDESC_CONSTANT }, 142 .driver_data = VAIO_RDESC_CONSTANT },
126 { } 143 { }
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c
index 12dcda529201..8d3b46f5d149 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -156,7 +156,9 @@ static int wacom_probe(struct hid_device *hdev,
156 struct hid_input *hidinput; 156 struct hid_input *hidinput;
157 struct input_dev *input; 157 struct input_dev *input;
158 struct wacom_data *wdata; 158 struct wacom_data *wdata;
159 char rep_data[2];
159 int ret; 160 int ret;
161 int limit;
160 162
161 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); 163 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
162 if (wdata == NULL) { 164 if (wdata == NULL) {
@@ -166,6 +168,7 @@ static int wacom_probe(struct hid_device *hdev,
166 168
167 hid_set_drvdata(hdev, wdata); 169 hid_set_drvdata(hdev, wdata);
168 170
171 /* Parse the HID report now */
169 ret = hid_parse(hdev); 172 ret = hid_parse(hdev);
170 if (ret) { 173 if (ret) {
171 dev_err(&hdev->dev, "parse failed\n"); 174 dev_err(&hdev->dev, "parse failed\n");
@@ -178,6 +181,31 @@ static int wacom_probe(struct hid_device *hdev,
178 goto err_free; 181 goto err_free;
179 } 182 }
180 183
184 /*
185 * Note that if the raw queries fail, it's not a hard failure and it
186 * is safe to continue
187 */
188
189 /* Set Wacom mode2 */
190 rep_data[0] = 0x03; rep_data[1] = 0x00;
191 limit = 3;
192 do {
193 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
194 HID_FEATURE_REPORT);
195 } while (ret < 0 && limit-- > 0);
196 if (ret < 0)
197 dev_warn(&hdev->dev, "failed to poke device #1, %d\n", ret);
198
199 /* 0x06 - high reporting speed, 0x05 - low speed */
200 rep_data[0] = 0x06; rep_data[1] = 0x00;
201 limit = 3;
202 do {
203 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
204 HID_FEATURE_REPORT);
205 } while (ret < 0 && limit-- > 0);
206 if (ret < 0)
207 dev_warn(&hdev->dev, "failed to poke device #2, %d\n", ret);
208
181 hidinput = list_entry(hdev->inputs.next, struct hid_input, list); 209 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
182 input = hidinput->input; 210 input = hidinput->input;
183 211
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index cdd136942bca..d04476700b7b 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -134,7 +134,7 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t
134 goto out; 134 goto out;
135 } 135 }
136 136
137 ret = dev->hid_output_raw_report(dev, buf, count); 137 ret = dev->hid_output_raw_report(dev, buf, count, HID_OUTPUT_REPORT);
138out: 138out:
139 kfree(buf); 139 kfree(buf);
140 return ret; 140 return ret;
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index ceaf4a14b67b..56d06cd8075b 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -798,7 +798,8 @@ static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
798 return 0; 798 return 0;
799} 799}
800 800
801static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count) 801static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count,
802 unsigned char report_type)
802{ 803{
803 struct usbhid_device *usbhid = hid->driver_data; 804 struct usbhid_device *usbhid = hid->driver_data;
804 struct usb_device *dev = hid_to_usb_dev(hid); 805 struct usb_device *dev = hid_to_usb_dev(hid);
@@ -809,7 +810,7 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co
809 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 810 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
810 HID_REQ_SET_REPORT, 811 HID_REQ_SET_REPORT,
811 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 812 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
812 ((HID_OUTPUT_REPORT + 1) << 8) | *buf, 813 ((report_type + 1) << 8) | *buf,
813 interface->desc.bInterfaceNumber, buf + 1, count - 1, 814 interface->desc.bInterfaceNumber, buf + 1, count - 1,
814 USB_CTRL_SET_TIMEOUT); 815 USB_CTRL_SET_TIMEOUT);
815 816