blob: 299bf88a6f4112220c0fda6766878646c5ad0143 [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>
Geert Uytterhoeven363737d2012-05-31 22:39:21 +020022#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/****************************************************************************/
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026struct map_info uclinux_ram_map = {
27 .name = "RAM",
Geert Uytterhoeven363737d2012-05-31 22:39:21 +020028 .phys = (unsigned long)__bss_stop,
Mike Frysingerfa254ec2009-05-26 19:33:16 -040029 .size = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070030};
31
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040032static struct mtd_info *uclinux_ram_mtdinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34/****************************************************************************/
35
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040036static struct mtd_partition uclinux_romfs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 { .name = "ROMfs" }
38};
39
Tobias Klauser87d10f32006-03-31 02:29:45 -080040#define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/****************************************************************************/
43
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040044static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
Jared Hulberta98889f2008-04-29 23:26:49 -070045 size_t *retlen, void **virt, resource_size_t *phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
47 struct map_info *map = mtd->priv;
Jared Hulberta98889f2008-04-29 23:26:49 -070048 *virt = map->virt + from;
49 if (phys)
50 *phys = map->phys + from;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 *retlen = len;
52 return(0);
53}
54
55/****************************************************************************/
56
Dmitri Vorobiev769455e2008-11-25 02:55:09 +020057static int __init uclinux_mtd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 struct mtd_info *mtd;
60 struct map_info *mapp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 mapp = &uclinux_ram_map;
Mike Frysingerfa254ec2009-05-26 19:33:16 -040063 if (!mapp->size)
64 mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 mapp->bankwidth = 4;
66
67 printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
Greg Ungererf6515db2005-09-12 11:18:10 +100068 (int) mapp->phys, (int) mapp->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Greg Ungerer08a3c4b2012-07-19 15:42:45 +100070 /*
71 * The filesystem is guaranteed to be in direct mapped memory. It is
72 * directly following the kernels own bss region. Following the same
73 * mechanism used by architectures setting up traditional initrds we
74 * use phys_to_virt to get the virtual address of its start.
75 */
76 mapp->virt = phys_to_virt(mapp->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 if (mapp->virt == 0) {
Greg Ungerer08a3c4b2012-07-19 15:42:45 +100079 printk("uclinux[mtd]: no virtual mapping?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 return(-EIO);
81 }
82
83 simple_map_init(mapp);
84
85 mtd = do_map_probe("map_ram", mapp);
86 if (!mtd) {
87 printk("uclinux[mtd]: failed to find a mapping?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 return(-ENXIO);
89 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 mtd->owner = THIS_MODULE;
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +020092 mtd->_point = uclinux_point;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 mtd->priv = mapp;
94
95 uclinux_ram_mtdinfo = mtd;
Jamie Iles5e7e9682011-05-23 10:23:12 +010096 mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
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) {
Jamie Iles5e7e9682011-05-23 10:23:12 +0100106 mtd_device_unregister(uclinux_ram_mtdinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 map_destroy(uclinux_ram_mtdinfo);
108 uclinux_ram_mtdinfo = NULL;
109 }
Greg Ungerer08a3c4b2012-07-19 15:42:45 +1000110 if (uclinux_ram_map.virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 uclinux_ram_map.virt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
114/****************************************************************************/
115
116module_init(uclinux_mtd_init);
117module_exit(uclinux_mtd_cleanup);
118
119MODULE_LICENSE("GPL");
120MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
121MODULE_DESCRIPTION("Generic RAM based MTD for uClinux");
122
123/****************************************************************************/