By analogy with RAW NAND drivers, select SYS_NAND_SELF_INIT
option and implement board_nand_init() function. It will be
called from nand_init().

Signed-off-by: Alexey Romanov <avroma...@salutedevices.com>
---
 drivers/mtd/nand/spi/Kconfig |  1 +
 drivers/mtd/nand/spi/core.c  | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/mtd/nand/spi/Kconfig b/drivers/mtd/nand/spi/Kconfig
index 0777dfdf0a..c9ca76a1c9 100644
--- a/drivers/mtd/nand/spi/Kconfig
+++ b/drivers/mtd/nand/spi/Kconfig
@@ -2,6 +2,7 @@ menuconfig MTD_SPI_NAND
        bool "SPI NAND device Support"
        depends on DM_MTD && DM_SPI
        select MTD_NAND_CORE
+       select SYS_NAND_SELF_INIT
        select SPI_MEM
        help
          This is the framework for the SPI NAND device drivers.
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 202e3f11ec..27ad6fefdb 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -28,6 +28,7 @@
 #include <spi-mem.h>
 #include <dm/device_compat.h>
 #include <dm/devres.h>
+#include <dm/uclass.h>
 #include <linux/bitops.h>
 #include <linux/bug.h>
 #include <linux/mtd/spinand.h>
@@ -1296,3 +1297,16 @@ U_BOOT_DRIVER(spinand) = {
        .priv_auto      = sizeof(struct spinand_device),
        .probe = spinand_probe,
 };
+
+void board_nand_init(void)
+{
+       struct udevice *dev;
+       int ret;
+
+       ret = uclass_get_device_by_driver(UCLASS_SPI,
+                                         DM_DRIVER_GET(spinand),
+                                         &dev);
+       if (ret && ret != -ENODEV)
+               log_err("Failed to initialize SPI NAND driver. (error %d)\n",
+                       ret);
+}
-- 
2.30.1

Reply via email to