From patchwork Tue Sep 15 14:17:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1364385 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=R/d28MAn; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4BrQMZ4Yq8z9sT6 for ; Wed, 16 Sep 2020 00:19:05 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 79C4782340; Tue, 15 Sep 2020 16:17:56 +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="R/d28MAn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9BA6A8231E; Tue, 15 Sep 2020 16:17:47 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) (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 A870D81281 for ; Tue, 15 Sep 2020 16:17:43 +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-qv1-xf41.google.com with SMTP id p15so1775777qvk.5 for ; Tue, 15 Sep 2020 07:17:43 -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=tIshYKkL5dCZtsiP2c38SCefgYyquvLrtgEpXwaG2JQ=; b=R/d28MAnKjaiy0o+KlEgKw6AW7g7Czww3UzMGH4WTo9geE4KFOks8bqBAgAUgWpkBd CKx6yNqBt3Q3+5+v0N06sOJYPD3R+GQZPT1HCgjNGKyxZx129peY1De/X72iAe4wHKVj ZflxoBDf5bBV8L1qtm2fOhVEvFZmV68SjRz+RPGOUNnlj7Q0ycSIxTw/qIGEStUGjEsd YBPAEXZDoVYfCAKFwFqmErOD7PReaDT7Lhm8pzxH4+Fmh+z5Vd8BfPhH6sLPXl+qOC6Y 8Oq+Cmn419djSdzpug0hwsSGp0VfkkpXceuXQCDqHrRUsjKAH7YI5TsYMIGmPCaHcQDa fndA== 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=tIshYKkL5dCZtsiP2c38SCefgYyquvLrtgEpXwaG2JQ=; b=CNiNWA/4RpZu1+Kcjr73VJnahwVG3cD6fmDzAGcNKIm+Vw4BGFB3Jel3Gm5Wypenay qAT3ebY9PkUMjzAtkFvSIHWunv6VkuDA168ph8y2DlrJ3FCPUiK0RnPmMnRaiJYsaoXr douTWv7EUK60HsuzAtoQFgNDjVnxXKFINFqEYUnC7BbbjALekDnxhHKSYDJFX5n6149B cR+XL6SM096HDOmGrOZIVAxdLJNIHDLZWuPk1+uTwO5c/Nuxk5LEcf0B2zuqtdhTP2k4 ZpztHBIwk7mJW/yLSIctd2TQDNYNiUZP4mV42qO1lsRxr/4RUyAPMvJnvRwRFnofsrm9 ELFA== X-Gm-Message-State: AOAM530QE6rJMsdb4sOZP+kfSV44/G4KDjwA56dBpxcs5oGYXzQid6nT L/oZpTmTGo3OwEZ+inRXduDXMXoi+/rvoQK+ X-Google-Smtp-Source: ABdhPJyyGGwnuNwcqSEImwl3Ssfh4aBcs7AcCtEfq7jhKkW/s5w4cDRH7LVx5/nejK/OUrvWT8SpZg== X-Received: by 2002:a0c:b902:: with SMTP id u2mr17752140qvf.7.1600179462424; Tue, 15 Sep 2020 07:17:42 -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 r78sm17600839qka.95.2020.09.15.07.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 07:17:41 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Pragnesh Patel , Anup Patel , Rick Chen , Sean Anderson , Pragnesh Patel Subject: [PATCH v5 6/9] riscv: Rework Sifive CLINT as UCLASS_TIMER driver Date: Tue, 15 Sep 2020 10:17:21 -0400 Message-Id: <20200915141724.503929-7-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915141724.503929-1-seanga2@gmail.com> References: <20200915141724.503929-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 converts the clint driver from the riscv-specific interface to be a DM-based UCLASS_TIMER driver. In addition, the SiFive DDR driver previously implicitly depended on the CLINT to select REGMAP. Unlike Andes's PLMT/PLIC (which AFAIK never have anything pass it a dtb), the SiFive CLINT is part of the device tree passed in by qemu. This device tree doesn't have a clocks or clock-frequency property on clint, so we need to fall back on the timebase-frequency property. Perhaps in the future we can get a clock-frequency property added to the qemu dtb. Unlike with the Andes PLMT, the Sifive CLINT is also an IPI controller. RISCV_SYSCON_CLINT is retained for this purpose. Signed-off-by: Sean Anderson Reviewed-by: Pragnesh Patel --- This patch builds but has only been tested on the K210 and QEMU. It has NOT been tested on a HiFive. Changes in v5: - Don't add a dependency on REGMAP for SIFIVE_FU540_DDR. Instead, depend on Bin Meng's patch. Changes in v4: - Use timer_timebase_fallback Changes in v3: - Don't initialize the IPI in spl_invoke_opensbi. Further testing has revealed it to be unnecessary. arch/riscv/Kconfig | 4 --- arch/riscv/lib/sifive_clint.c | 66 +++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index d9155b9bab..aaa3b833a5 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -155,10 +155,6 @@ config 64BIT config SIFIVE_CLINT bool depends on RISCV_MMODE || SPL_RISCV_MMODE - select REGMAP - select SYSCON - select SPL_REGMAP if SPL - select SPL_SYSCON if SPL help The SiFive CLINT block holds memory-mapped control and status registers associated with software and timer interrupts. diff --git a/arch/riscv/lib/sifive_clint.c b/arch/riscv/lib/sifive_clint.c index b9a2c649cc..c9704c596f 100644 --- a/arch/riscv/lib/sifive_clint.c +++ b/arch/riscv/lib/sifive_clint.c @@ -8,9 +8,9 @@ */ #include +#include #include -#include -#include +#include #include #include #include @@ -24,35 +24,19 @@ DECLARE_GLOBAL_DATA_PTR; -int riscv_get_time(u64 *time) -{ - /* ensure timer register base has a sane value */ - riscv_init_ipi(); - - *time = readq((void __iomem *)MTIME_REG(gd->arch.clint)); - - return 0; -} - -int riscv_set_timecmp(int hart, u64 cmp) -{ - /* ensure timer register base has a sane value */ - riscv_init_ipi(); - - writeq(cmp, (void __iomem *)MTIMECMP_REG(gd->arch.clint, hart)); - - return 0; -} - int riscv_init_ipi(void) { - if (!gd->arch.clint) { - long *ret = syscon_get_first_range(RISCV_SYSCON_CLINT); + int ret; + struct udevice *dev; - if (IS_ERR(ret)) - return PTR_ERR(ret); - gd->arch.clint = ret; - } + ret = uclass_get_device_by_driver(UCLASS_TIMER, + DM_GET_DRIVER(sifive_clint), &dev); + if (ret) + return ret; + + gd->arch.clint = dev_read_addr_ptr(dev); + if (!gd->arch.clint) + return -EINVAL; return 0; } @@ -78,14 +62,36 @@ int riscv_get_ipi(int hart, int *pending) return 0; } +static int sifive_clint_get_count(struct udevice *dev, u64 *count) +{ + *count = readq((void __iomem *)MTIME_REG(dev->priv)); + + return 0; +} + +static const struct timer_ops sifive_clint_ops = { + .get_count = sifive_clint_get_count, +}; + +static int sifive_clint_probe(struct udevice *dev) +{ + dev->priv = dev_read_addr_ptr(dev); + if (!dev->priv) + return -EINVAL; + + return timer_timebase_fallback(dev); +} + static const struct udevice_id sifive_clint_ids[] = { - { .compatible = "riscv,clint0", .data = RISCV_SYSCON_CLINT }, + { .compatible = "riscv,clint0" }, { } }; U_BOOT_DRIVER(sifive_clint) = { .name = "sifive_clint", - .id = UCLASS_SYSCON, + .id = UCLASS_TIMER, .of_match = sifive_clint_ids, + .probe = sifive_clint_probe, + .ops = &sifive_clint_ops, .flags = DM_FLAG_PRE_RELOC, };