x86: arch/x86/mm/init_32.c cleanup
[wrt350n-kernel.git] / drivers / mtd / maps / cdb89712.c
blob9f17bb6c5a9d388714c8822ea412230d918b6b38
1 /*
2 * Flash on Cirrus CDB89712
4 * $Id: cdb89712.c,v 1.11 2005/11/07 11:14:26 gleixner Exp $
5 */
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/ioport.h>
11 #include <linux/init.h>
12 #include <asm/io.h>
13 #include <asm/arch/hardware.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/map.h>
16 #include <linux/mtd/partitions.h>
21 static struct mtd_info *flash_mtd;
23 struct map_info cdb89712_flash_map = {
24 .name = "flash",
25 .size = FLASH_SIZE,
26 .bankwidth = FLASH_WIDTH,
27 .phys = FLASH_START,
30 struct resource cdb89712_flash_resource = {
31 .name = "Flash",
32 .start = FLASH_START,
33 .end = FLASH_START + FLASH_SIZE - 1,
34 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
37 static int __init init_cdb89712_flash (void)
39 int err;
41 if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
42 printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
43 err = -EBUSY;
44 goto out;
47 cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
48 if (!cdb89712_flash_map.virt) {
49 printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
50 err = -EIO;
51 goto out_resource;
53 simple_map_init(&cdb89712_flash_map);
54 flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map);
55 if (!flash_mtd) {
56 flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map);
57 if (flash_mtd)
58 flash_mtd->erasesize = 0x10000;
60 if (!flash_mtd) {
61 printk("FLASH probe failed\n");
62 err = -ENXIO;
63 goto out_ioremap;
66 flash_mtd->owner = THIS_MODULE;
68 if (add_mtd_device(flash_mtd)) {
69 printk("FLASH device addition failed\n");
70 err = -ENOMEM;
71 goto out_probe;
74 return 0;
76 out_probe:
77 map_destroy(flash_mtd);
78 flash_mtd = 0;
79 out_ioremap:
80 iounmap((void *)cdb89712_flash_map.virt);
81 out_resource:
82 release_resource (&cdb89712_flash_resource);
83 out:
84 return err;
91 static struct mtd_info *sram_mtd;
93 struct map_info cdb89712_sram_map = {
94 .name = "SRAM",
95 .size = SRAM_SIZE,
96 .bankwidth = SRAM_WIDTH,
97 .phys = SRAM_START,
100 struct resource cdb89712_sram_resource = {
101 .name = "SRAM",
102 .start = SRAM_START,
103 .end = SRAM_START + SRAM_SIZE - 1,
104 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
107 static int __init init_cdb89712_sram (void)
109 int err;
111 if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
112 printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
113 err = -EBUSY;
114 goto out;
117 cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
118 if (!cdb89712_sram_map.virt) {
119 printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
120 err = -EIO;
121 goto out_resource;
123 simple_map_init(&cdb89712_sram_map);
124 sram_mtd = do_map_probe("map_ram", &cdb89712_sram_map);
125 if (!sram_mtd) {
126 printk("SRAM probe failed\n");
127 err = -ENXIO;
128 goto out_ioremap;
131 sram_mtd->owner = THIS_MODULE;
132 sram_mtd->erasesize = 16;
134 if (add_mtd_device(sram_mtd)) {
135 printk("SRAM device addition failed\n");
136 err = -ENOMEM;
137 goto out_probe;
140 return 0;
142 out_probe:
143 map_destroy(sram_mtd);
144 sram_mtd = 0;
145 out_ioremap:
146 iounmap((void *)cdb89712_sram_map.virt);
147 out_resource:
148 release_resource (&cdb89712_sram_resource);
149 out:
150 return err;
159 static struct mtd_info *bootrom_mtd;
161 struct map_info cdb89712_bootrom_map = {
162 .name = "BootROM",
163 .size = BOOTROM_SIZE,
164 .bankwidth = BOOTROM_WIDTH,
165 .phys = BOOTROM_START,
168 struct resource cdb89712_bootrom_resource = {
169 .name = "BootROM",
170 .start = BOOTROM_START,
171 .end = BOOTROM_START + BOOTROM_SIZE - 1,
172 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
175 static int __init init_cdb89712_bootrom (void)
177 int err;
179 if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
180 printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
181 err = -EBUSY;
182 goto out;
185 cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
186 if (!cdb89712_bootrom_map.virt) {
187 printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
188 err = -EIO;
189 goto out_resource;
191 simple_map_init(&cdb89712_bootrom_map);
192 bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map);
193 if (!bootrom_mtd) {
194 printk("BootROM probe failed\n");
195 err = -ENXIO;
196 goto out_ioremap;
199 bootrom_mtd->owner = THIS_MODULE;
200 bootrom_mtd->erasesize = 0x10000;
202 if (add_mtd_device(bootrom_mtd)) {
203 printk("BootROM device addition failed\n");
204 err = -ENOMEM;
205 goto out_probe;
208 return 0;
210 out_probe:
211 map_destroy(bootrom_mtd);
212 bootrom_mtd = 0;
213 out_ioremap:
214 iounmap((void *)cdb89712_bootrom_map.virt);
215 out_resource:
216 release_resource (&cdb89712_bootrom_resource);
217 out:
218 return err;
225 static int __init init_cdb89712_maps(void)
228 printk(KERN_INFO "Cirrus CDB89712 MTD mappings:\n Flash 0x%x at 0x%x\n SRAM 0x%x at 0x%x\n BootROM 0x%x at 0x%x\n",
229 FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
231 init_cdb89712_flash();
232 init_cdb89712_sram();
233 init_cdb89712_bootrom();
235 return 0;
239 static void __exit cleanup_cdb89712_maps(void)
241 if (sram_mtd) {
242 del_mtd_device(sram_mtd);
243 map_destroy(sram_mtd);
244 iounmap((void *)cdb89712_sram_map.virt);
245 release_resource (&cdb89712_sram_resource);
248 if (flash_mtd) {
249 del_mtd_device(flash_mtd);
250 map_destroy(flash_mtd);
251 iounmap((void *)cdb89712_flash_map.virt);
252 release_resource (&cdb89712_flash_resource);
255 if (bootrom_mtd) {
256 del_mtd_device(bootrom_mtd);
257 map_destroy(bootrom_mtd);
258 iounmap((void *)cdb89712_bootrom_map.virt);
259 release_resource (&cdb89712_bootrom_resource);
263 module_init(init_cdb89712_maps);
264 module_exit(cleanup_cdb89712_maps);
266 MODULE_AUTHOR("Ray L");
267 MODULE_DESCRIPTION("ARM CDB89712 map driver");
268 MODULE_LICENSE("GPL");