All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm
@ 2017-01-31 21:37 Grygorii Strashko
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND Grygorii Strashko
                   ` (15 more replies)
  0 siblings, 16 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

This patch seires adds nand uclass driver and enables omap_gpmc to
adopt driver model. This has been tested on AM335x GP EVM and
AM437x GP EVM.

As preparation for introducing nand uclass driver the new API
get_nand_dev_by_index() was added to avoid direct acces to nand_info array and
u-boot core files were updated to use it.

Patches can be found at:
git at git.ti.com:~gragst/ti-u-boot/gragsts-ti-u-boot.git dm-nand-v2

Test case1:
 mmc rescan
 fatload mmc 0 ${loadaddr} MLO1
 nand erase.part <part>
 nand write ${loadaddr} <part>
 nand read 0x84000000 0 ${filesize}
 cmp ${loadaddr} 0x84000000 ${filesize}

Test case2:
 nand read $loadaddr NAND.kernel
 nand read $fdtaddr NAND.u-boot-spl-os
 run args_mmc
 bootz ${loadaddr} - ${fdtaddr}

Changes in v2:
 - series rebased on top of u-boot master
 - added more patches to convert u-boot core files to use get_nand_dev_by_index()
 - nand uclass driver was simplified thanks to commits
   17cb4b8 mtd: nand: Add+use mtd_to/from_nand and nand_get/set_controller_data
   b616d9b nand: Embed mtd_info in struct nand_chip

link on v1:
 http://lists.denx.de/pipermail/u-boot/2016-April/250197.html

Grygorii Strashko (8):
  cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND
  common: env_nand: use get_nand_dev_by_index()
  dfu: dfu_nand: use get_nand_dev_by_index()
  cmd: bootm: use get_nand_dev_by_index()
  cmd: jffs2: use get_nand_dev_by_index()
  common: use get_nand_dev_by_index()
  fs: use get_nand_dev_by_index()
  cmd: nand: remove direct access to struct mtd_info->priv

Mugunthan V N (7):
  cmd: nand: abstract global variable usage for dm conversion
  drivers: nand: implement a NAND uclass
  drivers: nand: omap_gpmc: convert driver to adopt driver model
  am43xx_evm: nand: do not define DM_NAND for spl
  defconfig: am43xx_evm: enable NAND driver model
  am335x_evm: nand: do not define DM_NAND for spl
  defconfig: am335x_evm: enable NAND driver model

 cmd/bootm.c                    |   6 +-
 cmd/jffs2.c                    |   7 +-
 cmd/nand.c                     |  69 ++++++++------
 common/env_nand.c              |  33 ++++---
 common/fb_nand.c               |   2 +-
 common/splash_source.c         |   5 +-
 configs/am335x_evm_defconfig   |   1 +
 configs/am43xx_evm_defconfig   |   1 +
 drivers/dfu/dfu_nand.c         |  12 +--
 drivers/mtd/nand/Kconfig       |  10 ++
 drivers/mtd/nand/Makefile      |   2 +
 drivers/mtd/nand/nand-uclass.c |  38 ++++++++
 drivers/mtd/nand/nand.c        |  40 ++++++--
 drivers/mtd/nand/omap_gpmc.c   | 212 ++++++++++++++++++++++++++++++++++++++++-
 fs/jffs2/jffs2_1pass.c         |   9 +-
 fs/jffs2/jffs2_nand_1pass.c    |   6 +-
 fs/yaffs2/yaffs_uboot_glue.c   |   8 +-
 include/configs/am335x_evm.h   |   1 +
 include/configs/am43xx_evm.h   |   1 +
 include/dm/uclass-id.h         |   1 +
 include/nand.h                 |   9 ++
 21 files changed, 397 insertions(+), 76 deletions(-)
 create mode 100644 drivers/mtd/nand/nand-uclass.c

-- 
2.10.1.dirty

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:56   ` Tom Rini
  2017-02-09  3:03   ` [U-Boot] [U-Boot, v2, " Tom Rini
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion Grygorii Strashko
                   ` (14 subsequent siblings)
  15 siblings, 2 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

Now when CONFIG_CMD_IMLS_NAND is enabled the u-boot build will fail,
because nand_read_skip_bad() function has been changed to accept more
parameters, hence fix it.

 CC      cmd/bootm.o
cmd/bootm.c: In function 'nand_imls_legacyimage':
cmd/bootm.c:390:8: error: too few arguments to function 'nand_read_skip_bad'
  ret = nand_read_skip_bad(mtd, off, &len, imgdata);
        ^
In file included from cmd/bootm.c:18:0:
include/nand.h:101:5: note: declared here
 int nand_read_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
     ^
 LD      drivers/block/built-in.o

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 cmd/bootm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/bootm.c b/cmd/bootm.c
index a7e181d..953a57d 100644
--- a/cmd/bootm.c
+++ b/cmd/bootm.c
@@ -390,7 +390,7 @@ static int nand_imls_legacyimage(struct mtd_info *mtd, int nand_dev,
 		return -ENOMEM;
 	}
 
-	ret = nand_read_skip_bad(mtd, off, &len, imgdata);
+	ret = nand_read_skip_bad(mtd, off, &len, NULL, mtd->size, imgdata);
 	if (ret < 0 && ret != -EUCLEAN) {
 		free(imgdata);
 		return ret;
@@ -430,7 +430,7 @@ static int nand_imls_fitimage(struct mtd_info *mtd, int nand_dev, loff_t off,
 		return -ENOMEM;
 	}
 
-	ret = nand_read_skip_bad(mtd, off, &len, imgdata);
+	ret = nand_read_skip_bad(mtd, off, &len, NULL, mtd->size, imgdata);
 	if (ret < 0 && ret != -EUCLEAN) {
 		free(imgdata);
 		return ret;
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
                     ` (2 more replies)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 03/15] common: env_nand: use get_nand_dev_by_index() Grygorii Strashko
                   ` (13 subsequent siblings)
  15 siblings, 3 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

From: Mugunthan V N <mugunthanvnm@ti.com>

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>
---
 cmd/nand.c                   | 69 +++++++++++++++++++++++++-------------------
 drivers/mtd/nand/nand.c      | 23 +++++++++++----
 drivers/mtd/nand/omap_gpmc.c |  7 ++---
 include/nand.h               |  9 ++++++
 4 files changed, 67 insertions(+), 41 deletions(-)

diff --git a/cmd/nand.c b/cmd/nand.c
index c16ec77..f2b440e 100644
--- a/cmd/nand.c
+++ b/cmd/nand.c
@@ -115,20 +115,20 @@ free_dat:
 
 static int set_dev(int dev)
 {
-	if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev]) {
-		puts("No such device\n");
-		return -1;
-	}
+	struct mtd_info *mtd = get_nand_dev_by_index(dev);
+
+	if (!mtd)
+		return -ENODEV;
 
 	if (nand_curr_device == dev)
 		return 0;
 
-	printf("Device %d: %s", dev, nand_info[dev]->name);
+	printf("Device %d: %s", dev, mtd->name);
 	puts("... is now current device\n");
 	nand_curr_device = dev;
 
 #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
-	board_nand_select_device(nand_info[dev]->priv, dev);
+	board_nand_select_device(mtd->priv, dev);
 #endif
 
 	return 0;
@@ -188,7 +188,7 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
 {
 	int ret;
 	uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)];
-	struct mtd_info *mtd = nand_info[0];
+	struct mtd_info *mtd = get_nand_dev_by_index(0);
 	char *cmd = argv[1];
 
 	if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !mtd) {
@@ -213,9 +213,10 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
 		if (argc < 3)
 			goto usage;
 
+		mtd = get_nand_dev_by_index(idx);
 		/* We don't care about size, or maxsize. */
 		if (mtd_arg_off(argv[2], &idx, &addr, &maxsize, &maxsize,
-				MTD_DEV_TYPE_NAND, nand_info[idx]->size)) {
+				MTD_DEV_TYPE_NAND, mtd->size)) {
 			puts("Offset or partition name expected\n");
 			return 1;
 		}
@@ -283,9 +284,14 @@ usage:
 
 static void nand_print_and_set_info(int idx)
 {
-	struct mtd_info *mtd = nand_info[idx];
-	struct nand_chip *chip = mtd_to_nand(mtd);
+	struct mtd_info *mtd;
+	struct nand_chip *chip;
+
+	mtd = get_nand_dev_by_index(idx);
+	if (!mtd)
+		return;
 
+	chip = mtd_to_nand(mtd);
 	printf("Device %d: ", idx);
 	if (chip->numchips > 1)
 		printf("%dx ", chip->numchips);
@@ -348,7 +354,7 @@ static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
 	/* We grab the nand info object here fresh because this is usually
 	 * called after arg_off_size() which can change the value of dev.
 	 */
-	struct mtd_info *mtd = nand_info[dev];
+	struct mtd_info *mtd = get_nand_dev_by_index(dev);
 	loff_t maxoffset = offset + *size;
 	int badblocks = 0;
 
@@ -397,10 +403,8 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	if (strcmp(cmd, "info") == 0) {
 
 		putc('\n');
-		for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
-			if (nand_info[i])
-				nand_print_and_set_info(i);
-		}
+		for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
+			nand_print_and_set_info(i);
 		return 0;
 	}
 
@@ -432,12 +436,11 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	 * one before these commands can run, even if a partition specifier
 	 * for another device is to be used.
 	 */
-	if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
-	    !nand_info[dev]) {
+	mtd = get_nand_dev_by_index(dev);
+	if (!mtd) {
 		puts("\nno devices available\n");
 		return 1;
 	}
-	mtd = nand_info[dev];
 
 	if (strcmp(cmd, "bad") == 0) {
 		printf("\nDevice %d bad blocks:\n", dev);
@@ -496,13 +499,13 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		/* skip first two or three arguments, look for offset and size */
 		if (mtd_arg_off_size(argc - o, argv + o, &dev, &off, &size,
 				     &maxsize, MTD_DEV_TYPE_NAND,
-				     nand_info[dev]->size) != 0)
+				     mtd->size) != 0)
 			return 1;
 
 		if (set_dev(dev))
 			return 1;
 
-		mtd = nand_info[dev];
+		mtd = get_nand_dev_by_index(dev);
 
 		memset(&opts, 0, sizeof(opts));
 		opts.offset = off;
@@ -565,13 +568,13 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 			if (mtd_arg_off(argv[3], &dev, &off, &size, &maxsize,
 					MTD_DEV_TYPE_NAND,
-					nand_info[dev]->size))
+					mtd->size))
 				return 1;
 
 			if (set_dev(dev))
 				return 1;
 
-			mtd = nand_info[dev];
+			mtd = get_nand_dev_by_index(dev);
 
 			if (argc > 4 && !str2long(argv[4], &pagecount)) {
 				printf("'%s' is not a number\n", argv[4]);
@@ -588,7 +591,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			if (mtd_arg_off_size(argc - 3, argv + 3, &dev, &off,
 					     &size, &maxsize,
 					     MTD_DEV_TYPE_NAND,
-					     nand_info[dev]->size) != 0)
+					     mtd->size) != 0)
 				return 1;
 
 			if (set_dev(dev))
@@ -600,7 +603,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			rwsize = size;
 		}
 
