1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2017 Andes Technology Corporation
4  * Rick Chen, Andes Technology Corporation <rick@andestech.com>
5  */
6 
7 #include <common.h>
8 #include <flash.h>
9 #include <image.h>
10 #include <init.h>
11 #include <net.h>
12 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
13 #include <netdev.h>
14 #endif
15 #include <asm/global_data.h>
16 #include <linux/io.h>
17 #include <faraday/ftsmc020.h>
18 #include <fdtdec.h>
19 #include <dm.h>
20 #include <spl.h>
21 
22 DECLARE_GLOBAL_DATA_PTR;
23 
24 /*
25  * Miscellaneous platform dependent initializations
26  */
27 
board_init(void)28 int board_init(void)
29 {
30 	gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400;
31 
32 	return 0;
33 }
34 
dram_init(void)35 int dram_init(void)
36 {
37 	return fdtdec_setup_mem_size_base();
38 }
39 
dram_init_banksize(void)40 int dram_init_banksize(void)
41 {
42 	return fdtdec_setup_memory_banksize();
43 }
44 
45 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
board_eth_init(struct bd_info * bd)46 int board_eth_init(struct bd_info *bd)
47 {
48 	return ftmac100_initialize(bd);
49 }
50 #endif
51 
board_flash_get_legacy(ulong base,int banknum,flash_info_t * info)52 ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
53 {
54 	return 0;
55 }
56 
board_fdt_blob_setup(int * err)57 void *board_fdt_blob_setup(int *err)
58 {
59 	*err = 0;
60 #if CONFIG_IS_ENABLED(OF_BOARD)
61 	return (void *)(ulong)gd->arch.firmware_fdt_addr;
62 #elif CONFIG_IS_ENABLED(OF_SEPARATE)
63 	return (void *)CONFIG_SYS_FDT_BASE;
64 #else
65 	*err = -EINVAL;
66 	return NULL;
67 #endif
68 }
69 
smc_init(void)70 int smc_init(void)
71 {
72 	int node = -1;
73 	const char *compat = "andestech,atfsmc020";
74 	void *blob = (void *)gd->fdt_blob;
75 	fdt_addr_t addr;
76 	struct ftsmc020_bank *regs;
77 
78 	node = fdt_node_offset_by_compatible(blob, -1, compat);
79 	if (node < 0)
80 		return -FDT_ERR_NOTFOUND;
81 
82 	addr = fdtdec_get_addr_size_auto_noparent(blob, node,
83 		"reg", 0, NULL, false);
84 
85 	if (addr == FDT_ADDR_T_NONE)
86 		return -EINVAL;
87 
88 	regs = (struct ftsmc020_bank *)(uintptr_t)addr;
89 	regs->cr &= ~FTSMC020_BANK_WPROT;
90 
91 	return 0;
92 }
93 
v5l2_init(void)94 static void v5l2_init(void)
95 {
96 	struct udevice *dev;
97 
98 	uclass_get_device(UCLASS_CACHE, 0, &dev);
99 }
100 
101 #ifdef CONFIG_BOARD_EARLY_INIT_F
board_early_init_f(void)102 int board_early_init_f(void)
103 {
104 	smc_init();
105 	v5l2_init();
106 
107 	return 0;
108 }
109 #endif
110 
111 #ifdef CONFIG_SPL
board_boot_order(u32 * spl_boot_list)112 void board_boot_order(u32 *spl_boot_list)
113 {
114 	u8 i;
115 	u32 boot_devices[] = {
116 #ifdef CONFIG_SPL_RAM_SUPPORT
117 		BOOT_DEVICE_RAM,
118 #endif
119 #ifdef CONFIG_SPL_MMC
120 		BOOT_DEVICE_MMC1,
121 #endif
122 	};
123 
124 	for (i = 0; i < ARRAY_SIZE(boot_devices); i++)
125 		spl_boot_list[i] = boot_devices[i];
126 }
127 #endif
128 
129 #ifdef CONFIG_SPL_LOAD_FIT
board_fit_config_name_match(const char * name)130 int board_fit_config_name_match(const char *name)
131 {
132 	/* boot using first FIT config */
133 	return 0;
134 }
135 #endif
136