linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* mtd-ram: add of-support
@ 2009-01-21 17:41 Wolfram Sang
  2009-01-21 17:41 ` [PATCH 1/2] maps/mtd-ram: refactor probe and remove Wolfram Sang
  2009-01-21 17:41 ` [PATCH 2/2] maps/mtd-ram: add an of-platform driver Wolfram Sang
  0 siblings, 2 replies; 10+ messages in thread
From: Wolfram Sang @ 2009-01-21 17:41 UTC (permalink / raw)
  To: linux-mtd; +Cc: linuxppc-dev, ben-linux

Hello,

as we needed an of-mtd-ram driver to support SRAM on the
phyCORE-MPC5200B-IO, I did the following:

Patch 1:
  refactor plat-ram.c to have generic probe and remove
  routines

Patch 2:
  use the new routines for an of-driver

Looking forward to comments. (Sidenote: Converting all these platform
drivers to support of is really tiring, sigh. Isn't there any other
way?)

Kind regards,

   Wolfram

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] maps/mtd-ram: refactor probe and remove
  2009-01-21 17:41 mtd-ram: add of-support Wolfram Sang
@ 2009-01-21 17:41 ` Wolfram Sang
  2009-05-19 14:41   ` Grant Likely
  2009-01-21 17:41 ` [PATCH 2/2] maps/mtd-ram: add an of-platform driver Wolfram Sang
  1 sibling, 1 reply; 10+ messages in thread
From: Wolfram Sang @ 2009-01-21 17:41 UTC (permalink / raw)
  To: linux-mtd; +Cc: linuxppc-dev, ben-linux

Refactor the probe and remove routines of the mtd-ram driver to export
a generic part which can later be accessed by an of-counterpart of this
driver. Tested with a phyCORE-MPC5200B-IO.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/mtd/maps/plat-ram.c  |  123 +++++++++++++++++++++---------------------
 include/linux/mtd/plat-ram.h |    4 ++
 2 files changed, 66 insertions(+), 61 deletions(-)

diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index e7dd9c8..1582cd6 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -50,16 +50,6 @@ struct platram_info {
 	struct platdata_mtd_ram	*pdata;
 };
 
-/* to_platram_info()
- *
- * device private data to struct platram_info conversion
-*/
-
-static inline struct platram_info *to_platram_info(struct platform_device *dev)
-{
-	return (struct platram_info *)platform_get_drvdata(dev);
-}
-
 /* platram_setrw
  *
  * call the platform device's set rw/ro control
@@ -77,18 +67,14 @@ static inline void platram_setrw(struct platram_info *info, int to)
 		(info->pdata->set_rw)(info->dev, to);
 }
 
-/* platram_remove
- *
- * called to remove the device from the driver's control
-*/
-
-static int platram_remove(struct platform_device *pdev)
+int __platram_remove(struct device *dev)
 {
-	struct platram_info *info = to_platram_info(pdev);
+	struct platram_info *info;
 
-	platform_set_drvdata(pdev, NULL);
+	dev_dbg(dev, "removing device\n");
 
-	dev_dbg(&pdev->dev, "removing device\n");
+	info = dev_get_drvdata(dev);
+	dev_set_drvdata(dev, NULL);
 
 	if (info == NULL)
 		return 0;
@@ -123,68 +109,49 @@ static int platram_remove(struct platform_device *pdev)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(__platram_remove);
 
-/* platram_probe
+/* platram_remove
  *
- * called from device drive system when a device matching our
- * driver is found.
+ * called to remove the device from the driver's control
 */
 
-static int platram_probe(struct platform_device *pdev)
+static int platram_remove(struct platform_device *pdev)
+{
+	return __platram_remove(&pdev->dev);
+}
+
+int __platram_probe(struct device *dev, const char *name,
+			struct resource *res, struct platdata_mtd_ram *pdata)
 {
-	struct platdata_mtd_ram	*pdata;
 	struct platram_info *info;
-	struct resource *res;
 	int err = 0;
 
-	dev_dbg(&pdev->dev, "probe entered\n");
-
-	if (pdev->dev.platform_data == NULL) {
-		dev_err(&pdev->dev, "no platform data supplied\n");
-		err = -ENOENT;
-		goto exit_error;
-	}
-
-	pdata = pdev->dev.platform_data;
-
 	info = kzalloc(sizeof(*info), GFP_KERNEL);
 	if (info == NULL) {
-		dev_err(&pdev->dev, "no memory for flash info\n");
+		dev_err(dev, "no memory for flash info\n");
 		err = -ENOMEM;
 		goto exit_error;
 	}
 
-	platform_set_drvdata(pdev, info);
+	dev_set_drvdata(dev, info);
 
-	info->dev = &pdev->dev;
+	info->dev = dev;
 	info->pdata = pdata;
 
-	/* get the resource for the memory mapping */
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
-	if (res == NULL) {
-		dev_err(&pdev->dev, "no memory resource specified\n");
-		err = -ENOENT;
-		goto exit_free;
-	}
-
-	dev_dbg(&pdev->dev, "got platform resource %p (0x%llx)\n", res,
-		(unsigned long long)res->start);
-
 	/* setup map parameters */
 
 	info->map.phys = res->start;
 	info->map.size = (res->end - res->start) + 1;
 	info->map.name = pdata->mapname != NULL ?
-			(char *)pdata->mapname : (char *)pdev->name;
+			(char *)pdata->mapname : (char *)name;
 	info->map.bankwidth = pdata->bankwidth;
 
 	/* register our usage of the memory area */
 
-	info->area = request_mem_region(res->start, info->map.size, pdev->name);
+	info->area = request_mem_region(res->start, info->map.size, name);
 	if (info->area == NULL) {
-		dev_err(&pdev->dev, "failed to request memory region\n");
+		dev_err(dev, "failed to request memory region\n");
 		err = -EIO;
 		goto exit_free;
 	}
@@ -192,17 +159,17 @@ static int platram_probe(struct platform_device *pdev)
 	/* remap the memory area */
 
 	info->map.virt = ioremap(res->start, info->map.size);
-	dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size);
+	dev_dbg(dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size);
 
 	if (info->map.virt == NULL) {
-		dev_err(&pdev->dev, "failed to ioremap() region\n");
+		dev_err(dev, "failed to ioremap() region\n");
 		err = -EIO;
 		goto exit_free;
 	}
 
 	simple_map_init(&info->map);
 
-	dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");
+	dev_dbg(dev, "initialised map, probing for mtd\n");
 
 	/* probe for the right mtd map driver
 	 * supplied by the platform_data struct */
@@ -218,7 +185,7 @@ static int platram_probe(struct platform_device *pdev)
 		info->mtd = do_map_probe("map_ram", &info->map);
 
 	if (info->mtd == NULL) {
-		dev_err(&pdev->dev, "failed to probe for map_ram\n");
+		dev_err(dev, "failed to probe for map_ram\n");
 		err = -ENOMEM;
 		goto exit_free;
 	}
@@ -249,20 +216,54 @@ static int platram_probe(struct platform_device *pdev)
 #endif /* CONFIG_MTD_PARTITIONS */
 
 	if (add_mtd_device(info->mtd)) {
-		dev_err(&pdev->dev, "add_mtd_device() failed\n");
+		dev_err(dev, "add_mtd_device() failed\n");
 		err = -ENOMEM;
 	}
 
 	if (!err)
-		dev_info(&pdev->dev, "registered mtd device\n");
+		dev_info(dev, "registered mtd device\n");
 
 	return err;
 
  exit_free:
-	platram_remove(pdev);
+	__platram_remove(dev);
  exit_error:
 	return err;
 }
+EXPORT_SYMBOL_GPL(__platram_probe);
+
+/* platram_probe
+ *
+ * called from device drive system when a device matching our
+ * driver is found.
+*/
+
+static int platram_probe(struct platform_device *pdev)
+{
+	struct platdata_mtd_ram	*pdata;
+	struct resource *res;
+
+	dev_dbg(&pdev->dev, "probe entered\n");
+
+	pdata = pdev->dev.platform_data;
+	if (pdata == NULL) {
+		dev_err(&pdev->dev, "no platform data supplied\n");
+		return -ENOENT;
+	}
+
+	/* get the resource for the memory mapping */
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (res == NULL) {
+		dev_err(&pdev->dev, "no memory resource specified\n");
+		return -ENOENT;
+	}
+
+	dev_dbg(&pdev->dev, "got platform resource %p (0x%llx)\n", res,
+		(unsigned long long)res->start);
+
+	return __platram_probe(&pdev->dev, pdev->name, res, pdata);
+}
 
 /* device driver info */
 
diff --git a/include/linux/mtd/plat-ram.h b/include/linux/mtd/plat-ram.h
index e07890a..c522562 100644
--- a/include/linux/mtd/plat-ram.h
+++ b/include/linux/mtd/plat-ram.h
@@ -31,4 +31,8 @@ struct platdata_mtd_ram {
 	void	(*set_rw)(struct device *dev, int to);
 };
 
+extern int __platram_probe(struct device *dev, const char *name,
+			struct resource *res, struct platdata_mtd_ram *pdata);
+extern int __platram_remove(struct device *dev);
+
 #endif /* __LINUX_MTD_PLATRAM_H */
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] maps/mtd-ram: add an of-platform driver
  2009-01-21 17:41 mtd-ram: add of-support Wolfram Sang
  2009-01-21 17:41 ` [PATCH 1/2] maps/mtd-ram: refactor probe and remove Wolfram Sang
