diff options
author | Han Xu <han.xu@nxp.com> | 2017-08-30 15:12:35 -0500 |
---|---|---|
committer | Jason Liu <jason.hui.liu@nxp.com> | 2019-02-12 10:33:12 +0800 |
commit | b318050696964bbfc9928da0c32eaa47c45e0678 (patch) | |
tree | 0f9cafe8974a26739803c0b230a0c369ab89f201 /drivers/mtd | |
parent | b66376f0f51afaf81ab16d754ac33931061a4111 (diff) |
MLK-16329-1: mtd: fsl-flexspi: fix the unalignment issue for fspi
ARM64 platforms may access FSPI from non-64-bit-aligned address which
causes unalignment fault. Fixed the issue for AHB reading.
Signed-off-by: Han Xu <han.xu@nxp.com>
(cherry picked from commit 948c1411230d5e02235fbd429d6ee2e2a2b9adb6)
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/spi-nor/fsl-flexspi.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/drivers/mtd/spi-nor/fsl-flexspi.c b/drivers/mtd/spi-nor/fsl-flexspi.c index 381894ec3906..4b2267ee0374 100644 --- a/drivers/mtd/spi-nor/fsl-flexspi.c +++ b/drivers/mtd/spi-nor/fsl-flexspi.c @@ -1021,6 +1021,7 @@ static ssize_t fsl_flexspi_read(struct spi_nor *nor, loff_t from, size_t len, u_char *buf) { struct fsl_flexspi *flex = nor->priv; + int i, j; /* if necessary,ioremap buffer before AHB read, */ if (!flex->ahb_addr) { @@ -1053,10 +1054,20 @@ static ssize_t fsl_flexspi_read(struct spi_nor *nor, loff_t from, } } - /* Read out the data directly from the AHB buffer.*/ - memcpy(buf, - flex->ahb_addr + flex->chip_base_addr + from - flex->memmap_offs, - len); + /* For non-8-byte alignment cases */ + if (from % 8) { + j = 8 - (from & 0x7); + for (i = 0; i < j; ++i) { + memcpy(buf + i, flex->ahb_addr + flex->chip_base_addr + + from - flex->memmap_offs + i, 1); + } + memcpy(buf + j, flex->ahb_addr + flex->chip_base_addr + from + - flex->memmap_offs + j, len - j); + } else { + /* Read out the data directly from the AHB buffer.*/ + memcpy(buf, flex->ahb_addr + flex->chip_base_addr + from + - flex->memmap_offs, len); + } return len; } |