blob: d3aa9be16621faa1f6a1e98a4b7f26cb6fe89ce6 [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
24#include <asm/cpuidle.h>
Joseph Lo3045cb32013-07-19 17:25:26 +080025#include <asm/smp_plat.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020026#include <asm/suspend.h>
Thierry Redingfc0cf172015-02-23 15:24:11 +010027#include <asm/psci.h>
Joseph Lo3045cb32013-07-19 17:25:26 +080028
Thierry Reding755c47e2016-04-28 14:52:45 +020029#include "cpuidle.h"
Joseph Lo3045cb32013-07-19 17:25:26 +080030#include "pm.h"
31#include "sleep.h"
32
33#ifdef CONFIG_PM_SLEEP
34#define TEGRA114_MAX_STATES 2
35#else
36#define TEGRA114_MAX_STATES 1
37#endif
38
39#ifdef CONFIG_PM_SLEEP
40static int tegra114_idle_power_down(struct cpuidle_device *dev,
41 struct cpuidle_driver *drv,
42 int index)
43{
44 local_fiq_disable();
45
46 tegra_set_cpu_in_lp2();
47 cpu_pm_enter();
48
Alexandre Courbot338f2aa2014-02-12 11:43:44 +090049 call_firmware_op(prepare_idle);
50
51 /* Do suspend by ourselves if the firmware does not implement it */
Bartlomiej Zolnierkiewicz0b7778a2014-09-25 17:59:41 +090052 if (call_firmware_op(do_idle, 0) == -ENOSYS)
Alexandre Courbot338f2aa2014-02-12 11:43:44 +090053 cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
Joseph Lo3045cb32013-07-19 17:25:26 +080054
Joseph Lo3045cb32013-07-19 17:25:26 +080055 cpu_pm_exit();
56 tegra_clear_cpu_in_lp2();
57
58 local_fiq_enable();
59
60 return index;
61}
Tomeu Vizoso1ec0e112015-05-19 16:49:12 +020062
63static void tegra114_idle_enter_freeze(struct cpuidle_device *dev,
64 struct cpuidle_driver *drv,
65 int index)
66{
67 tegra114_idle_power_down(dev, drv, index);
68}
Joseph Lo3045cb32013-07-19 17:25:26 +080069#endif
Joseph Lo51dc5252013-01-21 17:49:06 +080070
71static struct cpuidle_driver tegra_idle_driver = {
72 .name = "tegra_idle",
73 .owner = THIS_MODULE,
Joseph Lo3045cb32013-07-19 17:25:26 +080074 .state_count = TEGRA114_MAX_STATES,
Joseph Lo51dc5252013-01-21 17:49:06 +080075 .states = {
76 [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
Joseph Lo3045cb32013-07-19 17:25:26 +080077#ifdef CONFIG_PM_SLEEP
78 [1] = {
79 .enter = tegra114_idle_power_down,
Tomeu Vizoso1ec0e112015-05-19 16:49:12 +020080 .enter_freeze = tegra114_idle_enter_freeze,
Joseph Lo3045cb32013-07-19 17:25:26 +080081 .exit_latency = 500,
82 .target_residency = 1000,
Tomeu Vizoso1ec0e112015-05-19 16:49:12 +020083 .flags = CPUIDLE_FLAG_TIMER_STOP,
Joseph Lo3045cb32013-07-19 17:25:26 +080084 .power_usage = 0,
Joseph Lo3045cb32013-07-19 17:25:26 +080085 .name = "powered-down",
86 .desc = "CPU power gated",
87 },
88#endif
Joseph Lo51dc5252013-01-21 17:49:06 +080089 },
90};
91
Joseph Lo51dc5252013-01-21 17:49:06 +080092int __init tegra114_cpuidle_init(void)
93{
Thierry Redingfc0cf172015-02-23 15:24:11 +010094 if (!psci_smp_available())
95 return cpuidle_register(&tegra_idle_driver, NULL);
96
97 return 0;
Joseph Lo51dc5252013-01-21 17:49:06 +080098}