blob: 5df85722d1df2efd1da5d8ef400f8040deab6e81 [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>
Santan Kumarc61c6992017-03-07 11:21:03 +053026#include <asm/arch/ppa.h>
Laurentiu Tudor4adff392019-10-18 09:01:54 +000027#include <asm/arch-fsl-layerscape/fsl_icid.h>
Stephen Carlson4e979ac2021-06-22 16:42:02 -070028#include "../common/i2c_mux.h"
York Sun03017032015-03-20 19:28:23 -070029
30#include "../common/qixis.h"
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053031#include "ls2080aqds_qixis.h"
Priyanka Jain53e7ec02017-01-19 11:12:28 +053032#include "../common/vid.h"
York Sun03017032015-03-20 19:28:23 -070033
Haikun Wanga6cd9da2015-06-26 19:58:12 +080034#define PIN_MUX_SEL_SDHC 0x00
35#define PIN_MUX_SEL_DSPI 0x0a
Yuan Yao2ec85842016-06-08 18:24:52 +080036#define SCFG_QSPICLKCTRL_DIV_20 (5 << 27)
Haikun Wanga6cd9da2015-06-26 19:58:12 +080037
38#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
39
York Sun03017032015-03-20 19:28:23 -070040DECLARE_GLOBAL_DATA_PTR;
41
Haikun Wanga6cd9da2015-06-26 19:58:12 +080042enum {
43 MUX_TYPE_SDHC,
44 MUX_TYPE_DSPI,
45};
46
York Sun03017032015-03-20 19:28:23 -070047unsigned long long get_qixis_addr(void)
48{
49 unsigned long long addr;
50
51 if (gd->flags & GD_FLG_RELOC)
52 addr = QIXIS_BASE_PHYS;
53 else
54 addr = QIXIS_BASE_PHYS_EARLY;
55
56 /*
57 * IFC address under 256MB is mapped to 0x30000000, any address above
58 * is mapped to 0x5_10000000 up to 4GB.
59 */
60 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
61
62 return addr;
63}
64
65int checkboard(void)
66{
67 char buf[64];
68 u8 sw;
69 static const char *const freq[] = {"100", "125", "156.25",
70 "100 separate SSCG"};
71 int clock;
72
Prabhakar Kushwaha67f2e9c2015-05-28 14:54:07 +053073 cpu_name(buf);
74 printf("Board: %s-QDS, ", buf);
75
York Sun03017032015-03-20 19:28:23 -070076 sw = QIXIS_READ(arch);
York Sun03017032015-03-20 19:28:23 -070077 printf("Board Arch: V%d, ", sw >> 4);
78 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
79
Prabhakar Kushwaha67f2e9c2015-05-28 14:54:07 +053080 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
81
York Sun03017032015-03-20 19:28:23 -070082 sw = QIXIS_READ(brdcfg[0]);
83 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
84
85 if (sw < 0x8)
86 printf("vBank: %d\n", sw);
87 else if (sw == 0x8)
88 puts("PromJet\n");
89 else if (sw == 0x9)
90 puts("NAND\n");
Yuan Yao331c87c2016-06-08 18:25:00 +080091 else if (sw == 0xf)
92 puts("QSPI\n");
York Sun03017032015-03-20 19:28:23 -070093 else if (sw == 0x15)
94 printf("IFCCard\n");
95 else
96 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
97
98 printf("FPGA: v%d (%s), build %d",
99 (int)QIXIS_READ(scver), qixis_read_tag(buf),
100 (int)qixis_read_minor());
101 /* the timestamp string contains "\n" at the end */
102 printf(" on %s", qixis_read_time(buf));
103
104 /*
105 * Display the actual SERDES reference clocks as configured by the
106 * dip switches on the board. Note that the SWx registers could
107 * technically be set to force the reference clocks to match the
108 * values that the SERDES expects (or vice versa). For now, however,
109 * we just display both values and hope the user notices when they
110 * don't match.
111 */
112 puts("SERDES1 Reference : ");
113 sw = QIXIS_READ(brdcfg[2]);
114 clock = (sw >> 6) & 3;
115 printf("Clock1 = %sMHz ", freq[clock]);
116 clock = (sw >> 4) & 3;
117 printf("Clock2 = %sMHz", freq[clock]);
118
119 puts("\nSERDES2 Reference : ");
120 clock = (sw >> 2) & 3;
121 printf("Clock1 = %sMHz ", freq[clock]);
122 clock = (sw >> 0) & 3;
123 printf("Clock2 = %sMHz\n", freq[clock]);
124
125 return 0;
126}
127
128unsigned long get_board_sys_clk(void)
129{
130 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
131
132 switch (sysclk_conf & 0x0F) {
133 case QIXIS_SYSCLK_83:
134 return 83333333;
135 case QIXIS_SYSCLK_100:
136 return 100000000;
137 case QIXIS_SYSCLK_125:
138 return 125000000;
139 case QIXIS_SYSCLK_133:
140 return 133333333;
141 case QIXIS_SYSCLK_150:
142 return 150000000;
143 case QIXIS_SYSCLK_160:
144 return 160000000;
145 case QIXIS_SYSCLK_166:
146 return 166666666;
147 }
148 return 66666666;
149}
150
151unsigned long get_board_ddr_clk(void)
152{
153 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
154
155 switch ((ddrclk_conf & 0x30) >> 4) {
156 case QIXIS_DDRCLK_100:
157 return 100000000;
158 case QIXIS_DDRCLK_125:
159 return 125000000;
160 case QIXIS_DDRCLK_133:
161 return 133333333;
162 }
163 return 66666666;
164}
165
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800166int config_board_mux(int ctrl_type)
167{
168 u8 reg5;
169
170 reg5 = QIXIS_READ(brdcfg[5]);
171
172 switch (ctrl_type) {
173 case MUX_TYPE_SDHC:
174 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC);
175 break;
176 case MUX_TYPE_DSPI:
177 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI);
178 break;
179 default:
180 printf("Wrong mux interface type\n");
181 return -1;
182 }
183
184 QIXIS_WRITE(brdcfg[5], reg5);
185
186 return 0;
187}
188
York Sun03017032015-03-20 19:28:23 -0700189int board_init(void)
190{
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800191 char *env_hwconfig;
192 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
193 u32 val;
194
York Sun03017032015-03-20 19:28:23 -0700195 init_final_memctl_regs();
196
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800197 val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
198
Simon Glass64b723f2017-08-03 12:22:12 -0600199 env_hwconfig = env_get("hwconfig");
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800200
201 if (hwconfig_f("dspi", env_hwconfig) &&
202 DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
203 config_board_mux(MUX_TYPE_DSPI);
204 else
205 config_board_mux(MUX_TYPE_SDHC);
206
Miquel Raynald0935362019-10-03 19:50:03 +0200207#if defined(CONFIG_MTD_RAW_NAND) && defined(CONFIG_FSL_QSPI)
Yuan Yao86f42d72016-06-08 18:24:57 +0800208 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
209
210 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
211 QIXIS_WRITE(brdcfg[9],
212 (QIXIS_READ(brdcfg[9]) & 0xf8) |
213 FSL_QIXIS_BRDCFG9_QSPI);
214#endif
215
Stephen Carlson4e979ac2021-06-22 16:42:02 -0700216 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800217
Chuanhua Han4f97aac2019-07-26 19:24:00 +0800218#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
Igor Opaniukf7c91762021-02-09 13:52:45 +0200219#if CONFIG_IS_ENABLED(DM_I2C)
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800220 rtc_enable_32khz_output(0, CONFIG_SYS_I2C_RTC_ADDR);
221#else
Priyanka Jain2657e432015-06-29 15:39:40 +0530222 rtc_enable_32khz_output();
Chuanhua Han4f97aac2019-07-26 19:24:00 +0800223#endif
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800224#endif
225
Santan Kumarc61c6992017-03-07 11:21:03 +0530226#ifdef CONFIG_FSL_LS_PPA
227 ppa_init();
228#endif
229
Ioana Ciornei51a46492020-05-18 14:48:35 +0300230#if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
231 pci_init();
232#endif
233
York Sun03017032015-03-20 19:28:23 -0700234 return 0;
235}
236
237int board_early_init_f(void)
238{
Tom Rini714482a2021-08-18 23:12:25 -0400239#if defined(CONFIG_SYS_I2C_EARLY_INIT)
Yuan Yao5a89cce2016-06-08 18:24:54 +0800240 i2c_early_init_f();
241#endif
York Sun03017032015-03-20 19:28:23 -0700242 fsl_lsch3_early_init_f();
Yuan Yao2ec85842016-06-08 18:24:52 +0800243#ifdef CONFIG_FSL_QSPI
244 /* input clk: 1/2 platform clk, output: input/20 */
245 out_le32(SCFG_BASE + SCFG_QSPICLKCTLR, SCFG_QSPICLKCTRL_DIV_20);
246#endif
York Sun03017032015-03-20 19:28:23 -0700247 return 0;
248}
249
Priyanka Jain53e7ec02017-01-19 11:12:28 +0530250int misc_init_r(void)
251{
252 if (adjust_vdd(0))
253 printf("Warning: Adjusting core voltage failed.\n");
254
255 return 0;
256}
257
York Sun03017032015-03-20 19:28:23 -0700258void detail_board_ddr_info(void)
259{
260 puts("\nDDR ");
261 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
262 print_ddr_info(0);
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530263#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
York Suncbe8e1c2016-04-04 11:41:26 -0700264 if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) {
York Sun03017032015-03-20 19:28:23 -0700265 puts("\nDP-DDR ");
266 print_size(gd->bd->bi_dram[2].size, "");
267 print_ddr_info(CONFIG_DP_DDR_CTRL);
268 }
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530269#endif
York Sun03017032015-03-20 19:28:23 -0700270}
271
Santan Kumar1afa9002017-05-05 15:42:29 +0530272#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun03017032015-03-20 19:28:23 -0700273void fdt_fixup_board_enet(void *fdt)
274{
275 int offset;
276
Stuart Yodera3466152016-03-02 16:37:13 -0600277 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
York Sun03017032015-03-20 19:28:23 -0700278
279 if (offset < 0)
Stuart Yodera3466152016-03-02 16:37:13 -0600280 offset = fdt_path_offset(fdt, "/fsl-mc");
York Sun03017032015-03-20 19:28:23 -0700281
282 if (offset < 0) {
283 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
284 __func__, offset);
285 return;
286 }
287
Mian Yousaf Kaukab97124652018-12-18 14:01:17 +0100288 if (get_mc_boot_status() == 0 &&
289 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
York Sun03017032015-03-20 19:28:23 -0700290 fdt_status_okay(fdt, offset);
291 else
292 fdt_status_fail(fdt, offset);
293}
Alexander Graf2ebeb442016-11-17 01:02:57 +0100294
295void board_quiesce_devices(void)
296{
297 fsl_mc_ldpaa_exit(gd->bd);
298}
York Sun03017032015-03-20 19:28:23 -0700299#endif
300
301#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900302int ft_board_setup(void *blob, struct bd_info *bd)
York Sun03017032015-03-20 19:28:23 -0700303{
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530304 u64 base[CONFIG_NR_DRAM_BANKS];
305 u64 size[CONFIG_NR_DRAM_BANKS];
York Sun03017032015-03-20 19:28:23 -0700306
307 ft_cpu_setup(blob, bd);
308
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530309 /* fixup DT for the two GPP DDR banks */
310 base[0] = gd->bd->bi_dram[0].start;
311 size[0] = gd->bd->bi_dram[0].size;
312 base[1] = gd->bd->bi_dram[1].start;
313 size[1] = gd->bd->bi_dram[1].size;
314
York Sun4de24ef2017-03-06 09:02:28 -0800315#ifdef CONFIG_RESV_RAM
316 /* reduce size if reserved memory is within this bank */
317 if (gd->arch.resv_ram >= base[0] &&
318 gd->arch.resv_ram < base[0] + size[0])
319 size[0] = gd->arch.resv_ram - base[0];
320 else if (gd->arch.resv_ram >= base[1] &&
321 gd->arch.resv_ram < base[1] + size[1])
322 size[1] = gd->arch.resv_ram - base[1];
323#endif
324
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530325 fdt_fixup_memory_banks(blob, base, size, 2);
York Sun03017032015-03-20 19:28:23 -0700326
Nipun Guptad6912642018-08-20 16:01:14 +0530327 fdt_fsl_mc_fixup_iommu_map_entry(blob);
328
Sriram Dash9fd465c2016-09-16 17:12:15 +0530329 fsl_fdt_fixup_dr_usb(blob, bd);
Sriram Dash01820952016-06-13 09:58:36 +0530330
Santan Kumar1afa9002017-05-05 15:42:29 +0530331#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun03017032015-03-20 19:28:23 -0700332 fdt_fixup_board_enet(blob);
York Sun03017032015-03-20 19:28:23 -0700333#endif
334
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000335 fdt_fixup_icid(blob);
336
York Sun03017032015-03-20 19:28:23 -0700337 return 0;
338}
339#endif
340
341void qixis_dump_switch(void)
342{
343 int i, nr_of_cfgsw;
344
345 QIXIS_WRITE(cms[0], 0x00);
346 nr_of_cfgsw = QIXIS_READ(cms[1]);
347
348 puts("DIP switch settings dump:\n");
349 for (i = 1; i <= nr_of_cfgsw; i++) {
350 QIXIS_WRITE(cms[0], i);
351 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
352 }
353}