2 * HID driver for Sony / PS2 / PS3 BD devices.
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) 2008 Jiri Slaby
8 * Copyright (c) 2012 David Dillow <dave@thedillows.org>
9 * Copyright (c) 2006-2013 Jiri Kosina
10 * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option)
21 * NOTE: in order for the Sony PS3 BD Remote Control to be found by
22 * a Bluetooth host, the key combination Start+Enter has to be kept pressed
23 * for about 7 seconds with the Bluetooth Host Controller in discovering mode.
25 * There will be no PIN request from the device.
28 #include <linux/device.h>
29 #include <linux/hid.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/leds.h>
33 #include <linux/power_supply.h>
34 #include <linux/spinlock.h>
35 #include <linux/list.h>
36 #include <linux/idr.h>
37 #include <linux/input/mt.h>
41 #define VAIO_RDESC_CONSTANT BIT(0)
42 #define SIXAXIS_CONTROLLER_USB BIT(1)
43 #define SIXAXIS_CONTROLLER_BT BIT(2)
44 #define BUZZ_CONTROLLER BIT(3)
45 #define PS3REMOTE BIT(4)
46 #define DUALSHOCK4_CONTROLLER_USB BIT(5)
47 #define DUALSHOCK4_CONTROLLER_BT BIT(6)
49 #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)
50 #define DUALSHOCK4_CONTROLLER (DUALSHOCK4_CONTROLLER_USB |\
51 DUALSHOCK4_CONTROLLER_BT)
52 #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER | BUZZ_CONTROLLER |\
53 DUALSHOCK4_CONTROLLER)
54 #define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER)
55 #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER)
59 static __u8 sixaxis_rdesc[] = {
60 0x05, 0x01, /* Usage Page (Desktop), */
61 0x09, 0x04, /* Usage (Joystik), */
62 0xA1, 0x01, /* Collection (Application), */
63 0xA1, 0x02, /* Collection (Logical), */
64 0x85, 0x01, /* Report ID (1), */
65 0x75, 0x08, /* Report Size (8), */
66 0x95, 0x01, /* Report Count (1), */
67 0x15, 0x00, /* Logical Minimum (0), */
68 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
69 0x81, 0x03, /* Input (Constant, Variable), */
70 0x75, 0x01, /* Report Size (1), */
71 0x95, 0x13, /* Report Count (19), */
72 0x15, 0x00, /* Logical Minimum (0), */
73 0x25, 0x01, /* Logical Maximum (1), */
74 0x35, 0x00, /* Physical Minimum (0), */
75 0x45, 0x01, /* Physical Maximum (1), */
76 0x05, 0x09, /* Usage Page (Button), */
77 0x19, 0x01, /* Usage Minimum (01h), */
78 0x29, 0x13, /* Usage Maximum (13h), */
79 0x81, 0x02, /* Input (Variable), */
80 0x75, 0x01, /* Report Size (1), */
81 0x95, 0x0D, /* Report Count (13), */
82 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
83 0x81, 0x03, /* Input (Constant, Variable), */
84 0x15, 0x00, /* Logical Minimum (0), */
85 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
86 0x05, 0x01, /* Usage Page (Desktop), */
87 0x09, 0x01, /* Usage (Pointer), */
88 0xA1, 0x00, /* Collection (Physical), */
89 0x75, 0x08, /* Report Size (8), */
90 0x95, 0x04, /* Report Count (4), */
91 0x35, 0x00, /* Physical Minimum (0), */
92 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
93 0x09, 0x30, /* Usage (X), */
94 0x09, 0x31, /* Usage (Y), */
95 0x09, 0x32, /* Usage (Z), */
96 0x09, 0x35, /* Usage (Rz), */
97 0x81, 0x02, /* Input (Variable), */
98 0xC0, /* End Collection, */
99 0x05, 0x01, /* Usage Page (Desktop), */
100 0x95, 0x13, /* Report Count (19), */
101 0x09, 0x01, /* Usage (Pointer), */
102 0x81, 0x02, /* Input (Variable), */
103 0x95, 0x0C, /* Report Count (12), */
104 0x81, 0x01, /* Input (Constant), */
105 0x75, 0x10, /* Report Size (16), */
106 0x95, 0x04, /* Report Count (4), */
107 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
108 0x46, 0xFF, 0x03, /* Physical Maximum (1023), */
109 0x09, 0x01, /* Usage (Pointer), */
110 0x81, 0x02, /* Input (Variable), */
111 0xC0, /* End Collection, */
112 0xA1, 0x02, /* Collection (Logical), */
113 0x85, 0x02, /* Report ID (2), */
114 0x75, 0x08, /* Report Size (8), */
115 0x95, 0x30, /* Report Count (48), */
116 0x09, 0x01, /* Usage (Pointer), */
117 0xB1, 0x02, /* Feature (Variable), */
118 0xC0, /* End Collection, */
119 0xA1, 0x02, /* Collection (Logical), */
120 0x85, 0xEE, /* Report ID (238), */
121 0x75, 0x08, /* Report Size (8), */
122 0x95, 0x30, /* Report Count (48), */
123 0x09, 0x01, /* Usage (Pointer), */
124 0xB1, 0x02, /* Feature (Variable), */
125 0xC0, /* End Collection, */
126 0xA1, 0x02, /* Collection (Logical), */
127 0x85, 0xEF, /* Report ID (239), */
128 0x75, 0x08, /* Report Size (8), */
129 0x95, 0x30, /* Report Count (48), */
130 0x09, 0x01, /* Usage (Pointer), */
131 0xB1, 0x02, /* Feature (Variable), */
132 0xC0, /* End Collection, */
133 0xC0 /* End Collection */
137 * The default descriptor doesn't provide mapping for the accelerometers
138 * or orientation sensors. This fixed descriptor maps the accelerometers
139 * to usage values 0x40, 0x41 and 0x42 and maps the orientation sensors
140 * to usage values 0x43, 0x44 and 0x45.
142 static u8 dualshock4_usb_rdesc[] = {
143 0x05, 0x01, /* Usage Page (Desktop), */
144 0x09, 0x05, /* Usage (Gamepad), */
145 0xA1, 0x01, /* Collection (Application), */
146 0x85, 0x01, /* Report ID (1), */
147 0x09, 0x30, /* Usage (X), */
148 0x09, 0x31, /* Usage (Y), */
149 0x09, 0x32, /* Usage (Z), */
150 0x09, 0x35, /* Usage (Rz), */
151 0x15, 0x00, /* Logical Minimum (0), */
152 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
153 0x75, 0x08, /* Report Size (8), */
154 0x95, 0x04, /* Report Count (4), */
155 0x81, 0x02, /* Input (Variable), */
156 0x09, 0x39, /* Usage (Hat Switch), */
157 0x15, 0x00, /* Logical Minimum (0), */
158 0x25, 0x07, /* Logical Maximum (7), */
159 0x35, 0x00, /* Physical Minimum (0), */
160 0x46, 0x3B, 0x01, /* Physical Maximum (315), */
161 0x65, 0x14, /* Unit (Degrees), */
162 0x75, 0x04, /* Report Size (4), */
163 0x95, 0x01, /* Report Count (1), */
164 0x81, 0x42, /* Input (Variable, Null State), */
165 0x65, 0x00, /* Unit, */
166 0x05, 0x09, /* Usage Page (Button), */
167 0x19, 0x01, /* Usage Minimum (01h), */
168 0x29, 0x0E, /* Usage Maximum (0Eh), */
169 0x15, 0x00, /* Logical Minimum (0), */
170 0x25, 0x01, /* Logical Maximum (1), */
171 0x75, 0x01, /* Report Size (1), */
172 0x95, 0x0E, /* Report Count (14), */
173 0x81, 0x02, /* Input (Variable), */
174 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
175 0x09, 0x20, /* Usage (20h), */
176 0x75, 0x06, /* Report Size (6), */
177 0x95, 0x01, /* Report Count (1), */
178 0x15, 0x00, /* Logical Minimum (0), */
179 0x25, 0x7F, /* Logical Maximum (127), */
180 0x81, 0x02, /* Input (Variable), */
181 0x05, 0x01, /* Usage Page (Desktop), */
182 0x09, 0x33, /* Usage (Rx), */
183 0x09, 0x34, /* Usage (Ry), */
184 0x15, 0x00, /* Logical Minimum (0), */
185 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
186 0x75, 0x08, /* Report Size (8), */
187 0x95, 0x02, /* Report Count (2), */
188 0x81, 0x02, /* Input (Variable), */
189 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
190 0x09, 0x21, /* Usage (21h), */
191 0x95, 0x03, /* Report Count (3), */
192 0x81, 0x02, /* Input (Variable), */
193 0x05, 0x01, /* Usage Page (Desktop), */
194 0x19, 0x40, /* Usage Minimum (40h), */
195 0x29, 0x42, /* Usage Maximum (42h), */
196 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */
197 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */
198 0x75, 0x10, /* Report Size (16), */
199 0x95, 0x03, /* Report Count (3), */
200 0x81, 0x02, /* Input (Variable), */
201 0x19, 0x43, /* Usage Minimum (43h), */
202 0x29, 0x45, /* Usage Maximum (45h), */
203 0x16, 0xFF, 0xBF, /* Logical Minimum (-16385), */
204 0x26, 0x00, 0x40, /* Logical Maximum (16384), */
205 0x95, 0x03, /* Report Count (3), */
206 0x81, 0x02, /* Input (Variable), */
207 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
208 0x09, 0x21, /* Usage (21h), */
209 0x15, 0x00, /* Logical Minimum (0), */
210 0x25, 0xFF, /* Logical Maximum (255), */
211 0x75, 0x08, /* Report Size (8), */
212 0x95, 0x27, /* Report Count (39), */
213 0x81, 0x02, /* Input (Variable), */
214 0x85, 0x05, /* Report ID (5), */
215 0x09, 0x22, /* Usage (22h), */
216 0x95, 0x1F, /* Report Count (31), */
217 0x91, 0x02, /* Output (Variable), */
218 0x85, 0x04, /* Report ID (4), */
219 0x09, 0x23, /* Usage (23h), */
220 0x95, 0x24, /* Report Count (36), */
221 0xB1, 0x02, /* Feature (Variable), */
222 0x85, 0x02, /* Report ID (2), */
223 0x09, 0x24, /* Usage (24h), */
224 0x95, 0x24, /* Report Count (36), */
225 0xB1, 0x02, /* Feature (Variable), */
226 0x85, 0x08, /* Report ID (8), */
227 0x09, 0x25, /* Usage (25h), */
228 0x95, 0x03, /* Report Count (3), */
229 0xB1, 0x02, /* Feature (Variable), */
230 0x85, 0x10, /* Report ID (16), */
231 0x09, 0x26, /* Usage (26h), */
232 0x95, 0x04, /* Report Count (4), */
233 0xB1, 0x02, /* Feature (Variable), */
234 0x85, 0x11, /* Report ID (17), */
235 0x09, 0x27, /* Usage (27h), */
236 0x95, 0x02, /* Report Count (2), */
237 0xB1, 0x02, /* Feature (Variable), */
238 0x85, 0x12, /* Report ID (18), */
239 0x06, 0x02, 0xFF, /* Usage Page (FF02h), */
240 0x09, 0x21, /* Usage (21h), */
241 0x95, 0x0F, /* Report Count (15), */
242 0xB1, 0x02, /* Feature (Variable), */
243 0x85, 0x13, /* Report ID (19), */
244 0x09, 0x22, /* Usage (22h), */
245 0x95, 0x16, /* Report Count (22), */
246 0xB1, 0x02, /* Feature (Variable), */
247 0x85, 0x14, /* Report ID (20), */
248 0x06, 0x05, 0xFF, /* Usage Page (FF05h), */
249 0x09, 0x20, /* Usage (20h), */
250 0x95, 0x10, /* Report Count (16), */
251 0xB1, 0x02, /* Feature (Variable), */
252 0x85, 0x15, /* Report ID (21), */
253 0x09, 0x21, /* Usage (21h), */
254 0x95, 0x2C, /* Report Count (44), */
255 0xB1, 0x02, /* Feature (Variable), */
256 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */
257 0x85, 0x80, /* Report ID (128), */
258 0x09, 0x20, /* Usage (20h), */
259 0x95, 0x06, /* Report Count (6), */
260 0xB1, 0x02, /* Feature (Variable), */
261 0x85, 0x81, /* Report ID (129), */
262 0x09, 0x21, /* Usage (21h), */
263 0x95, 0x06, /* Report Count (6), */
264 0xB1, 0x02, /* Feature (Variable), */
265 0x85, 0x82, /* Report ID (130), */
266 0x09, 0x22, /* Usage (22h), */
267 0x95, 0x05, /* Report Count (5), */
268 0xB1, 0x02, /* Feature (Variable), */
269 0x85, 0x83, /* Report ID (131), */
270 0x09, 0x23, /* Usage (23h), */
271 0x95, 0x01, /* Report Count (1), */
272 0xB1, 0x02, /* Feature (Variable), */
273 0x85, 0x84, /* Report ID (132), */
274 0x09, 0x24, /* Usage (24h), */
275 0x95, 0x04, /* Report Count (4), */
276 0xB1, 0x02, /* Feature (Variable), */
277 0x85, 0x85, /* Report ID (133), */
278 0x09, 0x25, /* Usage (25h), */
279 0x95, 0x06, /* Report Count (6), */
280 0xB1, 0x02, /* Feature (Variable), */
281 0x85, 0x86, /* Report ID (134), */
282 0x09, 0x26, /* Usage (26h), */
283 0x95, 0x06, /* Report Count (6), */
284 0xB1, 0x02, /* Feature (Variable), */
285 0x85, 0x87, /* Report ID (135), */
286 0x09, 0x27, /* Usage (27h), */
287 0x95, 0x23, /* Report Count (35), */
288 0xB1, 0x02, /* Feature (Variable), */
289 0x85, 0x88, /* Report ID (136), */
290 0x09, 0x28, /* Usage (28h), */
291 0x95, 0x22, /* Report Count (34), */
292 0xB1, 0x02, /* Feature (Variable), */
293 0x85, 0x89, /* Report ID (137), */
294 0x09, 0x29, /* Usage (29h), */
295 0x95, 0x02, /* Report Count (2), */
296 0xB1, 0x02, /* Feature (Variable), */
297 0x85, 0x90, /* Report ID (144), */
298 0x09, 0x30, /* Usage (30h), */
299 0x95, 0x05, /* Report Count (5), */
300 0xB1, 0x02, /* Feature (Variable), */
301 0x85, 0x91, /* Report ID (145), */
302 0x09, 0x31, /* Usage (31h), */
303 0x95, 0x03, /* Report Count (3), */
304 0xB1, 0x02, /* Feature (Variable), */
305 0x85, 0x92, /* Report ID (146), */
306 0x09, 0x32, /* Usage (32h), */
307 0x95, 0x03, /* Report Count (3), */
308 0xB1, 0x02, /* Feature (Variable), */
309 0x85, 0x93, /* Report ID (147), */
310 0x09, 0x33, /* Usage (33h), */
311 0x95, 0x0C, /* Report Count (12), */
312 0xB1, 0x02, /* Feature (Variable), */
313 0x85, 0xA0, /* Report ID (160), */
314 0x09, 0x40, /* Usage (40h), */
315 0x95, 0x06, /* Report Count (6), */
316 0xB1, 0x02, /* Feature (Variable), */
317 0x85, 0xA1, /* Report ID (161), */
318 0x09, 0x41, /* Usage (41h), */
319 0x95, 0x01, /* Report Count (1), */
320 0xB1, 0x02, /* Feature (Variable), */
321 0x85, 0xA2, /* Report ID (162), */
322 0x09, 0x42, /* Usage (42h), */
323 0x95, 0x01, /* Report Count (1), */
324 0xB1, 0x02, /* Feature (Variable), */
325 0x85, 0xA3, /* Report ID (163), */
326 0x09, 0x43, /* Usage (43h), */
327 0x95, 0x30, /* Report Count (48), */
328 0xB1, 0x02, /* Feature (Variable), */
329 0x85, 0xA4, /* Report ID (164), */
330 0x09, 0x44, /* Usage (44h), */
331 0x95, 0x0D, /* Report Count (13), */
332 0xB1, 0x02, /* Feature (Variable), */
333 0x85, 0xA5, /* Report ID (165), */
334 0x09, 0x45, /* Usage (45h), */
335 0x95, 0x15, /* Report Count (21), */
336 0xB1, 0x02, /* Feature (Variable), */
337 0x85, 0xA6, /* Report ID (166), */
338 0x09, 0x46, /* Usage (46h), */
339 0x95, 0x15, /* Report Count (21), */
340 0xB1, 0x02, /* Feature (Variable), */
341 0x85, 0xF0, /* Report ID (240), */
342 0x09, 0x47, /* Usage (47h), */
343 0x95, 0x3F, /* Report Count (63), */
344 0xB1, 0x02, /* Feature (Variable), */
345 0x85, 0xF1, /* Report ID (241), */
346 0x09, 0x48, /* Usage (48h), */
347 0x95, 0x3F, /* Report Count (63), */
348 0xB1, 0x02, /* Feature (Variable), */
349 0x85, 0xF2, /* Report ID (242), */
350 0x09, 0x49, /* Usage (49h), */
351 0x95, 0x0F, /* Report Count (15), */
352 0xB1, 0x02, /* Feature (Variable), */
353 0x85, 0xA7, /* Report ID (167), */
354 0x09, 0x4A, /* Usage (4Ah), */
355 0x95, 0x01, /* Report Count (1), */
356 0xB1, 0x02, /* Feature (Variable), */
357 0x85, 0xA8, /* Report ID (168), */
358 0x09, 0x4B, /* Usage (4Bh), */
359 0x95, 0x01, /* Report Count (1), */
360 0xB1, 0x02, /* Feature (Variable), */
361 0x85, 0xA9, /* Report ID (169), */
362 0x09, 0x4C, /* Usage (4Ch), */
363 0x95, 0x08, /* Report Count (8), */
364 0xB1, 0x02, /* Feature (Variable), */
365 0x85, 0xAA, /* Report ID (170), */
366 0x09, 0x4E, /* Usage (4Eh), */
367 0x95, 0x01, /* Report Count (1), */
368 0xB1, 0x02, /* Feature (Variable), */
369 0x85, 0xAB, /* Report ID (171), */
370 0x09, 0x4F, /* Usage (4Fh), */
371 0x95, 0x39, /* Report Count (57), */
372 0xB1, 0x02, /* Feature (Variable), */
373 0x85, 0xAC, /* Report ID (172), */
374 0x09, 0x50, /* Usage (50h), */
375 0x95, 0x39, /* Report Count (57), */
376 0xB1, 0x02, /* Feature (Variable), */
377 0x85, 0xAD, /* Report ID (173), */
378 0x09, 0x51, /* Usage (51h), */
379 0x95, 0x0B, /* Report Count (11), */
380 0xB1, 0x02, /* Feature (Variable), */
381 0x85, 0xAE, /* Report ID (174), */
382 0x09, 0x52, /* Usage (52h), */
383 0x95, 0x01, /* Report Count (1), */
384 0xB1, 0x02, /* Feature (Variable), */
385 0x85, 0xAF, /* Report ID (175), */
386 0x09, 0x53, /* Usage (53h), */
387 0x95, 0x02, /* Report Count (2), */
388 0xB1, 0x02, /* Feature (Variable), */
389 0x85, 0xB0, /* Report ID (176), */
390 0x09, 0x54, /* Usage (54h), */
391 0x95, 0x3F, /* Report Count (63), */
392 0xB1, 0x02, /* Feature (Variable), */
393 0xC0 /* End Collection */
397 * The default behavior of the Dualshock 4 is to send reports using report
398 * type 1 when running over Bluetooth. However, as soon as it receives a
399 * report of type 17 to set the LEDs or rumble it starts returning it's state
400 * in report 17 instead of 1. Since report 17 is undefined in the default HID
401 * descriptor the button and axis definitions must be moved to report 17 or
402 * the HID layer won't process the received input once a report is sent.
404 static u8 dualshock4_bt_rdesc[] = {
405 0x05, 0x01, /* Usage Page (Desktop), */
406 0x09, 0x05, /* Usage (Gamepad), */
407 0xA1, 0x01, /* Collection (Application), */
408 0x85, 0x01, /* Report ID (1), */
409 0x75, 0x08, /* Report Size (8), */
410 0x95, 0x0A, /* Report Count (9), */
411 0x81, 0x02, /* Input (Variable), */
412 0x06, 0x04, 0xFF, /* Usage Page (FF04h), */
413 0x85, 0x02, /* Report ID (2), */
414 0x09, 0x24, /* Usage (24h), */
415 0x95, 0x24, /* Report Count (36), */
416 0xB1, 0x02, /* Feature (Variable), */
417 0x85, 0xA3, /* Report ID (163), */
418 0x09, 0x25, /* Usage (25h), */
419 0x95, 0x30, /* Report Count (48), */
420 0xB1, 0x02, /* Feature (Variable), */
421 0x85, 0x05, /* Report ID (5), */
422 0x09, 0x26, /* Usage (26h), */
423 0x95, 0x28, /* Report Count (40), */
424 0xB1, 0x02, /* Feature (Variable), */
425 0x85, 0x06, /* Report ID (6), */
426 0x09, 0x27, /* Usage (27h), */
427 0x95, 0x34, /* Report Count (52), */
428 0xB1, 0x02, /* Feature (Variable), */
429 0x85, 0x07, /* Report ID (7), */
430 0x09, 0x28, /* Usage (28h), */
431 0x95, 0x30, /* Report Count (48), */
432 0xB1, 0x02, /* Feature (Variable), */
433 0x85, 0x08, /* Report ID (8), */
434 0x09, 0x29, /* Usage (29h), */
435 0x95, 0x2F, /* Report Count (47), */
436 0xB1, 0x02, /* Feature (Variable), */
437 0x06, 0x03, 0xFF, /* Usage Page (FF03h), */
438 0x85, 0x03, /* Report ID (3), */
439 0x09, 0x21, /* Usage (21h), */
440 0x95, 0x26, /* Report Count (38), */
441 0xB1, 0x02, /* Feature (Variable), */
442 0x85, 0x04, /* Report ID (4), */
443 0x09, 0x22, /* Usage (22h), */
444 0x95, 0x2E, /* Report Count (46), */
445 0xB1, 0x02, /* Feature (Variable), */
446 0x85, 0xF0, /* Report ID (240), */
447 0x09, 0x47, /* Usage (47h), */
448 0x95, 0x3F, /* Report Count (63), */
449 0xB1, 0x02, /* Feature (Variable), */
450 0x85, 0xF1, /* Report ID (241), */
451 0x09, 0x48, /* Usage (48h), */
452 0x95, 0x3F, /* Report Count (63), */
453 0xB1, 0x02, /* Feature (Variable), */
454 0x85, 0xF2, /* Report ID (242), */
455 0x09, 0x49, /* Usage (49h), */
456 0x95, 0x0F, /* Report Count (15), */
457 0xB1, 0x02, /* Feature (Variable), */
458 0x85, 0x11, /* Report ID (17), */
459 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
460 0x09, 0x20, /* Usage (20h), */
461 0x95, 0x02, /* Report Count (2), */
462 0x81, 0x02, /* Input (Variable), */
463 0x05, 0x01, /* Usage Page (Desktop), */
464 0x09, 0x30, /* Usage (X), */
465 0x09, 0x31, /* Usage (Y), */
466 0x09, 0x32, /* Usage (Z), */
467 0x09, 0x35, /* Usage (Rz), */
468 0x15, 0x00, /* Logical Minimum (0), */
469 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
470 0x75, 0x08, /* Report Size (8), */
471 0x95, 0x04, /* Report Count (4), */
472 0x81, 0x02, /* Input (Variable), */
473 0x09, 0x39, /* Usage (Hat Switch), */
474 0x15, 0x00, /* Logical Minimum (0), */
475 0x25, 0x07, /* Logical Maximum (7), */
476 0x75, 0x04, /* Report Size (4), */
477 0x95, 0x01, /* Report Count (1), */
478 0x81, 0x42, /* Input (Variable, Null State), */
479 0x05, 0x09, /* Usage Page (Button), */
480 0x19, 0x01, /* Usage Minimum (01h), */
481 0x29, 0x0E, /* Usage Maximum (0Eh), */
482 0x15, 0x00, /* Logical Minimum (0), */
483 0x25, 0x01, /* Logical Maximum (1), */
484 0x75, 0x01, /* Report Size (1), */
485 0x95, 0x0E, /* Report Count (14), */
486 0x81, 0x02, /* Input (Variable), */
487 0x75, 0x06, /* Report Size (6), */
488 0x95, 0x01, /* Report Count (1), */
489 0x81, 0x01, /* Input (Constant), */
490 0x05, 0x01, /* Usage Page (Desktop), */
491 0x09, 0x33, /* Usage (Rx), */
492 0x09, 0x34, /* Usage (Ry), */
493 0x15, 0x00, /* Logical Minimum (0), */
494 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
495 0x75, 0x08, /* Report Size (8), */
496 0x95, 0x02, /* Report Count (2), */
497 0x81, 0x02, /* Input (Variable), */
498 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
499 0x09, 0x20, /* Usage (20h), */
500 0x95, 0x03, /* Report Count (3), */
501 0x81, 0x02, /* Input (Variable), */
502 0x05, 0x01, /* Usage Page (Desktop), */
503 0x19, 0x40, /* Usage Minimum (40h), */
504 0x29, 0x42, /* Usage Maximum (42h), */
505 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */
506 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */
507 0x75, 0x10, /* Report Size (16), */
508 0x95, 0x03, /* Report Count (3), */
509 0x81, 0x02, /* Input (Variable), */
510 0x19, 0x43, /* Usage Minimum (43h), */
511 0x29, 0x45, /* Usage Maximum (45h), */
512 0x16, 0xFF, 0xBF, /* Logical Minimum (-16385), */
513 0x26, 0x00, 0x40, /* Logical Maximum (16384), */
514 0x95, 0x03, /* Report Count (3), */
515 0x81, 0x02, /* Input (Variable), */
516 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
517 0x09, 0x20, /* Usage (20h), */
518 0x15, 0x00, /* Logical Minimum (0), */
519 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
520 0x75, 0x08, /* Report Size (8), */
521 0x95, 0x31, /* Report Count (51), */
522 0x81, 0x02, /* Input (Variable), */
523 0x09, 0x21, /* Usage (21h), */
524 0x75, 0x08, /* Report Size (8), */
525 0x95, 0x4D, /* Report Count (77), */
526 0x91, 0x02, /* Output (Variable), */
527 0x85, 0x12, /* Report ID (18), */
528 0x09, 0x22, /* Usage (22h), */
529 0x95, 0x8D, /* Report Count (141), */
530 0x81, 0x02, /* Input (Variable), */
531 0x09, 0x23, /* Usage (23h), */
532 0x91, 0x02, /* Output (Variable), */
533 0x85, 0x13, /* Report ID (19), */
534 0x09, 0x24, /* Usage (24h), */
535 0x95, 0xCD, /* Report Count (205), */
536 0x81, 0x02, /* Input (Variable), */
537 0x09, 0x25, /* Usage (25h), */
538 0x91, 0x02, /* Output (Variable), */
539 0x85, 0x14, /* Report ID (20), */
540 0x09, 0x26, /* Usage (26h), */
541 0x96, 0x0D, 0x01, /* Report Count (269), */
542 0x81, 0x02, /* Input (Variable), */
543 0x09, 0x27, /* Usage (27h), */
544 0x91, 0x02, /* Output (Variable), */
545 0x85, 0x15, /* Report ID (21), */
546 0x09, 0x28, /* Usage (28h), */
547 0x96, 0x4D, 0x01, /* Report Count (333), */
548 0x81, 0x02, /* Input (Variable), */
549 0x09, 0x29, /* Usage (29h), */
550 0x91, 0x02, /* Output (Variable), */
551 0x85, 0x16, /* Report ID (22), */
552 0x09, 0x2A, /* Usage (2Ah), */
553 0x96, 0x8D, 0x01, /* Report Count (397), */
554 0x81, 0x02, /* Input (Variable), */
555 0x09, 0x2B, /* Usage (2Bh), */
556 0x91, 0x02, /* Output (Variable), */
557 0x85, 0x17, /* Report ID (23), */
558 0x09, 0x2C, /* Usage (2Ch), */
559 0x96, 0xCD, 0x01, /* Report Count (461), */
560 0x81, 0x02, /* Input (Variable), */
561 0x09, 0x2D, /* Usage (2Dh), */
562 0x91, 0x02, /* Output (Variable), */
563 0x85, 0x18, /* Report ID (24), */
564 0x09, 0x2E, /* Usage (2Eh), */
565 0x96, 0x0D, 0x02, /* Report Count (525), */
566 0x81, 0x02, /* Input (Variable), */
567 0x09, 0x2F, /* Usage (2Fh), */
568 0x91, 0x02, /* Output (Variable), */
569 0x85, 0x19, /* Report ID (25), */
570 0x09, 0x30, /* Usage (30h), */
571 0x96, 0x22, 0x02, /* Report Count (546), */
572 0x81, 0x02, /* Input (Variable), */
573 0x09, 0x31, /* Usage (31h), */
574 0x91, 0x02, /* Output (Variable), */
575 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */
576 0x85, 0x82, /* Report ID (130), */
577 0x09, 0x22, /* Usage (22h), */
578 0x95, 0x3F, /* Report Count (63), */
579 0xB1, 0x02, /* Feature (Variable), */
580 0x85, 0x83, /* Report ID (131), */
581 0x09, 0x23, /* Usage (23h), */
582 0xB1, 0x02, /* Feature (Variable), */
583 0x85, 0x84, /* Report ID (132), */
584 0x09, 0x24, /* Usage (24h), */
585 0xB1, 0x02, /* Feature (Variable), */
586 0x85, 0x90, /* Report ID (144), */
587 0x09, 0x30, /* Usage (30h), */
588 0xB1, 0x02, /* Feature (Variable), */
589 0x85, 0x91, /* Report ID (145), */
590 0x09, 0x31, /* Usage (31h), */
591 0xB1, 0x02, /* Feature (Variable), */
592 0x85, 0x92, /* Report ID (146), */
593 0x09, 0x32, /* Usage (32h), */
594 0xB1, 0x02, /* Feature (Variable), */
595 0x85, 0x93, /* Report ID (147), */
596 0x09, 0x33, /* Usage (33h), */
597 0xB1, 0x02, /* Feature (Variable), */
598 0x85, 0xA0, /* Report ID (160), */
599 0x09, 0x40, /* Usage (40h), */
600 0xB1, 0x02, /* Feature (Variable), */
601 0x85, 0xA4, /* Report ID (164), */
602 0x09, 0x44, /* Usage (44h), */
603 0xB1, 0x02, /* Feature (Variable), */
604 0xC0 /* End Collection */
607 static __u8 ps3remote_rdesc[] = {
608 0x05, 0x01, /* GUsagePage Generic Desktop */
609 0x09, 0x05, /* LUsage 0x05 [Game Pad] */
610 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */
612 /* Use collection 1 for joypad buttons */
613 0xA1, 0x02, /* MCollection Logical (interrelated data) */
615 /* Ignore the 1st byte, maybe it is used for a controller
616 * number but it's not needed for correct operation */
617 0x75, 0x08, /* GReportSize 0x08 [8] */
618 0x95, 0x01, /* GReportCount 0x01 [1] */
619 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
621 /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these
622 * buttons multiple keypresses are allowed */
623 0x05, 0x09, /* GUsagePage Button */
624 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */
625 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */
626 0x14, /* GLogicalMinimum [0] */
627 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */
628 0x75, 0x01, /* GReportSize 0x01 [1] */
629 0x95, 0x18, /* GReportCount 0x18 [24] */
630 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
632 0xC0, /* MEndCollection */
634 /* Use collection 2 for remote control buttons */
635 0xA1, 0x02, /* MCollection Logical (interrelated data) */
637 /* 5th byte is used for remote control buttons */
638 0x05, 0x09, /* GUsagePage Button */
639 0x18, /* LUsageMinimum [No button pressed] */
640 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */
641 0x14, /* GLogicalMinimum [0] */
642 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */
643 0x75, 0x08, /* GReportSize 0x08 [8] */
644 0x95, 0x01, /* GReportCount 0x01 [1] */
647 /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at
648 * 0xff and 11th is for press indication */
649 0x75, 0x08, /* GReportSize 0x08 [8] */
650 0x95, 0x06, /* GReportCount 0x06 [6] */
651 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
653 /* 12th byte is for battery strength */
654 0x05, 0x06, /* GUsagePage Generic Device Controls */
655 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */
656 0x14, /* GLogicalMinimum [0] */
657 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */
658 0x75, 0x08, /* GReportSize 0x08 [8] */
659 0x95, 0x01, /* GReportCount 0x01 [1] */
660 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
662 0xC0, /* MEndCollection */
664 0xC0 /* MEndCollection [Game Pad] */
667 static const unsigned int ps3remote_keymap_joypad_buttons[] = {
669 [0x02] = BTN_THUMBL, /* L3 */
670 [0x03] = BTN_THUMBR, /* R3 */
676 [0x09] = BTN_TL2, /* L2 */
677 [0x0a] = BTN_TR2, /* R2 */
678 [0x0b] = BTN_TL, /* L1 */
679 [0x0c] = BTN_TR, /* R1 */
680 [0x0d] = KEY_OPTION, /* options/triangle */
681 [0x0e] = KEY_BACK, /* back/circle */
682 [0x0f] = BTN_0, /* cross */
683 [0x10] = KEY_SCREEN, /* view/square */
684 [0x11] = KEY_HOMEPAGE, /* PS button */
687 static const unsigned int ps3remote_keymap_remote_buttons[] = {
698 [0x0e] = KEY_ESC, /* return */
700 [0x16] = KEY_EJECTCD,
701 [0x1a] = KEY_MENU, /* top menu */
703 [0x30] = KEY_PREVIOUS,
706 [0x33] = KEY_REWIND, /* scan back */
707 [0x34] = KEY_FORWARD, /* scan forward */
710 [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */
711 [0x60] = KEY_FRAMEBACK, /* slow/step back */
712 [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */
713 [0x63] = KEY_SUBTITLE,
716 [0x70] = KEY_INFO, /* display */
723 static const unsigned int buzz_keymap[] = {
725 * The controller has 4 remote buzzers, each with one LED and 5
728 * We use the mapping chosen by the controller, which is:
731 * -------------------
738 * So, for example, the orange button on the third buzzer is mapped to
739 * BTN_TRIGGER_HAPPY14
741 [ 1] = BTN_TRIGGER_HAPPY1,
742 [ 2] = BTN_TRIGGER_HAPPY2,
743 [ 3] = BTN_TRIGGER_HAPPY3,
744 [ 4] = BTN_TRIGGER_HAPPY4,
745 [ 5] = BTN_TRIGGER_HAPPY5,
746 [ 6] = BTN_TRIGGER_HAPPY6,
747 [ 7] = BTN_TRIGGER_HAPPY7,
748 [ 8] = BTN_TRIGGER_HAPPY8,
749 [ 9] = BTN_TRIGGER_HAPPY9,
750 [10] = BTN_TRIGGER_HAPPY10,
751 [11] = BTN_TRIGGER_HAPPY11,
752 [12] = BTN_TRIGGER_HAPPY12,
753 [13] = BTN_TRIGGER_HAPPY13,
754 [14] = BTN_TRIGGER_HAPPY14,
755 [15] = BTN_TRIGGER_HAPPY15,
756 [16] = BTN_TRIGGER_HAPPY16,
757 [17] = BTN_TRIGGER_HAPPY17,
758 [18] = BTN_TRIGGER_HAPPY18,
759 [19] = BTN_TRIGGER_HAPPY19,
760 [20] = BTN_TRIGGER_HAPPY20,
763 static enum power_supply_property sony_battery_props[] = {
764 POWER_SUPPLY_PROP_PRESENT,
765 POWER_SUPPLY_PROP_CAPACITY,
766 POWER_SUPPLY_PROP_SCOPE,
767 POWER_SUPPLY_PROP_STATUS,
771 __u8 time_enabled; /* the total time the led is active (0xff means forever) */
772 __u8 duty_length; /* how long a cycle is in deciseconds (0 means "really fast") */
774 __u8 duty_off; /* % of duty_length the led is off (0xff means 100%) */
775 __u8 duty_on; /* % of duty_length the led is on (0xff mean 100%) */
778 struct sixaxis_rumble {
780 __u8 right_duration; /* Right motor duration (0xff means forever) */
781 __u8 right_motor_on; /* Right (small) motor on/off, only supports values of 0 or 1 (off/on) */
782 __u8 left_duration; /* Left motor duration (0xff means forever) */
783 __u8 left_motor_force; /* left (large) motor, supports force values from 0 to 255 */
786 struct sixaxis_output_report {
788 struct sixaxis_rumble rumble;
790 __u8 leds_bitmap; /* bitmap of enabled LEDs: LED_1 = 0x02, LED_2 = 0x04, ... */
791 struct sixaxis_led led[4]; /* LEDx at (4 - x) */
792 struct sixaxis_led _reserved; /* LED5, not actually soldered */
795 union sixaxis_output_report_01 {
796 struct sixaxis_output_report data;
800 static spinlock_t sony_dev_list_lock;
801 static LIST_HEAD(sony_device_list);
802 static DEFINE_IDA(sony_device_id_allocator);
806 struct list_head list_node;
807 struct hid_device *hdev;
808 struct led_classdev *leds[MAX_LEDS];
809 unsigned long quirks;
810 struct work_struct state_worker;
811 struct power_supply battery;
814 #ifdef CONFIG_SONY_FF
820 __u8 worker_initialized;
822 __u8 battery_charging;
823 __u8 battery_capacity;
824 __u8 led_state[MAX_LEDS];
825 __u8 led_delay_on[MAX_LEDS];
826 __u8 led_delay_off[MAX_LEDS];
830 static __u8 *sixaxis_fixup(struct hid_device *hdev, __u8 *rdesc,
833 *rsize = sizeof(sixaxis_rdesc);
834 return sixaxis_rdesc;
837 static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc,
840 *rsize = sizeof(ps3remote_rdesc);
841 return ps3remote_rdesc;
844 static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi,
845 struct hid_field *field, struct hid_usage *usage,
846 unsigned long **bit, int *max)
848 unsigned int key = usage->hid & HID_USAGE;
850 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
853 switch (usage->collection_index) {
855 if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons))
858 key = ps3remote_keymap_joypad_buttons[key];
863 if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons))
866 key = ps3remote_keymap_remote_buttons[key];
874 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
878 static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
881 struct sony_sc *sc = hid_get_drvdata(hdev);
884 * Some Sony RF receivers wrongly declare the mouse pointer as a
885 * a constant non-data variable.
887 if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 &&
888 /* usage page: generic desktop controls */
889 /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */
891 rdesc[2] == 0x09 && rdesc[3] == 0x02 &&
892 /* input (usage page for x,y axes): constant, variable, relative */
893 rdesc[54] == 0x81 && rdesc[55] == 0x07) {
894 hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n");
895 /* input: data, variable, relative */
900 * The default Dualshock 4 USB descriptor doesn't assign
901 * the gyroscope values to corresponding axes so we need a
904 if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && *rsize == 467) {
905 hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n");
906 rdesc = dualshock4_usb_rdesc;
907 *rsize = sizeof(dualshock4_usb_rdesc);
908 } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && *rsize == 357) {
909 hid_info(hdev, "Using modified Dualshock 4 Bluetooth report descriptor\n");
910 rdesc = dualshock4_bt_rdesc;
911 *rsize = sizeof(dualshock4_bt_rdesc);
914 if (sc->quirks & SIXAXIS_CONTROLLER)
915 return sixaxis_fixup(hdev, rdesc, rsize);
917 if (sc->quirks & PS3REMOTE)
918 return ps3remote_fixup(hdev, rdesc, rsize);
923 static void sixaxis_parse_report(struct sony_sc *sc, __u8 *rd, int size)
925 static const __u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 };
927 __u8 cable_state, battery_capacity, battery_charging;
930 * The sixaxis is charging if the battery value is 0xee
931 * and it is fully charged if the value is 0xef.
932 * It does not report the actual level while charging so it
933 * is set to 100% while charging is in progress.
935 if (rd[30] >= 0xee) {
936 battery_capacity = 100;
937 battery_charging = !(rd[30] & 0x01);
940 __u8 index = rd[30] <= 5 ? rd[30] : 5;
941 battery_capacity = sixaxis_battery_capacity[index];
942 battery_charging = 0;
946 spin_lock_irqsave(&sc->lock, flags);
947 sc->cable_state = cable_state;
948 sc->battery_capacity = battery_capacity;
949 sc->battery_charging = battery_charging;
950 spin_unlock_irqrestore(&sc->lock, flags);
953 static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size)
955 struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
956 struct hid_input, list);
957 struct input_dev *input_dev = hidinput->input;
960 __u8 cable_state, battery_capacity, battery_charging;
963 * Battery and touchpad data starts at byte 30 in the USB report and
964 * 32 in Bluetooth report.
966 offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 30 : 32;
969 * The lower 4 bits of byte 30 contain the battery level
970 * and the 5th bit contains the USB cable state.
972 cable_state = (rd[offset] >> 4) & 0x01;
973 battery_capacity = rd[offset] & 0x0F;
976 * When a USB power source is connected the battery level ranges from
977 * 0 to 10, and when running on battery power it ranges from 0 to 9.
978 * A battery level above 10 when plugged in means charge completed.
980 if (!cable_state || battery_capacity > 10)
981 battery_charging = 0;
983 battery_charging = 1;
987 if (battery_capacity > 10)
988 battery_capacity = 10;
990 battery_capacity *= 10;
992 spin_lock_irqsave(&sc->lock, flags);
993 sc->cable_state = cable_state;
994 sc->battery_capacity = battery_capacity;
995 sc->battery_charging = battery_charging;
996 spin_unlock_irqrestore(&sc->lock, flags);
1001 * The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB
1002 * and 37 on Bluetooth.
1003 * The first 7 bits of the first byte is a counter and bit 8 is a touch
1004 * indicator that is 0 when pressed and 1 when not pressed.
1005 * The next 3 bytes are two 12 bit touch coordinates, X and Y.
1006 * The data for the second touch is in the same format and immediatly
1007 * follows the data for the first.
1009 for (n = 0; n < 2; n++) {
1012 x = rd[offset+1] | ((rd[offset+2] & 0xF) << 8);
1013 y = ((rd[offset+2] & 0xF0) >> 4) | (rd[offset+3] << 4);
1015 input_mt_slot(input_dev, n);
1016 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
1017 !(rd[offset] >> 7));
1018 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
1019 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
1025 static int sony_raw_event(struct hid_device *hdev, struct hid_report *report,
1028 struct sony_sc *sc = hid_get_drvdata(hdev);
1031 * Sixaxis HID report has acclerometers/gyro with MSByte first, this
1032 * has to be BYTE_SWAPPED before passing up to joystick interface
1034 if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] == 0x01 && size == 49) {
1035 swap(rd[41], rd[42]);
1036 swap(rd[43], rd[44]);
1037 swap(rd[45], rd[46]);
1038 swap(rd[47], rd[48]);
1040 sixaxis_parse_report(sc, rd, size);
1041 } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 &&
1042 size == 64) || ((sc->quirks & DUALSHOCK4_CONTROLLER_BT)
1043 && rd[0] == 0x11 && size == 78)) {
1044 dualshock4_parse_report(sc, rd, size);
1050 static int sony_mapping(struct hid_device *hdev, struct hid_input *hi,
1051 struct hid_field *field, struct hid_usage *usage,
1052 unsigned long **bit, int *max)
1054 struct sony_sc *sc = hid_get_drvdata(hdev);
1056 if (sc->quirks & BUZZ_CONTROLLER) {
1057 unsigned int key = usage->hid & HID_USAGE;
1059 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
1062 switch (usage->collection_index) {
1064 if (key >= ARRAY_SIZE(buzz_keymap))
1067 key = buzz_keymap[key];
1075 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
1079 if (sc->quirks & PS3REMOTE)
1080 return ps3remote_mapping(hdev, hi, field, usage, bit, max);
1082 /* Let hid-core decide for the others */
1087 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
1088 * to "operational". Without this, the ps3 controller will not report any
1091 static int sixaxis_set_operational_usb(struct hid_device *hdev)
1094 char *buf = kmalloc(18, GFP_KERNEL);
1099 ret = hid_hw_raw_request(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT,
1100 HID_REQ_GET_REPORT);
1103 hid_err(hdev, "can't set operational mode\n");
1110 static int sixaxis_set_operational_bt(struct hid_device *hdev)
1112 unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
1113 return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
1114 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
1118 * Requesting feature report 0x02 in Bluetooth mode changes the state of the
1119 * controller so that it sends full input reports of type 0x11.
1121 static int dualshock4_set_operational_bt(struct hid_device *hdev)
1123 __u8 buf[37] = { 0 };
1125 return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
1126 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
1129 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
1131 static const __u8 sixaxis_leds[10][4] = {
1132 { 0x01, 0x00, 0x00, 0x00 },
1133 { 0x00, 0x01, 0x00, 0x00 },
1134 { 0x00, 0x00, 0x01, 0x00 },
1135 { 0x00, 0x00, 0x00, 0x01 },
1136 { 0x01, 0x00, 0x00, 0x01 },
1137 { 0x00, 0x01, 0x00, 0x01 },
1138 { 0x00, 0x00, 0x01, 0x01 },
1139 { 0x01, 0x00, 0x01, 0x01 },
1140 { 0x00, 0x01, 0x01, 0x01 },
1141 { 0x01, 0x01, 0x01, 0x01 }
1144 BUG_ON(MAX_LEDS < ARRAY_SIZE(sixaxis_leds[0]));
1150 memcpy(values, sixaxis_leds[id], sizeof(sixaxis_leds[id]));
1153 static void dualshock4_set_leds_from_id(int id, __u8 values[MAX_LEDS])
1155 /* The first 4 color/index entries match what the PS4 assigns */
1156 static const __u8 color_code[7][3] = {
1157 /* Blue */ { 0x00, 0x00, 0x01 },
1158 /* Red */ { 0x01, 0x00, 0x00 },
1159 /* Green */ { 0x00, 0x01, 0x00 },
1160 /* Pink */ { 0x02, 0x00, 0x01 },
1161 /* Orange */ { 0x02, 0x01, 0x00 },
1162 /* Teal */ { 0x00, 0x01, 0x01 },
1163 /* White */ { 0x01, 0x01, 0x01 }
1166 BUG_ON(MAX_LEDS < ARRAY_SIZE(color_code[0]));
1172 memcpy(values, color_code[id], sizeof(color_code[id]));
1175 static void buzz_set_leds(struct hid_device *hdev, const __u8 *leds)
1177 struct list_head *report_list =
1178 &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
1179 struct hid_report *report = list_entry(report_list->next,
1180 struct hid_report, list);
1181 __s32 *value = report->field[0]->value;
1184 value[1] = leds[0] ? 0xff : 0x00;
1185 value[2] = leds[1] ? 0xff : 0x00;
1186 value[3] = leds[2] ? 0xff : 0x00;
1187 value[4] = leds[3] ? 0xff : 0x00;
1190 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
1193 static void sony_set_leds(struct sony_sc *sc, const __u8 *leds, int count)
1197 BUG_ON(count > MAX_LEDS);
1199 if (sc->quirks & BUZZ_CONTROLLER && count == 4) {
1200 buzz_set_leds(sc->hdev, leds);
1202 for (n = 0; n < count; n++)
1203 sc->led_state[n] = leds[n];
1204 schedule_work(&sc->state_worker);
1208 static void sony_led_set_brightness(struct led_classdev *led,
1209 enum led_brightness value)
1211 struct device *dev = led->dev->parent;
1212 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1213 struct sony_sc *drv_data;
1218 drv_data = hid_get_drvdata(hdev);
1220 hid_err(hdev, "No device data\n");
1225 * The Sixaxis on USB will override any LED settings sent to it
1226 * and keep flashing all of the LEDs until the PS button is pressed.
1227 * Updates, even if redundant, must be always be sent to the
1228 * controller to avoid having to toggle the state of an LED just to
1229 * stop the flashing later on.
1231 force_update = !!(drv_data->quirks & SIXAXIS_CONTROLLER_USB);
1233 for (n = 0; n < drv_data->led_count; n++) {
1234 if (led == drv_data->leds[n] && (force_update ||
1235 (value != drv_data->led_state[n] ||
1236 drv_data->led_delay_on[n] ||
1237 drv_data->led_delay_off[n]))) {
1239 drv_data->led_state[n] = value;
1241 /* Setting the brightness stops the blinking */
1242 drv_data->led_delay_on[n] = 0;
1243 drv_data->led_delay_off[n] = 0;
1245 sony_set_leds(drv_data, drv_data->led_state,
1246 drv_data->led_count);
1252 static enum led_brightness sony_led_get_brightness(struct led_classdev *led)
1254 struct device *dev = led->dev->parent;
1255 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1256 struct sony_sc *drv_data;
1260 drv_data = hid_get_drvdata(hdev);
1262 hid_err(hdev, "No device data\n");
1266 for (n = 0; n < drv_data->led_count; n++) {
1267 if (led == drv_data->leds[n])
1268 return drv_data->led_state[n];
1274 static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on,
1275 unsigned long *delay_off)
1277 struct device *dev = led->dev->parent;
1278 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1279 struct sony_sc *drv_data = hid_get_drvdata(hdev);
1281 __u8 new_on, new_off;
1284 hid_err(hdev, "No device data\n");
1288 /* Max delay is 255 deciseconds or 2550 milliseconds */
1289 if (*delay_on > 2550)
1291 if (*delay_off > 2550)
1294 /* Blink at 1 Hz if both values are zero */
1295 if (!*delay_on && !*delay_off)
1296 *delay_on = *delay_off = 500;
1298 new_on = *delay_on / 10;
1299 new_off = *delay_off / 10;
1301 for (n = 0; n < drv_data->led_count; n++) {
1302 if (led == drv_data->leds[n])
1306 /* This LED is not registered on this device */
1307 if (n >= drv_data->led_count)
1310 /* Don't schedule work if the values didn't change */
1311 if (new_on != drv_data->led_delay_on[n] ||
1312 new_off != drv_data->led_delay_off[n]) {
1313 drv_data->led_delay_on[n] = new_on;
1314 drv_data->led_delay_off[n] = new_off;
1315 schedule_work(&drv_data->state_worker);
1321 static void sony_leds_remove(struct sony_sc *sc)
1323 struct led_classdev *led;
1326 BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
1328 for (n = 0; n < sc->led_count; n++) {
1333 led_classdev_unregister(led);
1340 static int sony_leds_init(struct sony_sc *sc)
1342 struct hid_device *hdev = sc->hdev;
1345 struct led_classdev *led;
1349 const char *name_fmt;
1350 static const char * const ds4_name_str[] = { "red", "green", "blue",
1352 __u8 initial_values[MAX_LEDS] = { 0 };
1353 __u8 max_brightness[MAX_LEDS] = { [0 ... (MAX_LEDS - 1)] = 1 };
1354 __u8 use_hw_blink[MAX_LEDS] = { 0 };
1356 BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
1358 if (sc->quirks & BUZZ_CONTROLLER) {
1361 name_len = strlen("::buzz#");
1362 name_fmt = "%s::buzz%d";
1363 /* Validate expected report characteristics. */
1364 if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7))
1366 } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
1367 dualshock4_set_leds_from_id(sc->device_id, initial_values);
1368 initial_values[3] = 1;
1370 memset(max_brightness, 255, 3);
1371 use_hw_blink[3] = 1;
1376 sixaxis_set_leds_from_id(sc->device_id, initial_values);
1378 memset(use_hw_blink, 1, 4);
1380 name_len = strlen("::sony#");
1381 name_fmt = "%s::sony%d";
1385 * Clear LEDs as we have no way of reading their initial state. This is
1386 * only relevant if the driver is loaded after somebody actively set the
1389 sony_set_leds(sc, initial_values, sc->led_count);
1391 name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1;
1393 for (n = 0; n < sc->led_count; n++) {
1396 name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2;
1398 led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
1400 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
1405 name = (void *)(&led[1]);
1407 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev),
1410 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1);
1412 led->brightness = initial_values[n];
1413 led->max_brightness = max_brightness[n];
1414 led->brightness_get = sony_led_get_brightness;
1415 led->brightness_set = sony_led_set_brightness;
1417 if (use_hw_blink[n])
1418 led->blink_set = sony_led_blink_set;
1422 ret = led_classdev_register(&hdev->dev, led);
1424 hid_err(hdev, "Failed to register LED %d\n", n);
1434 sony_leds_remove(sc);
1439 static void sixaxis_state_worker(struct work_struct *work)
1441 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
1443 union sixaxis_output_report_01 report = {
1446 0x00, 0xff, 0x00, 0xff, 0x00,
1447 0x00, 0x00, 0x00, 0x00, 0x00,
1448 0xff, 0x27, 0x10, 0x00, 0x32,
1449 0xff, 0x27, 0x10, 0x00, 0x32,
1450 0xff, 0x27, 0x10, 0x00, 0x32,
1451 0xff, 0x27, 0x10, 0x00, 0x32,
1452 0x00, 0x00, 0x00, 0x00, 0x00
1456 #ifdef CONFIG_SONY_FF
1457 report.data.rumble.right_motor_on = sc->right ? 1 : 0;
1458 report.data.rumble.left_motor_force = sc->left;
1461 report.data.leds_bitmap |= sc->led_state[0] << 1;
1462 report.data.leds_bitmap |= sc->led_state[1] << 2;
1463 report.data.leds_bitmap |= sc->led_state[2] << 3;
1464 report.data.leds_bitmap |= sc->led_state[3] << 4;
1466 /* Set flag for all leds off, required for 3rd party INTEC controller */
1467 if ((report.data.leds_bitmap & 0x1E) == 0)
1468 report.data.leds_bitmap |= 0x20;
1471 * The LEDs in the report are indexed in reverse order to their
1472 * corresponding light on the controller.
1473 * Index 0 = LED 4, index 1 = LED 3, etc...
1475 * In the case of both delay values being zero (blinking disabled) the
1476 * default report values should be used or the controller LED will be
1479 for (n = 0; n < 4; n++) {
1480 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
1481 report.data.led[3 - n].duty_off = sc->led_delay_off[n];
1482 report.data.led[3 - n].duty_on = sc->led_delay_on[n];
1486 hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
1487 sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
1490 static void dualshock4_state_worker(struct work_struct *work)
1492 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
1493 struct hid_device *hdev = sc->hdev;
1496 __u8 buf[78] = { 0 };
1498 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
1509 #ifdef CONFIG_SONY_FF
1510 buf[offset++] = sc->right;
1511 buf[offset++] = sc->left;
1516 /* LED 3 is the global control */
1517 if (sc->led_state[3]) {
1518 buf[offset++] = sc->led_state[0];
1519 buf[offset++] = sc->led_state[1];
1520 buf[offset++] = sc->led_state[2];
1525 /* If both delay values are zero the DualShock 4 disables blinking. */
1526 buf[offset++] = sc->led_delay_on[3];
1527 buf[offset++] = sc->led_delay_off[3];
1529 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
1530 hid_hw_output_report(hdev, buf, 32);
1532 hid_hw_raw_request(hdev, 0x11, buf, 78,
1533 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
1536 #ifdef CONFIG_SONY_FF
1537 static int sony_play_effect(struct input_dev *dev, void *data,
1538 struct ff_effect *effect)
1540 struct hid_device *hid = input_get_drvdata(dev);
1541 struct sony_sc *sc = hid_get_drvdata(hid);
1543 if (effect->type != FF_RUMBLE)
1546 sc->left = effect->u.rumble.strong_magnitude / 256;
1547 sc->right = effect->u.rumble.weak_magnitude / 256;
1549 schedule_work(&sc->state_worker);
1553 static int sony_init_ff(struct sony_sc *sc)
1555 struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
1556 struct hid_input, list);
1557 struct input_dev *input_dev = hidinput->input;
1559 input_set_capability(input_dev, EV_FF, FF_RUMBLE);
1560 return input_ff_create_memless(input_dev, NULL, sony_play_effect);
1564 static int sony_init_ff(struct sony_sc *sc)
1571 static int sony_battery_get_property(struct power_supply *psy,
1572 enum power_supply_property psp,
1573 union power_supply_propval *val)
1575 struct sony_sc *sc = container_of(psy, struct sony_sc, battery);
1576 unsigned long flags;
1578 u8 battery_charging, battery_capacity, cable_state;
1580 spin_lock_irqsave(&sc->lock, flags);
1581 battery_charging = sc->battery_charging;
1582 battery_capacity = sc->battery_capacity;
1583 cable_state = sc->cable_state;
1584 spin_unlock_irqrestore(&sc->lock, flags);
1587 case POWER_SUPPLY_PROP_PRESENT:
1590 case POWER_SUPPLY_PROP_SCOPE:
1591 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1593 case POWER_SUPPLY_PROP_CAPACITY:
1594 val->intval = battery_capacity;
1596 case POWER_SUPPLY_PROP_STATUS:
1597 if (battery_charging)
1598 val->intval = POWER_SUPPLY_STATUS_CHARGING;
1600 if (battery_capacity == 100 && cable_state)
1601 val->intval = POWER_SUPPLY_STATUS_FULL;
1603 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
1612 static int sony_battery_probe(struct sony_sc *sc)
1614 struct hid_device *hdev = sc->hdev;
1618 * Set the default battery level to 100% to avoid low battery warnings
1619 * if the battery is polled before the first device report is received.
1621 sc->battery_capacity = 100;
1623 sc->battery.properties = sony_battery_props;
1624 sc->battery.num_properties = ARRAY_SIZE(sony_battery_props);
1625 sc->battery.get_property = sony_battery_get_property;
1626 sc->battery.type = POWER_SUPPLY_TYPE_BATTERY;
1627 sc->battery.use_for_apm = 0;
1628 sc->battery.name = kasprintf(GFP_KERNEL, "sony_controller_battery_%pMR",
1630 if (!sc->battery.name)
1633 ret = power_supply_register(&hdev->dev, &sc->battery);
1635 hid_err(hdev, "Unable to register battery device\n");
1639 power_supply_powers(&sc->battery, &hdev->dev);
1643 kfree(sc->battery.name);
1644 sc->battery.name = NULL;
1648 static void sony_battery_remove(struct sony_sc *sc)
1650 if (!sc->battery.name)
1653 power_supply_unregister(&sc->battery);
1654 kfree(sc->battery.name);
1655 sc->battery.name = NULL;
1658 static int sony_register_touchpad(struct sony_sc *sc, int touch_count,
1661 struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
1662 struct hid_input, list);
1663 struct input_dev *input_dev = hidinput->input;
1666 ret = input_mt_init_slots(input_dev, touch_count, 0);
1668 hid_err(sc->hdev, "Unable to initialize multi-touch slots\n");
1672 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, w, 0, 0);
1673 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, h, 0, 0);
1679 * If a controller is plugged in via USB while already connected via Bluetooth
1680 * it will show up as two devices. A global list of connected controllers and
1681 * their MAC addresses is maintained to ensure that a device is only connected
1684 static int sony_check_add_dev_list(struct sony_sc *sc)
1686 struct sony_sc *entry;
1687 unsigned long flags;
1690 spin_lock_irqsave(&sony_dev_list_lock, flags);
1692 list_for_each_entry(entry, &sony_device_list, list_node) {
1693 ret = memcmp(sc->mac_address, entry->mac_address,
1694 sizeof(sc->mac_address));
1697 hid_info(sc->hdev, "controller with MAC address %pMR already connected\n",
1704 list_add(&(sc->list_node), &sony_device_list);
1707 spin_unlock_irqrestore(&sony_dev_list_lock, flags);
1711 static void sony_remove_dev_list(struct sony_sc *sc)
1713 unsigned long flags;
1715 if (sc->list_node.next) {
1716 spin_lock_irqsave(&sony_dev_list_lock, flags);
1717 list_del(&(sc->list_node));
1718 spin_unlock_irqrestore(&sony_dev_list_lock, flags);
1722 static int sony_get_bt_devaddr(struct sony_sc *sc)
1726 /* HIDP stores the device MAC address as a string in the uniq field. */
1727 ret = strlen(sc->hdev->uniq);
1731 ret = sscanf(sc->hdev->uniq,
1732 "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
1733 &sc->mac_address[5], &sc->mac_address[4], &sc->mac_address[3],
1734 &sc->mac_address[2], &sc->mac_address[1], &sc->mac_address[0]);
1742 static int sony_check_add(struct sony_sc *sc)
1746 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
1747 (sc->quirks & SIXAXIS_CONTROLLER_BT)) {
1749 * sony_get_bt_devaddr() attempts to parse the Bluetooth MAC
1750 * address from the uniq string where HIDP stores it.
1751 * As uniq cannot be guaranteed to be a MAC address in all cases
1752 * a failure of this function should not prevent the connection.
1754 if (sony_get_bt_devaddr(sc) < 0) {
1755 hid_warn(sc->hdev, "UNIQ does not contain a MAC address; duplicate check skipped\n");
1758 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
1762 * The MAC address of a DS4 controller connected via USB can be
1763 * retrieved with feature report 0x81. The address begins at
1766 ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
1767 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
1770 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
1771 return ret < 0 ? ret : -EINVAL;
1774 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
1775 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
1779 * The MAC address of a Sixaxis controller connected via USB can
1780 * be retrieved with feature report 0xf2. The address begins at
1783 ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
1784 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
1787 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
1788 return ret < 0 ? ret : -EINVAL;
1792 * The Sixaxis device MAC in the report is big-endian and must
1795 for (n = 0; n < 6; n++)
1796 sc->mac_address[5-n] = buf[4+n];
1801 return sony_check_add_dev_list(sc);
1804 static int sony_set_device_id(struct sony_sc *sc)
1809 * Only DualShock 4 or Sixaxis controllers get an id.
1810 * All others are set to -1.
1812 if ((sc->quirks & SIXAXIS_CONTROLLER) ||
1813 (sc->quirks & DUALSHOCK4_CONTROLLER)) {
1814 ret = ida_simple_get(&sony_device_id_allocator, 0, 0,
1820 sc->device_id = ret;
1828 static void sony_release_device_id(struct sony_sc *sc)
1830 if (sc->device_id >= 0) {
1831 ida_simple_remove(&sony_device_id_allocator, sc->device_id);
1836 static inline void sony_init_work(struct sony_sc *sc,
1837 void (*worker)(struct work_struct *))
1839 if (!sc->worker_initialized)
1840 INIT_WORK(&sc->state_worker, worker);
1842 sc->worker_initialized = 1;
1845 static inline void sony_cancel_work_sync(struct sony_sc *sc)
1847 if (sc->worker_initialized)
1848 cancel_work_sync(&sc->state_worker);
1851 static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
1854 unsigned long quirks = id->driver_data;
1856 unsigned int connect_mask = HID_CONNECT_DEFAULT;
1858 sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
1860 hid_err(hdev, "can't alloc sony descriptor\n");
1864 sc->quirks = quirks;
1865 hid_set_drvdata(hdev, sc);
1868 ret = hid_parse(hdev);
1870 hid_err(hdev, "parse failed\n");
1874 if (sc->quirks & VAIO_RDESC_CONSTANT)
1875 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
1876 else if (sc->quirks & SIXAXIS_CONTROLLER)
1877 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
1879 ret = hid_hw_start(hdev, connect_mask);
1881 hid_err(hdev, "hw start failed\n");
1885 ret = sony_set_device_id(sc);
1887 hid_err(hdev, "failed to allocate the device id\n");
1891 if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
1893 * The Sony Sixaxis does not handle HID Output Reports on the
1894 * Interrupt EP like it could, so we need to force HID Output
1895 * Reports to use HID_REQ_SET_REPORT on the Control EP.
1897 * There is also another issue about HID Output Reports via USB,
1898 * the Sixaxis does not want the report_id as part of the data
1899 * packet, so we have to discard buf[0] when sending the actual
1900 * control message, even for numbered reports, humpf!
1902 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
1903 hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID;
1904 ret = sixaxis_set_operational_usb(hdev);
1905 sony_init_work(sc, sixaxis_state_worker);
1906 } else if (sc->quirks & SIXAXIS_CONTROLLER_BT) {
1908 * The Sixaxis wants output reports sent on the ctrl endpoint
1909 * when connected via Bluetooth.
1911 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
1912 ret = sixaxis_set_operational_bt(hdev);
1913 sony_init_work(sc, sixaxis_state_worker);
1914 } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
1915 if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) {
1917 * The DualShock 4 wants output reports sent on the ctrl
1918 * endpoint when connected via Bluetooth.
1920 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
1921 ret = dualshock4_set_operational_bt(hdev);
1923 hid_err(hdev, "failed to set the Dualshock 4 operational mode\n");
1928 * The Dualshock 4 touchpad supports 2 touches and has a
1929 * resolution of 1920x940.
1931 ret = sony_register_touchpad(sc, 2, 1920, 940);
1935 sony_init_work(sc, dualshock4_state_worker);
1943 ret = sony_check_add(sc);
1947 if (sc->quirks & SONY_LED_SUPPORT) {
1948 ret = sony_leds_init(sc);
1953 if (sc->quirks & SONY_BATTERY_SUPPORT) {
1954 ret = sony_battery_probe(sc);
1958 /* Open the device to receive reports with battery info */
1959 ret = hid_hw_open(hdev);
1961 hid_err(hdev, "hw open failed\n");
1966 if (sc->quirks & SONY_FF_SUPPORT) {
1967 ret = sony_init_ff(sc);
1976 if (sc->quirks & SONY_LED_SUPPORT)
1977 sony_leds_remove(sc);
1978 if (sc->quirks & SONY_BATTERY_SUPPORT)
1979 sony_battery_remove(sc);
1980 sony_cancel_work_sync(sc);
1981 sony_remove_dev_list(sc);
1982 sony_release_device_id(sc);
1987 static void sony_remove(struct hid_device *hdev)
1989 struct sony_sc *sc = hid_get_drvdata(hdev);
1991 if (sc->quirks & SONY_LED_SUPPORT)
1992 sony_leds_remove(sc);
1994 if (sc->quirks & SONY_BATTERY_SUPPORT) {
1996 sony_battery_remove(sc);
1999 sony_cancel_work_sync(sc);
2001 sony_remove_dev_list(sc);
2003 sony_release_device_id(sc);
2008 static const struct hid_device_id sony_devices[] = {
2009 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
2010 .driver_data = SIXAXIS_CONTROLLER_USB },
2011 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
2012 .driver_data = SIXAXIS_CONTROLLER_USB },
2013 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
2014 .driver_data = SIXAXIS_CONTROLLER_BT },
2015 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
2016 .driver_data = VAIO_RDESC_CONSTANT },
2017 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE),
2018 .driver_data = VAIO_RDESC_CONSTANT },
2019 /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as
2020 * Logitech joystick from the device descriptor. */
2021 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER),
2022 .driver_data = BUZZ_CONTROLLER },
2023 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER),
2024 .driver_data = BUZZ_CONTROLLER },
2025 /* PS3 BD Remote Control */
2026 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE),
2027 .driver_data = PS3REMOTE },
2028 /* Logitech Harmony Adapter for PS3 */
2029 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3),
2030 .driver_data = PS3REMOTE },
2031 /* Sony Dualshock 4 controllers for PS4 */
2032 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
2033 .driver_data = DUALSHOCK4_CONTROLLER_USB },
2034 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
2035 .driver_data = DUALSHOCK4_CONTROLLER_BT },
2038 MODULE_DEVICE_TABLE(hid, sony_devices);
2040 static struct hid_driver sony_driver = {
2042 .id_table = sony_devices,
2043 .input_mapping = sony_mapping,
2044 .probe = sony_probe,
2045 .remove = sony_remove,
2046 .report_fixup = sony_report_fixup,
2047 .raw_event = sony_raw_event
2050 static int __init sony_init(void)
2052 dbg_hid("Sony:%s\n", __func__);
2054 return hid_register_driver(&sony_driver);
2057 static void __exit sony_exit(void)
2059 dbg_hid("Sony:%s\n", __func__);
2061 ida_destroy(&sony_device_id_allocator);
2062 hid_unregister_driver(&sony_driver);
2064 module_init(sony_init);
2065 module_exit(sony_exit);
2067 MODULE_LICENSE("GPL");