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