Linux-2.6.12-rc2
[linux-2.6/kvm.git] / drivers / mtd / maps / physmap.c
blobb853670bfb81d6b4ffc6d58d5aa62a2d00c5669d
1 /*
2 * $Id: physmap.c,v 1.37 2004/11/28 09:40:40 dwmw2 Exp $
4 * Normal mappings of chips in physical memory
6 * Copyright (C) 2003 MontaVista Software Inc.
7 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
9 * 031022 - [jsun] add run-time configure and partition setup
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <asm/io.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/map.h>
20 #include <linux/config.h>
21 #include <linux/mtd/partitions.h>
23 static struct mtd_info *mymtd;
25 struct map_info physmap_map = {
26 .name = "phys_mapped_flash",
27 .phys = CONFIG_MTD_PHYSMAP_START,
28 .size = CONFIG_MTD_PHYSMAP_LEN,
29 .bankwidth = CONFIG_MTD_PHYSMAP_BANKWIDTH,
32 #ifdef CONFIG_MTD_PARTITIONS
33 static struct mtd_partition *mtd_parts;
34 static int mtd_parts_nb;
36 static int num_physmap_partitions;
37 static struct mtd_partition *physmap_partitions;
39 static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
41 void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
43 physmap_partitions=parts;
44 num_physmap_partitions=num_parts;
46 #endif /* CONFIG_MTD_PARTITIONS */
48 static int __init init_physmap(void)
50 static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
51 const char **type;
53 printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys);
54 physmap_map.virt = ioremap(physmap_map.phys, physmap_map.size);
56 if (!physmap_map.virt) {
57 printk("Failed to ioremap\n");
58 return -EIO;
61 simple_map_init(&physmap_map);
63 mymtd = NULL;
64 type = rom_probe_types;
65 for(; !mymtd && *type; type++) {
66 mymtd = do_map_probe(*type, &physmap_map);
68 if (mymtd) {
69 mymtd->owner = THIS_MODULE;
71 #ifdef CONFIG_MTD_PARTITIONS
72 mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes,
73 &mtd_parts, 0);
75 if (mtd_parts_nb > 0)
77 add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
78 return 0;
81 if (num_physmap_partitions != 0)
83 printk(KERN_NOTICE
84 "Using physmap partition definition\n");
85 add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions);
86 return 0;
89 #endif
90 add_mtd_device(mymtd);
92 return 0;
95 iounmap(physmap_map.virt);
96 return -ENXIO;
99 static void __exit cleanup_physmap(void)
101 #ifdef CONFIG_MTD_PARTITIONS
102 if (mtd_parts_nb) {
103 del_mtd_partitions(mymtd);
104 kfree(mtd_parts);
105 } else if (num_physmap_partitions) {
106 del_mtd_partitions(mymtd);
107 } else {
108 del_mtd_device(mymtd);
110 #else
111 del_mtd_device(mymtd);
112 #endif
113 map_destroy(mymtd);
115 iounmap(physmap_map.virt);
116 physmap_map.virt = NULL;
119 module_init(init_physmap);
120 module_exit(cleanup_physmap);
123 MODULE_LICENSE("GPL");
124 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
125 MODULE_DESCRIPTION("Generic configurable MTD map driver");