]> git.sur5r.net Git - u-boot/commitdiff
mtd: nand: mxs_nand: add device tree support
authorStefan Agner <stefan.agner@toradex.com>
Fri, 22 Jun 2018 16:06:17 +0000 (18:06 +0200)
committerStefano Babic <sbabic@denx.de>
Wed, 27 Jun 2018 07:07:55 +0000 (09:07 +0200)
Support driver data from device tree. Also support fsl,use-minimal-ecc
similar to Linux' GPMI NAND driver.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
drivers/mtd/nand/Kconfig
drivers/mtd/nand/Makefile
drivers/mtd/nand/mxs_nand.c
drivers/mtd/nand/mxs_nand_dt.c [new file with mode: 0644]

index c039b9cc6058c6dca2498a99b9dba213b3e04768..bdc272142e5f714618b9c24890b0f13bbb3ca849 100644 (file)
@@ -154,6 +154,13 @@ config NAND_MXS
 
 if NAND_MXS
 
+config NAND_MXS_DT
+       bool "Support MXS NAND controller as a DT device"
+       depends on OF_CONTROL && MTD
+       help
+         Enable the driver for MXS NAND flash on platforms using
+         device tree.
+
 config NAND_MXS_USE_MINIMUM_ECC
        bool "Use minimum ECC strength supported by the controller"
        default false
index e20ef0777380c1a37002bd08fd091a3a9fb4ef6f..e00cbca0a9a6dc5d5e4cb0b25e5d59c7b4d3101c 100644 (file)
@@ -55,6 +55,7 @@ obj-$(CONFIG_NAND_LPC32XX_SLC) += lpc32xx_nand_slc.o
 obj-$(CONFIG_NAND_VF610_NFC) += vf610_nfc.o
 obj-$(CONFIG_NAND_MXC) += mxc_nand.o
 obj-$(CONFIG_NAND_MXS) += mxs_nand.o
+obj-$(CONFIG_NAND_MXS_DT) += mxs_nand_dt.o
 obj-$(CONFIG_NAND_PXA3XX) += pxa3xx_nand.o
 obj-$(CONFIG_NAND_SPEAR) += spr_nand.o
 obj-$(CONFIG_TEGRA_NAND) += tegra_nand.o
index 8748c927c61a26789557d1363d58c32642a1942a..99f392ef5cb0cf40ee39c323b79d8b6de7c980c7 100644 (file)
@@ -1201,6 +1201,9 @@ int mxs_nand_init_ctrl(struct mxs_nand_info *nand_info)
        nand_set_controller_data(nand, nand_info);
        nand->options |= NAND_NO_SUBPAGE_WRITE;
 
+       if (nand_info->dev)
+               nand->flash_node = dev_of_offset(nand_info->dev);
+
        nand->cmd_ctrl          = mxs_nand_cmd_ctrl;
 
        nand->dev_ready         = mxs_nand_device_ready;
@@ -1247,6 +1250,7 @@ err_free_buffers:
        return err;
 }
 
+#ifndef CONFIG_NAND_MXS_DT
 void board_nand_init(void)
 {
        struct mxs_nand_info *nand_info;
@@ -1279,3 +1283,4 @@ void board_nand_init(void)
 err:
        free(nand_info);
 }
+#endif
diff --git a/drivers/mtd/nand/mxs_nand_dt.c b/drivers/mtd/nand/mxs_nand_dt.c
new file mode 100644 (file)
index 0000000..f89eb09
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * NXP GPMI NAND flash driver (DT initialization)
+ *
+ * Copyright (C) 2018 Toradex
+ * Authors:
+ * Stefan Agner <stefan.agner@toradex.com>
+ *
+ * Based on denali_dt.c
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <dm.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/printk.h>
+
+#include "mxs_nand.h"
+
+struct mxs_nand_dt_data {
+       unsigned int max_ecc_strength_supported;
+};
+
+static const struct mxs_nand_dt_data mxs_nand_imx7d_data = {
+       .max_ecc_strength_supported = 62,
+};
+
+static const struct udevice_id mxs_nand_dt_ids[] = {
+       {
+               .compatible = "fsl,imx7d-gpmi-nand",
+               .data = (unsigned long)&mxs_nand_imx7d_data,
+       },
+       { /* sentinel */ }
+};
+
+static int mxs_nand_dt_probe(struct udevice *dev)
+{
+       struct mxs_nand_info *info = dev_get_priv(dev);
+       const struct mxs_nand_dt_data *data;
+       struct resource res;
+       int ret;
+
+       data = (void *)dev_get_driver_data(dev);
+       if (data)
+               info->max_ecc_strength_supported = data->max_ecc_strength_supported;
+
+       info->dev = dev;
+
+       ret = dev_read_resource_byname(dev, "gpmi-nand", &res);
+       if (ret)
+               return ret;
+
+       info->gpmi_regs = devm_ioremap(dev, res.start, resource_size(&res));
+
+
+       ret = dev_read_resource_byname(dev, "bch", &res);
+       if (ret)
+               return ret;
+
+       info->bch_regs = devm_ioremap(dev, res.start, resource_size(&res));
+
+       info->use_minimum_ecc = dev_read_bool(dev, "fsl,use-minimum-ecc");
+
+       return mxs_nand_init_ctrl(info);
+}
+
+U_BOOT_DRIVER(mxs_nand_dt) = {
+       .name = "mxs-nand-dt",
+       .id = UCLASS_MTD,
+       .of_match = mxs_nand_dt_ids,
+       .probe = mxs_nand_dt_probe,
+       .priv_auto_alloc_size = sizeof(struct mxs_nand_info),
+};
+
+void board_nand_init(void)
+{
+       struct udevice *dev;
+       int ret;
+
+       ret = uclass_get_device_by_driver(UCLASS_MTD,
+                                         DM_GET_DRIVER(mxs_nand_dt),
+                                         &dev);
+       if (ret && ret != -ENODEV)
+               pr_err("Failed to initialize MXS NAND controller. (error %d)\n",
+                      ret);
+}