HID: ayaneo: Add AYANEO 3 detachable controller driver
PATCH v6 1/1 HID: ayaneo: Add AYANEO 3 detachable controller driver
The AYANEO 3 handheld has a detachable controller with swappable modules ("Magic Modules"). The controller exposes three USB HID interfaces behind 1c4f:0002 (a generic SigmaMicro VID/PID): a gamepad, a keyboard for the extra buttons, and a vendor interface accepting 65-byte commands.
Add a driver claiming every interface of the shared ID. Interfaces other than the AYANEO 3 vendor interface are started as transparent generic devices, with reset_resume mirrored from hid-generic:
hid-generic yields any device that another driver's id table matches, so refusing those probes would leave the input interfaces driverless when the driver is present at boot.
On the vendor interface the driver provides module identification (module_left/module_right sysfs attributes), software eject of the modules (eject sysfs attribute, blocking until the firmware confirms the release handshake and a minimum settle time has passed), a configuration reset (reset), rumble strength selection (rumble_intensity), and RGB control of the joystick rings as a multicolor LED class device ("<device name>:rgb:joystick_rings"; userspace such as InputPlumber matches the function suffix). The firmware's fixed-tempo effects are exposed through the LED effect attribute (monocolor, breathe, rainbow), matching the attribute names established by hid-lenovo-go.
This complements the ayaneo-ec platform driver, which exposes module attach state and controller power. A full physical eject is performed by writing to eject and then cutting power through ayaneo-ec's controller_power attribute; that orchestration is deliberately left to userspace.
The protocol was reverse engineered in the Handheld Daemon project by Antheas Kapenekakis. Tested on an AYANEO 3: module identification, RGB solid, breathing and rainbow at several brightness levels, rumble level selection, gamepad and keyboard input through the transparent interfaces, a full eject/reinsert/repower cycle with the re-enumerated interfaces binding cleanly, and repeated driver unbinds under a concurrent brightness-write load.
---
Changes in v6 (from Ilpo Järvinen's review unless noted):
- Migrate the mutex_intr acquisitions from scoped_cond_guard() to the ACQUIRE()/ACQUIRE_ERR() cleanup macros.
- Pack the vibration field with FIELD_PREP() and a named mask, name the checksum start offset, and return the sum from ayaneo_checksum().
- Use ARRAY_SIZE() and U8_MAX for the literal counts and 255s, and min() for the open-coded clamps.
- Add explicit includes for array_size.h, bitfield.h, container_of.h and minmax.h.
- Reverse-xmas-tree the eject_store declarations, rename the effect_store locals, and reflow two wrapped lines.
- Fix a jiffies underflow in eject_store: the minimum-settle wait read jiffies twice, so a tick crossing the deadline between the reads could wrap the subtraction into a multi-year sleep. Read it once. [sashiko-bot]
No functional change beyond the jiffies fix. Rebuilt and smoke-tested on an AYANEO 3 (7.3.3 kernel): load, module identification, rumble and effect writes, LED. Thanks to Ilpo for the review.
Notes
-----
eject scope: a write-only eject attribute that drives a firmware release handshake follows existing practice. greybus exposes the same on its detachable modules (drivers/greybus/module.c, DEVICE_ATTR_WO), and ACPI uses an eject attribute for ejectable hardware (drivers/acpi/device_sysfs.c). This driver only performs the firmware handshake and leaves the power cut to userspace through ayaneo-ec. If the HID maintainers would prefer eject left entirely to userspace, the module-identification and LED parts stand on their own.
effect/effect_index are documented in this driver's own ABI file, as sysfs-driver-hid-lenovo-go and -go-s already document the same per-device LED attributes. A follow-up could consolidate the three into one shared description, but it crosses into the hid-lenovo-go maintainers' files.
The id_table matches the generic SigmaMicro 1c4f:0002 (shared with unrelated keyboards, see hid-quirks.c) because the AYANEO 3 controller presents under that ID; the non-vendor interfaces are started transparently so they are not stranded.
On a surprise disconnect the final LED-off write during unregister can log a benign -ENODEV; setting LED_HW_PLUGGABLE would silence it, left as a follow-up.
checkpatch flags the -ENOSYS check in ayaneo_send() as a misuse; it is the standard hid_hw_output_report() fallback.
v3: https://lore.kernel.org/linux-input/[email protected]/
v4: https://lore.kernel.org/linux-input/[email protected]/
v5: https://lore.kernel.org/linux-input/[email protected]/
.../ABI/testing/sysfs-driver-hid-ayaneo | 75 ++ MAINTAINERS | 7 + drivers/hid/Kconfig | 17 + drivers/hid/Makefile | 1 + drivers/hid/hid-ayaneo.c | 881 ++++++++++++++++++ 5 files changed, 981 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-ayaneo create mode 100644 drivers/hid/hid-ayaneo.c
Documentation/ABI/testing/sysfs-driver-hid-ayaneo new file +75 -0
@@ -0,0 +1,75 @@ +What: /sys/bus/hid/drivers/hid-ayaneo/<dev>/module_left +What: /sys/bus/hid/drivers/hid-ayaneo/<dev>/module_right +Date: September 2026 +KernelVersion: 7.4 +Contact: Matías Martínez <[email protected]> +Description: + Reports the type of the module currently inserted in the + left/right slot of the AYANEO 3 detachable controller, as + the raw identifier reported by the controller firmware in + hexadecimal (e.g. "0x04"). Bits 0-5 encode the module + type, bit 6 indicates the module is inserted rotated. + + Reading these attributes queries the controller and can + take up to a second. + +What: /sys/bus/hid/drivers/hid-ayaneo/<dev>/eject +Date: September 2026 +KernelVersion: 7.4 +Contact: Matías Martínez <[email protected]> +Description: + Write-only. Writing "left", "right" or "both" asks the + controller firmware to release the corresponding + module(s). The write blocks until the firmware confirms + the release handshake (typically a few seconds). The + module is physically released once controller power is + subsequently cut through the ayaneo-ec platform driver's + controller_power attribute. That final step is left to + userspace. + +What: /sys/bus/hid/drivers/hid-ayaneo/<dev>/reset +Date: September 2026 +KernelVersion: 7.4 +Contact: Matías Martínez <[email protected]> +Description: + Write-only. Writing "1" asks the controller firmware to + perform a quick reset of the controller configuration. + +What: /sys/bus/hid/drivers/hid-ayaneo/<dev>/rumble_intensity +Date: September 2026 +KernelVersion: 7.4 +Contact: Matías Martínez <[email protected]> +Description: + Controls the vibration strength of the AYANEO 3 controller + rumble motors. Reading returns the selected level. Supported + writes are the values listed by rumble_intensity_index. + Defaults to "medium", matching the firmware default. + +What: /sys/bus/hid/drivers/hid-ayaneo/<dev>/rumble_intensity_index +Date: September 2026 +KernelVersion: 7.4 +Contact: Matías Martínez <[email protected]> +Description: + Read-only. Space-separated list of the supported + rumble_intensity values: "off low medium high". + +What: /sys/class/leds/<dev>:rgb:joystick_rings/effect +Date: September 2026 +KernelVersion: 7.4 +Contact: Matías Martínez <[email protected]> +Description: + Controls the firmware LED effect of the joystick rings. + + Values are "monocolor", "breathe" or "rainbow", as listed + by the effect_index attribute. "rainbow" is a + firmware-timed colour cycle whose hue and tempo are fixed + by the firmware: brightness scales its amplitude and the + multi_intensity values are ignored while it is selected. + +What: /sys/class/leds/<dev>:rgb:joystick_rings/effect_index +Date: September 2026 +KernelVersion: 7.4 +Contact: Matías Martínez <[email protected]> +Description: + Read-only. Space-separated list of the supported effect + values: "monocolor breathe rainbow".
MAINTAINERS +7 -0
@@ -4535,6 +4535,13 @@ F: Documentation/devicetree/bindings/spi/axiado,ax3000-spi.yaml F: drivers/spi/spi-axiado.c F: drivers/spi/spi-axiado.h +AYANEO 3 CONTROLLER HID DRIVER +M: Matías Martínez <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-driver-hid-ayaneo +F: drivers/hid/hid-ayaneo.c + AYANEO PLATFORM EC DRIVER M: Antheas Kapenekakis <[email protected]> L: [email protected]
drivers/hid/Kconfig +17 -0
@@ -205,6 +205,23 @@ config HID_AUREAL help Support for Aureal Cy se W-01RN Remote Controller and other Aureal derived remotes. +config HID_AYANEO + tristate "AYANEO 3 detachable controller support" + depends on USB_HID + depends on DMI + depends on LEDS_CLASS_MULTICOLOR + help + Provides support for the detachable controller ("Magic Modules") + of the AYANEO 3 handheld: module identification, software eject + and RGB control of the joystick rings. Complements the ayaneo-ec + platform driver, which handles module attach state and controller + power. + + Say Y or M here if you have an AYANEO 3. + + To compile this driver as a module, choose M here: the + module will be called hid-ayaneo. + config HID_BELKIN tristate "Belkin Flip KVM and Wireless keyboard" help
drivers/hid/Makefile +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_HID_APPLETB_KBD) += hid-appletb-kbd.o obj-$(CONFIG_HID_CREATIVE_SB0540) += hid-creative-sb0540.o obj-$(CONFIG_HID_ASUS) += hid-asus.o obj-$(CONFIG_HID_AUREAL) += hid-aureal.o +obj-$(CONFIG_HID_AYANEO) += hid-ayaneo.o obj-$(CONFIG_HID_BELKIN) += hid-belkin.o obj-$(CONFIG_HID_BETOP_FF) += hid-betopff.o obj-$(CONFIG_HID_BIGBEN_FF) += hid-bigbenff.o
drivers/hid/hid-ayaneo.c new file +881 -0
881 lines not on this page · raw message
base-commit: 720806515cb6921ab05caaa6f470f7054b56385e
Signature · 1 line
2.54.0 (Apple Git-157)
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] HID: ayaneo: spurious -ENODEV errors and traffic on LED unregister --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] HID: ayaneo: spurious -ENODEV errors and traffic on LED unregister
--
commit 503e8577930caa05e37b8ae2f759096d42ca369b
Author: Matías Martínez <[email protected]>
HID: ayaneo: Add AYANEO 3 detachable controller driver
This commit adds a HID driver for the AYANEO 3 detachable controller, supporting module identification, software eject, rumble intensity, configuration reset, and multicolor LED control on its vendor interface.
Quoted 5 lines
drivers/hid/hid-ayaneo.c new file +0
-0
[ ... ]
Quoted 21 lines
drivers/hid/hid-ayaneo.c new file +21
-0+static int ayaneo_led_set (struct led_classdev *cdev,enum led_brightness value) +{ +struct led_classdev_mc *mc =lcdev_to_mccdev (cdev); + struct ayaneo *aya = container_of(mc, struct ayaneo, mcled); +int ret, i; + +ACQUIRE (mutex_intr, lock)(&aya->lock); + ret =ACQUIRE_ERR (mutex_intr, &lock); +if (ret) +return ret; + +led_mc_calc_color_components (mc, value); + aya->brightness =min (value,U8_MAX ); +for (i =0 ; i <ARRAY_SIZE (aya->subleds); i++) + aya->rgb[i] =min (aya->subleds[i].brightness,U8_MAX ); + + ret =ayaneo_send_config (aya,0 ); +if (ret) +hid_err (aya->hdev,"failed to update RGB config: %d\n" , ret); +return ret; +}
[ ... ]
Quoted 4 lines
drivers/hid/hid-ayaneo.c new file +4
-0+static int ayaneo_register_led (struct ayaneo *aya) +{ +struct led_classdev *cdev = &aya->mcled.led_cdev; +int ret, i;
[ ... ]
drivers/hid/hid-ayaneo.c line 705
Quoted 4 lines
drivers/hid/hid-ayaneo.c new file +4
-0+ cdev->color =LED_COLOR_ID_RGB ; + cdev->brightness =0 ; + cdev->max_brightness =U8_MAX ; + cdev->brightness_set_blocking = ayaneo_led_set;
[Severity: Low]
Does unregistering the LED on controller power-off or unbind log spurious -ENODEV errors and send unwanted config traffic?
When the controller is powered off (including after an eject handshake) or disconnected, usb_disconnect() marks the device detached before ayaneo_remove() runs. led_classdev_multicolor_unregister() then issues an LED_OFF write via set_brightness_work, which fails with -ENODEV in ayaneo_send(). Because cdev->flags does not set LED_HW_PLUGGABLE and ayaneo_led_set() logs all errors unconditionally, both ayaneo_led_set() and the LED core log -ENODEV errors on every disconnect.
In addition, when the driver is unbound while aya->configured is false, that same LED_OFF write during unregister still sends a 65-byte config report to the device, even though the driver otherwise avoids sending traffic unless userspace has configured it.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1