]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-3430sdp-flash.c
Merge branch 'omap-fixes'
[linux-2.6-omap-h63xx.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 #define NAND_BLOCK_SIZE         SZ_128K
30
31 /* NAND */
32 /* IMPORTANT NOTE ON MAPPING
33  * 3430SDP - 34XX
34  * ----------
35  * NOR always on 0x04000000 for SDPV1
36  * NOR always on 0x10000000 for SDPV2
37  * MPDB always on 0x08000000
38  * NAND always on 0x0C000000
39  * OneNand Mapped to 0x20000000
40  * Boot Mode(NAND/NOR). The other on CS1
41  */
42 #define FLASH_BASE_SDPV1        0x04000000 /* NOR flash (64 Meg aligned) */
43 #define FLASH_BASE_SDPV2        0x10000000 /* NOR flash (256 Meg aligned) */
44 #define DEBUG_BASE              0x08000000 /* debug board */
45 #define NAND_BASE               0x0C000000 /* NAND flash */
46 #define ONENAND_MAP             0x20000000 /* OneNand flash */
47
48 /* various memory sizes */
49 #define FLASH_SIZE_SDPV1        SZ_64M
50 #define FLASH_SIZE_SDPV2        SZ_128M
51
52 static struct mtd_partition sdp_nor_partitions[] = {
53         /* bootloader (U-Boot, etc) in first sector */
54         {
55                 .name           = "Bootloader-NOR",
56                 .offset         = 0,
57                 .size           = SZ_256K,
58                 .mask_flags     = MTD_WRITEABLE, /* force read-only */
59         },
60         /* bootloader params in the next sector */
61         {
62                 .name           = "Params-NOR",
63                 .offset         = MTDPART_OFS_APPEND,
64                 .size           = SZ_256K,
65                 .mask_flags     = 0,
66         },
67         /* kernel */
68         {
69                 .name           = "Kernel-NOR",
70                 .offset         = MTDPART_OFS_APPEND,
71                 .size           = SZ_2M,
72                 .mask_flags     = 0
73         },
74         /* file system */
75         {
76                 .name           = "Filesystem-NOR",
77                 .offset         = MTDPART_OFS_APPEND,
78                 .size           = MTDPART_SIZ_FULL,
79                 .mask_flags     = 0
80         }
81 };
82
83 static struct flash_platform_data sdp_nor_data = {
84         .map_name       = "cfi_probe",
85         .width          = 2,
86         .parts          = sdp_nor_partitions,
87         .nr_parts       = ARRAY_SIZE(sdp_nor_partitions),
88 };
89
90 static struct resource sdp_nor_resource = {
91         .start          = 0,
92         .end            = 0,
93         .flags          = IORESOURCE_MEM,
94 };
95
96 static struct platform_device sdp_nor_device = {
97         .name           = "omapflash",
98         .id             = 0,
99         .dev            = {
100                         .platform_data = &sdp_nor_data,
101         },
102         .num_resources  = 1,
103         .resource       = &sdp_nor_resource,
104 };
105
106 static int sdp_onenand_setup(void __iomem *, int freq);
107
108 static struct mtd_partition sdp_onenand_partitions[] = {
109         {
110                 .name           = "X-Loader-OneNAND",
111                 .offset         = 0,
112                 .size           = 4 * (64 * 2048),
113                 .mask_flags     = MTD_WRITEABLE  /* force read-only */
114         },
115         {
116                 .name           = "U-Boot-OneNAND",
117                 .offset         = MTDPART_OFS_APPEND,
118                 .size           = 2 * (64 * 2048),
119                 .mask_flags     = MTD_WRITEABLE  /* force read-only */
120         },
121         {
122                 .name           = "U-Boot Environment-OneNAND",
123                 .offset         = MTDPART_OFS_APPEND,
124                 .size           = 1 * (64 * 2048),
125         },
126         {
127                 .name           = "Kernel-OneNAND",
128                 .offset         = MTDPART_OFS_APPEND,
129                 .size           = 16 * (64 * 2048),
130         },
131         {
132                 .name           = "File System-OneNAND",
133                 .offset         = MTDPART_OFS_APPEND,
134                 .size           = MTDPART_SIZ_FULL,
135         },
136 };
137
138 static struct omap_onenand_platform_data sdp_onenand_data = {
139         .parts          = sdp_onenand_partitions,
140         .nr_parts       = ARRAY_SIZE(sdp_onenand_partitions),
141         .onenand_setup  = sdp_onenand_setup,
142         .dma_channel    = -1,   /* disable DMA in OMAP OneNAND driver */
143 };
144
145 static struct platform_device sdp_onenand_device = {
146         .name           = "omap2-onenand",
147         .id             = -1,
148         .dev = {
149                 .platform_data = &sdp_onenand_data,
150         },
151 };
152
153 /*
154  * sdp_onenand_setup - The function configures the onenand flash.
155  * @onenand_base: Onenand base address
156  *
157  * @return int: Currently always returning zero.
158  */
159 static int sdp_onenand_setup(void __iomem *onenand_base, int freq)
160 {
161         /* Onenand setup does nothing at present */
162         return 0;
163 }
164
165 static struct mtd_partition sdp_nand_partitions[] = {
166         /* All the partition sizes are listed in terms of NAND block size */
167         {
168                 .name           = "X-Loader-NAND",
169                 .offset         = 0,
170                 .size           = 4 * NAND_BLOCK_SIZE,
171                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
172         },
173         {
174                 .name           = "U-Boot-NAND",
175                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
176                 .size           = 4 * NAND_BLOCK_SIZE,
177                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
178         },
179         {
180                 .name           = "Boot Env-NAND",
181                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x100000 */
182                 .size           = 2 * NAND_BLOCK_SIZE,
183         },
184         {
185                 .name           = "Kernel-NAND",
186                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x140000 */
187                 .size           = 32 * NAND_BLOCK_SIZE,
188         },
189         {
190                 .name           = "File System - NAND",
191                 .size           = MTDPART_SIZ_FULL,
192                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x540000 */
193         },
194 };
195
196 static struct omap_nand_platform_data sdp_nand_data = {
197         .parts          = sdp_nand_partitions,
198         .nr_parts       = ARRAY_SIZE(sdp_nand_partitions),
199         .nand_setup     = NULL,
200         .dma_channel    = -1,           /* disable DMA in OMAP NAND driver */
201         .dev_ready      = NULL,
202 };
203
204 static struct resource sdp_nand_resource = {
205         .flags          = IORESOURCE_MEM,
206 };
207
208 static struct platform_device sdp_nand_device = {
209         .name           = "omap2-nand",
210         .id             = 0,
211         .dev            = {
212         .platform_data  = &sdp_nand_data,
213         },
214         .num_resources  = 1,
215         .resource       = &sdp_nand_resource,
216 };
217
218
219 /**
220  * sdp3430_flash_init - Identify devices connected to GPMC and register.
221  *
222  * @return - void.
223  */
224 void __init sdp3430_flash_init(void)
225 {
226         u8              cs = 0;
227         u8              nandcs = GPMC_CS_NUM + 1;
228         u8              onenandcs = GPMC_CS_NUM + 1;
229         unsigned long   gpmc_base_add;
230
231         gpmc_base_add   = OMAP34XX_GPMC_VIRT;
232
233         /* Configure start address and size of NOR device */
234         if (omap_rev() > OMAP3430_REV_ES1_0) {
235                 sdp_nor_resource.start  = FLASH_BASE_SDPV2;
236                 sdp_nor_resource.end    = FLASH_BASE_SDPV2
237                                                 + FLASH_SIZE_SDPV2 - 1;
238         } else {
239                 sdp_nor_resource.start  = FLASH_BASE_SDPV1;
240                 sdp_nor_resource.end    = FLASH_BASE_SDPV1
241                                                 + FLASH_SIZE_SDPV1 - 1;
242         }
243
244         if (platform_device_register(&sdp_nor_device) < 0)
245                 printk(KERN_ERR "Unable to register NOR device\n");
246
247         while (cs < GPMC_CS_NUM) {
248                 u32 ret = 0;
249                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
250
251                 /*
252                 * xloader/Uboot would have programmed the NAND/oneNAND
253                 * base address for us This is a ugly hack. The proper
254                 * way of doing this is to pass the setup of u-boot up
255                 * to kernel using kernel params - something on the
256                 * lines of machineID. Check if oneNAND is configured
257                 */
258                 if ((ret & 0xC00) == 0x800) {
259                         /* Found it!! */
260                         if (nandcs > GPMC_CS_NUM)
261                                 nandcs = cs;
262                 } else {
263                         ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
264                         if ((ret & 0x3F) == (ONENAND_MAP >> 24))
265                         onenandcs = cs;
266                 }
267                 cs++;
268         }
269         if ((nandcs > GPMC_CS_NUM) && (onenandcs > GPMC_CS_NUM)) {
270                 printk(KERN_INFO "NAND/OneNAND: Unable to find configuration "
271                                 " in GPMC\n ");
272                 return;
273         }
274
275         if (nandcs < GPMC_CS_NUM) {
276                 sdp_nand_data.cs        = nandcs;
277                 sdp_nand_data.gpmc_cs_baseaddr   = (void *)(gpmc_base_add +
278                                         GPMC_CS0_BASE + nandcs*GPMC_CS_SIZE);
279                 sdp_nand_data.gpmc_baseaddr     = (void *) (gpmc_base_add);
280
281                 if (platform_device_register(&sdp_nand_device) < 0)
282                         printk(KERN_ERR "Unable to register NAND device\n");
283         }
284
285         if (onenandcs < GPMC_CS_NUM) {
286                 sdp_onenand_data.cs = onenandcs;
287                 if (platform_device_register(&sdp_onenand_device) < 0)
288                         printk(KERN_ERR "Unable to register OneNAND device\n");
289         }
290 }