2 * linux/arch/arm/mach-omap2/board-2430sdp-flash.c
4 * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/platform_device.h>
14 #include <asm/mach/flash.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/partitions.h>
17 #include <linux/mtd/onenand_regs.h>
20 #include <asm/arch/onenand.h>
21 #include <asm/arch/board.h>
22 #include <asm/arch/gpmc.h>
23 #include <asm/arch/nand.h>
25 #define ONENAND_MAP 0x20000000
26 #define GPMC_OFF_CONFIG1_0 0x60
35 static enum fstype flash_type = NAND;
37 static struct mtd_partition nand_partitions[] = {
41 .size = 4*(64*2048), /* 0-3 blks reserved.
42 Mandated by ROM code */
43 .mask_flags = MTD_WRITEABLE /* force read-only */
47 .offset = MTDPART_OFS_APPEND,
49 .mask_flags = MTD_WRITEABLE /* force read-only */
52 .name = "U-Boot Environment",
53 .offset = MTDPART_OFS_APPEND,
58 .offset = MTDPART_OFS_APPEND,
59 .size = 32*(64*2048), /* 4*1M */
62 .name = "File System",
63 .offset = MTDPART_OFS_APPEND,
64 .size = MTDPART_SIZ_FULL,
67 static struct omap_nand_platform_data sdp_nand_data = {
68 .parts = nand_partitions,
69 .nr_parts = ARRAY_SIZE(nand_partitions),
70 .dma_channel = -1, /* disable DMA in OMAP OneNAND driver */
73 static struct platform_device sdp_nand_device = {
77 .platform_data = &sdp_nand_data,
81 static struct mtd_partition onenand_partitions[] = {
83 .name = "(OneNAND)X-Loader",
85 .size = 4*(64*2048), /* 0-3 blks reserved.
86 Mandated by ROM code */
87 .mask_flags = MTD_WRITEABLE /* force read-only */
90 .name = "(OneNAND)U-Boot",
91 .offset = MTDPART_OFS_APPEND,
93 .mask_flags = MTD_WRITEABLE /* force read-only */
96 .name = "(OneNAND)U-Boot Environment",
97 .offset = MTDPART_OFS_APPEND,
101 .name = "(OneNAND)Kernel",
102 .offset = MTDPART_OFS_APPEND,
106 .name = "(OneNAND)File System",
107 .offset = MTDPART_OFS_APPEND,
108 .size = MTDPART_SIZ_FULL,
112 static struct omap_onenand_platform_data sdp_onenand_data = {
113 .parts = onenand_partitions,
114 .nr_parts = ARRAY_SIZE(onenand_partitions),
115 .dma_channel = -1, /* disable DMA in OMAP OneNAND driver */
118 static struct platform_device sdp_onenand_device = {
119 .name = "omap2-onenand",
122 .platform_data = &sdp_onenand_data,
126 void __init sdp2430_flash_init(void)
128 unsigned long gpmc_base_add, gpmc_cs_base_add;
129 unsigned char cs = 0;
131 gpmc_base_add = OMAP243X_GPMC_VIRT;
132 while (cs < GPMC_CS_NUM) {
135 /* Each GPMC set for a single CS is at offset 0x30 */
137 (gpmc_base_add + GPMC_OFF_CONFIG1_0 + (cs*0x30));
139 /* xloader/Uboot would have programmed the NAND/oneNAND
140 * base address for us This is a ugly hack. The proper
141 * way of doing this is to pass the setup of u-boot up
142 * to kernel using kernel params - something on the
143 * lines of machineID. Check if Nand/oneNAND is
145 ret = __raw_readl(gpmc_cs_base_add + GPMC_CS_CONFIG1);
146 if ((ret & 0xC00) == (0x800)) {
148 printk(KERN_INFO "NAND: Found NAND on CS %d \n", cs);
152 ret = __raw_readl(gpmc_cs_base_add + GPMC_CS_CONFIG7);
153 if ((ret & 0x3F) == (ONENAND_MAP >> 24)) {
155 flash_type = ONENAND;
160 if (cs >= GPMC_CS_NUM) {
161 printk(KERN_INFO "MTD: Unable to find MTD configuration in "
162 "GPMC - not registering.\n");
166 if (flash_type == NAND) {
167 sdp_nand_data.cs = cs;
168 sdp_nand_data.gpmc_cs_baseaddr = (void *) gpmc_cs_base_add;
169 sdp_nand_data.gpmc_baseaddr = (void *) gpmc_base_add;
171 if (platform_device_register(&sdp_nand_device) < 0) {
172 printk(KERN_ERR "Unable to register NAND device\n");
177 if (flash_type == ONENAND) {
178 sdp_onenand_data.cs = cs;
180 if (platform_device_register(&sdp_onenand_device) < 0) {
181 printk(KERN_ERR "Unable to register OneNAND device\n");