Marek Vasut | 1778b41 | 2018-12-26 15:57:08 +0100 | [diff] [blame] | 1 | /* |
Biju Das | 68e68c6 | 2020-12-13 19:59:26 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, Renesas Electronics Corporation. All rights reserved. |
Marek Vasut | 1778b41 | 2018-12-26 15:57:08 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <arch_helpers.h> |
Biju Das | 68e68c6 | 2020-12-13 19:59:26 +0000 | [diff] [blame] | 9 | |
Marek Vasut | 1778b41 | 2018-12-26 15:57:08 +0100 | [diff] [blame] | 10 | #include "micro_delay.h" |
| 11 | |
| 12 | #define RCAR_CONV_MICROSEC 1000000U |
| 13 | |
| 14 | void |
| 15 | #if IMAGE_BL31 |
Biju Das | 68e68c6 | 2020-12-13 19:59:26 +0000 | [diff] [blame] | 16 | __attribute__ ((section(".system_ram"))) |
Marek Vasut | 1778b41 | 2018-12-26 15:57:08 +0100 | [diff] [blame] | 17 | #endif |
| 18 | rcar_micro_delay(uint64_t micro_sec) |
| 19 | { |
| 20 | uint64_t freq; |
| 21 | uint64_t base_count; |
| 22 | uint64_t get_count; |
| 23 | uint64_t wait_time = 0U; |
| 24 | |
| 25 | freq = read_cntfrq_el0(); |
| 26 | base_count = read_cntpct_el0(); |
| 27 | while (micro_sec > wait_time) { |
| 28 | get_count = read_cntpct_el0(); |
| 29 | wait_time = ((get_count - base_count) * RCAR_CONV_MICROSEC) / freq; |
| 30 | } |
| 31 | } |