1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2016 Google, Inc
4  */
5 #include <common.h>
6 #include <dm.h>
7 #include <ram.h>
8 #include <timer.h>
9 #include <asm/io.h>
10 #include <asm/arch/timer.h>
11 #include <linux/err.h>
12 #include <dm/uclass.h>
13 
14 DECLARE_GLOBAL_DATA_PTR;
15 
16 __weak int board_init(void)
17 {
18 	struct udevice *dev;
19 	int i;
20 	int ret;
21 
22 	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
23 
24 	/*
25 	 * Loop over all MISC uclass drivers to call the comphy code
26 	 * and init all CP110 devices enabled in the DT
27 	 */
28 	i = 0;
29 	while (1) {
30 		/* Call the comphy code via the MISC uclass driver */
31 		ret = uclass_get_device(UCLASS_MISC, i++, &dev);
32 
33 		/* We're done, once no further CP110 device is found */
34 		if (ret)
35 			break;
36 	}
37 
38 	return 0;
39 }
40 
41 #ifndef CONFIG_RAM
42 #define SDMC_CONFIG_VRAM_GET(x)		((x >> 2) & 0x3)
43 #define SDMC_CONFIG_MEM_GET(x)		(x & 0x3)
44 
45 static const u32 ast2500_dram_table[] = {
46 	0x08000000,	//128MB
47 	0x10000000,	//256MB
48 	0x20000000,	//512MB
49 	0x40000000,	//1024MB
50 };
51 
52 u32
53 ast_sdmc_get_mem_size(void)
54 {
55 	u32 size = 0;
56 	u32 size_conf = SDMC_CONFIG_MEM_GET(readl(0x1e6e0004));
57 
58 	size = ast2500_dram_table[size_conf];
59 
60 	return size;
61 
62 }
63 
64 static const u32 aspeed_vram_table[] = {
65 	0x00800000,	//8MB
66 	0x01000000,	//16MB
67 	0x02000000,	//32MB
68 	0x04000000,	//64MB
69 };
70 
71 static u32
72 ast_sdmc_get_vram_size(void)
73 {
74 	u32 size_conf = SDMC_CONFIG_VRAM_GET(readl(0x1e6e0004));
75 	return aspeed_vram_table[size_conf];
76 }
77 #endif
78 
79 __weak int dram_init(void)
80 {
81 #ifdef CONFIG_RAM
82 	struct udevice *dev;
83 	struct ram_info ram;
84 	int ret;
85 
86 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
87 	if (ret) {
88 		debug("DRAM FAIL1\r\n");
89 		return ret;
90 	}
91 
92 	ret = ram_get_info(dev, &ram);
93 	if (ret) {
94 		debug("DRAM FAIL2\r\n");
95 		return ret;
96 	}
97 
98 	gd->ram_size = ram.size;
99 #else
100 	u32 vga = ast_sdmc_get_vram_size();
101 	u32 dram = ast_sdmc_get_mem_size();
102 	gd->ram_size = (dram - vga);
103 #endif
104 	return 0;
105 }
106 
107 int arch_early_init_r(void)
108 {
109 #ifdef CONFIG_DM_PCI
110 	/* Trigger PCIe devices detection */
111 	pci_init();
112 #endif
113 
114 	return 0;
115 }
116 
117