update flash map driver for jffs2, squashfs will follow later
[openwrt-10.03/.git] / target / linux / magicbox-2.6 / patches / 002-flash_map.patch
1 diff -urN linux.old/drivers/mtd/maps/Kconfig linux.dev/drivers/mtd/maps/Kconfig
2 --- linux.old/drivers/mtd/maps/Kconfig  2006-08-30 06:30:59.000000000 +0200
3 +++ linux.dev/drivers/mtd/maps/Kconfig  2006-08-30 06:11:51.000000000 +0200
4 @@ -323,6 +323,15 @@
5           Walnut board. If you have one of these boards and would like to
6           use the flash chips on it, say 'Y'.
7  
8 +config MTD_MAGICMAP
9 +       tristate "Flash device mapped on IBM 405EP MagicBox"
10 +       depends on MTD_CFI && MTD_PARTITIONS && 40x && MAGICBOX
11 +       help
12 +         This enables access routines for the flash chips on the IBM 405EP
13 +         MagicBox board. If you have one of these boards and would like to
14 +         use the flash chips on it, say 'Y'.
15 +
16 +
17  config MTD_EBONY
18         tristate "Flash devices mapped on IBM 440GP Ebony"
19         depends on MTD_JEDECPROBE && EBONY
20 diff -urN linux.old/drivers/mtd/maps/magicmap.c linux.dev/drivers/mtd/maps/magicmap.c
21 --- linux.old/drivers/mtd/maps/magicmap.c       1970-01-01 01:00:00.000000000 +0100
22 +++ linux.dev/drivers/mtd/maps/magicmap.c       2006-08-30 06:52:34.000000000 +0200
23 @@ -0,0 +1,112 @@
24 +/*
25 + * magicmap.c: Copyleft 2005  Karol Lewandowski
26 + *
27 + * Mapping for MagicBox flash.
28 + * Based on walnut.c.
29 + *
30 + * Heikki Lindholm <holindho@infradead.org>
31 + *
32 + *
33 + * This program is free software; you can redistribute  it and/or modify it
34 + * under  the terms of  the GNU General  Public License as published by the
35 + * Free Software Foundation;  either version 2 of the  License, or (at your
36 + * option) any later version.
37 + */
38 +
39 +#include <linux/module.h>
40 +#include <linux/types.h>
41 +#include <linux/kernel.h>
42 +#include <linux/init.h>
43 +#include <linux/mtd/mtd.h>
44 +#include <linux/mtd/map.h>
45 +#include <linux/mtd/partitions.h>
46 +#include <linux/config.h>
47 +#include <asm/io.h>
48 +
49 +static struct mtd_info *flash;
50 +
51 +static struct map_info magic_map = {
52 +       .name =         "Magically mapped flash",
53 +       .phys =         0xffc00000,
54 +       .size =         0x400000,
55 +       .bankwidth =    2,
56 +};
57 +
58 +static struct mtd_partition magic_partitions[] = {
59 +       {
60 +               .name =   "linux",
61 +               .offset = 0x0,
62 +               .size =   0x3c0000,
63 +       },
64 +       {
65 +               .name =   "rootfs",
66 +               .offset = 0x100000,
67 +               .size =   0x2c0000,
68 +       },
69 +       {
70 +               .name =   "bootloader",
71 +               .offset = 0x3c0000,
72 +               .size =   0x040000,
73 +               .mask_flags = MTD_WRITEABLE,
74 +       },
75 +};
76 +
77 +int __init init_magic(void)
78 +{
79 +       u32 size, len;
80 +       
81 +       magic_map.virt =
82 +               (void __iomem *)ioremap(magic_map.phys, magic_map.size);
83 +
84 +       if (!magic_map.virt) {
85 +               printk("Failed to ioremap flash.\n");
86 +               return -EIO;
87 +       }
88 +
89 +       simple_map_init(&magic_map);
90 +
91 +       flash = do_map_probe("cfi_probe", &magic_map);
92 +       if (flash) {
93 +               flash->owner = THIS_MODULE;
94 +               if (MTD_READ(flash, 12, sizeof(u32), &len, (char *) &size) ||
95 +                       len != 4)
96 +                       return -ENXIO;
97 +               if ((size > 0) && (size < 0x400000)) {
98 +                       /* skip to next erase block */
99 +                       if (size & (flash->erasesize - 1)) {
100 +                               size |= (flash->erasesize - 1);
101 +                               size += 1;
102 +                       }
103 +                       magic_partitions[1].offset = size;
104 +                       magic_partitions[1].size = magic_partitions[2].offset - size;
105 +               }
106 +               
107 +               add_mtd_partitions(flash, magic_partitions,
108 +                                       ARRAY_SIZE(magic_partitions));
109 +       } else {
110 +               printk("map probe failed for flash\n");
111 +               return -ENXIO;
112 +       }
113 +
114 +       return 0;
115 +}
116 +
117 +static void __exit cleanup_magic(void)
118 +{
119 +       if (flash) {
120 +               del_mtd_partitions(flash);
121 +               map_destroy(flash);
122 +       }
123 +
124 +       if (magic_map.virt) {
125 +               iounmap((void *)magic_map.virt);
126 +               magic_map.virt = NULL;
127 +       }
128 +}
129 +
130 +module_init(init_magic);
131 +module_exit(cleanup_magic);
132 +
133 +MODULE_LICENSE("GPL");
134 +MODULE_AUTHOR("Karol Lewandowski");
135 +MODULE_DESCRIPTION("MTD map and partitions for IBM 405EP MagicBox boards");
136 diff -urN linux.old/drivers/mtd/maps/Makefile linux.dev/drivers/mtd/maps/Makefile
137 --- linux.old/drivers/mtd/maps/Makefile 2006-08-30 06:30:59.000000000 +0200
138 +++ linux.dev/drivers/mtd/maps/Makefile 2006-08-30 06:11:51.000000000 +0200
139 @@ -58,6 +58,7 @@
140  obj-$(CONFIG_MTD_BEECH)                += beech-mtd.o
141  obj-$(CONFIG_MTD_ARCTIC)       += arctic-mtd.o
142  obj-$(CONFIG_MTD_WALNUT)        += walnut.o
143 +obj-$(CONFIG_MTD_MAGICMAP)      += magicmap.o
144  obj-$(CONFIG_MTD_H720X)                += h720x-flash.o
145  obj-$(CONFIG_MTD_SBC8240)      += sbc8240.o
146  obj-$(CONFIG_MTD_NOR_TOTO)     += omap-toto-flash.o