blob: 9d2888d8676af33940a3ee2b33ba881de5a8ed24 [file] [log] [blame]
Mingkai Hua8d97582013-07-04 17:33:43 +08001/*
2 * Copyright 2013 Freescale Semiconductor, Inc.
3 *
York Sun3aab0cd2013-08-12 14:57:12 -07004 * SPDX-License-Identifier: GPL-2.0+
Mingkai Hua8d97582013-07-04 17:33:43 +08005 */
6
7#include <common.h>
8#include <asm/processor.h>
9#include <asm/mmu.h>
10#include <asm/cache.h>
11#include <asm/immap_85xx.h>
12#include <asm/io.h>
13#include <miiphy.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Mingkai Hua8d97582013-07-04 17:33:43 +080015#include <fdt_support.h>
16#include <fsl_mdio.h>
17#include <tsec.h>
18#include <mmc.h>
19#include <netdev.h>
20#include <pci.h>
York Sun0b665132013-10-22 12:39:02 -070021#include <fsl_ifc.h>
Mingkai Hua8d97582013-07-04 17:33:43 +080022#include <asm/fsl_pci.h>
23
24#include "cpld.h"
25
26DECLARE_GLOBAL_DATA_PTR;
27
28int checkboard(void)
29{
30 struct cpu_type *cpu = gd->arch.cpu;
31 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
32
33 printf("Board: %sPCIe, ", cpu->name);
34 printf("CPLD Ver: 0x%02x\n", in_8(&cpld_data->cpldver));
35
36 return 0;
37}
38
39int board_early_init_f(void)
40{
Jaiprakash Singh39b0bbb2015-03-20 19:28:27 -070041 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
Mingkai Hua8d97582013-07-04 17:33:43 +080042
43 /* Clock configuration to access CPLD using IFC(GPCM) */
Jaiprakash Singh39b0bbb2015-03-20 19:28:27 -070044 setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
Mingkai Hua8d97582013-07-04 17:33:43 +080045
46 return 0;
47}
48
49int board_early_init_r(void)
50{
51 const unsigned long flashbase = CONFIG_SYS_FLASH_BASE;
York Sun9d045682014-06-24 21:16:20 -070052 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Mingkai Hua8d97582013-07-04 17:33:43 +080053
54 /*
55 * Remap Boot flash region to caching-inhibited
56 * so that flash can be erased properly.
57 */
58
59 /* Flush d-cache and invalidate i-cache of any FLASH data */
60 flush_dcache();
61 invalidate_icache();
62
York Sun9d045682014-06-24 21:16:20 -070063 if (flash_esel == -1) {
64 /* very unlikely unless something is messed up */
65 puts("Error: Could not find TLB for FLASH BASE\n");
66 flash_esel = 1; /* give our best effort to continue */
67 } else {
68 /* invalidate existing TLB entry for flash */
69 disable_tlb(flash_esel);
70 }
Mingkai Hua8d97582013-07-04 17:33:43 +080071
72 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
73 MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
74 0, flash_esel, BOOKE_PAGESZ_64M, 1);
75
76 return 0;
77}
78
79#ifdef CONFIG_PCI
80void pci_init_board(void)
81{
82 fsl_pcie_init_board(0);
83}
84#endif /* ifdef CONFIG_PCI */
85
Mingkai Hua8d97582013-07-04 17:33:43 +080086int board_eth_init(bd_t *bis)
87{
Bin Meng98ae83b2016-01-11 22:41:13 -080088#ifdef CONFIG_TSEC_ENET
Mingkai Hua8d97582013-07-04 17:33:43 +080089 struct fsl_pq_mdio_info mdio_info;
90 struct tsec_info_struct tsec_info[2];
91 int num = 0;
92
93#ifdef CONFIG_TSEC1
94 SET_STD_TSEC_INFO(tsec_info[num], 1);
95 num++;
96#endif
97#ifdef CONFIG_TSEC2
98 SET_STD_TSEC_INFO(tsec_info[num], 2);
99 num++;
100#endif
101 if (!num) {
102 printf("No TSECs initialized\n");
103 return 0;
104 }
105
106 /* Register 1G MDIO bus */
107 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
108 mdio_info.name = DEFAULT_MII_NAME;
109
110 fsl_pq_mdio_init(bis, &mdio_info);
111
112 tsec_eth_init(bis, tsec_info, num);
Bin Meng98ae83b2016-01-11 22:41:13 -0800113#endif
Mingkai Hua8d97582013-07-04 17:33:43 +0800114
115 return pci_eth_init(bis);
116}
Mingkai Hua8d97582013-07-04 17:33:43 +0800117
118#if defined(CONFIG_OF_BOARD_SETUP)
119void fdt_del_sec(void *blob, int offset)
120{
121 int nodeoff = 0;
122
123 while ((nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,sec-v6.0",
124 CONFIG_SYS_CCSRBAR_PHYS + CONFIG_SYS_FSL_SEC_OFFSET
Alex Porosanu404bf452016-04-29 15:17:59 +0300125 + offset * CONFIG_SYS_FSL_SEC_IDX_OFFSET)) >= 0) {
Mingkai Hua8d97582013-07-04 17:33:43 +0800126 fdt_del_node(blob, nodeoff);
127 offset++;
128 }
129}
130
Simon Glasse895a4b2014-10-23 18:58:47 -0600131int ft_board_setup(void *blob, bd_t *bd)
Mingkai Hua8d97582013-07-04 17:33:43 +0800132{
133 phys_addr_t base;
134 phys_size_t size;
135 struct cpu_type *cpu;
136
137 cpu = gd->arch.cpu;
138
139 ft_cpu_setup(blob, bd);
140
Simon Glass723806c2017-08-03 12:22:15 -0600141 base = env_get_bootm_low();
142 size = env_get_bootm_size();
Mingkai Hua8d97582013-07-04 17:33:43 +0800143
144#if defined(CONFIG_PCI)
145 FT_FSL_PCI_SETUP;
146#endif
147
148 fdt_fixup_memory(blob, (u64)base, (u64)size);
149 if (cpu->soc_ver == SVR_C291)
150 fdt_del_sec(blob, 1);
151 else if (cpu->soc_ver == SVR_C292)
152 fdt_del_sec(blob, 2);
Simon Glasse895a4b2014-10-23 18:58:47 -0600153
154 return 0;
Mingkai Hua8d97582013-07-04 17:33:43 +0800155}
156#endif