On Tue, Dec 30, 2025 at 04:01:08PM +0000, Kuan-Wei Chiu wrote: > Add support for the Goldfish timer driver. This driver utilizes the > Goldfish RTC hardware to provide a nanosecond-resolution timer. This > virtual device is commonly found in QEMU virtual machines (such as the > m68k virt machine) and Android emulators. > > The driver implements the standard U-Boot timer UCLASS interface, > exposing a 64-bit monotonically increasing counter with a 1GHz clock > rate derived from the RTC registers. > > Signed-off-by: Kuan-Wei Chiu <[email protected]> > --- > Changes in v3: > - New patch. > > The link provided by Daniel [1] returned a 404 error. > Since the implementation is straightforward, I wrote this driver from > scratch. > > [1]: > https://github.com/fifteenhex/u-boot/blob/mc68000/drivers/rtc/goldfish_timer.c
... > diff --git a/drivers/timer/goldfish_timer.c b/drivers/timer/goldfish_timer.c > new file mode 100644 > index 00000000000..8205ac77853 > --- /dev/null > +++ b/drivers/timer/goldfish_timer.c > @@ -0,0 +1,60 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (C) 2025, Kuan-Wei Chiu <[email protected]> > + * > + * Goldfish Timer driver > + */ > + > +#include <dm.h> > +#include <timer.h> > +#include <asm/io.h> > +#include <linux/errno.h> > +#include <goldfish_timer.h> Sort the headers? > +/* Goldfish RTC registers used as Timer */ > +#define TIMER_TIME_LOW 0x00 > +#define TIMER_TIME_HIGH 0x04 > + > +static u64 goldfish_timer_get_count(struct udevice *dev) > +{ > + struct goldfish_timer_plat *plat = dev_get_plat(dev); > + u32 low, high; > + u64 time; > + > + /* > + * Goldfish RTC provides time in nanoseconds. > + * We read the high 32-bits and low 32-bits to construct the 64-bit > value. > + */ > + low = readl(plat->base + TIMER_TIME_LOW); > + high = readl(plat->base + TIMER_TIME_HIGH); It may be worth a comment to point out that the value of TIMER_TIME_HIGH only updates when TIMER_TIME_LOW is read, so it's impossible to read out teared values (higher half has been updated after lower half is read). > + time = ((u64)high << 32) | low; > + > + return time; > +} With the header sorted, Reviewed-by: Yao Zi <[email protected]> Regards, Yao Zi

