Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 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 | |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 24 | #include <common.h> |
| 25 | #include <netdev.h> |
Stefano Babic | 78129d9 | 2011-03-14 15:43:56 +0100 | [diff] [blame] | 26 | #include <asm/arch/clock.h> |
| 27 | #include <asm/arch/imx-regs.h> |
Helmut Raiger | 035929c | 2011-09-29 05:45:03 +0000 | [diff] [blame^] | 28 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 53937da | 2010-10-05 14:05:11 +0200 | [diff] [blame] | 29 | #include <asm/io.h> |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 30 | #include <nand.h> |
Stefano Babic | f7bcd53 | 2010-04-16 17:13:54 +0200 | [diff] [blame] | 31 | #include <fsl_pmic.h> |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 32 | #include <asm/gpio.h> |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 33 | #include "qong_fpga.h" |
Stefano Babic | e3dd862 | 2011-02-02 00:49:37 +0000 | [diff] [blame] | 34 | #include <watchdog.h> |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
Stefano Babic | e3dd862 | 2011-02-02 00:49:37 +0000 | [diff] [blame] | 38 | #ifdef CONFIG_HW_WATCHDOG |
| 39 | void hw_watchdog_reset(void) |
| 40 | { |
| 41 | mxc_hw_watchdog_reset(); |
| 42 | } |
| 43 | #endif |
| 44 | |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 45 | int dram_init (void) |
| 46 | { |
Heiko Schocher | 504f87c | 2010-09-17 13:10:40 +0200 | [diff] [blame] | 47 | /* dram_init must store complete ramsize in gd->ram_size */ |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 48 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
Heiko Schocher | 504f87c | 2010-09-17 13:10:40 +0200 | [diff] [blame] | 49 | PHYS_SDRAM_1_SIZE); |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 50 | return 0; |
| 51 | } |
| 52 | |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 53 | static void qong_fpga_reset(void) |
| 54 | { |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 55 | gpio_set_value(QONG_FPGA_RST_PIN, 0); |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 56 | udelay(30); |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 57 | gpio_set_value(QONG_FPGA_RST_PIN, 1); |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 58 | |
| 59 | udelay(300); |
| 60 | } |
| 61 | |
Heiko Schocher | 504f87c | 2010-09-17 13:10:40 +0200 | [diff] [blame] | 62 | int board_early_init_f (void) |
| 63 | { |
| 64 | #ifdef CONFIG_QONG_FPGA |
Helmut Raiger | 035929c | 2011-09-29 05:45:03 +0000 | [diff] [blame^] | 65 | /* CS1: FPGA/Network Controller/GPIO, 16-bit, no DTACK */ |
| 66 | static const struct mxc_weimcs cs1 = { |
| 67 | /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */ |
| 68 | CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 1), |
| 69 | /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */ |
| 70 | CSCR_L(2, 0, 0, 4, 0, 0, 5, 0, 0, 0, 0, 1), |
| 71 | /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/ |
| 72 | CSCR_A(0, 4, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0) |
| 73 | }; |
| 74 | |
| 75 | mxc_setup_weimcs(1, &cs1); |
Heiko Schocher | 504f87c | 2010-09-17 13:10:40 +0200 | [diff] [blame] | 76 | |
| 77 | /* setup pins for FPGA */ |
| 78 | mx31_gpio_mux(IOMUX_MODE(0x76, MUX_CTL_GPIO)); |
| 79 | mx31_gpio_mux(IOMUX_MODE(0x7e, MUX_CTL_GPIO)); |
| 80 | mx31_gpio_mux(IOMUX_MODE(0x91, MUX_CTL_OUT_FUNC | MUX_CTL_IN_GPIO)); |
| 81 | mx31_gpio_mux(IOMUX_MODE(0x92, MUX_CTL_GPIO)); |
| 82 | mx31_gpio_mux(IOMUX_MODE(0x93, MUX_CTL_GPIO)); |
| 83 | |
| 84 | /* FPGA reset Pin */ |
| 85 | /* rstn = 0 */ |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 86 | gpio_direction_output(QONG_FPGA_RST_PIN, 0); |
Heiko Schocher | 504f87c | 2010-09-17 13:10:40 +0200 | [diff] [blame] | 87 | |
| 88 | /* set interrupt pin as input */ |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 89 | gpio_direction_input(QONG_FPGA_IRQ_PIN); |
Heiko Schocher | 504f87c | 2010-09-17 13:10:40 +0200 | [diff] [blame] | 90 | |
Stefano Babic | fbb1f58 | 2010-06-29 11:48:24 +0200 | [diff] [blame] | 91 | /* FPGA JTAG Interface */ |
| 92 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SFS6, MUX_CTL_GPIO)); |
| 93 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SCK6, MUX_CTL_GPIO)); |
| 94 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_CAPTURE, MUX_CTL_GPIO)); |
| 95 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_COMPARE, MUX_CTL_GPIO)); |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 96 | gpio_direction_output(QONG_FPGA_TCK_PIN, 0); |
| 97 | gpio_direction_output(QONG_FPGA_TMS_PIN, 0); |
| 98 | gpio_direction_output(QONG_FPGA_TDI_PIN, 0); |
| 99 | gpio_direction_input(QONG_FPGA_TDO_PIN); |
Heiko Schocher | 504f87c | 2010-09-17 13:10:40 +0200 | [diff] [blame] | 100 | #endif |
| 101 | |
| 102 | /* setup pins for UART1 */ |
| 103 | mx31_gpio_mux(MUX_RXD1__UART1_RXD_MUX); |
| 104 | mx31_gpio_mux(MUX_TXD1__UART1_TXD_MUX); |
| 105 | mx31_gpio_mux(MUX_RTS1__UART1_RTS_B); |
| 106 | mx31_gpio_mux(MUX_CTS1__UART1_CTS_B); |
| 107 | |
| 108 | /* setup pins for SPI (pmic) */ |
| 109 | mx31_gpio_mux(MUX_CSPI2_SS0__CSPI2_SS0_B); |
| 110 | mx31_gpio_mux(MUX_CSPI2_MOSI__CSPI2_MOSI); |
| 111 | mx31_gpio_mux(MUX_CSPI2_MISO__CSPI2_MISO); |
| 112 | mx31_gpio_mux(MUX_CSPI2_SCLK__CSPI2_CLK); |
| 113 | mx31_gpio_mux(MUX_CSPI2_SPI_RDY__CSPI2_DATAREADY_B); |
| 114 | |
Stefano Babic | 53937da | 2010-10-05 14:05:11 +0200 | [diff] [blame] | 115 | /* Setup pins for USB2 Host */ |
| 116 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_CLK, MUX_CTL_FUNC)); |
| 117 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DIR, MUX_CTL_FUNC)); |
| 118 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_NXT, MUX_CTL_FUNC)); |
| 119 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_STP, MUX_CTL_FUNC)); |
| 120 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DATA0, MUX_CTL_FUNC)); |
| 121 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_USBH2_DATA1, MUX_CTL_FUNC)); |
| 122 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_STXD3, MUX_CTL_FUNC)); |
| 123 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SRXD3, MUX_CTL_FUNC)); |
| 124 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SCK3, MUX_CTL_FUNC)); |
| 125 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SFS3, MUX_CTL_FUNC)); |
| 126 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_STXD6, MUX_CTL_FUNC)); |
| 127 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SRXD6, MUX_CTL_FUNC)); |
| 128 | |
| 129 | #define H2_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \ |
| 130 | PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU) |
| 131 | |
| 132 | mx31_set_pad(MX31_PIN_USBH2_CLK, H2_PAD_CFG); |
| 133 | mx31_set_pad(MX31_PIN_USBH2_DIR, H2_PAD_CFG); |
| 134 | mx31_set_pad(MX31_PIN_USBH2_NXT, H2_PAD_CFG); |
| 135 | mx31_set_pad(MX31_PIN_USBH2_STP, H2_PAD_CFG); |
| 136 | mx31_set_pad(MX31_PIN_USBH2_DATA0, H2_PAD_CFG); /* USBH2_DATA0 */ |
| 137 | mx31_set_pad(MX31_PIN_USBH2_DATA1, H2_PAD_CFG); /* USBH2_DATA1 */ |
| 138 | mx31_set_pad(MX31_PIN_SRXD6, H2_PAD_CFG); /* USBH2_DATA2 */ |
| 139 | mx31_set_pad(MX31_PIN_STXD6, H2_PAD_CFG); /* USBH2_DATA3 */ |
| 140 | mx31_set_pad(MX31_PIN_SFS3, H2_PAD_CFG); /* USBH2_DATA4 */ |
| 141 | mx31_set_pad(MX31_PIN_SCK3, H2_PAD_CFG); /* USBH2_DATA5 */ |
| 142 | mx31_set_pad(MX31_PIN_SRXD3, H2_PAD_CFG); /* USBH2_DATA6 */ |
| 143 | mx31_set_pad(MX31_PIN_STXD3, H2_PAD_CFG); /* USBH2_DATA7 */ |
| 144 | |
| 145 | writel(readl((IOMUXC_BASE + 0x8)) | (1 << 11), IOMUXC_BASE + 0x8); |
| 146 | |
Heiko Schocher | 504f87c | 2010-09-17 13:10:40 +0200 | [diff] [blame] | 147 | return 0; |
| 148 | |
| 149 | } |
| 150 | |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 151 | int board_init (void) |
| 152 | { |
| 153 | /* Chip selects */ |
| 154 | /* CS0: Nor Flash #0 - it must be init'ed when executing from DDR */ |
| 155 | /* Assumptions: HCLK = 133 MHz, tACC = 130ns */ |
Helmut Raiger | 035929c | 2011-09-29 05:45:03 +0000 | [diff] [blame^] | 156 | static const struct mxc_weimcs cs0 = { |
| 157 | /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */ |
| 158 | CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 3, 21, 0, 0, 6), |
| 159 | /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */ |
| 160 | CSCR_L(0, 1, 3, 3, 1, 1, 5, 1, 0, 0, 0, 1), |
| 161 | /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/ |
| 162 | CSCR_A(0, 1, 2, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0) |
| 163 | }; |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 164 | |
Helmut Raiger | 035929c | 2011-09-29 05:45:03 +0000 | [diff] [blame^] | 165 | mxc_setup_weimcs(0, &cs0); |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 166 | |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 167 | /* board id for linux */ |
| 168 | gd->bd->bi_arch_number = MACH_TYPE_QONG; |
| 169 | gd->bd->bi_boot_params = (0x80000100); /* adress of boot parameters */ |
| 170 | |
Stefano Babic | fbb1f58 | 2010-06-29 11:48:24 +0200 | [diff] [blame] | 171 | qong_fpga_init(); |
| 172 | |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
Stefano Babic | f7bcd53 | 2010-04-16 17:13:54 +0200 | [diff] [blame] | 176 | int board_late_init(void) |
| 177 | { |
| 178 | u32 val; |
| 179 | |
| 180 | /* Enable RTC battery */ |
| 181 | val = pmic_reg_read(REG_POWER_CTL0); |
| 182 | pmic_reg_write(REG_POWER_CTL0, val | COINCHEN); |
| 183 | pmic_reg_write(REG_INT_STATUS1, RTCRSTI); |
| 184 | |
Stefano Babic | e3dd862 | 2011-02-02 00:49:37 +0000 | [diff] [blame] | 185 | #ifdef CONFIG_HW_WATCHDOG |
| 186 | mxc_hw_watchdog_enable(); |
| 187 | #endif |
| 188 | |
Stefano Babic | f7bcd53 | 2010-04-16 17:13:54 +0200 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 192 | int checkboard (void) |
| 193 | { |
Stefano Babic | 44744cc | 2010-04-13 12:19:06 +0200 | [diff] [blame] | 194 | printf("Board: DAVE/DENX Qong\n"); |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | int misc_init_r (void) |
| 199 | { |
| 200 | #ifdef CONFIG_QONG_FPGA |
| 201 | u32 tmp; |
| 202 | |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 203 | tmp = *(volatile u32*)QONG_FPGA_CTRL_VERSION; |
| 204 | printf("FPGA: "); |
| 205 | printf("version register = %u.%u.%u\n", |
| 206 | (tmp & 0xF000) >> 12, (tmp & 0x0F00) >> 8, tmp & 0x00FF); |
| 207 | #endif |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | int board_eth_init(bd_t *bis) |
| 212 | { |
| 213 | #if defined(CONFIG_QONG_FPGA) && defined(CONFIG_DNET) |
| 214 | return dnet_eth_initialize(0, (void *)CONFIG_DNET_BASE, -1); |
| 215 | #else |
| 216 | return 0; |
| 217 | #endif |
| 218 | } |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 219 | |
| 220 | #if defined(CONFIG_QONG_FPGA) && defined(CONFIG_NAND_PLAT) |
| 221 | static void board_nand_setup(void) |
| 222 | { |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 223 | /* CS3: NAND 8-bit */ |
Helmut Raiger | 035929c | 2011-09-29 05:45:03 +0000 | [diff] [blame^] | 224 | static const struct mxc_weimcs cs3 = { |
| 225 | /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */ |
| 226 | CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 1, 15, 0, 0, 0), |
| 227 | /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */ |
| 228 | CSCR_L(2, 0, 0, 1, 3, 1, 3, 3, 0, 0, 0, 1), |
| 229 | /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/ |
| 230 | CSCR_A(0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0) |
| 231 | }; |
| 232 | |
| 233 | mxc_setup_weimcs(3, &cs3); |
| 234 | |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 235 | __REG(IOMUXC_GPR) |= 1 << 13; |
| 236 | |
| 237 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_WP, MUX_CTL_IN_GPIO)); |
| 238 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_CE, MUX_CTL_IN_GPIO)); |
| 239 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_NFC_RB, MUX_CTL_IN_GPIO)); |
| 240 | |
| 241 | /* Make sure to reset the fpga else you cannot access NAND */ |
| 242 | qong_fpga_reset(); |
| 243 | |
| 244 | /* Enable NAND flash */ |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 245 | gpio_set_value(15, 1); |
| 246 | gpio_set_value(14, 1); |
| 247 | gpio_direction_output(15, 0); |
| 248 | gpio_direction_input(16); |
| 249 | gpio_direction_input(14); |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 250 | |
| 251 | } |
| 252 | |
| 253 | int qong_nand_rdy(void *chip) |
| 254 | { |
| 255 | udelay(1); |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 256 | return gpio_get_value(16); |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void qong_nand_select_chip(struct mtd_info *mtd, int chip) |
| 260 | { |
| 261 | if (chip >= 0) |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 262 | gpio_set_value(15, 0); |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 263 | else |
Stefano Babic | 07184e8 | 2011-08-21 10:52:58 +0200 | [diff] [blame] | 264 | gpio_set_value(15, 1); |
Stefano Babic | e764c3d | 2010-03-29 16:43:39 +0200 | [diff] [blame] | 265 | |
| 266 | } |
| 267 | |
| 268 | void qong_nand_plat_init(void *chip) |
| 269 | { |
| 270 | struct nand_chip *nand = (struct nand_chip *)chip; |
| 271 | nand->chip_delay = 20; |
| 272 | nand->select_chip = qong_nand_select_chip; |
| 273 | nand->options &= ~NAND_BUSWIDTH_16; |
| 274 | board_nand_setup(); |
| 275 | } |
| 276 | |
| 277 | #endif |