From patchwork Fri Feb 20 16:15:12 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 23556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1C5BDDDE31 for ; Mon, 23 Feb 2009 21:58:12 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1LbYUK-0000o0-0j; Mon, 23 Feb 2009 10:56:40 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.69 #1 (Red Hat Linux)) id 1LaY20-0001qU-Lc for linux-mtd@lists.infradead.org; Fri, 20 Feb 2009 16:15:19 +0000 Received: from [2001:6f8:1178:2:221:70ff:fe71:1890] (helo=localhost) by metis.ext.pengutronix.de with esmtp (Exim 4.63) (envelope-from ) id 1LaY1w-0006lU-OO; Fri, 20 Feb 2009 17:15:12 +0100 From: Wolfram Sang To: linux-mtd@lists.infradead.org Subject: [PATCH 2/2] maps/mtd-ram: add an of-platform driver Date: Fri, 20 Feb 2009 17:15:12 +0100 Message-Id: <1235146512-15170-3-git-send-email-w.sang@pengutronix.de> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1235146512-15170-1-git-send-email-w.sang@pengutronix.de> References: <1235146512-15170-1-git-send-email-w.sang@pengutronix.de> X-SA-Exim-Connect-IP: 2001:6f8:1178:2:221:70ff:fe71:1890 X-SA-Exim-Mail-From: w.sang@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mtd@lists.infradead.org X-Bad-Reply: References and In-Reply-To but no 'Re:' in Subject. X-Spam-Score: -0.0 (/) X-Mailman-Approved-At: Mon, 23 Feb 2009 05:56:38 -0500 Cc: dwmw2@infradead.org, Wolfram Sang , ben-linux@fluff.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Create an of-aware driver using the now exported generic functions from plat-ram.c. A typical oftree snipplet for it looks like this: sram@04e00000 { compatible = "mtd-ram"; reg = <0x04e00000 0x00200000>; bank-width = <2>; }; Partitions on this device are not yet supported. Tested on a phyCORE-MPC5200B-IO. Signed-off-by: Wolfram Sang --- drivers/mtd/maps/Kconfig | 6 ++ drivers/mtd/maps/Makefile | 1 + drivers/mtd/maps/of-ram.c | 120 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/maps/of-ram.c diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index 0225cbb..b238b6d 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig @@ -551,5 +551,11 @@ config MTD_PLATRAM This selection automatically selects the map_ram driver. +config MTD_OFRAM + tristate "Map driver for of-device RAM (mtd-ram)" + depends on MTD_PLATRAM && OF + help + Map driver for RAM areas described via the of-device + system. endmenu diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index 6d9ba35..f8e3908 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile @@ -58,6 +58,7 @@ obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o obj-$(CONFIG_MTD_DMV182) += dmv182.o obj-$(CONFIG_MTD_SHARP_SL) += sharpsl-flash.o obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o +obj-$(CONFIG_MTD_OFRAM) += of-ram.o obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o diff --git a/drivers/mtd/maps/of-ram.c b/drivers/mtd/maps/of-ram.c new file mode 100644 index 0000000..4d334a9 --- /dev/null +++ b/drivers/mtd/maps/of-ram.c @@ -0,0 +1,120 @@ +/* + * drivers/mtd/maps/of-ram.c + * + * Generic of device based RAM map + * + * Copyright (C) 2009 Wolfram Sang, Pengutronix + * + * Using plat-ram.c by Ben Dooks + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +static int of_ram_probe(struct of_device *op, const struct of_device_id *match) +{ + struct platdata_mtd_ram *pdata; + struct resource *resource; + const char *name; + const u32 *bankwidth; + int ret = -ENOMEM; + + pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); + if (!pdata) + goto bad0; + op->dev.platform_data = pdata; + + name = of_get_property(op->node, "name", NULL); + if (!name) { + ret = -ENOENT; + dev_dbg(&op->dev, "could not get node name\n"); + goto bad1; + } + + resource = kzalloc(sizeof(struct resource), GFP_KERNEL); + if (!resource) + goto bad1; + + if (of_address_to_resource(op->node, 0, resource)) { + ret = -ENXIO; + dev_dbg(&op->dev, "could not create resource\n"); + goto bad2; + } + + bankwidth = of_get_property(op->node, "bank-width", NULL); + if (*bankwidth == 0) { + ret = -ENOENT; + dev_dbg(&op->dev, "bank width not set\n"); + goto bad2; + } + pdata->bankwidth = *bankwidth; + + ret = __platram_probe(&op->dev, name, resource, pdata); + kfree(resource); + + if (ret) + goto bad1; + + return 0; + + bad2: + kfree(resource); + bad1: + op->dev.platform_data = NULL; + kfree(pdata); + bad0: + return ret; +} + +static int of_ram_remove(struct of_device *op) +{ + int ret; + struct platdata_mtd_ram *pdata = op->dev.platform_data; + + ret = __platram_remove(&op->dev); + op->dev.platform_data = NULL; + kfree(pdata); + return ret; +} + +static struct of_device_id of_ram_match[] = { + { .compatible = "mtd-ram", }, + {}, +}; +MODULE_DEVICE_TABLE(of, of_ram_match); + +static struct of_platform_driver of_ram_driver = { + .owner = THIS_MODULE, + .name = "of-ram", + .match_table = of_ram_match, + .probe = of_ram_probe, + .remove = of_ram_remove, +}; + +static int __init of_ram_init(void) +{ + return of_register_platform_driver(&of_ram_driver); +} + +static void __exit of_ram_exit(void) +{ + of_unregister_platform_driver(&of_ram_driver); +} + +module_init(of_ram_init); +module_exit(of_ram_exit); + +MODULE_AUTHOR("Wolfram Sang"); +MODULE_DESCRIPTION("MTD OF RAM map driver"); +MODULE_LICENSE("GPL v2");