blob: 540b9d3c785d97ef7bb0c8c349b4cb54cb037dff [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
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
454 /* Set the front panel LED color to red */
Christophe Leroy452fd722023-04-05 18:50:23 +0200455 clrbits_8((unsigned char __iomem *)CONFIG_FPGA_BASE + 0x44, 0x02);
Christophe Leroy9646af32023-01-30 09:07:38 +0100456
457 /* We must initialize data before changing direction */
458 setbits_be16(&iop->iop_pcdat, 0x0888);
459 setbits_be16(&iop->iop_pddat, 0x0201);
460 setbits_be32(&cp->cp_pbdat, 0x00021510);
461 setbits_be32(&cp->cp_pedat, 0x00000002);
462
463 /*
464 * PAPAR[13] = 1 [0x0004] -> GPIO: (RXD2)
465 * PAPAR[12] = 1 [0x0008] -> GPIO: (TXD2)
466 * PAPAR[9] = 1 [0x0040] -> GPIO: (TDM1O)
467 * PAPAR[8] = 1 [0x0080] -> GPIO: (TDM1I)
468 * PAPAR[7] = 1 [0x0100] -> GPIO: (TDM_BCLK_MPC)
469 * PAPAR[6] = 1 [0x0200] -> GPIO: (CLK2)
470 */
471 setbits_be16(&iop->iop_papar, 0x03CC);
472
473 /*
474 * PBODR[16] = 0 [0x00008000] -> GPIO: (L1ST4)
475 */
476 clrbits_be16(&cp->cp_pbodr, 0x00008000);
477
478 /*
479 * PBDIR[27] = 1 [0x00000010] -> GPIO: (WR_TEMP2)
480 * PBDIR[26] = 1 [0x00000020] -> GPIO: (BRG02)
481 * PBDIR[23] = 1 [0x00000100] -> GPIO: (CS_TEMP2)
482 * PBDIR[18] = 1 [0x00002000] -> GPIO: (RTS2)
483 * PBDIR[16] = 0 [0x00008000] -> GPIO: (L1ST4)
484 * PBDIR[15] = 1 [0x00010000] -> GPIO: (BRG03)
485 * PBDIR[14] = 1 [0x00020000] -> GPIO: (CS_TEMP)
486 */
487 clrsetbits_be32(&cp->cp_pbdir, 0x0003A130, 0x00032130);
488
489 /*
490 * PBPAR[20] = 1 [0x00000800] -> GPIO: (SMRXD2)
491 * PBPAR[17] = 1 [0x00004000] -> GPIO: (L1ST3)
492 * PBPAR[16] = 1 [0x00008000] -> GPIO: (L1ST4)
493 */
494 setbits_be32(&cp->cp_pbpar, 0x0000C800);
495
496 /*
497 * PCPAR[14] = 1 [0x0002] -> GPIO: (L1ST2)
498 */
499 setbits_be16(&iop->iop_pcpar, 0x0002);
500
501 /*
502 * PDPAR[14] = 1 [0x0002] -> GPIO: (TDM_FS_MPC)
503 * PDPAR[11] = 1 [0x0010] -> GPIO: (RXD3)
504 * PDPAR[10] = 1 [0x0020] -> GPIO: (TXD3)
505 * PDPAR[9] = 1 [0x0040] -> GPIO: (TXD4)
506 * PDPAR[7] = 1 [0x0100] -> GPIO: (RTS3)
507 * PDPAR[5] = 1 [0x0400] -> GPIO: (CLK8)
508 * PDPAR[3] = 1 [0x1000] -> GPIO: (CLK7)
509 */
510 setbits_be16(&iop->iop_pdpar, 0x1572);
511
512 /*
513 * PEPAR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
514 * PEPAR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
515 * PEPAR[25] = 1 [0x00000040] -> GPIO: (RXD4)
516 * PEPAR[24] = 1 [0x00000080] -> GPIO: (BRG01)
517 * PEPAR[23] = 1 [0x00000100] -> GPIO: (L1ST1)
518 * PEPAR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
519 * PEPAR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
520 * PEPAR[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
521 * PEPAR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
522 * PEPAR[17] = 1 [0x00004000] -> GPIO: (CLK5)
523 * PEPAR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
524 * PEPAR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
525 * PEPAR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
526 */
527 setbits_be32(&cp->cp_pepar, 0x0003DFF0);
528
529 /*
530 * PADIR[9] = 1 [0x0040] -> GPIO: (TDM1O)
531 * PADIR[8] = 1 [0x0080] -> GPIO: (TDM1I)
532 * PADIR[5] = 0 [0x0400] -> GPIO: ()
533 */
534 clrsetbits_be16(&iop->iop_padir, 0x04C0, 0x00C0);
535
536 /*
537 * PCDIR[15] = 1 [0x0001] -> GPIO: (WP_EEPROM2)
538 * PCDIR[14] = 1 [0x0002] -> GPIO: (L1ST2)
539 * PCDIR[13] = 0 [0x0004] -> GPIO: ()
540 * PCDIR[12] = 1 [0x0008] -> GPIO: (CS_EEPROM2)
541 * PCDIR[8] = 1 [0x0080] -> GPIO: (CS_CODEC_2)
542 * PCDIR[4] = 1 [0x0800] -> GPIO: (CS_CODEC_1)
543 */
544 clrsetbits_be16(&iop->iop_pcdir, 0x088F, 0x088B);
545
546 /*
547 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
548 * PDDIR[6] = 1 [0x0200] -> GPIO: (CS_CODEC_3)
549 */
550 setbits_be16(&iop->iop_pddir, 0x0240);
551
552 /*
553 * PEDIR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
554 * PEDIR[27] = 1 [0x00000010] -> GPIO: (R2_RXER)
555 * PEDIR[26] = 1 [0x00000020] -> GPIO: (R2_CRS_DV)
556 * PEDIR[23] = 1 [0x00000100] -> GPIO: (L1ST1)
557 * PEDIR[22] = 1 [0x00000200] -> GPIO: (R2_RXD1)
558 * PEDIR[21] = 1 [0x00000400] -> GPIO: (R2_RXD0)
559 * PEDIR[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
560 * PEDIR[18] = 1 [0x00002000] -> GPIO: (PE18)
561 * PEDIR[16] = 1 [0x00008000] -> GPIO: (R2_REF_CLK)
562 * PEDIR[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
563 * PEDIR[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
564 */
565 setbits_be32(&cp->cp_pedir, 0x0003B732);
566
567 /*
568 * PAODR[10] = 1 [0x0020] -> GPIO: (INIT_FPGA_F)
569 */
570 setbits_be16(&iop->iop_paodr, 0x0020);
571
572 /*
573 * PEODR[30] = 1 [0x00000002] -> GPIO: (FPGA_FIRMWARE)
574 * PEODR[18] = 0 [0x00002000] -> GPIO: (PE18)
575 */
576 clrsetbits_be32(&cp->cp_peodr, 0x00002002, 0x00000002);
577
578 /*
579 * PESO[24] = 1 [0x00000080] -> GPIO: (BRG01)
580 * PESO[23] = 1 [0x00000100] -> GPIO: (L1ST1)
581 * PESO[20] = 1 [0x00000800] -> GPIO: (SMTXD2)
582 * PESO[19] = 1 [0x00001000] -> GPIO: (R2_TXEN)
583 * PESO[15] = 1 [0x00010000] -> GPIO: (R2_TXD1)
584 * PESO[14] = 1 [0x00020000] -> GPIO: (R2_TXD0)
585 */
586 setbits_be32(&cp->cp_peso, 0x00031980);
587}
588
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200589int board_early_init_f(void)
590{
591 return 0;
592}
593
594/* Specific board initialization */
595int board_early_init_r(void)
596{
597 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
598 iop8xx_t __iomem *iop = &immr->im_ioport;
599 cpm8xx_t __iomem *cp = &immr->im_cpm;
600
601 /* MPC885 Port settings common to all boards */
602 setbits_be16(&iop->iop_padat, 0x0000);
603
604 /* Port A (MPC885 reference manual - 34.2) */
605 /*
606 * In/Out or per. Function 0/1
607 * PADIR[15] = 0 [0x0001] -> GPIO: (USB_RXD)
608 * PADIR[14] = 0 [0x0002] -> GPIO: (USB_OE)
609 * PADIR[13] = 0 [0x0004] -> GPIO: ()
610 * PADIR[12] = 0 [0x0008] -> GPIO: ()
611 * PADIR[11] = 1 [0x0010] -> GPIO: (R1_TXD0)
612 * PADIR[10] = 0 [0x0020] -> GPIO: ()
613 * PADIR[7] = 0 [0x0100] -> GPIO: ()
614 * PADIR[6] = 0 [0x0200] -> GPIO: ()
615 * PADIR[4] = 1 [0x0800] -> GPIO: (R1_TXD1)
616 * PADIR[3] = 0 [0x1000] -> GPIO: (R1_RXER)
617 * PADIR[2] = 0 [0x2000] -> GPIO: (R1_CRS_DV)
618 * PADIR[1] = 0 [0x4000] -> GPIO: (R1_RXD0)
619 * PADIR[0] = 0 [0x8000] -> GPIO: (R1_RXD1)
620 */
621 clrsetbits_be16(&iop->iop_padir, 0xFB3F, 0x0810);
622
623 /*
624 * Open drain or active output
625 * PAODR[15] = x [0x0001]
626 * PAODR[14] = 0 [0x0002]
627 * PAODR[13] = x [0x0004]
628 * PAODR[12] = 0 [0x0008]
629 * PAODR[11] = 0 [0x0010]
630 * PAODR[9] = 0 [0x0040]
631 * PAODR[8] = 0 [0x0080]
632 * PAODR[7] = 0 [0x0100]
633 */
634 clrbits_be16(&iop->iop_paodr, 0x01DF);
635
636 /*
637 * GPIO or per. Function
638 * PAPAR[15] = 1 [0x0001] -> GPIO: (USB_RXD)
639 * PAPAR[14] = 1 [0x0002] -> GPIO: (USB_OE)
640 * PAPAR[11] = 1 [0x0010] -> GPIO: (R1_TXD0)
641 * PAPAR[10] = 0 [0x0020] -> GPIO: (INIT_FPGA_F)
642 * PAPAR[5] = 0 [0x0400] -> GPIO: ()
643 * PAPAR[4] = 1 [0x0800] -> GPIO: (R1_TXD1)
644 * PAPAR[3] = 1 [0x1000] -> GPIO: (R1_RXER)
645 * PAPAR[2] = 1 [0x2000] -> GPIO: (R1_CRS_DV)
646 * PAPAR[1] = 1 [0x4000] -> GPIO: (R1_RXD0)
647 * PAPAR[0] = 1 [0x8000] -> GPIO: (R1_RXD1)
648 */
649 clrsetbits_be16(&iop->iop_papar, 0xFC33, 0xF813);
650
651 /* Port B (MPC885 reference manual - 34.3) */
652 /*
653 * In/Out or per. Function 0/1
654 * PBDIR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK)
655 * PBDIR[30] = 1 [0x00000002] -> GPIO: (CLK)
656 * PBDIR[29] = 1 [0x00000004] -> GPIO: (MOSI)
657 * PBDIR[28] = 1 [0x00000008] -> GPIO: (MISO)
658 * PBDIR[25] = 0 [0x00000040] -> GPIO: (SMTXD1)
659 * PBDIR[24] = 0 [0x00000080] -> GPIO: (SMRXD1)
660 * PBDIR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
661 * PBDIR[21] = 1 [0x00000400] -> GPIO: (CS_EEPROM)
662 * PBDIR[20] = 0 [0x00000800] -> GPIO: (SMRXD2)
663 * PBDIR[19] = 1 [0x00001000] -> GPIO: (WR_TEMP)
664 * PBDIR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
665 */
666 clrsetbits_be32(&cp->cp_pbdir, 0x00005ECF, 0x0000140E);
667
668 /*
669 * Open drain or active output
670 * PBODR[31] = 0 [0x00000001] -> GPIO: (R1_REF_CLK)
671 * PBODR[30] = 0 [0x00000002] -> GPIO: (CLK)
672 * PBODR[29] = 0 [0x00000004] -> GPIO: (MOSI)
673 * PBODR[28] = 0 [0x00000008] -> GPIO: (MISO)
674 * PBODR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2)
675 * PBODR[26] = 0 [0x00000020] -> GPIO: (BRG02)
676 * PBODR[25] = 0 [0x00000040] -> GPIO: (SMTXD1)
677 * PBODR[24] = 0 [0x00000080] -> GPIO: (SMRXD1)
678 * PBODR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2)
679 * PBODR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
680 * PBODR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM)
681 * PBODR[20] = 0 [0x00000800] -> GPIO: (SMRXD2)
682 * PBODR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP)
683 * PBODR[18] = 0 [0x00002000] -> GPIO: (RTS2)
684 * PBODR[17] = 0 [0x00004000] -> GPIO: (DONE_FPGA_MEZZ)
685 */
686 clrbits_be16(&cp->cp_pbodr, 0x00007FFF);
687
688 /*
689 * GPIO or per. Function
690 * PBPAR[31] = 1 [0x00000001] -> GPIO: (R1_REF_CLK)
691 * PBPAR[30] = 1 [0x00000002] -> GPIO: (CLK)
692 * PBPAR[29] = 1 [0x00000004] -> GPIO: (MOSI)
693 * PBPAR[28] = 1 [0x00000008] -> GPIO: (MISO)
694 * PBPAR[27] = 0 [0x00000010] -> GPIO: (WR_TEMP2)
695 * PBPAR[26] = 0 [0x00000020] -> GPIO: (BRG02)
696 * PBPAR[25] = 1 [0x00000040] -> GPIO: (SMTXD1)
697 * PBPAR[24] = 1 [0x00000080] -> GPIO: (SMRXD1)
698 * PBPAR[23] = 0 [0x00000100] -> GPIO: (CS_TEMP2)
699 * PBPAR[22] = 0 [0x00000200] -> GPIO: (INIT_FPGA_MEZZ)
700 * PBPAR[21] = 0 [0x00000400] -> GPIO: (CS_EEPROM)
701 * PBPAR[19] = 0 [0x00001000] -> GPIO: (WR_TEMP)
702 * PBPAR[18] = 0 [0x00002000] -> GPIO: (RTS2)
703 * PBPAR[15] = 0 [0x00010000] -> GPIO: (BRG03)
704 * PBPAR[14] = 0 [0x00020000] -> GPIO: (CS_TEMP)
705 */
706 clrsetbits_be32(&cp->cp_pbpar, 0x000337FF, 0x000000CF);
707
708 /* Port C (MPC885 Reference Manual - 34.4) */
709 /*
710 * In/Out or per. Function 0/1
711 * PCDIR[11] = 0 [0x0010] -> GPIO: (USB_RXP)
712 * PCDIR[10] = 0 [0x0020] -> GPIO: (USB_RXN)
713 * PCDIR[9] = 0 [0x0040] -> GPIO: (CTS2)
714 * PCDIR[7] = 1 [0x0100] -> GPIO: (USB_TXP)
715 * PCDIR[6] = 1 [0x0200] -> GPIO: (USB_TXN)
716 * PCDIR[5] = 0 [0x0400] -> GPIO: (CTS3)
717 */
718 clrsetbits_be16(&iop->iop_pcdir, 0x0770, 0x0300);
719
720 /*
721 * GPIO or per. Function
722 * PCPAR[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2)
723 * PCPAR[13] = 0 [0x0004] -> GPIO: (CS_POT1)
724 * PCPAR[12] = 0 [0x0008] -> GPIO: (CS_EEPROM2)
725 * PCPAR[11] = 0 [0x0010] -> GPIO: (USB_RXP)
726 * PCPAR[10] = 0 [0x0020] -> GPIO: (USB_RXN)
727 * PCPAR[9] = 0 [0x0040] -> GPIO: (CTS2)
728 * PCPAR[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV)
729 * PCPAR[7] = 1 [0x0100] -> GPIO: (USB_TXP)
730 * PCPAR[6] = 1 [0x0200] -> GPIO: (USB_TXN)
731 * PCPAR[5] = 0 [0x0400] -> GPIO: (CTS3)
732 * PCPAR[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO)
733 */
734 clrsetbits_be16(&iop->iop_pcpar, 0x0FFD, 0x0300);
735
736 /*
737 * Special Option register
738 * PCSO[15] = 0 [0x0001] -> GPIO: (WP_EEPROM2)
739 * PCSO[14] = 0 [0x0002] -> GPIO: (CS_POT2)
740 * PCSO[13] = x [0x0004] -> Reserved
741 * PCSO[12] = x [0x0008] -> Reserved
742 * PCSO[11] = 1 [0x0010] -> GPIO: (USB_RXP)
743 * PCSO[10] = 1 [0x0020] -> GPIO: (USB_RXN)
744 * PCSO[9] = 1 [0x0040] -> GPIO: (CTS2)
745 * PCSO[8] = 0 [0x0080] -> GPIO: (CS_CODEC_FAV)
746 * PCSO[7] = 0 [0x0100] -> GPIO: (USB_TXP)
747 * PCSO[6] = 0 [0x0200] -> GPIO: (USB_TXN)
748 * PCSO[5] = 1 [0x0400] -> GPIO: (CTS3)
749 * PCSO[4] = 0 [0x0800] -> GPIO: (CS_CODEC_RADIO)
750 */
751 clrsetbits_be16(&iop->iop_pcso, 0x0FF3, 0x0470);
752
753 /*
754 * Interrupt or IO
755 * PCINT[15] = 0 [0x0001] -> GPIO: ()
756 * PCINT[14] = 0 [0x0002] -> GPIO: ()
757 * PCINT[13] = 0 [0x0004] -> GPIO: ()
758 * PCINT[12] = 0 [0x0008] -> GPIO: ()
759 * PCINT[11] = 0 [0x0010] -> GPIO: (USB_RXP)
760 * PCINT[10] = 0 [0x0020] -> GPIO: (USB_RXN)
761 * PCINT[9] = 0 [0x0040] -> GPIO: ()
762 * PCINT[8] = 0 [0x0080] -> GPIO: ()
763 * PCINT[7] = 0 [0x0100] -> GPIO: (USB_TXP)
764 * PCINT[6] = 0 [0x0200] -> GPIO: (USB_TXN)
765 * PCINT[5] = 0 [0x0400] -> GPIO: ()
766 * PCINT[4] = 0 [0x0800] -> GPIO: ()
767 */
768 clrbits_be16(&iop->iop_pcint, 0x0FFF);
769
770 /* Port D (MPC885 Reference Manual - 34.5) */
771 /*
772 * In/Out or per. Function 0/1
773 * PDDIR[15] = 1 [0x0001] -> GPIO: (CS_NAND)
774 * PDDIR[14] = 0 [0x0002] -> GPIO: (TDM_FS_MPC)
775 * PDDIR[13] = 1 [0x0004] -> GPIO: (ALE_NAND)
776 * PDDIR[12] = 1 [0x0008] -> GPIO: (CLE_NAND)
777 * PDDIR[11] = 0 [0x0010] -> GPIO: (RXD3)
778 * PDDIR[10] = 0 [0x0020] -> GPIO: (TXD3)
779 * PDDIR[9] = 1 [0x0040] -> GPIO: (TXD4)
780 * PDDIR[8] = 0 [0x0080] -> GPIO: (R_MDC)
781 * PDDIR[7] = 0 [0x0100] -> GPIO: (RTS3)
782 * PDDIR[5] = 0 [0x0400] -> GPIO: (CLK8)
783 * PDDIR[4] = 0 [0x0800] -> GPIO: (CLK4)
784 * PDDIR[3] = 0 [0x1000] -> GPIO: (CLK7)
785 */
786 clrsetbits_be16(&iop->iop_pddir, 0x1DFF, 0x004D);
787
788 /*
789 * GPIO or per. Function
790 * PDPAR[15] = 0 [0x0001] -> GPIO: (CS_NAND)
791 * PDPAR[13] = 0 [0x0004] -> GPIO: (ALE_NAND)
792 * PDPAR[12] = 0 [0x0008] -> GPIO: (CLE_NAND)
793 * PDPAR[8] = 1 [0x0080] -> GPIO: (R_MDC)
794 * PDPAR[6] = 0 [0x0200] -> GPIO: (INIT_FPGA_RADIO)
795 * PDPAR[4] = 1 [0x0800] -> GPIO: (CLK4)
796 */
797 clrsetbits_be16(&iop->iop_pdpar, 0x0A8D, 0x0880);
798
799 /* Port E (MPC885 Reference Manual - 34.6) */
800 /*
801 * In/Out or per. Function 0/1
802 * PEDIR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
803 * PEDIR[29] = 1 [0x00000004] -> GPIO: (USB_SPEED)
804 * PEDIR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND)
805 * PEDIR[25] = 0 [0x00000040] -> GPIO: (RXD4)
806 * PEDIR[24] = 0 [0x00000080] -> GPIO: (BRG01)
807 * PEDIR[20] = 0 [0x00000800] -> GPIO: (SMTXD2)
808 * PEDIR[17] = 0 [0x00004000] -> GPIO: (CLK5)
809 */
810 clrsetbits_be32(&cp->cp_pedir, 0x000048CD, 0x0000000C);
811
812 /*
813 * open drain or active output
814 * PEODR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
815 * PEODR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
816 * PEODR[28] = 1 [0x00000008] -> GPIO: (USB_SUSPEND)
817 * PEODR[27] = 0 [0x00000010] -> GPIO: (R2_RXER)
818 * PEODR[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV)
819 * PEODR[25] = 0 [0x00000040] -> GPIO: (RXD4)
820 * PEODR[24] = 0 [0x00000080] -> GPIO: (BRG01)
821 * PEODR[23] = 0 [0x00000100] -> GPIO: (DONE_FPGA_RADIO)
822 * PEODR[22] = 0 [0x00000200] -> GPIO: (R2_RXD1)
823 * PEODR[21] = 0 [0x00000400] -> GPIO: (R2_RXD0)
824 * PEODR[20] = 0 [0x00000800] -> GPIO: (SMTXD2)
825 * PEODR[19] = 0 [0x00001000] -> GPIO: (R2_TXEN)
826 * PEODR[17] = 0 [0x00004000] -> GPIO: (CLK5)
827 * PEODR[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK)
828 */
829 clrsetbits_be32(&cp->cp_peodr, 0x0000DFFD, 0x00000008);
830
831 /*
832 * GPIO or per. Function
833 * PEPAR[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
834 * PEPAR[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE)
835 * PEPAR[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
836 * PEPAR[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND)
837 * PEPAR[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
838 */
839 clrbits_be32(&cp->cp_pepar, 0x0000200F);
840
841 /*
842 * Special Option register
843 * PESO[31] = 0 [0x00000001] -> GPIO: (DONE_FPGA_FIRMWARE)
844 * PESO[30] = 0 [0x00000002] -> GPIO: (PROG_FPGA_FIRMWARE)
845 * PESO[29] = 0 [0x00000004] -> GPIO: (USB_SPEED)
846 * PESO[28] = 0 [0x00000008] -> GPIO: (USB_SUSPEND)
847 * PESO[27] = 0 [0x00000010] -> GPIO: (R2_RXER)
848 * PESO[26] = 0 [0x00000020] -> GPIO: (R2_CRS_DV)
849 * PESO[25] = 0 [0x00000040] -> GPIO: (RXD4)
850 * PESO[22] = 0 [0x00000200] -> GPIO: (R2_RXD1)
851 * PESO[21] = 0 [0x00000400] -> GPIO: (R2_RXD0)
852 * PESO[18] = 0 [0x00002000] -> GPIO: (PROG_FPGA_RADIO)
853 * PESO[17] = 0 [0x00004000] -> GPIO: (CLK5)
854 * PESO[16] = 0 [0x00008000] -> GPIO: (R2_REF_CLK)
855 */
856 clrbits_be32(&cp->cp_peso, 0x0000E67F);
857
858 /* Is a motherboard present ? */
859 if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
860 /* Initialize signal PROG_FPGA_FIRMWARE */
861 out_be32(&cp->cp_pedat, 0x00000002);
862 out_be32(&cp->cp_peodr, 0x00000002);
863 out_be32(&cp->cp_pedir, 0x00000002);
864
865 /* Check if fpga firmware is loaded */
866 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
867 printf("Reloading FPGA firmware.\n");
868
869 /* Load fpga firmware */
870 /* Activate PROG_FPGA_FIRMWARE for 1 usec */
871 clrbits_be32(&cp->cp_pedat, 0x00000002);
872 udelay(1);
873 setbits_be32(&cp->cp_pedat, 0x00000002);
874
875 /* Wait 200 msec and check DONE_FPGA_FIRMWARE */
876 mdelay(200);
877 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
878 for (;;) {
879 printf("error loading firmware.\n");
880 mdelay(500);
881 }
882 }
883
884 /* Send a reset signal and wait for 20 msec */
885 clrbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS);
886 mdelay(20);
887 setbits_be16(ADDR_CPLD_R_RESET, R_RST_STATUS);
888 }
889
890 /* Wait 300 msec and check the reset state */
891 mdelay(300);
892 if (!(in_be16(ADDR_CPLD_R_RESET) & R_RESET_STATUS)) {
893 for (;;) {
894 printf("Could not reset FPGA.\n");
895 mdelay(500);
896 }
897 }
898
899 /* is FPGA firmware loaded ? */
900 if (!(in_be32(&cp->cp_pedat) & 0x00000001)) {
901 printf("Reloading FPGA firmware\n");
902
903 /* Load FPGA firmware */
904 /* Activate PROG_FPGA_FIRMWARE for 1 usec */
905 clrbits_be32(&cp->cp_pedat, 0x00000002);
906 udelay(1);
907 setbits_be32(&cp->cp_pedat, 0x00000002);
908
909 /* Wait 200ms before checking DONE_FPGA_FIRMWARE */
910 mdelay(200);
911 }
912
Christophe Leroy452fd722023-04-05 18:50:23 +0200913 iop_setup_common();
Christophe Leroy1fc46f52022-10-14 12:54:50 +0200914 } else {
915 iop_setup_cmpc885();
916 }
917
918 return 0;
919}