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