From: Kamal Dasu Subject: [PATCH v6 3/3] mtd: spi-nor: Add spi-nor mtd suspend and resume handlers Date: Fri, 24 Feb 2017 15:16:39 -0500 Message-ID: <1487967399-28967-4-git-send-email-kdasu.kdev@gmail.com> References: <1487967399-28967-1-git-send-email-kdasu.kdev@gmail.com> Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/w@public.gmane.org, Kamal Dasu To: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, cyrille.pitchen-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org, marex-ynQEQJNshbs@public.gmane.org, broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org Return-path: In-Reply-To: <1487967399-28967-1-git-send-email-kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Sender: linux-spi-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: 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 --- drivers/mtd/spi-nor/spi-nor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 || -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html