Layerscape: Enable Job ring driver model.
[platform/kernel/u-boot.git] / board / freescale / ls1021aiot / ls1021aiot.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2016 Freescale Semiconductor, Inc.
4  * Copyright 2021 NXP
5  */
6
7 #include <common.h>
8 #include <clock_legacy.h>
9 #include <fdt_support.h>
10 #include <init.h>
11 #include <net.h>
12 #include <asm/arch/immap_ls102xa.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/fsl_serdes.h>
15 #include <asm/arch/ls102xa_stream_id.h>
16 #include <asm/global_data.h>
17 #include <linux/delay.h>
18
19 #include <asm/arch/ls102xa_devdis.h>
20 #include <asm/arch/ls102xa_soc.h>
21 #include <fsl_csu.h>
22 #include <fsl_immap.h>
23 #include <netdev.h>
24 #include <fsl_mdio.h>
25 #include <tsec.h>
26 #include <spl.h>
27
28 #include <fsl_validate.h>
29 #include "../common/sleep.h"
30
31 DECLARE_GLOBAL_DATA_PTR;
32
33 #define DDR_SIZE                0x40000000
34
35
36 int checkboard(void)
37 {
38         puts("Board: LS1021AIOT\n");
39
40 #ifndef CONFIG_QSPI_BOOT
41         struct ccsr_gur *dcfg = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
42         u32 cpldrev;
43
44         cpldrev = in_be32(&dcfg->gpporcr1);
45
46         printf("CPLD:  V%d.%d\n", ((cpldrev >> 28) & 0xf), ((cpldrev >> 24) &
47                 0xf));
48 #endif
49         return 0;
50 }
51
52 void ddrmc_init(void)
53 {
54         struct ccsr_ddr *ddr = (struct ccsr_ddr *)CONFIG_SYS_FSL_DDR_ADDR;
55         u32 temp_sdram_cfg, tmp;
56
57         out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG);
58
59         out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS);
60         out_be32(&ddr->cs0_config, DDR_CS0_CONFIG);
61
62         out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0);
63         out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1);
64         out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2);
65         out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3);
66         out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4);
67         out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5);
68
69         out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2);
70         out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2);
71
72         out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE);
73         out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2);
74
75         out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL);
76
77         out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL);
78
79         out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2);
80         out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3);
81
82         out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1);
83
84         out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL);
85         out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL);
86
87         out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2);
88
89         /* DDR erratum A-009942 */
90         tmp = in_be32(&ddr->debug[28]);
91         out_be32(&ddr->debug[28], tmp | 0x0070006f);
92
93         udelay(500);
94
95         temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI);
96
97         out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg);
98 }
99
100 int dram_init(void)
101 {
102 #if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
103         ddrmc_init();
104 #endif
105
106         erratum_a008850_post();
107
108         gd->ram_size = DDR_SIZE;
109         return 0;
110 }
111
112 #ifdef CONFIG_TSEC_ENET
113 int board_eth_init(struct bd_info *bis)
114 {
115         struct fsl_pq_mdio_info mdio_info;
116         struct tsec_info_struct tsec_info[4];
117         int num = 0;
118
119 #ifdef CONFIG_TSEC1
120         SET_STD_TSEC_INFO(tsec_info[num], 1);
121         if (is_serdes_configured(SGMII_TSEC1)) {
122                 puts("eTSEC1 is in sgmii mode.\n");
123                 tsec_info[num].flags |= TSEC_SGMII;
124         }
125         num++;
126 #endif
127 #ifdef CONFIG_TSEC2
128         SET_STD_TSEC_INFO(tsec_info[num], 2);
129         if (is_serdes_configured(SGMII_TSEC2)) {
130                 puts("eTSEC2 is in sgmii mode.\n");
131                 tsec_info[num].flags |= TSEC_SGMII;
132         }
133         num++;
134 #endif
135         if (!num) {
136                 printf("No TSECs initialized\n");
137                 return 0;
138         }
139
140         mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
141         mdio_info.name = DEFAULT_MII_NAME;
142         fsl_pq_mdio_init(bis, &mdio_info);
143
144         tsec_eth_init(bis, tsec_info, num);
145
146         return pci_eth_init(bis);
147 }
148 #endif
149
150 int board_early_init_f(void)
151 {
152         struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
153
154 #ifdef CONFIG_TSEC_ENET
155         /* clear BD & FR bits for BE BD's and frame data */
156         clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
157         out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
158
159 #endif
160
161         arch_soc_init();
162
163         return 0;
164 }
165
166 #ifdef CONFIG_SPL_BUILD
167 void board_init_f(ulong dummy)
168 {
169         /* Clear the BSS */
170         memset(__bss_start, 0, __bss_end - __bss_start);
171
172         get_clocks();
173
174         preloader_console_init();
175
176         dram_init();
177
178         /* Allow OCRAM access permission as R/W */
179
180 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
181         enable_layerscape_ns_access();
182 #endif
183
184         board_init_r(NULL, 0);
185 }
186 #endif
187
188 int board_init(void)
189 {
190 #ifndef CONFIG_SYS_FSL_NO_SERDES
191         fsl_serdes_init();
192 #endif
193
194         ls102xa_smmu_stream_id_init();
195
196         return 0;
197 }
198
199 #ifdef CONFIG_BOARD_LATE_INIT
200 int board_late_init(void)
201 {
202         return 0;
203 }
204 #endif
205
206 #if defined(CONFIG_MISC_INIT_R)
207 int misc_init_r(void)
208 {
209 #ifdef CONFIG_FSL_DEVICE_DISABLE
210         device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
211
212 #endif
213         return 0;
214 }
215 #endif
216
217 int ft_board_setup(void *blob, struct bd_info *bd)
218 {
219         ft_cpu_setup(blob, bd);
220
221 #ifdef CONFIG_PCI
222         ft_pci_setup(blob, bd);
223 #endif
224
225         return 0;
226 }
227
228 void flash_write16(u16 val, void *addr)
229 {
230         u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
231
232         __raw_writew(shftval, addr);
233 }
234
235 u16 flash_read16(void *addr)
236 {
237         u16 val = __raw_readw(addr);
238
239         return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
240 }