fix(hal): Fix Key Manager clock changes

This commit is contained in:
Aditya Patwardhan 2024-02-05 09:20:05 +05:30 committed by Mahavir Jain
parent afbed25c6f
commit 3ffb811d18
2 changed files with 17 additions and 3 deletions

View File

@ -74,6 +74,7 @@ static void esp_key_mgr_acquire_hardware(void)
// Reset the Key Manager Clock
KEY_MANAGER_RCC_ATOMIC() {
key_mgr_ll_enable_bus_clock(true);
key_mgr_ll_enable_peripheral_clock(true);
key_mgr_ll_reset_register();
}
}
@ -83,6 +84,7 @@ static void esp_key_mgr_release_hardware(void)
esp_crypto_key_manager_lock_release();
// Reset the Key Manager Clock
KEY_MANAGER_RCC_ATOMIC() {
key_mgr_ll_enable_peripheral_clock(false);
key_mgr_ll_enable_bus_clock(false);
key_mgr_ll_reset_register();
}

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -41,12 +41,24 @@ static inline void key_mgr_ll_enable_bus_clock(bool enable)
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define key_mgr_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; key_mgr_ll_enable_bus_clock(__VA_ARGS__)
/**
* @brief Enable the peripheral clock for Key Manager
*
* @param true to enable, false to disable
*/
static inline void key_mgr_ll_enable_peripheral_clock(bool enable)
{
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_km_clk_en = enable;
}
#define key_mgr_ll_enable_peripheral_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; key_mgr_ll_enable_bus_clock(__VA_ARGS__)
/**
* @brief Reset the Key Manager peripheral */
static inline void key_mgr_ll_reset_register(void)
{
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_km_clk_en = 1;
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_km_clk_en = 0;
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_km = 1;
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_km = 0;
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 1;
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 0;
}