Since MTD support is added in spi_flash layer, this patch uses mtd_info operations instead of legacy spi_flash operations.
Reviewed-by: Heiko Schocher <h...@denx.de> Signed-off-by: Jagan Teki <jt...@openedev.com> --- drivers/mtd/spi/sf_ops.c | 66 ++++++++++++++++++++++++++++-------------------- include/spi_flash.h | 23 ++++++++--------- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index 7cbbeaf..5fa6113 100644 --- a/drivers/mtd/spi/sf_ops.c +++ b/drivers/mtd/spi/sf_ops.c @@ -297,18 +297,16 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd, return ret; } -static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, - size_t len) +static int spi_flash_cmd_erase_ops(struct mtd_info *mtd, + struct erase_info *instr) { - u32 erase_size, erase_addr; + struct spi_flash *flash = mtd->priv; + u32 offset, len, erase_addr; u8 cmd[SPI_FLASH_CMD_LEN]; int ret = -1; - erase_size = mtd->erasesize; - if (offset % erase_size || len % erase_size) { - debug("SF: Erase offset/length not multiple of erase size\n"); - return -1; - } + offset = instr->addr; + len = instr->len; if (flash->flash_is_locked(flash, offset, len) > 0) { printf("offset 0x%x is protected and cannot be erased\n", offset); @@ -336,19 +334,24 @@ static int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0); if (ret < 0) { debug("SF: erase failed\n"); - break; + goto erase_err; } - offset += erase_size; - len -= erase_size; + offset += mtd->erasesize; + len -= mtd->erasesize; } return ret; + +erase_err: + instr->state = MTD_ERASE_FAILED; + return ret; } -static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset, - size_t len, const void *buf) +static int spi_flash_cmd_write_ops(struct mtd_info *mtd, loff_t offset, + size_t len, size_t *retlen, const u_char *buf) { + struct spi_flash *flash = mtd->priv; unsigned long byte_addr, page_size; u32 write_addr; size_t chunk_len, actual; @@ -395,6 +398,7 @@ static int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset, } offset += chunk_len; + *retlen += chunk_len; } return ret; @@ -428,11 +432,12 @@ void __weak spi_flash_copy_mmap(void *data, void *offset, size_t len) memcpy(data, offset, len); } -static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, - size_t len, void *data) +static int spi_flash_cmd_read_ops(struct mtd_info *mtd, loff_t offset, + size_t len, size_t *retlen, u_char *data) { - u8 *cmd, cmdsz; + struct spi_flash *flash = mtd->priv; u32 remain_len, read_len, read_addr; + u8 *cmd, cmdsz; int bank_sel = 0; int ret = -1; @@ -489,6 +494,7 @@ static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, offset += read_len; len -= read_len; data += read_len; + *retlen += read_len; } free(cmd); @@ -496,7 +502,8 @@ static int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, } #ifdef CONFIG_SPI_FLASH_SST -static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf) +static int sst_byte_write(struct spi_flash *flash, u32 offset, + const void *buf, size_t *retlen) { int ret; u8 cmd[4] = { @@ -517,12 +524,15 @@ static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf) if (ret) return ret; + *retlen += 1; + return spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT); } -static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, - const void *buf) +static int sst_write_wp(struct mtd_info *mtd, loff_t offset, size_t len, + size_t *retlen, const u_char *buf) { + struct spi_flash *flash = mtd->priv; size_t actual, cmd_len; int ret; u8 cmd[4]; @@ -536,7 +546,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, /* If the data is not word aligned, write out leading single byte */ actual = offset % 2; if (actual) { - ret = sst_byte_write(flash, offset, buf); + ret = sst_byte_write(flash, offset, buf, retlen); if (ret) goto done; } @@ -553,7 +563,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, cmd[3] = offset; for (; actual < len - 1; actual += 2) { - debug("WP[%02x]: 0x%p => cmd = { 0x%02x 0x%06x }\n", + debug("WP[%02x]: 0x%p => cmd = { 0x%02x 0x%06llx }\n", spi_w8r8(flash->spi, CMD_READ_STATUS), buf + actual, cmd[0], offset); @@ -570,6 +580,7 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, cmd_len = 1; offset += 2; + *retlen += 2; } if (!ret) @@ -577,19 +588,20 @@ static int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, /* If there is a single trailing byte, write it out */ if (!ret && actual != len) - ret = sst_byte_write(flash, offset, buf + actual); + ret = sst_byte_write(flash, offset, buf + actual, retlen); done: - debug("SF: sst: program %s %zu bytes @ 0x%zx\n", + debug("SF: sst: program %s %zu bytes @ 0x%llx\n", ret ? "failure" : "success", len, offset - actual); spi_release_bus(flash->spi); return ret; } -static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len, - const void *buf) +static int sst_write_bp(struct mtd_info *mtd, loff_t offset, size_t len, + size_t *retlen, const u_char *buf) { + struct spi_flash *flash = mtd->priv; size_t actual; int ret; @@ -600,7 +612,7 @@ static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len, } for (actual = 0; actual < len; actual++) { - ret = sst_byte_write(flash, offset, buf + actual); + ret = sst_byte_write(flash, offset, buf + actual, retlen); if (ret) { debug("SF: sst byte program failed\n"); break; @@ -611,7 +623,7 @@ static int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len, if (!ret) ret = spi_flash_cmd_write_disable(flash); - debug("SF: sst: program %s %zu bytes @ 0x%zx\n", + debug("SF: sst: program %s %zu bytes @ 0x%llx\n", ret ? "failure" : "success", len, offset - actual); spi_release_bus(flash->spi); diff --git a/include/spi_flash.h b/include/spi_flash.h index 6010b15..4051a35 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -58,12 +58,6 @@ struct spi_slave; * @flash_lock: lock a region of the SPI Flash * @flash_unlock: unlock a region of the SPI Flash * @flash_is_locked: check if a region of the SPI Flash is completely locked - * @read: Flash read ops: Read len bytes at offset into buf - * Supported cmds: Fast Array Read - * @write: Flash write ops: Write len bytes from buf into offset - * Supported cmds: Page Program - * @erase: Flash erase ops: Erase len bytes from offset - * Supported cmds: Sector erase 4K, 32K, 64K * return 0 - Success, 1 - Failure */ struct spi_flash { @@ -95,10 +89,6 @@ struct spi_flash { int (*flash_lock)(struct spi_flash *flash, u32 ofs, size_t len); int (*flash_unlock)(struct spi_flash *flash, u32 ofs, size_t len); int (*flash_is_locked)(struct spi_flash *flash, u32 ofs, size_t len); - int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf); - int (*write)(struct spi_flash *flash, u32 offset, size_t len, - const void *buf); - int (*erase)(struct spi_flash *flash, u32 offset, size_t len); }; struct dm_spi_flash_ops { @@ -163,19 +153,26 @@ int spi_flash_remove(struct udevice *flash); static inline int spi_flash_read(struct spi_flash *flash, u32 offset, size_t len, void *buf) { - return spi_flash_read_dm(flash->dev, offset, len, buf); + return mtd_read(flash->mtd, offset, len, &len, (u_char *)buf); } static inline int spi_flash_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf) { - return spi_flash_write_dm(flash->dev, offset, len, buf); + return mtd_write(flash->mtd, offset, len, &len, (u_char *)buf); } static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, size_t len) { - return spi_flash_erase_dm(flash->dev, offset, len); + struct erase_info instr; + + instr.mtd = flash->mtd; + instr.addr = offset; + instr.len = len; + instr.callback = 0; + + return mtd_erase(flash->mtd, &instr); } struct sandbox_state; -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot