diff options
author | Mugunthan V N <mugunthanvnm@ti.com> | 2017-06-26 19:12:51 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-07-11 22:41:44 -0400 |
commit | ad92dff28c26b127391692e4d675a463ee4a4215 (patch) | |
tree | ce21b53edc58c4fe55c24cac4e11fcef6bb94927 /drivers/mtd/nand/nand.c | |
parent | 8d3a25685e4aac7070365a2b3c53c2c81b27930f (diff) | |
download | u-boot-ad92dff28c26b127391692e4d675a463ee4a4215.tar.gz |
cmd: nand: abstract global variable usage for dm conversion
nand_info is used all over the file so abstract it with
get_nand_dev_by_index() which will help for DM conversion.
Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Diffstat (limited to 'drivers/mtd/nand/nand.c')
-rw-r--r-- | drivers/mtd/nand/nand.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c index 168bac6055..fd9a3be354 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 |