blob: f94fdf89d4575abf86b413f368d9b9870b7d023c [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
Thierry Redinga0524ac2014-07-11 09:44:49 +020017#include <linux/bitops.h>
18#include <linux/cpumask.h>
Peter De Schrijverb36ab972012-02-10 01:47:45 +020019#include <linux/init.h>
20#include <linux/io.h>
Peter De Schrijverb36ab972012-02-10 01:47:45 +020021
Thierry Reding304664e2014-07-11 09:52:41 +020022#include <soc/tegra/fuse.h>
23
Peter De Schrijverb36ab972012-02-10 01:47:45 +020024#include <asm/cacheflush.h>
Alexandre Courbot265c89c2013-11-24 15:30:51 +090025#include <asm/firmware.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020026#include <asm/hardware/cache-l2x0.h>
Peter De Schrijverb36ab972012-02-10 01:47:45 +020027
Thierry Redinga0524ac2014-07-11 09:44:49 +020028#include "fuse.h"
Stephen Warren2be39c02012-10-04 14:24:09 -060029#include "iomap.h"
Stephen Warrenbb1de882012-10-04 14:16:59 -060030#include "irammap.h"
Peter De Schrijverb36ab972012-02-10 01:47:45 +020031#include "reset.h"
Joseph Lod3f29362012-10-31 17:41:16 +080032#include "sleep.h"
Peter De Schrijverb36ab972012-02-10 01:47:45 +020033
34#define TEGRA_IRAM_RESET_BASE (TEGRA_IRAM_BASE + \
35 TEGRA_IRAM_RESET_HANDLER_OFFSET)
36
37static bool is_enabled;
38
Alexandre Courbotad14ece2013-11-24 15:30:50 +090039static void __init tegra_cpu_reset_handler_set(const u32 reset_address)
Peter De Schrijverb36ab972012-02-10 01:47:45 +020040{
Peter De Schrijverb36ab972012-02-10 01:47:45 +020041 void __iomem *evp_cpu_reset =
42 IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE + 0x100);
43 void __iomem *sb_ctrl = IO_ADDRESS(TEGRA_SB_BASE);
44 u32 reg;
45
Peter De Schrijverb36ab972012-02-10 01:47:45 +020046 /*
47 * NOTE: This must be the one and only write to the EVP CPU reset
48 * vector in the entire system.
49 */
Alexandre Courbotad14ece2013-11-24 15:30:50 +090050 writel(reset_address, evp_cpu_reset);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020051 wmb();
52 reg = readl(evp_cpu_reset);
53
54 /*
55 * Prevent further modifications to the physical reset vector.
56 * NOTE: Has no effect on chips prior to Tegra30.
57 */
Thierry Reding304664e2014-07-11 09:52:41 +020058 if (tegra_get_chip_id() != TEGRA20) {
Peter De Schrijverb36ab972012-02-10 01:47:45 +020059 reg = readl(sb_ctrl);
60 reg |= 2;
61 writel(reg, sb_ctrl);
62 wmb();
63 }
Alexandre Courbotad14ece2013-11-24 15:30:50 +090064}
65
66static void __init tegra_cpu_reset_handler_enable(void)
67{
68 void __iomem *iram_base = IO_ADDRESS(TEGRA_IRAM_RESET_BASE);
69 const u32 reset_address = TEGRA_IRAM_RESET_BASE +
70 tegra_cpu_reset_handler_offset;
Alexandre Courbot265c89c2013-11-24 15:30:51 +090071 int err;
Alexandre Courbotad14ece2013-11-24 15:30:50 +090072
73 BUG_ON(is_enabled);
74 BUG_ON(tegra_cpu_reset_handler_size > TEGRA_IRAM_RESET_HANDLER_SIZE);
75
76 memcpy(iram_base, (void *)__tegra_cpu_reset_handler_start,
77 tegra_cpu_reset_handler_size);
78
Alexandre Courbot265c89c2013-11-24 15:30:51 +090079 err = call_firmware_op(set_cpu_boot_addr, 0, reset_address);
80 switch (err) {
81 case -ENOSYS:
82 tegra_cpu_reset_handler_set(reset_address);
83 /* pass-through */
84 case 0:
85 is_enabled = true;
86 break;
87 default:
88 pr_crit("Cannot set CPU reset handler: %d\n", err);
89 BUG();
90 }
Peter De Schrijverb36ab972012-02-10 01:47:45 +020091}
92
93void __init tegra_cpu_reset_handler_init(void)
94{
95
96#ifdef CONFIG_SMP
97 __tegra_cpu_reset_handler_data[TEGRA_RESET_MASK_PRESENT] =
Joseph Lo9e323662013-01-04 17:32:22 +080098 *((u32 *)cpu_possible_mask);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020099 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_SECONDARY] =
100 virt_to_phys((void *)tegra_secondary_startup);
101#endif
102
Joseph Lod3f29362012-10-31 17:41:16 +0800103#ifdef CONFIG_PM_SLEEP
Joseph Lo5b795d02013-08-12 17:40:00 +0800104 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP1] =
Stephen Warrenfddb7702013-08-20 16:19:15 -0600105 TEGRA_IRAM_LPx_RESUME_AREA;
Joseph Lod3f29362012-10-31 17:41:16 +0800106 __tegra_cpu_reset_handler_data[TEGRA_RESET_STARTUP_LP2] =
107 virt_to_phys((void *)tegra_resume);
108#endif
109
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200110 tegra_cpu_reset_handler_enable();
111}