MTK NAND Controller has the ability to check whether read data are mostly 0xff by comparing zero bit count of read data with empty threshold automatically. But now we never set this threshold and always make it be default value which is 10. This patch fixes this problem by setting empty threshold as the product of read sector count and ECC strength. Fixes: 1d6b1e464950 ("mtd: mediatek: driver for MTK Smart Device") Signed-off-by: Xiaolei Li <xiaolei.li@xxxxxxxxxxxx> --- drivers/mtd/nand/raw/mtk_nand.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c index 48759af5c058..b56965328771 100644 --- a/drivers/mtd/nand/raw/mtk_nand.c +++ b/drivers/mtd/nand/raw/mtk_nand.c @@ -94,6 +94,7 @@ #define NFI_MASTER_STA (0x224) #define MASTER_STA_MASK (0x0FFF) #define NFI_EMPTY_THRESH (0x23C) +#define EMPTY_THRESH_MASK GENMASK(7, 0) #define MTK_NAME "mtk-nand" #define KB(x) ((x) * 1024UL) @@ -947,6 +948,14 @@ static int mtk_nfc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, return -EINVAL; } + /** + * Setup empty threshold as the product of sector count + * and ECC strength + */ + reg = sectors * chip->ecc.strength; + reg = min_t(unsigned int, reg, EMPTY_THRESH_MASK); + nfi_writel(nfc, reg, NFI_EMPTY_THRESH); + reg = nfi_readw(nfc, NFI_CNFG); reg |= CNFG_READ_EN | CNFG_DMA_BURST_EN | CNFG_AHB; if (!raw) { -- 2.18.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/