Skip to content

Commit

Permalink
intel_adsp: timer: implemented sys_clock_idle_exit function
Browse files Browse the repository at this point in the history
Generic header for system clock allows to define a sys_clock_idle_exit
function for the clock implementation.
Implemented the function in the intel_adsp_timer to reinitialize
device driver after the idle exit state.
Redefined timer device using DEVICE_DT_INST_DEFINE to be able
to obtain device pointer for idle exit code.

Signed-off-by: Andrey Borisovich <andrey.borisovich@intel.com>
  • Loading branch information
Andrey Borisovich committed Mar 24, 2023
1 parent 95168e6 commit fc367d4
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions drivers/timer/intel_adsp_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <adsp_shim.h>
#include <adsp_interrupt.h>
#include <zephyr/irq.h>
#ifdef CONFIG_PM_DEVICE
#include <zephyr/pm/device.h>
#endif /* CONFIG_PM_DEVICE */

#define DT_DRV_COMPAT intel_adsp_timer

Expand Down Expand Up @@ -60,6 +63,12 @@ static uint64_t last_count;
const int32_t z_sys_timer_irq_for_test = TIMER_IRQ; /* See tests/kernel/context */
#endif

/**
* @brief Used to alternate driver initialization when initialized
* during boot or after idle state that restores context.
*/
static bool sys_clock_driver_reinit = false;

static void set_compare(uint64_t time)
{
/* Disarm the comparator to prevent spurious triggers */
Expand Down Expand Up @@ -217,13 +226,23 @@ void smp_timer_init(void)
static int sys_clock_driver_init(const struct device *dev)
{
uint64_t curr = count();

IRQ_CONNECT(TIMER_IRQ, 0, compare_isr, 0, 0);
if(!sys_clock_driver_reinit)
IRQ_CONNECT(TIMER_IRQ, 0, compare_isr, 0, 0);
set_compare(curr + CYC_PER_TICK);
last_count = curr;
irq_init();
return 0;
}

SYS_INIT(sys_clock_driver_init, PRE_KERNEL_2,
CONFIG_SYSTEM_CLOCK_INIT_PRIORITY);
#ifdef CONFIG_PM_DEVICE
void sys_clock_idle_exit(void)
{
pm_device_state_lock(DEVICE_DT_INST_GET(0));
sys_clock_driver_reinit = true;
sys_clock_driver_init(DEVICE_DT_INST_GET(0));
pm_device_state_unlock(DEVICE_DT_INST_GET(0));
}
#endif /* CONFIG_PM_DEVICE */

DEVICE_DT_INST_DEFINE(0, sys_clock_driver_init, NULL, NULL, NULL,
PRE_KERNEL_2, CONFIG_SYSTEM_CLOCK_INIT_PRIORITY, NULL);

0 comments on commit fc367d4

Please sign in to comment.