Use defines instead of hardcoded values for NFC_ECC_{ERR_MSK,PAT_FOUND}

SPL is using hard coded values for ECC error detection and empty chunk
detection.
The H6/H616 registers for that have changed, the pattern found is no
more in the NFC_REG_ECC_ST register.

So, don't presume anymore that pattern_found is in NFC_REG_ECC_ST, and
read the pattern_found register to get this information.

Apart from an additional register reading, no functional change.

Signed-off-by: Richard Genoud <[email protected]>
---
 drivers/mtd/nand/raw/sunxi_nand.h     |  3 +++
 drivers/mtd/nand/raw/sunxi_nand_spl.c | 21 +++++++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/sunxi_nand.h 
b/drivers/mtd/nand/raw/sunxi_nand.h
index a8224d1f7c85..52200468d343 100644
--- a/drivers/mtd/nand/raw/sunxi_nand.h
+++ b/drivers/mtd/nand/raw/sunxi_nand.h
@@ -151,6 +151,7 @@
 
 /* define bit use in NFC_ECC_ST */
 #define NFC_ECC_ERR(x)         BIT(x)
+#define NFC_ECC_ERR_MSK(nfc)   ((nfc)->caps->ecc_err_mask)
 
 /*
  * define bit use in NFC_REG_PAT_FOUND
@@ -178,6 +179,7 @@
  * @reg_spare_area:    Spare Area Register
  * @reg_pat_id:                Pattern ID Register
  * @reg_pat_found:     Data Pattern Status Register
+ * @ecc_err_mask:      ERR_ERR mask in NFC_ECC_ST register
  * @pat_found_mask:    ECC_PAT_FOUND mask in NFC_REG_PAT_FOUND register
  * @ecc_mode_mask:     ECC_MODE mask in NFC_ECC_CTL register
  * @random_en_mask:    RANDOM_EN mask in NFC_ECC_CTL register
@@ -191,6 +193,7 @@ struct sunxi_nfc_caps {
        unsigned int reg_pat_id;
        unsigned int reg_pat_found;
        unsigned int pat_found_mask;
+       unsigned int ecc_err_mask;
        unsigned int ecc_mode_mask;
        unsigned int random_en_mask;
 };
diff --git a/drivers/mtd/nand/raw/sunxi_nand_spl.c 
b/drivers/mtd/nand/raw/sunxi_nand_spl.c
index bb0dbd9977f5..544b46ce1d21 100644
--- a/drivers/mtd/nand/raw/sunxi_nand_spl.c
+++ b/drivers/mtd/nand/raw/sunxi_nand_spl.c
@@ -55,6 +55,9 @@ const uint16_t random_seed[128] = {
 __maybe_unused static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = {
        .has_ecc_block_512 = true,
        .reg_spare_area = NFC_REG_A10_SPARE_AREA,
+       .reg_pat_found = NFC_REG_ECC_ST,
+       .pat_found_mask = GENMASK(31, 16),
+       .ecc_err_mask = GENMASK(15, 0),
        .random_en_mask = BIT(9),
 };
 
@@ -202,7 +205,7 @@ static int nand_read_page(const struct nfc_config *conf, 
u32 offs,
        u16 rand_seed = 0;
        int oob_chunk_sz = ecc_bytes[conf->ecc_strength];
        int page = offs / conf->page_size;
-       u32 ecc_st;
+       u32 ecc_st, pattern_found;
        int i;
 
        if (offs % conf->page_size || len % conf->ecc_size ||
@@ -247,15 +250,21 @@ static int nand_read_page(const struct nfc_config *conf, 
u32 offs,
                ecc_st = readl(SUNXI_NFC_BASE + NFC_REG_ECC_ST);
 
                /* ECC error detected. */
-               if (ecc_st & 0xffff)
+               if (ecc_st & NFC_ECC_ERR_MSK(conf))
                        return -EIO;
 
                /*
-                * Return 1 if the first chunk is empty (needed for
-                * configuration detection).
+                * Return 1 if the first chunk is empty (all 00 or ff)
+                * (needed for configuration detection).
                 */
-               if (!i && (ecc_st & 0x10000))
-                       return 1;
+               if (!i) {
+                       pattern_found = readl(SUNXI_NFC_BASE +
+                                             conf->caps->reg_pat_found);
+                       pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(conf),
+                                                 pattern_found);
+                       if (pattern_found & NFC_ECC_PAT_FOUND(0))
+                               return 1;
+               }
 
                /* Retrieve the data from SRAM */
                memcpy_fromio(data,

Reply via email to