2 * HID driver for zydacron remote control
4 * Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
14 #include <linux/device.h>
15 #include <linux/hid.h>
16 #include <linux/module.h>
21 struct input_dev *input_ep81;
22 unsigned short last_key[4];
27 * Zydacron remote control has an invalid HID report descriptor,
28 * that needs fixing before we can parse it.
30 static __u8 *zc_report_fixup(struct hid_device *hdev, __u8 *rdesc,
34 rdesc[0x96] == 0xbc && rdesc[0x97] == 0xff &&
35 rdesc[0xca] == 0xbc && rdesc[0xcb] == 0xff &&
36 rdesc[0xe1] == 0xbc && rdesc[0xe2] == 0xff) {
38 "fixing up zydacron remote control report "
40 rdesc[0x96] = rdesc[0xca] = rdesc[0xe1] = 0x0c;
41 rdesc[0x97] = rdesc[0xcb] = rdesc[0xe2] = 0x00;
46 #define zc_map_key_clear(c) \
47 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
49 static int zc_input_mapping(struct hid_device *hdev, struct hid_input *hi,
50 struct hid_field *field, struct hid_usage *usage,
51 unsigned long **bit, int *max)
54 struct zc_device *zc = hid_get_drvdata(hdev);
55 zc->input_ep81 = hi->input;
57 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
60 dbg_hid("zynacron input mapping event [0x%x]\n",
61 usage->hid & HID_USAGE);
63 switch (usage->hid & HID_USAGE) {
66 zc_map_key_clear(KEY_MODE);
69 zc_map_key_clear(KEY_SCREEN);
72 zc_map_key_clear(KEY_INFO);
76 zc_map_key_clear(KEY_RADIO);
80 zc_map_key_clear(KEY_PVR);
83 zc_map_key_clear(KEY_TV);
86 zc_map_key_clear(KEY_AUDIO);
89 zc_map_key_clear(KEY_AUX);
92 zc_map_key_clear(KEY_VIDEO);
95 zc_map_key_clear(KEY_DVD);
98 zc_map_key_clear(KEY_MENU);
101 zc_map_key_clear(KEY_TEXT);
107 for (i = 0; i < 4; i++)
113 static int zc_raw_event(struct hid_device *hdev, struct hid_report *report,
116 struct zc_device *zc = hid_get_drvdata(hdev);
119 unsigned short index;
121 if (report->id == data[0]) {
124 for (index = 0; index < 4; index++) {
125 key = zc->last_key[index];
127 input_event(zc->input_ep81, EV_KEY, key, 0);
128 zc->last_key[index] = 0;
133 switch (report->id) {
156 input_event(zc->input_ep81, EV_KEY, key, 1);
157 zc->last_key[index] = key;
168 static int zc_probe(struct hid_device *hdev, const struct hid_device_id *id)
171 struct zc_device *zc;
173 zc = kzalloc(sizeof(*zc), GFP_KERNEL);
175 dev_err(&hdev->dev, "zydacron: can't alloc descriptor\n");
179 hid_set_drvdata(hdev, zc);
181 ret = hid_parse(hdev);
183 dev_err(&hdev->dev, "zydacron: parse failed\n");
187 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
189 dev_err(&hdev->dev, "zydacron: hw start failed\n");
200 static void zc_remove(struct hid_device *hdev)
202 struct zc_device *zc = hid_get_drvdata(hdev);
210 static const struct hid_device_id zc_devices[] = {
211 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
214 MODULE_DEVICE_TABLE(hid, zc_devices);
216 static struct hid_driver zc_driver = {
218 .id_table = zc_devices,
219 .report_fixup = zc_report_fixup,
220 .input_mapping = zc_input_mapping,
221 .raw_event = zc_raw_event,
226 static int __init zc_init(void)
228 return hid_register_driver(&zc_driver);
231 static void __exit zc_exit(void)
233 hid_unregister_driver(&zc_driver);
236 module_init(zc_init);
237 module_exit(zc_exit);
238 MODULE_LICENSE("GPL");