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