Skip to content

clk: samsung: zumapro: Keep the HSI0 USI2 and USI3 clocks on - #247

Merged
derekross merged 1 commit into
derekross:omamobilefrom
W4HO-ham:clk-zumapro-hsi0-usi-pclk
Nov 15, 2026
Merged

derekross merged 1 commit into
derekross:omamobilefrom
W4HO-ham:clk-zumapro-hsi0-usi-pclk

Conversation

@W4HO-ham

@W4HO-ham W4HO-ham commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

On the Pixel 9a a sleep now and then never woke: four in about 1,200 on the published tree (omarchy-mobile#659, SLEEP-PLAN "What is left" item 1). This is the cause and the fix.

The cause. A register access to a USI in the first microseconds after its clock gates are opened never returns. The CPU sits in the access, takes no tick and answers no IPI. The gates of USI2 and USI3 in HSI0 are writable and in manual mode, nothing holds them while their SPI controllers are idle, and the USI driver's noirq resume opens them and reads USI_CON at once. The USIs resumed before them, in PERIC0 and PERIC1, have read-only gates, and so has USI4 in HSI0. It is the shape #172 removed for the PERIC0 GPIO gate.

How it was found.

  • Two hangs caught with the device callback trace events on. On 2026-11-12, at the 41st sleep of a boot, the suspend task's last event is device_pm_callback_start for the USI at 111d00c0 (USI2, the touchscreen's SPI), noirq resume, with no end.

  • A first try at this change kept only the two PCLK gates on. On that kernel 226 sleeps woke and the 227th hung one callback further on: USI2's resume returns, and the last event is the start of USI3's, at 111e00c0. Its bus clock was on; what its resume switched was the function clock.

  • Awake, in under a second (11-13). A bring-up module repeats the driver's sequence on USI3 from a thread on CPU 7: clocks on, USI_CON read and written back, 1 us, clocks off. On the PCLK-only kernel, so with only the function and source gates switched:

    variant result
    as the driver does it, no wait hung within the first 1,000 rounds, twice of twice; the cluster watchdog reset the palmtop (APC Watchdog Early)
    10 us between the clocks and the access 2,000,000 rounds, no hang
    clocks switched, no register touched 2,000,000 rounds, no hang

    That also fits the 701 clean sleeps with the function tracer on: it puts microseconds between the gate's write and the read.

The fix. All six gates (PCLK, IP and SOURCE of USI2 and USI3) CLK_IS_CRITICAL, as the PERIC0 and HSI2 GPIO gates are, so the clock framework never closes them. A wait after the gate would do it too, but it would have to go into every path that opens one of these gates, and the tree's rule since #172 is that a CMU without automatic clock gating keeps such gates on.

Tested on my palmtop, on the published tip (2db2bc3) with only this change, defconfig plus main's omamobile.config, no debug switches:

  • clk_enable_count 1 or 2 and CLK_IS_CRITICAL on all six gates.
  • The same module, no wait: 2,000,000 rounds on USI3 and 2,000,000 on USI2, the gates never closed, no hang.
  • Sleeps of 60 s ended by the RTC alarm: 10 of 10 with me watching the screen (11-13, 06:54 to 07:07 MST; 59.3 to 60.3 s by the kernel log, pm_wakeup_irq 53 each, no UFS line). A series of 300 on the same boot followed, unattended (07:08 to 14:27 MST): 300 of 300 woke, each on the alarm (pm_wakeup_irq 53), 59.2 to 60.3 s by the kernel log, no UFS line, no oops; suspend_stats reads success 310, fail 0 for the boot.
  • Before this build, with a module holding the same clocks on and the kernel unchanged, 300 of 300 sleeps woke on the tracing build that had hung at the 70th and the 41st.
  • The touchscreen's controller (synaptics-tcm on USI2's SPI) is bound.

Not tested: the unchanged published tip under the module (the hangs above are on the tracing build of the same sources, with the PCLK gates kept on); touch itself on this build, beyond the driver being bound.

Who was there: the ten sleeps at the start of the series on this build were attended. The 300 with the module and the 226 on the PCLK-only kernel ran overnight with nobody at the palmtop, on a module and a kernel that had had no attended run, on my own say-so for my own palmtop; they don't count under the attended-first rule. The awake test resets the palmtop when it hangs; it ran in the morning with me near the palmtop, and the watchdog brought it back each time.

tools/kernel-pr-check is clean.

The gates of USI2 and USI3 in the HSI0 block (the bus, function and
source clock of each) are writable and in manual mode, and nothing holds
them while the SPI controllers behind them are idle. A register access
to the USI in the first microseconds after its gates are opened never
returns: the CPU sits in the access, takes no tick and answers no IPI.

The USI driver does that in its noirq resume (clk_bulk_prepare_enable(),
then USI_CON read and written), and so on the Pixel 9a a sleep now and
then never woke. Two such hangs were caught with the device callback
trace events on. In the first, at the 41st sleep of a boot, the suspend
task's last event is device_pm_callback_start for the USI at 111d00c0
(USI2, the touchscreen's SPI), with no end. In the second, on a kernel
that kept only the two bus clocks on, USI2's callback returns and the
last event is the start of USI3's, at 111e00c0, at the 227th sleep. The
USIs resumed before them, in PERIC0 and PERIC1, have read-only gates,
and so has USI4 in HSI0.

It reproduces awake in under a second. A test module that repeats the
driver's sequence on USI3 (clocks on, USI_CON read and written, 1 us,
clocks off), with the bus clock already on and only the function clock
switched, hung the SoC within its first thousand rounds, twice of twice,
until the watchdog reset it. With 10 us between the clocks and the
access, two million rounds passed, and so did two million rounds that
switched the clocks and touched no register.

Mark the six gates critical, as the PERIC0 and HSI2 GPIO gates are, so
the clock framework never closes them. With that, on the published tree
with nothing else added, two million rounds of the same module passed on
each USI with the gates never closed. Before it, with a module holding
the two USIs' clocks on, 300 of 300 sleeps of 60 s woke on the build
that had hung at the 70th and the 41st.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham. This is a careful piece of detective work. Catching the hang in the PM callback trace, then turning a 1-in-a-few-hundred sleep failure into a sub-second reproduction that tells the cases apart (no wait: hung twice in 1,000 rounds; 10 µs wait or no register access: 2,000,000 clean), is exactly the evidence a clock change like this needs. It also explains the CPU 7 lockup we had recorded without a cause.

I checked it against the base. exynos_usi_resume_noirq() really does read USI_CON straight after clk_bulk_prepare_enable(). USI4's and the PERIC0 USIs' gates are the read-only ones. The six HSI0 gates are the only writable manual-mode USI gates in the file. Only the 9a binds CMU_HSI0, so the Pixel 7 Pro doesn't change. Our gate passes on today's omamobile (2db2bc3): a clean merge, your sign-off, checkpatch --strict with nothing to read, and a W=1 build. CI is green too. It also merges cleanly with #193, which touches the same file.

Two things before I merge, both quick:

  1. A functional check of the two users on this build. Your notes say the touchscreen driver is bound but touch wasn't tried, and USI3 is the GNSS SPI. With their function clocks now running from boot, and USI3's mux still moving when GNSS sets its rate, could you confirm on this build that touch works in the session and that GNSS comes up (the CHPP link, no SPI timeouts in dmesg)?
  2. The 300-sleep count, once the series finishes. If it's clean, that's enough together with the awake test. If it hangs, we look again.

Two smaller things, not for this commit:

  • Could you add the test module to omarchy-mobile under device/tegu/bringup/, with a header saying it hangs the SoC by design? It's the strongest evidence here, and the next person chasing a USI hang will want it.
  • Thank you for saying plainly that the 300 sleeps with the module and the 226 on the PCLK-only kernel ran overnight before either had an attended run. The 9a's rule is one attended run of anything new before it runs unattended. I'd rather hear it from you like this than find it later. Please keep to it from here, and I'll take the rest of that conversation on the sleep plan.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Thank you. Both are coming today.

  1. Touch and GNSS on this build: right after the series, with the owner at the palmtop. Touch in the session on the boot the series ran on, then a clean reboot with the modem up for one GNSS session, with the kernel log read for the CHPP link and any SPI timeout.
  2. The series is past 150 of 300 with every sleep woken, and ends at about 21:40Z.

