lib/sbi/sbi_timer: Add sbi_timer_frequency() function

Drivers and other library code sometimes need the timer frequency
outside of lib/sbi/sbi_timer.c, but there is currently no accessor
for it. Add sbi_timer_frequency() to expose the frequency of the
registered timer device.

Signed-off-by: Sunil V L <sunilvl@oss.qualcomm.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260703050530.2460037-2-sunilvl@oss.qualcomm.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Sunil V L
2026-08-20 17:57:45 +05:30
committed by Anup Patel
parent 3876e7574d
commit 6499c02254
2 changed files with 15 additions and 0 deletions
+3
View File
@@ -140,6 +140,9 @@ bool sbi_timer_waitms_until(bool (*predicate)(void *), void *arg,
/** Get timer value for current HART */ /** Get timer value for current HART */
u64 sbi_timer_value(void); u64 sbi_timer_value(void);
/** Get timer frequency for current HART */
unsigned long sbi_timer_frequency(void);
/** Compute timer value after specified milliseconds */ /** Compute timer value after specified milliseconds */
static inline u64 sbi_timer_value_after_msecs(ulong msecs) static inline u64 sbi_timer_value_after_msecs(ulong msecs)
{ {
+12
View File
@@ -104,6 +104,18 @@ bool sbi_timer_waitms_until(bool (*predicate)(void *), void *arg,
return true; return true;
} }
unsigned long sbi_timer_frequency(void)
{
const struct sbi_timer_device *timer_dev = sbi_timer_get_device();
if (!timer_dev) {
sbi_printf("%s: called without timer device\n", __func__);
return 0;
}
return timer_dev->timer_freq;
}
u64 sbi_timer_value(void) u64 sbi_timer_value(void)
{ {
if (get_time_val) if (get_time_val)