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>
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/map.h>
23 #include <linux/mtd/partitions.h>
25 #include "../chips/epcs.h"
29 static struct mtd_info
*mymtd
;
31 struct map_info alt_epcs_map
= {
32 .name
= "Altera EPCS Flash",
33 .phys
= na_epcs_controller
,
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
[] =
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
};
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");
78 simple_map_init(&alt_epcs_map
);
81 type
= rom_probe_types
;
82 for(; !mymtd
&& *type
; type
++) {
85 printk(KERN_NOTICE
"Probing for %s\n",*type
);
88 mymtd
= do_map_probe(*type
, &alt_epcs_map
);
91 mymtd
->owner
= THIS_MODULE
;
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
);
97 #ifdef CONFIG_MTD_PARTITIONS
98 mtd_parts_nb
= parse_mtd_partitions(mymtd
, part_probes
,
101 if (mtd_parts_nb
> 0)
103 add_mtd_partitions (mymtd
, mtd_parts
, mtd_parts_nb
);
107 if (NUM_PARTITIONS
!= 0)
110 printk(KERN_NOTICE
"Using Altera EPCS partition definition\n");
113 add_mtd_partitions (mymtd
, epcs_partitions
, NUM_PARTITIONS
);
118 add_mtd_device(mymtd
);
124 printk(KERN_NOTICE
"No Partitions found on EPCS Device\n");
127 iounmap(alt_epcs_map
.virt
);
131 static void __exit
cleanup_epcsmap(void)
133 #ifdef CONFIG_MTD_PARTITIONS
135 del_mtd_partitions(mymtd
);
137 } else if (num_physmap_partitions
) {
138 del_mtd_partitions(mymtd
);
140 del_mtd_device(mymtd
);
143 del_mtd_device(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");