blob: 5c94c83121b5af3819c83b6ab6054436b0faf5f8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
York Sun03017032015-03-20 19:28:23 -07002/*
3 * Copyright 2015 Freescale Semiconductor
Gaurav Jain476c6392022-03-24 11:50:35 +05304 * Copyright 2021 NXP
York Sun03017032015-03-20 19:28:23 -07005 */
6#include <common.h>
Tom Rini8c70baa2021-12-14 13:36:40 -05007#include <clock_legacy.h>
Simon Glass1ab16922022-07-31 12:28:48 -06008#include <display_options.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
York Sun03017032015-03-20 19:28:23 -070011#include <malloc.h>
12#include <errno.h>
13#include <netdev.h>
14#include <fsl_ifc.h>
15#include <fsl_ddr.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
York Sun03017032015-03-20 19:28:23 -070017#include <asm/io.h>
18#include <fdt_support.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090019#include <linux/libfdt.h>
York Sun03017032015-03-20 19:28:23 -070020#include <fsl-mc/fsl_mc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060021#include <env_internal.h>
York Sun03017032015-03-20 19:28:23 -070022#include <i2c.h>
Priyanka Jain2657e432015-06-29 15:39:40 +053023#include <rtc.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080024#include <asm/arch/soc.h>
Haikun Wanga6cd9da2015-06-26 19:58:12 +080025#include <hwconfig.h>
Laurentiu Tudor4adff392019-10-18 09:01:54 +000026#include <asm/arch-fsl-layerscape/fsl_icid.h>
Stephen Carlson4e979ac2021-06-22 16:42:02 -070027#include "../common/i2c_mux.h"
York Sun03017032015-03-20 19:28:23 -070028
29#include "../common/qixis.h"
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053030#include "ls2080aqds_qixis.h"
Priyanka Jain53e7ec02017-01-19 11:12:28 +053031#include "../common/vid.h"
York Sun03017032015-03-20 19:28:23 -070032
Haikun Wanga6cd9da2015-06-26 19:58:12 +080033#define PIN_MUX_SEL_SDHC 0x00
34#define PIN_MUX_SEL_DSPI 0x0a
Yuan Yao2ec85842016-06-08 18:24:52 +080035#define SCFG_QSPICLKCTRL_DIV_20 (5 << 27)
Haikun Wanga6cd9da2015-06-26 19:58:12 +080036
37#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
38
York Sun03017032015-03-20 19:28:23 -070039DECLARE_GLOBAL_DATA_PTR;
40
Haikun Wanga6cd9da2015-06-26 19:58:12 +080041enum {
42 MUX_TYPE_SDHC,
43 MUX_TYPE_DSPI,
44};
45
York Sun03017032015-03-20 19:28:23 -070046unsigned long long get_qixis_addr(void)
47{
48 unsigned long long addr;
49
50 if (gd->flags & GD_FLG_RELOC)
51 addr = QIXIS_BASE_PHYS;
52 else
53 addr = QIXIS_BASE_PHYS_EARLY;
54
55 /*
56 * IFC address under 256MB is mapped to 0x30000000, any address above
57 * is mapped to 0x5_10000000 up to 4GB.
58 */
59 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
60
61 return addr;
62}
63
64int checkboard(void)
65{
66 char buf[64];
67 u8 sw;
68 static const char *const freq[] = {"100", "125", "156.25",
69 "100 separate SSCG"};
70 int clock;
71
Prabhakar Kushwaha67f2e9c2015-05-28 14:54:07 +053072 cpu_name(buf);
73 printf("Board: %s-QDS, ", buf);
74
York Sun03017032015-03-20 19:28:23 -070075 sw = QIXIS_READ(arch);
York Sun03017032015-03-20 19:28:23 -070076 printf("Board Arch: V%d, ", sw >> 4);
77 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
78
Prabhakar Kushwaha67f2e9c2015-05-28 14:54:07 +053079 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
80
York Sun03017032015-03-20 19:28:23 -070081 sw = QIXIS_READ(brdcfg[0]);
82 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
83
84 if (sw < 0x8)
85 printf("vBank: %d\n", sw);
86 else if (sw == 0x8)
87 puts("PromJet\n");
88 else if (sw == 0x9)
89 puts("NAND\n");
Yuan Yao331c87c2016-06-08 18:25:00 +080090 else if (sw == 0xf)
91 puts("QSPI\n");
York Sun03017032015-03-20 19:28:23 -070092 else if (sw == 0x15)
93 printf("IFCCard\n");
94 else
95 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
96
97 printf("FPGA: v%d (%s), build %d",
98 (int)QIXIS_READ(scver), qixis_read_tag(buf),
99 (int)qixis_read_minor());
100 /* the timestamp string contains "\n" at the end */
101 printf(" on %s", qixis_read_time(buf));
102
103 /*
104 * Display the actual SERDES reference clocks as configured by the
105 * dip switches on the board. Note that the SWx registers could
106 * technically be set to force the reference clocks to match the
107 * values that the SERDES expects (or vice versa). For now, however,
108 * we just display both values and hope the user notices when they
109 * don't match.
110 */
111 puts("SERDES1 Reference : ");
112 sw = QIXIS_READ(brdcfg[2]);
113 clock = (sw >> 6) & 3;
114 printf("Clock1 = %sMHz ", freq[clock]);
115 clock = (sw >> 4) & 3;
116 printf("Clock2 = %sMHz", freq[clock]);
117
118 puts("\nSERDES2 Reference : ");
119 clock = (sw >> 2) & 3;
120 printf("Clock1 = %sMHz ", freq[clock]);
121 clock = (sw >> 0) & 3;
122 printf("Clock2 = %sMHz\n", freq[clock]);
123
124 return 0;
125}
126
127unsigned long get_board_sys_clk(void)
128{
129 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
130
131 switch (sysclk_conf & 0x0F) {
132 case QIXIS_SYSCLK_83:
133 return 83333333;
134 case QIXIS_SYSCLK_100:
135 return 100000000;
136 case QIXIS_SYSCLK_125:
137 return 125000000;
138 case QIXIS_SYSCLK_133:
139 return 133333333;
140 case QIXIS_SYSCLK_150:
141 return 150000000;
142 case QIXIS_SYSCLK_160:
143 return 160000000;
144 case QIXIS_SYSCLK_166:
145 return 166666666;
146 }
147 return 66666666;
148}
149
150unsigned long get_board_ddr_clk(void)
151{
152 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
153
154 switch ((ddrclk_conf & 0x30) >> 4) {
155 case QIXIS_DDRCLK_100:
156 return 100000000;
157 case QIXIS_DDRCLK_125:
158 return 125000000;
159 case QIXIS_DDRCLK_133:
160 return 133333333;
161 }
162 return 66666666;
163}
164
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800165int config_board_mux(int ctrl_type)
166{
167 u8 reg5;
168
169 reg5 = QIXIS_READ(brdcfg[5]);
170
171 switch (ctrl_type) {
172 case MUX_TYPE_SDHC:
173 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC);
174 break;
175 case MUX_TYPE_DSPI:
176 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI);
177 break;
178 default:
179 printf("Wrong mux interface type\n");
180 return -1;
181 }
182
183 QIXIS_WRITE(brdcfg[5], reg5);
184
185 return 0;
186}
187
York Sun03017032015-03-20 19:28:23 -0700188int board_init(void)
189{
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800190 char *env_hwconfig;
191 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
192 u32 val;
193
York Sun03017032015-03-20 19:28:23 -0700194 init_final_memctl_regs();
195
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800196 val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
197
Simon Glass64b723f2017-08-03 12:22:12 -0600198 env_hwconfig = env_get("hwconfig");
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800199
200 if (hwconfig_f("dspi", env_hwconfig) &&
201 DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
202 config_board_mux(MUX_TYPE_DSPI);
203 else
204 config_board_mux(MUX_TYPE_SDHC);
205
Miquel Raynald0935362019-10-03 19:50:03 +0200206#if defined(CONFIG_MTD_RAW_NAND) && defined(CONFIG_FSL_QSPI)
Yuan Yao86f42d72016-06-08 18:24:57 +0800207 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
208
209 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
210 QIXIS_WRITE(brdcfg[9],
211 (QIXIS_READ(brdcfg[9]) & 0xf8) |
212 FSL_QIXIS_BRDCFG9_QSPI);
213#endif
214
Stephen Carlson4e979ac2021-06-22 16:42:02 -0700215 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800216
Chuanhua Han4f97aac2019-07-26 19:24:00 +0800217#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
Igor Opaniukf7c91762021-02-09 13:52:45 +0200218#if CONFIG_IS_ENABLED(DM_I2C)
Tom Rini6a5dccc2022-11-16 13:10:41 -0500219 rtc_enable_32khz_output(0, CFG_SYS_I2C_RTC_ADDR);
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800220#else
Priyanka Jain2657e432015-06-29 15:39:40 +0530221 rtc_enable_32khz_output();
Chuanhua Han4f97aac2019-07-26 19:24:00 +0800222#endif
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800223#endif
224
Ioana Ciornei9d249b32023-02-15 17:31:18 +0200225#if !defined(CONFIG_SYS_EARLY_PCI_INIT)
Ioana Ciornei51a46492020-05-18 14:48:35 +0300226 pci_init();
227#endif
228
York Sun03017032015-03-20 19:28:23 -0700229 return 0;
230}
231
232int board_early_init_f(void)
233{
Tom Rini714482a2021-08-18 23:12:25 -0400234#if defined(CONFIG_SYS_I2C_EARLY_INIT)
Yuan Yao5a89cce2016-06-08 18:24:54 +0800235 i2c_early_init_f();
236#endif
York Sun03017032015-03-20 19:28:23 -0700237 fsl_lsch3_early_init_f();
Yuan Yao2ec85842016-06-08 18:24:52 +0800238#ifdef CONFIG_FSL_QSPI
239 /* input clk: 1/2 platform clk, output: input/20 */
240 out_le32(SCFG_BASE + SCFG_QSPICLKCTLR, SCFG_QSPICLKCTRL_DIV_20);
241#endif
York Sun03017032015-03-20 19:28:23 -0700242 return 0;
243}
244
Priyanka Jain53e7ec02017-01-19 11:12:28 +0530245int misc_init_r(void)
246{
247 if (adjust_vdd(0))
248 printf("Warning: Adjusting core voltage failed.\n");
249
250 return 0;
251}
252
York Sun03017032015-03-20 19:28:23 -0700253void detail_board_ddr_info(void)
254{
255 puts("\nDDR ");
256 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
257 print_ddr_info(0);
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530258#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
York Suncbe8e1c2016-04-04 11:41:26 -0700259 if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) {
York Sun03017032015-03-20 19:28:23 -0700260 puts("\nDP-DDR ");
261 print_size(gd->bd->bi_dram[2].size, "");
262 print_ddr_info(CONFIG_DP_DDR_CTRL);
263 }
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530264#endif
York Sun03017032015-03-20 19:28:23 -0700265}
266
Santan Kumar1afa9002017-05-05 15:42:29 +0530267#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun03017032015-03-20 19:28:23 -0700268void fdt_fixup_board_enet(void *fdt)
269{
270 int offset;
271
Stuart Yodera3466152016-03-02 16:37:13 -0600272 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
York Sun03017032015-03-20 19:28:23 -0700273
274 if (offset < 0)
Stuart Yodera3466152016-03-02 16:37:13 -0600275 offset = fdt_path_offset(fdt, "/fsl-mc");
York Sun03017032015-03-20 19:28:23 -0700276
277 if (offset < 0) {
278 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
279 __func__, offset);
280 return;
281 }
282
Mian Yousaf Kaukab97124652018-12-18 14:01:17 +0100283 if (get_mc_boot_status() == 0 &&
284 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
York Sun03017032015-03-20 19:28:23 -0700285 fdt_status_okay(fdt, offset);
286 else
287 fdt_status_fail(fdt, offset);
288}
Alexander Graf2ebeb442016-11-17 01:02:57 +0100289
290void board_quiesce_devices(void)
291{
292 fsl_mc_ldpaa_exit(gd->bd);
293}
York Sun03017032015-03-20 19:28:23 -0700294#endif
295
296#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900297int ft_board_setup(void *blob, struct bd_info *bd)
York Sun03017032015-03-20 19:28:23 -0700298{
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530299 u64 base[CONFIG_NR_DRAM_BANKS];
300 u64 size[CONFIG_NR_DRAM_BANKS];
York Sun03017032015-03-20 19:28:23 -0700301
302 ft_cpu_setup(blob, bd);
303
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530304 /* fixup DT for the two GPP DDR banks */
305 base[0] = gd->bd->bi_dram[0].start;
306 size[0] = gd->bd->bi_dram[0].size;
307 base[1] = gd->bd->bi_dram[1].start;
308 size[1] = gd->bd->bi_dram[1].size;
309
York Sun4de24ef2017-03-06 09:02:28 -0800310#ifdef CONFIG_RESV_RAM
311 /* reduce size if reserved memory is within this bank */
312 if (gd->arch.resv_ram >= base[0] &&
313 gd->arch.resv_ram < base[0] + size[0])
314 size[0] = gd->arch.resv_ram - base[0];
315 else if (gd->arch.resv_ram >= base[1] &&
316 gd->arch.resv_ram < base[1] + size[1])
317 size[1] = gd->arch.resv_ram - base[1];
318#endif
319
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530320 fdt_fixup_memory_banks(blob, base, size, 2);
York Sun03017032015-03-20 19:28:23 -0700321
Nipun Guptad6912642018-08-20 16:01:14 +0530322 fdt_fsl_mc_fixup_iommu_map_entry(blob);
323
Sriram Dash9fd465c2016-09-16 17:12:15 +0530324 fsl_fdt_fixup_dr_usb(blob, bd);
Sriram Dash01820952016-06-13 09:58:36 +0530325
Santan Kumar1afa9002017-05-05 15:42:29 +0530326#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun03017032015-03-20 19:28:23 -0700327 fdt_fixup_board_enet(blob);
Laurentiu Tudoraa98c022023-09-27 18:30:48 +0300328 fdt_reserve_mc_mem(blob, 0x300);
York Sun03017032015-03-20 19:28:23 -0700329#endif
330
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000331 fdt_fixup_icid(blob);
332
York Sun03017032015-03-20 19:28:23 -0700333 return 0;
334}
335#endif
336
337void qixis_dump_switch(void)
338{
339 int i, nr_of_cfgsw;
340
341 QIXIS_WRITE(cms[0], 0x00);
342 nr_of_cfgsw = QIXIS_READ(cms[1]);
343
344 puts("DIP switch settings dump:\n");
345 for (i = 1; i <= nr_of_cfgsw; i++) {
346 QIXIS_WRITE(cms[0], i);
347 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
348 }
349}