summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@oss.qualcomm.com>2026-04-25 16:10:48 +0530
committerAnup Patel <anup@brainfault.org>2026-05-09 13:16:07 +0530
commit1932ee3f0ae2f200431c20018e2d75dbceb65695 (patch)
tree6ee68e4c69561126cd7ce2e37c5ac63a2f2b8f5a /lib
parentb7fa8a246cba80d74c0993dd0275b3c1589ef8b6 (diff)
downloadopensbi-1932ee3f0ae2f200431c20018e2d75dbceb65695.tar.gz
opensbi-1932ee3f0ae2f200431c20018e2d75dbceb65695.zip
lib: sbi_timer: Introduce sbi_timer_compute_delta() and friends
The users of timer event have to compute next_event (aka timer value in the future) based on desired units and unit frequency. Introduce sbi_timer_compute_delta() and friends to simplify computing next_event for timer event users. Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com> Reviewed-by: Nicholas Piggin <npiggin@gmail.com> Link: https://lore.kernel.org/r/20260425104048.2335262-5-anup.patel@oss.qualcomm.com Signed-off-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_timer.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c
index 70b8b5d2..4d737d22 100644
--- a/lib/sbi/sbi_timer.c
+++ b/lib/sbi/sbi_timer.c
@@ -58,6 +58,15 @@ static void nop_delay_fn(void *opaque)
cpu_relax();
}
+u64 sbi_timer_compute_delta(ulong units, u64 unit_freq)
+{
+ u64 delta;
+
+ delta = ((u64)timer_dev->timer_freq * (u64)units);
+ delta = delta / unit_freq;
+ return delta;
+}
+
void sbi_timer_delay_loop(ulong units, u64 unit_freq,
void (*delay_fn)(void *), void *opaque)
{
@@ -72,15 +81,12 @@ void sbi_timer_delay_loop(ulong units, u64 unit_freq,
/* Save starting timer value */
start_val = get_time_val();
- /* Compute desired timer value delta */
- delta = ((u64)timer_dev->timer_freq * (u64)units);
- delta = delta / unit_freq;
-
/* Use NOP delay function if delay function not available */
if (!delay_fn)
delay_fn = nop_delay_fn;
/* Busy loop until desired timer value delta reached */
+ delta = sbi_timer_compute_delta(units, unit_freq);
while ((get_time_val() - start_val) < delta)
delay_fn(opaque);
}