feat(esp_security): suppoer s31 security clock management

This commit is contained in:
wuzhenghui
2026-06-15 10:31:07 +08:00
parent 964511ca30
commit 58d89e8bc0
28 changed files with 266 additions and 9 deletions
@@ -0,0 +1,38 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_crypto_clk.h"
#include "soc/clk_tree_defs.h"
#include "soc/hp_sys_clkrst_struct.h"
#if !NON_OS_BUILD
#include "esp_private/critical_section.h"
#endif
#if !NON_OS_BUILD
DEFINE_CRIT_SECTION_LOCK_STATIC(s_crypto_common_clk_mux);
#endif
static int s_crypto_common_clk_ref_cnt;
void esp_crypto_common_clk_enable(bool enable)
{
#if !NON_OS_BUILD
esp_os_enter_critical_safe(&s_crypto_common_clk_mux);
#endif
if (enable) {
if (s_crypto_common_clk_ref_cnt++ == 0) {
HP_SYS_CLKRST.crypto_ctrl0.reg_crypto_sys_clk_en = 1;
HP_SYS_CLKRST.crypto_ctrl0.reg_crypto_sec_clk_en = 1;
}
} else {
if (s_crypto_common_clk_ref_cnt > 0 && --s_crypto_common_clk_ref_cnt == 0) {
HP_SYS_CLKRST.crypto_ctrl0.reg_crypto_sec_clk_en = 0;
HP_SYS_CLKRST.crypto_ctrl0.reg_crypto_sys_clk_en = 0;
}
}
#if !NON_OS_BUILD
esp_os_exit_critical_safe(&s_crypto_common_clk_mux);
#endif
}
@@ -1,15 +1,20 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/soc.h"
#include "soc/hp_sys_clkrst_reg.h"
#pragma once
#include <stdbool.h>
#include "soc/soc.h"
#include "soc/hp_sys_clkrst_reg.h"
#include "soc/hp_sys_clkrst_struct.h"
static inline void esp_crypto_clk_init(void)
{
// Set crypto clock (`clk_sec`) to use 240M PLL clock
REG_SET_FIELD(HP_SYS_CLKRST_CRYPTO_CTRL0_REG, HP_SYS_CLKRST_REG_CRYPTO_CLK_SRC_SEL, 0x2);
}
void esp_crypto_common_clk_enable(bool enable);