drivers/spi: Reduce the per loop delay of spi_flash_cmd_poll_bit()
At the end of some SPI operations the SPI device needs to be polled to determine if it is done with the operation. For SPI data writes the predicted time of that operation could be less than 10us. The current per loop delay of 500us is adding too much delay. This change replaces the delay(x) in the do-while loop with a timer so that the actual timeout value won't be lengthened by the delay of reading the SPI device. Change-Id: Ia8b00879135f926c402bbd9d08953c77a2dcc84e Signed-off-by: Dave Frodin <dave.frodin@se-eng.com> Reviewed-on: http://review.coreboot.org/5973 Tested-by: build bot (Jenkins) Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com> Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
This commit is contained in:
parent
ba92428514
commit
c50c0ab456
|
@ -16,6 +16,7 @@
|
||||||
#include <cpu/x86/smm.h>
|
#include <cpu/x86/smm.h>
|
||||||
#endif
|
#endif
|
||||||
#include "spi_flash_internal.h"
|
#include "spi_flash_internal.h"
|
||||||
|
#include <timer.h>
|
||||||
|
|
||||||
static void spi_flash_addr(u32 addr, u8 *cmd)
|
static void spi_flash_addr(u32 addr, u8 *cmd)
|
||||||
{
|
{
|
||||||
|
@ -106,27 +107,24 @@ int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
|
||||||
u8 cmd, u8 poll_bit)
|
u8 cmd, u8 poll_bit)
|
||||||
{
|
{
|
||||||
struct spi_slave *spi = flash->spi;
|
struct spi_slave *spi = flash->spi;
|
||||||
unsigned long timebase;
|
|
||||||
int ret;
|
int ret;
|
||||||
u8 status;
|
u8 status;
|
||||||
|
struct mono_time current, end;
|
||||||
|
|
||||||
|
timer_monotonic_get(¤t);
|
||||||
|
end = current;
|
||||||
|
mono_time_add_msecs(&end, timeout);
|
||||||
|
|
||||||
timebase = timeout;
|
|
||||||
do {
|
do {
|
||||||
ret = spi_flash_cmd_read(spi, &cmd, 1, &status, 1);
|
ret = spi_flash_cmd_read(spi, &cmd, 1, &status, 1);
|
||||||
if (ret)
|
if (ret)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((status & poll_bit) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
udelay(500);
|
|
||||||
} while (timebase--);
|
|
||||||
|
|
||||||
if ((status & poll_bit) == 0)
|
if ((status & poll_bit) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
timer_monotonic_get(¤t);
|
||||||
|
} while (!mono_time_after(¤t, &end));
|
||||||
|
|
||||||
/* Timed out */
|
printk(BIOS_DEBUG, "SF: timeout at %ld msec\n",timeout);
|
||||||
printk(BIOS_DEBUG, "SF: time out!\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue