xref: /openbmc/linux/arch/sh/kernel/cpu/shmobile/pm.c (revision 7426394f)
1e9edb3feSPaul Mundt /*
27426394fSMagnus Damm  * arch/sh/kernel/cpu/shmobile/pm.c
3e9edb3feSPaul Mundt  *
4e9edb3feSPaul Mundt  * Power management support code for SuperH Mobile
5e9edb3feSPaul Mundt  *
6e9edb3feSPaul Mundt  *  Copyright (C) 2009 Magnus Damm
7e9edb3feSPaul Mundt  *
8e9edb3feSPaul Mundt  * This file is subject to the terms and conditions of the GNU General Public
9e9edb3feSPaul Mundt  * License.  See the file "COPYING" in the main directory of this archive
10e9edb3feSPaul Mundt  * for more details.
11e9edb3feSPaul Mundt  */
12e9edb3feSPaul Mundt #include <linux/init.h>
13e9edb3feSPaul Mundt #include <linux/kernel.h>
14e9edb3feSPaul Mundt #include <linux/io.h>
15e9edb3feSPaul Mundt #include <linux/suspend.h>
16e9edb3feSPaul Mundt #include <asm/suspend.h>
17e9edb3feSPaul Mundt #include <asm/uaccess.h>
18e9edb3feSPaul Mundt 
19e9edb3feSPaul Mundt /*
20e9edb3feSPaul Mundt  * Sleep modes available on SuperH Mobile:
21e9edb3feSPaul Mundt  *
22e9edb3feSPaul Mundt  * Sleep mode is just plain "sleep" instruction
23e9edb3feSPaul Mundt  * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh
24e9edb3feSPaul Mundt  * Standby Self-Refresh mode is above plus stopped clocks
25e9edb3feSPaul Mundt  */
26e9edb3feSPaul Mundt #define SUSP_MODE_SLEEP		(SUSP_SH_SLEEP)
27e9edb3feSPaul Mundt #define SUSP_MODE_SLEEP_SF	(SUSP_SH_SLEEP | SUSP_SH_SF)
28e9edb3feSPaul Mundt #define SUSP_MODE_STANDBY_SF	(SUSP_SH_STANDBY | SUSP_SH_SF)
29e9edb3feSPaul Mundt 
30e9edb3feSPaul Mundt /*
31e9edb3feSPaul Mundt  * The following modes are not there yet:
32e9edb3feSPaul Mundt  *
33e9edb3feSPaul Mundt  * R-standby mode is unsupported, but will be added in the future
34e9edb3feSPaul Mundt  * U-standby mode is low priority since it needs bootloader hacks
35e9edb3feSPaul Mundt  */
36e9edb3feSPaul Mundt 
377426394fSMagnus Damm #define ILRAM_BASE 0xe5200000
387426394fSMagnus Damm 
39e9edb3feSPaul Mundt extern const unsigned char sh_mobile_standby[];
40e9edb3feSPaul Mundt extern const unsigned int sh_mobile_standby_size;
41e9edb3feSPaul Mundt 
427426394fSMagnus Damm void sh_mobile_call_standby(unsigned long mode)
43e9edb3feSPaul Mundt {
44e9edb3feSPaul Mundt 	extern void *vbr_base;
457426394fSMagnus Damm 	void *onchip_mem = (void *)ILRAM_BASE;
46e9edb3feSPaul Mundt 	void (*standby_onchip_mem)(unsigned long) = onchip_mem;
47e9edb3feSPaul Mundt 
48e9edb3feSPaul Mundt 	/* Note: Wake up from sleep may generate exceptions!
49e9edb3feSPaul Mundt 	 * Setup VBR to point to on-chip ram if self-refresh is
50e9edb3feSPaul Mundt 	 * going to be used.
51e9edb3feSPaul Mundt 	 */
52e9edb3feSPaul Mundt 	if (mode & SUSP_SH_SF)
53e9edb3feSPaul Mundt 		asm volatile("ldc %0, vbr" : : "r" (onchip_mem) : "memory");
54e9edb3feSPaul Mundt 
55e9edb3feSPaul Mundt 	/* Let assembly snippet in on-chip memory handle the rest */
56e9edb3feSPaul Mundt 	standby_onchip_mem(mode);
57e9edb3feSPaul Mundt 
58e9edb3feSPaul Mundt 	/* Put VBR back in System RAM again */
59e9edb3feSPaul Mundt 	if (mode & SUSP_SH_SF)
60e9edb3feSPaul Mundt 		asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
61e9edb3feSPaul Mundt }
62e9edb3feSPaul Mundt 
63e9edb3feSPaul Mundt static int sh_pm_enter(suspend_state_t state)
64e9edb3feSPaul Mundt {
65e9edb3feSPaul Mundt 	local_irq_disable();
66e9edb3feSPaul Mundt 	set_bl_bit();
67e9edb3feSPaul Mundt 	sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);
68e9edb3feSPaul Mundt 	local_irq_disable();
69e9edb3feSPaul Mundt 	clear_bl_bit();
70e9edb3feSPaul Mundt 	return 0;
71e9edb3feSPaul Mundt }
72e9edb3feSPaul Mundt 
73e9edb3feSPaul Mundt static struct platform_suspend_ops sh_pm_ops = {
74e9edb3feSPaul Mundt 	.enter          = sh_pm_enter,
75e9edb3feSPaul Mundt 	.valid          = suspend_valid_only_mem,
76e9edb3feSPaul Mundt };
77e9edb3feSPaul Mundt 
78e9edb3feSPaul Mundt static int __init sh_pm_init(void)
79e9edb3feSPaul Mundt {
807426394fSMagnus Damm 	void *onchip_mem = (void *)ILRAM_BASE;
817426394fSMagnus Damm 
827426394fSMagnus Damm 	/* Copy the assembly snippet to the otherwise ununsed ILRAM */
837426394fSMagnus Damm 	memcpy(onchip_mem, sh_mobile_standby, sh_mobile_standby_size);
847426394fSMagnus Damm 	wmb();
857426394fSMagnus Damm 	ctrl_barrier();
867426394fSMagnus Damm 
87e9edb3feSPaul Mundt 	suspend_set_ops(&sh_pm_ops);
887426394fSMagnus Damm 	sh_mobile_setup_cpuidle();
89e9edb3feSPaul Mundt 	return 0;
90e9edb3feSPaul Mundt }
91e9edb3feSPaul Mundt 
92e9edb3feSPaul Mundt late_initcall(sh_pm_init);
93