* [PATCH 1/5] mux: add devm_mux_control_get_from_np() to get mux from child node
2026-02-19 22:23 [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips Frank Li
@ 2026-02-19 22:23 ` Frank Li
2026-02-19 22:23 ` [PATCH 2/5] dt-bindings: pinctrl: Add generic pinctrl for board-level mux chips Frank Li
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2026-02-19 22:23 UTC (permalink / raw)
To: Peter Rosin, Linus Walleij, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: linux-kernel, linux-gpio, devicetree, imx, linux-arm-kernel,
Frank Li
Add new API devm_mux_control_get_from_np() to retrieve a mux control from
a specified child device node.
Make devm_mux_control_get() call devm_mux_control_get_from_np() with a NULL
node parameter, which defaults to using the device's own of_node.
Support the following DT schema:
pinctrl@0 {
uart-func {
mux-state = <&mux_chip 0>;
};
spi-func {
mux-state = <&mux_chip 1>;
};
};
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
drivers/mux/core.c | 40 ++++++++++++++++++++++++----------------
include/linux/mux/consumer.h | 16 ++++++++++++----
2 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index a3840fe0995fe0125432d34edd8ab0f2cd1a6e9a..bdd959389b4ee1b0b8a7367fadf2c148c8f2f0b1 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -522,13 +522,15 @@ static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
* @mux_name: The name identifying the mux-control.
* @state: Pointer to where the requested state is returned, or NULL when
* the required multiplexer states are handled by other means.
+ * @node: the device nodes, use dev->of_node if it is NULL.
*
* Return: A pointer to the mux-control, or an ERR_PTR with a negative errno.
*/
static struct mux_control *mux_get(struct device *dev, const char *mux_name,
- unsigned int *state)
+ unsigned int *state,
+ struct device_node *node)
{
- struct device_node *np = dev->of_node;
+ struct device_node *np = node ? node : dev->of_node;
struct of_phandle_args args;
struct mux_chip *mux_chip;
unsigned int controller;
@@ -617,7 +619,7 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
*/
struct mux_control *mux_control_get(struct device *dev, const char *mux_name)
{
- return mux_get(dev, mux_name, NULL);
+ return mux_get(dev, mux_name, NULL, NULL);
}
EXPORT_SYMBOL_GPL(mux_control_get);
@@ -641,15 +643,17 @@ static void devm_mux_control_release(struct device *dev, void *res)
}
/**
- * devm_mux_control_get() - Get the mux-control for a device, with resource
- * management.
+ * devm_mux_control_get_from_np() - Get the mux-control for a device, with
+ * resource management.
* @dev: The device that needs a mux-control.
* @mux_name: The name identifying the mux-control.
+ * @np: the device nodes, use dev->of_node if it is NULL.
*
* Return: Pointer to the mux-control, or an ERR_PTR with a negative errno.
*/
-struct mux_control *devm_mux_control_get(struct device *dev,
- const char *mux_name)
+struct mux_control *
+devm_mux_control_get_from_np(struct device *dev, const char *mux_name,
+ struct device_node *np)
{
struct mux_control **ptr, *mux;
@@ -668,16 +672,18 @@ struct mux_control *devm_mux_control_get(struct device *dev,
return mux;
}
-EXPORT_SYMBOL_GPL(devm_mux_control_get);
+EXPORT_SYMBOL_GPL(devm_mux_control_get_from_np);
/*
* mux_state_get() - Get the mux-state for a device.
* @dev: The device that needs a mux-state.
* @mux_name: The name identifying the mux-state.
+ * @np: the device nodes, use dev->of_node if it is NULL.
*
* Return: A pointer to the mux-state, or an ERR_PTR with a negative errno.
*/
-static struct mux_state *mux_state_get(struct device *dev, const char *mux_name)
+static struct mux_state *
+mux_state_get(struct device *dev, const char *mux_name, struct device_node *np)
{
struct mux_state *mstate;
@@ -685,7 +691,7 @@ static struct mux_state *mux_state_get(struct device *dev, const char *mux_name)
if (!mstate)
return ERR_PTR(-ENOMEM);
- mstate->mux = mux_get(dev, mux_name, &mstate->state);
+ mstate->mux = mux_get(dev, mux_name, &mstate->state, np);
if (IS_ERR(mstate->mux)) {
int err = PTR_ERR(mstate->mux);
@@ -716,15 +722,17 @@ static void devm_mux_state_release(struct device *dev, void *res)
}
/**
- * devm_mux_state_get() - Get the mux-state for a device, with resource
- * management.
+ * devm_mux_state_get_from_np() - Get the mux-state for a device, with resource
+ * management.
* @dev: The device that needs a mux-control.
* @mux_name: The name identifying the mux-control.
+ * @np: the device nodes, use dev->of_node if it is NULL.
*
* Return: Pointer to the mux-state, or an ERR_PTR with a negative errno.
*/
-struct mux_state *devm_mux_state_get(struct device *dev,
- const char *mux_name)
+struct mux_state *
+devm_mux_state_get_from_np(struct device *dev, const char *mux_name,
+ struct device_node *np)
{
struct mux_state **ptr, *mstate;
@@ -732,7 +740,7 @@ struct mux_state *devm_mux_state_get(struct device *dev,
if (!ptr)
return ERR_PTR(-ENOMEM);
- mstate = mux_state_get(dev, mux_name);
+ mstate = mux_state_get(dev, mux_name, np);
if (IS_ERR(mstate)) {
devres_free(ptr);
return mstate;
@@ -743,7 +751,7 @@ struct mux_state *devm_mux_state_get(struct device *dev,
return mstate;
}
-EXPORT_SYMBOL_GPL(devm_mux_state_get);
+EXPORT_SYMBOL_GPL(devm_mux_state_get_from_np);
/*
* Using subsys_initcall instead of module_init here to try to ensure - for
diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
index 2e25c838f8312532040441ee618424b76378aad7..6300e091035323dd6158d52a55a109d43ef120aa 100644
--- a/include/linux/mux/consumer.h
+++ b/include/linux/mux/consumer.h
@@ -56,9 +56,17 @@ int mux_state_deselect(struct mux_state *mstate);
struct mux_control *mux_control_get(struct device *dev, const char *mux_name);
void mux_control_put(struct mux_control *mux);
-struct mux_control *devm_mux_control_get(struct device *dev,
- const char *mux_name);
-struct mux_state *devm_mux_state_get(struct device *dev,
- const char *mux_name);
+struct mux_control *
+devm_mux_control_get_from_np(struct device *dev, const char *mux_name,
+ struct device_node *np);
+
+#define devm_mux_control_get(dev, mux_name) \
+ devm_mux_control_get_from_np(dev, mux_name, NULL)
+
+struct mux_state *
+devm_mux_state_get_from_np(struct device *dev, const char *mux_name,
+ struct device_node *np);
+#define devm_mux_state_get(dev, mux_name) \
+ devm_mux_state_get_from_np(dev, mux_name, NULL)
#endif /* _LINUX_MUX_CONSUMER_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 2/5] dt-bindings: pinctrl: Add generic pinctrl for board-level mux chips
2026-02-19 22:23 [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips Frank Li
2026-02-19 22:23 ` [PATCH 1/5] mux: add devm_mux_control_get_from_np() to get mux from child node Frank Li
@ 2026-02-19 22:23 ` Frank Li
2026-02-23 18:42 ` Rob Herring
2026-02-19 22:23 ` [PATCH 3/5] pinctrl: add generic board-level pinctrl driver using mux framework Frank Li
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Frank Li @ 2026-02-19 22:23 UTC (permalink / raw)
To: Peter Rosin, Linus Walleij, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: linux-kernel, linux-gpio, devicetree, imx, linux-arm-kernel,
Frank Li
Add a generic pinctrl binding for board-level pinmux chips that are
controlled through the multiplexer subsystem.
On some boards, especially development boards, external mux chips are used
to switch SoC signals between different peripherals (e.g. MMC and UART).
The mux select lines are often driven by a GPIO expander over I2C,
as illustrated below:
┌──────┐ ┌─────┐
│ SOC │ │ │ ┌───────┐
│ │ │ │───►│ MMC │
│ │ │ MUX │ └───────┘
│ ├─────►│ │ ┌───────┐
│ │ │ │───►│ UART │
│ │ └─────┘ └───────┘
│ │ ▲
│ │ ┌────┴──────────────┐
│ I2C ├───►│ GPIO Expander │
└──────┘ └───────────────────┘
Traditionally, gpio-hog is used to configure the onboard mux at boot.
However, the GPIO expander may probe later than consumer devices such as
MMC. As a result, the MUX might not be configured when the peripheral
driver probes, leading to initialization failures or data transfer errors.
Introduce a generic pinctrl binding that models the board-level MUX as a
pin control provider and builds proper device links between the MUX, its
GPIO controller, and peripheral devices. This ensures correct probe
ordering and reliable mux configuration.
The implementation leverages the standard multiplexer subsystem, which
provides broad support for onboard mux controllers and avoids the need for
per-driver custom MUX handling.
Allow pinctrl-* pattern as node name because this pinctrl device have not
reg property.
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
.../bindings/pinctrl/pinctrl-multiplexer.yaml | 54 ++++++++++++++++++++++
.../devicetree/bindings/pinctrl/pinctrl.yaml | 2 +-
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-multiplexer.yaml b/Documentation/devicetree/bindings/pinctrl/pinctrl-multiplexer.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..31efffb3167cba724b1afe0d403a0dcae65582ee
--- /dev/null
+++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-multiplexer.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/pinctrl-multiplexer.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic Pin Control Driver for Board-Level Mux Chips
+
+maintainers:
+ - Frank Li <Frank.Li@nxp.com>
+
+description:
+ This binding describes a generic pinctrl driver that controls on-board
+ pinmux chips using the multiplexer subsystem.
+
+properties:
+ compatible:
+ const: pinctrl-multiplexer
+
+patternProperties:
+ '-grp$':
+ type: object
+ properties:
+ mux-states:
+ maxItems: 1
+
+ required:
+ - mux-states
+
+required:
+ - compatible
+
+allOf:
+ - $ref: pinctrl.yaml#
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ pinctrl-mux {
+ compatible = "pinctrl-multiplexer";
+
+ uart-grp {
+ mux-states = <&mux 0>;
+ };
+
+ spi-grp {
+ mux-states = <&mux 1>;
+ };
+
+ i2c-grp {
+ mux-states = <&mux 2>;
+ };
+ };
diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/pinctrl.yaml
index 290438826c507ec6725f486d18cf686aa7c35e67..20176bf3074757de30f208e69b968a6bd6125273 100644
--- a/Documentation/devicetree/bindings/pinctrl/pinctrl.yaml
+++ b/Documentation/devicetree/bindings/pinctrl/pinctrl.yaml
@@ -27,7 +27,7 @@ description: |
properties:
$nodename:
- pattern: "^(pinctrl|pinmux)(@[0-9a-f]+)?$"
+ pattern: "^(pinctrl|pinmux)(@[0-9a-f]+|-[a-z0-9]+)?$"
"#pinctrl-cells":
description: >
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 2/5] dt-bindings: pinctrl: Add generic pinctrl for board-level mux chips
2026-02-19 22:23 ` [PATCH 2/5] dt-bindings: pinctrl: Add generic pinctrl for board-level mux chips Frank Li
@ 2026-02-23 18:42 ` Rob Herring
0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2026-02-23 18:42 UTC (permalink / raw)
To: Frank Li
Cc: Peter Rosin, Linus Walleij, Krzysztof Kozlowski, Conor Dooley,
Rafał Miłecki, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, linux-kernel, linux-gpio, devicetree, imx,
linux-arm-kernel
On Thu, Feb 19, 2026 at 05:23:42PM -0500, Frank Li wrote:
> Add a generic pinctrl binding for board-level pinmux chips that are
> controlled through the multiplexer subsystem.
>
> On some boards, especially development boards, external mux chips are used
> to switch SoC signals between different peripherals (e.g. MMC and UART).
> The mux select lines are often driven by a GPIO expander over I2C,
> as illustrated below:
>
> ┌──────┐ ┌─────┐
> │ SOC │ │ │ ┌───────┐
> │ │ │ │───►│ MMC │
> │ │ │ MUX │ └───────┘
> │ ├─────►│ │ ┌───────┐
> │ │ │ │───►│ UART │
> │ │ └─────┘ └───────┘
> │ │ ▲
> │ │ ┌────┴──────────────┐
> │ I2C ├───►│ GPIO Expander │
> └──────┘ └───────────────────┘
>
> Traditionally, gpio-hog is used to configure the onboard mux at boot.
> However, the GPIO expander may probe later than consumer devices such as
> MMC. As a result, the MUX might not be configured when the peripheral
> driver probes, leading to initialization failures or data transfer errors.
>
> Introduce a generic pinctrl binding that models the board-level MUX as a
> pin control provider and builds proper device links between the MUX, its
> GPIO controller, and peripheral devices. This ensures correct probe
> ordering and reliable mux configuration.
>
> The implementation leverages the standard multiplexer subsystem, which
> provides broad support for onboard mux controllers and avoids the need for
> per-driver custom MUX handling.
Seems reasonable to me.
>
> Allow pinctrl-* pattern as node name because this pinctrl device have not
> reg property.
>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> .../bindings/pinctrl/pinctrl-multiplexer.yaml | 54 ++++++++++++++++++++++
> .../devicetree/bindings/pinctrl/pinctrl.yaml | 2 +-
> 2 files changed, 55 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-multiplexer.yaml b/Documentation/devicetree/bindings/pinctrl/pinctrl-multiplexer.yaml
> new file mode 100644
> index 0000000000000000000000000000000000000000..31efffb3167cba724b1afe0d403a0dcae65582ee
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-multiplexer.yaml
> @@ -0,0 +1,54 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/pinctrl/pinctrl-multiplexer.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Generic Pin Control Driver for Board-Level Mux Chips
> +
> +maintainers:
> + - Frank Li <Frank.Li@nxp.com>
> +
> +description:
> + This binding describes a generic pinctrl driver that controls on-board
Bindings don't describe drivers.
> + pinmux chips using the multiplexer subsystem.
> +
> +properties:
> + compatible:
> + const: pinctrl-multiplexer
> +
> +patternProperties:
> + '-grp$':
> + type: object
additionalProperties: false
The tools should have caught this, I'll have to check why not...
> + properties:
> + mux-states:
> + maxItems: 1
> +
> + required:
> + - mux-states
> +
> +required:
> + - compatible
> +
> +allOf:
> + - $ref: pinctrl.yaml#
> +
> +unevaluatedProperties: false
> +
> +examples:
> + - |
> + pinctrl-mux {
> + compatible = "pinctrl-multiplexer";
> +
> + uart-grp {
> + mux-states = <&mux 0>;
> + };
> +
> + spi-grp {
> + mux-states = <&mux 1>;
> + };
> +
> + i2c-grp {
> + mux-states = <&mux 2>;
> + };
> + };
> diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/pinctrl.yaml
> index 290438826c507ec6725f486d18cf686aa7c35e67..20176bf3074757de30f208e69b968a6bd6125273 100644
> --- a/Documentation/devicetree/bindings/pinctrl/pinctrl.yaml
> +++ b/Documentation/devicetree/bindings/pinctrl/pinctrl.yaml
> @@ -27,7 +27,7 @@ description: |
>
> properties:
> $nodename:
> - pattern: "^(pinctrl|pinmux)(@[0-9a-f]+)?$"
> + pattern: "^(pinctrl|pinmux)(@[0-9a-f]+|-[a-z0-9]+)?$"
>
> "#pinctrl-cells":
> description: >
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/5] pinctrl: add generic board-level pinctrl driver using mux framework
2026-02-19 22:23 [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips Frank Li
2026-02-19 22:23 ` [PATCH 1/5] mux: add devm_mux_control_get_from_np() to get mux from child node Frank Li
2026-02-19 22:23 ` [PATCH 2/5] dt-bindings: pinctrl: Add generic pinctrl for board-level mux chips Frank Li
@ 2026-02-19 22:23 ` Frank Li
2026-02-20 8:50 ` Daniel Baluta
2026-02-20 23:38 ` Peter Rosin
2026-02-19 22:23 ` [PATCH 4/5] arm64: dts: imx8mp-evk: add board-level mux for CAN2 and MICFIL Frank Li
` (2 subsequent siblings)
5 siblings, 2 replies; 12+ messages in thread
From: Frank Li @ 2026-02-19 22:23 UTC (permalink / raw)
To: Peter Rosin, Linus Walleij, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: linux-kernel, linux-gpio, devicetree, imx, linux-arm-kernel,
Frank Li
Many boards use on-board mux chips (often controlled by GPIOs from an I2C
expander) to switch shared signals between peripherals.
Add a generic pinctrl driver built on top of the mux framework to
centralize mux handling and avoid probe ordering issues. Keep board-level
routing out of individual drivers and supports boot-time only mux
selection.
Ensure correct probe ordering, especially when the GPIO expander is probed
later.
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
drivers/pinctrl/Kconfig | 9 ++
drivers/pinctrl/Makefile | 1 +
drivers/pinctrl/pinctrl-generic-mux.c | 222 ++++++++++++++++++++++++++++++++++
3 files changed, 232 insertions(+)
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index afecd9407f5354f5b92223f8cd80d2f7a08f8e7d..0657eeeeb587fa5e68dc3c1e00be35608e243b80 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -274,6 +274,15 @@ config PINCTRL_GEMINI
select GENERIC_PINCONF
select MFD_SYSCON
+config PINCTRL_GENERIC_MUX
+ tristate "Generic Pinctrl driver by using multiplexer"
+ depends on MULTIPLEXER
+ select PINMUX
+ select GENERIC_PINCONF
+ help
+ Generic pinctrl driver by MULTIPLEXER framework to control on
+ board pin selection.
+
config PINCTRL_INGENIC
bool "Pinctrl driver for the Ingenic JZ47xx SoCs"
default MACH_INGENIC
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile
index f7d5d5f76d0c8becc0aa1d77c68b6ced924ea264..fcd1703440d24579636e8ddb6cbd83a0a982dfb7 100644
--- a/drivers/pinctrl/Makefile
+++ b/drivers/pinctrl/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_PINCTRL_EQUILIBRIUM) += pinctrl-equilibrium.o
obj-$(CONFIG_PINCTRL_EP93XX) += pinctrl-ep93xx.o
obj-$(CONFIG_PINCTRL_EYEQ5) += pinctrl-eyeq5.o
obj-$(CONFIG_PINCTRL_GEMINI) += pinctrl-gemini.o
+obj-$(CONFIG_PINCTRL_GENERIC_MUX) += pinctrl-generic-mux.o
obj-$(CONFIG_PINCTRL_INGENIC) += pinctrl-ingenic.o
obj-$(CONFIG_PINCTRL_K210) += pinctrl-k210.o
obj-$(CONFIG_PINCTRL_K230) += pinctrl-k230.o
diff --git a/drivers/pinctrl/pinctrl-generic-mux.c b/drivers/pinctrl/pinctrl-generic-mux.c
new file mode 100644
index 0000000000000000000000000000000000000000..555dd2966e205e7f90a8bf8df3e46ed51d29d562
--- /dev/null
+++ b/drivers/pinctrl/pinctrl-generic-mux.c
@@ -0,0 +1,222 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Generic Pin Control Driver for Board-Level Mux Chips
+ * Copyright (C) 2026
+ */
+
+#include <linux/cleanup.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/mutex.h>
+#include <linux/mux/consumer.h>
+#include <linux/platform_device.h>
+#include <linux/pinctrl/pinconf-generic.h>
+#include <linux/pinctrl/pinctrl.h>
+#include <linux/pinctrl/pinmux.h>
+#include <linux/slab.h>
+
+#include "core.h"
+#include "pinmux.h"
+
+struct mux_pin_function {
+ struct mux_state *mux_state;
+};
+
+struct mux_pinctrl {
+ struct device *dev;
+ struct pinctrl_dev *pctl;
+
+ /* mutex protecting the lists */
+ struct mutex lock;
+ int cur_select;
+};
+
+static int
+mux_pinmux_dt_node_to_map(struct pinctrl_dev *pctldev,
+ struct device_node *np_config,
+ struct pinctrl_map **map, unsigned int *num_maps)
+{
+ struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
+ struct mux_pin_function *function;
+ struct device *dev = mpctl->dev;
+ const char **pgnames;
+ int selector;
+ int group;
+ int ret;
+
+ *map = devm_kcalloc(dev, 1, sizeof(**map), GFP_KERNEL);
+ if (!map)
+ return -ENOMEM;
+
+ *num_maps = 0;
+
+ function = devm_kzalloc(dev, sizeof(*function), GFP_KERNEL);
+ if (!function) {
+ ret = -ENOMEM;
+ goto err_func;
+ }
+
+ pgnames = devm_kzalloc(dev, sizeof(*pgnames), GFP_KERNEL);
+ if (!pgnames) {
+ ret = -ENOMEM;
+ goto err_pgnames;
+ }
+
+ pgnames[0] = np_config->name;
+
+ guard(mutex)(&mpctl->lock);
+
+ selector = pinmux_generic_add_function(mpctl->pctl, np_config->name,
+ pgnames, 1, function);
+ if (selector < 0) {
+ ret = selector;
+ goto err_add_func;
+ }
+
+ group = pinctrl_generic_add_group(mpctl->pctl, np_config->name, NULL, 0, mpctl);
+ if (group < 0) {
+ ret = group;
+ goto err_add_group;
+ }
+
+ function->mux_state = devm_mux_state_get_from_np(pctldev->dev, NULL, np_config);
+ if (IS_ERR(function->mux_state)) {
+ ret = PTR_ERR(function->mux_state);
+ goto err_mux_state_get;
+ }
+
+ (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
+ (*map)->data.mux.group = np_config->name;
+ (*map)->data.mux.function = np_config->name;
+
+ *num_maps = 1;
+
+ return 0;
+
+err_mux_state_get:
+ pinctrl_generic_remove_group(mpctl->pctl, group);
+err_add_group:
+ pinmux_generic_remove_function(mpctl->pctl, selector);
+err_add_func:
+ devm_kfree(dev, pgnames);
+err_pgnames:
+ devm_kfree(dev, function);
+err_func:
+ devm_kfree(dev, *map);
+
+ return ret;
+}
+
+static void
+mux_pinmux_dt_free_map(struct pinctrl_dev *pctldev, struct pinctrl_map *map,
+ unsigned int num_maps)
+{
+ struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
+
+ devm_kfree(mpctl->dev, map);
+}
+
+static const struct pinctrl_ops mux_pinctrl_ops = {
+ .get_groups_count = pinctrl_generic_get_group_count,
+ .get_group_name = pinctrl_generic_get_group_name,
+ .get_group_pins = pinctrl_generic_get_group_pins,
+ .dt_node_to_map = mux_pinmux_dt_node_to_map,
+ .dt_free_map = mux_pinmux_dt_free_map,
+};
+
+static int mux_pinmux_set_mux(struct pinctrl_dev *pctldev,
+ unsigned int func_selector,
+ unsigned int group_selector)
+{
+ struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
+ const struct function_desc *function;
+ struct mux_pin_function *func;
+ int ret;
+
+ guard(mutex)(&mpctl->lock);
+
+ function = pinmux_generic_get_function(pctldev, func_selector);
+ func = function->data;
+
+ if (mpctl->cur_select == func_selector)
+ return 0;
+
+ if (mpctl->cur_select >= 0 && mpctl->cur_select != func_selector)
+ return -EINVAL;
+
+ ret = mux_state_select(func->mux_state);
+ if (ret)
+ return ret;
+
+ mpctl->cur_select = func_selector;
+
+ return 0;
+}
+
+static const struct pinmux_ops mux_pinmux_ops = {
+ .get_functions_count = pinmux_generic_get_function_count,
+ .get_function_name = pinmux_generic_get_function_name,
+ .get_function_groups = pinmux_generic_get_function_groups,
+ .set_mux = mux_pinmux_set_mux,
+};
+
+static int mux_pinctrl_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct mux_pinctrl *mpctl;
+ struct pinctrl_desc *pctl_desc;
+ int ret;
+
+ mpctl = devm_kzalloc(dev, sizeof(*mpctl), GFP_KERNEL);
+ if (!mpctl)
+ return -ENOMEM;
+
+ mpctl->dev = dev;
+ mpctl->cur_select = -1;
+
+ platform_set_drvdata(pdev, mpctl);
+
+ pctl_desc = devm_kzalloc(dev, sizeof(*pctl_desc), GFP_KERNEL);
+ if (!pctl_desc)
+ return -ENOMEM;
+
+ ret = devm_mutex_init(dev, &mpctl->lock);
+ if (ret)
+ return ret;
+
+ pctl_desc->name = dev_name(dev);
+ pctl_desc->owner = THIS_MODULE;
+ pctl_desc->pctlops = &mux_pinctrl_ops;
+ pctl_desc->pmxops = &mux_pinmux_ops;
+
+ ret = devm_pinctrl_register_and_init(dev, pctl_desc, mpctl,
+ &mpctl->pctl);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to register pinctrl.\n");
+
+ ret = pinctrl_enable(mpctl->pctl);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to enable pinctrl.\n");
+
+ return 0;
+}
+
+static const struct of_device_id mux_pinctrl_of_match[] = {
+ { .compatible = "pinctrl-multiplexer" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, mux_pinctrl_of_match);
+
+static struct platform_driver mux_pinctrl_driver = {
+ .driver = {
+ .name = "generic-pinctrl-mux",
+ .of_match_table = mux_pinctrl_of_match,
+ },
+ .probe = mux_pinctrl_probe,
+};
+module_platform_driver(mux_pinctrl_driver);
+
+MODULE_AUTHOR("Frank Li <Frank.Li@nxp.com>");
+MODULE_DESCRIPTION("Generic Pin Control Driver for Board-Level Mux Chips");
+MODULE_LICENSE("GPL");
+
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 3/5] pinctrl: add generic board-level pinctrl driver using mux framework
2026-02-19 22:23 ` [PATCH 3/5] pinctrl: add generic board-level pinctrl driver using mux framework Frank Li
@ 2026-02-20 8:50 ` Daniel Baluta
2026-02-20 15:54 ` Frank Li
2026-02-20 23:38 ` Peter Rosin
1 sibling, 1 reply; 12+ messages in thread
From: Daniel Baluta @ 2026-02-20 8:50 UTC (permalink / raw)
To: Frank Li, Peter Rosin, Linus Walleij, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Rafał Miłecki,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam
Cc: linux-kernel, linux-gpio, devicetree, imx, linux-arm-kernel
Hi Frank,
Few comments inline:
> --- /dev/null
> +++ b/drivers/pinctrl/pinctrl-generic-mux.c
> @@ -0,0 +1,222 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Generic Pin Control Driver for Board-Level Mux Chips
> + * Copyright (C) 2026
>
Copyright 2026 NXP
<snip>
> +struct mux_pin_function {
> + struct mux_state *mux_state;
> +};
> +
> +struct mux_pinctrl {
> + struct device *dev;
> + struct pinctrl_dev *pctl;
> +
> + /* mutex protecting the lists */
what lists?
> +static int
> +mux_pinmux_dt_node_to_map(struct pinctrl_dev *pctldev,
> + struct device_node *np_config,
> + struct pinctrl_map **map, unsigned int *num_maps)
> +{
> + struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
> + struct mux_pin_function *function;
> + struct device *dev = mpctl->dev;
> + const char **pgnames;
> + int selector;
> + int group;
> + int ret;
> +
> + *map = devm_kcalloc(dev, 1, sizeof(**map), GFP_KERNEL);
> + if (!map)
> + return -ENOMEM;
>
if (!*map) ?
> +
> + *num_maps = 0;
> +
> + function = devm_kzalloc(dev, sizeof(*function), GFP_KERNEL);
> + if (!function) {
> + ret = -ENOMEM;
> + goto err_func;
Do you really need this goto? Previously allocated memory is dev managed .
> + }
> +
> + pgnames = devm_kzalloc(dev, sizeof(*pgnames), GFP_KERNEL);
> + if (!pgnames) {
> + ret = -ENOMEM;
> + goto err_pgnames;
>
Same here.
<snip>
> +err_mux_state_get:
> + pinctrl_generic_remove_group(mpctl->pctl, group);
> +err_add_group:
> + pinmux_generic_remove_function(mpctl->pctl, selector);
> +err_add_func:
> + devm_kfree(dev, pgnames);
> +err_pgnames:
> + devm_kfree(dev, function);
> +err_func:
> + devm_kfree(dev, *map);
> +
> + return ret;
> +}
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 3/5] pinctrl: add generic board-level pinctrl driver using mux framework
2026-02-20 8:50 ` Daniel Baluta
@ 2026-02-20 15:54 ` Frank Li
0 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2026-02-20 15:54 UTC (permalink / raw)
To: Daniel Baluta
Cc: Peter Rosin, Linus Walleij, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, linux-kernel, linux-gpio,
devicetree, imx, linux-arm-kernel
On Fri, Feb 20, 2026 at 10:50:41AM +0200, Daniel Baluta wrote:
> Hi Frank,
>
> Few comments inline:
>
>
> > --- /dev/null
> > +++ b/drivers/pinctrl/pinctrl-generic-mux.c
> > @@ -0,0 +1,222 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Generic Pin Control Driver for Board-Level Mux Chips
> > + * Copyright (C) 2026
> >
> Copyright 2026 NXP
>
> <snip>
>
> > +struct mux_pin_function {
> > + struct mux_state *mux_state;
> > +};
> > +
> > +struct mux_pinctrl {
> > + struct device *dev;
> > + struct pinctrl_dev *pctl;
> > +
> > + /* mutex protecting the lists */
>
> what lists?
>
>
> > +static int
> > +mux_pinmux_dt_node_to_map(struct pinctrl_dev *pctldev,
> > + struct device_node *np_config,
> > + struct pinctrl_map **map, unsigned int *num_maps)
> > +{
> > + struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
> > + struct mux_pin_function *function;
> > + struct device *dev = mpctl->dev;
> > + const char **pgnames;
> > + int selector;
> > + int group;
> > + int ret;
> > +
> > + *map = devm_kcalloc(dev, 1, sizeof(**map), GFP_KERNEL);
> > + if (!map)
> > + return -ENOMEM;
> >
> if (!*map) ?
>
> > +
> > + *num_maps = 0;
> > +
> > + function = devm_kzalloc(dev, sizeof(*function), GFP_KERNEL);
> > + if (!function) {
> > + ret = -ENOMEM;
> > + goto err_func;
> Do you really need this goto? Previously allocated memory is dev managed .
Yes, dt_node_to_map() may re-entry because some defer. we don't want to
defer free previous allocated memory to module remove and generally
pinctrl driver is never removed.
why use devm_ version is because pinctrl framework assume you use devm_ to
allocate map.
Frank
> > + }
> > +
> > + pgnames = devm_kzalloc(dev, sizeof(*pgnames), GFP_KERNEL);
> > + if (!pgnames) {
> > + ret = -ENOMEM;
> > + goto err_pgnames;
> >
> Same here.
>
> <snip>
>
> > +err_mux_state_get:
> > + pinctrl_generic_remove_group(mpctl->pctl, group);
> > +err_add_group:
> > + pinmux_generic_remove_function(mpctl->pctl, selector);
> > +err_add_func:
> > + devm_kfree(dev, pgnames);
> > +err_pgnames:
> > + devm_kfree(dev, function);
> > +err_func:
> > + devm_kfree(dev, *map);
> > +
> > + return ret;
> > +}
>
>
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/5] pinctrl: add generic board-level pinctrl driver using mux framework
2026-02-19 22:23 ` [PATCH 3/5] pinctrl: add generic board-level pinctrl driver using mux framework Frank Li
2026-02-20 8:50 ` Daniel Baluta
@ 2026-02-20 23:38 ` Peter Rosin
1 sibling, 0 replies; 12+ messages in thread
From: Peter Rosin @ 2026-02-20 23:38 UTC (permalink / raw)
To: Frank Li, Linus Walleij, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: linux-kernel, linux-gpio, devicetree, imx, linux-arm-kernel
Hi!
2026-02-19 at 23:23, Frank Li wrote:
> Many boards use on-board mux chips (often controlled by GPIOs from an I2C
> expander) to switch shared signals between peripherals.
>
> Add a generic pinctrl driver built on top of the mux framework to
> centralize mux handling and avoid probe ordering issues. Keep board-level
> routing out of individual drivers and supports boot-time only mux
> selection.
>
> Ensure correct probe ordering, especially when the GPIO expander is probed
> later.
>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> drivers/pinctrl/Kconfig | 9 ++
> drivers/pinctrl/Makefile | 1 +
> drivers/pinctrl/pinctrl-generic-mux.c | 222 ++++++++++++++++++++++++++++++++++
> 3 files changed, 232 insertions(+)
>
> diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
> index afecd9407f5354f5b92223f8cd80d2f7a08f8e7d..0657eeeeb587fa5e68dc3c1e00be35608e243b80 100644
> --- a/drivers/pinctrl/Kconfig
> +++ b/drivers/pinctrl/Kconfig
> @@ -274,6 +274,15 @@ config PINCTRL_GEMINI
> select GENERIC_PINCONF
> select MFD_SYSCON
>
> +config PINCTRL_GENERIC_MUX
> + tristate "Generic Pinctrl driver by using multiplexer"
> + depends on MULTIPLEXER
> + select PINMUX
> + select GENERIC_PINCONF
> + help
> + Generic pinctrl driver by MULTIPLEXER framework to control on
> + board pin selection.
> +
> config PINCTRL_INGENIC
> bool "Pinctrl driver for the Ingenic JZ47xx SoCs"
> default MACH_INGENIC
> diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile
> index f7d5d5f76d0c8becc0aa1d77c68b6ced924ea264..fcd1703440d24579636e8ddb6cbd83a0a982dfb7 100644
> --- a/drivers/pinctrl/Makefile
> +++ b/drivers/pinctrl/Makefile
> @@ -29,6 +29,7 @@ obj-$(CONFIG_PINCTRL_EQUILIBRIUM) += pinctrl-equilibrium.o
> obj-$(CONFIG_PINCTRL_EP93XX) += pinctrl-ep93xx.o
> obj-$(CONFIG_PINCTRL_EYEQ5) += pinctrl-eyeq5.o
> obj-$(CONFIG_PINCTRL_GEMINI) += pinctrl-gemini.o
> +obj-$(CONFIG_PINCTRL_GENERIC_MUX) += pinctrl-generic-mux.o
> obj-$(CONFIG_PINCTRL_INGENIC) += pinctrl-ingenic.o
> obj-$(CONFIG_PINCTRL_K210) += pinctrl-k210.o
> obj-$(CONFIG_PINCTRL_K230) += pinctrl-k230.o
> diff --git a/drivers/pinctrl/pinctrl-generic-mux.c b/drivers/pinctrl/pinctrl-generic-mux.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..555dd2966e205e7f90a8bf8df3e46ed51d29d562
> --- /dev/null
> +++ b/drivers/pinctrl/pinctrl-generic-mux.c
> @@ -0,0 +1,222 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Generic Pin Control Driver for Board-Level Mux Chips
> + * Copyright (C) 2026
> + */
> +
> +#include <linux/cleanup.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/mutex.h>
> +#include <linux/mux/consumer.h>
> +#include <linux/platform_device.h>
> +#include <linux/pinctrl/pinconf-generic.h>
> +#include <linux/pinctrl/pinctrl.h>
> +#include <linux/pinctrl/pinmux.h>
> +#include <linux/slab.h>
> +
> +#include "core.h"
> +#include "pinmux.h"
> +
> +struct mux_pin_function {
> + struct mux_state *mux_state;
> +};
> +
> +struct mux_pinctrl {
> + struct device *dev;
> + struct pinctrl_dev *pctl;
> +
> + /* mutex protecting the lists */
> + struct mutex lock;
> + int cur_select;
> +};
> +
> +static int
> +mux_pinmux_dt_node_to_map(struct pinctrl_dev *pctldev,
> + struct device_node *np_config,
> + struct pinctrl_map **map, unsigned int *num_maps)
> +{
> + struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
> + struct mux_pin_function *function;
> + struct device *dev = mpctl->dev;
> + const char **pgnames;
> + int selector;
> + int group;
> + int ret;
> +
> + *map = devm_kcalloc(dev, 1, sizeof(**map), GFP_KERNEL);
> + if (!map)
> + return -ENOMEM;
> +
> + *num_maps = 0;
> +
> + function = devm_kzalloc(dev, sizeof(*function), GFP_KERNEL);
> + if (!function) {
> + ret = -ENOMEM;
> + goto err_func;
> + }
> +
> + pgnames = devm_kzalloc(dev, sizeof(*pgnames), GFP_KERNEL);
> + if (!pgnames) {
> + ret = -ENOMEM;
> + goto err_pgnames;
> + }
> +
> + pgnames[0] = np_config->name;
> +
> + guard(mutex)(&mpctl->lock);
> +
> + selector = pinmux_generic_add_function(mpctl->pctl, np_config->name,
> + pgnames, 1, function);
> + if (selector < 0) {
> + ret = selector;
> + goto err_add_func;
> + }
> +
> + group = pinctrl_generic_add_group(mpctl->pctl, np_config->name, NULL, 0, mpctl);
> + if (group < 0) {
> + ret = group;
> + goto err_add_group;
> + }
> +
> + function->mux_state = devm_mux_state_get_from_np(pctldev->dev, NULL, np_config);
> + if (IS_ERR(function->mux_state)) {
> + ret = PTR_ERR(function->mux_state);
> + goto err_mux_state_get;
> + }
> +
> + (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
> + (*map)->data.mux.group = np_config->name;
> + (*map)->data.mux.function = np_config->name;
> +
> + *num_maps = 1;
> +
> + return 0;
> +
> +err_mux_state_get:
> + pinctrl_generic_remove_group(mpctl->pctl, group);
> +err_add_group:
> + pinmux_generic_remove_function(mpctl->pctl, selector);
> +err_add_func:
> + devm_kfree(dev, pgnames);
> +err_pgnames:
> + devm_kfree(dev, function);
> +err_func:
> + devm_kfree(dev, *map);
> +
> + return ret;
> +}
> +
> +static void
> +mux_pinmux_dt_free_map(struct pinctrl_dev *pctldev, struct pinctrl_map *map,
> + unsigned int num_maps)
> +{
> + struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
> +
> + devm_kfree(mpctl->dev, map);
> +}
> +
> +static const struct pinctrl_ops mux_pinctrl_ops = {
> + .get_groups_count = pinctrl_generic_get_group_count,
> + .get_group_name = pinctrl_generic_get_group_name,
> + .get_group_pins = pinctrl_generic_get_group_pins,
> + .dt_node_to_map = mux_pinmux_dt_node_to_map,
> + .dt_free_map = mux_pinmux_dt_free_map,
> +};
> +
> +static int mux_pinmux_set_mux(struct pinctrl_dev *pctldev,
> + unsigned int func_selector,
> + unsigned int group_selector)
> +{
> + struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
> + const struct function_desc *function;
> + struct mux_pin_function *func;
> + int ret;
> +
> + guard(mutex)(&mpctl->lock);
> +
> + function = pinmux_generic_get_function(pctldev, func_selector);
> + func = function->data;
> +
> + if (mpctl->cur_select == func_selector)
> + return 0;
> +
> + if (mpctl->cur_select >= 0 && mpctl->cur_select != func_selector)
> + return -EINVAL;
> +
> + ret = mux_state_select(func->mux_state);
There is no matching call to mux_state_deselect(). Quoting the docs for
mux_state_select{,_delay}():
On successfully selecting the mux-state, its mux-control will be
locked until there is a call to mux_state_deselect(). If the
mux-control is already selected when mux_state_select() is called,
the caller will be blocked until mux_state_deselect() or
mux_control_deselect() is called (by someone else).
Therefore, make sure to call mux_state_deselect() when the
operation is complete and the mux-control is free for others to
use, but do not call mux_state_deselect() if mux_state_select()
fails.
So, unless I'm missing something, you will get a deadlock if a pinctrl
have states backed by mux-states connected to the same mux-control (which
feels like the typical case) and you try to change between these pinctrl
states. Have you tried calling pinctrl_select_state() with this pinctrl
to mux things at runtime?
Cheers,
Peter
> + if (ret)
> + return ret;
> +
> + mpctl->cur_select = func_selector;
> +
> + return 0;
> +}
> +
> +static const struct pinmux_ops mux_pinmux_ops = {
> + .get_functions_count = pinmux_generic_get_function_count,
> + .get_function_name = pinmux_generic_get_function_name,
> + .get_function_groups = pinmux_generic_get_function_groups,
> + .set_mux = mux_pinmux_set_mux,
> +};
> +
> +static int mux_pinctrl_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct mux_pinctrl *mpctl;
> + struct pinctrl_desc *pctl_desc;
> + int ret;
> +
> + mpctl = devm_kzalloc(dev, sizeof(*mpctl), GFP_KERNEL);
> + if (!mpctl)
> + return -ENOMEM;
> +
> + mpctl->dev = dev;
> + mpctl->cur_select = -1;
> +
> + platform_set_drvdata(pdev, mpctl);
> +
> + pctl_desc = devm_kzalloc(dev, sizeof(*pctl_desc), GFP_KERNEL);
> + if (!pctl_desc)
> + return -ENOMEM;
> +
> + ret = devm_mutex_init(dev, &mpctl->lock);
> + if (ret)
> + return ret;
> +
> + pctl_desc->name = dev_name(dev);
> + pctl_desc->owner = THIS_MODULE;
> + pctl_desc->pctlops = &mux_pinctrl_ops;
> + pctl_desc->pmxops = &mux_pinmux_ops;
> +
> + ret = devm_pinctrl_register_and_init(dev, pctl_desc, mpctl,
> + &mpctl->pctl);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to register pinctrl.\n");
> +
> + ret = pinctrl_enable(mpctl->pctl);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to enable pinctrl.\n");
> +
> + return 0;
> +}
> +
> +static const struct of_device_id mux_pinctrl_of_match[] = {
> + { .compatible = "pinctrl-multiplexer" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, mux_pinctrl_of_match);
> +
> +static struct platform_driver mux_pinctrl_driver = {
> + .driver = {
> + .name = "generic-pinctrl-mux",
> + .of_match_table = mux_pinctrl_of_match,
> + },
> + .probe = mux_pinctrl_probe,
> +};
> +module_platform_driver(mux_pinctrl_driver);
> +
> +MODULE_AUTHOR("Frank Li <Frank.Li@nxp.com>");
> +MODULE_DESCRIPTION("Generic Pin Control Driver for Board-Level Mux Chips");
> +MODULE_LICENSE("GPL");
> +
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/5] arm64: dts: imx8mp-evk: add board-level mux for CAN2 and MICFIL
2026-02-19 22:23 [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips Frank Li
` (2 preceding siblings ...)
2026-02-19 22:23 ` [PATCH 3/5] pinctrl: add generic board-level pinctrl driver using mux framework Frank Li
@ 2026-02-19 22:23 ` Frank Li
2026-02-20 8:53 ` Daniel Baluta
2026-02-19 22:23 ` [PATCH 5/5] arm64: dts: imx8mp-evk: add flexcan2 overlay file Frank Li
2026-02-19 23:12 ` [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips Linus Walleij
5 siblings, 1 reply; 12+ messages in thread
From: Frank Li @ 2026-02-19 22:23 UTC (permalink / raw)
To: Peter Rosin, Linus Walleij, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: linux-kernel, linux-gpio, devicetree, imx, linux-arm-kernel,
Frank Li
The board integrates an on-board mux to route shared signals to either
CAN2 or PDM (MICFIL). The mux is controlled by a GPIO.
Add a pinctrl-based multiplexer node to describe this routing and ensure
proper probe ordering of the dependent devices.
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
arch/arm64/boot/dts/freescale/imx8mp-evk.dts | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/boot/dts/freescale/imx8mp-evk.dts b/arch/arm64/boot/dts/freescale/imx8mp-evk.dts
index b256be710ea1281465f5cecc7a3b979f2c068e43..1341ee27239fd41a26117adc9023524ce50420a7 100644
--- a/arch/arm64/boot/dts/freescale/imx8mp-evk.dts
+++ b/arch/arm64/boot/dts/freescale/imx8mp-evk.dts
@@ -50,6 +50,25 @@ status {
};
};
+ can_mux: mux-controller-0 {
+ compatible = "gpio-mux";
+ #mux-control-cells = <0>;
+ #mux-state-cells = <1>;
+ mux-gpios = <&pca6416 3 GPIO_ACTIVE_HIGH>;
+ };
+
+ can_mux_pinctrl: pinctrl-gpiomux {
+ compatible = "pinctrl-multiplexer";
+
+ can_fun: can-grp {
+ mux-states = <&can_mux 1>;
+ };
+
+ pdm_fun: pdm-grp {
+ mux-states = <&can_mux 0>;
+ };
+ };
+
memory@40000000 {
device_type = "memory";
reg = <0x0 0x40000000 0 0xc0000000>,
@@ -446,7 +465,7 @@ &flexcan1 {
&flexcan2 {
pinctrl-names = "default";
- pinctrl-0 = <&pinctrl_flexcan2>;
+ pinctrl-0 = <&pinctrl_flexcan2>, <&can_fun>;
phys = <&flexcan_phy 1>;
status = "disabled";/* can2 pin conflict with pdm */
};
@@ -712,7 +731,7 @@ &lcdif3 {
&micfil {
#sound-dai-cells = <0>;
pinctrl-names = "default";
- pinctrl-0 = <&pinctrl_pdm>;
+ pinctrl-0 = <&pinctrl_pdm>, <&pdm_fun>;
assigned-clocks = <&clk IMX8MP_CLK_PDM>;
assigned-clock-parents = <&clk IMX8MP_AUDIO_PLL1_OUT>;
assigned-clock-rates = <196608000>;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 4/5] arm64: dts: imx8mp-evk: add board-level mux for CAN2 and MICFIL
2026-02-19 22:23 ` [PATCH 4/5] arm64: dts: imx8mp-evk: add board-level mux for CAN2 and MICFIL Frank Li
@ 2026-02-20 8:53 ` Daniel Baluta
0 siblings, 0 replies; 12+ messages in thread
From: Daniel Baluta @ 2026-02-20 8:53 UTC (permalink / raw)
To: Frank Li, Peter Rosin, Linus Walleij, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Rafał Miłecki,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam
Cc: linux-kernel, linux-gpio, devicetree, imx, linux-arm-kernel
On 2/20/26 00:23, Frank Li wrote:
> The board integrates an on-board mux to route shared signals to either
> CAN2 or PDM (MICFIL). The mux is controlled by a GPIO.
>
> Add a pinctrl-based multiplexer node to describe this routing and ensure
> proper probe ordering of the dependent devices.
>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
Can you please explain what is wrong with the current approach?
Current dtb imx8mp-evk.dtb is used to enable PDM MICFIL and
sets proper pinctrl routing.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/5] arm64: dts: imx8mp-evk: add flexcan2 overlay file
2026-02-19 22:23 [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips Frank Li
` (3 preceding siblings ...)
2026-02-19 22:23 ` [PATCH 4/5] arm64: dts: imx8mp-evk: add board-level mux for CAN2 and MICFIL Frank Li
@ 2026-02-19 22:23 ` Frank Li
2026-02-19 23:12 ` [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips Linus Walleij
5 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2026-02-19 22:23 UTC (permalink / raw)
To: Peter Rosin, Linus Walleij, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: linux-kernel, linux-gpio, devicetree, imx, linux-arm-kernel,
Frank Li
Add flexcan2 overlay file, which enable flexcan2 node and disable micfil
node.
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
arch/arm64/boot/dts/freescale/Makefile | 4 ++++
arch/arm64/boot/dts/freescale/imx8mp-evk-flexcan2.dtso | 15 +++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/arch/arm64/boot/dts/freescale/Makefile b/arch/arm64/boot/dts/freescale/Makefile
index 700bab4d3e6001fe6cf460fcb09cfe57acc77e36..bd377191a68a6167d5f9a65184d19c789a4223ee 100644
--- a/arch/arm64/boot/dts/freescale/Makefile
+++ b/arch/arm64/boot/dts/freescale/Makefile
@@ -233,6 +233,10 @@ dtb-$(CONFIG_ARCH_MXC) += imx8mp-dhcom-pdk3.dtb
dtb-$(CONFIG_ARCH_MXC) += imx8mp-dhcom-picoitx.dtb
dtb-$(CONFIG_ARCH_MXC) += imx8mp-edm-g-wb.dtb
dtb-$(CONFIG_ARCH_MXC) += imx8mp-evk.dtb
+
+imx8mp-evk-flexcan2-dtbs += imx8mp-evk.dtb imx8mp-evk-flexcan2.dtbo
+dtb-$(CONFIG_ARCH_MXC) += imx8mp-evk-flexcan2.dtb
+
dtb-$(CONFIG_ARCH_MXC) += imx8mp-frdm.dtb
dtb-$(CONFIG_ARCH_MXC) += imx8mp-hummingboard-mate.dtb
dtb-$(CONFIG_ARCH_MXC) += imx8mp-hummingboard-pro.dtb
diff --git a/arch/arm64/boot/dts/freescale/imx8mp-evk-flexcan2.dtso b/arch/arm64/boot/dts/freescale/imx8mp-evk-flexcan2.dtso
new file mode 100644
index 0000000000000000000000000000000000000000..f7d2674c45f72353a20300300e98c8a1eba4a2a6
--- /dev/null
+++ b/arch/arm64/boot/dts/freescale/imx8mp-evk-flexcan2.dtso
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright 2026 NXP
+ */
+
+/dts-v1/;
+/plugin/;
+
+&flexcan2 {
+ status = "okay"; /* can2 pin conflict with pdm */
+};
+
+&micfil {
+ status = "disabled";
+};
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips
2026-02-19 22:23 [PATCH 0/5] pinctrl: Add generic pinctrl for board-level mux chips Frank Li
` (4 preceding siblings ...)
2026-02-19 22:23 ` [PATCH 5/5] arm64: dts: imx8mp-evk: add flexcan2 overlay file Frank Li
@ 2026-02-19 23:12 ` Linus Walleij
5 siblings, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2026-02-19 23:12 UTC (permalink / raw)
To: Frank Li
Cc: Peter Rosin, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Rafał Miłecki, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, linux-kernel, linux-gpio, devicetree, imx,
linux-arm-kernel
Hi Frank,
On Thu, Feb 19, 2026 at 11:24 PM Frank Li <Frank.Li@nxp.com> wrote:
> Add a generic pinctrl binding for board-level pinmux chips that are
> controlled through the multiplexer subsystem.
>
> On some boards, especially development boards, external mux chips are used
> to switch SoC signals between different peripherals (e.g. MMC and UART).
> The mux select lines are often driven by a GPIO expander over I2C,
> as illustrated below:
>
> ┌──────┐ ┌─────┐
> │ SOC │ │ │ ┌───────┐
> │ │ │ │───►│ MMC │
> │ │ │ MUX │ └───────┘
> │ ├─────►│ │ ┌───────┐
> │ │ │ │───►│ UART │
> │ │ └─────┘ └───────┘
> │ │ ▲
> │ │ ┌────┴──────────────┐
> │ I2C ├───►│ GPIO Expander │
> └──────┘ └───────────────────┘
>
> Traditionally, gpio-hog is used to configure the onboard mux at boot.
> However, the GPIO expander may probe later than consumer devices such as
> MMC. As a result, the MUX might not be configured when the peripheral
> driver probes, leading to initialization failures or data transfer errors.
>
> Introduce a generic pinctrl binding that models the board-level MUX as a
> pin control provider and builds proper device links between the MUX, its
> GPIO controller, and peripheral devices. This ensures correct probe
> ordering and reliable mux configuration.
>
> The implementation leverages the standard multiplexer subsystem, which
> provides broad support for onboard mux controllers and avoids the need for
> per-driver custom MUX handling
>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
I kind of like what I see here. :)
This makes a lot of sense: it uses muxes, and it muxes pins.
So that is the appropriate description, pinmuxes using
muxes (in turn controlled by GPIOs).
I just need to have buy-in from DT binding
maintainers and the authors of the mux core that this is a good
idea.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread