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