blob: 146fe8e0ae7ce52eea0e960c3c508ebb0a35f3b6 [file] [log] [blame]
Peter De Schrijverb36ab972012-02-10 01:47:45 +02001/*
2 * arch/arm/mach-tegra/reset.c
3 *
4 * Copyright (C) 2011,2012 NVIDIA Corporation.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/init.h>
18#include <linux/io.h>
19#include <linux/cpumask.h>
20#include <linux/bitops.h>
21
22#include <asm/cacheflush.h>
23#include <asm/hardware/cache-l2x0.h>
Alexandre Courbot265c89c2013-11-24 15:30:51 +090024#include <asm/firmware.h>
Peter De Schrijverb36ab972012-02-10 01:47:45 +020025
Stephen Warren2be39c02012-10-04 14:24:09 -060026#include "iomap.h"
Stephen Warrenbb1de882012-10-04 14:16:59 -060027#include "irammap.h"
Peter De Schrijverb36ab972012-02-10 01:47:45 +020028#include "reset.h"
Joseph Lod3f29362012-10-31 17:41:16 +080029#include "sleep.h"
Peter De Schrijverb36ab972012-02-10 01:47:45 +020030#include "fuse.h"
31
32#define TEGRA_IRAM_RESET_BASE (TEGRA_IRAM_BASE + \
33 TEGRA_IRAM_RESET_HANDLER_OFFSET)
34
35static bool is_enabled;
36
Alexandre Courbotad14ece2013-11-24 15:30:50 +090037static void __init tegra_cpu_reset_handler_set(const u32 reset_address)
Peter De Schrijverb36ab972012-02-10 01:47:45 +020038{
Peter De Schrijverb36ab972012-02-10 01:47:45 +020039 void __iomem *evp_cpu_reset =
40 IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE + 0x100);
41 void __iomem *sb_ctrl = IO_ADDRESS(TEGRA_SB_BASE);
42 u32 reg;
43
Peter De Schrijverb36ab972012-02-10 01:47:45 +020044 /*
45 * NOTE: This must be the one and only write to the EVP CPU reset
46 * vector in the entire system.
47 */
Alexandre Courbotad14ece2013-11-24 15:30:50 +090048 writel(reset_address, evp_cpu_reset);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020049 wmb();
50 reg = readl(evp_cpu_reset);
51
52 /*
53 * Prevent further modifications to the physical reset vector.
54 * NOTE: Has no effect on chips prior to Tegra30.
55 */
56 if (tegra_chip_id != TEGRA20) {
57 reg = readl(sb_ctrl);
58 reg |= 2;
59 writel(reg, sb_ctrl);
60 wmb();
61 }
Alexandre Courbotad14ece2013-11-24 15:30:50 +090062}
63
64static void __init tegra_cpu_reset_handler_enable(void)
65{
66 void __iomem *iram_base = IO_ADDRESS(TEGRA_IRAM_RESET_BASE);
67 const u32 reset_address = TEGRA_IRAM_RESET_BASE +
68 tegra_cpu_reset_handler_offset;
Alexandre Courbot265c89c2013-11-24 15:30:51 +090069 int err;
Alexandre Courbotad14ece2013-11-24 15:30:50 +090070
71 BUG_ON(is_enabled);
72 BUG_ON(tegra_cpu_reset_handler_size > TEGRA_IRAM_RESET_HANDLER_SIZE);
73
74 memcpy(iram_base, (void *)__tegra_cpu_reset_handler_start,
75 tegra_cpu_reset_handler_size);
76
Alexandre Courbot265c89c2013-11-24 15:30:51 +090077 err = call_firmware_op(set_cpu_boot_addr, 0, reset_address);
78 switch (err) {
79 case -ENOSYS:
80 tegra_cpu_reset_handler_set(reset_address);
81 /* pass-through */
82 case 0:
83 is_enabled = true;
84 break;
85 default:
86 pr_crit("Cannot set CPU reset handler: %d\n", err);
87 BUG();
88 }
Peter De Schrijverb36ab972012-02-10 01:47:45 +020089}
90
91void __init tegra_cpu_reset_handler_init(void)
92{
93
94#ifdef CONFIG_SMP
95 __tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_PRESENT] =
Joseph Lo9e323662013-01-04 17:32:22 +080096 *((u32 *)cpu_possible_mask);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020097 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_SECONDARY] =
98 virt_to_phys((void *)tegra_secondary_startup);
99#endif
100
Joseph Lod3f29362012-10-31 17:41:16 +0800101#ifdef CONFIG_PM_SLEEP
Joseph Lo5b795d02013-08-12 17:40:00 +0800102 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP1] =
Stephen Warrenfddb7702013-08-20 16:19:15 -0600103 TEGRA_IRAM_LPx_RESUME_AREA;
Joseph Lod3f29362012-10-31 17:41:16 +0800104 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP2] =
105 virt_to_phys((void *)tegra_resume);
106#endif
107
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200108 tegra_cpu_reset_handler_enable();
109}