blob: ab83ef11a098b1b0437366ccc498d8c831ce28f0 [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>
Simon Glass3bbe70c2019-12-28 10:44:54 -07007#include <fdt_support.h>
Simon Glassf11478f2019-12-28 10:45:07 -07008#include <hang.h>
Prabhakar Kushwahaa315c662016-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 Kushwaha74d129b2017-01-30 17:05:35 +053013#ifdef CONFIG_FSL_LS_PPA
14#include <asm/arch/ppa.h>
15#endif
York Sun729f2d12017-03-06 09:02:34 -080016#include <asm/arch/mmu.h>
Prabhakar Kushwahaa315c662016-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 Kushwahaa315c662016-06-03 18:41:35 +053022#include <fsl_esdhc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060023#include <env_internal.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053024#include <fsl_mmdc.h>
25#include <netdev.h>
Vinitha Pillai-B57223eea4a322017-03-23 13:48:20 +053026#include <fsl_sec.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053027
28DECLARE_GLOBAL_DATA_PTR;
29
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +053030#define BOOT_FROM_UPPER_BANK 0x2
31#define BOOT_FROM_LOWER_BANK 0x1
32
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053033int checkboard(void)
34{
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +053035#ifdef CONFIG_TARGET_LS1012ARDB
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053036 u8 in1;
Biwen Li0a759bb2019-12-31 15:33:41 +080037 int ret, bus_num = 0;
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053038
39 puts("Board: LS1012ARDB ");
40
41 /* Initialize i2c early for Serial flash bank information */
Biwen Li0a759bb2019-12-31 15:33:41 +080042#if defined(CONFIG_DM_I2C)
43 struct udevice *dev;
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053044
Biwen Li0a759bb2019-12-31 15:33:41 +080045 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR,
46 1, &dev);
47 if (ret) {
48 printf("%s: Cannot find udev for a bus %d\n", __func__,
49 bus_num);
50 return -ENXIO;
51 }
52 ret = dm_i2c_read(dev, I2C_MUX_IO_1, &in1, 1);
53#else /* Non DM I2C support - will be removed */
54 i2c_set_bus_num(bus_num);
55 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1);
56#endif
57 if (ret < 0) {
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053058 printf("Error reading i2c boot information!\n");
59 return 0; /* Don't want to hang() on this error */
60 }
61
62 puts("Version");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080063 switch (in1 & SW_REV_MASK) {
64 case SW_REV_A:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053065 puts(": RevA");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080066 break;
67 case SW_REV_B:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053068 puts(": RevB");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080069 break;
70 case SW_REV_C:
71 puts(": RevC");
72 break;
73 case SW_REV_C1:
74 puts(": RevC1");
75 break;
76 case SW_REV_C2:
77 puts(": RevC2");
78 break;
79 case SW_REV_D:
80 puts(": RevD");
81 break;
82 case SW_REV_E:
83 puts(": RevE");
84 break;
85 default:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053086 puts(": unknown");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080087 break;
88 }
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053089
90 printf(", boot from QSPI");
Yangbo Lu2786f902017-12-08 15:35:35 +080091 if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053092 puts(": emu\n");
Yangbo Lu2786f902017-12-08 15:35:35 +080093 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053094 puts(": bank1\n");
Yangbo Lu2786f902017-12-08 15:35:35 +080095 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053096 puts(": bank2\n");
97 else
98 puts("unknown\n");
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +053099#else
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530100
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530101 puts("Board: LS1012A2G5RDB ");
102#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530103 return 0;
104}
105
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000106#ifdef CONFIG_TFABOOT
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530107int dram_init(void)
108{
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000109 gd->ram_size = tfa_get_dram_size();
110 if (!gd->ram_size)
111 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
112
113 return 0;
114}
115#else
116int dram_init(void)
117{
118#ifndef CONFIG_TFABOOT
York Sunc1e979b2016-09-26 08:09:25 -0700119 static const struct fsl_mmdc_info mparam = {
120 0x05180000, /* mdctl */
121 0x00030035, /* mdpdc */
122 0x12554000, /* mdotc */
123 0xbabf7954, /* mdcfg0 */
124 0xdb328f64, /* mdcfg1 */
125 0x01ff00db, /* mdcfg2 */
126 0x00001680, /* mdmisc */
127 0x0f3c8000, /* mdref */
128 0x00002000, /* mdrwd */
129 0x00bf1023, /* mdor */
130 0x0000003f, /* mdasp */
131 0x0000022a, /* mpodtctrl */
132 0xa1390003, /* mpzqhwctrl */
133 };
134
135 mmdc_init(&mparam);
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000136#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530137
138 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
York Sun729f2d12017-03-06 09:02:34 -0800139#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
140 /* This will break-before-make MMU for DDR */
141 update_early_mmu_table();
142#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530143
144 return 0;
145}
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000146#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530147
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530148
149int board_early_init_f(void)
150{
151 fsl_lsch2_early_init_f();
152
153 return 0;
154}
155
156int board_init(void)
157{
Ashish Kumar11234062017-08-11 11:09:14 +0530158 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
159 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530160 /*
161 * Set CCI-400 control override register to enable barrier
162 * transaction
163 */
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000164 if (current_el() == 3)
165 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530166
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800167#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
168 erratum_a010315();
169#endif
170
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530171#ifdef CONFIG_ENV_IS_NOWHERE
172 gd->env_addr = (ulong)&default_environment[0];
173#endif
174
Vinitha Pillai-B57223eea4a322017-03-23 13:48:20 +0530175#ifdef CONFIG_FSL_CAAM
176 sec_init();
177#endif
178
Prabhakar Kushwaha74d129b2017-01-30 17:05:35 +0530179#ifdef CONFIG_FSL_LS_PPA
180 ppa_init();
181#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530182 return 0;
183}
184
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530185#ifdef CONFIG_TARGET_LS1012ARDB
Yangbo Lub2495c02017-01-17 10:43:56 +0800186int esdhc_status_fixup(void *blob, const char *compat)
187{
Yangbo Lub2495c02017-01-17 10:43:56 +0800188 char esdhc1_path[] = "/soc/esdhc@1580000";
Yangbo Lu878c9782017-12-08 15:35:37 +0800189 bool sdhc2_en = false;
Yangbo Lub2495c02017-01-17 10:43:56 +0800190 u8 mux_sdhc2;
Yangbo Lu878c9782017-12-08 15:35:37 +0800191 u8 io = 0;
Biwen Li0a759bb2019-12-31 15:33:41 +0800192 int ret, bus_num = 0;
Yangbo Lub2495c02017-01-17 10:43:56 +0800193
Biwen Li0a759bb2019-12-31 15:33:41 +0800194#if defined(CONFIG_DM_I2C)
195 struct udevice *dev;
Yangbo Lub2495c02017-01-17 10:43:56 +0800196
Biwen Li0a759bb2019-12-31 15:33:41 +0800197 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR,
198 1, &dev);
199 if (ret) {
200 printf("%s: Cannot find udev for a bus %d\n", __func__,
201 bus_num);
202 return -ENXIO;
203 }
204 ret = dm_i2c_read(dev, I2C_MUX_IO_1, &io, 1);
205#else
206 i2c_set_bus_num(bus_num);
Yangbo Lu878c9782017-12-08 15:35:37 +0800207 /* IO1[7:3] is the field of board revision info. */
Biwen Li0a759bb2019-12-31 15:33:41 +0800208 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1);
209#endif
210 if (ret < 0) {
Yangbo Lub2495c02017-01-17 10:43:56 +0800211 printf("Error reading i2c boot information!\n");
Yangbo Lu878c9782017-12-08 15:35:37 +0800212 return 0;
Yangbo Lub2495c02017-01-17 10:43:56 +0800213 }
214
Yangbo Lu878c9782017-12-08 15:35:37 +0800215 /* hwconfig method is used for RevD and later versions. */
216 if ((io & SW_REV_MASK) <= SW_REV_D) {
217#ifdef CONFIG_HWCONFIG
218 if (hwconfig("esdhc1"))
219 sdhc2_en = true;
220#endif
221 } else {
222 /*
223 * The I2C IO-expander for mux select is used to control
224 * the muxing of various onboard interfaces.
225 *
226 * IO0[3:2] indicates SDHC2 interface demultiplexer
227 * select lines.
228 * 00 - SDIO wifi
229 * 01 - GPIO (to Arduino)
230 * 10 - eMMC Memory
231 * 11 - SPI
232 */
Biwen Li0a759bb2019-12-31 15:33:41 +0800233#if defined(CONFIG_DM_I2C)
234 ret = dm_i2c_read(dev, I2C_MUX_IO_0, &io, 1);
235#else
236 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1);
237#endif
238 if (ret < 0) {
Yangbo Lu878c9782017-12-08 15:35:37 +0800239 printf("Error reading i2c boot information!\n");
240 return 0;
241 }
242
243 mux_sdhc2 = (io & 0x0c) >> 2;
244 /* Enable SDHC2 only when use SDIO wifi and eMMC */
245 if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
246 sdhc2_en = true;
247 }
Yangbo Lu878c9782017-12-08 15:35:37 +0800248 if (sdhc2_en)
Yangbo Lub2495c02017-01-17 10:43:56 +0800249 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
250 sizeof("okay"), 1);
251 else
252 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
253 sizeof("disabled"), 1);
254 return 0;
255}
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530256#endif
Yangbo Lub2495c02017-01-17 10:43:56 +0800257
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530258int ft_board_setup(void *blob, bd_t *bd)
259{
260 arch_fixup_fdt(blob);
261
262 ft_cpu_setup(blob, bd);
263
264 return 0;
265}
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530266
267static int switch_to_bank1(void)
268{
Biwen Li0a759bb2019-12-31 15:33:41 +0800269 u8 data = 0xf4, chip_addr = 0x24, offset_addr = 0x03;
270 int ret, bus_num = 0;
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530271
Biwen Li0a759bb2019-12-31 15:33:41 +0800272#if defined(CONFIG_DM_I2C)
273 struct udevice *dev;
274
275 ret = i2c_get_chip_for_busnum(bus_num, chip_addr,
276 1, &dev);
277 if (ret) {
278 printf("%s: Cannot find udev for a bus %d\n", __func__,
279 bus_num);
280 return -ENXIO;
281 }
282 /*
283 * --------------------------------------------------------------------
284 * |bus |I2C address| Device | Notes |
285 * --------------------------------------------------------------------
286 * |I2C1|0x24, 0x25,| IO expander (CFG,| Provides 16bits of General |
287 * | |0x26 | RESET, and INT/ | Purpose parallel Input/Output|
288 * | | | KW41GPIO) - NXP | (GPIO) expansion for the |
289 * | | | PCAL9555AHF | I2C bus |
290 * ----- --------------------------------------------------------------
291 * - mount three IO expander(PCAL9555AHF) on I2C1
292 *
293 * PCAL9555A device address
294 * slave address
295 * --------------------------------------
296 * | 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W |
297 * --------------------------------------
298 * | fixed | hardware selectable|
299 *
300 * Output port 1(Pinter register bits = 0x03)
301 *
302 * P1_[7~0] = 0xf4
303 * P1_0 <---> CFG_MUX_QSPI_S0
304 * P1_1 <---> CFG_MUX_QSPI_S1
305 * CFG_MUX_QSPI_S[1:0] = 0b00
306 *
307 * QSPI chip-select demultiplexer select
308 * ---------------------------------------------------------------------
309 * CFG_MUX_QSPI_S1|CFG_MUX_QSPI_S0| Values
310 * ---------------------------------------------------------------------
311 * 0 | 0 |CS routed to SPI memory bank1(default)
312 * ---------------------------------------------------------------------
313 * 0 | 1 |CS routed to SPI memory bank2
314 * ---------------------------------------------------------------------
315 *
316 */
317 ret = dm_i2c_write(dev, offset_addr, &data, 1);
318#else /* Non DM I2C support - will be removed */
319 i2c_set_bus_num(bus_num);
320 ret = i2c_write(chip_addr, offset_addr, 1, &data, 1);
321#endif
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530322
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530323 if (ret) {
324 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
Biwen Li0a759bb2019-12-31 15:33:41 +0800325 chip_addr, offset_addr, data);
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530326 }
327
328 return ret;
329}
330
331static int switch_to_bank2(void)
332{
Biwen Li0a759bb2019-12-31 15:33:41 +0800333 u8 data[2] = {0xfc, 0xf5}, offset_addr[2] = {0x7, 0x3};
334 u8 chip_addr = 0x24;
335 int ret, i, bus_num = 0;
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530336
Biwen Li0a759bb2019-12-31 15:33:41 +0800337#if defined(CONFIG_DM_I2C)
338 struct udevice *dev;
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530339
Biwen Li0a759bb2019-12-31 15:33:41 +0800340 ret = i2c_get_chip_for_busnum(bus_num, chip_addr,
341 1, &dev);
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530342 if (ret) {
Biwen Li0a759bb2019-12-31 15:33:41 +0800343 printf("%s: Cannot find udev for a bus %d\n", __func__,
344 bus_num);
345 return -ENXIO;
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530346 }
Biwen Li0a759bb2019-12-31 15:33:41 +0800347#else /* Non DM I2C support - will be removed */
348 i2c_set_bus_num(bus_num);
349#endif
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530350
Biwen Li0a759bb2019-12-31 15:33:41 +0800351 /*
352 * 1th step: config port 1
353 * - the port 1 pin is enabled as an output
354 * 2th step: output port 1
355 * - P1_[7:0] output 0xf5,
356 * then CFG_MUX_QSPI_S[1:0] equal to 0b01,
357 * CS routed to SPI memory bank2
358 */
359 for (i = 0; i < sizeof(data); i++) {
360#if defined(CONFIG_DM_I2C)
361 ret = dm_i2c_write(dev, offset_addr[i], &data[i], 1);
362#else /* Non DM I2C support - will be removed */
363 ret = i2c_write(chip_addr, offset_addr[i], 1, &data[i], 1);
364#endif
365 if (ret) {
366 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
367 chip_addr, offset_addr[i], data[i]);
368 goto err;
369 }
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530370 }
Biwen Li0a759bb2019-12-31 15:33:41 +0800371
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530372err:
373 return ret;
374}
375
376static int convert_flash_bank(int bank)
377{
378 int ret = 0;
379
380 switch (bank) {
381 case BOOT_FROM_UPPER_BANK:
382 ret = switch_to_bank2();
383 break;
384 case BOOT_FROM_LOWER_BANK:
385 ret = switch_to_bank1();
386 break;
387 default:
388 ret = CMD_RET_USAGE;
389 break;
390 };
391
392 return ret;
393}
394
395static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
396 char * const argv[])
397{
398 if (argc != 2)
399 return CMD_RET_USAGE;
400 if (strcmp(argv[1], "1") == 0)
401 convert_flash_bank(BOOT_FROM_LOWER_BANK);
402 else if (strcmp(argv[1], "2") == 0)
403 convert_flash_bank(BOOT_FROM_UPPER_BANK);
404 else
405 return CMD_RET_USAGE;
406
407 return 0;
408}
409
410U_BOOT_CMD(
411 boot_bank, 2, 0, flash_bank_cmd,
412 "Flash bank Selection Control",
413 "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
414);