Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 1 | /* |
Andrew Victor | 9d04126 | 2007-02-05 11:42:07 +0100 | [diff] [blame] | 2 | * arch/arm/mach-at91/pm.c |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 3 | * AT91 Power Management |
| 4 | * |
| 5 | * Copyright (C) 2005 David Brownell |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 13 | #include <linux/genalloc.h> |
Alexandre Belloni | 9824c44 | 2017-01-31 13:49:24 +0100 | [diff] [blame] | 14 | #include <linux/io.h> |
| 15 | #include <linux/of_address.h> |
Alexandre Belloni | f5598d3 | 2015-01-15 15:59:24 +0100 | [diff] [blame] | 16 | #include <linux/of.h> |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 17 | #include <linux/of_platform.h> |
Alexandre Belloni | 9824c44 | 2017-01-31 13:49:24 +0100 | [diff] [blame] | 18 | #include <linux/suspend.h> |
| 19 | |
Boris BREZILLON | 2edb90a | 2013-10-11 09:37:45 +0200 | [diff] [blame] | 20 | #include <linux/clk/at91_pmc.h> |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 21 | |
Wenyou Yang | 385acc0 | 2015-03-09 11:54:26 +0800 | [diff] [blame] | 22 | #include <asm/cacheflush.h> |
Alexandre Belloni | 9824c44 | 2017-01-31 13:49:24 +0100 | [diff] [blame] | 23 | #include <asm/fncpy.h> |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 24 | #include <asm/system_misc.h> |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 25 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 26 | #include "generic.h" |
Albin Tonnerre | 1ea60cf | 2009-11-01 18:40:50 +0100 | [diff] [blame] | 27 | #include "pm.h" |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 28 | |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 29 | static void __iomem *pmc; |
| 30 | |
Alexandre Belloni | 23b8408 | 2015-03-13 22:57:23 +0100 | [diff] [blame] | 31 | /* |
| 32 | * FIXME: this is needed to communicate between the pinctrl driver and |
| 33 | * the PM implementation in the machine. Possibly part of the PM |
| 34 | * implementation should be moved down into the pinctrl driver and get |
| 35 | * called as part of the generic suspend/resume path. |
| 36 | */ |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 37 | #ifdef CONFIG_PINCTRL_AT91 |
Alexandre Belloni | 23b8408 | 2015-03-13 22:57:23 +0100 | [diff] [blame] | 38 | extern void at91_pinctrl_gpio_suspend(void); |
| 39 | extern void at91_pinctrl_gpio_resume(void); |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 40 | #endif |
Alexandre Belloni | 23b8408 | 2015-03-13 22:57:23 +0100 | [diff] [blame] | 41 | |
Alexandre Belloni | f5598d3 | 2015-01-15 15:59:24 +0100 | [diff] [blame] | 42 | static struct { |
| 43 | unsigned long uhp_udp_mask; |
| 44 | int memctrl; |
| 45 | } at91_pm_data; |
| 46 | |
Alexandre Belloni | 6cc7fbd | 2016-09-27 12:37:15 +0200 | [diff] [blame] | 47 | static void __iomem *at91_ramc_base[2]; |
Alexandre Belloni | 4d767bc | 2017-01-31 14:08:47 +0100 | [diff] [blame^] | 48 | #define at91_ramc_read(id, field) \ |
| 49 | __raw_readl(at91_ramc_base[id] + field) |
| 50 | |
| 51 | #define at91_ramc_write(id, field, value) \ |
| 52 | __raw_writel(value, at91_ramc_base[id] + field) |
| 53 | |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 54 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 55 | static int at91_pm_valid_state(suspend_state_t state) |
| 56 | { |
| 57 | switch (state) { |
| 58 | case PM_SUSPEND_ON: |
| 59 | case PM_SUSPEND_STANDBY: |
| 60 | case PM_SUSPEND_MEM: |
| 61 | return 1; |
| 62 | |
| 63 | default: |
| 64 | return 0; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | static suspend_state_t target_state; |
| 70 | |
| 71 | /* |
| 72 | * Called after processes are frozen, but before we shutdown devices. |
| 73 | */ |
Rafael J. Wysocki | c697eec | 2008-01-08 00:04:17 +0100 | [diff] [blame] | 74 | static int at91_pm_begin(suspend_state_t state) |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 75 | { |
| 76 | target_state = state; |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Verify that all the clocks are correct before entering |
| 82 | * slow-clock mode. |
| 83 | */ |
| 84 | static int at91_pm_verify_clocks(void) |
| 85 | { |
| 86 | unsigned long scsr; |
| 87 | int i; |
| 88 | |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 89 | scsr = readl(pmc + AT91_PMC_SCSR); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 90 | |
| 91 | /* USB must not be using PLLB */ |
Alexandre Belloni | f5598d3 | 2015-01-15 15:59:24 +0100 | [diff] [blame] | 92 | if ((scsr & at91_pm_data.uhp_udp_mask) != 0) { |
| 93 | pr_err("AT91: PM - Suspend-to-RAM with USB still active\n"); |
| 94 | return 0; |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 97 | /* PCK0..PCK3 must be disabled, or configured to use clk32k */ |
| 98 | for (i = 0; i < 4; i++) { |
| 99 | u32 css; |
| 100 | |
| 101 | if ((scsr & (AT91_PMC_PCK0 << i)) == 0) |
| 102 | continue; |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 103 | css = readl(pmc + AT91_PMC_PCKR(i)) & AT91_PMC_CSS; |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 104 | if (css != AT91_PMC_CSS_SLOW) { |
Ryan Mallon | 7f96b1c | 2009-04-01 20:33:30 +0100 | [diff] [blame] | 105 | pr_err("AT91: PM - Suspend-to-RAM with PCK%d src %d\n", i, css); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | } |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 109 | |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * Call this from platform driver suspend() to see how deeply to suspend. |
| 115 | * For example, some controllers (like OHCI) need one of the PLL clocks |
| 116 | * in order to act as a wakeup source, and those are not available when |
| 117 | * going into slow clock mode. |
| 118 | * |
| 119 | * REVISIT: generalize as clk_will_be_available(clk)? Other platforms have |
| 120 | * the very same problem (but not using at91 main_clk), and it'd be better |
| 121 | * to add one generic API rather than lots of platform-specific ones. |
| 122 | */ |
| 123 | int at91_suspend_entering_slow_clock(void) |
| 124 | { |
| 125 | return (target_state == PM_SUSPEND_MEM); |
| 126 | } |
| 127 | EXPORT_SYMBOL(at91_suspend_entering_slow_clock); |
| 128 | |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 129 | static void (*at91_suspend_sram_fn)(void __iomem *pmc, void __iomem *ramc0, |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 130 | void __iomem *ramc1, int memctrl); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 131 | |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 132 | extern void at91_pm_suspend_in_sram(void __iomem *pmc, void __iomem *ramc0, |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 133 | void __iomem *ramc1, int memctrl); |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 134 | extern u32 at91_pm_suspend_in_sram_sz; |
Andrew Victor | f5d0f45 | 2008-04-02 21:50:16 +0100 | [diff] [blame] | 135 | |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 136 | static void at91_pm_suspend(suspend_state_t state) |
| 137 | { |
| 138 | unsigned int pm_data = at91_pm_data.memctrl; |
| 139 | |
| 140 | pm_data |= (state == PM_SUSPEND_MEM) ? |
| 141 | AT91_PM_MODE(AT91_PM_SLOW_CLOCK) : 0; |
| 142 | |
Wenyou Yang | 385acc0 | 2015-03-09 11:54:26 +0800 | [diff] [blame] | 143 | flush_cache_all(); |
| 144 | outer_disable(); |
| 145 | |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 146 | at91_suspend_sram_fn(pmc, at91_ramc_base[0], |
| 147 | at91_ramc_base[1], pm_data); |
Wenyou Yang | 385acc0 | 2015-03-09 11:54:26 +0800 | [diff] [blame] | 148 | |
| 149 | outer_resume(); |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 150 | } |
| 151 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 152 | static int at91_pm_enter(suspend_state_t state) |
| 153 | { |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 154 | #ifdef CONFIG_PINCTRL_AT91 |
Arnd Bergmann | 85c4b31 | 2014-12-02 12:08:27 +0100 | [diff] [blame] | 155 | at91_pinctrl_gpio_suspend(); |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 156 | #endif |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 157 | switch (state) { |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 158 | /* |
| 159 | * Suspend-to-RAM is like STANDBY plus slow clock mode, so |
| 160 | * drivers must suspend more deeply, the master clock switches |
| 161 | * to the clk32k and turns off the main oscillator |
| 162 | */ |
| 163 | case PM_SUSPEND_MEM: |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 164 | /* |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 165 | * Ensure that clocks are in a valid state. |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 166 | */ |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 167 | if (!at91_pm_verify_clocks()) |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 168 | goto error; |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 169 | |
| 170 | at91_pm_suspend(state); |
| 171 | |
| 172 | break; |
| 173 | |
| 174 | /* |
| 175 | * STANDBY mode has *all* drivers suspended; ignores irqs not |
| 176 | * marked as 'wakeup' event sources; and reduces DRAM power. |
| 177 | * But otherwise it's identical to PM_SUSPEND_ON: cpu idle, and |
| 178 | * nothing fancy done with main or cpu clocks. |
| 179 | */ |
| 180 | case PM_SUSPEND_STANDBY: |
| 181 | at91_pm_suspend(state); |
| 182 | break; |
| 183 | |
| 184 | case PM_SUSPEND_ON: |
| 185 | cpu_do_idle(); |
| 186 | break; |
| 187 | |
| 188 | default: |
| 189 | pr_debug("AT91: PM - bogus suspend state %d\n", state); |
| 190 | goto error; |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 193 | error: |
| 194 | target_state = PM_SUSPEND_ON; |
Boris BREZILLON | 0719260 | 2014-07-10 19:14:20 +0200 | [diff] [blame] | 195 | |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 196 | #ifdef CONFIG_PINCTRL_AT91 |
Arnd Bergmann | 85c4b31 | 2014-12-02 12:08:27 +0100 | [diff] [blame] | 197 | at91_pinctrl_gpio_resume(); |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 198 | #endif |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | |
Rafael J. Wysocki | c697eec | 2008-01-08 00:04:17 +0100 | [diff] [blame] | 202 | /* |
| 203 | * Called right prior to thawing processes. |
| 204 | */ |
| 205 | static void at91_pm_end(void) |
| 206 | { |
| 207 | target_state = PM_SUSPEND_ON; |
| 208 | } |
| 209 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 210 | |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 211 | static const struct platform_suspend_ops at91_pm_ops = { |
Rafael J. Wysocki | c697eec | 2008-01-08 00:04:17 +0100 | [diff] [blame] | 212 | .valid = at91_pm_valid_state, |
| 213 | .begin = at91_pm_begin, |
| 214 | .enter = at91_pm_enter, |
| 215 | .end = at91_pm_end, |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 216 | }; |
| 217 | |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 218 | static struct platform_device at91_cpuidle_device = { |
| 219 | .name = "cpuidle-at91", |
| 220 | }; |
| 221 | |
Wenyou Yang | 047794e | 2015-03-04 09:44:45 +0800 | [diff] [blame] | 222 | static void at91_pm_set_standby(void (*at91_standby)(void)) |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 223 | { |
Wenyou Yang | e32d995 | 2015-03-09 11:51:49 +0800 | [diff] [blame] | 224 | if (at91_standby) |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 225 | at91_cpuidle_device.dev.platform_data = at91_standby; |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 226 | } |
| 227 | |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 228 | /* |
| 229 | * The AT91RM9200 goes into self-refresh mode with this command, and will |
| 230 | * terminate self-refresh automatically on the next SDRAM access. |
| 231 | * |
| 232 | * Self-refresh mode is exited as soon as a memory access is made, but we don't |
| 233 | * know for sure when that happens. However, we need to restore the low-power |
| 234 | * mode if it was enabled before going idle. Restoring low-power mode while |
| 235 | * still in self-refresh is "not recommended", but seems to work. |
| 236 | */ |
| 237 | static void at91rm9200_standby(void) |
| 238 | { |
Alexandre Belloni | d7d45f2 | 2015-03-16 15:14:50 +0100 | [diff] [blame] | 239 | u32 lpr = at91_ramc_read(0, AT91_MC_SDRAMC_LPR); |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 240 | |
| 241 | asm volatile( |
| 242 | "b 1f\n\t" |
| 243 | ".align 5\n\t" |
| 244 | "1: mcr p15, 0, %0, c7, c10, 4\n\t" |
| 245 | " str %0, [%1, %2]\n\t" |
| 246 | " str %3, [%1, %4]\n\t" |
| 247 | " mcr p15, 0, %0, c7, c0, 4\n\t" |
| 248 | " str %5, [%1, %2]" |
| 249 | : |
Alexandre Belloni | d7d45f2 | 2015-03-16 15:14:50 +0100 | [diff] [blame] | 250 | : "r" (0), "r" (at91_ramc_base[0]), "r" (AT91_MC_SDRAMC_LPR), |
| 251 | "r" (1), "r" (AT91_MC_SDRAMC_SRR), |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 252 | "r" (lpr)); |
| 253 | } |
| 254 | |
| 255 | /* We manage both DDRAM/SDRAM controllers, we need more than one value to |
| 256 | * remember. |
| 257 | */ |
| 258 | static void at91_ddr_standby(void) |
| 259 | { |
| 260 | /* Those two values allow us to delay self-refresh activation |
| 261 | * to the maximum. */ |
| 262 | u32 lpr0, lpr1 = 0; |
| 263 | u32 saved_lpr0, saved_lpr1 = 0; |
| 264 | |
| 265 | if (at91_ramc_base[1]) { |
| 266 | saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR); |
| 267 | lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB; |
| 268 | lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH; |
| 269 | } |
| 270 | |
| 271 | saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR); |
| 272 | lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB; |
| 273 | lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH; |
| 274 | |
| 275 | /* self-refresh mode now */ |
| 276 | at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0); |
| 277 | if (at91_ramc_base[1]) |
| 278 | at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1); |
| 279 | |
| 280 | cpu_do_idle(); |
| 281 | |
| 282 | at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0); |
| 283 | if (at91_ramc_base[1]) |
| 284 | at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1); |
| 285 | } |
| 286 | |
Nicolas Ferre | 60b89f1 | 2017-03-14 09:38:04 +0100 | [diff] [blame] | 287 | static void sama5d3_ddr_standby(void) |
| 288 | { |
| 289 | u32 lpr0; |
| 290 | u32 saved_lpr0; |
| 291 | |
| 292 | saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR); |
| 293 | lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB; |
| 294 | lpr0 |= AT91_DDRSDRC_LPCB_POWER_DOWN; |
| 295 | |
| 296 | at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0); |
| 297 | |
| 298 | cpu_do_idle(); |
| 299 | |
| 300 | at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0); |
| 301 | } |
| 302 | |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 303 | /* We manage both DDRAM/SDRAM controllers, we need more than one value to |
| 304 | * remember. |
| 305 | */ |
| 306 | static void at91sam9_sdram_standby(void) |
| 307 | { |
| 308 | u32 lpr0, lpr1 = 0; |
| 309 | u32 saved_lpr0, saved_lpr1 = 0; |
| 310 | |
| 311 | if (at91_ramc_base[1]) { |
| 312 | saved_lpr1 = at91_ramc_read(1, AT91_SDRAMC_LPR); |
| 313 | lpr1 = saved_lpr1 & ~AT91_SDRAMC_LPCB; |
| 314 | lpr1 |= AT91_SDRAMC_LPCB_SELF_REFRESH; |
| 315 | } |
| 316 | |
| 317 | saved_lpr0 = at91_ramc_read(0, AT91_SDRAMC_LPR); |
| 318 | lpr0 = saved_lpr0 & ~AT91_SDRAMC_LPCB; |
| 319 | lpr0 |= AT91_SDRAMC_LPCB_SELF_REFRESH; |
| 320 | |
| 321 | /* self-refresh mode now */ |
| 322 | at91_ramc_write(0, AT91_SDRAMC_LPR, lpr0); |
| 323 | if (at91_ramc_base[1]) |
| 324 | at91_ramc_write(1, AT91_SDRAMC_LPR, lpr1); |
| 325 | |
| 326 | cpu_do_idle(); |
| 327 | |
| 328 | at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr0); |
| 329 | if (at91_ramc_base[1]) |
| 330 | at91_ramc_write(1, AT91_SDRAMC_LPR, saved_lpr1); |
| 331 | } |
| 332 | |
Nicolas Pitre | 19c233b | 2015-07-27 18:27:52 -0400 | [diff] [blame] | 333 | static const struct of_device_id const ramc_ids[] __initconst = { |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 334 | { .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby }, |
| 335 | { .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby }, |
| 336 | { .compatible = "atmel,at91sam9g45-ddramc", .data = at91_ddr_standby }, |
Nicolas Ferre | 60b89f1 | 2017-03-14 09:38:04 +0100 | [diff] [blame] | 337 | { .compatible = "atmel,sama5d3-ddramc", .data = sama5d3_ddr_standby }, |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 338 | { /*sentinel*/ } |
| 339 | }; |
| 340 | |
Uwe Kleine-König | 444d2d3 | 2015-02-18 21:19:56 +0100 | [diff] [blame] | 341 | static __init void at91_dt_ramc(void) |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 342 | { |
| 343 | struct device_node *np; |
| 344 | const struct of_device_id *of_id; |
| 345 | int idx = 0; |
| 346 | const void *standby = NULL; |
| 347 | |
| 348 | for_each_matching_node_and_match(np, ramc_ids, &of_id) { |
| 349 | at91_ramc_base[idx] = of_iomap(np, 0); |
| 350 | if (!at91_ramc_base[idx]) |
| 351 | panic(pr_fmt("unable to map ramc[%d] cpu registers\n"), idx); |
| 352 | |
| 353 | if (!standby) |
| 354 | standby = of_id->data; |
| 355 | |
| 356 | idx++; |
| 357 | } |
| 358 | |
| 359 | if (!idx) |
| 360 | panic(pr_fmt("unable to find compatible ram controller node in dtb\n")); |
| 361 | |
| 362 | if (!standby) { |
| 363 | pr_warn("ramc no standby function available\n"); |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | at91_pm_set_standby(standby); |
| 368 | } |
| 369 | |
Ben Dooks | ab6778e | 2016-06-17 16:34:18 +0100 | [diff] [blame] | 370 | static void at91rm9200_idle(void) |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 371 | { |
| 372 | /* |
| 373 | * Disable the processor clock. The processor will be automatically |
| 374 | * re-enabled by an interrupt or by a reset. |
| 375 | */ |
| 376 | writel(AT91_PMC_PCK, pmc + AT91_PMC_SCDR); |
| 377 | } |
| 378 | |
Ben Dooks | ab6778e | 2016-06-17 16:34:18 +0100 | [diff] [blame] | 379 | static void at91sam9_idle(void) |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 380 | { |
| 381 | writel(AT91_PMC_PCK, pmc + AT91_PMC_SCDR); |
| 382 | cpu_do_idle(); |
| 383 | } |
| 384 | |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 385 | static void __init at91_pm_sram_init(void) |
| 386 | { |
| 387 | struct gen_pool *sram_pool; |
| 388 | phys_addr_t sram_pbase; |
| 389 | unsigned long sram_base; |
| 390 | struct device_node *node; |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 391 | struct platform_device *pdev = NULL; |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 392 | |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 393 | for_each_compatible_node(node, NULL, "mmio-sram") { |
| 394 | pdev = of_find_device_by_node(node); |
| 395 | if (pdev) { |
| 396 | of_node_put(node); |
| 397 | break; |
| 398 | } |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 401 | if (!pdev) { |
| 402 | pr_warn("%s: failed to find sram device!\n", __func__); |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 403 | return; |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 404 | } |
| 405 | |
Vladimir Zapolskiy | 7385817 | 2015-09-04 15:47:43 -0700 | [diff] [blame] | 406 | sram_pool = gen_pool_get(&pdev->dev, NULL); |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 407 | if (!sram_pool) { |
| 408 | pr_warn("%s: sram pool unavailable!\n", __func__); |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 409 | return; |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 410 | } |
| 411 | |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 412 | sram_base = gen_pool_alloc(sram_pool, at91_pm_suspend_in_sram_sz); |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 413 | if (!sram_base) { |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 414 | pr_warn("%s: unable to alloc sram!\n", __func__); |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 415 | return; |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base); |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 419 | at91_suspend_sram_fn = __arm_ioremap_exec(sram_pbase, |
| 420 | at91_pm_suspend_in_sram_sz, false); |
| 421 | if (!at91_suspend_sram_fn) { |
Wenyou Yang | d94e688 | 2015-03-09 11:49:01 +0800 | [diff] [blame] | 422 | pr_warn("SRAM: Could not map\n"); |
| 423 | return; |
| 424 | } |
| 425 | |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 426 | /* Copy the pm suspend handler to SRAM */ |
| 427 | at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn, |
| 428 | &at91_pm_suspend_in_sram, at91_pm_suspend_in_sram_sz); |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 429 | } |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 430 | |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 431 | static const struct of_device_id atmel_pmc_ids[] __initconst = { |
| 432 | { .compatible = "atmel,at91rm9200-pmc" }, |
| 433 | { .compatible = "atmel,at91sam9260-pmc" }, |
| 434 | { .compatible = "atmel,at91sam9g45-pmc" }, |
| 435 | { .compatible = "atmel,at91sam9n12-pmc" }, |
| 436 | { .compatible = "atmel,at91sam9x5-pmc" }, |
| 437 | { .compatible = "atmel,sama5d3-pmc" }, |
| 438 | { .compatible = "atmel,sama5d2-pmc" }, |
| 439 | { /* sentinel */ }, |
| 440 | }; |
| 441 | |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 442 | static void __init at91_pm_init(void (*pm_idle)(void)) |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 443 | { |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 444 | struct device_node *pmc_np; |
Andrew Victor | f5d0f45 | 2008-04-02 21:50:16 +0100 | [diff] [blame] | 445 | |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 446 | if (at91_cpuidle_device.dev.platform_data) |
| 447 | platform_device_register(&at91_cpuidle_device); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 448 | |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 449 | pmc_np = of_find_matching_node(NULL, atmel_pmc_ids); |
| 450 | pmc = of_iomap(pmc_np, 0); |
| 451 | if (!pmc) { |
| 452 | pr_err("AT91: PM not supported, PMC not found\n"); |
| 453 | return; |
| 454 | } |
| 455 | |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 456 | if (pm_idle) |
| 457 | arm_pm_idle = pm_idle; |
| 458 | |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 459 | at91_pm_sram_init(); |
| 460 | |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 461 | if (at91_suspend_sram_fn) |
Wenyou Yang | d94e688 | 2015-03-09 11:49:01 +0800 | [diff] [blame] | 462 | suspend_set_ops(&at91_pm_ops); |
| 463 | else |
| 464 | pr_info("AT91: PM not supported, due to no SRAM allocated\n"); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 465 | } |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 466 | |
Nicolas Ferre | ad3fc3e | 2015-01-27 18:41:33 +0100 | [diff] [blame] | 467 | void __init at91rm9200_pm_init(void) |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 468 | { |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 469 | at91_dt_ramc(); |
| 470 | |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 471 | /* |
| 472 | * AT91RM9200 SDRAM low-power mode cannot be used with self-refresh. |
| 473 | */ |
Alexandre Belloni | d7d45f2 | 2015-03-16 15:14:50 +0100 | [diff] [blame] | 474 | at91_ramc_write(0, AT91_MC_SDRAMC_LPR, 0); |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 475 | |
| 476 | at91_pm_data.uhp_udp_mask = AT91RM9200_PMC_UHP | AT91RM9200_PMC_UDP; |
| 477 | at91_pm_data.memctrl = AT91_MEMCTRL_MC; |
| 478 | |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 479 | at91_pm_init(at91rm9200_idle); |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Nicolas Ferre | ad3fc3e | 2015-01-27 18:41:33 +0100 | [diff] [blame] | 482 | void __init at91sam9260_pm_init(void) |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 483 | { |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 484 | at91_dt_ramc(); |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 485 | at91_pm_data.memctrl = AT91_MEMCTRL_SDRAMC; |
| 486 | at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP; |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 487 | at91_pm_init(at91sam9_idle); |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 488 | } |
| 489 | |
Nicolas Ferre | ad3fc3e | 2015-01-27 18:41:33 +0100 | [diff] [blame] | 490 | void __init at91sam9g45_pm_init(void) |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 491 | { |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 492 | at91_dt_ramc(); |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 493 | at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP; |
| 494 | at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR; |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 495 | at91_pm_init(at91sam9_idle); |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 496 | } |
Nicolas Ferre | bf02280 | 2015-01-22 16:54:50 +0100 | [diff] [blame] | 497 | |
Nicolas Ferre | ad3fc3e | 2015-01-27 18:41:33 +0100 | [diff] [blame] | 498 | void __init at91sam9x5_pm_init(void) |
Nicolas Ferre | bf02280 | 2015-01-22 16:54:50 +0100 | [diff] [blame] | 499 | { |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 500 | at91_dt_ramc(); |
Nicolas Ferre | bf02280 | 2015-01-22 16:54:50 +0100 | [diff] [blame] | 501 | at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP; |
| 502 | at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR; |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 503 | at91_pm_init(at91sam9_idle); |
| 504 | } |
| 505 | |
| 506 | void __init sama5_pm_init(void) |
| 507 | { |
| 508 | at91_dt_ramc(); |
| 509 | at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP; |
| 510 | at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR; |
| 511 | at91_pm_init(NULL); |
Nicolas Ferre | bf02280 | 2015-01-22 16:54:50 +0100 | [diff] [blame] | 512 | } |