aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/mouse
diff options
context:
space:
mode:
authorKevin Cernekee <cernekee@gmail.com>2013-02-14 01:19:01 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-02-14 12:17:52 -0500
commit24ba9707829818daab711eed7e41313d5e56d0b4 (patch)
treed0b765cca4a754b8f5c53f4dfddc91a092540d5a /drivers/input/mouse
parent2e992cc030d8e4e42632bcc9e16605e629886778 (diff)
Input: ALPS - introduce helper function for repeated commands
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> Tested-by: Dave Turvene <dturvene@dahetral.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/mouse')
-rw-r--r--drivers/input/mouse/alps.c71
1 files changed, 30 insertions, 41 deletions
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index c473549c33bd..1ca854b0b012 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,
964 return __alps_command_mode_write_reg(psmouse, value); 964 return __alps_command_mode_write_reg(psmouse, value);
965} 965}
966 966
967static int alps_rpt_cmd(struct psmouse *psmouse, int init_command,
968 int repeated_command, unsigned char *param)
969{
970 struct ps2dev *ps2dev = &psmouse->ps2dev;
971
972 param[0] = 0;
973 if (init_command && ps2_command(ps2dev, param, init_command))
974 return -EIO;
975
976 if (ps2_command(ps2dev, NULL, repeated_command) ||
977 ps2_command(ps2dev, NULL, repeated_command) ||
978 ps2_command(ps2dev, NULL, repeated_command))
979 return -EIO;
980
981 param[0] = param[1] = param[2] = 0xff;
982 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
983 return -EIO;
984
985 psmouse_dbg(psmouse, "%2.2X report: %2.2x %2.2x %2.2x\n",
986 repeated_command, param[0], param[1], param[2]);
987 return 0;
988}
989
967static int alps_enter_command_mode(struct psmouse *psmouse, 990static int alps_enter_command_mode(struct psmouse *psmouse,
968 unsigned char *resp) 991 unsigned char *resp)
969{ 992{
970 unsigned char param[4]; 993 unsigned char param[4];
971 struct ps2dev *ps2dev = &psmouse->ps2dev;
972 994
973 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) || 995 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_RESET_WRAP, param)) {
974 ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
975 ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_WRAP) ||
976 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
977 psmouse_err(psmouse, "failed to enter command mode\n"); 996 psmouse_err(psmouse, "failed to enter command mode\n");
978 return -1; 997 return -1;
979 } 998 }
980 999
981 if (param[0] != 0x88 && param[1] != 0x07) { 1000 if (param[0] != 0x88 && param[1] != 0x07) {
982 psmouse_dbg(psmouse, 1001 psmouse_dbg(psmouse,
983 "unknown response while entering command mode: %2.2x %2.2x %2.2x\n", 1002 "unknown response while entering command mode\n");
984 param[0], param[1], param[2]);
985 return -1; 1003 return -1;
986 } 1004 }
987 1005
@@ -1041,18 +1059,10 @@ static int alps_absolute_mode_v1_v2(struct psmouse *psmouse)
1041 1059
1042static int alps_get_status(struct psmouse *psmouse, char *param) 1060static int alps_get_status(struct psmouse *psmouse, char *param)
1043{ 1061{
1044 struct ps2dev *ps2dev = &psmouse->ps2dev;
1045
1046 /* Get status: 0xF5 0xF5 0xF5 0xE9 */ 1062 /* Get status: 0xF5 0xF5 0xF5 0xE9 */
1047 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || 1063 if (alps_rpt_cmd(psmouse, 0, PSMOUSE_CMD_DISABLE, param))
1048 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1049 ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) ||
1050 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1051 return -1; 1064 return -1;
1052 1065
1053 psmouse_dbg(psmouse, "Status: %2.2x %2.2x %2.2x",
1054 param[0], param[1], param[2]);
1055
1056 return 0; 1066 return 0;
1057} 1067}
1058 1068
@@ -1443,7 +1453,6 @@ static int alps_hw_init(struct psmouse *psmouse)
1443 1453
1444static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version) 1454static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *version)
1445{ 1455{
1446 struct ps2dev *ps2dev = &psmouse->ps2dev;
1447 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 }; 1456 static const unsigned char rates[] = { 0, 10, 20, 40, 60, 80, 100, 200 };
1448 unsigned char param[4]; 1457 unsigned char param[4];
1449 const struct alps_model_info *model = NULL; 1458 const struct alps_model_info *model = NULL;
@@ -1455,20 +1464,10 @@ static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int
1455 * The bits 0-2 of the first byte will be 1s if some buttons are 1464 * The bits 0-2 of the first byte will be 1s if some buttons are
1456 * pressed. 1465 * pressed.
1457 */ 1466 */
1458 param[0] = 0; 1467 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, PSMOUSE_CMD_SETSCALE11,
1459 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) || 1468 param))
1460 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1461 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
1462 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11))
1463 return NULL;
1464
1465 param[0] = param[1] = param[2] = 0xff;
1466 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1467 return NULL; 1469 return NULL;
1468 1470
1469 psmouse_dbg(psmouse, "E6 report: %2.2x %2.2x %2.2x",
1470 param[0], param[1], param[2]);
1471
1472 if ((param[0] & 0xf8) != 0 || param[1] != 0 || 1471 if ((param[0] & 0xf8) != 0 || param[1] != 0 ||
1473 (param[2] != 10 && param[2] != 100)) 1472 (param[2] != 10 && param[2] != 100))
1474 return NULL; 1473 return NULL;
@@ -1477,20 +1476,10 @@ static const struct alps_model_info *alps_get_model(struct psmouse *psmouse, int
1477 * Now try "E7 report". Allowed responses are in 1476 * Now try "E7 report". Allowed responses are in
1478 * alps_model_data[].signature 1477 * alps_model_data[].signature
1479 */ 1478 */
1480 param[0] = 0; 1479 if (alps_rpt_cmd(psmouse, PSMOUSE_CMD_SETRES, PSMOUSE_CMD_SETSCALE21,
1481 if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES) || 1480 param))
1482 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1483 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
1484 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21))
1485 return NULL;
1486
1487 param[0] = param[1] = param[2] = 0xff;
1488 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
1489 return NULL; 1481 return NULL;
1490 1482
1491 psmouse_dbg(psmouse, "E7 report: %2.2x %2.2x %2.2x",
1492 param[0], param[1], param[2]);
1493
1494 if (version) { 1483 if (version) {
1495 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++) 1484 for (i = 0; i < ARRAY_SIZE(rates) && param[2] != rates[i]; i++)
1496 /* empty */; 1485 /* empty */;