blob: ae77fc2fd124fb4a3cbcf00aa06fbe0f373b9803 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Eibachf74a0272014-11-13 19:21:18 +01002/*
3 * (C) Copyright 2014
Mario Sixb4893582018-03-06 08:04:58 +01004 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
Dirk Eibachf74a0272014-11-13 19:21:18 +01005 */
6
7#include <common.h>
8#include <command.h>
9#include <asm/processor.h>
10#include <asm/io.h>
Dirk Eibachf74a0272014-11-13 19:21:18 +010011#include <asm/global_data.h>
12
13#include "mpc8308.h"
14#include <gdsys_fpga.h>
15
16#define REFLECTION_TESTPATTERN 0xdede
17#define REFLECTION_TESTPATTERN_INV (~REFLECTION_TESTPATTERN & 0xffff)
18
19#ifdef CONFIG_SYS_FPGA_NO_RFL_HI
20#define REFLECTION_TESTREG reflection_low
21#else
22#define REFLECTION_TESTREG reflection_high
23#endif
24
25DECLARE_GLOBAL_DATA_PTR;
26
Mario Six78510212019-03-29 10:18:10 +010027#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
Mario Sixae0feaa2019-03-29 10:18:07 +010028/* as gpio output status cannot be read back, we have to buffer it locally */
29u32 gpio0_out;
30
31void setbits_gpio0_out(u32 mask)
32{
33 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
34
35 gpio0_out |= mask;
36 out_be32(&immr->gpio[0].dat, gpio0_out);
37}
38
39void clrbits_gpio0_out(u32 mask)
40{
41 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
42
43 gpio0_out &= ~mask;
44 out_be32(&immr->gpio[0].dat, gpio0_out);
45}
46
Mario Six3809c472019-03-29 10:18:06 +010047int get_fpga_state(uint dev)
Dirk Eibachf74a0272014-11-13 19:21:18 +010048{
49 return gd->arch.fpga_state[dev];
50}
51
Dirk Eibachf74a0272014-11-13 19:21:18 +010052int board_early_init_f(void)
53{
Mario Six3809c472019-03-29 10:18:06 +010054 uint k;
Dirk Eibachf74a0272014-11-13 19:21:18 +010055
56 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
57 gd->arch.fpga_state[k] = 0;
58
59 return 0;
60}
61
62int board_early_init_r(void)
63{
Mario Six3809c472019-03-29 10:18:06 +010064 uint k;
65 uint ctr;
Dirk Eibachf74a0272014-11-13 19:21:18 +010066
67 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
68 gd->arch.fpga_state[k] = 0;
69
70 /*
71 * reset FPGA
72 */
73 mpc8308_init();
74
75 mpc8308_set_fpga_reset(1);
76
77 mpc8308_setup_hw();
78
79 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
80 ctr = 0;
81 while (!mpc8308_get_fpga_done(k)) {
Mario Six3809c472019-03-29 10:18:06 +010082 mdelay(100);
Dirk Eibachf74a0272014-11-13 19:21:18 +010083 if (ctr++ > 5) {
84 gd->arch.fpga_state[k] |=
85 FPGA_STATE_DONE_FAILED;
86 break;
87 }
88 }
89 }
90
91 udelay(10);
92
93 mpc8308_set_fpga_reset(0);
94
95 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
96 /*
97 * wait for fpga out of reset
98 */
99 ctr = 0;
100 while (1) {
101 u16 val;
102
103 FPGA_SET_REG(k, reflection_low, REFLECTION_TESTPATTERN);
104
105 FPGA_GET_REG(k, REFLECTION_TESTREG, &val);
106 if (val == REFLECTION_TESTPATTERN_INV)
107 break;
108
Mario Six3809c472019-03-29 10:18:06 +0100109 mdelay(100);
Dirk Eibachf74a0272014-11-13 19:21:18 +0100110 if (ctr++ > 5) {
111 gd->arch.fpga_state[k] |=
112 FPGA_STATE_REFLECTION_FAILED;
113 break;
114 }
115 }
116 }
117
118 return 0;
119}
Mario Six78510212019-03-29 10:18:10 +0100120#endif