Re: [PATCH v1 0/2] i2c: add support for forced SDA recovery
From: Linus Walleij
Date: Thu Jan 15 2026 - 04:27:32 EST
Hi Jie,
thanks for your patch!
On Wed, Jan 14, 2026 at 3:13 PM Jie Li <lj29312931@xxxxxxxxx> wrote:
> This series addresses a limitation in the I2C bus recovery mechanism when
> dealing with certain open-drain GPIO configurations where the direction
> cannot be automatically detected.
I'm sorry but I don't understand the premise. How can we even get here?
So the mechanism is about I2C that is using a regular I2C block, and
the pins get re-muxed to GPIO to drive recovery using the I2C
core GPIO-mode recovery mechanism with bridge->sda_gpiod
which is retrieved in the core from "sda" which in DT is
sda-gpios = <....>; (calong with similarly named SCL) for
GPIO-mode recovery.
So if that is set in an input mode, such as during devm_gpiod_get()
reading the initial direction of the line,
so gpiod_get_direction(bri->sda_gpiod) == 1.
this patch set will go and write output values to the line
*anyway* because "it works".
This is how I understand the patch set.
In which scenario do you have a device tree where you can add
"force-set-sda" to a DT node, but you *can't* just fix up the
SCL/SDA flags like this:
#include <dt-bindings/gpio/gpio.h>
sda-gpios = <&gpio0 5 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
scl-gpios = <&gpio0 6 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
?
We should possibly also enforce it from the I2C recovery core,
for SDA we are currently doing:
gpiod = devm_gpiod_get(dev, "sda", GPIOD_IN);
what happens if you patch i2c-core-base.c to simply do:
gpiod = devm_gpiod_get(dev, "sda", GPIOD_OUT_HIGH_OPEN_DRAIN);
(Based on SDA resting polarity being high.)
I'm more uncertain about that one because I don't know exactly
how hardware behaves in response to this, but can you test this
first if you have to hack around in the core?
Yours,
Linus Walleij