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> |
Kever Yang | b04029e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 7 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 8 | #include <asm/arch-rockchip/hardware.h> |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame^] | 9 | #include <asm/arch-rockchip/grf_rk3328.h> |
| 10 | #include <asm/arch-rockchip/uart.h> |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 11 | #include <asm/armv8/mmu.h> |
| 12 | #include <asm/io.h> |
| 13 | |
Kever Yang | c205326 | 2017-06-23 16:11:11 +0800 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame^] | 16 | #define CRU_BASE 0xFF440000 |
| 17 | #define GRF_BASE 0xFF100000 |
| 18 | #define UART2_BASE 0xFF130000 |
| 19 | |
Kever Yang | b04029e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 20 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
| 21 | [BROM_BOOTSOURCE_EMMC] = "rksdmmc@ff520000", |
| 22 | [BROM_BOOTSOURCE_SD] = "rksdmmc@ff500000", |
| 23 | }; |
| 24 | |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 25 | static struct mm_region rk3328_mem_map[] = { |
| 26 | { |
| 27 | .virt = 0x0UL, |
| 28 | .phys = 0x0UL, |
Kever Yang | 6cd0cab | 2017-06-13 21:00:12 +0800 | [diff] [blame] | 29 | .size = 0xff000000UL, |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 30 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 31 | PTE_BLOCK_INNER_SHARE |
| 32 | }, { |
Kever Yang | 6cd0cab | 2017-06-13 21:00:12 +0800 | [diff] [blame] | 33 | .virt = 0xff000000UL, |
| 34 | .phys = 0xff000000UL, |
| 35 | .size = 0x1000000UL, |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 36 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 37 | PTE_BLOCK_NON_SHARE | |
| 38 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 39 | }, { |
| 40 | /* List terminator */ |
| 41 | 0, |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | struct mm_region *mem_map = rk3328_mem_map; |
| 46 | |
Kever Yang | c205326 | 2017-06-23 16:11:11 +0800 | [diff] [blame] | 47 | int dram_init_banksize(void) |
| 48 | { |
| 49 | size_t max_size = min((unsigned long)gd->ram_size, gd->ram_top); |
| 50 | |
| 51 | /* Reserve 0x200000 for ATF bl31 */ |
| 52 | gd->bd->bi_dram[0].start = 0x200000; |
| 53 | gd->bd->bi_dram[0].size = max_size - gd->bd->bi_dram[0].start; |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 58 | int arch_cpu_init(void) |
| 59 | { |
| 60 | /* We do some SoC one time setting here. */ |
| 61 | |
| 62 | return 0; |
| 63 | } |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame^] | 64 | |
| 65 | void board_debug_uart_init(void) |
| 66 | { |
| 67 | struct rk3328_grf_regs * const grf = (void *)GRF_BASE; |
| 68 | struct rk_uart * const uart = (void *)UART2_BASE; |
| 69 | enum{ |
| 70 | GPIO2A0_SEL_SHIFT = 0, |
| 71 | GPIO2A0_SEL_MASK = 3 << GPIO2A0_SEL_SHIFT, |
| 72 | GPIO2A0_UART2_TX_M1 = 1, |
| 73 | |
| 74 | GPIO2A1_SEL_SHIFT = 2, |
| 75 | GPIO2A1_SEL_MASK = 3 << GPIO2A1_SEL_SHIFT, |
| 76 | GPIO2A1_UART2_RX_M1 = 1, |
| 77 | }; |
| 78 | enum { |
| 79 | IOMUX_SEL_UART2_SHIFT = 0, |
| 80 | IOMUX_SEL_UART2_MASK = 3 << IOMUX_SEL_UART2_SHIFT, |
| 81 | IOMUX_SEL_UART2_M0 = 0, |
| 82 | IOMUX_SEL_UART2_M1, |
| 83 | }; |
| 84 | |
| 85 | /* uart_sel_clk default select 24MHz */ |
| 86 | writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148); |
| 87 | |
| 88 | /* init uart baud rate 1500000 */ |
| 89 | writel(0x83, &uart->lcr); |
| 90 | writel(0x1, &uart->rbr); |
| 91 | writel(0x3, &uart->lcr); |
| 92 | |
| 93 | /* Enable early UART2 */ |
| 94 | rk_clrsetreg(&grf->com_iomux, |
| 95 | IOMUX_SEL_UART2_MASK, |
| 96 | IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT); |
| 97 | rk_clrsetreg(&grf->gpio2a_iomux, |
| 98 | GPIO2A0_SEL_MASK, |
| 99 | GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT); |
| 100 | rk_clrsetreg(&grf->gpio2a_iomux, |
| 101 | GPIO2A1_SEL_MASK, |
| 102 | GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT); |
| 103 | |
| 104 | /* enable FIFO */ |
| 105 | writel(0x1, &uart->sfe); |
| 106 | } |