Some hardware need some time to switch from a bus to another. This can
cause the first transfers following the selection of a bus to fail.
There is no way to configure this kind of waiting time in the driver.
Add support for the 'settle-time-us' device-tree property. When set,
the i2c_mux_gpio_select() applies a delay before returning, leaving
enough time to the hardware to switch to the new bus.
Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com>
---
drivers/i2c/muxes/i2c-mux-gpio.c | 6 ++++++
include/linux/platform_data/i2c-mux-gpio.h | 2 ++
2 files changed, 8 insertions(+)
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index c61e9d9ea695..944577bb09c1 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -6,6 +6,7 @@
*/
#include <linux/bits.h>
+#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <linux/i2c.h>
@@ -37,6 +38,9 @@ static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan)
i2c_mux_gpio_set(mux, chan);
+ if (mux->data.settle_time)
+ fsleep(mux->data.settle_time);
+
return 0;
}
@@ -116,6 +120,8 @@ static int i2c_mux_gpio_probe_fw(struct gpiomux *mux,
if (device_property_read_u32(dev, "idle-state", &mux->data.idle))
mux->data.idle = I2C_MUX_GPIO_NO_IDLE;
+ device_property_read_u32(dev, "settle-time-us", &mux->data.settle_time);
+
return 0;
}
diff --git a/include/linux/platform_data/i2c-mux-gpio.h b/include/linux/platform_data/i2c-mux-gpio.h
index 816a4cd3ccb5..b548588aa1f2 100644
--- a/include/linux/platform_data/i2c-mux-gpio.h
+++ b/include/linux/platform_data/i2c-mux-gpio.h
@@ -19,6 +19,7 @@
* position
* @n_values: Number of multiplexer positions (busses to instantiate)
* @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used
+ * @settle_time: Delay to wait when a new bus is selected
*/
struct i2c_mux_gpio_platform_data {
int parent;
@@ -26,6 +27,7 @@ struct i2c_mux_gpio_platform_data {
const unsigned *values;
int n_values;
unsigned idle;
+ int settle_time;
};
#endif /* _LINUX_I2C_MUX_GPIO_H */
--
2.45.0
Hi Andi, > + int settle_time; Could you change this to u32 when applying? Sorry for being late... if you already applied this, I can send an incremental patch. Happy hacking, Wolfram
2024-06-17 at 14:08, Bastien Curutchet wrote: > Some hardware need some time to switch from a bus to another. This can > cause the first transfers following the selection of a bus to fail. > There is no way to configure this kind of waiting time in the driver. > > Add support for the 'settle-time-us' device-tree property. When set, > the i2c_mux_gpio_select() applies a delay before returning, leaving > enough time to the hardware to switch to the new bus. > > Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com> Acked-by: Peter Rosin <peda@axentia.se> Cheers, Peter
Hi, On Mon, Jun 17, 2024 at 02:08:18PM GMT, Bastien Curutchet wrote: > Some hardware need some time to switch from a bus to another. This can > cause the first transfers following the selection of a bus to fail. > There is no way to configure this kind of waiting time in the driver. > > Add support for the 'settle-time-us' device-tree property. When set, > the i2c_mux_gpio_select() applies a delay before returning, leaving > enough time to the hardware to switch to the new bus. > > Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com> Reviewed-by: Andi Shyti <andi.shyti@kernel.org> Thanks, Andi
© 2016 - 2026 Red Hat, Inc.