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 11A04C4332F for ; Wed, 21 Dec 2022 09:18:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 80F158540C; Wed, 21 Dec 2022 10:18:56 +0100 (CET) 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=1671614337; bh=6qCG9K4zWchMPkBINLXT6VEjTiZu3CY60uCWy5t8Ufo=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=lr92nRW8P2cwOLw0Hk/Xt27P1LjPbiWTjTaMyKOAeMdkR+xxJw6jenKMtAK5aSBPu hmZadPAeVj79U2UZw5rZCiXzuEeobrE/TE5JhUww0MiintxLZX4hyNsz1FCfapNMGF tzocGHjm6rVzg3XxYMMvlfLATImw5jDUcak6svrmVP8Dhx36dAA2+GfjrBky68rzbg h8u3KL1zivQv+wFvEc9qngZKCXmB2s1/31cwqW8qQ0WzM8JSQLs7oEQpEkAZfAd0g+ m4+LR+49KrfewA/kGN8BpQWmhKIs8JT1J9mbjlPajq5WvEzFJjpdO/y9lj7KqTmx3A e9ebGOEpdtWlA== Received: by phobos.denx.de (Postfix, from userid 109) id 13F7A8541A; Wed, 21 Dec 2022 10:18:55 +0100 (CET) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [80.241.59.207]) (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 D531985335 for ; Wed, 21 Dec 2022 10:18:52 +0100 (CET) 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 smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4NcSYQ3lzQz9sTq; Wed, 21 Dec 2022 10:18:50 +0100 (CET) From: Stefan Roese To: u-boot@lists.denx.de Cc: =?UTF-8?q?Pali=20Roh=C3=A1r?= , Michael Walle , Tony Dinh Subject: [PATCH] timer: orion-timer: Fix problem with early static variable Date: Wed, 21 Dec 2022 10:18:49 +0100 Message-Id: <20221221091849.1018783-1-sr@denx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4NcSYQ3lzQz9sTq 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 We've noticed that at least one Kirkwood board (Pogo v4) has problems with the new orion DM timer implementation. Debugging revealed that this issue is related with the static variable "early_init_done" which does not work correctly before relocation in all cases. This patch removes this static variable and replaces it's functionality via a function that detects if the timer is already initialized. Signed-off-by: Stefan Roese Cc: Pali Rohár Cc: Michael Walle Cc: Tony Dinh --- drivers/timer/orion-timer.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/timer/orion-timer.c b/drivers/timer/orion-timer.c index d0eab3ce781d..6804bf0fa2cb 100644 --- a/drivers/timer/orion-timer.c +++ b/drivers/timer/orion-timer.c @@ -23,15 +23,19 @@ struct orion_timer_priv { #define MVEBU_TIMER_FIXED_RATE_25MHZ 25000000 -static bool early_init_done __section(".data") = false; +static bool early_init_done(void *base) +{ + if (readl(base + TIMER_CTRL) & TIMER0_EN) + return true; + return false; +} /* Common functions for early (boot) and DM based timer */ static void orion_timer_init(void *base, enum input_clock_type type) { /* Only init the timer once */ - if (early_init_done) + if (early_init_done(base)) return; - early_init_done = true; writel(~0, base + TIMER0_VAL); writel(~0, base + TIMER0_RELOAD); -- 2.39.0