2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-11-07 12:15:40 +01:00
|
|
|
* $Id: ixp4xx.c,v 1.12 2005/11/07 11:14:27 gleixner Exp $
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* drivers/mtd/maps/ixp4xx.c
|
|
|
|
*
|
|
|
|
* MTD Map file for IXP4XX based systems. Please do not make per-board
|
|
|
|
* changes in here. If your board needs special setup, do it in your
|
|
|
|
* platform level code in arch/arm/mach-ixp4xx/board-setup.c
|
|
|
|
*
|
|
|
|
* Original Author: Intel Corporation
|
|
|
|
* Maintainer: Deepak Saxena <dsaxena@mvista.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Intel Corporation
|
|
|
|
* Copyright (C) 2003-2004 MontaVista Software, Inc.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
2005-10-31 00:03:48 +01:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/device.h>
|
2005-10-31 16:32:56 +01:00
|
|
|
#include <linux/platform_device.h>
|
2005-10-31 00:03:48 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/map.h>
|
|
|
|
#include <linux/mtd/partitions.h>
|
2005-10-31 00:03:48 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/mach/flash.h>
|
|
|
|
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
|
|
|
|
#ifndef __ARMEB__
|
|
|
|
#define BYTE0(h) ((h) & 0xFF)
|
|
|
|
#define BYTE1(h) (((h) >> 8) & 0xFF)
|
|
|
|
#else
|
|
|
|
#define BYTE0(h) (((h) >> 8) & 0xFF)
|
|
|
|
#define BYTE1(h) ((h) & 0xFF)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs)
|
|
|
|
{
|
|
|
|
map_word val;
|
2005-11-01 17:46:19 +01:00
|
|
|
val.x[0] = le16_to_cpu(readw(map->virt + ofs));
|
2005-04-17 00:20:36 +02:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The IXP4xx expansion bus only allows 16-bit wide acceses
|
|
|
|
* when attached to a 16-bit wide device (such as the 28F128J3A),
|
|
|
|
* so we can't just memcpy_fromio().
|
|
|
|
*/
|
|
|
|
static void ixp4xx_copy_from(struct map_info *map, void *to,
|
|
|
|
unsigned long from, ssize_t len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u8 *dest = (u8 *) to;
|
2005-11-01 17:46:19 +01:00
|
|
|
void __iomem *src = map->virt + from;
|
2005-04-17 00:20:36 +02:00
|
|
|
u16 data;
|
|
|
|
|
|
|
|
for (i = 0; i < (len / 2); i++) {
|
2005-11-01 17:46:19 +01:00
|
|
|
data = le16_to_cpu(readw(src + 2*i));
|
2005-04-17 00:20:36 +02:00
|
|
|
dest[i * 2] = BYTE0(data);
|
|
|
|
dest[i * 2 + 1] = BYTE1(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len & 1)
|
2005-11-01 17:46:19 +01:00
|
|
|
dest[len - 1] = BYTE0(le16_to_cpu(readw(src + 2*i)));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2005-11-07 12:15:40 +01:00
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Unaligned writes are ignored, causing the 8-bit
|
|
|
|
* probe to fail and proceed to the 16-bit probe (which succeeds).
|
|
|
|
*/
|
|
|
|
static void ixp4xx_probe_write16(struct map_info *map, map_word d, unsigned long adr)
|
|
|
|
{
|
|
|
|
if (!(adr & 1))
|
2005-11-01 17:46:19 +01:00
|
|
|
writew(cpu_to_le16(d.x[0]), map->virt + adr);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2005-11-07 12:15:40 +01:00
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Fast write16 function without the probing check above
|
|
|
|
*/
|
|
|
|
static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
|
|
|
|
{
|
2005-11-01 17:46:19 +01:00
|
|
|
writew(cpu_to_le16(d.x[0]), map->virt + adr);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ixp4xx_flash_info {
|
|
|
|
struct mtd_info *mtd;
|
|
|
|
struct map_info map;
|
|
|
|
struct mtd_partition *partitions;
|
|
|
|
struct resource *res;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
static int ixp4xx_flash_remove(struct platform_device *dev)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct flash_platform_data *plat = dev->dev.platform_data;
|
2005-11-09 23:32:44 +01:00
|
|
|
struct ixp4xx_flash_info *info = platform_get_drvdata(dev);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
platform_set_drvdata(dev, NULL);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if(!info)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (info->mtd) {
|
|
|
|
del_mtd_partitions(info->mtd);
|
|
|
|
map_destroy(info->mtd);
|
|
|
|
}
|
2005-11-01 17:46:19 +01:00
|
|
|
if (info->map.virt)
|
|
|
|
iounmap(info->map.virt);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-11-07 10:01:27 +01:00
|
|
|
kfree(info->partitions);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (info->res) {
|
|
|
|
release_resource(info->res);
|
|
|
|
kfree(info->res);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plat->exit)
|
|
|
|
plat->exit();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
static int ixp4xx_flash_probe(struct platform_device *dev)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct flash_platform_data *plat = dev->dev.platform_data;
|
|
|
|
struct ixp4xx_flash_info *info;
|
|
|
|
int err = -1;
|
|
|
|
|
|
|
|
if (!plat)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (plat->init) {
|
|
|
|
err = plat->init();
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
info = kmalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL);
|
|
|
|
if(!info) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto Error;
|
2005-11-07 12:15:40 +01:00
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
memzero(info, sizeof(struct ixp4xx_flash_info));
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
platform_set_drvdata(dev, info);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the MTD layer we're not 1:1 mapped so that it does
|
|
|
|
* not attempt to do a direct access on us.
|
|
|
|
*/
|
|
|
|
info->map.phys = NO_XIP;
|
|
|
|
info->map.size = dev->resource->end - dev->resource->start + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support 16-bit accesses for now. If and when
|
|
|
|
* any board use 8-bit access, we'll fixup the driver to
|
|
|
|
* handle that.
|
|
|
|
*/
|
|
|
|
info->map.bankwidth = 2;
|
|
|
|
info->map.name = dev->dev.bus_id;
|
|
|
|
info->map.read = ixp4xx_read16,
|
|
|
|
info->map.write = ixp4xx_probe_write16,
|
|
|
|
info->map.copy_from = ixp4xx_copy_from,
|
|
|
|
|
2005-11-07 12:15:40 +01:00
|
|
|
info->res = request_mem_region(dev->resource->start,
|
|
|
|
dev->resource->end - dev->resource->start + 1,
|
2005-04-17 00:20:36 +02:00
|
|
|
"IXP4XXFlash");
|
|
|
|
if (!info->res) {
|
|
|
|
printk(KERN_ERR "IXP4XXFlash: Could not reserve memory region\n");
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
2005-11-01 17:46:19 +01:00
|
|
|
info->map.virt = ioremap(dev->resource->start,
|
|
|
|
dev->resource->end - dev->resource->start + 1);
|
|
|
|
if (!info->map.virt) {
|
2005-04-17 00:20:36 +02:00
|
|
|
printk(KERN_ERR "IXP4XXFlash: Failed to ioremap region\n");
|
|
|
|
err = -EIO;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->mtd = do_map_probe(plat->map_name, &info->map);
|
|
|
|
if (!info->mtd) {
|
|
|
|
printk(KERN_ERR "IXP4XXFlash: map_probe failed\n");
|
|
|
|
err = -ENXIO;
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
info->mtd->owner = THIS_MODULE;
|
2005-11-07 12:15:40 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Use the fast version */
|
|
|
|
info->map.write = ixp4xx_write16,
|
|
|
|
|
|
|
|
err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
|
|
|
|
if (err > 0) {
|
|
|
|
err = add_mtd_partitions(info->mtd, info->partitions, err);
|
|
|
|
if(err)
|
|
|
|
printk(KERN_ERR "Could not parse partitions\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto Error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Error:
|
2005-11-09 23:32:44 +01:00
|
|
|
ixp4xx_flash_remove(dev);
|
2005-04-17 00:20:36 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
static struct platform_driver ixp4xx_flash_driver = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.probe = ixp4xx_flash_probe,
|
|
|
|
.remove = ixp4xx_flash_remove,
|
2005-11-09 23:32:44 +01:00
|
|
|
.driver = {
|
|
|
|
.name = "IXP4XX-Flash",
|
|
|
|
},
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ixp4xx_flash_init(void)
|
|
|
|
{
|
2005-11-09 23:32:44 +01:00
|
|
|
return platform_driver_register(&ixp4xx_flash_driver);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ixp4xx_flash_exit(void)
|
|
|
|
{
|
2005-11-09 23:32:44 +01:00
|
|
|
platform_driver_unregister(&ixp4xx_flash_driver);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(ixp4xx_flash_init);
|
|
|
|
module_exit(ixp4xx_flash_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
2005-09-29 01:42:54 +02:00
|
|
|
MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems");
|
2005-04-17 00:20:36 +02:00
|
|
|
MODULE_AUTHOR("Deepak Saxena");
|