#include "atmel_nand_ecc.h"    /* Hardware ECC registers */
 #include "atmel_nand_nfc.h"    /* Nand Flash Controller definition */
 
+struct atmel_nand_caps {
+       bool pmecc_correct_erase_page;
+};
+
 /* oob layout for large page size
  * bad block info is on bytes 0 and 1
  * the bytes have to be consecutives to avoid
 
        struct atmel_nfc        *nfc;
 
+       struct atmel_nand_caps  *caps;
        bool                    has_pmecc;
        u8                      pmecc_corr_cap;
        u16                     pmecc_sector_size;
        uint8_t *buf_pos;
        int max_bitflips = 0;
 
+       /* If can correct bitfilps from erased page, do the normal check */
+       if (host->caps->pmecc_correct_erase_page)
+               goto normal_check;
+
        for (i = 0; i < nand_chip->ecc.total; i++)
                if (ecc[i] != 0xff)
                        goto normal_check;
                ecc_writel(host->ecc, CR, ATMEL_ECC_RST);
 }
 
+static const struct of_device_id atmel_nand_dt_ids[];
+
 static int atmel_of_init_port(struct atmel_nand_host *host,
                              struct device_node *np)
 {
        struct atmel_nand_data *board = &host->board;
        enum of_gpio_flags flags = 0;
 
+       host->caps = (struct atmel_nand_caps *)
+               of_match_device(atmel_nand_dt_ids, host->dev)->data;
+
        if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
                if (val >= 32) {
                        dev_err(host->dev, "invalid addr-offset %u\n", val);
        return 0;
 }
 
+static struct atmel_nand_caps at91rm9200_caps = {
+       .pmecc_correct_erase_page = false,
+};
+
+static struct atmel_nand_caps sama5d4_caps = {
+       .pmecc_correct_erase_page = true,
+};
+
 static const struct of_device_id atmel_nand_dt_ids[] = {
-       { .compatible = "atmel,at91rm9200-nand" },
+       { .compatible = "atmel,at91rm9200-nand", .data = &at91rm9200_caps },
+       { .compatible = "atmel,sama5d4-nand", .data = &sama5d4_caps },
        { /* sentinel */ }
 };