[ARM] Move include/asm-arm/arch-* to arch/arm/*/include/mach
[linux-2.6-block.git] / drivers / mtd / maps / cdb89712.c
CommitLineData
1da177e4
LT
1/*
2 * Flash on Cirrus CDB89712
3 *
1da177e4
LT
4 */
5
6#include <linux/module.h>
7#include <linux/types.h>
8#include <linux/kernel.h>
9#include <linux/ioport.h>
10#include <linux/init.h>
11#include <asm/io.h>
a09e64fb 12#include <mach/hardware.h>
1da177e4
LT
13#include <linux/mtd/mtd.h>
14#include <linux/mtd/map.h>
15#include <linux/mtd/partitions.h>
16
17
18
19
20static struct mtd_info *flash_mtd;
21
22struct map_info cdb89712_flash_map = {
23 .name = "flash",
24 .size = FLASH_SIZE,
25 .bankwidth = FLASH_WIDTH,
26 .phys = FLASH_START,
27};
28
29struct resource cdb89712_flash_resource = {
30 .name = "Flash",
31 .start = FLASH_START,
32 .end = FLASH_START + FLASH_SIZE - 1,
33 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
34};
35
36static int __init init_cdb89712_flash (void)
37{
38 int err;
69f34c98 39
1da177e4
LT
40 if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
41 printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
42 err = -EBUSY;
43 goto out;
44 }
69f34c98 45
1da177e4
LT
46 cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
47 if (!cdb89712_flash_map.virt) {
48 printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
49 err = -EIO;
50 goto out_resource;
51 }
52 simple_map_init(&cdb89712_flash_map);
53 flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map);
54 if (!flash_mtd) {
55 flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map);
56 if (flash_mtd)
57 flash_mtd->erasesize = 0x10000;
58 }
59 if (!flash_mtd) {
60 printk("FLASH probe failed\n");
61 err = -ENXIO;
62 goto out_ioremap;
63 }
64
65 flash_mtd->owner = THIS_MODULE;
69f34c98 66
1da177e4
LT
67 if (add_mtd_device(flash_mtd)) {
68 printk("FLASH device addition failed\n");
69 err = -ENOMEM;
70 goto out_probe;
71 }
69f34c98 72
1da177e4
LT
73 return 0;
74
75out_probe:
76 map_destroy(flash_mtd);
77 flash_mtd = 0;
78out_ioremap:
79 iounmap((void *)cdb89712_flash_map.virt);
80out_resource:
81 release_resource (&cdb89712_flash_resource);
82out:
83 return err;
84}
85
86
87
88
89
90static struct mtd_info *sram_mtd;
91
92struct map_info cdb89712_sram_map = {
93 .name = "SRAM",
94 .size = SRAM_SIZE,
95 .bankwidth = SRAM_WIDTH,
96 .phys = SRAM_START,
97};
98
99struct resource cdb89712_sram_resource = {
100 .name = "SRAM",
101 .start = SRAM_START,
102 .end = SRAM_START + SRAM_SIZE - 1,
103 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
104};
105
106static int __init init_cdb89712_sram (void)
107{
108 int err;
69f34c98 109
1da177e4
LT
110 if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
111 printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
112 err = -EBUSY;
113 goto out;
114 }
69f34c98 115
1da177e4
LT
116 cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
117 if (!cdb89712_sram_map.virt) {
118 printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
119 err = -EIO;
120 goto out_resource;
121 }
122 simple_map_init(&cdb89712_sram_map);
123 sram_mtd = do_map_probe("map_ram", &cdb89712_sram_map);
124 if (!sram_mtd) {
125 printk("SRAM probe failed\n");
126 err = -ENXIO;
127 goto out_ioremap;
128 }
129
130 sram_mtd->owner = THIS_MODULE;
131 sram_mtd->erasesize = 16;
69f34c98 132
1da177e4
LT
133 if (add_mtd_device(sram_mtd)) {
134 printk("SRAM device addition failed\n");
135 err = -ENOMEM;
136 goto out_probe;
137 }
69f34c98 138
1da177e4
LT
139 return 0;
140
141out_probe:
142 map_destroy(sram_mtd);
143 sram_mtd = 0;
144out_ioremap:
145 iounmap((void *)cdb89712_sram_map.virt);
146out_resource:
147 release_resource (&cdb89712_sram_resource);
148out:
149 return err;
150}
151
152
153
154
155
156
157
158static struct mtd_info *bootrom_mtd;
159
160struct map_info cdb89712_bootrom_map = {
161 .name = "BootROM",
162 .size = BOOTROM_SIZE,
163 .bankwidth = BOOTROM_WIDTH,
164 .phys = BOOTROM_START,
165};
166
167struct resource cdb89712_bootrom_resource = {
168 .name = "BootROM",
169 .start = BOOTROM_START,
170 .end = BOOTROM_START + BOOTROM_SIZE - 1,
171 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
172};
173
174static int __init init_cdb89712_bootrom (void)
175{
176 int err;
69f34c98 177
1da177e4
LT
178 if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
179 printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
180 err = -EBUSY;
181 goto out;
182 }
69f34c98 183
1da177e4
LT
184 cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
185 if (!cdb89712_bootrom_map.virt) {
186 printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
187 err = -EIO;
188 goto out_resource;
189 }
190 simple_map_init(&cdb89712_bootrom_map);
191 bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map);
192 if (!bootrom_mtd) {
193 printk("BootROM probe failed\n");
194 err = -ENXIO;
195 goto out_ioremap;
196 }
197
198 bootrom_mtd->owner = THIS_MODULE;
199 bootrom_mtd->erasesize = 0x10000;
69f34c98 200
1da177e4
LT
201 if (add_mtd_device(bootrom_mtd)) {
202 printk("BootROM device addition failed\n");
203 err = -ENOMEM;
204 goto out_probe;
205 }
69f34c98 206
1da177e4
LT
207 return 0;
208
209out_probe:
210 map_destroy(bootrom_mtd);
211 bootrom_mtd = 0;
212out_ioremap:
213 iounmap((void *)cdb89712_bootrom_map.virt);
214out_resource:
215 release_resource (&cdb89712_bootrom_resource);
216out:
217 return err;
218}
219
220
221
222
223
224static int __init init_cdb89712_maps(void)
225{
226
69f34c98 227 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",
1da177e4
LT
228 FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
229
230 init_cdb89712_flash();
231 init_cdb89712_sram();
232 init_cdb89712_bootrom();
69f34c98 233
1da177e4
LT
234 return 0;
235}
69f34c98 236
1da177e4
LT
237
238static void __exit cleanup_cdb89712_maps(void)
239{
240 if (sram_mtd) {
241 del_mtd_device(sram_mtd);
242 map_destroy(sram_mtd);
243 iounmap((void *)cdb89712_sram_map.virt);
244 release_resource (&cdb89712_sram_resource);
245 }
69f34c98 246
1da177e4
LT
247 if (flash_mtd) {
248 del_mtd_device(flash_mtd);
249 map_destroy(flash_mtd);
250 iounmap((void *)cdb89712_flash_map.virt);
251 release_resource (&cdb89712_flash_resource);
252 }
253
254 if (bootrom_mtd) {
255 del_mtd_device(bootrom_mtd);
256 map_destroy(bootrom_mtd);
257 iounmap((void *)cdb89712_bootrom_map.virt);
258 release_resource (&cdb89712_bootrom_resource);
259 }
260}
261
262module_init(init_cdb89712_maps);
263module_exit(cleanup_cdb89712_maps);
264
265MODULE_AUTHOR("Ray L");
266MODULE_DESCRIPTION("ARM CDB89712 map driver");
267MODULE_LICENSE("GPL");