summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorApurva Nandan <a-nandan@ti.com>2023-01-23 23:13:29 +0530
committerPraneeth Bajjuri <praneeth@ti.com>2023-01-25 14:10:19 -0600
commit341effe314230347f952776b4ac660229613f47a (patch)
tree853ccee9c96a1a5e0f8bb0e94e0d6a6a655b6bc0 /drivers
parent13e96746ab470bbe7b44cde9b4a548946ff99c10 (diff)
spl: mtd: Remove MTD device after loading images
Releasing the flash into proper state, after the loading completes, is important for the next stage bootloader/kernel to be able to use the MTD device. This would enable to reset the device for fresh use by next boot stage. Signed-off-by: Apurva Nandan <a-nandan@ti.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/mtd-uclass.c12
-rw-r--r--drivers/mtd/nand/spi/core.c11
2 files changed, 18 insertions, 5 deletions
diff --git a/drivers/mtd/mtd-uclass.c b/drivers/mtd/mtd-uclass.c
index 5418217431..cf749b4a16 100644
--- a/drivers/mtd/mtd-uclass.c
+++ b/drivers/mtd/mtd-uclass.c
@@ -24,6 +24,18 @@ int mtd_probe(struct udevice *dev)
return device_probe(dev);
}
+/**
+ * mtd_remove - Remove the device @dev
+ *
+ * @dev: U-Boot device to probe
+ *
+ * @return 0 on success, an error otherwise.
+ */
+int mtd_remove(struct mtd_info *mtd)
+{
+ return device_remove(mtd->dev, DM_REMOVE_NORMAL);
+}
+
/*
* Implement a MTD uclass which should include most flash drivers.
* The uclass private is pointed to mtd_info.
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index f3dab39930..0c88310e28 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -1297,26 +1297,25 @@ err_spinand_cleanup:
return ret;
}
-#ifndef __UBOOT__
static int spinand_remove(struct udevice *slave)
{
- struct spinand_device *spinand;
+ struct spinand_device *spinand = dev_get_priv(slave);
struct mtd_info *mtd;
- int ret;
- spinand = spi_mem_get_drvdata(slave);
mtd = spinand_to_mtd(spinand);
free(mtd->name);
+#ifndef __UBOOT__
ret = mtd_device_unregister(mtd);
if (ret)
return ret;
-
+#endif
spinand_cleanup(spinand);
return 0;
}
+#ifndef __UBOOT__
static const struct spi_device_id spinand_ids[] = {
{ .name = "spi-nand" },
{ /* sentinel */ },
@@ -1358,4 +1357,6 @@ U_BOOT_DRIVER(spinand) = {
.of_match = spinand_ids,
.priv_auto_alloc_size = sizeof(struct spinand_device),
.probe = spinand_probe,
+ .remove = spinand_remove,
+ .flags = DM_FLAG_OS_PREPARE,
};