1 /*
2  * (C) Copyright 2015 Google, Inc
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 <syscon.h>
12 #include <asm/io.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/periph.h>
15 #include <asm/arch/pmu_rk3288.h>
16 #include <asm/arch/boot_mode.h>
17 #include <asm/gpio.h>
18 #include <dm/pinctrl.h>
19 
20 DECLARE_GLOBAL_DATA_PTR;
21 
22 int board_init(void)
23 {
24 #if defined(CONFIG_ROCKCHIP_SPL_BACK_TO_BROM)
25 	struct udevice *pinctrl;
26 	int ret;
27 
28 	/*
29 	 * We need to implement sdcard iomux here for the further
30 	 * initialization, otherwise, it'll hit sdcard command sending
31 	 * timeout exception.
32 	 */
33 	ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
34 	if (ret) {
35 		debug("%s: Cannot find pinctrl device\n", __func__);
36 		goto err;
37 	}
38 	ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
39 	if (ret) {
40 		debug("%s: Failed to set up SD card\n", __func__);
41 		goto err;
42 	}
43 
44 	return 0;
45 err:
46 	printf("board_init: Error %d\n", ret);
47 
48 	/* No way to report error here */
49 	hang();
50 
51 	return -1;
52 #else
53 	return 0;
54 #endif
55 }
56 
57 int dram_init(void)
58 {
59 	struct ram_info ram;
60 	struct udevice *dev;
61 	int ret;
62 
63 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
64 	if (ret) {
65 		debug("DRAM init failed: %d\n", ret);
66 		return ret;
67 	}
68 	ret = ram_get_info(dev, &ram);
69 	if (ret) {
70 		debug("Cannot get DRAM size: %d\n", ret);
71 		return ret;
72 	}
73 	debug("SDRAM base=%lx, size=%x\n", ram.base, ram.size);
74 	gd->ram_size = ram.size;
75 
76 	return 0;
77 }
78 
79 #ifndef CONFIG_SYS_DCACHE_OFF
80 void enable_caches(void)
81 {
82 	/* Enable D-cache. I-cache is already enabled in start.S */
83 	dcache_enable();
84 }
85 #endif
86