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 | |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 7 | #include <common.h> |
Simon Glass | b79fdc7 | 2020-05-10 11:39:54 -0600 | [diff] [blame] | 8 | #include <flash.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 9 | #include <image.h> |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <net.h> |
Rick Chen | 7885ea8 | 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 | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 16 | #include <linux/io.h> |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 17 | #include <faraday/ftsmc020.h> |
| 18 | #include <fdtdec.h> |
Rick Chen | edf0acb | 2019-08-28 18:46:07 +0800 | [diff] [blame] | 19 | #include <dm.h> |
Rick Chen | cd61e86 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 20 | #include <spl.h> |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Rick Chen | 48cbf62 | 2018-12-03 17:48:20 +0800 | [diff] [blame] | 24 | extern phys_addr_t prior_stage_fdt_address; |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 25 | /* |
| 26 | * Miscellaneous platform dependent initializations |
| 27 | */ |
| 28 | |
| 29 | int board_init(void) |
| 30 | { |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 31 | gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | int dram_init(void) |
| 37 | { |
Rick Chen | 7e24518 | 2019-11-14 13:52:23 +0800 | [diff] [blame] | 38 | return fdtdec_setup_mem_size_base(); |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | int dram_init_banksize(void) |
| 42 | { |
Rick Chen | 7e24518 | 2019-11-14 13:52:23 +0800 | [diff] [blame] | 43 | return fdtdec_setup_memory_banksize(); |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH) |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 47 | int board_eth_init(struct bd_info *bd) |
Rick Chen | 7885ea8 | 2017-12-26 13:55:53 +0800 | [diff] [blame] | 48 | { |
| 49 | return ftmac100_initialize(bd); |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info) |
| 54 | { |
| 55 | return 0; |
| 56 | } |
Rick Chen | d58717e | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 57 | |
| 58 | void *board_fdt_blob_setup(void) |
| 59 | { |
Rick Chen | d58717e | 2018-03-29 10:08:33 +0800 | [diff] [blame] | 60 | return (void *)CONFIG_SYS_FDT_BASE; |
| 61 | } |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 62 | |
| 63 | int smc_init(void) |
| 64 | { |
| 65 | int node = -1; |
| 66 | const char *compat = "andestech,atfsmc020"; |
| 67 | void *blob = (void *)gd->fdt_blob; |
| 68 | fdt_addr_t addr; |
| 69 | struct ftsmc020_bank *regs; |
| 70 | |
| 71 | node = fdt_node_offset_by_compatible(blob, -1, compat); |
| 72 | if (node < 0) |
| 73 | return -FDT_ERR_NOTFOUND; |
| 74 | |
Rick Chen | e8fa431 | 2020-07-17 16:24:44 +0800 | [diff] [blame] | 75 | addr = fdtdec_get_addr_size_auto_noparent(blob, node, |
| 76 | "reg", 0, NULL, false); |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 77 | |
| 78 | if (addr == FDT_ADDR_T_NONE) |
| 79 | return -EINVAL; |
| 80 | |
Bin Meng | b7324b5 | 2021-01-31 20:36:01 +0800 | [diff] [blame] | 81 | regs = (struct ftsmc020_bank *)(uintptr_t)addr; |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 82 | regs->cr &= ~FTSMC020_BANK_WPROT; |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Rick Chen | edf0acb | 2019-08-28 18:46:07 +0800 | [diff] [blame] | 87 | static void v5l2_init(void) |
| 88 | { |
| 89 | struct udevice *dev; |
| 90 | |
| 91 | uclass_get_device(UCLASS_CACHE, 0, &dev); |
| 92 | } |
| 93 | |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 94 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 95 | int board_early_init_f(void) |
| 96 | { |
| 97 | smc_init(); |
Rick Chen | edf0acb | 2019-08-28 18:46:07 +0800 | [diff] [blame] | 98 | v5l2_init(); |
Rick Chen | 44199eb | 2018-05-29 11:07:53 +0800 | [diff] [blame] | 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | #endif |
Rick Chen | cd61e86 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 103 | |
| 104 | #ifdef CONFIG_SPL |
| 105 | void board_boot_order(u32 *spl_boot_list) |
| 106 | { |
| 107 | u8 i; |
| 108 | u32 boot_devices[] = { |
| 109 | #ifdef CONFIG_SPL_RAM_SUPPORT |
| 110 | BOOT_DEVICE_RAM, |
| 111 | #endif |
Simon Glass | 103c5f1 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 112 | #ifdef CONFIG_SPL_MMC |
Rick Chen | cd61e86 | 2019-11-14 13:52:22 +0800 | [diff] [blame] | 113 | BOOT_DEVICE_MMC1, |
| 114 | #endif |
| 115 | }; |
| 116 | |
| 117 | for (i = 0; i < ARRAY_SIZE(boot_devices); i++) |
| 118 | spl_boot_list[i] = boot_devices[i]; |
| 119 | } |
| 120 | #endif |
| 121 | |
| 122 | #ifdef CONFIG_SPL_LOAD_FIT |
| 123 | int board_fit_config_name_match(const char *name) |
| 124 | { |
| 125 | /* boot using first FIT config */ |
| 126 | return 0; |
| 127 | } |
| 128 | #endif |