blob: 5cafd35cc411c6a4c17e036007cd9ddcfed3adcc [file] [log] [blame]
Magnus Damm97991652011-04-29 02:28:08 +09001/*
2 * sh7372 Power management support
3 *
4 * Copyright (C) 2011 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/pm.h>
12#include <linux/suspend.h>
Magnus Damm082a8ca2011-04-29 02:39:32 +090013#include <linux/cpuidle.h>
Magnus Damm97991652011-04-29 02:28:08 +090014#include <linux/module.h>
15#include <linux/list.h>
16#include <linux/err.h>
17#include <linux/slab.h>
Rafael J. Wysockib5e8d262011-08-25 15:34:19 +020018#include <linux/pm_clock.h>
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020019#include <linux/platform_device.h>
20#include <linux/delay.h>
Magnus Dammcf338352011-09-25 23:20:49 +020021#include <linux/irq.h>
22#include <linux/bitrev.h>
Magnus Damm056879d2011-11-10 00:44:01 +010023#include <linux/console.h>
Rafael J. Wysocki5b411472012-08-15 20:58:19 +020024#include <asm/cpuidle.h>
Magnus Damm97991652011-04-29 02:28:08 +090025#include <asm/io.h>
26#include <asm/tlbflush.h>
Magnus Damm06b84162011-09-25 23:18:42 +020027#include <asm/suspend.h>
Magnus Damm97991652011-04-29 02:28:08 +090028#include <mach/common.h>
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020029#include <mach/sh7372.h>
Kuninori Morimotob9299a72012-07-05 01:28:32 -070030#include <mach/pm-rmobile.h>
Magnus Damm97991652011-04-29 02:28:08 +090031
Magnus Dammcf338352011-09-25 23:20:49 +020032/* DBG */
33#define DBGREG1 0xe6100020
34#define DBGREG9 0xe6100040
Magnus Damm97991652011-04-29 02:28:08 +090035
Magnus Dammcf338352011-09-25 23:20:49 +020036/* CPGA */
37#define SYSTBCR 0xe6150024
38#define MSTPSR0 0xe6150030
39#define MSTPSR1 0xe6150038
40#define MSTPSR2 0xe6150040
41#define MSTPSR3 0xe6150048
42#define MSTPSR4 0xe615004c
43#define PLLC01STPCR 0xe61500c8
44
45/* SYSC */
Magnus Dammcf338352011-09-25 23:20:49 +020046#define SBAR 0xe6180020
Magnus Damm382414b2011-10-19 23:52:50 +020047#define WUPRMSK 0xe6180028
Magnus Dammcf338352011-09-25 23:20:49 +020048#define WUPSMSK 0xe618002c
49#define WUPSMSK2 0xe6180048
Magnus Dammcf338352011-09-25 23:20:49 +020050#define WUPSFAC 0xe6180098
51#define IRQCR 0xe618022c
52#define IRQCR2 0xe6180238
53#define IRQCR3 0xe6180244
54#define IRQCR4 0xe6180248
55#define PDNSEL 0xe6180254
56
57/* INTC */
58#define ICR1A 0xe6900000
59#define ICR2A 0xe6900004
60#define ICR3A 0xe6900008
61#define ICR4A 0xe690000c
62#define INTMSK00A 0xe6900040
63#define INTMSK10A 0xe6900044
64#define INTMSK20A 0xe6900048
65#define INTMSK30A 0xe690004c
66
67/* MFIS */
68#define SMFRAM 0xe6a70000
69
70/* AP-System Core */
71#define APARMBAREA 0xe6f10020
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020072
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020073#ifdef CONFIG_PM
74
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +020075#define PM_DOMAIN_ON_OFF_LATENCY_NS 250000
76
Kuninori Morimotob9299a72012-07-05 01:28:32 -070077static int sh7372_a4r_pd_suspend(void)
78{
79 sh7372_intcs_suspend();
80 __raw_writel(0x300fffff, WUPRMSK); /* avoid wakeup */
81 return 0;
82}
83
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020084static bool a4s_suspend_ready;
85
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +020086static int sh7372_a4s_pd_suspend(void)
Kuninori Morimotob9299a72012-07-05 01:28:32 -070087{
88 /*
89 * The A4S domain contains the CPU core and therefore it should
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020090 * only be turned off if the CPU is not in use. This may happen
91 * during system suspend, when SYSC is going to be used for generating
92 * resume signals and a4s_suspend_ready is set to let
93 * sh7372_enter_suspend() know that it can turn A4S off.
Kuninori Morimotob9299a72012-07-05 01:28:32 -070094 */
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020095 a4s_suspend_ready = true;
Kuninori Morimotob9299a72012-07-05 01:28:32 -070096 return -EBUSY;
97}
98
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +020099static void sh7372_a4s_pd_resume(void)
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +0200100{
101 a4s_suspend_ready = false;
102}
103
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700104static int sh7372_a3sp_pd_suspend(void)
105{
106 /*
107 * Serial consoles make use of SCIF hardware located in A3SP,
108 * keep such power domain on if "no_console_suspend" is set.
109 */
110 return console_suspend_enabled ? 0 : -EBUSY;
111}
112
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200113static struct rmobile_pm_domain sh7372_pm_domains[] = {
114 {
115 .genpd.name = "A4LC",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200116 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
117 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200118 .bit_shift = 1,
119 },
120 {
121 .genpd.name = "A4MP",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200122 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
123 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200124 .bit_shift = 2,
125 },
126 {
127 .genpd.name = "D4",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200128 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
129 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200130 .bit_shift = 3,
131 },
132 {
133 .genpd.name = "A4R",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200134 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
135 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200136 .bit_shift = 5,
137 .suspend = sh7372_a4r_pd_suspend,
138 .resume = sh7372_intcs_resume,
139 },
140 {
141 .genpd.name = "A3RV",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200142 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
143 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200144 .bit_shift = 6,
145 },
146 {
147 .genpd.name = "A3RI",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200148 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
149 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200150 .bit_shift = 8,
151 },
152 {
153 .genpd.name = "A4S",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200154 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
155 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200156 .bit_shift = 10,
157 .gov = &pm_domain_always_on_gov,
158 .no_debug = true,
159 .suspend = sh7372_a4s_pd_suspend,
160 .resume = sh7372_a4s_pd_resume,
161 },
162 {
163 .genpd.name = "A3SP",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200164 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
165 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200166 .bit_shift = 11,
167 .gov = &pm_domain_always_on_gov,
168 .no_debug = true,
169 .suspend = sh7372_a3sp_pd_suspend,
170 },
171 {
172 .genpd.name = "A3SG",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200173 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
174 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200175 .bit_shift = 13,
176 },
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700177};
178
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200179void __init sh7372_init_pm_domains(void)
180{
181 rmobile_init_domains(sh7372_pm_domains, ARRAY_SIZE(sh7372_pm_domains));
182 pm_genpd_add_subdomain_names("A4LC", "A3RV");
183 pm_genpd_add_subdomain_names("A4R", "A4LC");
184 pm_genpd_add_subdomain_names("A4S", "A3SG");
185 pm_genpd_add_subdomain_names("A4S", "A3SP");
186}
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700187
Kuninori Morimoto1645b762012-06-24 22:00:13 +0200188#endif /* CONFIG_PM */
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200189
Magnus Damma0089bd2011-09-25 23:21:02 +0200190#if defined(CONFIG_SUSPEND) || defined(CONFIG_CPU_IDLE)
Magnus Dammf7dadb32011-12-23 01:23:07 +0100191static void sh7372_set_reset_vector(unsigned long address)
Magnus Damm97991652011-04-29 02:28:08 +0900192{
Magnus Damm06b84162011-09-25 23:18:42 +0200193 /* set reset vector, translate 4k */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100194 __raw_writel(address, SBAR);
Magnus Damm06b84162011-09-25 23:18:42 +0200195 __raw_writel(0, APARMBAREA);
Magnus Dammf7dadb32011-12-23 01:23:07 +0100196}
197
Magnus Dammf7dadb32011-12-23 01:23:07 +0100198static void sh7372_enter_sysc(int pllc0_on, unsigned long sleep_mode)
Magnus Dammcf338352011-09-25 23:20:49 +0200199{
Magnus Dammcf338352011-09-25 23:20:49 +0200200 if (pllc0_on)
201 __raw_writel(0, PLLC01STPCR);
202 else
203 __raw_writel(1 << 28, PLLC01STPCR);
204
Magnus Dammcf338352011-09-25 23:20:49 +0200205 __raw_readl(WUPSFAC); /* read wakeup int. factor before sleep */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100206 cpu_suspend(sleep_mode, sh7372_do_idle_sysc);
Magnus Dammcf338352011-09-25 23:20:49 +0200207 __raw_readl(WUPSFAC); /* read wakeup int. factor after wakeup */
208
209 /* disable reset vector translation */
210 __raw_writel(0, SBAR);
211}
212
Magnus Dammf7dadb32011-12-23 01:23:07 +0100213static int sh7372_sysc_valid(unsigned long *mskp, unsigned long *msk2p)
Magnus Dammcf338352011-09-25 23:20:49 +0200214{
215 unsigned long mstpsr0, mstpsr1, mstpsr2, mstpsr3, mstpsr4;
216 unsigned long msk, msk2;
217
218 /* check active clocks to determine potential wakeup sources */
219
220 mstpsr0 = __raw_readl(MSTPSR0);
221 if ((mstpsr0 & 0x00000003) != 0x00000003) {
222 pr_debug("sh7372 mstpsr0 0x%08lx\n", mstpsr0);
223 return 0;
224 }
225
226 mstpsr1 = __raw_readl(MSTPSR1);
227 if ((mstpsr1 & 0xff079b7f) != 0xff079b7f) {
228 pr_debug("sh7372 mstpsr1 0x%08lx\n", mstpsr1);
229 return 0;
230 }
231
232 mstpsr2 = __raw_readl(MSTPSR2);
233 if ((mstpsr2 & 0x000741ff) != 0x000741ff) {
234 pr_debug("sh7372 mstpsr2 0x%08lx\n", mstpsr2);
235 return 0;
236 }
237
238 mstpsr3 = __raw_readl(MSTPSR3);
239 if ((mstpsr3 & 0x1a60f010) != 0x1a60f010) {
240 pr_debug("sh7372 mstpsr3 0x%08lx\n", mstpsr3);
241 return 0;
242 }
243
244 mstpsr4 = __raw_readl(MSTPSR4);
245 if ((mstpsr4 & 0x00008cf0) != 0x00008cf0) {
246 pr_debug("sh7372 mstpsr4 0x%08lx\n", mstpsr4);
247 return 0;
248 }
249
250 msk = 0;
251 msk2 = 0;
252
253 /* make bitmaps of limited number of wakeup sources */
254
255 if ((mstpsr2 & (1 << 23)) == 0) /* SPU2 */
256 msk |= 1 << 31;
257
258 if ((mstpsr2 & (1 << 12)) == 0) /* MFI_MFIM */
259 msk |= 1 << 21;
260
261 if ((mstpsr4 & (1 << 3)) == 0) /* KEYSC */
262 msk |= 1 << 2;
263
264 if ((mstpsr1 & (1 << 24)) == 0) /* CMT0 */
265 msk |= 1 << 1;
266
267 if ((mstpsr3 & (1 << 29)) == 0) /* CMT1 */
268 msk |= 1 << 1;
269
270 if ((mstpsr4 & (1 << 0)) == 0) /* CMT2 */
271 msk |= 1 << 1;
272
273 if ((mstpsr2 & (1 << 13)) == 0) /* MFI_MFIS */
274 msk2 |= 1 << 17;
275
276 *mskp = msk;
277 *msk2p = msk2;
278
279 return 1;
280}
281
282static void sh7372_icr_to_irqcr(unsigned long icr, u16 *irqcr1p, u16 *irqcr2p)
283{
284 u16 tmp, irqcr1, irqcr2;
285 int k;
286
287 irqcr1 = 0;
288 irqcr2 = 0;
289
290 /* convert INTCA ICR register layout to SYSC IRQCR+IRQCR2 */
291 for (k = 0; k <= 7; k++) {
292 tmp = (icr >> ((7 - k) * 4)) & 0xf;
293 irqcr1 |= (tmp & 0x03) << (k * 2);
294 irqcr2 |= (tmp >> 2) << (k * 2);
295 }
296
297 *irqcr1p = irqcr1;
298 *irqcr2p = irqcr2;
299}
300
Magnus Dammf7dadb32011-12-23 01:23:07 +0100301static void sh7372_setup_sysc(unsigned long msk, unsigned long msk2)
Magnus Dammcf338352011-09-25 23:20:49 +0200302{
303 u16 irqcrx_low, irqcrx_high, irqcry_low, irqcry_high;
304 unsigned long tmp;
305
306 /* read IRQ0A -> IRQ15A mask */
307 tmp = bitrev8(__raw_readb(INTMSK00A));
308 tmp |= bitrev8(__raw_readb(INTMSK10A)) << 8;
309
310 /* setup WUPSMSK from clocks and external IRQ mask */
311 msk = (~msk & 0xc030000f) | (tmp << 4);
312 __raw_writel(msk, WUPSMSK);
313
314 /* propage level/edge trigger for external IRQ 0->15 */
315 sh7372_icr_to_irqcr(__raw_readl(ICR1A), &irqcrx_low, &irqcry_low);
316 sh7372_icr_to_irqcr(__raw_readl(ICR2A), &irqcrx_high, &irqcry_high);
317 __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR);
318 __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR2);
319
320 /* read IRQ16A -> IRQ31A mask */
321 tmp = bitrev8(__raw_readb(INTMSK20A));
322 tmp |= bitrev8(__raw_readb(INTMSK30A)) << 8;
323
324 /* setup WUPSMSK2 from clocks and external IRQ mask */
325 msk2 = (~msk2 & 0x00030000) | tmp;
326 __raw_writel(msk2, WUPSMSK2);
327
328 /* propage level/edge trigger for external IRQ 16->31 */
329 sh7372_icr_to_irqcr(__raw_readl(ICR3A), &irqcrx_low, &irqcry_low);
330 sh7372_icr_to_irqcr(__raw_readl(ICR4A), &irqcrx_high, &irqcry_high);
331 __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR3);
332 __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR4);
333}
Magnus Dammf7dadb32011-12-23 01:23:07 +0100334
335static void sh7372_enter_a3sm_common(int pllc0_on)
336{
Magnus Damm591e2ac2012-07-05 14:46:07 +0900337 /* use INTCA together with SYSC for wakeup */
338 sh7372_setup_sysc(1 << 0, 0);
Magnus Dammf7dadb32011-12-23 01:23:07 +0100339 sh7372_set_reset_vector(__pa(sh7372_resume_core_standby_sysc));
340 sh7372_enter_sysc(pllc0_on, 1 << 12);
341}
Rafael J. Wysocki911a4722012-07-11 22:55:12 +0200342#endif /* CONFIG_SUSPEND || CONFIG_CPU_IDLE */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100343
Magnus Damm082a8ca2011-04-29 02:39:32 +0900344#ifdef CONFIG_CPU_IDLE
Magnus Damm591e2ac2012-07-05 14:46:07 +0900345static int sh7372_do_idle_core_standby(unsigned long unused)
346{
347 cpu_do_idle(); /* WFI when SYSTBCR == 0x10 -> Core Standby */
348 return 0;
349}
350
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200351static int sh7372_enter_core_standby(struct cpuidle_device *dev,
352 struct cpuidle_driver *drv, int index)
Magnus Damm591e2ac2012-07-05 14:46:07 +0900353{
354 sh7372_set_reset_vector(__pa(sh7372_resume_core_standby_sysc));
355
356 /* enter sleep mode with SYSTBCR to 0x10 */
357 __raw_writel(0x10, SYSTBCR);
358 cpu_suspend(0, sh7372_do_idle_core_standby);
359 __raw_writel(0, SYSTBCR);
360
361 /* disable reset vector translation */
362 __raw_writel(0, SBAR);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200363
364 return 1;
Magnus Damm591e2ac2012-07-05 14:46:07 +0900365}
Magnus Dammcf338352011-09-25 23:20:49 +0200366
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200367static int sh7372_enter_a3sm_pll_on(struct cpuidle_device *dev,
368 struct cpuidle_driver *drv, int index)
Magnus Damm3abd69d2012-07-05 14:46:47 +0900369{
370 sh7372_enter_a3sm_common(1);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200371 return 2;
Magnus Damm3abd69d2012-07-05 14:46:47 +0900372}
373
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200374static int sh7372_enter_a3sm_pll_off(struct cpuidle_device *dev,
375 struct cpuidle_driver *drv, int index)
Magnus Damm3abd69d2012-07-05 14:46:47 +0900376{
377 sh7372_enter_a3sm_common(0);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200378 return 3;
Magnus Damm3abd69d2012-07-05 14:46:47 +0900379}
380
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200381static struct cpuidle_driver sh7372_cpuidle_driver = {
382 .name = "sh7372_cpuidle",
383 .owner = THIS_MODULE,
384 .en_core_tk_irqen = 1,
385 .state_count = 4,
386 .safe_state_index = 0, /* C1 */
387 .states[0] = ARM_CPUIDLE_WFI_STATE,
388 .states[0].enter = shmobile_enter_wfi,
389 .states[1] = {
390 .name = "C2",
391 .desc = "Core Standby Mode",
392 .exit_latency = 10,
393 .target_residency = 20 + 10,
394 .flags = CPUIDLE_FLAG_TIME_VALID,
395 .enter = sh7372_enter_core_standby,
396 },
397 .states[2] = {
398 .name = "C3",
399 .desc = "A3SM PLL ON",
400 .exit_latency = 20,
401 .target_residency = 30 + 20,
402 .flags = CPUIDLE_FLAG_TIME_VALID,
403 .enter = sh7372_enter_a3sm_pll_on,
404 },
405 .states[3] = {
406 .name = "C4",
407 .desc = "A3SM PLL OFF",
408 .exit_latency = 120,
409 .target_residency = 30 + 120,
410 .flags = CPUIDLE_FLAG_TIME_VALID,
411 .enter = sh7372_enter_a3sm_pll_off,
412 },
413};
Magnus Damm082a8ca2011-04-29 02:39:32 +0900414
415static void sh7372_cpuidle_init(void)
416{
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200417 shmobile_cpuidle_set_driver(&sh7372_cpuidle_driver);
Magnus Damm082a8ca2011-04-29 02:39:32 +0900418}
419#else
420static void sh7372_cpuidle_init(void) {}
421#endif
422
423#ifdef CONFIG_SUSPEND
Magnus Damm3abd69d2012-07-05 14:46:47 +0900424static void sh7372_enter_a4s_common(int pllc0_on)
425{
426 sh7372_intca_suspend();
427 memcpy((void *)SMFRAM, sh7372_resume_core_standby_sysc, 0x100);
428 sh7372_set_reset_vector(SMFRAM);
429 sh7372_enter_sysc(pllc0_on, 1 << 10);
430 sh7372_intca_resume();
431}
Magnus Dammcf338352011-09-25 23:20:49 +0200432
Magnus Damm97991652011-04-29 02:28:08 +0900433static int sh7372_enter_suspend(suspend_state_t suspend_state)
434{
Magnus Dammcf338352011-09-25 23:20:49 +0200435 unsigned long msk, msk2;
436
437 /* check active clocks to determine potential wakeup sources */
Rafael J. Wysocki18c081e2012-08-15 20:57:06 +0200438 if (sh7372_sysc_valid(&msk, &msk2) && a4s_suspend_ready) {
439 /* convert INTC mask/sense to SYSC mask/sense */
440 sh7372_setup_sysc(msk, msk2);
Magnus Damm591e2ac2012-07-05 14:46:07 +0900441
Rafael J. Wysocki18c081e2012-08-15 20:57:06 +0200442 /* enter A4S sleep with PLLC0 off */
443 pr_debug("entering A4S\n");
444 sh7372_enter_a4s_common(0);
445 return 0;
Magnus Dammcf338352011-09-25 23:20:49 +0200446 }
Magnus Damm591e2ac2012-07-05 14:46:07 +0900447
448 /* default to enter A3SM sleep with PLLC0 off */
449 pr_debug("entering A3SM\n");
450 sh7372_enter_a3sm_common(0);
Magnus Damm97991652011-04-29 02:28:08 +0900451 return 0;
452}
453
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100454/**
455 * sh7372_pm_notifier_fn - SH7372 PM notifier routine.
456 * @notifier: Unused.
457 * @pm_event: Event being handled.
458 * @unused: Unused.
459 */
460static int sh7372_pm_notifier_fn(struct notifier_block *notifier,
461 unsigned long pm_event, void *unused)
462{
463 switch (pm_event) {
464 case PM_SUSPEND_PREPARE:
465 /*
466 * This is necessary, because the A4R domain has to be "on"
467 * when suspend_device_irqs() and resume_device_irqs() are
468 * executed during system suspend and resume, respectively, so
469 * that those functions don't crash while accessing the INTCS.
470 */
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200471 pm_genpd_name_poweron("A4R");
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100472 break;
473 case PM_POST_SUSPEND:
474 pm_genpd_poweroff_unused();
475 break;
476 }
477
478 return NOTIFY_DONE;
479}
480
Magnus Damm97991652011-04-29 02:28:08 +0900481static void sh7372_suspend_init(void)
482{
483 shmobile_suspend_ops.enter = sh7372_enter_suspend;
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100484 pm_notifier(sh7372_pm_notifier_fn, 0);
Magnus Damm97991652011-04-29 02:28:08 +0900485}
486#else
487static void sh7372_suspend_init(void) {}
488#endif
489
Magnus Damm97991652011-04-29 02:28:08 +0900490void __init sh7372_pm_init(void)
491{
492 /* enable DBG hardware block to kick SYSC */
493 __raw_writel(0x0000a500, DBGREG9);
494 __raw_writel(0x0000a501, DBGREG9);
495 __raw_writel(0x00000000, DBGREG1);
496
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200497 /* do not convert A3SM, A3SP, A3SG, A4R power down into A4S */
498 __raw_writel(0, PDNSEL);
499
Magnus Damm97991652011-04-29 02:28:08 +0900500 sh7372_suspend_init();
Magnus Damm082a8ca2011-04-29 02:39:32 +0900501 sh7372_cpuidle_init();
Magnus Damm97991652011-04-29 02:28:08 +0900502}