1 /*
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>
14 #include <asm/arch/grf_rk3036.h>
15 #include <asm/arch/boot_mode.h>
16 #include <asm/arch/sdram_rk3036.h>
17 #include <asm/gpio.h>
18 #include <dm/pinctrl.h>
19 
20 DECLARE_GLOBAL_DATA_PTR;
21 
22 __weak int rk_board_late_init(void)
23 {
24 	return 0;
25 }
26 
27 int board_late_init(void)
28 {
29 	setup_boot_mode();
30 
31 	return rk_board_late_init();
32 }
33 
34 int board_init(void)
35 {
36 	return 0;
37 }
38 
39 #if !CONFIG_IS_ENABLED(RAM)
40 /*
41  * When CONFIG_RAM is enabled, the dram_init() function is implemented
42  * in sdram_common.c.
43  */
44 int dram_init(void)
45 {
46 	gd->ram_size = sdram_size();
47 
48 	return 0;
49 }
50 #endif
51 
52 #ifndef CONFIG_SYS_DCACHE_OFF
53 void 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 
64 static 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 
70 int 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 
100 int board_usb_cleanup(int index, enum usb_init_type init)
101 {
102 	return 0;
103 }
104 #endif
105