blob: 689d573075b31cca368308f5955431b802e16363 [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>
12#include <common.h>
13#include <mpc8xx.h>
14#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
31#define BOARD_CMPC885 "cmpc885"
32#define BOARD_MCR3000_2G "mcr3k_2g"
Christophe Leroy9646af32023-01-30 09:07:38 +010033#define BOARD_VGOIP "vgoip"
34#define BOARD_MIAE "miae"
Christophe Leroy1fc46f52022-10-14 12:54:50 +020035
36#define TYPE_MCR 0x22
Christophe Leroy9646af32023-01-30 09:07:38 +010037#define TYPE_MIAE 0x23
38
39#define FAR_CASRSA 2
40#define FAR_VGOIP 4
41#define FAV_CLA 7
42#define FAV_SRSA 8
Christophe Leroy1fc46f52022-10-14 12:54:50 +020043
44#define ADDR_CPLD_R_RESET ((unsigned short __iomem *)CONFIG_CPLD_BASE)
45#define ADDR_CPLD_R_ETAT ((unsigned short __iomem *)(CONFIG_CPLD_BASE + 2))
46#define ADDR_CPLD_R_TYPE ((unsigned char __iomem *)(CONFIG_CPLD_BASE + 3))
47
48#define ADDR_FPGA_R_BASE ((unsigned char __iomem *)CONFIG_FPGA_BASE)
49#define ADDR_FPGA_R_ALARMES_IN ((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x31)
Christophe Leroy9646af32023-01-30 09:07:38 +010050#define ADDR_FPGA_R_FAV ((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x44)
51
52#define PATH_PHY2 "/soc@ff000000/mdio@e00/ethernet-phy@2"
53#define PATH_PHY3 "/soc@ff000000/mdio@e00/ethernet-phy@3"
54#define PATH_ETH1 "/soc@ff000000/ethernet@1e00"
55#define FIBER_PHY PATH_PHY2
Christophe Leroy1fc46f52022-10-14 12:54:50 +020056
57#define FPGA_R_ACQ_AL_FAV 0x04
58#define R_ETAT_PRES_BASE 0x0040
59
60#define R_RESET_STATUS 0x0400
61#define R_RST_STATUS 0x0004
62
63int ft_board_setup(void *blob, struct bd_info *bd)
64{
Christophe Leroy9646af32023-01-30 09:07:38 +010065 u8 fav_id, far_id;
66
Christophe Leroy1fc46f52022-10-14 12:54:50 +020067 const char *sync = "receive";
68
69 ft_cpu_setup(blob, bd);
70
71 /* BRG */
Christophe Leroy9646af32023-01-30 09:07:38 +010072 do_fixup_by_path_u32(blob, "/soc/cpm", "brg-frequency", bd->bi_busfreq, 1);
73
Christophe Leroy1fc46f52022-10-14 12:54:50 +020074 /* MAC addr */
75 fdt_fixup_ethernet(blob);
76
77 /* Bus Frequency for CPM */
78 do_fixup_by_path_u32(blob, "/soc", "bus-frequency", bd->bi_busfreq, 1);
79
80 /* E1 interface - Set data rate */
81 do_fixup_by_path_u32(blob, "/localbus/e1", "data-rate", 2, 1);
82
83 /* E1 interface - Set channel phase to 0 */
84 do_fixup_by_path_u32(blob, "/localbus/e1", "channel-phase", 0, 1);
85
86 /* E1 interface - rising edge sync pulse transmit */
Christophe Leroy9646af32023-01-30 09:07:38 +010087 do_fixup_by_path(blob, "/localbus/e1", "rising-edge-sync-pulse", sync, strlen(sync), 1);
88
89 /* MIAE only */
90 if (!(in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) || in_8(ADDR_FPGA_R_BASE) != TYPE_MIAE)
91 return 0;
92
93 far_id = in_8(ADDR_FPGA_R_BASE + 0x43) >> 5;
94 ft_cleanup(blob, (u32)far_id, "far-id", "cs,mia-far");
95
96 /*
97 * special case, with CASRSA (far_id: 2)
98 * FAV-SRSA register itself as FAV-CLA
99 */
100 fav_id = in_8(ADDR_FPGA_R_BASE + 0x44) >> 5;
101
102 if (far_id == FAR_CASRSA && fav_id == FAV_CLA)
103 fav_id = FAV_SRSA;
104
105 ft_cleanup(blob, (u32)fav_id, "fav-id", "cs,mia-fav");
106
107 if (far_id == FAR_CASRSA) {
108 /* switch to phy3 with gpio, we'll only use phy3 */
109 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
110 cpm8xx_t __iomem *cp = (cpm8xx_t __iomem *)&immr->im_cpm;
111
112 setbits_be32(&cp->cp_pedat, 0x00002000);
113 }
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200114
115 return 0;
116}
117
118int checkboard(void)
119{
120 serial_puts("Board: ");
121
122 /* Is a motherboard present ? */
123 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
124 switch (in_8(ADDR_FPGA_R_BASE)) {
Christophe Leroy9646af32023-01-30 09:07:38 +0100125 int far_id;
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200126 case TYPE_MCR:
127 printf("MCR3000_2G (CS GROUP)\n");
128 break;
Christophe Leroy9646af32023-01-30 09:07:38 +0100129 case TYPE_MIAE:
130 far_id = in_8(ADDR_FPGA_R_BASE + 0x43) >> 5;
131
132 if (far_id == FAR_VGOIP)
133 printf("VGoIP (CS GROUP)\n");
134 else
135 printf("MIAE (CS GROUP)\n");
136
137 break;
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200138 default:
139 printf("Unknown\n");
140 for (;;)
141 ;
142 break;
143 }
144 } else {
145 printf("CMPC885 (CS GROUP)\n");
146 }
147 return 0;
148}
149
150#define SPI_EEPROM_READ 0x03
151#define MAX_SPI_BYTES 0x20
152
153#define EE_OFF_MAC1 0x13
154#define EE_OFF_MAC2 0x19
155
156/* Reads MAC addresses from SPI EEPROM */
157static int setup_mac(void)
158{
159 struct udevice *eeprom;
160 struct spi_slave *slave;
161 char name[30], *str;
162 uchar din[MAX_SPI_BYTES];
163 uchar dout[MAX_SPI_BYTES] = {SPI_EEPROM_READ, 0, 0};
164 int bitlen = 256, cs = 0, mode = 0, bus = 0, ret;
165 unsigned long ident = 0x08005120;
166
167 snprintf(name, sizeof(name), "generic_%d:%d", bus, cs);
168
169 str = strdup(name);
170 if (!str)
171 return -1;
172
173 ret = uclass_get_device(UCLASS_SPI, 0, &eeprom);
174 if (ret) {
175 printf("Could not enable Serial Peripheral Interface (SPI).\n");
176 return -1;
177 }
178
179 ret = _spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv", str, &eeprom, &slave);
180 if (ret)
181 return ret;
182
183 ret = spi_claim_bus(slave);
184
185 ret = spi_xfer(slave, bitlen, dout, din, SPI_XFER_BEGIN | SPI_XFER_END);
186 if (ret) {
187 printf("Error %d during SPI transaction\n", ret);
188 return ret;
189 }
190
191 if (memcmp(din + EE_OFF_MAC1, &ident, sizeof(ident)) == 0)
192 eth_env_set_enetaddr("ethaddr", din + EE_OFF_MAC1);
193
194 if (memcmp(din + EE_OFF_MAC2, &ident, sizeof(ident)) == 0)
195 eth_env_set_enetaddr("eth1addr", din + EE_OFF_MAC2);
196
197 spi_release_bus(slave);
198
199 return 0;
200}
201
202int misc_init_r(void)
203{
Christophe Leroy9646af32023-01-30 09:07:38 +0100204 u8 val, tmp, far_id;
205 int count = 3;
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200206
207 val = in_8(ADDR_FPGA_R_BASE);
208
209 /* Verify mother board presence */
210 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
211 /* identify the type of mother board */
212 switch (val) {
213 case TYPE_MCR:
214 /* if at boot alarm button is pressed, delay boot */
215 if ((in_8(ADDR_FPGA_R_ALARMES_IN) & FPGA_R_ACQ_AL_FAV) == 0)
216 env_set("bootdelay", "60");
217
218 env_set("config", BOARD_MCR3000_2G);
219 env_set("hostname", BOARD_MCR3000_2G);
220 break;
Christophe Leroy9646af32023-01-30 09:07:38 +0100221
222 case TYPE_MIAE:
223 do {
224 tmp = in_8(ADDR_FPGA_R_BASE + 0x41);
225 count--;
226 mdelay(10); /* 10msec wait */
227 } while (count && tmp != in_8(ADDR_FPGA_R_BASE + 0x41));
228
229 if (!count) {
230 printf("Cannot read the reset factory switch position\n");
231 hang();
232 }
233
234 if (tmp & 0x1)
235 env_set_default("Factory settings switch ON", 0);
236
237 env_set("config", BOARD_MIAE);
238 far_id = in_8(ADDR_FPGA_R_BASE + 0x43) >> 5;
239
240 if (far_id == FAR_VGOIP)
241 env_set("hostname", BOARD_VGOIP);
242 else
243 env_set("hostname", BOARD_MIAE);
244 break;
245
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200246 default:
247 env_set("config", BOARD_CMPC885);
248 env_set("hostname", BOARD_CMPC885);
249 break;
250 }
251 } else {
252 printf("no mother board detected");
253 env_set("config", BOARD_CMPC885);
254 env_set("hostname", BOARD_CMPC885);
255 }
256
257 if (setup_mac())
258 printf("Error retrieving mac addresses\n");
259
260 /* Protection ON by default */
261 flash_protect(FLAG_PROTECT_SET, CFG_SYS_FLASH_BASE, 0xffffffff, &flash_info[0]);
262
263 return 0;
264}
265
266static void iop_setup_mcr(void)
267{
268 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
269 iop8xx_t __iomem *iop = &immr->im_ioport;
270 cpm8xx_t __iomem *cp = &immr->im_cpm;
271
272 /* Wait reset on FPGA_F */
273 udelay(100);
274
275 /* We must initialize data before changing direction */
276 setbits_be16(&iop->iop_pcdat, 0x088E);
277 setbits_be16(&iop->iop_pddat, 0x0001);
278 setbits_be32(&cp->cp_pbdat, 0x00029510);
279 setbits_be32(&cp->cp_pedat, 0x00000002);
280
281 /*
282 * PAPAR[13] = 0 [0x0004] -> GPIO: ()
283 * PAPAR[12] = 0 [0x0008] -> GPIO: ()
284 * PAPAR[9] = 1 [0x0040] -> GPIO: (PCM_IN_12_MPC)
285 * PAPAR[8] = 1 [0x0080] -> GPIO: (PCM_OUT_12_MPC)
286 * PAPAR[7] = 1 [0x0100] -> GPIO: (TDM_BCLK_MPC)
287 * PAPAR[6] = 1 [0x0200] -> GPIO: (CLK2)
288 */
289 clrsetbits_be16(&iop->iop_papar, 0x03CC, 0x03C0);
290
291 /*
292 * PBODR[16] = 1 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
293 */
294 setbits_be16(&cp->cp_pbodr, 0x00008000);
295
296 /*
297 * PBDIR[27] = 1 [0x00000010] -> GPIO: (WR_TEMP2)
298 * PBDIR[26] = 1 [0x00000020] -> GPIO: (BRG02)
299 * PBDIR[23] = 1 [0x00000100] -> GPIO: (CS_TEMP2)
300 * PBDIR[18] = 1 [0x00002000] -> GPIO: (RTS2)
301 * PBDIR[16] = 1 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
302 * PBDIR[15] = 1 [0x00010000] -> GPIO: (BRG03)
303 * PBDIR[14] = 1 [0x00020000] -> GPIO: (CS_TEMP)
304 */
305 setbits_be32(&cp->cp_pbdir, 0x0003A130);
306
307 /*
308 * PBPAR[20] = 1 [0x00000800] -> GPIO: (SMRXD2)
309 * PBPAR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
310 * PBPAR[16] = 0 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
311 */
312 clrsetbits_be32(&cp->cp_pbpar, 0x0000C800, 0x00000800);
313
314 /*
315 * PCPAR[14] = 0 [0x0002] -> GPIO: (CS_POT2)
316 */
317 clrbits_be16(&iop->iop_pcpar, 0x0002);
318
319 /*
320 * PDPAR[14] = 1 [0x0002] -> GPIO: (TDM_FS_MPC)
321 * PDPAR[11] = 1 [0x0010] -> GPIO: (RXD3)
322 * PDPAR[10] = 1 [0x0020] -> GPIO: (TXD3)
323 * PDPAR[9] = 1 [0x0040] -> GPIO: (TXD4)
324 * PDPAR[7] = 1 [0x0100] -> GPIO: (RTS3)
325 * PDPAR[5] = 1 [0x0400] -> GPIO: (CLK8)
326 * PDPAR[3] = 1 [0x1000] -> GPIO: (CLK7)
327 */
328 setbits_be16(&iop->iop_pdpar, 0x1572);
329
330 /*
331 * PEPAR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
332 * PEPAR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
333 * PEPAR[25] = 1 [0x00000040] -> GPIO: (RXD4)
334 * PEPAR[24] = 1 [0x00000080] -> GPIO: (BRG01)
335 * PEPAR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
336 * PEPAR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
337 * PEPAR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
338 * PEPAR[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
339 * PEPAR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
340 * PEPAR[17] = 1 [0x00004000] -> GPIO: (CLK5)
341 * PEPAR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
342 * PEPAR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
343 * PEPAR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
344 */
345 clrsetbits_be32(&cp->cp_pepar, 0x0003DFF0, 0x0003DEF0);
346
347 /*
348 * PADIR[9] = 1 [0x0040] -> GPIO: (PCM_IN_12_MPC)
349 * PADIR[8] = 1 [0x0080] -> GPIO: (PCM_OUT_12_MPC)
350 * PADIR[5] = 1 [0x0400] -> GPIO: ()
351 */
352 setbits_be16(&iop->iop_padir, 0x04C0);
353
354 /*
355 * PCDIR[15] = 1 [0x0001] -> GPIO: (WP_EEPROM2)
356 * PCDIR[14] = 1 [0x0002] -> GPIO: (CS_POT2)
357 * PCDIR[13] = 1 [0x0004] -> GPIO: (CS_POT1)
358 * PCDIR[12] = 1 [0x0008] -> GPIO: (CS_EEPROM2)
359 * PCDIR[8] = 1 [0x0080] -> GPIO: (CS_CODEC_FAV)
360 * PCDIR[4] = 1 [0x0800] -> GPIO: (CS_CODEC_RADIO)
361 */
362 setbits_be16(&iop->iop_pcdir, 0x088F);
363
364 /*
365 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
366 * PDDIR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO)
367 * PDDIR[2] = x [0x2000] -> Reserved
368 * PDDIR[1] = 0 [0x4000] -> ODR for PD10 : (TXD3)
369 * PDDIR[0] = 0 [0x8000] -> ODR for PD8 : (R_MDC)
370 */
371 clrsetbits_be16(&iop->iop_pddir, 0xC240, 0x0040);
372
373 /*
374 * PEDIR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
375 * PEDIR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
376 * PEDIR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
377 * PEDIR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
378 * PEDIR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
379 * PEDIR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
380 * PEDIR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
381 * PEDIR[18] = 1 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
382 * PEDIR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
383 * PEDIR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
384 * PEDIR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
385 */
386 clrsetbits_be32(&cp->cp_pedir, 0x0003B732, 0x0003B632);
387
388 /*
389 * PAODR[10] = 1 [0x0020] -> GPIO: (INIT_FPGA_F)
390 */
391 setbits_be16(&iop->iop_paodr, 0x0020); // set_bit
392
393 /*
394 * PEODR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
395 * PEODR[18] = 1 [0x00002000] -> GPIO: (FPGA_RADIO)
396 */
397 setbits_be32(&cp->cp_peodr, 0x00002002);
398
399 /*
400 * PESO[24] = 1 [0x00000080] -> GPIO: (BRG01)
401 * PESO[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
402 * PESO[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
403 * PESO[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
404 * PESO[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
405 * PESO[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
406 */
407 clrsetbits_be32(&cp->cp_peso, 0x00031980, 0x00031880);
408
409 /* Disable CS for device */
410 /* PROGFPGA down */
411 clrbits_be32(&cp->cp_pbdat, 0x00008000);
412
413 /* PROGFPGA down */
414 clrbits_be32(&cp->cp_pedat, 0x00002000);
415 udelay(1); /* Wait more than 300ns */
416
417 /*
418 * We do not set the PROG signal of the C4E1 because
419 * there is a conflic with the CS of the EEPROM.
420 * I don't know why there is not the same problem
421 * with the FPGA_R
422 */
423
424 /* PROGFPGA up */
425 setbits_be32(&cp->cp_pedat, 0x00002000);
426}
427
428static void iop_setup_cmpc885(void)
429{
430 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
431 iop8xx_t __iomem *iop = &immr->im_ioport;
432 cpm8xx_t __iomem *cp = &immr->im_cpm;
433
434 /* We must initialize data before changing direction */
435 out_be16(&iop->iop_pcdat, 0x0000);
436 out_be16(&iop->iop_pddat, 0x0001);
437
438 out_be32(&cp->cp_pbdat, 0x00021400);
439 out_be32(&cp->cp_pedat, 0x00000000);
440
441 /*
442 * PAPAR[13] = 0 [0x0004] -> GPIO: ()
443 * PAPAR[12] = 0 [0x0008] -> GPIO: ()
444 * PAPAR[9] = 0 [0x0040] -> GPIO: ()
445 * PAPAR[8] = 0 [0x0080] -> GPIO: ()
446 * PAPAR[7] = 0 [0x0100] -> GPIO: ()
447 * PAPAR[6] = 0 [0x0200] -> GPIO: ()
448 */
449 clrbits_be16(&iop->iop_papar, 0x03CC);
450
451 /*
452 * PBPAR[20] = 0 [0x00000800] -> GPIO: ()
453 * PBPAR[17] = 0 [0x00004000] -> GPIO: ()
454 * PBPAR[16] = 0 [0x00008000] -> GPIO: ()
455 */
456 clrbits_be32(&cp->cp_pbpar, 0x0000C800);
457
458 /*
459 * PCPAR[14] = 0 [0x0002] -> GPIO: ()
460 */
461 clrbits_be16(&iop->iop_pcpar, 0x0002);
462
463 /*
464 * PDPAR[14] = 0 [0x0002] -> GPIO: ()
465 * PDPAR[11] = 0 [0x0010] -> GPIO: ()
466 * PDPAR[10] = 0 [0x0020] -> GPIO: ()
467 * PDPAR[9] = 0 [0x0040] -> GPIO: ()
468 * PDPAR[7] = 0 [0x0100] -> GPIO: ()
469 * PDPAR[5] = 0 [0x0400] -> GPIO: ()
470 * PDPAR[3] = 0 [0x1000] -> GPIO: ()
471 */
472 clrbits_be16(&iop->iop_pdpar, 0x1572);
473
474 /*
475 * PEPAR[27] = 0 [0x00000010] -> GPIO: ()
476 * PEPAR[26] = 0 [0x00000020] -> GPIO: ()
477 * PEPAR[25] = 0 [0x00000040] -> GPIO: ()
478 * PEPAR[24] = 0 [0x00000080] -> GPIO: ()
479 * PEPAR[23] = 0 [0x00000100] -> GPIO: ()
480 * PEPAR[22] = 0 [0x00000200] -> GPIO: ()
481 * PEPAR[21] = 0 [0x00000400] -> GPIO: ()
482 * PEPAR[20] = 0 [0x00000800] -> GPIO: ()
483 * PEPAR[19] = 0 [0x00001000] -> GPIO: ()
484 * PEPAR[17] = 0 [0x00004000] -> GPIO: ()
485 * PEPAR[16] = 0 [0x00008000] -> GPIO: ()
486 * PEPAR[15] = 0 [0x00010000] -> GPIO: ()
487 * PEPAR[14] = 0 [0x00020000] -> GPIO: ()
488 */
489 clrbits_be32(&cp->cp_pepar, 0x0003DFF0);
490
491 /*
492 * PADIR[9] = 0 [0x0040] -> GPIO: ()
493 * PADIR[8] = 0 [0x0080] -> GPIO: ()
494 * PADIR[5] = 0 [0x0400] -> GPIO: ()
495 */
496 clrbits_be16(&iop->iop_padir, 0x04C0);
497
498 /*
499 * In/Out or per. Function 0/1
500 * PBDIR[27] = 0 [0x00000010] -> GPIO: ()
501 * PBDIR[26] = 0 [0x00000020] -> GPIO: ()
502 * PBDIR[23] = 0 [0x00000100] -> GPIO: ()
503 * PBDIR[17] = 0 [0x00004000] -> GPIO: ()
504 * PBDIR[16] = 0 [0x00008000] -> GPIO: ()
505 */
506 clrbits_be32(&cp->cp_pbdir, 0x0000C130);
507
508 /*
509 * PCDIR[15] = 0 [0x0001] -> GPIO: ()
510 * PCDIR[14] = 0 [0x0002] -> GPIO: ()
511 * PCDIR[13] = 0 [0x0004] -> GPIO: ()
512 * PCDIR[12] = 0 [0x0008] -> GPIO: ()
513 * PCDIR[8] = 0 [0x0080] -> GPIO: ()
514 * PCDIR[4] = 0 [0x0800] -> GPIO: ()
515 */
516 clrbits_be16(&iop->iop_pcdir, 0x088F);
517
518 /*
519 * PDDIR[9] = 0 [0x0040] -> GPIO: ()
520 * PDDIR[6] = 0 [0x0200] -> GPIO: ()
521 * PDDIR[2] = x [0x2000] -> Reserved
522 * PDDIR[1] = 0 [0x4000] -> ODR for PD10 : ()
523 * PDDIR[0] = 0 [0x8000] -> ODR for PD8 : (R_MDC)
524 */
525 clrbits_be16(&iop->iop_pddir, 0xC240);
526
527 /*
528 * PEDIR[30] = 0 [0x00000002] -> GPIO: ()
529 * PEDIR[27] = 0 [0x00000010] -> GPIO: ()
530 * PEDIR[26] = 0 [0x00000020] -> GPIO: ()
531 * PEDIR[23] = 0 [0x00000100] -> GPIO: ()
532 * PEDIR[22] = 0 [0x00000200] -> GPIO: ()
533 * PEDIR[21] = 0 [0x00000400] -> GPIO: ()
534 * PEDIR[19] = 0 [0x00001000] -> GPIO: ()
535 * PEDIR[18] = 0 [0x00002000] -> GPIO: ()
536 * PEDIR[16] = 0 [0x00008000] -> GPIO: ()
537 * PEDIR[15] = 0 [0x00010000] -> GPIO: ()
538 * PEDIR[14] = 0 [0x00020000] -> GPIO: ()
539 */
540 clrbits_be32(&cp->cp_pedir, 0x0003B732);
541
542 /*
543 * PAODR[10] = 0 [0x0020] -> GPIO: ()
544 */
545 clrbits_be16(&iop->iop_paodr, 0x0020);
546
547 /*
548 * PBODR[16] = 0 [0x00008000] -> GPIO: ()
549 */
550 clrbits_be16(&cp->cp_pbodr, 0x00008000);
551
552 /*
553 * PEODR[30] = 0 [0x00000002] -> GPIO: ()
554 * PEODR[18] = 0 [0x00002000] -> GPIO: ()
555 */
556 clrbits_be32(&cp->cp_peodr, 0x00002002);
557
558 /*
559 * PESO[24] = 0 [0x00000080] -> GPIO: ()
560 * PESO[23] = 0 [0x00000100] -> GPIO: ()
561 * PESO[20] = 0 [0x00000800] -> GPIO: ()
562 * PESO[19] = 0 [0x00001000] -> GPIO: ()
563 * PESO[15] = 0 [0x00010000] -> GPIO: ()
564 * PESO[14] = 0 [0x00020000] -> GPIO: ()
565 */
566 clrbits_be32(&cp->cp_peso, 0x00031980);
567}
568
Christophe Leroy9646af32023-01-30 09:07:38 +0100569static void iop_setup_miae(void)
570{
571 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
572 iop8xx_t __iomem *iop = &immr->im_ioport;
573 cpm8xx_t __iomem *cp = &immr->im_cpm;
574
575 /* Wait reset on FPGA_F */
576 udelay(100);
577
578 /* Set the front panel LED color to red */
579 clrbits_8(ADDR_FPGA_R_FAV, 0x02);
580
581 /* We must initialize data before changing direction */
582 setbits_be16(&iop->iop_pcdat, 0x0888);
583 setbits_be16(&iop->iop_pddat, 0x0201);
584 setbits_be32(&cp->cp_pbdat, 0x00021510);
585 setbits_be32(&cp->cp_pedat, 0x00000002);
586
587 /*
588 * PAPAR[13] = 1 [0x0004] -> GPIO: (RXD2)
589 * PAPAR[12] = 1 [0x0008] -> GPIO: (TXD2)
590 * PAPAR[9] = 1 [0x0040] -> GPIO: (TDM1O)
591 * PAPAR[8] = 1 [0x0080] -> GPIO: (TDM1I)
592 * PAPAR[7] = 1 [0x0100] -> GPIO: (TDM_BCLK_MPC)
593 * PAPAR[6] = 1 [0x0200] -> GPIO: (CLK2)
594 */
595 setbits_be16(&iop->iop_papar, 0x03CC);
596
597 /*
598 * PBODR[16] = 0 [0x00008000] -> GPIO: (L1ST4)
599 */
600 clrbits_be16(&cp->cp_pbodr, 0x00008000);
601
602 /*
603 * PBDIR[27] = 1 [0x00000010] -> GPIO: (WR_TEMP2)
604 * PBDIR[26] = 1 [0x00000020] -> GPIO: (BRG02)
605 * PBDIR[23] = 1 [0x00000100] -> GPIO: (CS_TEMP2)
606 * PBDIR[18] = 1 [0x00002000] -> GPIO: (RTS2)
607 * PBDIR[16] = 0 [0x00008000] -> GPIO: (L1ST4)
608 * PBDIR[15] = 1 [0x00010000] -> GPIO: (BRG03)
609 * PBDIR[14] = 1 [0x00020000] -> GPIO: (CS_TEMP)
610 */
611 clrsetbits_be32(&cp->cp_pbdir, 0x0003A130, 0x00032130);
612
613 /*
614 * PBPAR[20] = 1 [0x00000800] -> GPIO: (SMRXD2)
615 * PBPAR[17] = 1 [0x00004000] -> GPIO: (L1ST3)
616 * PBPAR[16] = 1 [0x00008000] -> GPIO: (L1ST4)
617 */
618 setbits_be32(&cp->cp_pbpar, 0x0000C800);
619
620 /*
621 * PCPAR[14] = 1 [0x0002] -> GPIO: (L1ST2)
622 */
623 setbits_be16(&iop->iop_pcpar, 0x0002);
624
625 /*
626 * PDPAR[14] = 1 [0x0002] -> GPIO: (TDM_FS_MPC)
627 * PDPAR[11] = 1 [0x0010] -> GPIO: (RXD3)
628 * PDPAR[10] = 1 [0x0020] -> GPIO: (TXD3)
629 * PDPAR[9] = 1 [0x0040] -> GPIO: (TXD4)
630 * PDPAR[7] = 1 [0x0100] -> GPIO: (RTS3)
631 * PDPAR[5] = 1 [0x0400] -> GPIO: (CLK8)
632 * PDPAR[3] = 1 [0x1000] -> GPIO: (CLK7)
633 */
634 setbits_be16(&iop->iop_pdpar, 0x1572);
635
636 /*
637 * PEPAR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
638 * PEPAR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
639 * PEPAR[25] = 1 [0x00000040] -> GPIO: (RXD4)
640 * PEPAR[24] = 1 [0x00000080] -> GPIO: (BRG01)
641 * PEPAR[23] = 1 [0x00000100] -> GPIO: (L1ST1)
642 * PEPAR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
643 * PEPAR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
644 * PEPAR[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
645 * PEPAR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
646 * PEPAR[17] = 1 [0x00004000] -> GPIO: (CLK5)
647 * PEPAR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
648 * PEPAR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
649 * PEPAR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
650 */
651 setbits_be32(&cp->cp_pepar, 0x0003DFF0);
652
653 /*
654 * PADIR[9] = 1 [0x0040] -> GPIO: (TDM1O)
655 * PADIR[8] = 1 [0x0080] -> GPIO: (TDM1I)
656 * PADIR[5] = 0 [0x0400] -> GPIO: ()
657 */
658 clrsetbits_be16(&iop->iop_padir, 0x04C0, 0x00C0);
659
660 /*
661 * PCDIR[15] = 1 [0x0001] -> GPIO: (WP_EEPROM2)
662 * PCDIR[14] = 1 [0x0002] -> GPIO: (L1ST2)
663 * PCDIR[13] = 0 [0x0004] -> GPIO: ()
664 * PCDIR[12] = 1 [0x0008] -> GPIO: (CS_EEPROM2)
665 * PCDIR[8] = 1 [0x0080] -> GPIO: (CS_CODEC_2)
666 * PCDIR[4] = 1 [0x0800] -> GPIO: (CS_CODEC_1)
667 */
668 clrsetbits_be16(&iop->iop_pcdir, 0x088F, 0x088B);
669
670 /*
671 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
672 * PDDIR[6] = 1 [0x0200] -> GPIO: (CS_CODEC_3)
673 */
674 setbits_be16(&iop->iop_pddir, 0x0240);
675
676 /*
677 * PEDIR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
678 * PEDIR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
679 * PEDIR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
680 * PEDIR[23] = 1 [0x00000100] -> GPIO: (L1ST1)
681 * PEDIR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
682 * PEDIR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
683 * PEDIR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
684 * PEDIR[18] = 1 [0x00002000] -> GPIO: (PE18)
685 * PEDIR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
686 * PEDIR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
687 * PEDIR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
688 */
689 setbits_be32(&cp->cp_pedir, 0x0003B732);
690
691 /*
692 * PAODR[10] = 1 [0x0020] -> GPIO: (INIT_FPGA_F)
693 */
694 setbits_be16(&iop->iop_paodr, 0x0020);
695
696 /*
697 * PEODR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
698 * PEODR[18] = 0 [0x00002000] -> GPIO: (PE18)
699 */
700 clrsetbits_be32(&cp->cp_peodr, 0x00002002, 0x00000002);
701
702 /*
703 * PESO[24] = 1 [0x00000080] -> GPIO: (BRG01)
704 * PESO[23] = 1 [0x00000100] -> GPIO: (L1ST1)
705 * PESO[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
706 * PESO[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
707 * PESO[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
708 * PESO[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
709 */
710 setbits_be32(&cp->cp_peso, 0x00031980);
711}
712
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200713int board_early_init_f(void)
714{
715 return 0;
716}
717
718/* Specific board initialization */
719int board_early_init_r(void)
720{
721 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
722 iop8xx_t __iomem *iop = &immr->im_ioport;
723 cpm8xx_t __iomem *cp = &immr->im_cpm;
724
725 /* MPC885 Port settings common to all boards */
726 setbits_be16(&iop->iop_padat, 0x0000);
727
728 /* Port A (MPC885 reference manual - 34.2) */
729 /*
730 * In/Out or per. Function 0/1
731 * PADIR[15] = 0 [0x0001] -> GPIO: (USB_RXD)
732 * PADIR[14] = 0 [0x0002] -> GPIO: (USB_OE)
733 * PADIR[13] = 0 [0x0004] -> GPIO: ()
734 * PADIR[12] = 0 [0x0008] -> GPIO: ()
735 * PADIR[11] = 1 [0x0010] -> GPIO: (R1_TXD0)
736 * PADIR[10] = 0 [0x0020] -> GPIO: ()
737 * PADIR[7] = 0 [0x0100] -> GPIO: ()
738 * PADIR[6] = 0 [0x0200] -> GPIO: ()
739 * PADIR[4] = 1 [0x0800] -> GPIO: (R1_TXD1)
740 * PADIR[3] = 0 [0x1000] -> GPIO: (R1_RXER)
741 * PADIR[2] = 0 [0x2000] -> GPIO: (R1_CRS_DV)
742 * PADIR[1] = 0 [0x4000] -> GPIO: (R1_RXD0)
743 * PADIR[0] = 0 [0x8000] -> GPIO: (R1_RXD1)
744 */
745 clrsetbits_be16(&iop->iop_padir, 0xFB3F, 0x0810);
746
747 /*
748 * Open drain or active output
749 * PAODR[15] = x [0x0001]
750 * PAODR[14] = 0 [0x0002]
751 * PAODR[13] = x [0x0004]
752 * PAODR[12] = 0 [0x0008]
753 * PAODR[11] = 0 [0x0010]
754 * PAODR[9] = 0 [0x0040]
755 * PAODR[8] = 0 [0x0080]
756 * PAODR[7] = 0 [0x0100]
757 */
758 clrbits_be16(&iop->iop_paodr, 0x01DF);
759
760 /*
761 * GPIO or per. Function
762 * PAPAR[15] = 1 [0x0001] -> GPIO: (USB_RXD)
763 * PAPAR[14] = 1 [0x0002] -> GPIO: (USB_OE)
764 * PAPAR[11] = 1 [0x0010] -> GPIO: (R1_TXD0)
765 * PAPAR[10] = 0 [0x0020] -> GPIO: (INIT_FPGA_F)
766 * PAPAR[5] = 0 [0x0400] -> GPIO: ()
767 * PAPAR[4] = 1 [0x0800] -> GPIO: (R1_TXD1)
768 * PAPAR[3] = 1 [0x1000] -> GPIO: (R1_RXER)
769 * PAPAR[2] = 1 [0x2000] -> GPIO: (R1_CRS_DV)
770 * PAPAR[1] = 1 [0x4000] -> GPIO: (R1_RXD0)
771 * PAPAR[0] = 1 [0x8000] -> GPIO: (R1_RXD1)
772 */
773 clrsetbits_be16(&iop->iop_papar, 0xFC33, 0xF813);
774
775 /* Port B (MPC885 reference manual - 34.3) */
776 /*
777 * In/Out or per. Function 0/1
778 * PBDIR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK)
779 * PBDIR[30] = 1 [0x00000002] -> GPIO: (CLK)
780 * PBDIR[29] = 1 [0x00000004] -> GPIO: (MOSI)
781 * PBDIR[28] = 1 [0x00000008] -> GPIO: (MISO)
782 * PBDIR[25] = 0 [0x00000040] -> GPIO: (SMTXD1)
783 * PBDIR[24] = 0 [0x00000080] -> GPIO: (SMRXD1)
784 * PBDIR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
785 * PBDIR[21] = 1 [0x00000400] -> GPIO: (CS_EEPROM)
786 * PBDIR[20] = 0 [0x00000800] -> GPIO: (SMRXD2)
787 * PBDIR[19] = 1 [0x00001000] -> GPIO: (WR_TEMP)
788 * PBDIR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
789 */
790 clrsetbits_be32(&cp->cp_pbdir, 0x00005ECF, 0x0000140E);
791
792 /*
793 * Open drain or active output
794 * PBODR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK)
795 * PBODR[30] = 0 [0x00000002] -> GPIO: (CLK)
796 * PBODR[29] = 0 [0x00000004] -> GPIO: (MOSI)
797 * PBODR[28] = 0 [0x00000008] -> GPIO: (MISO)
798 * PBODR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2)
799 * PBODR[26] = 0 [0x00000020] -> GPIO: (BRG02)
800 * PBODR[25] = 0 [0x00000040] -> GPIO: (SMTXD1)
801 * PBODR[24] = 0 [0x00000080] -> GPIO: (SMRXD1)
802 * PBODR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2)
803 * PBODR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
804 * PBODR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM)
805 * PBODR[20] = 0 [0x00000800] -> GPIO: (SMRXD2)
806 * PBODR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP)
807 * PBODR[18] = 0 [0x00002000] -> GPIO: (RTS2)
808 * PBODR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
809 */
810 clrbits_be16(&cp->cp_pbodr, 0x00007FFF);
811
812 /*
813 * GPIO or per. Function
814 * PBPAR[31] = 1 [0x00000001] -> GPIO: (R1_REF_CLK)
815 * PBPAR[30] = 1 [0x00000002] -> GPIO: (CLK)
816 * PBPAR[29] = 1 [0x00000004] -> GPIO: (MOSI)
817 * PBPAR[28] = 1 [0x00000008] -> GPIO: (MISO)
818 * PBPAR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2)
819 * PBPAR[26] = 0 [0x00000020] -> GPIO: (BRG02)
820 * PBPAR[25] = 1 [0x00000040] -> GPIO: (SMTXD1)
821 * PBPAR[24] = 1 [0x00000080] -> GPIO: (SMRXD1)
822 * PBPAR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2)
823 * PBPAR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
824 * PBPAR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM)
825 * PBPAR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP)
826 * PBPAR[18] = 0 [0x00002000] -> GPIO: (RTS2)
827 * PBPAR[15] = 0 [0x00010000] -> GPIO: (BRG03)
828 * PBPAR[14] = 0 [0x00020000] -> GPIO: (CS_TEMP)
829 */
830 clrsetbits_be32(&cp->cp_pbpar, 0x000337FF, 0x000000CF);
831
832 /* Port C (MPC885 Reference Manual - 34.4) */
833 /*
834 * In/Out or per. Function 0/1
835 * PCDIR[11] = 0 [0x0010] -> GPIO: (USB_RXP)
836 * PCDIR[10] = 0 [0x0020] -> GPIO: (USB_RXN)
837 * PCDIR[9] = 0 [0x0040] -> GPIO: (CTS2)
838 * PCDIR[7] = 1 [0x0100] -> GPIO: (USB_TXP)
839 * PCDIR[6] = 1 [0x0200] -> GPIO: (USB_TXN)
840 * PCDIR[5] = 0 [0x0400] -> GPIO: (CTS3)
841 */
842 clrsetbits_be16(&iop->iop_pcdir, 0x0770, 0x0300);
843
844 /*
845 * GPIO or per. Function
846 * PCPAR[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2)
847 * PCPAR[13] = 0 [0x0004] -> GPIO: (CS_POT1)
848 * PCPAR[12] = 0 [0x0008] -> GPIO: (CS_EEPROM2)
849 * PCPAR[11] = 0 [0x0010] -> GPIO: (USB_RXP)
850 * PCPAR[10] = 0 [0x0020] -> GPIO: (USB_RXN)
851 * PCPAR[9] = 0 [0x0040] -> GPIO: (CTS2)
852 * PCPAR[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV)
853 * PCPAR[7] = 1 [0x0100] -> GPIO: (USB_TXP)
854 * PCPAR[6] = 1 [0x0200] -> GPIO: (USB_TXN)
855 * PCPAR[5] = 0 [0x0400] -> GPIO: (CTS3)
856 * PCPAR[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO)
857 */
858 clrsetbits_be16(&iop->iop_pcpar, 0x0FFD, 0x0300);
859
860 /*
861 * Special Option register
862 * PCSO[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2)
863 * PCSO[14] = 0 [0x0002] -> GPIO: (CS_POT2)
864 * PCSO[13] = x [0x0004] -> Reserved
865 * PCSO[12] = x [0x0008] -> Reserved
866 * PCSO[11] = 1 [0x0010] -> GPIO: (USB_RXP)
867 * PCSO[10] = 1 [0x0020] -> GPIO: (USB_RXN)
868 * PCSO[9] = 1 [0x0040] -> GPIO: (CTS2)
869 * PCSO[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV)
870 * PCSO[7] = 0 [0x0100] -> GPIO: (USB_TXP)
871 * PCSO[6] = 0 [0x0200] -> GPIO: (USB_TXN)
872 * PCSO[5] = 1 [0x0400] -> GPIO: (CTS3)
873 * PCSO[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO)
874 */
875 clrsetbits_be16(&iop->iop_pcso, 0x0FF3, 0x0470);
876
877 /*
878 * Interrupt or IO
879 * PCINT[15] = 0 [0x0001] -> GPIO: ()
880 * PCINT[14] = 0 [0x0002] -> GPIO: ()
881 * PCINT[13] = 0 [0x0004] -> GPIO: ()
882 * PCINT[12] = 0 [0x0008] -> GPIO: ()
883 * PCINT[11] = 0 [0x0010] -> GPIO: (USB_RXP)
884 * PCINT[10] = 0 [0x0020] -> GPIO: (USB_RXN)
885 * PCINT[9] = 0 [0x0040] -> GPIO: ()
886 * PCINT[8] = 0 [0x0080] -> GPIO: ()
887 * PCINT[7] = 0 [0x0100] -> GPIO: (USB_TXP)
888 * PCINT[6] = 0 [0x0200] -> GPIO: (USB_TXN)
889 * PCINT[5] = 0 [0x0400] -> GPIO: ()
890 * PCINT[4] = 0 [0x0800] -> GPIO: ()
891 */
892 clrbits_be16(&iop->iop_pcint, 0x0FFF);
893
894 /* Port D (MPC885 Reference Manual - 34.5) */
895 /*
896 * In/Out or per. Function 0/1
897 * PDDIR[15] = 1 [0x0001] -> GPIO: (CS_NAND)
898 * PDDIR[14] = 0 [0x0002] -> GPIO: (TDM_FS_MPC)
899 * PDDIR[13] = 1 [0x0004] -> GPIO: (ALE_NAND)
900 * PDDIR[12] = 1 [0x0008] -> GPIO: (CLE_NAND)
901 * PDDIR[11] = 0 [0x0010] -> GPIO: (RXD3)
902 * PDDIR[10] = 0 [0x0020] -> GPIO: (TXD3)
903 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
904 * PDDIR[8] = 0 [0x0080] -> GPIO: (R_MDC)
905 * PDDIR[7] = 0 [0x0100] -> GPIO: (RTS3)
906 * PDDIR[5] = 0 [0x0400] -> GPIO: (CLK8)
907 * PDDIR[4] = 0 [0x0800] -> GPIO: (CLK4)
908 * PDDIR[3] = 0 [0x1000] -> GPIO: (CLK7)
909 */
910 clrsetbits_be16(&iop->iop_pddir, 0x1DFF, 0x004D);
911
912 /*
913 * GPIO or per. Function
914 * PDPAR[15] = 0 [0x0001] -> GPIO: (CS_NAND)
915 * PDPAR[13] = 0 [0x0004] -> GPIO: (ALE_NAND)
916 * PDPAR[12] = 0 [0x0008] -> GPIO: (CLE_NAND)
917 * PDPAR[8] = 1 [0x0080] -> GPIO: (R_MDC)
918 * PDPAR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO)
919 * PDPAR[4] = 1 [0x0800] -> GPIO: (CLK4)
920 */
921 clrsetbits_be16(&iop->iop_pdpar, 0x0A8D, 0x0880);
922
923 /* Port E (MPC885 Reference Manual - 34.6) */
924 /*
925 * In/Out or per. Function 0/1
926 * PEDIR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
927 * PEDIR[29] = 1 [0x00000004] -> GPIO: (USB_SPEED)
928 * PEDIR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND)
929 * PEDIR[25] = 0 [0x00000040] -> GPIO: (RXD4)
930 * PEDIR[24] = 0 [0x00000080] -> GPIO: (BRG01)
931 * PEDIR[20] = 0 [0x00000800] -> GPIO: (SMTXD2)
932 * PEDIR[17] = 0 [0x00004000] -> GPIO: (CLK5)
933 */
934 clrsetbits_be32(&cp->cp_pedir, 0x000048CD, 0x0000000C);
935
936 /*
937 * open drain or active output
938 * PEODR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
939 * PEODR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
940 * PEODR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND)
941 * PEODR[27] = 0 [0x00000010] -> GPIO: (R2_RXER)
942 * PEODR[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV)
943 * PEODR[25] = 0 [0x00000040] -> GPIO: (RXD4)
944 * PEODR[24] = 0 [0x00000080] -> GPIO: (BRG01)
945 * PEODR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
946 * PEODR[22] = 0 [0x00000200] -> GPIO: (R2_RXD1)
947 * PEODR[21] = 0 [0x00000400] -> GPIO: (R2_RXD0)
948 * PEODR[20] = 0 [0x00000800] -> GPIO: (SMTXD2)
949 * PEODR[19] = 0 [0x00001000] -> GPIO: (R2_TXEN)
950 * PEODR[17] = 0 [0x00004000] -> GPIO: (CLK5)
951 * PEODR[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK)
952 */
953 clrsetbits_be32(&cp->cp_peodr, 0x0000DFFD, 0x00000008);
954
955 /*
956 * GPIO or per. Function
957 * PEPAR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
958 * PEPAR[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE)
959 * PEPAR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
960 * PEPAR[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND)
961 * PEPAR[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
962 */
963 clrbits_be32(&cp->cp_pepar, 0x0000200F);
964
965 /*
966 * Special Option register
967 * PESO[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
968 * PESO[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE)
969 * PESO[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
970 * PESO[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND)
971 * PESO[27] = 0 [0x00000010] -> GPIO: (R2_RXER)
972 * PESO[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV)
973 * PESO[25] = 0 [0x00000040] -> GPIO: (RXD4)
974 * PESO[22] = 0 [0x00000200] -> GPIO: (R2_RXD1)
975 * PESO[21] = 0 [0x00000400] -> GPIO: (R2_RXD0)
976 * PESO[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
977 * PESO[17] = 0 [0x00004000] -> GPIO: (CLK5)
978 * PESO[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK)
979 */
980 clrbits_be32(&cp->cp_peso, 0x0000E67F);
981
982 /* Is a motherboard present ? */
983 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
984 /* Initialize signal PROG_FPGA_FIRMWARE */
985 out_be32(&cp->cp_pedat, 0x00000002);
986 out_be32(&cp->cp_peodr, 0x00000002);
987 out_be32(&cp->cp_pedir, 0x00000002);
988
989 /* Check if fpga firmware is loaded */
990 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
991 printf("Reloading FPGA firmware.\n");
992
993 /* Load fpga firmware */
994 /* Activate PROG_FPGA_FIRMWARE for 1 usec */
995 clrbits_be32(&cp->cp_pedat, 0x00000002);
996 udelay(1);
997 setbits_be32(&cp->cp_pedat, 0x00000002);
998
999 /* Wait 200 msec and check DONE_FPGA_FIRMWARE */
1000 mdelay(200);
1001 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
1002 for (;;) {
1003 printf("error loading firmware.\n");
1004 mdelay(500);
1005 }
1006 }
1007
1008 /* Send a reset signal and wait for 20 msec */
1009 clrbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS);
1010 mdelay(20);
1011 setbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS);
1012 }
1013
1014 /* Wait 300 msec and check the reset state */
1015 mdelay(300);
1016 if (!(in_be16(ADDR_CPLD_R_RESET) & R_RESET_STATUS)) {
1017 for (;;) {
1018 printf("Could not reset FPGA.\n");
1019 mdelay(500);
1020 }
1021 }
1022
1023 /* is FPGA firmware loaded ? */
1024 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
1025 printf("Reloading FPGA firmware\n");
1026
1027 /* Load FPGA firmware */
1028 /* Activate PROG_FPGA_FIRMWARE for 1 usec */
1029 clrbits_be32(&cp->cp_pedat, 0x00000002);
1030 udelay(1);
1031 setbits_be32(&cp->cp_pedat, 0x00000002);
1032
1033 /* Wait 200ms before checking DONE_FPGA_FIRMWARE */
1034 mdelay(200);
1035 }
1036
1037 /* Identify the type of mother board */
1038 switch (in_8(ADDR_FPGA_R_BASE)) {
1039 case TYPE_MCR:
1040 iop_setup_mcr();
1041 break;
1042
Christophe Leroy9646af32023-01-30 09:07:38 +01001043 case TYPE_MIAE:
1044 iop_setup_miae();
1045 break;
1046
Christophe Leroy1fc46f52022-10-14 12:54:50 +02001047 default:
1048 break;
1049 }
1050 /* CMPC885 board alone */
1051 } else {
1052 iop_setup_cmpc885();
1053 }
1054
1055 return 0;
1056}