Skip to contentSkip to conversation

i2c: npcm: Add clock toggle in case of stuck bus during init

PATCH New [email protected] 3 participants 17 messages Mar 24, 2025 – May 27, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover i2c: npcm: Add clock toggle in case of stuck bus during init

From: Tali Perry <[email protected]>

Hi,

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to toggle them first.

Fixes 76487532f797 (i2c: npcm: Add slave enable/disable function)

---

Tali Perry (1):
i2c: npcm: Add clock toggle in case of stuck bus during init in
npcm_i2c_init_module

 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 i2c: npcm: Add clock toggle in case of stuck bus during init in npcm_i2c_init_module

From: Tali Perry <[email protected]>

---
 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +8 -4
index 3ad6124be80f..78c85015d955 100644
@@ -2043,10 +2043,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
 	/* Check HW is OK: SDA and SCL should be high at this point. */
 	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempt recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+			dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
+			dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));
+			return -ENXIO;
+		}
 	}
 
 	npcm_i2c_int_enable(bus, true);
Signature · 4 lines
2.34.1

**Reported-by: Mohammed Elbadry <[email protected]>**
**Tested-by: Mohammed Elbadry <[email protected]>**
#2 lore raw

v2 cover i2c: npcm: Add clock toggle recovery

From: Tali Perry <[email protected]>

Hi,

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to toggle them first.

Fixes 76487532f797 (i2c: npcm: Add slave enable/disable function)

---

Tali Perry (1):
i2c: npcm: Add clock toggle recovery

 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 1/1 i2c: npcm: Add clock toggle recovery

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---
 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +8 -4
index 3ad6124be80f..78c85015d955 100644
@@ -2043,10 +2043,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
 	/* Check HW is OK: SDA and SCL should be high at this point. */
 	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempt recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+			dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
+			dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));
+			return -ENXIO;
+		}
 	}
 
 	npcm_i2c_int_enable(bus, true);
Signature · 4 lines
2.34.1

**Reported-by: Mohammed Elbadry <[email protected]>**
**Tested-by: Mohammed Elbadry <[email protected]>**
#4 lore raw

Re: [PATCH v2 1/1] i2c: npcm: Add clock toggle recovery

Quoted 20 lines · On 3/25/2025 2:28 AM, [email protected] wrote:

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---
  drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +0 -0
index 3ad6124be80f..78c85015d955 100644
@@ -2043,10 +2043,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
  	/* Check HW is OK: SDA and SCL should be high at this point. */
  	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, · line 2051

Quoted 10 lines
drivers/i2c/busses/i2c-npcm7xx.c +6 -4
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempt recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+			dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
+			dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));

Should combine logging into one line. First line you say they are low, second line you are printing the actual status, may be conflicting ?

Quoted 5 lines
drivers/i2c/busses/i2c-npcm7xx.c +2 -0
+			return -ENXIO;
+		}
  	}
 
  	npcm_i2c_int_enable(bus, true);
#5 lore raw

PATCH v3 1/1 i2c: npcm: Add clock toggle recovery

In reply to [email protected]

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---
 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +8 -4
index 2fe68615942e..f05cae20cb27 100644
@@ -1967,10 +1967,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
 	/* Check HW is OK: SDA and SCL should be high at this point. */
 	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempt recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+			dev_err(bus->dev, "I2C%d init fail: lines are low, SDA=%d SCL=%d\n",
+				bus->num, npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));
+			return -ENXIO;
+		}
 	}
 
 	npcm_i2c_int_enable(bus, true);
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
#6 lore raw

Re: [PATCH v3] i2c: npcm: Add clock toggle recovery

Quoted 17 lines · On 3/28/2025 1:08 AM, [email protected] wrote:

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---
  drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +0 -0
index 2fe68615942e..f05cae20cb27 100644

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, · line 1972

