[U-Boot] [PATCH v7 16/87] spi_flash: Use mtd_info operation for SPI-NOR
Jagan Teki
jteki at openedev.com
Tue Mar 22 08:37:28 CET 2016
Since spi-nor is using mtd layer for flash operations
this patch used mtd ops from user commands instead of
legacy spi_flash{} ops.
Cc: Simon Glass <sjg at chromium.org>
Cc: Bin Meng <bmeng.cn at gmail.com>
Cc: Mugunthan V N <mugunthanvnm at ti.com>
Cc: Michal Simek <michal.simek at xilinx.com>
Cc: Siva Durga Prasad Paladugu <sivadur at xilinx.com>
Signed-off-by: Jagan Teki <jteki at openedev.com>
---
include/spi_flash.h | 60 ++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 48 insertions(+), 12 deletions(-)
diff --git a/include/spi_flash.h b/include/spi_flash.h
index c7fd4f3..43abec9 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -12,6 +12,7 @@
#include <dm.h> /* Because we dereference struct udevice here */
#include <linux/types.h>
+#include <linux/mtd/mtd.h>
#ifndef CONFIG_SF_DEFAULT_SPEED
# define CONFIG_SF_DEFAULT_SPEED 1000000
@@ -112,6 +113,39 @@ struct spi_flash {
typedef struct mtd_info spi_flash_t;
+static inline int spi_flash_read(spi_flash_t *info, u32 offset,
+ size_t len, void *buf)
+{
+ return mtd_read(info, offset, len, &len, (u_char *)buf);
+}
+
+static inline int spi_flash_write(spi_flash_t *info, u32 offset,
+ size_t len, const void *buf)
+{
+ return mtd_write(info, offset, len, &len, (u_char *)buf);
+}
+
+static inline int spi_flash_erase(spi_flash_t *info, u32 offset, size_t len)
+{
+ struct erase_info instr;
+
+ instr.mtd = info;
+ instr.addr = offset;
+ instr.len = len;
+ instr.callback = 0;
+
+ return mtd_erase(info, &instr);
+}
+
+static inline int spi_flash_protect(spi_flash_t *info, u32 ofs,
+ u32 len, bool prot)
+{
+ if (prot)
+ return mtd_lock(info, ofs, len);
+ else
+ return mtd_unlock(info, ofs, len);
+}
+
#ifdef CONFIG_DM_MTD_SPI_NOR
int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
@@ -137,6 +171,20 @@ void spi_flash_free(spi_flash_t *flash);
#endif /* CONFIG_DM_MTD_SPI_NOR */
+#else
+
+static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
+ bool prot)
+{
+ if (!flash->flash_lock || !flash->flash_unlock)
+ return -EOPNOTSUPP;
+
+ if (prot)
+ return flash->flash_lock(flash, ofs, len);
+ else
+ return flash->flash_unlock(flash, ofs, len);
+}
+
#endif /* CONFIG_MTD_SPI_NOR */
struct dm_spi_flash_ops {
@@ -266,18 +314,6 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
}
#endif
-static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
- bool prot)
-{
- if (!flash->flash_lock || !flash->flash_unlock)
- return -EOPNOTSUPP;
-
- if (prot)
- return flash->flash_lock(flash, ofs, len);
- else
- return flash->flash_unlock(flash, ofs, len);
-}
-
void spi_boot(void) __noreturn;
void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
--
1.9.1
More information about the U-Boot
mailing list