From patchwork Sun Oct 4 20:29:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1376536 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=hi9/0+5s; 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 4C4Fjb0CNYz9s1t for ; Mon, 5 Oct 2020 07:30:43 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 71A0C82399; Sun, 4 Oct 2020 22:30:07 +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="hi9/0+5s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DE43B82366; Sun, 4 Oct 2020 22:30:04 +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-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (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 F0ABF822C8 for ; Sun, 4 Oct 2020 22:30: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=seanga2@gmail.com Received: by mail-qk1-x742.google.com with SMTP id y198so3210847qka.0 for ; Sun, 04 Oct 2020 13:30:00 -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=b41ZWipAaSqNONo0InIQbxFAqGQKnMAttluJAZVIIEQ=; b=hi9/0+5sHaHkppfXpI2gJYNRmKhyI/l1dxBdr4ub74elDPTbowb09blj6upQ+szUJR OBvPb80Gx3+H3/1RSLhWtnujanlHB6Ms/azeqcP4MafmfASm0zkbvzCTJ5UXqhkRTw97 48OpPo1D2E1H2ZYI9UA5iUVLO51hY2iqKSYiQdZ41/eKUjDVYftuVkf5cqbqkysA03Hh x6DjETcmXB5/t84bB7QH0Aun8lJTJ1MvAppYiUx/Exo2n7EKSE3lqtnM18Q1Iu36ytGq PEa6dIru7imzhHpNRbiJYyfz1Ko2B1Kf6XSbQJxfRGdLTe3aTsRSTilSDklNz6V2ftaD iqsw== 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=b41ZWipAaSqNONo0InIQbxFAqGQKnMAttluJAZVIIEQ=; b=J/EVJ4pO+fB0U4ZoRRBzGXblHL+H2XVCGMMXTyIX7KEaXv0QeTjbu7nxJjI8zZcgwn KD3+Ca7qaC1++trzhlofD3fAVSFKewEtYgoal7GP3HvL09OoAqKHOL/0QlmovlfBC7eh tB7wfNSZsqHgws1flyI6H1TfE9ebLAlBrHbrPfiazxwz22F/qM1u73ERjYxMrYfORhi1 QSWOjid1kqHOUkTbqoIaahcH+nJSfal82uSI/n/g7J0DnRWHdlQhO6Q1dp8HWR+KCpQl iUv0zPbACKFg0wn2zBBFCAODRiYXWESd/OZATMFHVSeqBxPobLT8EZtYHZj33NfCRJes +7mw== X-Gm-Message-State: AOAM531T6WeJqTuL34jYVQMFd1uH5S45Ldv5yUQO4Q7ZiHIO+3UDX9oE 9MgdpbULrabqUP8gv8bP/gKX+MuTNJNTHg== X-Google-Smtp-Source: ABdhPJwzKRRixv7+WJm5ELeTGl1yMKRS0YTDSvGwVojmfpW1MYL95XjAgefcWIlrKUgcBK/9NTk9XQ== X-Received: by 2002:a37:a0cf:: with SMTP id j198mr11710376qke.408.1601843399488; Sun, 04 Oct 2020 13:29:59 -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 d9sm6170597qtg.51.2020.10.04.13.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Oct 2020 13:29:58 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Simon Glass , Pragnesh Patel , Rick Chen , Sean Anderson Subject: [PATCH 3/3] riscv: Move timer portions of SiFive CLINT to drivers/timer Date: Sun, 4 Oct 2020 16:29:47 -0400 Message-Id: <20201004202947.469166-4-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201004202947.469166-1-seanga2@gmail.com> References: <20201004202947.469166-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 Half of this driver is a DM-based timer driver, and half is RISC-V-specific IPI code. Move the timer portions in with the other timer drivers. The KConfig is not moved, since it also enables IPIs. It could also be split into two configs, but no boards use the timer but not the IPI atm, so I haven't split it. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass Reviewed-by: Rick Chen --- MAINTAINERS | 1 + arch/riscv/lib/sifive_clint.c | 43 ++------------------------ drivers/timer/Makefile | 1 + drivers/timer/sifive_clint_timer.c | 49 ++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 drivers/timer/sifive_clint_timer.c diff --git a/MAINTAINERS b/MAINTAINERS index 32a2cdb52b..73d1c20a26 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -928,6 +928,7 @@ T: git https://gitlab.denx.de/u-boot/custodians/u-boot-riscv.git F: arch/riscv/ F: cmd/riscv/ F: drivers/timer/andes_plmt_timer.c +F: drivers/timer/sifive_clint_timer.c F: tools/prelink-riscv.c RISC-V KENDRYTE diff --git a/arch/riscv/lib/sifive_clint.c b/arch/riscv/lib/sifive_clint.c index c9704c596f..c8079dc510 100644 --- a/arch/riscv/lib/sifive_clint.c +++ b/arch/riscv/lib/sifive_clint.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* + * Copyright (C) 2020, Sean Anderson * Copyright (C) 2018, Bin Meng * * U-Boot syscon driver for SiFive's Core Local Interruptor (CLINT). @@ -8,19 +9,13 @@ */ #include -#include #include -#include #include -#include +#include #include /* MSIP registers */ #define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4) -/* mtime compare register */ -#define MTIMECMP_REG(base, hart) ((ulong)(base) + 0x4000 + (hart) * 8) -/* mtime register */ -#define MTIME_REG(base) ((ulong)(base) + 0xbff8) DECLARE_GLOBAL_DATA_PTR; @@ -61,37 +56,3 @@ 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" }, - { } -}; - -U_BOOT_DRIVER(sifive_clint) = { - .name = "sifive_clint", - .id = UCLASS_TIMER, - .of_match = sifive_clint_ids, - .probe = sifive_clint_probe, - .ops = &sifive_clint_ops, - .flags = DM_FLAG_PRE_RELOC, -}; diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile index eda311f0f5..410ada87b7 100644 --- a/drivers/timer/Makefile +++ b/drivers/timer/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_RENESAS_OSTM_TIMER) += ostm_timer.o obj-$(CONFIG_RISCV_TIMER) += riscv_timer.o obj-$(CONFIG_ROCKCHIP_TIMER) += rockchip_timer.o obj-$(CONFIG_SANDBOX_TIMER) += sandbox_timer.o +obj-$(CONFIG_SIFIVE_CLINT) += sifive_clint_timer.o obj-$(CONFIG_STI_TIMER) += sti-timer.o obj-$(CONFIG_STM32_TIMER) += stm32_timer.o obj-$(CONFIG_X86_TSC_TIMER) += tsc_timer.o diff --git a/drivers/timer/sifive_clint_timer.c b/drivers/timer/sifive_clint_timer.c new file mode 100644 index 0000000000..04e85c2564 --- /dev/null +++ b/drivers/timer/sifive_clint_timer.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020, Sean Anderson + * Copyright (C) 2018, Bin Meng + */ + +#include +#include +#include +#include +#include +#include + +/* mtime register */ +#define MTIME_REG(base) ((ulong)(base) + 0xbff8) + +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" }, + { } +}; + +U_BOOT_DRIVER(sifive_clint) = { + .name = "sifive_clint", + .id = UCLASS_TIMER, + .of_match = sifive_clint_ids, + .probe = sifive_clint_probe, + .ops = &sifive_clint_ops, + .flags = DM_FLAG_PRE_RELOC, +};