From nobody Wed Apr 1 11:15:18 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10EF233FE10 for ; Tue, 31 Mar 2026 17:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774977393; cv=none; b=CD+UOhFA/UuVCPDUO2DCrLAo0SDL27MSA6X+xeMR9ZrS/OaTdEMMvvjFJITu5I7I2jQ06BFZCTGqS96FxX6qGWaBRyKBx97dcttcCRa1g2M7rXgDlvr6jUtDMxNmKuRVnMWuRLs6xrjDiCQlagp0boF0kk3Pv88xXLoxo6odm14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774977393; c=relaxed/simple; bh=MCdTgQfl7kwvoBzn7pm2tVyEmi9iWvnnHsyOkpzCEqc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rf1BKGlVKBdRXZzk1VpJJcSPsRt5UK6ACt18K+XaZMn7MT+7Gy9DFBM/X5ntrB/6rRJazCzfTNEqkrLCS51jspm6yRd6/lAK2h3orh5F+f2qNjFNIpKz9gdJCd/thWiEUJbxkXk19HjEjVCkLXSolDOB0Q2C5v312yvnJS2ORk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1w7chK-0004mR-Dv; Tue, 31 Mar 2026 19:16:14 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w7chJ-0034jW-28; Tue, 31 Mar 2026 19:16:13 +0200 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1w7chJ-00000000QZa-2KOR; Tue, 31 Mar 2026 19:16:13 +0200 From: Oleksij Rempel To: Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lee Jones , Peter Rosin , Linus Walleij Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-gpio@vger.kernel.org, David Jander Subject: [PATCH v9 6/6] mux: add NXP MC33978/MC34978 AMUX driver Date: Tue, 31 Mar 2026 19:16:12 +0200 Message-ID: <20260331171612.102018-7-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260331171612.102018-1-o.rempel@pengutronix.de> References: <20260331171612.102018-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a mux-control driver for the 24-to-1 analog multiplexer (AMUX) embedded in the NXP MC33978/MC34978 Multiple Switch Detection Interface (MSDI) devices. Signed-off-by: Oleksij Rempel --- changes v9: - rename mc33978-mux to mux-mc33978 in the Kconfig help - fail if fwnode is NULL changes v8: - no chnages changes v7: - Simplify the return path and local variable assignment in mc33978_mux_set(). - Change idle_state to a signed integer to properly handle negative MUX subsystem constants. - Default to MUX_IDLE_AS_IS when the "idle-state" device tree property is missing. - Explicitly reject MUX_IDLE_DISCONNECT since the hardware does not support disconnecting the multiplexer. changes v6: - parse optional idle-state property - validate idle-state against available AMUX channels - lower-case probe error messages changes v5: - no changes changes v4: - no changes changes v3: - no changes changes v2: - Add missing include. - Add platform_device_id table --- drivers/mux/Kconfig | 14 ++++ drivers/mux/Makefile | 2 + drivers/mux/mc33978-mux.c | 141 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 drivers/mux/mc33978-mux.c diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig index c68132e38138..ffe92a714096 100644 --- a/drivers/mux/Kconfig +++ b/drivers/mux/Kconfig @@ -45,6 +45,20 @@ config MUX_GPIO To compile the driver as a module, choose M here: the module will be called mux-gpio. =20 +config MUX_MC33978 + tristate "NXP MC33978/MC34978 Analog Multiplexer" + depends on MFD_MC33978 + help + MC33978/MC34978 24-to-1 analog multiplexer (AMUX) driver. + + This driver provides mux-control for the analog multiplexer, + which can route switch voltages, temperature, and battery voltage + to an external ADC. Typically used with IIO ADC drivers to measure + analog values from the 22 switch inputs plus temperature and VBATP. + + To compile the driver as a module, choose M here: the module will + be called mux-mc33978. + config MUX_MMIO tristate "MMIO/Regmap register bitfield-controlled Multiplexer" depends on OF diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile index 6e9fa47daf56..339c44b4d4f4 100644 --- a/drivers/mux/Makefile +++ b/drivers/mux/Makefile @@ -7,10 +7,12 @@ mux-core-objs :=3D core.o mux-adg792a-objs :=3D adg792a.o mux-adgs1408-objs :=3D adgs1408.o mux-gpio-objs :=3D gpio.o +mux-mc33978-objs :=3D mc33978-mux.o mux-mmio-objs :=3D mmio.o =20 obj-$(CONFIG_MULTIPLEXER) +=3D mux-core.o obj-$(CONFIG_MUX_ADG792A) +=3D mux-adg792a.o obj-$(CONFIG_MUX_ADGS1408) +=3D mux-adgs1408.o obj-$(CONFIG_MUX_GPIO) +=3D mux-gpio.o +obj-$(CONFIG_MUX_MC33978) +=3D mux-mc33978.o obj-$(CONFIG_MUX_MMIO) +=3D mux-mmio.o diff --git a/drivers/mux/mc33978-mux.c b/drivers/mux/mc33978-mux.c new file mode 100644 index 000000000000..b44c862f0dbe --- /dev/null +++ b/drivers/mux/mc33978-mux.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) 2026 Pengutronix, Oleksij Rempel +/* + * MC33978/MC34978 Analog Multiplexer (AMUX) Driver + * + * This driver provides mux-control for the 24-to-1 analog multiplexer. + * The AMUX routes one of the following signals to the external AMUX pin: + * - Channels 0-13: SG0-SG13 switch voltages + * - Channels 14-21: SP0-SP7 switch voltages + * - Channel 22: Internal temperature diode + * - Channel 23: Battery voltage (VBATP) + * + * Consumer drivers (typically IIO ADC drivers) use the mux-control + * subsystem to select which signal to measure. + * + * Architecture: + * The MC33978 does not have an internal ADC. Instead, it routes analog + * signals to an external AMUX pin that must be connected to an external + * ADC (such as the SoC's internal ADC). The IIO subsystem is responsible + * for coordinating the mux selection and ADC sampling. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* AMUX_CTRL register field definitions */ +#define MC33978_AMUX_CTRL_MASK GENMASK(5, 0) /* 6-bit channel select */ + +struct mc33978_mux_priv { + struct device *dev; + struct regmap *map; +}; + +static int mc33978_mux_set(struct mux_control *mux, int state) +{ + struct mux_chip *mux_chip =3D mux->chip; + struct mc33978_mux_priv *priv =3D mux_chip_priv(mux_chip); + int ret; + + if (state < 0 || state >=3D MC33978_NUM_AMUX_CH) + return -EINVAL; + + ret =3D regmap_update_bits(priv->map, MC33978_REG_AMUX_CTRL, + MC33978_AMUX_CTRL_MASK, state); + if (ret) + dev_err(priv->dev, "failed to set AMUX channel %d: %d\n", + state, ret); + + return ret; +} + +static const struct mux_control_ops mc33978_mux_ops =3D { + .set =3D mc33978_mux_set, +}; + +static int mc33978_mux_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct mc33978_mux_priv *priv; + struct fwnode_handle *fwnode; + struct mux_chip *mux_chip; + struct mux_control *mux; + s32 idle_state; + int ret; + + mux_chip =3D devm_mux_chip_alloc(dev, 1, sizeof(*priv)); + if (IS_ERR(mux_chip)) + return dev_err_probe(dev, PTR_ERR(mux_chip), "failed to allocate mux chi= p\n"); + + fwnode =3D dev_fwnode(dev->parent); + if (!fwnode) + return dev_err_probe(dev, -ENODEV, "missing parent firmware node\n"); + + /* Borrow the parent's firmware node so consumers can find this mux chip = */ + device_set_node(&mux_chip->dev, fwnode); + + priv =3D mux_chip_priv(mux_chip); + priv->dev =3D dev; + + priv->map =3D dev_get_regmap(dev->parent, NULL); + if (!priv->map) + return dev_err_probe(dev, -ENODEV, "failed to get parent regmap\n"); + + mux_chip->ops =3D &mc33978_mux_ops; + + mux =3D &mux_chip->mux[0]; + mux->states =3D MC33978_NUM_AMUX_CH; + + ret =3D device_property_read_u32(&mux_chip->dev, "idle-state", + (u32 *)&idle_state); + if (ret < 0 && ret !=3D -EINVAL) { + return dev_err_probe(dev, ret, "failed to parse idle-state\n"); + } else if (ret =3D=3D -EINVAL) { + mux->idle_state =3D MUX_IDLE_AS_IS; + } else { + if (idle_state =3D=3D MUX_IDLE_DISCONNECT) + return dev_err_probe(dev, -EINVAL, + "idle-disconnect not supported by hardware\n"); + if (idle_state !=3D MUX_IDLE_AS_IS && + (idle_state < 0 || idle_state >=3D MC33978_NUM_AMUX_CH)) + return dev_err_probe(dev, -EINVAL, "invalid idle-state %d\n", + idle_state); + mux->idle_state =3D idle_state; + } + + ret =3D devm_mux_chip_register(dev, mux_chip); + if (ret) + return dev_err_probe(dev, ret, "failed to register mux chip\n"); + + platform_set_drvdata(pdev, mux_chip); + + return 0; +} + +static const struct platform_device_id mc33978_mux_id[] =3D { + { "mc33978-mux", }, + { "mc34978-mux", }, + { } +}; +MODULE_DEVICE_TABLE(platform, mc33978_mux_id); + +static struct platform_driver mc33978_mux_driver =3D { + .driver =3D { + .name =3D "mc33978-mux", + }, + .probe =3D mc33978_mux_probe, + .id_table =3D mc33978_mux_id, +}; +module_platform_driver(mc33978_mux_driver); + +MODULE_AUTHOR("Oleksij Rempel "); +MODULE_DESCRIPTION("NXP MC33978/MC34978 Analog Multiplexer Driver"); +MODULE_LICENSE("GPL"); --=20 2.47.3