common: Drop net.h from common header
[oweals/u-boot.git] / board / freescale / c29xpcie / c29xpcie.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2013 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <init.h>
8 #include <net.h>
9 #include <asm/processor.h>
10 #include <asm/mmu.h>
11 #include <asm/cache.h>
12 #include <asm/immap_85xx.h>
13 #include <asm/io.h>
14 #include <env.h>
15 #include <miiphy.h>
16 #include <linux/libfdt.h>
17 #include <fdt_support.h>
18 #include <fsl_mdio.h>
19 #include <tsec.h>
20 #include <mmc.h>
21 #include <netdev.h>
22 #include <pci.h>
23 #include <fsl_ifc.h>
24 #include <asm/fsl_pci.h>
25
26 #include "cpld.h"
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 int checkboard(void)
31 {
32         struct cpu_type *cpu = gd->arch.cpu;
33         struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
34
35         printf("Board: %sPCIe, ", cpu->name);
36         printf("CPLD Ver: 0x%02x\n", in_8(&cpld_data->cpldver));
37
38         return 0;
39 }
40
41 int board_early_init_f(void)
42 {
43         struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
44
45         /* Clock configuration to access CPLD using IFC(GPCM) */
46         setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
47
48         return 0;
49 }
50
51 int board_early_init_r(void)
52 {
53         const unsigned long flashbase = CONFIG_SYS_FLASH_BASE;
54         int flash_esel = find_tlb_idx((void *)flashbase, 1);
55
56         /*
57          * Remap Boot flash region to caching-inhibited
58          * so that flash can be erased properly.
59          */
60
61         /* Flush d-cache and invalidate i-cache of any FLASH data */
62         flush_dcache();
63         invalidate_icache();
64
65         if (flash_esel == -1) {
66                 /* very unlikely unless something is messed up */
67                 puts("Error: Could not find TLB for FLASH BASE\n");
68                 flash_esel = 1; /* give our best effort to continue */
69         } else {
70                 /* invalidate existing TLB entry for flash */
71                 disable_tlb(flash_esel);
72         }
73
74         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
75                         MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
76                         0, flash_esel, BOOKE_PAGESZ_64M, 1);
77
78         return 0;
79 }
80
81 #ifdef CONFIG_PCI
82 void pci_init_board(void)
83 {
84         fsl_pcie_init_board(0);
85 }
86 #endif /* ifdef CONFIG_PCI */
87
88 int board_eth_init(bd_t *bis)
89 {
90 #ifdef CONFIG_TSEC_ENET
91         struct fsl_pq_mdio_info mdio_info;
92         struct tsec_info_struct tsec_info[2];
93         int num = 0;
94
95 #ifdef CONFIG_TSEC1
96         SET_STD_TSEC_INFO(tsec_info[num], 1);
97         num++;
98 #endif
99 #ifdef CONFIG_TSEC2
100         SET_STD_TSEC_INFO(tsec_info[num], 2);
101         num++;
102 #endif
103         if (!num) {
104                 printf("No TSECs initialized\n");
105                 return 0;
106         }
107
108         /* Register 1G MDIO bus */
109         mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
110         mdio_info.name = DEFAULT_MII_NAME;
111
112         fsl_pq_mdio_init(bis, &mdio_info);
113
114         tsec_eth_init(bis, tsec_info, num);
115 #endif
116
117         return pci_eth_init(bis);
118 }
119
120 #if defined(CONFIG_OF_BOARD_SETUP)
121 void fdt_del_sec(void *blob, int offset)
122 {
123         int nodeoff = 0;
124
125         while ((nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,sec-v6.0",
126                         CONFIG_SYS_CCSRBAR_PHYS + CONFIG_SYS_FSL_SEC_OFFSET
127                         + offset * CONFIG_SYS_FSL_SEC_IDX_OFFSET)) >= 0) {
128                 fdt_del_node(blob, nodeoff);
129                 offset++;
130         }
131 }
132
133 int ft_board_setup(void *blob, bd_t *bd)
134 {
135         phys_addr_t base;
136         phys_size_t size;
137         struct cpu_type *cpu;
138
139         cpu = gd->arch.cpu;
140
141         ft_cpu_setup(blob, bd);
142
143         base = env_get_bootm_low();
144         size = env_get_bootm_size();
145
146 #if defined(CONFIG_PCI)
147         FT_FSL_PCI_SETUP;
148 #endif
149
150         fdt_fixup_memory(blob, (u64)base, (u64)size);
151         if (cpu->soc_ver == SVR_C291)
152                 fdt_del_sec(blob, 1);
153         else if (cpu->soc_ver == SVR_C292)
154                 fdt_del_sec(blob, 2);
155
156         return 0;
157 }
158 #endif