]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/davedenx/qong/qong.c
ARM: implement relocation for ARM11
[karo-tx-uboot.git] / board / davedenx / qong / qong.c
1 /*
2  *
3  * (c) 2009 Emcraft Systems, Ilya Yanok <yanok@emcraft.com>
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 <netdev.h>
26 #include <asm/arch/mx31.h>
27 #include <asm/arch/mx31-regs.h>
28 #include <nand.h>
29 #include <fsl_pmic.h>
30 #include "qong_fpga.h"
31
32 DECLARE_GLOBAL_DATA_PTR;
33
34 int dram_init (void)
35 {
36         /* dram_init must store complete ramsize in gd->ram_size */
37         gd->ram_size = get_ram_size((volatile void *)CONFIG_SYS_SDRAM_BASE,
38                                 PHYS_SDRAM_1_SIZE);
39         return 0;
40 }
41
42 static void qong_fpga_reset(void)
43 {
44         mx31_gpio_set(QONG_FPGA_RST_PIN, 0);
45         udelay(30);
46         mx31_gpio_set(QONG_FPGA_RST_PIN, 1);
47
48         udelay(300);
49 }
50
51 int board_early_init_f (void)
52 {
53 #ifdef CONFIG_QONG_FPGA
54         /* CS1: FPGA/Network Controller/GPIO */
55         /* 16-bit, no DTACK */
56         __REG(CSCR_U(1)) = 0x00000A01;
57         __REG(CSCR_L(1)) = 0x20040501;
58         __REG(CSCR_A(1)) = 0x04020C00;
59
60         /* setup pins for FPGA */
61         mx31_gpio_mux(IOMUX_MODE(0x76, MUX_CTL_GPIO));
62         mx31_gpio_mux(IOMUX_MODE(0x7e, MUX_CTL_GPIO));
63         mx31_gpio_mux(IOMUX_MODE(0x91, MUX_CTL_OUT_FUNC | MUX_CTL_IN_GPIO));
64         mx31_gpio_mux(IOMUX_MODE(0x92, MUX_CTL_GPIO));
65         mx31_gpio_mux(IOMUX_MODE(0x93, MUX_CTL_GPIO));
66
67         /* FPGA reset  Pin */
68         /* rstn = 0 */
69         mx31_gpio_set(QONG_FPGA_RST_PIN, 0);
70         mx31_gpio_direction(QONG_FPGA_RST_PIN, MX31_GPIO_DIRECTION_OUT);
71
72         /* set interrupt pin as input */
73         mx31_gpio_direction(QONG_FPGA_IRQ_PIN, MX31_GPIO_DIRECTION_IN);
74
75 #endif
76
77         /* setup pins for UART1 */
78         mx31_gpio_mux(MUX_RXD1__UART1_RXD_MUX);
79         mx31_gpio_mux(MUX_TXD1__UART1_TXD_MUX);
80         mx31_gpio_mux(MUX_RTS1__UART1_RTS_B);
81         mx31_gpio_mux(MUX_CTS1__UART1_CTS_B);
82
83         /* setup pins for SPI (pmic) */
84         mx31_gpio_mux(MUX_CSPI2_SS0__CSPI2_SS0_B);
85         mx31_gpio_mux(MUX_CSPI2_MOSI__CSPI2_MOSI);
86         mx31_gpio_mux(MUX_CSPI2_MISO__CSPI2_MISO);
87         mx31_gpio_mux(MUX_CSPI2_SCLK__CSPI2_CLK);
88         mx31_gpio_mux(MUX_CSPI2_SPI_RDY__CSPI2_DATAREADY_B);
89
90         return 0;
91
92 }
93
94 int board_init (void)
95 {
96         /* Chip selects */
97         /* CS0: Nor Flash #0 - it must be init'ed when executing from DDR */
98         /* Assumptions: HCLK = 133 MHz, tACC = 130ns */
99         __REG(CSCR_U(0)) = ((0 << 31)   | /* SP */
100                                                 (0 << 30)       | /* WP */
101                                                 (0 << 28)       | /* BCD */
102                                                 (0 << 24)       | /* BCS */
103                                                 (0 << 22)       | /* PSZ */
104                                                 (0 << 21)       | /* PME */
105                                                 (0 << 20)       | /* SYNC */
106                                                 (0 << 16)       | /* DOL */
107                                                 (3 << 14)       | /* CNC */
108                                                 (21 << 8)       | /* WSC */
109                                                 (0 << 7)        | /* EW */
110                                                 (0 << 4)        | /* WWS */
111                                                 (6 << 0)          /* EDC */
112                                            );
113
114         __REG(CSCR_L(0)) = ((2 << 28)   | /* OEA */
115                                                 (1 << 24)       | /* OEN */
116                                                 (3 << 20)       | /* EBWA */
117                                                 (3 << 16)       | /* EBWN */
118                                                 (1 << 12)       | /* CSA */
119                                                 (1 << 11)       | /* EBC */
120                                                 (5 << 8)        | /* DSZ */
121                                                 (1 << 4)        | /* CSN */
122                                                 (0 << 3)        | /* PSR */
123                                                 (0 << 2)        | /* CRE */
124                                                 (0 << 1)        | /* WRAP */
125                                                 (1 << 0)          /* CSEN */
126                                            );
127
128         __REG(CSCR_A(0)) = ((2 << 28)   | /* EBRA */
129                                                 (1 << 24)       | /* EBRN */
130                                                 (2 << 20)       | /* RWA */
131                                                 (2 << 16)       | /* RWN */
132                                                 (0 << 15)       | /* MUM */
133                                                 (0 << 13)       | /* LAH */
134                                                 (2 << 10)       | /* LBN */
135                                                 (0 << 8)        | /* LBA */
136                                                 (0 << 6)        | /* DWW */
137                                                 (0 << 4)        | /* DCT */
138                                                 (0 << 3)        | /* WWU */
139                                                 (0 << 2)        | /* AGE */
140                                                 (0 << 1)        | /* CNC2 */
141                                                 (0 << 0)          /* FCE */
142                                            );
143
144         /* board id for linux */
145         gd->bd->bi_arch_number = MACH_TYPE_QONG;
146         gd->bd->bi_boot_params = (0x80000100);  /* adress of boot parameters */
147
148         return 0;
149 }
150
151 int board_late_init(void)
152 {
153         u32 val;
154
155         /* Enable RTC battery */
156         val = pmic_reg_read(REG_POWER_CTL0);
157         pmic_reg_write(REG_POWER_CTL0, val | COINCHEN);
158         pmic_reg_write(REG_INT_STATUS1, RTCRSTI);
159
160         return 0;
161 }
162
163 int checkboard (void)
164 {
165         printf("Board: DAVE/DENX Qong\n");
166         return 0;
167 }
168
169 int misc_init_r (void)
170 {
171 #ifdef CONFIG_QONG_FPGA
172         u32 tmp;
173
174         tmp = *(volatile u32*)QONG_FPGA_CTRL_VERSION;
175         printf("FPGA:  ");
176         printf("version register = %u.%u.%u\n",
177                 (tmp & 0xF000) >> 12, (tmp & 0x0F00) >> 8, tmp & 0x00FF);
178 #endif
179         return 0;
180 }
181
182 int board_eth_init(bd_t *bis)
183 {
184 #if defined(CONFIG_QONG_FPGA) && defined(CONFIG_DNET)
185         return dnet_eth_initialize(0, (void *)CONFIG_DNET_BASE, -1);
186 #else
187         return 0;
188 #endif
189 }
190
191 #if defined(CONFIG_QONG_FPGA) && defined(CONFIG_NAND_PLAT)
192 static void board_nand_setup(void)
193 {
194
195         /* CS3: NAND 8-bit */
196         __REG(CSCR_U(3)) = 0x00004f00;
197         __REG(CSCR_L(3)) = 0x20013b31;
198         __REG(CSCR_A(3)) = 0x00020800;
199         __REG(IOMUXC_GPR) |= 1 << 13;
200
201         mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_WP, MUX_CTL_IN_GPIO));
202         mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_CE, MUX_CTL_IN_GPIO));
203         mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_RB, MUX_CTL_IN_GPIO));
204
205         /* Make sure to reset the fpga else you cannot access NAND */
206         qong_fpga_reset();
207
208         /* Enable NAND flash */
209         mx31_gpio_set(15, 1);
210         mx31_gpio_set(14, 1);
211         mx31_gpio_direction(15, MX31_GPIO_DIRECTION_OUT);
212         mx31_gpio_direction(16, MX31_GPIO_DIRECTION_IN);
213         mx31_gpio_direction(14, MX31_GPIO_DIRECTION_IN);
214         mx31_gpio_set(15, 0);
215
216 }
217
218 int qong_nand_rdy(void *chip)
219 {
220         udelay(1);
221         return mx31_gpio_get(16);
222 }
223
224 void qong_nand_select_chip(struct mtd_info *mtd, int chip)
225 {
226         if (chip >= 0)
227                 mx31_gpio_set(15, 0);
228         else
229                 mx31_gpio_set(15, 1);
230
231 }
232
233 void qong_nand_plat_init(void *chip)
234 {
235         struct nand_chip *nand = (struct nand_chip *)chip;
236         nand->chip_delay = 20;
237         nand->select_chip = qong_nand_select_chip;
238         nand->options &= ~NAND_BUSWIDTH_16;
239         board_nand_setup();
240 }
241
242 #endif