blob: e46ef0a3075c79ce43eb032860b6e7f8d5c22618 [file] [log] [blame]
Marek Vasutd1687252024-12-12 14:38:29 +01001// SPDX-License-Identifier: GPL-2.0
2/*
3 * R-Car Gen4 Cortex-R52 SPL
4 *
5 * Copyright (C) 2024 Marek Vasut <marek.vasut+renesas@mailbox.org>
6 */
7
8#include <asm/arch/renesas.h>
9#include <asm/io.h>
10#include <cpu_func.h>
11#include <dm/uclass.h>
12#include <dm/util.h>
13#include <hang.h>
14#include <image.h>
15#include <init.h>
16#include <linux/bitops.h>
17#include <log.h>
18#include <mapmem.h>
19#include <spl.h>
20
21#define CNTCR_EN BIT(0)
22
23#ifdef CONFIG_SPL_BUILD
24void board_debug_uart_init(void)
25{
26}
27#endif
28
29static void init_generic_timer(void)
30{
31 const u32 freq = CONFIG_SYS_CLK_FREQ;
32
33 /* Update memory mapped and register based freqency */
34 if (IS_ENABLED(CONFIG_ARM64))
35 asm volatile("msr cntfrq_el0, %0" :: "r" (freq));
36 else
37 asm volatile("mcr p15, 0, %0, c14, c0, 0" :: "r" (freq));
38
39 writel(freq, CNTFID0);
40
41 /* Enable counter */
42 setbits_le32(CNTCR_BASE, CNTCR_EN);
43}
44
45void board_init_f(ulong dummy)
46{
47 struct udevice *dev;
48 int ret;
49
50 if (CONFIG_IS_ENABLED(OF_CONTROL)) {
51 ret = spl_early_init();
52 if (ret) {
53 debug("spl_early_init() failed: %d\n", ret);
54 hang();
55 }
56 }
57
58 preloader_console_init();
59
60 ret = uclass_get_device_by_name(UCLASS_NOP, "ram@e6780000", &dev);
61 if (ret)
62 printf("DBSC5 init failed: %d\n", ret);
63
64 ret = uclass_get_device_by_name(UCLASS_RAM, "ram@ffec0000", &dev);
65 if (ret)
66 printf("RTVRAM init failed: %d\n", ret);
67};
68
69u32 spl_boot_device(void)
70{
71 return BOOT_DEVICE_SPI;
72}
73
74struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size)
75{
76 return map_sysmem(CONFIG_SYS_LOAD_ADDR + offset, 0);
77}
78
Marek Vasutd1687252024-12-12 14:38:29 +010079#define APMU_BASE 0xe6170000U
80#define CL0GRP3_BIT BIT(3)
81#define CL1GRP3_BIT BIT(7)
82#define RTGRP3_BIT BIT(19)
83#define APMU_ACC_ENB_FOR_ARM_CPU (CL0GRP3_BIT | CL1GRP3_BIT | RTGRP3_BIT)
84
85void s_init(void)
86{
87 /* Unlock CPG access */
88 writel(0x5A5AFFFF, CPGWPR);
89 writel(0xA5A50000, CPGWPCR);
90 init_generic_timer();
91
92 /* Define for Work Around of APMU */
93 writel(0x00ff00ff, APMU_BASE + 0x10);
94 writel(0x00ff00ff, APMU_BASE + 0x14);
95 writel(0x00ff00ff, APMU_BASE + 0x18);
96 writel(0x00ff00ff, APMU_BASE + 0x1c);
97 clrbits_le32(APMU_BASE + 0x68, BIT(29));
98}
99
100void reset_cpu(void)
101{
102}