diff mbox series

[4/4] i2c: gpio: Run deblock sequence on probe

Message ID 20200207155752.40930-4-marex@denx.de
State Awaiting Upstream
Delegated to: Heiko Schocher
Headers show
Series [1/4] i2c: Make deblock delay and SCL clock configurable | expand

Commit Message

Marek Vasut Feb. 7, 2020, 3:57 p.m. UTC
Add deblock dequence for the I2C bus, needed on some devices. This sequence
is issued once, when probing the driver, and is controlled by DT property,
"i2c-gpio,deblock".

Signed-off-by: Marek Vasut <marex@denx.de>
---
 drivers/i2c/i2c-gpio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Heiko Schocher Feb. 18, 2020, 7:11 a.m. UTC | #1
Hello Marek,

Am 07.02.2020 um 16:57 schrieb Marek Vasut:
> Add deblock dequence for the I2C bus, needed on some devices. This sequence
> is issued once, when probing the driver, and is controlled by DT property,
> "i2c-gpio,deblock".
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
>   drivers/i2c/i2c-gpio.c | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)

Nitpick: I see no entry in doc/device-tree-bindings/i2c/i2c-gpio.txt
for the new dts binding ... please send a follow up patch which adds it,
or a v2 for this one, thanks!

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
> 
> diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c
> index 4e8fa21473..b6b6ba9ee8 100644
> --- a/drivers/i2c/i2c-gpio.c
> +++ b/drivers/i2c/i2c-gpio.c
> @@ -305,6 +305,20 @@ static int i2c_gpio_set_bus_speed(struct udevice *dev, unsigned int speed_hz)
>   	return 0;
>   }
>   
> +static int i2c_gpio_drv_probe(struct udevice *dev)
> +{
> +	if (dev_read_bool(dev, "i2c-gpio,deblock")) {
> +		/* @200kHz 9 clocks = 44us, 62us is ok */
> +		const unsigned int DELAY_ABORT_SEQ = 62;
> +		struct i2c_gpio_bus *bus = dev_get_priv(dev);
> +		return i2c_deblock_gpio_loop(&bus->gpios[PIN_SDA],
> +					     &bus->gpios[PIN_SCL],
> +					     16, 5, DELAY_ABORT_SEQ);
> +	}
> +
> +	return 0;
> +}
> +
>   static int i2c_gpio_ofdata_to_platdata(struct udevice *dev)
>   {
>   	struct i2c_gpio_bus *bus = dev_get_priv(dev);
> @@ -341,6 +355,7 @@ U_BOOT_DRIVER(i2c_gpio) = {
>   	.name	= "i2c-gpio",
>   	.id	= UCLASS_I2C,
>   	.of_match = i2c_gpio_ids,
> +	.probe	= i2c_gpio_drv_probe,
>   	.ofdata_to_platdata = i2c_gpio_ofdata_to_platdata,
>   	.priv_auto_alloc_size = sizeof(struct i2c_gpio_bus),
>   	.ops	= &i2c_gpio_ops,
>
Marek Vasut Feb. 18, 2020, 5:25 p.m. UTC | #2
On 2/18/20 8:11 AM, Heiko Schocher wrote:
> Hello Marek,
> 
> Am 07.02.2020 um 16:57 schrieb Marek Vasut:
>> Add deblock dequence for the I2C bus, needed on some devices. This
>> sequence
>> is issued once, when probing the driver, and is controlled by DT
>> property,
>> "i2c-gpio,deblock".
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> ---
>>   drivers/i2c/i2c-gpio.c | 15 +++++++++++++++
>>   1 file changed, 15 insertions(+)
> 
> Nitpick: I see no entry in doc/device-tree-bindings/i2c/i2c-gpio.txt
> for the new dts binding ... please send a follow up patch which adds it,
> or a v2 for this one, thanks!

Done in
[PATCH] doc: i2c: gpio: Document deblock sequence on probe
Heiko Schocher March 17, 2020, 5:11 a.m. UTC | #3
Hello Marek,

Am 07.02.2020 um 16:57 schrieb Marek Vasut:
> Add deblock dequence for the I2C bus, needed on some devices. This sequence
> is issued once, when probing the driver, and is controlled by DT property,
> "i2c-gpio,deblock".
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
>   drivers/i2c/i2c-gpio.c | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)

Applied to u-boot-i2c next, thanks!

bye,
Heiko
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c
index 4e8fa21473..b6b6ba9ee8 100644
--- a/drivers/i2c/i2c-gpio.c
+++ b/drivers/i2c/i2c-gpio.c
@@ -305,6 +305,20 @@  static int i2c_gpio_set_bus_speed(struct udevice *dev, unsigned int speed_hz)
 	return 0;
 }
 
+static int i2c_gpio_drv_probe(struct udevice *dev)
+{
+	if (dev_read_bool(dev, "i2c-gpio,deblock")) {
+		/* @200kHz 9 clocks = 44us, 62us is ok */
+		const unsigned int DELAY_ABORT_SEQ = 62;
+		struct i2c_gpio_bus *bus = dev_get_priv(dev);
+		return i2c_deblock_gpio_loop(&bus->gpios[PIN_SDA],
+					     &bus->gpios[PIN_SCL],
+					     16, 5, DELAY_ABORT_SEQ);
+	}
+
+	return 0;
+}
+
 static int i2c_gpio_ofdata_to_platdata(struct udevice *dev)
 {
 	struct i2c_gpio_bus *bus = dev_get_priv(dev);
@@ -341,6 +355,7 @@  U_BOOT_DRIVER(i2c_gpio) = {
 	.name	= "i2c-gpio",
 	.id	= UCLASS_I2C,
 	.of_match = i2c_gpio_ids,
+	.probe	= i2c_gpio_drv_probe,
 	.ofdata_to_platdata = i2c_gpio_ofdata_to_platdata,
 	.priv_auto_alloc_size = sizeof(struct i2c_gpio_bus),
 	.ops	= &i2c_gpio_ops,