Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Rockchip Electronics Co., Ltd |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 7 | #include <spl_gpio.h> |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 8 | #include <asm/armv8/mmu.h> |
Kever Yang | f3ea046 | 2016-10-07 15:56:16 +0800 | [diff] [blame] | 9 | #include <asm/io.h> |
Philipp Tomsich | c3ee462 | 2019-04-29 19:05:26 +0200 | [diff] [blame] | 10 | #include <asm/arch-rockchip/gpio.h> |
Kever Yang | 91379d9 | 2019-03-29 09:09:06 +0800 | [diff] [blame] | 11 | #include <asm/arch-rockchip/grf_rk3399.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 12 | #include <asm/arch-rockchip/hardware.h> |
Kever Yang | f3ea046 | 2016-10-07 15:56:16 +0800 | [diff] [blame] | 13 | |
Kever Yang | c205326 | 2017-06-23 16:11:11 +0800 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Kever Yang | f3ea046 | 2016-10-07 15:56:16 +0800 | [diff] [blame] | 16 | #define GRF_EMMCCORE_CON11 0xff77f02c |
Kever Yang | 91379d9 | 2019-03-29 09:09:06 +0800 | [diff] [blame] | 17 | #define GRF_BASE 0xff770000 |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 18 | |
| 19 | static struct mm_region rk3399_mem_map[] = { |
| 20 | { |
| 21 | .virt = 0x0UL, |
| 22 | .phys = 0x0UL, |
Kever Yang | da77e49 | 2017-04-17 16:42:44 +0800 | [diff] [blame] | 23 | .size = 0xf8000000UL, |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 24 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 25 | PTE_BLOCK_INNER_SHARE |
| 26 | }, { |
Kever Yang | da77e49 | 2017-04-17 16:42:44 +0800 | [diff] [blame] | 27 | .virt = 0xf8000000UL, |
| 28 | .phys = 0xf8000000UL, |
| 29 | .size = 0x08000000UL, |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 30 | .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 | |
| 39 | struct mm_region *mem_map = rk3399_mem_map; |
Kever Yang | f3ea046 | 2016-10-07 15:56:16 +0800 | [diff] [blame] | 40 | |
Kever Yang | c205326 | 2017-06-23 16:11:11 +0800 | [diff] [blame] | 41 | int 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 Yang | f3ea046 | 2016-10-07 15:56:16 +0800 | [diff] [blame] | 52 | int arch_cpu_init(void) |
| 53 | { |
| 54 | /* We do some SoC one time setting here. */ |
Kever Yang | 91379d9 | 2019-03-29 09:09:06 +0800 | [diff] [blame] | 55 | struct rk3399_grf_regs * const grf = (void *)GRF_BASE; |
Kever Yang | f3ea046 | 2016-10-07 15:56:16 +0800 | [diff] [blame] | 56 | |
| 57 | /* Emmc clock generator: disable the clock multipilier */ |
Kever Yang | 91379d9 | 2019-03-29 09:09:06 +0800 | [diff] [blame] | 58 | rk_clrreg(&grf->emmccore_con[11], 0x0ff); |
Kever Yang | f3ea046 | 2016-10-07 15:56:16 +0800 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
Kever Yang | 0f7c824 | 2019-03-29 09:09:07 +0800 | [diff] [blame] | 62 | |
| 63 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 64 | void 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 Muellner | fca4476 | 2019-05-07 10:58:43 +0200 | [diff] [blame] | 83 | #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 Yang | 0f7c824 | 2019-03-29 09:09:07 +0800 | [diff] [blame] | 91 | #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 |