Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Google, Inc |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 38675c4 | 2016-01-21 19:45:07 -0700 | [diff] [blame] | 7 | #include <clk.h> |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <ram.h> |
Jacob Chen | c95f378 | 2016-09-19 18:46:28 +0800 | [diff] [blame] | 10 | #include <syscon.h> |
huang lin | 1115b64 | 2015-11-17 14:20:27 +0800 | [diff] [blame] | 11 | #include <asm/io.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 12 | #include <asm/arch-rockchip/clock.h> |
| 13 | #include <asm/arch-rockchip/cru_rk3288.h> |
| 14 | #include <asm/arch-rockchip/periph.h> |
| 15 | #include <asm/arch-rockchip/pmu_rk3288.h> |
| 16 | #include <asm/arch-rockchip/qos_rk3288.h> |
| 17 | #include <asm/arch-rockchip/boot_mode.h> |
Xu Ziyuan | 5401eb8 | 2016-07-12 19:09:49 +0800 | [diff] [blame] | 18 | #include <asm/gpio.h> |
Simon Glass | 9293fa4 | 2016-11-13 14:22:14 -0700 | [diff] [blame] | 19 | #include <dt-bindings/clock/rk3288-cru.h> |
| 20 | #include <power/regulator.h> |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Jacob Chen | c95f378 | 2016-09-19 18:46:28 +0800 | [diff] [blame] | 24 | __weak int rk_board_late_init(void) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
Nickey Yang Nickey Yang | 6766d14 | 2016-12-29 10:47:30 +0800 | [diff] [blame] | 29 | int rk3288_qos_init(void) |
| 30 | { |
| 31 | int val = 2 << PRIORITY_HIGH_SHIFT | 2 << PRIORITY_LOW_SHIFT; |
| 32 | /* set vop qos to higher priority */ |
| 33 | writel(val, CPU_AXI_QOS_PRIORITY + VIO0_VOP_QOS); |
| 34 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_VOP_QOS); |
| 35 | |
| 36 | if (!fdt_node_check_compatible(gd->fdt_blob, 0, |
Eddie Cai | 1e1a79f | 2017-01-18 11:03:54 +0800 | [diff] [blame] | 37 | "rockchip,rk3288-tinker")) |
Nickey Yang Nickey Yang | 6766d14 | 2016-12-29 10:47:30 +0800 | [diff] [blame] | 38 | { |
| 39 | /* set isp qos to higher priority */ |
| 40 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_R_QOS); |
| 41 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W0_QOS); |
| 42 | writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W1_QOS); |
| 43 | } |
| 44 | return 0; |
| 45 | } |
| 46 | |
Wadim Egorov | e9eb66c | 2017-08-21 13:36:57 +0200 | [diff] [blame] | 47 | static void rk3288_detect_reset_reason(void) |
| 48 | { |
| 49 | struct rk3288_cru *cru = rockchip_get_cru(); |
| 50 | const char *reason; |
| 51 | |
| 52 | if (IS_ERR(cru)) |
| 53 | return; |
| 54 | |
| 55 | switch (cru->cru_glb_rst_st) { |
| 56 | case GLB_POR_RST: |
| 57 | reason = "POR"; |
| 58 | break; |
| 59 | case FST_GLB_RST_ST: |
| 60 | case SND_GLB_RST_ST: |
| 61 | reason = "RST"; |
| 62 | break; |
| 63 | case FST_GLB_TSADC_RST_ST: |
| 64 | case SND_GLB_TSADC_RST_ST: |
| 65 | reason = "THERMAL"; |
| 66 | break; |
| 67 | case FST_GLB_WDT_RST_ST: |
| 68 | case SND_GLB_WDT_RST_ST: |
| 69 | reason = "WDOG"; |
| 70 | break; |
| 71 | default: |
| 72 | reason = "unknown reset"; |
| 73 | } |
| 74 | |
| 75 | env_set("reset_reason", reason); |
| 76 | |
| 77 | /* |
| 78 | * Clear cru_glb_rst_st, so we can determine the last reset cause |
| 79 | * for following resets. |
| 80 | */ |
| 81 | rk_clrreg(&cru->cru_glb_rst_st, GLB_RST_ST_MASK); |
| 82 | } |
| 83 | |
Jacob Chen | c95f378 | 2016-09-19 18:46:28 +0800 | [diff] [blame] | 84 | int board_late_init(void) |
| 85 | { |
| 86 | setup_boot_mode(); |
Nickey Yang Nickey Yang | 6766d14 | 2016-12-29 10:47:30 +0800 | [diff] [blame] | 87 | rk3288_qos_init(); |
Wadim Egorov | e9eb66c | 2017-08-21 13:36:57 +0200 | [diff] [blame] | 88 | rk3288_detect_reset_reason(); |
Jacob Chen | c95f378 | 2016-09-19 18:46:28 +0800 | [diff] [blame] | 89 | |
| 90 | return rk_board_late_init(); |
| 91 | } |
| 92 | |
Philipp Tomsich | 798370f | 2017-06-29 11:21:15 +0200 | [diff] [blame] | 93 | #if !CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) |
Simon Glass | 9293fa4 | 2016-11-13 14:22:14 -0700 | [diff] [blame] | 94 | static int veyron_init(void) |
| 95 | { |
| 96 | struct udevice *dev; |
| 97 | struct clk clk; |
| 98 | int ret; |
| 99 | |
| 100 | ret = regulator_get_by_platname("vdd_arm", &dev); |
Simon Glass | c4c2ca6 | 2017-05-31 17:57:27 -0600 | [diff] [blame] | 101 | if (ret) { |
| 102 | debug("Cannot set regulator name\n"); |
Simon Glass | 9293fa4 | 2016-11-13 14:22:14 -0700 | [diff] [blame] | 103 | return ret; |
Simon Glass | c4c2ca6 | 2017-05-31 17:57:27 -0600 | [diff] [blame] | 104 | } |
Simon Glass | 9293fa4 | 2016-11-13 14:22:14 -0700 | [diff] [blame] | 105 | |
| 106 | /* Slowly raise to max CPU voltage to prevent overshoot */ |
| 107 | ret = regulator_set_value(dev, 1200000); |
| 108 | if (ret) |
| 109 | return ret; |
| 110 | udelay(175); /* Must wait for voltage to stabilize, 2mV/us */ |
| 111 | ret = regulator_set_value(dev, 1400000); |
| 112 | if (ret) |
| 113 | return ret; |
| 114 | udelay(100); /* Must wait for voltage to stabilize, 2mV/us */ |
| 115 | |
| 116 | ret = rockchip_get_clk(&clk.dev); |
| 117 | if (ret) |
| 118 | return ret; |
| 119 | clk.id = PLL_APLL; |
| 120 | ret = clk_set_rate(&clk, 1800000000); |
| 121 | if (IS_ERR_VALUE(ret)) |
| 122 | return ret; |
| 123 | |
Carlo Caione | 2337063 | 2018-06-11 20:00:50 +0100 | [diff] [blame] | 124 | ret = regulator_get_by_platname("vcc33_sd", &dev); |
| 125 | if (ret) { |
| 126 | debug("Cannot get regulator name\n"); |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | ret = regulator_set_value(dev, 3300000); |
| 131 | if (ret) |
| 132 | return ret; |
| 133 | |
Carlo Caione | b5a119b | 2018-06-11 20:00:48 +0100 | [diff] [blame] | 134 | ret = regulators_enable_boot_on(false); |
| 135 | if (ret) { |
| 136 | debug("%s: Cannot enable boot on regulators\n", __func__); |
| 137 | return ret; |
| 138 | } |
| 139 | |
Simon Glass | 9293fa4 | 2016-11-13 14:22:14 -0700 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | #endif |
| 143 | |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 144 | int board_init(void) |
| 145 | { |
Philipp Tomsich | 798370f | 2017-06-29 11:21:15 +0200 | [diff] [blame] | 146 | #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) |
Xu Ziyuan | 5401eb8 | 2016-07-12 19:09:49 +0800 | [diff] [blame] | 147 | return 0; |
Xu Ziyuan | 5401eb8 | 2016-07-12 19:09:49 +0800 | [diff] [blame] | 148 | #else |
Simon Glass | 9293fa4 | 2016-11-13 14:22:14 -0700 | [diff] [blame] | 149 | int ret; |
| 150 | |
| 151 | /* We do some SoC one time setting here */ |
| 152 | if (!fdt_node_check_compatible(gd->fdt_blob, 0, "google,veyron")) { |
| 153 | ret = veyron_init(); |
| 154 | if (ret) |
| 155 | return ret; |
| 156 | } |
| 157 | |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 158 | return 0; |
Xu Ziyuan | 5401eb8 | 2016-07-12 19:09:49 +0800 | [diff] [blame] | 159 | #endif |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 160 | } |
| 161 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 162 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 163 | void enable_caches(void) |
| 164 | { |
| 165 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 166 | dcache_enable(); |
| 167 | } |
| 168 | #endif |
Simon Glass | e7d7a01 | 2016-01-21 19:45:06 -0700 | [diff] [blame] | 169 | |
Xu Ziyuan | a11a53f | 2016-07-15 00:26:59 +0800 | [diff] [blame] | 170 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
| 171 | #include <usb.h> |
| 172 | #include <usb/dwc2_udc.h> |
| 173 | |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 174 | static struct dwc2_plat_otg_data otg_data = { |
Xu Ziyuan | a11a53f | 2016-07-15 00:26:59 +0800 | [diff] [blame] | 175 | .rx_fifo_sz = 512, |
| 176 | .np_tx_fifo_sz = 16, |
| 177 | .tx_fifo_sz = 128, |
| 178 | }; |
| 179 | |
| 180 | int board_usb_init(int index, enum usb_init_type init) |
| 181 | { |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 182 | int node; |
Xu Ziyuan | a11a53f | 2016-07-15 00:26:59 +0800 | [diff] [blame] | 183 | const char *mode; |
| 184 | bool matched = false; |
| 185 | const void *blob = gd->fdt_blob; |
Xu Ziyuan | a11a53f | 2016-07-15 00:26:59 +0800 | [diff] [blame] | 186 | |
| 187 | /* find the usb_otg node */ |
| 188 | node = fdt_node_offset_by_compatible(blob, -1, |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 189 | "snps,dwc2"); |
Xu Ziyuan | a11a53f | 2016-07-15 00:26:59 +0800 | [diff] [blame] | 190 | |
| 191 | while (node > 0) { |
| 192 | mode = fdt_getprop(blob, node, "dr_mode", NULL); |
| 193 | if (mode && strcmp(mode, "otg") == 0) { |
| 194 | matched = true; |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | node = fdt_node_offset_by_compatible(blob, node, |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 199 | "snps,dwc2"); |
Xu Ziyuan | a11a53f | 2016-07-15 00:26:59 +0800 | [diff] [blame] | 200 | } |
| 201 | if (!matched) { |
| 202 | debug("Not found usb_otg device\n"); |
| 203 | return -ENODEV; |
| 204 | } |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 205 | otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg"); |
Xu Ziyuan | a11a53f | 2016-07-15 00:26:59 +0800 | [diff] [blame] | 206 | |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 207 | return dwc2_udc_probe(&otg_data); |
Xu Ziyuan | a11a53f | 2016-07-15 00:26:59 +0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 211 | { |
| 212 | return 0; |
| 213 | } |
| 214 | #endif |
| 215 | |
Simon Glass | 38675c4 | 2016-01-21 19:45:07 -0700 | [diff] [blame] | 216 | static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc, |
| 217 | char * const argv[]) |
| 218 | { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 219 | static const struct { |
| 220 | char *name; |
| 221 | int id; |
| 222 | } clks[] = { |
| 223 | { "osc", CLK_OSC }, |
| 224 | { "apll", CLK_ARM }, |
| 225 | { "dpll", CLK_DDR }, |
| 226 | { "cpll", CLK_CODEC }, |
| 227 | { "gpll", CLK_GENERAL }, |
| 228 | #ifdef CONFIG_ROCKCHIP_RK3036 |
| 229 | { "mpll", CLK_NEW }, |
| 230 | #else |
| 231 | { "npll", CLK_NEW }, |
| 232 | #endif |
| 233 | }; |
| 234 | int ret, i; |
Simon Glass | 38675c4 | 2016-01-21 19:45:07 -0700 | [diff] [blame] | 235 | struct udevice *dev; |
| 236 | |
Simon Glass | ae8fe41 | 2016-07-17 15:23:17 -0600 | [diff] [blame] | 237 | ret = rockchip_get_clk(&dev); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 238 | if (ret) { |
| 239 | printf("clk-uclass not found\n"); |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | for (i = 0; i < ARRAY_SIZE(clks); i++) { |
| 244 | struct clk clk; |
Simon Glass | 38675c4 | 2016-01-21 19:45:07 -0700 | [diff] [blame] | 245 | ulong rate; |
| 246 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 247 | clk.id = clks[i].id; |
| 248 | ret = clk_request(dev, &clk); |
| 249 | if (ret < 0) |
| 250 | continue; |
| 251 | |
| 252 | rate = clk_get_rate(&clk); |
| 253 | printf("%s: %lu\n", clks[i].name, rate); |
| 254 | |
| 255 | clk_free(&clk); |
Simon Glass | 38675c4 | 2016-01-21 19:45:07 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | U_BOOT_CMD( |
| 262 | clock, 2, 1, do_clock, |
| 263 | "display information about clocks", |
| 264 | "" |
| 265 | ); |
Simon Glass | e608ced | 2017-05-31 17:57:33 -0600 | [diff] [blame] | 266 | |
Simon Glass | e608ced | 2017-05-31 17:57:33 -0600 | [diff] [blame] | 267 | int board_early_init_f(void) |
| 268 | { |
Carlo Caione | cf8d7d1 | 2018-06-11 20:00:49 +0100 | [diff] [blame] | 269 | const uintptr_t GRF_SOC_CON0 = 0xff770244; |
| 270 | const uintptr_t GRF_SOC_CON2 = 0xff77024c; |
Simon Glass | e608ced | 2017-05-31 17:57:33 -0600 | [diff] [blame] | 271 | struct udevice *dev; |
| 272 | int ret; |
| 273 | |
| 274 | /* |
| 275 | * This init is done in SPL, but when chain-loading U-Boot SPL will |
| 276 | * have been skipped. Allow the clock driver to check if it needs |
| 277 | * setting up. |
| 278 | */ |
| 279 | ret = rockchip_get_clk(&dev); |
| 280 | if (ret) { |
| 281 | debug("CLK init failed: %d\n", ret); |
| 282 | return ret; |
| 283 | } |
Simon Glass | e608ced | 2017-05-31 17:57:33 -0600 | [diff] [blame] | 284 | |
Simon Glass | e608ced | 2017-05-31 17:57:33 -0600 | [diff] [blame] | 285 | rk_setreg(GRF_SOC_CON2, 1 << 0); |
| 286 | |
Carlo Caione | cf8d7d1 | 2018-06-11 20:00:49 +0100 | [diff] [blame] | 287 | /* |
| 288 | * Disable JTAG on sdmmc0 IO. The SDMMC won't work until this bit is |
| 289 | * cleared |
| 290 | */ |
| 291 | rk_clrreg(GRF_SOC_CON0, 1 << 12); |
| 292 | |
Simon Glass | e608ced | 2017-05-31 17:57:33 -0600 | [diff] [blame] | 293 | return 0; |
| 294 | } |