Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / hid / hid-belkin.c
blobfc0b3bb383cc7b7eba98da4c98a76dd4f770b962
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * HID driver for some belkin "special" devices
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
15 #include <linux/device.h>
16 #include <linux/hid.h>
17 #include <linux/module.h>
19 #include "hid-ids.h"
21 #define BELKIN_HIDDEV 0x01
22 #define BELKIN_WKBD 0x02
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)
30 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
32 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER ||
33 !(quirks & BELKIN_WKBD))
34 return 0;
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;
43 return 1;
46 static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id)
48 unsigned long quirks = id->driver_data;
49 int ret;
51 hid_set_drvdata(hdev, (void *)quirks);
53 ret = hid_parse(hdev);
54 if (ret) {
55 hid_err(hdev, "parse failed\n");
56 goto err_free;
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;
66 return 0;
67 err_free:
68 return ret;
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 { }
78 MODULE_DEVICE_TABLE(hid, belkin_devices);
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,
86 module_hid_driver(belkin_driver);
88 MODULE_LICENSE("GPL");