From: Kevin Cernekee <cernekee@gmail.com>
To: dmitry.torokhov@gmail.com
Cc: seth.forshee@canonical.com, emmanuel.thome@inria.fr,
dturvene@dahetral.com, vincent.vanackere@gmail.com,
bgamari@gmail.com, linux-input@vger.kernel.org
Subject: [PATCH V2 04/14] Input: ALPS - Introduce helper function for repeated commands
Date: Sun, 3 Feb 2013 15:56:44 -0800 [thread overview]
Message-ID: <1359935815-13507-5-git-send-email-cernekee@gmail.com> (raw)
In-Reply-To: <1359935815-13507-1-git-send-email-cernekee@gmail.com>
Several ALPS driver init sequences repeat a command three times, then
issue PSMOUSE_CMD_GETINFO to read the result. Move this into a helper
function to simplify the code.
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
drivers/input/mouse/alps.c | 71 +++++++++++++++++++-------------------------
1 file changed, 30 insertions(+), 41 deletions(-)
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index c473549..1ca854b 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -964,24 +964,42 @@ static int alps_command_mode_write_reg(struct psmouse *psmouse, int addr,
return __alps_command_mode_write_reg(psmouse, value);
}
+static int alps_rpt_cmd(struct psmouse *psmouse, int init_command,
+ int repeated_command, unsigned char *param)
+{
+ struct ps2dev *ps2dev = &psmouse->ps2dev;
+
+ param[0] = 0;
+ if (init_command && ps2_command(ps2dev, param, init_command))
+ return -EIO;
+
+ if (ps2_command(ps2dev, NULL, repeated_command) ||
+ ps2_command(ps2dev, NULL, repeated_command) ||
+ ps2_command(ps2dev, NULL, repeated_command))
+ return -EIO;
+
+ param[0] = param[1] = param[2] = 0xff;
+ if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
+ return -EIO;
+
+ psmouse_dbg(psmouse, "%2.2X report: %2.2x %2.2x %2.2x\n",
+ repeated_command, param[0], param[1], param[2]);
+ return 0;
+}
+
static int alps_enter_command_mode(struct psmouse *psmouse,
unsigned char *resp)
{
unsigned char param[4];
- struct ps2dev *ps2dev = &psmouse->ps2dev;
- if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
- ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
+ if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) {
psmouse_err(psmouse, "failed to enter command mode\n");
return -1;
}
if (param[0] != 0x88 && param[1] != 0x07) {
psmouse_dbg(psmouse,
- "unknown response while entering command mode: %2.2x %2.2x %2.2x\n",
- param[0], param[1], param[2]);
+ "unknown response while entering command mode\n");
return -1;
}
@@ -1041,18 +1059,10 @@ static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
static int alps_get_status(struct psmouse *psmouse, char *param)
{
- struct ps2dev *ps2dev = &psmouse->ps2dev;
-
/* Get status: 0xF5 0xF5 0xF5 0xE9 */
- if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
- ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
+ if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param))
return -1;
- psmouse_dbg(psmouse, "Status: %2.2x %2.2x %2.2x",
- param[0], param[1], param[2]);
-
return 0;
}
@@ -1443,7 +1453,6 @@ static int alps_hw_init(struct psmouse *psmouse)
static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
{
- struct ps2dev *ps2dev = &psmouse->ps2dev;
static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
unsigned char param[4];
const struct alps_model_info *model = NULL;
@@ -1455,20 +1464,10 @@ static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int
* The bits 0-2 of the first byte will be 1s if some buttons are
* pressed.
*/
- param[0] = 0;
- if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
- return NULL;
-
- param[0] = param[1] = param[2] = 0xff;
- if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
+ if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, PSMOUSE_CMD_SETSCALE11,
+ param))
return NULL;
- psmouse_dbg(psmouse, "E6 report: %2.2x %2.2x %2.2x",
- param[0], param[1], param[2]);
-
if ((param[0] & 0xf8) != 0 || param[1] != 0 ||
(param[2] != 10 && param[2] != 100))
return NULL;
@@ -1477,20 +1476,10 @@ static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int
* Now try "E7 report". Allowed responses are in
* alps_model_data[].signature
*/
- param[0] = 0;
- if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
- ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
- return NULL;
-
- param[0] = param[1] = param[2] = 0xff;
- if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
+ if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, PSMOUSE_CMD_SETSCALE21,
+ param))
return NULL;
- psmouse_dbg(psmouse, "E7 report: %2.2x %2.2x %2.2x",
- param[0], param[1], param[2]);
-
if (version) {
for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
/* empty */;
--
1.7.10.4
next prev parent reply other threads:[~2013-02-03 23:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-03 23:56 [PATCH V2 00/14] Input: ALPS - Clean up and rework driver to support newer touchpads Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 01/14] Input: ALPS - Document the alps.h data structures Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 02/14] Input: ALPS - Copy "model" info into alps_data struct Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 03/14] Input: ALPS - Move alps_get_model() down below hw_init code Kevin Cernekee
2013-02-03 23:56 ` Kevin Cernekee [this message]
2013-02-03 23:56 ` [PATCH V2 05/14] Input: ALPS - Rework detection sequence Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 06/14] Input: ALPS - Use function pointers for different protocol handlers Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 07/14] Input: ALPS - Move {addr,nibble}_command settings into alps_set_defaults() Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 08/14] Input: ALPS - Rework detection of Pinnacle AGx touchpads Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 09/14] Input: ALPS - Fix command mode check Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 10/14] Input: ALPS - Move pixel and bitmap info into alps_data struct Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 11/14] Input: ALPS - Make the V3 packet field decoder "pluggable" Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 12/14] Input: ALPS - Add support for "Rushmore" touchpads Kevin Cernekee
2013-02-03 23:56 ` [PATCH V2 13/14] Input: ALPS - Enable trackstick on Rushmore touchpads Kevin Cernekee
2013-02-03 23:56 ` [RFT V2 14/14] Input: ALPS - First attempt at "Dolphin" touchpad support Kevin Cernekee
2013-02-14 17:17 ` [PATCH V2 00/14] Input: ALPS - Clean up and rework driver to support newer touchpads Dmitry Torokhov
2013-02-14 18:02 ` Kevin Cernekee
2013-02-14 18:08 ` Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359935815-13507-5-git-send-email-cernekee@gmail.com \
--to=cernekee@gmail.com \
--cc=bgamari@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dturvene@dahetral.com \
--cc=emmanuel.thome@inria.fr \
--cc=linux-input@vger.kernel.org \
--cc=seth.forshee@canonical.com \
--cc=vincent.vanackere@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).