]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mtd: rawnand: sunxi_spl: use NFC_ECC_ERR_MSK and NFC_ECC_PAT_FOUND
authorRichard Genoud <richard.genoud@bootlin.com>
Fri, 23 Jan 2026 11:44:52 +0000 (12:44 +0100)
committerMichael Trimarchi <michael@amarulasolutions.com>
Tue, 3 Feb 2026 20:45:03 +0000 (21:45 +0100)
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 <richard.genoud@bootlin.com>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
drivers/mtd/nand/raw/sunxi_nand.h
drivers/mtd/nand/raw/sunxi_nand_spl.c

index b5a3800d33d25902fd32b0944978907786e560ff..25d18eaa0b81164fad9a73b49e9fdd4d578c5473 100644 (file)
 
 /* 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
  * @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
@@ -190,6 +192,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;
 };
index 7f9ee14ffc3c235005412ddb3ea36f3cae84ead7..da94285e6b72f38f2e9ff8bc3e5cd326f9c58815 100644 (file)
@@ -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),
 };
 
@@ -211,7 +214,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 ||
@@ -256,15 +259,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 */
                nand_readlcpy((u32 *)data,