[PATCH v2 13/16] timer: Add loongarch_timer driver
Simon Glass
sjg at chromium.org
Thu Jul 2 12:27:04 CEST 2026
Hi Yao,
On 2026-07-01T11:17:53, Yao Zi <me at ziyao.cc> wrote:
> timer: Add loongarch_timer driver
>
> Implement a timer driver for LoongArch architecture driver.
>
> It's synced in hardware for every core in a system, and frequency
> information can be gathered from CPUCFG instruction.
>
> It is not described in fdt, thus I have to declare a DRVINFO
> for it.
>
> Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
> Signed-off-by: Yao Zi <me at ziyao.cc>
>
> drivers/timer/Kconfig | 8 +++
> drivers/timer/Makefile | 1 +
> drivers/timer/loongarch_timer.c | 112 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 121 insertions(+)
> diff --git a/drivers/timer/loongarch_timer.c b/drivers/timer/loongarch_timer.c
> @@ -0,0 +1,112 @@
> +#include <dm.h>
> +#include <errno.h>
> +#include <timer.h>
> +#include <asm/loongarch.h>
lldiv() is used below but div64.h is not included. Please add it
(see riscv_timer.c).
> diff --git a/drivers/timer/loongarch_timer.c b/drivers/timer/loongarch_timer.c
> @@ -0,0 +1,112 @@
> +static int loongarch_timer_bind(struct udevice *dev)
> +{
> + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> + u32 rate;
> +
> + rate = loongarch_timer_get_freq_cpucfg();
> + uc_priv->clock_rate = rate;
> +
> + return 0;
> +}
This is wired up as .probe below, so please rename to
loongarch_timer_probe(). Also, if loongarch_timer_get_freq_cpucfg()
returns 0 (LLFTP not present, or CPUCFG5 reads back zero) the driver
still probes with clock_rate=0, which then trips a divide-by-zero
in timer_get_boot_us(). Perhaps return -EINVAL in that case?
> diff --git a/drivers/timer/loongarch_timer.c b/drivers/timer/loongarch_timer.c
> @@ -0,0 +1,112 @@
> + /* Below is converted from time(us) = (tick / rate) * 10000000 */
> + return lldiv(ticks * 1000, (rate / 1000));
This comment is copied from riscv_timer.c and has the same typo -
us is 10^6, not 10^7. Worth fixing here (or factoring the helper
out so both architectures share it).
Regards,
Simon
More information about the U-Boot
mailing list