From: Amelie Delaunay <amelie.delaunay@st.com>
To: Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@st.com>
Cc: linux-spi@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Amelie Delaunay <amelie.delaunay@st.com>
Subject: [PATCH 6/8] spi: stm32: add runtime PM support
Date: Fri, 23 Jun 2017 14:55:48 +0200 [thread overview]
Message-ID: <1498222550-19092-7-git-send-email-amelie.delaunay@st.com> (raw)
In-Reply-To: <1498222550-19092-1-git-send-email-amelie.delaunay@st.com>
This patch reworks suspend and resume callbacks and add runtime_suspend
and runtime_resume callbacks.
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
drivers/spi/spi-stm32.c | 43 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 7 deletions(-)
diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 72efc63..209afda 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -27,6 +27,7 @@
#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/of_platform.h>
+#include <linux/pm_runtime.h>
#include <linux/reset.h>
#include <linux/spi/spi.h>
@@ -1164,6 +1165,9 @@ static int stm32_spi_probe(struct platform_device *pdev)
if (spi->dma_tx || spi->dma_rx)
master->can_dma = stm32_spi_can_dma;
+ pm_runtime_set_active(&pdev->dev);
+ pm_runtime_enable(&pdev->dev);
+
ret = devm_spi_register_master(&pdev->dev, master);
if (ret) {
dev_err(&pdev->dev, "spi master registration failed: %d\n",
@@ -1203,6 +1207,8 @@ static int stm32_spi_probe(struct platform_device *pdev)
dma_release_channel(spi->dma_tx);
if (spi->dma_rx)
dma_release_channel(spi->dma_rx);
+
+ pm_runtime_disable(&pdev->dev);
err_clk_disable:
clk_disable_unprepare(spi->clk);
err_master_put:
@@ -1225,23 +1231,42 @@ static int stm32_spi_remove(struct platform_device *pdev)
clk_disable_unprepare(spi->clk);
+ pm_runtime_disable(&pdev->dev);
+
return 0;
}
+#ifdef CONFIG_PM
+static int stm32_spi_runtime_suspend(struct device *dev)
+{
+ struct spi_master *master = dev_get_drvdata(dev);
+ struct stm32_spi *spi = spi_master_get_devdata(master);
+
+ clk_disable_unprepare(spi->clk);
+
+ return 0;
+}
+
+static int stm32_spi_runtime_resume(struct device *dev)
+{
+ struct spi_master *master = dev_get_drvdata(dev);
+ struct stm32_spi *spi = spi_master_get_devdata(master);
+
+ return clk_prepare_enable(spi->clk);
+}
+#endif
+
#ifdef CONFIG_PM_SLEEP
static int stm32_spi_suspend(struct device *dev)
{
struct spi_master *master = dev_get_drvdata(dev);
- struct stm32_spi *spi = spi_master_get_devdata(master);
int ret;
ret = spi_master_suspend(master);
if (ret)
return ret;
- clk_disable_unprepare(spi->clk);
-
- return ret;
+ return pm_runtime_force_suspend(dev);
}
static int stm32_spi_resume(struct device *dev)
@@ -1250,9 +1275,10 @@ static int stm32_spi_resume(struct device *dev)
struct stm32_spi *spi = spi_master_get_devdata(master);
int ret;
- ret = clk_prepare_enable(spi->clk);
+ ret = pm_runtime_force_resume(dev);
if (ret)
return ret;
+
ret = spi_master_resume(master);
if (ret)
clk_disable_unprepare(spi->clk);
@@ -1261,8 +1287,11 @@ static int stm32_spi_resume(struct device *dev)
}
#endif
-static SIMPLE_DEV_PM_OPS(stm32_spi_pm_ops,
- stm32_spi_suspend, stm32_spi_resume);
+static const struct dev_pm_ops stm32_spi_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(stm32_spi_suspend, stm32_spi_resume)
+ SET_RUNTIME_PM_OPS(stm32_spi_runtime_suspend,
+ stm32_spi_runtime_resume, NULL)
+};
static struct platform_driver stm32_spi_driver = {
.probe = stm32_spi_probe,
--
1.9.1
next prev parent reply other threads:[~2017-06-23 12:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-23 12:55 [PATCH 0/8] STM32 SPI various fixes Amelie Delaunay
2017-06-23 12:55 ` [PATCH 1/8] dt-bindings: spi: stm32: use SoC specific compatible Amelie Delaunay
[not found] ` <1498222550-19092-2-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-26 19:08 ` Rob Herring
2017-06-28 19:25 ` Applied "spi: stm32: use SoC specific compatible" to the spi tree Mark Brown
2017-06-23 12:55 ` [PATCH 2/8] spi: stm32: fix compatible to fit with new bindings Amelie Delaunay
[not found] ` <1498222550-19092-3-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-28 19:25 ` Applied "spi: stm32: fix compatible to fit with new bindings" to the spi tree Mark Brown
2017-06-23 12:55 ` [PATCH 3/8] dt-bindings: spi: stm32: fix example with st,spi-midi-ns property Amelie Delaunay
[not found] ` <1498222550-19092-4-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-26 19:12 ` Rob Herring
2017-06-23 12:55 ` [PATCH 4/8] spi: stm32: replace st, spi-midi with st, spi-midi-ns to fit bindings Amelie Delaunay
[not found] ` <1498222550-19092-5-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-28 19:25 ` Applied "spi: stm32: replace st, spi-midi with st, spi-midi-ns to fit bindings" to the spi tree Mark Brown
2017-06-23 12:55 ` [PATCH 5/8] spi: stm32: use normal conditional statements instead of ternary operator Amelie Delaunay
[not found] ` <1498222550-19092-6-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-28 19:25 ` Applied "spi: stm32: use normal conditional statements instead of ternary operator" to the spi tree Mark Brown
2017-06-23 12:55 ` Amelie Delaunay [this message]
2017-06-28 19:25 ` Applied "spi: stm32: add runtime PM support" " Mark Brown
[not found] ` <1498222550-19092-1-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-23 12:55 ` [PATCH 7/8] spi: stm32: enhance DMA error management Amelie Delaunay
2017-06-23 12:55 ` [PATCH 8/8] spi: stm32: fix potential dereference null return value Amelie Delaunay
2017-06-28 19:25 ` Applied "spi: stm32: fix potential dereference null return value" to the spi tree Mark Brown
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=1498222550-19092-7-git-send-email-amelie.delaunay@st.com \
--to=amelie.delaunay@st.com \
--cc=alexandre.torgue@st.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=robh+dt@kernel.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).