ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / mtd / maps / physmap.c
1 /*
2  * $Id: physmap.c,v 1.29 2003/05/29 09:24:10 dwmw2 Exp $
3  *
4  * Normal mappings of chips in physical memory
5  */
6
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <asm/io.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/map.h>
15 #include <linux/config.h>
16 #include <linux/mtd/partitions.h>
17
18 #define WINDOW_ADDR CONFIG_MTD_PHYSMAP_START
19 #define WINDOW_SIZE CONFIG_MTD_PHYSMAP_LEN
20 #define BUSWIDTH CONFIG_MTD_PHYSMAP_BUSWIDTH
21
22 static struct mtd_info *mymtd;
23
24
25 struct map_info physmap_map = {
26         .name = "Physically mapped flash",
27         .size = WINDOW_SIZE,
28         .buswidth = BUSWIDTH,
29         .phys = WINDOW_ADDR,
30 };
31
32 #ifdef CONFIG_MTD_PARTITIONS
33 static struct mtd_partition *mtd_parts;
34 static int                   mtd_parts_nb;
35
36 static struct mtd_partition physmap_partitions[] = {
37 #if 0
38 /* Put your own partition definitions here */
39         {
40                 .name =         "bootROM",
41                 .size =         0x80000,
42                 .offset =       0,
43                 .mask_flags =   MTD_WRITEABLE,  /* force read-only */
44         }, {
45                 .name =         "zImage",
46                 .size =         0x100000,
47                 .offset =       MTDPART_OFS_APPEND,
48                 .mask_flags =   MTD_WRITEABLE,  /* force read-only */
49         }, {
50                 .name =         "ramdisk.gz",
51                 .size =         0x300000,
52                 .offset =       MTDPART_OFS_APPEND,
53                 .mask_flags =   MTD_WRITEABLE,  /* force read-only */
54         }, {
55                 .name =         "User FS",
56                 .size =         MTDPART_SIZ_FULL,
57                 .offset =       MTDPART_OFS_APPEND,
58         }
59 #endif
60 };
61
62 #define NUM_PARTITIONS  (sizeof(physmap_partitions)/sizeof(struct mtd_partition))
63 const char *part_probes[] = {"cmdlinepart", "RedBoot", NULL};
64
65 #endif /* CONFIG_MTD_PARTITIONS */
66
67 int __init init_physmap(void)
68 {
69         static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", 0 };
70         const char **type;
71
72         printk(KERN_NOTICE "physmap flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
73         physmap_map.virt = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
74
75         if (!physmap_map.virt) {
76                 printk("Failed to ioremap\n");
77                 return -EIO;
78         }
79
80         simple_map_init(&physmap_map);
81
82         mymtd = 0;
83         type = rom_probe_types;
84         for(; !mymtd && *type; type++) {
85                 mymtd = do_map_probe(*type, &physmap_map);
86         }
87         if (mymtd) {
88                 mymtd->owner = THIS_MODULE;
89
90 #ifdef CONFIG_MTD_PARTITIONS
91                 mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes, 
92                                                     &mtd_parts, 0);
93
94                 if (mtd_parts_nb > 0)
95                 {
96                         add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
97                         return 0;
98                 }
99
100                 if (NUM_PARTITIONS != 0) 
101                 {
102                         printk(KERN_NOTICE 
103                                "Using physmap partition definition\n");
104                         add_mtd_partitions (mymtd, physmap_partitions, NUM_PARTITIONS);
105                         return 0;
106                 }
107
108 #endif
109                 add_mtd_device(mymtd);
110
111                 return 0;
112         }
113
114         iounmap((void *)physmap_map.virt);
115         return -ENXIO;
116 }
117
118 static void __exit cleanup_physmap(void)
119 {
120 #ifdef CONFIG_MTD_PARTITIONS
121         if (mtd_parts_nb) {
122                 del_mtd_partitions(mymtd);
123                 kfree(mtd_parts);
124         } else if (NUM_PARTITIONS) {
125                 del_mtd_partitions(mymtd);
126         } else {
127                 del_mtd_device(mymtd);
128         }
129 #else
130         del_mtd_device(mymtd);
131 #endif
132         map_destroy(mymtd);
133
134         iounmap((void *)physmap_map.virt);
135         physmap_map.virt = 0;
136 }
137
138 module_init(init_physmap);
139 module_exit(cleanup_physmap);
140
141
142 MODULE_LICENSE("GPL");
143 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
144 MODULE_DESCRIPTION("Generic configurable MTD map driver");