blob: a5e2a692851d9f6597c6e63ff2226f79f915d6ce [file] [log] [blame]
Marek Vasut1778b412018-12-26 15:57:08 +01001/*
Biju Das68e68c62020-12-13 19:59:26 +00002 * Copyright (c) 2018-2020, Renesas Electronics Corporation. All rights reserved.
Marek Vasut1778b412018-12-26 15:57:08 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <arch_helpers.h>
Biju Das68e68c62020-12-13 19:59:26 +00009
Marek Vasut1778b412018-12-26 15:57:08 +010010#include "micro_delay.h"
11
12#define RCAR_CONV_MICROSEC 1000000U
13
14void
15#if IMAGE_BL31
Biju Das68e68c62020-12-13 19:59:26 +000016 __attribute__ ((section(".system_ram")))
Marek Vasut1778b412018-12-26 15:57:08 +010017#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}