From 6eb1caf49115c058facb7386402c5099c32e6e2c Mon Sep 17 00:00:00 2001 From: Alistair Reay Date: Fri, 4 Dec 2026 16:14:46 +0000 Subject: [PATCH 1/7] cpuidle: apple-s5l: Add WFI and s2idle driver for 32-bit Apple S5L SoCs 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 --- drivers/cpuidle/Kconfig.arm | 7 +++ drivers/cpuidle/Makefile | 1 + drivers/cpuidle/cpuidle-apple-s5l.c | 78 +++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 drivers/cpuidle/cpuidle-apple-s5l.c diff --git a/drivers/cpuidle/Kconfig.arm b/drivers/cpuidle/Kconfig.arm index a1ee475d180dac..9a31354baf8221 100644 --- a/drivers/cpuidle/Kconfig.arm +++ b/drivers/cpuidle/Kconfig.arm @@ -130,3 +130,10 @@ config ARM_QCOM_SPM_CPUIDLE The Subsystem Power Manager (SPM) controls low power modes for the CPU and L2 cores. It interface with various system drivers to put the cores in low power modes. + +config ARM_APPLE_S5L_CPUIDLE + bool "CPU Idle Driver for Apple 32-bit S5L SoCs" + depends on (ARCH_APPLE_S5L || COMPILE_TEST) && ARM && !ARM64 + help + Select this to enable WFI and suspend-to-idle (s2idle) CPU idle + states on 32-bit Apple S5L894x/S5L895x SoCs. diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index d103342b7cfc21..b27a6eb4570e1a 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_ARM_PSCI_CPUIDLE) += cpuidle-psci.o obj-$(CONFIG_ARM_PSCI_CPUIDLE_DOMAIN) += cpuidle-psci-domain.o obj-$(CONFIG_ARM_TEGRA_CPUIDLE) += cpuidle-tegra.o obj-$(CONFIG_ARM_QCOM_SPM_CPUIDLE) += cpuidle-qcom-spm.o +obj-$(CONFIG_ARM_APPLE_S5L_CPUIDLE) += cpuidle-apple-s5l.o ############################################################################### # MIPS drivers diff --git a/drivers/cpuidle/cpuidle-apple-s5l.c b/drivers/cpuidle/cpuidle-apple-s5l.c new file mode 100644 index 00000000000000..a5ba6784ff700e --- /dev/null +++ b/drivers/cpuidle/cpuidle-apple-s5l.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * CPU idle for 32-bit Apple S5L SoCs (A5 / A5X / A6), which have no PSCI. + * + * Without a cpuidle driver the idle loop never reaches the s2idle path, so + * suspend-to-idle keeps the tick running and does not suspend timekeeping: + * CLOCK_MONOTONIC counts the sleep, and service watchdogs armed before a + * long sleep expire on wake. The core only enters a state above index 0 for + * s2idle, and only one with a non-zero exit latency, hence the second state. + * + * Delegates to arch_cpu_idle() so secondary cores continue to enter the + * PMGR power-down path (apple_s5l_idle -> cpu_suspend) instead of plain WFI, + * which loses CPU1's L1 state on S5L894x/S5L895x. + */ + +#include +#include +#include +#include +#include + +static __cpuidle int apple_s5l_cpuidle_enter(struct cpuidle_device *dev, + struct cpuidle_driver *drv, + int index) +{ + arch_cpu_idle(); + return index; +} + +static struct cpuidle_driver apple_s5l_cpuidle_driver = { + .name = "apple_s5l_cpuidle", + .owner = THIS_MODULE, + .states = { + { + .enter = apple_s5l_cpuidle_enter, + .exit_latency = 1, + .target_residency = 1, + .name = "WFI", + .desc = "Apple S5L idle", + }, + { + .enter = apple_s5l_cpuidle_enter, + .enter_s2idle = apple_s5l_cpuidle_enter, + .exit_latency = 1, + .target_residency = 1000, + .name = "WFI-S2IDLE", + .desc = "Apple S5L idle (s2idle)", + }, + }, + .state_count = 2, +}; + +static const char *const apple_s5l_cpuidle_socs[] = { + "apple,s5l8940x", + "apple,s5l8942x", + "apple,s5l8945x", + "apple,s5l8950x", + "apple,s5l8955x", + NULL +}; + +static int __init apple_s5l_cpuidle_init(void) +{ + if (!of_machine_compatible_match(apple_s5l_cpuidle_socs)) + return -ENODEV; + + return cpuidle_register(&apple_s5l_cpuidle_driver, NULL); +} +module_init(apple_s5l_cpuidle_init); + +static void __exit apple_s5l_cpuidle_exit(void) +{ + cpuidle_unregister(&apple_s5l_cpuidle_driver); +} +module_exit(apple_s5l_cpuidle_exit); + +MODULE_DESCRIPTION("CPU idle for 32-bit Apple S5L SoCs"); +MODULE_LICENSE("GPL"); From 3f4694787b8cbace713981552510431331769c81 Mon Sep 17 00:00:00 2001 From: Alistair Reay Date: Fri, 4 Dec 2026 16:14:46 +0000 Subject: [PATCH 2/7] irqchip/apple-aic1: Skip set_wake and add a suspend-nonstop clocksource 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 --- drivers/irqchip/irq-apple-aic1.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/irqchip/irq-apple-aic1.c b/drivers/irqchip/irq-apple-aic1.c index 3216d7de00d1d4..1ea78cf1e94094 100644 --- a/drivers/irqchip/irq-apple-aic1.c +++ b/drivers/irqchip/irq-apple-aic1.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -466,6 +467,7 @@ static struct irq_chip aic1_chip = { .irq_mask = aic1_irq_mask, .irq_unmask = aic1_irq_unmask, .irq_eoi = aic1_irq_eoi, + .flags = IRQCHIP_SKIP_SET_WAKE, }; /* IRQ entries that found no event, and events handled in one entry beyond @@ -843,6 +845,19 @@ static u64 aic1_time(struct apple_aic1 *aic) return ((u64)hi << 32) | lo; } +static u64 aic1_cs_read(struct clocksource *cs) +{ + return aic1_time(apple_aic1); +} + +static struct clocksource aic1_cs = { + .name = "apple-aic1-time", + .rating = 360, + .read = aic1_cs_read, + .mask = CLOCKSOURCE_MASK(64), + .flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP, +}; + static void aic1_tmr_disarm(struct apple_aic1 *aic) { aic1_tmr_write(aic, AIC1_LOCAL_MASK_SET, AIC1_LOCAL_TIMER); @@ -1178,5 +1193,14 @@ void __init apple_aic1_prepare_boot(void) } early_initcall(aic1_timer_init); +static int __init aic1_clocksource_init(void) +{ + if (!apple_aic1 || !aic1_tmr_registered) + return 0; + + return clocksource_register_hz(&aic1_cs, AIC1_TIMER_HZ); +} +device_initcall(aic1_clocksource_init); + IRQCHIP_DECLARE(apple_aic1, "aic,1", aic1_of_init); IRQCHIP_DECLARE(apple_aic1_vendor, "apple,aic1", aic1_of_init); From 48f39bd6f8d87c24dcbffa2fa3c4cebd237dc3c7 Mon Sep 17 00:00:00 2001 From: Alistair Reay Date: Fri, 4 Dec 2026 16:14:46 +0000 Subject: [PATCH 3/7] pinctrl: s5l8940x-gpio: Forward irq_set_wake to the parent interrupt 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 --- drivers/pinctrl/pinctrl-s5l8940x-gpio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/pinctrl/pinctrl-s5l8940x-gpio.c b/drivers/pinctrl/pinctrl-s5l8940x-gpio.c index b38607939ad5cc..8b08adf12dad29 100644 --- a/drivers/pinctrl/pinctrl-s5l8940x-gpio.c +++ b/drivers/pinctrl/pinctrl-s5l8940x-gpio.c @@ -395,6 +395,13 @@ static int apple_s5l8940x_gpio_gpio_irq_set_type(struct irq_data *data, unsigned return 0; } +static int apple_s5l8940x_gpio_gpio_irq_set_wake(struct irq_data *data, unsigned int on) +{ + struct apple_s5l8940x_gpio_pinctrl *pctl = gpiochip_get_data(irq_data_get_irq_chip_data(data)); + + return irq_set_irq_wake(pctl->irqs[0], on); +} + static void apple_s5l8940x_gpio_gpio_irq_handler(struct irq_desc *desc) { struct gpio_chip *gc = irq_desc_get_handler_data(desc); @@ -462,6 +469,7 @@ static int apple_s5l8940x_gpio_gpio_register(struct apple_s5l8940x_gpio_pinctrl pctl->irq_chip.irq_mask = apple_s5l8940x_gpio_gpio_irq_mask; pctl->irq_chip.irq_unmask = apple_s5l8940x_gpio_gpio_irq_unmask; pctl->irq_chip.irq_set_type = apple_s5l8940x_gpio_gpio_irq_set_type; + pctl->irq_chip.irq_set_wake = apple_s5l8940x_gpio_gpio_irq_set_wake; { struct gpio_irq_chip *girq = &pctl->gpio_chip.irq; From 5b4320f1a1a9df2b3403dc6b9bb639aa6f2cb414 Mon Sep 17 00:00:00 2001 From: Alistair Reay Date: Fri, 4 Dec 2026 16:14:46 +0000 Subject: [PATCH 4/7] ARM: apple: Pause the reset watchdog across suspend 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 --- arch/arm/mach-apple/apple_wdt_clkevt.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/arm/mach-apple/apple_wdt_clkevt.c b/arch/arm/mach-apple/apple_wdt_clkevt.c index 19f86ae9fe2dce..98fab796b9c809 100644 --- a/arch/arm/mach-apple/apple_wdt_clkevt.c +++ b/arch/arm/mach-apple/apple_wdt_clkevt.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -414,6 +415,27 @@ static struct watchdog_device apple_wdt_wdd = { .max_timeout = U32_MAX / APPLE_WDT_REF_HZ, /* 178 s */ }; +static int apple_wdt_pm_notify(struct notifier_block *nb, unsigned long action, + void *data) +{ + if (!wdt_base || !watchdog_hw_running(&apple_wdt_wdd)) + return NOTIFY_DONE; + + switch (action) { + case PM_SUSPEND_PREPARE: + apple_wdt_stop(&apple_wdt_wdd); + break; + case PM_POST_SUSPEND: + apple_wdt_start(&apple_wdt_wdd); + break; + } + return NOTIFY_DONE; +} + +static struct notifier_block apple_wdt_pm_nb = { + .notifier_call = apple_wdt_pm_notify, +}; + static int __init apple_wdt_watchdog_init(void) { u32 ctrl; @@ -442,6 +464,7 @@ static int __init apple_wdt_watchdog_init(void) } pr_info("watchdog: armed, %u s, petted by the kernel until userspace opens /dev/watchdog (boot CTRL %#x)\n", apple_wdt_wdd.timeout, ctrl); + register_pm_notifier(&apple_wdt_pm_nb); debugfs_create_file("state", 0444, debugfs_create_dir("apple-wdt", NULL), NULL, &apple_wdt_state_fops); return 0; From 40e2baaf5486189c376d21b00bbaa3b51f2c9273 Mon Sep 17 00:00:00 2001 From: Alistair Reay Date: Fri, 4 Dec 2026 16:14:46 +0000 Subject: [PATCH 5/7] power: supply: apple-pmu-charger: Poll on the freezable workqueue 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 --- drivers/power/supply/apple-pmu-charger.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/apple-pmu-charger.c b/drivers/power/supply/apple-pmu-charger.c index dc3c37851433fc..dbab103399b0c1 100644 --- a/drivers/power/supply/apple-pmu-charger.c +++ b/drivers/power/supply/apple-pmu-charger.c @@ -845,7 +845,7 @@ static void pmu_chg_work(struct work_struct *w) mutex_unlock(&c->lock); if (changed) power_supply_changed(c->psy); - schedule_delayed_work(&c->work, msecs_to_jiffies(poll_ms)); + queue_delayed_work(system_freezable_wq, &c->work, msecs_to_jiffies(poll_ms)); } static int pmu_chg_get(struct power_supply *psy, enum power_supply_property psp, @@ -921,7 +921,7 @@ static int pmu_chg_set(struct power_supply *psy, enum power_supply_property psp, if (changed) { power_supply_changed(psy); - mod_delayed_work(system_wq, &c->work, 0); + mod_delayed_work(system_freezable_wq, &c->work, 0); } return 0; } @@ -1023,7 +1023,8 @@ static int pmu_chg_probe(struct platform_device *pdev) if (ret) return ret; /* Identify immediately when VBUS is already present at probe. */ - schedule_delayed_work(&c->work, c->online ? 0 : msecs_to_jiffies(POLL_OFFLINE_MS)); + queue_delayed_work(system_freezable_wq, &c->work, + c->online ? 0 : msecs_to_jiffies(POLL_OFFLINE_MS)); dev_info(&pdev->dev, "%s: 0x%02x = 0x%02x (%u mA) at probe, status0 0x%02x (VBUS %s), max %u mA, %s\n", From ad523f7f65da6f836bef16925d8ac2555233ce4e Mon Sep 17 00:00:00 2001 From: Alistair Reay Date: Fri, 4 Dec 2026 16:14:46 +0000 Subject: [PATCH 6/7] ARM: configs: orchard_applearmv7: Enable s2idle suspend and Apple S5L 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 --- arch/arm/configs/orchard_applearmv7_defconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm/configs/orchard_applearmv7_defconfig b/arch/arm/configs/orchard_applearmv7_defconfig index bbfc7645edab88..e1696751b6463f 100644 --- a/arch/arm/configs/orchard_applearmv7_defconfig +++ b/arch/arm/configs/orchard_applearmv7_defconfig @@ -63,10 +63,11 @@ CONFIG_ARM_SCMI_CPUFREQ=y CONFIG_CPU_IDLE=y CONFIG_ARM_CPUIDLE=y CONFIG_ARM_PSCI_CPUIDLE=y +CONFIG_ARM_APPLE_S5L_CPUIDLE=y CONFIG_VFP=y CONFIG_NEON=y CONFIG_KERNEL_MODE_NEON=y -# CONFIG_SUSPEND is not set +CONFIG_SUSPEND=y # CONFIG_VMAP_STACK is not set CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y From b57c3734e6af14c152e3a06452855415f39cfeef Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 05:39:23 +0800 Subject: [PATCH 7/7] ARM: dts: apple: Mark Home and Hold as wakeup sources on the iPad 2 and 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 --- arch/arm/boot/dts/apple/s5l8940x-k93.dts | 2 ++ arch/arm/boot/dts/apple/s5l8942x-p105.dts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/arm/boot/dts/apple/s5l8940x-k93.dts b/arch/arm/boot/dts/apple/s5l8940x-k93.dts index 97eea9ad4f7ac0..94ba8899da5e2d 100644 --- a/arch/arm/boot/dts/apple/s5l8940x-k93.dts +++ b/arch/arm/boot/dts/apple/s5l8940x-k93.dts @@ -200,12 +200,14 @@ gpios = <&gpio 0 1>; linux,code = <172>; debounce-interval = <20>; + wakeup-source; }; hold { label = "Hold"; gpios = <&gpio 1 1>; linux,code = <116>; debounce-interval = <20>; + wakeup-source; }; volume-up { label = "Volume Up"; diff --git a/arch/arm/boot/dts/apple/s5l8942x-p105.dts b/arch/arm/boot/dts/apple/s5l8942x-p105.dts index e9770e716a3e44..26d41950c9c7dd 100644 --- a/arch/arm/boot/dts/apple/s5l8942x-p105.dts +++ b/arch/arm/boot/dts/apple/s5l8942x-p105.dts @@ -319,12 +319,14 @@ gpios = <&gpio 0 1>; linux,code = <172>; debounce-interval = <20>; + wakeup-source; }; hold { label = "Hold"; gpios = <&gpio 1 1>; linux,code = <116>; debounce-interval = <20>; + wakeup-source; }; volume-up { label = "Volume Up";