2 * Copyright 2016 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <fdt_support.h>
10 #include <fsl_ddr_sdram.h>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/fsl_serdes.h>
14 #include <asm/arch/ppa.h>
15 #include <asm/arch/fdt.h>
16 #include <asm/arch/mmu.h>
17 #include <asm/arch/soc.h>
24 #include <fsl_esdhc.h>
29 #include "../common/vid.h"
30 #include "../common/qixis.h"
31 #include "ls1046aqds_qixis.h"
33 DECLARE_GLOBAL_DATA_PTR;
42 #ifndef CONFIG_SD_BOOT
46 puts("Board: LS1046AQDS, boot from ");
51 sw = QIXIS_READ(brdcfg[0]);
52 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
55 printf("vBank: %d\n", sw);
63 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
66 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
67 QIXIS_READ(id), QIXIS_READ(arch));
69 printf("FPGA: v%d (%s), build %d\n",
70 (int)QIXIS_READ(scver), qixis_read_tag(buf),
71 (int)qixis_read_minor());
76 bool if_board_diff_clk(void)
78 u8 diff_conf = QIXIS_READ(brdcfg[11]);
80 return diff_conf & 0x40;
83 unsigned long get_board_sys_clk(void)
85 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
87 switch (sysclk_conf & 0x0f) {
92 case QIXIS_SYSCLK_100:
94 case QIXIS_SYSCLK_125:
96 case QIXIS_SYSCLK_133:
98 case QIXIS_SYSCLK_150:
100 case QIXIS_SYSCLK_160:
102 case QIXIS_SYSCLK_166:
109 unsigned long get_board_ddr_clk(void)
111 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
113 if (if_board_diff_clk())
114 return get_board_sys_clk();
115 switch ((ddrclk_conf & 0x30) >> 4) {
116 case QIXIS_DDRCLK_100:
118 case QIXIS_DDRCLK_125:
120 case QIXIS_DDRCLK_133:
128 u32 get_lpuart_clk(void)
134 int select_i2c_ch_pca9547(u8 ch)
138 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
140 puts("PCA: failed to select proper channel\n");
150 * When resuming from deep sleep, the I2C channel may not be
151 * in the default channel. So, switch to the default channel
152 * before accessing DDR SPD.
154 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
156 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
157 /* This will break-before-make MMU for DDR */
158 update_early_mmu_table();
164 int i2c_multiplexer_select_vid_channel(u8 channel)
166 return select_i2c_ch_pca9547(channel);
169 int board_early_init_f(void)
171 #ifdef CONFIG_HAS_FSL_XHCI_USB
172 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
179 #ifdef CONFIG_SYS_I2C_EARLY_INIT
182 fsl_lsch2_early_init_f();
184 #ifdef CONFIG_HAS_FSL_XHCI_USB
185 out_be32(&scfg->rcwpmuxcr0, 0x3333);
186 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
187 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
188 SCFG_USBPWRFAULT_USB3_SHIFT) |
189 (SCFG_USBPWRFAULT_DEDICATED <<
190 SCFG_USBPWRFAULT_USB2_SHIFT) |
191 (SCFG_USBPWRFAULT_SHARED <<
192 SCFG_USBPWRFAULT_USB1_SHIFT);
193 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
197 /* We use lpuart0 as system console */
198 uart = QIXIS_READ(brdcfg[14]);
199 uart &= ~CFG_UART_MUX_MASK;
200 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
201 QIXIS_WRITE(brdcfg[14], uart);
207 #ifdef CONFIG_FSL_DEEP_SLEEP
208 /* determine if it is a warm boot */
209 bool is_warm_boot(void)
211 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
212 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
214 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
221 int config_board_mux(int ctrl_type)
225 reg14 = QIXIS_READ(brdcfg[14]);
229 reg14 = (reg14 & (~0x6)) | 0x2;
232 puts("Unsupported mux interface type\n");
236 QIXIS_WRITE(brdcfg[14], reg14);
241 int config_serdes_mux(void)
246 #ifdef CONFIG_MISC_INIT_R
247 int misc_init_r(void)
249 if (hwconfig("gpio"))
250 config_board_mux(MUX_TYPE_GPIO);
258 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
260 #ifdef CONFIG_SYS_FSL_SERDES
265 printf("Warning: Adjusting core voltage failed.\n");
267 #ifdef CONFIG_FSL_LS_PPA
271 #ifdef CONFIG_SECURE_BOOT
273 * In case of Secure Boot, the IBR configures the SMMU
274 * to allow only Secure transactions.
275 * SMMU must be reset in bypass mode.
276 * Set the ClientPD bit and Clear the USFCFG Bit
279 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
280 out_le32(SMMU_SCR0, val);
281 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
282 out_le32(SMMU_NSCR0, val);
285 #ifdef CONFIG_FSL_CAAM
292 #ifdef CONFIG_OF_BOARD_SETUP
293 int ft_board_setup(void *blob, bd_t *bd)
295 u64 base[CONFIG_NR_DRAM_BANKS];
296 u64 size[CONFIG_NR_DRAM_BANKS];
299 /* fixup DT for the two DDR banks */
300 base[0] = gd->bd->bi_dram[0].start;
301 size[0] = gd->bd->bi_dram[0].size;
302 base[1] = gd->bd->bi_dram[1].start;
303 size[1] = gd->bd->bi_dram[1].size;
305 fdt_fixup_memory_banks(blob, base, size, 2);
306 ft_cpu_setup(blob, bd);
308 #ifdef CONFIG_SYS_DPAA_FMAN
309 fdt_fixup_fman_ethernet(blob);
310 fdt_fixup_board_enet(blob);
313 reg = QIXIS_READ(brdcfg[0]);
314 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
316 /* Disable IFC if QSPI is enabled */
318 do_fixup_by_compat(blob, "fsl,ifc",
319 "status", "disabled", 8 + 1, 1);
325 u8 flash_read8(void *addr)
327 return __raw_readb(addr + 1);
330 void flash_write16(u16 val, void *addr)
332 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
334 __raw_writew(shftval, addr);
337 u16 flash_read16(void *addr)
339 u16 val = __raw_readw(addr);
341 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);