1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2006-2023 CS GROUP France
10 #include <env_internal.h>
12 #include <fdt_support.h>
21 #include <linux/delay.h>
22 #include <linux/immap_qe.h>
23 #include <linux/libfdt.h>
24 #include <linux/log2.h>
25 #include <linux/sizes.h>
28 #include <asm/global_data.h>
31 #include <u-boot/crc.h>
33 #include "../common/common.h"
35 DECLARE_GLOBAL_DATA_PTR;
37 #define ADDR_FPGA_BASE ((unsigned char __iomem *)CONFIG_CPLD_BASE)
38 #define ADDR_FPGA_RESET_G (ADDR_FPGA_BASE + 0x40)
39 #define ADDR_FPGA_REG_ETAT (ADDR_FPGA_BASE + 0x42)
41 #define R_ETAT_PRES_BASE 0x01
42 #define RESET_G_OK 0x08
44 /* SPI EEPROM parameters */
45 #define MAX_SPI_BYTES 0x28
46 #define EE_OFF_MAC1 0x10
47 #define EE_OFF_MAC2 0x16
48 #define EE_OFF_MAC3 0x1C
50 static uint upma_table[] = {
51 /* Read Single-Beat (RSS) */
52 0x00AC0C00, 0x00FC1C40, 0x30FCE045, 0xFFFF0C00,
53 0x00000000, 0x00000000, 0x00000000, 0x00000000,
54 /* Read Burst (RBS) */
55 0x00000000, 0x00000000, 0x00000000, 0x00000000,
56 0x00000000, 0x00000000, 0x00000000, 0x00000000,
57 0x00000000, 0x00000000, 0x00000000, 0x00000000,
58 0x00000000, 0x00000000, 0x00000000, 0x00000000,
59 /* Write Single-Beat (WSS) */
60 0x00A30C00, 0x00F31C40, 0x3FF3C045, 0xFFFF0C00,
61 0x00000000, 0x00000000, 0x00000000, 0x00000000,
62 /* Write Burst (WBS) */
63 0x00000000, 0x00000000, 0x00000000, 0x00000000,
64 0x00000000, 0x00000000, 0x00000000, 0x00000000,
65 0x00000000, 0x00000000, 0x00000000, 0x00000000,
66 0x00000000, 0x00000000, 0x00000000, 0x00000000,
67 /* Refresh Timer (RTS) */
68 0x00000000, 0x00000000, 0x00000000, 0x00000000,
69 0x00000000, 0x00000000, 0x00000000, 0x00000000,
70 0x00000000, 0x00000000, 0x00000000, 0x00000000,
71 /* Exception Condition (EXS) */
72 0xFFFF0C01, 0xFFFF0C01, 0xFFFF0C01, 0xFFFF0C01,
75 const qe_iop_conf_t qe_iop_conf_tab[] = {
77 {1, 0, 1, 0, 1}, /* TxD0 */
78 {1, 1, 1, 0, 1}, /* TxD1 */
79 {1, 2, 1, 0, 1}, /* TxD2 */
80 {1, 3, 1, 0, 1}, /* TxD3 */
81 {1, 9, 1, 0, 1}, /* TxER */
82 {1, 12, 1, 0, 1}, /* TxEN */
83 {3, 24, 2, 0, 1}, /* TxCLK->CLK10 */
85 {1, 4, 2, 0, 1}, /* RxD0 */
86 {1, 5, 2, 0, 1}, /* RxD1 */
87 {1, 6, 2, 0, 1}, /* RxD2 */
88 {1, 7, 2, 0, 1}, /* RxD3 */
89 {1, 8, 2, 0, 1}, /* RxER */
90 {1, 10, 2, 0, 1}, /* RxDV */
91 {0, 13, 2, 0, 1}, /* RxCLK->CLK9 */
92 {1, 11, 2, 0, 1}, /* COL */
93 {1, 13, 2, 0, 1}, /* CRS */
96 {1, 18, 1, 0, 1}, /* TxD0 */
97 {1, 19, 1, 0, 1}, /* TxD1 */
98 {1, 20, 1, 0, 1}, /* TxD2 */
99 {1, 21, 1, 0, 1}, /* TxD3 */
100 {1, 27, 1, 0, 1}, /* TxER */
101 {1, 30, 1, 0, 1}, /* TxEN */
102 {3, 6, 2, 0, 1}, /* TxCLK->CLK8 */
104 {1, 22, 2, 0, 1}, /* RxD0 */
105 {1, 23, 2, 0, 1}, /* RxD1 */
106 {1, 24, 2, 0, 1}, /* RxD2 */
107 {1, 25, 2, 0, 1}, /* RxD3 */
108 {1, 26, 1, 0, 1}, /* RxER */
109 {1, 28, 2, 0, 1}, /* Rx_DV */
110 {3, 31, 2, 0, 1}, /* RxCLK->CLK7 */
111 {1, 29, 2, 0, 1}, /* COL */
112 {1, 31, 2, 0, 1}, /* CRS */
114 {3, 4, 3, 0, 2}, /* MDIO */
115 {3, 5, 1, 0, 2}, /* MDC */
117 {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
120 void iop_setup_miae(void)
122 immap_t __iomem *im = (immap_t *)CONFIG_SYS_IMMR;
124 /* PORTA configuration */
125 out_be32(&im->qepio.ioport[0].pdat, 0x00808000);
126 out_be32(&im->qepio.ioport[0].podr, 0x00008000);
127 out_be32(&im->qepio.ioport[0].dir1, 0x40800968);
128 out_be32(&im->qepio.ioport[0].dir2, 0x650A0896);
129 out_be32(&im->qepio.ioport[0].ppar1, 0x40400204);
130 out_be32(&im->qepio.ioport[0].ppar2, 0x05050464);
132 /* PORTB configuration */
133 out_be32(&im->qepio.ioport[1].pdat, 0x00018000);
134 out_be32(&im->qepio.ioport[1].podr, 0x00000000);
135 out_be32(&im->qepio.ioport[1].dir1, 0x50A08949);
136 out_be32(&im->qepio.ioport[1].dir2, 0x5C0C6890);
137 out_be32(&im->qepio.ioport[1].ppar1, 0x50504644);
138 out_be32(&im->qepio.ioport[1].ppar2, 0x080800A0);
140 /* PORTC configuration */
141 out_be32(&im->qepio.ioport[2].pdat, 0x3D000108);
142 out_be32(&im->qepio.ioport[2].podr, 0x00000000);
143 out_be32(&im->qepio.ioport[2].dir1, 0x45518000);
144 out_be32(&im->qepio.ioport[2].dir2, 0xA8119561);
145 out_be32(&im->qepio.ioport[2].ppar1, 0x80008000);
146 out_be32(&im->qepio.ioport[2].ppar2, 0x00000000);
148 /* PORTD configuration */
149 out_be32(&im->qepio.ioport[3].pdat, 0x1000E000);
150 out_be32(&im->qepio.ioport[3].podr, 0x0000E000);
151 out_be32(&im->qepio.ioport[3].dir1, 0xFDD20800);
152 out_be32(&im->qepio.ioport[3].dir2, 0x54155228);
153 out_be32(&im->qepio.ioport[3].ppar1, 0x54A30C00);
154 out_be32(&im->qepio.ioport[3].ppar2, 0x00000100);
157 void iop_setup_mcr(void)
159 immap_t __iomem *im = (immap_t *)CONFIG_SYS_IMMR;
161 /* PORTA configuration */
162 out_be32(&im->qepio.ioport[0].pdat, 0x00808004);
163 out_be32(&im->qepio.ioport[0].podr, 0x00000000);
164 out_be32(&im->qepio.ioport[0].dir1, 0x40800A68);
165 out_be32(&im->qepio.ioport[0].dir2, 0x650A0896);
166 out_be32(&im->qepio.ioport[0].ppar1, 0x40400004);
167 out_be32(&im->qepio.ioport[0].ppar2, 0x05050444);
169 /* PORTB configuration */
170 out_be32(&im->qepio.ioport[1].pdat, 0x00008000);
171 out_be32(&im->qepio.ioport[1].podr, 0x00000004);
172 out_be32(&im->qepio.ioport[1].dir1, 0x50A08A4A);
173 out_be32(&im->qepio.ioport[1].dir2, 0x5C0C6890);
174 out_be32(&im->qepio.ioport[1].ppar1, 0x50504444);
175 out_be32(&im->qepio.ioport[1].ppar2, 0x08080080);
177 /* PORTC configuration */
178 out_be32(&im->qepio.ioport[2].pdat, 0x3D000018);
179 out_be32(&im->qepio.ioport[2].podr, 0x00000400);
180 out_be32(&im->qepio.ioport[2].dir1, 0x45518000);
181 out_be32(&im->qepio.ioport[2].dir2, 0xA8129561);
182 out_be32(&im->qepio.ioport[2].ppar1, 0x80008000);
183 out_be32(&im->qepio.ioport[2].ppar2, 0x00000000);
185 /* PORTD configuration */
186 out_be32(&im->qepio.ioport[3].pdat, 0x1000E000);
187 out_be32(&im->qepio.ioport[3].podr, 0x0000E000);
188 out_be32(&im->qepio.ioport[3].dir1, 0xFDD20800);
189 out_be32(&im->qepio.ioport[3].dir2, 0x54155228);
190 out_be32(&im->qepio.ioport[3].ppar1, 0x54A30C00);
191 out_be32(&im->qepio.ioport[3].ppar2, 0x00000100);
194 static void iop_setup_cmpcpro(void)
196 immap_t __iomem *im = (immap_t *)CONFIG_SYS_IMMR;
198 /* PORTA configuration */
199 out_be32(&im->qepio.ioport[0].pdat, 0x00000000);
200 out_be32(&im->qepio.ioport[0].podr, 0x00000000);
201 out_be32(&im->qepio.ioport[0].dir1, 0x50A84020);
202 out_be32(&im->qepio.ioport[0].dir2, 0x00000000);
203 out_be32(&im->qepio.ioport[0].ppar1, 0xF0FCC000);
204 out_be32(&im->qepio.ioport[0].ppar2, 0x00000000);
206 /* PORTB configuration */
207 out_be32(&im->qepio.ioport[1].pdat, 0x00000000);
208 out_be32(&im->qepio.ioport[1].podr, 0x00000000);
209 out_be32(&im->qepio.ioport[1].dir1, 0x00000000);
210 out_be32(&im->qepio.ioport[1].dir2, 0x00006800);
211 out_be32(&im->qepio.ioport[1].ppar1, 0x00000000);
212 out_be32(&im->qepio.ioport[1].ppar2, 0x00000000);
214 /* PORTC configuration */
215 out_be32(&im->qepio.ioport[2].pdat, 0x19000000);
216 out_be32(&im->qepio.ioport[2].podr, 0x00000000);
217 out_be32(&im->qepio.ioport[2].dir1, 0x01410000);
218 out_be32(&im->qepio.ioport[2].dir2, 0xA8009400);
219 out_be32(&im->qepio.ioport[2].ppar1, 0x00000000);
220 out_be32(&im->qepio.ioport[2].ppar2, 0x00000000);
222 /* PORTD configuration */
223 out_be32(&im->qepio.ioport[3].pdat, 0x1000E000);
224 out_be32(&im->qepio.ioport[3].podr, 0x0000E000);
225 out_be32(&im->qepio.ioport[3].dir1, 0xFD020000);
226 out_be32(&im->qepio.ioport[3].dir2, 0x54055000);
227 out_be32(&im->qepio.ioport[3].ppar1, 0x54030000);
228 out_be32(&im->qepio.ioport[3].ppar2, 0x00000000);
231 int board_early_init_r(void)
233 immap_t __iomem *im = (immap_t *)CONFIG_SYS_IMMR;
234 fsl_lbc_t *lbus = &im->im_lbc;
236 upmconfig(UPMA, upma_table, ARRAY_SIZE(upma_table));
238 out_be32(&lbus->mamr, 0x00044440);
240 /* configure LBCR register */
241 out_be32(&lbus->lbcr, 0x00000500);
244 if (in_8(ADDR_FPGA_REG_ETAT) & R_ETAT_PRES_BASE) {
247 /* Initialize signal PROG_FPGA_FIRMWARE */
248 setbits_be32(&im->qepio.ioport[0].pdat, 0x00008000);
249 setbits_be32(&im->qepio.ioport[0].dir2, 0x60000002);
250 setbits_be32(&im->qepio.ioport[0].podr, 0x00008000);
254 /* Now read CPDATA[31] to check if FPGA is loaded */
255 if (!in_be32(&im->qepio.ioport[0].pdat) & 0x00000001) {
256 printf("Reloading FPGA firmware.\n");
258 clrbits_be32(&im->qepio.ioport[0].pdat, 0x00008000);
260 setbits_be32(&im->qepio.ioport[0].pdat, 0x00008000);
262 /* Wait 200 msec and check DONE_FPGA_FIRMWARE */
264 if (!(in_be32(&im->qepio.ioport[0].pdat) & 0x00000001)) {
266 printf("error loading firmware.\n");
271 /* Send a reset signal and wait for 20 msec */
272 out_8(ADDR_FPGA_RESET_G, in_8(ADDR_FPGA_RESET_G) | RESET_G_OK);
274 out_8(ADDR_FPGA_RESET_G, in_8(ADDR_FPGA_RESET_G) & ~RESET_G_OK);
277 /* Wait 300 msec and check the reset state */
279 for (i = 0; !(in_8(ADDR_FPGA_REG_ETAT) & RESET_G_OK); i++) {
281 printf("Could not reset FPGA.\n");
288 /* clocks configuration */
289 out_be32(&qe_immr->qmx.cmxsi1cr_l, 0x00040004);
290 out_be32(&qe_immr->qmx.cmxsi1syr, 0x00000000);
298 int dram_init(int board_type)
300 immap_t __iomem *im = (immap_t __iomem *)CONFIG_SYS_IMMR;
302 out_be32(&im->sysconf.ddrlaw[0].bar, CFG_SYS_DDR_SDRAM_BASE & LAWBAR_BAR);
303 out_be32(&im->sysconf.ddrlaw[0].ar, LAWAR_EN | ((ilog2(SZ_512M) - 1) & LAWAR_SIZE));
305 out_be32(&im->ddr.sdram_clk_cntl, CFG_SYS_DDR_CLK_CNTL);
306 out_be32(&im->ddr.csbnds[0].csbnds, CFG_SYS_DDR_CS0_BNDS);
307 out_be32(&im->ddr.cs_config[0], CFG_SYS_DDR_CS0_CONFIG);
309 out_be32(&im->ddr.timing_cfg_0, CFG_SYS_DDR_TIMING_0);
310 out_be32(&im->ddr.timing_cfg_1, CFG_SYS_DDR_TIMING_1);
311 out_be32(&im->ddr.timing_cfg_2, CFG_SYS_DDR_TIMING_2);
312 out_be32(&im->ddr.timing_cfg_3, CFG_SYS_DDR_TIMING_3);
313 out_be32(&im->ddr.sdram_cfg, CFG_SYS_DDR_SDRAM_CFG);
314 out_be32(&im->ddr.sdram_cfg2, CFG_SYS_DDR_SDRAM_CFG2);
315 out_be32(&im->ddr.sdram_mode, CFG_SYS_DDR_MODE);
316 out_be32(&im->ddr.sdram_mode2, CFG_SYS_DDR_MODE2);
317 out_be32(&im->ddr.sdram_interval, CFG_SYS_DDR_INTERVAL);
320 setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
322 gd->ram_size = SZ_512M;
331 /* Is a motherboard present ? */
332 if (in_8(ADDR_FPGA_REG_ETAT) & R_ETAT_PRES_BASE)
333 return checkboard_common();
335 printf("CMPCPRO (CS GROUP)\n");
340 /* Reads MAC addresses from SPI EEPROM */
341 static int setup_mac(void)
343 uchar din[MAX_SPI_BYTES];
345 unsigned long ident = 0x08005120;
347 ret = read_eeprom(din, sizeof(din));
351 if (memcmp(din + EE_OFF_MAC1, &ident, sizeof(ident)) == 0) {
352 eth_env_set_enetaddr("ethaddr", din + EE_OFF_MAC1);
353 eth_env_set_enetaddr("eth3addr", din + EE_OFF_MAC1);
356 if (memcmp(din + EE_OFF_MAC2, &ident, sizeof(ident)) == 0)
357 eth_env_set_enetaddr("eth1addr", din + EE_OFF_MAC2);
359 if (memcmp(din + EE_OFF_MAC3, &ident, sizeof(ident)) == 0)
360 eth_env_set_enetaddr("eth2addr", din + EE_OFF_MAC3);
365 int misc_init_r(void)
367 /* we do not modify environment variable area if CRC is false */
368 /* Verify if mother board is present */
369 if (in_8(ADDR_FPGA_REG_ETAT) & R_ETAT_PRES_BASE) {
370 misc_init_r_common();
372 env_set("config", CFG_BOARD_CMPCXXX);
373 env_set("hostname", CFG_BOARD_CMPCXXX);
377 printf("Error retrieving mac addresses\n");
382 int ft_board_setup(void *blob, struct bd_info *bd)
384 ft_cpu_setup(blob, bd);
387 if (!(in_8(ADDR_FPGA_REG_ETAT) & R_ETAT_PRES_BASE))
390 return ft_board_setup_common(blob);
393 void ft_board_setup_phy3(void)
395 /* switch to phy3 with gpio, we'll only use phy3 */
396 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
398 setbits_be32(&immr->qepio.ioport[2].pdat, 0x00000400);
401 #define ADDR_FPGA_R_BASE ((unsigned char __iomem *)CONFIG_FPGA_BASE)
402 #define ADDR_FPGA_R_ALARMES_IN ((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x31)
403 #define ADDR_FPGA_R_FAV ((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x44)