From nobody Thu Jan 16 17:33:11 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YYqhR6dSHz5kj2r; Thu, 16 Jan 2025 17:33:11 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YYqhR5m3pz3NlV; Thu, 16 Jan 2025 17:33:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737048791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GeoFUnum3GqjyFnCkI1IrDq9LegW05589futcJsIwJg=; b=JNFo55TOuTpkjSyLGJKyTnJOkB/SvsEACkC749FS5+XipZVOH+3boVG+aN+VdxDm8MgEwE lwKGcSFLuO7o8lQSB61gb6E1esaPdrA6t+r63tQI6QlcMNgmK+pqAvhYcFiXVa39ArEKCy pMq14ryefcqb7arAewE5GltzA37vvXQMBdGwxNqXdWdf8GneYuWM+sdGZW5FQMxykSular 0nD7XXCsHE/GARoF95Bn/VoK941MGVUtVgL4UkIMa8nArxgc6vBI4RiCh4DPeMgdkINx1b XHWm1lnm8q0feDCWaq0H0Bt5hJ+4wKlNqc4UiHer9mM5uKicCcDtDoSFMq40Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737048791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GeoFUnum3GqjyFnCkI1IrDq9LegW05589futcJsIwJg=; b=v7ejl8upPB+66PjCE6FmBBaC0h+KdcgbH240yJImI0t1AS+0aU1mWFJKL56m33dQIwzheC V/I3msenX62Nn1/U1MNB0nrx61FOjaTWb4ZyoL+h/iY4slhch55YPPFZ8EdrOSqxXof/lz CvFUA4XK2E+fzBRPqZQ7tRnFOQPFRcA3lTXFcX0HdAQLwkWfYXp3vimxjERHBSxVdVOwJ1 bwIeDSrGWiJw/lHKTtw1CQT4R36qrTYNVW/7pVAJDv3ijmFFvlm/vPFMhCGZKZHM2areHr 71+bPoo7S+OyTHCsf1jTfn9XVF9dW6UzNfnXbitk6EbXOBL7bGdUdcdHL9WrTw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737048791; a=rsa-sha256; cv=none; b=u3AcoHA+LNKKVK0tTQh7BXCgmD3KyLlPZBFT1wy22AVzQQp0dRFHTznMWYW3XzB9Bp1MeR tCK3yJNyLdv0dC8uTflHnUY6dpgkMNkECdtrcxKxHS0RsL2fiNdd8LKKuyyXwBt20W3EBT FdmE1PH+6bLTbFbEqqtww/ps5TnD1Tq05WFuM9OdQcm97p6vSwyvAc9kbAbUEYwPhwUBZ3 4dLkJBd21iAQA9Zkrw5pjUU2nBK7HBXBTmF2cGg4m1recqYfNN0/DpPucVpMS8+Rs4KVVZ OiGC8jmNUbI9k7PxgK4cAOFHm9OTfrOczXaZCg+8+IHEFIqM9xfyJKT3I87kMA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YYqhR5FfTzhtG; Thu, 16 Jan 2025 17:33:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50GHXBUG033546; Thu, 16 Jan 2025 17:33:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50GHXBV9033543; Thu, 16 Jan 2025 17:33:11 GMT (envelope-from git) Date: Thu, 16 Jan 2025 17:33:11 GMT Message-Id: <202501161733.50GHXBV9033543@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 6f2775548278 - main - armada38x: implement gateclk clkdev methods List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6f2775548278c76e7c33b15aaaaa759270a8dcd5 Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=6f2775548278c76e7c33b15aaaaa759270a8dcd5 commit 6f2775548278c76e7c33b15aaaaa759270a8dcd5 Author: Mitchell Horne AuthorDate: 2024-04-15 20:18:25 +0000 Commit: Mitchell Horne CommitDate: 2025-01-16 17:27:00 +0000 armada38x: implement gateclk clkdev methods Implement basic clkdev methods required by the generic clk_gate device. This should make it functional, and prevent panics when invoking the clock's CLKNODE_GET_GATE method (e.g. with `sysctl -a`). Additionally, we need to fill in other key fields of the clk_gate_def structure before registering each clk. PR: 278188 Reported by: solo_code@protonmail.com Tested by: solo_code@protonmail.com MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D48419 --- sys/arm/mv/clk/armada38x_gateclk.c | 99 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/sys/arm/mv/clk/armada38x_gateclk.c b/sys/arm/mv/clk/armada38x_gateclk.c index 24355d9c9dac..0cc91b447199 100644 --- a/sys/arm/mv/clk/armada38x_gateclk.c +++ b/sys/arm/mv/clk/armada38x_gateclk.c @@ -43,11 +43,22 @@ #include "clkdev_if.h" +#define ARMADA38X_GATECLK_MAXREG 0 + +static struct resource_spec armada38x_gateclk_specs[] = { + { SYS_RES_MEMORY, 0, RF_ACTIVE }, + { -1, 0 } +}; + +#define RD4(_sc, addr) bus_read_4(_sc->res, addr) +#define WR4(_sc, addr, val) bus_write_4(_sc->res, addr, val) + struct armada38x_gateclk_softc { - struct clkdom *clkdom; - struct mtx mtx; - const char* parent; + struct resource *res; + struct clkdom *clkdom; + struct mtx mtx; + const char* parent; }; static struct clk_gate_def gateclk_nodes[] = @@ -219,10 +230,75 @@ static struct clk_gate_def gateclk_nodes[] = static int armada38x_gateclk_probe(device_t dev); static int armada38x_gateclk_attach(device_t dev); +static int +armada38x_gateclk_write_4(device_t dev, bus_addr_t addr, uint32_t val) +{ + struct armada38x_gateclk_softc *sc = device_get_softc(dev); + + if (addr > ARMADA38X_GATECLK_MAXREG) + return (EINVAL); + + WR4(sc, addr, val); + return (0); +} + +static int +armada38x_gateclk_read_4(device_t dev, bus_addr_t addr, uint32_t *val) +{ + struct armada38x_gateclk_softc *sc = device_get_softc(dev); + + if (addr > ARMADA38X_GATECLK_MAXREG) + return (EINVAL); + + *val = RD4(sc, addr); + return (0); +} + +static int +armada38x_gateclk_modify_4(device_t dev, bus_addr_t addr, uint32_t clr, + uint32_t set) +{ + struct armada38x_gateclk_softc *sc = device_get_softc(dev); + uint32_t reg; + + if (addr > ARMADA38X_GATECLK_MAXREG) + return (EINVAL); + + reg = RD4(sc, addr); + reg &= ~clr; + reg |= set; + WR4(sc, addr, reg); + + return (0); +} + +static void +armada38x_gateclk_device_lock(device_t dev) +{ + struct armada38x_gateclk_softc *sc = device_get_softc(dev); + + mtx_lock(&sc->mtx); +} + +static void +armada38x_gateclk_device_unlock(device_t dev) +{ + struct armada38x_gateclk_softc *sc = device_get_softc(dev); + + mtx_unlock(&sc->mtx); +} + static device_method_t armada38x_gateclk_methods[] = { DEVMETHOD(device_probe, armada38x_gateclk_probe), DEVMETHOD(device_attach, armada38x_gateclk_attach), + /* clkdev interface */ + DEVMETHOD(clkdev_write_4, armada38x_gateclk_write_4), + DEVMETHOD(clkdev_read_4, armada38x_gateclk_read_4), + DEVMETHOD(clkdev_modify_4, armada38x_gateclk_modify_4), + DEVMETHOD(clkdev_device_lock, armada38x_gateclk_device_lock), + DEVMETHOD(clkdev_device_unlock, armada38x_gateclk_device_unlock), + DEVMETHOD_END }; @@ -254,6 +330,7 @@ static int armada38x_gateclk_attach(device_t dev) { struct armada38x_gateclk_softc *sc; + struct clk_gate_def *defp; phandle_t node; int i, error; clk_t clock; @@ -261,6 +338,11 @@ armada38x_gateclk_attach(device_t dev) sc = device_get_softc(dev); node = ofw_bus_get_node(dev); + if (bus_alloc_resources(dev, armada38x_gateclk_specs, &sc->res) != 0) { + device_printf(dev, "Cannot allocate resources.\n"); + return (ENXIO); + } + mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); sc->clkdom = clkdom_create(dev); @@ -276,8 +358,15 @@ armada38x_gateclk_attach(device_t dev) sc->parent = clk_get_name(clock); for (i = 0; i < nitems(gateclk_nodes); ++i) { - gateclk_nodes[i].clkdef.parent_names = &sc->parent; - error = clknode_gate_register(sc->clkdom, &gateclk_nodes[i]); + /* Fill clk_gate fields. */ + defp = &gateclk_nodes[i]; + defp->clkdef.parent_names = &sc->parent; + defp->offset = 0; + defp->mask = 0x1; + defp->on_value = 1; + defp->off_value = 0; + + error = clknode_gate_register(sc->clkdom, defp); if (error != 0) { device_printf(dev, "Cannot create gate nodes\n"); return (error);