Skip to contentSkip to conversation

HID: add driver for EWEADN G5 mice

PATCH Superseded Liang Haowen 2 participants 2 messages Nov 1 HID

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 HID: add driver for EWEADN G5 mice

EWEADN G5 mice (YJX-CHIP receivers 0xa8a5:2255, replacement units and the wired mouse 0xa8a4:2255) send motion and buttons in a 9-byte vendor report on interface 0. The report descriptor the firmware ships does not describe that data: the 0xa8a5 receivers declare vendor usages with no mouse mapping, and the 0xa8a4 units declare a standard mouse report the firmware then does not send. Either way the stock input path produces no pointer events, and there is no Linux driver from the vendor.

The report itself is a plain mouse report: buttons, int16 dx and dy, an int8 wheel. Replace the descriptor at parse time with one that describes exactly that report, so hid-core can parse the frames with no custom event handling. The keyboard and vendor-configuration interfaces bind to this driver too and keep their own descriptors untouched.

Both device IDs bind with the fixed-up descriptor, and motion events flow through the stock input path. This also makes the userspace relay used until now (github.com/NB-Group/g5moused) unnecessary.

---
Changes in v2, from the review of v1:

- Bind all interfaces of the composite device instead of returning -ENODEV for the non-mouse ones: hid-generic steps aside for any registered driver whose id_table matches, so rejecting them left the keyboard and vendor-configuration interfaces with no driver at all. Only the mouse interface gets the fixed-up descriptor now; the others keep their own.

- Guard the USB interface lookup with hid_is_usb(): a virtual HID device created through /dev/uhid can claim BUS_USB with matching vendor and product IDs, and casting its parent would dereference memory that is not a usb_interface.

- Use the USB_VENDOR_ID_YJXCHIP macro for the original receiver.

---
 drivers/hid/Kconfig      |   9 +++
 drivers/hid/Makefile     |   1 +
 drivers/hid/hid-eweadn.c | 129 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 drivers/hid/hid-eweadn.c
drivers/hid/Kconfig +9 -0
index 2481bc0..3946f75 100644
@@ -380,6 +380,15 @@ config HID_EVISION
 	applying customization using userspace programs.
 	Support for some EVision devices requiring report descriptor fixups.
 
+config HID_EWEADN
+	tristate "EWEADN G5 mice support"
+	depends on USB_HID
+	help
+	Support for EWEADN G5 wireless mice (YJX-CHIP 0xa8a5:2255 receivers,
+	0xa8a4 replacement units and the wired mouse). The stock report
+	descriptor does not describe the reports the firmware sends, so
+	the pointer is dead without this fixup.
+
 config HID_EZKEY
 	tristate "Ezkey BTC 8193 keyboard"
 	help
drivers/hid/Makefile +1 -0
index 43a8eb0..2db5b5d 100644
@@ -51,6 +51,7 @@ obj-$(CONFIG_HID_ELAN)		+= hid-elan.o
 obj-$(CONFIG_HID_ELECOM)	+= hid-elecom.o
 obj-$(CONFIG_HID_ELO)		+= hid-elo.o
 obj-$(CONFIG_HID_EVISION)	+= hid-evision.o
+obj-$(CONFIG_HID_EWEADN)	+= hid-eweadn.o
 obj-$(CONFIG_HID_EZKEY)		+= hid-ezkey.o
 obj-$(CONFIG_HID_FT260)		+= hid-ft260.o
 obj-$(CONFIG_HID_GEMBIRD)	+= hid-gembird.o
drivers/hid/hid-eweadn.c new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] HID: hid-eweadn: missing hid-ids.h include breaks build - [Low] HID: hid-eweadn: redundant…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] HID: hid-eweadn: missing hid-ids.h include breaks build
- [Low] HID: hid-eweadn: redundant eweadn_probe() duplicates default probe --

commit 4edaba02eb50bfbcf89b68ad006b2e16efd6acc9
Author: Liang Haowen <[email protected]>

HID: add driver for EWEADN G5 mice

This commit adds a HID driver for EWEADN G5 wireless and wired mice that replaces the broken firmware report descriptor on USB interface 0 with a standard mouse report descriptor.

Quoted 6 lines
drivers/hid/hid-eweadn.c new file +0 -0
new file mode 100644
index 0000000000000..79a9a1545b395
@@ -0,0 +1,129 @@

[ ... ]

Quoted 5 lines
drivers/hid/hid-eweadn.c new file +5 -0
+#include <linux/hid.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+
+static __u8 eweadn_rdesc[] = {

[ ... ]

Quoted 9 lines
drivers/hid/hid-eweadn.c new file +9 -0
+static int eweadn_probe(struct hid_device *hdev,
+			const struct hid_device_id *id)
+{
+	int ret;
+
+	ret = hid_parse(hdev);
+	if (ret) {
+		hid_err(hdev, "parse failed: %d\n", ret);
+		return ret;

drivers/hid/hid-eweadn.c line 110

Quoted 10 lines
drivers/hid/hid-eweadn.c new file +10 -0
+	}
+
+	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+	if (ret) {
+		hid_err(hdev, "hw start failed: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}

[Severity: Low]
This isn't a bug, but is eweadn_probe() needed here?

In drivers/hid/hid-core.c, __hid_device_probe() already runs the default probe sequence when hdrv->probe is not set:

drivers/hid/hid-core.c:__hid_device_probe() {
	if (hdrv->probe) {
		ret = hdrv->probe(hdev, id);
	} else { /* default probe */
		ret = hid_open_report(hdev);
		if (!ret)
			ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
	}
}

Since hid_parse() is just a wrapper around hid_open_report(), could eweadn_probe() and the .probe assignment in eweadn_driver be dropped to rely on the default HID core probe like other report-fixup-only drivers?

Quoted 4 lines
drivers/hid/hid-eweadn.c new file +4 -0
+
+static const struct hid_device_id eweadn_devices[] = {
+	{ HID_USB_DEVICE(USB_VENDOR_ID_YJXCHIP, USB_DEVICE_ID_YJXCHIP_MOUSE) },
+	{ HID_USB_DEVICE(0xa8a4, 0x2255) },	/* replacement unit, wired mouse */

drivers/hid/hid-eweadn.c line 124

Quoted 10 lines
drivers/hid/hid-eweadn.c new file +10 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(hid, eweadn_devices);
+
+static struct hid_driver eweadn_driver = {
+	.name = "eweadn",
+	.id_table = eweadn_devices,
+	.report_fixup = eweadn_report_fixup,
+	.probe = eweadn_probe,
+};

[Severity: Low]
As reported by Sashiko on v1 [1], does this fail to build when CONFIG_HID_EWEADN is enabled because drivers/hid/hid-eweadn.c uses USB_VENDOR_ID_YJXCHIP and USB_DEVICE_ID_YJXCHIP_MOUSE in eweadn_devices[] without including "hid-ids.h"?

Those macros are defined in drivers/hid/hid-ids.h:

#define USB_VENDOR_ID_YJXCHIP 0xa8a5
#define USB_DEVICE_ID_YJXCHIP_MOUSE 0x2255

Should drivers/hid/hid-eweadn.c include "hid-ids.h", define symbolic constants in drivers/hid/hid-ids.h for the 0xa8a4:0x2255 device ID entry in eweadn_devices[] as well, and mark eweadn_rdesc[] as const?

[1] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1