aboutsummaryrefslogtreecommitdiff
path: root/drivers/renesas
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@gmail.com>2018-12-26 15:57:08 +0100
committerMarek Vasut <marek.vasut+renesas@gmail.com>2019-01-08 14:08:44 +0100
commitc97c5b5eee07f5192a708779704ec0349526a8c6 (patch)
tree17df5749269973122307b4efa33d1b3b846ab912 /drivers/renesas
parent47141b7396f5d84a8eeaa9e390819b6680ef4123 (diff)
downloadtrusted-firmware-a-c97c5b5eee07f5192a708779704ec0349526a8c6.tar.gz
rcar_gen3: drivers: delay: Rewrite from assembler to C
Rewrite the delay code from assembler to C. Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Diffstat (limited to 'drivers/renesas')
-rw-r--r--drivers/renesas/rcar/delay/micro_delay.S109
-rw-r--r--drivers/renesas/rcar/delay/micro_delay.c30
-rw-r--r--drivers/renesas/rcar/delay/micro_delay.h13
3 files changed, 31 insertions, 121 deletions
diff --git a/drivers/renesas/rcar/delay/micro_delay.S b/drivers/renesas/rcar/delay/micro_delay.S
deleted file mode 100644
index 978973c23f..0000000000
--- a/drivers/renesas/rcar/delay/micro_delay.S
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <arch.h>
-#include <asm_macros.S>
-#include "micro_delay.h"
-
-#define CPG_BASE (0xE6150000)
-#define CPG_SMSTPCR1 (0x0134)
-#define CPG_CPGWPR (0x0900)
-
-/* Module bit for TMU ch3-5 */
-#define MSTPCR1_TMU1 (1 << 24)
-
-#define TMU3_BASE (0xE6FC0000)
-#define TMU_TSTR (0x0004)
-#define TMU_TCOR (0x0008)
-#define TMU_TCNT (0x000C)
-#define TMU_TCR (0x0010)
-/* Start bit for TMU ch3 */
-#define TSTR1_TMU3 (1 << 0)
-
-#define MIDR_CA57 (0x0D07 << MIDR_PN_SHIFT)
-#define MIDR_CA53 (0x0D03 << MIDR_PN_SHIFT)
-
- .globl rcar_micro_delay
-#if (TMU3_MEASUREMENT == 1)
- .globl tmu3_init
- .globl tmu3_start
- .globl tmu3_stop
- .globl tcnt3_snapshot
-#endif
- /* Aligned with the cache line */
- .align 6
-
-func rcar_micro_delay
- cbz x0, micro_delay_e
- mrs x1, midr_el1
- and x1, x1, #MIDR_PN_MASK << MIDR_PN_SHIFT
- mov w2, #MIDR_CA53
- cmp w1, w2
- b.eq micro_delay_ca53
- b micro_delay_ca57
-micro_delay_e:
- ret
-endfunc rcar_micro_delay
-
-func micro_delay_ca57
-ca57_loop_1:
- mov x1, #185
-ca57_loop_2:
- subs x1, x1, #1
- b.ne ca57_loop_2
- subs x0, x0, #1
- b.ne ca57_loop_1
- ret
-endfunc micro_delay_ca57
-
-func micro_delay_ca53
-ca53_loop_1:
- mov x1, #134
-ca53_loop_2:
- subs x1, x1, #1
- b.ne ca53_loop_2
- subs x0, x0, #1
- b.ne ca53_loop_1
- ret
-endfunc micro_delay_ca53
-
-#if (TMU3_MEASUREMENT == 1)
-func tmu3_init
- ldr x2, =CPG_BASE
- ldr w0, [x2, #CPG_SMSTPCR1]
- ldr w1, [x2, #CPG_MSTPSR1]
- ldr w2, #MSTPCR1_TMU1
- bl mstpcr_write
- ret
-endfunc tmu3_init
-
-func tmu3_start
- ldr x0, =TMU3_BASE
- mov w1, #0xFFFFFFFF
- str w1, [x0, TMU_TCNT]
-
- ldr x0, =TMU3_BASE
- ldrb w1, [x0, TMU_TSTR]
- orr w1, w1, #TSTR1_TMU3
- strb w1, [x0, TMU_TSTR]
- ret
-endfunc tmu3_start
-
-func tcnt3_snapshot
- ldr x0, =TMU3_BASE
- ldr w0, [x0, TMU_TCNT]
- ret
-endfunc tcnt3_snapshot
-
-
-func tmu3_stop
- ldr x0, =TMU3_BASE
- ldrb w1, [x0, TMU_TSTR]
- and w1, w1, #~TSTR1_TMU3
- strb w1, [x0, TMU_TSTR]
- ret
-endfunc tmu3_stop
-#endif
diff --git a/drivers/renesas/rcar/delay/micro_delay.c b/drivers/renesas/rcar/delay/micro_delay.c
new file mode 100644
index 0000000000..aced5891a8
--- /dev/null
+++ b/drivers/renesas/rcar/delay/micro_delay.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018, Renesas Electronics Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <arch_helpers.h>
+#include "micro_delay.h"
+
+#define RCAR_CONV_MICROSEC 1000000U
+
+void
+#if IMAGE_BL31
+ __attribute__ ((section (".system_ram")))
+#endif
+ rcar_micro_delay(uint64_t micro_sec)
+{
+ uint64_t freq;
+ uint64_t base_count;
+ uint64_t get_count;
+ uint64_t wait_time = 0U;
+
+ freq = read_cntfrq_el0();
+ base_count = read_cntpct_el0();
+ while (micro_sec > wait_time) {
+ get_count = read_cntpct_el0();
+ wait_time = ((get_count - base_count) * RCAR_CONV_MICROSEC) / freq;
+ }
+}
diff --git a/drivers/renesas/rcar/delay/micro_delay.h b/drivers/renesas/rcar/delay/micro_delay.h
index 4e4b28babc..193daba631 100644
--- a/drivers/renesas/rcar/delay/micro_delay.h
+++ b/drivers/renesas/rcar/delay/micro_delay.h
@@ -7,20 +7,9 @@
#ifndef MICRO_DELAY_H
#define MICRO_DELAY_H
-#define TMU3_MEASUREMENT (0)
-
#ifndef __ASSEMBLY__
#include <stdint.h>
-void rcar_micro_delay(uint32_t count_us);
-
-#if (TMU3_MEASUREMENT == 1)
-void tmu3_start(void);
-void tmu3_init(void);
-void tmu3_stop(void);
-
-uint32_t tcnt3_snapshot(void);
-#endif
-
+void rcar_micro_delay(uint64_t micro_sec);
#endif
#endif /* MICRO_DELAY_H */