blob: 3eb40f5e2a213caa95adf76bcbe772bd2d2646dc [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
York Sun03017032015-03-20 19:28:23 -07004 */
5#include <common.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06006#include <env.h>
Simon Glass97589732020-05-10 11:40:02 -06007#include <init.h>
York Sun03017032015-03-20 19:28:23 -07008#include <malloc.h>
9#include <errno.h>
10#include <netdev.h>
11#include <fsl_ifc.h>
12#include <fsl_ddr.h>
13#include <asm/io.h>
14#include <fdt_support.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090015#include <linux/libfdt.h>
York Sun03017032015-03-20 19:28:23 -070016#include <fsl-mc/fsl_mc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060017#include <env_internal.h>
York Sun03017032015-03-20 19:28:23 -070018#include <i2c.h>
Priyanka Jain2657e432015-06-29 15:39:40 +053019#include <rtc.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080020#include <asm/arch/soc.h>
Haikun Wanga6cd9da2015-06-26 19:58:12 +080021#include <hwconfig.h>
Saksham Jainc0c38d22016-03-23 16:24:35 +053022#include <fsl_sec.h>
Santan Kumarc61c6992017-03-07 11:21:03 +053023#include <asm/arch/ppa.h>
Laurentiu Tudor4adff392019-10-18 09:01:54 +000024#include <asm/arch-fsl-layerscape/fsl_icid.h>
Santan Kumarc61c6992017-03-07 11:21:03 +053025
York Sun03017032015-03-20 19:28:23 -070026
27#include "../common/qixis.h"
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053028#include "ls2080aqds_qixis.h"
Priyanka Jain53e7ec02017-01-19 11:12:28 +053029#include "../common/vid.h"
York Sun03017032015-03-20 19:28:23 -070030
Haikun Wanga6cd9da2015-06-26 19:58:12 +080031#define PIN_MUX_SEL_SDHC 0x00
32#define PIN_MUX_SEL_DSPI 0x0a
Yuan Yao2ec85842016-06-08 18:24:52 +080033#define SCFG_QSPICLKCTRL_DIV_20 (5 << 27)
Haikun Wanga6cd9da2015-06-26 19:58:12 +080034
35#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
36
York Sun03017032015-03-20 19:28:23 -070037DECLARE_GLOBAL_DATA_PTR;
38
Haikun Wanga6cd9da2015-06-26 19:58:12 +080039enum {
40 MUX_TYPE_SDHC,
41 MUX_TYPE_DSPI,
42};
43
York Sun03017032015-03-20 19:28:23 -070044unsigned long long get_qixis_addr(void)
45{
46 unsigned long long addr;
47
48 if (gd->flags & GD_FLG_RELOC)
49 addr = QIXIS_BASE_PHYS;
50 else
51 addr = QIXIS_BASE_PHYS_EARLY;
52
53 /*
54 * IFC address under 256MB is mapped to 0x30000000, any address above
55 * is mapped to 0x5_10000000 up to 4GB.
56 */
57 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
58
59 return addr;
60}
61
62int checkboard(void)
63{
64 char buf[64];
65 u8 sw;
66 static const char *const freq[] = {"100", "125", "156.25",
67 "100 separate SSCG"};
68 int clock;
69
Prabhakar Kushwaha67f2e9c2015-05-28 14:54:07 +053070 cpu_name(buf);
71 printf("Board: %s-QDS, ", buf);
72
York Sun03017032015-03-20 19:28:23 -070073 sw = QIXIS_READ(arch);
York Sun03017032015-03-20 19:28:23 -070074 printf("Board Arch: V%d, ", sw >> 4);
75 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
76
Prabhakar Kushwaha67f2e9c2015-05-28 14:54:07 +053077 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
78
York Sun03017032015-03-20 19:28:23 -070079 sw = QIXIS_READ(brdcfg[0]);
80 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
81
82 if (sw < 0x8)
83 printf("vBank: %d\n", sw);
84 else if (sw == 0x8)
85 puts("PromJet\n");
86 else if (sw == 0x9)
87 puts("NAND\n");
Yuan Yao331c87c2016-06-08 18:25:00 +080088 else if (sw == 0xf)
89 puts("QSPI\n");
York Sun03017032015-03-20 19:28:23 -070090 else if (sw == 0x15)
91 printf("IFCCard\n");
92 else
93 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
94
95 printf("FPGA: v%d (%s), build %d",
96 (int)QIXIS_READ(scver), qixis_read_tag(buf),
97 (int)qixis_read_minor());
98 /* the timestamp string contains "\n" at the end */
99 printf(" on %s", qixis_read_time(buf));
100
101 /*
102 * Display the actual SERDES reference clocks as configured by the
103 * dip switches on the board. Note that the SWx registers could
104 * technically be set to force the reference clocks to match the
105 * values that the SERDES expects (or vice versa). For now, however,
106 * we just display both values and hope the user notices when they
107 * don't match.
108 */
109 puts("SERDES1 Reference : ");
110 sw = QIXIS_READ(brdcfg[2]);
111 clock = (sw >> 6) & 3;
112 printf("Clock1 = %sMHz ", freq[clock]);
113 clock = (sw >> 4) & 3;
114 printf("Clock2 = %sMHz", freq[clock]);
115
116 puts("\nSERDES2 Reference : ");
117 clock = (sw >> 2) & 3;
118 printf("Clock1 = %sMHz ", freq[clock]);
119 clock = (sw >> 0) & 3;
120 printf("Clock2 = %sMHz\n", freq[clock]);
121
122 return 0;
123}
124
125unsigned long get_board_sys_clk(void)
126{
127 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
128
129 switch (sysclk_conf & 0x0F) {
130 case QIXIS_SYSCLK_83:
131 return 83333333;
132 case QIXIS_SYSCLK_100:
133 return 100000000;
134 case QIXIS_SYSCLK_125:
135 return 125000000;
136 case QIXIS_SYSCLK_133:
137 return 133333333;
138 case QIXIS_SYSCLK_150:
139 return 150000000;
140 case QIXIS_SYSCLK_160:
141 return 160000000;
142 case QIXIS_SYSCLK_166:
143 return 166666666;
144 }
145 return 66666666;
146}
147
148unsigned long get_board_ddr_clk(void)
149{
150 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
151
152 switch ((ddrclk_conf & 0x30) >> 4) {
153 case QIXIS_DDRCLK_100:
154 return 100000000;
155 case QIXIS_DDRCLK_125:
156 return 125000000;
157 case QIXIS_DDRCLK_133:
158 return 133333333;
159 }
160 return 66666666;
161}
162
163int select_i2c_ch_pca9547(u8 ch)
164{
165 int ret;
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800166#ifdef CONFIG_DM_I2C
167 struct udevice *dev;
York Sun03017032015-03-20 19:28:23 -0700168
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800169 ret = i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
170 if (!ret)
171 ret = dm_i2c_write(dev, 0, &ch, 1);
172
173#else
York Sun03017032015-03-20 19:28:23 -0700174 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800175#endif
York Sun03017032015-03-20 19:28:23 -0700176 if (ret) {
177 puts("PCA: failed to select proper channel\n");
178 return ret;
179 }
180
181 return 0;
182}
183
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800184int config_board_mux(int ctrl_type)
185{
186 u8 reg5;
187
188 reg5 = QIXIS_READ(brdcfg[5]);
189
190 switch (ctrl_type) {
191 case MUX_TYPE_SDHC:
192 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC);
193 break;
194 case MUX_TYPE_DSPI:
195 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI);
196 break;
197 default:
198 printf("Wrong mux interface type\n");
199 return -1;
200 }
201
202 QIXIS_WRITE(brdcfg[5], reg5);
203
204 return 0;
205}
206
York Sun03017032015-03-20 19:28:23 -0700207int board_init(void)
208{
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800209 char *env_hwconfig;
210 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
211 u32 val;
212
York Sun03017032015-03-20 19:28:23 -0700213 init_final_memctl_regs();
214
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800215 val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
216
Simon Glass64b723f2017-08-03 12:22:12 -0600217 env_hwconfig = env_get("hwconfig");
Haikun Wanga6cd9da2015-06-26 19:58:12 +0800218
219 if (hwconfig_f("dspi", env_hwconfig) &&
220 DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
221 config_board_mux(MUX_TYPE_DSPI);
222 else
223 config_board_mux(MUX_TYPE_SDHC);
224
Miquel Raynald0935362019-10-03 19:50:03 +0200225#if defined(CONFIG_MTD_RAW_NAND) && defined(CONFIG_FSL_QSPI)
Yuan Yao86f42d72016-06-08 18:24:57 +0800226 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
227
228 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
229 QIXIS_WRITE(brdcfg[9],
230 (QIXIS_READ(brdcfg[9]) & 0xf8) |
231 FSL_QIXIS_BRDCFG9_QSPI);
232#endif
233
York Sun03017032015-03-20 19:28:23 -0700234#ifdef CONFIG_ENV_IS_NOWHERE
235 gd->env_addr = (ulong)&default_environment[0];
236#endif
237 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800238
Chuanhua Han4f97aac2019-07-26 19:24:00 +0800239#ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800240#ifdef CONFIG_DM_I2C
241 rtc_enable_32khz_output(0, CONFIG_SYS_I2C_RTC_ADDR);
242#else
Priyanka Jain2657e432015-06-29 15:39:40 +0530243 rtc_enable_32khz_output();
Chuanhua Han4f97aac2019-07-26 19:24:00 +0800244#endif
Chuanhua Han1ab68c72019-07-26 19:24:01 +0800245#endif
246
Udit Agarwalc83ea8a2017-08-16 07:13:29 -0400247#ifdef CONFIG_FSL_CAAM
248 sec_init();
249#endif
Santan Kumarc61c6992017-03-07 11:21:03 +0530250
251#ifdef CONFIG_FSL_LS_PPA
252 ppa_init();
253#endif
254
Ioana Ciornei51a46492020-05-18 14:48:35 +0300255#if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
256 pci_init();
257#endif
258
York Sun03017032015-03-20 19:28:23 -0700259 return 0;
260}
261
262int board_early_init_f(void)
263{
Yuan Yao5a89cce2016-06-08 18:24:54 +0800264#ifdef CONFIG_SYS_I2C_EARLY_INIT
265 i2c_early_init_f();
266#endif
York Sun03017032015-03-20 19:28:23 -0700267 fsl_lsch3_early_init_f();
Yuan Yao2ec85842016-06-08 18:24:52 +0800268#ifdef CONFIG_FSL_QSPI
269 /* input clk: 1/2 platform clk, output: input/20 */
270 out_le32(SCFG_BASE + SCFG_QSPICLKCTLR, SCFG_QSPICLKCTRL_DIV_20);
271#endif
York Sun03017032015-03-20 19:28:23 -0700272 return 0;
273}
274
Priyanka Jain53e7ec02017-01-19 11:12:28 +0530275int misc_init_r(void)
276{
277 if (adjust_vdd(0))
278 printf("Warning: Adjusting core voltage failed.\n");
279
280 return 0;
281}
282
York Sun03017032015-03-20 19:28:23 -0700283void detail_board_ddr_info(void)
284{
285 puts("\nDDR ");
286 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
287 print_ddr_info(0);
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530288#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
York Suncbe8e1c2016-04-04 11:41:26 -0700289 if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) {
York Sun03017032015-03-20 19:28:23 -0700290 puts("\nDP-DDR ");
291 print_size(gd->bd->bi_dram[2].size, "");
292 print_ddr_info(CONFIG_DP_DDR_CTRL);
293 }
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530294#endif
York Sun03017032015-03-20 19:28:23 -0700295}
296
Santan Kumar1afa9002017-05-05 15:42:29 +0530297#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun03017032015-03-20 19:28:23 -0700298void fdt_fixup_board_enet(void *fdt)
299{
300 int offset;
301
Stuart Yodera3466152016-03-02 16:37:13 -0600302 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
York Sun03017032015-03-20 19:28:23 -0700303
304 if (offset < 0)
Stuart Yodera3466152016-03-02 16:37:13 -0600305 offset = fdt_path_offset(fdt, "/fsl-mc");
York Sun03017032015-03-20 19:28:23 -0700306
307 if (offset < 0) {
308 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
309 __func__, offset);
310 return;
311 }
312
Mian Yousaf Kaukab97124652018-12-18 14:01:17 +0100313 if (get_mc_boot_status() == 0 &&
314 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
York Sun03017032015-03-20 19:28:23 -0700315 fdt_status_okay(fdt, offset);
316 else
317 fdt_status_fail(fdt, offset);
318}
Alexander Graf2ebeb442016-11-17 01:02:57 +0100319
320void board_quiesce_devices(void)
321{
322 fsl_mc_ldpaa_exit(gd->bd);
323}
York Sun03017032015-03-20 19:28:23 -0700324#endif
325
326#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900327int ft_board_setup(void *blob, struct bd_info *bd)
York Sun03017032015-03-20 19:28:23 -0700328{
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530329 u64 base[CONFIG_NR_DRAM_BANKS];
330 u64 size[CONFIG_NR_DRAM_BANKS];
York Sun03017032015-03-20 19:28:23 -0700331
332 ft_cpu_setup(blob, bd);
333
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530334 /* fixup DT for the two GPP DDR banks */
335 base[0] = gd->bd->bi_dram[0].start;
336 size[0] = gd->bd->bi_dram[0].size;
337 base[1] = gd->bd->bi_dram[1].start;
338 size[1] = gd->bd->bi_dram[1].size;
339
York Sun4de24ef2017-03-06 09:02:28 -0800340#ifdef CONFIG_RESV_RAM
341 /* reduce size if reserved memory is within this bank */
342 if (gd->arch.resv_ram >= base[0] &&
343 gd->arch.resv_ram < base[0] + size[0])
344 size[0] = gd->arch.resv_ram - base[0];
345 else if (gd->arch.resv_ram >= base[1] &&
346 gd->arch.resv_ram < base[1] + size[1])
347 size[1] = gd->arch.resv_ram - base[1];
348#endif
349
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530350 fdt_fixup_memory_banks(blob, base, size, 2);
York Sun03017032015-03-20 19:28:23 -0700351
Nipun Guptad6912642018-08-20 16:01:14 +0530352 fdt_fsl_mc_fixup_iommu_map_entry(blob);
353
Sriram Dash9fd465c2016-09-16 17:12:15 +0530354 fsl_fdt_fixup_dr_usb(blob, bd);
Sriram Dash01820952016-06-13 09:58:36 +0530355
Santan Kumar1afa9002017-05-05 15:42:29 +0530356#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun03017032015-03-20 19:28:23 -0700357 fdt_fixup_board_enet(blob);
York Sun03017032015-03-20 19:28:23 -0700358#endif
359
Laurentiu Tudor4adff392019-10-18 09:01:54 +0000360 fdt_fixup_icid(blob);
361
York Sun03017032015-03-20 19:28:23 -0700362 return 0;
363}
364#endif
365
366void qixis_dump_switch(void)
367{
368 int i, nr_of_cfgsw;
369
370 QIXIS_WRITE(cms[0], 0x00);
371 nr_of_cfgsw = QIXIS_READ(cms[1]);
372
373 puts("DIP switch settings dump:\n");
374 for (i = 1; i <= nr_of_cfgsw; i++) {
375 QIXIS_WRITE(cms[0], i);
376 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
377 }
378}