blob: 437b57d4ff6e01dcf46014c9629c6935b19afa26 [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>
Simon Glass52559322019-11-14 12:57:46 -07008#include <init.h>
Peter Tyserccf0fdd2008-12-17 16:36:23 -06009#include <asm/processor.h>
10#include <asm/mmu.h>
11#include <asm/immap_85xx.h>
Kumar Galac8514622009-04-02 13:22:48 -050012#include <asm/fsl_pci.h>
Peter Tyserccf0fdd2008-12-17 16:36:23 -060013#include <asm/io.h>
14#include <asm/cache.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090015#include <linux/libfdt.h>
Peter Tyserccf0fdd2008-12-17 16:36:23 -060016#include <fdt_support.h>
17#include <pca953x.h>
18
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090019extern void ft_board_pci_setup(void *blob, struct bd_info *bd);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060020
Peter Tyserccf0fdd2008-12-17 16:36:23 -060021static void flash_cs_fixup(void)
22{
Peter Tyserccf0fdd2008-12-17 16:36:23 -060023 int flash_sel;
24
25 /*
26 * Print boot dev and swap flash flash chip selects if booted from 2nd
27 * flash. Swapping chip selects presents user with a common memory
28 * map regardless of which flash was booted from.
29 */
30 flash_sel = !((pca953x_get_val(CONFIG_SYS_I2C_PCA953X_ADDR0) &
31 CONFIG_SYS_PCA953X_C0_FLASH_PASS_CS));
Peter Tysereddf52b2010-12-28 18:12:05 -060032 printf("Flash: Executed from flash%d\n", flash_sel ? 2 : 1);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060033
34 if (flash_sel) {
Becky Brucef51cdaf2010-06-17 11:37:20 -050035 set_lbc_br(0, CONFIG_SYS_BR1_PRELIM);
36 set_lbc_or(0, CONFIG_SYS_OR1_PRELIM);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060037
Becky Brucef51cdaf2010-06-17 11:37:20 -050038 set_lbc_br(1, CONFIG_SYS_BR0_PRELIM);
39 set_lbc_or(1, CONFIG_SYS_OR0_PRELIM);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060040 }
41}
42
43int board_early_init_r(void)
44{
45 /* Initialize PCA9557 devices */
46 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR0, 0xff, 0);
47 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR1, 0xff, 0);
Peter Tyser58f31b62009-07-19 19:17:41 -050048 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR2, 0xff, 0);
49 pca953x_set_pol(CONFIG_SYS_I2C_PCA953X_ADDR3, 0xff, 0);
Peter Tyserccf0fdd2008-12-17 16:36:23 -060050
51 /*
52 * Remap NOR flash region to caching-inhibited
53 * so that flash can be erased/programmed properly.
54 */
55
56 /* Flush d-cache and invalidate i-cache of any FLASH data */
57 flush_dcache();
58 invalidate_icache();
59
60 /* Invalidate existing TLB entry for NOR flash */
61 disable_tlb(0);
62 set_tlb(1, (CONFIG_SYS_FLASH_BASE2 & 0xf0000000),
63 (CONFIG_SYS_FLASH_BASE2 & 0xf0000000),
64 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
65 0, 0, BOOKE_PAGESZ_256M, 1);
66
67 flash_cs_fixup();
68
69 return 0;
70}
71
72#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090073int ft_board_setup(void *blob, struct bd_info *bd)
Peter Tyserccf0fdd2008-12-17 16:36:23 -060074{
75#ifdef CONFIG_PCI
76 ft_board_pci_setup(blob, bd);
77#endif
78 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -060079
80 return 0;
Peter Tyserccf0fdd2008-12-17 16:36:23 -060081}
82#endif