From 299f9bc19fce1031de42dbf1bd8732a57ca1863a Mon Sep 17 00:00:00 2001 From: Thomas Bourgoin Date: Fri, 8 Mar 2024 12:29:52 +0100 Subject: [PATCH] drivers: crypto: stm32_cryp: add pm to CRYP driver Add power management support to the CRYP driver through suspend/resume callbacks. Signed-off-by: Thomas Bourgoin Signed-off-by: Patrick Delaunay Reviewed-by: Etienne Carriere --- core/drivers/crypto/stm32/stm32_cryp.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/core/drivers/crypto/stm32/stm32_cryp.c b/core/drivers/crypto/stm32/stm32_cryp.c index 1fcbc8f5798..e8da4d58456 100644 --- a/core/drivers/crypto/stm32/stm32_cryp.c +++ b/core/drivers/crypto/stm32/stm32_cryp.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1242,6 +1243,29 @@ TEE_Result stm32_cryp_update(struct stm32_cryp_context *ctx, bool last_block, return res; } +static TEE_Result stm32_cryp_pm(enum pm_op op, uint32_t pm_hint, + const struct pm_callback_handle *hdl __unused) +{ + switch (op) { + case PM_OP_SUSPEND: + clk_disable(cryp_pdata.clock); + return TEE_SUCCESS; + case PM_OP_RESUME: + if (clk_enable(cryp_pdata.clock)) + panic(); + + if (PM_HINT_IS_STATE(pm_hint, CONTEXT) && stm32_cryp_reset()) + panic(); + + return TEE_SUCCESS; + default: + /* Unexpected PM operation */ + assert(0); + return TEE_ERROR_NOT_IMPLEMENTED; + } +} +DECLARE_KEEP_PAGER(stm32_cryp_pm); + static TEE_Result stm32_cryp_probe(const void *fdt, int node, const void *compt_data __unused) { @@ -1296,6 +1320,8 @@ static TEE_Result stm32_cryp_probe(const void *fdt, int node, } } + register_pm_core_service_cb(stm32_cryp_pm, NULL, "stm32-cryp"); + return TEE_SUCCESS; }