Joseph Lo | 51dc525 | 2013-01-21 17:49:06 +0800 | [diff] [blame] | 1 | /* |
| 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 Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 17 | #include <asm/firmware.h> |
Thomas Gleixner | a0b4122 | 2015-04-03 02:32:14 +0200 | [diff] [blame] | 18 | #include <linux/tick.h> |
Joseph Lo | 51dc525 | 2013-01-21 17:49:06 +0800 | [diff] [blame] | 19 | #include <linux/cpuidle.h> |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 20 | #include <linux/cpu_pm.h> |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
Joseph Lo | 51dc525 | 2013-01-21 17:49:06 +0800 | [diff] [blame] | 23 | |
| 24 | #include <asm/cpuidle.h> |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 25 | #include <asm/smp_plat.h> |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 26 | #include <asm/suspend.h> |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 27 | |
| 28 | #include "pm.h" |
| 29 | #include "sleep.h" |
| 30 | |
| 31 | #ifdef CONFIG_PM_SLEEP |
| 32 | #define TEGRA114_MAX_STATES 2 |
| 33 | #else |
| 34 | #define TEGRA114_MAX_STATES 1 |
| 35 | #endif |
| 36 | |
| 37 | #ifdef CONFIG_PM_SLEEP |
| 38 | static int tegra114_idle_power_down(struct cpuidle_device *dev, |
| 39 | struct cpuidle_driver *drv, |
| 40 | int index) |
| 41 | { |
| 42 | local_fiq_disable(); |
| 43 | |
| 44 | tegra_set_cpu_in_lp2(); |
| 45 | cpu_pm_enter(); |
| 46 | |
Thomas Gleixner | a0b4122 | 2015-04-03 02:32:14 +0200 | [diff] [blame] | 47 | tick_broadcast_enter(); |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 48 | |
Alexandre Courbot | 338f2aa | 2014-02-12 11:43:44 +0900 | [diff] [blame] | 49 | call_firmware_op(prepare_idle); |
| 50 | |
| 51 | /* Do suspend by ourselves if the firmware does not implement it */ |
Bartlomiej Zolnierkiewicz | 0b7778a | 2014-09-25 17:59:41 +0900 | [diff] [blame] | 52 | if (call_firmware_op(do_idle, 0) == -ENOSYS) |
Alexandre Courbot | 338f2aa | 2014-02-12 11:43:44 +0900 | [diff] [blame] | 53 | cpu_suspend(0, tegra30_sleep_cpu_secondary_finish); |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 54 | |
Thomas Gleixner | a0b4122 | 2015-04-03 02:32:14 +0200 | [diff] [blame] | 55 | tick_broadcast_exit(); |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 56 | |
| 57 | cpu_pm_exit(); |
| 58 | tegra_clear_cpu_in_lp2(); |
| 59 | |
| 60 | local_fiq_enable(); |
| 61 | |
| 62 | return index; |
| 63 | } |
| 64 | #endif |
Joseph Lo | 51dc525 | 2013-01-21 17:49:06 +0800 | [diff] [blame] | 65 | |
| 66 | static struct cpuidle_driver tegra_idle_driver = { |
| 67 | .name = "tegra_idle", |
| 68 | .owner = THIS_MODULE, |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 69 | .state_count = TEGRA114_MAX_STATES, |
Joseph Lo | 51dc525 | 2013-01-21 17:49:06 +0800 | [diff] [blame] | 70 | .states = { |
| 71 | [0] = ARM_CPUIDLE_WFI_STATE_PWR(600), |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 72 | #ifdef CONFIG_PM_SLEEP |
| 73 | [1] = { |
| 74 | .enter = tegra114_idle_power_down, |
| 75 | .exit_latency = 500, |
| 76 | .target_residency = 1000, |
| 77 | .power_usage = 0, |
Joseph Lo | 3045cb3 | 2013-07-19 17:25:26 +0800 | [diff] [blame] | 78 | .name = "powered-down", |
| 79 | .desc = "CPU power gated", |
| 80 | }, |
| 81 | #endif |
Joseph Lo | 51dc525 | 2013-01-21 17:49:06 +0800 | [diff] [blame] | 82 | }, |
| 83 | }; |
| 84 | |
Joseph Lo | 51dc525 | 2013-01-21 17:49:06 +0800 | [diff] [blame] | 85 | int __init tegra114_cpuidle_init(void) |
| 86 | { |
Daniel Lezcano | e158f9d | 2013-04-23 08:54:37 +0000 | [diff] [blame] | 87 | return cpuidle_register(&tegra_idle_driver, NULL); |
Joseph Lo | 51dc525 | 2013-01-21 17:49:06 +0800 | [diff] [blame] | 88 | } |