Skip to content

RK356x: lazy PMIC pinctrl for RK817/RK809 SLPPIN + ON/OFF source logging#2440

Draft
aenertia wants to merge 3 commits intoROCKNIX:nextfrom
aenertia:nert-next/rk356x-powerpin-additions
Draft

RK356x: lazy PMIC pinctrl for RK817/RK809 SLPPIN + ON/OFF source logging#2440
aenertia wants to merge 3 commits intoROCKNIX:nextfrom
aenertia:nert-next/rk356x-powerpin-additions

Conversation

@aenertia
Copy link
Copy Markdown
Contributor

This fixes a source of phantom drain on 353(m/p/v) and RGB30 whilst off many users encounter. Original testing done by @Zetarancio targeting the miyoo flip and then adapted to mainline compatible patchset for both rk3566 and rk3568 targets by myself with LLM assistance.

Tested on miyoo flip (out of tree), rgb30,353p, rgds (with -next branch).

Lazy pinctrl acquisition for RK817/RK809 SLPPIN (GPIO0_PA2):

  • Defer pinctrl_get() to first suspend/shutdown instead of probe time
  • Prevents devm_pinctrl_get() from applying default state during probe, which can reconfigure PA2 while PMIC register state is unknown
  • Cache pinctrl handle + states in struct rk808 after first load
  • Falls back to register-only path if no DTS pinctrl states defined
  • BSP sequence: NULL function → 2ms delay → select state → function write

DTS changes for Anbernic RG-DS and Powkiddy RK2023:

  • pinctrl-0 (default) has NO slppin state (matches stock Android)
  • pinctrl-1 = soc_slppin_slp (PMU_SLEEP for suspend)
  • pinctrl-2 = soc_slppin_gpio (GPIO low for poweroff)

ON/OFF source logging reads RK817_ON_SOURCE_REG and RK817_OFF_SOURCE_REG at probe time for power-cycle debugging (cold-start, watchdog, RTC wake, clean shutdown vs under-voltage).

@aenertia
Copy link
Copy Markdown
Contributor Author

@sydarn
Copy link
Copy Markdown
Contributor

sydarn commented Mar 18, 2026

The usb port on rgb30 is still powered while off with this patch...

@aenertia
Copy link
Copy Markdown
Contributor Author

yeah it doesn't fix everything on every device. It's a contributor to a multi-faceted set of issues.

@Zetarancio
Copy link
Copy Markdown

I was not able to properly shutdown without "SLPPIN_NULL_FUN → SLPPOL_H → pinctrl ". Are you sure a delay is enough there?

@aenertia
Copy link
Copy Markdown
Contributor Author

I was not able to properly shutdown without "SLPPIN_NULL_FUN → SLPPOL_H → pinctrl ". Are you sure a delay is enough there?

I tried a couple of different iterations with different behavior in ordering - this one was the one that seemed to consistently shutdown all 3 devices I tested on. But I can have another poke at it and see if there are improvements that can be made based on your feedback. I didn't dig into i.e rgb30's specific bag of issues - probably would need each specific device on BSP / Known loads which work ; and tapping the various kernel and i2c / pmic call orders to build a definitive per device quirks list to nail all the drain-whilst-off issues.

@aenertia aenertia marked this pull request as draft March 18, 2026 20:36
@aenertia aenertia force-pushed the nert-next/rk356x-powerpin-additions branch from 3235fe3 to 153872c Compare March 18, 2026 20:42
aenertia added a commit to aenertia/distribution that referenced this pull request Mar 18, 2026
Sync updated 0029 patch from nert-next/rk356x-powerpin-additions:
- Add SLPPOL_H step before pinctrl mux (Zetarancio feedback)
- Disable OTG switch before SLPPIN sequence (sydarn RGB30 USB drain)
- Full BSP ordering: OTG_OFF → NULL_FUN → SLPPOL_H → pinctrl → DN_FUN
@aenertia
Copy link
Copy Markdown
Contributor Author

I've been running this all day and it seems to work fine. Haven't been looking for anything other than 'does it shutdown' and does it power on tho. CI https://github.com/aenertia/distribution/actions/runs/23290369178

@Zetarancio
Copy link
Copy Markdown

I've been running this all day and it seems to work fine. Haven't been looking for anything other than 'does it shutdown' and does it power on tho. CI https://github.com/aenertia/distribution/actions/runs/23290369178

I think we really need to understand if they shutdown any different with this patch than they were doing before. Probably a longer "power off drain test" can actually tells us, unless you other meter benchmarks XD

@aenertia
Copy link
Copy Markdown
Contributor Author

aenertia commented Mar 19, 2026 via email

@Zetarancio
Copy link
Copy Markdown

