blob: 5f4ca0f5a7433372ed14b1afd68d6259d9039cf4 [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
17/*
18 * Miscellaneous platform dependent initializations
19 */
20
21int board_init(void)
22{
Rick Chen36cb27c2017-12-26 13:55:53 +080023 gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400;
24
25 return 0;
26}
27
28int dram_init(void)
29{
30 unsigned long sdram_base = PHYS_SDRAM_0;
31 unsigned long expected_size = PHYS_SDRAM_0_SIZE + PHYS_SDRAM_1_SIZE;
32 unsigned long actual_size;
33
34 actual_size = get_ram_size((void *)sdram_base, expected_size);
35 gd->ram_size = actual_size;
36
37 if (expected_size != actual_size) {
38 printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
39 actual_size >> 20, expected_size >> 20);
40 }
41
42 return 0;
43}
44
45int dram_init_banksize(void)
46{
47 gd->bd->bi_dram[0].start = PHYS_SDRAM_0;
48 gd->bd->bi_dram[0].size = PHYS_SDRAM_0_SIZE;
49 gd->bd->bi_dram[1].start = PHYS_SDRAM_1;
50 gd->bd->bi_dram[1].size = PHYS_SDRAM_1_SIZE;
51
52 return 0;
53}
54
55#if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
56int board_eth_init(bd_t *bd)
57{
58 return ftmac100_initialize(bd);
59}
60#endif
61
62ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
63{
64 return 0;
65}
Rick Chen40a6fe72018-03-29 10:08:33 +080066
67void *board_fdt_blob_setup(void)
68{
69 void **ptr = (void *)CONFIG_SYS_SDRAM_BASE;
70 if (fdt_magic(*ptr) == FDT_MAGIC)
71 return (void *)*ptr;
72
73 return (void *)CONFIG_SYS_FDT_BASE;
74}
Rick Chencea16d02018-05-29 11:07:53 +080075
76int smc_init(void)
77{
78 int node = -1;
79 const char *compat = "andestech,atfsmc020";
80 void *blob = (void *)gd->fdt_blob;
81 fdt_addr_t addr;
82 struct ftsmc020_bank *regs;
83
84 node = fdt_node_offset_by_compatible(blob, -1, compat);
85 if (node < 0)
86 return -FDT_ERR_NOTFOUND;
87
88 addr = fdtdec_get_addr(blob, node, "reg");
89
90 if (addr == FDT_ADDR_T_NONE)
91 return -EINVAL;
92
93 regs = (struct ftsmc020_bank *)addr;
94 regs->cr &= ~FTSMC020_BANK_WPROT;
95
96 return 0;
97}
98
99#ifdef CONFIG_BOARD_EARLY_INIT_F
100int board_early_init_f(void)
101{
102 smc_init();
103
104 return 0;
105}
106#endif