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 / epcs_map.c
blob78990b6e78fe882641efe9500f61b067ab56bd56
1 /*
3 * Mappings into EPCS Configuration Flash device by Altera
5 * Copyright (C) 2006 FPS-Tech (http://www.fps-tech.net)
6 * Author: Jai Dhar, contact@fps-tech.net (jdhar)
8 * Adapted from physmap.c
10 * - Driver to map partitions into EPCS Configuration device
11 * - Map Size should get set by epcs_probe when it detects a chip
12 * - IOREMAP is done for maximum size possible (64Mbit)
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <asm/io.h>
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/map.h>
23 #include <linux/mtd/partitions.h>
25 #include "../chips/epcs.h"
27 #define BUSWIDTH 1
29 static struct mtd_info *mymtd;
31 struct map_info alt_epcs_map = {
32 .name = "Altera EPCS Flash",
33 .phys = na_epcs_controller,
34 .size = 0,
35 .bankwidth = BUSWIDTH,
38 #ifdef CONFIG_MTD_PARTITIONS
39 static struct mtd_partition *mtd_parts;
40 static int mtd_parts_nb;
42 static int num_physmap_partitions;
43 static struct mtd_partition epcs_partitions[] =
46 .name = "small_part",
47 .size = 0x200000,
48 .offset = 0x400000,
51 .name = "big_part",
52 .size = 0x200000,
53 .offset = 0x600000,
57 static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
59 #define NUM_PARTITIONS (sizeof(epcs_partitions)/sizeof(struct mtd_partition))
61 #endif /* CONFIG_MTD_PARTITIONS */
63 static int __init init_epcsmap(void)
65 static const char *rom_probe_types[] = { "epcs", NULL };
66 const char **type;
68 /* Not sure about this, but since IOREMAP looks like it needs to happen before the chip is probed,
69 * the maximum space (64Mbit) must be allocated */
70 alt_epcs_map.virt = (unsigned long *)ioremap_nocache(na_epcs_controller, na_epcs_controller_size);
73 if (!physmap_map.virt) {
74 printk("Failed to ioremap\n");
75 return -EIO;
76 }*/
78 simple_map_init(&alt_epcs_map);
80 mymtd = NULL;
81 type = rom_probe_types;
82 for(; !mymtd && *type; type++) {
84 #if EPCS_DEBUG1
85 printk(KERN_NOTICE "Probing for %s\n",*type);
86 #endif
88 mymtd = do_map_probe(*type, &alt_epcs_map);
90 if (mymtd) {
91 mymtd->owner = THIS_MODULE;
93 #if EPCS_DEBUG1
94 printk(KERN_NOTICE "alt_epcs flash device: %d Kbytes at 0x%X\n", (u_int) alt_epcs_map.size/1024, (u_int) alt_epcs_map.phys);
95 #endif
97 #ifdef CONFIG_MTD_PARTITIONS
98 mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes,
99 &mtd_parts, 0);
101 if (mtd_parts_nb > 0)
103 add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
104 return 0;
107 if (NUM_PARTITIONS != 0)
109 #if EPCS_DEBUG1
110 printk(KERN_NOTICE "Using Altera EPCS partition definition\n");
111 #endif
113 add_mtd_partitions (mymtd, epcs_partitions, NUM_PARTITIONS);
114 return 0;
117 #endif
118 add_mtd_device(mymtd);
120 return 0;
122 else
124 printk(KERN_NOTICE "No Partitions found on EPCS Device\n");
127 iounmap(alt_epcs_map.virt);
128 return -ENXIO;
131 static void __exit cleanup_epcsmap(void)
133 #ifdef CONFIG_MTD_PARTITIONS
134 if (mtd_parts_nb) {
135 del_mtd_partitions(mymtd);
136 kfree(mtd_parts);
137 } else if (num_physmap_partitions) {
138 del_mtd_partitions(mymtd);
139 } else {
140 del_mtd_device(mymtd);
142 #else
143 del_mtd_device(mymtd);
144 #endif
145 map_destroy(mymtd);
147 iounmap(alt_epcs_map.virt);
148 alt_epcs_map.virt = NULL;
151 module_init(init_epcsmap);
152 module_exit(cleanup_epcsmap);
155 MODULE_LICENSE("GPL");
156 MODULE_AUTHOR("Jai Dhar <contact@fps-tech.net>");
157 MODULE_DESCRIPTION("Altera EPCS Map Device");