From: Josua Mayer <josua@solid-run.com>
To: Ulf Hansson <ulf.hansson@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Magnus Damm <magnus.damm@gmail.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol@kernel.org>,
Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@kernel.org>,
Peter Rosin <peda@axentia.se>,
Aaro Koskinen <aaro.koskinen@iki.fi>,
Andreas Kemnade <andreas@kemnade.info>,
Kevin Hilman <khilman@baylibre.com>,
Roger Quadros <rogerq@kernel.org>,
Tony Lindgren <tony@atomide.com>, Vignesh R <vigneshr@ti.com>,
Janusz Krzysztofik <jmkrzyszt@gmail.com>,
Andi Shyti <andi.shyti@kernel.org>
Cc: Mikhail Anikin <mikhail.anikin@solid-run.com>,
Yazan Shhady <yazan.shhady@solid-run.com>,
Jon Nettleton <jon@solid-run.com>,
linux-mmc@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-can@vger.kernel.org, linux-phy@lists.infradead.org,
linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org,
Josua Mayer <josua@solid-run.com>
Subject: [PATCH v3 2/6] mux: Add helper functions for getting optional and selected mux-state
Date: Wed, 10 Dec 2025 18:38:36 +0100 [thread overview]
Message-ID: <20251210-rz-sdio-mux-v3-2-ca628db56d60@solid-run.com> (raw)
In-Reply-To: <20251210-rz-sdio-mux-v3-0-ca628db56d60@solid-run.com>
In-tree phy-can-transceiver driver has already implemented a local
version of devm_mux_state_get_optional.
The omap-i2c driver gets and selects an optional mux in its probe
function without using any helper.
Add new helper functions covering both aforementioned use-cases:
- devm_mux_state_get_optional:
Get a mux-state if specified in dt, return NULL otherwise.
- devm_mux_state_get_optional_selected:
Get and select a mux-state if specified in dt, return error or NULL.
Existing mux_get helper function is changed to return -ENOENT in case dt
did not specify a mux-state or -control matching given name (if valid).
This matches of_parse_phandle_with_args semantics which also returns
-ENOENT if the property does nto exists, or its value is zero.
The new helper functions check for ENOENT to return NULL for optional
muxes.
Commit e153fdea9db04 ("phy: can-transceiver: Re-instate "mux-states"
property presence check") noted that "mux_get() always prints an error
message in case of an error, including when the property is not present,
confusing the user."
The first error message covers the case that a mux name is not matched
in dt. This is removed as the returned error code (-ENOENT) is clear.
The second error message is based on of_parse_phandle_with_args return
value. In case mux description is missing from DT, it returns -ENOENT.
Print error message only for other error codes.
This ensures that the new helper functions will not confuse the user
either.
Signed-off-by: Josua Mayer <josua@solid-run.com>
---
drivers/mux/core.c | 67 +++++++++++++++++++++++++++++++++++++++-----
include/linux/mux/consumer.h | 4 +++
2 files changed, 64 insertions(+), 7 deletions(-)
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index a3840fe0995fe..130ca47a8be37 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -542,11 +542,8 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
else
index = of_property_match_string(np, "mux-control-names",
mux_name);
- if (index < 0) {
- dev_err(dev, "mux controller '%s' not found\n",
- mux_name);
- return ERR_PTR(index);
- }
+ if (index < 0)
+ return ERR_PTR(-ENOENT);
}
if (state)
@@ -558,8 +555,10 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
"mux-controls", "#mux-control-cells",
index, &args);
if (ret) {
- dev_err(dev, "%pOF: failed to get mux-%s %s(%i)\n",
- np, state ? "state" : "control", mux_name ?: "", index);
+ if (ret != -ENOENT)
+ dev_err(dev, "%pOF: failed to get mux-%s %s(%i)\n",
+ np, state ? "state" : "control",
+ mux_name ?: "", index);
return ERR_PTR(ret);
}
@@ -745,6 +744,60 @@ struct mux_state *devm_mux_state_get(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_mux_state_get);
+/**
+ * devm_mux_state_get_optional() - Get the optional mux-state for a device,
+ * with resource management.
+ * @dev: The device that needs a mux-state.
+ * @mux_name: The name identifying the mux-state.
+ *
+ * Return: Pointer to the mux-state, or an ERR_PTR with a negative errno.
+ */
+struct mux_state *devm_mux_state_get_optional(struct device *dev,
+ const char *mux_name)
+{
+ struct mux_state *mux_state = devm_mux_state_get(dev, mux_name);
+
+ if (IS_ERR(mux_state) && PTR_ERR(mux_state) == -ENOENT)
+ return NULL;
+
+ return mux_state;
+}
+EXPORT_SYMBOL_GPL(devm_mux_state_get_optional);
+
+/**
+ * devm_mux_state_get_optional_selected() - Get the optional mux-state for
+ * a device, with resource management.
+ * @dev: The device that needs a mux-state.
+ * @mux_name: The name identifying the mux-state.
+ *
+ * Return: Pointer to the mux-state, or an ERR_PTR with a negative errno.
+ *
+ * The returned mux-state (if valid) is already selected.
+ */
+struct mux_state *devm_mux_state_get_optional_selected(struct device *dev,
+ const char *mux_name)
+{
+ struct mux_state *mux_state;
+ int ret;
+
+ mux_state = devm_mux_state_get_optional(dev, mux_name);
+ if (IS_ERR_OR_NULL(mux_state))
+ return mux_state;
+
+ ret = mux_state_select(mux_state);
+ if (ret) {
+ if (ret != -EPROBE_DEFER)
+ dev_err(dev, "failed to select mux-state %s: %d\n",
+ mux_name ?: "", ret);
+
+ mux_state_put(mux_state);
+ return ERR_PTR(ret);
+ }
+
+ return mux_state;
+}
+EXPORT_SYMBOL_GPL(devm_mux_state_get_optional_selected);
+
/*
* Using subsys_initcall instead of module_init here to try to ensure - for
* the non-modular case - that the subsystem is initialized when mux consumers
diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h
index 2e25c838f8312..a5da2e33a45c0 100644
--- a/include/linux/mux/consumer.h
+++ b/include/linux/mux/consumer.h
@@ -60,5 +60,9 @@ 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_state *devm_mux_state_get_optional(struct device *dev,
+ const char *mux_name);
+struct mux_state *devm_mux_state_get_optional_selected(struct device *dev,
+ const char *mux_name);
#endif /* _LINUX_MUX_CONSUMER_H */
--
2.51.0
next prev parent reply other threads:[~2025-12-10 17:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 17:38 [PATCH v3 0/6] mmc: host: renesas_sdhi_core: support configuring an optional sdio mux Josua Mayer
2025-12-10 17:38 ` [PATCH v3 1/6] phy: can-transceiver: rename temporary helper function to avoid conflict Josua Mayer
2025-12-10 17:38 ` Josua Mayer [this message]
2025-12-10 17:38 ` [PATCH v3 3/6] phy: can-transceiver: drop temporary helper getting optional mux-state Josua Mayer
2025-12-10 17:38 ` [PATCH v3 4/6] i2c: omap: switch to new generic helper for getting selected mux-state Josua Mayer
2025-12-10 17:38 ` [PATCH v3 5/6] dt-bindings: mmc: renesas,sdhi: Add mux-states property Josua Mayer
2025-12-10 17:38 ` [PATCH v3 6/6] mmc: host: renesas_sdhi_core: support selecting an optional mux Josua Mayer
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=20251210-rz-sdio-mux-v3-2-ca628db56d60@solid-run.com \
--to=josua@solid-run.com \
--cc=aaro.koskinen@iki.fi \
--cc=andi.shyti@kernel.org \
--cc=andreas@kemnade.info \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=geert+renesas@glider.be \
--cc=jmkrzyszt@gmail.com \
--cc=jon@solid-run.com \
--cc=khilman@baylibre.com \
--cc=kishon@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mailhol@kernel.org \
--cc=mikhail.anikin@solid-run.com \
--cc=mkl@pengutronix.de \
--cc=peda@axentia.se \
--cc=robh@kernel.org \
--cc=rogerq@kernel.org \
--cc=tony@atomide.com \
--cc=ulf.hansson@linaro.org \
--cc=vigneshr@ti.com \
--cc=vkoul@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=yazan.shhady@solid-run.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;
as well as URLs for NNTP newsgroup(s).