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 <rex-bc.chen@mediatek.com>
Change-Id: I40136eaeb2c08a97cd65bfb8a81f2f24739d4d51
Reviewed-on: https://review.coreboot.org/c/coreboot/+/65841
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Rex-BC Chen
2022-07-14 14:15:43 +08:00
committed by Felix Held
parent b9c1ce67a5
commit 823dcea39c
2 changed files with 19 additions and 8 deletions

View File

@@ -3,6 +3,7 @@
#ifndef __MEDIATEK_SOC_PMIF_CLK_COMMON__ #ifndef __MEDIATEK_SOC_PMIF_CLK_COMMON__
#define __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); int pmif_ulposc_cali(u32 target_val);
#endif /*__MEDIATEK_SOC_PMIF_CLK_COMMON__*/ #endif /*__MEDIATEK_SOC_PMIF_CLK_COMMON__*/

View File

@@ -5,6 +5,23 @@
#include <soc/pmif_clk_common.h> #include <soc/pmif_clk_common.h>
#include <soc/pmif_sw.h> #include <soc/pmif_sw.h>
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) int pmif_ulposc_cali(u32 target_val)
{ {
u32 current_val, min = 0, max = CAL_MAX_VAL, middle; 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); current_val = pmif_get_ulposc_freq_mhz(cal_result);
/* check if calibrated value is in the range of target value +- 15% */ /* check if calibrated value is in the range of target value +- 15% */
if (current_val < (target_val * (1000 - CAL_TOL_RATE) / 1000) || return pmif_ulposc_check(current_val, target_val);
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;
} }