Release 4.13 arch/arm/mach-tegra/pm.c
  
  
  
/*
 * CPU complex suspend & resume functions for Tegra SoCs
 *
 * Copyright (c) 2009-2012, 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/>.
 */
#include <linux/clk/tegra.h>
#include <linux/cpumask.h>
#include <linux/cpu_pm.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/suspend.h>
#include <soc/tegra/flowctrl.h>
#include <soc/tegra/fuse.h>
#include <soc/tegra/pm.h>
#include <soc/tegra/pmc.h>
#include <asm/cacheflush.h>
#include <asm/idmap.h>
#include <asm/proc-fns.h>
#include <asm/smp_plat.h>
#include <asm/suspend.h>
#include <asm/tlbflush.h>
#include "iomap.h"
#include "pm.h"
#include "reset.h"
#include "sleep.h"
#ifdef CONFIG_PM_SLEEP
static DEFINE_SPINLOCK(tegra_lp2_lock);
static u32 iram_save_size;
static void *iram_save_addr;
struct tegra_lp1_iram tegra_lp1_iram;
void (*tegra_tear_down_cpu)(void);
void (*tegra_sleep_core_finish)(unsigned long v2p);
static int (*tegra_sleep_func)(unsigned long v2p);
static void tegra_tear_down_cpu_init(void)
{
	switch (tegra_get_chip_id()) {
	case TEGRA20:
		if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
			tegra_tear_down_cpu = tegra20_tear_down_cpu;
		break;
	case TEGRA30:
	case TEGRA114:
	case TEGRA124:
		if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) ||
		    IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) ||
		    IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC))
			tegra_tear_down_cpu = tegra30_tear_down_cpu;
		break;
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 59 | 96.72% | 3 | 75.00% | 
| Thierry Reding | 2 | 3.28% | 1 | 25.00% | 
| Total | 61 | 100.00% | 4 | 100.00% | 
/*
 * restore_cpu_complex
 *
 * restores cpu clock setting, clears flow controller
 *
 * Always called on CPU 0.
 */
