2 * Copyright (C) 2009 Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/types.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/memory.h>
23 #include <linux/platform_device.h>
24 #include <linux/mtd/physmap.h>
25 #include <linux/mtd/nand.h>
26 #include <linux/gpio.h>
28 #include <mach/hardware.h>
29 #include <mach/irqs.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/time.h>
33 #include <asm/mach/map.h>
34 #include <mach/common.h>
36 #include <asm/setup.h>
37 #include <mach/board-qong.h>
38 #include <mach/imx-uart.h>
39 #include <mach/iomux-mx3.h>
43 #define QONG_FPGA_VERSION(major, minor, rev) \
44 (((major & 0xF) << 12) | ((minor & 0xF) << 8) | (rev & 0xFF))
46 #define QONG_FPGA_BASEADDR CS1_BASE_ADDR
47 #define QONG_FPGA_PERIPH_SIZE (1 << 24)
49 #define QONG_FPGA_CTRL_BASEADDR QONG_FPGA_BASEADDR
50 #define QONG_FPGA_CTRL_SIZE 0x10
51 /* FPGA control registers */
52 #define QONG_FPGA_CTRL_VERSION 0x00
54 #define QONG_DNET_ID 1
55 #define QONG_DNET_BASEADDR \
56 (QONG_FPGA_BASEADDR + QONG_DNET_ID * QONG_FPGA_PERIPH_SIZE)
57 #define QONG_DNET_SIZE 0x00001000
59 #define QONG_FPGA_IRQ IOMUX_TO_IRQ(MX31_PIN_DTR_DCE1)
62 * This file contains the board-specific initialization routines.
65 static struct imxuart_platform_data uart_pdata = {
66 .flags = IMXUART_HAVE_RTSCTS,
69 static int uart_pins[] = {
76 static inline void mxc_init_imx_uart(void)
78 mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins),
80 mxc_register_device(&mxc_uart_device0, &uart_pdata);
83 static struct resource dnet_resources[] = {
85 .name = "dnet-memory",
86 .start = QONG_DNET_BASEADDR,
87 .end = QONG_DNET_BASEADDR + QONG_DNET_SIZE - 1,
88 .flags = IORESOURCE_MEM,
91 .start = QONG_FPGA_IRQ,
93 .flags = IORESOURCE_IRQ,
97 static struct platform_device dnet_device = {
100 .num_resources = ARRAY_SIZE(dnet_resources),
101 .resource = dnet_resources,
104 static int __init qong_init_dnet(void)
108 ret = platform_device_register(&dnet_device);
114 static struct physmap_flash_data qong_flash_data = {
118 static struct resource qong_flash_resource = {
119 .start = CS0_BASE_ADDR,
120 .end = CS0_BASE_ADDR + QONG_NOR_SIZE - 1,
121 .flags = IORESOURCE_MEM,
124 static struct platform_device qong_nor_mtd_device = {
125 .name = "physmap-flash",
128 .platform_data = &qong_flash_data,
130 .resource = &qong_flash_resource,
134 static void qong_init_nor_mtd(void)
136 (void)platform_device_register(&qong_nor_mtd_device);
140 * Hardware specific access to control-lines
142 static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
144 struct nand_chip *nand_chip = mtd->priv;
146 if (cmd == NAND_CMD_NONE)
150 writeb(cmd, nand_chip->IO_ADDR_W + (1 << 24));
152 writeb(cmd, nand_chip->IO_ADDR_W + (1 << 23));
156 * Read the Device Ready pin.
158 static int qong_nand_device_ready(struct mtd_info *mtd)
160 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_NFRB));
163 static void qong_nand_select_chip(struct mtd_info *mtd, int chip)
166 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
168 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 1);
171 static struct platform_nand_data qong_nand_data = {
177 .cmd_ctrl = qong_nand_cmd_ctrl,
178 .dev_ready = qong_nand_device_ready,
179 .select_chip = qong_nand_select_chip,
183 static struct resource qong_nand_resource = {
184 .start = CS3_BASE_ADDR,
185 .end = CS3_BASE_ADDR + SZ_32M - 1,
186 .flags = IORESOURCE_MEM,
189 static struct platform_device qong_nand_device = {
193 .platform_data = &qong_nand_data,
196 .resource = &qong_nand_resource,
199 static void __init qong_init_nand_mtd(void)
202 __raw_writel(0x00004f00, CSCR_U(3));
203 __raw_writel(0x20013b31, CSCR_L(3));
204 __raw_writel(0x00020800, CSCR_A(3));
205 mxc_iomux_set_gpr(MUX_SDCTL_CSD1_SEL, true);
208 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFCE_B, IOMUX_CONFIG_GPIO));
209 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), "nand_enable"))
210 gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
213 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFRB, IOMUX_CONFIG_GPIO));
214 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFRB), "nand_rdy"))
215 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFRB));
217 /* write protect pin */
218 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFWP_B, IOMUX_CONFIG_GPIO));
219 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFWP_B), "nand_wp"))
220 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFWP_B));
222 platform_device_register(&qong_nand_device);
225 static void __init qong_init_fpga(void)
230 regs = ioremap(QONG_FPGA_CTRL_BASEADDR, QONG_FPGA_CTRL_SIZE);
232 printk(KERN_ERR "%s: failed to map registers, aborting.\n",
237 fpga_ver = readl(regs + QONG_FPGA_CTRL_VERSION);
239 printk(KERN_INFO "Qong FPGA version %d.%d.%d\n",
240 (fpga_ver & 0xF000) >> 12,
241 (fpga_ver & 0x0F00) >> 8, fpga_ver & 0x00FF);
242 if (fpga_ver < QONG_FPGA_VERSION(0, 8, 7)) {
243 printk(KERN_ERR "qong: Unexpected FPGA version, FPGA-based "
244 "devices won't be registered!\n");
248 /* register FPGA-based devices */
249 qong_init_nand_mtd();
254 * This structure defines the MX31 memory map.
256 static struct map_desc qong_io_desc[] __initdata = {
258 .virtual = AIPS1_BASE_ADDR_VIRT,
259 .pfn = __phys_to_pfn(AIPS1_BASE_ADDR),
260 .length = AIPS1_SIZE,
261 .type = MT_DEVICE_NONSHARED
263 .virtual = AIPS2_BASE_ADDR_VIRT,
264 .pfn = __phys_to_pfn(AIPS2_BASE_ADDR),
265 .length = AIPS2_SIZE,
266 .type = MT_DEVICE_NONSHARED
271 * Set up static virtual mappings.
273 static void __init qong_map_io(void)
276 iotable_init(qong_io_desc, ARRAY_SIZE(qong_io_desc));
280 * Board specific initialization.
282 static void __init mxc_board_init(void)
289 static void __init qong_timer_init(void)
291 mx31_clocks_init(26000000);
294 static struct sys_timer qong_timer = {
295 .init = qong_timer_init,
299 * The following uses standard kernel macros defined in arch.h in order to
300 * initialize __mach_desc_QONG data structure.
303 MACHINE_START(QONG, "Dave/DENX QongEVB-LITE")
304 /* Maintainer: DENX Software Engineering GmbH */
305 .phys_io = AIPS1_BASE_ADDR,
306 .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
307 .boot_params = PHYS_OFFSET + 0x100,
308 .map_io = qong_map_io,
309 .init_irq = mxc_init_irq,
310 .init_machine = mxc_board_init,
311 .timer = &qong_timer,