Merge current mainline tree into linux-omap tree
[pandora-kernel.git] / arch / arm / mach-omap2 / board-3430sdp-flash.c
1 /*
2  * linux/arch/arm/mach-omap2/board-3430sdp-flash.c
3  *
4  * Copyright (c) 2007 Texas Instruments
5  *
6  * Modified from mach-omap2/board-2430sdp-flash.c
7  * Author: Rohit Choraria <rohitkc@ti.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/platform_device.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/mtd/nand.h>
19 #include <linux/mtd/onenand_regs.h>
20 #include <linux/types.h>
21 #include <linux/io.h>
22
23 #include <asm/mach/flash.h>
24 #include <mach/onenand.h>
25 #include <mach/board.h>
26 #include <mach/gpmc.h>
27 #include <mach/nand.h>
28
29 static struct mtd_partition sdp_nor_partitions[] = {
30         /* bootloader (U-Boot, etc) in first sector */
31         {
32                 .name           = "Bootloader-NOR",
33                 .offset         = 0,
34                 .size           = SZ_256K,
35                 .mask_flags     = MTD_WRITEABLE, /* force read-only */
36         },
37         /* bootloader params in the next sector */
38         {
39                 .name           = "Params-NOR",
40                 .offset         = MTDPART_OFS_APPEND,
41                 .size           = SZ_256K,
42                 .mask_flags     = 0,
43         },
44         /* kernel */
45         {
46                 .name           = "Kernel-NOR",
47                 .offset         = MTDPART_OFS_APPEND,
48                 .size           = SZ_2M,
49                 .mask_flags     = 0
50         },
51         /* file system */
52         {
53                 .name           = "Filesystem-NOR",
54                 .offset         = MTDPART_OFS_APPEND,
55                 .size           = MTDPART_SIZ_FULL,
56                 .mask_flags     = 0
57         }
58 };
59
60 static struct flash_platform_data sdp_nor_data = {
61         .map_name       = "cfi_probe",
62         .width          = 2,
63         .parts          = sdp_nor_partitions,
64         .nr_parts       = ARRAY_SIZE(sdp_nor_partitions),
65 };
66
67 static struct resource sdp_nor_resource = {
68         .start          = 0,
69         .end            = 0,
70         .flags          = IORESOURCE_MEM,
71 };
72
73 static struct platform_device sdp_nor_device = {
74         .name           = "omapflash",
75         .id             = 0,
76         .dev            = {
77                         .platform_data = &sdp_nor_data,
78         },
79         .num_resources  = 1,
80         .resource       = &sdp_nor_resource,
81 };
82
83 static int sdp_onenand_setup(void __iomem *, int freq);
84
85 static struct mtd_partition sdp_onenand_partitions[] = {
86         {
87                 .name           = "X-Loader-OneNAND",
88                 .offset         = 0,
89                 .size           = 4 * (64 * 2048),
90                 .mask_flags     = MTD_WRITEABLE  /* force read-only */
91         },
92         {
93                 .name           = "U-Boot-OneNAND",
94                 .offset         = MTDPART_OFS_APPEND,
95                 .size           = 2 * (64 * 2048),
96                 .mask_flags     = MTD_WRITEABLE  /* force read-only */
97         },
98         {
99                 .name           = "U-Boot Environment-OneNAND",
100                 .offset         = MTDPART_OFS_APPEND,
101                 .size           = 1 * (64 * 2048),
102         },
103         {
104                 .name           = "Kernel-OneNAND",
105                 .offset         = MTDPART_OFS_APPEND,
106                 .size           = 16 * (64 * 2048),
107         },
108         {
109                 .name           = "File System-OneNAND",
110                 .offset         = MTDPART_OFS_APPEND,
111                 .size           = MTDPART_SIZ_FULL,
112         },
113 };
114
115 static struct omap_onenand_platform_data sdp_onenand_data = {
116         .parts          = sdp_onenand_partitions,
117         .nr_parts       = ARRAY_SIZE(sdp_onenand_partitions),
118         .onenand_setup  = sdp_onenand_setup,
119         .dma_channel    = -1,   /* disable DMA in OMAP OneNAND driver */
120 };
121
122 static struct platform_device sdp_onenand_device = {
123         .name           = "omap2-onenand",
124         .id             = -1,
125         .dev = {
126                 .platform_data = &sdp_onenand_data,
127         },
128 };
129
130 /*
131  * sdp_onenand_setup - The function configures the onenand flash.
132  * @onenand_base: Onenand base address
133  *
134  * @return int: Currently always returning zero.
135  */
136 static int sdp_onenand_setup(void __iomem *onenand_base, int freq)
137 {
138         /* Onenand setup does nothing at present */
139         return 0;
140 }
141
142 static struct mtd_partition sdp_nand_partitions[] = {
143         /* All the partition sizes are listed in terms of NAND block size */
144         {
145                 .name           = "X-Loader-NAND",
146                 .offset         = 0,
147                 .size           = 4 * NAND_BLOCK_SIZE,
148                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
149         },
150         {
151                 .name           = "U-Boot-NAND",
152                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
153                 .size           = 4 * NAND_BLOCK_SIZE,
154                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
155         },
156         {
157                 .name           = "Boot Env-NAND",
158                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x100000 */
159                 .size           = 2 * NAND_BLOCK_SIZE,
160         },
161         {
162                 .name           = "Kernel-NAND",
163                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x140000 */
164                 .size           = 32 * NAND_BLOCK_SIZE,
165         },
166         {
167                 .name           = "File System - NAND",
168                 .size           = MTDPART_SIZ_FULL,
169                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x540000 */
170         },
171 };
172
173 static struct omap_nand_platform_data sdp_nand_data = {
174         .parts          = sdp_nand_partitions,
175         .nr_parts       = ARRAY_SIZE(sdp_nand_partitions),
176         .nand_setup     = NULL,
177         .dma_channel    = -1,           /* disable DMA in OMAP NAND driver */
178         .dev_ready      = NULL,
179 };
180
181 static struct resource sdp_nand_resource = {
182         .flags          = IORESOURCE_MEM,
183 };
184
185 static struct platform_device sdp_nand_device = {
186         .name           = "omap2-nand",
187         .id             = 0,
188         .dev            = {
189         .platform_data  = &sdp_nand_data,
190         },
191         .num_resources  = 1,
192         .resource       = &sdp_nand_resource,
193 };
194
195
196 /**
197  * sdp3430_flash_init - Identify devices connected to GPMC and register.
198  *
199  * @return - void.
200  */
201 void __init sdp3430_flash_init(void)
202 {
203         u8              cs = 0;
204         u8              nandcs = GPMC_CS_NUM + 1;
205         u8              onenandcs = GPMC_CS_NUM + 1;
206         unsigned long   gpmc_base_add;
207
208         gpmc_base_add   = OMAP34XX_GPMC_VIRT;
209
210         /* Configure start address and size of NOR device */
211         if (system_rev > OMAP3430_REV_ES1_0) {
212                 sdp_nor_resource.start  = FLASH_BASE_SDPV2;
213                 sdp_nor_resource.end    = FLASH_BASE_SDPV2
214                                                 + FLASH_SIZE_SDPV2 - 1;
215         } else {
216                 sdp_nor_resource.start  = FLASH_BASE_SDPV1;
217                 sdp_nor_resource.end    = FLASH_BASE_SDPV1
218                                                 + FLASH_SIZE_SDPV1 - 1;
219         }
220
221         if (platform_device_register(&sdp_nor_device) < 0)
222                 printk(KERN_ERR "Unable to register NOR device\n");
223
224         while (cs < GPMC_CS_NUM) {
225                 u32 ret = 0;
226                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
227
228                 /*
229                 * xloader/Uboot would have programmed the NAND/oneNAND
230                 * base address for us This is a ugly hack. The proper
231                 * way of doing this is to pass the setup of u-boot up
232                 * to kernel using kernel params - something on the
233                 * lines of machineID. Check if oneNAND is configured
234                 */
235                 if ((ret & 0xC00) == 0x800) {
236                         /* Found it!! */
237                         if (nandcs > GPMC_CS_NUM)
238                                 nandcs = cs;
239                 } else {
240                         ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
241                         if ((ret & 0x3F) == (ONENAND_MAP >> 24))
242                         onenandcs = cs;
243                 }
244                 cs++;
245         }
246         if ((nandcs > GPMC_CS_NUM) && (onenandcs > GPMC_CS_NUM)) {
247                 printk(KERN_INFO "NAND/OneNAND: Unable to find configuration "
248                                 " in GPMC\n ");
249                 return;
250         }
251
252         if (nandcs < GPMC_CS_NUM) {
253                 sdp_nand_data.cs        = nandcs;
254                 sdp_nand_data.gpmc_cs_baseaddr   = (void *)(gpmc_base_add +
255                                         GPMC_CS0_BASE + nandcs*GPMC_CS_SIZE);
256                 sdp_nand_data.gpmc_baseaddr     = (void *) (gpmc_base_add);
257
258                 if (platform_device_register(&sdp_nand_device) < 0)
259                         printk(KERN_ERR "Unable to register NAND device\n");
260         }
261
262         if (onenandcs < GPMC_CS_NUM) {
263                 sdp_onenand_data.cs = onenandcs;
264                 if (platform_device_register(&sdp_onenand_device) < 0)
265                         printk(KERN_ERR "Unable to register OneNAND device\n");
266         }
267 }