static void restore_cpu_complex(void)
{
	int cpu = smp_processor_id();
	BUG_ON(cpu != 0);
#ifdef CONFIG_SMP
	cpu = cpu_logical_map(cpu);
#endif
	/* Restore the CPU clock settings */
	tegra_cpu_clock_resume();
	flowctrl_cpu_suspend_exit(cpu);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 42 | 100.00% | 1 | 100.00% | 
| Total | 42 | 100.00% | 1 | 100.00% | 
/*
 * suspend_cpu_complex
 *
 * saves pll state for use by restart_plls, prepares flow controller for
 * transition to suspend state
 *
 * Must always be called on cpu 0.
 */
static void suspend_cpu_complex(void)
{
	int cpu = smp_processor_id();
	BUG_ON(cpu != 0);
#ifdef CONFIG_SMP
	cpu = cpu_logical_map(cpu);
#endif
	/* Save the CPU clock settings */
	tegra_cpu_clock_suspend();
	flowctrl_cpu_suspend_enter(cpu);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 42 | 100.00% | 1 | 100.00% | 
| Total | 42 | 100.00% | 1 | 100.00% | 
void tegra_clear_cpu_in_lp2(void)
{
	int phy_cpu_id = cpu_logical_map(smp_processor_id());
	u32 *cpu_in_lp2 = tegra_cpu_lp2_mask;
	spin_lock(&tegra_lp2_lock);
	BUG_ON(!(*cpu_in_lp2 & BIT(phy_cpu_id)));
	*cpu_in_lp2 &= ~BIT(phy_cpu_id);
	spin_unlock(&tegra_lp2_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 57 | 100.00% | 2 | 100.00% | 
| Total | 57 | 100.00% | 2 | 100.00% | 
bool tegra_set_cpu_in_lp2(void)
{
	int phy_cpu_id = cpu_logical_map(smp_processor_id());
	bool last_cpu = false;
	cpumask_t *cpu_lp2_mask = tegra_cpu_lp2_mask;
	u32 *cpu_in_lp2 = tegra_cpu_lp2_mask;
	spin_lock(&tegra_lp2_lock);
	BUG_ON((*cpu_in_lp2 & BIT(phy_cpu_id)));
	*cpu_in_lp2 |= BIT(phy_cpu_id);
	if ((phy_cpu_id == 0) && cpumask_equal(cpu_lp2_mask, cpu_online_mask))
		last_cpu = true;
	else if (tegra_get_chip_id() == TEGRA20 && phy_cpu_id == 1)
		tegra20_cpu_set_resettable_soon();
	spin_unlock(&tegra_lp2_lock);
	return last_cpu;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 101 | 98.06% | 3 | 75.00% | 
| Thierry Reding | 2 | 1.94% | 1 | 25.00% | 
| Total | 103 | 100.00% | 4 | 100.00% | 
int tegra_cpu_do_idle(void)
{
	return cpu_do_idle();
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Arnd Bergmann | 11 | 100.00% | 1 | 100.00% | 
| Total | 11 | 100.00% | 1 | 100.00% | 
static int tegra_sleep_cpu(unsigned long v2p)
{
	setup_mm_for_reboot();
	tegra_sleep_cpu_finish(v2p);
	/* should never here */
	BUG();
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 24 | 96.00% | 1 | 50.00% | 
| Will Deacon | 1 | 4.00% | 1 | 50.00% | 
| Total | 25 | 100.00% | 2 | 100.00% | 
static void tegra_pm_set(enum tegra_suspend_mode mode)
{
	u32 value;
	switch (tegra_get_chip_id()) {
	case TEGRA20:
	case TEGRA30:
		break;
	default:
		/* Turn off CRAIL */
		value = flowctrl_read_cpu_csr(0);
		value &= ~FLOW_CTRL_CSR_ENABLE_EXT_MASK;
		value |= FLOW_CTRL_CSR_ENABLE_EXT_CRAIL;
		flowctrl_write_cpu_csr(0, value);
		break;
	}
	tegra_pmc_enter_suspend_mode(mode);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Thierry Reding | 58 | 100.00% | 1 | 100.00% | 
| Total | 58 | 100.00% | 1 | 100.00% | 
void tegra_idle_lp2_last(void)
{
	tegra_pm_set(TEGRA_SUSPEND_LP2);
	cpu_cluster_pm_enter();
	suspend_cpu_complex();
	cpu_suspend(PHYS_OFFSET - PAGE_OFFSET, &tegra_sleep_cpu);
	restore_cpu_complex();
	cpu_cluster_pm_exit();
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 33 | 97.06% | 3 | 75.00% | 
| Thierry Reding | 1 | 2.94% | 1 | 25.00% | 
| Total | 34 | 100.00% | 4 | 100.00% | 
enum tegra_suspend_mode tegra_pm_validate_suspend_mode(
				enum tegra_suspend_mode mode)
{
	/*
         * The Tegra devices support suspending to LP1 or lower currently.
         */
	if (mode > TEGRA_SUSPEND_LP1)
		return TEGRA_SUSPEND_LP1;
	return mode;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 23 | 100.00% | 2 | 100.00% | 
| Total | 23 | 100.00% | 2 | 100.00% | 
static int tegra_sleep_core(unsigned long v2p)
{
	setup_mm_for_reboot();
	tegra_sleep_core_finish(v2p);
	/* should never here */
	BUG();
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 25 | 100.00% | 1 | 100.00% | 
| Total | 25 | 100.00% | 1 | 100.00% | 
/*
 * tegra_lp1_iram_hook
 *
 * Hooking the address of LP1 reset vector and SDRAM self-refresh code in
 * SDRAM. These codes not be copied to IRAM in this fuction. We need to
 * copy these code to IRAM before LP0/LP1 suspend and restore the content
 * of IRAM after resume.
 */
static bool tegra_lp1_iram_hook(void)
{
	switch (tegra_get_chip_id()) {
	case TEGRA20:
		if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
			tegra20_lp1_iram_hook();
		break;
	case TEGRA30:
	case TEGRA114:
	case TEGRA124:
		if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) ||
		    IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) ||
		    IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC))
			tegra30_lp1_iram_hook();
		break;
	default:
		break;
	}
	if (!tegra_lp1_iram.start_addr || !tegra_lp1_iram.end_addr)
		return false;
	iram_save_size = tegra_lp1_iram.end_addr - tegra_lp1_iram.start_addr;
	iram_save_addr = kmalloc(iram_save_size, GFP_KERNEL);
	if (!iram_save_addr)
		return false;
	return true;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 104 | 98.11% | 6 | 85.71% | 
| Thierry Reding | 2 | 1.89% | 1 | 14.29% | 
| Total | 106 | 100.00% | 7 | 100.00% | 
static bool tegra_sleep_core_init(void)
{
	switch (tegra_get_chip_id()) {
	case TEGRA20:
		if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
			tegra20_sleep_core_init();
		break;
	case TEGRA30:
	case TEGRA114:
	case TEGRA124:
		if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) ||
		    IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) ||
		    IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC))
			tegra30_sleep_core_init();
		break;
	default:
		break;
	}
	if (!tegra_sleep_core_finish)
		return false;
	return true;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 70 | 97.22% | 5 | 83.33% | 
| Thierry Reding | 2 | 2.78% | 1 | 16.67% | 
| Total | 72 | 100.00% | 6 | 100.00% | 
static void tegra_suspend_enter_lp1(void)
{
	/* copy the reset vector & SDRAM shutdown code into IRAM */
	memcpy(iram_save_addr, IO_ADDRESS(TEGRA_IRAM_LPx_RESUME_AREA),
		iram_save_size);
	memcpy(IO_ADDRESS(TEGRA_IRAM_LPx_RESUME_AREA),
		tegra_lp1_iram.start_addr, iram_save_size);
	*((u32 *)tegra_cpu_lp1_mask) = 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 44 | 95.65% | 1 | 50.00% | 
| Stephen Warren | 2 | 4.35% | 1 | 50.00% | 
| Total | 46 | 100.00% | 2 | 100.00% | 
static void tegra_suspend_exit_lp1(void)
{
	/* restore IRAM */
	memcpy(IO_ADDRESS(TEGRA_IRAM_LPx_RESUME_AREA), iram_save_addr,
		iram_save_size);
	*(u32 *)tegra_cpu_lp1_mask = 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 29 | 96.67% | 1 | 50.00% | 
| Stephen Warren | 1 | 3.33% | 1 | 50.00% | 
| Total | 30 | 100.00% | 2 | 100.00% | 
static const char *lp_state[TEGRA_MAX_SUSPEND_MODE] = {
	[TEGRA_SUSPEND_NONE] = "none",
	[TEGRA_SUSPEND_LP2] = "LP2",
	[TEGRA_SUSPEND_LP1] = "LP1",
	[TEGRA_SUSPEND_LP0] = "LP0",
};
static int tegra_suspend_enter(suspend_state_t state)
{
	enum tegra_suspend_mode mode = tegra_pmc_get_suspend_mode();
	if (WARN_ON(mode < TEGRA_SUSPEND_NONE ||
		    mode >= TEGRA_MAX_SUSPEND_MODE))
		return -EINVAL;
	pr_info("Entering suspend state %s\n", lp_state[mode]);
	tegra_pm_set(mode);
	local_fiq_disable();
	suspend_cpu_complex();
	switch (mode) {
	case TEGRA_SUSPEND_LP1:
		tegra_suspend_enter_lp1();
		break;
	case TEGRA_SUSPEND_LP2:
		tegra_set_cpu_in_lp2();
		break;
	default:
		break;
	}
	cpu_suspend(PHYS_OFFSET - PAGE_OFFSET, tegra_sleep_func);
	switch (mode) {
	case TEGRA_SUSPEND_LP1:
		tegra_suspend_exit_lp1();
		break;
	case TEGRA_SUSPEND_LP2:
		tegra_clear_cpu_in_lp2();
		break;
	default:
		break;
	}
	restore_cpu_complex();
	local_fiq_enable();
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 115 | 99.14% | 4 | 80.00% | 
| Thierry Reding | 1 | 0.86% | 1 | 20.00% | 
| Total | 116 | 100.00% | 5 | 100.00% | 
static const struct platform_suspend_ops tegra_suspend_ops = {
	.valid		= suspend_valid_only_mem,
	.enter		= tegra_suspend_enter,
};
void __init tegra_init_suspend(void)
{
	enum tegra_suspend_mode mode = tegra_pmc_get_suspend_mode();
	if (mode == TEGRA_SUSPEND_NONE)
		return;
	tegra_tear_down_cpu_init();
	if (mode >= TEGRA_SUSPEND_LP1) {
		if (!tegra_lp1_iram_hook() || !tegra_sleep_core_init()) {
			pr_err("%s: unable to allocate memory for SDRAM"
			       "self-refresh -- LP0/LP1 unavailable\n",
			       __func__);
			tegra_pmc_set_suspend_mode(TEGRA_SUSPEND_LP2);
			mode = TEGRA_SUSPEND_LP2;
		}
	}
	/* set up sleep function for cpu_suspend */
	switch (mode) {
	case TEGRA_SUSPEND_LP1:
		tegra_sleep_func = tegra_sleep_core;
		break;
	case TEGRA_SUSPEND_LP2:
		tegra_sleep_func = tegra_sleep_cpu;
		break;
	default:
		break;
	}
	suspend_set_ops(&tegra_suspend_ops);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 93 | 100.00% | 4 | 100.00% | 
| Total | 93 | 100.00% | 4 | 100.00% | 
#endif
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joseph Lo | 1013 | 89.73% | 14 | 60.87% | 
| Thierry Reding | 94 | 8.33% | 3 | 13.04% | 
| Arnd Bergmann | 11 | 0.97% | 1 | 4.35% | 
| Jon Hunter | 3 | 0.27% | 1 | 4.35% | 
| Stephen Warren | 3 | 0.27% | 1 | 4.35% | 
| Tejun Heo | 2 | 0.18% | 1 | 4.35% | 
| Prashant Gaikwad | 2 | 0.18% | 1 | 4.35% | 
| Will Deacon | 1 | 0.09% | 1 | 4.35% | 
| Total | 1129 | 100.00% | 23 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.