blob: f6b14cac0076f6f6c2ed932022b072b5a2060c7c [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 */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000033#define DBGREG1 IOMEM(0xe6100020)
34#define DBGREG9 IOMEM(0xe6100040)
Magnus Damm97991652011-04-29 02:28:08 +090035
Magnus Dammcf338352011-09-25 23:20:49 +020036/* CPGA */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000037#define SYSTBCR IOMEM(0xe6150024)
38#define MSTPSR0 IOMEM(0xe6150030)
39#define MSTPSR1 IOMEM(0xe6150038)
40#define MSTPSR2 IOMEM(0xe6150040)
41#define MSTPSR3 IOMEM(0xe6150048)
42#define MSTPSR4 IOMEM(0xe615004c)
43#define PLLC01STPCR IOMEM(0xe61500c8)
Magnus Dammcf338352011-09-25 23:20:49 +020044
45/* SYSC */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000046#define SBAR IOMEM(0xe6180020)
47#define WUPRMSK IOMEM(0xe6180028)
48#define WUPSMSK IOMEM(0xe618002c)
49#define WUPSMSK2 IOMEM(0xe6180048)
50#define WUPSFAC IOMEM(0xe6180098)
51#define IRQCR IOMEM(0xe618022c)
52#define IRQCR2 IOMEM(0xe6180238)
53#define IRQCR3 IOMEM(0xe6180244)
54#define IRQCR4 IOMEM(0xe6180248)
55#define PDNSEL IOMEM(0xe6180254)
Magnus Dammcf338352011-09-25 23:20:49 +020056
57/* INTC */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000058#define ICR1A IOMEM(0xe6900000)
59#define ICR2A IOMEM(0xe6900004)
60#define ICR3A IOMEM(0xe6900008)
61#define ICR4A IOMEM(0xe690000c)
62#define INTMSK00A IOMEM(0xe6900040)
63#define INTMSK10A IOMEM(0xe6900044)
64#define INTMSK20A IOMEM(0xe6900048)
65#define INTMSK30A IOMEM(0xe690004c)
Magnus Dammcf338352011-09-25 23:20:49 +020066
67/* MFIS */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000068/* FIXME: pointing where? */
Magnus Dammcf338352011-09-25 23:20:49 +020069#define SMFRAM 0xe6a70000
70
71/* AP-System Core */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000072#define APARMBAREA IOMEM(0xe6f10020)
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020073
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020074#ifdef CONFIG_PM
75
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +020076#define PM_DOMAIN_ON_OFF_LATENCY_NS 250000
Kuninori Morimotob9299a72012-07-05 01:28:32 -070077
78static int sh7372_a4r_pd_suspend(void)
79{
80 sh7372_intcs_suspend();
81 __raw_writel(0x300fffff, WUPRMSK); /* avoid wakeup */
82 return 0;
83}
84
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020085static bool a4s_suspend_ready;
Kuninori Morimotob9299a72012-07-05 01:28:32 -070086
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +020087static int sh7372_a4s_pd_suspend(void)
Kuninori Morimotob9299a72012-07-05 01:28:32 -070088{
89 /*
90 * The A4S domain contains the CPU core and therefore it should
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020091 * only be turned off if the CPU is not in use. This may happen
92 * during system suspend, when SYSC is going to be used for generating
93 * resume signals and a4s_suspend_ready is set to let
94 * sh7372_enter_suspend() know that it can turn A4S off.
Kuninori Morimotob9299a72012-07-05 01:28:32 -070095 */
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020096 a4s_suspend_ready = true;
Kuninori Morimotob9299a72012-07-05 01:28:32 -070097 return -EBUSY;
98}
99
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200100static void sh7372_a4s_pd_resume(void)
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +0200101{
102 a4s_suspend_ready = false;
103}
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700104
105static int sh7372_a3sp_pd_suspend(void)
106{
107 /*
108 * Serial consoles make use of SCIF hardware located in A3SP,
109 * keep such power domain on if "no_console_suspend" is set.
110 */
111 return console_suspend_enabled ? 0 : -EBUSY;
112}
113
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200114static struct rmobile_pm_domain sh7372_pm_domains[] = {
115 {
116 .genpd.name = "A4LC",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200117 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
118 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200119 .bit_shift = 1,
120 },
121 {
122 .genpd.name = "A4MP",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200123 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
124 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200125 .bit_shift = 2,
126 },
127 {
128 .genpd.name = "D4",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200129 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
130 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200131 .bit_shift = 3,
132 },
133 {
134 .genpd.name = "A4R",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200135 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
136 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200137 .bit_shift = 5,
138 .suspend = sh7372_a4r_pd_suspend,
139 .resume = sh7372_intcs_resume,
140 },
141 {
142 .genpd.name = "A3RV",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200143 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
144 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200145 .bit_shift = 6,
146 },
147 {
148 .genpd.name = "A3RI",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200149 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
150 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200151 .bit_shift = 8,
152 },
153 {
154 .genpd.name = "A4S",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200155 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
156 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200157 .bit_shift = 10,
158 .gov = &pm_domain_always_on_gov,
159 .no_debug = true,
160 .suspend = sh7372_a4s_pd_suspend,
161 .resume = sh7372_a4s_pd_resume,
162 },
163 {
164 .genpd.name = "A3SP",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200165 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
166 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200167 .bit_shift = 11,
168 .gov = &pm_domain_always_on_gov,
169 .no_debug = true,
170 .suspend = sh7372_a3sp_pd_suspend,
171 },
172 {
173 .genpd.name = "A3SG",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200174 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
175 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200176 .bit_shift = 13,
177 },
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700178};
179
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200180void __init sh7372_init_pm_domains(void)
181{
182 rmobile_init_domains(sh7372_pm_domains, ARRAY_SIZE(sh7372_pm_domains));
183 pm_genpd_add_subdomain_names("A4LC", "A3RV");
184 pm_genpd_add_subdomain_names("A4R", "A4LC");
185 pm_genpd_add_subdomain_names("A4S", "A3SG");
186 pm_genpd_add_subdomain_names("A4S", "A3SP");
187}
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700188
Kuninori Morimoto1645b762012-06-24 22:00:13 +0200189#endif /* CONFIG_PM */
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200190
Magnus Damma0089bd2011-09-25 23:21:02 +0200191#if defined(CONFIG_SUSPEND) || defined(CONFIG_CPU_IDLE)
Magnus Dammf7dadb32011-12-23 01:23:07 +0100192static void sh7372_set_reset_vector(unsigned long address)
Magnus Damm97991652011-04-29 02:28:08 +0900193{
Magnus Damm06b84162011-09-25 23:18:42 +0200194 /* set reset vector, translate 4k */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100195 __raw_writel(address, SBAR);
Magnus Damm06b84162011-09-25 23:18:42 +0200196 __raw_writel(0, APARMBAREA);
Magnus Dammf7dadb32011-12-23 01:23:07 +0100197}
198
Magnus Dammf7dadb32011-12-23 01:23:07 +0100199static void sh7372_enter_sysc(int pllc0_on, unsigned long sleep_mode)
Magnus Dammcf338352011-09-25 23:20:49 +0200200{
Magnus Dammcf338352011-09-25 23:20:49 +0200201 if (pllc0_on)
202 __raw_writel(0, PLLC01STPCR);
203 else
204 __raw_writel(1 << 28, PLLC01STPCR);
205
Magnus Dammcf338352011-09-25 23:20:49 +0200206 __raw_readl(WUPSFAC); /* read wakeup int. factor before sleep */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100207 cpu_suspend(sleep_mode, sh7372_do_idle_sysc);
Magnus Dammcf338352011-09-25 23:20:49 +0200208 __raw_readl(WUPSFAC); /* read wakeup int. factor after wakeup */
209
210 /* disable reset vector translation */
211 __raw_writel(0, SBAR);
212}
213
Magnus Dammf7dadb32011-12-23 01:23:07 +0100214static int sh7372_sysc_valid(unsigned long *mskp, unsigned long *msk2p)
Magnus Dammcf338352011-09-25 23:20:49 +0200215{
216 unsigned long mstpsr0, mstpsr1, mstpsr2, mstpsr3, mstpsr4;
217 unsigned long msk, msk2;
218
219 /* check active clocks to determine potential wakeup sources */
220
221 mstpsr0 = __raw_readl(MSTPSR0);
222 if ((mstpsr0 & 0x00000003) != 0x00000003) {
223 pr_debug("sh7372 mstpsr0 0x%08lx\n", mstpsr0);
224 return 0;
225 }
226
227 mstpsr1 = __raw_readl(MSTPSR1);
228 if ((mstpsr1 & 0xff079b7f) != 0xff079b7f) {
229 pr_debug("sh7372 mstpsr1 0x%08lx\n", mstpsr1);
230 return 0;
231 }
232
233 mstpsr2 = __raw_readl(MSTPSR2);
234 if ((mstpsr2 & 0x000741ff) != 0x000741ff) {
235 pr_debug("sh7372 mstpsr2 0x%08lx\n", mstpsr2);
236 return 0;
237 }
238
239 mstpsr3 = __raw_readl(MSTPSR3);
240 if ((mstpsr3 & 0x1a60f010) != 0x1a60f010) {
241 pr_debug("sh7372 mstpsr3 0x%08lx\n", mstpsr3);
242 return 0;
243 }
244
245 mstpsr4 = __raw_readl(MSTPSR4);
246 if ((mstpsr4 & 0x00008cf0) != 0x00008cf0) {
247 pr_debug("sh7372 mstpsr4 0x%08lx\n", mstpsr4);
248 return 0;
249 }
250
251 msk = 0;
252 msk2 = 0;
253
254 /* make bitmaps of limited number of wakeup sources */
255
256 if ((mstpsr2 & (1 << 23)) == 0) /* SPU2 */
257 msk |= 1 << 31;
258
259 if ((mstpsr2 & (1 << 12)) == 0) /* MFI_MFIM */
260 msk |= 1 << 21;
261
262 if ((mstpsr4 & (1 << 3)) == 0) /* KEYSC */
263 msk |= 1 << 2;
264
265 if ((mstpsr1 & (1 << 24)) == 0) /* CMT0 */
266 msk |= 1 << 1;
267
268 if ((mstpsr3 & (1 << 29)) == 0) /* CMT1 */
269 msk |= 1 << 1;
270
271 if ((mstpsr4 & (1 << 0)) == 0) /* CMT2 */
272 msk |= 1 << 1;
273
274 if ((mstpsr2 & (1 << 13)) == 0) /* MFI_MFIS */
275 msk2 |= 1 << 17;
276
277 *mskp = msk;
278 *msk2p = msk2;
279
280 return 1;
281}
282
283static void sh7372_icr_to_irqcr(unsigned long icr, u16 *irqcr1p, u16 *irqcr2p)
284{
285 u16 tmp, irqcr1, irqcr2;
286 int k;
287
288 irqcr1 = 0;
289 irqcr2 = 0;
290
291 /* convert INTCA ICR register layout to SYSC IRQCR+IRQCR2 */
292 for (k = 0; k <= 7; k++) {
293 tmp = (icr >> ((7 - k) * 4)) & 0xf;
294 irqcr1 |= (tmp & 0x03) << (k * 2);
295 irqcr2 |= (tmp >> 2) << (k * 2);
296 }
297
298 *irqcr1p = irqcr1;
299 *irqcr2p = irqcr2;
300}
301
Magnus Dammf7dadb32011-12-23 01:23:07 +0100302static void sh7372_setup_sysc(unsigned long msk, unsigned long msk2)
Magnus Dammcf338352011-09-25 23:20:49 +0200303{
304 u16 irqcrx_low, irqcrx_high, irqcry_low, irqcry_high;
305 unsigned long tmp;
306
307 /* read IRQ0A -> IRQ15A mask */
308 tmp = bitrev8(__raw_readb(INTMSK00A));
309 tmp |= bitrev8(__raw_readb(INTMSK10A)) << 8;
310
311 /* setup WUPSMSK from clocks and external IRQ mask */
312 msk = (~msk & 0xc030000f) | (tmp << 4);
313 __raw_writel(msk, WUPSMSK);
314
315 /* propage level/edge trigger for external IRQ 0->15 */
316 sh7372_icr_to_irqcr(__raw_readl(ICR1A), &irqcrx_low, &irqcry_low);
317 sh7372_icr_to_irqcr(__raw_readl(ICR2A), &irqcrx_high, &irqcry_high);
318 __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR);
319 __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR2);
320
321 /* read IRQ16A -> IRQ31A mask */
322 tmp = bitrev8(__raw_readb(INTMSK20A));
323 tmp |= bitrev8(__raw_readb(INTMSK30A)) << 8;
324
325 /* setup WUPSMSK2 from clocks and external IRQ mask */
326 msk2 = (~msk2 & 0x00030000) | tmp;
327 __raw_writel(msk2, WUPSMSK2);
328
329 /* propage level/edge trigger for external IRQ 16->31 */
330 sh7372_icr_to_irqcr(__raw_readl(ICR3A), &irqcrx_low, &irqcry_low);
331 sh7372_icr_to_irqcr(__raw_readl(ICR4A), &irqcrx_high, &irqcry_high);
332 __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR3);
333 __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR4);
334}
Magnus Dammf7dadb32011-12-23 01:23:07 +0100335
336static void sh7372_enter_a3sm_common(int pllc0_on)
337{
Magnus Damm591e2ac2012-07-05 14:46:07 +0900338 /* use INTCA together with SYSC for wakeup */
339 sh7372_setup_sysc(1 << 0, 0);
Magnus Dammf7dadb32011-12-23 01:23:07 +0100340 sh7372_set_reset_vector(__pa(sh7372_resume_core_standby_sysc));
341 sh7372_enter_sysc(pllc0_on, 1 << 12);
342}
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200343
344static void sh7372_enter_a4s_common(int pllc0_on)
345{
346 sh7372_intca_suspend();
347 sh7372_set_reset_vector(SMFRAM);
348 sh7372_enter_sysc(pllc0_on, 1 << 10);
349 sh7372_intca_resume();
350}
351
352static void sh7372_pm_setup_smfram(void)
353{
354 memcpy((void *)SMFRAM, sh7372_resume_core_standby_sysc, 0x100);
355}
356#else
357static inline void sh7372_pm_setup_smfram(void) {}
Rafael J. Wysocki911a4722012-07-11 22:55:12 +0200358#endif /* CONFIG_SUSPEND || CONFIG_CPU_IDLE */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100359
Magnus Damm082a8ca2011-04-29 02:39:32 +0900360#ifdef CONFIG_CPU_IDLE
Magnus Damm591e2ac2012-07-05 14:46:07 +0900361static int sh7372_do_idle_core_standby(unsigned long unused)
362{
363 cpu_do_idle(); /* WFI when SYSTBCR == 0x10 -> Core Standby */
364 return 0;
365}
366
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200367static int sh7372_enter_core_standby(struct cpuidle_device *dev,
368 struct cpuidle_driver *drv, int index)
Magnus Damm591e2ac2012-07-05 14:46:07 +0900369{
370 sh7372_set_reset_vector(__pa(sh7372_resume_core_standby_sysc));
371
372 /* enter sleep mode with SYSTBCR to 0x10 */
373 __raw_writel(0x10, SYSTBCR);
374 cpu_suspend(0, sh7372_do_idle_core_standby);
375 __raw_writel(0, SYSTBCR);
376
377 /* disable reset vector translation */
378 __raw_writel(0, SBAR);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200379
380 return 1;
Magnus Damm591e2ac2012-07-05 14:46:07 +0900381}
Magnus Dammcf338352011-09-25 23:20:49 +0200382
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200383static int sh7372_enter_a3sm_pll_on(struct cpuidle_device *dev,
384 struct cpuidle_driver *drv, int index)
Magnus Damm3abd69d2012-07-05 14:46:47 +0900385{
386 sh7372_enter_a3sm_common(1);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200387 return 2;
Magnus Damm3abd69d2012-07-05 14:46:47 +0900388}
389
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200390static int sh7372_enter_a3sm_pll_off(struct cpuidle_device *dev,
391 struct cpuidle_driver *drv, int index)
Magnus Damm3abd69d2012-07-05 14:46:47 +0900392{
393 sh7372_enter_a3sm_common(0);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200394 return 3;
Magnus Damm3abd69d2012-07-05 14:46:47 +0900395}
396
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200397static int sh7372_enter_a4s(struct cpuidle_device *dev,
398 struct cpuidle_driver *drv, int index)
Magnus Damm082a8ca2011-04-29 02:39:32 +0900399{
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200400 unsigned long msk, msk2;
Magnus Damm082a8ca2011-04-29 02:39:32 +0900401
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200402 if (!sh7372_sysc_valid(&msk, &msk2))
403 return sh7372_enter_a3sm_pll_off(dev, drv, index);
Magnus Damm082a8ca2011-04-29 02:39:32 +0900404
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200405 sh7372_setup_sysc(msk, msk2);
406 sh7372_enter_a4s_common(0);
407 return 4;
Magnus Damm082a8ca2011-04-29 02:39:32 +0900408}
409
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200410static struct cpuidle_driver sh7372_cpuidle_driver = {
411 .name = "sh7372_cpuidle",
412 .owner = THIS_MODULE,
413 .en_core_tk_irqen = 1,
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200414 .state_count = 5,
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200415 .safe_state_index = 0, /* C1 */
416 .states[0] = ARM_CPUIDLE_WFI_STATE,
417 .states[0].enter = shmobile_enter_wfi,
418 .states[1] = {
419 .name = "C2",
420 .desc = "Core Standby Mode",
421 .exit_latency = 10,
422 .target_residency = 20 + 10,
423 .flags = CPUIDLE_FLAG_TIME_VALID,
424 .enter = sh7372_enter_core_standby,
425 },
426 .states[2] = {
427 .name = "C3",
428 .desc = "A3SM PLL ON",
429 .exit_latency = 20,
430 .target_residency = 30 + 20,
431 .flags = CPUIDLE_FLAG_TIME_VALID,
432 .enter = sh7372_enter_a3sm_pll_on,
433 },
434 .states[3] = {
435 .name = "C4",
436 .desc = "A3SM PLL OFF",
437 .exit_latency = 120,
438 .target_residency = 30 + 120,
439 .flags = CPUIDLE_FLAG_TIME_VALID,
440 .enter = sh7372_enter_a3sm_pll_off,
441 },
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200442 .states[4] = {
443 .name = "C5",
444 .desc = "A4S PLL OFF",
445 .exit_latency = 240,
446 .target_residency = 30 + 240,
447 .flags = CPUIDLE_FLAG_TIME_VALID,
448 .enter = sh7372_enter_a4s,
449 .disabled = true,
450 },
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200451};
Magnus Damm082a8ca2011-04-29 02:39:32 +0900452
Daniel Lezcanod5047092013-04-03 12:15:15 +0000453static void __init sh7372_cpuidle_init(void)
Magnus Damm082a8ca2011-04-29 02:39:32 +0900454{
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200455 shmobile_cpuidle_set_driver(&sh7372_cpuidle_driver);
Magnus Damm082a8ca2011-04-29 02:39:32 +0900456}
457#else
Daniel Lezcanod5047092013-04-03 12:15:15 +0000458static void __init sh7372_cpuidle_init(void) {}
Magnus Damm082a8ca2011-04-29 02:39:32 +0900459#endif
460
461#ifdef CONFIG_SUSPEND
Magnus Damm97991652011-04-29 02:28:08 +0900462static int sh7372_enter_suspend(suspend_state_t suspend_state)
463{
Magnus Dammcf338352011-09-25 23:20:49 +0200464 unsigned long msk, msk2;
465
466 /* check active clocks to determine potential wakeup sources */
Rafael J. Wysocki18c081e2012-08-15 20:57:06 +0200467 if (sh7372_sysc_valid(&msk, &msk2) && a4s_suspend_ready) {
468 /* convert INTC mask/sense to SYSC mask/sense */
469 sh7372_setup_sysc(msk, msk2);
Magnus Damm591e2ac2012-07-05 14:46:07 +0900470
Rafael J. Wysocki18c081e2012-08-15 20:57:06 +0200471 /* enter A4S sleep with PLLC0 off */
472 pr_debug("entering A4S\n");
473 sh7372_enter_a4s_common(0);
474 return 0;
Magnus Dammcf338352011-09-25 23:20:49 +0200475 }
Magnus Damm591e2ac2012-07-05 14:46:07 +0900476
477 /* default to enter A3SM sleep with PLLC0 off */
478 pr_debug("entering A3SM\n");
479 sh7372_enter_a3sm_common(0);
Magnus Damm97991652011-04-29 02:28:08 +0900480 return 0;
481}
482
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100483/**
484 * sh7372_pm_notifier_fn - SH7372 PM notifier routine.
485 * @notifier: Unused.
486 * @pm_event: Event being handled.
487 * @unused: Unused.
488 */
489static int sh7372_pm_notifier_fn(struct notifier_block *notifier,
490 unsigned long pm_event, void *unused)
491{
492 switch (pm_event) {
493 case PM_SUSPEND_PREPARE:
494 /*
495 * This is necessary, because the A4R domain has to be "on"
496 * when suspend_device_irqs() and resume_device_irqs() are
497 * executed during system suspend and resume, respectively, so
498 * that those functions don't crash while accessing the INTCS.
499 */
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200500 pm_genpd_name_poweron("A4R");
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100501 break;
502 case PM_POST_SUSPEND:
503 pm_genpd_poweroff_unused();
504 break;
505 }
506
507 return NOTIFY_DONE;
508}
509
Magnus Damm97991652011-04-29 02:28:08 +0900510static void sh7372_suspend_init(void)
511{
512 shmobile_suspend_ops.enter = sh7372_enter_suspend;
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100513 pm_notifier(sh7372_pm_notifier_fn, 0);
Magnus Damm97991652011-04-29 02:28:08 +0900514}
515#else
516static void sh7372_suspend_init(void) {}
517#endif
518
Magnus Damm97991652011-04-29 02:28:08 +0900519void __init sh7372_pm_init(void)
520{
521 /* enable DBG hardware block to kick SYSC */
522 __raw_writel(0x0000a500, DBGREG9);
523 __raw_writel(0x0000a501, DBGREG9);
524 __raw_writel(0x00000000, DBGREG1);
525
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200526 /* do not convert A3SM, A3SP, A3SG, A4R power down into A4S */
527 __raw_writel(0, PDNSEL);
528
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200529 sh7372_pm_setup_smfram();
530
Magnus Damm97991652011-04-29 02:28:08 +0900531 sh7372_suspend_init();
Magnus Damm082a8ca2011-04-29 02:39:32 +0900532 sh7372_cpuidle_init();
Magnus Damm97991652011-04-29 02:28:08 +0900533}
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200534
535void __init sh7372_pm_init_late(void)
536{
537 shmobile_init_late();
538 pm_genpd_name_attach_cpuidle("A4S", 4);
539}