--- zzzz-none-000/linux-4.1.52/drivers/mtd/nand/nand_base.c 2018-05-28 02:26:45.000000000 +0000 +++ bcm63-7530ax-731/linux-4.1.52/drivers/mtd/nand/nand_base.c 2022-03-02 11:37:13.000000000 +0000 @@ -48,6 +48,9 @@ #include #include #include +#if defined(CONFIG_BCM_KF_MTD_BCMNAND) +#include +#endif /* Define default oob placement schemes for large and small page devices */ static struct nand_ecclayout nand_oob_8 = { @@ -3634,7 +3637,10 @@ chip->ecc_step_ds = NAND_ECC_STEP(type); chip->onfi_timing_mode_default = type->onfi_timing_mode_default; - +#if defined(CONFIG_BCM_KF_MTD_BCMNAND) + chip->timing_1 = type->timing_1; + chip->timing_2 = type->timing_2; +#endif *busw = type->options & NAND_BUSWIDTH_16; if (!mtd->name) @@ -3809,6 +3815,41 @@ return type; } +#if defined(CONFIG_BCM_KF_MTD_BCMNAND) +static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, + struct device_node *dn) +{ + int ecc_mode, ecc_strength, ecc_step; + + if (of_get_nand_bus_width(dn) == 16) + chip->options |= NAND_BUSWIDTH_16; + + if (of_get_nand_on_flash_bbt(dn)) + chip->bbt_options |= NAND_BBT_USE_FLASH; + + ecc_mode = of_get_nand_ecc_mode(dn); + ecc_strength = of_get_nand_ecc_strength(dn); + ecc_step = of_get_nand_ecc_step_size(dn); + + if ((ecc_step >= 0 && !(ecc_strength >= 0)) || + (!(ecc_step >= 0) && ecc_strength >= 0)) { + pr_err("must set both strength and step size in DT\n"); + return -EINVAL; + } + + if (ecc_mode >= 0) + chip->ecc.mode = ecc_mode; + + if (ecc_strength >= 0) + chip->ecc.strength = ecc_strength; + + if (ecc_step > 0) + chip->ecc.size = ecc_step; + + return 0; +} +#endif + /** * nand_scan_ident - [NAND Interface] Scan for the NAND device * @mtd: MTD device structure @@ -3826,7 +3867,15 @@ int i, nand_maf_id, nand_dev_id; struct nand_chip *chip = mtd->priv; struct nand_flash_dev *type; +#if defined(CONFIG_BCM_KF_MTD_BCMNAND) + int ret; + if (chip->dn) { + ret = nand_dt_init(mtd, chip, chip->dn); + if (ret) + return ret; + } +#endif /* Set the default functions */ nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16); @@ -4173,6 +4222,10 @@ mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH; mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM : MTD_CAP_NANDFLASH; +#if defined(CONFIG_BCM_KF_MTD_BCMNAND) + if (chip->options & NAND_PAGE_NOP1) + mtd->flags |= MTD_NAND_NOP1; +#endif mtd->_erase = nand_erase; mtd->_point = NULL; mtd->_unpoint = NULL;