3 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/processor.h>
12 #include <asm/ppc4xx-gpio.h>
13 #include <asm/global_data.h>
16 #include <gdsys_fpga.h>
18 #define REFLECTION_TESTPATTERN 0xdede
19 #define REFLECTION_TESTPATTERN_INV (~REFLECTION_TESTPATTERN & 0xffff)
21 #ifdef CONFIG_SYS_FPGA_NO_RFL_HI
22 #define REFLECTION_TESTREG reflection_low
24 #define REFLECTION_TESTREG reflection_high
27 DECLARE_GLOBAL_DATA_PTR;
29 int get_fpga_state(unsigned dev)
31 return gd->arch.fpga_state[dev];
34 void print_fpga_state(unsigned dev)
36 if (gd->arch.fpga_state[dev] & FPGA_STATE_DONE_FAILED)
37 puts(" Waiting for FPGA-DONE timed out.\n");
38 if (gd->arch.fpga_state[dev] & FPGA_STATE_REFLECTION_FAILED)
39 puts(" FPGA reflection test failed.\n");
42 int board_early_init_f(void)
46 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
47 gd->arch.fpga_state[k] = 0;
49 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
50 mtdcr(UIC0ER, 0x00000000); /* disable all ints */
51 mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical */
52 mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */
53 mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
54 mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest prio */
55 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
58 * EBC Configuration Register: set ready timeout to 512 ebc-clks
61 mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */
65 int board_early_init_r(void)
70 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
71 gd->arch.fpga_state[k] = 0;
78 gd405ep_set_fpga_reset(1);
82 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
84 while (!gd405ep_get_fpga_done(k)) {
87 gd->arch.fpga_state[k] |=
88 FPGA_STATE_DONE_FAILED;
96 gd405ep_set_fpga_reset(0);
98 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
100 * wait for fpga out of reset
106 FPGA_SET_REG(k, reflection_low, REFLECTION_TESTPATTERN);
108 FPGA_GET_REG(k, REFLECTION_TESTREG, &val);
109 if (val == REFLECTION_TESTPATTERN_INV)
114 gd->arch.fpga_state[k] |=
115 FPGA_STATE_REFLECTION_FAILED;