diff mbox

[05/12] Input: synaptics - process button bits in AGM packets

Message ID 1309324042-22943-6-git-send-email-djkurtz@chromium.org (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Kurtz June 29, 2011, 5:07 a.m. UTC
From: Daniel Kurtz <djkurtz@chromium.org>

AGM packets contain valid button bits, too.
This patch refactors packet processing to parse button bits in AGM packets.
However, they aren't actually used or reported.

The point is to more completely process AGM packets,
and prepare for future patches that may actually use AGM packet button bits.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/mouse/synaptics.c |   35 ++++++++++++++++++-----------------
 1 files changed, 18 insertions(+), 17 deletions(-)

Comments

Henrik Rydberg July 4, 2011, 9:24 p.m. UTC | #1
Hi Daniel,

> AGM packets contain valid button bits, too.
> This patch refactors packet processing to parse button bits in AGM packets.
> However, they aren't actually used or reported.
> 
> The point is to more completely process AGM packets,
> and prepare for future patches that may actually use AGM packet button bits.
> 
> Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
> ---
>  drivers/input/mouse/synaptics.c |   35 ++++++++++++++++++-----------------
>  1 files changed, 18 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
> index 1ce47b7..74b1222 100644
> --- a/drivers/input/mouse/synaptics.c
> +++ b/drivers/input/mouse/synaptics.c
> @@ -408,27 +408,10 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
>  	memset(hw, 0, sizeof(struct synaptics_hw_state));
>  
>  	if (SYN_MODEL_NEWABS(priv->model_id)) {
> -		hw->x = (((buf[3] & 0x10) << 8) |
> -			 ((buf[1] & 0x0f) << 8) |
> -			 buf[4]);
> -		hw->y = INVERT_Y((((buf[3] & 0x20) << 7) |
> -			 ((buf[1] & 0xf0) << 4) |
> -			 buf[5]));
> -
> -		hw->z = buf[2];

Any particular reason to move these and leave them unassigned for clickpads?

>  		hw->w = (((buf[0] & 0x30) >> 2) |
>  			 ((buf[0] & 0x04) >> 1) |
>  			 ((buf[3] & 0x04) >> 2));
>  
> -		if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
> -			/* Gesture packet: (x, y, z) at half resolution */
> -			priv->mt.x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
> -			priv->mt.y = INVERT_Y((((buf[4] & 0xf0) << 4)
> -					      | buf[2]) << 1);
> -			priv->mt.z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
> -			return 1;
> -		}
> -
>  		hw->left  = (buf[0] & 0x01) ? 1 : 0;
>  		hw->right = (buf[0] & 0x02) ? 1 : 0;
>  
> @@ -451,6 +434,24 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
>  			hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
>  		}
>  
> +		if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
> +			/* Gesture packet: (x, y, z) at half resolution */
> +			priv->mt.x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
> +			priv->mt.y = INVERT_Y((((buf[4] & 0xf0) << 4)
> +					      | buf[2]) << 1);
> +			priv->mt.z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
> +			return 1;
> +		} else {
> +			hw->x = (((buf[3] & 0x10) << 8) |
> +				 ((buf[1] & 0x0f) << 8) |
> +				 buf[4]);
> +			hw->y = INVERT_Y((((buf[3] & 0x20) << 7) |
> +					 ((buf[1] & 0xf0) << 4) |
> +					 buf[5]));
> +
> +			hw->z = buf[2];
> +		}
> +
>  		if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
>  		    ((buf[0] ^ buf[3]) & 0x02)) {
>  			switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
> -- 
> 1.7.3.1
> 

Thanks,
Henrik
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chase Douglas July 5, 2011, 6:19 p.m. UTC | #2
On 07/05/2011 11:18 AM, Henrik Rydberg wrote:
>>> Any particular reason to move these and leave them unassigned for clickpads?
>>
>> Yes.  The current implementation incorrectly parses the x, y, z of AGM
>> packets and assigns junk values to the corresponding fields of the
>> temporary hw struct.  Luckily, this struct is then just discarded upon
>> return (synaptics_parse_hw_state returns 1 causing
>> synaptics_process_packet() to exit immediately).
>>
>> Instead, this patch parses the w value first to determine the packet
>> type, and then use this packet type information to parse the remaining
>> position and pressure fields correctly...
>>
>> Notice that the "else" clause is taken for SGM packets (w != 2), even
>> for clickpads.
> 
> Functionally, there is no difference between assigning new junk or
> reusing old junk, hence that part of the patch is not strictly needed.

True, it's not necessary, but I do like the new flow better. I was
reviewing the patch myself when I started wondering why we ever assigned
junk that was incorrect. I think this will help clean up the code and
make it more readable.

-- Chase
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov July 7, 2011, 6:24 a.m. UTC | #3
On Tue, Jul 05, 2011 at 10:47:19AM -0700, Chase Douglas wrote:
> On 06/28/2011 10:07 PM, djkurtz@chromium.org wrote:
> > From: Daniel Kurtz <djkurtz@chromium.org>
> > 
> > AGM packets contain valid button bits, too.
> > This patch refactors packet processing to parse button bits in AGM packets.
> > However, they aren't actually used or reported.
> > 
> > The point is to more completely process AGM packets,
> > and prepare for future patches that may actually use AGM packet button bits.
> > 
> > Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
> 
> I can't see anything wrong with this :).
> 
> Acked-by: Chase Douglas <chase.douglas@canonical.com>
> 

Applied with minor edits.

> > ---
> >  drivers/input/mouse/synaptics.c |   35 ++++++++++++++++++-----------------
> >  1 files changed, 18 insertions(+), 17 deletions(-)
> > 
> > diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
> > index 1ce47b7..74b1222 100644
> > --- a/drivers/input/mouse/synaptics.c
> > +++ b/drivers/input/mouse/synaptics.c
> > @@ -408,27 +408,10 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
> >  	memset(hw, 0, sizeof(struct synaptics_hw_state));
> >  
> >  	if (SYN_MODEL_NEWABS(priv->model_id)) {
> > -		hw->x = (((buf[3] & 0x10) << 8) |
> > -			 ((buf[1] & 0x0f) << 8) |
> > -			 buf[4]);
> > -		hw->y = INVERT_Y((((buf[3] & 0x20) << 7) |
> > -			 ((buf[1] & 0xf0) << 4) |
> > -			 buf[5]));
> > -
> > -		hw->z = buf[2];
> >  		hw->w = (((buf[0] & 0x30) >> 2) |
> >  			 ((buf[0] & 0x04) >> 1) |
> >  			 ((buf[3] & 0x04) >> 2));
> >  
> > -		if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
> > -			/* Gesture packet: (x, y, z) at half resolution */
> > -			priv->mt.x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
> > -			priv->mt.y = INVERT_Y((((buf[4] & 0xf0) << 4)
> > -					      | buf[2]) << 1);
> > -			priv->mt.z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
> > -			return 1;
> > -		}
> > -
> >  		hw->left  = (buf[0] & 0x01) ? 1 : 0;
> >  		hw->right = (buf[0] & 0x02) ? 1 : 0;
> >  
> > @@ -451,6 +434,24 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
> >  			hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
> >  		}
> >  
> > +		if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
> > +			/* Gesture packet: (x, y, z) at half resolution */
> > +			priv->mt.x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
> > +			priv->mt.y = INVERT_Y((((buf[4] & 0xf0) << 4)
> > +					      | buf[2]) << 1);
> > +			priv->mt.z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
> > +			return 1;
> > +		} else {
> > +			hw->x = (((buf[3] & 0x10) << 8) |
> > +				 ((buf[1] & 0x0f) << 8) |
> > +				 buf[4]);
> > +			hw->y = INVERT_Y((((buf[3] & 0x20) << 7) |
> > +					 ((buf[1] & 0xf0) << 4) |
> > +					 buf[5]));
> > +
> > +			hw->z = buf[2];
> > +		}
> > +
> >  		if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
> >  		    ((buf[0] ^ buf[3]) & 0x02)) {
> >  			switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
>
diff mbox

Patch

diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 1ce47b7..74b1222 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -408,27 +408,10 @@  static int synaptics_parse_hw_state(const unsigned char buf[],
 	memset(hw, 0, sizeof(struct synaptics_hw_state));
 
 	if (SYN_MODEL_NEWABS(priv->model_id)) {
-		hw->x = (((buf[3] & 0x10) << 8) |
-			 ((buf[1] & 0x0f) << 8) |
-			 buf[4]);
-		hw->y = INVERT_Y((((buf[3] & 0x20) << 7) |
-			 ((buf[1] & 0xf0) << 4) |
-			 buf[5]));
-
-		hw->z = buf[2];
 		hw->w = (((buf[0] & 0x30) >> 2) |
 			 ((buf[0] & 0x04) >> 1) |
 			 ((buf[3] & 0x04) >> 2));
 
-		if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
-			/* Gesture packet: (x, y, z) at half resolution */
-			priv->mt.x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
-			priv->mt.y = INVERT_Y((((buf[4] & 0xf0) << 4)
-					      | buf[2]) << 1);
-			priv->mt.z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
-			return 1;
-		}
-
 		hw->left  = (buf[0] & 0x01) ? 1 : 0;
 		hw->right = (buf[0] & 0x02) ? 1 : 0;
 
@@ -451,6 +434,24 @@  static int synaptics_parse_hw_state(const unsigned char buf[],
 			hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
 		}
 
+		if (SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) && hw->w == 2) {
+			/* Gesture packet: (x, y, z) at half resolution */
+			priv->mt.x = (((buf[4] & 0x0f) << 8) | buf[1]) << 1;
+			priv->mt.y = INVERT_Y((((buf[4] & 0xf0) << 4)
+					      | buf[2]) << 1);
+			priv->mt.z = ((buf[3] & 0x30) | (buf[5] & 0x0f)) << 1;
+			return 1;
+		} else {
+			hw->x = (((buf[3] & 0x10) << 8) |
+				 ((buf[1] & 0x0f) << 8) |
+				 buf[4]);
+			hw->y = INVERT_Y((((buf[3] & 0x20) << 7) |
+					 ((buf[1] & 0xf0) << 4) |
+					 buf[5]));
+
+			hw->z = buf[2];
+		}
+
 		if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
 		    ((buf[0] ^ buf[3]) & 0x02)) {
 			switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {