From: "Martin Hundebøll" <martin@geanix.com>
To: linux-can@vger.kernel.org
Cc: "Martin Hundebøll" <martin@geanix.com>,
"Chandrasekar Ramakrishnan" <rcsekar@samsung.com>,
"Wolfgang Grandegger" <wg@grandegger.com>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Dong Aisheng" <b29396@freescale.com>,
"Dan Murphy" <dmurphy@ti.com>
Subject: [PATCH v2 2/2] can: tcan4x5x: support resuming from rx interrupt signal
Date: Tue, 19 Sep 2023 14:28:33 +0200 [thread overview]
Message-ID: <20230919122841.3803289-2-martin@geanix.com> (raw)
In-Reply-To: <20230919122841.3803289-1-martin@geanix.com>
Implement the "wakeup-source" device tree property, so the chip is left
running when suspending, and its rx interrupt is used as a wakeup source
to resume operation.
Signed-off-by: Martin Hundebøll <martin@geanix.com>
---
Change since v1:
* Added `static` keyword to dev_pm_ops sturcture
drivers/net/can/m_can/tcan4x5x-core.c | 34 ++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
index 8a4143809d33..ccb279af22bb 100644
--- a/drivers/net/can/m_can/tcan4x5x-core.c
+++ b/drivers/net/can/m_can/tcan4x5x-core.c
@@ -459,6 +459,9 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
goto out_power;
}
+ if (device_property_read_bool(&spi->dev, "wakeup-source"))
+ device_init_wakeup(&spi->dev, true);
+
ret = m_can_class_register(mcan_class);
if (ret) {
dev_err(&spi->dev, "Failed registering m_can device %pe\n",
@@ -487,6 +490,31 @@ static void tcan4x5x_can_remove(struct spi_device *spi)
m_can_class_free_dev(priv->cdev.net);
}
+static int __maybe_unused tcan4x5x_suspend(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+
+ if (device_may_wakeup(dev)) {
+ enable_irq_wake(spi->irq);
+
+ return m_can_class_suspend(dev, true);
+ }
+
+ return m_can_class_suspend(dev, false);
+}
+
+static int __maybe_unused tcan4x5x_resume(struct device *dev)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ bool wake_source = device_may_wakeup(dev);
+ int ret = m_can_class_resume(dev, wake_source);
+
+ if (wake_source)
+ disable_irq_wake(spi->irq);
+
+ return ret;
+}
+
static const struct of_device_id tcan4x5x_of_match[] = {
{
.compatible = "ti,tcan4x5x",
@@ -505,11 +533,15 @@ static const struct spi_device_id tcan4x5x_id_table[] = {
};
MODULE_DEVICE_TABLE(spi, tcan4x5x_id_table);
+static const struct dev_pm_ops tcan4x5x_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(tcan4x5x_suspend, tcan4x5x_resume)
+};
+
static struct spi_driver tcan4x5x_can_driver = {
.driver = {
.name = KBUILD_MODNAME,
.of_match_table = tcan4x5x_of_match,
- .pm = NULL,
+ .pm = &tcan4x5x_pm_ops,
},
.id_table = tcan4x5x_id_table,
.probe = tcan4x5x_can_probe,
--
2.42.0
next prev parent reply other threads:[~2023-09-19 12:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 12:28 [PATCH v2 1/2] can: m_can: allow keeping the transceiver running in suspend Martin Hundebøll
2023-09-19 12:28 ` Martin Hundebøll [this message]
2023-09-29 14:27 ` [PATCH v2 2/2] can: tcan4x5x: support resuming from rx interrupt signal Markus Schneider-Pargmann
2023-09-29 14:25 ` [PATCH v2 1/2] can: m_can: allow keeping the transceiver running in suspend Markus Schneider-Pargmann
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=20230919122841.3803289-2-martin@geanix.com \
--to=martin@geanix.com \
--cc=b29396@freescale.com \
--cc=dmurphy@ti.com \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=rcsekar@samsung.com \
--cc=wg@grandegger.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 read-only IMAP folder(s) and NNTP newsgroup(s).