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