]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mtd: rawnand: sunxi: make the code mode self-explanatory
authorRichard Genoud <richard.genoud@bootlin.com>
Fri, 27 Mar 2026 14:05:05 +0000 (15:05 +0100)
committerAndre Przywara <andre.przywara@arm.com>
Thu, 30 Apr 2026 22:35:59 +0000 (00:35 +0200)
In sunxi_nfc_hw_ecc_{read,write}_chunk(), the ECC step was force to 0,
the reason is not trivial to get when reading the code.

The explanation is that, from the NAND flash controller perspective, we
are indeed at step 0 for user data length and ECC errors.

Just add a const value with an explanation to clarify things.

Signed-off-by: Richard Genoud <richard.genoud@bootlin.com>
Reviewed-By: Michael Trimarchi <michael@amarulasolutions.com>
Acked-by: Andre Przywara <andre.przywara@arm.com>
drivers/mtd/nand/raw/sunxi_nand.c
drivers/mtd/nand/raw/sunxi_nand_spl.c

index 91f7da2c5ce5ad4d2a083cd0956df2238ad3a91f..9fc9bc5e01987387048646fe9c33946175e13e94 100644 (file)
@@ -758,6 +758,8 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
        u32 status;
        u32 pattern_found;
        int ret;
+       /* From the controller point of view, we are at step 0 */
+       const int nfc_step = 0;
 
        if (*cur_off != data_off)
                nand->cmdfunc(mtd, NAND_CMD_RNDOUT, data_off, -1);
@@ -772,7 +774,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
                return ret;
 
        sunxi_nfc_reset_user_data_len(nfc);
-       sunxi_nfc_set_user_data_len(nfc, USER_DATA_SZ, 0);
+       sunxi_nfc_set_user_data_len(nfc, USER_DATA_SZ, nfc_step);
 
        sunxi_nfc_randomizer_enable(mtd);
        writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | NFC_ECC_OP,
@@ -787,7 +789,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
 
        pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found);
        pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found);
-       if (pattern_found & NFC_ECC_PAT_FOUND(0)) {
+       if (pattern_found & NFC_ECC_PAT_FOUND(nfc_step)) {
                u8 pattern = 0xff;
 
                if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID(nfc)) & 0x1)))
@@ -799,7 +801,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
                return 1;
        }
 
-       ret = NFC_ECC_ERR_CNT(0, readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, 0)));
+       ret = NFC_ECC_ERR_CNT(nfc_step, readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, nfc_step)));
 
        memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size);
 
@@ -807,7 +809,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
        sunxi_nfc_randomizer_read_buf(mtd, oob, ecc->bytes + USER_DATA_SZ, true, page);
 
        status = readl(nfc->regs + NFC_REG_ECC_ST);
-       if (status & NFC_ECC_ERR(0)) {
+       if (status & NFC_ECC_ERR(nfc_step)) {
                /*
                 * Re-read the data with the randomizer disabled to identify
                 * bitflips in erased pages.
@@ -830,7 +832,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
                 * Retrieve the corrected OOB bytes.
                 */
                sunxi_nfc_user_data_to_buf(readl(nfc->regs +
-                                                NFC_REG_USER_DATA(nfc, 0)),
+                                                NFC_REG_USER_DATA(nfc, nfc_step)),
                                           oob);
 
                /* De-randomize the Bad Block Marker. */
@@ -888,6 +890,8 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct mtd_info *mtd,
        struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
        struct nand_ecc_ctrl *ecc = &nand->ecc;
        int ret;
+       /* From the controller point of view, we are at step 0 */
+       const int nfc_step = 0;
 
        if (data_off != *cur_off)
                nand->cmdfunc(mtd, NAND_CMD_RNDIN, data_off, -1);
@@ -901,10 +905,10 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct mtd_info *mtd,
                memcpy(user_data, oob, USER_DATA_SZ);
                sunxi_nfc_randomize_bbm(mtd, page, user_data);
                writel(sunxi_nfc_buf_to_user_data(user_data),
-                      nfc->regs + NFC_REG_USER_DATA(nfc, 0));
+                      nfc->regs + NFC_REG_USER_DATA(nfc, nfc_step));
        } else {
                writel(sunxi_nfc_buf_to_user_data(oob),
-                      nfc->regs + NFC_REG_USER_DATA(nfc, 0));
+                      nfc->regs + NFC_REG_USER_DATA(nfc, nfc_step));
        }
 
        if (data_off + ecc->size != oob_off)
@@ -915,7 +919,7 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct mtd_info *mtd,
                return ret;
 
        sunxi_nfc_reset_user_data_len(nfc);
-       sunxi_nfc_set_user_data_len(nfc, USER_DATA_SZ, 0);
+       sunxi_nfc_set_user_data_len(nfc, USER_DATA_SZ, nfc_step);
 
        sunxi_nfc_randomizer_enable(mtd);
        writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD |
index 3a5271b49c36ec0c6c79ce8b8090dbfaed7ae044..0d1f060cc425fc50a97c264ff750cc71fcaf8890 100644 (file)
@@ -302,6 +302,8 @@ static int nand_read_page(const struct nfc_config *conf, u32 offs,
        int page = offs / conf->page_size;
        u32 ecc_st, pattern_found;
        int i;
+       /* From the controller point of view, we are at step 0 */
+       const int nfc_step = 0;
 
        if (offs % conf->page_size || len % conf->ecc_size ||
            len > conf->page_size || len < 0)
@@ -343,7 +345,7 @@ static int nand_read_page(const struct nfc_config *conf, u32 offs,
                nand_change_column(oob_off);
 
                sunxi_nfc_reset_user_data_len(conf);
-               sunxi_nfc_set_user_data_len(conf, USER_DATA_SZ, 0);
+               sunxi_nfc_set_user_data_len(conf, USER_DATA_SZ, nfc_step);
 
                nand_exec_cmd(NFC_DATA_TRANS | NFC_ECC_OP);
                /* Get the ECC status */
@@ -361,7 +363,7 @@ static int nand_read_page(const struct nfc_config *conf, u32 offs,
                        pattern_found = readl_nfc(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))
+                       if (pattern_found & NFC_ECC_PAT_FOUND(nfc_step))
                                return 1;
                }