Hi, On Tue, 2012-09-04 at 10:58 +0200, Sascha Hauer wrote: > > + for (i = 0; i < len; i++) { > > + /* wait till TX register is empty (TXS == 1) */ > > + while > (!(readl(®s->channel[spi->chip_select].chstat) & > > + OMAP3_MCSPI_CHSTAT_TXS)) { > > + if (--timeout <= 0) { > > + printf("SPI TXS timed out, status=0x% > 08x\n", > > + > readl(®s->channel[spi->chip_select].chstat)); > > + return -1; > > + } > > + } > > Please use a well defined timeout rather than 'poll a million times' I tried using is_timeout like this: timer_start = get_time_ns(); while (!(readl(®s->channel[spi->chip_select].chstat) & OMAP3_MCSPI_CHSTAT_TXS)) { if (is_timeout(timer_start, SPI_WAIT_TIMEOUT)) { printf("SPI TXS timed out, status=0x%08x\n", readl(®s->channel[spi->chip_select].chstat)); return -1; } } With SPI_WAIT_TIMEOUT = MSECOND this results in ~23% more time needed for reading/writing: With a simple counter: barebox@KSP-0500:/ time cp /dev/m25p0.norkernel /dev/null time: 12639ms barebox@KSP-0500:/ time cp /dev/m25p0.norkernel /dev/null time: 12639ms barebox@KSP-0500:/ time cp /dev/m25p0.norkernel /dev/null time: 12659ms With is_timeout(): barebox@KSP-0500:/ time cp /dev/m25p0.norkernel /dev/null time: 15561ms barebox@KSP-0500:/ time cp /dev/m25p0.norkernel /dev/null time: 15564ms barebox@KSP-0500:/ time cp /dev/m25p0.norkernel /dev/null time: 15568ms Is this really acceptable? Is there a way to avoid the overhead of calling several functions for each loop? Regards, Jan -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox