Skip to content

ARM: apple: Add s2idle suspend/resume support for 32-bit Apple S5L SoCs - #161

Merged
henrikklee merged 7 commits into
OrchardLinux:armv7from
alistairreay:apple-s5l-s2idle
Dec 4, 2026
Merged

henrikklee merged 7 commits into
OrchardLinux:armv7from
alistairreay:apple-s5l-s2idle

Conversation

@alistairreay

Copy link
Copy Markdown

Adds suspend-to-idle (s2idle) support for 32-bit Apple S5L894x/S5L895x SoCs, matching Orchard's arm64 cpuidle-apple + docs/bring-up/suspend.md architecture.

Changes

  1. cpuidle: apple-s5l: Add WFI and s2idle driver for 32-bit Apple S5L SoCs
    • Registers WFI (state 0) and WFI-S2IDLE (state 1, with enter_s2idle) so s2idle enters cpuidle_enter_s2idle(), freezes ticks and timekeeping, and stops CLOCK_MONOTONIC from advancing during sleep (preventing systemd watchdog kills after >3 min sleeps).
    • Delegates to arch_cpu_idle() rather than raw cpu_do_idle() so secondary cores keep taking apple_s5l_idle() (cpu_suspend() + L1 flush) instead of plain WFI, which causes PMGR to power off CPU1 and lose dirty L1 cache lines.
  2. ARM: apple: Support s2idle wake IRQs, nonstop clocksource, and WDT pause
    • drivers/irqchip/irq-apple-aic1.c: sets IRQCHIP_SKIP_SET_WAKE on aic1_chip, and registers AIC1's 64-bit 24 MHz timebase (apple-aic1-time, rating 360) with CLOCK_SOURCE_SUSPEND_NONSTOP so CLOCK_BOOTTIME advances accurately across arbitrarily long sleeps while CLOCK_MONOTONIC stays frozen.
    • drivers/pinctrl/pinctrl-s5l8940x-gpio.c: implements irq_set_wake forwarding to the parent AIC1 IRQ (pctl->irqs[0]) so wakeup-source GPIO buttons wake the SoC from s2idle.
    • arch/arm/mach-apple/apple_wdt_clkevt.c: pauses the 60 s hardware reset watchdog on PM_SUSPEND_PREPARE and re-arms/pings it on PM_POST_SUSPEND so sleeps longer than 60 s do not reset the device.
    • drivers/power/supply/apple-pmu-charger.c: queues periodic I2C polling on system_freezable_wq so it freezes cleanly across suspend.
  3. ARM: configs: orchard_applearmv7: Enable s2idle suspend and Apple S5L cpuidle
    • Enables CONFIG_SUSPEND, CONFIG_PM_DEBUG, and CONFIG_ARM_APPLE_S5L_CPUIDLE.

Live hardware verification (64 GB iPad 3 / iPad3,3 / j2a, dual-core A5X SMP)

Tested together with wakeup-source; on Home & Hold in #152:

  • pm_test=devices and pm_test=platform: PASS (success=2, fail=0).
  • Short sleep (46.05 s): woke cleanly on Home (pm_wakeup_irq=57), same boot_id.
  • Medium sleep (85.4 s, past the 60 s WDT): woke cleanly on Hold/Power (pm_wakeup_irq=58), same boot_id.
  • Full >3 min sleep (294.4 s / ~4m 54s wall time, dual-core SMP + apple_s5l_cpuidle + apple-aic1-time):
    • boot_id=ed91bf58-896e-42fb-98a1-e08e72950019 unchanged, suspend_stats: success=1 fail=0, pm_wakeup_irq=58 (Hold/Power).
    • CLOCK_MONOTONIC frozen during sleep (dmesg: suspend [41.636176] → resume [41.839688], only 0.20 s elapsed).
    • CLOCK_BOOTTIME (/proc/uptime) advanced accurately: 39.91 s → 359.76 s.
    • s2idle idle state counters incremented on both cores (cpu0/state1/s2idle/usage=2, cpu1/state1/s2idle/usage=1, apple_smp.powerdowns=3320).
    • Zero watchdog resets during sleep; apple-wdt cleanly re-armed on wake (ctrl 0x4).
    • Post-wake health: backlight automatically off during sleep and restored on wake (1658, bl_power=0), USB gadget re-enumerated and renegotiated 2400 mA Apple host grant, brcmfmac reloaded BCM4330/4 firmware (wlan0 up), battery HDQ live (100% Full), NAND /dev/applesftl0p1 intact, zero warnings/errors/stalls.

alistairreay and others added 7 commits December 5, 2026 05:44
Add a cpuidle driver for 32-bit Apple S5L894x/S5L895x SoCs so suspend-to-idle (s2idle) reaches cpuidle_enter_s2idle(), freezes the tick and timekeeping, and stops CLOCK_MONOTONIC from advancing during sleep.

