2 * Flash on Cirrus CDB89712
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>
12 #include <mach/hardware.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/map.h>
15 #include <linux/mtd/partitions.h>
17 /* dynamic ioremap() areas */
18 #define FLASH_START 0x00000000
19 #define FLASH_SIZE 0x800000
22 #define SRAM_START 0x60000000
23 #define SRAM_SIZE 0xc000
26 #define BOOTROM_START 0x70000000
27 #define BOOTROM_SIZE 0x80
28 #define BOOTROM_WIDTH 4
31 static struct mtd_info
*flash_mtd
;
33 struct map_info cdb89712_flash_map
= {
36 .bankwidth
= FLASH_WIDTH
,
40 struct resource cdb89712_flash_resource
= {
43 .end
= FLASH_START
+ FLASH_SIZE
- 1,
44 .flags
= IORESOURCE_IO
| IORESOURCE_BUSY
,
47 static int __init
init_cdb89712_flash (void)
51 if (request_resource (&ioport_resource
, &cdb89712_flash_resource
)) {
52 printk(KERN_NOTICE
"Failed to reserve Cdb89712 FLASH space\n");
57 cdb89712_flash_map
.virt
= ioremap(FLASH_START
, FLASH_SIZE
);
58 if (!cdb89712_flash_map
.virt
) {
59 printk(KERN_NOTICE
"Failed to ioremap Cdb89712 FLASH space\n");
63 simple_map_init(&cdb89712_flash_map
);
64 flash_mtd
= do_map_probe("cfi_probe", &cdb89712_flash_map
);
66 flash_mtd
= do_map_probe("map_rom", &cdb89712_flash_map
);
68 flash_mtd
->erasesize
= 0x10000;
71 printk("FLASH probe failed\n");
76 flash_mtd
->owner
= THIS_MODULE
;
78 if (mtd_device_register(flash_mtd
, NULL
, 0)) {
79 printk("FLASH device addition failed\n");
87 map_destroy(flash_mtd
);
90 iounmap((void *)cdb89712_flash_map
.virt
);
92 release_resource (&cdb89712_flash_resource
);
101 static struct mtd_info
*sram_mtd
;
103 struct map_info cdb89712_sram_map
= {
106 .bankwidth
= SRAM_WIDTH
,
110 struct resource cdb89712_sram_resource
= {
113 .end
= SRAM_START
+ SRAM_SIZE
- 1,
114 .flags
= IORESOURCE_IO
| IORESOURCE_BUSY
,
117 static int __init
init_cdb89712_sram (void)
121 if (request_resource (&ioport_resource
, &cdb89712_sram_resource
)) {
122 printk(KERN_NOTICE
"Failed to reserve Cdb89712 SRAM space\n");
127 cdb89712_sram_map
.virt
= ioremap(SRAM_START
, SRAM_SIZE
);
128 if (!cdb89712_sram_map
.virt
) {
129 printk(KERN_NOTICE
"Failed to ioremap Cdb89712 SRAM space\n");
133 simple_map_init(&cdb89712_sram_map
);
134 sram_mtd
= do_map_probe("map_ram", &cdb89712_sram_map
);
136 printk("SRAM probe failed\n");
141 sram_mtd
->owner
= THIS_MODULE
;
142 sram_mtd
->erasesize
= 16;
144 if (mtd_device_register(sram_mtd
, NULL
, 0)) {
145 printk("SRAM device addition failed\n");
153 map_destroy(sram_mtd
);
156 iounmap((void *)cdb89712_sram_map
.virt
);
158 release_resource (&cdb89712_sram_resource
);
169 static struct mtd_info
*bootrom_mtd
;
171 struct map_info cdb89712_bootrom_map
= {
173 .size
= BOOTROM_SIZE
,
174 .bankwidth
= BOOTROM_WIDTH
,
175 .phys
= BOOTROM_START
,
178 struct resource cdb89712_bootrom_resource
= {
180 .start
= BOOTROM_START
,
181 .end
= BOOTROM_START
+ BOOTROM_SIZE
- 1,
182 .flags
= IORESOURCE_IO
| IORESOURCE_BUSY
,
185 static int __init
init_cdb89712_bootrom (void)
189 if (request_resource (&ioport_resource
, &cdb89712_bootrom_resource
)) {
190 printk(KERN_NOTICE
"Failed to reserve Cdb89712 BOOTROM space\n");
195 cdb89712_bootrom_map
.virt
= ioremap(BOOTROM_START
, BOOTROM_SIZE
);
196 if (!cdb89712_bootrom_map
.virt
) {
197 printk(KERN_NOTICE
"Failed to ioremap Cdb89712 BootROM space\n");
201 simple_map_init(&cdb89712_bootrom_map
);
202 bootrom_mtd
= do_map_probe("map_rom", &cdb89712_bootrom_map
);
204 printk("BootROM probe failed\n");
209 bootrom_mtd
->owner
= THIS_MODULE
;
210 bootrom_mtd
->erasesize
= 0x10000;
212 if (mtd_device_register(bootrom_mtd
, NULL
, 0)) {
213 printk("BootROM device addition failed\n");
221 map_destroy(bootrom_mtd
);
224 iounmap((void *)cdb89712_bootrom_map
.virt
);
226 release_resource (&cdb89712_bootrom_resource
);
235 static int __init
init_cdb89712_maps(void)
238 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",
239 FLASH_SIZE
, FLASH_START
, SRAM_SIZE
, SRAM_START
, BOOTROM_SIZE
, BOOTROM_START
);
241 init_cdb89712_flash();
242 init_cdb89712_sram();
243 init_cdb89712_bootrom();
249 static void __exit
cleanup_cdb89712_maps(void)
252 mtd_device_unregister(sram_mtd
);
253 map_destroy(sram_mtd
);
254 iounmap((void *)cdb89712_sram_map
.virt
);
255 release_resource (&cdb89712_sram_resource
);
259 mtd_device_unregister(flash_mtd
);
260 map_destroy(flash_mtd
);
261 iounmap((void *)cdb89712_flash_map
.virt
);
262 release_resource (&cdb89712_flash_resource
);
266 mtd_device_unregister(bootrom_mtd
);
267 map_destroy(bootrom_mtd
);
268 iounmap((void *)cdb89712_bootrom_map
.virt
);
269 release_resource (&cdb89712_bootrom_resource
);
273 module_init(init_cdb89712_maps
);
274 module_exit(cleanup_cdb89712_maps
);
276 MODULE_AUTHOR("Ray L");
277 MODULE_DESCRIPTION("ARM CDB89712 map driver");
278 MODULE_LICENSE("GPL");