mbox series

[v2,0/3] i2c: mux: gpio: Add 'transition-delay-us' property

Message ID 20240529091739.10808-1-bastien.curutchet@bootlin.com
Headers show
Series i2c: mux: gpio: Add 'transition-delay-us' property | expand

Message

Bastien Curutchet May 29, 2024, 9:17 a.m. UTC
Hi all,

The i2c-gpio-mux can be used to describe a multiplexer built upon
several i2c isolators having an enable pin (such as LTC4310):

 +---------------+                     +------+  +------+
 | +-----------+ |                     | dev  |  | dev  |
 | | GPIO_EN_A |-|-----------|         +------+  +------+
 | +-----------+ |     +-----+---+         |         |
 |               |  |--| isol. A |---------+---------+
 |     +-----+   |  |  +---------+
 | SOC | I2C |---|--|
 |     +-----+   |  |  +---------+
 |               |  |--| isol. B |------+---------+---------+
 | +-----------+ |     +-----+---+      |         |         |
 | | GPIO_EN_B |-|-----------|      +------+  +------+  +------+
 | +-----------+ |                  | dev  |  | dev  |  | dev  |
 +---------------+                  +------+  +------+  +------+

These isolators often need some time between their enable pin's
assertion and the first i2c transfer. If the first i2c transfer
happens before this enabling time is reached, transfer fails.

There is no available option to configure such a time in the
i2c-gpio-mux driver.

Add a optional property in the bindings called 'transition-delay-us'.
If present, driver waits for this delay every time a new bus is
selected, i.e. before returning from the bus_select() callback.

Changes in v2:
 * Rewrite bindings' commit log
 * Express the 'transition delay' in us instead of ms

Bastien Curutchet (3):
  dt-bindings: i2c: gpio: Add 'transition-delay-us' property
  i2c: mux: gpio: Re-order #include to match alphabetic order
  i2c: mux: gpio: Add support for the 'transition-delay-us' property

 .../devicetree/bindings/i2c/i2c-mux-gpio.yaml      |  3 +++
 drivers/i2c/muxes/i2c-mux-gpio.c                   | 14 ++++++++++----
 include/linux/platform_data/i2c-mux-gpio.h         |  2 ++
 3 files changed, 15 insertions(+), 4 deletions(-)

Comments

Peter Rosin May 29, 2024, 12:16 p.m. UTC | #1
Hi!

2024-05-29 at 11:17, 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 'transition-delay-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..b9cfc80660e2 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.transition_delay)
> +		udelay(mux->data.transition_delay);

fsleep() is appropriate here.

Cheers,
Peter