Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Extreme Engineering Solutions, Inc. |
| 3 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
| 9 | #include <asm/processor.h> |
| 10 | #include <asm/mmu.h> |
| 11 | #include <asm/immap_85xx.h> |
Kumar Gala | 9bbd643 | 2009-04-02 13:22:48 -0500 | [diff] [blame] | 12 | #include <asm/fsl_pci.h> |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <asm/cache.h> |
| 15 | #include <libfdt.h> |
| 16 | #include <fdt_support.h> |
| 17 | #include <pca953x.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | extern void ft_board_pci_setup(void *blob, bd_t *bd); |
| 22 | |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 23 | static void flash_cs_fixup(void) |
| 24 | { |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 25 | int flash_sel; |
| 26 | |
| 27 | /* |
| 28 | * Print boot dev and swap flash flash chip selects if booted from 2nd |
| 29 | * flash. Swapping chip selects presents user with a common memory |
| 30 | * map regardless of which flash was booted from. |
| 31 | */ |
| 32 | flash_sel = !((pca953x_get_val(CONFIG_SYS_I2C_PCA953X_ADDR0) & |
| 33 | CONFIG_SYS_PCA953X_C0_FLASH_PASS_CS)); |
Peter Tyser | 0b5a263 | 2010-12-28 18:12:05 -0600 | [diff] [blame] | 34 | printf("Flash: Executed from flash%d\n", flash_sel ? 2 : 1); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 35 | |
| 36 | if (flash_sel) { |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 37 | set_lbc_br(0, CONFIG_SYS_BR1_PRELIM); |
| 38 | set_lbc_or(0, CONFIG_SYS_OR1_PRELIM); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 39 | |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 40 | set_lbc_br(1, CONFIG_SYS_BR0_PRELIM); |
| 41 | set_lbc_or(1, CONFIG_SYS_OR0_PRELIM); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | int board_early_init_r(void) |
| 46 | { |
| 47 | /* Initialize PCA9557 devices */ |
| 48 | pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR0, 0xff, 0); |
| 49 | pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR1, 0xff, 0); |
Peter Tyser | b6084fa | 2009-07-19 19:17:41 -0500 | [diff] [blame] | 50 | pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR2, 0xff, 0); |
| 51 | pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR3, 0xff, 0); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * Remap NOR flash region to caching-inhibited |
| 55 | * so that flash can be erased/programmed properly. |
| 56 | */ |
| 57 | |
| 58 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 59 | flush_dcache(); |
| 60 | invalidate_icache(); |
| 61 | |
| 62 | /* Invalidate existing TLB entry for NOR flash */ |
| 63 | disable_tlb(0); |
| 64 | set_tlb(1, (CONFIG_SYS_FLASH_BASE2 & 0xf0000000), |
| 65 | (CONFIG_SYS_FLASH_BASE2 & 0xf0000000), |
| 66 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, |
| 67 | 0, 0, BOOKE_PAGESZ_256M, 1); |
| 68 | |
| 69 | flash_cs_fixup(); |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 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 | 1c2b329 | 2008-12-17 16:36:23 -0600 | [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 | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 83 | } |
| 84 | #endif |