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.2 2002/08/07 00:43:45 gerg Exp $
11 /****************************************************************************/
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>
19 #include <linux/major.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/map.h>
22 #include <linux/mtd/partitions.h>
25 /****************************************************************************/
27 __u8 uclinux_read8(struct map_info *map, unsigned long ofs)
29 return(*((__u8 *) (map->map_priv_1 + ofs)));
32 __u16 uclinux_read16(struct map_info *map, unsigned long ofs)
34 return(*((__u16 *) (map->map_priv_1 + ofs)));
37 __u32 uclinux_read32(struct map_info *map, unsigned long ofs)
39 return(*((__u32 *) (map->map_priv_1 + ofs)));
42 void uclinux_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
44 memcpy(to, (void *)(map->map_priv_1 + from), len);
47 void uclinux_write8(struct map_info *map, __u8 d, unsigned long adr)
49 *((__u8 *) (map->map_priv_1 + adr)) = d;
52 void uclinux_write16(struct map_info *map, __u16 d, unsigned long adr)
54 *((__u16 *) (map->map_priv_1 + adr)) = d;
57 void uclinux_write32(struct map_info *map, __u32 d, unsigned long adr)
59 *((__u32 *) (map->map_priv_1 + adr)) = d;
62 void uclinux_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
64 memcpy((void *) (map->map_priv_1 + to), from, len);
67 /****************************************************************************/
69 struct map_info uclinux_ram_map = {
72 read16: uclinux_read16,
73 read32: uclinux_read32,
74 copy_from: uclinux_copy_from,
75 write8: uclinux_write8,
76 write16: uclinux_write16,
77 write32: uclinux_write32,
78 copy_to: uclinux_copy_to,
81 struct mtd_info *uclinux_ram_mtdinfo;
83 /****************************************************************************/
85 struct mtd_partition uclinux_romfs[] = {
86 { name: "ROMfs", offset: 0 }
89 #define NUM_PARTITIONS (sizeof(uclinux_romfs) / sizeof(uclinux_romfs[0]))
91 /****************************************************************************/
93 int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
94 size_t *retlen, u_char **mtdbuf)
96 struct map_info *map = (struct map_info *) mtd->priv;
97 *mtdbuf = (u_char *) (map->map_priv_1 + ((int) from));
102 /****************************************************************************/
104 int __init uclinux_mtd_init(void)
106 struct mtd_info *mtd;
107 struct map_info *mapp;
110 mapp = &uclinux_ram_map;
111 mapp->map_priv_2 = (unsigned long) &_ebss;
112 mapp->size = PAGE_ALIGN(*((unsigned long *)((&_ebss) + 8)));
115 printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
116 (int) mapp->map_priv_2, (int) mapp->size);
118 mapp->map_priv_1 = (unsigned long)
119 ioremap_nocache(mapp->map_priv_2, mapp->size);
121 if (mapp->map_priv_1 == 0) {
122 printk("uclinux[mtd]: ioremap_nocache() failed\n");
126 mtd = do_map_probe("map_ram", mapp);
128 printk("uclinux[mtd]: failed to find a mapping?\n");
129 iounmap((void *) mapp->map_priv_1);
133 mtd->module = THIS_MODULE;
134 mtd->point = uclinux_point;
137 uclinux_ram_mtdinfo = mtd;
138 add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS);
140 printk("uclinux[mtd]: set %s to be root filesystem\n",
141 uclinux_romfs[0].name);
142 ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, 0);
148 /****************************************************************************/
150 void __exit uclinux_mtd_cleanup(void)
152 if (uclinux_ram_mtdinfo) {
153 del_mtd_partitions(uclinux_ram_mtdinfo);
154 map_destroy(uclinux_ram_mtdinfo);
155 uclinux_ram_mtdinfo = NULL;
157 if (uclinux_ram_map.map_priv_1) {
158 iounmap((void *) uclinux_ram_map.map_priv_1);
159 uclinux_ram_map.map_priv_1 = 0;
163 /****************************************************************************/
165 module_init(uclinux_mtd_init);
166 module_exit(uclinux_mtd_cleanup);
168 MODULE_LICENSE("GPL");
169 MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
170 MODULE_DESCRIPTION("Generic RAM based MTD for uClinux");
172 /****************************************************************************/