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> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 6 | #include <command.h> |
Kever Yang | 88a87bc | 2019-07-22 20:02:13 +0800 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 8 | #include <env.h> |
Kever Yang | 88a87bc | 2019-07-22 20:02:13 +0800 | [diff] [blame] | 9 | #include <clk.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Kever Yang | 25c6173 | 2019-07-09 21:58:44 +0800 | [diff] [blame] | 12 | #include <asm/armv7.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 14 | #include <asm/io.h> |
Kever Yang | 8af6caf | 2019-07-22 19:59:30 +0800 | [diff] [blame] | 15 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | 88a87bc | 2019-07-22 20:02:13 +0800 | [diff] [blame] | 16 | #include <asm/arch-rockchip/clock.h> |
Jagan Teki | eab5c50 | 2020-07-21 12:16:38 +0530 | [diff] [blame] | 17 | #include <asm/arch-rockchip/cpu_rk3288.h> |
Jagan Teki | b52a199 | 2020-01-09 14:22:17 +0530 | [diff] [blame] | 18 | #include <asm/arch-rockchip/cru.h> |
Kever Yang | 15f09a1 | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 19 | #include <asm/arch-rockchip/hardware.h> |
Kever Yang | 070e48b | 2019-03-29 09:09:03 +0800 | [diff] [blame] | 20 | #include <asm/arch-rockchip/grf_rk3288.h> |
Kever Yang | f35c417 | 2019-07-22 19:59:26 +0800 | [diff] [blame] | 21 | #include <asm/arch-rockchip/pmu_rk3288.h> |
Kever Yang | 1e7d2be | 2019-07-22 20:02:10 +0800 | [diff] [blame] | 22 | #include <asm/arch-rockchip/qos_rk3288.h> |
Kever Yang | 5d19ddf | 2019-11-15 11:04:33 +0800 | [diff] [blame] | 23 | #include <asm/arch-rockchip/sdram.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 24 | #include <linux/err.h> |
Kever Yang | f35c417 | 2019-07-22 19:59:26 +0800 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 27 | |
Kever Yang | 070e48b | 2019-03-29 09:09:03 +0800 | [diff] [blame] | 28 | #define GRF_BASE 0xff770000 |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 29 | |
Kever Yang | 8af6caf | 2019-07-22 19:59:30 +0800 | [diff] [blame] | 30 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
Levin Du | 2d86ab5 | 2019-10-17 15:22:38 +0800 | [diff] [blame] | 31 | [BROM_BOOTSOURCE_EMMC] = "/dwmmc@ff0f0000", |
| 32 | [BROM_BOOTSOURCE_SD] = "/dwmmc@ff0c0000", |
Kever Yang | 8af6caf | 2019-07-22 19:59:30 +0800 | [diff] [blame] | 33 | }; |
| 34 | |
Kever Yang | 25c6173 | 2019-07-09 21:58:44 +0800 | [diff] [blame] | 35 | #ifdef CONFIG_SPL_BUILD |
| 36 | static void configure_l2ctlr(void) |
| 37 | { |
| 38 | u32 l2ctlr; |
| 39 | |
| 40 | l2ctlr = read_l2ctlr(); |
| 41 | l2ctlr &= 0xfffc0000; /* clear bit0~bit17 */ |
| 42 | |
| 43 | /* |
| 44 | * Data RAM write latency: 2 cycles |
| 45 | * Data RAM read latency: 2 cycles |
| 46 | * Data RAM setup latency: 1 cycle |
| 47 | * Tag RAM write latency: 1 cycle |
| 48 | * Tag RAM read latency: 1 cycle |
| 49 | * Tag RAM setup latency: 1 cycle |
| 50 | */ |
| 51 | l2ctlr |= (1 << 3 | 1 << 0); |
| 52 | write_l2ctlr(l2ctlr); |
| 53 | } |
| 54 | #endif |
| 55 | |
Kever Yang | 1e7d2be | 2019-07-22 20:02:10 +0800 | [diff] [blame] | 56 | int rk3288_qos_init(void) |
| 57 | { |
| 58 | int val = 2 << PRIORITY_HIGH_SHIFT | 2 << PRIORITY_LOW_SHIFT; |
| 59 | /* set vop qos to higher priority */ |
| 60 | writel(val, CPU_AXI_QOS_PRIORITY + VIO0_VOP_QOS); |
| 61 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_VOP_QOS); |
| 62 | |
| 63 | if (!fdt_node_check_compatible(gd->fdt_blob, 0, |
| 64 | "rockchip,rk3288-tinker")) { |
| 65 | /* set isp qos to higher priority */ |
| 66 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_R_QOS); |
| 67 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W0_QOS); |
| 68 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W1_QOS); |
| 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 74 | int arch_cpu_init(void) |
| 75 | { |
Kever Yang | ccab9e7 | 2019-07-09 21:58:43 +0800 | [diff] [blame] | 76 | #ifdef CONFIG_SPL_BUILD |
| 77 | configure_l2ctlr(); |
| 78 | #else |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 79 | /* We do some SoC one time setting here. */ |
Kever Yang | 070e48b | 2019-03-29 09:09:03 +0800 | [diff] [blame] | 80 | struct rk3288_grf * const grf = (void *)GRF_BASE; |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 81 | |
| 82 | /* Use rkpwm by default */ |
Kever Yang | 070e48b | 2019-03-29 09:09:03 +0800 | [diff] [blame] | 83 | rk_setreg(&grf->soc_con2, 1 << 0); |
Kever Yang | 1e7d2be | 2019-07-22 20:02:10 +0800 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * Disable JTAG on sdmmc0 IO. The SDMMC won't work until this bit is |
| 87 | * cleared |
| 88 | */ |
| 89 | rk_clrreg(&grf->soc_con0, 1 << 12); |
| 90 | |
| 91 | rk3288_qos_init(); |
Kever Yang | ccab9e7 | 2019-07-09 21:58:43 +0800 | [diff] [blame] | 92 | #endif |
Kever Yang | aa89b55 | 2016-08-12 17:58:12 +0800 | [diff] [blame] | 93 | |
| 94 | return 0; |
| 95 | } |
Kever Yang | e83e885 | 2019-03-29 09:09:04 +0800 | [diff] [blame] | 96 | |
| 97 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 98 | void board_debug_uart_init(void) |
| 99 | { |
| 100 | /* Enable early UART on the RK3288 */ |
| 101 | struct rk3288_grf * const grf = (void *)GRF_BASE; |
| 102 | |
| 103 | rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT | |
| 104 | GPIO7C6_MASK << GPIO7C6_SHIFT, |
| 105 | GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT | |
| 106 | GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT); |
| 107 | } |
| 108 | #endif |
Kever Yang | 88a87bc | 2019-07-22 20:02:13 +0800 | [diff] [blame] | 109 | |
Kever Yang | 271318a | 2019-07-22 20:02:14 +0800 | [diff] [blame] | 110 | __weak int rk3288_board_late_init(void) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | int rk_board_late_init(void) |
| 116 | { |
Kever Yang | 271318a | 2019-07-22 20:02:14 +0800 | [diff] [blame] | 117 | return rk3288_board_late_init(); |
| 118 | } |
| 119 | |
Jagan Teki | eab5c50 | 2020-07-21 12:16:38 +0530 | [diff] [blame] | 120 | static int ft_rk3288w_setup(void *blob) |
| 121 | { |
| 122 | const char *path; |
| 123 | int offs, ret; |
| 124 | |
| 125 | path = "/clock-controller@ff760000"; |
| 126 | offs = fdt_path_offset(blob, path); |
| 127 | if (offs < 0) { |
| 128 | debug("failed to found fdt path %s\n", path); |
| 129 | return offs; |
| 130 | } |
| 131 | |
| 132 | ret = fdt_setprop_string(blob, offs, "compatible", "rockchip,rk3288w-cru"); |
| 133 | if (ret) { |
| 134 | printf("failed to set rk3288w-cru compatible (ret=%d)\n", ret); |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 142 | { |
| 143 | if (soc_is_rk3288w()) |
| 144 | return ft_rk3288w_setup(blob); |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 149 | static int do_clock(struct cmd_tbl *cmdtp, int flag, int argc, |
| 150 | char *const argv[]) |
Kever Yang | 88a87bc | 2019-07-22 20:02:13 +0800 | [diff] [blame] | 151 | { |
| 152 | static const struct { |
| 153 | char *name; |
| 154 | int id; |
| 155 | } clks[] = { |
| 156 | { "osc", CLK_OSC }, |
| 157 | { "apll", CLK_ARM }, |
| 158 | { "dpll", CLK_DDR }, |
| 159 | { "cpll", CLK_CODEC }, |
| 160 | { "gpll", CLK_GENERAL }, |
| 161 | #ifdef CONFIG_ROCKCHIP_RK3036 |
| 162 | { "mpll", CLK_NEW }, |
| 163 | #else |
| 164 | { "npll", CLK_NEW }, |
| 165 | #endif |
| 166 | }; |
| 167 | int ret, i; |
| 168 | struct udevice *dev; |
| 169 | |
| 170 | ret = rockchip_get_clk(&dev); |
| 171 | if (ret) { |
| 172 | printf("clk-uclass not found\n"); |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | for (i = 0; i < ARRAY_SIZE(clks); i++) { |
| 177 | struct clk clk; |
| 178 | ulong rate; |
| 179 | |
| 180 | clk.id = clks[i].id; |
| 181 | ret = clk_request(dev, &clk); |
| 182 | if (ret < 0) |
| 183 | continue; |
| 184 | |
| 185 | rate = clk_get_rate(&clk); |
| 186 | printf("%s: %lu\n", clks[i].name, rate); |
| 187 | |
| 188 | clk_free(&clk); |
| 189 | } |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | U_BOOT_CMD( |
| 195 | clock, 2, 1, do_clock, |
| 196 | "display information about clocks", |
| 197 | "" |
| 198 | ); |