blob: 8776a02302c029b8049913f70b6869e304b82e33 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Tyserccf0fdd2008-12-17 16:36:23 -06002/*
3 * Copyright 2008 Extreme Engineering Solutions, Inc.
Peter Tyserccf0fdd2008-12-17 16:36:23 -06004 */
5
6#include <common.h>
7#include <command.h>
8#include <asm/processor.h>
9#include <asm/mmu.h>
10#include <asm/immap_85xx.h>
Kumar Galac8514622009-04-02 13:22:48 -050011#include <asm/fsl_pci.h>
Peter Tyserccf0fdd2008-12-17 16:36:23 -060012#include <asm/io.h>
13#include <asm/cache.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Peter Tyserccf0fdd2008-12-17 16:36:23 -060015#include <fdt_support.h>
16#include <pca953x.h>
17
Peter Tyserccf0fdd2008-12-17 16:36:23 -060018extern void ft_board_pci_setup(void *blob, bd_t *bd);
19
Peter Tyserccf0fdd2008-12-17 16:36:23 -060020static void flash_cs_fixup(void)
21{
Peter Tyserccf0fdd2008-12-17 16:36:23 -060022 int flash_sel;
23
24 /*
25 * Print boot dev and swap flash flash chip selects if booted from 2nd
26 * flash. Swapping chip selects presents user with a common memory
27 * map regardless of which flash was booted from.
28 */
29 flash_sel = !((pca953x_get_val(CONFIG_SYS_I2C_PCA953X_ADDR0) &
30 CONFIG_SYS_PCA953X_C0_FLASH_PASS_CS));
Peter Tysereddf52b2010-12-28 18:12:05 -060031 printf("Flash: Executed from flash%d\n", flash_sel ? 2 : 1);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060032
33 if (flash_sel) {
Becky Brucef51cdaf2010-06-17 11:37:20 -050034 set_lbc_br(0, CONFIG_SYS_BR1_PRELIM);
35 set_lbc_or(0, CONFIG_SYS_OR1_PRELIM);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060036
Becky Brucef51cdaf2010-06-17 11:37:20 -050037 set_lbc_br(1, CONFIG_SYS_BR0_PRELIM);
38 set_lbc_or(1, CONFIG_SYS_OR0_PRELIM);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060039 }
40}
41
42int board_early_init_r(void)
43{
44 /* Initialize PCA9557 devices */
45 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR0, 0xff, 0);
46 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR1, 0xff, 0);
Peter Tyser58f31b62009-07-19 19:17:41 -050047 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR2, 0xff, 0);
48 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR3, 0xff, 0);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060049
50 /*
51 * Remap NOR flash region to caching-inhibited
52 * so that flash can be erased/programmed properly.
53 */
54
55 /* Flush d-cache and invalidate i-cache of any FLASH data */
56 flush_dcache();
57 invalidate_icache();
58
59 /* Invalidate existing TLB entry for NOR flash */
60 disable_tlb(0);
61 set_tlb(1, (CONFIG_SYS_FLASH_BASE2 & 0xf0000000),
62 (CONFIG_SYS_FLASH_BASE2 & 0xf0000000),
63 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
64 0, 0, BOOKE_PAGESZ_256M, 1);
65
66 flash_cs_fixup();
67
68 return 0;
69}
70
71#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -060072int ft_board_setup(void *blob, bd_t *bd)
Peter Tyserccf0fdd2008-12-17 16:36:23 -060073{
74#ifdef CONFIG_PCI
75 ft_board_pci_setup(blob, bd);
76#endif
77 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -060078
79 return 0;
Peter Tyserccf0fdd2008-12-17 16:36:23 -060080}
81#endif