clocksource/drivers/timer-atmel-tcb: Fix initialization on SAM9 hardware
authorRonald Wahl <ronald.wahl@raritan.com>
Sat, 7 Oct 2023 16:17:13 +0000 (18:17 +0200)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Fri, 13 Oct 2023 10:56:50 +0000 (12:56 +0200)
commit6d3bc4c02d59996d1d3180d8ed409a9d7d5900e0
treeffcd0e92cfdd26fe3a8db7a8200663130ce84d30
parentd7f546c751e8c873302331af6a203ee61f894e9d
clocksource/drivers/timer-atmel-tcb: Fix initialization on SAM9 hardware

On SAM9 hardware two cascaded 16 bit timers are used to form a 32 bit
high resolution timer that is used as scheduler clock when the kernel
has been configured that way (CONFIG_ATMEL_CLOCKSOURCE_TCB).

The driver initially triggers a reset-to-zero of the two timers but this
reset is only performed on the next rising clock. For the first timer
this is ok - it will be in the next 60ns (16MHz clock). For the chained
second timer this will only happen after the first timer overflows, i.e.
after 2^16 clocks (~4ms with a 16MHz clock). So with other words the
scheduler clock resets to 0 after the first 2^16 clock cycles.

It looks like that the scheduler does not like this and behaves wrongly
over its lifetime, e.g. some tasks are scheduled with a long delay. Why
that is and if there are additional requirements for this behaviour has
not been further analysed.

There is a simple fix for resetting the second timer as well when the
first timer is reset and this is to set the ATMEL_TC_ASWTRG_SET bit in
the Channel Mode register (CMR) of the first timer. This will also rise
the TIOA line (clock input of the second timer) when a software trigger
respective SYNC is issued.

Signed-off-by: Ronald Wahl <ronald.wahl@raritan.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20231007161803.31342-1-rwahl@gmx.de
drivers/clocksource/timer-atmel-tcb.c