| mtd-ram1.patch | | Files affected: | drivers/mtd/maps/Kconfig | 8 8 + 0 - 0 ! | drivers/mtd/maps/Makefile | 1 1 + 0 - 0 ! | drivers/mtd/maps/plat-ram.c | 242 242 + 0 - 0 ! | include/linux/mtd/plat-ram.h | 29 29 + 0 - 0 ! | 4 files changed, 280 insertions(+) | | Ben Dooks, Mon, 22 Nov 2004 12:49:08 +0000 diff -urN -X ../dontdiff linux-2.6.10-rc2-bk6/include/linux/mtd/plat-ram.h linux-2.6.10-rc2-bk6-thcom1/include/linux/mtd/plat-ram.h --- linux-2.6.10-rc2-bk6/include/linux/mtd/plat-ram.h 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.10-rc2-bk6-thcom1/include/linux/mtd/plat-ram.h 2004-11-22 11:58:11.000000000 +0000 @@ -0,0 +1,29 @@ +/* linux/include/mtd/plat-ram.h + * + * (c) 2004 Simtec Electronics + * Ben Dooks + * + * Generic platform device based RAM map + * + * 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. + * + */ + +#ifndef __LINUX_MTD_PLATRAM_H +#define __LINUX_MTD_PLATRAM_H __FILE__ + +struct platdata_mtd_ram { + char *mapname; + char **probes; + struct mtd_partition *partitions; + int nr_partitions; + int bankwidth; + + /* control callbacks */ + + int (*set_rw)(struct device *dev, int to); +}; + +#endif /* __LINUX_MTD_PLATRAM_H */ diff -urN -X ../dontdiff linux-2.6.10-rc2-bk6/drivers/mtd/maps/Kconfig linux-2.6.10-rc2-bk6-thcom1/drivers/mtd/maps/Kconfig --- linux-2.6.10-rc2-bk6/drivers/mtd/maps/Kconfig 2004-11-15 11:12:01.000000000 +0000 +++ linux-2.6.10-rc2-bk6-thcom1/drivers/mtd/maps/Kconfig 2004-11-22 12:33:39.000000000 +0000 @@ -645,5 +645,13 @@ depends on MTD_BAST default "4" +config MTD_PLATRAM + tristate "Map driver for platfrom device RAM (mtd-ram)" + depends on MTD + select MTD_PARTITIONS + help + Map driver for RAM areas described via the platform device + system. + endmenu diff -urN -X ../dontdiff linux-2.6.10-rc2-bk6/drivers/mtd/maps/Makefile linux-2.6.10-rc2-bk6-thcom1/drivers/mtd/maps/Makefile --- linux-2.6.10-rc2-bk6/drivers/mtd/maps/Makefile 2004-11-15 11:12:01.000000000 +0000 +++ linux-2.6.10-rc2-bk6-thcom1/drivers/mtd/maps/Makefile 2004-11-22 12:34:28.000000000 +0000 @@ -69,3 +69,4 @@ obj-$(CONFIG_MTD_IXP2000) += ixp2000.o obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o obj-$(CONFIG_MTD_DMV182) += dmv182.o +obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o diff -urN -X ../dontdiff linux-2.6.10-rc2-bk6/drivers/mtd/maps/plat-ram.c linux-2.6.10-rc2-bk6-thcom1/drivers/mtd/maps/plat-ram.c --- linux-2.6.10-rc2-bk6/drivers/mtd/maps/plat-ram.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.10-rc2-bk6-thcom1/drivers/mtd/maps/plat-ram.c 2004-11-22 12:47:19.000000000 +0000 @@ -0,0 +1,242 @@ +/* drivers/mtd/maps/plat-ram.c + * + * (c) 2004 Simtec Electronics + * http://www.simtec.co.uk/products/SWLINUX/ + * Ben Dooks + * + * Generic platfrom device based RAM map + * + * $Id: $ + * + * 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + + + +struct platram_info { + struct device *dev; + struct mtd_info *mtd; + struct map_info map; + struct mtd_partition *partitions; + struct resource *area; + struct platdata_mtd_ram *pdata; +}; + +static struct platram_info *to_platram_info(struct device *dev) +{ + return (struct platram_info *)dev_get_drvdata(dev); +} + +static void platram_setrw(struct platram_info *info, int to) +{ + if (info->pdata == NULL) + return; + + if (info->pdata->set_rw != NULL) + (info->pdata->set_rw)(info->dev, to); +} + +static int platram_remove(struct device *dev) +{ + struct platram_info *info = to_platram_info(dev); + + dev_set_drvdata(dev, NULL); + + platram_setrw(info, 0); + + 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); + } + + if (info->partitions) + kfree(info->partitions); + + if (info->area) { + release_resource(info->area); + kfree(info->area); + } + + kfree(info); + + return 0; +} + +static int platram_probe(struct device *dev) +{ + struct platform_device *pd = to_platform_device(dev); + struct platdata_mtd_ram *pdata; + struct platram_info *info; + struct resource *res; + int err = 0; + + dev_dbg(dev, "probe entered\n"); + + if (dev->platform_data == NULL) { + dev_err(dev, "no platform data supplied\n"); + err = -ENOENT; + goto exit_error; + } + + pdata = dev->platform_data; + + info = kmalloc(sizeof(*info), GFP_KERNEL); + if (info == NULL) { + dev_err(dev, "no memory for flash info\n"); + err = -ENOMEM; + goto exit_error; + } + + memzero(info, sizeof(*info)); + dev_set_drvdata(dev, info); + + info->dev = dev; + info->pdata = pdata; + + /* get the resource for the memory mapping */ + + res = platform_get_resource(pd, IORESOURCE_MEM, 0); + + if (res == NULL) { + dev_err(dev, "no memory resource specified\n"); + err = -ENOENT; + goto exit_free; + } + + dev_dbg(dev, "got platform resource %p\n", res); + + /* setup map parameters */ + + info->map.phys = res->start; + info->map.size = (res->end - res->start) + 1; + info->map.name = pdata->mapname != NULL ? pdata->mapname : pd->name; + info->map.bankwidth = pdata->bankwidth; + + /* register our usage of the memory area */ + + info->area = request_mem_region(res->start, info->map.size, pd->name); + if (info->area == NULL) { + dev_err(dev, "failed to request flash region\n"); + err = -EIO; + goto exit_free; + } + + /* remap the memory area */ + + info->map.virt = ioremap(res->start, info->map.size); + dev_dbg(dev, "virt %p, %d bytes\n", info->map.virt, info->map.size); + + if (info->map.virt == NULL) { + dev_err(dev, "failed to ioremap() region\n"); + err = -EIO; + goto exit_free; + } + + simple_map_init(&info->map); + + /* probe for the right mtd map driver */ + + info->mtd = do_map_probe("map_ram" , &info->map); + if (info->mtd == NULL) { + dev_err(dev, "failed to probe for map_ram\n"); + err = -ENOMEM; + goto exit_free; + } + + info->mtd->owner = THIS_MODULE; + info->mtd->erasesize = pdata->bankwidth; + + platram_setrw(info, 1); + + /* check to see if there are any available partitions, or wether + * to add this device whole */ + + if (pdata->nr_partitions <= 0) { + if (add_mtd_device(info->mtd)) { + dev_err(dev, "add_mtd_device() failed\n"); + err = -ENOMEM; + } + } else { + char **probes = { NULL }; + + if (pdata->probes) + probes = pdata->probes; + + err = parse_mtd_partitions(info->mtd, probes, + &info->partitions, 0); + if (err > 0) { + err = add_mtd_partitions(info->mtd, info->partitions, + err); + } + } + + dev_info(dev, "registered mtd device\n"); + return err; + + exit_free: + platram_remove(dev); + exit_error: + return err; +} + +/* device driver info */ + +static struct device_driver platram_driver = { + .name = "mtd-ram", + .bus = &platform_bus_type, + .probe = platram_probe, + .remove = platram_remove, +}; + +/* module init/exit */ + +static int __init platram_init(void) +{ + printk("Generic platform RAM MTD, (c) 2004 Simtec Electronics\n"); + return driver_register(&platram_driver); +} + +static void __exit platram_exit(void) +{ + driver_unregister(&platram_driver); +} + +module_init(platram_init); +module_exit(platram_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Ben Dooks "); +MODULE_DESCRIPTION("MTD platform RAM map driver");