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 Logitech RumblePad and Rumblepad 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *  Copyright (c) 2008 Anssi Hannula <anssi.hannula@gmail.com>
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "hid-lg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct lg2ff_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int play_effect(struct input_dev *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 			 struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	struct hid_device *hid = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	struct lg2ff_device *lg2ff = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	int weak, strong;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	strong = effect->u.rumble.strong_magnitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	weak = effect->u.rumble.weak_magnitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	if (weak || strong) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		weak = weak * 0xff / 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 		strong = strong * 0xff / 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		lg2ff->report->field[0]->value[0] = 0x51;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		lg2ff->report->field[0]->value[2] = weak;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 		lg2ff->report->field[0]->value[4] = strong;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		lg2ff->report->field[0]->value[0] = 0xf3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		lg2ff->report->field[0]->value[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		lg2ff->report->field[0]->value[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	hid_hw_request(hid, lg2ff->report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int lg2ff_init(struct hid_device *hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	struct lg2ff_device *lg2ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	struct hid_input *hidinput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	if (list_empty(&hid->inputs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		hid_err(hid, "no inputs found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	hidinput = list_entry(hid->inputs.next, struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	dev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	/* Check that the report looks ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	if (!report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	if (!lg2ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	set_bit(FF_RUMBLE, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	error = input_ff_create_memless(dev, lg2ff, play_effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		kfree(lg2ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	lg2ff->report = report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	report->field[0]->value[0] = 0xf3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	report->field[0]->value[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	report->field[0]->value[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 	report->field[0]->value[3] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 	report->field[0]->value[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 	report->field[0]->value[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 	report->field[0]->value[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 	hid_hw_request(hid, report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 	hid_info(hid, "Force feedback for Logitech variant 2 rumble devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }