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 <asm/arch/onenand.h>
25 #include <asm/arch/board.h>
26 #include <asm/arch/gpmc.h>
27
28 static struct mtd_partition sdp_nor_partitions[] = {
29         /* bootloader (U-Boot, etc) in first sector */
30         {
31                 .name           = "Bootloader-NOR",
32                 .offset         = 0,
33                 .size           = SZ_256K,
34                 .mask_flags     = MTD_WRITEABLE, /* force read-only */
35         },
36         /* bootloader params in the next sector */
37         {
38                 .name           = "Params-NOR",
39                 .offset         = MTDPART_OFS_APPEND,
40                 .size           = SZ_256K,
41                 .mask_flags     = 0,
42         },
43         /* kernel */
44         {
45                 .name           = "Kernel-NOR",
46                 .offset         = MTDPART_OFS_APPEND,
47                 .size           = SZ_2M,
48                 .mask_flags     = 0
49         },
50         /* file system */
51         {
52                 .name           = "Filesystem-NOR",
53                 .offset         = MTDPART_OFS_APPEND,
54                 .size           = MTDPART_SIZ_FULL,
55                 .mask_flags     = 0
56         }
57 };
58
59 static struct flash_platform_data sdp_nor_data = {
60         .map_name       = "cfi_probe",
61         .width          = 2,
62         .parts          = sdp_nor_partitions,
63         .nr_parts       = ARRAY_SIZE(sdp_nor_partitions),
64 };
65
66 static struct resource sdp_nor_resource = {
67         .start          = 0,
68         .end            = 0,
69         .flags          = IORESOURCE_MEM,
70 };
71
72 static struct platform_device sdp_nor_device = {
73         .name           = "omapflash",
74         .id             = 0,
75         .dev            = {
76                         .platform_data = &sdp_nor_data,
77         },
78         .num_resources  = 1,
79         .resource       = &sdp_nor_resource,
80 };
81
82 static int sdp_onenand_setup(void __iomem *, int freq);
83
84 static struct mtd_partition sdp_onenand_partitions[] = {
85         {
86                 .name           = "X-Loader-OneNAND",
87                 .offset         = 0,
88                 .size           = 4 * (64 * 2048),
89                 .mask_flags     = MTD_WRITEABLE  /* force read-only */
90         },
91         {
92                 .name           = "U-Boot-OneNAND",
93                 .offset         = MTDPART_OFS_APPEND,
94                 .size           = 2 * (64 * 2048),
95                 .mask_flags     = MTD_WRITEABLE  /* force read-only */
96         },
97         {
98                 .name           = "U-Boot Environment-OneNAND",
99                 .offset         = MTDPART_OFS_APPEND,
100                 .size           = 1 * (64 * 2048),
101         },
102         {
103                 .name           = "Kernel-OneNAND",
104                 .offset         = MTDPART_OFS_APPEND,
105                 .size           = 16 * (64 * 2048),
106         },
107         {
108                 .name           = "File System-OneNAND",
109                 .offset         = MTDPART_OFS_APPEND,
110                 .size           = MTDPART_SIZ_FULL,
111         },
112 };
113
114 static struct omap_onenand_platform_data sdp_onenand_data = {
115         .parts          = sdp_onenand_partitions,
116         .nr_parts       = ARRAY_SIZE(sdp_onenand_partitions),
117         .onenand_setup  = sdp_onenand_setup,
118         .dma_channel    = -1,   /* disable DMA in OMAP OneNAND driver */
119 };
120
121 static struct platform_device sdp_onenand_device = {
122         .name           = "omap2-onenand",
123         .id             = -1,
124         .dev = {
125                 .platform_data = &sdp_onenand_data,
126         },
127 };
128
129 /*
130  * sdp_onenand_setup - The function configures the onenand flash.
131  * @onenand_base: Onenand base address
132  *
133  * @return int: Currently always returning zero.
134  */
135 static int sdp_onenand_setup(void __iomem *onenand_base, int freq)
136 {
137         /* Onenand setup does nothing at present */
138         return 0;
139 }
140 /**
141  * sdp3430_flash_init - Identify devices connected to GPMC and register.
142  *
143  * @return - void.
144  */
145 void __init sdp3430_flash_init(void)
146 {
147         u8              cs = 0;
148         u8              onenandcs = GPMC_CS_NUM + 1;
149
150         /* Configure start address and size of NOR device */
151         if (is_sil_rev_greater_than(OMAP3430_REV_ES1_0)) {
152                 sdp_nor_resource.start  = FLASH_BASE_SDPV2;
153                 sdp_nor_resource.end    = FLASH_BASE_SDPV2
154                                                 + FLASH_SIZE_SDPV2 - 1;
155         } else {
156                 sdp_nor_resource.start  = FLASH_BASE_SDPV1;
157                 sdp_nor_resource.end    = FLASH_BASE_SDPV1
158                                                 + FLASH_SIZE_SDPV1 - 1;
159         }
160
161         if (platform_device_register(&sdp_nor_device) < 0)
162                 printk(KERN_ERR "Unable to register NOR device\n");
163
164         while (cs < GPMC_CS_NUM) {
165                 u32 ret = 0;
166                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
167
168                 /*
169                 * xloader/Uboot would have programmed the oneNAND
170                 * base address for us This is a ugly hack. The proper
171                 * way of doing this is to pass the setup of u-boot up
172                 * to kernel using kernel params - something on the
173                 * lines of machineID. Check if oneNAND is configured
174                 */
175                 if ((ret & 0x3F) == (ONENAND_MAP >> 24))
176                         onenandcs = cs;
177                 cs++;
178         }
179         if (onenandcs > GPMC_CS_NUM) {
180                 printk(KERN_INFO "OneNAND: Unable to find configuration "
181                                 " in GPMC\n ");
182                 return;
183         }
184
185         if (onenandcs < GPMC_CS_NUM) {
186                 sdp_onenand_data.cs = onenandcs;
187                 if (platform_device_register(&sdp_onenand_device) < 0)
188                         printk(KERN_ERR "Unable to register OneNAND device\n");
189         }
190 }