Le Potato - Enable USB OTG for HID (KVM)

Hi,
I am trying to enable USB OTG port for use as a HID device for KVM.

Based on,
https://boot.libre.computer/ci/aml-s905x-cc.dts

usb = “/soc/usb@d0078080”;
dwc2 = “/soc/usb@d0078080/usb@c9100000”;
dwc3 = “/soc/usb@d0078080/usb@c9000000”;

I have added the following overlay for the USB OTG port highlighted above in BOLD.

/dts-v1/;
/plugin/;

/ {
compatible = “libretech,cc”, “amlogic,s905x”, “amlogic,meson-gxl-usb-ctrl”;

    fragment@0 {
            target = <&dwc2>;

            __overlay__ {
                    dr_mode = "otg";
                    status = "okay";
            };
    };

};

The usb-gadget service starts successfully and creates the /dev/hidg0 and /dev/hidg1 devices.

dmesg shows the following log.
[ 2.591463] dwc2 c9100000.usb: supply vusb_d not found, using dummy regulator
[ 2.591672] dwc2 c9100000.usb: supply vusb_a not found, using dummy regulator
[ 2.591906] dwc2 c9100000.usb: Configuration mismatch. dr_mode forced to device
[ 2.591990] dwc2 c9100000.usb: EPs: 7, dedicated fifos, 712 entries in SPRAM
[ 14.898891] dwc2 c9100000.usb: dwc2_hsotg_init_fifo: timeout flushing fifos (GRSTCTL=80000430)
[ 14.910718] dwc2 c9100000.usb: dwc2_core_reset: HANG! Soft Reset timeout GRSTCTL_CSFTRST
[ 14.910909] dwc2 c9100000.usb: bound driver configfs-gadget
[ 14.922404] dwc2 c9100000.usb: dwc2_core_reset: HANG! Soft Reset timeout GRSTCTL_CSFTRST

But unable to write anything to the device. Error is as follows.
echo -ne “\x20\0\xb\0\0\0\0\0” > /dev/hidg0 && echo -ne “\0\0\xc\0\0\0\0\0” > /dev/hidg0 && echo -ne “\0\0\0\0\0\0\0\0” > /dev/hidg0

-bash: echo: write error: Cannot send after transport endpoint shutdown

Can anyone help please?

Don’t have time to play with OTG but here is the driver: dwc2 - drivers/usb/dwc2 - Linux source code (v6.1) - Bootlin

You can check to make sure your DT entries are correct for dr_mode. Also some Googling.

Thanks. I am reading up on this now. Are there 2 separate USB bus/controllers on this board? What i mean is does the OTG port (top left port next to ethernet) on a different bus?

lsusb shows this.
Bus 001 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver

Bus 001 Device 002: ID 05e3:0610 Genesys Logic, Inc. Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

lsusb -t shows this.
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 3: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 3: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 3: Dev 3, If 2, Class=Human Interface Device, Driver=usbhid, 12M

At this link https://wiki.stmicroelectronics.cn/stm32mpu/index.php?title=USB_overview&direction=prev&oldid=77109,
lsusb -t /* lsusb -t shows the USB class, the driver used and the number of ports and speed of each USB devices */
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-platform/2p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc2/1p, 480M

dmesg | grep dwc2 shows the below errors.

[ 88.124011] dwc2 c9100000.usb: dwc2_hsotg_init_fifo: timeout flushing fifos (GRSTCTL=80000430)

[ 88.135725] dwc2 c9100000.usb : dwc2_core_reset: HANG! Soft Reset timeout GRSTCTL_CSFTRST

[ 88.135839] dwc2 c9100000.usb: bound driver g_mass_storage

[ 88.147320] dwc2 c9100000.usb : dwc2_core_reset: HANG! Soft Reset timeout GRSTCTL_CSFTRST

Seems like the dwc2 driver needs a patch.

https://community.st.com/s/question/0D53W00000UA60XSAT/mainline-linux-fails-to-set-up-fs-otg

We enabled UDC in our kernels but are experiencing some issues. We are still researching this at the moment.

dwc2 c9100000.usb: dwc2_hsotg_init_fifo: timeout flushing fifos (GRSTCTL=80000430)
dwc2 c9100000.usb: dwc2_core_reset: HANG! Soft Reset timeout GRSTCTL_CSFTRST
dwc2 c9100000.usb: bound driver g_mass_storage
dwc2 c9100000.usb: dwc2_core_reset: HANG! Soft Reset timeout GRSTCTL_CSFTRST

Please see How to enter Device Mode for USB OTG on USB Type A Port on AML-S905X-CC Le Potato