blob: e11cfafaa5801f14bb3f068c1105be4a82f13dd0 [file] [log] [blame]
Christophe Leroy1fc46f52022-10-14 12:54:50 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2010-2020 CS Group
4 * Charles Frey <charles.frey@c-s.fr>
5 * Florent Trinh Thai <florent.trinh-thai@c-s.fr>
6 * Christophe Leroy <christophe.leroy@c-s.fr>
7 *
8 * Board specific routines for the CMPC885 board
9 */
10
11#include <env.h>
Christophe Leroy1fc46f52022-10-14 12:54:50 +020012#include <mpc8xx.h>
Christophe Leroyd99596d2023-05-03 09:25:10 +020013#include <asm/cpm_8xx.h>
Christophe Leroy1fc46f52022-10-14 12:54:50 +020014#include <asm/io.h>
15#include <dm.h>
16#include <stdio.h>
17#include <stdarg.h>
18#include <watchdog.h>
19#include <serial.h>
20#include <hang.h>
21#include <flash.h>
22#include <init.h>
23#include <fdt_support.h>
24#include <linux/delay.h>
Christophe Leroy1fc46f52022-10-14 12:54:50 +020025#include <spi.h>
26
Christophe Leroy2a45fb62023-04-04 12:42:15 +020027#include "../common/common.h"
28
Christophe Leroy1fc46f52022-10-14 12:54:50 +020029DECLARE_GLOBAL_DATA_PTR;
30
Christophe Leroy1fc46f52022-10-14 12:54:50 +020031#define ADDR_CPLD_R_RESET ((unsigned short __iomem *)CONFIG_CPLD_BASE)
32#define ADDR_CPLD_R_ETAT ((unsigned short __iomem *)(CONFIG_CPLD_BASE + 2))
33#define ADDR_CPLD_R_TYPE ((unsigned char __iomem *)(CONFIG_CPLD_BASE + 3))
34
Christophe Leroy9646af32023-01-30 09:07:38 +010035#define PATH_PHY2 "/soc@ff000000/mdio@e00/ethernet-phy@2"
36#define PATH_PHY3 "/soc@ff000000/mdio@e00/ethernet-phy@3"
37#define PATH_ETH1 "/soc@ff000000/ethernet@1e00"
38#define FIBER_PHY PATH_PHY2
Christophe Leroy1fc46f52022-10-14 12:54:50 +020039
Christophe Leroy1fc46f52022-10-14 12:54:50 +020040#define R_ETAT_PRES_BASE 0x0040
41
42#define R_RESET_STATUS 0x0400
43#define R_RST_STATUS 0x0004
44
45int ft_board_setup(void *blob, struct bd_info *bd)
46{
47 const char *sync = "receive";
48
49 ft_cpu_setup(blob, bd);
50
51 /* BRG */
Christophe Leroy9646af32023-01-30 09:07:38 +010052 do_fixup_by_path_u32(blob, "/soc/cpm", "brg-frequency", bd->bi_busfreq, 1);
53
Christophe Leroy1fc46f52022-10-14 12:54:50 +020054 /* MAC addr */
55 fdt_fixup_ethernet(blob);
56
57 /* Bus Frequency for CPM */
58 do_fixup_by_path_u32(blob, "/soc", "bus-frequency", bd->bi_busfreq, 1);
59
60 /* E1 interface - Set data rate */
61 do_fixup_by_path_u32(blob, "/localbus/e1", "data-rate", 2, 1);
62
63 /* E1 interface - Set channel phase to 0 */
64 do_fixup_by_path_u32(blob, "/localbus/e1", "channel-phase", 0, 1);
65
66 /* E1 interface - rising edge sync pulse transmit */
Christophe Leroy9646af32023-01-30 09:07:38 +010067 do_fixup_by_path(blob, "/localbus/e1", "rising-edge-sync-pulse", sync, strlen(sync), 1);
68
69 /* MIAE only */
Christophe Leroy452fd722023-04-05 18:50:23 +020070 if (!(in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE))
Christophe Leroy9646af32023-01-30 09:07:38 +010071 return 0;
72
Christophe Leroy452fd722023-04-05 18:50:23 +020073 return ft_board_setup_common(blob);
74}
Christophe Leroy9646af32023-01-30 09:07:38 +010075
Christophe Leroy452fd722023-04-05 18:50:23 +020076void ft_board_setup_phy3(void)
77{
78 /* switch to phy3 with gpio, we'll only use phy3 */
79 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
80 cpm8xx_t __iomem *cp = (cpm8xx_t __iomem *)&immr->im_cpm;
Christophe Leroy1fc46f52022-10-14 12:54:50 +020081
Christophe Leroy452fd722023-04-05 18:50:23 +020082 setbits_be32(&cp->cp_pedat, 0x00002000);
Christophe Leroy1fc46f52022-10-14 12:54:50 +020083}
84
85int checkboard(void)
86{
87 serial_puts("Board: ");
88
89 /* Is a motherboard present ? */
Christophe Leroy452fd722023-04-05 18:50:23 +020090 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE)
91 return checkboard_common();
Christophe Leroy9646af32023-01-30 09:07:38 +010092
Christophe Leroy452fd722023-04-05 18:50:23 +020093 printf("CMPC885 (CS GROUP)\n");
Christophe Leroy9646af32023-01-30 09:07:38 +010094
Christophe Leroy1fc46f52022-10-14 12:54:50 +020095 return 0;
96}
97
Christophe Leroy1fc46f52022-10-14 12:54:50 +020098#define MAX_SPI_BYTES 0x20
99
Christophe Leroyeefb4612023-04-05 16:05:36 +0200100#define EE_OFF_MAC1 0x10
101#define EE_OFF_MAC2 0x16
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200102
103/* Reads MAC addresses from SPI EEPROM */
104static int setup_mac(void)
105{
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200106 uchar din[MAX_SPI_BYTES];
Christophe Leroyeefb4612023-04-05 16:05:36 +0200107 int ret;
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200108 unsigned long ident = 0x08005120;
109
Christophe Leroyeefb4612023-04-05 16:05:36 +0200110 ret = read_eeprom(din, sizeof(din));
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200111 if (ret)
112 return ret;
113
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200114 if (memcmp(din + EE_OFF_MAC1, &ident, sizeof(ident)) == 0)
115 eth_env_set_enetaddr("ethaddr", din + EE_OFF_MAC1);
116
117 if (memcmp(din + EE_OFF_MAC2, &ident, sizeof(ident)) == 0)
118 eth_env_set_enetaddr("eth1addr", din + EE_OFF_MAC2);
119
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200120 return 0;
121}
122
123int misc_init_r(void)
124{
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200125 /* Verify mother board presence */
126 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
Christophe Leroy452fd722023-04-05 18:50:23 +0200127 misc_init_r_common();
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200128 } else {
Christophe Leroy452fd722023-04-05 18:50:23 +0200129 env_set("config", CFG_BOARD_CMPCXXX);
130 env_set("hostname", CFG_BOARD_CMPCXXX);
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200131 }
132
133 if (setup_mac())
134 printf("Error retrieving mac addresses\n");
135
136 /* Protection ON by default */
137 flash_protect(FLAG_PROTECT_SET, CFG_SYS_FLASH_BASE, 0xffffffff, &flash_info[0]);
138
139 return 0;
140}
141
Christophe Leroy452fd722023-04-05 18:50:23 +0200142void iop_setup_mcr(void)
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200143{
144 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
145 iop8xx_t __iomem *iop = &immr->im_ioport;
146 cpm8xx_t __iomem *cp = &immr->im_cpm;
147
148 /* Wait reset on FPGA_F */
149 udelay(100);
150
151 /* We must initialize data before changing direction */
152 setbits_be16(&iop->iop_pcdat, 0x088E);
153 setbits_be16(&iop->iop_pddat, 0x0001);
154 setbits_be32(&cp->cp_pbdat, 0x00029510);
155 setbits_be32(&cp->cp_pedat, 0x00000002);
156
157 /*
158 * PAPAR[13] = 0 [0x0004] -> GPIO: ()
159 * PAPAR[12] = 0 [0x0008] -> GPIO: ()
160 * PAPAR[9] = 1 [0x0040] -> GPIO: (PCM_IN_12_MPC)
161 * PAPAR[8] = 1 [0x0080] -> GPIO: (PCM_OUT_12_MPC)
162 * PAPAR[7] = 1 [0x0100] -> GPIO: (TDM_BCLK_MPC)
163 * PAPAR[6] = 1 [0x0200] -> GPIO: (CLK2)
164 */
165 clrsetbits_be16(&iop->iop_papar, 0x03CC, 0x03C0);
166
167 /*
168 * PBODR[16] = 1 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
169 */
170 setbits_be16(&cp->cp_pbodr, 0x00008000);
171
172 /*
173 * PBDIR[27] = 1 [0x00000010] -> GPIO: (WR_TEMP2)
174 * PBDIR[26] = 1 [0x00000020] -> GPIO: (BRG02)
175 * PBDIR[23] = 1 [0x00000100] -> GPIO: (CS_TEMP2)
176 * PBDIR[18] = 1 [0x00002000] -> GPIO: (RTS2)
177 * PBDIR[16] = 1 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
178 * PBDIR[15] = 1 [0x00010000] -> GPIO: (BRG03)
179 * PBDIR[14] = 1 [0x00020000] -> GPIO: (CS_TEMP)
180 */
181 setbits_be32(&cp->cp_pbdir, 0x0003A130);
182
183 /*
184 * PBPAR[20] = 1 [0x00000800] -> GPIO: (SMRXD2)
185 * PBPAR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
186 * PBPAR[16] = 0 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
187 */
188 clrsetbits_be32(&cp->cp_pbpar, 0x0000C800, 0x00000800);
189
190 /*
191 * PCPAR[14] = 0 [0x0002] -> GPIO: (CS_POT2)
192 */
193 clrbits_be16(&iop->iop_pcpar, 0x0002);
194
195 /*
196 * PDPAR[14] = 1 [0x0002] -> GPIO: (TDM_FS_MPC)
197 * PDPAR[11] = 1 [0x0010] -> GPIO: (RXD3)
198 * PDPAR[10] = 1 [0x0020] -> GPIO: (TXD3)
199 * PDPAR[9] = 1 [0x0040] -> GPIO: (TXD4)
200 * PDPAR[7] = 1 [0x0100] -> GPIO: (RTS3)
201 * PDPAR[5] = 1 [0x0400] -> GPIO: (CLK8)
202 * PDPAR[3] = 1 [0x1000] -> GPIO: (CLK7)
203 */
204 setbits_be16(&iop->iop_pdpar, 0x1572);
205
206 /*
207 * PEPAR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
208 * PEPAR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
209 * PEPAR[25] = 1 [0x00000040] -> GPIO: (RXD4)
210 * PEPAR[24] = 1 [0x00000080] -> GPIO: (BRG01)
211 * PEPAR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
212 * PEPAR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
213 * PEPAR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
214 * PEPAR[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
215 * PEPAR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
216 * PEPAR[17] = 1 [0x00004000] -> GPIO: (CLK5)
217 * PEPAR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
218 * PEPAR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
219 * PEPAR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
220 */
221 clrsetbits_be32(&cp->cp_pepar, 0x0003DFF0, 0x0003DEF0);
222
223 /*
224 * PADIR[9] = 1 [0x0040] -> GPIO: (PCM_IN_12_MPC)
225 * PADIR[8] = 1 [0x0080] -> GPIO: (PCM_OUT_12_MPC)
226 * PADIR[5] = 1 [0x0400] -> GPIO: ()
227 */
228 setbits_be16(&iop->iop_padir, 0x04C0);
229
230 /*
231 * PCDIR[15] = 1 [0x0001] -> GPIO: (WP_EEPROM2)
232 * PCDIR[14] = 1 [0x0002] -> GPIO: (CS_POT2)
233 * PCDIR[13] = 1 [0x0004] -> GPIO: (CS_POT1)
234 * PCDIR[12] = 1 [0x0008] -> GPIO: (CS_EEPROM2)
235 * PCDIR[8] = 1 [0x0080] -> GPIO: (CS_CODEC_FAV)
236 * PCDIR[4] = 1 [0x0800] -> GPIO: (CS_CODEC_RADIO)
237 */
238 setbits_be16(&iop->iop_pcdir, 0x088F);
239
240 /*
241 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
242 * PDDIR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO)
243 * PDDIR[2] = x [0x2000] -> Reserved
244 * PDDIR[1] = 0 [0x4000] -> ODR for PD10 : (TXD3)
245 * PDDIR[0] = 0 [0x8000] -> ODR for PD8 : (R_MDC)
246 */
247 clrsetbits_be16(&iop->iop_pddir, 0xC240, 0x0040);
248
249 /*
250 * PEDIR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
251 * PEDIR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
252 * PEDIR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
253 * PEDIR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
254 * PEDIR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
255 * PEDIR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
256 * PEDIR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
257 * PEDIR[18] = 1 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
258 * PEDIR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
259 * PEDIR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
260 * PEDIR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
261 */
262 clrsetbits_be32(&cp->cp_pedir, 0x0003B732, 0x0003B632);
263
264 /*
265 * PAODR[10] = 1 [0x0020] -> GPIO: (INIT_FPGA_F)
266 */
267 setbits_be16(&iop->iop_paodr, 0x0020); // set_bit
268
269 /*
270 * PEODR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
271 * PEODR[18] = 1 [0x00002000] -> GPIO: (FPGA_RADIO)
272 */
273 setbits_be32(&cp->cp_peodr, 0x00002002);
274
275 /*
276 * PESO[24] = 1 [0x00000080] -> GPIO: (BRG01)
277 * PESO[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
278 * PESO[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
279 * PESO[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
280 * PESO[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
281 * PESO[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
282 */
283 clrsetbits_be32(&cp->cp_peso, 0x00031980, 0x00031880);
284
285 /* Disable CS for device */
286 /* PROGFPGA down */
287 clrbits_be32(&cp->cp_pbdat, 0x00008000);
288
289 /* PROGFPGA down */
290 clrbits_be32(&cp->cp_pedat, 0x00002000);
291 udelay(1); /* Wait more than 300ns */
292
293 /*
294 * We do not set the PROG signal of the C4E1 because
295 * there is a conflic with the CS of the EEPROM.
296 * I don't know why there is not the same problem
297 * with the FPGA_R
298 */
299
300 /* PROGFPGA up */
301 setbits_be32(&cp->cp_pedat, 0x00002000);
302}
303
304static void iop_setup_cmpc885(void)
305{
306 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
307 iop8xx_t __iomem *iop = &immr->im_ioport;
308 cpm8xx_t __iomem *cp = &immr->im_cpm;
309
310 /* We must initialize data before changing direction */
311 out_be16(&iop->iop_pcdat, 0x0000);
312 out_be16(&iop->iop_pddat, 0x0001);
313
314 out_be32(&cp->cp_pbdat, 0x00021400);
315 out_be32(&cp->cp_pedat, 0x00000000);
316
317 /*
318 * PAPAR[13] = 0 [0x0004] -> GPIO: ()
319 * PAPAR[12] = 0 [0x0008] -> GPIO: ()
320 * PAPAR[9] = 0 [0x0040] -> GPIO: ()
321 * PAPAR[8] = 0 [0x0080] -> GPIO: ()
322 * PAPAR[7] = 0 [0x0100] -> GPIO: ()
323 * PAPAR[6] = 0 [0x0200] -> GPIO: ()
324 */
325 clrbits_be16(&iop->iop_papar, 0x03CC);
326
327 /*
328 * PBPAR[20] = 0 [0x00000800] -> GPIO: ()
329 * PBPAR[17] = 0 [0x00004000] -> GPIO: ()
330 * PBPAR[16] = 0 [0x00008000] -> GPIO: ()
331 */
332 clrbits_be32(&cp->cp_pbpar, 0x0000C800);
333
334 /*
335 * PCPAR[14] = 0 [0x0002] -> GPIO: ()
336 */
337 clrbits_be16(&iop->iop_pcpar, 0x0002);
338
339 /*
340 * PDPAR[14] = 0 [0x0002] -> GPIO: ()
341 * PDPAR[11] = 0 [0x0010] -> GPIO: ()
342 * PDPAR[10] = 0 [0x0020] -> GPIO: ()
343 * PDPAR[9] = 0 [0x0040] -> GPIO: ()
344 * PDPAR[7] = 0 [0x0100] -> GPIO: ()
345 * PDPAR[5] = 0 [0x0400] -> GPIO: ()
346 * PDPAR[3] = 0 [0x1000] -> GPIO: ()
347 */
348 clrbits_be16(&iop->iop_pdpar, 0x1572);
349
350 /*
351 * PEPAR[27] = 0 [0x00000010] -> GPIO: ()
352 * PEPAR[26] = 0 [0x00000020] -> GPIO: ()
353 * PEPAR[25] = 0 [0x00000040] -> GPIO: ()
354 * PEPAR[24] = 0 [0x00000080] -> GPIO: ()
355 * PEPAR[23] = 0 [0x00000100] -> GPIO: ()
356 * PEPAR[22] = 0 [0x00000200] -> GPIO: ()
357 * PEPAR[21] = 0 [0x00000400] -> GPIO: ()
358 * PEPAR[20] = 0 [0x00000800] -> GPIO: ()
359 * PEPAR[19] = 0 [0x00001000] -> GPIO: ()
360 * PEPAR[17] = 0 [0x00004000] -> GPIO: ()
361 * PEPAR[16] = 0 [0x00008000] -> GPIO: ()
362 * PEPAR[15] = 0 [0x00010000] -> GPIO: ()
363 * PEPAR[14] = 0 [0x00020000] -> GPIO: ()
364 */
365 clrbits_be32(&cp->cp_pepar, 0x0003DFF0);
366
367 /*
368 * PADIR[9] = 0 [0x0040] -> GPIO: ()
369 * PADIR[8] = 0 [0x0080] -> GPIO: ()
370 * PADIR[5] = 0 [0x0400] -> GPIO: ()
371 */
372 clrbits_be16(&iop->iop_padir, 0x04C0);
373
374 /*
375 * In/Out or per. Function 0/1
376 * PBDIR[27] = 0 [0x00000010] -> GPIO: ()
377 * PBDIR[26] = 0 [0x00000020] -> GPIO: ()
378 * PBDIR[23] = 0 [0x00000100] -> GPIO: ()
379 * PBDIR[17] = 0 [0x00004000] -> GPIO: ()
380 * PBDIR[16] = 0 [0x00008000] -> GPIO: ()
381 */
382 clrbits_be32(&cp->cp_pbdir, 0x0000C130);
383
384 /*
385 * PCDIR[15] = 0 [0x0001] -> GPIO: ()
386 * PCDIR[14] = 0 [0x0002] -> GPIO: ()
387 * PCDIR[13] = 0 [0x0004] -> GPIO: ()
388 * PCDIR[12] = 0 [0x0008] -> GPIO: ()
389 * PCDIR[8] = 0 [0x0080] -> GPIO: ()
390 * PCDIR[4] = 0 [0x0800] -> GPIO: ()
391 */
392 clrbits_be16(&iop->iop_pcdir, 0x088F);
393
394 /*
395 * PDDIR[9] = 0 [0x0040] -> GPIO: ()
396 * PDDIR[6] = 0 [0x0200] -> GPIO: ()
397 * PDDIR[2] = x [0x2000] -> Reserved
398 * PDDIR[1] = 0 [0x4000] -> ODR for PD10 : ()
399 * PDDIR[0] = 0 [0x8000] -> ODR for PD8 : (R_MDC)
400 */
401 clrbits_be16(&iop->iop_pddir, 0xC240);
402
403 /*
404 * PEDIR[30] = 0 [0x00000002] -> GPIO: ()
405 * PEDIR[27] = 0 [0x00000010] -> GPIO: ()
406 * PEDIR[26] = 0 [0x00000020] -> GPIO: ()
407 * PEDIR[23] = 0 [0x00000100] -> GPIO: ()
408 * PEDIR[22] = 0 [0x00000200] -> GPIO: ()
409 * PEDIR[21] = 0 [0x00000400] -> GPIO: ()
410 * PEDIR[19] = 0 [0x00001000] -> GPIO: ()
411 * PEDIR[18] = 0 [0x00002000] -> GPIO: ()
412 * PEDIR[16] = 0 [0x00008000] -> GPIO: ()
413 * PEDIR[15] = 0 [0x00010000] -> GPIO: ()
414 * PEDIR[14] = 0 [0x00020000] -> GPIO: ()
415 */
416 clrbits_be32(&cp->cp_pedir, 0x0003B732);
417
418 /*
419 * PAODR[10] = 0 [0x0020] -> GPIO: ()
420 */
421 clrbits_be16(&iop->iop_paodr, 0x0020);
422
423 /*
424 * PBODR[16] = 0 [0x00008000] -> GPIO: ()
425 */
426 clrbits_be16(&cp->cp_pbodr, 0x00008000);
427
428 /*
429 * PEODR[30] = 0 [0x00000002] -> GPIO: ()
430 * PEODR[18] = 0 [0x00002000] -> GPIO: ()
431 */
432 clrbits_be32(&cp->cp_peodr, 0x00002002);
433
434 /*
435 * PESO[24] = 0 [0x00000080] -> GPIO: ()
436 * PESO[23] = 0 [0x00000100] -> GPIO: ()
437 * PESO[20] = 0 [0x00000800] -> GPIO: ()
438 * PESO[19] = 0 [0x00001000] -> GPIO: ()
439 * PESO[15] = 0 [0x00010000] -> GPIO: ()
440 * PESO[14] = 0 [0x00020000] -> GPIO: ()
441 */
442 clrbits_be32(&cp->cp_peso, 0x00031980);
443}
444
Christophe Leroy452fd722023-04-05 18:50:23 +0200445void iop_setup_miae(void)
Christophe Leroy9646af32023-01-30 09:07:38 +0100446{
447 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
448 iop8xx_t __iomem *iop = &immr->im_ioport;
449 cpm8xx_t __iomem *cp = &immr->im_cpm;
450
451 /* Wait reset on FPGA_F */
452 udelay(100);
453
Christophe Leroyd99596d2023-05-03 09:25:10 +0200454 /* Load CPM relocation code */
455 cpm_load_patch(cp);
456
Christophe Leroy9646af32023-01-30 09:07:38 +0100457 /* Set the front panel LED color to red */
Christophe Leroy452fd722023-04-05 18:50:23 +0200458 clrbits_8((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x44, 0x02);
Christophe Leroy9646af32023-01-30 09:07:38 +0100459
460 /* We must initialize data before changing direction */
461 setbits_be16(&iop->iop_pcdat, 0x0888);
462 setbits_be16(&iop->iop_pddat, 0x0201);
463 setbits_be32(&cp->cp_pbdat, 0x00021510);
464 setbits_be32(&cp->cp_pedat, 0x00000002);
465
466 /*
467 * PAPAR[13] = 1 [0x0004] -> GPIO: (RXD2)
468 * PAPAR[12] = 1 [0x0008] -> GPIO: (TXD2)
469 * PAPAR[9] = 1 [0x0040] -> GPIO: (TDM1O)
470 * PAPAR[8] = 1 [0x0080] -> GPIO: (TDM1I)
471 * PAPAR[7] = 1 [0x0100] -> GPIO: (TDM_BCLK_MPC)
472 * PAPAR[6] = 1 [0x0200] -> GPIO: (CLK2)
473 */
474 setbits_be16(&iop->iop_papar, 0x03CC);
475
476 /*
477 * PBODR[16] = 0 [0x00008000] -> GPIO: (L1ST4)
478 */
479 clrbits_be16(&cp->cp_pbodr, 0x00008000);
480
481 /*
482 * PBDIR[27] = 1 [0x00000010] -> GPIO: (WR_TEMP2)
483 * PBDIR[26] = 1 [0x00000020] -> GPIO: (BRG02)
484 * PBDIR[23] = 1 [0x00000100] -> GPIO: (CS_TEMP2)
485 * PBDIR[18] = 1 [0x00002000] -> GPIO: (RTS2)
486 * PBDIR[16] = 0 [0x00008000] -> GPIO: (L1ST4)
487 * PBDIR[15] = 1 [0x00010000] -> GPIO: (BRG03)
488 * PBDIR[14] = 1 [0x00020000] -> GPIO: (CS_TEMP)
489 */
490 clrsetbits_be32(&cp->cp_pbdir, 0x0003A130, 0x00032130);
491
492 /*
493 * PBPAR[20] = 1 [0x00000800] -> GPIO: (SMRXD2)
494 * PBPAR[17] = 1 [0x00004000] -> GPIO: (L1ST3)
495 * PBPAR[16] = 1 [0x00008000] -> GPIO: (L1ST4)
496 */
497 setbits_be32(&cp->cp_pbpar, 0x0000C800);
498
499 /*
500 * PCPAR[14] = 1 [0x0002] -> GPIO: (L1ST2)
501 */
502 setbits_be16(&iop->iop_pcpar, 0x0002);
503
504 /*
505 * PDPAR[14] = 1 [0x0002] -> GPIO: (TDM_FS_MPC)
506 * PDPAR[11] = 1 [0x0010] -> GPIO: (RXD3)
507 * PDPAR[10] = 1 [0x0020] -> GPIO: (TXD3)
508 * PDPAR[9] = 1 [0x0040] -> GPIO: (TXD4)
509 * PDPAR[7] = 1 [0x0100] -> GPIO: (RTS3)
510 * PDPAR[5] = 1 [0x0400] -> GPIO: (CLK8)
511 * PDPAR[3] = 1 [0x1000] -> GPIO: (CLK7)
512 */
513 setbits_be16(&iop->iop_pdpar, 0x1572);
514
515 /*
516 * PEPAR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
517 * PEPAR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
518 * PEPAR[25] = 1 [0x00000040] -> GPIO: (RXD4)
519 * PEPAR[24] = 1 [0x00000080] -> GPIO: (BRG01)
520 * PEPAR[23] = 1 [0x00000100] -> GPIO: (L1ST1)
521 * PEPAR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
522 * PEPAR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
523 * PEPAR[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
524 * PEPAR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
525 * PEPAR[17] = 1 [0x00004000] -> GPIO: (CLK5)
526 * PEPAR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
527 * PEPAR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
528 * PEPAR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
529 */
530 setbits_be32(&cp->cp_pepar, 0x0003DFF0);
531
532 /*
533 * PADIR[9] = 1 [0x0040] -> GPIO: (TDM1O)
534 * PADIR[8] = 1 [0x0080] -> GPIO: (TDM1I)
535 * PADIR[5] = 0 [0x0400] -> GPIO: ()
536 */
537 clrsetbits_be16(&iop->iop_padir, 0x04C0, 0x00C0);
538
539 /*
540 * PCDIR[15] = 1 [0x0001] -> GPIO: (WP_EEPROM2)
541 * PCDIR[14] = 1 [0x0002] -> GPIO: (L1ST2)
542 * PCDIR[13] = 0 [0x0004] -> GPIO: ()
543 * PCDIR[12] = 1 [0x0008] -> GPIO: (CS_EEPROM2)
544 * PCDIR[8] = 1 [0x0080] -> GPIO: (CS_CODEC_2)
545 * PCDIR[4] = 1 [0x0800] -> GPIO: (CS_CODEC_1)
546 */
547 clrsetbits_be16(&iop->iop_pcdir, 0x088F, 0x088B);
548
549 /*
550 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
551 * PDDIR[6] = 1 [0x0200] -> GPIO: (CS_CODEC_3)
552 */
553 setbits_be16(&iop->iop_pddir, 0x0240);
554
555 /*
556 * PEDIR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
557 * PEDIR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
558 * PEDIR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
559 * PEDIR[23] = 1 [0x00000100] -> GPIO: (L1ST1)
560 * PEDIR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
561 * PEDIR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
562 * PEDIR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
563 * PEDIR[18] = 1 [0x00002000] -> GPIO: (PE18)
564 * PEDIR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
565 * PEDIR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
566 * PEDIR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
567 */
568 setbits_be32(&cp->cp_pedir, 0x0003B732);
569
570 /*
571 * PAODR[10] = 1 [0x0020] -> GPIO: (INIT_FPGA_F)
572 */
573 setbits_be16(&iop->iop_paodr, 0x0020);
574
575 /*
576 * PEODR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
577 * PEODR[18] = 0 [0x00002000] -> GPIO: (PE18)
578 */
579 clrsetbits_be32(&cp->cp_peodr, 0x00002002, 0x00000002);
580
581 /*
582 * PESO[24] = 1 [0x00000080] -> GPIO: (BRG01)
583 * PESO[23] = 1 [0x00000100] -> GPIO: (L1ST1)
584 * PESO[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
585 * PESO[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
586 * PESO[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
587 * PESO[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
588 */
589 setbits_be32(&cp->cp_peso, 0x00031980);
590}
591
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200592/* Specific board initialization */
Christophe Leroy105c56d2023-05-03 08:38:16 +0200593int board_early_init_f(void)
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200594{
595 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
596 iop8xx_t __iomem *iop = &immr->im_ioport;
597 cpm8xx_t __iomem *cp = &immr->im_cpm;
598
599 /* MPC885 Port settings common to all boards */
600 setbits_be16(&iop->iop_padat, 0x0000);
601
602 /* Port A (MPC885 reference manual - 34.2) */
603 /*
604 * In/Out or per. Function 0/1
605 * PADIR[15] = 0 [0x0001] -> GPIO: (USB_RXD)
606 * PADIR[14] = 0 [0x0002] -> GPIO: (USB_OE)
607 * PADIR[13] = 0 [0x0004] -> GPIO: ()
608 * PADIR[12] = 0 [0x0008] -> GPIO: ()
609 * PADIR[11] = 1 [0x0010] -> GPIO: (R1_TXD0)
610 * PADIR[10] = 0 [0x0020] -> GPIO: ()
611 * PADIR[7] = 0 [0x0100] -> GPIO: ()
612 * PADIR[6] = 0 [0x0200] -> GPIO: ()
613 * PADIR[4] = 1 [0x0800] -> GPIO: (R1_TXD1)
614 * PADIR[3] = 0 [0x1000] -> GPIO: (R1_RXER)
615 * PADIR[2] = 0 [0x2000] -> GPIO: (R1_CRS_DV)
616 * PADIR[1] = 0 [0x4000] -> GPIO: (R1_RXD0)
617 * PADIR[0] = 0 [0x8000] -> GPIO: (R1_RXD1)
618 */
619 clrsetbits_be16(&iop->iop_padir, 0xFB3F, 0x0810);
620
621 /*
622 * Open drain or active output
623 * PAODR[15] = x [0x0001]
624 * PAODR[14] = 0 [0x0002]
625 * PAODR[13] = x [0x0004]
626 * PAODR[12] = 0 [0x0008]
627 * PAODR[11] = 0 [0x0010]
628 * PAODR[9] = 0 [0x0040]
629 * PAODR[8] = 0 [0x0080]
630 * PAODR[7] = 0 [0x0100]
631 */
632 clrbits_be16(&iop->iop_paodr, 0x01DF);
633
634 /*
635 * GPIO or per. Function
636 * PAPAR[15] = 1 [0x0001] -> GPIO: (USB_RXD)
637 * PAPAR[14] = 1 [0x0002] -> GPIO: (USB_OE)
638 * PAPAR[11] = 1 [0x0010] -> GPIO: (R1_TXD0)
639 * PAPAR[10] = 0 [0x0020] -> GPIO: (INIT_FPGA_F)
640 * PAPAR[5] = 0 [0x0400] -> GPIO: ()
641 * PAPAR[4] = 1 [0x0800] -> GPIO: (R1_TXD1)
642 * PAPAR[3] = 1 [0x1000] -> GPIO: (R1_RXER)
643 * PAPAR[2] = 1 [0x2000] -> GPIO: (R1_CRS_DV)
644 * PAPAR[1] = 1 [0x4000] -> GPIO: (R1_RXD0)
645 * PAPAR[0] = 1 [0x8000] -> GPIO: (R1_RXD1)
646 */
647 clrsetbits_be16(&iop->iop_papar, 0xFC33, 0xF813);
648
649 /* Port B (MPC885 reference manual - 34.3) */
650 /*
651 * In/Out or per. Function 0/1
652 * PBDIR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK)
653 * PBDIR[30] = 1 [0x00000002] -> GPIO: (CLK)
654 * PBDIR[29] = 1 [0x00000004] -> GPIO: (MOSI)
655 * PBDIR[28] = 1 [0x00000008] -> GPIO: (MISO)
656 * PBDIR[25] = 0 [0x00000040] -> GPIO: (SMTXD1)
657 * PBDIR[24] = 0 [0x00000080] -> GPIO: (SMRXD1)
658 * PBDIR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
659 * PBDIR[21] = 1 [0x00000400] -> GPIO: (CS_EEPROM)
660 * PBDIR[20] = 0 [0x00000800] -> GPIO: (SMRXD2)
661 * PBDIR[19] = 1 [0x00001000] -> GPIO: (WR_TEMP)
662 * PBDIR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
663 */
664 clrsetbits_be32(&cp->cp_pbdir, 0x00005ECF, 0x0000140E);
665
666 /*
667 * Open drain or active output
668 * PBODR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK)
669 * PBODR[30] = 0 [0x00000002] -> GPIO: (CLK)
670 * PBODR[29] = 0 [0x00000004] -> GPIO: (MOSI)
671 * PBODR[28] = 0 [0x00000008] -> GPIO: (MISO)
672 * PBODR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2)
673 * PBODR[26] = 0 [0x00000020] -> GPIO: (BRG02)
674 * PBODR[25] = 0 [0x00000040] -> GPIO: (SMTXD1)
675 * PBODR[24] = 0 [0x00000080] -> GPIO: (SMRXD1)
676 * PBODR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2)
677 * PBODR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
678 * PBODR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM)
679 * PBODR[20] = 0 [0x00000800] -> GPIO: (SMRXD2)
680 * PBODR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP)
681 * PBODR[18] = 0 [0x00002000] -> GPIO: (RTS2)
682 * PBODR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
683 */
684 clrbits_be16(&cp->cp_pbodr, 0x00007FFF);
685
686 /*
687 * GPIO or per. Function
688 * PBPAR[31] = 1 [0x00000001] -> GPIO: (R1_REF_CLK)
689 * PBPAR[30] = 1 [0x00000002] -> GPIO: (CLK)
690 * PBPAR[29] = 1 [0x00000004] -> GPIO: (MOSI)
691 * PBPAR[28] = 1 [0x00000008] -> GPIO: (MISO)
692 * PBPAR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2)
693 * PBPAR[26] = 0 [0x00000020] -> GPIO: (BRG02)
694 * PBPAR[25] = 1 [0x00000040] -> GPIO: (SMTXD1)
695 * PBPAR[24] = 1 [0x00000080] -> GPIO: (SMRXD1)
696 * PBPAR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2)
697 * PBPAR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
698 * PBPAR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM)
699 * PBPAR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP)
700 * PBPAR[18] = 0 [0x00002000] -> GPIO: (RTS2)
701 * PBPAR[15] = 0 [0x00010000] -> GPIO: (BRG03)
702 * PBPAR[14] = 0 [0x00020000] -> GPIO: (CS_TEMP)
703 */
704 clrsetbits_be32(&cp->cp_pbpar, 0x000337FF, 0x000000CF);
705
706 /* Port C (MPC885 Reference Manual - 34.4) */
707 /*
708 * In/Out or per. Function 0/1
709 * PCDIR[11] = 0 [0x0010] -> GPIO: (USB_RXP)
710 * PCDIR[10] = 0 [0x0020] -> GPIO: (USB_RXN)
711 * PCDIR[9] = 0 [0x0040] -> GPIO: (CTS2)
712 * PCDIR[7] = 1 [0x0100] -> GPIO: (USB_TXP)
713 * PCDIR[6] = 1 [0x0200] -> GPIO: (USB_TXN)
714 * PCDIR[5] = 0 [0x0400] -> GPIO: (CTS3)
715 */
716 clrsetbits_be16(&iop->iop_pcdir, 0x0770, 0x0300);
717
718 /*
719 * GPIO or per. Function
720 * PCPAR[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2)
721 * PCPAR[13] = 0 [0x0004] -> GPIO: (CS_POT1)
722 * PCPAR[12] = 0 [0x0008] -> GPIO: (CS_EEPROM2)
723 * PCPAR[11] = 0 [0x0010] -> GPIO: (USB_RXP)
724 * PCPAR[10] = 0 [0x0020] -> GPIO: (USB_RXN)
725 * PCPAR[9] = 0 [0x0040] -> GPIO: (CTS2)
726 * PCPAR[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV)
727 * PCPAR[7] = 1 [0x0100] -> GPIO: (USB_TXP)
728 * PCPAR[6] = 1 [0x0200] -> GPIO: (USB_TXN)
729 * PCPAR[5] = 0 [0x0400] -> GPIO: (CTS3)
730 * PCPAR[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO)
731 */
732 clrsetbits_be16(&iop->iop_pcpar, 0x0FFD, 0x0300);
733
734 /*
735 * Special Option register
736 * PCSO[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2)
737 * PCSO[14] = 0 [0x0002] -> GPIO: (CS_POT2)
738 * PCSO[13] = x [0x0004] -> Reserved
739 * PCSO[12] = x [0x0008] -> Reserved
740 * PCSO[11] = 1 [0x0010] -> GPIO: (USB_RXP)
741 * PCSO[10] = 1 [0x0020] -> GPIO: (USB_RXN)
742 * PCSO[9] = 1 [0x0040] -> GPIO: (CTS2)
743 * PCSO[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV)
744 * PCSO[7] = 0 [0x0100] -> GPIO: (USB_TXP)
745 * PCSO[6] = 0 [0x0200] -> GPIO: (USB_TXN)
746 * PCSO[5] = 1 [0x0400] -> GPIO: (CTS3)
747 * PCSO[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO)
748 */
749 clrsetbits_be16(&iop->iop_pcso, 0x0FF3, 0x0470);
750
751 /*
752 * Interrupt or IO
753 * PCINT[15] = 0 [0x0001] -> GPIO: ()
754 * PCINT[14] = 0 [0x0002] -> GPIO: ()
755 * PCINT[13] = 0 [0x0004] -> GPIO: ()
756 * PCINT[12] = 0 [0x0008] -> GPIO: ()
757 * PCINT[11] = 0 [0x0010] -> GPIO: (USB_RXP)
758 * PCINT[10] = 0 [0x0020] -> GPIO: (USB_RXN)
759 * PCINT[9] = 0 [0x0040] -> GPIO: ()
760 * PCINT[8] = 0 [0x0080] -> GPIO: ()
761 * PCINT[7] = 0 [0x0100] -> GPIO: (USB_TXP)
762 * PCINT[6] = 0 [0x0200] -> GPIO: (USB_TXN)
763 * PCINT[5] = 0 [0x0400] -> GPIO: ()
764 * PCINT[4] = 0 [0x0800] -> GPIO: ()
765 */
766 clrbits_be16(&iop->iop_pcint, 0x0FFF);
767
768 /* Port D (MPC885 Reference Manual - 34.5) */
769 /*
770 * In/Out or per. Function 0/1
771 * PDDIR[15] = 1 [0x0001] -> GPIO: (CS_NAND)
772 * PDDIR[14] = 0 [0x0002] -> GPIO: (TDM_FS_MPC)
773 * PDDIR[13] = 1 [0x0004] -> GPIO: (ALE_NAND)
774 * PDDIR[12] = 1 [0x0008] -> GPIO: (CLE_NAND)
775 * PDDIR[11] = 0 [0x0010] -> GPIO: (RXD3)
776 * PDDIR[10] = 0 [0x0020] -> GPIO: (TXD3)
777 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
778 * PDDIR[8] = 0 [0x0080] -> GPIO: (R_MDC)
779 * PDDIR[7] = 0 [0x0100] -> GPIO: (RTS3)
780 * PDDIR[5] = 0 [0x0400] -> GPIO: (CLK8)
781 * PDDIR[4] = 0 [0x0800] -> GPIO: (CLK4)
782 * PDDIR[3] = 0 [0x1000] -> GPIO: (CLK7)
783 */
784 clrsetbits_be16(&iop->iop_pddir, 0x1DFF, 0x004D);
785
786 /*
787 * GPIO or per. Function
788 * PDPAR[15] = 0 [0x0001] -> GPIO: (CS_NAND)
789 * PDPAR[13] = 0 [0x0004] -> GPIO: (ALE_NAND)
790 * PDPAR[12] = 0 [0x0008] -> GPIO: (CLE_NAND)
791 * PDPAR[8] = 1 [0x0080] -> GPIO: (R_MDC)
792 * PDPAR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO)
793 * PDPAR[4] = 1 [0x0800] -> GPIO: (CLK4)
794 */
795 clrsetbits_be16(&iop->iop_pdpar, 0x0A8D, 0x0880);
796
797 /* Port E (MPC885 Reference Manual - 34.6) */
798 /*
799 * In/Out or per. Function 0/1
800 * PEDIR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
801 * PEDIR[29] = 1 [0x00000004] -> GPIO: (USB_SPEED)
802 * PEDIR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND)
803 * PEDIR[25] = 0 [0x00000040] -> GPIO: (RXD4)
804 * PEDIR[24] = 0 [0x00000080] -> GPIO: (BRG01)
805 * PEDIR[20] = 0 [0x00000800] -> GPIO: (SMTXD2)
806 * PEDIR[17] = 0 [0x00004000] -> GPIO: (CLK5)
807 */
808 clrsetbits_be32(&cp->cp_pedir, 0x000048CD, 0x0000000C);
809
810 /*
811 * open drain or active output
812 * PEODR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
813 * PEODR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
814 * PEODR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND)
815 * PEODR[27] = 0 [0x00000010] -> GPIO: (R2_RXER)
816 * PEODR[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV)
817 * PEODR[25] = 0 [0x00000040] -> GPIO: (RXD4)
818 * PEODR[24] = 0 [0x00000080] -> GPIO: (BRG01)
819 * PEODR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
820 * PEODR[22] = 0 [0x00000200] -> GPIO: (R2_RXD1)
821 * PEODR[21] = 0 [0x00000400] -> GPIO: (R2_RXD0)
822 * PEODR[20] = 0 [0x00000800] -> GPIO: (SMTXD2)
823 * PEODR[19] = 0 [0x00001000] -> GPIO: (R2_TXEN)
824 * PEODR[17] = 0 [0x00004000] -> GPIO: (CLK5)
825 * PEODR[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK)
826 */
827 clrsetbits_be32(&cp->cp_peodr, 0x0000DFFD, 0x00000008);
828
829 /*
830 * GPIO or per. Function
831 * PEPAR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
832 * PEPAR[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE)
833 * PEPAR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
834 * PEPAR[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND)
835 * PEPAR[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
836 */
837 clrbits_be32(&cp->cp_pepar, 0x0000200F);
838
839 /*
840 * Special Option register
841 * PESO[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
842 * PESO[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE)
843 * PESO[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
844 * PESO[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND)
845 * PESO[27] = 0 [0x00000010] -> GPIO: (R2_RXER)
846 * PESO[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV)
847 * PESO[25] = 0 [0x00000040] -> GPIO: (RXD4)
848 * PESO[22] = 0 [0x00000200] -> GPIO: (R2_RXD1)
849 * PESO[21] = 0 [0x00000400] -> GPIO: (R2_RXD0)
850 * PESO[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
851 * PESO[17] = 0 [0x00004000] -> GPIO: (CLK5)
852 * PESO[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK)
853 */
854 clrbits_be32(&cp->cp_peso, 0x0000E67F);
855
856 /* Is a motherboard present ? */
857 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
858 /* Initialize signal PROG_FPGA_FIRMWARE */
859 out_be32(&cp->cp_pedat, 0x00000002);
860 out_be32(&cp->cp_peodr, 0x00000002);
861 out_be32(&cp->cp_pedir, 0x00000002);
862
863 /* Check if fpga firmware is loaded */
864 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200865 /* Load fpga firmware */
866 /* Activate PROG_FPGA_FIRMWARE for 1 usec */
867 clrbits_be32(&cp->cp_pedat, 0x00000002);
868 udelay(1);
869 setbits_be32(&cp->cp_pedat, 0x00000002);
870
871 /* Wait 200 msec and check DONE_FPGA_FIRMWARE */
872 mdelay(200);
Christophe Leroy105c56d2023-05-03 08:38:16 +0200873 if (!(in_be32(&cp->cp_pedat) & 0x00000001))
874 hang();
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200875
876 /* Send a reset signal and wait for 20 msec */
877 clrbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS);
878 mdelay(20);
879 setbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS);
880 }
881
882 /* Wait 300 msec and check the reset state */
883 mdelay(300);
Christophe Leroy105c56d2023-05-03 08:38:16 +0200884 if (!(in_be16(ADDR_CPLD_R_RESET) & R_RESET_STATUS))
885 hang();
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200886
Christophe Leroy452fd722023-04-05 18:50:23 +0200887 iop_setup_common();
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200888 } else {
889 iop_setup_cmpc885();
890 }
891
892 return 0;
893}