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)  *  Force feedback support for GreenAsia (Product ID 0x12) based devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  The devices are distributed under various names and the same USB device ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  can be used in many game controllers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  0e8f:0012 "GreenAsia Inc.    USB Joystick     "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *   - tested with MANTA Warior MM816 and SpeedLink Strike2 SL-6635.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  Copyright (c) 2008 Lukasz Lubojanski <lukasz@lubojanski.info>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #ifdef CONFIG_GREENASIA_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct gaff_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static int hid_gaff_play(struct input_dev *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			 struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct hid_device *hid = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct gaff_device *gaff = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int left, right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	left = effect->u.rumble.strong_magnitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	right = effect->u.rumble.weak_magnitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	dbg_hid("called with 0x%04x 0x%04x", left, right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	left = left * 0xfe / 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	right = right * 0xfe / 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	gaff->report->field[0]->value[0] = 0x51;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	gaff->report->field[0]->value[1] = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	gaff->report->field[0]->value[2] = right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	gaff->report->field[0]->value[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	gaff->report->field[0]->value[4] = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	gaff->report->field[0]->value[5] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	dbg_hid("running with 0x%02x 0x%02x", left, right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	gaff->report->field[0]->value[0] = 0xfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	gaff->report->field[0]->value[1] = 0xfe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	gaff->report->field[0]->value[2] = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	gaff->report->field[0]->value[4] = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int gaff_init(struct hid_device *hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct gaff_device *gaff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct hid_input *hidinput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct list_head *report_list =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			&hid->report_enum[HID_OUTPUT_REPORT].report_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct list_head *report_ptr = report_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (list_empty(&hid->inputs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		hid_err(hid, "no inputs found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	hidinput = list_entry(hid->inputs.next, struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	dev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (list_empty(report_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		hid_err(hid, "no output reports found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return -ENODEV;
^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) 	report_ptr = report_ptr->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	report = list_entry(report_ptr, struct hid_report, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (report->maxfield < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		hid_err(hid, "no fields in the report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (report->field[0]->report_count < 6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		hid_err(hid, "not enough values in the field\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	gaff = kzalloc(sizeof(struct gaff_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!gaff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	set_bit(FF_RUMBLE, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	error = input_ff_create_memless(dev, gaff, hid_gaff_play);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		kfree(gaff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	gaff->report = report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	gaff->report->field[0]->value[0] = 0x51;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	gaff->report->field[0]->value[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	gaff->report->field[0]->value[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	gaff->report->field[0]->value[3] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	gaff->report->field[0]->value[0] = 0xfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	gaff->report->field[0]->value[1] = 0xfe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	hid_info(hid, "Force Feedback for GreenAsia 0x12 devices by Lukasz Lubojanski <lukasz@lubojanski.info>\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static inline int gaff_init(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int ga_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	dev_dbg(&hdev->dev, "Greenasia HID hardware probe...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	gaff_init(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static const struct hid_device_id ga_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012),  },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) MODULE_DEVICE_TABLE(hid, ga_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static struct hid_driver ga_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	.name = "greenasia",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	.id_table = ga_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	.probe = ga_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) module_hid_driver(ga_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) MODULE_LICENSE("GPL");