]> Git Repo - linux.git/blame - drivers/hid/hid-sony.c
HID: sony: Refactor the output report sending functions
[linux.git] / drivers / hid / hid-sony.c
CommitLineData
bd28ce00 1/*
077147a3 2 * HID driver for Sony / PS2 / PS3 / PS4 BD devices.
bd28ce00
JS
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <[email protected]>
6 * Copyright (c) 2005 Michael Haboustak <[email protected]> for Concept2, Inc
bd28ce00 7 * Copyright (c) 2008 Jiri Slaby
078328da
JK
8 * Copyright (c) 2012 David Dillow <[email protected]>
9 * Copyright (c) 2006-2013 Jiri Kosina
f04d5140 10 * Copyright (c) 2013 Colin Leitner <[email protected]>
077147a3 11 * Copyright (c) 2014 Frank Praznik <[email protected]>
bd28ce00
JS
12 */
13
14/*
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the Free
17 * Software Foundation; either version 2 of the License, or (at your option)
18 * any later version.
19 */
20
ad142b9e
FP
21/*
22 * NOTE: in order for the Sony PS3 BD Remote Control to be found by
078328da
JK
23 * a Bluetooth host, the key combination Start+Enter has to be kept pressed
24 * for about 7 seconds with the Bluetooth Host Controller in discovering mode.
25 *
26 * There will be no PIN request from the device.
27 */
28
bd28ce00
JS
29#include <linux/device.h>
30#include <linux/hid.h>
31#include <linux/module.h>
5a0e3ad6 32#include <linux/slab.h>
40e32ee6 33#include <linux/leds.h>
d902f472
FP
34#include <linux/power_supply.h>
35#include <linux/spinlock.h>
d2d782fc 36#include <linux/list.h>
8025087a 37#include <linux/idr.h>
e5606230 38#include <linux/input/mt.h>
bd28ce00
JS
39
40#include "hid-ids.h"
41
6c79c18c
FP
42#define VAIO_RDESC_CONSTANT BIT(0)
43#define SIXAXIS_CONTROLLER_USB BIT(1)
44#define SIXAXIS_CONTROLLER_BT BIT(2)
45#define BUZZ_CONTROLLER BIT(3)
46#define PS3REMOTE BIT(4)
8ab1676b
FP
47#define DUALSHOCK4_CONTROLLER_USB BIT(5)
48#define DUALSHOCK4_CONTROLLER_BT BIT(6)
b3bca326
SW
49#define MOTION_CONTROLLER_USB BIT(7)
50#define MOTION_CONTROLLER_BT BIT(8)
4545ee0a
SW
51#define NAVIGATION_CONTROLLER_USB BIT(9)
52#define NAVIGATION_CONTROLLER_BT BIT(10)
cc6e0bbb 53
fee4e2d5 54#define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)
b3bca326 55#define MOTION_CONTROLLER (MOTION_CONTROLLER_USB | MOTION_CONTROLLER_BT)
4545ee0a
SW
56#define NAVIGATION_CONTROLLER (NAVIGATION_CONTROLLER_USB |\
57 NAVIGATION_CONTROLLER_BT)
68330d83
FP
58#define DUALSHOCK4_CONTROLLER (DUALSHOCK4_CONTROLLER_USB |\
59 DUALSHOCK4_CONTROLLER_BT)
fee4e2d5 60#define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER | BUZZ_CONTROLLER |\
4545ee0a
SW
61 DUALSHOCK4_CONTROLLER | MOTION_CONTROLLER |\
62 NAVIGATION_CONTROLLER)
12e9a6d7 63#define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER |\
4545ee0a 64 MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER)
c5e0c1c4
FP
65#define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER |\
66 MOTION_CONTROLLER)
60781cf4
FP
67
68#define MAX_LEDS 4
0a286ef2 69
4c3e8298
FP
70/*
71 * The Sixaxis reports both digital and analog values for each button on the
72 * controller except for Start, Select and the PS button. The controller ends
73 * up reporting 27 axes which causes them to spill over into the multi-touch
74 * axis values. Additionally, the controller only has 20 actual, physical axes
75 * so there are several unused axes in between the used ones.
76 */
c607fb8d 77static __u8 sixaxis_rdesc[] = {
fb705a6d 78 0x05, 0x01, /* Usage Page (Desktop), */
4c3e8298 79 0x09, 0x04, /* Usage (Joystick), */
fb705a6d
AO
80 0xA1, 0x01, /* Collection (Application), */
81 0xA1, 0x02, /* Collection (Logical), */
82 0x85, 0x01, /* Report ID (1), */
83 0x75, 0x08, /* Report Size (8), */
84 0x95, 0x01, /* Report Count (1), */
85 0x15, 0x00, /* Logical Minimum (0), */
86 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
87 0x81, 0x03, /* Input (Constant, Variable), */
88 0x75, 0x01, /* Report Size (1), */
89 0x95, 0x13, /* Report Count (19), */
90 0x15, 0x00, /* Logical Minimum (0), */
91 0x25, 0x01, /* Logical Maximum (1), */
92 0x35, 0x00, /* Physical Minimum (0), */
93 0x45, 0x01, /* Physical Maximum (1), */
94 0x05, 0x09, /* Usage Page (Button), */
95 0x19, 0x01, /* Usage Minimum (01h), */
96 0x29, 0x13, /* Usage Maximum (13h), */
97 0x81, 0x02, /* Input (Variable), */
98 0x75, 0x01, /* Report Size (1), */
99 0x95, 0x0D, /* Report Count (13), */
100 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
101 0x81, 0x03, /* Input (Constant, Variable), */
102 0x15, 0x00, /* Logical Minimum (0), */
103 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
104 0x05, 0x01, /* Usage Page (Desktop), */
105 0x09, 0x01, /* Usage (Pointer), */
106 0xA1, 0x00, /* Collection (Physical), */
107 0x75, 0x08, /* Report Size (8), */
108 0x95, 0x04, /* Report Count (4), */
109 0x35, 0x00, /* Physical Minimum (0), */
110 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
111 0x09, 0x30, /* Usage (X), */
112 0x09, 0x31, /* Usage (Y), */
113 0x09, 0x32, /* Usage (Z), */
114 0x09, 0x35, /* Usage (Rz), */
115 0x81, 0x02, /* Input (Variable), */
116 0xC0, /* End Collection, */
117 0x05, 0x01, /* Usage Page (Desktop), */
118 0x95, 0x13, /* Report Count (19), */
119 0x09, 0x01, /* Usage (Pointer), */
120 0x81, 0x02, /* Input (Variable), */
121 0x95, 0x0C, /* Report Count (12), */
122 0x81, 0x01, /* Input (Constant), */
123 0x75, 0x10, /* Report Size (16), */
124 0x95, 0x04, /* Report Count (4), */
125 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
126 0x46, 0xFF, 0x03, /* Physical Maximum (1023), */
127 0x09, 0x01, /* Usage (Pointer), */
128 0x81, 0x02, /* Input (Variable), */
129 0xC0, /* End Collection, */
130 0xA1, 0x02, /* Collection (Logical), */
131 0x85, 0x02, /* Report ID (2), */
132 0x75, 0x08, /* Report Size (8), */
133 0x95, 0x30, /* Report Count (48), */
134 0x09, 0x01, /* Usage (Pointer), */
135 0xB1, 0x02, /* Feature (Variable), */
136 0xC0, /* End Collection, */
137 0xA1, 0x02, /* Collection (Logical), */
138 0x85, 0xEE, /* Report ID (238), */
139 0x75, 0x08, /* Report Size (8), */
140 0x95, 0x30, /* Report Count (48), */
141 0x09, 0x01, /* Usage (Pointer), */
142 0xB1, 0x02, /* Feature (Variable), */
143 0xC0, /* End Collection, */
144 0xA1, 0x02, /* Collection (Logical), */
145 0x85, 0xEF, /* Report ID (239), */
146 0x75, 0x08, /* Report Size (8), */
147 0x95, 0x30, /* Report Count (48), */
148 0x09, 0x01, /* Usage (Pointer), */
149 0xB1, 0x02, /* Feature (Variable), */
150 0xC0, /* End Collection, */
151 0xC0 /* End Collection */
e57a67da
MCC
152};
153
c5e0c1c4
FP
154/* PS/3 Motion controller */
155static __u8 motion_rdesc[] = {
156 0x05, 0x01, /* Usage Page (Desktop), */
157 0x09, 0x04, /* Usage (Joystick), */
158 0xA1, 0x01, /* Collection (Application), */
159 0xA1, 0x02, /* Collection (Logical), */
160 0x85, 0x01, /* Report ID (1), */
c5e0c1c4 161 0x75, 0x01, /* Report Size (1), */
8b2513c3 162 0x95, 0x15, /* Report Count (21), */
c5e0c1c4
FP
163 0x15, 0x00, /* Logical Minimum (0), */
164 0x25, 0x01, /* Logical Maximum (1), */
165 0x35, 0x00, /* Physical Minimum (0), */
166 0x45, 0x01, /* Physical Maximum (1), */
167 0x05, 0x09, /* Usage Page (Button), */
168 0x19, 0x01, /* Usage Minimum (01h), */
8b2513c3
SW
169 0x29, 0x15, /* Usage Maximum (15h), */
170 0x81, 0x02, /* Input (Variable), * Buttons */
171 0x95, 0x0B, /* Report Count (11), */
c5e0c1c4 172 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
8b2513c3 173 0x81, 0x03, /* Input (Constant, Variable), * Padding */
c5e0c1c4
FP
174 0x15, 0x00, /* Logical Minimum (0), */
175 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
176 0x05, 0x01, /* Usage Page (Desktop), */
c5e0c1c4
FP
177 0xA1, 0x00, /* Collection (Physical), */
178 0x75, 0x08, /* Report Size (8), */
8b2513c3 179 0x95, 0x01, /* Report Count (1), */
c5e0c1c4
FP
180 0x35, 0x00, /* Physical Minimum (0), */
181 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
182 0x09, 0x30, /* Usage (X), */
8b2513c3 183 0x81, 0x02, /* Input (Variable), * Trigger */
c5e0c1c4 184 0xC0, /* End Collection, */
8b2513c3
SW
185 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
186 0x75, 0x08, /* Report Size (8), */
187 0x95, 0x07, /* Report Count (7), * skip 7 bytes */
c5e0c1c4 188 0x81, 0x02, /* Input (Variable), */
8b2513c3 189 0x05, 0x01, /* Usage Page (Desktop), */
c5e0c1c4 190 0x75, 0x10, /* Report Size (16), */
8b2513c3
SW
191 0x46, 0xFF, 0xFF, /* Physical Maximum (65535), */
192 0x27, 0xFF, 0xFF, 0x00, 0x00, /* Logical Maximum (65535), */
193 0x95, 0x03, /* Report Count (3), * 3x Accels */
194 0x09, 0x33, /* Usage (rX), */
195 0x09, 0x34, /* Usage (rY), */
196 0x09, 0x35, /* Usage (rZ), */
197 0x81, 0x02, /* Input (Variable), */
198 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
199 0x95, 0x03, /* Report Count (3), * Skip Accels 2nd frame */
200 0x81, 0x02, /* Input (Variable), */
201 0x05, 0x01, /* Usage Page (Desktop), */
c5e0c1c4 202 0x09, 0x01, /* Usage (Pointer), */
8b2513c3
SW
203 0x95, 0x03, /* Report Count (3), * 3x Gyros */
204 0x81, 0x02, /* Input (Variable), */
205 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
206 0x95, 0x03, /* Report Count (3), * Skip Gyros 2nd frame */
c5e0c1c4 207 0x81, 0x02, /* Input (Variable), */
8b2513c3
SW
208 0x75, 0x0C, /* Report Size (12), */
209 0x46, 0xFF, 0x0F, /* Physical Maximum (4095), */
210 0x26, 0xFF, 0x0F, /* Logical Maximum (4095), */
211 0x95, 0x04, /* Report Count (4), * Skip Temp and Magnetometers */
212 0x81, 0x02, /* Input (Variable), */
213 0x75, 0x08, /* Report Size (8), */
214 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
215 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
216 0x95, 0x06, /* Report Count (6), * Skip Timestamp and Extension Bytes */
217 0x81, 0x02, /* Input (Variable), */
218 0x75, 0x08, /* Report Size (8), */
219 0x95, 0x30, /* Report Count (48), */
220 0x09, 0x01, /* Usage (Pointer), */
221 0x91, 0x02, /* Output (Variable), */
222 0x75, 0x08, /* Report Size (8), */
223 0x95, 0x30, /* Report Count (48), */
224 0x09, 0x01, /* Usage (Pointer), */
225 0xB1, 0x02, /* Feature (Variable), */
c5e0c1c4
FP
226 0xC0, /* End Collection, */
227 0xA1, 0x02, /* Collection (Logical), */
228 0x85, 0x02, /* Report ID (2), */
229 0x75, 0x08, /* Report Size (8), */
230 0x95, 0x30, /* Report Count (48), */
231 0x09, 0x01, /* Usage (Pointer), */
232 0xB1, 0x02, /* Feature (Variable), */
233 0xC0, /* End Collection, */
234 0xA1, 0x02, /* Collection (Logical), */
235 0x85, 0xEE, /* Report ID (238), */
236 0x75, 0x08, /* Report Size (8), */
237 0x95, 0x30, /* Report Count (48), */
238 0x09, 0x01, /* Usage (Pointer), */
239 0xB1, 0x02, /* Feature (Variable), */
240 0xC0, /* End Collection, */
241 0xA1, 0x02, /* Collection (Logical), */
242 0x85, 0xEF, /* Report ID (239), */
243 0x75, 0x08, /* Report Size (8), */
244 0x95, 0x30, /* Report Count (48), */
245 0x09, 0x01, /* Usage (Pointer), */
246 0xB1, 0x02, /* Feature (Variable), */
247 0xC0, /* End Collection, */
248 0xC0 /* End Collection */
249};
250
b2723eb7
SW
251/* PS/3 Navigation controller */
252static __u8 navigation_rdesc[] = {
253 0x05, 0x01, /* Usage Page (Desktop), */
254 0x09, 0x04, /* Usage (Joystik), */
255 0xA1, 0x01, /* Collection (Application), */
256 0xA1, 0x02, /* Collection (Logical), */
257 0x85, 0x01, /* Report ID (1), */
258 0x75, 0x08, /* Report Size (8), */
259 0x95, 0x01, /* Report Count (1), */
260 0x15, 0x00, /* Logical Minimum (0), */
261 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
262 0x81, 0x03, /* Input (Constant, Variable), */
263 0x75, 0x01, /* Report Size (1), */
264 0x95, 0x13, /* Report Count (19), */
265 0x15, 0x00, /* Logical Minimum (0), */
266 0x25, 0x01, /* Logical Maximum (1), */
267 0x35, 0x00, /* Physical Minimum (0), */
268 0x45, 0x01, /* Physical Maximum (1), */
269 0x05, 0x09, /* Usage Page (Button), */
270 0x19, 0x01, /* Usage Minimum (01h), */
271 0x29, 0x13, /* Usage Maximum (13h), */
272 0x81, 0x02, /* Input (Variable), */
273 0x75, 0x01, /* Report Size (1), */
274 0x95, 0x0D, /* Report Count (13), */
275 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
276 0x81, 0x03, /* Input (Constant, Variable), */
277 0x15, 0x00, /* Logical Minimum (0), */
278 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
279 0x05, 0x01, /* Usage Page (Desktop), */
280 0x09, 0x01, /* Usage (Pointer), */
281 0xA1, 0x00, /* Collection (Physical), */
282 0x75, 0x08, /* Report Size (8), */
283 0x95, 0x02, /* Report Count (2), */
284 0x35, 0x00, /* Physical Minimum (0), */
285 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
286 0x09, 0x30, /* Usage (X), */
287 0x09, 0x31, /* Usage (Y), */
288 0x81, 0x02, /* Input (Variable), */
289 0xC0, /* End Collection, */
290 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
291 0x95, 0x06, /* Report Count (6), */
292 0x81, 0x03, /* Input (Constant, Variable), */
293 0x05, 0x01, /* Usage Page (Desktop), */
294 0x75, 0x08, /* Report Size (8), */
295 0x95, 0x05, /* Report Count (5), */
296 0x09, 0x01, /* Usage (Pointer), */
297 0x81, 0x02, /* Input (Variable), */
298 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
2259b5bb
SW
299 0x95, 0x01, /* Report Count (1), */
300 0x81, 0x02, /* Input (Variable), */
301 0x05, 0x01, /* Usage Page (Desktop), */
302 0x95, 0x01, /* Report Count (1), */
303 0x09, 0x01, /* Usage (Pointer), */
304 0x81, 0x02, /* Input (Variable), */
305 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
306 0x95, 0x1E, /* Report Count (24), */
b2723eb7
SW
307 0x81, 0x02, /* Input (Variable), */
308 0x75, 0x08, /* Report Size (8), */
309 0x95, 0x30, /* Report Count (48), */
310 0x09, 0x01, /* Usage (Pointer), */
311 0x91, 0x02, /* Output (Variable), */
312 0x75, 0x08, /* Report Size (8), */
313 0x95, 0x30, /* Report Count (48), */
314 0x09, 0x01, /* Usage (Pointer), */
315 0xB1, 0x02, /* Feature (Variable), */
316 0xC0, /* End Collection, */
317 0xA1, 0x02, /* Collection (Logical), */
318 0x85, 0x02, /* Report ID (2), */
319 0x75, 0x08, /* Report Size (8), */
320 0x95, 0x30, /* Report Count (48), */
321 0x09, 0x01, /* Usage (Pointer), */
322 0xB1, 0x02, /* Feature (Variable), */
323 0xC0, /* End Collection, */
324 0xA1, 0x02, /* Collection (Logical), */
325 0x85, 0xEE, /* Report ID (238), */
326 0x75, 0x08, /* Report Size (8), */
327 0x95, 0x30, /* Report Count (48), */
328 0x09, 0x01, /* Usage (Pointer), */
329 0xB1, 0x02, /* Feature (Variable), */
330 0xC0, /* End Collection, */
331 0xA1, 0x02, /* Collection (Logical), */
332 0x85, 0xEF, /* Report ID (239), */
333 0x75, 0x08, /* Report Size (8), */
334 0x95, 0x30, /* Report Count (48), */
335 0x09, 0x01, /* Usage (Pointer), */
336 0xB1, 0x02, /* Feature (Variable), */
337 0xC0, /* End Collection, */
338 0xC0 /* End Collection */
339};
c5e0c1c4 340
ad142b9e
FP
341/*
342 * The default descriptor doesn't provide mapping for the accelerometers
58d7027b
FP
343 * or orientation sensors. This fixed descriptor maps the accelerometers
344 * to usage values 0x40, 0x41 and 0x42 and maps the orientation sensors
345 * to usage values 0x43, 0x44 and 0x45.
346 */
ed19d8cf 347static u8 dualshock4_usb_rdesc[] = {
58d7027b
FP
348 0x05, 0x01, /* Usage Page (Desktop), */
349 0x09, 0x05, /* Usage (Gamepad), */
350 0xA1, 0x01, /* Collection (Application), */
351 0x85, 0x01, /* Report ID (1), */
352 0x09, 0x30, /* Usage (X), */
353 0x09, 0x31, /* Usage (Y), */
354 0x09, 0x32, /* Usage (Z), */
355 0x09, 0x35, /* Usage (Rz), */
356 0x15, 0x00, /* Logical Minimum (0), */
357 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
358 0x75, 0x08, /* Report Size (8), */
359 0x95, 0x04, /* Report Count (4), */
360 0x81, 0x02, /* Input (Variable), */
361 0x09, 0x39, /* Usage (Hat Switch), */
362 0x15, 0x00, /* Logical Minimum (0), */
363 0x25, 0x07, /* Logical Maximum (7), */
364 0x35, 0x00, /* Physical Minimum (0), */
365 0x46, 0x3B, 0x01, /* Physical Maximum (315), */
366 0x65, 0x14, /* Unit (Degrees), */
367 0x75, 0x04, /* Report Size (4), */
368 0x95, 0x01, /* Report Count (1), */
369 0x81, 0x42, /* Input (Variable, Null State), */
370 0x65, 0x00, /* Unit, */
371 0x05, 0x09, /* Usage Page (Button), */
372 0x19, 0x01, /* Usage Minimum (01h), */
373 0x29, 0x0E, /* Usage Maximum (0Eh), */
374 0x15, 0x00, /* Logical Minimum (0), */
375 0x25, 0x01, /* Logical Maximum (1), */
376 0x75, 0x01, /* Report Size (1), */
377 0x95, 0x0E, /* Report Count (14), */
378 0x81, 0x02, /* Input (Variable), */
379 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
380 0x09, 0x20, /* Usage (20h), */
381 0x75, 0x06, /* Report Size (6), */
382 0x95, 0x01, /* Report Count (1), */
383 0x15, 0x00, /* Logical Minimum (0), */
fb291cbd 384 0x25, 0x3F, /* Logical Maximum (63), */
58d7027b
FP
385 0x81, 0x02, /* Input (Variable), */
386 0x05, 0x01, /* Usage Page (Desktop), */
387 0x09, 0x33, /* Usage (Rx), */
388 0x09, 0x34, /* Usage (Ry), */
389 0x15, 0x00, /* Logical Minimum (0), */
390 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
391 0x75, 0x08, /* Report Size (8), */
392 0x95, 0x02, /* Report Count (2), */
393 0x81, 0x02, /* Input (Variable), */
394 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
395 0x09, 0x21, /* Usage (21h), */
396 0x95, 0x03, /* Report Count (3), */
397 0x81, 0x02, /* Input (Variable), */
398 0x05, 0x01, /* Usage Page (Desktop), */
399 0x19, 0x40, /* Usage Minimum (40h), */
400 0x29, 0x42, /* Usage Maximum (42h), */
401 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */
402 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */
403 0x75, 0x10, /* Report Size (16), */
404 0x95, 0x03, /* Report Count (3), */
405 0x81, 0x02, /* Input (Variable), */
406 0x19, 0x43, /* Usage Minimum (43h), */
407 0x29, 0x45, /* Usage Maximum (45h), */
fb291cbd
FP
408 0x16, 0x00, 0xE0, /* Logical Minimum (-8192), */
409 0x26, 0xFF, 0x1F, /* Logical Maximum (8191), */
58d7027b
FP
410 0x95, 0x03, /* Report Count (3), */
411 0x81, 0x02, /* Input (Variable), */
412 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
413 0x09, 0x21, /* Usage (21h), */
414 0x15, 0x00, /* Logical Minimum (0), */
fb291cbd 415 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
58d7027b
FP
416 0x75, 0x08, /* Report Size (8), */
417 0x95, 0x27, /* Report Count (39), */
418 0x81, 0x02, /* Input (Variable), */
419 0x85, 0x05, /* Report ID (5), */
420 0x09, 0x22, /* Usage (22h), */
421 0x95, 0x1F, /* Report Count (31), */
422 0x91, 0x02, /* Output (Variable), */
423 0x85, 0x04, /* Report ID (4), */
424 0x09, 0x23, /* Usage (23h), */
425 0x95, 0x24, /* Report Count (36), */
426 0xB1, 0x02, /* Feature (Variable), */
427 0x85, 0x02, /* Report ID (2), */
428 0x09, 0x24, /* Usage (24h), */
429 0x95, 0x24, /* Report Count (36), */
430 0xB1, 0x02, /* Feature (Variable), */
431 0x85, 0x08, /* Report ID (8), */
432 0x09, 0x25, /* Usage (25h), */
433 0x95, 0x03, /* Report Count (3), */
434 0xB1, 0x02, /* Feature (Variable), */
435 0x85, 0x10, /* Report ID (16), */
436 0x09, 0x26, /* Usage (26h), */
437 0x95, 0x04, /* Report Count (4), */
438 0xB1, 0x02, /* Feature (Variable), */
439 0x85, 0x11, /* Report ID (17), */
440 0x09, 0x27, /* Usage (27h), */
441 0x95, 0x02, /* Report Count (2), */
442 0xB1, 0x02, /* Feature (Variable), */
443 0x85, 0x12, /* Report ID (18), */
444 0x06, 0x02, 0xFF, /* Usage Page (FF02h), */
445 0x09, 0x21, /* Usage (21h), */
446 0x95, 0x0F, /* Report Count (15), */
447 0xB1, 0x02, /* Feature (Variable), */
448 0x85, 0x13, /* Report ID (19), */
449 0x09, 0x22, /* Usage (22h), */
450 0x95, 0x16, /* Report Count (22), */
451 0xB1, 0x02, /* Feature (Variable), */
452 0x85, 0x14, /* Report ID (20), */
453 0x06, 0x05, 0xFF, /* Usage Page (FF05h), */
454 0x09, 0x20, /* Usage (20h), */
455 0x95, 0x10, /* Report Count (16), */
456 0xB1, 0x02, /* Feature (Variable), */
457 0x85, 0x15, /* Report ID (21), */
458 0x09, 0x21, /* Usage (21h), */
459 0x95, 0x2C, /* Report Count (44), */
460 0xB1, 0x02, /* Feature (Variable), */
461 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */
462 0x85, 0x80, /* Report ID (128), */
463 0x09, 0x20, /* Usage (20h), */
464 0x95, 0x06, /* Report Count (6), */
465 0xB1, 0x02, /* Feature (Variable), */
466 0x85, 0x81, /* Report ID (129), */
467 0x09, 0x21, /* Usage (21h), */
468 0x95, 0x06, /* Report Count (6), */
469 0xB1, 0x02, /* Feature (Variable), */
470 0x85, 0x82, /* Report ID (130), */
471 0x09, 0x22, /* Usage (22h), */
472 0x95, 0x05, /* Report Count (5), */
473 0xB1, 0x02, /* Feature (Variable), */
474 0x85, 0x83, /* Report ID (131), */
475 0x09, 0x23, /* Usage (23h), */
476 0x95, 0x01, /* Report Count (1), */
477 0xB1, 0x02, /* Feature (Variable), */
478 0x85, 0x84, /* Report ID (132), */
479 0x09, 0x24, /* Usage (24h), */
480 0x95, 0x04, /* Report Count (4), */
481 0xB1, 0x02, /* Feature (Variable), */
482 0x85, 0x85, /* Report ID (133), */
483 0x09, 0x25, /* Usage (25h), */
484 0x95, 0x06, /* Report Count (6), */
485 0xB1, 0x02, /* Feature (Variable), */
486 0x85, 0x86, /* Report ID (134), */
487 0x09, 0x26, /* Usage (26h), */
488 0x95, 0x06, /* Report Count (6), */
489 0xB1, 0x02, /* Feature (Variable), */
490 0x85, 0x87, /* Report ID (135), */
491 0x09, 0x27, /* Usage (27h), */
492 0x95, 0x23, /* Report Count (35), */
493 0xB1, 0x02, /* Feature (Variable), */
494 0x85, 0x88, /* Report ID (136), */
495 0x09, 0x28, /* Usage (28h), */
496 0x95, 0x22, /* Report Count (34), */
497 0xB1, 0x02, /* Feature (Variable), */
498 0x85, 0x89, /* Report ID (137), */
499 0x09, 0x29, /* Usage (29h), */
500 0x95, 0x02, /* Report Count (2), */
501 0xB1, 0x02, /* Feature (Variable), */
502 0x85, 0x90, /* Report ID (144), */
503 0x09, 0x30, /* Usage (30h), */
504 0x95, 0x05, /* Report Count (5), */
505 0xB1, 0x02, /* Feature (Variable), */
506 0x85, 0x91, /* Report ID (145), */
507 0x09, 0x31, /* Usage (31h), */
508 0x95, 0x03, /* Report Count (3), */
509 0xB1, 0x02, /* Feature (Variable), */
510 0x85, 0x92, /* Report ID (146), */
511 0x09, 0x32, /* Usage (32h), */
512 0x95, 0x03, /* Report Count (3), */
513 0xB1, 0x02, /* Feature (Variable), */
514 0x85, 0x93, /* Report ID (147), */
515 0x09, 0x33, /* Usage (33h), */
516 0x95, 0x0C, /* Report Count (12), */
517 0xB1, 0x02, /* Feature (Variable), */
518 0x85, 0xA0, /* Report ID (160), */
519 0x09, 0x40, /* Usage (40h), */
520 0x95, 0x06, /* Report Count (6), */
521 0xB1, 0x02, /* Feature (Variable), */
522 0x85, 0xA1, /* Report ID (161), */
523 0x09, 0x41, /* Usage (41h), */
524 0x95, 0x01, /* Report Count (1), */
525 0xB1, 0x02, /* Feature (Variable), */
526 0x85, 0xA2, /* Report ID (162), */
527 0x09, 0x42, /* Usage (42h), */
528 0x95, 0x01, /* Report Count (1), */
529 0xB1, 0x02, /* Feature (Variable), */
530 0x85, 0xA3, /* Report ID (163), */
531 0x09, 0x43, /* Usage (43h), */
532 0x95, 0x30, /* Report Count (48), */
533 0xB1, 0x02, /* Feature (Variable), */
534 0x85, 0xA4, /* Report ID (164), */
535 0x09, 0x44, /* Usage (44h), */
536 0x95, 0x0D, /* Report Count (13), */
537 0xB1, 0x02, /* Feature (Variable), */
538 0x85, 0xA5, /* Report ID (165), */
539 0x09, 0x45, /* Usage (45h), */
540 0x95, 0x15, /* Report Count (21), */
541 0xB1, 0x02, /* Feature (Variable), */
542 0x85, 0xA6, /* Report ID (166), */
543 0x09, 0x46, /* Usage (46h), */
544 0x95, 0x15, /* Report Count (21), */
545 0xB1, 0x02, /* Feature (Variable), */
546 0x85, 0xF0, /* Report ID (240), */
547 0x09, 0x47, /* Usage (47h), */
548 0x95, 0x3F, /* Report Count (63), */
549 0xB1, 0x02, /* Feature (Variable), */
550 0x85, 0xF1, /* Report ID (241), */
551 0x09, 0x48, /* Usage (48h), */
552 0x95, 0x3F, /* Report Count (63), */
553 0xB1, 0x02, /* Feature (Variable), */
554 0x85, 0xF2, /* Report ID (242), */
555 0x09, 0x49, /* Usage (49h), */
556 0x95, 0x0F, /* Report Count (15), */
557 0xB1, 0x02, /* Feature (Variable), */
558 0x85, 0xA7, /* Report ID (167), */
559 0x09, 0x4A, /* Usage (4Ah), */
560 0x95, 0x01, /* Report Count (1), */
561 0xB1, 0x02, /* Feature (Variable), */
562 0x85, 0xA8, /* Report ID (168), */
563 0x09, 0x4B, /* Usage (4Bh), */
564 0x95, 0x01, /* Report Count (1), */
565 0xB1, 0x02, /* Feature (Variable), */
566 0x85, 0xA9, /* Report ID (169), */
567 0x09, 0x4C, /* Usage (4Ch), */
568 0x95, 0x08, /* Report Count (8), */
569 0xB1, 0x02, /* Feature (Variable), */
570 0x85, 0xAA, /* Report ID (170), */
571 0x09, 0x4E, /* Usage (4Eh), */
572 0x95, 0x01, /* Report Count (1), */
573 0xB1, 0x02, /* Feature (Variable), */
574 0x85, 0xAB, /* Report ID (171), */
575 0x09, 0x4F, /* Usage (4Fh), */
576 0x95, 0x39, /* Report Count (57), */
577 0xB1, 0x02, /* Feature (Variable), */
578 0x85, 0xAC, /* Report ID (172), */
579 0x09, 0x50, /* Usage (50h), */
580 0x95, 0x39, /* Report Count (57), */
581 0xB1, 0x02, /* Feature (Variable), */
582 0x85, 0xAD, /* Report ID (173), */
583 0x09, 0x51, /* Usage (51h), */
584 0x95, 0x0B, /* Report Count (11), */
585 0xB1, 0x02, /* Feature (Variable), */
586 0x85, 0xAE, /* Report ID (174), */
587 0x09, 0x52, /* Usage (52h), */
588 0x95, 0x01, /* Report Count (1), */
589 0xB1, 0x02, /* Feature (Variable), */
590 0x85, 0xAF, /* Report ID (175), */
591 0x09, 0x53, /* Usage (53h), */
592 0x95, 0x02, /* Report Count (2), */
593 0xB1, 0x02, /* Feature (Variable), */
594 0x85, 0xB0, /* Report ID (176), */
595 0x09, 0x54, /* Usage (54h), */
596 0x95, 0x3F, /* Report Count (63), */
597 0xB1, 0x02, /* Feature (Variable), */
598 0xC0 /* End Collection */
ed19d8cf
FP
599};
600
ad142b9e
FP
601/*
602 * The default behavior of the Dualshock 4 is to send reports using report
077147a3
FP
603 * type 1 when running over Bluetooth. However, when feature report 2 is
604 * requested during the controller initialization it starts sending input
605 * reports in report 17. Since report 17 is undefined in the default HID
d829674d 606 * descriptor the button and axis definitions must be moved to report 17 or
077147a3 607 * the HID layer won't process the received input.
d829674d
FP
608 */
609static u8 dualshock4_bt_rdesc[] = {
610 0x05, 0x01, /* Usage Page (Desktop), */
611 0x09, 0x05, /* Usage (Gamepad), */
612 0xA1, 0x01, /* Collection (Application), */
613 0x85, 0x01, /* Report ID (1), */
614 0x75, 0x08, /* Report Size (8), */
615 0x95, 0x0A, /* Report Count (9), */
616 0x81, 0x02, /* Input (Variable), */
617 0x06, 0x04, 0xFF, /* Usage Page (FF04h), */
618 0x85, 0x02, /* Report ID (2), */
619 0x09, 0x24, /* Usage (24h), */
620 0x95, 0x24, /* Report Count (36), */
621 0xB1, 0x02, /* Feature (Variable), */
622 0x85, 0xA3, /* Report ID (163), */
623 0x09, 0x25, /* Usage (25h), */
624 0x95, 0x30, /* Report Count (48), */
625 0xB1, 0x02, /* Feature (Variable), */
626 0x85, 0x05, /* Report ID (5), */
627 0x09, 0x26, /* Usage (26h), */
628 0x95, 0x28, /* Report Count (40), */
629 0xB1, 0x02, /* Feature (Variable), */
630 0x85, 0x06, /* Report ID (6), */
631 0x09, 0x27, /* Usage (27h), */
632 0x95, 0x34, /* Report Count (52), */
633 0xB1, 0x02, /* Feature (Variable), */
634 0x85, 0x07, /* Report ID (7), */
635 0x09, 0x28, /* Usage (28h), */
636 0x95, 0x30, /* Report Count (48), */
637 0xB1, 0x02, /* Feature (Variable), */
638 0x85, 0x08, /* Report ID (8), */
639 0x09, 0x29, /* Usage (29h), */
640 0x95, 0x2F, /* Report Count (47), */
641 0xB1, 0x02, /* Feature (Variable), */
642 0x06, 0x03, 0xFF, /* Usage Page (FF03h), */
643 0x85, 0x03, /* Report ID (3), */
644 0x09, 0x21, /* Usage (21h), */
645 0x95, 0x26, /* Report Count (38), */
646 0xB1, 0x02, /* Feature (Variable), */
647 0x85, 0x04, /* Report ID (4), */
648 0x09, 0x22, /* Usage (22h), */
649 0x95, 0x2E, /* Report Count (46), */
650 0xB1, 0x02, /* Feature (Variable), */
651 0x85, 0xF0, /* Report ID (240), */
652 0x09, 0x47, /* Usage (47h), */
653 0x95, 0x3F, /* Report Count (63), */
654 0xB1, 0x02, /* Feature (Variable), */
655 0x85, 0xF1, /* Report ID (241), */
656 0x09, 0x48, /* Usage (48h), */
657 0x95, 0x3F, /* Report Count (63), */
658 0xB1, 0x02, /* Feature (Variable), */
659 0x85, 0xF2, /* Report ID (242), */
660 0x09, 0x49, /* Usage (49h), */
661 0x95, 0x0F, /* Report Count (15), */
662 0xB1, 0x02, /* Feature (Variable), */
663 0x85, 0x11, /* Report ID (17), */
664 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
665 0x09, 0x20, /* Usage (20h), */
666 0x95, 0x02, /* Report Count (2), */
667 0x81, 0x02, /* Input (Variable), */
668 0x05, 0x01, /* Usage Page (Desktop), */
669 0x09, 0x30, /* Usage (X), */
670 0x09, 0x31, /* Usage (Y), */
671 0x09, 0x32, /* Usage (Z), */
672 0x09, 0x35, /* Usage (Rz), */
673 0x15, 0x00, /* Logical Minimum (0), */
674 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
675 0x75, 0x08, /* Report Size (8), */
676 0x95, 0x04, /* Report Count (4), */
677 0x81, 0x02, /* Input (Variable), */
678 0x09, 0x39, /* Usage (Hat Switch), */
679 0x15, 0x00, /* Logical Minimum (0), */
680 0x25, 0x07, /* Logical Maximum (7), */
681 0x75, 0x04, /* Report Size (4), */
682 0x95, 0x01, /* Report Count (1), */
683 0x81, 0x42, /* Input (Variable, Null State), */
684 0x05, 0x09, /* Usage Page (Button), */
685 0x19, 0x01, /* Usage Minimum (01h), */
686 0x29, 0x0E, /* Usage Maximum (0Eh), */
687 0x15, 0x00, /* Logical Minimum (0), */
688 0x25, 0x01, /* Logical Maximum (1), */
689 0x75, 0x01, /* Report Size (1), */
690 0x95, 0x0E, /* Report Count (14), */
691 0x81, 0x02, /* Input (Variable), */
692 0x75, 0x06, /* Report Size (6), */
693 0x95, 0x01, /* Report Count (1), */
694 0x81, 0x01, /* Input (Constant), */
695 0x05, 0x01, /* Usage Page (Desktop), */
696 0x09, 0x33, /* Usage (Rx), */
697 0x09, 0x34, /* Usage (Ry), */
698 0x15, 0x00, /* Logical Minimum (0), */
699 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
700 0x75, 0x08, /* Report Size (8), */
701 0x95, 0x02, /* Report Count (2), */
702 0x81, 0x02, /* Input (Variable), */
703 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
704 0x09, 0x20, /* Usage (20h), */
705 0x95, 0x03, /* Report Count (3), */
706 0x81, 0x02, /* Input (Variable), */
707 0x05, 0x01, /* Usage Page (Desktop), */
708 0x19, 0x40, /* Usage Minimum (40h), */
709 0x29, 0x42, /* Usage Maximum (42h), */
710 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */
711 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */
712 0x75, 0x10, /* Report Size (16), */
713 0x95, 0x03, /* Report Count (3), */
714 0x81, 0x02, /* Input (Variable), */
715 0x19, 0x43, /* Usage Minimum (43h), */
716 0x29, 0x45, /* Usage Maximum (45h), */
fb291cbd
FP
717 0x16, 0x00, 0xE0, /* Logical Minimum (-8192), */
718 0x26, 0xFF, 0x1F, /* Logical Maximum (8191), */
d829674d
FP
719 0x95, 0x03, /* Report Count (3), */
720 0x81, 0x02, /* Input (Variable), */
721 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
722 0x09, 0x20, /* Usage (20h), */
723 0x15, 0x00, /* Logical Minimum (0), */
724 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
725 0x75, 0x08, /* Report Size (8), */
726 0x95, 0x31, /* Report Count (51), */
727 0x81, 0x02, /* Input (Variable), */
728 0x09, 0x21, /* Usage (21h), */
729 0x75, 0x08, /* Report Size (8), */
730 0x95, 0x4D, /* Report Count (77), */
731 0x91, 0x02, /* Output (Variable), */
732 0x85, 0x12, /* Report ID (18), */
733 0x09, 0x22, /* Usage (22h), */
734 0x95, 0x8D, /* Report Count (141), */
735 0x81, 0x02, /* Input (Variable), */
736 0x09, 0x23, /* Usage (23h), */
737 0x91, 0x02, /* Output (Variable), */
738 0x85, 0x13, /* Report ID (19), */
739 0x09, 0x24, /* Usage (24h), */
740 0x95, 0xCD, /* Report Count (205), */
741 0x81, 0x02, /* Input (Variable), */
742 0x09, 0x25, /* Usage (25h), */
743 0x91, 0x02, /* Output (Variable), */
744 0x85, 0x14, /* Report ID (20), */
745 0x09, 0x26, /* Usage (26h), */
746 0x96, 0x0D, 0x01, /* Report Count (269), */
747 0x81, 0x02, /* Input (Variable), */
748 0x09, 0x27, /* Usage (27h), */
749 0x91, 0x02, /* Output (Variable), */
750 0x85, 0x15, /* Report ID (21), */
751 0x09, 0x28, /* Usage (28h), */
752 0x96, 0x4D, 0x01, /* Report Count (333), */
753 0x81, 0x02, /* Input (Variable), */
754 0x09, 0x29, /* Usage (29h), */
755 0x91, 0x02, /* Output (Variable), */
756 0x85, 0x16, /* Report ID (22), */
757 0x09, 0x2A, /* Usage (2Ah), */
758 0x96, 0x8D, 0x01, /* Report Count (397), */
759 0x81, 0x02, /* Input (Variable), */
760 0x09, 0x2B, /* Usage (2Bh), */
761 0x91, 0x02, /* Output (Variable), */
762 0x85, 0x17, /* Report ID (23), */
763 0x09, 0x2C, /* Usage (2Ch), */
764 0x96, 0xCD, 0x01, /* Report Count (461), */
765 0x81, 0x02, /* Input (Variable), */
766 0x09, 0x2D, /* Usage (2Dh), */
767 0x91, 0x02, /* Output (Variable), */
768 0x85, 0x18, /* Report ID (24), */
769 0x09, 0x2E, /* Usage (2Eh), */
770 0x96, 0x0D, 0x02, /* Report Count (525), */
771 0x81, 0x02, /* Input (Variable), */
772 0x09, 0x2F, /* Usage (2Fh), */
773 0x91, 0x02, /* Output (Variable), */
774 0x85, 0x19, /* Report ID (25), */
775 0x09, 0x30, /* Usage (30h), */
776 0x96, 0x22, 0x02, /* Report Count (546), */
777 0x81, 0x02, /* Input (Variable), */
778 0x09, 0x31, /* Usage (31h), */
779 0x91, 0x02, /* Output (Variable), */
780 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */
781 0x85, 0x82, /* Report ID (130), */
782 0x09, 0x22, /* Usage (22h), */
783 0x95, 0x3F, /* Report Count (63), */
784 0xB1, 0x02, /* Feature (Variable), */
785 0x85, 0x83, /* Report ID (131), */
786 0x09, 0x23, /* Usage (23h), */
787 0xB1, 0x02, /* Feature (Variable), */
788 0x85, 0x84, /* Report ID (132), */
789 0x09, 0x24, /* Usage (24h), */
790 0xB1, 0x02, /* Feature (Variable), */
791 0x85, 0x90, /* Report ID (144), */
792 0x09, 0x30, /* Usage (30h), */
793 0xB1, 0x02, /* Feature (Variable), */
794 0x85, 0x91, /* Report ID (145), */
795 0x09, 0x31, /* Usage (31h), */
796 0xB1, 0x02, /* Feature (Variable), */
797 0x85, 0x92, /* Report ID (146), */
798 0x09, 0x32, /* Usage (32h), */
799 0xB1, 0x02, /* Feature (Variable), */
800 0x85, 0x93, /* Report ID (147), */
801 0x09, 0x33, /* Usage (33h), */
802 0xB1, 0x02, /* Feature (Variable), */
803 0x85, 0xA0, /* Report ID (160), */
804 0x09, 0x40, /* Usage (40h), */
805 0xB1, 0x02, /* Feature (Variable), */
806 0x85, 0xA4, /* Report ID (164), */
807 0x09, 0x44, /* Usage (44h), */
808 0xB1, 0x02, /* Feature (Variable), */
809 0xC0 /* End Collection */
810};
811
078328da
JK
812static __u8 ps3remote_rdesc[] = {
813 0x05, 0x01, /* GUsagePage Generic Desktop */
814 0x09, 0x05, /* LUsage 0x05 [Game Pad] */
815 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */
816
817 /* Use collection 1 for joypad buttons */
818 0xA1, 0x02, /* MCollection Logical (interrelated data) */
819
820 /* Ignore the 1st byte, maybe it is used for a controller
821 * number but it's not needed for correct operation */
822 0x75, 0x08, /* GReportSize 0x08 [8] */
823 0x95, 0x01, /* GReportCount 0x01 [1] */
824 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
825
826 /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these
827 * buttons multiple keypresses are allowed */
828 0x05, 0x09, /* GUsagePage Button */
829 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */
830 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */
831 0x14, /* GLogicalMinimum [0] */
832 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */
833 0x75, 0x01, /* GReportSize 0x01 [1] */
834 0x95, 0x18, /* GReportCount 0x18 [24] */
835 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
836
837 0xC0, /* MEndCollection */
838
839 /* Use collection 2 for remote control buttons */
840 0xA1, 0x02, /* MCollection Logical (interrelated data) */
841
842 /* 5th byte is used for remote control buttons */
843 0x05, 0x09, /* GUsagePage Button */
844 0x18, /* LUsageMinimum [No button pressed] */
845 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */
846 0x14, /* GLogicalMinimum [0] */
847 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */
848 0x75, 0x08, /* GReportSize 0x08 [8] */
849 0x95, 0x01, /* GReportCount 0x01 [1] */
850 0x80, /* MInput */
851
852 /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at
853 * 0xff and 11th is for press indication */
854 0x75, 0x08, /* GReportSize 0x08 [8] */
855 0x95, 0x06, /* GReportCount 0x06 [6] */
856 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
857
858 /* 12th byte is for battery strength */
859 0x05, 0x06, /* GUsagePage Generic Device Controls */
860 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */
861 0x14, /* GLogicalMinimum [0] */
862 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */
863 0x75, 0x08, /* GReportSize 0x08 [8] */
864 0x95, 0x01, /* GReportCount 0x01 [1] */
865 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
866
867 0xC0, /* MEndCollection */
868
869 0xC0 /* MEndCollection [Game Pad] */
870};
871
872static const unsigned int ps3remote_keymap_joypad_buttons[] = {
873 [0x01] = KEY_SELECT,
874 [0x02] = BTN_THUMBL, /* L3 */
875 [0x03] = BTN_THUMBR, /* R3 */
876 [0x04] = BTN_START,
877 [0x05] = KEY_UP,
878 [0x06] = KEY_RIGHT,
879 [0x07] = KEY_DOWN,
880 [0x08] = KEY_LEFT,
881 [0x09] = BTN_TL2, /* L2 */
882 [0x0a] = BTN_TR2, /* R2 */
883 [0x0b] = BTN_TL, /* L1 */
884 [0x0c] = BTN_TR, /* R1 */
885 [0x0d] = KEY_OPTION, /* options/triangle */
886 [0x0e] = KEY_BACK, /* back/circle */
887 [0x0f] = BTN_0, /* cross */
888 [0x10] = KEY_SCREEN, /* view/square */
889 [0x11] = KEY_HOMEPAGE, /* PS button */
890 [0x14] = KEY_ENTER,
891};
892static const unsigned int ps3remote_keymap_remote_buttons[] = {
893 [0x00] = KEY_1,
894 [0x01] = KEY_2,
895 [0x02] = KEY_3,
896 [0x03] = KEY_4,
897 [0x04] = KEY_5,
898 [0x05] = KEY_6,
899 [0x06] = KEY_7,
900 [0x07] = KEY_8,
901 [0x08] = KEY_9,
902 [0x09] = KEY_0,
903 [0x0e] = KEY_ESC, /* return */
904 [0x0f] = KEY_CLEAR,
905 [0x16] = KEY_EJECTCD,
906 [0x1a] = KEY_MENU, /* top menu */
907 [0x28] = KEY_TIME,
908 [0x30] = KEY_PREVIOUS,
909 [0x31] = KEY_NEXT,
910 [0x32] = KEY_PLAY,
911 [0x33] = KEY_REWIND, /* scan back */
912 [0x34] = KEY_FORWARD, /* scan forward */
913 [0x38] = KEY_STOP,
914 [0x39] = KEY_PAUSE,
915 [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */
916 [0x60] = KEY_FRAMEBACK, /* slow/step back */
917 [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */
918 [0x63] = KEY_SUBTITLE,
919 [0x64] = KEY_AUDIO,
920 [0x65] = KEY_ANGLE,
921 [0x70] = KEY_INFO, /* display */
922 [0x80] = KEY_BLUE,
923 [0x81] = KEY_RED,
924 [0x82] = KEY_GREEN,
925 [0x83] = KEY_YELLOW,
926};
927
f04d5140 928static const unsigned int buzz_keymap[] = {
ad142b9e
FP
929 /*
930 * The controller has 4 remote buzzers, each with one LED and 5
f04d5140
CL
931 * buttons.
932 *
933 * We use the mapping chosen by the controller, which is:
934 *
935 * Key Offset
936 * -------------------
937 * Buzz 1
938 * Blue 5
939 * Orange 4
940 * Green 3
941 * Yellow 2
942 *
943 * So, for example, the orange button on the third buzzer is mapped to
944 * BTN_TRIGGER_HAPPY14
945 */
946 [ 1] = BTN_TRIGGER_HAPPY1,
947 [ 2] = BTN_TRIGGER_HAPPY2,
948 [ 3] = BTN_TRIGGER_HAPPY3,
949 [ 4] = BTN_TRIGGER_HAPPY4,
950 [ 5] = BTN_TRIGGER_HAPPY5,
951 [ 6] = BTN_TRIGGER_HAPPY6,
952 [ 7] = BTN_TRIGGER_HAPPY7,
953 [ 8] = BTN_TRIGGER_HAPPY8,
954 [ 9] = BTN_TRIGGER_HAPPY9,
955 [10] = BTN_TRIGGER_HAPPY10,
956 [11] = BTN_TRIGGER_HAPPY11,
957 [12] = BTN_TRIGGER_HAPPY12,
958 [13] = BTN_TRIGGER_HAPPY13,
959 [14] = BTN_TRIGGER_HAPPY14,
960 [15] = BTN_TRIGGER_HAPPY15,
961 [16] = BTN_TRIGGER_HAPPY16,
962 [17] = BTN_TRIGGER_HAPPY17,
963 [18] = BTN_TRIGGER_HAPPY18,
964 [19] = BTN_TRIGGER_HAPPY19,
965 [20] = BTN_TRIGGER_HAPPY20,
966};
967
d902f472
FP
968static enum power_supply_property sony_battery_props[] = {
969 POWER_SUPPLY_PROP_PRESENT,
970 POWER_SUPPLY_PROP_CAPACITY,
971 POWER_SUPPLY_PROP_SCOPE,
972 POWER_SUPPLY_PROP_STATUS,
973};
974
55d3b664
FP
975struct sixaxis_led {
976 __u8 time_enabled; /* the total time the led is active (0xff means forever) */
977 __u8 duty_length; /* how long a cycle is in deciseconds (0 means "really fast") */
978 __u8 enabled;
979 __u8 duty_off; /* % of duty_length the led is off (0xff means 100%) */
980 __u8 duty_on; /* % of duty_length the led is on (0xff mean 100%) */
981} __packed;
982
983struct sixaxis_rumble {
984 __u8 padding;
985 __u8 right_duration; /* Right motor duration (0xff means forever) */
986 __u8 right_motor_on; /* Right (small) motor on/off, only supports values of 0 or 1 (off/on) */
987 __u8 left_duration; /* Left motor duration (0xff means forever) */
988 __u8 left_motor_force; /* left (large) motor, supports force values from 0 to 255 */
989} __packed;
990
991struct sixaxis_output_report {
992 __u8 report_id;
993 struct sixaxis_rumble rumble;
994 __u8 padding[4];
995 __u8 leds_bitmap; /* bitmap of enabled LEDs: LED_1 = 0x02, LED_2 = 0x04, ... */
996 struct sixaxis_led led[4]; /* LEDx at (4 - x) */
997 struct sixaxis_led _reserved; /* LED5, not actually soldered */
998} __packed;
999
1000union sixaxis_output_report_01 {
1001 struct sixaxis_output_report data;
1002 __u8 buf[36];
1003};
1004
c5e0c1c4
FP
1005struct motion_output_report_02 {
1006 u8 type, zero;
1007 u8 r, g, b;
1008 u8 zero2;
1009 u8 rumble;
1010};
1011
9b2b5c9a
FP
1012#define DS4_REPORT_0x02_SIZE 37
1013#define DS4_REPORT_0x05_SIZE 32
1014#define DS4_REPORT_0x11_SIZE 78
1015#define DS4_REPORT_0x81_SIZE 7
29b691a8 1016#define SIXAXIS_REPORT_0xF2_SIZE 17
a85d67b5 1017#define SIXAXIS_REPORT_0xF5_SIZE 8
41d2d425 1018#define MOTION_REPORT_0x02_SIZE 49
9b2b5c9a 1019
8b402c92 1020static DEFINE_SPINLOCK(sony_dev_list_lock);
d2d782fc 1021static LIST_HEAD(sony_device_list);
8025087a 1022static DEFINE_IDA(sony_device_id_allocator);
d2d782fc 1023
cc6e0bbb 1024struct sony_sc {
d902f472 1025 spinlock_t lock;
d2d782fc 1026 struct list_head list_node;
0a286ef2 1027 struct hid_device *hdev;
60781cf4 1028 struct led_classdev *leds[MAX_LEDS];
cc6e0bbb 1029 unsigned long quirks;
0a286ef2 1030 struct work_struct state_worker;
d8aaccda 1031 void(*send_output_report)(struct sony_sc*);
297d716f
KK
1032 struct power_supply *battery;
1033 struct power_supply_desc battery_desc;
8025087a 1034 int device_id;
9b2b5c9a 1035 __u8 *output_report_dmabuf;
f04d5140 1036
9f323b68 1037#ifdef CONFIG_SONY_FF
9f323b68
SE
1038 __u8 left;
1039 __u8 right;
1040#endif
1041
d2d782fc 1042 __u8 mac_address[6];
5f5750d2 1043 __u8 worker_initialized;
d902f472
FP
1044 __u8 cable_state;
1045 __u8 battery_charging;
1046 __u8 battery_capacity;
60781cf4 1047 __u8 led_state[MAX_LEDS];
b3ed458c
FP
1048 __u8 led_delay_on[MAX_LEDS];
1049 __u8 led_delay_off[MAX_LEDS];
60781cf4 1050 __u8 led_count;
cc6e0bbb
JK
1051};
1052
c607fb8d
AO
1053static __u8 *sixaxis_fixup(struct hid_device *hdev, __u8 *rdesc,
1054 unsigned int *rsize)
1055{
1056 *rsize = sizeof(sixaxis_rdesc);
1057 return sixaxis_rdesc;
1058}
1059
c5e0c1c4
FP
1060static u8 *motion_fixup(struct hid_device *hdev, u8 *rdesc,
1061 unsigned int *rsize)
1062{
1063 *rsize = sizeof(motion_rdesc);
1064 return motion_rdesc;
1065}
1066
b2723eb7
SW
1067static u8 *navigation_fixup(struct hid_device *hdev, u8 *rdesc,
1068 unsigned int *rsize)
1069{
1070 *rsize = sizeof(navigation_rdesc);
1071 return navigation_rdesc;
1072}
1073
078328da
JK
1074static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc,
1075 unsigned int *rsize)
1076{
1077 *rsize = sizeof(ps3remote_rdesc);
1078 return ps3remote_rdesc;
1079}
1080
1081static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi,
1082 struct hid_field *field, struct hid_usage *usage,
1083 unsigned long **bit, int *max)
1084{
1085 unsigned int key = usage->hid & HID_USAGE;
1086
1087 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
1088 return -1;
1089
1090 switch (usage->collection_index) {
1091 case 1:
1092 if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons))
1093 return -1;
1094
1095 key = ps3remote_keymap_joypad_buttons[key];
1096 if (!key)
1097 return -1;
1098 break;
1099 case 2:
1100 if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons))
1101 return -1;
1102
1103 key = ps3remote_keymap_remote_buttons[key];
1104 if (!key)
1105 return -1;
1106 break;
1107 default:
1108 return -1;
1109 }
1110
1111 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
1112 return 1;
1113}
1114
73e4008d
NK
1115static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
1116 unsigned int *rsize)
cc6e0bbb
JK
1117{
1118 struct sony_sc *sc = hid_get_drvdata(hdev);
1119
99d24902
FLVC
1120 /*
1121 * Some Sony RF receivers wrongly declare the mouse pointer as a
1122 * a constant non-data variable.
1123 */
1124 if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 &&
1125 /* usage page: generic desktop controls */
1126 /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */
1127 /* usage: mouse */
1128 rdesc[2] == 0x09 && rdesc[3] == 0x02 &&
1129 /* input (usage page for x,y axes): constant, variable, relative */
1130 rdesc[54] == 0x81 && rdesc[55] == 0x07) {
a4649184 1131 hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n");
99d24902 1132 /* input: data, variable, relative */
cc6e0bbb
JK
1133 rdesc[55] = 0x06;
1134 }
61ab44be 1135
ed19d8cf
FP
1136 /*
1137 * The default Dualshock 4 USB descriptor doesn't assign
1138 * the gyroscope values to corresponding axes so we need a
1139 * modified one.
1140 */
1141 if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && *rsize == 467) {
1142 hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n");
1143 rdesc = dualshock4_usb_rdesc;
1144 *rsize = sizeof(dualshock4_usb_rdesc);
d829674d
FP
1145 } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && *rsize == 357) {
1146 hid_info(hdev, "Using modified Dualshock 4 Bluetooth report descriptor\n");
1147 rdesc = dualshock4_bt_rdesc;
1148 *rsize = sizeof(dualshock4_bt_rdesc);
ed19d8cf
FP
1149 }
1150
c607fb8d
AO
1151 if (sc->quirks & SIXAXIS_CONTROLLER)
1152 return sixaxis_fixup(hdev, rdesc, rsize);
078328da 1153
c5e0c1c4
FP
1154 if (sc->quirks & MOTION_CONTROLLER)
1155 return motion_fixup(hdev, rdesc, rsize);
1156
4545ee0a 1157 if (sc->quirks & NAVIGATION_CONTROLLER)
b2723eb7 1158 return navigation_fixup(hdev, rdesc, rsize);
4545ee0a 1159
078328da
JK
1160 if (sc->quirks & PS3REMOTE)
1161 return ps3remote_fixup(hdev, rdesc, rsize);
1162
73e4008d 1163 return rdesc;
cc6e0bbb
JK
1164}
1165
d902f472
FP
1166static void sixaxis_parse_report(struct sony_sc *sc, __u8 *rd, int size)
1167{
1168 static const __u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 };
1169 unsigned long flags;
12e9a6d7 1170 int offset;
d902f472
FP
1171 __u8 cable_state, battery_capacity, battery_charging;
1172
ad142b9e
FP
1173 /*
1174 * The sixaxis is charging if the battery value is 0xee
d902f472
FP
1175 * and it is fully charged if the value is 0xef.
1176 * It does not report the actual level while charging so it
1177 * is set to 100% while charging is in progress.
1178 */
12e9a6d7
SW
1179 offset = (sc->quirks & MOTION_CONTROLLER) ? 12 : 30;
1180
1181 if (rd[offset] >= 0xee) {
d902f472 1182 battery_capacity = 100;
12e9a6d7 1183 battery_charging = !(rd[offset] & 0x01);
9fddd74a 1184 cable_state = 1;
d902f472 1185 } else {
12e9a6d7 1186 __u8 index = rd[offset] <= 5 ? rd[offset] : 5;
ac3c9a94 1187 battery_capacity = sixaxis_battery_capacity[index];
d902f472 1188 battery_charging = 0;
9fddd74a 1189 cable_state = 0;
d902f472 1190 }
d902f472
FP
1191
1192 spin_lock_irqsave(&sc->lock, flags);
1193 sc->cable_state = cable_state;
1194 sc->battery_capacity = battery_capacity;
1195 sc->battery_charging = battery_charging;
1196 spin_unlock_irqrestore(&sc->lock, flags);
1197}
1198
1199static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size)
1200{
e5606230
FP
1201 struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
1202 struct hid_input, list);
1203 struct input_dev *input_dev = hidinput->input;
d902f472 1204 unsigned long flags;
6c5f860d 1205 int n, offset;
d902f472
FP
1206 __u8 cable_state, battery_capacity, battery_charging;
1207
ad142b9e
FP
1208 /*
1209 * Battery and touchpad data starts at byte 30 in the USB report and
6c5f860d
FP
1210 * 32 in Bluetooth report.
1211 */
1212 offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 30 : 32;
1213
ad142b9e
FP
1214 /*
1215 * The lower 4 bits of byte 30 contain the battery level
d902f472
FP
1216 * and the 5th bit contains the USB cable state.
1217 */
6c5f860d
FP
1218 cable_state = (rd[offset] >> 4) & 0x01;
1219 battery_capacity = rd[offset] & 0x0F;
d902f472 1220
ad142b9e
FP
1221 /*
1222 * When a USB power source is connected the battery level ranges from
6c5f860d
FP
1223 * 0 to 10, and when running on battery power it ranges from 0 to 9.
1224 * A battery level above 10 when plugged in means charge completed.
d902f472 1225 */
6c5f860d 1226 if (!cable_state || battery_capacity > 10)
d902f472
FP
1227 battery_charging = 0;
1228 else
1229 battery_charging = 1;
1230
6c5f860d
FP
1231 if (!cable_state)
1232 battery_capacity++;
d902f472 1233 if (battery_capacity > 10)
6c5f860d
FP
1234 battery_capacity = 10;
1235
d902f472
FP
1236 battery_capacity *= 10;
1237
1238 spin_lock_irqsave(&sc->lock, flags);
1239 sc->cable_state = cable_state;
1240 sc->battery_capacity = battery_capacity;
1241 sc->battery_charging = battery_charging;
1242 spin_unlock_irqrestore(&sc->lock, flags);
e5606230 1243
6c5f860d
FP
1244 offset += 5;
1245
ad142b9e
FP
1246 /*
1247 * The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB
6c5f860d 1248 * and 37 on Bluetooth.
e5606230
FP
1249 * The first 7 bits of the first byte is a counter and bit 8 is a touch
1250 * indicator that is 0 when pressed and 1 when not pressed.
1251 * The next 3 bytes are two 12 bit touch coordinates, X and Y.
1252 * The data for the second touch is in the same format and immediatly
1253 * follows the data for the first.
1254 */
1255 for (n = 0; n < 2; n++) {
1256 __u16 x, y;
1257
1258 x = rd[offset+1] | ((rd[offset+2] & 0xF) << 8);
1259 y = ((rd[offset+2] & 0xF0) >> 4) | (rd[offset+3] << 4);
1260
1261 input_mt_slot(input_dev, n);
1262 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
1263 !(rd[offset] >> 7));
1264 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
1265 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
1266
1267 offset += 4;
1268 }
d902f472
FP
1269}
1270
c9e4d877
SW
1271static int sony_raw_event(struct hid_device *hdev, struct hid_report *report,
1272 __u8 *rd, int size)
1273{
1274 struct sony_sc *sc = hid_get_drvdata(hdev);
1275
ad142b9e
FP
1276 /*
1277 * Sixaxis HID report has acclerometers/gyro with MSByte first, this
c9e4d877
SW
1278 * has to be BYTE_SWAPPED before passing up to joystick interface
1279 */
fee4e2d5 1280 if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] == 0x01 && size == 49) {
8f5f0bc2
FP
1281 /*
1282 * When connected via Bluetooth the Sixaxis occasionally sends
1283 * a report with the second byte 0xff and the rest zeroed.
1284 *
1285 * This report does not reflect the actual state of the
1286 * controller must be ignored to avoid generating false input
1287 * events.
1288 */
1289 if (rd[1] == 0xff)
1290 return -EINVAL;
1291
c9e4d877
SW
1292 swap(rd[41], rd[42]);
1293 swap(rd[43], rd[44]);
1294 swap(rd[45], rd[46]);
1295 swap(rd[47], rd[48]);
d902f472 1296
12e9a6d7
SW
1297 sixaxis_parse_report(sc, rd, size);
1298 } else if ((sc->quirks & MOTION_CONTROLLER_BT) && rd[0] == 0x01 && size == 49) {
d902f472 1299 sixaxis_parse_report(sc, rd, size);
4545ee0a
SW
1300 } else if ((sc->quirks & NAVIGATION_CONTROLLER) && rd[0] == 0x01 &&
1301 size == 49) {
1302 sixaxis_parse_report(sc, rd, size);
68330d83
FP
1303 } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 &&
1304 size == 64) || ((sc->quirks & DUALSHOCK4_CONTROLLER_BT)
1305 && rd[0] == 0x11 && size == 78)) {
d902f472 1306 dualshock4_parse_report(sc, rd, size);
c9e4d877
SW
1307 }
1308
1309 return 0;
1310}
1311
f04d5140
CL
1312static int sony_mapping(struct hid_device *hdev, struct hid_input *hi,
1313 struct hid_field *field, struct hid_usage *usage,
1314 unsigned long **bit, int *max)
1315{
1316 struct sony_sc *sc = hid_get_drvdata(hdev);
1317
1318 if (sc->quirks & BUZZ_CONTROLLER) {
1319 unsigned int key = usage->hid & HID_USAGE;
1320
1321 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
1322 return -1;
1323
1324 switch (usage->collection_index) {
1325 case 1:
1326 if (key >= ARRAY_SIZE(buzz_keymap))
1327 return -1;
1328
1329 key = buzz_keymap[key];
1330 if (!key)
1331 return -1;
1332 break;
1333 default:
1334 return -1;
1335 }
1336
1337 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
1338 return 1;
1339 }
1340
078328da
JK
1341 if (sc->quirks & PS3REMOTE)
1342 return ps3remote_mapping(hdev, hi, field, usage, bit, max);
1343
6f498018
BT
1344 /* Let hid-core decide for the others */
1345 return 0;
f04d5140
CL
1346}
1347
ce8efc3b
FP
1348static int sony_register_touchpad(struct hid_input *hi, int touch_count,
1349 int w, int h)
1350{
1351 struct input_dev *input_dev = hi->input;
1352 int ret;
1353
1354 ret = input_mt_init_slots(input_dev, touch_count, 0);
1355 if (ret < 0)
1356 return ret;
1357
1358 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, w, 0, 0);
1359 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, h, 0, 0);
1360
1361 return 0;
1362}
1363
9154301a 1364static int sony_input_configured(struct hid_device *hdev,
ce8efc3b
FP
1365 struct hid_input *hidinput)
1366{
1367 struct sony_sc *sc = hid_get_drvdata(hdev);
9154301a 1368 int ret;
ce8efc3b
FP
1369
1370 /*
1371 * The Dualshock 4 touchpad supports 2 touches and has a
981c5b4a 1372 * resolution of 1920x942 (44.86 dots/mm).
ce8efc3b
FP
1373 */
1374 if (sc->quirks & DUALSHOCK4_CONTROLLER) {
9154301a
DT
1375 ret = sony_register_touchpad(hidinput, 2, 1920, 942);
1376 if (ret) {
ce8efc3b 1377 hid_err(sc->hdev,
9154301a
DT
1378 "Unable to initialize multi-touch slots: %d\n",
1379 ret);
1380 return ret;
1381 }
ce8efc3b 1382 }
9154301a
DT
1383
1384 return 0;
ce8efc3b
FP
1385}
1386
bd28ce00
JS
1387/*
1388 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
1389 * to "operational". Without this, the ps3 controller will not report any
1390 * events.
1391 */
816651a7 1392static int sixaxis_set_operational_usb(struct hid_device *hdev)
bd28ce00 1393{
a85d67b5
AO
1394 const int buf_size =
1395 max(SIXAXIS_REPORT_0xF2_SIZE, SIXAXIS_REPORT_0xF5_SIZE);
2e701a35 1396 __u8 *buf;
bd28ce00 1397 int ret;
bd28ce00 1398
2e701a35 1399 buf = kmalloc(buf_size, GFP_KERNEL);
bd28ce00
JS
1400 if (!buf)
1401 return -ENOMEM;
1402
a85d67b5
AO
1403 ret = hid_hw_raw_request(hdev, 0xf2, buf, SIXAXIS_REPORT_0xF2_SIZE,
1404 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
a7de9b86
LK
1405 if (ret < 0) {
1406 hid_err(hdev, "can't set operational mode: step 1\n");
1407 goto out;
1408 }
f204828a 1409
a7de9b86
LK
1410 /*
1411 * Some compatible controllers like the Speedlink Strike FX and
1412 * Gasia need another query plus an USB interrupt to get operational.
1413 */
a85d67b5
AO
1414 ret = hid_hw_raw_request(hdev, 0xf5, buf, SIXAXIS_REPORT_0xF5_SIZE,
1415 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
a7de9b86
LK
1416 if (ret < 0) {
1417 hid_err(hdev, "can't set operational mode: step 2\n");
1418 goto out;
1419 }
f204828a 1420
a7de9b86 1421 ret = hid_hw_output_report(hdev, buf, 1);
bd28ce00 1422 if (ret < 0)
a7de9b86 1423 hid_err(hdev, "can't set operational mode: step 3\n");
bd28ce00 1424
a7de9b86 1425out:
bd28ce00
JS
1426 kfree(buf);
1427
1428 return ret;
1429}
1430
816651a7 1431static int sixaxis_set_operational_bt(struct hid_device *hdev)
f9ce7c28 1432{
9b2b5c9a
FP
1433 static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
1434 __u8 *buf;
1435 int ret;
1436
1437 buf = kmemdup(report, sizeof(report), GFP_KERNEL);
1438 if (!buf)
1439 return -ENOMEM;
1440
1441 ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
b0dd72aa 1442 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
9b2b5c9a
FP
1443
1444 kfree(buf);
1445
1446 return ret;
f9ce7c28
BN
1447}
1448
ad142b9e
FP
1449/*
1450 * Requesting feature report 0x02 in Bluetooth mode changes the state of the
68330d83
FP
1451 * controller so that it sends full input reports of type 0x11.
1452 */
1453static int dualshock4_set_operational_bt(struct hid_device *hdev)
1454{
9b2b5c9a
FP
1455 __u8 *buf;
1456 int ret;
68330d83 1457
9b2b5c9a
FP
1458 buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
1459 if (!buf)
1460 return -ENOMEM;
1461
1462 ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
68330d83 1463 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
9b2b5c9a
FP
1464
1465 kfree(buf);
1466
1467 return ret;
f9ce7c28
BN
1468}
1469
221399b3 1470static void sixaxis_set_leds_from_id(struct sony_sc *sc)
8025087a
FP
1471{
1472 static const __u8 sixaxis_leds[10][4] = {
1473 { 0x01, 0x00, 0x00, 0x00 },
1474 { 0x00, 0x01, 0x00, 0x00 },
1475 { 0x00, 0x00, 0x01, 0x00 },
1476 { 0x00, 0x00, 0x00, 0x01 },
1477 { 0x01, 0x00, 0x00, 0x01 },
1478 { 0x00, 0x01, 0x00, 0x01 },
1479 { 0x00, 0x00, 0x01, 0x01 },
1480 { 0x01, 0x00, 0x01, 0x01 },
1481 { 0x00, 0x01, 0x01, 0x01 },
1482 { 0x01, 0x01, 0x01, 0x01 }
1483 };
1484
221399b3
FP
1485 int id = sc->device_id;
1486
1487 BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(sixaxis_leds[0]));
8025087a
FP
1488
1489 if (id < 0)
1490 return;
1491
1492 id %= 10;
221399b3 1493 memcpy(sc->led_state, sixaxis_leds[id], sizeof(sixaxis_leds[id]));
8025087a
FP
1494}
1495
221399b3 1496static void dualshock4_set_leds_from_id(struct sony_sc *sc)
8025087a
FP
1497{
1498 /* The first 4 color/index entries match what the PS4 assigns */
1499 static const __u8 color_code[7][3] = {
1500 /* Blue */ { 0x00, 0x00, 0x01 },
1501 /* Red */ { 0x01, 0x00, 0x00 },
1502 /* Green */ { 0x00, 0x01, 0x00 },
1503 /* Pink */ { 0x02, 0x00, 0x01 },
1504 /* Orange */ { 0x02, 0x01, 0x00 },
1505 /* Teal */ { 0x00, 0x01, 0x01 },
1506 /* White */ { 0x01, 0x01, 0x01 }
1507 };
1508
221399b3
FP
1509 int id = sc->device_id;
1510
1511 BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(color_code[0]));
8025087a
FP
1512
1513 if (id < 0)
1514 return;
1515
1516 id %= 7;
221399b3 1517 memcpy(sc->led_state, color_code[id], sizeof(color_code[id]));
8025087a
FP
1518}
1519
221399b3 1520static void buzz_set_leds(struct sony_sc *sc)
f04d5140 1521{
221399b3 1522 struct hid_device *hdev = sc->hdev;
f04d5140
CL
1523 struct list_head *report_list =
1524 &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
1525 struct hid_report *report = list_entry(report_list->next,
1526 struct hid_report, list);
1527 __s32 *value = report->field[0]->value;
1528
221399b3
FP
1529 BUILD_BUG_ON(MAX_LEDS < 4);
1530
f04d5140 1531 value[0] = 0x00;
221399b3
FP
1532 value[1] = sc->led_state[0] ? 0xff : 0x00;
1533 value[2] = sc->led_state[1] ? 0xff : 0x00;
1534 value[3] = sc->led_state[2] ? 0xff : 0x00;
1535 value[4] = sc->led_state[3] ? 0xff : 0x00;
f04d5140
CL
1536 value[5] = 0x00;
1537 value[6] = 0x00;
1538 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
1539}
1540
221399b3 1541static void sony_set_leds(struct sony_sc *sc)
0a286ef2 1542{
221399b3 1543 if (!(sc->quirks & BUZZ_CONTROLLER))
fa57a810 1544 schedule_work(&sc->state_worker);
221399b3
FP
1545 else
1546 buzz_set_leds(sc);
0a286ef2
SE
1547}
1548
c5382519 1549static void sony_led_set_brightness(struct led_classdev *led,
f04d5140
CL
1550 enum led_brightness value)
1551{
1552 struct device *dev = led->dev->parent;
1553 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1554 struct sony_sc *drv_data;
f04d5140
CL
1555
1556 int n;
b3ed458c 1557 int force_update;
f04d5140
CL
1558
1559 drv_data = hid_get_drvdata(hdev);
2251b85f 1560 if (!drv_data) {
f04d5140
CL
1561 hid_err(hdev, "No device data\n");
1562 return;
1563 }
f04d5140 1564
b3ed458c
FP
1565 /*
1566 * The Sixaxis on USB will override any LED settings sent to it
1567 * and keep flashing all of the LEDs until the PS button is pressed.
1568 * Updates, even if redundant, must be always be sent to the
1569 * controller to avoid having to toggle the state of an LED just to
1570 * stop the flashing later on.
1571 */
1572 force_update = !!(drv_data->quirks & SIXAXIS_CONTROLLER_USB);
1573
60781cf4 1574 for (n = 0; n < drv_data->led_count; n++) {
b3ed458c
FP
1575 if (led == drv_data->leds[n] && (force_update ||
1576 (value != drv_data->led_state[n] ||
1577 drv_data->led_delay_on[n] ||
1578 drv_data->led_delay_off[n]))) {
1579
1580 drv_data->led_state[n] = value;
1581
1582 /* Setting the brightness stops the blinking */
1583 drv_data->led_delay_on[n] = 0;
1584 drv_data->led_delay_off[n] = 0;
1585
221399b3 1586 sony_set_leds(drv_data);
f04d5140
CL
1587 break;
1588 }
1589 }
1590}
1591
c5382519 1592static enum led_brightness sony_led_get_brightness(struct led_classdev *led)
f04d5140
CL
1593{
1594 struct device *dev = led->dev->parent;
1595 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1596 struct sony_sc *drv_data;
f04d5140
CL
1597
1598 int n;
f04d5140
CL
1599
1600 drv_data = hid_get_drvdata(hdev);
2251b85f 1601 if (!drv_data) {
f04d5140
CL
1602 hid_err(hdev, "No device data\n");
1603 return LED_OFF;
1604 }
f04d5140 1605
60781cf4 1606 for (n = 0; n < drv_data->led_count; n++) {
7db7504a
SW
1607 if (led == drv_data->leds[n])
1608 return drv_data->led_state[n];
f04d5140
CL
1609 }
1610
7db7504a 1611 return LED_OFF;
f04d5140 1612}
f04d5140 1613
b3ed458c
FP
1614static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on,
1615 unsigned long *delay_off)
1616{
1617 struct device *dev = led->dev->parent;
1618 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1619 struct sony_sc *drv_data = hid_get_drvdata(hdev);
1620 int n;
1621 __u8 new_on, new_off;
1622
1623 if (!drv_data) {
1624 hid_err(hdev, "No device data\n");
1625 return -EINVAL;
1626 }
1627
1628 /* Max delay is 255 deciseconds or 2550 milliseconds */
1629 if (*delay_on > 2550)
1630 *delay_on = 2550;
1631 if (*delay_off > 2550)
1632 *delay_off = 2550;
1633
1634 /* Blink at 1 Hz if both values are zero */
1635 if (!*delay_on && !*delay_off)
1636 *delay_on = *delay_off = 500;
1637
1638 new_on = *delay_on / 10;
1639 new_off = *delay_off / 10;
1640
1641 for (n = 0; n < drv_data->led_count; n++) {
1642 if (led == drv_data->leds[n])
1643 break;
1644 }
1645
1646 /* This LED is not registered on this device */
1647 if (n >= drv_data->led_count)
1648 return -EINVAL;
1649
1650 /* Don't schedule work if the values didn't change */
1651 if (new_on != drv_data->led_delay_on[n] ||
1652 new_off != drv_data->led_delay_off[n]) {
1653 drv_data->led_delay_on[n] = new_on;
1654 drv_data->led_delay_off[n] = new_off;
1655 schedule_work(&drv_data->state_worker);
1656 }
1657
1658 return 0;
1659}
1660
fa57a810 1661static void sony_leds_remove(struct sony_sc *sc)
0a286ef2 1662{
0a286ef2
SE
1663 struct led_classdev *led;
1664 int n;
1665
fa57a810 1666 BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
0a286ef2 1667
fa57a810
FP
1668 for (n = 0; n < sc->led_count; n++) {
1669 led = sc->leds[n];
1670 sc->leds[n] = NULL;
0a286ef2
SE
1671 if (!led)
1672 continue;
1673 led_classdev_unregister(led);
1674 kfree(led);
1675 }
60781cf4 1676
fa57a810 1677 sc->led_count = 0;
0a286ef2
SE
1678}
1679
fa57a810 1680static int sony_leds_init(struct sony_sc *sc)
f04d5140 1681{
fa57a810 1682 struct hid_device *hdev = sc->hdev;
40e32ee6 1683 int n, ret = 0;
b3ed458c 1684 int use_ds4_names;
40e32ee6
JK
1685 struct led_classdev *led;
1686 size_t name_sz;
1687 char *name;
0a286ef2
SE
1688 size_t name_len;
1689 const char *name_fmt;
b3ed458c
FP
1690 static const char * const ds4_name_str[] = { "red", "green", "blue",
1691 "global" };
5607c89a 1692 __u8 max_brightness[MAX_LEDS] = { [0 ... (MAX_LEDS - 1)] = 1 };
b3ed458c 1693 __u8 use_hw_blink[MAX_LEDS] = { 0 };
f04d5140 1694
fa57a810 1695 BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
0a286ef2 1696
fa57a810
FP
1697 if (sc->quirks & BUZZ_CONTROLLER) {
1698 sc->led_count = 4;
b3ed458c 1699 use_ds4_names = 0;
0a286ef2
SE
1700 name_len = strlen("::buzz#");
1701 name_fmt = "%s::buzz%d";
1702 /* Validate expected report characteristics. */
1703 if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7))
1704 return -ENODEV;
fa57a810 1705 } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
221399b3
FP
1706 dualshock4_set_leds_from_id(sc);
1707 sc->led_state[3] = 1;
b3ed458c
FP
1708 sc->led_count = 4;
1709 memset(max_brightness, 255, 3);
1710 use_hw_blink[3] = 1;
1711 use_ds4_names = 1;
61ebca93
FP
1712 name_len = 0;
1713 name_fmt = "%s:%s";
c5e0c1c4
FP
1714 } else if (sc->quirks & MOTION_CONTROLLER) {
1715 sc->led_count = 3;
1716 memset(max_brightness, 255, 3);
1717 use_ds4_names = 1;
1718 name_len = 0;
1719 name_fmt = "%s:%s";
4545ee0a
SW
1720 } else if (sc->quirks & NAVIGATION_CONTROLLER) {
1721 static const __u8 navigation_leds[4] = {0x01, 0x00, 0x00, 0x00};
1722
1723 memcpy(sc->led_state, navigation_leds, sizeof(navigation_leds));
1724 sc->led_count = 1;
1725 memset(use_hw_blink, 1, 4);
1726 use_ds4_names = 0;
1727 name_len = strlen("::sony#");
1728 name_fmt = "%s::sony%d";
60781cf4 1729 } else {
221399b3 1730 sixaxis_set_leds_from_id(sc);
fa57a810 1731 sc->led_count = 4;
b3ed458c
FP
1732 memset(use_hw_blink, 1, 4);
1733 use_ds4_names = 0;
61ebca93
FP
1734 name_len = strlen("::sony#");
1735 name_fmt = "%s::sony%d";
60781cf4
FP
1736 }
1737
ad142b9e
FP
1738 /*
1739 * Clear LEDs as we have no way of reading their initial state. This is
f04d5140 1740 * only relevant if the driver is loaded after somebody actively set the
ad142b9e
FP
1741 * LEDs to on
1742 */
221399b3 1743 sony_set_leds(sc);
f04d5140 1744
0a286ef2 1745 name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1;
f04d5140 1746
fa57a810 1747 for (n = 0; n < sc->led_count; n++) {
61ebca93 1748
b3ed458c
FP
1749 if (use_ds4_names)
1750 name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2;
61ebca93 1751
40e32ee6
JK
1752 led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
1753 if (!led) {
1754 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
8cd5fcda 1755 ret = -ENOMEM;
40e32ee6
JK
1756 goto error_leds;
1757 }
f04d5140 1758
40e32ee6 1759 name = (void *)(&led[1]);
b3ed458c
FP
1760 if (use_ds4_names)
1761 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev),
1762 ds4_name_str[n]);
61ebca93
FP
1763 else
1764 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1);
40e32ee6 1765 led->name = name;
221399b3 1766 led->brightness = sc->led_state[n];
b3ed458c 1767 led->max_brightness = max_brightness[n];
c5382519
SE
1768 led->brightness_get = sony_led_get_brightness;
1769 led->brightness_set = sony_led_set_brightness;
f04d5140 1770
b3ed458c
FP
1771 if (use_hw_blink[n])
1772 led->blink_set = sony_led_blink_set;
1773
8025087a
FP
1774 sc->leds[n] = led;
1775
8cd5fcda
JL
1776 ret = led_classdev_register(&hdev->dev, led);
1777 if (ret) {
40e32ee6 1778 hid_err(hdev, "Failed to register LED %d\n", n);
8025087a 1779 sc->leds[n] = NULL;
40e32ee6
JK
1780 kfree(led);
1781 goto error_leds;
f04d5140
CL
1782 }
1783 }
f04d5140
CL
1784
1785 return ret;
1786
f04d5140 1787error_leds:
fa57a810 1788 sony_leds_remove(sc);
f04d5140 1789
f04d5140 1790 return ret;
f04d5140
CL
1791}
1792
d8aaccda 1793static void sixaxis_send_output_report(struct sony_sc *sc)
a08c22c0 1794{
9b2b5c9a 1795 static const union sixaxis_output_report_01 default_report = {
55d3b664
FP
1796 .buf = {
1797 0x01,
1798 0x00, 0xff, 0x00, 0xff, 0x00,
1799 0x00, 0x00, 0x00, 0x00, 0x00,
1800 0xff, 0x27, 0x10, 0x00, 0x32,
1801 0xff, 0x27, 0x10, 0x00, 0x32,
1802 0xff, 0x27, 0x10, 0x00, 0x32,
1803 0xff, 0x27, 0x10, 0x00, 0x32,
1804 0x00, 0x00, 0x00, 0x00, 0x00
1805 }
a08c22c0 1806 };
9b2b5c9a
FP
1807 struct sixaxis_output_report *report =
1808 (struct sixaxis_output_report *)sc->output_report_dmabuf;
1809 int n;
1810
1811 /* Initialize the report with default values */
1812 memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
9f323b68 1813
0a286ef2 1814#ifdef CONFIG_SONY_FF
9b2b5c9a
FP
1815 report->rumble.right_motor_on = sc->right ? 1 : 0;
1816 report->rumble.left_motor_force = sc->left;
0a286ef2
SE
1817#endif
1818
9b2b5c9a
FP
1819 report->leds_bitmap |= sc->led_state[0] << 1;
1820 report->leds_bitmap |= sc->led_state[1] << 2;
1821 report->leds_bitmap |= sc->led_state[2] << 3;
1822 report->leds_bitmap |= sc->led_state[3] << 4;
9f323b68 1823
88f6576f 1824 /* Set flag for all leds off, required for 3rd party INTEC controller */
9b2b5c9a
FP
1825 if ((report->leds_bitmap & 0x1E) == 0)
1826 report->leds_bitmap |= 0x20;
88f6576f 1827
b3ed458c
FP
1828 /*
1829 * The LEDs in the report are indexed in reverse order to their
1830 * corresponding light on the controller.
1831 * Index 0 = LED 4, index 1 = LED 3, etc...
1832 *
1833 * In the case of both delay values being zero (blinking disabled) the
1834 * default report values should be used or the controller LED will be
1835 * always off.
1836 */
1837 for (n = 0; n < 4; n++) {
1838 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
9b2b5c9a
FP
1839 report->led[3 - n].duty_off = sc->led_delay_off[n];
1840 report->led[3 - n].duty_on = sc->led_delay_on[n];
b3ed458c
FP
1841 }
1842 }
1843
9b2b5c9a
FP
1844 hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
1845 sizeof(struct sixaxis_output_report),
1846 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
9f323b68
SE
1847}
1848
d8aaccda 1849static void dualshock4_send_output_report(struct sony_sc *sc)
0bd88dd3 1850{
0da8ea65 1851 struct hid_device *hdev = sc->hdev;
9b2b5c9a 1852 __u8 *buf = sc->output_report_dmabuf;
48220237
FP
1853 int offset;
1854
fdcf105d 1855 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
9b2b5c9a 1856 memset(buf, 0, DS4_REPORT_0x05_SIZE);
fdcf105d 1857 buf[0] = 0x05;
b3ed458c 1858 buf[1] = 0xFF;
fdcf105d
FP
1859 offset = 4;
1860 } else {
9b2b5c9a 1861 memset(buf, 0, DS4_REPORT_0x11_SIZE);
fdcf105d 1862 buf[0] = 0x11;
824deff8 1863 buf[1] = 0x80;
fdcf105d
FP
1864 buf[3] = 0x0F;
1865 offset = 6;
1866 }
0bd88dd3
FP
1867
1868#ifdef CONFIG_SONY_FF
48220237
FP
1869 buf[offset++] = sc->right;
1870 buf[offset++] = sc->left;
1871#else
1872 offset += 2;
0bd88dd3
FP
1873#endif
1874
b3ed458c
FP
1875 /* LED 3 is the global control */
1876 if (sc->led_state[3]) {
1877 buf[offset++] = sc->led_state[0];
1878 buf[offset++] = sc->led_state[1];
1879 buf[offset++] = sc->led_state[2];
1880 } else {
1881 offset += 3;
1882 }
1883
1884 /* If both delay values are zero the DualShock 4 disables blinking. */
1885 buf[offset++] = sc->led_delay_on[3];
1886 buf[offset++] = sc->led_delay_off[3];
60781cf4 1887
fdcf105d 1888 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
9b2b5c9a 1889 hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
fdcf105d 1890 else
9b2b5c9a 1891 hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
fdcf105d 1892 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
0bd88dd3
FP
1893}
1894
d8aaccda 1895static void motion_send_output_report(struct sony_sc *sc)
c5e0c1c4 1896{
c5e0c1c4
FP
1897 struct hid_device *hdev = sc->hdev;
1898 struct motion_output_report_02 *report =
1899 (struct motion_output_report_02 *)sc->output_report_dmabuf;
1900
41d2d425 1901 memset(report, 0, MOTION_REPORT_0x02_SIZE);
c5e0c1c4
FP
1902
1903 report->type = 0x02; /* set leds */
1904 report->r = sc->led_state[0];
1905 report->g = sc->led_state[1];
1906 report->b = sc->led_state[2];
1907
1908#ifdef CONFIG_SONY_FF
1909 report->rumble = max(sc->right, sc->left);
1910#endif
1911
41d2d425 1912 hid_hw_output_report(hdev, (__u8 *)report, MOTION_REPORT_0x02_SIZE);
c5e0c1c4
FP
1913}
1914
d8aaccda
FP
1915static void sony_state_worker(struct work_struct *work)
1916{
1917 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
1918 sc->send_output_report(sc);
1919}
1920
9b2b5c9a
FP
1921static int sony_allocate_output_report(struct sony_sc *sc)
1922{
4545ee0a
SW
1923 if ((sc->quirks & SIXAXIS_CONTROLLER) ||
1924 (sc->quirks & NAVIGATION_CONTROLLER))
9b2b5c9a
FP
1925 sc->output_report_dmabuf =
1926 kmalloc(sizeof(union sixaxis_output_report_01),
1927 GFP_KERNEL);
1928 else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
1929 sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
1930 GFP_KERNEL);
1931 else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
1932 sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
1933 GFP_KERNEL);
c5e0c1c4 1934 else if (sc->quirks & MOTION_CONTROLLER)
41d2d425
SW
1935 sc->output_report_dmabuf = kmalloc(MOTION_REPORT_0x02_SIZE,
1936 GFP_KERNEL);
9b2b5c9a
FP
1937 else
1938 return 0;
1939
1940 if (!sc->output_report_dmabuf)
1941 return -ENOMEM;
1942
1943 return 0;
1944}
1945
0a286ef2 1946#ifdef CONFIG_SONY_FF
9f323b68
SE
1947static int sony_play_effect(struct input_dev *dev, void *data,
1948 struct ff_effect *effect)
1949{
a08c22c0 1950 struct hid_device *hid = input_get_drvdata(dev);
9f323b68 1951 struct sony_sc *sc = hid_get_drvdata(hid);
a08c22c0
SE
1952
1953 if (effect->type != FF_RUMBLE)
1954 return 0;
1955
9f323b68 1956 sc->left = effect->u.rumble.strong_magnitude / 256;
0bd88dd3 1957 sc->right = effect->u.rumble.weak_magnitude / 256;
a08c22c0 1958
92b5c411 1959 schedule_work(&sc->state_worker);
9f323b68 1960 return 0;
a08c22c0
SE
1961}
1962
fa57a810 1963static int sony_init_ff(struct sony_sc *sc)
a08c22c0 1964{
fa57a810 1965 struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
a08c22c0
SE
1966 struct hid_input, list);
1967 struct input_dev *input_dev = hidinput->input;
1968
1969 input_set_capability(input_dev, EV_FF, FF_RUMBLE);
1970 return input_ff_create_memless(input_dev, NULL, sony_play_effect);
1971}
1972
1973#else
fa57a810 1974static int sony_init_ff(struct sony_sc *sc)
a08c22c0
SE
1975{
1976 return 0;
1977}
9f323b68 1978
a08c22c0
SE
1979#endif
1980
d902f472
FP
1981static int sony_battery_get_property(struct power_supply *psy,
1982 enum power_supply_property psp,
1983 union power_supply_propval *val)
1984{
297d716f 1985 struct sony_sc *sc = power_supply_get_drvdata(psy);
d902f472
FP
1986 unsigned long flags;
1987 int ret = 0;
1988 u8 battery_charging, battery_capacity, cable_state;
1989
1990 spin_lock_irqsave(&sc->lock, flags);
1991 battery_charging = sc->battery_charging;
1992 battery_capacity = sc->battery_capacity;
1993 cable_state = sc->cable_state;
1994 spin_unlock_irqrestore(&sc->lock, flags);
1995
1996 switch (psp) {
1997 case POWER_SUPPLY_PROP_PRESENT:
1998 val->intval = 1;
1999 break;
2000 case POWER_SUPPLY_PROP_SCOPE:
2001 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
2002 break;
2003 case POWER_SUPPLY_PROP_CAPACITY:
2004 val->intval = battery_capacity;
2005 break;
2006 case POWER_SUPPLY_PROP_STATUS:
2007 if (battery_charging)
2008 val->intval = POWER_SUPPLY_STATUS_CHARGING;
2009 else
2010 if (battery_capacity == 100 && cable_state)
2011 val->intval = POWER_SUPPLY_STATUS_FULL;
2012 else
2013 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
2014 break;
2015 default:
2016 ret = -EINVAL;
2017 break;
2018 }
2019 return ret;
9f323b68
SE
2020}
2021
d902f472 2022static int sony_battery_probe(struct sony_sc *sc)
c4e1ddf2 2023{
297d716f 2024 struct power_supply_config psy_cfg = { .drv_data = sc, };
c4e1ddf2 2025 struct hid_device *hdev = sc->hdev;
d902f472 2026 int ret;
c4e1ddf2 2027
ad142b9e
FP
2028 /*
2029 * Set the default battery level to 100% to avoid low battery warnings
d9a293a9
FP
2030 * if the battery is polled before the first device report is received.
2031 */
2032 sc->battery_capacity = 100;
2033
297d716f
KK
2034 sc->battery_desc.properties = sony_battery_props;
2035 sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props);
2036 sc->battery_desc.get_property = sony_battery_get_property;
2037 sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
2038 sc->battery_desc.use_for_apm = 0;
2039 sc->battery_desc.name = kasprintf(GFP_KERNEL,
2040 "sony_controller_battery_%pMR",
2041 sc->mac_address);
2042 if (!sc->battery_desc.name)
d902f472 2043 return -ENOMEM;
c4e1ddf2 2044
297d716f
KK
2045 sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc,
2046 &psy_cfg);
2047 if (IS_ERR(sc->battery)) {
2048 ret = PTR_ERR(sc->battery);
d902f472
FP
2049 hid_err(hdev, "Unable to register battery device\n");
2050 goto err_free;
2051 }
c4e1ddf2 2052
297d716f 2053 power_supply_powers(sc->battery, &hdev->dev);
a08c22c0 2054 return 0;
d902f472
FP
2055
2056err_free:
297d716f
KK
2057 kfree(sc->battery_desc.name);
2058 sc->battery_desc.name = NULL;
d902f472 2059 return ret;
a08c22c0 2060}
9f323b68 2061
d902f472 2062static void sony_battery_remove(struct sony_sc *sc)
9f323b68 2063{
297d716f 2064 if (!sc->battery_desc.name)
d902f472
FP
2065 return;
2066
297d716f
KK
2067 power_supply_unregister(sc->battery);
2068 kfree(sc->battery_desc.name);
2069 sc->battery_desc.name = NULL;
9f323b68 2070}
a08c22c0 2071
d2d782fc
FP
2072/*
2073 * If a controller is plugged in via USB while already connected via Bluetooth
2074 * it will show up as two devices. A global list of connected controllers and
2075 * their MAC addresses is maintained to ensure that a device is only connected
2076 * once.
2077 */
2078static int sony_check_add_dev_list(struct sony_sc *sc)
2079{
2080 struct sony_sc *entry;
2081 unsigned long flags;
2082 int ret;
2083
2084 spin_lock_irqsave(&sony_dev_list_lock, flags);
2085
2086 list_for_each_entry(entry, &sony_device_list, list_node) {
2087 ret = memcmp(sc->mac_address, entry->mac_address,
2088 sizeof(sc->mac_address));
2089 if (!ret) {
2090 ret = -EEXIST;
2091 hid_info(sc->hdev, "controller with MAC address %pMR already connected\n",
2092 sc->mac_address);
2093 goto unlock;
c4e1ddf2
FP
2094 }
2095 }
2096
d2d782fc
FP
2097 ret = 0;
2098 list_add(&(sc->list_node), &sony_device_list);
c4e1ddf2 2099
d2d782fc
FP
2100unlock:
2101 spin_unlock_irqrestore(&sony_dev_list_lock, flags);
2102 return ret;
2103}
2104
2105static void sony_remove_dev_list(struct sony_sc *sc)
2106{
2107 unsigned long flags;
c4e1ddf2 2108
d2d782fc
FP
2109 if (sc->list_node.next) {
2110 spin_lock_irqsave(&sony_dev_list_lock, flags);
2111 list_del(&(sc->list_node));
2112 spin_unlock_irqrestore(&sony_dev_list_lock, flags);
2113 }
c4e1ddf2
FP
2114}
2115
d2d782fc
FP
2116static int sony_get_bt_devaddr(struct sony_sc *sc)
2117{
2118 int ret;
2119
2120 /* HIDP stores the device MAC address as a string in the uniq field. */
2121 ret = strlen(sc->hdev->uniq);
2122 if (ret != 17)
2123 return -EINVAL;
2124
2125 ret = sscanf(sc->hdev->uniq,
2126 "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
2127 &sc->mac_address[5], &sc->mac_address[4], &sc->mac_address[3],
2128 &sc->mac_address[2], &sc->mac_address[1], &sc->mac_address[0]);
2129
2130 if (ret != 6)
2131 return -EINVAL;
2132
2133 return 0;
2134}
2135
2136static int sony_check_add(struct sony_sc *sc)
2137{
9b2b5c9a 2138 __u8 *buf = NULL;
d2d782fc
FP
2139 int n, ret;
2140
2141 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
12e9a6d7 2142 (sc->quirks & MOTION_CONTROLLER_BT) ||
4545ee0a 2143 (sc->quirks & NAVIGATION_CONTROLLER_BT) ||
d2d782fc
FP
2144 (sc->quirks & SIXAXIS_CONTROLLER_BT)) {
2145 /*
2146 * sony_get_bt_devaddr() attempts to parse the Bluetooth MAC
2147 * address from the uniq string where HIDP stores it.
2148 * As uniq cannot be guaranteed to be a MAC address in all cases
2149 * a failure of this function should not prevent the connection.
2150 */
2151 if (sony_get_bt_devaddr(sc) < 0) {
2152 hid_warn(sc->hdev, "UNIQ does not contain a MAC address; duplicate check skipped\n");
2153 return 0;
2154 }
2155 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
9b2b5c9a
FP
2156 buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
2157 if (!buf)
2158 return -ENOMEM;
d2d782fc
FP
2159
2160 /*
2161 * The MAC address of a DS4 controller connected via USB can be
2162 * retrieved with feature report 0x81. The address begins at
2163 * offset 1.
2164 */
9b2b5c9a
FP
2165 ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
2166 DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
2167 HID_REQ_GET_REPORT);
d2d782fc 2168
9b2b5c9a 2169 if (ret != DS4_REPORT_0x81_SIZE) {
d2d782fc 2170 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
9b2b5c9a
FP
2171 ret = ret < 0 ? ret : -EINVAL;
2172 goto out_free;
d2d782fc
FP
2173 }
2174
2175 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
4545ee0a
SW
2176 } else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||
2177 (sc->quirks & NAVIGATION_CONTROLLER_USB)) {
9b2b5c9a
FP
2178 buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
2179 if (!buf)
2180 return -ENOMEM;
d2d782fc
FP
2181
2182 /*
2183 * The MAC address of a Sixaxis controller connected via USB can
2184 * be retrieved with feature report 0xf2. The address begins at
2185 * offset 4.
2186 */
9b2b5c9a
FP
2187 ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
2188 SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
2189 HID_REQ_GET_REPORT);
d2d782fc 2190
9b2b5c9a 2191 if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
d2d782fc 2192 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
9b2b5c9a
FP
2193 ret = ret < 0 ? ret : -EINVAL;
2194 goto out_free;
d2d782fc
FP
2195 }
2196
2197 /*
2198 * The Sixaxis device MAC in the report is big-endian and must
2199 * be byte-swapped.
2200 */
2201 for (n = 0; n < 6; n++)
2202 sc->mac_address[5-n] = buf[4+n];
2203 } else {
2204 return 0;
2205 }
2206
9b2b5c9a
FP
2207 ret = sony_check_add_dev_list(sc);
2208
2209out_free:
2210
2211 kfree(buf);
2212
2213 return ret;
d2d782fc
FP
2214}
2215
8025087a
FP
2216static int sony_set_device_id(struct sony_sc *sc)
2217{
2218 int ret;
2219
2220 /*
2221 * Only DualShock 4 or Sixaxis controllers get an id.
2222 * All others are set to -1.
2223 */
2224 if ((sc->quirks & SIXAXIS_CONTROLLER) ||
2225 (sc->quirks & DUALSHOCK4_CONTROLLER)) {
2226 ret = ida_simple_get(&sony_device_id_allocator, 0, 0,
2227 GFP_KERNEL);
2228 if (ret < 0) {
2229 sc->device_id = -1;
2230 return ret;
2231 }
2232 sc->device_id = ret;
2233 } else {
2234 sc->device_id = -1;
2235 }
2236
2237 return 0;
2238}
2239
2240static void sony_release_device_id(struct sony_sc *sc)
2241{
2242 if (sc->device_id >= 0) {
2243 ida_simple_remove(&sony_device_id_allocator, sc->device_id);
2244 sc->device_id = -1;
2245 }
2246}
2247
d8aaccda
FP
2248static inline void sony_init_output_report(struct sony_sc *sc,
2249 void(*send_output_report)(struct sony_sc*))
46262047 2250{
d8aaccda
FP
2251 sc->send_output_report = send_output_report;
2252
46262047 2253 if (!sc->worker_initialized)
d8aaccda 2254 INIT_WORK(&sc->state_worker, sony_state_worker);
46262047
FP
2255
2256 sc->worker_initialized = 1;
2257}
2258
2259static inline void sony_cancel_work_sync(struct sony_sc *sc)
2260{
2261 if (sc->worker_initialized)
2262 cancel_work_sync(&sc->state_worker);
2263}
d2d782fc 2264
bd28ce00
JS
2265static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
2266{
2267 int ret;
cc6e0bbb
JK
2268 unsigned long quirks = id->driver_data;
2269 struct sony_sc *sc;
f04d5140 2270 unsigned int connect_mask = HID_CONNECT_DEFAULT;
cc6e0bbb 2271
abf832bf 2272 sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
cc6e0bbb 2273 if (sc == NULL) {
4291ee30 2274 hid_err(hdev, "can't alloc sony descriptor\n");
cc6e0bbb
JK
2275 return -ENOMEM;
2276 }
2277
b94993f6
FP
2278 spin_lock_init(&sc->lock);
2279
cc6e0bbb
JK
2280 sc->quirks = quirks;
2281 hid_set_drvdata(hdev, sc);
0a286ef2 2282 sc->hdev = hdev;
bd28ce00 2283
bd28ce00
JS
2284 ret = hid_parse(hdev);
2285 if (ret) {
4291ee30 2286 hid_err(hdev, "parse failed\n");
abf832bf 2287 return ret;
bd28ce00
JS
2288 }
2289
f04d5140
CL
2290 if (sc->quirks & VAIO_RDESC_CONSTANT)
2291 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
50764650 2292 else if (sc->quirks & SIXAXIS_CONTROLLER)
f04d5140
CL
2293 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
2294
2295 ret = hid_hw_start(hdev, connect_mask);
bd28ce00 2296 if (ret) {
4291ee30 2297 hid_err(hdev, "hw start failed\n");
abf832bf 2298 return ret;
bd28ce00
JS
2299 }
2300
131a8a9a 2301 ret = sony_set_device_id(sc);
9b2b5c9a 2302 if (ret < 0) {
131a8a9a 2303 hid_err(hdev, "failed to allocate the device id\n");
9b2b5c9a
FP
2304 goto err_stop;
2305 }
2306
131a8a9a 2307 ret = sony_allocate_output_report(sc);
8025087a 2308 if (ret < 0) {
131a8a9a 2309 hid_err(hdev, "failed to allocate the output report buffer\n");
8025087a
FP
2310 goto err_stop;
2311 }
2312
4545ee0a
SW
2313 if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||
2314 (sc->quirks & NAVIGATION_CONTROLLER_USB)) {
e534a935
BT
2315 /*
2316 * The Sony Sixaxis does not handle HID Output Reports on the
2317 * Interrupt EP like it could, so we need to force HID Output
2318 * Reports to use HID_REQ_SET_REPORT on the Control EP.
2319 *
2320 * There is also another issue about HID Output Reports via USB,
2321 * the Sixaxis does not want the report_id as part of the data
2322 * packet, so we have to discard buf[0] when sending the actual
2323 * control message, even for numbered reports, humpf!
2324 */
2325 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
2326 hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID;
816651a7 2327 ret = sixaxis_set_operational_usb(hdev);
d8aaccda 2328 sony_init_output_report(sc, sixaxis_send_output_report);
4545ee0a
SW
2329 } else if ((sc->quirks & SIXAXIS_CONTROLLER_BT) ||
2330 (sc->quirks & NAVIGATION_CONTROLLER_BT)) {
2078b9bb
FP
2331 /*
2332 * The Sixaxis wants output reports sent on the ctrl endpoint
2333 * when connected via Bluetooth.
2334 */
2335 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
816651a7 2336 ret = sixaxis_set_operational_bt(hdev);
d8aaccda 2337 sony_init_output_report(sc, sixaxis_send_output_report);
fee4e2d5 2338 } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
68330d83 2339 if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) {
2078b9bb
FP
2340 /*
2341 * The DualShock 4 wants output reports sent on the ctrl
2342 * endpoint when connected via Bluetooth.
2343 */
2344 hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
68330d83
FP
2345 ret = dualshock4_set_operational_bt(hdev);
2346 if (ret < 0) {
2347 hid_err(hdev, "failed to set the Dualshock 4 operational mode\n");
2348 goto err_stop;
2349 }
2350 }
c4e1ddf2 2351
d8aaccda 2352 sony_init_output_report(sc, dualshock4_send_output_report);
c5e0c1c4 2353 } else if (sc->quirks & MOTION_CONTROLLER) {
d8aaccda 2354 sony_init_output_report(sc, motion_send_output_report);
0bd88dd3
FP
2355 } else {
2356 ret = 0;
2357 }
f9ce7c28 2358
d2d782fc
FP
2359 if (ret < 0)
2360 goto err_stop;
2361
2362 ret = sony_check_add(sc);
4dfdc464 2363 if (ret < 0)
bd28ce00
JS
2364 goto err_stop;
2365
0a286ef2 2366 if (sc->quirks & SONY_LED_SUPPORT) {
fa57a810 2367 ret = sony_leds_init(sc);
0a286ef2
SE
2368 if (ret < 0)
2369 goto err_stop;
2370 }
2371
d902f472
FP
2372 if (sc->quirks & SONY_BATTERY_SUPPORT) {
2373 ret = sony_battery_probe(sc);
2374 if (ret < 0)
2375 goto err_stop;
2376
2377 /* Open the device to receive reports with battery info */
2378 ret = hid_hw_open(hdev);
2379 if (ret < 0) {
2380 hid_err(hdev, "hw open failed\n");
2381 goto err_stop;
2382 }
2383 }
2384
c8de9dbb 2385 if (sc->quirks & SONY_FF_SUPPORT) {
fa57a810 2386 ret = sony_init_ff(sc);
c8de9dbb
FP
2387 if (ret < 0)
2388 goto err_close;
5f5750d2 2389 }
a08c22c0 2390
bd28ce00 2391 return 0;
d902f472
FP
2392err_close:
2393 hid_hw_close(hdev);
bd28ce00 2394err_stop:
0a286ef2 2395 if (sc->quirks & SONY_LED_SUPPORT)
fa57a810 2396 sony_leds_remove(sc);
d902f472
FP
2397 if (sc->quirks & SONY_BATTERY_SUPPORT)
2398 sony_battery_remove(sc);
46262047 2399 sony_cancel_work_sync(sc);
9b2b5c9a 2400 kfree(sc->output_report_dmabuf);
d2d782fc 2401 sony_remove_dev_list(sc);
8025087a 2402 sony_release_device_id(sc);
bd28ce00 2403 hid_hw_stop(hdev);
bd28ce00
JS
2404 return ret;
2405}
2406
cc6e0bbb
JK
2407static void sony_remove(struct hid_device *hdev)
2408{
f04d5140
CL
2409 struct sony_sc *sc = hid_get_drvdata(hdev);
2410
0a286ef2 2411 if (sc->quirks & SONY_LED_SUPPORT)
fa57a810 2412 sony_leds_remove(sc);
f04d5140 2413
d902f472
FP
2414 if (sc->quirks & SONY_BATTERY_SUPPORT) {
2415 hid_hw_close(hdev);
2416 sony_battery_remove(sc);
2417 }
2418
46262047 2419 sony_cancel_work_sync(sc);
9f323b68 2420
9b2b5c9a
FP
2421 kfree(sc->output_report_dmabuf);
2422
d2d782fc 2423 sony_remove_dev_list(sc);
9f323b68 2424
8025087a
FP
2425 sony_release_device_id(sc);
2426
cc6e0bbb 2427 hid_hw_stop(hdev);
cc6e0bbb
JK
2428}
2429
bd28ce00 2430static const struct hid_device_id sony_devices[] = {
816651a7
AO
2431 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
2432 .driver_data = SIXAXIS_CONTROLLER_USB },
35dca5b4 2433 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
4545ee0a 2434 .driver_data = NAVIGATION_CONTROLLER_USB },
6eabaaa0 2435 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
4545ee0a 2436 .driver_data = NAVIGATION_CONTROLLER_BT },
c5e0c1c4 2437 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER),
b3bca326 2438 .driver_data = MOTION_CONTROLLER_USB },
a4afa854 2439 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER),
b3bca326 2440 .driver_data = MOTION_CONTROLLER_BT },
816651a7
AO
2441 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
2442 .driver_data = SIXAXIS_CONTROLLER_BT },
cc6e0bbb
JK
2443 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
2444 .driver_data = VAIO_RDESC_CONSTANT },
a4649184
FLVC
2445 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE),
2446 .driver_data = VAIO_RDESC_CONSTANT },
f04d5140
CL
2447 /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as
2448 * Logitech joystick from the device descriptor. */
2449 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER),
2450 .driver_data = BUZZ_CONTROLLER },
2451 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER),
2452 .driver_data = BUZZ_CONTROLLER },
078328da
JK
2453 /* PS3 BD Remote Control */
2454 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE),
2455 .driver_data = PS3REMOTE },
2456 /* Logitech Harmony Adapter for PS3 */
2457 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3),
2458 .driver_data = PS3REMOTE },
68a49e51
FP
2459 /* SMK-Link PS3 BD Remote Control */
2460 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE),
2461 .driver_data = PS3REMOTE },
0bd88dd3
FP
2462 /* Sony Dualshock 4 controllers for PS4 */
2463 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
8ab1676b 2464 .driver_data = DUALSHOCK4_CONTROLLER_USB },
0bd88dd3 2465 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
8ab1676b 2466 .driver_data = DUALSHOCK4_CONTROLLER_BT },
bd28ce00
JS
2467 { }
2468};
2469MODULE_DEVICE_TABLE(hid, sony_devices);
2470
2471static struct hid_driver sony_driver = {
ce8efc3b
FP
2472 .name = "sony",
2473 .id_table = sony_devices,
2474 .input_mapping = sony_mapping,
2475 .input_configured = sony_input_configured,
2476 .probe = sony_probe,
2477 .remove = sony_remove,
2478 .report_fixup = sony_report_fixup,
2479 .raw_event = sony_raw_event
bd28ce00 2480};
8025087a
FP
2481
2482static int __init sony_init(void)
2483{
2484 dbg_hid("Sony:%s\n", __func__);
2485
2486 return hid_register_driver(&sony_driver);
2487}
2488
2489static void __exit sony_exit(void)
2490{
2491 dbg_hid("Sony:%s\n", __func__);
2492
8025087a 2493 hid_unregister_driver(&sony_driver);
6c40065f 2494 ida_destroy(&sony_device_id_allocator);
8025087a
FP
2495}
2496module_init(sony_init);
2497module_exit(sony_exit);
bd28ce00 2498
bd28ce00 2499MODULE_LICENSE("GPL");
This page took 1.222864 seconds and 4 git commands to generate.