blob: e1f9f8b8efe8e7042427e09b618319541e51f179 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yang0d3d7832016-07-19 21:16:59 +08002/*
3 * Copyright (c) 2016 Rockchip Electronics Co., Ltd
Kever Yang0d3d7832016-07-19 21:16:59 +08004 */
5
6#include <common.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +08007#include <spl_gpio.h>
Kever Yang0d3d7832016-07-19 21:16:59 +08008#include <asm/armv8/mmu.h>
Kever Yangf3ea0462016-10-07 15:56:16 +08009#include <asm/io.h>
Philipp Tomsichc3ee4622019-04-29 19:05:26 +020010#include <asm/arch-rockchip/gpio.h>
Kever Yang91379d92019-03-29 09:09:06 +080011#include <asm/arch-rockchip/grf_rk3399.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080012#include <asm/arch-rockchip/hardware.h>
Kever Yangf3ea0462016-10-07 15:56:16 +080013
Kever Yangc2053262017-06-23 16:11:11 +080014DECLARE_GLOBAL_DATA_PTR;
15
Kever Yangf3ea0462016-10-07 15:56:16 +080016#define GRF_EMMCCORE_CON11 0xff77f02c
Kever Yang91379d92019-03-29 09:09:06 +080017#define GRF_BASE 0xff770000
Kever Yang0d3d7832016-07-19 21:16:59 +080018
19static struct mm_region rk3399_mem_map[] = {
20 {
21 .virt = 0x0UL,
22 .phys = 0x0UL,
Kever Yangda77e492017-04-17 16:42:44 +080023 .size = 0xf8000000UL,
Kever Yang0d3d7832016-07-19 21:16:59 +080024 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
25 PTE_BLOCK_INNER_SHARE
26 }, {
Kever Yangda77e492017-04-17 16:42:44 +080027 .virt = 0xf8000000UL,
28 .phys = 0xf8000000UL,
29 .size = 0x08000000UL,
Kever Yang0d3d7832016-07-19 21:16:59 +080030 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
31 PTE_BLOCK_NON_SHARE |
32 PTE_BLOCK_PXN | PTE_BLOCK_UXN
33 }, {
34 /* List terminator */
35 0,
36 }
37};
38
39struct mm_region *mem_map = rk3399_mem_map;
Kever Yangf3ea0462016-10-07 15:56:16 +080040
Kever Yangc2053262017-06-23 16:11:11 +080041int dram_init_banksize(void)
42{
43 size_t max_size = min((unsigned long)gd->ram_size, gd->ram_top);
44
45 /* Reserve 0x200000 for ATF bl31 */
46 gd->bd->bi_dram[0].start = 0x200000;
47 gd->bd->bi_dram[0].size = max_size - gd->bd->bi_dram[0].start;
48
49 return 0;
50}
51
Kever Yangf3ea0462016-10-07 15:56:16 +080052int arch_cpu_init(void)
53{
54 /* We do some SoC one time setting here. */
Kever Yang91379d92019-03-29 09:09:06 +080055 struct rk3399_grf_regs * const grf = (void *)GRF_BASE;
Kever Yangf3ea0462016-10-07 15:56:16 +080056
57 /* Emmc clock generator: disable the clock multipilier */
Kever Yang91379d92019-03-29 09:09:06 +080058 rk_clrreg(&grf->emmccore_con[11], 0x0ff);
Kever Yangf3ea0462016-10-07 15:56:16 +080059
60 return 0;
61}
Kever Yang0f7c8242019-03-29 09:09:07 +080062
63#ifdef CONFIG_DEBUG_UART_BOARD_INIT
64void board_debug_uart_init(void)
65{
66#define GRF_BASE 0xff770000
67#define GPIO0_BASE 0xff720000
68#define PMUGRF_BASE 0xff320000
69 struct rk3399_grf_regs * const grf = (void *)GRF_BASE;
70#ifdef CONFIG_TARGET_CHROMEBOOK_BOB
71 struct rk3399_pmugrf_regs * const pmugrf = (void *)PMUGRF_BASE;
72 struct rockchip_gpio_regs * const gpio = (void *)GPIO0_BASE;
73#endif
74
75#if defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff180000)
76 /* Enable early UART0 on the RK3399 */
77 rk_clrsetreg(&grf->gpio2c_iomux,
78 GRF_GPIO2C0_SEL_MASK,
79 GRF_UART0BT_SIN << GRF_GPIO2C0_SEL_SHIFT);
80 rk_clrsetreg(&grf->gpio2c_iomux,
81 GRF_GPIO2C1_SEL_MASK,
82 GRF_UART0BT_SOUT << GRF_GPIO2C1_SEL_SHIFT);
Christoph Muellnerfca44762019-05-07 10:58:43 +020083#elif defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff1B0000)
84 /* Enable early UART3 on the RK3399 */
85 rk_clrsetreg(&grf->gpio3b_iomux,
86 GRF_GPIO3B6_SEL_MASK,
87 GRF_UART3_SIN << GRF_GPIO3B6_SEL_SHIFT);
88 rk_clrsetreg(&grf->gpio3b_iomux,
89 GRF_GPIO3B7_SEL_MASK,
90 GRF_UART3_SOUT << GRF_GPIO3B7_SEL_SHIFT);
Kever Yang0f7c8242019-03-29 09:09:07 +080091#else
92# ifdef CONFIG_TARGET_CHROMEBOOK_BOB
93 rk_setreg(&grf->io_vsel, 1 << 0);
94
95 /*
96 * Let's enable these power rails here, we are already running the SPI
97 * Flash based code.
98 */
99 spl_gpio_output(gpio, GPIO(BANK_B, 2), 1); /* PP1500_EN */
100 spl_gpio_set_pull(&pmugrf->gpio0_p, GPIO(BANK_B, 2), GPIO_PULL_NORMAL);
101
102 spl_gpio_output(gpio, GPIO(BANK_B, 4), 1); /* PP3000_EN */
103 spl_gpio_set_pull(&pmugrf->gpio0_p, GPIO(BANK_B, 4), GPIO_PULL_NORMAL);
104#endif /* CONFIG_TARGET_CHROMEBOOK_BOB */
105
106 /* Enable early UART2 channel C on the RK3399 */
107 rk_clrsetreg(&grf->gpio4c_iomux,
108 GRF_GPIO4C3_SEL_MASK,
109 GRF_UART2DGBC_SIN << GRF_GPIO4C3_SEL_SHIFT);
110 rk_clrsetreg(&grf->gpio4c_iomux,
111 GRF_GPIO4C4_SEL_MASK,
112 GRF_UART2DBGC_SOUT << GRF_GPIO4C4_SEL_SHIFT);
113 /* Set channel C as UART2 input */
114 rk_clrsetreg(&grf->soc_con7,
115 GRF_UART_DBG_SEL_MASK,
116 GRF_UART_DBG_SEL_C << GRF_UART_DBG_SEL_SHIFT);
117#endif
118}
119#endif