diff mbox

[U-Boot,1/4] sf: unify read/write helpers

Message ID 1294644014-7560-2-git-send-email-vapier@gentoo.org
State Accepted
Commit 000044d8bfdc803a1a97e68ba95f289bfe5ad149
Delegated to: Mike Frysinger
Headers show

Commit Message

Mike Frysinger Jan. 10, 2011, 7:20 a.m. UTC
These functions largely do the same exact thing, so unify them all
into one basic function.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/spi/spi_flash.c |   67 ++++++++++++------------------------------
 1 files changed, 19 insertions(+), 48 deletions(-)

Comments

Wolfgang Denk April 11, 2011, 7:01 p.m. UTC | #1
Dear Mike Frysinger,

In message <1294644014-7560-2-git-send-email-vapier@gentoo.org> you wrote:
> These functions largely do the same exact thing, so unify them all
> into one basic function.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
>  drivers/mtd/spi/spi_flash.c |   67 ++++++++++++------------------------------
>  1 files changed, 19 insertions(+), 48 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index b61d219..2b7f22c 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -14,32 +14,10 @@ 
 
 #include "spi_flash_internal.h"
 
-int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len)
-{
-	unsigned long flags = SPI_XFER_BEGIN;
-	int ret;
-
-	if (len == 0)
-		flags |= SPI_XFER_END;
-
-	ret = spi_xfer(spi, 8, &cmd, NULL, flags);
-	if (ret) {
-		debug("SF: Failed to send command %02x: %d\n", cmd, ret);
-		return ret;
-	}
-
-	if (len) {
-		ret = spi_xfer(spi, len * 8, NULL, response, SPI_XFER_END);
-		if (ret)
-			debug("SF: Failed to read response (%zu bytes): %d\n",
-					len, ret);
-	}
-
-	return ret;
-}
-
-int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
-		size_t cmd_len, void *data, size_t data_len)
+static int spi_flash_read_write(struct spi_slave *spi,
+				const u8 *cmd, size_t cmd_len,
+				const u8 *data_out, u8 *data_in,
+				size_t data_len)
 {
 	unsigned long flags = SPI_XFER_BEGIN;
 	int ret;
@@ -49,41 +27,34 @@  int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
 
 	ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, flags);
 	if (ret) {
-		debug("SF: Failed to send read command (%zu bytes): %d\n",
+		debug("SF: Failed to send command (%zu bytes): %d\n",
 				cmd_len, ret);
 	} else if (data_len != 0) {
-		ret = spi_xfer(spi, data_len * 8, NULL, data, SPI_XFER_END);
+		ret = spi_xfer(spi, data_len * 8, data_out, data_in, SPI_XFER_END);
 		if (ret)
-			debug("SF: Failed to read %zu bytes of data: %d\n",
+			debug("SF: Failed to transfer %zu bytes of data: %d\n",
 					data_len, ret);
 	}
 
 	return ret;
 }
 
-int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
-		const void *data, size_t data_len)
+int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len)
 {
-	unsigned long flags = SPI_XFER_BEGIN;
-	int ret;
-
-	if (data_len == 0)
-		flags |= SPI_XFER_END;
-
-	ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, flags);
-	if (ret) {
-		debug("SF: Failed to send read command (%zu bytes): %d\n",
-				cmd_len, ret);
-	} else if (data_len != 0) {
-		ret = spi_xfer(spi, data_len * 8, data, NULL, SPI_XFER_END);
-		if (ret)
-			debug("SF: Failed to read %zu bytes of data: %d\n",
-					data_len, ret);
-	}
+	return spi_flash_cmd_read(spi, &cmd, 1, response, len);
+}
 
-	return ret;
+int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
+		size_t cmd_len, void *data, size_t data_len)
+{
+	return spi_flash_read_write(spi, cmd, cmd_len, NULL, data, data_len);
 }
 
+int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
+		const void *data, size_t data_len)
+{
+	return spi_flash_read_write(spi, cmd, cmd_len, data, NULL, data_len);
+}
 
 int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 		size_t cmd_len, void *data, size_t data_len)