[PATCH 04/10] timer: cadence-ttc: Add timer_early functions

Simon Glass sjg at chromium.org
Wed Sep 28 03:54:51 CEST 2022


On Mon, 26 Sept 2022 at 08:11, Stefan Roese <sr at denx.de> wrote:
>
> Hi Simon,
> Hi Michal,
>
> On 25.09.22 16:15, Simon Glass wrote:
> > Hi Stefan,
> >
> > On Wed, 21 Sept 2022 at 08:06, Stefan Roese <sr at denx.de> wrote:
> >>
> >> Currently this timer driver provides timer_get_boot_us() to support the
> >> BOOTSTAGE functionality. This patch adds the timer_early functions so
> >> that the "normal" timer functions can be used, when CONFIG_TIMER_EARLY
> >> is enabled.
> >>
> >> timer_get_boot_us() will get removed in a follow-up patch, once the
> >> BOOTSTAGE interface is migrated to timer_get_us().
> >>
> >> Signed-off-by: Stefan Roese <sr at denx.de>
> >> Cc: Michal Simek <michal.simek at xilinx.com>
> >> ---
> >>   drivers/timer/cadence-ttc.c | 25 +++++++++++++++++++++++++
> >>   1 file changed, 25 insertions(+)
> >>
> >> diff --git a/drivers/timer/cadence-ttc.c b/drivers/timer/cadence-ttc.c
> >> index 2eff45060ad6..e26c7923a140 100644
> >> --- a/drivers/timer/cadence-ttc.c
> >> +++ b/drivers/timer/cadence-ttc.c
> >> @@ -58,6 +58,31 @@ ulong timer_get_boot_us(void)
> >>   }
> >>   #endif
> >>
> >> +unsigned long notrace timer_early_get_rate(void)
> >> +{
> >> +       return 1;
> >> +}
> >> +
> >> +u64 notrace timer_early_get_count(void)
> >> +{
> >> +       u64 ticks = 0;
> >> +       u32 rate = 1;
> >> +       u64 us;
> >> +       int ret;
> >> +
> >> +       ret = dm_timer_init();
> >
> > I don't think you can call this if you want to support bootstage,
> > since driver model may not be inited.
>
> Yes, thanks for noticing. Still, this code is copied from the original
> timer_get_boot_us() function in this driver. Which also has problems
> with early timer access AFAICT.

Yes, good point.

Reviewed-by: Simon Glass <sjg at chromium.org>

>
> Michal, you are the author of the timer_get_boot_us() implementation
> in commit 56c0e646c4f6a ("timer: cadence: Implement timer_get_boot_us").
> How is this supposed to work in the early boot phase, before DM is
> initialized?
>
> Thanks,
> Stefan
>
> >> +       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;
> >> +}
> >> +
> >>   static u64 cadence_ttc_get_count(struct udevice *dev)
> >>   {
> >>          struct cadence_ttc_priv *priv = dev_get_priv(dev);
> >> --
> >> 2.37.3
> >>
> >
> > REgards,
> > Simon

Regards,
Simon


More information about the U-Boot mailing list