diff --git a/drivers/timer/npcx_itim_timer.c b/drivers/timer/npcx_itim_timer.c index 3fbc9c95b0c..e1c83a29980 100644 --- a/drivers/timer/npcx_itim_timer.c +++ b/drivers/timer/npcx_itim_timer.c @@ -279,7 +279,31 @@ uint64_t sys_clock_cycle_get_64(void) return current; } -int sys_clock_driver_init(const struct device *dev) +/* Platform specific system timer functions */ +#if defined(CONFIG_PM) +void npcx_clock_capture_low_freq_timer(void) +{ + cyc_evt_enter_deep_idle = npcx_itim_evt_elapsed_cyc32(); +} + +void npcx_clock_compensate_system_timer(void) +{ + uint32_t cyc_evt_elapsed_in_deep = npcx_itim_evt_elapsed_cyc32() - + cyc_evt_enter_deep_idle; + + cyc_sys_compensated += ((uint64_t)cyc_evt_elapsed_in_deep * + sys_clock_hw_cycles_per_sec()) / EVT_CYCLES_PER_SEC; +} + +#if defined(CONFIG_SOC_POWER_MANAGEMENT_TRACE) +uint64_t npcx_clock_get_sleep_ticks(void) +{ + return cyc_sys_compensated / SYS_CYCLES_PER_TICK; +} +#endif /* CONFIG_SOC_POWER_MANAGEMENT_TRACE */ +#endif /* CONFIG_PM */ + +static int sys_clock_driver_init(const struct device *dev) { ARG_UNUSED(dev); int ret; @@ -360,27 +384,5 @@ int sys_clock_driver_init(const struct device *dev) return 0; } - -/* Platform specific systme timer functions */ -#if defined(CONFIG_PM) -void npcx_clock_capture_low_freq_timer(void) -{ - cyc_evt_enter_deep_idle = npcx_itim_evt_elapsed_cyc32(); -} - -void npcx_clock_compensate_system_timer(void) -{ - uint32_t cyc_evt_elapsed_in_deep = npcx_itim_evt_elapsed_cyc32() - - cyc_evt_enter_deep_idle; - - cyc_sys_compensated += ((uint64_t)cyc_evt_elapsed_in_deep * - sys_clock_hw_cycles_per_sec()) / EVT_CYCLES_PER_SEC; -} - -#if defined(CONFIG_SOC_POWER_MANAGEMENT_TRACE) -uint64_t npcx_clock_get_sleep_ticks(void) -{ - return cyc_sys_compensated / SYS_CYCLES_PER_TICK; -} -#endif /* CONFIG_SOC_POWER_MANAGEMENT_TRACE */ -#endif /* CONFIG_PM */ +SYS_INIT(sys_clock_driver_init, PRE_KERNEL_2, + CONFIG_SYSTEM_CLOCK_INIT_PRIORITY);