All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kamal Dasu <kdasu.kdev@gmail.com>
To: linux-spi@vger.kernel.org, cyrille.pitchen@atmel.com,
	marex@denx.de, broonie@kernel.org
Cc: linux-mtd@lists.infradead.org, f.fainelli@gmail.com,
	bcm-kernel-feedback-list@broadcom.com,
	Kamal Dasu <kdasu.kdev@gmail.com>
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	[thread overview]
Message-ID: <1487967399-28967-4-git-send-email-kdasu.kdev@gmail.com> (raw)
In-Reply-To: <1487967399-28967-1-git-send-email-kdasu.kdev@gmail.com>

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 --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

WARNING: multiple messages have this Message-ID (diff)
From: Kamal Dasu <kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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
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 <kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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	[thread overview]
Message-ID: <1487967399-28967-4-git-send-email-kdasu.kdev@gmail.com> (raw)
In-Reply-To: <1487967399-28967-1-git-send-email-kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 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

  parent reply	other threads:[~2017-02-24 20:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24 20:16 [PATCH v6 0/3] Add spi-nor flash device pm support Kamal Dasu
2017-02-24 20:16 ` Kamal Dasu
2017-02-24 20:16 ` [PATCH v6 1/3] mtd: spi-nor: Add spi-nor init function Kamal Dasu
2017-02-24 20:16   ` Kamal Dasu
2017-02-24 20:16 ` [PATCH v6 2/3] mtd: spi-nor: Add spi-nor flash device synchronization between flash states Kamal Dasu
2017-02-24 20:16   ` Kamal Dasu
2017-02-26 12:18   ` Marek Vasut
2017-02-26 12:18     ` Marek Vasut
2017-03-03 21:38     ` Kamal Dasu
2017-03-03 21:38       ` Kamal Dasu
2017-03-05  1:11       ` Marek Vasut
2017-03-05  1:11         ` Marek Vasut
2017-03-07 23:08   ` Cyrille Pitchen
2017-03-07 23:08     ` Cyrille Pitchen
2017-03-09 20:03     ` Kamal Dasu
2017-03-09 20:03       ` Kamal Dasu
2017-02-24 20:16 ` Kamal Dasu [this message]
2017-02-24 20:16   ` [PATCH v6 3/3] mtd: spi-nor: Add spi-nor mtd suspend and resume handlers Kamal Dasu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1487967399-28967-4-git-send-email-kdasu.kdev@gmail.com \
    --to=kdasu.kdev@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=broonie@kernel.org \
    --cc=cyrille.pitchen@atmel.com \
    --cc=f.fainelli@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=marex@denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.