timer: Add helper for drivers using timebase fallback

This function is designed to be used when a timer used to be initialized by
the cpu (e.g. RISC-V timers), but now is initialized by dm_timer_init. In
such a case, the timer may prefer to use the clocks and clock-frequency
properties, but should be able to fall back on using the cpu's
timebase-frequency.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Rick Chen <rick@andestech.com>
This commit is contained in:
Sean Anderson 2020-09-28 10:52:22 -04:00 committed by Andes
parent c33efafaf9
commit 3576121687
2 changed files with 46 additions and 0 deletions

View file

@ -15,6 +15,21 @@
*/
int dm_timer_init(void);
/**
* timer_timebase_fallback() - Helper for timers using timebase fallback
* @dev: A timer partially-probed timer device
*
* This is a helper function designed for timers which need to fall back on the
* cpu's timebase. This function is designed to be called during the driver's
* probe(). If there is a clocks or clock-frequency property in the timer's
* binding, then it will be used. Otherwise, the timebase of the current cpu
* will be used. This is initialized by the cpu driver, and usually gotten from
* ``/cpus/timebase-frequency`` or ``/cpus/cpu@X/timebase-frequency``.
*
* Return: 0 if OK, or negative error code on failure
*/
int timer_timebase_fallback(struct udevice *dev);
/*
* timer_conv_64 - convert 32-bit counter value to 64-bit
*