From nobody Mon Jan 23 12:37:44 2023 X-Original-To: dev-commits-src-branches@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 4P0qPh6382z3bT65; Mon, 23 Jan 2023 12:37:44 +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 4P0qPh2pBnz3Ccp; Mon, 23 Jan 2023 12:37:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674477464; 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=pMguKDez53/yNzj81PVR7Uf5ezXh67csoeYn9kI6FbU=; b=MzIr6YAhfh3DMfamYJtkueBh0IWoXQMiX3hYDLQZrGyXNIwHtgkVGAEpAHx7xMvKxlrp+1 LYqwO43+Rhf94BO57wV8LobfJG5JkLukuNS31A5kb0XbF0HWRQVT98Ff5EmDxdsliW0VsY We/UK59eplw88wpuyx7u4T1XeqwFtNbnn4UZJWLDKBvtvgif359WPRzBwOAnFK3CV00Uk1 NijPFoMDUd21YLtIcpjguAkL5TUFlfMsGJq/c2ciQfjFadWMop3xvFZJUhUgctnyGKPhkl I7UbMCrfykHR10bojidR4LLtmtTJTxiDwRGXOULYyozZkNumI4Kw/CiiorZAVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674477464; 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=pMguKDez53/yNzj81PVR7Uf5ezXh67csoeYn9kI6FbU=; b=PbrvWB237imLeqz+sAUDfpS3To6dJbJAs1tkXuO5yxo8DnSbMDxwZrIP8nuyhGFCUFRVPR 0KmPjyP34eBnv/d2smZiON83FVbIOAFJcOg/5NyGNCh9xwDJpJNQiVr+p01SHkvCv0KmAg XBhrNCT0dwkut7VStEGYPaQIXihkEfMFbkcVONkZl1PukrHlZzqbEXPW1OZLJgUmy+Znny UJw079P3U1ewUVyBQ0pmJqjF5pPhBL656LUXPhw2e1bLM+QW2/L67RBekzWk99oqvreLsh SQYW3Ome2vje0WCtsLgZ8+zLRB9/Y+FPh+XS3CDXfILddPNqiqrzeGeeTFFCOg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674477464; a=rsa-sha256; cv=none; b=AUDBYD+Ui+i6VTzRKRCHSrfEhWElbsCYO6Df8eXgYoJEqrJMhjxPBu4tykioBZBk8ZaSF8 3x4GRmvczW3jXWRhpmTLXsnDZpmt2uy9/ULD4MmOGMZTWq2IAnsssFqhsRJ4dwOWGdT3eg y+iBgAD/TvIZKWxerxpZTLNS+9XVWwNoVTzU0RY+UKShkR/LEo+gf0/Pifn7Cc3RVTR2gA 2I5Ia8WcoRCHK6s4XaRE0uvbv25oLGys2D4jWItz9FzlM4K7rxlXVUV0COtR1Yz+c1oGWf MMjTs5+ntDstyADw44WX424jM4dD1cwfh1J3l53lov04JwFUxJn0yKxY+rAz9g== 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 4P0qPh1p2lzTHN; Mon, 23 Jan 2023 12:37:44 +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 30NCbit2085499; Mon, 23 Jan 2023 12:37:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30NCbiF3085498; Mon, 23 Jan 2023 12:37:44 GMT (envelope-from git) Date: Mon, 23 Jan 2023 12:37:44 GMT Message-Id: <202301231237.30NCbiF3085498@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Turner Subject: git: 5930ae92913b - stable/13 - Add support for an array of hwresets List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5930ae92913b86642727720518f8fd3144426e39 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=5930ae92913b86642727720518f8fd3144426e39 commit 5930ae92913b86642727720518f8fd3144426e39 Author: Andrew Turner AuthorDate: 2022-11-11 08:55:59 +0000 Commit: Andrew Turner CommitDate: 2023-01-23 12:36:28 +0000 Add support for an array of hwresets In some drivers we need to assert and deassert a group of hardware resets in any order. To support this add a new hwreset_array that manages all hwresets defined for a device. Reviewed by: bz, manu, mmel Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37357 (cherry picked from commit 969935b86b179b2b517ab5d35d943fcb761203c1) --- sys/conf/files | 1 + sys/dev/extres/hwreset/hwreset.h | 8 ++ sys/dev/extres/hwreset/hwreset_array.c | 139 +++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) diff --git a/sys/conf/files b/sys/conf/files index d97ad247a7bd..1dc36fd6f132 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1759,6 +1759,7 @@ dev/extres/phy/phy_usb.c optional phy fdt dev/extres/phy/phynode_usb_if.m optional phy fdt dev/extres/hwreset/hwreset.c optional hwreset fdt dev/extres/hwreset/hwreset_if.m optional hwreset fdt +dev/extres/hwreset/hwreset_array.c optional hwreset dev/extres/nvmem/nvmem.c optional nvmem fdt dev/extres/nvmem/nvmem_if.m optional nvmem fdt dev/extres/regulator/regdev_if.m optional regulator fdt diff --git a/sys/dev/extres/hwreset/hwreset.h b/sys/dev/extres/hwreset/hwreset.h index dd9290a9784c..02a0b4fe15a0 100644 --- a/sys/dev/extres/hwreset/hwreset.h +++ b/sys/dev/extres/hwreset/hwreset.h @@ -35,6 +35,7 @@ #endif typedef struct hwreset *hwreset_t; +typedef struct hwreset_array *hwreset_array_t; /* * Provider interface @@ -62,6 +63,13 @@ int hwreset_get_by_ofw_idx(device_t consumer_dev, phandle_t node, int idx, hwreset_t *rst); #endif +void hwreset_array_release(hwreset_array_t rsts); +int hwreset_array_assert(hwreset_array_t rsts); +int hwreset_array_deassert(hwreset_array_t rsts); +#ifdef FDT +int hwreset_array_get_ofw(device_t consumer_dev, phandle_t cnode, + hwreset_array_t *rsts); +#endif #endif /* DEV_EXTRES_HWRESET_HWRESET_H */ diff --git a/sys/dev/extres/hwreset/hwreset_array.c b/sys/dev/extres/hwreset/hwreset_array.c new file mode 100644 index 000000000000..c90bef9aafe8 --- /dev/null +++ b/sys/dev/extres/hwreset/hwreset_array.c @@ -0,0 +1,139 @@ +/*- + * Copyright (c) 2022 The FreeBSD Foundation + * + * This software was developed by Andrew Turner under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * This manages all hwresets for a device and asserts/deasserts them in + * an undefined order. + */ + +#include "opt_platform.h" +#include +#include +#include + +#ifdef FDT +#include +#include +#endif + +#include + +MALLOC_DECLARE(M_HWRESET); + +struct hwreset_array { + hwreset_t *rst_array; + int count; +}; + +int +hwreset_array_assert(hwreset_array_t rsts) +{ + int i, rv; + + for (i = 0; i < rsts->count; i++) { + rv = hwreset_assert(rsts->rst_array[i]); + if (rv != 0) + return (rv); + } + + return (0); +} + +int +hwreset_array_deassert(hwreset_array_t rsts) +{ + int i, rv; + + for (i = 0; i < rsts->count; i++) { + rv = hwreset_deassert(rsts->rst_array[i]); + if (rv != 0) + return (rv); + } + + return (0); +} + +void +hwreset_array_release(hwreset_array_t rsts) +{ + int i; + + for (i = 0; i < rsts->count; i++) { + hwreset_release(rsts->rst_array[i]); + } + free(rsts->rst_array, M_HWRESET); + free(rsts, M_HWRESET); +} + +#ifdef FDT +int +hwreset_array_get_ofw(device_t consumer_dev, phandle_t cnode, + hwreset_array_t *rsts) +{ + hwreset_array_t resets; + int count, i, rv; + + if (cnode <= 0) + cnode = ofw_bus_get_node(consumer_dev); + if (cnode <= 0) { + device_printf(consumer_dev, + "%s called on not ofw based device\n", __func__); + return (ENXIO); + } + + rv = ofw_bus_parse_xref_list_get_length(cnode, "resets", "#reset-cells", + &count); + if (rv != 0) + return (rv); + + resets = malloc(sizeof(struct hwreset_array), M_HWRESET, + M_WAITOK | M_ZERO); + resets->rst_array = mallocarray(count, sizeof(hwreset_t), M_HWRESET, + M_WAITOK | M_ZERO); + + for (i = 0; i < count; i++) { + rv = hwreset_get_by_ofw_idx(consumer_dev, cnode, i, + &resets->rst_array[i]); + if (rv != 0) + break; + } + + if (rv != 0) { + count = i; + for (i = 0; i < count; i++) { + hwreset_release(resets->rst_array[i]); + } + free(resets->rst_array, M_HWRESET); + free(resets, M_HWRESET); + } else { + resets->count = count; + *rsts = resets; + } + return (rv); +} +#endif