From: Richard Genoud Date: Fri, 23 Jan 2026 11:44:52 +0000 (+0100) Subject: mtd: rawnand: sunxi_spl: use NFC_ECC_ERR_MSK and NFC_ECC_PAT_FOUND X-Git-Tag: v2026.04-rc2~24^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50b459973c3e747d9e5e4b38acb0702724fd8e68;p=thirdparty%2Fu-boot.git mtd: rawnand: sunxi_spl: use NFC_ECC_ERR_MSK and NFC_ECC_PAT_FOUND 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 Signed-off-by: Michael Trimarchi --- diff --git a/drivers/mtd/nand/raw/sunxi_nand.h b/drivers/mtd/nand/raw/sunxi_nand.h index b5a3800d33d..25d18eaa0b8 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.h +++ b/drivers/mtd/nand/raw/sunxi_nand.h @@ -150,6 +150,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 @@ -177,6 +178,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 @@ -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; }; diff --git a/drivers/mtd/nand/raw/sunxi_nand_spl.c b/drivers/mtd/nand/raw/sunxi_nand_spl.c index 7f9ee14ffc3..da94285e6b7 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), }; @@ -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,