Skip to contentSkip to conversation

i2c: recovery: make pin init look like STOP

PATCH Superseded Wolfram Sang 5 participants 8 messages Jul 12, 2018 – Jul 17, 2018 I2C

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: recovery: make pin init look like STOP

When we we initialize the pins, make sure it looks like STOP by dividing the delay into halves. It shouldn't matter because SDA is expected to be held low by a device, but for super-safety, let's do it.

---
 drivers/i2c/i2c-core-base.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +3 -2
index 51cbb0c158f2..e57231ccb32a 100644
@@ -191,9 +191,10 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
 		bri->prepare_recovery(adap);
 
 	bri->set_scl(adap, scl);
+	ndelay(RECOVERY_NDELAY / 2);
 	if (bri->set_sda)
-		bri->set_sda(adap, 1);
-	ndelay(RECOVERY_NDELAY);
+		bri->set_sda(adap, scl);
+	ndelay(RECOVERY_NDELAY / 2);
 
 	/*
 	 * By this time SCL is high, as we need to give 9 falling-rising edges
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Wolfram Sang

When we we initialize the pins, make sure it looks like STOP by dividing the delay into halves. It shouldn't matter because SDA is expected to be held low by a device, but for super-safety, let's do it.

---
 drivers/i2c/i2c-core-base.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +0 -0
index 51cbb0c158f2..e57231ccb32a 100644

drivers/i2c/i2c-core-base.c int i2c_generic_scl_recovery(struct i2c_adapter *adap) · line 193

Quoted 3 lines
drivers/i2c/i2c-core-base.c +0 -0
@@ -191,9 +191,10 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
 		bri->prepare_recovery(adap);
 
 	bri->set_scl(adap, scl);

For me, it would be more natural to have

	bri->set_scl(adap, 1);

drivers/i2c/i2c-core-base.c int i2c_generic_scl_recovery(struct i2c_adapter *adap) · line 196

Quoted 5 lines
drivers/i2c/i2c-core-base.c +2 -2
+	ndelay(RECOVERY_NDELAY / 2);
 	if (bri->set_sda)
-		bri->set_sda(adap, 1);
-	ndelay(RECOVERY_NDELAY);
+		bri->set_sda(adap, scl);

instead of changing this "1" to "scl"? Same-same, but it looks odd to use scl as argument to sda (at least without that comment about sda following scl that is present inside the loop below).

At the same time, your version make the code inside the loop the same as this initializing code. Oh well, your call...

Either way

Cheers,
Peter

Quoted 5 lines
drivers/i2c/i2c-core-base.c +1 -0
+	ndelay(RECOVERY_NDELAY / 2);
 
 	/*
 	 * By this time SCL is high, as we need to give 9 falling-rising edges
#2 lore raw
Quoted 7 lines

instead of changing this "1" to "scl"? Same-same, but it looks odd to use scl as argument to sda (at least without that comment about sda following scl that is present inside the loop below).

At the same time, your version make the code inside the loop the same as this initializing code. Oh well, your call...

Yes, I wanted them to look alike. Yet, I agree to your comment about moving the comment. Will update.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Wolfram Sang
Quoted 3 lines · Wolfram Sang

When we we initialize the pins, make sure it looks like STOP by dividing the delay into halves. It shouldn't matter because SDA is expected to be held low by a device,

Yeah, what could possibly go wrong? :)

Quoted 24 lines
---
 drivers/i2c/i2c-core-base.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +3 -3
index 51cbb0c158f2..e57231ccb32a 100644
@@ -191,9 +191,10 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
                bri->prepare_recovery(adap);
 
        bri->set_scl(adap, scl);
+       ndelay(RECOVERY_NDELAY / 2);
        if (bri->set_sda)
-               bri->set_sda(adap, 1);
-       ndelay(RECOVERY_NDELAY);
+               bri->set_sda(adap, scl);
+       ndelay(RECOVERY_NDELAY / 2);
 
        /*
         * By this time SCL is high, as we need to give 9 falling-rising edges
--
Quoted 2 lines

2.11.0

CU
Uli

#4 lore raw
In reply to Wolfram Sang
Quoted 14 lines · Wolfram Sang

When we we initialize the pins, make sure it looks like STOP by dividing the delay into halves. It shouldn't matter because SDA is expected to be held low by a device, but for super-safety, let's do it.

---
 drivers/i2c/i2c-core-base.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +0 -0
index 51cbb0c158f2..e57231ccb32a 100644

drivers/i2c/i2c-core-base.c int i2c_generic_scl_recovery(struct i2c_adapter *adap) · line 194

Quoted 4 lines
drivers/i2c/i2c-core-base.c +1 -0
@@ -191,9 +191,10 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
                bri->prepare_recovery(adap);
 
        bri->set_scl(adap, scl);
+       ndelay(RECOVERY_NDELAY / 2);

Any change someone changes RECOVERY_NDELAY to 1, leading to a zero delay here? Is that an issue?

drivers/i2c/i2c-core-base.c int i2c_generic_scl_recovery(struct i2c_adapter *adap) · line 200

Quoted 8 lines
drivers/i2c/i2c-core-base.c +2 -2
        if (bri->set_sda)
-               bri->set_sda(adap, 1);
-       ndelay(RECOVERY_NDELAY);
+               bri->set_sda(adap, scl);
+       ndelay(RECOVERY_NDELAY / 2);
 
        /*
         * By this time SCL is high, as we need to give 9 falling-rising edges

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw
Quoted 18 lines · Geert Uytterhoeven
Quoted 16 lines · Wolfram Sang

When we we initialize the pins, make sure it looks like STOP by dividing the delay into halves. It shouldn't matter because SDA is expected to be held low by a device, but for super-safety, let's do it.

---
 drivers/i2c/i2c-core-base.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +0 -0
index 51cbb0c158f2..e57231ccb32a 100644
@@ -191,9 +191,10 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
                bri->prepare_recovery(adap);
 
Quoted 5 lines

drivers/i2c/i2c-core-base.c int i2c_generic_scl_recovery(struct i2c_adapter *adap) · line 194

Quoted 2 lines
drivers/i2c/i2c-core-base.c +1 -0
        bri->set_scl(adap, scl);
+       ndelay(RECOVERY_NDELAY / 2);

Any change someone changes RECOVERY_NDELAY to 1, leading to a zero delay here? Is that an issue?

No!

Above this, there is this line:

#define RECOVERY_NDELAY 5000

Cheers,
Peter

Quoted 13 lines

drivers/i2c/i2c-core-base.c int i2c_generic_scl_recovery(struct i2c_adapter *adap) · line 200

Quoted 8 lines
drivers/i2c/i2c-core-base.c +2 -2
        if (bri->set_sda)
-               bri->set_sda(adap, 1);
-       ndelay(RECOVERY_NDELAY);
+               bri->set_sda(adap, scl);
+       ndelay(RECOVERY_NDELAY / 2);
 
        /*
         * By this time SCL is high, as we need to give 9 falling-rising edges

Gr{oetje,eeting}s,

Geert

#6 lore raw

Hi Peter,

Quoted 25 lines · Peter Rosin
Quoted 18 lines · Geert Uytterhoeven
Quoted 16 lines · Wolfram Sang

When we we initialize the pins, make sure it looks like STOP by dividing the delay into halves. It shouldn't matter because SDA is expected to be held low by a device, but for super-safety, let's do it.

---
 drivers/i2c/i2c-core-base.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +0 -0
index 51cbb0c158f2..e57231ccb32a 100644
@@ -191,9 +191,10 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
                bri->prepare_recovery(adap);
 
Quoted 5 lines

drivers/i2c/i2c-core-base.c int i2c_generic_scl_recovery(struct i2c_adapter *adap) · line 194

Quoted 2 lines
drivers/i2c/i2c-core-base.c +1 -0
        bri->set_scl(adap, scl);
+       ndelay(RECOVERY_NDELAY / 2);

Any change someone changes RECOVERY_NDELAY to 1, leading to a zero delay here? Is that an issue?

Quoted 5 lines

No!

Above this, there is this line:

#define RECOVERY_NDELAY 5000

I did say "change".... (and the first once should have been "chance" ;-)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#7 lore raw
Quoted 11 lines
Quoted 9 lines
Quoted 3 lines

Any change someone changes RECOVERY_NDELAY to 1, leading to a zero delay here? Is that an issue?

No!

Above this, there is this line:

#define RECOVERY_NDELAY 5000

I did say "change".... (and the first once should have been "chance" ;-)

Still no ;) The pulses would be so small that devices won't recognize them. 1 or 0 as a delay won't make a difference then.