blob: 0f665c7bc68fa94445c14d7c05ab1532ddb5a22b [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>
Simon Glassdb41d652019-12-28 10:45:07 -07008#include <hang.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +05309#include <i2c.h>
10#include <asm/io.h>
11#include <asm/arch/clock.h>
12#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +053013#ifdef CONFIG_FSL_LS_PPA
14#include <asm/arch/ppa.h>
15#endif
York Sun4961eaf2017-03-06 09:02:34 -080016#include <asm/arch/mmu.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053017#include <asm/arch/soc.h>
18#include <hwconfig.h>
19#include <ahci.h>
20#include <mmc.h>
21#include <scsi.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053022#include <fsl_esdhc.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060023#include <env_internal.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053024#include <fsl_mmdc.h>
25#include <netdev.h>
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +053026#include <fsl_sec.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053027
28DECLARE_GLOBAL_DATA_PTR;
29
Jagdish Gediya3fa48f02018-04-13 00:18:22 +053030#define BOOT_FROM_UPPER_BANK 0x2
31#define BOOT_FROM_LOWER_BANK 0x1
32
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053033int checkboard(void)
34{
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053035#ifdef CONFIG_TARGET_LS1012ARDB
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053036 u8 in1;
37
38 puts("Board: LS1012ARDB ");
39
40 /* Initialize i2c early for Serial flash bank information */
41 i2c_set_bus_num(0);
42
Yangbo Lu481fb012017-12-08 15:35:35 +080043 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1) < 0) {
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053044 printf("Error reading i2c boot information!\n");
45 return 0; /* Don't want to hang() on this error */
46 }
47
48 puts("Version");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080049 switch (in1 & SW_REV_MASK) {
50 case SW_REV_A:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053051 puts(": RevA");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080052 break;
53 case SW_REV_B:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053054 puts(": RevB");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080055 break;
56 case SW_REV_C:
57 puts(": RevC");
58 break;
59 case SW_REV_C1:
60 puts(": RevC1");
61 break;
62 case SW_REV_C2:
63 puts(": RevC2");
64 break;
65 case SW_REV_D:
66 puts(": RevD");
67 break;
68 case SW_REV_E:
69 puts(": RevE");
70 break;
71 default:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053072 puts(": unknown");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080073 break;
74 }
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053075
76 printf(", boot from QSPI");
Yangbo Lu481fb012017-12-08 15:35:35 +080077 if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053078 puts(": emu\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080079 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053080 puts(": bank1\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080081 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053082 puts(": bank2\n");
83 else
84 puts("unknown\n");
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053085#else
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053086
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053087 puts("Board: LS1012A2G5RDB ");
88#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053089 return 0;
90}
91
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +000092#ifdef CONFIG_TFABOOT
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053093int dram_init(void)
94{
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +000095 gd->ram_size = tfa_get_dram_size();
96 if (!gd->ram_size)
97 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
98
99 return 0;
100}
101#else
102int dram_init(void)
103{
104#ifndef CONFIG_TFABOOT
York Sun1fdcc8d2016-09-26 08:09:25 -0700105 static const struct fsl_mmdc_info mparam = {
106 0x05180000, /* mdctl */
107 0x00030035, /* mdpdc */
108 0x12554000, /* mdotc */
109 0xbabf7954, /* mdcfg0 */
110 0xdb328f64, /* mdcfg1 */
111 0x01ff00db, /* mdcfg2 */
112 0x00001680, /* mdmisc */
113 0x0f3c8000, /* mdref */
114 0x00002000, /* mdrwd */
115 0x00bf1023, /* mdor */
116 0x0000003f, /* mdasp */
117 0x0000022a, /* mpodtctrl */
118 0xa1390003, /* mpzqhwctrl */
119 };
120
121 mmdc_init(&mparam);
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000122#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530123
124 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
York Sun4961eaf2017-03-06 09:02:34 -0800125#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
126 /* This will break-before-make MMU for DDR */
127 update_early_mmu_table();
128#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530129
130 return 0;
131}
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000132#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530133
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530134
135int board_early_init_f(void)
136{
137 fsl_lsch2_early_init_f();
138
139 return 0;
140}
141
142int board_init(void)
143{
Ashish Kumar63b23162017-08-11 11:09:14 +0530144 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
145 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530146 /*
147 * Set CCI-400 control override register to enable barrier
148 * transaction
149 */
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000150 if (current_el() == 3)
151 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530152
Hou Zhiqiangb392a6d2016-08-02 19:03:27 +0800153#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
154 erratum_a010315();
155#endif
156
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530157#ifdef CONFIG_ENV_IS_NOWHERE
158 gd->env_addr = (ulong)&default_environment[0];
159#endif
160
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +0530161#ifdef CONFIG_FSL_CAAM
162 sec_init();
163#endif
164
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +0530165#ifdef CONFIG_FSL_LS_PPA
166 ppa_init();
167#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530168 return 0;
169}
170
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530171#ifdef CONFIG_TARGET_LS1012ARDB
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800172int esdhc_status_fixup(void *blob, const char *compat)
173{
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800174 char esdhc1_path[] = "/soc/esdhc@1580000";
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800175 bool sdhc2_en = false;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800176 u8 mux_sdhc2;
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800177 u8 io = 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800178
179 i2c_set_bus_num(0);
180
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800181 /* IO1[7:3] is the field of board revision info. */
182 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1) < 0) {
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800183 printf("Error reading i2c boot information!\n");
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800184 return 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800185 }
186
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800187 /* hwconfig method is used for RevD and later versions. */
188 if ((io & SW_REV_MASK) <= SW_REV_D) {
189#ifdef CONFIG_HWCONFIG
190 if (hwconfig("esdhc1"))
191 sdhc2_en = true;
192#endif
193 } else {
194 /*
195 * The I2C IO-expander for mux select is used to control
196 * the muxing of various onboard interfaces.
197 *
198 * IO0[3:2] indicates SDHC2 interface demultiplexer
199 * select lines.
200 * 00 - SDIO wifi
201 * 01 - GPIO (to Arduino)
202 * 10 - eMMC Memory
203 * 11 - SPI
204 */
205 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1) < 0) {
206 printf("Error reading i2c boot information!\n");
207 return 0;
208 }
209
210 mux_sdhc2 = (io & 0x0c) >> 2;
211 /* Enable SDHC2 only when use SDIO wifi and eMMC */
212 if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
213 sdhc2_en = true;
214 }
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800215 if (sdhc2_en)
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800216 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
217 sizeof("okay"), 1);
218 else
219 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
220 sizeof("disabled"), 1);
221 return 0;
222}
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530223#endif
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800224
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530225int ft_board_setup(void *blob, bd_t *bd)
226{
227 arch_fixup_fdt(blob);
228
229 ft_cpu_setup(blob, bd);
230
231 return 0;
232}
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530233
234static int switch_to_bank1(void)
235{
236 u8 data;
237 int ret;
238
239 i2c_set_bus_num(0);
240
241 data = 0xf4;
242 ret = i2c_write(0x24, 0x3, 1, &data, 1);
243 if (ret) {
244 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
245 0x24, 0x3, data);
246 }
247
248 return ret;
249}
250
251static int switch_to_bank2(void)
252{
253 u8 data;
254 int ret;
255
256 i2c_set_bus_num(0);
257
258 data = 0xfc;
259 ret = i2c_write(0x24, 0x7, 1, &data, 1);
260 if (ret) {
261 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
262 0x24, 0x7, data);
263 goto err;
264 }
265
266 data = 0xf5;
267 ret = i2c_write(0x24, 0x3, 1, &data, 1);
268 if (ret) {
269 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
270 0x24, 0x3, data);
271 }
272err:
273 return ret;
274}
275
276static int convert_flash_bank(int bank)
277{
278 int ret = 0;
279
280 switch (bank) {
281 case BOOT_FROM_UPPER_BANK:
282 ret = switch_to_bank2();
283 break;
284 case BOOT_FROM_LOWER_BANK:
285 ret = switch_to_bank1();
286 break;
287 default:
288 ret = CMD_RET_USAGE;
289 break;
290 };
291
292 return ret;
293}
294
295static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
296 char * const argv[])
297{
298 if (argc != 2)
299 return CMD_RET_USAGE;
300 if (strcmp(argv[1], "1") == 0)
301 convert_flash_bank(BOOT_FROM_LOWER_BANK);
302 else if (strcmp(argv[1], "2") == 0)
303 convert_flash_bank(BOOT_FROM_UPPER_BANK);
304 else
305 return CMD_RET_USAGE;
306
307 return 0;
308}
309
310U_BOOT_CMD(
311 boot_bank, 2, 0, flash_bank_cmd,
312 "Flash bank Selection Control",
313 "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
314);