Quoted 10 lines
drivers/i2c/busses/i2c-npcm7xx.c +3 -4
@@ -1967,10 +1967,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
  	/* Check HW is OK: SDA and SCL should be high at this point. */
  	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempt recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		if (npcm_i2c_recovery_tgclk(&bus->adap)) {

You are here post trying recovery. In the log below you may want to add, "Post recovery" ? instead of "init fail" ? Just a suggestion.

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, · line 1974

Quoted 2 lines
drivers/i2c/busses/i2c-npcm7xx.c +2 -0
+			dev_err(bus->dev, "I2C%d init fail: lines are low, SDA=%d SCL=%d\n",
+				bus->num, npcm_i2c_get_SDA(&bus->adap),

Thanks for making previous change. Now "lines are low" not relevant as you just need to print status 1 or 0.

Quoted 6 lines
drivers/i2c/busses/i2c-npcm7xx.c +3 -0
+				npcm_i2c_get_SCL(&bus->adap));
+			return -ENXIO;
+		}
  	}
 
  	npcm_i2c_int_enable(bus, true);
#7 lore raw

PATCH v4 1/1 i2c: npcm: Add clock toggle recovery

In reply to [email protected]

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---
 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +8 -4
index 2fe68615942e..caf9aa1e6319 100644
@@ -1967,10 +1967,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
 	/* Check HW is OK: SDA and SCL should be high at this point. */
 	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+			dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n",
+				bus->num, npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));
+			return -ENXIO;
+		}
 	}
 
 	npcm_i2c_int_enable(bus, true);
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
Reviewed-by on v4 1/1
#8 lore raw

Re: [PATCH v4] i2c: npcm: Add clock toggle recovery

Looks good to me.

Quoted 8 lines · On 3/29/2025 1:02 AM, [email protected] wrote:

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

Quoted 27 lines
---
  drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +8 -4
index 2fe68615942e..caf9aa1e6319 100644
@@ -1967,10 +1967,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
  	/* Check HW is OK: SDA and SCL should be high at this point. */
  	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+			dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n",
+				bus->num, npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));
+			return -ENXIO;
+		}
  	}
 
  	npcm_i2c_int_enable(bus, true);
#9 lore raw

Re: [PATCH v4] i2c: npcm: Add clock toggle recovery

In reply to [email protected]

Thank you, Mukesh. Updated patch uploaded.

Mo

Quoted 47 lines · On Fri, Mar 28, 2025 at 12:33 PM <[email protected]> wrote:

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---
 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +1 -4
index 2fe68615942e..caf9aa1e6319 100644
@@ -1967,10 +1967,14 @@ static int npcm_i2c_init_module(struct npcm_i2c
 *bus, enum i2c_mode mode,
 
        /* Check HW is OK: SDA and SCL should be high at this point. */
        if ((npcm_i2c_get_SDA(&bus->adap) == 0) ||
 (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-               dev_err(bus->dev, "I2C%d init fail: lines are low\n",
 bus->num);
-               dev_err(bus->dev, "SDA=%d SCL=%d\n",
 npcm_i2c_get_SDA(&bus->adap),
-                       npcm_i2c_get_SCL(&bus->adap));
-               return -ENXIO;
+               dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to

recover\n", bus->num,
+ npcm_i2c_get_SDA(&bus->adap),
npcm_i2c_get_SCL(&bus->adap));

drivers/i2c/busses/i2c-npcm7xx.c +2 -0
+               if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+                       dev_err(bus->dev, "I2C%d init fail: SDA=%d

SCL=%d\n",

drivers/i2c/busses/i2c-npcm7xx.c +4 -1
+                               bus->num, npcm_i2c_get_SDA(&bus->adap),
+                               npcm_i2c_get_SCL(&bus->adap));
+                       return -ENXIO;
+               }
        }
 
        npcm_i2c_int_enable(bus, true);
--

2.49.0.472.ge94155a9ec-goog

maintainer
#10 lore raw

Re: [PATCH v4] i2c: npcm: Add clock toggle recovery

In reply to [email protected]

Hi Mohammed,

Quoted 9 lines · On Fri, Mar 28, 2025 at 07:32:50PM +0000, [email protected] wrote:

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---

