All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Srikar <ext-srikar.1.bhavanarayana@nokia.com>,
	Phil Carmody <ext-phil.2.carmody@nokia.com>,
	Aaro Koskinen <aaro.koskinen@nokia.com>
Cc: linux-input@vger.kernel.org, lauri.leukkunen@nokia.com,
	David Brownell <dbrownell@users.sourceforge.net>,
	Imre Deak <imre.deak@nokia.com>,
	Hiroshi DOYU <Hiroshi.DOYU@nokia.com>,
	Ari Kauppi <Ext-Ari.Kauppi@nokia.com>,
	Tony Lindgren <tony@atomide.com>,
	Jarkko Nikula <jhnikula@gmail.com>,
	Eero Nurkkala <ext-eero.nurkkala@nokia.com>,
	Roman Tereshonkov <roman.tereshonkov@nokia.com>
Subject: [PATCH 13/17] Input: tsc2005 - don't use work for 'pen up' handling
Date: Wed, 16 Mar 2011 00:19:07 -0700	[thread overview]
Message-ID: <20110316071907.25664.46804.stgit@hammer.corenet.prv> (raw)
In-Reply-To: <20110316071503.25664.55116.stgit@hammer.corenet.prv>

We do not need process context to send input events so let's switch to
a regular timer. I am going to get rid of taking ts->mutex in
tsc2005_irq_thread() later.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/input/touchscreen/tsc2005.c |   58 ++++++++++++++++-------------------
 1 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c
index 8a9c072..c0980ae 100644
--- a/drivers/input/touchscreen/tsc2005.c
+++ b/drivers/input/touchscreen/tsc2005.c
@@ -129,8 +129,8 @@ struct tsc2005 {
 	int                     in_z1;
 	int			in_z2;
 
+	spinlock_t		lock;
 	struct timer_list	penup_timer;
-	struct work_struct	penup_work;
 
 	unsigned int		esd_timeout;
 	struct timer_list	esd_timer;
@@ -239,11 +239,10 @@ static irqreturn_t tsc2005_irq_handler(int irq, void *dev_id)
 static irqreturn_t tsc2005_irq_thread(int irq, void *_ts)
 {
 	struct tsc2005 *ts = _ts;
+	unsigned long flags;
 	unsigned int pressure;
-	u32 x;
-	u32 y;
-	u32 z1;
-	u32 z2;
+	u32 x, y;
+	u32 z1, z2;
 
 	mutex_lock(&ts->mutex);
 
@@ -261,46 +260,50 @@ static irqreturn_t tsc2005_irq_thread(int irq, void *_ts)
 	if (unlikely(x > MAX_12BIT || y > MAX_12BIT))
 		goto out;
 
-	/* skip coords if the pressure components are out of range */
+	/* Skip reading if the pressure components are out of range */
 	if (unlikely(z1 == 0 || z2 > MAX_12BIT || z1 >= z2))
 		goto out;
 
-       /* skip point if this is a pen down with the exact same values as
+       /*
+	* Skip point if this is a pen down with the exact same values as
 	* the value before pen-up - that implies SPI fed us stale data
 	*/
 	if (!ts->pen_down &&
-	ts->in_x == x &&
-	ts->in_y == y &&
-	ts->in_z1 == z1 &&
-	ts->in_z2 == z2)
+	    ts->in_x == x && ts->in_y == y &&
+	    ts->in_z1 == z1 && ts->in_z2 == z2) {
 		goto out;
+	}
 
-	/* At this point we are happy we have a valid and useful reading.
-	* Remember it for later comparisons. We may now begin downsampling
-	*/
+	/*
+	 * At this point we are happy we have a valid and useful reading.
+	 * Remember it for later comparisons. We may now begin downsampling.
+	 */
 	ts->in_x = x;
 	ts->in_y = y;
 	ts->in_z1 = z1;
 	ts->in_z2 = z2;
 
-	/* compute touch pressure resistance using equation #1 */
+	/* Compute touch pressure resistance using equation #1 */
 	pressure = x * (z2 - z1) / z1;
 	pressure = pressure * ts->x_plate_ohm / 4096;
 	if (unlikely(pressure > MAX_12BIT))
 		goto out;
 
+	spin_lock_irqsave(&ts->lock, flags);
+
 	tsc2005_update_pen_state(ts, x, y, pressure);
 
 	/* set the penup timer */
 	mod_timer(&ts->penup_timer,
 		  jiffies + msecs_to_jiffies(TSC2005_PENUP_TIME_MS));
 
-	if (!ts->esd_timeout)
-		goto out;
+	if (ts->esd_timeout && ts->set_reset) {
+		/* update the watchdog timer */
+		mod_timer(&ts->esd_timer, round_jiffies(jiffies +
+					msecs_to_jiffies(ts->esd_timeout)));
+	}
 
-	/* update the watchdog timer */
-	mod_timer(&ts->esd_timer,
-		  round_jiffies(jiffies + msecs_to_jiffies(ts->esd_timeout)));
+	spin_unlock_irqrestore(&ts->lock, flags);
 
 out:
 	mutex_unlock(&ts->mutex);
@@ -310,17 +313,11 @@ out:
 static void tsc2005_penup_timer(unsigned long data)
 {
 	struct tsc2005 *ts = (struct tsc2005 *)data;
+	unsigned long flags;
 
-	schedule_work(&ts->penup_work);
-}
-
-static void tsc2005_penup_work(struct work_struct *work)
-{
-	struct tsc2005 *ts = container_of(work, struct tsc2005, penup_work);
-
-	mutex_lock(&ts->mutex);
+	spin_lock_irqsave(&ts->lock, flags);
 	tsc2005_update_pen_state(ts, 0, 0, 0);
-	mutex_unlock(&ts->mutex);
+	spin_unlock_irqrestore(&ts->lock, flags);
 }
 
 static void tsc2005_start_scan(struct tsc2005 *ts)
@@ -575,8 +572,8 @@ static int __devinit tsc2005_probe(struct spi_device *spi)
 
 	mutex_init(&ts->mutex);
 
+	spin_lock_init(&ts->lock);
 	setup_timer(&ts->penup_timer, tsc2005_penup_timer, (unsigned long)ts);
-	INIT_WORK(&ts->penup_work, tsc2005_penup_work);
 
 	setup_timer(&ts->esd_timer, tsc2005_esd_timer, (unsigned long)ts);
 	INIT_WORK(&ts->esd_work, tsc2005_esd_work);
@@ -657,7 +654,6 @@ static int __devexit tsc2005_remove(struct spi_device *spi)
 	del_timer_sync(&ts->penup_timer);
 
 	flush_work(&ts->esd_work);
-	flush_work(&ts->penup_work);
 
 	free_irq(ts->spi->irq, ts);
 	input_unregister_device(ts->idev);


  parent reply	other threads:[~2011-03-16  7:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-16  7:17 [PATCH 00/17] Merging of TSC2005 driver Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 01/17] Input: tsc2005 - use spi_get/set_drvdata() Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 02/17] Input: tsc2005 - convert to using dev_pm_ops Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 03/17] Input: tsc2005 - remove incorrect module alias Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 04/17] Input: tsc2005 - remove driver banner message Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 05/17] Input: tsc2005 - add module description Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 06/17] Input: tsc2005 - clear driver data after unbinding Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 07/17] Input: tsc2005 - set up parent device Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 08/17] Input: tsc2005 - set up bus type in input device Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 09/17] Input: tsc2005 - rework driver initialization code Dmitry Torokhov
