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