1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
6 #include <asm/firmware.h>
7 #include <linux/tick.h>
8 #include <linux/cpuidle.h>
9 #include <linux/cpu_pm.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
13 #include <linux/firmware/trusted_foundations.h>
15 #include <asm/cpuidle.h>
16 #include <asm/smp_plat.h>
17 #include <asm/suspend.h>
24 #ifdef CONFIG_PM_SLEEP
25 #define TEGRA114_MAX_STATES 2
27 #define TEGRA114_MAX_STATES 1
30 #ifdef CONFIG_PM_SLEEP
31 static int tegra114_idle_power_down(struct cpuidle_device
*dev
,
32 struct cpuidle_driver
*drv
,
37 tegra_set_cpu_in_lp2();
40 call_firmware_op(prepare_idle
, TF_PM_MODE_LP2_NOFLUSH_L2
);
42 /* Do suspend by ourselves if the firmware does not implement it */
43 if (call_firmware_op(do_idle
, 0) == -ENOSYS
)
44 cpu_suspend(0, tegra30_sleep_cpu_secondary_finish
);
47 tegra_clear_cpu_in_lp2();
54 static void tegra114_idle_enter_s2idle(struct cpuidle_device
*dev
,
55 struct cpuidle_driver
*drv
,
58 tegra114_idle_power_down(dev
, drv
, index
);
62 static struct cpuidle_driver tegra_idle_driver
= {
65 .state_count
= TEGRA114_MAX_STATES
,
67 [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
68 #ifdef CONFIG_PM_SLEEP
70 .enter
= tegra114_idle_power_down
,
71 .enter_s2idle
= tegra114_idle_enter_s2idle
,
73 .target_residency
= 1000,
74 .flags
= CPUIDLE_FLAG_TIMER_STOP
,
76 .name
= "powered-down",
77 .desc
= "CPU power gated",
83 int __init
tegra114_cpuidle_init(void)
85 if (!psci_smp_available())
86 return cpuidle_register(&tegra_idle_driver
, NULL
);