xref: /openbmc/linux/arch/arm64/kernel/cpuidle.c (revision 03638e62)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * ARM64 CPU idle arch support
4  *
5  * Copyright (C) 2014 ARM Ltd.
6  * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
7  */
8 
9 #include <linux/acpi.h>
10 #include <linux/cpuidle.h>
11 #include <linux/cpu_pm.h>
12 #include <linux/of.h>
13 #include <linux/of_device.h>
14 
15 #include <asm/cpuidle.h>
16 #include <asm/cpu_ops.h>
17 
18 int arm_cpuidle_init(unsigned int cpu)
19 {
20 	int ret = -EOPNOTSUPP;
21 
22 	if (cpu_ops[cpu] && cpu_ops[cpu]->cpu_suspend &&
23 			cpu_ops[cpu]->cpu_init_idle)
24 		ret = cpu_ops[cpu]->cpu_init_idle(cpu);
25 
26 	return ret;
27 }
28 
29 /**
30  * arm_cpuidle_suspend() - function to enter a low-power idle state
31  * @arg: argument to pass to CPU suspend operations
32  *
33  * Return: 0 on success, -EOPNOTSUPP if CPU suspend hook not initialized, CPU
34  * operations back-end error code otherwise.
35  */
36 int arm_cpuidle_suspend(int index)
37 {
38 	int cpu = smp_processor_id();
39 
40 	return cpu_ops[cpu]->cpu_suspend(index);
41 }
42 
43 #ifdef CONFIG_ACPI
44 
45 #include <acpi/processor.h>
46 
47 #define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags))
48 
49 int acpi_processor_ffh_lpi_probe(unsigned int cpu)
50 {
51 	return arm_cpuidle_init(cpu);
52 }
53 
54 int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
55 {
56 	if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags))
57 		return CPU_PM_CPU_IDLE_ENTER_RETENTION(arm_cpuidle_suspend,
58 						lpi->index);
59 	else
60 		return CPU_PM_CPU_IDLE_ENTER(arm_cpuidle_suspend, lpi->index);
61 }
62 #endif
63