[PATCH 0/3] Fix tsc2007 to report ABS_PRESSURE correctly

STALE3462d

10 messages, 4 authors, 2017-02-23 · open the first message on its own page

[PATCH 0/3] Fix tsc2007 to report ABS_PRESSURE correctly

From: H. Nikolaus Schaller <hidden>
Date: 2017-02-20 16:57:32

tsc2007 reports the touch resistance as ABS_PRESSURE, which jumps
to its maximum for light touch and goes down for increasing pressure.
This is not consistent with other touch drivers and not what one would
expect.

Additionally the name of the function tsc2007_calculate_pressure()
is misleading since the formula calculates an estimate for the touch
screen resistance. So it is renamed without changing the function.

While this patch changes the values reported to userspace,
ABS_PRESSURE is used rarely by userspace. Most software only
relies on BTN_TOUCH (boolean), which is not affected by this
patch. Some graphics software makes use of the interface and
does not work correctly with the currently used inverted
behaviour.

Note: this patch series assumes to be merged after

	"Input: tsc2007 - add iio interface to read external ADC input and temperature"

because that one renames tsc2007.c to tsc2007_core.c

H. Nikolaus Schaller (3):
  Input: tsc2007 - rename function tsc2007_calculate_pressure to
    tsc2007_calculate_resistance     because that is what it does
  Input: tsc2007 - correctly report pressure and not resistance to user
    space
  Input: tsc2007 - add a property "ti,report-resistance" to restore the
    old pressure reporting state     if needed.

 .../devicetree/bindings/input/touchscreen/tsc2007.txt      |  2 ++
 drivers/input/touchscreen/tsc2007.h                        |  1 +
 drivers/input/touchscreen/tsc2007_core.c                   | 14 ++++++++++----
 3 files changed, 13 insertions(+), 4 deletions(-)

-- 
2.7.3

[PATCH 3/3] Input: tsc2007 - add a property "ti,report-resistance" to restore the old pressure reporting state if needed.

From: H. Nikolaus Schaller <hidden>
Date: 2017-02-20 16:57:08

Signed-off-by: H. Nikolaus Schaller <redacted>
---
 Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt | 2 ++
 drivers/input/touchscreen/tsc2007.h                             | 1 +
 drivers/input/touchscreen/tsc2007_core.c                        | 6 +++++-
 3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt b/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt
index ec365e1..9b686af 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt
@@ -14,6 +14,8 @@ Optional properties:
 - interrupts: (gpio) interrupt to which the chip is connected
   (see interrupt binding[0]).
 - ti,max-rt: maximum pressure.
+- ti,report-resistance: report resistance (no pressure = max_rt) instead
+  of pressure (no pressure = 0).
 - ti,fuzzx: specifies the absolute input fuzz x value.
   If set, it will permit noise in the data up to +- the value given to the fuzz
   parameter, that is used to filter noise from the event stream.
diff --git a/drivers/input/touchscreen/tsc2007.h b/drivers/input/touchscreen/tsc2007.h
index 474bd29..81baabb 100644
--- a/drivers/input/touchscreen/tsc2007.h
+++ b/drivers/input/touchscreen/tsc2007.h
@@ -66,6 +66,7 @@ struct tsc2007 {
 
 	u16			model;
 	u16			x_plate_ohms;
+	bool			report_resistance;
 	u16			max_rt;
 	unsigned long		poll_period; /* in jiffies */
 	int			fuzzx;
diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index fc73849..984710f 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -141,7 +141,8 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 				"DOWN point(%4d,%4d), resistance (%4u)\n",
 				tc.x, tc.y, rt);
 
-			rt = ts->max_rt - rt;
+			if (!ts->report_resistance)
+				rt = ts->max_rt - rt;
 
 			input_report_key(input, BTN_TOUCH, 1);
 			input_report_abs(input, ABS_X, tc.x);
@@ -248,6 +249,9 @@ static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts)
 	else
 		ts->max_rt = MAX_12BIT;
 
