From nobody Sat Nov 06 08:11:30 2021 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 F2D021834738; Sat, 6 Nov 2021 08:11:31 +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 4HmVSz0M9qz3QC3; Sat, 6 Nov 2021 08:11:30 +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 2BEE72794E; Sat, 6 Nov 2021 08:11:30 +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 1A68BUJe041089; Sat, 6 Nov 2021 08:11:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A68BUBo041088; Sat, 6 Nov 2021 08:11:30 GMT (envelope-from git) Date: Sat, 6 Nov 2021 08:11:30 GMT Message-Id: <202111060811.1A68BUBo041088@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: b8b7c0dda9a0 - main - qoriq_gpio: Add support for driver inheritance 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b8b7c0dda9a085902f702f8c89271b852aa898a4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=b8b7c0dda9a085902f702f8c89271b852aa898a4 commit b8b7c0dda9a085902f702f8c89271b852aa898a4 Author: Kornel Duleba AuthorDate: 2021-10-29 14:06:35 +0000 Commit: Wojciech Macek CommitDate: 2021-11-06 08:08:45 +0000 qoriq_gpio: Add support for driver inheritance Expose softc and other necessary things in a separate header. This is needed for an armv8 specific driver, that will inherit from this one. Driver mutex was converted to a spin lock, so that it can be later used in interrupt filter context. Obtained from: Semihalf Sponsored by: Alstom Group Differential revision: https://reviews.freebsd.org/D32587 --- sys/dev/gpio/qoriq_gpio.c | 44 +++++--------------------------- sys/dev/gpio/qoriq_gpio.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 38 deletions(-) diff --git a/sys/dev/gpio/qoriq_gpio.c b/sys/dev/gpio/qoriq_gpio.c index dc4813e07b8e..eb790eb50d29 100644 --- a/sys/dev/gpio/qoriq_gpio.c +++ b/sys/dev/gpio/qoriq_gpio.c @@ -46,40 +46,12 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include "gpio_if.h" -#define MAXPIN (31) - -#define VALID_PIN(u) ((u) >= 0 && (u) <= MAXPIN) -#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \ - GPIO_PIN_OPENDRAIN | GPIO_PIN_PUSHPULL) - -#define GPIO_LOCK(sc) mtx_lock(&(sc)->sc_mtx) -#define GPIO_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) -#define GPIO_LOCK_INIT(sc) \ - mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->dev), \ - "gpio", MTX_DEF) -#define GPIO_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); - -#define GPIO_GPDIR 0x0 -#define GPIO_GPODR 0x4 -#define GPIO_GPDAT 0x8 -#define GPIO_GPIER 0xc -#define GPIO_GPIMR 0x10 -#define GPIO_GPICR 0x14 -#define GPIO_GPIBE 0x18 - -struct qoriq_gpio_softc { - device_t dev; - device_t busdev; - struct mtx sc_mtx; - struct resource *sc_mem; /* Memory resource */ - struct gpio_pin sc_pins[MAXPIN + 1]; -}; - static device_t qoriq_gpio_get_bus(device_t dev) { @@ -379,9 +351,7 @@ qoriq_gpio_map_gpios(device_t bus, phandle_t dev, phandle_t gparent, int gcells, return (err); } -static int qoriq_gpio_detach(device_t dev); - -static int +int qoriq_gpio_attach(device_t dev) { struct qoriq_gpio_softc *sc = device_get_softc(dev); @@ -422,7 +392,7 @@ qoriq_gpio_attach(device_t dev) return (0); } -static int +int qoriq_gpio_detach(device_t dev) { struct qoriq_gpio_softc *sc = device_get_softc(dev); @@ -464,13 +434,11 @@ static device_method_t qoriq_gpio_methods[] = { DEVMETHOD_END }; -static driver_t qoriq_gpio_driver = { - "gpio", - qoriq_gpio_methods, - sizeof(struct qoriq_gpio_softc), -}; static devclass_t qoriq_gpio_devclass; +DEFINE_CLASS_0(gpio, qoriq_gpio_driver, qoriq_gpio_methods, + sizeof(struct qoriq_gpio_softc)); + EARLY_DRIVER_MODULE(qoriq_gpio, simplebus, qoriq_gpio_driver, qoriq_gpio_devclass, NULL, NULL, BUS_PASS_RESOURCE + BUS_PASS_ORDER_MIDDLE); diff --git a/sys/dev/gpio/qoriq_gpio.h b/sys/dev/gpio/qoriq_gpio.h new file mode 100644 index 000000000000..6b401e1d3f44 --- /dev/null +++ b/sys/dev/gpio/qoriq_gpio.h @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2020 Alstom Group. + * Copyright (c) 2020 Semihalf. + * Copyright (c) 2015 Justin Hibbits + * All rights reserved. + * + * 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. + * + * $FreeBSD$ + */ + +#define MAXPIN (31) + +#define BIT(x) (1 << (x)) + +#define VALID_PIN(u) ((u) >= 0 && (u) <= MAXPIN) +#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \ + GPIO_PIN_OPENDRAIN | GPIO_PIN_PUSHPULL) + +#define GPIO_LOCK(sc) mtx_lock_spin(&(sc)->sc_mtx) +#define GPIO_UNLOCK(sc) mtx_unlock_spin(&(sc)->sc_mtx) +#define GPIO_LOCK_INIT(sc) \ + mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->dev), \ + "gpio", MTX_SPIN) +#define GPIO_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); + +#define GPIO_GPDIR 0x0 +#define GPIO_GPODR 0x4 +#define GPIO_GPDAT 0x8 +#define GPIO_GPIER 0xc +#define GPIO_GPIMR 0x10 +#define GPIO_GPICR 0x14 +#define GPIO_GPIBE 0x18 + +struct qoriq_gpio_softc { + device_t dev; + device_t busdev; + struct mtx sc_mtx; + struct resource *sc_mem; + struct gpio_pin sc_pins[MAXPIN + 1]; +}; + +device_attach_t qoriq_gpio_attach; +device_detach_t qoriq_gpio_detach; + +DECLARE_CLASS(qoriq_gpio_driver);