nand: davinci: add support for driver model
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 29 Jul 2019 06:58:03 +0000 (08:58 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 29 Jul 2019 21:58:52 +0000 (17:58 -0400)
Extend the davinci NAND driver to support the driver model. For now this
doesn't add any device-tree parsing due to the fact that we can't access
the actual nand node on the device-tree - it's a subnode of the aemif
device and we don't have an aemif driver on davinci at the moment.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
drivers/mtd/nand/raw/davinci_nand.c

index e1c4498cb90b36f47254e64d91da0d8bf664e3f2..33c2f16be8bd9d2d0848c78d82b9bc5fe9346ef0 100644 (file)
@@ -31,6 +31,7 @@
 #include <common.h>
 #include <asm/io.h>
 #include <nand.h>
+#include <dm/uclass.h>
 #include <asm/ti-common/davinci_nand.h>
 
 /* Definitions for 4-bit hardware ECC */
@@ -785,10 +786,53 @@ static void davinci_nand_init(struct nand_chip *nand)
        nand->dev_ready = nand_davinci_dev_ready;
 }
 
-int board_nand_init(struct nand_chip *chip) __attribute__((weak));
+#ifdef CONFIG_SYS_NAND_SELF_INIT
+static int davinci_nand_probe(struct udevice *dev)
+{
+       struct nand_chip *nand = dev_get_priv(dev);
+       struct mtd_info *mtd = nand_to_mtd(nand);
+       int ret;
+
+       nand->IO_ADDR_R = (void __iomem *)CONFIG_SYS_NAND_BASE;
+       nand->IO_ADDR_W = (void __iomem *)CONFIG_SYS_NAND_BASE;
+
+       davinci_nand_init(nand);
+
+       ret = nand_scan(mtd, CONFIG_SYS_NAND_MAX_CHIPS);
+       if (ret)
+               return ret;
+
+       return nand_register(0, mtd);
+}
+
+static const struct udevice_id davinci_nand_ids[] = {
+       { .compatible = "ti,davinci-nand" },
+       { }
+};
+
+U_BOOT_DRIVER(davinci_nand) = {
+       .name           = "davinci-nand",
+       .id             = UCLASS_MTD,
+       .of_match       = davinci_nand_ids,
+       .probe          = davinci_nand_probe,
+       .priv_auto_alloc_size = sizeof(struct nand_chip),
+};
+
+void board_nand_init(void)
+{
+       struct udevice *dev;
+       int ret;
 
+       ret = uclass_get_device_by_driver(UCLASS_MTD,
+                                         DM_GET_DRIVER(davinci_nand), &dev);
+       if (ret && ret != -ENODEV)
+               pr_err("Failed to initialize %s: %d\n", dev->name, ret);
+}
+#else
+int board_nand_init(struct nand_chip *chip) __attribute__((weak));
 int board_nand_init(struct nand_chip *chip)
 {
        davinci_nand_init(chip);
        return 0;
 }
+#endif /* CONFIG_SYS_NAND_SELF_INIT */