blob: db8b3a5b921e04c40a56140d75e62b75eaf74548 [file] [log] [blame]
Vabhav Sharma51641912019-06-06 12:35:28 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 NXP
4 */
5
6#include <common.h>
7#include <i2c.h>
8#include <fdt_support.h>
9#include <asm/io.h>
10#include <asm/arch/clock.h>
11#include <asm/arch/fsl_serdes.h>
12#include <asm/arch/soc.h>
13#include <asm/arch-fsl-layerscape/fsl_icid.h>
14#include <hwconfig.h>
15#include <ahci.h>
16#include <mmc.h>
17#include <scsi.h>
18#include <fm_eth.h>
19#include <fsl_csu.h>
20#include <fsl_esdhc.h>
21#include <fsl_sec.h>
22#include <fsl_dspi.h>
23
24#define LS1046A_PORSR1_REG 0x1EE0000
25#define BOOT_SRC_SD 0x20000000
26#define BOOT_SRC_MASK 0xFF800000
Pramod Kumar43f30ca2019-12-19 10:28:57 +000027#define BOARD_REV_GPIO_SHIFT 17
28#define BOARD_REV_MASK 0x03
Vabhav Sharma51641912019-06-06 12:35:28 +000029#define USB2_SEL_MASK 0x00000100
30
31#define BYTE_SWAP_32(word) ((((word) & 0xff000000) >> 24) | \
32(((word) & 0x00ff0000) >> 8) | \
33(((word) & 0x0000ff00) << 8) | \
34(((word) & 0x000000ff) << 24))
35#define SPI_MCR_REG 0x2100000
36
37DECLARE_GLOBAL_DATA_PTR;
38
39int select_i2c_ch_pca9547(u8 ch)
40{
41 int ret;
42
43 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
44 if (ret) {
45 puts("PCA: failed to select proper channel\n");
46 return ret;
47 }
48
49 return 0;
50}
51
52static inline void demux_select_usb2(void)
53{
54 u32 val;
55 struct ccsr_gpio *pgpio = (void *)(GPIO3_BASE_ADDR);
56
57 val = in_be32(&pgpio->gpdir);
58 val |= USB2_SEL_MASK;
59 out_be32(&pgpio->gpdir, val);
60
61 val = in_be32(&pgpio->gpdat);
62 val |= USB2_SEL_MASK;
63 out_be32(&pgpio->gpdat, val);
64}
65
66static inline void set_spi_cs_signal_inactive(void)
67{
68 /* default: all CS signals inactive state is high */
69 uint mcr_val;
70 uint mcr_cfg_val = DSPI_MCR_MSTR | DSPI_MCR_PCSIS_MASK |
71 DSPI_MCR_CRXF | DSPI_MCR_CTXF;
72
73 mcr_val = in_be32(SPI_MCR_REG);
74 mcr_val |= DSPI_MCR_HALT;
75 out_be32(SPI_MCR_REG, mcr_val);
76 out_be32(SPI_MCR_REG, mcr_cfg_val);
77 mcr_val = in_be32(SPI_MCR_REG);
78 mcr_val &= ~DSPI_MCR_HALT;
79 out_be32(SPI_MCR_REG, mcr_val);
80}
81
82int board_early_init_f(void)
83{
84 fsl_lsch2_early_init_f();
85
86 return 0;
87}
88
89static inline uint8_t get_board_version(void)
90{
Vabhav Sharma51641912019-06-06 12:35:28 +000091 struct ccsr_gpio *pgpio = (void *)(GPIO2_BASE_ADDR);
92
Pramod Kumar43f30ca2019-12-19 10:28:57 +000093 /* GPIO 13 and GPIO 14 are used for Board Rev */
94 u32 gpio_val = ((in_be32(&pgpio->gpdat) >> BOARD_REV_GPIO_SHIFT))
95 & BOARD_REV_MASK;
96
97 /* GPIOs' are 0..31 in Big Endiness, swap GPIO 13 and GPIO 14 */
98 u8 val = ((gpio_val >> 1) | (gpio_val << 1)) & BOARD_REV_MASK;
Vabhav Sharma51641912019-06-06 12:35:28 +000099
100 return val;
101}
102
103int checkboard(void)
104{
105 static const char *freq[2] = {"100.00MHZ", "100.00MHZ"};
106 u32 boot_src;
107 u8 rev;
108
109 rev = get_board_version();
110 switch (rev) {
111 case 0x00:
112 puts("Board: LS1046AFRWY, Rev: A, boot from ");
113 break;
114 case 0x01:
115 puts("Board: LS1046AFRWY, Rev: B, boot from ");
116 break;
117 default:
118 puts("Board: LS1046AFRWY, Rev: Unknown, boot from ");
119 break;
120 }
121 boot_src = BYTE_SWAP_32(readl(LS1046A_PORSR1_REG));
122
123 if ((boot_src & BOOT_SRC_MASK) == BOOT_SRC_SD)
124 puts("SD\n");
125 else
126 puts("QSPI\n");
127 printf("SD1_CLK1 = %s, SD1_CLK2 = %s\n", freq[0], freq[1]);
128
129 return 0;
130}
131
132int board_init(void)
133{
Udit Agarwal22ec2382019-11-07 16:11:32 +0000134#ifdef CONFIG_NXP_ESBC
Vabhav Sharma51641912019-06-06 12:35:28 +0000135 /*
136 * In case of Secure Boot, the IBR configures the SMMU
137 * to allow only Secure transactions.
138 * SMMU must be reset in bypass mode.
139 * Set the ClientPD bit and Clear the USFCFG Bit
140 */
141 u32 val;
142val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
143 out_le32(SMMU_SCR0, val);
144 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
145 out_le32(SMMU_NSCR0, val);
146#endif
147
148#ifdef CONFIG_FSL_CAAM
149 sec_init();
150#endif
151
152 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
153 return 0;
154}
155
156int board_setup_core_volt(u32 vdd)
157{
158 return 0;
159}
160
161void config_board_mux(void)
162{
163#ifdef CONFIG_HAS_FSL_XHCI_USB
164 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
165 u32 usb_pwrfault;
166 /*
167 * USB2 is used, configure mux to USB2_DRVVBUS/USB2_PWRFAULT
168 * USB3 is not used, configure mux to IIC4_SCL/IIC4_SDA
169 */
170 out_be32(&scfg->rcwpmuxcr0, 0x3300);
171#ifdef CONFIG_HAS_FSL_IIC3
172 /* IIC3 is used, configure mux to use IIC3_SCL/IIC3/SDA */
173 out_be32(&scfg->rcwpmuxcr0, 0x0000);
174#endif
175 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
176 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
177 SCFG_USBPWRFAULT_USB3_SHIFT) |
178 (SCFG_USBPWRFAULT_DEDICATED <<
179 SCFG_USBPWRFAULT_USB2_SHIFT) |
180 (SCFG_USBPWRFAULT_SHARED <<
181 SCFG_USBPWRFAULT_USB1_SHIFT);
182 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
183#ifndef CONFIG_HAS_FSL_IIC3
184 /*
185 * LS1046A FRWY board has demultiplexer NX3DV42GU with GPIO3_23 as input
186 * to select I2C3_USB2_SEL_IO
187 * I2C3_USB2_SEL = 0: I2C3_SCL/SDA signals are routed to
188 * I2C3 header (default)
189 * I2C3_USB2_SEL = 1: USB2_DRVVBUS/PWRFAULT signals are routed to
190 * USB2 port
191 * programmed to select USB2 by setting GPIO3_23 output to one
192 */
193 demux_select_usb2();
194#endif
195#endif
196 set_spi_cs_signal_inactive();
197}
198
199#ifdef CONFIG_MISC_INIT_R
200int misc_init_r(void)
201{
202 config_board_mux();
203 return 0;
204}
205#endif
206
207int ft_board_setup(void *blob, bd_t *bd)
208{
209 u64 base[CONFIG_NR_DRAM_BANKS];
210 u64 size[CONFIG_NR_DRAM_BANKS];
211
212 /* fixup DT for the two DDR banks */
213 base[0] = gd->bd->bi_dram[0].start;
214 size[0] = gd->bd->bi_dram[0].size;
215 base[1] = gd->bd->bi_dram[1].start;
216 size[1] = gd->bd->bi_dram[1].size;
217
218 fdt_fixup_memory_banks(blob, base, size, 2);
219 ft_cpu_setup(blob, bd);
220
221#ifdef CONFIG_SYS_DPAA_FMAN
222 fdt_fixup_fman_ethernet(blob);
223#endif
224
225 fdt_fixup_icid(blob);
226
227 return 0;
228}