mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Peter Rosin <peda@lysator.liu.se>
Cc: Andi Shyti <andi.shyti@kernel.org>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH 2/3] i2c: mux: pca954x: Introduce pca954x_set_idle_state()
Date: Fri,  6 Nov 2026 12:33:21 -0800	[thread overview]
Message-ID: <561e1795c458534235b070e8895669673bf3897c.1793997098.git.bvanassche@acm.org> (raw)
In-Reply-To: <cover.1793997098.git.bvanassche@acm.org>

idle_state_store() calls pca954x_deselect_mux() with a dummy channel
number of 0 since it only needs to program the mux into the state that
corresponds to idle_state. Move the body of pca954x_deselect_mux() into
a new function pca954x_set_idle_state() that does not have a channel
argument, and call that function from idle_state_store(). This prepares
for making pca954x_deselect_mux() report failures that include the
channel number. Also convert the if-statement for MUX_IDLE_DISCONNECT
into an early return.

No functional change intended.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/i2c/muxes/i2c-mux-pca954x.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index e34b4668a1fa..91df2d2fa2b7 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -333,7 +333,8 @@ static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan)
 	return ret;
 }
 
-static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
+/* Program the mux into the state that corresponds to idle_state. */
+static int pca954x_set_idle_state(struct i2c_mux_core *muxc)
 {
 	struct pca954x *data = i2c_mux_priv(muxc);
 	struct i2c_client *client = data->client;
@@ -345,16 +346,20 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
 		/* Set the mux back to a predetermined channel */
 		return pca954x_select_chan(muxc, idle_state);
 
-	if (idle_state == MUX_IDLE_DISCONNECT) {
-		/* Deselect active channel */
-		ret = pca954x_reg_write(muxc->parent, client, 0);
-		data->last_chan = ret < 0 ? -1 : 0;
-		return ret;
-	}
+	/* Leave the mux as-is unless idle_state is MUX_IDLE_DISCONNECT */
+	if (idle_state != MUX_IDLE_DISCONNECT)
+		return 0;
 
-	/* otherwise leave as-is */
+	/* Deselect active channel */
+	ret = pca954x_reg_write(muxc->parent, client, 0);
+	data->last_chan = ret < 0 ? -1 : 0;
 
-	return 0;
+	return ret;
+}
+
+static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
+{
+	return pca954x_set_idle_state(muxc);
 }
 
 static ssize_t idle_state_show(struct device *dev,
@@ -394,7 +399,7 @@ static ssize_t idle_state_store(struct device *dev,
 	 * idle_state.
 	 */
 	if (data->last_chan != 0 || val != MUX_IDLE_DISCONNECT)
-		ret = pca954x_deselect_mux(muxc, 0);
+		ret = pca954x_set_idle_state(muxc);
 
 	i2c_unlock_bus(muxc->parent, I2C_LOCK_SEGMENT);
 

  parent reply	other threads:[~2026-11-06 20:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 20:33 [PATCH 0/3] i2c: mux: pca954x: Track unknown mux state and report deselect failures Bart Van Assche
2026-11-06 20:33 ` [PATCH 1/3] i2c: mux: pca954x: Track unknown channel state Bart Van Assche
2026-11-06 20:33 ` Bart Van Assche [this message]
2026-11-06 20:33 ` [PATCH 3/3] i2c: mux: pca954x: Report deselect failures Bart Van Assche

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=561e1795c458534235b070e8895669673bf3897c.1793997098.git.bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=andi.shyti@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@lysator.liu.se \
    --cc=wsa+renesas@sang-engineering.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®