The test module comes to device/tegu/bringup/ with the sleep plan's follow-up, with a header that says it hangs the SoC by design and how it must be run. Meanwhile both modules are on my fork's tegu-hsi0-usi-bringup branch under bringup/tegu-hsi0-usi/, with a README. And yes: one attended run of anything new first, from here on. The owner has said the same for his palmtop.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

The series is done: 300 of 300 sleeps of 60 s woke on this build (7.3.0-rc6-omamobile-push1-gd74c5bd9dd0e, the published tip at 2db2bc3 with this commit and nothing else), on one boot, modem off, on the charger, 07:08 to 14:27 MST on 11-13.

  • Every wake was the RTC alarm (pm_wakeup_irq 53), 59.2 to 60.3 s asleep by the kernel log.
  • No UFS line, no link failure, no oops in any cycle; suspend_stats for the boot reads success 310, fail 0 (the ten attended sleeps before it included).
  • The RTC difference the script prints read 62 or 63 s in 224 cycles and other values (8 to 108 s) in 76. That is the RTC reading that rtc: s5m: wait for the S2MPG14's read update too #245 fixed; this build is from before it was merged, and the kernel log's own times are what I count by.

For comparison, the same series without the fix stopped at the 70th, the 41st and (bus clocks only) the 227th sleep. The description has the count now. Touch and GNSS on this build are next, with the owner at the palmtop.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Both checks on this build (7.3.0-rc6-omamobile-push1-gd74c5bd9dd0e), 11-13, with the owner at the palmtop.

Touch (USI2), on the boot the 300 ran on, right after the series. The driver had probed as on the daily kernel (synaptics-tcm spi0.0: S3908GA1B0-15.0, TouchComm v1). The owner unlocked with the PIN, swiped and opened a couple of apps: all normal, he says. The touch interrupt count went from 62 to 292 while he did, and the kernel log has no SPI or synaptics-tcm error line. zumapro_dout_hsi0_usi2 reads 39.936 MHz, so the function clock is still divided. (The fingerprint icon was missing on the lock screen: the palmtop's fingerprint driver is a module built for its daily kernel and doesn't load on this one. Nothing to do with this change.)

GNSS (USI3), after a clean reboot with the modem up, kernel log streamed to the laptop from boot. zumapro_gpio_peric0 reads CLK_IS_CRITICAL; the CP was ONLINE 40 s into the boot, then registered on LTE with IMS. One on-demand session of 150 s through the NMEA socket: 109 GGA sentences, 104 of them with a fix, up to 14 satellites, and the service stopped cleanly on its idle lease with the CP still ONLINE. The whole boot's kernel log has no -110, no I/O Error and no failed to transfer line, no UFS error-handler pass and no oops. With the session's rate set, zumapro_dout_hsi0_usi3 read 12.288 MHz, so CLK_SET_RATE_PARENT still reaches the divider. I have no kernel line that names the CHPP link; the fixes arrive over it.

One thing that is not the kernel: the first session attempt on that boot failed at once, because the palmtop's omamobile-gnss 0.2.9 from the repository has no omamobile-gnss-client (the 9a's HAL client is a prebuilt the package leaves out when it isn't there). I reinstalled the package built with it, cleared the marker, and the session above is the second attempt. I'll raise that separately.

With the 300 of 300 above, that is everything you asked for here. The palmtop goes back to its daily kernel now.

@Somnius

Somnius commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Hi @W4HO-ham, this was a good read, and it made me look at zuma, because the 8 Pro has the same two buses.

On today's omamobile (2eda146) drivers/clk/samsung/clk-zuma.c has the shape zumapro had before this PR. The six HSI0 gates of USI2 and USI3 (0x2120, 0x20fc, 0x2100, 0x2124, 0x2104, 0x2108) are writable, they are in hsi0_regs and the comment over it says they run in manual mode, and they are flagged CLK_IGNORE_UNUSED, not CLK_IS_CRITICAL. usi2_hsi0 and spi20 (touch) are enabled on husky and on akita, so exynos_usi_resume_noirq() opens USI2's gates and reads USI_CON straight after on every resume there too, and the SPI controller's runtime resume turns its clocks on and goes straight into s3c64xx_spi_hwinit() after the 2 s autosuspend.

What I don't know is whether zuma hangs on it the way zumapro does. The only no-wake I've had on my 8 Pro was a deep suspend on 2026-11-12, which is a different path from s2idle, and I haven't seen one in s2idle, but I've only done a handful of those (eight successes by 2026-11-13 in my notes), far fewer than your roughly 1 in 300 needs, and I haven't run your stress module or anything like it. So this is from reading the source only, nothing tested.

It matters for GNSS on the 8 Pro: stage 2 of my plan in derekross/omarchy-mobile#739 enables usi3_hsi0 and spi21, which is this path on USI3. I'll put it into the plan before that stage runs.

@derekross, would it be wanted for zuma as well, the six gates critical, as its own PR after this one? I can send it, but I could only test it on the 8 Pro, and not with a long sleep series yet.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Thanks @Somnius, I read the same in clk-zuma.c on 2eda146: the six gates at those offsets, CLK_IGNORE_UNUSED, in hsi0_regs under the manual-mode comment.

One thing that may save you the long series: on the 9a the answer came awake, not from sleeps. The stress module in #800 (device/tegu/bringup/hsi0-usi/tegu-hsi0-usi-stress.c) repeats what exynos_usi_enable() does at every resume, both clocks on, USI_CON read and written back, 1 us, both clocks off, in a loop on one CPU. On the build with only the PCLK gates critical it hung within the first 1,000 rounds, twice of twice; with the six gates critical, 2,000,000 rounds passed on each USI. That's minutes against about 1 in 300 sleeps.

It finds the USI by device-tree path and takes pclk and ipclk from the node, so on husky it needs only husky's paths in nodes[]. But it hangs the SoC by design, so only attended, with the filesystems synced and a watchdog fed from userspace, and on a USI nothing else is using: on husky today that would be USI2 with the touchscreen not in use, or USI3 once your stage 2 has enabled it and before anything else depends on it. A pass there (access=0 and delay_us=10 are the two controls) would say a lot more about zuma than a handful of sleeps.

@Somnius

Somnius commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Thanks @W4HO-ham, that is a much better test than a long sleep series, and it makes the question testable in minutes. I haven't run it or built it for husky. Since it hangs the SoC by design, I won't run it unless @derekross says it's wanted, and then only attended: filesystems synced, a watchdog fed from userspace, the slot B retry count read first, and on a USI nothing else is using. On my unit that would be USI2 with the touchscreen unused, or USI3 after stage 2 of derekross/omarchy-mobile#739.

I did the software-only reads on my unit instead (the clk debugfs enable counts and flags, and the SPI controllers' runtime_status, no register access), kernel 7.3.0-rc6-omamobile-push1-g596d44e5bd5e, 15,632 s after boot. The three USI2 gates (ip, pclk, source) have enable count 1 and 111d0000.spi (the touchscreen) has been active for 15,630 s and suspended for 1.5 s, so those gates are opened once and stay open. The USI1 gates have count 0 and 111c0000.spi was active for 9 s in total and suspended the rest, so its clocks were on for about 9 s in total and then off, without a hang. USI3 reads 0 because it's disabled in this image. All of them carry CLK_IGNORE_UNUSED. That is evidence that open-then-access has run on zuma without a hang, not proof, and it says nothing about the first microseconds under stress, which is what your module tests. If @derekross wants it, I'd add husky's paths to nodes[] as you describe and send that as a small change next to your tegu module.

@derekross

Copy link
Copy Markdown
Owner

Thank you, both are in. The 300 of 300 on the published tip with only this commit, after the attended ten and against the same series stopping at the 70th, 41st and 227th without it, is the count I asked for. Touch in the session and a GNSS session with 104 of 109 fixes, no SPI errors, and the USI3 divider still following the session's rate, covers what I wanted from the two users. I re-ran our gate on today's omamobile (d49d68c): it merges cleanly, the sign-off is in place, checkpatch --strict has nothing to read, and the W=1 build is clean. Nothing in clk-zumapro.c has moved on the base since your CI run. The Pixel 7 Pro never binds this clock block, so it doesn't change. I'm merging it.

Thank you also for putting the modules in the tree in #800. I've asked there for the stress module to refuse anything but a 9a and to have no default USI, since it hangs the SoC on purpose.

@Somnius, thank you for reading zuma's side. I'll answer separately on whether I want the same change for zuma. Until then, please keep the stress module off your 8 Pro, as you said you would.

@derekross
derekross merged commit 55b1c4b into derekross:omamobile Nov 15, 2026
1 check passed
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