Skip to contentSkip to conversation

HID: add cmedia-fixup driver

PATCH In review Thomas Weißschuh 3 participants 7 messages Jul 4, 2021 – Jul 20, 2021 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: add cmedia-fixup driver

This driver provides HID fixups for CMedia audio chips.
For now this enables the recognition of the microphone mute button for the HS-100B.

---
 drivers/hid/Kconfig            |  6 +++
 drivers/hid/Makefile           |  1 +
 drivers/hid/hid-cmedia-fixup.c | 82 ++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h          |  1 +
 drivers/hid/hid-quirks.c       |  3 ++
 5 files changed, 93 insertions(+)
 create mode 100644 drivers/hid/hid-cmedia-fixup.c
drivers/hid/Kconfig +6 -0
index 160554903ef9..5e139c93f75a 100644
@@ -264,6 +264,12 @@ config HID_CMEDIA
 	help
 	Support for CMedia CM6533 HID audio jack controls.
 
+config HID_CMEDIA_FIXUP
+	tristate "CMedia hid fixup"
+	depends on HID
+	help
+	Fixups for CMedia based audio chips.
+
 config HID_CP2112
 	tristate "Silicon Labs CP2112 HID USB-to-SMBus Bridge support"
 	depends on USB_HID && HIDRAW && I2C && GPIOLIB
drivers/hid/Makefile +1 -0
index 1ea1a7c0b20f..66d6b06ce4d2 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_HID_BIGBEN_FF)	+= hid-bigbenff.o
 obj-$(CONFIG_HID_CHERRY)	+= hid-cherry.o
 obj-$(CONFIG_HID_CHICONY)	+= hid-chicony.o
 obj-$(CONFIG_HID_CMEDIA)	+= hid-cmedia.o
+obj-$(CONFIG_HID_CMEDIA_FIXUP)	+= hid-cmedia-fixup.o
 obj-$(CONFIG_HID_CORSAIR)	+= hid-corsair.o
 obj-$(CONFIG_HID_COUGAR)	+= hid-cougar.o
 obj-$(CONFIG_HID_CP2112)	+= hid-cp2112.o
drivers/hid/hid-cmedia-fixup.c new file +82 -0

82 lines not on this page · raw message

drivers/hid/hid-ids.h +1 -0
index 8f1893e68112..6864e4e6ac8b 100644
@@ -292,6 +292,7 @@
 
 #define USB_VENDOR_ID_CMEDIA		0x0d8c
 #define USB_DEVICE_ID_CM109		0x000e
+#define USB_DEVICE_ID_CMEDIA_HS100B	0x0014
 #define USB_DEVICE_ID_CM6533		0x0022
 
 #define USB_VENDOR_ID_CODEMERCS		0x07c0
drivers/hid/hid-quirks.c +3 -0
index 51b39bda9a9d..7776aa13ee27 100644
@@ -346,6 +346,9 @@ static const struct hid_device_id hid_have_special_driver[] = {
 #if IS_ENABLED(CONFIG_HID_CMEDIA)
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
 #endif
+#if IS_ENABLED(CONFIG_HID_CMEDIA_FIXUP)
+	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CMEDIA_HS100B) },
+#endif
 #if IS_ENABLED(CONFIG_HID_CORSAIR)
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K90) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_GLAIVE_RGB) },

base-commit: df04fbe8680bfe07f3d7487eccff9f768bb02533

Signature · 1 line
2.32.0
maintainer
#1 lore raw
Quoted 5 lines · Thomas Weißschuh

This driver provides HID fixups for CMedia audio chips.
For now this enables the recognition of the microphone mute button for the HS-100B.

Quoted 8 lines
---
 drivers/hid/Kconfig            |  6 +++
 drivers/hid/Makefile           |  1 +
 drivers/hid/hid-cmedia-fixup.c | 82 ++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h          |  1 +
 drivers/hid/hid-quirks.c       |  3 ++
 5 files changed, 93 insertions(+)
 create mode 100644 drivers/hid/hid-cmedia-fixup.c

Can you please drop the '-fixup' from the driver name? We have quite a couple of drivers that do report descriptor modifications, but we're not using this '-fixup' naming scheme for them either.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#2 lore raw
Quoted 16 lines · Jiri Kosina
Quoted 5 lines · Thomas Weißschuh

This driver provides HID fixups for CMedia audio chips.
For now this enables the recognition of the microphone mute button for the HS-100B.

