Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Furquan Shaikh | 4208e0c | 2014-04-28 16:43:07 -0700 | [diff] [blame] | 3 | |
Furquan Shaikh | 4208e0c | 2014-04-28 16:43:07 -0700 | [diff] [blame] | 4 | #include <timer.h> |
| 5 | #include <delay.h> |
| 6 | #include <thread.h> |
| 7 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 8 | __weak void init_timer(void) { /* do nothing */ } |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 9 | |
Lee Leahy | 75b8599 | 2017-03-08 16:34:12 -0800 | [diff] [blame] | 10 | void udelay(unsigned int usec) |
Furquan Shaikh | 4208e0c | 2014-04-28 16:43:07 -0700 | [diff] [blame] | 11 | { |
Aaron Durbin | b9894ef | 2014-09-23 16:33:21 -0500 | [diff] [blame] | 12 | struct stopwatch sw; |
Aaron Durbin | 515bd13 | 2014-08-04 16:21:50 -0500 | [diff] [blame] | 13 | |
| 14 | /* |
Aaron Durbin | e5e3630 | 2014-09-25 10:05:15 -0500 | [diff] [blame] | 15 | * As the timer granularity is in microseconds pad the |
Aaron Durbin | 515bd13 | 2014-08-04 16:21:50 -0500 | [diff] [blame] | 16 | * requested delay by one to get at least >= requested usec delay. |
| 17 | */ |
Aaron Durbin | b9894ef | 2014-09-23 16:33:21 -0500 | [diff] [blame] | 18 | usec += 1; |
| 19 | |
| 20 | if (!thread_yield_microseconds(usec)) |
| 21 | return; |
| 22 | |
| 23 | stopwatch_init_usecs_expire(&sw, usec); |
Jonathan Neuschäfer | c966075 | 2017-09-19 15:19:54 +0200 | [diff] [blame] | 24 | stopwatch_wait_until_expired(&sw); |
Furquan Shaikh | 4208e0c | 2014-04-28 16:43:07 -0700 | [diff] [blame] | 25 | } |