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