blob: de4c46318abb80c1938345fe0b62083c7c673017 [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
Thomas Huth251f26c2019-04-27 17:14:57 +020034static struct map_info uclinux_ram_map = {
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010035 .name = MAP_NAME,
Mike Frysingerfa254ec2009-05-26 19:33:16 -040036 .size = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070037};
38
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010039static unsigned long physaddr = -1;
40module_param(physaddr, ulong, S_IRUGO);
41
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040042static struct mtd_info *uclinux_ram_mtdinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/****************************************************************************/
45
Arvind Yadavd4906682017-08-28 13:54:57 +053046static const struct mtd_partition uclinux_romfs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 { .name = "ROMfs" }
48};
49
Tobias Klauser87d10f32006-03-31 02:29:45 -080050#define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/****************************************************************************/
53
Mike Frysinger9f31f4b2009-05-26 19:33:17 -040054static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
Jared Hulberta98889f2008-04-29 23:26:49 -070055 size_t *retlen, void **virt, resource_size_t *phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 struct map_info *map = mtd->priv;
Jared Hulberta98889f2008-04-29 23:26:49 -070058 *virt = map->virt + from;
59 if (phys)
60 *phys = map->phys + from;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 *retlen = len;
62 return(0);
63}
64
65/****************************************************************************/
66
Dmitri Vorobiev769455e2008-11-25 02:55:09 +020067static int __init uclinux_mtd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 struct mtd_info *mtd;
70 struct map_info *mapp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 mapp = &uclinux_ram_map;
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010073
74 if (physaddr == -1)
75 mapp->phys = (resource_size_t)__bss_stop;
76 else
77 mapp->phys = physaddr;
78
Mike Frysingerfa254ec2009-05-26 19:33:16 -040079 if (!mapp->size)
80 mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 mapp->bankwidth = 4;
82
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +010083 printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
Greg Ungererf6515db2005-09-12 11:18:10 +100084 (int) mapp->phys, (int) mapp->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Greg Ungerer08a3c4b2012-07-19 15:42:45 +100086 /*
87 * The filesystem is guaranteed to be in direct mapped memory. It is
88 * directly following the kernels own bss region. Following the same
89 * mechanism used by architectures setting up traditional initrds we
90 * use phys_to_virt to get the virtual address of its start.
91 */
92 mapp->virt = phys_to_virt(mapp->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 if (mapp->virt == 0) {
Greg Ungerer08a3c4b2012-07-19 15:42:45 +100095 printk("uclinux[mtd]: no virtual mapping?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return(-EIO);
97 }
98
99 simple_map_init(mapp);
100
Uwe Kleine-König81f53ff2013-01-16 15:36:55 +0100101 mtd = do_map_probe("map_" MAP_NAME, mapp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (!mtd) {
103 printk("uclinux[mtd]: failed to find a mapping?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 return(-ENXIO);
105 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 mtd->owner = THIS_MODULE;
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200108 mtd->_point = uclinux_point;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 mtd->priv = mapp;
110
111 uclinux_ram_mtdinfo = mtd;
Jamie Iles5e7e9682011-05-23 10:23:12 +0100112 mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return(0);
115}
Paul Gortmaker025ce022016-03-27 12:13:54 -0400116device_initcall(uclinux_mtd_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/****************************************************************************/