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