1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2009 Extreme Engineering Solutions, Inc.
4  */
5 
6 #include <common.h>
7 #include <init.h>
8 #include <asm/global_data.h>
9 #include <asm/processor.h>
10 #include <fsl_ddr_sdram.h>
11 #include <asm/mmu.h>
12 #include <asm/io.h>
13 #include <fdt_support.h>
14 #include <pca953x.h>
15 #include "../common/fsl_8xxx_misc.h"
16 
17 DECLARE_GLOBAL_DATA_PTR;
18 
19 #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_PCI)
20 extern void ft_board_pci_setup(void *blob, struct bd_info *bd);
21 #endif
22 
23 /*
24  * Print out which flash was booted from and if booting from the 2nd flash,
25  * swap flash chip selects to maintain consistent flash numbering/addresses.
26  */
flash_cs_fixup(void)27 static void flash_cs_fixup(void)
28 {
29 	int flash_sel;
30 
31 	/*
32 	 * Print boot dev and swap flash flash chip selects if booted from 2nd
33 	 * flash.  Swapping chip selects presents user with a common memory
34 	 * map regardless of which flash was booted from.
35 	 */
36 	flash_sel = !((pca953x_get_val(CONFIG_SYS_I2C_PCA953X_ADDR0) &
37 			CONFIG_SYS_PCA953X_C0_FLASH_PASS_CS));
38 	printf("Flash: Executed from flash%d\n", flash_sel ? 2 : 1);
39 
40 	if (flash_sel) {
41 		set_lbc_br(0, CONFIG_SYS_BR1_PRELIM);
42 		set_lbc_or(0, CONFIG_SYS_OR1_PRELIM);
43 
44 		set_lbc_br(1, CONFIG_SYS_BR0_PRELIM);
45 		set_lbc_or(1, CONFIG_SYS_OR0_PRELIM);
46 	}
47 }
48 
board_early_init_r(void)49 int board_early_init_r(void)
50 {
51 	/* Initialize PCA9557 devices */
52 	pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR0, 0xff, 0);
53 	pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR1, 0xff, 0);
54 	pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR2, 0xff, 0);
55 	pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR3, 0xff, 0);
56 
57 	flash_cs_fixup();
58 
59 	return 0;
60 }
61 
dram_init(void)62 int dram_init(void)
63 {
64 	phys_size_t dram_size = fsl_ddr_sdram();
65 
66 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
67 	/* Initialize and enable DDR ECC */
68 	ddr_enable_ecc(dram_size);
69 #endif
70 
71 	gd->ram_size = dram_size;
72 
73 	return 0;
74 }
75 
76 #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,struct bd_info * bd)77 int ft_board_setup(void *blob, struct bd_info *bd)
78 {
79 #ifdef CONFIG_PCI
80 	ft_board_pci_setup(blob, bd);
81 #endif
82 	ft_cpu_setup(blob, bd);
83 
84 	return 0;
85 }
86 #endif
87