Quoted 8 lines
---
 drivers/hid/Kconfig            |  6 +++
 drivers/hid/Makefile           |  1 +
 drivers/hid/hid-cmedia-fixup.c | 82 ++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h          |  1 +
 drivers/hid/hid-quirks.c       |  3 ++
 5 files changed, 93 insertions(+)
 create mode 100644 drivers/hid/hid-cmedia-fixup.c
Quoted 3 lines

Can you please drop the '-fixup' from the driver name? We have quite a couple of drivers that do report descriptor modifications, but we're not using this '-fixup' naming scheme for them either.

There is already an existing driver "hid-cmedia":
"HID driver for CMedia CM6533 audio jack controls".

This driver works in a completely different way from mine, so I thought to keep them separate.
The idea was for the new driver to be a collection of simple, similar report fixups.

Should they be combined?

Thomas

maintainer
#3 lore raw
Quoted 18 lines · Thomas Weißschuh
Quoted 14 lines
Quoted 5 lines

This driver provides HID fixups for CMedia audio chips.
For now this enables the recognition of the microphone mute button for the HS-100B.

Quoted 8 lines
---
 drivers/hid/Kconfig            |  6 +++
 drivers/hid/Makefile           |  1 +
 drivers/hid/hid-cmedia-fixup.c | 82 ++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h          |  1 +
 drivers/hid/hid-quirks.c       |  3 ++
 5 files changed, 93 insertions(+)
 create mode 100644 drivers/hid/hid-cmedia-fixup.c
Quoted 3 lines

Can you please drop the '-fixup' from the driver name? We have quite a couple of drivers that do report descriptor modifications, but we're not using this '-fixup' naming scheme for them either.

Quoted 8 lines

There is already an existing driver "hid-cmedia":
"HID driver for CMedia CM6533 audio jack controls".

This driver works in a completely different way from mine, so I thought to keep them separate. The idea was for the new driver to be a collection of simple, similar report fixups.

Should they be combined?

If it's the same vendor, then yes. We generally (with exceptions, of course :) ) group the HID drivers by vendor, even if completely different quirks are needed for different devices from the same vendor.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#4 lore raw
Quoted 27 lines · Jiri Kosina
Quoted 25 lines · Thomas Weißschuh
Quoted 14 lines
Quoted 5 lines

This driver provides HID fixups for CMedia audio chips.
For now this enables the recognition of the microphone mute button for the HS-100B.

Quoted 8 lines
---
 drivers/hid/Kconfig            |  6 +++
 drivers/hid/Makefile           |  1 +
 drivers/hid/hid-cmedia-fixup.c | 82 ++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h          |  1 +
 drivers/hid/hid-quirks.c       |  3 ++
 5 files changed, 93 insertions(+)
 create mode 100644 drivers/hid/hid-cmedia-fixup.c
Quoted 3 lines

Can you please drop the '-fixup' from the driver name? We have quite a couple of drivers that do report descriptor modifications, but we're not using this '-fixup' naming scheme for them either.

There is already an existing driver "hid-cmedia":
"HID driver for CMedia CM6533 audio jack controls".

This driver works in a completely different way from mine, so I thought to keep them separate. The idea was for the new driver to be a collection of simple, similar report fixups.

Quoted 5 lines
Quoted 1 line

Should they be combined?

If it's the same vendor, then yes. We generally (with exceptions, of course :) ) group the HID drivers by vendor, even if completely different quirks are needed for different devices from the same vendor.

Will do.

Should I merge it into the existing struct hid_driver and do id checks in every member function or declare a dedicated struct hid_driver?

Thanks!

#5 lore raw
Quoted 31 lines · Thomas Weißschuh
Quoted 29 lines · Jiri Kosina
Quoted 26 lines · Thomas Weißschuh
Quoted 14 lines
Quoted 5 lines

This driver provides HID fixups for CMedia audio chips.
For now this enables the recognition of the microphone mute button for the HS-100B.

Quoted 8 lines
---
 drivers/hid/Kconfig            |  6 +++
 drivers/hid/Makefile           |  1 +
 drivers/hid/hid-cmedia-fixup.c | 82 ++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h          |  1 +
 drivers/hid/hid-quirks.c       |  3 ++
 5 files changed, 93 insertions(+)
 create mode 100644 drivers/hid/hid-cmedia-fixup.c
Quoted 3 lines

