]> Git Repo - J-u-boot.git/blame - board/andestech/ae350/ae350.c
fdt: Swap the signature for board_fdt_blob_setup()
[J-u-boot.git] / board / andestech / ae350 / ae350.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
7885ea85
RC
2/*
3 * Copyright (C) 2017 Andes Technology Corporation
4 * Rick Chen, Andes Technology Corporation <[email protected]>
7885ea85
RC
5 */
6
0b9441ae 7#include <config.h>
e74e21ce 8#include <cpu_func.h>
b79fdc76 9#include <flash.h>
4d72caa5 10#include <image.h>
9b4a205f 11#include <init.h>
90526e9f 12#include <net.h>
7885ea85
RC
13#if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
14#include <netdev.h>
15#endif
936b5030 16#include <asm/csr.h>
401d1c4f 17#include <asm/global_data.h>
936b5030 18#include <asm/sbi.h>
7885ea85 19#include <linux/io.h>
44199ebc
RC
20#include <faraday/ftsmc020.h>
21#include <fdtdec.h>
edf0acb3 22#include <dm.h>
cd61e86e 23#include <spl.h>
7885ea85
RC
24
25DECLARE_GLOBAL_DATA_PTR;
26
27/*
28 * Miscellaneous platform dependent initializations
29 */
936b5030
LYCL
30#if IS_ENABLED(CONFIG_MISC_INIT_R)
31int misc_init_r(void)
32{
33 long csr_marchid = 0;
34 const long mask_64 = 0x8000;
35 const long mask_cpu = 0xff;
36 char cpu_name[10] = {};
37
38#if CONFIG_IS_ENABLED(RISCV_SMODE)
39 sbi_get_marchid(&csr_marchid);
40#elif CONFIG_IS_ENABLED(RISCV_MMODE)
41 csr_marchid = csr_read(CSR_MARCHID);
42#endif
43 if (mask_64 & csr_marchid)
44 snprintf(cpu_name, sizeof(cpu_name), "ax%lx", (mask_cpu & csr_marchid));
45 else
46 snprintf(cpu_name, sizeof(cpu_name), "a%lx", (mask_cpu & csr_marchid));
47
48 return env_set("cpu", cpu_name);
49}
50#endif
7885ea85
RC
51
52int board_init(void)
53{
7885ea85
RC
54 gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400;
55
56 return 0;
57}
58
59int dram_init(void)
60{
7e24518c 61 return fdtdec_setup_mem_size_base();
7885ea85
RC
62}
63
64int dram_init_banksize(void)
65{
7e24518c 66 return fdtdec_setup_memory_banksize();
7885ea85
RC
67}
68
69#if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
b75d8dc5 70int board_eth_init(struct bd_info *bd)
7885ea85
RC
71{
72 return ftmac100_initialize(bd);
73}
74#endif
75
76ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
77{
78 return 0;
79}
d58717e4 80
f4512618 81#define ANDES_HW_DTB_ADDRESS 0xF2000000
fc37a73e 82int board_fdt_blob_setup(void **fdtp)
d58717e4 83{
f4512618 84 if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
fc37a73e
SG
85 if (fdt_magic((uintptr_t)gd->arch.firmware_fdt_addr) ==
86 FDT_MAGIC) {
87 *fdtp = (void *)(ulong)gd->arch.firmware_fdt_addr;
88
89 return 0;
90 }
f4512618
LYCL
91 }
92
fc37a73e
SG
93 if (fdt_magic(CONFIG_SYS_FDT_BASE) == FDT_MAGIC) {
94 *fdtp = (void *)CONFIG_SYS_FDT_BASE;
95
96 return 0;
97 }
f4512618 98
fc37a73e 99 return -EINVAL;
d58717e4 100}
44199ebc 101
e74e21ce
YCPL
102#ifdef CONFIG_SPL_BOARD_INIT
103void spl_board_init()
104{
2b8dc36b 105 /* enable andes-l2 cache */
b0469041
LYCL
106 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
107 enable_caches();
e74e21ce
YCPL
108}
109#endif
110
44199ebc
RC
111int smc_init(void)
112{
113 int node = -1;
114 const char *compat = "andestech,atfsmc020";
115 void *blob = (void *)gd->fdt_blob;
116 fdt_addr_t addr;
117 struct ftsmc020_bank *regs;
118
119 node = fdt_node_offset_by_compatible(blob, -1, compat);
120 if (node < 0)
121 return -FDT_ERR_NOTFOUND;
122
e8fa4318
RC
123 addr = fdtdec_get_addr_size_auto_noparent(blob, node,
124 "reg", 0, NULL, false);
44199ebc
RC
125
126 if (addr == FDT_ADDR_T_NONE)
127 return -EINVAL;
128
b7324b5d 129 regs = (struct ftsmc020_bank *)(uintptr_t)addr;
44199ebc
RC
130 regs->cr &= ~FTSMC020_BANK_WPROT;
131
132 return 0;
133}
134
135#ifdef CONFIG_BOARD_EARLY_INIT_F
136int board_early_init_f(void)
137{
138 smc_init();
139
140 return 0;
141}
142#endif
cd61e86e
RC
143
144#ifdef CONFIG_SPL
145void board_boot_order(u32 *spl_boot_list)
146{
147 u8 i;
148 u32 boot_devices[] = {
149#ifdef CONFIG_SPL_RAM_SUPPORT
150 BOOT_DEVICE_RAM,
151#endif
103c5f18 152#ifdef CONFIG_SPL_MMC
cd61e86e
RC
153 BOOT_DEVICE_MMC1,
154#endif
155 };
156
157 for (i = 0; i < ARRAY_SIZE(boot_devices); i++)
158 spl_boot_list[i] = boot_devices[i];
159}
160#endif
161
162#ifdef CONFIG_SPL_LOAD_FIT
163int board_fit_config_name_match(const char *name)
164{
165 /* boot using first FIT config */
166 return 0;
167}
168#endif
This page took 0.186332 seconds and 4 git commands to generate.