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