1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2011 Freescale Semiconductor, Inc.
4 * Copyright 2011 Linaro Ltd.
7 #include <linux/init.h>
9 #include <linux/iopoll.h>
11 #include <linux/of_address.h>
12 #include <linux/platform_device.h>
13 #include <linux/reset-controller.h>
14 #include <linux/smp.h>
15 #include <asm/smp_plat.h>
20 #define SRC_GPR1_V1 0x020
21 #define SRC_GPR1_V2 0x074
22 #define SRC_GPR1(gpr_v2) ((gpr_v2) ? SRC_GPR1_V2 : SRC_GPR1_V1)
23 #define BP_SRC_SCR_WARM_RESET_ENABLE 0
24 #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
29 #define BP_SRC_SCR_CORE1_RST 14
30 #define BP_SRC_SCR_CORE1_ENABLE 22
31 /* below is for i.MX7D */
32 #define SRC_A7RCR1 0x008
33 #define BP_SRC_A7RCR1_A7_CORE1_ENABLE 1
34 #define GPC_CPU_PGC_SW_PUP_REQ 0xf0
35 #define GPC_CPU_PGC_SW_PDN_REQ 0xfc
36 #define GPC_PGC_C1 0x840
37 #define BM_CPU_PGC_SW_PDN_PUP_REQ_CORE1_A7 0x2
39 static void __iomem
*src_base
;
40 static DEFINE_SPINLOCK(scr_lock
);
42 static void __iomem
*gpc_base
;
44 static const int sw_reset_bits
[5] = {
45 BP_SRC_SCR_SW_GPU_RST
,
46 BP_SRC_SCR_SW_VPU_RST
,
47 BP_SRC_SCR_SW_IPU1_RST
,
48 BP_SRC_SCR_SW_OPEN_VG_RST
,
49 BP_SRC_SCR_SW_IPU2_RST
52 static int imx_src_reset_module(struct reset_controller_dev
*rcdev
,
53 unsigned long sw_reset_idx
)
55 unsigned long timeout
;
60 if (sw_reset_idx
>= ARRAY_SIZE(sw_reset_bits
))
63 bit
= 1 << sw_reset_bits
[sw_reset_idx
];
65 spin_lock_irqsave(&scr_lock
, flags
);
66 val
= readl_relaxed(src_base
+ SRC_SCR
);
68 writel_relaxed(val
, src_base
+ SRC_SCR
);
69 spin_unlock_irqrestore(&scr_lock
, flags
);
71 timeout
= jiffies
+ msecs_to_jiffies(1000);
72 while (readl(src_base
+ SRC_SCR
) & bit
) {
73 if (time_after(jiffies
, timeout
))
81 static const struct reset_control_ops imx_src_ops
= {
82 .reset
= imx_src_reset_module
,
85 static void imx_gpcv2_set_m_core_pgc(bool enable
, u32 offset
)
87 writel_relaxed(enable
, gpc_base
+ offset
);
91 * The motivation for bringing up the second i.MX7D core inside the kernel
92 * is that legacy vendor bootloaders usually do not implement PSCI support.
93 * This is a significant blocker for systems in the field that are running old
94 * bootloader versions to upgrade to a modern mainline kernel version, as only
95 * one CPU of the i.MX7D would be brought up.
96 * Bring up the second i.MX7D core inside the kernel to make the migration
97 * path to mainline kernel easier for the existing iMX7D users.
99 void imx_gpcv2_set_core1_pdn_pup_by_software(bool pdn
)
101 u32 reg
= pdn
? GPC_CPU_PGC_SW_PDN_REQ
: GPC_CPU_PGC_SW_PUP_REQ
;
105 imx_gpcv2_set_m_core_pgc(true, GPC_PGC_C1
);
106 val
= readl_relaxed(gpc_base
+ reg
);
107 val
|= BM_CPU_PGC_SW_PDN_PUP_REQ_CORE1_A7
;
108 writel_relaxed(val
, gpc_base
+ reg
);
110 ret
= readl_relaxed_poll_timeout_atomic(gpc_base
+ reg
, pup
,
111 !(pup
& BM_CPU_PGC_SW_PDN_PUP_REQ_CORE1_A7
),
114 pr_err("i.MX7D: CORE1_A7 power up timeout\n");
115 val
&= ~BM_CPU_PGC_SW_PDN_PUP_REQ_CORE1_A7
;
116 writel_relaxed(val
, gpc_base
+ reg
);
119 imx_gpcv2_set_m_core_pgc(false, GPC_PGC_C1
);
122 void imx_enable_cpu(int cpu
, bool enable
)
126 cpu
= cpu_logical_map(cpu
);
127 spin_lock(&scr_lock
);
130 imx_gpcv2_set_core1_pdn_pup_by_software(false);
132 mask
= 1 << (BP_SRC_A7RCR1_A7_CORE1_ENABLE
+ cpu
- 1);
133 val
= readl_relaxed(src_base
+ SRC_A7RCR1
);
134 val
= enable
? val
| mask
: val
& ~mask
;
135 writel_relaxed(val
, src_base
+ SRC_A7RCR1
);
137 mask
= 1 << (BP_SRC_SCR_CORE1_ENABLE
+ cpu
- 1);
138 val
= readl_relaxed(src_base
+ SRC_SCR
);
139 val
= enable
? val
| mask
: val
& ~mask
;
140 val
|= 1 << (BP_SRC_SCR_CORE1_RST
+ cpu
- 1);
141 writel_relaxed(val
, src_base
+ SRC_SCR
);
143 spin_unlock(&scr_lock
);
146 void imx_set_cpu_jump(int cpu
, void *jump_addr
)
148 cpu
= cpu_logical_map(cpu
);
149 writel_relaxed(__pa_symbol(jump_addr
),
150 src_base
+ SRC_GPR1(gpr_v2
) + cpu
* 8);
153 u32
imx_get_cpu_arg(int cpu
)
155 cpu
= cpu_logical_map(cpu
);
156 return readl_relaxed(src_base
+ SRC_GPR1(gpr_v2
) + cpu
* 8 + 4);
159 void imx_set_cpu_arg(int cpu
, u32 arg
)
161 cpu
= cpu_logical_map(cpu
);
162 writel_relaxed(arg
, src_base
+ SRC_GPR1(gpr_v2
) + cpu
* 8 + 4);
165 void __init
imx_src_init(void)
167 struct device_node
*np
;
170 np
= of_find_compatible_node(NULL
, NULL
, "fsl,imx51-src");
173 src_base
= of_iomap(np
, 0);
177 * force warm reset sources to generate cold reset
178 * for a more reliable restart
180 spin_lock(&scr_lock
);
181 val
= readl_relaxed(src_base
+ SRC_SCR
);
182 val
&= ~(1 << BP_SRC_SCR_WARM_RESET_ENABLE
);
183 writel_relaxed(val
, src_base
+ SRC_SCR
);
184 spin_unlock(&scr_lock
);
187 void __init
imx7_src_init(void)
189 struct device_node
*np
;
193 np
= of_find_compatible_node(NULL
, NULL
, "fsl,imx7d-src");
197 src_base
= of_iomap(np
, 0);
201 np
= of_find_compatible_node(NULL
, NULL
, "fsl,imx7d-gpc");
205 gpc_base
= of_iomap(np
, 0);
210 static const struct of_device_id imx_src_dt_ids
[] = {
211 { .compatible
= "fsl,imx51-src" },
215 static int imx_src_probe(struct platform_device
*pdev
)
217 struct reset_controller_dev
*rcdev
;
219 rcdev
= devm_kzalloc(&pdev
->dev
, sizeof(*rcdev
), GFP_KERNEL
);
223 rcdev
->ops
= &imx_src_ops
;
224 rcdev
->dev
= &pdev
->dev
;
225 rcdev
->of_node
= pdev
->dev
.of_node
;
226 rcdev
->nr_resets
= ARRAY_SIZE(sw_reset_bits
);
228 return devm_reset_controller_register(&pdev
->dev
, rcdev
);
231 static struct platform_driver imx_src_driver
= {
234 .of_match_table
= imx_src_dt_ids
,
236 .probe
= imx_src_probe
,
238 builtin_platform_driver(imx_src_driver
);