u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: Stefan Roese <sr@denx.de>
Cc: "Michael Walle" <michael@walle.cc>,
	"U-Boot Mailing List" <u-boot@lists.denx.de>,
	"Pali Rohár" <pali@kernel.org>, "Tony Dinh" <mibodhi@gmail.com>
Subject: Re: [PATCH 2/6] timer: orion-timer: Add timer_get_boot_us() for BOOTSTAGE support
Date: Tue, 30 Aug 2022 09:56:59 -0600	[thread overview]
Message-ID: <CAPnjgZ0et2ZankP+=C37z7z9PYBF2BkO2JxWo_XDe1ZLRXup3A@mail.gmail.com> (raw)
In-Reply-To: <57f2671c-3841-74ec-b6c0-2c7aff3c3239@denx.de>

Hi Stefan,

On Tue, 30 Aug 2022 at 06:08, Stefan Roese <sr@denx.de> wrote:
>
> Adding Simon to Cc...
>
> On 30.08.22 14:00, Michael Walle wrote:
> > Am 2022-08-30 13:53, schrieb Stefan Roese:
> >> Add timer_get_boot_us() to support boards, that have CONFIG_BOOTSTAGE
> >> enabled, like pogo_v4.
> >>
> >> Signed-off-by: Stefan Roese <sr@denx.de>
> >> ---
> >>  drivers/timer/orion-timer.c | 22 ++++++++++++++++++++++
> >>  1 file changed, 22 insertions(+)
> >>
> >> diff --git a/drivers/timer/orion-timer.c b/drivers/timer/orion-timer.c
> >> index 02ed138642b8..7e920eaeaa40 100644
> >> --- a/drivers/timer/orion-timer.c
> >> +++ b/drivers/timer/orion-timer.c
> >> @@ -41,6 +41,28 @@ u64 notrace timer_early_get_count(void)
> >>  }
> >>  #endif
> >>
> >> +#if CONFIG_IS_ENABLED(BOOTSTAGE)
> >> +ulong timer_get_boot_us(void)
> >> +{
> >> +    u64 ticks = 0;
> >> +    u32 rate = 1;
> >> +    u64 us;
> >> +    int ret;
> >> +
> >> +    ret = dm_timer_init();
> >> +    if (!ret) {
> >> +        /* The timer is available */
> >> +        rate = timer_get_rate(gd->timer);
> >> +        timer_get_count(gd->timer, &ticks);
> >> +    } else {
> >> +        return 0;
> >> +    }
> >> +
> >> +    us = (ticks * 1000) / rate;
> >> +    return us;
> >> +}
> >> +#endif
> >
> > This is duplicate code in almost all the timer drivers, shouldn't
> > this be a (weak) default implementation in timer-uclass.c?
>
> Yes. I was lazy and just copied this function and did not notice, that
> even more timer drivers have this function. Of course it makes sense
> to not duplicate code here, but have a common function for this. Frankly
> I don't even know why exactly this function is needed, as I did not
> look into BOOTSTAGE yet.
>
> Simon, do we really need this function? Can't bootstage just use the
> "normal" timer functionality instead?

It is needed because bootstage is called before driver model is ready.
In fact it can be used to time driver model things.

The function here isn't that useful, since we cannot call
dm_timer_init() before driver model is set up.

The timer_get_boot_us() function can by in a timer driver, but must
exist outside the driver infrastructure. It must init the hard and
then return the correct time. One driver model probes the timer
driver, it must then continue on in that way.

Actually it looks like all the timers do this wrong. See
arch/arm/mach-imx/syscounter.c or arch/arm/cpu/armv8/generic_timer.c
for some ideas.

>
> > Also,
> > do you need to guard it with CONFIG_IS_ENABLED(BOOTSTAGE), aren't
> > unused functions discarded anyway?
>
> Yes, this should be the case. Also just a result of my lazy copy-and-
> past.
>

Regards,
SImon

  reply	other threads:[~2022-08-30 15:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 11:53 [PATCH 0/6] Enable CONFIG_TIMER for all Kirwood / MVEBU boards Stefan Roese
2022-08-30 11:53 ` [PATCH 1/6] timer: orion-timer: Add support for other Armada SoC's Stefan Roese
2022-08-30 11:53 ` [PATCH 2/6] timer: orion-timer: Add timer_get_boot_us() for BOOTSTAGE support Stefan Roese
2022-08-30 12:00   ` Michael Walle
2022-08-30 12:08     ` Stefan Roese
2022-08-30 15:56       ` Simon Glass [this message]
2022-08-31  5:57         ` Stefan Roese
2022-08-31 17:44           ` Simon Glass
2022-09-01  5:33             ` Stefan Roese
2022-08-30 11:53 ` [PATCH 3/6] arm: mvebu: Use CONFIG_TIMER on all MVEBU & KIRKWOOD platforms Stefan Roese
2022-08-30 12:04   ` Michael Walle
2022-08-30 12:11     ` Stefan Roese
2022-08-30 11:53 ` [PATCH 4/6] arm: mvebu: dts: Makefile: Compile Armada 375 dtb in a separate step Stefan Roese
2022-08-30 11:53 ` [PATCH 5/6] arm: mvebu: dts: armada-375.dtsi: Add timer0 & timer1 Stefan Roese
2022-08-30 11:53 ` [PATCH 6/6] arm: mvebu: dts: mvebu-u-boot.dtsi: Add "u-boot, dm-pre-reloc" to timer DT node Stefan Roese
2022-08-30 22:15 ` [PATCH 0/6] Enable CONFIG_TIMER for all Kirwood / MVEBU boards Tony Dinh
2022-08-31  5:02   ` Stefan Roese
2022-08-31  5:08     ` Stefan Roese
2022-08-31  6:12       ` Stefan Roese
2022-08-31  6:45         ` Tony Dinh
2022-08-31  6:30       ` Tony Dinh
2022-08-31  7:22         ` Stefan Roese
2022-08-31 15:08           ` Tony Dinh
2022-08-31 21:53             ` Tony Dinh
2022-09-01  1:38               ` Tony Dinh
2022-09-01  2:27                 ` Simon Glass
2022-09-01  7:39                   ` Tony Dinh
2022-09-01  9:27                     ` Stefan Roese
2022-09-01 11:52                       ` Stefan Herbrechtsmeier
2022-09-02  5:38                         ` Stefan Roese
2022-09-01 14:34                       ` Simon Glass
2022-09-01 23:46                         ` Tony Dinh
2022-09-02  2:51                           ` Tony Dinh
2022-09-02  3:49                             ` Tony Dinh

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='CAPnjgZ0et2ZankP+=C37z7z9PYBF2BkO2JxWo_XDe1ZLRXup3A@mail.gmail.com' \
    --to=sjg@chromium.org \
    --cc=mibodhi@gmail.com \
    --cc=michael@walle.cc \
    --cc=pali@kernel.org \
    --cc=sr@denx.de \
    --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;
as well as URLs for NNTP newsgroup(s).