mirror of https://gitee.com/openkylin/linux.git
Input: trackpoint - combine calls to ps2_command()
We do not need to call ps2_command() several times in a row, transmitting every byte as it were a command byte, we can often pack it all in a single command. Also, now that ps2_command() handles retransmission, we do not need to do it ourselves in trackpoint_power_on_reset(). Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
29acc42e8e
commit
3aceaa34d7
|
@ -33,18 +33,15 @@ static const char * const trackpoint_variants[] = {
|
|||
*/
|
||||
static int trackpoint_power_on_reset(struct ps2dev *ps2dev)
|
||||
{
|
||||
u8 results[2];
|
||||
int tries = 0;
|
||||
u8 param[2] = { TP_POR };
|
||||
int err;
|
||||
|
||||
/* Issue POR command, and repeat up to once if 0xFC00 received */
|
||||
do {
|
||||
if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
|
||||
ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 2, TP_POR)))
|
||||
return -1;
|
||||
} while (results[0] == 0xFC && results[1] == 0x00 && ++tries < 2);
|
||||
err = ps2_command(ps2dev, param, MAKE_PS2_CMD(1, 2, TP_COMMAND));
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Check for success response -- 0xAA00 */
|
||||
if (results[0] != 0xAA || results[1] != 0x00)
|
||||
if (param[0] != 0xAA || param[1] != 0x00)
|
||||
return -ENODEV;
|
||||
|
||||
return 0;
|
||||
|
@ -55,49 +52,39 @@ static int trackpoint_power_on_reset(struct ps2dev *ps2dev)
|
|||
*/
|
||||
static int trackpoint_read(struct ps2dev *ps2dev, u8 loc, u8 *results)
|
||||
{
|
||||
if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
|
||||
ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc))) {
|
||||
return -1;
|
||||
}
|
||||
results[0] = loc;
|
||||
|
||||
return 0;
|
||||
return ps2_command(ps2dev, results, MAKE_PS2_CMD(1, 1, TP_COMMAND));
|
||||
}
|
||||
|
||||
static int trackpoint_write(struct ps2dev *ps2dev, u8 loc, u8 val)
|
||||
{
|
||||
if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
|
||||
ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM)) ||
|
||||
ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) ||
|
||||
ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, val))) {
|
||||
return -1;
|
||||
}
|
||||
u8 param[3] = { TP_WRITE_MEM, loc, val };
|
||||
|
||||
return 0;
|
||||
return ps2_command(ps2dev, param, MAKE_PS2_CMD(3, 0, TP_COMMAND));
|
||||
}
|
||||
|
||||
static int trackpoint_toggle_bit(struct ps2dev *ps2dev, u8 loc, u8 mask)
|
||||
{
|
||||
u8 param[3] = { TP_TOGGLE, loc, mask };
|
||||
|
||||
/* Bad things will happen if the loc param isn't in this range */
|
||||
if (loc < 0x20 || loc >= 0x2F)
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
|
||||
if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) ||
|
||||
ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_TOGGLE)) ||
|
||||
ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) ||
|
||||
ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, mask))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ps2_command(ps2dev, param, MAKE_PS2_CMD(3, 0, TP_COMMAND));
|
||||
}
|
||||
|
||||
static int trackpoint_update_bit(struct ps2dev *ps2dev,
|
||||
u8 loc, u8 mask, u8 value)
|
||||
{
|
||||
int retval = 0;
|
||||
int retval;
|
||||
u8 data;
|
||||
|
||||
trackpoint_read(ps2dev, loc, &data);
|
||||
retval = trackpoint_read(ps2dev, loc, &data);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
if (((data & mask) == mask) != !!value)
|
||||
retval = trackpoint_toggle_bit(ps2dev, loc, mask);
|
||||
|
||||
|
@ -142,9 +129,9 @@ static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data,
|
|||
return err;
|
||||
|
||||
*field = value;
|
||||
trackpoint_write(&psmouse->ps2dev, attr->command, value);
|
||||
err = trackpoint_write(&psmouse->ps2dev, attr->command, value);
|
||||
|
||||
return count;
|
||||
return err ?: count;
|
||||
}
|
||||
|
||||
#define TRACKPOINT_INT_ATTR(_name, _command, _default) \
|
||||
|
@ -175,10 +162,11 @@ static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data,
|
|||
|
||||
if (*field != value) {
|
||||
*field = value;
|
||||
trackpoint_toggle_bit(&psmouse->ps2dev, attr->command, attr->mask);
|
||||
err = trackpoint_toggle_bit(&psmouse->ps2dev,
|
||||
attr->command, attr->mask);
|
||||
}
|
||||
|
||||
return count;
|
||||
return err ?: count;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue