[v11,09/11] HID: nintendo: patch hw version for userspace HID mappings
diff mbox series

Message ID 20200317032928.546172-10-djogorchock@gmail.com
State New
Delegated to: Jiri Kosina
Headers show
  • HID: nintendo
Related show

Commit Message

Daniel Ogorchock March 17, 2020, 3:29 a.m. UTC
This patch sets the most significant bit of the hid hw version to allow
userspace to distinguish between this driver's input mappings vs. the
default hid mappings. This prevents breaking userspace applications that
use SDL2 for gamepad input, allowing them to distinguish the mappings
based on the version.

Signed-off-by: Daniel J. Ogorchock <djogorchock@gmail.com>
 drivers/hid/hid-nintendo.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff mbox series

diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index abac0497b1cb..a56fa5ffee1a 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
@@ -1422,6 +1422,15 @@  static int nintendo_hid_probe(struct hid_device *hdev,
 		goto err_wq;
+	/*
+	 * Patch the hw version of pro controller/joycons, so applications can
+	 * distinguish between the default HID mappings and the mappings defined
+	 * by the Linux game controller spec. This is important for the SDL2
+	 * library, which has a game controller database, which uses device ids
+	 * in combination with version as a key.
+	 */
+	hdev->version |= 0x8000;
 	ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
 	if (ret) {
 		hid_err(hdev, "HW start failed\n");