1 /****************************************************************************/
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 $
11 /****************************************************************************/
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/init.h>
16 #include <linux/kernel.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>
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
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"
39 #error "Unknown uClinux map type"
42 /****************************************************************************/
44 struct map_info uclinux_map
= {
48 struct mtd_info
*uclinux_mtdinfo
;
50 /****************************************************************************/
52 struct mtd_partition uclinux_fs
[] = {
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
));
69 /****************************************************************************/
71 int __init
uclinux_mtd_init(void)
74 struct map_info
*mapp
;
75 unsigned long addr
= (unsigned long) CONFIG_MTD_UCLINUX_ADDRESS
;
79 mapp
->size
= PAGE_ALIGN(ntohl(*((unsigned long *)(addr
+ 8))));
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");
92 simple_map_init(mapp
);
94 mtd
= do_map_probe(MAP_TYPE
, mapp
);
96 printk("uclinux[mtd]: failed to find a mapping?\n");
101 mtd
->owner
= THIS_MODULE
;
102 mtd
->point
= uclinux_point
;
105 uclinux_mtdinfo
= mtd
;
106 add_mtd_partitions(mtd
, uclinux_fs
, NUM_PARTITIONS
);
108 printk("uclinux[mtd]: set %s to be root filesystem\n",
110 ROOT_DEV
= MKDEV(MTD_BLOCK_MAJOR
, 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 /****************************************************************************/