2 * Copyright 2015 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>
22 #include <fsl_esdhc.h>
26 #include "../common/qixis.h"
27 #include "ls1043aqds_qixis.h"
29 DECLARE_GLOBAL_DATA_PTR;
35 /* LS1043AQDS serdes mux */
36 #define CFG_SD_MUX1_SLOT2 0x0 /* SLOT2 TX/RX0 */
37 #define CFG_SD_MUX1_SLOT1 0x1 /* SLOT1 TX/RX1 */
38 #define CFG_SD_MUX2_SLOT3 0x0 /* SLOT3 TX/RX0 */
39 #define CFG_SD_MUX2_SLOT1 0x1 /* SLOT1 TX/RX2 */
40 #define CFG_SD_MUX3_SLOT4 0x0 /* SLOT4 TX/RX0 */
41 #define CFG_SD_MUX3_MUX4 0x1 /* MUX4 */
42 #define CFG_SD_MUX4_SLOT3 0x0 /* SLOT3 TX/RX1 */
43 #define CFG_SD_MUX4_SLOT1 0x1 /* SLOT1 TX/RX3 */
44 #define CFG_UART_MUX_MASK 0x6
45 #define CFG_UART_MUX_SHIFT 1
46 #define CFG_LPUART_EN 0x1
51 #ifndef CONFIG_SD_BOOT
55 puts("Board: LS1043AQDS, boot from ");
60 sw = QIXIS_READ(brdcfg[0]);
61 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
64 printf("vBank: %d\n", sw);
72 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
75 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
76 QIXIS_READ(id), QIXIS_READ(arch));
78 printf("FPGA: v%d (%s), build %d\n",
79 (int)QIXIS_READ(scver), qixis_read_tag(buf),
80 (int)qixis_read_minor());
85 bool if_board_diff_clk(void)
87 u8 diff_conf = QIXIS_READ(brdcfg[11]);
89 return diff_conf & 0x40;
92 unsigned long get_board_sys_clk(void)
94 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
96 switch (sysclk_conf & 0x0f) {
101 case QIXIS_SYSCLK_100:
103 case QIXIS_SYSCLK_125:
105 case QIXIS_SYSCLK_133:
107 case QIXIS_SYSCLK_150:
109 case QIXIS_SYSCLK_160:
111 case QIXIS_SYSCLK_166:
118 unsigned long get_board_ddr_clk(void)
120 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
122 if (if_board_diff_clk())
123 return get_board_sys_clk();
124 switch ((ddrclk_conf & 0x30) >> 4) {
125 case QIXIS_DDRCLK_100:
127 case QIXIS_DDRCLK_125:
129 case QIXIS_DDRCLK_133:
136 int select_i2c_ch_pca9547(u8 ch)
140 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
142 puts("PCA: failed to select proper channel\n");
152 * When resuming from deep sleep, the I2C channel may not be
153 * in the default channel. So, switch to the default channel
154 * before accessing DDR SPD.
156 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
158 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
159 /* This will break-before-make MMU for DDR */
160 update_early_mmu_table();
166 int i2c_multiplexer_select_vid_channel(u8 channel)
168 return select_i2c_ch_pca9547(channel);
171 void board_retimer_init(void)
175 /* Retimer is connected to I2C1_CH7_CH5 */
176 select_i2c_ch_pca9547(I2C_MUX_CH7);
178 i2c_write(I2C_MUX_PCA_ADDR_SEC, 0, 1, ®, 1);
180 /* Access to Control/Shared register */
182 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, ®, 1);
184 /* Read device revision and ID */
185 i2c_read(I2C_RETIMER_ADDR, 1, 1, ®, 1);
186 debug("Retimer version id = 0x%x\n", reg);
188 /* Enable Broadcast. All writes target all channel register sets */
190 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, ®, 1);
192 /* Reset Channel Registers */
193 i2c_read(I2C_RETIMER_ADDR, 0, 1, ®, 1);
195 i2c_write(I2C_RETIMER_ADDR, 0, 1, ®, 1);
197 /* Enable override divider select and Enable Override Output Mux */
198 i2c_read(I2C_RETIMER_ADDR, 9, 1, ®, 1);
200 i2c_write(I2C_RETIMER_ADDR, 9, 1, ®, 1);
202 /* Select VCO Divider to full rate (000) */
203 i2c_read(I2C_RETIMER_ADDR, 0x18, 1, ®, 1);
205 i2c_write(I2C_RETIMER_ADDR, 0x18, 1, ®, 1);
207 /* Selects active PFD MUX Input as Re-timed Data (001) */
208 i2c_read(I2C_RETIMER_ADDR, 0x1e, 1, ®, 1);
211 i2c_write(I2C_RETIMER_ADDR, 0x1e, 1, ®, 1);
213 /* Set data rate as 10.3125 Gbps */
215 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, ®, 1);
217 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, ®, 1);
219 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, ®, 1);
221 i2c_write(I2C_RETIMER_ADDR, 0x63, 1, ®, 1);
223 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, ®, 1);
225 /* Return the default channel */
226 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
229 int board_early_init_f(void)
231 #ifdef CONFIG_HAS_FSL_XHCI_USB
232 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
239 #ifdef CONFIG_SYS_I2C_EARLY_INIT
242 fsl_lsch2_early_init_f();
244 #ifdef CONFIG_HAS_FSL_XHCI_USB
245 out_be32(&scfg->rcwpmuxcr0, 0x3333);
246 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
248 (SCFG_USBPWRFAULT_DEDICATED << SCFG_USBPWRFAULT_USB3_SHIFT) |
249 (SCFG_USBPWRFAULT_DEDICATED << SCFG_USBPWRFAULT_USB2_SHIFT) |
250 (SCFG_USBPWRFAULT_SHARED << SCFG_USBPWRFAULT_USB1_SHIFT);
251 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
255 /* We use lpuart0 as system console */
256 uart = QIXIS_READ(brdcfg[14]);
257 uart &= ~CFG_UART_MUX_MASK;
258 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
259 QIXIS_WRITE(brdcfg[14], uart);
265 #ifdef CONFIG_FSL_DEEP_SLEEP
266 /* determine if it is a warm boot */
267 bool is_warm_boot(void)
269 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
270 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
272 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
279 int config_board_mux(int ctrl_type)
283 reg14 = QIXIS_READ(brdcfg[14]);
287 reg14 = (reg14 & (~0x30)) | 0x20;
290 puts("Unsupported mux interface type\n");
294 QIXIS_WRITE(brdcfg[14], reg14);
299 int config_serdes_mux(void)
305 #ifdef CONFIG_MISC_INIT_R
306 int misc_init_r(void)
308 if (hwconfig("gpio"))
309 config_board_mux(MUX_TYPE_GPIO);
317 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
321 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
322 board_retimer_init();
324 #ifdef CONFIG_SYS_FSL_SERDES
331 #ifdef CONFIG_OF_BOARD_SETUP
332 int ft_board_setup(void *blob, bd_t *bd)
334 u64 base[CONFIG_NR_DRAM_BANKS];
335 u64 size[CONFIG_NR_DRAM_BANKS];
338 /* fixup DT for the two DDR banks */
339 base[0] = gd->bd->bi_dram[0].start;
340 size[0] = gd->bd->bi_dram[0].size;
341 base[1] = gd->bd->bi_dram[1].start;
342 size[1] = gd->bd->bi_dram[1].size;
344 fdt_fixup_memory_banks(blob, base, size, 2);
345 ft_cpu_setup(blob, bd);
347 #ifdef CONFIG_SYS_DPAA_FMAN
348 fdt_fixup_fman_ethernet(blob);
349 fdt_fixup_board_enet(blob);
352 reg = QIXIS_READ(brdcfg[0]);
353 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
355 /* Disable IFC if QSPI is enabled */
357 do_fixup_by_compat(blob, "fsl,ifc",
358 "status", "disabled", 8 + 1, 1);
364 u8 flash_read8(void *addr)
366 return __raw_readb(addr + 1);
369 void flash_write16(u16 val, void *addr)
371 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
373 __raw_writew(shftval, addr);
376 u16 flash_read16(void *addr)
378 u16 val = __raw_readw(addr);
380 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);