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