1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 <asm/io.h>
29#include <nand.h>
30#include <fsl_pmic.h>
31#include <mxc_gpio.h>
32#include "qong_fpga.h"
33
34DECLARE_GLOBAL_DATA_PTR;
35
36int dram_init (void)
37{
38
39 gd->ram_size = get_ram_size((volatile void *)CONFIG_SYS_SDRAM_BASE,
40 PHYS_SDRAM_1_SIZE);
41 return 0;
42}
43
44static void qong_fpga_reset(void)
45{
46 mxc_gpio_set(QONG_FPGA_RST_PIN, 0);
47 udelay(30);
48 mxc_gpio_set(QONG_FPGA_RST_PIN, 1);
49
50 udelay(300);
51}
52
53int board_early_init_f (void)
54{
55#ifdef CONFIG_QONG_FPGA
56
57
58 __REG(CSCR_U(1)) = 0x00000A01;
59 __REG(CSCR_L(1)) = 0x20040501;
60 __REG(CSCR_A(1)) = 0x04020C00;
61
62
63 mx31_gpio_mux(IOMUX_MODE(0x76, MUX_CTL_GPIO));
64 mx31_gpio_mux(IOMUX_MODE(0x7e, MUX_CTL_GPIO));
65 mx31_gpio_mux(IOMUX_MODE(0x91, MUX_CTL_OUT_FUNC | MUX_CTL_IN_GPIO));
66 mx31_gpio_mux(IOMUX_MODE(0x92, MUX_CTL_GPIO));
67 mx31_gpio_mux(IOMUX_MODE(0x93, MUX_CTL_GPIO));
68
69
70
71 mxc_gpio_set(QONG_FPGA_RST_PIN, 0);
72 mxc_gpio_direction(QONG_FPGA_RST_PIN, MXC_GPIO_DIRECTION_OUT);
73
74
75 mxc_gpio_direction(QONG_FPGA_IRQ_PIN, MXC_GPIO_DIRECTION_IN);
76
77
78 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SFS6, MUX_CTL_GPIO));
79 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SCK6, MUX_CTL_GPIO));
80 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_CAPTURE, MUX_CTL_GPIO));
81 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_COMPARE, MUX_CTL_GPIO));
82 mxc_gpio_direction(QONG_FPGA_TCK_PIN, MXC_GPIO_DIRECTION_OUT);
83 mxc_gpio_direction(QONG_FPGA_TMS_PIN, MXC_GPIO_DIRECTION_OUT);
84 mxc_gpio_direction(QONG_FPGA_TDI_PIN, MXC_GPIO_DIRECTION_OUT);
85 mxc_gpio_direction(QONG_FPGA_TDO_PIN, MXC_GPIO_DIRECTION_IN);
86#endif
87
88
89 mx31_gpio_mux(MUX_RXD1__UART1_RXD_MUX);
90 mx31_gpio_mux(MUX_TXD1__UART1_TXD_MUX);
91 mx31_gpio_mux(MUX_RTS1__UART1_RTS_B);
92 mx31_gpio_mux(MUX_CTS1__UART1_CTS_B);
93
94
95 mx31_gpio_mux(MUX_CSPI2_SS0__CSPI2_SS0_B);
96 mx31_gpio_mux(MUX_CSPI2_MOSI__CSPI2_MOSI);
97 mx31_gpio_mux(MUX_CSPI2_MISO__CSPI2_MISO);
98 mx31_gpio_mux(MUX_CSPI2_SCLK__CSPI2_CLK);
99 mx31_gpio_mux(MUX_CSPI2_SPI_RDY__CSPI2_DATAREADY_B);
100
101
102 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_CLK, MUX_CTL_FUNC));
103 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DIR, MUX_CTL_FUNC));
104 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_NXT, MUX_CTL_FUNC));
105 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_STP, MUX_CTL_FUNC));
106 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DATA0, MUX_CTL_FUNC));
107 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DATA1, MUX_CTL_FUNC));
108 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_STXD3, MUX_CTL_FUNC));
109 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SRXD3, MUX_CTL_FUNC));
110 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SCK3, MUX_CTL_FUNC));
111 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SFS3, MUX_CTL_FUNC));
112 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_STXD6, MUX_CTL_FUNC));
113 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SRXD6, MUX_CTL_FUNC));
114
115#define H2_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
116 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
117
118 mx31_set_pad(MX31_PIN_USBH2_CLK, H2_PAD_CFG);
119 mx31_set_pad(MX31_PIN_USBH2_DIR, H2_PAD_CFG);
120 mx31_set_pad(MX31_PIN_USBH2_NXT, H2_PAD_CFG);
121 mx31_set_pad(MX31_PIN_USBH2_STP, H2_PAD_CFG);
122 mx31_set_pad(MX31_PIN_USBH2_DATA0, H2_PAD_CFG);
123 mx31_set_pad(MX31_PIN_USBH2_DATA1, H2_PAD_CFG);
124 mx31_set_pad(MX31_PIN_SRXD6, H2_PAD_CFG);
125 mx31_set_pad(MX31_PIN_STXD6, H2_PAD_CFG);
126 mx31_set_pad(MX31_PIN_SFS3, H2_PAD_CFG);
127 mx31_set_pad(MX31_PIN_SCK3, H2_PAD_CFG);
128 mx31_set_pad(MX31_PIN_SRXD3, H2_PAD_CFG);
129 mx31_set_pad(MX31_PIN_STXD3, H2_PAD_CFG);
130
131 writel(readl((IOMUXC_BASE + 0x8)) | (1 << 11), IOMUXC_BASE + 0x8);
132
133 return 0;
134
135}
136
137int board_init (void)
138{
139
140
141
142 __REG(CSCR_U(0)) = ((0 << 31) |
143 (0 << 30) |
144 (0 << 28) |
145 (0 << 24) |
146 (0 << 22) |
147 (0 << 21) |
148 (0 << 20) |
149 (0 << 16) |
150 (3 << 14) |
151 (21 << 8) |
152 (0 << 7) |
153 (0 << 4) |
154 (6 << 0)
155 );
156
157 __REG(CSCR_L(0)) = ((2 << 28) |
158 (1 << 24) |
159 (3 << 20) |
160 (3 << 16) |
161 (1 << 12) |
162 (1 << 11) |
163 (5 << 8) |
164 (1 << 4) |
165 (0 << 3) |
166 (0 << 2) |
167 (0 << 1) |
168 (1 << 0)
169 );
170
171 __REG(CSCR_A(0)) = ((2 << 28) |
172 (1 << 24) |
173 (2 << 20) |
174 (2 << 16) |
175 (0 << 15) |
176 (0 << 13) |
177 (2 << 10) |
178 (0 << 8) |
179 (0 << 6) |
180 (0 << 4) |
181 (0 << 3) |
182 (0 << 2) |
183 (0 << 1) |
184 (0 << 0)
185 );
186
187
188 gd->bd->bi_arch_number = MACH_TYPE_QONG;
189 gd->bd->bi_boot_params = (0x80000100);
190
191 qong_fpga_init();
192
193 return 0;
194}
195
196int board_late_init(void)
197{
198 u32 val;
199
200
201 val = pmic_reg_read(REG_POWER_CTL0);
202 pmic_reg_write(REG_POWER_CTL0, val | COINCHEN);
203 pmic_reg_write(REG_INT_STATUS1, RTCRSTI);
204
205 return 0;
206}
207
208int checkboard (void)
209{
210 printf("Board: DAVE/DENX Qong\n");
211 return 0;
212}
213
214int misc_init_r (void)
215{
216#ifdef CONFIG_QONG_FPGA
217 u32 tmp;
218
219 tmp = *(volatile u32*)QONG_FPGA_CTRL_VERSION;
220 printf("FPGA: ");
221 printf("version register = %u.%u.%u\n",
222 (tmp & 0xF000) >> 12, (tmp & 0x0F00) >> 8, tmp & 0x00FF);
223#endif
224 return 0;
225}
226
227int board_eth_init(bd_t *bis)
228{
229#if defined(CONFIG_QONG_FPGA) && defined(CONFIG_DNET)
230 return dnet_eth_initialize(0, (void *)CONFIG_DNET_BASE, -1);
231#else
232 return 0;
233#endif
234}
235
236#if defined(CONFIG_QONG_FPGA) && defined(CONFIG_NAND_PLAT)
237static void board_nand_setup(void)
238{
239
240
241 __REG(CSCR_U(3)) = 0x00004f00;
242 __REG(CSCR_L(3)) = 0x20013b31;
243 __REG(CSCR_A(3)) = 0x00020800;
244 __REG(IOMUXC_GPR) |= 1 << 13;
245
246 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_WP, MUX_CTL_IN_GPIO));
247 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_CE, MUX_CTL_IN_GPIO));
248 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_RB, MUX_CTL_IN_GPIO));
249
250
251 qong_fpga_reset();
252
253
254 mxc_gpio_set(15, 1);
255 mxc_gpio_set(14, 1);
256 mxc_gpio_direction(15, MXC_GPIO_DIRECTION_OUT);
257 mxc_gpio_direction(16, MXC_GPIO_DIRECTION_IN);
258 mxc_gpio_direction(14, MXC_GPIO_DIRECTION_IN);
259 mxc_gpio_set(15, 0);
260
261}
262
263int qong_nand_rdy(void *chip)
264{
265 udelay(1);
266 return mxc_gpio_get(16);
267}
268
269void qong_nand_select_chip(struct mtd_info *mtd, int chip)
270{
271 if (chip >= 0)
272 mxc_gpio_set(15, 0);
273 else
274 mxc_gpio_set(15, 1);
275
276}
277
278void qong_nand_plat_init(void *chip)
279{
280 struct nand_chip *nand = (struct nand_chip *)chip;
281 nand->chip_delay = 20;
282 nand->select_chip = qong_nand_select_chip;
283 nand->options &= ~NAND_BUSWIDTH_16;
284 board_nand_setup();
285}
286
287#endif
288