@@ -339,17 +339,28 @@ void pmu_sleep_shutdown_dcdc(void) {
339339 pmu_ll_hp_set_regulator_dbias (& PMU , PMU_MODE_HP_ACTIVE , HP_CALI_ACTIVE_DBIAS_DEFAULT );
340340}
341341
342- void pmu_sleep_enable_dcdc (void ) {
342+ FORCE_INLINE_ATTR void pmu_sleep_enable_dcdc (void ) {
343343 CLEAR_PERI_REG_MASK (LP_SYSTEM_REG_SYS_CTRL_REG , LP_SYSTEM_REG_LP_FIB_DCDC_SWITCH ); //0: enable, 1: disable
344344 SET_PERI_REG_MASK (PMU_DCM_CTRL_REG , PMU_DCDC_ON_REQ );
345345 REG_SET_FIELD (PMU_HP_ACTIVE_BIAS_REG , PMU_HP_ACTIVE_DCM_VSET , HP_CALI_ACTIVE_DCM_VSET_DEFAULT );
346346}
347347
348- void pmu_sleep_shutdown_ldo (void ) {
348+ FORCE_INLINE_ATTR void pmu_sleep_shutdown_ldo (void ) {
349349 CLEAR_PERI_REG_MASK (LP_SYSTEM_REG_SYS_CTRL_REG , LP_SYSTEM_REG_LP_FIB_DCDC_SWITCH ); //0: enable, 1: disable
350350 CLEAR_PERI_REG_MASK (PMU_HP_ACTIVE_HP_REGULATOR0_REG , PMU_HP_ACTIVE_HP_REGULATOR_XPD );
351351}
352352
353+ FORCE_INLINE_ATTR void pmu_sleep_cache_sync_items (uint32_t gid , uint32_t type , uint32_t map , uint32_t addr , uint32_t bytes )
354+ {
355+ REG_WRITE (CACHE_SYNC_ADDR_REG , addr );
356+ REG_WRITE (CACHE_SYNC_SIZE_REG , bytes );
357+ REG_WRITE (CACHE_SYNC_MAP_REG , map );
358+ REG_SET_FIELD (CACHE_SYNC_CTRL_REG , CACHE_SYNC_RGID , gid );
359+ REG_SET_BIT (CACHE_SYNC_CTRL_REG , type );
360+ while (!REG_GET_BIT (CACHE_SYNC_CTRL_REG , CACHE_SYNC_DONE ))
361+ ;
362+ }
363+
353364static TCM_DRAM_ATTR uint32_t s_mpll_freq_mhz_before_sleep = 0 ;
354365
355366TCM_IRAM_ATTR uint32_t pmu_sleep_start (uint32_t wakeup_opt , uint32_t reject_opt , uint32_t lslp_mem_inf_fpu , bool dslp )
@@ -364,11 +375,12 @@ TCM_IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt,
364375 pmu_ll_hp_clear_reject_intr_status (PMU_instance ()-> hal -> dev );
365376 pmu_ll_hp_clear_reject_cause (PMU_instance ()-> hal -> dev );
366377
367- // For the sleep where powered down the TOP domain, the L1 cache data memory will be lost and needs to be written back here.
368- // For the sleep without power down the TOP domain, regdma retention may still be enabled, and dirty data in the L1 cache needs
369- // to be written back so that regdma can get the correct link. So we always need to write back to L1 DCache here.
370- // !!! Need to manually check that data in L2 memory will not be modified from now on. !!!
371- Cache_WriteBack_All (CACHE_MAP_L1_DCACHE );
378+ // 1. For the sleep where powered down the TOP domain, the L1 cache data memory will be lost and needs to be written back here.
379+ // 2. For the sleep without power down the TOP domain, regdma retention may still be enabled, and dirty data in the L1 cache needs
380+ // to be written back so that regdma can get the correct link.
381+ // 3. We cannot use the API provided by ROM to invalidate the cache, since it is a function calling that writes data to the stack during
382+ // the return process, which results in dirty cachelines in L1 Cache again.
383+ pmu_sleep_cache_sync_items (SMMU_GID_DEFAULT , CACHE_SYNC_WRITEBACK , CACHE_MAP_L1_DCACHE , 0 , 0 );
372384
373385#if CONFIG_SPIRAM
374386 psram_ctrlr_ll_wait_all_transaction_done ();
0 commit comments