From: Hou Zhiqiang <b48286@freescale.com>
To: <linux-mtd@lists.infradead.org>, <linuxppc-dev@ozlabs.org>
Cc: scottwood@freescale.com, Mingkai.Hu@freescale.com,
Hou Zhiqiang <b48286@freescale.com>,
dwmw2@infradead.org
Subject: [PATCH v2] mtd: m25p80: Add Power Management support
Date: Thu, 12 Dec 2013 13:38:36 +0800 [thread overview]
Message-ID: <1386826716-20476-1-git-send-email-b48286@freescale.com> (raw)
Add PM support using callback function suspend and resume in
.driver.pm of spi_driver.
Signed-off-by: Hou Zhiqiang <b48286@freescale.com>
---
v2:
- Replace .driver.suspend and .driver.resume with .driver.pm
- Use CONFIG_PM_SLEEP instead of CONFIG_PM
drivers/mtd/devices/m25p80.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 7eda71d..eb558e8 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -66,6 +66,8 @@
/* Used for Spansion flashes only. */
#define OPCODE_BRWR 0x17 /* Bank register write */
+#define OPCODE_DP 0xb9 /* Enter deep power down mode */
+#define OPCODE_RES 0xab /* Exit deep power down mode */
/* Status Register bits. */
#define SR_WIP 1 /* Write in progress */
@@ -1128,11 +1130,46 @@ static int m25p_remove(struct spi_device *spi)
return mtd_device_unregister(&flash->mtd);
}
+#ifdef CONFIG_PM_SLEEP
+static int m25p_suspend(struct device *dev)
+{
+ struct m25p *flash = dev_get_drvdata(dev);
+ int ret;
+
+ flash->command[0] = OPCODE_DP;
+ mutex_lock(&flash->lock);
+ /* Wait until finished previous write/erase command. */
+ ret = wait_till_ready(flash);
+ if (ret) {
+ mutex_unlock(&flash->lock);
+ return ret;
+ }
+ ret = spi_write(flash->spi, flash->command, 1);
+ mutex_unlock(&flash->lock);
+
+ return ret;
+}
+
+static int m25p_resume(struct device *dev)
+{
+ struct m25p *flash = dev_get_drvdata(dev);
+ int ret;
+
+ flash->command[0] = OPCODE_RES;
+
+ return spi_write(flash->spi, flash->command, 1);
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static const struct dev_pm_ops m25p_pm = {
+ SET_SYSTEM_SLEEP_PM_OPS(m25p_suspend, m25p_resume)
+};
static struct spi_driver m25p80_driver = {
.driver = {
.name = "m25p80",
.owner = THIS_MODULE,
+ .pm = &m25p_pm,
},
.id_table = m25p_ids,
.probe = m25p_probe,
--
1.8.4.1
next reply other threads:[~2013-12-12 7:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-12 5:38 Hou Zhiqiang [this message]
2014-01-03 19:07 ` [PATCH v2] mtd: m25p80: Add Power Management support Brian Norris
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=1386826716-20476-1-git-send-email-b48286@freescale.com \
--to=b48286@freescale.com \
--cc=Mingkai.Hu@freescale.com \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=scottwood@freescale.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).