edb7312.c 3.33 KB
Newer Older
1
/*
Thomas Gleixner's avatar
Thomas Gleixner committed
2
 * $Id: edb7312.c,v 1.12 2004/09/16 23:27:13 gleixner Exp $
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 * Handle mapping of the NOR flash on Cogent EDB7312 boards
 *
 * Copyright 2002 SYSGO Real-Time Solutions GmbH
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
David Woodhouse's avatar
David Woodhouse committed
16
#include <linux/init.h>
17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <asm/io.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/config.h>

#ifdef CONFIG_MTD_PARTITIONS
#include <linux/mtd/partitions.h>
#endif

#define WINDOW_ADDR 0x00000000      /* physical properties of flash */
#define WINDOW_SIZE 0x01000000
#define BUSWIDTH    2
#define FLASH_BLOCKSIZE_MAIN	0x20000
#define FLASH_NUMBLOCKS_MAIN	128
David Woodhouse's avatar
David Woodhouse committed
31 32
/* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */
#define PROBETYPES { "cfi_probe", NULL }
33 34 35 36 37 38 39

#define MSG_PREFIX "EDB7312-NOR:"   /* prefix for our printk()'s */
#define MTDID      "edb7312-nor"    /* for mtdparts= partitioning */

static struct mtd_info *mymtd;

struct map_info edb7312nor_map = {
David Woodhouse's avatar
David Woodhouse committed
40 41
	.name = "NOR flash on EDB7312",
	.size = WINDOW_SIZE,
David Woodhouse's avatar
David Woodhouse committed
42
	.bankwidth = BUSWIDTH,
David Woodhouse's avatar
David Woodhouse committed
43
	.phys = WINDOW_ADDR,
44 45 46 47 48 49 50
};

#ifdef CONFIG_MTD_PARTITIONS

/*
 * MTD partitioning stuff 
 */
David Woodhouse's avatar
David Woodhouse committed
51 52
static struct mtd_partition static_partitions[3] =
{
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
	{
		.name = "ARMboot",
		.size = 0x40000,
		.offset = 0
	},
	{
		.name = "Kernel",
		.size = 0x200000,
		.offset = 0x40000
	},
	{
		.name = "RootFS",
		.size = 0xDC0000,
		.offset = 0x240000
	},
68 69
};

David Woodhouse's avatar
David Woodhouse committed
70
static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
71 72 73

#endif

Thomas Gleixner's avatar
Thomas Gleixner committed
74 75
static int                   mtd_parts_nb = 0;
static struct mtd_partition *mtd_parts    = 0;
76 77 78 79 80

int __init init_edb7312nor(void)
{
	static const char *rom_probe_types[] = PROBETYPES;
	const char **type;
Thomas Gleixner's avatar
Thomas Gleixner committed
81
	const char *part_type = 0;
82 83 84

       	printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n", 
	       WINDOW_SIZE, WINDOW_ADDR);
Thomas Gleixner's avatar
Thomas Gleixner committed
85 86
	edb7312nor_map.virt = (void __iomem *)
		ioremap(WINDOW_ADDR, WINDOW_SIZE);
87

David Woodhouse's avatar
David Woodhouse committed
88
	if (!edb7312nor_map.virt) {
89 90 91
		printk(MSG_PREFIX "failed to ioremap\n");
		return -EIO;
	}
David Woodhouse's avatar
David Woodhouse committed
92 93
	
	simple_map_init(&edb7312nor_map);
94

Thomas Gleixner's avatar
Thomas Gleixner committed
95
	mymtd = 0;
96 97 98 99 100
	type = rom_probe_types;
	for(; !mymtd && *type; type++) {
		mymtd = do_map_probe(*type, &edb7312nor_map);
	}
	if (mymtd) {
David Woodhouse's avatar
David Woodhouse committed
101
		mymtd->owner = THIS_MODULE;
102 103

#ifdef CONFIG_MTD_PARTITIONS
David Woodhouse's avatar
David Woodhouse committed
104
		mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);
105
		if (mtd_parts_nb > 0)
David Woodhouse's avatar
David Woodhouse committed
106 107
		  part_type = "detected";

108 109 110
		if (mtd_parts_nb == 0)
		{
			mtd_parts = static_partitions;
David Woodhouse's avatar
David Woodhouse committed
111
			mtd_parts_nb = ARRAY_SIZE(static_partitions);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
			part_type = "static";
		}
#endif
		add_mtd_device(mymtd);
		if (mtd_parts_nb == 0)
		  printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
		else
		{
			printk(KERN_NOTICE MSG_PREFIX
			       "using %s partition definition\n", part_type);
			add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);
		}
		return 0;
	}

David Woodhouse's avatar
David Woodhouse committed
127
	iounmap((void *)edb7312nor_map.virt);
128 129 130 131 132 133 134 135 136
	return -ENXIO;
}

static void __exit cleanup_edb7312nor(void)
{
	if (mymtd) {
		del_mtd_device(mymtd);
		map_destroy(mymtd);
	}
David Woodhouse's avatar
David Woodhouse committed
137 138 139
	if (edb7312nor_map.virt) {
		iounmap((void *)edb7312nor_map.virt);
		edb7312nor_map.virt = 0;
140 141 142 143 144 145 146 147 148
	}
}

module_init(init_edb7312nor);
module_exit(cleanup_edb7312nor);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
MODULE_DESCRIPTION("Generic configurable MTD map driver");