Linux Audio

Check our new training course

Loading...
v6.2
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * HID driver for primax and similar keyboards with in-band modifiers
 4 *
 5 * Copyright 2011 Google Inc. All Rights Reserved
 6 *
 7 * Author:
 8 *	Terry Lambert <tlambert@google.com>
 
 
 
 
 
 
 
 
 
 9 */
10
11#include <linux/device.h>
12#include <linux/hid.h>
13#include <linux/module.h>
14
15#include "hid-ids.h"
16
17static int px_raw_event(struct hid_device *hid, struct hid_report *report,
18	 u8 *data, int size)
19{
20	int idx = size;
21
22	switch (report->id) {
23	case 0:		/* keyboard input */
24		/*
25		 * Convert in-band modifier key values into out of band
26		 * modifier bits and pull the key strokes from the report.
27		 * Thus a report data set which looked like:
28		 *
29		 * [00][00][E0][30][00][00][00][00]
30		 * (no modifier bits + "Left Shift" key + "1" key)
31		 *
32		 * Would be converted to:
33		 *
34		 * [01][00][00][30][00][00][00][00]
35		 * (Left Shift modifier bit + "1" key)
36		 *
37		 * As long as it's in the size range, the upper level
38		 * drivers don't particularly care if there are in-band
39		 * 0-valued keys, so they don't stop parsing.
40		 */
41		while (--idx > 1) {
42			if (data[idx] < 0xE0 || data[idx] > 0xE7)
43				continue;
44			data[0] |= (1 << (data[idx] - 0xE0));
45			data[idx] = 0;
46		}
47		hid_report_raw_event(hid, HID_INPUT_REPORT, data, size, 0);
48		return 1;
49
50	default:	/* unknown report */
51		/* Unknown report type; pass upstream */
52		hid_info(hid, "unknown report type %d\n", report->id);
53		break;
54	}
55
56	return 0;
57}
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59static const struct hid_device_id px_devices[] = {
60	{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
61	{ }
62};
63MODULE_DEVICE_TABLE(hid, px_devices);
64
65static struct hid_driver px_driver = {
66	.name = "primax",
67	.id_table = px_devices,
68	.raw_event = px_raw_event,
 
 
69};
70module_hid_driver(px_driver);
71
 
 
 
 
 
 
 
 
 
 
 
 
72MODULE_AUTHOR("Terry Lambert <tlambert@google.com>");
73MODULE_LICENSE("GPL");
v3.5.6
 
  1/*
  2 * HID driver for primax and similar keyboards with in-band modifiers
  3 *
  4 * Copyright 2011 Google Inc. All Rights Reserved
  5 *
  6 * Author:
  7 *	Terry Lambert <tlambert@google.com>
  8 *
  9 * This software is licensed under the terms of the GNU General Public
 10 * License version 2, as published by the Free Software Foundation, and
 11 * may be copied, distributed, and modified under those terms.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 */
 18
 19#include <linux/device.h>
 20#include <linux/hid.h>
 21#include <linux/module.h>
 22
 23#include "hid-ids.h"
 24
 25static int px_raw_event(struct hid_device *hid, struct hid_report *report,
 26	 u8 *data, int size)
 27{
 28	int idx = size;
 29
 30	switch (report->id) {
 31	case 0:		/* keyboard input */
 32		/*
 33		 * Convert in-band modifier key values into out of band
 34		 * modifier bits and pull the key strokes from the report.
 35		 * Thus a report data set which looked like:
 36		 *
 37		 * [00][00][E0][30][00][00][00][00]
 38		 * (no modifier bits + "Left Shift" key + "1" key)
 39		 *
 40		 * Would be converted to:
 41		 *
 42		 * [01][00][00][30][00][00][00][00]
 43		 * (Left Shift modifier bit + "1" key)
 44		 *
 45		 * As long as it's in the size range, the upper level
 46		 * drivers don't particularly care if there are in-band
 47		 * 0-valued keys, so they don't stop parsing.
 48		 */
 49		while (--idx > 1) {
 50			if (data[idx] < 0xE0 || data[idx] > 0xE7)
 51				continue;
 52			data[0] |= (1 << (data[idx] - 0xE0));
 53			data[idx] = 0;
 54		}
 55		hid_report_raw_event(hid, HID_INPUT_REPORT, data, size, 0);
 56		return 1;
 57
 58	default:	/* unknown report */
 59		/* Unknown report type; pass upstream */
 60		hid_info(hid, "unknown report type %d\n", report->id);
 61		break;
 62	}
 63
 64	return 0;
 65}
 66
 67static int px_probe(struct hid_device *hid, const struct hid_device_id *id)
 68{
 69	int ret;
 70
 71	ret = hid_parse(hid);
 72	if (ret) {
 73		hid_err(hid, "parse failed\n");
 74		goto fail;
 75	}
 76
 77	ret = hid_hw_start(hid, HID_CONNECT_DEFAULT);
 78	if (ret)
 79		hid_err(hid, "hw start failed\n");
 80
 81fail:
 82	return ret;
 83}
 84
 85static void px_remove(struct hid_device *hid)
 86{
 87	hid_hw_stop(hid);
 88}
 89
 90static const struct hid_device_id px_devices[] = {
 91	{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
 92	{ }
 93};
 94MODULE_DEVICE_TABLE(hid, px_devices);
 95
 96static struct hid_driver px_driver = {
 97	.name = "primax",
 98	.id_table = px_devices,
 99	.raw_event = px_raw_event,
100	.probe = px_probe,
101	.remove = px_remove,
102};
 
103
104static int __init px_init(void)
105{
106	return hid_register_driver(&px_driver);
107}
108
109static void __exit px_exit(void)
110{
111	hid_unregister_driver(&px_driver);
112}
113
114module_init(px_init);
115module_exit(px_exit);
116MODULE_AUTHOR("Terry Lambert <tlambert@google.com>");
117MODULE_LICENSE("GPL");