blob: 41789aa4df86c7b9ba3910ceb1d30e77886dfc0c [file] [log] [blame]
Andrew Victor907d6de2006-06-20 19:30:19 +01001/*
Andrew Victor9d041262007-02-05 11:42:07 +01002 * arch/arm/mach-at91/pm.c
Andrew Victor907d6de2006-06-20 19:30:19 +01003 * 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 Bellonid2e46792015-01-15 15:59:25 +010013#include <linux/genalloc.h>
Alexandre Belloni9824c442017-01-31 13:49:24 +010014#include <linux/io.h>
15#include <linux/of_address.h>
Alexandre Bellonif5598d32015-01-15 15:59:24 +010016#include <linux/of.h>
Alexandre Bellonid2e46792015-01-15 15:59:25 +010017#include <linux/of_platform.h>
Alexandre Belloni9824c442017-01-31 13:49:24 +010018#include <linux/suspend.h>
19
Boris BREZILLON2edb90a2013-10-11 09:37:45 +020020#include <linux/clk/at91_pmc.h>
Andrew Victor907d6de2006-06-20 19:30:19 +010021
Wenyou Yang385acc02015-03-09 11:54:26 +080022#include <asm/cacheflush.h>
Alexandre Belloni9824c442017-01-31 13:49:24 +010023#include <asm/fncpy.h>
Alexandre Bellonifbc7edc2015-09-30 01:58:40 +020024#include <asm/system_misc.h>
Andrew Victor907d6de2006-06-20 19:30:19 +010025
Andrew Victor907d6de2006-06-20 19:30:19 +010026#include "generic.h"
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010027#include "pm.h"
Andrew Victor907d6de2006-06-20 19:30:19 +010028
Alexandre Belloni5737b732015-09-30 01:31:34 +020029static void __iomem *pmc;
30
Alexandre Belloni23b84082015-03-13 22:57:23 +010031/*
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 Desroches84235362015-12-01 11:44:40 +010037#ifdef CONFIG_PINCTRL_AT91
Alexandre Belloni23b84082015-03-13 22:57:23 +010038extern void at91_pinctrl_gpio_suspend(void);
39extern void at91_pinctrl_gpio_resume(void);
Ludovic Desroches84235362015-12-01 11:44:40 +010040#endif
Alexandre Belloni23b84082015-03-13 22:57:23 +010041
Alexandre Bellonif5598d32015-01-15 15:59:24 +010042static struct {
43 unsigned long uhp_udp_mask;
44 int memctrl;
45} at91_pm_data;
46
Alexandre Belloni6cc7fbd2016-09-27 12:37:15 +020047static void __iomem *at91_ramc_base[2];
Alexandre Belloni4d767bc2017-01-31 14:08:47 +010048#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 Lezcano5ad945e2013-09-22 22:29:57 +020054
Andrew Victor907d6de2006-06-20 19:30:19 +010055static 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
69static suspend_state_t target_state;
70
71/*
72 * Called after processes are frozen, but before we shutdown devices.
73 */
Rafael J. Wysockic697eec2008-01-08 00:04:17 +010074static int at91_pm_begin(suspend_state_t state)
Andrew Victor907d6de2006-06-20 19:30:19 +010075{
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 */
84static int at91_pm_verify_clocks(void)
85{
86 unsigned long scsr;
87 int i;
88
Alexandre Belloni5737b732015-09-30 01:31:34 +020089 scsr = readl(pmc + AT91_PMC_SCSR);
Andrew Victor907d6de2006-06-20 19:30:19 +010090
91 /* USB must not be using PLLB */
Alexandre Bellonif5598d32015-01-15 15:59:24 +010092 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 Victor907d6de2006-06-20 19:30:19 +010095 }
96
Andrew Victor907d6de2006-06-20 19:30:19 +010097 /* 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 Belloni5737b732015-09-30 01:31:34 +0200103 css = readl(pmc + AT91_PMC_PCKR(i)) & AT91_PMC_CSS;
Andrew Victor907d6de2006-06-20 19:30:19 +0100104 if (css != AT91_PMC_CSS_SLOW) {
Ryan Mallon7f96b1c2009-04-01 20:33:30 +0100105 pr_err("AT91: PM - Suspend-to-RAM with PCK%d src %d\n", i, css);
Andrew Victor907d6de2006-06-20 19:30:19 +0100106 return 0;
107 }
108 }
Andrew Victor907d6de2006-06-20 19:30:19 +0100109
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 */
123int at91_suspend_entering_slow_clock(void)
124{
125 return (target_state == PM_SUSPEND_MEM);
126}
127EXPORT_SYMBOL(at91_suspend_entering_slow_clock);
128
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800129static void (*at91_suspend_sram_fn)(void __iomem *pmc, void __iomem *ramc0,
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100130 void __iomem *ramc1, int memctrl);
Andrew Victor907d6de2006-06-20 19:30:19 +0100131
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800132extern void at91_pm_suspend_in_sram(void __iomem *pmc, void __iomem *ramc0,
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100133 void __iomem *ramc1, int memctrl);
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800134extern u32 at91_pm_suspend_in_sram_sz;
Andrew Victorf5d0f452008-04-02 21:50:16 +0100135
Wenyou Yang23be4be2015-03-09 11:49:46 +0800136static 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 Yang385acc02015-03-09 11:54:26 +0800143 flush_cache_all();
144 outer_disable();
145
Alexandre Belloni5737b732015-09-30 01:31:34 +0200146 at91_suspend_sram_fn(pmc, at91_ramc_base[0],
147 at91_ramc_base[1], pm_data);
Wenyou Yang385acc02015-03-09 11:54:26 +0800148
149 outer_resume();
Wenyou Yang23be4be2015-03-09 11:49:46 +0800150}
151
Andrew Victor907d6de2006-06-20 19:30:19 +0100152static int at91_pm_enter(suspend_state_t state)
153{
Ludovic Desroches84235362015-12-01 11:44:40 +0100154#ifdef CONFIG_PINCTRL_AT91
Arnd Bergmann85c4b312014-12-02 12:08:27 +0100155 at91_pinctrl_gpio_suspend();
Ludovic Desroches84235362015-12-01 11:44:40 +0100156#endif
Andrew Victor907d6de2006-06-20 19:30:19 +0100157 switch (state) {
Wenyou Yang23be4be2015-03-09 11:49:46 +0800158 /*
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 Victor907d6de2006-06-20 19:30:19 +0100164 /*
Wenyou Yang23be4be2015-03-09 11:49:46 +0800165 * Ensure that clocks are in a valid state.
Andrew Victor907d6de2006-06-20 19:30:19 +0100166 */
Wenyou Yang23be4be2015-03-09 11:49:46 +0800167 if (!at91_pm_verify_clocks())
Andrew Victor907d6de2006-06-20 19:30:19 +0100168 goto error;
Wenyou Yang23be4be2015-03-09 11:49:46 +0800169
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 Victor907d6de2006-06-20 19:30:19 +0100191 }
192
Andrew Victor907d6de2006-06-20 19:30:19 +0100193error:
194 target_state = PM_SUSPEND_ON;
Boris BREZILLON07192602014-07-10 19:14:20 +0200195
Ludovic Desroches84235362015-12-01 11:44:40 +0100196#ifdef CONFIG_PINCTRL_AT91
Arnd Bergmann85c4b312014-12-02 12:08:27 +0100197 at91_pinctrl_gpio_resume();
Ludovic Desroches84235362015-12-01 11:44:40 +0100198#endif
Andrew Victor907d6de2006-06-20 19:30:19 +0100199 return 0;
200}
201
Rafael J. Wysockic697eec2008-01-08 00:04:17 +0100202/*
203 * Called right prior to thawing processes.
204 */
205static void at91_pm_end(void)
206{
207 target_state = PM_SUSPEND_ON;
208}
209
Andrew Victor907d6de2006-06-20 19:30:19 +0100210
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100211static const struct platform_suspend_ops at91_pm_ops = {
Rafael J. Wysockic697eec2008-01-08 00:04:17 +0100212 .valid = at91_pm_valid_state,
213 .begin = at91_pm_begin,
214 .enter = at91_pm_enter,
215 .end = at91_pm_end,
Andrew Victor907d6de2006-06-20 19:30:19 +0100216};
217
Daniel Lezcano5ad945e2013-09-22 22:29:57 +0200218static struct platform_device at91_cpuidle_device = {
219 .name = "cpuidle-at91",
220};
221
Wenyou Yang047794e2015-03-04 09:44:45 +0800222static void at91_pm_set_standby(void (*at91_standby)(void))
Daniel Lezcano5ad945e2013-09-22 22:29:57 +0200223{
Wenyou Yange32d9952015-03-09 11:51:49 +0800224 if (at91_standby)
Daniel Lezcano5ad945e2013-09-22 22:29:57 +0200225 at91_cpuidle_device.dev.platform_data = at91_standby;
Daniel Lezcano5ad945e2013-09-22 22:29:57 +0200226}
227
Alexandre Bellonia18d0692015-03-16 23:44:37 +0100228/*
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 */
237static void at91rm9200_standby(void)
238{
Alexandre Bellonid7d45f22015-03-16 15:14:50 +0100239 u32 lpr = at91_ramc_read(0, AT91_MC_SDRAMC_LPR);
Alexandre Bellonia18d0692015-03-16 23:44:37 +0100240
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 Bellonid7d45f22015-03-16 15:14:50 +0100250 : "r" (0), "r" (at91_ramc_base[0]), "r" (AT91_MC_SDRAMC_LPR),
251 "r" (1), "r" (AT91_MC_SDRAMC_SRR),
Alexandre Bellonia18d0692015-03-16 23:44:37 +0100252 "r" (lpr));
253}
254
255/* We manage both DDRAM/SDRAM controllers, we need more than one value to
256 * remember.
257 */
258static 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 Ferre60b89f12017-03-14 09:38:04 +0100287static 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 Bellonia18d0692015-03-16 23:44:37 +0100303/* We manage both DDRAM/SDRAM controllers, we need more than one value to
304 * remember.
305 */
306static 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 Pitre19c233b2015-07-27 18:27:52 -0400333static const struct of_device_id const ramc_ids[] __initconst = {
Alexandre Belloni827de1f2015-01-27 17:38:46 +0100334 { .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 Ferre60b89f12017-03-14 09:38:04 +0100337 { .compatible = "atmel,sama5d3-ddramc", .data = sama5d3_ddr_standby },
Alexandre Belloni827de1f2015-01-27 17:38:46 +0100338 { /*sentinel*/ }
339};
340
Uwe Kleine-König444d2d32015-02-18 21:19:56 +0100341static __init void at91_dt_ramc(void)
Alexandre Belloni827de1f2015-01-27 17:38:46 +0100342{
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 Dooksab6778e2016-06-17 16:34:18 +0100370static void at91rm9200_idle(void)
Alexandre Bellonifbc7edc2015-09-30 01:58:40 +0200371{
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 Dooksab6778e2016-06-17 16:34:18 +0100379static void at91sam9_idle(void)
Alexandre Bellonifbc7edc2015-09-30 01:58:40 +0200380{
381 writel(AT91_PMC_PCK, pmc + AT91_PMC_SCDR);
382 cpu_do_idle();
383}
384
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100385static 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 Belloni4a031f72015-03-03 08:38:07 +0100391 struct platform_device *pdev = NULL;
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100392
Alexandre Belloni4a031f72015-03-03 08:38:07 +0100393 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 Bellonid2e46792015-01-15 15:59:25 +0100399 }
400
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100401 if (!pdev) {
402 pr_warn("%s: failed to find sram device!\n", __func__);
Alexandre Belloni4a031f72015-03-03 08:38:07 +0100403 return;
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100404 }
405
Vladimir Zapolskiy73858172015-09-04 15:47:43 -0700406 sram_pool = gen_pool_get(&pdev->dev, NULL);
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100407 if (!sram_pool) {
408 pr_warn("%s: sram pool unavailable!\n", __func__);
Alexandre Belloni4a031f72015-03-03 08:38:07 +0100409 return;
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100410 }
411
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800412 sram_base = gen_pool_alloc(sram_pool, at91_pm_suspend_in_sram_sz);
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100413 if (!sram_base) {
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800414 pr_warn("%s: unable to alloc sram!\n", __func__);
Alexandre Belloni4a031f72015-03-03 08:38:07 +0100415 return;
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100416 }
417
418 sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800419 at91_suspend_sram_fn = __arm_ioremap_exec(sram_pbase,
420 at91_pm_suspend_in_sram_sz, false);
421 if (!at91_suspend_sram_fn) {
Wenyou Yangd94e6882015-03-09 11:49:01 +0800422 pr_warn("SRAM: Could not map\n");
423 return;
424 }
425
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800426 /* 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 Bellonid2e46792015-01-15 15:59:25 +0100429}
Alexandre Bellonid2e46792015-01-15 15:59:25 +0100430
Alexandre Belloni5737b732015-09-30 01:31:34 +0200431static 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 Bellonifbc7edc2015-09-30 01:58:40 +0200442static void __init at91_pm_init(void (*pm_idle)(void))
Andrew Victor907d6de2006-06-20 19:30:19 +0100443{
Alexandre Belloni5737b732015-09-30 01:31:34 +0200444 struct device_node *pmc_np;
Andrew Victorf5d0f452008-04-02 21:50:16 +0100445
Daniel Lezcano5ad945e2013-09-22 22:29:57 +0200446 if (at91_cpuidle_device.dev.platform_data)
447 platform_device_register(&at91_cpuidle_device);
Andrew Victor907d6de2006-06-20 19:30:19 +0100448
Alexandre Belloni5737b732015-09-30 01:31:34 +0200449 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 Bellonifbc7edc2015-09-30 01:58:40 +0200456 if (pm_idle)
457 arm_pm_idle = pm_idle;
458
Alexandre Belloni5737b732015-09-30 01:31:34 +0200459 at91_pm_sram_init();
460
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800461 if (at91_suspend_sram_fn)
Wenyou Yangd94e6882015-03-09 11:49:01 +0800462 suspend_set_ops(&at91_pm_ops);
463 else
464 pr_info("AT91: PM not supported, due to no SRAM allocated\n");
Andrew Victor907d6de2006-06-20 19:30:19 +0100465}
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100466
Nicolas Ferread3fc3e2015-01-27 18:41:33 +0100467void __init at91rm9200_pm_init(void)
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100468{
Alexandre Belloni827de1f2015-01-27 17:38:46 +0100469 at91_dt_ramc();
470
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100471 /*
472 * AT91RM9200 SDRAM low-power mode cannot be used with self-refresh.
473 */
Alexandre Bellonid7d45f22015-03-16 15:14:50 +0100474 at91_ramc_write(0, AT91_MC_SDRAMC_LPR, 0);
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100475
476 at91_pm_data.uhp_udp_mask = AT91RM9200_PMC_UHP | AT91RM9200_PMC_UDP;
477 at91_pm_data.memctrl = AT91_MEMCTRL_MC;
478
Alexandre Bellonifbc7edc2015-09-30 01:58:40 +0200479 at91_pm_init(at91rm9200_idle);
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100480}
481
Nicolas Ferread3fc3e2015-01-27 18:41:33 +0100482void __init at91sam9260_pm_init(void)
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100483{
Alexandre Belloni827de1f2015-01-27 17:38:46 +0100484 at91_dt_ramc();
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100485 at91_pm_data.memctrl = AT91_MEMCTRL_SDRAMC;
486 at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP;
Alexandre Bellonifbc7edc2015-09-30 01:58:40 +0200487 at91_pm_init(at91sam9_idle);
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100488}
489
Nicolas Ferread3fc3e2015-01-27 18:41:33 +0100490void __init at91sam9g45_pm_init(void)
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100491{
Alexandre Belloni827de1f2015-01-27 17:38:46 +0100492 at91_dt_ramc();
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100493 at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP;
494 at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR;
Alexandre Bellonifbc7edc2015-09-30 01:58:40 +0200495 at91_pm_init(at91sam9_idle);
Alexandre Belloni4db0ba22015-01-15 15:59:27 +0100496}
Nicolas Ferrebf022802015-01-22 16:54:50 +0100497
Nicolas Ferread3fc3e2015-01-27 18:41:33 +0100498void __init at91sam9x5_pm_init(void)
Nicolas Ferrebf022802015-01-22 16:54:50 +0100499{
Alexandre Belloni827de1f2015-01-27 17:38:46 +0100500 at91_dt_ramc();
Nicolas Ferrebf022802015-01-22 16:54:50 +0100501 at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP;
502 at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR;
Alexandre Bellonifbc7edc2015-09-30 01:58:40 +0200503 at91_pm_init(at91sam9_idle);
504}
505
506void __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 Ferrebf022802015-01-22 16:54:50 +0100512}