Generic function for spi-flash memory reading.

Signed-off-by: Jagan Teki <jt...@openedev.com>
---
Changes for v3:
        - none
Changes for v2:
        - none

 drivers/mtd/spi/sf.c          | 23 +++++++++++++++++++++++
 drivers/mtd/spi/sf_internal.h |  3 +++
 2 files changed, 26 insertions(+)

diff --git a/drivers/mtd/spi/sf.c b/drivers/mtd/spi/sf.c
index cb36946..2670207 100644
--- a/drivers/mtd/spi/sf.c
+++ b/drivers/mtd/spi/sf.c
@@ -79,3 +79,26 @@ int flash_read_reg(struct spi_flash *flash, u8 cmd, u8 *val, 
int len)
 
        return ret;
 }
+
+int flash_read(struct spi_flash *flash, const u8 *cmd, size_t cmd_len,
+                               void *data, size_t data_len)
+{
+       struct spi_slave *spi = flash->spi;
+       int ret;
+
+       ret = spi_claim_bus(spi);
+       if (ret < 0) {
+               debug("SF: unable to claim SPI bus\n");
+               return ret;
+       }
+
+       ret = spi_flash_read_write(spi, cmd, cmd_len, NULL, data, data_len);
+       if (ret < 0) {
+               debug("SF: error %d reading %x\n", ret, *cmd);
+               return ret;
+       }
+
+       spi_release_bus(spi);
+
+       return ret;
+}
diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index 9341fb3..4dfc67d 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -159,6 +159,9 @@ int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
 /* Read flash register - common call for all flash register reads */
 int flash_read_reg(struct spi_flash *flash, u8 cmd, u8 *val, int len);
 
+/* Read flash memory - Read data from spi flash */
+int flash_read(struct spi_flash *flash, const u8 *cmd, size_t cmd_len,
+                               void *data, size_t data_len);
 /*
  * Send a multi-byte command to the device followed by (optional)
  * data. Used for programming the flash array, etc.
-- 
1.9.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to