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> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds /****************************************************************************/ 241da177e4SLinus Torvalds 25fa254ecbSMike Frysinger extern char _ebss; 26fa254ecbSMike Frysinger 271da177e4SLinus Torvalds struct map_info uclinux_ram_map = { 281da177e4SLinus Torvalds .name = "RAM", 29fa254ecbSMike Frysinger .phys = (unsigned long)&_ebss, 30fa254ecbSMike Frysinger .size = 0, 311da177e4SLinus Torvalds }; 321da177e4SLinus Torvalds 339f31f4b9SMike Frysinger static struct mtd_info *uclinux_ram_mtdinfo; 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds /****************************************************************************/ 361da177e4SLinus Torvalds 379f31f4b9SMike Frysinger static struct mtd_partition uclinux_romfs[] = { 381da177e4SLinus Torvalds { .name = "ROMfs" } 391da177e4SLinus Torvalds }; 401da177e4SLinus Torvalds 4187d10f3cSTobias Klauser #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs) 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds /****************************************************************************/ 441da177e4SLinus Torvalds 459f31f4b9SMike Frysinger static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len, 46a98889f3SJared Hulbert size_t *retlen, void **virt, resource_size_t *phys) 471da177e4SLinus Torvalds { 481da177e4SLinus Torvalds struct map_info *map = mtd->priv; 49a98889f3SJared Hulbert *virt = map->virt + from; 50a98889f3SJared Hulbert if (phys) 51a98889f3SJared Hulbert *phys = map->phys + from; 521da177e4SLinus Torvalds *retlen = len; 531da177e4SLinus Torvalds return(0); 541da177e4SLinus Torvalds } 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /****************************************************************************/ 571da177e4SLinus Torvalds 58769455e2SDmitri Vorobiev static int __init uclinux_mtd_init(void) 591da177e4SLinus Torvalds { 601da177e4SLinus Torvalds struct mtd_info *mtd; 611da177e4SLinus Torvalds struct map_info *mapp; 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds mapp = &uclinux_ram_map; 64fa254ecbSMike Frysinger if (!mapp->size) 65fa254ecbSMike Frysinger mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8)))); 661da177e4SLinus Torvalds mapp->bankwidth = 4; 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n", 69f6515db4SGreg Ungerer (int) mapp->phys, (int) mapp->size); 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds mapp->virt = ioremap_nocache(mapp->phys, mapp->size); 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds if (mapp->virt == 0) { 741da177e4SLinus Torvalds printk("uclinux[mtd]: ioremap_nocache() failed\n"); 751da177e4SLinus Torvalds return(-EIO); 761da177e4SLinus Torvalds } 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds simple_map_init(mapp); 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds mtd = do_map_probe("map_ram", mapp); 811da177e4SLinus Torvalds if (!mtd) { 821da177e4SLinus Torvalds printk("uclinux[mtd]: failed to find a mapping?\n"); 831da177e4SLinus Torvalds iounmap(mapp->virt); 841da177e4SLinus Torvalds return(-ENXIO); 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds mtd->owner = THIS_MODULE; 88*3c3c10bbSArtem Bityutskiy mtd->_point = uclinux_point; 891da177e4SLinus Torvalds mtd->priv = mapp; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds uclinux_ram_mtdinfo = mtd; 925e7e9686SJamie Iles mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS); 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds return(0); 951da177e4SLinus Torvalds } 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds /****************************************************************************/ 981da177e4SLinus Torvalds 99769455e2SDmitri Vorobiev static void __exit uclinux_mtd_cleanup(void) 1001da177e4SLinus Torvalds { 1011da177e4SLinus Torvalds if (uclinux_ram_mtdinfo) { 1025e7e9686SJamie Iles mtd_device_unregister(uclinux_ram_mtdinfo); 1031da177e4SLinus Torvalds map_destroy(uclinux_ram_mtdinfo); 1041da177e4SLinus Torvalds uclinux_ram_mtdinfo = NULL; 1051da177e4SLinus Torvalds } 106f6515db4SGreg Ungerer if (uclinux_ram_map.virt) { 1071da177e4SLinus Torvalds iounmap((void *) uclinux_ram_map.virt); 1081da177e4SLinus Torvalds uclinux_ram_map.virt = 0; 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds } 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds /****************************************************************************/ 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds module_init(uclinux_mtd_init); 1151da177e4SLinus Torvalds module_exit(uclinux_mtd_cleanup); 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 1181da177e4SLinus Torvalds MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>"); 1191da177e4SLinus Torvalds MODULE_DESCRIPTION("Generic RAM based MTD for uClinux"); 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds /****************************************************************************/ 122