Input: touchscreen - parse touchscreen-x-mm and touchscreen-y-mm properties
Subsystems (4)
Dmitry Torokhov
maintainercover Input: touchscreen - parse touchscreen-x-mm and touchscreen-y-mm properties
The common touchscreen device tree binding documents touchscreen-x-mm and touchscreen-y-mm to specify the physical dimensions of the touch surface, which userspace uses via axis resolution (units/mm) for gesture scaling and palm rejection. However, touchscreen_parse_properties() has not been parsing these properties.
This series teaches touchscreen_parse_properties() to read touchscreen-x-mm and touchscreen-y-mm and calculate the corresponding X and Y axis resolutions from the configured axis ranges, accompanied by KUnit tests.
It also updates wacom_w9000 to drop its manual parsing of these properties, and adjusts goodix-berlin and apple_z2 to set their fallback resolutions before calling touchscreen_parse_properties() so firmware- provided dimensions can override the defaults instead of being clobbered.
Dmitry Torokhov (4):
Input: touchscreen - parse touchscreen-x-mm and touchscreen-y-mm
Input: wacom_w9000 - rely on touchscreen_parse_properties() for
resolution
Input: goodix-berlin - set default resolution before parsing
properties
Input: apple_z2 - set default resolution before parsing properties
drivers/input/tests/Makefile | 1 + drivers/input/tests/touchscreen_test.c | 209 ++++++++++++++++++ drivers/input/touchscreen.c | 18 +- drivers/input/touchscreen/apple_z2.c | 2 +- .../input/touchscreen/goodix_berlin_core.c | 4 +- drivers/input/touchscreen/wacom_w9000.c | 10 - 6 files changed, 226 insertions(+), 18 deletions(-) create mode 100644 drivers/input/tests/touchscreen_test.c
Signature · 1 line
2.56.0.385.gac671c819a-goog
Dmitry Torokhov
maintainerPATCH 1/4 Input: touchscreen - parse touchscreen-x-mm and touchscreen-y-mm
The touchscreen device tree bindings define common touchscreen-x-mm and touchscreen-y-mm properties specifying the physical dimensions of the touchscreen in millimeters. However, touchscreen_parse_properties() does not parse these properties, forcing individual drivers to parse them manually or fall back to arbitrary resolution values.
Parse touchscreen-x-mm and touchscreen-y-mm in touchscreen_parse_properties() and calculate axis resolution in units per millimeter as the coordinate count (maximum - minimum + 1) divided by the physical dimension, rounded to the nearest integer. Guard against zero physical size or invalid axis ranges, and preserve pre-existing resolution settings when the properties are omitted. Apply resolution before early exit so callers passing a NULL properties pointer still get axes configured and so coordinate inversion and axis swapping continue to work seamlessly. Also add KUnit test coverage for resolution calculation.
--- drivers/input/tests/Makefile | 1 + drivers/input/tests/touchscreen_test.c | 209 +++++++++++++++++++++++++ drivers/input/touchscreen.c | 18 ++- 3 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 drivers/input/tests/touchscreen_test.c
drivers/input/tests/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_INPUT_KUNIT_TEST) += input_test.o +obj-$(CONFIG_INPUT_KUNIT_TEST) += touchscreen_test.o
drivers/input/tests/touchscreen_test.c new file +209 -0
209 lines not on this page · raw message
drivers/input/touchscreen.c +13 -5
@@ -7,6 +7,7 @@*/ #include <linux/export.h> +#include <linux/math.h> #include <linux/property.h> #include <linux/input.h> #include <linux/input/mt.h>
@@ -33,7 +34,8 @@ static bool touchscreen_get_prop_u32(struct device *dev,static void touchscreen_set_params (struct input_dev *dev,unsigned long axis, -int min,int max,int fuzz) +int min,int max,int fuzz, +unsigned int size_mm) {struct input_absinfo *absinfo;
@@ -48,6 +50,8 @@ static void touchscreen_set_params(struct input_dev *dev, absinfo->minimum = min; absinfo->maximum = max; absinfo->fuzz = fuzz; +if (size_mm && min >=0 && max > min) + absinfo->resolution =DIV_ROUND_CLOSEST (max - min +1 , size_mm); }/**
@@ -69,7 +73,7 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch,struct device *dev = input->dev.parent;struct input_absinfo *absinfo;unsigned int axis, axis_x, axis_y; -unsigned int minimum, maximum, fuzz; +unsigned int minimum, maximum, fuzz, size_mm;bool data_present;input_alloc_absinfo (input);
@@ -89,8 +93,10 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch, data_present |=touchscreen_get_prop_u32 (dev,"touchscreen-fuzz-x" ,input_abs_get_fuzz (input, axis_x), &fuzz); + data_present |=touchscreen_get_prop_u32 (dev,"touchscreen-x-mm" ,0 , + &size_mm);if (data_present) -touchscreen_set_params (input, axis_x, minimum, maximum -1 , fuzz); +touchscreen_set_params (input, axis_x, minimum, maximum -1 , fuzz, size_mm); data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-y", input_abs_get_min(input, axis_y),
@@ -102,8 +108,10 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch, data_present |=touchscreen_get_prop_u32 (dev,"touchscreen-fuzz-y" ,input_abs_get_fuzz (input, axis_y), &fuzz); + data_present |=touchscreen_get_prop_u32 (dev,"touchscreen-y-mm" ,0 , + &size_mm);if (data_present) -touchscreen_set_params (input, axis_y, minimum, maximum -1 , fuzz); +touchscreen_set_params (input, axis_y, minimum, maximum -1 , fuzz, size_mm); axis = multitouch ?ABS_MT_PRESSURE :ABS_PRESSURE ; data_present = touchscreen_get_prop_u32(dev,
@@ -115,7 +123,7 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch,input_abs_get_fuzz (input, axis), &fuzz);if (data_present) -touchscreen_set_params (input, axis,0 , maximum, fuzz); +touchscreen_set_params (input, axis,0 , maximum, fuzz,0 );if (!prop)return ;
Signature · 1 line
2.56.0.385.gac671c819a-goog
Dmitry Torokhov
maintainerPATCH 2/4 Input: wacom_w9000 - rely on touchscreen_parse_properties() for resolution
In reply to Dmitry TorokhovThe input core's touchscreen_parse_properties() helper now parses the touchscreen-x-mm and touchscreen-y-mm properties and calculates axis resolution in units per millimeter automatically, including handling axis swapping.
Rely on touchscreen_parse_properties() to configure axis resolutions and remove the manual property parsing and resolution assignment block in wacom_w9000_probe(), along with the now-unused local variable.
--- drivers/input/touchscreen/wacom_w9000.c | 10 ---------- 1 file changed, 10 deletions(-)
drivers/input/touchscreen/wacom_w9000.c +0 -10
@@ -249,7 +249,6 @@ static int wacom_w9000_probe(struct i2c_client *client)struct wacom_w9000_data *wacom_data;struct input_dev *input_dev;int error; -u32 val;if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) {dev_err (dev,"i2c_check_functionality error\n" );
@@ -350,15 +349,6 @@ static int wacom_w9000_probe(struct i2c_client *client)dev_info (dev,"%s size X%uY%u\n" , wacom_data->variant->name, wacom_data->prop.max_x, wacom_data->prop.max_y); - error =device_property_read_u32 (dev,"touchscreen-x-mm" , &val); -if (!error && val) -input_abs_set_res (input_dev, wacom_data->prop.swap_x_y ?ABS_Y :ABS_X , - wacom_data->prop.max_x / val); - error =device_property_read_u32 (dev,"touchscreen-y-mm" , &val); -if (!error && val) -input_abs_set_res (input_dev, wacom_data->prop.swap_x_y ?ABS_X :ABS_Y , - wacom_data->prop.max_y / val); - error =input_register_device (wacom_data->input_dev);if (error)return dev_err_probe (dev, error,"Failed to register input device\n" );
Signature · 1 line
2.56.0.385.gac671c819a-goog
Dmitry Torokhov
maintainerPATCH 3/4 Input: goodix-berlin - set default resolution before parsing properties
In reply to Dmitry Torokhovgoodix_berlin_input_dev_config() currently configures the default 10 units/mm resolution on ABS_MT_POSITION_X and ABS_MT_POSITION_Y after calling touchscreen_parse_properties(). This unconditionally overwrites any axis resolution calculated by touchscreen_parse_properties() from touchscreen-x-mm and touchscreen-y-mm device properties.
Set the default resolution before calling touchscreen_parse_properties() so the default resolution remains in place when physical dimensions are not specified, while allowing touchscreen-x-mm and touchscreen-y-mm to override it when present.
--- drivers/input/touchscreen/goodix_berlin_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/input/touchscreen/goodix_berlin_core.c +2 -2
@@ -626,8 +626,6 @@ static int goodix_berlin_input_dev_config(struct goodix_berlin_core *cd, 0, SZ_64K - 1, 0, 0);input_set_abs_params (cd->input_dev,ABS_MT_TOUCH_MAJOR ,0 ,255 ,0 ,0 ); -touchscreen_parse_properties (cd->input_dev, true, &cd->props); -/* * The resolution of these touchscreens is about 10 units/mm, the actual * resolution does not matter much since we set INPUT_PROP_DIRECT.
@@ -636,6 +634,8 @@ static int goodix_berlin_input_dev_config(struct goodix_berlin_core *cd,input_abs_set_res (cd->input_dev,ABS_MT_POSITION_X ,10 );input_abs_set_res (cd->input_dev,ABS_MT_POSITION_Y ,10 ); +touchscreen_parse_properties (cd->input_dev, true, &cd->props); + error =input_mt_init_slots (cd->input_dev,GOODIX_BERLIN_MAX_TOUCH ,INPUT_MT_DIRECT |INPUT_MT_DROP_UNUSED );if (error)
Signature · 1 line
2.56.0.385.gac671c819a-goog
Re: [PATCH 3/4] Input: goodix-berlin - set default resolution before parsing properties
Quoted 30 lines · Dmitry Torokhov
goodix_berlin_input_dev_config()currently configures the default 10 units/mm resolution onABS_MT_POSITION_XandABS_MT_POSITION_Yafter callingtouchscreen_parse_properties(). This unconditionally overwrites any axis resolution calculated bytouchscreen_parse_properties()from touchscreen-x-mm and touchscreen-y-mm device properties.Set the default resolution before calling
touchscreen_parse_properties()so the default resolution remains in place when physical dimensions are not specified, while allowing touchscreen-x-mm and touchscreen-y-mm to override it when present.Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/touchscreen/goodix_berlin_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/input/touchscreen/goodix_berlin_core.c +0
-2@@ -626,8 +626,6 @@ static int goodix_berlin_input_dev_config(struct goodix_berlin_core *cd, 0, SZ_64K - 1, 0, 0);input_set_abs_params (cd->input_dev,ABS_MT_TOUCH_MAJOR ,0 ,255 ,0 ,0 ); -touchscreen_parse_properties (cd->input_dev, true, &cd->props); -/* * The resolution of these touchscreens is about 10 units/mm, the actual * resolution does not matter much since we set INPUT_PROP_DIRECT.
drivers/input/touchscreen/goodix_berlin_core.c static int goodix_berlin_input_dev_config(struct goodix_berlin_core *cd, · line 641
Quoted 8 lines
drivers/input/touchscreen/goodix_berlin_core.c +2
-0@@ -636,6 +634,8 @@ static int goodix_berlin_input_dev_config(struct goodix_berlin_core *cd,input_abs_set_res (cd->input_dev,ABS_MT_POSITION_X ,10 );input_abs_set_res (cd->input_dev,ABS_MT_POSITION_Y ,10 ); +touchscreen_parse_properties (cd->input_dev, true, &cd->props); + error =input_mt_init_slots (cd->input_dev,GOODIX_BERLIN_MAX_TOUCH ,INPUT_MT_DIRECT |INPUT_MT_DROP_UNUSED );if (error)
Thanks,
Neil
Dmitry Torokhov
maintainerPATCH 4/4 Input: apple_z2 - set default resolution before parsing properties
In reply to Dmitry Torokhovapple_z2_probe() currently sets the default 100 units/mm resolution on ABS_MT_POSITION_X and ABS_MT_POSITION_Y after calling touchscreen_parse_properties(). This unconditionally overwrites any axis resolution calculated by touchscreen_parse_properties() from touchscreen-x-mm and touchscreen-y-mm device properties.
Set the default resolution before calling touchscreen_parse_properties() so the default resolution remains in place when physical dimensions are omitted, while allowing touchscreen-x-mm and touchscreen-y-mm to override it when present.
--- drivers/input/touchscreen/apple_z2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/apple_z2.c +1 -1
@@ -397,9 +397,9 @@ static int apple_z2_probe(struct spi_device *spi)/* Allocate the axes before setting from DT */ input_set_abs_params (z2->input_dev,ABS_MT_POSITION_X ,0 ,0 ,0 ,0 );input_set_abs_params (z2->input_dev,ABS_MT_POSITION_Y ,0 ,0 ,0 ,0 ); -touchscreen_parse_properties (z2->input_dev, true, &z2->props);input_abs_set_res (z2->input_dev,ABS_MT_POSITION_X ,100 );input_abs_set_res (z2->input_dev,ABS_MT_POSITION_Y ,100 ); +touchscreen_parse_properties (z2->input_dev, true, &z2->props);input_set_abs_params (z2->input_dev,ABS_MT_WIDTH_MAJOR ,0 ,65535 ,0 ,0 );input_set_abs_params (z2->input_dev,ABS_MT_WIDTH_MINOR ,0 ,65535 ,0 ,0 );input_set_abs_params (z2->input_dev,ABS_MT_TOUCH_MAJOR ,0 ,65535 ,0 ,0 );
Signature · 1 line
2.56.0.385.gac671c819a-goog