2013-01-21 17:49:06 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-07-11 15:44:49 +08:00
|
|
|
#include <asm/firmware.h>
|
2015-04-03 08:32:14 +08:00
|
|
|
#include <linux/tick.h>
|
2013-01-21 17:49:06 +08:00
|
|
|
#include <linux/cpuidle.h>
|
2013-07-19 17:25:26 +08:00
|
|
|
#include <linux/cpu_pm.h>
|
2014-07-11 15:44:49 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2013-01-21 17:49:06 +08:00
|
|
|
|
|
|
|
#include <asm/cpuidle.h>
|
2013-07-19 17:25:26 +08:00
|
|
|
#include <asm/smp_plat.h>
|
2014-07-11 15:44:49 +08:00
|
|
|
#include <asm/suspend.h>
|
2015-02-23 22:24:11 +08:00
|
|
|
#include <asm/psci.h>
|
2013-07-19 17:25:26 +08:00
|
|
|
|
2016-04-28 20:52:45 +08:00
|
|
|
#include "cpuidle.h"
|
2013-07-19 17:25:26 +08:00
|
|
|
#include "pm.h"
|
|
|
|
#include "sleep.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
#define TEGRA114_MAX_STATES 2
|
|
|
|
#else
|
|
|
|
#define TEGRA114_MAX_STATES 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int tegra114_idle_power_down(struct cpuidle_device *dev,
|
|
|
|
struct cpuidle_driver *drv,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
local_fiq_disable();
|
|
|
|
|
|
|
|
tegra_set_cpu_in_lp2();
|
|
|
|
cpu_pm_enter();
|
|
|
|
|
2014-02-12 10:43:44 +08:00
|
|
|
call_firmware_op(prepare_idle);
|
|
|
|
|
|
|
|
/* Do suspend by ourselves if the firmware does not implement it */
|
2014-09-25 16:59:41 +08:00
|
|
|
if (call_firmware_op(do_idle, 0) == -ENOSYS)
|
2014-02-12 10:43:44 +08:00
|
|
|
cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
|
2013-07-19 17:25:26 +08:00
|
|
|
|
|
|
|
cpu_pm_exit();
|
|
|
|
tegra_clear_cpu_in_lp2();
|
|
|
|
|
|
|
|
local_fiq_enable();
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
2015-05-19 22:49:12 +08:00
|
|
|
|
2017-08-10 06:14:45 +08:00
|
|
|
static void tegra114_idle_enter_s2idle(struct cpuidle_device *dev,
|
2015-05-19 22:49:12 +08:00
|
|
|
struct cpuidle_driver *drv,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
tegra114_idle_power_down(dev, drv, index);
|
|
|
|
}
|
2013-07-19 17:25:26 +08:00
|
|
|
#endif
|
2013-01-21 17:49:06 +08:00
|
|
|
|
|
|
|
static struct cpuidle_driver tegra_idle_driver = {
|
|
|
|
.name = "tegra_idle",
|
|
|
|
.owner = THIS_MODULE,
|
2013-07-19 17:25:26 +08:00
|
|
|
.state_count = TEGRA114_MAX_STATES,
|
2013-01-21 17:49:06 +08:00
|
|
|
.states = {
|
|
|
|
[0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
|
2013-07-19 17:25:26 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
[1] = {
|
|
|
|
.enter = tegra114_idle_power_down,
|
2017-08-10 06:14:45 +08:00
|
|
|
.enter_s2idle = tegra114_idle_enter_s2idle,
|
2013-07-19 17:25:26 +08:00
|
|
|
.exit_latency = 500,
|
|
|
|
.target_residency = 1000,
|
2015-05-19 22:49:12 +08:00
|
|
|
.flags = CPUIDLE_FLAG_TIMER_STOP,
|
2013-07-19 17:25:26 +08:00
|
|
|
.power_usage = 0,
|
|
|
|
.name = "powered-down",
|
|
|
|
.desc = "CPU power gated",
|
|
|
|
},
|
|
|
|
#endif
|
2013-01-21 17:49:06 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
int __init tegra114_cpuidle_init(void)
|
|
|
|
{
|
2015-02-23 22:24:11 +08:00
|
|
|
if (!psci_smp_available())
|
|
|
|
return cpuidle_register(&tegra_idle_driver, NULL);
|
|
|
|
|
|
|
|
return 0;
|
2013-01-21 17:49:06 +08:00
|
|
|
}
|