blob: f742c61c8902653df3158d51b46bf67543892326 [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>
Magnus Damm97991652011-04-29 02:28:08 +090024#include <asm/system.h>
25#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>
Magnus Damm97991652011-04-29 02:28:08 +090030
Magnus Dammcf338352011-09-25 23:20:49 +020031/* DBG */
32#define DBGREG1 0xe6100020
33#define DBGREG9 0xe6100040
Magnus Damm97991652011-04-29 02:28:08 +090034
Magnus Dammcf338352011-09-25 23:20:49 +020035/* CPGA */
36#define SYSTBCR 0xe6150024
37#define MSTPSR0 0xe6150030
38#define MSTPSR1 0xe6150038
39#define MSTPSR2 0xe6150040
40#define MSTPSR3 0xe6150048
41#define MSTPSR4 0xe615004c
42#define PLLC01STPCR 0xe61500c8
43
44/* SYSC */
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020045#define SPDCR 0xe6180008
46#define SWUCR 0xe6180014
Magnus Dammcf338352011-09-25 23:20:49 +020047#define SBAR 0xe6180020
Magnus Damm382414b2011-10-19 23:52:50 +020048#define WUPRMSK 0xe6180028
Magnus Dammcf338352011-09-25 23:20:49 +020049#define WUPSMSK 0xe618002c
50#define WUPSMSK2 0xe6180048
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020051#define PSTR 0xe6180080
Magnus Dammcf338352011-09-25 23:20:49 +020052#define WUPSFAC 0xe6180098
53#define IRQCR 0xe618022c
54#define IRQCR2 0xe6180238
55#define IRQCR3 0xe6180244
56#define IRQCR4 0xe6180248
57#define PDNSEL 0xe6180254
58
59/* INTC */
60#define ICR1A 0xe6900000
61#define ICR2A 0xe6900004
62#define ICR3A 0xe6900008
63#define ICR4A 0xe690000c
64#define INTMSK00A 0xe6900040
65#define INTMSK10A 0xe6900044
66#define INTMSK20A 0xe6900048
67#define INTMSK30A 0xe690004c
68
69/* MFIS */
70#define SMFRAM 0xe6a70000
71
72/* AP-System Core */
73#define APARMBAREA 0xe6f10020
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020074
75#define PSTR_RETRIES 100
76#define PSTR_DELAY_US 10
77
78#ifdef CONFIG_PM
79
80static int pd_power_down(struct generic_pm_domain *genpd)
81{
82 struct sh7372_pm_domain *sh7372_pd = to_sh7372_pd(genpd);
83 unsigned int mask = 1 << sh7372_pd->bit_shift;
84
Magnus Damm382414b2011-10-19 23:52:50 +020085 if (sh7372_pd->suspend)
86 sh7372_pd->suspend();
87
88 if (sh7372_pd->stay_on)
89 return 0;
90
Rafael J. Wysockie3e01092011-07-01 22:13:56 +020091 if (__raw_readl(PSTR) & mask) {
92 unsigned int retry_count;
93
94 __raw_writel(mask, SPDCR);
95
96 for (retry_count = PSTR_RETRIES; retry_count; retry_count--) {
97 if (!(__raw_readl(SPDCR) & mask))
98 break;
99 cpu_relax();
100 }
101 }
102
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200103 if (!sh7372_pd->no_debug)
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100104 pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n",
105 genpd->name, mask, __raw_readl(PSTR));
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200106
107 return 0;
108}
109
Rafael J. Wysockibc9f5442011-11-11 13:10:08 +0100110static int __pd_power_up(struct sh7372_pm_domain *sh7372_pd, bool do_resume)
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200111{
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200112 unsigned int mask = 1 << sh7372_pd->bit_shift;
113 unsigned int retry_count;
114 int ret = 0;
115
Magnus Damm382414b2011-10-19 23:52:50 +0200116 if (sh7372_pd->stay_on)
117 goto out;
118
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200119 if (__raw_readl(PSTR) & mask)
120 goto out;
121
122 __raw_writel(mask, SWUCR);
123
124 for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) {
125 if (!(__raw_readl(SWUCR) & mask))
Guennadi Liakhovetskibe2658f2011-11-10 00:43:52 +0100126 break;
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200127 if (retry_count > PSTR_RETRIES)
128 udelay(PSTR_DELAY_US);
129 else
130 cpu_relax();
131 }
Guennadi Liakhovetskibe2658f2011-11-10 00:43:52 +0100132 if (!retry_count)
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200133 ret = -EIO;
134
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200135 if (!sh7372_pd->no_debug)
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100136 pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n",
137 sh7372_pd->genpd.name, mask, __raw_readl(PSTR));
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200138
Magnus Damm382414b2011-10-19 23:52:50 +0200139 out:
Rafael J. Wysockibc9f5442011-11-11 13:10:08 +0100140 if (ret == 0 && sh7372_pd->resume && do_resume)
Magnus Damm382414b2011-10-19 23:52:50 +0200141 sh7372_pd->resume();
142
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200143 return ret;
144}
145
Rafael J. Wysockibc9f5442011-11-11 13:10:08 +0100146static int pd_power_up(struct generic_pm_domain *genpd)
147{
148 return __pd_power_up(to_sh7372_pd(genpd), true);
149}
150
Magnus Damm382414b2011-10-19 23:52:50 +0200151static void sh7372_a4r_suspend(void)
152{
153 sh7372_intcs_suspend();
154 __raw_writel(0x300fffff, WUPRMSK); /* avoid wakeup */
155}
156
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200157static bool pd_active_wakeup(struct device *dev)
158{
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100159 bool (*active_wakeup)(struct device *dev);
160
161 active_wakeup = dev_gpd_data(dev)->ops.active_wakeup;
162 return active_wakeup ? active_wakeup(dev) : true;
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200163}
164
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100165static int sh7372_stop_dev(struct device *dev)
166{
167 int (*stop)(struct device *dev);
168
169 stop = dev_gpd_data(dev)->ops.stop;
170 if (stop) {
171 int ret = stop(dev);
172 if (ret)
173 return ret;
174 }
175 return pm_clk_suspend(dev);
176}
177
178static int sh7372_start_dev(struct device *dev)
179{
180 int (*start)(struct device *dev);
181 int ret;
182
183 ret = pm_clk_resume(dev);
184 if (ret)
185 return ret;
186
187 start = dev_gpd_data(dev)->ops.start;
188 if (start)
189 ret = start(dev);
190
191 return ret;
192}
193
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200194void sh7372_init_pm_domain(struct sh7372_pm_domain *sh7372_pd)
195{
196 struct generic_pm_domain *genpd = &sh7372_pd->genpd;
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100197 struct dev_power_governor *gov = sh7372_pd->gov;
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200198
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100199 pm_genpd_init(genpd, gov ? : &simple_qos_governor, false);
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100200 genpd->dev_ops.stop = sh7372_stop_dev;
201 genpd->dev_ops.start = sh7372_start_dev;
202 genpd->dev_ops.active_wakeup = pd_active_wakeup;
Rafael J. Wysocki0aa2a222011-08-25 15:37:04 +0200203 genpd->dev_irq_safe = true;
Rafael J. Wysocki111058c2011-08-14 13:35:39 +0200204 genpd->power_off = pd_power_down;
205 genpd->power_on = pd_power_up;
Rafael J. Wysockibc9f5442011-11-11 13:10:08 +0100206 __pd_power_up(sh7372_pd, false);
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200207}
208
209void sh7372_add_device_to_domain(struct sh7372_pm_domain *sh7372_pd,
210 struct platform_device *pdev)
211{
212 struct device *dev = &pdev->dev;
213
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200214 pm_genpd_add_device(&sh7372_pd->genpd, dev);
Rafael J. Wysocki4605ab62011-08-25 15:34:12 +0200215 if (pm_clk_no_clocks(dev))
216 pm_clk_add(dev, NULL);
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200217}
218
Rafael J. Wysocki111058c2011-08-14 13:35:39 +0200219void sh7372_pm_add_subdomain(struct sh7372_pm_domain *sh7372_pd,
220 struct sh7372_pm_domain *sh7372_sd)
221{
222 pm_genpd_add_subdomain(&sh7372_pd->genpd, &sh7372_sd->genpd);
223}
224
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200225struct sh7372_pm_domain sh7372_a4lc = {
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100226 .genpd.name = "A4LC",
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200227 .bit_shift = 1,
228};
229
Kuninori Morimotoc1ba5bb2011-07-10 10:12:08 +0200230struct sh7372_pm_domain sh7372_a4mp = {
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100231 .genpd.name = "A4MP",
Kuninori Morimotoc1ba5bb2011-07-10 10:12:08 +0200232 .bit_shift = 2,
233};
234
Magnus Dammd24771d2011-07-10 10:38:22 +0200235struct sh7372_pm_domain sh7372_d4 = {
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100236 .genpd.name = "D4",
Magnus Dammd24771d2011-07-10 10:38:22 +0200237 .bit_shift = 3,
238};
239
Magnus Damm382414b2011-10-19 23:52:50 +0200240struct sh7372_pm_domain sh7372_a4r = {
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100241 .genpd.name = "A4R",
Magnus Damm382414b2011-10-19 23:52:50 +0200242 .bit_shift = 5,
Mark Browna87dc8f2011-12-08 23:27:40 +0100243 .gov = &pm_domain_always_on_gov,
Magnus Damm382414b2011-10-19 23:52:50 +0200244 .suspend = sh7372_a4r_suspend,
245 .resume = sh7372_intcs_resume,
246 .stay_on = true,
247};
248
Magnus Damm33afebf2011-07-01 22:14:45 +0200249struct sh7372_pm_domain sh7372_a3rv = {
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100250 .genpd.name = "A3RV",
Magnus Damm33afebf2011-07-01 22:14:45 +0200251 .bit_shift = 6,
252};
253
Magnus Damm082517a2011-07-01 22:14:53 +0200254struct sh7372_pm_domain sh7372_a3ri = {
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100255 .genpd.name = "A3RI",
Magnus Damm082517a2011-07-01 22:14:53 +0200256 .bit_shift = 8,
257};
258
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200259struct sh7372_pm_domain sh7372_a3sp = {
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100260 .genpd.name = "A3SP",
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200261 .bit_shift = 11,
Mark Browna87dc8f2011-12-08 23:27:40 +0100262 .gov = &pm_domain_always_on_gov,
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200263 .no_debug = true,
264};
265
Rafael J. Wysocki88995e82011-11-17 21:39:55 +0100266static void sh7372_a3sp_init(void)
267{
268 /* serial consoles make use of SCIF hardware located in A3SP,
269 * keep such power domain on if "no_console_suspend" is set.
270 */
271 sh7372_a3sp.stay_on = !console_suspend_enabled;
272}
273
Magnus Dammc47586b2011-07-01 22:15:01 +0200274struct sh7372_pm_domain sh7372_a3sg = {
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +0100275 .genpd.name = "A3SG",
Magnus Dammc47586b2011-07-01 22:15:01 +0200276 .bit_shift = 13,
277};
278
Rafael J. Wysocki88995e82011-11-17 21:39:55 +0100279#else /* !CONFIG_PM */
280
281static inline void sh7372_a3sp_init(void) {}
282
283#endif /* !CONFIG_PM */
Rafael J. Wysockie3e01092011-07-01 22:13:56 +0200284
Magnus Damma0089bd2011-09-25 23:21:02 +0200285#if defined(CONFIG_SUSPEND) || defined(CONFIG_CPU_IDLE)
Magnus Damm06b84162011-09-25 23:18:42 +0200286static int sh7372_do_idle_core_standby(unsigned long unused)
287{
288 cpu_do_idle(); /* WFI when SYSTBCR == 0x10 -> Core Standby */
289 return 0;
290}
291
Paul Mundt66ad1292011-05-25 11:22:58 +0900292static void sh7372_enter_core_standby(void)
Magnus Damm97991652011-04-29 02:28:08 +0900293{
Magnus Damm06b84162011-09-25 23:18:42 +0200294 /* set reset vector, translate 4k */
Magnus Dammcf338352011-09-25 23:20:49 +0200295 __raw_writel(__pa(sh7372_resume_core_standby_a3sm), SBAR);
Magnus Damm06b84162011-09-25 23:18:42 +0200296 __raw_writel(0, APARMBAREA);
Magnus Damm97991652011-04-29 02:28:08 +0900297
Magnus Damm06b84162011-09-25 23:18:42 +0200298 /* enter sleep mode with SYSTBCR to 0x10 */
299 __raw_writel(0x10, SYSTBCR);
300 cpu_suspend(0, sh7372_do_idle_core_standby);
301 __raw_writel(0, SYSTBCR);
Magnus Damm97991652011-04-29 02:28:08 +0900302
Magnus Damm06b84162011-09-25 23:18:42 +0200303 /* disable reset vector translation */
304 __raw_writel(0, SBAR);
Magnus Damm97991652011-04-29 02:28:08 +0900305}
Magnus Damma0089bd2011-09-25 23:21:02 +0200306#endif
Magnus Damm97991652011-04-29 02:28:08 +0900307
Magnus Damma0089bd2011-09-25 23:21:02 +0200308#ifdef CONFIG_SUSPEND
Magnus Dammcf338352011-09-25 23:20:49 +0200309static void sh7372_enter_a3sm_common(int pllc0_on)
310{
311 /* set reset vector, translate 4k */
312 __raw_writel(__pa(sh7372_resume_core_standby_a3sm), SBAR);
313 __raw_writel(0, APARMBAREA);
314
315 if (pllc0_on)
316 __raw_writel(0, PLLC01STPCR);
317 else
318 __raw_writel(1 << 28, PLLC01STPCR);
319
320 __raw_writel(0, PDNSEL); /* power-down A3SM only, not A4S */
321 __raw_readl(WUPSFAC); /* read wakeup int. factor before sleep */
322 cpu_suspend(0, sh7372_do_idle_a3sm);
323 __raw_readl(WUPSFAC); /* read wakeup int. factor after wakeup */
324
325 /* disable reset vector translation */
326 __raw_writel(0, SBAR);
327}
328
329static int sh7372_a3sm_valid(unsigned long *mskp, unsigned long *msk2p)
330{
331 unsigned long mstpsr0, mstpsr1, mstpsr2, mstpsr3, mstpsr4;
332 unsigned long msk, msk2;
333
334 /* check active clocks to determine potential wakeup sources */
335
336 mstpsr0 = __raw_readl(MSTPSR0);
337 if ((mstpsr0 & 0x00000003) != 0x00000003) {
338 pr_debug("sh7372 mstpsr0 0x%08lx\n", mstpsr0);
339 return 0;
340 }
341
342 mstpsr1 = __raw_readl(MSTPSR1);
343 if ((mstpsr1 & 0xff079b7f) != 0xff079b7f) {
344 pr_debug("sh7372 mstpsr1 0x%08lx\n", mstpsr1);
345 return 0;
346 }
347
348 mstpsr2 = __raw_readl(MSTPSR2);
349 if ((mstpsr2 & 0x000741ff) != 0x000741ff) {
350 pr_debug("sh7372 mstpsr2 0x%08lx\n", mstpsr2);
351 return 0;
352 }
353
354 mstpsr3 = __raw_readl(MSTPSR3);
355 if ((mstpsr3 & 0x1a60f010) != 0x1a60f010) {
356 pr_debug("sh7372 mstpsr3 0x%08lx\n", mstpsr3);
357 return 0;
358 }
359
360 mstpsr4 = __raw_readl(MSTPSR4);
361 if ((mstpsr4 & 0x00008cf0) != 0x00008cf0) {
362 pr_debug("sh7372 mstpsr4 0x%08lx\n", mstpsr4);
363 return 0;
364 }
365
366 msk = 0;
367 msk2 = 0;
368
369 /* make bitmaps of limited number of wakeup sources */
370
371 if ((mstpsr2 & (1 << 23)) == 0) /* SPU2 */
372 msk |= 1 << 31;
373
374 if ((mstpsr2 & (1 << 12)) == 0) /* MFI_MFIM */
375 msk |= 1 << 21;
376
377 if ((mstpsr4 & (1 << 3)) == 0) /* KEYSC */
378 msk |= 1 << 2;
379
380 if ((mstpsr1 & (1 << 24)) == 0) /* CMT0 */
381 msk |= 1 << 1;
382
383 if ((mstpsr3 & (1 << 29)) == 0) /* CMT1 */
384 msk |= 1 << 1;
385
386 if ((mstpsr4 & (1 << 0)) == 0) /* CMT2 */
387 msk |= 1 << 1;
388
389 if ((mstpsr2 & (1 << 13)) == 0) /* MFI_MFIS */
390 msk2 |= 1 << 17;
391
392 *mskp = msk;
393 *msk2p = msk2;
394
395 return 1;
396}
397
398static void sh7372_icr_to_irqcr(unsigned long icr, u16 *irqcr1p, u16 *irqcr2p)
399{
400 u16 tmp, irqcr1, irqcr2;
401 int k;
402
403 irqcr1 = 0;
404 irqcr2 = 0;
405
406 /* convert INTCA ICR register layout to SYSC IRQCR+IRQCR2 */
407 for (k = 0; k <= 7; k++) {
408 tmp = (icr >> ((7 - k) * 4)) & 0xf;
409 irqcr1 |= (tmp & 0x03) << (k * 2);
410 irqcr2 |= (tmp >> 2) << (k * 2);
411 }
412
413 *irqcr1p = irqcr1;
414 *irqcr2p = irqcr2;
415}
416
417static void sh7372_setup_a3sm(unsigned long msk, unsigned long msk2)
418{
419 u16 irqcrx_low, irqcrx_high, irqcry_low, irqcry_high;
420 unsigned long tmp;
421
422 /* read IRQ0A -> IRQ15A mask */
423 tmp = bitrev8(__raw_readb(INTMSK00A));
424 tmp |= bitrev8(__raw_readb(INTMSK10A)) << 8;
425
426 /* setup WUPSMSK from clocks and external IRQ mask */
427 msk = (~msk & 0xc030000f) | (tmp << 4);
428 __raw_writel(msk, WUPSMSK);
429
430 /* propage level/edge trigger for external IRQ 0->15 */
431 sh7372_icr_to_irqcr(__raw_readl(ICR1A), &irqcrx_low, &irqcry_low);
432 sh7372_icr_to_irqcr(__raw_readl(ICR2A), &irqcrx_high, &irqcry_high);
433 __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR);
434 __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR2);
435
436 /* read IRQ16A -> IRQ31A mask */
437 tmp = bitrev8(__raw_readb(INTMSK20A));
438 tmp |= bitrev8(__raw_readb(INTMSK30A)) << 8;
439
440 /* setup WUPSMSK2 from clocks and external IRQ mask */
441 msk2 = (~msk2 & 0x00030000) | tmp;
442 __raw_writel(msk2, WUPSMSK2);
443
444 /* propage level/edge trigger for external IRQ 16->31 */
445 sh7372_icr_to_irqcr(__raw_readl(ICR3A), &irqcrx_low, &irqcry_low);
446 sh7372_icr_to_irqcr(__raw_readl(ICR4A), &irqcrx_high, &irqcry_high);
447 __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR3);
448 __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR4);
449}
Magnus Damma0089bd2011-09-25 23:21:02 +0200450#endif
Magnus Dammcf338352011-09-25 23:20:49 +0200451
Magnus Damm082a8ca2011-04-29 02:39:32 +0900452#ifdef CONFIG_CPU_IDLE
Magnus Dammcf338352011-09-25 23:20:49 +0200453
Magnus Dammb73b5c42011-11-11 14:01:30 +0900454static void sh7372_cpuidle_setup(struct cpuidle_driver *drv)
Magnus Damm082a8ca2011-04-29 02:39:32 +0900455{
Magnus Dammb73b5c42011-11-11 14:01:30 +0900456 struct cpuidle_state *state = &drv->states[drv->state_count];
Magnus Damm082a8ca2011-04-29 02:39:32 +0900457
Magnus Damm082a8ca2011-04-29 02:39:32 +0900458 snprintf(state->name, CPUIDLE_NAME_LEN, "C2");
459 strncpy(state->desc, "Core Standby Mode", CPUIDLE_DESC_LEN);
460 state->exit_latency = 10;
461 state->target_residency = 20 + 10;
Magnus Dammb73b5c42011-11-11 14:01:30 +0900462 state->flags = CPUIDLE_FLAG_TIME_VALID;
463 shmobile_cpuidle_modes[drv->state_count] = sh7372_enter_core_standby;
Magnus Damm082a8ca2011-04-29 02:39:32 +0900464
Magnus Dammb73b5c42011-11-11 14:01:30 +0900465 drv->state_count++;
Magnus Damm082a8ca2011-04-29 02:39:32 +0900466}
467
468static void sh7372_cpuidle_init(void)
469{
470 shmobile_cpuidle_setup = sh7372_cpuidle_setup;
471}
472#else
473static void sh7372_cpuidle_init(void) {}
474#endif
475
476#ifdef CONFIG_SUSPEND
Magnus Dammcf338352011-09-25 23:20:49 +0200477
Magnus Damm97991652011-04-29 02:28:08 +0900478static int sh7372_enter_suspend(suspend_state_t suspend_state)
479{
Magnus Dammcf338352011-09-25 23:20:49 +0200480 unsigned long msk, msk2;
481
482 /* check active clocks to determine potential wakeup sources */
483 if (sh7372_a3sm_valid(&msk, &msk2)) {
484
485 /* convert INTC mask and sense to SYSC mask and sense */
486 sh7372_setup_a3sm(msk, msk2);
487
488 /* enter A3SM sleep with PLLC0 off */
489 pr_debug("entering A3SM\n");
490 sh7372_enter_a3sm_common(0);
491 } else {
492 /* default to Core Standby that supports all wakeup sources */
493 pr_debug("entering Core Standby\n");
494 sh7372_enter_core_standby();
495 }
Magnus Damm97991652011-04-29 02:28:08 +0900496 return 0;
497}
498
499static void sh7372_suspend_init(void)
500{
501 shmobile_suspend_ops.enter = sh7372_enter_suspend;
502}
503#else
504static void sh7372_suspend_init(void) {}
505#endif
506
Magnus Damm97991652011-04-29 02:28:08 +0900507void __init sh7372_pm_init(void)
508{
509 /* enable DBG hardware block to kick SYSC */
510 __raw_writel(0x0000a500, DBGREG9);
511 __raw_writel(0x0000a501, DBGREG9);
512 __raw_writel(0x00000000, DBGREG1);
513
Magnus Dammd93f5cd2011-10-19 23:52:41 +0200514 /* do not convert A3SM, A3SP, A3SG, A4R power down into A4S */
515 __raw_writel(0, PDNSEL);
516
Rafael J. Wysocki88995e82011-11-17 21:39:55 +0100517 sh7372_a3sp_init();
Magnus Damm056879d2011-11-10 00:44:01 +0100518
Magnus Damm97991652011-04-29 02:28:08 +0900519 sh7372_suspend_init();
Magnus Damm082a8ca2011-04-29 02:39:32 +0900520 sh7372_cpuidle_init();
Magnus Damm97991652011-04-29 02:28:08 +0900521}