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