@ 2009-01-21 17:41 ` Wolfram Sang
  2009-01-24 22:30   ` Wolfram Sang
  2009-05-19 14:57   ` Grant Likely
  1 sibling, 2 replies; 10+ messages in thread
From: Wolfram Sang @ 2009-01-21 17:41 UTC (permalink / raw)
  To: linux-mtd; +Cc: linuxppc-dev, ben-linux

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.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 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 <linux/module.h>
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/mtd/plat-ram.h>
+
+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");
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] maps/mtd-ram: add an of-platform driver
  2009-01-21 17:41 ` [PATCH 2/2] maps/mtd-ram: add an of-platform driver Wolfram Sang
@ 2009-01-24 22:30   ` Wolfram Sang
  2009-05-19 14:57   ` Grant Likely
  1 sibling, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2009-01-24 22:30 UTC (permalink / raw)
  To: linux-mtd; +Cc: linuxppc-dev, ben-linux

[-- Attachment #1: Type: text/plain, Size: 5379 bytes --]

Hello,

found one question thing myself...

On Wed, Jan 21, 2009 at 06:41:25PM +0100, Wolfram Sang wrote:
> 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.
> 
> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
> ---
>  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 <linux/module.h>
> +#include <linux/types.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/device.h>
> +#include <linux/platform_device.h>
> +#include <linux/of_device.h>
> +#include <linux/of_platform.h>
> +#include <linux/mtd/plat-ram.h>
> +
> +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);

