blob: fc0b3bb383cc7b7eba98da4c98a76dd4f770b962 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jiri Slabyb5635b12008-06-24 23:24:57 +02002/*
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
Jiri Slabyb5635b12008-06-24 23:24:57 +02009 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
Jiri Slabyb5635b12008-06-24 23:24:57 +020013 */
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))
26static 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
46static 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
Jiri Slabyb5635b12008-06-24 23:24:57 +020053 ret = hid_parse(hdev);
54 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -080055 hid_err(hdev, "parse failed\n");
Jiri Slabyb5635b12008-06-24 23:24:57 +020056 goto err_free;
57 }
58
Jiri Slaby93c10132008-06-27 00:04:24 +020059 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
60 ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0));
Jiri Slabyb5635b12008-06-24 23:24:57 +020061 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -080062 hid_err(hdev, "hw start failed\n");
Jiri Slabyb5635b12008-06-24 23:24:57 +020063 goto err_free;
64 }
65
66 return 0;
67err_free:
68 return ret;
69}
70
71static 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};
78MODULE_DEVICE_TABLE(hid, belkin_devices);
79
80static struct hid_driver belkin_driver = {
81 .name = "belkin",
82 .id_table = belkin_devices,
83 .input_mapping = belkin_input_mapping,
84 .probe = belkin_probe,
85};
H Hartley Sweetenf4254582012-12-17 15:28:26 -070086module_hid_driver(belkin_driver);
Jiri Slabyb5635b12008-06-24 23:24:57 +020087
Jiri Slabyb5635b12008-06-24 23:24:57 +020088MODULE_LICENSE("GPL");