From patchwork Wed Jul 22 15:51:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1333967 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=EseFgnix; 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 4BBg1s12VCz9sPB for ; Thu, 23 Jul 2020 01:51:45 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1FF9C819EA; Wed, 22 Jul 2020 17:51:38 +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="EseFgnix"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A43FD81EF5; Wed, 22 Jul 2020 17:51:31 +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-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) (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 6A2E081B96 for ; Wed, 22 Jul 2020 17:51:28 +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-x844.google.com with SMTP id k18so2135770qtm.10 for ; Wed, 22 Jul 2020 08:51:28 -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=OODZhXq2gFQQim+berPgK0SSd1P55YqtN747uUGCPFI=; b=EseFgnixFFH6ph16UWUaAz4W61ENJ+qlMCU+MABRkR3JJVjP6J4ztq/9UfDX1YAgbF zvb5YLD4BkFCFJXdmyyp3i38D7uAHProvonXKNLEFybZzrRkF7T3E2mx0TmPBz/BPbah +8HPUqcbg/J8lMvD6AaPojL7Nr+h9sO23kOAeKE2DwJA3rvjAqqwSl0Ky+lrYOUbFfUi rHjTb2FDQpntxXZxTEySD7bD+HT8zHoBOZ0dCXDfEmh+Mztdylu9F3ZXCosgOkEFYMO2 621T/5cIUHSvW/WQxYS//G/rSrOZdejxw4ciBcvNb+q2b888B6bGeOKXkBB8fNJIeTvj vQHw== 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=OODZhXq2gFQQim+berPgK0SSd1P55YqtN747uUGCPFI=; b=r/dxMLVHxDjYr+0oAar+LQAxXmmHQewYF2OlYdhiwFyXhHwxtCCcHFoMSEiqPPx1MO gxuuBhKWq5pDz6aAmsSddiOFWS6e7IfWSf5gsBDf2Pz8mQb47M52Bo4tGT31lLb5KmhO /Fqi9GV/8O6VXFCzLmH0nfPDOaxPY80l7/BuqBjRwWbS2TTHXfxlAx+uFKYuZSjH+R0z BwwT2PktdvqnfN7Y2538UIqqJypJL6udp3rSqiCqEoI0jJpxhqxgpdUwTwvDNURQc2Q/ NpVSSKU+Vv+XUhVswFGPPyxPYcFHjMw7lFGJERdQmkx5X5RbI+2OJOEgTndMH2vRXfqk TM/Q== X-Gm-Message-State: AOAM532vfJZ9FKCRFVQ+2gYueFFu16hc1W51DDqRm638hTTTrJcFQQia hth/iKjU4bVjEs6qnjF5PtyEKbHqZjY= X-Google-Smtp-Source: ABdhPJy6g5LHPCptzKB6j8gHwdumlMROMqjCYBmPYrtYe+vzldAapPs7RiWoHrbVmyGgcUNOE87J+g== X-Received: by 2002:aed:252c:: with SMTP id v41mr34987917qtc.234.1595433086885; Wed, 22 Jul 2020 08:51:26 -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 z60sm55658qtc.30.2020.07.22.08.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 08:51:26 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson , Anup Patel Subject: [PATCH 1/6] riscv: Rework riscv timer driver to only support S-mode Date: Wed, 22 Jul 2020 11:51:05 -0400 Message-Id: <20200722155110.713966-2-seanga2@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722155110.713966-1-seanga2@gmail.com> References: <20200722155110.713966-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 The riscv-timer driver currently serves as a shim for several riscv timer drivers. This is not too desirable because it bypasses the usual timer selection via the driver model. There is no easy way to specify an alternate timing driver, or have the tick rate depend on the cpu's configured frequency. The timer drivers also do not have device structs, and so have to rely on storing parameters in gd_t. Lastly, there is no initialization call, so driver init is done in the same function which reads the time. This can result in confusing error messages. To a user, it looks like the driver failed when trying to read the time, whereas it may have failed while initializing. This patch removes the shim functionality from the riscv-timer driver, and has it instead implement the former rdtime.c timer driver. This is because existing u-boot users who pass in a device tree (e.g. qemu) do not create a timer device for S-mode u-boot. The existing behavior of creating the riscv-timer device in the riscv cpu driver must be kept. The actual reading of the CSRs has been redone in the style of Linux's get_cycles64. Signed-off-by: Sean Anderson --- arch/riscv/lib/Makefile | 1 - arch/riscv/lib/rdtime.c | 38 ------------------------------------ drivers/timer/Kconfig | 6 +++--- drivers/timer/riscv_timer.c | 39 +++++++++++++++++++------------------ 4 files changed, 23 insertions(+), 61 deletions(-) delete mode 100644 arch/riscv/lib/rdtime.c diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index 6c503ff2b2..10ac5b06d3 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -15,7 +15,6 @@ obj-$(CONFIG_SIFIVE_CLINT) += sifive_clint.o obj-$(CONFIG_ANDES_PLIC) += andes_plic.o obj-$(CONFIG_ANDES_PLMT) += andes_plmt.o else -obj-$(CONFIG_RISCV_RDTIME) += rdtime.o obj-$(CONFIG_SBI) += sbi.o obj-$(CONFIG_SBI_IPI) += sbi_ipi.o endif diff --git a/arch/riscv/lib/rdtime.c b/arch/riscv/lib/rdtime.c deleted file mode 100644 index e128d7fce6..0000000000 --- a/arch/riscv/lib/rdtime.c +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2018, Anup Patel - * Copyright (C) 2018, Bin Meng - * - * The riscv_get_time() API implementation that is using the - * standard rdtime instruction. - */ - -#include - -/* Implement the API required by RISC-V timer driver */ -int riscv_get_time(u64 *time) -{ -#ifdef CONFIG_64BIT - u64 n; - - __asm__ __volatile__ ( - "rdtime %0" - : "=r" (n)); - - *time = n; -#else - u32 lo, hi, tmp; - - __asm__ __volatile__ ( - "1:\n" - "rdtimeh %0\n" - "rdtime %1\n" - "rdtimeh %2\n" - "bne %0, %2, 1b" - : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); - - *time = ((u64)hi << 32) | lo; -#endif - - return 0; -} diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index 637024445c..b85fa33e47 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -144,10 +144,10 @@ config OMAP_TIMER config RISCV_TIMER bool "RISC-V timer support" - depends on TIMER && RISCV + depends on TIMER && RISCV_SMODE help - Select this to enable support for the timer as defined - by the RISC-V privileged architecture spec. + Select this to enable support for a generic RISC-V S-Mode timer + driver. config ROCKCHIP_TIMER bool "Rockchip timer support" diff --git a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 9f9f070e0b..449fcfcfd5 100644 --- a/drivers/timer/riscv_timer.c +++ b/drivers/timer/riscv_timer.c @@ -1,36 +1,37 @@ // SPDX-License-Identifier: GPL-2.0+ /* + * Copyright (C) 2020, Sean Anderson * Copyright (C) 2018, Bin Meng + * Copyright (C) 2018, Anup Patel + * Copyright (C) 2012 Regents of the University of California * - * RISC-V privileged architecture defined generic timer driver + * RISC-V architecturally-defined generic timer driver * - * This driver relies on RISC-V platform codes to provide the essential API - * riscv_get_time() which is supposed to return the timer counter as defined - * by the RISC-V privileged architecture spec. - * - * This driver can be used in both M-mode and S-mode U-Boot. + * This driver provides generic timer support for S-mode U-Boot. */ #include #include #include #include -#include - -/** - * riscv_get_time() - get the timer counter - * - * Platform codes should provide this API in order to make this driver function. - * - * @time: the 64-bit timer count as defined by the RISC-V privileged - * architecture spec. - * @return: 0 on success, -ve on error. - */ -extern int riscv_get_time(u64 *time); +#include static int riscv_timer_get_count(struct udevice *dev, u64 *count) { - return riscv_get_time(count); + if (IS_ENABLED(CONFIG_64BIT)) { + *count = csr_read(CSR_TIME); + } else { + u32 hi, lo; + + do { + hi = csr_read(CSR_TIMEH); + lo = csr_read(CSR_TIME); + } while (hi != csr_read(CSR_TIMEH)); + + *count = ((u64)hi << 32) | lo; + } + + return 0; } static int riscv_timer_probe(struct udevice *dev) From patchwork Wed Jul 22 15:51:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1333968 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=LlkgH/Nw; 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 4BBg242F9vz9sR4 for ; Thu, 23 Jul 2020 01:51:56 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5E15181F2D; Wed, 22 Jul 2020 17:51:41 +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="LlkgH/Nw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F17DB81F2D; Wed, 22 Jul 2020 17:51:33 +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-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) (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 5DFBD81E6F for ; Wed, 22 Jul 2020 17:51:29 +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-x743.google.com with SMTP id b14so709259qkn.4 for ; Wed, 22 Jul 2020 08:51:29 -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=GMdJlq5RyqJteT/StGARprcKKHFRS6SnHlPICKcVVfM=; b=LlkgH/NwuaqZTl/zo2Epmu+UX3JEFCLt1nkZepiCUNorpDHFsapLu/ovt2H9b2XHnD s4K538V6TVmUkZqxv/5iW3P1lAk+8UT/EFu4vbsrpjzASzyo69gNyFilcsBeASOcYcib On1We9MCo+ZlCuKipLsee9lkCZfua10Hc262fZ+Xb2p3VmqcgkLlwFKF+Aqr7gkRdKkG rPDn+a+hHKw0XdxppcSzAW+cA/s2tXv1JmRAQ+ib8duMmJmWgMwxfLn3Ywfj6YWaNt+h IwTpFwbIumTS5o44IWcblJhvnmZIYhu5IsfcylGm2hXxzgC4xnBVnY0fMjjZ7UpAFUsG eyQw== 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=GMdJlq5RyqJteT/StGARprcKKHFRS6SnHlPICKcVVfM=; b=WB1mpWHUawMiwOCPGYeB32j2u1elou9Fd/v7udyfN7KA84c2AGSEQ1z3QbUIgKEZJn NpwH3quNX5VfjzoCFgldmPlHMaAak6qO/UarBPrmOk8nkQKMXkZheJ/J5UCuYJv1JiJs JeDdLgAfedwQe81Afounng8mtL769529jnXG7Kd7h2hiGGrY+2OiYQa+FE/0zcYZxpiw nDo3hgxHVgdR24IuqutRQ3D30Znlo6Rt2KdMiNBmebqcalpvd3HJVAtLF077SLKYM/qc pREnZI+zuPD7xJbrvPbVIvaQh93tKYPvLBMfcdJii0dCjYO425Tjhim3y8LRu7/iM1UR Oa+A== X-Gm-Message-State: AOAM531dY9mn0R7xRByWZXEPXgwTtLJt36iiQUoTN5WdcytTB5aa2J5b uF0pZqHOyRtm4rtvXwgUo3RwilhYzJg= X-Google-Smtp-Source: ABdhPJyVYSZYp+ZVSjrzsJla2GTGTkYbWnU02SYRFOLNJs4FJHE+2bDabM0f+NA4AJ2zCqcDXLQaPg== X-Received: by 2002:a37:9484:: with SMTP id w126mr557633qkd.35.1595433087945; Wed, 22 Jul 2020 08:51:27 -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 z60sm55658qtc.30.2020.07.22.08.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 08:51:27 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson Subject: [PATCH 2/6] riscv: Rework Andes PLMT as a UCLASS_TIMER driver Date: Wed, 22 Jul 2020 11:51:06 -0400 Message-Id: <20200722155110.713966-3-seanga2@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722155110.713966-1-seanga2@gmail.com> References: <20200722155110.713966-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. Signed-off-by: Sean Anderson --- This patch builds but has NOT been tested. arch/riscv/Kconfig | 4 --- arch/riscv/dts/ae350_32.dts | 1 + arch/riscv/dts/ae350_64.dts | 1 + arch/riscv/include/asm/global_data.h | 3 -- arch/riscv/lib/andes_plmt.c | 42 +++++++++++++--------------- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 009a545fcf..502f27b92d 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/dts/ae350_32.dts b/arch/riscv/dts/ae350_32.dts index 3f8525fe56..afcb9cfbbf 100644 --- a/arch/riscv/dts/ae350_32.dts +++ b/arch/riscv/dts/ae350_32.dts @@ -162,6 +162,7 @@ &CPU2_intc 7 &CPU3_intc 7>; reg = <0xe6000000 0x100000>; + clock-frequency = <60000000>; }; }; diff --git a/arch/riscv/dts/ae350_64.dts b/arch/riscv/dts/ae350_64.dts index 482c707503..1c37879049 100644 --- a/arch/riscv/dts/ae350_64.dts +++ b/arch/riscv/dts/ae350_64.dts @@ -162,6 +162,7 @@ &CPU2_intc 7 &CPU3_intc 7>; reg = <0x0 0xe6000000 0x0 0x100000>; + clock-frequency = <60000000>; }; }; diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h index 2eb14815bc..0dec5e669e 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/lib/andes_plmt.c b/arch/riscv/lib/andes_plmt.c index a7e90ca992..b0245d0b52 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(); + *count = readq((void __iomem *)MTIME_REG(dev->priv)); - *time = readq((void __iomem *)MTIME_REG(gd->arch.plmt)); + 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 0; } 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, }; From patchwork Wed Jul 22 15:51:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1333969 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=gdWhRxdB; 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 4BBg2J25zmz9sPB for ; Thu, 23 Jul 2020 01:52:08 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AA2AC81F67; Wed, 22 Jul 2020 17:51:44 +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="gdWhRxdB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4809B81F2D; Wed, 22 Jul 2020 17:51:35 +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-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) (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 38DE9819EA for ; Wed, 22 Jul 2020 17:51:30 +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-x844.google.com with SMTP id s16so2154268qtn.7 for ; Wed, 22 Jul 2020 08:51:30 -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=kVtJJfsf+AY7WWGieEvvCPsnXcnTD2N7wK9gLUDApU4=; b=gdWhRxdBcSu1dsK3DuHF4Vc0/QU1/SCau/MEyuCJ6W8FG/KBvLKhDqJNGiCbWzxp+X qu+hEXfvdPNN9QMcBSTGojepHrH2eqCYN/LUfVBnR1STRygYaFGeCun4IDySjygGxbM+ pKcuKy3CwWymyOzobT1ISBIO6/7u/WvHuvfk1+bpOTf0YTweNH7QUbmGWGuglusywzmS XZkq4JPL4H8s+Mk4y2Vz5ImssFIFFJFvuTwL8pSXynOmChOlIwe9OeuHesZg1HUvHHBf SNvKWIjoscJ6DEvtf0pF1cHCBPOTStV4mxu2a9CXMb7wTy0KOhkUz3DrMPvlhXn3NUyg 4/Yg== 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=kVtJJfsf+AY7WWGieEvvCPsnXcnTD2N7wK9gLUDApU4=; b=BmJWP9bAEh+g1Z7SIr8D4PSI1F9gIAmAGPek6guZKoLeczKX9j8vxGOG/2gxFvSZBo iRWE4JqJr8132mLgyn+GtO1z9MGE77/KH8fFUtR8btyc/yZNE/gNiqLOHYnhvE4c+W23 dMA4PM0ONGWlZ3GDlJ8Ml4H+0I6EnAgd9JcR7js0nez38s59VWc3KIJ4LkMtZJXs+YrF jFER2Sjxwt2TMi5BJ2s+gEtC2hyCG8lOfoK6hMZE9bjGgQvPjkxA232Gvs/D2IyqI4ig 17Bq8ulfzgouXUbV0wqMCJnRhNO82paAmXenkapqF+FhkcYIN9Gx2ymtyTJ+TLycRAoX 8u6Q== X-Gm-Message-State: AOAM533oRsaQ/3uvuemAV1RP24rR6Au+/JfCl1h9iok3fx3yVRIcPU4Y kt8L8Ky9X+HqbkqUnVDeTZXeXoRnl68= X-Google-Smtp-Source: ABdhPJzkgvRR+xN+m+Um7RiRjUcdZTTTHVLir46tv2pWsa+uZDncvIPxvnt/53AkNGSwK9gvSaTGgQ== X-Received: by 2002:ac8:5389:: with SMTP id x9mr6484500qtp.25.1595433088924; Wed, 22 Jul 2020 08:51:28 -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 z60sm55658qtc.30.2020.07.22.08.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 08:51:28 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson Subject: [PATCH 3/6] riscv: Clean up initialization in Andes PLIC Date: Wed, 22 Jul 2020 11:51:07 -0400 Message-Id: <20200722155110.713966-4-seanga2@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722155110.713966-1-seanga2@gmail.com> References: <20200722155110.713966-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 merges the PLIC initialization code from two functions into one. Signed-off-by: Sean Anderson --- This patch builds but has NOT been tested. arch/riscv/lib/andes_plic.c | 58 ++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/arch/riscv/lib/andes_plic.c b/arch/riscv/lib/andes_plic.c index 5cf29df670..267d6a191b 100644 --- a/arch/riscv/lib/andes_plic.c +++ b/arch/riscv/lib/andes_plic.c @@ -41,53 +41,45 @@ static int enable_ipi(int hart) return 0; } -static int init_plic(void) +int riscv_init_ipi(void) { - struct udevice *dev; - ofnode node; int ret; + long *base = syscon_get_first_range(RISCV_SYSCON_PLIC); + ofnode node; + struct udevice *dev; u32 reg; + if (IS_ERR(base)) + return PTR_ERR(base); + gd->arch.plic = base; + ret = uclass_find_first_device(UCLASS_CPU, &dev); if (ret) return ret; + else if (!dev) + return -ENODEV; - if (ret == 0 && dev) { - ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) { - const char *device_type; + ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) { + const char *device_type; - device_type = ofnode_read_string(node, "device_type"); - if (!device_type) - continue; + device_type = ofnode_read_string(node, "device_type"); + if (!device_type) + continue; - if (strcmp(device_type, "cpu")) - continue; + if (strcmp(device_type, "cpu")) + continue; - /* skip if hart is marked as not available */ - if (!ofnode_is_available(node)) - continue; + /* skip if hart is marked as not available */ + if (!ofnode_is_available(node)) + continue; - /* read hart ID of CPU */ - ret = ofnode_read_u32(node, "reg", ®); - if (ret == 0) - enable_ipi(reg); - } - - return 0; + /* read hart ID of CPU */ + ret = ofnode_read_u32(node, "reg", ®); + if (ret == 0) + enable_ipi(reg); } - return -ENODEV; -} - -int riscv_init_ipi(void) -{ - long *ret = syscon_get_first_range(RISCV_SYSCON_PLIC); - - if (IS_ERR(ret)) - return PTR_ERR(ret); - gd->arch.plic = ret; - - return init_plic(); + return 0; } int riscv_send_ipi(int hart) From patchwork Wed Jul 22 15:51:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1333970 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=KSV3J7DS; 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 4BBg2Y2S4Bz9sPB for ; Thu, 23 Jul 2020 01:52:21 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 06ADD8216F; Wed, 22 Jul 2020 17:51:47 +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="KSV3J7DS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5995081F13; Wed, 22 Jul 2020 17:51:36 +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-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 2C34E819F0 for ; Wed, 22 Jul 2020 17:51:32 +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 k18so2135919qtm.10 for ; Wed, 22 Jul 2020 08:51:32 -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=qYcf5vITReLYIoslAjYguAnwpQNv+MgzPrI9HZnO9A0=; b=KSV3J7DSzFzIRy1BA6g/rN52FwUGnHHCsu2tXnpNBxKGEDk01uGXFiKO+Kw1THxV/f 9ylEqPk1T8AKgM4oRqfJm3vrR3bG29btB2HH5F1yEfbkGpmgZcwTs3LFeFLO7+FNL3hm Frg05cceKKfKnj7KDV0R3jUM/5hqqRC0OEfbFqeIim8IYDxdX+2JVYz5zqYUHxzJi3Sf GsAYJ0+jmzGhhqYNrxAev274S6YxNp85adSya/PPtSrTyir9PPq7EJXl8XH4QxjsAkRZ vcUrxyGIq89moZTE/hEWaSljtLvnYZbvQm3jAzsGixZ0T0lI9hJtrgrMc40XII3GoSie E4PA== 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=qYcf5vITReLYIoslAjYguAnwpQNv+MgzPrI9HZnO9A0=; b=Ms0CpIV9rnp/Z8N8GMO5zkWA5cDXpwU/SAXPiXjYv7JZvDDNzeSC4SyFBYlNDPyzMi Q5xV8Fd+OAs0PC7d5zSX18n+uL7WRGgDtMRyVAklIVwjoO23rIYy+SZZu0tVckCMMX01 MhWBrzFXXGmo1ukUUBUwWMpK697AXpRu4ZUDH9QdrXHj71WyOKlwcwV5lvGsadcFRRFf EGbM/f03Gu+11t/1x7a3SK2QPId/THtUWAWLPBrMc1zGmXgSkMyGOa8tUa7rmBR5+5WQ 11/OaUoM8YnQXnWIcM7IKUgL/LCLvYIeWMndqvP6539k59J4pFVtEuBe8S87fzaGgD1y zhhg== X-Gm-Message-State: AOAM531qrCpBHkTFPSV6jZ5DyrbMiZnoZYnRYDMTNgqUvMX/Cr3L+Xw7 CrVA8Cudm0oAJL91DYIgVNnw0KmTDPI= X-Google-Smtp-Source: ABdhPJxVUPbsTQ+v7LHQvQQO8CiHPOALMEF0JPCXYN81Gz1l1u6Y2wj2MYSFo5sIMAzgiCQ0hnhEjA== X-Received: by 2002:ac8:7b23:: with SMTP id l3mr35156689qtu.65.1595433090176; Wed, 22 Jul 2020 08:51:30 -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 z60sm55658qtc.30.2020.07.22.08.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 08:51:29 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson Subject: [PATCH 4/6] riscv: Rework Sifive CLINT as UCLASS_TIMER driver Date: Wed, 22 Jul 2020 11:51:08 -0400 Message-Id: <20200722155110.713966-5-seanga2@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722155110.713966-1-seanga2@gmail.com> References: <20200722155110.713966-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. We also need to re-add the initialization for IPI back into the SPL code. This was previously implicitly done when the timer was initialized. 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. Signed-off-by: Sean Anderson f --- This patch builds but has only been tested on the K210 and QEMU. It has NOT been tested on a HiFive. arch/riscv/Kconfig | 4 -- arch/riscv/lib/sifive_clint.c | 87 +++++++++++++++++++++++------------ common/spl/spl_opensbi.c | 5 ++ drivers/ram/sifive/Kconfig | 2 + 4 files changed, 64 insertions(+), 34 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 502f27b92d..f2641ffc53 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..3345a17ad2 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,57 @@ 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) +{ + int ret; + ofnode cpu; + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); + u32 rate; + + dev->priv = dev_read_addr_ptr(dev); + if (!dev->priv) + return -EINVAL; + + /* Did we get our clock rate from the device tree? */ + if (uc_priv->clock_rate) + return 0; + + /* Fall back to timebase-frequency */ + cpu = ofnode_path("/cpus"); + if (!ofnode_valid(cpu)) + return -EINVAL; + + ret = ofnode_read_u32(cpu, "timebase-frequency", &rate); + if (ret) + return ret; + + log_warning("missing clocks or clock-frequency property, falling back on timebase-frequency\n"); + uc_priv->clock_rate = rate; + + return 0; +} + 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, }; diff --git a/common/spl/spl_opensbi.c b/common/spl/spl_opensbi.c index 14f335f75f..3440bc0294 100644 --- a/common/spl/spl_opensbi.c +++ b/common/spl/spl_opensbi.c @@ -79,6 +79,11 @@ void spl_invoke_opensbi(struct spl_image_info *spl_image) invalidate_icache_all(); #ifdef CONFIG_SPL_SMP + /* Initialize the IPI before we use it */ + ret = riscv_init_ipi(); + if (ret) + hang(); + /* * Start OpenSBI on all secondary harts and wait for acknowledgment. * diff --git a/drivers/ram/sifive/Kconfig b/drivers/ram/sifive/Kconfig index 6aca22ab2a..31ad0a7e45 100644 --- a/drivers/ram/sifive/Kconfig +++ b/drivers/ram/sifive/Kconfig @@ -9,5 +9,7 @@ config SIFIVE_FU540_DDR bool "SiFive FU540 DDR driver" depends on RAM_SIFIVE default y if TARGET_SIFIVE_FU540 + select REGMAP + select SPL_REGMAP if SPL help This enables DDR support for the platforms based on SiFive FU540 SoC. From patchwork Wed Jul 22 15:51:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1333974 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=WK8W11FR; 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 4BBg2p1rV8z9sPB for ; Thu, 23 Jul 2020 01:52:34 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0C87E820DB; Wed, 22 Jul 2020 17:51: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=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="WK8W11FR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8039D81F13; Wed, 22 Jul 2020 17:51:37 +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-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (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 99A4E81F2C for ; Wed, 22 Jul 2020 17:51:33 +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-x744.google.com with SMTP id j187so2387131qke.11 for ; Wed, 22 Jul 2020 08:51:33 -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=whEjgFZPUYEi2xpU8Wr4RS2+D16UdajP3MNG9vAvl2g=; b=WK8W11FRS+NAR8hAhVFyQmeYumsCtCg6I3UrhzJR0t7gP3VG1huVNvHpk3Suq4l4LK RCHOHUCQ+U74vdsqnsqy7Np6viHe6lFi/4n1IIx8TtqBVOXOs8sjWvkiUJfz1qjYCUEf 8LpIdMydR2Boij58RoIskx6e75lkyj2gY5+nRgO6n4UEVMFMT78ttfm28BfZR4fnXQ1Z tPZ971Phsc/hoTgN6P4weRoeP/pLI7egXyk6ernEgVYLCH4fE/mXCBdlUFFC1Em0Y/pj 7wCqdSDmOyVICwInq1b3F3d7NHY/LKeXdBTX3JxMdakjStAkLfCCKupCxJGRV4ASHhFm eCLA== 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=whEjgFZPUYEi2xpU8Wr4RS2+D16UdajP3MNG9vAvl2g=; b=cbf5EGK4gbW0Ht/IRCNsAVdtuqysISx7PbXxf4mquJ9roezOs2bt0+6vuObK09NTGd wBQI2+WalAEj4xY1ngECVwMfuJt2zm6W41LS0tS+c5SGVU1X2dN4/s2IJZEXeQNc8YSx b7WNDzIAcGbMh+4pj796jJwLA5HzwzUfrHsUH2r+HezE3ee6MgctOnXbwRx6BucuVmOv YsoZJEKSQQ90Uz/7vxawJX+Q4SorIuVqkKsX2Y/uUHyXzW9OlAvwXCx9nqpg9++AY9Es nSd7Odcc6Dr8pemxv/ZmhTsAE0ZClhdQCUk3VFXY4wmbqts3qaMCmkKtwttXhY0cvaMk 2dKw== X-Gm-Message-State: AOAM533DoS9hu3qT0Qi2MvYoBUmoj9fZOVjD/OouTfbq5Pi7gWsQMHzM sU84ZPYVKuKxjfiiYz37KIhQKrBEd+g= X-Google-Smtp-Source: ABdhPJxJb1lDopqzxDY343xsZEoFtt6OvhajNrX960SegTiYQAdzn+cSNLgNWhoKI/btFhhtla1o5w== X-Received: by 2002:a37:b0c5:: with SMTP id z188mr601913qke.412.1595433092129; Wed, 22 Jul 2020 08:51:32 -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 z60sm55658qtc.30.2020.07.22.08.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 08:51:30 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson Subject: [PATCH 5/6] riscv: Update Kendryte device tree for new CLINT driver Date: Wed, 22 Jul 2020 11:51:09 -0400 Message-Id: <20200722155110.713966-6-seanga2@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722155110.713966-1-seanga2@gmail.com> References: <20200722155110.713966-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 AFAIK because the K210 clock driver does not come up until after relocation, the clint will always use the clock-frequency parameter. Ideally, it should update itself after relocation to take into account the actual CPU frequency. Signed-off-by: Sean Anderson --- arch/riscv/dts/k210.dtsi | 10 ++++++---- drivers/clk/kendryte/clk.c | 4 ++++ include/dt-bindings/clock/k210-sysctl.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/riscv/dts/k210.dtsi b/arch/riscv/dts/k210.dtsi index 2546c7d4e0..9583694c46 100644 --- a/arch/riscv/dts/k210.dtsi +++ b/arch/riscv/dts/k210.dtsi @@ -17,6 +17,8 @@ compatible = "kendryte,k210"; aliases { + cpu0 = &cpu0; + cpu1 = &cpu1; dma0 = &dmac0; gpio0 = &gpio0; gpio1 = &gpio1_0; @@ -40,7 +42,6 @@ cpus { #address-cells = <1>; #size-cells = <0>; - timebase-frequency = <7800000>; cpu0: cpu@0 { device_type = "cpu"; compatible = "kendryte,k210", "sifive,rocket0", "riscv"; @@ -126,14 +127,15 @@ read-only; }; - clint0: interrupt-controller@2000000 { + clint0: clint@2000000 { #interrupt-cells = <1>; compatible = "kendryte,k210-clint", "riscv,clint0"; reg = <0x2000000 0xC000>; - interrupt-controller; interrupts-extended = <&cpu0_intc 3>, <&cpu0_intc 7>, <&cpu1_intc 3>, <&cpu1_intc 7>; - clocks = <&sysclk K210_CLK_CPU>; + clocks = <&sysclk K210_CLK_CLINT>; + /* sysclk is only available post-relocation */ + clock-frequency = <7800000>; }; plic0: interrupt-controller@C000000 { diff --git a/drivers/clk/kendryte/clk.c b/drivers/clk/kendryte/clk.c index 981b3b7699..bb196961af 100644 --- a/drivers/clk/kendryte/clk.c +++ b/drivers/clk/kendryte/clk.c @@ -646,6 +646,10 @@ static int k210_clk_probe(struct udevice *dev) REGISTER_GATE(K210_CLK_RTC, "rtc", in0); #undef REGISTER_GATE + /* The MTIME register in CLINT runs at one 50th the CPU clock speed */ + clk_dm(K210_CLK_CLINT, + clk_register_fixed_factor(NULL, "clint", "cpu", 0, 1, 50)); + return 0; } diff --git a/include/dt-bindings/clock/k210-sysctl.h b/include/dt-bindings/clock/k210-sysctl.h index 0e3ed3fb9f..fe852bbd92 100644 --- a/include/dt-bindings/clock/k210-sysctl.h +++ b/include/dt-bindings/clock/k210-sysctl.h @@ -55,5 +55,6 @@ #define K210_CLK_OTP 43 #define K210_CLK_RTC 44 #define K210_CLK_ACLK 45 +#define K210_CLK_CLINT 46 #endif /* CLOCK_K210_SYSCTL_H */ From patchwork Wed Jul 22 15:51:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1333976 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=d8Lhcxf0; 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 4BBg303303z9sPB for ; Thu, 23 Jul 2020 01:52:44 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4853481F3F; Wed, 22 Jul 2020 17:52:05 +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="d8Lhcxf0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1A65A81F2C; Wed, 22 Jul 2020 17:51:38 +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-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 3E16B81E6F for ; Wed, 22 Jul 2020 17:51:34 +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 e13so2420558qkg.5 for ; Wed, 22 Jul 2020 08:51:34 -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=PJGUtRS+pTXszRjOYuacIbdu/85vGcEytuOKvV7jCpc=; b=d8Lhcxf0GQ1GXgFCKMUZgasUJSHB6Ay0U4wk4VG6Ye3/MEdQl/z6f9Ih64j5KkLRHc GTSBMjVywxbwcVNdc7yVysaTSMOUV6z+N9qYTu+Tn2GOX5KMO7uUB4481MuTZSGCmlyK 3ZrWtpov5tLrj/HsAXwvfYf9/6d3cwjh5AfbAMdzU0qRpw464dWOrfhUQqgbixKCbNJ9 eZu7Vhcg9mOswmCmZ8j9P/mN+GH2Pu/1r5sUa8ra6QMPJysF2mtcjLh8/v2MLtyIjn/S AuJKpSv3gGZZjhgE93MbELp2t6S0L2mEJ1EmkLDP52pUN7mRfsQspqnsqDkHHvUiLvxJ 2EsQ== 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=PJGUtRS+pTXszRjOYuacIbdu/85vGcEytuOKvV7jCpc=; b=NtY6QP1KFTS5vkVVYzT+it4oB64OIUl2DPwcVy+xa5ILyiEZ1mTJnRTKQ1t+oLZWed RqIE3x2TTPZ/T3uIyH7UzC9MGb8s2ZN1AnfPekLWOvUbIAET22YmiR4ZtGjm4KYx7Lb0 kMyHaDhNC9AxfDqqR836acjeHfBK532GgbfQItnk1PofJApUTFJCBSKdq+A56HVFE55Z NTLJ5iNThEspGSbq3mAJMyC8ej2AtMOPloYN88Vy9fDvhS+FDh/dvpVVFR+LtjGFXaMg bCFYFZu1l6603ny1aFKhr1fgfG+pXOvwdjCfyyvqIk2nPh3lIrWHwPsyMH8Mv4VevIPr zfwA== X-Gm-Message-State: AOAM533RD+dsBpg4k+0/mJmx0kba+5rwD8lvJ39/V1BzQ98Ozqfu4MEJ 9QzFwIei6Uckxe0ZhWPcHA+CuQ4o7gk= X-Google-Smtp-Source: ABdhPJxX/5snzD9xvdbjFMZyVCmM97TJkijxvLloxWF1w1CK+UwjiyDDUaBZLGNg3q78QTSivzRowg== X-Received: by 2002:a05:620a:c08:: with SMTP id l8mr567155qki.239.1595433092958; Wed, 22 Jul 2020 08:51:32 -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 z60sm55658qtc.30.2020.07.22.08.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 08:51:32 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson Subject: [PATCH 6/6] riscv: Update SiFive device tree for new CLINT driver Date: Wed, 22 Jul 2020 11:51:10 -0400 Message-Id: <20200722155110.713966-7-seanga2@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722155110.713966-1-seanga2@gmail.com> References: <20200722155110.713966-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 We may need to add a clock-frequency binding like for the K210. Signed-off-by: Sean Anderson --- This patch builds but has NOT been tested. arch/riscv/dts/fu540-c000-u-boot.dtsi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/riscv/dts/fu540-c000-u-boot.dtsi b/arch/riscv/dts/fu540-c000-u-boot.dtsi index afdb4f4402..e56bfc7595 100644 --- a/arch/riscv/dts/fu540-c000-u-boot.dtsi +++ b/arch/riscv/dts/fu540-c000-u-boot.dtsi @@ -55,8 +55,13 @@ }; clint@2000000 { compatible = "riscv,clint0"; - interrupts-extended = <&cpu0_intc 3 &cpu0_intc 7 &cpu1_intc 3 &cpu1_intc 7 &cpu2_intc 3 &cpu2_intc 7 &cpu3_intc 3 &cpu3_intc 7 &cpu4_intc 3 &cpu4_intc 7>; + interrupts-extended = <&cpu0_intc 3 &cpu0_intc 7 + &cpu1_intc 3 &cpu1_intc 7 + &cpu2_intc 3 &cpu2_intc 7 + &cpu3_intc 3 &cpu3_intc 7 + &cpu4_intc 3 &cpu4_intc 7>; reg = <0x0 0x2000000 0x0 0xc0000>; + clocks = <&prci PRCI_CLK_COREPLL>; u-boot,dm-spl; }; dmc: dmc@100b0000 {