From dcdbda5c93bedbce202e2f55903a7f52dd4f84f6 Mon Sep 17 00:00:00 2001 From: Bo-Chen Chen Date: Thu, 18 Aug 2022 18:28:27 +0800 Subject: [PATCH] soc/mediatek/mt8188: Use MHz as unit for current_clk The unit of current_clk in pmif_ulposc_check() should be MHz. We use pmif_get_ulposc_freq_mhz() to get the default hardware value in MHz. Without this modification, the judgement in pmif_ulposc_check() is alway wrong due to the wrong unit. TEST=build pass. BUG=b:233720142 Signed-off-by: Bo-Chen Chen Change-Id: I3bf80a23bb35ff657023eb4b7e009fa233f61244 Reviewed-on: https://review.coreboot.org/c/coreboot/+/66971 Tested-by: build bot (Jenkins) Reviewed-by: Yu-Ping Wu --- src/soc/mediatek/common/pmif_clk.c | 4 ++-- src/soc/mediatek/mt8188/include/soc/pmif.h | 1 + src/soc/mediatek/mt8188/pmif_clk.c | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/soc/mediatek/common/pmif_clk.c b/src/soc/mediatek/common/pmif_clk.c index b7f2228a76..cfd1dbce6b 100644 --- a/src/soc/mediatek/common/pmif_clk.c +++ b/src/soc/mediatek/common/pmif_clk.c @@ -10,13 +10,13 @@ int pmif_ulposc_check(u32 current_clk, u32 target_clk) if (current_clk < (target_clk * (1000 - CAL_TOL_RATE) / 1000) || current_clk > (target_clk * (1000 + CAL_TOL_RATE) / 1000)) { printk(BIOS_WARNING, - "[%s] calibration fail: cur=%d, CAL_RATE=%d, target=%dM\n", + "[%s] calibration fail: cur=%dM, CAL_RATE=%d, target=%dM\n", __func__, current_clk, CAL_TOL_RATE, target_clk); return -1; } printk(BIOS_DEBUG, - "[%s] calibration done: cur=%d, CAL_RATE=%d, target=%dM\n", + "[%s] calibration done: cur=%dM, CAL_RATE=%d, target=%dM\n", __func__, current_clk, CAL_TOL_RATE, target_clk); return 0; diff --git a/src/soc/mediatek/mt8188/include/soc/pmif.h b/src/soc/mediatek/mt8188/include/soc/pmif.h index bc4f136c79..3cb8f3505f 100644 --- a/src/soc/mediatek/mt8188/include/soc/pmif.h +++ b/src/soc/mediatek/mt8188/include/soc/pmif.h @@ -138,5 +138,6 @@ enum { }; #define FREQ_METER_ABIST_AD_OSC_CK 42 +#define CALI_DEFAULT_CAP_VALUE 0x3d #endif /*__MT8188_SOC_PMIF_H__*/ diff --git a/src/soc/mediatek/mt8188/pmif_clk.c b/src/soc/mediatek/mt8188/pmif_clk.c index e292ba186a..aac9b7b696 100644 --- a/src/soc/mediatek/mt8188/pmif_clk.c +++ b/src/soc/mediatek/mt8188/pmif_clk.c @@ -123,8 +123,13 @@ int pmif_clk_init(void) { u32 ulposc1; - ulposc1 = mt_fmeter_get_freq_khz(FMETER_ABIST, FREQ_METER_ABIST_AD_OSC_CK); + /* check hardware default value first */ + ulposc1 = pmif_get_ulposc_freq_mhz(CALI_DEFAULT_CAP_VALUE); if (pmif_ulposc_check(ulposc1, FREQ_260MHZ)) { + /* + * If the hardware value is not what we want, we need to adjust + * it by the software setting. + */ pmif_clockmonitor_config(false); if (pmif_init_ulposc()) return E_NODEV;