From: Siva Durga Prasad Paladugu Date: Tue, 31 Jan 2017 05:14:07 +0000 (+0530) Subject: mtd: spi_flash: Add support for read if offset is odd X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=88071ec108fbca19055ec5421326b7c0b7ea47cf;p=thirdparty%2Fu-boot.git mtd: spi_flash: Add support for read if offset is odd Add support ot read from flash if offset received is odd incase of dual parallel. This fixes the issue of spi flash read failures if received offset is odd Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek --- diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 169c3ea93df..93d255e4c76 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -599,6 +599,27 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, u32 remain_len, read_len, read_addr, bank_addr; int bank_sel = 0; int ret = -1; +#ifdef CONFIG_SF_DUAL_FLASH + u8 moveoffs = 0; + void *tempbuf = NULL; + size_t length = len; +#endif + +#ifdef CONFIG_SF_DUAL_FLASH + /* + * Incase of dual parallel, if odd offset is received + * decrease it by 1 and read extra byte, otherwise + * any read with odd offset fails + */ + if (flash->dual_flash == SF_DUAL_PARALLEL_FLASH) { + if (offset & 1) { + offset -= 1; + len += 1; + moveoffs = 1; + tempbuf = data; + } + } +#endif /* Handle memory-mapped SPI */ if (flash->memory_map) { @@ -681,6 +702,15 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, data += read_len; } +#ifdef CONFIG_SF_DUAL_FLASH + if (flash->dual_flash == SF_DUAL_PARALLEL_FLASH) { + if (moveoffs) { + data = tempbuf + 1; + memcpy(tempbuf, data, length); + } + } +#endif + free(cmd); return ret; }