aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm
diff options
context:
space:
mode:
authorChris Zhong <zyw@rock-chips.com>2014-12-01 03:52:17 -0500
committerHeiko Stuebner <heiko@sntech.de>2014-12-31 10:16:50 -0500
commit9c1ec8e18c210092418d27278a742a2a98eafffe (patch)
treed3b3a6deb200dd0000e900e4a14df3d8bc673654 /arch/arm
parent97bf6af1f928216fd6c5a66e8a57bfa95a659672 (diff)
ARM: rockchip: add suspend and resume for RK3288
It's a basic version of suspend and resume for rockchip, it only support RK3288 now. Signed-off-by: Tony Xie <xxx@rock-chips.com> Signed-off-by: Chris Zhong <zyw@rock-chips.com> Tested-by: Doug Anderson <dianders@chromium.org> Reviewed-by: Doug Anderson <dianders@chromium.org> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Diffstat (limited to 'arch/arm')
-rw-r--r--arch/arm/mach-rockchip/Makefile1
-rw-r--r--arch/arm/mach-rockchip/pm.c260
-rw-r--r--arch/arm/mach-rockchip/pm.h99
-rw-r--r--arch/arm/mach-rockchip/rockchip.c2
-rw-r--r--arch/arm/mach-rockchip/sleep.S73
5 files changed, 435 insertions, 0 deletions
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index b29d8ead4cf2..5c3a9b2de920 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -1,4 +1,5 @@
1CFLAGS_platsmp.o := -march=armv7-a 1CFLAGS_platsmp.o := -march=armv7-a
2 2
3obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip.o 3obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip.o
4obj-$(CONFIG_PM_SLEEP) += pm.o sleep.o
4obj-$(CONFIG_SMP) += headsmp.o platsmp.o 5obj-$(CONFIG_SMP) += headsmp.o platsmp.o
diff --git a/arch/arm/mach-rockchip/pm.c b/arch/arm/mach-rockchip/pm.c
new file mode 100644
index 000000000000..50cb781aaa36
--- /dev/null
+++ b/arch/arm/mach-rockchip/pm.c
@@ -0,0 +1,260 @@
1/*
2 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
3 * Author: Tony Xie <tony.xie@rock-chips.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#include <linux/init.h>
17#include <linux/io.h>
18#include <linux/kernel.h>
19#include <linux/of.h>
20#include <linux/of_address.h>
21#include <linux/regmap.h>
22#include <linux/suspend.h>
23#include <linux/mfd/syscon.h>
24#include <linux/regulator/machine.h>
25
26#include <asm/cacheflush.h>
27#include <asm/tlbflush.h>
28#include <asm/suspend.h>
29
30#include "pm.h"
31
32/* These enum are option of low power mode */
33enum {
34 ROCKCHIP_ARM_OFF_LOGIC_NORMAL = 0,
35 ROCKCHIP_ARM_OFF_LOGIC_DEEP = 1,
36};
37
38struct rockchip_pm_data {
39 const struct platform_suspend_ops *ops;
40 int (*init)(struct device_node *np);
41};
42
43static void __iomem *rk3288_bootram_base;
44static phys_addr_t rk3288_bootram_phy;
45
46static struct regmap *pmu_regmap;
47static struct regmap *sgrf_regmap;
48
49static u32 rk3288_pmu_pwr_mode_con;
50static u32 rk3288_sgrf_soc_con0;
51
52static inline u32 rk3288_l2_config(void)
53{
54 u32 l2ctlr;
55
56 asm("mrc p15, 1, %0, c9, c0, 2" : "=r" (l2ctlr));
57 return l2ctlr;
58}
59
60static void rk3288_config_bootdata(void)
61{
62 rkpm_bootdata_cpusp = rk3288_bootram_phy + (SZ_4K - 8);
63 rkpm_bootdata_cpu_code = virt_to_phys(cpu_resume);
64
65 rkpm_bootdata_l2ctlr_f = 1;
66 rkpm_bootdata_l2ctlr = rk3288_l2_config();
67}
68
69static void rk3288_slp_mode_set(int level)
70{
71 u32 mode_set, mode_set1;
72
73 regmap_read(sgrf_regmap, RK3288_SGRF_SOC_CON0, &rk3288_sgrf_soc_con0);
74
75 regmap_read(pmu_regmap, RK3288_PMU_PWRMODE_CON,
76 &rk3288_pmu_pwr_mode_con);
77
78 /* set bit 8 so that system will resume to FAST_BOOT_ADDR */
79 regmap_write(sgrf_regmap, RK3288_SGRF_SOC_CON0,
80 SGRF_FAST_BOOT_EN | SGRF_FAST_BOOT_EN_WRITE);
81
82 /* booting address of resuming system is from this register value */
83 regmap_write(sgrf_regmap, RK3288_SGRF_FAST_BOOT_ADDR,
84 rk3288_bootram_phy);
85
86 regmap_write(pmu_regmap, RK3288_PMU_WAKEUP_CFG1,
87 PMU_ARMINT_WAKEUP_EN);
88
89 mode_set = BIT(PMU_GLOBAL_INT_DISABLE) | BIT(PMU_L2FLUSH_EN) |
90 BIT(PMU_SREF0_ENTER_EN) | BIT(PMU_SREF1_ENTER_EN) |
91 BIT(PMU_DDR0_GATING_EN) | BIT(PMU_DDR1_GATING_EN) |
92 BIT(PMU_PWR_MODE_EN) | BIT(PMU_CHIP_PD_EN) |
93 BIT(PMU_SCU_EN);
94
95 mode_set1 = BIT(PMU_CLR_CORE) | BIT(PMU_CLR_CPUP);
96
97 if (level == ROCKCHIP_ARM_OFF_LOGIC_DEEP) {
98 /* arm off, logic deep sleep */
99 mode_set |= BIT(PMU_BUS_PD_EN) |
100 BIT(PMU_DDR1IO_RET_EN) | BIT(PMU_DDR0IO_RET_EN) |
101 BIT(PMU_OSC_24M_DIS) | BIT(PMU_PMU_USE_LF) |
102 BIT(PMU_ALIVE_USE_LF) | BIT(PMU_PLL_PD_EN);
103
104 mode_set1 |= BIT(PMU_CLR_ALIVE) | BIT(PMU_CLR_BUS) |
105 BIT(PMU_CLR_PERI) | BIT(PMU_CLR_DMA);
106 } else {
107 /*
108 * arm off, logic normal
109 * if pmu_clk_core_src_gate_en is not set,
110 * wakeup will be error
111 */
112 mode_set |= BIT(PMU_CLK_CORE_SRC_GATE_EN);
113 }
114
115 regmap_write(pmu_regmap, RK3288_PMU_PWRMODE_CON, mode_set);
116 regmap_write(pmu_regmap, RK3288_PMU_PWRMODE_CON1, mode_set1);
117}
118
119static void rk3288_slp_mode_set_resume(void)
120{
121 regmap_write(pmu_regmap, RK3288_PMU_PWRMODE_CON,
122 rk3288_pmu_pwr_mode_con);
123
124 regmap_write(sgrf_regmap, RK3288_SGRF_SOC_CON0,
125 rk3288_sgrf_soc_con0 | SGRF_FAST_BOOT_EN_WRITE);
126}
127
128static int rockchip_lpmode_enter(unsigned long arg)
129{
130 flush_cache_all();
131
132 cpu_do_idle();
133
134 pr_err("%s: Failed to suspend\n", __func__);
135
136 return 1;
137}
138
139static int rk3288_suspend_enter(suspend_state_t state)
140{
141 local_fiq_disable();
142
143 rk3288_slp_mode_set(ROCKCHIP_ARM_OFF_LOGIC_NORMAL);
144
145 cpu_suspend(0, rockchip_lpmode_enter);
146
147 rk3288_slp_mode_set_resume();
148
149 local_fiq_enable();
150
151 return 0;
152}
153
154static int rk3288_suspend_prepare(void)
155{
156 return regulator_suspend_prepare(PM_SUSPEND_MEM);
157}
158
159static void rk3288_suspend_finish(void)
160{
161 if (regulator_suspend_finish())
162 pr_err("%s: Suspend finish failed\n", __func__);
163}
164
165static int rk3288_suspend_init(struct device_node *np)
166{
167 struct device_node *sram_np;
168 struct resource res;
169 int ret;
170
171 pmu_regmap = syscon_node_to_regmap(np);
172 if (IS_ERR(pmu_regmap)) {
173 pr_err("%s: could not find pmu regmap\n", __func__);
174 return PTR_ERR(pmu_regmap);
175 }
176
177 sgrf_regmap = syscon_regmap_lookup_by_compatible(
178 "rockchip,rk3288-sgrf");
179 if (IS_ERR(sgrf_regmap)) {
180 pr_err("%s: could not find sgrf regmap\n", __func__);
181 return PTR_ERR(pmu_regmap);
182 }
183
184 sram_np = of_find_compatible_node(NULL, NULL,
185 "rockchip,rk3288-pmu-sram");
186 if (!sram_np) {
187 pr_err("%s: could not find bootram dt node\n", __func__);
188 return -ENODEV;
189 }
190
191 rk3288_bootram_base = of_iomap(sram_np, 0);
192 if (!rk3288_bootram_base) {
193 pr_err("%s: could not map bootram base\n", __func__);
194 return -ENOMEM;
195 }
196
197 ret = of_address_to_resource(sram_np, 0, &res);
198 if (ret) {
199 pr_err("%s: could not get bootram phy addr\n", __func__);
200 return ret;
201 }
202 rk3288_bootram_phy = res.start;
203
204 of_node_put(sram_np);
205
206 rk3288_config_bootdata();
207
208 /* copy resume code and data to bootsram */
209 memcpy(rk3288_bootram_base, rockchip_slp_cpu_resume,
210 rk3288_bootram_sz);
211
212 return 0;
213}
214
215static const struct platform_suspend_ops rk3288_suspend_ops = {
216 .enter = rk3288_suspend_enter,
217 .valid = suspend_valid_only_mem,
218 .prepare = rk3288_suspend_prepare,
219 .finish = rk3288_suspend_finish,
220};
221
222static const struct rockchip_pm_data rk3288_pm_data __initconst = {
223 .ops = &rk3288_suspend_ops,
224 .init = rk3288_suspend_init,
225};
226
227static const struct of_device_id rockchip_pmu_of_device_ids[] __initconst = {
228 {
229 .compatible = "rockchip,rk3288-pmu",
230 .data = &rk3288_pm_data,
231 },
232 { /* sentinel */ },
233};
234
235void __init rockchip_suspend_init(void)
236{
237 const struct rockchip_pm_data *pm_data;
238 const struct of_device_id *match;
239 struct device_node *np;
240 int ret;
241
242 np = of_find_matching_node_and_match(NULL, rockchip_pmu_of_device_ids,
243 &match);
244 if (!match) {
245 pr_err("Failed to find PMU node\n");
246 return;
247 }
248 pm_data = (struct rockchip_pm_data *) match->data;
249
250 if (pm_data->init) {
251 ret = pm_data->init(np);
252
253 if (ret) {
254 pr_err("%s: matches init error %d\n", __func__, ret);
255 return;
256 }
257 }
258
259 suspend_set_ops(pm_data->ops);
260}
diff --git a/arch/arm/mach-rockchip/pm.h b/arch/arm/mach-rockchip/pm.h
new file mode 100644
index 000000000000..7d752ff39f91
--- /dev/null
+++ b/arch/arm/mach-rockchip/pm.h
@@ -0,0 +1,99 @@
1/*
2 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
3 * Author: Tony Xie <tony.xie@rock-chips.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef __MACH_ROCKCHIP_PM_H
16#define __MACH_ROCKCHIP_PM_H
17
18extern unsigned long rkpm_bootdata_cpusp;
19extern unsigned long rkpm_bootdata_cpu_code;
20extern unsigned long rkpm_bootdata_l2ctlr_f;
21extern unsigned long rkpm_bootdata_l2ctlr;
22extern unsigned long rkpm_bootdata_ddr_code;
23extern unsigned long rkpm_bootdata_ddr_data;
24extern unsigned long rk3288_bootram_sz;
25
26void rockchip_slp_cpu_resume(void);
27void __init rockchip_suspend_init(void);
28
29/****** following is rk3288 defined **********/
30#define RK3288_PMU_WAKEUP_CFG0 0x00
31#define RK3288_PMU_WAKEUP_CFG1 0x04
32#define RK3288_PMU_PWRMODE_CON 0x18
33#define RK3288_PMU_OSC_CNT 0x20
34#define RK3288_PMU_PLL_CNT 0x24
35#define RK3288_PMU_STABL_CNT 0x28
36#define RK3288_PMU_DDR0IO_PWRON_CNT 0x2c
37#define RK3288_PMU_DDR1IO_PWRON_CNT 0x30
38#define RK3288_PMU_CORE_PWRDWN_CNT 0x34
39#define RK3288_PMU_CORE_PWRUP_CNT 0x38
40#define RK3288_PMU_GPU_PWRDWN_CNT 0x3c
41#define RK3288_PMU_GPU_PWRUP_CNT 0x40
42#define RK3288_PMU_WAKEUP_RST_CLR_CNT 0x44
43#define RK3288_PMU_PWRMODE_CON1 0x90
44
45#define RK3288_SGRF_SOC_CON0 (0x0000)
46#define RK3288_SGRF_FAST_BOOT_ADDR (0x0120)
47#define SGRF_FAST_BOOT_EN BIT(8)
48#define SGRF_FAST_BOOT_EN_WRITE BIT(24)
49
50#define RK3288_CRU_MODE_CON 0x50
51#define RK3288_CRU_SEL0_CON 0x60
52#define RK3288_CRU_SEL1_CON 0x64
53#define RK3288_CRU_SEL10_CON 0x88
54#define RK3288_CRU_SEL33_CON 0xe4
55#define RK3288_CRU_SEL37_CON 0xf4
56
57/* PMU_WAKEUP_CFG1 bits */
58#define PMU_ARMINT_WAKEUP_EN BIT(0)
59
60enum rk3288_pwr_mode_con {
61 PMU_PWR_MODE_EN = 0,
62 PMU_CLK_CORE_SRC_GATE_EN,
63 PMU_GLOBAL_INT_DISABLE,
64 PMU_L2FLUSH_EN,
65 PMU_BUS_PD_EN,
66 PMU_A12_0_PD_EN,
67 PMU_SCU_EN,
68 PMU_PLL_PD_EN,
69 PMU_CHIP_PD_EN, /* POWER OFF PIN ENABLE */
70 PMU_PWROFF_COMB,
71 PMU_ALIVE_USE_LF,
72 PMU_PMU_USE_LF,
73 PMU_OSC_24M_DIS,
74 PMU_INPUT_CLAMP_EN,
75 PMU_WAKEUP_RESET_EN,
76 PMU_SREF0_ENTER_EN,
77 PMU_SREF1_ENTER_EN,
78 PMU_DDR0IO_RET_EN,
79 PMU_DDR1IO_RET_EN,
80 PMU_DDR0_GATING_EN,
81 PMU_DDR1_GATING_EN,
82 PMU_DDR0IO_RET_DE_REQ,
83 PMU_DDR1IO_RET_DE_REQ
84};
85
86enum rk3288_pwr_mode_con1 {
87 PMU_CLR_BUS = 0,
88 PMU_CLR_CORE,
89 PMU_CLR_CPUP,
90 PMU_CLR_ALIVE,
91 PMU_CLR_DMA,
92 PMU_CLR_PERI,
93 PMU_CLR_GPU,
94 PMU_CLR_VIDEO,
95 PMU_CLR_HEVC,
96 PMU_CLR_VIO,
97};
98
99#endif /* __MACH_ROCKCHIP_PM_H */
diff --git a/arch/arm/mach-rockchip/rockchip.c b/arch/arm/mach-rockchip/rockchip.c
index d226b71d21d5..2b68a1a70912 100644
--- a/arch/arm/mach-rockchip/rockchip.c
+++ b/arch/arm/mach-rockchip/rockchip.c
@@ -23,9 +23,11 @@
23#include <asm/mach/map.h> 23#include <asm/mach/map.h>
24#include <asm/hardware/cache-l2x0.h> 24#include <asm/hardware/cache-l2x0.h>
25#include "core.h" 25#include "core.h"
26#include "pm.h"
26 27
27static void __init rockchip_dt_init(void) 28static void __init rockchip_dt_init(void)
28{ 29{
30 rockchip_suspend_init();
29 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); 31 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
30 platform_device_register_simple("cpufreq-dt", 0, NULL, 0); 32 platform_device_register_simple("cpufreq-dt", 0, NULL, 0);
31} 33}
diff --git a/arch/arm/mach-rockchip/sleep.S b/arch/arm/mach-rockchip/sleep.S
new file mode 100644
index 000000000000..2eec9a341f05
--- /dev/null
+++ b/arch/arm/mach-rockchip/sleep.S
@@ -0,0 +1,73 @@
1/*
2 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
3 * Author: Tony Xie <tony.xie@rock-chips.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#include <linux/linkage.h>
17#include <asm/assembler.h>
18#include <asm/memory.h>
19
20.data
21/*
22 * this code will be copied from
23 * ddr to sram for system resumeing.
24 * so it is ".data section".
25 */
26.align
27
28ENTRY(rockchip_slp_cpu_resume)
29 setmode PSR_I_BIT | PSR_F_BIT | SVC_MODE, r1 @ set svc, irqs off
30 mrc p15, 0, r1, c0, c0, 5
31 and r1, r1, #0xf
32 cmp r1, #0
33 /* olny cpu0 can continue to run, the others is halt here */
34 beq cpu0run
35secondary_loop:
36 wfe
37 b secondary_loop
38cpu0run:
39 ldr r3, rkpm_bootdata_l2ctlr_f
40 cmp r3, #0
41 beq sp_set
42 ldr r3, rkpm_bootdata_l2ctlr
43 mcr p15, 1, r3, c9, c0, 2
44sp_set:
45 ldr sp, rkpm_bootdata_cpusp
46 ldr r1, rkpm_bootdata_cpu_code
47 bx r1
48ENDPROC(rockchip_slp_cpu_resume)
49
50/* Parameters filled in by the kernel */
51
52/* Flag for whether to restore L2CTLR on resume */
53 .global rkpm_bootdata_l2ctlr_f
54rkpm_bootdata_l2ctlr_f:
55 .long 0
56
57/* Saved L2CTLR to restore on resume */
58 .global rkpm_bootdata_l2ctlr
59rkpm_bootdata_l2ctlr:
60 .long 0
61
62/* CPU resume SP addr */
63 .globl rkpm_bootdata_cpusp
64rkpm_bootdata_cpusp:
65 .long 0
66
67/* CPU resume function (physical address) */
68 .globl rkpm_bootdata_cpu_code
69rkpm_bootdata_cpu_code:
70 .long 0
71
72ENTRY(rk3288_bootram_sz)
73 .word . - rockchip_slp_cpu_resume