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