diff options
author | Amit Daniel Kachhap <amit.kachhap@arm.com> | 2018-07-13 10:19:03 +0530 |
---|---|---|
committer | Amit Daniel Kachhap <amit.kachhap@arm.com> | 2018-12-20 20:47:04 +0530 |
commit | b05e3df569933930d1e350434c233d0893b192bb (patch) | |
tree | 2049feee75fe0c4b0726561ec675fe460449d374 | |
parent | bda58756f32c3b445d67d4ceb214d9d13ad71004 (diff) |
Revert "Input: libps2 - support retransmission of command data"
This reverts commit b99e1f2a1a3f4158bed9b9e9e97ac46678d8c2ac.
-rw-r--r-- | drivers/input/serio/libps2.c | 103 |
1 files changed, 32 insertions, 71 deletions
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c index f05c407b31f3..82befae4dab0 100644 --- a/drivers/input/serio/libps2.c +++ b/drivers/input/serio/libps2.c @@ -26,63 +26,35 @@ MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>"); MODULE_DESCRIPTION("PS/2 driver library"); MODULE_LICENSE("GPL"); -static int ps2_do_sendbyte(struct ps2dev *ps2dev, u8 byte, - unsigned int timeout, unsigned int max_attempts) - __releases(&ps2dev->serio->lock) __acquires(&ps2dev->serio->lock) +static int ps2_do_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) { - int attempt = 0; int error; - lockdep_assert_held(&ps2dev->serio->lock); - - do { - ps2dev->nak = 1; - ps2dev->flags |= PS2_FLAG_ACK; - - serio_continue_rx(ps2dev->serio); - - error = serio_write(ps2dev->serio, byte); - if (error) - dev_dbg(&ps2dev->serio->dev, - "failed to write %#02x: %d\n", byte, error); - else - wait_event_timeout(ps2dev->wait, - !(ps2dev->flags & PS2_FLAG_ACK), - msecs_to_jiffies(timeout)); + serio_pause_rx(ps2dev->serio); + ps2dev->nak = 1; + ps2dev->flags |= PS2_FLAG_ACK; + serio_continue_rx(ps2dev->serio); - serio_pause_rx(ps2dev->serio); - } while (ps2dev->nak == PS2_RET_NAK && ++attempt < max_attempts); + error = serio_write(ps2dev->serio, byte); + if (error) + dev_dbg(&ps2dev->serio->dev, + "failed to write %#02x: %d\n", byte, error); + else + wait_event_timeout(ps2dev->wait, + !(ps2dev->flags & PS2_FLAG_ACK), + msecs_to_jiffies(timeout)); + serio_pause_rx(ps2dev->serio); ps2dev->flags &= ~PS2_FLAG_ACK; + serio_continue_rx(ps2dev->serio); - if (!error) { - switch (ps2dev->nak) { - case 0: - break; - case PS2_RET_NAK: - error = -EAGAIN; - break; - case PS2_RET_ERR: - error = -EPROTO; - break; - default: - error = -EIO; - break; - } - } - - if (error || attempt > 1) - dev_dbg(&ps2dev->serio->dev, - "%02x - %d (%x), attempt %d\n", - byte, error, ps2dev->nak, attempt); - - return error; + return -ps2dev->nak; } /* * ps2_sendbyte() sends a byte to the device and waits for acknowledge. - * It doesn't handle retransmission, the caller is expected to handle - * it when needed. + * It doesn't handle retransmission, though it could - because if there + * is a need for retransmissions device has to be replaced anyway. * * ps2_sendbyte() can only be called from a process context. */ @@ -91,13 +63,9 @@ int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) { int retval; - serio_pause_rx(ps2dev->serio); - - retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1); + retval = ps2_do_sendbyte(ps2dev, byte, timeout); dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak); - serio_continue_rx(ps2dev->serio); - return retval; } EXPORT_SYMBOL(ps2_sendbyte); @@ -232,48 +200,48 @@ int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) unsigned int timeout; unsigned int send = (command >> 12) & 0xf; unsigned int receive = (command >> 8) & 0xf; - int rc; + int rc = -1; int i; u8 send_param[16]; if (receive > sizeof(ps2dev->cmdbuf)) { WARN_ON(1); - return -EINVAL; + return -1; } if (send && !param) { WARN_ON(1); - return -EINVAL; + return -1; } memcpy(send_param, param, send); serio_pause_rx(ps2dev->serio); - ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0; ps2dev->cmdcnt = receive; if (receive && param) for (i = 0; i < receive; i++) ps2dev->cmdbuf[(receive - 1) - i] = param[i]; + serio_continue_rx(ps2dev->serio); /* * Some devices (Synaptics) peform the reset before * ACKing the reset command, and so it can take a long * time before the ACK arrives. */ - rc = ps2_do_sendbyte(ps2dev, command & 0xff, - command == PS2_CMD_RESET_BAT ? 1000 : 200, 2); - if (rc) + if (ps2_do_sendbyte(ps2dev, command & 0xff, + command == PS2_CMD_RESET_BAT ? 1000 : 200)) { + serio_pause_rx(ps2dev->serio); goto out_reset_flags; + } for (i = 0; i < send; i++) { - rc = ps2_do_sendbyte(ps2dev, param[i], 200, 2); - if (rc) + if (ps2_do_sendbyte(ps2dev, param[i], 200)) { + serio_pause_rx(ps2dev->serio); goto out_reset_flags; + } } - serio_continue_rx(ps2dev->serio); - /* * The reset command takes a long time to execute. */ @@ -295,11 +263,8 @@ int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) for (i = 0; i < receive; i++) param[i] = ps2dev->cmdbuf[(receive - 1) - i]; - if (ps2dev->cmdcnt && - (command != PS2_CMD_RESET_BAT || ps2dev->cmdcnt != 1)) { - rc = -EPROTO; + if (ps2dev->cmdcnt && (command != PS2_CMD_RESET_BAT || ps2dev->cmdcnt != 1)) goto out_reset_flags; - } rc = 0; @@ -313,11 +278,7 @@ int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) ps2dev->nak, ps2dev->flags, receive, param ?: send_param); - /* - * ps_command() handles resends itself, so do not leak -EAGAIN - * to the callers. - */ - return rc != -EAGAIN ? rc : -EPROTO; + return rc; } EXPORT_SYMBOL(__ps2_command); |