/* Service routine to read status register until ready, or timeout occurs. Returns non-zero if error.  */
static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor, unsigned long timeout)
/* Service routine to read status register until ready, or timeout occurs. Returns non-zero if error.  */
static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor, unsigned long timeout)
{
	unsigned long timebase;
	int ret;
	timebase = get_timer(0);
	while (get_timer(timebase) < timeout) {
		ret = spi_nor_ready(nor);
		if (ret < 0)
			return ret;
		if (ret)
			return 0;
	}
	dev_err(nor->dev, "flash operation timed out\n");
	return -ETIMEDOUT;
}