blob: 1e718f26942925ec280829a875fdaab1c546e7b9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yang168eef72017-06-23 17:17:52 +08002/*
3 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
Kever Yang168eef72017-06-23 17:17:52 +08004 */
5
6#include <common.h>
7#include <debug_uart.h>
8#include <dm.h>
9#include <ram.h>
10#include <spl.h>
11#include <asm/io.h>
12#include <asm/arch/bootrom.h>
13#include <asm/arch/cru_rk322x.h>
14#include <asm/arch/grf_rk322x.h>
15#include <asm/arch/hardware.h>
16#include <asm/arch/timer.h>
17#include <asm/arch/uart.h>
18
19u32 spl_boot_device(void)
20{
21 return BOOT_DEVICE_MMC1;
22}
Kever Yang168eef72017-06-23 17:17:52 +080023#define GRF_BASE 0x11000000
24#define SGRF_BASE 0x10140000
25
26#define DEBUG_UART_BASE 0x11030000
27
28void board_debug_uart_init(void)
29{
David Wu424324d2018-01-13 14:04:26 +080030 static struct rk322x_grf * const grf = (void *)GRF_BASE;
31 enum {
32 GPIO1B2_SHIFT = 4,
33 GPIO1B2_MASK = 3 << GPIO1B2_SHIFT,
34 GPIO1B2_GPIO = 0,
35 GPIO1B2_UART1_SIN,
36 GPIO1B2_UART21_SIN,
37
38 GPIO1B1_SHIFT = 2,
39 GPIO1B1_MASK = 3 << GPIO1B1_SHIFT,
40 GPIO1B1_GPIO = 0,
41 GPIO1B1_UART1_SOUT,
42 GPIO1B1_UART21_SOUT,
43 };
44 enum {
45 CON_IOMUX_UART2SEL_SHIFT= 8,
46 CON_IOMUX_UART2SEL_MASK = 1 << CON_IOMUX_UART2SEL_SHIFT,
47 CON_IOMUX_UART2SEL_2 = 0,
48 CON_IOMUX_UART2SEL_21,
49 };
50
Kever Yang168eef72017-06-23 17:17:52 +080051 /* Enable early UART2 channel 1 on the RK322x */
52 rk_clrsetreg(&grf->gpio1b_iomux,
53 GPIO1B1_MASK | GPIO1B2_MASK,
54 GPIO1B2_UART21_SIN << GPIO1B2_SHIFT |
55 GPIO1B1_UART21_SOUT << GPIO1B1_SHIFT);
56 /* Set channel C as UART2 input */
57 rk_clrsetreg(&grf->con_iomux,
58 CON_IOMUX_UART2SEL_MASK,
59 CON_IOMUX_UART2SEL_21 << CON_IOMUX_UART2SEL_SHIFT);
60}
Kever Yang18d38d32017-07-27 12:53:59 +080061
62#define SGRF_DDR_CON0 0x10150000
Kever Yang168eef72017-06-23 17:17:52 +080063void board_init_f(ulong dummy)
64{
65 struct udevice *dev;
66 int ret;
67
68 /*
69 * Debug UART can be used from here if required:
70 *
71 * debug_uart_init();
72 * printch('a');
73 * printhex8(0x1234);
74 * printascii("string");
75 */
76 debug_uart_init();
77 printascii("SPL Init");
78
79 ret = spl_early_init();
80 if (ret) {
81 debug("spl_early_init() failed: %d\n", ret);
82 hang();
83 }
84
85 rockchip_timer_init();
86 printf("timer init done\n");
87 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
88 if (ret) {
89 printf("DRAM init failed: %d\n", ret);
90 return;
91 }
92
Kever Yang18d38d32017-07-27 12:53:59 +080093 /* Disable the ddr secure region setting to make it non-secure */
94 rk_clrreg(SGRF_DDR_CON0, 0x4000);
Kever Yangcb7116a2018-04-18 12:45:33 +080095#if defined(CONFIG_SPL_ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
Philipp Tomsichb82bd1f2017-10-10 16:21:16 +020096 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Kever Yang168eef72017-06-23 17:17:52 +080097#endif
98}