blob: c1af83db5202fe46f503b68289fbc06d0ee59828 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/****************************************************************************/
2
3/*
4 * uclinux.c -- generic memory mapped MTD driver for uclinux
5 *
6 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9/****************************************************************************/
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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 Righi27ac7922008-07-23 21:28:13 -070016#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/major.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/mtd/mtd.h>
19#include <linux/mtd/map.h>
20#include <linux/mtd/partitions.h>
21#include <asm/io.h>
Geert Uytterhoeven363737d2012-05-31 22:39:21 +020022#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/****************************************************************************/
25
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010026#ifdef CONFIG_MTD_ROM
27#define MAP_NAME "rom"
28#else
29#define MAP_NAME "ram"
30#endif
31
Uwe Kleine-König44fe63f2013-01-16 15:36:56 +010032/*
33 * Blackfin uses uclinux_ram_map during startup, so it must not be static.
34 * Provide a dummy declaration to make sparse happy.
35 */
36extern struct map_info uclinux_ram_map;
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038struct map_info uclinux_ram_map = {
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010039 .name = MAP_NAME,
Mike Frysingerfa254ec2009-05-26 19:33:16 -040040 .size = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041};
42
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010043static unsigned long physaddr = -1;
44module_param(physaddr, ulong, S_IRUGO);
45
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040046static struct mtd_info *uclinux_ram_mtdinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/****************************************************************************/
49
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040050static struct mtd_partition uclinux_romfs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 { .name = "ROMfs" }
52};
53
Tobias Klauser87d10f32006-03-31 02:29:45 -080054#define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/****************************************************************************/
57
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040058static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
Jared Hulberta98889f2008-04-29 23:26:49 -070059 size_t *retlen, void **virt, resource_size_t *phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 struct map_info *map = mtd->priv;
Jared Hulberta98889f2008-04-29 23:26:49 -070062 *virt = map->virt + from;
63 if (phys)
64 *phys = map->phys + from;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 *retlen = len;
66 return(0);
67}
68
69/****************************************************************************/
70
Dmitri Vorobiev769455e2008-11-25 02:55:09 +020071static int __init uclinux_mtd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 struct mtd_info *mtd;
74 struct map_info *mapp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 mapp = &uclinux_ram_map;
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010077
78 if (physaddr == -1)
79 mapp->phys = (resource_size_t)__bss_stop;
80 else
81 mapp->phys = physaddr;
82
Mike Frysingerfa254ec2009-05-26 19:33:16 -040083 if (!mapp->size)
84 mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 mapp->bankwidth = 4;
86
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010087 printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
Greg Ungererf6515db2005-09-12 11:18:10 +100088 (int) mapp->phys, (int) mapp->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Greg Ungerer08a3c4b2012-07-19 15:42:45 +100090 /*
91 * The filesystem is guaranteed to be in direct mapped memory. It is
92 * directly following the kernels own bss region. Following the same
93 * mechanism used by architectures setting up traditional initrds we
94 * use phys_to_virt to get the virtual address of its start.
95 */
96 mapp->virt = phys_to_virt(mapp->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 if (mapp->virt == 0) {
Greg Ungerer08a3c4b2012-07-19 15:42:45 +100099 printk("uclinux[mtd]: no virtual mapping?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return(-EIO);
101 }
102
103 simple_map_init(mapp);
104
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +0100105 mtd = do_map_probe("map_" MAP_NAME, mapp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 if (!mtd) {
107 printk("uclinux[mtd]: failed to find a mapping?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return(-ENXIO);
109 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 mtd->owner = THIS_MODULE;
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200112 mtd->_point = uclinux_point;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 mtd->priv = mapp;
114
115 uclinux_ram_mtdinfo = mtd;
Jamie Iles5e7e9682011-05-23 10:23:12 +0100116 mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return(0);
119}
120
121/****************************************************************************/
122
Dmitri Vorobiev769455e2008-11-25 02:55:09 +0200123static void __exit uclinux_mtd_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 if (uclinux_ram_mtdinfo) {
Jamie Iles5e7e9682011-05-23 10:23:12 +0100126 mtd_device_unregister(uclinux_ram_mtdinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 map_destroy(uclinux_ram_mtdinfo);
128 uclinux_ram_mtdinfo = NULL;
129 }
Greg Ungerer08a3c4b2012-07-19 15:42:45 +1000130 if (uclinux_ram_map.virt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 uclinux_ram_map.virt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134/****************************************************************************/
135
136module_init(uclinux_mtd_init);
137module_exit(uclinux_mtd_cleanup);
138
139MODULE_LICENSE("GPL");
140MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +0100141MODULE_DESCRIPTION("Generic MTD for uClinux");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143/****************************************************************************/