Merge tag 'u-boot-amlogic-20181207' of git://git.denx.de/u-boot-amlogic
[platform/kernel/u-boot.git] / board / AndesTech / ax25-ae350 / ax25-ae350.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2017 Andes Technology Corporation
4  * Rick Chen, Andes Technology Corporation <rick@andestech.com>
5  */
6
7 #include <common.h>
8 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
9 #include <netdev.h>
10 #endif
11 #include <linux/io.h>
12 #include <faraday/ftsmc020.h>
13 #include <fdtdec.h>
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 extern phys_addr_t prior_stage_fdt_address;
18 /*
19  * Miscellaneous platform dependent initializations
20  */
21
22 int board_init(void)
23 {
24         gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400;
25
26         return 0;
27 }
28
29 int 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
46 int 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)
57 int board_eth_init(bd_t *bd)
58 {
59         return ftmac100_initialize(bd);
60 }
61 #endif
62
63 ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
64 {
65         return 0;
66 }
67
68 void *board_fdt_blob_setup(void)
69 {
70         void **ptr = (void *)&prior_stage_fdt_address;
71         if (fdt_magic(*ptr) == FDT_MAGIC)
72                         return (void *)*ptr;
73
74         return (void *)CONFIG_SYS_FDT_BASE;
75 }
76
77 int 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
101 int board_early_init_f(void)
102 {
103         smc_init();
104
105         return 0;
106 }
107 #endif