-		mtd = nand_info[dev];
+		mtd = get_nand_dev_by_index(dev);
 
 		if (!s || !strcmp(s, ".jffs2") ||
 		    !strcmp(s, ".e") || !strcmp(s, ".i")) {
@@ -760,13 +763,15 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 		if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &off, &size,
 				     &maxsize, MTD_DEV_TYPE_NAND,
-				     nand_info[dev]->size) < 0)
+				     mtd->size) < 0)
 			return 1;
 
 		if (set_dev(dev))
 			return 1;
 
-		if (!nand_unlock(nand_info[dev], off, size, allexcept)) {
+		mtd = get_nand_dev_by_index(dev);
+
+		if (!nand_unlock(mtd, off, size, allexcept)) {
 			puts("NAND flash successfully unlocked\n");
 		} else {
 			puts("Error unlocking NAND flash, "
@@ -929,6 +934,7 @@ static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc,
 	char *boot_device = NULL;
 	int idx;
 	ulong addr, offset = 0;
+	struct mtd_info *mtd;
 #if defined(CONFIG_CMD_MTDPARTS)
 	struct mtd_device *dev;
 	struct part_info *part;
@@ -948,8 +954,10 @@ static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc,
 				addr = simple_strtoul(argv[1], NULL, 16);
 			else
 				addr = CONFIG_SYS_LOAD_ADDR;
-			return nand_load_image(cmdtp, nand_info[dev->id->num],
-					       part->offset, addr, argv[0]);
+
+			mtd = get_nand_dev_by_index(dev->id->num);
+			return nand_load_image(cmdtp, mtd, part->offset,
+					       addr, argv[0]);
 		}
 	}
 #endif
@@ -991,14 +999,15 @@ usage:
 
 	idx = simple_strtoul(boot_device, NULL, 16);
 
-	if (idx < 0 || idx >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[idx]) {
+	mtd = get_nand_dev_by_index(idx);
+	if (!mtd) {
 		printf("\n** Device %d not available\n", idx);
 		bootstage_error(BOOTSTAGE_ID_NAND_AVAILABLE);
 		return 1;
 	}
 	bootstage_mark(BOOTSTAGE_ID_NAND_AVAILABLE);
 
-	return nand_load_image(cmdtp, nand_info[idx], offset, addr, argv[0]);
+	return nand_load_image(cmdtp, mtd, offset, addr, argv[0]);
 }
 
 U_BOOT_CMD(nboot, 4, 1, do_nandboot,
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c
index 0551241..18c346a 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,23 @@ 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]->name) {
+		puts("No such device\n");
+		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 +111,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++;
 		}
 	}
@@ -148,7 +159,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;
diff --git a/include/nand.h b/include/nand.h
index b6eb223..6c785a0 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -145,3 +145,12 @@ int spl_nand_erase_one(int block, int page);
 
 /* platform specific init functions */
 void sunxi_nand_init(void);
+
+/*
+ * get_nand_dev_by_index - Get the nand info based in index.
+ *
+ * @dev - index to the nand device.
+ *
+ * returns pointer to the nand device info structure or NULL on failure.
+ */
+struct mtd_info *get_nand_dev_by_index(int dev);
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 03/15] common: env_nand: use get_nand_dev_by_index()
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND Grygorii Strashko
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 04/15] dfu: dfu_nand: " Grygorii Strashko
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

As part of preparation for nand DM conversion the new API has been
introduced to remove direct access to nand_info array. So, use it here
instead of accessing to nand_info array directly.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 common/env_nand.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/common/env_nand.c b/common/env_nand.c
index 2e28171..133ecfb 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -130,17 +130,22 @@ static int writeenv(size_t offset, u_char *buf)
 	size_t end = offset + CONFIG_ENV_RANGE;
 	size_t amount_saved = 0;
 	size_t blocksize, len;
+	struct mtd_info *mtd;
 	u_char *char_ptr;
 
