Skip to content

rg35xx-sp: no charging while Knulli is running (usbc0 stuck in usb_host, VBUS never detected); charger plug-in always boots the device #112

Open

Description

@frostyfightclub

Knulli build version

scarab 2026/05/11 00:09

Your architecture

Anbernic RG35XX SP (handheld), board rg35xx-sp, H700 + AXP2202 PMIC, kernel 4.9.170

Issue description

The RG35XX SP never charges while Knulli is running — awake or suspended — with any charger. It only charges while fully off, but connecting a charger to a powered-off device always boots it (bootreason=charger), and once Linux is up charging stops. Net result: the device can't be charged with the Knulli card inserted. Stock Anbernic firmware charges normally (including while powered on) with the same chargers and cables.

Detailed reproduction steps

  1. Power the device off completely.
  2. Connect a charger (tested: Nintendo Switch USB-C PD charger, and two plain 5V USB-A bricks with an A-to-C cable).
  3. Orange charge LED lights for ~5 s, then the green power LED comes on and Knulli boots by itself (also with the lid closed).
  4. While booted: no charge LED, battery keeps discharging (37% -> 29% -> 16% -> 14% over an evening while plugged in).
  5. Shut down from the menu with the charger still connected: the device boots again immediately.
  6. Close the lid to suspend while plugged in: still no charging; the device wakes every ~20 s (see logs).

Check: /sys/class/power_supply/axp2202-usb/online and present stay 0, voltage_now stays 0, and /proc/interrupts shows vbus_insert = 0 the whole time the charger is connected.

Details of any attempts to fix this yourself

  • Tried three chargers / two cables: same result. All charge fine while the device is off, and on stock firmware.
  • Found usbc0 is in host role while booted: /sys/devices/platform/soc/usbc0/otg_role = usb_host. Writing "usb_device" to otg_role blocked in the kernel and the role did not change. (Note: on this kernel, merely reading usbc0/usb_host or usb_device appears to trigger a role switch.)
  • system.usbmode=off, so S28usbmode does nothing; no USB devices are attached.
  • /usr/bin/charger (run from rcS) reads axp2202-battery/status, which already says "Discharging", so it logs "Starting without power connected - going straight to boot" and the charging screen is skipped.
  • knulli-suspend arms no RTC alarm with batterysaver modes = suspend, yet the device wakes every ~20 s while suspended on the charger.

Workaround that works: power off, remove the TF1 (Knulli) card, connect the charger, then re-insert the card. With nothing to boot at the moment power arrives, it stays off and charges; it keeps charging with the card back in until powered on manually.

Details of any modifications you have made to Knulli.

