xref: /linux/drivers/mtd/maps/uclinux.c (revision c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2)
11da177e4SLinus Torvalds /****************************************************************************/
21da177e4SLinus Torvalds 
31da177e4SLinus Torvalds /*
41da177e4SLinus Torvalds  *	uclinux.c -- generic memory mapped MTD driver for uclinux
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *	(C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
7025ce02dSPaul Gortmaker  *
8025ce02dSPaul Gortmaker  *      License: GPL
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds /****************************************************************************/
121da177e4SLinus Torvalds 
13025ce02dSPaul Gortmaker #include <linux/moduleparam.h>
141da177e4SLinus Torvalds #include <linux/types.h>
151da177e4SLinus Torvalds #include <linux/init.h>
161da177e4SLinus Torvalds #include <linux/kernel.h>
171da177e4SLinus Torvalds #include <linux/fs.h>
1827ac792cSAndrea Righi #include <linux/mm.h>
191da177e4SLinus Torvalds #include <linux/major.h>
201da177e4SLinus Torvalds #include <linux/mtd/mtd.h>
211da177e4SLinus Torvalds #include <linux/mtd/map.h>
221da177e4SLinus Torvalds #include <linux/mtd/partitions.h>
231da177e4SLinus Torvalds #include <asm/io.h>
24363737d6SGeert Uytterhoeven #include <asm/sections.h>
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds /****************************************************************************/
271da177e4SLinus Torvalds 
2881f53ff8SUwe Kleine-König #ifdef CONFIG_MTD_ROM
2981f53ff8SUwe Kleine-König #define MAP_NAME "rom"
3081f53ff8SUwe Kleine-König #else
3181f53ff8SUwe Kleine-König #define MAP_NAME "ram"
3281f53ff8SUwe Kleine-König #endif
3381f53ff8SUwe Kleine-König 
34*251f26c9SThomas Huth static struct map_info uclinux_ram_map = {
3581f53ff8SUwe Kleine-König 	.name = MAP_NAME,
36fa254ecbSMike Frysinger 	.size = 0,
371da177e4SLinus Torvalds };
381da177e4SLinus Torvalds 
3981f53ff8SUwe Kleine-König static unsigned long physaddr = -1;
4081f53ff8SUwe Kleine-König module_param(physaddr, ulong, S_IRUGO);
4181f53ff8SUwe Kleine-König 
429f31f4b9SMike Frysinger static struct mtd_info *uclinux_ram_mtdinfo;
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds /****************************************************************************/
451da177e4SLinus Torvalds 
46d4906688SArvind Yadav static const struct mtd_partition uclinux_romfs[] = {
471da177e4SLinus Torvalds 	{ .name = "ROMfs" }
481da177e4SLinus Torvalds };
491da177e4SLinus Torvalds 
5087d10f3cSTobias Klauser #define	NUM_PARTITIONS	ARRAY_SIZE(uclinux_romfs)
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds /****************************************************************************/
531da177e4SLinus Torvalds 
uclinux_point(struct mtd_info * mtd,loff_t from,size_t len,size_t * retlen,void ** virt,resource_size_t * phys)549f31f4b9SMike Frysinger static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
55a98889f3SJared Hulbert 	size_t *retlen, void **virt, resource_size_t *phys)
561da177e4SLinus Torvalds {
571da177e4SLinus Torvalds 	struct map_info *map = mtd->priv;
58a98889f3SJared Hulbert 	*virt = map->virt + from;
59a98889f3SJared Hulbert 	if (phys)
60a98889f3SJared Hulbert 		*phys = map->phys + from;
611da177e4SLinus Torvalds 	*retlen = len;
621da177e4SLinus Torvalds 	return(0);
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds /****************************************************************************/
661da177e4SLinus Torvalds 
uclinux_mtd_init(void)67769455e2SDmitri Vorobiev static int __init uclinux_mtd_init(void)
681da177e4SLinus Torvalds {
691da177e4SLinus Torvalds 	struct mtd_info *mtd;
701da177e4SLinus Torvalds 	struct map_info *mapp;
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds 	mapp = &uclinux_ram_map;
7381f53ff8SUwe Kleine-König 
7481f53ff8SUwe Kleine-König 	if (physaddr == -1)
7581f53ff8SUwe Kleine-König 		mapp->phys = (resource_size_t)__bss_stop;
7681f53ff8SUwe Kleine-König 	else
7781f53ff8SUwe Kleine-König 		mapp->phys = physaddr;
7881f53ff8SUwe Kleine-König 
79fa254ecbSMike Frysinger 	if (!mapp->size)
80fa254ecbSMike Frysinger 		mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
811da177e4SLinus Torvalds 	mapp->bankwidth = 4;
821da177e4SLinus Torvalds 
8381f53ff8SUwe Kleine-König 	printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
84f6515db4SGreg Ungerer 	       	(int) mapp->phys, (int) mapp->size);
851da177e4SLinus Torvalds 
8608a3c4bcSGreg Ungerer 	/*
8708a3c4bcSGreg Ungerer 	 * The filesystem is guaranteed to be in direct mapped memory. It is
8808a3c4bcSGreg Ungerer 	 * directly following the kernels own bss region. Following the same
8908a3c4bcSGreg Ungerer 	 * mechanism used by architectures setting up traditional initrds we
9008a3c4bcSGreg Ungerer 	 * use phys_to_virt to get the virtual address of its start.
9108a3c4bcSGreg Ungerer 	 */
9208a3c4bcSGreg Ungerer 	mapp->virt = phys_to_virt(mapp->phys);
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds 	if (mapp->virt == 0) {
9508a3c4bcSGreg Ungerer 		printk("uclinux[mtd]: no virtual mapping?\n");
961da177e4SLinus Torvalds 		return(-EIO);
971da177e4SLinus Torvalds 	}
981da177e4SLinus Torvalds 
991da177e4SLinus Torvalds 	simple_map_init(mapp);
1001da177e4SLinus Torvalds 
10181f53ff8SUwe Kleine-König 	mtd = do_map_probe("map_" MAP_NAME, mapp);
1021da177e4SLinus Torvalds 	if (!mtd) {
1031da177e4SLinus Torvalds 		printk("uclinux[mtd]: failed to find a mapping?\n");
1041da177e4SLinus Torvalds 		return(-ENXIO);
1051da177e4SLinus Torvalds 	}
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	mtd->owner = THIS_MODULE;
1083c3c10bbSArtem Bityutskiy 	mtd->_point = uclinux_point;
1091da177e4SLinus Torvalds 	mtd->priv = mapp;
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds 	uclinux_ram_mtdinfo = mtd;
1125e7e9686SJamie Iles 	mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds 	return(0);
1151da177e4SLinus Torvalds }
116025ce02dSPaul Gortmaker device_initcall(uclinux_mtd_init);
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds /****************************************************************************/
119