The USER_DATA register cannot be accessed using byte accessors on A13
SoCs, thus triggering a bug when using memcpy_toio on this register.
Declare a temporary u32 variable to store the USER_DATA value and access
the register with writel.

Signed-off-by: Boris Brezillon <[email protected]>
---
 drivers/mtd/nand/sunxi_nand.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index 6f93b29..5e374ab 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -624,6 +624,8 @@ static int sunxi_nfc_hw_ecc_write_page(struct mtd_info *mtd,
        writel(tmp, nfc->regs + NFC_REG_ECC_CTL);
 
        for (i = 0; i < ecc->steps; i++) {
+               u32 user_data;
+
                if (i)
                        chip->cmdfunc(mtd, NAND_CMD_RNDIN, i * ecc->size, -1);
 
@@ -632,16 +634,16 @@ static int sunxi_nfc_hw_ecc_write_page(struct mtd_info 
*mtd,
                offset = layout->eccpos[i * ecc->bytes] - 4 + mtd->writesize;
 
                /* Fill OOB data in */
-               if (oob_required) {
-                       tmp = 0xffffffff;
-                       memcpy_toio(nfc->regs + NFC_REG_USER_DATA_BASE, &tmp,
-                                   4);
+               if (!oob_required) {
+                       user_data = 0xffffffff;
                } else {
-                       memcpy_toio(nfc->regs + NFC_REG_USER_DATA_BASE,
-                                   chip->oob_poi + offset - mtd->writesize,
-                                   4);
+                       memcpy(&user_data,
+                              chip->oob_poi + layout->oobfree[i].offset, 4);
+                       user_data = le32_to_cpu(user_data);
                }
 
+               writel(user_data, nfc->regs + NFC_REG_USER_DATA_BASE);
+
                chip->cmdfunc(mtd, NAND_CMD_RNDIN, offset, -1);
 
                ret = sunxi_nfc_wait_cmd_fifo_empty(nfc);
@@ -772,13 +774,13 @@ static int sunxi_nfc_hw_syndrome_ecc_write_page(struct 
mtd_info *mtd,
                /* Fill OOB data in */
                if (oob_required) {
                        tmp = 0xffffffff;
-                       memcpy_toio(nfc->regs + NFC_REG_USER_DATA_BASE, &tmp,
-                                   4);
                } else {
-                       memcpy_toio(nfc->regs + NFC_REG_USER_DATA_BASE, oob,
-                                   4);
+                       memcpy(&tmp, oob, sizeof(tmp));
+                       tmp = le32_to_cpu(tmp);
                }
 
+               writel(tmp, nfc->regs + NFC_REG_USER_DATA_BASE);
+
                tmp = NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | NFC_ACCESS_DIR |
                      (1 << 30);
                writel(tmp, nfc->regs + NFC_REG_CMD);
-- 
1.9.1

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to