blob: 426dc05c7d3cea53fda73193e25a3a2e40007aa2 [file] [log] [blame]
Dirk Eibach9a13d812010-10-21 10:50:05 +02001/*
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 Eibach9a13d812010-10-21 10:50:05 +02006 */
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 Eibach81b37932011-01-21 09:31:21 +010013#include <asm/global_data.h>
Dirk Eibach9a13d812010-10-21 10:50:05 +020014
Dirk Eibach9a659572012-04-26 03:54:22 +000015#include "405ep.h"
Dirk Eibach81b37932011-01-21 09:31:21 +010016#include <gdsys_fpga.h>
Dirk Eibach9a13d812010-10-21 10:50:05 +020017
Dirk Eibach9a13d812010-10-21 10:50:05 +020018#define REFLECTION_TESTPATTERN 0xdede
19#define REFLECTION_TESTPATTERN_INV (~REFLECTION_TESTPATTERN & 0xffff)
20
Dirk Eibach20614a22013-06-26 16:04:26 +020021#ifdef CONFIG_SYS_FPGA_NO_RFL_HI
22#define REFLECTION_TESTREG reflection_low
23#else
24#define REFLECTION_TESTREG reflection_high
25#endif
26
Dirk Eibach81b37932011-01-21 09:31:21 +010027DECLARE_GLOBAL_DATA_PTR;
28
29int get_fpga_state(unsigned dev)
30{
Simon Glassf2d9aaf2012-12-13 20:49:02 +000031 return gd->arch.fpga_state[dev];
Dirk Eibach81b37932011-01-21 09:31:21 +010032}
33
34void print_fpga_state(unsigned dev)
35{
Simon Glassf2d9aaf2012-12-13 20:49:02 +000036 if (gd->arch.fpga_state[dev] & FPGA_STATE_DONE_FAILED)
Dirk Eibach81b37932011-01-21 09:31:21 +010037 puts(" Waiting for FPGA-DONE timed out.\n");
Simon Glassf2d9aaf2012-12-13 20:49:02 +000038 if (gd->arch.fpga_state[dev] & FPGA_STATE_REFLECTION_FAILED)
Dirk Eibach81b37932011-01-21 09:31:21 +010039 puts(" FPGA reflection test failed.\n");
40}
41
Dirk Eibach9a13d812010-10-21 10:50:05 +020042int board_early_init_f(void)
43{
Dirk Eibach81b37932011-01-21 09:31:21 +010044 unsigned k;
Dirk Eibach81b37932011-01-21 09:31:21 +010045
46 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
Simon Glassf2d9aaf2012-12-13 20:49:02 +000047 gd->arch.fpga_state[k] = 0;
Dirk Eibach81b37932011-01-21 09:31:21 +010048
Dirk Eibach9a13d812010-10-21 10:50:05 +020049 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 */
56
57 /*
58 * EBC Configuration Register: set ready timeout to 512 ebc-clks
59 * -> ca. 15 us
60 */
61 mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */
Dirk Eibach9a659572012-04-26 03:54:22 +000062 return 0;
63}
Dirk Eibach9a13d812010-10-21 10:50:05 +020064
Dirk Eibach9a659572012-04-26 03:54:22 +000065int board_early_init_r(void)
66{
67 unsigned k;
68 unsigned ctr;
Dirk Eibach9a13d812010-10-21 10:50:05 +020069
Dirk Eibach9a659572012-04-26 03:54:22 +000070 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
Simon Glassf2d9aaf2012-12-13 20:49:02 +000071 gd->arch.fpga_state[k] = 0;
Dirk Eibach9a13d812010-10-21 10:50:05 +020072
73 /*
Dirk Eibach9a659572012-04-26 03:54:22 +000074 * reset FPGA
Dirk Eibach9a13d812010-10-21 10:50:05 +020075 */
Dirk Eibach9a659572012-04-26 03:54:22 +000076 gd405ep_init();
77
78 gd405ep_set_fpga_reset(1);
79
80 gd405ep_setup_hw();
81
Dirk Eibach81b37932011-01-21 09:31:21 +010082 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
83 ctr = 0;
Dirk Eibach9a659572012-04-26 03:54:22 +000084 while (!gd405ep_get_fpga_done(k)) {
Dirk Eibach81b37932011-01-21 09:31:21 +010085 udelay(100000);
86 if (ctr++ > 5) {
Simon Glassf2d9aaf2012-12-13 20:49:02 +000087 gd->arch.fpga_state[k] |=
88 FPGA_STATE_DONE_FAILED;
Dirk Eibach81b37932011-01-21 09:31:21 +010089 break;
90 }
91 }
92 }
Dirk Eibach9a13d812010-10-21 10:50:05 +020093
Dirk Eibach9a13d812010-10-21 10:50:05 +020094 udelay(10);
Dirk Eibach9a659572012-04-26 03:54:22 +000095
96 gd405ep_set_fpga_reset(0);
Dirk Eibach9a13d812010-10-21 10:50:05 +020097
Dirk Eibach81b37932011-01-21 09:31:21 +010098 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) {
Dirk Eibach81b37932011-01-21 09:31:21 +010099 /*
100 * wait for fpga out of reset
101 */
102 ctr = 0;
103 while (1) {
Dirk Eibach20614a22013-06-26 16:04:26 +0200104 u16 val;
105
106 FPGA_SET_REG(k, reflection_low, REFLECTION_TESTPATTERN);
Dirk Eibacha46eb6e2011-04-06 13:53:46 +0200107
Dirk Eibach20614a22013-06-26 16:04:26 +0200108 FPGA_GET_REG(k, REFLECTION_TESTREG, &val);
109 if (val == REFLECTION_TESTPATTERN_INV)
Dirk Eibach81b37932011-01-21 09:31:21 +0100110 break;
Dirk Eibacha46eb6e2011-04-06 13:53:46 +0200111
Dirk Eibach81b37932011-01-21 09:31:21 +0100112 udelay(100000);
113 if (ctr++ > 5) {
Simon Glassf2d9aaf2012-12-13 20:49:02 +0000114 gd->arch.fpga_state[k] |=
Dirk Eibach81b37932011-01-21 09:31:21 +0100115 FPGA_STATE_REFLECTION_FAILED;
116 break;
117 }
118 }
Dirk Eibach9a13d812010-10-21 10:50:05 +0200119 }
120
121 return 0;
122}