All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: Tony Dinh <mibodhi@gmail.com>
Cc: "U-Boot Mailing List" <u-boot@lists.denx.de>,
	"Pali Rohár" <pali@kernel.org>,
	"Michael Walle" <michael@walle.cc>,
	"Simon Glass" <sjg@chromium.org>
Subject: Re: [PATCH v2 3/8] timer: orion-timer: Add timer_get_boot_us() for BOOTSTAGE support
Date: Sat, 3 Sep 2022 12:44:20 +0200	[thread overview]
Message-ID: <3e1fdcaf-2d9d-bcfb-3067-d8c723af52cb@denx.de> (raw)
In-Reply-To: <CAJaLiFzKT4ciSb2DdsDZBWQj_vgAVsi-GEqUKRF=82jB3ySnmg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1186 bytes --]

Hi Tony,

On 03.09.22 11:44, Tony Dinh wrote:
> Hi Stefan,
> 
> On Thu, Sep 1, 2022 at 11:25 PM Stefan Roese <sr@denx.de> wrote:
>>
>> Add timer_get_boot_us() to support boards, that have CONFIG_BOOTSTAGE
>> enabled, like pogo_v4.
>>
>> Signed-off-by: Stefan Roese <sr@denx.de>
>> ---
>> v2:
>> - Change timer_get_boot_us() to use the timer_early functions
>> - Remove #if CONFIG_IS_ENABLED(BOOTSTAGE)
>>
>> Simon, I'm currently looking into this timer_get_boot_us() to using
>> timer_early_get_count() etc consolidation.
> 
> Indeed, as you've mentioned above, I think timer_early_get_count() and
> timer_early_get_rate() do need to take into consideration  what the
> input_clock_type is for Kirkwood boards with CONFIG_BOOTSTAGE such as
> the Pogo V4.
> 
> I'm seeing on the Pogo V4 test, the timer command reports time about 6
> times slower than it should. It does seem to jive with the fact that
> the Pogo V4 CONFIG_SYS_TCLK is 166Mhz, versus MVEBU 25MHz clock rate.

Ah, I've missing updating the early functions to also differentiate
between fixed clocks and TCLK timer.

Please give the attached patch a try - should be applied on top of this
latest patchset.

Thanks,
Stefan

[-- Attachment #2: orion-timer-fix-early-init.patch --]
[-- Type: text/x-patch, Size: 3230 bytes --]

diff --git a/drivers/timer/orion-timer.c b/drivers/timer/orion-timer.c
index 6c0b8550412d..cd63ea916237 100644
--- a/drivers/timer/orion-timer.c
+++ b/drivers/timer/orion-timer.c
@@ -23,12 +23,56 @@ struct orion_timer_priv {
 
 #define MVEBU_TIMER_FIXED_RATE_25MHZ	25000000
 
+static bool early_init_done __section(".data") = false;
+
+/* Common functions for early (boot) and DM based timer */
+static void orion_timer_init(void *base, enum input_clock_type type)
+{
+	writel(~0, base + TIMER0_VAL);
+	writel(~0, base + TIMER0_RELOAD);
+
+	if (type == INPUT_CLOCK_25MHZ) {
+		/*
+		 * On Armada XP / 38x ..., the 25MHz clock source needs to
+		 * be enabled
+		 */
+		setbits_le32(base + TIMER_CTRL, BIT(11));
+	}
+
+	/* enable timer */
+	setbits_le32(base + TIMER_CTRL, TIMER0_EN | TIMER0_RELOAD_EN);
+}
+
+static uint64_t orion_timer_get_count(void *base)
+{
+	return timer_conv_64(~readl(base + TIMER0_VAL));
+}
+
+/* Early (e.g. bootstage etc) timer functions */
+static void notrace timer_early_init(void)
+{
+	/* Only init the timer once */
+	if (early_init_done)
+		return;
+	early_init_done = true;
+
+	if (IS_ENABLED(CONFIG_ARCH_MVEBU))
+		orion_timer_init((void *)MVEBU_TIMER_BASE, INPUT_CLOCK_25MHZ);
+	else
+		orion_timer_init((void *)MVEBU_TIMER_BASE, INPUT_CLOCK_NON_FIXED);
+}
+
 /**
  * timer_early_get_rate() - Get the timer rate before driver model
  */
 unsigned long notrace timer_early_get_rate(void)
 {
-	return MVEBU_TIMER_FIXED_RATE_25MHZ;
+	timer_early_init();
+
+	if (IS_ENABLED(CONFIG_ARCH_MVEBU))
+		return MVEBU_TIMER_FIXED_RATE_25MHZ;
+	else
+		return CONFIG_SYS_TCLK;
 }
 
 /**
@@ -37,7 +81,9 @@ unsigned long notrace timer_early_get_rate(void)
  */
 u64 notrace timer_early_get_count(void)
 {
-	return timer_conv_64(~readl(MVEBU_TIMER_BASE + TIMER0_VAL));
+	timer_early_init();
+
+	return orion_timer_get_count((void *)MVEBU_TIMER_BASE);
 }
 
 ulong timer_get_boot_us(void)
@@ -48,11 +94,12 @@ ulong timer_get_boot_us(void)
 	return lldiv(ticks * 1000, timer_early_get_rate());
 }
 
-static uint64_t orion_timer_get_count(struct udevice *dev)
+/* DM timer functions */
+static uint64_t dm_orion_timer_get_count(struct udevice *dev)
 {
 	struct orion_timer_priv *priv = dev_get_priv(dev);
 
-	return timer_conv_64(~readl(priv->base + TIMER0_VAL));
+	return orion_timer_get_count(priv->base);
 }
 
 static int orion_timer_probe(struct udevice *dev)
@@ -67,28 +114,17 @@ static int orion_timer_probe(struct udevice *dev)
 		return -ENOMEM;
 	}
 
