blob: 54c7eb3a12aba1abbf3f33e7dc0b6fb420ad3451 [file] [log] [blame]
Dirk Eibach81b37932011-01-21 09:31:21 +01001/*
2 * (C) Copyright 2010
3 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Dirk Eibach81b37932011-01-21 09:31:21 +01006 */
7
8#include <common.h>
9#include <command.h>
10#include <asm/processor.h>
11#include <asm/io.h>
12#include <asm/ppc4xx-gpio.h>
Dirk Eibach6b4b92f2012-04-26 03:54:23 +000013#include <dtt.h>
Dirk Eibach81b37932011-01-21 09:31:21 +010014
Dirk Eibach9a659572012-04-26 03:54:22 +000015#include "405ep.h"
Dirk Eibach81b37932011-01-21 09:31:21 +010016#include <gdsys_fpga.h>
17
18#include "../common/osd.h"
19
Dirk Eibach9a659572012-04-26 03:54:22 +000020#define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
21#define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
Dirk Eibachcf868222011-04-06 13:53:44 +020022#define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
Dirk Eibacha46eb6e2011-04-06 13:53:46 +020023#define LATCH3_BASE (CONFIG_SYS_LATCH_BASE + 0x300)
24
Dirk Eibach9a659572012-04-26 03:54:22 +000025#define LATCH2_MC2_PRESENT_N 0x0080
26
Dirk Eibach81b37932011-01-21 09:31:21 +010027enum {
Dirk Eibachfbb4e532015-10-28 11:46:28 +010028 UNITTYPE_MAIN = 1<<0,
29 UNITTYPE_SERVER = 1<<1,
30 UNITTYPE_DISPLAYPORT = 1<<2,
Dirk Eibach81b37932011-01-21 09:31:21 +010031};
32
33enum {
34 HWVER_101 = 0,
35 HWVER_110 = 1,
Dirk Eibachfbb4e532015-10-28 11:46:28 +010036 HWVER_130 = 2,
37 HWVER_140 = 3,
38 HWVER_150 = 4,
39 HWVER_160 = 5,
40 HWVER_170 = 6,
Dirk Eibach81b37932011-01-21 09:31:21 +010041};
42
43enum {
44 AUDIO_NONE = 0,
45 AUDIO_TX = 1,
46 AUDIO_RX = 2,
47 AUDIO_RXTX = 3,
48};
49
50enum {
51 SYSCLK_156250 = 2,
52};
53
54enum {
55 RAM_NONE = 0,
56 RAM_DDR2_32 = 1,
57 RAM_DDR2_64 = 2,
58};
59
Dirk Eibach20614a22013-06-26 16:04:26 +020060struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
61
Dirk Eibach6b4b92f2012-04-26 03:54:23 +000062int misc_init_r(void)
63{
64 /* startup fans */
65 dtt_init();
66
67 return 0;
68}
69
Dirk Eibacha46eb6e2011-04-06 13:53:46 +020070static unsigned int get_hwver(void)
71{
72 u16 latch3 = in_le16((void *)LATCH3_BASE);
73
74 return latch3 & 0x0003;
75}
76
77static unsigned int get_mc2_present(void)
78{
79 u16 latch2 = in_le16((void *)LATCH2_BASE);
80
81 return !(latch2 & LATCH2_MC2_PRESENT_N);
82}
83
Dirk Eibach81b37932011-01-21 09:31:21 +010084static void print_fpga_info(unsigned dev)
85{
Dirk Eibach20614a22013-06-26 16:04:26 +020086 u16 versions;
87 u16 fpga_version;
88 u16 fpga_features;
Dirk Eibach81b37932011-01-21 09:31:21 +010089 unsigned unit_type;
90 unsigned hardware_version;
Dirk Eibach81b37932011-01-21 09:31:21 +010091 unsigned feature_rs232;
92 unsigned feature_audio;
93 unsigned feature_sysclock;
94 unsigned feature_ramconfig;
95 unsigned feature_carrier_speed;
96 unsigned feature_carriers;
97 unsigned feature_video_channels;
98 int fpga_state = get_fpga_state(dev);
99
100 printf("FPGA%d: ", dev);
101
Dirk Eibach20614a22013-06-26 16:04:26 +0200102 FPGA_GET_REG(dev, versions, &versions);
103 FPGA_GET_REG(dev, fpga_version, &fpga_version);
104 FPGA_GET_REG(dev, fpga_features, &fpga_features);
105
Dirk Eibach81b37932011-01-21 09:31:21 +0100106 hardware_version = versions & 0x000f;
107
108 if (fpga_state
109 && !((hardware_version == HWVER_101)
110 && (fpga_state == FPGA_STATE_DONE_FAILED))) {
111 puts("not available\n");
112 print_fpga_state(dev);
113 return;
114 }
115
116 unit_type = (versions >> 4) & 0x000f;
117 hardware_version = versions & 0x000f;
Dirk Eibach81b37932011-01-21 09:31:21 +0100118 feature_rs232 = fpga_features & (1<<11);
119 feature_audio = (fpga_features >> 9) & 0x0003;
120 feature_sysclock = (fpga_features >> 7) & 0x0003;
121 feature_ramconfig = (fpga_features >> 5) & 0x0003;
122 feature_carrier_speed = fpga_features & (1<<4);
123 feature_carriers = (fpga_features >> 2) & 0x0003;
124 feature_video_channels = fpga_features & 0x0003;
125
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100126 if (unit_type & UNITTYPE_MAIN)
127 printf("Mainchannel ");
128 else
129 printf("Videochannel ");
Dirk Eibach81b37932011-01-21 09:31:21 +0100130
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100131 if (unit_type & UNITTYPE_SERVER)
132 printf("Serverside ");
133 else
134 printf("Userside ");
Dirk Eibach81b37932011-01-21 09:31:21 +0100135
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100136 if (unit_type & UNITTYPE_DISPLAYPORT)
137 printf("DisplayPort");
138 else
139 printf("DVI-DL");
140
141 switch (hardware_version) {
142 case HWVER_101:
143 printf(" HW-Ver 1.01\n");
Dirk Eibach81b37932011-01-21 09:31:21 +0100144 break;
145
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100146 case HWVER_110:
147 printf(" HW-Ver 1.10-1.20\n");
Dirk Eibach81b37932011-01-21 09:31:21 +0100148 break;
149
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100150 case HWVER_130:
151 printf(" HW-Ver 1.30\n");
Dirk Eibach81b37932011-01-21 09:31:21 +0100152 break;
Dirk Eibach81b37932011-01-21 09:31:21 +0100153
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100154 case HWVER_140:
155 printf(" HW-Ver 1.40-1.43\n");
Dirk Eibach81b37932011-01-21 09:31:21 +0100156 break;
157
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100158 case HWVER_150:
159 printf(" HW-Ver 1.50\n");
Dirk Eibach50477bf2012-04-26 03:54:24 +0000160 break;
161
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100162 case HWVER_160:
163 printf(" HW-Ver 1.60-1.61\n");
Dirk Eibach50477bf2012-04-26 03:54:24 +0000164 break;
165
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100166 case HWVER_170:
167 printf(" HW-Ver 1.70\n");
Dirk Eibach81b37932011-01-21 09:31:21 +0100168 break;
169
170 default:
171 printf(" HW-Ver %d(not supported)\n",
172 hardware_version);
173 break;
174 }
175
176 printf(" FPGA V %d.%02d, features:",
177 fpga_version / 100, fpga_version % 100);
178
179 printf(" %sRS232", feature_rs232 ? "" : "no ");
180
181 switch (feature_audio) {
182 case AUDIO_NONE:
183 printf(", no audio");
184 break;
185
186 case AUDIO_TX:
187 printf(", audio tx");
188 break;
189
190 case AUDIO_RX:
191 printf(", audio rx");
192 break;
193
194 case AUDIO_RXTX:
195 printf(", audio rx+tx");
196 break;
197
198 default:
199 printf(", audio %d(not supported)", feature_audio);
200 break;
201 }
202
203 switch (feature_sysclock) {
204 case SYSCLK_156250:
205 printf(", clock 156.25 MHz");
206 break;
207
208 default:
209 printf(", clock %d(not supported)", feature_sysclock);
210 break;
211 }
212
213 puts(",\n ");
214
215 switch (feature_ramconfig) {
216 case RAM_NONE:
217 printf("no RAM");
218 break;
219
220 case RAM_DDR2_32:
221 printf("RAM 32 bit DDR2");
222 break;
223
224 case RAM_DDR2_64:
225 printf("RAM 64 bit DDR2");
226 break;
227
228 default:
229 printf("RAM %d(not supported)", feature_ramconfig);
230 break;
231 }
232
233 printf(", %d carrier(s) %s", feature_carriers,
234 feature_carrier_speed ? "10 Gbit/s" : "of unknown speed");
235
236 printf(", %d video channel(s)\n", feature_video_channels);
237}
238
239/*
240 * Check Board Identity:
241 */
242int checkboard(void)
243{
Dirk Eibach6b4b92f2012-04-26 03:54:23 +0000244 char *s = getenv("serial#");
Dirk Eibach81b37932011-01-21 09:31:21 +0100245
Dirk Eibach6b4b92f2012-04-26 03:54:23 +0000246 puts("Board: ");
Dirk Eibach81b37932011-01-21 09:31:21 +0100247
Dirk Eibach6b4b92f2012-04-26 03:54:23 +0000248 puts("DLVision 10G");
Dirk Eibach81b37932011-01-21 09:31:21 +0100249
Dirk Eibach6b4b92f2012-04-26 03:54:23 +0000250 if (s != NULL) {
Dirk Eibach81b37932011-01-21 09:31:21 +0100251 puts(", serial# ");
Dirk Eibach6b4b92f2012-04-26 03:54:23 +0000252 puts(s);
Dirk Eibach81b37932011-01-21 09:31:21 +0100253 }
254
255 puts("\n");
256
Dirk Eibach81b37932011-01-21 09:31:21 +0100257 return 0;
258}
259
260int last_stage_init(void)
261{
Dirk Eibach20614a22013-06-26 16:04:26 +0200262 u16 versions;
263
264 FPGA_GET_REG(0, versions, &versions);
Dirk Eibachcf868222011-04-06 13:53:44 +0200265
Dirk Eibach6b4b92f2012-04-26 03:54:23 +0000266 print_fpga_info(0);
267 if (get_mc2_present())
268 print_fpga_info(1);
269
Dirk Eibachfbb4e532015-10-28 11:46:28 +0100270 if (((versions >> 4) & 0x000f) & UNITTYPE_SERVER)
Dirk Eibachcf868222011-04-06 13:53:44 +0200271 return 0;
272
Dirk Eibacha46eb6e2011-04-06 13:53:46 +0200273 if (!get_fpga_state(0) || (get_hwver() == HWVER_101))
Dirk Eibachcf868222011-04-06 13:53:44 +0200274 osd_probe(0);
Dirk Eibach81b37932011-01-21 09:31:21 +0100275
Dirk Eibacha46eb6e2011-04-06 13:53:46 +0200276 if (get_mc2_present() &&
277 (!get_fpga_state(1) || (get_hwver() == HWVER_101)))
Dirk Eibachcf868222011-04-06 13:53:44 +0200278 osd_probe(1);
Dirk Eibach81b37932011-01-21 09:31:21 +0100279
280 return 0;
281}
Dirk Eibach9a659572012-04-26 03:54:22 +0000282
283void gd405ep_init(void)
284{
285}
286
287void gd405ep_set_fpga_reset(unsigned state)
288{
289 if (state) {
290 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
291 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
292 } else {
293 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
294 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
295 }
296}
297
298void gd405ep_setup_hw(void)
299{
300 /*
301 * set "startup-finished"-gpios
302 */
303 gpio_write_bit(21, 0);
304 gpio_write_bit(22, 1);
305}
306
307int gd405ep_get_fpga_done(unsigned fpga)
308{
309 return in_le16((void *)LATCH2_BASE) & CONFIG_SYS_FPGA_DONE(fpga);
310}