Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 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 |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 9 | * Copyright (c) 2008 Jiri Slaby |
| 10 | */ |
| 11 | |
| 12 | /* |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 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 | |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 53 | ret = hid_parse(hdev); |
| 54 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 55 | hid_err(hdev, "parse failed\n"); |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 56 | goto err_free; |
| 57 | } |
| 58 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 59 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | |
| 60 | ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0)); |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 61 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 62 | hid_err(hdev, "hw start failed\n"); |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 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 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 86 | module_hid_driver(belkin_driver); |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 87 | |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 88 | MODULE_LICENSE("GPL"); |