blob: 8c96b962b7883279793cb66e1d0167e883a5e74f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shaohui Xie02b5d2e2015-11-11 17:58:37 +08002/*
3 * Copyright 2015 Freescale Semiconductor, Inc.
Shaohui Xie02b5d2e2015-11-11 17:58:37 +08004 */
5
6#include <common.h>
7#include <i2c.h>
8#include <fdt_support.h>
Simon Glass3eace372017-04-06 12:47:04 -06009#include <fsl_ddr_sdram.h>
Shaohui Xie02b5d2e2015-11-11 17:58:37 +080010#include <asm/io.h>
11#include <asm/arch/clock.h>
12#include <asm/arch/fsl_serdes.h>
Hou Zhiqiange1b09292017-04-14 14:48:21 +080013#include <asm/arch/ppa.h>
Shaohui Xie02b5d2e2015-11-11 17:58:37 +080014#include <asm/arch/fdt.h>
York Sun4961eaf2017-03-06 09:02:34 -080015#include <asm/arch/mmu.h>
Rajesh Bhagat8aa6b172018-11-05 18:02:48 +000016#include <asm/arch/cpu.h>
Shaohui Xie02b5d2e2015-11-11 17:58:37 +080017#include <asm/arch/soc.h>
Laurentiu Tudordc29a4c2018-08-27 17:33:59 +030018#include <asm/arch-fsl-layerscape/fsl_icid.h>
Shaohui Xie02b5d2e2015-11-11 17:58:37 +080019#include <ahci.h>
20#include <hwconfig.h>
21#include <mmc.h>
22#include <scsi.h>
23#include <fm_eth.h>
Shaohui Xie02b5d2e2015-11-11 17:58:37 +080024#include <fsl_esdhc.h>
25#include <fsl_ifc.h>
26#include <spl.h>
27
28#include "../common/qixis.h"
29#include "ls1043aqds_qixis.h"
30
31DECLARE_GLOBAL_DATA_PTR;
32
33enum {
34 MUX_TYPE_GPIO,
35};
36
37/* LS1043AQDS serdes mux */
38#define CFG_SD_MUX1_SLOT2 0x0 /* SLOT2 TX/RX0 */
39#define CFG_SD_MUX1_SLOT1 0x1 /* SLOT1 TX/RX1 */
40#define CFG_SD_MUX2_SLOT3 0x0 /* SLOT3 TX/RX0 */
41#define CFG_SD_MUX2_SLOT1 0x1 /* SLOT1 TX/RX2 */
42#define CFG_SD_MUX3_SLOT4 0x0 /* SLOT4 TX/RX0 */
43#define CFG_SD_MUX3_MUX4 0x1 /* MUX4 */
44#define CFG_SD_MUX4_SLOT3 0x0 /* SLOT3 TX/RX1 */
45#define CFG_SD_MUX4_SLOT1 0x1 /* SLOT1 TX/RX3 */
Shaohui Xie8c35cc32016-01-21 17:14:53 +080046#define CFG_UART_MUX_MASK 0x6
47#define CFG_UART_MUX_SHIFT 1
48#define CFG_LPUART_EN 0x1
Shaohui Xie02b5d2e2015-11-11 17:58:37 +080049
Rajesh Bhagat8aa6b172018-11-05 18:02:48 +000050#ifdef CONFIG_TFABOOT
51struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
52 {
53 "nor0",
54 CONFIG_SYS_NOR0_CSPR,
55 CONFIG_SYS_NOR0_CSPR_EXT,
56 CONFIG_SYS_NOR_AMASK,
57 CONFIG_SYS_NOR_CSOR,
58 {
59 CONFIG_SYS_NOR_FTIM0,
60 CONFIG_SYS_NOR_FTIM1,
61 CONFIG_SYS_NOR_FTIM2,
62 CONFIG_SYS_NOR_FTIM3
63 },
64
65 },
66 {
67 "nor1",
68 CONFIG_SYS_NOR1_CSPR,
69 CONFIG_SYS_NOR1_CSPR_EXT,
70 CONFIG_SYS_NOR_AMASK,
71 CONFIG_SYS_NOR_CSOR,
72 {
73 CONFIG_SYS_NOR_FTIM0,
74 CONFIG_SYS_NOR_FTIM1,
75 CONFIG_SYS_NOR_FTIM2,
76 CONFIG_SYS_NOR_FTIM3
77 },
78 },
79 {
80 "nand",
81 CONFIG_SYS_NAND_CSPR,
82 CONFIG_SYS_NAND_CSPR_EXT,
83 CONFIG_SYS_NAND_AMASK,
84 CONFIG_SYS_NAND_CSOR,
85 {
86 CONFIG_SYS_NAND_FTIM0,
87 CONFIG_SYS_NAND_FTIM1,
88 CONFIG_SYS_NAND_FTIM2,
89 CONFIG_SYS_NAND_FTIM3
90 },
91 },
92 {
93 "fpga",
94 CONFIG_SYS_FPGA_CSPR,
95 CONFIG_SYS_FPGA_CSPR_EXT,
96 CONFIG_SYS_FPGA_AMASK,
97 CONFIG_SYS_FPGA_CSOR,
98 {
99 CONFIG_SYS_FPGA_FTIM0,
100 CONFIG_SYS_FPGA_FTIM1,
101 CONFIG_SYS_FPGA_FTIM2,
102 CONFIG_SYS_FPGA_FTIM3
103 },
104 }
105};
106
107struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
108 {
109 "nand",
110 CONFIG_SYS_NAND_CSPR,
111 CONFIG_SYS_NAND_CSPR_EXT,
112 CONFIG_SYS_NAND_AMASK,
113 CONFIG_SYS_NAND_CSOR,
114 {
115 CONFIG_SYS_NAND_FTIM0,
116 CONFIG_SYS_NAND_FTIM1,
117 CONFIG_SYS_NAND_FTIM2,
118 CONFIG_SYS_NAND_FTIM3
119 },
120 },
121 {
122 "nor0",
123 CONFIG_SYS_NOR0_CSPR,
124 CONFIG_SYS_NOR0_CSPR_EXT,
125 CONFIG_SYS_NOR_AMASK,
126 CONFIG_SYS_NOR_CSOR,
127 {
128 CONFIG_SYS_NOR_FTIM0,
129 CONFIG_SYS_NOR_FTIM1,
130 CONFIG_SYS_NOR_FTIM2,
131 CONFIG_SYS_NOR_FTIM3
132 },
133 },
134 {
135 "nor1",
136 CONFIG_SYS_NOR1_CSPR,
137 CONFIG_SYS_NOR1_CSPR_EXT,
138 CONFIG_SYS_NOR_AMASK,
139 CONFIG_SYS_NOR_CSOR,
140 {
141 CONFIG_SYS_NOR_FTIM0,
142 CONFIG_SYS_NOR_FTIM1,
143 CONFIG_SYS_NOR_FTIM2,
144 CONFIG_SYS_NOR_FTIM3
145 },
146 },
147 {
148 "fpga",
149 CONFIG_SYS_FPGA_CSPR,
150 CONFIG_SYS_FPGA_CSPR_EXT,
151 CONFIG_SYS_FPGA_AMASK,
152 CONFIG_SYS_FPGA_CSOR,
153 {
154 CONFIG_SYS_FPGA_FTIM0,
155 CONFIG_SYS_FPGA_FTIM1,
156 CONFIG_SYS_FPGA_FTIM2,
157 CONFIG_SYS_FPGA_FTIM3
158 },
159 }
160};
161
162void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
163{
164 enum boot_src src = get_boot_src();
165
166 if (src == BOOT_SOURCE_IFC_NAND)
167 regs_info->regs = ifc_cfg_nand_boot;
168 else
169 regs_info->regs = ifc_cfg_nor_boot;
170 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
171}
172#endif
173
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800174int checkboard(void)
175{
Rajesh Bhagat8aa6b172018-11-05 18:02:48 +0000176#ifdef CONFIG_TFABOOT
177 enum boot_src src = get_boot_src();
178#endif
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800179 char buf[64];
Qianyu Gonga2fd2382016-06-13 11:20:30 +0800180#ifndef CONFIG_SD_BOOT
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800181 u8 sw;
182#endif
183
184 puts("Board: LS1043AQDS, boot from ");
185
Rajesh Bhagat8aa6b172018-11-05 18:02:48 +0000186#ifdef CONFIG_TFABOOT
187 if (src == BOOT_SOURCE_SD_MMC)
188 puts("SD\n");
189 else {
190#endif
191
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800192#ifdef CONFIG_SD_BOOT
193 puts("SD\n");
194#else
195 sw = QIXIS_READ(brdcfg[0]);
196 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
197
198 if (sw < 0x8)
199 printf("vBank: %d\n", sw);
200 else if (sw == 0x8)
201 puts("PromJet\n");
202 else if (sw == 0x9)
203 puts("NAND\n");
Qianyu Gonga2fd2382016-06-13 11:20:30 +0800204 else if (sw == 0xF)
205 printf("QSPI\n");
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800206 else
207 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
208#endif
209
Rajesh Bhagat8aa6b172018-11-05 18:02:48 +0000210#ifdef CONFIG_TFABOOT
211 }
212#endif
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800213 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
214 QIXIS_READ(id), QIXIS_READ(arch));
215
216 printf("FPGA: v%d (%s), build %d\n",
217 (int)QIXIS_READ(scver), qixis_read_tag(buf),
218 (int)qixis_read_minor());
219
220 return 0;
221}
222
223bool if_board_diff_clk(void)
224{
225 u8 diff_conf = QIXIS_READ(brdcfg[11]);
226
227 return diff_conf & 0x40;
228}
229
230unsigned long get_board_sys_clk(void)
231{
232 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
233
234 switch (sysclk_conf & 0x0f) {
235 case QIXIS_SYSCLK_64:
236 return 64000000;
237 case QIXIS_SYSCLK_83:
238 return 83333333;
239 case QIXIS_SYSCLK_100:
240 return 100000000;
241 case QIXIS_SYSCLK_125:
242 return 125000000;
243 case QIXIS_SYSCLK_133:
244 return 133333333;
245 case QIXIS_SYSCLK_150:
246 return 150000000;
247 case QIXIS_SYSCLK_160:
248 return 160000000;
249 case QIXIS_SYSCLK_166:
250 return 166666666;
251 }
252
253 return 66666666;
254}
255
256unsigned long get_board_ddr_clk(void)
257{
258 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
259
260 if (if_board_diff_clk())
261 return get_board_sys_clk();
262 switch ((ddrclk_conf & 0x30) >> 4) {
263 case QIXIS_DDRCLK_100:
264 return 100000000;
265 case QIXIS_DDRCLK_125:
266 return 125000000;
267 case QIXIS_DDRCLK_133:
268 return 133333333;
269 }
270
271 return 66666666;
272}
273
274int select_i2c_ch_pca9547(u8 ch)
275{
276 int ret;
277
278 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
279 if (ret) {
280 puts("PCA: failed to select proper channel\n");
281 return ret;
282 }
283
284 return 0;
285}
286
287int dram_init(void)
288{
289 /*
290 * When resuming from deep sleep, the I2C channel may not be
291 * in the default channel. So, switch to the default channel
292 * before accessing DDR SPD.
293 */
294 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
Simon Glass3eace372017-04-06 12:47:04 -0600295 fsl_initdram();
Rajesh Bhagat8aa6b172018-11-05 18:02:48 +0000296#if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
297 defined(CONFIG_SPL_BUILD)
York Sun4961eaf2017-03-06 09:02:34 -0800298 /* This will break-before-make MMU for DDR */
299 update_early_mmu_table();
300#endif
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800301
302 return 0;
303}
304
305int i2c_multiplexer_select_vid_channel(u8 channel)
306{
307 return select_i2c_ch_pca9547(channel);
308}
309
310void board_retimer_init(void)
311{
312 u8 reg;
313
314 /* Retimer is connected to I2C1_CH7_CH5 */
Wenbin Songec442892016-03-09 13:38:24 +0800315 select_i2c_ch_pca9547(I2C_MUX_CH7);
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800316 reg = I2C_MUX_CH5;
317 i2c_write(I2C_MUX_PCA_ADDR_SEC, 0, 1, &reg, 1);
318
319 /* Access to Control/Shared register */
320 reg = 0x0;
321 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
322
323 /* Read device revision and ID */
324 i2c_read(I2C_RETIMER_ADDR, 1, 1, &reg, 1);
325 debug("Retimer version id = 0x%x\n", reg);
326
327 /* Enable Broadcast. All writes target all channel register sets */
328 reg = 0x0c;
329 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
330
331 /* Reset Channel Registers */
332 i2c_read(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
333 reg |= 0x4;
334 i2c_write(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
335
336 /* Enable override divider select and Enable Override Output Mux */
337 i2c_read(I2C_RETIMER_ADDR, 9, 1, &reg, 1);
338 reg |= 0x24;
339 i2c_write(I2C_RETIMER_ADDR, 9, 1, &reg, 1);
340
341 /* Select VCO Divider to full rate (000) */
342 i2c_read(I2C_RETIMER_ADDR, 0x18, 1, &reg, 1);
343 reg &= 0x8f;
344 i2c_write(I2C_RETIMER_ADDR, 0x18, 1, &reg, 1);
345
346 /* Selects active PFD MUX Input as Re-timed Data (001) */
347 i2c_read(I2C_RETIMER_ADDR, 0x1e, 1, &reg, 1);
348 reg &= 0x3f;
349 reg |= 0x20;
350 i2c_write(I2C_RETIMER_ADDR, 0x1e, 1, &reg, 1);
351
352 /* Set data rate as 10.3125 Gbps */
353 reg = 0x0;
354 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, &reg, 1);
355 reg = 0xb2;
356 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, &reg, 1);
357 reg = 0x90;
358 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, &reg, 1);
359 reg = 0xb3;
360 i2c_write(I2C_RETIMER_ADDR, 0x63, 1, &reg, 1);
361 reg = 0xcd;
362 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
Wenbin Songec442892016-03-09 13:38:24 +0800363
364 /* Return the default channel */
365 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800366}
367
368int board_early_init_f(void)
369{
Qianyu Gong5a7c40b2016-02-16 13:12:53 +0800370#ifdef CONFIG_HAS_FSL_XHCI_USB
371 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
372 u32 usb_pwrfault;
373#endif
Shaohui Xie8c35cc32016-01-21 17:14:53 +0800374#ifdef CONFIG_LPUART
375 u8 uart;
376#endif
Qianyu Gong581ff002016-06-13 11:20:31 +0800377
378#ifdef CONFIG_SYS_I2C_EARLY_INIT
379 i2c_early_init_f();
380#endif
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800381 fsl_lsch2_early_init_f();
Qianyu Gong5a7c40b2016-02-16 13:12:53 +0800382
383#ifdef CONFIG_HAS_FSL_XHCI_USB
384 out_be32(&scfg->rcwpmuxcr0, 0x3333);
385 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
386 usb_pwrfault =
Shaohui Xie3e06ba82016-05-30 14:26:55 +0800387 (SCFG_USBPWRFAULT_DEDICATED << SCFG_USBPWRFAULT_USB3_SHIFT) |
388 (SCFG_USBPWRFAULT_DEDICATED << SCFG_USBPWRFAULT_USB2_SHIFT) |
Qianyu Gong5a7c40b2016-02-16 13:12:53 +0800389 (SCFG_USBPWRFAULT_SHARED << SCFG_USBPWRFAULT_USB1_SHIFT);
390 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
391#endif
392
Shaohui Xie8c35cc32016-01-21 17:14:53 +0800393#ifdef CONFIG_LPUART
394 /* We use lpuart0 as system console */
395 uart = QIXIS_READ(brdcfg[14]);
396 uart &= ~CFG_UART_MUX_MASK;
397 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
398 QIXIS_WRITE(brdcfg[14], uart);
399#endif
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800400
401 return 0;
402}
403
404#ifdef CONFIG_FSL_DEEP_SLEEP
405/* determine if it is a warm boot */
406bool is_warm_boot(void)
407{
408#define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
409 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
410
411 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
412 return 1;
413
414 return 0;
415}
416#endif
417
418int config_board_mux(int ctrl_type)
419{
420 u8 reg14;
421
422 reg14 = QIXIS_READ(brdcfg[14]);
423
424 switch (ctrl_type) {
425 case MUX_TYPE_GPIO:
426 reg14 = (reg14 & (~0x30)) | 0x20;
427 break;
428 default:
429 puts("Unsupported mux interface type\n");
430 return -1;
431 }
432
433 QIXIS_WRITE(brdcfg[14], reg14);
434
435 return 0;
436}
437
438int config_serdes_mux(void)
439{
440 return 0;
441}
442
443
444#ifdef CONFIG_MISC_INIT_R
445int misc_init_r(void)
446{
447 if (hwconfig("gpio"))
448 config_board_mux(MUX_TYPE_GPIO);
449
450 return 0;
451}
452#endif
453
454int board_init(void)
455{
Hou Zhiqiangb392a6d2016-08-02 19:03:27 +0800456#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
457 erratum_a010315();
458#endif
459
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800460 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
461 board_retimer_init();
462
463#ifdef CONFIG_SYS_FSL_SERDES
464 config_serdes_mux();
465#endif
466
Hou Zhiqiange1b09292017-04-14 14:48:21 +0800467#ifdef CONFIG_FSL_LS_PPA
468 ppa_init();
469#endif
470
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800471 return 0;
472}
473
474#ifdef CONFIG_OF_BOARD_SETUP
475int ft_board_setup(void *blob, bd_t *bd)
476{
Shaohui Xie58e4ad12016-01-04 11:03:44 +0800477 u64 base[CONFIG_NR_DRAM_BANKS];
478 u64 size[CONFIG_NR_DRAM_BANKS];
Qianyu Gong8401c712016-07-21 12:39:27 +0800479 u8 reg;
Shaohui Xie58e4ad12016-01-04 11:03:44 +0800480
481 /* fixup DT for the two DDR banks */
482 base[0] = gd->bd->bi_dram[0].start;
483 size[0] = gd->bd->bi_dram[0].size;
484 base[1] = gd->bd->bi_dram[1].start;
485 size[1] = gd->bd->bi_dram[1].size;
486
487 fdt_fixup_memory_banks(blob, base, size, 2);
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800488 ft_cpu_setup(blob, bd);
489
490#ifdef CONFIG_SYS_DPAA_FMAN
491 fdt_fixup_fman_ethernet(blob);
492 fdt_fixup_board_enet(blob);
493#endif
Qianyu Gong8401c712016-07-21 12:39:27 +0800494
Laurentiu Tudordc29a4c2018-08-27 17:33:59 +0300495 fdt_fixup_icid(blob);
496
Qianyu Gong8401c712016-07-21 12:39:27 +0800497 reg = QIXIS_READ(brdcfg[0]);
498 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
499
500 /* Disable IFC if QSPI is enabled */
501 if (reg == 0xF)
502 do_fixup_by_compat(blob, "fsl,ifc",
503 "status", "disabled", 8 + 1, 1);
504
Shaohui Xie02b5d2e2015-11-11 17:58:37 +0800505 return 0;
506}
507#endif
508
509u8 flash_read8(void *addr)
510{
511 return __raw_readb(addr + 1);
512}
513
514void flash_write16(u16 val, void *addr)
515{
516 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
517
518 __raw_writew(shftval, addr);
519}
520
521u16 flash_read16(void *addr)
522{
523 u16 val = __raw_readw(addr);
524
525 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
526}
Rajesh Bhagat8aa6b172018-11-05 18:02:48 +0000527
Tom Rinidbcb4da2019-11-18 20:02:08 -0500528#if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
Rajesh Bhagat8aa6b172018-11-05 18:02:48 +0000529void *env_sf_get_env_addr(void)
530{
531 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);
532}
533#endif