public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Nikula <jarkko.nikula@nokia.com>
To: ext Sakari Ailus <sakari.ailus@nokia.com>
Cc: linux-omap@vger.kernel.org
Subject: Re: [RFC] i2c-omap: Don't wait needlessly
Date: Fri, 24 Oct 2008 13:17:40 +0300	[thread overview]
Message-ID: <20081024131740.64641d26.jarkko.nikula@nokia.com> (raw)
In-Reply-To: <12246059481717-git-send-email-sakari.ailus@nokia.com>

[-- Attachment #1: Type: text/plain, Size: 1531 bytes --]

On Tue, 21 Oct 2008 19:19:08 +0300
"ext Sakari Ailus" <sakari.ailus@nokia.com> wrote:

>  /* timeout waiting for the controller to respond */
>  #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
> +/* no more busyloop in ns */
> +#define OMAP_I2C_MINOR_TIMEOUT		10
>  
>  #define OMAP_I2C_REV_REG		0x00
>  #define OMAP_I2C_IE_REG			0x04
> @@ -255,6 +257,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
>  	unsigned long internal_clk = 0;
>  
>  	if (!dev->rev1) {
> +		int delay = 0;
> +
>  		omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST);
>  		/* For some reason we need to set the EN bit before the
>  		 * reset done bit gets set. */
> @@ -262,6 +266,14 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
>  		omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
>  		while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) &
>  			 OMAP_I2C_SYSS_RDONE)) {
> +			if (delay < OMAP_I2C_MINOR_TIMEOUT) {
> +				ndelay(1);
> +				delay++;
> +				continue;
> +			} else if (delay == OMAP_I2C_MINOR_TIMEOUT) {
> +				dev_warn(dev->dev, "minor timeout not enough");
> +				delay++;
> +			}
>  			if (time_after(jiffies, timeout)) {
>  				dev_warn(dev->dev, "timeout waiting "
>  						"for controller reset\n");
>
I would rather, if there is no need for such a long delay like
OMAP_I2C_TIMEOUT, remove that time_after and msleep(1) stuff and
just loop few iterations with udelay(1). Zero thinked & tested diff
attached.

I would say that ndelay(1) just doesn't look relevant to < 1 GHz
cpus :-)


Jarkko

[-- Attachment #2: hack.diff --]
[-- Type: text/x-diff, Size: 766 bytes --]

--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -248,16 +248,16 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
 		omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST);
 		/* For some reason we need to set the EN bit before the
 		 * reset done bit gets set. */
-		timeout = jiffies + OMAP_I2C_TIMEOUT;
+		timeout = 10;
 		omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
 		while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) &
 			 OMAP_I2C_SYSS_RDONE)) {
-			if (time_after(jiffies, timeout)) {
+			udelay(1);
+			if (--timeout) {
 				dev_warn(dev->dev, "timeout waiting "
 						"for controller reset\n");
 				return -ETIMEDOUT;
 			}
-			msleep(1);
 		}
 	}
 	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);

  reply	other threads:[~2008-10-24 10:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-21 16:19 [RFC] i2c-omap: Don't wait needlessly Sakari Ailus
2008-10-24 10:17 ` Jarkko Nikula [this message]
2008-10-27 16:20   ` Sakari Ailus
2008-11-21 21:43     ` Tony Lindgren
2008-11-25  9:35       ` Sakari Ailus

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=20081024131740.64641d26.jarkko.nikula@nokia.com \
    --to=jarkko.nikula@nokia.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=sakari.ailus@nokia.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