blob: a9ea986579aee3fcdcdc91c7a062ae53de96b0fc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mingkai Hue04004b2013-07-04 17:33:43 +08002/*
3 * Copyright 2013 Freescale Semiconductor, Inc.
Mingkai Hue04004b2013-07-04 17:33:43 +08004 */
5
6#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Mingkai Hue04004b2013-07-04 17:33:43 +08008#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>
Simon Glass0af6e2d2019-08-01 09:46:52 -060013#include <env.h>
Mingkai Hue04004b2013-07-04 17:33:43 +080014#include <miiphy.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090015#include <linux/libfdt.h>
Mingkai Hue04004b2013-07-04 17:33:43 +080016#include <fdt_support.h>
17#include <fsl_mdio.h>
18#include <tsec.h>
19#include <mmc.h>
20#include <netdev.h>
21#include <pci.h>
York Sun37562f62013-10-22 12:39:02 -070022#include <fsl_ifc.h>
Mingkai Hue04004b2013-07-04 17:33:43 +080023#include <asm/fsl_pci.h>
24
25#include "cpld.h"
26
27DECLARE_GLOBAL_DATA_PTR;
28
29int checkboard(void)
30{
31 struct cpu_type *cpu = gd->arch.cpu;
32 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
33
34 printf("Board: %sPCIe, ", cpu->name);
35 printf("CPLD Ver: 0x%02x\n", in_8(&cpld_data->cpldver));
36
37 return 0;
38}
39
40int board_early_init_f(void)
41{
Jaiprakash Singhdd888062015-03-20 19:28:27 -070042 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
Mingkai Hue04004b2013-07-04 17:33:43 +080043
44 /* Clock configuration to access CPLD using IFC(GPCM) */
Jaiprakash Singhdd888062015-03-20 19:28:27 -070045 setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
Mingkai Hue04004b2013-07-04 17:33:43 +080046
47 return 0;
48}
49
50int board_early_init_r(void)
51{
52 const unsigned long flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -070053 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Mingkai Hue04004b2013-07-04 17:33:43 +080054
55 /*
56 * Remap Boot flash region to caching-inhibited
57 * so that flash can be erased properly.
58 */
59
60 /* Flush d-cache and invalidate i-cache of any FLASH data */
61 flush_dcache();
62 invalidate_icache();
63
York Sun220c3462014-06-24 21:16:20 -070064 if (flash_esel == -1) {
65 /* very unlikely unless something is messed up */
66 puts("Error: Could not find TLB for FLASH BASE\n");
67 flash_esel = 1; /* give our best effort to continue */
68 } else {
69 /* invalidate existing TLB entry for flash */
70 disable_tlb(flash_esel);
71 }
Mingkai Hue04004b2013-07-04 17:33:43 +080072
73 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
74 MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
75 0, flash_esel, BOOKE_PAGESZ_64M, 1);
76
77 return 0;
78}
79
80#ifdef CONFIG_PCI
81void pci_init_board(void)
82{
83 fsl_pcie_init_board(0);
84}
85#endif /* ifdef CONFIG_PCI */
86
Mingkai Hue04004b2013-07-04 17:33:43 +080087int board_eth_init(bd_t *bis)
88{
Bin Menge1bd42d2016-01-11 22:41:13 -080089#ifdef CONFIG_TSEC_ENET
Mingkai Hue04004b2013-07-04 17:33:43 +080090 struct fsl_pq_mdio_info mdio_info;
91 struct tsec_info_struct tsec_info[2];
92 int num = 0;
93
94#ifdef CONFIG_TSEC1
95 SET_STD_TSEC_INFO(tsec_info[num], 1);
96 num++;
97#endif
98#ifdef CONFIG_TSEC2
99 SET_STD_TSEC_INFO(tsec_info[num], 2);
100 num++;
101#endif
102 if (!num) {
103 printf("No TSECs initialized\n");
104 return 0;
105 }
106
107 /* Register 1G MDIO bus */
108 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
109 mdio_info.name = DEFAULT_MII_NAME;
110
111 fsl_pq_mdio_init(bis, &mdio_info);
112
113 tsec_eth_init(bis, tsec_info, num);
Bin Menge1bd42d2016-01-11 22:41:13 -0800114#endif
Mingkai Hue04004b2013-07-04 17:33:43 +0800115
116 return pci_eth_init(bis);
117}
Mingkai Hue04004b2013-07-04 17:33:43 +0800118
119#if defined(CONFIG_OF_BOARD_SETUP)
120void fdt_del_sec(void *blob, int offset)
121{
122 int nodeoff = 0;
123
124 while ((nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,sec-v6.0",
125 CONFIG_SYS_CCSRBAR_PHYS + CONFIG_SYS_FSL_SEC_OFFSET
Alex Porosanub4848d02016-04-29 15:17:59 +0300126 + offset * CONFIG_SYS_FSL_SEC_IDX_OFFSET)) >= 0) {
Mingkai Hue04004b2013-07-04 17:33:43 +0800127 fdt_del_node(blob, nodeoff);
128 offset++;
129 }
130}
131
Simon Glass2aec3cc2014-10-23 18:58:47 -0600132int ft_board_setup(void *blob, bd_t *bd)
Mingkai Hue04004b2013-07-04 17:33:43 +0800133{
134 phys_addr_t base;
135 phys_size_t size;
136 struct cpu_type *cpu;
137
138 cpu = gd->arch.cpu;
139
140 ft_cpu_setup(blob, bd);
141
Simon Glassda1a1342017-08-03 12:22:15 -0600142 base = env_get_bootm_low();
143 size = env_get_bootm_size();
Mingkai Hue04004b2013-07-04 17:33:43 +0800144
145#if defined(CONFIG_PCI)
146 FT_FSL_PCI_SETUP;
147#endif
148
149 fdt_fixup_memory(blob, (u64)base, (u64)size);
150 if (cpu->soc_ver == SVR_C291)
151 fdt_del_sec(blob, 1);
152 else if (cpu->soc_ver == SVR_C292)
153 fdt_del_sec(blob, 2);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600154
155 return 0;
Mingkai Hue04004b2013-07-04 17:33:43 +0800156}
157#endif