we are missing the changelog here. You are at v4 and I need to see the changes between the versions. For now it's OK, please, next time don't forget to add the changelog.

One more thing, no need to send patches as --in-reply-to your previous patch.

Quoted 8 lines
 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +0 -0
index 2fe68615942e..caf9aa1e6319 100644

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, · line 1970

Quoted 8 lines
drivers/i2c/busses/i2c-npcm7xx.c +1 -4
@@ -1967,10 +1967,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
 	/* Check HW is OK: SDA and SCL should be high at this point. */
 	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to recover\n", bus->num,

the space at the beginning of the line should be removed. I will take care of it if you won't be asked to send a new version.

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, · line 1976

Quoted 6 lines
drivers/i2c/busses/i2c-npcm7xx.c +6 -0
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+			dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n",
+				bus->num, npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));
+			return -ENXIO;

why don't we return the error coming from npcm_i2c_recovery_tgclk() instead of forcing it to ENXIO?

Thanks,
Andi

Quoted 7 lines
drivers/i2c/busses/i2c-npcm7xx.c +1 -0
+		}
 	}
 
 	npcm_i2c_int_enable(bus, true);
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
#11 lore raw

Re: [PATCH v4] i2c: npcm: Add clock toggle recovery

Hi Andi,

Quoted 10 lines · Andi Shyti

Hi Mohammed,

Quoted 6 lines · On Fri, Mar 28, 2025 at 07:32:50PM +0000, [email protected] wrote:

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

Quoted 7 lines
Quoted 3 lines

---

we are missing the changelog here. You are at v4 and I need to see the changes between the versions. For now it's OK, please, next time don't forget to add the changelog.

I understand, I will do that, thank you.

Quoted 13 lines

One more thing, no need to send patches as --in-reply-to your previous patch.

Quoted 9 lines
 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +0 -0
index 2fe68615942e..caf9aa1e6319 100644
@@ -1967,10 +1967,14 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
Quoted 11 lines

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, · line 1970

Quoted 7 lines
drivers/i2c/busses/i2c-npcm7xx.c +1 -4
      /* Check HW is OK: SDA and SCL should be high at this point. */
      if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-             dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-             dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-                     npcm_i2c_get_SCL(&bus->adap));
-             return -ENXIO;
+             dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to recover\n", bus->num,

the space at the beginning of the line should be removed. I will take care of it if you won't be asked to send a new version.

Got it, thank you.

Quoted 9 lines

drivers/i2c/busses/i2c-npcm7xx.c static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, · line 1976

Quoted 6 lines
drivers/i2c/busses/i2c-npcm7xx.c +6 -0
+                              npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+             if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+                     dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n",
+                             bus->num, npcm_i2c_get_SDA(&bus->adap),
+                             npcm_i2c_get_SCL(&bus->adap));
+                     return -ENXIO;

why don't we return the error coming from npcm_i2c_recovery_tgclk() instead of forcing it to ENXIO?

The error that comes from the current driver is only -ENOTRECOVERABLE. I do not see why we cannot return that error instead. I understand the difference between both states; however, from the driver's perspective, on initialization, ENXIO and ENOTRECOVERABLE behavior is identical in that state.

ENXIO was what the driver returned by default without trying to recover. Do you recommend changing it? Let me know. I am happy to send the v5 patch with the change and address the above comments, too.

Thank you,
Mo

Quoted 11 lines

Thanks,
Andi

Quoted 7 lines
drivers/i2c/busses/i2c-npcm7xx.c +1 -1
+             }
      }
 
      npcm_i2c_int_enable(bus, true);
--

2.49.0.472.ge94155a9ec-goog

maintainer
#12 lore raw

Re: [PATCH v4] i2c: npcm: Add clock toggle recovery

Hi Mohammed,

...

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/i2c/busses/i2c-npcm7xx.c +6 -0
+                              npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+             if (npcm_i2c_recovery_tgclk(&bus->adap)) {
+                     dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n",
+                             bus->num, npcm_i2c_get_SDA(&bus->adap),
+                             npcm_i2c_get_SCL(&bus->adap));
+                     return -ENXIO;
Quoted 8 lines
Quoted 2 lines

