linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Federico Vaga <federico.vaga@cern.ch>
Cc: Peter Korsgaard <peter@korsgaard.com>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/5] i2c:ocores: add polling interface
Date: Sat, 9 Feb 2019 22:33:53 +0100	[thread overview]
Message-ID: <20190209213353.GA9061@lunn.ch> (raw)
In-Reply-To: <20190208161201.7860-4-federico.vaga@cern.ch>

> +static int ocores_poll_wait(struct ocores_i2c *i2c)
> +{
> +	u8 mask;
> +	int err;
> +
> +	if (i2c->state == STATE_DONE || i2c->state == STATE_ERROR) {
> +		/* transfer is over */
> +		mask = OCI2C_STAT_BUSY;
> +	} else {
> +		/* on going transfer */
> +		mask = OCI2C_STAT_TIP;
> +		udelay((8 * 1000) / i2c->bus_clock_khz);
> +	}
> +
> +	/*
> +	 * once we are here we expect to get the expected result immediately
> +	 * so if after 1ms we timeout then something is broken.
> +	 */
> +	err = ocores_wait(i2c, OCI2C_STATUS, mask, 0, msecs_to_jiffies(1));

Hi Federico

I did some timing tests for this. On my box, we request a udelay of
80uS. The kernel actually delays for about 79uS. We then spin in
ocores_wait() for an additional 10-11uS, which is 3 to 4 iterations.

There are actually 9 bits on the wire, not 8, since there is an
ACK/NACK bit after the actual data transfer. So i changed the delay to
(9 * 1000) / i2c->bus_clock_khz. That resulted in ocores_wait() mostly
not looping at all. But for reading an 4K AT24 EEPROM, it increased
the read time by 10ms, from 424ms to 434ms. So we should probably keep
with 8.

Tested-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

  reply	other threads:[~2019-02-09 21:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-08 16:11 [PATCH v3 0/5] Federico Vaga
2019-02-08 16:11 ` [PATCH v3 1/5] i2c:ocores: stop transfer on timeout Federico Vaga
2019-02-08 16:58   ` Andrew Lunn
2019-02-08 16:11 ` [PATCH v3 2/5] i2c:ocores: do not handle IRQ if IF is not set Federico Vaga
2019-02-08 17:00   ` Andrew Lunn
2019-02-08 16:11 ` [PATCH v3 3/5] i2c:ocores: add polling interface Federico Vaga
2019-02-09 21:33   ` Andrew Lunn [this message]
2019-02-11  8:20     ` Federico Vaga
2019-02-08 16:12 ` [PATCH v3 4/5] i2c:ocores: add SPDX tag Federico Vaga
2019-02-08 17:01   ` Andrew Lunn
2019-02-08 17:16   ` Peter Rosin
2019-02-08 16:12 ` [PATCH v3 5/5] i2c:ocores: checkpatch fixes Federico Vaga
2019-02-08 17:03   ` Andrew Lunn
2019-02-09 21:41 ` [PATCH v3 0/5] Andrew Lunn

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=20190209213353.GA9061@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=federico.vaga@cern.ch \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).