blob: 6a71187b5cf659124f2e165de37efd881a3da90c [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jiri Slaby3b239cd2008-06-24 20:42:25 +02002/*
3 * HID driver for some cherry "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 Slaby3b239cd2008-06-24 20:42:25 +02009 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
Jiri Slaby3b239cd2008-06-24 20:42:25 +020013 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
18
19#include "hid-ids.h"
20
21/*
22 * Cherry Cymotion keyboard have an invalid HID report descriptor,
23 * that needs fixing before we can parse it.
24 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040025static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
26 unsigned int *rsize)
Jiri Slaby3b239cd2008-06-24 20:42:25 +020027{
Jiri Kosina4ab25782014-08-21 09:57:48 -050028 if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
Joe Perches4291ee32010-12-09 19:29:03 -080029 hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
Jiri Slaby3b239cd2008-06-24 20:42:25 +020030 rdesc[11] = rdesc[16] = 0xff;
31 rdesc[12] = rdesc[17] = 0x03;
32 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040033 return rdesc;
Jiri Slaby3b239cd2008-06-24 20:42:25 +020034}
35
36#define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
37 EV_KEY, (c))
38static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
39 struct hid_field *field, struct hid_usage *usage,
40 unsigned long **bit, int *max)
41{
42 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
43 return 0;
44
45 switch (usage->hid & HID_USAGE) {
46 case 0x301: ch_map_key_clear(KEY_PROG1); break;
47 case 0x302: ch_map_key_clear(KEY_PROG2); break;
48 case 0x303: ch_map_key_clear(KEY_PROG3); break;
49 default:
50 return 0;
51 }
52
53 return 1;
54}
55
56static const struct hid_device_id ch_devices[] = {
57 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
Raphaƫl Doursenaud1ce31b22010-04-08 13:40:52 +020058 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
Jiri Slaby3b239cd2008-06-24 20:42:25 +020059 { }
60};
61MODULE_DEVICE_TABLE(hid, ch_devices);
62
63static struct hid_driver ch_driver = {
64 .name = "cherry",
65 .id_table = ch_devices,
66 .report_fixup = ch_report_fixup,
67 .input_mapping = ch_input_mapping,
68};
H Hartley Sweetenf4254582012-12-17 15:28:26 -070069module_hid_driver(ch_driver);
Jiri Slaby3b239cd2008-06-24 20:42:25 +020070
Jiri Slaby3b239cd2008-06-24 20:42:25 +020071MODULE_LICENSE("GPL");