blob: 2aca8baf3ddaabefc928b81100d742dc08bd30c8 [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
79void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
80{
81 debug("image entry point: 0x%lx\n", spl_image->entry_point);
82 if (spl_image->os == IH_OS_ARM_TRUSTED_FIRMWARE) {
83 typedef void (*image_entry_arg_t)(int, int, int, int)
84 __attribute__ ((noreturn));
85 image_entry_arg_t image_entry =
86 (image_entry_arg_t)(uintptr_t) spl_image->entry_point;
87 image_entry(IH_MAGIC, CONFIG_SPL_TEXT_BASE, 0, 0);
88 } else {
89 typedef void __noreturn (*image_entry_noargs_t)(void);
90 image_entry_noargs_t image_entry =
91 (image_entry_noargs_t)spl_image->entry_point;
92 image_entry();
93 }
94}
95
96#define APMU_BASE 0xe6170000U
97#define CL0GRP3_BIT BIT(3)
98#define CL1GRP3_BIT BIT(7)
99#define RTGRP3_BIT BIT(19)
100#define APMU_ACC_ENB_FOR_ARM_CPU (CL0GRP3_BIT | CL1GRP3_BIT | RTGRP3_BIT)
101
102void s_init(void)
103{
104 /* Unlock CPG access */
105 writel(0x5A5AFFFF, CPGWPR);
106 writel(0xA5A50000, CPGWPCR);
107 init_generic_timer();
108
109 /* Define for Work Around of APMU */
110 writel(0x00ff00ff, APMU_BASE + 0x10);
111 writel(0x00ff00ff, APMU_BASE + 0x14);
112 writel(0x00ff00ff, APMU_BASE + 0x18);
113 writel(0x00ff00ff, APMU_BASE + 0x1c);
114 clrbits_le32(APMU_BASE + 0x68, BIT(29));
115}
116
117void reset_cpu(void)
118{
119}