As this pointer gets passed on and used, I must probably add something
like of_node_get(op->node) here and put the node later in the remove
function? Not 100% sure, though...

> +	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");
> -- 
> 1.5.6.5
> 

-- 
  Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] maps/mtd-ram: refactor probe and remove
  2009-01-21 17:41 ` [PATCH 1/2] maps/mtd-ram: refactor probe and remove Wolfram Sang
@ 2009-05-19 14:41   ` Grant Likely
  0 siblings, 0 replies; 10+ messages in thread
From: Grant Likely @ 2009-05-19 14:41 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linuxppc-dev, linux-mtd, ben-linux

On Wed, Jan 21, 2009 at 11:41 AM, Wolfram Sang <w.sang@pengutronix.de> wrot=
e:
> Refactor the probe and remove routines of the mtd-ram driver to export
> a generic part which can later be accessed by an of-counterpart of this
> driver. Tested with a phyCORE-MPC5200B-IO.
>
> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>

On brief review, looks okay by me.

Acked-by: Grant Likely <grant.likely@secretlab.ca>

> ---
> =A0drivers/mtd/maps/plat-ram.c =A0| =A0123 +++++++++++++++++++++---------=
------------
> =A0include/linux/mtd/plat-ram.h | =A0 =A04 ++
> =A02 files changed, 66 insertions(+), 61 deletions(-)
>
> diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
> index e7dd9c8..1582cd6 100644
> --- a/drivers/mtd/maps/plat-ram.c
> +++ b/drivers/mtd/maps/plat-ram.c
> @@ -50,16 +50,6 @@ struct platram_info {
> =A0 =A0 =A0 =A0struct platdata_mtd_ram *pdata;
> =A0};
>
> -/* to_platram_info()
> - *
> - * device private data to struct platram_info conversion
> -*/
> -
> -static inline struct platram_info *to_platram_info(struct platform_devic=
e *dev)
> -{
> - =A0 =A0 =A0 return (struct platram_info *)platform_get_drvdata(dev);
> -}
> -
> =A0/* platram_setrw
> =A0*
> =A0* call the platform device's set rw/ro control
> @@ -77,18 +67,14 @@ static inline void platram_setrw(struct platram_info =
*info, int to)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(info->pdata->set_rw)(info->dev, to);
> =A0}
>
> -/* platram_remove
> - *
> - * called to remove the device from the driver's control
> -*/
> -
> -static int platram_remove(struct platform_device *pdev)
> +int __platram_remove(struct device *dev)
> =A0{
> - =A0 =A0 =A0 struct platram_info *info =3D to_platram_info(pdev);
> + =A0 =A0 =A0 struct platram_info *info;
>
> - =A0 =A0 =A0 platform_set_drvdata(pdev, NULL);
> + =A0 =A0 =A0 dev_dbg(dev, "removing device\n");
>
> - =A0 =A0 =A0 dev_dbg(&pdev->dev, "removing device\n");
> + =A0 =A0 =A0 info =3D dev_get_drvdata(dev);
> + =A0 =A0 =A0 dev_set_drvdata(dev, NULL);
>
> =A0 =A0 =A0 =A0if (info =3D=3D NULL)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return 0;
> @@ -123,68 +109,49 @@ static int platram_remove(struct platform_device *p=
dev)
>
> =A0 =A0 =A0 =A0return 0;
> =A0}
> +EXPORT_SYMBOL_GPL(__platram_remove);
>
> -/* platram_probe
> +/* platram_remove
> =A0*
> - * called from device drive system when a device matching our
> - * driver is found.
> + * called to remove the device from the driver's control
> =A0*/
>
> -static int platram_probe(struct platform_device *pdev)
> +static int platram_remove(struct platform_device *pdev)
> +{
> + =A0 =A0 =A0 return __platram_remove(&pdev->dev);
> +}
> +
> +int __platram_probe(struct device *dev, const char *name,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct resource *res, struc=
t platdata_mtd_ram *pdata)
> =A0{
> - =A0 =A0 =A0 struct platdata_mtd_ram *pdata;
> =A0 =A0 =A0 =A0struct platram_info *info;
> - =A0 =A0 =A0 struct resource *res;
> =A0 =A0 =A0 =A0int err =3D 0;
>
> - =A0 =A0 =A0 dev_dbg(&pdev->dev, "probe entered\n");
> -
> - =A0 =A0 =A0 if (pdev->dev.platform_data =3D=3D NULL) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "no platform data suppl=
ied\n");
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -ENOENT;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto exit_error;
> - =A0 =A0 =A0 }
> -
> - =A0 =A0 =A0 pdata =3D pdev->dev.platform_data;
> -
> =A0 =A0 =A0 =A0info =3D kzalloc(sizeof(*info), GFP_KERNEL);
> =A0 =A0 =A0 =A0if (info =3D=3D NULL) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "no memory for flash in=
fo\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "no memory for flash info\n");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -ENOMEM;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto exit_error;
> =A0 =A0 =A0 =A0}
>
> - =A0 =A0 =A0 platform_set_drvdata(pdev, info);
> + =A0 =A0 =A0 dev_set_drvdata(dev, info);
>
> - =A0 =A0 =A0 info->dev =3D &pdev->dev;
> + =A0 =A0 =A0 info->dev =3D dev;
> =A0 =A0 =A0 =A0info->pdata =3D pdata;
>
> - =A0 =A0 =A0 /* get the resource for the memory mapping */
> -
> - =A0 =A0 =A0 res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -
> - =A0 =A0 =A0 if (res =3D=3D NULL) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "no memory resource spe=
cified\n");
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -ENOENT;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto exit_free;
> - =A0 =A0 =A0 }
> -
> - =A0 =A0 =A0 dev_dbg(&pdev->dev, "got platform resource %p (0x%llx)\n", =
res,
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 (unsigned long long)res->start);
> -
> =A0 =A0 =A0 =A0/* setup map parameters */
>
> =A0 =A0 =A0 =A0info->map.phys =3D res->start;
> =A0 =A0 =A0 =A0info->map.size =3D (res->end - res->start) + 1;
> =A0 =A0 =A0 =A0info->map.name =3D pdata->mapname !=3D NULL ?
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (char *)pdata->mapname : (c=
har *)pdev->name;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (char *)pdata->mapname : (c=
har *)name;
> =A0 =A0 =A0 =A0info->map.bankwidth =3D pdata->bankwidth;
>
> =A0 =A0 =A0 =A0/* register our usage of the memory area */
>
> - =A0 =A0 =A0 info->area =3D request_mem_region(res->start, info->map.siz=
e, pdev->name);
> + =A0 =A0 =A0 info->area =3D request_mem_region(res->start, info->map.siz=
e, name);
> =A0 =A0 =A0 =A0if (info->area =3D=3D NULL) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "failed to request memo=
ry region\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "failed to request memory regi=
on\n");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -EIO;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto exit_free;
> =A0 =A0 =A0 =A0}
> @@ -192,17 +159,17 @@ static int platram_probe(struct platform_device *pd=
ev)
> =A0 =A0 =A0 =A0/* remap the memory area */
>
> =A0 =A0 =A0 =A0info->map.virt =3D ioremap(res->start, info->map.size);
> - =A0 =A0 =A0 dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt,=
 info->map.size);
> + =A0 =A0 =A0 dev_dbg(dev, "virt %p, %lu bytes\n", info->map.virt, info->=
map.size);
>
> =A0 =A0 =A0 =A0if (info->map.virt =3D=3D NULL) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "failed to ioremap() re=
gion\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "failed to ioremap() region\n"=
);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -EIO;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto exit_free;
> =A0 =A0 =A0 =A0}
>
> =A0 =A0 =A0 =A0simple_map_init(&info->map);
>
> - =A0 =A0 =A0 dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");
> + =A0 =A0 =A0 dev_dbg(dev, "initialised map, probing for mtd\n");
>
> =A0 =A0 =A0 =A0/* probe for the right mtd map driver
> =A0 =A0 =A0 =A0 * supplied by the platform_data struct */
> @@ -218,7 +185,7 @@ static int platram_probe(struct platform_device *pdev=
)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0info->mtd =3D do_map_probe("map_ram", &inf=
o->map);
>
> =A0 =A0 =A0 =A0if (info->mtd =3D=3D NULL) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "failed to probe for ma=
p_ram\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "failed to probe for map_ram\n=
");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -ENOMEM;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto exit_free;
> =A0 =A0 =A0 =A0}
> @@ -249,20 +216,54 @@ static int platram_probe(struct platform_device *pd=
ev)
> =A0#endif /* CONFIG_MTD_PARTITIONS */
>
> =A0 =A0 =A0 =A0if (add_mtd_device(info->mtd)) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "add_mtd_device() faile=
d\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "add_mtd_device() failed\n");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -ENOMEM;
> =A0 =A0 =A0 =A0}
>
> =A0 =A0 =A0 =A0if (!err)
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_info(&pdev->dev, "registered mtd device=
\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_info(dev, "registered mtd device\n");
>
> =A0 =A0 =A0 =A0return err;
>
> =A0exit_free:
> - =A0 =A0 =A0 platram_remove(pdev);
> + =A0 =A0 =A0 __platram_remove(dev);
> =A0exit_error:
> =A0 =A0 =A0 =A0return err;
> =A0}
> +EXPORT_SYMBOL_GPL(__platram_probe);
> +
> +/* platram_probe
> + *
> + * called from device drive system when a device matching our
> + * driver is found.
> +*/
> +
> +static int platram_probe(struct platform_device *pdev)
> +{
> + =A0 =A0 =A0 struct platdata_mtd_ram *pdata;
> + =A0 =A0 =A0 struct resource *res;
> +
> + =A0 =A0 =A0 dev_dbg(&pdev->dev, "probe entered\n");
> +
> + =A0 =A0 =A0 pdata =3D pdev->dev.platform_data;
> + =A0 =A0 =A0 if (pdata =3D=3D NULL) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "no platform data suppl=
ied\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOENT;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /* get the resource for the memory mapping */
> +
> + =A0 =A0 =A0 res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + =A0 =A0 =A0 if (res =3D=3D NULL) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&pdev->dev, "no memory resource spe=
cified\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOENT;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 dev_dbg(&pdev->dev, "got platform resource %p (0x%llx)\n", =
res,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 (unsigned long long)res->start);
> +
> + =A0 =A0 =A0 return __platram_probe(&pdev->dev, pdev->name, res, pdata);
> +}
>
> =A0/* device driver info */
>
> diff --git a/include/linux/mtd/plat-ram.h b/include/linux/mtd/plat-ram.h
> index e07890a..c522562 100644
> --- a/include/linux/mtd/plat-ram.h
> +++ b/include/linux/mtd/plat-ram.h
> @@ -31,4 +31,8 @@ struct platdata_mtd_ram {
> =A0 =A0 =A0 =A0void =A0 =A0(*set_rw)(struct device *dev, int to);
> =A0};
>
> +extern int __platram_probe(struct device *dev, const char *name,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct resource *res, struc=
t platdata_mtd_ram *pdata);
> +extern int __platram_remove(struct device *dev);
> +
> =A0#endif /* __LINUX_MTD_PLATRAM_H */
> --
> 1.5.6.5
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
>



