From 8c05d6fd9dbb58e5d46f0d558fda3a1d37da08c1 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Mon, 31 Oct 2022 15:22:23 +0800 Subject: [PATCH] modem clock(hal): implemented the modem clock hal-layer for esp32c6 --- components/hal/CMakeLists.txt | 4 + .../hal/esp32c6/include/hal/modem_clock_hal.h | 40 ++++ components/hal/esp32c6/modem_clock_hal.c | 179 ++++++++++++++++++ .../hal/include/hal/modem_clock_types.h | 42 ++++ 4 files changed, 265 insertions(+) create mode 100644 components/hal/esp32c6/include/hal/modem_clock_hal.h create mode 100644 components/hal/esp32c6/modem_clock_hal.c create mode 100644 components/hal/include/hal/modem_clock_types.h diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 234d90d294..47ca3a4212 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -111,6 +111,10 @@ if(NOT BOOTLOADER_BUILD) list(APPEND srcs "sha_hal.c") endif() + if(CONFIG_SOC_MODEM_CLOCK_IS_INDEPENDENT) + list(APPEND srcs "${target}/modem_clock_hal.c") + endif() + if(${target} STREQUAL "esp32") list(APPEND srcs "sdio_slave_hal.c" diff --git a/components/hal/esp32c6/include/hal/modem_clock_hal.h b/components/hal/esp32c6/include/hal/modem_clock_hal.h new file mode 100644 index 0000000000..bbd6866fc8 --- /dev/null +++ b/components/hal/esp32c6/include/hal/modem_clock_hal.h @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// The HAL layer for MODEM CLOCK + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "hal/modem_syscon_ll.h" +#include "hal/modem_lpcon_ll.h" +#include "hal/modem_clock_types.h" + +typedef struct { + modem_syscon_dev_t *syscon_dev; + modem_lpcon_dev_t *lpcon_dev; +} modem_clock_hal_context_t; + +void modem_clock_hal_set_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain, uint32_t bitmap); + +void modem_clock_hal_select_lp_timer_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src); + +void modem_clock_hal_deselect_all_lp_timer_lpclk_source(modem_clock_hal_context_t *hal); + +void modem_clock_hal_select_coex_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src); + +void modem_clock_hal_deselect_all_coex_lpclk_source(modem_clock_hal_context_t *hal); + +void modem_clock_hal_select_wifi_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src); + +void modem_clock_hal_deselect_all_wifi_lpclk_source(modem_clock_hal_context_t *hal); + +#ifdef __cplusplus +} +#endif diff --git a/components/hal/esp32c6/modem_clock_hal.c b/components/hal/esp32c6/modem_clock_hal.c new file mode 100644 index 0000000000..7cbe2bf820 --- /dev/null +++ b/components/hal/esp32c6/modem_clock_hal.c @@ -0,0 +1,179 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// The HAL layer for MODEM CLOCK (ESP32-C6 specific part) +#include +#include "soc/soc.h" +#include "esp_attr.h" +#include "hal/modem_clock_hal.h" +#include "hal/modem_clock_types.h" +#include "hal/assert.h" + +typedef enum { + MODEM_CLOCK_XTAL32K_CODE = 0, + MODEM_CLOCK_RC32K_CODE = 1, + MODEM_CLOCK_EXT32K_CODE = 2 +} modem_clock_32k_clk_src_code_t; + +void modem_clock_hal_set_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain, uint32_t bitmap) +{ + HAL_ASSERT(domain < MODEM_CLOCK_DOMAIN_MAX); + switch (domain) + { + case MODEM_CLOCK_DOMAIN_MODEM_APB: + modem_syscon_ll_set_modem_apb_icg_bitmap(hal->syscon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_MODEM_PERIPH: + modem_syscon_ll_set_modem_periph_icg_bitmap(hal->syscon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_WIFI: + modem_syscon_ll_set_wifi_icg_bitmap(hal->syscon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_BT: + modem_syscon_ll_set_bt_icg_bitmap(hal->syscon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_FE: + modem_syscon_ll_set_fe_icg_bitmap(hal->syscon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_IEEE802154: + modem_syscon_ll_set_ieee802154_icg_bitmap(hal->syscon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_LP_APB: + modem_lpcon_ll_set_lp_apb_icg_bitmap(hal->lpcon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_I2C_MASTER: + modem_lpcon_ll_set_i2c_master_icg_bitmap(hal->lpcon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_COEX: + modem_lpcon_ll_set_coex_icg_bitmap(hal->lpcon_dev, bitmap); + break; + case MODEM_CLOCK_DOMAIN_WIFIPWR: + modem_lpcon_ll_set_wifipwr_icg_bitmap(hal->lpcon_dev, bitmap); + break; + default: + break; + } +} + +void modem_clock_hal_deselect_all_lp_timer_lpclk_source(modem_clock_hal_context_t *hal) +{ + modem_lpcon_ll_enable_lp_timer_slow_osc(hal->lpcon_dev, false); + modem_lpcon_ll_enable_lp_timer_fast_osc(hal->lpcon_dev, false); + modem_lpcon_ll_enable_lp_timer_32k_xtal(hal->lpcon_dev, false); + modem_lpcon_ll_enable_lp_timer_main_xtal(hal->lpcon_dev, false); +} + +void modem_clock_hal_select_lp_timer_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src) +{ + HAL_ASSERT(src < MODEM_CLOCK_LPCLK_SRC_MAX); + + switch (src) + { + case MODEM_CLOCK_LPCLK_SRC_RC_SLOW: + modem_lpcon_ll_enable_lp_timer_slow_osc(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_RC_FAST: + modem_lpcon_ll_enable_lp_timer_fast_osc(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL: + modem_lpcon_ll_enable_lp_timer_main_xtal(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_RC32K: + modem_lpcon_ll_enable_lp_timer_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_RC32K_CODE); + break; + case MODEM_CLOCK_LPCLK_SRC_XTAL32K: + modem_lpcon_ll_enable_lp_timer_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_XTAL32K_CODE); + break; + case MODEM_CLOCK_LPCLK_SRC_EXT32K: + modem_lpcon_ll_enable_lp_timer_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_EXT32K_CODE); + break; + default: + break; + } +} + +void modem_clock_hal_deselect_all_coex_lpclk_source(modem_clock_hal_context_t *hal) +{ + modem_lpcon_ll_enable_coex_lpclk_slow_osc(hal->lpcon_dev, false); + modem_lpcon_ll_enable_coex_lpclk_fast_osc(hal->lpcon_dev, false); + modem_lpcon_ll_enable_coex_lpclk_32k_xtal(hal->lpcon_dev, false); + modem_lpcon_ll_enable_coex_lpclk_main_xtal(hal->lpcon_dev, false); +} + +void modem_clock_hal_select_coex_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src) +{ + HAL_ASSERT(src < MODEM_CLOCK_LPCLK_SRC_MAX); + + switch (src) + { + case MODEM_CLOCK_LPCLK_SRC_RC_SLOW: + modem_lpcon_ll_enable_coex_lpclk_slow_osc(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_RC_FAST: + modem_lpcon_ll_enable_coex_lpclk_fast_osc(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL: + modem_lpcon_ll_enable_coex_lpclk_main_xtal(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_RC32K: + modem_lpcon_ll_enable_coex_lpclk_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_RC32K_CODE); + break; + case MODEM_CLOCK_LPCLK_SRC_XTAL32K: + modem_lpcon_ll_enable_coex_lpclk_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_XTAL32K_CODE); + break; + case MODEM_CLOCK_LPCLK_SRC_EXT32K: + modem_lpcon_ll_enable_coex_lpclk_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_EXT32K_CODE); + break; + default: + break; + } +} + +void modem_clock_hal_deselect_all_wifi_lpclk_source(modem_clock_hal_context_t *hal) +{ + modem_lpcon_ll_enable_wifi_lpclk_slow_osc(hal->lpcon_dev, false); + modem_lpcon_ll_enable_wifi_lpclk_fast_osc(hal->lpcon_dev, false); + modem_lpcon_ll_enable_wifi_lpclk_32k_xtal(hal->lpcon_dev, false); + modem_lpcon_ll_enable_wifi_lpclk_main_xtal(hal->lpcon_dev, false); +} + +void modem_clock_hal_select_wifi_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src) +{ + HAL_ASSERT(src < MODEM_CLOCK_LPCLK_SRC_MAX); + + switch (src) + { + case MODEM_CLOCK_LPCLK_SRC_RC_SLOW: + modem_lpcon_ll_enable_wifi_lpclk_slow_osc(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_RC_FAST: + modem_lpcon_ll_enable_wifi_lpclk_fast_osc(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL: + modem_lpcon_ll_enable_wifi_lpclk_main_xtal(hal->lpcon_dev, true); + break; + case MODEM_CLOCK_LPCLK_SRC_RC32K: + modem_lpcon_ll_enable_wifi_lpclk_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_RC32K_CODE); + break; + case MODEM_CLOCK_LPCLK_SRC_XTAL32K: + modem_lpcon_ll_enable_wifi_lpclk_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_XTAL32K_CODE); + break; + case MODEM_CLOCK_LPCLK_SRC_EXT32K: + modem_lpcon_ll_enable_wifi_lpclk_32k_xtal(hal->lpcon_dev, true); + modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_EXT32K_CODE); + break; + default: + break; + } +} diff --git a/components/hal/include/hal/modem_clock_types.h b/components/hal/include/hal/modem_clock_types.h new file mode 100644 index 0000000000..2ebb2fc018 --- /dev/null +++ b/components/hal/include/hal/modem_clock_types.h @@ -0,0 +1,42 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + MODEM_CLOCK_DOMAIN_MODEM_APB = 0, + MODEM_CLOCK_DOMAIN_MODEM_PERIPH, + MODEM_CLOCK_DOMAIN_WIFI, + MODEM_CLOCK_DOMAIN_BT, + MODEM_CLOCK_DOMAIN_FE, + MODEM_CLOCK_DOMAIN_IEEE802154, + + MODEM_CLOCK_DOMAIN_LP_APB, + MODEM_CLOCK_DOMAIN_I2C_MASTER, + MODEM_CLOCK_DOMAIN_COEX, + MODEM_CLOCK_DOMAIN_WIFIPWR, + + MODEM_CLOCK_DOMAIN_MAX +} modem_clock_domain_t; + +typedef enum { + MODEM_CLOCK_LPCLK_SRC_INVALID = -1, + MODEM_CLOCK_LPCLK_SRC_RC_SLOW = 0, + MODEM_CLOCK_LPCLK_SRC_RC_FAST, + MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL, + MODEM_CLOCK_LPCLK_SRC_RC32K, + MODEM_CLOCK_LPCLK_SRC_XTAL32K, + MODEM_CLOCK_LPCLK_SRC_EXT32K, + MODEM_CLOCK_LPCLK_SRC_MAX +} modem_clock_lpclk_src_t; + +#ifdef __cplusplus +} +#endif