From: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Linux OMAP Mailing List
<linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Tony Lindgren <tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>,
Benoit Cousson <b-cousson-l0cyMroinI0@public.gmane.org>,
Linux ARM Kernel Mailing List
<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org,
Shubhrajyoti Datta <shubhrajyoti-l0cyMroinI0@public.gmane.org>,
Santosh Shilimkar
<santosh.shilimkar-l0cyMroinI0@public.gmane.org>,
Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
Subject: [PATCH 6/8] i2c: omap: wait for transfer completion before sending STP bit
Date: Mon, 22 Oct 2012 12:46:56 +0300 [thread overview]
Message-ID: <1350899218-13624-7-git-send-email-balbi@ti.com> (raw)
In-Reply-To: <1350899218-13624-1-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
Later patches will come adding support for
reporting amount of bytes transferred so that
client drivers can count how many bytes are
left to transfer.
This is useful mostly in case of NACKs when
client driver wants to know exactly which
byte got NACKed so it doesn't have to resend
all bytes again.
In order to make that work with OMAP's I2C
controller, we need to prevent sending STP
bit until message is transferred. The reason
behind that is because OMAP_I2C_CNT_REG gets
reset to original value after STP bit is
shifted through I2C_SDA line and that would
prevent us from reading the correct number of
bytes left to transfer.
The full programming model suggested by IP
owner was the following:
- start I2C transfer (without STP bit)
- upon completion or NACK, read I2C_CNT register
- write STP bit to I2C_CON register
- wait for ARDY bit
With this patch we're implementing all steps
except step #2 which will come in a later
patch adding such support.
Signed-off-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
---
drivers/i2c/busses/i2c-omap.c | 101 ++++++++++++++++--------------------------
1 file changed, 39 insertions(+), 62 deletions(-)
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index c65d526..8104aa2 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -438,9 +438,9 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
/* Enable interrupts */
dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
- OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
- OMAP_I2C_IE_AL) | ((dev->fifo_size) ?
- (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0);
+ OMAP_I2C_IE_NACK | OMAP_I2C_IE_AL) |
+ ((dev->fifo_size) ? (OMAP_I2C_IE_RDR |
+ OMAP_I2C_IE_XDR) : 0);
omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate);
if (dev->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) {
dev->pscstate = psc;
@@ -470,6 +476,22 @@ static int omap_i2c_wait_for_bb(struct omap_i2c_dev *dev)
return 0;
}
+static int omap_i2c_wait_for_ardy(struct omap_i2c_dev *dev)
+{
+ unsigned long timeout;
+
+ timeout = jiffies + OMAP_I2C_TIMEOUT;
+ while (!(omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_ARDY)) {
+ if (time_after(jiffies, timeout)) {
+ dev_warn(dev->dev, "timeout waiting for access ready\n");
+ return -ETIMEDOUT;
+ }
+ usleep_range(800, 1200);
+ }
+
+ return 0;
+}
+
static void omap_i2c_resize_fifo(struct omap_i2c_dev *dev, u8 size, bool is_rx)
{
u16 buf;
@@ -515,7 +537,7 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
{
struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
unsigned long timeout;
- int ret;
+ int ret = 0;
u16 w;
dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n",
@@ -556,35 +578,9 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
if (!(msg->flags & I2C_M_RD))
w |= OMAP_I2C_CON_TRX;
- if (!dev->b_hw && stop)
- w |= OMAP_I2C_CON_STP;
-
omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
/*
- * Don't write stt and stp together on some hardware.
- */
- if (dev->b_hw && stop) {
- unsigned long delay = jiffies + OMAP_I2C_TIMEOUT;
- u16 con = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
- while (con & OMAP_I2C_CON_STT) {
- con = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
-
- /* Let the user know if i2c is in a bad state */
- if (time_after(jiffies, delay)) {
- dev_err(dev->dev, "controller timed out "
- "waiting for start condition to finish\n");
- return -ETIMEDOUT;
- }
- cpu_relax();
- }
-
- w |= OMAP_I2C_CON_STP;
- w &= ~OMAP_I2C_CON_STT;
- omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
- }
-
- /*
* REVISIT: We should abort the transfer on signals, but the bus goes
* into arbitration and we're currently unable to recover from it.
*/
@@ -594,36 +590,36 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
if (timeout == 0) {
dev_err(dev->dev, "controller timed out\n");
ret = -ETIMEDOUT;
- goto err_i2c_init;
+ omap_i2c_init(dev);
+ goto out;
}
if ((dev->cmd_err & OMAP_I2C_STAT_AL)
|| (dev->cmd_err & OMAP_I2C_STAT_ROVR)
|| (dev->cmd_err & OMAP_I2C_STAT_XUDF)) {
ret = -EIO;
- goto err_i2c_init;
+ omap_i2c_init(dev);
+ goto out;
}
if (dev->cmd_err & OMAP_I2C_STAT_NACK) {
if (msg->flags & I2C_M_IGNORE_NAK)
return 0;
- if (stop) {
- w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
- w |= OMAP_I2C_CON_STP;
- omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
- }
-
ret = -EREMOTEIO;
- goto err;
+ omap_i2c_init(dev);
}
- return 0;
+out:
-err_i2c_init:
- omap_i2c_init(dev);
+ if (stop) {
+ w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
+ w |= OMAP_I2C_CON_STP;
+ omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
+
+ ret = omap_i2c_wait_for_ardy(dev);
+ }
-err:
return ret;
}
@@ -947,19 +937,6 @@ omap_i2c_isr_thread(int this_irq, void *dev_id)
break;
}
- /*
- * ProDB0017052: Clear ARDY bit twice
- */
- if (stat & (OMAP_I2C_STAT_ARDY | OMAP_I2C_STAT_NACK |
- OMAP_I2C_STAT_AL)) {
- omap_i2c_ack_stat(dev, (OMAP_I2C_STAT_RRDY |
- OMAP_I2C_STAT_RDR |
- OMAP_I2C_STAT_XRDY |
- OMAP_I2C_STAT_XDR |
- OMAP_I2C_STAT_ARDY));
- break;
- }
-
if (stat & OMAP_I2C_STAT_RDR) {
u8 num_bytes = 1;
--
1.8.0.rc0
next prev parent reply other threads:[~2012-10-22 9:46 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-22 9:46 [PATCH 0/8] I2C patches for v3.8 merge window Felipe Balbi
2012-10-22 9:46 ` [PATCH 1/8] i2c: omap: no need to access platform_device Felipe Balbi
2012-10-22 9:46 ` [PATCH 2/8] i2c: omap: reorder exit path of omap_i2c_xfer_msg() Felipe Balbi
2012-10-25 11:40 ` Shubhrajyoti Datta
[not found] ` <CAM=Q2cvUeLbS20HScrGTOcraSUrCzhzCi8MQLxd9MOb_7ZFFYA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-25 12:01 ` Felipe Balbi
[not found] ` <1350899218-13624-1-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-22 9:46 ` [PATCH 3/8] i2c: omap: fix error checking Felipe Balbi
[not found] ` <1350899218-13624-4-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-24 14:41 ` Michael Trimarchi
[not found] ` <5087FE07.6090504-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2012-10-25 10:10 ` Felipe Balbi
[not found] ` <20121025101010.GC21217-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-10-25 10:33 ` Michael Trimarchi
[not found] ` <5089156E.7020701-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org>
2012-10-25 10:48 ` Felipe Balbi
2012-10-22 9:46 ` [PATCH 4/8] i2c: omap: also complete() when stat becomes zero Felipe Balbi
2012-10-22 9:46 ` Felipe Balbi [this message]
2012-10-22 9:46 ` [PATCH 7/8] i2c: add 'transferred' field to struct i2c_msg Felipe Balbi
2012-10-25 12:57 ` Jean Delvare
[not found] ` <20121025145748.760c218b-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-10-25 13:14 ` Russell King - ARM Linux
2012-10-25 13:42 ` Jean Delvare
[not found] ` <20121025154202.41f3cbba-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-10-25 13:46 ` Russell King - ARM Linux
[not found] ` <20121025134609.GH28061-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-10-25 13:56 ` Jean Delvare
[not found] ` <20121025155633.609c5554-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-10-25 14:18 ` Russell King - ARM Linux
[not found] ` <20121025141800.GI28061-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-10-27 14:32 ` Jean Delvare
[not found] ` <20121027163224.67d57aef-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-10-27 16:40 ` Al Viro
2012-10-27 17:02 ` Al Viro
[not found] ` <20121027170235.GA24388-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2012-10-27 17:10 ` Al Viro
2012-10-27 19:03 ` Jean Delvare
2012-10-27 17:25 ` Russell King - ARM Linux
2012-10-22 9:46 ` [PATCH 8/8] i2c: omap: implement handling for 'transferred' bytes Felipe Balbi
2012-10-22 9:46 ` [PATCH 5/8] i2c: omap: introduce and use OMAP_I2C_IP_VERSION_3 Felipe Balbi
[not found] ` <1350899218-13624-6-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-22 12:27 ` Benoit Cousson
2012-10-22 12:28 ` Felipe Balbi
[not found] ` <20121022122853.GW14033-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-10-22 13:05 ` Benoit Cousson
[not found] ` <50854490.4060306-l0cyMroinI0@public.gmane.org>
2012-10-22 13:09 ` Felipe Balbi
2012-10-22 13:18 ` [PATCH v2 5/8] i2c: omap: in case of VERSION_2 read IRQSTATUS_RAW but write to IRQSTATUS Felipe Balbi
2012-10-22 13:30 ` [PATCH 0/8] I2C patches for v3.8 merge window Felipe Balbi
[not found] ` <20121022133023.GC14033-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-10-22 14:06 ` Shubhrajyoti Datta
2012-10-22 14:06 ` Felipe Balbi
2012-10-22 15:02 ` Shubhrajyoti
[not found] ` <CAM=Q2ctS3hxngk5efcvScAdv-2GtH2pHRZoxRhRTiOWmQA-AXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-11-14 16:58 ` Wolfram Sang
2012-10-25 12:25 ` [PATCH v2 0/7] " Felipe Balbi
[not found] ` <1351167915-15079-1-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-25 12:25 ` [PATCH v2 1/7] i2c: omap: no need to access platform_device Felipe Balbi
[not found] ` <1351167915-15079-2-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-25 12:41 ` Santosh Shilimkar
2012-10-25 12:25 ` [PATCH v2 2/7] i2c: omap: reorder exit path of omap_i2c_xfer_msg() Felipe Balbi
[not found] ` <1351167915-15079-3-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-25 12:42 ` Santosh Shilimkar
[not found] ` <50893398.6070004-l0cyMroinI0@public.gmane.org>
2012-10-25 12:40 ` Felipe Balbi
2012-10-25 12:53 ` Lothar Waßmann
2012-10-25 12:25 ` [PATCH v2 3/7] i2c: omap: also complete() when stat becomes zero Felipe Balbi
[not found] ` <1351167915-15079-4-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-25 12:43 ` Santosh Shilimkar
[not found] ` <508933E4.7070608-l0cyMroinI0@public.gmane.org>
2012-10-25 12:39 ` Felipe Balbi
2012-10-25 12:25 ` [PATCH v2 4/7] i2c: omap: in case of VERSION_2 read IRQSTATUS_RAW but write to IRQSTATUS Felipe Balbi
[not found] ` <1351167915-15079-5-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-25 12:53 ` Santosh Shilimkar
[not found] ` <50893665.60604-l0cyMroinI0@public.gmane.org>
2012-10-25 12:52 ` Felipe Balbi
2012-10-25 13:06 ` Santosh Shilimkar
2012-10-25 12:25 ` [PATCH v2 5/7] i2c: omap: wait for transfer completion before sending STP bit Felipe Balbi
2012-10-25 12:32 ` Felipe Balbi
2012-10-25 12:34 ` [PATCH v3 " Felipe Balbi
[not found] ` <1351167915-15079-6-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-25 13:01 ` [PATCH v2 " Santosh Shilimkar
2012-10-25 14:15 ` Felipe Balbi
2012-10-25 12:25 ` [PATCH v2 7/7] i2c: omap: implement handling for 'transferred' bytes Felipe Balbi
[not found] ` <1351167915-15079-8-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2012-10-27 18:55 ` Paul Walmsley
2012-11-05 8:10 ` [PATCH v2 0/7] I2C patches for v3.8 merge window Felipe Balbi
2012-10-25 12:25 ` [PATCH v2 6/7] i2c: add 'transferred' field to struct i2c_msg Felipe Balbi
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=1350899218-13624-7-git-send-email-balbi@ti.com \
--to=balbi-l0cymroini0@public.gmane.org \
--cc=b-cousson-l0cyMroinI0@public.gmane.org \
--cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=santosh.shilimkar-l0cyMroinI0@public.gmane.org \
--cc=shubhrajyoti-l0cyMroinI0@public.gmane.org \
--cc=tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org \
--cc=w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
/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).