Linux-2.6.12-rc2
[linux-flexiantxendom0-natty.git] / drivers / mtd / maps / redwood.c
1 /*
2  * $Id: redwood.c,v 1.10 2004/11/04 13:24:15 gleixner Exp $
3  *
4  * drivers/mtd/maps/redwood.c
5  *
6  * FLASH map for the IBM Redwood 4/5/6 boards.
7  *
8  * Author: MontaVista Software, Inc. <source@mvista.com>
9  *
10  * 2001-2003 (c) MontaVista, Software, Inc. This file is licensed under
11  * the terms of the GNU General Public License version 2. This program
12  * is licensed "as is" without any warranty of any kind, whether express
13  * or implied.
14  */
15
16 #include <linux/config.h>
17 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/map.h>
24 #include <linux/mtd/partitions.h>
25
26 #include <asm/io.h>
27
28 #if !defined (CONFIG_REDWOOD_6)
29
30 #define WINDOW_ADDR 0xffc00000
31 #define WINDOW_SIZE 0x00400000
32
33 #define RW_PART0_OF     0
34 #define RW_PART0_SZ     0x10000
35 #define RW_PART1_OF     RW_PART0_SZ
36 #define RW_PART1_SZ     0x200000 - 0x10000
37 #define RW_PART2_OF     0x200000
38 #define RW_PART2_SZ     0x10000
39 #define RW_PART3_OF     0x210000
40 #define RW_PART3_SZ     0x200000 - (0x10000 + 0x20000)
41 #define RW_PART4_OF     0x3e0000
42 #define RW_PART4_SZ     0x20000
43
44 static struct mtd_partition redwood_flash_partitions[] = {
45         {
46                 .name = "Redwood OpenBIOS Vital Product Data",
47                 .offset = RW_PART0_OF,
48                 .size = RW_PART0_SZ,
49                 .mask_flags = MTD_WRITEABLE     /* force read-only */
50         },
51         {
52                 .name = "Redwood kernel",
53                 .offset = RW_PART1_OF,
54                 .size = RW_PART1_SZ
55         },
56         {
57                 .name = "Redwood OpenBIOS non-volatile storage",
58                 .offset = RW_PART2_OF,
59                 .size = RW_PART2_SZ,
60                 .mask_flags = MTD_WRITEABLE     /* force read-only */
61         },
62         {
63                 .name = "Redwood filesystem",
64                 .offset = RW_PART3_OF,
65                 .size = RW_PART3_SZ
66         },
67         {
68                 .name = "Redwood OpenBIOS",
69                 .offset = RW_PART4_OF,
70                 .size = RW_PART4_SZ,
71                 .mask_flags = MTD_WRITEABLE     /* force read-only */
72         }
73 };
74
75 #else /* CONFIG_REDWOOD_6 */
76 /* FIXME: the window is bigger - armin */
77 #define WINDOW_ADDR 0xff800000
78 #define WINDOW_SIZE 0x00800000
79
80 #define RW_PART0_OF     0
81 #define RW_PART0_SZ     0x400000        /* 4 MiB data */
82 #define RW_PART1_OF     RW_PART0_OF + RW_PART0_SZ 
83 #define RW_PART1_SZ     0x10000         /* 64K VPD */
84 #define RW_PART2_OF     RW_PART1_OF + RW_PART1_SZ
85 #define RW_PART2_SZ     0x400000 - (0x10000 + 0x20000)
86 #define RW_PART3_OF     RW_PART2_OF + RW_PART2_SZ
87 #define RW_PART3_SZ     0x20000
88
89 static struct mtd_partition redwood_flash_partitions[] = {
90         {
91                 .name = "Redwood filesystem",
92                 .offset = RW_PART0_OF,
93                 .size = RW_PART0_SZ
94         },
95         {
96                 .name = "Redwood OpenBIOS Vital Product Data",
97                 .offset = RW_PART1_OF,
98                 .size = RW_PART1_SZ,
99                 .mask_flags = MTD_WRITEABLE     /* force read-only */
100         },
101         {
102                 .name = "Redwood kernel",
103                 .offset = RW_PART2_OF,
104                 .size = RW_PART2_SZ
105         },
106         {
107                 .name = "Redwood OpenBIOS",
108                 .offset = RW_PART3_OF,
109                 .size = RW_PART3_SZ,
110                 .mask_flags = MTD_WRITEABLE     /* force read-only */
111         }
112 };
113
114 #endif /* CONFIG_REDWOOD_6 */
115
116 struct map_info redwood_flash_map = {
117         .name = "IBM Redwood",
118         .size = WINDOW_SIZE,
119         .bankwidth = 2,
120         .phys = WINDOW_ADDR,
121 };
122
123
124 #define NUM_REDWOOD_FLASH_PARTITIONS \
125         (sizeof(redwood_flash_partitions)/sizeof(redwood_flash_partitions[0]))
126
127 static struct mtd_info *redwood_mtd;
128
129 int __init init_redwood_flash(void)
130 {
131         printk(KERN_NOTICE "redwood: flash mapping: %x at %x\n",
132                         WINDOW_SIZE, WINDOW_ADDR);
133
134         redwood_flash_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
135
136         if (!redwood_flash_map.virt) {
137                 printk("init_redwood_flash: failed to ioremap\n");
138                 return -EIO;
139         }
140         simple_map_init(&redwood_flash_map);
141
142         redwood_mtd = do_map_probe("cfi_probe",&redwood_flash_map);
143
144         if (redwood_mtd) {
145                 redwood_mtd->owner = THIS_MODULE;
146                 return add_mtd_partitions(redwood_mtd,
147                                 redwood_flash_partitions,
148                                 NUM_REDWOOD_FLASH_PARTITIONS);
149         }
150
151         return -ENXIO;
152 }
153
154 static void __exit cleanup_redwood_flash(void)
155 {
156         if (redwood_mtd) {
157                 del_mtd_partitions(redwood_mtd);
158                 /* moved iounmap after map_destroy - armin */
159                 map_destroy(redwood_mtd);
160                 iounmap((void *)redwood_flash_map.virt);
161         }
162 }
163
164 module_init(init_redwood_flash);
165 module_exit(cleanup_redwood_flash);
166
167 MODULE_LICENSE("GPL");
168 MODULE_AUTHOR("MontaVista Software <source@mvista.com>");
169 MODULE_DESCRIPTION("MTD map driver for the IBM Redwood reference boards");