Zetarancio commented Mar 19, 2026

I hope you had some kind of table benchmark or something XD. Anyway we are really behind on this to merge it as of now. Currently the miyoo does not drain while off but cannot reliably resume from sleep (The opposite of what was happening before). So I guess it's too early for any of this.

Edit: It was unrelated to this but rather to the wifi driver I was patching.

@aenertia
Copy link
Copy Markdown
Contributor Author

Well the 353p I have it on at the moment has been draining whilst off to dead pretty reliably on nightlies for months now. I'll leave it off at 100% tonight and see what it is in the morning. It's one of those ; how many things can you actually test reliably things. It's not exhaustive but it's something.

On Thu, 19 Mar 2026 at 23:39, Zetarancio @.> wrote: Zetarancio left a comment (ROCKNIX/distribution#2440) <#2440 (comment)> I've been running this all day and it seems to work fine. Haven't been looking for anything other than 'does it shutdown' and does it power on tho. CI https://github.com/aenertia/distribution/actions/runs/23290369178 I think we really need to understand if they shutdown any different with this patch than they were doing before. Probably a longer "power off drain test" can actually tells us, unless you other meter benchmarks XD — Reply to this email directly, view it on GitHub <#2440 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACF5LYFNMOHBDGZI6BIL3L4RPE5BAVCNFSM6AAAAACWVTO4AKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DAOBZGIYDOOBTGQ . You are receiving this because you authored the thread.Message ID: @.>

Well it was still at 100% this morning which is one datapoint. I will put a build on the rgb30 today and leave it for a day or so.

@aenertia aenertia force-pushed the nert-next/rk356x-powerpin-additions branch from 153872c to 1ab415d Compare March 20, 2026 01:27
@aenertia
Copy link
Copy Markdown
Contributor Author

Have revised significantly based on setting up some probes on the RGDS from gamma's android build and dumping i2c/pmic writes to logs over several reboot cycle. Still a WIP but current notes attached.
RGDS-Power-Notes.md

Revised based on ADB register tracing of Android/GammaOS shutdown
on the RG-DS. Android does NOT manipulate SLPPIN — it relies solely
on DEV_OFF (bit 0 of SYS_CFG(3)) via the standard pm_power_off().

Key findings from i2c register tracing during Android shutdown:
  - SLPPIN function stays RST(3), polarity stays LOW(0)
  - No SYS_CFG(3) writes until the final DEV_OFF
  - OFF_SOURCE and INT_STS persist across reboot (never cleared)
  - OTG disabled by Android before shutdown

Changes:
  Patch 0029 (REVISED): OTG switch disable + INT_STS flag clearing
    - Disable OTG (BIT(2)|BIT(6) of POWER_EN(3)) before poweroff
    - Clear stale INT_STS(0-2) registers (W1C) to prevent
      UVLO/OVP/HOTDIE flags persisting across reboots
    - REMOVED: SLPPIN manipulation, SLPPOL_H override, pinctrl
    - REMOVED: Lazy pinctrl acquisition, rk808.h struct changes

  Patch 0030 (UNCHANGED): ON/OFF_SOURCE logging at probe

  Patch 0031 (REMOVED): DTS SLPPIN pinctrl states no longer needed

Our previous SLPPOL_H=1 was WRONG — Android uses SLPPOL=0 (LOW).
Setting HIGH polarity interfered with the PMIC power state machine,
causing unreliable soft shutdown and power button wake issues.
@aenertia aenertia force-pushed the nert-next/rk356x-powerpin-additions branch from 1ab415d to 389505d Compare March 20, 2026 07:35
LCD panels hold their last framebuffer content after shutdown because
no backlight-off signal is sent. Add ExecStopPost that writes 4 (off)
to all bl_power sysfs nodes when sway stops.
After a PMIC OCP brownout (no clean shutdown), stale INT_STS flags
persist and can leave the PMIC confused on next boot. Clear all three
INT_STS registers (W1C) at probe time, before interrupt handlers
register, alongside the existing ON/OFF_SOURCE logging.
@aenertia aenertia force-pushed the nert-next/rk356x-powerpin-additions branch from 9dbd7c0 to 24f92b1 Compare March 20, 2026 09:35
aenertia added a commit to aenertia/distribution that referenced this pull request Mar 29, 2026
Sync updated 0029 patch from nert-next/rk356x-powerpin-additions:
- Add SLPPOL_H step before pinctrl mux (Zetarancio feedback)
- Disable OTG switch before SLPPIN sequence (sydarn RGB30 USB drain)
- Full BSP ordering: OTG_OFF → NULL_FUN → SLPPOL_H → pinctrl → DN_FUN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants