Update rdc to .21, mark it as broken
[openwrt.git] / target / linux / magicbox-2.6 / files / drivers / mtd / maps / magicmap.c
1 /*
2  * magicmap.c: Copyleft 2005  Karol Lewandowski
3  *
4  * Mapping for MagicBox flash.
5  * Based on walnut.c.
6  *
7  * Heikki Lindholm <holindho@infradead.org>
8  *
9  *
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.
14  */
15
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>
24 #include <asm/io.h>
25
26 static struct mtd_info *flash;
27
28 static struct map_info magic_map = {
29         .name =         "Magically mapped flash",
30         .phys =         0xffc00000,
31         .size =         0x400000,
32         .bankwidth =    2,
33 };
34
35 static struct mtd_partition magic_partitions[] = {
36         {
37                 .name =   "linux",
38                 .offset = 0x0,
39                 .size =   0x3c0000,
40         },
41         {
42                 .name =   "rootfs",
43                 .offset = 0x100000,
44                 .size =   0x2c0000,
45         },
46         {
47                 .name =   "bootloader",
48                 .offset = 0x3c0000,
49                 .size =   0x040000,
50                 .mask_flags = MTD_WRITEABLE,
51         },
52 };
53
54 int __init init_magic(void)
55 {
56         u32 size, len;
57         
58         magic_map.virt =
59                 (void __iomem *)ioremap(magic_map.phys, magic_map.size);
60
61         if (!magic_map.virt) {
62                 printk("Failed to ioremap flash.\n");
63                 return -EIO;
64         }
65
66         simple_map_init(&magic_map);
67
68         flash = do_map_probe("cfi_probe", &magic_map);
69         if (flash) {
70                 flash->owner = THIS_MODULE;
71                 if (flash->read(flash, 12, sizeof(u32), &len, (char *) &size) ||
72                         len != 4)
73                         return -ENXIO;
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);
79                                 size += 1;
80                         }
81                         magic_partitions[1].offset = size;
82                         magic_partitions[1].size = magic_partitions[2].offset - size;
83                 }
84                 
85                 add_mtd_partitions(flash, magic_partitions,
86                                         ARRAY_SIZE(magic_partitions));
87         } else {
88                 printk("map probe failed for flash\n");
89                 return -ENXIO;
90         }
91
92         return 0;
93 }
94
95 static void __exit cleanup_magic(void)
96 {
97         if (flash) {
98                 del_mtd_partitions(flash);
99                 map_destroy(flash);
100         }
101
102         if (magic_map.virt) {
103                 iounmap((void *)magic_map.virt);
104                 magic_map.virt = NULL;
105         }
106 }
107
108 module_init(init_magic);
109 module_exit(cleanup_magic);
110
111 MODULE_LICENSE("GPL");
112 MODULE_AUTHOR("Karol Lewandowski");
113 MODULE_DESCRIPTION("MTD map and partitions for IBM 405EP MagicBox boards");