/* ps2_drain() waits for device to transmit requested number of bytes and discards them.  */
void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
/* ps2_drain() waits for device to transmit requested number of bytes and discards them.  */
void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
{
	if (maxbytes > sizeof(ps2dev->cmdbuf)) {
		WARN_ON(1);
		maxbytes = sizeof(ps2dev->cmdbuf);
	}
	ps2_begin_command(ps2dev);
	serio_pause_rx(ps2dev->serio);
	ps2dev->flags = PS2_FLAG_CMD;
	ps2dev->cmdcnt = maxbytes;
	serio_continue_rx(ps2dev->serio);
	wait_event_timeout(ps2dev->wait,
			   !(ps2dev->flags & PS2_FLAG_CMD),
			   msecs_to_jiffies(timeout));
	ps2_end_command(ps2dev);
}