1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HID driver for Retrode 2 controller adapter and plug-in extensions
5 * Copyright (c) 2017 Bastien Nocera <hadess@hadess.net>
11 #include <linux/input.h>
12 #include <linux/slab.h>
13 #include <linux/hid.h>
14 #include <linux/module.h>
17 #define CONTROLLER_NAME_BASE "Retrode"
19 static int retrode_input_configured(struct hid_device *hdev,
22 struct hid_field *field = hi->report->field[0];
27 switch (field->report->id) {
29 suffix = "SNES Mouse";
33 suffix = "SNES / N64";
34 number = field->report->id;
38 suffix = "Mega Drive";
39 number = field->report->id - 2;
42 hid_err(hdev, "Got unhandled report id %d\n", field->report->id);
47 name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
48 "%s %s #%d", CONTROLLER_NAME_BASE,
51 name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
52 "%s %s", CONTROLLER_NAME_BASE, suffix);
57 hi->input->name = name;
62 static int retrode_probe(struct hid_device *hdev,
63 const struct hid_device_id *id)
68 /* Has no effect on the mouse device */
69 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
71 ret = hid_parse(hdev);
75 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
82 static const struct hid_device_id retrode_devices[] = {
83 { HID_USB_DEVICE(USB_VENDOR_ID_FUTURE_TECHNOLOGY, USB_DEVICE_ID_RETRODE2) },
86 MODULE_DEVICE_TABLE(hid, retrode_devices);
88 static struct hid_driver retrode_driver = {
89 .name = "hid-retrode",
90 .id_table = retrode_devices,
91 .input_configured = retrode_input_configured,
92 .probe = retrode_probe,
95 module_hid_driver(retrode_driver);
97 MODULE_LICENSE("GPL");