diff mbox

[U-Boot,2/3] i2c: tegra: write clean data to TX FIFO

Message ID 1403715449-2177-2-git-send-email-swarren@wwwdotorg.org
State Accepted
Delegated to: Heiko Schocher
Headers show

Commit Message

Stephen Warren June 25, 2014, 4:57 p.m. UTC
From: Stephen Warren <swarren@nvidia.com>

The Tegra I2C controller's TX FIFO contains 32-bit words. If the final
FIFO entry of a transaction contains fewer than 4 bytes, the driver
currently fills the unused FIFO bytes with uninitialized data. This can
be confusing when reading back the FIFO content for debugging purposes.

Solve this by explicitly initializing the variable containing FIFO data
before filling it (partially) with data. With this change,
send_recv_packets()'s loop's if (is_write) code mirrors the else (i.e.
read) branch.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 drivers/i2c/tegra_i2c.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Yen Lin June 25, 2014, 11:37 p.m. UTC | #1
Hi Stephen,

> Subject: [U-Boot] [PATCH 2/3] i2c: tegra: write clean data to TX FIFO
> 
> From: Stephen Warren <swarren@nvidia.com>
> 
> The Tegra I2C controller's TX FIFO contains 32-bit words. If the final FIFO
> entry of a transaction contains fewer than 4 bytes, the driver currently fills
> the unused FIFO bytes with uninitialized data. This can be confusing when
> reading back the FIFO content for debugging purposes.
> 
> Solve this by explicitly initializing the variable containing FIFO data before
> filling it (partially) with data. With this change, send_recv_packets()'s loop's if
> (is_write) code mirrors the else (i.e.
> read) branch.
> 
> Signed-off-by: Stephen Warren <swarren@nvidia.com>

LGME.

Reviewed-by: Yen Lin <yelin@nvidia.com>

Regards,
Yen Lin

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Yen Lin June 25, 2014, 11:42 p.m. UTC | #2
> >
> > Signed-off-by: Stephen Warren <swarren@nvidia.com>
> 
> LGME.

Oops, should be LGTM.

> 
> Reviewed-by: Yen Lin <yelin@nvidia.com>
> 
> Regards,
> Yen Lin

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
diff mbox

Patch

diff --git a/drivers/i2c/tegra_i2c.c b/drivers/i2c/tegra_i2c.c
index 97f0ca44c59a..a62f30e66ce1 100644
--- a/drivers/i2c/tegra_i2c.c
+++ b/drivers/i2c/tegra_i2c.c
@@ -224,14 +224,16 @@  static int send_recv_packets(struct i2c_bus *i2c_bus,
 
 		if (is_write) {
 			/* deal with word alignment */
-			if ((unsigned)dptr & 3) {
+			if ((words == 1) && last_bytes) {
+				local = 0;
+				memcpy(&local, dptr, last_bytes);
+			} else if ((unsigned)dptr & 3) {
 				memcpy(&local, dptr, sizeof(u32));
-				writel(local, &control->tx_fifo);
-				debug("pkt data sent (0x%x)\n", local);
 			} else {
-				writel(*wptr, &control->tx_fifo);
-				debug("pkt data sent (0x%x)\n", *wptr);
+				local = *wptr;
 			}
+			writel(local, &control->tx_fifo);
+			debug("pkt data sent (0x%x)\n", local);
 			if (!wait_for_tx_fifo_empty(control)) {
 				error = -1;
 				goto exit;