From 823dcea39ceb44e938ace8b40e0cca4244a052c5 Mon Sep 17 00:00:00 2001 From: Rex-BC Chen Date: Thu, 14 Jul 2022 14:15:43 +0800 Subject: soc/mediatek: Create a function to check ulposc We will use the same drivers for checking ulposc in MT8188, so we add a new function pmif_ulposc_check() to common. TEST=build pass BUG=b:233720142 Signed-off-by: Bo-Chen Chen Change-Id: I40136eaeb2c08a97cd65bfb8a81f2f24739d4d51 Reviewed-on: https://review.coreboot.org/c/coreboot/+/65841 Reviewed-by: Yu-Ping Wu Tested-by: build bot (Jenkins) --- .../mediatek/common/include/soc/pmif_clk_common.h | 1 + src/soc/mediatek/common/pmif_clk.c | 26 +++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/soc/mediatek/common') diff --git a/src/soc/mediatek/common/include/soc/pmif_clk_common.h b/src/soc/mediatek/common/include/soc/pmif_clk_common.h index f1bd2c7cf8..c61cd1a96e 100644 --- a/src/soc/mediatek/common/include/soc/pmif_clk_common.h +++ b/src/soc/mediatek/common/include/soc/pmif_clk_common.h @@ -3,6 +3,7 @@ #ifndef __MEDIATEK_SOC_PMIF_CLK_COMMON__ #define __MEDIATEK_SOC_PMIF_CLK_COMMON__ +int pmif_ulposc_check(u32 current_clk, u32 target_clk); int pmif_ulposc_cali(u32 target_val); #endif /*__MEDIATEK_SOC_PMIF_CLK_COMMON__*/ diff --git a/src/soc/mediatek/common/pmif_clk.c b/src/soc/mediatek/common/pmif_clk.c index 5b458a02c7..b7f2228a76 100644 --- a/src/soc/mediatek/common/pmif_clk.c +++ b/src/soc/mediatek/common/pmif_clk.c @@ -5,6 +5,23 @@ #include #include +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", + __func__, current_clk, CAL_TOL_RATE, target_clk); + return -1; + } + + printk(BIOS_DEBUG, + "[%s] calibration done: cur=%d, CAL_RATE=%d, target=%dM\n", + __func__, current_clk, CAL_TOL_RATE, target_clk); + + return 0; +} + int pmif_ulposc_cali(u32 target_val) { u32 current_val, min = 0, max = CAL_MAX_VAL, middle; @@ -32,12 +49,5 @@ int pmif_ulposc_cali(u32 target_val) current_val = pmif_get_ulposc_freq_mhz(cal_result); /* check if calibrated value is in the range of target value +- 15% */ - if (current_val < (target_val * (1000 - CAL_TOL_RATE) / 1000) || - current_val > (target_val * (1000 + CAL_TOL_RATE) / 1000)) { - printk(BIOS_ERR, "[%s] calibration fail: cur=%d, CAL_RATE=%d, target=%dM\n", - __func__, current_val, CAL_TOL_RATE, target_val); - return 1; - } - - return 0; + return pmif_ulposc_check(current_val, target_val); } -- cgit v1.2.3