blob: 0028870db07784a6e417cd4f39b305cbecf33dc2 [file] [log] [blame]
Peter Tyser5da6f802009-06-30 17:26:01 -05001/*
2 * Copyright 2009 Extreme Engineering Solutions, Inc.
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Peter Tyser5da6f802009-06-30 17:26:01 -05005 */
6
7#include <common.h>
8#include <asm/processor.h>
York Sun5614e712013-09-30 09:22:09 -07009#include <fsl_ddr_sdram.h>
Peter Tyser5da6f802009-06-30 17:26:01 -050010#include <asm/mmu.h>
11#include <asm/io.h>
12#include <fdt_support.h>
13#include <pca953x.h>
John Schmoller92af65492010-10-22 00:20:24 -050014#include "../common/fsl_8xxx_misc.h"
Peter Tyser5da6f802009-06-30 17:26:01 -050015
16#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_PCI)
17extern void ft_board_pci_setup(void *blob, bd_t *bd);
18#endif
19
Peter Tyser5da6f802009-06-30 17:26:01 -050020/*
21 * Print out which flash was booted from and if booting from the 2nd flash,
22 * swap flash chip selects to maintain consistent flash numbering/addresses.
23 */
24static void flash_cs_fixup(void)
25{
Peter Tyser5da6f802009-06-30 17:26:01 -050026 int flash_sel;
27
28 /*
29 * Print boot dev and swap flash flash chip selects if booted from 2nd
30 * flash. Swapping chip selects presents user with a common memory
31 * map regardless of which flash was booted from.
32 */
33 flash_sel = !((pca953x_get_val(CONFIG_SYS_I2C_PCA953X_ADDR0) &
34 CONFIG_SYS_PCA953X_C0_FLASH_PASS_CS));
Peter Tysereddf52b2010-12-28 18:12:05 -060035 printf("Flash: Executed from flash%d\n", flash_sel ? 2 : 1);
Peter Tyser5da6f802009-06-30 17:26:01 -050036
37 if (flash_sel) {
Becky Brucef51cdaf2010-06-17 11:37:20 -050038 set_lbc_br(0, CONFIG_SYS_BR1_PRELIM);
39 set_lbc_or(0, CONFIG_SYS_OR1_PRELIM);
Peter Tyser5da6f802009-06-30 17:26:01 -050040
Becky Brucef51cdaf2010-06-17 11:37:20 -050041 set_lbc_br(1, CONFIG_SYS_BR0_PRELIM);
42 set_lbc_or(1, CONFIG_SYS_OR0_PRELIM);
Peter Tyser5da6f802009-06-30 17:26:01 -050043 }
44}
45
46int board_early_init_r(void)
47{
48 /* Initialize PCA9557 devices */
49 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR0, 0xff, 0);
50 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR1, 0xff, 0);
51 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR2, 0xff, 0);
52 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR3, 0xff, 0);
53
54 flash_cs_fixup();
55
56 return 0;
57}
58
Becky Bruce38dba0c2010-12-17 17:17:56 -060059phys_size_t initdram(int board_type)
60{
61 phys_size_t dram_size = fsl_ddr_sdram();
62
63#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
64 /* Initialize and enable DDR ECC */
65 ddr_enable_ecc(dram_size);
66#endif
67
68 return dram_size;
69}
70
Peter Tyser5da6f802009-06-30 17:26:01 -050071#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -060072int ft_board_setup(void *blob, bd_t *bd)
Peter Tyser5da6f802009-06-30 17:26:01 -050073{
74#ifdef CONFIG_PCI
75 ft_board_pci_setup(blob, bd);
76#endif
77 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -060078
79 return 0;
Peter Tyser5da6f802009-06-30 17:26:01 -050080}
81#endif