Forráskód Böngészése

esp_hw_support: add modem module mac reset api

wuzhenghui 2 éve
szülő
commit
4196eddff1

+ 28 - 0
components/esp_hw_support/include/esp_private/esp_modem_clock.h

@@ -29,6 +29,16 @@ extern "C" {
  * module depends on the wifi mac, wifi baseband and FE, when wifi module
  * clock is enabled, the wifi MAC, baseband and FE clocks will be enabled
  *
+ * This interface and modem_clock_module_disable will jointly maintain the
+ * ref_cnt of each device clock source. The ref_cnt indicates how many modules
+ * are relying on the clock source. Each enable ops will add 1 to the ref_cnt of
+ * the clock source that the module depends on, and only when the ref_cnt of
+ * the module is from 0 to 1 will the clock enable be actually configured.
+ *
+ * !!! Do not use the hal/ll layer interface to configure the clock for the
+ * consistency of the hardware state maintained in the driver and the hardware
+ * actual state.
+ *
  * @param module  modem module
  */
 void modem_clock_module_enable(periph_module_t module);
@@ -36,10 +46,28 @@ void modem_clock_module_enable(periph_module_t module);
 /**
  * @brief Disable the clock of modem module
  *
+ * This interface and modem_clock_module_enable will jointly maintain the ref_cnt
+ * of each device clock source. The ref_cnt indicates how many modules are relying
+ * on the clock source. Each disable ops will minus 1 to the ref_cnt of the clock
+ * source that the module depends on, and only when the ref_cnt of the module is
+ * from 1 to 0 will the clock disable be actually configured.
+ *
+ * !!! Do not use the hal/ll layer interface to configure the clock for the
+ * consistency of the hardware state maintained in the driver and the hardware
+ * actual state.
+ *
  * @param module  modem module
  */
 void modem_clock_module_disable(periph_module_t module);
 
+/**
+ * @brief Reset the mac of modem module
+ *
+ * @param module  modem module, must be one of
+ *    PERIPH_WIFI_MODULE / PERIPH_BT_MODULE /PERIPH_IEEE802154_MODULE
+ */
+void modem_clock_module_mac_reset(periph_module_t module);
+
 /**
  * @brief Initialize the clock gating control signal of each clock domain of the modem
  *

+ 24 - 5
components/esp_hw_support/modem_clock.c

@@ -214,15 +214,34 @@ static void IRAM_ATTR modem_clock_device_disable(modem_clock_context_t *ctx, uin
     assert(refs >= 0);
 }
 
-void IRAM_ATTR modem_clock_wifi_mac_reset(void)
+void IRAM_ATTR modem_clock_module_mac_reset(periph_module_t module)
 {
-#if SOC_WIFI_SUPPORTED
     modem_clock_context_t *ctx = MODEM_CLOCK_instance();
     portENTER_CRITICAL_SAFE(&ctx->lock);
-    //TODO: IDF-5713
-    modem_syscon_ll_reset_wifimac(ctx->hal->syscon_dev);
-    portEXIT_CRITICAL_SAFE(&ctx->lock);
+    switch (module)
+    {
+#if SOC_WIFI_SUPPORTED
+        case PERIPH_WIFI_MODULE:
+            modem_syscon_ll_reset_wifimac(ctx->hal->syscon_dev);
+            break;
 #endif
+#if SOC_BT_SUPPORTED
+        case PERIPH_BT_MODULE:
+            modem_syscon_ll_reset_btmac(ctx->hal->syscon_dev);
+            modem_syscon_ll_reset_btmac_apb(ctx->hal->syscon_dev);
+            modem_syscon_ll_reset_ble_timer(ctx->hal->syscon_dev);
+            modem_syscon_ll_reset_modem_sec(ctx->hal->syscon_dev);
+            break;
+#endif
+#if SOC_IEEE802154_SUPPORTED
+        case PERIPH_IEEE802154_MODULE:
+            modem_syscon_ll_reset_zbmac(ctx->hal->syscon_dev);
+            break;
+        default:
+#endif
+            assert(0);
+    }
+    portEXIT_CRITICAL_SAFE(&ctx->lock);
 }
 
 #define WIFI_CLOCK_DEPS       (BIT(MODEM_CLOCK_WIFI_MAC) | BIT(MODEM_CLOCK_FE) | BIT(MODEM_CLOCK_WIFI_BB) | BIT(MODEM_CLOCK_COEXIST))

+ 4 - 36
components/hal/esp32c6/include/hal/clk_gate_ll.h

@@ -18,7 +18,7 @@ extern "C" {
 #endif
 
 static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
-{ // TODO: IDF-5713
+{
     switch (periph) {
         case PERIPH_SARADC_MODULE:
             return PCR_SARADC_CLK_EN;
@@ -78,25 +78,13 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
             return PCR_SDIO_SLAVE_CLK_EN;
         case PERIPH_REGDMA_MODULE:
             return PCR_REGDMA_CLK_EN;
-        // case PERIPH_RNG_MODULE:
-        //     return PCR_WIFI_CLK_RNG_EN;
-        // case PERIPH_WIFI_MODULE:
-        //     return PCR_WIFI_CLK_WIFI_EN_M;
-        // case PERIPH_BT_MODULE:
-        //     return PCR_WIFI_CLK_BT_EN_M;
-        // case PERIPH_WIFI_BT_COMMON_MODULE:
-        //     return PCR_WIFI_CLK_WIFI_BT_COMMON_M;
-        // case PERIPH_BT_BASEBAND_MODULE:
-        //     return PCR_BT_BASEBAND_EN;
-        // case PERIPH_BT_LC_MODULE:
-        //     return PCR_BT_LC_EN;
         default:
             return 0;
     }
 }
 
 static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool enable)
-{ // TODO: IDF-5713
+{
     (void)enable; // unused
 
     switch (periph) {
@@ -171,34 +159,14 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en
             return PCR_SDIO_SLAVE_RST_EN;
         case PERIPH_REGDMA_MODULE:
             return PCR_REGDMA_RST_EN;
-        // case PERIPH_RNG_MODULE:
-        //     return PCR_WIFI_CLK_RNG_EN;
-        // case PERIPH_WIFI_MODULE:
-        //     return PCR_WIFI_CLK_WIFI_EN_M;
-        // case PERIPH_BT_MODULE:
-        //     return PCR_WIFI_CLK_BT_EN_M;
-        // case PERIPH_WIFI_BT_COMMON_MODULE:
-        //     return PCR_WIFI_CLK_WIFI_BT_COMMON_M;
-        // case PERIPH_BT_BASEBAND_MODULE:
-        //     return PCR_BT_BASEBAND_EN;
-        // case PERIPH_BT_LC_MODULE:
-        //     return PCR_BT_LC_EN;
         default:
             return 0;
     }
 }
 
 static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
-{ // TODO: IDF-5713
+{
     switch (periph) {
-    // case PERIPH_RNG_MODULE:
-    // case PERIPH_WIFI_MODULE:
-    // case PERIPH_BT_MODULE:
-    // case PERIPH_WIFI_BT_COMMON_MODULE:
-    // case PERIPH_BT_BASEBAND_MODULE:
-    // case PERIPH_BT_LC_MODULE:
-    //      return SYSTEM_WIFI_CLK_EN_REG;
-
         case PERIPH_SARADC_MODULE:
             return PCR_SARADC_CONF_REG;
         case PERIPH_RMT_MODULE:
@@ -263,7 +231,7 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
 }
 
 static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph)
-{ // TODO: IDF-5713
+{
     switch (periph) {
         case PERIPH_SARADC_MODULE:
             return PCR_SARADC_CONF_REG;

+ 28 - 0
components/hal/esp32c6/include/hal/modem_lpcon_ll.h

@@ -216,6 +216,34 @@ static inline void modem_lpcon_ll_set_lp_apb_icg_bitmap(modem_lpcon_dev_t *hw, u
     hw->clk_conf_power_st.clk_lp_apb_st_map = bitmap;
 }
 
+__attribute__((always_inline))
+static inline void modem_lpcon_ll_reset_wifipwr(modem_lpcon_dev_t *hw)
+{
+    hw->rst_conf.rst_wifipwr = 1;
+    hw->rst_conf.rst_wifipwr = 0;
+}
+
+__attribute__((always_inline))
+static inline void modem_lpcon_ll_reset_coex(modem_lpcon_dev_t *hw)
+{
+    hw->rst_conf.rst_coex = 1;
+    hw->rst_conf.rst_coex = 0;
+}
+
+__attribute__((always_inline))
+static inline void modem_lpcon_ll_reset_i2c_master(modem_lpcon_dev_t *hw)
+{
+    hw->rst_conf.rst_i2c_mst = 1;
+    hw->rst_conf.rst_i2c_mst = 0;
+}
+
+__attribute__((always_inline))
+static inline void modem_lpcon_ll_reset_ble_rtc_timer(modem_lpcon_dev_t *hw)
+{
+    hw->rst_conf.rst_lp_timer = 1;
+    hw->rst_conf.rst_lp_timer = 0;
+}
+
 __attribute__((always_inline))
 static inline void modem_lpcon_ll_reset_all(modem_lpcon_dev_t *hw)
 {

+ 4 - 19
components/hal/esp32c6/include/hal/modem_syscon_ll.h

@@ -205,30 +205,15 @@ static inline void modem_syscon_ll_reset_zbmac(modem_syscon_dev_t *hw)
 }
 
 __attribute__((always_inline))
-static inline void modem_syscon_ll_reset_modem_ecb(modem_syscon_dev_t *hw)
+static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw)
 {
     hw->modem_rst_conf.rst_modem_ecb = 1;
-    hw->modem_rst_conf.rst_modem_ecb = 0;
-}
-
-__attribute__((always_inline))
-static inline void modem_syscon_ll_reset_modem_ccm(modem_syscon_dev_t *hw)
-{
     hw->modem_rst_conf.rst_modem_ccm = 1;
-    hw->modem_rst_conf.rst_modem_ccm = 0;
-}
-
-__attribute__((always_inline))
-static inline void modem_syscon_ll_reset_modem_bah(modem_syscon_dev_t *hw)
-{
     hw->modem_rst_conf.rst_modem_bah = 1;
-    hw->modem_rst_conf.rst_modem_bah = 0;
-}
-
-__attribute__((always_inline))
-static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw)
-{
     hw->modem_rst_conf.rst_modem_sec = 1;
+    hw->modem_rst_conf.rst_modem_ecb = 0;
+    hw->modem_rst_conf.rst_modem_ccm = 0;
+    hw->modem_rst_conf.rst_modem_bah = 0;
     hw->modem_rst_conf.rst_modem_sec = 0;
 }
 

+ 14 - 0
components/hal/esp32h2/include/hal/modem_lpcon_ll.h

@@ -96,6 +96,20 @@ static inline void modem_lpcon_ll_enable_fe_mem_force_clock(modem_lpcon_dev_t *h
     hw->clk_conf_force_on.clk_fe_mem_fo = en;
 }
 
+__attribute__((always_inline))
+static inline void modem_lpcon_ll_reset_coex(modem_lpcon_dev_t *hw)
+{
+    hw->rst_conf.rst_coex = 1;
+    hw->rst_conf.rst_coex = 0;
+}
+
+__attribute__((always_inline))
+static inline void modem_lpcon_ll_reset_i2c_master(modem_lpcon_dev_t *hw)
+{
+    hw->rst_conf.rst_i2c_mst = 1;
+    hw->rst_conf.rst_i2c_mst = 0;
+}
+
 __attribute__((always_inline))
 static inline void modem_lpcon_ll_reset_all(modem_lpcon_dev_t *hw)
 {

+ 4 - 19
components/hal/esp32h2/include/hal/modem_syscon_ll.h

@@ -151,30 +151,15 @@ static inline void modem_syscon_ll_reset_zbmac(modem_syscon_dev_t *hw)
 }
 
 __attribute__((always_inline))
-static inline void modem_syscon_ll_reset_modem_ecb(modem_syscon_dev_t *hw)
+static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw)
 {
     hw->modem_rst_conf.rst_modem_ecb = 1;
-    hw->modem_rst_conf.rst_modem_ecb = 0;
-}
-
-__attribute__((always_inline))
-static inline void modem_syscon_ll_reset_modem_ccm(modem_syscon_dev_t *hw)
-{
     hw->modem_rst_conf.rst_modem_ccm = 1;
-    hw->modem_rst_conf.rst_modem_ccm = 0;
-}
-
-__attribute__((always_inline))
-static inline void modem_syscon_ll_reset_modem_bah(modem_syscon_dev_t *hw)
-{
     hw->modem_rst_conf.rst_modem_bah = 1;
-    hw->modem_rst_conf.rst_modem_bah = 0;
-}
-
-__attribute__((always_inline))
-static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw)
-{
     hw->modem_rst_conf.rst_modem_sec = 1;
+    hw->modem_rst_conf.rst_modem_ecb = 0;
+    hw->modem_rst_conf.rst_modem_ccm = 0;
+    hw->modem_rst_conf.rst_modem_bah = 0;
     hw->modem_rst_conf.rst_modem_sec = 0;
 }