2 * HID driver for Sony / PS2 / PS3 BD devices.
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
7 * Copyright (c) 2008 Jiri Slaby
8 * Copyright (c) 2012 David Dillow <dave@thedillows.org>
9 * Copyright (c) 2006-2013 Jiri Kosina
10 * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com>
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)
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.
24 * There will be no PIN request from the device.
27 #include <linux/device.h>
28 #include <linux/hid.h>
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/usb.h>
32 #include <linux/leds.h>
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)
41 #define DUALSHOCK4_CONTROLLER BIT(5)
43 #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER)
45 static const u8 sixaxis_rdesc_fixup[] = {
46 0x95, 0x13, 0x09, 0x01, 0x81, 0x02, 0x95, 0x0C,
47 0x81, 0x01, 0x75, 0x10, 0x95, 0x04, 0x26, 0xFF,
48 0x03, 0x46, 0xFF, 0x03, 0x09, 0x01, 0x81, 0x02
51 static const u8 sixaxis_rdesc_fixup2[] = {
52 0x05, 0x01, 0x09, 0x04, 0xa1, 0x01, 0xa1, 0x02,
53 0x85, 0x01, 0x75, 0x08, 0x95, 0x01, 0x15, 0x00,
54 0x26, 0xff, 0x00, 0x81, 0x03, 0x75, 0x01, 0x95,
55 0x13, 0x15, 0x00, 0x25, 0x01, 0x35, 0x00, 0x45,
56 0x01, 0x05, 0x09, 0x19, 0x01, 0x29, 0x13, 0x81,
57 0x02, 0x75, 0x01, 0x95, 0x0d, 0x06, 0x00, 0xff,
58 0x81, 0x03, 0x15, 0x00, 0x26, 0xff, 0x00, 0x05,
59 0x01, 0x09, 0x01, 0xa1, 0x00, 0x75, 0x08, 0x95,
60 0x04, 0x35, 0x00, 0x46, 0xff, 0x00, 0x09, 0x30,
61 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x81, 0x02,
62 0xc0, 0x05, 0x01, 0x95, 0x13, 0x09, 0x01, 0x81,
63 0x02, 0x95, 0x0c, 0x81, 0x01, 0x75, 0x10, 0x95,
64 0x04, 0x26, 0xff, 0x03, 0x46, 0xff, 0x03, 0x09,
65 0x01, 0x81, 0x02, 0xc0, 0xa1, 0x02, 0x85, 0x02,
66 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, 0xb1, 0x02,
67 0xc0, 0xa1, 0x02, 0x85, 0xee, 0x75, 0x08, 0x95,
68 0x30, 0x09, 0x01, 0xb1, 0x02, 0xc0, 0xa1, 0x02,
69 0x85, 0xef, 0x75, 0x08, 0x95, 0x30, 0x09, 0x01,
70 0xb1, 0x02, 0xc0, 0xc0,
73 static __u8 ps3remote_rdesc[] = {
74 0x05, 0x01, /* GUsagePage Generic Desktop */
75 0x09, 0x05, /* LUsage 0x05 [Game Pad] */
76 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */
78 /* Use collection 1 for joypad buttons */
79 0xA1, 0x02, /* MCollection Logical (interrelated data) */
81 /* Ignore the 1st byte, maybe it is used for a controller
82 * number but it's not needed for correct operation */
83 0x75, 0x08, /* GReportSize 0x08 [8] */
84 0x95, 0x01, /* GReportCount 0x01 [1] */
85 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
87 /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these
88 * buttons multiple keypresses are allowed */
89 0x05, 0x09, /* GUsagePage Button */
90 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */
91 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */
92 0x14, /* GLogicalMinimum [0] */
93 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */
94 0x75, 0x01, /* GReportSize 0x01 [1] */
95 0x95, 0x18, /* GReportCount 0x18 [24] */
96 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
98 0xC0, /* MEndCollection */
100 /* Use collection 2 for remote control buttons */
101 0xA1, 0x02, /* MCollection Logical (interrelated data) */
103 /* 5th byte is used for remote control buttons */
104 0x05, 0x09, /* GUsagePage Button */
105 0x18, /* LUsageMinimum [No button pressed] */
106 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */
107 0x14, /* GLogicalMinimum [0] */
108 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */
109 0x75, 0x08, /* GReportSize 0x08 [8] */
110 0x95, 0x01, /* GReportCount 0x01 [1] */
113 /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at
114 * 0xff and 11th is for press indication */
115 0x75, 0x08, /* GReportSize 0x08 [8] */
116 0x95, 0x06, /* GReportCount 0x06 [6] */
117 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
119 /* 12th byte is for battery strength */
120 0x05, 0x06, /* GUsagePage Generic Device Controls */
121 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */
122 0x14, /* GLogicalMinimum [0] */
123 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */
124 0x75, 0x08, /* GReportSize 0x08 [8] */
125 0x95, 0x01, /* GReportCount 0x01 [1] */
126 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
128 0xC0, /* MEndCollection */
130 0xC0 /* MEndCollection [Game Pad] */
133 static const unsigned int ps3remote_keymap_joypad_buttons[] = {
135 [0x02] = BTN_THUMBL, /* L3 */
136 [0x03] = BTN_THUMBR, /* R3 */
142 [0x09] = BTN_TL2, /* L2 */
143 [0x0a] = BTN_TR2, /* R2 */
144 [0x0b] = BTN_TL, /* L1 */
145 [0x0c] = BTN_TR, /* R1 */
146 [0x0d] = KEY_OPTION, /* options/triangle */
147 [0x0e] = KEY_BACK, /* back/circle */
148 [0x0f] = BTN_0, /* cross */
149 [0x10] = KEY_SCREEN, /* view/square */
150 [0x11] = KEY_HOMEPAGE, /* PS button */
153 static const unsigned int ps3remote_keymap_remote_buttons[] = {
164 [0x0e] = KEY_ESC, /* return */
166 [0x16] = KEY_EJECTCD,
167 [0x1a] = KEY_MENU, /* top menu */
169 [0x30] = KEY_PREVIOUS,
172 [0x33] = KEY_REWIND, /* scan back */
173 [0x34] = KEY_FORWARD, /* scan forward */
176 [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */
177 [0x60] = KEY_FRAMEBACK, /* slow/step back */
178 [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */
179 [0x63] = KEY_SUBTITLE,
182 [0x70] = KEY_INFO, /* display */
189 static const unsigned int buzz_keymap[] = {
190 /* The controller has 4 remote buzzers, each with one LED and 5
193 * We use the mapping chosen by the controller, which is:
196 * -------------------
203 * So, for example, the orange button on the third buzzer is mapped to
204 * BTN_TRIGGER_HAPPY14
206 [ 1] = BTN_TRIGGER_HAPPY1,
207 [ 2] = BTN_TRIGGER_HAPPY2,
208 [ 3] = BTN_TRIGGER_HAPPY3,
209 [ 4] = BTN_TRIGGER_HAPPY4,
210 [ 5] = BTN_TRIGGER_HAPPY5,
211 [ 6] = BTN_TRIGGER_HAPPY6,
212 [ 7] = BTN_TRIGGER_HAPPY7,
213 [ 8] = BTN_TRIGGER_HAPPY8,
214 [ 9] = BTN_TRIGGER_HAPPY9,
215 [10] = BTN_TRIGGER_HAPPY10,
216 [11] = BTN_TRIGGER_HAPPY11,
217 [12] = BTN_TRIGGER_HAPPY12,
218 [13] = BTN_TRIGGER_HAPPY13,
219 [14] = BTN_TRIGGER_HAPPY14,
220 [15] = BTN_TRIGGER_HAPPY15,
221 [16] = BTN_TRIGGER_HAPPY16,
222 [17] = BTN_TRIGGER_HAPPY17,
223 [18] = BTN_TRIGGER_HAPPY18,
224 [19] = BTN_TRIGGER_HAPPY19,
225 [20] = BTN_TRIGGER_HAPPY20,
229 struct hid_device *hdev;
230 struct led_classdev *leds[4];
231 unsigned long quirks;
232 struct work_struct state_worker;
234 #ifdef CONFIG_SONY_FF
242 static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc,
245 *rsize = sizeof(ps3remote_rdesc);
246 return ps3remote_rdesc;
249 static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi,
250 struct hid_field *field, struct hid_usage *usage,
251 unsigned long **bit, int *max)
253 unsigned int key = usage->hid & HID_USAGE;
255 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
258 switch (usage->collection_index) {
260 if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons))
263 key = ps3remote_keymap_joypad_buttons[key];
268 if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons))
271 key = ps3remote_keymap_remote_buttons[key];
279 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
284 /* Sony Vaio VGX has wrongly mouse pointer declared as constant */
285 static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
288 struct sony_sc *sc = hid_get_drvdata(hdev);
291 * Some Sony RF receivers wrongly declare the mouse pointer as a
292 * a constant non-data variable.
294 if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 &&
295 /* usage page: generic desktop controls */
296 /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */
298 rdesc[2] == 0x09 && rdesc[3] == 0x02 &&
299 /* input (usage page for x,y axes): constant, variable, relative */
300 rdesc[54] == 0x81 && rdesc[55] == 0x07) {
301 hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n");
302 /* input: data, variable, relative */
306 /* The HID descriptor exposed over BT has a trailing zero byte */
307 if ((((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize == 148) ||
308 ((sc->quirks & SIXAXIS_CONTROLLER_BT) && *rsize == 149)) &&
310 hid_info(hdev, "Fixing up Sony Sixaxis report descriptor\n");
311 memcpy((void *)&rdesc[83], (void *)&sixaxis_rdesc_fixup,
312 sizeof(sixaxis_rdesc_fixup));
313 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB &&
314 *rsize > sizeof(sixaxis_rdesc_fixup2)) {
315 hid_info(hdev, "Sony Sixaxis clone detected. Using original report descriptor (size: %d clone; %d new)\n",
316 *rsize, (int)sizeof(sixaxis_rdesc_fixup2));
317 *rsize = sizeof(sixaxis_rdesc_fixup2);
318 memcpy(rdesc, &sixaxis_rdesc_fixup2, *rsize);
321 if (sc->quirks & PS3REMOTE)
322 return ps3remote_fixup(hdev, rdesc, rsize);
327 static int sony_raw_event(struct hid_device *hdev, struct hid_report *report,
330 struct sony_sc *sc = hid_get_drvdata(hdev);
332 /* Sixaxis HID report has acclerometers/gyro with MSByte first, this
333 * has to be BYTE_SWAPPED before passing up to joystick interface
335 if ((sc->quirks & (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)) &&
336 rd[0] == 0x01 && size == 49) {
337 swap(rd[41], rd[42]);
338 swap(rd[43], rd[44]);
339 swap(rd[45], rd[46]);
340 swap(rd[47], rd[48]);
346 static int sony_mapping(struct hid_device *hdev, struct hid_input *hi,
347 struct hid_field *field, struct hid_usage *usage,
348 unsigned long **bit, int *max)
350 struct sony_sc *sc = hid_get_drvdata(hdev);
352 if (sc->quirks & BUZZ_CONTROLLER) {
353 unsigned int key = usage->hid & HID_USAGE;
355 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
358 switch (usage->collection_index) {
360 if (key >= ARRAY_SIZE(buzz_keymap))
363 key = buzz_keymap[key];
371 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
375 if (sc->quirks & PS3REMOTE)
376 return ps3remote_mapping(hdev, hi, field, usage, bit, max);
378 /* Let hid-core decide for the others */
383 * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP
384 * like it should according to usbhid/hid-core.c::usbhid_output_raw_report()
385 * so we need to override that forcing HID Output Reports on the Control EP.
387 * There is also another issue about HID Output Reports via USB, the Sixaxis
388 * does not want the report_id as part of the data packet, so we have to
389 * discard buf[0] when sending the actual control message, even for numbered
392 static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf,
393 size_t count, unsigned char report_type)
395 struct usb_interface *intf = to_usb_interface(hid->dev.parent);
396 struct usb_device *dev = interface_to_usbdev(intf);
397 struct usb_host_interface *interface = intf->cur_altsetting;
398 int report_id = buf[0];
401 if (report_type == HID_OUTPUT_REPORT) {
402 /* Don't send the Report ID */
407 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
409 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
410 ((report_type + 1) << 8) | report_id,
411 interface->desc.bInterfaceNumber, buf, count,
412 USB_CTRL_SET_TIMEOUT);
414 /* Count also the Report ID, in case of an Output report. */
415 if (ret > 0 && report_type == HID_OUTPUT_REPORT)
422 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
423 * to "operational". Without this, the ps3 controller will not report any
426 static int sixaxis_set_operational_usb(struct hid_device *hdev)
429 char *buf = kmalloc(18, GFP_KERNEL);
434 ret = hdev->hid_get_raw_report(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT);
437 hid_err(hdev, "can't set operational mode\n");
444 static int sixaxis_set_operational_bt(struct hid_device *hdev)
446 unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
447 return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
450 static void buzz_set_leds(struct hid_device *hdev, int leds)
452 struct list_head *report_list =
453 &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
454 struct hid_report *report = list_entry(report_list->next,
455 struct hid_report, list);
456 __s32 *value = report->field[0]->value;
459 value[1] = (leds & 1) ? 0xff : 0x00;
460 value[2] = (leds & 2) ? 0xff : 0x00;
461 value[3] = (leds & 4) ? 0xff : 0x00;
462 value[4] = (leds & 8) ? 0xff : 0x00;
465 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
468 static void sony_set_leds(struct hid_device *hdev, __u8 leds)
470 struct sony_sc *drv_data = hid_get_drvdata(hdev);
472 if (drv_data->quirks & BUZZ_CONTROLLER) {
473 buzz_set_leds(hdev, leds);
474 } else if (drv_data->quirks & SIXAXIS_CONTROLLER_USB) {
475 drv_data->led_state = leds;
476 schedule_work(&drv_data->state_worker);
480 static void sony_led_set_brightness(struct led_classdev *led,
481 enum led_brightness value)
483 struct device *dev = led->dev->parent;
484 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
485 struct sony_sc *drv_data;
489 drv_data = hid_get_drvdata(hdev);
491 hid_err(hdev, "No device data\n");
495 for (n = 0; n < 4; n++) {
496 if (led == drv_data->leds[n]) {
497 int on = !!(drv_data->led_state & (1 << n));
498 if (value == LED_OFF && on) {
499 drv_data->led_state &= ~(1 << n);
500 sony_set_leds(hdev, drv_data->led_state);
501 } else if (value != LED_OFF && !on) {
502 drv_data->led_state |= (1 << n);
503 sony_set_leds(hdev, drv_data->led_state);
510 static enum led_brightness sony_led_get_brightness(struct led_classdev *led)
512 struct device *dev = led->dev->parent;
513 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
514 struct sony_sc *drv_data;
519 drv_data = hid_get_drvdata(hdev);
521 hid_err(hdev, "No device data\n");
525 for (n = 0; n < 4; n++) {
526 if (led == drv_data->leds[n]) {
527 on = !!(drv_data->led_state & (1 << n));
532 return on ? LED_FULL : LED_OFF;
535 static void sony_leds_remove(struct hid_device *hdev)
537 struct sony_sc *drv_data;
538 struct led_classdev *led;
541 drv_data = hid_get_drvdata(hdev);
542 BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT));
544 for (n = 0; n < 4; n++) {
545 led = drv_data->leds[n];
546 drv_data->leds[n] = NULL;
549 led_classdev_unregister(led);
554 static int sony_leds_init(struct hid_device *hdev)
556 struct sony_sc *drv_data;
558 struct led_classdev *led;
562 const char *name_fmt;
564 drv_data = hid_get_drvdata(hdev);
565 BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT));
567 if (drv_data->quirks & BUZZ_CONTROLLER) {
568 name_len = strlen("::buzz#");
569 name_fmt = "%s::buzz%d";
570 /* Validate expected report characteristics. */
571 if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7))
574 name_len = strlen("::sony#");
575 name_fmt = "%s::sony%d";
578 /* Clear LEDs as we have no way of reading their initial state. This is
579 * only relevant if the driver is loaded after somebody actively set the
581 sony_set_leds(hdev, 0x00);
583 name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1;
585 for (n = 0; n < 4; n++) {
586 led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
588 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
593 name = (void *)(&led[1]);
594 snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1);
597 led->max_brightness = 1;
598 led->brightness_get = sony_led_get_brightness;
599 led->brightness_set = sony_led_set_brightness;
601 ret = led_classdev_register(&hdev->dev, led);
603 hid_err(hdev, "Failed to register LED %d\n", n);
608 drv_data->leds[n] = led;
614 sony_leds_remove(hdev);
619 static void sony_state_worker(struct work_struct *work)
621 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
622 unsigned char buf[] = {
624 0x00, 0xff, 0x00, 0xff, 0x00,
625 0x00, 0x00, 0x00, 0x00, 0x00,
626 0xff, 0x27, 0x10, 0x00, 0x32,
627 0xff, 0x27, 0x10, 0x00, 0x32,
628 0xff, 0x27, 0x10, 0x00, 0x32,
629 0xff, 0x27, 0x10, 0x00, 0x32,
630 0x00, 0x00, 0x00, 0x00, 0x00
633 #ifdef CONFIG_SONY_FF
634 buf[3] = sc->right ? 1 : 0;
638 buf[10] |= (sc->led_state & 0xf) << 1;
640 sc->hdev->hid_output_raw_report(sc->hdev, buf, sizeof(buf),
644 static void dualshock4_state_worker(struct work_struct *work)
646 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
647 unsigned char buf[] = {
649 0x03, 0x00, 0x00, 0x00, 0x00,
650 0x00, 0x00, 0x00, 0x00, 0x00,
651 0x00, 0x00, 0x00, 0x00, 0x00,
652 0x00, 0x00, 0x00, 0x00, 0x00,
653 0x00, 0x00, 0x00, 0x00, 0x00,
654 0x00, 0x00, 0x00, 0x00, 0x00,
658 #ifdef CONFIG_SONY_FF
663 sc->hdev->hid_output_raw_report(sc->hdev, buf, sizeof(buf),
667 #ifdef CONFIG_SONY_FF
668 static int sony_play_effect(struct input_dev *dev, void *data,
669 struct ff_effect *effect)
671 struct hid_device *hid = input_get_drvdata(dev);
672 struct sony_sc *sc = hid_get_drvdata(hid);
674 if (effect->type != FF_RUMBLE)
677 sc->left = effect->u.rumble.strong_magnitude / 256;
678 sc->right = effect->u.rumble.weak_magnitude / 256;
680 schedule_work(&sc->state_worker);
684 static int sony_init_ff(struct hid_device *hdev)
686 struct hid_input *hidinput = list_entry(hdev->inputs.next,
687 struct hid_input, list);
688 struct input_dev *input_dev = hidinput->input;
690 input_set_capability(input_dev, EV_FF, FF_RUMBLE);
691 return input_ff_create_memless(input_dev, NULL, sony_play_effect);
694 static void sony_destroy_ff(struct hid_device *hdev)
696 struct sony_sc *sc = hid_get_drvdata(hdev);
698 cancel_work_sync(&sc->state_worker);
702 static int sony_init_ff(struct hid_device *hdev)
707 static void sony_destroy_ff(struct hid_device *hdev)
712 static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
715 unsigned long quirks = id->driver_data;
717 unsigned int connect_mask = HID_CONNECT_DEFAULT;
719 sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
721 hid_err(hdev, "can't alloc sony descriptor\n");
726 hid_set_drvdata(hdev, sc);
729 ret = hid_parse(hdev);
731 hid_err(hdev, "parse failed\n");
735 if (sc->quirks & VAIO_RDESC_CONSTANT)
736 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
737 else if (sc->quirks & SIXAXIS_CONTROLLER_USB)
738 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
739 else if (sc->quirks & SIXAXIS_CONTROLLER_BT)
740 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
742 ret = hid_hw_start(hdev, connect_mask);
744 hid_err(hdev, "hw start failed\n");
748 if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
749 hdev->hid_output_raw_report = sixaxis_usb_output_raw_report;
750 ret = sixaxis_set_operational_usb(hdev);
751 INIT_WORK(&sc->state_worker, sony_state_worker);
753 else if (sc->quirks & SIXAXIS_CONTROLLER_BT)
754 ret = sixaxis_set_operational_bt(hdev);
755 else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
757 INIT_WORK(&sc->state_worker, dualshock4_state_worker);
765 if (sc->quirks & SONY_LED_SUPPORT) {
766 ret = sony_leds_init(hdev);
771 ret = sony_init_ff(hdev);
777 if (sc->quirks & SONY_LED_SUPPORT)
778 sony_leds_remove(hdev);
783 static void sony_remove(struct hid_device *hdev)
785 struct sony_sc *sc = hid_get_drvdata(hdev);
787 if (sc->quirks & SONY_LED_SUPPORT)
788 sony_leds_remove(hdev);
790 sony_destroy_ff(hdev);
795 static const struct hid_device_id sony_devices[] = {
796 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
797 .driver_data = SIXAXIS_CONTROLLER_USB },
798 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
799 .driver_data = SIXAXIS_CONTROLLER_USB },
800 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
801 .driver_data = SIXAXIS_CONTROLLER_BT },
802 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
803 .driver_data = VAIO_RDESC_CONSTANT },
804 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE),
805 .driver_data = VAIO_RDESC_CONSTANT },
806 /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as
807 * Logitech joystick from the device descriptor. */
808 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER),
809 .driver_data = BUZZ_CONTROLLER },
810 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER),
811 .driver_data = BUZZ_CONTROLLER },
812 /* PS3 BD Remote Control */
813 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE),
814 .driver_data = PS3REMOTE },
815 /* Logitech Harmony Adapter for PS3 */
816 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3),
817 .driver_data = PS3REMOTE },
818 /* Sony Dualshock 4 controllers for PS4 */
819 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
820 .driver_data = DUALSHOCK4_CONTROLLER },
821 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
822 .driver_data = DUALSHOCK4_CONTROLLER },
825 MODULE_DEVICE_TABLE(hid, sony_devices);
827 static struct hid_driver sony_driver = {
829 .id_table = sony_devices,
830 .input_mapping = sony_mapping,
832 .remove = sony_remove,
833 .report_fixup = sony_report_fixup,
834 .raw_event = sony_raw_event
836 module_hid_driver(sony_driver);
838 MODULE_LICENSE("GPL");