Input: edt-ft5x06 - use get_unaligned_be16()
Subsystems (2)
Dmitry Torokhov
maintainerPATCH 1/2 Input: edt-ft5x06 - use get_unaligned_be16()
Instead of doing conversion by hand, let's use the proper accessors.
--- drivers/input/touchscreen/edt-ft5x06.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/touchscreen/edt-ft5x06.c +3 -2
@@ -27,6 +27,7 @@#include <linux/gpio/consumer.h> #include <linux/input/mt.h> #include <linux/input/touchscreen.h> +#include <asm/unaligned.h> #define WORK_REGISTER_THRESHOLD 0x00#define WORK_REGISTER_REPORT_RATE 0x08
@@ -239,8 +240,8 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)if (tsdata->version ==EDT_M06 && type ==TOUCH_EVENT_DOWN )continue ; - x = ((buf[0 ] <<8 ) | buf[1 ]) &0x0fff ; - y = ((buf[2 ] <<8 ) | buf[3 ]) &0x0fff ; + x =get_unaligned_be16 (buf) &0x0fff ; + y =get_unaligned_be16 (buf +2 ) &0x0fff ;/* The FT5x26 send the y coordinate first */ if (tsdata->version ==EV_FT )swap (x, y);
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Dmitry Torokhov
maintainerPATCH 2/2 Input: edt-ft5x06 - simplify event reporting code
Now that input_mt_report_slot_state() returns true if slot is active we no longer need a temporary for the slot state.
--- drivers/input/touchscreen/edt-ft5x06.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/input/touchscreen/edt-ft5x06.c +4 -9
@@ -229,7 +229,6 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)for (i =0 ; i < tsdata->max_support_points; i++) {u8 *buf = &rdbuf[i * tplen + offset]; -bool down; type = buf[0 ] >>6 ;/* ignore Reserved events */
@@ -247,16 +246,12 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)swap (x, y); id = (buf[2 ] >>4 ) &0x0f ; - down = type !=TOUCH_EVENT_UP ;input_mt_slot (tsdata->input, id); -input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , down); - -if (!down) -continue ; - -touchscreen_report_pos (tsdata->input, &tsdata->prop, x, y, - true); +if (input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , + type !=TOUCH_EVENT_UP )) +touchscreen_report_pos (tsdata->input, &tsdata->prop, + x, y, true); }input_mt_report_pointer_emulation (tsdata->input, true);
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Re: [PATCH 2/2] Input: edt-ft5x06 - simplify event reporting code
drivers/input/touchscreen/edt-ft5x06.c static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
Quoted 12 lines · Dmitry Torokhov
Now that
input_mt_report_slot_state()returns true if slot is active we no longer need a temporary for the slot state.drivers/input/touchscreen/edt-ft5x06.c +2
-2- down = type !=TOUCH_EVENT_UP ;input_mt_slot (tsdata->input, id); -input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , down); +if (input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , + type !=TOUCH_EVENT_UP ))
Can't we simple do somethink like
- down = type != TOUCH_EVENT_UP;
+ down = input_mt_report_slot_state(tsdata->input,MT_TOOL_FINGER, type != TOUCH_EVENT_UP);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Dmitry Torokhov
maintainerRe: [PATCH 2/2] Input: edt-ft5x06 - simplify event reporting code
Quoted 18 lines · Andy Shevchenko
drivers/input/touchscreen/edt-ft5x06.c static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
Quoted 12 lines · Dmitry Torokhov
Now that
input_mt_report_slot_state()returns true if slot is active we no longer need a temporary for the slot state.drivers/input/touchscreen/edt-ft5x06.c +2
-2- down = type !=TOUCH_EVENT_UP ;input_mt_slot (tsdata->input, id); -input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , down); +if (input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , + type !=TOUCH_EVENT_UP ))Can't we simple do somethink like
(quoted diff) +1
-1- down = type != TOUCH_EVENT_UP; + down = input_mt_report_slot_state(tsdata->input,
Quoted 1 line
MT_TOOL_FINGER, type !=TOUCH_EVENT_UP);
Why though? The temporary was needed so we did not have to repeat the expression for "contact down" condition, and now we do not need it. The whole change was done so that we cab remove the temporary...
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH 2/2] Input: edt-ft5x06 - simplify event reporting code
Quoted 16 lines · Dmitry Torokhov
Quoted 14 lines · Andy Shevchenko
Quoted 11 lines · Dmitry Torokhov
Now that
input_mt_report_slot_state()returns true if slot is active we no longer need a temporary for the slot state.drivers/input/touchscreen/edt-ft5x06.c +2
-2- down = type !=TOUCH_EVENT_UP ;input_mt_slot (tsdata->input, id); -input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , down); +if (input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , + type !=TOUCH_EVENT_UP ))
Quoted 8 lines
Quoted 4 lines
Can't we simple do somethink like
(quoted diff) +1
-1- down = type != TOUCH_EVENT_UP; + down = input_mt_report_slot_state(tsdata->input,
MT_TOOL_FINGER, type !=TOUCH_EVENT_UP);Why though? The temporary was needed so we did not have to repeat the expression for "contact down" condition, and now we do not need it. The whole change was done so that we cab remove the temporary...
I see. Thanks for explanation.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/2] Input: edt-ft5x06 - simplify event reporting code
In reply to Dmitry TorokhovDmitry Torokhov <[email protected]> wrote on Sat [2019-Jun-22 23:31:53 -0700]:
Quoted 4 lines
Now that
input_mt_report_slot_state()returns true if slot is active we no longer need a temporary for the slot state.Signed-off-by Dmitry Torokhov <[email protected]>
Appears to work fine in my test:
Quoted 40 lines
--- drivers/input/touchscreen/edt-ft5x06.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/input/touchscreen/edt-ft5x06.c +4
-9@@ -229,7 +229,6 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)for (i =0 ; i < tsdata->max_support_points; i++) {u8 *buf = &rdbuf[i * tplen + offset]; -bool down; type = buf[0 ] >>6 ;/* ignore Reserved events */ @@ -247,16 +246,12 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)swap (x, y); id = (buf[2 ] >>4 ) &0x0f ; - down = type !=TOUCH_EVENT_UP ;input_mt_slot (tsdata->input, id); -input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , down); - -if (!down) -continue ; - -touchscreen_report_pos (tsdata->input, &tsdata->prop, x, y, - true); +if (input_mt_report_slot_state (tsdata->input,MT_TOOL_FINGER , + type !=TOUCH_EVENT_UP )) +touchscreen_report_pos (tsdata->input, &tsdata->prop, + x, y, true); }input_mt_report_pointer_emulation (tsdata->input, true);Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Quoted 3 lines · Dmitry Torokhov
Instead of doing conversion by hand, let's use the proper accessors.
The code looks fine to me,
I can test it later next week (Wednesday or so).
Quoted 31 lines
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/touchscreen/edt-ft5x06.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/input/touchscreen/edt-ft5x06.c +3
-3@@ -27,6 +27,7 @@#include <linux/gpio/consumer.h> #include <linux/input/mt.h> #include <linux/input/touchscreen.h> +#include <asm/unaligned.h> #define WORK_REGISTER_THRESHOLD 0x00#define WORK_REGISTER_REPORT_RATE 0x08@@ -239,8 +240,8 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)if (tsdata->version ==EDT_M06 && type ==TOUCH_EVENT_DOWN )continue ; - x = ((buf[0 ] <<8 ) | buf[1 ]) &0x0fff ; - y = ((buf[2 ] <<8 ) | buf[3 ]) &0x0fff ; + x =get_unaligned_be16 (buf) &0x0fff ; + y =get_unaligned_be16 (buf +2 ) &0x0fff ;/* The FT5x26 send the y coordinate first */ if (tsdata->version ==EV_FT )swap (x, y); --2.22.0.410.gd8fdbe21b5-goog
Signature · 2 lines
With Best Regards, Andy Shevchenko
From: Dmitry Torokhov
Quoted 22 lines
Sent: 23 June 2019 07:32
Instead of doing conversion by hand, let's use the proper accessors.
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/touchscreen/edt-ft5x06.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/input/touchscreen/edt-ft5x06.c +1
-0@@ -27,6 +27,7 @@#include <linux/gpio/consumer.h> #include <linux/input/mt.h> #include <linux/input/touchscreen.h> +#include <asm/unaligned.h> #define WORK_REGISTER_THRESHOLD 0x00#define WORK_REGISTER_REPORT_RATE 0x08
drivers/input/touchscreen/edt-ft5x06.c static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id) · line 244
Quoted 7 lines
drivers/input/touchscreen/edt-ft5x06.c +2
-2@@ -239,8 +240,8 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)if (tsdata->version ==EDT_M06 && type ==TOUCH_EVENT_DOWN )continue ; - x = ((buf[0 ] <<8 ) | buf[1 ]) &0x0fff ; - y = ((buf[2 ] <<8 ) | buf[3 ]) &0x0fff ; + x =get_unaligned_be16 (buf) &0x0fff ; + y =get_unaligned_be16 (buf +2 ) &0x0fff ;
You might as well delete the pointless masking with 0xff.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 27 lines · David Laight
From: Dmitry Torokhov
Quoted 25 lines
Sent: 23 June 2019 07:32
Instead of doing conversion by hand, let's use the proper accessors.
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/touchscreen/edt-ft5x06.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/input/touchscreen/edt-ft5x06.c +1
-0@@ -27,6 +27,7 @@#include <linux/gpio/consumer.h> #include <linux/input/mt.h> #include <linux/input/touchscreen.h> +#include <asm/unaligned.h> #define WORK_REGISTER_THRESHOLD 0x00#define WORK_REGISTER_REPORT_RATE 0x08@@ -239,8 +240,8 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)if (tsdata->version ==EDT_M06 && type ==TOUCH_EVENT_DOWN )continue ;
Quoted 6 lines
drivers/input/touchscreen/edt-ft5x06.c static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id) · line 244
Quoted 4 lines
drivers/input/touchscreen/edt-ft5x06.c +2
-2- x = ((buf[0 ] <<8 ) | buf[1 ]) &0x0fff ; - y = ((buf[2 ] <<8 ) | buf[3 ]) &0x0fff ; + x =get_unaligned_be16 (buf) &0x0fff ; + y =get_unaligned_be16 (buf +2 ) &0x0fff ;You might as well delete the pointless masking with
0xff.
Hmm... Does it guarantee the most significant nibble to be always 0? (Note 16-bit value and three f:s in the mask)
Signature · 2 lines
With Best Regards, Andy Shevchenko
From: Andy Shevchenko
Quoted 41 lines
Sent: 25 June 2019 11:50
To: David Laight
Cc: Dmitry Torokhov; [email protected]; Marco Felsch; Benoit Parrot; linux- [email protected]
Subject: Re: [PATCH 1/2] Input: edt-ft5x06 - useget_unaligned_be16()Quoted 27 lines · David Laight
From: Dmitry Torokhov
Quoted 25 lines
Sent: 23 June 2019 07:32
Instead of doing conversion by hand, let's use the proper accessors.
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/touchscreen/edt-ft5x06.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/input/touchscreen/edt-ft5x06.c +1
-0@@ -27,6 +27,7 @@#include <linux/gpio/consumer.h> #include <linux/input/mt.h> #include <linux/input/touchscreen.h> +#include <asm/unaligned.h> #define WORK_REGISTER_THRESHOLD 0x00#define WORK_REGISTER_REPORT_RATE 0x08@@ -239,8 +240,8 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)if (tsdata->version ==EDT_M06 && type ==TOUCH_EVENT_DOWN )continue ;Quoted 6 lines
drivers/input/touchscreen/edt-ft5x06.c static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id) · line 244
Quoted 4 lines
drivers/input/touchscreen/edt-ft5x06.c +2
-2- x = ((buf[0 ] <<8 ) | buf[1 ]) &0x0fff ; - y = ((buf[2 ] <<8 ) | buf[3 ]) &0x0fff ; + x =get_unaligned_be16 (buf) &0x0fff ; + y =get_unaligned_be16 (buf +2 ) &0x0fff ;You might as well delete the pointless masking with
0xff.
Quoted 2 lines
Hmm... Does it guarantee the most significant nibble to be always 0? (Note 16-bit value and three f:s in the mask)
Sorry, I misread it :-(
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Dmitry Torokhov <[email protected]> wrote on Sat [2019-Jun-22 23:31:52 -0700]:
Quoted 20 lines
Instead of doing conversion by hand, let's use the proper accessors.
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/touchscreen/edt-ft5x06.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/input/touchscreen/edt-ft5x06.c +1
-0@@ -27,6 +27,7 @@#include <linux/gpio/consumer.h> #include <linux/input/mt.h> #include <linux/input/touchscreen.h> +#include <asm/unaligned.h> #define WORK_REGISTER_THRESHOLD 0x00#define WORK_REGISTER_REPORT_RATE 0x08
drivers/input/touchscreen/edt-ft5x06.c static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id) · line 244
Quoted 7 lines
drivers/input/touchscreen/edt-ft5x06.c +2
-2@@ -239,8 +240,8 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)if (tsdata->version ==EDT_M06 && type ==TOUCH_EVENT_DOWN )continue ; - x = ((buf[0 ] <<8 ) | buf[1 ]) &0x0fff ; - y = ((buf[2 ] <<8 ) | buf[3 ]) &0x0fff ; + x =get_unaligned_be16 (buf) &0x0fff ; + y =get_unaligned_be16 (buf +2 ) &0x0fff ;
Appears to work fine in my test:
Quoted 6 lines
drivers/input/touchscreen/edt-ft5x06.c +0
-0/* The FT5x26 send the y coordinate first */ if (tsdata->version ==EV_FT )swap (x, y);Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog