2 * arch/sh/kernel/cpu/shmobile/pm.c
4 * Power management support code for SuperH Mobile
6 * Copyright (C) 2009 Magnus Damm
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
12 #include <linux/init.h>
13 #include <linux/kernel.h>
15 #include <linux/suspend.h>
16 #include <asm/suspend.h>
17 #include <asm/uaccess.h>
20 * Notifier lists for pre/post sleep notification
22 ATOMIC_NOTIFIER_HEAD(sh_mobile_pre_sleep_notifier_list);
23 ATOMIC_NOTIFIER_HEAD(sh_mobile_post_sleep_notifier_list);
26 * Sleep modes available on SuperH Mobile:
28 * Sleep mode is just plain "sleep" instruction
29 * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh
30 * Standby Self-Refresh mode is above plus stopped clocks
32 #define SUSP_MODE_SLEEP (SUSP_SH_SLEEP)
33 #define SUSP_MODE_SLEEP_SF (SUSP_SH_SLEEP | SUSP_SH_SF)
34 #define SUSP_MODE_STANDBY_SF (SUSP_SH_STANDBY | SUSP_SH_SF)
37 * The following modes are not there yet:
39 * R-standby mode is unsupported, but will be added in the future
40 * U-standby mode is low priority since it needs bootloader hacks
43 #define ILRAM_BASE 0xe5200000
45 void sh_mobile_call_standby(unsigned long mode)
47 void *onchip_mem = (void *)ILRAM_BASE;
48 struct sh_sleep_data *sdp = onchip_mem;
49 void (*standby_onchip_mem)(unsigned long, unsigned long);
51 /* code located directly after data structure */
52 standby_onchip_mem = (void *)(sdp + 1);
54 atomic_notifier_call_chain(&sh_mobile_pre_sleep_notifier_list,
57 /* Let assembly snippet in on-chip memory handle the rest */
58 standby_onchip_mem(mode, ILRAM_BASE);
60 atomic_notifier_call_chain(&sh_mobile_post_sleep_notifier_list,
64 extern char sh_mobile_sleep_enter_start;
65 extern char sh_mobile_sleep_enter_end;
67 extern char sh_mobile_sleep_resume_start;
68 extern char sh_mobile_sleep_resume_end;
70 unsigned long sh_mobile_sleep_supported = SUSP_SH_SLEEP;
72 void sh_mobile_register_self_refresh(unsigned long flags,
73 void *pre_start, void *pre_end,
74 void *post_start, void *post_end)
76 void *onchip_mem = (void *)ILRAM_BASE;
78 struct sh_sleep_data *sdp;
81 /* part 0: data area */
83 sdp->addr.stbcr = 0xa4150020; /* STBCR */
86 /* part 1: common code to enter sleep mode */
87 n = &sh_mobile_sleep_enter_end - &sh_mobile_sleep_enter_start;
88 memcpy(vp, &sh_mobile_sleep_enter_start, n);
91 /* part 2: board specific code to enter self-refresh mode */
92 n = pre_end - pre_start;
93 memcpy(vp, pre_start, n);
94 sdp->sf_pre = (unsigned long)vp;
97 /* part 3: board specific code to resume from self-refresh mode */
98 n = post_end - post_start;
99 memcpy(vp, post_start, n);
100 sdp->sf_post = (unsigned long)vp;
103 /* part 4: common code to resume from sleep mode */
104 WARN_ON(vp > (onchip_mem + 0x600));
105 vp = onchip_mem + 0x600; /* located at interrupt vector */
106 n = &sh_mobile_sleep_resume_end - &sh_mobile_sleep_resume_start;
107 memcpy(vp, &sh_mobile_sleep_resume_start, n);
109 sh_mobile_sleep_supported |= flags;
112 static int sh_pm_enter(suspend_state_t state)
114 if (!(sh_mobile_sleep_supported & SUSP_MODE_STANDBY_SF))
119 sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);
125 static struct platform_suspend_ops sh_pm_ops = {
126 .enter = sh_pm_enter,
127 .valid = suspend_valid_only_mem,
130 static int __init sh_pm_init(void)
132 suspend_set_ops(&sh_pm_ops);
133 sh_mobile_setup_cpuidle();
137 late_initcall(sh_pm_init);