diff options
author | Magnus Damm <damm@igel.co.jp> | 2009-03-13 11:23:04 -0400 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2009-03-16 06:52:53 -0400 |
commit | 7759491274bc5ba7cd72b3b9cc5ec8247b937efb (patch) | |
tree | f6e98001aa8296220e429c30ac3a8cc42b8cc95d /arch | |
parent | 7a516280b6a99634933b417834e178bde8659da1 (diff) |
sh: SuperH Mobile suspend support
This patch contains CONFIG_SUSPEND support to the SuperH
architecture. If enabled, SuperH Mobile processors will
register their suspend callbacks during boot.
To suspend, use "echo mem > /sys/power/state". To allow
wakeup, make sure "/sys/device/platform/../power/wakeup"
contains "enabled". Additional per-device driver patches
are most likely needed.
Signed-off-by: Magnus Damm <damm@igel.co.jp>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/sh/Kconfig | 1 | ||||
-rw-r--r-- | arch/sh/include/asm/suspend.h | 9 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/sh4a/Makefile | 4 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/sh4a/pm-sh_mobile.c | 92 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/sh4a/sleep-sh_mobile.S | 125 |
5 files changed, 231 insertions, 0 deletions
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index adffbf4048b1..a0c879d17fd6 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig | |||
@@ -181,6 +181,7 @@ config CPU_SHX3 | |||
181 | 181 | ||
182 | config ARCH_SHMOBILE | 182 | config ARCH_SHMOBILE |
183 | bool | 183 | bool |
184 | select ARCH_SUSPEND_POSSIBLE | ||
184 | 185 | ||
185 | choice | 186 | choice |
186 | prompt "Processor sub-type selection" | 187 | prompt "Processor sub-type selection" |
diff --git a/arch/sh/include/asm/suspend.h b/arch/sh/include/asm/suspend.h index 5d6d8aba5682..b1b995370e79 100644 --- a/arch/sh/include/asm/suspend.h +++ b/arch/sh/include/asm/suspend.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _ASM_SH_SUSPEND_H | 1 | #ifndef _ASM_SH_SUSPEND_H |
2 | #define _ASM_SH_SUSPEND_H | 2 | #define _ASM_SH_SUSPEND_H |
3 | 3 | ||
4 | #ifndef __ASSEMBLY__ | ||
4 | static inline int arch_prepare_suspend(void) { return 0; } | 5 | static inline int arch_prepare_suspend(void) { return 0; } |
5 | 6 | ||
6 | #include <asm/ptrace.h> | 7 | #include <asm/ptrace.h> |
@@ -9,5 +10,13 @@ struct swsusp_arch_regs { | |||
9 | struct pt_regs user_regs; | 10 | struct pt_regs user_regs; |
10 | unsigned long bank1_regs[8]; | 11 | unsigned long bank1_regs[8]; |
11 | }; | 12 | }; |
13 | #endif | ||
14 | |||
15 | /* flags passed to assembly suspend code */ | ||
16 | #define SUSP_SH_SLEEP (1 << 0) /* Regular sleep mode */ | ||
17 | #define SUSP_SH_STANDBY (1 << 1) /* SH-Mobile Software standby mode */ | ||
18 | #define SUSP_SH_RSTANDBY (1 << 2) /* SH-Mobile R-standby mode */ | ||
19 | #define SUSP_SH_USTANDBY (1 << 3) /* SH-Mobile U-standby mode */ | ||
20 | #define SUSP_SH_SF (1 << 4) /* Enable self-refresh */ | ||
12 | 21 | ||
13 | #endif /* _ASM_SH_SUSPEND_H */ | 22 | #endif /* _ASM_SH_SUSPEND_H */ |
diff --git a/arch/sh/kernel/cpu/sh4a/Makefile b/arch/sh/kernel/cpu/sh4a/Makefile index 1a92361feeb9..09967dc0065a 100644 --- a/arch/sh/kernel/cpu/sh4a/Makefile +++ b/arch/sh/kernel/cpu/sh4a/Makefile | |||
@@ -35,6 +35,10 @@ pinmux-$(CONFIG_CPU_SUBTYPE_SH7723) := pinmux-sh7723.o | |||
35 | pinmux-$(CONFIG_CPU_SUBTYPE_SH7785) := pinmux-sh7785.o | 35 | pinmux-$(CONFIG_CPU_SUBTYPE_SH7785) := pinmux-sh7785.o |
36 | pinmux-$(CONFIG_CPU_SUBTYPE_SH7786) := pinmux-sh7786.o | 36 | pinmux-$(CONFIG_CPU_SUBTYPE_SH7786) := pinmux-sh7786.o |
37 | 37 | ||
38 | # Power Mangement & Sleep mode | ||
39 | pm-$(CONFIG_ARCH_SHMOBILE) := pm-sh_mobile.o sleep-sh_mobile.o | ||
40 | |||
38 | obj-y += $(clock-y) | 41 | obj-y += $(clock-y) |
39 | obj-$(CONFIG_SMP) += $(smp-y) | 42 | obj-$(CONFIG_SMP) += $(smp-y) |
40 | obj-$(CONFIG_GENERIC_GPIO) += $(pinmux-y) | 43 | obj-$(CONFIG_GENERIC_GPIO) += $(pinmux-y) |
44 | obj-$(CONFIG_PM) += $(pm-y) | ||
diff --git a/arch/sh/kernel/cpu/sh4a/pm-sh_mobile.c b/arch/sh/kernel/cpu/sh4a/pm-sh_mobile.c new file mode 100644 index 000000000000..8c067adf6830 --- /dev/null +++ b/arch/sh/kernel/cpu/sh4a/pm-sh_mobile.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | * arch/sh/kernel/cpu/sh4a/pm-sh_mobile.c | ||
3 | * | ||
4 | * Power management support code for SuperH Mobile | ||
5 | * | ||
6 | * Copyright (C) 2009 Magnus Damm | ||
7 | * | ||
8 | * This file is subject to the terms and conditions of the GNU General Public | ||
9 | * License. See the file "COPYING" in the main directory of this archive | ||
10 | * for more details. | ||
11 | */ | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/suspend.h> | ||
16 | #include <asm/suspend.h> | ||
17 | #include <asm/uaccess.h> | ||
18 | |||
19 | /* | ||
20 | * Sleep modes available on SuperH Mobile: | ||
21 | * | ||
22 | * Sleep mode is just plain "sleep" instruction | ||
23 | * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh | ||
24 | * Standby Self-Refresh mode is above plus stopped clocks | ||
25 | */ | ||
26 | #define SUSP_MODE_SLEEP (SUSP_SH_SLEEP) | ||
27 | #define SUSP_MODE_SLEEP_SF (SUSP_SH_SLEEP | SUSP_SH_SF) | ||
28 | #define SUSP_MODE_STANDBY_SF (SUSP_SH_STANDBY | SUSP_SH_SF) | ||
29 | |||
30 | /* | ||
31 | * The following modes are not there yet: | ||
32 | * | ||
33 | * R-standby mode is unsupported, but will be added in the future | ||
34 | * U-standby mode is low priority since it needs bootloader hacks | ||
35 | * | ||
36 | * All modes should be tied in with cpuidle. But before that can | ||
37 | * happen we need to keep track of enabled hardware blocks so we | ||
38 | * can avoid entering sleep modes that stop clocks to hardware | ||
39 | * blocks that are in use even though the cpu core is idle. | ||
40 | */ | ||
41 | |||
42 | extern const unsigned char sh_mobile_standby[]; | ||
43 | extern const unsigned int sh_mobile_standby_size; | ||
44 | |||
45 | static void sh_mobile_call_standby(unsigned long mode) | ||
46 | { | ||
47 | extern void *vbr_base; | ||
48 | void *onchip_mem = (void *)0xe5200000; /* ILRAM */ | ||
49 | void (*standby_onchip_mem)(unsigned long) = onchip_mem; | ||
50 | |||
51 | /* Note: Wake up from sleep may generate exceptions! | ||
52 | * Setup VBR to point to on-chip ram if self-refresh is | ||
53 | * going to be used. | ||
54 | */ | ||
55 | if (mode & SUSP_SH_SF) | ||
56 | asm volatile("ldc %0, vbr" : : "r" (onchip_mem) : "memory"); | ||
57 | |||
58 | /* Copy the assembly snippet to the otherwise ununsed ILRAM */ | ||
59 | memcpy(onchip_mem, sh_mobile_standby, sh_mobile_standby_size); | ||
60 | wmb(); | ||
61 | ctrl_barrier(); | ||
62 | |||
63 | /* Let assembly snippet in on-chip memory handle the rest */ | ||
64 | standby_onchip_mem(mode); | ||
65 | |||
66 | /* Put VBR back in System RAM again */ | ||
67 | if (mode & SUSP_SH_SF) | ||
68 | asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory"); | ||
69 | } | ||
70 | |||
71 | static int sh_pm_enter(suspend_state_t state) | ||
72 | { | ||
73 | local_irq_disable(); | ||
74 | set_bl_bit(); | ||
75 | sh_mobile_call_standby(SUSP_MODE_STANDBY_SF); | ||
76 | local_irq_disable(); | ||
77 | clear_bl_bit(); | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | static struct platform_suspend_ops sh_pm_ops = { | ||
82 | .enter = sh_pm_enter, | ||
83 | .valid = suspend_valid_only_mem, | ||
84 | }; | ||
85 | |||
86 | static int __init sh_pm_init(void) | ||
87 | { | ||
88 | suspend_set_ops(&sh_pm_ops); | ||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | late_initcall(sh_pm_init); | ||
diff --git a/arch/sh/kernel/cpu/sh4a/sleep-sh_mobile.S b/arch/sh/kernel/cpu/sh4a/sleep-sh_mobile.S new file mode 100644 index 000000000000..5d888ef53d82 --- /dev/null +++ b/arch/sh/kernel/cpu/sh4a/sleep-sh_mobile.S | |||
@@ -0,0 +1,125 @@ | |||
1 | /* | ||
2 | * arch/sh/kernel/cpu/sh4a/sleep-sh_mobile.S | ||
3 | * | ||
4 | * Sleep mode and Standby modes support for SuperH Mobile | ||
5 | * | ||
6 | * Copyright (C) 2009 Magnus Damm | ||
7 | * | ||
8 | * This file is subject to the terms and conditions of the GNU General Public | ||
9 | * License. See the file "COPYING" in the main directory of this archive | ||
10 | * for more details. | ||
11 | */ | ||
12 | |||
13 | #include <linux/sys.h> | ||
14 | #include <linux/errno.h> | ||
15 | #include <linux/linkage.h> | ||
16 | #include <asm/asm-offsets.h> | ||
17 | #include <asm/suspend.h> | ||
18 | |||
19 | /* manage self-refresh and enter standby mode. | ||
20 | * this code will be copied to on-chip memory and executed from there. | ||
21 | */ | ||
22 | |||
23 | .balign 4096,0,4096 | ||
24 | ENTRY(sh_mobile_standby) | ||
25 | mov r4, r0 | ||
26 | |||
27 | tst #SUSP_SH_SF, r0 | ||
28 | bt skip_set_sf | ||
29 | |||
30 | /* SDRAM: disable power down and put in self-refresh mode */ | ||
31 | mov.l 1f, r4 | ||
32 | mov.l 2f, r1 | ||
33 | mov.l @r4, r2 | ||
34 | or r1, r2 | ||
35 | mov.l 3f, r3 | ||
36 | and r3, r2 | ||
37 | mov.l r2, @r4 | ||
38 | |||
39 | skip_set_sf: | ||
40 | tst #SUSP_SH_SLEEP, r0 | ||
41 | bt test_standby | ||
42 | |||
43 | /* set mode to "sleep mode" */ | ||
44 | bra do_sleep | ||
45 | mov #0x00, r1 | ||
46 | |||
47 | test_standby: | ||
48 | tst #SUSP_SH_STANDBY, r0 | ||
49 | bt test_rstandby | ||
50 | |||
51 | /* set mode to "software standby mode" */ | ||
52 | bra do_sleep | ||
53 | mov #0x80, r1 | ||
54 | |||
55 | test_rstandby: | ||
56 | tst #SUSP_SH_RSTANDBY, r0 | ||
57 | bt test_ustandby | ||
58 | |||
59 | /* set mode to "r-standby mode" */ | ||
60 | bra do_sleep | ||
61 | mov #0x20, r1 | ||
62 | |||
63 | test_ustandby: | ||
64 | tst #SUSP_SH_USTANDBY, r0 | ||
65 | bt done_sleep | ||
66 | |||
67 | /* set mode to "u-standby mode" */ | ||
68 | mov #0x10, r1 | ||
69 | |||
70 | /* fall-through */ | ||
71 | |||
72 | do_sleep: | ||
73 | /* setup and enter selected standby mode */ | ||
74 | mov.l 5f, r4 | ||
75 | mov.l r1, @r4 | ||
76 | sleep | ||
77 | |||
78 | done_sleep: | ||
79 | /* reset standby mode to sleep mode */ | ||
80 | mov.l 5f, r4 | ||
81 | mov #0x00, r1 | ||
82 | mov.l r1, @r4 | ||
83 | |||
84 | tst #SUSP_SH_SF, r0 | ||
85 | bt skip_restore_sf | ||
86 | |||
87 | /* SDRAM: set auto-refresh mode */ | ||
88 | mov.l 1f, r4 | ||
89 | mov.l @r4, r2 | ||
90 | mov.l 4f, r3 | ||
91 | and r3, r2 | ||
92 | mov.l r2, @r4 | ||
93 | mov.l 6f, r4 | ||
94 | mov.l 7f, r1 | ||
95 | mov.l 8f, r2 | ||
96 | mov.l @r4, r3 | ||
97 | mov #-1, r4 | ||
98 | add r4, r3 | ||
99 | or r2, r3 | ||
100 | mov.l r3, @r1 | ||
101 | skip_restore_sf: | ||
102 | rts | ||
103 | nop | ||
104 | |||
105 | .balign 4 | ||
106 | 1: .long 0xfe400008 /* SDCR0 */ | ||
107 | 2: .long 0x00000400 | ||
108 | 3: .long 0xffff7fff | ||
109 | 4: .long 0xfffffbff | ||
110 | 5: .long 0xa4150020 /* STBCR */ | ||
111 | 6: .long 0xfe40001c /* RTCOR */ | ||
112 | 7: .long 0xfe400018 /* RTCNT */ | ||
113 | 8: .long 0xa55a0000 | ||
114 | |||
115 | /* interrupt vector @ 0x600 */ | ||
116 | .balign 0x400,0,0x400 | ||
117 | .long 0xdeadbeef | ||
118 | .balign 0x200,0,0x200 | ||
119 | /* sh7722 will end up here in sleep mode */ | ||
120 | rte | ||
121 | nop | ||
122 | sh_mobile_standby_end: | ||
123 | |||
124 | ENTRY(sh_mobile_standby_size) | ||
125 | .long sh_mobile_standby_end - sh_mobile_standby | ||