RE: [PATCH v5 2/2] i2c: core: support recovery for single-ended GPIOs

"Jie I. Li (Nokia)" <[email protected]> Thu, 30 Jul 2026 07:11:43 +0000
Newsgroups org.kernel.vger.linux-i2c,org.kernel.vger.linux-gpio,org.kernel.vger.linux-kernel
Message-ID <AMDPR07MB11191AB1C5459FFB55CA4B612DDC92@AMDPR07MB11191.eurprd07.prod.outlook.com>
Hi Andi,

Thank you very much for resolving the conflict and merging the patch!=20

This is my first time contributing code to the Linux community, and seeing =
it finally merged means a lot to me. I truly appreciate your patience, help=
, and time in guiding me through this.

I will also keep the --in-reply-to note in mind for future submissions.

Best regards,
Jie Li


-----Original Message-----
From: Andi Shyti <[email protected]>=20
Sent: Wednesday, July 29, 2026 11:47 PM
To: Jie Li <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>; Linus Walleij <[email protected]=
>; Wolfram Sang <[email protected]>; Wolfram Sang <wsa+renesas@sang-engineerin=
g.com>; [email protected]; [email protected]; linux-kernel=
@vger.kernel.org; Jie I. Li (Nokia) <[email protected]>
Subject: Re: [PATCH v5 2/2] i2c: core: support recovery for single-ended GP=
IOs

[You don't often get email from [email protected]. Learn why this is im=
portant at https://aka.ms/LearnAboutSenderIdentification ]

CAUTION: This is an external email. Please be very careful when clicking li=
nks or opening attachments. See the URL nok.it/ext for additional informati=
on.



Hi Jie,

On Mon, May 11, 2026 at 01:37:26PM +0200, Jie Li wrote:
> Currently, i2c_init_recovery() only assigns the set_sda/set_scl hooks=20
> if gpiod_get_direction() returns GPIO_LINE_DIRECTION_OUT.
>
> This logic fails on certain SoC controllers where open-drain lines in=20
> a high-impedance state are physically reported as inputs. This leads=20
> to a "deadlock" where the I2C core refuses to assign the recovery=20
> hooks because it incorrectly assumes the pins are input-only, even=20
> though they are fully capable of driving the bus low for recovery.
>
> Update the recovery initialization to use the new
> gpiod_is_single_ended() helper. If a GPIO is configured as open-drain=20
> or open-source in the firmware, it is safe to assume it can be used=20
> for bus recovery, even if the current hardware direction is reported=20
> as input.
>
> Signed-off-by: Jie Li <[email protected]>
> Reviewed-by: Linus Walleij <[email protected]>
> Acked-by: Wolfram Sang <[email protected]>

Please do not send subsequent versions as --in-reply-to, it's difficult to =
track them.

> ---
>  drivers/i2c/i2c-core-base.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c=20
> index 9c46147e3506..a3c33e804d47 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -445,8 +445,8 @@ static int i2c_init_recovery(struct i2c_adapter *adap=
)
>               bri->set_scl =3D set_scl_gpio_value;
>               if (bri->sda_gpiod) {
>                       bri->get_sda =3D get_sda_gpio_value;
> -                     /* FIXME: add proper flag instead of '0' once avail=
able */
> -                     if (gpiod_get_direction(bri->sda_gpiod) =3D=3D 0)
> +                     if (gpiod_get_direction(bri->sda_gpiod) =3D=3D GPIO=
_LINE_DIRECTION_OUT ||
> +                         gpiod_is_single_ended(bri->sda_gpiod))

there was a little conflict here which I fixes and merged to i2c/i2c.

Thanks,
Andi