1 From 0c4cbd38a705bdeab11de4c84ad0ce8c3de8a81d Mon Sep 17 00:00:00 2001
2 From: Claudiu Beznea <claudiu.beznea@microchip.com>
3 Date: Thu, 15 Apr 2021 13:49:50 +0300
4 Subject: [PATCH 200/247] ARM: at91: pm: check for different controllers in
7 at91_pm_modes_init() checks for proper nodes in device tree and maps
8 them accordingly. Up to SAMA7G5 all AT91 SoCs had the same mapping
9 b/w power saving modes and different controllers needed in the
10 final/first steps of suspend/resume. SAMA7G5 is not aligned with the
11 old SoCs thus the code is adapted for this. This patch prepares
12 the field for next commits.
14 Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
15 Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com>
16 Link: https://lore.kernel.org/r/20210415105010.569620-5-claudiu.beznea@microchip.com
18 arch/arm/mach-at91/pm.c | 143 +++++++++++++++++++++++++---------------
19 1 file changed, 91 insertions(+), 52 deletions(-)
21 diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
22 index a060bec77f20..e9f9fb410761 100644
23 --- a/arch/arm/mach-at91/pm.c
24 +++ b/arch/arm/mach-at91/pm.c
25 @@ -57,6 +57,18 @@ struct at91_soc_pm {
26 struct at91_pm_data data;
30 + * enum at91_pm_iomaps: IOs that needs to be mapped for different PM modes
31 + * @AT91_PM_IOMAP_SHDWC: SHDWC controller
32 + * @AT91_PM_IOMAP_SFRBU: SFRBU controller
34 +enum at91_pm_iomaps {
35 + AT91_PM_IOMAP_SHDWC,
36 + AT91_PM_IOMAP_SFRBU,
39 +#define AT91_PM_IOMAP(name) BIT(AT91_PM_IOMAP_##name)
41 static struct at91_soc_pm soc_pm = {
43 .standby_mode = AT91_PM_STANDBY,
44 @@ -671,24 +683,15 @@ static int __init at91_pm_backup_init(void)
45 if (!at91_is_pm_mode_active(AT91_PM_BACKUP))
48 - np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-sfrbu");
50 - pr_warn("%s: failed to find sfrbu!\n", __func__);
54 - soc_pm.data.sfrbu = of_iomap(np, 0);
57 np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
59 - goto securam_fail_no_ref_dev;
62 pdev = of_find_device_by_node(np);
65 pr_warn("%s: failed to find securam device!\n", __func__);
66 - goto securam_fail_no_ref_dev;
70 sram_pool = gen_pool_get(&pdev->dev, NULL);
71 @@ -712,64 +715,92 @@ static int __init at91_pm_backup_init(void)
74 put_device(&pdev->dev);
75 -securam_fail_no_ref_dev:
76 - iounmap(soc_pm.data.sfrbu);
77 - soc_pm.data.sfrbu = NULL;
81 -static void __init at91_pm_use_default_mode(int pm_mode)
83 - if (pm_mode != AT91_PM_ULP1 && pm_mode != AT91_PM_BACKUP)
86 - if (soc_pm.data.standby_mode == pm_mode)
87 - soc_pm.data.standby_mode = AT91_PM_ULP0;
88 - if (soc_pm.data.suspend_mode == pm_mode)
89 - soc_pm.data.suspend_mode = AT91_PM_ULP0;
92 static const struct of_device_id atmel_shdwc_ids[] = {
93 { .compatible = "atmel,sama5d2-shdwc" },
94 { .compatible = "microchip,sam9x60-shdwc" },
98 -static void __init at91_pm_modes_init(void)
99 +static void __init at91_pm_modes_init(const u32 *maps, int len)
101 struct device_node *np;
105 - if (!at91_is_pm_mode_active(AT91_PM_BACKUP) &&
106 - !at91_is_pm_mode_active(AT91_PM_ULP1))
108 + ret = at91_pm_backup_init();
110 + if (soc_pm.data.standby_mode == AT91_PM_BACKUP)
111 + soc_pm.data.standby_mode = AT91_PM_ULP0;
112 + if (soc_pm.data.suspend_mode == AT91_PM_BACKUP)
113 + soc_pm.data.suspend_mode = AT91_PM_ULP0;
116 - np = of_find_matching_node(NULL, atmel_shdwc_ids);
118 - pr_warn("%s: failed to find shdwc!\n", __func__);
120 + if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC) ||
121 + maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC)) {
122 + np = of_find_matching_node(NULL, atmel_shdwc_ids);
124 + pr_warn("%s: failed to find shdwc!\n", __func__);
126 + /* Use ULP0 if it doesn't needs SHDWC.*/
127 + if (!(maps[AT91_PM_ULP0] & AT91_PM_IOMAP(SHDWC)))
128 + mode = AT91_PM_ULP0;
130 + mode = AT91_PM_STANDBY;
132 + if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC))
133 + soc_pm.data.standby_mode = mode;
134 + if (maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC))
135 + soc_pm.data.suspend_mode = mode;
137 + soc_pm.data.shdwc = of_iomap(np, 0);
142 - soc_pm.data.shdwc = of_iomap(np, 0);
144 + if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU) ||
145 + maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU)) {
146 + np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-sfrbu");
148 + pr_warn("%s: failed to find sfrbu!\n", __func__);
151 + * Use ULP0 if it doesn't need SHDWC or if SHDWC
152 + * was already located.
154 + if (!(maps[AT91_PM_ULP0] & AT91_PM_IOMAP(SHDWC)) ||
156 + mode = AT91_PM_ULP0;
158 + mode = AT91_PM_STANDBY;
160 + if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU))
161 + soc_pm.data.standby_mode = mode;
162 + if (maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU))
163 + soc_pm.data.suspend_mode = mode;
165 + soc_pm.data.sfrbu = of_iomap(np, 0);
170 - ret = at91_pm_backup_init();
172 - if (!at91_is_pm_mode_active(AT91_PM_ULP1))
175 - goto backup_default;
176 + /* Unmap all unnecessary. */
177 + if (soc_pm.data.shdwc &&
178 + !(maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC) ||
179 + maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC))) {
180 + iounmap(soc_pm.data.shdwc);
181 + soc_pm.data.shdwc = NULL;
185 + if (soc_pm.data.sfrbu &&
186 + !(maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU) ||
187 + maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU))) {
188 + iounmap(soc_pm.data.sfrbu);
189 + soc_pm.data.sfrbu = NULL;
193 - iounmap(soc_pm.data.shdwc);
194 - soc_pm.data.shdwc = NULL;
196 - at91_pm_use_default_mode(AT91_PM_ULP1);
198 - at91_pm_use_default_mode(AT91_PM_BACKUP);
203 @@ -936,13 +967,16 @@ void __init sam9x60_pm_init(void)
204 static const int modes[] __initconst = {
205 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST, AT91_PM_ULP1,
207 + static const int iomaps[] __initconst = {
208 + [AT91_PM_ULP1] = AT91_PM_IOMAP(SHDWC),
212 if (!IS_ENABLED(CONFIG_SOC_SAM9X60))
215 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
216 - at91_pm_modes_init();
217 + at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
218 ret = at91_dt_ramc();
221 @@ -999,13 +1033,18 @@ void __init sama5d2_pm_init(void)
222 AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST, AT91_PM_ULP1,
225 + static const u32 iomaps[] __initconst = {
226 + [AT91_PM_ULP1] = AT91_PM_IOMAP(SHDWC),
227 + [AT91_PM_BACKUP] = AT91_PM_IOMAP(SHDWC) |
228 + AT91_PM_IOMAP(SFRBU),
232 if (!IS_ENABLED(CONFIG_SOC_SAMA5D2))
235 at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
236 - at91_pm_modes_init();
237 + at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
238 ret = at91_dt_ramc();