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