From patchwork Mon Sep 28 14:52: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: 1372684 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=GOSalXuy; 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 4C0QWR32Tlz9s0b for ; Tue, 29 Sep 2020 00:53:38 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E2CAE82380; Mon, 28 Sep 2020 16:53:00 +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="GOSalXuy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DA0F18233E; Mon, 28 Sep 2020 16:52:53 +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-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (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 C3B9D82294 for ; Mon, 28 Sep 2020 16:52:50 +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-x843.google.com with SMTP id 19so944090qtp.1 for ; Mon, 28 Sep 2020 07:52:50 -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=SAy+KRcHvnJu7M3RoeYMq63x1OQxPMSCy6wbEzD5SEk=; b=GOSalXuyPHXYaMXrwTEUbhrq72Cq0neZ9867BTqhupPoUhEV0xPnTJ1rwlB6KpNjCO CXu6WPjfjVIbKfcEu54HOlESnaq0b6ANFTR3p00WttRrOs+1P8ud4t/nbp/QANCpeztf CHNBngrDhV7J9c9tzxDM1WQw3ACC1H2IBMEjPmW6f4TOPQ/5Fx56qJZ5O6NQ2sY5y3a+ QBBXtXbfDDWK31/4h6MZqrSfGhwD7a1xvUoQFokItRATkSiX7/6dXqWaNRIcecunPMSe f7ztzawf2iFslIYzkXrEfj4gW0MhObJ0BCwaNbz3mZ1ZVQfr7bwo2zQTsnCydMzbl0a8 jGoA== 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=SAy+KRcHvnJu7M3RoeYMq63x1OQxPMSCy6wbEzD5SEk=; b=HxUXi2w+KI/j+cK8XYcku80N9nNGd6DGKkwRAWpa5fPemzSvMa+gcnTNFkYKDBMehY 04icqB6pMtwJzt4kzm54jrIWmOpk0JUrdEb8GXcYdL7t4JT2VPeoPG0uy4YY7IBMhabG BP5TPWYlIqm2xAj6cu9OD+1RH62kSbSO95yIs6OYhv37vd212FQcNAtkiFng6r6yPky/ oIhjBfOi+y59wgaED3Gh414mlm7HpCFEcL/LyWOgzEq12lxMQIf263M0Lt2nvu+nUe/1 30tJ3nY07KvIqm9OC7lwsONQzmkdGBja0MF4oH/XgXYmw32w3+aPCP7bRruvZLzoGMUI 5mYQ== X-Gm-Message-State: AOAM533sbMkZG/XitEVZQM8nBFmHwWxHRVMVNmMm3MDulxqwHFR2MfVT 9jUn7qcDbFhJQqcUaGYopP+BxSAjQI47xg== X-Google-Smtp-Source: ABdhPJxya8LiAgLO0ZchrRyPY2koR7FYcfJmviLcqHCEVLHSf9W1/tpC8z6ll+mbQ2keLwt38POFbg== X-Received: by 2002:ac8:23a3:: with SMTP id q32mr1945701qtq.361.1601304769441; Mon, 28 Sep 2020 07:52:49 -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 e7sm1530651qtk.17.2020.09.28.07.52.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 07:52:48 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Pragnesh Patel , Rick Chen , Bin Meng , Anup Patel , Sean Anderson , Rick Chen Subject: [PATCH v6 4/9] riscv: Rework Andes PLMT as a UCLASS_TIMER driver Date: Mon, 28 Sep 2020 10:52:24 -0400 Message-Id: <20200928145229.449782-5-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200928145229.449782-1-seanga2@gmail.com> References: <20200928145229.449782-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 PLMT driver from the riscv-specific timer interface to be a DM-based UCLASS_TIMER driver. The clock-frequency/clocks properties are preferred over timebase-frequency for two reasons. First, properties which affect a device should be located near its binding in the device tree. Using timebase-frequency only really makes sense when the cpu itself is the timer device. This is the case when we read the time from a CSR, but not when there is a separate device. Second, it lets the device use the clock subsystem which adds flexibility. If the device is configured for a different clock speed, the timer can adjust itself. Signed-off-by: Sean Anderson Reviewed-by: Rick Chen --- This patch builds but has NOT been tested. (no changes since v5) Changes in v5: - Remove RISCV_SYSCON_PLMT - Undo changes to ae350 device trees. They are unnecessary with timer_timebase_fallback. Changes in v4: - Use timer_timebase_fallback arch/riscv/Kconfig | 4 --- arch/riscv/include/asm/global_data.h | 3 -- arch/riscv/include/asm/syscon.h | 4 +-- arch/riscv/lib/andes_plmt.c | 44 +++++++++++++--------------- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 21e6690f4d..d9155b9bab 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -177,10 +177,6 @@ config ANDES_PLIC config ANDES_PLMT bool depends on RISCV_MMODE || SPL_RISCV_MMODE - select REGMAP - select SYSCON - select SPL_REGMAP if SPL - select SPL_SYSCON if SPL help The Andes PLMT block holds memory-mapped mtime register associated with timer tick. diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h index b711fcc44d..d3a0b1d221 100644 --- a/arch/riscv/include/asm/global_data.h +++ b/arch/riscv/include/asm/global_data.h @@ -24,9 +24,6 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLIC void __iomem *plic; /* plic base address */ #endif -#ifdef CONFIG_ANDES_PLMT - void __iomem *plmt; /* plmt base address */ -#endif #if CONFIG_IS_ENABLED(SMP) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git a/arch/riscv/include/asm/syscon.h b/arch/riscv/include/asm/syscon.h index 26a008ca59..c3629e4b53 100644 --- a/arch/riscv/include/asm/syscon.h +++ b/arch/riscv/include/asm/syscon.h @@ -7,13 +7,13 @@ #define _ASM_SYSCON_H /* - * System controllers in a RISC-V system + * System controllers in a RISC-V system. These should only be used for + * identifying IPI controllers. Other devices should use DM to probe. */ enum { RISCV_NONE, RISCV_SYSCON_CLINT, /* Core Local Interruptor (CLINT) */ RISCV_SYSCON_PLIC, /* Platform Level Interrupt Controller (PLIC) */ - RISCV_SYSCON_PLMT, /* Platform Level Machine Timer (PLMT) */ }; #endif /* _ASM_SYSCON_H */ diff --git a/arch/riscv/lib/andes_plmt.c b/arch/riscv/lib/andes_plmt.c index a7e90ca992..a28c14c1eb 100644 --- a/arch/riscv/lib/andes_plmt.c +++ b/arch/riscv/lib/andes_plmt.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2019, Rick Chen + * Copyright (C) 2020, Sean Anderson * * U-Boot syscon driver for Andes's Platform Level Machine Timer (PLMT). * The PLMT block holds memory-mapped mtime register @@ -9,46 +10,43 @@ #include #include -#include -#include +#include #include -#include #include /* mtime register */ #define MTIME_REG(base) ((ulong)(base)) -DECLARE_GLOBAL_DATA_PTR; - -#define PLMT_BASE_GET(void) \ - do { \ - long *ret; \ - \ - if (!gd->arch.plmt) { \ - ret = syscon_get_first_range(RISCV_SYSCON_PLMT); \ - if (IS_ERR(ret)) \ - return PTR_ERR(ret); \ - gd->arch.plmt = ret; \ - } \ - } while (0) - -int riscv_get_time(u64 *time) +static int andes_plmt_get_count(struct udevice *dev, u64 *count) { - PLMT_BASE_GET(); - - *time = readq((void __iomem *)MTIME_REG(gd->arch.plmt)); + *count = readq((void __iomem *)MTIME_REG(dev->priv)); return 0; } +static const struct timer_ops andes_plmt_ops = { + .get_count = andes_plmt_get_count, +}; + +static int andes_plmt_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 andes_plmt_ids[] = { - { .compatible = "riscv,plmt0", .data = RISCV_SYSCON_PLMT }, + { .compatible = "riscv,plmt0" }, { } }; U_BOOT_DRIVER(andes_plmt) = { .name = "andes_plmt", - .id = UCLASS_SYSCON, + .id = UCLASS_TIMER, .of_match = andes_plmt_ids, + .ops = &andes_plmt_ops, + .probe = andes_plmt_probe, .flags = DM_FLAG_PRE_RELOC, };