summaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-retrode.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 01:02:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 01:02:30 +0000
commit76cb841cb886eef6b3bee341a2266c76578724ad (patch)
treef5892e5ba6cc11949952a6ce4ecbe6d516d6ce58 /drivers/hid/hid-retrode.c
parentInitial commit. (diff)
downloadlinux-76cb841cb886eef6b3bee341a2266c76578724ad.tar.xz
linux-76cb841cb886eef6b3bee341a2266c76578724ad.zip
Adding upstream version 4.19.249.upstream/4.19.249
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'drivers/hid/hid-retrode.c')
-rw-r--r--drivers/hid/hid-retrode.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/drivers/hid/hid-retrode.c b/drivers/hid/hid-retrode.c
new file mode 100644
index 000000000..30cc7ebb4
--- /dev/null
+++ b/drivers/hid/hid-retrode.c
@@ -0,0 +1,100 @@
+/*
+ * HID driver for Retrode 2 controller adapter and plug-in extensions
+ *
+ * Copyright (c) 2017 Bastien Nocera <hadess@hadess.net>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include <linux/input.h>
+#include <linux/slab.h>
+#include <linux/hid.h>
+#include <linux/module.h>
+#include "hid-ids.h"
+
+#define CONTROLLER_NAME_BASE "Retrode"
+
+static int retrode_input_configured(struct hid_device *hdev,
+ struct hid_input *hi)
+{
+ struct hid_field *field = hi->report->field[0];
+ const char *suffix;
+ int number = 0;
+ char *name;
+
+ switch (field->report->id) {
+ case 0:
+ suffix = "SNES Mouse";
+ break;
+ case 1:
+ case 2:
+ suffix = "SNES / N64";
+ number = field->report->id;
+ break;
+ case 3:
+ case 4:
+ suffix = "Mega Drive";
+ number = field->report->id - 2;
+ break;
+ default:
+ hid_err(hdev, "Got unhandled report id %d\n", field->report->id);
+ suffix = "Unknown";
+ }
+
+ if (number)
+ name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
+ "%s %s #%d", CONTROLLER_NAME_BASE,
+ suffix, number);
+ else
+ name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
+ "%s %s", CONTROLLER_NAME_BASE, suffix);
+
+ if (!name)
+ return -ENOMEM;
+
+ hi->input->name = name;
+
+ return 0;
+}
+
+static int retrode_probe(struct hid_device *hdev,
+ const struct hid_device_id *id)
+{
+
+ int ret;
+
+ /* Has no effect on the mouse device */
+ hdev->quirks |= HID_QUIRK_MULTI_INPUT;
+
+ ret = hid_parse(hdev);
+ if (ret)
+ return ret;
+
+ ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static const struct hid_device_id retrode_devices[] = {
+ { HID_USB_DEVICE(USB_VENDOR_ID_FUTURE_TECHNOLOGY, USB_DEVICE_ID_RETRODE2) },
+ { }
+};
+MODULE_DEVICE_TABLE(hid, retrode_devices);
+
+static struct hid_driver retrode_driver = {
+ .name = "hid-retrode",
+ .id_table = retrode_devices,
+ .input_configured = retrode_input_configured,
+ .probe = retrode_probe,
+};
+
+module_hid_driver(retrode_driver);
+
+MODULE_LICENSE("GPL");