Re: [PATCH v2 2/5] clocksource/drivers/spacemit: Add K1 timer support

From: Philipp Zabel

Date: Tue Nov 17 2026 - 04:52:32 EST


On Di, 2026-11-17 at 09:45 +0000, Troy Mitchell wrote:
> SpacemiT K1 and K3 have APB timers that can provide a shared clockevent
> alongside the per-CPU RISC-V timer. Use counter 0 and its first match
> comparator as a oneshot device available to the tick broadcast framework.
>
> Counter enable changes cross clock domains. Wait for the synchronized
> counter value to stop changing before reprogramming the match register,
> and check interrupt acknowledgment through the status register rather
> than reading the write-only clear register. Bound all synchronization
> waits and propagate programming failures to the clockevent core.
>
> Obtain the counter rate from the functional clock and protect it against
> rate changes. Keep the clocks enabled for the clockevent lifetime and
> restore counter configuration through the tick resume callback without
> sleeping clock operations. Use a platform driver so clock and reset
> providers can probe before the timer is registered.
>
> Signed-off-by: Troy Mitchell <troy.mitchell@xxxxxxxxxxxxxxxxxx>
> ---
> drivers/clocksource/Kconfig | 11 ++
> drivers/clocksource/Makefile | 1 +
> drivers/clocksource/timer-spacemit.c | 317 +++++++++++++++++++++++++++++++++++
> 3 files changed, 329 insertions(+)
>
> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
> index da83483296d5..3e7dd5d628cd 100644
> --- a/drivers/clocksource/Kconfig
> +++ b/drivers/clocksource/Kconfig
> @@ -163,6 +163,17 @@ config RZN1_TIMER
> - 2 32-bit timers
> Two timers blocks are available in RZ/N1 SoCs.
>
> +config SPACEMIT_TIMER
> + bool "SpacemiT K1/K3 timer"
> + depends on ARCH_SPACEMIT || COMPILE_TEST
> + depends on OF && COMMON_CLK && RESET_CONTROLLER && HAS_IOMEM

Drop the unnecessary RESET_CONTROLLER dependency, the reset controller
API has stubs for consumers.

regards
Philipp