@@ -224,6 +224,7 @@ static void rtc_clk_cpu_freq_to_cpll_mhz(int cpu_freq_mhz, hal_utils_clk_div_t *
224224 uint32_t mem_divider = 1 ;
225225 uint32_t sys_divider = 1 ; // We are not going to change this
226226 uint32_t apb_divider = 1 ;
227+ #if CONFIG_ESP32P4_SELECTS_REV_LESS_V2
227228 switch (cpu_freq_mhz ) {
228229 case 360 :
229230 mem_divider = 2 ;
@@ -244,6 +245,28 @@ static void rtc_clk_cpu_freq_to_cpll_mhz(int cpu_freq_mhz, hal_utils_clk_div_t *
244245 // To avoid such case, we will strictly do abort here.
245246 abort ();
246247 }
248+ #else
249+ switch (cpu_freq_mhz ) {
250+ case 400 :
251+ mem_divider = 2 ;
252+ apb_divider = 2 ;
253+ break ;
254+ case 200 :
255+ mem_divider = 1 ;
256+ apb_divider = 2 ;
257+ break ;
258+ case 100 :
259+ mem_divider = 1 ;
260+ apb_divider = 1 ;
261+ break ;
262+ default :
263+ // Unsupported configuration
264+ // This is dangerous to modify dividers. Hardware could automatically correct the divider, and it won't be
265+ // reflected to the registers. Therefore, you won't even be able to calculate out the real mem_clk, apb_clk freq.
266+ // To avoid such case, we will strictly do abort here.
267+ abort ();
268+ }
269+ #endif
247270
248271 // If it's upscaling, the divider of MEM/SYS/APB needs to be increased, to avoid illegal intermediate states,
249272 // the clock divider should be updated in the order from the APB_CLK to CPU_CLK.
@@ -289,14 +312,14 @@ bool rtc_clk_cpu_freq_mhz_to_config(uint32_t freq_mhz, rtc_cpu_freq_config_t *ou
289312
290313 // Keep default CPLL at 360MHz
291314 uint32_t xtal_freq = (uint32_t )rtc_clk_xtal_freq_get ();
315+ #if CONFIG_ESP32P4_SELECTS_REV_LESS_V2
292316 if (freq_mhz <= xtal_freq && freq_mhz != 0 ) {
293317 divider .integer = xtal_freq / freq_mhz ;
294318 real_freq_mhz = (xtal_freq + divider .integer / 2 ) / divider .integer ; /* round */
295319 if (real_freq_mhz != freq_mhz ) {
296320 // no suitable divider
297321 return false;
298322 }
299-
300323 source_freq_mhz = xtal_freq ;
301324 source = SOC_CPU_CLK_SRC_XTAL ;
302325 } else if (freq_mhz == 90 ) {
@@ -314,6 +337,30 @@ bool rtc_clk_cpu_freq_mhz_to_config(uint32_t freq_mhz, rtc_cpu_freq_config_t *ou
314337 source = SOC_CPU_CLK_SRC_CPLL ;
315338 source_freq_mhz = CLK_LL_PLL_360M_FREQ_MHZ ;
316339 divider .integer = 1 ;
340+ } else {
341+ // unsupported frequency
342+ return false;
343+ }
344+ #else
345+ if (freq_mhz <= xtal_freq && freq_mhz != 0 ) {
346+ divider .integer = xtal_freq / freq_mhz ;
347+ real_freq_mhz = (xtal_freq + divider .integer / 2 ) / divider .integer ; /* round */
348+ if (real_freq_mhz != freq_mhz ) {
349+ // no suitable divider
350+ return false;
351+ }
352+ source_freq_mhz = xtal_freq ;
353+ source = SOC_CPU_CLK_SRC_XTAL ;
354+ } else if (freq_mhz == 100 ) {
355+ real_freq_mhz = freq_mhz ;
356+ source = SOC_CPU_CLK_SRC_CPLL ;
357+ source_freq_mhz = CLK_LL_PLL_400M_FREQ_MHZ ;
358+ divider .integer = 4 ;
359+ } else if (freq_mhz == 200 ) {
360+ real_freq_mhz = freq_mhz ;
361+ source = SOC_CPU_CLK_SRC_CPLL ;
362+ source_freq_mhz = CLK_LL_PLL_400M_FREQ_MHZ ;
363+ divider .integer = 2 ;
317364 } else if (freq_mhz == 400 ) {
318365 // If CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ selects 400MHz, then at app startup stage will need a CPLL calibration to raise its freq from 360MHz to 400MHz
319366 real_freq_mhz = freq_mhz ;
@@ -324,6 +371,7 @@ bool rtc_clk_cpu_freq_mhz_to_config(uint32_t freq_mhz, rtc_cpu_freq_config_t *ou
324371 // unsupported frequency
325372 return false;
326373 }
374+ #endif
327375 * out_config = (rtc_cpu_freq_config_t ) {
328376 .source = source ,
329377 .div = divider ,
0 commit comments