blob: f648a9040b6d5e8d43725eb74d30e7e353a6ec32 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +05302/*
3 * Copyright 2016 Freescale Semiconductor, Inc.
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +05304 */
5
6#include <common.h>
7#include <i2c.h>
8#include <asm/io.h>
9#include <asm/arch/clock.h>
10#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha74d129b2017-01-30 17:05:35 +053011#ifdef CONFIG_FSL_LS_PPA
12#include <asm/arch/ppa.h>
13#endif
York Sun729f2d12017-03-06 09:02:34 -080014#include <asm/arch/mmu.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053015#include <asm/arch/soc.h>
16#include <hwconfig.h>
17#include <ahci.h>
18#include <mmc.h>
19#include <scsi.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053020#include <fsl_esdhc.h>
21#include <environment.h>
22#include <fsl_mmdc.h>
23#include <netdev.h>
Vinitha Pillai-B57223eea4a322017-03-23 13:48:20 +053024#include <fsl_sec.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053025
26DECLARE_GLOBAL_DATA_PTR;
27
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +053028#define BOOT_FROM_UPPER_BANK 0x2
29#define BOOT_FROM_LOWER_BANK 0x1
30
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053031int checkboard(void)
32{
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +053033#ifdef CONFIG_TARGET_LS1012ARDB
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053034 u8 in1;
35
36 puts("Board: LS1012ARDB ");
37
38 /* Initialize i2c early for Serial flash bank information */
39 i2c_set_bus_num(0);
40
Yangbo Lu2786f902017-12-08 15:35:35 +080041 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1) < 0) {
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053042 printf("Error reading i2c boot information!\n");
43 return 0; /* Don't want to hang() on this error */
44 }
45
46 puts("Version");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080047 switch (in1 & SW_REV_MASK) {
48 case SW_REV_A:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053049 puts(": RevA");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080050 break;
51 case SW_REV_B:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053052 puts(": RevB");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080053 break;
54 case SW_REV_C:
55 puts(": RevC");
56 break;
57 case SW_REV_C1:
58 puts(": RevC1");
59 break;
60 case SW_REV_C2:
61 puts(": RevC2");
62 break;
63 case SW_REV_D:
64 puts(": RevD");
65 break;
66 case SW_REV_E:
67 puts(": RevE");
68 break;
69 default:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053070 puts(": unknown");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080071 break;
72 }
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053073
74 printf(", boot from QSPI");
Yangbo Lu2786f902017-12-08 15:35:35 +080075 if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053076 puts(": emu\n");
Yangbo Lu2786f902017-12-08 15:35:35 +080077 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053078 puts(": bank1\n");
Yangbo Lu2786f902017-12-08 15:35:35 +080079 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053080 puts(": bank2\n");
81 else
82 puts("unknown\n");
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +053083#else
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053084
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +053085 puts("Board: LS1012A2G5RDB ");
86#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053087 return 0;
88}
89
Rajesh Bhagatfcafef62018-11-05 18:02:53 +000090#ifdef CONFIG_TFABOOT
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053091int dram_init(void)
92{
Rajesh Bhagatfcafef62018-11-05 18:02:53 +000093 gd->ram_size = tfa_get_dram_size();
94 if (!gd->ram_size)
95 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
96
97 return 0;
98}
99#else
100int dram_init(void)
101{
102#ifndef CONFIG_TFABOOT
York Sunc1e979b2016-09-26 08:09:25 -0700103 static const struct fsl_mmdc_info mparam = {
104 0x05180000, /* mdctl */
105 0x00030035, /* mdpdc */
106 0x12554000, /* mdotc */
107 0xbabf7954, /* mdcfg0 */
108 0xdb328f64, /* mdcfg1 */
109 0x01ff00db, /* mdcfg2 */
110 0x00001680, /* mdmisc */
111 0x0f3c8000, /* mdref */
112 0x00002000, /* mdrwd */
113 0x00bf1023, /* mdor */
114 0x0000003f, /* mdasp */
115 0x0000022a, /* mpodtctrl */
116 0xa1390003, /* mpzqhwctrl */
117 };
118
119 mmdc_init(&mparam);
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000120#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530121
122 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
York Sun729f2d12017-03-06 09:02:34 -0800123#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
124 /* This will break-before-make MMU for DDR */
125 update_early_mmu_table();
126#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530127
128 return 0;
129}
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000130#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530131
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530132
133int board_early_init_f(void)
134{
135 fsl_lsch2_early_init_f();
136
137 return 0;
138}
139
140int board_init(void)
141{
Ashish Kumar11234062017-08-11 11:09:14 +0530142 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
143 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530144 /*
145 * Set CCI-400 control override register to enable barrier
146 * transaction
147 */
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000148 if (current_el() == 3)
149 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530150
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800151#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
152 erratum_a010315();
153#endif
154
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530155#ifdef CONFIG_ENV_IS_NOWHERE
156 gd->env_addr = (ulong)&default_environment[0];
157#endif
158
Vinitha Pillai-B57223eea4a322017-03-23 13:48:20 +0530159#ifdef CONFIG_FSL_CAAM
160 sec_init();
161#endif
162
Prabhakar Kushwaha74d129b2017-01-30 17:05:35 +0530163#ifdef CONFIG_FSL_LS_PPA
164 ppa_init();
165#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530166 return 0;
167}
168
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530169#ifdef CONFIG_TARGET_LS1012ARDB
Yangbo Lub2495c02017-01-17 10:43:56 +0800170int esdhc_status_fixup(void *blob, const char *compat)
171{
Yangbo Lub2495c02017-01-17 10:43:56 +0800172 char esdhc1_path[] = "/soc/esdhc@1580000";
Yangbo Lu878c9782017-12-08 15:35:37 +0800173 bool sdhc2_en = false;
Yangbo Lub2495c02017-01-17 10:43:56 +0800174 u8 mux_sdhc2;
Yangbo Lu878c9782017-12-08 15:35:37 +0800175 u8 io = 0;
Yangbo Lub2495c02017-01-17 10:43:56 +0800176
177 i2c_set_bus_num(0);
178
Yangbo Lu878c9782017-12-08 15:35:37 +0800179 /* IO1[7:3] is the field of board revision info. */
180 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1) < 0) {
Yangbo Lub2495c02017-01-17 10:43:56 +0800181 printf("Error reading i2c boot information!\n");
Yangbo Lu878c9782017-12-08 15:35:37 +0800182 return 0;
Yangbo Lub2495c02017-01-17 10:43:56 +0800183 }
184
Yangbo Lu878c9782017-12-08 15:35:37 +0800185 /* hwconfig method is used for RevD and later versions. */
186 if ((io & SW_REV_MASK) <= SW_REV_D) {
187#ifdef CONFIG_HWCONFIG
188 if (hwconfig("esdhc1"))
189 sdhc2_en = true;
190#endif
191 } else {
192 /*
193 * The I2C IO-expander for mux select is used to control
194 * the muxing of various onboard interfaces.
195 *
196 * IO0[3:2] indicates SDHC2 interface demultiplexer
197 * select lines.
198 * 00 - SDIO wifi
199 * 01 - GPIO (to Arduino)
200 * 10 - eMMC Memory
201 * 11 - SPI
202 */
203 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1) < 0) {
204 printf("Error reading i2c boot information!\n");
205 return 0;
206 }
207
208 mux_sdhc2 = (io & 0x0c) >> 2;
209 /* Enable SDHC2 only when use SDIO wifi and eMMC */
210 if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
211 sdhc2_en = true;
212 }
Yangbo Lu878c9782017-12-08 15:35:37 +0800213 if (sdhc2_en)
Yangbo Lub2495c02017-01-17 10:43:56 +0800214 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
215 sizeof("okay"), 1);
216 else
217 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
218 sizeof("disabled"), 1);
219 return 0;
220}
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530221#endif
Yangbo Lub2495c02017-01-17 10:43:56 +0800222
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530223int ft_board_setup(void *blob, bd_t *bd)
224{
225 arch_fixup_fdt(blob);
226
227 ft_cpu_setup(blob, bd);
228
229 return 0;
230}
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530231
232static int switch_to_bank1(void)
233{
234 u8 data;
235 int ret;
236
237 i2c_set_bus_num(0);
238
239 data = 0xf4;
240 ret = i2c_write(0x24, 0x3, 1, &data, 1);
241 if (ret) {
242 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
243 0x24, 0x3, data);
244 }
245
246 return ret;
247}
248
249static int switch_to_bank2(void)
250{
251 u8 data;
252 int ret;
253
254 i2c_set_bus_num(0);
255
256 data = 0xfc;
257 ret = i2c_write(0x24, 0x7, 1, &data, 1);
258 if (ret) {
259 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
260 0x24, 0x7, data);
261 goto err;
262 }
263
264 data = 0xf5;
265 ret = i2c_write(0x24, 0x3, 1, &data, 1);
266 if (ret) {
267 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
268 0x24, 0x3, data);
269 }
270err:
271 return ret;
272}
273
274static int convert_flash_bank(int bank)
275{
276 int ret = 0;
277
278 switch (bank) {
279 case BOOT_FROM_UPPER_BANK:
280 ret = switch_to_bank2();
281 break;
282 case BOOT_FROM_LOWER_BANK:
283 ret = switch_to_bank1();
284 break;
285 default:
286 ret = CMD_RET_USAGE;
287 break;
288 };
289
290 return ret;
291}
292
293static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
294 char * const argv[])
295{
296 if (argc != 2)
297 return CMD_RET_USAGE;
298 if (strcmp(argv[1], "1") == 0)
299 convert_flash_bank(BOOT_FROM_LOWER_BANK);
300 else if (strcmp(argv[1], "2") == 0)
301 convert_flash_bank(BOOT_FROM_UPPER_BANK);
302 else
303 return CMD_RET_USAGE;
304
305 return 0;
306}
307
308U_BOOT_CMD(
309 boot_bank, 2, 0, flash_bank_cmd,
310 "Flash bank Selection Control",
311 "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
312);