linux-gbmc(npcm): i2c: Add clock toggle recovery

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

Upstream-process:
https://patchwork.ozlabs.org/project/linux-i2c/patch/20250327193816.670658-1-mohammed.0.elbadry@gmail.com/
Tested: Repeated hardware lockup and can see bus recovering.
Google-Bug-Id: 392117920
Change-Id: I9fc2671c89c88bf849177f0855888694b984f3ea
Signed-off-by: Mo Elbadry <elbadrym@google.com>
diff --git a/recipes-kernel/linux/files/0001-i2c-npcm-Add-clock-toggle-recovery.patch b/recipes-kernel/linux/files/0001-i2c-npcm-Add-clock-toggle-recovery.patch
new file mode 100644
index 0000000..c1afdf2
--- /dev/null
+++ b/recipes-kernel/linux/files/0001-i2c-npcm-Add-clock-toggle-recovery.patch
@@ -0,0 +1,41 @@
+From 20569a4897a7f13a79ab4af8f874a97cbf1aafb1 Mon Sep 17 00:00:00 2001
+From: Tali Perry <tali.perry1@gmail.com>
+Date: Wed, 5 Mar 2025 11:10:42 +0200
+Subject: [PATCH v3] i2c: npcm: Add clock toggle recovery
+
+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
+
diff --git a/recipes-kernel/linux/linux-gbmc_5.15.bb b/recipes-kernel/linux/linux-gbmc_5.15.bb
index 2c3f597..44d5c5a 100644
--- a/recipes-kernel/linux/linux-gbmc_5.15.bb
+++ b/recipes-kernel/linux/linux-gbmc_5.15.bb
@@ -24,6 +24,7 @@
   file://0001-drivers-iio-adc-sync-npcm-adc.patch \
   file://0001-iio-adc-npcm-add-reset-method-to-fix-get-value-faile.patch \
   file://0001-hwmon-pmbus-Initialise-page-count-in-pmbus_identify.patch \
+  file://0001-i2c-npcm-Add-clock-toggle-recovery.patch \
   "
 
 SRC_URI:append:aspeed-g6 = " \
diff --git a/recipes-kernel/linux/linux-gbmc_lts.bb b/recipes-kernel/linux/linux-gbmc_lts.bb
index 371a84b..09bf0f8 100644
--- a/recipes-kernel/linux/linux-gbmc_lts.bb
+++ b/recipes-kernel/linux/linux-gbmc_lts.bb
@@ -21,6 +21,7 @@
   file://0004-i2c-npcm-Assign-client-address-earlier-for-i2c_recov.patch \
   file://0005-i2c-npcm-use-i2c-frequency-table.patch \
   file://0006-i2c-npcm-Enable-slave-in-eob-interrupt.patch \
+  file://0001-i2c-npcm-Add-clock-toggle-recovery.patch \
   file://DOWNSTREAM_0001-i2c-npcm-speed-set.patch \
   "
 
diff --git a/recipes-kernel/linux/linux-gbmc_mainline.bb b/recipes-kernel/linux/linux-gbmc_mainline.bb
index f13abf4..fd5b085 100644
--- a/recipes-kernel/linux/linux-gbmc_mainline.bb
+++ b/recipes-kernel/linux/linux-gbmc_mainline.bb
@@ -14,6 +14,7 @@
   file://0001-ARM-npcm-Add-CPU-hotplug-callbacks-for-kexec-support.patch \
   file://0001-hwmon-max34451-Workaround-for-lost-page.patch \
   file://0001-ARM-dts-nuvoton-Add-UDC-nodes.patch \
+  file://0001-i2c-npcm-Add-clock-toggle-recovery.patch \
   file://DOWNSTREAM_0001-i2c-npcm-speed-set.patch \
   "
 
diff --git a/recipes-kernel/linux/linux-gbmc_stable.bb b/recipes-kernel/linux/linux-gbmc_stable.bb
index e78c6b1..1ec58d7 100644
--- a/recipes-kernel/linux/linux-gbmc_stable.bb
+++ b/recipes-kernel/linux/linux-gbmc_stable.bb
@@ -19,6 +19,7 @@
   file://0004-i2c-npcm-Assign-client-address-earlier-for-i2c_recov.patch \
   file://0005-i2c-npcm-use-i2c-frequency-table.patch \
   file://0006-i2c-npcm-Enable-slave-in-eob-interrupt.patch \
+  file://0001-i2c-npcm-Add-clock-toggle-recovery.patch \
   file://DOWNSTREAM_0001-i2c-npcm-speed-set.patch \
   "