mtd: nand: driver for Nomadik 8815 SoC (on NHK8815 board)
[safe/jmp/linux-2.6] / arch / arm / mach-nomadik / board-nhk8815.c
1 /*
2  *  linux/arch/arm/mach-nomadik/board-8815nhk.c
3  *
4  *  Copyright (C) STMicroelectronics
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2, as
8  * published by the Free Software Foundation.
9  *
10  *  NHK15 board specifc driver definition
11  */
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/amba/bus.h>
17 #include <linux/interrupt.h>
18 #include <linux/gpio.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/nand.h>
21 #include <linux/mtd/partitions.h>
22 #include <linux/io.h>
23 #include <asm/sizes.h>
24 #include <asm/mach-types.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/irq.h>
27 #include <mach/setup.h>
28 #include <mach/nand.h>
29 #include <mach/fsmc.h>
30 #include "clock.h"
31
32 /* These adresses span 16MB, so use three individual pages */
33 static struct resource nhk8815_nand_resources[] = {
34         {
35                 .name = "nand_addr",
36                 .start = NAND_IO_ADDR,
37                 .end = NAND_IO_ADDR + 0xfff,
38                 .flags = IORESOURCE_MEM,
39         }, {
40                 .name = "nand_cmd",
41                 .start = NAND_IO_CMD,
42                 .end = NAND_IO_CMD + 0xfff,
43                 .flags = IORESOURCE_MEM,
44         }, {
45                 .name = "nand_data",
46                 .start = NAND_IO_DATA,
47                 .end = NAND_IO_DATA + 0xfff,
48                 .flags = IORESOURCE_MEM,
49         }
50 };
51
52 static int nhk8815_nand_init(void)
53 {
54         /* FSMC setup for nand chip select (8-bit nand in 8815NHK) */
55         writel(0x0000000E, FSMC_PCR(0));
56         writel(0x000D0A00, FSMC_PMEM(0));
57         writel(0x00100A00, FSMC_PATT(0));
58
59         /* enable access to the chip select area */
60         writel(readl(FSMC_PCR(0)) | 0x04, FSMC_PCR(0));
61
62         return 0;
63 }
64
65 /*
66  * These partitions are the same as those used in the 2.6.20 release
67  * shipped by the vendor; the first two partitions are mandated
68  * by the boot ROM, and the bootloader area is somehow oversized...
69  */
70 static struct mtd_partition nhk8815_partitions[] = {
71         {
72                 .name   = "X-Loader(NAND)",
73                 .offset = 0,
74                 .size   = SZ_256K,
75         }, {
76                 .name   = "MemInit(NAND)",
77                 .offset = MTDPART_OFS_APPEND,
78                 .size   = SZ_256K,
79         }, {
80                 .name   = "BootLoader(NAND)",
81                 .offset = MTDPART_OFS_APPEND,
82                 .size   = SZ_2M,
83         }, {
84                 .name   = "Kernel zImage(NAND)",
85                 .offset = MTDPART_OFS_APPEND,
86                 .size   = 3 * SZ_1M,
87         }, {
88                 .name   = "Root Filesystem(NAND)",
89                 .offset = MTDPART_OFS_APPEND,
90                 .size   = 22 * SZ_1M,
91         }, {
92                 .name   = "User Filesystem(NAND)",
93                 .offset = MTDPART_OFS_APPEND,
94                 .size   = MTDPART_SIZ_FULL,
95         }
96 };
97
98 static struct nomadik_nand_platform_data nhk8815_nand_data = {
99         .parts          = nhk8815_partitions,
100         .nparts         = ARRAY_SIZE(nhk8815_partitions),
101         .options        = NAND_COPYBACK | NAND_CACHEPRG | NAND_NO_PADDING \
102                         | NAND_NO_READRDY | NAND_NO_AUTOINCR,
103         .init           = nhk8815_nand_init,
104 };
105
106 static struct platform_device nhk8815_nand_device = {
107         .name           = "nomadik_nand",
108         .dev            = {
109                 .platform_data = &nhk8815_nand_data,
110         },
111         .resource       = nhk8815_nand_resources,
112         .num_resources  = ARRAY_SIZE(nhk8815_nand_resources),
113 };
114
115
116 #define __MEM_4K_RESOURCE(x) \
117         .res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM}
118
119 static struct amba_device uart0_device = {
120         .dev = { .init_name = "uart0" },
121         __MEM_4K_RESOURCE(NOMADIK_UART0_BASE),
122         .irq = {IRQ_UART0, NO_IRQ},
123 };
124
125 static struct amba_device uart1_device = {
126         .dev = { .init_name = "uart1" },
127         __MEM_4K_RESOURCE(NOMADIK_UART1_BASE),
128         .irq = {IRQ_UART1, NO_IRQ},
129 };
130
131 static struct amba_device *amba_devs[] __initdata = {
132         &uart0_device,
133         &uart1_device,
134 };
135
136 /* We have a fixed clock alone, by now */
137 static struct clk nhk8815_clk_48 = {
138         .rate = 48*1000*1000,
139 };
140
141 static struct resource nhk8815_eth_resources[] = {
142         {
143                 .name = "smc91x-regs",
144                 .start = 0x34000000 + 0x300,
145                 .end = 0x34000000 + SZ_64K - 1,
146                 .flags = IORESOURCE_MEM,
147         }, {
148                 .start = NOMADIK_GPIO_TO_IRQ(115),
149                 .end = NOMADIK_GPIO_TO_IRQ(115),
150                 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING,
151         }
152 };
153
154 static struct platform_device nhk8815_eth_device = {
155         .name = "smc91x",
156         .resource = nhk8815_eth_resources,
157         .num_resources = ARRAY_SIZE(nhk8815_eth_resources),
158 };
159
160 static int __init nhk8815_eth_init(void)
161 {
162         int gpio_nr = 115; /* hardwired in the board */
163         int err;
164
165         err = gpio_request(gpio_nr, "eth_irq");
166         if (!err) err = nmk_gpio_set_mode(gpio_nr, NMK_GPIO_ALT_GPIO);
167         if (!err) err = gpio_direction_input(gpio_nr);
168         if (err)
169                 pr_err("Error %i in %s\n", err, __func__);
170         return err;
171 }
172 device_initcall(nhk8815_eth_init);
173
174 static struct platform_device *nhk8815_platform_devices[] __initdata = {
175         &nhk8815_nand_device,
176         &nhk8815_eth_device,
177         /* will add more devices */
178 };
179
180 static void __init nhk8815_platform_init(void)
181 {
182         int i;
183
184         cpu8815_platform_init();
185         platform_add_devices(nhk8815_platform_devices,
186                              ARRAY_SIZE(nhk8815_platform_devices));
187
188         for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
189                 nmdk_clk_create(&nhk8815_clk_48, amba_devs[i]->dev.init_name);
190                 amba_device_register(amba_devs[i], &iomem_resource);
191         }
192 }
193
194 MACHINE_START(NOMADIK, "NHK8815")
195         /* Maintainer: ST MicroElectronics */
196         .phys_io        = NOMADIK_UART0_BASE,
197         .io_pg_offst    = (IO_ADDRESS(NOMADIK_UART0_BASE) >> 18) & 0xfffc,
198         .boot_params    = 0x100,
199         .map_io         = cpu8815_map_io,
200         .init_irq       = cpu8815_init_irq,
201         .timer          = &nomadik_timer,
202         .init_machine   = nhk8815_platform_init,
203 MACHINE_END