1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Google, Inc
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>
19 #include <dt-bindings/clock/rk3288-cru.h>
20 #include <power/regulator.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 __weak int rk_board_late_init(void)
29 int rk3288_qos_init(void)
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);
36 if (!fdt_node_check_compatible(gd->fdt_blob, 0,
37 "rockchip,rk3288-tinker"))
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);
47 static void rk3288_detect_reset_reason(void)
49 struct rk3288_cru *cru = rockchip_get_cru();
55 switch (cru->cru_glb_rst_st) {
63 case FST_GLB_TSADC_RST_ST:
64 case SND_GLB_TSADC_RST_ST:
67 case FST_GLB_WDT_RST_ST:
68 case SND_GLB_WDT_RST_ST:
72 reason = "unknown reset";
75 env_set("reset_reason", reason);
78 * Clear cru_glb_rst_st, so we can determine the last reset cause
79 * for following resets.
81 rk_clrreg(&cru->cru_glb_rst_st, GLB_RST_ST_MASK);
84 int board_late_init(void)
88 rk3288_detect_reset_reason();
90 return rk_board_late_init();
93 #if !CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
94 static int veyron_init(void)
100 ret = regulator_get_by_platname("vdd_arm", &dev);
102 debug("Cannot set regulator name\n");
106 /* Slowly raise to max CPU voltage to prevent overshoot */
107 ret = regulator_set_value(dev, 1200000);
110 udelay(175); /* Must wait for voltage to stabilize, 2mV/us */
111 ret = regulator_set_value(dev, 1400000);
114 udelay(100); /* Must wait for voltage to stabilize, 2mV/us */
116 ret = rockchip_get_clk(&clk.dev);
120 ret = clk_set_rate(&clk, 1800000000);
121 if (IS_ERR_VALUE(ret))
124 ret = regulator_get_by_platname("vcc33_sd", &dev);
126 debug("Cannot get regulator name\n");
130 ret = regulator_set_value(dev, 3300000);
134 ret = regulators_enable_boot_on(false);
136 debug("%s: Cannot enable boot on regulators\n", __func__);
146 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
151 /* We do some SoC one time setting here */
152 if (!fdt_node_check_compatible(gd->fdt_blob, 0, "google,veyron")) {
162 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
163 void enable_caches(void)
165 /* Enable D-cache. I-cache is already enabled in start.S */
170 #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
172 #include <usb/dwc2_udc.h>
174 static struct dwc2_plat_otg_data rk3288_otg_data = {
180 int board_usb_init(int index, enum usb_init_type init)
184 bool matched = false;
185 const void *blob = gd->fdt_blob;
188 /* find the usb_otg node */
189 node = fdt_node_offset_by_compatible(blob, -1,
190 "rockchip,rk3288-usb");
193 mode = fdt_getprop(blob, node, "dr_mode", NULL);
194 if (mode && strcmp(mode, "otg") == 0) {
199 node = fdt_node_offset_by_compatible(blob, node,
200 "rockchip,rk3288-usb");
203 debug("Not found usb_otg device\n");
206 rk3288_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
208 node = fdtdec_lookup_phandle(blob, node, "phys");
210 debug("Not found usb phy device\n");
214 phy_node = fdt_parent_offset(blob, node);
216 debug("Not found usb phy device\n");
220 rk3288_otg_data.phy_of_node = phy_node;
221 grf_phy_offset = fdtdec_get_addr(blob, node, "reg");
223 /* find the grf node */
224 node = fdt_node_offset_by_compatible(blob, -1,
225 "rockchip,rk3288-grf");
227 debug("Not found grf device\n");
230 rk3288_otg_data.regs_phy = grf_phy_offset +
231 fdtdec_get_addr(blob, node, "reg");
233 return dwc2_udc_probe(&rk3288_otg_data);
236 int board_usb_cleanup(int index, enum usb_init_type init)
242 static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc,
245 static const struct {
252 { "cpll", CLK_CODEC },
253 { "gpll", CLK_GENERAL },
254 #ifdef CONFIG_ROCKCHIP_RK3036
263 ret = rockchip_get_clk(&dev);
265 printf("clk-uclass not found\n");
269 for (i = 0; i < ARRAY_SIZE(clks); i++) {
274 ret = clk_request(dev, &clk);
278 rate = clk_get_rate(&clk);
279 printf("%s: %lu\n", clks[i].name, rate);
288 clock, 2, 1, do_clock,
289 "display information about clocks",
293 int board_early_init_f(void)
295 const uintptr_t GRF_SOC_CON0 = 0xff770244;
296 const uintptr_t GRF_SOC_CON2 = 0xff77024c;
301 * This init is done in SPL, but when chain-loading U-Boot SPL will
302 * have been skipped. Allow the clock driver to check if it needs
305 ret = rockchip_get_clk(&dev);
307 debug("CLK init failed: %d\n", ret);
311 rk_setreg(GRF_SOC_CON2, 1 << 0);
314 * Disable JTAG on sdmmc0 IO. The SDMMC won't work until this bit is
317 rk_clrreg(GRF_SOC_CON0, 1 << 12);