Input: tsc2007 - Disable irq when the irq thread is handling data
Subsystems (2)
PATCH 1/2 Input: tsc2007 - Disable irq when the irq thread is handling data
The TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. So add the disable_irq/enable_irq protection around data handling.
--- drivers/input/touchscreen/tsc2007.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/input/touchscreen/tsc2007.c +8 -0
@@ -171,6 +171,13 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)struct ts_event tc;u32 rt; +/* +* Disable the irq, as it may fire several other IRQs during +* this thread is handling data, as suggested by the TSC2007 +* datasheet, p19, "Touch Detect" chapter +*/ +disable_irq_nosync (irq); +while (!ts->stopped &&tsc2007_is_pen_down (ts)) {/* pen is down, continue with the measurement */
@@ -221,6 +228,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)if (ts->clear_penirq) ts->clear_penirq (); +enable_irq (irq);return IRQ_HANDLED ; }
Signature · 1 line
1.7.1
PATCH 2/2 Input: tsc2007 - Add a z1_low_threshhold platform data parameter
This originates from a patch in Meego IVI kernel with the name
linux-2.6.37-connext-0027-tsc2007.patch
There is no author info excepte a line "From MeeGo <[email protected]>"
When integrating tsc2007 on Intel IVI platform, there are a lot of noise data whose z1 value is around 10 which is not a sane "z1". So add a "z1_low_threshhold" to filter those nosie data, to make the device work properly.
--- drivers/input/touchscreen/tsc2007.c | 4 +++- include/linux/i2c/tsc2007.h | 1 + 2 files changed, 4 insertions(+), 1 deletions(-)
drivers/input/touchscreen/tsc2007.c +3 -1
@@ -72,6 +72,7 @@ struct tsc2007 {u16 model;u16 x_plate_ohms;u16 max_rt; +u16 z1_low_threshhold;unsigned long poll_delay;unsigned long poll_period;
@@ -130,7 +131,7 @@ static u32 tsc2007_calculate_pressure(struct tsc2007 *tsc, struct ts_event *tc)if (tc->x ==MAX_12BIT ) tc->x =0 ; -if (likely (tc->x && tc->z1)) { +if (likely (tc->x && tc->z1 > tsc->z1_low_threshhold)) {/* compute touch pressure resistance using equation #1 */ rt = tc->z2 - tc->z1; rt *= tc->x;
@@ -313,6 +314,7 @@ static int __devinit tsc2007_probe(struct i2c_client *client, ts->model = pdata->model; ts->x_plate_ohms = pdata->x_plate_ohms; ts->max_rt = pdata->max_rt ? :MAX_12BIT ; + ts->z1_low_threshhold = pdata->z1_low_threshhold ? :1 ; ts->poll_delay = pdata->poll_delay ? :1 ; ts->poll_period = pdata->poll_period ? :1 ; ts->get_pendown_state = pdata->get_pendown_state;
include/linux/i2c/tsc2007.h +1 -0
@@ -7,6 +7,7 @@ struct tsc2007_platform_data {u16 model;/* 2007. */ u16 x_plate_ohms;/* must be non-zero value */ u16 max_rt;/* max. resistance above which samples are ignored */ +u16 z1_low_threshhold;/* threshhold to prevent some noise data */ unsigned long poll_delay;/* delay (in ms) after pen-down event before polling starts */ unsigned long poll_period;/* time (in ms) between samples */
Signature · 1 line
1.7.1
Dmitry Torokhov
maintainerRe: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Quoted 8 lines · Feng Tang
This originates from a patch in Meego IVI kernel with the name
linux-2.6.37-connext-0027-tsc2007.patchThere is no author info excepte a line "From MeeGo <[email protected]>"
When integrating tsc2007 on Intel IVI platform, there are a lot of noise data whose z1 value is around 10 which is not a sane "z1". So add a "
z1_low_threshhold" to filter those nosie data, to make the device work properly.
Sounds like a task for userspace to ignore pressure that is too low. Bonus points for making it configurable so user can adjust sensitivity.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Quoted 6 lines · On Tue, 29 Nov 2011 17:23:10 +0800 Dmitry Torokhov <[email protected]>…
Quoted 5 lines · Feng Tang
This originates from a patch in Meego IVI kernel with the name
linux-2.6.37-connext-0027-tsc2007.patchThere is no author info excepte a line "From MeeGo <[email protected]>"
Quoted 8 lines
Quoted 4 lines
When integrating tsc2007 on Intel IVI platform, there are a lot of noise data whose z1 value is around 10 which is not a sane "z1". So add a "
z1_low_threshhold" to filter those nosie data, to make the device work properly.Sounds like a task for userspace to ignore pressure that is too low. Bonus points for making it configurable so user can adjust sensitivity.
Actually, there is one more point :), without this patch, the driver won't work on our platforms.
The tsc2007_soft_irq will keep reading the input data unless there is no valid pressure data. In our case, those noise data will be seen as valid data during tsc2007_calculate_pressure(), and the tsc2007_soft_irq will run endlessly.
Thanks,
Feng
Quoted 3 lines
Thanks.
Dmitry Torokhov
maintainerRe: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Quoted 18 lines · Feng Tang
Quoted 6 lines · On Tue, 29 Nov 2011 17:23:10 +0800 Dmitry Torokhov <[email protected]>…
Quoted 5 lines · Feng Tang
This originates from a patch in Meego IVI kernel with the name
linux-2.6.37-connext-0027-tsc2007.patchThere is no author info excepte a line "From MeeGo <[email protected]>"
Quoted 8 lines
Quoted 4 lines
When integrating tsc2007 on Intel IVI platform, there are a lot of noise data whose z1 value is around 10 which is not a sane "z1". So add a "
z1_low_threshhold" to filter those nosie data, to make the device work properly.Sounds like a task for userspace to ignore pressure that is too low. Bonus points for making it configurable so user can adjust sensitivity.
Quoted 7 lines
Actually, there is one more point :), without this patch, the driver won't work on our platforms.
The
tsc2007_soft_irqwill keep reading the input data unless there is no valid pressure data. In our case, those noise data will be seen as valid data duringtsc2007_calculate_pressure(), and thetsc2007_soft_irqwill run endlessly.
Even if we add the pressure threshold would not that noise cause endless stream of interrupts?
Also, what kind of z2 is reported with low z1? And do you implement get_pendown_state()?
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Quoted 22 lines · On Thu, 1 Dec 2011 13:47:26 +0800 Dmitry Torokhov <[email protected]>…
Quoted 21 lines · Feng Tang
Quoted 6 lines · On Tue, 29 Nov 2011 17:23:10 +0800 Dmitry Torokhov <[email protected]>…
Quoted 5 lines · Feng Tang
This originates from a patch in Meego IVI kernel with the name
linux-2.6.37-connext-0027-tsc2007.patchThere is no author info excepte a line "From MeeGo <[email protected]>"
Quoted 8 lines
Quoted 4 lines
When integrating tsc2007 on Intel IVI platform, there are a lot of noise data whose z1 value is around 10 which is not a sane "z1". So add a "
z1_low_threshhold" to filter those nosie data, to make the device work properly.Sounds like a task for userspace to ignore pressure that is too low. Bonus points for making it configurable so user can adjust sensitivity.
Actually, there is one more point :), without this patch, the driver won't work on our platforms.
Quoted 7 lines
Quoted 4 lines
The
tsc2007_soft_irqwill keep reading the input data unless there is no valid pressure data. In our case, those noise data will be seen as valid data duringtsc2007_calculate_pressure(), and thetsc2007_soft_irqwill run endlessly.Even if we add the pressure threshold would not that noise cause endless stream of interrupts?
No, there is no endless interrupts for tsc2007. Without the z1 threshold, the while circle in tsc2007_soft_irq will run endlessly as the noise data will be seen as a valid data:
rt = tsc2007_calculate_pressure(ts, &tc);
if (rt == 0 && !ts->get_pendown_state) {
/*
* If pressure reported is 0 and we don't have
* callback to check pendown state, we have to
* assume that pen was lifted up.
*/
break;
}With the z1 threshold check, the rt will be 0 for noise data, and the code flow broke out.
Quoted 3 lines
Also, what kind of z2 is reported with low z1? And do you implement
get_pendown_state()?
z2 seems normal as some data between 3000-4000. We don't have a get_pendown_state().
Thanks,
Feng
Quoted 3 lines
Thanks.
Dmitry Torokhov
maintainerRe: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Quoted 47 lines · Feng Tang
Quoted 22 lines · On Thu, 1 Dec 2011 13:47:26 +0800 Dmitry Torokhov <[email protected]>…
Quoted 21 lines · Feng Tang
Quoted 6 lines · On Tue, 29 Nov 2011 17:23:10 +0800 Dmitry Torokhov <[email protected]>…
Quoted 5 lines · Feng Tang
This originates from a patch in Meego IVI kernel with the name
linux-2.6.37-connext-0027-tsc2007.patchThere is no author info excepte a line "From MeeGo <[email protected]>"
Quoted 8 lines
Quoted 4 lines
When integrating tsc2007 on Intel IVI platform, there are a lot of noise data whose z1 value is around 10 which is not a sane "z1". So add a "
z1_low_threshhold" to filter those nosie data, to make the device work properly.Sounds like a task for userspace to ignore pressure that is too low. Bonus points for making it configurable so user can adjust sensitivity.
Actually, there is one more point :), without this patch, the driver won't work on our platforms.
Quoted 7 lines
Quoted 4 lines
The
tsc2007_soft_irqwill keep reading the input data unless there is no valid pressure data. In our case, those noise data will be seen as valid data duringtsc2007_calculate_pressure(), and thetsc2007_soft_irqwill run endlessly.Even if we add the pressure threshold would not that noise cause endless stream of interrupts?
No, there is no endless interrupts for tsc2007. Without the z1 threshold, the while circle in
tsc2007_soft_irqwill run endlessly as the noise data will be seen as a valid data:rt = tsc2007_calculate_pressure(ts, &tc); if (rt == 0 && !ts->get_pendown_state) { /* * If pressure reported is 0 and we don't have * callback to check pendown state, we have to * assume that pen was lifted up. */ break; }
Quoted 2 lines
With the z1 threshold check, the rt will be 0 for noise data, and the code flow broke out.
What I meant is with the threshold check we'll break out of the ISR but why won't IRQ be raised again?
Quoted 7 lines
Quoted 4 lines
Also, what kind of z2 is reported with low z1? And do you implement
get_pendown_state()?z2 seems normal as some data between 3000-4000. We don't have a
get_pendown_state().
OK, there is max_rt platform parameter. I think we should employ it instead and break out if we get several incorrect samples in a row. Too bad you do not have a dedicate method.
Signature · 1 line
Dmitry
Re: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Hi Dmitry,
Quoted 20 lines · On Thu, 1 Dec 2011 16:45:24 +0800 Dmitry Torokhov <[email protected]>…
Quoted 20 lines
Quoted 3 lines
Even if we add the pressure threshold would not that noise cause endless stream of interrupts?
No, there is no endless interrupts for tsc2007. Without the z1 threshold, the while circle in
tsc2007_soft_irqwill run endlessly as the noise data will be seen as a valid data:rt = tsc2007_calculate_pressure(ts, &tc); if (rt == 0 && !ts->get_pendown_state) { /* * If pressure reported is 0 and we don't have * callback to check pendown state, we have to * assume that pen was lifted up. */ break; }
Quoted 5 lines
Quoted 2 lines
With the z1 threshold check, the rt will be 0 for noise data, and the code flow broke out.
What I meant is with the threshold check we'll break out of the ISR but why won't IRQ be raised again?
The IRQ will be fired again after we exist the tsc2007_soft_irq in my test, as I re-enable the irq before existing the code.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Also, what kind of z2 is reported with low z1? And do you implement
get_pendown_state()?
Quoted 7 lines
Quoted 2 lines
z2 seems normal as some data between 3000-4000. We don't have a
get_pendown_state().OK, there is
max_rtplatform parameter. I think we should employ it instead and break out if we get several incorrect samples in a row. Too bad you do not have a dedicate method.
No, the max_rt won't help here, if the rt > max_rt, it won't break the while loop, but just issue a warning message
if (rt <= ts->max_rt) {
.......
} else {
/*
* Sample found inconsistent by debouncing or pressure is
* beyond the maximum. Don't report it to user space,
* repeat at least once more the measurement.
*/
dev_dbg(&ts->client->dev, "ignored pressure %d\n", rt);
}Thanks,
Feng
Dmitry Torokhov
maintainerRe: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Quoted 52 lines · Feng Tang
Hi Dmitry,
Quoted 20 lines · On Thu, 1 Dec 2011 16:45:24 +0800 Dmitry Torokhov <[email protected]>…
Quoted 20 lines
Quoted 3 lines
Even if we add the pressure threshold would not that noise cause endless stream of interrupts?
No, there is no endless interrupts for tsc2007. Without the z1 threshold, the while circle in
tsc2007_soft_irqwill run endlessly as the noise data will be seen as a valid data:rt = tsc2007_calculate_pressure(ts, &tc); if (rt == 0 && !ts->get_pendown_state) { /* * If pressure reported is 0 and we don't have * callback to check pendown state, we have to * assume that pen was lifted up. */ break; }Quoted 5 lines
Quoted 2 lines
With the z1 threshold check, the rt will be 0 for noise data, and the code flow broke out.
What I meant is with the threshold check we'll break out of the ISR but why won't IRQ be raised again?
The IRQ will be fired again after we exist the
tsc2007_soft_irqin my test, as I re-enable the irq before existing the code.Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Also, what kind of z2 is reported with low z1? And do you implement
get_pendown_state()?Quoted 7 lines
Quoted 2 lines
z2 seems normal as some data between 3000-4000. We don't have a
get_pendown_state().OK, there is
max_rtplatform parameter. I think we should employ it instead and break out if we get several incorrect samples in a row. Too bad you do not have a dedicate method.No, the
max_rtwon't help here, if the rt >max_rt, it won't break the while loop, but just issue a warning message
Quoted 11 lines
if (rt <= ts->max_rt) {
.......
} else {
/*
* Sample found inconsistent by debouncing or pressure is
* beyond the maximum. Don't report it to user space,
* repeat at least once more the measurement.
*/
dev_dbg(&ts->client->dev, "ignored pressure %d\n", rt);
}What I meant that we need to ajust the logic to _exit_ the loop if we receive several samples with rt > max_rt instead of adding a new parameter.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Hi Dmitry,
Quoted 67 lines · On Sun, 4 Dec 2011 16:54:05 +0800 Dmitry Torokhov <[email protected]>…
Quoted 58 lines · Feng Tang
Hi Dmitry,
Quoted 20 lines · On Thu, 1 Dec 2011 16:45:24 +0800 Dmitry Torokhov <[email protected]>…
Quoted 20 lines
Quoted 3 lines
Even if we add the pressure threshold would not that noise cause endless stream of interrupts?
No, there is no endless interrupts for tsc2007. Without the z1 threshold, the while circle in
tsc2007_soft_irqwill run endlessly as the noise data will be seen as a valid data:rt = tsc2007_calculate_pressure(ts, &tc); if (rt == 0 && !ts->get_pendown_state) { /* * If pressure reported is 0 and we don't have * callback to check pendown state, we have to * assume that pen was lifted up. */ break; }Quoted 5 lines
Quoted 2 lines
With the z1 threshold check, the rt will be 0 for noise data, and the code flow broke out.
What I meant is with the threshold check we'll break out of the ISR but why won't IRQ be raised again?
The IRQ will be fired again after we exist the
tsc2007_soft_irqin my test, as I re-enable the irq before existing the code.Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Also, what kind of z2 is reported with low z1? And do you implement
get_pendown_state()?Quoted 7 lines
Quoted 2 lines
z2 seems normal as some data between 3000-4000. We don't have a
get_pendown_state().OK, there is
max_rtplatform parameter. I think we should employ it instead and break out if we get several incorrect samples in a row. Too bad you do not have a dedicate method.No, the
max_rtwon't help here, if the rt >max_rt, it won't break the while loop, but just issue a warning messageif (rt <= ts->max_rt) { ....... } else { /* * Sample found inconsistent by debouncingQuoted 7 lines
or pressure is
* beyond the maximum. Don't report it to
user space,
* repeat at least once more the
measurement. */dev_dbg(&ts->client->dev, "ignored pressure%d\n", rt); }
Quoted 3 lines
What I meant that we need to ajust the logic to _exit_ the loop if we receive several samples with rt >
max_rtinstead of adding a new parameter.
Yes, I did try a similar way to set a retry limit which also works basically, code is like this
@@ -169,6 +169,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
struct tsc2007 *ts = handle;
struct input_dev *input = ts->input;
struct ts_event tc;
+ u32 max_retry = 2;
u32 rt;
while (!ts->stopped && tsc2007_is_pen_down(ts)) {
@@ -206,6 +207,8 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
* repeat at least once more the measurement.
*/
dev_dbg(&ts->client->dev, "ignored pressure %d\n", rt);
+ if (!--max_retry)
+ break;
}But I still have some concerns:
1. How many retries should we try? the tsc2007_read_values() will take about 70 ms on our platform, plus the "poll_period", one retry will take about 100ms.
2. I checked the noise data, its z1 value is always in a range from 9 to 13, while the real data's z1 is always bigger than 300. So I think there is a very clear gap to tell the noise data from valid data by z1 value.
How do you think about it?
Thanks,
Feng
Quoted 3 lines
Thanks.
Re: [PATCH 2/2] Input: tsc2007 - Add a z1_low_threshhold platform data parameter
Hi Dmitry,
Quoted 35 lines · On Mon, 5 Dec 2011 13:35:41 +0800 Feng Tang <[email protected]> wrote:
Quoted 10 lines
Quoted 9 lines
/* * Sample found inconsistent by debouncingor pressure is
* beyond the maximum. Don't report it to
user space,
* repeat at least once more the
measurement. */dev_dbg(&ts->client->dev, "ignored pressure%d\n", rt); }
Quoted 3 lines
What I meant that we need to ajust the logic to _exit_ the loop if we receive several samples with rt >
max_rtinstead of adding a new parameter.Yes, I did try a similar way to set a retry limit which also works basically, code is like this
(quoted diff) +3
-0@@ -169,6 +169,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) struct tsc2007 *ts = handle; struct input_dev *input = ts->input; struct ts_event tc; + u32 max_retry = 2; u32 rt; while (!ts->stopped && tsc2007_is_pen_down(ts)) {@@ -206,6 +207,8 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) * repeat at least once more the measurement. */ dev_dbg(&ts->client->dev, "ignored pressure %d\n", rt); + if (!--max_retry) + break; }
Quoted 8 lines
But I still have some concerns:
1. How many retries should we try? thetsc2007_read_values()will take about 70 ms on our platform, plus the "poll_period", one retry will take about 100ms. 2. I checked the noise data, its z1 value is always in a range from 9 to 13, while the real data's z1 is always bigger than 300. So I think there is a very clear gap to tell the noise data from valid data by z1 value.How do you think about it?
Any further comments?
Thanks,
Feng
Dmitry Torokhov
maintainerHi Feng,
Quoted 3 lines · Feng Tang
The TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. So add the disable_irq/enable_irq protection around data handling.
IRQF_ONESHOT should prevent IRQ from firing again while thread is servicing it. Did you actually observe it not working?
Thanks.
Quoted 36 lines
Signed-off-by Feng Tang <[email protected]>--- drivers/input/touchscreen/tsc2007.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)drivers/input/touchscreen/tsc2007.c +8
-0@@ -171,6 +171,13 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)struct ts_event tc;u32 rt; +/* +* Disable the irq, as it may fire several other IRQs during +* this thread is handling data, as suggested by the TSC2007 +* datasheet, p19, "Touch Detect" chapter +*/ +disable_irq_nosync (irq); +while (!ts->stopped &&tsc2007_is_pen_down (ts)) {/* pen is down, continue with the measurement */ @@ -221,6 +228,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)if (ts->clear_penirq) ts->clear_penirq (); +enable_irq (irq);return IRQ_HANDLED ; }Signature · 1 line
1.7.1
Signature · 1 line
Dmitry
Hi Dmitry,
Thanks for the review.
Quoted 9 lines · On Tue, 29 Nov 2011 17:22:08 +0800 Dmitry Torokhov <[email protected]>…
Hi Feng,
Quoted 3 lines · Feng Tang
The TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. So add the disable_irq/enable_irq protection around data handling.
IRQF_ONESHOTshould prevent IRQ from firing again while thread is servicing it. Did you actually observe it not working?
You are right, the tsc's threaded IRQ function is not re-entered, and the driver is working actually. My bad not stating the problem clearly. The real problem I want solve is, many platforms including ours use a GPIO line as the tsc2007's IRQ line, and when these extra tsc2007 IRQ is triggered on the gpio line, that GPIO controller will fire up extra noise IRQ accordingly, causing its ISR to be called. And my patch is
trying to let the GPIO controller driver disable that specific IRQ pin
from tsc2007. As disable_irq will call GPIO irq_chip's irq_disable() or mask() hook.
By grep the tsc2007_platform_data in kernel, I see most of the most of the tsc2007 platforms are using GPIO line as tsc2007 IRQ ine. So this should be a general problem.
Following is patch with updated log and comments.
Thanks,
Feng
-----------------
Quoted 1 line
From
16585020d27a066d2908959e370ea4f8905a0d34Mon Sep 17 00:00:00 2001
From: Feng Tang <[email protected]>
Date: Tue, 29 Nov 2011 15:48:42 +0800
Subject: [PATCH 1/2] Input: tsc2007 - Disable irq when the irq thread is handling data
The TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. Most of the tsc2007 platforms including ours are using a gpio line as tsc2007's irq line, so calling disable_irq_nosync() to actually prevent the gpio controller from firing IRQ for tsc2007 in such case.
--- drivers/input/touchscreen/tsc2007.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/input/touchscreen/tsc2007.c +13 -0
@@ -171,6 +171,18 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)struct ts_event tc;u32 rt; +/* +* Disable the irq, as it may fire several other IRQs during +* this thread is handling data, as suggested by the TSC2007 +* datasheet, p19, "Touch Detect" chapter. +* +* Most of the tsc2007 platforms are using a gpio line as +* tsc2007's irq line, so calling disable_irq_nosync() will +* actually prevent the gpio controller from firing IRQ for +* this tsc2007 line in such case. +*/ +disable_irq_nosync (irq); +while (!ts->stopped &&tsc2007_is_pen_down (ts)) {/* pen is down, continue with the measurement */
@@ -221,6 +233,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)if (ts->clear_penirq) ts->clear_penirq (); +enable_irq (irq);return IRQ_HANDLED ; }
Signature · 1 line
1.7.1
Quoted 42 lines
Thanks.
Quoted 38 lines
Signed-off-by Feng Tang <[email protected]>--- drivers/input/touchscreen/tsc2007.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/input/touchscreen/tsc2007.cindex 1f674cb..789f216 100644drivers/input/touchscreen/tsc2007.c +2
-0@@ -171,6 +171,13 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) struct ts_event tc;u32 rt; +/* +* Disable the irq, as it may fire several other IRQs during
drivers/input/touchscreen/tsc2007.c +1
-0+* this thread is handling data, as suggested by the TSC2007
drivers/input/touchscreen/tsc2007.c +5
-0+* datasheet, p19, "Touch Detect" chapter +*/ +disable_irq_nosync (irq); +while (!ts->stopped &&tsc2007_is_pen_down (ts)) {/* pen is down, continue with the measurement */ @@ -221,6 +228,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) if (ts->clear_penirq) ts->clear_penirq (); +enable_irq (irq);return IRQ_HANDLED ; }Signature · 1 line
1.7.1
Dmitry Torokhov
maintainerQuoted 17 lines · Feng Tang
Hi Dmitry,
Thanks for the review.
Quoted 9 lines · On Tue, 29 Nov 2011 17:22:08 +0800 Dmitry Torokhov <[email protected]>…
Hi Feng,
Quoted 3 lines · Feng Tang
The TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. So add the disable_irq/enable_irq protection around data handling.
IRQF_ONESHOTshould prevent IRQ from firing again while thread is servicing it. Did you actually observe it not working?
Quoted 9 lines
You are right, the tsc's threaded IRQ function is not re-entered, and the driver is working actually. My bad not stating the problem clearly. The real problem I want solve is, many platforms including ours use a GPIO line as the tsc2007's IRQ line, and when these extra tsc2007 IRQ is triggered on the gpio line, that GPIO controller will fire up extra noise IRQ accordingly, causing its ISR to be called. And my patch is
trying to let the GPIO controller driver disable that specific IRQ pin
from tsc2007. Asdisable_irqwill call GPIO irq_chip'sirq_disable()ormask()hook.
But ONESHOT interrupt handler will not unmask interrupt until thead finishes servicing it so we should not be seeing these extra IRQs. I'm adding Thomas in case I misunderstand how it threaded IRQ supposed to work.
Also, there is clear_penirq() platform method that is called to clean penirq state, if needed.
Quoted 103 lines
By grep the
tsc2007_platform_datain kernel, I see most of the most of the tsc2007 platforms are using GPIO line as tsc2007 IRQ ine. So this should be a general problem.Following is patch with updated log and comments.
Thanks,
Feng-----------------
From
16585020d27a066d2908959e370ea4f8905a0d34Mon Sep 17 00:00:00 2001
From: Feng Tang <[email protected]>
Date: Tue, 29 Nov 2011 15:48:42 +0800
Subject: [PATCH 1/2] Input: tsc2007 - Disable irq when the irq thread is handling dataThe TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. Most of the tsc2007 platforms including ours are using a gpio line as tsc2007's irq line, so calling
disable_irq_nosync()to actually prevent the gpio controller from firing IRQ for tsc2007 in such case.Signed-off-by Feng Tang <[email protected]>--- drivers/input/touchscreen/tsc2007.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)drivers/input/touchscreen/tsc2007.c +13
-0@@ -171,6 +171,18 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)struct ts_event tc;u32 rt; +/* +* Disable the irq, as it may fire several other IRQs during +* this thread is handling data, as suggested by the TSC2007 +* datasheet, p19, "Touch Detect" chapter. +* +* Most of the tsc2007 platforms are using a gpio line as +* tsc2007's irq line, so calling disable_irq_nosync() will +* actually prevent the gpio controller from firing IRQ for +* this tsc2007 line in such case. +*/ +disable_irq_nosync (irq); +while (!ts->stopped &&tsc2007_is_pen_down (ts)) {/* pen is down, continue with the measurement */ @@ -221,6 +233,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)if (ts->clear_penirq) ts->clear_penirq (); +enable_irq (irq);return IRQ_HANDLED ; }Signature · 1 line
1.7.1Quoted 42 lines
Thanks.
Quoted 38 lines
Signed-off-by Feng Tang <[email protected]>--- drivers/input/touchscreen/tsc2007.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/input/touchscreen/tsc2007.cindex 1f674cb..789f216 100644drivers/input/touchscreen/tsc2007.c +2
-0@@ -171,6 +171,13 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) struct ts_event tc;u32 rt; +/* +* Disable the irq, as it may fire several other IRQs during
drivers/input/touchscreen/tsc2007.c +1
-0+* this thread is handling data, as suggested by the TSC2007
drivers/input/touchscreen/tsc2007.c +5
-0+* datasheet, p19, "Touch Detect" chapter +*/ +disable_irq_nosync (irq); +while (!ts->stopped &&tsc2007_is_pen_down (ts)) {/* pen is down, continue with the measurement */ @@ -221,6 +228,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) if (ts->clear_penirq) ts->clear_penirq (); +enable_irq (irq);return IRQ_HANDLED ; }Signature · 1 line
1.7.1
Signature · 1 line
Dmitry
Hi Dmitry,
Quoted 29 lines · On Thu, 1 Dec 2011 14:10:15 +0800 Dmitry Torokhov <[email protected]>…
Quoted 18 lines · Feng Tang
Hi Dmitry,
Thanks for the review.
Quoted 10 lines · On Tue, 29 Nov 2011 17:22:08 +0800 Dmitry Torokhov <[email protected]>…
Hi Feng,
Quoted 4 lines · Feng Tang
The TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. So add the disable_irq/enable_irq protection around data handling.
IRQF_ONESHOTshould prevent IRQ from firing again while thread is servicing it. Did you actually observe it not working?Quoted 9 lines
You are right, the tsc's threaded IRQ function is not re-entered, and the driver is working actually. My bad not stating the problem clearly. The real problem I want solve is, many platforms including ours use a GPIO line as the tsc2007's IRQ line, and when these extra tsc2007 IRQ is triggered on the gpio line, that GPIO controller will fire up extra noise IRQ accordingly, causing its ISR to be called. And my patch is trying to let the GPIO controller driver disable that specific IRQ pin from tsc2007. As
disable_irqwill call GPIO irq_chip'sirq_disable()ormask()hook.
Quoted 4 lines
But ONESHOT interrupt handler will not unmask interrupt until thead finishes servicing it so we should not be seeing these extra IRQs. I'm adding Thomas in case I misunderstand how it threaded IRQ supposed to work.
I did see these extra IRQs. As the tsc2007 datasheet says, the PENIRQ may be falsely triggered, and that signal is passed to the GPIO controller, if the tsc2007 specific pin is not disabled in GPIOC level, then the GPIOC HW will send out a IRQ anyway.
While calling the disable_irq(), it will call the irq_chip's (implemented by GPIO controller) irq_disable() or irq_mask() hook to disable that specific line for tsc2007.
I did check the original tsc2007 driver, which used the disable_irq/enable_irq too, which means this problem is a general one and has been seen before.
Or should we have a another flag in tsc2007 platform data, to let each platform chose whether or not to use the disable/enable_irq according to their platform need.
Quoted 3 lines
Also, there is
clear_penirq()platform method that is called to clean penirq state, if needed.
Sadly we don't have a way to clear the irq from TSC2007 on our platform :(
Thanks,
Feng
Quoted 67 lines
Quoted 67 lines
By grep the
tsc2007_platform_datain kernel, I see most of the most of the tsc2007 platforms are using GPIO line as tsc2007 IRQ ine. So this should be a general problem.Following is patch with updated log and comments.
Thanks,
Feng-----------------
From
16585020d27a066d2908959e370ea4f8905a0d34Mon Sep 17 00:00:00 2001 From: Feng Tang <[email protected]>
Date: Tue, 29 Nov 2011 15:48:42 +0800
Subject: [PATCH 1/2] Input: tsc2007 - Disable irq when the irq thread is handling dataThe TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. Most of the tsc2007 platforms including ours are using a gpio line as tsc2007's irq line, so calling
disable_irq_nosync()to actually prevent the gpio controller from firing IRQ for tsc2007 in such case.Signed-off-by Feng Tang <[email protected]>--- drivers/input/touchscreen/tsc2007.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/input/touchscreen/tsc2007.cindex 1f674cb..03c1961 100644drivers/input/touchscreen/tsc2007.c +2
-0@@ -171,6 +171,18 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) struct ts_event tc;u32 rt; +/* +* Disable the irq, as it may fire several other IRQs during
drivers/input/touchscreen/tsc2007.c +1
-0+* this thread is handling data, as suggested by the TSC2007
drivers/input/touchscreen/tsc2007.c +10
-0+* datasheet, p19, "Touch Detect" chapter. +* +* Most of the tsc2007 platforms are using a gpio line as +* tsc2007's irq line, so calling disable_irq_nosync() will +* actually prevent the gpio controller from firing IRQ for +* this tsc2007 line in such case. +*/ +disable_irq_nosync (irq); +while (!ts->stopped &&tsc2007_is_pen_down (ts)) {/* pen is down, continue with the measurement */ @@ -221,6 +233,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) if (ts->clear_penirq) ts->clear_penirq (); +enable_irq (irq);return IRQ_HANDLED ; }Signature · 1 line
1.7.1
Dmitry Torokhov
maintainerQuoted 44 lines · Feng Tang
Hi Dmitry,
Quoted 29 lines · On Thu, 1 Dec 2011 14:10:15 +0800 Dmitry Torokhov <[email protected]>…
Quoted 18 lines · Feng Tang
Hi Dmitry,
Thanks for the review.
Quoted 10 lines · On Tue, 29 Nov 2011 17:22:08 +0800 Dmitry Torokhov <[email protected]>…
Hi Feng,
Quoted 4 lines · Feng Tang
The TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. So add the disable_irq/enable_irq protection around data handling.
IRQF_ONESHOTshould prevent IRQ from firing again while thread is servicing it. Did you actually observe it not working?Quoted 9 lines
You are right, the tsc's threaded IRQ function is not re-entered, and the driver is working actually. My bad not stating the problem clearly. The real problem I want solve is, many platforms including ours use a GPIO line as the tsc2007's IRQ line, and when these extra tsc2007 IRQ is triggered on the gpio line, that GPIO controller will fire up extra noise IRQ accordingly, causing its ISR to be called. And my patch is trying to let the GPIO controller driver disable that specific IRQ pin from tsc2007. As
disable_irqwill call GPIO irq_chip'sirq_disable()ormask()hook.Quoted 4 lines
But ONESHOT interrupt handler will not unmask interrupt until thead finishes servicing it so we should not be seeing these extra IRQs. I'm adding Thomas in case I misunderstand how it threaded IRQ supposed to work.
I did see these extra IRQs. As the tsc2007 datasheet says, the PENIRQ may be falsely triggered, and that signal is passed to the GPIO controller, if the tsc2007 specific pin is not disabled in GPIOC level, then the GPIOC HW will send out a IRQ anyway.
Quoted 7 lines
While calling the
disable_irq(), it will call the irq_chip's (implemented by GPIO controller)irq_disable()orirq_mask()hook to disable that specific line for tsc2007.I did check the original tsc2007 driver, which used the disable_irq/enable_irq too, which means this problem is a general one and has been seen before.
No, the original had disable/enable IRQ because it was the only way to stop interrupt storm with combination of hard IRQ + workqueue or thread.
BTW, do you have it configured as level or edge interrupt?
Quoted 10 lines
Or should we have a another flag in tsc2007 platform data, to let each platform chose whether or not to use the disable/enable_irq according to their platform need.
Quoted 3 lines
Also, there is
clear_penirq()platform method that is called to clean penirq state, if needed.Sadly we don't have a way to clear the irq from TSC2007 on our platform :(
Thanks.
Signature · 1 line
Dmitry
Hi Dmitry
Quoted 51 lines · On Thu, 1 Dec 2011 16:48:18 +0800 Dmitry Torokhov <[email protected]>…
Quoted 50 lines · Feng Tang
Hi Dmitry,
Quoted 31 lines · On Thu, 1 Dec 2011 14:10:15 +0800 Dmitry Torokhov <[email protected]>…
Quoted 19 lines · Feng Tang
Hi Dmitry,
Thanks for the review.
Quoted 11 lines · On Tue, 29 Nov 2011 17:22:08 +0800 Dmitry Torokhov <[email protected]>…
Hi Feng,
Quoted 4 lines · Feng Tang
The TSC2007 data sheet say in some case the HW may fire some false interrrupt, which I also met during integrating one TSC2007 device. So add the disable_irq/enable_irq protection around data handling.
IRQF_ONESHOTshould prevent IRQ from firing again while thread is servicing it. Did you actually observe it not working?Quoted 10 lines
You are right, the tsc's threaded IRQ function is not re-entered, and the driver is working actually. My bad not stating the problem clearly. The real problem I want solve is, many platforms including ours use a GPIO line as the tsc2007's IRQ line, and when these extra tsc2007 IRQ is triggered on the gpio line, that GPIO controller will fire up extra noise IRQ accordingly, causing its ISR to be called. And my patch is trying to let the GPIO controller driver disable that specific IRQ pin from tsc2007. As
disable_irqwill call GPIO irq_chip'sirq_disable()ormask()hook.Quoted 4 lines
But ONESHOT interrupt handler will not unmask interrupt until thead finishes servicing it so we should not be seeing these extra IRQs. I'm adding Thomas in case I misunderstand how it threaded IRQ supposed to work.
I did see these extra IRQs. As the tsc2007 datasheet says, the PENIRQ may be falsely triggered, and that signal is passed to the GPIO controller, if the tsc2007 specific pin is not disabled in GPIOC level, then the GPIOC HW will send out a IRQ anyway.
While calling the
disable_irq(), it will call the irq_chip's (implemented by GPIO controller)irq_disable()orirq_mask()hook to disable that specific line for tsc2007.
Quoted 8 lines
Quoted 4 lines
I did check the original tsc2007 driver, which used the disable_irq/enable_irq too, which means this problem is a general one and has been seen before.
No, the original had disable/enable IRQ because it was the only way to stop interrupt storm with combination of hard IRQ + workqueue or thread.
My understanding is, if the GPIO line used by tsc2007 is not disabled in GPIO controller level, the GPIOC will always be triggered by tsc2007 to fire those extra interrupts.
Actually I did try the old version driver (no threaded irq version), which will see the extra interrupts if the disable_irq/enable_irq is removed.
Quoted 2 lines
BTW, do you have it configured as level or edge interrupt?
I'm now using the falling edge trigger, but I tried the level trigger which will have more interrupts storm.
Thanks,
Feng
Quoted 15 lines
Quoted 6 lines
Or should we have a another flag in tsc2007 platform data, to let each platform chose whether or not to use the disable/enable_irq according to their platform need.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Also, there is
clear_penirq()platform method that is called to clean penirq state, if needed.Sadly we don't have a way to clear the irq from TSC2007 on our platform :(
Thanks.