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