[U-Boot] [PATCH 1/9 v2] i.MX31: fix SPI driver for shorter than 32 bit transfers

Guennadi Liakhovetski lg at denx.de
Thu Feb 5 13:31:55 CET 2009


Fix 8 and 16-bit transfers in mxc_spi driver and a wrong pointer in the
free routine.

Signed-off-by: Guennadi Liakhovetski <lg at denx.de>
---

Changes since v1: chose a simpler fix

>From e31f4128d852be04ed459c271d6c1d9f4b08ec69 Mon Sep 17 00:00:00 2001
From: Guennadi Liakhovetski <lg at denx.de>
Date: Thu, 5 Feb 2009 12:44:28 +0100
Subject: [PATCH] i.MX31: fix SPI driver for shorter than 32 bit transfers

Fix 8 and 16-bit transfers in mxc_spi driver and a wrong pointer in the
free routine.

Signed-off-by: Guennadi Liakhovetski <lg at denx.de>
---
 drivers/spi/mxc_spi.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c
index 5957ada..b7bd84b 100644
--- a/drivers/spi/mxc_spi.c
+++ b/drivers/spi/mxc_spi.c
@@ -122,8 +122,17 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 
 	for (i = 0, in_l = (u32 *)din, out_l = (u32 *)dout;
 	     i < n_blks;
-	     i++, in_l++, out_l++, bitlen -= 32)
-		*in_l = spi_xchg_single(slave, *out_l, bitlen);
+	     i++, in_l++, out_l++, bitlen -= 32) {
+		u32 data = spi_xchg_single(slave, *out_l, bitlen);
+
+		/* Check if we're only transfering 8 or 16 bits */
+		if (!i) {
+			if (bitlen < 9)
+				*(u8 *)din = data;
+			else if (bitlen < 17)
+				*(u16 *)din = data;
+		}
+	}
 
 	return 0;
 }
@@ -169,7 +178,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 
 void spi_free_slave(struct spi_slave *slave)
 {
-	free(slave);
+	struct mxc_spi_slave *mxcs = to_mxc_spi_slave(slave);
+	free(mxcs);
 }
 
 int spi_claim_bus(struct spi_slave *slave)
-- 
1.5.4



More information about the U-Boot mailing list