integrator-flash.c 4.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
/*======================================================================

    drivers/mtd/maps/integrator-flash.c: ARM Integrator flash map driver
4

L
Linus Torvalds 已提交
5 6
    Copyright (C) 2000 ARM Limited
    Copyright (C) 2003 Deep Blue Solutions Ltd.
7

L
Linus Torvalds 已提交
8 9 10 11
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
12

L
Linus Torvalds 已提交
13 14 15 16
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
17

L
Linus Torvalds 已提交
18 19 20
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 22

   This is access code for flashes using ARM's flash partitioning
L
Linus Torvalds 已提交
23 24 25 26 27 28 29 30 31
   standards.

======================================================================*/

#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/ioport.h>
32
#include <linux/platform_device.h>
L
Linus Torvalds 已提交
33 34 35 36 37 38 39
#include <linux/init.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>

#include <asm/mach/flash.h>
40
#include <mach/hardware.h>
L
Linus Torvalds 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#include <asm/io.h>
#include <asm/system.h>

#ifdef CONFIG_ARCH_P720T
#define FLASH_BASE		(0x04000000)
#define FLASH_SIZE		(64*1024*1024)
#endif

struct armflash_info {
	struct flash_platform_data *plat;
	struct resource		*res;
	struct mtd_partition	*parts;
	struct mtd_info		*mtd;
	struct map_info		map;
};

static void armflash_set_vpp(struct map_info *map, int on)
{
	struct armflash_info *info = container_of(map, struct armflash_info, map);

	if (info->plat && info->plat->set_vpp)
		info->plat->set_vpp(on);
}

static const char *probes[] = { "cmdlinepart", "RedBoot", "afs", NULL };

67
static int armflash_probe(struct platform_device *dev)
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75
{
	struct flash_platform_data *plat = dev->dev.platform_data;
	struct resource *res = dev->resource;
	unsigned int size = res->end - res->start + 1;
	struct armflash_info *info;
	int err;
	void __iomem *base;

76
	info = kzalloc(sizeof(struct armflash_info), GFP_KERNEL);
L
Linus Torvalds 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
	if (!info) {
		err = -ENOMEM;
		goto out;
	}

	info->plat = plat;
	if (plat && plat->init) {
		err = plat->init();
		if (err)
			goto no_resource;
	}

	info->res = request_mem_region(res->start, size, "armflash");
	if (!info->res) {
		err = -EBUSY;
		goto no_resource;
	}

	base = ioremap(res->start, size);
	if (!base) {
		err = -ENOMEM;
		goto no_mem;
	}

	/*
	 * look for CFI based flash parts fitted to this board
	 */
	info->map.size		= size;
	info->map.bankwidth	= plat->width;
	info->map.phys		= res->start;
	info->map.virt		= base;
108
	info->map.name		= dev_name(&dev->dev);
L
Linus Torvalds 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
	info->map.set_vpp	= armflash_set_vpp;

	simple_map_init(&info->map);

	/*
	 * Also, the CFI layer automatically works out what size
	 * of chips we have, and does the necessary identification
	 * for us automatically.
	 */
	info->mtd = do_map_probe(plat->map_name, &info->map);
	if (!info->mtd) {
		err = -ENXIO;
		goto no_device;
	}

	info->mtd->owner = THIS_MODULE;

	err = parse_mtd_partitions(info->mtd, probes, &info->parts, 0);
	if (err > 0) {
		err = add_mtd_partitions(info->mtd, info->parts, err);
		if (err)
			printk(KERN_ERR
			       "mtd partition registration failed: %d\n", err);
	}

	if (err == 0)
135
		platform_set_drvdata(dev, info);
L
Linus Torvalds 已提交
136 137 138 139 140 141 142 143 144

	/*
	 * If we got an error, free all resources.
	 */
	if (err < 0) {
		if (info->mtd) {
			del_mtd_partitions(info->mtd);
			map_destroy(info->mtd);
		}
J
Jesper Juhl 已提交
145
		kfree(info->parts);
L
Linus Torvalds 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159

 no_device:
		iounmap(base);
 no_mem:
		release_mem_region(res->start, size);
 no_resource:
		if (plat && plat->exit)
			plat->exit();
		kfree(info);
	}
 out:
	return err;
}

160
static int armflash_remove(struct platform_device *dev)
L
Linus Torvalds 已提交
161
{
162
	struct armflash_info *info = platform_get_drvdata(dev);
L
Linus Torvalds 已提交
163

164
	platform_set_drvdata(dev, NULL);
L
Linus Torvalds 已提交
165 166 167 168 169 170

	if (info) {
		if (info->mtd) {
			del_mtd_partitions(info->mtd);
			map_destroy(info->mtd);
		}
J
Jesper Juhl 已提交
171
		kfree(info->parts);
L
Linus Torvalds 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185

		iounmap(info->map.virt);
		release_resource(info->res);
		kfree(info->res);

		if (info->plat && info->plat->exit)
			info->plat->exit();

		kfree(info);
	}

	return 0;
}

186
static struct platform_driver armflash_driver = {
L
Linus Torvalds 已提交
187 188
	.probe		= armflash_probe,
	.remove		= armflash_remove,
189 190
	.driver		= {
		.name	= "armflash",
191
		.owner	= THIS_MODULE,
192
	},
L
Linus Torvalds 已提交
193 194 195 196
};

static int __init armflash_init(void)
{
197
	return platform_driver_register(&armflash_driver);
L
Linus Torvalds 已提交
198 199 200 201
}

static void __exit armflash_exit(void)
{
202
	platform_driver_unregister(&armflash_driver);
L
Linus Torvalds 已提交
203 204 205 206 207 208 209 210
}

module_init(armflash_init);
module_exit(armflash_exit);

MODULE_AUTHOR("ARM Ltd");
MODULE_DESCRIPTION("ARM Integrator CFI map driver");
MODULE_LICENSE("GPL");
211
MODULE_ALIAS("platform:armflash");