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/fdt.h>
15 #include <asm/arch/mmu.h>
16 #include <asm/arch/soc.h>
23 #include <fsl_esdhc.h>
28 #include "../common/vid.h"
29 #include "../common/qixis.h"
30 #include "ls1046aqds_qixis.h"
32 DECLARE_GLOBAL_DATA_PTR;
41 #ifndef CONFIG_SD_BOOT
45 puts("Board: LS1046AQDS, boot from ");
50 sw = QIXIS_READ(brdcfg[0]);
51 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
54 printf("vBank: %d\n", sw);
62 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
65 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
66 QIXIS_READ(id), QIXIS_READ(arch));
68 printf("FPGA: v%d (%s), build %d\n",
69 (int)QIXIS_READ(scver), qixis_read_tag(buf),
70 (int)qixis_read_minor());
75 bool if_board_diff_clk(void)
77 u8 diff_conf = QIXIS_READ(brdcfg[11]);
79 return diff_conf & 0x40;
82 unsigned long get_board_sys_clk(void)
84 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
86 switch (sysclk_conf & 0x0f) {
91 case QIXIS_SYSCLK_100:
93 case QIXIS_SYSCLK_125:
95 case QIXIS_SYSCLK_133:
97 case QIXIS_SYSCLK_150:
99 case QIXIS_SYSCLK_160:
101 case QIXIS_SYSCLK_166:
108 unsigned long get_board_ddr_clk(void)
110 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
112 if (if_board_diff_clk())
113 return get_board_sys_clk();
114 switch ((ddrclk_conf & 0x30) >> 4) {
115 case QIXIS_DDRCLK_100:
117 case QIXIS_DDRCLK_125:
119 case QIXIS_DDRCLK_133:
127 u32 get_lpuart_clk(void)
133 int select_i2c_ch_pca9547(u8 ch)
137 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
139 puts("PCA: failed to select proper channel\n");
149 * When resuming from deep sleep, the I2C channel may not be
150 * in the default channel. So, switch to the default channel
151 * before accessing DDR SPD.
153 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
155 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
156 /* This will break-before-make MMU for DDR */
157 update_early_mmu_table();
163 int i2c_multiplexer_select_vid_channel(u8 channel)
165 return select_i2c_ch_pca9547(channel);
168 int board_early_init_f(void)
170 #ifdef CONFIG_HAS_FSL_XHCI_USB
171 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
178 #ifdef CONFIG_SYS_I2C_EARLY_INIT
181 fsl_lsch2_early_init_f();
183 #ifdef CONFIG_HAS_FSL_XHCI_USB
184 out_be32(&scfg->rcwpmuxcr0, 0x3333);
185 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
186 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
187 SCFG_USBPWRFAULT_USB3_SHIFT) |
188 (SCFG_USBPWRFAULT_DEDICATED <<
189 SCFG_USBPWRFAULT_USB2_SHIFT) |
190 (SCFG_USBPWRFAULT_SHARED <<
191 SCFG_USBPWRFAULT_USB1_SHIFT);
192 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
196 /* We use lpuart0 as system console */
197 uart = QIXIS_READ(brdcfg[14]);
198 uart &= ~CFG_UART_MUX_MASK;
199 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
200 QIXIS_WRITE(brdcfg[14], uart);
206 #ifdef CONFIG_FSL_DEEP_SLEEP
207 /* determine if it is a warm boot */
208 bool is_warm_boot(void)
210 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
211 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
213 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
220 int config_board_mux(int ctrl_type)
224 reg14 = QIXIS_READ(brdcfg[14]);
228 reg14 = (reg14 & (~0x6)) | 0x2;
231 puts("Unsupported mux interface type\n");
235 QIXIS_WRITE(brdcfg[14], reg14);
240 int config_serdes_mux(void)
245 #ifdef CONFIG_MISC_INIT_R
246 int misc_init_r(void)
248 if (hwconfig("gpio"))
249 config_board_mux(MUX_TYPE_GPIO);
257 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
259 #ifdef CONFIG_SYS_FSL_SERDES
263 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
264 enable_layerscape_ns_access();
268 printf("Warning: Adjusting core voltage failed.\n");
270 #ifdef CONFIG_SECURE_BOOT
272 * In case of Secure Boot, the IBR configures the SMMU
273 * to allow only Secure transactions.
274 * SMMU must be reset in bypass mode.
275 * Set the ClientPD bit and Clear the USFCFG Bit
278 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
279 out_le32(SMMU_SCR0, val);
280 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
281 out_le32(SMMU_NSCR0, val);
284 #ifdef CONFIG_FSL_CAAM
291 #ifdef CONFIG_OF_BOARD_SETUP
292 int ft_board_setup(void *blob, bd_t *bd)
294 u64 base[CONFIG_NR_DRAM_BANKS];
295 u64 size[CONFIG_NR_DRAM_BANKS];
298 /* fixup DT for the two DDR banks */
299 base[0] = gd->bd->bi_dram[0].start;
300 size[0] = gd->bd->bi_dram[0].size;
301 base[1] = gd->bd->bi_dram[1].start;
302 size[1] = gd->bd->bi_dram[1].size;
304 fdt_fixup_memory_banks(blob, base, size, 2);
305 ft_cpu_setup(blob, bd);
307 #ifdef CONFIG_SYS_DPAA_FMAN
308 fdt_fixup_fman_ethernet(blob);
309 fdt_fixup_board_enet(blob);
312 reg = QIXIS_READ(brdcfg[0]);
313 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
315 /* Disable IFC if QSPI is enabled */
317 do_fixup_by_compat(blob, "fsl,ifc",
318 "status", "disabled", 8 + 1, 1);
324 u8 flash_read8(void *addr)
326 return __raw_readb(addr + 1);
329 void flash_write16(u16 val, void *addr)
331 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
333 __raw_writew(shftval, addr);
336 u16 flash_read16(void *addr)
338 u16 val = __raw_readw(addr);
340 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);