-	blocksize = nand_info[0]->erasesize;
+	mtd = get_nand_dev_by_index(0);
+	if (!mtd)
+		return 1;
+
+	blocksize = mtd->erasesize;
 	len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
 
 	while (amount_saved < CONFIG_ENV_SIZE && offset < end) {
-		if (nand_block_isbad(nand_info[0], offset)) {
+		if (nand_block_isbad(mtd, offset)) {
 			offset += blocksize;
 		} else {
 			char_ptr = &buf[amount_saved];
-			if (nand_write(nand_info[0], offset, &len, char_ptr))
+			if (nand_write(mtd, offset, &len, char_ptr))
 				return 1;
 
 			offset += blocksize;
@@ -161,13 +166,15 @@ struct env_location {
 static int erase_and_write_env(const struct env_location *location,
 		u_char *env_new)
 {
+	struct mtd_info *mtd;
 	int ret = 0;
 
-	if (!nand_info[0])
+	mtd = get_nand_dev_by_index(0);
+	if (!mtd)
 		return 1;
 
 	printf("Erasing %s...\n", location->name);
-	if (nand_erase_opts(nand_info[0], &location->erase_opts))
+	if (nand_erase_opts(mtd, &location->erase_opts))
 		return 1;
 
 	printf("Writing to %s... ", location->name);
@@ -248,22 +255,24 @@ static int readenv(size_t offset, u_char *buf)
 	size_t end = offset + CONFIG_ENV_RANGE;
 	size_t amount_loaded = 0;
 	size_t blocksize, len;
+	struct mtd_info *mtd;
 	u_char *char_ptr;
 
-	if (!nand_info[0])
+	mtd = get_nand_dev_by_index(0);
+	if (!mtd)
 		return 1;
 
-	blocksize = nand_info[0]->erasesize;
+	blocksize = mtd->erasesize;
 	len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
 
 	while (amount_loaded < CONFIG_ENV_SIZE && offset < end) {
-		if (nand_block_isbad(nand_info[0], offset)) {
+		if (nand_block_isbad(mtd, offset)) {
 			offset += blocksize;
 		} else {
 			char_ptr = &buf[amount_loaded];
-			if (nand_read_skip_bad(nand_info[0], offset,
+			if (nand_read_skip_bad(mtd, offset,
 					       &len, NULL,
-					       nand_info[0]->size, char_ptr))
+					       mtd->size, char_ptr))
 				return 1;
 
 			offset += blocksize;
@@ -390,12 +399,12 @@ void env_relocate_spec(void)
 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
 
 #if defined(CONFIG_ENV_OFFSET_OOB)
+	struct mtd_info *mtd  = get_nand_dev_by_index(0);
 	/*
 	 * If unable to read environment offset from NAND OOB then fall through
 	 * to the normal environment reading code below
 	 */
-	if (nand_info[0] && !get_nand_env_oob(nand_info[0],
-					      &nand_env_oob_offset)) {
+	if (mtd && !get_nand_env_oob(mtd, &nand_env_oob_offset)) {
 		printf("Found Environment offset in OOB..\n");
 	} else {
 		set_default_env("!no env offset in OOB");
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 04/15] dfu: dfu_nand: use get_nand_dev_by_index()
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (2 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 03/15] common: env_nand: use get_nand_dev_by_index() Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 05/15] cmd: bootm: " Grygorii Strashko
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

As part of preparation for nand DM conversion the new API has been
introduced to remove direct access to nand_info array. So, use it here
instead of accessing to nand_info array directly.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 drivers/dfu/dfu_nand.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c
index 23f1571..97cd608 100644
--- a/drivers/dfu/dfu_nand.c
+++ b/drivers/dfu/dfu_nand.c
@@ -37,15 +37,15 @@ static int nand_block_op(enum dfu_op op, struct dfu_entity *dfu,
 	lim = dfu->data.nand.start + dfu->data.nand.size - start;
 	count = *len;
 
+	mtd = get_nand_dev_by_index(nand_curr_device);
+
 	if (nand_curr_device < 0 ||
 	    nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
-	    !nand_info[nand_curr_device]) {
+	    !mtd) {
 		printf("%s: invalid nand device\n", __func__);
 		return -1;
 	}
 
-	mtd = nand_info[nand_curr_device];
-
 	if (op == DFU_OP_READ) {
 		ret = nand_read_skip_bad(mtd, start, &count, &actual,
 					 lim, buf);
@@ -143,18 +143,16 @@ static int dfu_flush_medium_nand(struct dfu_entity *dfu)
 
 	/* in case of ubi partition, erase rest of the partition */
 	if (dfu->data.nand.ubi) {
-		struct mtd_info *mtd;
+		struct mtd_info *mtd = get_nand_dev_by_index(nand_curr_device);
 		nand_erase_options_t opts;
 
 		if (nand_curr_device < 0 ||
 		    nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
-		    !nand_info[nand_curr_device]) {
+		    !mtd) {
 			printf("%s: invalid nand device\n", __func__);
 			return -1;
 		}
 
-		mtd = nand_info[nand_curr_device];
-
 		memset(&opts, 0, sizeof(opts));
 		off = dfu->offset;
 		if ((off & (mtd->erasesize - 1)) != 0) {
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 05/15] cmd: bootm: use get_nand_dev_by_index()
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (3 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 04/15] dfu: dfu_nand: " Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 06/15] cmd: jffs2: " Grygorii Strashko
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

As part of preparation for nand DM conversion the new API has been
introduced to remove direct access to nand_info array. So, use it here
instead of accessing to nand_info array directly.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 cmd/bootm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/bootm.c b/cmd/bootm.c
index 953a57d..daf15d9 100644
--- a/cmd/bootm.c
+++ b/cmd/bootm.c
@@ -465,7 +465,7 @@ static int do_imls_nand(void)
 	printf("\n");
 
 	for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
-		mtd = nand_info[nand_dev];
+		mtd = get_nand_dev_by_index(nand_dev);
 		if (!mtd->name || !mtd->size)
 			continue;
 
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 06/15] cmd: jffs2: use get_nand_dev_by_index()
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (4 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 05/15] cmd: bootm: " Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 07/15] common: " Grygorii Strashko
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

As part of preparation for nand DM conversion the new API has been
introduced to remove direct access to nand_info array. So, use it here
instead of accessing to nand_info array directly.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 cmd/jffs2.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/cmd/jffs2.c b/cmd/jffs2.c
index f00d53a..162c8fe 100644
--- a/cmd/jffs2.c
+++ b/cmd/jffs2.c
@@ -166,8 +166,9 @@ static int mtd_device_validate(u8 type, u8 num, u32 *size)
 #endif
 	} else if (type == MTD_DEV_TYPE_NAND) {
 #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
-		if (num < CONFIG_SYS_MAX_NAND_DEVICE) {
-			*size = nand_info[num]->size;
+		struct mtd_info *mtd = get_nand_dev_by_index(num);
+		if (mtd) {
+			*size = mtd->size;
 			return 0;
 		}
 
@@ -244,7 +245,7 @@ static inline u32 get_part_sector_size_nand(struct mtdids *id)
 #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
 	struct mtd_info *mtd;
 
-	mtd = nand_info[id->num];
+	mtd = get_nand_dev_by_index(id->num);
 
 	return mtd->erasesize;
 #else
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 07/15] common: use get_nand_dev_by_index()
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (5 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 06/15] cmd: jffs2: " Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 08/15] fs: " Grygorii Strashko
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

As part of preparation for nand DM conversion the new API has been
introduced to remove direct access to nand_info array. So, use it here
instead of accessing to nand_info array directly.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 common/fb_nand.c       | 2 +-
 common/splash_source.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/common/fb_nand.c b/common/fb_nand.c
index c8c79e9..3d027d4 100644
--- a/common/fb_nand.c
+++ b/common/fb_nand.c
@@ -59,7 +59,7 @@ static int fb_nand_lookup(const char *partname,
 		return -EINVAL;
 	}
 
-	*mtd = nand_info[dev->id->num];
+	*mtd = get_nand_dev_by_index(dev->id->num);
 
 	return 0;
 }
diff --git a/common/splash_source.c b/common/splash_source.c
index a5eeb3f..7c9b7b5 100644
--- a/common/splash_source.c
+++ b/common/splash_source.c
@@ -47,9 +47,10 @@ static int splash_sf_read_raw(u32 bmp_load_addr, int offset, size_t read_size)
 #ifdef CONFIG_CMD_NAND
 static int splash_nand_read_raw(u32 bmp_load_addr, int offset, size_t read_size)
 {
-	return nand_read_skip_bad(nand_info[nand_curr_device], offset,
+	struct mtd_info *mtd = get_nand_dev_by_index(nand_curr_device);
+	return nand_read_skip_bad(mtd, offset,
 				  &read_size, NULL,
-				  nand_info[nand_curr_device]->size,
+				  mtd->size,
 				  (u_char *)bmp_load_addr);
 }
 #else
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 08/15] fs: use get_nand_dev_by_index()
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (6 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 07/15] common: " Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 09/15] cmd: nand: remove direct access to struct mtd_info->priv Grygorii Strashko
                   ` (7 subsequent siblings)
  15 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

As part of preparation for nand DM conversion the new API has been
introduced to remove direct access to nand_info array. So, use it here
instead of accessing to nand_info array directly.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 fs/jffs2/jffs2_1pass.c       | 9 +++++++--
 fs/jffs2/jffs2_nand_1pass.c  | 6 +++++-
 fs/yaffs2/yaffs_uboot_glue.c | 8 ++++++--
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/fs/jffs2/jffs2_1pass.c b/fs/jffs2/jffs2_1pass.c
index ed60c5b..4c6dfbf 100644
--- a/fs/jffs2/jffs2_1pass.c
+++ b/fs/jffs2/jffs2_1pass.c
@@ -175,10 +175,15 @@ static u32 nand_cache_off = (u32)-1;
 static int read_nand_cached(u32 off, u32 size, u_char *buf)
 {
 	struct mtdids *id = current_part->dev->id;
+	struct mtd_info *mtd;
 	u32 bytes_read = 0;
 	size_t retlen;
 	int cpy_bytes;
 
+	mtd = get_nand_dev_by_index(id->num);
+	if (!mtd)
+		return -1;
+
 	while (bytes_read < size) {
 		if ((off + bytes_read < nand_cache_off) ||
 		    (off + bytes_read >= nand_cache_off+NAND_CACHE_SIZE)) {
@@ -195,8 +200,8 @@ static int read_nand_cached(u32 off, u32 size, u_char *buf)
 			}
 
 			retlen = NAND_CACHE_SIZE;
-			if (nand_read(nand_info[id->num], nand_cache_off,
-						&retlen, nand_cache) != 0 ||
+			if (nand_read(mtd, nand_cache_off,
+				      &retlen, nand_cache) != 0 ||
 					retlen != NAND_CACHE_SIZE) {
 				printf("read_nand_cached: error reading nand off %#x size %d bytes\n",
 						nand_cache_off, NAND_CACHE_SIZE);
diff --git a/fs/jffs2/jffs2_nand_1pass.c b/fs/jffs2/jffs2_nand_1pass.c
index d94c48f..1d63fc9 100644
--- a/fs/jffs2/jffs2_nand_1pass.c
+++ b/fs/jffs2/jffs2_nand_1pass.c
@@ -796,7 +796,11 @@ jffs2_1pass_build_lists(struct part_info * part)
 	u32 counterN = 0;
 
 	struct mtdids *id = part->dev->id;
-	mtd = nand_info[id->num];
+	mtd = get_nand_dev_by_index(id->num);
+	if (!mtd) {
+		error("\nno NAND devices available\n");
+		return 0;
+	}
 
 	/* if we are building a list we need to refresh the cache. */
 	jffs_init_1pass_list(part);
diff --git a/fs/yaffs2/yaffs_uboot_glue.c b/fs/yaffs2/yaffs_uboot_glue.c
index 25aa6d1..347424e 100644
--- a/fs/yaffs2/yaffs_uboot_glue.c
+++ b/fs/yaffs2/yaffs_uboot_glue.c
@@ -166,11 +166,15 @@ void cmd_yaffs_devconfig(char *_mp, int flash_dev,
 	char *mp = NULL;
 	struct nand_chip *chip;
 
+	mtd = get_nand_dev_by_index(flash_dev);
+	if (!mtd) {
+		error("\nno NAND devices available\n");
+		return;
+	}
+
 	dev = calloc(1, sizeof(*dev));
 	mp = strdup(_mp);
 
-	mtd = nand_info[flash_dev];
-
 	if (!dev || !mp) {
 		/* Alloc error */
 		printf("Failed to allocate memory\n");
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 09/15] cmd: nand: remove direct access to struct mtd_info->priv
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (7 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 08/15] fs: " Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:34   ` Simon Glass
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass Grygorii Strashko
                   ` (6 subsequent siblings)
  15 siblings, 2 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

Replace direct access to struct mtd_info->priv with proper
accessor mtd_to_nand().

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 cmd/nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/nand.c b/cmd/nand.c
index f2b440e..d9de978 100644
--- a/cmd/nand.c
+++ b/cmd/nand.c
@@ -128,7 +128,7 @@ static int set_dev(int dev)
 	nand_curr_device = dev;
 
 #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
-	board_nand_select_device(mtd->priv, dev);
+	board_nand_select_device(mtd_to_nand(mtd), dev);
 #endif
 
 	return 0;
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (8 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 09/15] cmd: nand: remove direct access to struct mtd_info->priv Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06 15:34   ` Simon Glass
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model Grygorii Strashko
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

From: Mugunthan V N <mugunthanvnm@ti.com>

Implement a NAND uclass so that the NAND devices can be
accessed via the DM framework.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 drivers/mtd/nand/Kconfig       | 10 ++++++++++
 drivers/mtd/nand/Makefile      |  2 ++
 drivers/mtd/nand/nand-uclass.c | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/mtd/nand/nand.c        | 17 +++++++++++++++--
 include/dm/uclass-id.h         |  1 +
 5 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100644 drivers/mtd/nand/nand-uclass.c

diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 65bb040..a96b646 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -1,5 +1,15 @@
 menu "NAND Device Support"
 
+config DM_NAND
+	bool "Enable driver model for NAND"
+	depends on DM
+	help
+	  Enable driver model for NAND. The NAND interface is then
+	  implemented by the NAND uclass. Multiple NAND devices can
+	  be attached and used. The 'nand' command works as normal.
+
+	  If the NAND drivers doesn't support DM, say N.
+
 config SYS_NAND_SELF_INIT
 	bool
 	help
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index fd4bb66..83a986a 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -38,6 +38,8 @@ endif # not spl
 
 ifdef NORMAL_DRIVERS
 
+obj-$(CONFIG_DM_NAND) += nand-uclass.o
+
 obj-$(CONFIG_NAND_ECC_BCH) += nand_bch.o
 
 obj-$(CONFIG_NAND_ATMEL) += atmel_nand.o
diff --git a/drivers/mtd/nand/nand-uclass.c b/drivers/mtd/nand/nand-uclass.c
new file mode 100644
index 0000000..403c363
--- /dev/null
+++ b/drivers/mtd/nand/nand-uclass.c
@@ -0,0 +1,38 @@
+/*
+ * NAND uclass driver for NAND bus.
+ *
+ * (C) Copyright 2017
+ *     Texas Instruments Incorporated, <www.ti.com>
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <nand.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct mtd_info *get_nand_dev_by_index(int idx)
+{
+	struct nand_chip *chip;
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_get_device(UCLASS_NAND, idx, &dev);
+	if (ret) {
+		debug("NAND device (%d) not found\n", idx);
+		return NULL;
+	}
+
+	chip = (struct nand_chip *)dev_get_priv(dev);
+
+	return nand_to_mtd(chip);
+}
+
+UCLASS_DRIVER(nand) = {
+	.id				= UCLASS_NAND,
+	.name				= "nand",
+	.flags				= DM_UC_FLAG_SEQ_ALIAS,
+};
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c
index 18c346a..408b7ef 100644
--- a/drivers/mtd/nand/nand.c
+++ b/drivers/mtd/nand/nand.c
@@ -21,7 +21,7 @@ int nand_curr_device = -1;
 
 struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
 
-#ifndef CONFIG_SYS_NAND_SELF_INIT
+#if !defined(CONFIG_SYS_NAND_SELF_INIT) && !defined(CONFIG_DM_NAND)
 static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE];
 static ulong base_address[CONFIG_SYS_MAX_NAND_DEVICE] = CONFIG_SYS_NAND_BASE_LIST;
 #endif
@@ -30,6 +30,7 @@ static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];
 
 static unsigned long total_nand_size; /* in kiB */
 
+#ifndef CONFIG_DM_NAND
 struct mtd_info *get_nand_dev_by_index(int dev)
 {
 	if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
@@ -40,6 +41,7 @@ struct mtd_info *get_nand_dev_by_index(int dev)
 
 	return nand_info[dev];
 }
+#endif
 
 int nand_mtd_to_devnum(struct mtd_info *mtd)
 {
@@ -59,8 +61,9 @@ int nand_register(int devnum, struct mtd_info *mtd)
 	if (devnum >= CONFIG_SYS_MAX_NAND_DEVICE)
 		return -EINVAL;
 
+#if !defined(CONFIG_SYS_NAND_SELF_INIT) && !defined(CONFIG_DM_NAND)
 	nand_info[devnum] = mtd;
-
+#endif
 	sprintf(dev_name[devnum], "nand%d", devnum);
 	mtd->name = dev_name[devnum];
 
@@ -83,18 +86,28 @@ int nand_register(int devnum, struct mtd_info *mtd)
 #ifndef CONFIG_SYS_NAND_SELF_INIT
 static void nand_init_chip(int i)
 {
+#ifndef CONFIG_DM_NAND
 	struct nand_chip *nand = &nand_chip[i];
 	struct mtd_info *mtd = nand_to_mtd(nand);
 	ulong base_addr = base_address[i];
+#else
+	struct mtd_info *mtd;
+#endif
 	int maxchips = CONFIG_SYS_NAND_MAX_CHIPS;
 
 	if (maxchips < 1)
 		maxchips = 1;
 
+#ifdef CONFIG_DM_NAND
+	mtd = get_nand_dev_by_index(i);
+	if (!mtd)
+		return;
+#else
 	nand->IO_ADDR_R = nand->IO_ADDR_W = (void  __iomem *)base_addr;
 
 	if (board_nand_init(nand))
 		return;
+#endif
 
 	if (nand_scan(mtd, maxchips))
 		return;
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 8c92d0b..6556dc8 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -49,6 +49,7 @@ enum uclass_id {
 	UCLASS_MMC,		/* SD / MMC card or chip */
 	UCLASS_MOD_EXP,		/* RSA Mod Exp device */
 	UCLASS_MTD,		/* Memory Technology Device (MTD) device */
+	UCLASS_NAND,		/* NAND device */
 	UCLASS_NORTHBRIDGE,	/* Intel Northbridge / SDRAM controller */
 	UCLASS_PANEL,		/* Display panel, such as an LCD */
 	UCLASS_PANEL_BACKLIGHT,	/* Backlight controller for panel */
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (9 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-02-10 16:22   ` Simon Glass
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 12/15] am43xx_evm: nand: do not define DM_NAND for spl Grygorii Strashko
                   ` (4 subsequent siblings)
  15 siblings, 2 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

From: Mugunthan V N <mugunthanvnm@ti.com>

adopt omap_gpmc driver to driver model.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 drivers/mtd/nand/omap_gpmc.c | 205 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 205 insertions(+)

diff --git a/drivers/mtd/nand/omap_gpmc.c b/drivers/mtd/nand/omap_gpmc.c
index b540bc3..a2d1634 100644
--- a/drivers/mtd/nand/omap_gpmc.c
+++ b/drivers/mtd/nand/omap_gpmc.c
@@ -16,6 +16,10 @@
 #include <nand.h>
 #include <linux/mtd/omap_elm.h>
 
+#include <dm.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
 #define BADBLOCK_MARKER_LENGTH	2
 #define SECTOR_BYTES		512
 #define ECCCLEAR		(0x1 << 8)
@@ -46,11 +50,22 @@ struct omap_nand_info {
 	enum omap_ecc ecc_scheme;
 	uint8_t cs;
 	uint8_t ws;		/* wait status pin (0,1) */
+	uint8_t bus_width;	/* Bus width of NAND device */
 };
 
+#ifndef CONFIG_DM_NAND
 /* We are wasting a bit of memory but al least we are safe */
 static struct omap_nand_info omap_nand_info[GPMC_MAX_CS];
 
+#else
+
+struct omap_gpmc_platdata {
+	struct omap_nand_info *omap_nand_info;
+	struct gpmc *gpmc_cfg;
+	int max_cs;
+};
+#endif
+
 /*
  * omap_nand_hwcontrol - Set the address pointers corretly for the
  *			following address/data/command operation
@@ -945,6 +960,8 @@ int __maybe_unused omap_nand_switch_ecc(uint32_t hardware, uint32_t eccstrength)
 }
 #endif /* CONFIG_SPL_BUILD */
 
+#ifndef CONFIG_DM_NAND
+
 /*
  * Board-specific NAND initialization. The following members of the
  * argument are board-specific:
@@ -1036,3 +1053,191 @@ int board_nand_init(struct nand_chip *nand)
 
 	return 0;
 }
+
+#else /* CONFIG_DM_NAND */
+
+static int omap_gpmc_probe(struct udevice *dev)
+{
+	struct nand_chip *nand = dev_get_priv(dev);
+	struct omap_gpmc_platdata *pdata = dev_get_platdata(dev);
+	struct gpmc *gpmc_cfg = pdata->gpmc_cfg;
+	int32_t gpmc_config = 0;
+	int ecc_opt;
+	int cs = cs_next++;
+	int err = 0;
+
+	while (cs < pdata->max_cs) {
+		/* Check if NAND type is set */
+		if ((readl(&gpmc_cfg->cs[cs].config1) & 0xC00) == 0x800) {
+			/* Found it!! */
+			break;
+		}
+		cs++;
+	}
+
+	if (cs >= pdata->max_cs) {
+		printf("nand: error: Unable to find NAND settings in GPMC Configuration - quitting\n");
+		return -ENODEV;
+	}
+
+	gpmc_config = readl(&gpmc_cfg->config);
+	/* Disable Write protect */
+	gpmc_config |= 0x10;
+	writel(gpmc_config, &gpmc_cfg->config);
+
+	nand->IO_ADDR_R = (void __iomem *)&gpmc_cfg->cs[cs].nand_dat;
+	nand->IO_ADDR_W = (void __iomem *)&gpmc_cfg->cs[cs].nand_cmd;
+	nand->priv	= &pdata->omap_nand_info[cs];
+	nand->cmd_ctrl	= omap_nand_hwcontrol;
+	nand->options	|= NAND_NO_PADDING | NAND_CACHEPRG;
+	nand->chip_delay = 100;
+	nand->ecc.layout = &omap_ecclayout;
+
+	/* configure driver and controller based on NAND device bus-width */
+	gpmc_config = readl(&gpmc_cfg->cs[cs].config1);
+	if (pdata->omap_nand_info[cs].bus_width == 16) {
+		nand->options |= NAND_BUSWIDTH_16;
+		writel(gpmc_config | (0x1 << 12), &gpmc_cfg->cs[cs].config1);
+	} else {
+		nand->options &= ~NAND_BUSWIDTH_16;
+		writel(gpmc_config & ~(0x1 << 12), &gpmc_cfg->cs[cs].config1);
+	}
+
+	ecc_opt = pdata->omap_nand_info[cs].ecc_scheme;
+	/* select ECC scheme */
+	if (ecc_opt != OMAP_ECC_HAM1_CODE_SW) {
+		err = omap_select_ecc_scheme(nand, ecc_opt,
+					     CONFIG_SYS_NAND_PAGE_SIZE,
+					     CONFIG_SYS_NAND_OOBSIZE);
+	} else {
+		/*
+		 * pagesize and oobsize are not required to
+		 * configure sw ecc-scheme
+		 */
+		err = omap_select_ecc_scheme(nand, ecc_opt, 0, 0);
+	}
+	if (err)
+		return err;
+
+#ifdef CONFIG_NAND_OMAP_GPMC_PREFETCH
+	nand->read_buf = omap_nand_read_prefetch;
+#else
+	if (nand->options & NAND_BUSWIDTH_16)
+		nand->read_buf = nand_read_buf16;
+	else
+		nand->read_buf = nand_read_buf;
+#endif
+
+	nand->dev_ready = omap_dev_ready;
+
+	return 0;
+}
+
+static int omap_gpmc_get_ecc_opt(int node, int elm_node)
+{
+	const void *fdt = gd->fdt_blob;
+	const char *ecc_str;
+	int ecc_opt = -ENOENT;
+
+	ecc_str = fdt_getprop(fdt, node, "ti,nand-ecc-opt", NULL);
+	if (!ecc_str) {
+		error("DT entry for ti,nand-ecc-opt not found\n");
+		return -ENOENT;
+	}
+
+	if (!strcmp(ecc_str, "sw")) {
+		ecc_opt = OMAP_ECC_HAM1_CODE_SW;
+	} else if (!strcmp(ecc_str, "ham1") ||
+		   !strcmp(ecc_str, "hw") ||
+		   !strcmp(ecc_str, "hw-romcode")) {
+		ecc_opt = OMAP_ECC_HAM1_CODE_HW;
+	} else if (!strcmp(ecc_str, "bch4")) {
+		if (elm_node > 0)
+			ecc_opt = OMAP_ECC_BCH4_CODE_HW;
+		else
+			ecc_opt = OMAP_ECC_BCH4_CODE_HW_DETECTION_SW;
+	} else if (!strcmp(ecc_str, "bch8")) {
+		if (elm_node > 0)
+			ecc_opt = OMAP_ECC_BCH8_CODE_HW;
+		else
+			ecc_opt = OMAP_ECC_BCH8_CODE_HW_DETECTION_SW;
+	} else if (!strcmp(ecc_str, "bch16")) {
+		if (elm_node > 0)
+			ecc_opt = OMAP_ECC_BCH16_CODE_HW;
+		else
+			error("BCH16 requires ELM support\n");
+	} else {
+		error("ti,nand-ecc-opt invalid value\n");
+		return -EINVAL;
+	}
+
+	return ecc_opt;
+}
+
+static int omap_gpmc_ofdata_to_platdata(struct udevice *dev)
+{
+	struct omap_gpmc_platdata *pdata = dev_get_platdata(dev);
+	const void *fdt = gd->fdt_blob;
+	int node = dev->of_offset;
+	int subnode;
+
+	pdata->gpmc_cfg = (struct gpmc *)dev_get_addr(dev);
+	pdata->max_cs = fdtdec_get_int(fdt, node, "gpmc,num-cs", -1);
+	if (pdata->max_cs < 0) {
+		error("max chip select not found in DT\n");
+		return -ENOENT;
+	}
+
+	pdata->omap_nand_info = calloc(pdata->max_cs,
+				       sizeof(struct omap_nand_info));
+	if (!pdata->omap_nand_info)
+		return -ENOMEM;
+
+	fdt_for_each_subnode(subnode, fdt, node) {
+		int cs;
+		int len;
+		int elm_node;
+		const char *name;
+		struct omap_nand_info *nand_info;
+
+		name = fdt_get_name(fdt, subnode, &len);
+		if (strncmp(name, "nand", 4))
+			continue;
+
+		cs = fdtdec_get_int(fdt, subnode, "reg", -1);
+		if (cs < 0 || cs >= pdata->max_cs) {
+			error("Invalid cs for nand device\n");
+			return -EINVAL;
+		}
+		nand_info = &pdata->omap_nand_info[cs];
+
+		/* get bus width 8 or 16, if not present 8 */
+		nand_info->bus_width = fdtdec_get_int(fdt, subnode,
+						      "nand-bus-width", 8);
+
+		elm_node = fdtdec_lookup_phandle(fdt, subnode, "ti,elm-id");
+
+		nand_info->ecc_scheme = omap_gpmc_get_ecc_opt(subnode,
+							      elm_node);
+		if (nand_info->ecc_scheme < 0)
+			return nand_info->ecc_scheme;
+	}
+	return 0;
+}
+
+static const struct udevice_id omap_gpmc_ids[] = {
+	{ .compatible = "ti,am3352-gpmc" },
+	{ }
+};
+
+U_BOOT_DRIVER(omap_gpmc) = {
+	.name	= "omap_gpmc",
+	.id	= UCLASS_NAND,
+	.of_match = omap_gpmc_ids,
+	.ofdata_to_platdata = omap_gpmc_ofdata_to_platdata,
+	.probe	= omap_gpmc_probe,
+	.priv_auto_alloc_size = sizeof(struct nand_chip),
+	.platdata_auto_alloc_size = sizeof(struct omap_gpmc_platdata),
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
+#endif /* CONFIG_DM_NAND */
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 12/15] am43xx_evm: nand: do not define DM_NAND for spl
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (10 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 13/15] defconfig: am43xx_evm: enable NAND driver model Grygorii Strashko
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

From: Mugunthan V N <mugunthanvnm@ti.com>

Since OMAP's spl doesn't support DM currently, do not define
DM_NAND for spl build.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 include/configs/am43xx_evm.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/configs/am43xx_evm.h b/include/configs/am43xx_evm.h
index 1d622ef..2f026c6 100644
--- a/include/configs/am43xx_evm.h
+++ b/include/configs/am43xx_evm.h
@@ -115,6 +115,7 @@
 #undef CONFIG_DM_SPI
 #undef CONFIG_DM_SPI_FLASH
 #undef CONFIG_TIMER
+#undef CONFIG_DM_NAND
 #endif
 
 #ifndef CONFIG_SPL_BUILD
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 13/15] defconfig: am43xx_evm: enable NAND driver model
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (11 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 12/15] am43xx_evm: nand: do not define DM_NAND for spl Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 14/15] am335x_evm: nand: do not define DM_NAND for spl Grygorii Strashko
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

From: Mugunthan V N <mugunthanvnm@ti.com>

Enable NAND driver model for am43xx_evm as omap_gpmc supports
driver model.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 configs/am43xx_evm_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am43xx_evm_defconfig b/configs/am43xx_evm_defconfig
index 6fb2053..dcddb7d 100644
--- a/configs/am43xx_evm_defconfig
+++ b/configs/am43xx_evm_defconfig
@@ -74,3 +74,4 @@ CONFIG_G_DNL_MANUFACTURER="Texas Instruments"
 CONFIG_G_DNL_VENDOR_NUM=0x0403
 CONFIG_G_DNL_PRODUCT_NUM=0xbd00
 CONFIG_SPL_OF_LIBFDT=y
+CONFIG_DM_NAND=y
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 14/15] am335x_evm: nand: do not define DM_NAND for spl
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (12 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 13/15] defconfig: am43xx_evm: enable NAND driver model Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 15/15] defconfig: am335x_evm: enable NAND driver model Grygorii Strashko
  2017-02-06  1:56 ` [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Tom Rini
  15 siblings, 0 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

From: Mugunthan V N <mugunthanvnm@ti.com>

Since OMAP's spl doesn't support DM currently, do not define
DM_NAND for spl build.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 include/configs/am335x_evm.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h
index d8e6ba3..7390015 100644
--- a/include/configs/am335x_evm.h
+++ b/include/configs/am335x_evm.h
@@ -287,6 +287,7 @@
 #undef CONFIG_DM_MMC
 #undef CONFIG_TIMER
 #undef CONFIG_DM_USB
+#undef CONFIG_DM_NAND
 #endif
 
 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_USBETH_SUPPORT)
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 15/15] defconfig: am335x_evm: enable NAND driver model
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (13 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 14/15] am335x_evm: nand: do not define DM_NAND for spl Grygorii Strashko
@ 2017-01-31 21:37 ` Grygorii Strashko
  2017-02-06  1:56 ` [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Tom Rini
  15 siblings, 0 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-01-31 21:37 UTC (permalink / raw)
  To: u-boot

From: Mugunthan V N <mugunthanvnm@ti.com>

Enable NAND driver model for am335x_evm as omap_gpmc supports
driver model.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 configs/am335x_evm_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am335x_evm_defconfig b/configs/am335x_evm_defconfig
index ab7b9aa..6f624e9 100644
--- a/configs/am335x_evm_defconfig
+++ b/configs/am335x_evm_defconfig
@@ -58,3 +58,4 @@ CONFIG_G_DNL_VENDOR_NUM=0x0451
 CONFIG_G_DNL_PRODUCT_NUM=0xd022
 CONFIG_RSA=y
 CONFIG_SPL_OF_LIBFDT=y
+CONFIG_DM_NAND=y
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm
  2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
                   ` (14 preceding siblings ...)
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 15/15] defconfig: am335x_evm: enable NAND driver model Grygorii Strashko
@ 2017-02-06  1:56 ` Tom Rini
  2017-02-06 18:50   ` Grygorii Strashko
  15 siblings, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:56 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:02PM -0600, Grygorii Strashko wrote:

> This patch seires adds nand uclass driver and enables omap_gpmc to
> adopt driver model. This has been tested on AM335x GP EVM and
> AM437x GP EVM.
> 
> As preparation for introducing nand uclass driver the new API
> get_nand_dev_by_index() was added to avoid direct acces to nand_info array and
> u-boot core files were updated to use it.
> 
> Patches can be found at:
> git at git.ti.com:~gragst/ti-u-boot/gragsts-ti-u-boot.git dm-nand-v2

My conceptual concern here is that we need to address (as I've stated
elsewhere) the need to get DM/DT support within SPL on these families
(and yes, figure out what we'll do with respect to HS and the further
size constraints) before we push farther down this path of DM/DT
conversion as it's adding more #if/#else/#endif code that we need to be
able to drop.  Thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/34771082/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND Grygorii Strashko
@ 2017-02-06  1:56   ` Tom Rini
  2017-02-06 15:33     ` Simon Glass
  2017-02-09  3:03   ` [U-Boot] [U-Boot, v2, " Tom Rini
  1 sibling, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:56 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:03PM -0600, Grygorii Strashko wrote:

> Now when CONFIG_CMD_IMLS_NAND is enabled the u-boot build will fail,
> because nand_read_skip_bad() function has been changed to accept more
> parameters, hence fix it.
> 
>  CC      cmd/bootm.o
> cmd/bootm.c: In function 'nand_imls_legacyimage':
> cmd/bootm.c:390:8: error: too few arguments to function 'nand_read_skip_bad'
>   ret = nand_read_skip_bad(mtd, off, &len, imgdata);
>         ^
> In file included from cmd/bootm.c:18:0:
> include/nand.h:101:5: note: declared here
>  int nand_read_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
>      ^
>  LD      drivers/block/built-in.o
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/540f3a31/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-09 17:51     ` Grygorii Strashko
  2017-02-06 15:33   ` Simon Glass
  2017-02-08 21:23   ` [U-Boot] [U-Boot, v2, " Tom Rini
  2 siblings, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:04PM -0600, Grygorii Strashko wrote:

> From: Mugunthan V N <mugunthanvnm@ti.com>
> 
> 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>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/c09d3ece/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 03/15] common: env_nand: use get_nand_dev_by_index()
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 03/15] common: env_nand: use get_nand_dev_by_index() Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:33     ` Simon Glass
  0 siblings, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:05PM -0600, Grygorii Strashko wrote:

> As part of preparation for nand DM conversion the new API has been
> introduced to remove direct access to nand_info array. So, use it here
> instead of accessing to nand_info array directly.
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/8aeef128/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 04/15] dfu: dfu_nand: use get_nand_dev_by_index()
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 04/15] dfu: dfu_nand: " Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:34     ` Simon Glass
  0 siblings, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:06PM -0600, Grygorii Strashko wrote:

> As part of preparation for nand DM conversion the new API has been
> introduced to remove direct access to nand_info array. So, use it here
> instead of accessing to nand_info array directly.
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/86621820/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 05/15] cmd: bootm: use get_nand_dev_by_index()
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 05/15] cmd: bootm: " Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:34     ` Simon Glass
  0 siblings, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:07PM -0600, Grygorii Strashko wrote:

> As part of preparation for nand DM conversion the new API has been
> introduced to remove direct access to nand_info array. So, use it here
> instead of accessing to nand_info array directly.
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/5236c36d/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 06/15] cmd: jffs2: use get_nand_dev_by_index()
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 06/15] cmd: jffs2: " Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:34     ` Simon Glass
  0 siblings, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:08PM -0600, Grygorii Strashko wrote:

> As part of preparation for nand DM conversion the new API has been
> introduced to remove direct access to nand_info array. So, use it here
> instead of accessing to nand_info array directly.
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/b6b456da/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 07/15] common: use get_nand_dev_by_index()
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 07/15] common: " Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:33     ` Simon Glass
  0 siblings, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:09PM -0600, Grygorii Strashko wrote:

> As part of preparation for nand DM conversion the new API has been
> introduced to remove direct access to nand_info array. So, use it here
> instead of accessing to nand_info array directly.
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/948c768e/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 08/15] fs: use get_nand_dev_by_index()
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 08/15] fs: " Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:34     ` Simon Glass
  0 siblings, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:10PM -0600, Grygorii Strashko wrote:

