From c64036ad1e8fa982d84d6627759f702b90f781a9 Mon Sep 17 00:00:00 2001 From: monkaBlyat <54044929+monkaBlyat@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:55:39 +0200 Subject: [PATCH 1/4] legacy kernel patch for ds4 controllers --- patch/kernel/rk35xx-legacy/001-hid-sony.patch | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 patch/kernel/rk35xx-legacy/001-hid-sony.patch diff --git a/patch/kernel/rk35xx-legacy/001-hid-sony.patch b/patch/kernel/rk35xx-legacy/001-hid-sony.patch new file mode 100644 index 000000000000..6d001c38e960 --- /dev/null +++ b/patch/kernel/rk35xx-legacy/001-hid-sony.patch @@ -0,0 +1,111 @@ +Signed-off-by: Ivan Mironov +--- + drivers/hid/hid-sony.c | 72 ++++++++++++++++++++++++++++++------------ + 1 file changed, 52 insertions(+), 20 deletions(-) + +diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c +index e3a557dc9ffd..97df12180e45 100644 +--- a/drivers/hid/hid-sony.c ++++ b/drivers/hid/hid-sony.c +@@ -491,6 +491,7 @@ struct motion_output_report_02 { + + #define DS4_FEATURE_REPORT_0x02_SIZE 37 + #define DS4_FEATURE_REPORT_0x05_SIZE 41 ++#define DS4_FEATURE_REPORT_0x12_SIZE 16 + #define DS4_FEATURE_REPORT_0x81_SIZE 7 + #define DS4_FEATURE_REPORT_0xA3_SIZE 49 + #define DS4_INPUT_REPORT_0x11_SIZE 78 +@@ -2593,6 +2594,53 @@ static int sony_get_bt_devaddr(struct sony_sc *sc) + return 0; + } + ++static int sony_get_usb_ds4_devaddr(struct sony_sc *sc) ++{ ++ u8 *buf = NULL; ++ int ret; ++ ++ buf = kmalloc(max(DS4_FEATURE_REPORT_0x12_SIZE, DS4_FEATURE_REPORT_0x81_SIZE), GFP_KERNEL); ++ if (!buf) ++ return -ENOMEM; ++ ++ /* ++ * The MAC address of a DS4 controller connected via USB can be ++ * retrieved with feature report 0x81. The address begins at ++ * offset 1. ++ */ ++ ret = hid_hw_raw_request(sc->hdev, 0x81, buf, ++ DS4_FEATURE_REPORT_0x81_SIZE, HID_FEATURE_REPORT, ++ HID_REQ_GET_REPORT); ++ if (ret == DS4_FEATURE_REPORT_0x81_SIZE) { ++ memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); ++ goto out_free; ++ } ++ dbg_hid("%s: hid_hw_raw_request(..., 0x81, ...) returned %d\n", __func__, ret); ++ ++ /* ++ * Some variants do not implement feature report 0x81 at all. ++ * Fortunately, feature report 0x12 also contains the MAC address of ++ * a controller. ++ */ ++ ret = hid_hw_raw_request(sc->hdev, 0x12, buf, ++ DS4_FEATURE_REPORT_0x12_SIZE, HID_FEATURE_REPORT, ++ HID_REQ_GET_REPORT); ++ if (ret == DS4_FEATURE_REPORT_0x12_SIZE) { ++ memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); ++ goto out_free; ++ } ++ dbg_hid("%s: hid_hw_raw_request(..., 0x12, ...) returned %d\n", __func__, ret); ++ ++ hid_err(sc->hdev, "failed to retrieve feature reports 0x81 and 0x12 with the DualShock 4 MAC address\n"); ++ ret = ret < 0 ? ret : -EINVAL; ++ ++out_free: ++ ++ kfree(buf); ++ ++ return ret; ++} ++ + static int sony_check_add(struct sony_sc *sc) + { + u8 *buf = NULL; +@@ -2613,26 +2661,9 @@ 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); +- if (!buf) +- return -ENOMEM; +- +- /* +- * The MAC address of a DS4 controller connected via USB can be +- * retrieved with feature report 0x81. The address begins at +- * offset 1. +- */ +- ret = hid_hw_raw_request(sc->hdev, 0x81, buf, +- DS4_FEATURE_REPORT_0x81_SIZE, HID_FEATURE_REPORT, +- 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; +- } +- +- memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); ++ ret = sony_get_usb_ds4_devaddr(sc); ++ if (ret < 0) ++ return ret; + + snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq), + "%pMR", sc->mac_address); +@@ -2670,6 +2701,7 @@ static int sony_check_add(struct sony_sc *sc) + return 0; + } + ++ dbg_hid("%s: retrieved MAC address: %s\n", __func__, sc->hdev->uniq); + ret = sony_check_add_dev_list(sc); + + out_free: +-- +2.29.2 \ No newline at end of file From d463b49f10f205f083139457c0277a2a1941d4a6 Mon Sep 17 00:00:00 2001 From: monkaBlyat <54044929+monkaBlyat@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:56:34 +0200 Subject: [PATCH 2/4] vendor kernel patch for ds4 controllers --- .../rk35xx-vendor-6.1/001-hid-sony.patch | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 patch/kernel/rk35xx-vendor-6.1/001-hid-sony.patch diff --git a/patch/kernel/rk35xx-vendor-6.1/001-hid-sony.patch b/patch/kernel/rk35xx-vendor-6.1/001-hid-sony.patch new file mode 100644 index 000000000000..6d001c38e960 --- /dev/null +++ b/patch/kernel/rk35xx-vendor-6.1/001-hid-sony.patch @@ -0,0 +1,111 @@ +Signed-off-by: Ivan Mironov +--- + drivers/hid/hid-sony.c | 72 ++++++++++++++++++++++++++++++------------ + 1 file changed, 52 insertions(+), 20 deletions(-) + +diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c +index e3a557dc9ffd..97df12180e45 100644 +--- a/drivers/hid/hid-sony.c ++++ b/drivers/hid/hid-sony.c +@@ -491,6 +491,7 @@ struct motion_output_report_02 { + + #define DS4_FEATURE_REPORT_0x02_SIZE 37 + #define DS4_FEATURE_REPORT_0x05_SIZE 41 ++#define DS4_FEATURE_REPORT_0x12_SIZE 16 + #define DS4_FEATURE_REPORT_0x81_SIZE 7 + #define DS4_FEATURE_REPORT_0xA3_SIZE 49 + #define DS4_INPUT_REPORT_0x11_SIZE 78 +@@ -2593,6 +2594,53 @@ static int sony_get_bt_devaddr(struct sony_sc *sc) + return 0; + } + ++static int sony_get_usb_ds4_devaddr(struct sony_sc *sc) ++{ ++ u8 *buf = NULL; ++ int ret; ++ ++ buf = kmalloc(max(DS4_FEATURE_REPORT_0x12_SIZE, DS4_FEATURE_REPORT_0x81_SIZE), GFP_KERNEL); ++ if (!buf) ++ return -ENOMEM; ++ ++ /* ++ * The MAC address of a DS4 controller connected via USB can be ++ * retrieved with feature report 0x81. The address begins at ++ * offset 1. ++ */ ++ ret = hid_hw_raw_request(sc->hdev, 0x81, buf, ++ DS4_FEATURE_REPORT_0x81_SIZE, HID_FEATURE_REPORT, ++ HID_REQ_GET_REPORT); ++ if (ret == DS4_FEATURE_REPORT_0x81_SIZE) { ++ memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); ++ goto out_free; ++ } ++ dbg_hid("%s: hid_hw_raw_request(..., 0x81, ...) returned %d\n", __func__, ret); ++ ++ /* ++ * Some variants do not implement feature report 0x81 at all. ++ * Fortunately, feature report 0x12 also contains the MAC address of ++ * a controller. ++ */ ++ ret = hid_hw_raw_request(sc->hdev, 0x12, buf, ++ DS4_FEATURE_REPORT_0x12_SIZE, HID_FEATURE_REPORT, ++ HID_REQ_GET_REPORT); ++ if (ret == DS4_FEATURE_REPORT_0x12_SIZE) { ++ memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); ++ goto out_free; ++ } ++ dbg_hid("%s: hid_hw_raw_request(..., 0x12, ...) returned %d\n", __func__, ret); ++ ++ hid_err(sc->hdev, "failed to retrieve feature reports 0x81 and 0x12 with the DualShock 4 MAC address\n"); ++ ret = ret < 0 ? ret : -EINVAL; ++ ++out_free: ++ ++ kfree(buf); ++ ++ return ret; ++} ++ + static int sony_check_add(struct sony_sc *sc) + { + u8 *buf = NULL; +@@ -2613,26 +2661,9 @@ 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); +- if (!buf) +- return -ENOMEM; +- +- /* +- * The MAC address of a DS4 controller connected via USB can be +- * retrieved with feature report 0x81. The address begins at +- * offset 1. +- */ +- ret = hid_hw_raw_request(sc->hdev, 0x81, buf, +- DS4_FEATURE_REPORT_0x81_SIZE, HID_FEATURE_REPORT, +- 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; +- } +- +- memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); ++ ret = sony_get_usb_ds4_devaddr(sc); ++ if (ret < 0) ++ return ret; + + snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq), + "%pMR", sc->mac_address); +@@ -2670,6 +2701,7 @@ static int sony_check_add(struct sony_sc *sc) + return 0; + } + ++ dbg_hid("%s: retrieved MAC address: %s\n", __func__, sc->hdev->uniq); + ret = sony_check_add_dev_list(sc); + + out_free: +-- +2.29.2 \ No newline at end of file From 2f17e3ed9f418dcd2cc2493726805c9c4fdd1d9c Mon Sep 17 00:00:00 2001 From: monkaBlyat <54044929+monkaBlyat@users.noreply.github.com> Date: Fri, 16 Aug 2024 22:00:53 +0200 Subject: [PATCH 3/4] fix ps4 controller led's on legacy kernel --- config/kernel/linux-rk35xx-legacy.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/kernel/linux-rk35xx-legacy.config b/config/kernel/linux-rk35xx-legacy.config index a79fc3429f57..1a848f9a6700 100644 --- a/config/kernel/linux-rk35xx-legacy.config +++ b/config/kernel/linux-rk35xx-legacy.config @@ -6100,7 +6100,7 @@ CONFIG_MMC_HSQ=y CONFIG_NEW_LEDS=y CONFIG_LEDS_CLASS=y # CONFIG_LEDS_CLASS_FLASH is not set -# CONFIG_LEDS_CLASS_MULTICOLOR is not set +CONFIG_LEDS_CLASS_MULTICOLOR=m # CONFIG_LEDS_BRIGHTNESS_HW_CHANGED is not set # From 2cbdfcc8188d4508b430f3a698eae1f868635d08 Mon Sep 17 00:00:00 2001 From: monkaBlyat <54044929+monkaBlyat@users.noreply.github.com> Date: Fri, 16 Aug 2024 22:04:21 +0200 Subject: [PATCH 4/4] fix ps4 controller led's on vendor kernel --- config/kernel/linux-rk35xx-vendor.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/kernel/linux-rk35xx-vendor.config b/config/kernel/linux-rk35xx-vendor.config index 45e75b4f5d66..4d90e83e2cad 100644 --- a/config/kernel/linux-rk35xx-vendor.config +++ b/config/kernel/linux-rk35xx-vendor.config @@ -6953,7 +6953,7 @@ CONFIG_MMC_HSQ=y CONFIG_NEW_LEDS=y CONFIG_LEDS_CLASS=y # CONFIG_LEDS_CLASS_FLASH is not set -# CONFIG_LEDS_CLASS_MULTICOLOR is not set +CONFIG_LEDS_CLASS_MULTICOLOR=m # CONFIG_LEDS_BRIGHTNESS_HW_CHANGED is not set #