Introduce has_ecc_block_512 capability The H616 controller can't handle 512 bytes ECC block size. The NFC_ECC_BLOCK_512 bit disappeared in H6, and NDFC_RANDOM_EN took its place.
So, add has_ecc_block_512 capability to only set this bit on SoC having it. On the way, let's drop NFC_ECC_BLOCK_SIZE_MSK which was just a mask for the very same bit. No functional change. Signed-off-by: Richard Genoud <[email protected]> --- drivers/mtd/nand/raw/sunxi_nand.c | 14 +++++++++++--- drivers/mtd/nand/raw/sunxi_nand.h | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 07026ced0af6..d14a12b6662c 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -659,11 +659,12 @@ static void sunxi_nfc_hw_ecc_enable(struct mtd_info *mtd) u32 ecc_ctl; ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL); - ecc_ctl &= ~(NFC_ECC_MODE_MSK | NFC_ECC_PIPELINE | - NFC_ECC_BLOCK_SIZE_MSK); + ecc_ctl &= ~(NFC_ECC_MODE_MSK | NFC_ECC_PIPELINE); + if (nfc->caps->has_ecc_block_512) + ecc_ctl &= ~NFC_ECC_BLOCK_512; ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE(data->mode) | NFC_ECC_EXCEPTION; - if (nand->ecc.size == 512) + if (nand->ecc.size == 512 && nfc->caps->has_ecc_block_512) ecc_ctl |= NFC_ECC_BLOCK_512; writel(ecc_ctl, nfc->regs + NFC_REG_ECC_CTL); @@ -1453,6 +1454,8 @@ static void sunxi_nand_ecc_cleanup(struct nand_ecc_ctrl *ecc) static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc) { struct nand_chip *nand = mtd_to_nand(mtd); + struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); + struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); int ret; if (!ecc->size) { @@ -1463,6 +1466,10 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc) if (!ecc->size || !ecc->strength) return -EINVAL; + /* If 512B ECC is not supported, switch to 1024 */ + if (ecc->size == 512 && !nfc->caps->has_ecc_block_512) + ecc->size = 1024; + switch (ecc->mode) { case NAND_ECC_SOFT_BCH: break; @@ -1714,6 +1721,7 @@ static int sunxi_nand_probe(struct udevice *dev) } static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = { + .has_ecc_block_512 = true, .nstrengths = 9, .reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT, .reg_user_data = NFC_REG_A10_USER_DATA, diff --git a/drivers/mtd/nand/raw/sunxi_nand.h b/drivers/mtd/nand/raw/sunxi_nand.h index 35079d37bb1f..b4a05733c810 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.h +++ b/drivers/mtd/nand/raw/sunxi_nand.h @@ -138,7 +138,6 @@ #define NFC_ECC_EN BIT(0) #define NFC_ECC_PIPELINE BIT(3) #define NFC_ECC_EXCEPTION BIT(4) -#define NFC_ECC_BLOCK_SIZE_MSK BIT(5) #define NFC_ECC_BLOCK_512 BIT(5) #define NFC_RANDOM_EN BIT(9) #define NFC_RANDOM_DIRECTION BIT(10) @@ -169,6 +168,7 @@ * NAND Controller capabilities structure: stores NAND controller capabilities * for distinction between compatible strings. * + * @has_ecc_block_512: If the ECC can handle 512B or only 1024B chuncks * @nstrengths: Number of element of ECC strengths array * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register @@ -176,6 +176,7 @@ * @pat_found_mask: ECC_PAT_FOUND mask in NFC_REG_PAT_FOUND register */ struct sunxi_nfc_caps { + bool has_ecc_block_512; unsigned int nstrengths; unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; -- 2.47.3

