blob: 4bde04f99e38ceda85fd4cb43f89bf2eb080ead7 [file] [log] [blame]
Shawn Guo9fbbe682011-09-06 14:39:44 +08001/*
2 * Copyright 2011 Freescale Semiconductor, Inc.
3 * Copyright 2011 Linaro Ltd.
4 *
5 * The code contained herein is licensed under the GNU General Public
6 * License. You may obtain a copy of the GNU General Public License
7 * Version 2 or later at the following locations:
8 *
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
11 */
12
13#include <linux/init.h>
14#include <linux/io.h>
15#include <linux/of.h>
16#include <linux/of_address.h>
Will Deaconeaa142c2011-08-09 12:24:07 +010017#include <linux/smp.h>
Shawn Guo9fbbe682011-09-06 14:39:44 +080018#include <asm/unified.h>
19
20#define SRC_SCR 0x000
21#define SRC_GPR1 0x020
Shawn Guo0575fb72011-12-09 00:51:26 +010022#define BP_SRC_SCR_WARM_RESET_ENABLE 0
Shawn Guo9fbbe682011-09-06 14:39:44 +080023#define BP_SRC_SCR_CORE1_RST 14
24#define BP_SRC_SCR_CORE1_ENABLE 22
25
26static void __iomem *src_base;
27
Will Deaconeaa142c2011-08-09 12:24:07 +010028#ifndef CONFIG_SMP
29#define cpu_logical_map(cpu) 0
30#endif
31
Shawn Guo9fbbe682011-09-06 14:39:44 +080032void imx_enable_cpu(int cpu, bool enable)
33{
34 u32 mask, val;
35
Will Deaconeaa142c2011-08-09 12:24:07 +010036 cpu = cpu_logical_map(cpu);
Shawn Guo9fbbe682011-09-06 14:39:44 +080037 mask = 1 << (BP_SRC_SCR_CORE1_ENABLE + cpu - 1);
38 val = readl_relaxed(src_base + SRC_SCR);
39 val = enable ? val | mask : val & ~mask;
40 writel_relaxed(val, src_base + SRC_SCR);
41}
42
43void imx_set_cpu_jump(int cpu, void *jump_addr)
44{
Will Deaconeaa142c2011-08-09 12:24:07 +010045 cpu = cpu_logical_map(cpu);
Shawn Guo9fbbe682011-09-06 14:39:44 +080046 writel_relaxed(BSYM(virt_to_phys(jump_addr)),
47 src_base + SRC_GPR1 + cpu * 8);
48}
49
Shawn Guo0575fb72011-12-09 00:51:26 +010050void imx_src_prepare_restart(void)
51{
52 u32 val;
53
54 /* clear enable bits of secondary cores */
55 val = readl_relaxed(src_base + SRC_SCR);
56 val &= ~(0x7 << BP_SRC_SCR_CORE1_ENABLE);
57 writel_relaxed(val, src_base + SRC_SCR);
58
59 /* clear persistent entry register of primary core */
60 writel_relaxed(0, src_base + SRC_GPR1);
61}
62
Shawn Guo9fbbe682011-09-06 14:39:44 +080063void __init imx_src_init(void)
64{
65 struct device_node *np;
Shawn Guo0575fb72011-12-09 00:51:26 +010066 u32 val;
Shawn Guo9fbbe682011-09-06 14:39:44 +080067
68 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-src");
69 src_base = of_iomap(np, 0);
70 WARN_ON(!src_base);
Shawn Guo0575fb72011-12-09 00:51:26 +010071
72 /*
73 * force warm reset sources to generate cold reset
74 * for a more reliable restart
75 */
76 val = readl_relaxed(src_base + SRC_SCR);
77 val &= ~(1 << BP_SRC_SCR_WARM_RESET_ENABLE);
78 writel_relaxed(val, src_base + SRC_SCR);
Shawn Guo9fbbe682011-09-06 14:39:44 +080079}