> As part of preparation for nand DM conversion the new API has been
> introduced to remove direct access to nand_info array. So, use it here
> instead of accessing to nand_info array directly.
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/cfb0cc52/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 09/15] cmd: nand: remove direct access to struct mtd_info->priv
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 09/15] cmd: nand: remove direct access to struct mtd_info->priv Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:34   ` Simon Glass
  1 sibling, 0 replies; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:11PM -0600, Grygorii Strashko wrote:

> Replace direct access to struct mtd_info->priv with proper
> accessor mtd_to_nand().
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/43198bbd/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model Grygorii Strashko
@ 2017-02-06  1:57   ` Tom Rini
  2017-02-06 18:40     ` Grygorii Strashko
  2017-02-10 16:22   ` Simon Glass
  1 sibling, 1 reply; 48+ messages in thread
From: Tom Rini @ 2017-02-06  1:57 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:13PM -0600, Grygorii Strashko wrote:

> From: Mugunthan V N <mugunthanvnm@ti.com>
> 
> adopt omap_gpmc driver to driver model.
> 
> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
> ---
>  drivers/mtd/nand/omap_gpmc.c | 205 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 205 insertions(+)

Is there any way we can do this while sharing more of the code between
the DM and non-DM versions?

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170205/278a447f/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 07/15] common: use get_nand_dev_by_index()
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 15:33     ` Simon Glass
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:33 UTC (permalink / raw)
  To: u-boot

On 5 February 2017 at 17:57, Tom Rini <trini@konsulko.com> wrote:
> On Tue, Jan 31, 2017 at 03:37:09PM -0600, Grygorii Strashko wrote:
>
>> As part of preparation for nand DM conversion the new API has been
>> introduced to remove direct access to nand_info array. So, use it here
>> instead of accessing to nand_info array directly.
>>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 03/15] common: env_nand: use get_nand_dev_by_index()
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 15:33     ` Simon Glass
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:33 UTC (permalink / raw)
  To: u-boot

