blob: e4d6af2fdec716ae36028f8e060dda92fb5127d2 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Lorenzo Pieralisid64f84f2014-07-17 10:30:07 +01002/*
3 * ARM64 CPU idle arch support
4 *
5 * Copyright (C) 2014 ARM Ltd.
6 * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Lorenzo Pieralisid64f84f2014-07-17 10:30:07 +01007 */
8
Sudeep Holla5a611ed2016-07-19 18:52:58 +01009#include <linux/acpi.h>
10#include <linux/cpuidle.h>
11#include <linux/cpu_pm.h>
Lorenzo Pieralisid64f84f2014-07-17 10:30:07 +010012#include <linux/of.h>
13#include <linux/of_device.h>
Lorenzo Pieralisi78896142019-08-09 12:03:11 +010014#include <linux/psci.h>
Lorenzo Pieralisid64f84f2014-07-17 10:30:07 +010015
16#include <asm/cpuidle.h>
17#include <asm/cpu_ops.h>
18
Sudeep Hollace3ad712016-07-19 18:52:55 +010019int arm_cpuidle_init(unsigned int cpu)
Lorenzo Pieralisid64f84f2014-07-17 10:30:07 +010020{
21 int ret = -EOPNOTSUPP;
Lorenzo Pieralisid64f84f2014-07-17 10:30:07 +010022
Jisheng Zhangb5fda7e2016-03-25 11:08:55 +080023 if (cpu_ops[cpu] && cpu_ops[cpu]->cpu_suspend &&
24 cpu_ops[cpu]->cpu_init_idle)
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +010025 ret = cpu_ops[cpu]->cpu_init_idle(cpu);
Lorenzo Pieralisid64f84f2014-07-17 10:30:07 +010026
Lorenzo Pieralisid64f84f2014-07-17 10:30:07 +010027 return ret;
28}
Lorenzo Pieralisiaf3cfdb2015-01-26 18:33:44 +000029
30/**
Geert Uytterhoeven0e4c0e62017-02-17 15:25:08 +010031 * arm_cpuidle_suspend() - function to enter a low-power idle state
Lorenzo Pieralisiaf3cfdb2015-01-26 18:33:44 +000032 * @arg: argument to pass to CPU suspend operations
33 *
34 * Return: 0 on success, -EOPNOTSUPP if CPU suspend hook not initialized, CPU
35 * operations back-end error code otherwise.
36 */
Sudeep Hollaaf391b12015-06-18 15:41:32 +010037int arm_cpuidle_suspend(int index)
Lorenzo Pieralisiaf3cfdb2015-01-26 18:33:44 +000038{
39 int cpu = smp_processor_id();
40
Sudeep Hollaaf391b12015-06-18 15:41:32 +010041 return cpu_ops[cpu]->cpu_suspend(index);
Lorenzo Pieralisiaf3cfdb2015-01-26 18:33:44 +000042}
Sudeep Holla5a611ed2016-07-19 18:52:58 +010043
44#ifdef CONFIG_ACPI
45
46#include <acpi/processor.h>
47
Prashanth Prakash8b9951e2017-11-15 10:11:50 -070048#define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags))
49
Lorenzo Pieralisi9ffeb6d2019-08-09 12:03:12 +010050static int psci_acpi_cpu_init_idle(unsigned int cpu)
51{
52 int i, count;
53 struct acpi_lpi_state *lpi;
54 struct acpi_processor *pr = per_cpu(processors, cpu);
55
56 /*
57 * If the PSCI cpu_suspend function hook has not been initialized
58 * idle states must not be enabled, so bail out
59 */
60 if (!psci_ops.cpu_suspend)
61 return -EOPNOTSUPP;
62
63 if (unlikely(!pr || !pr->flags.has_lpi))
64 return -EINVAL;
65
66 count = pr->power.count - 1;
67 if (count <= 0)
68 return -ENODEV;
69
70 for (i = 0; i < count; i++) {
71 u32 state;
72
73 lpi = &pr->power.lpi_states[i + 1];
74 /*
75 * Only bits[31:0] represent a PSCI power_state while
76 * bits[63:32] must be 0x0 as per ARM ACPI FFH Specification
77 */
78 state = lpi->address;
79 if (!psci_power_state_is_valid(state)) {
80 pr_warn("Invalid PSCI power state %#x\n", state);
81 return -EINVAL;
82 }
83 }
84
85 return 0;
86}
87
Sudeep Holla5a611ed2016-07-19 18:52:58 +010088int acpi_processor_ffh_lpi_probe(unsigned int cpu)
89{
Lorenzo Pieralisi9ffeb6d2019-08-09 12:03:12 +010090 return psci_acpi_cpu_init_idle(cpu);
Sudeep Holla5a611ed2016-07-19 18:52:58 +010091}
92
93int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
94{
Lorenzo Pieralisi9ffeb6d2019-08-09 12:03:12 +010095 u32 state = lpi->address;
96
Prashanth Prakash8b9951e2017-11-15 10:11:50 -070097 if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags))
Lorenzo Pieralisi9ffeb6d2019-08-09 12:03:12 +010098 return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(psci_cpu_suspend_enter,
99 lpi->index, state);
Prashanth Prakash8b9951e2017-11-15 10:11:50 -0700100 else
Lorenzo Pieralisi9ffeb6d2019-08-09 12:03:12 +0100101 return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter,
102 lpi->index, state);
Sudeep Holla5a611ed2016-07-19 18:52:58 +0100103}
104#endif