blob: 2c4f8eb9a6810afa34185f7c597e65d36026ac29 [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Furquan Shaikh4208e0c2014-04-28 16:43:07 -07003
Furquan Shaikh4208e0c2014-04-28 16:43:07 -07004#include <timer.h>
5#include <delay.h>
6#include <thread.h>
7
Aaron Durbin64031672018-04-21 14:45:32 -06008__weak void init_timer(void) { /* do nothing */ }
Julius Werner44cf8702014-12-08 13:39:14 -08009
Lee Leahy75b85992017-03-08 16:34:12 -080010void udelay(unsigned int usec)
Furquan Shaikh4208e0c2014-04-28 16:43:07 -070011{
Aaron Durbinb9894ef2014-09-23 16:33:21 -050012 struct stopwatch sw;
Aaron Durbin515bd132014-08-04 16:21:50 -050013
14 /*
Aaron Durbine5e36302014-09-25 10:05:15 -050015 * As the timer granularity is in microseconds pad the
Aaron Durbin515bd132014-08-04 16:21:50 -050016 * requested delay by one to get at least >= requested usec delay.
17 */
Aaron Durbinb9894ef2014-09-23 16:33:21 -050018 usec += 1;
19
20 if (!thread_yield_microseconds(usec))
21 return;
22
23 stopwatch_init_usecs_expire(&sw, usec);
Jonathan Neuschäferc9660752017-09-19 15:19:54 +020024 stopwatch_wait_until_expired(&sw);
Furquan Shaikh4208e0c2014-04-28 16:43:07 -070025}