--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] maps/mtd-ram: add an of-platform driver
  2009-01-21 17:41 ` [PATCH 2/2] maps/mtd-ram: add an of-platform driver Wolfram Sang
  2009-01-24 22:30   ` Wolfram Sang
@ 2009-05-19 14:57   ` Grant Likely
  2009-05-19 20:30     ` Wolfram Sang
  2009-05-21  0:46     ` Wolfram Sang
  1 sibling, 2 replies; 10+ messages in thread
From: Grant Likely @ 2009-05-19 14:57 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linuxppc-dev, linux-mtd, ben-linux

On Wed, Jan 21, 2009 at 11:41 AM, Wolfram Sang <w.sang@pengutronix.de> wrot=
e:
> 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 {
> =A0 =A0 =A0 =A0compatible =3D "mtd-ram";
> =A0 =A0 =A0 =A0reg =3D <0x04e00000 0x00200000>;
> =A0 =A0 =A0 =A0bank-width =3D <2>;
> };
>
> Partitions on this device are not yet supported.

This is a new device tree binding.  It must be documented in
Documentation/powerpc/dts-bindings and posted to
devicetree-discuss@ozlabs.org for review.

> 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) =A0 +=3D wr_sbc82xx_flash.o
> =A0obj-$(CONFIG_MTD_DMV182) =A0 =A0 =A0 +=3D dmv182.o
> =A0obj-$(CONFIG_MTD_SHARP_SL) =A0 =A0 +=3D sharpsl-flash.o
> =A0obj-$(CONFIG_MTD_PLATRAM) =A0 =A0 =A0+=3D plat-ram.o
> +obj-$(CONFIG_MTD_OFRAM) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0+=3D of-ram.o
> =A0obj-$(CONFIG_MTD_OMAP_NOR) =A0 =A0 +=3D omap_nor.o
> =A0obj-$(CONFIG_MTD_INTEL_VR_NOR) +=3D intel_vr_nor.o
> =A0obj-$(CONFIG_MTD_BFIN_ASYNC) =A0 +=3D 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 publis=
hed by
> + * the Free Software Foundation.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/types.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/device.h>
> +#include <linux/platform_device.h>
> +#include <linux/of_device.h>
> +#include <linux/of_platform.h>
> +#include <linux/mtd/plat-ram.h>
> +
> +static int of_ram_probe(struct of_device *op, const struct of_device_id =
*match)

__devinit

> +{
> + =A0 =A0 =A0 struct platdata_mtd_ram *pdata;
> + =A0 =A0 =A0 struct resource *resource;
> + =A0 =A0 =A0 const char *name;
> + =A0 =A0 =A0 const u32 *bankwidth;
> + =A0 =A0 =A0 int ret =3D -ENOMEM;
> +
> + =A0 =A0 =A0 pdata =3D kzalloc(sizeof(*pdata), GFP_KERNEL);
> + =A0 =A0 =A0 if (!pdata)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto bad0;
> + =A0 =A0 =A0 op->dev.platform_data =3D pdata;
> +
> + =A0 =A0 =A0 name =3D of_get_property(op->node, "name", NULL);
> + =A0 =A0 =A0 if (!name) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOENT;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(&op->dev, "could not get node name\=
n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto bad1;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 resource =3D kzalloc(sizeof(struct resource), GFP_KERNEL);
> + =A0 =A0 =A0 if (!resource)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto bad1;

Why isn't resource on the stack?

> +
> + =A0 =A0 =A0 if (of_address_to_resource(op->node, 0, resource)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENXIO;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(&op->dev, "could not create resourc=
e\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto bad2;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 bankwidth =3D of_get_property(op->node, "bank-width", NULL)=
;
> + =A0 =A0 =A0 if (*bankwidth =3D=3D 0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOENT;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(&op->dev, "bank width not set\n");
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto bad2;
> + =A0 =A0 =A0 }
> + =A0 =A0 =A0 pdata->bankwidth =3D *bankwidth;
> +
> + =A0 =A0 =A0 ret =3D __platram_probe(&op->dev, name, resource, pdata);
> + =A0 =A0 =A0 kfree(resource);
> +
> + =A0 =A0 =A0 if (ret)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto bad1;
> +
> + =A0 =A0 =A0 return 0;
> +
> + bad2:
> + =A0 =A0 =A0 kfree(resource);
> + bad1:
> + =A0 =A0 =A0 op->dev.platform_data =3D NULL;
> + =A0 =A0 =A0 kfree(pdata);
> + bad0:
> + =A0 =A0 =A0 return ret;

I'd rather see more meaningful labels.  ie "err_kalloc:" and
"err_platram_probe:".

> +}
> +
> +static int of_ram_remove(struct of_device *op)

__devexit

> +{
> + =A0 =A0 =A0 int ret;
> + =A0 =A0 =A0 struct platdata_mtd_ram *pdata =3D op->dev.platform_data;
> +
> + =A0 =A0 =A0 ret =3D __platram_remove(&op->dev);
> + =A0 =A0 =A0 op->dev.platform_data =3D NULL;
> + =A0 =A0 =A0 kfree(pdata);
> + =A0 =A0 =A0 return ret;
> +}
> +
> +static struct of_device_id of_ram_match[] =3D {
> + =A0 =A0 =A0 { .compatible =3D "mtd-ram", },
> + =A0 =A0 =A0 {},
> +};
> +MODULE_DEVICE_TABLE(of, of_ram_match);
> +
> +static struct of_platform_driver of_ram_driver =3D {

__devinitdata

> + =A0 =A0 =A0 .owner =3D THIS_MODULE,
> + =A0 =A0 =A0 .name =3D "of-ram",

This name is too generic for an of_platform device.  'mtd' needs to be
in there somewhere.

> + =A0 =A0 =A0 .match_table =3D of_ram_match,
> + =A0 =A0 =A0 .probe =3D of_ram_probe,
> + =A0 =A0 =A0 .remove =3D of_ram_remove,

__devexit_p()

> +};
> +
> +static int __init of_ram_init(void)
> +{
> + =A0 =A0 =A0 return of_register_platform_driver(&of_ram_driver);
> +}
> +
> +static void __exit of_ram_exit(void)
> +{
> + =A0 =A0 =A0 of_unregister_platform_driver(&of_ram_driver);
> +}
> +
> +module_init(of_ram_init);

Put the module_init() statement directly after the of_ram_init() definition=
.

> +module_exit(of_ram_exit);
> +
> +MODULE_AUTHOR("Wolfram Sang");
> +MODULE_DESCRIPTION("MTD OF RAM map driver");
> +MODULE_LICENSE("GPL v2");
> --
> 1.5.6.5
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
>



--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] maps/mtd-ram: add an of-platform driver
  2009-05-19 14:57   ` Grant Likely
