blob: 335b0bf93eb539aa7a66ad70400726ef0cbec218 [file] [log] [blame]
Ilya Yanok148854c2009-03-11 03:22:00 +03001/*
2 * Copyright (C) 2009 Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com>
3 *
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.
8 *
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.
Ilya Yanok148854c2009-03-11 03:22:00 +030013 */
14
15#include <linux/types.h>
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/memory.h>
19#include <linux/platform_device.h>
20#include <linux/mtd/physmap.h>
21#include <linux/mtd/nand.h>
22#include <linux/gpio.h>
23
24#include <mach/hardware.h>
25#include <mach/irqs.h>
26#include <asm/mach-types.h>
27#include <asm/mach/arch.h>
28#include <asm/mach/time.h>
29#include <asm/mach/map.h>
30#include <mach/common.h>
31#include <asm/page.h>
32#include <asm/setup.h>
Ilya Yanok148854c2009-03-11 03:22:00 +030033#include <mach/imx-uart.h>
34#include <mach/iomux-mx3.h>
35#include "devices.h"
36
37/* FPGA defines */
38#define QONG_FPGA_VERSION(major, minor, rev) \
39 (((major & 0xF) << 12) | ((minor & 0xF) << 8) | (rev & 0xFF))
40
Uwe Kleine-Königf568dd72009-12-09 11:57:21 +010041#define QONG_FPGA_BASEADDR MX31_CS1_BASE_ADDR
Ilya Yanok148854c2009-03-11 03:22:00 +030042#define QONG_FPGA_PERIPH_SIZE (1 << 24)
43
44#define QONG_FPGA_CTRL_BASEADDR QONG_FPGA_BASEADDR
45#define QONG_FPGA_CTRL_SIZE 0x10
46/* FPGA control registers */
47#define QONG_FPGA_CTRL_VERSION 0x00
48
49#define QONG_DNET_ID 1
50#define QONG_DNET_BASEADDR \
51 (QONG_FPGA_BASEADDR + QONG_DNET_ID * QONG_FPGA_PERIPH_SIZE)
52#define QONG_DNET_SIZE 0x00001000
53
54#define QONG_FPGA_IRQ IOMUX_TO_IRQ(MX31_PIN_DTR_DCE1)
55
56/*
57 * This file contains the board-specific initialization routines.
58 */
59
60static struct imxuart_platform_data uart_pdata = {
61 .flags = IMXUART_HAVE_RTSCTS,
62};
63
64static int uart_pins[] = {
65 MX31_PIN_CTS1__CTS1,
66 MX31_PIN_RTS1__RTS1,
67 MX31_PIN_TXD1__TXD1,
68 MX31_PIN_RXD1__RXD1
69};
70
71static inline void mxc_init_imx_uart(void)
72{
73 mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins),
74 "uart-0");
75 mxc_register_device(&mxc_uart_device0, &uart_pdata);
76}
77
78static struct resource dnet_resources[] = {
Sascha Hauer3f4f54b2009-06-23 12:12:00 +020079 {
Ilya Yanok148854c2009-03-11 03:22:00 +030080 .name = "dnet-memory",
81 .start = QONG_DNET_BASEADDR,
82 .end = QONG_DNET_BASEADDR + QONG_DNET_SIZE - 1,
83 .flags = IORESOURCE_MEM,
Sascha Hauer3f4f54b2009-06-23 12:12:00 +020084 }, {
Ilya Yanok148854c2009-03-11 03:22:00 +030085 .start = QONG_FPGA_IRQ,
86 .end = QONG_FPGA_IRQ,
87 .flags = IORESOURCE_IRQ,
88 },
89};
90
91static struct platform_device dnet_device = {
92 .name = "dnet",
93 .id = -1,
94 .num_resources = ARRAY_SIZE(dnet_resources),
95 .resource = dnet_resources,
96};
97
98static int __init qong_init_dnet(void)
99{
100 int ret;
101
102 ret = platform_device_register(&dnet_device);
103 return ret;
104}
105
106/* MTD NOR flash */
107
108static struct physmap_flash_data qong_flash_data = {
109 .width = 2,
110};
111
112static struct resource qong_flash_resource = {
Uwe Kleine-Königf568dd72009-12-09 11:57:21 +0100113 .start = MX31_CS0_BASE_ADDR,
Uwe Kleine-Königd57351a2010-03-08 16:11:51 +0100114 .end = MX31_CS0_BASE_ADDR + SZ_128M - 1,
Ilya Yanok148854c2009-03-11 03:22:00 +0300115 .flags = IORESOURCE_MEM,
116};
117
118static struct platform_device qong_nor_mtd_device = {
119 .name = "physmap-flash",
120 .id = 0,
121 .dev = {
122 .platform_data = &qong_flash_data,
123 },
124 .resource = &qong_flash_resource,
125 .num_resources = 1,
126};
127
128static void qong_init_nor_mtd(void)
129{
130 (void)platform_device_register(&qong_nor_mtd_device);
131}
132
133/*
134 * Hardware specific access to control-lines
135 */
136static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
137{
138 struct nand_chip *nand_chip = mtd->priv;
139
140 if (cmd == NAND_CMD_NONE)
141 return;
142
143 if (ctrl & NAND_CLE)
144 writeb(cmd, nand_chip->IO_ADDR_W + (1 << 24));
145 else
146 writeb(cmd, nand_chip->IO_ADDR_W + (1 << 23));
147}
148
149/*
150 * Read the Device Ready pin.
151 */
152static int qong_nand_device_ready(struct mtd_info *mtd)
153{
154 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_NFRB));
155}
156
157static void qong_nand_select_chip(struct mtd_info *mtd, int chip)
158{
159 if (chip >= 0)
160 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
161 else
162 gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 1);
163}
164
165static struct platform_nand_data qong_nand_data = {
166 .chip = {
167 .chip_delay = 20,
168 .options = 0,
169 },
170 .ctrl = {
171 .cmd_ctrl = qong_nand_cmd_ctrl,
172 .dev_ready = qong_nand_device_ready,
173 .select_chip = qong_nand_select_chip,
174 }
175};
176
177static struct resource qong_nand_resource = {
Uwe Kleine-Königf568dd72009-12-09 11:57:21 +0100178 .start = MX31_CS3_BASE_ADDR,
179 .end = MX31_CS3_BASE_ADDR + SZ_32M - 1,
Ilya Yanok148854c2009-03-11 03:22:00 +0300180 .flags = IORESOURCE_MEM,
181};
182
183static struct platform_device qong_nand_device = {
184 .name = "gen_nand",
185 .id = -1,
186 .dev = {
187 .platform_data = &qong_nand_data,
188 },
189 .num_resources = 1,
190 .resource = &qong_nand_resource,
191};
192
193static void __init qong_init_nand_mtd(void)
194{
195 /* init CS */
Uwe Kleine-Königa8dfb642010-01-07 11:27:17 +0100196 mx31_setup_weimcs(3, 0x00004f00, 0x20013b31, 0x00020800);
Ilya Yanok148854c2009-03-11 03:22:00 +0300197 mxc_iomux_set_gpr(MUX_SDCTL_CSD1_SEL, true);
198
199 /* enable pin */
200 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFCE_B, IOMUX_CONFIG_GPIO));
201 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), "nand_enable"))
202 gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
203
204 /* ready/busy pin */
205 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFRB, IOMUX_CONFIG_GPIO));
206 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFRB), "nand_rdy"))
207 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFRB));
208
209 /* write protect pin */
210 mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFWP_B, IOMUX_CONFIG_GPIO));
211 if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFWP_B), "nand_wp"))
212 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFWP_B));
213
214 platform_device_register(&qong_nand_device);
215}
216
217static void __init qong_init_fpga(void)
218{
219 void __iomem *regs;
220 u32 fpga_ver;
221
222 regs = ioremap(QONG_FPGA_CTRL_BASEADDR, QONG_FPGA_CTRL_SIZE);
223 if (!regs) {
224 printk(KERN_ERR "%s: failed to map registers, aborting.\n",
225 __func__);
226 return;
227 }
228
229 fpga_ver = readl(regs + QONG_FPGA_CTRL_VERSION);
230 iounmap(regs);
231 printk(KERN_INFO "Qong FPGA version %d.%d.%d\n",
232 (fpga_ver & 0xF000) >> 12,
233 (fpga_ver & 0x0F00) >> 8, fpga_ver & 0x00FF);
234 if (fpga_ver < QONG_FPGA_VERSION(0, 8, 7)) {
235 printk(KERN_ERR "qong: Unexpected FPGA version, FPGA-based "
236 "devices won't be registered!\n");
237 return;
238 }
239
240 /* register FPGA-based devices */
241 qong_init_nand_mtd();
242 qong_init_dnet();
243}
244
245/*
Ilya Yanok148854c2009-03-11 03:22:00 +0300246 * Board specific initialization.
247 */
248static void __init mxc_board_init(void)
249{
250 mxc_init_imx_uart();
251 qong_init_nor_mtd();
252 qong_init_fpga();
253}
254
255static void __init qong_timer_init(void)
256{
257 mx31_clocks_init(26000000);
258}
259
260static struct sys_timer qong_timer = {
261 .init = qong_timer_init,
262};
263
264/*
265 * The following uses standard kernel macros defined in arch.h in order to
266 * initialize __mach_desc_QONG data structure.
267 */
268
269MACHINE_START(QONG, "Dave/DENX QongEVB-LITE")
270 /* Maintainer: DENX Software Engineering GmbH */
Uwe Kleine-Königf568dd72009-12-09 11:57:21 +0100271 .phys_io = MX31_AIPS1_BASE_ADDR,
Uwe Kleine-König321ed162009-12-10 10:41:26 +0100272 .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc,
Uwe Kleine-König34101232010-01-29 17:36:05 +0100273 .boot_params = MX3x_PHYS_OFFSET + 0x100,
Sascha Hauer35c82da2009-05-05 11:13:23 +0200274 .map_io = mx31_map_io,
Sascha Hauerc5aa0ad2009-05-25 17:36:19 +0200275 .init_irq = mx31_init_irq,
Ilya Yanok148854c2009-03-11 03:22:00 +0300276 .init_machine = mxc_board_init,
277 .timer = &qong_timer,
278MACHINE_END