blob: 888f8500d4b09f82d134e5ae6037bd7f9c37097c [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>
7#include <i2c.h>
8#include <asm/io.h>
9#include <asm/arch/clock.h>
10#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +053011#ifdef CONFIG_FSL_LS_PPA
12#include <asm/arch/ppa.h>
13#endif
York Sun4961eaf2017-03-06 09:02:34 -080014#include <asm/arch/mmu.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053015#include <asm/arch/soc.h>
16#include <hwconfig.h>
17#include <ahci.h>
18#include <mmc.h>
19#include <scsi.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053020#include <fsl_esdhc.h>
21#include <environment.h>
22#include <fsl_mmdc.h>
23#include <netdev.h>
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +053024#include <fsl_sec.h>
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053025
26DECLARE_GLOBAL_DATA_PTR;
27
Jagdish Gediya3fa48f02018-04-13 00:18:22 +053028#define BOOT_FROM_UPPER_BANK 0x2
29#define BOOT_FROM_LOWER_BANK 0x1
30
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053031int checkboard(void)
32{
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053033#ifdef CONFIG_TARGET_LS1012ARDB
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053034 u8 in1;
35
36 puts("Board: LS1012ARDB ");
37
38 /* Initialize i2c early for Serial flash bank information */
39 i2c_set_bus_num(0);
40
Yangbo Lu481fb012017-12-08 15:35:35 +080041 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1) < 0) {
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053042 printf("Error reading i2c boot information!\n");
43 return 0; /* Don't want to hang() on this error */
44 }
45
46 puts("Version");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080047 switch (in1 & SW_REV_MASK) {
48 case SW_REV_A:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053049 puts(": RevA");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080050 break;
51 case SW_REV_B:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053052 puts(": RevB");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080053 break;
54 case SW_REV_C:
55 puts(": RevC");
56 break;
57 case SW_REV_C1:
58 puts(": RevC1");
59 break;
60 case SW_REV_C2:
61 puts(": RevC2");
62 break;
63 case SW_REV_D:
64 puts(": RevD");
65 break;
66 case SW_REV_E:
67 puts(": RevE");
68 break;
69 default:
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053070 puts(": unknown");
Yangbo Lu4a47bf82017-12-08 15:35:36 +080071 break;
72 }
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053073
74 printf(", boot from QSPI");
Yangbo Lu481fb012017-12-08 15:35:35 +080075 if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053076 puts(": emu\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080077 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053078 puts(": bank1\n");
Yangbo Lu481fb012017-12-08 15:35:35 +080079 else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053080 puts(": bank2\n");
81 else
82 puts("unknown\n");
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053083#else
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053084
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +053085 puts("Board: LS1012A2G5RDB ");
86#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053087 return 0;
88}
89
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +053090int dram_init(void)
91{
York Sun1fdcc8d2016-09-26 08:09:25 -070092 static const struct fsl_mmdc_info mparam = {
93 0x05180000, /* mdctl */
94 0x00030035, /* mdpdc */
95 0x12554000, /* mdotc */
96 0xbabf7954, /* mdcfg0 */
97 0xdb328f64, /* mdcfg1 */
98 0x01ff00db, /* mdcfg2 */
99 0x00001680, /* mdmisc */
100 0x0f3c8000, /* mdref */
101 0x00002000, /* mdrwd */
102 0x00bf1023, /* mdor */
103 0x0000003f, /* mdasp */
104 0x0000022a, /* mpodtctrl */
105 0xa1390003, /* mpzqhwctrl */
106 };
107
108 mmdc_init(&mparam);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530109
110 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
York Sun4961eaf2017-03-06 09:02:34 -0800111#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
112 /* This will break-before-make MMU for DDR */
113 update_early_mmu_table();
114#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530115
116 return 0;
117}
118
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530119
120int board_early_init_f(void)
121{
122 fsl_lsch2_early_init_f();
123
124 return 0;
125}
126
127int board_init(void)
128{
Ashish Kumar63b23162017-08-11 11:09:14 +0530129 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
130 CONFIG_SYS_CCI400_OFFSET);
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530131 /*
132 * Set CCI-400 control override register to enable barrier
133 * transaction
134 */
135 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
136
Hou Zhiqiangb392a6d2016-08-02 19:03:27 +0800137#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
138 erratum_a010315();
139#endif
140
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530141#ifdef CONFIG_ENV_IS_NOWHERE
142 gd->env_addr = (ulong)&default_environment[0];
143#endif
144
Vinitha Pillai-B5722311d14bf2017-03-23 13:48:20 +0530145#ifdef CONFIG_FSL_CAAM
146 sec_init();
147#endif
148
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +0530149#ifdef CONFIG_FSL_LS_PPA
150 ppa_init();
151#endif
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530152 return 0;
153}
154
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530155#ifdef CONFIG_TARGET_LS1012ARDB
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800156int esdhc_status_fixup(void *blob, const char *compat)
157{
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800158 char esdhc1_path[] = "/soc/esdhc@1580000";
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800159 bool sdhc2_en = false;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800160 u8 mux_sdhc2;
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800161 u8 io = 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800162
163 i2c_set_bus_num(0);
164
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800165 /* IO1[7:3] is the field of board revision info. */
166 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1) < 0) {
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800167 printf("Error reading i2c boot information!\n");
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800168 return 0;
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800169 }
170
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800171 /* hwconfig method is used for RevD and later versions. */
172 if ((io & SW_REV_MASK) <= SW_REV_D) {
173#ifdef CONFIG_HWCONFIG
174 if (hwconfig("esdhc1"))
175 sdhc2_en = true;
176#endif
177 } else {
178 /*
179 * The I2C IO-expander for mux select is used to control
180 * the muxing of various onboard interfaces.
181 *
182 * IO0[3:2] indicates SDHC2 interface demultiplexer
183 * select lines.
184 * 00 - SDIO wifi
185 * 01 - GPIO (to Arduino)
186 * 10 - eMMC Memory
187 * 11 - SPI
188 */
189 if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1) < 0) {
190 printf("Error reading i2c boot information!\n");
191 return 0;
192 }
193
194 mux_sdhc2 = (io & 0x0c) >> 2;
195 /* Enable SDHC2 only when use SDIO wifi and eMMC */
196 if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
197 sdhc2_en = true;
198 }
Yangbo Lu6aaa5392017-12-08 15:35:37 +0800199 if (sdhc2_en)
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800200 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
201 sizeof("okay"), 1);
202 else
203 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
204 sizeof("disabled"), 1);
205 return 0;
206}
Bhaskar Upadhayab0ce1872018-01-11 20:03:31 +0530207#endif
Yangbo Lu5e4a6db2017-01-17 10:43:56 +0800208
Prabhakar Kushwaha3b6e3892016-06-03 18:41:35 +0530209int ft_board_setup(void *blob, bd_t *bd)
210{
211 arch_fixup_fdt(blob);
212
213 ft_cpu_setup(blob, bd);
214
215 return 0;
216}
Jagdish Gediya3fa48f02018-04-13 00:18:22 +0530217
218static int switch_to_bank1(void)
219{
220 u8 data;
221 int ret;
222
223 i2c_set_bus_num(0);
224
225 data = 0xf4;
226 ret = i2c_write(0x24, 0x3, 1, &data, 1);
227 if (ret) {
228 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
229 0x24, 0x3, data);
230 }
231
232 return ret;
233}
234
235static int switch_to_bank2(void)
236{
237 u8 data;
238 int ret;
239
240 i2c_set_bus_num(0);
241
242 data = 0xfc;
243 ret = i2c_write(0x24, 0x7, 1, &data, 1);
244 if (ret) {
245 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
246 0x24, 0x7, data);
247 goto err;
248 }
249
250 data = 0xf5;
251 ret = i2c_write(0x24, 0x3, 1, &data, 1);
252 if (ret) {
253 printf("i2c write error to chip : %u, addr : %u, data : %u\n",
254 0x24, 0x3, data);
255 }
256err:
257 return ret;
258}
259
260static int convert_flash_bank(int bank)
261{
262 int ret = 0;
263
264 switch (bank) {
265 case BOOT_FROM_UPPER_BANK:
266 ret = switch_to_bank2();
267 break;
268 case BOOT_FROM_LOWER_BANK:
269 ret = switch_to_bank1();
270 break;
271 default:
272 ret = CMD_RET_USAGE;
273 break;
274 };
275
276 return ret;
277}
278
279static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
280 char * const argv[])
281{
282 if (argc != 2)
283 return CMD_RET_USAGE;
284 if (strcmp(argv[1], "1") == 0)
285 convert_flash_bank(BOOT_FROM_LOWER_BANK);
286 else if (strcmp(argv[1], "2") == 0)
287 convert_flash_bank(BOOT_FROM_UPPER_BANK);
288 else
289 return CMD_RET_USAGE;
290
291 return 0;
292}
293
294U_BOOT_CMD(
295 boot_bank, 2, 0, flash_bank_cmd,
296 "Flash bank Selection Control",
297 "bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
298);