--- v1
+++ v2
@@ -10,9 +10,9 @@
drivers/hid/Kconfig | 9 +
drivers/hid/Makefile | 1 +
drivers/hid/hid-ids.h | 1 +
- drivers/hid/hid-playstation.c | 317 ++++++++++++++++++++++++++++++++++
+ drivers/hid/hid-playstation.c | 321 ++++++++++++++++++++++++++++++++++
drivers/hid/hid-quirks.c | 3 +
- 6 files changed, 337 insertions(+)
+ 6 files changed, 341 insertions(+)
create mode 100644 drivers/hid/hid-playstation.c
diff --git a/MAINTAINERS b/MAINTAINERS
@@ -78,10 +78,10 @@
#define USB_DEVICE_ID_SONY_BUZZ_CONTROLLER 0x0002
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
new file mode 100644
-index 000000000000..8dbd0ae7e082
+index 000000000000..3d5fe9069c26
--- /dev/null
+++ b/drivers/hid/hid-playstation.c
-@@ -0,0 +1,317 @@
+@@ -0,0 +1,321 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * HID driver for Sony DualSense(TM) controller.
@@ -89,14 +89,18 @@
+ * Copyright (c) 2020 Sony Interactive Entertainment
+ */
+
++#include <linux/bits.h>
++#include <linux/crc32.h>
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/input/mt.h>
+#include <linux/module.h>
-+#include <linux/crc32.h>
++
+#include <asm/unaligned.h>
+
+#include "hid-ids.h"
++
++#define HID_PLAYSTATION_VERSION_PATCH 0x8000
+
+/* Base class for playstation devices. */
+struct ps_device {
@@ -163,7 +167,7 @@
+ * Note: for device with a touchpad, touchpad button is not included
+ * as it will be part of the touchpad device.
+ */
-+static int ps_gamepad_buttons[] = {
++static const int ps_gamepad_buttons[] = {
+ BTN_WEST, /* Square */
+ BTN_NORTH, /* Triangle */
+ BTN_EAST, /* Circle */
@@ -203,8 +207,9 @@
+ name_suffix);
+ if (!input_dev->name)
+ return ERR_PTR(-ENOMEM);
-+ } else
++ } else {
+ input_dev->name = hdev->name;
++ }
+
+ input_set_drvdata(input_dev, hdev);
+
@@ -245,7 +250,7 @@
+ u8 *data, int size)
+{
+ struct hid_device *hdev = ps_dev->hdev;
-+ struct dualsense *ds = (struct dualsense *)ps_dev;
++ struct dualsense *ds = container_of(ps_dev, struct dualsense, base);
+ struct dualsense_input_report *ds_report;
+ uint8_t value;
+
@@ -260,11 +265,11 @@
+ return -1;
+ }
+
-+ input_report_abs(ds->gamepad, ABS_X, ds_report->x);
-+ input_report_abs(ds->gamepad, ABS_Y, ds_report->y);
++ input_report_abs(ds->gamepad, ABS_X, ds_report->x);
++ input_report_abs(ds->gamepad, ABS_Y, ds_report->y);
+ input_report_abs(ds->gamepad, ABS_RX, ds_report->rx);
+ input_report_abs(ds->gamepad, ABS_RY, ds_report->ry);
-+ input_report_abs(ds->gamepad, ABS_Z, ds_report->z);
++ input_report_abs(ds->gamepad, ABS_Z, ds_report->z);
+ input_report_abs(ds->gamepad, ABS_RZ, ds_report->rz);
+
+ value = ds_report->buttons[0] & DS_BUTTONS0_HAT_SWITCH;
@@ -273,19 +278,19 @@
+ input_report_abs(ds->gamepad, ABS_HAT0X, ps_gamepad_hat_mapping[value].x);
+ input_report_abs(ds->gamepad, ABS_HAT0Y, ps_gamepad_hat_mapping[value].y);
+
-+ input_report_key(ds->gamepad, BTN_WEST, ds_report->buttons[0] & DS_BUTTONS0_SQUARE);
-+ input_report_key(ds->gamepad, BTN_SOUTH, ds_report->buttons[0] & DS_BUTTONS0_CROSS);
-+ input_report_key(ds->gamepad, BTN_EAST, ds_report->buttons[0] & DS_BUTTONS0_CIRCLE);
-+ input_report_key(ds->gamepad, BTN_NORTH, ds_report->buttons[0] & DS_BUTTONS0_TRIANGLE);
-+ input_report_key(ds->gamepad, BTN_TL, ds_report->buttons[1] & DS_BUTTONS1_L1);
-+ input_report_key(ds->gamepad, BTN_TR, ds_report->buttons[1] & DS_BUTTONS1_R1);
-+ input_report_key(ds->gamepad, BTN_TL2, ds_report->buttons[1] & DS_BUTTONS1_L2);
-+ input_report_key(ds->gamepad, BTN_TR2, ds_report->buttons[1] & DS_BUTTONS1_R2);
++ input_report_key(ds->gamepad, BTN_WEST, ds_report->buttons[0] & DS_BUTTONS0_SQUARE);
++ input_report_key(ds->gamepad, BTN_SOUTH, ds_report->buttons[0] & DS_BUTTONS0_CROSS);
++ input_report_key(ds->gamepad, BTN_EAST, ds_report->buttons[0] & DS_BUTTONS0_CIRCLE);
++ input_report_key(ds->gamepad, BTN_NORTH, ds_report->buttons[0] & DS_BUTTONS0_TRIANGLE);
++ input_report_key(ds->gamepad, BTN_TL, ds_report->buttons[1] & DS_BUTTONS1_L1);
++ input_report_key(ds->gamepad, BTN_TR, ds_report->buttons[1] & DS_BUTTONS1_R1);
++ input_report_key(ds->gamepad, BTN_TL2, ds_report->buttons[1] & DS_BUTTONS1_L2);
++ input_report_key(ds->gamepad, BTN_TR2, ds_report->buttons[1] & DS_BUTTONS1_R2);
+ input_report_key(ds->gamepad, BTN_SELECT, ds_report->buttons[1] & DS_BUTTONS1_CREATE);
-+ input_report_key(ds->gamepad, BTN_START, ds_report->buttons[1] & DS_BUTTONS1_OPTIONS);
++ input_report_key(ds->gamepad, BTN_START, ds_report->buttons[1] & DS_BUTTONS1_OPTIONS);
+ input_report_key(ds->gamepad, BTN_THUMBL, ds_report->buttons[1] & DS_BUTTONS1_L3);
+ input_report_key(ds->gamepad, BTN_THUMBR, ds_report->buttons[1] & DS_BUTTONS1_R3);
-+ input_report_key(ds->gamepad, BTN_MODE, ds_report->buttons[2] & DS_BUTTONS2_PS_HOME);
++ input_report_key(ds->gamepad, BTN_MODE, ds_report->buttons[2] & DS_BUTTONS2_PS_HOME);
+ input_sync(ds->gamepad);
+
+ return 0;
@@ -303,7 +308,7 @@
+ /* Patch version to allow userspace to distinguish between
+ * hid-generic vs hid-playstation axis and button mapping.
+ */
-+ hdev->version |= 0x8000;
++ hdev->version |= HID_PLAYSTATION_VERSION_PATCH;
+
+ ds->base.hdev = hdev;
+ ds->base.parse_report = dualsense_parse_report;
@@ -315,7 +320,7 @@
+ goto err;
+ }
+
-+ return (struct ps_device *)ds;
++ return &ds->base;
+
+err:
+ return ERR_PTR(ret);
@@ -362,10 +367,6 @@
+ ret = PTR_ERR(dev);
+ goto err_close;
+ }
-+ } else {
-+ hid_err(hdev, "Unhandled device\n");
-+ ret = -EINVAL;
-+ goto err_close;
+ }
+
+ return ret;
@@ -384,9 +385,10 @@
+}
+
+static const struct hid_device_id ps_devices[] = {
-+ { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER),
-+ .driver_data = 0 },
-+};
++ { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) },
++ { }
++};
++MODULE_DEVICE_TABLE(hid, ps_devices);
+
+static struct hid_driver ps_driver = {
+ .name = "playstation",
@@ -398,6 +400,8 @@
+
+module_hid_driver(ps_driver);
+
++MODULE_AUTHOR("Sony Interactive Entertainment");
++MODULE_DESCRIPTION("HID Driver for PlayStation peripherals.");
+MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index d9ca874dffac..1ca46cb445be 100644