blob: f2949cf8b6959498b8d4947094826a32a653d8f2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mingkai Hud2396512016-09-07 18:47:28 +08002/*
3 * Copyright 2016 Freescale Semiconductor, Inc.
Mingkai Hud2396512016-09-07 18:47:28 +08004 */
5
6#include <common.h>
7#include <i2c.h>
8#include <fdt_support.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Sean Anderson99e12862022-03-22 17:16:05 -040010#include <semihosting.h>
11#include <serial.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Mingkai Hud2396512016-09-07 18:47:28 +080013#include <asm/io.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/fsl_serdes.h>
16#include <asm/arch/ppa.h>
17#include <asm/arch/soc.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030018#include <asm/arch-fsl-layerscape/fsl_icid.h>
Mingkai Hud2396512016-09-07 18:47:28 +080019#include <hwconfig.h>
20#include <ahci.h>
21#include <mmc.h>
22#include <scsi.h>
23#include <fm_eth.h>
24#include <fsl_csu.h>
25#include <fsl_esdhc.h>
Hou Zhiqiang67b6d0a2016-12-09 16:09:01 +080026#include <power/mc34vr500_pmic.h>
Mingkai Hud2396512016-09-07 18:47:28 +080027#include "cpld.h"
Vinitha Pillai-B57223a47072e2017-03-23 13:48:18 +053028#include <fsl_sec.h>
Mingkai Hud2396512016-09-07 18:47:28 +080029
30DECLARE_GLOBAL_DATA_PTR;
31
Sean Anderson99e12862022-03-22 17:16:05 -040032struct serial_device *default_serial_console(void)
33{
34#if IS_ENABLED(CONFIG_SEMIHOSTING_SERIAL)
Sean Anderson409024e2022-03-22 16:59:33 -040035 if (semihosting_enabled())
36 return &serial_smh_device;
Sean Anderson99e12862022-03-22 17:16:05 -040037#endif
38 return &eserial1_device;
39}
40
Sumit Gargc064fc72017-03-30 09:53:13 +053041int board_early_init_f(void)
42{
43 fsl_lsch2_early_init_f();
44
45 return 0;
46}
47
48#ifndef CONFIG_SPL_BUILD
Mingkai Hud2396512016-09-07 18:47:28 +080049int checkboard(void)
50{
51 static const char *freq[2] = {"100.00MHZ", "156.25MHZ"};
52 u8 cfg_rcw_src1, cfg_rcw_src2;
53 u16 cfg_rcw_src;
54 u8 sd1refclk_sel;
55
56 puts("Board: LS1046ARDB, boot from ");
57
58 cfg_rcw_src1 = CPLD_READ(cfg_rcw_src1);
59 cfg_rcw_src2 = CPLD_READ(cfg_rcw_src2);
60 cpld_rev_bit(&cfg_rcw_src1);
61 cfg_rcw_src = cfg_rcw_src1;
62 cfg_rcw_src = (cfg_rcw_src << 1) | cfg_rcw_src2;
63
64 if (cfg_rcw_src == 0x44)
65 printf("QSPI vBank %d\n", CPLD_READ(vbank));
66 else if (cfg_rcw_src == 0x40)
67 puts("SD\n");
68 else
69 puts("Invalid setting of SW5\n");
70
71 printf("CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(cpld_ver),
72 CPLD_READ(cpld_ver_sub), CPLD_READ(pcba_ver));
73
74 puts("SERDES Reference Clocks:\n");
75 sd1refclk_sel = CPLD_READ(sd1refclk_sel);
76 printf("SD1_CLK1 = %s, SD1_CLK2 = %s\n", freq[sd1refclk_sel], freq[0]);
77
78 return 0;
79}
80
Mingkai Hud2396512016-09-07 18:47:28 +080081int board_init(void)
82{
83 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
84
Udit Agarwal22ec2382019-11-07 16:11:32 +000085#ifdef CONFIG_NXP_ESBC
Vinitha Pillai-B57223a47072e2017-03-23 13:48:18 +053086 /*
87 * In case of Secure Boot, the IBR configures the SMMU
88 * to allow only Secure transactions.
89 * SMMU must be reset in bypass mode.
90 * Set the ClientPD bit and Clear the USFCFG Bit
91 */
92 u32 val;
93 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
94 out_le32(SMMU_SCR0, val);
95 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
96 out_le32(SMMU_NSCR0, val);
97#endif
98
99#ifdef CONFIG_FSL_CAAM
100 sec_init();
101#endif
102
Mingkai Hud2396512016-09-07 18:47:28 +0800103#ifdef CONFIG_FSL_LS_PPA
104 ppa_init();
105#endif
106
Martin Schillerfb425ee2021-11-17 12:59:20 +0100107#if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
108 pci_init();
109#endif
110
Mingkai Hud2396512016-09-07 18:47:28 +0800111 /* invert AQR105 IRQ pins polarity */
112 out_be32(&scfg->intpcr, AQR105_IRQ_MASK);
113
114 return 0;
115}
116
Hou Zhiqiang67b6d0a2016-12-09 16:09:01 +0800117int board_setup_core_volt(u32 vdd)
118{
119 bool en_0v9;
120
121 en_0v9 = (vdd == 900) ? true : false;
122 cpld_select_core_volt(en_0v9);
123
124 return 0;
125}
126
127int get_serdes_volt(void)
128{
129 return mc34vr500_get_sw_volt(SW4);
130}
131
132int set_serdes_volt(int svdd)
133{
134 return mc34vr500_set_sw_volt(SW4, svdd);
135}
136
137int power_init_board(void)
138{
139 int ret;
140
141 ret = power_mc34vr500_init(0);
142 if (ret)
143 return ret;
144
145 setup_chip_volt();
146
147 return 0;
148}
149
Mingkai Hud2396512016-09-07 18:47:28 +0800150void config_board_mux(void)
151{
152#ifdef CONFIG_HAS_FSL_XHCI_USB
153 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
154 u32 usb_pwrfault;
155
156 /* USB3 is not used, configure mux to IIC4_SCL/IIC4_SDA */
157 out_be32(&scfg->rcwpmuxcr0, 0x3300);
158 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
159 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
160 SCFG_USBPWRFAULT_USB3_SHIFT) |
161 (SCFG_USBPWRFAULT_DEDICATED <<
162 SCFG_USBPWRFAULT_USB2_SHIFT) |
163 (SCFG_USBPWRFAULT_SHARED <<
164 SCFG_USBPWRFAULT_USB1_SHIFT);
165 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
166#endif
167}
168
169#ifdef CONFIG_MISC_INIT_R
170int misc_init_r(void)
171{
172 config_board_mux();
173 return 0;
174}
175#endif
176
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900177int ft_board_setup(void *blob, struct bd_info *bd)
Mingkai Hud2396512016-09-07 18:47:28 +0800178{
179 u64 base[CONFIG_NR_DRAM_BANKS];
180 u64 size[CONFIG_NR_DRAM_BANKS];
181
182 /* fixup DT for the two DDR banks */
183 base[0] = gd->bd->bi_dram[0].start;
184 size[0] = gd->bd->bi_dram[0].size;
185 base[1] = gd->bd->bi_dram[1].start;
186 size[1] = gd->bd->bi_dram[1].size;
187
188 fdt_fixup_memory_banks(blob, base, size, 2);
189 ft_cpu_setup(blob, bd);
190
191#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300192#ifndef CONFIG_DM_ETH
Mingkai Hud2396512016-09-07 18:47:28 +0800193 fdt_fixup_fman_ethernet(blob);
194#endif
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300195#endif
Mingkai Hud2396512016-09-07 18:47:28 +0800196
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300197 fdt_fixup_icid(blob);
198
Mingkai Hud2396512016-09-07 18:47:28 +0800199 return 0;
200}
Sumit Gargc064fc72017-03-30 09:53:13 +0530201#endif