blob: 24978314a172120879361fef410886cab70b08ca [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwaha55432502016-06-03 18:41:34 +05302/*
3 * Copyright 2016 Freescale Semiconductor, Inc.
Prabhakar Kushwaha55432502016-06-03 18:41:34 +05304 */
5
6#include <common.h>
7#include <i2c.h>
8#include <fdt_support.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <asm/cache.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053011#include <asm/io.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha74d129b2017-01-30 17:05:35 +053014#ifdef CONFIG_FSL_LS_PPA
15#include <asm/arch/ppa.h>
16#endif
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053017#include <asm/arch/fdt.h>
York Sun729f2d12017-03-06 09:02:34 -080018#include <asm/arch/mmu.h>
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053019#include <asm/arch/soc.h>
20#include <ahci.h>
21#include <hwconfig.h>
22#include <mmc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060023#include <env_internal.h>
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053024#include <scsi.h>
25#include <fm_eth.h>
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053026#include <fsl_esdhc.h>
27#include <fsl_mmdc.h>
28#include <spl.h>
29#include <netdev.h>
Rajesh Bhagatbf39fe62018-11-05 18:02:59 +000030#include <fsl_sec.h>
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053031#include "../common/qixis.h"
32#include "ls1012aqds_qixis.h"
Calvin Johnsonf6615022018-03-08 15:30:28 +053033#include "ls1012aqds_pfe.h"
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053034
35DECLARE_GLOBAL_DATA_PTR;
36
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053037int checkboard(void)
38{
39 char buf[64];
40 u8 sw;
41
42 sw = QIXIS_READ(arch);
43 printf("Board Arch: V%d, ", sw >> 4);
44 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
45
46 sw = QIXIS_READ(brdcfg[QIXIS_LBMAP_BRDCFG_REG]);
47
48 if (sw & QIXIS_LBMAP_ALTBANK)
49 printf("flash: 2\n");
50 else
51 printf("flash: 1\n");
52
53 printf("FPGA: v%d (%s), build %d",
54 (int)QIXIS_READ(scver), qixis_read_tag(buf),
55 (int)qixis_read_minor());
56
57 /* the timestamp string contains "\n" at the end */
58 printf(" on %s", qixis_read_time(buf));
59 return 0;
60}
61
Rajesh Bhagat45d8a542018-11-05 18:03:04 +000062#ifdef CONFIG_TFABOOT
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053063int dram_init(void)
64{
Rajesh Bhagat45d8a542018-11-05 18:03:04 +000065 gd->ram_size = tfa_get_dram_size();
66 if (!gd->ram_size)
67 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
68
69 return 0;
70}
71#else
72int dram_init(void)
73{
York Sunc1e979b2016-09-26 08:09:25 -070074 static const struct fsl_mmdc_info mparam = {
75 0x05180000, /* mdctl */
76 0x00030035, /* mdpdc */
77 0x12554000, /* mdotc */
78 0xbabf7954, /* mdcfg0 */
79 0xdb328f64, /* mdcfg1 */
80 0x01ff00db, /* mdcfg2 */
81 0x00001680, /* mdmisc */
82 0x0f3c8000, /* mdref */
83 0x00002000, /* mdrwd */
84 0x00bf1023, /* mdor */
85 0x0000003f, /* mdasp */
86 0x0000022a, /* mpodtctrl */
87 0xa1390003, /* mpzqhwctrl */
88 };
89
90 mmdc_init(&mparam);
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053091 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
York Sun729f2d12017-03-06 09:02:34 -080092#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
93 /* This will break-before-make MMU for DDR */
94 update_early_mmu_table();
95#endif
Prabhakar Kushwaha55432502016-06-03 18:41:34 +053096
97 return 0;
98}
Rajesh Bhagat45d8a542018-11-05 18:03:04 +000099#endif
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530100
101int board_early_init_f(void)
102{
103 fsl_lsch2_early_init_f();
104
105 return 0;
106}
107
108#ifdef CONFIG_MISC_INIT_R
109int misc_init_r(void)
110{
111 u8 mux_sdhc_cd = 0x80;
Biwen Li0a759bb2019-12-31 15:33:41 +0800112 int bus_num = 0;
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530113
Biwen Li0a759bb2019-12-31 15:33:41 +0800114#ifdef CONFIG_DM_I2C
115 struct udevice *dev;
116 int ret;
117
118 ret = i2c_get_chip_for_busnum(bus_num, CONFIG_SYS_I2C_FPGA_ADDR,
119 1, &dev);
120 if (ret) {
121 printf("%s: Cannot find udev for a bus %d\n", __func__,
122 bus_num);
123 return ret;
124 }
125 dm_i2c_write(dev, 0x5a, &mux_sdhc_cd, 1);
126#else
127 i2c_set_bus_num(bus_num);
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530128
129 i2c_write(CONFIG_SYS_I2C_FPGA_ADDR, 0x5a, 1, &mux_sdhc_cd, 1);
Biwen Li0a759bb2019-12-31 15:33:41 +0800130#endif
131
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530132 return 0;
133}
134#endif
135
136int board_init(void)
137{
Ashish Kumar11234062017-08-11 11:09:14 +0530138 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
139 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530140
141 /* Set CCI-400 control override register to enable barrier
142 * transaction */
Rajesh Bhagat45d8a542018-11-05 18:03:04 +0000143 if (current_el() == 3)
144 out_le32(&cci->ctrl_ord,
145 CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530146
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800147#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
148 erratum_a010315();
149#endif
150
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530151#ifdef CONFIG_ENV_IS_NOWHERE
152 gd->env_addr = (ulong)&default_environment[0];
153#endif
Prabhakar Kushwaha74d129b2017-01-30 17:05:35 +0530154
Rajesh Bhagatbf39fe62018-11-05 18:02:59 +0000155#ifdef CONFIG_FSL_CAAM
156 sec_init();
157#endif
158
Prabhakar Kushwaha74d129b2017-01-30 17:05:35 +0530159#ifdef CONFIG_FSL_LS_PPA
160 ppa_init();
161#endif
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530162 return 0;
163}
164
Yangbo Lu4bb1aee2017-01-17 10:43:55 +0800165int esdhc_status_fixup(void *blob, const char *compat)
166{
167 char esdhc0_path[] = "/soc/esdhc@1560000";
168 char esdhc1_path[] = "/soc/esdhc@1580000";
169 u8 card_id;
170
171 do_fixup_by_path(blob, esdhc0_path, "status", "okay",
172 sizeof("okay"), 1);
173
174 /*
175 * The Presence Detect 2 register detects the installation
176 * of cards in various PCI Express or SGMII slots.
177 *
178 * STAT_PRS2[7:5]: Specifies the type of card installed in the
179 * SDHC2 Adapter slot. 0b111 indicates no adapter is installed.
180 */
181 card_id = (QIXIS_READ(present2) & 0xe0) >> 5;
182
183 /* If no adapter is installed in SDHC2, disable SDHC2 */
184 if (card_id == 0x7)
185 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
186 sizeof("disabled"), 1);
187 else
188 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
189 sizeof("okay"), 1);
190 return 0;
191}
192
Calvin Johnsonf6615022018-03-08 15:30:28 +0530193static int pfe_set_properties(void *set_blob, struct pfe_prop_val prop_val,
194 char *enet_path, char *mdio_path)
195{
196 do_fixup_by_path(set_blob, enet_path, "fsl,gemac-bus-id",
197 &prop_val.busid, PFE_PROP_LEN, 1);
198 do_fixup_by_path(set_blob, enet_path, "fsl,gemac-phy-id",
199 &prop_val.phyid, PFE_PROP_LEN, 1);
200 do_fixup_by_path(set_blob, enet_path, "fsl,mdio-mux-val",
201 &prop_val.mux_val, PFE_PROP_LEN, 1);
202 do_fixup_by_path(set_blob, enet_path, "phy-mode",
203 prop_val.phy_mode, strlen(prop_val.phy_mode) + 1, 1);
204 do_fixup_by_path(set_blob, mdio_path, "fsl,mdio-phy-mask",
205 &prop_val.phy_mask, PFE_PROP_LEN, 1);
206 return 0;
207}
208
209static void fdt_fsl_fixup_of_pfe(void *blob)
210{
211 int i = 0;
212 struct pfe_prop_val prop_val;
213 void *l_blob = blob;
214
215 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
216 unsigned int srds_s1 = in_be32(&gur->rcwsr[4]) &
217 FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK;
218 srds_s1 >>= FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT;
219
220 for (i = 0; i < NUM_ETH_NODE; i++) {
221 switch (srds_s1) {
222 case SERDES_1_G_PROTOCOL:
223 if (i == 0) {
224 prop_val.busid = cpu_to_fdt32(
225 ETH_1_1G_BUS_ID);
226 prop_val.phyid = cpu_to_fdt32(
227 ETH_1_1G_PHY_ID);
228 prop_val.mux_val = cpu_to_fdt32(
229 ETH_1_1G_MDIO_MUX);
230 prop_val.phy_mask = cpu_to_fdt32(
231 ETH_1G_MDIO_PHY_MASK);
232 prop_val.phy_mode = "sgmii";
233 pfe_set_properties(l_blob, prop_val, ETH_1_PATH,
234 ETH_1_MDIO);
235 } else {
236 prop_val.busid = cpu_to_fdt32(
237 ETH_2_1G_BUS_ID);
238 prop_val.phyid = cpu_to_fdt32(
239 ETH_2_1G_PHY_ID);
240 prop_val.mux_val = cpu_to_fdt32(
241 ETH_2_1G_MDIO_MUX);
242 prop_val.phy_mask = cpu_to_fdt32(
243 ETH_1G_MDIO_PHY_MASK);
244 prop_val.phy_mode = "rgmii";
245 pfe_set_properties(l_blob, prop_val, ETH_2_PATH,
246 ETH_2_MDIO);
247 }
248 break;
249 case SERDES_2_5_G_PROTOCOL:
250 if (i == 0) {
251 prop_val.busid = cpu_to_fdt32(
252 ETH_1_2_5G_BUS_ID);
253 prop_val.phyid = cpu_to_fdt32(
254 ETH_1_2_5G_PHY_ID);
255 prop_val.mux_val = cpu_to_fdt32(
256 ETH_1_2_5G_MDIO_MUX);
257 prop_val.phy_mask = cpu_to_fdt32(
258 ETH_2_5G_MDIO_PHY_MASK);
259 prop_val.phy_mode = "sgmii-2500";
260 pfe_set_properties(l_blob, prop_val, ETH_1_PATH,
261 ETH_1_MDIO);
262 } else {
263 prop_val.busid = cpu_to_fdt32(
264 ETH_2_2_5G_BUS_ID);
265 prop_val.phyid = cpu_to_fdt32(
266 ETH_2_2_5G_PHY_ID);
267 prop_val.mux_val = cpu_to_fdt32(
268 ETH_2_2_5G_MDIO_MUX);
269 prop_val.phy_mask = cpu_to_fdt32(
270 ETH_2_5G_MDIO_PHY_MASK);
271 prop_val.phy_mode = "sgmii-2500";
272 pfe_set_properties(l_blob, prop_val, ETH_2_PATH,
273 ETH_2_MDIO);
274 }
275 break;
276 default:
277 printf("serdes:[%d]\n", srds_s1);
278 }
279 }
280}
281
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530282#ifdef CONFIG_OF_BOARD_SETUP
283int ft_board_setup(void *blob, bd_t *bd)
284{
285 arch_fixup_fdt(blob);
286
287 ft_cpu_setup(blob, bd);
Calvin Johnsonf6615022018-03-08 15:30:28 +0530288 fdt_fsl_fixup_of_pfe(blob);
Prabhakar Kushwaha55432502016-06-03 18:41:34 +0530289
290 return 0;
291}
292#endif