xref: /openbmc/u-boot/board/freescale/ls1012ardb/ls1012ardb.c (revision d94604d558cda9f89722c967d6f8d6269a2db21c)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
23b6e3898SPrabhakar Kushwaha /*
33b6e3898SPrabhakar Kushwaha  * Copyright 2016 Freescale Semiconductor, Inc.
43b6e3898SPrabhakar Kushwaha  */
53b6e3898SPrabhakar Kushwaha 
63b6e3898SPrabhakar Kushwaha #include <common.h>
73b6e3898SPrabhakar Kushwaha #include <i2c.h>
83b6e3898SPrabhakar Kushwaha #include <asm/io.h>
93b6e3898SPrabhakar Kushwaha #include <asm/arch/clock.h>
103b6e3898SPrabhakar Kushwaha #include <asm/arch/fsl_serdes.h>
115b404be6SPrabhakar Kushwaha #ifdef CONFIG_FSL_LS_PPA
125b404be6SPrabhakar Kushwaha #include <asm/arch/ppa.h>
135b404be6SPrabhakar Kushwaha #endif
144961eafcSYork Sun #include <asm/arch/mmu.h>
153b6e3898SPrabhakar Kushwaha #include <asm/arch/soc.h>
163b6e3898SPrabhakar Kushwaha #include <hwconfig.h>
173b6e3898SPrabhakar Kushwaha #include <ahci.h>
183b6e3898SPrabhakar Kushwaha #include <mmc.h>
193b6e3898SPrabhakar Kushwaha #include <scsi.h>
203b6e3898SPrabhakar Kushwaha #include <fsl_esdhc.h>
213b6e3898SPrabhakar Kushwaha #include <environment.h>
223b6e3898SPrabhakar Kushwaha #include <fsl_mmdc.h>
233b6e3898SPrabhakar Kushwaha #include <netdev.h>
2411d14bfbSVinitha Pillai-B57223 #include <fsl_sec.h>
253b6e3898SPrabhakar Kushwaha 
263b6e3898SPrabhakar Kushwaha DECLARE_GLOBAL_DATA_PTR;
273b6e3898SPrabhakar Kushwaha 
283fa48f0aSJagdish Gediya #define BOOT_FROM_UPPER_BANK	0x2
293fa48f0aSJagdish Gediya #define BOOT_FROM_LOWER_BANK	0x1
303fa48f0aSJagdish Gediya 
checkboard(void)313b6e3898SPrabhakar Kushwaha int checkboard(void)
323b6e3898SPrabhakar Kushwaha {
33b0ce187bSBhaskar Upadhaya #ifdef CONFIG_TARGET_LS1012ARDB
343b6e3898SPrabhakar Kushwaha 	u8 in1;
353b6e3898SPrabhakar Kushwaha 
363b6e3898SPrabhakar Kushwaha 	puts("Board: LS1012ARDB ");
373b6e3898SPrabhakar Kushwaha 
383b6e3898SPrabhakar Kushwaha 	/* Initialize i2c early for Serial flash bank information */
393b6e3898SPrabhakar Kushwaha 	i2c_set_bus_num(0);
403b6e3898SPrabhakar Kushwaha 
41481fb01fSYangbo Lu 	if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1) < 0) {
423b6e3898SPrabhakar Kushwaha 		printf("Error reading i2c boot information!\n");
433b6e3898SPrabhakar Kushwaha 		return 0; /* Don't want to hang() on this error */
443b6e3898SPrabhakar Kushwaha 	}
453b6e3898SPrabhakar Kushwaha 
463b6e3898SPrabhakar Kushwaha 	puts("Version");
474a47bf8aSYangbo Lu 	switch (in1 & SW_REV_MASK) {
484a47bf8aSYangbo Lu 	case SW_REV_A:
493b6e3898SPrabhakar Kushwaha 		puts(": RevA");
504a47bf8aSYangbo Lu 		break;
514a47bf8aSYangbo Lu 	case SW_REV_B:
523b6e3898SPrabhakar Kushwaha 		puts(": RevB");
534a47bf8aSYangbo Lu 		break;
544a47bf8aSYangbo Lu 	case SW_REV_C:
554a47bf8aSYangbo Lu 		puts(": RevC");
564a47bf8aSYangbo Lu 		break;
574a47bf8aSYangbo Lu 	case SW_REV_C1:
584a47bf8aSYangbo Lu 		puts(": RevC1");
594a47bf8aSYangbo Lu 		break;
604a47bf8aSYangbo Lu 	case SW_REV_C2:
614a47bf8aSYangbo Lu 		puts(": RevC2");
624a47bf8aSYangbo Lu 		break;
634a47bf8aSYangbo Lu 	case SW_REV_D:
644a47bf8aSYangbo Lu 		puts(": RevD");
654a47bf8aSYangbo Lu 		break;
664a47bf8aSYangbo Lu 	case SW_REV_E:
674a47bf8aSYangbo Lu 		puts(": RevE");
684a47bf8aSYangbo Lu 		break;
694a47bf8aSYangbo Lu 	default:
703b6e3898SPrabhakar Kushwaha 		puts(": unknown");
714a47bf8aSYangbo Lu 		break;
724a47bf8aSYangbo Lu 	}
733b6e3898SPrabhakar Kushwaha 
743b6e3898SPrabhakar Kushwaha 	printf(", boot from QSPI");
75481fb01fSYangbo Lu 	if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU)
763b6e3898SPrabhakar Kushwaha 		puts(": emu\n");
77481fb01fSYangbo Lu 	else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1)
783b6e3898SPrabhakar Kushwaha 		puts(": bank1\n");
79481fb01fSYangbo Lu 	else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2)
803b6e3898SPrabhakar Kushwaha 		puts(": bank2\n");
813b6e3898SPrabhakar Kushwaha 	else
823b6e3898SPrabhakar Kushwaha 		puts("unknown\n");
83b0ce187bSBhaskar Upadhaya #else
843b6e3898SPrabhakar Kushwaha 
85b0ce187bSBhaskar Upadhaya 	puts("Board: LS1012A2G5RDB ");
86b0ce187bSBhaskar Upadhaya #endif
873b6e3898SPrabhakar Kushwaha 	return 0;
883b6e3898SPrabhakar Kushwaha }
893b6e3898SPrabhakar Kushwaha 
90*1f6180dfSRajesh Bhagat #ifdef CONFIG_TFABOOT
dram_init(void)913b6e3898SPrabhakar Kushwaha int dram_init(void)
923b6e3898SPrabhakar Kushwaha {
93*1f6180dfSRajesh Bhagat 	gd->ram_size = tfa_get_dram_size();
94*1f6180dfSRajesh Bhagat 	if (!gd->ram_size)
95*1f6180dfSRajesh Bhagat 		gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
96*1f6180dfSRajesh Bhagat 
97*1f6180dfSRajesh Bhagat 	return 0;
98*1f6180dfSRajesh Bhagat }
99*1f6180dfSRajesh Bhagat #else
dram_init(void)100*1f6180dfSRajesh Bhagat int dram_init(void)
101*1f6180dfSRajesh Bhagat {
102*1f6180dfSRajesh Bhagat #ifndef CONFIG_TFABOOT
1031fdcc8dfSYork Sun 	static const struct fsl_mmdc_info mparam = {
1041fdcc8dfSYork Sun 		0x05180000,	/* mdctl */
1051fdcc8dfSYork Sun 		0x00030035,	/* mdpdc */
1061fdcc8dfSYork Sun 		0x12554000,	/* mdotc */
1071fdcc8dfSYork Sun 		0xbabf7954,	/* mdcfg0 */
1081fdcc8dfSYork Sun 		0xdb328f64,	/* mdcfg1 */
1091fdcc8dfSYork Sun 		0x01ff00db,	/* mdcfg2 */
1101fdcc8dfSYork Sun 		0x00001680,	/* mdmisc */
1111fdcc8dfSYork Sun 		0x0f3c8000,	/* mdref */
1121fdcc8dfSYork Sun 		0x00002000,	/* mdrwd */
1131fdcc8dfSYork Sun 		0x00bf1023,	/* mdor */
1141fdcc8dfSYork Sun 		0x0000003f,	/* mdasp */
1151fdcc8dfSYork Sun 		0x0000022a,	/* mpodtctrl */
1161fdcc8dfSYork Sun 		0xa1390003,	/* mpzqhwctrl */
1171fdcc8dfSYork Sun 	};
1181fdcc8dfSYork Sun 
1191fdcc8dfSYork Sun 	mmdc_init(&mparam);
120*1f6180dfSRajesh Bhagat #endif
1213b6e3898SPrabhakar Kushwaha 
1223b6e3898SPrabhakar Kushwaha 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
1234961eafcSYork Sun #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
1244961eafcSYork Sun 	/* This will break-before-make MMU for DDR */
1254961eafcSYork Sun 	update_early_mmu_table();
1264961eafcSYork Sun #endif
1273b6e3898SPrabhakar Kushwaha 
1283b6e3898SPrabhakar Kushwaha 	return 0;
1293b6e3898SPrabhakar Kushwaha }
130*1f6180dfSRajesh Bhagat #endif
1313b6e3898SPrabhakar Kushwaha 
1323b6e3898SPrabhakar Kushwaha 
board_early_init_f(void)1333b6e3898SPrabhakar Kushwaha int board_early_init_f(void)
1343b6e3898SPrabhakar Kushwaha {
1353b6e3898SPrabhakar Kushwaha 	fsl_lsch2_early_init_f();
1363b6e3898SPrabhakar Kushwaha 
1373b6e3898SPrabhakar Kushwaha 	return 0;
1383b6e3898SPrabhakar Kushwaha }
1393b6e3898SPrabhakar Kushwaha 
board_init(void)1403b6e3898SPrabhakar Kushwaha int board_init(void)
1413b6e3898SPrabhakar Kushwaha {
14263b2316cSAshish Kumar 	struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
14363b2316cSAshish Kumar 					CONFIG_SYS_CCI400_OFFSET);
1443b6e3898SPrabhakar Kushwaha 	/*
1453b6e3898SPrabhakar Kushwaha 	 * Set CCI-400 control override register to enable barrier
1463b6e3898SPrabhakar Kushwaha 	 * transaction
1473b6e3898SPrabhakar Kushwaha 	 */
148*1f6180dfSRajesh Bhagat 	if (current_el() == 3)
1493b6e3898SPrabhakar Kushwaha 		out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
1503b6e3898SPrabhakar Kushwaha 
151b392a6d4SHou Zhiqiang #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
152b392a6d4SHou Zhiqiang 	erratum_a010315();
153b392a6d4SHou Zhiqiang #endif
154b392a6d4SHou Zhiqiang 
1553b6e3898SPrabhakar Kushwaha #ifdef CONFIG_ENV_IS_NOWHERE
1563b6e3898SPrabhakar Kushwaha 	gd->env_addr = (ulong)&default_environment[0];
1573b6e3898SPrabhakar Kushwaha #endif
1583b6e3898SPrabhakar Kushwaha 
15911d14bfbSVinitha Pillai-B57223 #ifdef CONFIG_FSL_CAAM
16011d14bfbSVinitha Pillai-B57223 	sec_init();
16111d14bfbSVinitha Pillai-B57223 #endif
16211d14bfbSVinitha Pillai-B57223 
1635b404be6SPrabhakar Kushwaha #ifdef CONFIG_FSL_LS_PPA
1645b404be6SPrabhakar Kushwaha 	ppa_init();
1655b404be6SPrabhakar Kushwaha #endif
1663b6e3898SPrabhakar Kushwaha 	return 0;
1673b6e3898SPrabhakar Kushwaha }
1683b6e3898SPrabhakar Kushwaha 
169b0ce187bSBhaskar Upadhaya #ifdef CONFIG_TARGET_LS1012ARDB
esdhc_status_fixup(void * blob,const char * compat)1705e4a6db8SYangbo Lu int esdhc_status_fixup(void *blob, const char *compat)
1715e4a6db8SYangbo Lu {
1725e4a6db8SYangbo Lu 	char esdhc1_path[] = "/soc/esdhc@1580000";
1736aaa539fSYangbo Lu 	bool sdhc2_en = false;
1745e4a6db8SYangbo Lu 	u8 mux_sdhc2;
1756aaa539fSYangbo Lu 	u8 io = 0;
1765e4a6db8SYangbo Lu 
1775e4a6db8SYangbo Lu 	i2c_set_bus_num(0);
1785e4a6db8SYangbo Lu 
1796aaa539fSYangbo Lu 	/* IO1[7:3] is the field of board revision info. */
1806aaa539fSYangbo Lu 	if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1) < 0) {
1816aaa539fSYangbo Lu 		printf("Error reading i2c boot information!\n");
1826aaa539fSYangbo Lu 		return 0;
1836aaa539fSYangbo Lu 	}
1846aaa539fSYangbo Lu 
1856aaa539fSYangbo Lu 	/* hwconfig method is used for RevD and later versions. */
1866aaa539fSYangbo Lu 	if ((io & SW_REV_MASK) <= SW_REV_D) {
1876aaa539fSYangbo Lu #ifdef CONFIG_HWCONFIG
1886aaa539fSYangbo Lu 		if (hwconfig("esdhc1"))
1896aaa539fSYangbo Lu 			sdhc2_en = true;
1906aaa539fSYangbo Lu #endif
1916aaa539fSYangbo Lu 	} else {
1925e4a6db8SYangbo Lu 		/*
1936aaa539fSYangbo Lu 		 * The I2C IO-expander for mux select is used to control
1946aaa539fSYangbo Lu 		 * the muxing of various onboard interfaces.
1955e4a6db8SYangbo Lu 		 *
1966aaa539fSYangbo Lu 		 * IO0[3:2] indicates SDHC2 interface demultiplexer
1976aaa539fSYangbo Lu 		 * select lines.
1985e4a6db8SYangbo Lu 		 *	00 - SDIO wifi
1995e4a6db8SYangbo Lu 		 *	01 - GPIO (to Arduino)
2005e4a6db8SYangbo Lu 		 *	10 - eMMC Memory
2015e4a6db8SYangbo Lu 		 *	11 - SPI
2025e4a6db8SYangbo Lu 		 */
203481fb01fSYangbo Lu 		if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1) < 0) {
2045e4a6db8SYangbo Lu 			printf("Error reading i2c boot information!\n");
2056aaa539fSYangbo Lu 			return 0;
2065e4a6db8SYangbo Lu 		}
2075e4a6db8SYangbo Lu 
2085e4a6db8SYangbo Lu 		mux_sdhc2 = (io & 0x0c) >> 2;
2095e4a6db8SYangbo Lu 		/* Enable SDHC2 only when use SDIO wifi and eMMC */
2105e4a6db8SYangbo Lu 		if (mux_sdhc2 == 2 || mux_sdhc2 == 0)
2116aaa539fSYangbo Lu 			sdhc2_en = true;
2126aaa539fSYangbo Lu 	}
2136aaa539fSYangbo Lu 	if (sdhc2_en)
2145e4a6db8SYangbo Lu 		do_fixup_by_path(blob, esdhc1_path, "status", "okay",
2155e4a6db8SYangbo Lu 				 sizeof("okay"), 1);
2165e4a6db8SYangbo Lu 	else
2175e4a6db8SYangbo Lu 		do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
2185e4a6db8SYangbo Lu 				 sizeof("disabled"), 1);
2195e4a6db8SYangbo Lu 	return 0;
2205e4a6db8SYangbo Lu }
221b0ce187bSBhaskar Upadhaya #endif
2225e4a6db8SYangbo Lu 
ft_board_setup(void * blob,bd_t * bd)2233b6e3898SPrabhakar Kushwaha int ft_board_setup(void *blob, bd_t *bd)
2243b6e3898SPrabhakar Kushwaha {
2253b6e3898SPrabhakar Kushwaha 	arch_fixup_fdt(blob);
2263b6e3898SPrabhakar Kushwaha 
2273b6e3898SPrabhakar Kushwaha 	ft_cpu_setup(blob, bd);
2283b6e3898SPrabhakar Kushwaha 
2293b6e3898SPrabhakar Kushwaha 	return 0;
2303b6e3898SPrabhakar Kushwaha }
2313fa48f0aSJagdish Gediya 
switch_to_bank1(void)2323fa48f0aSJagdish Gediya static int switch_to_bank1(void)
2333fa48f0aSJagdish Gediya {
2343fa48f0aSJagdish Gediya 	u8 data;
2353fa48f0aSJagdish Gediya 	int ret;
2363fa48f0aSJagdish Gediya 
2373fa48f0aSJagdish Gediya 	i2c_set_bus_num(0);
2383fa48f0aSJagdish Gediya 
2393fa48f0aSJagdish Gediya 	data = 0xf4;
2403fa48f0aSJagdish Gediya 	ret = i2c_write(0x24, 0x3, 1, &data, 1);
2413fa48f0aSJagdish Gediya 	if (ret) {
2423fa48f0aSJagdish Gediya 		printf("i2c write error to chip : %u, addr : %u, data : %u\n",
2433fa48f0aSJagdish Gediya 		       0x24, 0x3, data);
2443fa48f0aSJagdish Gediya 	}
2453fa48f0aSJagdish Gediya 
2463fa48f0aSJagdish Gediya 	return ret;
2473fa48f0aSJagdish Gediya }
2483fa48f0aSJagdish Gediya 
switch_to_bank2(void)2493fa48f0aSJagdish Gediya static int switch_to_bank2(void)
2503fa48f0aSJagdish Gediya {
2513fa48f0aSJagdish Gediya 	u8 data;
2523fa48f0aSJagdish Gediya 	int ret;
2533fa48f0aSJagdish Gediya 
2543fa48f0aSJagdish Gediya 	i2c_set_bus_num(0);
2553fa48f0aSJagdish Gediya 
2563fa48f0aSJagdish Gediya 	data = 0xfc;
2573fa48f0aSJagdish Gediya 	ret = i2c_write(0x24, 0x7, 1, &data, 1);
2583fa48f0aSJagdish Gediya 	if (ret) {
2593fa48f0aSJagdish Gediya 		printf("i2c write error to chip : %u, addr : %u, data : %u\n",
2603fa48f0aSJagdish Gediya 		       0x24, 0x7, data);
2613fa48f0aSJagdish Gediya 		goto err;
2623fa48f0aSJagdish Gediya 	}
2633fa48f0aSJagdish Gediya 
2643fa48f0aSJagdish Gediya 	data = 0xf5;
2653fa48f0aSJagdish Gediya 	ret = i2c_write(0x24, 0x3, 1, &data, 1);
2663fa48f0aSJagdish Gediya 	if (ret) {
2673fa48f0aSJagdish Gediya 		printf("i2c write error to chip : %u, addr : %u, data : %u\n",
2683fa48f0aSJagdish Gediya 		       0x24, 0x3, data);
2693fa48f0aSJagdish Gediya 	}
2703fa48f0aSJagdish Gediya err:
2713fa48f0aSJagdish Gediya 	return ret;
2723fa48f0aSJagdish Gediya }
2733fa48f0aSJagdish Gediya 
convert_flash_bank(int bank)2743fa48f0aSJagdish Gediya static int convert_flash_bank(int bank)
2753fa48f0aSJagdish Gediya {
2763fa48f0aSJagdish Gediya 	int ret = 0;
2773fa48f0aSJagdish Gediya 
2783fa48f0aSJagdish Gediya 	switch (bank) {
2793fa48f0aSJagdish Gediya 	case BOOT_FROM_UPPER_BANK:
2803fa48f0aSJagdish Gediya 		ret = switch_to_bank2();
2813fa48f0aSJagdish Gediya 		break;
2823fa48f0aSJagdish Gediya 	case BOOT_FROM_LOWER_BANK:
2833fa48f0aSJagdish Gediya 		ret = switch_to_bank1();
2843fa48f0aSJagdish Gediya 		break;
2853fa48f0aSJagdish Gediya 	default:
2863fa48f0aSJagdish Gediya 		ret = CMD_RET_USAGE;
2873fa48f0aSJagdish Gediya 		break;
2883fa48f0aSJagdish Gediya 	};
2893fa48f0aSJagdish Gediya 
2903fa48f0aSJagdish Gediya 	return ret;
2913fa48f0aSJagdish Gediya }
2923fa48f0aSJagdish Gediya 
flash_bank_cmd(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])2933fa48f0aSJagdish Gediya static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
2943fa48f0aSJagdish Gediya 			  char * const argv[])
2953fa48f0aSJagdish Gediya {
2963fa48f0aSJagdish Gediya 	if (argc != 2)
2973fa48f0aSJagdish Gediya 		return CMD_RET_USAGE;
2983fa48f0aSJagdish Gediya 	if (strcmp(argv[1], "1") == 0)
2993fa48f0aSJagdish Gediya 		convert_flash_bank(BOOT_FROM_LOWER_BANK);
3003fa48f0aSJagdish Gediya 	else if (strcmp(argv[1], "2") == 0)
3013fa48f0aSJagdish Gediya 		convert_flash_bank(BOOT_FROM_UPPER_BANK);
3023fa48f0aSJagdish Gediya 	else
3033fa48f0aSJagdish Gediya 		return CMD_RET_USAGE;
3043fa48f0aSJagdish Gediya 
3053fa48f0aSJagdish Gediya 	return 0;
3063fa48f0aSJagdish Gediya }
3073fa48f0aSJagdish Gediya 
3083fa48f0aSJagdish Gediya U_BOOT_CMD(
3093fa48f0aSJagdish Gediya 	boot_bank, 2, 0, flash_bank_cmd,
3103fa48f0aSJagdish Gediya 	"Flash bank Selection Control",
3113fa48f0aSJagdish Gediya 	"bank[1-lower bank/2-upper bank] (e.g. boot_bank 1)"
3123fa48f0aSJagdish Gediya );
313