Skip to content

Commit f2f5cf7

Browse files
clementlegerclaudiubeznea
authored andcommitted
ARM: at91: pm: add support for sama5d2 secure suspend
When running with OP-TEE, the suspend control is handled securely. Suspend can be entered using PSCI support. Since the sama5d2 supports multiple suspend modes, add a new CONFIG_ATMEL_SECURE_PM which will send a SMC call to select the suspend mode at init time. "atmel.pm_modes" boot argument is still supported for compatibility purposes but the standby value is actually ignored since PSCI suspend is used and it only support one mode (suspend). Signed-off-by: Clément Léger <clement.leger@bootlin.com> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com>
1 parent 0c9fd82 commit f2f5cf7

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

arch/arm/mach-at91/Kconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,16 @@ config SOC_SAMA5
218218
select SRAM if PM
219219

220220
config ATMEL_PM
221-
bool
221+
bool "Atmel PM support"
222+
223+
config ATMEL_SECURE_PM
224+
bool "Atmel Secure PM support"
225+
depends on SOC_SAMA5D2 && ATMEL_PM
226+
select ARM_PSCI
227+
help
228+
When running under a TEE, the suspend mode must be requested to be set
229+
at TEE level. When enable, this option will use secure monitor calls
230+
to set the suspend level. PSCI is then used to enter suspend.
222231

223232
config SOC_SAMA7
224233
bool

arch/arm/mach-at91/pm.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "generic.h"
3030
#include "pm.h"
31+
#include "sam_secure.h"
3132

3233
#define BACKUP_DDR_PHY_CALIBRATION (9)
3334

@@ -1078,6 +1079,35 @@ static int __init at91_pm_backup_init(void)
10781079
return ret;
10791080
}
10801081

1082+
static void at91_pm_secure_init(void)
1083+
{
1084+
int suspend_mode;
1085+
struct arm_smccc_res res;
1086+
1087+
suspend_mode = soc_pm.data.suspend_mode;
1088+
1089+
res = sam_smccc_call(SAMA5_SMC_SIP_SET_SUSPEND_MODE,
1090+
suspend_mode, 0);
1091+
if (res.a0 == 0) {
1092+
pr_info("AT91: Secure PM: suspend mode set to %s\n",
1093+
pm_modes[suspend_mode].pattern);
1094+
return;
1095+
}
1096+
1097+
pr_warn("AT91: Secure PM: %s mode not supported !\n",
1098+
pm_modes[suspend_mode].pattern);
1099+
1100+
res = sam_smccc_call(SAMA5_SMC_SIP_GET_SUSPEND_MODE, 0, 0);
1101+
if (res.a0 == 0) {
1102+
pr_warn("AT91: Secure PM: failed to get default mode\n");
1103+
return;
1104+
}
1105+
1106+
pr_info("AT91: Secure PM: using default suspend mode %s\n",
1107+
pm_modes[suspend_mode].pattern);
1108+
1109+
soc_pm.data.suspend_mode = res.a1;
1110+
}
10811111
static const struct of_device_id atmel_shdwc_ids[] = {
10821112
{ .compatible = "atmel,sama5d2-shdwc" },
10831113
{ .compatible = "microchip,sam9x60-shdwc" },
@@ -1526,6 +1556,12 @@ void __init sama5d2_pm_init(void)
15261556
if (!IS_ENABLED(CONFIG_SOC_SAMA5D2))
15271557
return;
15281558

1559+
if (IS_ENABLED(CONFIG_ATMEL_SECURE_PM)) {
1560+
pr_warn("AT91: Secure PM: ignoring standby mode\n");
1561+
at91_pm_secure_init();
1562+
return;
1563+
}
1564+
15291565
at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
15301566
at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
15311567
ret = at91_dt_ramc(false);

arch/arm/mach-at91/sam_secure.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
#include <linux/arm-smccc.h>
1010

11+
/* Secure Monitor mode APIs */
12+
#define SAMA5_SMC_SIP_SET_SUSPEND_MODE 0x400
13+
#define SAMA5_SMC_SIP_GET_SUSPEND_MODE 0x401
14+
1115
void __init sam_secure_init(void);
1216
struct arm_smccc_res sam_smccc_call(u32 fn, u32 arg0, u32 arg1);
1317

0 commit comments

Comments
 (0)