Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kever Yang | 85a3cfb | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Rockchip Electronics Co., Ltd |
Kever Yang | 85a3cfb | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Kever Yang | 612fd9e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 7 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | 15f09a1 | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 8 | #include <asm/arch-rockchip/hardware.h> |
Kever Yang | 604814c | 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 | 85a3cfb | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 11 | #include <asm/armv8/mmu.h> |
| 12 | #include <asm/io.h> |
| 13 | |
Kever Yang | 975e4ab | 2017-06-23 16:11:11 +0800 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Kever Yang | 604814c | 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 | 612fd9e | 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 | 85a3cfb | 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 | be8da53 | 2017-06-13 21:00:12 +0800 | [diff] [blame] | 29 | .size = 0xff000000UL, |
Kever Yang | 85a3cfb | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 30 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 31 | PTE_BLOCK_INNER_SHARE |
| 32 | }, { |
Kever Yang | be8da53 | 2017-06-13 21:00:12 +0800 | [diff] [blame] | 33 | .virt = 0xff000000UL, |
| 34 | .phys = 0xff000000UL, |
| 35 | .size = 0x1000000UL, |
Kever Yang | 85a3cfb | 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 | 85a3cfb | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 47 | int arch_cpu_init(void) |
| 48 | { |
| 49 | /* We do some SoC one time setting here. */ |
| 50 | |
| 51 | return 0; |
| 52 | } |
Kever Yang | 604814c | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 53 | |
| 54 | void board_debug_uart_init(void) |
| 55 | { |
| 56 | struct rk3328_grf_regs * const grf = (void *)GRF_BASE; |
| 57 | struct rk_uart * const uart = (void *)UART2_BASE; |
| 58 | enum{ |
| 59 | GPIO2A0_SEL_SHIFT = 0, |
| 60 | GPIO2A0_SEL_MASK = 3 << GPIO2A0_SEL_SHIFT, |
| 61 | GPIO2A0_UART2_TX_M1 = 1, |
| 62 | |
| 63 | GPIO2A1_SEL_SHIFT = 2, |
| 64 | GPIO2A1_SEL_MASK = 3 << GPIO2A1_SEL_SHIFT, |
| 65 | GPIO2A1_UART2_RX_M1 = 1, |
| 66 | }; |
| 67 | enum { |
| 68 | IOMUX_SEL_UART2_SHIFT = 0, |
| 69 | IOMUX_SEL_UART2_MASK = 3 << IOMUX_SEL_UART2_SHIFT, |
| 70 | IOMUX_SEL_UART2_M0 = 0, |
| 71 | IOMUX_SEL_UART2_M1, |
| 72 | }; |
| 73 | |
| 74 | /* uart_sel_clk default select 24MHz */ |
| 75 | writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148); |
| 76 | |
| 77 | /* init uart baud rate 1500000 */ |
| 78 | writel(0x83, &uart->lcr); |
| 79 | writel(0x1, &uart->rbr); |
| 80 | writel(0x3, &uart->lcr); |
| 81 | |
| 82 | /* Enable early UART2 */ |
| 83 | rk_clrsetreg(&grf->com_iomux, |
| 84 | IOMUX_SEL_UART2_MASK, |
| 85 | IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT); |
| 86 | rk_clrsetreg(&grf->gpio2a_iomux, |
| 87 | GPIO2A0_SEL_MASK, |
| 88 | GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT); |
| 89 | rk_clrsetreg(&grf->gpio2a_iomux, |
| 90 | GPIO2A1_SEL_MASK, |
| 91 | GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT); |
| 92 | |
| 93 | /* enable FIFO */ |
| 94 | writel(0x1, &uart->sfe); |
| 95 | } |