blob: e55968712706ced993660240b04417ac0a59e5ca [file] [log] [blame]
Magnus Damm77594912009-03-13 15:23:04 +00001/*
Magnus Damm74263942009-07-03 10:28:00 +00002 * arch/sh/kernel/cpu/shmobile/pm.c
Magnus Damm77594912009-03-13 15:23:04 +00003 *
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>
Magnus Damm99675a72009-10-30 04:24:23 +000018#include <asm/cacheflush.h>
Magnus Damm77594912009-03-13 15:23:04 +000019
20/*
Magnus Damm49f42642009-10-29 10:51:48 +000021 * Notifier lists for pre/post sleep notification
22 */
23ATOMIC_NOTIFIER_HEAD(sh_mobile_pre_sleep_notifier_list);
24ATOMIC_NOTIFIER_HEAD(sh_mobile_post_sleep_notifier_list);
25
26/*
Magnus Damm77594912009-03-13 15:23:04 +000027 * Sleep modes available on SuperH Mobile:
28 *
29 * Sleep mode is just plain "sleep" instruction
30 * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh
31 * Standby Self-Refresh mode is above plus stopped clocks
32 */
33#define SUSP_MODE_SLEEP (SUSP_SH_SLEEP)
34#define SUSP_MODE_SLEEP_SF (SUSP_SH_SLEEP | SUSP_SH_SF)
35#define SUSP_MODE_STANDBY_SF (SUSP_SH_STANDBY | SUSP_SH_SF)
Magnus Damm41bfb7d2010-02-25 11:03:24 +000036#define SUSP_MODE_RSTANDBY_SF \
37 (SUSP_SH_RSTANDBY | SUSP_SH_MMU | SUSP_SH_REGS | SUSP_SH_SF)
Magnus Dammbb3e0ee2009-10-30 04:24:40 +000038 /*
39 * U-standby mode is unsupported since it needs bootloader hacks
40 */
Magnus Damm77594912009-03-13 15:23:04 +000041
Magnus Damm03625e72009-10-30 04:24:32 +000042#ifdef CONFIG_CPU_SUBTYPE_SH7724
43#define RAM_BASE 0xfd800000 /* RSMEM */
44#else
45#define RAM_BASE 0xe5200000 /* ILRAM */
46#endif
Magnus Damm74263942009-07-03 10:28:00 +000047
Magnus Damm74263942009-07-03 10:28:00 +000048void sh_mobile_call_standby(unsigned long mode)
Magnus Damm77594912009-03-13 15:23:04 +000049{
Magnus Damm03625e72009-10-30 04:24:32 +000050 void *onchip_mem = (void *)RAM_BASE;
Magnus Damm323ef8d2009-10-30 04:24:07 +000051 struct sh_sleep_data *sdp = onchip_mem;
52 void (*standby_onchip_mem)(unsigned long, unsigned long);
53
54 /* code located directly after data structure */
55 standby_onchip_mem = (void *)(sdp + 1);
Magnus Damm77594912009-03-13 15:23:04 +000056
Magnus Damm49f42642009-10-29 10:51:48 +000057 atomic_notifier_call_chain(&sh_mobile_pre_sleep_notifier_list,
58 mode, NULL);
59
Magnus Damm99675a72009-10-30 04:24:23 +000060 /* flush the caches if MMU flag is set */
61 if (mode & SUSP_SH_MMU)
62 flush_cache_all();
63
Magnus Damm77594912009-03-13 15:23:04 +000064 /* Let assembly snippet in on-chip memory handle the rest */
Magnus Damm03625e72009-10-30 04:24:32 +000065 standby_onchip_mem(mode, RAM_BASE);
Magnus Damm49f42642009-10-29 10:51:48 +000066
67 atomic_notifier_call_chain(&sh_mobile_post_sleep_notifier_list,
68 mode, NULL);
Magnus Damm77594912009-03-13 15:23:04 +000069}
70
Magnus Damm323ef8d2009-10-30 04:24:07 +000071extern char sh_mobile_sleep_enter_start;
72extern char sh_mobile_sleep_enter_end;
73
74extern char sh_mobile_sleep_resume_start;
75extern char sh_mobile_sleep_resume_end;
76
Magnus Damm02bf8932009-10-30 04:24:15 +000077unsigned long sh_mobile_sleep_supported = SUSP_SH_SLEEP;
78
Magnus Damm159f8cd2009-10-29 10:52:06 +000079void sh_mobile_register_self_refresh(unsigned long flags,
80 void *pre_start, void *pre_end,
81 void *post_start, void *post_end)
82{
Magnus Damm03625e72009-10-30 04:24:32 +000083 void *onchip_mem = (void *)RAM_BASE;
Magnus Damm323ef8d2009-10-30 04:24:07 +000084 void *vp;
85 struct sh_sleep_data *sdp;
86 int n;
87
88 /* part 0: data area */
89 sdp = onchip_mem;
90 sdp->addr.stbcr = 0xa4150020; /* STBCR */
Magnus Dammbb3e0ee2009-10-30 04:24:40 +000091 sdp->addr.bar = 0xa4150040; /* BAR */
Magnus Damm99675a72009-10-30 04:24:23 +000092 sdp->addr.pteh = 0xff000000; /* PTEH */
93 sdp->addr.ptel = 0xff000004; /* PTEL */
94 sdp->addr.ttb = 0xff000008; /* TTB */
95 sdp->addr.tea = 0xff00000c; /* TEA */
96 sdp->addr.mmucr = 0xff000010; /* MMUCR */
97 sdp->addr.ptea = 0xff000034; /* PTEA */
98 sdp->addr.pascr = 0xff000070; /* PASCR */
99 sdp->addr.irmcr = 0xff000078; /* IRMCR */
100 sdp->addr.ccr = 0xff00001c; /* CCR */
101 sdp->addr.ramcr = 0xff000074; /* RAMCR */
Magnus Damm323ef8d2009-10-30 04:24:07 +0000102 vp = sdp + 1;
103
104 /* part 1: common code to enter sleep mode */
105 n = &sh_mobile_sleep_enter_end - &sh_mobile_sleep_enter_start;
106 memcpy(vp, &sh_mobile_sleep_enter_start, n);
107 vp += roundup(n, 4);
108
109 /* part 2: board specific code to enter self-refresh mode */
110 n = pre_end - pre_start;
111 memcpy(vp, pre_start, n);
112 sdp->sf_pre = (unsigned long)vp;
113 vp += roundup(n, 4);
114
115 /* part 3: board specific code to resume from self-refresh mode */
116 n = post_end - post_start;
117 memcpy(vp, post_start, n);
118 sdp->sf_post = (unsigned long)vp;
119 vp += roundup(n, 4);
120
121 /* part 4: common code to resume from sleep mode */
122 WARN_ON(vp > (onchip_mem + 0x600));
123 vp = onchip_mem + 0x600; /* located at interrupt vector */
124 n = &sh_mobile_sleep_resume_end - &sh_mobile_sleep_resume_start;
125 memcpy(vp, &sh_mobile_sleep_resume_start, n);
Magnus Dammbb3e0ee2009-10-30 04:24:40 +0000126 sdp->resume = (unsigned long)vp;
Magnus Damm02bf8932009-10-30 04:24:15 +0000127
128 sh_mobile_sleep_supported |= flags;
Magnus Damm159f8cd2009-10-29 10:52:06 +0000129}
130
Magnus Damm77594912009-03-13 15:23:04 +0000131static int sh_pm_enter(suspend_state_t state)
132{
Magnus Damm02bf8932009-10-30 04:24:15 +0000133 if (!(sh_mobile_sleep_supported & SUSP_MODE_STANDBY_SF))
134 return -ENXIO;
135
Magnus Damm77594912009-03-13 15:23:04 +0000136 local_irq_disable();
137 set_bl_bit();
138 sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);
139 local_irq_disable();
140 clear_bl_bit();
141 return 0;
142}
143
144static struct platform_suspend_ops sh_pm_ops = {
145 .enter = sh_pm_enter,
146 .valid = suspend_valid_only_mem,
147};
148
149static int __init sh_pm_init(void)
150{
151 suspend_set_ops(&sh_pm_ops);
Magnus Damm74263942009-07-03 10:28:00 +0000152 sh_mobile_setup_cpuidle();
Magnus Damm77594912009-03-13 15:23:04 +0000153 return 0;
154}
155
156late_initcall(sh_pm_init);