* [PATCH REPOST 1/3] i2c: Tegra: Add of_match_table
2011-08-30 17:46 [PATCH REPOST 0/3] i2c: tegra: Outstanding patches Stephen Warren
@ 2011-08-30 17:46 ` Stephen Warren
2011-08-30 17:46 ` [PATCH REPOST 2/3] i2c: i2c-tegra: add I2C_FUNC_SMBUS_EMUL Stephen Warren
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Stephen Warren @ 2011-08-30 17:46 UTC (permalink / raw)
To: linux-arm-kernel
From: John Bonesio <bones@secretlab.ca>
This patch was intended to be part of 7ca2d1a105a239e300b937e9c41a10a4bd08f569
"i2c: Tegra: Add DeviceTree support". However, an early version of that patch,
which was missing a chunk, was applied to next-i2c. This change is that
missing chunk.
Signed-off-by: John Bonesio <bones@secretlab.ca>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
drivers/i2c/busses/i2c-tegra.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 0c6e840..dd1f21b 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -720,6 +720,17 @@ static int tegra_i2c_resume(struct platform_device *pdev)
}
#endif
+#if defined(CONFIG_OF)
+/* Match table for of_platform binding */
+static const struct of_device_id tegra_i2c_of_match[] __devinitconst = {
+ { .compatible = "nvidia,tegra20-i2c", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, tegra_i2c_of_match);
+#else
+#define tegra_i2c_of_match NULL
+#endif
+
static struct platform_driver tegra_i2c_driver = {
.probe = tegra_i2c_probe,
.remove = tegra_i2c_remove,
@@ -730,6 +741,7 @@ static struct platform_driver tegra_i2c_driver = {
.driver = {
.name = "tegra-i2c",
.owner = THIS_MODULE,
+ .of_match_table = tegra_i2c_of_match,
},
};
--
1.7.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH REPOST 2/3] i2c: i2c-tegra: add I2C_FUNC_SMBUS_EMUL
2011-08-30 17:46 [PATCH REPOST 0/3] i2c: tegra: Outstanding patches Stephen Warren
2011-08-30 17:46 ` [PATCH REPOST 1/3] i2c: Tegra: Add of_match_table Stephen Warren
@ 2011-08-30 17:46 ` Stephen Warren
2011-08-30 17:46 ` [PATCH REPOST 3/3] i2c: tegra: fix possible race condition after tx Stephen Warren
2011-09-06 23:15 ` [PATCH REPOST 0/3] i2c: tegra: Outstanding patches Ben Dooks
3 siblings, 0 replies; 5+ messages in thread
From: Stephen Warren @ 2011-08-30 17:46 UTC (permalink / raw)
To: linux-arm-kernel
From: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
drivers/i2c/busses/i2c-tegra.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index dd1f21b..8848a4b 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -532,7 +532,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
static u32 tegra_i2c_func(struct i2c_adapter *adap)
{
- return I2C_FUNC_I2C;
+ return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
}
static const struct i2c_algorithm tegra_i2c_algo = {
--
1.7.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH REPOST 3/3] i2c: tegra: fix possible race condition after tx
2011-08-30 17:46 [PATCH REPOST 0/3] i2c: tegra: Outstanding patches Stephen Warren
2011-08-30 17:46 ` [PATCH REPOST 1/3] i2c: Tegra: Add of_match_table Stephen Warren
2011-08-30 17:46 ` [PATCH REPOST 2/3] i2c: i2c-tegra: add I2C_FUNC_SMBUS_EMUL Stephen Warren
@ 2011-08-30 17:46 ` Stephen Warren
2011-09-06 23:15 ` [PATCH REPOST 0/3] i2c: tegra: Outstanding patches Ben Dooks
3 siblings, 0 replies; 5+ messages in thread
From: Stephen Warren @ 2011-08-30 17:46 UTC (permalink / raw)
To: linux-arm-kernel
From: Doug Anderson <dianders@chromium.org>
In tegra_i2c_fill_tx_fifo, once we have finished pushing all the bytes
to the I2C hardware controller, the interrupt might happen before we
have updated i2c_dev->msg_buf_remaining at the end of the function.
Then, in tegra_i2c_isr, we will call again tegra_i2c_fill_tx_fifo
triggering weird behaviour. This has been shown to happen under real
conditions.
Signed-off-by: Doug Anderson <dianders@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Acked-by: Rhyland Klein <rklein@nvidia.com>
Acked-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
drivers/i2c/busses/i2c-tegra.c | 46 +++++++++++++++++++++++++++------------
1 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 8848a4b..b402435 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -271,14 +271,30 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
/* Rounds down to not include partial word at the end of buf */
words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD;
- if (words_to_transfer > tx_fifo_avail)
- words_to_transfer = tx_fifo_avail;
- i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
-
- buf += words_to_transfer * BYTES_PER_FIFO_WORD;
- buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD;
- tx_fifo_avail -= words_to_transfer;
+ /* It's very common to have < 4 bytes, so optimize that case. */
+ if (words_to_transfer) {
+ if (words_to_transfer > tx_fifo_avail)
+ words_to_transfer = tx_fifo_avail;
+
+ /*
+ * Update state before writing to FIFO. If this casues us
+ * to finish writing all bytes (AKA buf_remaining goes to 0) we
+ * have a potential for an interrupt (PACKET_XFER_COMPLETE is
+ * not maskable). We need to make sure that the isr sees
+ * buf_remaining as 0 and doesn't call us back re-entrantly.
+ */
+ buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD;
+ tx_fifo_avail -= words_to_transfer;
+ i2c_dev->msg_buf_remaining = buf_remaining;
+ i2c_dev->msg_buf = buf +
+ words_to_transfer * BYTES_PER_FIFO_WORD;
+ barrier();
+
+ i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
+
+ buf += words_to_transfer * BYTES_PER_FIFO_WORD;
+ }
/*
* If there is a partial word at the end of buf, handle it manually to
@@ -288,14 +304,15 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
if (tx_fifo_avail > 0 && buf_remaining > 0) {
BUG_ON(buf_remaining > 3);
memcpy(&val, buf, buf_remaining);
+
+ /* Again update before writing to FIFO to make sure isr sees. */
+ i2c_dev->msg_buf_remaining = 0;
+ i2c_dev->msg_buf = NULL;
+ barrier();
+
i2c_writel(i2c_dev, val, I2C_TX_FIFO);
- buf_remaining = 0;
- tx_fifo_avail--;
}
- BUG_ON(tx_fifo_avail > 0 && buf_remaining > 0);
- i2c_dev->msg_buf_remaining = buf_remaining;
- i2c_dev->msg_buf = buf;
return 0;
}
@@ -412,9 +429,10 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
tegra_i2c_mask_irq(i2c_dev, I2C_INT_TX_FIFO_DATA_REQ);
}
- if ((status & I2C_INT_PACKET_XFER_COMPLETE) &&
- !i2c_dev->msg_buf_remaining)
+ if (status & I2C_INT_PACKET_XFER_COMPLETE) {
+ BUG_ON(i2c_dev->msg_buf_remaining);
complete(&i2c_dev->msg_complete);
+ }
i2c_writel(i2c_dev, status, I2C_INT_STATUS);
if (i2c_dev->is_dvc)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH REPOST 0/3] i2c: tegra: Outstanding patches
2011-08-30 17:46 [PATCH REPOST 0/3] i2c: tegra: Outstanding patches Stephen Warren
` (2 preceding siblings ...)
2011-08-30 17:46 ` [PATCH REPOST 3/3] i2c: tegra: fix possible race condition after tx Stephen Warren
@ 2011-09-06 23:15 ` Ben Dooks
3 siblings, 0 replies; 5+ messages in thread
From: Ben Dooks @ 2011-09-06 23:15 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Aug 30, 2011 at 11:46:07AM -0600, Stephen Warren wrote:
> For convenience, here's a repost of the outstanding patches for the Tegra
> I2C driver.
applied all of them.
in future, it would be helpful to have just i2c-tegra on the
front of the subject. fixed these up and put them in pull req
to linus
> Doug Anderson (1):
> i2c: tegra: fix possible race condition after tx
>
> John Bonesio (1):
> i2c: Tegra: Add of_match_table
>
> Mike Rapoport (1):
> i2c: i2c-tegra: add I2C_FUNC_SMBUS_EMUL
>
> drivers/i2c/busses/i2c-tegra.c | 60 ++++++++++++++++++++++++++++++----------
> 1 files changed, 45 insertions(+), 15 deletions(-)
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread