blob: 62b93b4ecba12d07bf8a2f77683d0bac9285744e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rick Chen36cb27c2017-12-26 13:55:53 +08002/*
3 * Copyright (C) 2017 Andes Technology Corporation
4 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
Rick Chen36cb27c2017-12-26 13:55:53 +08005 */
6
Tom Rinib6b99002023-10-12 19:03:59 -04007#include <config.h>
Yu Chien Peter Lin39689a92023-02-06 16:10:45 +08008#include <cpu_func.h>
Simon Glass8e201882020-05-10 11:39:54 -06009#include <flash.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <image.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070011#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <net.h>
Rick Chen36cb27c2017-12-26 13:55:53 +080013#if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
14#include <netdev.h>
15#endif
Leo Yu-Chi Liangcec100f2023-12-26 14:54:27 +080016#include <asm/csr.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Leo Yu-Chi Liangcec100f2023-12-26 14:54:27 +080018#include <asm/sbi.h>
Rick Chen36cb27c2017-12-26 13:55:53 +080019#include <linux/io.h>
Rick Chencea16d02018-05-29 11:07:53 +080020#include <faraday/ftsmc020.h>
21#include <fdtdec.h>
Rick Chen9e017162019-08-28 18:46:07 +080022#include <dm.h>
Rick Chenc3027d02019-11-14 13:52:22 +080023#include <spl.h>
Rick Chen36cb27c2017-12-26 13:55:53 +080024
25DECLARE_GLOBAL_DATA_PTR;
26
27/*
28 * Miscellaneous platform dependent initializations
29 */
Leo Yu-Chi Liangcec100f2023-12-26 14:54:27 +080030#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
Rick Chen36cb27c2017-12-26 13:55:53 +080051
52int board_init(void)
53{
Rick Chen36cb27c2017-12-26 13:55:53 +080054 gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400;
55
56 return 0;
57}
58
59int dram_init(void)
60{
Rick Chen92038262019-11-14 13:52:23 +080061 return fdtdec_setup_mem_size_base();
Rick Chen36cb27c2017-12-26 13:55:53 +080062}
63
64int dram_init_banksize(void)
65{
Rick Chen92038262019-11-14 13:52:23 +080066 return fdtdec_setup_memory_banksize();
Rick Chen36cb27c2017-12-26 13:55:53 +080067}
68
69#if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090070int board_eth_init(struct bd_info *bd)
Rick Chen36cb27c2017-12-26 13:55:53 +080071{
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}
Rick Chen40a6fe72018-03-29 10:08:33 +080080
Leo Yu-Chi Liang4150eec2022-06-01 10:01:49 +080081#define ANDES_HW_DTB_ADDRESS 0xF2000000
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030082void *board_fdt_blob_setup(int *err)
Rick Chen40a6fe72018-03-29 10:08:33 +080083{
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030084 *err = 0;
Leo Yu-Chi Liang4150eec2022-06-01 10:01:49 +080085
86 if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
Rick Chen206feaa2022-10-20 13:56:17 +080087 if (fdt_magic((uintptr_t)gd->arch.firmware_fdt_addr) == FDT_MAGIC)
Leo Yu-Chi Liang4150eec2022-06-01 10:01:49 +080088 return (void *)(ulong)gd->arch.firmware_fdt_addr;
89 }
90
91 if (fdt_magic(CONFIG_SYS_FDT_BASE) == FDT_MAGIC)
92 return (void *)CONFIG_SYS_FDT_BASE;
93 return (void *)ANDES_HW_DTB_ADDRESS;
94
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030095 *err = -EINVAL;
Ilias Apalodimasdc35df42021-10-12 00:00:13 +030096 return NULL;
Rick Chen40a6fe72018-03-29 10:08:33 +080097}
Rick Chencea16d02018-05-29 11:07:53 +080098
Yu Chien Peter Lin39689a92023-02-06 16:10:45 +080099#ifdef CONFIG_SPL_BOARD_INIT
100void spl_board_init()
101{
102 /* enable v5l2 cache */
Leo Yu-Chi Liang1eb9f912023-12-26 14:17:33 +0800103 if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
104 enable_caches();
Yu Chien Peter Lin39689a92023-02-06 16:10:45 +0800105}
106#endif
107
Rick Chencea16d02018-05-29 11:07:53 +0800108int smc_init(void)
109{
110 int node = -1;
111 const char *compat = "andestech,atfsmc020";
112 void *blob = (void *)gd->fdt_blob;
113 fdt_addr_t addr;
114 struct ftsmc020_bank *regs;
115
116 node = fdt_node_offset_by_compatible(blob, -1, compat);
117 if (node < 0)
118 return -FDT_ERR_NOTFOUND;
119
Rick Chenca3e5e42020-07-17 16:24:44 +0800120 addr = fdtdec_get_addr_size_auto_noparent(blob, node,
121 "reg", 0, NULL, false);
Rick Chencea16d02018-05-29 11:07:53 +0800122
123 if (addr == FDT_ADDR_T_NONE)
124 return -EINVAL;
125
Bin Meng65d59952021-01-31 20:36:01 +0800126 regs = (struct ftsmc020_bank *)(uintptr_t)addr;
Rick Chencea16d02018-05-29 11:07:53 +0800127 regs->cr &= ~FTSMC020_BANK_WPROT;
128
129 return 0;
130}
131
132#ifdef CONFIG_BOARD_EARLY_INIT_F
133int board_early_init_f(void)
134{
135 smc_init();
136
137 return 0;
138}
139#endif
Rick Chenc3027d02019-11-14 13:52:22 +0800140
141#ifdef CONFIG_SPL
142void board_boot_order(u32 *spl_boot_list)
143{
144 u8 i;
145 u32 boot_devices[] = {
146#ifdef CONFIG_SPL_RAM_SUPPORT
147 BOOT_DEVICE_RAM,
148#endif
Simon Glassb58bfe02021-08-08 12:20:09 -0600149#ifdef CONFIG_SPL_MMC
Rick Chenc3027d02019-11-14 13:52:22 +0800150 BOOT_DEVICE_MMC1,
151#endif
152 };
153
154 for (i = 0; i < ARRAY_SIZE(boot_devices); i++)
155 spl_boot_list[i] = boot_devices[i];
156}
157#endif
158
159#ifdef CONFIG_SPL_LOAD_FIT
160int board_fit_config_name_match(const char *name)
161{
162 /* boot using first FIT config */
163 return 0;
164}
165#endif