common: Drop net.h from common header
[pandora-u-boot.git] / board / freescale / p1_twr / p1_twr.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2013 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <command.h>
8 #include <env.h>
9 #include <hwconfig.h>
10 #include <init.h>
11 #include <net.h>
12 #include <pci.h>
13 #include <i2c.h>
14 #include <asm/processor.h>
15 #include <asm/mmu.h>
16 #include <asm/cache.h>
17 #include <asm/immap_85xx.h>
18 #include <asm/fsl_pci.h>
19 #include <fsl_ddr_sdram.h>
20 #include <asm/io.h>
21 #include <asm/fsl_law.h>
22 #include <asm/fsl_lbc.h>
23 #include <asm/mp.h>
24 #include <miiphy.h>
25 #include <linux/libfdt.h>
26 #include <fdt_support.h>
27 #include <fsl_mdio.h>
28 #include <tsec.h>
29 #include <ioports.h>
30 #include <asm/fsl_serdes.h>
31 #include <netdev.h>
32
33 #define SYSCLK_64       64000000
34 #define SYSCLK_66       66666666
35
36 unsigned long get_board_sys_clk(ulong dummy)
37 {
38         ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
39         par_io_t *par_io = (par_io_t *) &(gur->qe_par_io);
40         unsigned int cpdat_val = 0;
41
42         /* Set-up up pin muxing based on board switch settings */
43         cpdat_val = par_io[1].cpdat;
44
45         /* Check switch setting for SYSCLK select (PB3)  */
46         if (cpdat_val & 0x10000000)
47                 return SYSCLK_64;
48         else
49                 return SYSCLK_66;
50
51         return 0;
52 }
53
54 #ifdef CONFIG_QE
55
56 #define PCA_IOPORT_I2C_ADDR             0x23
57 #define PCA_IOPORT_OUTPUT_CMD           0x2
58 #define PCA_IOPORT_CFG_CMD              0x6
59
60 const qe_iop_conf_t qe_iop_conf_tab[] = {
61
62 #ifdef CONFIG_TWR_P1025
63         /* GPIO */
64         {1,  0, 1, 0, 0},
65         {1,  18, 1, 0, 0},
66
67         /* GPIO for switch options */
68         {1,  2, 2, 0, 0}, /* PROFIBUS_MODE_SEL */
69         {1,  3, 2, 0, 0}, /* SYS_CLK_SELECT */
70         {1,  29, 2, 0, 0}, /* LOCALBUS_QE_MUXSEL */
71         {1,  30, 2, 0, 0}, /* ETH_TDM_SEL */
72
73         /* QE_MUX_MDC */
74         {1,  19, 1, 0, 1}, /* QE_MUX_MDC */
75
76         /* QE_MUX_MDIO */
77         {1,  20, 3, 0, 1}, /* QE_MUX_MDIO */
78
79         /* UCC_1_MII */
80         {0, 23, 2, 0, 2}, /* CLK12 */
81         {0, 24, 2, 0, 1}, /* CLK9 */
82         {0,  7, 1, 0, 2}, /* ENET1_TXD0_SER1_TXD0 */
83         {0,  9, 1, 0, 2}, /* ENET1_TXD1_SER1_TXD1 */
84         {0, 11, 1, 0, 2}, /* ENET1_TXD2_SER1_TXD2 */
85         {0, 12, 1, 0, 2}, /* ENET1_TXD3_SER1_TXD3 */
86         {0,  6, 2, 0, 2}, /* ENET1_RXD0_SER1_RXD0 */
87         {0, 10, 2, 0, 2}, /* ENET1_RXD1_SER1_RXD1 */
88         {0, 14, 2, 0, 2}, /* ENET1_RXD2_SER1_RXD2 */
89         {0, 15, 2, 0, 2}, /* ENET1_RXD3_SER1_RXD3 */
90         {0,  5, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B */
91         {0, 13, 1, 0, 2}, /* ENET1_TX_ER */
92         {0,  4, 2, 0, 2}, /* ENET1_RX_DV_SER1_CTS_B */
93         {0,  8, 2, 0, 2}, /* ENET1_RX_ER_SER1_CD_B */
94         {0, 17, 2, 0, 2}, /* ENET1_CRS */
95         {0, 16, 2, 0, 2}, /* ENET1_COL */
96
97         /* UCC_5_RMII */
98         {1, 11, 2, 0, 1}, /* CLK13 */
99         {1, 7,  1, 0, 2}, /* ENET5_TXD0_SER5_TXD0 */
100         {1, 10, 1, 0, 2}, /* ENET5_TXD1_SER5_TXD1 */
101         {1, 6, 2, 0, 2}, /* ENET5_RXD0_SER5_RXD0 */
102         {1, 9, 2, 0, 2}, /* ENET5_RXD1_SER5_RXD1 */
103         {1, 5, 1, 0, 2}, /* ENET5_TX_EN_SER5_RTS_B */
104         {1, 4, 2, 0, 2}, /* ENET5_RX_DV_SER5_CTS_B */
105         {1, 8, 2, 0, 2}, /* ENET5_RX_ER_SER5_CD_B */
106
107         /* TDMA - clock option is configured in OS based on board setting */
108         {1, 23, 2, 0, 2}, /* TDMA_TXD */
109         {1, 25, 2, 0, 2}, /* TDMA_RXD */
110         {1, 26, 1, 0, 2}, /* TDMA_SYNC */
111 #endif
112
113         {0,  0, 0, 0, QE_IOP_TAB_END} /* END of table */
114 };
115 #endif
116
117 int board_early_init_f(void)
118 {
119         ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
120
121         setbits_be32(&gur->pmuxcr,
122                         (MPC85xx_PMUXCR_SDHC_CD | MPC85xx_PMUXCR_SDHC_WP));
123
124         /* SDHC_DAT[4:7] not exposed to pins (use as SPI) */
125         clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
126
127         return 0;
128 }
129
130 int checkboard(void)
131 {
132         ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
133         u8 boot_status;
134
135         printf("Board: %s\n", CONFIG_BOARDNAME);
136
137         boot_status = ((gur->porbmsr) >> MPC85xx_PORBMSR_ROMLOC_SHIFT) & 0xf;
138         puts("rom_loc: ");
139         if (boot_status == PORBMSR_ROMLOC_NOR)
140                 puts("nor flash");
141         else if (boot_status == PORBMSR_ROMLOC_SDHC)
142                 puts("sd");
143         else
144                 puts("unknown");
145         puts("\n");
146
147         return 0;
148 }
149
150 #ifdef CONFIG_PCI
151 void pci_init_board(void)
152 {
153         fsl_pcie_init_board(0);
154 }
155 #endif
156
157 int board_early_init_r(void)
158 {
159         const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
160         int flash_esel = find_tlb_idx((void *)flashbase, 1);
161
162         /*
163          * Remap Boot flash region to caching-inhibited
164          * so that flash can be erased properly.
165          */
166
167         /* Flush d-cache and invalidate i-cache of any FLASH data */
168         flush_dcache();
169         invalidate_icache();
170
171         if (flash_esel == -1) {
172                 /* very unlikely unless something is messed up */
173                 puts("Error: Could not find TLB for FLASH BASE\n");
174                 flash_esel = 2; /* give our best effort to continue */
175         } else {
176                 /* invalidate existing TLB entry for flash */
177                 disable_tlb(flash_esel);
178         }
179
180         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */
181                 MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,           /* perms, wimge */
182                 0, flash_esel, BOOKE_PAGESZ_64M, 1);/* ts, esel, tsize, iprot */
183         return 0;
184 }
185
186 int board_eth_init(bd_t *bis)
187 {
188         struct fsl_pq_mdio_info mdio_info;
189         struct tsec_info_struct tsec_info[4];
190         ccsr_gur_t *gur __attribute__((unused)) =
191                 (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
192         int num = 0;
193
194 #ifdef CONFIG_TSEC1
195         SET_STD_TSEC_INFO(tsec_info[num], 1);
196         num++;
197 #endif
198 #ifdef CONFIG_TSEC2
199         SET_STD_TSEC_INFO(tsec_info[num], 2);
200         if (is_serdes_configured(SGMII_TSEC2)) {
201                 printf("eTSEC2 is in sgmii mode.\n");
202                 tsec_info[num].flags |= TSEC_SGMII;
203         }
204         num++;
205 #endif
206 #ifdef CONFIG_TSEC3
207         SET_STD_TSEC_INFO(tsec_info[num], 3);
208         num++;
209 #endif
210
211         if (!num) {
212                 printf("No TSECs initialized\n");
213                 return 0;
214         }
215
216         mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
217         mdio_info.name = DEFAULT_MII_NAME;
218
219         fsl_pq_mdio_init(bis, &mdio_info);
220
221         tsec_eth_init(bis, tsec_info, num);
222
223 #if defined(CONFIG_UEC_ETH)
224         /* QE0 and QE3 need to be exposed for UCC1
225          * and UCC5 Eth mode (in PMUXCR register).
226          * Currently QE/LBC muxed pins assumed to be
227          * LBC for U-Boot and PMUXCR updated by OS if required */
228
229         uec_standard_init(bis);
230 #endif
231
232         return pci_eth_init(bis);
233 }
234
235 #if defined(CONFIG_QE)
236 static void fdt_board_fixup_qe_pins(void *blob)
237 {
238         int node;
239
240         if (!hwconfig("qe")) {
241                 /* For QE and eLBC pins multiplexing,
242                  * When don't use QE function, remove
243                  * qe node from dt blob.
244                  */
245                 node = fdt_path_offset(blob, "/qe");
246                 if (node >= 0)
247                         fdt_del_node(blob, node);
248         } else {
249                 /* For TWR Peripheral Modules - TWR-SER2
250                  * board only can support Signal Port MII,
251                  * so delete one UEC node when use MII port.
252                  */
253                 if (hwconfig("mii"))
254                         node = fdt_path_offset(blob, "/qe/ucc@2400");
255                 else
256                         node = fdt_path_offset(blob, "/qe/ucc@2000");
257                 if (node >= 0)
258                         fdt_del_node(blob, node);
259         }
260
261         return;
262 }
263 #endif
264
265 #ifdef CONFIG_OF_BOARD_SETUP
266 int ft_board_setup(void *blob, bd_t *bd)
267 {
268         phys_addr_t base;
269         phys_size_t size;
270
271         ft_cpu_setup(blob, bd);
272
273         base = env_get_bootm_low();
274         size = env_get_bootm_size();
275
276         fdt_fixup_memory(blob, (u64)base, (u64)size);
277
278         FT_FSL_PCI_SETUP;
279
280 #ifdef CONFIG_QE
281         do_fixup_by_compat(blob, "fsl,qe", "status", "okay",
282                         sizeof("okay"), 0);
283 #endif
284 #if defined(CONFIG_TWR_P1025)
285         fdt_board_fixup_qe_pins(blob);
286 #endif
287         fsl_fdt_fixup_dr_usb(blob, bd);
288
289         return 0;
290 }
291 #endif