blob: 8a5b52c4952757521183001890d0bd8d7316914c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Tyseredb9d592009-06-30 17:26:01 -05002/*
3 * Copyright 2009 Extreme Engineering Solutions, Inc.
Peter Tyseredb9d592009-06-30 17:26:01 -05004 */
5
6#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Peter Tyseredb9d592009-06-30 17:26:01 -05009#include <asm/processor.h>
York Sunf0626592013-09-30 09:22:09 -070010#include <fsl_ddr_sdram.h>
Peter Tyseredb9d592009-06-30 17:26:01 -050011#include <asm/mmu.h>
12#include <asm/io.h>
13#include <fdt_support.h>
14#include <pca953x.h>
John Schmollerd9c2dd52010-10-22 00:20:24 -050015#include "../common/fsl_8xxx_misc.h"
Peter Tyseredb9d592009-06-30 17:26:01 -050016
Simon Glass39f90ba2017-03-31 08:40:25 -060017DECLARE_GLOBAL_DATA_PTR;
18
Peter Tyseredb9d592009-06-30 17:26:01 -050019#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_PCI)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090020extern void ft_board_pci_setup(void *blob, struct bd_info *bd);
Peter Tyseredb9d592009-06-30 17:26:01 -050021#endif
22
Peter Tyseredb9d592009-06-30 17:26:01 -050023/*
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 */
27static void flash_cs_fixup(void)
28{
Peter Tyseredb9d592009-06-30 17:26:01 -050029 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));
Peter Tyser0b5a2632010-12-28 18:12:05 -060038 printf("Flash: Executed from flash%d\n", flash_sel ? 2 : 1);
Peter Tyseredb9d592009-06-30 17:26:01 -050039
40 if (flash_sel) {
Becky Bruce0d4cee12010-06-17 11:37:20 -050041 set_lbc_br(0, CONFIG_SYS_BR1_PRELIM);
42 set_lbc_or(0, CONFIG_SYS_OR1_PRELIM);
Peter Tyseredb9d592009-06-30 17:26:01 -050043
Becky Bruce0d4cee12010-06-17 11:37:20 -050044 set_lbc_br(1, CONFIG_SYS_BR0_PRELIM);
45 set_lbc_or(1, CONFIG_SYS_OR0_PRELIM);
Peter Tyseredb9d592009-06-30 17:26:01 -050046 }
47}
48
49int 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
Simon Glassd35f3382017-04-06 12:47:05 -060062int dram_init(void)
Becky Bruce5e35d8a2010-12-17 17:17:56 -060063{
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
Simon Glass39f90ba2017-03-31 08:40:25 -060071 gd->ram_size = dram_size;
72
73 return 0;
Becky Bruce5e35d8a2010-12-17 17:17:56 -060074}
75
Peter Tyseredb9d592009-06-30 17:26:01 -050076#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090077int ft_board_setup(void *blob, struct bd_info *bd)
Peter Tyseredb9d592009-06-30 17:26:01 -050078{
79#ifdef CONFIG_PCI
80 ft_board_pci_setup(blob, bd);
81#endif
82 ft_cpu_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -060083
84 return 0;
Peter Tyseredb9d592009-06-30 17:26:01 -050085}
86#endif