MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / mtd / maps / uclinux.c
blob428d1de05204a8ca4cb9c0ffaf2cef994c6796fc
1 /****************************************************************************/
3 /*
4 * uclinux.c -- generic memory mapped MTD driver for uclinux
6 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
8 * $Id: uclinux.c,v 1.12 2005/11/07 11:14:29 gleixner Exp $
9 */
11 /****************************************************************************/
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/fs.h>
18 #include <linux/major.h>
19 #include <linux/root_dev.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/map.h>
22 #include <linux/mtd/partitions.h>
23 #include <asm/io.h>
25 /****************************************************************************/
27 #ifdef CONFIG_MTD_UCLINUX_EBSS
28 #define MAP_TYPE "map_ram"
29 #define MAP_NAME "RAM"
30 #define CONFIG_MTD_UCLINUX_ADDRESS &_ebss
31 extern char _ebss;
32 #elif CONFIG_MTD_UCLINUX_RAM
33 #define MAP_TYPE "map_ram"
34 #define MAP_NAME "RAM"
35 #elif CONFIG_MTD_UCLINUX_ROM
36 #define MAP_TYPE "map_rom"
37 #define MAP_NAME "ROM"
38 #else
39 #error "Unknown uClinux map type"
40 #endif
42 /****************************************************************************/
44 struct map_info uclinux_map = {
45 .name = MAP_NAME,
48 struct mtd_info *uclinux_mtdinfo;
50 /****************************************************************************/
52 struct mtd_partition uclinux_fs[] = {
53 { .name = "ROMfs" }
56 #define NUM_PARTITIONS ARRAY_SIZE(uclinux_fs)
58 /****************************************************************************/
60 int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
61 size_t *retlen, u_char **mtdbuf)
63 struct map_info *map = mtd->priv;
64 *mtdbuf = (u_char *) (map->virt + ((int) from));
65 *retlen = len;
66 return(0);
69 /****************************************************************************/
71 int __init uclinux_mtd_init(void)
73 struct mtd_info *mtd;
74 struct map_info *mapp;
75 unsigned long addr = (unsigned long) CONFIG_MTD_UCLINUX_ADDRESS;
77 mapp = &uclinux_map;
78 mapp->phys = addr;
79 mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(addr + 8))));
80 mapp->bankwidth = 4;
82 printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
83 (int) mapp->phys, (int) mapp->size);
85 mapp->virt = ioremap_nocache(mapp->phys, mapp->size);
87 if (mapp->virt == 0) {
88 printk("uclinux[mtd]: ioremap_nocache() failed\n");
89 return(-EIO);
92 simple_map_init(mapp);
94 mtd = do_map_probe(MAP_TYPE, mapp);
95 if (!mtd) {
96 printk("uclinux[mtd]: failed to find a mapping?\n");
97 iounmap(mapp->virt);
98 return(-ENXIO);
101 mtd->owner = THIS_MODULE;
102 mtd->point = uclinux_point;
103 mtd->priv = mapp;
105 uclinux_mtdinfo = mtd;
106 add_mtd_partitions(mtd, uclinux_fs, NUM_PARTITIONS);
108 printk("uclinux[mtd]: set %s to be root filesystem\n",
109 uclinux_fs[0].name);
110 ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, 0);
112 return(0);
115 /****************************************************************************/
117 void __exit uclinux_mtd_cleanup(void)
119 if (uclinux_mtdinfo) {
120 del_mtd_partitions(uclinux_mtdinfo);
121 map_destroy(uclinux_mtdinfo);
122 uclinux_mtdinfo = NULL;
124 if (uclinux_map.virt) {
125 iounmap((void *) uclinux_map.virt);
126 uclinux_map.virt = 0;
130 /****************************************************************************/
132 module_init(uclinux_mtd_init);
133 module_exit(uclinux_mtd_cleanup);
135 MODULE_LICENSE("GPL");
136 MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
137 MODULE_DESCRIPTION("Generic RAM based MTD for uClinux");
139 /****************************************************************************/