None to the system image, kernel, power, or USB configuration. Additions, all in /userdata:

  • An extra SSH login (key-only) used for diagnostics, recreated at boot by /userdata/system/custom.sh.
  • A Ports app (Python + mpv media player) in /userdata/system and /userdata/roms/ports; it creates a /var/run/battery-saver/*.pause file only while it is running.
    None of these touch power, charging or USB settings. The issue reproduces from a cold boot with the app not running.

Logs and data

Booted, charger connected:
/sys/class/power_supply/axp2202-usb:     online=0 present=0 voltage_now=0 input_current_limit=2500
/sys/class/power_supply/axp2202-battery: status=Discharging constant_charge_current=230 otg_id=1 boot_mode=1
/sys/devices/platform/soc/usbc0/otg_role: usb_host
/sys/class/udc/5100000.udc-controller/state: not attached
/proc/cmdline: androidboot.mode=charger bootreason=charger

/proc/interrupts after ~18 min with charger connected:
  axp2202_irq_chip  7 Edge  vbus_insert   0
  axp2202_irq_chip  8 Edge  vbus_remove   1

dmesg:
  axp2202_usb_power: axp2202-acin device is not configed, not use vbus-det
  axp2202_usb_power: current limit not set: usb adapter type

Suspended on charger (lid closed), wakes every ~20 s:
  969.09 suspend entry -> 989.25 exit
  991.20 entry -> 1011.28 exit
  1013.21 entry -> 1033.29 exit
  1035.22 entry -> 1055.32 exit
(/sys/power/pm_wakeup_irq not available on this kernel)

Possibly related (old repo): knulli-cfw/distribution#287 (rg35xx-sp boots when charger is unplugged), knulli-cfw/distribution#479 (RG35XX Pro / H700: no power/LED with Knulli SD, stock SD works), knulli-cfw/distribution#140 (RG34XXSP mixed state after charging).

Activity

  1. frostyfightclub commented on Oct 5, 2026

    @frostyfightclub
    Author

    Root cause found, plus a working workaround

    Follow-up on the RG35XX SP not charging while Knulli is running. I compared my SP against an RG35XX Pro on the same release (Knulli scarab 2026/05/11, kernel 4.9.170) that charges fine. Both use the same AXP2202 PMIC and have identical usb_power_supply and usbc0 device-tree properties, so I could diff them live.

    What's happening

    1. On the SP, the USB ID detect pin PI4 (allen_usb_id_det, gpio-260) reads high. On the Pro it reads low.
    2. Because of that, the sunxi OTG manager puts usbc0 into host mode on the SP: otg_role=usb_host, and dmesg shows insmod_host_driver about 3.7 s into boot. The Pro stays usb_device.
    3. In host mode the OTG manager drives PI16 (usb_drv_vbus_gpio, gpio-272) high. That switches VBUS to output power and disconnects the charger from the PMIC.
    4. Result: the AXP2202 never sees the charger.
    SP (broken) Pro (works)
    PI4 usb_id_det in, hi in, lo
    PI16 usb_drv_vbus out, hi out, lo
    otg_role usb_host usb_device
    AXP2202 REG00 (bit 5 = VBUS good) 0x18 0x38
    axp2202-usb present / online 0 / 0 1 / 1

    This also explains the workaround from the original report. With the card pulled, Linux never runs, PI16 is never driven high, and the device charges normally.

    Confirmation

    With the charger connected and the SP in host mode, I cleared PI16 by writing the PIO bank I data register (0x0300b130, bit 16) through /dev/mem. Nothing else was changed.

    • REG00 changed 0x18 → 0x39 (VBUS good).
    • vbus_insert fired.
    • axp2202-usb went to present=1 online=1.
    • The battery went Discharging → Charging, and the charge LED came on.

    It survives reboots when the workaround below is started from custom.sh. The LED goes off for a few seconds during boot, between the host-mode switch and custom.sh running, then comes back on.

    Workaround (userspace)

    /userdata/system/charge-fix.py:

    import mmap, os, struct, time
    BASE, OFF, BIT = 0x0300b000, 8 * 0x24 + 0x10, 1 << 16   # PIO bank I data register, PI16
    fd = os.open("/dev/mem", os.O_RDWR | os.O_SYNC)
    m = mmap.mmap(fd, 0x1000, mmap.MAP_SHARED, mmap.PROT_READ | mmap.PROT_WRITE, offset=BASE)
    while True:
        v = struct.unpack_from("<I", m, OFF)[0]
        if v & BIT:
            struct.pack_into("<I", m, OFF, v & ~BIT)
        time.sleep(5)

    Appended to /userdata/system/custom.sh:

    pgrep -f "[c]harge-fix.py" >/dev/null || nohup python3 /userdata/system/charge-fix.py >/dev/null 2>&1 &

    Side effect: the SP's USB-C port can't power OTG devices while this is running.

    Suggested proper fix

    A device-tree change for the RG35XX SP board only. The Pro is fine as is. Options:

    • Set usbc0 usb_port_type = <0> (device only) on the SP, so it never enters host mode and never drives VBUS out.
    • Or fix the ID-detect handling for the SP. Either PI4 reads high on the SP hardware by design and needs inverted polarity, or the SP's USB-C ID line isn't connected the same way as on the Pro.

    I can test a patched DTB on the SP if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions