Input: synaptics - separate old and new protocol parsing From: Dmitry Torokhov Split synaptics_parse_hw_state into 2 separate functions in preparation for CLickPad support. Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/synaptics.c | 98 ++++++++++++++++++++------------------- 1 files changed, 50 insertions(+), 48 deletions(-) diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index 05689e7..0d60cb7 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -326,40 +326,34 @@ static void synaptics_pt_create(struct psmouse *psmouse) /***************************************************************************** * Functions to interpret the absolute mode packets ****************************************************************************/ - -static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data *priv, struct synaptics_hw_state *hw) +static void synaptics_parse_new_hw(unsigned char buf[], + struct synaptics_data *priv, + struct synaptics_hw_state *hw) { - 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 = (((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)); - - hw->left = (buf[0] & 0x01) ? 1 : 0; - hw->right = (buf[0] & 0x02) ? 1 : 0; - - if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { - hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; - if (hw->w == 2) - hw->scroll = (signed char)(buf[1]); - } + hw->x = (((buf[3] & 0x10) << 8) | ((buf[1] & 0x0f) << 8) | buf[4]); + hw->y = (((buf[3] & 0x20) << 7) | ((buf[1] & 0xf0) << 4) | buf[5]); - if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { - hw->up = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; - hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0; - } + hw->z = buf[2]; + hw->w = (((buf[0] & 0x30) >> 2) | + ((buf[0] & 0x04) >> 1) | + ((buf[3] & 0x04) >> 2)); + + hw->left = buf[0] & 0x01; + hw->right = buf[0] & 0x02; - if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) && - ((buf[0] ^ buf[3]) & 0x02)) { + if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { + hw->middle = (buf[0] ^ buf[3]) & 0x01; + hw->scroll = hw->w == 2 ? (signed char)(buf[1]) : 0; + } + + if (SYN_CAP_FOUR_BUTTON(priv->capabilities)) { + hw->up = (buf[0] ^ buf[3]) & 0x01; + hw->down = (buf[0] ^ buf[3]) & 0x02; + } + + if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap)) { + hw->ext_buttons = 0; + if ((buf[0] ^ buf[3]) & 0x02) { switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) { default: /* @@ -368,29 +362,34 @@ static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data */ break; case 8: - hw->ext_buttons |= ((buf[5] & 0x08)) ? 0x80 : 0; - hw->ext_buttons |= ((buf[4] & 0x08)) ? 0x40 : 0; + hw->ext_buttons |= (buf[5] & 0x08) << 4; + hw->ext_buttons |= (buf[4] & 0x08) << 3; case 6: - hw->ext_buttons |= ((buf[5] & 0x04)) ? 0x20 : 0; - hw->ext_buttons |= ((buf[4] & 0x04)) ? 0x10 : 0; + hw->ext_buttons |= (buf[5] & 0x04) << 3; + hw->ext_buttons |= (buf[4] & 0x04) << 2; case 4: - hw->ext_buttons |= ((buf[5] & 0x02)) ? 0x08 : 0; - hw->ext_buttons |= ((buf[4] & 0x02)) ? 0x04 : 0; + hw->ext_buttons |= (buf[5] & 0x02) << 2; + hw->ext_buttons |= (buf[4] & 0x02) << 1; case 2: - hw->ext_buttons |= ((buf[5] & 0x01)) ? 0x02 : 0; - hw->ext_buttons |= ((buf[4] & 0x01)) ? 0x01 : 0; + hw->ext_buttons |= (buf[5] & 0x01) << 1; + hw->ext_buttons |= (buf[4] & 0x01) << 0; } } - } else { - hw->x = (((buf[1] & 0x1f) << 8) | buf[2]); - hw->y = (((buf[4] & 0x1f) << 8) | buf[5]); + } +} - hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F)); - hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1)); +static void synaptics_parse_old_hw(unsigned char buf[], + struct synaptics_data *priv, + struct synaptics_hw_state *hw) +{ + hw->x = (((buf[1] & 0x1f) << 8) | buf[2]); + hw->y = (((buf[4] & 0x1f) << 8) | buf[5]); - hw->left = (buf[0] & 0x01) ? 1 : 0; - hw->right = (buf[0] & 0x02) ? 1 : 0; - } + hw->z = (((buf[0] & 0x30) << 2) | (buf[3] & 0x3F)); + hw->w = (((buf[1] & 0x80) >> 4) | ((buf[0] & 0x04) >> 1)); + + hw->left = buf[0] & 0x01; + hw->right = buf[0] & 0x02; } /* @@ -405,7 +404,10 @@ static void synaptics_process_packet(struct psmouse *psmouse) int finger_width; int i; - synaptics_parse_hw_state(psmouse->packet, priv, &hw); + if (SYN_MODEL_NEWABS(priv->model_id)) + synaptics_parse_new_hw(psmouse->packet, priv, &hw); + else + synaptics_parse_old_hw(psmouse->packet, priv, &hw); if (hw.scroll) { priv->scroll += hw.scroll;