blob: 00a8190797ec1d4a445fd4bd46bfe03903699a15 [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)
Paul Gortmaker025ce022016-03-27 12:13:54 -04007 *
8 * License: GPL
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
11/****************************************************************************/
12
Paul Gortmaker025ce022016-03-27 12:13:54 -040013#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/fs.h>
Andrea Righi27ac7922008-07-23 21:28:13 -070018#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/major.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/mtd/mtd.h>
21#include <linux/mtd/map.h>
22#include <linux/mtd/partitions.h>
23#include <asm/io.h>
Geert Uytterhoeven363737d2012-05-31 22:39:21 +020024#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26/****************************************************************************/
27
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010028#ifdef CONFIG_MTD_ROM
29#define MAP_NAME "rom"
30#else
31#define MAP_NAME "ram"
32#endif
33
Uwe Kleine-König44fe63f2013-01-16 15:36:56 +010034/*
35 * Blackfin uses uclinux_ram_map during startup, so it must not be static.
36 * Provide a dummy declaration to make sparse happy.
37 */
38extern struct map_info uclinux_ram_map;
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040struct map_info uclinux_ram_map = {
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010041 .name = MAP_NAME,
Mike Frysingerfa254ec2009-05-26 19:33:16 -040042 .size = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010045static unsigned long physaddr = -1;
46module_param(physaddr, ulong, S_IRUGO);
47
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040048static struct mtd_info *uclinux_ram_mtdinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/****************************************************************************/
51
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040052static struct mtd_partition uclinux_romfs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 { .name = "ROMfs" }
54};
55
Tobias Klauser87d10f32006-03-31 02:29:45 -080056#define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/****************************************************************************/
59
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040060static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
Jared Hulberta98889f2008-04-29 23:26:49 -070061 size_t *retlen, void **virt, resource_size_t *phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 struct map_info *map = mtd->priv;
Jared Hulberta98889f2008-04-29 23:26:49 -070064 *virt = map->virt + from;
65 if (phys)
66 *phys = map->phys + from;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *retlen = len;
68 return(0);
69}
70
71/****************************************************************************/
72
Dmitri Vorobiev769455e2008-11-25 02:55:09 +020073static int __init uclinux_mtd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 struct mtd_info *mtd;
76 struct map_info *mapp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 mapp = &uclinux_ram_map;
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010079
80 if (physaddr == -1)
81 mapp->phys = (resource_size_t)__bss_stop;
82 else
83 mapp->phys = physaddr;
84
Mike Frysingerfa254ec2009-05-26 19:33:16 -040085 if (!mapp->size)
86 mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 mapp->bankwidth = 4;
88
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010089 printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
Greg Ungererf6515db2005-09-12 11:18:10 +100090 (int) mapp->phys, (int) mapp->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Greg Ungerer08a3c4b2012-07-19 15:42:45 +100092 /*
93 * The filesystem is guaranteed to be in direct mapped memory. It is
94 * directly following the kernels own bss region. Following the same
95 * mechanism used by architectures setting up traditional initrds we
96 * use phys_to_virt to get the virtual address of its start.
97 */
98 mapp->virt = phys_to_virt(mapp->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 if (mapp->virt == 0) {
Greg Ungerer08a3c4b2012-07-19 15:42:45 +1000101 printk("uclinux[mtd]: no virtual mapping?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return(-EIO);
103 }
104
105 simple_map_init(mapp);
106
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +0100107 mtd = do_map_probe("map_" MAP_NAME, mapp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 if (!mtd) {
109 printk("uclinux[mtd]: failed to find a mapping?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return(-ENXIO);
111 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 mtd->owner = THIS_MODULE;
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200114 mtd->_point = uclinux_point;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 mtd->priv = mapp;
116
117 uclinux_ram_mtdinfo = mtd;
Jamie Iles5e7e9682011-05-23 10:23:12 +0100118 mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return(0);
121}
Paul Gortmaker025ce022016-03-27 12:13:54 -0400122device_initcall(uclinux_mtd_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/****************************************************************************/