Skip to content

Commit f0d0058

Browse files
author
Raffael Rostagno
committed
soc: clock: esp32h: Add RNG clock control
Add RNG peripheral clock control. Signed-off-by: Raffael Rostagno <[email protected]>
1 parent 8f30421 commit f0d0058

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

components/hal/esp32h2/include/hal/clk_gate_ll.h

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -11,6 +11,7 @@
1111
#include "soc/periph_defs.h"
1212
#include "soc/pcr_reg.h"
1313
#include "soc/soc.h"
14+
#include "soc/lpperi_reg.h"
1415

1516
#ifdef __cplusplus
1617
extern "C" {
@@ -77,8 +78,6 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
7778
return PCR_TSENS_CLK_EN;
7879
case PERIPH_REGDMA_MODULE:
7980
return PCR_REGDMA_CLK_EN;
80-
// case PERIPH_RNG_MODULE:
81-
// return PCR_WIFI_CLK_RNG_EN;
8281
// case PERIPH_WIFI_MODULE:
8382
// return PCR_WIFI_CLK_WIFI_EN_M;
8483
// case PERIPH_BT_MODULE:
@@ -89,6 +88,8 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
8988
// return PCR_BT_BASEBAND_EN;
9089
// case PERIPH_BT_LC_MODULE:
9190
// return PCR_BT_LC_EN;
91+
case PERIPH_RNG_MODULE:
92+
return LPPERI_RNG_CK_EN;
9293
default:
9394
return 0;
9495
}
@@ -197,7 +198,6 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en
197198
static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
198199
{// ESP32H2-TODO: IDF-6400
199200
switch (periph) {
200-
// case PERIPH_RNG_MODULE:
201201
// case PERIPH_WIFI_MODULE:
202202
// case PERIPH_BT_MODULE:
203203
// case PERIPH_WIFI_BT_COMMON_MODULE:
@@ -263,6 +263,8 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
263263
return PCR_TSENS_CLK_CONF_REG;
264264
case PERIPH_REGDMA_MODULE:
265265
return PCR_REGDMA_CONF_REG;
266+
case PERIPH_RNG_MODULE:
267+
return LPPERI_CLK_EN_REG;
266268
default:
267269
return 0;
268270
}
@@ -337,14 +339,30 @@ static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph)
337339

338340
static inline void periph_ll_enable_clk_clear_rst(periph_module_t periph)
339341
{
340-
SET_PERI_REG_MASK(periph_ll_get_clk_en_reg(periph), periph_ll_get_clk_en_mask(periph));
341-
CLEAR_PERI_REG_MASK(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, true));
342+
uint32_t clk_en_reg = periph_ll_get_clk_en_reg(periph);
343+
uint32_t rst_en_reg = periph_ll_get_rst_en_reg(periph);
344+
345+
if (clk_en_reg != 0) {
346+
SET_PERI_REG_MASK(clk_en_reg, periph_ll_get_clk_en_mask(periph));
347+
}
348+
349+
if (rst_en_reg != 0) {
350+
CLEAR_PERI_REG_MASK(rst_en_reg, periph_ll_get_rst_en_mask(periph, true));
351+
}
342352
}
343353

344354
static inline void periph_ll_disable_clk_set_rst(periph_module_t periph)
345355
{
346-
CLEAR_PERI_REG_MASK(periph_ll_get_clk_en_reg(periph), periph_ll_get_clk_en_mask(periph));
347-
SET_PERI_REG_MASK(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, false));
356+
uint32_t clk_en_reg = periph_ll_get_clk_en_reg(periph);
357+
uint32_t rst_en_reg = periph_ll_get_rst_en_reg(periph);
358+
359+
if (clk_en_reg != 0) {
360+
CLEAR_PERI_REG_MASK(clk_en_reg, periph_ll_get_clk_en_mask(periph));
361+
}
362+
363+
if (rst_en_reg != 0) {
364+
SET_PERI_REG_MASK(rst_en_reg, periph_ll_get_rst_en_mask(periph, false));
365+
}
348366
}
349367

350368
static inline void periph_ll_wifi_bt_module_enable_clk(void)
@@ -359,14 +377,26 @@ static inline void periph_ll_wifi_bt_module_disable_clk(void)
359377

360378
static inline void periph_ll_reset(periph_module_t periph)
361379
{
362-
SET_PERI_REG_MASK(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, false));
363-
CLEAR_PERI_REG_MASK(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, false));
380+
uint32_t rst_en_reg = periph_ll_get_rst_en_reg(periph);
381+
382+
if (rst_en_reg != 0) {
383+
SET_PERI_REG_MASK(rst_en_reg, periph_ll_get_rst_en_mask(periph, false));
384+
CLEAR_PERI_REG_MASK(rst_en_reg, periph_ll_get_rst_en_mask(periph, false));
385+
}
364386
}
365387

366388
static inline bool periph_ll_periph_enabled(periph_module_t periph)
367389
{
368-
return REG_GET_BIT(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, false)) == 0 &&
369-
REG_GET_BIT(periph_ll_get_clk_en_reg(periph), periph_ll_get_clk_en_mask(periph)) != 0;
390+
uint32_t clk_en_reg = periph_ll_get_clk_en_reg(periph);
391+
uint32_t rst_en_reg = periph_ll_get_rst_en_reg(periph);
392+
393+
bool clk_enabled = (clk_en_reg != 0) &&
394+
(REG_GET_BIT(clk_en_reg, periph_ll_get_clk_en_mask(periph)) != 0);
395+
396+
bool rst_disabled = (rst_en_reg == 0) ||
397+
(REG_GET_BIT(rst_en_reg, periph_ll_get_rst_en_mask(periph, false)) == 0);
398+
399+
return clk_enabled && rst_disabled;
370400
}
371401

372402
static inline void periph_ll_wifi_module_enable_clk_clear_rst(void)

0 commit comments

Comments
 (0)