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