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