i2c: muxes: pca954x: Reset if (de)select fails

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>
This commit is contained in:
Wojciech Siudy
2025-06-03 14:47:21 +02:00
committed by Wolfram Sang
parent 690de2902d
commit 94c2967764

View File

@@ -315,6 +315,25 @@ static u8 pca954x_regval(struct pca954x *data, u8 chan)
return 1 << 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) static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan)
{ {
struct pca954x *data = i2c_mux_priv(muxc); 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); ret = pca954x_reg_write(muxc->parent, client, regval);
data->last_chan = ret < 0 ? 0 : regval; data->last_chan = ret < 0 ? 0 : regval;
} }
if (ret == -ETIMEDOUT && data->reset_cont)
pca954x_reset_mux(data);
return ret; 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 pca954x *data = i2c_mux_priv(muxc);
struct i2c_client *client = data->client; struct i2c_client *client = data->client;
s32 idle_state; s32 idle_state;
int ret = 0;
idle_state = READ_ONCE(data->idle_state); idle_state = READ_ONCE(data->idle_state);
if (idle_state >= 0) 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) { if (idle_state == MUX_IDLE_DISCONNECT) {
/* Deselect active channel */ /* Deselect active channel */
data->last_chan = 0; data->last_chan = 0;
return pca954x_reg_write(muxc->parent, client, ret = pca954x_reg_write(muxc->parent, client,
data->last_chan); data->last_chan);
if (ret == -ETIMEDOUT && data->reset_cont)
pca954x_reset_mux(data);
} }
/* otherwise leave as-is */ /* otherwise leave as-is */
@@ -530,12 +554,6 @@ static int pca954x_get_reset(struct device *dev, struct pca954x *data)
return 0; 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 * I2C init/probing/exit functions
*/ */