@ 2009-05-19 20:30     ` Wolfram Sang
  2009-05-19 20:36       ` Grant Likely
  2009-05-21  0:46     ` Wolfram Sang
  1 sibling, 1 reply; 10+ messages in thread
From: Wolfram Sang @ 2009-05-19 20:30 UTC (permalink / raw)
  To: Grant Likely; +Cc: linuxppc-dev, linux-mtd, ben-linux

[-- Attachment #1: Type: text/plain, Size: 6437 bytes --]

Hi Grant,

thanks a lot for the review!

On Tue, May 19, 2009 at 08:57:15AM -0600, Grant Likely wrote:
> On Wed, Jan 21, 2009 at 11:41 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
> > 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.
> 
> This is a new device tree binding.  It must be documented in
> Documentation/powerpc/dts-bindings and posted to
> devicetree-discuss@ozlabs.org for review.

Yeah, noticed that myself. I wanted to start another try to mainline this
driver next week, then also asking devicetree-discuss; will do it happily this
week, too :)

> 
> > 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 <linux/module.h>
> > +#include <linux/types.h>
> > +#include <linux/init.h>
> > +#include <linux/kernel.h>
> > +#include <linux/device.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/of_device.h>
> > +#include <linux/of_platform.h>
> > +#include <linux/mtd/plat-ram.h>
> > +
> > +static int of_ram_probe(struct of_device *op, const struct of_device_id *match)
> 
> __devinit

Oops, missed all of those.

> 
> > +{
> > +       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;
> 
> Why isn't resource on the stack?

Point taken.

> 
> > +
> > +       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;
> 
> I'd rather see more meaningful labels.  ie "err_kalloc:" and
> "err_platram_probe:".

Okay.

> 
> > +}
> > +
> > +static int of_ram_remove(struct of_device *op)
> 
> __devexit
> 
> > +{
> > +       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 = {
> 
> __devinitdata
> 
> > +       .owner = THIS_MODULE,
> > +       .name = "of-ram",
> 
> This name is too generic for an of_platform device.  'mtd' needs to be
> in there somewhere.

Will "of-mtd-ram" do? (I'd think so)

> 
> > +       .match_table = of_ram_match,
> > +       .probe = of_ram_probe,
> > +       .remove = of_ram_remove,
> 
> __devexit_p()
> 
> > +};
> > +
> > +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);
> 
> Put the module_init() statement directly after the of_ram_init() definition.
> 
> > +module_exit(of_ram_exit);
> > +
> > +MODULE_AUTHOR("Wolfram Sang");
> > +MODULE_DESCRIPTION("MTD OF RAM map driver");
> > +MODULE_LICENSE("GPL v2");
> > --
> > 1.5.6.5
> >
> > _______________________________________________
> > Linuxppc-dev mailing list
> > Linuxppc-dev@ozlabs.org
> > https://ozlabs.org/mailman/listinfo/linuxppc-dev
> >
> 
> 
> 
> -- 
> Grant Likely, B.Sc., P.Eng.
> Secret Lab Technologies Ltd.

Will send V2 after some tests tomorrow...

Thanks,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] maps/mtd-ram: add an of-platform driver
  2009-05-19 20:30     ` Wolfram Sang
@ 2009-05-19 20:36       ` Grant Likely
  0 siblings, 0 replies; 10+ messages in thread
From: Grant Likely @ 2009-05-19 20:36 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linuxppc-dev, linux-mtd, ben-linux

On Tue, May 19, 2009 at 2:30 PM, Wolfram Sang <w.sang@pengutronix.de> wrote=
:
>> This name is too generic for an of_platform device. =A0'mtd' needs to be
>> in there somewhere.
>
> Will "of-mtd-ram" do? (I'd think so)

fine by me.

g

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] maps/mtd-ram: add an of-platform driver
  2009-05-19 14:57   ` Grant Likely
  2009-05-19 20:30     ` Wolfram Sang
@ 2009-05-21  0:46     ` Wolfram Sang
  2009-05-21  4:21       ` Grant Likely
  1 sibling, 1 reply; 10+ messages in thread
From: Wolfram Sang @ 2009-05-21  0:46 UTC (permalink / raw)
  To: Grant Likely; +Cc: linuxppc-dev, linux-mtd, ben-linux

[-- Attachment #1: Type: text/plain, Size: 6832 bytes --]

Hello Grant,

as I am just working on V2 (fixed even some additional things), two more
questions came up:

On Tue, May 19, 2009 at 08:57:15AM -0600, Grant Likely wrote:
> On Wed, Jan 21, 2009 at 11:41 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
> > 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.
> 
> This is a new device tree binding.  It must be documented in
> Documentation/powerpc/dts-bindings and posted to
> devicetree-discuss@ozlabs.org for review.
> 
> > 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 <linux/module.h>
> > +#include <linux/types.h>
> > +#include <linux/init.h>
> > +#include <linux/kernel.h>
> > +#include <linux/device.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/of_device.h>
> > +#include <linux/of_platform.h>
> > +#include <linux/mtd/plat-ram.h>
> > +
> > +static int of_ram_probe(struct of_device *op, const struct of_device_id *match)
> 
> __devinit
> 
> > +{
> > +       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;
> > +       }

Can I just use

	name = op->node->name

here? I wonder because of_device in asm/of_device.h states 'node' as "to be
obsoleted". And could I safely assume that all architectures will have the node
entry?

At least, I could drop the error check, if I understand booting-without-of
correctly? A name property will always be constructed, even if it is not
explicitly given.

> > +
> > +       resource = kzalloc(sizeof(struct resource), GFP_KERNEL);
> > +       if (!resource)
> > +               goto bad1;
> 
> Why isn't resource on the stack?
> 
> > +
> > +       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;
> 
> I'd rather see more meaningful labels.  ie "err_kalloc:" and
> "err_platram_probe:".
> 
> > +}
> > +
> > +static int of_ram_remove(struct of_device *op)
> 
> __devexit
> 
> > +{
> > +       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 = {
> 
> __devinitdata

I assume you mean the match_table and not the of_platform_driver. Shouldn't it
even better be const and using __devinitconst?

> 
> > +       .owner = THIS_MODULE,
> > +       .name = "of-ram",
> 
> This name is too generic for an of_platform device.  'mtd' needs to be
> in there somewhere.
> 
> > +       .match_table = of_ram_match,
> > +       .probe = of_ram_probe,
> > +       .remove = of_ram_remove,
> 
> __devexit_p()
> 
> > +};
> > +
> > +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);
> 
> Put the module_init() statement directly after the of_ram_init() definition.
> 
> > +module_exit(of_ram_exit);
> > +
> > +MODULE_AUTHOR("Wolfram Sang");
> > +MODULE_DESCRIPTION("MTD OF RAM map driver");
> > +MODULE_LICENSE("GPL v2");
> > --
> > 1.5.6.5
> >
> > _______________________________________________
> > Linuxppc-dev mailing list
> > Linuxppc-dev@ozlabs.org
> > https://ozlabs.org/mailman/listinfo/linuxppc-dev
> >
> 
> 
> 
> -- 
> Grant Likely, B.Sc., P.Eng.
> Secret Lab Technologies Ltd.
> 
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] maps/mtd-ram: add an of-platform driver
  2009-05-21  0:46     ` Wolfram Sang
