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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * HID driver for primax and similar keyboards with in-band modifiers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright 2011 Google Inc. All Rights Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Author:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *	Terry Lambert <tlambert@google.com>
^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/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^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) static int px_raw_event(struct hid_device *hid, struct hid_report *report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	 u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	int idx = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	switch (report->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	case 0:		/* keyboard input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 		 * Convert in-band modifier key values into out of band
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 		 * modifier bits and pull the key strokes from the report.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		 * Thus a report data set which looked like:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		 * [00][00][E0][30][00][00][00][00]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		 * (no modifier bits + "Left Shift" key + "1" key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 		 * Would be converted to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 		 * [01][00][00][30][00][00][00][00]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 		 * (Left Shift modifier bit + "1" key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		 * As long as it's in the size range, the upper level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 		 * drivers don't particularly care if there are in-band
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		 * 0-valued keys, so they don't stop parsing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		while (--idx > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 			if (data[idx] < 0xE0 || data[idx] > 0xE7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 			data[0] |= (1 << (data[idx] - 0xE0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 			data[idx] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		hid_report_raw_event(hid, HID_INPUT_REPORT, data, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	default:	/* unknown report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		/* Unknown report type; pass upstream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		hid_info(hid, "unknown report type %d\n", report->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static const struct hid_device_id px_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
^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) MODULE_DEVICE_TABLE(hid, px_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static struct hid_driver px_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	.name = "primax",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	.id_table = px_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	.raw_event = px_raw_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) module_hid_driver(px_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) MODULE_AUTHOR("Terry Lambert <tlambert@google.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) MODULE_LICENSE("GPL");