blob: 0d8fba851d1920562574df72956cb40687c1ad46 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Tyser5da6f802009-06-30 17:26:01 -05002/*
3 * Copyright 2009 Extreme Engineering Solutions, Inc.
Peter Tyser5da6f802009-06-30 17:26:01 -05004 */
5
6#include <common.h>
7#include <asm/processor.h>
York Sun5614e712013-09-30 09:22:09 -07008#include <fsl_ddr_sdram.h>
Peter Tyser5da6f802009-06-30 17:26:01 -05009#include <asm/mmu.h>
10#include <asm/io.h>
11#include <fdt_support.h>
12#include <pca953x.h>
John Schmoller92af65492010-10-22 00:20:24 -050013#include "../common/fsl_8xxx_misc.h"
Peter Tyser5da6f802009-06-30 17:26:01 -050014
Simon Glass088454c2017-03-31 08:40:25 -060015DECLARE_GLOBAL_DATA_PTR;
16
Peter Tyser5da6f802009-06-30 17:26:01 -050017#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_PCI)
18extern void ft_board_pci_setup(void *blob, bd_t *bd);
19#endif
20
Peter Tyser5da6f802009-06-30 17:26:01 -050021/*
22 * Print out which flash was booted from and if booting from the 2nd flash,
23 * swap flash chip selects to maintain consistent flash numbering/addresses.
24 */
25static void flash_cs_fixup(void)
26{
Peter Tyser5da6f802009-06-30 17:26:01 -050027 int flash_sel;
28
29 /*
30 * Print boot dev and swap flash flash chip selects if booted from 2nd
31 * flash. Swapping chip selects presents user with a common memory
32 * map regardless of which flash was booted from.
33 */
34 flash_sel = !((pca953x_get_val(CONFIG_SYS_I2C_PCA953X_ADDR0) &
35 CONFIG_SYS_PCA953X_C0_FLASH_PASS_CS));
Peter Tysereddf52b2010-12-28 18:12:05 -060036 printf("Flash: Executed from flash%d\n", flash_sel ? 2 : 1);
Peter Tyser5da6f802009-06-30 17:26:01 -050037
38 if (flash_sel) {
Becky Brucef51cdaf2010-06-17 11:37:20 -050039 set_lbc_br(0, CONFIG_SYS_BR1_PRELIM);
40 set_lbc_or(0, CONFIG_SYS_OR1_PRELIM);
Peter Tyser5da6f802009-06-30 17:26:01 -050041
Becky Brucef51cdaf2010-06-17 11:37:20 -050042 set_lbc_br(1, CONFIG_SYS_BR0_PRELIM);
43 set_lbc_or(1, CONFIG_SYS_OR0_PRELIM);
Peter Tyser5da6f802009-06-30 17:26:01 -050044 }
45}
46
47int board_early_init_r(void)
48{
49 /* Initialize PCA9557 devices */
50 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR0, 0xff, 0);
51 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR1, 0xff, 0);
52 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR2, 0xff, 0);
53 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR3, 0xff, 0);
54
55 flash_cs_fixup();
56
57 return 0;
58}
59
Simon Glassf1683aa2017-04-06 12:47:05 -060060int dram_init(void)
Becky Bruce38dba0c2010-12-17 17:17:56 -060061{
62 phys_size_t dram_size = fsl_ddr_sdram();
63
64#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
65 /* Initialize and enable DDR ECC */
66 ddr_enable_ecc(dram_size);
67#endif
68
Simon Glass088454c2017-03-31 08:40:25 -060069 gd->ram_size = dram_size;
70
71 return 0;
Becky Bruce38dba0c2010-12-17 17:17:56 -060072}
73
Peter Tyser5da6f802009-06-30 17:26:01 -050074#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -060075int ft_board_setup(void *blob, bd_t *bd)
Peter Tyser5da6f802009-06-30 17:26:01 -050076{
77#ifdef CONFIG_PCI
78 ft_board_pci_setup(blob, bd);
79#endif
80 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -060081
82 return 0;
Peter Tyser5da6f802009-06-30 17:26:01 -050083}
84#endif