blob: 18f92089caef1b4a3f8821b5b583cd7d79059abe [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.
Gaurav Jain476c6392022-03-24 11:50:35 +05304 * Copyright 2021 NXP
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +05305 */
6
Tom Riniabb9a042024-05-18 20:20:43 -06007#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -07009#include <fdt_support.h>
Simon Glassf11478f2019-12-28 10:45:07 -070010#include <hang.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053011#include <i2c.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <asm/cache.h>
Simon Glass97589732020-05-10 11:40:02 -060013#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053015#include <asm/io.h>
16#include <asm/arch/clock.h>
17#include <asm/arch/fsl_serdes.h>
York Sun729f2d12017-03-06 09:02:34 -080018#include <asm/arch/mmu.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053019#include <asm/arch/soc.h>
20#include <hwconfig.h>
21#include <ahci.h>
22#include <mmc.h>
23#include <scsi.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053024#include <fsl_esdhc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060025#include <env_internal.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053026#include <fsl_mmdc.h>
27#include <netdev.h>
Mian Yousaf Kaukab2529deae2021-04-14 12:33:58 +020028#include <net/pfe_eth/pfe/pfe_hw.h>
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053029
30DECLARE_GLOBAL_DATA_PTR;
31
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +053032#define BOOT_FROM_UPPER_BANK 0x2
33#define BOOT_FROM_LOWER_BANK 0x1
34
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053035int checkboard(void)
36{
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +053037#ifdef CONFIG_TARGET_LS1012ARDB
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053038 u8 in1;
Biwen Li0a759bb2019-12-31 15:33:41 +080039 int ret, bus_num = 0;
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053040
41 puts("Board: LS1012ARDB ");
42
43 /* Initialize i2c early for Serial flash bank information */
Igor Opaniukf7c91762021-02-09 13:52:45 +020044#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li0a759bb2019-12-31 15:33:41 +080045 struct udevice *dev;
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053046
Biwen Li0a759bb2019-12-31 15:33:41 +080047 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR,
48 1, &dev);
49 if (ret) {
50 printf("%s: Cannot find udev for a bus %d\n", __func__,
51 bus_num);
52 return -ENXIO;
53 }
54 ret = dm_i2c_read(dev, I2C_MUX_IO_1, &in1, 1);
55#else /* Non DM I2C support - will be removed */
56 i2c_set_bus_num(bus_num);
57 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1);
58#endif
59 if (ret < 0) {
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053060 printf("Error reading i2c boot information!\n");
61 return 0; /* Don't want to hang() on this error */
62 }
63
64 puts("Version");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080065 switch (in1 & SW_REV_MASK) {
66 case SW_REV_A:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053067 puts(": RevA");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080068 break;
69 case SW_REV_B:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053070 puts(": RevB");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080071 break;
72 case SW_REV_C:
73 puts(": RevC");
74 break;
75 case SW_REV_C1:
76 puts(": RevC1");
77 break;
78 case SW_REV_C2:
79 puts(": RevC2");
80 break;
81 case SW_REV_D:
82 puts(": RevD");
83 break;
84 case SW_REV_E:
85 puts(": RevE");
86 break;
87 default:
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053088 puts(": unknown");
Yangbo Lu13acb0d2017-12-08 15:35:36 +080089 break;
90 }
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053091
92 printf(", boot from QSPI");
Yangbo Lu2786f902017-12-08 15:35:35 +080093 if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053094 puts(": emu\n");
Yangbo Lu2786f902017-12-08 15:35:35 +080095 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053096 puts(": bank1\n");
Yangbo Lu2786f902017-12-08 15:35:35 +080097 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +053098 puts(": bank2\n");
99 else
100 puts("unknown\n");
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530101#else
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530102
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530103 puts("Board: LS1012A2G5RDB ");
104#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530105 return 0;
106}
107
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000108#ifdef CONFIG_TFABOOT
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530109int dram_init(void)
110{
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000111 gd->ram_size = tfa_get_dram_size();
112 if (!gd->ram_size)
Tom Rinibb4dd962022-11-16 13:10:37 -0500113 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000114
115 return 0;
116}
117#else
118int dram_init(void)
119{
120#ifndef CONFIG_TFABOOT
York Sunc1e979b2016-09-26 08:09:25 -0700121 static const struct fsl_mmdc_info mparam = {
122 0x05180000, /* mdctl */
123 0x00030035, /* mdpdc */
124 0x12554000, /* mdotc */
125 0xbabf7954, /* mdcfg0 */
126 0xdb328f64, /* mdcfg1 */
127 0x01ff00db, /* mdcfg2 */
128 0x00001680, /* mdmisc */
129 0x0f3c8000, /* mdref */
130 0x00002000, /* mdrwd */
131 0x00bf1023, /* mdor */
132 0x0000003f, /* mdasp */
133 0x0000022a, /* mpodtctrl */
134 0xa1390003, /* mpzqhwctrl */
135 };
136
137 mmdc_init(&mparam);
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000138#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530139
Tom Rinibb4dd962022-11-16 13:10:37 -0500140 gd->ram_size = CFG_SYS_SDRAM_SIZE;
York Sun729f2d12017-03-06 09:02:34 -0800141#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
142 /* This will break-before-make MMU for DDR */
143 update_early_mmu_table();
144#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530145
146 return 0;
147}
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000148#endif
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530149
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530150
151int board_early_init_f(void)
152{
153 fsl_lsch2_early_init_f();
154
155 return 0;
156}
157
158int board_init(void)
159{
Ashish Kumar11234062017-08-11 11:09:14 +0530160 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
161 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530162 /*
163 * Set CCI-400 control override register to enable barrier
164 * transaction
165 */
Rajesh Bhagatfcafef62018-11-05 18:02:53 +0000166 if (current_el() == 3)
167 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530168
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800169#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
170 erratum_a010315();
171#endif
172
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530173 return 0;
174}
175
Mian Yousaf Kaukab2529deae2021-04-14 12:33:58 +0200176#ifdef CONFIG_FSL_PFE
177void board_quiesce_devices(void)
178{
179 pfe_command_stop(0, NULL);
180}
181#endif
182
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530183#ifdef CONFIG_TARGET_LS1012ARDB
Yangbo Lub2495c02017-01-17 10:43:56 +0800184int esdhc_status_fixup(void *blob, const char *compat)
185{
Yangbo Lub2495c02017-01-17 10:43:56 +0800186 char esdhc1_path[] = "/soc/esdhc@1580000";
Yangbo Lu878c9782017-12-08 15:35:37 +0800187 bool sdhc2_en = false;
Yangbo Lub2495c02017-01-17 10:43:56 +0800188 u8 mux_sdhc2;
Yangbo Lu878c9782017-12-08 15:35:37 +0800189 u8 io = 0;
Biwen Li0a759bb2019-12-31 15:33:41 +0800190 int ret, bus_num = 0;
Yangbo Lub2495c02017-01-17 10:43:56 +0800191
Igor Opaniukf7c91762021-02-09 13:52:45 +0200192#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li0a759bb2019-12-31 15:33:41 +0800193 struct udevice *dev;
Yangbo Lub2495c02017-01-17 10:43:56 +0800194
Biwen Li0a759bb2019-12-31 15:33:41 +0800195 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR,
196 1, &dev);
197 if (ret) {
198 printf("%s: Cannot find udev for a bus %d\n", __func__,
199 bus_num);
200 return -ENXIO;
201 }
202 ret = dm_i2c_read(dev, I2C_MUX_IO_1, &io, 1);
203#else
204 i2c_set_bus_num(bus_num);
Yangbo Lu878c9782017-12-08 15:35:37 +0800205 /* IO1[7:3] is the field of board revision info. */
Biwen Li0a759bb2019-12-31 15:33:41 +0800206 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1);
207#endif
208 if (ret < 0) {
Yangbo Lub2495c02017-01-17 10:43:56 +0800209 printf("Error reading i2c boot information!\n");
Yangbo Lu878c9782017-12-08 15:35:37 +0800210 return 0;
Yangbo Lub2495c02017-01-17 10:43:56 +0800211 }
212
Yangbo Lu878c9782017-12-08 15:35:37 +0800213 /* hwconfig method is used for RevD and later versions. */
214 if ((io & SW_REV_MASK) <= SW_REV_D) {
215#ifdef CONFIG_HWCONFIG
216 if (hwconfig("esdhc1"))
217 sdhc2_en = true;
218#endif
219 } else {
220 /*
221 * The I2C IO-expander for mux select is used to control
222 * the muxing of various onboard interfaces.
223 *
224 * IO0[3:2] indicates SDHC2 interface demultiplexer
225 * select lines.
226 * 00 - SDIO wifi
227 * 01 - GPIO (to Arduino)
228 * 10 - eMMC Memory
229 * 11 - SPI
230 */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200231#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li0a759bb2019-12-31 15:33:41 +0800232 ret = dm_i2c_read(dev, I2C_MUX_IO_0, &io, 1);
233#else
234 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1);
235#endif
236 if (ret < 0) {
Yangbo Lu878c9782017-12-08 15:35:37 +0800237 printf("Error reading i2c boot information!\n");
238 return 0;
239 }
240
241 mux_sdhc2 = (io & 0x0c) >> 2;
242 /* Enable SDHC2 only when use SDIO wifi and eMMC */
243 if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
244 sdhc2_en = true;
245 }
Yangbo Lu878c9782017-12-08 15:35:37 +0800246 if (sdhc2_en)
Yangbo Lub2495c02017-01-17 10:43:56 +0800247 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
248 sizeof("okay"), 1);
249 else
250 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
251 sizeof("disabled"), 1);
252 return 0;
253}
Bhaskar Upadhaya7fff22a2018-01-11 20:03:31 +0530254#endif
Yangbo Lub2495c02017-01-17 10:43:56 +0800255
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900256int ft_board_setup(void *blob, struct bd_info *bd)
Prabhakar Kushwahaa315c662016-06-03 18:41:35 +0530257{
258 arch_fixup_fdt(blob);
259
260 ft_cpu_setup(blob, bd);
261
262 return 0;
263}
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530264
265static int switch_to_bank1(void)
266{
Biwen Li0a759bb2019-12-31 15:33:41 +0800267 u8 data = 0xf4, chip_addr = 0x24, offset_addr = 0x03;
268 int ret, bus_num = 0;
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530269
Igor Opaniukf7c91762021-02-09 13:52:45 +0200270#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li0a759bb2019-12-31 15:33:41 +0800271 struct udevice *dev;
272
273 ret = i2c_get_chip_for_busnum(bus_num, chip_addr,
274 1, &dev);
275 if (ret) {
276 printf("%s: Cannot find udev for a bus %d\n", __func__,
277 bus_num);
278 return -ENXIO;
279 }
280 /*
281 * --------------------------------------------------------------------
282 * |bus |I2C address| Device | Notes |
283 * --------------------------------------------------------------------
284 * |I2C1|0x24, 0x25,| IO expander (CFG,| Provides 16bits of General |
285 * | |0x26 | RESET, and INT/ | Purpose parallel Input/Output|
286 * | | | KW41GPIO) - NXP | (GPIO) expansion for the |
287 * | | | PCAL9555AHF | I2C bus |
288 * ----- --------------------------------------------------------------
289 * - mount three IO expander(PCAL9555AHF) on I2C1
290 *
291 * PCAL9555A device address
292 * slave address
293 * --------------------------------------
294 * | 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W |
295 * --------------------------------------
296 * | fixed | hardware selectable|
297 *
298 * Output port 1(Pinter register bits = 0x03)
299 *
300 * P1_[7~0] = 0xf4
301 * P1_0 <---> CFG_MUX_QSPI_S0
302 * P1_1 <---> CFG_MUX_QSPI_S1
303 * CFG_MUX_QSPI_S[1:0] = 0b00
304 *
305 * QSPI chip-select demultiplexer select
306 * ---------------------------------------------------------------------
307 * CFG_MUX_QSPI_S1|CFG_MUX_QSPI_S0| Values
308 * ---------------------------------------------------------------------
309 * 0 | 0 |CS routed to SPI memory bank1(default)
310 * ---------------------------------------------------------------------
311 * 0 | 1 |CS routed to SPI memory bank2
312 * ---------------------------------------------------------------------
313 *
314 */
315 ret = dm_i2c_write(dev, offset_addr, &data, 1);
316#else /* Non DM I2C support - will be removed */
317 i2c_set_bus_num(bus_num);
318 ret = i2c_write(chip_addr, offset_addr, 1, &data, 1);
319#endif
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530320
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530321 if (ret) {
322 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
Biwen Li0a759bb2019-12-31 15:33:41 +0800323 chip_addr, offset_addr, data);
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530324 }
325
326 return ret;
327}
328
329static int switch_to_bank2(void)
330{
Biwen Li0a759bb2019-12-31 15:33:41 +0800331 u8 data[2] = {0xfc, 0xf5}, offset_addr[2] = {0x7, 0x3};
332 u8 chip_addr = 0x24;
333 int ret, i, bus_num = 0;
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530334
Igor Opaniukf7c91762021-02-09 13:52:45 +0200335#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li0a759bb2019-12-31 15:33:41 +0800336 struct udevice *dev;
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530337
Biwen Li0a759bb2019-12-31 15:33:41 +0800338 ret = i2c_get_chip_for_busnum(bus_num, chip_addr,
339 1, &dev);
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530340 if (ret) {
Biwen Li0a759bb2019-12-31 15:33:41 +0800341 printf("%s: Cannot find udev for a bus %d\n", __func__,
342 bus_num);
343 return -ENXIO;
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530344 }
Biwen Li0a759bb2019-12-31 15:33:41 +0800345#else /* Non DM I2C support - will be removed */
346 i2c_set_bus_num(bus_num);
347#endif
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530348
Biwen Li0a759bb2019-12-31 15:33:41 +0800349 /*
350 * 1th step: config port 1
351 * - the port 1 pin is enabled as an output
352 * 2th step: output port 1
353 * - P1_[7:0] output 0xf5,
354 * then CFG_MUX_QSPI_S[1:0] equal to 0b01,
355 * CS routed to SPI memory bank2
356 */
357 for (i = 0; i < sizeof(data); i++) {
Igor Opaniukf7c91762021-02-09 13:52:45 +0200358#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li0a759bb2019-12-31 15:33:41 +0800359 ret = dm_i2c_write(dev, offset_addr[i], &data[i], 1);
360#else /* Non DM I2C support - will be removed */
361 ret = i2c_write(chip_addr, offset_addr[i], 1, &data[i], 1);
362#endif
363 if (ret) {
364 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
365 chip_addr, offset_addr[i], data[i]);
366 goto err;
367 }
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530368 }
Biwen Li0a759bb2019-12-31 15:33:41 +0800369
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530370err:
371 return ret;
372}
373
374static int convert_flash_bank(int bank)
375{
376 int ret = 0;
377
378 switch (bank) {
379 case BOOT_FROM_UPPER_BANK:
380 ret = switch_to_bank2();
381 break;
382 case BOOT_FROM_LOWER_BANK:
383 ret = switch_to_bank1();
384 break;
385 default:
386 ret = CMD_RET_USAGE;
387 break;
388 };
389
390 return ret;
391}
392
Simon Glassed38aef2020-05-10 11:40:03 -0600393static int flash_bank_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
394 char *const argv[])
Jagdish Gediyaf9cb31e2018-04-13 00:18:22 +0530395{
396 if (argc != 2)
397 return CMD_RET_USAGE;
398 if (strcmp(argv[1], "1") == 0)
399 convert_flash_bank(BOOT_FROM_LOWER_BANK);
400 else if (strcmp(argv[1], "2") == 0)
401 convert_flash_bank(BOOT_FROM_UPPER_BANK);
402 else
403 return CMD_RET_USAGE;
404
405 return 0;
406}
407
408U_BOOT_CMD(
409 boot_bank, 2, 0, flash_bank_cmd,
410 "Flash bank Selection Control",
411 "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
412);