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