Skip to content

Commit bebf882

Browse files
t-8chJiri Kosina
authored andcommitted
HID: cmedia: add support for HS-100B mute button
These chips report mute button events in bit 4 of their report without it being part of the report descriptor. Use a custom descriptor that maps this bit. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent df04fbe commit bebf882

3 files changed

Lines changed: 92 additions & 4 deletions

File tree

drivers/hid/Kconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,11 @@ config HID_PRODIKEYS
259259
and some additional multimedia keys.
260260

261261
config HID_CMEDIA
262-
tristate "CMedia CM6533 HID audio jack controls"
262+
tristate "CMedia audio chips"
263263
depends on HID
264264
help
265-
Support for CMedia CM6533 HID audio jack controls.
265+
Support for CMedia CM6533 HID audio jack controls
266+
and HS100B mute buttons.
266267

267268
config HID_CP2112
268269
tristate "Silicon Labs CP2112 HID USB-to-SMBus Bridge support"

drivers/hid/hid-cmedia.c

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
33
* HID driver for CMedia CM6533 audio jack controls
4+
* and HS100B mute buttons
45
*
56
* Copyright (C) 2015 Ben Chen <ben_chen@bizlinktech.com>
7+
* Copyright (C) 2021 Thomas Weißschuh <linux@weissschuh.net>
68
*/
79

810
#include <linux/device.h>
@@ -11,13 +13,53 @@
1113
#include "hid-ids.h"
1214

1315
MODULE_AUTHOR("Ben Chen");
14-
MODULE_DESCRIPTION("CM6533 HID jack controls");
16+
MODULE_AUTHOR("Thomas Weißschuh");
17+
MODULE_DESCRIPTION("CM6533 HID jack controls and HS100B mute button");
1518
MODULE_LICENSE("GPL");
1619

1720
#define CM6533_JD_TYPE_COUNT 1
1821
#define CM6533_JD_RAWEV_LEN 16
1922
#define CM6533_JD_SFX_OFFSET 8
2023

24+
#define HS100B_RDESC_ORIG_SIZE 60
25+
26+
/* Fixed report descriptor of HS-100B audio chip
27+
* Bit 4 is an abolute Microphone mute usage instead of being unassigned.
28+
*/
29+
static __u8 hs100b_rdesc_fixed[] = {
30+
0x05, 0x0C, /* Usage Page (Consumer), */
31+
0x09, 0x01, /* Usage (Consumer Control), */
32+
0xA1, 0x01, /* Collection (Application), */
33+
0x15, 0x00, /* Logical Minimum (0), */
34+
0x25, 0x01, /* Logical Maximum (1), */
35+
0x09, 0xE9, /* Usage (Volume Inc), */
36+
0x09, 0xEA, /* Usage (Volume Dec), */
37+
0x75, 0x01, /* Report Size (1), */
38+
0x95, 0x02, /* Report Count (2), */
39+
0x81, 0x02, /* Input (Variable), */
40+
0x09, 0xE2, /* Usage (Mute), */
41+
0x95, 0x01, /* Report Count (1), */
42+
0x81, 0x06, /* Input (Variable, Relative), */
43+
0x05, 0x0B, /* Usage Page (Telephony), */
44+
0x09, 0x2F, /* Usage (2Fh), */
45+
0x81, 0x02, /* Input (Variable), */
46+
0x09, 0x20, /* Usage (20h), */
47+
0x81, 0x06, /* Input (Variable, Relative), */
48+
0x05, 0x0C, /* Usage Page (Consumer), */
49+
0x09, 0x00, /* Usage (00h), */
50+
0x95, 0x03, /* Report Count (3), */
51+
0x81, 0x02, /* Input (Variable), */
52+
0x26, 0xFF, 0x00, /* Logical Maximum (255), */
53+
0x09, 0x00, /* Usage (00h), */
54+
0x75, 0x08, /* Report Size (8), */
55+
0x95, 0x03, /* Report Count (3), */
56+
0x81, 0x02, /* Input (Variable), */
57+
0x09, 0x00, /* Usage (00h), */
58+
0x95, 0x04, /* Report Count (4), */
59+
0x91, 0x02, /* Output (Variable), */
60+
0xC0 /* End Collection */
61+
};
62+
2163
/*
2264
*
2365
*CM6533 audio jack HID raw events:
@@ -156,5 +198,49 @@ static struct hid_driver cmhid_driver = {
156198
.remove = cmhid_remove,
157199
.input_mapping = cmhid_input_mapping,
158200
};
159-
module_hid_driver(cmhid_driver);
160201

202+
static __u8 *cmhid_hs100b_report_fixup(struct hid_device *hid, __u8 *rdesc,
203+
unsigned int *rsize)
204+
{
205+
if (*rsize == HS100B_RDESC_ORIG_SIZE) {
206+
hid_info(hid, "Fixing CMedia HS-100B report descriptor\n");
207+
rdesc = hs100b_rdesc_fixed;
208+
*rsize = sizeof(hs100b_rdesc_fixed);
209+
}
210+
return rdesc;
211+
}
212+
213+
static const struct hid_device_id cmhid_hs100b_devices[] = {
214+
{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CMEDIA_HS100B) },
215+
{ }
216+
};
217+
MODULE_DEVICE_TABLE(hid, cmhid_hs100b_devices);
218+
219+
static struct hid_driver cmhid_hs100b_driver = {
220+
.name = "cmedia_hs100b",
221+
.id_table = cmhid_hs100b_devices,
222+
.report_fixup = cmhid_hs100b_report_fixup,
223+
};
224+
225+
static int cmedia_init(void)
226+
{
227+
int ret;
228+
229+
ret = hid_register_driver(&cmhid_driver);
230+
if (ret)
231+
return ret;
232+
233+
ret = hid_register_driver(&cmhid_hs100b_driver);
234+
if (ret)
235+
hid_unregister_driver(&cmhid_driver);
236+
237+
return ret;
238+
}
239+
module_init(cmedia_init);
240+
241+
static void cmedia_exit(void)
242+
{
243+
hid_unregister_driver(&cmhid_driver);
244+
hid_unregister_driver(&cmhid_hs100b_driver);
245+
}
246+
module_exit(cmedia_exit);

drivers/hid/hid-ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292

293293
#define USB_VENDOR_ID_CMEDIA 0x0d8c
294294
#define USB_DEVICE_ID_CM109 0x000e
295+
#define USB_DEVICE_ID_CMEDIA_HS100B 0x0014
295296
#define USB_DEVICE_ID_CM6533 0x0022
296297

297298
#define USB_VENDOR_ID_CODEMERCS 0x07c0

0 commit comments

Comments
 (0)