On 5 February 2017 at 17:57, Tom Rini <trini@konsulko.com> wrote:
> On Tue, Jan 31, 2017 at 03:37:05PM -0600, Grygorii Strashko wrote:
>
>> As part of preparation for nand DM conversion the new API has been
>> introduced to remove direct access to nand_info array. So, use it here
>> instead of accessing to nand_info array directly.
>>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND
  2017-02-06  1:56   ` Tom Rini
@ 2017-02-06 15:33     ` Simon Glass
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:33 UTC (permalink / raw)
  To: u-boot

On 5 February 2017 at 17:56, Tom Rini <trini@konsulko.com> wrote:
> On Tue, Jan 31, 2017 at 03:37:03PM -0600, Grygorii Strashko wrote:
>
>> Now when CONFIG_CMD_IMLS_NAND is enabled the u-boot build will fail,
>> because nand_read_skip_bad() function has been changed to accept more
>> parameters, hence fix it.
>>
>>  CC      cmd/bootm.o
>> cmd/bootm.c: In function 'nand_imls_legacyimage':
>> cmd/bootm.c:390:8: error: too few arguments to function 'nand_read_skip_bad'
>>   ret = nand_read_skip_bad(mtd, off, &len, imgdata);
>>         ^
>> In file included from cmd/bootm.c:18:0:
>> include/nand.h:101:5: note: declared here
>>  int nand_read_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
>>      ^
>>  LD      drivers/block/built-in.o
>>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 15:33   ` Simon Glass
  2017-02-08 21:23   ` [U-Boot] [U-Boot, v2, " Tom Rini
  2 siblings, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:33 UTC (permalink / raw)
  To: u-boot

On 31 January 2017 at 13:37, Grygorii Strashko <grygorii.strashko@ti.com> wrote:
> From: Mugunthan V N <mugunthanvnm@ti.com>
>
> 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>
> ---
>  cmd/nand.c                   | 69 +++++++++++++++++++++++++-------------------
>  drivers/mtd/nand/nand.c      | 23 +++++++++++----
>  drivers/mtd/nand/omap_gpmc.c |  7 ++---
>  include/nand.h               |  9 ++++++
>  4 files changed, 67 insertions(+), 41 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 05/15] cmd: bootm: use get_nand_dev_by_index()
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 15:34     ` Simon Glass
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:34 UTC (permalink / raw)
  To: u-boot

On 5 February 2017 at 17:57, Tom Rini <trini@konsulko.com> wrote:
> On Tue, Jan 31, 2017 at 03:37:07PM -0600, Grygorii Strashko wrote:
>
>> As part of preparation for nand DM conversion the new API has been
>> introduced to remove direct access to nand_info array. So, use it here
>> instead of accessing to nand_info array directly.
>>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 06/15] cmd: jffs2: use get_nand_dev_by_index()
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 15:34     ` Simon Glass
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:34 UTC (permalink / raw)
  To: u-boot

