Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Rockchip Electronics Co., Ltd |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 7 | #include <init.h> |
Kever Yang | b04029e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 8 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 9 | #include <asm/arch-rockchip/hardware.h> |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 10 | #include <asm/arch-rockchip/grf_rk3328.h> |
| 11 | #include <asm/arch-rockchip/uart.h> |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 12 | #include <asm/armv8/mmu.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | |
Kever Yang | c205326 | 2017-06-23 16:11:11 +0800 | [diff] [blame] | 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 18 | #define CRU_BASE 0xFF440000 |
| 19 | #define GRF_BASE 0xFF100000 |
| 20 | #define UART2_BASE 0xFF130000 |
Kever Yang | a18a645 | 2019-07-29 12:18:18 +0300 | [diff] [blame] | 21 | #define FW_DDR_CON_REG 0xFF7C0040 |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 22 | |
Kever Yang | b04029e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 23 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
Johan Jonker | f05aa9d | 2022-04-15 23:21:43 +0200 | [diff] [blame] | 24 | [BROM_BOOTSOURCE_EMMC] = "/mmc@ff520000", |
| 25 | [BROM_BOOTSOURCE_SD] = "/mmc@ff500000", |
Kever Yang | b04029e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 26 | }; |
| 27 | |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 28 | static struct mm_region rk3328_mem_map[] = { |
| 29 | { |
| 30 | .virt = 0x0UL, |
| 31 | .phys = 0x0UL, |
Kever Yang | 6cd0cab | 2017-06-13 21:00:12 +0800 | [diff] [blame] | 32 | .size = 0xff000000UL, |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 33 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 34 | PTE_BLOCK_INNER_SHARE |
| 35 | }, { |
Kever Yang | 6cd0cab | 2017-06-13 21:00:12 +0800 | [diff] [blame] | 36 | .virt = 0xff000000UL, |
| 37 | .phys = 0xff000000UL, |
| 38 | .size = 0x1000000UL, |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 39 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 40 | PTE_BLOCK_NON_SHARE | |
| 41 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 42 | }, { |
| 43 | /* List terminator */ |
| 44 | 0, |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | struct mm_region *mem_map = rk3328_mem_map; |
| 49 | |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 50 | int arch_cpu_init(void) |
| 51 | { |
Kever Yang | a18a645 | 2019-07-29 12:18:18 +0300 | [diff] [blame] | 52 | #ifdef CONFIG_SPL_BUILD |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 53 | /* We do some SoC one time setting here. */ |
| 54 | |
Kever Yang | a18a645 | 2019-07-29 12:18:18 +0300 | [diff] [blame] | 55 | /* Disable the ddr secure region setting to make it non-secure */ |
| 56 | rk_setreg(FW_DDR_CON_REG, 0x200); |
| 57 | #endif |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 58 | return 0; |
| 59 | } |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 60 | |
| 61 | void board_debug_uart_init(void) |
| 62 | { |
| 63 | struct rk3328_grf_regs * const grf = (void *)GRF_BASE; |
| 64 | struct rk_uart * const uart = (void *)UART2_BASE; |
| 65 | enum{ |
| 66 | GPIO2A0_SEL_SHIFT = 0, |
| 67 | GPIO2A0_SEL_MASK = 3 << GPIO2A0_SEL_SHIFT, |
| 68 | GPIO2A0_UART2_TX_M1 = 1, |
| 69 | |
| 70 | GPIO2A1_SEL_SHIFT = 2, |
| 71 | GPIO2A1_SEL_MASK = 3 << GPIO2A1_SEL_SHIFT, |
| 72 | GPIO2A1_UART2_RX_M1 = 1, |
| 73 | }; |
| 74 | enum { |
| 75 | IOMUX_SEL_UART2_SHIFT = 0, |
| 76 | IOMUX_SEL_UART2_MASK = 3 << IOMUX_SEL_UART2_SHIFT, |
| 77 | IOMUX_SEL_UART2_M0 = 0, |
| 78 | IOMUX_SEL_UART2_M1, |
| 79 | }; |
| 80 | |
| 81 | /* uart_sel_clk default select 24MHz */ |
| 82 | writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148); |
| 83 | |
| 84 | /* init uart baud rate 1500000 */ |
| 85 | writel(0x83, &uart->lcr); |
| 86 | writel(0x1, &uart->rbr); |
| 87 | writel(0x3, &uart->lcr); |
| 88 | |
| 89 | /* Enable early UART2 */ |
| 90 | rk_clrsetreg(&grf->com_iomux, |
| 91 | IOMUX_SEL_UART2_MASK, |
| 92 | IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT); |
| 93 | rk_clrsetreg(&grf->gpio2a_iomux, |
| 94 | GPIO2A0_SEL_MASK, |
| 95 | GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT); |
| 96 | rk_clrsetreg(&grf->gpio2a_iomux, |
| 97 | GPIO2A1_SEL_MASK, |
| 98 | GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT); |
| 99 | |
| 100 | /* enable FIFO */ |
| 101 | writel(0x1, &uart->sfe); |
| 102 | } |