Merge tag 'arm-dt-6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-microblaze.git] / arch / arm64 / kernel / cpuidle.c
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 #include <linux/psci.h>
15
16 #ifdef CONFIG_ACPI
17
18 #include <acpi/processor.h>
19
20 #define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags))
21
22 static int psci_acpi_cpu_init_idle(unsigned int cpu)
23 {
24         int i, count;
25         struct acpi_lpi_state *lpi;
26         struct acpi_processor *pr = per_cpu(processors, cpu);
27
28         if (unlikely(!pr || !pr->flags.has_lpi))
29                 return -EINVAL;
30
31         /*
32          * If the PSCI cpu_suspend function hook has not been initialized
33          * idle states must not be enabled, so bail out
34          */
35         if (!psci_ops.cpu_suspend)
36                 return -EOPNOTSUPP;
37
38         count = pr->power.count - 1;
39         if (count <= 0)
40                 return -ENODEV;
41
42         for (i = 0; i < count; i++) {
43                 u32 state;
44
45                 lpi = &pr->power.lpi_states[i + 1];
46                 /*
47                  * Only bits[31:0] represent a PSCI power_state while
48                  * bits[63:32] must be 0x0 as per ARM ACPI FFH Specification
49                  */
50                 state = lpi->address;
51                 if (!psci_power_state_is_valid(state)) {
52                         pr_warn("Invalid PSCI power state %#x\n", state);
53                         return -EINVAL;
54                 }
55         }
56
57         return 0;
58 }
59
60 int acpi_processor_ffh_lpi_probe(unsigned int cpu)
61 {
62         return psci_acpi_cpu_init_idle(cpu);
63 }
64
65 int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
66 {
67         u32 state = lpi->address;
68
69         if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags))
70                 return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(psci_cpu_suspend_enter,
71                                                 lpi->index, state);
72         else
73                 return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter,
74                                              lpi->index, state);
75 }
76 #endif