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