From: Aswath Govindraju <a-govindraju@ti.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Vignesh Raghavendra <vigneshr@ti.com>,
Roger Quadros <rogerq@kernel.org>,
Kishon Vijay Abraham I <kishon@ti.com>,
Aswath Govindraju <a-govindraju@ti.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sven Peter <sven@svenpeter.dev>, Hector Martin <marcan@marcan.st>,
Alyssa Rosenzweig <alyssa@rosenzweig.io>,
Jens Axboe <axboe@kernel.dk>,
"Bryan O'Donoghue" <bryan.odonoghue@linaro.org>,
<linux-usb@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] usb: typec: tipd: Add support for polling interrupts status when interrupt line is not connected
Date: Thu, 14 Apr 2022 14:01:18 +0530 [thread overview]
Message-ID: <20220414083120.22535-3-a-govindraju@ti.com> (raw)
In-Reply-To: <20220414083120.22535-1-a-govindraju@ti.com>
In some cases the interrupt line from the pd controller may not be
connected. In these cases, poll the status of various events.
Suggested-by: Roger Quadros <rogerq@kernel.org>
Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
---
drivers/usb/typec/tipd/core.c | 99 +++++++++++++++++++++++++++++++----
1 file changed, 88 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 16b4560216ba..72fd586ac080 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -15,6 +15,8 @@
#include <linux/interrupt.h>
#include <linux/usb/typec.h>
#include <linux/usb/role.h>
+#include <linux/workqueue.h>
+#include <linux/devm-helpers.h>
#include "tps6598x.h"
#include "trace.h"
@@ -93,6 +95,8 @@ struct tps6598x {
struct power_supply *psy;
struct power_supply_desc psy_desc;
enum power_supply_usb_type usb_type;
+
+ struct delayed_work wq_poll;
};
static enum power_supply_property tps6598x_psy_props[] = {
@@ -473,9 +477,8 @@ static void tps6598x_handle_plug_event(struct tps6598x *tps, u32 status)
}
}
-static irqreturn_t cd321x_interrupt(int irq, void *data)
+static int cd321x_handle_interrupt_status(struct tps6598x *tps)
{
- struct tps6598x *tps = data;
u64 event;
u32 status;
int ret;
@@ -513,14 +516,45 @@ static irqreturn_t cd321x_interrupt(int irq, void *data)
err_unlock:
mutex_unlock(&tps->lock);
+ if (ret)
+ return ret;
+
if (event)
- return IRQ_HANDLED;
- return IRQ_NONE;
+ return 0;
+ return 1;
}
-static irqreturn_t tps6598x_interrupt(int irq, void *data)
+static irqreturn_t cd321x_interrupt(int irq, void *data)
{
struct tps6598x *tps = data;
+ int ret;
+
+ ret = cd321x_handle_interrupt_status(tps);
+ if (ret)
+ return IRQ_NONE;
+ return IRQ_HANDLED;
+}
+
+/* Time interval for Polling */
+#define POLL_INTERVAL 500 /* msecs */
+static void cd321x_poll_work(struct work_struct *work)
+{
+ struct tps6598x *tps = container_of(to_delayed_work(work),
+ struct tps6598x, wq_poll);
+ int ret;
+
+ ret = cd321x_handle_interrupt_status(tps);
+ /*
+ * If there is an error while reading the interrupt registers
+ * then stop polling else, schedule another poll work item
+ */
+ if (!(ret < 0))
+ queue_delayed_work(system_power_efficient_wq,
+ &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL));
+}
+
+static int tps6598x_handle_interrupt_status(struct tps6598x *tps)
+{
u64 event1;
u64 event2;
u32 status;
@@ -561,9 +595,39 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
err_unlock:
mutex_unlock(&tps->lock);
+ if (ret)
+ return ret;
+
if (event1 | event2)
- return IRQ_HANDLED;
- return IRQ_NONE;
+ return 0;
+ return 1;
+}
+
+static irqreturn_t tps6598x_interrupt(int irq, void *data)
+{
+ struct tps6598x *tps = data;
+ int ret;
+
+ ret = tps6598x_handle_interrupt_status(tps);
+ if (ret)
+ return IRQ_NONE;
+ return IRQ_HANDLED;
+}
+
+static void tps6598x_poll_work(struct work_struct *work)
+{
+ struct tps6598x *tps = container_of(to_delayed_work(work),
+ struct tps6598x, wq_poll);
+ int ret;
+
+ ret = tps6598x_handle_interrupt_status(tps);
+ /*
+ * If there is an error while reading the interrupt registers
+ * then stop polling else, schedule another poll work item
+ */
+ if (!(ret < 0))
+ queue_delayed_work(system_power_efficient_wq,
+ &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL));
}
static int tps6598x_check_mode(struct tps6598x *tps)
@@ -704,6 +768,7 @@ static int devm_tps6598_psy_register(struct tps6598x *tps)
static int tps6598x_probe(struct i2c_client *client)
{
irq_handler_t irq_handler = tps6598x_interrupt;
+ work_func_t work_poll_handler = tps6598x_poll_work;
struct device_node *np = client->dev.of_node;
struct typec_capability typec_cap = { };
struct tps6598x *tps;
@@ -748,6 +813,7 @@ static int tps6598x_probe(struct i2c_client *client)
APPLE_CD_REG_INT_PLUG_EVENT;
irq_handler = cd321x_interrupt;
+ work_poll_handler = cd321x_poll_work;
} else {
/* Enable power status, data status and plug event interrupts */
mask1 = TPS_REG_INT_POWER_STATUS_UPDATE |
@@ -842,10 +908,21 @@ static int tps6598x_probe(struct i2c_client *client)
dev_err(&client->dev, "failed to register partner\n");
}
- ret = devm_request_threaded_irq(&client->dev, client->irq, NULL,
- irq_handler,
- IRQF_SHARED | IRQF_ONESHOT,
- dev_name(&client->dev), tps);
+ if (client->irq) {
+ ret = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+ irq_handler,
+ IRQF_SHARED | IRQF_ONESHOT,
+ dev_name(&client->dev), tps);
+ } else {
+ dev_warn(&client->dev, "Unable to find the interrupt, switching to polling\n");
+ ret = devm_delayed_work_autocancel(tps->dev, &tps->wq_poll, work_poll_handler);
+ if (ret)
+ dev_err(&client->dev, "error while initializing workqueue\n");
+ else
+ queue_delayed_work(system_power_efficient_wq, &tps->wq_poll,
+ msecs_to_jiffies(POLL_INTERVAL));
+ }
+
if (ret) {
tps6598x_disconnect(tps, 0);
typec_unregister_port(tps->port);
--
2.17.1
prev parent reply other threads:[~2022-04-14 8:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-14 8:31 [PATCH 0/2] typec: tipd: Add support for polling Aswath Govindraju
2022-04-14 8:31 ` [PATCH 1/2] dt-bindings: usb: tps6598x: Make the interrupts property optional Aswath Govindraju
2022-04-14 18:10 ` Roger Quadros
2022-04-18 5:19 ` Aswath Govindraju
2022-04-20 19:16 ` Roger Quadros
2022-04-22 5:07 ` Aswath Govindraju
2022-04-26 6:42 ` Roger Quadros
2022-04-26 6:57 ` Heikki Krogerus
2022-05-02 5:30 ` Aswath Govindraju
2022-06-09 5:33 ` Aswath Govindraju
2022-04-14 8:31 ` Aswath Govindraju [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=20220414083120.22535-3-a-govindraju@ti.com \
--to=a-govindraju@ti.com \
--cc=alyssa@rosenzweig.io \
--cc=axboe@kernel.dk \
--cc=bryan.odonoghue@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=kishon@ti.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=marcan@marcan.st \
--cc=robh+dt@kernel.org \
--cc=rogerq@kernel.org \
--cc=sven@svenpeter.dev \
--cc=vigneshr@ti.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 NNTP newsgroup(s).