Skip to contentSkip to conversation

i2c: npcm7xx: bug fix timeout (usec instead of msec)

PATCH In review Tali Perry 3 participants 5 messages Aug 30, 2020 – Aug 31, 2020

Subsystems (2)
lore
Share & tools
lore

Tali Perry

author maintainer
#0 lore raw

PATCH v2 1/1 i2c: npcm7xx: bug fix timeout (usec instead of msec)

i2c: npcm7xx: bug fix timeout (usec instead of msec)

---
 drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +7 -2
index 75f07138a6fa..abb334492a3d 100644
@@ -2093,8 +2093,13 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 		}
 	}
 
-	/* Adaptive TimeOut: astimated time in usec + 100% margin */
-	timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
+	/*
+	 * Adaptive TimeOut: estimated time in usec + 100% margin:
+	 * 2: double the timeout for clock stretching case
+	 * 9: bits per transaction (including the ack/nack)
+	 * 1000000: micro second in a second
+	 */
+	timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);
 	timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
 	if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
 		dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);

base-commit: d012a7190fc1fd72ed48911e77ca97ba4521bccd

Signature · 1 line
2.22.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Tali Perry

i2c: npcm7xx: bug fix timeout (usec instead of msec)

Quoted 25 lines
---
 drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +7 -2
index 75f07138a6fa..abb334492a3d 100644
@@ -2093,8 +2093,13 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
                }
        }
 
-       /* Adaptive TimeOut: astimated time in usec + 100% margin */
-       timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
+       /*
+        * Adaptive TimeOut: estimated time in usec + 100% margin:
+        * 2: double the timeout for clock stretching case
+        * 9: bits per transaction (including the ack/nack)
+        * 1000000: micro second in a second
+        */
+       timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);
        timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
        if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
                dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);
Quoted 4 lines

base-commit: d012a7190fc1fd72ed48911e77ca97ba4521bccd --
2.22.0

--
Regards,
Avi

#2 lore raw
In reply to Tali Perry
Quoted 2 lines · Tali Perry

i2c: npcm7xx: bug fix timeout (usec instead of msec)

This commit message is awful. Please read [1] as a tutorial how to write a commit messages.

[1]: https://chris.beams.io/posts/git-commit/

...

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, · line 2100

Quoted 8 lines
drivers/i2c/busses/i2c-npcm7xx.c +5 -2
-       /* Adaptive TimeOut: astimated time in usec + 100% margin */
-       timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
+       /*
+        * Adaptive TimeOut: estimated time in usec + 100% margin:
+        * 2: double the timeout for clock stretching case
+        * 9: bits per transaction (including the ack/nack)
 
+        * 1000000: micro second in a second

No need. See below.

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, · line 2102

Quoted 3 lines
drivers/i2c/busses/i2c-npcm7xx.c +2 -0
+        */
 
+       timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);

USEC_PER_SEC

Quoted 3 lines
        timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
        if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
                dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 2 lines · Tali Perry

i2c: npcm7xx: bug fix timeout (usec instead of msec)

This commit message is awful. Please read [1] as a tutorial how to write a commit messages.

Would this be better:
i2c: npcm7xx: Fix microsecond timeout calculation

Inside npcm_i2c_master_xfer() we calculate a timeout for the entire transaction in microseconds, the calculation was wrong so big i2c massages would timeout before they ended.
This commit fix that.

Quoted 13 lines

[1]: https://chris.beams.io/posts/git-commit/

...

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, · line 2100

Quoted 8 lines
drivers/i2c/busses/i2c-npcm7xx.c +5 -2
-       /* Adaptive TimeOut: astimated time in usec + 100% margin */
-       timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
+       /*
+        * Adaptive TimeOut: estimated time in usec + 100% margin:
+        * 2: double the timeout for clock stretching case
+        * 9: bits per transaction (including the ack/nack)
 
+        * 1000000: micro second in a second
Quoted 7 lines

No need. See below.

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, · line 2102

Quoted 3 lines
drivers/i2c/busses/i2c-npcm7xx.c +2 -0
+        */
 
+       timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);

USEC_PER_SEC

OK

Quoted 8 lines
Quoted 4 lines
        timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
        if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
                dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);

--
With Best Regards,
Andy Shevchenko

Signature · 2 lines
Regards,
Avi
maintainer
#4 lore raw

Please ignore my last mail, Tali already sent v3.

Quoted 58 lines · Avi Fishman
Quoted 9 lines · Andy Shevchenko
Quoted 2 lines · Tali Perry

i2c: npcm7xx: bug fix timeout (usec instead of msec)

This commit message is awful. Please read [1] as a tutorial how to write a commit messages.

Would this be better:
i2c: npcm7xx: Fix microsecond timeout calculation

Inside npcm_i2c_master_xfer() we calculate a timeout for the entire transaction in microseconds, the calculation was wrong so big i2c massages would timeout before they ended.
This commit fix that.

Quoted 13 lines

[1]: https://chris.beams.io/posts/git-commit/

...

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, · line 2100

Quoted 8 lines
drivers/i2c/busses/i2c-npcm7xx.c +5 -2
-       /* Adaptive TimeOut: astimated time in usec + 100% margin */
-       timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite);
+       /*
+        * Adaptive TimeOut: estimated time in usec + 100% margin:
+        * 2: double the timeout for clock stretching case
+        * 9: bits per transaction (including the ack/nack)
 
+        * 1000000: micro second in a second
Quoted 7 lines

No need. See below.

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, · line 2102

Quoted 3 lines
drivers/i2c/busses/i2c-npcm7xx.c +2 -0
+        */
 
+       timeout_usec = (2 * 9 * 1000000 / bus->bus_freq) * (2 + nread + nwrite);

USEC_PER_SEC

OK

Quoted 8 lines
Quoted 4 lines
        timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec));
        if (nwrite >= 32 * 1024 || nread >= 32 * 1024) {
                dev_err(bus->dev, "i2c%d buffer too big\n", bus->num);

--
With Best Regards,
Andy Shevchenko

--
Regards,
Avi

Signature · 2 lines
Regards,
Avi