summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/nand/nand.c21
-rw-r--r--drivers/mtd/nand/omap_gpmc.c7
2 files changed, 17 insertions, 11 deletions
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c
index 168bac6..fd9a3be 100644
--- a/drivers/mtd/nand/nand.c
+++ b/drivers/mtd/nand/nand.c
@@ -19,7 +19,6 @@ DECLARE_GLOBAL_DATA_PTR;
int nand_curr_device = -1;
-
struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
#ifndef CONFIG_SYS_NAND_SELF_INIT
@@ -31,12 +30,21 @@ static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];
static unsigned long total_nand_size; /* in kiB */
+struct mtd_info *get_nand_dev_by_index(int dev)
+{
+ if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev] ||
+ !nand_info[dev]->name)
+ return NULL;
+
+ return nand_info[dev];
+}
+
int nand_mtd_to_devnum(struct mtd_info *mtd)
{
int i;
- for (i = 0; i < ARRAY_SIZE(nand_info); i++) {
- if (mtd && nand_info[i] == mtd)
+ for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
+ if (mtd && get_nand_dev_by_index(i) == mtd)
return i;
}
@@ -101,8 +109,9 @@ static void create_mtd_concat(void)
int i;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
- if (nand_info[i] != NULL) {
- nand_info_list[nand_devices_found] = nand_info[i];
+ struct mtd_info *mtd = get_nand_dev_by_index(i);
+ if (mtd != NULL) {
+ nand_info_list[nand_devices_found] = mtd;
nand_devices_found++;
}
}
@@ -161,7 +170,7 @@ void nand_init(void)
/*
* Select the chip in the board/cpu specific driver
*/
- board_nand_select_device(mtd_to_nand(nand_info[nand_curr_device]),
+ board_nand_select_device(mtd_to_nand(get_nand_dev_by_index(nand_curr_device)),
nand_curr_device);
#endif
diff --git a/drivers/mtd/nand/omap_gpmc.c b/drivers/mtd/nand/omap_gpmc.c
index f4f0de3..b540bc3 100644
--- a/drivers/mtd/nand/omap_gpmc.c
+++ b/drivers/mtd/nand/omap_gpmc.c
@@ -894,17 +894,14 @@ static int omap_select_ecc_scheme(struct nand_chip *nand,
int __maybe_unused omap_nand_switch_ecc(uint32_t hardware, uint32_t eccstrength)
{
struct nand_chip *nand;
- struct mtd_info *mtd;
+ struct mtd_info *mtd = get_nand_dev_by_index(nand_curr_device);
int err = 0;
- if (nand_curr_device < 0 ||
- nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
- !nand_info[nand_curr_device]) {
+ if (!mtd) {
printf("nand: error: no NAND devices found\n");
return -ENODEV;
}
- mtd = nand_info[nand_curr_device];
nand = mtd_to_nand(mtd);
nand->options |= NAND_OWN_BUFFERS;
nand->options &= ~NAND_SUBPAGE_READ;