blob: bda7ccce077b6a5b282bfcc3cc188f47de68e7df [file] [log] [blame]
Priyanka Jain58c3e622018-11-28 13:04:27 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
Priyanka Jainedc975b2019-02-04 06:32:36 +00003 * Copyright 2018-2019 NXP
Priyanka Jain58c3e622018-11-28 13:04:27 +00004 */
5
6#include <common.h>
7#include <dm.h>
8#include <dm/platform_data/serial_pl01x.h>
9#include <i2c.h>
10#include <malloc.h>
11#include <errno.h>
12#include <netdev.h>
13#include <fsl_ddr.h>
14#include <fsl_sec.h>
15#include <asm/io.h>
16#include <fdt_support.h>
17#include <linux/libfdt.h>
18#include <fsl-mc/fsl_mc.h>
19#include <environment.h>
20#include <efi_loader.h>
21#include <asm/arch/mmu.h>
22#include <hwconfig.h>
23#include <asm/arch/fsl_serdes.h>
24#include <asm/arch/soc.h>
25#include "../common/qixis.h"
26#include "../common/vid.h"
27#include <fsl_immap.h>
28
Meenakshi Aggarwal938e35e2018-11-30 22:32:12 +053029#ifdef CONFIG_EMC2305
30#include "../common/emc2305.h"
31#endif
32
Priyanka Jain58c3e622018-11-28 13:04:27 +000033DECLARE_GLOBAL_DATA_PTR;
34
35static struct pl01x_serial_platdata serial0 = {
36#if CONFIG_CONS_INDEX == 0
37 .base = CONFIG_SYS_SERIAL0,
38#elif CONFIG_CONS_INDEX == 1
39 .base = CONFIG_SYS_SERIAL1,
40#else
41#error "Unsupported console index value."
42#endif
43 .type = TYPE_PL011,
44};
45
46U_BOOT_DEVICE(nxp_serial0) = {
47 .name = "serial_pl01x",
48 .platdata = &serial0,
49};
50
51static struct pl01x_serial_platdata serial1 = {
52 .base = CONFIG_SYS_SERIAL1,
53 .type = TYPE_PL011,
54};
55
56U_BOOT_DEVICE(nxp_serial1) = {
57 .name = "serial_pl01x",
58 .platdata = &serial1,
59};
60
61int select_i2c_ch_pca9547(u8 ch)
62{
63 int ret;
64
65 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
66 if (ret) {
67 puts("PCA: failed to select proper channel\n");
68 return ret;
69 }
70
71 return 0;
72}
73
74static void uart_get_clock(void)
75{
76 serial0.clock = get_serial_clock();
77 serial1.clock = get_serial_clock();
78}
79
80int board_early_init_f(void)
81{
82#ifdef CONFIG_SYS_I2C_EARLY_INIT
83 i2c_early_init_f();
84#endif
85 /* get required clock for UART IP */
86 uart_get_clock();
87
Meenakshi Aggarwal938e35e2018-11-30 22:32:12 +053088#ifdef CONFIG_EMC2305
89 select_i2c_ch_pca9547(I2C_MUX_CH_EMC2305);
90 emc2305_init();
91 set_fan_speed(I2C_EMC2305_PWM);
92 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
93#endif
94
Priyanka Jain58c3e622018-11-28 13:04:27 +000095 fsl_lsch3_early_init_f();
96 return 0;
97}
98
99int esdhc_status_fixup(void *blob, const char *compat)
100{
101 /* Enable both esdhc DT nodes for LX2160ARDB */
102 do_fixup_by_compat(blob, compat, "status", "okay",
103 sizeof("okay"), 1);
104
105 return 0;
106}
107
108#if defined(CONFIG_VID)
109int i2c_multiplexer_select_vid_channel(u8 channel)
110{
111 return select_i2c_ch_pca9547(channel);
112}
113
Priyanka Jainedc975b2019-02-04 06:32:36 +0000114int init_func_vid(void)
115{
116 if (adjust_vdd(0) < 0)
117 printf("core voltage not adjusted\n");
118
119 return 0;
120}
Priyanka Jain58c3e622018-11-28 13:04:27 +0000121#endif
122
123int checkboard(void)
124{
125 enum boot_src src = get_boot_src();
126 char buf[64];
127 u8 sw;
128
129 cpu_name(buf);
130 printf("Board: %s-RDB, ", buf);
131
132 sw = QIXIS_READ(arch);
133 printf("Board version: %c, boot from ", (sw & 0xf) - 1 + 'A');
134
135 if (src == BOOT_SOURCE_SD_MMC) {
136 puts("SD\n");
137 } else {
138 sw = QIXIS_READ(brdcfg[0]);
139 sw = (sw >> QIXIS_XMAP_SHIFT) & QIXIS_XMAP_MASK;
140 switch (sw) {
141 case 0:
142 case 4:
143 puts("FlexSPI DEV#0\n");
144 break;
145 case 1:
146 puts("FlexSPI DEV#1\n");
147 break;
148 case 2:
149 case 3:
150 puts("FlexSPI EMU\n");
151 break;
152 default:
153 printf("invalid setting, xmap: %d\n", sw);
154 break;
155 }
156 }
157 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
158
159 puts("SERDES1 Reference: Clock1 = 161.13MHz Clock2 = 161.13MHz\n");
160 puts("SERDES2 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
161 puts("SERDES3 Reference: Clock1 = 100MHz Clock2 = 100Hz\n");
162 return 0;
163}
164
165unsigned long get_board_sys_clk(void)
166{
167 return 100000000;
168}
169
170unsigned long get_board_ddr_clk(void)
171{
172 return 100000000;
173}
174
175int board_init(void)
176{
177#ifdef CONFIG_ENV_IS_NOWHERE
178 gd->env_addr = (ulong)&default_environment[0];
179#endif
180
181 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
182
183#ifdef CONFIG_FSL_CAAM
184 sec_init();
185#endif
186
187 return 0;
188}
189
190void detail_board_ddr_info(void)
191{
192 int i;
193 u64 ddr_size = 0;
194
195 puts("\nDDR ");
196 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
197 ddr_size += gd->bd->bi_dram[i].size;
198 print_size(ddr_size, "");
199 print_ddr_info(0);
200}
201
202#if defined(CONFIG_ARCH_MISC_INIT)
203int arch_misc_init(void)
204{
205 return 0;
206}
207#endif
208
209#ifdef CONFIG_FSL_MC_ENET
210extern int fdt_fixup_board_phy(void *fdt);
211
212void fdt_fixup_board_enet(void *fdt)
213{
214 int offset;
215
216 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
217
218 if (offset < 0)
219 offset = fdt_path_offset(fdt, "/fsl-mc");
220
221 if (offset < 0) {
222 printf("%s: fsl-mc node not found in device tree (error %d)\n",
223 __func__, offset);
224 return;
225 }
226
227 if ((get_mc_boot_status() == 0) && (get_dpl_apply_status() == 0)) {
228 fdt_status_okay(fdt, offset);
229 fdt_fixup_board_phy(fdt);
230 } else {
231 fdt_status_fail(fdt, offset);
232 }
233}
234
235void board_quiesce_devices(void)
236{
237 fsl_mc_ldpaa_exit(gd->bd);
238}
239#endif
240
241#ifdef CONFIG_OF_BOARD_SETUP
242
243int ft_board_setup(void *blob, bd_t *bd)
244{
245 int i;
246 u64 base[CONFIG_NR_DRAM_BANKS];
247 u64 size[CONFIG_NR_DRAM_BANKS];
248
249 ft_cpu_setup(blob, bd);
250
251 /* fixup DT for the three GPP DDR banks */
252 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
253 base[i] = gd->bd->bi_dram[i].start;
254 size[i] = gd->bd->bi_dram[i].size;
255 }
256
257#ifdef CONFIG_RESV_RAM
258 /* reduce size if reserved memory is within this bank */
259 if (gd->arch.resv_ram >= base[0] &&
260 gd->arch.resv_ram < base[0] + size[0])
261 size[0] = gd->arch.resv_ram - base[0];
262 else if (gd->arch.resv_ram >= base[1] &&
263 gd->arch.resv_ram < base[1] + size[1])
264 size[1] = gd->arch.resv_ram - base[1];
265 else if (gd->arch.resv_ram >= base[2] &&
266 gd->arch.resv_ram < base[2] + size[2])
267 size[2] = gd->arch.resv_ram - base[2];
268#endif
269
270 fdt_fixup_memory_banks(blob, base, size, CONFIG_NR_DRAM_BANKS);
271
272#ifdef CONFIG_USB
273 fsl_fdt_fixup_dr_usb(blob, bd);
274#endif
275
276#ifdef CONFIG_FSL_MC_ENET
277 fdt_fsl_mc_fixup_iommu_map_entry(blob);
278 fdt_fixup_board_enet(blob);
279#endif
280
281 return 0;
282}
283#endif
284
285void qixis_dump_switch(void)
286{
287 int i, nr_of_cfgsw;
288
289 QIXIS_WRITE(cms[0], 0x00);
290 nr_of_cfgsw = QIXIS_READ(cms[1]);
291
292 puts("DIP switch settings dump:\n");
293 for (i = 1; i <= nr_of_cfgsw; i++) {
294 QIXIS_WRITE(cms[0], i);
295 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
296 }
297}