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 descriptor\n");
39 rdesc
[0x96] = rdesc
[0xca] = rdesc
[0xe1] = 0x0c;
40 rdesc
[0x97] = rdesc
[0xcb] = rdesc
[0xe2] = 0x00;
45 #define zc_map_key_clear(c) \
46 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
48 static int zc_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
49 struct hid_field
*field
, struct hid_usage
*usage
,
50 unsigned long **bit
, int *max
)
53 struct zc_device
*zc
= hid_get_drvdata(hdev
);
54 zc
->input_ep81
= hi
->input
;
56 if ((usage
->hid
& HID_USAGE_PAGE
) != HID_UP_CONSUMER
)
59 dbg_hid("zynacron input mapping event [0x%x]\n",
60 usage
->hid
& HID_USAGE
);
62 switch (usage
->hid
& HID_USAGE
) {
65 zc_map_key_clear(KEY_MODE
);
68 zc_map_key_clear(KEY_SCREEN
);
71 zc_map_key_clear(KEY_INFO
);
75 zc_map_key_clear(KEY_RADIO
);
79 zc_map_key_clear(KEY_PVR
);
82 zc_map_key_clear(KEY_TV
);
85 zc_map_key_clear(KEY_AUDIO
);
88 zc_map_key_clear(KEY_AUX
);
91 zc_map_key_clear(KEY_VIDEO
);
94 zc_map_key_clear(KEY_DVD
);
97 zc_map_key_clear(KEY_MENU
);
100 zc_map_key_clear(KEY_TEXT
);
106 for (i
= 0; i
< 4; i
++)
112 static int zc_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
115 struct zc_device
*zc
= hid_get_drvdata(hdev
);
118 unsigned short index
;
120 if (report
->id
== data
[0]) {
123 for (index
= 0; index
< 4; index
++) {
124 key
= zc
->last_key
[index
];
126 input_event(zc
->input_ep81
, EV_KEY
, key
, 0);
127 zc
->last_key
[index
] = 0;
132 switch (report
->id
) {
155 input_event(zc
->input_ep81
, EV_KEY
, key
, 1);
156 zc
->last_key
[index
] = key
;
167 static int zc_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
170 struct zc_device
*zc
;
172 zc
= kzalloc(sizeof(*zc
), GFP_KERNEL
);
174 hid_err(hdev
, "can't alloc descriptor\n");
178 hid_set_drvdata(hdev
, zc
);
180 ret
= hid_parse(hdev
);
182 hid_err(hdev
, "parse failed\n");
186 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
188 hid_err(hdev
, "hw start failed\n");
199 static void zc_remove(struct hid_device
*hdev
)
201 struct zc_device
*zc
= hid_get_drvdata(hdev
);
209 static const struct hid_device_id zc_devices
[] = {
210 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON
, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL
) },
213 MODULE_DEVICE_TABLE(hid
, zc_devices
);
215 static struct hid_driver zc_driver
= {
217 .id_table
= zc_devices
,
218 .report_fixup
= zc_report_fixup
,
219 .input_mapping
= zc_input_mapping
,
220 .raw_event
= zc_raw_event
,
225 static int __init
zc_init(void)
227 return hid_register_driver(&zc_driver
);
230 static void __exit
zc_exit(void)
232 hid_unregister_driver(&zc_driver
);
235 module_init(zc_init
);
236 module_exit(zc_exit
);
237 MODULE_LICENSE("GPL");