/* linux/drivers/mtd/maps/amlm5900-flash.c * * Copyright (c) 2004-2005 Simtec Electronics * Ben Dooks <ben@simtec.co.uk> * modifications Copyright (c) 2006 American Microsystems Ltd. * David Anders <danders@amltd.com> * * AML M5900 NOR MTD Mapping driver * * Changelog: * 20-Sep-2004 BJD Initial version * * 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. * * 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. * * 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*/#include <linux/module.h>#include <linux/types.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/ioport.h>#include <linux/device.h>#include <linux/slab.h>#include <linux/platform_device.h>#include <linux/mtd/mtd.h>#include <linux/mtd/map.h>#include <linux/mtd/partitions.h>#include <asm/io.h>#include <asm/mach/flash.h>#include <asm/arch/map.h>#define AREA_MAXSIZE (16 * SZ_1M)#define PFX "amlm5900-flash: "struct amlm5900_flash_info { struct mtd_info *mtd; struct map_info map; struct mtd_partition *partitions; struct resource *area;};static int amlm5900_flash_remove(struct platform_device *pdev){ struct amlm5900_flash_info *info = platform_get_drvdata(pdev); platform_set_drvdata(pdev, NULL); if (info == NULL) return 0; if (info->map.virt != NULL) iounmap(info->map.virt); if (info->mtd) { del_mtd_partitions(info->mtd); map_destroy(info->mtd); } kfree(info->partitions); if (info->area) { release_resource(info->area); kfree(info->area); } kfree(info); return 0;}static int amlm5900_flash_probe(struct platform_device *pdev){ struct amlm5900_flash_info *info; struct resource *res; struct flash_platform_data *partitions; int err = 0; info = kmalloc(sizeof(*info), GFP_KERNEL); if (info == NULL) { printk(KERN_ERR PFX "no memory for flash info\n"); err = -ENOMEM; goto exit_error; } memzero(info, sizeof(*info)); platform_set_drvdata(pdev, info); res = pdev->resource; /* assume that the flash has one resource */ partitions= pdev->dev.platform_data; info->map.phys = res->start; info->map.size = res->end - res->start + 1; info->map.name = pdev->dev.bus_id; info->map.bankwidth = 2; info->partitions = partitions->parts; if (info->map.size > AREA_MAXSIZE) info->map.size = AREA_MAXSIZE; pr_debug("%s: area %08lx, size %ld\n", __FUNCTION__, info->map.phys, info->map.size); info->area = request_mem_region(res->start, info->map.size, pdev->name); if (info->area == NULL) { printk(KERN_ERR PFX "cannot reserve flash memory region\n"); err = -ENOENT; goto exit_error; } info->map.virt = ioremap(res->start, info->map.size); pr_debug("%s: virt at %08x\n", __FUNCTION__, (int)info->map.virt); if (info->map.virt == 0) { printk(KERN_ERR PFX "failed to ioremap() region\n"); err = -EIO; goto exit_error; } simple_map_init(&info->map); /* probe for the device(s) */ info->mtd = do_map_probe("cfi_probe", &info->map); if (info->mtd == NULL) { printk(KERN_ERR PFX "map_probe() failed\n"); err = -ENXIO; goto exit_error; } /* mark ourselves as the owner */ info->mtd->owner = THIS_MODULE; err = add_mtd_partitions(info->mtd, info->partitions , partitions->nr_parts); if (err) printk(KERN_ERR PFX "cannot add/parse partitions\n"); if (err == 0) return 0; /* fall through to exit error */ exit_error: amlm5900_flash_remove(pdev); return err;}#ifdef CONFIG_PMstatic int amlm5900_mtd_suspend(struct platform_device *dev, pm_message_t state){ struct amlm5900_flash_info *info = platform_get_drvdata(dev); int ret = 0; if (info) ret = info->mtd->suspend(info->mtd); return ret;}static int amlm5900_mtd_resume(struct platform_device *dev){ struct amlm5900_flash_info *info = platform_get_drvdata(dev); if (info) info->mtd->resume(info->mtd); return 0;}static void amlm5900_mtd_shutdown(struct platform_device *dev){ struct amlm5900_flash_info *info = platform_get_drvdata(dev); if (info && info->mtd->suspend(info->mtd) == 0) info->mtd->resume(info->mtd);}#else#define amlm5900_mtd_suspend NULL#define amlm5900_mtd_resume NULL#define amlm5900_mtd_shutdown NULL#endifstatic struct platform_driver amlm5900_flash_driver = { .probe = amlm5900_flash_probe, .remove = amlm5900_flash_remove, .suspend = amlm5900_mtd_suspend, .resume = amlm5900_mtd_resume, .shutdown = amlm5900_mtd_shutdown, .driver = { .name = "amlm5900-nor", .owner = THIS_MODULE, },};static int __init amlm5900_flash_init(void){ printk("AML M5900 NOR-Flash Driver\n"); return platform_driver_register(&amlm5900_flash_driver);}static void __exit amlm5900_flash_exit(void){ platform_driver_unregister(&amlm5900_flash_driver);}module_init(amlm5900_flash_init);module_exit(amlm5900_flash_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("David Anders <danders@amltd.com>");MODULE_DESCRIPTION("AML M5900 MTD Map driver");