From patchwork Wed Sep 9 20:09:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1361011 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=iK8aGF1r; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BmtRY6b5sz9sTd for ; Thu, 10 Sep 2020 06:10:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F2BA0822D7; Wed, 9 Sep 2020 22:09:55 +0200 (CEST) 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="iK8aGF1r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 85CEC82189; Wed, 9 Sep 2020 22:09:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) (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 54A0E82189 for ; Wed, 9 Sep 2020 22:09:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x842.google.com with SMTP id t20so2998726qtr.8 for ; Wed, 09 Sep 2020 13:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fduAFZZ7RShP1Khm+aYntQ+R38wdzLOI5qosPo22h1A=; b=iK8aGF1rau42i30qgCAHemvWqwKTTj+yCycqPMFKoFGejWCqAcld9M6TYXKK/B3oUz 4jAi0QNGxowfruiOi1hOy7uCs1oh8bo+ezno/r/ZY0dWyf9AIIsmnPVJKLcAjwC/1iIt +oCnv807LM7pCQfSTqckeRo3P+aEr9eEirNeXQOCDlN2Hr8QvVddXBg+YPLtlsFNIrWC jZq0lhDremimdHSpZ71tWeL/vMBZ1tSyzIQoI2iiZF3/ile7mR+PcnjtKG5oXuec7wFO RvI5tEuV0x/S9PUlNpY2GaHVAVl61z1z2iF8WcYhDXlB4NVCCHr3hBqsDlMf6df8woMw PyQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fduAFZZ7RShP1Khm+aYntQ+R38wdzLOI5qosPo22h1A=; b=jXCbZ5mXH6gdL9BiXP0TCZ8F5EyVl61l+IRa7ZyqxkBt0D5We1fO/XlW8Ri3qBn/G9 dI9+vZE6MCHDWOFPq/E2Crs1ntYrAADLIt5MsHqynKcQNmo4UWRy+JsB0K9EP1bhfJ7N zAp/u+QHD0pEuzVUGfb3bWGJYSbPrT3IlxrPT8V0Mtm9mF41mx1u/xfbw3iwaXiiyXQP aD7jJ3WTfBJF47DhgdP+DNyYtH9+uKr93sJMVp0soOzV5j+RUROmcW50pIXIwAw759em szFJYWJU78iL6eQboF/yl75WWeEU9rUOOkpwgOe9Ilm9J8kyn879bQwk04kgCN8v4lcO wCNA== X-Gm-Message-State: AOAM5321JbFwPuaFNH04d+RKKwMYLicpPxs7diinourYcoXGB+YZifK/ s8OHVU8b2oQzLrUUtu3trz5/d/2BNo67OHDf X-Google-Smtp-Source: ABdhPJxaiY0BR4vOwiIz/wxPIrm8UJP2GiFtFI1QjDyKc0NHenvGJq4q2DmQ6ruLqnpBlS19IYjmAA== X-Received: by 2002:ac8:12c1:: with SMTP id b1mr5113247qtj.148.1599682188008; Wed, 09 Sep 2020 13:09:48 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id s30sm4342831qth.65.2020.09.09.13.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 13:09:47 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Anup Patel , Pragnesh Patel , Bin Meng , Rick Chen , Sean Anderson , Simon Glass Subject: [PATCH v4 2/8] timer: Add helper for drivers using timebase fallback Date: Wed, 9 Sep 2020 16:09:24 -0400 Message-Id: <20200909200930.232174-3-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200909200930.232174-1-seanga2@gmail.com> References: <20200909200930.232174-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean This function is designed to be used when a timer used to be initialized by the cpu (e.g. RISC-V timers), but now is initialized by dm_timer_init. In such a case, the timer may prefer to use the clocks and clock-frequency properties, but should be able to fall back on using the cpu's timebase-frequency. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v4: - New drivers/timer/timer-uclass.c | 25 +++++++++++++++++++++++++ include/timer.h | 15 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c index 14dde950a1..fb2f4c351a 100644 --- a/drivers/timer/timer-uclass.c +++ b/drivers/timer/timer-uclass.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -79,6 +80,30 @@ static int timer_post_probe(struct udevice *dev) return 0; } +int timer_timebase_fallback(struct udevice *dev) +{ + struct udevice *cpu; + struct cpu_platdata *cpu_plat; + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); + + /* Did we get our clock rate from the device tree? */ + if (uc_priv->clock_rate) + return 0; + + /* Fall back to timebase-frequency */ + dev_dbg(dev, "missing clocks or clock-frequency property; falling back on timebase-frequency\n"); + cpu = cpu_get_current_dev(); + if (!cpu) + return -ENODEV; + + cpu_plat = dev_get_parent_platdata(cpu); + if (!cpu_plat) + return -ENODEV; + + uc_priv->clock_rate = cpu_plat->timebase_freq; + return 0; +} + u64 timer_conv_64(u32 count) { /* increment tbh if tbl has rolled over */ diff --git a/include/timer.h b/include/timer.h index a49b500ce3..8b9fa51c53 100644 --- a/include/timer.h +++ b/include/timer.h @@ -15,6 +15,21 @@ */ int dm_timer_init(void); +/** + * timer_timebase_fallback() - Helper for timers using timebase fallback + * @dev: A timer partially-probed timer device + * + * This is a helper function designed for timers which need to fall back on the + * cpu's timebase. This function is designed to be called during the driver's + * probe(). If there is a clocks or clock-frequency property in the timer's + * binding, then it will be used. Otherwise, the timebase of the current cpu + * will be used. This is initialized by the cpu driver, and usually gotten from + * ``/cpus/timebase-frequency`` or ``/cpus/cpu@X/timebase-frequency``. + * + * Return: 0 if OK, or negative error code on failure + */ +int timer_timebase_fallback(struct udevice *dev); + /* * timer_conv_64 - convert 32-bit counter value to 64-bit *