On 5 February 2017 at 17:57, Tom Rini <trini@konsulko.com> wrote:
> On Tue, Jan 31, 2017 at 03:37:08PM -0600, Grygorii Strashko wrote:
>
>> As part of preparation for nand DM conversion the new API has been
>> introduced to remove direct access to nand_info array. So, use it here
>> instead of accessing to nand_info array directly.
>>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 09/15] cmd: nand: remove direct access to struct mtd_info->priv
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 09/15] cmd: nand: remove direct access to struct mtd_info->priv Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 15:34   ` Simon Glass
  1 sibling, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:34 UTC (permalink / raw)
  To: u-boot

On 31 January 2017 at 13:37, Grygorii Strashko <grygorii.strashko@ti.com> wrote:
> Replace direct access to struct mtd_info->priv with proper
> accessor mtd_to_nand().
>
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
> ---
>  cmd/nand.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 04/15] dfu: dfu_nand: use get_nand_dev_by_index()
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 15:34     ` Simon Glass
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:34 UTC (permalink / raw)
  To: u-boot

On 5 February 2017 at 17:57, Tom Rini <trini@konsulko.com> wrote:
> On Tue, Jan 31, 2017 at 03:37:06PM -0600, Grygorii Strashko wrote:
>
>> As part of preparation for nand DM conversion the new API has been
>> introduced to remove direct access to nand_info array. So, use it here
>> instead of accessing to nand_info array directly.
>>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 08/15] fs: use get_nand_dev_by_index()
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 15:34     ` Simon Glass
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:34 UTC (permalink / raw)
  To: u-boot

On 5 February 2017 at 17:57, Tom Rini <trini@konsulko.com> wrote:
> On Tue, Jan 31, 2017 at 03:37:10PM -0600, Grygorii Strashko wrote:
>
>> As part of preparation for nand DM conversion the new API has been
>> introduced to remove direct access to nand_info array. So, use it here
>> instead of accessing to nand_info array directly.
>>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass Grygorii Strashko
@ 2017-02-06 15:34   ` Simon Glass
  2017-02-06 18:39     ` Grygorii Strashko
  0 siblings, 1 reply; 48+ messages in thread
From: Simon Glass @ 2017-02-06 15:34 UTC (permalink / raw)
  To: u-boot

Hi,

On 31 January 2017 at 13:37, Grygorii Strashko <grygorii.strashko@ti.com> wrote:
> From: Mugunthan V N <mugunthanvnm@ti.com>
>
> Implement a NAND uclass so that the NAND devices can be
> accessed via the DM framework.
>
> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
> ---
>  drivers/mtd/nand/Kconfig       | 10 ++++++++++
>  drivers/mtd/nand/Makefile      |  2 ++
>  drivers/mtd/nand/nand-uclass.c | 38 ++++++++++++++++++++++++++++++++++++++
>  drivers/mtd/nand/nand.c        | 17 +++++++++++++++--
>  include/dm/uclass-id.h         |  1 +
>  5 files changed, 66 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/mtd/nand/nand-uclass.c
>
> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
> index 65bb040..a96b646 100644
> --- a/drivers/mtd/nand/Kconfig
> +++ b/drivers/mtd/nand/Kconfig
> @@ -1,5 +1,15 @@
>  menu "NAND Device Support"
>
> +config DM_NAND
> +       bool "Enable driver model for NAND"
> +       depends on DM
> +       help
> +         Enable driver model for NAND. The NAND interface is then
> +         implemented by the NAND uclass. Multiple NAND devices can
> +         be attached and used. The 'nand' command works as normal.
> +
> +         If the NAND drivers doesn't support DM, say N.
> +
>  config SYS_NAND_SELF_INIT
>         bool
>         help
> diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
> index fd4bb66..83a986a 100644
> --- a/drivers/mtd/nand/Makefile
> +++ b/drivers/mtd/nand/Makefile
> @@ -38,6 +38,8 @@ endif # not spl
>
>  ifdef NORMAL_DRIVERS
>
> +obj-$(CONFIG_DM_NAND) += nand-uclass.o
> +
>  obj-$(CONFIG_NAND_ECC_BCH) += nand_bch.o
>
>  obj-$(CONFIG_NAND_ATMEL) += atmel_nand.o
> diff --git a/drivers/mtd/nand/nand-uclass.c b/drivers/mtd/nand/nand-uclass.c
> new file mode 100644
> index 0000000..403c363
> --- /dev/null
> +++ b/drivers/mtd/nand/nand-uclass.c
> @@ -0,0 +1,38 @@
> +/*
> + * NAND uclass driver for NAND bus.
> + *
> + * (C) Copyright 2017
> + *     Texas Instruments Incorporated, <www.ti.com>
> + *
> + * SPDX-License-Identifier:     GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <errno.h>
> +#include <nand.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +struct mtd_info *get_nand_dev_by_index(int idx)
> +{
> +       struct nand_chip *chip;
> +       struct udevice *dev;
> +       int ret;
> +
> +       ret = uclass_get_device(UCLASS_NAND, idx, &dev);
> +       if (ret) {
> +               debug("NAND device (%d) not found\n", idx);
> +               return NULL;
> +       }
> +
> +       chip = (struct nand_chip *)dev_get_priv(dev);
> +
> +       return nand_to_mtd(chip);

Can you add some comments to the nand.h header file (perhaps within
#ifdef CONFIG_DM_NAND) to explain that drivers must have struct
nand_chip as the first part of their private data? Assuming I have
this right...

> +}
> +
> +UCLASS_DRIVER(nand) = {
> +       .id                             = UCLASS_NAND,
> +       .name                           = "nand",
> +       .flags                          = DM_UC_FLAG_SEQ_ALIAS,
> +};

Also can we have a sandbox NAND driver and some tests.

> diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c
> index 18c346a..408b7ef 100644
> --- a/drivers/mtd/nand/nand.c
> +++ b/drivers/mtd/nand/nand.c
> @@ -21,7 +21,7 @@ int nand_curr_device = -1;
>
>  struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
>
> -#ifndef CONFIG_SYS_NAND_SELF_INIT
> +#if !defined(CONFIG_SYS_NAND_SELF_INIT) && !defined(CONFIG_DM_NAND)
>  static struct nand_chip nand_chip[CONFIG_SYS_MAX_NAND_DEVICE];
>  static ulong base_address[CONFIG_SYS_MAX_NAND_DEVICE] = CONFIG_SYS_NAND_BASE_LIST;
>  #endif
> @@ -30,6 +30,7 @@ static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];
>
>  static unsigned long total_nand_size; /* in kiB */
>
> +#ifndef CONFIG_DM_NAND
>  struct mtd_info *get_nand_dev_by_index(int dev)
>  {
>         if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
> @@ -40,6 +41,7 @@ struct mtd_info *get_nand_dev_by_index(int dev)
>
>         return nand_info[dev];
>  }
> +#endif
>
>  int nand_mtd_to_devnum(struct mtd_info *mtd)
>  {
> @@ -59,8 +61,9 @@ int nand_register(int devnum, struct mtd_info *mtd)
>         if (devnum >= CONFIG_SYS_MAX_NAND_DEVICE)
>                 return -EINVAL;
>
> +#if !defined(CONFIG_SYS_NAND_SELF_INIT) && !defined(CONFIG_DM_NAND)
>         nand_info[devnum] = mtd;
> -
> +#endif
>         sprintf(dev_name[devnum], "nand%d", devnum);
>         mtd->name = dev_name[devnum];
>
> @@ -83,18 +86,28 @@ int nand_register(int devnum, struct mtd_info *mtd)
>  #ifndef CONFIG_SYS_NAND_SELF_INIT
>  static void nand_init_chip(int i)
>  {
> +#ifndef CONFIG_DM_NAND
>         struct nand_chip *nand = &nand_chip[i];
>         struct mtd_info *mtd = nand_to_mtd(nand);
>         ulong base_addr = base_address[i];
> +#else
> +       struct mtd_info *mtd;
> +#endif
>         int maxchips = CONFIG_SYS_NAND_MAX_CHIPS;
>
>         if (maxchips < 1)
>                 maxchips = 1;
>
> +#ifdef CONFIG_DM_NAND
> +       mtd = get_nand_dev_by_index(i);
> +       if (!mtd)
> +               return;
> +#else
>         nand->IO_ADDR_R = nand->IO_ADDR_W = (void  __iomem *)base_addr;
>
>         if (board_nand_init(nand))
>                 return;
> +#endif
>
>         if (nand_scan(mtd, maxchips))
>                 return;
> diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> index 8c92d0b..6556dc8 100644
> --- a/include/dm/uclass-id.h
> +++ b/include/dm/uclass-id.h
> @@ -49,6 +49,7 @@ enum uclass_id {
>         UCLASS_MMC,             /* SD / MMC card or chip */
>         UCLASS_MOD_EXP,         /* RSA Mod Exp device */
>         UCLASS_MTD,             /* Memory Technology Device (MTD) device */
> +       UCLASS_NAND,            /* NAND device */
>         UCLASS_NORTHBRIDGE,     /* Intel Northbridge / SDRAM controller */
>         UCLASS_PANEL,           /* Display panel, such as an LCD */
>         UCLASS_PANEL_BACKLIGHT, /* Backlight controller for panel */
> --
> 2.10.1.dirty
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass
  2017-02-06 15:34   ` Simon Glass
@ 2017-02-06 18:39     ` Grygorii Strashko
  2017-02-10 16:22       ` Simon Glass
  0 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-02-06 18:39 UTC (permalink / raw)
  To: u-boot



On 02/06/2017 09:34 AM, Simon Glass wrote:
> Hi,
>
> On 31 January 2017 at 13:37, Grygorii Strashko <grygorii.strashko@ti.com> wrote:
>> From: Mugunthan V N <mugunthanvnm@ti.com>
>>
>> Implement a NAND uclass so that the NAND devices can be
>> accessed via the DM framework.
>>
>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>> ---
>>  drivers/mtd/nand/Kconfig       | 10 ++++++++++
>>  drivers/mtd/nand/Makefile      |  2 ++
>>  drivers/mtd/nand/nand-uclass.c | 38 ++++++++++++++++++++++++++++++++++++++
>>  drivers/mtd/nand/nand.c        | 17 +++++++++++++++--
>>  include/dm/uclass-id.h         |  1 +
>>  5 files changed, 66 insertions(+), 2 deletions(-)
>>  create mode 100644 drivers/mtd/nand/nand-uclass.c
>>

[...]

