oe-linux-nfc.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: linux-nfc@lists.01.org
Subject: [PATCH] NFC: NCI: make parent aware in PM terms
Date: Thu, 19 Aug 2021 16:02:28 +0200	[thread overview]
Message-ID: <20210819140228.15591-1-oneukum@suse.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2134 bytes --]

The NCI device is a child of an i2c device.
If the i2c layer uses runtime PM the power to
the NFC device can be cut whenever the i2c
layer is done transmitting data to the NFC
device.
Under these conditions NFC can not work, as
it needs power to wait for reception of packets.

The necessary extension of runtime PM
to the NFC device requires that it
be activated as a child of the i2c device.
It is not necessary to do any runtime PM
operations. This will disable runtime PM
for this branch of the tree, but otherwise
the NFC device is inoperable.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/nfc/nxp-nci/i2c.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c
index 94f7f6d9cbad..dba78a5d217a 100644
--- a/drivers/nfc/nxp-nci/i2c.c
+++ b/drivers/nfc/nxp-nci/i2c.c
@@ -18,6 +18,7 @@
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/nfc.h>
+#include <linux/pm_runtime.h>
 #include <linux/gpio/consumer.h>
 #include <asm/unaligned.h>
 
@@ -261,6 +262,7 @@ static int nxp_nci_i2c_probe(struct i2c_client *client,
 {
 	struct device *dev = &client->dev;
 	struct nxp_nci_i2c_phy *phy;
+	struct nfc_dev *ndev;
 	int r;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
@@ -297,6 +299,11 @@ static int nxp_nci_i2c_probe(struct i2c_client *client,
 	if (r < 0)
 		return r;
 
+	ndev = phy->ndev->nfc_dev;
+	pm_runtime_set_active(&ndev->dev);
+	pm_runtime_enable(&ndev->dev);
+	pm_runtime_mark_last_busy(&ndev->dev);
+
 	r = request_threaded_irq(client->irq, NULL,
 				 nxp_nci_i2c_irq_thread_fn,
 				 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
@@ -310,9 +317,12 @@ static int nxp_nci_i2c_probe(struct i2c_client *client,
 static int nxp_nci_i2c_remove(struct i2c_client *client)
 {
 	struct nxp_nci_i2c_phy *phy = i2c_get_clientdata(client);
+	struct nfc_dev *ndev = phy->ndev->nfc_dev;
 
 	nxp_nci_remove(phy->ndev);
 	free_irq(client->irq, phy);
+	pm_runtime_disable(&ndev->dev);
+	pm_runtime_set_suspended(&ndev->dev);
 
 	return 0;
 }
-- 
2.26.2

             reply	other threads:[~2021-08-19 14:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 14:02 Oliver Neukum [this message]
2021-08-19 14:45 ` [PATCH] NFC: NCI: make parent aware in PM terms Krzysztof Kozlowski
2021-08-19 14:58   ` Krzysztof Kozlowski
2021-08-23 10:50   ` Oliver Neukum
2021-08-23 11:29     ` Krzysztof Kozlowski
2021-08-23 11:52       ` Oliver Neukum
2021-08-24  7:24         ` Krzysztof Kozlowski

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=20210819140228.15591-1-oneukum@suse.com \
    --to=oneukum@suse.com \
    --cc=linux-nfc@lists.01.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).