]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
i2c: muxes: pca954x: Reset if (de)select fails
authorWojciech Siudy <wojciech.siudy@nokia.com>
Tue, 3 Jun 2025 12:47:21 +0000 (14:47 +0200)
committerWolfram Sang <wsa+renesas@sang-engineering.com>
Mon, 11 Aug 2025 18:10:09 +0000 (20:10 +0200)
If the channel selection or deselection times out, it indicates
a failure in the mux's I2C subsystem. Without sending a reset pulse,
a power-on-reset of the entire device would be required to restore
communication.

The datasheet specifies a minimum hold time of 4 ns for the reset
pulse, but due to the path's capacitance and themux having its own
clock, it is recommended to extend this to approximately 1 us.

Since reset controller is used, there is no need to take care of other
devices sharing the same reset line.

Signed-off-by: Wojciech Siudy <wojciech.siudy@nokia.com>
[wsa: removed superfluous prinout, unneeded braces and fixed indent]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
drivers/i2c/muxes/i2c-mux-pca954x.c

index a9ddd548781ccf04f0ebd9bb8ed575d10bd8210a..75c8d08fa24e56fcb22b755133efeab79ea85397 100644 (file)
@@ -315,6 +315,25 @@ static u8 pca954x_regval(struct pca954x *data, u8 chan)
                return 1 << chan;
 }
 
+static void pca954x_reset_assert(struct pca954x *data)
+{
+       if (data->reset_cont)
+               reset_control_assert(data->reset_cont);
+}
+
+static void pca954x_reset_deassert(struct pca954x *data)
+{
+       if (data->reset_cont)
+               reset_control_deassert(data->reset_cont);
+}
+
+static void pca954x_reset_mux(struct pca954x *data)
+{
+       pca954x_reset_assert(data);
+       udelay(1);
+       pca954x_reset_deassert(data);
+}
+
 static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan)
 {
        struct pca954x *data = i2c_mux_priv(muxc);
@@ -328,6 +347,8 @@ static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan)
                ret = pca954x_reg_write(muxc->parent, client, regval);
                data->last_chan = ret < 0 ? 0 : regval;
        }
+       if (ret == -ETIMEDOUT && data->reset_cont)
+               pca954x_reset_mux(data);
 
        return ret;
 }
@@ -337,6 +358,7 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
        struct pca954x *data = i2c_mux_priv(muxc);
        struct i2c_client *client = data->client;
        s32 idle_state;
+       int ret = 0;
 
        idle_state = READ_ONCE(data->idle_state);
        if (idle_state >= 0)
@@ -346,8 +368,10 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
        if (idle_state == MUX_IDLE_DISCONNECT) {
                /* Deselect active channel */
                data->last_chan = 0;
-               return pca954x_reg_write(muxc->parent, client,
-                                        data->last_chan);
+               ret = pca954x_reg_write(muxc->parent, client,
+                                       data->last_chan);
+               if (ret == -ETIMEDOUT && data->reset_cont)
+                       pca954x_reset_mux(data);
        }
 
        /* otherwise leave as-is */
@@ -530,12 +554,6 @@ static int pca954x_get_reset(struct device *dev, struct pca954x *data)
        return 0;
 }
 
-static void pca954x_reset_deassert(struct pca954x *data)
-{
-       if (data->reset_cont)
-               reset_control_deassert(data->reset_cont);
-}
-
 /*
  * I2C init/probing/exit functions
  */