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 CB602C07E9D for ; Sat, 24 Sep 2022 07:57:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DACC384461; Sat, 24 Sep 2022 09:57:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 10E4C84565; Sat, 24 Sep 2022 09:57:21 +0200 (CEST) Received: from mail-m11877.qiye.163.com (mail-m11877.qiye.163.com [115.236.118.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9BB5980757 for ; Sat, 24 Sep 2022 09:57:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kever.yang@rock-chips.com Received: from [172.16.12.93] (unknown [58.22.7.114]) by mail-m11877.qiye.163.com (Hmail) with ESMTPA id AA685400185; Sat, 24 Sep 2022 15:57:03 +0800 (CST) Message-ID: Date: Sat, 24 Sep 2022 15:57:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 06/10] timer: rockchip_timer: Add timer_early functions Content-Language: en-US To: Stefan Roese , u-boot@lists.denx.de Cc: sjg@chromium.org, trini@konsulko.com, Philipp Tomsich References: <20220921140625.999002-1-sr@denx.de> <20220921140625.999002-7-sr@denx.de> From: Kever Yang In-Reply-To: <20220921140625.999002-7-sr@denx.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFJSktLSjdXWS1ZQUlXWQ8JGhUIEh9ZQVlDQx9LVkpOGR5KTh9JHRkdQ1UTARMWGhIXJB QOD1lXWRgSC1lBWU5DVUlJVUxVSkpPWVdZFhoPEhUdFFlBWU9LSFVKSktITkhVSktLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PhA6Hyo5ST0uIhQSIk4#Hhge Vk4aCi1VSlVKTU1PS0tNSUlPSUpKVTMWGhIXVRAeDR4JVQIaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFITE5DNwY+ X-HM-Tid: 0a836e7ff7f12eb3kusnaa685400185 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 On 2022/9/21 22:06, Stefan Roese 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 > Cc: Kever Yang > Cc: Philipp Tomsich Reviewed-by: Kever Yang Thanks, - Kever > --- > 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);