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