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