MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / mtd / maps / altera.c
blob4f0be50c7385805a6deb8ade207934af560a3070
1 /*
2 * Normal mappings of altera Nios II development kit flash in physical memory
3 * Derived from physmap.c, by Microtronix Datacom Ltd.
4 */
6 #include <linux/module.h>
7 #include <linux/types.h>
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/slab.h>
11 #include <asm/io.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/map.h>
14 #include <linux/mtd/partitions.h>
15 #include <asm/nios.h>
17 /* map solutions */
18 #define WINDOW_ADDR na_flash_kernel
19 #define WINDOW_SIZE na_flash_kernel_size
20 #define BUSWIDTH 1
22 static struct mtd_info *mymtd;
25 struct map_info ndk_amd_map = {
26 .name = "Altera NDK flash (AMD)",
27 .size = WINDOW_SIZE,
28 .bankwidth = BUSWIDTH,
29 .phys = WINDOW_ADDR,
32 #ifdef CONFIG_MTD_PARTITIONS
33 static struct mtd_partition *mtd_parts;
34 static int mtd_parts_nb;
36 static struct mtd_partition alteramap_partitions[] = {
37 #ifdef CONFIG_ALTERA_STRATIX_II
39 .name = "romfs/jffs2",
40 .size = 0x600000,
41 .offset = 0x200000,
42 },{
43 .name = "loader/kernel",
44 .size = 0x200000,
45 .offset = 0,
46 }, {
47 .name = "User configuration",
48 .size = 0x400000,
49 .offset = 0x800000,
50 }, {
51 .name = "safe configuration",
52 .size = 0x400000,
53 .offset = 0xc00000,
54 .mask_flags = MTD_WRITEABLE, /* force read-only */
56 #elif defined(CONFIG_ALTERA_STRATIX_PRO)
58 .name = "romfs/jffs2",
59 .size = 0x200000,
60 .offset = 0x200000,
61 },{
62 .name = "loader/kernel",
63 .size = 0x200000,
64 .offset = 0,
65 }, {
66 .name = "User configuration",
67 .size = 0x200000,
68 .offset = 0x400000,
69 }, {
70 .name = "safe configuration",
71 .size = 0x200000,
72 .offset = 0x600000,
73 .mask_flags = MTD_WRITEABLE, /* force read-only */
75 #else
77 .name = "romfs/jffs2",
78 .size = 0x400000,
79 .offset = 0x200000,
80 },{
81 .name = "loader/kernel",
82 .size = 0x200000,
83 .offset = 0,
84 }, {
85 .name = "User configuration",
86 .size = 0x100000,
87 .offset = 0x600000,
88 }, {
89 .name = "safe configuration",
90 .size = 0x100000,
91 .offset = 0x700000,
92 .mask_flags = MTD_WRITEABLE, /* force read-only */
94 #endif
97 #define NUM_PARTITIONS (sizeof(alteramap_partitions)/sizeof(struct mtd_partition))
98 const char *part_probes[] = {"cmdlinepart", "RedBoot", NULL};
100 #endif /* CONFIG_MTD_PARTITIONS */
102 int __init init_alteramap(void)
104 static const char *rom_probe_types[] = {"cfi_probe", "jedec_probe", 0 };
105 const char **type;
107 ndk_amd_map.virt = (unsigned long *)ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
109 if (!ndk_amd_map.virt) {
110 printk("Failed to ioremap\n");
111 return -EIO;
114 simple_map_init(&ndk_amd_map);
116 mymtd = 0;
117 type = rom_probe_types;
118 for(; !mymtd && *type; type++) {
119 mymtd = do_map_probe(*type, &ndk_amd_map);
121 if (mymtd) {
122 mymtd->owner = THIS_MODULE;
124 #ifdef CONFIG_MTD_PARTITIONS
125 mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes,
126 &mtd_parts, 0);
128 if (mtd_parts_nb > 0)
130 add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
131 return 0;
134 if (NUM_PARTITIONS != 0)
136 printk(KERN_NOTICE
137 "Using Altera NDK partition definition\n");
138 add_mtd_partitions (mymtd, alteramap_partitions, NUM_PARTITIONS);
139 return 0;
142 #endif
143 add_mtd_device(mymtd);
145 return 0;
148 iounmap((void *)ndk_amd_map.virt);
149 return -ENXIO;
152 static void __exit cleanup_alteramap(void)
154 #ifdef CONFIG_MTD_PARTITIONS
155 if (mtd_parts_nb) {
156 del_mtd_partitions(mymtd);
157 kfree(mtd_parts);
158 } else if (NUM_PARTITIONS) {
159 del_mtd_partitions(mymtd);
160 } else {
161 del_mtd_device(mymtd);
163 #else
164 del_mtd_device(mymtd);
165 #endif
166 map_destroy(mymtd);
168 iounmap((void *)ndk_amd_map.virt);
169 ndk_amd_map.virt = 0;
172 module_init(init_alteramap);
173 module_exit(cleanup_alteramap);
176 MODULE_LICENSE("GPL");
177 MODULE_AUTHOR("Microtronix Datacom <www.microtronix.com>");
178 MODULE_DESCRIPTION("MTD map driver for Altera Nios Development Kit");