drivers/spi: Convert spi_flash_cmd_poll_bit to use stopwatch API

The previous code required a bit too much effort to read. It also didn't
print out the actual duration.

BUG=b:228289365
TEST=Boot guybrush

Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: Ia620e789c5186f2e1d3cf3c548bda00a294d23bf
Reviewed-on: https://review.coreboot.org/c/coreboot/+/63939
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Rob Barnes <robbarnes@google.com>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
This commit is contained in:
Raul E Rangel 2022-04-28 16:17:01 -06:00 committed by Felix Held
parent 471f2eefdd
commit b10cbd0d08
1 changed files with 5 additions and 8 deletions

View File

@ -193,22 +193,19 @@ int spi_flash_cmd_poll_bit(const struct spi_flash *flash, unsigned long timeout,
const struct spi_slave *spi = &flash->spi; const struct spi_slave *spi = &flash->spi;
int ret; int ret;
u8 status; u8 status;
struct mono_time current, end; struct stopwatch sw;
timer_monotonic_get(&current);
end = current;
mono_time_add_msecs(&end, timeout);
stopwatch_init_msecs_expire(&sw, timeout);
do { do {
ret = do_spi_flash_cmd(spi, &cmd, 1, &status, 1); ret = do_spi_flash_cmd(spi, &cmd, 1, &status, 1);
if (ret) if (ret)
return -1; return -1;
if ((status & poll_bit) == 0) if ((status & poll_bit) == 0)
return 0; return 0;
timer_monotonic_get(&current); } while (!stopwatch_expired(&sw));
} while (!mono_time_after(&current, &end));
printk(BIOS_WARNING, "SF: timeout at %ld msec\n", stopwatch_duration_msecs(&sw));
printk(BIOS_DEBUG, "SF: timeout at %ld msec\n",timeout);
return -1; return -1;
} }