Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Andes Technology Corporation |
| 4 | * Rick Chen, Andes Technology Corporation <rick@andestech.com> |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | 0b9441a | 2023-10-12 19:03:59 -0400 | [diff] [blame^] | 7 | #include <config.h> |
Yu Chien Peter Lin | e74e21c | 2023-02-06 16:10:45 +0800 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | b79fdc7 | 2020-05-10 11:39:54 -0600 | [diff] [blame] | 9 | #include <flash.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 10 | #include <image.h> |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 12 | #include <net.h> |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 13 | #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH) |
| 14 | #include <netdev.h> |
| 15 | #endif |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 17 | #include <linux/io.h> |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 18 | #include <faraday/ftsmc020.h> |
| 19 | #include <fdtdec.h> |
Rick Chen | edf0acb | 2019-08-28 18:46:07 +0800 | [diff] [blame] | 20 | #include <dm.h> |
Rick Chen | cd61e86 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 21 | #include <spl.h> |
Randolph | 03a4504 | 2023-10-12 14:35:09 +0800 | [diff] [blame] | 22 | #include <mapmem.h> |
| 23 | #include <hang.h> |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | /* |
| 28 | * Miscellaneous platform dependent initializations |
| 29 | */ |
| 30 | |
Randolph | 03a4504 | 2023-10-12 14:35:09 +0800 | [diff] [blame] | 31 | #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL) |
| 32 | #define ANDES_SPL_FDT_ADDR (CONFIG_TEXT_BASE - 0x100000) |
| 33 | void spl_perform_fixups(struct spl_image_info *spl_image) |
| 34 | { |
| 35 | /* |
| 36 | * Originally, u-boot-spl will place DTB directly after the kernel, |
| 37 | * but the size of the kernel did not include the BSS section, which |
| 38 | * means u-boot-spl will place the DTB in the kernel BSS section |
| 39 | * causing the DTB to be cleared by kernel BSS initializtion. |
| 40 | * Moving DTB in front of the kernel can avoid the error. |
| 41 | */ |
| 42 | if (ANDES_SPL_FDT_ADDR < 0) { |
| 43 | printf("%s: CONFIG_TEXT_BASE needs to be larger than 0x100000\n", |
| 44 | __func__); |
| 45 | hang(); |
| 46 | } |
| 47 | |
| 48 | memcpy((void *)ANDES_SPL_FDT_ADDR, spl_image->fdt_addr, |
| 49 | fdt_totalsize(spl_image->fdt_addr)); |
| 50 | spl_image->fdt_addr = map_sysmem(ANDES_SPL_FDT_ADDR, 0); |
| 51 | } |
| 52 | #endif |
| 53 | |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 54 | int board_init(void) |
| 55 | { |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 56 | gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400; |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | int dram_init(void) |
| 62 | { |
Rick Chen | 7e24518 | 2019-11-14 13:52:23 +0800 | [diff] [blame] | 63 | return fdtdec_setup_mem_size_base(); |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | int dram_init_banksize(void) |
| 67 | { |
Rick Chen | 7e24518 | 2019-11-14 13:52:23 +0800 | [diff] [blame] | 68 | return fdtdec_setup_memory_banksize(); |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH) |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 72 | int board_eth_init(struct bd_info *bd) |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 73 | { |
| 74 | return ftmac100_initialize(bd); |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info) |
| 79 | { |
| 80 | return 0; |
| 81 | } |
Rick Chen | d58717e | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 82 | |
Leo Yu-Chi Liang | f451261 | 2022-06-01 10:01:49 +0800 | [diff] [blame] | 83 | #define ANDES_HW_DTB_ADDRESS 0xF2000000 |
Ilias Apalodimas | e7fb789 | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 84 | void *board_fdt_blob_setup(int *err) |
Rick Chen | d58717e | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 85 | { |
Ilias Apalodimas | e7fb789 | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 86 | *err = 0; |
Leo Yu-Chi Liang | f451261 | 2022-06-01 10:01:49 +0800 | [diff] [blame] | 87 | |
| 88 | if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD)) { |
Rick Chen | b3b44c6 | 2022-10-20 13:56:17 +0800 | [diff] [blame] | 89 | if (fdt_magic((uintptr_t)gd->arch.firmware_fdt_addr) == FDT_MAGIC) |
Leo Yu-Chi Liang | f451261 | 2022-06-01 10:01:49 +0800 | [diff] [blame] | 90 | return (void *)(ulong)gd->arch.firmware_fdt_addr; |
| 91 | } |
| 92 | |
| 93 | if (fdt_magic(CONFIG_SYS_FDT_BASE) == FDT_MAGIC) |
| 94 | return (void *)CONFIG_SYS_FDT_BASE; |
| 95 | return (void *)ANDES_HW_DTB_ADDRESS; |
| 96 | |
Ilias Apalodimas | e7fb789 | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 97 | *err = -EINVAL; |
Ilias Apalodimas | 2e8d2f8 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 98 | return NULL; |
Rick Chen | d58717e | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 99 | } |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 100 | |
Yu Chien Peter Lin | e74e21c | 2023-02-06 16:10:45 +0800 | [diff] [blame] | 101 | #ifdef CONFIG_SPL_BOARD_INIT |
| 102 | void spl_board_init() |
| 103 | { |
| 104 | /* enable v5l2 cache */ |
| 105 | enable_caches(); |
| 106 | } |
| 107 | #endif |
| 108 | |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 109 | int smc_init(void) |
| 110 | { |
| 111 | int node = -1; |
| 112 | const char *compat = "andestech,atfsmc020"; |
| 113 | void *blob = (void *)gd->fdt_blob; |
| 114 | fdt_addr_t addr; |
| 115 | struct ftsmc020_bank *regs; |
| 116 | |
| 117 | node = fdt_node_offset_by_compatible(blob, -1, compat); |
| 118 | if (node < 0) |
| 119 | return -FDT_ERR_NOTFOUND; |
| 120 | |
Rick Chen | e8fa431 | 2020-07-17 16:24:44 +0800 | [diff] [blame] | 121 | addr = fdtdec_get_addr_size_auto_noparent(blob, node, |
| 122 | "reg", 0, NULL, false); |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 123 | |
| 124 | if (addr == FDT_ADDR_T_NONE) |
| 125 | return -EINVAL; |
| 126 | |
Bin Meng | b7324b5 | 2021-01-31 20:36:01 +0800 | [diff] [blame] | 127 | regs = (struct ftsmc020_bank *)(uintptr_t)addr; |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 128 | regs->cr &= ~FTSMC020_BANK_WPROT; |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 134 | int board_early_init_f(void) |
| 135 | { |
| 136 | smc_init(); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | #endif |
Rick Chen | cd61e86 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 141 | |
| 142 | #ifdef CONFIG_SPL |
| 143 | void board_boot_order(u32 *spl_boot_list) |
| 144 | { |
| 145 | u8 i; |
| 146 | u32 boot_devices[] = { |
| 147 | #ifdef CONFIG_SPL_RAM_SUPPORT |
| 148 | BOOT_DEVICE_RAM, |
| 149 | #endif |
Simon Glass | 103c5f1 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 150 | #ifdef CONFIG_SPL_MMC |
Rick Chen | cd61e86 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 151 | BOOT_DEVICE_MMC1, |
| 152 | #endif |
| 153 | }; |
| 154 | |
| 155 | for (i = 0; i < ARRAY_SIZE(boot_devices); i++) |
| 156 | spl_boot_list[i] = boot_devices[i]; |
| 157 | } |
| 158 | #endif |
| 159 | |
| 160 | #ifdef CONFIG_SPL_LOAD_FIT |
| 161 | int board_fit_config_name_match(const char *name) |
| 162 | { |
| 163 | /* boot using first FIT config */ |
| 164 | return 0; |
| 165 | } |
| 166 | #endif |