summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2019-06-22 21:02:35 +0800
committerCommit Bot <commit-bot@chromium.org>2019-06-24 06:45:16 +0000
commit5d4f631acf5ef95a8893d3f91512ed549f105ec0 (patch)
tree29095a2766ce5e9fa832936962a4e1becae1f224
parent406fb2c7181f0dcf25d4a8d0626af2fca8c01f93 (diff)
downloadchrome-ec-5d4f631acf5ef95a8893d3f91512ed549f105ec0.tar.gz
chip/mt_scp/clock: Fix frequency meter divider (1024, not 1000)
The frequency meter measures at 26 Mhz / 1024, not 26 Mhz / 1000, and use DIV_ROUND_CLOSEST to get a closer frequency meter target. Also, print the frequencies in kHz, not Mhz. BRANCH=none BUG=b:120176040 TEST=Add new timer sourced from (precise) 32.768 kHz to tick every second, see that the interval is close to a second. Change-Id: I32a9265187ed2936a928f2c09da8f544d814b5ae Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1672650 Reviewed-by: Yilun Lin <yllin@chromium.org>
-rw-r--r--chip/mt_scp/clock.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/chip/mt_scp/clock.c b/chip/mt_scp/clock.c
index 579db68dd3..8214f5ae15 100644
--- a/chip/mt_scp/clock.c
+++ b/chip/mt_scp/clock.c
@@ -127,8 +127,8 @@ static unsigned int scp_measure_ulposc_freq(int osc)
AP_SCP_CFG_0 |= CFG_FREQ_METER_RUN;
/*
- * Frequency meter counts cycles in 1 / (26 * 1000) second period.
- * freq_in_hz = freq_counter * 26 * 1000
+ * Frequency meter counts cycles in 1 / (26 * 1024) second period.
+ * freq_in_hz = freq_counter * 26 * 1024
*
* The hardware takes 38us to count cycles. Delay up to 100us,
* as busy_udelay may not be accurate when sysclk is not 26Mhz
@@ -163,9 +163,9 @@ static int scp_ulposc_config_measure(int osc, int div, int cali)
scp_ulposc_config(osc, div, cali);
freq = scp_measure_ulposc_freq(osc);
- CPRINTF("ULPOSC%d: %d %d %d (%dMHz)\n",
+ CPRINTF("ULPOSC%d: %d %d %d (%dkHz)\n",
osc + 1, div, cali, freq,
- freq * 26 / 1000);
+ freq * 26 * 1000 / 1024);
return freq;
}
@@ -180,7 +180,7 @@ static int scp_ulposc_config_measure(int osc, int div, int cali)
*/
static int scp_calibrate_ulposc(int osc, int target_mhz)
{
- int target_freq = target_mhz * 1000 / 26;
+ int target_freq = DIV_ROUND_NEAREST(target_mhz * 1024, 26);
struct ulposc {
int div; /* frequency divisor/multiplier */
int cali; /* variable resistor calibrator */
@@ -338,11 +338,11 @@ int command_ulposc(int argc, char *argv[])
scp_calibrate_ulposc(1, ULPOSC2_CLOCK_MHZ);
}
- /* SCP clock meter counts every (26MHz / 1000) tick */
- ccprintf("ULPOSC1 frequency: %u MHz\n",
- scp_measure_ulposc_freq(0) * 26 / 1000);
- ccprintf("ULPOSC2 frequency: %u MHz\n",
- scp_measure_ulposc_freq(1) * 26 / 1000);
+ /* SCP clock meter counts every (26MHz / 1024) tick */
+ ccprintf("ULPOSC1 frequency: %u kHz\n",
+ scp_measure_ulposc_freq(0) * 26 * 1000 / 1024);
+ ccprintf("ULPOSC2 frequency: %u kHz\n",
+ scp_measure_ulposc_freq(1) * 26 * 1000 / 1024);
return EC_SUCCESS;
}