linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aaron Sierra <asierra@xes-inc.com>
To: Kwangwoo Lee <kwangwoo.lee@gmail.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Thierry Reding <thierry.reding@avionic-design.de>,
	Philip Rakity <prakity@marvell.com>
Cc: linux-input@vger.kernel.org
Subject: [PATCH 2/2] input: tsc2007: Don't require an interrupt to load
Date: Tue, 31 Mar 2015 10:06:05 -0500 (CDT)	[thread overview]
Message-ID: <2054629675.19924.1427814365859.JavaMail.zimbra@xes-inc.com> (raw)
In-Reply-To: <1959876509.19488.1427814135809.JavaMail.zimbra@xes-inc.com>

When an IRQ isn't available, poll the device based on poll_period.

Signed-off-by: Aaron Sierra <asierra@xes-inc.com>
---
 drivers/input/touchscreen/tsc2007.c | 43 +++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/tsc2007.c b/drivers/input/touchscreen/tsc2007.c
index 4e97afb..e49a88f 100644
--- a/drivers/input/touchscreen/tsc2007.c
+++ b/drivers/input/touchscreen/tsc2007.c
@@ -71,6 +71,7 @@ struct tsc2007 {
 	char			phys[32];
 
 	struct i2c_client	*client;
+	struct delayed_work	work;
 
 	u16			model;
 	u16			x_plate_ohms;
@@ -82,6 +83,7 @@ struct tsc2007 {
 
 	unsigned		gpio;
 	int			irq;
+	bool			using_irq;
 
 	wait_queue_head_t	wait;
 	bool			stopped;
@@ -242,13 +244,27 @@ static irqreturn_t tsc2007_hard_irq(int irq, void *handle)
 	return IRQ_HANDLED;
 }
 
+static void tsc2007_work(struct work_struct *work)
+{
+	struct tsc2007 *ts =
+		container_of(to_delayed_work(work), struct tsc2007, work);
+
+	tsc2007_soft_irq(ts->irq, ts);
+
+	/* reschedule the task */
+	schedule_delayed_work(&ts->work, ts->poll_period);
+}
+
 static void tsc2007_stop(struct tsc2007 *ts)
 {
 	ts->stopped = true;
 	mb();
 	wake_up(&ts->wait);
 
-	disable_irq(ts->irq);
+	if (ts->using_irq)
+		disable_irq(ts->irq);
+	else
+		cancel_delayed_work_sync(&ts->work);
 }
 
 static int tsc2007_open(struct input_dev *input_dev)
@@ -259,7 +275,10 @@ static int tsc2007_open(struct input_dev *input_dev)
 	ts->stopped = false;
 	mb();
 
-	enable_irq(ts->irq);
+	if (ts->using_irq)
+		enable_irq(ts->irq);
+	else
+		schedule_delayed_work(&ts->work, ts->poll_period);
 
 	/* Prepare for touch readings - power down ADC and enable PENIRQ */
 	err = tsc2007_xfer(ts, PWRDOWN);
@@ -405,6 +424,7 @@ static int tsc2007_probe(struct i2c_client *client,
 
 	ts->client = client;
 	ts->irq = client->irq;
+	ts->using_irq = false;
 	ts->input = input_dev;
 	init_waitqueue_head(&ts->wait);
 
@@ -445,14 +465,23 @@ static int tsc2007_probe(struct i2c_client *client,
 			pdata->init_platform_hw();
 	}
 
-	err = devm_request_threaded_irq(&client->dev, ts->irq,
+	if (ts->irq >= 0) {
+		err = devm_request_threaded_irq(&client->dev, ts->irq,
 					tsc2007_hard_irq, tsc2007_soft_irq,
 					IRQF_ONESHOT,
 					client->dev.driver->name, ts);
-	if (err) {
-		dev_err(&client->dev, "Failed to request irq %d: %d\n",
-			ts->irq, err);
-		return err;
+		if (err) {
+			dev_warn(&client->dev, "Failed to request irq %d: %d\n",
+				ts->irq, err);
+		} else {
+			ts->using_irq = true;
+		}
+	}
+
+	if (!ts->using_irq) {
+		dev_info(&client->dev,
+			"No IRQ, polling every %ld ms\n", ts->poll_period);
+		INIT_DELAYED_WORK(&ts->work, tsc2007_work);
 	}
 
 	tsc2007_stop(ts);
-- 
1.9.1

       reply	other threads:[~2015-03-31 15:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1959876509.19488.1427814135809.JavaMail.zimbra@xes-inc.com>
2015-03-31 15:06 ` Aaron Sierra [this message]
2015-03-31 21:35   ` [PATCH 2/2] input: tsc2007: Don't require an interrupt to load Dmitry Torokhov
2015-03-31 21:55     ` Aaron Sierra

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=2054629675.19924.1427814365859.JavaMail.zimbra@xes-inc.com \
    --to=asierra@xes-inc.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=kwangwoo.lee@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=prakity@marvell.com \
    --cc=thierry.reding@avionic-design.de \
    /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).