blob: 0945829d0e495ff2a31c7ee98be1de5f43d7ae91 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yangaa827752017-11-28 16:04:16 +08002/*
3 * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
Kever Yangaa827752017-11-28 16:04:16 +08004 */
5#include <common.h>
6#include <clk.h>
7#include <dm.h>
8#include <ram.h>
9#include <syscon.h>
10#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080011#include <asm/arch-rockchip/clock.h>
12#include <asm/arch-rockchip/periph.h>
13#include <asm/arch-rockchip/grf_rk3128.h>
14#include <asm/arch-rockchip/boot_mode.h>
Kever Yangaa827752017-11-28 16:04:16 +080015#include <power/regulator.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
19__weak int rk_board_late_init(void)
20{
21 return 0;
22}
23
24int board_late_init(void)
25{
26 setup_boot_mode();
27
28 return rk_board_late_init();
29}
30
31int board_init(void)
32{
33 int ret = 0;
34
Kever Yangaa827752017-11-28 16:04:16 +080035 ret = regulators_enable_boot_on(false);
36 if (ret) {
37 debug("%s: Cannot enable boot on regulator\n", __func__);
38 return ret;
39 }
40
41 return 0;
42}
43
44int dram_init_banksize(void)
45{
46 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
47 gd->bd->bi_dram[0].size = 0x8400000;
48 /* Reserve 0xe00000(14MB) for OPTEE with TA enabled, otherwise 2MB */
49 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE
50 + gd->bd->bi_dram[0].size + 0xe00000;
51 gd->bd->bi_dram[1].size = gd->bd->bi_dram[0].start
52 + gd->ram_size - gd->bd->bi_dram[1].start;
53
54 return 0;
55}
56
Trevor Woerner43ec7e02019-05-03 09:41:00 -040057#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Kever Yangaa827752017-11-28 16:04:16 +080058void enable_caches(void)
59{
60 /* Enable D-cache. I-cache is already enabled in start.S */
61 dcache_enable();
62}
63#endif
64
65#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
66#include <usb.h>
67#include <usb/dwc2_udc.h>
68
69static struct dwc2_plat_otg_data rk3128_otg_data = {
70 .rx_fifo_sz = 512,
71 .np_tx_fifo_sz = 16,
72 .tx_fifo_sz = 128,
73};
74
75int board_usb_init(int index, enum usb_init_type init)
76{
77 int node;
78 const char *mode;
79 bool matched = false;
80 const void *blob = gd->fdt_blob;
81
82 /* find the usb_otg node */
83 node = fdt_node_offset_by_compatible(blob, -1,
84 "rockchip,rk3128-usb");
85
86 while (node > 0) {
87 mode = fdt_getprop(blob, node, "dr_mode", NULL);
88 if (mode && strcmp(mode, "otg") == 0) {
89 matched = true;
90 break;
91 }
92
93 node = fdt_node_offset_by_compatible(blob, node,
94 "rockchip,rk3128-usb");
95 }
96 if (!matched) {
97 debug("Not found usb_otg device\n");
98 return -ENODEV;
99 }
100 rk3128_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
101
102 return dwc2_udc_probe(&rk3128_otg_data);
103}
104
105int board_usb_cleanup(int index, enum usb_init_type init)
106{
107 return 0;
108}
109#endif
110
Alex Kiernan5512c432018-05-29 15:30:46 +0000111#if CONFIG_IS_ENABLED(FASTBOOT)
112int fastboot_set_reboot_flag(void)
Kever Yangaa827752017-11-28 16:04:16 +0800113{
114 struct rk3128_grf *grf;
115
116 printf("Setting reboot to fastboot flag ...\n");
117 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
118 /* Set boot mode to fastboot */
119 writel(BOOT_FASTBOOT, &grf->os_reg[0]);
120
121 return 0;
122}
123#endif