linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time
@ 2012-02-20  8:14 Alexander Stein
  2012-02-24 12:17 ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander Stein @ 2012-02-20  8:14 UTC (permalink / raw)
  To: Jean Delvare, Ben Dooks, Wolfram Sang
  Cc: Tomoya MORINAGA, Feng Tang, Toshiharu Okada, linux-i2c,
	linux-kernel, Alexander Stein

If you insert several i2c transfers, the driver might start the next one
while the STOP bit of the previous transfer is still on the bus, marking
the bus as busy.
pch_i2c_wait_for_bus_idle does an msleep(20) delaying the next transfer
by >=20ms. Reduce wait time by actively waiting 5 us once, then using
usleep_range.

Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
---
Changes in v2:
* Remove redundant code

 drivers/i2c/busses/i2c-eg20t.c |   42 ++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index ca88776..1eb60ca 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -271,30 +271,36 @@ static inline bool ktime_lt(const ktime_t cmp1, const ktime_t cmp2)
 /**
  * pch_i2c_wait_for_bus_idle() - check the status of bus.
  * @adap:	Pointer to struct i2c_algo_pch_data.
- * @timeout:	waiting time counter (us).
+ * @timeout:	waiting time counter (ms).
  */
 static s32 pch_i2c_wait_for_bus_idle(struct i2c_algo_pch_data *adap,
 				     s32 timeout)
 {
 	void __iomem *p = adap->pch_base_address;
-	ktime_t ns_val;
+	int schedule = 0;
+	unsigned long end = jiffies + msecs_to_jiffies(timeout);
+
+	while (ioread32(p + PCH_I2CSR) & I2CMBB_BIT) {
+		if (time_after(jiffies, end)) {
+			pch_dbg(adap, "I2CSR = %x\n", ioread32(p + PCH_I2CSR));
+			pch_err(adap, "%s: Timeout Error.return%d\n",
+					__func__, -ETIME);
+			pch_i2c_init(adap);
 
-	if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
-		return 0;
+			return -ETIME;
+		}
 
-	/* MAX timeout value is timeout*1000*1000nsec */
-	ns_val = ktime_add_ns(ktime_get(), timeout*1000*1000);
-	do {
-		msleep(20);
-		if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
-			return 0;
-	} while (ktime_lt(ktime_get(), ns_val));
+		if (!schedule)
+			/* Retry after some usecs */
+			udelay(5);
+		else
+			/* Wait a bit more without consuming CPU */
+			usleep_range(20, 1000);
 
-	pch_dbg(adap, "I2CSR = %x\n", ioread32(p + PCH_I2CSR));
-	pch_err(adap, "%s: Timeout Error.return%d\n", __func__, -ETIME);
-	pch_i2c_init(adap);
+		schedule = 1;
+	}
 
-	return -ETIME;
+	return 0;
 }
 
 /**
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time
  2012-02-20  8:14 [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time Alexander Stein
@ 2012-02-24 12:17 ` Wolfram Sang
  2012-02-27 23:53   ` Tomoya MORINAGA
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2012-02-24 12:17 UTC (permalink / raw)
  To: Alexander Stein
  Cc: Jean Delvare, Ben Dooks, Feng Tang, linux-i2c, linux-kernel

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

On Mon, Feb 20, 2012 at 09:14:16AM +0100, Alexander Stein wrote:
> If you insert several i2c transfers, the driver might start the next one
> while the STOP bit of the previous transfer is still on the bus, marking
> the bus as busy.
> pch_i2c_wait_for_bus_idle does an msleep(20) delaying the next transfer
> by >=20ms. Reduce wait time by actively waiting 5 us once, then using
> usleep_range.
> 
> Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>

Tomoya, are you happy with it? (I hope he reads the list, since his
companies mailserver doesn't seem to accept my mails).

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time
  2012-02-24 12:17 ` Wolfram Sang
@ 2012-02-27 23:53   ` Tomoya MORINAGA
  2012-03-01 10:15     ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Tomoya MORINAGA @ 2012-02-27 23:53 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Alexander Stein, Jean Delvare, Ben Dooks, Feng Tang, linux-i2c,
	linux-kernel

Hi

Our team moved to ROHM Co., Ltd.
So, previous email address already disappeared.
Current my mail address is "tomoya.rohm@gmail.com".

thanks.
ROHM Co., Ltd.
tomoya

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time
  2012-02-27 23:53   ` Tomoya MORINAGA
@ 2012-03-01 10:15     ` Wolfram Sang
  2012-03-02  0:51       ` Tomoya MORINAGA
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2012-03-01 10:15 UTC (permalink / raw)
  To: Tomoya MORINAGA
  Cc: Alexander Stein, Jean Delvare, Ben Dooks, Feng Tang, linux-i2c,
	linux-kernel

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


> Our team moved to ROHM Co., Ltd.
> So, previous email address already disappeared.
> Current my mail address is "tomoya.rohm@gmail.com".

Ah, thanks for the update! Are you fine with the patch in question now?

Thanks,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time
  2012-03-01 10:15     ` Wolfram Sang
@ 2012-03-02  0:51       ` Tomoya MORINAGA
  2012-03-06  7:36         ` Alexander Stein
  0 siblings, 1 reply; 7+ messages in thread
From: Tomoya MORINAGA @ 2012-03-02  0:51 UTC (permalink / raw)
  To: Wolfram Sang, Alexander Stein
  Cc: Jean Delvare, Ben Dooks, Feng Tang, linux-i2c, linux-kernel

2012年3月1日19:15 Wolfram Sang <w.sang@pengutronix.de>:
> Ah, thanks for the update! Are you fine with the patch in question now?

Alexander's patch looks good.
Did Alexander test i2c-eg20t driver with this patch ?

thanks,
-- 
ROHM Co., Ltd.
tomoya

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time
  2012-03-02  0:51       ` Tomoya MORINAGA
@ 2012-03-06  7:36         ` Alexander Stein
  2012-03-07 18:16           ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Alexander Stein @ 2012-03-06  7:36 UTC (permalink / raw)
  To: Tomoya MORINAGA
  Cc: Wolfram Sang, Jean Delvare, Ben Dooks, Feng Tang, linux-i2c,
	linux-kernel

Am Freitag, 2. März 2012, 09:51:29 schrieb Tomoya MORINAGA:
> 2012年3月1日19:15 Wolfram Sang <w.sang@pengutronix.de>:
> > Ah, thanks for the update! Are you fine with the patch in question now?
> 
> Alexander's patch looks good.
> Did Alexander test i2c-eg20t driver with this patch ?

Yes, I did test it.

Best regards,
Alexander


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time
  2012-03-06  7:36         ` Alexander Stein
@ 2012-03-07 18:16           ` Wolfram Sang
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2012-03-07 18:16 UTC (permalink / raw)
  To: Alexander Stein
  Cc: Tomoya MORINAGA, Jean Delvare, Ben Dooks, Feng Tang, linux-i2c,
	linux-kernel

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

> > Alexander's patch looks good.
> > Did Alexander test i2c-eg20t driver with this patch ?
> 
> Yes, I did test it.

Applied to for-3.4, thanks!

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-03-07 18:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-20  8:14 [PATCH v2] i2c-eg20t: Rework pch_i2c_wait_for_bus_idle to reduce wait time Alexander Stein
2012-02-24 12:17 ` Wolfram Sang
2012-02-27 23:53   ` Tomoya MORINAGA
2012-03-01 10:15     ` Wolfram Sang
2012-03-02  0:51       ` Tomoya MORINAGA
2012-03-06  7:36         ` Alexander Stein
2012-03-07 18:16           ` Wolfram Sang

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