Skip to contentSkip to conversation

i2c: correct I2C deblock logic

PATCH In review [email protected] 3 participants 3 messages Mar 27, 2023 – Apr 11, 2023 I2C

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 i2c: correct I2C deblock logic

From: Haibo Chen <[email protected]>

Current code use dm_gpio_get_value() to get SDA and SCL value, and the value depends on whether DTS file config the GPIO_ACTIVE_LOW. In ususal case for i2c GPIO, DTS need to set GPIO_ACTIVE_LOW for SCL/SDA pins. So here the logic is not correct.

And we must not use GPIOD_ACTIVE_LOW in client code include the dm_gpio_set_dir_flags(), it is DTS's responsibility for this flag. So remove GPIOD_ACTIVE_LOW here.

Fixes aa54192d4a87 ("dm: i2c: implement gpio-based I2C deblock")
---
 drivers/i2c/i2c-uclass.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/i2c-uclass.c +2 -2
index 8d9a89ed89..8867a560bd 100644
@@ -508,13 +508,13 @@ static void i2c_gpio_set_pin(struct gpio_desc *pin, int bit)
 		dm_gpio_set_dir_flags(pin, GPIOD_IS_IN);
 	else
 		dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT |
-					   GPIOD_ACTIVE_LOW |
 					   GPIOD_IS_OUT_ACTIVE);
 }
 
 static int i2c_gpio_get_pin(struct gpio_desc *pin)
 {
-	return dm_gpio_get_value(pin);
+	/* DTS need config GPIO_ACTIVE_LOW */
+	return !dm_gpio_get_value(pin);
 }
 
 int i2c_deblock_gpio_loop(struct gpio_desc *sda_pin,
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw

Hello Haibo Chen.

The patch looks fine!

Reviewed-by Alexander Kochetkov <[email protected] <mailto:[email protected]>>
Quoted 42 lines

27 марта 2023 г., в 14:21, [email protected] написал(а):

From: Haibo Chen <[email protected]>

Current code use dm_gpio_get_value() to get SDA and SCL value, and the value depends on whether DTS file config the GPIO_ACTIVE_LOW. In ususal case for i2c GPIO, DTS need to set GPIO_ACTIVE_LOW for SCL/SDA pins. So here the logic is not correct.

And we must not use GPIOD_ACTIVE_LOW in client code include the dm_gpio_set_dir_flags(), it is DTS's responsibility for this flag. So remove GPIOD_ACTIVE_LOW here.

Fixes aa54192d4a87 ("dm: i2c: implement gpio-based I2C deblock")

---
drivers/i2c/i2c-uclass.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/i2c-uclass.c +2 -2
index 8d9a89ed89..8867a560bd 100644
@@ -508,13 +508,13 @@ static void i2c_gpio_set_pin(struct gpio_desc *pin, int bit)
 		dm_gpio_set_dir_flags(pin, GPIOD_IS_IN);
 	else
 		dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT |
-					   GPIOD_ACTIVE_LOW |
 					   GPIOD_IS_OUT_ACTIVE);
 }
 
 static int i2c_gpio_get_pin(struct gpio_desc *pin)
 {
-	return dm_gpio_get_value(pin);
+	/* DTS need config GPIO_ACTIVE_LOW */
+	return !dm_gpio_get_value(pin);
 }
 
 int i2c_deblock_gpio_loop(struct gpio_desc *sda_pin,
Signature · 1 line
2.34.1
#2 lore raw
In reply to [email protected]

Hello haibo,

Quoted 11 lines · On 27.03.23 13:21, [email protected] wrote:

From: Haibo Chen <[email protected]>

Current code use dm_gpio_get_value() to get SDA and SCL value, and the value depends on whether DTS file config the GPIO_ACTIVE_LOW. In ususal case for i2c GPIO, DTS need to set GPIO_ACTIVE_LOW for SCL/SDA pins. So here the logic is not correct.

And we must not use GPIOD_ACTIVE_LOW in client code include the dm_gpio_set_dir_flags(), it is DTS's responsibility for this flag. So remove GPIOD_ACTIVE_LOW here.

Quoted 5 lines
Fixes aa54192d4a87 ("dm: i2c: implement gpio-based I2C deblock")
---
 drivers/i2c/i2c-uclass.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-i2c.git master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]