/* Write a byte to the PS2 port. We have to wait for the port to indicate that the transmitter is empty.  */
static int ps2_write(struct serio *io, unsigned char val)
/* Write a byte to the PS2 port. We have to wait for the port to indicate that the transmitter is empty.  */
static int ps2_write(struct serio *io, unsigned char val)
{
	struct ps2if *ps2if = io->port_data;
	unsigned long flags;
	unsigned int head;
	spin_lock_irqsave(&ps2if->lock, flags);
	if (sa1111_readl(ps2if->base + SA1111_PS2STAT) & PS2STAT_TXE) {
		sa1111_writel(val, ps2if->base + SA1111_PS2DATA);
	} else {
		if (ps2if->head == ps2if->tail)
			enable_irq(ps2if->dev->irq[1]);
		head = (ps2if->head + 1) & (sizeof(ps2if->buf) - 1);
		if (head != ps2if->tail) {
			ps2if->buf[ps2if->head] = val;
			ps2if->head = head;
		}
	}
	spin_unlock_irqrestore(&ps2if->lock, flags);
	return 0;
}