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