xref: /linux/drivers/hid/hid-cherry.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
23b239cd7SJiri Slaby /*
33b239cd7SJiri Slaby  *  HID driver for some cherry "special" devices
43b239cd7SJiri Slaby  *
53b239cd7SJiri Slaby  *  Copyright (c) 1999 Andreas Gal
63b239cd7SJiri Slaby  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
73b239cd7SJiri Slaby  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
83b239cd7SJiri Slaby  *  Copyright (c) 2006-2007 Jiri Kosina
93b239cd7SJiri Slaby  *  Copyright (c) 2008 Jiri Slaby
103b239cd7SJiri Slaby  */
113b239cd7SJiri Slaby 
123b239cd7SJiri Slaby /*
133b239cd7SJiri Slaby  */
143b239cd7SJiri Slaby 
153b239cd7SJiri Slaby #include <linux/device.h>
163b239cd7SJiri Slaby #include <linux/hid.h>
173b239cd7SJiri Slaby #include <linux/module.h>
183b239cd7SJiri Slaby 
193b239cd7SJiri Slaby #include "hid-ids.h"
203b239cd7SJiri Slaby 
213b239cd7SJiri Slaby /*
223b239cd7SJiri Slaby  * Cherry Cymotion keyboard have an invalid HID report descriptor,
233b239cd7SJiri Slaby  * that needs fixing before we can parse it.
243b239cd7SJiri Slaby  */
ch_report_fixup(struct hid_device * hdev,__u8 * rdesc,unsigned int * rsize)25*fe73965dSThomas Weißschuh static const __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
2673e4008dSNikolai Kondrashov 		unsigned int *rsize)
273b239cd7SJiri Slaby {
284ab25786SJiri Kosina 	if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
294291ee30SJoe Perches 		hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
303b239cd7SJiri Slaby 		rdesc[11] = rdesc[16] = 0xff;
313b239cd7SJiri Slaby 		rdesc[12] = rdesc[17] = 0x03;
323b239cd7SJiri Slaby 	}
3373e4008dSNikolai Kondrashov 	return rdesc;
343b239cd7SJiri Slaby }
353b239cd7SJiri Slaby 
363b239cd7SJiri Slaby #define ch_map_key_clear(c)	hid_map_usage_clear(hi, usage, bit, max, \
373b239cd7SJiri Slaby 					EV_KEY, (c))
ch_input_mapping(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)383b239cd7SJiri Slaby static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
393b239cd7SJiri Slaby 		struct hid_field *field, struct hid_usage *usage,
403b239cd7SJiri Slaby 		unsigned long **bit, int *max)
413b239cd7SJiri Slaby {
423b239cd7SJiri Slaby 	if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
433b239cd7SJiri Slaby 		return 0;
443b239cd7SJiri Slaby 
453b239cd7SJiri Slaby 	switch (usage->hid & HID_USAGE) {
463b239cd7SJiri Slaby 	case 0x301: ch_map_key_clear(KEY_PROG1);	break;
473b239cd7SJiri Slaby 	case 0x302: ch_map_key_clear(KEY_PROG2);	break;
483b239cd7SJiri Slaby 	case 0x303: ch_map_key_clear(KEY_PROG3);	break;
493b239cd7SJiri Slaby 	default:
503b239cd7SJiri Slaby 		return 0;
513b239cd7SJiri Slaby 	}
523b239cd7SJiri Slaby 
533b239cd7SJiri Slaby 	return 1;
543b239cd7SJiri Slaby }
553b239cd7SJiri Slaby 
563b239cd7SJiri Slaby static const struct hid_device_id ch_devices[] = {
573b239cd7SJiri Slaby 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
581ce31b25SRaphaël Doursenaud 	{ HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
593b239cd7SJiri Slaby 	{ }
603b239cd7SJiri Slaby };
613b239cd7SJiri Slaby MODULE_DEVICE_TABLE(hid, ch_devices);
623b239cd7SJiri Slaby 
633b239cd7SJiri Slaby static struct hid_driver ch_driver = {
643b239cd7SJiri Slaby 	.name = "cherry",
653b239cd7SJiri Slaby 	.id_table = ch_devices,
663b239cd7SJiri Slaby 	.report_fixup = ch_report_fixup,
673b239cd7SJiri Slaby 	.input_mapping = ch_input_mapping,
683b239cd7SJiri Slaby };
69f425458eSH Hartley Sweeten module_hid_driver(ch_driver);
703b239cd7SJiri Slaby 
719d262f35SJeff Johnson MODULE_DESCRIPTION("HID driver for some cherry \"special\" devices");
723b239cd7SJiri Slaby MODULE_LICENSE("GPL");
73