Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 2 | /* |
Andrew Victor | 9d04126 | 2007-02-05 11:42:07 +0100 | [diff] [blame] | 3 | * arch/arm/mach-at91/pm.c |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 4 | * AT91 Power Management |
| 5 | * |
| 6 | * Copyright (C) 2005 David Brownell |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 9 | #include <linux/genalloc.h> |
Alexandre Belloni | 9824c44 | 2017-01-31 13:49:24 +0100 | [diff] [blame] | 10 | #include <linux/io.h> |
| 11 | #include <linux/of_address.h> |
Alexandre Belloni | f5598d3 | 2015-01-15 15:59:24 +0100 | [diff] [blame] | 12 | #include <linux/of.h> |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 13 | #include <linux/of_platform.h> |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 14 | #include <linux/parser.h> |
Alexandre Belloni | 9824c44 | 2017-01-31 13:49:24 +0100 | [diff] [blame] | 15 | #include <linux/suspend.h> |
| 16 | |
Boris BREZILLON | 2edb90a | 2013-10-11 09:37:45 +0200 | [diff] [blame] | 17 | #include <linux/clk/at91_pmc.h> |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 18 | |
Wenyou Yang | 385acc0 | 2015-03-09 11:54:26 +0800 | [diff] [blame] | 19 | #include <asm/cacheflush.h> |
Alexandre Belloni | 9824c44 | 2017-01-31 13:49:24 +0100 | [diff] [blame] | 20 | #include <asm/fncpy.h> |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 21 | #include <asm/system_misc.h> |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 22 | #include <asm/suspend.h> |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 23 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 24 | #include "generic.h" |
Albin Tonnerre | 1ea60cf | 2009-11-01 18:40:50 +0100 | [diff] [blame] | 25 | #include "pm.h" |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 26 | |
Alexandre Belloni | 23b8408 | 2015-03-13 22:57:23 +0100 | [diff] [blame] | 27 | /* |
| 28 | * FIXME: this is needed to communicate between the pinctrl driver and |
| 29 | * the PM implementation in the machine. Possibly part of the PM |
| 30 | * implementation should be moved down into the pinctrl driver and get |
| 31 | * called as part of the generic suspend/resume path. |
| 32 | */ |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 33 | #ifdef CONFIG_PINCTRL_AT91 |
Alexandre Belloni | 23b8408 | 2015-03-13 22:57:23 +0100 | [diff] [blame] | 34 | extern void at91_pinctrl_gpio_suspend(void); |
| 35 | extern void at91_pinctrl_gpio_resume(void); |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 36 | #endif |
Alexandre Belloni | 23b8408 | 2015-03-13 22:57:23 +0100 | [diff] [blame] | 37 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 38 | struct at91_soc_pm { |
Claudiu Beznea | a958156 | 2019-02-14 15:54:51 +0000 | [diff] [blame] | 39 | int (*config_shdwc_ws)(void __iomem *shdwc, u32 *mode, u32 *polarity); |
| 40 | int (*config_pmc_ws)(void __iomem *pmc, u32 mode, u32 polarity); |
| 41 | const struct of_device_id *ws_ids; |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 42 | struct at91_pm_data data; |
| 43 | }; |
| 44 | |
| 45 | static struct at91_soc_pm soc_pm = { |
| 46 | .data = { |
| 47 | .standby_mode = AT91_PM_STANDBY, |
| 48 | .suspend_mode = AT91_PM_ULP0, |
| 49 | }, |
| 50 | }; |
| 51 | |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 52 | static const match_table_t pm_modes __initconst = { |
Claudiu Beznea | 514e2a2 | 2018-07-17 11:26:54 +0300 | [diff] [blame] | 53 | { AT91_PM_STANDBY, "standby" }, |
| 54 | { AT91_PM_ULP0, "ulp0" }, |
Wenyou Yang | 5b56c18 | 2018-07-17 11:26:55 +0300 | [diff] [blame] | 55 | { AT91_PM_ULP1, "ulp1" }, |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 56 | { AT91_PM_BACKUP, "backup" }, |
| 57 | { -1, NULL }, |
| 58 | }; |
| 59 | |
Alexandre Belloni | 4d767bc | 2017-01-31 14:08:47 +0100 | [diff] [blame] | 60 | #define at91_ramc_read(id, field) \ |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 61 | __raw_readl(soc_pm.data.ramc[id] + field) |
Alexandre Belloni | 4d767bc | 2017-01-31 14:08:47 +0100 | [diff] [blame] | 62 | |
| 63 | #define at91_ramc_write(id, field, value) \ |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 64 | __raw_writel(value, soc_pm.data.ramc[id] + field) |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 65 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 66 | static int at91_pm_valid_state(suspend_state_t state) |
| 67 | { |
| 68 | switch (state) { |
| 69 | case PM_SUSPEND_ON: |
| 70 | case PM_SUSPEND_STANDBY: |
| 71 | case PM_SUSPEND_MEM: |
| 72 | return 1; |
| 73 | |
| 74 | default: |
| 75 | return 0; |
| 76 | } |
| 77 | } |
| 78 | |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 79 | static int canary = 0xA5A5A5A5; |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 80 | |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 81 | static struct at91_pm_bu { |
| 82 | int suspended; |
| 83 | unsigned long reserved; |
| 84 | phys_addr_t canary; |
| 85 | phys_addr_t resume; |
| 86 | } *pm_bu; |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 87 | |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 88 | struct wakeup_source_info { |
| 89 | unsigned int pmc_fsmr_bit; |
| 90 | unsigned int shdwc_mr_bit; |
| 91 | bool set_polarity; |
| 92 | }; |
| 93 | |
| 94 | static const struct wakeup_source_info ws_info[] = { |
| 95 | { .pmc_fsmr_bit = AT91_PMC_FSTT(10), .set_polarity = true }, |
| 96 | { .pmc_fsmr_bit = AT91_PMC_RTCAL, .shdwc_mr_bit = BIT(17) }, |
| 97 | { .pmc_fsmr_bit = AT91_PMC_USBAL }, |
| 98 | { .pmc_fsmr_bit = AT91_PMC_SDMMC_CD }, |
Claudiu Beznea | eaedc0d | 2019-02-14 15:54:57 +0000 | [diff] [blame] | 99 | { .pmc_fsmr_bit = AT91_PMC_RTTAL }, |
| 100 | { .pmc_fsmr_bit = AT91_PMC_RXLP_MCE }, |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | static const struct of_device_id sama5d2_ws_ids[] = { |
| 104 | { .compatible = "atmel,sama5d2-gem", .data = &ws_info[0] }, |
| 105 | { .compatible = "atmel,at91rm9200-rtc", .data = &ws_info[1] }, |
| 106 | { .compatible = "atmel,sama5d3-udc", .data = &ws_info[2] }, |
| 107 | { .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] }, |
| 108 | { .compatible = "usb-ohci", .data = &ws_info[2] }, |
| 109 | { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] }, |
| 110 | { .compatible = "usb-ehci", .data = &ws_info[2] }, |
| 111 | { .compatible = "atmel,sama5d2-sdhci", .data = &ws_info[3] }, |
| 112 | { /* sentinel */ } |
| 113 | }; |
| 114 | |
Claudiu Beznea | eaedc0d | 2019-02-14 15:54:57 +0000 | [diff] [blame] | 115 | static const struct of_device_id sam9x60_ws_ids[] = { |
| 116 | { .compatible = "atmel,at91sam9x5-rtc", .data = &ws_info[1] }, |
| 117 | { .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] }, |
| 118 | { .compatible = "usb-ohci", .data = &ws_info[2] }, |
| 119 | { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] }, |
| 120 | { .compatible = "usb-ehci", .data = &ws_info[2] }, |
| 121 | { .compatible = "atmel,at91sam9260-rtt", .data = &ws_info[4] }, |
| 122 | { .compatible = "cdns,sam9x60-macb", .data = &ws_info[5] }, |
| 123 | { /* sentinel */ } |
| 124 | }; |
| 125 | |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 126 | static int at91_pm_config_ws(unsigned int pm_mode, bool set) |
| 127 | { |
| 128 | const struct wakeup_source_info *wsi; |
| 129 | const struct of_device_id *match; |
| 130 | struct platform_device *pdev; |
| 131 | struct device_node *np; |
| 132 | unsigned int mode = 0, polarity = 0, val = 0; |
| 133 | |
| 134 | if (pm_mode != AT91_PM_ULP1) |
| 135 | return 0; |
| 136 | |
Claudiu Beznea | a958156 | 2019-02-14 15:54:51 +0000 | [diff] [blame] | 137 | if (!soc_pm.data.pmc || !soc_pm.data.shdwc || !soc_pm.ws_ids) |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 138 | return -EPERM; |
| 139 | |
| 140 | if (!set) { |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 141 | writel(mode, soc_pm.data.pmc + AT91_PMC_FSMR); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
Claudiu Beznea | a958156 | 2019-02-14 15:54:51 +0000 | [diff] [blame] | 145 | if (soc_pm.config_shdwc_ws) |
| 146 | soc_pm.config_shdwc_ws(soc_pm.data.shdwc, &mode, &polarity); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 147 | |
| 148 | /* SHDWC.MR */ |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 149 | val = readl(soc_pm.data.shdwc + 0x04); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 150 | |
| 151 | /* Loop through defined wakeup sources. */ |
Claudiu Beznea | a958156 | 2019-02-14 15:54:51 +0000 | [diff] [blame] | 152 | for_each_matching_node_and_match(np, soc_pm.ws_ids, &match) { |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 153 | pdev = of_find_device_by_node(np); |
| 154 | if (!pdev) |
| 155 | continue; |
| 156 | |
| 157 | if (device_may_wakeup(&pdev->dev)) { |
| 158 | wsi = match->data; |
| 159 | |
| 160 | /* Check if enabled on SHDWC. */ |
| 161 | if (wsi->shdwc_mr_bit && !(val & wsi->shdwc_mr_bit)) |
zhong jiang | 95590a6 | 2018-08-16 18:26:22 +0800 | [diff] [blame] | 162 | goto put_device; |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 163 | |
| 164 | mode |= wsi->pmc_fsmr_bit; |
| 165 | if (wsi->set_polarity) |
| 166 | polarity |= wsi->pmc_fsmr_bit; |
| 167 | } |
| 168 | |
zhong jiang | 95590a6 | 2018-08-16 18:26:22 +0800 | [diff] [blame] | 169 | put_device: |
| 170 | put_device(&pdev->dev); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | if (mode) { |
Claudiu Beznea | a958156 | 2019-02-14 15:54:51 +0000 | [diff] [blame] | 174 | if (soc_pm.config_pmc_ws) |
| 175 | soc_pm.config_pmc_ws(soc_pm.data.pmc, mode, polarity); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 176 | } else { |
| 177 | pr_err("AT91: PM: no ULP1 wakeup sources found!"); |
| 178 | } |
| 179 | |
| 180 | return mode ? 0 : -EPERM; |
| 181 | } |
| 182 | |
Claudiu Beznea | a958156 | 2019-02-14 15:54:51 +0000 | [diff] [blame] | 183 | static int at91_sama5d2_config_shdwc_ws(void __iomem *shdwc, u32 *mode, |
| 184 | u32 *polarity) |
| 185 | { |
| 186 | u32 val; |
| 187 | |
| 188 | /* SHDWC.WUIR */ |
| 189 | val = readl(shdwc + 0x0c); |
| 190 | *mode |= (val & 0x3ff); |
| 191 | *polarity |= ((val >> 16) & 0x3ff); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static int at91_sama5d2_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity) |
| 197 | { |
| 198 | writel(mode, pmc + AT91_PMC_FSMR); |
| 199 | writel(polarity, pmc + AT91_PMC_FSPR); |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
Claudiu Beznea | eaedc0d | 2019-02-14 15:54:57 +0000 | [diff] [blame] | 204 | static int at91_sam9x60_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity) |
| 205 | { |
| 206 | writel(mode, pmc + AT91_PMC_FSMR); |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 211 | /* |
| 212 | * Called after processes are frozen, but before we shutdown devices. |
| 213 | */ |
Rafael J. Wysocki | c697eec | 2008-01-08 00:04:17 +0100 | [diff] [blame] | 214 | static int at91_pm_begin(suspend_state_t state) |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 215 | { |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 216 | switch (state) { |
| 217 | case PM_SUSPEND_MEM: |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 218 | soc_pm.data.mode = soc_pm.data.suspend_mode; |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 219 | break; |
| 220 | |
| 221 | case PM_SUSPEND_STANDBY: |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 222 | soc_pm.data.mode = soc_pm.data.standby_mode; |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 223 | break; |
| 224 | |
| 225 | default: |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 226 | soc_pm.data.mode = -1; |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 229 | return at91_pm_config_ws(soc_pm.data.mode, true); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Verify that all the clocks are correct before entering |
| 234 | * slow-clock mode. |
| 235 | */ |
| 236 | static int at91_pm_verify_clocks(void) |
| 237 | { |
| 238 | unsigned long scsr; |
| 239 | int i; |
| 240 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 241 | scsr = readl(soc_pm.data.pmc + AT91_PMC_SCSR); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 242 | |
| 243 | /* USB must not be using PLLB */ |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 244 | if ((scsr & soc_pm.data.uhp_udp_mask) != 0) { |
Alexandre Belloni | f5598d3 | 2015-01-15 15:59:24 +0100 | [diff] [blame] | 245 | pr_err("AT91: PM - Suspend-to-RAM with USB still active\n"); |
| 246 | return 0; |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 249 | /* PCK0..PCK3 must be disabled, or configured to use clk32k */ |
| 250 | for (i = 0; i < 4; i++) { |
| 251 | u32 css; |
| 252 | |
| 253 | if ((scsr & (AT91_PMC_PCK0 << i)) == 0) |
| 254 | continue; |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 255 | css = readl(soc_pm.data.pmc + AT91_PMC_PCKR(i)) & AT91_PMC_CSS; |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 256 | if (css != AT91_PMC_CSS_SLOW) { |
Ryan Mallon | 7f96b1c | 2009-04-01 20:33:30 +0100 | [diff] [blame] | 257 | pr_err("AT91: PM - Suspend-to-RAM with PCK%d src %d\n", i, css); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | } |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 261 | |
| 262 | return 1; |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * Call this from platform driver suspend() to see how deeply to suspend. |
| 267 | * For example, some controllers (like OHCI) need one of the PLL clocks |
| 268 | * in order to act as a wakeup source, and those are not available when |
| 269 | * going into slow clock mode. |
| 270 | * |
| 271 | * REVISIT: generalize as clk_will_be_available(clk)? Other platforms have |
| 272 | * the very same problem (but not using at91 main_clk), and it'd be better |
| 273 | * to add one generic API rather than lots of platform-specific ones. |
| 274 | */ |
| 275 | int at91_suspend_entering_slow_clock(void) |
| 276 | { |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 277 | return (soc_pm.data.mode >= AT91_PM_ULP0); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 278 | } |
| 279 | EXPORT_SYMBOL(at91_suspend_entering_slow_clock); |
| 280 | |
Alexandre Belloni | 65cc1a5 | 2017-01-31 18:12:57 +0100 | [diff] [blame] | 281 | static void (*at91_suspend_sram_fn)(struct at91_pm_data *); |
| 282 | extern void at91_pm_suspend_in_sram(struct at91_pm_data *pm_data); |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 283 | extern u32 at91_pm_suspend_in_sram_sz; |
Andrew Victor | f5d0f45 | 2008-04-02 21:50:16 +0100 | [diff] [blame] | 284 | |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 285 | static int at91_suspend_finish(unsigned long val) |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 286 | { |
Wenyou Yang | 385acc0 | 2015-03-09 11:54:26 +0800 | [diff] [blame] | 287 | flush_cache_all(); |
| 288 | outer_disable(); |
| 289 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 290 | at91_suspend_sram_fn(&soc_pm.data); |
Wenyou Yang | 385acc0 | 2015-03-09 11:54:26 +0800 | [diff] [blame] | 291 | |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | static void at91_pm_suspend(suspend_state_t state) |
| 296 | { |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 297 | if (soc_pm.data.mode == AT91_PM_BACKUP) { |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 298 | pm_bu->suspended = 1; |
| 299 | |
| 300 | cpu_suspend(0, at91_suspend_finish); |
| 301 | |
| 302 | /* The SRAM is lost between suspend cycles */ |
| 303 | at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn, |
| 304 | &at91_pm_suspend_in_sram, |
| 305 | at91_pm_suspend_in_sram_sz); |
| 306 | } else { |
| 307 | at91_suspend_finish(0); |
| 308 | } |
| 309 | |
Wenyou Yang | 385acc0 | 2015-03-09 11:54:26 +0800 | [diff] [blame] | 310 | outer_resume(); |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 311 | } |
| 312 | |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 313 | /* |
| 314 | * STANDBY mode has *all* drivers suspended; ignores irqs not marked as 'wakeup' |
| 315 | * event sources; and reduces DRAM power. But otherwise it's identical to |
| 316 | * PM_SUSPEND_ON: cpu idle, and nothing fancy done with main or cpu clocks. |
| 317 | * |
Claudiu Beznea | 514e2a2 | 2018-07-17 11:26:54 +0300 | [diff] [blame] | 318 | * AT91_PM_ULP0 is like STANDBY plus slow clock mode, so drivers must |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 319 | * suspend more deeply, the master clock switches to the clk32k and turns off |
| 320 | * the main oscillator |
| 321 | * |
| 322 | * AT91_PM_BACKUP turns off the whole SoC after placing the DDR in self refresh |
| 323 | */ |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 324 | static int at91_pm_enter(suspend_state_t state) |
| 325 | { |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 326 | #ifdef CONFIG_PINCTRL_AT91 |
Arnd Bergmann | 85c4b31 | 2014-12-02 12:08:27 +0100 | [diff] [blame] | 327 | at91_pinctrl_gpio_suspend(); |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 328 | #endif |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 329 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 330 | switch (state) { |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 331 | case PM_SUSPEND_MEM: |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 332 | case PM_SUSPEND_STANDBY: |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 333 | /* |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 334 | * Ensure that clocks are in a valid state. |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 335 | */ |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 336 | if (soc_pm.data.mode >= AT91_PM_ULP0 && |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 337 | !at91_pm_verify_clocks()) |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 338 | goto error; |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 339 | |
| 340 | at91_pm_suspend(state); |
| 341 | |
| 342 | break; |
| 343 | |
Wenyou Yang | 23be4be | 2015-03-09 11:49:46 +0800 | [diff] [blame] | 344 | case PM_SUSPEND_ON: |
| 345 | cpu_do_idle(); |
| 346 | break; |
| 347 | |
| 348 | default: |
| 349 | pr_debug("AT91: PM - bogus suspend state %d\n", state); |
| 350 | goto error; |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 353 | error: |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 354 | #ifdef CONFIG_PINCTRL_AT91 |
Arnd Bergmann | 85c4b31 | 2014-12-02 12:08:27 +0100 | [diff] [blame] | 355 | at91_pinctrl_gpio_resume(); |
Ludovic Desroches | 8423536 | 2015-12-01 11:44:40 +0100 | [diff] [blame] | 356 | #endif |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | |
Rafael J. Wysocki | c697eec | 2008-01-08 00:04:17 +0100 | [diff] [blame] | 360 | /* |
| 361 | * Called right prior to thawing processes. |
| 362 | */ |
| 363 | static void at91_pm_end(void) |
| 364 | { |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 365 | at91_pm_config_ws(soc_pm.data.mode, false); |
Rafael J. Wysocki | c697eec | 2008-01-08 00:04:17 +0100 | [diff] [blame] | 366 | } |
| 367 | |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 368 | |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 369 | static const struct platform_suspend_ops at91_pm_ops = { |
Rafael J. Wysocki | c697eec | 2008-01-08 00:04:17 +0100 | [diff] [blame] | 370 | .valid = at91_pm_valid_state, |
| 371 | .begin = at91_pm_begin, |
| 372 | .enter = at91_pm_enter, |
| 373 | .end = at91_pm_end, |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 374 | }; |
| 375 | |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 376 | static struct platform_device at91_cpuidle_device = { |
| 377 | .name = "cpuidle-at91", |
| 378 | }; |
| 379 | |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 380 | /* |
| 381 | * The AT91RM9200 goes into self-refresh mode with this command, and will |
| 382 | * terminate self-refresh automatically on the next SDRAM access. |
| 383 | * |
| 384 | * Self-refresh mode is exited as soon as a memory access is made, but we don't |
| 385 | * know for sure when that happens. However, we need to restore the low-power |
| 386 | * mode if it was enabled before going idle. Restoring low-power mode while |
| 387 | * still in self-refresh is "not recommended", but seems to work. |
| 388 | */ |
| 389 | static void at91rm9200_standby(void) |
| 390 | { |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 391 | asm volatile( |
| 392 | "b 1f\n\t" |
| 393 | ".align 5\n\t" |
| 394 | "1: mcr p15, 0, %0, c7, c10, 4\n\t" |
Alexandre Belloni | 5a2d4f0 | 2017-02-01 21:32:43 +0100 | [diff] [blame] | 395 | " str %2, [%1, %3]\n\t" |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 396 | " mcr p15, 0, %0, c7, c0, 4\n\t" |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 397 | : |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 398 | : "r" (0), "r" (soc_pm.data.ramc[0]), |
Alexandre Belloni | 5a2d4f0 | 2017-02-01 21:32:43 +0100 | [diff] [blame] | 399 | "r" (1), "r" (AT91_MC_SDRAMC_SRR)); |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /* We manage both DDRAM/SDRAM controllers, we need more than one value to |
| 403 | * remember. |
| 404 | */ |
| 405 | static void at91_ddr_standby(void) |
| 406 | { |
| 407 | /* Those two values allow us to delay self-refresh activation |
| 408 | * to the maximum. */ |
| 409 | u32 lpr0, lpr1 = 0; |
Alexandre Belloni | 5638763 | 2017-02-01 22:10:34 +0100 | [diff] [blame] | 410 | u32 mdr, saved_mdr0, saved_mdr1 = 0; |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 411 | u32 saved_lpr0, saved_lpr1 = 0; |
| 412 | |
Alexandre Belloni | 5638763 | 2017-02-01 22:10:34 +0100 | [diff] [blame] | 413 | /* LPDDR1 --> force DDR2 mode during self-refresh */ |
| 414 | saved_mdr0 = at91_ramc_read(0, AT91_DDRSDRC_MDR); |
| 415 | if ((saved_mdr0 & AT91_DDRSDRC_MD) == AT91_DDRSDRC_MD_LOW_POWER_DDR) { |
| 416 | mdr = saved_mdr0 & ~AT91_DDRSDRC_MD; |
| 417 | mdr |= AT91_DDRSDRC_MD_DDR2; |
| 418 | at91_ramc_write(0, AT91_DDRSDRC_MDR, mdr); |
| 419 | } |
| 420 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 421 | if (soc_pm.data.ramc[1]) { |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 422 | saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR); |
| 423 | lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB; |
| 424 | lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH; |
Alexandre Belloni | 5638763 | 2017-02-01 22:10:34 +0100 | [diff] [blame] | 425 | saved_mdr1 = at91_ramc_read(1, AT91_DDRSDRC_MDR); |
| 426 | if ((saved_mdr1 & AT91_DDRSDRC_MD) == AT91_DDRSDRC_MD_LOW_POWER_DDR) { |
| 427 | mdr = saved_mdr1 & ~AT91_DDRSDRC_MD; |
| 428 | mdr |= AT91_DDRSDRC_MD_DDR2; |
| 429 | at91_ramc_write(1, AT91_DDRSDRC_MDR, mdr); |
| 430 | } |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR); |
| 434 | lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB; |
| 435 | lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH; |
| 436 | |
| 437 | /* self-refresh mode now */ |
| 438 | at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0); |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 439 | if (soc_pm.data.ramc[1]) |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 440 | at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1); |
| 441 | |
| 442 | cpu_do_idle(); |
| 443 | |
Alexandre Belloni | 5638763 | 2017-02-01 22:10:34 +0100 | [diff] [blame] | 444 | at91_ramc_write(0, AT91_DDRSDRC_MDR, saved_mdr0); |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 445 | at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0); |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 446 | if (soc_pm.data.ramc[1]) { |
Alexandre Belloni | 5638763 | 2017-02-01 22:10:34 +0100 | [diff] [blame] | 447 | at91_ramc_write(0, AT91_DDRSDRC_MDR, saved_mdr1); |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 448 | at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1); |
Alexandre Belloni | 5638763 | 2017-02-01 22:10:34 +0100 | [diff] [blame] | 449 | } |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Nicolas Ferre | 60b89f1 | 2017-03-14 09:38:04 +0100 | [diff] [blame] | 452 | static void sama5d3_ddr_standby(void) |
| 453 | { |
| 454 | u32 lpr0; |
| 455 | u32 saved_lpr0; |
| 456 | |
| 457 | saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR); |
| 458 | lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB; |
| 459 | lpr0 |= AT91_DDRSDRC_LPCB_POWER_DOWN; |
| 460 | |
| 461 | at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0); |
| 462 | |
| 463 | cpu_do_idle(); |
| 464 | |
| 465 | at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0); |
| 466 | } |
| 467 | |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 468 | /* We manage both DDRAM/SDRAM controllers, we need more than one value to |
| 469 | * remember. |
| 470 | */ |
| 471 | static void at91sam9_sdram_standby(void) |
| 472 | { |
| 473 | u32 lpr0, lpr1 = 0; |
| 474 | u32 saved_lpr0, saved_lpr1 = 0; |
| 475 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 476 | if (soc_pm.data.ramc[1]) { |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 477 | saved_lpr1 = at91_ramc_read(1, AT91_SDRAMC_LPR); |
| 478 | lpr1 = saved_lpr1 & ~AT91_SDRAMC_LPCB; |
| 479 | lpr1 |= AT91_SDRAMC_LPCB_SELF_REFRESH; |
| 480 | } |
| 481 | |
| 482 | saved_lpr0 = at91_ramc_read(0, AT91_SDRAMC_LPR); |
| 483 | lpr0 = saved_lpr0 & ~AT91_SDRAMC_LPCB; |
| 484 | lpr0 |= AT91_SDRAMC_LPCB_SELF_REFRESH; |
| 485 | |
| 486 | /* self-refresh mode now */ |
| 487 | at91_ramc_write(0, AT91_SDRAMC_LPR, lpr0); |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 488 | if (soc_pm.data.ramc[1]) |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 489 | at91_ramc_write(1, AT91_SDRAMC_LPR, lpr1); |
| 490 | |
| 491 | cpu_do_idle(); |
| 492 | |
| 493 | at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr0); |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 494 | if (soc_pm.data.ramc[1]) |
Alexandre Belloni | a18d069 | 2015-03-16 23:44:37 +0100 | [diff] [blame] | 495 | at91_ramc_write(1, AT91_SDRAMC_LPR, saved_lpr1); |
| 496 | } |
| 497 | |
Alexandre Belloni | aab02d6 | 2017-02-01 22:41:50 +0100 | [diff] [blame] | 498 | struct ramc_info { |
| 499 | void (*idle)(void); |
| 500 | unsigned int memctrl; |
| 501 | }; |
| 502 | |
| 503 | static const struct ramc_info ramc_infos[] __initconst = { |
| 504 | { .idle = at91rm9200_standby, .memctrl = AT91_MEMCTRL_MC}, |
| 505 | { .idle = at91sam9_sdram_standby, .memctrl = AT91_MEMCTRL_SDRAMC}, |
| 506 | { .idle = at91_ddr_standby, .memctrl = AT91_MEMCTRL_DDRSDR}, |
| 507 | { .idle = sama5d3_ddr_standby, .memctrl = AT91_MEMCTRL_DDRSDR}, |
| 508 | }; |
| 509 | |
Arnd Bergmann | 0527873 | 2017-05-11 13:50:16 +0200 | [diff] [blame] | 510 | static const struct of_device_id ramc_ids[] __initconst = { |
Alexandre Belloni | aab02d6 | 2017-02-01 22:41:50 +0100 | [diff] [blame] | 511 | { .compatible = "atmel,at91rm9200-sdramc", .data = &ramc_infos[0] }, |
| 512 | { .compatible = "atmel,at91sam9260-sdramc", .data = &ramc_infos[1] }, |
| 513 | { .compatible = "atmel,at91sam9g45-ddramc", .data = &ramc_infos[2] }, |
| 514 | { .compatible = "atmel,sama5d3-ddramc", .data = &ramc_infos[3] }, |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 515 | { /*sentinel*/ } |
| 516 | }; |
| 517 | |
Uwe Kleine-König | 444d2d3 | 2015-02-18 21:19:56 +0100 | [diff] [blame] | 518 | static __init void at91_dt_ramc(void) |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 519 | { |
| 520 | struct device_node *np; |
| 521 | const struct of_device_id *of_id; |
| 522 | int idx = 0; |
Alexandre Belloni | e56d75a | 2017-02-01 23:55:10 +0100 | [diff] [blame] | 523 | void *standby = NULL; |
Alexandre Belloni | aab02d6 | 2017-02-01 22:41:50 +0100 | [diff] [blame] | 524 | const struct ramc_info *ramc; |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 525 | |
| 526 | for_each_matching_node_and_match(np, ramc_ids, &of_id) { |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 527 | soc_pm.data.ramc[idx] = of_iomap(np, 0); |
| 528 | if (!soc_pm.data.ramc[idx]) |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 529 | panic(pr_fmt("unable to map ramc[%d] cpu registers\n"), idx); |
| 530 | |
Alexandre Belloni | aab02d6 | 2017-02-01 22:41:50 +0100 | [diff] [blame] | 531 | ramc = of_id->data; |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 532 | if (!standby) |
Alexandre Belloni | aab02d6 | 2017-02-01 22:41:50 +0100 | [diff] [blame] | 533 | standby = ramc->idle; |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 534 | soc_pm.data.memctrl = ramc->memctrl; |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 535 | |
| 536 | idx++; |
| 537 | } |
| 538 | |
| 539 | if (!idx) |
| 540 | panic(pr_fmt("unable to find compatible ram controller node in dtb\n")); |
| 541 | |
| 542 | if (!standby) { |
| 543 | pr_warn("ramc no standby function available\n"); |
| 544 | return; |
| 545 | } |
| 546 | |
Alexandre Belloni | e56d75a | 2017-02-01 23:55:10 +0100 | [diff] [blame] | 547 | at91_cpuidle_device.dev.platform_data = standby; |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 548 | } |
| 549 | |
Ben Dooks | ab6778e | 2016-06-17 16:34:18 +0100 | [diff] [blame] | 550 | static void at91rm9200_idle(void) |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 551 | { |
| 552 | /* |
| 553 | * Disable the processor clock. The processor will be automatically |
| 554 | * re-enabled by an interrupt or by a reset. |
| 555 | */ |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 556 | writel(AT91_PMC_PCK, soc_pm.data.pmc + AT91_PMC_SCDR); |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 557 | } |
| 558 | |
Claudiu Beznea | 01c7031 | 2019-02-14 15:54:41 +0000 | [diff] [blame] | 559 | static void at91sam9x60_idle(void) |
| 560 | { |
| 561 | cpu_do_idle(); |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 562 | } |
| 563 | |
Ben Dooks | ab6778e | 2016-06-17 16:34:18 +0100 | [diff] [blame] | 564 | static void at91sam9_idle(void) |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 565 | { |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 566 | writel(AT91_PMC_PCK, soc_pm.data.pmc + AT91_PMC_SCDR); |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 567 | cpu_do_idle(); |
| 568 | } |
| 569 | |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 570 | static void __init at91_pm_sram_init(void) |
| 571 | { |
| 572 | struct gen_pool *sram_pool; |
| 573 | phys_addr_t sram_pbase; |
| 574 | unsigned long sram_base; |
| 575 | struct device_node *node; |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 576 | struct platform_device *pdev = NULL; |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 577 | |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 578 | for_each_compatible_node(node, NULL, "mmio-sram") { |
| 579 | pdev = of_find_device_by_node(node); |
| 580 | if (pdev) { |
| 581 | of_node_put(node); |
| 582 | break; |
| 583 | } |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 584 | } |
| 585 | |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 586 | if (!pdev) { |
| 587 | pr_warn("%s: failed to find sram device!\n", __func__); |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 588 | return; |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 589 | } |
| 590 | |
Vladimir Zapolskiy | 7385817 | 2015-09-04 15:47:43 -0700 | [diff] [blame] | 591 | sram_pool = gen_pool_get(&pdev->dev, NULL); |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 592 | if (!sram_pool) { |
| 593 | pr_warn("%s: sram pool unavailable!\n", __func__); |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 594 | return; |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 595 | } |
| 596 | |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 597 | sram_base = gen_pool_alloc(sram_pool, at91_pm_suspend_in_sram_sz); |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 598 | if (!sram_base) { |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 599 | pr_warn("%s: unable to alloc sram!\n", __func__); |
Alexandre Belloni | 4a031f7 | 2015-03-03 08:38:07 +0100 | [diff] [blame] | 600 | return; |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base); |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 604 | at91_suspend_sram_fn = __arm_ioremap_exec(sram_pbase, |
| 605 | at91_pm_suspend_in_sram_sz, false); |
| 606 | if (!at91_suspend_sram_fn) { |
Wenyou Yang | d94e688 | 2015-03-09 11:49:01 +0800 | [diff] [blame] | 607 | pr_warn("SRAM: Could not map\n"); |
| 608 | return; |
| 609 | } |
| 610 | |
Wenyou Yang | 5726a8b | 2015-03-09 11:51:09 +0800 | [diff] [blame] | 611 | /* Copy the pm suspend handler to SRAM */ |
| 612 | at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn, |
| 613 | &at91_pm_suspend_in_sram, at91_pm_suspend_in_sram_sz); |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 614 | } |
Alexandre Belloni | d2e4679 | 2015-01-15 15:59:25 +0100 | [diff] [blame] | 615 | |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 616 | static bool __init at91_is_pm_mode_active(int pm_mode) |
| 617 | { |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 618 | return (soc_pm.data.standby_mode == pm_mode || |
| 619 | soc_pm.data.suspend_mode == pm_mode); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | static int __init at91_pm_backup_init(void) |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 623 | { |
| 624 | struct gen_pool *sram_pool; |
| 625 | struct device_node *np; |
| 626 | struct platform_device *pdev = NULL; |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 627 | int ret = -ENODEV; |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 628 | |
Claudiu Beznea | 2fa86e5 | 2019-02-14 15:54:47 +0000 | [diff] [blame] | 629 | if (!IS_ENABLED(CONFIG_SOC_SAMA5D2)) |
| 630 | return -EPERM; |
| 631 | |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 632 | if (!at91_is_pm_mode_active(AT91_PM_BACKUP)) |
| 633 | return 0; |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 634 | |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 635 | np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-sfrbu"); |
| 636 | if (!np) { |
| 637 | pr_warn("%s: failed to find sfrbu!\n", __func__); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 638 | return ret; |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 639 | } |
| 640 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 641 | soc_pm.data.sfrbu = of_iomap(np, 0); |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 642 | of_node_put(np); |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 643 | |
| 644 | np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam"); |
| 645 | if (!np) |
Peng Hao | ba5e60c | 2019-04-02 22:12:38 +0800 | [diff] [blame] | 646 | goto securam_fail_no_ref_dev; |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 647 | |
| 648 | pdev = of_find_device_by_node(np); |
| 649 | of_node_put(np); |
| 650 | if (!pdev) { |
| 651 | pr_warn("%s: failed to find securam device!\n", __func__); |
Peng Hao | ba5e60c | 2019-04-02 22:12:38 +0800 | [diff] [blame] | 652 | goto securam_fail_no_ref_dev; |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | sram_pool = gen_pool_get(&pdev->dev, NULL); |
| 656 | if (!sram_pool) { |
| 657 | pr_warn("%s: securam pool unavailable!\n", __func__); |
| 658 | goto securam_fail; |
| 659 | } |
| 660 | |
| 661 | pm_bu = (void *)gen_pool_alloc(sram_pool, sizeof(struct at91_pm_bu)); |
| 662 | if (!pm_bu) { |
| 663 | pr_warn("%s: unable to alloc securam!\n", __func__); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 664 | ret = -ENOMEM; |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 665 | goto securam_fail; |
| 666 | } |
| 667 | |
| 668 | pm_bu->suspended = 0; |
Alexandre Belloni | 093d79f | 2017-08-24 13:44:54 +0200 | [diff] [blame] | 669 | pm_bu->canary = __pa_symbol(&canary); |
| 670 | pm_bu->resume = __pa_symbol(cpu_resume); |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 671 | |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 672 | return 0; |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 673 | |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 674 | securam_fail: |
Peng Hao | ba5e60c | 2019-04-02 22:12:38 +0800 | [diff] [blame] | 675 | put_device(&pdev->dev); |
| 676 | securam_fail_no_ref_dev: |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 677 | iounmap(soc_pm.data.sfrbu); |
| 678 | soc_pm.data.sfrbu = NULL; |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 679 | return ret; |
| 680 | } |
Alexandre Belloni | 2873223 | 2017-04-26 16:34:24 +0200 | [diff] [blame] | 681 | |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 682 | static void __init at91_pm_use_default_mode(int pm_mode) |
| 683 | { |
| 684 | if (pm_mode != AT91_PM_ULP1 && pm_mode != AT91_PM_BACKUP) |
| 685 | return; |
| 686 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 687 | if (soc_pm.data.standby_mode == pm_mode) |
| 688 | soc_pm.data.standby_mode = AT91_PM_ULP0; |
| 689 | if (soc_pm.data.suspend_mode == pm_mode) |
| 690 | soc_pm.data.suspend_mode = AT91_PM_ULP0; |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 691 | } |
| 692 | |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 693 | static void __init at91_pm_modes_init(void) |
| 694 | { |
| 695 | struct device_node *np; |
| 696 | int ret; |
| 697 | |
| 698 | if (!at91_is_pm_mode_active(AT91_PM_BACKUP) && |
| 699 | !at91_is_pm_mode_active(AT91_PM_ULP1)) |
| 700 | return; |
| 701 | |
| 702 | np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-shdwc"); |
| 703 | if (!np) { |
| 704 | pr_warn("%s: failed to find shdwc!\n", __func__); |
| 705 | goto ulp1_default; |
| 706 | } |
| 707 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 708 | soc_pm.data.shdwc = of_iomap(np, 0); |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 709 | of_node_put(np); |
| 710 | |
| 711 | ret = at91_pm_backup_init(); |
| 712 | if (ret) { |
| 713 | if (!at91_is_pm_mode_active(AT91_PM_ULP1)) |
| 714 | goto unmap; |
| 715 | else |
| 716 | goto backup_default; |
| 717 | } |
| 718 | |
| 719 | return; |
| 720 | |
| 721 | unmap: |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 722 | iounmap(soc_pm.data.shdwc); |
| 723 | soc_pm.data.shdwc = NULL; |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 724 | ulp1_default: |
| 725 | at91_pm_use_default_mode(AT91_PM_ULP1); |
| 726 | backup_default: |
| 727 | at91_pm_use_default_mode(AT91_PM_BACKUP); |
| 728 | } |
| 729 | |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 730 | struct pmc_info { |
| 731 | unsigned long uhp_udp_mask; |
| 732 | }; |
| 733 | |
| 734 | static const struct pmc_info pmc_infos[] __initconst = { |
| 735 | { .uhp_udp_mask = AT91RM9200_PMC_UHP | AT91RM9200_PMC_UDP }, |
| 736 | { .uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP }, |
| 737 | { .uhp_udp_mask = AT91SAM926x_PMC_UHP }, |
Alexandre Belloni | 91f8718 | 2018-06-07 10:41:06 +0200 | [diff] [blame] | 738 | { .uhp_udp_mask = 0 }, |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 739 | }; |
| 740 | |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 741 | static const struct of_device_id atmel_pmc_ids[] __initconst = { |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 742 | { .compatible = "atmel,at91rm9200-pmc", .data = &pmc_infos[0] }, |
| 743 | { .compatible = "atmel,at91sam9260-pmc", .data = &pmc_infos[1] }, |
Alexandre Belloni | 91f8718 | 2018-06-07 10:41:06 +0200 | [diff] [blame] | 744 | { .compatible = "atmel,at91sam9261-pmc", .data = &pmc_infos[1] }, |
| 745 | { .compatible = "atmel,at91sam9263-pmc", .data = &pmc_infos[1] }, |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 746 | { .compatible = "atmel,at91sam9g45-pmc", .data = &pmc_infos[2] }, |
| 747 | { .compatible = "atmel,at91sam9n12-pmc", .data = &pmc_infos[1] }, |
Alexandre Belloni | 91f8718 | 2018-06-07 10:41:06 +0200 | [diff] [blame] | 748 | { .compatible = "atmel,at91sam9rl-pmc", .data = &pmc_infos[3] }, |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 749 | { .compatible = "atmel,at91sam9x5-pmc", .data = &pmc_infos[1] }, |
| 750 | { .compatible = "atmel,sama5d3-pmc", .data = &pmc_infos[1] }, |
Alexandre Belloni | 91f8718 | 2018-06-07 10:41:06 +0200 | [diff] [blame] | 751 | { .compatible = "atmel,sama5d4-pmc", .data = &pmc_infos[1] }, |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 752 | { .compatible = "atmel,sama5d2-pmc", .data = &pmc_infos[1] }, |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 753 | { /* sentinel */ }, |
| 754 | }; |
| 755 | |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 756 | static void __init at91_pm_init(void (*pm_idle)(void)) |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 757 | { |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 758 | struct device_node *pmc_np; |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 759 | const struct of_device_id *of_id; |
| 760 | const struct pmc_info *pmc; |
Andrew Victor | f5d0f45 | 2008-04-02 21:50:16 +0100 | [diff] [blame] | 761 | |
Daniel Lezcano | 5ad945e | 2013-09-22 22:29:57 +0200 | [diff] [blame] | 762 | if (at91_cpuidle_device.dev.platform_data) |
| 763 | platform_device_register(&at91_cpuidle_device); |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 764 | |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 765 | pmc_np = of_find_matching_node_and_match(NULL, atmel_pmc_ids, &of_id); |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 766 | soc_pm.data.pmc = of_iomap(pmc_np, 0); |
| 767 | if (!soc_pm.data.pmc) { |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 768 | pr_err("AT91: PM not supported, PMC not found\n"); |
| 769 | return; |
| 770 | } |
| 771 | |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 772 | pmc = of_id->data; |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 773 | soc_pm.data.uhp_udp_mask = pmc->uhp_udp_mask; |
Alexandre Belloni | 13f1601 | 2017-02-01 23:35:18 +0100 | [diff] [blame] | 774 | |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 775 | if (pm_idle) |
| 776 | arm_pm_idle = pm_idle; |
| 777 | |
Alexandre Belloni | 5737b73 | 2015-09-30 01:31:34 +0200 | [diff] [blame] | 778 | at91_pm_sram_init(); |
| 779 | |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 780 | if (at91_suspend_sram_fn) { |
Wenyou Yang | d94e688 | 2015-03-09 11:49:01 +0800 | [diff] [blame] | 781 | suspend_set_ops(&at91_pm_ops); |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 782 | pr_info("AT91: PM: standby: %s, suspend: %s\n", |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 783 | pm_modes[soc_pm.data.standby_mode].pattern, |
| 784 | pm_modes[soc_pm.data.suspend_mode].pattern); |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 785 | } else { |
Wenyou Yang | d94e688 | 2015-03-09 11:49:01 +0800 | [diff] [blame] | 786 | pr_info("AT91: PM not supported, due to no SRAM allocated\n"); |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 787 | } |
Andrew Victor | 907d6de | 2006-06-20 19:30:19 +0100 | [diff] [blame] | 788 | } |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 789 | |
Nicolas Ferre | ad3fc3e | 2015-01-27 18:41:33 +0100 | [diff] [blame] | 790 | void __init at91rm9200_pm_init(void) |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 791 | { |
Arnd Bergmann | dbeb0c8 | 2017-08-23 16:46:15 +0200 | [diff] [blame] | 792 | if (!IS_ENABLED(CONFIG_SOC_AT91RM9200)) |
| 793 | return; |
| 794 | |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 795 | at91_dt_ramc(); |
| 796 | |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 797 | /* |
| 798 | * AT91RM9200 SDRAM low-power mode cannot be used with self-refresh. |
| 799 | */ |
Alexandre Belloni | d7d45f2 | 2015-03-16 15:14:50 +0100 | [diff] [blame] | 800 | at91_ramc_write(0, AT91_MC_SDRAMC_LPR, 0); |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 801 | |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 802 | at91_pm_init(at91rm9200_idle); |
Alexandre Belloni | 4db0ba2 | 2015-01-15 15:59:27 +0100 | [diff] [blame] | 803 | } |
| 804 | |
Claudiu Beznea | 01c7031 | 2019-02-14 15:54:41 +0000 | [diff] [blame] | 805 | void __init sam9x60_pm_init(void) |
| 806 | { |
| 807 | if (!IS_ENABLED(CONFIG_SOC_AT91SAM9)) |
| 808 | return; |
| 809 | |
Claudiu Beznea | eaedc0d | 2019-02-14 15:54:57 +0000 | [diff] [blame] | 810 | at91_pm_modes_init(); |
Claudiu Beznea | 01c7031 | 2019-02-14 15:54:41 +0000 | [diff] [blame] | 811 | at91_dt_ramc(); |
| 812 | at91_pm_init(at91sam9x60_idle); |
Claudiu Beznea | eaedc0d | 2019-02-14 15:54:57 +0000 | [diff] [blame] | 813 | |
| 814 | soc_pm.ws_ids = sam9x60_ws_ids; |
| 815 | soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws; |
Claudiu Beznea | 01c7031 | 2019-02-14 15:54:41 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Alexandre Belloni | 1346919 | 2017-02-01 23:43:03 +0100 | [diff] [blame] | 818 | void __init at91sam9_pm_init(void) |
Nicolas Ferre | bf02280 | 2015-01-22 16:54:50 +0100 | [diff] [blame] | 819 | { |
Arnd Bergmann | dbeb0c8 | 2017-08-23 16:46:15 +0200 | [diff] [blame] | 820 | if (!IS_ENABLED(CONFIG_SOC_AT91SAM9)) |
| 821 | return; |
| 822 | |
Alexandre Belloni | 827de1f | 2015-01-27 17:38:46 +0100 | [diff] [blame] | 823 | at91_dt_ramc(); |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 824 | at91_pm_init(at91sam9_idle); |
| 825 | } |
| 826 | |
| 827 | void __init sama5_pm_init(void) |
| 828 | { |
Arnd Bergmann | dbeb0c8 | 2017-08-23 16:46:15 +0200 | [diff] [blame] | 829 | if (!IS_ENABLED(CONFIG_SOC_SAMA5)) |
| 830 | return; |
| 831 | |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 832 | at91_dt_ramc(); |
Alexandre Belloni | fbc7edc | 2015-09-30 01:58:40 +0200 | [diff] [blame] | 833 | at91_pm_init(NULL); |
Nicolas Ferre | bf02280 | 2015-01-22 16:54:50 +0100 | [diff] [blame] | 834 | } |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 835 | |
| 836 | void __init sama5d2_pm_init(void) |
| 837 | { |
Arnd Bergmann | dbeb0c8 | 2017-08-23 16:46:15 +0200 | [diff] [blame] | 838 | if (!IS_ENABLED(CONFIG_SOC_SAMA5D2)) |
| 839 | return; |
| 840 | |
Claudiu Beznea | d7484f5 | 2018-07-17 14:06:24 +0300 | [diff] [blame] | 841 | at91_pm_modes_init(); |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 842 | sama5_pm_init(); |
Claudiu Beznea | a958156 | 2019-02-14 15:54:51 +0000 | [diff] [blame] | 843 | |
| 844 | soc_pm.ws_ids = sama5d2_ws_ids; |
| 845 | soc_pm.config_shdwc_ws = at91_sama5d2_config_shdwc_ws; |
| 846 | soc_pm.config_pmc_ws = at91_sama5d2_config_pmc_ws; |
Alexandre Belloni | 24a0f5c | 2016-09-27 12:29:50 +0200 | [diff] [blame] | 847 | } |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 848 | |
| 849 | static int __init at91_pm_modes_select(char *str) |
| 850 | { |
| 851 | char *s; |
| 852 | substring_t args[MAX_OPT_ARGS]; |
| 853 | int standby, suspend; |
| 854 | |
| 855 | if (!str) |
| 856 | return 0; |
| 857 | |
| 858 | s = strsep(&str, ","); |
| 859 | standby = match_token(s, pm_modes, args); |
| 860 | if (standby < 0) |
| 861 | return 0; |
| 862 | |
| 863 | suspend = match_token(str, pm_modes, args); |
| 864 | if (suspend < 0) |
| 865 | return 0; |
| 866 | |
Claudiu Beznea | c3f5b8f | 2019-02-14 15:54:31 +0000 | [diff] [blame] | 867 | soc_pm.data.standby_mode = standby; |
| 868 | soc_pm.data.suspend_mode = suspend; |
Alexandre Belloni | 7693e18 | 2017-04-26 16:31:03 +0200 | [diff] [blame] | 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | early_param("atmel.pm_modes", at91_pm_modes_select); |