blob: 90c1824e467e98f4b10e8c5bce7576fb4b7dc295 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +05302/*
3 * Copyright 2016 Freescale Semiconductor, Inc.
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +05304 */
5
6#include <common.h>
Simon Glass807765b2019-12-28 10:44:54 -07007#include <fdt_support.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +05308#include <i2c.h>
9#include <asm/io.h>
10#include <asm/arch/clock.h>
11#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +053012#ifdef CONFIG_FSL_LS_PPA
13#include <asm/arch/ppa.h>
14#endif
York Sun4961eaf2017-03-06 09:02:34 -080015#include <asm/arch/mmu.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053016#include <asm/arch/soc.h>
17#include <hwconfig.h>
18#include <ahci.h>
19#include <mmc.h>
20#include <scsi.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053021#include <fsl_esdhc.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060022#include <env_internal.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053023#include <fsl_mmdc.h>
24#include <netdev.h>
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +053025#include <fsl_sec.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053026
27DECLARE_GLOBAL_DATA_PTR;
28
Jagdish Gediya3fa48f02018-04-13 00:18:22 +053029#define BOOT_FROM_UPPER_BANK 0x2
30#define BOOT_FROM_LOWER_BANK 0x1
31
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053032int checkboard(void)
33{
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053034#ifdef CONFIG_TARGET_LS1012ARDB
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053035 u8 in1;
36
37 puts("Board: LS1012ARDB ");
38
39 /* Initialize i2c early for Serial flash bank information */
40 i2c_set_bus_num(0);
41
Yangbo Lu481fb012017-12-08 15:35:35 +080042 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1) < 0) {
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053043 printf("Error reading i2c boot information!\n");
44 return 0; /* Don't want to hang() on this error */
45 }
46
47 puts("Version");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080048 switch (in1 & SW_REV_MASK) {
49 case SW_REV_A:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053050 puts(": RevA");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080051 break;
52 case SW_REV_B:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053053 puts(": RevB");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080054 break;
55 case SW_REV_C:
56 puts(": RevC");
57 break;
58 case SW_REV_C1:
59 puts(": RevC1");
60 break;
61 case SW_REV_C2:
62 puts(": RevC2");
63 break;
64 case SW_REV_D:
65 puts(": RevD");
66 break;
67 case SW_REV_E:
68 puts(": RevE");
69 break;
70 default:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053071 puts(": unknown");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080072 break;
73 }
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053074
75 printf(", boot from QSPI");
Yangbo Lu481fb012017-12-08 15:35:35 +080076 if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053077 puts(": emu\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080078 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053079 puts(": bank1\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080080 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053081 puts(": bank2\n");
82 else
83 puts("unknown\n");
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053084#else
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053085
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053086 puts("Board: LS1012A2G5RDB ");
87#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053088 return 0;
89}
90
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +000091#ifdef CONFIG_TFABOOT
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053092int dram_init(void)
93{
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +000094 gd->ram_size = tfa_get_dram_size();
95 if (!gd->ram_size)
96 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
97
98 return 0;
99}
100#else
101int dram_init(void)
102{
103#ifndef CONFIG_TFABOOT
York Sun1fdcc8d2016-09-26 08:09:25 -0700104 static const struct fsl_mmdc_info mparam = {
105 0x05180000, /* mdctl */
106 0x00030035, /* mdpdc */
107 0x12554000, /* mdotc */
108 0xbabf7954, /* mdcfg0 */
109 0xdb328f64, /* mdcfg1 */
110 0x01ff00db, /* mdcfg2 */
111 0x00001680, /* mdmisc */
112 0x0f3c8000, /* mdref */
113 0x00002000, /* mdrwd */
114 0x00bf1023, /* mdor */
115 0x0000003f, /* mdasp */
116 0x0000022a, /* mpodtctrl */
117 0xa1390003, /* mpzqhwctrl */
118 };
119
120 mmdc_init(&mparam);
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000121#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530122
123 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
York Sun4961eaf2017-03-06 09:02:34 -0800124#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
125 /* This will break-before-make MMU for DDR */
126 update_early_mmu_table();
127#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530128
129 return 0;
130}
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000131#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530132
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530133
134int board_early_init_f(void)
135{
136 fsl_lsch2_early_init_f();
137
138 return 0;
139}
140
141int board_init(void)
142{
Ashish Kumar63b23162017-08-11 11:09:14 +0530143 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
144 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530145 /*
146 * Set CCI-400 control override register to enable barrier
147 * transaction
148 */
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000149 if (current_el() == 3)
150 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530151
Hou Zhiqiangb392a6d2016-08-02 19:03:27 +0800152#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
153 erratum_a010315();
154#endif
155
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530156#ifdef CONFIG_ENV_IS_NOWHERE
157 gd->env_addr = (ulong)&default_environment[0];
158#endif
159
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +0530160#ifdef CONFIG_FSL_CAAM
161 sec_init();
162#endif
163
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +0530164#ifdef CONFIG_FSL_LS_PPA
165 ppa_init();
166#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530167 return 0;
168}
169
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530170#ifdef CONFIG_TARGET_LS1012ARDB
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800171int esdhc_status_fixup(void *blob, const char *compat)
172{
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800173 char esdhc1_path[] = "/soc/esdhc@1580000";
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800174 bool sdhc2_en = false;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800175 u8 mux_sdhc2;
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800176 u8 io = 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800177
178 i2c_set_bus_num(0);
179
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800180 /* IO1[7:3] is the field of board revision info. */
181 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1) < 0) {
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800182 printf("Error reading i2c boot information!\n");
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800183 return 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800184 }
185
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800186 /* hwconfig method is used for RevD and later versions. */
187 if ((io & SW_REV_MASK) <= SW_REV_D) {
188#ifdef CONFIG_HWCONFIG
189 if (hwconfig("esdhc1"))
190 sdhc2_en = true;
191#endif
192 } else {
193 /*
194 * The I2C IO-expander for mux select is used to control
195 * the muxing of various onboard interfaces.
196 *
197 * IO0[3:2] indicates SDHC2 interface demultiplexer
198 * select lines.
199 * 00 - SDIO wifi
200 * 01 - GPIO (to Arduino)
201 * 10 - eMMC Memory
202 * 11 - SPI
203 */
204 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1) < 0) {
205 printf("Error reading i2c boot information!\n");
206 return 0;
207 }
208
209 mux_sdhc2 = (io & 0x0c) >> 2;
210 /* Enable SDHC2 only when use SDIO wifi and eMMC */
211 if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
212 sdhc2_en = true;
213 }
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800214 if (sdhc2_en)
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800215 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
216 sizeof("okay"), 1);
217 else
218 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
219 sizeof("disabled"), 1);
220 return 0;
221}
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530222#endif
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800223
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530224int ft_board_setup(void *blob, bd_t *bd)
225{
226 arch_fixup_fdt(blob);
227
228 ft_cpu_setup(blob, bd);
229
230 return 0;
231}
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530232
233static int switch_to_bank1(void)
234{
235 u8 data;
236 int ret;
237
238 i2c_set_bus_num(0);
239
240 data = 0xf4;
241 ret = i2c_write(0x24, 0x3, 1, &data, 1);
242 if (ret) {
243 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
244 0x24, 0x3, data);
245 }
246
247 return ret;
248}
249
250static int switch_to_bank2(void)
251{
252 u8 data;
253 int ret;
254
255 i2c_set_bus_num(0);
256
257 data = 0xfc;
258 ret = i2c_write(0x24, 0x7, 1, &data, 1);
259 if (ret) {
260 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
261 0x24, 0x7, data);
262 goto err;
263 }
264
265 data = 0xf5;
266 ret = i2c_write(0x24, 0x3, 1, &data, 1);
267 if (ret) {
268 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
269 0x24, 0x3, data);
270 }
271err:
272 return ret;
273}
274
275static int convert_flash_bank(int bank)
276{
277 int ret = 0;
278
279 switch (bank) {
280 case BOOT_FROM_UPPER_BANK:
281 ret = switch_to_bank2();
282 break;
283 case BOOT_FROM_LOWER_BANK:
284 ret = switch_to_bank1();
285 break;
286 default:
287 ret = CMD_RET_USAGE;
288 break;
289 };
290
291 return ret;
292}
293
294static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
295 char * const argv[])
296{
297 if (argc != 2)
298 return CMD_RET_USAGE;
299 if (strcmp(argv[1], "1") == 0)
300 convert_flash_bank(BOOT_FROM_LOWER_BANK);
301 else if (strcmp(argv[1], "2") == 0)
302 convert_flash_bank(BOOT_FROM_UPPER_BANK);
303 else
304 return CMD_RET_USAGE;
305
306 return 0;
307}
308
309U_BOOT_CMD(
310 boot_bank, 2, 0, flash_bank_cmd,
311 "Flash bank Selection Control",
312 "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
313);