why don't we return the error coming from npcm_i2c_recovery_tgclk() instead of forcing it to ENXIO?

The error that comes from the current driver is only -ENOTRECOVERABLE. I do not see why we cannot return that error instead. I understand the difference between both states; however, from the driver's perspective, on initialization, ENXIO and ENOTRECOVERABLE behavior is identical in that state.

I think it makes more sense to return the error we receive from npcm_i2c_recovery_tgclk(). Then we can discuss whether that error is correct or not, but that's a different topic.

Quoted 3 lines

ENXIO was what the driver returned by default without trying to recover. Do you recommend changing it? Let me know. I am happy to send the v5 patch with the change and address the above comments, too.

Yes, please do.

Andi

#13 lore raw

PATCH v5 1/1 i2c: npcm: Add clock toggle recovery

In reply to [email protected]

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---
 drivers/i2c/busses/i2c-npcm7xx.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +9 -4
index de713b5747fe..0757a23dc1cd 100644
@@ -2178,10 +2178,15 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
 	/* Check HW is OK: SDA and SCL should be high at this point. */
 	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		ret = npcm_i2c_recovery_tgclk(&bus->adap);
+		if (ret) {
+			dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n",
+				bus->num, npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));
+			return ret;
+		}
 	}
 
 	npcm_i2c_int_enable(bus, true);
Signature · 1 line
2.39.5 (Apple Git-154)
#14 lore raw

PATCH v5 1/1 i2c: npcm: Add clock toggle recovery

In reply to [email protected]

From: Tali Perry <[email protected]>

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to recover them first before failing. Sometimes SDA and SCL are low if improper reset occurs (e.g., reboot).

---
 drivers/i2c/busses/i2c-npcm7xx.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-npcm7xx.c +9 -4
index de713b5747fe..4738fc450a6b 100644
@@ -2178,10 +2178,15 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode,
 
 	/* Check HW is OK: SDA and SCL should be high at this point. */
 	if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) {
-		dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num);
-		dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap),
-			npcm_i2c_get_SCL(&bus->adap));
-		return -ENXIO;
+		dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to recover\n", bus->num,
+				 npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap));
+		ret = npcm_i2c_recovery_tgclk(&bus->adap);
+		if (ret) {
+			dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n",
+				bus->num, npcm_i2c_get_SDA(&bus->adap),
+				npcm_i2c_get_SCL(&bus->adap));
+			return ret;
+		}
 	}
 
 	npcm_i2c_int_enable(bus, true);
Signature · 1 line
2.39.5 (Apple Git-154)
#15 lore raw

Re: [PATCH v2 0/1] i2c: npcm: Add clock toggle recovery

In reply to [email protected]
Quoted 7 lines · On 3/25/2025 2:28 AM, [email protected] wrote:

From: Tali Perry <[email protected]>

Hi,

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to toggle them first.

As such there is one file change and single patch. You may go ahead without cover-letter. Just my thought.

Quoted 11 lines
Fixes 76487532f797 (i2c: npcm: Add slave enable/disable function)

---

Tali Perry (1):
i2c: npcm: Add clock toggle recovery

  drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
#16 lore raw

Re: [PATCH v2 0/1] i2c: npcm: Add clock toggle recovery

Understood, will update the patch per comment: combining log messages and removing cover letter, thank you.

Mo

Quoted 24 lines · Mukesh Kumar Savaliya
Quoted 7 lines · On 3/25/2025 2:28 AM, [email protected] wrote:

From: Tali Perry <[email protected]>

Hi,

During init of the bus, the module checks that the bus is idle. If one of the lines are stuck try to toggle them first.

As such there is one file change and single patch. You may go ahead without cover-letter. Just my thought.

Quoted 11 lines
Fixes 76487532f797 (i2c: npcm: Add slave enable/disable function)

---

Tali Perry (1):
i2c: npcm: Add clock toggle recovery

  drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)