Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for some belkin "special" devices |
| 3 | * |
| 4 | * Copyright (c) 1999 Andreas Gal |
| 5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
| 7 | * Copyright (c) 2006-2007 Jiri Kosina |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 8 | * Copyright (c) 2008 Jiri Slaby |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the Free |
| 14 | * Software Foundation; either version 2 of the License, or (at your option) |
| 15 | * any later version. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/device.h> |
| 19 | #include <linux/hid.h> |
| 20 | #include <linux/module.h> |
| 21 | |
| 22 | #include "hid-ids.h" |
| 23 | |
| 24 | #define BELKIN_HIDDEV 0x01 |
| 25 | #define BELKIN_WKBD 0x02 |
| 26 | |
| 27 | #define belkin_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 28 | EV_KEY, (c)) |
| 29 | static int belkin_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 30 | struct hid_field *field, struct hid_usage *usage, |
| 31 | unsigned long **bit, int *max) |
| 32 | { |
| 33 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); |
| 34 | |
| 35 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER || |
| 36 | !(quirks & BELKIN_WKBD)) |
| 37 | return 0; |
| 38 | |
| 39 | switch (usage->hid & HID_USAGE) { |
| 40 | case 0x03a: belkin_map_key_clear(KEY_SOUND); break; |
| 41 | case 0x03b: belkin_map_key_clear(KEY_CAMERA); break; |
| 42 | case 0x03c: belkin_map_key_clear(KEY_DOCUMENTS); break; |
| 43 | default: |
| 44 | return 0; |
| 45 | } |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 50 | { |
| 51 | unsigned long quirks = id->driver_data; |
| 52 | int ret; |
| 53 | |
| 54 | hid_set_drvdata(hdev, (void *)quirks); |
| 55 | |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 56 | ret = hid_parse(hdev); |
| 57 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 58 | hid_err(hdev, "parse failed\n"); |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 59 | goto err_free; |
| 60 | } |
| 61 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 62 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | |
| 63 | ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0)); |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 64 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 65 | hid_err(hdev, "hw start failed\n"); |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 66 | goto err_free; |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | err_free: |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | static const struct hid_device_id belkin_devices[] = { |
| 75 | { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM), |
| 76 | .driver_data = BELKIN_HIDDEV }, |
| 77 | { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD), |
| 78 | .driver_data = BELKIN_WKBD }, |
| 79 | { } |
| 80 | }; |
| 81 | MODULE_DEVICE_TABLE(hid, belkin_devices); |
| 82 | |
| 83 | static struct hid_driver belkin_driver = { |
| 84 | .name = "belkin", |
| 85 | .id_table = belkin_devices, |
| 86 | .input_mapping = belkin_input_mapping, |
| 87 | .probe = belkin_probe, |
| 88 | }; |
| 89 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 90 | static int __init belkin_init(void) |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 91 | { |
| 92 | return hid_register_driver(&belkin_driver); |
| 93 | } |
| 94 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 95 | static void __exit belkin_exit(void) |
Jiri Slaby | b5635b1 | 2008-06-24 23:24:57 +0200 | [diff] [blame] | 96 | { |
| 97 | hid_unregister_driver(&belkin_driver); |
| 98 | } |
| 99 | |
| 100 | module_init(belkin_init); |
| 101 | module_exit(belkin_exit); |
| 102 | MODULE_LICENSE("GPL"); |