From: Grygorii Strashko <grygorii.strashko@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass
Date: Tue, 31 Jan 2017 15:37:12 -0600 [thread overview]
Message-ID: <20170131213717.30745-11-grygorii.strashko@ti.com> (raw)
In-Reply-To: <20170131213717.30745-1-grygorii.strashko@ti.com>
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
next prev parent reply other threads:[~2017-01-31 21:37 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Grygorii Strashko [this message]
2017-02-06 15:34 ` [U-Boot] [PATCH v2 10/15] drivers: nand: implement a NAND uclass 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170131213717.30745-11-grygorii.strashko@ti.com \
--to=grygorii.strashko@ti.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.