162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci *  Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is>
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci *  This program is free software; you can redistribute  it and/or modify it
562306a36Sopenharmony_ci *  under  the terms of  the GNU General  Public License as published by the
662306a36Sopenharmony_ci *  Free Software Foundation;  either version 2 of the  License, or (at your
762306a36Sopenharmony_ci *  option) any later version.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
1062306a36Sopenharmony_ci *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
1162306a36Sopenharmony_ci *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
1262306a36Sopenharmony_ci *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
1362306a36Sopenharmony_ci *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1462306a36Sopenharmony_ci *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
1562306a36Sopenharmony_ci *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
1662306a36Sopenharmony_ci *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
1762306a36Sopenharmony_ci *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1862306a36Sopenharmony_ci *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1962306a36Sopenharmony_ci *
2062306a36Sopenharmony_ci *  You should have received a copy of the  GNU General Public License along
2162306a36Sopenharmony_ci *  with this program; if not, write  to the Free Software Foundation, Inc.,
2262306a36Sopenharmony_ci *  675 Mass Ave, Cambridge, MA 02139, USA.
2362306a36Sopenharmony_ci */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#include <linux/module.h>
2662306a36Sopenharmony_ci#include <linux/types.h>
2762306a36Sopenharmony_ci#include <linux/kernel.h>
2862306a36Sopenharmony_ci#include <linux/init.h>
2962306a36Sopenharmony_ci#include <asm/io.h>
3062306a36Sopenharmony_ci#include <linux/mtd/mtd.h>
3162306a36Sopenharmony_ci#include <linux/mtd/map.h>
3262306a36Sopenharmony_ci#include <linux/mtd/partitions.h>
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/* We split the flash chip up into four parts.
3662306a36Sopenharmony_ci * 1: bootloader first 128k			(0x00000000 - 0x0001FFFF) size 0x020000
3762306a36Sopenharmony_ci * 2: kernel 640k					(0x00020000 - 0x000BFFFF) size 0x0A0000
3862306a36Sopenharmony_ci * 3: compressed 1536k root ramdisk	(0x000C0000 - 0x0023FFFF) size 0x180000
3962306a36Sopenharmony_ci * 4: writeable diskpartition (jffs)(0x00240000 - 0x003FFFFF) size 0x1C0000
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define FLASH_PHYS_ADDR 0x40000000
4362306a36Sopenharmony_ci#define FLASH_SIZE 0x400000
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#define FLASH_PARTITION0_ADDR 0x00000000
4662306a36Sopenharmony_ci#define FLASH_PARTITION0_SIZE 0x00020000
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define FLASH_PARTITION1_ADDR 0x00020000
4962306a36Sopenharmony_ci#define FLASH_PARTITION1_SIZE 0x000A0000
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define FLASH_PARTITION2_ADDR 0x000C0000
5262306a36Sopenharmony_ci#define FLASH_PARTITION2_SIZE 0x00180000
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define FLASH_PARTITION3_ADDR 0x00240000
5562306a36Sopenharmony_ci#define FLASH_PARTITION3_SIZE 0x001C0000
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cistatic struct map_info flagadm_map = {
5962306a36Sopenharmony_ci		.name =		"FlagaDM flash device",
6062306a36Sopenharmony_ci		.size =		FLASH_SIZE,
6162306a36Sopenharmony_ci		.bankwidth =	2,
6262306a36Sopenharmony_ci};
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_cistatic const struct mtd_partition flagadm_parts[] = {
6562306a36Sopenharmony_ci	{
6662306a36Sopenharmony_ci		.name =		"Bootloader",
6762306a36Sopenharmony_ci		.offset	=	FLASH_PARTITION0_ADDR,
6862306a36Sopenharmony_ci		.size =		FLASH_PARTITION0_SIZE
6962306a36Sopenharmony_ci	},
7062306a36Sopenharmony_ci	{
7162306a36Sopenharmony_ci		.name =		"Kernel image",
7262306a36Sopenharmony_ci		.offset =	FLASH_PARTITION1_ADDR,
7362306a36Sopenharmony_ci		.size =		FLASH_PARTITION1_SIZE
7462306a36Sopenharmony_ci	},
7562306a36Sopenharmony_ci	{
7662306a36Sopenharmony_ci		.name =		"Initial ramdisk image",
7762306a36Sopenharmony_ci		.offset =	FLASH_PARTITION2_ADDR,
7862306a36Sopenharmony_ci		.size =		FLASH_PARTITION2_SIZE
7962306a36Sopenharmony_ci	},
8062306a36Sopenharmony_ci	{
8162306a36Sopenharmony_ci		.name =		"Persistent storage",
8262306a36Sopenharmony_ci		.offset =	FLASH_PARTITION3_ADDR,
8362306a36Sopenharmony_ci		.size =		FLASH_PARTITION3_SIZE
8462306a36Sopenharmony_ci	}
8562306a36Sopenharmony_ci};
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define PARTITION_COUNT ARRAY_SIZE(flagadm_parts)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistatic struct mtd_info *mymtd;
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_cistatic int __init init_flagadm(void)
9262306a36Sopenharmony_ci{
9362306a36Sopenharmony_ci	printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n",
9462306a36Sopenharmony_ci			FLASH_SIZE, FLASH_PHYS_ADDR);
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci	flagadm_map.phys = FLASH_PHYS_ADDR;
9762306a36Sopenharmony_ci	flagadm_map.virt = ioremap(FLASH_PHYS_ADDR,
9862306a36Sopenharmony_ci					FLASH_SIZE);
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	if (!flagadm_map.virt) {
10162306a36Sopenharmony_ci		printk("Failed to ioremap\n");
10262306a36Sopenharmony_ci		return -EIO;
10362306a36Sopenharmony_ci	}
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	simple_map_init(&flagadm_map);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci	mymtd = do_map_probe("cfi_probe", &flagadm_map);
10862306a36Sopenharmony_ci	if (mymtd) {
10962306a36Sopenharmony_ci		mymtd->owner = THIS_MODULE;
11062306a36Sopenharmony_ci		mtd_device_register(mymtd, flagadm_parts, PARTITION_COUNT);
11162306a36Sopenharmony_ci		printk(KERN_NOTICE "FlagaDM flash device initialized\n");
11262306a36Sopenharmony_ci		return 0;
11362306a36Sopenharmony_ci	}
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	iounmap((void __iomem *)flagadm_map.virt);
11662306a36Sopenharmony_ci	return -ENXIO;
11762306a36Sopenharmony_ci}
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistatic void __exit cleanup_flagadm(void)
12062306a36Sopenharmony_ci{
12162306a36Sopenharmony_ci	if (mymtd) {
12262306a36Sopenharmony_ci		mtd_device_unregister(mymtd);
12362306a36Sopenharmony_ci		map_destroy(mymtd);
12462306a36Sopenharmony_ci	}
12562306a36Sopenharmony_ci	if (flagadm_map.virt) {
12662306a36Sopenharmony_ci		iounmap((void __iomem *)flagadm_map.virt);
12762306a36Sopenharmony_ci		flagadm_map.virt = NULL;
12862306a36Sopenharmony_ci	}
12962306a36Sopenharmony_ci}
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_cimodule_init(init_flagadm);
13262306a36Sopenharmony_cimodule_exit(cleanup_flagadm);
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciMODULE_LICENSE("GPL");
13662306a36Sopenharmony_ciMODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
13762306a36Sopenharmony_ciMODULE_DESCRIPTION("MTD map driver for Flaga digital module");
138