]>
Commit | Line | Data |
---|---|---|
bd28ce00 | 1 | /* |
078328da | 2 | * HID driver for Sony / PS2 / PS3 BD devices. |
bd28ce00 JS |
3 | * |
4 | * Copyright (c) 1999 Andreas Gal | |
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | |
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | |
bd28ce00 | 7 | * Copyright (c) 2008 Jiri Slaby |
078328da JK |
8 | * Copyright (c) 2012 David Dillow <dave@thedillows.org> |
9 | * Copyright (c) 2006-2013 Jiri Kosina | |
f04d5140 | 10 | * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com> |
bd28ce00 JS |
11 | */ |
12 | ||
13 | /* | |
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) | |
17 | * any later version. | |
18 | */ | |
19 | ||
078328da JK |
20 | /* NOTE: in order for the Sony PS3 BD Remote Control to be found by |
21 | * a Bluetooth host, the key combination Start+Enter has to be kept pressed | |
22 | * for about 7 seconds with the Bluetooth Host Controller in discovering mode. | |
23 | * | |
24 | * There will be no PIN request from the device. | |
25 | */ | |
26 | ||
bd28ce00 JS |
27 | #include <linux/device.h> |
28 | #include <linux/hid.h> | |
29 | #include <linux/module.h> | |
5a0e3ad6 | 30 | #include <linux/slab.h> |
bd28ce00 | 31 | #include <linux/usb.h> |
40e32ee6 | 32 | #include <linux/leds.h> |
d902f472 FP |
33 | #include <linux/power_supply.h> |
34 | #include <linux/spinlock.h> | |
e5606230 | 35 | #include <linux/input/mt.h> |
bd28ce00 JS |
36 | |
37 | #include "hid-ids.h" | |
38 | ||
6c79c18c FP |
39 | #define VAIO_RDESC_CONSTANT BIT(0) |
40 | #define SIXAXIS_CONTROLLER_USB BIT(1) | |
41 | #define SIXAXIS_CONTROLLER_BT BIT(2) | |
42 | #define BUZZ_CONTROLLER BIT(3) | |
43 | #define PS3REMOTE BIT(4) | |
8ab1676b FP |
44 | #define DUALSHOCK4_CONTROLLER_USB BIT(5) |
45 | #define DUALSHOCK4_CONTROLLER_BT BIT(6) | |
cc6e0bbb | 46 | |
8ab1676b | 47 | #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER | DUALSHOCK4_CONTROLLER_USB) |
d902f472 | 48 | #define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT | DUALSHOCK4_CONTROLLER_USB) |
60781cf4 FP |
49 | |
50 | #define MAX_LEDS 4 | |
0a286ef2 | 51 | |
61ab44be SW |
52 | static const u8 sixaxis_rdesc_fixup[] = { |
53 | 0x95, 0x13, 0x09, 0x01, 0x81, 0x02, 0x95, 0x0C, | |
54 | 0x81, 0x01, 0x75, 0x10, 0x95, 0x04, 0x26, 0xFF, | |
55 | 0x03, 0x46, 0xFF, 0x03, 0x09, 0x01, 0x81, 0x02 | |
56 | }; | |
57 | ||
e57a67da MCC |
58 | static const u8 sixaxis_rdesc_fixup2[] = { |
59 | 0x05, 0x01, 0x09, 0x04, 0xa1, 0x01, 0xa1, 0x02, | |
60 | 0x85, 0x01, 0x75, 0x08, 0x95, 0x01, 0x15, 0x00, | |
61 | 0x26, 0xff, 0x00, 0x81, 0x03, 0x75, 0x01, 0x95, | |
62 | 0x13, 0x15, 0x00, 0x25, 0x01, 0x35, 0x00, 0x45, | |
63 | 0x01, 0x05, 0x09, 0x19, 0x01, 0x29, 0x13, 0x81, | |
64 | 0x02, 0x75, 0x01, 0x95, 0x0d, 0x06, 0x00, 0xff, | |
65 | 0x81, 0x03, 0x15, 0x00, 0x26, 0xff, 0x00, 0x05, | |
66 | 0x01, 0x09, 0x01, 0xa1, 0x00, 0x75, 0x08, 0x95, | |
67 | 0x04, 0x35, 0x00, 0x46, 0xff, 0x00, 0x09, 0x30, | |
68 | 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x81, 0x02, | |
69 | 0xc0, 0x05, 0x01, 0x95, 0x13, 0x09, 0x01, 0x81, | |
70 | 0x02, 0x95, 0x0c, 0x81, 0x01, 0x75, 0x10, 0x95, | |
71 | 0x04, 0x26, 0xff, 0x03, 0x46, 0xff, 0x03, 0x09, | |
72 | 0x01, 0x81, 0x02, 0xc0, 0xa1, 0x02, 0x85, 0x02, | |
73 | 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, 0xb1, 0x02, | |
74 | 0xc0, 0xa1, 0x02, 0x85, 0xee, 0x75, 0x08, 0x95, | |
75 | 0x30, 0x09, 0x01, 0xb1, 0x02, 0xc0, 0xa1, 0x02, | |
76 | 0x85, 0xef, 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, | |
77 | 0xb1, 0x02, 0xc0, 0xc0, | |
78 | }; | |
79 | ||
58d7027b FP |
80 | /* The default descriptor doesn't provide mapping for the accelerometers |
81 | * or orientation sensors. This fixed descriptor maps the accelerometers | |
82 | * to usage values 0x40, 0x41 and 0x42 and maps the orientation sensors | |
83 | * to usage values 0x43, 0x44 and 0x45. | |
84 | */ | |
ed19d8cf | 85 | static u8 dualshock4_usb_rdesc[] = { |
58d7027b FP |
86 | 0x05, 0x01, /* Usage Page (Desktop), */ |
87 | 0x09, 0x05, /* Usage (Gamepad), */ | |
88 | 0xA1, 0x01, /* Collection (Application), */ | |
89 | 0x85, 0x01, /* Report ID (1), */ | |
90 | 0x09, 0x30, /* Usage (X), */ | |
91 | 0x09, 0x31, /* Usage (Y), */ | |
92 | 0x09, 0x32, /* Usage (Z), */ | |
93 | 0x09, 0x35, /* Usage (Rz), */ | |
94 | 0x15, 0x00, /* Logical Minimum (0), */ | |
95 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | |
96 | 0x75, 0x08, /* Report Size (8), */ | |
97 | 0x95, 0x04, /* Report Count (4), */ | |
98 | 0x81, 0x02, /* Input (Variable), */ | |
99 | 0x09, 0x39, /* Usage (Hat Switch), */ | |
100 | 0x15, 0x00, /* Logical Minimum (0), */ | |
101 | 0x25, 0x07, /* Logical Maximum (7), */ | |
102 | 0x35, 0x00, /* Physical Minimum (0), */ | |
103 | 0x46, 0x3B, 0x01, /* Physical Maximum (315), */ | |
104 | 0x65, 0x14, /* Unit (Degrees), */ | |
105 | 0x75, 0x04, /* Report Size (4), */ | |
106 | 0x95, 0x01, /* Report Count (1), */ | |
107 | 0x81, 0x42, /* Input (Variable, Null State), */ | |
108 | 0x65, 0x00, /* Unit, */ | |
109 | 0x05, 0x09, /* Usage Page (Button), */ | |
110 | 0x19, 0x01, /* Usage Minimum (01h), */ | |
111 | 0x29, 0x0E, /* Usage Maximum (0Eh), */ | |
112 | 0x15, 0x00, /* Logical Minimum (0), */ | |
113 | 0x25, 0x01, /* Logical Maximum (1), */ | |
114 | 0x75, 0x01, /* Report Size (1), */ | |
115 | 0x95, 0x0E, /* Report Count (14), */ | |
116 | 0x81, 0x02, /* Input (Variable), */ | |
117 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | |
118 | 0x09, 0x20, /* Usage (20h), */ | |
119 | 0x75, 0x06, /* Report Size (6), */ | |
120 | 0x95, 0x01, /* Report Count (1), */ | |
121 | 0x15, 0x00, /* Logical Minimum (0), */ | |
122 | 0x25, 0x7F, /* Logical Maximum (127), */ | |
123 | 0x81, 0x02, /* Input (Variable), */ | |
124 | 0x05, 0x01, /* Usage Page (Desktop), */ | |
125 | 0x09, 0x33, /* Usage (Rx), */ | |
126 | 0x09, 0x34, /* Usage (Ry), */ | |
127 | 0x15, 0x00, /* Logical Minimum (0), */ | |
128 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | |
129 | 0x75, 0x08, /* Report Size (8), */ | |
130 | 0x95, 0x02, /* Report Count (2), */ | |
131 | 0x81, 0x02, /* Input (Variable), */ | |
132 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | |
133 | 0x09, 0x21, /* Usage (21h), */ | |
134 | 0x95, 0x03, /* Report Count (3), */ | |
135 | 0x81, 0x02, /* Input (Variable), */ | |
136 | 0x05, 0x01, /* Usage Page (Desktop), */ | |
137 | 0x19, 0x40, /* Usage Minimum (40h), */ | |
138 | 0x29, 0x42, /* Usage Maximum (42h), */ | |
139 | 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */ | |
140 | 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */ | |
141 | 0x75, 0x10, /* Report Size (16), */ | |
142 | 0x95, 0x03, /* Report Count (3), */ | |
143 | 0x81, 0x02, /* Input (Variable), */ | |
144 | 0x19, 0x43, /* Usage Minimum (43h), */ | |
145 | 0x29, 0x45, /* Usage Maximum (45h), */ | |
146 | 0x16, 0xFF, 0xBF, /* Logical Minimum (-16385), */ | |
147 | 0x26, 0x00, 0x40, /* Logical Maximum (16384), */ | |
148 | 0x95, 0x03, /* Report Count (3), */ | |
149 | 0x81, 0x02, /* Input (Variable), */ | |
150 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | |
151 | 0x09, 0x21, /* Usage (21h), */ | |
152 | 0x15, 0x00, /* Logical Minimum (0), */ | |
153 | 0x25, 0xFF, /* Logical Maximum (255), */ | |
154 | 0x75, 0x08, /* Report Size (8), */ | |
155 | 0x95, 0x27, /* Report Count (39), */ | |
156 | 0x81, 0x02, /* Input (Variable), */ | |
157 | 0x85, 0x05, /* Report ID (5), */ | |
158 | 0x09, 0x22, /* Usage (22h), */ | |
159 | 0x95, 0x1F, /* Report Count (31), */ | |
160 | 0x91, 0x02, /* Output (Variable), */ | |
161 | 0x85, 0x04, /* Report ID (4), */ | |
162 | 0x09, 0x23, /* Usage (23h), */ | |
163 | 0x95, 0x24, /* Report Count (36), */ | |
164 | 0xB1, 0x02, /* Feature (Variable), */ | |
165 | 0x85, 0x02, /* Report ID (2), */ | |
166 | 0x09, 0x24, /* Usage (24h), */ | |
167 | 0x95, 0x24, /* Report Count (36), */ | |
168 | 0xB1, 0x02, /* Feature (Variable), */ | |
169 | 0x85, 0x08, /* Report ID (8), */ | |
170 | 0x09, 0x25, /* Usage (25h), */ | |
171 | 0x95, 0x03, /* Report Count (3), */ | |
172 | 0xB1, 0x02, /* Feature (Variable), */ | |
173 | 0x85, 0x10, /* Report ID (16), */ | |
174 | 0x09, 0x26, /* Usage (26h), */ | |
175 | 0x95, 0x04, /* Report Count (4), */ | |
176 | 0xB1, 0x02, /* Feature (Variable), */ | |
177 | 0x85, 0x11, /* Report ID (17), */ | |
178 | 0x09, 0x27, /* Usage (27h), */ | |
179 | 0x95, 0x02, /* Report Count (2), */ | |
180 | 0xB1, 0x02, /* Feature (Variable), */ | |
181 | 0x85, 0x12, /* Report ID (18), */ | |
182 | 0x06, 0x02, 0xFF, /* Usage Page (FF02h), */ | |
183 | 0x09, 0x21, /* Usage (21h), */ | |
184 | 0x95, 0x0F, /* Report Count (15), */ | |
185 | 0xB1, 0x02, /* Feature (Variable), */ | |
186 | 0x85, 0x13, /* Report ID (19), */ | |
187 | 0x09, 0x22, /* Usage (22h), */ | |
188 | 0x95, 0x16, /* Report Count (22), */ | |
189 | 0xB1, 0x02, /* Feature (Variable), */ | |
190 | 0x85, 0x14, /* Report ID (20), */ | |
191 | 0x06, 0x05, 0xFF, /* Usage Page (FF05h), */ | |
192 | 0x09, 0x20, /* Usage (20h), */ | |
193 | 0x95, 0x10, /* Report Count (16), */ | |
194 | 0xB1, 0x02, /* Feature (Variable), */ | |
195 | 0x85, 0x15, /* Report ID (21), */ | |
196 | 0x09, 0x21, /* Usage (21h), */ | |
197 | 0x95, 0x2C, /* Report Count (44), */ | |
198 | 0xB1, 0x02, /* Feature (Variable), */ | |
199 | 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */ | |
200 | 0x85, 0x80, /* Report ID (128), */ | |
201 | 0x09, 0x20, /* Usage (20h), */ | |
202 | 0x95, 0x06, /* Report Count (6), */ | |
203 | 0xB1, 0x02, /* Feature (Variable), */ | |
204 | 0x85, 0x81, /* Report ID (129), */ | |
205 | 0x09, 0x21, /* Usage (21h), */ | |
206 | 0x95, 0x06, /* Report Count (6), */ | |
207 | 0xB1, 0x02, /* Feature (Variable), */ | |
208 | 0x85, 0x82, /* Report ID (130), */ | |
209 | 0x09, 0x22, /* Usage (22h), */ | |
210 | 0x95, 0x05, /* Report Count (5), */ | |
211 | 0xB1, 0x02, /* Feature (Variable), */ | |
212 | 0x85, 0x83, /* Report ID (131), */ | |
213 | 0x09, 0x23, /* Usage (23h), */ | |
214 | 0x95, 0x01, /* Report Count (1), */ | |
215 | 0xB1, 0x02, /* Feature (Variable), */ | |
216 | 0x85, 0x84, /* Report ID (132), */ | |
217 | 0x09, 0x24, /* Usage (24h), */ | |
218 | 0x95, 0x04, /* Report Count (4), */ | |
219 | 0xB1, 0x02, /* Feature (Variable), */ | |
220 | 0x85, 0x85, /* Report ID (133), */ | |
221 | 0x09, 0x25, /* Usage (25h), */ | |
222 | 0x95, 0x06, /* Report Count (6), */ | |
223 | 0xB1, 0x02, /* Feature (Variable), */ | |
224 | 0x85, 0x86, /* Report ID (134), */ | |
225 | 0x09, 0x26, /* Usage (26h), */ | |
226 | 0x95, 0x06, /* Report Count (6), */ | |
227 | 0xB1, 0x02, /* Feature (Variable), */ | |
228 | 0x85, 0x87, /* Report ID (135), */ | |
229 | 0x09, 0x27, /* Usage (27h), */ | |
230 | 0x95, 0x23, /* Report Count (35), */ | |
231 | 0xB1, 0x02, /* Feature (Variable), */ | |
232 | 0x85, 0x88, /* Report ID (136), */ | |
233 | 0x09, 0x28, /* Usage (28h), */ | |
234 | 0x95, 0x22, /* Report Count (34), */ | |
235 | 0xB1, 0x02, /* Feature (Variable), */ | |
236 | 0x85, 0x89, /* Report ID (137), */ | |
237 | 0x09, 0x29, /* Usage (29h), */ | |
238 | 0x95, 0x02, /* Report Count (2), */ | |
239 | 0xB1, 0x02, /* Feature (Variable), */ | |
240 | 0x85, 0x90, /* Report ID (144), */ | |
241 | 0x09, 0x30, /* Usage (30h), */ | |
242 | 0x95, 0x05, /* Report Count (5), */ | |
243 | 0xB1, 0x02, /* Feature (Variable), */ | |
244 | 0x85, 0x91, /* Report ID (145), */ | |
245 | 0x09, 0x31, /* Usage (31h), */ | |
246 | 0x95, 0x03, /* Report Count (3), */ | |
247 | 0xB1, 0x02, /* Feature (Variable), */ | |
248 | 0x85, 0x92, /* Report ID (146), */ | |
249 | 0x09, 0x32, /* Usage (32h), */ | |
250 | 0x95, 0x03, /* Report Count (3), */ | |
251 | 0xB1, 0x02, /* Feature (Variable), */ | |
252 | 0x85, 0x93, /* Report ID (147), */ | |
253 | 0x09, 0x33, /* Usage (33h), */ | |
254 | 0x95, 0x0C, /* Report Count (12), */ | |
255 | 0xB1, 0x02, /* Feature (Variable), */ | |
256 | 0x85, 0xA0, /* Report ID (160), */ | |
257 | 0x09, 0x40, /* Usage (40h), */ | |
258 | 0x95, 0x06, /* Report Count (6), */ | |
259 | 0xB1, 0x02, /* Feature (Variable), */ | |
260 | 0x85, 0xA1, /* Report ID (161), */ | |
261 | 0x09, 0x41, /* Usage (41h), */ | |
262 | 0x95, 0x01, /* Report Count (1), */ | |
263 | 0xB1, 0x02, /* Feature (Variable), */ | |
264 | 0x85, 0xA2, /* Report ID (162), */ | |
265 | 0x09, 0x42, /* Usage (42h), */ | |
266 | 0x95, 0x01, /* Report Count (1), */ | |
267 | 0xB1, 0x02, /* Feature (Variable), */ | |
268 | 0x85, 0xA3, /* Report ID (163), */ | |
269 | 0x09, 0x43, /* Usage (43h), */ | |
270 | 0x95, 0x30, /* Report Count (48), */ | |
271 | 0xB1, 0x02, /* Feature (Variable), */ | |
272 | 0x85, 0xA4, /* Report ID (164), */ | |
273 | 0x09, 0x44, /* Usage (44h), */ | |
274 | 0x95, 0x0D, /* Report Count (13), */ | |
275 | 0xB1, 0x02, /* Feature (Variable), */ | |
276 | 0x85, 0xA5, /* Report ID (165), */ | |
277 | 0x09, 0x45, /* Usage (45h), */ | |
278 | 0x95, 0x15, /* Report Count (21), */ | |
279 | 0xB1, 0x02, /* Feature (Variable), */ | |
280 | 0x85, 0xA6, /* Report ID (166), */ | |
281 | 0x09, 0x46, /* Usage (46h), */ | |
282 | 0x95, 0x15, /* Report Count (21), */ | |
283 | 0xB1, 0x02, /* Feature (Variable), */ | |
284 | 0x85, 0xF0, /* Report ID (240), */ | |
285 | 0x09, 0x47, /* Usage (47h), */ | |
286 | 0x95, 0x3F, /* Report Count (63), */ | |
287 | 0xB1, 0x02, /* Feature (Variable), */ | |
288 | 0x85, 0xF1, /* Report ID (241), */ | |
289 | 0x09, 0x48, /* Usage (48h), */ | |
290 | 0x95, 0x3F, /* Report Count (63), */ | |
291 | 0xB1, 0x02, /* Feature (Variable), */ | |
292 | 0x85, 0xF2, /* Report ID (242), */ | |
293 | 0x09, 0x49, /* Usage (49h), */ | |
294 | 0x95, 0x0F, /* Report Count (15), */ | |
295 | 0xB1, 0x02, /* Feature (Variable), */ | |
296 | 0x85, 0xA7, /* Report ID (167), */ | |
297 | 0x09, 0x4A, /* Usage (4Ah), */ | |
298 | 0x95, 0x01, /* Report Count (1), */ | |
299 | 0xB1, 0x02, /* Feature (Variable), */ | |
300 | 0x85, 0xA8, /* Report ID (168), */ | |
301 | 0x09, 0x4B, /* Usage (4Bh), */ | |
302 | 0x95, 0x01, /* Report Count (1), */ | |
303 | 0xB1, 0x02, /* Feature (Variable), */ | |
304 | 0x85, 0xA9, /* Report ID (169), */ | |
305 | 0x09, 0x4C, /* Usage (4Ch), */ | |
306 | 0x95, 0x08, /* Report Count (8), */ | |
307 | 0xB1, 0x02, /* Feature (Variable), */ | |
308 | 0x85, 0xAA, /* Report ID (170), */ | |
309 | 0x09, 0x4E, /* Usage (4Eh), */ | |
310 | 0x95, 0x01, /* Report Count (1), */ | |
311 | 0xB1, 0x02, /* Feature (Variable), */ | |
312 | 0x85, 0xAB, /* Report ID (171), */ | |
313 | 0x09, 0x4F, /* Usage (4Fh), */ | |
314 | 0x95, 0x39, /* Report Count (57), */ | |
315 | 0xB1, 0x02, /* Feature (Variable), */ | |
316 | 0x85, 0xAC, /* Report ID (172), */ | |
317 | 0x09, 0x50, /* Usage (50h), */ | |
318 | 0x95, 0x39, /* Report Count (57), */ | |
319 | 0xB1, 0x02, /* Feature (Variable), */ | |
320 | 0x85, 0xAD, /* Report ID (173), */ | |
321 | 0x09, 0x51, /* Usage (51h), */ | |
322 | 0x95, 0x0B, /* Report Count (11), */ | |
323 | 0xB1, 0x02, /* Feature (Variable), */ | |
324 | 0x85, 0xAE, /* Report ID (174), */ | |
325 | 0x09, 0x52, /* Usage (52h), */ | |
326 | 0x95, 0x01, /* Report Count (1), */ | |
327 | 0xB1, 0x02, /* Feature (Variable), */ | |
328 | 0x85, 0xAF, /* Report ID (175), */ | |
329 | 0x09, 0x53, /* Usage (53h), */ | |
330 | 0x95, 0x02, /* Report Count (2), */ | |
331 | 0xB1, 0x02, /* Feature (Variable), */ | |
332 | 0x85, 0xB0, /* Report ID (176), */ | |
333 | 0x09, 0x54, /* Usage (54h), */ | |
334 | 0x95, 0x3F, /* Report Count (63), */ | |
335 | 0xB1, 0x02, /* Feature (Variable), */ | |
336 | 0xC0 /* End Collection */ | |
ed19d8cf FP |
337 | }; |
338 | ||
d829674d FP |
339 | /* The default behavior of the Dualshock 4 is to send reports using report |
340 | * type 1 when running over Bluetooth. However, as soon as it receives a | |
341 | * report of type 17 to set the LEDs or rumble it starts returning it's state | |
342 | * in report 17 instead of 1. Since report 17 is undefined in the default HID | |
343 | * descriptor the button and axis definitions must be moved to report 17 or | |
344 | * the HID layer won't process the received input once a report is sent. | |
345 | */ | |
346 | static u8 dualshock4_bt_rdesc[] = { | |
347 | 0x05, 0x01, /* Usage Page (Desktop), */ | |
348 | 0x09, 0x05, /* Usage (Gamepad), */ | |
349 | 0xA1, 0x01, /* Collection (Application), */ | |
350 | 0x85, 0x01, /* Report ID (1), */ | |
351 | 0x75, 0x08, /* Report Size (8), */ | |
352 | 0x95, 0x0A, /* Report Count (9), */ | |
353 | 0x81, 0x02, /* Input (Variable), */ | |
354 | 0x06, 0x04, 0xFF, /* Usage Page (FF04h), */ | |
355 | 0x85, 0x02, /* Report ID (2), */ | |
356 | 0x09, 0x24, /* Usage (24h), */ | |
357 | 0x95, 0x24, /* Report Count (36), */ | |
358 | 0xB1, 0x02, /* Feature (Variable), */ | |
359 | 0x85, 0xA3, /* Report ID (163), */ | |
360 | 0x09, 0x25, /* Usage (25h), */ | |
361 | 0x95, 0x30, /* Report Count (48), */ | |
362 | 0xB1, 0x02, /* Feature (Variable), */ | |
363 | 0x85, 0x05, /* Report ID (5), */ | |
364 | 0x09, 0x26, /* Usage (26h), */ | |
365 | 0x95, 0x28, /* Report Count (40), */ | |
366 | 0xB1, 0x02, /* Feature (Variable), */ | |
367 | 0x85, 0x06, /* Report ID (6), */ | |
368 | 0x09, 0x27, /* Usage (27h), */ | |
369 | 0x95, 0x34, /* Report Count (52), */ | |
370 | 0xB1, 0x02, /* Feature (Variable), */ | |
371 | 0x85, 0x07, /* Report ID (7), */ | |
372 | 0x09, 0x28, /* Usage (28h), */ | |
373 | 0x95, 0x30, /* Report Count (48), */ | |
374 | 0xB1, 0x02, /* Feature (Variable), */ | |
375 | 0x85, 0x08, /* Report ID (8), */ | |
376 | 0x09, 0x29, /* Usage (29h), */ | |
377 | 0x95, 0x2F, /* Report Count (47), */ | |
378 | 0xB1, 0x02, /* Feature (Variable), */ | |
379 | 0x06, 0x03, 0xFF, /* Usage Page (FF03h), */ | |
380 | 0x85, 0x03, /* Report ID (3), */ | |
381 | 0x09, 0x21, /* Usage (21h), */ | |
382 | 0x95, 0x26, /* Report Count (38), */ | |
383 | 0xB1, 0x02, /* Feature (Variable), */ | |
384 | 0x85, 0x04, /* Report ID (4), */ | |
385 | 0x09, 0x22, /* Usage (22h), */ | |
386 | 0x95, 0x2E, /* Report Count (46), */ | |
387 | 0xB1, 0x02, /* Feature (Variable), */ | |
388 | 0x85, 0xF0, /* Report ID (240), */ | |
389 | 0x09, 0x47, /* Usage (47h), */ | |
390 | 0x95, 0x3F, /* Report Count (63), */ | |
391 | 0xB1, 0x02, /* Feature (Variable), */ | |
392 | 0x85, 0xF1, /* Report ID (241), */ | |
393 | 0x09, 0x48, /* Usage (48h), */ | |
394 | 0x95, 0x3F, /* Report Count (63), */ | |
395 | 0xB1, 0x02, /* Feature (Variable), */ | |
396 | 0x85, 0xF2, /* Report ID (242), */ | |
397 | 0x09, 0x49, /* Usage (49h), */ | |
398 | 0x95, 0x0F, /* Report Count (15), */ | |
399 | 0xB1, 0x02, /* Feature (Variable), */ | |
400 | 0x85, 0x11, /* Report ID (17), */ | |
401 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | |
402 | 0x09, 0x20, /* Usage (20h), */ | |
403 | 0x95, 0x02, /* Report Count (2), */ | |
404 | 0x81, 0x02, /* Input (Variable), */ | |
405 | 0x05, 0x01, /* Usage Page (Desktop), */ | |
406 | 0x09, 0x30, /* Usage (X), */ | |
407 | 0x09, 0x31, /* Usage (Y), */ | |
408 | 0x09, 0x32, /* Usage (Z), */ | |
409 | 0x09, 0x35, /* Usage (Rz), */ | |
410 | 0x15, 0x00, /* Logical Minimum (0), */ | |
411 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | |
412 | 0x75, 0x08, /* Report Size (8), */ | |
413 | 0x95, 0x04, /* Report Count (4), */ | |
414 | 0x81, 0x02, /* Input (Variable), */ | |
415 | 0x09, 0x39, /* Usage (Hat Switch), */ | |
416 | 0x15, 0x00, /* Logical Minimum (0), */ | |
417 | 0x25, 0x07, /* Logical Maximum (7), */ | |
418 | 0x75, 0x04, /* Report Size (4), */ | |
419 | 0x95, 0x01, /* Report Count (1), */ | |
420 | 0x81, 0x42, /* Input (Variable, Null State), */ | |
421 | 0x05, 0x09, /* Usage Page (Button), */ | |
422 | 0x19, 0x01, /* Usage Minimum (01h), */ | |
423 | 0x29, 0x0E, /* Usage Maximum (0Eh), */ | |
424 | 0x15, 0x00, /* Logical Minimum (0), */ | |
425 | 0x25, 0x01, /* Logical Maximum (1), */ | |
426 | 0x75, 0x01, /* Report Size (1), */ | |
427 | 0x95, 0x0E, /* Report Count (14), */ | |
428 | 0x81, 0x02, /* Input (Variable), */ | |
429 | 0x75, 0x06, /* Report Size (6), */ | |
430 | 0x95, 0x01, /* Report Count (1), */ | |
431 | 0x81, 0x01, /* Input (Constant), */ | |
432 | 0x05, 0x01, /* Usage Page (Desktop), */ | |
433 | 0x09, 0x33, /* Usage (Rx), */ | |
434 | 0x09, 0x34, /* Usage (Ry), */ | |
435 | 0x15, 0x00, /* Logical Minimum (0), */ | |
436 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | |
437 | 0x75, 0x08, /* Report Size (8), */ | |
438 | 0x95, 0x02, /* Report Count (2), */ | |
439 | 0x81, 0x02, /* Input (Variable), */ | |
440 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | |
441 | 0x09, 0x20, /* Usage (20h), */ | |
442 | 0x95, 0x03, /* Report Count (3), */ | |
443 | 0x81, 0x02, /* Input (Variable), */ | |
444 | 0x05, 0x01, /* Usage Page (Desktop), */ | |
445 | 0x19, 0x40, /* Usage Minimum (40h), */ | |
446 | 0x29, 0x42, /* Usage Maximum (42h), */ | |
447 | 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */ | |
448 | 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */ | |
449 | 0x75, 0x10, /* Report Size (16), */ | |
450 | 0x95, 0x03, /* Report Count (3), */ | |
451 | 0x81, 0x02, /* Input (Variable), */ | |
452 | 0x19, 0x43, /* Usage Minimum (43h), */ | |
453 | 0x29, 0x45, /* Usage Maximum (45h), */ | |
454 | 0x16, 0xFF, 0xBF, /* Logical Minimum (-16385), */ | |
455 | 0x26, 0x00, 0x40, /* Logical Maximum (16384), */ | |
456 | 0x95, 0x03, /* Report Count (3), */ | |
457 | 0x81, 0x02, /* Input (Variable), */ | |
458 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | |
459 | 0x09, 0x20, /* Usage (20h), */ | |
460 | 0x15, 0x00, /* Logical Minimum (0), */ | |
461 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | |
462 | 0x75, 0x08, /* Report Size (8), */ | |
463 | 0x95, 0x31, /* Report Count (51), */ | |
464 | 0x81, 0x02, /* Input (Variable), */ | |
465 | 0x09, 0x21, /* Usage (21h), */ | |
466 | 0x75, 0x08, /* Report Size (8), */ | |
467 | 0x95, 0x4D, /* Report Count (77), */ | |
468 | 0x91, 0x02, /* Output (Variable), */ | |
469 | 0x85, 0x12, /* Report ID (18), */ | |
470 | 0x09, 0x22, /* Usage (22h), */ | |
471 | 0x95, 0x8D, /* Report Count (141), */ | |
472 | 0x81, 0x02, /* Input (Variable), */ | |
473 | 0x09, 0x23, /* Usage (23h), */ | |
474 | 0x91, 0x02, /* Output (Variable), */ | |
475 | 0x85, 0x13, /* Report ID (19), */ | |
476 | 0x09, 0x24, /* Usage (24h), */ | |
477 | 0x95, 0xCD, /* Report Count (205), */ | |
478 | 0x81, 0x02, /* Input (Variable), */ | |
479 | 0x09, 0x25, /* Usage (25h), */ | |
480 | 0x91, 0x02, /* Output (Variable), */ | |
481 | 0x85, 0x14, /* Report ID (20), */ | |
482 | 0x09, 0x26, /* Usage (26h), */ | |
483 | 0x96, 0x0D, 0x01, /* Report Count (269), */ | |
484 | 0x81, 0x02, /* Input (Variable), */ | |
485 | 0x09, 0x27, /* Usage (27h), */ | |
486 | 0x91, 0x02, /* Output (Variable), */ | |
487 | 0x85, 0x15, /* Report ID (21), */ | |
488 | 0x09, 0x28, /* Usage (28h), */ | |
489 | 0x96, 0x4D, 0x01, /* Report Count (333), */ | |
490 | 0x81, 0x02, /* Input (Variable), */ | |
491 | 0x09, 0x29, /* Usage (29h), */ | |
492 | 0x91, 0x02, /* Output (Variable), */ | |
493 | 0x85, 0x16, /* Report ID (22), */ | |
494 | 0x09, 0x2A, /* Usage (2Ah), */ | |
495 | 0x96, 0x8D, 0x01, /* Report Count (397), */ | |
496 | 0x81, 0x02, /* Input (Variable), */ | |
497 | 0x09, 0x2B, /* Usage (2Bh), */ | |
498 | 0x91, 0x02, /* Output (Variable), */ | |
499 | 0x85, 0x17, /* Report ID (23), */ | |
500 | 0x09, 0x2C, /* Usage (2Ch), */ | |
501 | 0x96, 0xCD, 0x01, /* Report Count (461), */ | |
502 | 0x81, 0x02, /* Input (Variable), */ | |
503 | 0x09, 0x2D, /* Usage (2Dh), */ | |
504 | 0x91, 0x02, /* Output (Variable), */ | |
505 | 0x85, 0x18, /* Report ID (24), */ | |
506 | 0x09, 0x2E, /* Usage (2Eh), */ | |
507 | 0x96, 0x0D, 0x02, /* Report Count (525), */ | |
508 | 0x81, 0x02, /* Input (Variable), */ | |
509 | 0x09, 0x2F, /* Usage (2Fh), */ | |
510 | 0x91, 0x02, /* Output (Variable), */ | |
511 | 0x85, 0x19, /* Report ID (25), */ | |
512 | 0x09, 0x30, /* Usage (30h), */ | |
513 | 0x96, 0x22, 0x02, /* Report Count (546), */ | |
514 | 0x81, 0x02, /* Input (Variable), */ | |
515 | 0x09, 0x31, /* Usage (31h), */ | |
516 | 0x91, 0x02, /* Output (Variable), */ | |
517 | 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */ | |
518 | 0x85, 0x82, /* Report ID (130), */ | |
519 | 0x09, 0x22, /* Usage (22h), */ | |
520 | 0x95, 0x3F, /* Report Count (63), */ | |
521 | 0xB1, 0x02, /* Feature (Variable), */ | |
522 | 0x85, 0x83, /* Report ID (131), */ | |
523 | 0x09, 0x23, /* Usage (23h), */ | |
524 | 0xB1, 0x02, /* Feature (Variable), */ | |
525 | 0x85, 0x84, /* Report ID (132), */ | |
526 | 0x09, 0x24, /* Usage (24h), */ | |
527 | 0xB1, 0x02, /* Feature (Variable), */ | |
528 | 0x85, 0x90, /* Report ID (144), */ | |
529 | 0x09, 0x30, /* Usage (30h), */ | |
530 | 0xB1, 0x02, /* Feature (Variable), */ | |
531 | 0x85, 0x91, /* Report ID (145), */ | |
532 | 0x09, 0x31, /* Usage (31h), */ | |
533 | 0xB1, 0x02, /* Feature (Variable), */ | |
534 | 0x85, 0x92, /* Report ID (146), */ | |
535 | 0x09, 0x32, /* Usage (32h), */ | |
536 | 0xB1, 0x02, /* Feature (Variable), */ | |
537 | 0x85, 0x93, /* Report ID (147), */ | |
538 | 0x09, 0x33, /* Usage (33h), */ | |
539 | 0xB1, 0x02, /* Feature (Variable), */ | |
540 | 0x85, 0xA0, /* Report ID (160), */ | |
541 | 0x09, 0x40, /* Usage (40h), */ | |
542 | 0xB1, 0x02, /* Feature (Variable), */ | |
543 | 0x85, 0xA4, /* Report ID (164), */ | |
544 | 0x09, 0x44, /* Usage (44h), */ | |
545 | 0xB1, 0x02, /* Feature (Variable), */ | |
546 | 0xC0 /* End Collection */ | |
547 | }; | |
548 | ||
078328da JK |
549 | static __u8 ps3remote_rdesc[] = { |
550 | 0x05, 0x01, /* GUsagePage Generic Desktop */ | |
551 | 0x09, 0x05, /* LUsage 0x05 [Game Pad] */ | |
552 | 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */ | |
553 | ||
554 | /* Use collection 1 for joypad buttons */ | |
555 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ | |
556 | ||
557 | /* Ignore the 1st byte, maybe it is used for a controller | |
558 | * number but it's not needed for correct operation */ | |
559 | 0x75, 0x08, /* GReportSize 0x08 [8] */ | |
560 | 0x95, 0x01, /* GReportCount 0x01 [1] */ | |
561 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ | |
562 | ||
563 | /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these | |
564 | * buttons multiple keypresses are allowed */ | |
565 | 0x05, 0x09, /* GUsagePage Button */ | |
566 | 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */ | |
567 | 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */ | |
568 | 0x14, /* GLogicalMinimum [0] */ | |
569 | 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */ | |
570 | 0x75, 0x01, /* GReportSize 0x01 [1] */ | |
571 | 0x95, 0x18, /* GReportCount 0x18 [24] */ | |
572 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ | |
573 | ||
574 | 0xC0, /* MEndCollection */ | |
575 | ||
576 | /* Use collection 2 for remote control buttons */ | |
577 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ | |
578 | ||
579 | /* 5th byte is used for remote control buttons */ | |
580 | 0x05, 0x09, /* GUsagePage Button */ | |
581 | 0x18, /* LUsageMinimum [No button pressed] */ | |
582 | 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */ | |
583 | 0x14, /* GLogicalMinimum [0] */ | |
584 | 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */ | |
585 | 0x75, 0x08, /* GReportSize 0x08 [8] */ | |
586 | 0x95, 0x01, /* GReportCount 0x01 [1] */ | |
587 | 0x80, /* MInput */ | |
588 | ||
589 | /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at | |
590 | * 0xff and 11th is for press indication */ | |
591 | 0x75, 0x08, /* GReportSize 0x08 [8] */ | |
592 | 0x95, 0x06, /* GReportCount 0x06 [6] */ | |
593 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ | |
594 | ||
595 | /* 12th byte is for battery strength */ | |
596 | 0x05, 0x06, /* GUsagePage Generic Device Controls */ | |
597 | 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */ | |
598 | 0x14, /* GLogicalMinimum [0] */ | |
599 | 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */ | |
600 | 0x75, 0x08, /* GReportSize 0x08 [8] */ | |
601 | 0x95, 0x01, /* GReportCount 0x01 [1] */ | |
602 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ | |
603 | ||
604 | 0xC0, /* MEndCollection */ | |
605 | ||
606 | 0xC0 /* MEndCollection [Game Pad] */ | |
607 | }; | |
608 | ||
609 | static const unsigned int ps3remote_keymap_joypad_buttons[] = { | |
610 | [0x01] = KEY_SELECT, | |
611 | [0x02] = BTN_THUMBL, /* L3 */ | |
612 | [0x03] = BTN_THUMBR, /* R3 */ | |
613 | [0x04] = BTN_START, | |
614 | [0x05] = KEY_UP, | |
615 | [0x06] = KEY_RIGHT, | |
616 | [0x07] = KEY_DOWN, | |
617 | [0x08] = KEY_LEFT, | |
618 | [0x09] = BTN_TL2, /* L2 */ | |
619 | [0x0a] = BTN_TR2, /* R2 */ | |
620 | [0x0b] = BTN_TL, /* L1 */ | |
621 | [0x0c] = BTN_TR, /* R1 */ | |
622 | [0x0d] = KEY_OPTION, /* options/triangle */ | |
623 | [0x0e] = KEY_BACK, /* back/circle */ | |
624 | [0x0f] = BTN_0, /* cross */ | |
625 | [0x10] = KEY_SCREEN, /* view/square */ | |
626 | [0x11] = KEY_HOMEPAGE, /* PS button */ | |
627 | [0x14] = KEY_ENTER, | |
628 | }; | |
629 | static const unsigned int ps3remote_keymap_remote_buttons[] = { | |
630 | [0x00] = KEY_1, | |
631 | [0x01] = KEY_2, | |
632 | [0x02] = KEY_3, | |
633 | [0x03] = KEY_4, | |
634 | [0x04] = KEY_5, | |
635 | [0x05] = KEY_6, | |
636 | [0x06] = KEY_7, | |
637 | [0x07] = KEY_8, | |
638 | [0x08] = KEY_9, | |
639 | [0x09] = KEY_0, | |
640 | [0x0e] = KEY_ESC, /* return */ | |
641 | [0x0f] = KEY_CLEAR, | |
642 | [0x16] = KEY_EJECTCD, | |
643 | [0x1a] = KEY_MENU, /* top menu */ | |
644 | [0x28] = KEY_TIME, | |
645 | [0x30] = KEY_PREVIOUS, | |
646 | [0x31] = KEY_NEXT, | |
647 | [0x32] = KEY_PLAY, | |
648 | [0x33] = KEY_REWIND, /* scan back */ | |
649 | [0x34] = KEY_FORWARD, /* scan forward */ | |
650 | [0x38] = KEY_STOP, | |
651 | [0x39] = KEY_PAUSE, | |
652 | [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */ | |
653 | [0x60] = KEY_FRAMEBACK, /* slow/step back */ | |
654 | [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */ | |
655 | [0x63] = KEY_SUBTITLE, | |
656 | [0x64] = KEY_AUDIO, | |
657 | [0x65] = KEY_ANGLE, | |
658 | [0x70] = KEY_INFO, /* display */ | |
659 | [0x80] = KEY_BLUE, | |
660 | [0x81] = KEY_RED, | |
661 | [0x82] = KEY_GREEN, | |
662 | [0x83] = KEY_YELLOW, | |
663 | }; | |
664 | ||
f04d5140 CL |
665 | static const unsigned int buzz_keymap[] = { |
666 | /* The controller has 4 remote buzzers, each with one LED and 5 | |
667 | * buttons. | |
668 | * | |
669 | * We use the mapping chosen by the controller, which is: | |
670 | * | |
671 | * Key Offset | |
672 | * ------------------- | |
673 | * Buzz 1 | |
674 | * Blue 5 | |
675 | * Orange 4 | |
676 | * Green 3 | |
677 | * Yellow 2 | |
678 | * | |
679 | * So, for example, the orange button on the third buzzer is mapped to | |
680 | * BTN_TRIGGER_HAPPY14 | |
681 | */ | |
682 | [ 1] = BTN_TRIGGER_HAPPY1, | |
683 | [ 2] = BTN_TRIGGER_HAPPY2, | |
684 | [ 3] = BTN_TRIGGER_HAPPY3, | |
685 | [ 4] = BTN_TRIGGER_HAPPY4, | |
686 | [ 5] = BTN_TRIGGER_HAPPY5, | |
687 | [ 6] = BTN_TRIGGER_HAPPY6, | |
688 | [ 7] = BTN_TRIGGER_HAPPY7, | |
689 | [ 8] = BTN_TRIGGER_HAPPY8, | |
690 | [ 9] = BTN_TRIGGER_HAPPY9, | |
691 | [10] = BTN_TRIGGER_HAPPY10, | |
692 | [11] = BTN_TRIGGER_HAPPY11, | |
693 | [12] = BTN_TRIGGER_HAPPY12, | |
694 | [13] = BTN_TRIGGER_HAPPY13, | |
695 | [14] = BTN_TRIGGER_HAPPY14, | |
696 | [15] = BTN_TRIGGER_HAPPY15, | |
697 | [16] = BTN_TRIGGER_HAPPY16, | |
698 | [17] = BTN_TRIGGER_HAPPY17, | |
699 | [18] = BTN_TRIGGER_HAPPY18, | |
700 | [19] = BTN_TRIGGER_HAPPY19, | |
701 | [20] = BTN_TRIGGER_HAPPY20, | |
702 | }; | |
703 | ||
d902f472 FP |
704 | static enum power_supply_property sony_battery_props[] = { |
705 | POWER_SUPPLY_PROP_PRESENT, | |
706 | POWER_SUPPLY_PROP_CAPACITY, | |
707 | POWER_SUPPLY_PROP_SCOPE, | |
708 | POWER_SUPPLY_PROP_STATUS, | |
709 | }; | |
710 | ||
cc6e0bbb | 711 | struct sony_sc { |
d902f472 | 712 | spinlock_t lock; |
0a286ef2 | 713 | struct hid_device *hdev; |
60781cf4 | 714 | struct led_classdev *leds[MAX_LEDS]; |
cc6e0bbb | 715 | unsigned long quirks; |
0a286ef2 | 716 | struct work_struct state_worker; |
d902f472 | 717 | struct power_supply battery; |
f04d5140 | 718 | |
9f323b68 | 719 | #ifdef CONFIG_SONY_FF |
9f323b68 SE |
720 | __u8 left; |
721 | __u8 right; | |
722 | #endif | |
723 | ||
d902f472 FP |
724 | __u8 cable_state; |
725 | __u8 battery_charging; | |
726 | __u8 battery_capacity; | |
60781cf4 FP |
727 | __u8 led_state[MAX_LEDS]; |
728 | __u8 led_count; | |
cc6e0bbb JK |
729 | }; |
730 | ||
078328da JK |
731 | static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc, |
732 | unsigned int *rsize) | |
733 | { | |
734 | *rsize = sizeof(ps3remote_rdesc); | |
735 | return ps3remote_rdesc; | |
736 | } | |
737 | ||
738 | static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi, | |
739 | struct hid_field *field, struct hid_usage *usage, | |
740 | unsigned long **bit, int *max) | |
741 | { | |
742 | unsigned int key = usage->hid & HID_USAGE; | |
743 | ||
744 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) | |
745 | return -1; | |
746 | ||
747 | switch (usage->collection_index) { | |
748 | case 1: | |
749 | if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons)) | |
750 | return -1; | |
751 | ||
752 | key = ps3remote_keymap_joypad_buttons[key]; | |
753 | if (!key) | |
754 | return -1; | |
755 | break; | |
756 | case 2: | |
757 | if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons)) | |
758 | return -1; | |
759 | ||
760 | key = ps3remote_keymap_remote_buttons[key]; | |
761 | if (!key) | |
762 | return -1; | |
763 | break; | |
764 | default: | |
765 | return -1; | |
766 | } | |
767 | ||
768 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); | |
769 | return 1; | |
770 | } | |
771 | ||
772 | ||
cc6e0bbb | 773 | /* Sony Vaio VGX has wrongly mouse pointer declared as constant */ |
73e4008d NK |
774 | static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
775 | unsigned int *rsize) | |
cc6e0bbb JK |
776 | { |
777 | struct sony_sc *sc = hid_get_drvdata(hdev); | |
778 | ||
99d24902 FLVC |
779 | /* |
780 | * Some Sony RF receivers wrongly declare the mouse pointer as a | |
781 | * a constant non-data variable. | |
782 | */ | |
783 | if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 && | |
784 | /* usage page: generic desktop controls */ | |
785 | /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */ | |
786 | /* usage: mouse */ | |
787 | rdesc[2] == 0x09 && rdesc[3] == 0x02 && | |
788 | /* input (usage page for x,y axes): constant, variable, relative */ | |
789 | rdesc[54] == 0x81 && rdesc[55] == 0x07) { | |
a4649184 | 790 | hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n"); |
99d24902 | 791 | /* input: data, variable, relative */ |
cc6e0bbb JK |
792 | rdesc[55] = 0x06; |
793 | } | |
61ab44be | 794 | |
ed19d8cf FP |
795 | /* |
796 | * The default Dualshock 4 USB descriptor doesn't assign | |
797 | * the gyroscope values to corresponding axes so we need a | |
798 | * modified one. | |
799 | */ | |
800 | if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && *rsize == 467) { | |
801 | hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n"); | |
802 | rdesc = dualshock4_usb_rdesc; | |
803 | *rsize = sizeof(dualshock4_usb_rdesc); | |
d829674d FP |
804 | } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && *rsize == 357) { |
805 | hid_info(hdev, "Using modified Dualshock 4 Bluetooth report descriptor\n"); | |
806 | rdesc = dualshock4_bt_rdesc; | |
807 | *rsize = sizeof(dualshock4_bt_rdesc); | |
ed19d8cf FP |
808 | } |
809 | ||
61ab44be SW |
810 | /* The HID descriptor exposed over BT has a trailing zero byte */ |
811 | if ((((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize == 148) || | |
812 | ((sc->quirks & SIXAXIS_CONTROLLER_BT) && *rsize == 149)) && | |
813 | rdesc[83] == 0x75) { | |
814 | hid_info(hdev, "Fixing up Sony Sixaxis report descriptor\n"); | |
815 | memcpy((void *)&rdesc[83], (void *)&sixaxis_rdesc_fixup, | |
816 | sizeof(sixaxis_rdesc_fixup)); | |
e57a67da MCC |
817 | } else if (sc->quirks & SIXAXIS_CONTROLLER_USB && |
818 | *rsize > sizeof(sixaxis_rdesc_fixup2)) { | |
819 | hid_info(hdev, "Sony Sixaxis clone detected. Using original report descriptor (size: %d clone; %d new)\n", | |
820 | *rsize, (int)sizeof(sixaxis_rdesc_fixup2)); | |
821 | *rsize = sizeof(sixaxis_rdesc_fixup2); | |
822 | memcpy(rdesc, &sixaxis_rdesc_fixup2, *rsize); | |
61ab44be | 823 | } |
078328da JK |
824 | |
825 | if (sc->quirks & PS3REMOTE) | |
826 | return ps3remote_fixup(hdev, rdesc, rsize); | |
827 | ||
73e4008d | 828 | return rdesc; |
cc6e0bbb JK |
829 | } |
830 | ||
d902f472 FP |
831 | static void sixaxis_parse_report(struct sony_sc *sc, __u8 *rd, int size) |
832 | { | |
833 | static const __u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 }; | |
834 | unsigned long flags; | |
835 | __u8 cable_state, battery_capacity, battery_charging; | |
836 | ||
837 | /* The sixaxis is charging if the battery value is 0xee | |
838 | * and it is fully charged if the value is 0xef. | |
839 | * It does not report the actual level while charging so it | |
840 | * is set to 100% while charging is in progress. | |
841 | */ | |
842 | if (rd[30] >= 0xee) { | |
843 | battery_capacity = 100; | |
844 | battery_charging = rd[30] & 0x01; | |
845 | } else { | |
846 | battery_capacity = sixaxis_battery_capacity[rd[30]]; | |
847 | battery_charging = 0; | |
848 | } | |
849 | cable_state = (rd[31] >> 4) & 0x01; | |
850 | ||
851 | spin_lock_irqsave(&sc->lock, flags); | |
852 | sc->cable_state = cable_state; | |
853 | sc->battery_capacity = battery_capacity; | |
854 | sc->battery_charging = battery_charging; | |
855 | spin_unlock_irqrestore(&sc->lock, flags); | |
856 | } | |
857 | ||
858 | static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size) | |
859 | { | |
e5606230 FP |
860 | struct hid_input *hidinput = list_entry(sc->hdev->inputs.next, |
861 | struct hid_input, list); | |
862 | struct input_dev *input_dev = hidinput->input; | |
d902f472 | 863 | unsigned long flags; |
e5606230 | 864 | int n, offset = 35; |
d902f472 FP |
865 | __u8 cable_state, battery_capacity, battery_charging; |
866 | ||
867 | /* The lower 4 bits of byte 30 contain the battery level | |
868 | * and the 5th bit contains the USB cable state. | |
869 | */ | |
870 | cable_state = (rd[30] >> 4) & 0x01; | |
871 | battery_capacity = rd[30] & 0x0F; | |
872 | ||
873 | /* On USB the Dualshock 4 battery level goes from 0 to 11. | |
874 | * A battery level of 11 means fully charged. | |
875 | */ | |
876 | if (cable_state && battery_capacity == 11) | |
877 | battery_charging = 0; | |
878 | else | |
879 | battery_charging = 1; | |
880 | ||
881 | if (battery_capacity > 10) | |
882 | battery_capacity--; | |
883 | battery_capacity *= 10; | |
884 | ||
885 | spin_lock_irqsave(&sc->lock, flags); | |
886 | sc->cable_state = cable_state; | |
887 | sc->battery_capacity = battery_capacity; | |
888 | sc->battery_charging = battery_charging; | |
889 | spin_unlock_irqrestore(&sc->lock, flags); | |
e5606230 FP |
890 | |
891 | /* The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB. | |
892 | * The first 7 bits of the first byte is a counter and bit 8 is a touch | |
893 | * indicator that is 0 when pressed and 1 when not pressed. | |
894 | * The next 3 bytes are two 12 bit touch coordinates, X and Y. | |
895 | * The data for the second touch is in the same format and immediatly | |
896 | * follows the data for the first. | |
897 | */ | |
898 | for (n = 0; n < 2; n++) { | |
899 | __u16 x, y; | |
900 | ||
901 | x = rd[offset+1] | ((rd[offset+2] & 0xF) << 8); | |
902 | y = ((rd[offset+2] & 0xF0) >> 4) | (rd[offset+3] << 4); | |
903 | ||
904 | input_mt_slot(input_dev, n); | |
905 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, | |
906 | !(rd[offset] >> 7)); | |
907 | input_report_abs(input_dev, ABS_MT_POSITION_X, x); | |
908 | input_report_abs(input_dev, ABS_MT_POSITION_Y, y); | |
909 | ||
910 | offset += 4; | |
911 | } | |
d902f472 FP |
912 | } |
913 | ||
c9e4d877 SW |
914 | static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, |
915 | __u8 *rd, int size) | |
916 | { | |
917 | struct sony_sc *sc = hid_get_drvdata(hdev); | |
918 | ||
919 | /* Sixaxis HID report has acclerometers/gyro with MSByte first, this | |
920 | * has to be BYTE_SWAPPED before passing up to joystick interface | |
921 | */ | |
922 | if ((sc->quirks & (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)) && | |
923 | rd[0] == 0x01 && size == 49) { | |
924 | swap(rd[41], rd[42]); | |
925 | swap(rd[43], rd[44]); | |
926 | swap(rd[45], rd[46]); | |
927 | swap(rd[47], rd[48]); | |
d902f472 FP |
928 | |
929 | sixaxis_parse_report(sc, rd, size); | |
930 | } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 && | |
931 | size == 64) { | |
932 | dualshock4_parse_report(sc, rd, size); | |
c9e4d877 SW |
933 | } |
934 | ||
935 | return 0; | |
936 | } | |
937 | ||
f04d5140 CL |
938 | static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, |
939 | struct hid_field *field, struct hid_usage *usage, | |
940 | unsigned long **bit, int *max) | |
941 | { | |
942 | struct sony_sc *sc = hid_get_drvdata(hdev); | |
943 | ||
944 | if (sc->quirks & BUZZ_CONTROLLER) { | |
945 | unsigned int key = usage->hid & HID_USAGE; | |
946 | ||
947 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) | |
948 | return -1; | |
949 | ||
950 | switch (usage->collection_index) { | |
951 | case 1: | |
952 | if (key >= ARRAY_SIZE(buzz_keymap)) | |
953 | return -1; | |
954 | ||
955 | key = buzz_keymap[key]; | |
956 | if (!key) | |
957 | return -1; | |
958 | break; | |
959 | default: | |
960 | return -1; | |
961 | } | |
962 | ||
963 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); | |
964 | return 1; | |
965 | } | |
966 | ||
078328da JK |
967 | if (sc->quirks & PS3REMOTE) |
968 | return ps3remote_mapping(hdev, hi, field, usage, bit, max); | |
969 | ||
6f498018 BT |
970 | /* Let hid-core decide for the others */ |
971 | return 0; | |
f04d5140 CL |
972 | } |
973 | ||
5710fabf AO |
974 | /* |
975 | * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP | |
976 | * like it should according to usbhid/hid-core.c::usbhid_output_raw_report() | |
977 | * so we need to override that forcing HID Output Reports on the Control EP. | |
978 | * | |
979 | * There is also another issue about HID Output Reports via USB, the Sixaxis | |
980 | * does not want the report_id as part of the data packet, so we have to | |
981 | * discard buf[0] when sending the actual control message, even for numbered | |
982 | * reports, humpf! | |
983 | */ | |
569b10a5 AO |
984 | static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf, |
985 | size_t count, unsigned char report_type) | |
986 | { | |
987 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); | |
988 | struct usb_device *dev = interface_to_usbdev(intf); | |
989 | struct usb_host_interface *interface = intf->cur_altsetting; | |
990 | int report_id = buf[0]; | |
991 | int ret; | |
992 | ||
5710fabf AO |
993 | if (report_type == HID_OUTPUT_REPORT) { |
994 | /* Don't send the Report ID */ | |
995 | buf++; | |
996 | count--; | |
997 | } | |
998 | ||
569b10a5 AO |
999 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
1000 | HID_REQ_SET_REPORT, | |
1001 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | |
1002 | ((report_type + 1) << 8) | report_id, | |
1003 | interface->desc.bInterfaceNumber, buf, count, | |
1004 | USB_CTRL_SET_TIMEOUT); | |
1005 | ||
5710fabf AO |
1006 | /* Count also the Report ID, in case of an Output report. */ |
1007 | if (ret > 0 && report_type == HID_OUTPUT_REPORT) | |
1008 | ret++; | |
1009 | ||
569b10a5 AO |
1010 | return ret; |
1011 | } | |
1012 | ||
bd28ce00 JS |
1013 | /* |
1014 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller | |
1015 | * to "operational". Without this, the ps3 controller will not report any | |
1016 | * events. | |
1017 | */ | |
816651a7 | 1018 | static int sixaxis_set_operational_usb(struct hid_device *hdev) |
bd28ce00 | 1019 | { |
bd28ce00 JS |
1020 | int ret; |
1021 | char *buf = kmalloc(18, GFP_KERNEL); | |
1022 | ||
1023 | if (!buf) | |
1024 | return -ENOMEM; | |
1025 | ||
cafebc05 BT |
1026 | ret = hid_hw_raw_request(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT, |
1027 | HID_REQ_GET_REPORT); | |
f204828a | 1028 | |
bd28ce00 | 1029 | if (ret < 0) |
4291ee30 | 1030 | hid_err(hdev, "can't set operational mode\n"); |
bd28ce00 JS |
1031 | |
1032 | kfree(buf); | |
1033 | ||
1034 | return ret; | |
1035 | } | |
1036 | ||
816651a7 | 1037 | static int sixaxis_set_operational_bt(struct hid_device *hdev) |
f9ce7c28 | 1038 | { |
fddb33f2 | 1039 | unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; |
7e845d46 BT |
1040 | return hid_output_raw_report(hdev, buf, sizeof(buf), |
1041 | HID_FEATURE_REPORT); | |
f9ce7c28 BN |
1042 | } |
1043 | ||
60781cf4 | 1044 | static void buzz_set_leds(struct hid_device *hdev, const __u8 *leds) |
f04d5140 CL |
1045 | { |
1046 | struct list_head *report_list = | |
1047 | &hdev->report_enum[HID_OUTPUT_REPORT].report_list; | |
1048 | struct hid_report *report = list_entry(report_list->next, | |
1049 | struct hid_report, list); | |
1050 | __s32 *value = report->field[0]->value; | |
1051 | ||
1052 | value[0] = 0x00; | |
60781cf4 FP |
1053 | value[1] = leds[0] ? 0xff : 0x00; |
1054 | value[2] = leds[1] ? 0xff : 0x00; | |
1055 | value[3] = leds[2] ? 0xff : 0x00; | |
1056 | value[4] = leds[3] ? 0xff : 0x00; | |
f04d5140 CL |
1057 | value[5] = 0x00; |
1058 | value[6] = 0x00; | |
1059 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); | |
1060 | } | |
1061 | ||
60781cf4 | 1062 | static void sony_set_leds(struct hid_device *hdev, const __u8 *leds, int count) |
0a286ef2 SE |
1063 | { |
1064 | struct sony_sc *drv_data = hid_get_drvdata(hdev); | |
60781cf4 | 1065 | int n; |
0a286ef2 | 1066 | |
60781cf4 FP |
1067 | BUG_ON(count > MAX_LEDS); |
1068 | ||
1069 | if (drv_data->quirks & BUZZ_CONTROLLER && count == 4) { | |
0a286ef2 | 1070 | buzz_set_leds(hdev, leds); |
60781cf4 | 1071 | } else if ((drv_data->quirks & SIXAXIS_CONTROLLER_USB) || |
8ab1676b | 1072 | (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB)) { |
60781cf4 FP |
1073 | for (n = 0; n < count; n++) |
1074 | drv_data->led_state[n] = leds[n]; | |
0a286ef2 SE |
1075 | schedule_work(&drv_data->state_worker); |
1076 | } | |
1077 | } | |
1078 | ||
c5382519 | 1079 | static void sony_led_set_brightness(struct led_classdev *led, |
f04d5140 CL |
1080 | enum led_brightness value) |
1081 | { | |
1082 | struct device *dev = led->dev->parent; | |
1083 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | |
1084 | struct sony_sc *drv_data; | |
f04d5140 CL |
1085 | |
1086 | int n; | |
1087 | ||
1088 | drv_data = hid_get_drvdata(hdev); | |
2251b85f | 1089 | if (!drv_data) { |
f04d5140 CL |
1090 | hid_err(hdev, "No device data\n"); |
1091 | return; | |
1092 | } | |
f04d5140 | 1093 | |
60781cf4 | 1094 | for (n = 0; n < drv_data->led_count; n++) { |
2251b85f | 1095 | if (led == drv_data->leds[n]) { |
60781cf4 FP |
1096 | if (value != drv_data->led_state[n]) { |
1097 | drv_data->led_state[n] = value; | |
1098 | sony_set_leds(hdev, drv_data->led_state, drv_data->led_count); | |
f04d5140 CL |
1099 | } |
1100 | break; | |
1101 | } | |
1102 | } | |
1103 | } | |
1104 | ||
c5382519 | 1105 | static enum led_brightness sony_led_get_brightness(struct led_classdev *led) |
f04d5140 CL |
1106 | { |
1107 | struct device *dev = led->dev->parent; | |
1108 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); | |
1109 | struct sony_sc *drv_data; | |
f04d5140 CL |
1110 | |
1111 | int n; | |
f04d5140 CL |
1112 | |
1113 | drv_data = hid_get_drvdata(hdev); | |
2251b85f | 1114 | if (!drv_data) { |
f04d5140 CL |
1115 | hid_err(hdev, "No device data\n"); |
1116 | return LED_OFF; | |
1117 | } | |
f04d5140 | 1118 | |
60781cf4 | 1119 | for (n = 0; n < drv_data->led_count; n++) { |
7db7504a SW |
1120 | if (led == drv_data->leds[n]) |
1121 | return drv_data->led_state[n]; | |
f04d5140 CL |
1122 | } |
1123 | ||
7db7504a | 1124 | return LED_OFF; |
f04d5140 | 1125 | } |
f04d5140 | 1126 | |
0a286ef2 SE |
1127 | static void sony_leds_remove(struct hid_device *hdev) |
1128 | { | |
1129 | struct sony_sc *drv_data; | |
1130 | struct led_classdev *led; | |
1131 | int n; | |
1132 | ||
1133 | drv_data = hid_get_drvdata(hdev); | |
1134 | BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT)); | |
1135 | ||
60781cf4 | 1136 | for (n = 0; n < drv_data->led_count; n++) { |
0a286ef2 SE |
1137 | led = drv_data->leds[n]; |
1138 | drv_data->leds[n] = NULL; | |
1139 | if (!led) | |
1140 | continue; | |
1141 | led_classdev_unregister(led); | |
1142 | kfree(led); | |
1143 | } | |
60781cf4 FP |
1144 | |
1145 | drv_data->led_count = 0; | |
0a286ef2 SE |
1146 | } |
1147 | ||
c5382519 | 1148 | static int sony_leds_init(struct hid_device *hdev) |
f04d5140 CL |
1149 | { |
1150 | struct sony_sc *drv_data; | |
40e32ee6 | 1151 | int n, ret = 0; |
60781cf4 | 1152 | int max_brightness; |
61ebca93 | 1153 | int use_colors; |
40e32ee6 JK |
1154 | struct led_classdev *led; |
1155 | size_t name_sz; | |
1156 | char *name; | |
0a286ef2 SE |
1157 | size_t name_len; |
1158 | const char *name_fmt; | |
61ebca93 | 1159 | static const char * const color_str[] = { "red", "green", "blue" }; |
60781cf4 | 1160 | static const __u8 initial_values[MAX_LEDS] = { 0x00, 0x00, 0x00, 0x00 }; |
f04d5140 CL |
1161 | |
1162 | drv_data = hid_get_drvdata(hdev); | |
0a286ef2 SE |
1163 | BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT)); |
1164 | ||
1165 | if (drv_data->quirks & BUZZ_CONTROLLER) { | |
61ebca93 FP |
1166 | drv_data->led_count = 4; |
1167 | max_brightness = 1; | |
1168 | use_colors = 0; | |
0a286ef2 SE |
1169 | name_len = strlen("::buzz#"); |
1170 | name_fmt = "%s::buzz%d"; | |
1171 | /* Validate expected report characteristics. */ | |
1172 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) | |
1173 | return -ENODEV; | |
61ebca93 | 1174 | } else if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) { |
60781cf4 FP |
1175 | drv_data->led_count = 3; |
1176 | max_brightness = 255; | |
61ebca93 FP |
1177 | use_colors = 1; |
1178 | name_len = 0; | |
1179 | name_fmt = "%s:%s"; | |
60781cf4 FP |
1180 | } else { |
1181 | drv_data->led_count = 4; | |
1182 | max_brightness = 1; | |
61ebca93 FP |
1183 | use_colors = 0; |
1184 | name_len = strlen("::sony#"); | |
1185 | name_fmt = "%s::sony%d"; | |
60781cf4 FP |
1186 | } |
1187 | ||
f04d5140 CL |
1188 | /* Clear LEDs as we have no way of reading their initial state. This is |
1189 | * only relevant if the driver is loaded after somebody actively set the | |
1190 | * LEDs to on */ | |
60781cf4 | 1191 | sony_set_leds(hdev, initial_values, drv_data->led_count); |
f04d5140 | 1192 | |
0a286ef2 | 1193 | name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; |
f04d5140 | 1194 | |
60781cf4 | 1195 | for (n = 0; n < drv_data->led_count; n++) { |
61ebca93 FP |
1196 | |
1197 | if (use_colors) | |
1198 | name_sz = strlen(dev_name(&hdev->dev)) + strlen(color_str[n]) + 2; | |
1199 | ||
40e32ee6 JK |
1200 | led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); |
1201 | if (!led) { | |
1202 | hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); | |
8cd5fcda | 1203 | ret = -ENOMEM; |
40e32ee6 JK |
1204 | goto error_leds; |
1205 | } | |
f04d5140 | 1206 | |
40e32ee6 | 1207 | name = (void *)(&led[1]); |
61ebca93 FP |
1208 | if (use_colors) |
1209 | snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), color_str[n]); | |
1210 | else | |
1211 | snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); | |
40e32ee6 JK |
1212 | led->name = name; |
1213 | led->brightness = 0; | |
60781cf4 | 1214 | led->max_brightness = max_brightness; |
c5382519 SE |
1215 | led->brightness_get = sony_led_get_brightness; |
1216 | led->brightness_set = sony_led_set_brightness; | |
f04d5140 | 1217 | |
8cd5fcda JL |
1218 | ret = led_classdev_register(&hdev->dev, led); |
1219 | if (ret) { | |
40e32ee6 JK |
1220 | hid_err(hdev, "Failed to register LED %d\n", n); |
1221 | kfree(led); | |
1222 | goto error_leds; | |
f04d5140 | 1223 | } |
40e32ee6 | 1224 | |
2251b85f | 1225 | drv_data->leds[n] = led; |
f04d5140 | 1226 | } |
f04d5140 CL |
1227 | |
1228 | return ret; | |
1229 | ||
f04d5140 | 1230 | error_leds: |
0a286ef2 | 1231 | sony_leds_remove(hdev); |
f04d5140 | 1232 | |
f04d5140 | 1233 | return ret; |
f04d5140 CL |
1234 | } |
1235 | ||
cad665a2 | 1236 | static void sixaxis_state_worker(struct work_struct *work) |
a08c22c0 | 1237 | { |
92b5c411 | 1238 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); |
a08c22c0 SE |
1239 | unsigned char buf[] = { |
1240 | 0x01, | |
1241 | 0x00, 0xff, 0x00, 0xff, 0x00, | |
0a286ef2 | 1242 | 0x00, 0x00, 0x00, 0x00, 0x00, |
a08c22c0 SE |
1243 | 0xff, 0x27, 0x10, 0x00, 0x32, |
1244 | 0xff, 0x27, 0x10, 0x00, 0x32, | |
1245 | 0xff, 0x27, 0x10, 0x00, 0x32, | |
1246 | 0xff, 0x27, 0x10, 0x00, 0x32, | |
1247 | 0x00, 0x00, 0x00, 0x00, 0x00 | |
1248 | }; | |
9f323b68 | 1249 | |
0a286ef2 | 1250 | #ifdef CONFIG_SONY_FF |
0bd88dd3 | 1251 | buf[3] = sc->right ? 1 : 0; |
9f323b68 | 1252 | buf[5] = sc->left; |
0a286ef2 SE |
1253 | #endif |
1254 | ||
60781cf4 FP |
1255 | buf[10] |= sc->led_state[0] << 1; |
1256 | buf[10] |= sc->led_state[1] << 2; | |
1257 | buf[10] |= sc->led_state[2] << 3; | |
1258 | buf[10] |= sc->led_state[3] << 4; | |
9f323b68 | 1259 | |
7e845d46 | 1260 | hid_output_raw_report(sc->hdev, buf, sizeof(buf), HID_OUTPUT_REPORT); |
9f323b68 SE |
1261 | } |
1262 | ||
0bd88dd3 FP |
1263 | static void dualshock4_state_worker(struct work_struct *work) |
1264 | { | |
1265 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); | |
0da8ea65 | 1266 | struct hid_device *hdev = sc->hdev; |
48220237 FP |
1267 | int offset; |
1268 | ||
1269 | __u8 buf[32] = { 0 }; | |
0da8ea65 | 1270 | |
48220237 FP |
1271 | buf[0] = 0x05; |
1272 | buf[1] = 0x03; | |
1273 | offset = 4; | |
0bd88dd3 FP |
1274 | |
1275 | #ifdef CONFIG_SONY_FF | |
48220237 FP |
1276 | buf[offset++] = sc->right; |
1277 | buf[offset++] = sc->left; | |
1278 | #else | |
1279 | offset += 2; | |
0bd88dd3 FP |
1280 | #endif |
1281 | ||
48220237 FP |
1282 | buf[offset++] = sc->led_state[0]; |
1283 | buf[offset++] = sc->led_state[1]; | |
1284 | buf[offset++] = sc->led_state[2]; | |
60781cf4 | 1285 | |
48220237 | 1286 | hid_hw_output_report(hdev, buf, sizeof(buf)); |
0bd88dd3 FP |
1287 | } |
1288 | ||
0a286ef2 | 1289 | #ifdef CONFIG_SONY_FF |
9f323b68 SE |
1290 | static int sony_play_effect(struct input_dev *dev, void *data, |
1291 | struct ff_effect *effect) | |
1292 | { | |
a08c22c0 | 1293 | struct hid_device *hid = input_get_drvdata(dev); |
9f323b68 | 1294 | struct sony_sc *sc = hid_get_drvdata(hid); |
a08c22c0 SE |
1295 | |
1296 | if (effect->type != FF_RUMBLE) | |
1297 | return 0; | |
1298 | ||
9f323b68 | 1299 | sc->left = effect->u.rumble.strong_magnitude / 256; |
0bd88dd3 | 1300 | sc->right = effect->u.rumble.weak_magnitude / 256; |
a08c22c0 | 1301 | |
92b5c411 | 1302 | schedule_work(&sc->state_worker); |
9f323b68 | 1303 | return 0; |
a08c22c0 SE |
1304 | } |
1305 | ||
1306 | static int sony_init_ff(struct hid_device *hdev) | |
1307 | { | |
1308 | struct hid_input *hidinput = list_entry(hdev->inputs.next, | |
1309 | struct hid_input, list); | |
1310 | struct input_dev *input_dev = hidinput->input; | |
1311 | ||
1312 | input_set_capability(input_dev, EV_FF, FF_RUMBLE); | |
1313 | return input_ff_create_memless(input_dev, NULL, sony_play_effect); | |
1314 | } | |
1315 | ||
9f323b68 SE |
1316 | static void sony_destroy_ff(struct hid_device *hdev) |
1317 | { | |
1318 | struct sony_sc *sc = hid_get_drvdata(hdev); | |
1319 | ||
92b5c411 | 1320 | cancel_work_sync(&sc->state_worker); |
9f323b68 SE |
1321 | } |
1322 | ||
a08c22c0 SE |
1323 | #else |
1324 | static int sony_init_ff(struct hid_device *hdev) | |
1325 | { | |
1326 | return 0; | |
1327 | } | |
9f323b68 SE |
1328 | |
1329 | static void sony_destroy_ff(struct hid_device *hdev) | |
1330 | { | |
1331 | } | |
a08c22c0 SE |
1332 | #endif |
1333 | ||
d902f472 FP |
1334 | static int sony_battery_get_property(struct power_supply *psy, |
1335 | enum power_supply_property psp, | |
1336 | union power_supply_propval *val) | |
1337 | { | |
1338 | struct sony_sc *sc = container_of(psy, struct sony_sc, battery); | |
1339 | unsigned long flags; | |
1340 | int ret = 0; | |
1341 | u8 battery_charging, battery_capacity, cable_state; | |
1342 | ||
1343 | spin_lock_irqsave(&sc->lock, flags); | |
1344 | battery_charging = sc->battery_charging; | |
1345 | battery_capacity = sc->battery_capacity; | |
1346 | cable_state = sc->cable_state; | |
1347 | spin_unlock_irqrestore(&sc->lock, flags); | |
1348 | ||
1349 | switch (psp) { | |
1350 | case POWER_SUPPLY_PROP_PRESENT: | |
1351 | val->intval = 1; | |
1352 | break; | |
1353 | case POWER_SUPPLY_PROP_SCOPE: | |
1354 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; | |
1355 | break; | |
1356 | case POWER_SUPPLY_PROP_CAPACITY: | |
1357 | val->intval = battery_capacity; | |
1358 | break; | |
1359 | case POWER_SUPPLY_PROP_STATUS: | |
1360 | if (battery_charging) | |
1361 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | |
1362 | else | |
1363 | if (battery_capacity == 100 && cable_state) | |
1364 | val->intval = POWER_SUPPLY_STATUS_FULL; | |
1365 | else | |
1366 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; | |
1367 | break; | |
1368 | default: | |
1369 | ret = -EINVAL; | |
1370 | break; | |
1371 | } | |
1372 | return ret; | |
1373 | } | |
1374 | ||
1375 | static int sony_battery_probe(struct sony_sc *sc) | |
1376 | { | |
1377 | static atomic_t power_id_seq = ATOMIC_INIT(0); | |
1378 | unsigned long power_id; | |
1379 | struct hid_device *hdev = sc->hdev; | |
1380 | int ret; | |
1381 | ||
1382 | power_id = (unsigned long)atomic_inc_return(&power_id_seq); | |
1383 | ||
1384 | sc->battery.properties = sony_battery_props; | |
1385 | sc->battery.num_properties = ARRAY_SIZE(sony_battery_props); | |
1386 | sc->battery.get_property = sony_battery_get_property; | |
1387 | sc->battery.type = POWER_SUPPLY_TYPE_BATTERY; | |
1388 | sc->battery.use_for_apm = 0; | |
1389 | sc->battery.name = kasprintf(GFP_KERNEL, "sony_controller_battery_%lu", | |
1390 | power_id); | |
1391 | if (!sc->battery.name) | |
1392 | return -ENOMEM; | |
1393 | ||
1394 | ret = power_supply_register(&hdev->dev, &sc->battery); | |
1395 | if (ret) { | |
1396 | hid_err(hdev, "Unable to register battery device\n"); | |
1397 | goto err_free; | |
1398 | } | |
1399 | ||
1400 | power_supply_powers(&sc->battery, &hdev->dev); | |
1401 | return 0; | |
1402 | ||
1403 | err_free: | |
1404 | kfree(sc->battery.name); | |
1405 | sc->battery.name = NULL; | |
1406 | return ret; | |
1407 | } | |
1408 | ||
1409 | static void sony_battery_remove(struct sony_sc *sc) | |
1410 | { | |
1411 | if (!sc->battery.name) | |
1412 | return; | |
1413 | ||
1414 | power_supply_unregister(&sc->battery); | |
1415 | kfree(sc->battery.name); | |
1416 | sc->battery.name = NULL; | |
1417 | } | |
1418 | ||
e5606230 FP |
1419 | static int sony_register_touchpad(struct sony_sc *sc, int touch_count, |
1420 | int w, int h) | |
1421 | { | |
1422 | struct hid_input *hidinput = list_entry(sc->hdev->inputs.next, | |
1423 | struct hid_input, list); | |
1424 | struct input_dev *input_dev = hidinput->input; | |
1425 | int ret; | |
1426 | ||
1427 | ret = input_mt_init_slots(input_dev, touch_count, 0); | |
1428 | if (ret < 0) { | |
1429 | hid_err(sc->hdev, "Unable to initialize multi-touch slots\n"); | |
1430 | return ret; | |
1431 | } | |
1432 | ||
1433 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, w, 0, 0); | |
1434 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, h, 0, 0); | |
1435 | ||
1436 | return 0; | |
1437 | } | |
1438 | ||
bd28ce00 JS |
1439 | static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) |
1440 | { | |
1441 | int ret; | |
cc6e0bbb JK |
1442 | unsigned long quirks = id->driver_data; |
1443 | struct sony_sc *sc; | |
f04d5140 | 1444 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
cc6e0bbb | 1445 | |
abf832bf | 1446 | sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); |
cc6e0bbb | 1447 | if (sc == NULL) { |
4291ee30 | 1448 | hid_err(hdev, "can't alloc sony descriptor\n"); |
cc6e0bbb JK |
1449 | return -ENOMEM; |
1450 | } | |
1451 | ||
1452 | sc->quirks = quirks; | |
1453 | hid_set_drvdata(hdev, sc); | |
0a286ef2 | 1454 | sc->hdev = hdev; |
bd28ce00 | 1455 | |
bd28ce00 JS |
1456 | ret = hid_parse(hdev); |
1457 | if (ret) { | |
4291ee30 | 1458 | hid_err(hdev, "parse failed\n"); |
abf832bf | 1459 | return ret; |
bd28ce00 JS |
1460 | } |
1461 | ||
f04d5140 CL |
1462 | if (sc->quirks & VAIO_RDESC_CONSTANT) |
1463 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; | |
1464 | else if (sc->quirks & SIXAXIS_CONTROLLER_USB) | |
1465 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; | |
1466 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) | |
1467 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; | |
1468 | ||
1469 | ret = hid_hw_start(hdev, connect_mask); | |
bd28ce00 | 1470 | if (ret) { |
4291ee30 | 1471 | hid_err(hdev, "hw start failed\n"); |
abf832bf | 1472 | return ret; |
bd28ce00 JS |
1473 | } |
1474 | ||
569b10a5 AO |
1475 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) { |
1476 | hdev->hid_output_raw_report = sixaxis_usb_output_raw_report; | |
816651a7 | 1477 | ret = sixaxis_set_operational_usb(hdev); |
cad665a2 | 1478 | INIT_WORK(&sc->state_worker, sixaxis_state_worker); |
569b10a5 | 1479 | } |
816651a7 AO |
1480 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) |
1481 | ret = sixaxis_set_operational_bt(hdev); | |
8ab1676b | 1482 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { |
e5606230 FP |
1483 | /* The Dualshock 4 touchpad supports 2 touches and has a |
1484 | * resolution of 1920x940. | |
1485 | */ | |
1486 | ret = sony_register_touchpad(sc, 2, 1920, 940); | |
1487 | if (ret < 0) | |
1488 | goto err_stop; | |
1489 | ||
0bd88dd3 FP |
1490 | INIT_WORK(&sc->state_worker, dualshock4_state_worker); |
1491 | } else { | |
1492 | ret = 0; | |
1493 | } | |
f9ce7c28 | 1494 | |
4dfdc464 | 1495 | if (ret < 0) |
bd28ce00 JS |
1496 | goto err_stop; |
1497 | ||
0a286ef2 SE |
1498 | if (sc->quirks & SONY_LED_SUPPORT) { |
1499 | ret = sony_leds_init(hdev); | |
1500 | if (ret < 0) | |
1501 | goto err_stop; | |
1502 | } | |
1503 | ||
d902f472 FP |
1504 | if (sc->quirks & SONY_BATTERY_SUPPORT) { |
1505 | ret = sony_battery_probe(sc); | |
1506 | if (ret < 0) | |
1507 | goto err_stop; | |
1508 | ||
1509 | /* Open the device to receive reports with battery info */ | |
1510 | ret = hid_hw_open(hdev); | |
1511 | if (ret < 0) { | |
1512 | hid_err(hdev, "hw open failed\n"); | |
1513 | goto err_stop; | |
1514 | } | |
1515 | } | |
1516 | ||
a08c22c0 SE |
1517 | ret = sony_init_ff(hdev); |
1518 | if (ret < 0) | |
d902f472 | 1519 | goto err_close; |
a08c22c0 | 1520 | |
bd28ce00 | 1521 | return 0; |
d902f472 FP |
1522 | err_close: |
1523 | hid_hw_close(hdev); | |
bd28ce00 | 1524 | err_stop: |
0a286ef2 SE |
1525 | if (sc->quirks & SONY_LED_SUPPORT) |
1526 | sony_leds_remove(hdev); | |
d902f472 FP |
1527 | if (sc->quirks & SONY_BATTERY_SUPPORT) |
1528 | sony_battery_remove(sc); | |
bd28ce00 | 1529 | hid_hw_stop(hdev); |
bd28ce00 JS |
1530 | return ret; |
1531 | } | |
1532 | ||
cc6e0bbb JK |
1533 | static void sony_remove(struct hid_device *hdev) |
1534 | { | |
f04d5140 CL |
1535 | struct sony_sc *sc = hid_get_drvdata(hdev); |
1536 | ||
0a286ef2 | 1537 | if (sc->quirks & SONY_LED_SUPPORT) |
c5382519 | 1538 | sony_leds_remove(hdev); |
f04d5140 | 1539 | |
d902f472 FP |
1540 | if (sc->quirks & SONY_BATTERY_SUPPORT) { |
1541 | hid_hw_close(hdev); | |
1542 | sony_battery_remove(sc); | |
1543 | } | |
1544 | ||
9f323b68 SE |
1545 | sony_destroy_ff(hdev); |
1546 | ||
cc6e0bbb | 1547 | hid_hw_stop(hdev); |
cc6e0bbb JK |
1548 | } |
1549 | ||
bd28ce00 | 1550 | static const struct hid_device_id sony_devices[] = { |
816651a7 AO |
1551 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
1552 | .driver_data = SIXAXIS_CONTROLLER_USB }, | |
35dca5b4 JK |
1553 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER), |
1554 | .driver_data = SIXAXIS_CONTROLLER_USB }, | |
816651a7 AO |
1555 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
1556 | .driver_data = SIXAXIS_CONTROLLER_BT }, | |
cc6e0bbb JK |
1557 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE), |
1558 | .driver_data = VAIO_RDESC_CONSTANT }, | |
a4649184 FLVC |
1559 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE), |
1560 | .driver_data = VAIO_RDESC_CONSTANT }, | |
f04d5140 CL |
1561 | /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as |
1562 | * Logitech joystick from the device descriptor. */ | |
1563 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER), | |
1564 | .driver_data = BUZZ_CONTROLLER }, | |
1565 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER), | |
1566 | .driver_data = BUZZ_CONTROLLER }, | |
078328da JK |
1567 | /* PS3 BD Remote Control */ |
1568 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE), | |
1569 | .driver_data = PS3REMOTE }, | |
1570 | /* Logitech Harmony Adapter for PS3 */ | |
1571 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3), | |
1572 | .driver_data = PS3REMOTE }, | |
0bd88dd3 FP |
1573 | /* Sony Dualshock 4 controllers for PS4 */ |
1574 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER), | |
8ab1676b | 1575 | .driver_data = DUALSHOCK4_CONTROLLER_USB }, |
0bd88dd3 | 1576 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER), |
8ab1676b | 1577 | .driver_data = DUALSHOCK4_CONTROLLER_BT }, |
bd28ce00 JS |
1578 | { } |
1579 | }; | |
1580 | MODULE_DEVICE_TABLE(hid, sony_devices); | |
1581 | ||
1582 | static struct hid_driver sony_driver = { | |
f04d5140 CL |
1583 | .name = "sony", |
1584 | .id_table = sony_devices, | |
1585 | .input_mapping = sony_mapping, | |
1586 | .probe = sony_probe, | |
1587 | .remove = sony_remove, | |
1588 | .report_fixup = sony_report_fixup, | |
1589 | .raw_event = sony_raw_event | |
bd28ce00 | 1590 | }; |
f425458e | 1591 | module_hid_driver(sony_driver); |
bd28ce00 | 1592 | |
bd28ce00 | 1593 | MODULE_LICENSE("GPL"); |