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/parser.h>
16 #include <linux/suspend.h>
18 #include <linux/clk.h>
19 #include <linux/clk/at91_pmc.h>
20 #include <linux/platform_data/atmel.h>
22 #include <soc/at91/pm.h>
24 #include <asm/cacheflush.h>
25 #include <asm/fncpy.h>
26 #include <asm/system_misc.h>
27 #include <asm/suspend.h>
31 #include "sam_secure.h"
33 #define BACKUP_DDR_PHY_CALIBRATION (9)
36 * struct at91_pm_bu - AT91 power management backup unit data structure
37 * @suspended: true if suspended to backup mode
39 * @canary: canary data for memory checking after exit from backup mode
41 * @ddr_phy_calibration: DDR PHY calibration data: ZQ0CR0, first 8 words
46 unsigned long reserved;
49 unsigned long ddr_phy_calibration[BACKUP_DDR_PHY_CALIBRATION];
53 * struct at91_pm_sfrbu_regs - registers mapping for SFRBU
54 * @pswbu: power switch BU control registers
56 struct at91_pm_sfrbu_regs {
66 * enum at91_pm_eth_clk - Ethernet clock indexes
67 * @AT91_PM_ETH_PCLK: pclk index
68 * @AT91_PM_ETH_HCLK: hclk index
69 * @AT91_PM_ETH_MAX_CLK: max index
71 enum at91_pm_eth_clk {
78 * enum at91_pm_eth - Ethernet controller indexes
79 * @AT91_PM_G_ETH: gigabit Ethernet controller index
80 * @AT91_PM_E_ETH: megabit Ethernet controller index
81 * @AT91_PM_MAX_ETH: max index
90 * struct at91_pm_quirk_eth - AT91 PM Ethernet quirks
91 * @dev: Ethernet device
92 * @np: Ethernet device node
93 * @clks: Ethernet clocks
94 * @modes: power management mode that this quirk applies to
95 * @dns_modes: do not suspend modes: stop suspending if Ethernet is configured
96 * as wakeup source but buggy and no other wakeup source is
99 struct at91_pm_quirk_eth {
101 struct device_node *np;
102 struct clk_bulk_data clks[AT91_PM_ETH_MAX_CLK];
108 * struct at91_pm_quirks - AT91 PM quirks
109 * @eth: Ethernet quirks
111 struct at91_pm_quirks {
112 struct at91_pm_quirk_eth eth[AT91_PM_MAX_ETH];
116 * struct at91_soc_pm - AT91 SoC power management data structure
117 * @config_shdwc_ws: wakeup sources configuration function for SHDWC
118 * @config_pmc_ws: wakeup srouces configuration function for PMC
119 * @ws_ids: wakup sources of_device_id array
120 * @bu: backup unit mapped data (for backup mode)
122 * @data: PM data to be used on last phase of suspend
123 * @sfrbu_regs: SFRBU registers mapping
124 * @memcs: memory chip select
127 int (*config_shdwc_ws)(void __iomem *shdwc, u32 *mode, u32 *polarity);
128 int (*config_pmc_ws)(void __iomem *pmc, u32 mode, u32 polarity);
129 const struct of_device_id *ws_ids;
130 struct at91_pm_bu *bu;
131 struct at91_pm_quirks quirks;
132 struct at91_pm_data data;
133 struct at91_pm_sfrbu_regs sfrbu_regs;
138 * enum at91_pm_iomaps - IOs that needs to be mapped for different PM modes
139 * @AT91_PM_IOMAP_SHDWC: SHDWC controller
140 * @AT91_PM_IOMAP_SFRBU: SFRBU controller
141 * @AT91_PM_IOMAP_ETHC: Ethernet controller
143 enum at91_pm_iomaps {
149 #define AT91_PM_IOMAP(name) BIT(AT91_PM_IOMAP_##name)
151 static struct at91_soc_pm soc_pm = {
153 .standby_mode = AT91_PM_STANDBY,
154 .suspend_mode = AT91_PM_ULP0,
158 static const match_table_t pm_modes __initconst = {
159 { AT91_PM_STANDBY, "standby" },
160 { AT91_PM_ULP0, "ulp0" },
161 { AT91_PM_ULP0_FAST, "ulp0-fast" },
162 { AT91_PM_ULP1, "ulp1" },
163 { AT91_PM_BACKUP, "backup" },
167 #define at91_ramc_read(id, field) \
168 __raw_readl(soc_pm.data.ramc[id] + field)
170 #define at91_ramc_write(id, field, value) \
171 __raw_writel(value, soc_pm.data.ramc[id] + field)
173 static int at91_pm_valid_state(suspend_state_t state)
177 case PM_SUSPEND_STANDBY:
186 static int canary = 0xA5A5A5A5;
188 struct wakeup_source_info {
189 unsigned int pmc_fsmr_bit;
190 unsigned int shdwc_mr_bit;
194 static const struct wakeup_source_info ws_info[] = {
195 { .pmc_fsmr_bit = AT91_PMC_FSTT(10), .set_polarity = true },
196 { .pmc_fsmr_bit = AT91_PMC_RTCAL, .shdwc_mr_bit = BIT(17) },
197 { .pmc_fsmr_bit = AT91_PMC_USBAL },
198 { .pmc_fsmr_bit = AT91_PMC_SDMMC_CD },
199 { .pmc_fsmr_bit = AT91_PMC_RTTAL },
200 { .pmc_fsmr_bit = AT91_PMC_RXLP_MCE },
203 static const struct of_device_id sama5d2_ws_ids[] = {
204 { .compatible = "atmel,sama5d2-gem", .data = &ws_info[0] },
205 { .compatible = "atmel,sama5d2-rtc", .data = &ws_info[1] },
206 { .compatible = "atmel,sama5d3-udc", .data = &ws_info[2] },
207 { .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] },
208 { .compatible = "usb-ohci", .data = &ws_info[2] },
209 { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
210 { .compatible = "usb-ehci", .data = &ws_info[2] },
211 { .compatible = "atmel,sama5d2-sdhci", .data = &ws_info[3] },
215 static const struct of_device_id sam9x60_ws_ids[] = {
216 { .compatible = "microchip,sam9x60-rtc", .data = &ws_info[1] },
217 { .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] },
218 { .compatible = "usb-ohci", .data = &ws_info[2] },
219 { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
220 { .compatible = "usb-ehci", .data = &ws_info[2] },
221 { .compatible = "microchip,sam9x60-rtt", .data = &ws_info[4] },
222 { .compatible = "cdns,sam9x60-macb", .data = &ws_info[5] },
226 static const struct of_device_id sama7g5_ws_ids[] = {
227 { .compatible = "microchip,sama7g5-rtc", .data = &ws_info[1] },
228 { .compatible = "microchip,sama7g5-ohci", .data = &ws_info[2] },
229 { .compatible = "usb-ohci", .data = &ws_info[2] },
230 { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
231 { .compatible = "usb-ehci", .data = &ws_info[2] },
232 { .compatible = "microchip,sama7g5-sdhci", .data = &ws_info[3] },
233 { .compatible = "microchip,sama7g5-rtt", .data = &ws_info[4] },
237 static int at91_pm_config_ws(unsigned int pm_mode, bool set)
239 const struct wakeup_source_info *wsi;
240 const struct of_device_id *match;
241 struct platform_device *pdev;
242 struct device_node *np;
243 unsigned int mode = 0, polarity = 0, val = 0;
245 if (pm_mode != AT91_PM_ULP1)
248 if (!soc_pm.data.pmc || !soc_pm.data.shdwc || !soc_pm.ws_ids)
252 writel(mode, soc_pm.data.pmc + AT91_PMC_FSMR);
256 if (soc_pm.config_shdwc_ws)
257 soc_pm.config_shdwc_ws(soc_pm.data.shdwc, &mode, &polarity);
260 val = readl(soc_pm.data.shdwc + 0x04);
262 /* Loop through defined wakeup sources. */
263 for_each_matching_node_and_match(np, soc_pm.ws_ids, &match) {
264 pdev = of_find_device_by_node(np);
268 if (device_may_wakeup(&pdev->dev)) {
271 /* Check if enabled on SHDWC. */
272 if (wsi->shdwc_mr_bit && !(val & wsi->shdwc_mr_bit))
275 mode |= wsi->pmc_fsmr_bit;
276 if (wsi->set_polarity)
277 polarity |= wsi->pmc_fsmr_bit;
281 put_device(&pdev->dev);
285 if (soc_pm.config_pmc_ws)
286 soc_pm.config_pmc_ws(soc_pm.data.pmc, mode, polarity);
288 pr_err("AT91: PM: no ULP1 wakeup sources found!");
291 return mode ? 0 : -EPERM;
294 static int at91_sama5d2_config_shdwc_ws(void __iomem *shdwc, u32 *mode,
300 val = readl(shdwc + 0x0c);
301 *mode |= (val & 0x3ff);
302 *polarity |= ((val >> 16) & 0x3ff);
307 static int at91_sama5d2_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity)
309 writel(mode, pmc + AT91_PMC_FSMR);
310 writel(polarity, pmc + AT91_PMC_FSPR);
315 static int at91_sam9x60_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity)
317 writel(mode, pmc + AT91_PMC_FSMR);
322 static bool at91_pm_eth_quirk_is_valid(struct at91_pm_quirk_eth *eth)
324 struct platform_device *pdev;
326 /* Interface NA in DT. */
330 /* No quirks for this interface and current suspend mode. */
331 if (!(eth->modes & BIT(soc_pm.data.mode)))
335 /* Driver not probed. */
336 pdev = of_find_device_by_node(eth->np);
339 eth->dev = &pdev->dev;
342 /* No quirks if device isn't a wakeup source. */
343 if (!device_may_wakeup(eth->dev)) {
344 put_device(eth->dev);
348 /* put_device(eth->dev) is called at the end of suspend. */
352 static int at91_pm_config_quirks(bool suspend)
354 struct at91_pm_quirk_eth *eth;
358 * Ethernet IPs who's device_node pointers are stored into
359 * soc_pm.quirks.eth[].np cannot handle WoL packets while in ULP0, ULP1
360 * or both due to a hardware bug. If they receive WoL packets while in
361 * ULP0 or ULP1 IPs could stop working or the whole system could stop
362 * working. We cannot handle this scenario in the ethernet driver itself
363 * as the driver is common to multiple vendors and also we only know
364 * here, in this file, if we suspend to ULP0 or ULP1 mode. Thus handle
365 * these scenarios here, as quirks.
367 for (i = 0; i < AT91_PM_MAX_ETH; i++) {
368 eth = &soc_pm.quirks.eth[i];
370 if (!at91_pm_eth_quirk_is_valid(eth))
374 * For modes in dns_modes mask the system blocks if quirk is not
375 * applied but if applied the interface doesn't act at WoL
376 * events. Thus take care to avoid suspending if this interface
377 * is the only configured wakeup source.
379 if (suspend && eth->dns_modes & BIT(soc_pm.data.mode)) {
381 #ifdef CONFIG_PM_SLEEP
382 struct wakeup_source *ws;
384 for_each_wakeup_source(ws) {
385 if (ws->dev == eth->dev)
394 * Checking !ws is good for all platforms with issues
395 * even when both G_ETH and E_ETH are available as dns_modes
396 * is populated only on G_ETH interface.
399 pr_err("AT91: PM: Ethernet cannot resume from WoL!");
401 put_device(eth->dev);
403 /* No need to revert clock settings for this eth. */
405 goto clk_unconfigure;
410 clk_bulk_disable_unprepare(AT91_PM_ETH_MAX_CLK, eth->clks);
412 ret = clk_bulk_prepare_enable(AT91_PM_ETH_MAX_CLK,
415 goto clk_unconfigure;
417 * Release the reference to eth->dev taken in
418 * at91_pm_eth_quirk_is_valid().
420 put_device(eth->dev);
429 * In case of resume we reach this point if clk_prepare_enable() failed.
430 * we don't want to revert the previous clk_prepare_enable() for the
433 for (j = i; j >= 0; j--) {
434 eth = &soc_pm.quirks.eth[j];
436 if (!at91_pm_eth_quirk_is_valid(eth))
439 tmp = clk_bulk_prepare_enable(AT91_PM_ETH_MAX_CLK, eth->clks);
441 pr_err("AT91: PM: failed to enable %s clocks\n",
442 j == AT91_PM_G_ETH ? "geth" : "eth");
446 * Release the reference to eth->dev taken in
447 * at91_pm_eth_quirk_is_valid().
449 put_device(eth->dev);
458 * Called after processes are frozen, but before we shutdown devices.
460 static int at91_pm_begin(suspend_state_t state)
466 soc_pm.data.mode = soc_pm.data.suspend_mode;
469 case PM_SUSPEND_STANDBY:
470 soc_pm.data.mode = soc_pm.data.standby_mode;
474 soc_pm.data.mode = -1;
477 ret = at91_pm_config_ws(soc_pm.data.mode, true);
481 if (soc_pm.data.mode == AT91_PM_BACKUP)
482 soc_pm.bu->suspended = 1;
484 soc_pm.bu->suspended = 0;
490 * Verify that all the clocks are correct before entering
493 static int at91_pm_verify_clocks(void)
498 scsr = readl(soc_pm.data.pmc + AT91_PMC_SCSR);
500 /* USB must not be using PLLB */
501 if ((scsr & soc_pm.data.uhp_udp_mask) != 0) {
502 pr_err("AT91: PM - Suspend-to-RAM with USB still active\n");
506 /* PCK0..PCK3 must be disabled, or configured to use clk32k */
507 for (i = 0; i < 4; i++) {
510 if ((scsr & (AT91_PMC_PCK0 << i)) == 0)
512 css = readl(soc_pm.data.pmc + AT91_PMC_PCKR(i)) & AT91_PMC_CSS;
513 if (css != AT91_PMC_CSS_SLOW) {
514 pr_err("AT91: PM - Suspend-to-RAM with PCK%d src %d\n", i, css);
523 * Call this from platform driver suspend() to see how deeply to suspend.
524 * For example, some controllers (like OHCI) need one of the PLL clocks
525 * in order to act as a wakeup source, and those are not available when
526 * going into slow clock mode.
528 * REVISIT: generalize as clk_will_be_available(clk)? Other platforms have
529 * the very same problem (but not using at91 main_clk), and it'd be better
530 * to add one generic API rather than lots of platform-specific ones.
532 int at91_suspend_entering_slow_clock(void)
534 return (soc_pm.data.mode >= AT91_PM_ULP0);
536 EXPORT_SYMBOL(at91_suspend_entering_slow_clock);
538 static void (*at91_suspend_sram_fn)(struct at91_pm_data *);
539 extern void at91_pm_suspend_in_sram(struct at91_pm_data *pm_data);
540 extern u32 at91_pm_suspend_in_sram_sz;
542 static int at91_suspend_finish(unsigned long val)
546 if (soc_pm.data.mode == AT91_PM_BACKUP && soc_pm.data.ramc_phy) {
548 * The 1st 8 words of memory might get corrupted in the process
549 * of DDR PHY recalibration; it is saved here in securam and it
550 * will be restored later, after recalibration, by bootloader
552 for (i = 1; i < BACKUP_DDR_PHY_CALIBRATION; i++)
553 soc_pm.bu->ddr_phy_calibration[i] =
554 *((unsigned int *)soc_pm.memcs + (i - 1));
560 at91_suspend_sram_fn(&soc_pm.data);
565 static void at91_pm_switch_ba_to_vbat(void)
567 unsigned int offset = offsetof(struct at91_pm_sfrbu_regs, pswbu);
570 /* Just for safety. */
571 if (!soc_pm.data.sfrbu)
574 val = readl(soc_pm.data.sfrbu + offset);
576 /* Already on VBAT. */
577 if (!(val & soc_pm.sfrbu_regs.pswbu.state))
580 val &= ~soc_pm.sfrbu_regs.pswbu.softsw;
581 val |= soc_pm.sfrbu_regs.pswbu.key | soc_pm.sfrbu_regs.pswbu.ctrl;
582 writel(val, soc_pm.data.sfrbu + offset);
584 /* Wait for update. */
585 val = readl(soc_pm.data.sfrbu + offset);
586 while (val & soc_pm.sfrbu_regs.pswbu.state)
587 val = readl(soc_pm.data.sfrbu + offset);
590 static void at91_pm_suspend(suspend_state_t state)
592 if (soc_pm.data.mode == AT91_PM_BACKUP) {
593 at91_pm_switch_ba_to_vbat();
595 cpu_suspend(0, at91_suspend_finish);
597 /* The SRAM is lost between suspend cycles */
598 at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn,
599 &at91_pm_suspend_in_sram,
600 at91_pm_suspend_in_sram_sz);
602 at91_suspend_finish(0);
609 * STANDBY mode has *all* drivers suspended; ignores irqs not marked as 'wakeup'
610 * event sources; and reduces DRAM power. But otherwise it's identical to
611 * PM_SUSPEND_ON: cpu idle, and nothing fancy done with main or cpu clocks.
613 * AT91_PM_ULP0 is like STANDBY plus slow clock mode, so drivers must
614 * suspend more deeply, the master clock switches to the clk32k and turns off
615 * the main oscillator
617 * AT91_PM_BACKUP turns off the whole SoC after placing the DDR in self refresh
619 static int at91_pm_enter(suspend_state_t state)
623 ret = at91_pm_config_quirks(true);
627 #ifdef CONFIG_PINCTRL_AT91
629 * FIXME: this is needed to communicate between the pinctrl driver and
630 * the PM implementation in the machine. Possibly part of the PM
631 * implementation should be moved down into the pinctrl driver and get
632 * called as part of the generic suspend/resume path.
634 at91_pinctrl_gpio_suspend();
639 case PM_SUSPEND_STANDBY:
641 * Ensure that clocks are in a valid state.
643 if (soc_pm.data.mode >= AT91_PM_ULP0 &&
644 !at91_pm_verify_clocks())
647 at91_pm_suspend(state);
656 pr_debug("AT91: PM - bogus suspend state %d\n", state);
661 #ifdef CONFIG_PINCTRL_AT91
662 at91_pinctrl_gpio_resume();
664 at91_pm_config_quirks(false);
669 * Called right prior to thawing processes.
671 static void at91_pm_end(void)
673 at91_pm_config_ws(soc_pm.data.mode, false);
677 static const struct platform_suspend_ops at91_pm_ops = {
678 .valid = at91_pm_valid_state,
679 .begin = at91_pm_begin,
680 .enter = at91_pm_enter,
684 static struct platform_device at91_cpuidle_device = {
685 .name = "cpuidle-at91",
689 * The AT91RM9200 goes into self-refresh mode with this command, and will
690 * terminate self-refresh automatically on the next SDRAM access.
692 * Self-refresh mode is exited as soon as a memory access is made, but we don't
693 * know for sure when that happens. However, we need to restore the low-power
694 * mode if it was enabled before going idle. Restoring low-power mode while
695 * still in self-refresh is "not recommended", but seems to work.
697 static void at91rm9200_standby(void)
702 "1: mcr p15, 0, %0, c7, c10, 4\n\t"
703 " str %2, [%1, %3]\n\t"
704 " mcr p15, 0, %0, c7, c0, 4\n\t"
706 : "r" (0), "r" (soc_pm.data.ramc[0]),
707 "r" (1), "r" (AT91_MC_SDRAMC_SRR));
710 /* We manage both DDRAM/SDRAM controllers, we need more than one value to
713 static void at91_ddr_standby(void)
715 /* Those two values allow us to delay self-refresh activation
718 u32 mdr, saved_mdr0, saved_mdr1 = 0;
719 u32 saved_lpr0, saved_lpr1 = 0;
721 /* LPDDR1 --> force DDR2 mode during self-refresh */
722 saved_mdr0 = at91_ramc_read(0, AT91_DDRSDRC_MDR);
723 if ((saved_mdr0 & AT91_DDRSDRC_MD) == AT91_DDRSDRC_MD_LOW_POWER_DDR) {
724 mdr = saved_mdr0 & ~AT91_DDRSDRC_MD;
725 mdr |= AT91_DDRSDRC_MD_DDR2;
726 at91_ramc_write(0, AT91_DDRSDRC_MDR, mdr);
729 if (soc_pm.data.ramc[1]) {
730 saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR);
731 lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB;
732 lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
733 saved_mdr1 = at91_ramc_read(1, AT91_DDRSDRC_MDR);
734 if ((saved_mdr1 & AT91_DDRSDRC_MD) == AT91_DDRSDRC_MD_LOW_POWER_DDR) {
735 mdr = saved_mdr1 & ~AT91_DDRSDRC_MD;
736 mdr |= AT91_DDRSDRC_MD_DDR2;
737 at91_ramc_write(1, AT91_DDRSDRC_MDR, mdr);
741 saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
742 lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
743 lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
745 /* self-refresh mode now */
746 at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
747 if (soc_pm.data.ramc[1])
748 at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1);
752 at91_ramc_write(0, AT91_DDRSDRC_MDR, saved_mdr0);
753 at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
754 if (soc_pm.data.ramc[1]) {
755 at91_ramc_write(0, AT91_DDRSDRC_MDR, saved_mdr1);
756 at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1);
760 static void sama5d3_ddr_standby(void)
765 saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
766 lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
767 lpr0 |= AT91_DDRSDRC_LPCB_POWER_DOWN;
769 at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
773 at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
776 /* We manage both DDRAM/SDRAM controllers, we need more than one value to
779 static void at91sam9_sdram_standby(void)
782 u32 saved_lpr0, saved_lpr1 = 0;
784 if (soc_pm.data.ramc[1]) {
785 saved_lpr1 = at91_ramc_read(1, AT91_SDRAMC_LPR);
786 lpr1 = saved_lpr1 & ~AT91_SDRAMC_LPCB;
787 lpr1 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
790 saved_lpr0 = at91_ramc_read(0, AT91_SDRAMC_LPR);
791 lpr0 = saved_lpr0 & ~AT91_SDRAMC_LPCB;
792 lpr0 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
794 /* self-refresh mode now */
795 at91_ramc_write(0, AT91_SDRAMC_LPR, lpr0);
796 if (soc_pm.data.ramc[1])
797 at91_ramc_write(1, AT91_SDRAMC_LPR, lpr1);
801 at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr0);
802 if (soc_pm.data.ramc[1])
803 at91_ramc_write(1, AT91_SDRAMC_LPR, saved_lpr1);
806 static void sama7g5_standby(void)
810 pwrtmg = readl(soc_pm.data.ramc[0] + UDDRC_PWRCTL);
811 ratio = readl(soc_pm.data.pmc + AT91_PMC_RATIO);
814 * Place RAM into self-refresh after a maximum idle clocks. The maximum
815 * idle clocks is configured by bootloader in
816 * UDDRC_PWRMGT.SELFREF_TO_X32.
818 writel(pwrtmg | UDDRC_PWRCTL_SELFREF_EN,
819 soc_pm.data.ramc[0] + UDDRC_PWRCTL);
820 /* Divide CPU clock by 16. */
821 writel(ratio & ~AT91_PMC_RATIO_RATIO, soc_pm.data.pmc + AT91_PMC_RATIO);
825 /* Restore previous configuration. */
826 writel(ratio, soc_pm.data.pmc + AT91_PMC_RATIO);
827 writel(pwrtmg, soc_pm.data.ramc[0] + UDDRC_PWRCTL);
832 unsigned int memctrl;
835 static const struct ramc_info ramc_infos[] __initconst = {
836 { .idle = at91rm9200_standby, .memctrl = AT91_MEMCTRL_MC},
837 { .idle = at91sam9_sdram_standby, .memctrl = AT91_MEMCTRL_SDRAMC},
838 { .idle = at91_ddr_standby, .memctrl = AT91_MEMCTRL_DDRSDR},
839 { .idle = sama5d3_ddr_standby, .memctrl = AT91_MEMCTRL_DDRSDR},
840 { .idle = sama7g5_standby, },
843 static const struct of_device_id ramc_ids[] __initconst = {
844 { .compatible = "atmel,at91rm9200-sdramc", .data = &ramc_infos[0] },
845 { .compatible = "atmel,at91sam9260-sdramc", .data = &ramc_infos[1] },
846 { .compatible = "atmel,at91sam9g45-ddramc", .data = &ramc_infos[2] },
847 { .compatible = "atmel,sama5d3-ddramc", .data = &ramc_infos[3] },
848 { .compatible = "microchip,sama7g5-uddrc", .data = &ramc_infos[4], },
852 static const struct of_device_id ramc_phy_ids[] __initconst = {
853 { .compatible = "microchip,sama7g5-ddr3phy", },
857 static __init int at91_dt_ramc(bool phy_mandatory)
859 struct device_node *np;
860 const struct of_device_id *of_id;
862 void *standby = NULL;
863 const struct ramc_info *ramc;
866 for_each_matching_node_and_match(np, ramc_ids, &of_id) {
867 soc_pm.data.ramc[idx] = of_iomap(np, 0);
868 if (!soc_pm.data.ramc[idx]) {
869 pr_err("unable to map ramc[%d] cpu registers\n", idx);
878 standby = ramc->idle;
879 soc_pm.data.memctrl = ramc->memctrl;
886 pr_err("unable to find compatible ram controller node in dtb\n");
891 /* Lookup for DDR PHY node, if any. */
892 for_each_matching_node_and_match(np, ramc_phy_ids, &of_id) {
893 soc_pm.data.ramc_phy = of_iomap(np, 0);
894 if (!soc_pm.data.ramc_phy) {
895 pr_err("unable to map ramc phy cpu registers\n");
902 if (phy_mandatory && !soc_pm.data.ramc_phy) {
903 pr_err("DDR PHY is mandatory!\n");
909 pr_warn("ramc no standby function available\n");
913 at91_cpuidle_device.dev.platform_data = standby;
919 iounmap(soc_pm.data.ramc[--idx]);
924 static void at91rm9200_idle(void)
927 * Disable the processor clock. The processor will be automatically
928 * re-enabled by an interrupt or by a reset.
930 writel(AT91_PMC_PCK, soc_pm.data.pmc + AT91_PMC_SCDR);
933 static void at91sam9_idle(void)
935 writel(AT91_PMC_PCK, soc_pm.data.pmc + AT91_PMC_SCDR);
939 static void __init at91_pm_sram_init(void)
941 struct gen_pool *sram_pool;
942 phys_addr_t sram_pbase;
943 unsigned long sram_base;
944 struct device_node *node;
945 struct platform_device *pdev = NULL;
947 for_each_compatible_node(node, NULL, "mmio-sram") {
948 pdev = of_find_device_by_node(node);
956 pr_warn("%s: failed to find sram device!\n", __func__);
960 sram_pool = gen_pool_get(&pdev->dev, NULL);
962 pr_warn("%s: sram pool unavailable!\n", __func__);
966 sram_base = gen_pool_alloc(sram_pool, at91_pm_suspend_in_sram_sz);
968 pr_warn("%s: unable to alloc sram!\n", __func__);
972 sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
973 at91_suspend_sram_fn = __arm_ioremap_exec(sram_pbase,
974 at91_pm_suspend_in_sram_sz, false);
975 if (!at91_suspend_sram_fn) {
976 pr_warn("SRAM: Could not map\n");
980 /* Copy the pm suspend handler to SRAM */
981 at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn,
982 &at91_pm_suspend_in_sram, at91_pm_suspend_in_sram_sz);
986 put_device(&pdev->dev);
990 static bool __init at91_is_pm_mode_active(int pm_mode)
992 return (soc_pm.data.standby_mode == pm_mode ||
993 soc_pm.data.suspend_mode == pm_mode);
996 static int __init at91_pm_backup_scan_memcs(unsigned long node,
997 const char *uname, int depth,
1002 int *located = data;
1005 /* Memory node already located. */
1009 type = of_get_flat_dt_prop(node, "device_type", NULL);
1011 /* We are scanning "memory" nodes only. */
1012 if (!type || strcmp(type, "memory"))
1015 reg = of_get_flat_dt_prop(node, "reg", &size);
1017 soc_pm.memcs = __va((phys_addr_t)be32_to_cpu(*reg));
1024 static int __init at91_pm_backup_init(void)
1026 struct gen_pool *sram_pool;
1027 struct device_node *np;
1028 struct platform_device *pdev;
1029 int ret = -ENODEV, located = 0;
1031 if (!IS_ENABLED(CONFIG_SOC_SAMA5D2) &&
1032 !IS_ENABLED(CONFIG_SOC_SAMA7G5))
1035 if (!at91_is_pm_mode_active(AT91_PM_BACKUP))
1038 np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
1042 pdev = of_find_device_by_node(np);
1045 pr_warn("%s: failed to find securam device!\n", __func__);
1049 sram_pool = gen_pool_get(&pdev->dev, NULL);
1051 pr_warn("%s: securam pool unavailable!\n", __func__);
1055 soc_pm.bu = (void *)gen_pool_alloc(sram_pool, sizeof(struct at91_pm_bu));
1057 pr_warn("%s: unable to alloc securam!\n", __func__);
1062 soc_pm.bu->suspended = 0;
1063 soc_pm.bu->canary = __pa_symbol(&canary);
1064 soc_pm.bu->resume = __pa_symbol(cpu_resume);
1065 if (soc_pm.data.ramc_phy) {
1066 of_scan_flat_dt(at91_pm_backup_scan_memcs, &located);
1070 /* DDR3PHY_ZQ0SR0 */
1071 soc_pm.bu->ddr_phy_calibration[0] = readl(soc_pm.data.ramc_phy +
1078 put_device(&pdev->dev);
1082 static void __init at91_pm_secure_init(void)
1085 struct arm_smccc_res res;
1087 suspend_mode = soc_pm.data.suspend_mode;
1089 res = sam_smccc_call(SAMA5_SMC_SIP_SET_SUSPEND_MODE,
1092 pr_info("AT91: Secure PM: suspend mode set to %s\n",
1093 pm_modes[suspend_mode].pattern);
1097 pr_warn("AT91: Secure PM: %s mode not supported !\n",
1098 pm_modes[suspend_mode].pattern);
1100 res = sam_smccc_call(SAMA5_SMC_SIP_GET_SUSPEND_MODE, 0, 0);
1102 pr_warn("AT91: Secure PM: failed to get default mode\n");
1106 pr_info("AT91: Secure PM: using default suspend mode %s\n",
1107 pm_modes[suspend_mode].pattern);
1109 soc_pm.data.suspend_mode = res.a1;
1111 static const struct of_device_id atmel_shdwc_ids[] = {
1112 { .compatible = "atmel,sama5d2-shdwc" },
1113 { .compatible = "microchip,sam9x60-shdwc" },
1114 { .compatible = "microchip,sama7g5-shdwc" },
1118 static const struct of_device_id gmac_ids[] __initconst = {
1119 { .compatible = "atmel,sama5d3-gem" },
1120 { .compatible = "atmel,sama5d2-gem" },
1121 { .compatible = "atmel,sama5d29-gem" },
1122 { .compatible = "microchip,sama7g5-gem" },
1126 static const struct of_device_id emac_ids[] __initconst = {
1127 { .compatible = "atmel,sama5d3-macb" },
1128 { .compatible = "microchip,sama7g5-emac" },
1133 * Replaces _mode_to_replace with a supported mode that doesn't depend
1134 * on controller pointed by _map_bitmask
1135 * @_maps: u32 array containing AT91_PM_IOMAP() flags and indexed by AT91
1137 * @_map_bitmask: AT91_PM_IOMAP() bitmask; if _mode_to_replace depends on
1138 * controller represented by _map_bitmask, _mode_to_replace needs to be
1140 * @_mode_to_replace: standby_mode or suspend_mode that need to be
1142 * @_mode_to_check: standby_mode or suspend_mode; this is needed here
1143 * to avoid having standby_mode and suspend_mode set with the same AT91
1146 #define AT91_PM_REPLACE_MODE(_maps, _map_bitmask, _mode_to_replace, \
1149 if (((_maps)[(_mode_to_replace)]) & (_map_bitmask)) { \
1150 int _mode_to_use, _mode_complementary; \
1151 /* Use ULP0 if it doesn't need _map_bitmask. */ \
1152 if (!((_maps)[AT91_PM_ULP0] & (_map_bitmask))) {\
1153 _mode_to_use = AT91_PM_ULP0; \
1154 _mode_complementary = AT91_PM_STANDBY; \
1156 _mode_to_use = AT91_PM_STANDBY; \
1157 _mode_complementary = AT91_PM_STANDBY; \
1160 if ((_mode_to_check) != _mode_to_use) \
1161 (_mode_to_replace) = _mode_to_use; \
1163 (_mode_to_replace) = _mode_complementary;\
1168 * Replaces standby and suspend modes with default supported modes:
1170 * @_maps: u32 array indexed by AT91 PM mode containing AT91_PM_IOMAP()
1172 * @_map: controller specific name; standby and suspend mode need to be
1173 * replaced in order to not depend on this controller
1175 #define AT91_PM_REPLACE_MODES(_maps, _map) \
1177 AT91_PM_REPLACE_MODE((_maps), BIT(AT91_PM_IOMAP_##_map),\
1178 (soc_pm.data.standby_mode), \
1179 (soc_pm.data.suspend_mode)); \
1180 AT91_PM_REPLACE_MODE((_maps), BIT(AT91_PM_IOMAP_##_map),\
1181 (soc_pm.data.suspend_mode), \
1182 (soc_pm.data.standby_mode)); \
1185 static int __init at91_pm_get_eth_clks(struct device_node *np,
1186 struct clk_bulk_data *clks)
1188 clks[AT91_PM_ETH_PCLK].clk = of_clk_get_by_name(np, "pclk");
1189 if (IS_ERR(clks[AT91_PM_ETH_PCLK].clk))
1190 return PTR_ERR(clks[AT91_PM_ETH_PCLK].clk);
1192 clks[AT91_PM_ETH_HCLK].clk = of_clk_get_by_name(np, "hclk");
1193 if (IS_ERR(clks[AT91_PM_ETH_HCLK].clk))
1194 return PTR_ERR(clks[AT91_PM_ETH_HCLK].clk);
1199 static int __init at91_pm_eth_clks_empty(struct clk_bulk_data *clks)
1201 return IS_ERR(clks[AT91_PM_ETH_PCLK].clk) ||
1202 IS_ERR(clks[AT91_PM_ETH_HCLK].clk);
1205 static void __init at91_pm_modes_init(const u32 *maps, int len)
1207 struct at91_pm_quirk_eth *gmac = &soc_pm.quirks.eth[AT91_PM_G_ETH];
1208 struct at91_pm_quirk_eth *emac = &soc_pm.quirks.eth[AT91_PM_E_ETH];
1209 struct device_node *np;
1212 ret = at91_pm_backup_init();
1214 if (soc_pm.data.standby_mode == AT91_PM_BACKUP)
1215 soc_pm.data.standby_mode = AT91_PM_ULP0;
1216 if (soc_pm.data.suspend_mode == AT91_PM_BACKUP)
1217 soc_pm.data.suspend_mode = AT91_PM_ULP0;
1220 if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC) ||
1221 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC)) {
1222 np = of_find_matching_node(NULL, atmel_shdwc_ids);
1224 pr_warn("%s: failed to find shdwc!\n", __func__);
1225 AT91_PM_REPLACE_MODES(maps, SHDWC);
1227 soc_pm.data.shdwc = of_iomap(np, 0);
1232 if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU) ||
1233 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU)) {
1234 np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-sfrbu");
1236 pr_warn("%s: failed to find sfrbu!\n", __func__);
1237 AT91_PM_REPLACE_MODES(maps, SFRBU);
1239 soc_pm.data.sfrbu = of_iomap(np, 0);
1244 if ((at91_is_pm_mode_active(AT91_PM_ULP1) ||
1245 at91_is_pm_mode_active(AT91_PM_ULP0) ||
1246 at91_is_pm_mode_active(AT91_PM_ULP0_FAST)) &&
1247 (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(ETHC) ||
1248 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(ETHC))) {
1249 np = of_find_matching_node(NULL, gmac_ids);
1251 np = of_find_matching_node(NULL, emac_ids);
1254 AT91_PM_REPLACE_MODES(maps, ETHC);
1255 goto unmap_unused_nodes;
1258 at91_pm_get_eth_clks(np, gmac->clks);
1261 np = of_find_matching_node(NULL, emac_ids);
1263 if (at91_pm_eth_clks_empty(gmac->clks))
1264 AT91_PM_REPLACE_MODES(maps, ETHC);
1268 ret = at91_pm_get_eth_clks(np, emac->clks);
1269 if (ret && at91_pm_eth_clks_empty(gmac->clks)) {
1270 of_node_put(gmac->np);
1271 of_node_put(emac->np);
1279 /* Unmap all unnecessary. */
1280 if (soc_pm.data.shdwc &&
1281 !(maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC) ||
1282 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC))) {
1283 iounmap(soc_pm.data.shdwc);
1284 soc_pm.data.shdwc = NULL;
1287 if (soc_pm.data.sfrbu &&
1288 !(maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU) ||
1289 maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU))) {
1290 iounmap(soc_pm.data.sfrbu);
1291 soc_pm.data.sfrbu = NULL;
1298 unsigned long uhp_udp_mask;
1300 unsigned long version;
1303 static const struct pmc_info pmc_infos[] __initconst = {
1305 .uhp_udp_mask = AT91RM9200_PMC_UHP | AT91RM9200_PMC_UDP,
1307 .version = AT91_PMC_V1,
1311 .uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP,
1313 .version = AT91_PMC_V1,
1316 .uhp_udp_mask = AT91SAM926x_PMC_UHP,
1318 .version = AT91_PMC_V1,
1320 { .uhp_udp_mask = 0,
1322 .version = AT91_PMC_V1,
1325 .uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP,
1327 .version = AT91_PMC_V2,
1331 .version = AT91_PMC_V2,
1336 static const struct of_device_id atmel_pmc_ids[] __initconst = {
1337 { .compatible = "atmel,at91rm9200-pmc", .data = &pmc_infos[0] },
1338 { .compatible = "atmel,at91sam9260-pmc", .data = &pmc_infos[1] },
1339 { .compatible = "atmel,at91sam9261-pmc", .data = &pmc_infos[1] },
1340 { .compatible = "atmel,at91sam9263-pmc", .data = &pmc_infos[1] },
1341 { .compatible = "atmel,at91sam9g45-pmc", .data = &pmc_infos[2] },
1342 { .compatible = "atmel,at91sam9n12-pmc", .data = &pmc_infos[1] },
1343 { .compatible = "atmel,at91sam9rl-pmc", .data = &pmc_infos[3] },
1344 { .compatible = "atmel,at91sam9x5-pmc", .data = &pmc_infos[1] },
1345 { .compatible = "atmel,sama5d3-pmc", .data = &pmc_infos[1] },
1346 { .compatible = "atmel,sama5d4-pmc", .data = &pmc_infos[1] },
1347 { .compatible = "atmel,sama5d2-pmc", .data = &pmc_infos[1] },
1348 { .compatible = "microchip,sam9x60-pmc", .data = &pmc_infos[4] },
1349 { .compatible = "microchip,sama7g5-pmc", .data = &pmc_infos[5] },
1353 static void __init at91_pm_modes_validate(const int *modes, int len)
1355 u8 i, standby = 0, suspend = 0;
1358 for (i = 0; i < len; i++) {
1359 if (standby && suspend)
1362 if (modes[i] == soc_pm.data.standby_mode && !standby) {
1367 if (modes[i] == soc_pm.data.suspend_mode && !suspend) {
1374 if (soc_pm.data.suspend_mode == AT91_PM_STANDBY)
1375 mode = AT91_PM_ULP0;
1377 mode = AT91_PM_STANDBY;
1379 pr_warn("AT91: PM: %s mode not supported! Using %s.\n",
1380 pm_modes[soc_pm.data.standby_mode].pattern,
1381 pm_modes[mode].pattern);
1382 soc_pm.data.standby_mode = mode;
1386 if (soc_pm.data.standby_mode == AT91_PM_ULP0)
1387 mode = AT91_PM_STANDBY;
1389 mode = AT91_PM_ULP0;
1391 pr_warn("AT91: PM: %s mode not supported! Using %s.\n",
1392 pm_modes[soc_pm.data.suspend_mode].pattern,
1393 pm_modes[mode].pattern);
1394 soc_pm.data.suspend_mode = mode;
1398 static void __init at91_pm_init(void (*pm_idle)(void))
1400 struct device_node *pmc_np;
1401 const struct of_device_id *of_id;
1402 const struct pmc_info *pmc;
1404 if (at91_cpuidle_device.dev.platform_data)
1405 platform_device_register(&at91_cpuidle_device);
1407 pmc_np = of_find_matching_node_and_match(NULL, atmel_pmc_ids, &of_id);
1408 soc_pm.data.pmc = of_iomap(pmc_np, 0);
1409 of_node_put(pmc_np);
1410 if (!soc_pm.data.pmc) {
1411 pr_err("AT91: PM not supported, PMC not found\n");
1416 soc_pm.data.uhp_udp_mask = pmc->uhp_udp_mask;
1417 soc_pm.data.pmc_mckr_offset = pmc->mckr;
1418 soc_pm.data.pmc_version = pmc->version;
1421 arm_pm_idle = pm_idle;
1423 at91_pm_sram_init();
1425 if (at91_suspend_sram_fn) {
1426 suspend_set_ops(&at91_pm_ops);
1427 pr_info("AT91: PM: standby: %s, suspend: %s\n",
1428 pm_modes[soc_pm.data.standby_mode].pattern,
1429 pm_modes[soc_pm.data.suspend_mode].pattern);
1431 pr_info("AT91: PM not supported, due to no SRAM allocated\n");
1435 void __init at91rm9200_pm_init(void)
1439 if (!IS_ENABLED(CONFIG_SOC_AT91RM9200))
1443 * Force STANDBY and ULP0 mode to avoid calling
1444 * at91_pm_modes_validate() which may increase booting time.
1445 * Platform supports anyway only STANDBY and ULP0 modes.
1447 soc_pm.data.standby_mode = AT91_PM_STANDBY;
1448 soc_pm.data.suspend_mode = AT91_PM_ULP0;
1450 ret = at91_dt_ramc(false);
1455 * AT91RM9200 SDRAM low-power mode cannot be used with self-refresh.
1457 at91_ramc_write(0, AT91_MC_SDRAMC_LPR, 0);
1459 at91_pm_init(at91rm9200_idle);
1462 void __init sam9x60_pm_init(void)
1464 static const int modes[] __initconst = {
1465 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST, AT91_PM_ULP1,
1467 static const int iomaps[] __initconst = {
1468 [AT91_PM_ULP1] = AT91_PM_IOMAP(SHDWC),
1472 if (!IS_ENABLED(CONFIG_SOC_SAM9X60))
1475 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1476 at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
1477 ret = at91_dt_ramc(false);
1483 soc_pm.ws_ids = sam9x60_ws_ids;
1484 soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
1487 void __init at91sam9_pm_init(void)
1491 if (!IS_ENABLED(CONFIG_SOC_AT91SAM9))
1495 * Force STANDBY and ULP0 mode to avoid calling
1496 * at91_pm_modes_validate() which may increase booting time.
1497 * Platform supports anyway only STANDBY and ULP0 modes.
1499 soc_pm.data.standby_mode = AT91_PM_STANDBY;
1500 soc_pm.data.suspend_mode = AT91_PM_ULP0;
1502 ret = at91_dt_ramc(false);
1506 at91_pm_init(at91sam9_idle);
1509 void __init sama5_pm_init(void)
1511 static const int modes[] __initconst = {
1512 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST,
1514 static const u32 iomaps[] __initconst = {
1515 [AT91_PM_ULP0] = AT91_PM_IOMAP(ETHC),
1516 [AT91_PM_ULP0_FAST] = AT91_PM_IOMAP(ETHC),
1520 if (!IS_ENABLED(CONFIG_SOC_SAMA5))
1523 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1524 at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
1525 ret = at91_dt_ramc(false);
1531 /* Quirks applies to ULP0, ULP0 fast and ULP1 modes. */
1532 soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP0) |
1533 BIT(AT91_PM_ULP0_FAST) |
1535 /* Do not suspend in ULP0, ULP0 fast if GETH is the only wakeup source. */
1536 soc_pm.quirks.eth[AT91_PM_G_ETH].dns_modes = BIT(AT91_PM_ULP0) |
1537 BIT(AT91_PM_ULP0_FAST);
1540 void __init sama5d2_pm_init(void)
1542 static const int modes[] __initconst = {
1543 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST, AT91_PM_ULP1,
1546 static const u32 iomaps[] __initconst = {
1547 [AT91_PM_ULP0] = AT91_PM_IOMAP(ETHC),
1548 [AT91_PM_ULP0_FAST] = AT91_PM_IOMAP(ETHC),
1549 [AT91_PM_ULP1] = AT91_PM_IOMAP(SHDWC) |
1550 AT91_PM_IOMAP(ETHC),
1551 [AT91_PM_BACKUP] = AT91_PM_IOMAP(SHDWC) |
1552 AT91_PM_IOMAP(SFRBU),
1556 if (!IS_ENABLED(CONFIG_SOC_SAMA5D2))
1559 if (IS_ENABLED(CONFIG_ATMEL_SECURE_PM)) {
1560 pr_warn("AT91: Secure PM: ignoring standby mode\n");
1561 at91_pm_secure_init();
1565 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1566 at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
1567 ret = at91_dt_ramc(false);
1573 soc_pm.ws_ids = sama5d2_ws_ids;
1574 soc_pm.config_shdwc_ws = at91_sama5d2_config_shdwc_ws;
1575 soc_pm.config_pmc_ws = at91_sama5d2_config_pmc_ws;
1577 soc_pm.sfrbu_regs.pswbu.key = (0x4BD20C << 8);
1578 soc_pm.sfrbu_regs.pswbu.ctrl = BIT(0);
1579 soc_pm.sfrbu_regs.pswbu.softsw = BIT(1);
1580 soc_pm.sfrbu_regs.pswbu.state = BIT(3);
1582 /* Quirk applies to ULP0, ULP0 fast and ULP1 modes. */
1583 soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP0) |
1584 BIT(AT91_PM_ULP0_FAST) |
1587 * Do not suspend in ULP0, ULP0 fast if GETH is the only wakeup
1590 soc_pm.quirks.eth[AT91_PM_G_ETH].dns_modes = BIT(AT91_PM_ULP0) |
1591 BIT(AT91_PM_ULP0_FAST);
1594 void __init sama7_pm_init(void)
1596 static const int modes[] __initconst = {
1597 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP1, AT91_PM_BACKUP,
1599 static const u32 iomaps[] __initconst = {
1600 [AT91_PM_ULP0] = AT91_PM_IOMAP(SFRBU),
1601 [AT91_PM_ULP1] = AT91_PM_IOMAP(SFRBU) |
1602 AT91_PM_IOMAP(SHDWC) |
1603 AT91_PM_IOMAP(ETHC),
1604 [AT91_PM_BACKUP] = AT91_PM_IOMAP(SFRBU) |
1605 AT91_PM_IOMAP(SHDWC),
1609 if (!IS_ENABLED(CONFIG_SOC_SAMA7))
1612 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
1614 ret = at91_dt_ramc(true);
1618 at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
1621 soc_pm.ws_ids = sama7g5_ws_ids;
1622 soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
1624 soc_pm.sfrbu_regs.pswbu.key = (0x4BD20C << 8);
1625 soc_pm.sfrbu_regs.pswbu.ctrl = BIT(0);
1626 soc_pm.sfrbu_regs.pswbu.softsw = BIT(1);
1627 soc_pm.sfrbu_regs.pswbu.state = BIT(2);
1629 /* Quirks applies to ULP1 for both Ethernet interfaces. */
1630 soc_pm.quirks.eth[AT91_PM_E_ETH].modes = BIT(AT91_PM_ULP1);
1631 soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP1);
1634 static int __init at91_pm_modes_select(char *str)
1637 substring_t args[MAX_OPT_ARGS];
1638 int standby, suspend;
1643 s = strsep(&str, ",");
1644 standby = match_token(s, pm_modes, args);
1648 suspend = match_token(str, pm_modes, args);
1652 soc_pm.data.standby_mode = standby;
1653 soc_pm.data.suspend_mode = suspend;
1657 early_param("atmel.pm_modes", at91_pm_modes_select);