summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2019-06-23 21:17:53 +0800
committerCommit Bot <commit-bot@chromium.org>2019-06-24 06:45:15 +0000
commit406fb2c7181f0dcf25d4a8d0626af2fca8c01f93 (patch)
tree12774ddd23879f7aec391a434cb8d5b3122ff1f3 /chip
parentb337f7bb6ca74776c2e35e019ba8d43b710cb360 (diff)
downloadchrome-ec-406fb2c7181f0dcf25d4a8d0626af2fca8c01f93.tar.gz
chip/mt_scp/clock: Move ULPOSC1/2 frequency settings to clock_chip.h
Refactor the code to make it easier for hrtimer to use ULPOSC1 frequency. BRANCH=none BUG=b:134035444 TEST=make BOARD=kukui_scp -j && \ bash board/kukui_scp/update_scp $IP powerd_dbus_suspend Change-Id: Ic1a7eab0f9075bf77c1b17ace9e3e95bee2924df Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1672656 Reviewed-by: Yilun Lin <yllin@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/mt_scp/clock.c22
-rw-r--r--chip/mt_scp/clock_chip.h9
2 files changed, 16 insertions, 15 deletions
diff --git a/chip/mt_scp/clock.c b/chip/mt_scp/clock.c
index d9c654b8b2..579db68dd3 100644
--- a/chip/mt_scp/clock.c
+++ b/chip/mt_scp/clock.c
@@ -16,14 +16,6 @@
#define CPRINTF(format, args...) cprintf(CC_CLOCK, format, ## args)
-/* Default ULPOSC clock speed in Hz */
-#ifndef ULPOSC1_CLOCK_HZ
-#define ULPOSC1_CLOCK_HZ 250000000
-#endif
-#ifndef ULPOSC2_CLOCK_HZ
-#define ULPOSC2_CLOCK_HZ 330000000
-#endif
-
#define ULPOSC_DIV_MAX (1 << OSC_DIV_BITS)
#define ULPOSC_CALI_MAX (1 << OSC_CALI_BITS)
@@ -182,13 +174,13 @@ static int scp_ulposc_config_measure(int osc, int div, int cali)
* Calibrate ULPOSC to target frequency.
*
* @param osc 0:ULPOSC1, 1:ULPOSC2
- * @param target_hz Target frequency to set
+ * @param target_mhz Target frequency to set
* @return Frequency counter output
*
*/
-static int scp_calibrate_ulposc(int osc, int target_hz)
+static int scp_calibrate_ulposc(int osc, int target_mhz)
{
- int target_freq = target_hz / (26 * 1000);
+ int target_freq = target_mhz * 1000 / 26;
struct ulposc {
int div; /* frequency divisor/multiplier */
int cali; /* variable resistor calibrator */
@@ -311,8 +303,8 @@ void scp_enable_clock(void)
scp_clock_high_enable(1); /* Turn on ULPOSC2 */
/* Calibrate ULPOSC */
- scp_calibrate_ulposc(0, ULPOSC1_CLOCK_HZ);
- scp_calibrate_ulposc(1, ULPOSC2_CLOCK_HZ);
+ scp_calibrate_ulposc(0, ULPOSC1_CLOCK_MHZ);
+ scp_calibrate_ulposc(1, ULPOSC2_CLOCK_MHZ);
/* Select ULPOSC2 high speed CPU clock */
SCP_CLK_SEL = CLK_SEL_ULPOSC_2;
@@ -342,8 +334,8 @@ DECLARE_IRQ(SCP_IRQ_CLOCK2, clock_fast_wakeup_irq, 3);
int command_ulposc(int argc, char *argv[])
{
if (argc > 1 && !strncmp(argv[1], "cal", 3)) {
- scp_calibrate_ulposc(0, ULPOSC1_CLOCK_HZ);
- scp_calibrate_ulposc(1, ULPOSC2_CLOCK_HZ);
+ scp_calibrate_ulposc(0, ULPOSC1_CLOCK_MHZ);
+ scp_calibrate_ulposc(1, ULPOSC2_CLOCK_MHZ);
}
/* SCP clock meter counts every (26MHz / 1000) tick */
diff --git a/chip/mt_scp/clock_chip.h b/chip/mt_scp/clock_chip.h
index 7d9bd0f0e7..fe27d5914f 100644
--- a/chip/mt_scp/clock_chip.h
+++ b/chip/mt_scp/clock_chip.h
@@ -8,8 +8,17 @@
#ifndef __CROS_EC_CLOCK_CHIP_H
#define __CROS_EC_CLOCK_CHIP_H
+#include "common.h"
#include "registers.h"
+/* Default ULPOSC clock speed in MHz */
+#ifndef ULPOSC1_CLOCK_MHZ
+#define ULPOSC1_CLOCK_MHZ 250
+#endif
+#ifndef ULPOSC2_CLOCK_MHZ
+#define ULPOSC2_CLOCK_MHZ 330
+#endif
+
void scp_enable_clock(void);
#endif /* __CROS_EC_CLOCK_CHIP_H */