blob: a3079dbca367e2b7cb60b5c25a5c50ac8f22bc14 [file] [log] [blame]
Ilya Yanok0d19f6c2009-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 Yanok0d19f6c2009-02-10 00:22:31 +010024#include <common.h>
25#include <netdev.h>
Stefano Babic86271112011-03-14 15:43:56 +010026#include <asm/arch/clock.h>
27#include <asm/arch/imx-regs.h>
Helmut Raiger47c54552011-09-29 05:45:03 +000028#include <asm/arch/sys_proto.h>
Stefano Babicd7dc4642010-10-05 14:05:11 +020029#include <asm/io.h>
Stefano Babic45997e02010-03-29 16:43:39 +020030#include <nand.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000031#include <power/pmic.h>
Stefano Babice98ecd72010-04-16 17:13:54 +020032#include <fsl_pmic.h>
Stefano Babic9400f592011-08-21 10:52:58 +020033#include <asm/gpio.h>
Ilya Yanok0d19f6c2009-02-10 00:22:31 +010034#include "qong_fpga.h"
Stefano Babic8640c982011-02-02 00:49:37 +000035#include <watchdog.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000036#include <errno.h>
Ilya Yanok0d19f6c2009-02-10 00:22:31 +010037
38DECLARE_GLOBAL_DATA_PTR;
39
Stefano Babic8640c982011-02-02 00:49:37 +000040#ifdef CONFIG_HW_WATCHDOG
41void hw_watchdog_reset(void)
42{
43 mxc_hw_watchdog_reset();
44}
45#endif
46
Fabio Estevam77f11a92011-10-13 05:34:59 +000047int dram_init(void)
Ilya Yanok0d19f6c2009-02-10 00:22:31 +010048{
Heiko Schochere48b7c02010-09-17 13:10:40 +020049 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa55d23c2011-07-03 05:55:33 +000050 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
Heiko Schochere48b7c02010-09-17 13:10:40 +020051 PHYS_SDRAM_1_SIZE);
Ilya Yanok0d19f6c2009-02-10 00:22:31 +010052 return 0;
53}
54
Stefano Babic45997e02010-03-29 16:43:39 +020055static void qong_fpga_reset(void)
56{
Stefano Babic9400f592011-08-21 10:52:58 +020057 gpio_set_value(QONG_FPGA_RST_PIN, 0);
Stefano Babic45997e02010-03-29 16:43:39 +020058 udelay(30);
Stefano Babic9400f592011-08-21 10:52:58 +020059 gpio_set_value(QONG_FPGA_RST_PIN, 1);
Stefano Babic45997e02010-03-29 16:43:39 +020060
61 udelay(300);
62}
63
Fabio Estevam77f11a92011-10-13 05:34:59 +000064int board_early_init_f(void)
Heiko Schochere48b7c02010-09-17 13:10:40 +020065{
66#ifdef CONFIG_QONG_FPGA
Helmut Raiger47c54552011-09-29 05:45:03 +000067 /* CS1: FPGA/Network Controller/GPIO, 16-bit, no DTACK */
68 static const struct mxc_weimcs cs1 = {
69 /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */
70 CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 1),
71 /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */
72 CSCR_L(2, 0, 0, 4, 0, 0, 5, 0, 0, 0, 0, 1),
73 /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/
74 CSCR_A(0, 4, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0)
75 };
76
77 mxc_setup_weimcs(1, &cs1);
Heiko Schochere48b7c02010-09-17 13:10:40 +020078
79 /* setup pins for FPGA */
80 mx31_gpio_mux(IOMUX_MODE(0x76, MUX_CTL_GPIO));
81 mx31_gpio_mux(IOMUX_MODE(0x7e, MUX_CTL_GPIO));
82 mx31_gpio_mux(IOMUX_MODE(0x91, MUX_CTL_OUT_FUNC | MUX_CTL_IN_GPIO));
83 mx31_gpio_mux(IOMUX_MODE(0x92, MUX_CTL_GPIO));
84 mx31_gpio_mux(IOMUX_MODE(0x93, MUX_CTL_GPIO));
85
86 /* FPGA reset Pin */
87 /* rstn = 0 */
Stefano Babic9400f592011-08-21 10:52:58 +020088 gpio_direction_output(QONG_FPGA_RST_PIN, 0);
Heiko Schochere48b7c02010-09-17 13:10:40 +020089
90 /* set interrupt pin as input */
Stefano Babic9400f592011-08-21 10:52:58 +020091 gpio_direction_input(QONG_FPGA_IRQ_PIN);
Heiko Schochere48b7c02010-09-17 13:10:40 +020092
Stefano Babicb9eb3fd2010-06-29 11:48:24 +020093 /* FPGA JTAG Interface */
94 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SFS6, MUX_CTL_GPIO));
95 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SCK6, MUX_CTL_GPIO));
96 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_CAPTURE, MUX_CTL_GPIO));
97 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_COMPARE, MUX_CTL_GPIO));
Stefano Babic9400f592011-08-21 10:52:58 +020098 gpio_direction_output(QONG_FPGA_TCK_PIN, 0);
99 gpio_direction_output(QONG_FPGA_TMS_PIN, 0);
100 gpio_direction_output(QONG_FPGA_TDI_PIN, 0);
101 gpio_direction_input(QONG_FPGA_TDO_PIN);
Heiko Schochere48b7c02010-09-17 13:10:40 +0200102#endif
103
104 /* setup pins for UART1 */
105 mx31_gpio_mux(MUX_RXD1__UART1_RXD_MUX);
106 mx31_gpio_mux(MUX_TXD1__UART1_TXD_MUX);
107 mx31_gpio_mux(MUX_RTS1__UART1_RTS_B);
108 mx31_gpio_mux(MUX_CTS1__UART1_CTS_B);
109
110 /* setup pins for SPI (pmic) */
111 mx31_gpio_mux(MUX_CSPI2_SS0__CSPI2_SS0_B);
112 mx31_gpio_mux(MUX_CSPI2_MOSI__CSPI2_MOSI);
113 mx31_gpio_mux(MUX_CSPI2_MISO__CSPI2_MISO);
114 mx31_gpio_mux(MUX_CSPI2_SCLK__CSPI2_CLK);
115 mx31_gpio_mux(MUX_CSPI2_SPI_RDY__CSPI2_DATAREADY_B);
116
Stefano Babicd7dc4642010-10-05 14:05:11 +0200117 /* Setup pins for USB2 Host */
118 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_CLK, MUX_CTL_FUNC));
119 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DIR, MUX_CTL_FUNC));
120 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_NXT, MUX_CTL_FUNC));
121 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_STP, MUX_CTL_FUNC));
122 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DATA0, MUX_CTL_FUNC));
123 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DATA1, MUX_CTL_FUNC));
Stefano Babicd7dc4642010-10-05 14:05:11 +0200124
125#define H2_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
126 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
127
128 mx31_set_pad(MX31_PIN_USBH2_CLK, H2_PAD_CFG);
129 mx31_set_pad(MX31_PIN_USBH2_DIR, H2_PAD_CFG);
130 mx31_set_pad(MX31_PIN_USBH2_NXT, H2_PAD_CFG);
131 mx31_set_pad(MX31_PIN_USBH2_STP, H2_PAD_CFG);
132 mx31_set_pad(MX31_PIN_USBH2_DATA0, H2_PAD_CFG); /* USBH2_DATA0 */
133 mx31_set_pad(MX31_PIN_USBH2_DATA1, H2_PAD_CFG); /* USBH2_DATA1 */
134 mx31_set_pad(MX31_PIN_SRXD6, H2_PAD_CFG); /* USBH2_DATA2 */
135 mx31_set_pad(MX31_PIN_STXD6, H2_PAD_CFG); /* USBH2_DATA3 */
136 mx31_set_pad(MX31_PIN_SFS3, H2_PAD_CFG); /* USBH2_DATA4 */
137 mx31_set_pad(MX31_PIN_SCK3, H2_PAD_CFG); /* USBH2_DATA5 */
138 mx31_set_pad(MX31_PIN_SRXD3, H2_PAD_CFG); /* USBH2_DATA6 */
139 mx31_set_pad(MX31_PIN_STXD3, H2_PAD_CFG); /* USBH2_DATA7 */
140
Fabio Estevam842d8532011-10-20 16:01:30 +0000141 mx31_set_gpr(MUX_PGP_UH2, 1);
Stefano Babicd7dc4642010-10-05 14:05:11 +0200142
Heiko Schochere48b7c02010-09-17 13:10:40 +0200143 return 0;
144
145}
146
Fabio Estevam77f11a92011-10-13 05:34:59 +0000147int board_init(void)
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100148{
149 /* Chip selects */
150 /* CS0: Nor Flash #0 - it must be init'ed when executing from DDR */
151 /* Assumptions: HCLK = 133 MHz, tACC = 130ns */
Helmut Raiger47c54552011-09-29 05:45:03 +0000152 static const struct mxc_weimcs cs0 = {
153 /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */
154 CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 3, 21, 0, 0, 6),
155 /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */
156 CSCR_L(0, 1, 3, 3, 1, 1, 5, 1, 0, 0, 0, 1),
157 /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/
158 CSCR_A(0, 1, 2, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0)
159 };
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100160
Helmut Raiger47c54552011-09-29 05:45:03 +0000161 mxc_setup_weimcs(0, &cs0);
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100162
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100163 /* board id for linux */
164 gd->bd->bi_arch_number = MACH_TYPE_QONG;
165 gd->bd->bi_boot_params = (0x80000100); /* adress of boot parameters */
166
Stefano Babicb9eb3fd2010-06-29 11:48:24 +0200167 qong_fpga_init();
168
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100169 return 0;
170}
171
Stefano Babice98ecd72010-04-16 17:13:54 +0200172int board_late_init(void)
173{
174 u32 val;
Stefano Babicf33bd082011-10-06 11:23:33 +0200175 struct pmic *p;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000176 int ret;
Stefano Babicf33bd082011-10-06 11:23:33 +0200177
Łukasz Majewskic7336812012-11-13 03:21:55 +0000178 ret = pmic_init(I2C_PMIC);
179 if (ret)
180 return ret;
Stefano Babice98ecd72010-04-16 17:13:54 +0200181
Łukasz Majewskic7336812012-11-13 03:21:55 +0000182 p = pmic_get("FSL_PMIC");
183 if (!p)
184 return -ENODEV;
Stefano Babice98ecd72010-04-16 17:13:54 +0200185 /* Enable RTC battery */
Stefano Babicf33bd082011-10-06 11:23:33 +0200186 pmic_reg_read(p, REG_POWER_CTL0, &val);
187 pmic_reg_write(p, REG_POWER_CTL0, val | COINCHEN);
188 pmic_reg_write(p, REG_INT_STATUS1, RTCRSTI);
Stefano Babice98ecd72010-04-16 17:13:54 +0200189
Stefano Babic8640c982011-02-02 00:49:37 +0000190#ifdef CONFIG_HW_WATCHDOG
191 mxc_hw_watchdog_enable();
192#endif
193
Stefano Babice98ecd72010-04-16 17:13:54 +0200194 return 0;
195}
196
Fabio Estevam77f11a92011-10-13 05:34:59 +0000197int checkboard(void)
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100198{
Stefano Babiceeb50ce2010-04-13 12:19:06 +0200199 printf("Board: DAVE/DENX Qong\n");
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100200 return 0;
201}
202
Fabio Estevam77f11a92011-10-13 05:34:59 +0000203int misc_init_r(void)
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100204{
205#ifdef CONFIG_QONG_FPGA
206 u32 tmp;
207
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100208 tmp = *(volatile u32*)QONG_FPGA_CTRL_VERSION;
209 printf("FPGA: ");
210 printf("version register = %u.%u.%u\n",
211 (tmp & 0xF000) >> 12, (tmp & 0x0F00) >> 8, tmp & 0x00FF);
212#endif
Ilya Yanok0d19f6c2009-02-10 00:22:31 +0100213 return 0;
214}
215
216int board_eth_init(bd_t *bis)
217{
218#if defined(CONFIG_QONG_FPGA) && defined(CONFIG_DNET)
219 return dnet_eth_initialize(0, (void *)CONFIG_DNET_BASE, -1);
220#else
221 return 0;
222#endif
223}
Stefano Babic45997e02010-03-29 16:43:39 +0200224
225#if defined(CONFIG_QONG_FPGA) && defined(CONFIG_NAND_PLAT)
226static void board_nand_setup(void)
227{
Stefano Babic45997e02010-03-29 16:43:39 +0200228 /* CS3: NAND 8-bit */
Helmut Raiger47c54552011-09-29 05:45:03 +0000229 static const struct mxc_weimcs cs3 = {
230 /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */
231 CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 1, 15, 0, 0, 0),
232 /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */
233 CSCR_L(2, 0, 0, 1, 3, 1, 3, 3, 0, 0, 0, 1),
234 /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/
235 CSCR_A(0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0)
236 };
237
238 mxc_setup_weimcs(3, &cs3);
239
Fabio Estevamf6311722011-11-09 04:15:00 +0000240 mx31_set_gpr(MUX_SDCTL_CSD1_SEL, 1);
Stefano Babic45997e02010-03-29 16:43:39 +0200241
242 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_WP, MUX_CTL_IN_GPIO));
243 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_CE, MUX_CTL_IN_GPIO));
244 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_RB, MUX_CTL_IN_GPIO));
245
246 /* Make sure to reset the fpga else you cannot access NAND */
247 qong_fpga_reset();
248
249 /* Enable NAND flash */
Stefano Babic9400f592011-08-21 10:52:58 +0200250 gpio_set_value(15, 1);
251 gpio_set_value(14, 1);
252 gpio_direction_output(15, 0);
253 gpio_direction_input(16);
254 gpio_direction_input(14);
Stefano Babic45997e02010-03-29 16:43:39 +0200255
256}
257
258int qong_nand_rdy(void *chip)
259{
260 udelay(1);
Stefano Babic9400f592011-08-21 10:52:58 +0200261 return gpio_get_value(16);
Stefano Babic45997e02010-03-29 16:43:39 +0200262}
263
264void qong_nand_select_chip(struct mtd_info *mtd, int chip)
265{
266 if (chip >= 0)
Stefano Babic9400f592011-08-21 10:52:58 +0200267 gpio_set_value(15, 0);
Stefano Babic45997e02010-03-29 16:43:39 +0200268 else
Stefano Babic9400f592011-08-21 10:52:58 +0200269 gpio_set_value(15, 1);
Stefano Babic45997e02010-03-29 16:43:39 +0200270
271}
272
273void qong_nand_plat_init(void *chip)
274{
275 struct nand_chip *nand = (struct nand_chip *)chip;
276 nand->chip_delay = 20;
277 nand->select_chip = qong_nand_select_chip;
278 nand->options &= ~NAND_BUSWIDTH_16;
279 board_nand_setup();
280}
281
282#endif