Jiri Slaby | 3b239cd | 2008-06-24 20:42:25 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for some cherry "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 |
| 8 | * Copyright (c) 2007 Paul Walmsley |
| 9 | * Copyright (c) 2008 Jiri Slaby |
| 10 | */ |
| 11 | |
| 12 | /* |
| 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. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/hid.h> |
| 21 | #include <linux/module.h> |
| 22 | |
| 23 | #include "hid-ids.h" |
| 24 | |
| 25 | /* |
| 26 | * Cherry Cymotion keyboard have an invalid HID report descriptor, |
| 27 | * that needs fixing before we can parse it. |
| 28 | */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 29 | static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 30 | unsigned int *rsize) |
Jiri Slaby | 3b239cd | 2008-06-24 20:42:25 +0200 | [diff] [blame] | 31 | { |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 32 | if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 33 | hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n"); |
Jiri Slaby | 3b239cd | 2008-06-24 20:42:25 +0200 | [diff] [blame] | 34 | rdesc[11] = rdesc[16] = 0xff; |
| 35 | rdesc[12] = rdesc[17] = 0x03; |
| 36 | } |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 37 | return rdesc; |
Jiri Slaby | 3b239cd | 2008-06-24 20:42:25 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 41 | EV_KEY, (c)) |
| 42 | static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 43 | struct hid_field *field, struct hid_usage *usage, |
| 44 | unsigned long **bit, int *max) |
| 45 | { |
| 46 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) |
| 47 | return 0; |
| 48 | |
| 49 | switch (usage->hid & HID_USAGE) { |
| 50 | case 0x301: ch_map_key_clear(KEY_PROG1); break; |
| 51 | case 0x302: ch_map_key_clear(KEY_PROG2); break; |
| 52 | case 0x303: ch_map_key_clear(KEY_PROG3); break; |
| 53 | default: |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | static const struct hid_device_id ch_devices[] = { |
| 61 | { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, |
Raphaƫl Doursenaud | 1ce31b2 | 2010-04-08 13:40:52 +0200 | [diff] [blame] | 62 | { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) }, |
Jiri Slaby | 3b239cd | 2008-06-24 20:42:25 +0200 | [diff] [blame] | 63 | { } |
| 64 | }; |
| 65 | MODULE_DEVICE_TABLE(hid, ch_devices); |
| 66 | |
| 67 | static struct hid_driver ch_driver = { |
| 68 | .name = "cherry", |
| 69 | .id_table = ch_devices, |
| 70 | .report_fixup = ch_report_fixup, |
| 71 | .input_mapping = ch_input_mapping, |
| 72 | }; |
| 73 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 74 | static int __init ch_init(void) |
Jiri Slaby | 3b239cd | 2008-06-24 20:42:25 +0200 | [diff] [blame] | 75 | { |
| 76 | return hid_register_driver(&ch_driver); |
| 77 | } |
| 78 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 79 | static void __exit ch_exit(void) |
Jiri Slaby | 3b239cd | 2008-06-24 20:42:25 +0200 | [diff] [blame] | 80 | { |
| 81 | hid_unregister_driver(&ch_driver); |
| 82 | } |
| 83 | |
| 84 | module_init(ch_init); |
| 85 | module_exit(ch_exit); |
| 86 | MODULE_LICENSE("GPL"); |