Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Rockchip Electronics Co., Ltd |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 4 | */ |
Kever Yang | 1e7d2be | 2019-07-22 20:02:10 +0800 | [diff] [blame] | 5 | #include <common.h> |
Kever Yang | 88a87bc | 2019-07-22 20:02:13 +0800 | [diff] [blame^] | 6 | #include <dm.h> |
| 7 | #include <clk.h> |
Kever Yang | 25c6173 | 2019-07-09 21:58:44 +0800 | [diff] [blame] | 8 | #include <asm/armv7.h> |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 9 | #include <asm/io.h> |
Kever Yang | 8af6caf | 2019-07-22 19:59:30 +0800 | [diff] [blame] | 10 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | 88a87bc | 2019-07-22 20:02:13 +0800 | [diff] [blame^] | 11 | #include <asm/arch-rockchip/clock.h> |
| 12 | #include <asm/arch-rockchip/cru_rk3288.h> |
Kever Yang | 15f09a1 | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 13 | #include <asm/arch-rockchip/hardware.h> |
Kever Yang | 070e48b | 2019-03-29 09:09:03 +0800 | [diff] [blame] | 14 | #include <asm/arch-rockchip/grf_rk3288.h> |
Kever Yang | f35c417 | 2019-07-22 19:59:26 +0800 | [diff] [blame] | 15 | #include <asm/arch-rockchip/pmu_rk3288.h> |
Kever Yang | 1e7d2be | 2019-07-22 20:02:10 +0800 | [diff] [blame] | 16 | #include <asm/arch-rockchip/qos_rk3288.h> |
Kever Yang | f35c417 | 2019-07-22 19:59:26 +0800 | [diff] [blame] | 17 | #include <asm/arch-rockchip/sdram_common.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 20 | |
Kever Yang | 070e48b | 2019-03-29 09:09:03 +0800 | [diff] [blame] | 21 | #define GRF_BASE 0xff770000 |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 22 | |
Kever Yang | 8af6caf | 2019-07-22 19:59:30 +0800 | [diff] [blame] | 23 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
| 24 | [BROM_BOOTSOURCE_EMMC] = "dwmmc@ff0f0000", |
| 25 | [BROM_BOOTSOURCE_SD] = "dwmmc@ff0c0000", |
| 26 | }; |
| 27 | |
Kever Yang | 25c6173 | 2019-07-09 21:58:44 +0800 | [diff] [blame] | 28 | #ifdef CONFIG_SPL_BUILD |
| 29 | static void configure_l2ctlr(void) |
| 30 | { |
| 31 | u32 l2ctlr; |
| 32 | |
| 33 | l2ctlr = read_l2ctlr(); |
| 34 | l2ctlr &= 0xfffc0000; /* clear bit0~bit17 */ |
| 35 | |
| 36 | /* |
| 37 | * Data RAM write latency: 2 cycles |
| 38 | * Data RAM read latency: 2 cycles |
| 39 | * Data RAM setup latency: 1 cycle |
| 40 | * Tag RAM write latency: 1 cycle |
| 41 | * Tag RAM read latency: 1 cycle |
| 42 | * Tag RAM setup latency: 1 cycle |
| 43 | */ |
| 44 | l2ctlr |= (1 << 3 | 1 << 0); |
| 45 | write_l2ctlr(l2ctlr); |
| 46 | } |
| 47 | #endif |
| 48 | |
Kever Yang | 1e7d2be | 2019-07-22 20:02:10 +0800 | [diff] [blame] | 49 | int rk3288_qos_init(void) |
| 50 | { |
| 51 | int val = 2 << PRIORITY_HIGH_SHIFT | 2 << PRIORITY_LOW_SHIFT; |
| 52 | /* set vop qos to higher priority */ |
| 53 | writel(val, CPU_AXI_QOS_PRIORITY + VIO0_VOP_QOS); |
| 54 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_VOP_QOS); |
| 55 | |
| 56 | if (!fdt_node_check_compatible(gd->fdt_blob, 0, |
| 57 | "rockchip,rk3288-tinker")) { |
| 58 | /* set isp qos to higher priority */ |
| 59 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_R_QOS); |
| 60 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W0_QOS); |
| 61 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W1_QOS); |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 67 | int arch_cpu_init(void) |
| 68 | { |
Kever Yang | ccab9e7 | 2019-07-09 21:58:43 +0800 | [diff] [blame] | 69 | #ifdef CONFIG_SPL_BUILD |
| 70 | configure_l2ctlr(); |
| 71 | #else |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 72 | /* We do some SoC one time setting here. */ |
Kever Yang | 070e48b | 2019-03-29 09:09:03 +0800 | [diff] [blame] | 73 | struct rk3288_grf * const grf = (void *)GRF_BASE; |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 74 | |
| 75 | /* Use rkpwm by default */ |
Kever Yang | 070e48b | 2019-03-29 09:09:03 +0800 | [diff] [blame] | 76 | rk_setreg(&grf->soc_con2, 1 << 0); |
Kever Yang | 1e7d2be | 2019-07-22 20:02:10 +0800 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Disable JTAG on sdmmc0 IO. The SDMMC won't work until this bit is |
| 80 | * cleared |
| 81 | */ |
| 82 | rk_clrreg(&grf->soc_con0, 1 << 12); |
| 83 | |
| 84 | rk3288_qos_init(); |
Kever Yang | ccab9e7 | 2019-07-09 21:58:43 +0800 | [diff] [blame] | 85 | #endif |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
Kever Yang | e83e885 | 2019-03-29 09:09:04 +0800 | [diff] [blame] | 89 | |
| 90 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 91 | void board_debug_uart_init(void) |
| 92 | { |
| 93 | /* Enable early UART on the RK3288 */ |
| 94 | struct rk3288_grf * const grf = (void *)GRF_BASE; |
| 95 | |
| 96 | rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT | |
| 97 | GPIO7C6_MASK << GPIO7C6_SHIFT, |
| 98 | GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT | |
| 99 | GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT); |
| 100 | } |
| 101 | #endif |
Kever Yang | 88a87bc | 2019-07-22 20:02:13 +0800 | [diff] [blame^] | 102 | |
| 103 | static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc, |
| 104 | char * const argv[]) |
| 105 | { |
| 106 | static const struct { |
| 107 | char *name; |
| 108 | int id; |
| 109 | } clks[] = { |
| 110 | { "osc", CLK_OSC }, |
| 111 | { "apll", CLK_ARM }, |
| 112 | { "dpll", CLK_DDR }, |
| 113 | { "cpll", CLK_CODEC }, |
| 114 | { "gpll", CLK_GENERAL }, |
| 115 | #ifdef CONFIG_ROCKCHIP_RK3036 |
| 116 | { "mpll", CLK_NEW }, |
| 117 | #else |
| 118 | { "npll", CLK_NEW }, |
| 119 | #endif |
| 120 | }; |
| 121 | int ret, i; |
| 122 | struct udevice *dev; |
| 123 | |
| 124 | ret = rockchip_get_clk(&dev); |
| 125 | if (ret) { |
| 126 | printf("clk-uclass not found\n"); |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | for (i = 0; i < ARRAY_SIZE(clks); i++) { |
| 131 | struct clk clk; |
| 132 | ulong rate; |
| 133 | |
| 134 | clk.id = clks[i].id; |
| 135 | ret = clk_request(dev, &clk); |
| 136 | if (ret < 0) |
| 137 | continue; |
| 138 | |
| 139 | rate = clk_get_rate(&clk); |
| 140 | printf("%s: %lu\n", clks[i].name, rate); |
| 141 | |
| 142 | clk_free(&clk); |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | U_BOOT_CMD( |
| 149 | clock, 2, 1, do_clock, |
| 150 | "display information about clocks", |
| 151 | "" |
| 152 | ); |