[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <a8252fd8-a1cb-40da-bd74-e2f424136a41@lunn.ch>
Date: Tue, 7 Oct 2025 16:50:37 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Matthias Schiffer <matthias.schiffer@...tq-group.com>
Cc: Peter Korsgaard <peter@...sgaard.com>,
Andi Shyti <andi.shyti@...nel.org>, linux-i2c@...r.kernel.org,
linux-kernel@...r.kernel.org, linux@...tq-group.com
Subject: Re: [PATCH 1/2] i2c: ocores: replace 1ms poll iteration timeout with
total transfer timeout
On Tue, Oct 07, 2025 at 04:41:00PM +0200, Matthias Schiffer wrote:
> On Tue, 2025-10-07 at 16:20 +0200, Andrew Lunn wrote:
> > On Tue, Oct 07, 2025 at 04:06:36PM +0200, Matthias Schiffer wrote:
> > > On Tue, 2025-10-07 at 14:34 +0200, Andrew Lunn wrote:
> > > > On Tue, Oct 07, 2025 at 02:09:24PM +0200, Matthias Schiffer wrote:
> > > > > When a target makes use of clock stretching, a timeout of 1ms may not be
> > > > > enough. One extreme example is the NXP PTN3460 eDP to LVDS bridge, which
> > > > > takes ~320ms to send its ACK after a flash command has been
> > > > > submitted.
> > > > >
> > > > > Replace the per-iteration timeout of 1ms with limiting the total
> > > > > transfer time to the timeout set in struct i2c_adapter (defaulting to
> > > > > 1s, configurable through the I2C_TIMEOUT ioctl). While we're at it, also
> > > > > add a cpu_relax() to the busy poll loop.
> > > >
> > > > 1s is a long time to spin. Maybe it would be better to keep with the
> > > > current spin for 1ms, and then use one of the helpers from iopoll.h to
> > > > do a sleeping wait? Say with 10ms sleeps, up to the 1s maximum?
> > > >
> > > > Andrew
> > >
> > > Makes sense. I don't think I can use something from iopoll.h directly, as i2c-
> > > ocores has its own ioreadX abstraction to deal with different register widths
> > > and endianesses, but a combination of spin + sleep is probably the way to go.
> >
> > I think iopoll.h should work.
> >
> >
> > u8 status = oc_getreg(i2c, reg);
> >
> > if ((status & mask) == val)
> > break;
> >
> > This maps to
> >
> > u8 status;
> >
> > ret = read_poll_timeout(oc_getreg, status, (status & mask) == val,
> > 10000, 1000000, false, i2c, reg);
> >
> > Andrew
>
> Ah, you are right, that should work.
>
> If we want to keep the spin case for short waits, not duplicating the read and
> mask check seems preferable to me though - maybe something like the following
> (which could also be extended to exponentially increasing sleeps or similar if
> we want to start with something smaller than 10ms):
I think something like this will work:
u8 status;
ret = read_poll_timeout_atomic(oc_getreg, status, (status & mask) == val,
100, 1000, false, i2c, reg);
if (ret != ETIMEDOUT)
return ret;
return read_poll_timeout(oc_getreg, status, (status & mask) == val,
10000, 1000000, false, i2c, reg);
which probably ends up being the same length, but simpler than the
current ocores_wait().
Andrew
Powered by blists - more mailing lists