Skip to contentSkip to conversation

HID: santroller: add driver for Santroller controllers

PATCH Superseded Sanjay Govind 2 participants 2 messages Nov 7 – Nov 8 HID

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 HID: santroller: add driver for Santroller controllers

Santroller is an open source firmware for DIY and modded game controllers and instruments: https://github.com/Santroller/Santroller

Santroller devices work like hubs: a user can connect several instruments and controllers to one device, and on USB each active profile appears as its own HID gamepad interface. On current firmware, each of these interfaces answers a vendor features report (usage 0xff00:0x2882) with the emulated controller type and a set of capability bits.

Santroller uses the pid.codes vendor ID 0x1209 and product IDs 0x2882 and 0x2883 for its v1 and v2 devices, respectively, over USB and Bluetooth.

Inputs are left to the generic HID input layer, as the report descriptor already describes the buttons, axes and d-pad. Since users name each profile, and on USB the firmware puts that name in the interface string, the driver uses it to name the input device, so each connected instrument or controller can be told apart.

The driver also handles the outputs the device reports supporting:
rumble, player LEDs, an RGB indicator LED and the euphoria LED of DJ Hero turntables.

The configuration interface and devices whose report descriptor lacks a matching input/output features report pair use default HID handling within this driver, without Santroller-specific setup. Devices that advertise the pair but fail to answer are still connected as plain gamepads.

---
Changes since v2:
- Track feature-report responses under the driver lock, accept only the first reply while discovery is pending, and ignore late replies once discovery has finished.
- Require matching input and output features reports; validate the input report ID/type before accepting capabilities.
- Serialize RGB component calculation and state copying. Initialize the RGB LED at brightness zero, matching its zero-valued color components.
- Preserve pending rumble work across resume and skip LED restoration if no registered input device exists. Validate the saved input against the registered hid-input list after hid_connect() before using it.
- Initialize player LED state before registering LEDs so an early userspace update is not overwritten.
- Do not expose force feedback when the euphoria LED capability is present, because turntables use the rumble command for that LED.
- Guard USB profile naming with IS_REACHABLE(CONFIG_USB_HID), keeping Bluetooth-only builds free of an unresolved USB HID reference.
- Retry failed output sends up to three total attempts, with a 20 ms delay between attempts. Refresh retries from current state under the lock and stop on disconnect or disabled output. Persistent failures are still logged and abandoned after the bounded attempt limit.
- Correct the fallback description: interfaces without the features report pair use default HID handling within Santroller, rather than binding to hid-generic.
- Use heap-backed storage for the feature query because USB transports may DMA the buffer. Distinguish local allocation failure from transport errors, stop retrying when the device is gone, and return zero on a successful query. Add a short wait after transient send errors to avoid exhausting retries immediately.

Testing:
- x86-64 GCC 16.2.1, W=1: vmlinux and modules linked with Santroller modular/USB disabled, modular/USB HID built in, both modular, Santroller built in/USB HID modular, and built in/USB disabled. Verified hid_is_usb symbol reachability. No driver warnings or link errors; one unrelated proc_sysctl.c unused-variable warning.
- On 7.2.11-arch1-1, tested the final rebuilt module: USB and Bluetooth inputs, rumble, player LEDs, RGB and suspend/resume; USB unplug/replug; euphoria LED.
- A v1 USB device lacking the features-report pair bound with default HID handling; buttons and axes worked, without force feedback or LEDs.
- With firmware modified to suppress the features reply while retaining the report pair, verified -ETIMEDOUT and plain-gamepad registration without force feedback; the submitter confirmed inputs still worked.
- Ten ASan/UBSan fault-injection scenarios passed using the actual output worker functions, covering retries, exhaustion, disconnect, updated state and shutdown. The serial harness does not test kernel locking or real transports.
- Checkpatch: no errors, one existing -ENOSYS warning.
- Not tested: the exact Xtensa/SPARC64 robot configs.

AI assistance:
- Copilot assisted with revision preparation, build validation and this testing summary. The existing revision changelog describes changes prepared with AI assistance; the submitter remains responsible for reviewing and understanding the code before submission.
- Sashiko using Claude Code reviewed the driver. Copilot checked its output-loss finding with fault injection and implemented bounded retries, and corrected the fallback description.

---
 MAINTAINERS                  |   6 +
 drivers/hid/Kconfig          |  12 +
 drivers/hid/Makefile         |   1 +
 drivers/hid/hid-ids.h        |   4 +
 drivers/hid/hid-santroller.c | 709 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 732 insertions(+)
MAINTAINERS +6 -0
index 4a69da715c58..028c8f7f40fa 100644
@@ -11703,6 +11703,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/hid/hid-pulsar.c
 
+HID SANTROLLER DRIVER
+M:	Sanjay Govind <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/hid/hid-santroller.c
+
 HID SENSOR HUB DRIVERS
 M:	Jiri Kosina <[email protected]>
 M:	Jonathan Cameron <[email protected]>
drivers/hid/Kconfig +12 -0
index 2481bc01c435..2fab7003ce18 100644
@@ -1138,6 +1138,18 @@ config HID_SAMSUNG
 	help
 	Support for Samsung InfraRed remote control or keyboards.
 
+config HID_SANTROLLER
+	tristate "Santroller game controller support"
+	depends on LEDS_CLASS_MULTICOLOR
+	select INPUT_FF_MEMLESS
+	help
+	  Support for game controllers and instruments running the Santroller
+	  firmware, including rumble, player LEDs, the RGB indicator LED and
+	  the DJ Hero turntable euphoria LED.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called hid-santroller.
+
 config HID_SEMITEK
 	tristate "Semitek USB keyboards"
 	help
