Commit 94c29677 authored by Wojciech Siudy's avatar Wojciech Siudy Committed by Wolfram Sang
Browse files

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: default avatarWojciech Siudy <wojciech.siudy@nokia.com>
[wsa: removed superfluous prinout, unneeded braces and fixed indent]
Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
parent 690de290
Loading
Loading
Loading
Loading
+26 −8
Original line number Diff line number Diff line
@@ -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,
		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
 */