mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

This patch sync with David's patch on Linux for handling nand_scan_ident.

	commit 5e81e88a4c140586d9212999cea683bcd66a15c6
	Author: David Woodhouse <David.Woodhouse@intel.com>
	Date:   Fri Feb 26 18:32:56 2010 +0000

	mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

	Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

Signed-off-by: Lei Wen <leiwen@marvell.com>
This commit is contained in:
Lei Wen 2011-01-06 09:48:18 +08:00 committed by Scott Wood
parent 47fc18f1e7
commit 245eb90091
3 changed files with 19 additions and 16 deletions

View File

@ -296,7 +296,7 @@ int board_nand_init(struct nand_chip *nand)
mtd->priv = nand; mtd->priv = nand;
/* Detect NAND chips */ /* Detect NAND chips */
if (nand_scan_ident(mtd, 1)) { if (nand_scan_ident(mtd, 1, NULL)) {
printk(KERN_WARNING "NAND Flash not found !\n"); printk(KERN_WARNING "NAND Flash not found !\n");
return -ENXIO; return -ENXIO;
} }

View File

@ -2414,10 +2414,10 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
*/ */
static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
struct nand_chip *chip, struct nand_chip *chip,
int busw, int *maf_id) int busw, int *maf_id,
const struct nand_flash_dev *type)
{ {
const struct nand_flash_dev *type = NULL; int dev_id, maf_idx;
int i, dev_id, maf_idx;
int tmp_id, tmp_manf; int tmp_id, tmp_manf;
/* Select the device */ /* Select the device */
@ -2456,15 +2456,14 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
} }
/* Lookup the flash id */ if (!type)
for (i = 0; nand_flash_ids[i].name != NULL; i++) { type = nand_flash_ids;
if (dev_id == nand_flash_ids[i].id) {
type = &nand_flash_ids[i];
break;
}
}
if (!type) { for (; type->name != NULL; type++)
if (dev_id == type->id)
break;
if (!type->name) {
/* supress warning if there is no nand */ /* supress warning if there is no nand */
if (*maf_id != 0x00 && *maf_id != 0xff && if (*maf_id != 0x00 && *maf_id != 0xff &&
dev_id != 0x00 && dev_id != 0xff) dev_id != 0x00 && dev_id != 0xff)
@ -2580,13 +2579,15 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
* nand_scan_ident - [NAND Interface] Scan for the NAND device * nand_scan_ident - [NAND Interface] Scan for the NAND device
* @mtd: MTD device structure * @mtd: MTD device structure
* @maxchips: Number of chips to scan for * @maxchips: Number of chips to scan for
* @table: Alternative NAND ID table
* *
* This is the first phase of the normal nand_scan() function. It * This is the first phase of the normal nand_scan() function. It
* reads the flash ID and sets up MTD fields accordingly. * reads the flash ID and sets up MTD fields accordingly.
* *
* The mtd->owner field must be set to the module of the caller. * The mtd->owner field must be set to the module of the caller.
*/ */
int nand_scan_ident(struct mtd_info *mtd, int maxchips) int nand_scan_ident(struct mtd_info *mtd, int maxchips,
const struct nand_flash_dev *table)
{ {
int i, busw, nand_maf_id; int i, busw, nand_maf_id;
struct nand_chip *chip = mtd->priv; struct nand_chip *chip = mtd->priv;
@ -2598,7 +2599,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips)
nand_set_defaults(chip, busw); nand_set_defaults(chip, busw);
/* Read the flash type */ /* Read the flash type */
type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id); type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id, table);
if (IS_ERR(type)) { if (IS_ERR(type)) {
#ifndef CONFIG_SYS_NAND_QUIET_TEST #ifndef CONFIG_SYS_NAND_QUIET_TEST
@ -2869,7 +2870,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
{ {
int ret; int ret;
ret = nand_scan_ident(mtd, maxchips); ret = nand_scan_ident(mtd, maxchips, NULL);
if (!ret) if (!ret)
ret = nand_scan_tail(mtd); ret = nand_scan_tail(mtd);
return ret; return ret;

View File

@ -33,11 +33,13 @@
struct mtd_info; struct mtd_info;
struct nand_flash_dev;
/* Scan and identify a NAND device */ /* Scan and identify a NAND device */
extern int nand_scan (struct mtd_info *mtd, int max_chips); extern int nand_scan (struct mtd_info *mtd, int max_chips);
/* Separate phases of nand_scan(), allowing board driver to intervene /* Separate phases of nand_scan(), allowing board driver to intervene
* and override command or ECC setup according to flash type */ * and override command or ECC setup according to flash type */
extern int nand_scan_ident(struct mtd_info *mtd, int max_chips); extern int nand_scan_ident(struct mtd_info *mtd, int max_chips,
const struct nand_flash_dev *table);
extern int nand_scan_tail(struct mtd_info *mtd); extern int nand_scan_tail(struct mtd_info *mtd);
/* Free resources held by the NAND device */ /* Free resources held by the NAND device */