
On 2022/9/21 22:06, Stefan Roese wrote:
Currently this timer driver provides timer_get_boot_us() to support the BOOTSTAGE functionality. This patch adds the timer_early functions so that the "normal" timer functions can be used, when CONFIG_TIMER_EARLY is enabled.
timer_get_boot_us() will get removed in a follow-up patch, once the BOOTSTAGE interface is migrated to timer_get_us().
Signed-off-by: Stefan Roese sr@denx.de Cc: Kever Yang kever.yang@rock-chips.com Cc: Philipp Tomsich philipp.tomsich@theobroma-systems.com
Reviewed-by: Kever Yang kever.yang@rock-chips.com
Thanks, - Kever
drivers/timer/rockchip_timer.c | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
diff --git a/drivers/timer/rockchip_timer.c b/drivers/timer/rockchip_timer.c index 62eacb986890..6e3483edce72 100644 --- a/drivers/timer/rockchip_timer.c +++ b/drivers/timer/rockchip_timer.c @@ -87,6 +87,56 @@ ulong timer_get_boot_us(void) } #endif
+static u64 timer_early_get_count_rate(uint32_t *rate) +{
- uint64_t ticks = 0;
- *rate = 1;
- if (CONFIG_IS_ENABLED(OF_REAL)) {
/* We have been called so early that the DM is not ready,... */
ofnode node = offset_to_ofnode(-1);
struct rk_timer *timer = NULL;
/*
* ... so we try to access the raw timer, if it is specified
* via the tick-timer property in /chosen.
*/
node = ofnode_get_chosen_node("tick-timer");
if (!ofnode_valid(node)) {
debug("%s: no /chosen/tick-timer\n", __func__);
return 0;
}
timer = (struct rk_timer *)ofnode_get_addr(node);
/* This timer is down-counting */
ticks = ~0ULL - rockchip_timer_get_curr_value(timer);
if (ofnode_read_u32(node, "clock-frequency", rate)) {
debug("%s: could not read clock-frequency\n", __func__);
return 0;
}
- } else {
return 0;
- }
- return ticks;
+}
+unsigned long notrace timer_early_get_rate(void) +{
- uint32_t rate;
- timer_early_get_count_rate(&rate);
- return rate;
+}
+u64 notrace timer_early_get_count(void) +{
- uint32_t rate;
- return timer_early_get_count_rate(&rate);
+}
- static u64 rockchip_timer_get_count(struct udevice *dev) { struct rockchip_timer_priv *priv = dev_get_priv(dev);