Path: blob/master/arch/sh/kernel/cpu/shmobile/pm.c
17359 views
/*1* arch/sh/kernel/cpu/shmobile/pm.c2*3* Power management support code for SuperH Mobile4*5* Copyright (C) 2009 Magnus Damm6*7* This file is subject to the terms and conditions of the GNU General Public8* License. See the file "COPYING" in the main directory of this archive9* for more details.10*/11#include <linux/init.h>12#include <linux/kernel.h>13#include <linux/io.h>14#include <linux/suspend.h>15#include <asm/suspend.h>16#include <asm/uaccess.h>17#include <asm/cacheflush.h>1819/*20* Notifier lists for pre/post sleep notification21*/22ATOMIC_NOTIFIER_HEAD(sh_mobile_pre_sleep_notifier_list);23ATOMIC_NOTIFIER_HEAD(sh_mobile_post_sleep_notifier_list);2425/*26* Sleep modes available on SuperH Mobile:27*28* Sleep mode is just plain "sleep" instruction29* Sleep Self-Refresh mode is above plus RAM put in Self-Refresh30* Standby Self-Refresh mode is above plus stopped clocks31*/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)35#define SUSP_MODE_RSTANDBY_SF \36(SUSP_SH_RSTANDBY | SUSP_SH_MMU | SUSP_SH_REGS | SUSP_SH_SF)37/*38* U-standby mode is unsupported since it needs bootloader hacks39*/4041#ifdef CONFIG_CPU_SUBTYPE_SH772442#define RAM_BASE 0xfd800000 /* RSMEM */43#else44#define RAM_BASE 0xe5200000 /* ILRAM */45#endif4647void sh_mobile_call_standby(unsigned long mode)48{49void *onchip_mem = (void *)RAM_BASE;50struct sh_sleep_data *sdp = onchip_mem;51void (*standby_onchip_mem)(unsigned long, unsigned long);5253/* code located directly after data structure */54standby_onchip_mem = (void *)(sdp + 1);5556atomic_notifier_call_chain(&sh_mobile_pre_sleep_notifier_list,57mode, NULL);5859/* flush the caches if MMU flag is set */60if (mode & SUSP_SH_MMU)61flush_cache_all();6263/* Let assembly snippet in on-chip memory handle the rest */64standby_onchip_mem(mode, RAM_BASE);6566atomic_notifier_call_chain(&sh_mobile_post_sleep_notifier_list,67mode, NULL);68}6970extern char sh_mobile_sleep_enter_start;71extern char sh_mobile_sleep_enter_end;7273extern char sh_mobile_sleep_resume_start;74extern char sh_mobile_sleep_resume_end;7576unsigned long sh_mobile_sleep_supported = SUSP_SH_SLEEP;7778void sh_mobile_register_self_refresh(unsigned long flags,79void *pre_start, void *pre_end,80void *post_start, void *post_end)81{82void *onchip_mem = (void *)RAM_BASE;83void *vp;84struct sh_sleep_data *sdp;85int n;8687/* part 0: data area */88sdp = onchip_mem;89sdp->addr.stbcr = 0xa4150020; /* STBCR */90sdp->addr.bar = 0xa4150040; /* BAR */91sdp->addr.pteh = 0xff000000; /* PTEH */92sdp->addr.ptel = 0xff000004; /* PTEL */93sdp->addr.ttb = 0xff000008; /* TTB */94sdp->addr.tea = 0xff00000c; /* TEA */95sdp->addr.mmucr = 0xff000010; /* MMUCR */96sdp->addr.ptea = 0xff000034; /* PTEA */97sdp->addr.pascr = 0xff000070; /* PASCR */98sdp->addr.irmcr = 0xff000078; /* IRMCR */99sdp->addr.ccr = 0xff00001c; /* CCR */100sdp->addr.ramcr = 0xff000074; /* RAMCR */101vp = sdp + 1;102103/* part 1: common code to enter sleep mode */104n = &sh_mobile_sleep_enter_end - &sh_mobile_sleep_enter_start;105memcpy(vp, &sh_mobile_sleep_enter_start, n);106vp += roundup(n, 4);107108/* part 2: board specific code to enter self-refresh mode */109n = pre_end - pre_start;110memcpy(vp, pre_start, n);111sdp->sf_pre = (unsigned long)vp;112vp += roundup(n, 4);113114/* part 3: board specific code to resume from self-refresh mode */115n = post_end - post_start;116memcpy(vp, post_start, n);117sdp->sf_post = (unsigned long)vp;118vp += roundup(n, 4);119120/* part 4: common code to resume from sleep mode */121WARN_ON(vp > (onchip_mem + 0x600));122vp = onchip_mem + 0x600; /* located at interrupt vector */123n = &sh_mobile_sleep_resume_end - &sh_mobile_sleep_resume_start;124memcpy(vp, &sh_mobile_sleep_resume_start, n);125sdp->resume = (unsigned long)vp;126127sh_mobile_sleep_supported |= flags;128}129130static int sh_pm_enter(suspend_state_t state)131{132if (!(sh_mobile_sleep_supported & SUSP_MODE_STANDBY_SF))133return -ENXIO;134135local_irq_disable();136set_bl_bit();137sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);138local_irq_disable();139clear_bl_bit();140return 0;141}142143static const struct platform_suspend_ops sh_pm_ops = {144.enter = sh_pm_enter,145.valid = suspend_valid_only_mem,146};147148static int __init sh_pm_init(void)149{150suspend_set_ops(&sh_pm_ops);151sh_mobile_setup_cpuidle();152return 0;153}154155late_initcall(sh_pm_init);156157158