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