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