Can you please drop the '-fixup' from the driver name? We have quite a couple of drivers that do report descriptor modifications, but we're not using this '-fixup' naming scheme for them either.

There is already an existing driver "hid-cmedia":
"HID driver for CMedia CM6533 audio jack controls".

This driver works in a completely different way from mine, so I thought to keep them separate. The idea was for the new driver to be a collection of simple, similar report fixups.

Should they be combined?

Quoted 8 lines
Quoted 3 lines

If it's the same vendor, then yes. We generally (with exceptions, of course :) ) group the HID drivers by vendor, even if completely different quirks are needed for different devices from the same vendor.

Will do.

Should I merge it into the existing struct hid_driver and do id checks in every member function or declare a dedicated struct hid_driver?

Adding checks for every function is less than ideal because that would add useless calls for every raw event.
But adding a new struct hid_driver is tempting given how different the 2 drivers are. However, you would have to write a new module_init/exit for it to register 2 drivers.

Worse case, if you can not create 2 drivers in one module, you could always not set .raw_event in the main struct hid_driver, and assign it in the .probe once you know which device you are facing. In both cases, this is not something we already have in the HID subsystem, but we need a first, right?

I also have a small nitpick on the patch itself, will comment in the original submission email.

Cheers,
Benjamin

Quoted 3 lines

Thanks!

#6 lore raw
In reply to Thomas Weißschuh
Quoted 149 lines · Thomas Weißschuh

This driver provides HID fixups for CMedia audio chips.
For now this enables the recognition of the microphone mute button for the HS-100B.

---
 drivers/hid/Kconfig            |  6 +++
 drivers/hid/Makefile           |  1 +
 drivers/hid/hid-cmedia-fixup.c | 82 ++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h          |  1 +
 drivers/hid/hid-quirks.c       |  3 ++
 5 files changed, 93 insertions(+)
 create mode 100644 drivers/hid/hid-cmedia-fixup.c
drivers/hid/Kconfig +6 -0
index 160554903ef9..5e139c93f75a 100644
@@ -264,6 +264,12 @@ config HID_CMEDIA
        help
        Support for CMedia CM6533 HID audio jack controls.
 
+config HID_CMEDIA_FIXUP
+       tristate "CMedia hid fixup"
+       depends on HID
+       help
+       Fixups for CMedia based audio chips.
+
 config HID_CP2112
        tristate "Silicon Labs CP2112 HID USB-to-SMBus Bridge support"
        depends on USB_HID && HIDRAW && I2C && GPIOLIB
drivers/hid/Makefile +1 -0
index 1ea1a7c0b20f..66d6b06ce4d2 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_HID_BIGBEN_FF)   += hid-bigbenff.o
 obj-$(CONFIG_HID_CHERRY)       += hid-cherry.o
 obj-$(CONFIG_HID_CHICONY)      += hid-chicony.o
 obj-$(CONFIG_HID_CMEDIA)       += hid-cmedia.o
+obj-$(CONFIG_HID_CMEDIA_FIXUP) += hid-cmedia-fixup.o
 obj-$(CONFIG_HID_CORSAIR)      += hid-corsair.o
 obj-$(CONFIG_HID_COUGAR)       += hid-cougar.o
 obj-$(CONFIG_HID_CP2112)       += hid-cp2112.o
