Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / hid / hid-belkin.c
blob12c8a9ba6ed69badc7340d770954b249c29d1076
1 /*
2 * HID driver for some belkin "special" devices
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
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
19 #include <linux/device.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
23 #include "hid-ids.h"
25 #define BELKIN_HIDDEV 0x01
26 #define BELKIN_WKBD 0x02
28 #define belkin_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
29 EV_KEY, (c))
30 static int belkin_input_mapping(struct hid_device *hdev, struct hid_input *hi,
31 struct hid_field *field, struct hid_usage *usage,
32 unsigned long **bit, int *max)
34 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
36 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER ||
37 !(quirks & BELKIN_WKBD))
38 return 0;
40 switch (usage->hid & HID_USAGE) {
41 case 0x03a: belkin_map_key_clear(KEY_SOUND); break;
42 case 0x03b: belkin_map_key_clear(KEY_CAMERA); break;
43 case 0x03c: belkin_map_key_clear(KEY_DOCUMENTS); break;
44 default:
45 return 0;
47 return 1;
50 static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id)
52 unsigned long quirks = id->driver_data;
53 int ret;
55 hid_set_drvdata(hdev, (void *)quirks);
57 ret = hid_parse(hdev);
58 if (ret) {
59 dev_err(&hdev->dev, "parse failed\n");
60 goto err_free;
63 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
64 ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0));
65 if (ret) {
66 dev_err(&hdev->dev, "hw start failed\n");
67 goto err_free;
70 return 0;
71 err_free:
72 return ret;
75 static const struct hid_device_id belkin_devices[] = {
76 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM),
77 .driver_data = BELKIN_HIDDEV },
78 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD),
79 .driver_data = BELKIN_WKBD },
80 { }
82 MODULE_DEVICE_TABLE(hid, belkin_devices);
84 static struct hid_driver belkin_driver = {
85 .name = "belkin",
86 .id_table = belkin_devices,
87 .input_mapping = belkin_input_mapping,
88 .probe = belkin_probe,
91 static int belkin_init(void)
93 return hid_register_driver(&belkin_driver);
96 static void belkin_exit(void)
98 hid_unregister_driver(&belkin_driver);
101 module_init(belkin_init);
102 module_exit(belkin_exit);
103 MODULE_LICENSE("GPL");
105 HID_COMPAT_LOAD_DRIVER(belkin);