blob: 1c2288b6ce9f965c03fb26a68b451035a909033e [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
Rick Chen36cb27c2017-12-26 13:55:53 +08007#include <common.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
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Rick Chen36cb27c2017-12-26 13:55:53 +080017#include <linux/io.h>
Rick Chencea16d02018-05-29 11:07:53 +080018#include <faraday/ftsmc020.h>
19#include <fdtdec.h>
Rick Chen9e017162019-08-28 18:46:07 +080020#include <dm.h>
Rick Chenc3027d02019-11-14 13:52:22 +080021#include <spl.h>
Rick Chen36cb27c2017-12-26 13:55:53 +080022
23DECLARE_GLOBAL_DATA_PTR;
24
25/*
26 * Miscellaneous platform dependent initializations
27 */
28
29int board_init(void)
30{
Rick Chen36cb27c2017-12-26 13:55:53 +080031 gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400;
32
33 return 0;
34}
35
36int dram_init(void)
37{
Rick Chen92038262019-11-14 13:52:23 +080038 return fdtdec_setup_mem_size_base();
Rick Chen36cb27c2017-12-26 13:55:53 +080039}
40
41int dram_init_banksize(void)
42{
Rick Chen92038262019-11-14 13:52:23 +080043 return fdtdec_setup_memory_banksize();
Rick Chen36cb27c2017-12-26 13:55:53 +080044}
45
46#if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090047int board_eth_init(struct bd_info *bd)
Rick Chen36cb27c2017-12-26 13:55:53 +080048{
49 return ftmac100_initialize(bd);
50}
51#endif
52
53ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
54{
55 return 0;
56}
Rick Chen40a6fe72018-03-29 10:08:33 +080057
Leo Yu-Chi Liang4150eec2022-06-01 10:01:49 +080058#define ANDES_HW_DTB_ADDRESS 0xF2000000
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030059void *board_fdt_blob_setup(int *err)
Rick Chen40a6fe72018-03-29 10:08:33 +080060{
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030061 *err = 0;
Leo Yu-Chi Liang4150eec2022-06-01 10:01:49 +080062
63 if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) {
Rick Chen206feaa2022-10-20 13:56:17 +080064 if (fdt_magic((uintptr_t)gd->arch.firmware_fdt_addr) == FDT_MAGIC)
Leo Yu-Chi Liang4150eec2022-06-01 10:01:49 +080065 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
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030072 *err = -EINVAL;
Ilias Apalodimasdc35df42021-10-12 00:00:13 +030073 return NULL;
Rick Chen40a6fe72018-03-29 10:08:33 +080074}
Rick Chencea16d02018-05-29 11:07:53 +080075
Yu Chien Peter Lin39689a92023-02-06 16:10:45 +080076#ifdef CONFIG_SPL_BOARD_INIT
77void spl_board_init()
78{
79 /* enable v5l2 cache */
80 enable_caches();
81}
82#endif
83
Rick Chencea16d02018-05-29 11:07:53 +080084int 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
Rick Chenca3e5e42020-07-17 16:24:44 +080096 addr = fdtdec_get_addr_size_auto_noparent(blob, node,
97 "reg", 0, NULL, false);
Rick Chencea16d02018-05-29 11:07:53 +080098
99 if (addr == FDT_ADDR_T_NONE)
100 return -EINVAL;
101
Bin Meng65d59952021-01-31 20:36:01 +0800102 regs = (struct ftsmc020_bank *)(uintptr_t)addr;
Rick Chencea16d02018-05-29 11:07:53 +0800103 regs->cr &= ~FTSMC020_BANK_WPROT;
104
105 return 0;
106}
107
108#ifdef CONFIG_BOARD_EARLY_INIT_F
109int board_early_init_f(void)
110{
111 smc_init();
112
113 return 0;
114}
115#endif
Rick Chenc3027d02019-11-14 13:52:22 +0800116
117#ifdef CONFIG_SPL
118void 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
Simon Glassb58bfe02021-08-08 12:20:09 -0600125#ifdef CONFIG_SPL_MMC
Rick Chenc3027d02019-11-14 13:52:22 +0800126 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
136int board_fit_config_name_match(const char *name)
137{
138 /* boot using first FIT config */
139 return 0;
140}
141#endif