| 
									
										
										
										
											2021-11-06 17:24:45 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-03-14 16:27:29 +08:00
										 |  |  |  * SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD | 
					
						
							| 
									
										
										
										
											2021-11-06 17:24:45 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: Apache-2.0 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | #include "sdkconfig.h"
 | 
					
						
							|  |  |  | #include "soc/soc.h"
 | 
					
						
							| 
									
										
										
										
											2023-07-12 15:21:40 +08:00
										 |  |  | #include "esp_private/periph_ctrl.h"
 | 
					
						
							| 
									
										
										
										
											2020-08-27 19:12:00 +10:00
										 |  |  | #ifndef CONFIG_IDF_TARGET_ESP32
 | 
					
						
							|  |  |  | #include "soc/system_reg.h"
 | 
					
						
							|  |  |  | #endif // not CONFIG_IDF_TARGET_ESP32
 | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | #include "soc/rtc.h"
 | 
					
						
							| 
									
										
										
										
											2022-07-12 20:42:28 +08:00
										 |  |  | #if CONFIG_IDF_TARGET_ESP32
 | 
					
						
							|  |  |  | #include "esp32/rom/rtc.h"
 | 
					
						
							|  |  |  | #elif CONFIG_IDF_TARGET_ESP32S2
 | 
					
						
							|  |  |  | #include "esp32s2/rom/rtc.h"
 | 
					
						
							|  |  |  | #elif CONFIG_IDF_TARGET_ESP32S3
 | 
					
						
							|  |  |  | #include "esp32s3/rom/rtc.h"
 | 
					
						
							|  |  |  | #elif CONFIG_IDF_TARGET_ESP32C3
 | 
					
						
							|  |  |  | #include "esp32c3/rom/rtc.h"
 | 
					
						
							|  |  |  | #elif CONFIG_IDF_TARGET_ESP32C2
 | 
					
						
							|  |  |  | #include "esp32c2/rom/rtc.h"
 | 
					
						
							|  |  |  | #elif CONFIG_IDF_TARGET_ESP32C6
 | 
					
						
							|  |  |  | #include "esp32c6/rom/rtc.h"
 | 
					
						
							| 
									
										
										
										
											2023-01-30 16:37:20 +08:00
										 |  |  | #include "esp_private/esp_pmu.h"
 | 
					
						
							| 
									
										
										
										
											2024-03-14 16:27:29 +08:00
										 |  |  | #elif CONFIG_IDF_TARGET_ESP32C61
 | 
					
						
							|  |  |  | #include "esp32c61/rom/rtc.h"
 | 
					
						
							|  |  |  | #include "esp_private/esp_pmu.h"
 | 
					
						
							| 
									
										
										
										
											2022-12-06 13:46:03 +08:00
										 |  |  | #elif CONFIG_IDF_TARGET_ESP32H2
 | 
					
						
							|  |  |  | #include "esp32h2/rom/rtc.h"
 | 
					
						
							| 
									
										
										
										
											2023-07-21 12:36:57 +08:00
										 |  |  | #elif CONFIG_IDF_TARGET_ESP32P4
 | 
					
						
							|  |  |  | #include "esp32p4/rom/rtc.h"
 | 
					
						
							| 
									
										
										
										
											2024-03-13 16:58:13 +08:00
										 |  |  | #elif CONFIG_IDF_TARGET_ESP32C5
 | 
					
						
							|  |  |  | #include "esp32c5/rom/rtc.h"
 | 
					
						
							| 
									
										
										
										
											2022-07-12 20:42:28 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | #include "esp_log.h"
 | 
					
						
							|  |  |  | #include "esp_rom_sys.h"
 | 
					
						
							|  |  |  | #include "esp_rom_uart.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-05 10:42:19 +08:00
										 |  |  | static const char *TAG = "fpga_clk"; | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void s_warn(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-12-05 10:42:19 +08:00
										 |  |  |     ESP_EARLY_LOGE(TAG, "Project configuration is for internal FPGA use, clock functions will not work"); | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void bootloader_clock_configure(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     s_warn(); | 
					
						
							| 
									
										
										
										
											2024-01-17 17:19:49 +08:00
										 |  |  |     esp_rom_output_tx_wait_idle(0); | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     uint32_t xtal_freq_mhz = 40; | 
					
						
							|  |  |  | #ifdef CONFIG_IDF_TARGET_ESP32S2
 | 
					
						
							|  |  |  |     uint32_t apb_freq_hz = 20000000; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2022-07-12 20:42:28 +08:00
										 |  |  |     uint32_t apb_freq_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 1000000; | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | #endif // CONFIG_IDF_TARGET_ESP32S2
 | 
					
						
							| 
									
										
										
										
											2023-04-19 11:54:57 +08:00
										 |  |  |     esp_rom_set_cpu_ticks_per_us(apb_freq_hz / 1000000); | 
					
						
							| 
									
										
										
										
											2020-11-06 10:21:25 +11:00
										 |  |  | #ifdef RTC_APB_FREQ_REG
 | 
					
						
							|  |  |  |     REG_WRITE(RTC_APB_FREQ_REG, (apb_freq_hz >> 12) | ((apb_freq_hz >> 12) << 16)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2022-07-12 20:42:28 +08:00
										 |  |  |     REG_WRITE(RTC_XTAL_FREQ_REG, (xtal_freq_mhz) | ((xtal_freq_mhz) << 16)); | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void esp_clk_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     s_warn(); | 
					
						
							| 
									
										
										
										
											2023-01-30 16:37:20 +08:00
										 |  |  | #if SOC_PMU_SUPPORTED
 | 
					
						
							|  |  |  |     pmu_init(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void esp_perip_clk_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @brief No-op function, used to force linking this file | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2023-12-05 10:42:19 +08:00
										 |  |  | void esp_common_include_fpga_overrides_clk(void) | 
					
						
							| 
									
										
										
										
											2021-01-26 13:12:54 +08:00
										 |  |  | { | 
					
						
							|  |  |  | } |