1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HID driver for zydacron remote control
5 * Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk>
11 #include <linux/device.h>
12 #include <linux/hid.h>
13 #include <linux/module.h>
18 struct input_dev
*input_ep81
;
19 unsigned short last_key
[4];
24 * Zydacron remote control has an invalid HID report descriptor,
25 * that needs fixing before we can parse it.
27 static __u8
*zc_report_fixup(struct hid_device
*hdev
, __u8
*rdesc
,
31 rdesc
[0x96] == 0xbc && rdesc
[0x97] == 0xff &&
32 rdesc
[0xca] == 0xbc && rdesc
[0xcb] == 0xff &&
33 rdesc
[0xe1] == 0xbc && rdesc
[0xe2] == 0xff) {
35 "fixing up zydacron remote control report descriptor\n");
36 rdesc
[0x96] = rdesc
[0xca] = rdesc
[0xe1] = 0x0c;
37 rdesc
[0x97] = rdesc
[0xcb] = rdesc
[0xe2] = 0x00;
42 #define zc_map_key_clear(c) \
43 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
45 static int zc_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
46 struct hid_field
*field
, struct hid_usage
*usage
,
47 unsigned long **bit
, int *max
)
50 struct zc_device
*zc
= hid_get_drvdata(hdev
);
51 zc
->input_ep81
= hi
->input
;
53 if ((usage
->hid
& HID_USAGE_PAGE
) != HID_UP_CONSUMER
)
56 dbg_hid("zynacron input mapping event [0x%x]\n",
57 usage
->hid
& HID_USAGE
);
59 switch (usage
->hid
& HID_USAGE
) {
62 zc_map_key_clear(KEY_MODE
);
65 zc_map_key_clear(KEY_SCREEN
);
68 zc_map_key_clear(KEY_INFO
);
72 zc_map_key_clear(KEY_RADIO
);
76 zc_map_key_clear(KEY_PVR
);
79 zc_map_key_clear(KEY_TV
);
82 zc_map_key_clear(KEY_AUDIO
);
85 zc_map_key_clear(KEY_AUX
);
88 zc_map_key_clear(KEY_VIDEO
);
91 zc_map_key_clear(KEY_DVD
);
94 zc_map_key_clear(KEY_MENU
);
97 zc_map_key_clear(KEY_TEXT
);
103 for (i
= 0; i
< 4; i
++)
109 static int zc_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
112 struct zc_device
*zc
= hid_get_drvdata(hdev
);
115 unsigned short index
;
117 if (report
->id
== data
[0]) {
120 for (index
= 0; index
< 4; index
++) {
121 key
= zc
->last_key
[index
];
123 input_event(zc
->input_ep81
, EV_KEY
, key
, 0);
124 zc
->last_key
[index
] = 0;
129 switch (report
->id
) {
152 input_event(zc
->input_ep81
, EV_KEY
, key
, 1);
153 zc
->last_key
[index
] = key
;
164 static int zc_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
167 struct zc_device
*zc
;
169 zc
= devm_kzalloc(&hdev
->dev
, sizeof(*zc
), GFP_KERNEL
);
171 hid_err(hdev
, "can't alloc descriptor\n");
175 hid_set_drvdata(hdev
, zc
);
177 ret
= hid_parse(hdev
);
179 hid_err(hdev
, "parse failed\n");
183 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
185 hid_err(hdev
, "hw start failed\n");
192 static const struct hid_device_id zc_devices
[] = {
193 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON
, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL
) },
196 MODULE_DEVICE_TABLE(hid
, zc_devices
);
198 static struct hid_driver zc_driver
= {
200 .id_table
= zc_devices
,
201 .report_fixup
= zc_report_fixup
,
202 .input_mapping
= zc_input_mapping
,
203 .raw_event
= zc_raw_event
,
206 module_hid_driver(zc_driver
);
208 MODULE_LICENSE("GPL");