of_touchscreen-helpers: Add support for inverted / swapp
Subsystems (5)
v4 cover of_touchscreen-helpers: Add support for inverted / swapp
Hi Dmitry,
Here is a v4 of my of_touchscreen-helpers patch with the changes discussed before, as well as adding the extra NULL parameter to the touchscreen_parse_properties call in the new(ish) ad7879.c and cyttsp_core.c drivers.
Patches 2-4 have been tested on various ARM tablets with the actual touchscreens affected by the changes.
Regards,
Hans
PATCH v3 1/4 of_touchscreen-helpers: Add support for inverted / swapped axis
Extend touchscreen_parse_properties() with support for the touchscreen-inverted-x/y and touchscreen-swapped-x-y properties and add touchscreen_set_mt_pos() and touchscreen_report_pos() helper functions for storing coordinates into a input_mt_pos struct, or directly reporting them, taking these properties into account.
This commit also modifies the existing callers of touchscreen_parse_properties() to pass in NULL for the new third argument, keeping the existing behavior.
---
Changes in v2:
-No changes
Changes in v3:
-Add touchscreen_set_mt_pos / touchscreen_report_pos helpers replacing
the touchscreen_apply_properties helper
Changes in v4:
-Also add extra NULL parameter to touchscreen_parse_properties() calls
in ad7879.c and cyttsp_core.c
--- drivers/input/touchscreen/ad7879.c | 2 +- drivers/input/touchscreen/cyttsp_core.c | 2 +- drivers/input/touchscreen/edt-ft5x06.c | 2 +- drivers/input/touchscreen/of_touchscreen.c | 91 +++++++++++++++++++++++++++++- drivers/input/touchscreen/pixcir_i2c_ts.c | 2 +- drivers/input/touchscreen/tsc200x-core.c | 2 +- include/linux/input/touchscreen.h | 20 ++++++- 7 files changed, 114 insertions(+), 7 deletions(-)
drivers/input/touchscreen/ad7879.c +1 -1
@@ -595,7 +595,7 @@ struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq, }else {input_set_abs_params (input_dev,ABS_X ,0 ,MAX_12BIT ,0 ,0 );input_set_abs_params (input_dev,ABS_Y ,0 ,MAX_12BIT ,0 ,0 ); -touchscreen_parse_properties (input_dev, false); +touchscreen_parse_properties (input_dev, false,NULL );if (!input_abs_get_max (input_dev,ABS_PRESSURE )) {dev_err (dev,"Touchscreen pressure is not specified\n" );return ERR_PTR (-EINVAL );
drivers/input/touchscreen/cyttsp_core.c +1 -1
@@ -657,7 +657,7 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,input_set_capability (input_dev,EV_ABS ,ABS_MT_POSITION_X );input_set_capability (input_dev,EV_ABS ,ABS_MT_POSITION_Y ); -touchscreen_parse_properties (input_dev, true); +touchscreen_parse_properties (input_dev, true,NULL ); error =input_mt_init_slots (input_dev,CY_MAX_ID ,0 );if (error) {
drivers/input/touchscreen/edt-ft5x06.c +1 -1
@@ -972,7 +972,7 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , tsdata->num_y *64 -1 ,0 ,0 ); -touchscreen_parse_properties (input, true); +touchscreen_parse_properties (input, true,NULL ); error =input_mt_init_slots (input, tsdata->max_support_points,INPUT_MT_DIRECT );
drivers/input/touchscreen/of_touchscreen.c +90 -1
107 lines not on this page · raw message
drivers/input/touchscreen/pixcir_i2c_ts.c +1 -1
@@ -515,7 +515,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, }else {input_set_capability (input,EV_ABS ,ABS_MT_POSITION_X );input_set_capability (input,EV_ABS ,ABS_MT_POSITION_Y ); -touchscreen_parse_properties (input, true); +touchscreen_parse_properties (input, true,NULL );if (!input_abs_get_max (input,ABS_MT_POSITION_X ) || !input_abs_get_max (input,ABS_MT_POSITION_Y )) {dev_err (dev,"Touchscreen size is not specified\n" );
drivers/input/touchscreen/tsc200x-core.c +1 -1
@@ -559,7 +559,7 @@ int tsc200x_probe(struct device *dev, int irq, __u16 bustype,input_set_abs_params (input_dev,ABS_PRESSURE ,0 , max_p, fudge_p,0 );if (np) -touchscreen_parse_properties (input_dev, false); +touchscreen_parse_properties (input_dev, false,NULL ); input_dev->open = tsc200x_open; input_dev->close = tsc200x_close;
include/linux/input/touchscreen.h +19 -1
@@ -11,6 +11,24 @@struct input_dev ; -void touchscreen_parse_properties (struct input_dev *dev,bool multitouch); +struct touchscreen_properties { +unsigned int max_x; +unsigned int max_y; +bool invert_x; +bool invert_y; +bool swap_x_y; +}; + +void touchscreen_parse_properties (struct input_dev *input,bool multitouch, +struct touchscreen_properties *prop); + +void touchscreen_set_mt_pos (struct input_mt_pos *pos, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y); + +void touchscreen_report_pos (struct input_dev *input, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y, +bool multitouch);#endif
Signature · 1 line
2.7.4
Dmitry Torokhov
maintainerRe: [PATCH v3 1/4] of_touchscreen-helpers: Add support for inverted / swapped axis
Quoted 11 lines · Hans de Goede
Extend
touchscreen_parse_properties()with support for the touchscreen-inverted-x/y and touchscreen-swapped-x-y properties and addtouchscreen_set_mt_pos()andtouchscreen_report_pos()helper functions for storing coordinates into ainput_mt_posstruct, or directly reporting them, taking these properties into account.This commit also modifies the existing callers of
touchscreen_parse_properties()to pass in NULL for the new third argument, keeping the existing behavior.Signed-off-by Hans de Goede <[email protected]>
Applied with a couple of minor adjustments (see below), thanks!
Quoted 96 lines
---
Changes in v2:
-No changes
Changes in v3:
-Addtouchscreen_set_mt_pos/touchscreen_report_poshelpers replacing
thetouchscreen_apply_propertieshelper
Changes in v4:(quoted diff) +0
-2-Also add extra NULL parameter to touchscreen_parse_properties() calls in ad7879.c and cyttsp_core.c --- drivers/input/touchscreen/ad7879.c | 2 +- drivers/input/touchscreen/cyttsp_core.c | 2 +- drivers/input/touchscreen/edt-ft5x06.c | 2 +- drivers/input/touchscreen/of_touchscreen.c | 91 +++++++++++++++++++++++++++++- drivers/input/touchscreen/pixcir_i2c_ts.c | 2 +- drivers/input/touchscreen/tsc200x-core.c | 2 +- include/linux/input/touchscreen.h | 20 ++++++- 7 files changed, 114 insertions(+), 7 deletions(-)drivers/input/touchscreen/ad7879.c +1
-1@@ -595,7 +595,7 @@ struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq, }else {input_set_abs_params (input_dev,ABS_X ,0 ,MAX_12BIT ,0 ,0 );input_set_abs_params (input_dev,ABS_Y ,0 ,MAX_12BIT ,0 ,0 ); -touchscreen_parse_properties (input_dev, false); +touchscreen_parse_properties (input_dev, false,NULL );if (!input_abs_get_max (input_dev,ABS_PRESSURE )) {dev_err (dev,"Touchscreen pressure is not specified\n" );return ERR_PTR (-EINVAL );drivers/input/touchscreen/cyttsp_core.c +1
-1@@ -657,7 +657,7 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,input_set_capability (input_dev,EV_ABS ,ABS_MT_POSITION_X );input_set_capability (input_dev,EV_ABS ,ABS_MT_POSITION_Y ); -touchscreen_parse_properties (input_dev, true); +touchscreen_parse_properties (input_dev, true,NULL ); error =input_mt_init_slots (input_dev,CY_MAX_ID ,0 );if (error) {drivers/input/touchscreen/edt-ft5x06.c +1
-1@@ -972,7 +972,7 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , tsdata->num_y *64 -1 ,0 ,0 ); -touchscreen_parse_properties (input, true); +touchscreen_parse_properties (input, true,NULL ); error =input_mt_init_slots (input, tsdata->max_support_points,INPUT_MT_DIRECT );drivers/input/touchscreen/of_touchscreen.c +17
-1@@ -55,12 +55,16 @@ static void touchscreen_set_params(struct input_dev *dev,* @input: input device that should be parsed * @multitouch: specifies whether parsed properties should be applied to * single-touch or multi-touch axes +* @prop: pointer to a struct touchscreen_properties into which to store +* axis swap and invert info for use with touchscreen_report_x_y(); +* or NULL * * This function parses common DT properties for touchscreens and setups the * input device accordingly. The function keeps previously set up default * values if no value is specified via DT. */ -void touchscreen_parse_properties (struct input_dev *input,bool multitouch) +void touchscreen_parse_properties (struct input_dev *input,bool multitouch, +struct touchscreen_properties *prop) {struct device *dev = input->dev.parent;unsigned int axis;@@ -104,5 +108,90 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch) &fuzz);if (data_present)touchscreen_set_params (input, axis, maximum, fuzz); + +if (!prop) +return ; + + axis = multitouch ?ABS_MT_POSITION_X :ABS_X ; + + prop->max_x =input_abs_get_max (input, axis); + prop->max_y =input_abs_get_max (input, axis +1 ); + prop->invert_x = +device_property_read_bool (dev,"touchscreen-inverted-x" ); + prop->invert_y = +device_property_read_bool (dev,"touchscreen-inverted-y" );
drivers/input/touchscreen/of_touchscreen.c void touchscreen_parse_properties(struct input_dev *input, bool multitouch) · line 132
Quoted 10 lines
drivers/input/touchscreen/of_touchscreen.c +10
-0+ prop->swap_x_y = +device_property_read_bool (dev,"touchscreen-swapped-x-y" ); + +if (prop->swap_x_y) { +struct input_absinfo tmp_absinfo; + + tmp_absinfo = input->absinfo[axis]; + input->absinfo[axis] = input->absinfo[axis +1 ]; + input->absinfo[axis +1 ] = tmp_absinfo; + }
We have a nice swap() macro.
Quoted 10 lines
drivers/input/touchscreen/of_touchscreen.c +8
-0}EXPORT_SYMBOL (touchscreen_parse_properties); + +static void touchscreen_apply_prop_to_x_y ( +const struct touchscreen_properties *prop, +unsigned int *x,unsigned int *y) +{ +if (prop->invert_x) + *x = prop->max_x - *x; +
drivers/input/touchscreen/of_touchscreen.c void touchscreen_parse_properties(struct input_dev *input, bool multitouch) · line 152
Quoted 10 lines
drivers/input/touchscreen/of_touchscreen.c +10
-0+if (prop->invert_y) + *y = prop->max_y - *y; + +if (prop->swap_x_y) { +unsigned int tmp; + + tmp = *x; + *x = *y; + *y = tmp; + }
Same here.
Quoted 76 lines
drivers/input/touchscreen/of_touchscreen.c +45
-0+} + +/** +* touchscreen_set_mt_pos - Set input_mt_pos coordinates +* @pos: input_mt_pos to set coordinates of +* @prop: pointer to a struct touchscreen_properties +* @x: X coordinate to store in pos +* @y: Y coordinate to store in pos +* +* Adjust the passed in x and y values applying any axis inversion and +* swapping requested in the passed in touchscreen_properties and store +* the result in a struct input_mt_pos. +*/ +void touchscreen_set_mt_pos (struct input_mt_pos *pos, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y) +{ +touchscreen_apply_prop_to_x_y (prop, &x, &y); + pos->x = x; + pos->y = y; +} +EXPORT_SYMBOL (touchscreen_set_mt_pos); + +/** +* touchscreen_report_pos - Report touchscreen coordinates +* @input: input_device to report coordinates for +* @prop: pointer to a struct touchscreen_properties +* @x: X coordinate to report +* @y: Y coordinate to report +* @multitouch: Report coordinates on single-touch or multi-touch axes +* +* Adjust the passed in x and y values applying any axis inversion and +* swapping requested in the passed in touchscreen_properties and then +* report the resulting coordinates on the input_dev's x and y axis. +*/ +void touchscreen_report_pos (struct input_dev *input, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y, +bool multitouch) +{ +touchscreen_apply_prop_to_x_y (prop, &x, &y); +input_report_abs (input, multitouch ?ABS_MT_POSITION_X :ABS_X , x); +input_report_abs (input, multitouch ?ABS_MT_POSITION_Y :ABS_Y , y); +} +EXPORT_SYMBOL (touchscreen_report_pos);drivers/input/touchscreen/pixcir_i2c_ts.c +1
-1@@ -515,7 +515,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, }else {input_set_capability (input,EV_ABS ,ABS_MT_POSITION_X );input_set_capability (input,EV_ABS ,ABS_MT_POSITION_Y ); -touchscreen_parse_properties (input, true); +touchscreen_parse_properties (input, true,NULL );if (!input_abs_get_max (input,ABS_MT_POSITION_X ) || !input_abs_get_max (input,ABS_MT_POSITION_Y )) {dev_err (dev,"Touchscreen size is not specified\n" );drivers/input/touchscreen/tsc200x-core.c +1
-1@@ -559,7 +559,7 @@ int tsc200x_probe(struct device *dev, int irq, __u16 bustype,input_set_abs_params (input_dev,ABS_PRESSURE ,0 , max_p, fudge_p,0 );if (np) -touchscreen_parse_properties (input_dev, false); +touchscreen_parse_properties (input_dev, false,NULL ); input_dev->open = tsc200x_open; input_dev->close = tsc200x_close;include/linux/input/touchscreen.h +0
-0
include/linux/input/touchscreen.h line 13
Quoted 3 lines
include/linux/input/touchscreen.h +0
-0@@ -11,6 +11,24 @@struct input_dev ;
Added forward declaration for input_mt_pos.
Quoted 25 lines
include/linux/input/touchscreen.h +19
-1-void touchscreen_parse_properties (struct input_dev *dev,bool multitouch); +struct touchscreen_properties { +unsigned int max_x; +unsigned int max_y; +bool invert_x; +bool invert_y; +bool swap_x_y; +}; + +void touchscreen_parse_properties (struct input_dev *input,bool multitouch, +struct touchscreen_properties *prop); + +void touchscreen_set_mt_pos (struct input_mt_pos *pos, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y); + +void touchscreen_report_pos (struct input_dev *input, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y, +bool multitouch);#endif Signature · 1 line
2.7.4
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v3 1/4] of_touchscreen-helpers: Add support for inverted / swapped axis
Hi,
Quoted 7 lines · Dmitry Torokhov
Quoted 6 lines · Hans de Goede
Extend
touchscreen_parse_properties()with support for the touchscreen-inverted-x/y and touchscreen-swapped-x-y properties and addtouchscreen_set_mt_pos()andtouchscreen_report_pos()helper functions for storing coordinates into ainput_mt_posstruct, or directly reporting them, taking these properties into account.
Quoted 7 lines
Quoted 5 lines
This commit also modifies the existing callers of
touchscreen_parse_properties()to pass in NULL for the new third argument, keeping the existing behavior.Signed-off-by Hans de Goede <[email protected]>Applied with a couple of minor adjustments (see below), thanks!
I was just about to ask if you took v4 and not v3, but from the Changes list below I see you did and I accidentally send v4 with v3 in the subject. Thank you for merging this.
Regards,
Hans
Quoted 243 lines
Quoted 97 lines
---
Changes in v2:
-No changes
Changes in v3:
-Addtouchscreen_set_mt_pos/touchscreen_report_poshelpers replacing
thetouchscreen_apply_propertieshelper
Changes in v4:(quoted diff) +0
-2-Also add extra NULL parameter to touchscreen_parse_properties() calls in ad7879.c and cyttsp_core.c --- drivers/input/touchscreen/ad7879.c | 2 +- drivers/input/touchscreen/cyttsp_core.c | 2 +- drivers/input/touchscreen/edt-ft5x06.c | 2 +- drivers/input/touchscreen/of_touchscreen.c | 91 +++++++++++++++++++++++++++++- drivers/input/touchscreen/pixcir_i2c_ts.c | 2 +- drivers/input/touchscreen/tsc200x-core.c | 2 +- include/linux/input/touchscreen.h | 20 ++++++- 7 files changed, 114 insertions(+), 7 deletions(-)drivers/input/touchscreen/ad7879.c +1
-1@@ -595,7 +595,7 @@ struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq, }else {input_set_abs_params (input_dev,ABS_X ,0 ,MAX_12BIT ,0 ,0 );input_set_abs_params (input_dev,ABS_Y ,0 ,MAX_12BIT ,0 ,0 ); -touchscreen_parse_properties (input_dev, false); +touchscreen_parse_properties (input_dev, false,NULL );if (!input_abs_get_max (input_dev,ABS_PRESSURE )) {dev_err (dev,"Touchscreen pressure is not specified\n" );return ERR_PTR (-EINVAL );drivers/input/touchscreen/cyttsp_core.c +1
-1@@ -657,7 +657,7 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,input_set_capability (input_dev,EV_ABS ,ABS_MT_POSITION_X );input_set_capability (input_dev,EV_ABS ,ABS_MT_POSITION_Y ); -touchscreen_parse_properties (input_dev, true); +touchscreen_parse_properties (input_dev, true,NULL ); error =input_mt_init_slots (input_dev,CY_MAX_ID ,0 );if (error) {drivers/input/touchscreen/edt-ft5x06.c +1
-1@@ -972,7 +972,7 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , tsdata->num_y *64 -1 ,0 ,0 ); -touchscreen_parse_properties (input, true); +touchscreen_parse_properties (input, true,NULL ); error =input_mt_init_slots (input, tsdata->max_support_points,INPUT_MT_DIRECT );drivers/input/touchscreen/of_touchscreen.c +17
-1@@ -55,12 +55,16 @@ static void touchscreen_set_params(struct input_dev *dev,* @input: input device that should be parsed * @multitouch: specifies whether parsed properties should be applied to * single-touch or multi-touch axes +* @prop: pointer to a struct touchscreen_properties into which to store +* axis swap and invert info for use with touchscreen_report_x_y(); +* or NULL * * This function parses common DT properties for touchscreens and setups the * input device accordingly. The function keeps previously set up default * values if no value is specified via DT. */ -void touchscreen_parse_properties (struct input_dev *input,bool multitouch) +void touchscreen_parse_properties (struct input_dev *input,bool multitouch, +struct touchscreen_properties *prop) {struct device *dev = input->dev.parent;unsigned int axis;@@ -104,5 +108,90 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch) &fuzz);if (data_present)touchscreen_set_params (input, axis, maximum, fuzz); + +if (!prop) +return ; + + axis = multitouch ?ABS_MT_POSITION_X :ABS_X ; + + prop->max_x =input_abs_get_max (input, axis); + prop->max_y =input_abs_get_max (input, axis +1 ); + prop->invert_x = +device_property_read_bool (dev,"touchscreen-inverted-x" ); + prop->invert_y = +device_property_read_bool (dev,"touchscreen-inverted-y" );drivers/input/touchscreen/of_touchscreen.c void touchscreen_parse_properties(struct input_dev *input, bool multitouch) · line 132
Quoted 10 lines
drivers/input/touchscreen/of_touchscreen.c +10
-0+ prop->swap_x_y = +device_property_read_bool (dev,"touchscreen-swapped-x-y" ); + +if (prop->swap_x_y) { +struct input_absinfo tmp_absinfo; + + tmp_absinfo = input->absinfo[axis]; + input->absinfo[axis] = input->absinfo[axis +1 ]; + input->absinfo[axis +1 ] = tmp_absinfo; + }We have a nice
swap()macro.Quoted 10 lines
drivers/input/touchscreen/of_touchscreen.c +8
-0}EXPORT_SYMBOL (touchscreen_parse_properties); + +static void touchscreen_apply_prop_to_x_y ( +const struct touchscreen_properties *prop, +unsigned int *x,unsigned int *y) +{ +if (prop->invert_x) + *x = prop->max_x - *x; +drivers/input/touchscreen/of_touchscreen.c void touchscreen_parse_properties(struct input_dev *input, bool multitouch) · line 152
Quoted 10 lines
drivers/input/touchscreen/of_touchscreen.c +10
-0+if (prop->invert_y) + *y = prop->max_y - *y; + +if (prop->swap_x_y) { +unsigned int tmp; + + tmp = *x; + *x = *y; + *y = tmp; + }Same here.
Quoted 76 lines
drivers/input/touchscreen/of_touchscreen.c +45
-0+} + +/** +* touchscreen_set_mt_pos - Set input_mt_pos coordinates +* @pos: input_mt_pos to set coordinates of +* @prop: pointer to a struct touchscreen_properties +* @x: X coordinate to store in pos +* @y: Y coordinate to store in pos +* +* Adjust the passed in x and y values applying any axis inversion and +* swapping requested in the passed in touchscreen_properties and store +* the result in a struct input_mt_pos. +*/ +void touchscreen_set_mt_pos (struct input_mt_pos *pos, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y) +{ +touchscreen_apply_prop_to_x_y (prop, &x, &y); + pos->x = x; + pos->y = y; +} +EXPORT_SYMBOL (touchscreen_set_mt_pos); + +/** +* touchscreen_report_pos - Report touchscreen coordinates +* @input: input_device to report coordinates for +* @prop: pointer to a struct touchscreen_properties +* @x: X coordinate to report +* @y: Y coordinate to report +* @multitouch: Report coordinates on single-touch or multi-touch axes +* +* Adjust the passed in x and y values applying any axis inversion and +* swapping requested in the passed in touchscreen_properties and then +* report the resulting coordinates on the input_dev's x and y axis. +*/ +void touchscreen_report_pos (struct input_dev *input, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y, +bool multitouch) +{ +touchscreen_apply_prop_to_x_y (prop, &x, &y); +input_report_abs (input, multitouch ?ABS_MT_POSITION_X :ABS_X , x); +input_report_abs (input, multitouch ?ABS_MT_POSITION_Y :ABS_Y , y); +} +EXPORT_SYMBOL (touchscreen_report_pos);drivers/input/touchscreen/pixcir_i2c_ts.c +1
-1@@ -515,7 +515,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, }else {input_set_capability (input,EV_ABS ,ABS_MT_POSITION_X );input_set_capability (input,EV_ABS ,ABS_MT_POSITION_Y ); -touchscreen_parse_properties (input, true); +touchscreen_parse_properties (input, true,NULL );if (!input_abs_get_max (input,ABS_MT_POSITION_X ) || !input_abs_get_max (input,ABS_MT_POSITION_Y )) {dev_err (dev,"Touchscreen size is not specified\n" );drivers/input/touchscreen/tsc200x-core.c +1
-1@@ -559,7 +559,7 @@ int tsc200x_probe(struct device *dev, int irq, __u16 bustype,input_set_abs_params (input_dev,ABS_PRESSURE ,0 , max_p, fudge_p,0 );if (np) -touchscreen_parse_properties (input_dev, false); +touchscreen_parse_properties (input_dev, false,NULL ); input_dev->open = tsc200x_open; input_dev->close = tsc200x_close;include/linux/input/touchscreen.h +0
-0include/linux/input/touchscreen.h line 13
Quoted 3 lines
include/linux/input/touchscreen.h +0
-0@@ -11,6 +11,24 @@struct input_dev ;Added forward declaration for
input_mt_pos.Quoted 23 lines
include/linux/input/touchscreen.h +19
-2-void touchscreen_parse_properties (struct input_dev *dev,bool multitouch); +struct touchscreen_properties { +unsigned int max_x; +unsigned int max_y; +bool invert_x; +bool invert_y; +bool swap_x_y; +}; + +void touchscreen_parse_properties (struct input_dev *input,bool multitouch, +struct touchscreen_properties *prop); + +void touchscreen_set_mt_pos (struct input_mt_pos *pos, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y); + +void touchscreen_report_pos (struct input_dev *input, +const struct touchscreen_properties *prop, +unsigned int x,unsigned int y, +bool multitouch);#endif --Quoted 2 lines
2.7.4
Thanks.
PATCH v3 2/4 touchscreen: ft5x06: Add support for axis inversion / swapping
In reply to Hans de GoedeAdd support for axis inversion / swapping using the new touchscreen_parse_properties and touchscreen_apply_prop_to_x_y functionality.
---
Changes in v2:
-No changes
Changes in v3:
-Use new touchscreen_report_pos helper
--- drivers/input/touchscreen/edt-ft5x06.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/input/touchscreen/edt-ft5x06.c +4 -3
@@ -86,6 +86,7 @@ struct edt_reg_addr {struct edt_ft5x06_ts_data {struct i2c_client *client;struct input_dev *input; +struct touchscreen_properties prop;u16 num_x;u16 num_y;
@@ -246,8 +247,8 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)if (!down)continue ; -input_report_abs (tsdata->input,ABS_MT_POSITION_X , x); -input_report_abs (tsdata->input,ABS_MT_POSITION_Y , y); +touchscreen_report_pos (tsdata->input, &tsdata->prop, x, y, + true); }input_mt_report_pointer_emulation (tsdata->input, true);
@@ -972,7 +973,7 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , tsdata->num_y *64 -1 ,0 ,0 ); -touchscreen_parse_properties (input, true,NULL ); +touchscreen_parse_properties (input, true, &tsdata->prop); error =input_mt_init_slots (input, tsdata->max_support_points,INPUT_MT_DIRECT );
Signature · 1 line
2.7.4
PATCH v3 3/4 touchscreen: icn8318: Use parse_properties and apply_prop_to_x_y helpers
In reply to Hans de GoedeUse the touchscreen_parse_properties and touchscreen_apply_prop_to_x_y functions, instead of DIY code, this results in a nice cleanup.
---
Changes in v2:
-Call input_set_capability() before calling touchscreen_parse_properties() Changes in v3:
-Use new touchscreen_report_pos helper
--- drivers/input/touchscreen/chipone_icn8318.c | 60 +++++++---------------------- 1 file changed, 13 insertions(+), 47 deletions(-)
drivers/input/touchscreen/chipone_icn8318.c +13 -47
@@ -17,6 +17,7 @@#include <linux/i2c.h> #include <linux/input.h> #include <linux/input/mt.h> +#include <linux/input/touchscreen.h> #include <linux/module.h> #include <linux/of.h>
@@ -52,11 +53,7 @@ struct icn8318_data {struct i2c_client *client;struct input_dev *input;struct gpio_desc *wake_gpio; -u32 max_x; -u32 max_y; -bool invert_x; -bool invert_y; -bool swap_x_y; +struct touchscreen_properties prop; }; static int icn8318_read_touch_data(struct i2c_client *client,
@@ -91,7 +88,7 @@ static irqreturn_t icn8318_irq(int irq, void *dev_id)struct icn8318_data *data = dev_id;struct device *dev = &data->client->dev;struct icn8318_touch_data touch_data; -int i, ret, x, y; +int i, ret; ret =icn8318_read_touch_data (data->client, &touch_data);if (ret <0 ) {
@@ -124,22 +121,9 @@ static irqreturn_t icn8318_irq(int irq, void *dev_id)if (!act)continue ; - x =be16_to_cpu (touch->x); - y =be16_to_cpu (touch->y); - -if (data->invert_x) - x = data->max_x - x; - -if (data->invert_y) - y = data->max_y - y; - -if (!data->swap_x_y) { -input_event (data->input,EV_ABS ,ABS_MT_POSITION_X , x); -input_event (data->input,EV_ABS ,ABS_MT_POSITION_Y , y); - }else { -input_event (data->input,EV_ABS ,ABS_MT_POSITION_X , y); -input_event (data->input,EV_ABS ,ABS_MT_POSITION_Y , x); - } +touchscreen_report_pos (data->input, &data->prop, +be16_to_cpu (touch->x), +be16_to_cpu (touch->y), true); }input_mt_sync_frame (data->input);
@@ -200,10 +184,8 @@ static int icn8318_probe(struct i2c_client *client, const struct i2c_device_id *id) {struct device *dev = &client->dev; -struct device_node *np = dev->of_node;struct icn8318_data *data;struct input_dev *input; -u32 fuzz_x =0 , fuzz_y =0 ;int error;if (!client->irq) {
@@ -223,19 +205,6 @@ static int icn8318_probe(struct i2c_client *client,return error; } -if (of_property_read_u32 (np,"touchscreen-size-x" , &data->max_x) || -of_property_read_u32 (np,"touchscreen-size-y" , &data->max_y)) { -dev_err (dev,"Error touchscreen-size-x and/or -y missing\n" ); -return -EINVAL ; - } - -/* Optional */ -of_property_read_u32 (np,"touchscreen-fuzz-x" , &fuzz_x); -of_property_read_u32 (np,"touchscreen-fuzz-y" , &fuzz_y); - data->invert_x =of_property_read_bool (np,"touchscreen-inverted-x" ); - data->invert_y =of_property_read_bool (np,"touchscreen-inverted-y" ); - data->swap_x_y =of_property_read_bool (np,"touchscreen-swapped-x-y" ); - input =devm_input_allocate_device (dev);if (!input)return -ENOMEM ;
@@ -246,16 +215,13 @@ static int icn8318_probe(struct i2c_client *client, input->close = icn8318_stop; input->dev.parent = dev; -if (!data->swap_x_y) { -input_set_abs_params (input,ABS_MT_POSITION_X ,0 , - data->max_x, fuzz_x,0 ); -input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , - data->max_y, fuzz_y,0 ); - }else { -input_set_abs_params (input,ABS_MT_POSITION_X ,0 , - data->max_y, fuzz_y,0 ); -input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , - data->max_x, fuzz_x,0 ); +input_set_capability (input,EV_ABS ,ABS_MT_POSITION_X ); +input_set_capability (input,EV_ABS ,ABS_MT_POSITION_Y ); +touchscreen_parse_properties (input, true, &data->prop); +if (!input_abs_get_max (input,ABS_MT_POSITION_X ) || + !input_abs_get_max (input,ABS_MT_POSITION_Y )) { +dev_err (dev,"Error touchscreen-size-x and/or -y missing\n" ); +return -EINVAL ; } error = input_mt_init_slots(input, ICN8318_MAX_TOUCHES,
Signature · 1 line
2.7.4
PATCH v3 4/4 touchscreen: pixcir_ts: Add support for axis inversion / swapping
In reply to Hans de GoedeAdd support for axis inversion / swapping using the new touchscreen_parse_properties and touchscreen_apply_prop_to_x_y functionality.
---
Changes in v2:
-Add a fix which actually makes this patch compile, which accidentally ended
up in a later commit in my tree
Changes in v3:
-Use new touchscreen_set_mt_pos helper
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 48 ++++++++++++------------------- 1 file changed, 18 insertions(+), 30 deletions(-)
drivers/input/touchscreen/pixcir_i2c_ts.c +18 -30
@@ -41,19 +41,15 @@ struct pixcir_i2c_ts_data {struct gpio_desc *gpio_enable;struct gpio_desc *gpio_wake;const struct pixcir_i2c_chip_data *chip; +struct touchscreen_properties prop;int max_fingers;/* Max fingers supported in this instance */ bool running; }; -struct pixcir_touch { -int x; -int y; -int id; -}; -struct pixcir_report_data {int num_touches; -struct pixcir_touch touches[PIXCIR_MAX_SLOTS ]; +struct input_mt_pos pos[PIXCIR_MAX_SLOTS ]; +int ids[PIXCIR_MAX_SLOTS ]; }; static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,
@@ -98,11 +94,11 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata, bufptr = &rdbuf[2 ];for (i =0 ; i < touch; i++) { - report->touches[i].x = (bufptr[1 ] <<8 ) | bufptr[0 ]; - report->touches[i].y = (bufptr[3 ] <<8 ) | bufptr[2 ]; - +touchscreen_set_mt_pos (&report->pos[i], &tsdata->prop, + (bufptr[1 ] <<8 ) | bufptr[0 ], + (bufptr[3 ] <<8 ) | bufptr[2 ]);if (chip->has_hw_ids) { - report->touches[i].id = bufptr[4 ]; + report->ids[i] = bufptr[4 ]; bufptr = bufptr +5 ; }else { bufptr = bufptr +4 ;
@@ -113,9 +109,7 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,static void pixcir_ts_report (struct pixcir_i2c_ts_data *ts,struct pixcir_report_data *report) { -struct input_mt_pos pos[PIXCIR_MAX_SLOTS ];int slots[PIXCIR_MAX_SLOTS ]; -struct pixcir_touch *touch;int n, i, slot;struct device *dev = &ts->client->dev;const struct pixcir_i2c_chip_data *chip = ts->chip;
@@ -124,24 +118,16 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,if (n >PIXCIR_MAX_SLOTS ) n =PIXCIR_MAX_SLOTS ; -if (!ts->chip->has_hw_ids) { -for (i =0 ; i < n; i++) { - touch = &report->touches[i]; - pos[i].x = touch->x; - pos[i].y = touch->y; - } - -input_mt_assign_slots (ts->input, slots, pos, n,0 ); - } +if (!ts->chip->has_hw_ids) +input_mt_assign_slots (ts->input, slots, report->pos, n,0 );for (i =0 ; i < n; i++) { - touch = &report->touches[i]; -if (chip->has_hw_ids) { - slot =input_mt_get_slot_by_key (ts->input, touch->id); + slot =input_mt_get_slot_by_key (ts->input, + report->ids[i]);if (slot <0 ) {dev_dbg (dev,"no free slot for id 0x%x\n" , - touch->id); + report->ids[i]);continue ; } }else {
@@ -152,11 +138,13 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,input_mt_report_slot_state (ts->input,MT_TOOL_FINGER , true); -input_event (ts->input,EV_ABS ,ABS_MT_POSITION_X , touch->x); -input_event (ts->input,EV_ABS ,ABS_MT_POSITION_Y , touch->y); +input_event (ts->input,EV_ABS ,ABS_MT_POSITION_X , + report->pos[i].x); +input_event (ts->input,EV_ABS ,ABS_MT_POSITION_Y , + report->pos[i].y);dev_dbg (dev,"%d: slot %d, x %d, y %d\n" , - i, slot, touch->x, touch->y); + i, slot, report->pos[i].x, report->pos[i].y); }input_mt_sync_frame (ts->input);
@@ -515,7 +503,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, }else {input_set_capability (input,EV_ABS ,ABS_MT_POSITION_X );input_set_capability (input,EV_ABS ,ABS_MT_POSITION_Y ); -touchscreen_parse_properties (input, true,NULL ); +touchscreen_parse_properties (input, true, &tsdata->prop);if (!input_abs_get_max (input,ABS_MT_POSITION_X ) || !input_abs_get_max (input,ABS_MT_POSITION_Y )) {dev_err (dev,"Touchscreen size is not specified\n" );
Signature · 1 line
2.7.4
Re: [PATCH v3 4/4] touchscreen: pixcir_ts: Add support for axis inversion / swapping
Quoted 43 lines · Hans de Goede
Add support for axis inversion / swapping using the new
touchscreen_parse_propertiesandtouchscreen_apply_prop_to_x_yfunctionality.Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
-Add a fix which actually makes this patch compile, which accidentally ended
up in a later commit in my tree
Changes in v3:(quoted diff) +0
-2-Use new touchscreen_set_mt_pos helper --- drivers/input/touchscreen/pixcir_i2c_ts.c | 48 ++++++++++++------------------- 1 file changed, 18 insertions(+), 30 deletions(-)drivers/input/touchscreen/pixcir_i2c_ts.c +3
-7@@ -41,19 +41,15 @@ struct pixcir_i2c_ts_data {struct gpio_desc *gpio_enable;struct gpio_desc *gpio_wake;const struct pixcir_i2c_chip_data *chip; +struct touchscreen_properties prop;int max_fingers;/* Max fingers supported in this instance */ bool running; }; -struct pixcir_touch { -int x; -int y; -int id; -}; -struct pixcir_report_data {int num_touches; -struct pixcir_touch touches[PIXCIR_MAX_SLOTS ]; +struct input_mt_pos pos[PIXCIR_MAX_SLOTS ]; +int ids[PIXCIR_MAX_SLOTS ]; }; static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,
drivers/input/touchscreen/pixcir_i2c_ts.c static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata, · line 99
Quoted 9 lines
drivers/input/touchscreen/pixcir_i2c_ts.c +3
-3@@ -98,11 +94,11 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata, bufptr = &rdbuf[2 ];for (i =0 ; i < touch; i++) { - report->touches[i].x = (bufptr[1 ] <<8 ) | bufptr[0 ]; - report->touches[i].y = (bufptr[3 ] <<8 ) | bufptr[2 ]; - +touchscreen_set_mt_pos (&report->pos[i], &tsdata->prop, + (bufptr[1 ] <<8 ) | bufptr[0 ], + (bufptr[3 ] <<8 ) | bufptr[2 ]);
I replaced this with calls to get_unaligned_le16() while we are at it.
Quoted 47 lines
drivers/input/touchscreen/pixcir_i2c_ts.c +6
-16if (chip->has_hw_ids) { - report->touches[i].id = bufptr[4 ]; + report->ids[i] = bufptr[4 ]; bufptr = bufptr +5 ; }else { bufptr = bufptr +4 ;@@ -113,9 +109,7 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,static void pixcir_ts_report (struct pixcir_i2c_ts_data *ts,struct pixcir_report_data *report) { -struct input_mt_pos pos[PIXCIR_MAX_SLOTS ];int slots[PIXCIR_MAX_SLOTS ]; -struct pixcir_touch *touch;int n, i, slot;struct device *dev = &ts->client->dev;const struct pixcir_i2c_chip_data *chip = ts->chip;@@ -124,24 +118,16 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,if (n >PIXCIR_MAX_SLOTS ) n =PIXCIR_MAX_SLOTS ; -if (!ts->chip->has_hw_ids) { -for (i =0 ; i < n; i++) { - touch = &report->touches[i]; - pos[i].x = touch->x; - pos[i].y = touch->y; - } - -input_mt_assign_slots (ts->input, slots, pos, n,0 ); - } +if (!ts->chip->has_hw_ids) +input_mt_assign_slots (ts->input, slots, report->pos, n,0 );for (i =0 ; i < n; i++) { - touch = &report->touches[i]; -if (chip->has_hw_ids) { - slot =input_mt_get_slot_by_key (ts->input, touch->id); + slot =input_mt_get_slot_by_key (ts->input, + report->ids[i]);if (slot <0 ) {dev_dbg (dev,"no free slot for id 0x%x\n" , - touch->id); + report->ids[i]);continue ; } }else {
drivers/input/touchscreen/pixcir_i2c_ts.c static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts, · line 144
Quoted 9 lines
drivers/input/touchscreen/pixcir_i2c_ts.c +4
-2@@ -152,11 +138,13 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,input_mt_report_slot_state (ts->input,MT_TOOL_FINGER , true); -input_event (ts->input,EV_ABS ,ABS_MT_POSITION_X , touch->x); -input_event (ts->input,EV_ABS ,ABS_MT_POSITION_Y , touch->y); +input_event (ts->input,EV_ABS ,ABS_MT_POSITION_X , + report->pos[i].x); +input_event (ts->input,EV_ABS ,ABS_MT_POSITION_Y , + report->pos[i].y);
and this with input_report_abs().
Quoted 19 lines
drivers/input/touchscreen/pixcir_i2c_ts.c +2
-2dev_dbg (dev,"%d: slot %d, x %d, y %d\n" , - i, slot, touch->x, touch->y); + i, slot, report->pos[i].x, report->pos[i].y); }input_mt_sync_frame (ts->input);@@ -515,7 +503,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, }else {input_set_capability (input,EV_ABS ,ABS_MT_POSITION_X );input_set_capability (input,EV_ABS ,ABS_MT_POSITION_Y ); -touchscreen_parse_properties (input, true,NULL ); +touchscreen_parse_properties (input, true, &tsdata->prop);if (!input_abs_get_max (input,ABS_MT_POSITION_X ) || !input_abs_get_max (input,ABS_MT_POSITION_Y )) {dev_err (dev,"Touchscreen size is not specified\n" );Signature · 1 line
2.7.4
Applied, thank you.
Signature · 1 line
Dmitry