Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2009 Extreme Engineering Solutions, Inc. |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <asm/processor.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 8 | #include <fsl_ddr_sdram.h> |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 9 | #include <asm/mmu.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <fdt_support.h> |
| 12 | #include <pca953x.h> |
John Schmoller | d9c2dd5 | 2010-10-22 00:20:24 -0500 | [diff] [blame] | 13 | #include "../common/fsl_8xxx_misc.h" |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 14 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 17 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_PCI) |
| 18 | extern void ft_board_pci_setup(void *blob, bd_t *bd); |
| 19 | #endif |
| 20 | |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 21 | /* |
| 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 | */ |
| 25 | static void flash_cs_fixup(void) |
| 26 | { |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 27 | 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 Tyser | 0b5a263 | 2010-12-28 18:12:05 -0600 | [diff] [blame] | 36 | printf("Flash: Executed from flash%d\n", flash_sel ? 2 : 1); |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 37 | |
| 38 | if (flash_sel) { |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 39 | set_lbc_br(0, CONFIG_SYS_BR1_PRELIM); |
| 40 | set_lbc_or(0, CONFIG_SYS_OR1_PRELIM); |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 41 | |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 42 | set_lbc_br(1, CONFIG_SYS_BR0_PRELIM); |
| 43 | set_lbc_or(1, CONFIG_SYS_OR0_PRELIM); |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | int 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 Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 60 | int dram_init(void) |
Becky Bruce | 5e35d8a | 2010-12-17 17:17:56 -0600 | [diff] [blame] | 61 | { |
| 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 Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 69 | gd->ram_size = dram_size; |
| 70 | |
| 71 | return 0; |
Becky Bruce | 5e35d8a | 2010-12-17 17:17:56 -0600 | [diff] [blame] | 72 | } |
| 73 | |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 74 | #if defined(CONFIG_OF_BOARD_SETUP) |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 75 | int ft_board_setup(void *blob, bd_t *bd) |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 76 | { |
| 77 | #ifdef CONFIG_PCI |
| 78 | ft_board_pci_setup(blob, bd); |
| 79 | #endif |
| 80 | ft_cpu_setup(blob, bd); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 81 | |
| 82 | return 0; |
Peter Tyser | edb9d59 | 2009-06-30 17:26:01 -0500 | [diff] [blame] | 83 | } |
| 84 | #endif |