Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / drivers / mtd / maps / edb7312.c
1 /*
2  * $Id: edb7312.c,v 1.14 2005/11/07 11:14:27 gleixner Exp $
3  *
4  * Handle mapping of the NOR flash on Cogent EDB7312 boards
5  *
6  * Copyright 2002 SYSGO Real-Time Solutions GmbH
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <asm/io.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/map.h>
20
21 #ifdef CONFIG_MTD_PARTITIONS
22 #include <linux/mtd/partitions.h>
23 #endif
24
25 #define WINDOW_ADDR 0x00000000      /* physical properties of flash */
26 #define WINDOW_SIZE 0x01000000
27 #define BUSWIDTH    2
28 #define FLASH_BLOCKSIZE_MAIN    0x20000
29 #define FLASH_NUMBLOCKS_MAIN    128
30 /* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */
31 #define PROBETYPES { "cfi_probe", NULL }
32
33 #define MSG_PREFIX "EDB7312-NOR:"   /* prefix for our printk()'s */
34 #define MTDID      "edb7312-nor"    /* for mtdparts= partitioning */
35
36 static struct mtd_info *mymtd;
37
38 struct map_info edb7312nor_map = {
39         .name = "NOR flash on EDB7312",
40         .size = WINDOW_SIZE,
41         .bankwidth = BUSWIDTH,
42         .phys = WINDOW_ADDR,
43 };
44
45 #ifdef CONFIG_MTD_PARTITIONS
46
47 /*
48  * MTD partitioning stuff
49  */
50 static struct mtd_partition static_partitions[3] =
51 {
52         {
53                 .name = "ARMboot",
54                 .size = 0x40000,
55                 .offset = 0
56         },
57         {
58                 .name = "Kernel",
59                 .size = 0x200000,
60                 .offset = 0x40000
61         },
62         {
63                 .name = "RootFS",
64                 .size = 0xDC0000,
65                 .offset = 0x240000
66         },
67 };
68
69 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
70
71 #endif
72
73 static int                   mtd_parts_nb = 0;
74 static struct mtd_partition *mtd_parts    = 0;
75
76 int __init init_edb7312nor(void)
77 {
78         static const char *rom_probe_types[] = PROBETYPES;
79         const char **type;
80         const char *part_type = 0;
81
82         printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n",
83                WINDOW_SIZE, WINDOW_ADDR);
84         edb7312nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
85
86         if (!edb7312nor_map.virt) {
87                 printk(MSG_PREFIX "failed to ioremap\n");
88                 return -EIO;
89         }
90
91         simple_map_init(&edb7312nor_map);
92
93         mymtd = 0;
94         type = rom_probe_types;
95         for(; !mymtd && *type; type++) {
96                 mymtd = do_map_probe(*type, &edb7312nor_map);
97         }
98         if (mymtd) {
99                 mymtd->owner = THIS_MODULE;
100
101 #ifdef CONFIG_MTD_PARTITIONS
102                 mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);
103                 if (mtd_parts_nb > 0)
104                   part_type = "detected";
105
106                 if (mtd_parts_nb == 0)
107                 {
108                         mtd_parts = static_partitions;
109                         mtd_parts_nb = ARRAY_SIZE(static_partitions);
110                         part_type = "static";
111                 }
112 #endif
113                 add_mtd_device(mymtd);
114                 if (mtd_parts_nb == 0)
115                   printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
116                 else
117                 {
118                         printk(KERN_NOTICE MSG_PREFIX
119                                "using %s partition definition\n", part_type);
120                         add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);
121                 }
122                 return 0;
123         }
124
125         iounmap((void *)edb7312nor_map.virt);
126         return -ENXIO;
127 }
128
129 static void __exit cleanup_edb7312nor(void)
130 {
131         if (mymtd) {
132                 del_mtd_device(mymtd);
133                 map_destroy(mymtd);
134         }
135         if (edb7312nor_map.virt) {
136                 iounmap((void *)edb7312nor_map.virt);
137                 edb7312nor_map.virt = 0;
138         }
139 }
140
141 module_init(init_edb7312nor);
142 module_exit(cleanup_edb7312nor);
143
144 MODULE_LICENSE("GPL");
145 MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
146 MODULE_DESCRIPTION("Generic configurable MTD map driver");