MTD/JFFS2: remove CVS keywords
[safe/jmp/linux-2.6] / drivers / mtd / maps / ebony.c
1 /*
2  * Mapping for Ebony user flash
3  *
4  * Matt Porter <mporter@kernel.crashing.org>
5  *
6  * Copyright 2002-2004 MontaVista Software Inc.
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  */
13
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/map.h>
20 #include <linux/mtd/partitions.h>
21 #include <asm/io.h>
22 #include <asm/ibm44x.h>
23 #include <platforms/4xx/ebony.h>
24
25 static struct mtd_info *flash;
26
27 static struct map_info ebony_small_map = {
28         .name =         "Ebony small flash",
29         .size =         EBONY_SMALL_FLASH_SIZE,
30         .bankwidth =    1,
31 };
32
33 static struct map_info ebony_large_map = {
34         .name =         "Ebony large flash",
35         .size =         EBONY_LARGE_FLASH_SIZE,
36         .bankwidth =    1,
37 };
38
39 static struct mtd_partition ebony_small_partitions[] = {
40         {
41                 .name =   "OpenBIOS",
42                 .offset = 0x0,
43                 .size =   0x80000,
44         }
45 };
46
47 static struct mtd_partition ebony_large_partitions[] = {
48         {
49                 .name =   "fs",
50                 .offset = 0,
51                 .size =   0x380000,
52         },
53         {
54                 .name =   "firmware",
55                 .offset = 0x380000,
56                 .size =   0x80000,
57         }
58 };
59
60 int __init init_ebony(void)
61 {
62         u8 fpga0_reg;
63         u8 __iomem *fpga0_adr;
64         unsigned long long small_flash_base, large_flash_base;
65
66         fpga0_adr = ioremap64(EBONY_FPGA_ADDR, 16);
67         if (!fpga0_adr)
68                 return -ENOMEM;
69
70         fpga0_reg = readb(fpga0_adr);
71         iounmap(fpga0_adr);
72
73         if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
74                         !EBONY_FLASH_SEL(fpga0_reg))
75                 small_flash_base = EBONY_SMALL_FLASH_HIGH2;
76         else if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
77                         EBONY_FLASH_SEL(fpga0_reg))
78                 small_flash_base = EBONY_SMALL_FLASH_HIGH1;
79         else if (!EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
80                         !EBONY_FLASH_SEL(fpga0_reg))
81                 small_flash_base = EBONY_SMALL_FLASH_LOW2;
82         else
83                 small_flash_base = EBONY_SMALL_FLASH_LOW1;
84
85         if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
86                         !EBONY_ONBRD_FLASH_EN(fpga0_reg))
87                 large_flash_base = EBONY_LARGE_FLASH_LOW;
88         else
89                 large_flash_base = EBONY_LARGE_FLASH_HIGH;
90
91         ebony_small_map.phys = small_flash_base;
92         ebony_small_map.virt = ioremap64(small_flash_base,
93                                          ebony_small_map.size);
94
95         if (!ebony_small_map.virt) {
96                 printk("Failed to ioremap flash\n");
97                 return -EIO;
98         }
99
100         simple_map_init(&ebony_small_map);
101
102         flash = do_map_probe("jedec_probe", &ebony_small_map);
103         if (flash) {
104                 flash->owner = THIS_MODULE;
105                 add_mtd_partitions(flash, ebony_small_partitions,
106                                         ARRAY_SIZE(ebony_small_partitions));
107         } else {
108                 printk("map probe failed for flash\n");
109                 iounmap(ebony_small_map.virt);
110                 return -ENXIO;
111         }
112
113         ebony_large_map.phys = large_flash_base;
114         ebony_large_map.virt = ioremap64(large_flash_base,
115                                          ebony_large_map.size);
116
117         if (!ebony_large_map.virt) {
118                 printk("Failed to ioremap flash\n");
119                 iounmap(ebony_small_map.virt);
120                 return -EIO;
121         }
122
123         simple_map_init(&ebony_large_map);
124
125         flash = do_map_probe("jedec_probe", &ebony_large_map);
126         if (flash) {
127                 flash->owner = THIS_MODULE;
128                 add_mtd_partitions(flash, ebony_large_partitions,
129                                         ARRAY_SIZE(ebony_large_partitions));
130         } else {
131                 printk("map probe failed for flash\n");
132                 iounmap(ebony_small_map.virt);
133                 iounmap(ebony_large_map.virt);
134                 return -ENXIO;
135         }
136
137         return 0;
138 }
139
140 static void __exit cleanup_ebony(void)
141 {
142         if (flash) {
143                 del_mtd_partitions(flash);
144                 map_destroy(flash);
145         }
146
147         if (ebony_small_map.virt) {
148                 iounmap(ebony_small_map.virt);
149                 ebony_small_map.virt = NULL;
150         }
151
152         if (ebony_large_map.virt) {
153                 iounmap(ebony_large_map.virt);
154                 ebony_large_map.virt = NULL;
155         }
156 }
157
158 module_init(init_ebony);
159 module_exit(cleanup_ebony);
160
161 MODULE_LICENSE("GPL");
162 MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
163 MODULE_DESCRIPTION("MTD map and partitions for IBM 440GP Ebony boards");