blob: f745d2c1325ec8872a376e668cdd71b3c9c523f3 [file] [log] [blame]
Jiri Slaby3b239cd2008-06-24 20:42:25 +02001/*
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
Jiri Slaby3b239cd2008-06-24 20:42:25 +02008 * 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/*
25 * Cherry Cymotion keyboard have an invalid HID report descriptor,
26 * that needs fixing before we can parse it.
27 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040028static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
29 unsigned int *rsize)
Jiri Slaby3b239cd2008-06-24 20:42:25 +020030{
Jiri Kosina4ab25782014-08-21 09:57:48 -050031 if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
Joe Perches4291ee32010-12-09 19:29:03 -080032 hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
Jiri Slaby3b239cd2008-06-24 20:42:25 +020033 rdesc[11] = rdesc[16] = 0xff;
34 rdesc[12] = rdesc[17] = 0x03;
35 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040036 return rdesc;
Jiri Slaby3b239cd2008-06-24 20:42:25 +020037}
38
39#define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
40 EV_KEY, (c))
41static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
42 struct hid_field *field, struct hid_usage *usage,
43 unsigned long **bit, int *max)
44{
45 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
46 return 0;
47
48 switch (usage->hid & HID_USAGE) {
49 case 0x301: ch_map_key_clear(KEY_PROG1); break;
50 case 0x302: ch_map_key_clear(KEY_PROG2); break;
51 case 0x303: ch_map_key_clear(KEY_PROG3); break;
52 default:
53 return 0;
54 }
55
56 return 1;
57}
58
59static const struct hid_device_id ch_devices[] = {
60 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
Raphaƫl Doursenaud1ce31b22010-04-08 13:40:52 +020061 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
Jiri Slaby3b239cd2008-06-24 20:42:25 +020062 { }
63};
64MODULE_DEVICE_TABLE(hid, ch_devices);
65
66static struct hid_driver ch_driver = {
67 .name = "cherry",
68 .id_table = ch_devices,
69 .report_fixup = ch_report_fixup,
70 .input_mapping = ch_input_mapping,
71};
H Hartley Sweetenf4254582012-12-17 15:28:26 -070072module_hid_driver(ch_driver);
Jiri Slaby3b239cd2008-06-24 20:42:25 +020073
Jiri Slaby3b239cd2008-06-24 20:42:25 +020074MODULE_LICENSE("GPL");