1 /* 2 * arch/sh/kernel/cpu/shmobile/pm.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 37 #define ILRAM_BASE 0xe5200000 38 39 extern const unsigned char sh_mobile_standby[]; 40 extern const unsigned int sh_mobile_standby_size; 41 42 void sh_mobile_call_standby(unsigned long mode) 43 { 44 extern void *vbr_base; 45 void *onchip_mem = (void *)ILRAM_BASE; 46 void (*standby_onchip_mem)(unsigned long) = onchip_mem; 47 48 /* Note: Wake up from sleep may generate exceptions! 49 * Setup VBR to point to on-chip ram if self-refresh is 50 * going to be used. 51 */ 52 if (mode & SUSP_SH_SF) 53 asm volatile("ldc %0, vbr" : : "r" (onchip_mem) : "memory"); 54 55 /* Let assembly snippet in on-chip memory handle the rest */ 56 standby_onchip_mem(mode); 57 58 /* Put VBR back in System RAM again */ 59 if (mode & SUSP_SH_SF) 60 asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory"); 61 } 62 63 static int sh_pm_enter(suspend_state_t state) 64 { 65 local_irq_disable(); 66 set_bl_bit(); 67 sh_mobile_call_standby(SUSP_MODE_STANDBY_SF); 68 local_irq_disable(); 69 clear_bl_bit(); 70 return 0; 71 } 72 73 static struct platform_suspend_ops sh_pm_ops = { 74 .enter = sh_pm_enter, 75 .valid = suspend_valid_only_mem, 76 }; 77 78 static int __init sh_pm_init(void) 79 { 80 void *onchip_mem = (void *)ILRAM_BASE; 81 82 /* Copy the assembly snippet to the otherwise ununsed ILRAM */ 83 memcpy(onchip_mem, sh_mobile_standby, sh_mobile_standby_size); 84 wmb(); 85 ctrl_barrier(); 86 87 suspend_set_ops(&sh_pm_ops); 88 sh_mobile_setup_cpuidle(); 89 return 0; 90 } 91 92 late_initcall(sh_pm_init); 93