[PATCH v2] drivers: hid: warn feature report 0x81

From: Henry Castro
Date: Sun Oct 30 2022 - 11:41:24 EST


Unfortunately, my PS DualShock 4, does not support
the feature 0x81 to get the MAC address. Instead,
fallback feature report 0x12, so I can
use DS4 to play Retroarch :)

Signed-off-by: Henry Castro <hcvcastro@xxxxxxxxx>
---

What do you think about patching the existing driver to
fix with the feature 0x12 to obtain the MAC address,
meanwhile the new driver is released?

drivers/hid/hid-sony.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index c10513efe677..ee364bef81a7 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -506,6 +506,8 @@ struct motion_output_report_02 {
#define DS4_FEATURE_REPORT_0x05_SIZE 41
#define DS4_FEATURE_REPORT_0x81_SIZE 7
#define DS4_FEATURE_REPORT_0xA3_SIZE 49
+#define DS4_FEATURE_REPORT_PAIRING_INFO 0x12
+#define DS4_FEATURE_REPORT_PAIRING_INFO_SIZE 16
#define DS4_INPUT_REPORT_0x11_SIZE 78
#define DS4_OUTPUT_REPORT_0x05_SIZE 32
#define DS4_OUTPUT_REPORT_0x11_SIZE 78
@@ -1259,7 +1261,7 @@ static void nsg_mrxu_parse_report(struct sony_sc *sc, u8 *rd, int size)
* the touch-related data starts at offset 2.
* For the first byte, bit 0 is set when touchpad button is pressed.
* Bit 2 is set when a touch is active and the drag (Fn) key is pressed.
- * This drag key is mapped to BTN_LEFT. It is operational only when a
+ * This drag key is mapped to BTN_LEFT. It is operational only when a
* touch point is active.
* Bit 4 is set when only the first touch point is active.
* Bit 6 is set when only the second touch point is active.
@@ -1532,13 +1534,13 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count,
input_set_abs_params(sc->touchpad, ABS_MT_POSITION_Y, 0, h, 0, 0);

if (touch_major > 0) {
- input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR,
+ input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR,
0, touch_major, 0, 0);
if (touch_minor > 0)
- input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR,
+ input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR,
0, touch_minor, 0, 0);
if (orientation > 0)
- input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION,
+ input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION,
0, orientation, 0, 0);
}

@@ -2627,7 +2629,8 @@ static int sony_check_add(struct sony_sc *sc)
return 0;
}
} else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) {
- buf = kmalloc(DS4_FEATURE_REPORT_0x81_SIZE, GFP_KERNEL);
+ buf = kzalloc(DS4_FEATURE_REPORT_PAIRING_INFO_SIZE, GFP_KERNEL);
+
if (!buf)
return -ENOMEM;

@@ -2641,9 +2644,17 @@ static int sony_check_add(struct sony_sc *sc)
HID_REQ_GET_REPORT);

if (ret != DS4_FEATURE_REPORT_0x81_SIZE) {
- hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
- ret = ret < 0 ? ret : -EINVAL;
- goto out_free;
+ hid_warn(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
+
+ ret = hid_hw_raw_request(sc->hdev, DS4_FEATURE_REPORT_PAIRING_INFO,
+ buf, DS4_FEATURE_REPORT_PAIRING_INFO_SIZE,
+ HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+
+ if (ret != DS4_FEATURE_REPORT_PAIRING_INFO_SIZE) {
+ hid_err(sc->hdev, "Failed to retrieve DualShock4 pairing info:%d\n",
+ ret);
+ goto out_free;
+ }
}

memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
--
2.20.1