5321e26a9cf02fe017c76cd9546f3bcea9b539e8
[platform/kernel/u-boot.git] / board / freescale / p1023rdb / p1023rdb.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2013 Freescale Semiconductor, Inc.
4  *
5  * Authors:  Roy Zang <tie-fei.zang@freescale.com>
6  *           Chunhe Lan <Chunhe.Lan@freescale.com>
7  */
8
9 #include <common.h>
10 #include <command.h>
11 #include <env.h>
12 #include <init.h>
13 #include <net.h>
14 #include <pci.h>
15 #include <asm/io.h>
16 #include <asm/cache.h>
17 #include <asm/processor.h>
18 #include <asm/mmu.h>
19 #include <asm/immap_85xx.h>
20 #include <asm/fsl_pci.h>
21 #include <fsl_ddr_sdram.h>
22 #include <asm/fsl_portals.h>
23 #include <fsl_qbman.h>
24 #include <linux/libfdt.h>
25 #include <fdt_support.h>
26 #include <netdev.h>
27 #include <malloc.h>
28 #include <fm_eth.h>
29 #include <fsl_mdio.h>
30 #include <miiphy.h>
31 #include <phy.h>
32 #include <fsl_dtsec.h>
33
34 DECLARE_GLOBAL_DATA_PTR;
35
36 int board_early_init_f(void)
37 {
38         fsl_lbc_t *lbc = LBC_BASE_ADDR;
39
40         /* Set ABSWP to implement conversion of addresses in the LBC */
41         setbits_be32(&lbc->lbcr, CONFIG_SYS_LBC_LBCR);
42
43         return 0;
44 }
45
46 int checkboard(void)
47 {
48         printf("Board: P1023 RDB\n");
49
50         return 0;
51 }
52
53 #ifdef CONFIG_PCI
54 void pci_init_board(void)
55 {
56         fsl_pcie_init_board(0);
57 }
58 #endif
59
60 int board_early_init_r(void)
61 {
62         const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
63         int flash_esel = find_tlb_idx((void *)flashbase, 1);
64
65         /*
66          * Remap Boot flash + PROMJET region to caching-inhibited
67          * so that flash can be erased properly.
68          */
69
70         /* Flush d-cache and invalidate i-cache of any FLASH data */
71         flush_dcache();
72         invalidate_icache();
73
74         if (flash_esel == -1) {
75                 /* very unlikely unless something is messed up */
76                 puts("Error: Could not find TLB for FLASH BASE\n");
77                 flash_esel = 2; /* give our best effort to continue */
78         } else {
79                 /* invalidate existing TLB entry for flash + promjet */
80                 disable_tlb(flash_esel);
81         }
82
83         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
84                 MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
85                 0, flash_esel, BOOKE_PAGESZ_256M, 1);
86
87         setup_qbman_portals();
88
89         return 0;
90 }
91
92 unsigned long get_board_sys_clk(ulong dummy)
93 {
94         return gd->bus_clk;
95 }
96
97 unsigned long get_board_ddr_clk(ulong dummy)
98 {
99         return gd->mem_clk;
100 }
101
102 int board_eth_init(bd_t *bis)
103 {
104         ccsr_gur_t *gur = (ccsr_gur_t *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
105         struct fsl_pq_mdio_info dtsec_mdio_info;
106
107         /*
108          * Need to set dTSEC 1 pin multiplexing to TSEC. The default setting
109          * is not correct.
110          */
111         setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_TSEC1_1);
112
113         dtsec_mdio_info.regs =
114                 (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
115         dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
116
117         /* Register the 1G MDIO bus */
118         fsl_pq_mdio_init(bis, &dtsec_mdio_info);
119
120         fm_info_set_phy_address(FM1_DTSEC1, CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
121         fm_info_set_phy_address(FM1_DTSEC2, CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
122
123         fm_info_set_mdio(FM1_DTSEC1,
124                          miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME));
125         fm_info_set_mdio(FM1_DTSEC2,
126                          miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME));
127
128 #ifdef CONFIG_FMAN_ENET
129         cpu_eth_init(bis);
130 #endif
131
132         return pci_eth_init(bis);
133 }
134
135 #if defined(CONFIG_OF_BOARD_SETUP)
136 int ft_board_setup(void *blob, bd_t *bd)
137 {
138         phys_addr_t base;
139         phys_size_t size;
140
141         ft_cpu_setup(blob, bd);
142
143         base = env_get_bootm_low();
144         size = env_get_bootm_size();
145
146         fdt_fixup_memory(blob, (u64)base, (u64)size);
147
148 #ifdef CONFIG_HAS_FSL_DR_USB
149         fsl_fdt_fixup_dr_usb(blob, bd);
150 #endif
151
152         fdt_fixup_fman_ethernet(blob);
153
154         return 0;
155 }
156 #endif