blob: 0e37da654ed5dfe20b6dc9962fbce3d80b0876f0 [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>
Geert Uytterhoeven113522e2014-06-20 18:53:08 +020024
Rafael J. Wysocki5b411472012-08-15 20:58:19 +020025#include <asm/cpuidle.h>
Magnus Damm97991652011-04-29 02:28:08 +090026#include <asm/io.h>
27#include <asm/tlbflush.h>
Magnus Damm06b84162011-09-25 23:18:42 +020028#include <asm/suspend.h>
Geert Uytterhoeven113522e2014-06-20 18:53:08 +020029
Magnus Dammfd44aa52014-06-17 16:47:37 +090030#include "common.h"
Magnus Damm6b8b0cb2014-06-17 16:47:45 +090031#include "pm-rmobile.h"
Geert Uytterhoeven113522e2014-06-20 18:53:08 +020032#include "sh7372.h"
Magnus Damm97991652011-04-29 02:28:08 +090033
Magnus Dammcf338352011-09-25 23:20:49 +020034/* DBG */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000035#define DBGREG1 IOMEM(0xe6100020)
36#define DBGREG9 IOMEM(0xe6100040)
Magnus Damm97991652011-04-29 02:28:08 +090037
Magnus Dammcf338352011-09-25 23:20:49 +020038/* CPGA */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000039#define SYSTBCR IOMEM(0xe6150024)
40#define MSTPSR0 IOMEM(0xe6150030)
41#define MSTPSR1 IOMEM(0xe6150038)
42#define MSTPSR2 IOMEM(0xe6150040)
43#define MSTPSR3 IOMEM(0xe6150048)
44#define MSTPSR4 IOMEM(0xe615004c)
45#define PLLC01STPCR IOMEM(0xe61500c8)
Magnus Dammcf338352011-09-25 23:20:49 +020046
47/* SYSC */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000048#define SBAR IOMEM(0xe6180020)
49#define WUPRMSK IOMEM(0xe6180028)
50#define WUPSMSK IOMEM(0xe618002c)
51#define WUPSMSK2 IOMEM(0xe6180048)
52#define WUPSFAC IOMEM(0xe6180098)
53#define IRQCR IOMEM(0xe618022c)
54#define IRQCR2 IOMEM(0xe6180238)
55#define IRQCR3 IOMEM(0xe6180244)
56#define IRQCR4 IOMEM(0xe6180248)
57#define PDNSEL IOMEM(0xe6180254)
Magnus Dammcf338352011-09-25 23:20:49 +020058
59/* INTC */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000060#define ICR1A IOMEM(0xe6900000)
61#define ICR2A IOMEM(0xe6900004)
62#define ICR3A IOMEM(0xe6900008)
63#define ICR4A IOMEM(0xe690000c)
64#define INTMSK00A IOMEM(0xe6900040)
65#define INTMSK10A IOMEM(0xe6900044)
66#define INTMSK20A IOMEM(0xe6900048)
67#define INTMSK30A IOMEM(0xe690004c)
Magnus Dammcf338352011-09-25 23:20:49 +020068
69/* MFIS */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000070/* FIXME: pointing where? */
Magnus Dammcf338352011-09-25 23:20:49 +020071#define SMFRAM 0xe6a70000
72
73/* AP-System Core */
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +000074#define APARMBAREA IOMEM(0xe6f10020)
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020075
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020076#ifdef CONFIG_PM
77
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +020078#define PM_DOMAIN_ON_OFF_LATENCY_NS 250000
Kuninori Morimotob9299a72012-07-05 01:28:32 -070079
80static int sh7372_a4r_pd_suspend(void)
81{
82 sh7372_intcs_suspend();
83 __raw_writel(0x300fffff, WUPRMSK); /* avoid wakeup */
84 return 0;
85}
86
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020087static bool a4s_suspend_ready;
Kuninori Morimotob9299a72012-07-05 01:28:32 -070088
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +020089static int sh7372_a4s_pd_suspend(void)
Kuninori Morimotob9299a72012-07-05 01:28:32 -070090{
91 /*
92 * The A4S domain contains the CPU core and therefore it should
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020093 * only be turned off if the CPU is not in use. This may happen
94 * during system suspend, when SYSC is going to be used for generating
95 * resume signals and a4s_suspend_ready is set to let
96 * sh7372_enter_suspend() know that it can turn A4S off.
Kuninori Morimotob9299a72012-07-05 01:28:32 -070097 */
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +020098 a4s_suspend_ready = true;
Kuninori Morimotob9299a72012-07-05 01:28:32 -070099 return -EBUSY;
100}
101
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200102static void sh7372_a4s_pd_resume(void)
Rafael J. Wysocki70fe7b22012-08-15 20:54:15 +0200103{
104 a4s_suspend_ready = false;
105}
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700106
107static int sh7372_a3sp_pd_suspend(void)
108{
109 /*
110 * Serial consoles make use of SCIF hardware located in A3SP,
111 * keep such power domain on if "no_console_suspend" is set.
112 */
113 return console_suspend_enabled ? 0 : -EBUSY;
114}
115
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200116static struct rmobile_pm_domain sh7372_pm_domains[] = {
117 {
118 .genpd.name = "A4LC",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200119 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
120 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200121 .bit_shift = 1,
122 },
123 {
124 .genpd.name = "A4MP",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200125 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
126 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200127 .bit_shift = 2,
128 },
129 {
130 .genpd.name = "D4",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200131 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
132 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200133 .bit_shift = 3,
134 },
135 {
136 .genpd.name = "A4R",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200137 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
138 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200139 .bit_shift = 5,
140 .suspend = sh7372_a4r_pd_suspend,
141 .resume = sh7372_intcs_resume,
142 },
143 {
144 .genpd.name = "A3RV",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200145 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
146 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200147 .bit_shift = 6,
148 },
149 {
150 .genpd.name = "A3RI",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200151 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
152 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200153 .bit_shift = 8,
154 },
155 {
156 .genpd.name = "A4S",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200157 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
158 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200159 .bit_shift = 10,
160 .gov = &pm_domain_always_on_gov,
161 .no_debug = true,
162 .suspend = sh7372_a4s_pd_suspend,
163 .resume = sh7372_a4s_pd_resume,
164 },
165 {
166 .genpd.name = "A3SP",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200167 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
168 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200169 .bit_shift = 11,
170 .gov = &pm_domain_always_on_gov,
171 .no_debug = true,
172 .suspend = sh7372_a3sp_pd_suspend,
173 },
174 {
175 .genpd.name = "A3SG",
Rafael J. Wysocki8ae28ec2012-08-08 00:27:10 +0200176 .genpd.power_on_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
177 .genpd.power_off_latency_ns = PM_DOMAIN_ON_OFF_LATENCY_NS,
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200178 .bit_shift = 13,
179 },
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700180};
181
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200182void __init sh7372_init_pm_domains(void)
183{
184 rmobile_init_domains(sh7372_pm_domains, ARRAY_SIZE(sh7372_pm_domains));
185 pm_genpd_add_subdomain_names("A4LC", "A3RV");
186 pm_genpd_add_subdomain_names("A4R", "A4LC");
187 pm_genpd_add_subdomain_names("A4S", "A3SG");
188 pm_genpd_add_subdomain_names("A4S", "A3SP");
189}
Kuninori Morimotob9299a72012-07-05 01:28:32 -0700190
Kuninori Morimoto1645b762012-06-24 22:00:13 +0200191#endif /* CONFIG_PM */
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200192
Magnus Damma0089bd2011-09-25 23:21:02 +0200193#if defined(CONFIG_SUSPEND) || defined(CONFIG_CPU_IDLE)
Magnus Dammf7dadb32011-12-23 01:23:07 +0100194static void sh7372_set_reset_vector(unsigned long address)
Magnus Damm97991652011-04-29 02:28:08 +0900195{
Magnus Damm06b84162011-09-25 23:18:42 +0200196 /* set reset vector, translate 4k */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100197 __raw_writel(address, SBAR);
Magnus Damm06b84162011-09-25 23:18:42 +0200198 __raw_writel(0, APARMBAREA);
Magnus Dammf7dadb32011-12-23 01:23:07 +0100199}
200
Magnus Dammf7dadb32011-12-23 01:23:07 +0100201static void sh7372_enter_sysc(int pllc0_on, unsigned long sleep_mode)
Magnus Dammcf338352011-09-25 23:20:49 +0200202{
Magnus Dammcf338352011-09-25 23:20:49 +0200203 if (pllc0_on)
204 __raw_writel(0, PLLC01STPCR);
205 else
206 __raw_writel(1 << 28, PLLC01STPCR);
207
Magnus Dammcf338352011-09-25 23:20:49 +0200208 __raw_readl(WUPSFAC); /* read wakeup int. factor before sleep */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100209 cpu_suspend(sleep_mode, sh7372_do_idle_sysc);
Magnus Dammcf338352011-09-25 23:20:49 +0200210 __raw_readl(WUPSFAC); /* read wakeup int. factor after wakeup */
211
212 /* disable reset vector translation */
213 __raw_writel(0, SBAR);
214}
215
Magnus Dammf7dadb32011-12-23 01:23:07 +0100216static int sh7372_sysc_valid(unsigned long *mskp, unsigned long *msk2p)
Magnus Dammcf338352011-09-25 23:20:49 +0200217{
218 unsigned long mstpsr0, mstpsr1, mstpsr2, mstpsr3, mstpsr4;
219 unsigned long msk, msk2;
220
221 /* check active clocks to determine potential wakeup sources */
222
223 mstpsr0 = __raw_readl(MSTPSR0);
224 if ((mstpsr0 & 0x00000003) != 0x00000003) {
225 pr_debug("sh7372 mstpsr0 0x%08lx\n", mstpsr0);
226 return 0;
227 }
228
229 mstpsr1 = __raw_readl(MSTPSR1);
230 if ((mstpsr1 & 0xff079b7f) != 0xff079b7f) {
231 pr_debug("sh7372 mstpsr1 0x%08lx\n", mstpsr1);
232 return 0;
233 }
234
235 mstpsr2 = __raw_readl(MSTPSR2);
236 if ((mstpsr2 & 0x000741ff) != 0x000741ff) {
237 pr_debug("sh7372 mstpsr2 0x%08lx\n", mstpsr2);
238 return 0;
239 }
240
241 mstpsr3 = __raw_readl(MSTPSR3);
242 if ((mstpsr3 & 0x1a60f010) != 0x1a60f010) {
243 pr_debug("sh7372 mstpsr3 0x%08lx\n", mstpsr3);
244 return 0;
245 }
246
247 mstpsr4 = __raw_readl(MSTPSR4);
248 if ((mstpsr4 & 0x00008cf0) != 0x00008cf0) {
249 pr_debug("sh7372 mstpsr4 0x%08lx\n", mstpsr4);
250 return 0;
251 }
252
253 msk = 0;
254 msk2 = 0;
255
256 /* make bitmaps of limited number of wakeup sources */
257
258 if ((mstpsr2 & (1 << 23)) == 0) /* SPU2 */
259 msk |= 1 << 31;
260
261 if ((mstpsr2 & (1 << 12)) == 0) /* MFI_MFIM */
262 msk |= 1 << 21;
263
264 if ((mstpsr4 & (1 << 3)) == 0) /* KEYSC */
265 msk |= 1 << 2;
266
267 if ((mstpsr1 & (1 << 24)) == 0) /* CMT0 */
268 msk |= 1 << 1;
269
270 if ((mstpsr3 & (1 << 29)) == 0) /* CMT1 */
271 msk |= 1 << 1;
272
273 if ((mstpsr4 & (1 << 0)) == 0) /* CMT2 */
274 msk |= 1 << 1;
275
276 if ((mstpsr2 & (1 << 13)) == 0) /* MFI_MFIS */
277 msk2 |= 1 << 17;
278
279 *mskp = msk;
280 *msk2p = msk2;
281
282 return 1;
283}
284
285static void sh7372_icr_to_irqcr(unsigned long icr, u16 *irqcr1p, u16 *irqcr2p)
286{
287 u16 tmp, irqcr1, irqcr2;
288 int k;
289
290 irqcr1 = 0;
291 irqcr2 = 0;
292
293 /* convert INTCA ICR register layout to SYSC IRQCR+IRQCR2 */
294 for (k = 0; k <= 7; k++) {
295 tmp = (icr >> ((7 - k) * 4)) & 0xf;
296 irqcr1 |= (tmp & 0x03) << (k * 2);
297 irqcr2 |= (tmp >> 2) << (k * 2);
298 }
299
300 *irqcr1p = irqcr1;
301 *irqcr2p = irqcr2;
302}
303
Magnus Dammf7dadb32011-12-23 01:23:07 +0100304static void sh7372_setup_sysc(unsigned long msk, unsigned long msk2)
Magnus Dammcf338352011-09-25 23:20:49 +0200305{
306 u16 irqcrx_low, irqcrx_high, irqcry_low, irqcry_high;
307 unsigned long tmp;
308
309 /* read IRQ0A -> IRQ15A mask */
310 tmp = bitrev8(__raw_readb(INTMSK00A));
311 tmp |= bitrev8(__raw_readb(INTMSK10A)) << 8;
312
313 /* setup WUPSMSK from clocks and external IRQ mask */
314 msk = (~msk & 0xc030000f) | (tmp << 4);
315 __raw_writel(msk, WUPSMSK);
316
317 /* propage level/edge trigger for external IRQ 0->15 */
318 sh7372_icr_to_irqcr(__raw_readl(ICR1A), &irqcrx_low, &irqcry_low);
319 sh7372_icr_to_irqcr(__raw_readl(ICR2A), &irqcrx_high, &irqcry_high);
320 __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR);
321 __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR2);
322
323 /* read IRQ16A -> IRQ31A mask */
324 tmp = bitrev8(__raw_readb(INTMSK20A));
325 tmp |= bitrev8(__raw_readb(INTMSK30A)) << 8;
326
327 /* setup WUPSMSK2 from clocks and external IRQ mask */
328 msk2 = (~msk2 & 0x00030000) | tmp;
329 __raw_writel(msk2, WUPSMSK2);
330
331 /* propage level/edge trigger for external IRQ 16->31 */
332 sh7372_icr_to_irqcr(__raw_readl(ICR3A), &irqcrx_low, &irqcry_low);
333 sh7372_icr_to_irqcr(__raw_readl(ICR4A), &irqcrx_high, &irqcry_high);
334 __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR3);
335 __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR4);
336}
Magnus Dammf7dadb32011-12-23 01:23:07 +0100337
338static void sh7372_enter_a3sm_common(int pllc0_on)
339{
Magnus Damm591e2ac2012-07-05 14:46:07 +0900340 /* use INTCA together with SYSC for wakeup */
341 sh7372_setup_sysc(1 << 0, 0);
Magnus Dammf7dadb32011-12-23 01:23:07 +0100342 sh7372_set_reset_vector(__pa(sh7372_resume_core_standby_sysc));
343 sh7372_enter_sysc(pllc0_on, 1 << 12);
344}
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200345
346static void sh7372_enter_a4s_common(int pllc0_on)
347{
348 sh7372_intca_suspend();
349 sh7372_set_reset_vector(SMFRAM);
350 sh7372_enter_sysc(pllc0_on, 1 << 10);
351 sh7372_intca_resume();
352}
353
354static void sh7372_pm_setup_smfram(void)
355{
Magnus Damme26f4062013-06-05 16:45:53 +0900356 /* pass physical address of cpu_resume() to assembly resume code */
357 sh7372_cpu_resume = virt_to_phys(cpu_resume);
358
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200359 memcpy((void *)SMFRAM, sh7372_resume_core_standby_sysc, 0x100);
360}
361#else
362static inline void sh7372_pm_setup_smfram(void) {}
Rafael J. Wysocki911a4722012-07-11 22:55:12 +0200363#endif /* CONFIG_SUSPEND || CONFIG_CPU_IDLE */
Magnus Dammf7dadb32011-12-23 01:23:07 +0100364
Magnus Damm082a8ca2011-04-29 02:39:32 +0900365#ifdef CONFIG_CPU_IDLE
Magnus Damm591e2ac2012-07-05 14:46:07 +0900366static int sh7372_do_idle_core_standby(unsigned long unused)
367{
368 cpu_do_idle(); /* WFI when SYSTBCR == 0x10 -> Core Standby */
369 return 0;
370}
371
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200372static int sh7372_enter_core_standby(struct cpuidle_device *dev,
373 struct cpuidle_driver *drv, int index)
Magnus Damm591e2ac2012-07-05 14:46:07 +0900374{
375 sh7372_set_reset_vector(__pa(sh7372_resume_core_standby_sysc));
376
377 /* enter sleep mode with SYSTBCR to 0x10 */
378 __raw_writel(0x10, SYSTBCR);
379 cpu_suspend(0, sh7372_do_idle_core_standby);
380 __raw_writel(0, SYSTBCR);
381
382 /* disable reset vector translation */
383 __raw_writel(0, SBAR);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200384
385 return 1;
Magnus Damm591e2ac2012-07-05 14:46:07 +0900386}
Magnus Dammcf338352011-09-25 23:20:49 +0200387
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200388static int sh7372_enter_a3sm_pll_on(struct cpuidle_device *dev,
389 struct cpuidle_driver *drv, int index)
Magnus Damm3abd69d2012-07-05 14:46:47 +0900390{
391 sh7372_enter_a3sm_common(1);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200392 return 2;
Magnus Damm3abd69d2012-07-05 14:46:47 +0900393}
394
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200395static int sh7372_enter_a3sm_pll_off(struct cpuidle_device *dev,
396 struct cpuidle_driver *drv, int index)
Magnus Damm3abd69d2012-07-05 14:46:47 +0900397{
398 sh7372_enter_a3sm_common(0);
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200399 return 3;
Magnus Damm3abd69d2012-07-05 14:46:47 +0900400}
401
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200402static int sh7372_enter_a4s(struct cpuidle_device *dev,
403 struct cpuidle_driver *drv, int index)
Magnus Damm082a8ca2011-04-29 02:39:32 +0900404{
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200405 unsigned long msk, msk2;
Magnus Damm082a8ca2011-04-29 02:39:32 +0900406
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200407 if (!sh7372_sysc_valid(&msk, &msk2))
408 return sh7372_enter_a3sm_pll_off(dev, drv, index);
Magnus Damm082a8ca2011-04-29 02:39:32 +0900409
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200410 sh7372_setup_sysc(msk, msk2);
411 sh7372_enter_a4s_common(0);
412 return 4;
Magnus Damm082a8ca2011-04-29 02:39:32 +0900413}
414
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200415static struct cpuidle_driver sh7372_cpuidle_driver = {
416 .name = "sh7372_cpuidle",
417 .owner = THIS_MODULE,
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200418 .state_count = 5,
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200419 .safe_state_index = 0, /* C1 */
420 .states[0] = ARM_CPUIDLE_WFI_STATE,
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200421 .states[1] = {
422 .name = "C2",
423 .desc = "Core Standby Mode",
424 .exit_latency = 10,
425 .target_residency = 20 + 10,
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200426 .enter = sh7372_enter_core_standby,
427 },
428 .states[2] = {
429 .name = "C3",
430 .desc = "A3SM PLL ON",
431 .exit_latency = 20,
432 .target_residency = 30 + 20,
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200433 .enter = sh7372_enter_a3sm_pll_on,
434 },
435 .states[3] = {
436 .name = "C4",
437 .desc = "A3SM PLL OFF",
438 .exit_latency = 120,
439 .target_residency = 30 + 120,
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200440 .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,
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200447 .enter = sh7372_enter_a4s,
448 .disabled = true,
449 },
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200450};
Magnus Damm082a8ca2011-04-29 02:39:32 +0900451
Daniel Lezcanod5047092013-04-03 12:15:15 +0000452static void __init sh7372_cpuidle_init(void)
Magnus Damm082a8ca2011-04-29 02:39:32 +0900453{
Rafael J. Wysocki5b411472012-08-15 20:58:19 +0200454 shmobile_cpuidle_set_driver(&sh7372_cpuidle_driver);
Magnus Damm082a8ca2011-04-29 02:39:32 +0900455}
456#else
Daniel Lezcanod5047092013-04-03 12:15:15 +0000457static void __init sh7372_cpuidle_init(void) {}
Magnus Damm082a8ca2011-04-29 02:39:32 +0900458#endif
459
460#ifdef CONFIG_SUSPEND
Magnus Damm97991652011-04-29 02:28:08 +0900461static int sh7372_enter_suspend(suspend_state_t suspend_state)
462{
Magnus Dammcf338352011-09-25 23:20:49 +0200463 unsigned long msk, msk2;
464
465 /* check active clocks to determine potential wakeup sources */
Rafael J. Wysocki18c081e2012-08-15 20:57:06 +0200466 if (sh7372_sysc_valid(&msk, &msk2) && a4s_suspend_ready) {
467 /* convert INTC mask/sense to SYSC mask/sense */
468 sh7372_setup_sysc(msk, msk2);
Magnus Damm591e2ac2012-07-05 14:46:07 +0900469
Rafael J. Wysocki18c081e2012-08-15 20:57:06 +0200470 /* enter A4S sleep with PLLC0 off */
471 pr_debug("entering A4S\n");
472 sh7372_enter_a4s_common(0);
473 return 0;
Magnus Dammcf338352011-09-25 23:20:49 +0200474 }
Magnus Damm591e2ac2012-07-05 14:46:07 +0900475
476 /* default to enter A3SM sleep with PLLC0 off */
477 pr_debug("entering A3SM\n");
478 sh7372_enter_a3sm_common(0);
Magnus Damm97991652011-04-29 02:28:08 +0900479 return 0;
480}
481
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100482/**
483 * sh7372_pm_notifier_fn - SH7372 PM notifier routine.
484 * @notifier: Unused.
485 * @pm_event: Event being handled.
486 * @unused: Unused.
487 */
488static int sh7372_pm_notifier_fn(struct notifier_block *notifier,
489 unsigned long pm_event, void *unused)
490{
491 switch (pm_event) {
492 case PM_SUSPEND_PREPARE:
493 /*
494 * This is necessary, because the A4R domain has to be "on"
495 * when suspend_device_irqs() and resume_device_irqs() are
496 * executed during system suspend and resume, respectively, so
497 * that those functions don't crash while accessing the INTCS.
498 */
Rafael J. Wysockie7e59a42012-08-07 01:12:56 +0200499 pm_genpd_name_poweron("A4R");
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100500 break;
501 case PM_POST_SUSPEND:
502 pm_genpd_poweroff_unused();
503 break;
504 }
505
506 return NOTIFY_DONE;
507}
508
Magnus Damm97991652011-04-29 02:28:08 +0900509static void sh7372_suspend_init(void)
510{
511 shmobile_suspend_ops.enter = sh7372_enter_suspend;
Rafael J. Wysockia8cf27b2011-12-23 01:24:34 +0100512 pm_notifier(sh7372_pm_notifier_fn, 0);
Magnus Damm97991652011-04-29 02:28:08 +0900513}
514#else
515static void sh7372_suspend_init(void) {}
516#endif
517
Magnus Damm97991652011-04-29 02:28:08 +0900518void __init sh7372_pm_init(void)
519{
520 /* enable DBG hardware block to kick SYSC */
521 __raw_writel(0x0000a500, DBGREG9);
522 __raw_writel(0x0000a501, DBGREG9);
523 __raw_writel(0x00000000, DBGREG1);
524
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200525 /* do not convert A3SM, A3SP, A3SG, A4R power down into A4S */
526 __raw_writel(0, PDNSEL);
527
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200528 sh7372_pm_setup_smfram();
529
Magnus Damm97991652011-04-29 02:28:08 +0900530 sh7372_suspend_init();
Magnus Damm082a8ca2011-04-29 02:39:32 +0900531 sh7372_cpuidle_init();
Magnus Damm97991652011-04-29 02:28:08 +0900532}
Rafael J. Wysockicaaca992012-08-22 12:27:24 +0200533
534void __init sh7372_pm_init_late(void)
535{
536 shmobile_init_late();
537 pm_genpd_name_attach_cpuidle("A4S", 4);
538}