blob: fc929c441c24615270b35855b07f1754409be5d2 [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>
Simon Glass90526e92020-05-10 11:39:56 -060010#include <asm/cache.h>
Simon Glass691d7192020-05-10 11:40:02 -060011#include <init.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053012#include <asm/io.h>
13#include <asm/arch/clock.h>
14#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +053015#ifdef CONFIG_FSL_LS_PPA
16#include <asm/arch/ppa.h>
17#endif
York Sun4961eaf2017-03-06 09:02:34 -080018#include <asm/arch/mmu.h>
Prabhakar Kushwaha3b6e3892016-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 Kushwaha3b6e3892016-06-03 18:41:35 +053024#include <fsl_esdhc.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060025#include <env_internal.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053026#include <fsl_mmdc.h>
27#include <netdev.h>
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +053028#include <fsl_sec.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053029
30DECLARE_GLOBAL_DATA_PTR;
31
Jagdish Gediya3fa48f02018-04-13 00:18:22 +053032#define BOOT_FROM_UPPER_BANK 0x2
33#define BOOT_FROM_LOWER_BANK 0x1
34
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053035int checkboard(void)
36{
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053037#ifdef CONFIG_TARGET_LS1012ARDB
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053038 u8 in1;
Biwen Lia0affb32019-12-31 15:33:41 +080039 int ret, bus_num = 0;
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053040
41 puts("Board: LS1012ARDB ");
42
43 /* Initialize i2c early for Serial flash bank information */
Biwen Lia0affb32019-12-31 15:33:41 +080044#if defined(CONFIG_DM_I2C)
45 struct udevice *dev;
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053046
Biwen Lia0affb32019-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 Kushwaha3b6e3892016-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 Lu4a47bf82017-12-08 15:35:36 +080065 switch (in1 & SW_REV_MASK) {
66 case SW_REV_A:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053067 puts(": RevA");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080068 break;
69 case SW_REV_B:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053070 puts(": RevB");
Yangbo Lu4a47bf82017-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 Kushwaha3b6e3892016-06-03 18:41:35 +053088 puts(": unknown");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080089 break;
90 }
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053091
92 printf(", boot from QSPI");
Yangbo Lu481fb012017-12-08 15:35:35 +080093 if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053094 puts(": emu\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080095 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053096 puts(": bank1\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080097 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053098 puts(": bank2\n");
99 else
100 puts("unknown\n");
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530101#else
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530102
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530103 puts("Board: LS1012A2G5RDB ");
104#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530105 return 0;
106}
107
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000108#ifdef CONFIG_TFABOOT
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530109int dram_init(void)
110{
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000111 gd->ram_size = tfa_get_dram_size();
112 if (!gd->ram_size)
113 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
114
115 return 0;
116}
117#else
118int dram_init(void)
119{
120#ifndef CONFIG_TFABOOT
York Sun1fdcc8d2016-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 Bhagat1f6180d2018-11-05 18:02:53 +0000138#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530139
140 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
York Sun4961eaf2017-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 Kushwaha3b6e3892016-06-03 18:41:35 +0530145
146 return 0;
147}
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000148#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530149
Prabhakar Kushwaha3b6e3892016-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 Kumar63b23162017-08-11 11:09:14 +0530160 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
161 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530162 /*
163 * Set CCI-400 control override register to enable barrier
164 * transaction
165 */
Rajesh Bhagat1f6180d2018-11-05 18:02:53 +0000166 if (current_el() == 3)
167 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530168
Hou Zhiqiangb392a6d2016-08-02 19:03:27 +0800169#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
170 erratum_a010315();
171#endif
172
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530173#ifdef CONFIG_ENV_IS_NOWHERE
174 gd->env_addr = (ulong)&default_environment[0];
175#endif
176
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +0530177#ifdef CONFIG_FSL_CAAM
178 sec_init();
179#endif
180
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +0530181#ifdef CONFIG_FSL_LS_PPA
182 ppa_init();
183#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530184 return 0;
185}
186
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530187#ifdef CONFIG_TARGET_LS1012ARDB
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800188int esdhc_status_fixup(void *blob, const char *compat)
189{
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800190 char esdhc1_path[] = "/soc/esdhc@1580000";
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800191 bool sdhc2_en = false;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800192 u8 mux_sdhc2;
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800193 u8 io = 0;
Biwen Lia0affb32019-12-31 15:33:41 +0800194 int ret, bus_num = 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800195
Biwen Lia0affb32019-12-31 15:33:41 +0800196#if defined(CONFIG_DM_I2C)
197 struct udevice *dev;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800198
Biwen Lia0affb32019-12-31 15:33:41 +0800199 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_IO_ADDR,
200 1, &dev);
201 if (ret) {
202 printf("%s: Cannot find udev for a bus %d\n", __func__,
203 bus_num);
204 return -ENXIO;
205 }
206 ret = dm_i2c_read(dev, I2C_MUX_IO_1, &io, 1);
207#else
208 i2c_set_bus_num(bus_num);
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800209 /* IO1[7:3] is the field of board revision info. */
Biwen Lia0affb32019-12-31 15:33:41 +0800210 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1);
211#endif
212 if (ret < 0) {
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800213 printf("Error reading i2c boot information!\n");
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800214 return 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800215 }
216
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800217 /* hwconfig method is used for RevD and later versions. */
218 if ((io & SW_REV_MASK) <= SW_REV_D) {
219#ifdef CONFIG_HWCONFIG
220 if (hwconfig("esdhc1"))
221 sdhc2_en = true;
222#endif
223 } else {
224 /*
225 * The I2C IO-expander for mux select is used to control
226 * the muxing of various onboard interfaces.
227 *
228 * IO0[3:2] indicates SDHC2 interface demultiplexer
229 * select lines.
230 * 00 - SDIO wifi
231 * 01 - GPIO (to Arduino)
232 * 10 - eMMC Memory
233 * 11 - SPI
234 */
Biwen Lia0affb32019-12-31 15:33:41 +0800235#if defined(CONFIG_DM_I2C)
236 ret = dm_i2c_read(dev, I2C_MUX_IO_0, &io, 1);
237#else
238 ret = i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1);
239#endif
240 if (ret < 0) {
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800241 printf("Error reading i2c boot information!\n");
242 return 0;
243 }
244
245 mux_sdhc2 = (io & 0x0c) >> 2;
246 /* Enable SDHC2 only when use SDIO wifi and eMMC */
247 if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
248 sdhc2_en = true;
249 }
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800250 if (sdhc2_en)
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800251 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
252 sizeof("okay"), 1);
253 else
254 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
255 sizeof("disabled"), 1);
256 return 0;
257}
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530258#endif
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800259
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530260int ft_board_setup(void *blob, bd_t *bd)
261{
262 arch_fixup_fdt(blob);
263
264 ft_cpu_setup(blob, bd);
265
266 return 0;
267}
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530268
269static int switch_to_bank1(void)
270{
Biwen Lia0affb32019-12-31 15:33:41 +0800271 u8 data = 0xf4, chip_addr = 0x24, offset_addr = 0x03;
272 int ret, bus_num = 0;
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530273
Biwen Lia0affb32019-12-31 15:33:41 +0800274#if defined(CONFIG_DM_I2C)
275 struct udevice *dev;
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530276
Biwen Lia0affb32019-12-31 15:33:41 +0800277 ret = i2c_get_chip_for_busnum(bus_num, chip_addr,
278 1, &dev);
279 if (ret) {
280 printf("%s: Cannot find udev for a bus %d\n", __func__,
281 bus_num);
282 return -ENXIO;
283 }
284 /*
285 * --------------------------------------------------------------------
286 * |bus |I2C address| Device | Notes |
287 * --------------------------------------------------------------------
288 * |I2C1|0x24, 0x25,| IO expander (CFG,| Provides 16bits of General |
289 * | |0x26 | RESET, and INT/ | Purpose parallel Input/Output|
290 * | | | KW41GPIO) - NXP | (GPIO) expansion for the |
291 * | | | PCAL9555AHF | I2C bus |
292 * ----- --------------------------------------------------------------
293 * - mount three IO expander(PCAL9555AHF) on I2C1
294 *
295 * PCAL9555A device address
296 * slave address
297 * --------------------------------------
298 * | 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W |
299 * --------------------------------------
300 * | fixed | hardware selectable|
301 *
302 * Output port 1(Pinter register bits = 0x03)
303 *
304 * P1_[7~0] = 0xf4
305 * P1_0 <---> CFG_MUX_QSPI_S0
306 * P1_1 <---> CFG_MUX_QSPI_S1
307 * CFG_MUX_QSPI_S[1:0] = 0b00
308 *
309 * QSPI chip-select demultiplexer select
310 * ---------------------------------------------------------------------
311 * CFG_MUX_QSPI_S1|CFG_MUX_QSPI_S0| Values
312 * ---------------------------------------------------------------------
313 * 0 | 0 |CS routed to SPI memory bank1(default)
314 * ---------------------------------------------------------------------
315 * 0 | 1 |CS routed to SPI memory bank2
316 * ---------------------------------------------------------------------
317 *
318 */
319 ret = dm_i2c_write(dev, offset_addr, &data, 1);
320#else /* Non DM I2C support - will be removed */
321 i2c_set_bus_num(bus_num);
322 ret = i2c_write(chip_addr, offset_addr, 1, &data, 1);
323#endif
324
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530325 if (ret) {
326 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
Biwen Lia0affb32019-12-31 15:33:41 +0800327 chip_addr, offset_addr, data);
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530328 }
329
330 return ret;
331}
332
333static int switch_to_bank2(void)
334{
Biwen Lia0affb32019-12-31 15:33:41 +0800335 u8 data[2] = {0xfc, 0xf5}, offset_addr[2] = {0x7, 0x3};
336 u8 chip_addr = 0x24;
337 int ret, i, bus_num = 0;
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530338
Biwen Lia0affb32019-12-31 15:33:41 +0800339#if defined(CONFIG_DM_I2C)
340 struct udevice *dev;
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530341
Biwen Lia0affb32019-12-31 15:33:41 +0800342 ret = i2c_get_chip_for_busnum(bus_num, chip_addr,
343 1, &dev);
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530344 if (ret) {
Biwen Lia0affb32019-12-31 15:33:41 +0800345 printf("%s: Cannot find udev for a bus %d\n", __func__,
346 bus_num);
347 return -ENXIO;
348 }
349#else /* Non DM I2C support - will be removed */
350 i2c_set_bus_num(bus_num);
351#endif
352
353 /*
354 * 1th step: config port 1
355 * - the port 1 pin is enabled as an output
356 * 2th step: output port 1
357 * - P1_[7:0] output 0xf5,
358 * then CFG_MUX_QSPI_S[1:0] equal to 0b01,
359 * CS routed to SPI memory bank2
360 */
361 for (i = 0; i < sizeof(data); i++) {
362#if defined(CONFIG_DM_I2C)
363 ret = dm_i2c_write(dev, offset_addr[i], &data[i], 1);
364#else /* Non DM I2C support - will be removed */
365 ret = i2c_write(chip_addr, offset_addr[i], 1, &data[i], 1);
366#endif
367 if (ret) {
368 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
369 chip_addr, offset_addr[i], data[i]);
370 goto err;
371 }
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530372 }
373
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530374err:
375 return ret;
376}
377
378static int convert_flash_bank(int bank)
379{
380 int ret = 0;
381
382 switch (bank) {
383 case BOOT_FROM_UPPER_BANK:
384 ret = switch_to_bank2();
385 break;
386 case BOOT_FROM_LOWER_BANK:
387 ret = switch_to_bank1();
388 break;
389 default:
390 ret = CMD_RET_USAGE;
391 break;
392 };
393
394 return ret;
395}
396
397static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
398 char * const argv[])
399{
400 if (argc != 2)
401 return CMD_RET_USAGE;
402 if (strcmp(argv[1], "1") == 0)
403 convert_flash_bank(BOOT_FROM_LOWER_BANK);
404 else if (strcmp(argv[1], "2") == 0)
405 convert_flash_bank(BOOT_FROM_UPPER_BANK);
406 else
407 return CMD_RET_USAGE;
408
409 return 0;
410}
411
412U_BOOT_CMD(
413 boot_bank, 2, 0, flash_bank_cmd,
414 "Flash bank Selection Control",
415 "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
416);