From: Jie Li <lj29312931@gmail.com>
To: wsa@kernel.org
Cc: linux-i2c@vger.kernel.org, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, devicetree@vger.kernel.org,
linus.walleij@linaro.org, linux-kernel@vger.kernel.org,
Jie Li <jie.i.li@nokia.com>
Subject: [PATCH v1 1/2] i2c: core: add "force-set-sda" flag for open-drain SDA without "FLAG_IS_OUT" bit
Date: Wed, 14 Jan 2026 15:13:51 +0100 [thread overview]
Message-ID: <20260114141352.103425-2-jie.i.li@nokia.com> (raw)
In-Reply-To: <20260114141352.103425-1-jie.i.li@nokia.com>
On certain specialized SoC platforms, the I2C SDA pin is physically
open-drain but lacks the "FLAG_IS_OUT" bit in the GPIO subsystem.
In such cases, the set_sda function isn't assigned, causing bus
recovery to fail.
This patch introduces a new optional pinctrl flag "force-set-sda".
When this flag is present in the device tree, the I2C recovery
mechanism will explicitly attempt to toggle the SDA line through
the pinctrl state, ensuring the bus can be freed even when the
default recovery logic is insufficient for this specific hardware
implementation.
This change is necessary to improve the robustness of I2C
communication on hardware where the SDA line can remain stuck
low and standard recovery fails.
Signed-off-by: Jie Li <jie.i.li@nokia.com>
---
drivers/i2c/i2c-core-base.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index ae7e9c8b65a6..ffbab3e4528d 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -42,6 +42,9 @@
#include <linux/rwsem.h>
#include <linux/slab.h>
#include <linux/string_choices.h>
+#include <linux/device.h>
+#include <linux/gpio/driver.h>
+#include <linux/fwnode.h>
#include "i2c-core.h"
@@ -422,9 +425,25 @@ static int i2c_gpio_init_recovery(struct i2c_adapter *adap)
return i2c_gpio_init_generic_recovery(adap);
}
+/* Check if SDA can be driven for recovery when
+ * GPIO direction reporting is unavailable.
+ * Usage: add new flag "force-set-sda" in dts pinctrl.
+ */
+static bool force_set_sda(struct device *dev)
+{
+ if (!dev || !dev->of_node)
+ return false;
+
+ if (of_property_read_bool(dev->of_node, "force-set-sda"))
+ return true;
+ else
+ return false;
+}
+
static int i2c_init_recovery(struct i2c_adapter *adap)
{
struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
+ struct device *dev = &adap->dev;
bool is_error_level = true;
char *err_str;
@@ -446,7 +465,7 @@ static int i2c_init_recovery(struct i2c_adapter *adap)
if (bri->sda_gpiod) {
bri->get_sda = get_sda_gpio_value;
/* FIXME: add proper flag instead of '0' once available */
- if (gpiod_get_direction(bri->sda_gpiod) == 0)
+ if (gpiod_get_direction(bri->sda_gpiod) == 0 || force_set_sda(dev))
bri->set_sda = set_sda_gpio_value;
}
} else if (bri->recover_bus == i2c_generic_scl_recovery) {
--
2.43.0
next prev parent reply other threads:[~2026-01-14 14:14 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-14 14:13 [PATCH v1 0/2] i2c: add support for forced SDA recovery Jie Li
2026-01-14 14:13 ` Jie Li [this message]
2026-01-14 14:13 ` [PATCH v1 2/2] dt-bindings: i2c: add force-set-sda property Jie Li
2026-01-16 14:14 ` Krzysztof Kozlowski
2026-01-15 9:27 ` [PATCH v1 0/2] i2c: add support for forced SDA recovery Linus Walleij
2026-01-15 13:12 ` 李杰
2026-01-16 13:59 ` Linus Walleij
2026-01-25 19:51 ` [PATCH v2 0/2] i2c: improve bus recovery for single-ended GPIOs Jie Li
2026-01-25 19:51 ` [PATCH v2 1/2] gpiolib: add gpiod_is_single_ended() helper Jie Li
2026-01-27 9:46 ` Linus Walleij
2026-01-25 19:51 ` [PATCH v2 2/2] i2c: core: support recovery for single-ended GPIOs Jie Li
2026-01-27 9:47 ` Linus Walleij
2026-02-01 11:18 ` [PATCH v3 0/2] i2c: improve bus " Jie Li
2026-02-01 11:18 ` [PATCH v3 1/2] gpiolib: add gpiod_is_single_ended() helper Jie Li
2026-02-01 11:18 ` [PATCH v3 2/2] i2c: core: support recovery for single-ended GPIOs Jie Li
2026-05-04 12:14 ` Wolfram Sang
2026-05-09 9:12 ` [PATCH v4 0/2] i2c: improve bus " Jie Li
2026-05-09 9:12 ` [PATCH v4 1/2] gpiolib: add gpiod_is_single_ended() helper Jie Li
2026-05-09 9:12 ` [PATCH v4 2/2] i2c: core: support recovery for single-ended GPIOs Jie Li
2026-05-09 10:10 ` Wolfram Sang
2026-05-11 7:25 ` 李杰
2026-04-22 18:47 ` [PATCH v3 0/2] i2c: improve bus " 李杰
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=20260114141352.103425-2-jie.i.li@nokia.com \
--to=lj29312931@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jie.i.li@nokia.com \
--cc=krzk+dt@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=wsa@kernel.org \
/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