summaryrefslogtreecommitdiff
path: root/drivers/mtd
diff options
context:
space:
mode:
authorMugunthan V N <mugunthanvnm@ti.com>2017-06-27 00:12:51 (GMT)
committerTom Rini <trini@konsulko.com>2017-07-12 02:41:44 (GMT)
commitad92dff28c26b127391692e4d675a463ee4a4215 (patch)
treece21b53edc58c4fe55c24cac4e11fcef6bb94927 /drivers/mtd
parent8d3a25685e4aac7070365a2b3c53c2c81b27930f (diff)
downloadu-boot-fsl-qoriq-ad92dff28c26b127391692e4d675a463ee4a4215.tar.xz
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')
-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;