drivers/hid/hid-cmedia-fixup.c new file +82 -0
new file mode 100644
index 000000000000..c9a984ea6f0a
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * HID driver containing fixups for CMedia audio chips.
+ *
+ * Copyright (C) 2021 Thomas Weißschuh <[email protected]>
+ */
+
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/module.h>
+#include "hid-ids.h"
+
+#define HS100B_RDESC_ORIG_SIZE 60
+
+/* Fixed report descriptor of HS-100B audio chip
+ * Bit 4 is an abolute Microphone mute usage instead of being unassigned.
+ */
+static __u8 hs100b_rdesc_fixed[] = {
+       0x05, 0x0C,         /*  Usage Page (Consumer),          */
+       0x09, 0x01,         /*  Usage (Consumer Control),       */
+       0xA1, 0x01,         /*  Collection (Application),       */
+       0x15, 0x00,         /*      Logical Minimum (0),        */
+       0x25, 0x01,         /*      Logical Maximum (1),        */
+       0x09, 0xE9,         /*      Usage (Volume Inc),         */
+       0x09, 0xEA,         /*      Usage (Volume Dec),         */
+       0x75, 0x01,         /*      Report Size (1),            */
+       0x95, 0x02,         /*      Report Count (2),           */
+       0x81, 0x02,         /*      Input (Variable),           */
+       0x09, 0xE2,         /*      Usage (Mute),               */
+       0x95, 0x01,         /*      Report Count (1),           */
+       0x81, 0x06,         /*      Input (Variable, Relative), */
+       0x05, 0x0B,         /*      Usage Page (Telephony),     */
+       0x09, 0x2F,         /*      Usage (2Fh),                */
+       0x81, 0x02,         /*      Input (Variable),           */
+       0x09, 0x20,         /*      Usage (20h),                */
+       0x81, 0x06,         /*      Input (Variable, Relative), */
+       0x05, 0x0C,         /*      Usage Page (Consumer),      */
+       0x09, 0x00,         /*      Usage (00h),                */
+       0x95, 0x03,         /*      Report Count (3),           */
+       0x81, 0x02,         /*      Input (Variable),           */
+       0x26, 0xFF, 0x00,   /*      Logical Maximum (255),      */
+       0x09, 0x00,         /*      Usage (00h),                */
+       0x75, 0x08,         /*      Report Size (8),            */
+       0x95, 0x03,         /*      Report Count (3),           */
+       0x81, 0x02,         /*      Input (Variable),           */
+       0x09, 0x00,         /*      Usage (00h),                */
+       0x95, 0x04,         /*      Report Count (4),           */
+       0x91, 0x02,         /*      Output (Variable),          */
+       0xC0                /*  End Collection                  */
+};
+
+static __u8 *cmhid_fixup_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+                                     unsigned int *rsize)
+{
+       switch (hdev->product) {
+       case USB_DEVICE_ID_CMEDIA_HS100B:
+               if (*rsize == HS100B_RDESC_ORIG_SIZE) {
+                       hid_info(hdev, "Fixing CMedia HS-100B report descriptor\n");
+                       rdesc = hs100b_rdesc_fixed;
+                       *rsize = sizeof(hs100b_rdesc_fixed);
+               }
+               break;
+       }
+       return rdesc;
+}
+
+static const struct hid_device_id cmhid_fixup_devices[] = {
+       { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CMEDIA_HS100B) },
+       { }
+};
+
+static struct hid_driver cmhid_fixup_driver = {
+       .name = "cmedia_fixups",
+       .id_table = cmhid_fixup_devices,
+       .report_fixup = cmhid_fixup_report_fixup,
+};
+module_hid_driver(cmhid_fixup_driver);
+
+MODULE_DEVICE_TABLE(hid, cmhid_fixup_devices);
+MODULE_AUTHOR("Thomas Weißschuh <[email protected]>");
+MODULE_DESCRIPTION("CMedia HID fixup");
+MODULE_LICENSE("GPL");
drivers/hid/hid-ids.h +1 -0
index 8f1893e68112..6864e4e6ac8b 100644
@@ -292,6 +292,7 @@
 
 #define USB_VENDOR_ID_CMEDIA           0x0d8c
 #define USB_DEVICE_ID_CM109            0x000e
+#define USB_DEVICE_ID_CMEDIA_HS100B    0x0014
 #define USB_DEVICE_ID_CM6533           0x0022
 
 #define USB_VENDOR_ID_CODEMERCS                0x07c0
drivers/hid/hid-quirks.c +0 -0
index 51b39bda9a9d..7776aa13ee27 100644

drivers/hid/hid-quirks.c static const struct hid_device_id hid_have_special_driver[] = { · line 351

Quoted 6 lines
drivers/hid/hid-quirks.c +3 -0
@@ -346,6 +346,9 @@ static const struct hid_device_id hid_have_special_driver[] = {
 #if IS_ENABLED(CONFIG_HID_CMEDIA)
        { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
 #endif
+#if IS_ENABLED(CONFIG_HID_CMEDIA_FIXUP)
+       { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CMEDIA_HS100B) },
+#endif

FWIW, this hunk should be dropped entirely if the driver works without it.

Cheers,
Benjamin

Quoted 8 lines
drivers/hid/hid-quirks.c +0 -0
 #if IS_ENABLED(CONFIG_HID_CORSAIR)
        { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K90) },
        { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_GLAIVE_RGB) },

base-commit: df04fbe8680bfe07f3d7487eccff9f768bb02533 --
2.32.0