[U-Boot] [PATCH 0/2] Add denali DT driver

1/2 is required for 2/2. Denali NAND controller has two reg regions named "nand_data" and "denali_reg" as described by Documentation/devicetree/bindings/mtd/denali-nand.txt
Masahiro Yamada (2): ofnode: add {ofnode,dev}_read_resource_byname() mtd: nand: denali_dt: add a DT driver
drivers/core/ofnode.c | 12 ++++++++ drivers/core/read.c | 6 ++++ drivers/mtd/nand/Kconfig | 7 +++++ drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/denali.c | 4 ++- drivers/mtd/nand/denali.h | 2 ++ drivers/mtd/nand/denali_dt.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ include/dm/ofnode.h | 2 ++ include/dm/read.h | 20 ++++++++++++- 9 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 drivers/mtd/nand/denali_dt.c

Linux supports platform_get_resource_byname() to look up a resource by name.
We want a similar helper. It is useful when a device node has two or more named register regions.
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com ---
drivers/core/ofnode.c | 12 ++++++++++++ drivers/core/read.c | 6 ++++++ include/dm/ofnode.h | 2 ++ include/dm/read.h | 20 +++++++++++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index c1a2e9f0daef..0685b689d846 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -627,3 +627,15 @@ int ofnode_read_resource(ofnode node, uint index, struct resource *res) return 0; } } + +int ofnode_read_resource_byname(ofnode node, const char *name, + struct resource *res) +{ + int index; + + index = ofnode_stringlist_search(node, "reg-names", name); + if (index < 0) + return index; + + return ofnode_read_resource(node, index, res); +} diff --git a/drivers/core/read.c b/drivers/core/read.c index fe40bed64de3..6acb33388f56 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -164,3 +164,9 @@ int dev_read_resource(struct udevice *dev, uint index, struct resource *res) { return ofnode_read_resource(dev_ofnode(dev), index, res); } + +int dev_read_resource_byname(struct udevice *dev, const char *name, + struct resource *res) +{ + return ofnode_read_resource_byname(dev_ofnode(dev), name, res); +} diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 210ddb2e5d74..de2769ed5376 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -625,5 +625,7 @@ int ofnode_read_simple_size_cells(ofnode node); bool ofnode_pre_reloc(ofnode node);
int ofnode_read_resource(ofnode node, uint index, struct resource *res); +int ofnode_read_resource_byname(ofnode node, const char *name, + struct resource *res);
#endif diff --git a/include/dm/read.h b/include/dm/read.h index c3a4a5611a70..49d69c990f6e 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -359,13 +359,24 @@ int dev_read_enabled(struct udevice *dev); /** * dev_read_resource() - obtain an indexed resource from a device. * - * @dev: devuce to examine + * @dev: device to examine * @index index of the resource to retrieve (0 = first) * @res returns the resource * @return 0 if ok, negative on error */ int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
+/** + * dev_read_resource_byname() - obtain a named resource from a device. + * + * @dev: device to examine + * @name: name of the resource to retrieve + * @res: returns the resource + * @return 0 if ok, negative on error + */ +int dev_read_resource_byname(struct udevice *dev, const char *name, + struct resource *res); + #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
static inline int dev_read_u32_default(struct udevice *dev, @@ -513,6 +524,13 @@ static inline int dev_read_resource(struct udevice *dev, uint index, return ofnode_read_resource(dev_ofnode(dev), index, res); }
+static inline int dev_read_resource_byname(struct udevice *dev, + const char *name, + struct resource *res) +{ + return ofnode_read_resource_byname(dev_ofnode(dev), name, res); +} + #endif /* CONFIG_DM_DEV_READ_INLINE */
/**

On 25 August 2017 at 10:12, Masahiro Yamada yamada.masahiro@socionext.com wrote:
Linux supports platform_get_resource_byname() to look up a resource by name.
We want a similar helper. It is useful when a device node has two or more named register regions.
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com
drivers/core/ofnode.c | 12 ++++++++++++ drivers/core/read.c | 6 ++++++ include/dm/ofnode.h | 2 ++ include/dm/read.h | 20 +++++++++++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

A patch for NAND uclass support was proposed about half a year: https://patchwork.ozlabs.org/patch/722282/
It was not merged and I do not see on-going work for this.
Without DM-based probing, we need to set up pinctrl etc. in an ad-hoc way and give lots of crappy CONFIG options for base addresses and properties, which are supposed to be specified by DT. This is painful.
This commit just provides a probe hook to retrieve "reg" from DT and allocate private data in a DM manner. This DT driver is not essentially a NAND driver, in fact it is (ab)using UCLASS_MISC. Once UCLASS_NAND is supported, it would be possible to migrate to it.
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com ---
drivers/mtd/nand/Kconfig | 7 +++++ drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/denali.c | 4 ++- drivers/mtd/nand/denali.h | 2 ++ drivers/mtd/nand/denali_dt.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 drivers/mtd/nand/denali_dt.c
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig index 71d678fc66b5..85b26d608851 100644 --- a/drivers/mtd/nand/Kconfig +++ b/drivers/mtd/nand/Kconfig @@ -16,6 +16,13 @@ config NAND_DENALI help Enable support for the Denali NAND controller.
+config NAND_DENALI_DT + bool "Support Denali NAND controller as a DT device" + depends on NAND_DENALI && OF_CONTROL && DM + help + Enable the driver for NAND flash on platforms using a Denali NAND + controller as a DT device. + config SYS_NAND_DENALI_64BIT bool "Use 64-bit variant of Denali NAND controller" depends on NAND_DENALI diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index c3d4a996f37f..9f7d9d6ff7ae 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_NAND_ATMEL) += atmel_nand.o obj-$(CONFIG_NAND_ARASAN) += arasan_nfc.o obj-$(CONFIG_NAND_DAVINCI) += davinci_nand.o obj-$(CONFIG_NAND_DENALI) += denali.o +obj-$(CONFIG_NAND_DENALI_DT) += denali_dt.o obj-$(CONFIG_NAND_FSL_ELBC) += fsl_elbc_nand.o obj-$(CONFIG_NAND_FSL_IFC) += fsl_ifc_nand.o obj-$(CONFIG_NAND_FSL_UPM) += fsl_upm.o diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 18280b0b2fe8..47cf37d1d9b7 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -1175,7 +1175,7 @@ static void denali_hw_init(struct denali_nand_info *denali)
static struct nand_ecclayout nand_oob;
-static int denali_init(struct denali_nand_info *denali) +int denali_init(struct denali_nand_info *denali) { struct mtd_info *mtd = nand_to_mtd(&denali->nand); int ret; @@ -1273,6 +1273,7 @@ fail: return ret; }
+#ifndef CONFIG_NAND_DENALI_DT static int __board_nand_init(void) { struct denali_nand_info *denali; @@ -1296,3 +1297,4 @@ void board_nand_init(void) if (__board_nand_init() < 0) pr_warn("Failed to initialize Denali NAND controller.\n"); } +#endif diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h index 0e098bddf11d..694bce53a955 100644 --- a/drivers/mtd/nand/denali.h +++ b/drivers/mtd/nand/denali.h @@ -464,4 +464,6 @@ struct denali_nand_info { uint32_t max_banks; };
+int denali_init(struct denali_nand_info *denali); + #endif /* __DENALI_H__ */ diff --git a/drivers/mtd/nand/denali_dt.c b/drivers/mtd/nand/denali_dt.c new file mode 100644 index 000000000000..6a987c5b7880 --- /dev/null +++ b/drivers/mtd/nand/denali_dt.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 Socionext Inc. + * Author: Masahiro Yamada yamada.masahiro@socionext.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <linux/io.h> +#include <linux/ioport.h> + +#include "denali.h" + +static const struct udevice_id denali_nand_dt_ids[] = { + { + .compatible = "altr,socfpga-denali-nand", + }, + { + .compatible = "socionext,uniphier-denali-nand-v5a", + }, + { + .compatible = "socionext,uniphier-denali-nand-v5b", + }, + { /* sentinel */ } +}; + +static int denali_dt_probe(struct udevice *dev) +{ + struct denali_nand_info *denali = dev_get_priv(dev); + struct resource res; + int ret; + + ret = dev_read_resource_byname(dev, "denali_reg", &res); + if (ret) + return ret; + + denali->flash_reg = devm_ioremap(dev, res.start, resource_size(&res)); + + ret = dev_read_resource_byname(dev, "nand_data", &res); + if (ret) + return ret; + + denali->flash_mem = devm_ioremap(dev, res.start, resource_size(&res)); + + return denali_init(denali); +} + +U_BOOT_DRIVER(denali_nand_dt) = { + .name = "denali-nand-dt", + .id = UCLASS_MISC, + .of_match = denali_nand_dt_ids, + .probe = denali_dt_probe, + .priv_auto_alloc_size = sizeof(struct denali_nand_info), +}; + +void board_nand_init(void) +{ + struct udevice *dev; + int ret; + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_GET_DRIVER(denali_nand_dt), + &dev); + if (ret) + printf("Failed to initialize Denali NAND controller.\n"); +}

2017-08-26 1:12 GMT+09:00 Masahiro Yamada yamada.masahiro@socionext.com:
1/2 is required for 2/2. Denali NAND controller has two reg regions named "nand_data" and "denali_reg" as described by Documentation/devicetree/bindings/mtd/denali-nand.txt
Masahiro Yamada (2): ofnode: add {ofnode,dev}_read_resource_byname() mtd: nand: denali_dt: add a DT driver
Both applied to u-boot-uniphier.
participants (2)
-
Masahiro Yamada
-
Simon Glass