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) 71da177e4SLinus Torvalds */ 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds /****************************************************************************/ 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds #include <linux/module.h> 121da177e4SLinus Torvalds #include <linux/types.h> 131da177e4SLinus Torvalds #include <linux/init.h> 141da177e4SLinus Torvalds #include <linux/kernel.h> 151da177e4SLinus Torvalds #include <linux/fs.h> 1627ac792cSAndrea Righi #include <linux/mm.h> 171da177e4SLinus Torvalds #include <linux/major.h> 181da177e4SLinus Torvalds #include <linux/mtd/mtd.h> 191da177e4SLinus Torvalds #include <linux/mtd/map.h> 201da177e4SLinus Torvalds #include <linux/mtd/partitions.h> 211da177e4SLinus Torvalds #include <asm/io.h> 22363737d6SGeert Uytterhoeven #include <asm/sections.h> 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds /****************************************************************************/ 251da177e4SLinus Torvalds 2681f53ff8SUwe Kleine-König #ifdef CONFIG_MTD_ROM 2781f53ff8SUwe Kleine-König #define MAP_NAME "rom" 2881f53ff8SUwe Kleine-König #else 2981f53ff8SUwe Kleine-König #define MAP_NAME "ram" 3081f53ff8SUwe Kleine-König #endif 3181f53ff8SUwe Kleine-König 32*44fe63fcSUwe Kleine-König /* 33*44fe63fcSUwe Kleine-König * Blackfin uses uclinux_ram_map during startup, so it must not be static. 34*44fe63fcSUwe Kleine-König * Provide a dummy declaration to make sparse happy. 35*44fe63fcSUwe Kleine-König */ 36*44fe63fcSUwe Kleine-König extern struct map_info uclinux_ram_map; 37*44fe63fcSUwe Kleine-König 381da177e4SLinus Torvalds struct map_info uclinux_ram_map = { 3981f53ff8SUwe Kleine-König .name = MAP_NAME, 40fa254ecbSMike Frysinger .size = 0, 411da177e4SLinus Torvalds }; 421da177e4SLinus Torvalds 4381f53ff8SUwe Kleine-König static unsigned long physaddr = -1; 4481f53ff8SUwe Kleine-König module_param(physaddr, ulong, S_IRUGO); 4581f53ff8SUwe Kleine-König 469f31f4b9SMike Frysinger static struct mtd_info *uclinux_ram_mtdinfo; 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds /****************************************************************************/ 491da177e4SLinus Torvalds 509f31f4b9SMike Frysinger static struct mtd_partition uclinux_romfs[] = { 511da177e4SLinus Torvalds { .name = "ROMfs" } 521da177e4SLinus Torvalds }; 531da177e4SLinus Torvalds 5487d10f3cSTobias Klauser #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs) 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /****************************************************************************/ 571da177e4SLinus Torvalds 589f31f4b9SMike Frysinger static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len, 59a98889f3SJared Hulbert size_t *retlen, void **virt, resource_size_t *phys) 601da177e4SLinus Torvalds { 611da177e4SLinus Torvalds struct map_info *map = mtd->priv; 62a98889f3SJared Hulbert *virt = map->virt + from; 63a98889f3SJared Hulbert if (phys) 64a98889f3SJared Hulbert *phys = map->phys + from; 651da177e4SLinus Torvalds *retlen = len; 661da177e4SLinus Torvalds return(0); 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /****************************************************************************/ 701da177e4SLinus Torvalds 71769455e2SDmitri Vorobiev static int __init uclinux_mtd_init(void) 721da177e4SLinus Torvalds { 731da177e4SLinus Torvalds struct mtd_info *mtd; 741da177e4SLinus Torvalds struct map_info *mapp; 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds mapp = &uclinux_ram_map; 7781f53ff8SUwe Kleine-König 7881f53ff8SUwe Kleine-König if (physaddr == -1) 7981f53ff8SUwe Kleine-König mapp->phys = (resource_size_t)__bss_stop; 8081f53ff8SUwe Kleine-König else 8181f53ff8SUwe Kleine-König mapp->phys = physaddr; 8281f53ff8SUwe Kleine-König 83fa254ecbSMike Frysinger if (!mapp->size) 84fa254ecbSMike Frysinger mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8)))); 851da177e4SLinus Torvalds mapp->bankwidth = 4; 861da177e4SLinus Torvalds 8781f53ff8SUwe Kleine-König printk("uclinux[mtd]: probe address=0x%x size=0x%x\n", 88f6515db4SGreg Ungerer (int) mapp->phys, (int) mapp->size); 891da177e4SLinus Torvalds 9008a3c4bcSGreg Ungerer /* 9108a3c4bcSGreg Ungerer * The filesystem is guaranteed to be in direct mapped memory. It is 9208a3c4bcSGreg Ungerer * directly following the kernels own bss region. Following the same 9308a3c4bcSGreg Ungerer * mechanism used by architectures setting up traditional initrds we 9408a3c4bcSGreg Ungerer * use phys_to_virt to get the virtual address of its start. 9508a3c4bcSGreg Ungerer */ 9608a3c4bcSGreg Ungerer mapp->virt = phys_to_virt(mapp->phys); 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds if (mapp->virt == 0) { 9908a3c4bcSGreg Ungerer printk("uclinux[mtd]: no virtual mapping?\n"); 1001da177e4SLinus Torvalds return(-EIO); 1011da177e4SLinus Torvalds } 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds simple_map_init(mapp); 1041da177e4SLinus Torvalds 10581f53ff8SUwe Kleine-König mtd = do_map_probe("map_" MAP_NAME, mapp); 1061da177e4SLinus Torvalds if (!mtd) { 1071da177e4SLinus Torvalds printk("uclinux[mtd]: failed to find a mapping?\n"); 1081da177e4SLinus Torvalds return(-ENXIO); 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds mtd->owner = THIS_MODULE; 1123c3c10bbSArtem Bityutskiy mtd->_point = uclinux_point; 1131da177e4SLinus Torvalds mtd->priv = mapp; 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds uclinux_ram_mtdinfo = mtd; 1165e7e9686SJamie Iles mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS); 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds return(0); 1191da177e4SLinus Torvalds } 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds /****************************************************************************/ 1221da177e4SLinus Torvalds 123769455e2SDmitri Vorobiev static void __exit uclinux_mtd_cleanup(void) 1241da177e4SLinus Torvalds { 1251da177e4SLinus Torvalds if (uclinux_ram_mtdinfo) { 1265e7e9686SJamie Iles mtd_device_unregister(uclinux_ram_mtdinfo); 1271da177e4SLinus Torvalds map_destroy(uclinux_ram_mtdinfo); 1281da177e4SLinus Torvalds uclinux_ram_mtdinfo = NULL; 1291da177e4SLinus Torvalds } 13008a3c4bcSGreg Ungerer if (uclinux_ram_map.virt) 1311da177e4SLinus Torvalds uclinux_ram_map.virt = 0; 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds /****************************************************************************/ 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds module_init(uclinux_mtd_init); 1371da177e4SLinus Torvalds module_exit(uclinux_mtd_cleanup); 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 1401da177e4SLinus Torvalds MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>"); 14181f53ff8SUwe Kleine-König MODULE_DESCRIPTION("Generic MTD for uClinux"); 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds /****************************************************************************/ 144