From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: Yao Zi <me@ziyao.cc>
Cc: alison.wang@nxp.com, angelo@kernel-space.org, trini@konsulko.com,
daniel@0x0f.com, jserv@ccns.ncku.edu.tw, eleanor15x@gmail.com,
u-boot@lists.denx.de
Subject: Re: [PATCH v3 2/6] timer: Add Goldfish timer driver
Date: Thu, 1 Jan 2026 00:15:42 +0800 [thread overview]
Message-ID: <aVVMLtqON6maL21n@google.com> (raw)
In-Reply-To: <aVTCZUacn68Nbg10@pie>
Hi Yao,
On Wed, Dec 31, 2025 at 06:27:49AM +0000, Yao Zi wrote:
> 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 <visitorckw@gmail.com>
> > ---
> > 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 <visitorckw@gmail.com>
> > + *
> > + * Goldfish Timer driver
> > + */
> > +
> > +#include <dm.h>
> > +#include <timer.h>
> > +#include <asm/io.h>
> > +#include <linux/errno.h>
> > +#include <goldfish_timer.h>
>
> Sort the headers?
My apologies, I should have remembered that.
I will sort the headers in the next version.
>
> > +/* 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).
Agreed.
I will add a comment explaining this.
>
> > + time = ((u64)high << 32) | low;
> > +
> > + return time;
> > +}
>
> With the header sorted,
>
> Reviewed-by: Yao Zi <me@ziyao.cc>
Thanks for the review!
Regards,
Kuan-Wei
next prev parent reply other threads:[~2025-12-31 17:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-30 16:01 [PATCH v3 0/6] m68k: Add support for QEMU virt machine Kuan-Wei Chiu
2025-12-30 16:01 ` [PATCH v3 1/6] serial: Add Goldfish TTY driver Kuan-Wei Chiu
2025-12-31 3:01 ` Yao Zi
2025-12-31 3:52 ` Daniel Palmer
2025-12-31 12:25 ` Heinrich Schuchardt
2025-12-31 16:18 ` Kuan-Wei Chiu
2025-12-30 16:01 ` [PATCH v3 2/6] timer: Add Goldfish timer driver Kuan-Wei Chiu
2025-12-31 3:49 ` Daniel Palmer
2025-12-31 6:27 ` Yao Zi
2025-12-31 16:15 ` Kuan-Wei Chiu [this message]
2025-12-30 16:01 ` [PATCH v3 3/6] rtc: goldfish: Support platform data for non-DT probing Kuan-Wei Chiu
2025-12-31 12:12 ` Heinrich Schuchardt
2025-12-31 16:23 ` Kuan-Wei Chiu
2025-12-30 16:01 ` [PATCH v3 4/6] m68k: Add support for M68040 CPU Kuan-Wei Chiu
2025-12-30 16:01 ` [PATCH v3 5/6] board: Add QEMU m68k virt board support Kuan-Wei Chiu
2025-12-31 3:59 ` Daniel Palmer
2025-12-30 16:01 ` [PATCH v3 6/6] CI: Add test jobs for QEMU m68k virt machine Kuan-Wei Chiu
2025-12-30 16:09 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aVVMLtqON6maL21n@google.com \
--to=visitorckw@gmail.com \
--cc=alison.wang@nxp.com \
--cc=angelo@kernel-space.org \
--cc=daniel@0x0f.com \
--cc=eleanor15x@gmail.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=me@ziyao.cc \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox