blob: a5d257168f8f45a34609f02217bc04bd6f57b1ca [file] [log] [blame]
Jacob Chenf48f2b72016-09-19 18:46:27 +08001/*
2 * (C) Copyright 2015 Rockchip Electronics Co., Ltd
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <clk.h>
9#include <dm.h>
10#include <ram.h>
11#include <asm/io.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/periph.h>
Jacob Chen67171e12016-09-19 18:46:28 +080014#include <asm/arch/grf_rk3036.h>
15#include <asm/arch/boot_mode.h>
16#include <asm/arch/sdram_rk3036.h>
Jacob Chenf48f2b72016-09-19 18:46:27 +080017#include <asm/gpio.h>
18#include <dm/pinctrl.h>
19
20DECLARE_GLOBAL_DATA_PTR;
21
Jacob Chen67171e12016-09-19 18:46:28 +080022__weak int rk_board_late_init(void)
23{
24 return 0;
25}
26
27int board_late_init(void)
28{
29 setup_boot_mode();
30
31 return rk_board_late_init();
32}
33
Jacob Chenf48f2b72016-09-19 18:46:27 +080034int board_init(void)
35{
36 return 0;
37}
38
Kever Yang7805cdf2017-06-23 16:11:06 +080039#if !CONFIG_IS_ENABLED(RAM)
40/*
41 * When CONFIG_RAM is enabled, the dram_init() function is implemented
42 * in sdram_common.c.
43 */
Jacob Chenf48f2b72016-09-19 18:46:27 +080044int dram_init(void)
45{
46 gd->ram_size = sdram_size();
47
48 return 0;
49}
Kever Yang7805cdf2017-06-23 16:11:06 +080050#endif
Jacob Chenf48f2b72016-09-19 18:46:27 +080051
52#ifndef CONFIG_SYS_DCACHE_OFF
53void enable_caches(void)
54{
55 /* Enable D-cache. I-cache is already enabled in start.S */
56 dcache_enable();
57}
58#endif
59
60#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
61#include <usb.h>
62#include <usb/dwc2_udc.h>
63
64static struct dwc2_plat_otg_data rk3036_otg_data = {
65 .rx_fifo_sz = 512,
66 .np_tx_fifo_sz = 16,
67 .tx_fifo_sz = 128,
68};
69
70int board_usb_init(int index, enum usb_init_type init)
71{
72 int node;
73 const char *mode;
74 bool matched = false;
75 const void *blob = gd->fdt_blob;
76
77 /* find the usb_otg node */
78 node = fdt_node_offset_by_compatible(blob, -1,
79 "rockchip,rk3288-usb");
80
81 while (node > 0) {
82 mode = fdt_getprop(blob, node, "dr_mode", NULL);
83 if (mode && strcmp(mode, "otg") == 0) {
84 matched = true;
85 break;
86 }
87
88 node = fdt_node_offset_by_compatible(blob, node,
89 "rockchip,rk3288-usb");
90 }
91 if (!matched) {
92 debug("Not found usb_otg device\n");
93 return -ENODEV;
94 }
95 rk3036_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
96
97 return dwc2_udc_probe(&rk3036_otg_data);
98}
99
100int board_usb_cleanup(int index, enum usb_init_type init)
101{
102 return 0;
103}
104#endif