/* This function waits for FIFO to empty. It returns 1 when FIFO is empty, or 0 if the timeout @timeout is reached before, or if a signal is pending.  */
static unsigned int parport_ip32_drain_fifo(struct parport *p, unsigned long timeout)
/* This function waits for FIFO to empty. It returns 1 when FIFO is empty, or 0 if the timeout @timeout is reached before, or if a signal is pending.  */
static unsigned int parport_ip32_drain_fifo(struct parport *p, unsigned long timeout)
{
	unsigned long expire = jiffies + timeout;
	unsigned int polling_interval;
	unsigned int counter;
	for (counter = 0; counter < 40; counter++) {
		if (parport_ip32_read_econtrol(p) & ECR_F_EMPTY)
			break;
		if (time_after(jiffies, expire))
			break;
		if (signal_pending(current))
			break;
		udelay(5);
	}
	polling_interval = 1;
	while (!(parport_ip32_read_econtrol(p) & ECR_F_EMPTY)) {
		if (time_after_eq(jiffies, expire))
			break;
		msleep_interruptible(polling_interval);
		if (signal_pending(current))
			break;
		if (polling_interval < 128)
			polling_interval *= 2;
	}
	return !!(parport_ip32_read_econtrol(p) & ECR_F_EMPTY);
}