1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * arch/arm/mach-at91/pm.c
4 * AT91 Power Management
6 * Copyright (C) 2005 David Brownell
9 #include <linux/genalloc.h>
11 #include <linux/of_address.h>
13 #include <linux/of_fdt.h>
14 #include <linux/of_platform.h>
15 #include <linux/platform_device.h>
16 #include <linux/parser.h>
17 #include <linux/suspend.h>
19 #include <linux/clk.h>
20 #include <linux/clk/at91_pmc.h>
21 #include <linux/platform_data/atmel.h>
23 #include <asm/cacheflush.h>
24 #include <asm/fncpy.h>
25 #include <asm/system_misc.h>
26 #include <asm/suspend.h>
30 #include "sam_secure.h"
32 #define BACKUP_DDR_PHY_CALIBRATION (9)
35 * struct at91_pm_bu - AT91 power management backup unit data structure
36 * @suspended: true if suspended to backup mode
38 * @canary: canary data for memory checking after exit from backup mode
40 * @ddr_phy_calibration: DDR PHY calibration data: ZQ0CR0, first 8 words
45 unsigned long reserved;
48 unsigned long ddr_phy_calibration[BACKUP_DDR_PHY_CALIBRATION];
52 * struct at91_pm_sfrbu_regs - registers mapping for SFRBU
53 * @pswbu: power switch BU control registers
55 struct at91_pm_sfrbu_regs {
65 * enum at91_pm_eth_clk - Ethernet clock indexes
66 * @AT91_PM_ETH_PCLK: pclk index
67 * @AT91_PM_ETH_HCLK: hclk index
68 * @AT91_PM_ETH_MAX_CLK: max index
70 enum at91_pm_eth_clk {
77 * enum at91_pm_eth - Ethernet controller indexes
78 * @AT91_PM_G_ETH: gigabit Ethernet controller index
79 * @AT91_PM_E_ETH: megabit Ethernet controller index
80 * @AT91_PM_MAX_ETH: max index
89 * struct at91_pm_quirk_eth - AT91 PM Ethernet quirks
90 * @dev: Ethernet device
91 * @np: Ethernet device node
92 * @clks: Ethernet clocks
93 * @modes: power management mode that this quirk applies to
94 * @dns_modes: do not suspend modes: stop suspending if Ethernet is configured
95 * as wakeup source but buggy and no other wakeup source is
98 struct at91_pm_quirk_eth {
100 struct device_node *np;
101 struct clk_bulk_data clks[AT91_PM_ETH_MAX_CLK];
107 * struct at91_pm_quirks - AT91 PM quirks
108 * @eth: Ethernet quirks
110 struct at91_pm_quirks {
111 struct at91_pm_quirk_eth eth[AT91_PM_MAX_ETH];
115 * struct at91_soc_pm - AT91 SoC power management data structure
116 * @config_shdwc_ws: wakeup sources configuration function for SHDWC
117 * @config_pmc_ws: wakeup srouces configuration function for PMC
118 * @ws_ids: wakup sources of_device_id array
119 * @bu: backup unit mapped data (for backup mode)
121 * @data: PM data to be used on last phase of suspend
122 * @sfrbu_regs: SFRBU registers mapping
123 * @memcs: memory chip select
126 int (*config_shdwc_ws)(void __iomem *shdwc, u32 *mode, u32 *polarity);
127 int (*config_pmc_ws)(void __iomem *pmc, u32 mode, u32 polarity);
128 const struct of_device_id *ws_ids;
129 struct at91_pm_bu *bu;
130 struct at91_pm_quirks quirks;
131 struct at91_pm_data data;
132 struct at91_pm_sfrbu_regs sfrbu_regs;
137 * enum at91_pm_iomaps - IOs that needs to be mapped for different PM modes
138 * @AT91_PM_IOMAP_SHDWC: SHDWC controller
139 * @AT91_PM_IOMAP_SFRBU: SFRBU controller
140 * @AT91_PM_IOMAP_ETHC: Ethernet controller
142 enum at91_pm_iomaps {
148 #define AT91_PM_IOMAP(name) BIT(AT91_PM_IOMAP_##name)
150 static struct at91_soc_pm soc_pm = {
152 .standby_mode = AT91_PM_STANDBY,
153 .suspend_mode = AT91_PM_ULP0,
157 static const match_table_t pm_modes __initconst = {
158 { AT91_PM_STANDBY, "standby" },
159 { AT91_PM_ULP0, "ulp0" },
160 { AT91_PM_ULP0_FAST, "ulp0-fast" },
161 { AT91_PM_ULP1, "ulp1" },
162 { AT91_PM_BACKUP, "backup" },
166 #define at91_ramc_read(id, field) \
167 __raw_readl(soc_pm.data.ramc[id] + field)
169 #define at91_ramc_write(id, field, value) \
170 __raw_writel(value, soc_pm.data.ramc[id] + field)
172 static int at91_pm_valid_state(suspend_state_t state)
176 case PM_SUSPEND_STANDBY:
185 static int canary = 0xA5A5A5A5;
187 struct wakeup_source_info {
188 unsigned int pmc_fsmr_bit;
189 unsigned int shdwc_mr_bit;
193 static const struct wakeup_source_info ws_info[] = {
194 { .pmc_fsmr_bit = AT91_PMC_FSTT(10), .set_polarity = true },
195 { .pmc_fsmr_bit = AT91_PMC_RTCAL, .shdwc_mr_bit = BIT(17) },
196 { .pmc_fsmr_bit = AT91_PMC_USBAL },
197 { .pmc_fsmr_bit = AT91_PMC_SDMMC_CD },
198 { .pmc_fsmr_bit = AT91_PMC_RTTAL },
199 { .pmc_fsmr_bit = AT91_PMC_RXLP_MCE },
202 static const struct of_device_id sama5d2_ws_ids[] = {
203 { .compatible = "atmel,sama5d2-gem", .data = &ws_info[0] },
204 { .compatible = "atmel,sama5d2-rtc", .data = &ws_info[1] },
205 { .compatible = "atmel,sama5d3-udc", .data = &ws_info[2] },
206 { .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] },
207 { .compatible = "usb-ohci", .data = &ws_info[2] },
208 { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
209 { .compatible = "usb-ehci", .data = &ws_info[2] },
210 { .compatible = "atmel,sama5d2-sdhci", .data = &ws_info[3] },
214 static const struct of_device_id sam9x60_ws_ids[] = {
215 { .compatible = "microchip,sam9x60-rtc", .data = &ws_info[1] },
216 { .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] },
217 { .compatible = "usb-ohci", .data = &ws_info[2] },
218 { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
219 { .compatible = "usb-ehci", .data = &ws_info[2] },
220 { .compatible = "microchip,sam9x60-rtt", .data = &ws_info[4] },
221 { .compatible = "cdns,sam9x60-macb", .data = &ws_info[5] },
225 static const struct of_device_id sama7g5_ws_ids[] = {
226 { .compatible = "microchip,sama7g5-rtc", .data = &ws_info[1] },
227 { .compatible = "microchip,sama7g5-ohci", .data = &ws_info[2] },
228 { .compatible = "usb-ohci", .data = &ws_info[2] },
229 { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
230 { .compatible = "usb-ehci", .data = &ws_info[2] },
231 { .compatible = "microchip,sama7g5-sdhci", .data = &ws_info[3] },
232 { .compatible = "microchip,sama7g5-rtt", .data = &ws_info[4] },
236 static const struct of_device_id sam9x7_ws_ids[] = {
237 { .compatible = "microchip,sam9x7-rtc", .data = &ws_info[1] },
238 { .compatible = "microchip,sam9x7-rtt", .data = &ws_info[4] },
239 { .compatible = "microchip,sam9x7-gem", .data = &ws_info[5] },
243 static int at91_pm_config_ws(unsigned int pm_mode, bool set)
245 const struct wakeup_source_info *wsi;
246 const struct of_device_id *match;
247 struct platform_device *pdev;
248 struct device_node *np;
249 unsigned int mode = 0, polarity = 0, val = 0;
251 if (pm_mode != AT91_PM_ULP1)
254 if (!soc_pm.data.pmc || !soc_pm.data.shdwc || !soc_pm.ws_ids)
258 writel(mode, soc_pm.data.pmc + AT91_PMC_FSMR);
262 if (soc_pm.config_shdwc_ws)
263 soc_pm.config_shdwc_ws(soc_pm.data.shdwc, &mode, &polarity);
266 val = readl(soc_pm.data.shdwc + 0x04);
268 /* Loop through defined wakeup sources. */
269 for_each_matching_node_and_match(np, soc_pm.ws_ids, &match) {
270 pdev = of_find_device_by_node(np);
274 if (device_may_wakeup(&pdev->dev)) {
277 /* Check if enabled on SHDWC. */
278 if (wsi->shdwc_mr_bit && !(val & wsi->shdwc_mr_bit))
281 mode |= wsi->pmc_fsmr_bit;
282 if (wsi->set_polarity)
283 polarity |= wsi->pmc_fsmr_bit;
287 put_device(&pdev->dev);
291 if (soc_pm.config_pmc_ws)
292 soc_pm.config_pmc_ws(soc_pm.data.pmc, mode, polarity);
294 pr_err("AT91: PM: no ULP1 wakeup sources found!");
297 return mode ? 0 : -EPERM;
300 static int at91_sama5d2_config_shdwc_ws(void __iomem *shdwc, u32 *mode,
306 val = readl(shdwc + 0x0c);
307 *mode |= (val & 0x3ff);
308 *polarity |= ((val >> 16) & 0x3ff);
313 static int at91_sama5d2_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity)
315 writel(mode, pmc + AT91_PMC_FSMR);
316 writel(polarity, pmc + AT91_PMC_FSPR);
321 static int at91_sam9x60_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity)
323 writel(mode, pmc + AT91_PMC_FSMR);
328 static bool at91_pm_eth_quirk_is_valid(struct at91_pm_quirk_eth *eth)
330 struct platform_device *pdev;
332 /* Interface NA in DT. */
336 /* No quirks for this interface and current suspend mode. */
337 if (!(eth->modes & BIT(soc_pm.data.mode)))
341 /* Driver not probed. */
342 pdev = of_find_device_by_node(eth->np);
345 /* put_device(eth->dev) is called at the end of suspend. */
346 eth->dev = &pdev->dev;
349 /* No quirks if device isn't a wakeup source. */
350 if (!device_may_wakeup(eth->dev))
356 static int at91_pm_config_quirks(bool suspend)
358 struct at91_pm_quirk_eth *eth;
362 * Ethernet IPs who's device_node pointers are stored into
363 * soc_pm.quirks.eth[].np cannot handle WoL packets while in ULP0, ULP1
364 * or both due to a hardware bug. If they receive WoL packets while in
365 * ULP0 or ULP1 IPs could stop working or the whole system could stop
366 * working. We cannot handle this scenario in the ethernet driver itself
367 * as the driver is common to multiple vendors and also we only know
368 * here, in this file, if we suspend to ULP0 or ULP1 mode. Thus handle
369 * these scenarios here, as quirks.
371 for (i = 0; i < AT91_PM_MAX_ETH; i++) {
372 eth = &soc_pm.quirks.eth[i];
374 if (!at91_pm_eth_quirk_is_valid(eth))
378 * For modes in dns_modes mask the system blocks if quirk is not
379 * applied but if applied the interface doesn't act at WoL
380 * events. Thus take care to avoid suspending if this interface
381 * is the only configured wakeup source.
383 if (suspend && eth->dns_modes & BIT(soc_pm.data.mode)) {
385 #ifdef CONFIG_PM_SLEEP
386 struct wakeup_source *ws;
388 for_each_wakeup_source(ws) {
389 if (ws->dev == eth->dev)
398 * Checking !ws is good for all platforms with issues
399 * even when both G_ETH and E_ETH are available as dns_modes
400 * is populated only on G_ETH interface.
403 pr_err("AT91: PM: Ethernet cannot resume from WoL!");
405 put_device(eth->dev);
407 /* No need to revert clock settings for this eth. */
409 goto clk_unconfigure;
414 clk_bulk_disable_unprepare(AT91_PM_ETH_MAX_CLK, eth->clks);
416 ret = clk_bulk_prepare_enable(AT91_PM_ETH_MAX_CLK,
419 goto clk_unconfigure;
421 * Release the reference to eth->dev taken in
422 * at91_pm_eth_quirk_is_valid().
424 put_device(eth->dev);
433 * In case of resume we reach this point if clk_prepare_enable() failed.
434 * we don't want to revert the previous clk_prepare_enable() for the
437 for (j = i; j >= 0; j--) {
438 eth = &soc_pm.quirks.eth[j];
440 if (!at91_pm_eth_quirk_is_valid(eth))
443 tmp = clk_bulk_prepare_enable(AT91_PM_ETH_MAX_CLK, eth->clks);
445 pr_err("AT91: PM: failed to enable %s clocks\n",
446 j == AT91_PM_G_ETH ? "geth" : "eth");
451 * Release the reference to eth->dev taken in
452 * at91_pm_eth_quirk_is_valid().
454 put_device(eth->dev);
462 * Called after processes are frozen, but before we shutdown devices.
464 static int at91_pm_begin(suspend_state_t state)
470 soc_pm.data.mode = soc_pm.data.suspend_mode;
473 case PM_SUSPEND_STANDBY:
474 soc_pm.data.mode = soc_pm.data.standby_mode;
478 soc_pm.data.mode = -1;
481 ret = at91_pm_config_ws(soc_pm.data.mode, true);
485 if (soc_pm.data.mode == AT91_PM_BACKUP)
486 soc_pm.bu->suspended = 1;
488 soc_pm.bu->suspended = 0;
494 * Verify that all the clocks are correct before entering
497 static int at91_pm_verify_clocks(void)
502 scsr = readl(soc_pm.data.pmc + AT91_PMC_SCSR);
504 /* USB must not be using PLLB */
505 if ((scsr & soc_pm.data.uhp_udp_mask) != 0) {
506 pr_err("AT91: PM - Suspend-to-RAM with USB still active\n");
510 /* PCK0..PCK3 must be disabled, or configured to use clk32k */
511 for (i = 0; i < 4; i++) {
514 if ((scsr & (AT91_PMC_PCK0 << i)) == 0)
516 css = readl(soc_pm.data.pmc + AT91_PMC_PCKR(i)) & AT91_PMC_CSS;
517 if (css != AT91_PMC_CSS_SLOW) {
518 pr_err("AT91: PM - Suspend-to-RAM with PCK%d src %d\n", i, css);
527 * Call this from platform driver suspend() to see how deeply to suspend.
528 * For example, some controllers (like OHCI) need one of the PLL clocks
529 * in order to act as a wakeup source, and those are not available when
530 * going into slow clock mode.
532 * REVISIT: generalize as clk_will_be_available(clk)? Other platforms have
533 * the very same problem (but not using at91 main_clk), and it'd be better
534 * to add one generic API rather than lots of platform-specific ones.
536 int at91_suspend_entering_slow_clock(void)
538 return (soc_pm.data.mode >= AT91_PM_ULP0);
540 EXPORT_SYMBOL(at91_suspend_entering_slow_clock);
542 static void (*at91_suspend_sram_fn)(struct at91_pm_data *);
543 extern void at91_pm_suspend_in_sram(struct at91_pm_data *pm_data);
544 extern u32 at91_pm_suspend_in_sram_sz;
546 static int at91_suspend_finish(unsigned long val)
548 unsigned char modified_gray_code[] = {
549 0x00, 0x01, 0x02, 0x03, 0x06, 0x07, 0x04, 0x05, 0x0c, 0x0d,
550 0x0e, 0x0f, 0x0a, 0x0b, 0x08, 0x09, 0x18, 0x19, 0x1a, 0x1b,
551 0x1e, 0x1f, 0x1c, 0x1d, 0x14, 0x15, 0x16, 0x17, 0x12, 0x13,
554 unsigned int tmp, index;
557 if (soc_pm.data.mode == AT91_PM_BACKUP && soc_pm.data.ramc_phy) {
559 * Bootloader will perform DDR recalibration and will try to
560 * restore the ZQ0SR0 with the value saved here. But the
561 * calibration is buggy and restoring some values from ZQ0SR0
562 * is forbidden and risky thus we need to provide processed
563 * values for these (modified gray code values).
565 tmp = readl(soc_pm.data.ramc_phy + DDR3PHY_ZQ0SR0);
567 /* Store pull-down output impedance select. */
568 index = (tmp >> DDR3PHY_ZQ0SR0_PDO_OFF) & 0x1f;
569 soc_pm.bu->ddr_phy_calibration[0] = modified_gray_code[index];
571 /* Store pull-up output impedance select. */
572 index = (tmp >> DDR3PHY_ZQ0SR0_PUO_OFF) & 0x1f;
573 soc_pm.bu->ddr_phy_calibration[0] |= modified_gray_code[index];
575 /* Store pull-down on-die termination impedance select. */
576 index = (tmp >> DDR3PHY_ZQ0SR0_PDODT_OFF) & 0x1f;
577 soc_pm.bu->ddr_phy_calibration[0] |= modified_gray_code[index];
579 /* Store pull-up on-die termination impedance select. */
580 index = (tmp >> DDR3PHY_ZQ0SRO_PUODT_OFF) & 0x1f;
581 soc_pm.bu->ddr_phy_calibration[0] |= modified_gray_code[index];
584 * The 1st 8 words of memory might get corrupted in the process
585 * of DDR PHY recalibration; it is saved here in securam and it
586 * will be restored later, after recalibration, by bootloader
588 for (i = 1; i < BACKUP_DDR_PHY_CALIBRATION; i++)
589 soc_pm.bu->ddr_phy_calibration[i] =
590 *((unsigned int *)soc_pm.memcs + (i - 1));
596 at91_suspend_sram_fn(&soc_pm.data);
602 * at91_pm_switch_ba_to_auto() - Configure Backup Unit Power Switch
603 * to automatic/hardware mode.
605 * The Backup Unit Power Switch can be managed either by software or hardware.
606 * Enabling hardware mode allows the automatic transition of power between
607 * VDDANA (or VDDIN33) and VDDBU (or VBAT, respectively), based on the
608 * availability of these power sources.
610 * If the Backup Unit Power Switch is already in automatic mode, no action is
611 * required. If it is in software-controlled mode, it is switched to automatic
612 * mode to enhance safety and eliminate the need for toggling between power
615 static void at91_pm_switch_ba_to_auto(void)
617 unsigned int offset = offsetof(struct at91_pm_sfrbu_regs, pswbu);
620 /* Just for safety. */
621 if (!soc_pm.data.sfrbu)
624 val = readl(soc_pm.data.sfrbu + offset);
626 /* Already on auto/hardware. */
627 if (!(val & soc_pm.sfrbu_regs.pswbu.ctrl))
630 val &= ~soc_pm.sfrbu_regs.pswbu.ctrl;
631 val |= soc_pm.sfrbu_regs.pswbu.key;
632 writel(val, soc_pm.data.sfrbu + offset);
635 static void at91_pm_suspend(suspend_state_t state)
637 if (soc_pm.data.mode == AT91_PM_BACKUP) {
638 at91_pm_switch_ba_to_auto();
640 cpu_suspend(0, at91_suspend_finish);
642 /* The SRAM is lost between suspend cycles */
643 at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn,
644 &at91_pm_suspend_in_sram,
645 at91_pm_suspend_in_sram_sz);
647 at91_suspend_finish(0);
654 * STANDBY mode has *all* drivers suspended; ignores irqs not marked as 'wakeup'
655 * event sources; and reduces DRAM power. But otherwise it's identical to
656 * PM_SUSPEND_ON: cpu idle, and nothing fancy done with main or cpu clocks.
658 * AT91_PM_ULP0 is like STANDBY plus slow clock mode, so drivers must
659 * suspend more deeply, the master clock switches to the clk32k and turns off
660 * the main oscillator
662 * AT91_PM_BACKUP turns off the whole SoC after placing the DDR in self refresh
664 static int at91_pm_enter(suspend_state_t state)
668 ret = at91_pm_config_quirks(true);
674 case PM_SUSPEND_STANDBY:
676 * Ensure that clocks are in a valid state.
678 if (soc_pm.data.mode >= AT91_PM_ULP0 &&
679 !at91_pm_verify_clocks())
682 at91_pm_suspend(state);
691 pr_debug("AT91: PM - bogus suspend state %d\n", state);
696 at91_pm_config_quirks(false);
701 * Called right prior to thawing processes.
703 static void at91_pm_end(void)
705 at91_pm_config_ws(soc_pm.data.mode, false);
709 static const struct platform_suspend_ops at91_pm_ops = {
710 .valid = at91_pm_valid_state,
711 .begin = at91_pm_begin,
712 .enter = at91_pm_enter,
716 static struct platform_device at91_cpuidle_device = {
717 .name = "cpuidle-at91",
721 * The AT91RM9200 goes into self-refresh mode with this command, and will
722 * terminate self-refresh automatically on the next SDRAM access.
724 * Self-refresh mode is exited as soon as a memory access is made, but we don't
725 * know for sure when that happens. However, we need to restore the low-power
726 * mode if it was enabled before going idle. Restoring low-power mode while
727 * still in self-refresh is "not recommended", but seems to work.
729 static void at91rm9200_standby(void)
734 "1: mcr p15, 0, %0, c7, c10, 4\n\t"
735 " str %2, [%1, %3]\n\t"
736 " mcr p15, 0, %0, c7, c0, 4\n\t"
738 : "r" (0), "r" (soc_pm.data.ramc[0]),
739 "r" (1), "r" (AT91_MC_SDRAMC_SRR));
742 /* We manage both DDRAM/SDRAM controllers, we need more than one value to
745 static void at91_ddr_standby(void)
747 /* Those two values allow us to delay self-refresh activation
750 u32 mdr, saved_mdr0, saved_mdr1 = 0;
751 u32 saved_lpr0, saved_lpr1 = 0;
753 /* LPDDR1 --> force DDR2 mode during self-refresh */
754 saved_mdr0 = at91_ramc_read(0, AT91_DDRSDRC_MDR);
755 if ((saved_mdr0 & AT91_DDRSDRC_MD) == AT91_DDRSDRC_MD_LOW_POWER_DDR) {
756 mdr = saved_mdr0 & ~AT91_DDRSDRC_MD;
757 mdr |= AT91_DDRSDRC_MD_DDR2;
758 at91_ramc_write(0, AT91_DDRSDRC_MDR, mdr);
761 if (soc_pm.data.ramc[1]) {
762 saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR);
763 lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB;
764 lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
765 saved_mdr1 = at91_ramc_read(1, AT91_DDRSDRC_MDR);
766 if ((saved_mdr1 & AT91_DDRSDRC_MD) == AT91_DDRSDRC_MD_LOW_POWER_DDR) {
767 mdr = saved_mdr1 & ~AT91_DDRSDRC_MD;
768 mdr |= AT91_DDRSDRC_MD_DDR2;
769 at91_ramc_write(1, AT91_DDRSDRC_MDR, mdr);
773 saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
774 lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
775 lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
777 /* self-refresh mode now */
778 at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
779 if (soc_pm.data.ramc[1])
780 at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1);
784 at91_ramc_write(0, AT91_DDRSDRC_MDR, saved_mdr0);
785 at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
786 if (soc_pm.data.ramc[1]) {
787 at91_ramc_write(0, AT91_DDRSDRC_MDR, saved_mdr1);
788 at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1);
792 static void sama5d3_ddr_standby(void)
797 saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
798 lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
799 lpr0 |= AT91_DDRSDRC_LPCB_POWER_DOWN;
801 at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
805 at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
808 /* We manage both DDRAM/SDRAM controllers, we need more than one value to
811 static void at91sam9_sdram_standby(void)
814 u32 saved_lpr0, saved_lpr1 = 0;
816 if (soc_pm.data.ramc[1]) {
817 saved_lpr1 = at91_ramc_read(1, AT91_SDRAMC_LPR);
818 lpr1 = saved_lpr1 & ~AT91_SDRAMC_LPCB;
819 lpr1 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
822 saved_lpr0 = at91_ramc_read(0, AT91_SDRAMC_LPR);
823 lpr0 = saved_lpr0 & ~AT91_SDRAMC_LPCB;
824 lpr0 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
826 /* self-refresh mode now */
827 at91_ramc_write(0, AT91_SDRAMC_LPR, lpr0);
828 if (soc_pm.data.ramc[1])
829 at91_ramc_write(1, AT91_SDRAMC_LPR, lpr1);
833 at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr0);
834 if (soc_pm.data.ramc[1])
835 at91_ramc_write(1, AT91_SDRAMC_LPR, saved_lpr1);
838 static void sama7g5_standby(void)
842 pwrtmg = readl(soc_pm.data.ramc[0] + UDDRC_PWRCTL);
843 ratio = readl(soc_pm.data.pmc + AT91_PMC_RATIO);
846 * Place RAM into self-refresh after a maximum idle clocks. The maximum
847 * idle clocks is configured by bootloader in
848 * UDDRC_PWRMGT.SELFREF_TO_X32.
850 writel(pwrtmg | UDDRC_PWRCTL_SELFREF_EN,
851 soc_pm.data.ramc[0] + UDDRC_PWRCTL);
852 /* Divide CPU clock by 16. */
853 writel(ratio & ~AT91_PMC_RATIO_RATIO, soc_pm.data.pmc + AT91_PMC_RATIO);
857 /* Restore previous configuration. */
858 writel(ratio, soc_pm.data.pmc + AT91_PMC_RATIO);
859 writel(pwrtmg, soc_pm.data.ramc[0] + UDDRC_PWRCTL);
864 unsigned int memctrl;
867 static const struct ramc_info ramc_infos[] __initconst = {
868 { .idle = at91rm9200_standby, .memctrl = AT91_MEMCTRL_MC},
869 { .idle = at91sam9_sdram_standby, .memctrl = AT91_MEMCTRL_SDRAMC},
870 { .idle = at91_ddr_standby, .memctrl = AT91_MEMCTRL_DDRSDR},
871 { .idle = sama5d3_ddr_standby, .memctrl = AT91_MEMCTRL_DDRSDR},
872 { .idle = sama7g5_standby, },
875 static const struct of_device_id ramc_ids[] __initconst = {
876 { .compatible = "atmel,at91rm9200-sdramc", .data = &ramc_infos[0] },
877 { .compatible = "atmel,at91sam9260-sdramc", .data = &ramc_infos[1] },
878 { .compatible = "atmel,at91sam9g45-ddramc", .data = &ramc_infos[2] },
879 { .compatible = "atmel,sama5d3-ddramc", .data = &ramc_infos[3] },
880 { .compatible = "microchip,sama7g5-uddrc", .data = &ramc_infos[4], },
884 static const struct of_device_id ramc_phy_ids[] __initconst = {
885 { .compatible = "microchip,sama7g5-ddr3phy", },
889 static __init int at91_dt_ramc(bool phy_mandatory)
891 struct device_node *np;
892 const struct of_device_id *of_id;
894 void *standby = NULL;
895 const struct ramc_info *ramc;
898 for_each_matching_node_and_match(np, ramc_ids, &of_id) {
899 soc_pm.data.ramc[idx] = of_iomap(np, 0);
900 if (!soc_pm.data.ramc[idx]) {
901 pr_err("unable to map ramc[%d] cpu registers\n", idx);
910 standby = ramc->idle;
911 soc_pm.data.memctrl = ramc->memctrl;
918 pr_err("unable to find compatible ram controller node in dtb\n");
923 /* Lookup for DDR PHY node, if any. */
924 for_each_matching_node_and_match(np, ramc_phy_ids, &of_id) {
925 soc_pm.data.ramc_phy = of_iomap(np, 0);
926 if (!soc_pm.data.ramc_phy) {
927 pr_err("unable to map ramc phy cpu registers\n");
934 if (phy_mandatory && !soc_pm.data.ramc_phy) {
935 pr_err("DDR PHY is mandatory!\n");
941 pr_warn("ramc no standby function available\n");
945 at91_cpuidle_device.dev.platform_data = standby;
951 iounmap(soc_pm.data.ramc[--idx]);
956 static void at91rm9200_idle(void)
959 * Disable the processor clock. The processor will be automatically
960 * re-enabled by an interrupt or by a reset.
962 writel(AT91_PMC_PCK, soc_pm.data.pmc + AT91_PMC_SCDR);
965 static void at91sam9_idle(void)
967 writel(AT91_PMC_PCK, soc_pm.data.pmc + AT91_PMC_SCDR);
971 static void __init at91_pm_sram_init(void)
973 struct gen_pool *sram_pool;
974 phys_addr_t sram_pbase;
975 unsigned long sram_base;
976 struct device_node *node;
977 struct platform_device *pdev = NULL;
979 for_each_compatible_node(node, NULL, "mmio-sram") {
980 pdev = of_find_device_by_node(node);
988 pr_warn("%s: failed to find sram device!\n", __func__);
992 sram_pool = gen_pool_get(&pdev->dev, NULL);
994 pr_warn("%s: sram pool unavailable!\n", __func__);
998 sram_base = gen_pool_alloc(sram_pool, at91_pm_suspend_in_sram_sz);
1000 pr_warn("%s: unable to alloc sram!\n", __func__);
1001 goto out_put_device;
1004 sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
1005 at91_suspend_sram_fn = __arm_ioremap_exec(sram_pbase,
1006 at91_pm_suspend_in_sram_sz, false);
1007 if (!at91_suspend_sram_fn) {
1008 pr_warn("SRAM: Could not map\n");
1009 goto out_put_device;
1012 /* Copy the pm suspend handler to SRAM */
1013 at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn,
1014 &at91_pm_suspend_in_sram, at91_pm_suspend_in_sram_sz);
1018 put_device(&pdev->dev);
1022 static bool __init at91_is_pm_mode_active(int pm_mode)
1024 return (soc_pm.data.standby_mode == pm_mode ||
1025 soc_pm.data.suspend_mode == pm_mode);
1028 static int __init at91_pm_backup_scan_memcs(unsigned long node,
1029 const char *uname, int depth,
1034 int *located = data;
1037 /* Memory node already located. */
1041 type = of_get_flat_dt_prop(node, "device_type", NULL);
1043 /* We are scanning "memory" nodes only. */
1044 if (!type || strcmp(type, "memory"))
1047 reg = of_get_flat_dt_prop(node, "reg", &size);
1049 soc_pm.memcs = __va((phys_addr_t)be32_to_cpu(*reg));
1056 static int __init at91_pm_backup_init(void)
1058 struct gen_pool *sram_pool;
1059 struct device_node *np;
1060 struct platform_device *pdev;
1061 int ret = -ENODEV, located = 0;
1063 if (!IS_ENABLED(CONFIG_SOC_SAMA5D2) &&
1064 !IS_ENABLED(CONFIG_SOC_SAMA7G5))
1067 if (!at91_is_pm_mode_active(AT91_PM_BACKUP))
1070 np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
1074 pdev = of_find_device_by_node(np);
1077 pr_warn("%s: failed to find securam device!\n", __func__);
1081 sram_pool = gen_pool_get(&pdev->dev, NULL);
1083 pr_warn("%s: securam pool unavailable!\n", __func__);
1087 soc_pm.bu = (void *)gen_pool_alloc(sram_pool, sizeof(struct at91_pm_bu));
1089 pr_warn("%s: unable to alloc securam!\n", __func__);
1094 soc_pm.bu->suspended = 0;
1095 soc_pm.bu->canary = __pa_symbol(&canary);
1096 soc_pm.bu->resume = __pa_symbol(cpu_resume);
1097 if (soc_pm.data.ramc_phy) {
1098 of_scan_flat_dt(at91_pm_backup_scan_memcs, &located);
1106 put_device(&pdev->dev);
1110 static void __init at91_pm_secure_init(void)
1113 struct arm_smccc_res res;
1115 suspend_mode = soc_pm.data.suspend_mode;
1117 res = sam_smccc_call(SAMA5_SMC_SIP_SET_SUSPEND_MODE,
1120 pr_info("AT91: Secure PM: suspend mode set to %s\n",
1121 pm_modes[suspend_mode].pattern);
1122 soc_pm.data.mode = suspend_mode;
1126 pr_warn("AT91: Secure PM: %s mode not supported !\n",
1127 pm_modes[suspend_mode].pattern);
1129 res = sam_smccc_call(SAMA5_SMC_SIP_GET_SUSPEND_MODE, 0, 0);
1131 pr_warn("AT91: Secure PM: failed to get default mode\n");
1132 soc_pm.data.mode = -1;
1136 pr_info("AT91: Secure PM: using default suspend mode %s\n",
1137 pm_modes[suspend_mode].pattern);
1139 soc_pm.data.suspend_mode = res.a1;
1140 soc_pm.data.mode = soc_pm.data.suspend_mode;
1142 static const struct of_device_id atmel_shdwc_ids[] = {
1143 { .compatible = "atmel,sama5d2-shdwc" },
1144 { .compatible = "microchip,sam9x60-shdwc" },
1145 { .compatible = "microchip,sama7g5-shdwc" },
1149 static const struct of_device_id gmac_ids[] __initconst = {
1150 { .compatible = "atmel,sama5d3-gem" },
1151 { .compatible = "atmel,sama5d2-gem" },
1152 { .compatible = "atmel,sama5d29-gem" },
1153 { .compatible = "microchip,sama7g5-gem" },
1157 static const struct of_device_id emac_ids[] __initconst = {
1158 { .compatible = "atmel,sama5d3-macb" },
1159 { .compatible = "microchip,sama7g5-emac" },
1164 * Replaces _mode_to_replace with a supported mode that doesn't depend
1165 * on controller pointed by _map_bitmask
1166 * @_maps: u32 array containing AT91_PM_IOMAP() flags and indexed by AT91
1168 * @_map_bitmask: AT91_PM_IOMAP() bitmask; if _mode_to_replace depends on
1169 * controller represented by _map_bitmask, _mode_to_replace needs to be
1171 * @_mode_to_replace: standby_mode or suspend_mode that need to be
1173 * @_mode_to_check: standby_mode or suspend_mode; this is needed here
1174 * to avoid having standby_mode and suspend_mode set with the same AT91
1177 #define AT91_PM_REPLACE_MODE(_maps, _map_bitmask, _mode_to_replace, \
1180 if (((_maps)[(_mode_to_replace)]) & (_map_bitmask)) { \
1181 int _mode_to_use, _mode_complementary; \
1182 /* Use ULP0 if it doesn't need _map_bitmask. */ \
1183 if (!((_maps)[AT91_PM_ULP0] & (_map_bitmask))) {\
1184 _mode_to_use = AT91_PM_ULP0; \
1185 _mode_complementary = AT91_PM_STANDBY; \
1187 _mode_to_use = AT91_PM_STANDBY; \
1188 _mode_complementary = AT91_PM_STANDBY; \
1191 if ((_mode_to_check) != _mode_to_use) \
1192 (_mode_to_replace) = _mode_to_use; \
1194 (_mode_to_replace) = _mode_complementary;\
1199 * Replaces standby and suspend modes with default supported modes:
1201 * @_maps: u32 array indexed by AT91 PM mode containing AT91_PM_IOMAP()
1203 * @_map: controller specific name; standby and suspend mode need to be
1204 * replaced in order to not depend on this controller
1206 #define AT91_PM_REPLACE_MODES(_maps, _map) \
1208 AT91_PM_REPLACE_MODE((_maps), BIT(AT91_PM_IOMAP_##_map),\
1209 (soc_pm.data.standby_mode), \
1210 (soc_pm.data.suspend_mode)); \
1211 AT91_PM_REPLACE_MODE((_maps), BIT(AT91_PM_IOMAP_##_map),\
1212 (soc_pm.data.suspend_mode), \
1213 (soc_pm.data.standby_mode)); \
1216 static int __init at91_pm_get_eth_clks(struct device_node *np,
1217 struct clk_bulk_data *clks)
1219 clks[AT91_PM_ETH_PCLK].clk = of_clk_get_by_name(np, "pclk");
1220 if (IS_ERR(clks[AT91_PM_ETH_PCLK].clk))
1221 return PTR_ERR(clks[AT91_PM_ETH_PCLK].clk);
1223 clks[AT91_PM_ETH_HCLK].clk = of_clk_get_by_name(np, "hclk");
1224 if (IS_ERR(clks[AT91_PM_ETH_HCLK].clk))
1225 return PTR_ERR(clks[AT91_PM_ETH_HCLK].clk);
1230 static int __init at91_pm_eth_clks_empty(struct clk_bulk_data *clks)
1232 return IS_ERR(clks[AT91_PM_ETH_PCLK].clk) ||
1233 IS_ERR(clks[AT91_PM_ETH_HCLK].clk);
1236 static void __init at91_pm_modes_init(const u32 *maps, int len)
1238 struct at91_pm_quirk_eth *gmac = &soc_pm.quirks.eth[AT91_PM_G_ETH];
1239 struct at91_pm_quirk_eth *emac = &soc_pm.quirks.eth[AT91_PM_E_ETH];
1240 struct device_node *np;
1243 ret = at91_pm_backup_init();
1245 if (soc_pm.data.standby_mode == AT91_PM_BACKUP)
1246 soc_pm.data.standby_mode = AT91_PM_ULP0;
1247 if (soc_pm.data.suspend_mode == AT91_PM_BACKUP)
1248 soc_pm.data.suspend_mode = AT91_PM_ULP0;
1251 if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC) ||
1252 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC)) {
1253 np = of_find_matching_node(NULL, atmel_shdwc_ids);
1255 pr_warn("%s: failed to find shdwc!\n", __func__);
1256 AT91_PM_REPLACE_MODES(maps, SHDWC);
1258 soc_pm.data.shdwc = of_iomap(np, 0);
1263 if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU) ||
1264 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU)) {
1265 np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-sfrbu");
1267 pr_warn("%s: failed to find sfrbu!\n", __func__);
1268 AT91_PM_REPLACE_MODES(maps, SFRBU);
1270 soc_pm.data.sfrbu = of_iomap(np, 0);
1275 if ((at91_is_pm_mode_active(AT91_PM_ULP1) ||
1276 at91_is_pm_mode_active(AT91_PM_ULP0) ||
1277 at91_is_pm_mode_active(AT91_PM_ULP0_FAST)) &&
1278 (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(ETHC) ||
1279 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(ETHC))) {
1280 np = of_find_matching_node(NULL, gmac_ids);
1282 np = of_find_matching_node(NULL, emac_ids);
1285 AT91_PM_REPLACE_MODES(maps, ETHC);
1286 goto unmap_unused_nodes;
1289 at91_pm_get_eth_clks(np, gmac->clks);
1292 np = of_find_matching_node(NULL, emac_ids);
1294 if (at91_pm_eth_clks_empty(gmac->clks))
1295 AT91_PM_REPLACE_MODES(maps, ETHC);
1299 ret = at91_pm_get_eth_clks(np, emac->clks);
1300 if (ret && at91_pm_eth_clks_empty(gmac->clks)) {
1301 of_node_put(gmac->np);
1302 of_node_put(emac->np);
1310 /* Unmap all unnecessary. */
1311 if (soc_pm.data.shdwc &&
1312 !(maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC) ||
1313 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC))) {
1314 iounmap(soc_pm.data.shdwc);
1315 soc_pm.data.shdwc = NULL;
1318 if (soc_pm.data.sfrbu &&
1319 !(maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU) ||
1320 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU))) {
1321 iounmap(soc_pm.data.sfrbu);
1322 soc_pm.data.sfrbu = NULL;
1329 unsigned long uhp_udp_mask;
1331 unsigned long version;
1334 static const struct pmc_info pmc_infos[] __initconst = {
1336 .uhp_udp_mask = AT91RM9200_PMC_UHP | AT91RM9200_PMC_UDP,
1338 .version = AT91_PMC_V1,
1342 .uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP,
1344 .version = AT91_PMC_V1,
1347 .uhp_udp_mask = AT91SAM926x_PMC_UHP,
1349 .version = AT91_PMC_V1,
1351 { .uhp_udp_mask = 0,
1353 .version = AT91_PMC_V1,
1356 .uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP,
1358 .version = AT91_PMC_V2,
1362 .version = AT91_PMC_V2,
1367 static const struct of_device_id atmel_pmc_ids[] __initconst = {
1368 { .compatible = "atmel,at91rm9200-pmc", .data = &pmc_infos[0] },
1369 { .compatible = "atmel,at91sam9260-pmc", .data = &pmc_infos[1] },
1370 { .compatible = "atmel,at91sam9261-pmc", .data = &pmc_infos[1] },
1371 { .compatible = "atmel,at91sam9263-pmc", .data = &pmc_infos[1] },
1372 { .compatible = "atmel,at91sam9g45-pmc", .data = &pmc_infos[2] },
1373 { .compatible = "atmel,at91sam9n12-pmc", .data = &pmc_infos[1] },
1374 { .compatible = "atmel,at91sam9rl-pmc", .data = &pmc_infos[3] },
1375 { .compatible = "atmel,at91sam9x5-pmc", .data = &pmc_infos[1] },
1376 { .compatible = "atmel,sama5d3-pmc", .data = &pmc_infos[1] },
1377 { .compatible = "atmel,sama5d4-pmc", .data = &pmc_infos[1] },
1378 { .compatible = "atmel,sama5d2-pmc", .data = &pmc_infos[1] },
1379 { .compatible = "microchip,sam9x60-pmc", .data = &pmc_infos[4] },
1380 { .compatible = "microchip,sam9x7-pmc", .data = &pmc_infos[4] },
1381 { .compatible = "microchip,sama7g5-pmc", .data = &pmc_infos[5] },
1385 static void __init at91_pm_modes_validate(const int *modes, int len)
1387 u8 i, standby = 0, suspend = 0;
1390 for (i = 0; i < len; i++) {
1391 if (standby && suspend)
1394 if (modes[i] == soc_pm.data.standby_mode && !standby) {
1399 if (modes[i] == soc_pm.data.suspend_mode && !suspend) {
1406 if (soc_pm.data.suspend_mode == AT91_PM_STANDBY)
1407 mode = AT91_PM_ULP0;
1409 mode = AT91_PM_STANDBY;
1411 pr_warn("AT91: PM: %s mode not supported! Using %s.\n",
1412 pm_modes[soc_pm.data.standby_mode].pattern,
1413 pm_modes[mode].pattern);
1414 soc_pm.data.standby_mode = mode;
1418 if (soc_pm.data.standby_mode == AT91_PM_ULP0)
1419 mode = AT91_PM_STANDBY;
1421 mode = AT91_PM_ULP0;
1423 pr_warn("AT91: PM: %s mode not supported! Using %s.\n",
1424 pm_modes[soc_pm.data.suspend_mode].pattern,
1425 pm_modes[mode].pattern);
1426 soc_pm.data.suspend_mode = mode;
1430 static void __init at91_pm_init(void (*pm_idle)(void))
1432 struct device_node *pmc_np;
1433 const struct of_device_id *of_id;
1434 const struct pmc_info *pmc;
1436 if (at91_cpuidle_device.dev.platform_data)
1437 platform_device_register(&at91_cpuidle_device);
1439 pmc_np = of_find_matching_node_and_match(NULL, atmel_pmc_ids, &of_id);
1440 soc_pm.data.pmc = of_iomap(pmc_np, 0);
1441 of_node_put(pmc_np);
1442 if (!soc_pm.data.pmc) {
1443 pr_err("AT91: PM not supported, PMC not found\n");
1448 soc_pm.data.uhp_udp_mask = pmc->uhp_udp_mask;
1449 soc_pm.data.pmc_mckr_offset = pmc->mckr;
1450 soc_pm.data.pmc_version = pmc->version;
1453 arm_pm_idle = pm_idle;
1455 at91_pm_sram_init();
1457 if (at91_suspend_sram_fn) {
1458 suspend_set_ops(&at91_pm_ops);
1459 pr_info("AT91: PM: standby: %s, suspend: %s\n",
1460 pm_modes[soc_pm.data.standby_mode].pattern,
1461 pm_modes[soc_pm.data.suspend_mode].pattern);
1463 pr_info("AT91: PM not supported, due to no SRAM allocated\n");
1467 void __init at91rm9200_pm_init(void)
1471 if (!IS_ENABLED(CONFIG_SOC_AT91RM9200))
1475 * Force STANDBY and ULP0 mode to avoid calling
1476 * at91_pm_modes_validate() which may increase booting time.
1477 * Platform supports anyway only STANDBY and ULP0 modes.
1479 soc_pm.data.standby_mode = AT91_PM_STANDBY;
1480 soc_pm.data.suspend_mode = AT91_PM_ULP0;
1482 ret = at91_dt_ramc(false);
1487 * AT91RM9200 SDRAM low-power mode cannot be used with self-refresh.
1489 at91_ramc_write(0, AT91_MC_SDRAMC_LPR, 0);
1491 at91_pm_init(at91rm9200_idle);
1494 void __init sam9x60_pm_init(void)
1496 static const int modes[] __initconst = {
1497 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST, AT91_PM_ULP1,
1499 static const int iomaps[] __initconst = {
1500 [AT91_PM_ULP1] = AT91_PM_IOMAP(SHDWC),
1504 if (!IS_ENABLED(CONFIG_SOC_SAM9X60))
1507 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1508 at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
1509 ret = at91_dt_ramc(false);
1515 soc_pm.ws_ids = sam9x60_ws_ids;
1516 soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
1519 void __init sam9x7_pm_init(void)
1521 static const int modes[] __initconst = {
1522 AT91_PM_STANDBY, AT91_PM_ULP0,
1526 if (!IS_ENABLED(CONFIG_SOC_SAM9X7))
1529 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1530 ret = at91_dt_ramc(false);
1536 soc_pm.ws_ids = sam9x7_ws_ids;
1537 soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
1540 void __init at91sam9_pm_init(void)
1544 if (!IS_ENABLED(CONFIG_SOC_AT91SAM9))
1548 * Force STANDBY and ULP0 mode to avoid calling
1549 * at91_pm_modes_validate() which may increase booting time.
1550 * Platform supports anyway only STANDBY and ULP0 modes.
1552 soc_pm.data.standby_mode = AT91_PM_STANDBY;
1553 soc_pm.data.suspend_mode = AT91_PM_ULP0;
1555 ret = at91_dt_ramc(false);
1559 at91_pm_init(at91sam9_idle);
1562 void __init sama5_pm_init(void)
1564 static const int modes[] __initconst = {
1565 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST,
1567 static const u32 iomaps[] __initconst = {
1568 [AT91_PM_ULP0] = AT91_PM_IOMAP(ETHC),
1569 [AT91_PM_ULP0_FAST] = AT91_PM_IOMAP(ETHC),
1573 if (!IS_ENABLED(CONFIG_SOC_SAMA5))
1576 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1577 at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
1578 ret = at91_dt_ramc(false);
1584 /* Quirks applies to ULP0, ULP0 fast and ULP1 modes. */
1585 soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP0) |
1586 BIT(AT91_PM_ULP0_FAST) |
1588 /* Do not suspend in ULP0, ULP0 fast if GETH is the only wakeup source. */
1589 soc_pm.quirks.eth[AT91_PM_G_ETH].dns_modes = BIT(AT91_PM_ULP0) |
1590 BIT(AT91_PM_ULP0_FAST);
1593 void __init sama5d2_pm_init(void)
1595 static const int modes[] __initconst = {
1596 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST, AT91_PM_ULP1,
1599 static const u32 iomaps[] __initconst = {
1600 [AT91_PM_ULP0] = AT91_PM_IOMAP(ETHC),
1601 [AT91_PM_ULP0_FAST] = AT91_PM_IOMAP(ETHC),
1602 [AT91_PM_ULP1] = AT91_PM_IOMAP(SHDWC) |
1603 AT91_PM_IOMAP(ETHC),
1604 [AT91_PM_BACKUP] = AT91_PM_IOMAP(SHDWC) |
1605 AT91_PM_IOMAP(SFRBU),
1609 if (!IS_ENABLED(CONFIG_SOC_SAMA5D2))
1612 if (IS_ENABLED(CONFIG_ATMEL_SECURE_PM)) {
1613 pr_warn("AT91: Secure PM: ignoring standby mode\n");
1614 at91_pm_secure_init();
1618 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1619 at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
1620 ret = at91_dt_ramc(false);
1626 soc_pm.ws_ids = sama5d2_ws_ids;
1627 soc_pm.config_shdwc_ws = at91_sama5d2_config_shdwc_ws;
1628 soc_pm.config_pmc_ws = at91_sama5d2_config_pmc_ws;
1630 soc_pm.sfrbu_regs.pswbu.key = (0x4BD20C << 8);
1631 soc_pm.sfrbu_regs.pswbu.ctrl = BIT(0);
1632 soc_pm.sfrbu_regs.pswbu.softsw = BIT(1);
1633 soc_pm.sfrbu_regs.pswbu.state = BIT(3);
1635 /* Quirk applies to ULP0, ULP0 fast and ULP1 modes. */
1636 soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP0) |
1637 BIT(AT91_PM_ULP0_FAST) |
1640 * Do not suspend in ULP0, ULP0 fast if GETH is the only wakeup
1643 soc_pm.quirks.eth[AT91_PM_G_ETH].dns_modes = BIT(AT91_PM_ULP0) |
1644 BIT(AT91_PM_ULP0_FAST);
1647 void __init sama7_pm_init(void)
1649 static const int modes[] __initconst = {
1650 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP1, AT91_PM_BACKUP,
1652 static const u32 iomaps[] __initconst = {
1653 [AT91_PM_ULP0] = AT91_PM_IOMAP(SFRBU),
1654 [AT91_PM_ULP1] = AT91_PM_IOMAP(SFRBU) |
1655 AT91_PM_IOMAP(SHDWC) |
1656 AT91_PM_IOMAP(ETHC),
1657 [AT91_PM_BACKUP] = AT91_PM_IOMAP(SFRBU) |
1658 AT91_PM_IOMAP(SHDWC),
1662 if (!IS_ENABLED(CONFIG_SOC_SAMA7))
1665 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1667 ret = at91_dt_ramc(true);
1671 at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
1674 soc_pm.ws_ids = sama7g5_ws_ids;
1675 soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
1677 soc_pm.sfrbu_regs.pswbu.key = (0x4BD20C << 8);
1678 soc_pm.sfrbu_regs.pswbu.ctrl = BIT(0);
1679 soc_pm.sfrbu_regs.pswbu.softsw = BIT(1);
1680 soc_pm.sfrbu_regs.pswbu.state = BIT(2);
1682 /* Quirks applies to ULP1 for both Ethernet interfaces. */
1683 soc_pm.quirks.eth[AT91_PM_E_ETH].modes = BIT(AT91_PM_ULP1);
1684 soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP1);
1687 static int __init at91_pm_modes_select(char *str)
1690 substring_t args[MAX_OPT_ARGS];
1691 int standby, suspend;
1696 s = strsep(&str, ",");
1697 standby = match_token(s, pm_modes, args);
1701 suspend = match_token(str, pm_modes, args);
1705 soc_pm.data.standby_mode = standby;
1706 soc_pm.data.suspend_mode = suspend;
1710 early_param("atmel.pm_modes", at91_pm_modes_select);