blob: 4e0236c89c5ed2a3dbf8870b48ccb641ae6c2b80 [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>
Philipp Zabel02985b92013-03-28 17:35:19 +010017#include <linux/reset-controller.h>
Will Deaconeaa142c2011-08-09 12:24:07 +010018#include <linux/smp.h>
Will Deaconeb504392012-01-20 12:01:12 +010019#include <asm/smp_plat.h>
Shawn Guo9fbbe682011-09-06 14:39:44 +080020
21#define SRC_SCR 0x000
22#define SRC_GPR1 0x020
Shawn Guo0575fb72011-12-09 00:51:26 +010023#define BP_SRC_SCR_WARM_RESET_ENABLE 0
Philipp Zabel02985b92013-03-28 17:35:19 +010024#define BP_SRC_SCR_SW_GPU_RST 1
25#define BP_SRC_SCR_SW_VPU_RST 2
26#define BP_SRC_SCR_SW_IPU1_RST 3
27#define BP_SRC_SCR_SW_OPEN_VG_RST 4
28#define BP_SRC_SCR_SW_IPU2_RST 12
Shawn Guo9fbbe682011-09-06 14:39:44 +080029#define BP_SRC_SCR_CORE1_RST 14
30#define BP_SRC_SCR_CORE1_ENABLE 22
31
32static void __iomem *src_base;
Philipp Zabel02985b92013-03-28 17:35:19 +010033static DEFINE_SPINLOCK(scr_lock);
34
35static const int sw_reset_bits[5] = {
36 BP_SRC_SCR_SW_GPU_RST,
37 BP_SRC_SCR_SW_VPU_RST,
38 BP_SRC_SCR_SW_IPU1_RST,
39 BP_SRC_SCR_SW_OPEN_VG_RST,
40 BP_SRC_SCR_SW_IPU2_RST
41};
42
43static int imx_src_reset_module(struct reset_controller_dev *rcdev,
44 unsigned long sw_reset_idx)
45{
46 unsigned long timeout;
47 unsigned long flags;
48 int bit;
49 u32 val;
50
51 if (!src_base)
52 return -ENODEV;
53
54 if (sw_reset_idx >= ARRAY_SIZE(sw_reset_bits))
55 return -EINVAL;
56
57 bit = 1 << sw_reset_bits[sw_reset_idx];
58
59 spin_lock_irqsave(&scr_lock, flags);
60 val = readl_relaxed(src_base + SRC_SCR);
61 val |= bit;
62 writel_relaxed(val, src_base + SRC_SCR);
63 spin_unlock_irqrestore(&scr_lock, flags);
64
65 timeout = jiffies + msecs_to_jiffies(1000);
66 while (readl(src_base + SRC_SCR) & bit) {
67 if (time_after(jiffies, timeout))
68 return -ETIME;
69 cpu_relax();
70 }
71
72 return 0;
73}
74
75static struct reset_control_ops imx_src_ops = {
76 .reset = imx_src_reset_module,
77};
78
79static struct reset_controller_dev imx_reset_controller = {
80 .ops = &imx_src_ops,
81 .nr_resets = ARRAY_SIZE(sw_reset_bits),
82};
Shawn Guo9fbbe682011-09-06 14:39:44 +080083
84void imx_enable_cpu(int cpu, bool enable)
85{
86 u32 mask, val;
87
Will Deaconeaa142c2011-08-09 12:24:07 +010088 cpu = cpu_logical_map(cpu);
Shawn Guo9fbbe682011-09-06 14:39:44 +080089 mask = 1 << (BP_SRC_SCR_CORE1_ENABLE + cpu - 1);
Philipp Zabel02985b92013-03-28 17:35:19 +010090 spin_lock(&scr_lock);
Shawn Guo9fbbe682011-09-06 14:39:44 +080091 val = readl_relaxed(src_base + SRC_SCR);
92 val = enable ? val | mask : val & ~mask;
93 writel_relaxed(val, src_base + SRC_SCR);
Philipp Zabel02985b92013-03-28 17:35:19 +010094 spin_unlock(&scr_lock);
Shawn Guo9fbbe682011-09-06 14:39:44 +080095}
96
97void imx_set_cpu_jump(int cpu, void *jump_addr)
98{
Will Deaconeaa142c2011-08-09 12:24:07 +010099 cpu = cpu_logical_map(cpu);
Rob Herring0a60cb12012-01-09 15:41:40 -0600100 writel_relaxed(virt_to_phys(jump_addr),
Shawn Guo9fbbe682011-09-06 14:39:44 +0800101 src_base + SRC_GPR1 + cpu * 8);
102}
103
Shawn Guo2f3edfd2013-03-26 16:46:07 +0800104u32 imx_get_cpu_arg(int cpu)
105{
106 cpu = cpu_logical_map(cpu);
107 return readl_relaxed(src_base + SRC_GPR1 + cpu * 8 + 4);
108}
109
110void imx_set_cpu_arg(int cpu, u32 arg)
111{
112 cpu = cpu_logical_map(cpu);
113 writel_relaxed(arg, src_base + SRC_GPR1 + cpu * 8 + 4);
114}
115
Shawn Guo0575fb72011-12-09 00:51:26 +0100116void imx_src_prepare_restart(void)
117{
118 u32 val;
119
120 /* clear enable bits of secondary cores */
Philipp Zabel02985b92013-03-28 17:35:19 +0100121 spin_lock(&scr_lock);
Shawn Guo0575fb72011-12-09 00:51:26 +0100122 val = readl_relaxed(src_base + SRC_SCR);
123 val &= ~(0x7 << BP_SRC_SCR_CORE1_ENABLE);
124 writel_relaxed(val, src_base + SRC_SCR);
Philipp Zabel02985b92013-03-28 17:35:19 +0100125 spin_unlock(&scr_lock);
Shawn Guo0575fb72011-12-09 00:51:26 +0100126
127 /* clear persistent entry register of primary core */
128 writel_relaxed(0, src_base + SRC_GPR1);
129}
130
Shawn Guo9fbbe682011-09-06 14:39:44 +0800131void __init imx_src_init(void)
132{
133 struct device_node *np;
Shawn Guo0575fb72011-12-09 00:51:26 +0100134 u32 val;
Shawn Guo9fbbe682011-09-06 14:39:44 +0800135
136 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-src");
137 src_base = of_iomap(np, 0);
138 WARN_ON(!src_base);
Shawn Guo0575fb72011-12-09 00:51:26 +0100139
Philipp Zabel02985b92013-03-28 17:35:19 +0100140 imx_reset_controller.of_node = np;
Arnd Bergmann5c5f0422013-04-30 14:58:31 +0200141 if (IS_ENABLED(CONFIG_RESET_CONTROLLER))
142 reset_controller_register(&imx_reset_controller);
Philipp Zabel02985b92013-03-28 17:35:19 +0100143
Shawn Guo0575fb72011-12-09 00:51:26 +0100144 /*
145 * force warm reset sources to generate cold reset
146 * for a more reliable restart
147 */
Philipp Zabel02985b92013-03-28 17:35:19 +0100148 spin_lock(&scr_lock);
Shawn Guo0575fb72011-12-09 00:51:26 +0100149 val = readl_relaxed(src_base + SRC_SCR);
150 val &= ~(1 << BP_SRC_SCR_WARM_RESET_ENABLE);
151 writel_relaxed(val, src_base + SRC_SCR);
Philipp Zabel02985b92013-03-28 17:35:19 +0100152 spin_unlock(&scr_lock);
Shawn Guo9fbbe682011-09-06 14:39:44 +0800153}