f144bf6b37bf9ab5765b2cf4fc39c8444ee97cea
[pandora-u-boot.git] / board / freescale / ls2080a / ls2080a.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2014 Freescale Semiconductor
4  */
5 #include <common.h>
6 #include <malloc.h>
7 #include <errno.h>
8 #include <net.h>
9 #include <netdev.h>
10 #include <fsl_ifc.h>
11 #include <fsl_ddr.h>
12 #include <asm/io.h>
13 #include <fdt_support.h>
14 #include <linux/libfdt.h>
15 #include <fsl-mc/fsl_mc.h>
16 #include <env_internal.h>
17 #include <asm/arch/soc.h>
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 int board_init(void)
22 {
23         init_final_memctl_regs();
24
25 #ifdef CONFIG_ENV_IS_NOWHERE
26         gd->env_addr = (ulong)&default_environment[0];
27 #endif
28
29         return 0;
30 }
31
32 int board_early_init_f(void)
33 {
34         fsl_lsch3_early_init_f();
35         return 0;
36 }
37
38 void detail_board_ddr_info(void)
39 {
40         puts("\nDDR    ");
41         print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
42         print_ddr_info(0);
43 #ifdef CONFIG_SYS_FSL_HAS_DP_DDR
44         if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) {
45                 puts("\nDP-DDR ");
46                 print_size(gd->bd->bi_dram[2].size, "");
47                 print_ddr_info(CONFIG_DP_DDR_CTRL);
48         }
49 #endif
50 }
51
52 int board_eth_init(bd_t *bis)
53 {
54         int error = 0;
55
56 #ifdef CONFIG_SMC91111
57         error = smc91111_initialize(0, CONFIG_SMC91111_BASE);
58 #endif
59
60 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
61         error = cpu_eth_init(bis);
62 #endif
63         return error;
64 }
65
66 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
67 void fdt_fixup_board_enet(void *fdt)
68 {
69         int offset;
70
71         offset = fdt_path_offset(fdt, "/soc/fsl-mc");
72
73         /*
74          * TODO: Remove this when backward compatibility
75          * with old DT node (/fsl-mc) is no longer needed.
76          */
77         if (offset < 0)
78                 offset = fdt_path_offset(fdt, "/fsl-mc");
79
80         if (offset < 0) {
81                 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
82                        __func__, offset);
83                 return;
84         }
85
86         if (get_mc_boot_status() == 0 &&
87             (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
88                 fdt_status_okay(fdt, offset);
89         else
90                 fdt_status_fail(fdt, offset);
91 }
92
93 void board_quiesce_devices(void)
94 {
95         fsl_mc_ldpaa_exit(gd->bd);
96 }
97 #endif
98
99 #ifdef CONFIG_OF_BOARD_SETUP
100 int ft_board_setup(void *blob, bd_t *bd)
101 {
102         u64 base[CONFIG_NR_DRAM_BANKS];
103         u64 size[CONFIG_NR_DRAM_BANKS];
104
105         ft_cpu_setup(blob, bd);
106
107         /* fixup DT for the two GPP DDR banks */
108         base[0] = gd->bd->bi_dram[0].start;
109         size[0] = gd->bd->bi_dram[0].size;
110         base[1] = gd->bd->bi_dram[1].start;
111         size[1] = gd->bd->bi_dram[1].size;
112
113 #ifdef CONFIG_RESV_RAM
114         /* reduce size if reserved memory is within this bank */
115         if (gd->arch.resv_ram >= base[0] &&
116             gd->arch.resv_ram < base[0] + size[0])
117                 size[0] = gd->arch.resv_ram - base[0];
118         else if (gd->arch.resv_ram >= base[1] &&
119                  gd->arch.resv_ram < base[1] + size[1])
120                 size[1] = gd->arch.resv_ram - base[1];
121 #endif
122
123         fdt_fixup_memory_banks(blob, base, size, 2);
124
125         fdt_fsl_mc_fixup_iommu_map_entry(blob);
126
127 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
128         fdt_fixup_board_enet(blob);
129 #endif
130
131         return 0;
132 }
133 #endif
134
135 #if defined(CONFIG_RESET_PHY_R)
136 void reset_phy(void)
137 {
138 }
139 #endif
140
141 #ifdef CONFIG_TFABOOT
142 void *env_sf_get_env_addr(void)
143 {
144         return (void *)(CONFIG_SYS_FSL_QSPI_BASE1 + CONFIG_ENV_OFFSET);
145 }
146 #endif