common: Drop log.h from common header
[oweals/u-boot.git] / arch / arm / mach-rockchip / spl.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4  */
5
6 #include <common.h>
7 #include <debug_uart.h>
8 #include <dm.h>
9 #include <hang.h>
10 #include <image.h>
11 #include <init.h>
12 #include <log.h>
13 #include <ram.h>
14 #include <spl.h>
15 #include <asm/arch-rockchip/bootrom.h>
16 #include <asm/io.h>
17
18 DECLARE_GLOBAL_DATA_PTR;
19
20 int board_return_to_bootrom(struct spl_image_info *spl_image,
21                             struct spl_boot_device *bootdev)
22 {
23         back_to_bootrom(BROM_BOOT_NEXTSTAGE);
24
25         return 0;
26 }
27
28 __weak const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
29 };
30
31 const char *board_spl_was_booted_from(void)
32 {
33         u32  bootdevice_brom_id = readl(BROM_BOOTSOURCE_ID_ADDR);
34         const char *bootdevice_ofpath = NULL;
35
36         if (bootdevice_brom_id < ARRAY_SIZE(boot_devices))
37                 bootdevice_ofpath = boot_devices[bootdevice_brom_id];
38
39         if (bootdevice_ofpath)
40                 debug("%s: brom_bootdevice_id %x maps to '%s'\n",
41                       __func__, bootdevice_brom_id, bootdevice_ofpath);
42         else
43                 debug("%s: failed to resolve brom_bootdevice_id %x\n",
44                       __func__, bootdevice_brom_id);
45
46         return bootdevice_ofpath;
47 }
48
49 u32 spl_boot_device(void)
50 {
51         u32 boot_device = BOOT_DEVICE_MMC1;
52
53 #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
54                 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
55                 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE)
56         return BOOT_DEVICE_SPI;
57 #endif
58         if (CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM))
59                 return BOOT_DEVICE_BOOTROM;
60
61         return boot_device;
62 }
63
64 u32 spl_mmc_boot_mode(const u32 boot_device)
65 {
66         return MMCSD_MODE_RAW;
67 }
68
69 #if !defined(CONFIG_ROCKCHIP_RK3188)
70 #define TIMER_LOAD_COUNT_L      0x00
71 #define TIMER_LOAD_COUNT_H      0x04
72 #define TIMER_CONTROL_REG       0x10
73 #define TIMER_EN        0x1
74 #define TIMER_FMODE     BIT(0)
75 #define TIMER_RMODE     BIT(1)
76
77 __weak void rockchip_stimer_init(void)
78 {
79         /* If Timer already enabled, don't re-init it */
80         u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
81
82         if (reg & TIMER_EN)
83                 return;
84 #ifndef CONFIG_ARM64
85         asm volatile("mcr p15, 0, %0, c14, c0, 0"
86                      : : "r"(COUNTER_FREQUENCY));
87 #endif
88         writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
89         writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
90         writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
91         writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
92                TIMER_CONTROL_REG);
93 }
94 #endif
95
96 __weak int board_early_init_f(void)
97 {
98         return 0;
99 }
100
101 __weak int arch_cpu_init(void)
102 {
103         return 0;
104 }
105
106 void board_init_f(ulong dummy)
107 {
108         int ret;
109 #if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT)
110         struct udevice *dev;
111 #endif
112
113 #ifdef CONFIG_DEBUG_UART
114         /*
115          * Debug UART can be used from here if required:
116          *
117          * debug_uart_init();
118          * printch('a');
119          * printhex8(0x1234);
120          * printascii("string");
121          */
122         debug_uart_init();
123         debug("\nspl:debug uart enabled in %s\n", __func__);
124 #endif
125
126         board_early_init_f();
127
128         ret = spl_early_init();
129         if (ret) {
130                 printf("spl_early_init() failed: %d\n", ret);
131                 hang();
132         }
133         arch_cpu_init();
134 #if !defined(CONFIG_ROCKCHIP_RK3188)
135         rockchip_stimer_init();
136 #endif
137 #ifdef CONFIG_SYS_ARCH_TIMER
138         /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
139         timer_init();
140 #endif
141 #if !defined(CONFIG_TPL) || defined(CONFIG_SPL_OS_BOOT)
142         debug("\nspl:init dram\n");
143         ret = uclass_get_device(UCLASS_RAM, 0, &dev);
144         if (ret) {
145                 printf("DRAM init failed: %d\n", ret);
146                 return;
147         }
148 #endif
149         preloader_console_init();
150 }
151
152 #ifdef CONFIG_SPL_LOAD_FIT
153 int __weak board_fit_config_name_match(const char *name)
154 {
155         /* Just empty function now - can't decide what to choose */
156         debug("%s: %s\n", __func__, name);
157
158         return 0;
159 }
160 #endif