aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-prima2
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-prima2')
-rw-r--r--arch/arm/mach-prima2/Makefile1
-rw-r--r--arch/arm/mach-prima2/pm.c149
-rw-r--r--arch/arm/mach-prima2/pm.h29
-rw-r--r--arch/arm/mach-prima2/sleep.S64
4 files changed, 243 insertions, 0 deletions
diff --git a/arch/arm/mach-prima2/Makefile b/arch/arm/mach-prima2/Makefile
index f49d70b86854..13dd1604d951 100644
--- a/arch/arm/mach-prima2/Makefile
+++ b/arch/arm/mach-prima2/Makefile
@@ -6,3 +6,4 @@ obj-y += prima2.o
6obj-y += rtciobrg.o 6obj-y += rtciobrg.o
7obj-$(CONFIG_DEBUG_LL) += lluart.o 7obj-$(CONFIG_DEBUG_LL) += lluart.o
8obj-$(CONFIG_CACHE_L2X0) += l2x0.o 8obj-$(CONFIG_CACHE_L2X0) += l2x0.o
9obj-$(CONFIG_SUSPEND) += pm.o sleep.o
diff --git a/arch/arm/mach-prima2/pm.c b/arch/arm/mach-prima2/pm.c
new file mode 100644
index 000000000000..0ba39f3e16ba
--- /dev/null
+++ b/arch/arm/mach-prima2/pm.c
@@ -0,0 +1,149 @@
1/*
2 * power management entry for CSR SiRFprimaII
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/kernel.h>
10#include <linux/suspend.h>
11#include <linux/slab.h>
12#include <linux/of.h>
13#include <linux/of_address.h>
14#include <linux/of_device.h>
15#include <linux/of_platform.h>
16#include <linux/io.h>
17#include <linux/rtc/sirfsoc_rtciobrg.h>
18#include <asm/suspend.h>
19#include <asm/hardware/cache-l2x0.h>
20
21#include "pm.h"
22
23/*
24 * suspend asm codes will access these to make DRAM become self-refresh and
25 * system sleep
26 */
27u32 sirfsoc_pwrc_base;
28void __iomem *sirfsoc_memc_base;
29
30static void sirfsoc_set_wakeup_source(void)
31{
32 u32 pwr_trigger_en_reg;
33 pwr_trigger_en_reg = sirfsoc_rtc_iobrg_readl(sirfsoc_pwrc_base +
34 SIRFSOC_PWRC_TRIGGER_EN);
35#define X_ON_KEY_B (1 << 0)
36 sirfsoc_rtc_iobrg_writel(pwr_trigger_en_reg | X_ON_KEY_B,
37 sirfsoc_pwrc_base + SIRFSOC_PWRC_TRIGGER_EN);
38}
39
40static void sirfsoc_set_sleep_mode(u32 mode)
41{
42 u32 sleep_mode = sirfsoc_rtc_iobrg_readl(sirfsoc_pwrc_base +
43 SIRFSOC_PWRC_PDN_CTRL);
44 sleep_mode &= ~(SIRFSOC_SLEEP_MODE_MASK << 1);
45 sleep_mode |= mode << 1;
46 sirfsoc_rtc_iobrg_writel(sleep_mode, sirfsoc_pwrc_base +
47 SIRFSOC_PWRC_PDN_CTRL);
48}
49
50static int sirfsoc_pre_suspend_power_off(void)
51{
52 u32 wakeup_entry = virt_to_phys(cpu_resume);
53
54 sirfsoc_rtc_iobrg_writel(wakeup_entry, sirfsoc_pwrc_base +
55 SIRFSOC_PWRC_SCRATCH_PAD1);
56
57 sirfsoc_set_wakeup_source();
58
59 sirfsoc_set_sleep_mode(SIRFSOC_DEEP_SLEEP_MODE);
60
61 return 0;
62}
63
64static int sirfsoc_pm_enter(suspend_state_t state)
65{
66 switch (state) {
67 case PM_SUSPEND_MEM:
68 sirfsoc_pre_suspend_power_off();
69
70 outer_flush_all();
71 outer_disable();
72 /* go zzz */
73 cpu_suspend(0, sirfsoc_finish_suspend);
74 break;
75 default:
76 return -EINVAL;
77 }
78 return 0;
79}
80
81static const struct platform_suspend_ops sirfsoc_pm_ops = {
82 .enter = sirfsoc_pm_enter,
83 .valid = suspend_valid_only_mem,
84};
85
86static int __init sirfsoc_pm_init(void)
87{
88 suspend_set_ops(&sirfsoc_pm_ops);
89 return 0;
90}
91late_initcall(sirfsoc_pm_init);
92
93static const struct of_device_id pwrc_ids[] = {
94 { .compatible = "sirf,prima2-pwrc" },
95 {}
96};
97
98static int __init sirfsoc_of_pwrc_init(void)
99{
100 struct device_node *np;
101
102 np = of_find_matching_node(NULL, pwrc_ids);
103 if (!np)
104 panic("unable to find compatible pwrc node in dtb\n");
105
106 /*
107 * pwrc behind rtciobrg is not located in memory space
108 * though the property is named reg. reg only means base
109 * offset for pwrc. then of_iomap is not suitable here.
110 */
111 if (of_property_read_u32(np, "reg", &sirfsoc_pwrc_base))
112 panic("unable to find base address of pwrc node in dtb\n");
113
114 of_node_put(np);
115
116 return 0;
117}
118postcore_initcall(sirfsoc_of_pwrc_init);
119
120static const struct of_device_id memc_ids[] = {
121 { .compatible = "sirf,prima2-memc" },
122 {}
123};
124
125static int __devinit sirfsoc_memc_probe(struct platform_device *op)
126{
127 struct device_node *np = op->dev.of_node;
128
129 sirfsoc_memc_base = of_iomap(np, 0);
130 if (!sirfsoc_memc_base)
131 panic("unable to map memc registers\n");
132
133 return 0;
134}
135
136static struct platform_driver sirfsoc_memc_driver = {
137 .probe = sirfsoc_memc_probe,
138 .driver = {
139 .name = "sirfsoc-memc",
140 .owner = THIS_MODULE,
141 .of_match_table = memc_ids,
142 },
143};
144
145static int __init sirfsoc_memc_init(void)
146{
147 return platform_driver_register(&sirfsoc_memc_driver);
148}
149postcore_initcall(sirfsoc_memc_init);
diff --git a/arch/arm/mach-prima2/pm.h b/arch/arm/mach-prima2/pm.h
new file mode 100644
index 000000000000..bae6d77e01ab
--- /dev/null
+++ b/arch/arm/mach-prima2/pm.h
@@ -0,0 +1,29 @@
1/*
2 * arch/arm/mach-prima2/pm.h
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#ifndef _MACH_PRIMA2_PM_H_
10#define _MACH_PRIMA2_PM_H_
11
12#define SIRFSOC_PWR_SLEEPFORCE 0x01
13
14#define SIRFSOC_SLEEP_MODE_MASK 0x3
15#define SIRFSOC_DEEP_SLEEP_MODE 0x1
16
17#define SIRFSOC_PWRC_PDN_CTRL 0x0
18#define SIRFSOC_PWRC_PON_OFF 0x4
19#define SIRFSOC_PWRC_TRIGGER_EN 0x8
20#define SIRFSOC_PWRC_PIN_STATUS 0x14
21#define SIRFSOC_PWRC_SCRATCH_PAD1 0x18
22#define SIRFSOC_PWRC_SCRATCH_PAD2 0x1C
23
24#ifndef __ASSEMBLY__
25extern int sirfsoc_finish_suspend(unsigned long);
26#endif
27
28#endif
29
diff --git a/arch/arm/mach-prima2/sleep.S b/arch/arm/mach-prima2/sleep.S
new file mode 100644
index 000000000000..0745abc365fc
--- /dev/null
+++ b/arch/arm/mach-prima2/sleep.S
@@ -0,0 +1,64 @@
1/*
2 * sleep mode for CSR SiRFprimaII
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/linkage.h>
10#include <asm/ptrace.h>
11#include <asm/assembler.h>
12
13#include "pm.h"
14
15#define DENALI_CTL_22_OFF 0x58
16#define DENALI_CTL_112_OFF 0x1c0
17
18 .text
19
20ENTRY(sirfsoc_finish_suspend)
21 @ r5: mem controller
22 ldr r0, =sirfsoc_memc_base
23 ldr r5, [r0]
24 @ r6: pwrc base offset
25 ldr r0, =sirfsoc_pwrc_base
26 ldr r6, [r0]
27 @ r7: rtc iobrg controller
28 ldr r0, =sirfsoc_rtciobrg_base
29 ldr r7, [r0]
30
31 @ Read the power control register and set the
32 @ sleep force bit.
33 add r0, r6, #SIRFSOC_PWRC_PDN_CTRL
34 bl __sirfsoc_rtc_iobrg_readl
35 orr r0,r0,#SIRFSOC_PWR_SLEEPFORCE
36 add r1, r6, #SIRFSOC_PWRC_PDN_CTRL
37 bl sirfsoc_rtc_iobrg_pre_writel
38 mov r1, #0x1
39
40 @ read the MEM ctl register and set the self
41 @ refresh bit
42
43 ldr r2, [r5, #DENALI_CTL_22_OFF]
44 orr r2, r2, #0x1
45
46 @ Following code has to run from cache since
47 @ the RAM is going to self refresh mode
48 .align 5
49 str r2, [r5, #DENALI_CTL_22_OFF]
50
511:
52 ldr r4, [r5, #DENALI_CTL_112_OFF]
53 tst r4, #0x1
54 bne 1b
55
56 @ write SLEEPFORCE through rtc iobridge
57
58 str r1, [r7]
59 @ wait rtc io bridge sync
601:
61 ldr r3, [r7]
62 tst r3, #0x01
63 bne 1b
64 b .