Joseph Chen | 72cd879 | 2021-06-02 15:58:25 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2021 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <asm/armv8/mmu.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch-rockchip/grf_rk3568.h> |
| 11 | #include <asm/arch-rockchip/hardware.h> |
| 12 | #include <dt-bindings/clock/rk3568-cru.h> |
| 13 | |
Nico Cheng | 131e1ab | 2021-10-26 10:42:21 +0800 | [diff] [blame^] | 14 | #define PMUGRF_BASE 0xfdc20000 |
| 15 | #define GRF_BASE 0xfdc60000 |
| 16 | #define GRF_GPIO1B_DS_2 0x218 |
| 17 | #define GRF_GPIO1B_DS_3 0x21c |
| 18 | #define GRF_GPIO1C_DS_0 0x220 |
| 19 | #define GRF_GPIO1C_DS_1 0x224 |
| 20 | #define GRF_GPIO1C_DS_2 0x228 |
| 21 | #define GRF_GPIO1C_DS_3 0x22c |
| 22 | #define SGRF_BASE 0xFDD18000 |
| 23 | #define SGRF_SOC_CON4 0x10 |
| 24 | #define EMMC_HPROT_SECURE_CTRL 0x03 |
| 25 | #define SDMMC0_HPROT_SECURE_CTRL 0x01 |
Joseph Chen | 72cd879 | 2021-06-02 15:58:25 +0800 | [diff] [blame] | 26 | /* PMU_GRF_GPIO0D_IOMUX_L */ |
| 27 | enum { |
| 28 | GPIO0D1_SHIFT = 4, |
| 29 | GPIO0D1_MASK = GENMASK(6, 4), |
| 30 | GPIO0D1_GPIO = 0, |
| 31 | GPIO0D1_UART2_TXM0, |
| 32 | |
| 33 | GPIO0D0_SHIFT = 0, |
| 34 | GPIO0D0_MASK = GENMASK(2, 0), |
| 35 | GPIO0D0_GPIO = 0, |
| 36 | GPIO0D0_UART2_RXM0, |
| 37 | }; |
| 38 | |
| 39 | /* GRF_IOFUNC_SEL3 */ |
| 40 | enum { |
| 41 | UART2_IO_SEL_SHIFT = 10, |
| 42 | UART2_IO_SEL_MASK = GENMASK(11, 10), |
| 43 | UART2_IO_SEL_M0 = 0, |
| 44 | }; |
| 45 | |
| 46 | static struct mm_region rk3568_mem_map[] = { |
| 47 | { |
| 48 | .virt = 0x0UL, |
| 49 | .phys = 0x0UL, |
| 50 | .size = 0xf0000000UL, |
| 51 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 52 | PTE_BLOCK_INNER_SHARE |
| 53 | }, { |
| 54 | .virt = 0xf0000000UL, |
| 55 | .phys = 0xf0000000UL, |
| 56 | .size = 0x10000000UL, |
| 57 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 58 | PTE_BLOCK_NON_SHARE | |
| 59 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 60 | }, { |
| 61 | .virt = 0x300000000, |
| 62 | .phys = 0x300000000, |
| 63 | .size = 0x0c0c00000, |
| 64 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 65 | PTE_BLOCK_NON_SHARE | |
| 66 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 67 | }, { |
| 68 | /* List terminator */ |
| 69 | 0, |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | struct mm_region *mem_map = rk3568_mem_map; |
| 74 | |
| 75 | void board_debug_uart_init(void) |
| 76 | { |
| 77 | static struct rk3568_pmugrf * const pmugrf = (void *)PMUGRF_BASE; |
| 78 | static struct rk3568_grf * const grf = (void *)GRF_BASE; |
| 79 | |
| 80 | /* UART2 M0 */ |
| 81 | rk_clrsetreg(&grf->iofunc_sel3, UART2_IO_SEL_MASK, |
| 82 | UART2_IO_SEL_M0 << UART2_IO_SEL_SHIFT); |
| 83 | |
| 84 | /* Switch iomux */ |
| 85 | rk_clrsetreg(&pmugrf->pmu_gpio0d_iomux_l, |
| 86 | GPIO0D1_MASK | GPIO0D0_MASK, |
| 87 | GPIO0D1_UART2_TXM0 << GPIO0D1_SHIFT | |
| 88 | GPIO0D0_UART2_RXM0 << GPIO0D0_SHIFT); |
| 89 | } |
| 90 | |
| 91 | int arch_cpu_init(void) |
| 92 | { |
Nico Cheng | 131e1ab | 2021-10-26 10:42:21 +0800 | [diff] [blame^] | 93 | #ifdef CONFIG_SPL_BUILD |
| 94 | /* Set the emmc sdmmc0 to secure */ |
| 95 | rk_clrreg(SGRF_BASE + SGRF_SOC_CON4, (EMMC_HPROT_SECURE_CTRL << 11 |
| 96 | | SDMMC0_HPROT_SECURE_CTRL << 4)); |
| 97 | /* set the emmc driver strength to level 2 */ |
| 98 | writel(0x3f3f0707, GRF_BASE + GRF_GPIO1B_DS_2); |
| 99 | writel(0x3f3f0707, GRF_BASE + GRF_GPIO1B_DS_3); |
| 100 | writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_0); |
| 101 | writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_1); |
| 102 | writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_2); |
| 103 | writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_3); |
| 104 | #endif |
Joseph Chen | 72cd879 | 2021-06-02 15:58:25 +0800 | [diff] [blame] | 105 | return 0; |
| 106 | } |