xref: /openbmc/linux/drivers/hid/hid-belkin.c (revision b4f63bbf)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  HID driver for some belkin "special" devices
4  *
5  *  Copyright (c) 1999 Andreas Gal
6  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
7  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
8  *  Copyright (c) 2006-2007 Jiri Kosina
9  *  Copyright (c) 2008 Jiri Slaby
10  */
11 
12 /*
13  */
14 
15 #include <linux/device.h>
16 #include <linux/hid.h>
17 #include <linux/module.h>
18 
19 #include "hid-ids.h"
20 
21 #define BELKIN_HIDDEV	0x01
22 #define BELKIN_WKBD	0x02
23 
24 #define belkin_map_key_clear(c)	hid_map_usage_clear(hi, usage, bit, max, \
25 					EV_KEY, (c))
26 static int belkin_input_mapping(struct hid_device *hdev, struct hid_input *hi,
27 		struct hid_field *field, struct hid_usage *usage,
28 		unsigned long **bit, int *max)
29 {
30 	unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
31 
32 	if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER ||
33 			!(quirks & BELKIN_WKBD))
34 		return 0;
35 
36 	switch (usage->hid & HID_USAGE) {
37 	case 0x03a: belkin_map_key_clear(KEY_SOUND);		break;
38 	case 0x03b: belkin_map_key_clear(KEY_CAMERA);		break;
39 	case 0x03c: belkin_map_key_clear(KEY_DOCUMENTS);	break;
40 	default:
41 		return 0;
42 	}
43 	return 1;
44 }
45 
46 static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id)
47 {
48 	unsigned long quirks = id->driver_data;
49 	int ret;
50 
51 	hid_set_drvdata(hdev, (void *)quirks);
52 
53 	ret = hid_parse(hdev);
54 	if (ret) {
55 		hid_err(hdev, "parse failed\n");
56 		goto err_free;
57 	}
58 
59 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
60 		((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0));
61 	if (ret) {
62 		hid_err(hdev, "hw start failed\n");
63 		goto err_free;
64 	}
65 
66 	return 0;
67 err_free:
68 	return ret;
69 }
70 
71 static const struct hid_device_id belkin_devices[] = {
72 	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM),
73 		.driver_data = BELKIN_HIDDEV },
74 	{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD),
75 		.driver_data = BELKIN_WKBD },
76 	{ }
77 };
78 MODULE_DEVICE_TABLE(hid, belkin_devices);
79 
80 static struct hid_driver belkin_driver = {
81 	.name = "belkin",
82 	.id_table = belkin_devices,
83 	.input_mapping = belkin_input_mapping,
84 	.probe = belkin_probe,
85 };
86 module_hid_driver(belkin_driver);
87 
88 MODULE_LICENSE("GPL");
89