From: Kamal Dasu <kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/w@public.gmane.org,
Kamal Dasu <kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH v2, 1/1] mtd: devices: m25p80: Add PM suspend resume support
Date: Mon, 12 Sep 2016 16:01:34 -0400 [thread overview]
Message-ID: <1473710494-4084-1-git-send-email-kdasu.kdev@gmail.com> (raw)
Adding PM support so as to be able to probe spi-nor flash
on resume. There are vendor specific commands to setup
the transfer mode and enable read/write as part of
spi_nor_scan(), done on initial probe and needed on resume().
The spi-nor structure is private to the m25p driver and hence
is the only place this can be done without having to duplicate
code in controller driver.
Signed-off-by: Kamal Dasu <kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/mtd/devices/m25p80.c | 68 +++++++++++++++++++++++++++++++-------------
1 file changed, 48 insertions(+), 20 deletions(-)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 9cf7fcd..48c3f64 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -186,6 +186,39 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
}
/*
+ * scan for spi nor flash vendor parts and setup
+ * read/write mode
+ */
+static int m25p_nor_flash_scan(struct device *dev)
+{
+ struct m25p *flash = dev_get_drvdata(dev);
+ struct flash_platform_data *data;
+ char *flash_name = NULL;
+ enum read_mode mode = SPI_NOR_NORMAL;
+
+ data = dev_get_platdata(dev);
+
+ /* For some (historical?) reason many platforms provide two different
+ * names in flash_platform_data: "name" and "type". Quite often name is
+ * set to "m25p80" and then "type" provides a real chip name.
+ * If that's the case, respect "type" and ignore a "name".
+ */
+ if (data && data->type)
+ flash_name = data->type;
+ else if (!strcmp(flash->spi->modalias, "spi-nor"))
+ flash_name = NULL; /* auto-detect */
+ else
+ flash_name = flash->spi->modalias;
+
+ if (flash->spi->mode & SPI_RX_QUAD)
+ mode = SPI_NOR_QUAD;
+ else if (flash->spi->mode & SPI_RX_DUAL)
+ mode = SPI_NOR_DUAL;
+
+ return spi_nor_scan(&flash->spi_nor, flash_name, mode);
+}
+
+/*
* board specific setup should have ensured the SPI clock used here
* matches what the READ command supports, at least until this driver
* understands FAST_READ (for clocks over 25 MHz).
@@ -195,8 +228,6 @@ static int m25p_probe(struct spi_device *spi)
struct flash_platform_data *data;
struct m25p *flash;
struct spi_nor *nor;
- enum read_mode mode = SPI_NOR_NORMAL;
- char *flash_name;
int ret;
data = dev_get_platdata(&spi->dev);
@@ -220,27 +251,11 @@ static int m25p_probe(struct spi_device *spi)
spi_set_drvdata(spi, flash);
flash->spi = spi;
- if (spi->mode & SPI_RX_QUAD)
- mode = SPI_NOR_QUAD;
- else if (spi->mode & SPI_RX_DUAL)
- mode = SPI_NOR_DUAL;
-
if (data && data->name)
nor->mtd.name = data->name;
- /* For some (historical?) reason many platforms provide two different
- * names in flash_platform_data: "name" and "type". Quite often name is
- * set to "m25p80" and then "type" provides a real chip name.
- * If that's the case, respect "type" and ignore a "name".
- */
- if (data && data->type)
- flash_name = data->type;
- else if (!strcmp(spi->modalias, "spi-nor"))
- flash_name = NULL; /* auto-detect */
- else
- flash_name = spi->modalias;
+ ret = m25p_nor_flash_scan(nor->dev);
- ret = spi_nor_scan(nor, flash_name, mode);
if (ret)
return ret;
@@ -248,7 +263,6 @@ static int m25p_probe(struct spi_device *spi)
data ? data->nr_parts : 0);
}
-
static int m25p_remove(struct spi_device *spi)
{
struct m25p *flash = spi_get_drvdata(spi);
@@ -319,10 +333,24 @@ static const struct of_device_id m25p_of_table[] = {
};
MODULE_DEVICE_TABLE(of, m25p_of_table);
+#ifdef CONFIG_PM_SLEEP
+static int m25p_suspend(struct device *dev)
+{
+ return 0;
+}
+
+static int m25p_resume(struct device *dev)
+{
+ return m25p_nor_flash_scan(dev);
+}
+#endif
+static SIMPLE_DEV_PM_OPS(m25p_pm_ops, m25p_suspend, m25p_resume);
+
static struct spi_driver m25p80_driver = {
.driver = {
.name = "m25p80",
.of_match_table = m25p_of_table,
+ .pm = &m25p_pm_ops,
},
.id_table = m25p_ids,
.probe = m25p_probe,
--
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
next reply other threads:[~2016-09-12 20:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-12 20:01 Kamal Dasu [this message]
[not found] ` <1473710494-4084-1-git-send-email-kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-14 17:42 ` [PATCH v2, 1/1] mtd: devices: m25p80: Add PM suspend resume support Kamal Dasu
2016-10-17 17:08 ` Cyrille Pitchen
[not found] ` <CAKekbeubczM5NpQy-Umqx-SmDM+deMcgYciyST2Sgrh2_dOsAw@mail.gmail.com>
[not found] ` <CAKekbeubczM5NpQy-Umqx-SmDM+deMcgYciyST2Sgrh2_dOsAw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-11-29 1:35 ` Florian Fainelli
2016-11-29 13:11 ` Cyrille Pitchen
[not found] ` <c9198202-29d1-5e67-f675-5a53d926ede9-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
2016-12-01 15:43 ` Marek Vasut
2017-01-20 16:33 ` Kamal Dasu
2017-01-20 17:22 ` Marek Vasut
2017-01-20 18:50 ` Kamal Dasu
[not found] ` <CAC=U0a3Q_dBefFayi4G2TueZNXYAhdakduSwYdKPxDDL5Uoi_A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-20 19:36 ` Michal Suchanek
2017-01-20 20:02 ` Marek Vasut
[not found] ` <0b33765b-52b7-65f4-34d3-0a446a2df59e-ynQEQJNshbs@public.gmane.org>
2017-01-20 20:07 ` Florian Fainelli
[not found] ` <fc4c2fc2-6779-6e42-8002-0d636156fe66-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-20 20:13 ` Marek Vasut
2017-01-20 20:23 ` Florian Fainelli
2017-01-20 20:42 ` Marek Vasut
[not found] ` <36831150-8147-2d6f-f5e6-57c675f4c875-ynQEQJNshbs@public.gmane.org>
2017-01-20 21:15 ` Kamal Dasu
[not found] ` <CAC=U0a35M4_DqsJqyp0f-k7XzayvK7z5sQ+JTJ4qJAu=4P3dZw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-20 22:30 ` Marek Vasut
2017-01-20 22:58 ` Florian Fainelli
[not found] ` <3bc8d8d3-936c-51c7-30c4-deac0b3bc7d8-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
2017-01-21 0:13 ` Marek Vasut
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=1473710494-4084-1-git-send-email-kdasu.kdev@gmail.com \
--to=kdasu.kdev-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=bcm-kernel-feedback-list-dY08KVG/lbpWk0Htik3J/w@public.gmane.org \
--cc=computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/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).