diff mbox

[U-Boot,v7,36/87] mtd: dataflash: Use spi_write_then_read

Message ID 1458632319-24866-36-git-send-email-jteki@openedev.com
State Deferred
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Commit Message

Jagan Teki March 22, 2016, 7:37 a.m. UTC
Use spi_write_then_read call from spi layer for
dataflash write and then read calling.

Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: York Sun <york.sun@nxp.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
 drivers/mtd/spi-nor/sf_dataflash.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/drivers/mtd/spi-nor/sf_dataflash.c b/drivers/mtd/spi-nor/sf_dataflash.c
index 722ab7e..525af0a 100644
--- a/drivers/mtd/spi-nor/sf_dataflash.c
+++ b/drivers/mtd/spi-nor/sf_dataflash.c
@@ -84,12 +84,12 @@  struct dataflash {
 static inline int dataflash_status(struct spi_slave *spi)
 {
 	int ret;
-	u8 status;
+	u8 cmd = OP_READ_STATUS, status;
 	/*
 	 * NOTE:  at45db321c over 25 MHz wants to write
 	 * a dummy byte after the opcode...
 	 */
-	ret = spi_flash_cmd(spi, OP_READ_STATUS, &status, 1);
+	ret = spi_write_then_read(spi, &cmd, 1, NULL, &status, 1);
 	return ret ? -EIO : status;
 }
 
@@ -171,7 +171,7 @@  static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
 		      command[0], command[1], command[2], command[3],
 		      pageaddr);
 
-		status = spi_flash_cmd_write(spi, command, 4, NULL, 0);
+		status = spi_write_then_read(spi, command, 4, NULL, NULL, 0);
 		if (status < 0) {
 			debug("%s: erase send command error!\n", mtd->name);
 			return -EIO;
@@ -247,7 +247,7 @@  static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
 	command[3] = (uint8_t)(addr >> 0);
 
 	/* plus 4 "don't care" bytes, command len: 4 + 4 "don't care" bytes */
-	status = spi_flash_cmd_read(spi, command, 8, buf, len);
+	status = spi_write_then_read(spi, command, 8, NULL, buf, len);
 	if (status >= 0) {
 		*retlen = len - 8;
 		status = 0;
@@ -327,7 +327,7 @@  static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
 			debug("TRANSFER: (%x) %x %x %x\n",
 			      command[0], command[1], command[2], command[3]);
 
-			status = spi_flash_cmd_write(spi, command, 4, NULL, 0);
+			status = spi_write_then_read(spi, command, 4, NULL, NULL, 0);
 			if (status < 0) {
 				debug("%s: write(<pagesize) command error!\n",
 				      mtd->name);
@@ -352,8 +352,8 @@  static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
 		debug("PROGRAM: (%x) %x %x %x\n",
 		      command[0], command[1], command[2], command[3]);
 
-		status = spi_flash_cmd_write(spi, command,
-					     4, writebuf, writelen);
+		status = spi_write_then_read(spi, command, 4,
+					     writebuf, NULL, writelen);
 		if (status < 0) {
 			debug("%s: write send command error!\n", mtd->name);
 			return -EIO;
@@ -376,8 +376,8 @@  static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
 		debug("COMPARE: (%x) %x %x %x\n",
 		      command[0], command[1], command[2], command[3]);
 
-		status = spi_flash_cmd_write(spi, command,
-					     4, writebuf, writelen);
+		status = spi_write_then_read(spi, command, 4,
+					     writebuf, NULL, writelen);
 		if (status < 0) {
 			debug("%s: write(compare) send command error!\n",
 			      mtd->name);
@@ -519,6 +519,7 @@  static struct flash_info *jedec_probe(struct spi_slave *spi)
 	uint8_t			id[5];
 	uint32_t		jedec;
 	struct flash_info	*info;
+	u8 cmd = CMD_READ_ID;
 	int status;
 
 	/*
@@ -530,7 +531,7 @@  static struct flash_info *jedec_probe(struct spi_slave *spi)
 	 * That's not an error; only rev C and newer chips handle it, and
 	 * only Atmel sells these chips.
 	 */
-	tmp = spi_flash_cmd(spi, CMD_READ_ID, id, sizeof(id));
+	tmp = spi_write_then_read(spi, &cmd, 1, NULL, id, sizeof(id));
 	if (tmp < 0) {
 		printf("dataflash: error %d reading JEDEC ID\n", tmp);
 		return ERR_PTR(tmp);