blob: 36a51bc419043bcbf8aa434e105e8847977341a8 [file] [log] [blame]
Hai Phamff3812c2023-02-28 22:37:08 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
Marek Vasut10a37c82024-12-12 14:37:34 +01003 * board/renesas/rcar-common/gen4-common.c
Hai Phamff3812c2023-02-28 22:37:08 +01004 *
Marek Vasut10a37c82024-12-12 14:37:34 +01005 * Copyright (C) 2021-2024 Renesas Electronics Corp.
Hai Phamff3812c2023-02-28 22:37:08 +01006 */
7
Marek Vasut97a070b2024-02-27 17:05:54 +01008#include <asm/arch/renesas.h>
Hai Phamff3812c2023-02-28 22:37:08 +01009#include <asm/arch/sys_proto.h>
10#include <asm/global_data.h>
11#include <asm/io.h>
12#include <asm/mach-types.h>
13#include <asm/processor.h>
Hai Phamff3812c2023-02-28 22:37:08 +010014#include <asm/system.h>
Marek Vasut10a37c82024-12-12 14:37:34 +010015#include <linux/errno.h>
16
17#define RST_BASE 0xE6160000 /* Domain0 */
18#define RST_WDTRSTCR (RST_BASE + 0x10)
19#define RST_RWDT 0xA55A8002
Hai Phamff3812c2023-02-28 22:37:08 +010020
21DECLARE_GLOBAL_DATA_PTR;
22
23static void init_generic_timer(void)
24{
25 const u32 freq = CONFIG_SYS_CLK_FREQ;
26
27 /* Update memory mapped and register based freqency */
28 asm volatile ("msr cntfrq_el0, %0" :: "r" (freq));
29 writel(freq, CNTFID0);
30
31 /* Enable counter */
32 setbits_le32(CNTCR_BASE, CNTCR_EN);
33}
34
35static void init_gic_v3(void)
36{
Marek Vasut00eed1e2024-01-21 18:33:12 +010037 /* GIC v3 power on */
Hai Phamff3812c2023-02-28 22:37:08 +010038 writel(BIT(1), GICR_LPI_PWRR);
39
40 /* Wait till the WAKER_CA_BIT changes to 0 */
41 clrbits_le32(GICR_LPI_WAKER, BIT(1));
42 while (readl(GICR_LPI_WAKER) & BIT(2))
43 ;
44
45 writel(0xffffffff, GICR_SGI_BASE + GICR_IGROUPR0);
46}
47
48void s_init(void)
49{
50 if (current_el() == 3)
51 init_generic_timer();
52}
53
54int board_early_init_f(void)
55{
56 /* Unlock CPG access */
57 writel(0x5A5AFFFF, CPGWPR);
58 writel(0xA5A50000, CPGWPCR);
59
60 return 0;
61}
62
63int board_init(void)
64{
Marek Vasut10a37c82024-12-12 14:37:34 +010065 if (current_el() != 3)
66 return 0;
67 init_gic_v3();
68
69 /* Enable RWDT reset on V3U in EL3 */
70 if (IS_ENABLED(CONFIG_R8A779A0) &&
71 renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A779A0) {
72 writel(RST_RWDT, RST_WDTRSTCR);
73 }
Hai Phamff3812c2023-02-28 22:37:08 +010074
75 return 0;
76}