summaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-playstation.c
diff options
context:
space:
mode:
authorRoderick Colenbrander <roderick@gaikai.com>2022-10-29 11:48:40 -0700
committerJiri Kosina <jkosina@suse.cz>2022-11-11 11:07:08 +0100
commit9a62280a1bdc71e89ea44395bd03829ad896c447 (patch)
tree28fab23e53b2b9999992b833a90d4328dd540168 /drivers/hid/hid-playstation.c
parentf55b9b56cefb1c4a7422e2b1fcb3a84ae4cd74d1 (diff)
downloadlinux-9a62280a1bdc71e89ea44395bd03829ad896c447.tar.bz2
HID: playstation: report DualShock4 hardware and firmware version.
Report DualShock4 hardware and firmware version info through sysfs. It uses the same sysfs nodes as the DualSense did (and hid-sony). Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-playstation.c')
-rw-r--r--drivers/hid/hid-playstation.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 04d03d2e40db..df4353a4f1e9 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -286,6 +286,8 @@ struct dualsense_output_report {
#define DS4_INPUT_REPORT_USB 0x01
#define DS4_INPUT_REPORT_USB_SIZE 64
+#define DS4_FEATURE_REPORT_FIRMWARE_INFO 0xa3
+#define DS4_FEATURE_REPORT_FIRMWARE_INFO_SIZE 49
#define DS4_FEATURE_REPORT_PAIRING_INFO 0x12
#define DS4_FEATURE_REPORT_PAIRING_INFO_SIZE 16
@@ -1494,6 +1496,30 @@ err:
return ERR_PTR(ret);
}
+static int dualshock4_get_firmware_info(struct dualshock4 *ds4)
+{
+ uint8_t *buf;
+ int ret;
+
+ buf = kzalloc(DS4_FEATURE_REPORT_FIRMWARE_INFO_SIZE, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ ret = ps_get_report(ds4->base.hdev, DS4_FEATURE_REPORT_FIRMWARE_INFO, buf,
+ DS4_FEATURE_REPORT_FIRMWARE_INFO_SIZE);
+ if (ret) {
+ hid_err(ds4->base.hdev, "Failed to retrieve DualShock4 firmware info: %d\n", ret);
+ goto err_free;
+ }
+
+ ds4->base.hw_version = get_unaligned_le16(&buf[35]);
+ ds4->base.fw_version = get_unaligned_le16(&buf[41]);
+
+err_free:
+ kfree(buf);
+ return ret;
+}
+
static int dualshock4_get_mac_address(struct dualshock4 *ds4)
{
uint8_t *buf;
@@ -1600,6 +1626,12 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev)
}
snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds4->base.mac_address);
+ ret = dualshock4_get_firmware_info(ds4);
+ if (ret) {
+ hid_err(hdev, "Failed to get firmware info from DualShock4\n");
+ return ERR_PTR(ret);
+ }
+
ret = ps_devices_list_add(ps_dev);
if (ret)
return ERR_PTR(ret);
@@ -1616,6 +1648,12 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev)
goto err;
}
+ /*
+ * Reporting hardware and firmware is important as there are frequent updates, which
+ * can change behavior.
+ */
+ hid_info(hdev, "Registered DualShock4 controller hw_version=0x%08x fw_version=0x%08x\n",
+ ds4->base.hw_version, ds4->base.fw_version);
return &ds4->base;
err: