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 | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 23 | #include <asm/system.h> |
| 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> |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 29 | |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 30 | /* DBG */ |
| 31 | #define DBGREG1 0xe6100020 |
| 32 | #define DBGREG9 0xe6100040 |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 33 | |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 34 | /* CPGA */ |
| 35 | #define SYSTBCR 0xe6150024 |
| 36 | #define MSTPSR0 0xe6150030 |
| 37 | #define MSTPSR1 0xe6150038 |
| 38 | #define MSTPSR2 0xe6150040 |
| 39 | #define MSTPSR3 0xe6150048 |
| 40 | #define MSTPSR4 0xe615004c |
| 41 | #define PLLC01STPCR 0xe61500c8 |
| 42 | |
| 43 | /* SYSC */ |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 44 | #define SPDCR 0xe6180008 |
| 45 | #define SWUCR 0xe6180014 |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 46 | #define SBAR 0xe6180020 |
| 47 | #define WUPSMSK 0xe618002c |
| 48 | #define WUPSMSK2 0xe6180048 |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 49 | #define PSTR 0xe6180080 |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 50 | #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. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 72 | |
| 73 | #define PSTR_RETRIES 100 |
| 74 | #define PSTR_DELAY_US 10 |
| 75 | |
| 76 | #ifdef CONFIG_PM |
| 77 | |
| 78 | static int pd_power_down(struct generic_pm_domain *genpd) |
| 79 | { |
| 80 | struct sh7372_pm_domain *sh7372_pd = to_sh7372_pd(genpd); |
| 81 | unsigned int mask = 1 << sh7372_pd->bit_shift; |
| 82 | |
| 83 | if (__raw_readl(PSTR) & mask) { |
| 84 | unsigned int retry_count; |
| 85 | |
| 86 | __raw_writel(mask, SPDCR); |
| 87 | |
| 88 | for (retry_count = PSTR_RETRIES; retry_count; retry_count--) { |
| 89 | if (!(__raw_readl(SPDCR) & mask)) |
| 90 | break; |
| 91 | cpu_relax(); |
| 92 | } |
| 93 | } |
| 94 | |
Magnus Damm | d93f5cd | 2011-10-19 23:52:41 +0200 | [diff] [blame^] | 95 | if (!sh7372_pd->no_debug) |
| 96 | pr_debug("sh7372 power domain down 0x%08x -> PSTR = 0x%08x\n", |
| 97 | mask, __raw_readl(PSTR)); |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static int pd_power_up(struct generic_pm_domain *genpd) |
| 103 | { |
| 104 | struct sh7372_pm_domain *sh7372_pd = to_sh7372_pd(genpd); |
| 105 | unsigned int mask = 1 << sh7372_pd->bit_shift; |
| 106 | unsigned int retry_count; |
| 107 | int ret = 0; |
| 108 | |
| 109 | if (__raw_readl(PSTR) & mask) |
| 110 | goto out; |
| 111 | |
| 112 | __raw_writel(mask, SWUCR); |
| 113 | |
| 114 | for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) { |
| 115 | if (!(__raw_readl(SWUCR) & mask)) |
| 116 | goto out; |
| 117 | if (retry_count > PSTR_RETRIES) |
| 118 | udelay(PSTR_DELAY_US); |
| 119 | else |
| 120 | cpu_relax(); |
| 121 | } |
| 122 | if (__raw_readl(SWUCR) & mask) |
| 123 | ret = -EIO; |
| 124 | |
| 125 | out: |
Magnus Damm | d93f5cd | 2011-10-19 23:52:41 +0200 | [diff] [blame^] | 126 | if (!sh7372_pd->no_debug) |
| 127 | pr_debug("sh7372 power domain up 0x%08x -> PSTR = 0x%08x\n", |
| 128 | mask, __raw_readl(PSTR)); |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 129 | |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | static bool pd_active_wakeup(struct device *dev) |
| 134 | { |
| 135 | return true; |
| 136 | } |
| 137 | |
Magnus Damm | d93f5cd | 2011-10-19 23:52:41 +0200 | [diff] [blame^] | 138 | static bool sh7372_power_down_forbidden(struct dev_pm_domain *domain) |
| 139 | { |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | struct dev_power_governor sh7372_always_on_gov = { |
| 144 | .power_down_ok = sh7372_power_down_forbidden, |
| 145 | }; |
| 146 | |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 147 | void sh7372_init_pm_domain(struct sh7372_pm_domain *sh7372_pd) |
| 148 | { |
| 149 | struct generic_pm_domain *genpd = &sh7372_pd->genpd; |
| 150 | |
Magnus Damm | d93f5cd | 2011-10-19 23:52:41 +0200 | [diff] [blame^] | 151 | pm_genpd_init(genpd, sh7372_pd->gov, false); |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 152 | genpd->stop_device = pm_clk_suspend; |
| 153 | genpd->start_device = pm_clk_resume; |
Rafael J. Wysocki | 0aa2a22 | 2011-08-25 15:37:04 +0200 | [diff] [blame] | 154 | genpd->dev_irq_safe = true; |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 155 | genpd->active_wakeup = pd_active_wakeup; |
Rafael J. Wysocki | 111058c | 2011-08-14 13:35:39 +0200 | [diff] [blame] | 156 | genpd->power_off = pd_power_down; |
| 157 | genpd->power_on = pd_power_up; |
Magnus Damm | 775b8ae | 2011-07-10 10:39:32 +0200 | [diff] [blame] | 158 | genpd->power_on(&sh7372_pd->genpd); |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void sh7372_add_device_to_domain(struct sh7372_pm_domain *sh7372_pd, |
| 162 | struct platform_device *pdev) |
| 163 | { |
| 164 | struct device *dev = &pdev->dev; |
| 165 | |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 166 | pm_genpd_add_device(&sh7372_pd->genpd, dev); |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 167 | if (pm_clk_no_clocks(dev)) |
| 168 | pm_clk_add(dev, NULL); |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Rafael J. Wysocki | 111058c | 2011-08-14 13:35:39 +0200 | [diff] [blame] | 171 | void sh7372_pm_add_subdomain(struct sh7372_pm_domain *sh7372_pd, |
| 172 | struct sh7372_pm_domain *sh7372_sd) |
| 173 | { |
| 174 | pm_genpd_add_subdomain(&sh7372_pd->genpd, &sh7372_sd->genpd); |
| 175 | } |
| 176 | |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 177 | struct sh7372_pm_domain sh7372_a4lc = { |
| 178 | .bit_shift = 1, |
| 179 | }; |
| 180 | |
Kuninori Morimoto | c1ba5bb | 2011-07-10 10:12:08 +0200 | [diff] [blame] | 181 | struct sh7372_pm_domain sh7372_a4mp = { |
| 182 | .bit_shift = 2, |
| 183 | }; |
| 184 | |
Magnus Damm | d24771d | 2011-07-10 10:38:22 +0200 | [diff] [blame] | 185 | struct sh7372_pm_domain sh7372_d4 = { |
| 186 | .bit_shift = 3, |
| 187 | }; |
| 188 | |
Magnus Damm | 33afebf | 2011-07-01 22:14:45 +0200 | [diff] [blame] | 189 | struct sh7372_pm_domain sh7372_a3rv = { |
| 190 | .bit_shift = 6, |
| 191 | }; |
| 192 | |
Magnus Damm | 082517a | 2011-07-01 22:14:53 +0200 | [diff] [blame] | 193 | struct sh7372_pm_domain sh7372_a3ri = { |
| 194 | .bit_shift = 8, |
| 195 | }; |
| 196 | |
Magnus Damm | d93f5cd | 2011-10-19 23:52:41 +0200 | [diff] [blame^] | 197 | struct sh7372_pm_domain sh7372_a3sp = { |
| 198 | .bit_shift = 11, |
| 199 | .gov = &sh7372_always_on_gov, |
| 200 | .no_debug = true, |
| 201 | }; |
| 202 | |
Magnus Damm | c47586b | 2011-07-01 22:15:01 +0200 | [diff] [blame] | 203 | struct sh7372_pm_domain sh7372_a3sg = { |
| 204 | .bit_shift = 13, |
| 205 | }; |
| 206 | |
Rafael J. Wysocki | e3e0109 | 2011-07-01 22:13:56 +0200 | [diff] [blame] | 207 | #endif /* CONFIG_PM */ |
| 208 | |
Magnus Damm | a0089bd6 | 2011-09-25 23:21:02 +0200 | [diff] [blame] | 209 | #if defined(CONFIG_SUSPEND) || defined(CONFIG_CPU_IDLE) |
Magnus Damm | 06b8416 | 2011-09-25 23:18:42 +0200 | [diff] [blame] | 210 | static int sh7372_do_idle_core_standby(unsigned long unused) |
| 211 | { |
| 212 | cpu_do_idle(); /* WFI when SYSTBCR == 0x10 -> Core Standby */ |
| 213 | return 0; |
| 214 | } |
| 215 | |
Paul Mundt | 66ad129 | 2011-05-25 11:22:58 +0900 | [diff] [blame] | 216 | static void sh7372_enter_core_standby(void) |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 217 | { |
Magnus Damm | 06b8416 | 2011-09-25 23:18:42 +0200 | [diff] [blame] | 218 | /* set reset vector, translate 4k */ |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 219 | __raw_writel(__pa(sh7372_resume_core_standby_a3sm), SBAR); |
Magnus Damm | 06b8416 | 2011-09-25 23:18:42 +0200 | [diff] [blame] | 220 | __raw_writel(0, APARMBAREA); |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 221 | |
Magnus Damm | 06b8416 | 2011-09-25 23:18:42 +0200 | [diff] [blame] | 222 | /* enter sleep mode with SYSTBCR to 0x10 */ |
| 223 | __raw_writel(0x10, SYSTBCR); |
| 224 | cpu_suspend(0, sh7372_do_idle_core_standby); |
| 225 | __raw_writel(0, SYSTBCR); |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 226 | |
Magnus Damm | 06b8416 | 2011-09-25 23:18:42 +0200 | [diff] [blame] | 227 | /* disable reset vector translation */ |
| 228 | __raw_writel(0, SBAR); |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 229 | } |
Magnus Damm | a0089bd6 | 2011-09-25 23:21:02 +0200 | [diff] [blame] | 230 | #endif |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 231 | |
Magnus Damm | a0089bd6 | 2011-09-25 23:21:02 +0200 | [diff] [blame] | 232 | #ifdef CONFIG_SUSPEND |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 233 | static void sh7372_enter_a3sm_common(int pllc0_on) |
| 234 | { |
| 235 | /* set reset vector, translate 4k */ |
| 236 | __raw_writel(__pa(sh7372_resume_core_standby_a3sm), SBAR); |
| 237 | __raw_writel(0, APARMBAREA); |
| 238 | |
| 239 | if (pllc0_on) |
| 240 | __raw_writel(0, PLLC01STPCR); |
| 241 | else |
| 242 | __raw_writel(1 << 28, PLLC01STPCR); |
| 243 | |
| 244 | __raw_writel(0, PDNSEL); /* power-down A3SM only, not A4S */ |
| 245 | __raw_readl(WUPSFAC); /* read wakeup int. factor before sleep */ |
| 246 | cpu_suspend(0, sh7372_do_idle_a3sm); |
| 247 | __raw_readl(WUPSFAC); /* read wakeup int. factor after wakeup */ |
| 248 | |
| 249 | /* disable reset vector translation */ |
| 250 | __raw_writel(0, SBAR); |
| 251 | } |
| 252 | |
| 253 | static int sh7372_a3sm_valid(unsigned long *mskp, unsigned long *msk2p) |
| 254 | { |
| 255 | unsigned long mstpsr0, mstpsr1, mstpsr2, mstpsr3, mstpsr4; |
| 256 | unsigned long msk, msk2; |
| 257 | |
| 258 | /* check active clocks to determine potential wakeup sources */ |
| 259 | |
| 260 | mstpsr0 = __raw_readl(MSTPSR0); |
| 261 | if ((mstpsr0 & 0x00000003) != 0x00000003) { |
| 262 | pr_debug("sh7372 mstpsr0 0x%08lx\n", mstpsr0); |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | mstpsr1 = __raw_readl(MSTPSR1); |
| 267 | if ((mstpsr1 & 0xff079b7f) != 0xff079b7f) { |
| 268 | pr_debug("sh7372 mstpsr1 0x%08lx\n", mstpsr1); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | mstpsr2 = __raw_readl(MSTPSR2); |
| 273 | if ((mstpsr2 & 0x000741ff) != 0x000741ff) { |
| 274 | pr_debug("sh7372 mstpsr2 0x%08lx\n", mstpsr2); |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | mstpsr3 = __raw_readl(MSTPSR3); |
| 279 | if ((mstpsr3 & 0x1a60f010) != 0x1a60f010) { |
| 280 | pr_debug("sh7372 mstpsr3 0x%08lx\n", mstpsr3); |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | mstpsr4 = __raw_readl(MSTPSR4); |
| 285 | if ((mstpsr4 & 0x00008cf0) != 0x00008cf0) { |
| 286 | pr_debug("sh7372 mstpsr4 0x%08lx\n", mstpsr4); |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | msk = 0; |
| 291 | msk2 = 0; |
| 292 | |
| 293 | /* make bitmaps of limited number of wakeup sources */ |
| 294 | |
| 295 | if ((mstpsr2 & (1 << 23)) == 0) /* SPU2 */ |
| 296 | msk |= 1 << 31; |
| 297 | |
| 298 | if ((mstpsr2 & (1 << 12)) == 0) /* MFI_MFIM */ |
| 299 | msk |= 1 << 21; |
| 300 | |
| 301 | if ((mstpsr4 & (1 << 3)) == 0) /* KEYSC */ |
| 302 | msk |= 1 << 2; |
| 303 | |
| 304 | if ((mstpsr1 & (1 << 24)) == 0) /* CMT0 */ |
| 305 | msk |= 1 << 1; |
| 306 | |
| 307 | if ((mstpsr3 & (1 << 29)) == 0) /* CMT1 */ |
| 308 | msk |= 1 << 1; |
| 309 | |
| 310 | if ((mstpsr4 & (1 << 0)) == 0) /* CMT2 */ |
| 311 | msk |= 1 << 1; |
| 312 | |
| 313 | if ((mstpsr2 & (1 << 13)) == 0) /* MFI_MFIS */ |
| 314 | msk2 |= 1 << 17; |
| 315 | |
| 316 | *mskp = msk; |
| 317 | *msk2p = msk2; |
| 318 | |
| 319 | return 1; |
| 320 | } |
| 321 | |
| 322 | static void sh7372_icr_to_irqcr(unsigned long icr, u16 *irqcr1p, u16 *irqcr2p) |
| 323 | { |
| 324 | u16 tmp, irqcr1, irqcr2; |
| 325 | int k; |
| 326 | |
| 327 | irqcr1 = 0; |
| 328 | irqcr2 = 0; |
| 329 | |
| 330 | /* convert INTCA ICR register layout to SYSC IRQCR+IRQCR2 */ |
| 331 | for (k = 0; k <= 7; k++) { |
| 332 | tmp = (icr >> ((7 - k) * 4)) & 0xf; |
| 333 | irqcr1 |= (tmp & 0x03) << (k * 2); |
| 334 | irqcr2 |= (tmp >> 2) << (k * 2); |
| 335 | } |
| 336 | |
| 337 | *irqcr1p = irqcr1; |
| 338 | *irqcr2p = irqcr2; |
| 339 | } |
| 340 | |
| 341 | static void sh7372_setup_a3sm(unsigned long msk, unsigned long msk2) |
| 342 | { |
| 343 | u16 irqcrx_low, irqcrx_high, irqcry_low, irqcry_high; |
| 344 | unsigned long tmp; |
| 345 | |
| 346 | /* read IRQ0A -> IRQ15A mask */ |
| 347 | tmp = bitrev8(__raw_readb(INTMSK00A)); |
| 348 | tmp |= bitrev8(__raw_readb(INTMSK10A)) << 8; |
| 349 | |
| 350 | /* setup WUPSMSK from clocks and external IRQ mask */ |
| 351 | msk = (~msk & 0xc030000f) | (tmp << 4); |
| 352 | __raw_writel(msk, WUPSMSK); |
| 353 | |
| 354 | /* propage level/edge trigger for external IRQ 0->15 */ |
| 355 | sh7372_icr_to_irqcr(__raw_readl(ICR1A), &irqcrx_low, &irqcry_low); |
| 356 | sh7372_icr_to_irqcr(__raw_readl(ICR2A), &irqcrx_high, &irqcry_high); |
| 357 | __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR); |
| 358 | __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR2); |
| 359 | |
| 360 | /* read IRQ16A -> IRQ31A mask */ |
| 361 | tmp = bitrev8(__raw_readb(INTMSK20A)); |
| 362 | tmp |= bitrev8(__raw_readb(INTMSK30A)) << 8; |
| 363 | |
| 364 | /* setup WUPSMSK2 from clocks and external IRQ mask */ |
| 365 | msk2 = (~msk2 & 0x00030000) | tmp; |
| 366 | __raw_writel(msk2, WUPSMSK2); |
| 367 | |
| 368 | /* propage level/edge trigger for external IRQ 16->31 */ |
| 369 | sh7372_icr_to_irqcr(__raw_readl(ICR3A), &irqcrx_low, &irqcry_low); |
| 370 | sh7372_icr_to_irqcr(__raw_readl(ICR4A), &irqcrx_high, &irqcry_high); |
| 371 | __raw_writel((irqcrx_high << 16) | irqcrx_low, IRQCR3); |
| 372 | __raw_writel((irqcry_high << 16) | irqcry_low, IRQCR4); |
| 373 | } |
Magnus Damm | a0089bd6 | 2011-09-25 23:21:02 +0200 | [diff] [blame] | 374 | #endif |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 375 | |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 376 | #ifdef CONFIG_CPU_IDLE |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 377 | |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 378 | static void sh7372_cpuidle_setup(struct cpuidle_device *dev) |
| 379 | { |
| 380 | struct cpuidle_state *state; |
| 381 | int i = dev->state_count; |
| 382 | |
| 383 | state = &dev->states[i]; |
| 384 | snprintf(state->name, CPUIDLE_NAME_LEN, "C2"); |
| 385 | strncpy(state->desc, "Core Standby Mode", CPUIDLE_DESC_LEN); |
| 386 | state->exit_latency = 10; |
| 387 | state->target_residency = 20 + 10; |
| 388 | state->power_usage = 1; /* perhaps not */ |
| 389 | state->flags = 0; |
| 390 | state->flags |= CPUIDLE_FLAG_TIME_VALID; |
| 391 | shmobile_cpuidle_modes[i] = sh7372_enter_core_standby; |
| 392 | |
| 393 | dev->state_count = i + 1; |
| 394 | } |
| 395 | |
| 396 | static void sh7372_cpuidle_init(void) |
| 397 | { |
| 398 | shmobile_cpuidle_setup = sh7372_cpuidle_setup; |
| 399 | } |
| 400 | #else |
| 401 | static void sh7372_cpuidle_init(void) {} |
| 402 | #endif |
| 403 | |
| 404 | #ifdef CONFIG_SUSPEND |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 405 | |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 406 | static int sh7372_enter_suspend(suspend_state_t suspend_state) |
| 407 | { |
Magnus Damm | cf33835 | 2011-09-25 23:20:49 +0200 | [diff] [blame] | 408 | unsigned long msk, msk2; |
| 409 | |
| 410 | /* check active clocks to determine potential wakeup sources */ |
| 411 | if (sh7372_a3sm_valid(&msk, &msk2)) { |
| 412 | |
| 413 | /* convert INTC mask and sense to SYSC mask and sense */ |
| 414 | sh7372_setup_a3sm(msk, msk2); |
| 415 | |
| 416 | /* enter A3SM sleep with PLLC0 off */ |
| 417 | pr_debug("entering A3SM\n"); |
| 418 | sh7372_enter_a3sm_common(0); |
| 419 | } else { |
| 420 | /* default to Core Standby that supports all wakeup sources */ |
| 421 | pr_debug("entering Core Standby\n"); |
| 422 | sh7372_enter_core_standby(); |
| 423 | } |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | static void sh7372_suspend_init(void) |
| 428 | { |
| 429 | shmobile_suspend_ops.enter = sh7372_enter_suspend; |
| 430 | } |
| 431 | #else |
| 432 | static void sh7372_suspend_init(void) {} |
| 433 | #endif |
| 434 | |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 435 | void __init sh7372_pm_init(void) |
| 436 | { |
| 437 | /* enable DBG hardware block to kick SYSC */ |
| 438 | __raw_writel(0x0000a500, DBGREG9); |
| 439 | __raw_writel(0x0000a501, DBGREG9); |
| 440 | __raw_writel(0x00000000, DBGREG1); |
| 441 | |
Magnus Damm | d93f5cd | 2011-10-19 23:52:41 +0200 | [diff] [blame^] | 442 | /* do not convert A3SM, A3SP, A3SG, A4R power down into A4S */ |
| 443 | __raw_writel(0, PDNSEL); |
| 444 | |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 445 | sh7372_suspend_init(); |
Magnus Damm | 082a8ca | 2011-04-29 02:39:32 +0900 | [diff] [blame] | 446 | sh7372_cpuidle_init(); |
Magnus Damm | 9799165 | 2011-04-29 02:28:08 +0900 | [diff] [blame] | 447 | } |