This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / mtd / maps / physmap.c
1 /*
2  * $Id: physmap.c,v 1.33 2004/07/12 14:37:24 dwmw2 Exp $
3  *
4  * Normal mappings of chips in physical memory
5  *
6  * Copyright (C) 2003 MontaVista Software Inc.
7  * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
8  *
9  * 031022 - [jsun] add run-time configure and partition setup
10  */
11
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>
22
23 static struct mtd_info *mymtd;
24
25 struct map_info physmap_map = {.name = "phys_mapped_flash"};
26
27 #ifdef CONFIG_MTD_PARTITIONS
28 static struct mtd_partition *mtd_parts;
29 static int                   mtd_parts_nb;
30
31 static int num_physmap_partitions;
32 static struct mtd_partition *physmap_partitions;
33
34 static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
35
36 void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
37 {
38         physmap_partitions=parts;
39         num_physmap_partitions=num_parts;
40 }
41 #endif /* CONFIG_MTD_PARTITIONS */
42
43 static int __init init_physmap(void)
44 {
45         static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
46         const char **type;
47
48         printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys);
49         physmap_map.virt = (unsigned long)ioremap(physmap_map.phys, physmap_map.size);
50
51         if (!physmap_map.virt) {
52                 printk("Failed to ioremap\n");
53                 return -EIO;
54         }
55
56         simple_map_init(&physmap_map);
57
58         mymtd = NULL;
59         type = rom_probe_types;
60         for(; !mymtd && *type; type++) {
61                 mymtd = do_map_probe(*type, &physmap_map);
62         }
63         if (mymtd) {
64                 mymtd->owner = THIS_MODULE;
65
66 #ifdef CONFIG_MTD_PARTITIONS
67                 mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes, 
68                                                     &mtd_parts, 0);
69
70                 if (mtd_parts_nb > 0)
71                 {
72                         add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
73                         return 0;
74                 }
75
76                 if (num_physmap_partitions != 0) 
77                 {
78                         printk(KERN_NOTICE 
79                                "Using physmap partition definition\n");
80                         add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions);
81                         return 0;
82                 }
83
84 #endif
85                 add_mtd_device(mymtd);
86
87                 return 0;
88         }
89
90         iounmap((void *)physmap_map.virt);
91         return -ENXIO;
92 }
93
94 static void __exit cleanup_physmap(void)
95 {
96 #ifdef CONFIG_MTD_PARTITIONS
97         if (mtd_parts_nb) {
98                 del_mtd_partitions(mymtd);
99                 kfree(mtd_parts);
100         } else if (num_physmap_partitions) {
101                 del_mtd_partitions(mymtd);
102         } else {
103                 del_mtd_device(mymtd);
104         }
105 #else
106         del_mtd_device(mymtd);
107 #endif
108         map_destroy(mymtd);
109
110         iounmap((void *)physmap_map.virt);
111         physmap_map.virt = 0;
112 }
113
114 module_init(init_physmap);
115 module_exit(cleanup_physmap);
116
117
118 MODULE_LICENSE("GPL");
119 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
120 MODULE_DESCRIPTION("Generic configurable MTD map driver");