blob: 35009294b435f33a62c0dbb4496ffe5c8b189174 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/****************************************************************************/
2
3/*
4 * uclinux.c -- generic memory mapped MTD driver for uclinux
5 *
6 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9/****************************************************************************/
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/init.h>
14#include <linux/kernel.h>
15#include <linux/fs.h>
Andrea Righi27ac7922008-07-23 21:28:13 -070016#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/major.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#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
Mike Frysingerfa254ec2009-05-26 19:33:16 -040025extern char _ebss;
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027struct map_info uclinux_ram_map = {
28 .name = "RAM",
Mike Frysingerfa254ec2009-05-26 19:33:16 -040029 .phys = (unsigned long)&_ebss,
30 .size = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070031};
32
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040033static struct mtd_info *uclinux_ram_mtdinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/****************************************************************************/
36
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040037static struct mtd_partition uclinux_romfs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 { .name = "ROMfs" }
39};
40
Tobias Klauser87d10f32006-03-31 02:29:45 -080041#define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/****************************************************************************/
44
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040045static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
Jared Hulberta98889f2008-04-29 23:26:49 -070046 size_t *retlen, void **virt, resource_size_t *phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
48 struct map_info *map = mtd->priv;
Jared Hulberta98889f2008-04-29 23:26:49 -070049 *virt = map->virt + from;
50 if (phys)
51 *phys = map->phys + from;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 *retlen = len;
53 return(0);
54}
55
56/****************************************************************************/
57
Dmitri Vorobiev769455e2008-11-25 02:55:09 +020058static int __init uclinux_mtd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 struct mtd_info *mtd;
61 struct map_info *mapp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63 mapp = &uclinux_ram_map;
Mike Frysingerfa254ec2009-05-26 19:33:16 -040064 if (!mapp->size)
65 mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 mapp->bankwidth = 4;
67
68 printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
Greg Ungererf6515db2005-09-12 11:18:10 +100069 (int) mapp->phys, (int) mapp->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
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 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 mtd->owner = THIS_MODULE;
88 mtd->point = uclinux_point;
89 mtd->priv = mapp;
90
91 uclinux_ram_mtdinfo = mtd;
Timofei Bondarenko3ff230a2009-05-20 19:59:02 -040092#ifdef CONFIG_MTD_PARTITIONS
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS);
Timofei Bondarenko3ff230a2009-05-20 19:59:02 -040094#else
95 add_mtd_device(mtd);
96#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return(0);
99}
100
101/****************************************************************************/
102
Dmitri Vorobiev769455e2008-11-25 02:55:09 +0200103static void __exit uclinux_mtd_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 if (uclinux_ram_mtdinfo) {
Timofei Bondarenko3ff230a2009-05-20 19:59:02 -0400106#ifdef CONFIG_MTD_PARTITIONS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 del_mtd_partitions(uclinux_ram_mtdinfo);
Timofei Bondarenko3ff230a2009-05-20 19:59:02 -0400108#else
109 del_mtd_device(uclinux_ram_mtdinfo);
110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 map_destroy(uclinux_ram_mtdinfo);
112 uclinux_ram_mtdinfo = NULL;
113 }
Greg Ungererf6515db2005-09-12 11:18:10 +1000114 if (uclinux_ram_map.virt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 iounmap((void *) uclinux_ram_map.virt);
116 uclinux_ram_map.virt = 0;
117 }
118}
119
120/****************************************************************************/
121
122module_init(uclinux_mtd_init);
123module_exit(uclinux_mtd_cleanup);
124
125MODULE_LICENSE("GPL");
126MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
127MODULE_DESCRIPTION("Generic RAM based MTD for uClinux");
128
129/****************************************************************************/