blob: cde9a558efcb88b08b87b6f3e56a891698a5c255 [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>
25
26#include <spi.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
30#define BOARD_CMPC885 "cmpc885"
31#define BOARD_MCR3000_2G "mcr3k_2g"
32
33#define TYPE_MCR 0x22
34
35#define ADDR_CPLD_R_RESET ((unsigned short __iomem *)CONFIG_CPLD_BASE)
36#define ADDR_CPLD_R_ETAT ((unsigned short __iomem *)(CONFIG_CPLD_BASE + 2))
37#define ADDR_CPLD_R_TYPE ((unsigned char __iomem *)(CONFIG_CPLD_BASE + 3))
38
39#define ADDR_FPGA_R_BASE ((unsigned char __iomem *)CONFIG_FPGA_BASE)
40#define ADDR_FPGA_R_ALARMES_IN ((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x31)
41
42#define FPGA_R_ACQ_AL_FAV 0x04
43#define R_ETAT_PRES_BASE 0x0040
44
45#define R_RESET_STATUS 0x0400
46#define R_RST_STATUS 0x0004
47
48int ft_board_setup(void *blob, struct bd_info *bd)
49{
50 const char *sync = "receive";
51
52 ft_cpu_setup(blob, bd);
53
54 /* BRG */
55 do_fixup_by_path_u32(blob, "/soc/cpm", "brg-frequency",
56 bd->bi_busfreq, 1);
57 /* MAC addr */
58 fdt_fixup_ethernet(blob);
59
60 /* Bus Frequency for CPM */
61 do_fixup_by_path_u32(blob, "/soc", "bus-frequency", bd->bi_busfreq, 1);
62
63 /* E1 interface - Set data rate */
64 do_fixup_by_path_u32(blob, "/localbus/e1", "data-rate", 2, 1);
65
66 /* E1 interface - Set channel phase to 0 */
67 do_fixup_by_path_u32(blob, "/localbus/e1", "channel-phase", 0, 1);
68
69 /* E1 interface - rising edge sync pulse transmit */
70 do_fixup_by_path(blob, "/localbus/e1", "rising-edge-sync-pulse",
71 sync, strlen(sync), 1);
72
73 return 0;
74}
75
76int checkboard(void)
77{
78 serial_puts("Board: ");
79
80 /* Is a motherboard present ? */
81 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
82 switch (in_8(ADDR_FPGA_R_BASE)) {
83 case TYPE_MCR:
84 printf("MCR3000_2G (CS GROUP)\n");
85 break;
86 default:
87 printf("Unknown\n");
88 for (;;)
89 ;
90 break;
91 }
92 } else {
93 printf("CMPC885 (CS GROUP)\n");
94 }
95 return 0;
96}
97
98#define SPI_EEPROM_READ 0x03
99#define MAX_SPI_BYTES 0x20
100
101#define EE_OFF_MAC1 0x13
102#define EE_OFF_MAC2 0x19
103
104/* Reads MAC addresses from SPI EEPROM */
105static int setup_mac(void)
106{
107 struct udevice *eeprom;
108 struct spi_slave *slave;
109 char name[30], *str;
110 uchar din[MAX_SPI_BYTES];
111 uchar dout[MAX_SPI_BYTES] = {SPI_EEPROM_READ, 0, 0};
112 int bitlen = 256, cs = 0, mode = 0, bus = 0, ret;
113 unsigned long ident = 0x08005120;
114
115 snprintf(name, sizeof(name), "generic_%d:%d", bus, cs);
116
117 str = strdup(name);
118 if (!str)
119 return -1;
120
121 ret = uclass_get_device(UCLASS_SPI, 0, &eeprom);
122 if (ret) {
123 printf("Could not enable Serial Peripheral Interface (SPI).\n");
124 return -1;
125 }
126
127 ret = _spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv", str, &eeprom, &slave);
128 if (ret)
129 return ret;
130
131 ret = spi_claim_bus(slave);
132
133 ret = spi_xfer(slave, bitlen, dout, din, SPI_XFER_BEGIN | SPI_XFER_END);
134 if (ret) {
135 printf("Error %d during SPI transaction\n", ret);
136 return ret;
137 }
138
139 if (memcmp(din + EE_OFF_MAC1, &ident, sizeof(ident)) == 0)
140 eth_env_set_enetaddr("ethaddr", din + EE_OFF_MAC1);
141
142 if (memcmp(din + EE_OFF_MAC2, &ident, sizeof(ident)) == 0)
143 eth_env_set_enetaddr("eth1addr", din + EE_OFF_MAC2);
144
145 spi_release_bus(slave);
146
147 return 0;
148}
149
150int misc_init_r(void)
151{
152 u8 val;
153
154 val = in_8(ADDR_FPGA_R_BASE);
155
156 /* Verify mother board presence */
157 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
158 /* identify the type of mother board */
159 switch (val) {
160 case TYPE_MCR:
161 /* if at boot alarm button is pressed, delay boot */
162 if ((in_8(ADDR_FPGA_R_ALARMES_IN) & FPGA_R_ACQ_AL_FAV) == 0)
163 env_set("bootdelay", "60");
164
165 env_set("config", BOARD_MCR3000_2G);
166 env_set("hostname", BOARD_MCR3000_2G);
167 break;
168 default:
169 env_set("config", BOARD_CMPC885);
170 env_set("hostname", BOARD_CMPC885);
171 break;
172 }
173 } else {
174 printf("no mother board detected");
175 env_set("config", BOARD_CMPC885);
176 env_set("hostname", BOARD_CMPC885);
177 }
178
179 if (setup_mac())
180 printf("Error retrieving mac addresses\n");
181
182 /* Protection ON by default */
183 flash_protect(FLAG_PROTECT_SET, CFG_SYS_FLASH_BASE, 0xffffffff, &flash_info[0]);
184
185 return 0;
186}
187
188static void iop_setup_mcr(void)
189{
190 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
191 iop8xx_t __iomem *iop = &immr->im_ioport;
192 cpm8xx_t __iomem *cp = &immr->im_cpm;
193
194 /* Wait reset on FPGA_F */
195 udelay(100);
196
197 /* We must initialize data before changing direction */
198 setbits_be16(&iop->iop_pcdat, 0x088E);
199 setbits_be16(&iop->iop_pddat, 0x0001);
200 setbits_be32(&cp->cp_pbdat, 0x00029510);
201 setbits_be32(&cp->cp_pedat, 0x00000002);
202
203 /*
204 * PAPAR[13] = 0 [0x0004] -> GPIO: ()
205 * PAPAR[12] = 0 [0x0008] -> GPIO: ()
206 * PAPAR[9] = 1 [0x0040] -> GPIO: (PCM_IN_12_MPC)
207 * PAPAR[8] = 1 [0x0080] -> GPIO: (PCM_OUT_12_MPC)
208 * PAPAR[7] = 1 [0x0100] -> GPIO: (TDM_BCLK_MPC)
209 * PAPAR[6] = 1 [0x0200] -> GPIO: (CLK2)
210 */
211 clrsetbits_be16(&iop->iop_papar, 0x03CC, 0x03C0);
212
213 /*
214 * PBODR[16] = 1 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
215 */
216 setbits_be16(&cp->cp_pbodr, 0x00008000);
217
218 /*
219 * PBDIR[27] = 1 [0x00000010] -> GPIO: (WR_TEMP2)
220 * PBDIR[26] = 1 [0x00000020] -> GPIO: (BRG02)
221 * PBDIR[23] = 1 [0x00000100] -> GPIO: (CS_TEMP2)
222 * PBDIR[18] = 1 [0x00002000] -> GPIO: (RTS2)
223 * PBDIR[16] = 1 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
224 * PBDIR[15] = 1 [0x00010000] -> GPIO: (BRG03)
225 * PBDIR[14] = 1 [0x00020000] -> GPIO: (CS_TEMP)
226 */
227 setbits_be32(&cp->cp_pbdir, 0x0003A130);
228
229 /*
230 * PBPAR[20] = 1 [0x00000800] -> GPIO: (SMRXD2)
231 * PBPAR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
232 * PBPAR[16] = 0 [0x00008000] -> GPIO: (PROG_FPGA_MEZZ)
233 */
234 clrsetbits_be32(&cp->cp_pbpar, 0x0000C800, 0x00000800);
235
236 /*
237 * PCPAR[14] = 0 [0x0002] -> GPIO: (CS_POT2)
238 */
239 clrbits_be16(&iop->iop_pcpar, 0x0002);
240
241 /*
242 * PDPAR[14] = 1 [0x0002] -> GPIO: (TDM_FS_MPC)
243 * PDPAR[11] = 1 [0x0010] -> GPIO: (RXD3)
244 * PDPAR[10] = 1 [0x0020] -> GPIO: (TXD3)
245 * PDPAR[9] = 1 [0x0040] -> GPIO: (TXD4)
246 * PDPAR[7] = 1 [0x0100] -> GPIO: (RTS3)
247 * PDPAR[5] = 1 [0x0400] -> GPIO: (CLK8)
248 * PDPAR[3] = 1 [0x1000] -> GPIO: (CLK7)
249 */
250 setbits_be16(&iop->iop_pdpar, 0x1572);
251
252 /*
253 * PEPAR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
254 * PEPAR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
255 * PEPAR[25] = 1 [0x00000040] -> GPIO: (RXD4)
256 * PEPAR[24] = 1 [0x00000080] -> GPIO: (BRG01)
257 * PEPAR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
258 * PEPAR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
259 * PEPAR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
260 * PEPAR[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
261 * PEPAR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
262 * PEPAR[17] = 1 [0x00004000] -> GPIO: (CLK5)
263 * PEPAR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
264 * PEPAR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
265 * PEPAR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
266 */
267 clrsetbits_be32(&cp->cp_pepar, 0x0003DFF0, 0x0003DEF0);
268
269 /*
270 * PADIR[9] = 1 [0x0040] -> GPIO: (PCM_IN_12_MPC)
271 * PADIR[8] = 1 [0x0080] -> GPIO: (PCM_OUT_12_MPC)
272 * PADIR[5] = 1 [0x0400] -> GPIO: ()
273 */
274 setbits_be16(&iop->iop_padir, 0x04C0);
275
276 /*
277 * PCDIR[15] = 1 [0x0001] -> GPIO: (WP_EEPROM2)
278 * PCDIR[14] = 1 [0x0002] -> GPIO: (CS_POT2)
279 * PCDIR[13] = 1 [0x0004] -> GPIO: (CS_POT1)
280 * PCDIR[12] = 1 [0x0008] -> GPIO: (CS_EEPROM2)
281 * PCDIR[8] = 1 [0x0080] -> GPIO: (CS_CODEC_FAV)
282 * PCDIR[4] = 1 [0x0800] -> GPIO: (CS_CODEC_RADIO)
283 */
284 setbits_be16(&iop->iop_pcdir, 0x088F);
285
286 /*
287 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
288 * PDDIR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO)
289 * PDDIR[2] = x [0x2000] -> Reserved
290 * PDDIR[1] = 0 [0x4000] -> ODR for PD10 : (TXD3)
291 * PDDIR[0] = 0 [0x8000] -> ODR for PD8 : (R_MDC)
292 */
293 clrsetbits_be16(&iop->iop_pddir, 0xC240, 0x0040);
294
295 /*
296 * PEDIR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
297 * PEDIR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
298 * PEDIR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
299 * PEDIR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
300 * PEDIR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
301 * PEDIR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
302 * PEDIR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
303 * PEDIR[18] = 1 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
304 * PEDIR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
305 * PEDIR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
306 * PEDIR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
307 */
308 clrsetbits_be32(&cp->cp_pedir, 0x0003B732, 0x0003B632);
309
310 /*
311 * PAODR[10] = 1 [0x0020] -> GPIO: (INIT_FPGA_F)
312 */
313 setbits_be16(&iop->iop_paodr, 0x0020); // set_bit
314
315 /*
316 * PEODR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
317 * PEODR[18] = 1 [0x00002000] -> GPIO: (FPGA_RADIO)
318 */
319 setbits_be32(&cp->cp_peodr, 0x00002002);
320
321 /*
322 * PESO[24] = 1 [0x00000080] -> GPIO: (BRG01)
323 * PESO[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
324 * PESO[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
325 * PESO[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
326 * PESO[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
327 * PESO[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
328 */
329 clrsetbits_be32(&cp->cp_peso, 0x00031980, 0x00031880);
330
331 /* Disable CS for device */
332 /* PROGFPGA down */
333 clrbits_be32(&cp->cp_pbdat, 0x00008000);
334
335 /* PROGFPGA down */
336 clrbits_be32(&cp->cp_pedat, 0x00002000);
337 udelay(1); /* Wait more than 300ns */
338
339 /*
340 * We do not set the PROG signal of the C4E1 because
341 * there is a conflic with the CS of the EEPROM.
342 * I don't know why there is not the same problem
343 * with the FPGA_R
344 */
345
346 /* PROGFPGA up */
347 setbits_be32(&cp->cp_pedat, 0x00002000);
348}
349
350static void iop_setup_cmpc885(void)
351{
352 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
353 iop8xx_t __iomem *iop = &immr->im_ioport;
354 cpm8xx_t __iomem *cp = &immr->im_cpm;
355
356 /* We must initialize data before changing direction */
357 out_be16(&iop->iop_pcdat, 0x0000);
358 out_be16(&iop->iop_pddat, 0x0001);
359
360 out_be32(&cp->cp_pbdat, 0x00021400);
361 out_be32(&cp->cp_pedat, 0x00000000);
362
363 /*
364 * PAPAR[13] = 0 [0x0004] -> GPIO: ()
365 * PAPAR[12] = 0 [0x0008] -> GPIO: ()
366 * PAPAR[9] = 0 [0x0040] -> GPIO: ()
367 * PAPAR[8] = 0 [0x0080] -> GPIO: ()
368 * PAPAR[7] = 0 [0x0100] -> GPIO: ()
369 * PAPAR[6] = 0 [0x0200] -> GPIO: ()
370 */
371 clrbits_be16(&iop->iop_papar, 0x03CC);
372
373 /*
374 * PBPAR[20] = 0 [0x00000800] -> GPIO: ()
375 * PBPAR[17] = 0 [0x00004000] -> GPIO: ()
376 * PBPAR[16] = 0 [0x00008000] -> GPIO: ()
377 */
378 clrbits_be32(&cp->cp_pbpar, 0x0000C800);
379
380 /*
381 * PCPAR[14] = 0 [0x0002] -> GPIO: ()
382 */
383 clrbits_be16(&iop->iop_pcpar, 0x0002);
384
385 /*
386 * PDPAR[14] = 0 [0x0002] -> GPIO: ()
387 * PDPAR[11] = 0 [0x0010] -> GPIO: ()
388 * PDPAR[10] = 0 [0x0020] -> GPIO: ()
389 * PDPAR[9] = 0 [0x0040] -> GPIO: ()
390 * PDPAR[7] = 0 [0x0100] -> GPIO: ()
391 * PDPAR[5] = 0 [0x0400] -> GPIO: ()
392 * PDPAR[3] = 0 [0x1000] -> GPIO: ()
393 */
394 clrbits_be16(&iop->iop_pdpar, 0x1572);
395
396 /*
397 * PEPAR[27] = 0 [0x00000010] -> GPIO: ()
398 * PEPAR[26] = 0 [0x00000020] -> GPIO: ()
399 * PEPAR[25] = 0 [0x00000040] -> GPIO: ()
400 * PEPAR[24] = 0 [0x00000080] -> GPIO: ()
401 * PEPAR[23] = 0 [0x00000100] -> GPIO: ()
402 * PEPAR[22] = 0 [0x00000200] -> GPIO: ()
403 * PEPAR[21] = 0 [0x00000400] -> GPIO: ()
404 * PEPAR[20] = 0 [0x00000800] -> GPIO: ()
405 * PEPAR[19] = 0 [0x00001000] -> GPIO: ()
406 * PEPAR[17] = 0 [0x00004000] -> GPIO: ()
407 * PEPAR[16] = 0 [0x00008000] -> GPIO: ()
408 * PEPAR[15] = 0 [0x00010000] -> GPIO: ()
409 * PEPAR[14] = 0 [0x00020000] -> GPIO: ()
410 */
411 clrbits_be32(&cp->cp_pepar, 0x0003DFF0);
412
413 /*
414 * PADIR[9] = 0 [0x0040] -> GPIO: ()
415 * PADIR[8] = 0 [0x0080] -> GPIO: ()
416 * PADIR[5] = 0 [0x0400] -> GPIO: ()
417 */
418 clrbits_be16(&iop->iop_padir, 0x04C0);
419
420 /*
421 * In/Out or per. Function 0/1
422 * PBDIR[27] = 0 [0x00000010] -> GPIO: ()
423 * PBDIR[26] = 0 [0x00000020] -> GPIO: ()
424 * PBDIR[23] = 0 [0x00000100] -> GPIO: ()
425 * PBDIR[17] = 0 [0x00004000] -> GPIO: ()
426 * PBDIR[16] = 0 [0x00008000] -> GPIO: ()
427 */
428 clrbits_be32(&cp->cp_pbdir, 0x0000C130);
429
430 /*
431 * PCDIR[15] = 0 [0x0001] -> GPIO: ()
432 * PCDIR[14] = 0 [0x0002] -> GPIO: ()
433 * PCDIR[13] = 0 [0x0004] -> GPIO: ()
434 * PCDIR[12] = 0 [0x0008] -> GPIO: ()
435 * PCDIR[8] = 0 [0x0080] -> GPIO: ()
436 * PCDIR[4] = 0 [0x0800] -> GPIO: ()
437 */
438 clrbits_be16(&iop->iop_pcdir, 0x088F);
439
440 /*
441 * PDDIR[9] = 0 [0x0040] -> GPIO: ()
442 * PDDIR[6] = 0 [0x0200] -> GPIO: ()
443 * PDDIR[2] = x [0x2000] -> Reserved
444 * PDDIR[1] = 0 [0x4000] -> ODR for PD10 : ()
445 * PDDIR[0] = 0 [0x8000] -> ODR for PD8 : (R_MDC)
446 */
447 clrbits_be16(&iop->iop_pddir, 0xC240);
448
449 /*
450 * PEDIR[30] = 0 [0x00000002] -> GPIO: ()
451 * PEDIR[27] = 0 [0x00000010] -> GPIO: ()
452 * PEDIR[26] = 0 [0x00000020] -> GPIO: ()
453 * PEDIR[23] = 0 [0x00000100] -> GPIO: ()
454 * PEDIR[22] = 0 [0x00000200] -> GPIO: ()
455 * PEDIR[21] = 0 [0x00000400] -> GPIO: ()
456 * PEDIR[19] = 0 [0x00001000] -> GPIO: ()
457 * PEDIR[18] = 0 [0x00002000] -> GPIO: ()
458 * PEDIR[16] = 0 [0x00008000] -> GPIO: ()
459 * PEDIR[15] = 0 [0x00010000] -> GPIO: ()
460 * PEDIR[14] = 0 [0x00020000] -> GPIO: ()
461 */
462 clrbits_be32(&cp->cp_pedir, 0x0003B732);
463
464 /*
465 * PAODR[10] = 0 [0x0020] -> GPIO: ()
466 */
467 clrbits_be16(&iop->iop_paodr, 0x0020);
468
469 /*
470 * PBODR[16] = 0 [0x00008000] -> GPIO: ()
471 */
472 clrbits_be16(&cp->cp_pbodr, 0x00008000);
473
474 /*
475 * PEODR[30] = 0 [0x00000002] -> GPIO: ()
476 * PEODR[18] = 0 [0x00002000] -> GPIO: ()
477 */
478 clrbits_be32(&cp->cp_peodr, 0x00002002);
479
480 /*
481 * PESO[24] = 0 [0x00000080] -> GPIO: ()
482 * PESO[23] = 0 [0x00000100] -> GPIO: ()
483 * PESO[20] = 0 [0x00000800] -> GPIO: ()
484 * PESO[19] = 0 [0x00001000] -> GPIO: ()
485 * PESO[15] = 0 [0x00010000] -> GPIO: ()
486 * PESO[14] = 0 [0x00020000] -> GPIO: ()
487 */
488 clrbits_be32(&cp->cp_peso, 0x00031980);
489}
490
491int board_early_init_f(void)
492{
493 return 0;
494}
495
496/* Specific board initialization */
497int board_early_init_r(void)
498{
499 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
500 iop8xx_t __iomem *iop = &immr->im_ioport;
501 cpm8xx_t __iomem *cp = &immr->im_cpm;
502
503 /* MPC885 Port settings common to all boards */
504 setbits_be16(&iop->iop_padat, 0x0000);
505
506 /* Port A (MPC885 reference manual - 34.2) */
507 /*
508 * In/Out or per. Function 0/1
509 * PADIR[15] = 0 [0x0001] -> GPIO: (USB_RXD)
510 * PADIR[14] = 0 [0x0002] -> GPIO: (USB_OE)
511 * PADIR[13] = 0 [0x0004] -> GPIO: ()
512 * PADIR[12] = 0 [0x0008] -> GPIO: ()
513 * PADIR[11] = 1 [0x0010] -> GPIO: (R1_TXD0)
514 * PADIR[10] = 0 [0x0020] -> GPIO: ()
515 * PADIR[7] = 0 [0x0100] -> GPIO: ()
516 * PADIR[6] = 0 [0x0200] -> GPIO: ()
517 * PADIR[4] = 1 [0x0800] -> GPIO: (R1_TXD1)
518 * PADIR[3] = 0 [0x1000] -> GPIO: (R1_RXER)
519 * PADIR[2] = 0 [0x2000] -> GPIO: (R1_CRS_DV)
520 * PADIR[1] = 0 [0x4000] -> GPIO: (R1_RXD0)
521 * PADIR[0] = 0 [0x8000] -> GPIO: (R1_RXD1)
522 */
523 clrsetbits_be16(&iop->iop_padir, 0xFB3F, 0x0810);
524
525 /*
526 * Open drain or active output
527 * PAODR[15] = x [0x0001]
528 * PAODR[14] = 0 [0x0002]
529 * PAODR[13] = x [0x0004]
530 * PAODR[12] = 0 [0x0008]
531 * PAODR[11] = 0 [0x0010]
532 * PAODR[9] = 0 [0x0040]
533 * PAODR[8] = 0 [0x0080]
534 * PAODR[7] = 0 [0x0100]
535 */
536 clrbits_be16(&iop->iop_paodr, 0x01DF);
537
538 /*
539 * GPIO or per. Function
540 * PAPAR[15] = 1 [0x0001] -> GPIO: (USB_RXD)
541 * PAPAR[14] = 1 [0x0002] -> GPIO: (USB_OE)
542 * PAPAR[11] = 1 [0x0010] -> GPIO: (R1_TXD0)
543 * PAPAR[10] = 0 [0x0020] -> GPIO: (INIT_FPGA_F)
544 * PAPAR[5] = 0 [0x0400] -> GPIO: ()
545 * PAPAR[4] = 1 [0x0800] -> GPIO: (R1_TXD1)
546 * PAPAR[3] = 1 [0x1000] -> GPIO: (R1_RXER)
547 * PAPAR[2] = 1 [0x2000] -> GPIO: (R1_CRS_DV)
548 * PAPAR[1] = 1 [0x4000] -> GPIO: (R1_RXD0)
549 * PAPAR[0] = 1 [0x8000] -> GPIO: (R1_RXD1)
550 */
551 clrsetbits_be16(&iop->iop_papar, 0xFC33, 0xF813);
552
553 /* Port B (MPC885 reference manual - 34.3) */
554 /*
555 * In/Out or per. Function 0/1
556 * PBDIR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK)
557 * PBDIR[30] = 1 [0x00000002] -> GPIO: (CLK)
558 * PBDIR[29] = 1 [0x00000004] -> GPIO: (MOSI)
559 * PBDIR[28] = 1 [0x00000008] -> GPIO: (MISO)
560 * PBDIR[25] = 0 [0x00000040] -> GPIO: (SMTXD1)
561 * PBDIR[24] = 0 [0x00000080] -> GPIO: (SMRXD1)
562 * PBDIR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
563 * PBDIR[21] = 1 [0x00000400] -> GPIO: (CS_EEPROM)
564 * PBDIR[20] = 0 [0x00000800] -> GPIO: (SMRXD2)
565 * PBDIR[19] = 1 [0x00001000] -> GPIO: (WR_TEMP)
566 * PBDIR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
567 */
568 clrsetbits_be32(&cp->cp_pbdir, 0x00005ECF, 0x0000140E);
569
570 /*
571 * Open drain or active output
572 * PBODR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK)
573 * PBODR[30] = 0 [0x00000002] -> GPIO: (CLK)
574 * PBODR[29] = 0 [0x00000004] -> GPIO: (MOSI)
575 * PBODR[28] = 0 [0x00000008] -> GPIO: (MISO)
576 * PBODR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2)
577 * PBODR[26] = 0 [0x00000020] -> GPIO: (BRG02)
578 * PBODR[25] = 0 [0x00000040] -> GPIO: (SMTXD1)
579 * PBODR[24] = 0 [0x00000080] -> GPIO: (SMRXD1)
580 * PBODR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2)
581 * PBODR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
582 * PBODR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM)
583 * PBODR[20] = 0 [0x00000800] -> GPIO: (SMRXD2)
584 * PBODR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP)
585 * PBODR[18] = 0 [0x00002000] -> GPIO: (RTS2)
586 * PBODR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
587 */
588 clrbits_be16(&cp->cp_pbodr, 0x00007FFF);
589
590 /*
591 * GPIO or per. Function
592 * PBPAR[31] = 1 [0x00000001] -> GPIO: (R1_REF_CLK)
593 * PBPAR[30] = 1 [0x00000002] -> GPIO: (CLK)
594 * PBPAR[29] = 1 [0x00000004] -> GPIO: (MOSI)
595 * PBPAR[28] = 1 [0x00000008] -> GPIO: (MISO)
596 * PBPAR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2)
597 * PBPAR[26] = 0 [0x00000020] -> GPIO: (BRG02)
598 * PBPAR[25] = 1 [0x00000040] -> GPIO: (SMTXD1)
599 * PBPAR[24] = 1 [0x00000080] -> GPIO: (SMRXD1)
600 * PBPAR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2)
601 * PBPAR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
602 * PBPAR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM)
603 * PBPAR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP)
604 * PBPAR[18] = 0 [0x00002000] -> GPIO: (RTS2)
605 * PBPAR[15] = 0 [0x00010000] -> GPIO: (BRG03)
606 * PBPAR[14] = 0 [0x00020000] -> GPIO: (CS_TEMP)
607 */
608 clrsetbits_be32(&cp->cp_pbpar, 0x000337FF, 0x000000CF);
609
610 /* Port C (MPC885 Reference Manual - 34.4) */
611 /*
612 * In/Out or per. Function 0/1
613 * PCDIR[11] = 0 [0x0010] -> GPIO: (USB_RXP)
614 * PCDIR[10] = 0 [0x0020] -> GPIO: (USB_RXN)
615 * PCDIR[9] = 0 [0x0040] -> GPIO: (CTS2)
616 * PCDIR[7] = 1 [0x0100] -> GPIO: (USB_TXP)
617 * PCDIR[6] = 1 [0x0200] -> GPIO: (USB_TXN)
618 * PCDIR[5] = 0 [0x0400] -> GPIO: (CTS3)
619 */
620 clrsetbits_be16(&iop->iop_pcdir, 0x0770, 0x0300);
621
622 /*
623 * GPIO or per. Function
624 * PCPAR[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2)
625 * PCPAR[13] = 0 [0x0004] -> GPIO: (CS_POT1)
626 * PCPAR[12] = 0 [0x0008] -> GPIO: (CS_EEPROM2)
627 * PCPAR[11] = 0 [0x0010] -> GPIO: (USB_RXP)
628 * PCPAR[10] = 0 [0x0020] -> GPIO: (USB_RXN)
629 * PCPAR[9] = 0 [0x0040] -> GPIO: (CTS2)
630 * PCPAR[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV)
631 * PCPAR[7] = 1 [0x0100] -> GPIO: (USB_TXP)
632 * PCPAR[6] = 1 [0x0200] -> GPIO: (USB_TXN)
633 * PCPAR[5] = 0 [0x0400] -> GPIO: (CTS3)
634 * PCPAR[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO)
635 */
636 clrsetbits_be16(&iop->iop_pcpar, 0x0FFD, 0x0300);
637
638 /*
639 * Special Option register
640 * PCSO[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2)
641 * PCSO[14] = 0 [0x0002] -> GPIO: (CS_POT2)
642 * PCSO[13] = x [0x0004] -> Reserved
643 * PCSO[12] = x [0x0008] -> Reserved
644 * PCSO[11] = 1 [0x0010] -> GPIO: (USB_RXP)
645 * PCSO[10] = 1 [0x0020] -> GPIO: (USB_RXN)
646 * PCSO[9] = 1 [0x0040] -> GPIO: (CTS2)
647 * PCSO[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV)
648 * PCSO[7] = 0 [0x0100] -> GPIO: (USB_TXP)
649 * PCSO[6] = 0 [0x0200] -> GPIO: (USB_TXN)
650 * PCSO[5] = 1 [0x0400] -> GPIO: (CTS3)
651 * PCSO[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO)
652 */
653 clrsetbits_be16(&iop->iop_pcso, 0x0FF3, 0x0470);
654
655 /*
656 * Interrupt or IO
657 * PCINT[15] = 0 [0x0001] -> GPIO: ()
658 * PCINT[14] = 0 [0x0002] -> GPIO: ()
659 * PCINT[13] = 0 [0x0004] -> GPIO: ()
660 * PCINT[12] = 0 [0x0008] -> GPIO: ()
661 * PCINT[11] = 0 [0x0010] -> GPIO: (USB_RXP)
662 * PCINT[10] = 0 [0x0020] -> GPIO: (USB_RXN)
663 * PCINT[9] = 0 [0x0040] -> GPIO: ()
664 * PCINT[8] = 0 [0x0080] -> GPIO: ()
665 * PCINT[7] = 0 [0x0100] -> GPIO: (USB_TXP)
666 * PCINT[6] = 0 [0x0200] -> GPIO: (USB_TXN)
667 * PCINT[5] = 0 [0x0400] -> GPIO: ()
668 * PCINT[4] = 0 [0x0800] -> GPIO: ()
669 */
670 clrbits_be16(&iop->iop_pcint, 0x0FFF);
671
672 /* Port D (MPC885 Reference Manual - 34.5) */
673 /*
674 * In/Out or per. Function 0/1
675 * PDDIR[15] = 1 [0x0001] -> GPIO: (CS_NAND)
676 * PDDIR[14] = 0 [0x0002] -> GPIO: (TDM_FS_MPC)
677 * PDDIR[13] = 1 [0x0004] -> GPIO: (ALE_NAND)
678 * PDDIR[12] = 1 [0x0008] -> GPIO: (CLE_NAND)
679 * PDDIR[11] = 0 [0x0010] -> GPIO: (RXD3)
680 * PDDIR[10] = 0 [0x0020] -> GPIO: (TXD3)
681 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
682 * PDDIR[8] = 0 [0x0080] -> GPIO: (R_MDC)
683 * PDDIR[7] = 0 [0x0100] -> GPIO: (RTS3)
684 * PDDIR[5] = 0 [0x0400] -> GPIO: (CLK8)
685 * PDDIR[4] = 0 [0x0800] -> GPIO: (CLK4)
686 * PDDIR[3] = 0 [0x1000] -> GPIO: (CLK7)
687 */
688 clrsetbits_be16(&iop->iop_pddir, 0x1DFF, 0x004D);
689
690 /*
691 * GPIO or per. Function
692 * PDPAR[15] = 0 [0x0001] -> GPIO: (CS_NAND)
693 * PDPAR[13] = 0 [0x0004] -> GPIO: (ALE_NAND)
694 * PDPAR[12] = 0 [0x0008] -> GPIO: (CLE_NAND)
695 * PDPAR[8] = 1 [0x0080] -> GPIO: (R_MDC)
696 * PDPAR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO)
697 * PDPAR[4] = 1 [0x0800] -> GPIO: (CLK4)
698 */
699 clrsetbits_be16(&iop->iop_pdpar, 0x0A8D, 0x0880);
700
701 /* Port E (MPC885 Reference Manual - 34.6) */
702 /*
703 * In/Out or per. Function 0/1
704 * PEDIR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
705 * PEDIR[29] = 1 [0x00000004] -> GPIO: (USB_SPEED)
706 * PEDIR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND)
707 * PEDIR[25] = 0 [0x00000040] -> GPIO: (RXD4)
708 * PEDIR[24] = 0 [0x00000080] -> GPIO: (BRG01)
709 * PEDIR[20] = 0 [0x00000800] -> GPIO: (SMTXD2)
710 * PEDIR[17] = 0 [0x00004000] -> GPIO: (CLK5)
711 */
712 clrsetbits_be32(&cp->cp_pedir, 0x000048CD, 0x0000000C);
713
714 /*
715 * open drain or active output
716 * PEODR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
717 * PEODR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
718 * PEODR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND)
719 * PEODR[27] = 0 [0x00000010] -> GPIO: (R2_RXER)
720 * PEODR[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV)
721 * PEODR[25] = 0 [0x00000040] -> GPIO: (RXD4)
722 * PEODR[24] = 0 [0x00000080] -> GPIO: (BRG01)
723 * PEODR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
724 * PEODR[22] = 0 [0x00000200] -> GPIO: (R2_RXD1)
725 * PEODR[21] = 0 [0x00000400] -> GPIO: (R2_RXD0)
726 * PEODR[20] = 0 [0x00000800] -> GPIO: (SMTXD2)
727 * PEODR[19] = 0 [0x00001000] -> GPIO: (R2_TXEN)
728 * PEODR[17] = 0 [0x00004000] -> GPIO: (CLK5)
729 * PEODR[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK)
730 */
731 clrsetbits_be32(&cp->cp_peodr, 0x0000DFFD, 0x00000008);
732
733 /*
734 * GPIO or per. Function
735 * PEPAR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
736 * PEPAR[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE)
737 * PEPAR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
738 * PEPAR[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND)
739 * PEPAR[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
740 */
741 clrbits_be32(&cp->cp_pepar, 0x0000200F);
742
743 /*
744 * Special Option register
745 * PESO[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
746 * PESO[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE)
747 * PESO[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
748 * PESO[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND)
749 * PESO[27] = 0 [0x00000010] -> GPIO: (R2_RXER)
750 * PESO[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV)
751 * PESO[25] = 0 [0x00000040] -> GPIO: (RXD4)
752 * PESO[22] = 0 [0x00000200] -> GPIO: (R2_RXD1)
753 * PESO[21] = 0 [0x00000400] -> GPIO: (R2_RXD0)
754 * PESO[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
755 * PESO[17] = 0 [0x00004000] -> GPIO: (CLK5)
756 * PESO[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK)
757 */
758 clrbits_be32(&cp->cp_peso, 0x0000E67F);
759
760 /* Is a motherboard present ? */
761 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
762 /* Initialize signal PROG_FPGA_FIRMWARE */
763 out_be32(&cp->cp_pedat, 0x00000002);
764 out_be32(&cp->cp_peodr, 0x00000002);
765 out_be32(&cp->cp_pedir, 0x00000002);
766
767 /* Check if fpga firmware is loaded */
768 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
769 printf("Reloading FPGA firmware.\n");
770
771 /* Load fpga firmware */
772 /* Activate PROG_FPGA_FIRMWARE for 1 usec */
773 clrbits_be32(&cp->cp_pedat, 0x00000002);
774 udelay(1);
775 setbits_be32(&cp->cp_pedat, 0x00000002);
776
777 /* Wait 200 msec and check DONE_FPGA_FIRMWARE */
778 mdelay(200);
779 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
780 for (;;) {
781 printf("error loading firmware.\n");
782 mdelay(500);
783 }
784 }
785
786 /* Send a reset signal and wait for 20 msec */
787 clrbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS);
788 mdelay(20);
789 setbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS);
790 }
791
792 /* Wait 300 msec and check the reset state */
793 mdelay(300);
794 if (!(in_be16(ADDR_CPLD_R_RESET) & R_RESET_STATUS)) {
795 for (;;) {
796 printf("Could not reset FPGA.\n");
797 mdelay(500);
798 }
799 }
800
801 /* is FPGA firmware loaded ? */
802 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
803 printf("Reloading FPGA firmware\n");
804
805 /* Load FPGA firmware */
806 /* Activate PROG_FPGA_FIRMWARE for 1 usec */
807 clrbits_be32(&cp->cp_pedat, 0x00000002);
808 udelay(1);
809 setbits_be32(&cp->cp_pedat, 0x00000002);
810
811 /* Wait 200ms before checking DONE_FPGA_FIRMWARE */
812 mdelay(200);
813 }
814
815 /* Identify the type of mother board */
816 switch (in_8(ADDR_FPGA_R_BASE)) {
817 case TYPE_MCR:
818 iop_setup_mcr();
819 break;
820
821 default:
822 break;
823 }
824 /* CMPC885 board alone */
825 } else {
826 iop_setup_cmpc885();
827 }
828
829 return 0;
830}