Skip to content
Merged
2 changes: 2 additions & 0 deletions arch/arm/boot/dts/apple/s5l8940x-k93.dts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/boot/dts/apple/s5l8942x-p105.dts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion arch/arm/configs/orchard_applearmv7_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions arch/arm/mach-apple/apple_wdt_clkevt.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <linux/printk.h>
#include <linux/reboot.h>
#include <linux/seq_file.h>
#include <linux/suspend.h>
#include <linux/sched_clock.h>
#include <linux/watchdog.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions drivers/cpuidle/Kconfig.arm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions drivers/cpuidle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
78 changes: 78 additions & 0 deletions drivers/cpuidle/cpuidle-apple-s5l.c
Original file line number Diff line number Diff line change
@@ -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 <linux/cpu.h>
#include <linux/cpuidle.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>

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");
24 changes: 24 additions & 0 deletions drivers/irqchip/irq-apple-aic1.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <linux/bitfield.h>
#include <linux/bits.h>
#include <linux/clockchips.h>
#include <linux/clocksource.h>
#include <linux/cpuhotplug.h>
#include <linux/cpumask.h>
#include <linux/delay.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
8 changes: 8 additions & 0 deletions drivers/pinctrl/pinctrl-s5l8940x-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions drivers/power/supply/apple-pmu-charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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",
Expand Down
Loading