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