Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4170C6FA89 for ; Thu, 15 Sep 2022 14:22:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8F91184849; Thu, 15 Sep 2022 16:21:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1663251682; bh=4LROs2CQiINVlo6MsJAQBpOZcvZ07y6WctyG3ppf/Oc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HObHOl5XlJVX8zCXye124T7x2tlRnGGPpd0JkfbJhcgAe094fIRo8tXhuxk7kFiki D2tYm9U2BZvIQsdtmxpyh0NJQaBl3DzvJh0owGOKvIpKq7vqV21WBNUz7TK+ffZPtP wjoT4L/+zRFFA/vHV6DbD7AfqA69rbb74Eu7kt64wF87Yi5ldLL6jGjSLkdKGmamtg fyLjPh5Z5rXw9twHyw2fsCVWBugB2BPK8QCZT62RMwEkQT0P8ml4hrOsA2iBUu8P0F aBTK/+c+IPbqSjhVo4ED9e9m1jKVyStm7458DmN42IgUgCDJO3TukD5Y6VIt8zXFaX fasRpLDID3o6Q== Received: by phobos.denx.de (Postfix, from userid 109) id 70A5A84BE0; Thu, 15 Sep 2022 16:21:06 +0200 (CEST) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [IPv6:2001:67c:2050:101:465::204]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5D79984B7A for ; Thu, 15 Sep 2022 16:20:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4MSzrY30VHz9sSJ; Thu, 15 Sep 2022 16:20:45 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: pali@kernel.org, mibodhi@gmail.com, michael@walle.cc Subject: [PATCH v3 3/8] timer: orion-timer: Add timer_get_boot_us() for BOOTSTAGE support Date: Thu, 15 Sep 2022 16:20:38 +0200 Message-Id: <20220915142043.1549061-4-sr@denx.de> In-Reply-To: <20220915142043.1549061-1-sr@denx.de> References: <20220915142043.1549061-1-sr@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4MSzrY30VHz9sSJ X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Add timer_get_boot_us() to support boards, that have CONFIG_BOOTSTAGE enabled, like pogo_v4. Signed-off-by: Stefan Roese Tested-by: Tony Dinh --- v3: - Also support fixed input clock in early timer code - Consolidate code for this v2: - Change timer_get_boot_us() to use the timer_early functions - Remove #if CONFIG_IS_ENABLED(BOOTSTAGE) drivers/timer/orion-timer.c | 83 ++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/drivers/timer/orion-timer.c b/drivers/timer/orion-timer.c index 14f318e57d4d..cd63ea916237 100644 --- a/drivers/timer/orion-timer.c +++ b/drivers/timer/orion-timer.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include #include +#include #include #include #include @@ -22,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; } /** @@ -36,14 +81,25 @@ 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); } -static uint64_t orion_timer_get_count(struct udevice *dev) +ulong timer_get_boot_us(void) +{ + u64 ticks; + + ticks = timer_early_get_count(); + return lldiv(ticks * 1000, timer_early_get_rate()); +} + +/* 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) @@ -58,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[] = { -- 2.37.3