Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *  HID driver for Retrode 2 controller adapter and plug-in extensions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *  Copyright (c) 2017 Bastien Nocera <hadess@hadess.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define CONTROLLER_NAME_BASE "Retrode"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static int retrode_input_configured(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 					struct hid_input *hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	struct hid_field *field = hi->report->field[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	const char *suffix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	int number = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	switch (field->report->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		suffix = "SNES Mouse";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		suffix = "SNES / N64";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 		number = field->report->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 		suffix = "Mega Drive";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		number = field->report->id - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		hid_err(hdev, "Got unhandled report id %d\n", field->report->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 		suffix = "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	if (number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 				"%s %s #%d", CONTROLLER_NAME_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 				suffix, number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 				"%s %s", CONTROLLER_NAME_BASE, suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	hi->input->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int retrode_probe(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 			const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	/* Has no effect on the mouse device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	hdev->quirks |= HID_QUIRK_MULTI_INPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static const struct hid_device_id retrode_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	{ HID_USB_DEVICE(USB_VENDOR_ID_FUTURE_TECHNOLOGY, USB_DEVICE_ID_RETRODE2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) MODULE_DEVICE_TABLE(hid, retrode_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static struct hid_driver retrode_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 	.name             = "hid-retrode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 	.id_table         = retrode_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 	.input_configured = retrode_input_configured,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 	.probe            = retrode_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) module_hid_driver(retrode_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) MODULE_LICENSE("GPL");