From owner-dev-commits-src-all@freebsd.org Sat Aug 7 18:28:20 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B67B066F56B; Sat, 7 Aug 2021 18:28:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GhrSh4LBVz4ZSh; Sat, 7 Aug 2021 18:28:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7C4DA25F1A; Sat, 7 Aug 2021 18:28:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 177ISKIM082472; Sat, 7 Aug 2021 18:28:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 177ISKBu082471; Sat, 7 Aug 2021 18:28:20 GMT (envelope-from git) Date: Sat, 7 Aug 2021 18:28:20 GMT Message-Id: <202108071828.177ISKBu082471@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: 8e7e0690ecd7 - main - sifive_prci: Add reset support for the FU540 and FU740 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8e7e0690ecd79e8adc9182d486c05748bd97d26d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Aug 2021 18:28:20 -0000 The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=8e7e0690ecd79e8adc9182d486c05748bd97d26d commit 8e7e0690ecd79e8adc9182d486c05748bd97d26d Author: Jessica Clarke AuthorDate: 2021-08-07 18:27:29 +0000 Commit: Jessica Clarke CommitDate: 2021-08-07 18:27:29 +0000 sifive_prci: Add reset support for the FU540 and FU740 This is needed for FU740 PCIe support. Whilst we don't need the FU540's resets they are also defined for completeness. Reviewed by: manu MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31024 --- sys/riscv/conf/GENERIC | 1 + sys/riscv/sifive/sifive_prci.c | 57 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/sys/riscv/conf/GENERIC b/sys/riscv/conf/GENERIC index c6cd8e0fdedb..2af5f8803be7 100644 --- a/sys/riscv/conf/GENERIC +++ b/sys/riscv/conf/GENERIC @@ -82,6 +82,7 @@ device rcons # EXT_RESOURCES pseudo devices options EXT_RESOURCES device clk +device hwreset device syscon device syscon_power device riscv_syscon diff --git a/sys/riscv/sifive/sifive_prci.c b/sys/riscv/sifive/sifive_prci.c index 36f2f6705f7e..fee67bb153ac 100644 --- a/sys/riscv/sifive/sifive_prci.c +++ b/sys/riscv/sifive/sifive_prci.c @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include "clkdev_if.h" +#include "hwreset_if.h" static struct resource_spec prci_spec[] = { { SYS_RES_MEMORY, 0, RF_ACTIVE }, @@ -69,6 +70,8 @@ struct prci_softc { struct resource *res; bus_space_tag_t bst; bus_space_handle_t bsh; + + int nresets; }; struct prci_clk_pll_sc { @@ -94,6 +97,9 @@ struct prci_clk_div_sc { #define PRCI_PLL_DIVQ_MASK 0x38000 #define PRCI_PLL_DIVQ_SHIFT 15 +/* Called devicesresetreg on the FU540 */ +#define PRCI_DEVICES_RESET_N 0x28 + #define PRCI_READ(_sc, _reg) \ bus_space_read_4((_sc)->bst, (_sc)->bsh, (_reg)) #define PRCI_WRITE(_sc, _reg, _val) \ @@ -155,6 +161,7 @@ struct prci_config { struct prci_div_def *div_clks; struct prci_gate_def *gate_clks; struct clk_fixed_def *tlclk_def; + int nresets; }; /* FU540 clock numbers */ @@ -191,6 +198,7 @@ static struct clk_fixed_def fu540_tlclk_def = { struct prci_config fu540_prci_config = { .pll_clks = fu540_pll_clks, .tlclk_def = &fu540_tlclk_def, + .nresets = 6, }; /* FU740 clock numbers */ @@ -254,6 +262,7 @@ struct prci_config fu740_prci_config = { .div_clks = fu740_div_clks, .gate_clks = fu740_gate_clks, .tlclk_def = &fu740_tlclk_def, + .nresets = 7, }; static struct ofw_compat_data compat_data[] = { @@ -547,6 +556,8 @@ prci_attach(device_t dev) if (error) panic("Couldn't finalise clock domain"); + sc->nresets = cfg->nresets; + return (0); fail1: @@ -616,6 +627,48 @@ prci_device_unlock(device_t dev) PRCI_UNLOCK(sc); } +static int +prci_reset_assert(device_t dev, intptr_t id, bool reset) +{ + struct prci_softc *sc; + uint32_t reg; + + sc = device_get_softc(dev); + + if (id >= sc->nresets) + return (ENXIO); + + PRCI_LOCK(sc); + reg = PRCI_READ(sc, PRCI_DEVICES_RESET_N); + if (reset) + reg &= ~(1u << id); + else + reg |= (1u << id); + PRCI_WRITE(sc, PRCI_DEVICES_RESET_N, reg); + PRCI_UNLOCK(sc); + + return (0); +} + +static int +prci_reset_is_asserted(device_t dev, intptr_t id, bool *reset) +{ + struct prci_softc *sc; + uint32_t reg; + + sc = device_get_softc(dev); + + if (id >= sc->nresets) + return (ENXIO); + + PRCI_LOCK(sc); + reg = PRCI_READ(sc, PRCI_DEVICES_RESET_N); + *reset = (reg & (1u << id)) == 0; + PRCI_UNLOCK(sc); + + return (0); +} + static device_method_t prci_methods[] = { DEVMETHOD(device_probe, prci_probe), DEVMETHOD(device_attach, prci_attach), @@ -627,6 +680,10 @@ static device_method_t prci_methods[] = { DEVMETHOD(clkdev_device_lock, prci_device_lock), DEVMETHOD(clkdev_device_unlock, prci_device_unlock), + /* Reset interface */ + DEVMETHOD(hwreset_assert, prci_reset_assert), + DEVMETHOD(hwreset_is_asserted, prci_reset_is_asserted), + DEVMETHOD_END };