From mboxrd@z Thu Jan 1 00:00:00 1970 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 63343C32771 for ; Wed, 21 Sep 2022 14:07:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 85D5984CB4; Wed, 21 Sep 2022 16:06:52 +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=1663769212; bh=K937KNmOy0I/Hi+at7YyniPLapKYxaLScDE45SpBlG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=rz1vraA85u+8iWwZXjLGxt2IZ4pMWuQlVgr3U+WQ6xqTreeSQ1W38oO4k6AVJQWN5 X6Pz2o+Nj1L/RMo5CSMix3/Ur0EV7CpKR6NgE3xRtAuGBtkZdvrdTix+057YP+5j8d CE198wV/CaqcBljlRCUdeex32AEssOxtpzfRF6kqNmMV3KuBRm5FwuzGMEYUC8MWAN AidmQYUclcV99yUvPtj0L618HkzPY2lTpfMxnvA9CFEZypj2LCGjcowY4k8jqnyefX MHaGSRIpJUJByNpPOxY7JacByXVnDPQEueJSRVQ4Ht3+JTAjHDYSJA9KEtZF7URtN/ /dOiVr7WEHKZQ== Received: by phobos.denx.de (Postfix, from userid 109) id 56994849BB; Wed, 21 Sep 2022 16:06:38 +0200 (CEST) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:101:465::107]) (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 7A4CC84CA0 for ; Wed, 21 Sep 2022 16:06:31 +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-107.mailbox.org (Postfix) with ESMTPS id 4MXgFK4dwDz9scZ; Wed, 21 Sep 2022 16:06:29 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: sjg@chromium.org, trini@konsulko.com, Kever Yang , Philipp Tomsich Subject: [PATCH 06/10] timer: rockchip_timer: Add timer_early functions Date: Wed, 21 Sep 2022 16:06:21 +0200 Message-Id: <20220921140625.999002-7-sr@denx.de> In-Reply-To: <20220921140625.999002-1-sr@denx.de> References: <20220921140625.999002-1-sr@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4MXgFK4dwDz9scZ 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 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 Cc: Kever Yang Cc: Philipp Tomsich --- drivers/timer/rockchip_timer.c | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/timer/rockchip_timer.c b/drivers/timer/rockchip_timer.c index 62eacb986890..6e3483edce72 100644 --- a/drivers/timer/rockchip_timer.c +++ b/drivers/timer/rockchip_timer.c @@ -87,6 +87,56 @@ ulong timer_get_boot_us(void) } #endif +static u64 timer_early_get_count_rate(uint32_t *rate) +{ + uint64_t ticks = 0; + + *rate = 1; + if (CONFIG_IS_ENABLED(OF_REAL)) { + /* We have been called so early that the DM is not ready,... */ + ofnode node = offset_to_ofnode(-1); + struct rk_timer *timer = NULL; + + /* + * ... so we try to access the raw timer, if it is specified + * via the tick-timer property in /chosen. + */ + node = ofnode_get_chosen_node("tick-timer"); + if (!ofnode_valid(node)) { + debug("%s: no /chosen/tick-timer\n", __func__); + return 0; + } + + timer = (struct rk_timer *)ofnode_get_addr(node); + + /* This timer is down-counting */ + ticks = ~0ULL - rockchip_timer_get_curr_value(timer); + if (ofnode_read_u32(node, "clock-frequency", rate)) { + debug("%s: could not read clock-frequency\n", __func__); + return 0; + } + } else { + return 0; + } + + return ticks; +} + +unsigned long notrace timer_early_get_rate(void) +{ + uint32_t rate; + + timer_early_get_count_rate(&rate); + return rate; +} + +u64 notrace timer_early_get_count(void) +{ + uint32_t rate; + + return timer_early_get_count_rate(&rate); +} + static u64 rockchip_timer_get_count(struct udevice *dev) { struct rockchip_timer_priv *priv = dev_get_priv(dev); -- 2.37.3