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 0528EC433EF for ; Fri, 11 Mar 2022 17:12:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 405E783AFC; Fri, 11 Mar 2022 18:12:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bfJM1YSi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 68A5683AE8; Fri, 11 Mar 2022 18:12:10 +0100 (CET) Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9E3BB83AE8 for ; Fri, 11 Mar 2022 18:11:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=krjdev@gmail.com Received: by mail-wm1-x32e.google.com with SMTP id k29-20020a05600c1c9d00b003817fdc0f00so5699796wms.4 for ; Fri, 11 Mar 2022 09:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AT4TNZhDIp8xECiVBilWNGt/oNv6hZDXZ6CJX3L2IKs=; b=bfJM1YSiTEmS9IdyoVJjM6ZADlXCKbAWmqp8Dc2L/GCdH/gzYrG0dnnyuNGbu+1/dq uIcV/GxqEBgjxbrBn7bd2TegB8xih/vZG85PgZZNYS9weujfh4ZqvbTHk5OfCumWg46h RjFLu052hJzJ9MuUW8/vguzHh8/Al6mFIjVFUly9BkTdrqNhOMwqGjUWPvgfN8PFv5Z9 BTE9hzAGhxOrUkRTe5cOdy4ifrT3RTLlcb0dZGuR4K9fFImIWMaNlGE+UAL6I+SBUBT6 KzXH57FeP5tlW4kFpPSbIhA7mENpWfpfRnwxsaCEcFJjGa50fPK1OYqB7QIGfbcZhOvy TMDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AT4TNZhDIp8xECiVBilWNGt/oNv6hZDXZ6CJX3L2IKs=; b=2QNzNi333CgCXeGPFFoEFl3lMUyC2qtgrL1MVUHyFYqjdH9DkE59TZmWn/H25PcVRh SJj+lGBFQNFIxxLIVF6UDAUaS1/se3y3V8dCaMQbZyV2IRzDeUj8qhQPKCmX/5sjiWuf l56MZp2O78ndj17LE6fhaJW6JBugQXSeeQEP5LZUIVhIdv2gsgqrOWNXuaup7IrjtNWd oGVJjdtYQNcixfvV9g4/ZubSqVAunSbnO6AqbMdl5C8KrfPa3z8r7xl7TfoJ+LdCPvnx 8yyKSL05btj9UW0VziDMeoI5ZxkLkE+wC7RWQqjwI3p6wKDiF8oEYBXVfKhQr7aulxCk CHLw== X-Gm-Message-State: AOAM533H1Wsljv84s4Yqha8y7sKtMXX6Ole18A3lvH7Vvwbx6SSlUB3K M9Mj+e5FQKVXR1FVTqpCqSjgK96QWEeBXw== X-Google-Smtp-Source: ABdhPJwhdzOow+or7d8Z5MBQhtkhI9zc8D6MVesJlGmqzLaFYiiSg/uqgbWvWMJR4Ch8gtpWI8/etA== X-Received: by 2002:a05:600c:3c9c:b0:389:cc3b:9462 with SMTP id bg28-20020a05600c3c9c00b00389cc3b9462mr13482221wmb.105.1647018717048; Fri, 11 Mar 2022 09:11:57 -0800 (PST) Received: from matrix42.lan (212-197-176-189.adsl.highway.telekom.at. [212.197.176.189]) by smtp.gmail.com with ESMTPSA id bi9-20020a05600c3d8900b00389a623c80esm6837300wmb.1.2022.03.11.09.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 09:11:56 -0800 (PST) From: Johannes Krottmayer To: u-boot@lists.denx.de Cc: Johannes Krottmayer , Wolfgang Denk , Thomas Chou , Rick Chen , Leo , Bin Meng , Sean Anderson , Anup Patel Subject: [PATCH 1/2] lib: time: Change behaviour of CONFIG_TIMER_EARLY Date: Fri, 11 Mar 2022 18:11:50 +0100 Message-Id: <20220311171151.29004-2-krjdev@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220311171151.29004-1-krjdev@gmail.com> References: <20220311171151.29004-1-krjdev@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.5 at phobos.denx.de X-Virus-Status: Clean If CONFIG_TIMER_EARLY is selected and the timer driver implements timer_early_get_count() and timer_early_get_rate(), check first if the virtual root driver is running, when it is initialized yet use the virtual timer driver instead. When the virtual root driver doesn't exists fallback to the timer_early_get_count() and timer_early_get_rate(). Signed-off-by: Johannes Krottmayer Cc: Wolfgang Denk Cc: Thomas Chou Cc: Rick Chen Cc: Leo Cc: Bin Meng Cc: Sean Anderson Cc: Anup Patel Cc: Thomas Chou --- lib/time.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/time.c b/lib/time.c index 96074b84af..b5c9760042 100644 --- a/lib/time.c +++ b/lib/time.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -66,16 +67,28 @@ extern unsigned long __weak timer_read_counter(void); #if CONFIG_IS_ENABLED(TIMER) ulong notrace get_tbclk(void) { - if (!gd->timer) { + int ret; + #ifdef CONFIG_TIMER_EARLY + + /* + * Check if the virtual root driver does not yet exist, + * if not fallback to timer_early_get_rate(). + */ + if (gd->dm_root == NULL) return timer_early_get_rate(); -#else - int ret; +#endif /* CONFIG_TIMER_EARLY */ + + /* + * Check if the virtual timer driver does not yet exist, + * if not initialize the driver. + */ + if (!gd->timer) { ret = dm_timer_init(); + if (ret) - return ret; -#endif + panic("Could not initialize timer (err %d)\n", ret); } return timer_get_rate(gd->timer); @@ -86,19 +99,30 @@ uint64_t notrace get_ticks(void) u64 count; int ret; - if (!gd->timer) { #ifdef CONFIG_TIMER_EARLY + + /* + * Check if the virtual root driver does not yet exist, + * if not fallback to timer_early_get_rate(). + */ + if (gd->dm_root == NULL) return timer_early_get_count(); -#else - int ret; +#endif /* CONFIG_TIMER_EARLY */ + + /* + * Check if the virtual timer driver does not yet exist, + * if not initialize the driver. + */ + if (!gd->timer) { ret = dm_timer_init(); + if (ret) panic("Could not initialize timer (err %d)\n", ret); -#endif } ret = timer_get_count(gd->timer, &count); + if (ret) { if (spl_phase() > PHASE_TPL) panic("Could not read count from timer (err %d)\n", -- 2.34.1