blob: 42c45ecedceade1fa76c58f2e126b783a56aa50f [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
Dirk Eibachf74a0272014-11-13 19:21:18 +01007#include <command.h>
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Dirk Eibachf74a0272014-11-13 19:21:18 +01009#include <asm/processor.h>
10#include <asm/io.h>
Dirk Eibachf74a0272014-11-13 19:21:18 +010011#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060012#include <linux/delay.h>
Dirk Eibachf74a0272014-11-13 19:21:18 +010013
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 Six78510212019-03-29 10:18:10 +010028#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
Mario Sixae0feaa2019-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 Six3809c472019-03-29 10:18:06 +010048int get_fpga_state(uint dev)
Dirk Eibachf74a0272014-11-13 19:21:18 +010049{
50 return gd->arch.fpga_state[dev];
51}
52
Dirk Eibachf74a0272014-11-13 19:21:18 +010053int board_early_init_f(void)
54{
Mario Six3809c472019-03-29 10:18:06 +010055 uint k;
Dirk Eibachf74a0272014-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 Six3809c472019-03-29 10:18:06 +010065 uint k;
66 uint ctr;
Dirk Eibachf74a0272014-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 Six3809c472019-03-29 10:18:06 +010083 mdelay(100);
Dirk Eibachf74a0272014-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 Six3809c472019-03-29 10:18:06 +0100110 mdelay(100);
Dirk Eibachf74a0272014-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 Six78510212019-03-29 10:18:10 +0100121#endif