Delegates to arch_cpu_idle() rather than raw cpu_do_idle() so secondary cores keep entering apple_s5l_idle() (cpu_suspend + L1 clean) instead of plain WFI, which powers off CPU1 and loses its L1 state on S5L894x/S5L895x.

Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
Two pieces suspend-to-idle needs from AIC1 on 32-bit Apple S5L SoCs:

- aic1_chip has no irq_set_wake, so enable_irq_wake() on its interrupts
  (and on GPIO interrupts forwarded to it) failed. Set
  IRQCHIP_SKIP_SET_WAKE: wake interrupts stay enabled through s2idle
  and wake the CPU.
- Register AIC1's 64-bit 24 MHz timebase as the apple-aic1-time
  clocksource with CLOCK_SOURCE_SUSPEND_NONSTOP, so CLOCK_BOOTTIME
  advances accurately across long sleeps while CLOCK_MONOTONIC stays
  frozen.

[Orchard: split by subsystem out of "ARM: apple: Support s2idle wake IRQs,
 nonstop clocksource, and WDT pause" (linux#161)]

Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
Implement irq_set_wake by forwarding it to the controller's parent AIC1
interrupt, so GPIO lines marked wakeup-source (gpio-keys buttons) can
wake the SoC from suspend-to-idle.

[Orchard: split by subsystem out of "ARM: apple: Support s2idle wake IRQs,
 nonstop clocksource, and WDT pause" (linux#161)]

Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
Nothing pets the 60 s hardware reset watchdog while the system is
suspended to idle. Stop the watchdog on PM_SUSPEND_PREPARE and
re-arm and ping it on PM_POST_SUSPEND, so sleeps longer than the
timeout do not reset the device.

[Orchard: split by subsystem out of "ARM: apple: Support s2idle wake IRQs,
 nonstop clocksource, and WDT pause" (linux#161)]

Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
Queue the charger's periodic I2C polling, and the immediate re-run a
USB host report triggers, on system_freezable_wq, so the work freezes
cleanly during suspend instead of touching the PMU while devices are
suspended.

[Orchard: split by subsystem out of "ARM: apple: Support s2idle wake IRQs,
 nonstop clocksource, and WDT pause" (linux#161), and applied to all three
 places the reworked driver from linux#139 queues its work]

Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
… cpuidle

Enable CONFIG_SUSPEND and CONFIG_ARM_APPLE_S5L_CPUIDLE in
orchard_applearmv7_defconfig, for suspend-to-idle on the 32-bit Apple
S5L boards.

[Orchard: dropped CONFIG_PM_DEBUG, a debugging aid (pm_test and
 friends) that s2idle does not need]

Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
…nd mini

Like the iPad 3, let the Home and Hold (power) buttons wake the iPad 2
(K93 family) and the iPad mini 1 (P105) from suspend-to-idle. The GPIO
controller forwards wake requests to AIC1, so a press on either button
wakes the SoC. The iPhone 5 boards describe no buttons yet.

Assisted-by: LLM
Signed-off-by: Henrik Klee <henrik@goat-code.com>
@henrikklee
henrikklee merged commit 1412c7e into OrchardLinux:armv7 Dec 4, 2026
3 checks passed
@henrikklee

Copy link
Copy Markdown

Thanks a lot, @alistairreay! Merged. With this, the 32-bit boards can suspend to idle: the new cpuidle driver, wake interrupts through AIC1 and the GPIO controller, a clocksource that keeps counting through sleep, and the watchdog paused while asleep.

What we changed on your branch:

  • Rebased onto armv7 after apple-pmu-charger: Add shared adaptive charging and iPad 3 D1974 support #139. The charger's work now runs on the freezable workqueue in all three places the reworked driver queues it (poll, probe, and the immediate re-run after a USB host report).
  • Split the plumbing commit by subsystem, without changing behaviour: irqchip (AIC1 wake + clocksource), pinctrl (GPIO wake forwarding), the watchdog, and the charger. Each stays under your name.
  • Dropped CONFIG_PM_DEBUG from the defconfig. It's a debugging aid (pm_test) and s2idle doesn't need it.
  • Wake buttons on every 32-bit board that has them (our commit): Home and Hold are now wakeup sources on the iPad 2 (K93 family) and the iPad mini 1 (P105), as on the iPad 3 since iPad 3: Add GPIO buttons and side switch #152. The iPhone 5 boards describe no buttons yet.

Nothing was left out.

Open follow-up: the watchdog is stopped from PM_SUSPEND_PREPARE until PM_POST_SUSPEND, so a hang while devices suspend or resume goes undetected. A narrower window (stopping it at the last step before idle, for example from a syscore or noirq hook, and restarting it first thing on resume) would keep that protection.

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.

2 participants