diff mbox

[v6,3/3] mtd: spi-nor: Add spi-nor mtd suspend and resume handlers

Message ID 1487967399-28967-4-git-send-email-kdasu.kdev@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kamal Dasu Feb. 24, 2017, 8:16 p.m. UTC
Implemented and populated spi-nor mtd PM handlers for suspend and resume ops.
spi-nor suspend op set's the flash state to FL_PM_SUSPENDED state and resume
op re-initializes spi-nor flash and set's flash state to FL_READY. The handlers
ensures synchronization between the spi-nor and the mtd layer by calling
spi_nor_get/release_device() and setting respective flash states.

Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
---
 drivers/mtd/spi-nor/spi-nor.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox

Patch

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 5363807..8e38895 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1629,6 +1629,28 @@  int spi_nor_init(struct spi_nor *nor)
 }
 EXPORT_SYMBOL_GPL(spi_nor_init);
 
+/* mtd suspend handler */
+static int spi_nor_suspend(struct mtd_info *mtd)
+{
+	return spi_nor_get_device(mtd, FL_PM_SUSPENDED);
+}
+
+/* mtd resume handler */
+static void spi_nor_resume(struct mtd_info *mtd)
+{
+	struct spi_nor *nor = mtd_to_spi_nor(mtd);
+	struct device *dev = nor->dev;
+
+	if (nor->state == FL_PM_SUSPENDED) {
+		/* re-initialize the nor chip */
+		spi_nor_init(nor);
+		/* mtd can resume transfers */
+		spi_nor_release_device(mtd);
+	} else {
+	       dev_err(dev, "resume() called, chip not in suspended state\n");
+	}
+}
+
 int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
 {
 	const struct flash_info *info = NULL;
@@ -1695,6 +1717,8 @@  int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
 	mtd->size = info->sector_size * info->n_sectors;
 	mtd->_erase = spi_nor_erase;
 	mtd->_read = spi_nor_read;
+	mtd->_suspend = spi_nor_suspend;
+	mtd->_resume = spi_nor_resume;
 
 	/* NOR protection support for STmicro/Micron chips and similar */
 	if (JEDEC_MFR(info) == SNOR_MFR_MICRON ||