-	writel(~0, priv->base + TIMER0_VAL);
-	writel(~0, priv->base + TIMER0_RELOAD);
-
-	if (type == INPUT_CLOCK_25MHZ) {
-		/*
-		 * On Armada XP / 38x ..., the 25MHz clock source needs to
-		 * be enabled
-		 */
-		setbits_le32(priv->base + TIMER_CTRL, BIT(11));
+	if (type == INPUT_CLOCK_25MHZ)
 		uc_priv->clock_rate = MVEBU_TIMER_FIXED_RATE_25MHZ;
-	} else {
+	else
 		uc_priv->clock_rate = CONFIG_SYS_TCLK;
-	}
-
-	/* enable timer */
-	setbits_le32(priv->base + TIMER_CTRL, TIMER0_EN | TIMER0_RELOAD_EN);
+	orion_timer_init(priv->base, type);
 
 	return 0;
 }
 
 static const struct timer_ops orion_timer_ops = {
-	.get_count = orion_timer_get_count,
+	.get_count = dm_orion_timer_get_count,
 };
 
 static const struct udevice_id orion_timer_ids[] = {

  reply	other threads:[~2022-09-03 10:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02  6:25 [PATCH v2 0/8] Enable CONFIG_TIMER for all Kirkwood / MVEBU boards Stefan Roese
2022-09-02  6:25 ` [PATCH v2 1/8] timer: orion-timer: Use timer_conv_64() to fix timer wrap around Stefan Roese
2022-09-02  7:44   ` Michael Walle
2022-09-02  7:45     ` Stefan Roese
2022-09-02  6:25 ` [PATCH v2 2/8] timer: orion-timer: Add support for other Armada SoC's Stefan Roese
2022-09-02  6:25 ` [PATCH v2 3/8] timer: orion-timer: Add timer_get_boot_us() for BOOTSTAGE support Stefan Roese
2022-09-03  9:44   ` Tony Dinh
2022-09-03 10:44     ` Stefan Roese [this message]
2022-09-03 23:43       ` Tony Dinh
2022-09-04  0:02         ` Tony Dinh
2022-09-04  0:38           ` Tony Dinh
2022-09-04  1:08             ` Pali Rohár
2022-09-04  2:36               ` Tony Dinh
2022-09-04  9:41                 ` Pali Rohár
2022-09-04  8:54           ` Michael Walle
2022-09-04 19:47             ` Tony Dinh
2022-09-02  6:25 ` [PATCH v2 4/8] arm: mvebu: Use CONFIG_TIMER on all MVEBU & KIRKWOOD platforms Stefan Roese
2022-09-02  6:25 ` [PATCH v2 5/8] arm: mvebu: dts: Makefile: Compile Armada 375 dtb in a separate step Stefan Roese
2022-09-02  6:25 ` [PATCH v2 6/8] arm: mvebu: dts: armada-375.dtsi: Add timer0 & timer1 Stefan Roese
2022-09-02  6:25 ` [PATCH v2 7/8] arm: mvebu: dts: mvebu-u-boot.dtsi: Add "u-boot, dm-pre-reloc" to timer DT node Stefan Roese
2022-09-02  6:25 ` [PATCH v2 8/8] kirkwood: lsxl: Sync defconfigs Stefan Roese
2022-09-03  0:10 ` [PATCH v2 0/8] Enable CONFIG_TIMER for all Kirkwood / MVEBU boards 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=3e1fdcaf-2d9d-bcfb-3067-d8c723af52cb@denx.de \
    --to=sr@denx.de \
    --cc=mibodhi@gmail.com \
    --cc=michael@walle.cc \
    --cc=pali@kernel.org \
    --cc=sjg@chromium.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.