xref: /linux/drivers/mtd/maps/uclinux.c (revision 025ce02d92b67d6c702676c11f7f1f5e8f0a81fa)
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)
7*025ce02dSPaul Gortmaker  *
8*025ce02dSPaul Gortmaker  *      License: GPL
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds /****************************************************************************/
121da177e4SLinus Torvalds 
13*025ce02dSPaul 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 
3444fe63fcSUwe Kleine-König /*
3544fe63fcSUwe Kleine-König  * Blackfin uses uclinux_ram_map during startup, so it must not be static.
3644fe63fcSUwe Kleine-König  * Provide a dummy declaration to make sparse happy.
3744fe63fcSUwe Kleine-König  */
3844fe63fcSUwe Kleine-König extern struct map_info uclinux_ram_map;
3944fe63fcSUwe Kleine-König 
401da177e4SLinus Torvalds struct map_info uclinux_ram_map = {
4181f53ff8SUwe Kleine-König 	.name = MAP_NAME,
42fa254ecbSMike Frysinger 	.size = 0,
431da177e4SLinus Torvalds };
441da177e4SLinus Torvalds 
4581f53ff8SUwe Kleine-König static unsigned long physaddr = -1;
4681f53ff8SUwe Kleine-König module_param(physaddr, ulong, S_IRUGO);
4781f53ff8SUwe Kleine-König 
489f31f4b9SMike Frysinger static struct mtd_info *uclinux_ram_mtdinfo;
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds /****************************************************************************/
511da177e4SLinus Torvalds 
529f31f4b9SMike Frysinger static struct mtd_partition uclinux_romfs[] = {
531da177e4SLinus Torvalds 	{ .name = "ROMfs" }
541da177e4SLinus Torvalds };
551da177e4SLinus Torvalds 
5687d10f3cSTobias Klauser #define	NUM_PARTITIONS	ARRAY_SIZE(uclinux_romfs)
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds /****************************************************************************/
591da177e4SLinus Torvalds 
609f31f4b9SMike Frysinger static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
61a98889f3SJared Hulbert 	size_t *retlen, void **virt, resource_size_t *phys)
621da177e4SLinus Torvalds {
631da177e4SLinus Torvalds 	struct map_info *map = mtd->priv;
64a98889f3SJared Hulbert 	*virt = map->virt + from;
65a98889f3SJared Hulbert 	if (phys)
66a98889f3SJared Hulbert 		*phys = map->phys + from;
671da177e4SLinus Torvalds 	*retlen = len;
681da177e4SLinus Torvalds 	return(0);
691da177e4SLinus Torvalds }
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds /****************************************************************************/
721da177e4SLinus Torvalds 
73769455e2SDmitri Vorobiev static int __init uclinux_mtd_init(void)
741da177e4SLinus Torvalds {
751da177e4SLinus Torvalds 	struct mtd_info *mtd;
761da177e4SLinus Torvalds 	struct map_info *mapp;
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds 	mapp = &uclinux_ram_map;
7981f53ff8SUwe Kleine-König 
8081f53ff8SUwe Kleine-König 	if (physaddr == -1)
8181f53ff8SUwe Kleine-König 		mapp->phys = (resource_size_t)__bss_stop;
8281f53ff8SUwe Kleine-König 	else
8381f53ff8SUwe Kleine-König 		mapp->phys = physaddr;
8481f53ff8SUwe Kleine-König 
85fa254ecbSMike Frysinger 	if (!mapp->size)
86fa254ecbSMike Frysinger 		mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
871da177e4SLinus Torvalds 	mapp->bankwidth = 4;
881da177e4SLinus Torvalds 
8981f53ff8SUwe Kleine-König 	printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
90f6515db4SGreg Ungerer 	       	(int) mapp->phys, (int) mapp->size);
911da177e4SLinus Torvalds 
9208a3c4bcSGreg Ungerer 	/*
9308a3c4bcSGreg Ungerer 	 * The filesystem is guaranteed to be in direct mapped memory. It is
9408a3c4bcSGreg Ungerer 	 * directly following the kernels own bss region. Following the same
9508a3c4bcSGreg Ungerer 	 * mechanism used by architectures setting up traditional initrds we
9608a3c4bcSGreg Ungerer 	 * use phys_to_virt to get the virtual address of its start.
9708a3c4bcSGreg Ungerer 	 */
9808a3c4bcSGreg Ungerer 	mapp->virt = phys_to_virt(mapp->phys);
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds 	if (mapp->virt == 0) {
10108a3c4bcSGreg Ungerer 		printk("uclinux[mtd]: no virtual mapping?\n");
1021da177e4SLinus Torvalds 		return(-EIO);
1031da177e4SLinus Torvalds 	}
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	simple_map_init(mapp);
1061da177e4SLinus Torvalds 
10781f53ff8SUwe Kleine-König 	mtd = do_map_probe("map_" MAP_NAME, mapp);
1081da177e4SLinus Torvalds 	if (!mtd) {
1091da177e4SLinus Torvalds 		printk("uclinux[mtd]: failed to find a mapping?\n");
1101da177e4SLinus Torvalds 		return(-ENXIO);
1111da177e4SLinus Torvalds 	}
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds 	mtd->owner = THIS_MODULE;
1143c3c10bbSArtem Bityutskiy 	mtd->_point = uclinux_point;
1151da177e4SLinus Torvalds 	mtd->priv = mapp;
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds 	uclinux_ram_mtdinfo = mtd;
1185e7e9686SJamie Iles 	mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds 	return(0);
1211da177e4SLinus Torvalds }
122*025ce02dSPaul Gortmaker device_initcall(uclinux_mtd_init);
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds /****************************************************************************/
125