]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
spi: sf: Support byte program for sst spi flash
authorBin Meng <bmeng.cn@gmail.com>
Fri, 12 Dec 2014 14:06:13 +0000 (19:36 +0530)
committerSimon Glass <sjg@chromium.org>
Sat, 13 Dec 2014 22:08:04 +0000 (15:08 -0700)
Currently if SST flash advertises SST_WP flag in the params table
the word program command (ADh) with auto address increment will be
used for the flash write op. However some SPI controllers do not
support the word program command (like the Intel ICH 7), the byte
programm command (02h) has to be used.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
drivers/mtd/spi/sf_internal.h
drivers/mtd/spi/sf_ops.c

index 7218e697a05574b3902a9294444152444d9765dd..fb53cb083470de674e98d7fe75226fadec6a5d41 100644 (file)
@@ -110,6 +110,8 @@ enum {
 
 int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
                const void *buf);
+int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
+               const void *buf);
 #endif
 
 /**
index 759231f2e34b6d66f55ac38e25a85c179cd50732..34bc54e73e1f7b74d58d1d47fe87b56471371081 100644 (file)
@@ -517,4 +517,35 @@ int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
        spi_release_bus(flash->spi);
        return ret;
 }
+
+int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
+               const void *buf)
+{
+       size_t actual;
+       int ret;
+
+       ret = spi_claim_bus(flash->spi);
+       if (ret) {
+               debug("SF: Unable to claim SPI bus\n");
+               return ret;
+       }
+
+       for (actual = 0; actual < len; actual++) {
+               ret = sst_byte_write(flash, offset, buf + actual);
+               if (ret) {
+                       debug("SF: sst byte program failed\n");
+                       break;
+               }
+               offset++;
+       }
+
+       if (!ret)
+               ret = spi_flash_cmd_write_disable(flash);
+
+       debug("SF: sst: program %s %zu bytes @ 0x%zx\n",
+             ret ? "failure" : "success", len, offset - actual);
+
+       spi_release_bus(flash->spi);
+       return ret;
+}
 #endif