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