blob: e71847de8799b4d1bc2bdff26e634c381b8455a5 [file] [log] [blame]
Kever Yang57d4dbf2017-06-23 17:17:52 +08001/*
2 * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6#include <common.h>
7#include <clk.h>
8#include <dm.h>
9#include <ram.h>
Kever Yangf58692a2017-08-09 19:28:03 +080010#include <syscon.h>
Kever Yang57d4dbf2017-06-23 17:17:52 +080011#include <asm/io.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/periph.h>
14#include <asm/arch/grf_rk322x.h>
15#include <asm/arch/boot_mode.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
Kever Yang57d4dbf2017-06-23 17:17:52 +080019__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#include <asm/arch/grf_rk322x.h>
34 /* Enable early UART2 channel 1 on the RK322x */
35#define GRF_BASE 0x11000000
36 struct rk322x_grf * const grf = (void *)GRF_BASE;
37
38 rk_clrsetreg(&grf->gpio1b_iomux,
39 GPIO1B1_MASK | GPIO1B2_MASK,
40 GPIO1B2_UART21_SIN << GPIO1B2_SHIFT |
41 GPIO1B1_UART21_SOUT << GPIO1B1_SHIFT);
42 /* Set channel C as UART2 input */
43 rk_clrsetreg(&grf->con_iomux,
44 CON_IOMUX_UART2SEL_MASK,
45 CON_IOMUX_UART2SEL_21 << CON_IOMUX_UART2SEL_SHIFT);
46
David Wud0f8d782017-08-14 15:04:28 +080047 /*
48 * The integrated macphy is enabled by default, disable it
49 * for saving power consuming.
50 */
51 rk_clrsetreg(&grf->macphy_con[0],
52 MACPHY_CFG_ENABLE_MASK,
53 0 << MACPHY_CFG_ENABLE_SHIFT);
54
Kever Yang57d4dbf2017-06-23 17:17:52 +080055 return 0;
56}
57
58int dram_init_banksize(void)
59{
Kever Yang405b2d02017-07-21 18:21:07 +080060 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
Kever Yang57d4dbf2017-06-23 17:17:52 +080061 gd->bd->bi_dram[0].size = 0x8400000;
Kever Yang405b2d02017-07-21 18:21:07 +080062 /* Reserve 0x200000 for OPTEE */
63 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE
64 + gd->bd->bi_dram[0].size + 0x200000;
65 gd->bd->bi_dram[1].size = gd->bd->bi_dram[0].start
66 + gd->ram_size - gd->bd->bi_dram[1].start;
Kever Yang57d4dbf2017-06-23 17:17:52 +080067
68 return 0;
69}
70
71#ifndef CONFIG_SYS_DCACHE_OFF
72void enable_caches(void)
73{
74 /* Enable D-cache. I-cache is already enabled in start.S */
75 dcache_enable();
76}
77#endif
78
79#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
80#include <usb.h>
81#include <usb/dwc2_udc.h>
82
83static struct dwc2_plat_otg_data rk322x_otg_data = {
84 .rx_fifo_sz = 512,
85 .np_tx_fifo_sz = 16,
86 .tx_fifo_sz = 128,
87};
88
89int board_usb_init(int index, enum usb_init_type init)
90{
91 int node;
92 const char *mode;
93 bool matched = false;
94 const void *blob = gd->fdt_blob;
95
96 /* find the usb_otg node */
97 node = fdt_node_offset_by_compatible(blob, -1,
98 "rockchip,rk3288-usb");
99
100 while (node > 0) {
101 mode = fdt_getprop(blob, node, "dr_mode", NULL);
102 if (mode && strcmp(mode, "otg") == 0) {
103 matched = true;
104 break;
105 }
106
107 node = fdt_node_offset_by_compatible(blob, node,
108 "rockchip,rk3288-usb");
109 }
110 if (!matched) {
111 debug("Not found usb_otg device\n");
112 return -ENODEV;
113 }
114 rk322x_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
115
116 return dwc2_udc_probe(&rk322x_otg_data);
117}
118
119int board_usb_cleanup(int index, enum usb_init_type init)
120{
121 return 0;
122}
123#endif
Kever Yangf58692a2017-08-09 19:28:03 +0800124
125#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
126int fb_set_reboot_flag(void)
127{
128 struct rk322x_grf *grf;
129
130 printf("Setting reboot to fastboot flag ...\n");
131 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
132 /* Set boot mode to fastboot */
133 writel(BOOT_FASTBOOT, &grf->os_reg[0]);
134
135 return 0;
136}
137#endif