2 * magicmap.c: Copyleft 2005 Karol Lewandowski
4 * Mapping for MagicBox flash.
7 * Heikki Lindholm <holindho@infradead.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/map.h>
22 #include <linux/mtd/partitions.h>
23 #include <linux/autoconf.h>
26 static struct mtd_info *flash;
28 static struct map_info magic_map = {
29 .name = "Magically mapped flash",
35 static struct mtd_partition magic_partitions[] = {
50 .mask_flags = MTD_WRITEABLE,
54 int __init init_magic(void)
59 (void __iomem *)ioremap(magic_map.phys, magic_map.size);
61 if (!magic_map.virt) {
62 printk("Failed to ioremap flash.\n");
66 simple_map_init(&magic_map);
68 flash = do_map_probe("cfi_probe", &magic_map);
70 flash->owner = THIS_MODULE;
71 if (flash->read(flash, 12, sizeof(u32), &len, (char *) &size) ||
74 size += 0x40; /* header size of the uImage */
75 if (size < 0x400000) {
76 /* skip to next erase block */
77 if (size & (flash->erasesize - 1)) {
78 size |= (flash->erasesize - 1);
81 magic_partitions[1].offset = size;
82 magic_partitions[1].size = magic_partitions[2].offset - size;
85 add_mtd_partitions(flash, magic_partitions,
86 ARRAY_SIZE(magic_partitions));
88 printk("map probe failed for flash\n");
95 static void __exit cleanup_magic(void)
98 del_mtd_partitions(flash);
102 if (magic_map.virt) {
103 iounmap((void *)magic_map.virt);
104 magic_map.virt = NULL;
108 module_init(init_magic);
109 module_exit(cleanup_magic);
111 MODULE_LICENSE("GPL");
112 MODULE_AUTHOR("Karol Lewandowski");
113 MODULE_DESCRIPTION("MTD map and partitions for IBM 405EP MagicBox boards");