Merge commit 'ac30d240dbb520d0980f0687630feb702a14f51a' of https://source.denx.de/u-boot/custodians/u-boot-nand-flash into next

Re-sync again on some linux part, add some fixes for fsl_elbc from
Pali and switch
imx8mn bsh to use nand base ident

For nand subsystem tested on:
 - imx8mn  Macronix MX30LF4G18AC
 - P2020 based board Turris 1.1 for fsl_elbc
This commit is contained in:
Tom Rini 2022-08-24 17:30:29 -04:00
commit a2aa7d6550
8 changed files with 55 additions and 39 deletions

View File

@ -45,6 +45,8 @@ CONFIG_SPL_DMA=y
CONFIG_SPL_I2C=y
CONFIG_SPL_MTD_SUPPORT=y
CONFIG_SPL_NAND_SUPPORT=y
CONFIG_SPL_NAND_BASE=y
CONFIG_SPL_NAND_IDENT=y
CONFIG_SPL_POWER=y
CONFIG_SPL_WATCHDOG=y
CONFIG_SYS_MAXARGS=64

View File

@ -732,7 +732,6 @@ static int fsl_elbc_chip_init(int devnum, u8 *addr, struct udevice *dev)
nand->bbt_md = &bbt_mirror_descr;
/* set up nand options */
nand->options = NAND_NO_SUBPAGE_WRITE;
nand->bbt_options = NAND_BBT_USE_FLASH;
nand->controller = &elbc_ctrl->controller;
@ -839,7 +838,7 @@ void board_nand_init(void)
static int fsl_elbc_nand_probe(struct udevice *dev)
{
return fsl_elbc_chip_init(0, (void *)dev_read_addr(dev), dev);
return fsl_elbc_chip_init(0, dev_read_addr_ptr(dev), dev);
}
static const struct udevice_id fsl_elbc_nand_dt_ids[] = {

View File

@ -1184,13 +1184,12 @@ int mt7621_nfc_spl_post_init(struct mt7621_nfc *nfc)
{
struct nand_chip *nand = &nfc->nand;
int nand_maf_id, nand_dev_id;
struct nand_flash_dev *type;
int ret;
type = nand_get_flash_type(nand, &nand_maf_id,
&nand_dev_id, NULL);
ret = nand_detect(nand, &nand_maf_id, &nand_dev_id, NULL);
if (IS_ERR(type))
return PTR_ERR(type);
if (ret)
return ret;
nand->numchips = 1;
nand->mtd.size = nand->chipsize;

View File

@ -81,13 +81,13 @@ static int mxs_flash_full_ident(struct mtd_info *mtd)
{
int nand_maf_id, nand_dev_id;
struct nand_chip *chip = mtd_to_nand(mtd);
struct nand_flash_dev *type;
int ret;
type = nand_get_flash_type(mtd, chip, &nand_maf_id, &nand_dev_id, NULL);
ret = nand_detect(chip, &nand_maf_id, &nand_dev_id, NULL);
if (IS_ERR(type)) {
if (ret) {
chip->select_chip(mtd, -1);
return PTR_ERR(type);
return ret;
}
return 0;

View File

@ -4261,7 +4261,7 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip,
* Returns a nand_manufacturer_desc object if the manufacturer is defined
* in the NAND manufacturers database, NULL otherwise.
*/
static const struct nand_manufacturers *nand_get_manufacturer_desc(u8 id)
static const struct nand_manufacturer *nand_get_manufacturer_desc(u8 id)
{
int i;
@ -4276,12 +4276,11 @@ static const struct nand_manufacturers *nand_get_manufacturer_desc(u8 id)
/*
* Get the flash and manufacturer id and lookup if the type is supported.
*/
struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id,
int *dev_id,
struct nand_flash_dev *type)
int nand_detect(struct nand_chip *chip, int *maf_id,
int *dev_id, struct nand_flash_dev *type)
{
struct mtd_info *mtd = &chip->mtd;
const struct nand_manufacturers *manufacturer_desc;
const struct nand_manufacturer *manufacturer_desc;
int busw, ret;
u8 *id_data = chip->id.data;
@ -4291,7 +4290,7 @@ struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id,
*/
ret = nand_reset(chip, 0);
if (ret)
return ERR_PTR(ret);
return ret;
/* Select the device */
chip->select_chip(mtd, 0);
@ -4299,7 +4298,7 @@ struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id,
/* Send the command for reading device ID */
ret = nand_readid_op(chip, 0, id_data, 2);
if (ret)
return ERR_PTR(ret);
return ret;
/* Read manufacturer and device IDs */
*maf_id = id_data[0];
@ -4315,12 +4314,12 @@ struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id,
/* Read entire ID string */
ret = nand_readid_op(chip, 0, id_data, 8);
if (ret)
return ERR_PTR(ret);
return ret;
if (id_data[0] != *maf_id || id_data[1] != *dev_id) {
pr_info("second ID read did not match %02x,%02x against %02x,%02x\n",
*maf_id, *dev_id, id_data[0], id_data[1]);
return ERR_PTR(-ENODEV);
return -ENODEV;
}
chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data));
@ -4368,7 +4367,7 @@ struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id,
}
if (!type->name)
return ERR_PTR(-ENODEV);
return -ENODEV;
if (!mtd->name)
mtd->name = type->name;
@ -4401,7 +4400,7 @@ ident_done:
pr_warn("bus width %d instead %d bit\n",
(chip->options & NAND_BUSWIDTH_16) ? 16 : 8,
busw ? 16 : 8);
return ERR_PTR(-EINVAL);
return -EINVAL;
}
nand_decode_bbm_options(mtd, chip);
@ -4432,7 +4431,7 @@ ident_done:
ret = nand_manufacturer_init(chip);
if (ret)
return ERR_PTR(ret);
return ret;
pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n",
*maf_id, *dev_id);
@ -4460,9 +4459,9 @@ ident_done:
pr_info("%d MiB, %s, erase size: %d KiB, page size: %d, OOB size: %d\n",
(int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC",
mtd->erasesize >> 10, mtd->writesize, mtd->oobsize);
return type;
return 0;
}
EXPORT_SYMBOL(nand_get_flash_type);
EXPORT_SYMBOL(nand_detect);
#if CONFIG_IS_ENABLED(OF_CONTROL)
@ -4547,7 +4546,6 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
{
int i, nand_maf_id, nand_dev_id;
struct nand_chip *chip = mtd_to_nand(mtd);
struct nand_flash_dev *type;
int ret;
if (ofnode_valid(chip->flash_node)) {
@ -4560,14 +4558,13 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);
/* Read the flash type */
type = nand_get_flash_type(chip, &nand_maf_id,
&nand_dev_id, table);
ret = nand_detect(chip, &nand_maf_id, &nand_dev_id, table);
if (IS_ERR(type)) {
if (ret) {
if (!(chip->options & NAND_SCAN_SILENT_NODEV))
pr_warn("No NAND device found\n");
chip->select_chip(mtd, -1);
return PTR_ERR(type);
return ret;
}
/* Initialize the ->data_interface field. */
@ -4593,7 +4590,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
for (i = 1; i < maxchips; i++) {
u8 id[2];
/* See comment in nand_get_flash_type for reset */
/* See comment in nand_detect for reset */
nand_reset(chip, i);
chip->select_chip(mtd, i);

View File

@ -177,7 +177,7 @@ struct nand_flash_dev nand_flash_ids[] = {
};
/* Manufacturer IDs */
struct nand_manufacturers nand_manuf_ids[] = {
struct nand_manufacturer nand_manuf_ids[] = {
{NAND_MFR_TOSHIBA, "Toshiba", &toshiba_nand_manuf_ops},
{NAND_MFR_SAMSUNG, "Samsung", &samsung_nand_manuf_ops},
{NAND_MFR_FUJITSU, "Fujitsu"},

View File

@ -64,6 +64,26 @@ static void samsung_nand_decode_id(struct nand_chip *chip)
extid >>= 2;
mtd->erasesize = (128 * 1024) <<
(((extid >> 1) & 0x04) | (extid & 0x03));
/* Extract ECC requirements from 5th id byte*/
extid = (chip->id.data[4] >> 4) & 0x07;
if (extid < 5) {
chip->ecc_step_ds = 512;
chip->ecc_strength_ds = 1 << extid;
} else {
chip->ecc_step_ds = 1024;
switch (extid) {
case 5:
chip->ecc_strength_ds = 24;
break;
case 6:
chip->ecc_strength_ds = 40;
break;
case 7:
chip->ecc_strength_ds = 60;
break;
}
}
} else {
nand_decode_ext_id(chip);
}

View File

@ -29,9 +29,8 @@ struct nand_flash_dev;
struct device_node;
/* Get the flash and manufacturer id and lookup if the type is supported. */
struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip,
int *maf_id, int *dev_id,
struct nand_flash_dev *type);
int nand_detect(struct nand_chip *chip, int *maf_id, int *dev_id,
struct nand_flash_dev *type);
/* Scan and identify a NAND device */
int nand_scan(struct mtd_info *mtd, int max_chips);
@ -976,7 +975,7 @@ struct nand_chip {
void *priv;
struct {
const struct nand_manufacturers *desc;
const struct nand_manufacturer *desc;
void *priv;
} manufacturer;
};
@ -1124,19 +1123,19 @@ struct nand_flash_dev {
};
/**
* struct nand_manufacturers - NAND Flash Manufacturer ID Structure
* struct nand_manufacturer - NAND Flash Manufacturer ID Structure
* @name: Manufacturer name
* @id: manufacturer ID code of device.
* @ops: manufacturer operations
*/
struct nand_manufacturers {
struct nand_manufacturer {
int id;
char *name;
const struct nand_manufacturer_ops *ops;
};
extern struct nand_flash_dev nand_flash_ids[];
extern struct nand_manufacturers nand_manuf_ids[];
extern struct nand_manufacturer nand_manuf_ids[];
extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops;
extern const struct nand_manufacturer_ops samsung_nand_manuf_ops;