/* 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
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;
};
__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),
};
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 ||
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,