Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1 | /* |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 2 | * HID driver for Sony / PS2 / PS3 BD devices. |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 1999 Andreas Gal |
| 5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 7 | * Copyright (c) 2008 Jiri Slaby |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 8 | * Copyright (c) 2012 David Dillow <dave@thedillows.org> |
| 9 | * Copyright (c) 2006-2013 Jiri Kosina |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 10 | * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * This program is free software; you can redistribute it and/or modify it |
| 15 | * under the terms of the GNU General Public License as published by the Free |
| 16 | * Software Foundation; either version 2 of the License, or (at your option) |
| 17 | * any later version. |
| 18 | */ |
| 19 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 20 | /* NOTE: in order for the Sony PS3 BD Remote Control to be found by |
| 21 | * a Bluetooth host, the key combination Start+Enter has to be kept pressed |
| 22 | * for about 7 seconds with the Bluetooth Host Controller in discovering mode. |
| 23 | * |
| 24 | * There will be no PIN request from the device. |
| 25 | */ |
| 26 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 27 | #include <linux/device.h> |
| 28 | #include <linux/hid.h> |
| 29 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 31 | #include <linux/usb.h> |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 32 | #include <linux/leds.h> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 33 | |
| 34 | #include "hid-ids.h" |
| 35 | |
Sven Eckelmann | f1c458c | 2013-11-19 20:26:29 +0100 | [diff] [blame] | 36 | #define VAIO_RDESC_CONSTANT BIT(0) |
| 37 | #define SIXAXIS_CONTROLLER_USB BIT(1) |
| 38 | #define SIXAXIS_CONTROLLER_BT BIT(2) |
| 39 | #define BUZZ_CONTROLLER BIT(3) |
| 40 | #define PS3REMOTE BIT(4) |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 41 | |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 42 | static const u8 sixaxis_rdesc_fixup[] = { |
| 43 | 0x95, 0x13, 0x09, 0x01, 0x81, 0x02, 0x95, 0x0C, |
| 44 | 0x81, 0x01, 0x75, 0x10, 0x95, 0x04, 0x26, 0xFF, |
| 45 | 0x03, 0x46, 0xFF, 0x03, 0x09, 0x01, 0x81, 0x02 |
| 46 | }; |
| 47 | |
Mauro Carvalho Chehab | e57a67d | 2012-12-14 20:57:34 -0200 | [diff] [blame] | 48 | static const u8 sixaxis_rdesc_fixup2[] = { |
| 49 | 0x05, 0x01, 0x09, 0x04, 0xa1, 0x01, 0xa1, 0x02, |
| 50 | 0x85, 0x01, 0x75, 0x08, 0x95, 0x01, 0x15, 0x00, |
| 51 | 0x26, 0xff, 0x00, 0x81, 0x03, 0x75, 0x01, 0x95, |
| 52 | 0x13, 0x15, 0x00, 0x25, 0x01, 0x35, 0x00, 0x45, |
| 53 | 0x01, 0x05, 0x09, 0x19, 0x01, 0x29, 0x13, 0x81, |
| 54 | 0x02, 0x75, 0x01, 0x95, 0x0d, 0x06, 0x00, 0xff, |
| 55 | 0x81, 0x03, 0x15, 0x00, 0x26, 0xff, 0x00, 0x05, |
| 56 | 0x01, 0x09, 0x01, 0xa1, 0x00, 0x75, 0x08, 0x95, |
| 57 | 0x04, 0x35, 0x00, 0x46, 0xff, 0x00, 0x09, 0x30, |
| 58 | 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x81, 0x02, |
| 59 | 0xc0, 0x05, 0x01, 0x95, 0x13, 0x09, 0x01, 0x81, |
| 60 | 0x02, 0x95, 0x0c, 0x81, 0x01, 0x75, 0x10, 0x95, |
| 61 | 0x04, 0x26, 0xff, 0x03, 0x46, 0xff, 0x03, 0x09, |
| 62 | 0x01, 0x81, 0x02, 0xc0, 0xa1, 0x02, 0x85, 0x02, |
| 63 | 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, 0xb1, 0x02, |
| 64 | 0xc0, 0xa1, 0x02, 0x85, 0xee, 0x75, 0x08, 0x95, |
| 65 | 0x30, 0x09, 0x01, 0xb1, 0x02, 0xc0, 0xa1, 0x02, |
| 66 | 0x85, 0xef, 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, |
| 67 | 0xb1, 0x02, 0xc0, 0xc0, |
| 68 | }; |
| 69 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 70 | static __u8 ps3remote_rdesc[] = { |
| 71 | 0x05, 0x01, /* GUsagePage Generic Desktop */ |
| 72 | 0x09, 0x05, /* LUsage 0x05 [Game Pad] */ |
| 73 | 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */ |
| 74 | |
| 75 | /* Use collection 1 for joypad buttons */ |
| 76 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ |
| 77 | |
| 78 | /* Ignore the 1st byte, maybe it is used for a controller |
| 79 | * number but it's not needed for correct operation */ |
| 80 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 81 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 82 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ |
| 83 | |
| 84 | /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these |
| 85 | * buttons multiple keypresses are allowed */ |
| 86 | 0x05, 0x09, /* GUsagePage Button */ |
| 87 | 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */ |
| 88 | 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */ |
| 89 | 0x14, /* GLogicalMinimum [0] */ |
| 90 | 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */ |
| 91 | 0x75, 0x01, /* GReportSize 0x01 [1] */ |
| 92 | 0x95, 0x18, /* GReportCount 0x18 [24] */ |
| 93 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ |
| 94 | |
| 95 | 0xC0, /* MEndCollection */ |
| 96 | |
| 97 | /* Use collection 2 for remote control buttons */ |
| 98 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ |
| 99 | |
| 100 | /* 5th byte is used for remote control buttons */ |
| 101 | 0x05, 0x09, /* GUsagePage Button */ |
| 102 | 0x18, /* LUsageMinimum [No button pressed] */ |
| 103 | 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */ |
| 104 | 0x14, /* GLogicalMinimum [0] */ |
| 105 | 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */ |
| 106 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 107 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 108 | 0x80, /* MInput */ |
| 109 | |
| 110 | /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at |
| 111 | * 0xff and 11th is for press indication */ |
| 112 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 113 | 0x95, 0x06, /* GReportCount 0x06 [6] */ |
| 114 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ |
| 115 | |
| 116 | /* 12th byte is for battery strength */ |
| 117 | 0x05, 0x06, /* GUsagePage Generic Device Controls */ |
| 118 | 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */ |
| 119 | 0x14, /* GLogicalMinimum [0] */ |
| 120 | 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */ |
| 121 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 122 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 123 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ |
| 124 | |
| 125 | 0xC0, /* MEndCollection */ |
| 126 | |
| 127 | 0xC0 /* MEndCollection [Game Pad] */ |
| 128 | }; |
| 129 | |
| 130 | static const unsigned int ps3remote_keymap_joypad_buttons[] = { |
| 131 | [0x01] = KEY_SELECT, |
| 132 | [0x02] = BTN_THUMBL, /* L3 */ |
| 133 | [0x03] = BTN_THUMBR, /* R3 */ |
| 134 | [0x04] = BTN_START, |
| 135 | [0x05] = KEY_UP, |
| 136 | [0x06] = KEY_RIGHT, |
| 137 | [0x07] = KEY_DOWN, |
| 138 | [0x08] = KEY_LEFT, |
| 139 | [0x09] = BTN_TL2, /* L2 */ |
| 140 | [0x0a] = BTN_TR2, /* R2 */ |
| 141 | [0x0b] = BTN_TL, /* L1 */ |
| 142 | [0x0c] = BTN_TR, /* R1 */ |
| 143 | [0x0d] = KEY_OPTION, /* options/triangle */ |
| 144 | [0x0e] = KEY_BACK, /* back/circle */ |
| 145 | [0x0f] = BTN_0, /* cross */ |
| 146 | [0x10] = KEY_SCREEN, /* view/square */ |
| 147 | [0x11] = KEY_HOMEPAGE, /* PS button */ |
| 148 | [0x14] = KEY_ENTER, |
| 149 | }; |
| 150 | static const unsigned int ps3remote_keymap_remote_buttons[] = { |
| 151 | [0x00] = KEY_1, |
| 152 | [0x01] = KEY_2, |
| 153 | [0x02] = KEY_3, |
| 154 | [0x03] = KEY_4, |
| 155 | [0x04] = KEY_5, |
| 156 | [0x05] = KEY_6, |
| 157 | [0x06] = KEY_7, |
| 158 | [0x07] = KEY_8, |
| 159 | [0x08] = KEY_9, |
| 160 | [0x09] = KEY_0, |
| 161 | [0x0e] = KEY_ESC, /* return */ |
| 162 | [0x0f] = KEY_CLEAR, |
| 163 | [0x16] = KEY_EJECTCD, |
| 164 | [0x1a] = KEY_MENU, /* top menu */ |
| 165 | [0x28] = KEY_TIME, |
| 166 | [0x30] = KEY_PREVIOUS, |
| 167 | [0x31] = KEY_NEXT, |
| 168 | [0x32] = KEY_PLAY, |
| 169 | [0x33] = KEY_REWIND, /* scan back */ |
| 170 | [0x34] = KEY_FORWARD, /* scan forward */ |
| 171 | [0x38] = KEY_STOP, |
| 172 | [0x39] = KEY_PAUSE, |
| 173 | [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */ |
| 174 | [0x60] = KEY_FRAMEBACK, /* slow/step back */ |
| 175 | [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */ |
| 176 | [0x63] = KEY_SUBTITLE, |
| 177 | [0x64] = KEY_AUDIO, |
| 178 | [0x65] = KEY_ANGLE, |
| 179 | [0x70] = KEY_INFO, /* display */ |
| 180 | [0x80] = KEY_BLUE, |
| 181 | [0x81] = KEY_RED, |
| 182 | [0x82] = KEY_GREEN, |
| 183 | [0x83] = KEY_YELLOW, |
| 184 | }; |
| 185 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 186 | static const unsigned int buzz_keymap[] = { |
| 187 | /* The controller has 4 remote buzzers, each with one LED and 5 |
| 188 | * buttons. |
| 189 | * |
| 190 | * We use the mapping chosen by the controller, which is: |
| 191 | * |
| 192 | * Key Offset |
| 193 | * ------------------- |
| 194 | * Buzz 1 |
| 195 | * Blue 5 |
| 196 | * Orange 4 |
| 197 | * Green 3 |
| 198 | * Yellow 2 |
| 199 | * |
| 200 | * So, for example, the orange button on the third buzzer is mapped to |
| 201 | * BTN_TRIGGER_HAPPY14 |
| 202 | */ |
| 203 | [ 1] = BTN_TRIGGER_HAPPY1, |
| 204 | [ 2] = BTN_TRIGGER_HAPPY2, |
| 205 | [ 3] = BTN_TRIGGER_HAPPY3, |
| 206 | [ 4] = BTN_TRIGGER_HAPPY4, |
| 207 | [ 5] = BTN_TRIGGER_HAPPY5, |
| 208 | [ 6] = BTN_TRIGGER_HAPPY6, |
| 209 | [ 7] = BTN_TRIGGER_HAPPY7, |
| 210 | [ 8] = BTN_TRIGGER_HAPPY8, |
| 211 | [ 9] = BTN_TRIGGER_HAPPY9, |
| 212 | [10] = BTN_TRIGGER_HAPPY10, |
| 213 | [11] = BTN_TRIGGER_HAPPY11, |
| 214 | [12] = BTN_TRIGGER_HAPPY12, |
| 215 | [13] = BTN_TRIGGER_HAPPY13, |
| 216 | [14] = BTN_TRIGGER_HAPPY14, |
| 217 | [15] = BTN_TRIGGER_HAPPY15, |
| 218 | [16] = BTN_TRIGGER_HAPPY16, |
| 219 | [17] = BTN_TRIGGER_HAPPY17, |
| 220 | [18] = BTN_TRIGGER_HAPPY18, |
| 221 | [19] = BTN_TRIGGER_HAPPY19, |
| 222 | [20] = BTN_TRIGGER_HAPPY20, |
| 223 | }; |
| 224 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 225 | struct sony_sc { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 226 | struct led_classdev *leds[4]; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 227 | unsigned long quirks; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 228 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 229 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 230 | struct work_struct state_worker; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 231 | struct hid_device *hdev; |
| 232 | __u8 left; |
| 233 | __u8 right; |
| 234 | #endif |
| 235 | |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 236 | __u8 led_state; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 237 | }; |
| 238 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 239 | static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 240 | unsigned int *rsize) |
| 241 | { |
| 242 | *rsize = sizeof(ps3remote_rdesc); |
| 243 | return ps3remote_rdesc; |
| 244 | } |
| 245 | |
| 246 | static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 247 | struct hid_field *field, struct hid_usage *usage, |
| 248 | unsigned long **bit, int *max) |
| 249 | { |
| 250 | unsigned int key = usage->hid & HID_USAGE; |
| 251 | |
| 252 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| 253 | return -1; |
| 254 | |
| 255 | switch (usage->collection_index) { |
| 256 | case 1: |
| 257 | if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons)) |
| 258 | return -1; |
| 259 | |
| 260 | key = ps3remote_keymap_joypad_buttons[key]; |
| 261 | if (!key) |
| 262 | return -1; |
| 263 | break; |
| 264 | case 2: |
| 265 | if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons)) |
| 266 | return -1; |
| 267 | |
| 268 | key = ps3remote_keymap_remote_buttons[key]; |
| 269 | if (!key) |
| 270 | return -1; |
| 271 | break; |
| 272 | default: |
| 273 | return -1; |
| 274 | } |
| 275 | |
| 276 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); |
| 277 | return 1; |
| 278 | } |
| 279 | |
| 280 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 281 | /* Sony Vaio VGX has wrongly mouse pointer declared as constant */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 282 | static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 283 | unsigned int *rsize) |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 284 | { |
| 285 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 286 | |
Fernando Luis Vázquez Cao | 99d2490 | 2013-01-22 15:20:38 +0900 | [diff] [blame] | 287 | /* |
| 288 | * Some Sony RF receivers wrongly declare the mouse pointer as a |
| 289 | * a constant non-data variable. |
| 290 | */ |
| 291 | if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 && |
| 292 | /* usage page: generic desktop controls */ |
| 293 | /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */ |
| 294 | /* usage: mouse */ |
| 295 | rdesc[2] == 0x09 && rdesc[3] == 0x02 && |
| 296 | /* input (usage page for x,y axes): constant, variable, relative */ |
| 297 | rdesc[54] == 0x81 && rdesc[55] == 0x07) { |
Fernando Luis Vázquez Cao | a464918 | 2013-01-15 19:40:48 +0900 | [diff] [blame] | 298 | 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] | 299 | /* input: data, variable, relative */ |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 300 | rdesc[55] = 0x06; |
| 301 | } |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 302 | |
| 303 | /* The HID descriptor exposed over BT has a trailing zero byte */ |
| 304 | if ((((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize == 148) || |
| 305 | ((sc->quirks & SIXAXIS_CONTROLLER_BT) && *rsize == 149)) && |
| 306 | rdesc[83] == 0x75) { |
| 307 | hid_info(hdev, "Fixing up Sony Sixaxis report descriptor\n"); |
| 308 | memcpy((void *)&rdesc[83], (void *)&sixaxis_rdesc_fixup, |
| 309 | sizeof(sixaxis_rdesc_fixup)); |
Mauro Carvalho Chehab | e57a67d | 2012-12-14 20:57:34 -0200 | [diff] [blame] | 310 | } else if (sc->quirks & SIXAXIS_CONTROLLER_USB && |
| 311 | *rsize > sizeof(sixaxis_rdesc_fixup2)) { |
| 312 | hid_info(hdev, "Sony Sixaxis clone detected. Using original report descriptor (size: %d clone; %d new)\n", |
| 313 | *rsize, (int)sizeof(sixaxis_rdesc_fixup2)); |
| 314 | *rsize = sizeof(sixaxis_rdesc_fixup2); |
| 315 | memcpy(rdesc, &sixaxis_rdesc_fixup2, *rsize); |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 316 | } |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 317 | |
| 318 | if (sc->quirks & PS3REMOTE) |
| 319 | return ps3remote_fixup(hdev, rdesc, rsize); |
| 320 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 321 | return rdesc; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Simon Wood | c9e4d87 | 2011-06-10 12:00:27 +0200 | [diff] [blame] | 324 | static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 325 | __u8 *rd, int size) |
| 326 | { |
| 327 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 328 | |
| 329 | /* Sixaxis HID report has acclerometers/gyro with MSByte first, this |
| 330 | * has to be BYTE_SWAPPED before passing up to joystick interface |
| 331 | */ |
| 332 | if ((sc->quirks & (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)) && |
| 333 | rd[0] == 0x01 && size == 49) { |
| 334 | swap(rd[41], rd[42]); |
| 335 | swap(rd[43], rd[44]); |
| 336 | swap(rd[45], rd[46]); |
| 337 | swap(rd[47], rd[48]); |
| 338 | } |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 343 | static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 344 | struct hid_field *field, struct hid_usage *usage, |
| 345 | unsigned long **bit, int *max) |
| 346 | { |
| 347 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 348 | |
| 349 | if (sc->quirks & BUZZ_CONTROLLER) { |
| 350 | unsigned int key = usage->hid & HID_USAGE; |
| 351 | |
| 352 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| 353 | return -1; |
| 354 | |
| 355 | switch (usage->collection_index) { |
| 356 | case 1: |
| 357 | if (key >= ARRAY_SIZE(buzz_keymap)) |
| 358 | return -1; |
| 359 | |
| 360 | key = buzz_keymap[key]; |
| 361 | if (!key) |
| 362 | return -1; |
| 363 | break; |
| 364 | default: |
| 365 | return -1; |
| 366 | } |
| 367 | |
| 368 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); |
| 369 | return 1; |
| 370 | } |
| 371 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 372 | if (sc->quirks & PS3REMOTE) |
| 373 | return ps3remote_mapping(hdev, hi, field, usage, bit, max); |
| 374 | |
Benjamin Tissoires | 6f49801 | 2013-07-24 16:53:07 +0200 | [diff] [blame] | 375 | /* Let hid-core decide for the others */ |
| 376 | return 0; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 377 | } |
| 378 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 379 | /* |
| 380 | * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP |
| 381 | * like it should according to usbhid/hid-core.c::usbhid_output_raw_report() |
| 382 | * so we need to override that forcing HID Output Reports on the Control EP. |
| 383 | * |
| 384 | * There is also another issue about HID Output Reports via USB, the Sixaxis |
| 385 | * does not want the report_id as part of the data packet, so we have to |
| 386 | * discard buf[0] when sending the actual control message, even for numbered |
| 387 | * reports, humpf! |
| 388 | */ |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 389 | static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf, |
| 390 | size_t count, unsigned char report_type) |
| 391 | { |
| 392 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); |
| 393 | struct usb_device *dev = interface_to_usbdev(intf); |
| 394 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 395 | int report_id = buf[0]; |
| 396 | int ret; |
| 397 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 398 | if (report_type == HID_OUTPUT_REPORT) { |
| 399 | /* Don't send the Report ID */ |
| 400 | buf++; |
| 401 | count--; |
| 402 | } |
| 403 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 404 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 405 | HID_REQ_SET_REPORT, |
| 406 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 407 | ((report_type + 1) << 8) | report_id, |
| 408 | interface->desc.bInterfaceNumber, buf, count, |
| 409 | USB_CTRL_SET_TIMEOUT); |
| 410 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 411 | /* Count also the Report ID, in case of an Output report. */ |
| 412 | if (ret > 0 && report_type == HID_OUTPUT_REPORT) |
| 413 | ret++; |
| 414 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 415 | return ret; |
| 416 | } |
| 417 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 418 | /* |
| 419 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
| 420 | * to "operational". Without this, the ps3 controller will not report any |
| 421 | * events. |
| 422 | */ |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 423 | static int sixaxis_set_operational_usb(struct hid_device *hdev) |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 424 | { |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 425 | int ret; |
| 426 | char *buf = kmalloc(18, GFP_KERNEL); |
| 427 | |
| 428 | if (!buf) |
| 429 | return -ENOMEM; |
| 430 | |
Benjamin Tissoires | f204828a | 2013-09-11 22:12:25 +0200 | [diff] [blame] | 431 | ret = hdev->hid_get_raw_report(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT); |
| 432 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 433 | if (ret < 0) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 434 | hid_err(hdev, "can't set operational mode\n"); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 435 | |
| 436 | kfree(buf); |
| 437 | |
| 438 | return ret; |
| 439 | } |
| 440 | |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 441 | static int sixaxis_set_operational_bt(struct hid_device *hdev) |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 442 | { |
Antonio Ospite | fddb33f | 2010-05-03 17:19:03 +0200 | [diff] [blame] | 443 | unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 444 | return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); |
| 445 | } |
| 446 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 447 | static void buzz_set_leds(struct hid_device *hdev, int leds) |
| 448 | { |
| 449 | struct list_head *report_list = |
| 450 | &hdev->report_enum[HID_OUTPUT_REPORT].report_list; |
| 451 | struct hid_report *report = list_entry(report_list->next, |
| 452 | struct hid_report, list); |
| 453 | __s32 *value = report->field[0]->value; |
| 454 | |
| 455 | value[0] = 0x00; |
| 456 | value[1] = (leds & 1) ? 0xff : 0x00; |
| 457 | value[2] = (leds & 2) ? 0xff : 0x00; |
| 458 | value[3] = (leds & 4) ? 0xff : 0x00; |
| 459 | value[4] = (leds & 8) ? 0xff : 0x00; |
| 460 | value[5] = 0x00; |
| 461 | value[6] = 0x00; |
| 462 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
| 463 | } |
| 464 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 465 | static void sony_led_set_brightness(struct led_classdev *led, |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 466 | enum led_brightness value) |
| 467 | { |
| 468 | struct device *dev = led->dev->parent; |
| 469 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 470 | struct sony_sc *drv_data; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 471 | |
| 472 | int n; |
| 473 | |
| 474 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 475 | if (!drv_data) { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 476 | hid_err(hdev, "No device data\n"); |
| 477 | return; |
| 478 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 479 | |
| 480 | for (n = 0; n < 4; n++) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 481 | if (led == drv_data->leds[n]) { |
| 482 | int on = !!(drv_data->led_state & (1 << n)); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 483 | if (value == LED_OFF && on) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 484 | drv_data->led_state &= ~(1 << n); |
| 485 | buzz_set_leds(hdev, drv_data->led_state); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 486 | } else if (value != LED_OFF && !on) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 487 | drv_data->led_state |= (1 << n); |
| 488 | buzz_set_leds(hdev, drv_data->led_state); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 489 | } |
| 490 | break; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 495 | static enum led_brightness sony_led_get_brightness(struct led_classdev *led) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 496 | { |
| 497 | struct device *dev = led->dev->parent; |
| 498 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 499 | struct sony_sc *drv_data; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 500 | |
| 501 | int n; |
| 502 | int on = 0; |
| 503 | |
| 504 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 505 | if (!drv_data) { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 506 | hid_err(hdev, "No device data\n"); |
| 507 | return LED_OFF; |
| 508 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 509 | |
| 510 | for (n = 0; n < 4; n++) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 511 | if (led == drv_data->leds[n]) { |
| 512 | on = !!(drv_data->led_state & (1 << n)); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 513 | break; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | return on ? LED_FULL : LED_OFF; |
| 518 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 519 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 520 | static int sony_leds_init(struct hid_device *hdev) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 521 | { |
| 522 | struct sony_sc *drv_data; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 523 | int n, ret = 0; |
| 524 | struct led_classdev *led; |
| 525 | size_t name_sz; |
| 526 | char *name; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 527 | |
| 528 | drv_data = hid_get_drvdata(hdev); |
| 529 | BUG_ON(!(drv_data->quirks & BUZZ_CONTROLLER)); |
| 530 | |
Kees Cook | 9446edb | 2013-09-11 21:56:52 +0200 | [diff] [blame] | 531 | /* Validate expected report characteristics. */ |
| 532 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) |
| 533 | return -ENODEV; |
| 534 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 535 | /* Clear LEDs as we have no way of reading their initial state. This is |
| 536 | * only relevant if the driver is loaded after somebody actively set the |
| 537 | * LEDs to on */ |
| 538 | buzz_set_leds(hdev, 0x00); |
| 539 | |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 540 | name_sz = strlen(dev_name(&hdev->dev)) + strlen("::buzz#") + 1; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 541 | |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 542 | for (n = 0; n < 4; n++) { |
| 543 | led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); |
| 544 | if (!led) { |
| 545 | hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); |
| 546 | goto error_leds; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 547 | } |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 548 | |
| 549 | name = (void *)(&led[1]); |
| 550 | snprintf(name, name_sz, "%s::buzz%d", dev_name(&hdev->dev), n + 1); |
| 551 | led->name = name; |
| 552 | led->brightness = 0; |
| 553 | led->max_brightness = 1; |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 554 | led->brightness_get = sony_led_get_brightness; |
| 555 | led->brightness_set = sony_led_set_brightness; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 556 | |
| 557 | if (led_classdev_register(&hdev->dev, led)) { |
| 558 | hid_err(hdev, "Failed to register LED %d\n", n); |
| 559 | kfree(led); |
| 560 | goto error_leds; |
| 561 | } |
| 562 | |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 563 | drv_data->leds[n] = led; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 564 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 565 | |
| 566 | return ret; |
| 567 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 568 | error_leds: |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 569 | for (n = 0; n < 4; n++) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 570 | led = drv_data->leds[n]; |
| 571 | drv_data->leds[n] = NULL; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 572 | if (!led) |
| 573 | continue; |
| 574 | led_classdev_unregister(led); |
| 575 | kfree(led); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 576 | } |
| 577 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 578 | return ret; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 579 | } |
| 580 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 581 | static void sony_leds_remove(struct hid_device *hdev) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 582 | { |
| 583 | struct sony_sc *drv_data; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 584 | struct led_classdev *led; |
| 585 | int n; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 586 | |
| 587 | drv_data = hid_get_drvdata(hdev); |
| 588 | BUG_ON(!(drv_data->quirks & BUZZ_CONTROLLER)); |
| 589 | |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 590 | for (n = 0; n < 4; n++) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame^] | 591 | led = drv_data->leds[n]; |
| 592 | drv_data->leds[n] = NULL; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 593 | if (!led) |
| 594 | continue; |
| 595 | led_classdev_unregister(led); |
| 596 | kfree(led); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 597 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 600 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 601 | static void sony_state_worker(struct work_struct *work) |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 602 | { |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 603 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 604 | unsigned char buf[] = { |
| 605 | 0x01, |
| 606 | 0x00, 0xff, 0x00, 0xff, 0x00, |
| 607 | 0x00, 0x00, 0x00, 0x00, 0x03, |
| 608 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 609 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 610 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 611 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 612 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 613 | }; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 614 | |
| 615 | buf[3] = sc->right; |
| 616 | buf[5] = sc->left; |
| 617 | |
| 618 | sc->hdev->hid_output_raw_report(sc->hdev, buf, sizeof(buf), |
| 619 | HID_OUTPUT_REPORT); |
| 620 | } |
| 621 | |
| 622 | static int sony_play_effect(struct input_dev *dev, void *data, |
| 623 | struct ff_effect *effect) |
| 624 | { |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 625 | struct hid_device *hid = input_get_drvdata(dev); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 626 | struct sony_sc *sc = hid_get_drvdata(hid); |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 627 | |
| 628 | if (effect->type != FF_RUMBLE) |
| 629 | return 0; |
| 630 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 631 | sc->left = effect->u.rumble.strong_magnitude / 256; |
| 632 | sc->right = effect->u.rumble.weak_magnitude ? 1 : 0; |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 633 | |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 634 | schedule_work(&sc->state_worker); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 635 | return 0; |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static int sony_init_ff(struct hid_device *hdev) |
| 639 | { |
| 640 | struct hid_input *hidinput = list_entry(hdev->inputs.next, |
| 641 | struct hid_input, list); |
| 642 | struct input_dev *input_dev = hidinput->input; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 643 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 644 | |
| 645 | sc->hdev = hdev; |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 646 | INIT_WORK(&sc->state_worker, sony_state_worker); |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 647 | |
| 648 | input_set_capability(input_dev, EV_FF, FF_RUMBLE); |
| 649 | return input_ff_create_memless(input_dev, NULL, sony_play_effect); |
| 650 | } |
| 651 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 652 | static void sony_destroy_ff(struct hid_device *hdev) |
| 653 | { |
| 654 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 655 | |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 656 | cancel_work_sync(&sc->state_worker); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 657 | } |
| 658 | |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 659 | #else |
| 660 | static int sony_init_ff(struct hid_device *hdev) |
| 661 | { |
| 662 | return 0; |
| 663 | } |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 664 | |
| 665 | static void sony_destroy_ff(struct hid_device *hdev) |
| 666 | { |
| 667 | } |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 668 | #endif |
| 669 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 670 | static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 671 | { |
| 672 | int ret; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 673 | unsigned long quirks = id->driver_data; |
| 674 | struct sony_sc *sc; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 675 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 676 | |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 677 | sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 678 | if (sc == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 679 | hid_err(hdev, "can't alloc sony descriptor\n"); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 680 | return -ENOMEM; |
| 681 | } |
| 682 | |
| 683 | sc->quirks = quirks; |
| 684 | hid_set_drvdata(hdev, sc); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 685 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 686 | ret = hid_parse(hdev); |
| 687 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 688 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 689 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 690 | } |
| 691 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 692 | if (sc->quirks & VAIO_RDESC_CONSTANT) |
| 693 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 694 | else if (sc->quirks & SIXAXIS_CONTROLLER_USB) |
| 695 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 696 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) |
| 697 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 698 | |
| 699 | ret = hid_hw_start(hdev, connect_mask); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 700 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 701 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 702 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 703 | } |
| 704 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 705 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) { |
| 706 | hdev->hid_output_raw_report = sixaxis_usb_output_raw_report; |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 707 | ret = sixaxis_set_operational_usb(hdev); |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 708 | } |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 709 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) |
| 710 | ret = sixaxis_set_operational_bt(hdev); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 711 | else if (sc->quirks & BUZZ_CONTROLLER) |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 712 | ret = sony_leds_init(hdev); |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 713 | else |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 714 | ret = 0; |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 715 | |
Jiri Kosina | 4dfdc46 | 2008-12-30 00:49:59 +0100 | [diff] [blame] | 716 | if (ret < 0) |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 717 | goto err_stop; |
| 718 | |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 719 | ret = sony_init_ff(hdev); |
| 720 | if (ret < 0) |
| 721 | goto err_stop; |
| 722 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 723 | return 0; |
| 724 | err_stop: |
| 725 | hid_hw_stop(hdev); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 726 | return ret; |
| 727 | } |
| 728 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 729 | static void sony_remove(struct hid_device *hdev) |
| 730 | { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 731 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 732 | |
| 733 | if (sc->quirks & BUZZ_CONTROLLER) |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 734 | sony_leds_remove(hdev); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 735 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 736 | sony_destroy_ff(hdev); |
| 737 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 738 | hid_hw_stop(hdev); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 739 | } |
| 740 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 741 | static const struct hid_device_id sony_devices[] = { |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 742 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
| 743 | .driver_data = SIXAXIS_CONTROLLER_USB }, |
Jiri Kosina | 35dca5b | 2011-04-28 15:43:13 +0200 | [diff] [blame] | 744 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER), |
| 745 | .driver_data = SIXAXIS_CONTROLLER_USB }, |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 746 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
| 747 | .driver_data = SIXAXIS_CONTROLLER_BT }, |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 748 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE), |
| 749 | .driver_data = VAIO_RDESC_CONSTANT }, |
Fernando Luis Vázquez Cao | a464918 | 2013-01-15 19:40:48 +0900 | [diff] [blame] | 750 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE), |
| 751 | .driver_data = VAIO_RDESC_CONSTANT }, |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 752 | /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as |
| 753 | * Logitech joystick from the device descriptor. */ |
| 754 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER), |
| 755 | .driver_data = BUZZ_CONTROLLER }, |
| 756 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER), |
| 757 | .driver_data = BUZZ_CONTROLLER }, |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 758 | /* PS3 BD Remote Control */ |
| 759 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE), |
| 760 | .driver_data = PS3REMOTE }, |
| 761 | /* Logitech Harmony Adapter for PS3 */ |
| 762 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3), |
| 763 | .driver_data = PS3REMOTE }, |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 764 | { } |
| 765 | }; |
| 766 | MODULE_DEVICE_TABLE(hid, sony_devices); |
| 767 | |
| 768 | static struct hid_driver sony_driver = { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 769 | .name = "sony", |
| 770 | .id_table = sony_devices, |
| 771 | .input_mapping = sony_mapping, |
| 772 | .probe = sony_probe, |
| 773 | .remove = sony_remove, |
| 774 | .report_fixup = sony_report_fixup, |
| 775 | .raw_event = sony_raw_event |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 776 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 777 | module_hid_driver(sony_driver); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 778 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 779 | MODULE_LICENSE("GPL"); |