>> +
>> +DECLARE_GLOBAL_DATA_PTR;
>> +
>> +struct mtd_info *get_nand_dev_by_index(int idx)
>> +{
>> +       struct nand_chip *chip;
>> +       struct udevice *dev;
>> +       int ret;
>> +
>> +       ret = uclass_get_device(UCLASS_NAND, idx, &dev);
>> +       if (ret) {
>> +               debug("NAND device (%d) not found\n", idx);
>> +               return NULL;
>> +       }
>> +
>> +       chip = (struct nand_chip *)dev_get_priv(dev);
>> +
>> +       return nand_to_mtd(chip);
>
> Can you add some comments to the nand.h header file (perhaps within
> #ifdef CONFIG_DM_NAND) to explain that drivers must have struct
> nand_chip as the first part of their private data? Assuming I have
> this right...
>

Will below work for you?

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index d55807b..567f286 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -684,6 +684,16 @@ struct nand_buffers {
   *                     correctable).
   * @write_page:                [REPLACEABLE] High-level page write 
function
   */
+#ifdef CONFIG_DM_NAND
+/**
+ * DM compatible nand drivers must have struct nand_chip as
+ * the first part of their private data:
+ * U_BOOT_DRIVER(...) = {
+ *     ...
+ *             .priv_auto_alloc_size = sizeof(struct nand_chip),
+ * };
+ */
+#endif

  struct nand_chip {
         struct mtd_info mtd;


>> +}
>> +
>> +UCLASS_DRIVER(nand) = {
>> +       .id                             = UCLASS_NAND,
>> +       .name                           = "nand",
>> +       .flags                          = DM_UC_FLAG_SEQ_ALIAS,
>> +};
>
> Also can we have a sandbox NAND driver and some tests.
>

Sry, for the stupid question, but what's "sandbox NAND driver"? Any ref?

Also does it really required to be done as part of this series?

-- 
regards,
-grygorii

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-06 18:40     ` Grygorii Strashko
  0 siblings, 0 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-02-06 18:40 UTC (permalink / raw)
  To: u-boot



On 02/05/2017 07:57 PM, Tom Rini wrote:
> On Tue, Jan 31, 2017 at 03:37:13PM -0600, Grygorii Strashko wrote:
>
>> From: Mugunthan V N <mugunthanvnm@ti.com>
>>
>> adopt omap_gpmc driver to driver model.
>>
>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>> ---
>>  drivers/mtd/nand/omap_gpmc.c | 205 +++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 205 insertions(+)
>
> Is there any way we can do this while sharing more of the code between
> the DM and non-DM versions?
>

I could try combine code from board_nand_init and omap_gpmc_probe.

-- 
regards,
-grygorii

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm
  2017-02-06  1:56 ` [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Tom Rini
@ 2017-02-06 18:50   ` Grygorii Strashko
  2017-02-07 17:19     ` Tom Rini
  0 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-02-06 18:50 UTC (permalink / raw)
  To: u-boot

Hi Tom,

On 02/05/2017 07:56 PM, Tom Rini wrote:
> On Tue, Jan 31, 2017 at 03:37:02PM -0600, Grygorii Strashko wrote:
> 
>> This patch seires adds nand uclass driver and enables omap_gpmc to
>> adopt driver model. This has been tested on AM335x GP EVM and
>> AM437x GP EVM.
>>
>> As preparation for introducing nand uclass driver the new API
>> get_nand_dev_by_index() was added to avoid direct acces to nand_info array and
>> u-boot core files were updated to use it.
>>
>> Patches can be found at:
>> git at git.ti.com:~gragst/ti-u-boot/gragsts-ti-u-boot.git dm-nand-v2
> 
> My conceptual concern here is that we need to address (as I've stated
> elsewhere) the need to get DM/DT support within SPL on these families
> (and yes, figure out what we'll do with respect to HS and the further
> size constraints) before we push farther down this path of DM/DT
> conversion as it's adding more #if/#else/#endif code that we need to be
> able to drop.  Thanks!
> 

I understand your concern and see it's discussed now in [1], but I'd 
like to understand how to proceed with this series.

The original patches from from Mugunthan are at about 1 year old and
and it took me pretty a lot of time to just re-base them properly,
so will it be acceptable if i will re-send only patches 1-10 as they are
do not depend on TI SPL and will unblock DM conversation of other drivers?
Really want to reduce existed patch queue :(

[1] https://www.mail-archive.com/u-boot at lists.denx.de/msg237938.html
-- 
regards,
-grygorii

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm
  2017-02-06 18:50   ` Grygorii Strashko
@ 2017-02-07 17:19     ` Tom Rini
  0 siblings, 0 replies; 48+ messages in thread
From: Tom Rini @ 2017-02-07 17:19 UTC (permalink / raw)
  To: u-boot

On Mon, Feb 06, 2017 at 12:50:25PM -0600, Grygorii Strashko wrote:
> Hi Tom,
> 
> On 02/05/2017 07:56 PM, Tom Rini wrote:
> > On Tue, Jan 31, 2017 at 03:37:02PM -0600, Grygorii Strashko wrote:
> > 
> >> This patch seires adds nand uclass driver and enables omap_gpmc to
> >> adopt driver model. This has been tested on AM335x GP EVM and
> >> AM437x GP EVM.
> >>
> >> As preparation for introducing nand uclass driver the new API
> >> get_nand_dev_by_index() was added to avoid direct acces to nand_info array and
> >> u-boot core files were updated to use it.
> >>
> >> Patches can be found at:
> >> git at git.ti.com:~gragst/ti-u-boot/gragsts-ti-u-boot.git dm-nand-v2
> > 
> > My conceptual concern here is that we need to address (as I've stated
> > elsewhere) the need to get DM/DT support within SPL on these families
> > (and yes, figure out what we'll do with respect to HS and the further
> > size constraints) before we push farther down this path of DM/DT
> > conversion as it's adding more #if/#else/#endif code that we need to be
> > able to drop.  Thanks!
> > 
> 
> I understand your concern and see it's discussed now in [1], but I'd 
> like to understand how to proceed with this series.
> 
> The original patches from from Mugunthan are at about 1 year old and
> and it took me pretty a lot of time to just re-base them properly,
> so will it be acceptable if i will re-send only patches 1-10 as they are
> do not depend on TI SPL and will unblock DM conversation of other drivers?
> Really want to reduce existed patch queue :(
> 
> [1] https://www.mail-archive.com/u-boot at lists.denx.de/msg237938.html

We can take up some of the underlying patches now, yes.  But we really
need to do the DM conversion fully, in order to really unblock progress.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170207/875a20cb/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [U-Boot, v2, 02/15] cmd: nand: abstract global variable usage for dm conversion
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
  2017-02-06 15:33   ` Simon Glass
@ 2017-02-08 21:23   ` Tom Rini
  2 siblings, 0 replies; 48+ messages in thread
From: Tom Rini @ 2017-02-08 21:23 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:04PM -0600, Grygorii Strashko wrote:

> From: Mugunthan V N <mugunthanvnm@ti.com>
> 
> 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>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

So this is incomplete and breaks omap3_beagle booting for example, we
hang during bootup.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170208/f43929d0/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [U-Boot, v2, 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND Grygorii Strashko
  2017-02-06  1:56   ` Tom Rini
@ 2017-02-09  3:03   ` Tom Rini
  1 sibling, 0 replies; 48+ messages in thread
From: Tom Rini @ 2017-02-09  3:03 UTC (permalink / raw)
  To: u-boot

On Tue, Jan 31, 2017 at 03:37:03PM -0600, Grygorii Strashko wrote:

> Now when CONFIG_CMD_IMLS_NAND is enabled the u-boot build will fail,
> because nand_read_skip_bad() function has been changed to accept more
> parameters, hence fix it.
> 
>  CC      cmd/bootm.o
> cmd/bootm.c: In function 'nand_imls_legacyimage':
> cmd/bootm.c:390:8: error: too few arguments to function 'nand_read_skip_bad'
>   ret = nand_read_skip_bad(mtd, off, &len, imgdata);
>         ^
> In file included from cmd/bootm.c:18:0:
> include/nand.h:101:5: note: declared here
>  int nand_read_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
>      ^
>  LD      drivers/block/built-in.o
> 
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170208/b04c258e/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-09 17:51     ` Grygorii Strashko
  2017-02-09 18:12       ` Tom Rini
  0 siblings, 1 reply; 48+ messages in thread
From: Grygorii Strashko @ 2017-02-09 17:51 UTC (permalink / raw)
  To: u-boot

Hi Tom,

On 02/05/2017 07:57 PM, Tom Rini wrote:
> On Tue, Jan 31, 2017 at 03:37:04PM -0600, Grygorii Strashko wrote:
> 
>> From: Mugunthan V N <mugunthanvnm@ti.com>
>>
>> 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>
> 
> Reviewed-by: Tom Rini <trini@konsulko.com>
> 

Sry, I've not received your last comment:
"So this is incomplete and breaks omap3_beagle booting for example, we
hang during bootup."

I have one question - was boot tested only with this patch or with whole series?

-- 
regards,
-grygorii

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion
  2017-02-09 17:51     ` Grygorii Strashko
@ 2017-02-09 18:12       ` Tom Rini
  0 siblings, 0 replies; 48+ messages in thread
From: Tom Rini @ 2017-02-09 18:12 UTC (permalink / raw)
  To: u-boot

On Thu, Feb 09, 2017 at 11:51:38AM -0600, Grygorii Strashko wrote:
> Hi Tom,
> 
> On 02/05/2017 07:57 PM, Tom Rini wrote:
> > On Tue, Jan 31, 2017 at 03:37:04PM -0600, Grygorii Strashko wrote:
> > 
> >> From: Mugunthan V N <mugunthanvnm@ti.com>
> >>
> >> 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>
> > 
> > Reviewed-by: Tom Rini <trini@konsulko.com>
> > 
> 
> Sry, I've not received your last comment:
> "So this is incomplete and breaks omap3_beagle booting for example, we
> hang during bootup."
> 
> I have one question - was boot tested only with this patch or with whole series?

I tested with up until the TI driver was converted itself.  So... if
this series requires all drivers to have been converted in order to not
hang, then you need to convert all of the drivers to use the helper to
not break bisectability.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170209/e75a958c/attachment.sig>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass
  2017-02-06 18:39     ` Grygorii Strashko
@ 2017-02-10 16:22       ` Simon Glass
  2017-02-10 18:23         ` Grygorii Strashko
  0 siblings, 1 reply; 48+ messages in thread
From: Simon Glass @ 2017-02-10 16:22 UTC (permalink / raw)
  To: u-boot

Hi,

On 6 February 2017 at 11:39, Grygorii Strashko <grygorii.strashko@ti.com> wrote:
>
>
> On 02/06/2017 09:34 AM, Simon Glass wrote:
>>
>> Hi,
>>
>> On 31 January 2017 at 13:37, Grygorii Strashko <grygorii.strashko@ti.com>
>> wrote:
>>>
>>> From: Mugunthan V N <mugunthanvnm@ti.com>
>>>
>>> Implement a NAND uclass so that the NAND devices can be
>>> accessed via the DM framework.
>>>
>>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>>> ---
>>>  drivers/mtd/nand/Kconfig       | 10 ++++++++++
>>>  drivers/mtd/nand/Makefile      |  2 ++
>>>  drivers/mtd/nand/nand-uclass.c | 38
>>> ++++++++++++++++++++++++++++++++++++++
>>>  drivers/mtd/nand/nand.c        | 17 +++++++++++++++--
>>>  include/dm/uclass-id.h         |  1 +
>>>  5 files changed, 66 insertions(+), 2 deletions(-)
>>>  create mode 100644 drivers/mtd/nand/nand-uclass.c
>>>
>
> [...]
>
>>> +
>>> +DECLARE_GLOBAL_DATA_PTR;
>>> +
>>> +struct mtd_info *get_nand_dev_by_index(int idx)
>>> +{
>>> +       struct nand_chip *chip;
>>> +       struct udevice *dev;
>>> +       int ret;
>>> +
>>> +       ret = uclass_get_device(UCLASS_NAND, idx, &dev);
>>> +       if (ret) {
>>> +               debug("NAND device (%d) not found\n", idx);
>>> +               return NULL;
>>> +       }
>>> +
>>> +       chip = (struct nand_chip *)dev_get_priv(dev);
>>> +
>>> +       return nand_to_mtd(chip);
>>
>>
>> Can you add some comments to the nand.h header file (perhaps within
>> #ifdef CONFIG_DM_NAND) to explain that drivers must have struct
>> nand_chip as the first part of their private data? Assuming I have
>> this right...
>>
>
> Will below work for you?
>
> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
> index d55807b..567f286 100644
> --- a/include/linux/mtd/nand.h
> +++ b/include/linux/mtd/nand.h
> @@ -684,6 +684,16 @@ struct nand_buffers {
>   *                     correctable).
>   * @write_page:                [REPLACEABLE] High-level page write function
>   */
> +#ifdef CONFIG_DM_NAND
> +/**
> + * DM compatible nand drivers must have struct nand_chip as
> + * the first part of their private data:
> + * U_BOOT_DRIVER(...) = {
> + *     ...
> + *             .priv_auto_alloc_size = sizeof(struct nand_chip),
> + * };
> + */
> +#endif

Seems good

>
>  struct nand_chip {
>         struct mtd_info mtd;
>
>
>>> +}
>>> +
>>> +UCLASS_DRIVER(nand) = {
>>> +       .id                             = UCLASS_NAND,
>>> +       .name                           = "nand",
>>> +       .flags                          = DM_UC_FLAG_SEQ_ALIAS,
>>> +};
>>
>>
>> Also can we have a sandbox NAND driver and some tests.
>>
>
> Sry, for the stupid question, but what's "sandbox NAND driver"? Any ref?

I mean you should create a NAND driver for sandbox. It should pretend
to be a NAND chip and support operation as such. There are various
sandbox drivers for other uclasses that do this.

Do you have any operations in your uclass? See for example struct
dm_mmc_ops. I added the MMC uclass without the operations, and it was
painful to add them later.

>
> Also does it really required to be done as part of this series?

Yes - any new uclass needs a test in test/dm. It can be a simple test, though.

Regards,
Simon

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model
  2017-01-31 21:37 ` [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model Grygorii Strashko
  2017-02-06  1:57   ` Tom Rini
@ 2017-02-10 16:22   ` Simon Glass
  1 sibling, 0 replies; 48+ messages in thread
From: Simon Glass @ 2017-02-10 16:22 UTC (permalink / raw)
  To: u-boot

Hi,

On 31 January 2017 at 14:37, Grygorii Strashko <grygorii.strashko@ti.com> wrote:
> From: Mugunthan V N <mugunthanvnm@ti.com>
>
> adopt omap_gpmc driver to driver model.
>
> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
> ---
>  drivers/mtd/nand/omap_gpmc.c | 205 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 205 insertions(+)
>

My only comment here is that it looks like read_buf and the like
should be operations implemented by the NAND uclass. See struct
dm_mmc_ops for how it works for mmc.

Regards,
Simon

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass
  2017-02-10 16:22       ` Simon Glass
@ 2017-02-10 18:23         ` Grygorii Strashko
  0 siblings, 0 replies; 48+ messages in thread
From: Grygorii Strashko @ 2017-02-10 18:23 UTC (permalink / raw)
  To: u-boot



On 02/10/2017 10:22 AM, Simon Glass wrote:
> Hi,
>
> On 6 February 2017 at 11:39, Grygorii Strashko <grygorii.strashko@ti.com> wrote:
>>
>>
>> On 02/06/2017 09:34 AM, Simon Glass wrote:
>>>
>>> Hi,
>>>
>>> On 31 January 2017 at 13:37, Grygorii Strashko <grygorii.strashko@ti.com>
>>> wrote:
>>>>
>>>> From: Mugunthan V N <mugunthanvnm@ti.com>
>>>>
>>>> Implement a NAND uclass so that the NAND devices can be
>>>> accessed via the DM framework.
>>>>
>>>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>>>> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
>>>> ---
>>>>  drivers/mtd/nand/Kconfig       | 10 ++++++++++
>>>>  drivers/mtd/nand/Makefile      |  2 ++
>>>>  drivers/mtd/nand/nand-uclass.c | 38
>>>> ++++++++++++++++++++++++++++++++++++++
>>>>  drivers/mtd/nand/nand.c        | 17 +++++++++++++++--
>>>>  include/dm/uclass-id.h         |  1 +
>>>>  5 files changed, 66 insertions(+), 2 deletions(-)
>>>>  create mode 100644 drivers/mtd/nand/nand-uclass.c
>>>>
>>
>> [...]
>>
>>>> +
>>>> +DECLARE_GLOBAL_DATA_PTR;
>>>> +
>>>> +struct mtd_info *get_nand_dev_by_index(int idx)
>>>> +{
>>>> +       struct nand_chip *chip;
>>>> +       struct udevice *dev;
>>>> +       int ret;
>>>> +
>>>> +       ret = uclass_get_device(UCLASS_NAND, idx, &dev);
>>>> +       if (ret) {
>>>> +               debug("NAND device (%d) not found\n", idx);
>>>> +               return NULL;
>>>> +       }
>>>> +
>>>> +       chip = (struct nand_chip *)dev_get_priv(dev);
>>>> +
>>>> +       return nand_to_mtd(chip);
>>>
>>>
>>> Can you add some comments to the nand.h header file (perhaps within
>>> #ifdef CONFIG_DM_NAND) to explain that drivers must have struct
>>> nand_chip as the first part of their private data? Assuming I have
>>> this right...
>>>
>>
>> Will below work for you?
>>
>> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
>> index d55807b..567f286 100644
>> --- a/include/linux/mtd/nand.h
>> +++ b/include/linux/mtd/nand.h
>> @@ -684,6 +684,16 @@ struct nand_buffers {
>>   *                     correctable).
>>   * @write_page:                [REPLACEABLE] High-level page write function
>>   */
>> +#ifdef CONFIG_DM_NAND
>> +/**
>> + * DM compatible nand drivers must have struct nand_chip as
>> + * the first part of their private data:
>> + * U_BOOT_DRIVER(...) = {
>> + *     ...
>> + *             .priv_auto_alloc_size = sizeof(struct nand_chip),
>> + * };
>> + */
>> +#endif
>
> Seems good
>
>>
>>  struct nand_chip {
>>         struct mtd_info mtd;
>>
>>
>>>> +}
>>>> +
>>>> +UCLASS_DRIVER(nand) = {
>>>> +       .id                             = UCLASS_NAND,
>>>> +       .name                           = "nand",
>>>> +       .flags                          = DM_UC_FLAG_SEQ_ALIAS,
>>>> +};
>>>
>>>
>>> Also can we have a sandbox NAND driver and some tests.
>>>
>>
>> Sry, for the stupid question, but what's "sandbox NAND driver"? Any ref?
>
> I mean you should create a NAND driver for sandbox. It should pretend
> to be a NAND chip and support operation as such. There are various
> sandbox drivers for other uclasses that do this.
>
> Do you have any operations in your uclass? See for example struct
> dm_mmc_ops. I added the MMC uclass without the operations, and it was
> painful to add them later.
>
>>
>> Also does it really required to be done as part of this series?
>
> Yes - any new uclass needs a test in test/dm. It can be a simple test, though.
>

ok. i understood your requests, but, unfortunately, I'm not sure
that i'll be able to satisfy them now :( - i'm pretty limited in time.

For now I'll resend preparation patches get_nand_dev_by_index() and will 
try to get back here as soon as i can.

-- 
regards,
-grygorii

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2017-02-10 18:23 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-31 21:37 [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Grygorii Strashko
2017-01-31 21:37 ` [U-Boot] [PATCH v2 01/15] cmd: bootm: fix build when CONFIG_CMD_IMLS_NAND Grygorii Strashko
2017-02-06  1:56   ` Tom Rini
2017-02-06 15:33     ` Simon Glass
2017-02-09  3:03   ` [U-Boot] [U-Boot, v2, " Tom Rini
2017-01-31 21:37 ` [U-Boot] [PATCH v2 02/15] cmd: nand: abstract global variable usage for dm conversion Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-09 17:51     ` Grygorii Strashko
2017-02-09 18:12       ` Tom Rini
2017-02-06 15:33   ` Simon Glass
2017-02-08 21:23   ` [U-Boot] [U-Boot, v2, " Tom Rini
2017-01-31 21:37 ` [U-Boot] [PATCH v2 03/15] common: env_nand: use get_nand_dev_by_index() Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-06 15:33     ` Simon Glass
2017-01-31 21:37 ` [U-Boot] [PATCH v2 04/15] dfu: dfu_nand: " Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-06 15:34     ` Simon Glass
2017-01-31 21:37 ` [U-Boot] [PATCH v2 05/15] cmd: bootm: " Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-06 15:34     ` Simon Glass
2017-01-31 21:37 ` [U-Boot] [PATCH v2 06/15] cmd: jffs2: " Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-06 15:34     ` Simon Glass
2017-01-31 21:37 ` [U-Boot] [PATCH v2 07/15] common: " Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-06 15:33     ` Simon Glass
2017-01-31 21:37 ` [U-Boot] [PATCH v2 08/15] fs: " Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-06 15:34     ` Simon Glass
2017-01-31 21:37 ` [U-Boot] [PATCH v2 09/15] cmd: nand: remove direct access to struct mtd_info->priv Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-06 15:34   ` Simon Glass
2017-01-31 21:37 ` [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass Grygorii Strashko
2017-02-06 15:34   ` Simon Glass
2017-02-06 18:39     ` Grygorii Strashko
2017-02-10 16:22       ` Simon Glass
2017-02-10 18:23         ` Grygorii Strashko
2017-01-31 21:37 ` [U-Boot] [PATCH v2 11/15] drivers: nand: omap_gpmc: convert driver to adopt driver model Grygorii Strashko
2017-02-06  1:57   ` Tom Rini
2017-02-06 18:40     ` Grygorii Strashko
2017-02-10 16:22   ` Simon Glass
2017-01-31 21:37 ` [U-Boot] [PATCH v2 12/15] am43xx_evm: nand: do not define DM_NAND for spl Grygorii Strashko
2017-01-31 21:37 ` [U-Boot] [PATCH v2 13/15] defconfig: am43xx_evm: enable NAND driver model Grygorii Strashko
2017-01-31 21:37 ` [U-Boot] [PATCH v2 14/15] am335x_evm: nand: do not define DM_NAND for spl Grygorii Strashko
2017-01-31 21:37 ` [U-Boot] [PATCH v2 15/15] defconfig: am335x_evm: enable NAND driver model Grygorii Strashko
2017-02-06  1:56 ` [U-Boot] [PATCH v2 00/15] nand: device model bringup on am335x evm and am437x gpevm Tom Rini
2017-02-06 18:50   ` Grygorii Strashko
2017-02-07 17:19     ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.