patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / mtd / maps / uclinux.c
1 /****************************************************************************/
2
3 /*
4  *      uclinux.c -- generic memory mapped MTD driver for uclinux
5  *
6  *      (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
7  *
8  *      $Id: uclinux.c,v 1.5 2003/05/20 20:59:32 dwmw2 Exp $
9  */
10
11 /****************************************************************************/
12
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/fs.h>
19 #include <linux/major.h>
20 #include <linux/root_dev.h>
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/map.h>
23 #include <linux/mtd/partitions.h>
24 #include <asm/io.h>
25
26 /****************************************************************************/
27
28
29 /****************************************************************************/
30
31 struct map_info uclinux_ram_map = {
32         .name = "RAM",
33 };
34
35 struct mtd_info *uclinux_ram_mtdinfo;
36
37 /****************************************************************************/
38
39 struct mtd_partition uclinux_romfs[] = {
40         { .name = "ROMfs" }
41 };
42
43 #define NUM_PARTITIONS  (sizeof(uclinux_romfs) / sizeof(uclinux_romfs[0]))
44
45 /****************************************************************************/
46
47 int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
48         size_t *retlen, u_char **mtdbuf)
49 {
50         struct map_info *map = (struct map_info *) mtd->priv;
51         *mtdbuf = (u_char *) (map->virt + ((int) from));
52         *retlen = len;
53         return(0);
54 }
55
56 /****************************************************************************/
57
58 int __init uclinux_mtd_init(void)
59 {
60         struct mtd_info *mtd;
61         struct map_info *mapp;
62         extern char _ebss;
63
64         mapp = &uclinux_ram_map;
65         mapp->phys = (unsigned long) &_ebss;
66         mapp->size = PAGE_ALIGN(*((unsigned long *)((&_ebss) + 8)));
67         mapp->buswidth = 4;
68
69         printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
70                 (int) mapp->map_priv_2, (int) mapp->size);
71
72         mapp->virt = (unsigned long)
73                 ioremap_nocache(mapp->phys, mapp->size);
74
75         if (mapp->virt == 0) {
76                 printk("uclinux[mtd]: ioremap_nocache() failed\n");
77                 return(-EIO);
78         }
79
80         simple_map_init(mapp);
81
82         mtd = do_map_probe("map_ram", mapp);
83         if (!mtd) {
84                 printk("uclinux[mtd]: failed to find a mapping?\n");
85                 iounmap((void *) mapp->virt);
86                 return(-ENXIO);
87         }
88                 
89         mtd->owner = THIS_MODULE;
90         mtd->point = uclinux_point;
91         mtd->priv = mapp;
92
93         uclinux_ram_mtdinfo = mtd;
94         add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS);
95
96         printk("uclinux[mtd]: set %s to be root filesystem\n",
97                 uclinux_romfs[0].name);
98         ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, 0);
99         put_mtd_device(mtd);
100
101         return(0);
102 }
103
104 /****************************************************************************/
105
106 void __exit uclinux_mtd_cleanup(void)
107 {
108         if (uclinux_ram_mtdinfo) {
109                 del_mtd_partitions(uclinux_ram_mtdinfo);
110                 map_destroy(uclinux_ram_mtdinfo);
111                 uclinux_ram_mtdinfo = NULL;
112         }
113         if (uclinux_ram_map.map_priv_1) {
114                 iounmap((void *) uclinux_ram_map.virt);
115                 uclinux_ram_map.virt = 0;
116         }
117 }
118
119 /****************************************************************************/
120
121 module_init(uclinux_mtd_init);
122 module_exit(uclinux_mtd_cleanup);
123
124 MODULE_LICENSE("GPL");
125 MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
126 MODULE_DESCRIPTION("Generic RAM based MTD for uClinux");
127
128 /****************************************************************************/