49
49
#include <esp_private/esp_pmu.h>
50
50
#include <esp_private/esp_modem_clock.h>
51
51
#include <ocode_init.h>
52
+ #elif defined(CONFIG_SOC_SERIES_ESP32H2 )
53
+ #define DT_CPU_COMPAT espressif_riscv
54
+ #include <zephyr/dt-bindings/clock/esp32h2_clock.h>
55
+ #include <soc/lpperi_reg.h>
56
+ #include <soc/lp_clkrst_reg.h>
57
+ #include <regi2c_ctrl.h>
58
+ #include <esp32h2/rom/rtc.h>
59
+ #include <soc/dport_access.h>
60
+ #include <hal/clk_tree_ll.h>
61
+ #include <hal/usb_serial_jtag_ll.h>
62
+ #include <esp_private/esp_pmu.h>
63
+ #include <esp_sleep.h>
52
64
#endif
53
65
54
66
#include <zephyr/drivers/clock_control.h>
@@ -85,10 +97,13 @@ static bool reset_reason_is_cpu_reset(void)
85
97
return false;
86
98
}
87
99
88
- #if defined(CONFIG_SOC_SERIES_ESP32C6 )
100
+ #if defined(CONFIG_SOC_SERIES_ESP32C6 ) || defined( CONFIG_SOC_SERIES_ESP32H2 )
89
101
static void esp32_clock_perip_init (void )
90
102
{
91
103
soc_rtc_slow_clk_src_t rtc_slow_clk_src = rtc_clk_slow_src_get ();
104
+ soc_reset_reason_t rst_reason = esp_rom_get_reset_reason (0 );
105
+
106
+ #if defined(CONFIG_SOC_SERIES_ESP32C6 )
92
107
modem_clock_lpclk_src_t modem_lpclk_src =
93
108
(modem_clock_lpclk_src_t )((rtc_slow_clk_src == SOC_RTC_SLOW_CLK_SRC_RC_SLOW )
94
109
? MODEM_CLOCK_LPCLK_SRC_RC_SLOW
@@ -101,19 +116,36 @@ static void esp32_clock_perip_init(void)
101
116
: MODEM_CLOCK_LPCLK_SRC_RC_SLOW );
102
117
103
118
modem_clock_select_lp_clock_source (PERIPH_WIFI_MODULE , modem_lpclk_src , 0 );
104
-
105
- soc_reset_reason_t rst_reason = esp_rom_get_reset_reason (0 );
119
+ #elif defined(CONFIG_SOC_SERIES_ESP32H2 )
120
+ esp_sleep_pd_domain_t pu_domain =
121
+ (esp_sleep_pd_domain_t )((rtc_slow_clk_src == SOC_RTC_SLOW_CLK_SRC_XTAL32K )
122
+ ? ESP_PD_DOMAIN_XTAL32K
123
+ : (rtc_slow_clk_src == SOC_RTC_SLOW_CLK_SRC_RC32K )
124
+ ? ESP_PD_DOMAIN_RC32K
125
+ : ESP_PD_DOMAIN_MAX );
126
+ esp_sleep_pd_config (pu_domain , ESP_PD_OPTION_ON );
127
+ #endif
106
128
107
129
if ((rst_reason != RESET_REASON_CPU0_MWDT0 ) && (rst_reason != RESET_REASON_CPU0_MWDT1 ) &&
108
130
(rst_reason != RESET_REASON_CPU0_SW ) && (rst_reason != RESET_REASON_CPU0_RTC_WDT )) {
109
131
132
+ #if CONFIG_ESP_CONSOLE_UART_NUM != 0
133
+ periph_ll_disable_clk_set_rst (PERIPH_UART0_MODULE );
134
+ #endif
135
+ #if CONFIG_ESP_CONSOLE_UART_NUM != 1
110
136
periph_ll_disable_clk_set_rst (PERIPH_UART1_MODULE );
137
+ #endif
111
138
periph_ll_disable_clk_set_rst (PERIPH_I2C0_MODULE );
139
+ #if defined(CONFIG_SOC_SERIES_ESP32H2 )
140
+ periph_ll_disable_clk_set_rst (PERIPH_I2C1_MODULE );
141
+ #endif
112
142
periph_ll_disable_clk_set_rst (PERIPH_RMT_MODULE );
113
143
periph_ll_disable_clk_set_rst (PERIPH_LEDC_MODULE );
114
144
periph_ll_disable_clk_set_rst (PERIPH_TIMG1_MODULE );
115
145
periph_ll_disable_clk_set_rst (PERIPH_TWAI0_MODULE );
146
+ #if defined(CONFIG_SOC_SERIES_ESP32C6 )
116
147
periph_ll_disable_clk_set_rst (PERIPH_TWAI1_MODULE );
148
+ #endif
117
149
periph_ll_disable_clk_set_rst (PERIPH_I2S1_MODULE );
118
150
periph_ll_disable_clk_set_rst (PERIPH_PCNT_MODULE );
119
151
periph_ll_disable_clk_set_rst (PERIPH_ETM_MODULE );
@@ -124,17 +156,24 @@ static void esp32_clock_perip_init(void)
124
156
periph_ll_disable_clk_set_rst (PERIPH_TEMPSENSOR_MODULE );
125
157
periph_ll_disable_clk_set_rst (PERIPH_UHCI0_MODULE );
126
158
periph_ll_disable_clk_set_rst (PERIPH_SARADC_MODULE );
159
+ #if defined(CONFIG_SOC_SERIES_ESP32C6 )
127
160
periph_ll_disable_clk_set_rst (PERIPH_SDIO_SLAVE_MODULE );
161
+ #endif
128
162
periph_ll_disable_clk_set_rst (PERIPH_RSA_MODULE );
129
163
periph_ll_disable_clk_set_rst (PERIPH_AES_MODULE );
130
164
periph_ll_disable_clk_set_rst (PERIPH_SHA_MODULE );
131
165
periph_ll_disable_clk_set_rst (PERIPH_ECC_MODULE );
132
166
periph_ll_disable_clk_set_rst (PERIPH_HMAC_MODULE );
133
167
periph_ll_disable_clk_set_rst (PERIPH_DS_MODULE );
168
+ #if defined(CONFIG_SOC_SERIES_ESP32H2 )
169
+ periph_ll_disable_clk_set_rst (PERIPH_ECDSA_MODULE );
170
+ #endif
134
171
135
172
REG_CLR_BIT (PCR_CTRL_TICK_CONF_REG , PCR_TICK_ENABLE );
136
173
REG_CLR_BIT (PCR_TRACE_CONF_REG , PCR_TRACE_CLK_EN );
174
+ #if defined(CONFIG_SOC_SERIES_ESP32C6 )
137
175
REG_CLR_BIT (PCR_RETENTION_CONF_REG , PCR_RETENTION_CLK_EN );
176
+ #endif
138
177
REG_CLR_BIT (PCR_MEM_MONITOR_CONF_REG , PCR_MEM_MONITOR_CLK_EN );
139
178
REG_CLR_BIT (PCR_PVT_MONITOR_CONF_REG , PCR_PVT_MONITOR_CLK_EN );
140
179
REG_CLR_BIT (PCR_PVT_MONITOR_FUNC_CLK_CONF_REG , PCR_PVT_MONITOR_FUNC_CLK_EN );
@@ -150,8 +189,9 @@ static void esp32_clock_perip_init(void)
150
189
(rst_reason == RESET_REASON_SYS_RTC_WDT ) ||
151
190
(rst_reason == RESET_REASON_SYS_SUPER_WDT )) {
152
191
192
+ #if defined(CONFIG_SOC_SERIES_ESP32C6 )
153
193
periph_ll_disable_clk_set_rst (PERIPH_LP_I2C0_MODULE );
154
-
194
+ #endif
155
195
CLEAR_PERI_REG_MASK (LPPERI_CLK_EN_REG , LPPERI_RNG_CK_EN );
156
196
CLEAR_PERI_REG_MASK (LPPERI_CLK_EN_REG , LPPERI_LP_UART_CK_EN );
157
197
CLEAR_PERI_REG_MASK (LPPERI_CLK_EN_REG , LPPERI_OTP_DBG_CK_EN );
@@ -544,7 +584,7 @@ static int clock_control_esp32_get_rate(const struct device *dev, clock_control_
544
584
545
585
static int esp32_select_rtc_slow_clk (uint8_t slow_clk )
546
586
{
547
- #if !defined(CONFIG_SOC_SERIES_ESP32C6 )
587
+ #if !defined(CONFIG_SOC_SERIES_ESP32C6 ) && !defined( CONFIG_SOC_SERIES_ESP32H2 )
548
588
soc_rtc_slow_clk_src_t rtc_slow_clk_src = slow_clk & RTC_CNTL_ANA_CLK_RTC_SEL_V ;
549
589
#else
550
590
soc_rtc_slow_clk_src_t rtc_slow_clk_src = slow_clk ;
@@ -600,7 +640,7 @@ static int esp32_select_rtc_slow_clk(uint8_t slow_clk)
600
640
return - ENODEV ;
601
641
}
602
642
}
603
- #if defined(CONFIG_SOC_SERIES_ESP32C6 )
643
+ #if defined(CONFIG_SOC_SERIES_ESP32C6 ) || defined( CONFIG_SOC_SERIES_ESP32H2 )
604
644
} else if (rtc_slow_clk_src == SOC_RTC_SLOW_CLK_SRC_RC32K ) {
605
645
rtc_clk_rc32k_enable (true);
606
646
}
@@ -642,11 +682,21 @@ static int esp32_cpu_clock_configure(const struct esp32_cpu_clock_config *cpu_cf
642
682
#if defined(CONFIG_SOC_SERIES_ESP32C6 )
643
683
rtc_clk_modem_clock_domain_active_state_icg_map_preinit ();
644
684
645
- REG_SET_FIELD (LP_CLKRST_FOSC_CNTL_REG , LP_CLKRST_FOSC_DFREQ , rtc_clk_cfg .clk_8m_dfreq );
646
685
REGI2C_WRITE_MASK (I2C_DIG_REG , I2C_DIG_REG_SCK_DCAP , rtc_clk_cfg .slow_clk_dcap );
647
- REG_SET_FIELD (LP_CLKRST_RC32K_CNTL_REG , LP_CLKRST_RC32K_DFREQ , rtc_clk_cfg .rc32k_dfreq );
648
686
REGI2C_WRITE_MASK (I2C_DIG_REG , I2C_DIG_REG_ENIF_RTC_DREG , 1 );
649
687
REGI2C_WRITE_MASK (I2C_DIG_REG , I2C_DIG_REG_ENIF_DIG_DREG , 1 );
688
+ #elif defined(CONFIG_SOC_SERIES_ESP32H2 )
689
+ REGI2C_WRITE_MASK (I2C_PMU , I2C_PMU_OC_SCK_DCAP , rtc_clk_cfg .slow_clk_dcap );
690
+ REGI2C_WRITE_MASK (I2C_PMU , I2C_PMU_EN_I2C_RTC_DREG , 0 );
691
+ REGI2C_WRITE_MASK (I2C_PMU , I2C_PMU_EN_I2C_DIG_DREG , 0 );
692
+ #else
693
+ REG_SET_FIELD (RTC_CNTL_REG , RTC_CNTL_SCK_DCAP , rtc_clk_cfg .slow_clk_dcap );
694
+ REG_SET_FIELD (RTC_CNTL_CLK_CONF_REG , RTC_CNTL_CK8M_DFREQ , rtc_clk_cfg .clk_8m_dfreq );
695
+ #endif
696
+
697
+ #if defined(CONFIG_SOC_SERIES_ESP32C6 ) || defined(CONFIG_SOC_SERIES_ESP32H2 )
698
+ REG_SET_FIELD (LP_CLKRST_FOSC_CNTL_REG , LP_CLKRST_FOSC_DFREQ , rtc_clk_cfg .clk_8m_dfreq );
699
+ REG_SET_FIELD (LP_CLKRST_RC32K_CNTL_REG , LP_CLKRST_RC32K_DFREQ , rtc_clk_cfg .rc32k_dfreq );
650
700
651
701
uint32_t hp_cali_dbias = get_act_hp_dbias ();
652
702
uint32_t lp_cali_dbias = get_act_lp_dbias ();
@@ -657,15 +707,11 @@ static int esp32_cpu_clock_configure(const struct esp32_cpu_clock_config *cpu_cf
657
707
hp_cali_dbias , PMU_HP_MODEM_HP_REGULATOR_DBIAS_S );
658
708
SET_PERI_REG_BITS (PMU_HP_SLEEP_LP_REGULATOR0_REG , PMU_HP_SLEEP_LP_REGULATOR_DBIAS ,
659
709
lp_cali_dbias , PMU_HP_SLEEP_LP_REGULATOR_DBIAS_S );
660
-
661
- #else
662
- REG_SET_FIELD (RTC_CNTL_REG , RTC_CNTL_SCK_DCAP , rtc_clk_cfg .slow_clk_dcap );
663
- REG_SET_FIELD (RTC_CNTL_CLK_CONF_REG , RTC_CNTL_CK8M_DFREQ , rtc_clk_cfg .clk_8m_dfreq );
664
710
#endif
665
711
666
712
#if defined(CONFIG_SOC_SERIES_ESP32 )
667
713
REG_SET_FIELD (RTC_CNTL_CLK_CONF_REG , RTC_CNTL_CK8M_DIV_SEL , rtc_clk_cfg .clk_8m_div - 1 );
668
- #elif defined(CONFIG_SOC_SERIES_ESP32C6 )
714
+ #elif defined(CONFIG_SOC_SERIES_ESP32C6 ) || defined( CONFIG_SOC_SERIES_ESP32H2 )
669
715
clk_ll_rc_fast_tick_conf ();
670
716
671
717
esp_rom_uart_tx_wait_idle (0 );
@@ -678,7 +724,7 @@ static int esp32_cpu_clock_configure(const struct esp32_cpu_clock_config *cpu_cf
678
724
rtc_clk_8m_divider_set (rtc_clk_cfg .clk_8m_clk_div );
679
725
#endif
680
726
681
- #if !defined(CONFIG_SOC_SERIES_ESP32C6 )
727
+ #if !defined(CONFIG_SOC_SERIES_ESP32C6 ) && !defined( CONFIG_SOC_SERIES_ESP32H2 )
682
728
/* Reset (disable) i2c internal bus for all regi2c registers */
683
729
regi2c_ctrl_ll_i2c_reset ();
684
730
/* Enable the internal bus used to configure BBPLL */
@@ -699,7 +745,7 @@ static int esp32_cpu_clock_configure(const struct esp32_cpu_clock_config *cpu_cf
699
745
* to make it run at 80MHz after the switch. PLL = 480MHz, so divider is 6.
700
746
*/
701
747
clk_ll_mspi_fast_set_hs_divider (6 );
702
- #else
748
+ #elif !defined( CONFIG_SOC_SERIES_ESP32H2 )
703
749
rtc_clk_apb_freq_update (rtc_clk_cfg .xtal_freq * MHZ (1 ));
704
750
#endif
705
751
@@ -719,7 +765,8 @@ static int esp32_cpu_clock_configure(const struct esp32_cpu_clock_config *cpu_cf
719
765
old_config .freq_mhz );
720
766
721
767
#if defined(CONFIG_ESP_CONSOLE_UART )
722
- #if !defined(CONFIG_SOC_SERIES_ESP32C2 ) && !defined(CONFIG_SOC_SERIES_ESP32C6 )
768
+ #if !defined(CONFIG_SOC_SERIES_ESP32C2 ) && !defined(CONFIG_SOC_SERIES_ESP32C6 ) && \
769
+ !defined(CONFIG_SOC_SERIES_ESP32H2 )
723
770
#if defined(CONFIG_MCUBOOT ) && defined(ESP_ROM_UART_CLK_IS_XTAL )
724
771
uint32_t uart_clock_src_hz = (uint32_t )rtc_clk_xtal_freq_get () * MHZ (1 );
725
772
#else
@@ -775,7 +822,9 @@ static int clock_control_esp32_init(const struct device *dev)
775
822
if (rst_reas == RESET_REASON_CHIP_POWER_ON ) {
776
823
esp_ocode_calib_init ();
777
824
}
778
- #else /* CONFIG_SOC_SERIES_ESP32C6 */
825
+ #elif defined(CONFIG_SOC_SERIES_ESP32H2 )
826
+ pmu_init ();
827
+ #else /* CONFIG_SOC_SERIES_ESP32C6 || CONFIG_SOC_SERIES_ESP32H2 */
779
828
rtc_config_t rtc_cfg = RTC_CONFIG_DEFAULT ();
780
829
781
830
#if !defined(CONFIG_SOC_SERIES_ESP32 )
@@ -788,7 +837,7 @@ static int clock_control_esp32_init(const struct device *dev)
788
837
}
789
838
#endif /* !CONFIG_SOC_SERIES_ESP32 */
790
839
rtc_init (rtc_cfg );
791
- #endif /* CONFIG_SOC_SERIES_ESP32C6 */
840
+ #endif /* CONFIG_SOC_SERIES_ESP32C6 || CONFIG_SOC_SERIES_ESP32H2 */
792
841
793
842
ret = esp32_cpu_clock_configure (& cfg -> cpu );
794
843
if (ret ) {
0 commit comments