From nobody Mon Jul 18 09:50:07 2022 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 4LmcdX1QZpz4WtDp; Mon, 18 Jul 2022 09:50:08 +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 4LmcdX0kDhz3D5V; Mon, 18 Jul 2022 09:50:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658137808; 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=ZBMI6LXPVQzbJK9DPxnIJ7ZV+fHgq9cEihE2IEeRgRI=; b=T3O9LORAqZBn/0HxZ3DNWUDLICW1dydZs48FoZAXYGRJwItjRS7vWz3CD4ygBdn2Pu32j9 cTGUOh3w46VhhjuAiWzsDsq4B96iIVKen978T1Ijwj2e7eFrGRqMrVZQq1EC22IJFgTbUF IN0YL63+AymJXSYv+1PoD7V5PmFjhQh9defPteAPg4rWRtDrBZv1Dp/DWk+PZCjAxxdYaF sM6kOhgD1qEeWN9O1udQK7TEKulSHfZbI31t+Gmwf2aYMvBI/iXQMdoeB9DlgH183pkmF2 n4/3UkUxlTJvFDPtHv4A419riwvv1YTPw8IPOSeZaoYNQ537DBpx/WtwBCyCuA== 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 4LmcdW6QqFzZk6; Mon, 18 Jul 2022 09:50:07 +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 26I9o7uS033928; Mon, 18 Jul 2022 09:50:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26I9o7SW033925; Mon, 18 Jul 2022 09:50:07 GMT (envelope-from git) Date: Mon, 18 Jul 2022 09:50:07 GMT Message-Id: <202207180950.26I9o7SW033925@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: ab82f64eb5b3 - stable/13 - pca954x: harmonize pca9547 and pca954x and add pca9540 support 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: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ab82f64eb5b3f23beee5610a2ce8d1fdb4732522 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658137808; 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=ZBMI6LXPVQzbJK9DPxnIJ7ZV+fHgq9cEihE2IEeRgRI=; b=tGoM9JFkzF2qk8UM3hOIgObFFuK52xknHLoH+pJan2AoVM387VeonGmS33nFM/gPR+v882 4NPzI2ozQOuPuEmzJQpiGqRzpNJrA0sTxvrXjuR0sMUPz1qmfsIxFXvPYiSITg3O9Je/gw cvHHwJPn5O4heYj9XAVwhUMAfE9DgADjQkvnyPn2QF78yLBxCMljjVjq47jshQ/YyEpjKr 81EqaynausTSSXt+Lhj/VUf9YsHqrOwE/HegCyhTLaWmps0rbv2akH3j389ctiMBLCVr4u vOmHxYiv3Xl+anojLYBlwmY3m8LS5t/TEA6F3ztc+6EdwGaXO/cyJ5JJcizXNw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658137808; a=rsa-sha256; cv=none; b=koLDd/OXisOPPhc8nZ1dRMoFl/0qt8JFExs7AQE1thMy7iMheA+N11ZWewAhPoqFWc6te1 8exLT/b2z1nkzD4e20ZXxXofE7HD7MzIw8qFDBGdMbu6ahG252OSs2WXieJ8TYm2FEvjGR /V+9MzaLOLebNG3Cw03wxIzlCi1vwg+48nAYIgqp6mGtG0DjRpgunjW8RuGlkrWfNS6OMu hs1nDAErEOaVMCf4BC/aV8aq+0+/lCyhA/f/fyN+nIJeKa4sf1i3iY7gB3qKnRPafBEkqf nShPXaTYMz2RkQT4N3J8iyXzPl/HNNwo4tqiNmKOWTsmstwFpOGPLty/cKHlAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=ab82f64eb5b3f23beee5610a2ce8d1fdb4732522 commit ab82f64eb5b3f23beee5610a2ce8d1fdb4732522 Author: Bjoern A. Zeeb AuthorDate: 2022-07-02 23:33:32 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-07-18 01:00:20 +0000 pca954x: harmonize pca9547 and pca954x and add pca9540 support The two implementations for the pca9548 switch and the pca9547 mux seemed close enough so we can put them together and with a bit more abstraction add pca9540 support. While here apply a bit of consistency in variable and driver naming and use device_has_property instead of the FDT-only OF_ variant. This disconnects pca9547 from the build but does not yet delete it. Reviewed by: mmel (earlier version), avg Sponsored by: Traverse Technologies (providing Ten64 HW for testing) Differential Revision: https://reviews.freebsd.org/D35701 (cherry picked from commit 97dbd37753ae1bf9c4f6a23e46e21f0a9f408c82) --- sys/arm64/conf/GENERIC | 2 +- sys/conf/files | 3 +- sys/dev/iicbus/mux/pca954x.c | 110 +++++++++++++++++++++++++++++-------------- 3 files changed, 76 insertions(+), 39 deletions(-) diff --git a/sys/arm64/conf/GENERIC b/sys/arm64/conf/GENERIC index b14776d4d979..ef5c2be54766 100644 --- a/sys/arm64/conf/GENERIC +++ b/sys/arm64/conf/GENERIC @@ -189,7 +189,7 @@ device iicmux device iic device icee # Generic IIC eeprom device twsi # Allwinner I2C controller -device pca9547 # NPX I2C bus multiplexer +device pca954x # NPX I2C bus multiplexer device pcf8563 # NXP Real-time clock/calendar device rk_i2c # RockChip I2C controller device syr827 # Silergy SYR827 PMIC diff --git a/sys/conf/files b/sys/conf/files index 87711570355a..525b998145a8 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1880,12 +1880,11 @@ dev/iicbus/iicoc_pci.c optional iicoc pci dev/iicbus/isl12xx.c optional isl12xx dev/iicbus/lm75.c optional lm75 dev/iicbus/max44009.c optional max44009 -dev/iicbus/mux/pca9547.c optional pca9547 iicmux fdt dev/iicbus/mux/iicmux.c optional iicmux dev/iicbus/mux/iicmux_if.m optional iicmux dev/iicbus/mux/iic_gpiomux.c optional iic_gpiomux fdt dev/iicbus/mux/ltc430x.c optional ltc430x -dev/iicbus/mux/pca954x.c optional pca954x +dev/iicbus/mux/pca954x.c optional pca954x iicbus iicmux dev/iicbus/nxprtc.c optional nxprtc | pcf8563 dev/iicbus/ofw_iicbus.c optional fdt iicbus dev/iicbus/pcf8574.c optional pcf8574 diff --git a/sys/dev/iicbus/mux/pca954x.c b/sys/dev/iicbus/mux/pca954x.c index 44c81539691e..9fcb01f65b7e 100644 --- a/sys/dev/iicbus/mux/pca954x.c +++ b/sys/dev/iicbus/mux/pca954x.c @@ -1,13 +1,15 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) Andriy Gapon + * Copyright (c) 2019 Ian Lepore + * Copyright (c) 2020-2021 Andriy Gapon + * Copyright (c) 2022 Bjoern A. Zeeb * * 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. + * 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. @@ -15,15 +17,14 @@ * 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 + * 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. - * */ #include @@ -49,31 +50,60 @@ __FBSDID("$FreeBSD$"); #include "iicmux_if.h" #include +enum pca954x_type { + PCA954X_MUX, + PCA954X_SW, +}; + struct pca954x_descr { - const char *partname; - const char *description; - int numchannels; + const char *partname; + const char *description; + enum pca954x_type type; + uint8_t numchannels; + uint8_t enable; +}; + +static struct pca954x_descr pca9540_descr = { + .partname = "pca9540", + .description = "PCA9540B I2C Mux", + .type = PCA954X_MUX, + .numchannels = 2, + .enable = 0x04, +}; + +static struct pca954x_descr pca9547_descr = { + .partname = "pca9547", + .description = "PCA9547 I2C Mux", + .type = PCA954X_MUX, + .numchannels = 8, + .enable = 0x08, }; static struct pca954x_descr pca9548_descr = { .partname = "pca9548", - .description = "PCA9548A I2C Mux", + .description = "PCA9548A I2C Switch", + .type = PCA954X_SW, .numchannels = 8, }; #ifdef FDT static struct ofw_compat_data compat_data[] = { + { "nxp,pca9540", (uintptr_t)&pca9540_descr }, + { "nxp,pca9547", (uintptr_t)&pca9547_descr }, { "nxp,pca9548", (uintptr_t)&pca9548_descr }, { NULL, 0 }, }; #else static struct pca954x_descr *part_descrs[] = { + &pca9540_descr, + &pca9547_descr, &pca9548_descr, }; #endif struct pca954x_softc { struct iicmux_softc mux; + const struct pca954x_descr *descr; uint8_t addr; bool idle_disconnect; }; @@ -81,10 +111,12 @@ struct pca954x_softc { static int pca954x_bus_select(device_t dev, int busidx, struct iic_reqbus_data *rd) { + struct pca954x_softc *sc; struct iic_msg msg; - struct pca954x_softc *sc = device_get_softc(dev); - uint8_t busbits; int error; + uint8_t busbits; + + sc = device_get_softc(dev); /* * The iicmux caller ensures busidx is between 0 and the number of buses @@ -98,8 +130,18 @@ pca954x_bus_select(device_t dev, int busidx, struct iic_reqbus_data *rd) busbits = 0; else return (0); - } else { + } else if (sc->descr->type == PCA954X_MUX) { + uint8_t en; + + en = sc->descr->enable; + KASSERT(en > 0 && powerof2(en), ("%s: %s enable %#x " + "invalid\n", __func__, sc->descr->partname, en)); + busbits = en | (busidx & (en - 1)); + } else if (sc->descr->type == PCA954X_SW) { busbits = 1u << busidx; + } else { + panic("%s: %s: unsupported type %d\n", + __func__, sc->descr->partname, sc->descr->type); } msg.slave = sc->addr; @@ -116,6 +158,9 @@ pca954x_find_chip(device_t dev) #ifdef FDT const struct ofw_compat_data *compat; + if (!ofw_bus_status_okay(dev)) + return (NULL); + compat = ofw_bus_search_compatible(dev, compat_data); if (compat == NULL) return (NULL); @@ -151,34 +196,29 @@ pca954x_probe(device_t dev) static int pca954x_attach(device_t dev) { -#ifdef FDT - phandle_t node; -#endif struct pca954x_softc *sc; const struct pca954x_descr *descr; - int err; + int error; sc = device_get_softc(dev); sc->addr = iicbus_get_addr(dev); -#ifdef FDT - node = ofw_bus_get_node(dev); - sc->idle_disconnect = OF_hasprop(node, "i2c-mux-idle-disconnect"); -#endif + sc->idle_disconnect = device_has_property(dev, "i2c-mux-idle-disconnect"); - descr = pca954x_find_chip(dev); - err = iicmux_attach(dev, device_get_parent(dev), descr->numchannels); - if (err == 0) + sc->descr = descr = pca954x_find_chip(dev); + error = iicmux_attach(dev, device_get_parent(dev), descr->numchannels); + if (error == 0) bus_generic_attach(dev); - return (err); + + return (error); } static int pca954x_detach(device_t dev) { - int err; + int error; - err = iicmux_detach(dev); - return (err); + error = iicmux_detach(dev); + return (error); } static device_method_t pca954x_methods[] = { @@ -193,21 +233,19 @@ static device_method_t pca954x_methods[] = { DEVMETHOD_END }; -static devclass_t pca954x_devclass; - -DEFINE_CLASS_1(pca9548, pca954x_driver, pca954x_methods, +DEFINE_CLASS_1(pca954x, pca954x_driver, pca954x_methods, sizeof(struct pca954x_softc), iicmux_driver); -DRIVER_MODULE(pca9548, iicbus, pca954x_driver, pca954x_devclass, 0, 0); +DRIVER_MODULE(pca954x, iicbus, pca954x_driver, 0, 0); #ifdef FDT -DRIVER_MODULE(ofw_iicbus, pca9548, ofw_iicbus_driver, ofw_iicbus_devclass, 0, 0); +DRIVER_MODULE(ofw_iicbus, pca954x, ofw_iicbus_driver, 0, 0); #else -DRIVER_MODULE(iicbus, pca9548, iicbus_driver, iicbus_devclass, 0, 0); +DRIVER_MODULE(iicbus, pca954x, iicbus_driver, 0, 0); #endif -MODULE_DEPEND(pca9548, iicmux, 1, 1, 1); -MODULE_DEPEND(pca9548, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER); -MODULE_VERSION(pca9548, 1); +MODULE_DEPEND(pca954x, iicmux, 1, 1, 1); +MODULE_DEPEND(pca954x, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER); +MODULE_VERSION(pca954x, 1); #ifdef FDT IICBUS_FDT_PNP_INFO(compat_data);