@ 2009-05-21  4:21       ` Grant Likely
  0 siblings, 0 replies; 10+ messages in thread
From: Grant Likely @ 2009-05-21  4:21 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linuxppc-dev, linux-mtd, ben-linux

On Wed, May 20, 2009 at 6:46 PM, Wolfram Sang <w.sang@pengutronix.de> wrote=
:
>> > + =A0 =A0 =A0 name =3D of_get_property(op->node, "name", NULL);
>> > + =A0 =A0 =A0 if (!name) {
>> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOENT;
>> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(&op->dev, "could not get node na=
me\n");
>> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto bad1;
>> > + =A0 =A0 =A0 }
>
> Can I just use
>
> =A0 =A0 =A0 =A0name =3D op->node->name
>
> here? I wonder because of_device in asm/of_device.h states 'node' as "to =
be
> obsoleted"
It may be labeled as such, but it's been so for over 2 years now, and
op->node is used all over the place.  I think Ben would like to
eventually move to using the node pointer in archdata, but that will
require a fair bit of refactoring.

Ben will kick me if I'm wrong, but I'll go out on a limb and say that
I think you're okay to use it.

>. And could I safely assume that all architectures will have the node
> entry?

All three current users do.

>> > +static struct of_device_id of_ram_match[] =3D {
>> > + =A0 =A0 =A0 { .compatible =3D "mtd-ram", },
>> > + =A0 =A0 =A0 {},
>> > +};
>> > +MODULE_DEVICE_TABLE(of, of_ram_match);
>> > +
>> > +static struct of_platform_driver of_ram_driver =3D {
>>
>> __devinitdata
>
> I assume you mean the match_table and not the of_platform_driver. Shouldn=
't it
> even better be const and using __devinitconst?

correct on both counts.

g.

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-05-21  4:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-21 17:41 mtd-ram: add of-support Wolfram Sang
2009-01-21 17:41 ` [PATCH 1/2] maps/mtd-ram: refactor probe and remove Wolfram Sang
2009-05-19 14:41   ` Grant Likely
2009-01-21 17:41 ` [PATCH 2/2] maps/mtd-ram: add an of-platform driver Wolfram Sang
2009-01-24 22:30   ` Wolfram Sang
2009-05-19 14:57   ` Grant Likely
2009-05-19 20:30     ` Wolfram Sang
2009-05-19 20:36       ` Grant Likely
2009-05-21  0:46     ` Wolfram Sang
2009-05-21  4:21       ` Grant Likely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).