common: Drop net.h from common header
[platform/kernel/u-boot.git] / board / freescale / bsc9132qds / bsc9132qds.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 <fsl_ifc.h>
23 #include <hwconfig.h>
24 #include <i2c.h>
25 #include <fsl_ddr_sdram.h>
26 #include <jffs2/load_kernel.h>
27 #include <mtd_node.h>
28 #include <flash.h>
29
30 #ifdef CONFIG_PCI
31 #include <pci.h>
32 #include <asm/fsl_pci.h>
33 #endif
34
35 #include "../common/qixis.h"
36 DECLARE_GLOBAL_DATA_PTR;
37
38
39 int board_early_init_f(void)
40 {
41         struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
42
43         setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
44
45         return 0;
46 }
47
48 void board_config_serdes_mux(void)
49 {
50         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
51         u32 pordevsr = in_be32(&gur->pordevsr);
52         u32 srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
53                                 MPC85xx_PORDEVSR_IO_SEL_SHIFT;
54
55         switch (srds_cfg) {
56         /* PEX(1) PEX(2) CPRI 2 CPRI 1 */
57         case  1:
58         case  2:
59         case  3:
60         case  4:
61         case  5:
62         case 22:
63         case 23:
64         case 24:
65         case 25:
66         case 26:
67                 QIXIS_WRITE_I2C(brdcfg[4], 0x03);
68                 break;
69
70         /* PEX(1) PEX(2) SGMII1 CPRI 1 */
71         case  6:
72         case  7:
73         case  8:
74         case  9:
75         case 10:
76         case 27:
77         case 28:
78         case 29:
79         case 30:
80         case 31:
81                 QIXIS_WRITE_I2C(brdcfg[4], 0x01);
82                 break;
83
84         /* PEX(1) PEX(2) SGMII1 SGMII2 */
85         case 11:
86         case 32:
87                 QIXIS_WRITE_I2C(brdcfg[4], 0x00);
88                 break;
89
90         /* PEX(1) SGMII2 CPRI 2 CPRI 1 */
91         case 12:
92         case 13:
93         case 14:
94         case 15:
95         case 16:
96         case 33:
97         case 34:
98         case 35:
99         case 36:
100         case 37:
101                 QIXIS_WRITE_I2C(brdcfg[4], 0x07);
102                 break;
103
104         /* PEX(1) SGMII2 SGMII1 CPRI 1 */
105         case 17:
106         case 18:
107         case 19:
108         case 20:
109         case 21:
110         case 38:
111         case 39:
112         case 40:
113         case 41:
114         case 42:
115                 QIXIS_WRITE_I2C(brdcfg[4], 0x05);
116                 break;
117
118         /* SGMII1 SGMII2 CPRI 2 CPRI 1 */
119         case 43:
120         case 44:
121         case 45:
122         case 46:
123         case 47:
124                 QIXIS_WRITE_I2C(brdcfg[4], 0x0F);
125                 break;
126
127
128         default:
129                 break;
130         }
131 }
132
133 /* Configure DSP DDR controller */
134 void dsp_ddr_configure(void)
135 {
136         /*
137          *There are separate DDR-controllers for DSP and PowerPC side DDR.
138          *copy the ddr controller settings from PowerPC side DDR controller
139          *to the DSP DDR controller as connected DDR memories are similar.
140          */
141         struct ccsr_ddr __iomem *pa_ddr =
142                         (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DDR_ADDR;
143         struct ccsr_ddr temp_ddr;
144         struct ccsr_ddr __iomem *dsp_ddr =
145                         (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DSP_CCSR_DDR_ADDR;
146
147         memcpy(&temp_ddr, pa_ddr, sizeof(struct ccsr_ddr));
148         temp_ddr.cs0_bnds = CONFIG_SYS_DDR1_CS0_BNDS;
149         temp_ddr.sdram_cfg &= ~SDRAM_CFG_MEM_EN;
150         memcpy(dsp_ddr, &temp_ddr, sizeof(struct ccsr_ddr));
151         dsp_ddr->sdram_cfg |= SDRAM_CFG_MEM_EN;
152 }
153
154 int board_early_init_r(void)
155 {
156 #ifdef CONFIG_MTD_NOR_FLASH
157         const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
158         int flash_esel = find_tlb_idx((void *)flashbase, 1);
159
160         /*
161          * Remap Boot flash region to caching-inhibited
162          * so that flash can be erased properly.
163          */
164
165         /* Flush d-cache and invalidate i-cache of any FLASH data */
166         flush_dcache();
167         invalidate_icache();
168
169         if (flash_esel == -1) {
170                 /* very unlikely unless something is messed up */
171                 puts("Error: Could not find TLB for FLASH BASE\n");
172                 flash_esel = 2; /* give our best effort to continue */
173         } else {
174                 /* invalidate existing TLB entry for flash */
175                 disable_tlb(flash_esel);
176         }
177
178         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
179                         MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
180                         0, flash_esel, BOOKE_PAGESZ_64M, 1);
181
182         set_tlb(1, flashbase + 0x4000000,
183                         CONFIG_SYS_FLASH_BASE_PHYS + 0x4000000,
184                         MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
185                         0, flash_esel+1, BOOKE_PAGESZ_64M, 1);
186 #endif
187         board_config_serdes_mux();
188         dsp_ddr_configure();
189         return 0;
190 }
191
192 #ifdef CONFIG_PCI
193 void pci_init_board(void)
194 {
195         fsl_pcie_init_board(0);
196 }
197 #endif /* ifdef CONFIG_PCI */
198
199 int checkboard(void)
200 {
201         struct cpu_type *cpu;
202         u8 sw;
203
204         cpu = gd->arch.cpu;
205         printf("Board: %sQDS\n", cpu->name);
206
207         printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x,\n",
208         QIXIS_READ(id), QIXIS_READ(arch), QIXIS_READ(scver));
209
210         sw = QIXIS_READ(brdcfg[0]);
211         sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
212
213         printf("IFC chip select:");
214         switch (sw) {
215         case 0:
216                 printf("NOR\n");
217                 break;
218         case 2:
219                 printf("Promjet\n");
220                 break;
221         case 4:
222                 printf("NAND\n");
223                 break;
224         default:
225                 printf("Invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
226                 break;
227         }
228
229         return 0;
230 }
231
232 int board_eth_init(bd_t *bis)
233 {
234 #ifdef CONFIG_TSEC_ENET
235         struct fsl_pq_mdio_info mdio_info;
236         struct tsec_info_struct tsec_info[4];
237         int num = 0;
238
239 #ifdef CONFIG_TSEC1
240         SET_STD_TSEC_INFO(tsec_info[num], 1);
241         num++;
242
243 #endif
244
245 #ifdef CONFIG_TSEC2
246         SET_STD_TSEC_INFO(tsec_info[num], 2);
247         num++;
248 #endif
249
250         mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
251         mdio_info.name = DEFAULT_MII_NAME;
252
253         fsl_pq_mdio_init(bis, &mdio_info);
254         tsec_eth_init(bis, tsec_info, num);
255 #endif
256
257         #ifdef CONFIG_PCI
258         pci_eth_init(bis);
259         #endif
260
261         return 0;
262 }
263
264 #define USBMUX_SEL_MASK         0xc0
265 #define USBMUX_SEL_UART2        0xc0
266 #define USBMUX_SEL_USB          0x40
267 #define SPIMUX_SEL_UART3        0x80
268 #define GPS_MUX_SEL_GPS         0x40
269
270 #define TSEC_1588_CLKIN_MASK    0x03
271 #define CON_XCVR_REF_CLK        0x00
272
273 int misc_init_r(void)
274 {
275         u8 val;
276         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
277         u32 porbmsr = in_be32(&gur->porbmsr);
278         u32 romloc = (porbmsr >> MPC85xx_PORBMSR_ROMLOC_SHIFT) & 0xf;
279
280         /*Configure 1588 clock-in source from RF Card*/
281         val = QIXIS_READ_I2C(brdcfg[5]);
282         QIXIS_WRITE_I2C(brdcfg[5],
283                 (val & ~(TSEC_1588_CLKIN_MASK)) | CON_XCVR_REF_CLK);
284
285         if (hwconfig("uart2") && hwconfig("usb1")) {
286                 printf("UART2 and USB cannot work together on the board\n");
287                 printf("Remove one from hwconfig and reset\n");
288         } else {
289                 if (hwconfig("uart2")) {
290                         val = QIXIS_READ_I2C(brdcfg[5]);
291                         QIXIS_WRITE_I2C(brdcfg[5],
292                                 (val & ~(USBMUX_SEL_MASK)) | USBMUX_SEL_UART2);
293                         clrbits_be32(&gur->pmuxcr3,
294                                                 MPC85xx_PMUXCR3_USB_SEL_MASK);
295                         setbits_be32(&gur->pmuxcr3, MPC85xx_PMUXCR3_UART2_SEL);
296                 } else {
297                         /* By default USB should be selected.
298                         * Programming FPGA to select USB. */
299                         val = QIXIS_READ_I2C(brdcfg[5]);
300                         QIXIS_WRITE_I2C(brdcfg[5],
301                                 (val & ~(USBMUX_SEL_MASK)) | USBMUX_SEL_USB);
302                 }
303
304         }
305
306         if (hwconfig("sim")) {
307                 if (romloc == PORBMSR_ROMLOC_NAND_2K ||
308                         romloc == PORBMSR_ROMLOC_NOR ||
309                         romloc == PORBMSR_ROMLOC_SPI) {
310
311                         val = QIXIS_READ_I2C(brdcfg[3]);
312                         QIXIS_WRITE_I2C(brdcfg[3], val|0x10);
313                         clrbits_be32(&gur->pmuxcr,
314                                 MPC85xx_PMUXCR0_SIM_SEL_MASK);
315                         setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR0_SIM_SEL);
316                 }
317         }
318
319         if (hwconfig("uart3")) {
320                 if (romloc == PORBMSR_ROMLOC_NAND_2K ||
321                         romloc == PORBMSR_ROMLOC_NOR ||
322                         romloc == PORBMSR_ROMLOC_SDHC) {
323
324                         /* UART3 and SPI1 (Flashes) are muxed together */
325                         val = QIXIS_READ_I2C(brdcfg[3]);
326                         QIXIS_WRITE_I2C(brdcfg[3], (val | SPIMUX_SEL_UART3));
327                         clrbits_be32(&gur->pmuxcr3,
328                                                 MPC85xx_PMUXCR3_UART3_SEL_MASK);
329                         setbits_be32(&gur->pmuxcr3, MPC85xx_PMUXCR3_UART3_SEL);
330
331                         /* MUX to select UART3 connection to J24 header
332                          * or to GPS */
333                         val = QIXIS_READ_I2C(brdcfg[6]);
334                         if (hwconfig("gps"))
335                                 QIXIS_WRITE_I2C(brdcfg[6],
336                                                 (val | GPS_MUX_SEL_GPS));
337                         else
338                                 QIXIS_WRITE_I2C(brdcfg[6],
339                                                 (val & ~(GPS_MUX_SEL_GPS)));
340                 }
341         }
342         return 0;
343 }
344
345 void fdt_del_node_compat(void *blob, const char *compatible)
346 {
347         int err;
348         int off = fdt_node_offset_by_compatible(blob, -1, compatible);
349         if (off < 0) {
350                 printf("WARNING: could not find compatible node %s: %s.\n",
351                         compatible, fdt_strerror(off));
352                 return;
353         }
354         err = fdt_del_node(blob, off);
355         if (err < 0) {
356                 printf("WARNING: could not remove %s: %s.\n",
357                         compatible, fdt_strerror(err));
358         }
359 }
360
361 #if defined(CONFIG_OF_BOARD_SETUP)
362 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
363 static const struct node_info nodes[] = {
364         { "cfi-flash",                  MTD_DEV_TYPE_NOR,  },
365         { "fsl,ifc-nand",               MTD_DEV_TYPE_NAND, },
366 };
367 #endif
368 int ft_board_setup(void *blob, bd_t *bd)
369 {
370         phys_addr_t base;
371         phys_size_t size;
372
373         ft_cpu_setup(blob, bd);
374
375         base = env_get_bootm_low();
376         size = env_get_bootm_size();
377
378         #if defined(CONFIG_PCI)
379         FT_FSL_PCI_SETUP;
380         #endif
381
382         fdt_fixup_memory(blob, (u64)base, (u64)size);
383 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
384         fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
385 #endif
386
387         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
388         u32 porbmsr = in_be32(&gur->porbmsr);
389         u32 romloc = (porbmsr >> MPC85xx_PORBMSR_ROMLOC_SHIFT) & 0xf;
390
391         if (!(hwconfig("uart2") && hwconfig("usb1"))) {
392                 /* If uart2 is there in hwconfig remove usb node from
393                  *  device tree */
394
395                 if (hwconfig("uart2")) {
396                         /* remove dts usb node */
397                         fdt_del_node_compat(blob, "fsl-usb2-dr");
398                 } else {
399                         fsl_fdt_fixup_dr_usb(blob, bd);
400                         fdt_del_node_and_alias(blob, "serial2");
401                 }
402         }
403
404         if (hwconfig("uart3")) {
405                 if (romloc == PORBMSR_ROMLOC_NAND_2K ||
406                         romloc == PORBMSR_ROMLOC_NOR ||
407                         romloc == PORBMSR_ROMLOC_SDHC)
408                         /* Delete SPI node from the device tree */
409                                 fdt_del_node_and_alias(blob, "spi1");
410         } else
411                 fdt_del_node_and_alias(blob, "serial3");
412
413         if (hwconfig("sim")) {
414                 if (romloc == PORBMSR_ROMLOC_NAND_2K ||
415                         romloc == PORBMSR_ROMLOC_NOR ||
416                         romloc == PORBMSR_ROMLOC_SPI) {
417
418                         /* remove dts sdhc node */
419                         fdt_del_node_compat(blob, "fsl,esdhc");
420                 } else if (romloc == PORBMSR_ROMLOC_SDHC) {
421
422                         /* remove dts sim node */
423                         fdt_del_node_compat(blob, "fsl,sim-v1.0");
424                         printf("SIM & SDHC can't work together on the board");
425                         printf("\nRemove sim from hwconfig and reset\n");
426                 }
427         }
428
429         return 0;
430 }
431 #endif