From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org
Subject: [PATCH 2/2] spi: wire up wakeup-source/wakeirq handling
Date: Mon, 11 Nov 2019 21:54:11 -0800 [thread overview]
Message-ID: <20191112055412.192675-3-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20191112055412.192675-1-dmitry.torokhov@gmail.com>
Many SPI drivers need to configure their devices for waking up the
system. Instead of forcing them to reimplement wakeup handling, let's
mirror what I2C core is doing and handle "wakeup-source" device property
in SPI core.
Also, let's allow naming device's interrupt lines as "irq" and "wakeup"
and automatically configure the right one as wakeirq when device is
supposed to be a wakeup source.
Implementing this is very helpful for drivers that use both I2C and SPI
for transport, such as tsc2004/tsc2005.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/spi/spi.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 50769a8475d66..baa7aac300d9f 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -22,6 +22,7 @@
#include <linux/gpio/consumer.h>
#include <linux/pm_runtime.h>
#include <linux/pm_domain.h>
+#include <linux/pm_wakeirq.h>
#include <linux/property.h>
#include <linux/export.h>
#include <linux/sched/rt.h>
@@ -394,13 +395,37 @@ static int spi_drv_probe(struct device *dev)
return ret;
if (dev->of_node) {
- spi->irq = of_irq_get(dev->of_node, 0);
+ spi->irq = of_irq_get_byname(dev->of_node, "irq");
+ if (spi->irq == -EINVAL || spi->irq == -ENODATA)
+ spi->irq = of_irq_get(dev->of_node, 0);
if (spi->irq == -EPROBE_DEFER)
return -EPROBE_DEFER;
if (spi->irq < 0)
spi->irq = 0;
}
+ if (device_property_read_bool(dev, "wakeup-source")) {
+ int wakeirq = -ENOENT;
+
+ if (dev->of_node) {
+ wakeirq = of_irq_get_byname(dev->of_node, "wakeup");
+ if (wakeirq == -EPROBE_DEFER)
+ return wakeirq;
+ }
+
+ device_init_wakeup(dev, true);
+
+ if (wakeirq > 0 && wakeirq != spi->irq)
+ ret = dev_pm_set_dedicated_wake_irq(dev, wakeirq);
+ else if (spi->irq > 0)
+ ret = dev_pm_set_wake_irq(dev, spi->irq);
+ else
+ ret = 0;
+
+ if (ret)
+ dev_warn(dev, "failed to set up wakeup irq: %d\n", ret);
+ }
+
ret = dev_pm_domain_attach(dev, true);
if (ret)
return ret;
--
2.24.0.rc1.363.gb1bccd3e3d-goog
prev parent reply other threads:[~2019-11-12 5:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-12 5:54 [PATCH 0/2] spi: add wakeup handling to SPI core Dmitry Torokhov
2019-11-12 5:54 ` [PATCH 1/2] spi: dt-bindings: spi-controller: add wakeup-source and interrupts Dmitry Torokhov
2019-11-12 12:03 ` Mark Brown
2019-11-12 19:03 ` Dmitry Torokhov
2019-11-12 19:15 ` Mark Brown
2019-11-12 19:36 ` Dmitry Torokhov
2019-11-12 19:42 ` Mark Brown
2019-11-14 22:26 ` Rob Herring
2019-11-14 23:08 ` Dmitry Torokhov
2019-11-15 13:52 ` Rob Herring
2019-11-15 15:22 ` Mark Brown
2019-11-15 19:43 ` Rob Herring
2019-11-12 5:54 ` Dmitry Torokhov [this message]
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=20191112055412.192675-3-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.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).