Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * uclinux.c -- generic memory mapped MTD driver for uclinux |
| 5 | * |
| 6 | * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /****************************************************************************/ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #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 Righi | 27ac792 | 2008-07-23 21:28:13 -0700 | [diff] [blame] | 16 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/major.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/mtd/mtd.h> |
| 19 | #include <linux/mtd/map.h> |
| 20 | #include <linux/mtd/partitions.h> |
| 21 | #include <asm/io.h> |
Geert Uytterhoeven | 363737d | 2012-05-31 22:39:21 +0200 | [diff] [blame] | 22 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | /****************************************************************************/ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | struct map_info uclinux_ram_map = { |
| 27 | .name = "RAM", |
Geert Uytterhoeven | 363737d | 2012-05-31 22:39:21 +0200 | [diff] [blame] | 28 | .phys = (unsigned long)__bss_stop, |
Mike Frysinger | fa254ec | 2009-05-26 19:33:16 -0400 | [diff] [blame] | 29 | .size = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Mike Frysinger | 9f31f4b | 2009-05-26 19:33:17 -0400 | [diff] [blame] | 32 | static struct mtd_info *uclinux_ram_mtdinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | /****************************************************************************/ |
| 35 | |
Mike Frysinger | 9f31f4b | 2009-05-26 19:33:17 -0400 | [diff] [blame] | 36 | static struct mtd_partition uclinux_romfs[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { .name = "ROMfs" } |
| 38 | }; |
| 39 | |
Tobias Klauser | 87d10f3 | 2006-03-31 02:29:45 -0800 | [diff] [blame] | 40 | #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /****************************************************************************/ |
| 43 | |
Mike Frysinger | 9f31f4b | 2009-05-26 19:33:17 -0400 | [diff] [blame] | 44 | static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len, |
Jared Hulbert | a98889f | 2008-04-29 23:26:49 -0700 | [diff] [blame] | 45 | size_t *retlen, void **virt, resource_size_t *phys) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
| 47 | struct map_info *map = mtd->priv; |
Jared Hulbert | a98889f | 2008-04-29 23:26:49 -0700 | [diff] [blame] | 48 | *virt = map->virt + from; |
| 49 | if (phys) |
| 50 | *phys = map->phys + from; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | *retlen = len; |
| 52 | return(0); |
| 53 | } |
| 54 | |
| 55 | /****************************************************************************/ |
| 56 | |
Dmitri Vorobiev | 769455e | 2008-11-25 02:55:09 +0200 | [diff] [blame] | 57 | static int __init uclinux_mtd_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | struct mtd_info *mtd; |
| 60 | struct map_info *mapp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | mapp = &uclinux_ram_map; |
Mike Frysinger | fa254ec | 2009-05-26 19:33:16 -0400 | [diff] [blame] | 63 | if (!mapp->size) |
| 64 | mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8)))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | mapp->bankwidth = 4; |
| 66 | |
| 67 | printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n", |
Greg Ungerer | f6515db | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 68 | (int) mapp->phys, (int) mapp->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Greg Ungerer | 08a3c4b | 2012-07-19 15:42:45 +1000 | [diff] [blame] | 70 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | if (mapp->virt == 0) { |
Greg Ungerer | 08a3c4b | 2012-07-19 15:42:45 +1000 | [diff] [blame] | 79 | printk("uclinux[mtd]: no virtual mapping?\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | return(-ENXIO); |
| 89 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | mtd->owner = THIS_MODULE; |
Artem Bityutskiy | 3c3c10b | 2012-01-30 14:58:32 +0200 | [diff] [blame] | 92 | mtd->_point = uclinux_point; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | mtd->priv = mapp; |
| 94 | |
| 95 | uclinux_ram_mtdinfo = mtd; |
Jamie Iles | 5e7e968 | 2011-05-23 10:23:12 +0100 | [diff] [blame] | 96 | mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | return(0); |
| 99 | } |
| 100 | |
| 101 | /****************************************************************************/ |
| 102 | |
Dmitri Vorobiev | 769455e | 2008-11-25 02:55:09 +0200 | [diff] [blame] | 103 | static void __exit uclinux_mtd_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
| 105 | if (uclinux_ram_mtdinfo) { |
Jamie Iles | 5e7e968 | 2011-05-23 10:23:12 +0100 | [diff] [blame] | 106 | mtd_device_unregister(uclinux_ram_mtdinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | map_destroy(uclinux_ram_mtdinfo); |
| 108 | uclinux_ram_mtdinfo = NULL; |
| 109 | } |
Greg Ungerer | 08a3c4b | 2012-07-19 15:42:45 +1000 | [diff] [blame] | 110 | if (uclinux_ram_map.virt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | uclinux_ram_map.virt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /****************************************************************************/ |
| 115 | |
| 116 | module_init(uclinux_mtd_init); |
| 117 | module_exit(uclinux_mtd_cleanup); |
| 118 | |
| 119 | MODULE_LICENSE("GPL"); |
| 120 | MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>"); |
| 121 | MODULE_DESCRIPTION("Generic RAM based MTD for uClinux"); |
| 122 | |
| 123 | /****************************************************************************/ |