Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 1 | /* |
| 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 Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 13 | #include <linux/cpuidle.h> |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/list.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/slab.h> |
Rafael J. Wysocki | b5e8d26 | 2011-08-25 15:34:19 +0200 | [diff] [blame] | 18 | #include <linux/pm_clock.h> |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/delay.h> |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 21 | #include <linux/irq.h> |
| 22 | #include <linux/bitrev.h> |
Magnus Damm | 056879d | 2011-11-10 00:44:01 +0100 | [diff] [blame] | 23 | #include <linux/console.h> |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 24 | #include <asm/io.h> |
| 25 | #include <asm/tlbflush.h> |
Magnus Damm | 06b8416 | 2011-09-25 23:18:42 +0200 | [diff] [blame] | 26 | #include <asm/suspend.h> |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 27 | #include <mach/common.h> |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 28 | #include <mach/sh7372.h> |
Kuninori Morimoto | b9299a7 | 2012-07-05 01:28:32 -0700 | [diff] [blame] | 29 | #include <mach/pm-rmobile.h> |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 30 | |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 31 | /* DBG */ |
| 32 | #define DBGREG1 0xe6100020 |
| 33 | #define DBGREG9 0xe6100040 |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 34 | |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 35 | /* 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 */ |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 45 | #define SBAR 0xe6180020 |
Magnus Damm | 382414b | 2011-10-19 23:52:50 +0200 | [diff] [blame] | 46 | #define WUPRMSK 0xe6180028 |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 47 | #define WUPSMSK 0xe618002c |
| 48 | #define WUPSMSK2 0xe6180048 |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 49 | #define WUPSFAC 0xe6180098 |
| 50 | #define IRQCR 0xe618022c |
| 51 | #define IRQCR2 0xe6180238 |
| 52 | #define IRQCR3 0xe6180244 |
| 53 | #define IRQCR4 0xe6180248 |
| 54 | #define PDNSEL 0xe6180254 |
| 55 | |
| 56 | /* INTC */ |
| 57 | #define ICR1A 0xe6900000 |
| 58 | #define ICR2A 0xe6900004 |
| 59 | #define ICR3A 0xe6900008 |
| 60 | #define ICR4A 0xe690000c |
| 61 | #define INTMSK00A 0xe6900040 |
| 62 | #define INTMSK10A 0xe6900044 |
| 63 | #define INTMSK20A 0xe6900048 |
| 64 | #define INTMSK30A 0xe690004c |
| 65 | |
| 66 | /* MFIS */ |
| 67 | #define SMFRAM 0xe6a70000 |
| 68 | |
| 69 | /* AP-System Core */ |
| 70 | #define APARMBAREA 0xe6f10020 |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 71 | |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 72 | #ifdef CONFIG_PM |
| 73 | |
Kuninori Morimoto | b9299a7 | 2012-07-05 01:28:32 -0700 | [diff] [blame] | 74 | struct rmobile_pm_domain sh7372_pd_a4lc = { |
| 75 | .genpd.name = "A4LC", |
| 76 | .bit_shift = 1, |
| 77 | }; |
| 78 | |
| 79 | struct rmobile_pm_domain sh7372_pd_a4mp = { |
| 80 | .genpd.name = "A4MP", |
| 81 | .bit_shift = 2, |
| 82 | }; |
| 83 | |
| 84 | struct rmobile_pm_domain sh7372_pd_d4 = { |
| 85 | .genpd.name = "D4", |
| 86 | .bit_shift = 3, |
| 87 | }; |
| 88 | |
| 89 | static int sh7372_a4r_pd_suspend(void) |
| 90 | { |
| 91 | sh7372_intcs_suspend(); |
| 92 | __raw_writel(0x300fffff, WUPRMSK); /* avoid wakeup */ |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | struct rmobile_pm_domain sh7372_pd_a4r = { |
| 97 | .genpd.name = "A4R", |
| 98 | .bit_shift = 5, |
| 99 | .suspend = sh7372_a4r_pd_suspend, |
| 100 | .resume = sh7372_intcs_resume, |
| 101 | }; |
| 102 | |
| 103 | struct rmobile_pm_domain sh7372_pd_a3rv = { |
| 104 | .genpd.name = "A3RV", |
| 105 | .bit_shift = 6, |
| 106 | }; |
| 107 | |
| 108 | struct rmobile_pm_domain sh7372_pd_a3ri = { |
| 109 | .genpd.name = "A3RI", |
| 110 | .bit_shift = 8, |
| 111 | }; |
| 112 | |
Rafael J. Wysocki | 70fe7b2 | 2012-08-15 20:54:15 +0200 | [diff] [blame^] | 113 | static bool a4s_suspend_ready; |
| 114 | |
Kuninori Morimoto | b9299a7 | 2012-07-05 01:28:32 -0700 | [diff] [blame] | 115 | static int sh7372_pd_a4s_suspend(void) |
| 116 | { |
| 117 | /* |
| 118 | * The A4S domain contains the CPU core and therefore it should |
Rafael J. Wysocki | 70fe7b2 | 2012-08-15 20:54:15 +0200 | [diff] [blame^] | 119 | * only be turned off if the CPU is not in use. This may happen |
| 120 | * during system suspend, when SYSC is going to be used for generating |
| 121 | * resume signals and a4s_suspend_ready is set to let |
| 122 | * sh7372_enter_suspend() know that it can turn A4S off. |
Kuninori Morimoto | b9299a7 | 2012-07-05 01:28:32 -0700 | [diff] [blame] | 123 | */ |
Rafael J. Wysocki | 70fe7b2 | 2012-08-15 20:54:15 +0200 | [diff] [blame^] | 124 | a4s_suspend_ready = true; |
Kuninori Morimoto | b9299a7 | 2012-07-05 01:28:32 -0700 | [diff] [blame] | 125 | return -EBUSY; |
| 126 | } |
| 127 | |
Rafael J. Wysocki | 70fe7b2 | 2012-08-15 20:54:15 +0200 | [diff] [blame^] | 128 | static void sh7372_pd_a4s_resume(void) |
| 129 | { |
| 130 | a4s_suspend_ready = false; |
| 131 | } |
| 132 | |
Kuninori Morimoto | b9299a7 | 2012-07-05 01:28:32 -0700 | [diff] [blame] | 133 | struct rmobile_pm_domain sh7372_pd_a4s = { |
| 134 | .genpd.name = "A4S", |
| 135 | .bit_shift = 10, |
| 136 | .gov = &pm_domain_always_on_gov, |
| 137 | .no_debug = true, |
| 138 | .suspend = sh7372_pd_a4s_suspend, |
Rafael J. Wysocki | 70fe7b2 | 2012-08-15 20:54:15 +0200 | [diff] [blame^] | 139 | .resume = sh7372_pd_a4s_resume, |
Kuninori Morimoto | b9299a7 | 2012-07-05 01:28:32 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | static int sh7372_a3sp_pd_suspend(void) |
| 143 | { |
| 144 | /* |
| 145 | * Serial consoles make use of SCIF hardware located in A3SP, |
| 146 | * keep such power domain on if "no_console_suspend" is set. |
| 147 | */ |
| 148 | return console_suspend_enabled ? 0 : -EBUSY; |
| 149 | } |
| 150 | |
| 151 | struct rmobile_pm_domain sh7372_pd_a3sp = { |
| 152 | .genpd.name = "A3SP", |
| 153 | .bit_shift = 11, |
| 154 | .gov = &pm_domain_always_on_gov, |
| 155 | .no_debug = true, |
| 156 | .suspend = sh7372_a3sp_pd_suspend, |
| 157 | }; |
| 158 | |
| 159 | struct rmobile_pm_domain sh7372_pd_a3sg = { |
| 160 | .genpd.name = "A3SG", |
| 161 | .bit_shift = 13, |
| 162 | }; |
| 163 | |
Kuninori Morimoto | 1645b76 | 2012-06-24 22:00:13 +0200 | [diff] [blame] | 164 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 165 | |
Magnus Damm | a0089bd6 | 2011-09-25 23:21:02 +0200 | [diff] [blame] | 166 | #if defined(CONFIG_SUSPEND) || defined(CONFIG_CPU_IDLE) |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 167 | static void sh7372_set_reset_vector(unsigned long address) |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 168 | { |
Magnus Damm | 06b8416 | 2011-09-25 23:18:42 +0200 | [diff] [blame] | 169 | /* set reset vector, translate 4k */ |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 170 | __raw_writel(address, SBAR); |
Magnus Damm | 06b8416 | 2011-09-25 23:18:42 +0200 | [diff] [blame] | 171 | __raw_writel(0, APARMBAREA); |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 174 | static void sh7372_enter_sysc(int pllc0_on, unsigned long sleep_mode) |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 175 | { |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 176 | if (pllc0_on) |
| 177 | __raw_writel(0, PLLC01STPCR); |
| 178 | else |
| 179 | __raw_writel(1 << 28, PLLC01STPCR); |
| 180 | |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 181 | __raw_readl(WUPSFAC); /* read wakeup int. factor before sleep */ |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 182 | cpu_suspend(sleep_mode, sh7372_do_idle_sysc); |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 183 | __raw_readl(WUPSFAC); /* read wakeup int. factor after wakeup */ |
| 184 | |
| 185 | /* disable reset vector translation */ |
| 186 | __raw_writel(0, SBAR); |
| 187 | } |
| 188 | |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 189 | static int sh7372_sysc_valid(unsigned long *mskp, unsigned long *msk2p) |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 190 | { |
| 191 | unsigned long mstpsr0, mstpsr1, mstpsr2, mstpsr3, mstpsr4; |
| 192 | unsigned long msk, msk2; |
| 193 | |
| 194 | /* check active clocks to determine potential wakeup sources */ |
| 195 | |
| 196 | mstpsr0 = __raw_readl(MSTPSR0); |
| 197 | if ((mstpsr0 & 0x00000003) != 0x00000003) { |
| 198 | pr_debug("sh7372 mstpsr0 0x%08lx\n", mstpsr0); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | mstpsr1 = __raw_readl(MSTPSR1); |
| 203 | if ((mstpsr1 & 0xff079b7f) != 0xff079b7f) { |
| 204 | pr_debug("sh7372 mstpsr1 0x%08lx\n", mstpsr1); |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | mstpsr2 = __raw_readl(MSTPSR2); |
| 209 | if ((mstpsr2 & 0x000741ff) != 0x000741ff) { |
| 210 | pr_debug("sh7372 mstpsr2 0x%08lx\n", mstpsr2); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | mstpsr3 = __raw_readl(MSTPSR3); |
| 215 | if ((mstpsr3 & 0x1a60f010) != 0x1a60f010) { |
| 216 | pr_debug("sh7372 mstpsr3 0x%08lx\n", mstpsr3); |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | mstpsr4 = __raw_readl(MSTPSR4); |
| 221 | if ((mstpsr4 & 0x00008cf0) != 0x00008cf0) { |
| 222 | pr_debug("sh7372 mstpsr4 0x%08lx\n", mstpsr4); |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | msk = 0; |
| 227 | msk2 = 0; |
| 228 | |
| 229 | /* make bitmaps of limited number of wakeup sources */ |
| 230 | |
| 231 | if ((mstpsr2 & (1 << 23)) == 0) /* SPU2 */ |
| 232 | msk |= 1 << 31; |
| 233 | |
| 234 | if ((mstpsr2 & (1 << 12)) == 0) /* MFI_MFIM */ |
| 235 | msk |= 1 << 21; |
| 236 | |
| 237 | if ((mstpsr4 & (1 << 3)) == 0) /* KEYSC */ |
| 238 | msk |= 1 << 2; |
| 239 | |
| 240 | if ((mstpsr1 & (1 << 24)) == 0) /* CMT0 */ |
| 241 | msk |= 1 << 1; |
| 242 | |
| 243 | if ((mstpsr3 & (1 << 29)) == 0) /* CMT1 */ |
| 244 | msk |= 1 << 1; |
| 245 | |
| 246 | if ((mstpsr4 & (1 << 0)) == 0) /* CMT2 */ |
| 247 | msk |= 1 << 1; |
| 248 | |
| 249 | if ((mstpsr2 & (1 << 13)) == 0) /* MFI_MFIS */ |
| 250 | msk2 |= 1 << 17; |
| 251 | |
| 252 | *mskp = msk; |
| 253 | *msk2p = msk2; |
| 254 | |
| 255 | return 1; |
| 256 | } |
| 257 | |
| 258 | static void sh7372_icr_to_irqcr(unsigned long icr, u16 *irqcr1p, u16 *irqcr2p) |
| 259 | { |
| 260 | u16 tmp, irqcr1, irqcr2; |
| 261 | int k; |
| 262 | |
| 263 | irqcr1 = 0; |
| 264 | irqcr2 = 0; |
| 265 | |
| 266 | /* convert INTCA ICR register layout to SYSC IRQCR+IRQCR2 */ |
| 267 | for (k = 0; k <= 7; k++) { |
| 268 | tmp = (icr >> ((7 - k) * 4)) & 0xf; |
| 269 | irqcr1 |= (tmp & 0x03) << (k * 2); |
| 270 | irqcr2 |= (tmp >> 2) << (k * 2); |
| 271 | } |
| 272 | |
| 273 | *irqcr1p = irqcr1; |
| 274 | *irqcr2p = irqcr2; |
| 275 | } |
| 276 | |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 277 | static void sh7372_setup_sysc(unsigned long msk, unsigned long msk2) |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 278 | { |
| 279 | u16 irqcrx_low, irqcrx_high, irqcry_low, irqcry_high; |
| 280 | unsigned long tmp; |
| 281 | |
| 282 | /* read IRQ0A -> IRQ15A mask */ |
| 283 | tmp = bitrev8(__raw_readb(INTMSK00A)); |
| 284 | tmp |= bitrev8(__raw_readb(INTMSK10A)) << 8; |
| 285 | |
| 286 | /* setup WUPSMSK from clocks and external IRQ mask */ |
| 287 | msk = (~msk & 0xc030000f) | (tmp << 4); |
| 288 | __raw_writel(msk, WUPSMSK); |
| 289 | |
| 290 | /* propage level/edge trigger for external IRQ 0->15 */ |
| 291 | sh7372_icr_to_irqcr(__raw_readl(ICR1A), &irqcrx_low, &irqcry_low); |
| 292 | sh7372_icr_to_irqcr(__raw_readl(ICR2A), &irqcrx_high, &irqcry_high); |
| 293 | __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR); |
| 294 | __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR2); |
| 295 | |
| 296 | /* read IRQ16A -> IRQ31A mask */ |
| 297 | tmp = bitrev8(__raw_readb(INTMSK20A)); |
| 298 | tmp |= bitrev8(__raw_readb(INTMSK30A)) << 8; |
| 299 | |
| 300 | /* setup WUPSMSK2 from clocks and external IRQ mask */ |
| 301 | msk2 = (~msk2 & 0x00030000) | tmp; |
| 302 | __raw_writel(msk2, WUPSMSK2); |
| 303 | |
| 304 | /* propage level/edge trigger for external IRQ 16->31 */ |
| 305 | sh7372_icr_to_irqcr(__raw_readl(ICR3A), &irqcrx_low, &irqcry_low); |
| 306 | sh7372_icr_to_irqcr(__raw_readl(ICR4A), &irqcrx_high, &irqcry_high); |
| 307 | __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR3); |
| 308 | __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR4); |
| 309 | } |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 310 | |
| 311 | static void sh7372_enter_a3sm_common(int pllc0_on) |
| 312 | { |
Magnus Damm | 591e2ac | 2012-07-05 14:46:07 +0900 | [diff] [blame] | 313 | /* use INTCA together with SYSC for wakeup */ |
| 314 | sh7372_setup_sysc(1 << 0, 0); |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 315 | sh7372_set_reset_vector(__pa(sh7372_resume_core_standby_sysc)); |
| 316 | sh7372_enter_sysc(pllc0_on, 1 << 12); |
| 317 | } |
Rafael J. Wysocki | 911a472 | 2012-07-11 22:55:12 +0200 | [diff] [blame] | 318 | #endif /* CONFIG_SUSPEND || CONFIG_CPU_IDLE */ |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 319 | |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 320 | #ifdef CONFIG_CPU_IDLE |
Magnus Damm | 591e2ac | 2012-07-05 14:46:07 +0900 | [diff] [blame] | 321 | static int sh7372_do_idle_core_standby(unsigned long unused) |
| 322 | { |
| 323 | cpu_do_idle(); /* WFI when SYSTBCR == 0x10 -> Core Standby */ |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static void sh7372_enter_core_standby(void) |
| 328 | { |
| 329 | sh7372_set_reset_vector(__pa(sh7372_resume_core_standby_sysc)); |
| 330 | |
| 331 | /* enter sleep mode with SYSTBCR to 0x10 */ |
| 332 | __raw_writel(0x10, SYSTBCR); |
| 333 | cpu_suspend(0, sh7372_do_idle_core_standby); |
| 334 | __raw_writel(0, SYSTBCR); |
| 335 | |
| 336 | /* disable reset vector translation */ |
| 337 | __raw_writel(0, SBAR); |
| 338 | } |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 339 | |
Magnus Damm | 3abd69d | 2012-07-05 14:46:47 +0900 | [diff] [blame] | 340 | static void sh7372_enter_a3sm_pll_on(void) |
| 341 | { |
| 342 | sh7372_enter_a3sm_common(1); |
| 343 | } |
| 344 | |
| 345 | static void sh7372_enter_a3sm_pll_off(void) |
| 346 | { |
| 347 | sh7372_enter_a3sm_common(0); |
| 348 | } |
| 349 | |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 350 | static void sh7372_cpuidle_setup(struct cpuidle_driver *drv) |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 351 | { |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 352 | struct cpuidle_state *state = &drv->states[drv->state_count]; |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 353 | |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 354 | snprintf(state->name, CPUIDLE_NAME_LEN, "C2"); |
| 355 | strncpy(state->desc, "Core Standby Mode", CPUIDLE_DESC_LEN); |
| 356 | state->exit_latency = 10; |
| 357 | state->target_residency = 20 + 10; |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 358 | state->flags = CPUIDLE_FLAG_TIME_VALID; |
| 359 | shmobile_cpuidle_modes[drv->state_count] = sh7372_enter_core_standby; |
Magnus Damm | 3abd69d | 2012-07-05 14:46:47 +0900 | [diff] [blame] | 360 | drv->state_count++; |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 361 | |
Magnus Damm | 3abd69d | 2012-07-05 14:46:47 +0900 | [diff] [blame] | 362 | state = &drv->states[drv->state_count]; |
| 363 | snprintf(state->name, CPUIDLE_NAME_LEN, "C3"); |
| 364 | strncpy(state->desc, "A3SM PLL ON", CPUIDLE_DESC_LEN); |
| 365 | state->exit_latency = 20; |
| 366 | state->target_residency = 30 + 20; |
| 367 | state->flags = CPUIDLE_FLAG_TIME_VALID; |
| 368 | shmobile_cpuidle_modes[drv->state_count] = sh7372_enter_a3sm_pll_on; |
| 369 | drv->state_count++; |
| 370 | |
| 371 | state = &drv->states[drv->state_count]; |
| 372 | snprintf(state->name, CPUIDLE_NAME_LEN, "C4"); |
| 373 | strncpy(state->desc, "A3SM PLL OFF", CPUIDLE_DESC_LEN); |
| 374 | state->exit_latency = 120; |
| 375 | state->target_residency = 30 + 120; |
| 376 | state->flags = CPUIDLE_FLAG_TIME_VALID; |
| 377 | shmobile_cpuidle_modes[drv->state_count] = sh7372_enter_a3sm_pll_off; |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 378 | drv->state_count++; |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | static void sh7372_cpuidle_init(void) |
| 382 | { |
| 383 | shmobile_cpuidle_setup = sh7372_cpuidle_setup; |
| 384 | } |
| 385 | #else |
| 386 | static void sh7372_cpuidle_init(void) {} |
| 387 | #endif |
| 388 | |
| 389 | #ifdef CONFIG_SUSPEND |
Magnus Damm | 3abd69d | 2012-07-05 14:46:47 +0900 | [diff] [blame] | 390 | static void sh7372_enter_a4s_common(int pllc0_on) |
| 391 | { |
| 392 | sh7372_intca_suspend(); |
| 393 | memcpy((void *)SMFRAM, sh7372_resume_core_standby_sysc, 0x100); |
| 394 | sh7372_set_reset_vector(SMFRAM); |
| 395 | sh7372_enter_sysc(pllc0_on, 1 << 10); |
| 396 | sh7372_intca_resume(); |
| 397 | } |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 398 | |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 399 | static int sh7372_enter_suspend(suspend_state_t suspend_state) |
| 400 | { |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 401 | unsigned long msk, msk2; |
| 402 | |
| 403 | /* check active clocks to determine potential wakeup sources */ |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 404 | if (sh7372_sysc_valid(&msk, &msk2)) { |
Rafael J. Wysocki | 70fe7b2 | 2012-08-15 20:54:15 +0200 | [diff] [blame^] | 405 | if (!console_suspend_enabled && a4s_suspend_ready) { |
Magnus Damm | 591e2ac | 2012-07-05 14:46:07 +0900 | [diff] [blame] | 406 | /* convert INTC mask/sense to SYSC mask/sense */ |
| 407 | sh7372_setup_sysc(msk, msk2); |
| 408 | |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 409 | /* enter A4S sleep with PLLC0 off */ |
| 410 | pr_debug("entering A4S\n"); |
| 411 | sh7372_enter_a4s_common(0); |
Magnus Damm | 591e2ac | 2012-07-05 14:46:07 +0900 | [diff] [blame] | 412 | return 0; |
Magnus Damm | f7dadb3 | 2011-12-23 01:23:07 +0100 | [diff] [blame] | 413 | } |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 414 | } |
Magnus Damm | 591e2ac | 2012-07-05 14:46:07 +0900 | [diff] [blame] | 415 | |
| 416 | /* default to enter A3SM sleep with PLLC0 off */ |
| 417 | pr_debug("entering A3SM\n"); |
| 418 | sh7372_enter_a3sm_common(0); |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 419 | return 0; |
| 420 | } |
| 421 | |
Rafael J. Wysocki | a8cf27b | 2011-12-23 01:24:34 +0100 | [diff] [blame] | 422 | /** |
| 423 | * sh7372_pm_notifier_fn - SH7372 PM notifier routine. |
| 424 | * @notifier: Unused. |
| 425 | * @pm_event: Event being handled. |
| 426 | * @unused: Unused. |
| 427 | */ |
| 428 | static int sh7372_pm_notifier_fn(struct notifier_block *notifier, |
| 429 | unsigned long pm_event, void *unused) |
| 430 | { |
| 431 | switch (pm_event) { |
| 432 | case PM_SUSPEND_PREPARE: |
| 433 | /* |
| 434 | * This is necessary, because the A4R domain has to be "on" |
| 435 | * when suspend_device_irqs() and resume_device_irqs() are |
| 436 | * executed during system suspend and resume, respectively, so |
| 437 | * that those functions don't crash while accessing the INTCS. |
| 438 | */ |
Kuninori Morimoto | b9299a7 | 2012-07-05 01:28:32 -0700 | [diff] [blame] | 439 | pm_genpd_poweron(&sh7372_pd_a4r.genpd); |
Rafael J. Wysocki | a8cf27b | 2011-12-23 01:24:34 +0100 | [diff] [blame] | 440 | break; |
| 441 | case PM_POST_SUSPEND: |
| 442 | pm_genpd_poweroff_unused(); |
| 443 | break; |
| 444 | } |
| 445 | |
| 446 | return NOTIFY_DONE; |
| 447 | } |
| 448 | |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 449 | static void sh7372_suspend_init(void) |
| 450 | { |
| 451 | shmobile_suspend_ops.enter = sh7372_enter_suspend; |
Rafael J. Wysocki | a8cf27b | 2011-12-23 01:24:34 +0100 | [diff] [blame] | 452 | pm_notifier(sh7372_pm_notifier_fn, 0); |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 453 | } |
| 454 | #else |
| 455 | static void sh7372_suspend_init(void) {} |
| 456 | #endif |
| 457 | |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 458 | void __init sh7372_pm_init(void) |
| 459 | { |
| 460 | /* enable DBG hardware block to kick SYSC */ |
| 461 | __raw_writel(0x0000a500, DBGREG9); |
| 462 | __raw_writel(0x0000a501, DBGREG9); |
| 463 | __raw_writel(0x00000000, DBGREG1); |
| 464 | |
Magnus Damm | d93f5cd | 2011-10-19 23:52:41 +0200 | [diff] [blame] | 465 | /* do not convert A3SM, A3SP, A3SG, A4R power down into A4S */ |
| 466 | __raw_writel(0, PDNSEL); |
| 467 | |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 468 | sh7372_suspend_init(); |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 469 | sh7372_cpuidle_init(); |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 470 | } |