blob: fd5aaa1579a7599d10b5ca6d300d11eca739366b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rick Chen7885ea82017-12-26 13:55:53 +08002/*
3 * Copyright (C) 2017 Andes Technology Corporation
4 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
Rick Chen7885ea82017-12-26 13:55:53 +08005 */
6
7#include <asm/mach-types.h>
8#include <common.h>
9#if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
10#include <netdev.h>
11#endif
12#include <linux/io.h>
Rick Chen44199eb2018-05-29 11:07:53 +080013#include <faraday/ftsmc020.h>
14#include <fdtdec.h>
Rick Chen7885ea82017-12-26 13:55:53 +080015
16DECLARE_GLOBAL_DATA_PTR;
17
18/*
19 * Miscellaneous platform dependent initializations
20 */
21
22int board_init(void)
23{
Rick Chen28c6cf22018-05-29 10:06:42 +080024 gd->bd->bi_arch_number = MACH_TYPE_AE350;
Rick Chen7885ea82017-12-26 13:55:53 +080025 gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400;
26
27 return 0;
28}
29
30int dram_init(void)
31{
32 unsigned long sdram_base = PHYS_SDRAM_0;
33 unsigned long expected_size = PHYS_SDRAM_0_SIZE + PHYS_SDRAM_1_SIZE;
34 unsigned long actual_size;
35
36 actual_size = get_ram_size((void *)sdram_base, expected_size);
37 gd->ram_size = actual_size;
38
39 if (expected_size != actual_size) {
40 printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
41 actual_size >> 20, expected_size >> 20);
42 }
43
44 return 0;
45}
46
47int dram_init_banksize(void)
48{
49 gd->bd->bi_dram[0].start = PHYS_SDRAM_0;
50 gd->bd->bi_dram[0].size = PHYS_SDRAM_0_SIZE;
51 gd->bd->bi_dram[1].start = PHYS_SDRAM_1;
52 gd->bd->bi_dram[1].size = PHYS_SDRAM_1_SIZE;
53
54 return 0;
55}
56
57#if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
58int board_eth_init(bd_t *bd)
59{
60 return ftmac100_initialize(bd);
61}
62#endif
63
64ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
65{
66 return 0;
67}
Rick Chend58717e2018-03-29 10:08:33 +080068
69void *board_fdt_blob_setup(void)
70{
71 void **ptr = (void *)CONFIG_SYS_SDRAM_BASE;
72 if (fdt_magic(*ptr) == FDT_MAGIC)
73 return (void *)*ptr;
74
75 return (void *)CONFIG_SYS_FDT_BASE;
76}
Rick Chen44199eb2018-05-29 11:07:53 +080077
78int smc_init(void)
79{
80 int node = -1;
81 const char *compat = "andestech,atfsmc020";
82 void *blob = (void *)gd->fdt_blob;
83 fdt_addr_t addr;
84 struct ftsmc020_bank *regs;
85
86 node = fdt_node_offset_by_compatible(blob, -1, compat);
87 if (node < 0)
88 return -FDT_ERR_NOTFOUND;
89
90 addr = fdtdec_get_addr(blob, node, "reg");
91
92 if (addr == FDT_ADDR_T_NONE)
93 return -EINVAL;
94
95 regs = (struct ftsmc020_bank *)addr;
96 regs->cr &= ~FTSMC020_BANK_WPROT;
97
98 return 0;
99}
100
101#ifdef CONFIG_BOARD_EARLY_INIT_F
102int board_early_init_f(void)
103{
104 smc_init();
105
106 return 0;
107}
108#endif