+	ts->report_resistance =
+		of_property_read_bool(np, "ti,report-resistance");
+
 	if (!of_property_read_u32(np, "ti,fuzzx", &val32))
 		ts->fuzzx = val32;
 
-- 
2.7.3

[PATCH 1/3] Input: tsc2007 - rename function tsc2007_calculate_pressure to tsc2007_calculate_resistance because that is what it does

From: H. Nikolaus Schaller <hidden>
Date: 2017-02-20 16:57:13

Signed-off-by: H. Nikolaus Schaller <redacted>
---
 drivers/input/touchscreen/tsc2007_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index 98dbefc..30b53ca 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -68,7 +68,7 @@ static void tsc2007_read_values(struct tsc2007 *tsc, struct ts_event *tc)
 	tsc2007_xfer(tsc, PWRDOWN);
 }
 
-u32 tsc2007_calculate_pressure(struct tsc2007 *tsc, struct ts_event *tc)
+u32 tsc2007_calculate_resistance(struct tsc2007 *tsc, struct ts_event *tc)
 {
 	u32 rt = 0;
 
@@ -77,7 +77,7 @@ u32 tsc2007_calculate_pressure(struct tsc2007 *tsc, struct ts_event *tc)
 		tc->x = 0;
 
 	if (likely(tc->x && tc->z1)) {
-		/* compute touch pressure resistance using equation #1 */
+		/* compute touch resistance using equation #1 */
 		rt = tc->z2 - tc->z1;
 		rt *= tc->x;
 		rt *= tsc->x_plate_ohms;
@@ -125,7 +125,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 		tsc2007_read_values(ts, &tc);
 		mutex_unlock(&ts->mlock);
 
-		rt = tsc2007_calculate_pressure(ts, &tc);
+		rt = tsc2007_calculate_resistance(ts, &tc);
 
 		if (!rt && !ts->get_pendown_state) {
 			/*
@@ -138,7 +138,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 
 		if (rt <= ts->max_rt) {
 			dev_dbg(&ts->client->dev,
-				"DOWN point(%4d,%4d), pressure (%4u)\n",
+				"DOWN point(%4d,%4d), resistance (%4u)\n",
 				tc.x, tc.y, rt);
 
 			input_report_key(input, BTN_TOUCH, 1);
-- 
2.7.3

[PATCH 2/3] Input: tsc2007 - correctly report pressure and not resistance to user space

From: H. Nikolaus Schaller <hidden>
Date: 2017-02-20 16:57:30

previously, tsc2007 will report as ABS_PRESSURE:
0              for no pressure (resistance infinite)
high value     for soft pressure (high resistance)
low value      for firm pressure (lower resistance)

This does not matter for most applications (e.g. GUI, Menu, Scrolling
etc.) where the ABS_PRESSURE is ignored and only BTN_TOUCH is processed
to detect screen taps.

Only some special graphics applications read the pressure channel and
they will be mixed up by this non-monotonic relation.

So we fix it to become:
0              for no pressure (resistance infinite)
low value      for soft pressure (high resistance)
high value     for firm pressure (lower resistance)

While this patch changes the values reported to userspace,
ABS_PRESSURE is used rarely by userspace. Most software only
relies on BTN_TOUCH (boolean), which is not affected by this
patch. Some graphics software makes use of the interface and
does not work correctly with the currently used inverted
behaviour.

Signed-off-by: H. Nikolaus Schaller <redacted>
---
 drivers/input/touchscreen/tsc2007_core.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index 30b53ca..fc73849 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -141,6 +141,8 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 				"DOWN point(%4d,%4d), resistance (%4u)\n",
 				tc.x, tc.y, rt);
 
+			rt = ts->max_rt - rt;
+
 			input_report_key(input, BTN_TOUCH, 1);
 			input_report_abs(input, ABS_X, tc.x);
 			input_report_abs(input, ABS_Y, tc.y);
-- 
2.7.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Re: [PATCH 3/3] Input: tsc2007 - add a property "ti,report-resistance" to restore the old pressure reporting state if needed.

From: Pavel Machek <hidden>
Date: 2017-02-21 11:07:28

On Mon 2017-02-20 17:56:36, H. Nikolaus Schaller wrote:
Signed-off-by: H. Nikolaus Schaller <redacted>
No. device tree is for hardware description, not kernel configuration.

									Pavel
									
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Re: [PATCH 3/3] Input: tsc2007 - add a property "ti,report-resistance" to restore the old pressure reporting state if needed.

From: H. Nikolaus Schaller <hidden>
Date: 2017-02-21 11:44:04

Hi Pavel,
Am 21.02.2017 um 12:07 schrieb Pavel Machek [off-list ref]:

On Mon 2017-02-20 17:56:36, H. Nikolaus Schaller wrote:
quoted
Signed-off-by: H. Nikolaus Schaller <redacted>
No. device tree is for hardware description, not kernel configuration.
Yes, I agree. A new Kernel CONFIG would be better in this case.
I just did copy&paste from the old patch set without thinking that far.

Would

CONFIG_TSC2007_REPORT_RAW_RESISTANCE_AS_PRESSURE

be ok?

BR and thanks,
Nikolaus

Re: [PATCH 2/3] Input: tsc2007 - correctly report pressure and not resistance to user space

From: Sebastian Reichel <sre@kernel.org>
Date: 2017-02-21 17:14:09

Hi,

On Mon, Feb 20, 2017 at 05:56:35PM +0100, H. Nikolaus Schaller wrote:
quoted hunk
previously, tsc2007 will report as ABS_PRESSURE:
0              for no pressure (resistance infinite)
high value     for soft pressure (high resistance)
low value      for firm pressure (lower resistance)

This does not matter for most applications (e.g. GUI, Menu, Scrolling
etc.) where the ABS_PRESSURE is ignored and only BTN_TOUCH is processed
to detect screen taps.

Only some special graphics applications read the pressure channel and
they will be mixed up by this non-monotonic relation.

So we fix it to become:
0              for no pressure (resistance infinite)
low value      for soft pressure (high resistance)
high value     for firm pressure (lower resistance)

While this patch changes the values reported to userspace,
ABS_PRESSURE is used rarely by userspace. Most software only
relies on BTN_TOUCH (boolean), which is not affected by this
patch. Some graphics software makes use of the interface and
does not work correctly with the currently used inverted
behaviour.

Signed-off-by: H. Nikolaus Schaller <redacted>
---
 drivers/input/touchscreen/tsc2007_core.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index 30b53ca..fc73849 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -141,6 +141,8 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 				"DOWN point(%4d,%4d), resistance (%4u)\n",
 				tc.x, tc.y, rt);
 
+			rt = ts->max_rt - rt;
+
 			input_report_key(input, BTN_TOUCH, 1);
 			input_report_abs(input, ABS_X, tc.x);
 			input_report_abs(input, ABS_Y, tc.y);
Reviewed-By: Sebastian Reichel <redacted>

We should add the same to ts200x-core.

-- Sebastian

Re: [PATCH 3/3] Input: tsc2007 - add a property "ti,report-resistance" to restore the old pressure reporting state if needed.

From: Sebastian Reichel <sre@kernel.org>
Date: 2017-02-21 17:20:05

Hi,

On Tue, Feb 21, 2017 at 12:43:28PM +0100, H. Nikolaus Schaller wrote:
quoted
Am 21.02.2017 um 12:07 schrieb Pavel Machek [off-list ref]:
On Mon 2017-02-20 17:56:36, H. Nikolaus Schaller wrote:
quoted
Signed-off-by: H. Nikolaus Schaller <redacted>
No. device tree is for hardware description, not kernel configuration.
Yes, I agree. A new Kernel CONFIG would be better in this case.
I just did copy&paste from the old patch set without thinking that far.

Would

CONFIG_TSC2007_REPORT_RAW_RESISTANCE_AS_PRESSURE

be ok?
I guess either a CONFIG or a module parameter may be used to provide
the previous (broken) behaviour. I suggest to ignore the problem
until its reported, though. There is a high chance, that nobody will
notice the change at all / nobody needs the compat layer.

-- Sebastian

Re: [PATCH 1/3] Input: tsc2007 - rename function tsc2007_calculate_pressure to tsc2007_calculate_resistance because that is what it does

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: 2017-02-23 08:45:16

On Mon, Feb 20, 2017 at 05:56:34PM +0100, H. Nikolaus Schaller wrote:
p Signed-off-by: H. Nikolaus Schaller [off-list ref]
Applied, thank you.
quoted hunk
---
 drivers/input/touchscreen/tsc2007_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index 98dbefc..30b53ca 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -68,7 +68,7 @@ static void tsc2007_read_values(struct tsc2007 *tsc, struct ts_event *tc)
 	tsc2007_xfer(tsc, PWRDOWN);
 }
 
-u32 tsc2007_calculate_pressure(struct tsc2007 *tsc, struct ts_event *tc)
+u32 tsc2007_calculate_resistance(struct tsc2007 *tsc, struct ts_event *tc)
 {
 	u32 rt = 0;
 
@@ -77,7 +77,7 @@ u32 tsc2007_calculate_pressure(struct tsc2007 *tsc, struct ts_event *tc)
 		tc->x = 0;
 
 	if (likely(tc->x && tc->z1)) {
-		/* compute touch pressure resistance using equation #1 */
+		/* compute touch resistance using equation #1 */
 		rt = tc->z2 - tc->z1;
 		rt *= tc->x;
 		rt *= tsc->x_plate_ohms;
@@ -125,7 +125,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 		tsc2007_read_values(ts, &tc);
 		mutex_unlock(&ts->mlock);
 
-		rt = tsc2007_calculate_pressure(ts, &tc);
+		rt = tsc2007_calculate_resistance(ts, &tc);
 
 		if (!rt && !ts->get_pendown_state) {
 			/*
@@ -138,7 +138,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 
 		if (rt <= ts->max_rt) {
 			dev_dbg(&ts->client->dev,
-				"DOWN point(%4d,%4d), pressure (%4u)\n",
+				"DOWN point(%4d,%4d), resistance (%4u)\n",
 				tc.x, tc.y, rt);
 
 			input_report_key(input, BTN_TOUCH, 1);
-- 
2.7.3
-- 
Dmitry

Re: [PATCH 2/3] Input: tsc2007 - correctly report pressure and not resistance to user space

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: 2017-02-23 08:45:37

On Tue, Feb 21, 2017 at 06:13:32PM +0100, Sebastian Reichel wrote:
Hi,

On Mon, Feb 20, 2017 at 05:56:35PM +0100, H. Nikolaus Schaller wrote:
quoted
previously, tsc2007 will report as ABS_PRESSURE:
0              for no pressure (resistance infinite)
high value     for soft pressure (high resistance)
low value      for firm pressure (lower resistance)

This does not matter for most applications (e.g. GUI, Menu, Scrolling
etc.) where the ABS_PRESSURE is ignored and only BTN_TOUCH is processed
to detect screen taps.

Only some special graphics applications read the pressure channel and
they will be mixed up by this non-monotonic relation.

So we fix it to become:
0              for no pressure (resistance infinite)
low value      for soft pressure (high resistance)
high value     for firm pressure (lower resistance)

While this patch changes the values reported to userspace,
ABS_PRESSURE is used rarely by userspace. Most software only
relies on BTN_TOUCH (boolean), which is not affected by this
patch. Some graphics software makes use of the interface and
does not work correctly with the currently used inverted
behaviour.

Signed-off-by: H. Nikolaus Schaller <redacted>
---
 drivers/input/touchscreen/tsc2007_core.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index 30b53ca..fc73849 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -141,6 +141,8 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle)
 				"DOWN point(%4d,%4d), resistance (%4u)\n",
 				tc.x, tc.y, rt);
 
+			rt = ts->max_rt - rt;
+
 			input_report_key(input, BTN_TOUCH, 1);
 			input_report_abs(input, ABS_X, tc.x);
 			input_report_abs(input, ABS_Y, tc.y);
Reviewed-By: Sebastian Reichel <redacted>
Applied, thank you.

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help