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