2011-03-16 15:11   ` Aaro Koskinen
2011-03-16  7:18 ` [PATCH 10/17] Input: tsc2005 - hide selftest attribute if we can't reset Dmitry Torokhov
2011-03-16  7:18 ` [PATCH 11/17] Input: tsc2005 - use true/false for boolean variables Dmitry Torokhov
2011-03-16  7:19 ` [PATCH 12/17] Input: tsc2005 - do not use 0 in place of NULL Dmitry Torokhov
2011-03-16  7:19 ` Dmitry Torokhov [this message]
2011-03-16  7:19 ` [PATCH 14/17] Input: tsc2005 - do not rearm timer in hardirq handler Dmitry Torokhov
2011-03-16  7:19 ` [PATCH 15/17] Input: tsc2005 - handle read errors from SPI layer Dmitry Torokhov
2011-03-16  7:19 ` [PATCH 16/17] Input: tsc2005 - add open/close Dmitry Torokhov
2011-03-16 15:37   ` Aaro Koskinen
2011-03-16  7:19 ` [PATCH 17/17] Input: tsc2005 - remove 'disable' sysfs attribute Dmitry Torokhov
2011-03-16  7:41 ` [PATCH 00/17] Merging of TSC2005 driver Dmitry Torokhov
2011-03-16 15:44 ` Aaro Koskinen
2011-03-16 16:40   ` Dmitry Torokhov

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=20110316071907.25664.46804.stgit@hammer.corenet.prv \
    --to=dmitry.torokhov@gmail.com \
    --cc=Ext-Ari.Kauppi@nokia.com \
    --cc=Hiroshi.DOYU@nokia.com \
    --cc=aaro.koskinen@nokia.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=ext-eero.nurkkala@nokia.com \
    --cc=ext-phil.2.carmody@nokia.com \
    --cc=ext-srikar.1.bhavanarayana@nokia.com \
    --cc=imre.deak@nokia.com \
    --cc=jhnikula@gmail.com \
    --cc=lauri.leukkunen@nokia.com \
    --cc=linux-input@vger.kernel.org \
    --cc=roman.tereshonkov@nokia.com \
    --cc=tony@atomide.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.