^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * HID driver for Sony / PS2 / PS3 / PS4 BD devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 1999 Andreas Gal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (c) 2008 Jiri Slaby
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (c) 2012 David Dillow <dave@thedillows.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (c) 2006-2013 Jiri Kosina
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (c) 2014-2016 Frank Praznik <frank.praznik@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Copyright (c) 2018 Todd Kelner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * NOTE: in order for the Sony PS3 BD Remote Control to be found by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * a Bluetooth host, the key combination Start+Enter has to be kept pressed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * for about 7 seconds with the Bluetooth Host Controller in discovering mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * There will be no PIN request from the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/power_supply.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define VAIO_RDESC_CONSTANT BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define SIXAXIS_CONTROLLER_USB BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define SIXAXIS_CONTROLLER_BT BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define BUZZ_CONTROLLER BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define PS3REMOTE BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define DUALSHOCK4_CONTROLLER_USB BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define DUALSHOCK4_CONTROLLER_BT BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define DUALSHOCK4_DONGLE BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define MOTION_CONTROLLER_USB BIT(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define MOTION_CONTROLLER_BT BIT(9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define NAVIGATION_CONTROLLER_USB BIT(10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define NAVIGATION_CONTROLLER_BT BIT(11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define SINO_LITE_CONTROLLER BIT(12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define FUTUREMAX_DANCE_MAT BIT(13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define NSG_MR5U_REMOTE_BT BIT(14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define NSG_MR7U_REMOTE_BT BIT(15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define SHANWAN_GAMEPAD BIT(16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define MOTION_CONTROLLER (MOTION_CONTROLLER_USB | MOTION_CONTROLLER_BT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define NAVIGATION_CONTROLLER (NAVIGATION_CONTROLLER_USB |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) NAVIGATION_CONTROLLER_BT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define DUALSHOCK4_CONTROLLER (DUALSHOCK4_CONTROLLER_USB |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) DUALSHOCK4_CONTROLLER_BT | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) DUALSHOCK4_DONGLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER | BUZZ_CONTROLLER |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) DUALSHOCK4_CONTROLLER | MOTION_CONTROLLER |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) NAVIGATION_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) MOTION_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define SONY_BT_DEVICE (SIXAXIS_CONTROLLER_BT | DUALSHOCK4_CONTROLLER_BT |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER_BT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define NSG_MRXU_REMOTE (NSG_MR5U_REMOTE_BT | NSG_MR7U_REMOTE_BT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define MAX_LEDS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define NSG_MRXU_MAX_X 1667
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define NSG_MRXU_MAX_Y 1868
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* PS/3 Motion controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static u8 motion_rdesc[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 0x05, 0x01, /* Usage Page (Desktop), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 0x09, 0x04, /* Usage (Joystick), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 0xA1, 0x01, /* Collection (Application), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 0xA1, 0x02, /* Collection (Logical), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 0x85, 0x01, /* Report ID (1), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 0x75, 0x01, /* Report Size (1), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 0x95, 0x15, /* Report Count (21), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 0x15, 0x00, /* Logical Minimum (0), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 0x25, 0x01, /* Logical Maximum (1), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 0x35, 0x00, /* Physical Minimum (0), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) 0x45, 0x01, /* Physical Maximum (1), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) 0x05, 0x09, /* Usage Page (Button), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) 0x19, 0x01, /* Usage Minimum (01h), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) 0x29, 0x15, /* Usage Maximum (15h), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) 0x81, 0x02, /* Input (Variable), * Buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 0x95, 0x0B, /* Report Count (11), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 0x81, 0x03, /* Input (Constant, Variable), * Padding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 0x15, 0x00, /* Logical Minimum (0), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 0x05, 0x01, /* Usage Page (Desktop), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 0xA1, 0x00, /* Collection (Physical), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 0x95, 0x01, /* Report Count (1), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 0x35, 0x00, /* Physical Minimum (0), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 0x09, 0x30, /* Usage (X), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 0x81, 0x02, /* Input (Variable), * Trigger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 0xC0, /* End Collection, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 0x95, 0x07, /* Report Count (7), * skip 7 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 0x05, 0x01, /* Usage Page (Desktop), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 0x75, 0x10, /* Report Size (16), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 0x46, 0xFF, 0xFF, /* Physical Maximum (65535), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 0x27, 0xFF, 0xFF, 0x00, 0x00, /* Logical Maximum (65535), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 0x95, 0x03, /* Report Count (3), * 3x Accels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 0x09, 0x33, /* Usage (rX), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 0x09, 0x34, /* Usage (rY), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 0x09, 0x35, /* Usage (rZ), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 0x95, 0x03, /* Report Count (3), * Skip Accels 2nd frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 0x05, 0x01, /* Usage Page (Desktop), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 0x09, 0x01, /* Usage (Pointer), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 0x95, 0x03, /* Report Count (3), * 3x Gyros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 0x95, 0x03, /* Report Count (3), * Skip Gyros 2nd frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 0x75, 0x0C, /* Report Size (12), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 0x46, 0xFF, 0x0F, /* Physical Maximum (4095), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 0x26, 0xFF, 0x0F, /* Logical Maximum (4095), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 0x95, 0x04, /* Report Count (4), * Skip Temp and Magnetometers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 0x95, 0x06, /* Report Count (6), * Skip Timestamp and Extension Bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 0x95, 0x30, /* Report Count (48), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 0x09, 0x01, /* Usage (Pointer), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 0x91, 0x02, /* Output (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 0x95, 0x30, /* Report Count (48), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 0x09, 0x01, /* Usage (Pointer), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 0xB1, 0x02, /* Feature (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 0xC0, /* End Collection, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 0xA1, 0x02, /* Collection (Logical), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 0x85, 0x02, /* Report ID (2), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 0x95, 0x30, /* Report Count (48), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 0x09, 0x01, /* Usage (Pointer), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 0xB1, 0x02, /* Feature (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 0xC0, /* End Collection, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 0xA1, 0x02, /* Collection (Logical), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 0x85, 0xEE, /* Report ID (238), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 0x95, 0x30, /* Report Count (48), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 0x09, 0x01, /* Usage (Pointer), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 0xB1, 0x02, /* Feature (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 0xC0, /* End Collection, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 0xA1, 0x02, /* Collection (Logical), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 0x85, 0xEF, /* Report ID (239), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 0x95, 0x30, /* Report Count (48), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 0x09, 0x01, /* Usage (Pointer), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 0xB1, 0x02, /* Feature (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 0xC0, /* End Collection, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 0xC0 /* End Collection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static u8 ps3remote_rdesc[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 0x05, 0x01, /* GUsagePage Generic Desktop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 0x09, 0x05, /* LUsage 0x05 [Game Pad] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Use collection 1 for joypad buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 0xA1, 0x02, /* MCollection Logical (interrelated data) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * Ignore the 1st byte, maybe it is used for a controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * number but it's not needed for correct operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 0x75, 0x08, /* GReportSize 0x08 [8] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 0x95, 0x01, /* GReportCount 0x01 [1] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * Bytes from 2nd to 4th are a bitmap for joypad buttons, for these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * buttons multiple keypresses are allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 0x05, 0x09, /* GUsagePage Button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 0x14, /* GLogicalMinimum [0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 0x75, 0x01, /* GReportSize 0x01 [1] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 0x95, 0x18, /* GReportCount 0x18 [24] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 0xC0, /* MEndCollection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* Use collection 2 for remote control buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 0xA1, 0x02, /* MCollection Logical (interrelated data) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* 5th byte is used for remote control buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 0x05, 0x09, /* GUsagePage Button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 0x18, /* LUsageMinimum [No button pressed] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 0x14, /* GLogicalMinimum [0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 0x75, 0x08, /* GReportSize 0x08 [8] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 0x95, 0x01, /* GReportCount 0x01 [1] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 0x80, /* MInput */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * Ignore bytes from 6th to 11th, 6th to 10th are always constant at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * 0xff and 11th is for press indication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 0x75, 0x08, /* GReportSize 0x08 [8] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 0x95, 0x06, /* GReportCount 0x06 [6] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* 12th byte is for battery strength */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 0x05, 0x06, /* GUsagePage Generic Device Controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 0x14, /* GLogicalMinimum [0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 0x75, 0x08, /* GReportSize 0x08 [8] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 0x95, 0x01, /* GReportCount 0x01 [1] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 0xC0, /* MEndCollection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 0xC0 /* MEndCollection [Game Pad] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static const unsigned int ps3remote_keymap_joypad_buttons[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) [0x01] = KEY_SELECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) [0x02] = BTN_THUMBL, /* L3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) [0x03] = BTN_THUMBR, /* R3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) [0x04] = BTN_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) [0x05] = KEY_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) [0x06] = KEY_RIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) [0x07] = KEY_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) [0x08] = KEY_LEFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) [0x09] = BTN_TL2, /* L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) [0x0a] = BTN_TR2, /* R2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) [0x0b] = BTN_TL, /* L1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) [0x0c] = BTN_TR, /* R1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) [0x0d] = KEY_OPTION, /* options/triangle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) [0x0e] = KEY_BACK, /* back/circle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) [0x0f] = BTN_0, /* cross */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) [0x10] = KEY_SCREEN, /* view/square */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) [0x11] = KEY_HOMEPAGE, /* PS button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) [0x14] = KEY_ENTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static const unsigned int ps3remote_keymap_remote_buttons[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) [0x00] = KEY_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) [0x01] = KEY_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) [0x02] = KEY_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) [0x03] = KEY_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) [0x04] = KEY_5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) [0x05] = KEY_6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) [0x06] = KEY_7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) [0x07] = KEY_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) [0x08] = KEY_9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) [0x09] = KEY_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) [0x0e] = KEY_ESC, /* return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) [0x0f] = KEY_CLEAR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) [0x16] = KEY_EJECTCD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) [0x1a] = KEY_MENU, /* top menu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) [0x28] = KEY_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) [0x30] = KEY_PREVIOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) [0x31] = KEY_NEXT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) [0x32] = KEY_PLAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) [0x33] = KEY_REWIND, /* scan back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) [0x34] = KEY_FORWARD, /* scan forward */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) [0x38] = KEY_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) [0x39] = KEY_PAUSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) [0x60] = KEY_FRAMEBACK, /* slow/step back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) [0x63] = KEY_SUBTITLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) [0x64] = KEY_AUDIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) [0x65] = KEY_ANGLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) [0x70] = KEY_INFO, /* display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) [0x80] = KEY_BLUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) [0x81] = KEY_RED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) [0x82] = KEY_GREEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) [0x83] = KEY_YELLOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static const unsigned int buzz_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * The controller has 4 remote buzzers, each with one LED and 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * buttons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * We use the mapping chosen by the controller, which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * Key Offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * -------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * Buzz 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * Blue 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * Orange 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * Green 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * Yellow 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * So, for example, the orange button on the third buzzer is mapped to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * BTN_TRIGGER_HAPPY14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) [1] = BTN_TRIGGER_HAPPY1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) [2] = BTN_TRIGGER_HAPPY2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) [3] = BTN_TRIGGER_HAPPY3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) [4] = BTN_TRIGGER_HAPPY4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) [5] = BTN_TRIGGER_HAPPY5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) [6] = BTN_TRIGGER_HAPPY6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) [7] = BTN_TRIGGER_HAPPY7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) [8] = BTN_TRIGGER_HAPPY8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) [9] = BTN_TRIGGER_HAPPY9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) [10] = BTN_TRIGGER_HAPPY10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) [11] = BTN_TRIGGER_HAPPY11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) [12] = BTN_TRIGGER_HAPPY12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) [13] = BTN_TRIGGER_HAPPY13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) [14] = BTN_TRIGGER_HAPPY14,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) [15] = BTN_TRIGGER_HAPPY15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) [16] = BTN_TRIGGER_HAPPY16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) [17] = BTN_TRIGGER_HAPPY17,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) [18] = BTN_TRIGGER_HAPPY18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) [19] = BTN_TRIGGER_HAPPY19,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) [20] = BTN_TRIGGER_HAPPY20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* The Navigation controller is a partial DS3 and uses the same HID report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * and hence the same keymap indices, however not not all axes/buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * are physically present. We use the same axis and button mapping as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * the DS3, which uses the Linux gamepad spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static const unsigned int navigation_absmap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) [0x30] = ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) [0x31] = ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) [0x33] = ABS_Z, /* L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* Buttons not physically available on the device, but still available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * in the reports are explicitly set to 0 for documentation purposes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static const unsigned int navigation_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) [0x01] = 0, /* Select */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) [0x02] = BTN_THUMBL, /* L3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) [0x03] = 0, /* R3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) [0x04] = 0, /* Start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) [0x05] = BTN_DPAD_UP, /* Up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) [0x06] = BTN_DPAD_RIGHT, /* Right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) [0x07] = BTN_DPAD_DOWN, /* Down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) [0x08] = BTN_DPAD_LEFT, /* Left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) [0x09] = BTN_TL2, /* L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) [0x0a] = 0, /* R2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) [0x0b] = BTN_TL, /* L1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) [0x0c] = 0, /* R1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) [0x0d] = BTN_NORTH, /* Triangle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) [0x0e] = BTN_EAST, /* Circle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) [0x0f] = BTN_SOUTH, /* Cross */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) [0x10] = BTN_WEST, /* Square */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) [0x11] = BTN_MODE, /* PS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static const unsigned int sixaxis_absmap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) [0x30] = ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) [0x31] = ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) [0x32] = ABS_RX, /* right stick X */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) [0x35] = ABS_RY, /* right stick Y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static const unsigned int sixaxis_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) [0x01] = BTN_SELECT, /* Select */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) [0x02] = BTN_THUMBL, /* L3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) [0x03] = BTN_THUMBR, /* R3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) [0x04] = BTN_START, /* Start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) [0x05] = BTN_DPAD_UP, /* Up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) [0x06] = BTN_DPAD_RIGHT, /* Right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) [0x07] = BTN_DPAD_DOWN, /* Down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) [0x08] = BTN_DPAD_LEFT, /* Left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) [0x09] = BTN_TL2, /* L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) [0x0a] = BTN_TR2, /* R2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) [0x0b] = BTN_TL, /* L1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) [0x0c] = BTN_TR, /* R1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) [0x0d] = BTN_NORTH, /* Triangle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) [0x0e] = BTN_EAST, /* Circle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) [0x0f] = BTN_SOUTH, /* Cross */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) [0x10] = BTN_WEST, /* Square */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) [0x11] = BTN_MODE, /* PS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static const unsigned int ds4_absmap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) [0x30] = ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) [0x31] = ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) [0x32] = ABS_RX, /* right stick X */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) [0x33] = ABS_Z, /* L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) [0x34] = ABS_RZ, /* R2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) [0x35] = ABS_RY, /* right stick Y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static const unsigned int ds4_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) [0x1] = BTN_WEST, /* Square */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) [0x2] = BTN_SOUTH, /* Cross */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) [0x3] = BTN_EAST, /* Circle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) [0x4] = BTN_NORTH, /* Triangle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) [0x5] = BTN_TL, /* L1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) [0x6] = BTN_TR, /* R1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) [0x7] = BTN_TL2, /* L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) [0x8] = BTN_TR2, /* R2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) [0x9] = BTN_SELECT, /* Share */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) [0xa] = BTN_START, /* Options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) [0xb] = BTN_THUMBL, /* L3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) [0xc] = BTN_THUMBR, /* R3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) [0xd] = BTN_MODE, /* PS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static const struct {int x; int y; } ds4_hat_mapping[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {0, 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static enum power_supply_property sony_battery_props[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) POWER_SUPPLY_PROP_PRESENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) POWER_SUPPLY_PROP_CAPACITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) POWER_SUPPLY_PROP_SCOPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) POWER_SUPPLY_PROP_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct sixaxis_led {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) u8 time_enabled; /* the total time the led is active (0xff means forever) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) u8 duty_length; /* how long a cycle is in deciseconds (0 means "really fast") */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) u8 enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) u8 duty_off; /* % of duty_length the led is off (0xff means 100%) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) u8 duty_on; /* % of duty_length the led is on (0xff mean 100%) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct sixaxis_rumble {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) u8 padding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) u8 right_duration; /* Right motor duration (0xff means forever) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) u8 right_motor_on; /* Right (small) motor on/off, only supports values of 0 or 1 (off/on) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) u8 left_duration; /* Left motor duration (0xff means forever) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) u8 left_motor_force; /* left (large) motor, supports force values from 0 to 255 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct sixaxis_output_report {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) u8 report_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct sixaxis_rumble rumble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) u8 padding[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) u8 leds_bitmap; /* bitmap of enabled LEDs: LED_1 = 0x02, LED_2 = 0x04, ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct sixaxis_led led[4]; /* LEDx at (4 - x) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct sixaxis_led _reserved; /* LED5, not actually soldered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) union sixaxis_output_report_01 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct sixaxis_output_report data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) u8 buf[36];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct motion_output_report_02 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) u8 type, zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) u8 r, g, b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) u8 zero2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) u8 rumble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) #define DS4_FEATURE_REPORT_0x02_SIZE 37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) #define DS4_FEATURE_REPORT_0x05_SIZE 41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) #define DS4_FEATURE_REPORT_0x81_SIZE 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) #define DS4_FEATURE_REPORT_0xA3_SIZE 49
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) #define DS4_INPUT_REPORT_0x11_SIZE 78
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) #define DS4_OUTPUT_REPORT_0x05_SIZE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) #define DS4_OUTPUT_REPORT_0x11_SIZE 78
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) #define SIXAXIS_REPORT_0xF2_SIZE 17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) #define SIXAXIS_REPORT_0xF5_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) #define MOTION_REPORT_0x02_SIZE 49
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* Offsets relative to USB input report (0x1). Bluetooth (0x11) requires an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * additional +2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) #define DS4_INPUT_REPORT_AXIS_OFFSET 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) #define DS4_INPUT_REPORT_BUTTON_OFFSET 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) #define DS4_INPUT_REPORT_TIMESTAMP_OFFSET 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) #define DS4_INPUT_REPORT_GYRO_X_OFFSET 13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) #define DS4_INPUT_REPORT_BATTERY_OFFSET 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) #define DS4_INPUT_REPORT_TOUCHPAD_OFFSET 33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) #define SENSOR_SUFFIX " Motion Sensors"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) #define DS4_TOUCHPAD_SUFFIX " Touchpad"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /* Default to 4ms poll interval, which is same as USB (not adjustable). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) #define DS4_BT_DEFAULT_POLL_INTERVAL_MS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) #define DS4_BT_MAX_POLL_INTERVAL_MS 62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) #define DS4_GYRO_RES_PER_DEG_S 1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) #define DS4_ACC_RES_PER_G 8192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) #define SIXAXIS_INPUT_REPORT_ACC_X_OFFSET 41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) #define SIXAXIS_ACC_RES_PER_G 113
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static DEFINE_SPINLOCK(sony_dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static LIST_HEAD(sony_device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static DEFINE_IDA(sony_device_id_allocator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /* Used for calibration of DS4 accelerometer and gyro. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct ds4_calibration_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) int abs_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) short bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /* Calibration requires scaling against a sensitivity value, which is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * float. Store sensitivity as a fraction to limit floating point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * calculations until final calibration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) int sens_numer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) int sens_denom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) enum ds4_dongle_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) DONGLE_DISCONNECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) DONGLE_CALIBRATING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) DONGLE_CONNECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) DONGLE_DISABLED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) enum sony_worker {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) SONY_WORKER_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) SONY_WORKER_HOTPLUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct sony_sc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct list_head list_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct hid_device *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct input_dev *touchpad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct input_dev *sensor_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) struct led_classdev *leds[MAX_LEDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) unsigned long quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct work_struct hotplug_worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) struct work_struct state_worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) void (*send_output_report)(struct sony_sc *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct power_supply *battery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) struct power_supply_desc battery_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) int device_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) unsigned fw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) unsigned hw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) u8 *output_report_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) #ifdef CONFIG_SONY_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) u8 left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) u8 right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) u8 mac_address[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) u8 hotplug_worker_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) u8 state_worker_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) u8 defer_initialization;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) u8 cable_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) u8 battery_charging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) u8 battery_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) u8 led_state[MAX_LEDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) u8 led_delay_on[MAX_LEDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) u8 led_delay_off[MAX_LEDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) u8 led_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) bool timestamp_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) u16 prev_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) unsigned int timestamp_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) u8 ds4_bt_poll_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) enum ds4_dongle_state ds4_dongle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) /* DS4 calibration data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) struct ds4_calibration_data ds4_calib_data[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) static void sony_set_leds(struct sony_sc *sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static inline void sony_schedule_work(struct sony_sc *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) enum sony_worker which)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) switch (which) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) case SONY_WORKER_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (!sc->defer_initialization && sc->state_worker_initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) schedule_work(&sc->state_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) case SONY_WORKER_HOTPLUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if (sc->hotplug_worker_initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) schedule_work(&sc->hotplug_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static ssize_t ds4_show_poll_interval(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct device_attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return snprintf(buf, PAGE_SIZE, "%i\n", sc->ds4_bt_poll_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) static ssize_t ds4_store_poll_interval(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) u8 interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (kstrtou8(buf, 0, &interval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (interval > DS4_BT_MAX_POLL_INTERVAL_MS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) sc->ds4_bt_poll_interval = interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) sony_schedule_work(sc, SONY_WORKER_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) static DEVICE_ATTR(bt_poll_interval, 0644, ds4_show_poll_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) ds4_store_poll_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static ssize_t sony_show_firmware_version(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) struct device_attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->fw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) static DEVICE_ATTR(firmware_version, 0444, sony_show_firmware_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static ssize_t sony_show_hardware_version(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct device_attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->hw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static DEVICE_ATTR(hardware_version, 0444, sony_show_hardware_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) static u8 *motion_fixup(struct hid_device *hdev, u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) *rsize = sizeof(motion_rdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) return motion_rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static u8 *ps3remote_fixup(struct hid_device *hdev, u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) *rsize = sizeof(ps3remote_rdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) return ps3remote_rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) unsigned int key = usage->hid & HID_USAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) switch (usage->collection_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) key = ps3remote_keymap_joypad_buttons[key];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) key = ps3remote_keymap_remote_buttons[key];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) static int navigation_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) unsigned int key = usage->hid & HID_USAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (key >= ARRAY_SIZE(sixaxis_keymap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) key = navigation_keymap[key];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) } else if (usage->hid == HID_GD_POINTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /* See comment in sixaxis_mapping, basically the L2 (and R2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * triggers are reported through GD Pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) * In addition we ignore any analog button 'axes' and only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * support digital buttons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) switch (usage->usage_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) case 8: /* L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) usage->hid = HID_GD_Z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) hid_map_usage_clear(hi, usage, bit, max, EV_ABS, usage->hid & 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) unsigned int abs = usage->hid & HID_USAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (abs >= ARRAY_SIZE(navigation_absmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) abs = navigation_absmap[abs];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) hid_map_usage_clear(hi, usage, bit, max, EV_ABS, abs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static int sixaxis_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) unsigned int key = usage->hid & HID_USAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if (key >= ARRAY_SIZE(sixaxis_keymap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) key = sixaxis_keymap[key];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) } else if (usage->hid == HID_GD_POINTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /* The DS3 provides analog values for most buttons and even
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * for HAT axes through GD Pointer. L2 and R2 are reported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * among these as well instead of as GD Z / RZ. Remap L2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * and R2 and ignore other analog 'button axes' as there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * no good way for reporting them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) switch (usage->usage_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) case 8: /* L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) usage->hid = HID_GD_Z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) case 9: /* R2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) usage->hid = HID_GD_RZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) hid_map_usage_clear(hi, usage, bit, max, EV_ABS, usage->hid & 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) unsigned int abs = usage->hid & HID_USAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (abs >= ARRAY_SIZE(sixaxis_absmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) abs = sixaxis_absmap[abs];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) hid_map_usage_clear(hi, usage, bit, max, EV_ABS, abs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) static int ds4_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) unsigned int key = usage->hid & HID_USAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) if (key >= ARRAY_SIZE(ds4_keymap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) key = ds4_keymap[key];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) unsigned int abs = usage->hid & HID_USAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) /* Let the HID parser deal with the HAT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (usage->hid == HID_GD_HATSWITCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (abs >= ARRAY_SIZE(ds4_absmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) abs = ds4_absmap[abs];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) hid_map_usage_clear(hi, usage, bit, max, EV_ABS, abs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) static u8 *sony_report_fixup(struct hid_device *hdev, u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (sc->quirks & (SINO_LITE_CONTROLLER | FUTUREMAX_DANCE_MAT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * Some Sony RF receivers wrongly declare the mouse pointer as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * a constant non-data variable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) /* usage page: generic desktop controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) /* usage: mouse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) rdesc[2] == 0x09 && rdesc[3] == 0x02 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) /* input (usage page for x,y axes): constant, variable, relative */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) rdesc[54] == 0x81 && rdesc[55] == 0x07) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) /* input: data, variable, relative */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) rdesc[55] = 0x06;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (sc->quirks & MOTION_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) return motion_fixup(hdev, rdesc, rsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (sc->quirks & PS3REMOTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return ps3remote_fixup(hdev, rdesc, rsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * Some knock-off USB dongles incorrectly report their button count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * as 13 instead of 16 causing three non-functional buttons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) if ((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize >= 45 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) /* Report Count (13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) rdesc[23] == 0x95 && rdesc[24] == 0x0D &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) /* Usage Maximum (13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) rdesc[37] == 0x29 && rdesc[38] == 0x0D &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) /* Report Count (3) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) rdesc[43] == 0x95 && rdesc[44] == 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) hid_info(hdev, "Fixing up USB dongle report descriptor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) rdesc[24] = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) rdesc[38] = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) rdesc[44] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) static void sixaxis_parse_report(struct sony_sc *sc, u8 *rd, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) static const u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) u8 cable_state, battery_capacity, battery_charging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) * The sixaxis is charging if the battery value is 0xee
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) * and it is fully charged if the value is 0xef.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) * It does not report the actual level while charging so it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) * is set to 100% while charging is in progress.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) offset = (sc->quirks & MOTION_CONTROLLER) ? 12 : 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (rd[offset] >= 0xee) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) battery_capacity = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) battery_charging = !(rd[offset] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) cable_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) u8 index = rd[offset] <= 5 ? rd[offset] : 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) battery_capacity = sixaxis_battery_capacity[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) battery_charging = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) cable_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) sc->cable_state = cable_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) sc->battery_capacity = battery_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) sc->battery_charging = battery_charging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (sc->quirks & SIXAXIS_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) offset = SIXAXIS_INPUT_REPORT_ACC_X_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) val = ((rd[offset+1] << 8) | rd[offset]) - 511;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) input_report_abs(sc->sensor_dev, ABS_X, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) /* Y and Z are swapped and inversed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) val = 511 - ((rd[offset+5] << 8) | rd[offset+4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) input_report_abs(sc->sensor_dev, ABS_Y, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) val = 511 - ((rd[offset+3] << 8) | rd[offset+2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) input_report_abs(sc->sensor_dev, ABS_Z, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) input_sync(sc->sensor_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) static void dualshock4_parse_report(struct sony_sc *sc, u8 *rd, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) struct hid_input *hidinput = list_entry(sc->hdev->inputs.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) struct input_dev *input_dev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) int n, m, offset, num_touch_data, max_touch_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) u8 cable_state, battery_capacity, battery_charging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) u16 timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) /* When using Bluetooth the header is 2 bytes longer, so skip these. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) int data_offset = (sc->quirks & DUALSHOCK4_CONTROLLER_BT) ? 2 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) /* Second bit of third button byte is for the touchpad button. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) offset = data_offset + DS4_INPUT_REPORT_BUTTON_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) input_report_key(sc->touchpad, BTN_LEFT, rd[offset+2] & 0x2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) * The default behavior of the Dualshock 4 is to send reports using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) * report type 1 when running over Bluetooth. However, when feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) * report 2 is requested during the controller initialization it starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) * sending input reports in report 17. Since report 17 is undefined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) * in the default HID descriptor, the HID layer won't generate events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) * While it is possible (and this was done before) to fixup the HID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) * descriptor to add this mapping, it was better to do this manually.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) * The reason is there were various pieces software both open and closed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) * source, relying on the descriptors to be the same across various
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) * operating systems. If the descriptors wouldn't match some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) * applications e.g. games on Wine would not be able to function due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) * to different descriptors, which such applications are not parsing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) if (rd[0] == 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) offset = data_offset + DS4_INPUT_REPORT_AXIS_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) input_report_abs(input_dev, ABS_X, rd[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) input_report_abs(input_dev, ABS_Y, rd[offset+1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) input_report_abs(input_dev, ABS_RX, rd[offset+2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) input_report_abs(input_dev, ABS_RY, rd[offset+3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) value = rd[offset+4] & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (value > 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) value = 8; /* Center 0, 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) input_report_abs(input_dev, ABS_HAT0X, ds4_hat_mapping[value].x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) input_report_abs(input_dev, ABS_HAT0Y, ds4_hat_mapping[value].y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) input_report_key(input_dev, BTN_WEST, rd[offset+4] & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) input_report_key(input_dev, BTN_SOUTH, rd[offset+4] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) input_report_key(input_dev, BTN_EAST, rd[offset+4] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) input_report_key(input_dev, BTN_NORTH, rd[offset+4] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) input_report_key(input_dev, BTN_TL, rd[offset+5] & 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) input_report_key(input_dev, BTN_TR, rd[offset+5] & 0x2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) input_report_key(input_dev, BTN_TL2, rd[offset+5] & 0x4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) input_report_key(input_dev, BTN_TR2, rd[offset+5] & 0x8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) input_report_key(input_dev, BTN_SELECT, rd[offset+5] & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) input_report_key(input_dev, BTN_START, rd[offset+5] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) input_report_key(input_dev, BTN_THUMBL, rd[offset+5] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) input_report_key(input_dev, BTN_THUMBR, rd[offset+5] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) input_report_key(input_dev, BTN_MODE, rd[offset+6] & 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) input_report_abs(input_dev, ABS_Z, rd[offset+7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) input_report_abs(input_dev, ABS_RZ, rd[offset+8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) input_sync(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) /* Convert timestamp (in 5.33us unit) to timestamp_us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) offset = data_offset + DS4_INPUT_REPORT_TIMESTAMP_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) timestamp = get_unaligned_le16(&rd[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) if (!sc->timestamp_initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) sc->timestamp_us = ((unsigned int)timestamp * 16) / 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) sc->timestamp_initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) u16 delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (sc->prev_timestamp > timestamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) delta = (U16_MAX - sc->prev_timestamp + timestamp + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) delta = timestamp - sc->prev_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) sc->timestamp_us += (delta * 16) / 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) sc->prev_timestamp = timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) input_event(sc->sensor_dev, EV_MSC, MSC_TIMESTAMP, sc->timestamp_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) offset = data_offset + DS4_INPUT_REPORT_GYRO_X_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) for (n = 0; n < 6; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) /* Store data in int for more precision during mult_frac. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) int raw_data = (short)((rd[offset+1] << 8) | rd[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) struct ds4_calibration_data *calib = &sc->ds4_calib_data[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) /* High precision is needed during calibration, but the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) * calibrated values are within 32-bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) * Note: we swap numerator 'x' and 'numer' in mult_frac for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) * precision reasons so we don't need 64-bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) int calib_data = mult_frac(calib->sens_numer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) raw_data - calib->bias,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) calib->sens_denom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) input_report_abs(sc->sensor_dev, calib->abs_code, calib_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) offset += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) input_sync(sc->sensor_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) * The lower 4 bits of byte 30 (or 32 for BT) contain the battery level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) * and the 5th bit contains the USB cable state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) offset = data_offset + DS4_INPUT_REPORT_BATTERY_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) cable_state = (rd[offset] >> 4) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) battery_capacity = rd[offset] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) * When a USB power source is connected the battery level ranges from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) * 0 to 10, and when running on battery power it ranges from 0 to 9.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) * A battery level above 10 when plugged in means charge completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (!cable_state || battery_capacity > 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) battery_charging = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) battery_charging = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (!cable_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) battery_capacity++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (battery_capacity > 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) battery_capacity = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) battery_capacity *= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) sc->cable_state = cable_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) sc->battery_capacity = battery_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) sc->battery_charging = battery_charging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) * The Dualshock 4 multi-touch trackpad data starts at offset 33 on USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) * and 35 on Bluetooth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) * The first byte indicates the number of touch data in the report.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) * Trackpad data starts 2 bytes later (e.g. 35 for USB).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) offset = data_offset + DS4_INPUT_REPORT_TOUCHPAD_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) max_touch_data = (sc->quirks & DUALSHOCK4_CONTROLLER_BT) ? 4 : 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (rd[offset] > 0 && rd[offset] <= max_touch_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) num_touch_data = rd[offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) num_touch_data = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) offset += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) for (m = 0; m < num_touch_data; m++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) /* Skip past timestamp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) offset += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) * The first 7 bits of the first byte is a counter and bit 8 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) * a touch indicator that is 0 when pressed and 1 when not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) * pressed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) * The next 3 bytes are two 12 bit touch coordinates, X and Y.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) * The data for the second touch is in the same format and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) * immediately follows the data for the first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) for (n = 0; n < 2; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) u16 x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) bool active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) x = rd[offset+1] | ((rd[offset+2] & 0xF) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) y = ((rd[offset+2] & 0xF0) >> 4) | (rd[offset+3] << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) active = !(rd[offset] >> 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) input_mt_slot(sc->touchpad, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) input_mt_report_slot_state(sc->touchpad, MT_TOOL_FINGER, active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) input_report_abs(sc->touchpad, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) input_report_abs(sc->touchpad, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) offset += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) input_mt_sync_frame(sc->touchpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) input_sync(sc->touchpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static void nsg_mrxu_parse_report(struct sony_sc *sc, u8 *rd, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) int n, offset, relx, rely;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) u8 active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) * The NSG-MRxU multi-touch trackpad data starts at offset 1 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) * the touch-related data starts at offset 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) * For the first byte, bit 0 is set when touchpad button is pressed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) * Bit 2 is set when a touch is active and the drag (Fn) key is pressed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) * This drag key is mapped to BTN_LEFT. It is operational only when a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) * touch point is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) * Bit 4 is set when only the first touch point is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) * Bit 6 is set when only the second touch point is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) * Bits 5 and 7 are set when both touch points are active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) * The next 3 bytes are two 12 bit X/Y coordinates for the first touch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) * The following byte, offset 5, has the touch width and length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * Bits 0-4=X (width), bits 5-7=Y (length).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) * A signed relative X coordinate is at offset 6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) * The bytes at offset 7-9 are the second touch X/Y coordinates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) * Offset 10 has the second touch width and length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) * Offset 11 has the relative Y coordinate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) offset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) input_report_key(sc->touchpad, BTN_LEFT, rd[offset] & 0x0F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) active = (rd[offset] >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) relx = (s8) rd[offset+5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) rely = ((s8) rd[offset+10]) * -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) offset++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) for (n = 0; n < 2; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) u16 x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) u8 contactx, contacty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) x = rd[offset] | ((rd[offset+1] & 0x0F) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) y = ((rd[offset+1] & 0xF0) >> 4) | (rd[offset+2] << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) input_mt_slot(sc->touchpad, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) input_mt_report_slot_state(sc->touchpad, MT_TOOL_FINGER, active & 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) if (active & 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) contactx = rd[offset+3] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) contacty = rd[offset+3] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) input_report_abs(sc->touchpad, ABS_MT_TOUCH_MAJOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) max(contactx, contacty));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) input_report_abs(sc->touchpad, ABS_MT_TOUCH_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) min(contactx, contacty));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) input_report_abs(sc->touchpad, ABS_MT_ORIENTATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) (bool) (contactx > contacty));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) input_report_abs(sc->touchpad, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) input_report_abs(sc->touchpad, ABS_MT_POSITION_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) NSG_MRXU_MAX_Y - y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) * The relative coordinates belong to the first touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) * point, when present, or to the second touch point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) * when the first is not active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) if ((n == 0) || ((n == 1) && (active & 0x01))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) input_report_rel(sc->touchpad, REL_X, relx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) input_report_rel(sc->touchpad, REL_Y, rely);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) offset += 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) active >>= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) input_mt_sync_frame(sc->touchpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) input_sync(sc->touchpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) static int sony_raw_event(struct hid_device *hdev, struct hid_report *report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) u8 *rd, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) * Sixaxis HID report has acclerometers/gyro with MSByte first, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) * has to be BYTE_SWAPPED before passing up to joystick interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] == 0x01 && size == 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) * When connected via Bluetooth the Sixaxis occasionally sends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) * a report with the second byte 0xff and the rest zeroed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) * This report does not reflect the actual state of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) * controller must be ignored to avoid generating false input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) * events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) if (rd[1] == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) swap(rd[41], rd[42]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) swap(rd[43], rd[44]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) swap(rd[45], rd[46]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) swap(rd[47], rd[48]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) sixaxis_parse_report(sc, rd, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) } else if ((sc->quirks & MOTION_CONTROLLER_BT) && rd[0] == 0x01 && size == 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) sixaxis_parse_report(sc, rd, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) } else if ((sc->quirks & NAVIGATION_CONTROLLER) && rd[0] == 0x01 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) size == 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) sixaxis_parse_report(sc, rd, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) size == 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) dualshock4_parse_report(sc, rd, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && rd[0] == 0x11 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) size == 78)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) /* CRC check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) u8 bthdr = 0xA1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) u32 crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) u32 report_crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) crc = crc32_le(0xFFFFFFFF, &bthdr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) crc = ~crc32_le(crc, rd, DS4_INPUT_REPORT_0x11_SIZE-4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) report_crc = get_unaligned_le32(&rd[DS4_INPUT_REPORT_0x11_SIZE-4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) if (crc != report_crc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) hid_dbg(sc->hdev, "DualShock 4 input report's CRC check failed, received crc 0x%0x != 0x%0x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) report_crc, crc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) dualshock4_parse_report(sc, rd, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) } else if ((sc->quirks & DUALSHOCK4_DONGLE) && rd[0] == 0x01 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) size == 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) enum ds4_dongle_state dongle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) * In the case of a DS4 USB dongle, bit[2] of byte 31 indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) * if a DS4 is actually connected (indicated by '0').
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) * For non-dongle, this bit is always 0 (connected).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) bool connected = (rd[31] & 0x04) ? false : true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) dongle_state = sc->ds4_dongle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) * The dongle always sends input reports even when no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) * DS4 is attached. When a DS4 is connected, we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) * obtain calibration data before we can use it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * The code below tracks dongle state and kicks of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) * calibration when needed and only allows us to process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * input if a DS4 is actually connected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (dongle_state == DONGLE_DISCONNECTED && connected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) hid_info(sc->hdev, "DualShock 4 USB dongle: controller connected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) sony_set_leds(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) sc->ds4_dongle_state = DONGLE_CALIBRATING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) sony_schedule_work(sc, SONY_WORKER_HOTPLUG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) /* Don't process the report since we don't have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) * calibration data, but let hidraw have it anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) } else if ((dongle_state == DONGLE_CONNECTED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) dongle_state == DONGLE_DISABLED) && !connected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) hid_info(sc->hdev, "DualShock 4 USB dongle: controller disconnected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) sc->ds4_dongle_state = DONGLE_DISCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) /* Return 0, so hidraw can get the report. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) } else if (dongle_state == DONGLE_CALIBRATING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) dongle_state == DONGLE_DISABLED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) dongle_state == DONGLE_DISCONNECTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) /* Return 0, so hidraw can get the report. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) dualshock4_parse_report(sc, rd, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) } else if ((sc->quirks & NSG_MRXU_REMOTE) && rd[0] == 0x02) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) nsg_mrxu_parse_report(sc, rd, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) if (sc->defer_initialization) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) sc->defer_initialization = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) sony_schedule_work(sc, SONY_WORKER_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) static int sony_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) if (sc->quirks & BUZZ_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) unsigned int key = usage->hid & HID_USAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) switch (usage->collection_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) if (key >= ARRAY_SIZE(buzz_keymap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) key = buzz_keymap[key];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) if (sc->quirks & PS3REMOTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) return ps3remote_mapping(hdev, hi, field, usage, bit, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if (sc->quirks & NAVIGATION_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) return navigation_mapping(hdev, hi, field, usage, bit, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) if (sc->quirks & SIXAXIS_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) return sixaxis_mapping(hdev, hi, field, usage, bit, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) if (sc->quirks & DUALSHOCK4_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) return ds4_mapping(hdev, hi, field, usage, bit, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) /* Let hid-core decide for the others */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) static int sony_register_touchpad(struct sony_sc *sc, int touch_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) int w, int h, int touch_major, int touch_minor, int orientation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) size_t name_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) sc->touchpad = devm_input_allocate_device(&sc->hdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) if (!sc->touchpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) input_set_drvdata(sc->touchpad, sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) sc->touchpad->dev.parent = &sc->hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) sc->touchpad->phys = sc->hdev->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) sc->touchpad->uniq = sc->hdev->uniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) sc->touchpad->id.bustype = sc->hdev->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) sc->touchpad->id.vendor = sc->hdev->vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) sc->touchpad->id.product = sc->hdev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) sc->touchpad->id.version = sc->hdev->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) /* Append a suffix to the controller name as there are various
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) * DS4 compatible non-Sony devices with different names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) sc->touchpad->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) /* We map the button underneath the touchpad to BTN_LEFT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) __set_bit(EV_KEY, sc->touchpad->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) __set_bit(BTN_LEFT, sc->touchpad->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) __set_bit(INPUT_PROP_BUTTONPAD, sc->touchpad->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) input_set_abs_params(sc->touchpad, ABS_MT_POSITION_X, 0, w, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) input_set_abs_params(sc->touchpad, ABS_MT_POSITION_Y, 0, h, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) if (touch_major > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 0, touch_major, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) if (touch_minor > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 0, touch_minor, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) if (orientation > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 0, orientation, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) if (sc->quirks & NSG_MRXU_REMOTE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) __set_bit(EV_REL, sc->touchpad->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) ret = input_register_device(sc->touchpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) static int sony_register_sensors(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) size_t name_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) int range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) sc->sensor_dev = devm_input_allocate_device(&sc->hdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (!sc->sensor_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) input_set_drvdata(sc->sensor_dev, sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) sc->sensor_dev->dev.parent = &sc->hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) sc->sensor_dev->phys = sc->hdev->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) sc->sensor_dev->uniq = sc->hdev->uniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) sc->sensor_dev->id.bustype = sc->hdev->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) sc->sensor_dev->id.vendor = sc->hdev->vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) sc->sensor_dev->id.product = sc->hdev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) sc->sensor_dev->id.version = sc->hdev->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) /* Append a suffix to the controller name as there are various
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) * DS4 compatible non-Sony devices with different names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) sc->sensor_dev->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) if (sc->quirks & SIXAXIS_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) /* For the DS3 we only support the accelerometer, which works
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) * quite well even without calibration. The device also has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * a 1-axis gyro, but it is very difficult to manage from within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) * the driver even to get data, the sensor is inaccurate and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) * the behavior is very different between hardware revisions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) input_set_abs_params(sc->sensor_dev, ABS_X, -512, 511, 4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) input_set_abs_params(sc->sensor_dev, ABS_Y, -512, 511, 4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) input_set_abs_params(sc->sensor_dev, ABS_Z, -512, 511, 4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) input_abs_set_res(sc->sensor_dev, ABS_X, SIXAXIS_ACC_RES_PER_G);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) input_abs_set_res(sc->sensor_dev, ABS_Y, SIXAXIS_ACC_RES_PER_G);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) input_abs_set_res(sc->sensor_dev, ABS_Z, SIXAXIS_ACC_RES_PER_G);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) range = DS4_ACC_RES_PER_G*4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) input_set_abs_params(sc->sensor_dev, ABS_X, -range, range, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) input_set_abs_params(sc->sensor_dev, ABS_Y, -range, range, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) input_set_abs_params(sc->sensor_dev, ABS_Z, -range, range, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) input_abs_set_res(sc->sensor_dev, ABS_X, DS4_ACC_RES_PER_G);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) input_abs_set_res(sc->sensor_dev, ABS_Y, DS4_ACC_RES_PER_G);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) input_abs_set_res(sc->sensor_dev, ABS_Z, DS4_ACC_RES_PER_G);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) range = DS4_GYRO_RES_PER_DEG_S*2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) input_set_abs_params(sc->sensor_dev, ABS_RX, -range, range, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) input_set_abs_params(sc->sensor_dev, ABS_RY, -range, range, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) input_set_abs_params(sc->sensor_dev, ABS_RZ, -range, range, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) input_abs_set_res(sc->sensor_dev, ABS_RX, DS4_GYRO_RES_PER_DEG_S);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) input_abs_set_res(sc->sensor_dev, ABS_RY, DS4_GYRO_RES_PER_DEG_S);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) input_abs_set_res(sc->sensor_dev, ABS_RZ, DS4_GYRO_RES_PER_DEG_S);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) __set_bit(EV_MSC, sc->sensor_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) __set_bit(MSC_TIMESTAMP, sc->sensor_dev->mscbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) __set_bit(INPUT_PROP_ACCELEROMETER, sc->sensor_dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) ret = input_register_device(sc->sensor_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) * to "operational". Without this, the ps3 controller will not report any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) * events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) static int sixaxis_set_operational_usb(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) const int buf_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) max(SIXAXIS_REPORT_0xF2_SIZE, SIXAXIS_REPORT_0xF5_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) buf = kmalloc(buf_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) ret = hid_hw_raw_request(hdev, 0xf2, buf, SIXAXIS_REPORT_0xF2_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) hid_err(hdev, "can't set operational mode: step 1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) * Some compatible controllers like the Speedlink Strike FX and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) * Gasia need another query plus an USB interrupt to get operational.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) ret = hid_hw_raw_request(hdev, 0xf5, buf, SIXAXIS_REPORT_0xF5_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) hid_err(hdev, "can't set operational mode: step 2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) * But the USB interrupt would cause SHANWAN controllers to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) * start rumbling non-stop, so skip step 3 for these controllers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) if (sc->quirks & SHANWAN_GAMEPAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) ret = hid_hw_output_report(hdev, buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) hid_info(hdev, "can't set operational mode: step 3, ignoring\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) static int sixaxis_set_operational_bt(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) static const u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) buf = kmemdup(report, sizeof(report), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) * Request DS4 calibration data for the motion sensors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) * For Bluetooth this also affects the operating mode (see below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) static int dualshock4_get_calibration_data(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) short gyro_pitch_bias, gyro_pitch_plus, gyro_pitch_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) short gyro_yaw_bias, gyro_yaw_plus, gyro_yaw_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) short gyro_roll_bias, gyro_roll_plus, gyro_roll_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) short gyro_speed_plus, gyro_speed_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) short acc_x_plus, acc_x_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) short acc_y_plus, acc_y_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) short acc_z_plus, acc_z_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) int speed_2x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) int range_2g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) /* For Bluetooth we use a different request, which supports CRC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) * Note: in Bluetooth mode feature report 0x02 also changes the state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) * of the controller, so that it sends input reports of type 0x11.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) buf = kmalloc(DS4_FEATURE_REPORT_0x02_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) ret = hid_hw_raw_request(sc->hdev, 0x02, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) DS4_FEATURE_REPORT_0x02_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) u8 bthdr = 0xA3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) u32 crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) u32 report_crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) int retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) buf = kmalloc(DS4_FEATURE_REPORT_0x05_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) for (retries = 0; retries < 3; retries++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) ret = hid_hw_raw_request(sc->hdev, 0x05, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) DS4_FEATURE_REPORT_0x05_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) /* CRC check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) crc = crc32_le(0xFFFFFFFF, &bthdr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) crc = ~crc32_le(crc, buf, DS4_FEATURE_REPORT_0x05_SIZE-4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) report_crc = get_unaligned_le32(&buf[DS4_FEATURE_REPORT_0x05_SIZE-4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) if (crc != report_crc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) hid_warn(sc->hdev, "DualShock 4 calibration report's CRC check failed, received crc 0x%0x != 0x%0x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) report_crc, crc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) if (retries < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) hid_warn(sc->hdev, "Retrying DualShock 4 get calibration report request\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) ret = -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) gyro_pitch_bias = get_unaligned_le16(&buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) gyro_yaw_bias = get_unaligned_le16(&buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) gyro_roll_bias = get_unaligned_le16(&buf[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) gyro_pitch_plus = get_unaligned_le16(&buf[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) gyro_pitch_minus = get_unaligned_le16(&buf[9]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) gyro_yaw_plus = get_unaligned_le16(&buf[11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) gyro_yaw_minus = get_unaligned_le16(&buf[13]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) gyro_roll_plus = get_unaligned_le16(&buf[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) gyro_roll_minus = get_unaligned_le16(&buf[17]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) /* BT + Dongle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) gyro_pitch_plus = get_unaligned_le16(&buf[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) gyro_yaw_plus = get_unaligned_le16(&buf[9]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) gyro_roll_plus = get_unaligned_le16(&buf[11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) gyro_pitch_minus = get_unaligned_le16(&buf[13]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) gyro_yaw_minus = get_unaligned_le16(&buf[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) gyro_roll_minus = get_unaligned_le16(&buf[17]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) gyro_speed_plus = get_unaligned_le16(&buf[19]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) gyro_speed_minus = get_unaligned_le16(&buf[21]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) acc_x_plus = get_unaligned_le16(&buf[23]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) acc_x_minus = get_unaligned_le16(&buf[25]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) acc_y_plus = get_unaligned_le16(&buf[27]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) acc_y_minus = get_unaligned_le16(&buf[29]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) acc_z_plus = get_unaligned_le16(&buf[31]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) acc_z_minus = get_unaligned_le16(&buf[33]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) /* Set gyroscope calibration and normalization parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) * Data values will be normalized to 1/DS4_GYRO_RES_PER_DEG_S degree/s.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) speed_2x = (gyro_speed_plus + gyro_speed_minus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) sc->ds4_calib_data[0].abs_code = ABS_RX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) sc->ds4_calib_data[0].bias = gyro_pitch_bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) sc->ds4_calib_data[0].sens_numer = speed_2x*DS4_GYRO_RES_PER_DEG_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) sc->ds4_calib_data[0].sens_denom = gyro_pitch_plus - gyro_pitch_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) sc->ds4_calib_data[1].abs_code = ABS_RY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) sc->ds4_calib_data[1].bias = gyro_yaw_bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) sc->ds4_calib_data[1].sens_numer = speed_2x*DS4_GYRO_RES_PER_DEG_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) sc->ds4_calib_data[1].sens_denom = gyro_yaw_plus - gyro_yaw_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) sc->ds4_calib_data[2].abs_code = ABS_RZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) sc->ds4_calib_data[2].bias = gyro_roll_bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) sc->ds4_calib_data[2].sens_numer = speed_2x*DS4_GYRO_RES_PER_DEG_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) sc->ds4_calib_data[2].sens_denom = gyro_roll_plus - gyro_roll_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) /* Set accelerometer calibration and normalization parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) * Data values will be normalized to 1/DS4_ACC_RES_PER_G G.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) range_2g = acc_x_plus - acc_x_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) sc->ds4_calib_data[3].abs_code = ABS_X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) sc->ds4_calib_data[3].bias = acc_x_plus - range_2g / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) sc->ds4_calib_data[3].sens_numer = 2*DS4_ACC_RES_PER_G;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) sc->ds4_calib_data[3].sens_denom = range_2g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) range_2g = acc_y_plus - acc_y_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) sc->ds4_calib_data[4].abs_code = ABS_Y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) sc->ds4_calib_data[4].bias = acc_y_plus - range_2g / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) sc->ds4_calib_data[4].sens_numer = 2*DS4_ACC_RES_PER_G;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) sc->ds4_calib_data[4].sens_denom = range_2g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) range_2g = acc_z_plus - acc_z_minus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) sc->ds4_calib_data[5].abs_code = ABS_Z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) sc->ds4_calib_data[5].bias = acc_z_plus - range_2g / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) sc->ds4_calib_data[5].sens_numer = 2*DS4_ACC_RES_PER_G;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) sc->ds4_calib_data[5].sens_denom = range_2g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) err_stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) static void dualshock4_calibration_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) struct sony_sc *sc = container_of(work, struct sony_sc, hotplug_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) enum ds4_dongle_state dongle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) ret = dualshock4_get_calibration_data(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) /* This call is very unlikely to fail for the dongle. When it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) * fails we are probably in a very bad state, so mark the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) * dongle as disabled. We will re-enable the dongle if a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) * DS4 hotplug is detect from sony_raw_event as any issues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) * are likely resolved then (the dongle is quite stupid).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) hid_err(sc->hdev, "DualShock 4 USB dongle: calibration failed, disabling device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) dongle_state = DONGLE_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) hid_info(sc->hdev, "DualShock 4 USB dongle: calibration completed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) dongle_state = DONGLE_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) sc->ds4_dongle_state = dongle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) static int dualshock4_get_version_info(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) buf = kmalloc(DS4_FEATURE_REPORT_0xA3_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) ret = hid_hw_raw_request(sc->hdev, 0xA3, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) DS4_FEATURE_REPORT_0xA3_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) sc->hw_version = get_unaligned_le16(&buf[35]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) sc->fw_version = get_unaligned_le16(&buf[41]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) static void sixaxis_set_leds_from_id(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) static const u8 sixaxis_leds[10][4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) { 0x01, 0x00, 0x00, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) { 0x00, 0x01, 0x00, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) { 0x00, 0x00, 0x01, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) { 0x00, 0x00, 0x00, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) { 0x01, 0x00, 0x00, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) { 0x00, 0x01, 0x00, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) { 0x00, 0x00, 0x01, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) { 0x01, 0x00, 0x01, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) { 0x00, 0x01, 0x01, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) { 0x01, 0x01, 0x01, 0x01 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) int id = sc->device_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(sixaxis_leds[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) if (id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) id %= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) memcpy(sc->led_state, sixaxis_leds[id], sizeof(sixaxis_leds[id]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) static void dualshock4_set_leds_from_id(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) /* The first 4 color/index entries match what the PS4 assigns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) static const u8 color_code[7][3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) /* Blue */ { 0x00, 0x00, 0x40 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) /* Red */ { 0x40, 0x00, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) /* Green */ { 0x00, 0x40, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) /* Pink */ { 0x20, 0x00, 0x20 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) /* Orange */ { 0x02, 0x01, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) /* Teal */ { 0x00, 0x01, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) /* White */ { 0x01, 0x01, 0x01 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) int id = sc->device_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(color_code[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) if (id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) id %= 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) memcpy(sc->led_state, color_code[id], sizeof(color_code[id]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) static void buzz_set_leds(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) struct hid_device *hdev = sc->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) struct list_head *report_list =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) struct hid_report *report = list_entry(report_list->next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) struct hid_report, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) s32 *value = report->field[0]->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) BUILD_BUG_ON(MAX_LEDS < 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) value[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) value[1] = sc->led_state[0] ? 0xff : 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) value[2] = sc->led_state[1] ? 0xff : 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) value[3] = sc->led_state[2] ? 0xff : 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) value[4] = sc->led_state[3] ? 0xff : 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) value[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) value[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) static void sony_set_leds(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) if (!(sc->quirks & BUZZ_CONTROLLER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) sony_schedule_work(sc, SONY_WORKER_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) buzz_set_leds(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) static void sony_led_set_brightness(struct led_classdev *led,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) struct device *dev = led->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) struct sony_sc *drv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) int force_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) drv_data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) if (!drv_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) hid_err(hdev, "No device data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) * The Sixaxis on USB will override any LED settings sent to it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) * and keep flashing all of the LEDs until the PS button is pressed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) * Updates, even if redundant, must be always be sent to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) * controller to avoid having to toggle the state of an LED just to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) * stop the flashing later on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) force_update = !!(drv_data->quirks & SIXAXIS_CONTROLLER_USB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) for (n = 0; n < drv_data->led_count; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) if (led == drv_data->leds[n] && (force_update ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) (value != drv_data->led_state[n] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) drv_data->led_delay_on[n] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) drv_data->led_delay_off[n]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) drv_data->led_state[n] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) /* Setting the brightness stops the blinking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) drv_data->led_delay_on[n] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) drv_data->led_delay_off[n] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) sony_set_leds(drv_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) static enum led_brightness sony_led_get_brightness(struct led_classdev *led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) struct device *dev = led->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) struct sony_sc *drv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) drv_data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) if (!drv_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) hid_err(hdev, "No device data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) return LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) for (n = 0; n < drv_data->led_count; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) if (led == drv_data->leds[n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) return drv_data->led_state[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) return LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) unsigned long *delay_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) struct device *dev = led->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) struct sony_sc *drv_data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) u8 new_on, new_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) if (!drv_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) hid_err(hdev, "No device data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) /* Max delay is 255 deciseconds or 2550 milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) if (*delay_on > 2550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) *delay_on = 2550;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) if (*delay_off > 2550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) *delay_off = 2550;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) /* Blink at 1 Hz if both values are zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) if (!*delay_on && !*delay_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) *delay_on = *delay_off = 500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) new_on = *delay_on / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) new_off = *delay_off / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) for (n = 0; n < drv_data->led_count; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) if (led == drv_data->leds[n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) /* This LED is not registered on this device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) if (n >= drv_data->led_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) /* Don't schedule work if the values didn't change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) if (new_on != drv_data->led_delay_on[n] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) new_off != drv_data->led_delay_off[n]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) drv_data->led_delay_on[n] = new_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) drv_data->led_delay_off[n] = new_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) sony_schedule_work(drv_data, SONY_WORKER_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) static int sony_leds_init(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) struct hid_device *hdev = sc->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) int n, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) int use_ds4_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) struct led_classdev *led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) size_t name_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) size_t name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) const char *name_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) static const char * const ds4_name_str[] = { "red", "green", "blue",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) "global" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) u8 max_brightness[MAX_LEDS] = { [0 ... (MAX_LEDS - 1)] = 1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) u8 use_hw_blink[MAX_LEDS] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) if (sc->quirks & BUZZ_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) sc->led_count = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) use_ds4_names = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) name_len = strlen("::buzz#");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) name_fmt = "%s::buzz%d";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) /* Validate expected report characteristics. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) dualshock4_set_leds_from_id(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) sc->led_state[3] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) sc->led_count = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) memset(max_brightness, 255, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) use_hw_blink[3] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) use_ds4_names = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) name_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) name_fmt = "%s:%s";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) } else if (sc->quirks & MOTION_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) sc->led_count = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) memset(max_brightness, 255, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) use_ds4_names = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) name_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) name_fmt = "%s:%s";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) } else if (sc->quirks & NAVIGATION_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) static const u8 navigation_leds[4] = {0x01, 0x00, 0x00, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) memcpy(sc->led_state, navigation_leds, sizeof(navigation_leds));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) sc->led_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) memset(use_hw_blink, 1, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) use_ds4_names = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) name_len = strlen("::sony#");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) name_fmt = "%s::sony%d";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) sixaxis_set_leds_from_id(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) sc->led_count = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) memset(use_hw_blink, 1, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) use_ds4_names = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) name_len = strlen("::sony#");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) name_fmt = "%s::sony%d";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) * Clear LEDs as we have no way of reading their initial state. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) * only relevant if the driver is loaded after somebody actively set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) * LEDs to on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) sony_set_leds(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) for (n = 0; n < sc->led_count; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) if (use_ds4_names)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) if (!led) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) name = (void *)(&led[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) if (use_ds4_names)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) ds4_name_str[n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) led->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) led->brightness = sc->led_state[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) led->max_brightness = max_brightness[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) led->flags = LED_CORE_SUSPENDRESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) led->brightness_get = sony_led_get_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) led->brightness_set = sony_led_set_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) if (use_hw_blink[n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) led->blink_set = sony_led_blink_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) sc->leds[n] = led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) ret = devm_led_classdev_register(&hdev->dev, led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) hid_err(hdev, "Failed to register LED %d\n", n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) static void sixaxis_send_output_report(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) static const union sixaxis_output_report_01 default_report = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) .buf = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 0x01, 0xff, 0x00, 0xff, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 0x00, 0x00, 0x00, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 0xff, 0x27, 0x10, 0x00, 0x32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 0xff, 0x27, 0x10, 0x00, 0x32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 0xff, 0x27, 0x10, 0x00, 0x32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 0xff, 0x27, 0x10, 0x00, 0x32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 0x00, 0x00, 0x00, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) struct sixaxis_output_report *report =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) (struct sixaxis_output_report *)sc->output_report_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) /* Initialize the report with default values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) #ifdef CONFIG_SONY_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) report->rumble.right_motor_on = sc->right ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) report->rumble.left_motor_force = sc->left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) report->leds_bitmap |= sc->led_state[0] << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) report->leds_bitmap |= sc->led_state[1] << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) report->leds_bitmap |= sc->led_state[2] << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) report->leds_bitmap |= sc->led_state[3] << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) /* Set flag for all leds off, required for 3rd party INTEC controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) if ((report->leds_bitmap & 0x1E) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) report->leds_bitmap |= 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) * The LEDs in the report are indexed in reverse order to their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) * corresponding light on the controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) * Index 0 = LED 4, index 1 = LED 3, etc...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) * In the case of both delay values being zero (blinking disabled) the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) * default report values should be used or the controller LED will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) * always off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) for (n = 0; n < 4; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) report->led[3 - n].duty_off = sc->led_delay_off[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) report->led[3 - n].duty_on = sc->led_delay_on[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) /* SHANWAN controllers require output reports via intr channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) if (sc->quirks & SHANWAN_GAMEPAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) hid_hw_output_report(sc->hdev, (u8 *)report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) sizeof(struct sixaxis_output_report));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) hid_hw_raw_request(sc->hdev, report->report_id, (u8 *)report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) sizeof(struct sixaxis_output_report),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) static void dualshock4_send_output_report(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) struct hid_device *hdev = sc->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) u8 *buf = sc->output_report_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) * NOTE: The lower 6 bits of buf[1] field of the Bluetooth report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) * control the interval at which Dualshock 4 reports data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) * 0x00 - 1ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) * 0x01 - 1ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) * 0x02 - 2ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) * 0x3E - 62ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) * 0x3F - disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) memset(buf, 0, DS4_OUTPUT_REPORT_0x05_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) buf[0] = 0x05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) buf[1] = 0x07; /* blink + LEDs + motor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) offset = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) memset(buf, 0, DS4_OUTPUT_REPORT_0x11_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) buf[0] = 0x11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) buf[1] = 0xC0 /* HID + CRC */ | sc->ds4_bt_poll_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) buf[3] = 0x07; /* blink + LEDs + motor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) offset = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) #ifdef CONFIG_SONY_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) buf[offset++] = sc->right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) buf[offset++] = sc->left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) offset += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) /* LED 3 is the global control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) if (sc->led_state[3]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) buf[offset++] = sc->led_state[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) buf[offset++] = sc->led_state[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) buf[offset++] = sc->led_state[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) offset += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) /* If both delay values are zero the DualShock 4 disables blinking. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) buf[offset++] = sc->led_delay_on[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) buf[offset++] = sc->led_delay_off[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) hid_hw_output_report(hdev, buf, DS4_OUTPUT_REPORT_0x05_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) /* CRC generation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) u8 bthdr = 0xA2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) u32 crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) crc = crc32_le(0xFFFFFFFF, &bthdr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) crc = ~crc32_le(crc, buf, DS4_OUTPUT_REPORT_0x11_SIZE-4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) put_unaligned_le32(crc, &buf[74]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) hid_hw_output_report(hdev, buf, DS4_OUTPUT_REPORT_0x11_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) static void motion_send_output_report(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) struct hid_device *hdev = sc->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) struct motion_output_report_02 *report =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) (struct motion_output_report_02 *)sc->output_report_dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) memset(report, 0, MOTION_REPORT_0x02_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) report->type = 0x02; /* set leds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) report->r = sc->led_state[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) report->g = sc->led_state[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) report->b = sc->led_state[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) #ifdef CONFIG_SONY_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) report->rumble = max(sc->right, sc->left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) hid_hw_output_report(hdev, (u8 *)report, MOTION_REPORT_0x02_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) static inline void sony_send_output_report(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) if (sc->send_output_report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) sc->send_output_report(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) static void sony_state_worker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) sc->send_output_report(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) static int sony_allocate_output_report(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) if ((sc->quirks & SIXAXIS_CONTROLLER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) (sc->quirks & NAVIGATION_CONTROLLER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) sc->output_report_dmabuf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) devm_kmalloc(&sc->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) sizeof(union sixaxis_output_report_01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) DS4_OUTPUT_REPORT_0x11_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) DS4_OUTPUT_REPORT_0x05_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) else if (sc->quirks & MOTION_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) MOTION_REPORT_0x02_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) if (!sc->output_report_dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) #ifdef CONFIG_SONY_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) static int sony_play_effect(struct input_dev *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) struct hid_device *hid = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) struct sony_sc *sc = hid_get_drvdata(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) if (effect->type != FF_RUMBLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) sc->left = effect->u.rumble.strong_magnitude / 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) sc->right = effect->u.rumble.weak_magnitude / 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) sony_schedule_work(sc, SONY_WORKER_STATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) static int sony_init_ff(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) struct hid_input *hidinput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) if (list_empty(&sc->hdev->inputs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) hid_err(sc->hdev, "no inputs found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) hidinput = list_entry(sc->hdev->inputs.next, struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) input_dev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) input_set_capability(input_dev, EV_FF, FF_RUMBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) return input_ff_create_memless(input_dev, NULL, sony_play_effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) static int sony_init_ff(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) static int sony_battery_get_property(struct power_supply *psy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) enum power_supply_property psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) union power_supply_propval *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) struct sony_sc *sc = power_supply_get_drvdata(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) u8 battery_charging, battery_capacity, cable_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) battery_charging = sc->battery_charging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) battery_capacity = sc->battery_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) cable_state = sc->cable_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) switch (psp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) case POWER_SUPPLY_PROP_PRESENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) val->intval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) case POWER_SUPPLY_PROP_SCOPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) val->intval = POWER_SUPPLY_SCOPE_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) case POWER_SUPPLY_PROP_CAPACITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) val->intval = battery_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) case POWER_SUPPLY_PROP_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) if (battery_charging)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) val->intval = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) if (battery_capacity == 100 && cable_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) val->intval = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) static int sony_battery_probe(struct sony_sc *sc, int append_dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) const char *battery_str_fmt = append_dev_id ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) "sony_controller_battery_%pMR_%i" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) "sony_controller_battery_%pMR";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) struct power_supply_config psy_cfg = { .drv_data = sc, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) struct hid_device *hdev = sc->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) * Set the default battery level to 100% to avoid low battery warnings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) * if the battery is polled before the first device report is received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) sc->battery_capacity = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) sc->battery_desc.properties = sony_battery_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) sc->battery_desc.get_property = sony_battery_get_property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) sc->battery_desc.use_for_apm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) sc->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) battery_str_fmt, sc->mac_address, sc->device_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) if (!sc->battery_desc.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) sc->battery = devm_power_supply_register(&hdev->dev, &sc->battery_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) &psy_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) if (IS_ERR(sc->battery)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) ret = PTR_ERR(sc->battery);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) hid_err(hdev, "Unable to register battery device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) power_supply_powers(sc->battery, &hdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) * If a controller is plugged in via USB while already connected via Bluetooth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) * it will show up as two devices. A global list of connected controllers and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) * their MAC addresses is maintained to ensure that a device is only connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) * once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) * Some USB-only devices masquerade as Sixaxis controllers and all have the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) * same dummy Bluetooth address, so a comparison of the connection type is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) * required. Devices are only rejected in the case where two devices have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) * matching Bluetooth addresses on different bus types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) static inline int sony_compare_connection_type(struct sony_sc *sc0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) struct sony_sc *sc1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) const int sc0_not_bt = !(sc0->quirks & SONY_BT_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) const int sc1_not_bt = !(sc1->quirks & SONY_BT_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) return sc0_not_bt == sc1_not_bt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) static int sony_check_add_dev_list(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) struct sony_sc *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) spin_lock_irqsave(&sony_dev_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) list_for_each_entry(entry, &sony_device_list, list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) ret = memcmp(sc->mac_address, entry->mac_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) sizeof(sc->mac_address));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) if (sony_compare_connection_type(sc, entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) ret = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) hid_info(sc->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) "controller with MAC address %pMR already connected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) sc->mac_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) list_add(&(sc->list_node), &sony_device_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) spin_unlock_irqrestore(&sony_dev_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) static void sony_remove_dev_list(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) if (sc->list_node.next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) spin_lock_irqsave(&sony_dev_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) list_del(&(sc->list_node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) spin_unlock_irqrestore(&sony_dev_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) static int sony_get_bt_devaddr(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) /* HIDP stores the device MAC address as a string in the uniq field. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) ret = strlen(sc->hdev->uniq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) if (ret != 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) ret = sscanf(sc->hdev->uniq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) &sc->mac_address[5], &sc->mac_address[4], &sc->mac_address[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) &sc->mac_address[2], &sc->mac_address[1], &sc->mac_address[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) if (ret != 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) static int sony_check_add(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) u8 *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) int n, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) (sc->quirks & MOTION_CONTROLLER_BT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) (sc->quirks & NAVIGATION_CONTROLLER_BT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) (sc->quirks & SIXAXIS_CONTROLLER_BT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) * sony_get_bt_devaddr() attempts to parse the Bluetooth MAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) * address from the uniq string where HIDP stores it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) * As uniq cannot be guaranteed to be a MAC address in all cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) * a failure of this function should not prevent the connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) if (sony_get_bt_devaddr(sc) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) hid_warn(sc->hdev, "UNIQ does not contain a MAC address; duplicate check skipped\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) } else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) buf = kmalloc(DS4_FEATURE_REPORT_0x81_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) * The MAC address of a DS4 controller connected via USB can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) * retrieved with feature report 0x81. The address begins at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) * offset 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) DS4_FEATURE_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) if (ret != DS4_FEATURE_REPORT_0x81_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) ret = ret < 0 ? ret : -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) "%pMR", sc->mac_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) } else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) (sc->quirks & NAVIGATION_CONTROLLER_USB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) * The MAC address of a Sixaxis controller connected via USB can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) * be retrieved with feature report 0xf2. The address begins at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) * offset 4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) ret = ret < 0 ? ret : -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) * The Sixaxis device MAC in the report is big-endian and must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) * be byte-swapped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) for (n = 0; n < 6; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) sc->mac_address[5-n] = buf[4+n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) "%pMR", sc->mac_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) ret = sony_check_add_dev_list(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) static int sony_set_device_id(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) * Only DualShock 4 or Sixaxis controllers get an id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) * All others are set to -1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) if ((sc->quirks & SIXAXIS_CONTROLLER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) (sc->quirks & DUALSHOCK4_CONTROLLER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) ret = ida_simple_get(&sony_device_id_allocator, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) sc->device_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) sc->device_id = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) sc->device_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) static void sony_release_device_id(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) if (sc->device_id >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) ida_simple_remove(&sony_device_id_allocator, sc->device_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) sc->device_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) static inline void sony_init_output_report(struct sony_sc *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) void (*send_output_report)(struct sony_sc *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) sc->send_output_report = send_output_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) if (!sc->state_worker_initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) INIT_WORK(&sc->state_worker, sony_state_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) sc->state_worker_initialized = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) static inline void sony_cancel_work_sync(struct sony_sc *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) if (sc->hotplug_worker_initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) cancel_work_sync(&sc->hotplug_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) if (sc->state_worker_initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) spin_lock_irqsave(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) sc->state_worker_initialized = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) spin_unlock_irqrestore(&sc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) cancel_work_sync(&sc->state_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) static int sony_input_configured(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) struct hid_input *hidinput)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) int append_dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) ret = sony_set_device_id(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) hid_err(hdev, "failed to allocate the device id\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) ret = append_dev_id = sony_check_add(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) ret = sony_allocate_output_report(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) hid_err(hdev, "failed to allocate the output report buffer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) if (sc->quirks & NAVIGATION_CONTROLLER_USB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) * The Sony Sixaxis does not handle HID Output Reports on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) * Interrupt EP like it could, so we need to force HID Output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) * Reports to use HID_REQ_SET_REPORT on the Control EP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) * There is also another issue about HID Output Reports via USB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) * the Sixaxis does not want the report_id as part of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) * packet, so we have to discard buf[0] when sending the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) * control message, even for numbered reports, humpf!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) * Additionally, the Sixaxis on USB isn't properly initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) * until the PS logo button is pressed and as such won't retain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) * any state set by an output report, so the initial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) * configuration report is deferred until the first input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) * report arrives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) sc->defer_initialization = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) ret = sixaxis_set_operational_usb(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) hid_err(hdev, "Failed to set controller into operational mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) sony_init_output_report(sc, sixaxis_send_output_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) } else if (sc->quirks & NAVIGATION_CONTROLLER_BT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) * The Navigation controller wants output reports sent on the ctrl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) * endpoint when connected via Bluetooth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) ret = sixaxis_set_operational_bt(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) hid_err(hdev, "Failed to set controller into operational mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) sony_init_output_report(sc, sixaxis_send_output_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) * The Sony Sixaxis does not handle HID Output Reports on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) * Interrupt EP and the device only becomes active when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) * PS button is pressed. See comment for Navigation controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) * above for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) sc->defer_initialization = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) ret = sixaxis_set_operational_usb(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) hid_err(hdev, "Failed to set controller into operational mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) ret = sony_register_sensors(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) hid_err(sc->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) "Unable to initialize motion sensors: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) sony_init_output_report(sc, sixaxis_send_output_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) } else if (sc->quirks & SIXAXIS_CONTROLLER_BT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) * The Sixaxis wants output reports sent on the ctrl endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) * when connected via Bluetooth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) ret = sixaxis_set_operational_bt(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) hid_err(hdev, "Failed to set controller into operational mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) ret = sony_register_sensors(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) hid_err(sc->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) "Unable to initialize motion sensors: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) sony_init_output_report(sc, sixaxis_send_output_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) } else if (sc->quirks & DUALSHOCK4_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) ret = dualshock4_get_calibration_data(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) hid_err(hdev, "Failed to get calibration data from Dualshock 4\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) ret = dualshock4_get_version_info(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) hid_err(sc->hdev, "Failed to get version data from Dualshock 4\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) ret = device_create_file(&sc->hdev->dev, &dev_attr_firmware_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) /* Make zero for cleanup reasons of sysfs entries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) sc->fw_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) sc->hw_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) hid_err(sc->hdev, "can't create sysfs firmware_version attribute err: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) ret = device_create_file(&sc->hdev->dev, &dev_attr_hardware_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) sc->hw_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) hid_err(sc->hdev, "can't create sysfs hardware_version attribute err: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) * The Dualshock 4 touchpad supports 2 touches and has a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) * resolution of 1920x942 (44.86 dots/mm).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) ret = sony_register_touchpad(sc, 2, 1920, 942, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) hid_err(sc->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) "Unable to initialize multi-touch slots: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) ret = sony_register_sensors(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) hid_err(sc->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) "Unable to initialize motion sensors: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) sc->ds4_bt_poll_interval = DS4_BT_DEFAULT_POLL_INTERVAL_MS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) ret = device_create_file(&sc->hdev->dev, &dev_attr_bt_poll_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) hid_warn(sc->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) "can't create sysfs bt_poll_interval attribute err: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) if (sc->quirks & DUALSHOCK4_DONGLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) INIT_WORK(&sc->hotplug_worker, dualshock4_calibration_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) sc->hotplug_worker_initialized = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) sc->ds4_dongle_state = DONGLE_DISCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) sony_init_output_report(sc, dualshock4_send_output_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) } else if (sc->quirks & NSG_MRXU_REMOTE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) * The NSG-MRxU touchpad supports 2 touches and has a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) * resolution of 1667x1868
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) ret = sony_register_touchpad(sc, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) NSG_MRXU_MAX_X, NSG_MRXU_MAX_Y, 15, 15, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) hid_err(sc->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) "Unable to initialize multi-touch slots: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) } else if (sc->quirks & MOTION_CONTROLLER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) sony_init_output_report(sc, motion_send_output_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) if (sc->quirks & SONY_LED_SUPPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) ret = sony_leds_init(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) if (sc->quirks & SONY_BATTERY_SUPPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) ret = sony_battery_probe(sc, append_dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) /* Open the device to receive reports with battery info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) ret = hid_hw_open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) hid_err(hdev, "hw open failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) goto err_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) if (sc->quirks & SONY_FF_SUPPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) ret = sony_init_ff(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) goto err_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) err_close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) err_stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) /* Piggy back on the default ds4_bt_ poll_interval to determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) * if we need to remove the file as we don't know for sure if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) * executed that logic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) if (sc->ds4_bt_poll_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) if (sc->fw_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) if (sc->hw_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) sony_cancel_work_sync(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) sony_remove_dev_list(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) sony_release_device_id(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) unsigned long quirks = id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) struct sony_sc *sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) unsigned int connect_mask = HID_CONNECT_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) if (!strcmp(hdev->name, "FutureMax Dance Mat"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) quirks |= FUTUREMAX_DANCE_MAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) if (!strcmp(hdev->name, "SHANWAN PS3 GamePad"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) quirks |= SHANWAN_GAMEPAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) if (sc == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) hid_err(hdev, "can't alloc sony descriptor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) spin_lock_init(&sc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) sc->quirks = quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) hid_set_drvdata(hdev, sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) sc->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) if (sc->quirks & VAIO_RDESC_CONSTANT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) connect_mask |= HID_CONNECT_HIDDEV_FORCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) else if (sc->quirks & SIXAXIS_CONTROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) connect_mask |= HID_CONNECT_HIDDEV_FORCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) /* Patch the hw version on DS3/4 compatible devices, so applications can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) * distinguish between the default HID mappings and the mappings defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) * by the Linux game controller spec. This is important for the SDL2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) * library, which has a game controller database, which uses device ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) * in combination with version as a key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) if (sc->quirks & (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) hdev->version |= 0x8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) ret = hid_hw_start(hdev, connect_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) /* sony_input_configured can fail, but this doesn't result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) * in hid_hw_start failures (intended). Check whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) * the HID layer claimed the device else fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) * We don't know the actual reason for the failure, most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) * likely it is due to EEXIST in case of double connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) * of USB and Bluetooth, but could have been due to ENOMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) * or other reasons as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) if (!(hdev->claimed & HID_CLAIMED_INPUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) hid_err(hdev, "failed to claim input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) static void sony_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) if (sc->fw_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) if (sc->hw_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) sony_cancel_work_sync(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) sony_remove_dev_list(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) sony_release_device_id(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) static int sony_suspend(struct hid_device *hdev, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) #ifdef CONFIG_SONY_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) /* On suspend stop any running force-feedback events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) if (SONY_FF_SUPPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) sc->left = sc->right = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) sony_send_output_report(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) static int sony_resume(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) struct sony_sc *sc = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) * The Sixaxis and navigation controllers on USB need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) * reinitialized on resume or they won't behave properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) (sc->quirks & NAVIGATION_CONTROLLER_USB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) sixaxis_set_operational_usb(sc->hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) sc->defer_initialization = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) static const struct hid_device_id sony_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) .driver_data = SIXAXIS_CONTROLLER_USB },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) .driver_data = NAVIGATION_CONTROLLER_USB },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) .driver_data = NAVIGATION_CONTROLLER_BT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) .driver_data = MOTION_CONTROLLER_USB },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) .driver_data = MOTION_CONTROLLER_BT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) .driver_data = SIXAXIS_CONTROLLER_BT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) .driver_data = VAIO_RDESC_CONSTANT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) .driver_data = VAIO_RDESC_CONSTANT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) * Wired Buzz Controller. Reported as Sony Hub from its USB ID and as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) * Logitech joystick from the device descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) .driver_data = BUZZ_CONTROLLER },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) .driver_data = BUZZ_CONTROLLER },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) /* PS3 BD Remote Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) .driver_data = PS3REMOTE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) /* Logitech Harmony Adapter for PS3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) .driver_data = PS3REMOTE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) /* SMK-Link PS3 BD Remote Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) .driver_data = PS3REMOTE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) /* Sony Dualshock 4 controllers for PS4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) .driver_data = DUALSHOCK4_CONTROLLER_USB },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) .driver_data = DUALSHOCK4_CONTROLLER_BT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) .driver_data = DUALSHOCK4_CONTROLLER_USB },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) .driver_data = DUALSHOCK4_CONTROLLER_BT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) .driver_data = DUALSHOCK4_DONGLE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) /* Nyko Core Controller for PS3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) { HID_USB_DEVICE(USB_VENDOR_ID_SINO_LITE, USB_DEVICE_ID_SINO_LITE_CONTROLLER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) .driver_data = SIXAXIS_CONTROLLER_USB | SINO_LITE_CONTROLLER },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) /* SMK-Link NSG-MR5U Remote Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_NSG_MR5U_REMOTE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) .driver_data = NSG_MR5U_REMOTE_BT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) /* SMK-Link NSG-MR7U Remote Control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_NSG_MR7U_REMOTE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) .driver_data = NSG_MR7U_REMOTE_BT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) MODULE_DEVICE_TABLE(hid, sony_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) static struct hid_driver sony_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) .name = "sony",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) .id_table = sony_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) .input_mapping = sony_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) .input_configured = sony_input_configured,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) .probe = sony_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) .remove = sony_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) .report_fixup = sony_report_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) .raw_event = sony_raw_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) .suspend = sony_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) .resume = sony_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) .reset_resume = sony_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) static int __init sony_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) dbg_hid("Sony:%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) return hid_register_driver(&sony_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) static void __exit sony_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) dbg_hid("Sony:%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) hid_unregister_driver(&sony_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) ida_destroy(&sony_device_id_allocator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) module_init(sony_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) module_exit(sony_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) MODULE_LICENSE("GPL");