public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: mohammed.0.elbadry@gmail.com
To: avifishman70@gmail.com, linux-i2c@vger.kernel.org,
	linux-kernel@vger.kernel.org, andi.shyti@kernel.org,
	venture@google.com
Cc: Tali Perry <tali.perry1@gmail.com>,
	Mohammed Elbadry <mohammed.0.elbadry@gmail.com>
Subject: [PATCH v3] i2c: npcm: Add clock toggle recovery
Date: Thu, 27 Mar 2025 19:38:16 +0000	[thread overview]
Message-ID: <20250327193816.670658-1-mohammed.0.elbadry@gmail.com> (raw)
In-Reply-To: <20250324205901.1274708-2-mohammed.0.elbadry@gmail.com>

From: Tali Perry <tali.perry1@gmail.com>

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).

Signed-off-by: Tali Perry <tali.perry1@gmail.com>
Signed-off-by: Mohammed Elbadry <mohammed.0.elbadry@gmail.com>
---
 drivers/i2c/busses/i2c-npcm7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
index 2fe68615942e..f05cae20cb27 100644
--- a/drivers/i2c/busses/i2c-npcm7xx.c
+++ b/drivers/i2c/busses/i2c-npcm7xx.c
@@ -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);
-- 
2.49.0.472.ge94155a9ec-goog


  parent reply	other threads:[~2025-03-27 19:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24 20:32 [PATCH v1 0/1] i2c: npcm: Add clock toggle in case of stuck bus during init mohammed.0.elbadry
2025-03-24 20:32 ` [PATCH v1 1/1] i2c: npcm: Add clock toggle in case of stuck bus during init in npcm_i2c_init_module mohammed.0.elbadry
2025-03-24 20:58   ` [PATCH v2 0/1] i2c: npcm: Add clock toggle recovery mohammed.0.elbadry
2025-03-24 20:58     ` [PATCH v2 1/1] " mohammed.0.elbadry
2025-03-26  4:43       ` Mukesh Kumar Savaliya
2025-03-27 19:38       ` mohammed.0.elbadry [this message]
2025-03-28 11:19         ` [PATCH v3] " Mukesh Kumar Savaliya
2025-03-28 19:32         ` [PATCH v4] " mohammed.0.elbadry
2025-03-29  9:15           ` Mukesh Kumar Savaliya
2025-04-13 23:06           ` Andi Shyti
2025-04-14  0:07             ` Mohammed Elbadry
2025-04-17 16:11               ` Andi Shyti
2025-05-27  2:22           ` [PATCH v5] " Mohammed Elbadry
2025-05-27  3:05           ` Mohammed Elbadry
2025-03-26  4:45     ` [PATCH v2 0/1] " Mukesh Kumar Savaliya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250327193816.670658-1-mohammed.0.elbadry@gmail.com \
    --to=mohammed.0.elbadry@gmail.com \
    --cc=andi.shyti@kernel.org \
    --cc=avifishman70@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tali.perry1@gmail.com \
    --cc=venture@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox