tizen 2.4 release
[kernel/u-boot-tm1.git] / board / gdsys / 405ep / 405ep.c
1 /*
2  * (C) Copyright 2010
3  * Dirk Eibach,  Guntermann & Drunck GmbH, eibach@gdsys.de
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <command.h>
26 #include <asm/processor.h>
27 #include <asm/io.h>
28 #include <asm/ppc4xx-gpio.h>
29
30 #include "../common/fpga.h"
31
32 #define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
33 #define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
34 #define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
35
36 #define REFLECTION_TESTPATTERN 0xdede
37 #define REFLECTION_TESTPATTERN_INV (~REFLECTION_TESTPATTERN & 0xffff)
38
39 int board_early_init_f(void)
40 {
41         mtdcr(UIC0SR, 0xFFFFFFFF);      /* clear all ints */
42         mtdcr(UIC0ER, 0x00000000);      /* disable all ints */
43         mtdcr(UIC0CR, 0x00000000);      /* set all to be non-critical */
44         mtdcr(UIC0PR, 0xFFFFFF80);      /* set int polarities */
45         mtdcr(UIC0TR, 0x10000000);      /* set int trigger levels */
46         mtdcr(UIC0VCR, 0x00000001);     /* set vect base=0,INT0 highest prio */
47         mtdcr(UIC0SR, 0xFFFFFFFF);      /* clear all ints */
48
49         /*
50          * EBC Configuration Register: set ready timeout to 512 ebc-clks
51          * -> ca. 15 us
52          */
53         mtebc(EBC0_CFG, 0xa8400000);    /* ebc always driven */
54
55         /*
56          * setup io-latches for reset
57          */
58         out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
59         out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
60
61         /*
62          * set "startup-finished"-gpios
63          */
64         gpio_write_bit(21, 0);
65         gpio_write_bit(22, 1);
66
67         /*
68          * wait for fpga-done
69          * fail ungraceful if fpga is not configuring properly
70          */
71         while (!(in_le16((void *)LATCH2_BASE) & 0x0010))
72                 ;
73
74         /*
75          * setup io-latches for boot (stop reset)
76          */
77         udelay(10);
78         out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
79         out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
80
81         /*
82          * wait for fpga out of reset
83          * fail ungraceful if fpga is not working properly
84          */
85         while (1) {
86                 fpga_set_reg(CONFIG_SYS_FPGA_RFL_LOW, REFLECTION_TESTPATTERN);
87                 if (fpga_get_reg(CONFIG_SYS_FPGA_RFL_HIGH) ==
88                         REFLECTION_TESTPATTERN_INV)
89                         break;
90         }
91
92         return 0;
93 }