blob: c88257d96772d7cf2eb8d6d3e75086fdcb15d92c [file] [log] [blame]
Hai Pham747a7ab2020-05-21 20:14:05 +07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * board/renesas/falcon/falcon.c
4 * This file is Falcon board support.
5 *
6 * Copyright (C) 2020 Renesas Electronics Corp.
7 */
8
Marek Vasut97a070b2024-02-27 17:05:54 +01009#include <asm/arch/renesas.h>
Hai Pham747a7ab2020-05-21 20:14:05 +070010#include <asm/arch/sys_proto.h>
11#include <asm/global_data.h>
12#include <asm/io.h>
13#include <asm/mach-types.h>
14#include <asm/processor.h>
15#include <linux/errno.h>
Hai Pham89b45d42023-02-28 00:02:18 +010016#include <asm/system.h>
Hai Pham747a7ab2020-05-21 20:14:05 +070017
18DECLARE_GLOBAL_DATA_PTR;
19
20#define CPGWPR 0xE6150000
21#define CPGWPCR 0xE6150004
22
Koji Matsuoka3528c7a2020-07-21 15:21:53 +090023#define EXTAL_CLK 16666600u
24#define CNTCR_BASE 0xE6080000
25#define CNTFID0 (CNTCR_BASE + 0x020)
26#define CNTCR_EN BIT(0)
27
28static void init_generic_timer(void)
29{
30 u32 freq;
31
32 /* Set frequency data in CNTFID0 */
33 freq = EXTAL_CLK;
34
35 /* Update memory mapped and register based freqency */
36 asm volatile ("msr cntfrq_el0, %0" :: "r" (freq));
37 writel(freq, CNTFID0);
38
39 /* Enable counter */
40 setbits_le32(CNTCR_BASE, CNTCR_EN);
41}
42
Koji Matsuoka69b7cc02020-07-16 12:11:16 +090043/* Distributor Registers */
44#define GICD_BASE 0xF1000000
45
46/* ReDistributor Registers for Control and Physical LPIs */
47#define GICR_LPI_BASE 0xF1060000
48#define GICR_WAKER 0x0014
49#define GICR_PWRR 0x0024
50#define GICR_LPI_WAKER (GICR_LPI_BASE + GICR_WAKER)
51#define GICR_LPI_PWRR (GICR_LPI_BASE + GICR_PWRR)
52
53/* ReDistributor Registers for SGIs and PPIs */
54#define GICR_SGI_BASE 0xF1070000
55#define GICR_IGROUPR0 0x0080
56
57static void init_gic_v3(void)
58{
59 /* GIC v3 power on */
60 writel(0x00000002, (GICR_LPI_PWRR));
61
62 /* Wait till the WAKER_CA_BIT changes to 0 */
63 writel(readl(GICR_LPI_WAKER) & ~0x00000002, (GICR_LPI_WAKER));
64 while (readl(GICR_LPI_WAKER) & 0x00000004)
65 ;
66
67 writel(0xffffffff, GICR_SGI_BASE + GICR_IGROUPR0);
68}
69
Koji Matsuoka3528c7a2020-07-21 15:21:53 +090070void s_init(void)
71{
Hai Pham89b45d42023-02-28 00:02:18 +010072 if (current_el() == 3)
73 init_generic_timer();
Koji Matsuoka3528c7a2020-07-21 15:21:53 +090074}
75
Hai Pham747a7ab2020-05-21 20:14:05 +070076int board_early_init_f(void)
77{
78 /* Unlock CPG access */
79 writel(0x5A5AFFFF, CPGWPR);
80 writel(0xA5A50000, CPGWPCR);
81
82 return 0;
83}
84
Hai Pham8872b482023-02-28 00:02:19 +010085#define RST_BASE 0xE6160000 /* Domain0 */
Hai Pham8872b482023-02-28 00:02:19 +010086#define RST_WDTRSTCR (RST_BASE + 0x10)
87#define RST_RWDT 0xA55A8002
88
Hai Pham747a7ab2020-05-21 20:14:05 +070089int board_init(void)
90{
91 /* address of boot parameters */
Simon Glass72cc5382022-10-20 18:22:39 -060092 gd->bd->bi_boot_params = CONFIG_TEXT_BASE + 0x50000;
Hai Pham747a7ab2020-05-21 20:14:05 +070093
Hai Pham8872b482023-02-28 00:02:19 +010094 if (current_el() == 3) {
Hai Pham89b45d42023-02-28 00:02:18 +010095 init_gic_v3();
Koji Matsuoka69b7cc02020-07-16 12:11:16 +090096
Hai Pham8872b482023-02-28 00:02:19 +010097 /* Enable RWDT reset */
98 writel(RST_RWDT, RST_WDTRSTCR);
99 }
100
Hai Pham747a7ab2020-05-21 20:14:05 +0700101 return 0;
102}