blob: 064fb4d39fad90d236d6810ded5bd9ace9d52372 [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 Glass09140112020-05-10 11:40:03 -06007#include <command.h>
Simon Glass807765b2019-12-28 10:44:54 -07008#include <fdt_support.h>
Simon Glassdb41d652019-12-28 10:45:07 -07009#include <hang.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053010#include <i2c.h>
Simon Glass90526e92020-05-10 11:39:56 -060011#include <asm/cache.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053014#include <asm/io.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +053017#ifdef CONFIG_FSL_LS_PPA
18#include <asm/arch/ppa.h>
19#endif
York Sun4961eaf2017-03-06 09:02:34 -080020#include <asm/arch/mmu.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053021#include <asm/arch/soc.h>
22#include <hwconfig.h>
23#include <ahci.h>
24#include <mmc.h>
25#include <scsi.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053026#include <fsl_esdhc.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060027#include <env_internal.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053028#include <fsl_mmdc.h>
29#include <netdev.h>
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +053030#include <fsl_sec.h>
Mian Yousaf Kaukab864c3db2021-04-14 12:33:58 +020031#include <net/pfe_eth/pfe/pfe_hw.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053032
33DECLARE_GLOBAL_DATA_PTR;
34
Jagdish Gediya3fa48f02018-04-13 00:18:22 +053035#define BOOT_FROM_UPPER_BANK 0x2
36#define BOOT_FROM_LOWER_BANK 0x1
37
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053038int checkboard(void)
39{
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053040#ifdef CONFIG_TARGET_LS1012ARDB
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053041 u8 in1;
Biwen Lia0affb32019-12-31 15:33:41 +080042 int ret, bus_num = 0;
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053043
44 puts("Board: LS1012ARDB ");
45
46 /* Initialize i2c early for Serial flash bank information */
Igor Opaniuk2147a162021-02-09 13:52:45 +020047#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Lia0affb32019-12-31 15:33:41 +080048 struct udevice *dev;
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053049
Biwen Lia0affb32019-12-31 15:33:41 +080050 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR,
51 1, &dev);
52 if (ret) {
53 printf("%s: Cannot find udev for a bus %d\n", __func__,
54 bus_num);
55 return -ENXIO;
56 }
57 ret = dm_i2c_read(dev, I2C_MUX_IO_1, &in1, 1);
58#else /* Non DM I2C support - will be removed */
59 i2c_set_bus_num(bus_num);
60 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1);
61#endif
62 if (ret < 0) {
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053063 printf("Error reading i2c boot information!\n");
64 return 0; /* Don't want to hang() on this error */
65 }
66
67 puts("Version");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080068 switch (in1 & SW_REV_MASK) {
69 case SW_REV_A:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053070 puts(": RevA");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080071 break;
72 case SW_REV_B:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053073 puts(": RevB");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080074 break;
75 case SW_REV_C:
76 puts(": RevC");
77 break;
78 case SW_REV_C1:
79 puts(": RevC1");
80 break;
81 case SW_REV_C2:
82 puts(": RevC2");
83 break;
84 case SW_REV_D:
85 puts(": RevD");
86 break;
87 case SW_REV_E:
88 puts(": RevE");
89 break;
90 default:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053091 puts(": unknown");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080092 break;
93 }
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053094
95 printf(", boot from QSPI");
Yangbo Lu481fb012017-12-08 15:35:35 +080096 if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053097 puts(": emu\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080098 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053099 puts(": bank1\n");
Yangbo Lu481fb012017-12-08 15:35:35 +0800100 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530101 puts(": bank2\n");
102 else
103 puts("unknown\n");
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530104#else
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530105
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530106 puts("Board: LS1012A2G5RDB ");
107#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530108 return 0;
109}
110
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000111#ifdef CONFIG_TFABOOT
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530112int dram_init(void)
113{
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000114 gd->ram_size = tfa_get_dram_size();
115 if (!gd->ram_size)
116 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
117
118 return 0;
119}
120#else
121int dram_init(void)
122{
123#ifndef CONFIG_TFABOOT
York Sun1fdcc8d2016-09-26 08:09:25 -0700124 static const struct fsl_mmdc_info mparam = {
125 0x05180000, /* mdctl */
126 0x00030035, /* mdpdc */
127 0x12554000, /* mdotc */
128 0xbabf7954, /* mdcfg0 */
129 0xdb328f64, /* mdcfg1 */
130 0x01ff00db, /* mdcfg2 */
131 0x00001680, /* mdmisc */
132 0x0f3c8000, /* mdref */
133 0x00002000, /* mdrwd */
134 0x00bf1023, /* mdor */
135 0x0000003f, /* mdasp */
136 0x0000022a, /* mpodtctrl */
137 0xa1390003, /* mpzqhwctrl */
138 };
139
140 mmdc_init(&mparam);
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000141#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530142
143 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
York Sun4961eaf2017-03-06 09:02:34 -0800144#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
145 /* This will break-before-make MMU for DDR */
146 update_early_mmu_table();
147#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530148
149 return 0;
150}
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000151#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530152
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530153
154int board_early_init_f(void)
155{
156 fsl_lsch2_early_init_f();
157
158 return 0;
159}
160
161int board_init(void)
162{
Ashish Kumar63b23162017-08-11 11:09:14 +0530163 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
164 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530165 /*
166 * Set CCI-400 control override register to enable barrier
167 * transaction
168 */
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000169 if (current_el() == 3)
170 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530171
Hou Zhiqiangb392a6d2016-08-02 19:03:27 +0800172#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
173 erratum_a010315();
174#endif
175
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +0530176#ifdef CONFIG_FSL_CAAM
177 sec_init();
178#endif
179
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +0530180#ifdef CONFIG_FSL_LS_PPA
181 ppa_init();
182#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530183 return 0;
184}
185
Mian Yousaf Kaukab864c3db2021-04-14 12:33:58 +0200186#ifdef CONFIG_FSL_PFE
187void board_quiesce_devices(void)
188{
189 pfe_command_stop(0, NULL);
190}
191#endif
192
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530193#ifdef CONFIG_TARGET_LS1012ARDB
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800194int esdhc_status_fixup(void *blob, const char *compat)
195{
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800196 char esdhc1_path[] = "/soc/esdhc@1580000";
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800197 bool sdhc2_en = false;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800198 u8 mux_sdhc2;
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800199 u8 io = 0;
Biwen Lia0affb32019-12-31 15:33:41 +0800200 int ret, bus_num = 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800201
Igor Opaniuk2147a162021-02-09 13:52:45 +0200202#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Lia0affb32019-12-31 15:33:41 +0800203 struct udevice *dev;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800204
Biwen Lia0affb32019-12-31 15:33:41 +0800205 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR,
206 1, &dev);
207 if (ret) {
208 printf("%s: Cannot find udev for a bus %d\n", __func__,
209 bus_num);
210 return -ENXIO;
211 }
212 ret = dm_i2c_read(dev, I2C_MUX_IO_1, &io, 1);
213#else
214 i2c_set_bus_num(bus_num);
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800215 /* IO1[7:3] is the field of board revision info. */
Biwen Lia0affb32019-12-31 15:33:41 +0800216 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1);
217#endif
218 if (ret < 0) {
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800219 printf("Error reading i2c boot information!\n");
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800220 return 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800221 }
222
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800223 /* hwconfig method is used for RevD and later versions. */
224 if ((io & SW_REV_MASK) <= SW_REV_D) {
225#ifdef CONFIG_HWCONFIG
226 if (hwconfig("esdhc1"))
227 sdhc2_en = true;
228#endif
229 } else {
230 /*
231 * The I2C IO-expander for mux select is used to control
232 * the muxing of various onboard interfaces.
233 *
234 * IO0[3:2] indicates SDHC2 interface demultiplexer
235 * select lines.
236 * 00 - SDIO wifi
237 * 01 - GPIO (to Arduino)
238 * 10 - eMMC Memory
239 * 11 - SPI
240 */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200241#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Lia0affb32019-12-31 15:33:41 +0800242 ret = dm_i2c_read(dev, I2C_MUX_IO_0, &io, 1);
243#else
244 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1);
245#endif
246 if (ret < 0) {
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800247 printf("Error reading i2c boot information!\n");
248 return 0;
249 }
250
251 mux_sdhc2 = (io & 0x0c) >> 2;
252 /* Enable SDHC2 only when use SDIO wifi and eMMC */
253 if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
254 sdhc2_en = true;
255 }
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800256 if (sdhc2_en)
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800257 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
258 sizeof("okay"), 1);
259 else
260 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
261 sizeof("disabled"), 1);
262 return 0;
263}
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530264#endif
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800265
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900266int ft_board_setup(void *blob, struct bd_info *bd)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530267{
268 arch_fixup_fdt(blob);
269
270 ft_cpu_setup(blob, bd);
271
272 return 0;
273}
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530274
275static int switch_to_bank1(void)
276{
Biwen Lia0affb32019-12-31 15:33:41 +0800277 u8 data = 0xf4, chip_addr = 0x24, offset_addr = 0x03;
278 int ret, bus_num = 0;
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530279
Igor Opaniuk2147a162021-02-09 13:52:45 +0200280#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Lia0affb32019-12-31 15:33:41 +0800281 struct udevice *dev;
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530282
Biwen Lia0affb32019-12-31 15:33:41 +0800283 ret = i2c_get_chip_for_busnum(bus_num, chip_addr,
284 1, &dev);
285 if (ret) {
286 printf("%s: Cannot find udev for a bus %d\n", __func__,
287 bus_num);
288 return -ENXIO;
289 }
290 /*
291 * --------------------------------------------------------------------
292 * |bus |I2C address| Device | Notes |
293 * --------------------------------------------------------------------
294 * |I2C1|0x24, 0x25,| IO expander (CFG,| Provides 16bits of General |
295 * | |0x26 | RESET, and INT/ | Purpose parallel Input/Output|
296 * | | | KW41GPIO) - NXP | (GPIO) expansion for the |
297 * | | | PCAL9555AHF | I2C bus |
298 * ----- --------------------------------------------------------------
299 * - mount three IO expander(PCAL9555AHF) on I2C1
300 *
301 * PCAL9555A device address
302 * slave address
303 * --------------------------------------
304 * | 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W |
305 * --------------------------------------
306 * | fixed | hardware selectable|
307 *
308 * Output port 1(Pinter register bits = 0x03)
309 *
310 * P1_[7~0] = 0xf4
311 * P1_0 <---> CFG_MUX_QSPI_S0
312 * P1_1 <---> CFG_MUX_QSPI_S1
313 * CFG_MUX_QSPI_S[1:0] = 0b00
314 *
315 * QSPI chip-select demultiplexer select
316 * ---------------------------------------------------------------------
317 * CFG_MUX_QSPI_S1|CFG_MUX_QSPI_S0| Values
318 * ---------------------------------------------------------------------
319 * 0 | 0 |CS routed to SPI memory bank1(default)
320 * ---------------------------------------------------------------------
321 * 0 | 1 |CS routed to SPI memory bank2
322 * ---------------------------------------------------------------------
323 *
324 */
325 ret = dm_i2c_write(dev, offset_addr, &data, 1);
326#else /* Non DM I2C support - will be removed */
327 i2c_set_bus_num(bus_num);
328 ret = i2c_write(chip_addr, offset_addr, 1, &data, 1);
329#endif
330
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530331 if (ret) {
332 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
Biwen Lia0affb32019-12-31 15:33:41 +0800333 chip_addr, offset_addr, data);
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530334 }
335
336 return ret;
337}
338
339static int switch_to_bank2(void)
340{
Biwen Lia0affb32019-12-31 15:33:41 +0800341 u8 data[2] = {0xfc, 0xf5}, offset_addr[2] = {0x7, 0x3};
342 u8 chip_addr = 0x24;
343 int ret, i, bus_num = 0;
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530344
Igor Opaniuk2147a162021-02-09 13:52:45 +0200345#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Lia0affb32019-12-31 15:33:41 +0800346 struct udevice *dev;
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530347
Biwen Lia0affb32019-12-31 15:33:41 +0800348 ret = i2c_get_chip_for_busnum(bus_num, chip_addr,
349 1, &dev);
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530350 if (ret) {
Biwen Lia0affb32019-12-31 15:33:41 +0800351 printf("%s: Cannot find udev for a bus %d\n", __func__,
352 bus_num);
353 return -ENXIO;
354 }
355#else /* Non DM I2C support - will be removed */
356 i2c_set_bus_num(bus_num);
357#endif
358
359 /*
360 * 1th step: config port 1
361 * - the port 1 pin is enabled as an output
362 * 2th step: output port 1
363 * - P1_[7:0] output 0xf5,
364 * then CFG_MUX_QSPI_S[1:0] equal to 0b01,
365 * CS routed to SPI memory bank2
366 */
367 for (i = 0; i < sizeof(data); i++) {
Igor Opaniuk2147a162021-02-09 13:52:45 +0200368#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Lia0affb32019-12-31 15:33:41 +0800369 ret = dm_i2c_write(dev, offset_addr[i], &data[i], 1);
370#else /* Non DM I2C support - will be removed */
371 ret = i2c_write(chip_addr, offset_addr[i], 1, &data[i], 1);
372#endif
373 if (ret) {
374 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
375 chip_addr, offset_addr[i], data[i]);
376 goto err;
377 }
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530378 }
379
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530380err:
381 return ret;
382}
383
384static int convert_flash_bank(int bank)
385{
386 int ret = 0;
387
388 switch (bank) {
389 case BOOT_FROM_UPPER_BANK:
390 ret = switch_to_bank2();
391 break;
392 case BOOT_FROM_LOWER_BANK:
393 ret = switch_to_bank1();
394 break;
395 default:
396 ret = CMD_RET_USAGE;
397 break;
398 };
399
400 return ret;
401}
402
Simon Glass09140112020-05-10 11:40:03 -0600403static int flash_bank_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
404 char *const argv[])
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530405{
406 if (argc != 2)
407 return CMD_RET_USAGE;
408 if (strcmp(argv[1], "1") == 0)
409 convert_flash_bank(BOOT_FROM_LOWER_BANK);
410 else if (strcmp(argv[1], "2") == 0)
411 convert_flash_bank(BOOT_FROM_UPPER_BANK);
412 else
413 return CMD_RET_USAGE;
414
415 return 0;
416}
417
418U_BOOT_CMD(
419 boot_bank, 2, 0, flash_bank_cmd,
420 "Flash bank Selection Control",
421 "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
422);