blob: 43c695d83f03467eb89e316d29d213385a80b85d [file] [log] [blame]
Joseph Lo51dc5252013-01-21 17:49:06 +08001/*
2 * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
Thierry Redinga0524ac2014-07-11 09:44:49 +020017#include <asm/firmware.h>
Thomas Gleixnera0b41222015-04-03 02:32:14 +020018#include <linux/tick.h>
Joseph Lo51dc5252013-01-21 17:49:06 +080019#include <linux/cpuidle.h>
Joseph Lo3045cb32013-07-19 17:25:26 +080020#include <linux/cpu_pm.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020021#include <linux/kernel.h>
22#include <linux/module.h>
Joseph Lo51dc5252013-01-21 17:49:06 +080023
Thierry Reding4cb5d9e2019-04-10 10:47:28 +020024#include <linux/firmware/trusted_foundations.h>
25
Joseph Lo51dc5252013-01-21 17:49:06 +080026#include <asm/cpuidle.h>
Joseph Lo3045cb32013-07-19 17:25:26 +080027#include <asm/smp_plat.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020028#include <asm/suspend.h>
Thierry Redingfc0cf172015-02-23 15:24:11 +010029#include <asm/psci.h>
Joseph Lo3045cb32013-07-19 17:25:26 +080030
Thierry Reding755c47e2016-04-28 14:52:45 +020031#include "cpuidle.h"
Joseph Lo3045cb32013-07-19 17:25:26 +080032#include "pm.h"
33#include "sleep.h"
34
35#ifdef CONFIG_PM_SLEEP
36#define TEGRA114_MAX_STATES 2
37#else
38#define TEGRA114_MAX_STATES 1
39#endif
40
41#ifdef CONFIG_PM_SLEEP
42static int tegra114_idle_power_down(struct cpuidle_device *dev,
43 struct cpuidle_driver *drv,
44 int index)
45{
46 local_fiq_disable();
47
48 tegra_set_cpu_in_lp2();
49 cpu_pm_enter();
50
Dmitry Osipenko96446e22019-03-18 01:52:05 +030051 call_firmware_op(prepare_idle, TF_PM_MODE_LP2_NOFLUSH_L2);
Alexandre Courbot338f2aad2014-02-12 11:43:44 +090052
53 /* Do suspend by ourselves if the firmware does not implement it */
Bartlomiej Zolnierkiewicz0b7778a2014-09-25 17:59:41 +090054 if (call_firmware_op(do_idle, 0) == -ENOSYS)
Alexandre Courbot338f2aad2014-02-12 11:43:44 +090055 cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
Joseph Lo3045cb32013-07-19 17:25:26 +080056
Joseph Lo3045cb32013-07-19 17:25:26 +080057 cpu_pm_exit();
58 tegra_clear_cpu_in_lp2();
59
60 local_fiq_enable();
61
62 return index;
63}
Tomeu Vizoso1ec0e112015-05-19 16:49:12 +020064
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +020065static void tegra114_idle_enter_s2idle(struct cpuidle_device *dev,
Tomeu Vizoso1ec0e112015-05-19 16:49:12 +020066 struct cpuidle_driver *drv,
67 int index)
68{
69 tegra114_idle_power_down(dev, drv, index);
70}
Joseph Lo3045cb32013-07-19 17:25:26 +080071#endif
Joseph Lo51dc5252013-01-21 17:49:06 +080072
73static struct cpuidle_driver tegra_idle_driver = {
74 .name = "tegra_idle",
75 .owner = THIS_MODULE,
Joseph Lo3045cb32013-07-19 17:25:26 +080076 .state_count = TEGRA114_MAX_STATES,
Joseph Lo51dc5252013-01-21 17:49:06 +080077 .states = {
78 [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
Joseph Lo3045cb32013-07-19 17:25:26 +080079#ifdef CONFIG_PM_SLEEP
80 [1] = {
81 .enter = tegra114_idle_power_down,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +020082 .enter_s2idle = tegra114_idle_enter_s2idle,
Joseph Lo3045cb32013-07-19 17:25:26 +080083 .exit_latency = 500,
84 .target_residency = 1000,
Tomeu Vizoso1ec0e112015-05-19 16:49:12 +020085 .flags = CPUIDLE_FLAG_TIMER_STOP,
Joseph Lo3045cb32013-07-19 17:25:26 +080086 .power_usage = 0,
Joseph Lo3045cb32013-07-19 17:25:26 +080087 .name = "powered-down",
88 .desc = "CPU power gated",
89 },
90#endif
Joseph Lo51dc5252013-01-21 17:49:06 +080091 },
92};
93
Joseph Lo51dc5252013-01-21 17:49:06 +080094int __init tegra114_cpuidle_init(void)
95{
Thierry Redingfc0cf172015-02-23 15:24:11 +010096 if (!psci_smp_available())
97 return cpuidle_register(&tegra_idle_driver, NULL);
98
99 return 0;
Joseph Lo51dc5252013-01-21 17:49:06 +0800100}