mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Peter Korsgaard <peter@korsgaard.com>,
	Andi Shyti <andi.shyti@kernel.org>,
	 linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux@ew.tq-group.com
Subject: Re: [PATCH 1/2] i2c: ocores: replace 1ms poll iteration timeout with total transfer timeout
Date: Tue, 07 Oct 2025 16:41:00 +0200	[thread overview]
Message-ID: <0007bc39777fc1e09f953be943fd8ce474b054da.camel@ew.tq-group.com> (raw)
In-Reply-To: <7470fb97-1991-4347-a084-11f24006b67f@lunn.ch>

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

	unsigned long spin_timeout = jiffies + msecs_to_jiffies(1);
	...

		if (time_before(jiffies, spin_timeout))
			cpu_relax();
		else
			msleep(10);

Best,
Matthias


-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/

  reply	other threads:[~2025-10-07 14:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07 12:09 Matthias Schiffer
2025-10-07 12:09 ` [PATCH 2/2] i2c: ocores: respect adapter timeout in IRQ mode Matthias Schiffer
2025-10-07 14:32   ` Peter Korsgaard
2025-10-07 12:34 ` [PATCH 1/2] i2c: ocores: replace 1ms poll iteration timeout with total transfer timeout Andrew Lunn
2025-10-07 14:06   ` Matthias Schiffer
2025-10-07 14:20     ` Andrew Lunn
2025-10-07 14:41       ` Matthias Schiffer [this message]
2025-10-07 14:50         ` Andrew Lunn
2025-10-09 22:25 ` Andi Shyti

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=0007bc39777fc1e09f953be943fd8ce474b054da.camel@ew.tq-group.com \
    --to=matthias.schiffer@ew.tq-group.com \
    --cc=andi.shyti@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@ew.tq-group.com \
    --cc=peter@korsgaard.com \
    /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

all inboxes | Powered by JetHome®