driver: timer: npcx_itim: Add timer initialization

The init responsibility moves to the drivers themselves. The npcx itim
initialize doesn't work now. This adds timer initialization for npcx
itim to fix it.

Signed-off-by: Wealian Liao <WHLIAO@nuvoton.com>
This commit is contained in:
Wealian Liao 2021-12-06 15:44:45 +08:00 committed by Maureen Helm
commit 3cdf684cd9

View file

@ -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);