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 <s...@chromium.org>
Cc: Bin Meng <bmeng...@gmail.com>
Cc: Mugunthan V N <mugunthan...@ti.com>
Cc: Michal Simek <michal.si...@xilinx.com>
Cc: Siva Durga Prasad Paladugu <siva...@xilinx.com>
Signed-off-by: Jagan Teki <jt...@openedev.com>
---
Changes for v7:
        - Rename CONFIG_MTD_DM_SPI_NOR to CONFIG_DM_MTD_SPI_NOR

 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 181b31e..09a7ce6 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 {
@@ -259,18 +307,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

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

Reply via email to