Skip to content

Commit

Permalink
drivers: crypto: stm32_cryp: add pm to CRYP driver
Browse files Browse the repository at this point in the history
Add power management support to the CRYP driver through suspend/resume
callbacks.

Signed-off-by: Thomas Bourgoin <thomas.bourgoin@foss.st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
  • Loading branch information
tbourgoi authored and jforissier committed Mar 25, 2024
1 parent 14d6863 commit 299f9bc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/drivers/crypto/stm32/stm32_cryp.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <kernel/dt.h>
#include <kernel/dt_driver.h>
#include <kernel/mutex.h>
#include <kernel/pm.h>
#include <libfdt.h>
#include <mm/core_memprot.h>
#include <stdint.h>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 299f9bc

Please sign in to comment.