Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1 | /* |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 2 | * HID driver for Sony / PS2 / PS3 BD devices. |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 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 |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 7 | * Copyright (c) 2008 Jiri Slaby |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 8 | * Copyright (c) 2012 David Dillow <dave@thedillows.org> |
| 9 | * Copyright (c) 2006-2013 Jiri Kosina |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 10 | * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 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 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 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 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 27 | #include <linux/device.h> |
| 28 | #include <linux/hid.h> |
| 29 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 31 | #include <linux/usb.h> |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 32 | #include <linux/leds.h> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 33 | |
| 34 | #include "hid-ids.h" |
| 35 | |
Frank Praznik | 6c79c18 | 2014-01-16 21:43:03 -0500 | [diff] [blame] | 36 | #define VAIO_RDESC_CONSTANT BIT(0) |
| 37 | #define SIXAXIS_CONTROLLER_USB BIT(1) |
| 38 | #define SIXAXIS_CONTROLLER_BT BIT(2) |
| 39 | #define BUZZ_CONTROLLER BIT(3) |
| 40 | #define PS3REMOTE BIT(4) |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 41 | #define DUALSHOCK4_CONTROLLER_USB BIT(5) |
| 42 | #define DUALSHOCK4_CONTROLLER_BT BIT(6) |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 43 | |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 44 | #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER | DUALSHOCK4_CONTROLLER_USB) |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 45 | |
| 46 | #define MAX_LEDS 4 |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 47 | |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 48 | static const u8 sixaxis_rdesc_fixup[] = { |
| 49 | 0x95, 0x13, 0x09, 0x01, 0x81, 0x02, 0x95, 0x0C, |
| 50 | 0x81, 0x01, 0x75, 0x10, 0x95, 0x04, 0x26, 0xFF, |
| 51 | 0x03, 0x46, 0xFF, 0x03, 0x09, 0x01, 0x81, 0x02 |
| 52 | }; |
| 53 | |
Mauro Carvalho Chehab | e57a67d | 2012-12-14 20:57:34 -0200 | [diff] [blame] | 54 | static const u8 sixaxis_rdesc_fixup2[] = { |
| 55 | 0x05, 0x01, 0x09, 0x04, 0xa1, 0x01, 0xa1, 0x02, |
| 56 | 0x85, 0x01, 0x75, 0x08, 0x95, 0x01, 0x15, 0x00, |
| 57 | 0x26, 0xff, 0x00, 0x81, 0x03, 0x75, 0x01, 0x95, |
| 58 | 0x13, 0x15, 0x00, 0x25, 0x01, 0x35, 0x00, 0x45, |
| 59 | 0x01, 0x05, 0x09, 0x19, 0x01, 0x29, 0x13, 0x81, |
| 60 | 0x02, 0x75, 0x01, 0x95, 0x0d, 0x06, 0x00, 0xff, |
| 61 | 0x81, 0x03, 0x15, 0x00, 0x26, 0xff, 0x00, 0x05, |
| 62 | 0x01, 0x09, 0x01, 0xa1, 0x00, 0x75, 0x08, 0x95, |
| 63 | 0x04, 0x35, 0x00, 0x46, 0xff, 0x00, 0x09, 0x30, |
| 64 | 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x81, 0x02, |
| 65 | 0xc0, 0x05, 0x01, 0x95, 0x13, 0x09, 0x01, 0x81, |
| 66 | 0x02, 0x95, 0x0c, 0x81, 0x01, 0x75, 0x10, 0x95, |
| 67 | 0x04, 0x26, 0xff, 0x03, 0x46, 0xff, 0x03, 0x09, |
| 68 | 0x01, 0x81, 0x02, 0xc0, 0xa1, 0x02, 0x85, 0x02, |
| 69 | 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, 0xb1, 0x02, |
| 70 | 0xc0, 0xa1, 0x02, 0x85, 0xee, 0x75, 0x08, 0x95, |
| 71 | 0x30, 0x09, 0x01, 0xb1, 0x02, 0xc0, 0xa1, 0x02, |
| 72 | 0x85, 0xef, 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, |
| 73 | 0xb1, 0x02, 0xc0, 0xc0, |
| 74 | }; |
| 75 | |
Frank Praznik | 58d7027 | 2014-01-20 12:27:01 -0500 | [diff] [blame^] | 76 | /* The default descriptor doesn't provide mapping for the accelerometers |
| 77 | * or orientation sensors. This fixed descriptor maps the accelerometers |
| 78 | * to usage values 0x40, 0x41 and 0x42 and maps the orientation sensors |
| 79 | * to usage values 0x43, 0x44 and 0x45. |
| 80 | */ |
Frank Praznik | ed19d8c | 2014-01-16 21:43:12 -0500 | [diff] [blame] | 81 | static u8 dualshock4_usb_rdesc[] = { |
Frank Praznik | 58d7027 | 2014-01-20 12:27:01 -0500 | [diff] [blame^] | 82 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 83 | 0x09, 0x05, /* Usage (Gamepad), */ |
| 84 | 0xA1, 0x01, /* Collection (Application), */ |
| 85 | 0x85, 0x01, /* Report ID (1), */ |
| 86 | 0x09, 0x30, /* Usage (X), */ |
| 87 | 0x09, 0x31, /* Usage (Y), */ |
| 88 | 0x09, 0x32, /* Usage (Z), */ |
| 89 | 0x09, 0x35, /* Usage (Rz), */ |
| 90 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 91 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 92 | 0x75, 0x08, /* Report Size (8), */ |
| 93 | 0x95, 0x04, /* Report Count (4), */ |
| 94 | 0x81, 0x02, /* Input (Variable), */ |
| 95 | 0x09, 0x39, /* Usage (Hat Switch), */ |
| 96 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 97 | 0x25, 0x07, /* Logical Maximum (7), */ |
| 98 | 0x35, 0x00, /* Physical Minimum (0), */ |
| 99 | 0x46, 0x3B, 0x01, /* Physical Maximum (315), */ |
| 100 | 0x65, 0x14, /* Unit (Degrees), */ |
| 101 | 0x75, 0x04, /* Report Size (4), */ |
| 102 | 0x95, 0x01, /* Report Count (1), */ |
| 103 | 0x81, 0x42, /* Input (Variable, Null State), */ |
| 104 | 0x65, 0x00, /* Unit, */ |
| 105 | 0x05, 0x09, /* Usage Page (Button), */ |
| 106 | 0x19, 0x01, /* Usage Minimum (01h), */ |
| 107 | 0x29, 0x0E, /* Usage Maximum (0Eh), */ |
| 108 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 109 | 0x25, 0x01, /* Logical Maximum (1), */ |
| 110 | 0x75, 0x01, /* Report Size (1), */ |
| 111 | 0x95, 0x0E, /* Report Count (14), */ |
| 112 | 0x81, 0x02, /* Input (Variable), */ |
| 113 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 114 | 0x09, 0x20, /* Usage (20h), */ |
| 115 | 0x75, 0x06, /* Report Size (6), */ |
| 116 | 0x95, 0x01, /* Report Count (1), */ |
| 117 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 118 | 0x25, 0x7F, /* Logical Maximum (127), */ |
| 119 | 0x81, 0x02, /* Input (Variable), */ |
| 120 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 121 | 0x09, 0x33, /* Usage (Rx), */ |
| 122 | 0x09, 0x34, /* Usage (Ry), */ |
| 123 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 124 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 125 | 0x75, 0x08, /* Report Size (8), */ |
| 126 | 0x95, 0x02, /* Report Count (2), */ |
| 127 | 0x81, 0x02, /* Input (Variable), */ |
| 128 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 129 | 0x09, 0x21, /* Usage (21h), */ |
| 130 | 0x95, 0x03, /* Report Count (3), */ |
| 131 | 0x81, 0x02, /* Input (Variable), */ |
| 132 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 133 | 0x19, 0x40, /* Usage Minimum (40h), */ |
| 134 | 0x29, 0x42, /* Usage Maximum (42h), */ |
| 135 | 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */ |
| 136 | 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */ |
| 137 | 0x75, 0x10, /* Report Size (16), */ |
| 138 | 0x95, 0x03, /* Report Count (3), */ |
| 139 | 0x81, 0x02, /* Input (Variable), */ |
| 140 | 0x19, 0x43, /* Usage Minimum (43h), */ |
| 141 | 0x29, 0x45, /* Usage Maximum (45h), */ |
| 142 | 0x16, 0xFF, 0xBF, /* Logical Minimum (-16385), */ |
| 143 | 0x26, 0x00, 0x40, /* Logical Maximum (16384), */ |
| 144 | 0x95, 0x03, /* Report Count (3), */ |
| 145 | 0x81, 0x02, /* Input (Variable), */ |
| 146 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 147 | 0x09, 0x21, /* Usage (21h), */ |
| 148 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 149 | 0x25, 0xFF, /* Logical Maximum (255), */ |
| 150 | 0x75, 0x08, /* Report Size (8), */ |
| 151 | 0x95, 0x27, /* Report Count (39), */ |
| 152 | 0x81, 0x02, /* Input (Variable), */ |
| 153 | 0x85, 0x05, /* Report ID (5), */ |
| 154 | 0x09, 0x22, /* Usage (22h), */ |
| 155 | 0x95, 0x1F, /* Report Count (31), */ |
| 156 | 0x91, 0x02, /* Output (Variable), */ |
| 157 | 0x85, 0x04, /* Report ID (4), */ |
| 158 | 0x09, 0x23, /* Usage (23h), */ |
| 159 | 0x95, 0x24, /* Report Count (36), */ |
| 160 | 0xB1, 0x02, /* Feature (Variable), */ |
| 161 | 0x85, 0x02, /* Report ID (2), */ |
| 162 | 0x09, 0x24, /* Usage (24h), */ |
| 163 | 0x95, 0x24, /* Report Count (36), */ |
| 164 | 0xB1, 0x02, /* Feature (Variable), */ |
| 165 | 0x85, 0x08, /* Report ID (8), */ |
| 166 | 0x09, 0x25, /* Usage (25h), */ |
| 167 | 0x95, 0x03, /* Report Count (3), */ |
| 168 | 0xB1, 0x02, /* Feature (Variable), */ |
| 169 | 0x85, 0x10, /* Report ID (16), */ |
| 170 | 0x09, 0x26, /* Usage (26h), */ |
| 171 | 0x95, 0x04, /* Report Count (4), */ |
| 172 | 0xB1, 0x02, /* Feature (Variable), */ |
| 173 | 0x85, 0x11, /* Report ID (17), */ |
| 174 | 0x09, 0x27, /* Usage (27h), */ |
| 175 | 0x95, 0x02, /* Report Count (2), */ |
| 176 | 0xB1, 0x02, /* Feature (Variable), */ |
| 177 | 0x85, 0x12, /* Report ID (18), */ |
| 178 | 0x06, 0x02, 0xFF, /* Usage Page (FF02h), */ |
| 179 | 0x09, 0x21, /* Usage (21h), */ |
| 180 | 0x95, 0x0F, /* Report Count (15), */ |
| 181 | 0xB1, 0x02, /* Feature (Variable), */ |
| 182 | 0x85, 0x13, /* Report ID (19), */ |
| 183 | 0x09, 0x22, /* Usage (22h), */ |
| 184 | 0x95, 0x16, /* Report Count (22), */ |
| 185 | 0xB1, 0x02, /* Feature (Variable), */ |
| 186 | 0x85, 0x14, /* Report ID (20), */ |
| 187 | 0x06, 0x05, 0xFF, /* Usage Page (FF05h), */ |
| 188 | 0x09, 0x20, /* Usage (20h), */ |
| 189 | 0x95, 0x10, /* Report Count (16), */ |
| 190 | 0xB1, 0x02, /* Feature (Variable), */ |
| 191 | 0x85, 0x15, /* Report ID (21), */ |
| 192 | 0x09, 0x21, /* Usage (21h), */ |
| 193 | 0x95, 0x2C, /* Report Count (44), */ |
| 194 | 0xB1, 0x02, /* Feature (Variable), */ |
| 195 | 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */ |
| 196 | 0x85, 0x80, /* Report ID (128), */ |
| 197 | 0x09, 0x20, /* Usage (20h), */ |
| 198 | 0x95, 0x06, /* Report Count (6), */ |
| 199 | 0xB1, 0x02, /* Feature (Variable), */ |
| 200 | 0x85, 0x81, /* Report ID (129), */ |
| 201 | 0x09, 0x21, /* Usage (21h), */ |
| 202 | 0x95, 0x06, /* Report Count (6), */ |
| 203 | 0xB1, 0x02, /* Feature (Variable), */ |
| 204 | 0x85, 0x82, /* Report ID (130), */ |
| 205 | 0x09, 0x22, /* Usage (22h), */ |
| 206 | 0x95, 0x05, /* Report Count (5), */ |
| 207 | 0xB1, 0x02, /* Feature (Variable), */ |
| 208 | 0x85, 0x83, /* Report ID (131), */ |
| 209 | 0x09, 0x23, /* Usage (23h), */ |
| 210 | 0x95, 0x01, /* Report Count (1), */ |
| 211 | 0xB1, 0x02, /* Feature (Variable), */ |
| 212 | 0x85, 0x84, /* Report ID (132), */ |
| 213 | 0x09, 0x24, /* Usage (24h), */ |
| 214 | 0x95, 0x04, /* Report Count (4), */ |
| 215 | 0xB1, 0x02, /* Feature (Variable), */ |
| 216 | 0x85, 0x85, /* Report ID (133), */ |
| 217 | 0x09, 0x25, /* Usage (25h), */ |
| 218 | 0x95, 0x06, /* Report Count (6), */ |
| 219 | 0xB1, 0x02, /* Feature (Variable), */ |
| 220 | 0x85, 0x86, /* Report ID (134), */ |
| 221 | 0x09, 0x26, /* Usage (26h), */ |
| 222 | 0x95, 0x06, /* Report Count (6), */ |
| 223 | 0xB1, 0x02, /* Feature (Variable), */ |
| 224 | 0x85, 0x87, /* Report ID (135), */ |
| 225 | 0x09, 0x27, /* Usage (27h), */ |
| 226 | 0x95, 0x23, /* Report Count (35), */ |
| 227 | 0xB1, 0x02, /* Feature (Variable), */ |
| 228 | 0x85, 0x88, /* Report ID (136), */ |
| 229 | 0x09, 0x28, /* Usage (28h), */ |
| 230 | 0x95, 0x22, /* Report Count (34), */ |
| 231 | 0xB1, 0x02, /* Feature (Variable), */ |
| 232 | 0x85, 0x89, /* Report ID (137), */ |
| 233 | 0x09, 0x29, /* Usage (29h), */ |
| 234 | 0x95, 0x02, /* Report Count (2), */ |
| 235 | 0xB1, 0x02, /* Feature (Variable), */ |
| 236 | 0x85, 0x90, /* Report ID (144), */ |
| 237 | 0x09, 0x30, /* Usage (30h), */ |
| 238 | 0x95, 0x05, /* Report Count (5), */ |
| 239 | 0xB1, 0x02, /* Feature (Variable), */ |
| 240 | 0x85, 0x91, /* Report ID (145), */ |
| 241 | 0x09, 0x31, /* Usage (31h), */ |
| 242 | 0x95, 0x03, /* Report Count (3), */ |
| 243 | 0xB1, 0x02, /* Feature (Variable), */ |
| 244 | 0x85, 0x92, /* Report ID (146), */ |
| 245 | 0x09, 0x32, /* Usage (32h), */ |
| 246 | 0x95, 0x03, /* Report Count (3), */ |
| 247 | 0xB1, 0x02, /* Feature (Variable), */ |
| 248 | 0x85, 0x93, /* Report ID (147), */ |
| 249 | 0x09, 0x33, /* Usage (33h), */ |
| 250 | 0x95, 0x0C, /* Report Count (12), */ |
| 251 | 0xB1, 0x02, /* Feature (Variable), */ |
| 252 | 0x85, 0xA0, /* Report ID (160), */ |
| 253 | 0x09, 0x40, /* Usage (40h), */ |
| 254 | 0x95, 0x06, /* Report Count (6), */ |
| 255 | 0xB1, 0x02, /* Feature (Variable), */ |
| 256 | 0x85, 0xA1, /* Report ID (161), */ |
| 257 | 0x09, 0x41, /* Usage (41h), */ |
| 258 | 0x95, 0x01, /* Report Count (1), */ |
| 259 | 0xB1, 0x02, /* Feature (Variable), */ |
| 260 | 0x85, 0xA2, /* Report ID (162), */ |
| 261 | 0x09, 0x42, /* Usage (42h), */ |
| 262 | 0x95, 0x01, /* Report Count (1), */ |
| 263 | 0xB1, 0x02, /* Feature (Variable), */ |
| 264 | 0x85, 0xA3, /* Report ID (163), */ |
| 265 | 0x09, 0x43, /* Usage (43h), */ |
| 266 | 0x95, 0x30, /* Report Count (48), */ |
| 267 | 0xB1, 0x02, /* Feature (Variable), */ |
| 268 | 0x85, 0xA4, /* Report ID (164), */ |
| 269 | 0x09, 0x44, /* Usage (44h), */ |
| 270 | 0x95, 0x0D, /* Report Count (13), */ |
| 271 | 0xB1, 0x02, /* Feature (Variable), */ |
| 272 | 0x85, 0xA5, /* Report ID (165), */ |
| 273 | 0x09, 0x45, /* Usage (45h), */ |
| 274 | 0x95, 0x15, /* Report Count (21), */ |
| 275 | 0xB1, 0x02, /* Feature (Variable), */ |
| 276 | 0x85, 0xA6, /* Report ID (166), */ |
| 277 | 0x09, 0x46, /* Usage (46h), */ |
| 278 | 0x95, 0x15, /* Report Count (21), */ |
| 279 | 0xB1, 0x02, /* Feature (Variable), */ |
| 280 | 0x85, 0xF0, /* Report ID (240), */ |
| 281 | 0x09, 0x47, /* Usage (47h), */ |
| 282 | 0x95, 0x3F, /* Report Count (63), */ |
| 283 | 0xB1, 0x02, /* Feature (Variable), */ |
| 284 | 0x85, 0xF1, /* Report ID (241), */ |
| 285 | 0x09, 0x48, /* Usage (48h), */ |
| 286 | 0x95, 0x3F, /* Report Count (63), */ |
| 287 | 0xB1, 0x02, /* Feature (Variable), */ |
| 288 | 0x85, 0xF2, /* Report ID (242), */ |
| 289 | 0x09, 0x49, /* Usage (49h), */ |
| 290 | 0x95, 0x0F, /* Report Count (15), */ |
| 291 | 0xB1, 0x02, /* Feature (Variable), */ |
| 292 | 0x85, 0xA7, /* Report ID (167), */ |
| 293 | 0x09, 0x4A, /* Usage (4Ah), */ |
| 294 | 0x95, 0x01, /* Report Count (1), */ |
| 295 | 0xB1, 0x02, /* Feature (Variable), */ |
| 296 | 0x85, 0xA8, /* Report ID (168), */ |
| 297 | 0x09, 0x4B, /* Usage (4Bh), */ |
| 298 | 0x95, 0x01, /* Report Count (1), */ |
| 299 | 0xB1, 0x02, /* Feature (Variable), */ |
| 300 | 0x85, 0xA9, /* Report ID (169), */ |
| 301 | 0x09, 0x4C, /* Usage (4Ch), */ |
| 302 | 0x95, 0x08, /* Report Count (8), */ |
| 303 | 0xB1, 0x02, /* Feature (Variable), */ |
| 304 | 0x85, 0xAA, /* Report ID (170), */ |
| 305 | 0x09, 0x4E, /* Usage (4Eh), */ |
| 306 | 0x95, 0x01, /* Report Count (1), */ |
| 307 | 0xB1, 0x02, /* Feature (Variable), */ |
| 308 | 0x85, 0xAB, /* Report ID (171), */ |
| 309 | 0x09, 0x4F, /* Usage (4Fh), */ |
| 310 | 0x95, 0x39, /* Report Count (57), */ |
| 311 | 0xB1, 0x02, /* Feature (Variable), */ |
| 312 | 0x85, 0xAC, /* Report ID (172), */ |
| 313 | 0x09, 0x50, /* Usage (50h), */ |
| 314 | 0x95, 0x39, /* Report Count (57), */ |
| 315 | 0xB1, 0x02, /* Feature (Variable), */ |
| 316 | 0x85, 0xAD, /* Report ID (173), */ |
| 317 | 0x09, 0x51, /* Usage (51h), */ |
| 318 | 0x95, 0x0B, /* Report Count (11), */ |
| 319 | 0xB1, 0x02, /* Feature (Variable), */ |
| 320 | 0x85, 0xAE, /* Report ID (174), */ |
| 321 | 0x09, 0x52, /* Usage (52h), */ |
| 322 | 0x95, 0x01, /* Report Count (1), */ |
| 323 | 0xB1, 0x02, /* Feature (Variable), */ |
| 324 | 0x85, 0xAF, /* Report ID (175), */ |
| 325 | 0x09, 0x53, /* Usage (53h), */ |
| 326 | 0x95, 0x02, /* Report Count (2), */ |
| 327 | 0xB1, 0x02, /* Feature (Variable), */ |
| 328 | 0x85, 0xB0, /* Report ID (176), */ |
| 329 | 0x09, 0x54, /* Usage (54h), */ |
| 330 | 0x95, 0x3F, /* Report Count (63), */ |
| 331 | 0xB1, 0x02, /* Feature (Variable), */ |
| 332 | 0xC0 /* End Collection */ |
Frank Praznik | ed19d8c | 2014-01-16 21:43:12 -0500 | [diff] [blame] | 333 | }; |
| 334 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 335 | static __u8 ps3remote_rdesc[] = { |
| 336 | 0x05, 0x01, /* GUsagePage Generic Desktop */ |
| 337 | 0x09, 0x05, /* LUsage 0x05 [Game Pad] */ |
| 338 | 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */ |
| 339 | |
| 340 | /* Use collection 1 for joypad buttons */ |
| 341 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ |
| 342 | |
| 343 | /* Ignore the 1st byte, maybe it is used for a controller |
| 344 | * number but it's not needed for correct operation */ |
| 345 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 346 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 347 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ |
| 348 | |
| 349 | /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these |
| 350 | * buttons multiple keypresses are allowed */ |
| 351 | 0x05, 0x09, /* GUsagePage Button */ |
| 352 | 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */ |
| 353 | 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */ |
| 354 | 0x14, /* GLogicalMinimum [0] */ |
| 355 | 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */ |
| 356 | 0x75, 0x01, /* GReportSize 0x01 [1] */ |
| 357 | 0x95, 0x18, /* GReportCount 0x18 [24] */ |
| 358 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ |
| 359 | |
| 360 | 0xC0, /* MEndCollection */ |
| 361 | |
| 362 | /* Use collection 2 for remote control buttons */ |
| 363 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ |
| 364 | |
| 365 | /* 5th byte is used for remote control buttons */ |
| 366 | 0x05, 0x09, /* GUsagePage Button */ |
| 367 | 0x18, /* LUsageMinimum [No button pressed] */ |
| 368 | 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */ |
| 369 | 0x14, /* GLogicalMinimum [0] */ |
| 370 | 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */ |
| 371 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 372 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 373 | 0x80, /* MInput */ |
| 374 | |
| 375 | /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at |
| 376 | * 0xff and 11th is for press indication */ |
| 377 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 378 | 0x95, 0x06, /* GReportCount 0x06 [6] */ |
| 379 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ |
| 380 | |
| 381 | /* 12th byte is for battery strength */ |
| 382 | 0x05, 0x06, /* GUsagePage Generic Device Controls */ |
| 383 | 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */ |
| 384 | 0x14, /* GLogicalMinimum [0] */ |
| 385 | 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */ |
| 386 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 387 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 388 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ |
| 389 | |
| 390 | 0xC0, /* MEndCollection */ |
| 391 | |
| 392 | 0xC0 /* MEndCollection [Game Pad] */ |
| 393 | }; |
| 394 | |
| 395 | static const unsigned int ps3remote_keymap_joypad_buttons[] = { |
| 396 | [0x01] = KEY_SELECT, |
| 397 | [0x02] = BTN_THUMBL, /* L3 */ |
| 398 | [0x03] = BTN_THUMBR, /* R3 */ |
| 399 | [0x04] = BTN_START, |
| 400 | [0x05] = KEY_UP, |
| 401 | [0x06] = KEY_RIGHT, |
| 402 | [0x07] = KEY_DOWN, |
| 403 | [0x08] = KEY_LEFT, |
| 404 | [0x09] = BTN_TL2, /* L2 */ |
| 405 | [0x0a] = BTN_TR2, /* R2 */ |
| 406 | [0x0b] = BTN_TL, /* L1 */ |
| 407 | [0x0c] = BTN_TR, /* R1 */ |
| 408 | [0x0d] = KEY_OPTION, /* options/triangle */ |
| 409 | [0x0e] = KEY_BACK, /* back/circle */ |
| 410 | [0x0f] = BTN_0, /* cross */ |
| 411 | [0x10] = KEY_SCREEN, /* view/square */ |
| 412 | [0x11] = KEY_HOMEPAGE, /* PS button */ |
| 413 | [0x14] = KEY_ENTER, |
| 414 | }; |
| 415 | static const unsigned int ps3remote_keymap_remote_buttons[] = { |
| 416 | [0x00] = KEY_1, |
| 417 | [0x01] = KEY_2, |
| 418 | [0x02] = KEY_3, |
| 419 | [0x03] = KEY_4, |
| 420 | [0x04] = KEY_5, |
| 421 | [0x05] = KEY_6, |
| 422 | [0x06] = KEY_7, |
| 423 | [0x07] = KEY_8, |
| 424 | [0x08] = KEY_9, |
| 425 | [0x09] = KEY_0, |
| 426 | [0x0e] = KEY_ESC, /* return */ |
| 427 | [0x0f] = KEY_CLEAR, |
| 428 | [0x16] = KEY_EJECTCD, |
| 429 | [0x1a] = KEY_MENU, /* top menu */ |
| 430 | [0x28] = KEY_TIME, |
| 431 | [0x30] = KEY_PREVIOUS, |
| 432 | [0x31] = KEY_NEXT, |
| 433 | [0x32] = KEY_PLAY, |
| 434 | [0x33] = KEY_REWIND, /* scan back */ |
| 435 | [0x34] = KEY_FORWARD, /* scan forward */ |
| 436 | [0x38] = KEY_STOP, |
| 437 | [0x39] = KEY_PAUSE, |
| 438 | [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */ |
| 439 | [0x60] = KEY_FRAMEBACK, /* slow/step back */ |
| 440 | [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */ |
| 441 | [0x63] = KEY_SUBTITLE, |
| 442 | [0x64] = KEY_AUDIO, |
| 443 | [0x65] = KEY_ANGLE, |
| 444 | [0x70] = KEY_INFO, /* display */ |
| 445 | [0x80] = KEY_BLUE, |
| 446 | [0x81] = KEY_RED, |
| 447 | [0x82] = KEY_GREEN, |
| 448 | [0x83] = KEY_YELLOW, |
| 449 | }; |
| 450 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 451 | static const unsigned int buzz_keymap[] = { |
| 452 | /* The controller has 4 remote buzzers, each with one LED and 5 |
| 453 | * buttons. |
| 454 | * |
| 455 | * We use the mapping chosen by the controller, which is: |
| 456 | * |
| 457 | * Key Offset |
| 458 | * ------------------- |
| 459 | * Buzz 1 |
| 460 | * Blue 5 |
| 461 | * Orange 4 |
| 462 | * Green 3 |
| 463 | * Yellow 2 |
| 464 | * |
| 465 | * So, for example, the orange button on the third buzzer is mapped to |
| 466 | * BTN_TRIGGER_HAPPY14 |
| 467 | */ |
| 468 | [ 1] = BTN_TRIGGER_HAPPY1, |
| 469 | [ 2] = BTN_TRIGGER_HAPPY2, |
| 470 | [ 3] = BTN_TRIGGER_HAPPY3, |
| 471 | [ 4] = BTN_TRIGGER_HAPPY4, |
| 472 | [ 5] = BTN_TRIGGER_HAPPY5, |
| 473 | [ 6] = BTN_TRIGGER_HAPPY6, |
| 474 | [ 7] = BTN_TRIGGER_HAPPY7, |
| 475 | [ 8] = BTN_TRIGGER_HAPPY8, |
| 476 | [ 9] = BTN_TRIGGER_HAPPY9, |
| 477 | [10] = BTN_TRIGGER_HAPPY10, |
| 478 | [11] = BTN_TRIGGER_HAPPY11, |
| 479 | [12] = BTN_TRIGGER_HAPPY12, |
| 480 | [13] = BTN_TRIGGER_HAPPY13, |
| 481 | [14] = BTN_TRIGGER_HAPPY14, |
| 482 | [15] = BTN_TRIGGER_HAPPY15, |
| 483 | [16] = BTN_TRIGGER_HAPPY16, |
| 484 | [17] = BTN_TRIGGER_HAPPY17, |
| 485 | [18] = BTN_TRIGGER_HAPPY18, |
| 486 | [19] = BTN_TRIGGER_HAPPY19, |
| 487 | [20] = BTN_TRIGGER_HAPPY20, |
| 488 | }; |
| 489 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 490 | struct sony_sc { |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 491 | struct hid_device *hdev; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 492 | struct led_classdev *leds[MAX_LEDS]; |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 493 | struct hid_report *output_report; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 494 | unsigned long quirks; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 495 | struct work_struct state_worker; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 496 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 497 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 498 | __u8 left; |
| 499 | __u8 right; |
| 500 | #endif |
| 501 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 502 | __u8 led_state[MAX_LEDS]; |
| 503 | __u8 led_count; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 504 | }; |
| 505 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 506 | static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 507 | unsigned int *rsize) |
| 508 | { |
| 509 | *rsize = sizeof(ps3remote_rdesc); |
| 510 | return ps3remote_rdesc; |
| 511 | } |
| 512 | |
| 513 | static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 514 | struct hid_field *field, struct hid_usage *usage, |
| 515 | unsigned long **bit, int *max) |
| 516 | { |
| 517 | unsigned int key = usage->hid & HID_USAGE; |
| 518 | |
| 519 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| 520 | return -1; |
| 521 | |
| 522 | switch (usage->collection_index) { |
| 523 | case 1: |
| 524 | if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons)) |
| 525 | return -1; |
| 526 | |
| 527 | key = ps3remote_keymap_joypad_buttons[key]; |
| 528 | if (!key) |
| 529 | return -1; |
| 530 | break; |
| 531 | case 2: |
| 532 | if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons)) |
| 533 | return -1; |
| 534 | |
| 535 | key = ps3remote_keymap_remote_buttons[key]; |
| 536 | if (!key) |
| 537 | return -1; |
| 538 | break; |
| 539 | default: |
| 540 | return -1; |
| 541 | } |
| 542 | |
| 543 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); |
| 544 | return 1; |
| 545 | } |
| 546 | |
| 547 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 548 | /* Sony Vaio VGX has wrongly mouse pointer declared as constant */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 549 | static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 550 | unsigned int *rsize) |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 551 | { |
| 552 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 553 | |
Fernando Luis Vázquez Cao | 99d2490 | 2013-01-22 15:20:38 +0900 | [diff] [blame] | 554 | /* |
| 555 | * Some Sony RF receivers wrongly declare the mouse pointer as a |
| 556 | * a constant non-data variable. |
| 557 | */ |
| 558 | if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 && |
| 559 | /* usage page: generic desktop controls */ |
| 560 | /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */ |
| 561 | /* usage: mouse */ |
| 562 | rdesc[2] == 0x09 && rdesc[3] == 0x02 && |
| 563 | /* input (usage page for x,y axes): constant, variable, relative */ |
| 564 | rdesc[54] == 0x81 && rdesc[55] == 0x07) { |
Fernando Luis Vázquez Cao | a4649184 | 2013-01-15 19:40:48 +0900 | [diff] [blame] | 565 | hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n"); |
Fernando Luis Vázquez Cao | 99d2490 | 2013-01-22 15:20:38 +0900 | [diff] [blame] | 566 | /* input: data, variable, relative */ |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 567 | rdesc[55] = 0x06; |
| 568 | } |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 569 | |
Frank Praznik | ed19d8c | 2014-01-16 21:43:12 -0500 | [diff] [blame] | 570 | /* |
| 571 | * The default Dualshock 4 USB descriptor doesn't assign |
| 572 | * the gyroscope values to corresponding axes so we need a |
| 573 | * modified one. |
| 574 | */ |
| 575 | if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && *rsize == 467) { |
| 576 | hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n"); |
| 577 | rdesc = dualshock4_usb_rdesc; |
| 578 | *rsize = sizeof(dualshock4_usb_rdesc); |
| 579 | } |
| 580 | |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 581 | /* The HID descriptor exposed over BT has a trailing zero byte */ |
| 582 | if ((((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize == 148) || |
| 583 | ((sc->quirks & SIXAXIS_CONTROLLER_BT) && *rsize == 149)) && |
| 584 | rdesc[83] == 0x75) { |
| 585 | hid_info(hdev, "Fixing up Sony Sixaxis report descriptor\n"); |
| 586 | memcpy((void *)&rdesc[83], (void *)&sixaxis_rdesc_fixup, |
| 587 | sizeof(sixaxis_rdesc_fixup)); |
Mauro Carvalho Chehab | e57a67d | 2012-12-14 20:57:34 -0200 | [diff] [blame] | 588 | } else if (sc->quirks & SIXAXIS_CONTROLLER_USB && |
| 589 | *rsize > sizeof(sixaxis_rdesc_fixup2)) { |
| 590 | hid_info(hdev, "Sony Sixaxis clone detected. Using original report descriptor (size: %d clone; %d new)\n", |
| 591 | *rsize, (int)sizeof(sixaxis_rdesc_fixup2)); |
| 592 | *rsize = sizeof(sixaxis_rdesc_fixup2); |
| 593 | memcpy(rdesc, &sixaxis_rdesc_fixup2, *rsize); |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 594 | } |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 595 | |
| 596 | if (sc->quirks & PS3REMOTE) |
| 597 | return ps3remote_fixup(hdev, rdesc, rsize); |
| 598 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 599 | return rdesc; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Simon Wood | c9e4d87 | 2011-06-10 12:00:27 +0200 | [diff] [blame] | 602 | static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 603 | __u8 *rd, int size) |
| 604 | { |
| 605 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 606 | |
| 607 | /* Sixaxis HID report has acclerometers/gyro with MSByte first, this |
| 608 | * has to be BYTE_SWAPPED before passing up to joystick interface |
| 609 | */ |
| 610 | if ((sc->quirks & (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)) && |
| 611 | rd[0] == 0x01 && size == 49) { |
| 612 | swap(rd[41], rd[42]); |
| 613 | swap(rd[43], rd[44]); |
| 614 | swap(rd[45], rd[46]); |
| 615 | swap(rd[47], rd[48]); |
| 616 | } |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 621 | static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 622 | struct hid_field *field, struct hid_usage *usage, |
| 623 | unsigned long **bit, int *max) |
| 624 | { |
| 625 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 626 | |
| 627 | if (sc->quirks & BUZZ_CONTROLLER) { |
| 628 | unsigned int key = usage->hid & HID_USAGE; |
| 629 | |
| 630 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| 631 | return -1; |
| 632 | |
| 633 | switch (usage->collection_index) { |
| 634 | case 1: |
| 635 | if (key >= ARRAY_SIZE(buzz_keymap)) |
| 636 | return -1; |
| 637 | |
| 638 | key = buzz_keymap[key]; |
| 639 | if (!key) |
| 640 | return -1; |
| 641 | break; |
| 642 | default: |
| 643 | return -1; |
| 644 | } |
| 645 | |
| 646 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); |
| 647 | return 1; |
| 648 | } |
| 649 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 650 | if (sc->quirks & PS3REMOTE) |
| 651 | return ps3remote_mapping(hdev, hi, field, usage, bit, max); |
| 652 | |
Benjamin Tissoires | 6f49801 | 2013-07-24 16:53:07 +0200 | [diff] [blame] | 653 | /* Let hid-core decide for the others */ |
| 654 | return 0; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 655 | } |
| 656 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 657 | /* |
| 658 | * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP |
| 659 | * like it should according to usbhid/hid-core.c::usbhid_output_raw_report() |
| 660 | * so we need to override that forcing HID Output Reports on the Control EP. |
| 661 | * |
| 662 | * There is also another issue about HID Output Reports via USB, the Sixaxis |
| 663 | * does not want the report_id as part of the data packet, so we have to |
| 664 | * discard buf[0] when sending the actual control message, even for numbered |
| 665 | * reports, humpf! |
| 666 | */ |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 667 | static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf, |
| 668 | size_t count, unsigned char report_type) |
| 669 | { |
| 670 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); |
| 671 | struct usb_device *dev = interface_to_usbdev(intf); |
| 672 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 673 | int report_id = buf[0]; |
| 674 | int ret; |
| 675 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 676 | if (report_type == HID_OUTPUT_REPORT) { |
| 677 | /* Don't send the Report ID */ |
| 678 | buf++; |
| 679 | count--; |
| 680 | } |
| 681 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 682 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 683 | HID_REQ_SET_REPORT, |
| 684 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 685 | ((report_type + 1) << 8) | report_id, |
| 686 | interface->desc.bInterfaceNumber, buf, count, |
| 687 | USB_CTRL_SET_TIMEOUT); |
| 688 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 689 | /* Count also the Report ID, in case of an Output report. */ |
| 690 | if (ret > 0 && report_type == HID_OUTPUT_REPORT) |
| 691 | ret++; |
| 692 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 693 | return ret; |
| 694 | } |
| 695 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 696 | /* |
| 697 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
| 698 | * to "operational". Without this, the ps3 controller will not report any |
| 699 | * events. |
| 700 | */ |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 701 | static int sixaxis_set_operational_usb(struct hid_device *hdev) |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 702 | { |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 703 | int ret; |
| 704 | char *buf = kmalloc(18, GFP_KERNEL); |
| 705 | |
| 706 | if (!buf) |
| 707 | return -ENOMEM; |
| 708 | |
Benjamin Tissoires | f204828a | 2013-09-11 22:12:25 +0200 | [diff] [blame] | 709 | ret = hdev->hid_get_raw_report(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT); |
| 710 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 711 | if (ret < 0) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 712 | hid_err(hdev, "can't set operational mode\n"); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 713 | |
| 714 | kfree(buf); |
| 715 | |
| 716 | return ret; |
| 717 | } |
| 718 | |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 719 | static int sixaxis_set_operational_bt(struct hid_device *hdev) |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 720 | { |
Antonio Ospite | fddb33f | 2010-05-03 17:19:03 +0200 | [diff] [blame] | 721 | unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 722 | return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); |
| 723 | } |
| 724 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 725 | static void buzz_set_leds(struct hid_device *hdev, const __u8 *leds) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 726 | { |
| 727 | struct list_head *report_list = |
| 728 | &hdev->report_enum[HID_OUTPUT_REPORT].report_list; |
| 729 | struct hid_report *report = list_entry(report_list->next, |
| 730 | struct hid_report, list); |
| 731 | __s32 *value = report->field[0]->value; |
| 732 | |
| 733 | value[0] = 0x00; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 734 | value[1] = leds[0] ? 0xff : 0x00; |
| 735 | value[2] = leds[1] ? 0xff : 0x00; |
| 736 | value[3] = leds[2] ? 0xff : 0x00; |
| 737 | value[4] = leds[3] ? 0xff : 0x00; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 738 | value[5] = 0x00; |
| 739 | value[6] = 0x00; |
| 740 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
| 741 | } |
| 742 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 743 | static void sony_set_leds(struct hid_device *hdev, const __u8 *leds, int count) |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 744 | { |
| 745 | struct sony_sc *drv_data = hid_get_drvdata(hdev); |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 746 | int n; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 747 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 748 | BUG_ON(count > MAX_LEDS); |
| 749 | |
| 750 | if (drv_data->quirks & BUZZ_CONTROLLER && count == 4) { |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 751 | buzz_set_leds(hdev, leds); |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 752 | } else if ((drv_data->quirks & SIXAXIS_CONTROLLER_USB) || |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 753 | (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB)) { |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 754 | for (n = 0; n < count; n++) |
| 755 | drv_data->led_state[n] = leds[n]; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 756 | schedule_work(&drv_data->state_worker); |
| 757 | } |
| 758 | } |
| 759 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 760 | static void sony_led_set_brightness(struct led_classdev *led, |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 761 | enum led_brightness value) |
| 762 | { |
| 763 | struct device *dev = led->dev->parent; |
| 764 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 765 | struct sony_sc *drv_data; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 766 | |
| 767 | int n; |
| 768 | |
| 769 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 770 | if (!drv_data) { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 771 | hid_err(hdev, "No device data\n"); |
| 772 | return; |
| 773 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 774 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 775 | for (n = 0; n < drv_data->led_count; n++) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 776 | if (led == drv_data->leds[n]) { |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 777 | if (value != drv_data->led_state[n]) { |
| 778 | drv_data->led_state[n] = value; |
| 779 | sony_set_leds(hdev, drv_data->led_state, drv_data->led_count); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 780 | } |
| 781 | break; |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 786 | static enum led_brightness sony_led_get_brightness(struct led_classdev *led) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 787 | { |
| 788 | struct device *dev = led->dev->parent; |
| 789 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 790 | struct sony_sc *drv_data; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 791 | |
| 792 | int n; |
| 793 | int on = 0; |
| 794 | |
| 795 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 796 | if (!drv_data) { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 797 | hid_err(hdev, "No device data\n"); |
| 798 | return LED_OFF; |
| 799 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 800 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 801 | for (n = 0; n < drv_data->led_count; n++) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 802 | if (led == drv_data->leds[n]) { |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 803 | on = !!(drv_data->led_state[n]); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 804 | break; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | return on ? LED_FULL : LED_OFF; |
| 809 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 810 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 811 | static void sony_leds_remove(struct hid_device *hdev) |
| 812 | { |
| 813 | struct sony_sc *drv_data; |
| 814 | struct led_classdev *led; |
| 815 | int n; |
| 816 | |
| 817 | drv_data = hid_get_drvdata(hdev); |
| 818 | BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT)); |
| 819 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 820 | for (n = 0; n < drv_data->led_count; n++) { |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 821 | led = drv_data->leds[n]; |
| 822 | drv_data->leds[n] = NULL; |
| 823 | if (!led) |
| 824 | continue; |
| 825 | led_classdev_unregister(led); |
| 826 | kfree(led); |
| 827 | } |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 828 | |
| 829 | drv_data->led_count = 0; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 830 | } |
| 831 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 832 | static int sony_leds_init(struct hid_device *hdev) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 833 | { |
| 834 | struct sony_sc *drv_data; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 835 | int n, ret = 0; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 836 | int max_brightness; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 837 | struct led_classdev *led; |
| 838 | size_t name_sz; |
| 839 | char *name; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 840 | size_t name_len; |
| 841 | const char *name_fmt; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 842 | static const __u8 initial_values[MAX_LEDS] = { 0x00, 0x00, 0x00, 0x00 }; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 843 | |
| 844 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 845 | BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT)); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 846 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 847 | if (drv_data->quirks & BUZZ_CONTROLLER) { |
| 848 | name_len = strlen("::buzz#"); |
| 849 | name_fmt = "%s::buzz%d"; |
| 850 | /* Validate expected report characteristics. */ |
| 851 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) |
| 852 | return -ENODEV; |
| 853 | } else { |
| 854 | name_len = strlen("::sony#"); |
| 855 | name_fmt = "%s::sony%d"; |
| 856 | } |
Kees Cook | 9446edb | 2013-09-11 21:56:52 +0200 | [diff] [blame] | 857 | |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 858 | if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) { |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 859 | drv_data->led_count = 3; |
| 860 | max_brightness = 255; |
| 861 | } else { |
| 862 | drv_data->led_count = 4; |
| 863 | max_brightness = 1; |
| 864 | } |
| 865 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 866 | /* Clear LEDs as we have no way of reading their initial state. This is |
| 867 | * only relevant if the driver is loaded after somebody actively set the |
| 868 | * LEDs to on */ |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 869 | sony_set_leds(hdev, initial_values, drv_data->led_count); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 870 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 871 | name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 872 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 873 | for (n = 0; n < drv_data->led_count; n++) { |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 874 | led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); |
| 875 | if (!led) { |
| 876 | hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); |
Julia Lawall | 8cd5fcd | 2013-12-29 23:47:27 +0100 | [diff] [blame] | 877 | ret = -ENOMEM; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 878 | goto error_leds; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 879 | } |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 880 | |
| 881 | name = (void *)(&led[1]); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 882 | snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 883 | led->name = name; |
| 884 | led->brightness = 0; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 885 | led->max_brightness = max_brightness; |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 886 | led->brightness_get = sony_led_get_brightness; |
| 887 | led->brightness_set = sony_led_set_brightness; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 888 | |
Julia Lawall | 8cd5fcd | 2013-12-29 23:47:27 +0100 | [diff] [blame] | 889 | ret = led_classdev_register(&hdev->dev, led); |
| 890 | if (ret) { |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 891 | hid_err(hdev, "Failed to register LED %d\n", n); |
| 892 | kfree(led); |
| 893 | goto error_leds; |
| 894 | } |
| 895 | |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 896 | drv_data->leds[n] = led; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 897 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 898 | |
| 899 | return ret; |
| 900 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 901 | error_leds: |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 902 | sony_leds_remove(hdev); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 903 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 904 | return ret; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 905 | } |
| 906 | |
Frank Praznik | cad665a | 2014-01-11 15:13:54 -0500 | [diff] [blame] | 907 | static void sixaxis_state_worker(struct work_struct *work) |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 908 | { |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 909 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 910 | unsigned char buf[] = { |
| 911 | 0x01, |
| 912 | 0x00, 0xff, 0x00, 0xff, 0x00, |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 913 | 0x00, 0x00, 0x00, 0x00, 0x00, |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 914 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 915 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 916 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 917 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 918 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 919 | }; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 920 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 921 | #ifdef CONFIG_SONY_FF |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 922 | buf[3] = sc->right ? 1 : 0; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 923 | buf[5] = sc->left; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 924 | #endif |
| 925 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 926 | buf[10] |= sc->led_state[0] << 1; |
| 927 | buf[10] |= sc->led_state[1] << 2; |
| 928 | buf[10] |= sc->led_state[2] << 3; |
| 929 | buf[10] |= sc->led_state[3] << 4; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 930 | |
| 931 | sc->hdev->hid_output_raw_report(sc->hdev, buf, sizeof(buf), |
| 932 | HID_OUTPUT_REPORT); |
| 933 | } |
| 934 | |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 935 | static void dualshock4_state_worker(struct work_struct *work) |
| 936 | { |
| 937 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); |
Frank Praznik | 0da8ea6 | 2014-01-16 21:42:51 -0500 | [diff] [blame] | 938 | struct hid_device *hdev = sc->hdev; |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 939 | struct hid_report *report = sc->output_report; |
| 940 | __s32 *value = report->field[0]->value; |
Frank Praznik | 0da8ea6 | 2014-01-16 21:42:51 -0500 | [diff] [blame] | 941 | |
Frank Praznik | 0da8ea6 | 2014-01-16 21:42:51 -0500 | [diff] [blame] | 942 | value[0] = 0x03; |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 943 | |
| 944 | #ifdef CONFIG_SONY_FF |
Frank Praznik | 0da8ea6 | 2014-01-16 21:42:51 -0500 | [diff] [blame] | 945 | value[3] = sc->right; |
| 946 | value[4] = sc->left; |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 947 | #endif |
| 948 | |
Frank Praznik | 0da8ea6 | 2014-01-16 21:42:51 -0500 | [diff] [blame] | 949 | value[5] = sc->led_state[0]; |
| 950 | value[6] = sc->led_state[1]; |
| 951 | value[7] = sc->led_state[2]; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 952 | |
Frank Praznik | 0da8ea6 | 2014-01-16 21:42:51 -0500 | [diff] [blame] | 953 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 954 | } |
| 955 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 956 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 957 | static int sony_play_effect(struct input_dev *dev, void *data, |
| 958 | struct ff_effect *effect) |
| 959 | { |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 960 | struct hid_device *hid = input_get_drvdata(dev); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 961 | struct sony_sc *sc = hid_get_drvdata(hid); |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 962 | |
| 963 | if (effect->type != FF_RUMBLE) |
| 964 | return 0; |
| 965 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 966 | sc->left = effect->u.rumble.strong_magnitude / 256; |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 967 | sc->right = effect->u.rumble.weak_magnitude / 256; |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 968 | |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 969 | schedule_work(&sc->state_worker); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 970 | return 0; |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | static int sony_init_ff(struct hid_device *hdev) |
| 974 | { |
| 975 | struct hid_input *hidinput = list_entry(hdev->inputs.next, |
| 976 | struct hid_input, list); |
| 977 | struct input_dev *input_dev = hidinput->input; |
| 978 | |
| 979 | input_set_capability(input_dev, EV_FF, FF_RUMBLE); |
| 980 | return input_ff_create_memless(input_dev, NULL, sony_play_effect); |
| 981 | } |
| 982 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 983 | static void sony_destroy_ff(struct hid_device *hdev) |
| 984 | { |
| 985 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 986 | |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 987 | cancel_work_sync(&sc->state_worker); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 988 | } |
| 989 | |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 990 | #else |
| 991 | static int sony_init_ff(struct hid_device *hdev) |
| 992 | { |
| 993 | return 0; |
| 994 | } |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 995 | |
| 996 | static void sony_destroy_ff(struct hid_device *hdev) |
| 997 | { |
| 998 | } |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 999 | #endif |
| 1000 | |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 1001 | static int sony_set_output_report(struct sony_sc *sc, int req_id, int req_size) |
| 1002 | { |
| 1003 | struct list_head *head, *list; |
| 1004 | struct hid_report *report; |
| 1005 | struct hid_device *hdev = sc->hdev; |
| 1006 | |
| 1007 | list = &hdev->report_enum[HID_OUTPUT_REPORT].report_list; |
| 1008 | |
| 1009 | list_for_each(head, list) { |
| 1010 | report = list_entry(head, struct hid_report, list); |
| 1011 | |
| 1012 | if (report->id == req_id) { |
| 1013 | if (report->size < req_size) { |
| 1014 | hid_err(hdev, "Output report 0x%02x (%i bits) is smaller than requested size (%i bits)\n", |
| 1015 | req_id, report->size, req_size); |
| 1016 | return -EINVAL; |
| 1017 | } |
| 1018 | sc->output_report = report; |
| 1019 | return 0; |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | hid_err(hdev, "Unable to locate output report 0x%02x\n", req_id); |
| 1024 | |
| 1025 | return -EINVAL; |
| 1026 | } |
| 1027 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1028 | static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 1029 | { |
| 1030 | int ret; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1031 | unsigned long quirks = id->driver_data; |
| 1032 | struct sony_sc *sc; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1033 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1034 | |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 1035 | sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1036 | if (sc == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 1037 | hid_err(hdev, "can't alloc sony descriptor\n"); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1038 | return -ENOMEM; |
| 1039 | } |
| 1040 | |
| 1041 | sc->quirks = quirks; |
| 1042 | hid_set_drvdata(hdev, sc); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1043 | sc->hdev = hdev; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1044 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1045 | ret = hid_parse(hdev); |
| 1046 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 1047 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 1048 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1051 | if (sc->quirks & VAIO_RDESC_CONSTANT) |
| 1052 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 1053 | else if (sc->quirks & SIXAXIS_CONTROLLER_USB) |
| 1054 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 1055 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) |
| 1056 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 1057 | |
| 1058 | ret = hid_hw_start(hdev, connect_mask); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1059 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 1060 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 1061 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 1064 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) { |
| 1065 | hdev->hid_output_raw_report = sixaxis_usb_output_raw_report; |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 1066 | ret = sixaxis_set_operational_usb(hdev); |
Frank Praznik | cad665a | 2014-01-11 15:13:54 -0500 | [diff] [blame] | 1067 | INIT_WORK(&sc->state_worker, sixaxis_state_worker); |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 1068 | } |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 1069 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) |
| 1070 | ret = sixaxis_set_operational_bt(hdev); |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 1071 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 1072 | /* Report 5 (31 bytes) is used to send data to the controller via USB */ |
| 1073 | ret = sony_set_output_report(sc, 0x05, 248); |
| 1074 | if (ret < 0) |
| 1075 | goto err_stop; |
| 1076 | |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 1077 | INIT_WORK(&sc->state_worker, dualshock4_state_worker); |
| 1078 | } else { |
| 1079 | ret = 0; |
| 1080 | } |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 1081 | |
Jiri Kosina | 4dfdc46 | 2008-12-30 00:49:59 +0100 | [diff] [blame] | 1082 | if (ret < 0) |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1083 | goto err_stop; |
| 1084 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1085 | if (sc->quirks & SONY_LED_SUPPORT) { |
| 1086 | ret = sony_leds_init(hdev); |
| 1087 | if (ret < 0) |
| 1088 | goto err_stop; |
| 1089 | } |
| 1090 | |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1091 | ret = sony_init_ff(hdev); |
| 1092 | if (ret < 0) |
| 1093 | goto err_stop; |
| 1094 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1095 | return 0; |
| 1096 | err_stop: |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1097 | if (sc->quirks & SONY_LED_SUPPORT) |
| 1098 | sony_leds_remove(hdev); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1099 | hid_hw_stop(hdev); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1100 | return ret; |
| 1101 | } |
| 1102 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1103 | static void sony_remove(struct hid_device *hdev) |
| 1104 | { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1105 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 1106 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1107 | if (sc->quirks & SONY_LED_SUPPORT) |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 1108 | sony_leds_remove(hdev); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1109 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1110 | sony_destroy_ff(hdev); |
| 1111 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1112 | hid_hw_stop(hdev); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1113 | } |
| 1114 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1115 | static const struct hid_device_id sony_devices[] = { |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 1116 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
| 1117 | .driver_data = SIXAXIS_CONTROLLER_USB }, |
Jiri Kosina | 35dca5b | 2011-04-28 15:43:13 +0200 | [diff] [blame] | 1118 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER), |
| 1119 | .driver_data = SIXAXIS_CONTROLLER_USB }, |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 1120 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
| 1121 | .driver_data = SIXAXIS_CONTROLLER_BT }, |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1122 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE), |
| 1123 | .driver_data = VAIO_RDESC_CONSTANT }, |
Fernando Luis Vázquez Cao | a4649184 | 2013-01-15 19:40:48 +0900 | [diff] [blame] | 1124 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE), |
| 1125 | .driver_data = VAIO_RDESC_CONSTANT }, |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1126 | /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as |
| 1127 | * Logitech joystick from the device descriptor. */ |
| 1128 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER), |
| 1129 | .driver_data = BUZZ_CONTROLLER }, |
| 1130 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER), |
| 1131 | .driver_data = BUZZ_CONTROLLER }, |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 1132 | /* PS3 BD Remote Control */ |
| 1133 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE), |
| 1134 | .driver_data = PS3REMOTE }, |
| 1135 | /* Logitech Harmony Adapter for PS3 */ |
| 1136 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3), |
| 1137 | .driver_data = PS3REMOTE }, |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 1138 | /* Sony Dualshock 4 controllers for PS4 */ |
| 1139 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER), |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 1140 | .driver_data = DUALSHOCK4_CONTROLLER_USB }, |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 1141 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER), |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 1142 | .driver_data = DUALSHOCK4_CONTROLLER_BT }, |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1143 | { } |
| 1144 | }; |
| 1145 | MODULE_DEVICE_TABLE(hid, sony_devices); |
| 1146 | |
| 1147 | static struct hid_driver sony_driver = { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1148 | .name = "sony", |
| 1149 | .id_table = sony_devices, |
| 1150 | .input_mapping = sony_mapping, |
| 1151 | .probe = sony_probe, |
| 1152 | .remove = sony_remove, |
| 1153 | .report_fixup = sony_report_fixup, |
| 1154 | .raw_event = sony_raw_event |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1155 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 1156 | module_hid_driver(sony_driver); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1157 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1158 | MODULE_LICENSE("GPL"); |