rockchip: back-to-bootrom: replace assembly-implementation with C-code
[platform/kernel/u-boot.git] / arch / arm / mach-rockchip / rk3188-board-tpl.c
1 /*
2  * (C) Copyright 2015 Google, Inc
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <debug_uart.h>
9 #include <spl.h>
10 #include <asm/io.h>
11 #include <asm/arch/bootrom.h>
12 #include <asm/arch/pmu_rk3188.h>
13
14 DECLARE_GLOBAL_DATA_PTR;
15
16 /* track how often we were entered */
17 static int rk3188_num_entries __attribute__ ((section(".data")));
18
19 #define PMU_BASE        0x20004000
20 #define SPL_ENTRY       0x10080C00
21
22 static void jump_to_spl(void)
23 {
24         typedef void __noreturn (*image_entry_noargs_t)(void);
25
26         struct rk3188_pmu * const pmu = (void *)PMU_BASE;
27         image_entry_noargs_t tpl_entry =
28                 (image_entry_noargs_t)(unsigned long)SPL_ENTRY;
29
30         /* Store the SAVE_SP_ADDR in a location shared with SPL. */
31         writel(SAVE_SP_ADDR, &pmu->sys_reg[2]);
32         tpl_entry();
33 }
34
35 void board_init_f(ulong dummy)
36 {
37         /* Example code showing how to enable the debug UART on RK3188 */
38 #ifdef EARLY_UART
39 #include <asm/arch/grf_rk3188.h>
40         /* Enable early UART on the RK3188 */
41 #define GRF_BASE        0x20008000
42         struct rk3188_grf * const grf = (void *)GRF_BASE;
43
44         rk_clrsetreg(&grf->gpio1b_iomux,
45                      GPIO1B1_MASK << GPIO1B1_SHIFT |
46                      GPIO1B0_MASK << GPIO1B0_SHIFT,
47                      GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
48                      GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
49         /*
50          * Debug UART can be used from here if required:
51          *
52          * debug_uart_init();
53          * printch('a');
54          * printhex8(0x1234);
55          * printascii("string");
56          */
57         debug_uart_init();
58
59         printch('t');
60         printch('p');
61         printch('l');
62         printch('-');
63         printch(rk3188_num_entries + 1 + '0');
64         printch('\n');
65 #endif
66
67         rk3188_num_entries++;
68
69         if (rk3188_num_entries == 1) {
70                 /*
71                  * The original loader did some very basic integrity
72                  * checking at this point, but the remaining few bytes
73                  * could be used for any improvement making sense
74                  * really early on.
75                  */
76
77                 back_to_bootrom();
78         } else {
79                 /*
80                  * TPL part of the loader should now wait for us
81                  * at offset 0xC00 in the sram. Should never return
82                  * from there.
83                  */
84                 jump_to_spl();
85         }
86 }