blob: ad1694b79fb7d7ef77af0a1014a9c006b731d2b1 [file] [log] [blame]
Ilya Yanok509a1ea2009-02-10 00:22:31 +01001/*
2 *
3 * (c) 2009 Emcraft Systems, Ilya Yanok <yanok@emcraft.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Ilya Yanok509a1ea2009-02-10 00:22:31 +01006 */
7
Ilya Yanok509a1ea2009-02-10 00:22:31 +01008#include <common.h>
9#include <netdev.h>
Stefano Babic78129d92011-03-14 15:43:56 +010010#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
Helmut Raiger035929c2011-09-29 05:45:03 +000012#include <asm/arch/sys_proto.h>
Stefano Babic53937da2010-10-05 14:05:11 +020013#include <asm/io.h>
Stefano Babice764c3d2010-03-29 16:43:39 +020014#include <nand.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000015#include <power/pmic.h>
Stefano Babicf7bcd532010-04-16 17:13:54 +020016#include <fsl_pmic.h>
Stefano Babic07184e82011-08-21 10:52:58 +020017#include <asm/gpio.h>
Ilya Yanok509a1ea2009-02-10 00:22:31 +010018#include "qong_fpga.h"
Stefano Babice3dd8622011-02-02 00:49:37 +000019#include <watchdog.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000020#include <errno.h>
Ilya Yanok509a1ea2009-02-10 00:22:31 +010021
22DECLARE_GLOBAL_DATA_PTR;
23
Fabio Estevamf231efb2011-10-13 05:34:59 +000024int dram_init(void)
Ilya Yanok509a1ea2009-02-10 00:22:31 +010025{
Heiko Schocher504f87c2010-09-17 13:10:40 +020026 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa9606732011-07-03 05:55:33 +000027 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
Heiko Schocher504f87c2010-09-17 13:10:40 +020028 PHYS_SDRAM_1_SIZE);
Ilya Yanok509a1ea2009-02-10 00:22:31 +010029 return 0;
30}
31
Stefano Babice764c3d2010-03-29 16:43:39 +020032static void qong_fpga_reset(void)
33{
Stefano Babic07184e82011-08-21 10:52:58 +020034 gpio_set_value(QONG_FPGA_RST_PIN, 0);
Stefano Babice764c3d2010-03-29 16:43:39 +020035 udelay(30);
Stefano Babic07184e82011-08-21 10:52:58 +020036 gpio_set_value(QONG_FPGA_RST_PIN, 1);
Stefano Babice764c3d2010-03-29 16:43:39 +020037
38 udelay(300);
39}
40
Fabio Estevamf231efb2011-10-13 05:34:59 +000041int board_early_init_f(void)
Heiko Schocher504f87c2010-09-17 13:10:40 +020042{
43#ifdef CONFIG_QONG_FPGA
Helmut Raiger035929c2011-09-29 05:45:03 +000044 /* CS1: FPGA/Network Controller/GPIO, 16-bit, no DTACK */
45 static const struct mxc_weimcs cs1 = {
46 /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */
47 CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 1),
48 /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */
49 CSCR_L(2, 0, 0, 4, 0, 0, 5, 0, 0, 0, 0, 1),
50 /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/
51 CSCR_A(0, 4, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0)
52 };
53
54 mxc_setup_weimcs(1, &cs1);
Heiko Schocher504f87c2010-09-17 13:10:40 +020055
56 /* setup pins for FPGA */
57 mx31_gpio_mux(IOMUX_MODE(0x76, MUX_CTL_GPIO));
58 mx31_gpio_mux(IOMUX_MODE(0x7e, MUX_CTL_GPIO));
59 mx31_gpio_mux(IOMUX_MODE(0x91, MUX_CTL_OUT_FUNC | MUX_CTL_IN_GPIO));
60 mx31_gpio_mux(IOMUX_MODE(0x92, MUX_CTL_GPIO));
61 mx31_gpio_mux(IOMUX_MODE(0x93, MUX_CTL_GPIO));
62
63 /* FPGA reset Pin */
64 /* rstn = 0 */
Stefano Babic07184e82011-08-21 10:52:58 +020065 gpio_direction_output(QONG_FPGA_RST_PIN, 0);
Heiko Schocher504f87c2010-09-17 13:10:40 +020066
67 /* set interrupt pin as input */
Stefano Babic07184e82011-08-21 10:52:58 +020068 gpio_direction_input(QONG_FPGA_IRQ_PIN);
Heiko Schocher504f87c2010-09-17 13:10:40 +020069
Stefano Babicfbb1f582010-06-29 11:48:24 +020070 /* FPGA JTAG Interface */
71 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SFS6, MUX_CTL_GPIO));
72 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SCK6, MUX_CTL_GPIO));
73 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_CAPTURE, MUX_CTL_GPIO));
74 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_COMPARE, MUX_CTL_GPIO));
Stefano Babic07184e82011-08-21 10:52:58 +020075 gpio_direction_output(QONG_FPGA_TCK_PIN, 0);
76 gpio_direction_output(QONG_FPGA_TMS_PIN, 0);
77 gpio_direction_output(QONG_FPGA_TDI_PIN, 0);
78 gpio_direction_input(QONG_FPGA_TDO_PIN);
Heiko Schocher504f87c2010-09-17 13:10:40 +020079#endif
80
81 /* setup pins for UART1 */
82 mx31_gpio_mux(MUX_RXD1__UART1_RXD_MUX);
83 mx31_gpio_mux(MUX_TXD1__UART1_TXD_MUX);
84 mx31_gpio_mux(MUX_RTS1__UART1_RTS_B);
85 mx31_gpio_mux(MUX_CTS1__UART1_CTS_B);
86
87 /* setup pins for SPI (pmic) */
88 mx31_gpio_mux(MUX_CSPI2_SS0__CSPI2_SS0_B);
89 mx31_gpio_mux(MUX_CSPI2_MOSI__CSPI2_MOSI);
90 mx31_gpio_mux(MUX_CSPI2_MISO__CSPI2_MISO);
91 mx31_gpio_mux(MUX_CSPI2_SCLK__CSPI2_CLK);
92 mx31_gpio_mux(MUX_CSPI2_SPI_RDY__CSPI2_DATAREADY_B);
93
Stefano Babic53937da2010-10-05 14:05:11 +020094 /* Setup pins for USB2 Host */
95 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_CLK, MUX_CTL_FUNC));
96 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DIR, MUX_CTL_FUNC));
97 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_NXT, MUX_CTL_FUNC));
98 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_STP, MUX_CTL_FUNC));
99 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DATA0, MUX_CTL_FUNC));
100 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DATA1, MUX_CTL_FUNC));
Stefano Babic53937da2010-10-05 14:05:11 +0200101
102#define H2_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
103 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
104
105 mx31_set_pad(MX31_PIN_USBH2_CLK, H2_PAD_CFG);
106 mx31_set_pad(MX31_PIN_USBH2_DIR, H2_PAD_CFG);
107 mx31_set_pad(MX31_PIN_USBH2_NXT, H2_PAD_CFG);
108 mx31_set_pad(MX31_PIN_USBH2_STP, H2_PAD_CFG);
109 mx31_set_pad(MX31_PIN_USBH2_DATA0, H2_PAD_CFG); /* USBH2_DATA0 */
110 mx31_set_pad(MX31_PIN_USBH2_DATA1, H2_PAD_CFG); /* USBH2_DATA1 */
111 mx31_set_pad(MX31_PIN_SRXD6, H2_PAD_CFG); /* USBH2_DATA2 */
112 mx31_set_pad(MX31_PIN_STXD6, H2_PAD_CFG); /* USBH2_DATA3 */
113 mx31_set_pad(MX31_PIN_SFS3, H2_PAD_CFG); /* USBH2_DATA4 */
114 mx31_set_pad(MX31_PIN_SCK3, H2_PAD_CFG); /* USBH2_DATA5 */
115 mx31_set_pad(MX31_PIN_SRXD3, H2_PAD_CFG); /* USBH2_DATA6 */
116 mx31_set_pad(MX31_PIN_STXD3, H2_PAD_CFG); /* USBH2_DATA7 */
117
Fabio Estevam717bd4a2011-10-20 16:01:30 +0000118 mx31_set_gpr(MUX_PGP_UH2, 1);
Stefano Babic53937da2010-10-05 14:05:11 +0200119
Heiko Schocher504f87c2010-09-17 13:10:40 +0200120 return 0;
121
122}
123
Fabio Estevamf231efb2011-10-13 05:34:59 +0000124int board_init(void)
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100125{
126 /* Chip selects */
127 /* CS0: Nor Flash #0 - it must be init'ed when executing from DDR */
128 /* Assumptions: HCLK = 133 MHz, tACC = 130ns */
Helmut Raiger035929c2011-09-29 05:45:03 +0000129 static const struct mxc_weimcs cs0 = {
130 /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */
131 CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 3, 21, 0, 0, 6),
132 /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */
133 CSCR_L(0, 1, 3, 3, 1, 1, 5, 1, 0, 0, 0, 1),
134 /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/
135 CSCR_A(0, 1, 2, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0)
136 };
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100137
Helmut Raiger035929c2011-09-29 05:45:03 +0000138 mxc_setup_weimcs(0, &cs0);
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100139
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100140 /* board id for linux */
141 gd->bd->bi_arch_number = MACH_TYPE_QONG;
142 gd->bd->bi_boot_params = (0x80000100); /* adress of boot parameters */
143
Stefano Babicfbb1f582010-06-29 11:48:24 +0200144 qong_fpga_init();
145
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100146 return 0;
147}
148
Stefano Babicf7bcd532010-04-16 17:13:54 +0200149int board_late_init(void)
150{
151 u32 val;
Stefano Babicd8deec72011-10-06 11:23:33 +0200152 struct pmic *p;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000153 int ret;
Stefano Babicd8deec72011-10-06 11:23:33 +0200154
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000155 ret = pmic_init(I2C_PMIC);
156 if (ret)
157 return ret;
Stefano Babicf7bcd532010-04-16 17:13:54 +0200158
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000159 p = pmic_get("FSL_PMIC");
160 if (!p)
161 return -ENODEV;
Stefano Babicf7bcd532010-04-16 17:13:54 +0200162 /* Enable RTC battery */
Stefano Babicd8deec72011-10-06 11:23:33 +0200163 pmic_reg_read(p, REG_POWER_CTL0, &val);
164 pmic_reg_write(p, REG_POWER_CTL0, val | COINCHEN);
165 pmic_reg_write(p, REG_INT_STATUS1, RTCRSTI);
Stefano Babicf7bcd532010-04-16 17:13:54 +0200166
Stefano Babice3dd8622011-02-02 00:49:37 +0000167#ifdef CONFIG_HW_WATCHDOG
Troy Kisky4b7c6022012-10-22 15:19:01 +0000168 hw_watchdog_init();
Stefano Babice3dd8622011-02-02 00:49:37 +0000169#endif
170
Stefano Babicf7bcd532010-04-16 17:13:54 +0200171 return 0;
172}
173
Fabio Estevamf231efb2011-10-13 05:34:59 +0000174int checkboard(void)
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100175{
Stefano Babic44744cc2010-04-13 12:19:06 +0200176 printf("Board: DAVE/DENX Qong\n");
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100177 return 0;
178}
179
Fabio Estevamf231efb2011-10-13 05:34:59 +0000180int misc_init_r(void)
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100181{
182#ifdef CONFIG_QONG_FPGA
183 u32 tmp;
184
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100185 tmp = *(volatile u32*)QONG_FPGA_CTRL_VERSION;
186 printf("FPGA: ");
187 printf("version register = %u.%u.%u\n",
188 (tmp & 0xF000) >> 12, (tmp & 0x0F00) >> 8, tmp & 0x00FF);
189#endif
Ilya Yanok509a1ea2009-02-10 00:22:31 +0100190 return 0;
191}
192
193int board_eth_init(bd_t *bis)
194{
195#if defined(CONFIG_QONG_FPGA) && defined(CONFIG_DNET)
196 return dnet_eth_initialize(0, (void *)CONFIG_DNET_BASE, -1);
197#else
198 return 0;
199#endif
200}
Stefano Babice764c3d2010-03-29 16:43:39 +0200201
202#if defined(CONFIG_QONG_FPGA) && defined(CONFIG_NAND_PLAT)
203static void board_nand_setup(void)
204{
Stefano Babice764c3d2010-03-29 16:43:39 +0200205 /* CS3: NAND 8-bit */
Helmut Raiger035929c2011-09-29 05:45:03 +0000206 static const struct mxc_weimcs cs3 = {
207 /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */
208 CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 1, 15, 0, 0, 0),
209 /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */
210 CSCR_L(2, 0, 0, 1, 3, 1, 3, 3, 0, 0, 0, 1),
211 /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/
212 CSCR_A(0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0)
213 };
214
215 mxc_setup_weimcs(3, &cs3);
216
Fabio Estevamd2a4cd32011-11-09 04:15:00 +0000217 mx31_set_gpr(MUX_SDCTL_CSD1_SEL, 1);
Stefano Babice764c3d2010-03-29 16:43:39 +0200218
219 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_WP, MUX_CTL_IN_GPIO));
220 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_CE, MUX_CTL_IN_GPIO));
221 mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_RB, MUX_CTL_IN_GPIO));
222
223 /* Make sure to reset the fpga else you cannot access NAND */
224 qong_fpga_reset();
225
226 /* Enable NAND flash */
Stefano Babic07184e82011-08-21 10:52:58 +0200227 gpio_set_value(15, 1);
228 gpio_set_value(14, 1);
229 gpio_direction_output(15, 0);
230 gpio_direction_input(16);
231 gpio_direction_input(14);
Stefano Babice764c3d2010-03-29 16:43:39 +0200232
233}
234
235int qong_nand_rdy(void *chip)
236{
237 udelay(1);
Stefano Babic07184e82011-08-21 10:52:58 +0200238 return gpio_get_value(16);
Stefano Babice764c3d2010-03-29 16:43:39 +0200239}
240
241void qong_nand_select_chip(struct mtd_info *mtd, int chip)
242{
243 if (chip >= 0)
Stefano Babic07184e82011-08-21 10:52:58 +0200244 gpio_set_value(15, 0);
Stefano Babice764c3d2010-03-29 16:43:39 +0200245 else
Stefano Babic07184e82011-08-21 10:52:58 +0200246 gpio_set_value(15, 1);
Stefano Babice764c3d2010-03-29 16:43:39 +0200247
248}
249
250void qong_nand_plat_init(void *chip)
251{
252 struct nand_chip *nand = (struct nand_chip *)chip;
253 nand->chip_delay = 20;
254 nand->select_chip = qong_nand_select_chip;
255 nand->options &= ~NAND_BUSWIDTH_16;
256 board_nand_setup();
257}
258
259#endif