From: Chintan Vankar <c-vankar@ti.com>
To: Thorsten Blum <thorsten.blum@linux.dev>,
Andrew Davis <afd@ti.com>, Chintan Vankar <c-vankar@ti.com>,
Conor Dooley <conor+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Rob Herring <robh@kernel.org>, Peter Rosin <peda@axentia.se>
Cc: <linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
<s-vadapalli@ti.com>, <vigneshr@ti.com>, <nm@ti.com>,
<danishanwar@ti.com>
Subject: [PATCH 2/2] mux: mmio: Extend mmio-mux driver to configure mux with mux-reg-masks-state
Date: Thu, 5 Jun 2025 12:04:22 +0530 [thread overview]
Message-ID: <20250605063422.3813260-3-c-vankar@ti.com> (raw)
In-Reply-To: <20250605063422.3813260-1-c-vankar@ti.com>
MMIO mux driver is designed to parse "mux-reg-masks" and "idle-states"
property independently to configure mux. The current design is complex for
the devices with larger memory space, which requires synchronization
between the two properties.
Extend mmio-mux driver to support a single property, "mux-reg-masks-state"
which configures mux registers without above constraint.
Signed-off-by: Chintan Vankar <c-vankar@ti.com>
---
drivers/mux/mmio.c | 144 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 118 insertions(+), 26 deletions(-)
diff --git a/drivers/mux/mmio.c b/drivers/mux/mmio.c
index 9993ce38a818..5ce9c16fd431 100644
--- a/drivers/mux/mmio.c
+++ b/drivers/mux/mmio.c
@@ -2,7 +2,7 @@
/*
* MMIO register bitfield-controlled multiplexer driver
*
- * Copyright (C) 2017 Pengutronix, Philipp Zabel <kernel@pengutronix.de>
+ * Copyright (C) 2017-2025 Pengutronix, Philipp Zabel <kernel@pengutronix.de>
*/
#include <linux/bitops.h>
@@ -39,10 +39,83 @@ static const struct regmap_config mux_mmio_regmap_cfg = {
.reg_stride = 4,
};
+static int reg_mux_get_controllers(const struct device_node *np, char *prop_name)
+{
+ int ret;
+
+ ret = of_property_count_u32_elems(np, prop_name);
+ if (ret == 0 || ret % 2)
+ ret = -EINVAL;
+
+ return ret;
+}
+
+static int reg_mux_get_controllers_extended(const struct device_node *np, char *prop_name)
+{
+ int ret;
+
+ ret = of_property_count_u32_elems(np, prop_name);
+ if (ret == 0 || ret % 3)
+ ret = -EINVAL;
+
+ return ret;
+}
+
+static int reg_mux_parse_dt(const struct device_node *np, bool *mux_reg_masks_state,
+ int *num_fields)
+{
+ int ret;
+
+ if (of_property_present(np, "mux-reg-masks-state")) {
+ *mux_reg_masks_state = true;
+ ret = reg_mux_get_controllers_extended(np, "mux-reg-masks-state");
+ if (ret < 0)
+ return ret;
+ *num_fields = ret / 3;
+ } else {
+ ret = reg_mux_get_controllers(np, "mux-reg-masks");
+ if (ret < 0)
+ return ret;
+ *num_fields = ret / 2;
+ }
+ return ret;
+}
+
+static int mux_reg_set_parameters(const struct device_node *np, char *prop_name, u32 *reg,
+ u32 *mask, int index)
+{
+ int ret;
+
+ ret = of_property_read_u32_index(np, prop_name, 2 * index, reg);
+ if (!ret)
+ ret = of_property_read_u32_index(np, prop_name, 2 * index + 1, mask);
+
+ return ret;
+}
+
+static int mux_reg_set_parameters_extended(const struct device_node *np, char *prop_name, u32 *reg,
+ u32 *mask, u32 *state, int index)
+{
+ int ret;
+
+ ret = of_property_read_u32_index(np, prop_name, 3 * index, reg);
+ if (ret < 0)
+ return ret;
+
+ ret = of_property_read_u32_index(np, prop_name, 3 * index + 1, mask);
+ if (ret < 0)
+ return ret;
+
+ ret = of_property_read_u32_index(np, prop_name, 3 * index + 2, state);
+
+ return ret;
+}
+
static int mux_mmio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
+ bool mux_reg_masks_state = false;
struct regmap_field **fields;
struct mux_chip *mux_chip;
struct regmap *regmap;
@@ -70,15 +143,16 @@ static int mux_mmio_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(regmap),
"failed to get regmap\n");
- ret = of_property_count_u32_elems(np, "mux-reg-masks");
- if (ret == 0 || ret % 2)
- ret = -EINVAL;
+ ret = reg_mux_parse_dt(np, &mux_reg_masks_state, &num_fields);
if (ret < 0) {
- dev_err(dev, "mux-reg-masks property missing or invalid: %d\n",
- ret);
+ if (mux_reg_masks_state)
+ dev_err(dev, "mux-reg-masks-state property missing or invalid: %d\n",
+ ret);
+ else
+ dev_err(dev, "mux-reg-masks property missing or invalid: %d\n",
+ ret);
return ret;
}
- num_fields = ret / 2;
mux_chip = devm_mux_chip_alloc(dev, num_fields, num_fields *
sizeof(*fields));
@@ -90,19 +164,25 @@ static int mux_mmio_probe(struct platform_device *pdev)
for (i = 0; i < num_fields; i++) {
struct mux_control *mux = &mux_chip->mux[i];
struct reg_field field;
- s32 idle_state = MUX_IDLE_AS_IS;
+ s32 state, idle_state = MUX_IDLE_AS_IS;
u32 reg, mask;
int bits;
- ret = of_property_read_u32_index(np, "mux-reg-masks",
- 2 * i, ®);
- if (!ret)
- ret = of_property_read_u32_index(np, "mux-reg-masks",
- 2 * i + 1, &mask);
- if (ret < 0) {
- dev_err(dev, "bitfield %d: failed to read mux-reg-masks property: %d\n",
- i, ret);
- return ret;
+ if (!mux_reg_masks_state) {
+ ret = mux_reg_set_parameters(np, "mux-reg-masks", ®, &mask, i);
+ if (ret < 0) {
+ dev_err(dev, "bitfield %d: failed to read mux-reg-masks property: %d\n",
+ i, ret);
+ return ret;
+ }
+ } else {
+ ret = mux_reg_set_parameters_extended(np, "mux-reg-masks-state", ®,
+ &mask, &state, i);
+ if (ret < 0) {
+ dev_err(dev, "bitfield %d: failed to read custom-states property: %d\n",
+ i, ret);
+ return ret;
+ }
}
field.reg = reg;
@@ -126,16 +206,28 @@ static int mux_mmio_probe(struct platform_device *pdev)
bits = 1 + field.msb - field.lsb;
mux->states = 1 << bits;
- of_property_read_u32_index(np, "idle-states", i,
- (u32 *)&idle_state);
- if (idle_state != MUX_IDLE_AS_IS) {
- if (idle_state < 0 || idle_state >= mux->states) {
- dev_err(dev, "bitfield: %d: out of range idle state %d\n",
- i, idle_state);
- return -EINVAL;
+ if (!mux_reg_masks_state) {
+ of_property_read_u32_index(np, "idle-states", i,
+ (u32 *)&idle_state);
+ if (idle_state != MUX_IDLE_AS_IS) {
+ if (idle_state < 0 || idle_state >= mux->states) {
+ dev_err(dev, "bitfield: %d: out of range idle state %d\n",
+ i, idle_state);
+ return -EINVAL;
+ }
+
+ mux->idle_state = idle_state;
+ }
+ } else {
+ if (state != MUX_IDLE_AS_IS) {
+ if (state < 0 || state >= mux->states) {
+ dev_err(dev, "bitfield: %d: out of range idle state %d\n",
+ i, state);
+ return -EINVAL;
+ }
+
+ mux->idle_state = state;
}
-
- mux->idle_state = idle_state;
}
}
--
2.34.1
next prev parent reply other threads:[~2025-06-05 6:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 6:34 [PATCH 0/2] Add support for new property 'mux-reg-masks-state' for mmio mux Chintan Vankar
2025-06-05 6:34 ` [PATCH 1/2] devicetree: bindings: mux: reg-mux: Add support for new property 'mux-reg-masks-state' Chintan Vankar
2025-06-05 6:46 ` Krzysztof Kozlowski
2025-06-25 18:48 ` Rob Herring
2025-06-05 6:34 ` Chintan Vankar [this message]
2025-06-05 6:36 ` [PATCH 2/2] mux: mmio: Extend mmio-mux driver to configure mux with mux-reg-masks-state Krzysztof Kozlowski
2025-06-05 6:41 ` Chintan Vankar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250605063422.3813260-3-c-vankar@ti.com \
--to=c-vankar@ti.com \
--cc=afd@ti.com \
--cc=conor+dt@kernel.org \
--cc=danishanwar@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nm@ti.com \
--cc=peda@axentia.se \
--cc=robh@kernel.org \
--cc=s-vadapalli@ti.com \
--cc=thorsten.blum@linux.dev \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®