Repository navigation
clk: apple-nco: put the probe-time registers back for a firmware sleep - #4200
Conversation
On T6020 (J414s), in 7 deep sleeps with the clock state recorded, the 3 that woke had every NCO channel as the boot loader left it, and the 4 that stalled had a channel that Linux had programmed and then disabled, which is what closing a PCM leaves behind. Clearing every channel's enable bit before the sleep still stalled. With the probe-time registers back in place for the sleep, a sequence that had stalled woke. Save each channel's registers at probe. For a sleep through the firmware, put them back in suspend_late and restore the live ones in resume_early. The enable counts aren't touched: a consumer that holds its clock enabled over the sleep has it running at its rate again before its own resume. Suspend-to-idle and hibernation are unchanged. Which of the registers matters isn't known. CTRL differs by the enable bit, and DIV, INC1 and INC2 differ too. Signed-off-by: DjDeveloperr <hey@djdev.me>
On T6020 (J414s) a deep sleep entered with a programmed, disabled channel also woke when suspend_late only set the enable bit of every channel and left DIV, INC1, INC2 and ACCINIT alone. That is what the T8103, T8112 and T8122 sleep code already does with stopped channels at the commit, so do only that here too. It leaves a channel with a user at its rate instead of moving it to the probe-time values, and no longer depends on what the registers held at probe. The registers are still put back in resume_early. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
J414c (M2 Max, T6021, 13.5 firmware) ran this head, With it: three deep sleeps and wakes in one boot from a full Hyprland desktop with PipeWire running, entered from the menu, woken from the keyboard. Resume count 0 → 3, nothing reported broken by the drivers after any of them. Without it: the same stack with A/B in one boot (with the J414s reference tree's handling, channels saved and enabled across the sleep, behind a switch, before I saw this PR): switch on, two sleeps and wakes; switch off, next sleep, the failure above. Nothing else changed between them. So on T6021 the symptom is earlier than the one described here: not a stall on the wake, the SoC does not go down at all. A desktop always hits it, since the audio server opens the device at login. Test tree: |
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Follow-up on the "Not yet" items, J414c on this head again (same stack as above):
|
Hardware verification (J414s / M2 Pro, exact-head shipping row, n=2 deep sleeps in one boot)
Results (
|
| Stage | Sleep / Wake | Timed 2.0 s audio (plughw:AppleJ414,0) |
Display & Backlight | GPU 3D & Compute (aurora G14S B1) |
Keyboard (Apple MTP keyboard) |
PCIe / Wi-Fi / BT / Faults |
|---|---|---|---|---|---|---|
| Pre-sleep | resumes 0, success=0 fail=0 |
48 kHz: 2.165 s, 44.1 kHz: 2.039 s (rc=0) |
apple-panel-bl 117/500 (bl_power=0), eDP-1 connected/enabled/On, kwin_wayland active 3024x1964 AR30 fb |
dEQP-VK.api.smoke.* 8/8 PASS; clpeak float4: 5.64 TFLOPS |
/dev/input/event3 open/ioctl + Caps Lock LED round-trip 00 -> 02 -> 00 |
lspci 5/5 devices, Wi-Fi 3/3 ping, 0 GPU/MMU/RTKit faults |
Post-wake 1 (rtcwake -s 100) |
WOKE_RC=0, resumes 0 -> 1, success=1 fail=0, 194/252 AP pins put back, halted 0x19, held/macOS-off/clusters stuck 0, RTC 1796313583 -> 1796313706 |
48 kHz: 2.142 s, 44.1 kHz: 2.033 s (rc=0) |
apple-panel-bl 117/500 (bl_power=0), eDP-1 connected/enabled/On, kwin_wayland active 3024x1964 AR30 fb |
GPU fw 27.2 back in 3565 us (pending=0); dEQP-VK.api.smoke.* 8/8 PASS; clpeak float4: 5.64 TFLOPS |
/dev/input/event3 open/ioctl + Caps Lock LED round-trip 00 -> 02 -> 00 |
pci@0,0 & pci@1,0 links/bridges restored, lspci identical, Wi-Fi 3/3 ping, 0 GPU/MMU/RTKit/MTP/SPMI faults |
Post-wake 2 (rtcwake -s 30) |
WOKE_RC=0, resumes 1 -> 2, success=2 fail=0, 194/252 AP pins put back, halted 0x19, held/macOS-off/clusters stuck 0, RTC 1796313802 -> 1796313850 |
48 kHz: 2.203 s, 44.1 kHz: 2.044 s (rc=0) |
apple-panel-bl 117/500 (bl_power=0), eDP-1 connected/enabled/On, kwin_wayland active 3024x1964 AR30 fb |
GPU fw 27.2 back in 3700 us (pending=0); dEQP-VK.api.smoke.* 8/8 PASS; clpeak float4: 5.60 TFLOPS |
/dev/input/event3 open/ioctl + Caps Lock LED round-trip 00 -> 02 -> 00 |
pci@0,0 & pci@1,0 links/bridges restored, lspci identical, Wi-Fi 3/3 ping, BT Powered: yes, 0 GPU/MMU/RTKit/MTP/SPMI faults |
Notes
- Audio playback rate stayed at 1.0x across both deep-sleep wakes (
~2.14–2.20 s@ 48 kHz and~2.03–2.04 s@ 44.1 kHz for 2.0 s of silence), confirming both theclk-apple-ncosleep fix (#4200) and T6020 MCA clock mux save/restore (#3999). - Display and keyboard checks were verified programmatically over SSH (backlight sysfs, DRM connector/DPMS state,
kwin_waylandactive3024x1964framebuffer, andApple MTP keyboardEVIOCGNAME/EVIOCGLED+ Caps Lock LED round-trip); no human physically pressed keys or visually inspected the screen.
There was a problem hiding this comment.
Verdict: MERGE at ae343b8
Checked: An exact-callback host run exercised four channels with mixed enable states. Firmware sleep set only CTRL's enable bit. Resume restored all five registers per channel with the divider written while stopped and final CTRL written last. Repeated cycles and a suspend-abort unwind restored every channel with no clock enable count changes. Non-firmware sleep made no writes. Apple sets its firmware flag before late suspend, and the MCA clock phandles point to the NCO supplier for early resume ordering.
The exact J414s composite with #3999 completed two deep cycles and retained the measured audio timing. The T6020 clock-mux work remains with #3999.
sithglan
left a comment
There was a problem hiding this comment.
Verdict: MERGE at ae343b883fbac21117d3faa2eef66de4293a4eab
Blockers: none
Checked:
- Reviewed the full single-file diff in
drivers/clk/clk-apple-nco.c:applnco_suspend_late()gates strictly onpm_suspend_via_firmware()(leavings2idleuntouched), saves all five channel registers (REG_CTRL,REG_DIV,REG_INC1,REG_INC2,REG_ACCINIT) underchan->lock, enables every channel viaapplnco_enable_nolock(), and markschan->suspended = true.applnco_resume_early()restores the saved registers only whenchan->suspendedis set, clearingCTRL_ENABLEbefore programmingDIV/INC1/INC2/ACCINITand writingREG_CTRLlast (matchingapplnco_set_rate()), then clearschan->suspended.- Uses
LATE_SYSTEM_SLEEP_PM_OPS+pm_sleep_ptr(&applnco_pm_ops)and callsplatform_set_drvdata(pdev, onecell_data)inapplnco_probe().
- Verified exact-head J414s and J414c timed-audio deep-sleep rows and green CI (
host-tests,readiness,pr-text).
|
J516s row (M3 Pro, T6030, OS firmware 27.2) for The trial boot ( Also in that boot, not explained yet: This PR still owes the J516s row. It needs a main whose PCIe probes on J516s, or a kernel without the main PCIe change. Kit and journal: |
RyanTheTide
left a comment
There was a problem hiding this comment.
Approving at ae343b8. The review-lane App approval at this head covers the code review; this adds the code-owner approval the branch rules need.
|
J516s row, head PASS:
FAIL: timed audio, before the first sleep as well as after both. 2 s of zeros to |
|
J516s follow-up row (post-merge With the boot-time T6030 MCA clock-mux fault fixed (
Results (53/53 PASS, 0 FAIL):
|
What: On T6020 (J414s) with the stock driver, every recorded deep sleep entered with an NCO channel that Linux had programmed and then disabled stalled on the wake. For a sleep through the firmware this sets the enable bit of every channel in
suspend_late, as the T8103, T8112 and T8122 sleep code already does with stopped channels, and puts every channel's registers back inresume_early, the enable bit included. The clock enable counts and the rates of channels in use aren't touched. Suspend-to-idle and hibernation are unchanged. No parameter, no SoC or board check.The second commit replaces the first one's way (the probe-time registers for the sleep); both were tried, see below.
Tested: J414s (T6020), deep sleep on a T6020 sleep stack that isn't in main yet (#3999), three boots at the head
ae343b883fba(the third with a test T6020 sleep kernel, below); before that812e8451a3ae(the first commit) and prototypes, each sequence once.ae343b883fba(module build id checked on the running kernel), with the speaker protection and ALSA state services running and three NCO channels opened and used before the sleep: woke (RTC), resumes 0 -> 1, 0 failed suspends. Second boot at the head, same setup: three deep sleeps in a row, all woke, resumes 0 -> 1 -> 2 -> 3, 0 failed suspends, Wi-Fi and the PCI devices back after each (two of the wakes came from USB, one from the PMU). Timed playback of 2 s of silence before the sleep: 2.158 s at 48000 Hz, 2.039 s at 44100 Hz.snd_pcm_prepareat 3.072 MHz, no start, then close) stalled with the stock module and woke with the prototype. Channel 0 went from ctrl 0 / div 0xfe7 / inc 0xea600, 0xffdfc600 to its probe-time ctrl 0x80000000 / div 0 / inc 0, 0. The kernel log shows those values being written for the sleep.clk_summaryread 3072000 Hz, disabled, after the wake, but that rate is the clock framework's cached one: the divider registers were not read back after the wake.812e8451a3ae: the same steps again (module build id checked on the running kernel) woke.812e8451a3aeandae343b883fba: the same timed playback ran too fast, 0.307 s and 0.311 s at 48000 Hz, 0.273 s and 0.272 s at 44100 Hz, against 2.158 s and 2.039 s before the sleep. That is the T6020 sleep code, not this driver: the sleep put the first MCA clock mux on its bypass source (0x85100100 before the sleep, 0x80100100 after the wake) and reset NCO channel 0's divider (0x23c before, 0 after).ae343b883fbawith a test kernel whose T6020 sleep code also saves the MCA clock muxes and NCO channels and puts them back on the wake (for soc: apple: add T6020 (M2 Pro) suspend-to-RAM and DCP S2R power layouts #3999, not part of this PR): 2.348 s and 2.058 s before the sleep, 2.166 s and 2.043 s after the wake, at 48000 and 44100 Hz. The muxes read back as before the sleep, none stuck. Playback was silence through the headphone PCM; nothing audible was checked.speakerguardd-v2-switchtest, at boot before any sleep on the first two (the third's log doesn't list units); it is in the speaker self-check, and this driver does nothing outside a firmware sleep, so it isn't from this change (by the code, not measured against the stock module).mca0power domain without a PCM woke.W=1for the object: no warnings. That was in the J414s test tree, where this file is identical to main's, not in a main tree.checkpatch --strict: clean. The driver has no KUnit test; the change is register save and restore, so none was added.Risk: two-way · every SoC with an NCO node that deep-sleeps through the firmware. The link to the stall is a correlation plus the A/B above; no cause is claimed. Inferred only: that ctrl bit 31 is the enable, as the driver already treats it.
resume_earlystops them again. A row there is still owed.Not yet: