devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@ti.com>
To: tony@atomide.com, dwmw2@infradead.org, computersforpeace@gmail.com
Cc: devicetree@vger.kernel.org, nsekhar@ti.com,
	linux-kernel@vger.kernel.org, kyungmin.park@samsung.com,
	linux-mtd@lists.infradead.org, pekon@ti.com,
	ezequiel.garcia@free-electrons.com, javier@dowhile0.org,
	linux-omap@vger.kernel.org, Roger Quadros <rogerq@ti.com>
Subject: [PATCH 20/36] mtd: onenand: omap: Clean up device tree support
Date: Wed, 11 Jun 2014 11:56:25 +0300	[thread overview]
Message-ID: <1402477001-31132-21-git-send-email-rogerq@ti.com> (raw)
In-Reply-To: <1402477001-31132-1-git-send-email-rogerq@ti.com>

Move OneNAND specific device tree parsing to NAND driver.
The OneNAND device node must have its own compatible id.

Add a new property 'ti,onenand-sync-rw' to indicate
synchronous read + write support. Default mode would be
only synchronous reads.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 .../devicetree/bindings/mtd/gpmc-onenand.txt       |  4 +
 arch/arm/mach-omap2/gpmc-onenand.c                 | 14 ----
 arch/arm/mach-omap2/gpmc.c                         | 55 +++----------
 drivers/mtd/onenand/omap2.c                        | 90 ++++++++++++++++------
 include/linux/platform_data/mtd-onenand-omap2.h    |  4 +-
 5 files changed, 84 insertions(+), 83 deletions(-)

diff --git a/Documentation/devicetree/bindings/mtd/gpmc-onenand.txt b/Documentation/devicetree/bindings/mtd/gpmc-onenand.txt
index b752942..7fc9c13 100644
--- a/Documentation/devicetree/bindings/mtd/gpmc-onenand.txt
+++ b/Documentation/devicetree/bindings/mtd/gpmc-onenand.txt
@@ -9,9 +9,12 @@ Documentation/devicetree/bindings/bus/ti-gpmc.txt
 
 Required properties:
 
+ - compatible:		"ti,omap2-onenand"
  - reg:			The CS line the peripheral is connected to
  - gpmc,device-width	Width of the ONENAND device connected to the GPMC
 			in bytes. Must be 1 or 2.
+ - ti,onenand-sync-rw:	Bool. Enable synchronous Read and Write. If not
+			present, only Synchronous Read is enabled.
 
 Optional properties:
 
@@ -35,6 +38,7 @@ Example for an OMAP3430 board:
 		#size-cells = <1>;
 
 		onenand@0 {
+			compatible = "ti,omap2-onenand"
 			reg = <0 0 0>; /* CS0, offset 0 */
 			gpmc,device-width = <2>;
 
diff --git a/arch/arm/mach-omap2/gpmc-onenand.c b/arch/arm/mach-omap2/gpmc-onenand.c
index d09c342..37ed4f1 100644
--- a/arch/arm/mach-omap2/gpmc-onenand.c
+++ b/arch/arm/mach-omap2/gpmc-onenand.c
@@ -75,20 +75,6 @@ static int omap2_onenand_setup_async(struct omap_onenand_platform_data
 	struct gpmc_device_timings dev_t;
 	int ret;
 
-	if (gpmc_onenand_data->of_node) {
-		gpmc_read_settings_dt(gpmc_onenand_data->of_node,
-				      &onenand_async);
-		if (onenand_async.sync_read || onenand_async.sync_write) {
-			if (onenand_async.sync_write)
-				gpmc_onenand_data->flags |=
-					ONENAND_SYNC_READWRITE;
-			else
-				gpmc_onenand_data->flags |= ONENAND_SYNC_READ;
-			onenand_async.sync_read = false;
-			onenand_async.sync_write = false;
-		}
-	}
-
 	ret = gpmc_cs_program_settings(gpmc_onenand_data->cs, &onenand_async);
 	if (ret < 0)
 		return ret;
diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
index 50ef1a9..ee030cd 100644
--- a/arch/arm/mach-omap2/gpmc.c
+++ b/arch/arm/mach-omap2/gpmc.c
@@ -39,7 +39,6 @@
 #include "common.h"
 #include "omap_device.h"
 #include "gpmc.h"
-#include "gpmc-onenand.h"
 
 #define	DEVICE_NAME		"omap-gpmc"
 
@@ -1166,43 +1165,6 @@ static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
 		of_property_read_bool(np, "gpmc,time-para-granularity");
 }
 
-#if IS_ENABLED(CONFIG_MTD_ONENAND)
-static int gpmc_probe_onenand_child(struct platform_device *pdev,
-				 struct device_node *child)
-{
-	u32 val;
-	struct omap_onenand_platform_data *gpmc_onenand_data;
-
-	if (of_property_read_u32(child, "reg", &val) < 0) {
-		dev_err(&pdev->dev, "%s has no 'reg' property\n",
-			child->full_name);
-		return -ENODEV;
-	}
-
-	gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
-					 GFP_KERNEL);
-	if (!gpmc_onenand_data)
-		return -ENOMEM;
-
-	gpmc_onenand_data->cs = val;
-	gpmc_onenand_data->of_node = child;
-	gpmc_onenand_data->dma_channel = -1;
-
-	if (!of_property_read_u32(child, "dma-channel", &val))
-		gpmc_onenand_data->dma_channel = val;
-
-	gpmc_onenand_init(gpmc_onenand_data);
-
-	return 0;
-}
-#else
-static int gpmc_probe_onenand_child(struct platform_device *pdev,
-				    struct device_node *child)
-{
-	return 0;
-}
-#endif
-
 /**
  * gpmc_probe_generic_child - configures the gpmc for a child device
  * @pdev:	pointer to gpmc platform device
@@ -1292,6 +1254,12 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
 		}
 
 		gpmc_s.device_nand = true;
+
+	} else if (of_node_cmp(child->name, "onenand") == 0) {
+		/* DT incorrectly sets sync modes, onenand default is async */
+		gpmc_s.sync_read = false;
+		gpmc_s.sync_write = false;
+
 	} else {
 		if (of_property_read_u32(child, "bank-width",
 					 &gpmc_s.device_width)) {
@@ -1363,12 +1331,11 @@ static int gpmc_probe_dt(struct platform_device *pdev)
 		if (!child->name)
 			continue;
 
-		if (of_node_cmp(child->name, "onenand") == 0)
-			ret = gpmc_probe_onenand_child(pdev, child);
-		else if (of_node_cmp(child->name, "ethernet") == 0 ||
-			 of_node_cmp(child->name, "nor") == 0 ||
-			 of_node_cmp(child->name, "uart") == 0 ||
-			 of_node_cmp(child->name, "nand") == 0)
+		if (of_node_cmp(child->name, "ethernet") == 0 ||
+		    of_node_cmp(child->name, "nor") == 0 ||
+		    of_node_cmp(child->name, "uart") == 0 ||
+		    of_node_cmp(child->name, "nand") == 0 ||
+		    of_node_cmp(child->name, "onenand") == 0)
 			ret = gpmc_probe_generic_child(pdev, child);
 
 		if (WARN(ret < 0, "%s: probing gpmc child %s failed\n",
diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c
index b6a9ec0..35d2d39 100644
--- a/drivers/mtd/onenand/omap2.c
+++ b/drivers/mtd/onenand/omap2.c
@@ -40,6 +40,10 @@
 #include <linux/platform_data/gpmc-omap.h>
 #include <linux/gpio.h>
 #include <linux/omap-dma.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_mtd.h>
+#include <linux/of_gpio.h>
 
 #define DRIVER_NAME "omap2-onenand"
 
@@ -826,9 +830,33 @@ static void omap2_onenand_shutdown(struct platform_device *pdev)
 	memset((__force void *)c->onenand.base, 0, ONENAND_BUFRAM_SIZE);
 }
 
+static int omap2_onenand_get_dt_info(struct device *dev,
+				     struct omap2_onenand *c)
+{
+	struct device_node *node = dev->of_node;
+
+	/* Chip Select number */
+	if (of_property_read_u32(node, "reg", &c->gpmc_cs) < 0) {
+		dev_err(dev, "No 'reg' property\n");
+		return -EINVAL;
+	}
+
+	/* Enable synchronous read by default */
+	c->flags = ONENAND_SYNC_READ;
+	/* Enable synchronous write only if indicated by DT */
+	if (of_property_read_bool(node, "ti,onenand-sync-rw"))
+		c->flags = ONENAND_SYNC_READWRITE;
+
+	/* TODO: DMA channel, GPIO IRQ for wait */
+	c->dma_channel = -1;
+	c->gpio_irq = -EINVAL;
+
+	return 0;
+}
+
 static int omap2_onenand_probe(struct platform_device *pdev)
 {
-	struct omap_onenand_platform_data *pdata;
+	struct omap_onenand_platform_data *pdata = NULL;
 	struct omap2_onenand *c;
 	struct onenand_chip *this;
 	int r;
@@ -836,28 +864,40 @@ static int omap2_onenand_probe(struct platform_device *pdev)
 	struct mtd_part_parser_data ppdata = {};
 	struct device *dev = &pdev->dev;
 
-	pdata = dev_get_platdata(&pdev->dev);
-	if (pdata == NULL) {
-		dev_err(&pdev->dev, "platform data missing\n");
-		return -ENODEV;
-	}
-
 	c = devm_kzalloc(dev, sizeof(struct omap2_onenand), GFP_KERNEL);
 	if (!c)
 		return -ENOMEM;
 
-	init_completion(&c->irq_done);
-	init_completion(&c->dma_done);
-	c->pdev = pdev;
-	c->flags = pdata->flags;
-	c->gpmc_cs = pdata->cs;
-	c->gpio_irq = pdata->gpio_irq;
-	c->dma_channel = pdata->dma_channel;
+	this = &c->onenand;
+
+	if (dev->of_node) {
+		if (omap2_onenand_get_dt_info(dev, c))
+			return -EINVAL;
+
+	} else {
+		pdata = dev_get_platdata(dev);
+		if (pdata == NULL) {
+			dev_err(dev, "platform data missing\n");
+			return -ENODEV;
+		}
+
+		c->flags = pdata->flags;
+		c->gpio_irq = pdata->gpio_irq;
+		c->dma_channel = pdata->dma_channel;
+
+		if (pdata->skip_initial_unlocking)
+			this->options |= ONENAND_SKIP_INITIAL_UNLOCKING;
+	}
+
 	if (c->dma_channel < 0) {
 		/* if -1, don't use DMA */
 		c->gpio_irq = -EINVAL;
 	}
 
+	init_completion(&c->irq_done);
+	init_completion(&c->dma_done);
+	c->pdev = pdev;
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	c->onenand.base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(c->onenand.base))
@@ -921,7 +961,6 @@ static int omap2_onenand_probe(struct platform_device *pdev)
 
 	c->mtd.dev.parent = &pdev->dev;
 
-	this = &c->onenand;
 	if (c->dma_channel >= 0) {
 		this->wait = omap2_onenand_wait;
 		if (c->flags & ONENAND_IN_OMAP34XX) {
@@ -933,19 +972,20 @@ static int omap2_onenand_probe(struct platform_device *pdev)
 		}
 	}
 
-	if (pdata->skip_initial_unlocking)
-		this->options |= ONENAND_SKIP_INITIAL_UNLOCKING;
-
 	r = onenand_scan(&c->mtd, 1);
 	if (r) {
 		dev_err(dev, "OneNAND scan failed :%d\n", r);
 		goto err_release_dma;
 	}
 
-	ppdata.of_node = pdata->of_node;
-	r = mtd_device_parse_register(&c->mtd, NULL, &ppdata,
-				      pdata ? pdata->parts : NULL,
-				      pdata ? pdata->nr_parts : 0);
+	if (dev->of_node) {
+		ppdata.of_node = dev->of_node;
+		r = mtd_device_parse_register(&c->mtd, NULL, &ppdata, NULL, 0);
+
+	} else {
+		r = mtd_device_register(&c->mtd, pdata->parts, pdata->nr_parts);
+	}
+
 	if (r)
 		goto err_release_onenand;
 
@@ -974,6 +1014,11 @@ static int omap2_onenand_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id omap2_onenand_ids[] = {
+	{ .compatible = "ti,omap2-onenand", },
+	{},
+};
+
 static struct platform_driver omap2_onenand_driver = {
 	.probe		= omap2_onenand_probe,
 	.remove		= omap2_onenand_remove,
@@ -981,6 +1026,7 @@ static struct platform_driver omap2_onenand_driver = {
 	.driver		= {
 		.name	= DRIVER_NAME,
 		.owner  = THIS_MODULE,
+		.of_match_table = of_match_ptr(omap2_onenand_ids),
 	},
 };
 
diff --git a/include/linux/platform_data/mtd-onenand-omap2.h b/include/linux/platform_data/mtd-onenand-omap2.h
index ac1e6f3..99d8716 100644
--- a/include/linux/platform_data/mtd-onenand-omap2.h
+++ b/include/linux/platform_data/mtd-onenand-omap2.h
@@ -26,10 +26,8 @@ struct omap_onenand_platform_data {
 	u8			flags;
 	u8			skip_initial_unlocking;
 
-	/* for passing the partitions */
-	struct device_node	*of_node;
-
 	u8			regulator_can_sleep;	/* deprecated */
 	int (*onenand_setup)(void __iomem *, int *freq_ptr);	/* deprecated */
+	struct device_node	*of_node;		/* deprecated */
 };
 #endif
-- 
1.8.3.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  parent reply	other threads:[~2014-06-11  8:56 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-11  8:56 [PATCH 00/36] OMAP: GPMC: Restructure and move OMAP GPMC driver out of mach-omap2 Roger Quadros
2014-06-11  8:56 ` [PATCH 01/36] ARM: OMAP3: hwmod: Fix gpmc memory resource space Roger Quadros
2014-06-13  7:13   ` Tony Lindgren
2014-06-13  7:15     ` Roger Quadros
2014-06-11  8:56 ` [PATCH 02/36] ARM: dts: OMAP2+: Fix GPMC register space size Roger Quadros
2014-06-11  8:56 ` [PATCH 03/36] ARM: OMAP2+: gpmc: Add platform data Roger Quadros
2014-06-11  8:56 ` [PATCH 04/36] ARM: OMAP2+: gpmc: Add gpmc timings and settings to " Roger Quadros
2014-06-11  8:56 ` [PATCH 05/36] mtd: nand: omap: Move IRQ handling from GPMC to NAND driver Roger Quadros
2014-06-13  7:18   ` Tony Lindgren
     [not found]     ` <20140613071820.GI17845-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2014-06-13  7:38       ` Roger Quadros
     [not found]         ` <539AAA8C.2070709-l0cyMroinI0@public.gmane.org>
2014-06-13  7:58           ` Tony Lindgren
2014-06-13  8:13             ` Gupta, Pekon
2014-06-13  8:23               ` Roger Quadros
2014-06-13 10:46                 ` Tony Lindgren
     [not found]                   ` <20140613104610.GS17845-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2014-06-13 11:42                     ` Roger Quadros
     [not found]                       ` <539AE390.4080504-l0cyMroinI0@public.gmane.org>
2014-06-13 12:08                         ` Tony Lindgren
2014-07-01 10:11                           ` Roger Quadros
2014-07-01 13:16                             ` Tony Lindgren
2014-06-11  8:56 ` [PATCH 06/36] mtd: nand: omap: Move gpmc_update_nand_reg to nand driver Roger Quadros
     [not found]   ` <1402477001-31132-7-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2014-06-13  7:19     ` Tony Lindgren
2014-06-11  8:56 ` [PATCH 07/36] mtd: nand: omap: Move NAND write protect code from GPMC to NAND driver Roger Quadros
2014-06-13  7:20   ` Tony Lindgren
2014-06-11  8:56 ` [PATCH 08/36] mtd: nand: omap: Copy platform data parameters to omap_nand_info data Roger Quadros
2014-06-11  8:56 ` [PATCH 09/36] mtd: nand: omap: Clean up device tree support Roger Quadros
2014-06-11  8:56 ` [PATCH 10/36] ARM: dts: OMAP2+: Fix NAND device nodes Roger Quadros
     [not found]   ` <1402477001-31132-11-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2014-06-13  7:21     ` Tony Lindgren
2014-06-11  8:56 ` [PATCH 11/36] mtd: nand: omap: Update DT binding documentation Roger Quadros
2014-06-11  8:56 ` [PATCH 12/36] ARM: dts: omap3-beagle: Add NAND device Roger Quadros
2014-06-11  8:56 ` [PATCH 13/36] ARM: OMAP2+: gpmc.c: sanity check bank-width DT property Roger Quadros
2014-06-11  8:56 ` [PATCH 14/36] ARM: OMAP2+: gpmc: Allow drivers to reconfigure GPMC settings & timings Roger Quadros
2014-06-13  7:25   ` Tony Lindgren
2014-06-13  7:44     ` Roger Quadros
     [not found]       ` <539AABE5.10907-l0cyMroinI0@public.gmane.org>
2014-06-13  8:04         ` Tony Lindgren
2014-06-11  8:56 ` [PATCH 15/36] ARM: OMAP2+: gpmc: Allow drivers to query GPMC_CLK period Roger Quadros
2014-06-13  7:26   ` Tony Lindgren
2014-06-13  7:48     ` Roger Quadros
2014-06-11  8:56 ` [PATCH 16/36] mtd: onenand: omap: Remove regulator management code Roger Quadros
2014-06-11  8:56 ` [PATCH 17/36] ARM: OMAP2+: gpmc-onenand: Use Async settings/timings by default Roger Quadros
2014-06-11  8:56 ` [PATCH 18/36] ARM: OMAP2+: gpmc-onenand: Move Synchronous setting code to drivers/ Roger Quadros
     [not found]   ` <1402477001-31132-19-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2014-06-13  7:55     ` Tony Lindgren
     [not found]       ` <20140613075527.GP17845-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2014-06-13  8:30         ` Roger Quadros
2014-06-11  8:56 ` [PATCH 19/36] mtd: onenand: omap: Use devres managed resources Roger Quadros
2014-06-11  8:56 ` Roger Quadros [this message]
2014-06-11  8:56 ` [PATCH 21/36] ARM: dts: OMAP2+: Fix OneNAND device nodes Roger Quadros
2014-06-11  8:56 ` [PATCH 22/36] ARM: OMAP2+: gmpc: add gpmc_generic_init() Roger Quadros
2014-06-11  8:56 ` [PATCH 23/36] ARM: OMAP2+: gpmc: use platform data to configure CS space and poplulate device Roger Quadros
2014-06-11  8:56 ` [PATCH 24/36] ARM: OMAP2+: gpmc: add NAND specific setup Roger Quadros
2014-06-11  8:56 ` [PATCH 25/36] ARM: OMAP2+: gpmc: Support multiple Chip Selects per device Roger Quadros
2014-06-11  8:56 ` [PATCH 26/36] ARM: OMAP2+: gpmc-smc91x: Get rid of retime() from omap_smc91x_platform_data Roger Quadros
2014-06-11  8:56 ` [PATCH 27/36] ARM: OMAP2+: usb-tusb6010: Use omap_gpmc_retime() Roger Quadros
2014-06-11  8:56 ` [PATCH 28/36] ARM: OMAP2+: nand: Update gpmc_nand_init() to use generic_gpmc_init() Roger Quadros
2014-06-11  8:56 ` [PATCH 29/36] ARM: OMAP2+: gpmc-smc91x: Use gpmc_generic_init() Roger Quadros
2014-06-11  8:56 ` [PATCH 30/36] ARM: OMAP2+: gpmc-smsc911x: " Roger Quadros
2014-06-11  8:56 ` [PATCH 31/36] ARM: OMAP2: usb-tusb6010: " Roger Quadros
2014-06-11  8:56 ` [PATCH 32/36] ARM: OMAP2+: onenand: " Roger Quadros
2014-06-11  8:56 ` [PATCH 33/36] ARM: OMAP2+: board-flash: Use gpmc_generic_init() for NOR Roger Quadros
2014-06-11  8:56 ` [PATCH 34/36] ARM: OMAP2+: gpmc: Make externally unused functions/defines private Roger Quadros
2014-06-11  8:56 ` [PATCH 35/36] ARM: OMAP2+: gpmc: move GPMC driver into drivers/memory Roger Quadros
     [not found]   ` <1402477001-31132-36-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2014-06-11 11:45     ` [resend][PATCH " Roger Quadros
2014-06-11  8:56 ` [PATCH 36/36] ARM: OMAP2+: defconfig: Enable TI GPMC driver Roger Quadros
     [not found] ` <1402477001-31132-1-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2014-06-11 11:52   ` [PATCH 00/36] OMAP: GPMC: Restructure and move OMAP GPMC driver out of mach-omap2 Javier Martinez Canillas
2014-06-11 11:54     ` Roger Quadros

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1402477001-31132-21-git-send-email-rogerq@ti.com \
    --to=rogerq@ti.com \
    --cc=computersforpeace@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=ezequiel.garcia@free-electrons.com \
    --cc=javier@dowhile0.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=nsekhar@ti.com \
    --cc=pekon@ti.com \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).