Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rick Chen | 36cb27c | 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 | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Rick Chen | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 7 | #include <common.h> |
Simon Glass | 8e20188 | 2020-05-10 11:39:54 -0600 | [diff] [blame] | 8 | #include <flash.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 9 | #include <image.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <net.h> |
Rick Chen | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 12 | #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH) |
| 13 | #include <netdev.h> |
| 14 | #endif |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Rick Chen | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 16 | #include <linux/io.h> |
Rick Chen | cea16d0 | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 17 | #include <faraday/ftsmc020.h> |
| 18 | #include <fdtdec.h> |
Rick Chen | 9e01716 | 2019-08-28 18:46:07 +0800 | [diff] [blame] | 19 | #include <dm.h> |
Rick Chen | c3027d0 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 20 | #include <spl.h> |
Rick Chen | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | /* |
| 25 | * Miscellaneous platform dependent initializations |
| 26 | */ |
| 27 | |
| 28 | int board_init(void) |
| 29 | { |
Rick Chen | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 30 | gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400; |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | int dram_init(void) |
| 36 | { |
Rick Chen | 9203826 | 2019-11-14 13:52:23 +0800 | [diff] [blame] | 37 | return fdtdec_setup_mem_size_base(); |
Rick Chen | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int dram_init_banksize(void) |
| 41 | { |
Rick Chen | 9203826 | 2019-11-14 13:52:23 +0800 | [diff] [blame] | 42 | return fdtdec_setup_memory_banksize(); |
Rick Chen | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 46 | int board_eth_init(struct bd_info *bd) |
Rick Chen | 36cb27c | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 47 | { |
| 48 | return ftmac100_initialize(bd); |
| 49 | } |
| 50 | #endif |
| 51 | |
| 52 | ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info) |
| 53 | { |
| 54 | return 0; |
| 55 | } |
Rick Chen | 40a6fe7 | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 56 | |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 57 | void *board_fdt_blob_setup(int *err) |
Rick Chen | 40a6fe7 | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 58 | { |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 59 | *err = 0; |
Leo Yu-Chi Liang | d3a09ec | 2021-11-01 17:00:43 +0800 | [diff] [blame] | 60 | #if defined(CONFIG_OF_BOARD) |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 61 | return (void *)(ulong)gd->arch.firmware_fdt_addr; |
Leo Yu-Chi Liang | d3a09ec | 2021-11-01 17:00:43 +0800 | [diff] [blame] | 62 | #elif defined(CONFIG_OF_SEPARATE) |
Rick Chen | 40a6fe7 | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 63 | return (void *)CONFIG_SYS_FDT_BASE; |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 64 | #else |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 65 | *err = -EINVAL; |
Ilias Apalodimas | dc35df4 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 66 | return NULL; |
| 67 | #endif |
Rick Chen | 40a6fe7 | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 68 | } |
Rick Chen | cea16d0 | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 69 | |
| 70 | int smc_init(void) |
| 71 | { |
| 72 | int node = -1; |
| 73 | const char *compat = "andestech,atfsmc020"; |
| 74 | void *blob = (void *)gd->fdt_blob; |
| 75 | fdt_addr_t addr; |
| 76 | struct ftsmc020_bank *regs; |
| 77 | |
| 78 | node = fdt_node_offset_by_compatible(blob, -1, compat); |
| 79 | if (node < 0) |
| 80 | return -FDT_ERR_NOTFOUND; |
| 81 | |
Rick Chen | ca3e5e4 | 2020-07-17 16:24:44 +0800 | [diff] [blame] | 82 | addr = fdtdec_get_addr_size_auto_noparent(blob, node, |
| 83 | "reg", 0, NULL, false); |
Rick Chen | cea16d0 | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 84 | |
| 85 | if (addr == FDT_ADDR_T_NONE) |
| 86 | return -EINVAL; |
| 87 | |
Bin Meng | 65d5995 | 2021-01-31 20:36:01 +0800 | [diff] [blame] | 88 | regs = (struct ftsmc020_bank *)(uintptr_t)addr; |
Rick Chen | cea16d0 | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 89 | regs->cr &= ~FTSMC020_BANK_WPROT; |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Rick Chen | 9e01716 | 2019-08-28 18:46:07 +0800 | [diff] [blame] | 94 | static void v5l2_init(void) |
| 95 | { |
| 96 | struct udevice *dev; |
| 97 | |
| 98 | uclass_get_device(UCLASS_CACHE, 0, &dev); |
| 99 | } |
| 100 | |
Rick Chen | cea16d0 | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 101 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 102 | int board_early_init_f(void) |
| 103 | { |
| 104 | smc_init(); |
Rick Chen | 9e01716 | 2019-08-28 18:46:07 +0800 | [diff] [blame] | 105 | v5l2_init(); |
Rick Chen | cea16d0 | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | #endif |
Rick Chen | c3027d0 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 110 | |
| 111 | #ifdef CONFIG_SPL |
| 112 | void board_boot_order(u32 *spl_boot_list) |
| 113 | { |
| 114 | u8 i; |
| 115 | u32 boot_devices[] = { |
| 116 | #ifdef CONFIG_SPL_RAM_SUPPORT |
| 117 | BOOT_DEVICE_RAM, |
| 118 | #endif |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 119 | #ifdef CONFIG_SPL_MMC |
Rick Chen | c3027d0 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 120 | BOOT_DEVICE_MMC1, |
| 121 | #endif |
| 122 | }; |
| 123 | |
| 124 | for (i = 0; i < ARRAY_SIZE(boot_devices); i++) |
| 125 | spl_boot_list[i] = boot_devices[i]; |
| 126 | } |
| 127 | #endif |
| 128 | |
| 129 | #ifdef CONFIG_SPL_LOAD_FIT |
| 130 | int board_fit_config_name_match(const char *name) |
| 131 | { |
| 132 | /* boot using first FIT config */ |
| 133 | return 0; |
| 134 | } |
| 135 | #endif |