Skip to contentSkip to conversation

Fix tsc2007 to report ABS_PRESSURE correctly

PATCH Applied H. Nikolaus Schaller 4 participants 10 messages Feb 20, 2017 – Feb 23, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Fix tsc2007 to report ABS_PRESSURE correctly

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(-)
Signature · 1 line
2.7.3
#1 lore raw

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

---
 drivers/input/touchscreen/tsc2007_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/input/touchscreen/tsc2007_core.c +4 -4
index 98dbefc..30b53ca 100644
@@ -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);
Signature · 1 line
2.7.3
maintainer Applied
#2 lore raw

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

Quoted 1 line · H. Nikolaus Schaller

p Signed-off-by: H. Nikolaus Schaller <[email protected]>

Applied, thank you.

Quoted 47 lines
---
 drivers/input/touchscreen/tsc2007_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/input/touchscreen/tsc2007_core.c +4 -4
index 98dbefc..30b53ca 100644
@@ -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);
Signature · 1 line
2.7.3
Signature · 1 line
Dmitry
#3 lore raw

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

In reply to H. Nikolaus Schaller

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.

---
 drivers/input/touchscreen/tsc2007_core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/touchscreen/tsc2007_core.c +2 -0
index 30b53ca..fc73849 100644
@@ -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);
Signature · 6 lines
2.7.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v1 2/3
#4 lore raw

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

Hi,

Quoted 34 lines · H. Nikolaus Schaller

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.

---
 drivers/input/touchscreen/tsc2007_core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/touchscreen/tsc2007_core.c +0 -0
index 30b53ca..fc73849 100644

drivers/input/touchscreen/tsc2007_core.c static irqreturn_t tsc2007_soft_irq(int irq, void *handle) · line 148

Quoted 8 lines
drivers/input/touchscreen/tsc2007_core.c +2 -0
@@ -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);

We should add the same to ts200x-core.

-- Sebastian

maintainer Applied
#5 lore raw

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

Quoted 40 lines · Sebastian Reichel

Hi,

Quoted 37 lines · H. Nikolaus Schaller

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.

---
 drivers/input/touchscreen/tsc2007_core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/touchscreen/tsc2007_core.c +0 -0
index 30b53ca..fc73849 100644
@@ -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);
 
Quoted 7 lines

drivers/input/touchscreen/tsc2007_core.c static irqreturn_t tsc2007_soft_irq(int irq, void *handle) · line 148

Quoted 5 lines
drivers/input/touchscreen/tsc2007_core.c +2 -0
+			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);

Applied, thank you.

Signature · 5 lines
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

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

In reply to H. Nikolaus Schaller
---
 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(-)
Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt +2 -0
index ec365e1..9b686af 100644
@@ -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.
drivers/input/touchscreen/tsc2007.h +1 -0
index 474bd29..81baabb 100644
@@ -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;
drivers/input/touchscreen/tsc2007_core.c +5 -1
index fc73849..984710f 100644
@@ -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;
 
Signature · 1 line
2.7.3
#7 lore raw

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

Quoted 1 line · H. Nikolaus Schaller

No. device tree is for hardware description, not kernel configuration.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#8 lore raw

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

Hi Pavel,

Quoted 6 lines

Am 21.02.2017 um 12:07 schrieb Pavel Machek <[email protected]>:

Quoted 1 line · H. Nikolaus Schaller

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

#9 lore raw

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

Hi,

Quoted 6 lines · H. Nikolaus Schaller
Quoted 5 lines

Am 21.02.2017 um 12:07 schrieb Pavel Machek <[email protected]>:

Quoted 1 line · H. Nikolaus Schaller

No. device tree is for hardware description, not kernel configuration.

Quoted 8 lines

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