drivers/hid/Makefile +1 -0
index 43a8eb0f389b..afe88185289b 100644
@@ -131,6 +131,7 @@ obj-$(CONFIG_HID_ROCCAT)	+= hid-roccat.o hid-roccat-common.o \
 obj-$(CONFIG_HID_RMI)		+= hid-rmi.o
 obj-$(CONFIG_HID_SAITEK)	+= hid-saitek.o
 obj-$(CONFIG_HID_SAMSUNG)	+= hid-samsung.o
+obj-$(CONFIG_HID_SANTROLLER)	+= hid-santroller.o
 obj-$(CONFIG_HID_SEMITEK)	+= hid-semitek.o
 obj-$(CONFIG_HID_SIGMAMICRO)	+= hid-sigmamicro.o
 obj-$(CONFIG_HID_SMARTJOYPLUS)	+= hid-sjoy.o
drivers/hid/hid-ids.h +4 -0
index 91319aa6516d..ed3940cd36cd 100644
@@ -1216,6 +1216,10 @@
 #define USB_VENDOR_ID_PHILIPS		0x0471
 #define USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE 0x0617
 
+#define USB_VENDOR_ID_PID_CODES		0x1209
+#define USB_DEVICE_ID_SANTROLLER	0x2882
+#define USB_DEVICE_ID_SANTROLLER_V2	0x2883
+
 #define USB_VENDOR_ID_PI_ENGINEERING	0x05f3
 #define USB_DEVICE_ID_PI_ENGINEERING_VEC_USB_FOOTPEDAL	0xff
 
drivers/hid/hid-santroller.c new file +709 -0

709 lines not on this page · raw message

base-commit: 720806515cb6921ab05caaa6f470f7054b56385e

#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] HID: santroller: stale brightness read in santroller_player_led_set() - [Low] HID: santroller: USB…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] HID: santroller: stale brightness read in santroller_player_led_set()
- [Low] HID: santroller: USB profile naming compiled out when USB_HID=m and HID_SANTROLLER=y
--

commit 28369893e9b4de37e159a34ce2a7a1ca4302cd7d
Author: Sanjay Govind <[email protected]>

HID: santroller: add driver for Santroller controllers

This commit adds a HID driver for Santroller USB and Bluetooth game controllers and instruments, supporting profile naming, rumble, player LEDs, RGB indicator LEDs, and turntable euphoria LEDs.

drivers/hid/Kconfig config HID_SAMSUNG · line 1144

Quoted 12 lines
drivers/hid/Kconfig +4 -0
index 2481bc01c435b..2fab7003ce18f 100644
@@ -1138,6 +1138,18 @@ config HID_SAMSUNG
 	help
 	Support for Samsung InfraRed remote control or keyboards.
 
+config HID_SANTROLLER
+	tristate "Santroller game controller support"
+	depends on LEDS_CLASS_MULTICOLOR
+	select INPUT_FF_MEMLESS

[Severity: Low]
Should this also depend on USB_HID || !USB_HID? When CONFIG_HID_SANTROLLER=y and CONFIG_USB_HID=m, IS_REACHABLE(CONFIG_USB_HID) in santroller_profile_name() evaluates to false and silently compiles out USB profile naming even though USB HID support is enabled.

Quoted 5 lines
drivers/hid/hid-santroller.c new file +0 -0
new file mode 100644
index 0000000000000..7dcc5d7eae604

[ ... ]

Quoted 9 lines
drivers/hid/hid-santroller.c new file +9 -0
+static void santroller_player_led_set(struct led_classdev *led,
+				      enum led_brightness value)
+{
+	struct hid_device *hdev = to_hid_device(led->dev->parent);
+	struct santroller *sc = hid_get_drvdata(hdev);
+	int i;
+
+	guard(spinlock_irqsave)(&sc->lock);
+

drivers/hid/hid-santroller.c line 224

Quoted 10 lines
drivers/hid/hid-santroller.c new file +10 -0
+	sc->player = SANTROLLER_PLAYER_LED_OFF;
+	for (i = 0; i < SANTROLLER_NUM_PLAYER_LEDS; i++) {
+		if (sc->player_leds[i].brightness) {
+			sc->player = i;
+			break;
+		}
+	}
+	sc->player_dirty = true;
+	santroller_schedule_output(sc);
+}

[Severity: Medium]
Can santroller_player_led_set() send a stale player LED state by ignoring value and reading sc->player_leds[i].brightness?

When software blinking (such as the timer trigger) is stopped while the LED is in its ON phase, led_set_brightness(led_cdev, LED_OFF) defers the update to set_brightness_delayed() without clearing led_cdev->brightness:

drivers/leds/led-core.c:set_brightness_delayed() {
    ...
	if (test_and_clear_bit(LED_SET_BRIGHTNESS_OFF, &led_cdev->work_flags)) {
		set_brightness_delayed_set_brightness(led_cdev, LED_OFF);
    ...
}

set_brightness_delayed_set_brightness() calls __led_set_brightness(led_cdev, LED_OFF) -> santroller_player_led_set(led_cdev, LED_OFF) while led->brightness is still 1, leaving the hardware player LED lit. Using value for the entry matching led (or updating led->brightness = value under sc->lock before the loop) would keep the state in sync.

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