All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
@ 2012-04-25  3:06 ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  3:06 UTC (permalink / raw)
  To: shawn.guo; +Cc: Huang Shijie, linux-mtd, linux-arm-kernel, dedekind1

The mx6q-arm2 and imx28evk have already support the device tree now.
So i decide to add the gpmi-nand dt support to them.

The mx23 does not support the device tree now. I will add the gpmi dt support
when it is ready.

Test this patch set on both MX6Q(arm2) and mx28(evk).

v1 --> v2
	[1] merge the gpmi/bch device node into one node.
	[2] add partitions support.
	[3] misc

Huang Shijie (3):
  mtd: gpmi: add device tree support for mx6q and mx28
  ARM: mx28: add gpmi-nand dt support
  ARM: mx6q: add gpmi-nand dt support

 .../devicetree/bindings/mtd/gpmi-nand.txt          |   34 +++++
 arch/arm/boot/dts/imx28-evk.dts                    |    4 +
 arch/arm/boot/dts/imx28.dtsi                       |   18 ++--
 arch/arm/boot/dts/imx6q-arm2.dts                   |    4 +
 arch/arm/boot/dts/imx6q.dtsi                       |   12 ++
 arch/arm/mach-imx/clock-imx6q.c                    |    5 +-
 arch/arm/mach-mxs/clock-mx28.c                     |    2 +-
 drivers/mtd/nand/Kconfig                           |    2 +-
 drivers/mtd/nand/gpmi-nand/bch-regs.h              |   42 +++++--
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c              |   18 ++--
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c             |  131 ++++++++++----------
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h             |    6 +-
 include/linux/mtd/gpmi-nand.h                      |    8 +-
 13 files changed, 185 insertions(+), 101 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/gpmi-nand.txt

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

* [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
@ 2012-04-25  3:06 ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

The mx6q-arm2 and imx28evk have already support the device tree now.
So i decide to add the gpmi-nand dt support to them.

The mx23 does not support the device tree now. I will add the gpmi dt support
when it is ready.

Test this patch set on both MX6Q(arm2) and mx28(evk).

v1 --> v2
	[1] merge the gpmi/bch device node into one node.
	[2] add partitions support.
	[3] misc

Huang Shijie (3):
  mtd: gpmi: add device tree support for mx6q and mx28
  ARM: mx28: add gpmi-nand dt support
  ARM: mx6q: add gpmi-nand dt support

 .../devicetree/bindings/mtd/gpmi-nand.txt          |   34 +++++
 arch/arm/boot/dts/imx28-evk.dts                    |    4 +
 arch/arm/boot/dts/imx28.dtsi                       |   18 ++--
 arch/arm/boot/dts/imx6q-arm2.dts                   |    4 +
 arch/arm/boot/dts/imx6q.dtsi                       |   12 ++
 arch/arm/mach-imx/clock-imx6q.c                    |    5 +-
 arch/arm/mach-mxs/clock-mx28.c                     |    2 +-
 drivers/mtd/nand/Kconfig                           |    2 +-
 drivers/mtd/nand/gpmi-nand/bch-regs.h              |   42 +++++--
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c              |   18 ++--
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c             |  131 ++++++++++----------
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h             |    6 +-
 include/linux/mtd/gpmi-nand.h                      |    8 +-
 13 files changed, 185 insertions(+), 101 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/gpmi-nand.txt

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

* [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
  2012-04-25  3:06 ` Huang Shijie
@ 2012-04-25  3:06   ` Huang Shijie
  -1 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  3:06 UTC (permalink / raw)
  To: shawn.guo; +Cc: Huang Shijie, linux-mtd, linux-arm-kernel, dedekind1

add gpmi support for mx6q.
add DT support to mx6q and mx28.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 .../devicetree/bindings/mtd/gpmi-nand.txt          |   34 +++++
 drivers/mtd/nand/Kconfig                           |    2 +-
 drivers/mtd/nand/gpmi-nand/bch-regs.h              |   42 +++++--
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c              |   18 ++--
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c             |  131 ++++++++++----------
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h             |    6 +-
 include/linux/mtd/gpmi-nand.h                      |    8 +-
 7 files changed, 152 insertions(+), 89 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/gpmi-nand.txt

diff --git a/Documentation/devicetree/bindings/mtd/gpmi-nand.txt b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
new file mode 100644
index 0000000..13fbb35
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
@@ -0,0 +1,34 @@
+* Freescale General-Purpose Media Interface (GPMI)
+
+The GPMI nand controller provides an interface to control the
+NAND flash chips. We support only one NAND chip now.
+
+Required properties:
+  - compatible : should be "fsl,<chip>-gpmi-nand"
+  - reg : should contain registers location and length for gpmi and bch.
+  - reg-names: Should contain the reg names "gpmi-nand" and "bch"
+  - interrupts : The first is the DMA interrupt number for GPMI.
+                 The second is the BCH interrupt number.
+  - interrupt-names : The interrupt names "gpmi-dma", "bch";
+  - fsl,gpmi-dma-channel : Should contain the dma channel it uses.
+
+Optional properties:
+  - partition : contain sub-nodes describing partitions of the
+                address space. See partition.txt for more detail.
+
+Examples:
+
+gpmi-nand@8000c000 {
+	compatible = "fsl,imx28-gpmi-nand";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x8000c000 2000>, <0x8000a000 2000>;
+	reg-names = "gpmi-nand", "bch";
+	interrupts = <88>, <41>;
+	interrupt-names = "gpmi-dma", "bch";
+	fsl,gpmi-dma-channel = <4>;
+
+	partition@0 {
+	...
+	};
+};
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 7d17cec..bf0a28d 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -440,7 +440,7 @@ config MTD_NAND_NANDSIM
 
 config MTD_NAND_GPMI_NAND
         bool "GPMI NAND Flash Controller driver"
-        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28)
+        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28 || SOC_IMX6Q)
         help
 	 Enables NAND Flash support for IMX23 or IMX28.
 	 The GPMI controller is very powerful, with the help of BCH
diff --git a/drivers/mtd/nand/gpmi-nand/bch-regs.h b/drivers/mtd/nand/gpmi-nand/bch-regs.h
index 4effb8c..a092451 100644
--- a/drivers/mtd/nand/gpmi-nand/bch-regs.h
+++ b/drivers/mtd/nand/gpmi-nand/bch-regs.h
@@ -51,15 +51,26 @@
 
 #define BP_BCH_FLASH0LAYOUT0_ECC0		12
 #define BM_BCH_FLASH0LAYOUT0_ECC0	(0xf << BP_BCH_FLASH0LAYOUT0_ECC0)
-#define BF_BCH_FLASH0LAYOUT0_ECC0(v)		\
-	(((v) << BP_BCH_FLASH0LAYOUT0_ECC0) & BM_BCH_FLASH0LAYOUT0_ECC0)
+#define MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0		11
+#define MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0	(0x1f << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)
+#define BF_BCH_FLASH0LAYOUT0_ECC0(v, x)				\
+	(GPMI_IS_MX6Q(x)					\
+		? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)	\
+			& MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0)	\
+		: (((v) << BP_BCH_FLASH0LAYOUT0_ECC0)		\
+			& BM_BCH_FLASH0LAYOUT0_ECC0)		\
+	)
 
 #define BP_BCH_FLASH0LAYOUT0_DATA0_SIZE		0
 #define BM_BCH_FLASH0LAYOUT0_DATA0_SIZE		\
 			(0xfff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
-#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v)	\
-	(((v) << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)\
-					 & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)
+#define MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE	\
+			(0x3ff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
+#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v, x)				\
+	(GPMI_IS_MX6Q(x)						\
+		? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)	\
+		: ((v) & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)		\
+	)
 
 #define HW_BCH_FLASH0LAYOUT1			0x00000090
 
@@ -72,13 +83,24 @@
 
 #define BP_BCH_FLASH0LAYOUT1_ECCN		12
 #define BM_BCH_FLASH0LAYOUT1_ECCN	(0xf << BP_BCH_FLASH0LAYOUT1_ECCN)
-#define BF_BCH_FLASH0LAYOUT1_ECCN(v)		\
-	(((v) << BP_BCH_FLASH0LAYOUT1_ECCN) & BM_BCH_FLASH0LAYOUT1_ECCN)
+#define MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN		11
+#define MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN	(0x1f << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)
+#define BF_BCH_FLASH0LAYOUT1_ECCN(v, x)				\
+	(GPMI_IS_MX6Q(x)					\
+		? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)	\
+			& MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN)	\
+		: (((v) << BP_BCH_FLASH0LAYOUT1_ECCN)		\
+			& BM_BCH_FLASH0LAYOUT1_ECCN)		\
+	)
 
 #define BP_BCH_FLASH0LAYOUT1_DATAN_SIZE		0
 #define BM_BCH_FLASH0LAYOUT1_DATAN_SIZE		\
 			(0xfff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
-#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v)	\
-	(((v) << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE) \
-					 & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)
+#define MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE	\
+			(0x3ff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
+#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v, x)				\
+	(GPMI_IS_MX6Q(x)						\
+		? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)	\
+		: ((v) & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)		\
+	)
 #endif
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
index fa5200b..a1f4332 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
@@ -224,13 +224,13 @@ int bch_set_geometry(struct gpmi_nand_data *this)
 	/* Configure layout 0. */
 	writel(BF_BCH_FLASH0LAYOUT0_NBLOCKS(block_count)
 			| BF_BCH_FLASH0LAYOUT0_META_SIZE(metadata_size)
-			| BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength)
-			| BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size),
+			| BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this)
+			| BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this),
 			r->bch_regs + HW_BCH_FLASH0LAYOUT0);
 
 	writel(BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size)
-			| BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength)
-			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size),
+			| BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this)
+			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this),
 			r->bch_regs + HW_BCH_FLASH0LAYOUT1);
 
 	/* Set *all* chip selects to use layout 0. */
@@ -256,11 +256,12 @@ static unsigned int ns_to_cycles(unsigned int time,
 	return max(k, min);
 }
 
+#define DEF_MIN_PROP_DELAY	5
+#define DEF_MAX_PROP_DELAY	9
 /* Apply timing to current hardware conditions. */
 static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
 					struct gpmi_nfc_hardware_timing *hw)
 {
-	struct gpmi_nand_platform_data *pdata = this->pdata;
 	struct timing_threshod *nfc = &timing_default_threshold;
 	struct nand_chip *nand = &this->nand;
 	struct nand_timing target = this->timing;
@@ -277,8 +278,8 @@ static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
 	int ideal_sample_delay_in_ns;
 	unsigned int sample_delay_factor;
 	int tEYE;
-	unsigned int min_prop_delay_in_ns = pdata->min_prop_delay_in_ns;
-	unsigned int max_prop_delay_in_ns = pdata->max_prop_delay_in_ns;
+	unsigned int min_prop_delay_in_ns = DEF_MIN_PROP_DELAY;
+	unsigned int max_prop_delay_in_ns = DEF_MAX_PROP_DELAY;
 
 	/*
 	 * If there are multiple chips, we need to relax the timings to allow
@@ -804,7 +805,8 @@ int gpmi_is_ready(struct gpmi_nand_data *this, unsigned chip)
 	if (GPMI_IS_MX23(this)) {
 		mask = MX23_BM_GPMI_DEBUG_READY0 << chip;
 		reg = readl(r->gpmi_regs + HW_GPMI_DEBUG);
-	} else if (GPMI_IS_MX28(this)) {
+	} else if (GPMI_IS_MX28(this) || GPMI_IS_MX6Q(this)) {
+		/* MX28 shares the same R/B register as MX6Q. */
 		mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip);
 		reg = readl(r->gpmi_regs + HW_GPMI_STAT);
 	} else
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 75b1dde..e0ea598 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -24,6 +24,9 @@
 #include <linux/module.h>
 #include <linux/mtd/gpmi-nand.h>
 #include <linux/mtd/partitions.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
 #include "gpmi-nand.h"
 
 /* add our owner bbt descriptor */
@@ -385,7 +388,7 @@ static void release_bch_irq(struct gpmi_nand_data *this)
 static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
 {
 	struct gpmi_nand_data *this = param;
-	struct resource *r = this->private;
+	int dma_channel = (int)this->private;
 
 	if (!mxs_dma_is_apbh(chan))
 		return false;
@@ -397,7 +400,7 @@ static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
 	 *	for mx28 :	MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7
 	 *		(These eight channels share the same IRQ!)
 	 */
-	if (r->start <= chan->chan_id && chan->chan_id <= r->end) {
+	if (dma_channel == chan->chan_id) {
 		chan->private = &this->dma_data;
 		return true;
 	}
@@ -417,57 +420,45 @@ static void release_dma_channels(struct gpmi_nand_data *this)
 static int __devinit acquire_dma_channels(struct gpmi_nand_data *this)
 {
 	struct platform_device *pdev = this->pdev;
-	struct gpmi_nand_platform_data *pdata = this->pdata;
-	struct resources *res = &this->resources;
-	struct resource *r, *r_dma;
-	unsigned int i;
+	struct resource *r_dma;
+	struct device_node *dn;
+	int dma_channel;
+	unsigned int ret;
+	struct dma_chan *dma_chan;
+	dma_cap_mask_t mask;
+
+	/* dma channel, we only use the first one. */
+	dn = pdev->dev.of_node;
+	ret = of_property_read_u32(dn, "fsl,gpmi-dma-channel", &dma_channel);
+	if (ret) {
+		pr_err("unable to get DMA channel from dt.\n");
+		goto acquire_err;
+	}
+	this->private = (void *)dma_channel;
 
-	r = platform_get_resource_byname(pdev, IORESOURCE_DMA,
-					GPMI_NAND_DMA_CHANNELS_RES_NAME);
+	/* gpmi dma interrupt */
 	r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
 					GPMI_NAND_DMA_INTERRUPT_RES_NAME);
-	if (!r || !r_dma) {
+	if (!r_dma) {
 		pr_err("Can't get resource for DMA\n");
-		return -ENXIO;
+		goto acquire_err;
 	}
+	this->dma_data.chan_irq = r_dma->start;
 
-	/* used in gpmi_dma_filter() */
-	this->private = r;
-
-	for (i = r->start; i <= r->end; i++) {
-		struct dma_chan *dma_chan;
-		dma_cap_mask_t mask;
-
-		if (i - r->start >= pdata->max_chip_count)
-			break;
+	/* request dma channel */
+	dma_cap_zero(mask);
+	dma_cap_set(DMA_SLAVE, mask);
 
-		dma_cap_zero(mask);
-		dma_cap_set(DMA_SLAVE, mask);
-
-		/* get the DMA interrupt */
-		if (r_dma->start == r_dma->end) {
-			/* only register the first. */
-			if (i == r->start)
-				this->dma_data.chan_irq = r_dma->start;
-			else
-				this->dma_data.chan_irq = NO_IRQ;
-		} else
-			this->dma_data.chan_irq = r_dma->start + (i - r->start);
-
-		dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
-		if (!dma_chan)
-			goto acquire_err;
-
-		/* fill the first empty item */
-		this->dma_chans[i - r->start] = dma_chan;
+	dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
+	if (!dma_chan) {
+		pr_err("dma_request_channel failed.\n");
+		goto acquire_err;
 	}
 
-	res->dma_low_channel = r->start;
-	res->dma_high_channel = i;
+	this->dma_chans[0] = dma_chan;
 	return 0;
 
 acquire_err:
-	pr_err("Can't acquire DMA channel %u\n", i);
 	release_dma_channels(this);
 	return -EINVAL;
 }
@@ -1461,9 +1452,9 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)
 
 static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
 {
-	struct gpmi_nand_platform_data *pdata = this->pdata;
 	struct mtd_info  *mtd = &this->mtd;
 	struct nand_chip *chip = &this->nand;
+	struct mtd_part_parser_data ppdata = {};
 	int ret;
 
 	/* init current chip */
@@ -1501,14 +1492,14 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
 	if (ret)
 		goto err_out;
 
-	ret = nand_scan(mtd, pdata->max_chip_count);
+	ret = nand_scan(mtd, 1);
 	if (ret) {
 		pr_err("Chip scan failed\n");
 		goto err_out;
 	}
 
-	ret = mtd_device_parse_register(mtd, NULL, NULL,
-			pdata->partitions, pdata->partition_count);
+	ppdata.of_node = this->pdev->dev.of_node;
+	ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
 	if (ret)
 		goto err_out;
 	return 0;
@@ -1518,12 +1509,41 @@ err_out:
 	return ret;
 }
 
+static const struct platform_device_id gpmi_ids[] = {
+	{ .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
+	{ .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
+	{ .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
+	{},
+};
+
+static const struct of_device_id gpmi_nand_id_table[] = {
+	{
+		.compatible = "fsl,imx23-gpmi-nand",
+		.data = (void *)&gpmi_ids[IS_MX23]
+	}, {
+		.compatible = "fsl,imx28-gpmi-nand",
+		.data = (void *)&gpmi_ids[IS_MX28]
+	}, {
+		.compatible = "fsl,imx6q-gpmi-nand",
+		.data = (void *)&gpmi_ids[IS_MX6Q]
+	}, {}
+};
+MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
+
 static int __devinit gpmi_nand_probe(struct platform_device *pdev)
 {
-	struct gpmi_nand_platform_data *pdata = pdev->dev.platform_data;
 	struct gpmi_nand_data *this;
+	const struct of_device_id *of_id;
 	int ret;
 
+	of_id = of_match_device(gpmi_nand_id_table, &pdev->dev);
+	if (of_id)
+		pdev->id_entry = of_id->data;
+	else {
+		pr_err("Failed to find the right device id.\n");
+		return -ENOMEM;
+	}
+
 	this = kzalloc(sizeof(*this), GFP_KERNEL);
 	if (!this) {
 		pr_err("Failed to allocate per-device memory\n");
@@ -1533,13 +1553,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, this);
 	this->pdev  = pdev;
 	this->dev   = &pdev->dev;
-	this->pdata = pdata;
-
-	if (pdata->platform_init) {
-		ret = pdata->platform_init();
-		if (ret)
-			goto platform_init_error;
-	}
 
 	ret = acquire_resources(this);
 	if (ret)
@@ -1557,7 +1570,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
 
 exit_nfc_init:
 	release_resources(this);
-platform_init_error:
 exit_acquire_resources:
 	platform_set_drvdata(pdev, NULL);
 	kfree(this);
@@ -1575,19 +1587,10 @@ static int __exit gpmi_nand_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static const struct platform_device_id gpmi_ids[] = {
-	{
-		.name = "imx23-gpmi-nand",
-		.driver_data = IS_MX23,
-	}, {
-		.name = "imx28-gpmi-nand",
-		.driver_data = IS_MX28,
-	}, {},
-};
-
 static struct platform_driver gpmi_nand_driver = {
 	.driver = {
 		.name = "gpmi-nand",
+		.of_match_table = gpmi_nand_id_table,
 	},
 	.probe   = gpmi_nand_probe,
 	.remove  = __exit_p(gpmi_nand_remove),
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
index ec6180d..ce5daa1 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
@@ -266,8 +266,10 @@ extern int gpmi_read_page(struct gpmi_nand_data *,
 #define STATUS_UNCORRECTABLE	0xfe
 
 /* Use the platform_id to distinguish different Archs. */
-#define IS_MX23			0x1
-#define IS_MX28			0x2
+#define IS_MX23			0x0
+#define IS_MX28			0x1
+#define IS_MX6Q			0x2
 #define GPMI_IS_MX23(x)		((x)->pdev->id_entry->driver_data == IS_MX23)
 #define GPMI_IS_MX28(x)		((x)->pdev->id_entry->driver_data == IS_MX28)
+#define GPMI_IS_MX6Q(x)		((x)->pdev->id_entry->driver_data == IS_MX6Q)
 #endif
diff --git a/include/linux/mtd/gpmi-nand.h b/include/linux/mtd/gpmi-nand.h
index 69b6dbf..ed3c4e0 100644
--- a/include/linux/mtd/gpmi-nand.h
+++ b/include/linux/mtd/gpmi-nand.h
@@ -23,12 +23,12 @@
 #define GPMI_NAND_RES_SIZE	6
 
 /* Resource names for the GPMI NAND driver. */
-#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME  "GPMI NAND GPMI Registers"
+#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME  "gpmi-nand"
 #define GPMI_NAND_GPMI_INTERRUPT_RES_NAME  "GPMI NAND GPMI Interrupt"
-#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME   "GPMI NAND BCH Registers"
-#define GPMI_NAND_BCH_INTERRUPT_RES_NAME   "GPMI NAND BCH Interrupt"
+#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME   "bch"
+#define GPMI_NAND_BCH_INTERRUPT_RES_NAME   "bch"
 #define GPMI_NAND_DMA_CHANNELS_RES_NAME    "GPMI NAND DMA Channels"
-#define GPMI_NAND_DMA_INTERRUPT_RES_NAME   "GPMI NAND DMA Interrupt"
+#define GPMI_NAND_DMA_INTERRUPT_RES_NAME   "gpmi-dma"
 
 /**
  * struct gpmi_nand_platform_data - GPMI NAND driver platform data.
-- 
1.7.0.4

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

* [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
@ 2012-04-25  3:06   ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

add gpmi support for mx6q.
add DT support to mx6q and mx28.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 .../devicetree/bindings/mtd/gpmi-nand.txt          |   34 +++++
 drivers/mtd/nand/Kconfig                           |    2 +-
 drivers/mtd/nand/gpmi-nand/bch-regs.h              |   42 +++++--
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c              |   18 ++--
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c             |  131 ++++++++++----------
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h             |    6 +-
 include/linux/mtd/gpmi-nand.h                      |    8 +-
 7 files changed, 152 insertions(+), 89 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/gpmi-nand.txt

diff --git a/Documentation/devicetree/bindings/mtd/gpmi-nand.txt b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
new file mode 100644
index 0000000..13fbb35
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
@@ -0,0 +1,34 @@
+* Freescale General-Purpose Media Interface (GPMI)
+
+The GPMI nand controller provides an interface to control the
+NAND flash chips. We support only one NAND chip now.
+
+Required properties:
+  - compatible : should be "fsl,<chip>-gpmi-nand"
+  - reg : should contain registers location and length for gpmi and bch.
+  - reg-names: Should contain the reg names "gpmi-nand" and "bch"
+  - interrupts : The first is the DMA interrupt number for GPMI.
+                 The second is the BCH interrupt number.
+  - interrupt-names : The interrupt names "gpmi-dma", "bch";
+  - fsl,gpmi-dma-channel : Should contain the dma channel it uses.
+
+Optional properties:
+  - partition : contain sub-nodes describing partitions of the
+                address space. See partition.txt for more detail.
+
+Examples:
+
+gpmi-nand at 8000c000 {
+	compatible = "fsl,imx28-gpmi-nand";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x8000c000 2000>, <0x8000a000 2000>;
+	reg-names = "gpmi-nand", "bch";
+	interrupts = <88>, <41>;
+	interrupt-names = "gpmi-dma", "bch";
+	fsl,gpmi-dma-channel = <4>;
+
+	partition at 0 {
+	...
+	};
+};
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 7d17cec..bf0a28d 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -440,7 +440,7 @@ config MTD_NAND_NANDSIM
 
 config MTD_NAND_GPMI_NAND
         bool "GPMI NAND Flash Controller driver"
-        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28)
+        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28 || SOC_IMX6Q)
         help
 	 Enables NAND Flash support for IMX23 or IMX28.
 	 The GPMI controller is very powerful, with the help of BCH
diff --git a/drivers/mtd/nand/gpmi-nand/bch-regs.h b/drivers/mtd/nand/gpmi-nand/bch-regs.h
index 4effb8c..a092451 100644
--- a/drivers/mtd/nand/gpmi-nand/bch-regs.h
+++ b/drivers/mtd/nand/gpmi-nand/bch-regs.h
@@ -51,15 +51,26 @@
 
 #define BP_BCH_FLASH0LAYOUT0_ECC0		12
 #define BM_BCH_FLASH0LAYOUT0_ECC0	(0xf << BP_BCH_FLASH0LAYOUT0_ECC0)
-#define BF_BCH_FLASH0LAYOUT0_ECC0(v)		\
-	(((v) << BP_BCH_FLASH0LAYOUT0_ECC0) & BM_BCH_FLASH0LAYOUT0_ECC0)
+#define MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0		11
+#define MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0	(0x1f << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)
+#define BF_BCH_FLASH0LAYOUT0_ECC0(v, x)				\
+	(GPMI_IS_MX6Q(x)					\
+		? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)	\
+			& MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0)	\
+		: (((v) << BP_BCH_FLASH0LAYOUT0_ECC0)		\
+			& BM_BCH_FLASH0LAYOUT0_ECC0)		\
+	)
 
 #define BP_BCH_FLASH0LAYOUT0_DATA0_SIZE		0
 #define BM_BCH_FLASH0LAYOUT0_DATA0_SIZE		\
 			(0xfff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
-#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v)	\
-	(((v) << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)\
-					 & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)
+#define MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE	\
+			(0x3ff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
+#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v, x)				\
+	(GPMI_IS_MX6Q(x)						\
+		? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)	\
+		: ((v) & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)		\
+	)
 
 #define HW_BCH_FLASH0LAYOUT1			0x00000090
 
@@ -72,13 +83,24 @@
 
 #define BP_BCH_FLASH0LAYOUT1_ECCN		12
 #define BM_BCH_FLASH0LAYOUT1_ECCN	(0xf << BP_BCH_FLASH0LAYOUT1_ECCN)
-#define BF_BCH_FLASH0LAYOUT1_ECCN(v)		\
-	(((v) << BP_BCH_FLASH0LAYOUT1_ECCN) & BM_BCH_FLASH0LAYOUT1_ECCN)
+#define MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN		11
+#define MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN	(0x1f << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)
+#define BF_BCH_FLASH0LAYOUT1_ECCN(v, x)				\
+	(GPMI_IS_MX6Q(x)					\
+		? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)	\
+			& MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN)	\
+		: (((v) << BP_BCH_FLASH0LAYOUT1_ECCN)		\
+			& BM_BCH_FLASH0LAYOUT1_ECCN)		\
+	)
 
 #define BP_BCH_FLASH0LAYOUT1_DATAN_SIZE		0
 #define BM_BCH_FLASH0LAYOUT1_DATAN_SIZE		\
 			(0xfff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
-#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v)	\
-	(((v) << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE) \
-					 & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)
+#define MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE	\
+			(0x3ff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
+#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v, x)				\
+	(GPMI_IS_MX6Q(x)						\
+		? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)	\
+		: ((v) & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)		\
+	)
 #endif
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
index fa5200b..a1f4332 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
@@ -224,13 +224,13 @@ int bch_set_geometry(struct gpmi_nand_data *this)
 	/* Configure layout 0. */
 	writel(BF_BCH_FLASH0LAYOUT0_NBLOCKS(block_count)
 			| BF_BCH_FLASH0LAYOUT0_META_SIZE(metadata_size)
-			| BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength)
-			| BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size),
+			| BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this)
+			| BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this),
 			r->bch_regs + HW_BCH_FLASH0LAYOUT0);
 
 	writel(BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size)
-			| BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength)
-			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size),
+			| BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this)
+			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this),
 			r->bch_regs + HW_BCH_FLASH0LAYOUT1);
 
 	/* Set *all* chip selects to use layout 0. */
@@ -256,11 +256,12 @@ static unsigned int ns_to_cycles(unsigned int time,
 	return max(k, min);
 }
 
+#define DEF_MIN_PROP_DELAY	5
+#define DEF_MAX_PROP_DELAY	9
 /* Apply timing to current hardware conditions. */
 static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
 					struct gpmi_nfc_hardware_timing *hw)
 {
-	struct gpmi_nand_platform_data *pdata = this->pdata;
 	struct timing_threshod *nfc = &timing_default_threshold;
 	struct nand_chip *nand = &this->nand;
 	struct nand_timing target = this->timing;
@@ -277,8 +278,8 @@ static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
 	int ideal_sample_delay_in_ns;
 	unsigned int sample_delay_factor;
 	int tEYE;
-	unsigned int min_prop_delay_in_ns = pdata->min_prop_delay_in_ns;
-	unsigned int max_prop_delay_in_ns = pdata->max_prop_delay_in_ns;
+	unsigned int min_prop_delay_in_ns = DEF_MIN_PROP_DELAY;
+	unsigned int max_prop_delay_in_ns = DEF_MAX_PROP_DELAY;
 
 	/*
 	 * If there are multiple chips, we need to relax the timings to allow
@@ -804,7 +805,8 @@ int gpmi_is_ready(struct gpmi_nand_data *this, unsigned chip)
 	if (GPMI_IS_MX23(this)) {
 		mask = MX23_BM_GPMI_DEBUG_READY0 << chip;
 		reg = readl(r->gpmi_regs + HW_GPMI_DEBUG);
-	} else if (GPMI_IS_MX28(this)) {
+	} else if (GPMI_IS_MX28(this) || GPMI_IS_MX6Q(this)) {
+		/* MX28 shares the same R/B register as MX6Q. */
 		mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip);
 		reg = readl(r->gpmi_regs + HW_GPMI_STAT);
 	} else
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 75b1dde..e0ea598 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -24,6 +24,9 @@
 #include <linux/module.h>
 #include <linux/mtd/gpmi-nand.h>
 #include <linux/mtd/partitions.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
 #include "gpmi-nand.h"
 
 /* add our owner bbt descriptor */
@@ -385,7 +388,7 @@ static void release_bch_irq(struct gpmi_nand_data *this)
 static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
 {
 	struct gpmi_nand_data *this = param;
-	struct resource *r = this->private;
+	int dma_channel = (int)this->private;
 
 	if (!mxs_dma_is_apbh(chan))
 		return false;
@@ -397,7 +400,7 @@ static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
 	 *	for mx28 :	MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7
 	 *		(These eight channels share the same IRQ!)
 	 */
-	if (r->start <= chan->chan_id && chan->chan_id <= r->end) {
+	if (dma_channel == chan->chan_id) {
 		chan->private = &this->dma_data;
 		return true;
 	}
@@ -417,57 +420,45 @@ static void release_dma_channels(struct gpmi_nand_data *this)
 static int __devinit acquire_dma_channels(struct gpmi_nand_data *this)
 {
 	struct platform_device *pdev = this->pdev;
-	struct gpmi_nand_platform_data *pdata = this->pdata;
-	struct resources *res = &this->resources;
-	struct resource *r, *r_dma;
-	unsigned int i;
+	struct resource *r_dma;
+	struct device_node *dn;
+	int dma_channel;
+	unsigned int ret;
+	struct dma_chan *dma_chan;
+	dma_cap_mask_t mask;
+
+	/* dma channel, we only use the first one. */
+	dn = pdev->dev.of_node;
+	ret = of_property_read_u32(dn, "fsl,gpmi-dma-channel", &dma_channel);
+	if (ret) {
+		pr_err("unable to get DMA channel from dt.\n");
+		goto acquire_err;
+	}
+	this->private = (void *)dma_channel;
 
-	r = platform_get_resource_byname(pdev, IORESOURCE_DMA,
-					GPMI_NAND_DMA_CHANNELS_RES_NAME);
+	/* gpmi dma interrupt */
 	r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
 					GPMI_NAND_DMA_INTERRUPT_RES_NAME);
-	if (!r || !r_dma) {
+	if (!r_dma) {
 		pr_err("Can't get resource for DMA\n");
-		return -ENXIO;
+		goto acquire_err;
 	}
+	this->dma_data.chan_irq = r_dma->start;
 
-	/* used in gpmi_dma_filter() */
-	this->private = r;
-
-	for (i = r->start; i <= r->end; i++) {
-		struct dma_chan *dma_chan;
-		dma_cap_mask_t mask;
-
-		if (i - r->start >= pdata->max_chip_count)
-			break;
+	/* request dma channel */
+	dma_cap_zero(mask);
+	dma_cap_set(DMA_SLAVE, mask);
 
-		dma_cap_zero(mask);
-		dma_cap_set(DMA_SLAVE, mask);
-
-		/* get the DMA interrupt */
-		if (r_dma->start == r_dma->end) {
-			/* only register the first. */
-			if (i == r->start)
-				this->dma_data.chan_irq = r_dma->start;
-			else
-				this->dma_data.chan_irq = NO_IRQ;
-		} else
-			this->dma_data.chan_irq = r_dma->start + (i - r->start);
-
-		dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
-		if (!dma_chan)
-			goto acquire_err;
-
-		/* fill the first empty item */
-		this->dma_chans[i - r->start] = dma_chan;
+	dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
+	if (!dma_chan) {
+		pr_err("dma_request_channel failed.\n");
+		goto acquire_err;
 	}
 
-	res->dma_low_channel = r->start;
-	res->dma_high_channel = i;
+	this->dma_chans[0] = dma_chan;
 	return 0;
 
 acquire_err:
-	pr_err("Can't acquire DMA channel %u\n", i);
 	release_dma_channels(this);
 	return -EINVAL;
 }
@@ -1461,9 +1452,9 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)
 
 static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
 {
-	struct gpmi_nand_platform_data *pdata = this->pdata;
 	struct mtd_info  *mtd = &this->mtd;
 	struct nand_chip *chip = &this->nand;
+	struct mtd_part_parser_data ppdata = {};
 	int ret;
 
 	/* init current chip */
@@ -1501,14 +1492,14 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
 	if (ret)
 		goto err_out;
 
-	ret = nand_scan(mtd, pdata->max_chip_count);
+	ret = nand_scan(mtd, 1);
 	if (ret) {
 		pr_err("Chip scan failed\n");
 		goto err_out;
 	}
 
-	ret = mtd_device_parse_register(mtd, NULL, NULL,
-			pdata->partitions, pdata->partition_count);
+	ppdata.of_node = this->pdev->dev.of_node;
+	ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
 	if (ret)
 		goto err_out;
 	return 0;
@@ -1518,12 +1509,41 @@ err_out:
 	return ret;
 }
 
+static const struct platform_device_id gpmi_ids[] = {
+	{ .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
+	{ .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
+	{ .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
+	{},
+};
+
+static const struct of_device_id gpmi_nand_id_table[] = {
+	{
+		.compatible = "fsl,imx23-gpmi-nand",
+		.data = (void *)&gpmi_ids[IS_MX23]
+	}, {
+		.compatible = "fsl,imx28-gpmi-nand",
+		.data = (void *)&gpmi_ids[IS_MX28]
+	}, {
+		.compatible = "fsl,imx6q-gpmi-nand",
+		.data = (void *)&gpmi_ids[IS_MX6Q]
+	}, {}
+};
+MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
+
 static int __devinit gpmi_nand_probe(struct platform_device *pdev)
 {
-	struct gpmi_nand_platform_data *pdata = pdev->dev.platform_data;
 	struct gpmi_nand_data *this;
+	const struct of_device_id *of_id;
 	int ret;
 
+	of_id = of_match_device(gpmi_nand_id_table, &pdev->dev);
+	if (of_id)
+		pdev->id_entry = of_id->data;
+	else {
+		pr_err("Failed to find the right device id.\n");
+		return -ENOMEM;
+	}
+
 	this = kzalloc(sizeof(*this), GFP_KERNEL);
 	if (!this) {
 		pr_err("Failed to allocate per-device memory\n");
@@ -1533,13 +1553,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, this);
 	this->pdev  = pdev;
 	this->dev   = &pdev->dev;
-	this->pdata = pdata;
-
-	if (pdata->platform_init) {
-		ret = pdata->platform_init();
-		if (ret)
-			goto platform_init_error;
-	}
 
 	ret = acquire_resources(this);
 	if (ret)
@@ -1557,7 +1570,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
 
 exit_nfc_init:
 	release_resources(this);
-platform_init_error:
 exit_acquire_resources:
 	platform_set_drvdata(pdev, NULL);
 	kfree(this);
@@ -1575,19 +1587,10 @@ static int __exit gpmi_nand_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static const struct platform_device_id gpmi_ids[] = {
-	{
-		.name = "imx23-gpmi-nand",
-		.driver_data = IS_MX23,
-	}, {
-		.name = "imx28-gpmi-nand",
-		.driver_data = IS_MX28,
-	}, {},
-};
-
 static struct platform_driver gpmi_nand_driver = {
 	.driver = {
 		.name = "gpmi-nand",
+		.of_match_table = gpmi_nand_id_table,
 	},
 	.probe   = gpmi_nand_probe,
 	.remove  = __exit_p(gpmi_nand_remove),
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
index ec6180d..ce5daa1 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
@@ -266,8 +266,10 @@ extern int gpmi_read_page(struct gpmi_nand_data *,
 #define STATUS_UNCORRECTABLE	0xfe
 
 /* Use the platform_id to distinguish different Archs. */
-#define IS_MX23			0x1
-#define IS_MX28			0x2
+#define IS_MX23			0x0
+#define IS_MX28			0x1
+#define IS_MX6Q			0x2
 #define GPMI_IS_MX23(x)		((x)->pdev->id_entry->driver_data == IS_MX23)
 #define GPMI_IS_MX28(x)		((x)->pdev->id_entry->driver_data == IS_MX28)
+#define GPMI_IS_MX6Q(x)		((x)->pdev->id_entry->driver_data == IS_MX6Q)
 #endif
diff --git a/include/linux/mtd/gpmi-nand.h b/include/linux/mtd/gpmi-nand.h
index 69b6dbf..ed3c4e0 100644
--- a/include/linux/mtd/gpmi-nand.h
+++ b/include/linux/mtd/gpmi-nand.h
@@ -23,12 +23,12 @@
 #define GPMI_NAND_RES_SIZE	6
 
 /* Resource names for the GPMI NAND driver. */
-#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME  "GPMI NAND GPMI Registers"
+#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME  "gpmi-nand"
 #define GPMI_NAND_GPMI_INTERRUPT_RES_NAME  "GPMI NAND GPMI Interrupt"
-#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME   "GPMI NAND BCH Registers"
-#define GPMI_NAND_BCH_INTERRUPT_RES_NAME   "GPMI NAND BCH Interrupt"
+#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME   "bch"
+#define GPMI_NAND_BCH_INTERRUPT_RES_NAME   "bch"
 #define GPMI_NAND_DMA_CHANNELS_RES_NAME    "GPMI NAND DMA Channels"
-#define GPMI_NAND_DMA_INTERRUPT_RES_NAME   "GPMI NAND DMA Interrupt"
+#define GPMI_NAND_DMA_INTERRUPT_RES_NAME   "gpmi-dma"
 
 /**
  * struct gpmi_nand_platform_data - GPMI NAND driver platform data.
-- 
1.7.0.4

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

* [PATCH v2 2/3] ARM: mx28: add gpmi-nand dt support
  2012-04-25  3:06 ` Huang Shijie
@ 2012-04-25  3:06   ` Huang Shijie
  -1 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  3:06 UTC (permalink / raw)
  To: shawn.guo; +Cc: Huang Shijie, linux-mtd, linux-arm-kernel, dedekind1

add gpmi-nand device tree support, and add proper clock for it.
Also enable the gpmi support for mx28-evk board.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 arch/arm/boot/dts/imx28-evk.dts |    4 ++++
 arch/arm/boot/dts/imx28.dtsi    |   18 +++++++++---------
 arch/arm/mach-mxs/clock-mx28.c  |    2 +-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/arch/arm/boot/dts/imx28-evk.dts b/arch/arm/boot/dts/imx28-evk.dts
index 157ecac..66a4b3b 100644
--- a/arch/arm/boot/dts/imx28-evk.dts
+++ b/arch/arm/boot/dts/imx28-evk.dts
@@ -22,6 +22,10 @@
 
         apb@80000000 {
                 apbh@80000000 {
+			gpmi-nand@8000c000 {
+				status = "okay";
+			};
+
 			mmc1: ssp@80010000 {
 				slot-8bit;
 				status = "okay";
diff --git a/arch/arm/boot/dts/imx28.dtsi b/arch/arm/boot/dts/imx28.dtsi
index dd209a3..c1e783e 100644
--- a/arch/arm/boot/dts/imx28.dtsi
+++ b/arch/arm/boot/dts/imx28.dtsi
@@ -62,15 +62,15 @@
 				status = "disabled";
 			};
 
-			bch@8000a000 {
-				reg = <0x8000a000 2000>;
-				interrupts = <41>;
-				status = "disabled";
-			};
-
-			gpmi@8000c000 {
-				reg = <0x8000c000 2000>;
-				interrupts = <42 88>;
+			gpmi-nand@8000c000 {
+				compatible = "fsl,imx28-gpmi-nand";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				reg = <0x8000c000 2000>, <0x8000a000 2000>;
+				reg-names = "gpmi-nand", "bch";
+				interrupts = <88>, <41>;
+				interrupt-names = "gpmi-dma", "bch";
+				fsl,gpmi-dma-channel = <4>;
 				status = "disabled";
 			};
 
diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index 8401854..6fe6737 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -617,7 +617,6 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("duart", NULL, uart_clk)
 	_REGISTER_CLOCK("imx28-fec.0", NULL, fec_clk)
 	_REGISTER_CLOCK("imx28-fec.1", NULL, fec_clk)
-	_REGISTER_CLOCK("imx28-gpmi-nand", NULL, gpmi_clk)
 	_REGISTER_CLOCK("mxs-auart.0", NULL, uart_clk)
 	_REGISTER_CLOCK("mxs-auart.1", NULL, uart_clk)
 	_REGISTER_CLOCK("mxs-auart.2", NULL, uart_clk)
@@ -649,6 +648,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxs-saif.0", NULL, saif0_clk)
 	_REGISTER_CLOCK("mxs-saif.1", NULL, saif1_clk)
 	/* for DT */
+	_REGISTER_CLOCK("8000c000.gpmi-nand", NULL, gpmi_clk)
 	_REGISTER_CLOCK("80074000.serial", NULL, uart_clk)
 	_REGISTER_CLOCK("800f0000.ethernet", NULL, fec_clk)
 	_REGISTER_CLOCK("800f4000.ethernet", NULL, fec_clk)
-- 
1.7.0.4

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

* [PATCH v2 2/3] ARM: mx28: add gpmi-nand dt support
@ 2012-04-25  3:06   ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

add gpmi-nand device tree support, and add proper clock for it.
Also enable the gpmi support for mx28-evk board.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 arch/arm/boot/dts/imx28-evk.dts |    4 ++++
 arch/arm/boot/dts/imx28.dtsi    |   18 +++++++++---------
 arch/arm/mach-mxs/clock-mx28.c  |    2 +-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/arch/arm/boot/dts/imx28-evk.dts b/arch/arm/boot/dts/imx28-evk.dts
index 157ecac..66a4b3b 100644
--- a/arch/arm/boot/dts/imx28-evk.dts
+++ b/arch/arm/boot/dts/imx28-evk.dts
@@ -22,6 +22,10 @@
 
         apb at 80000000 {
                 apbh at 80000000 {
+			gpmi-nand at 8000c000 {
+				status = "okay";
+			};
+
 			mmc1: ssp at 80010000 {
 				slot-8bit;
 				status = "okay";
diff --git a/arch/arm/boot/dts/imx28.dtsi b/arch/arm/boot/dts/imx28.dtsi
index dd209a3..c1e783e 100644
--- a/arch/arm/boot/dts/imx28.dtsi
+++ b/arch/arm/boot/dts/imx28.dtsi
@@ -62,15 +62,15 @@
 				status = "disabled";
 			};
 
-			bch at 8000a000 {
-				reg = <0x8000a000 2000>;
-				interrupts = <41>;
-				status = "disabled";
-			};
-
-			gpmi at 8000c000 {
-				reg = <0x8000c000 2000>;
-				interrupts = <42 88>;
+			gpmi-nand at 8000c000 {
+				compatible = "fsl,imx28-gpmi-nand";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				reg = <0x8000c000 2000>, <0x8000a000 2000>;
+				reg-names = "gpmi-nand", "bch";
+				interrupts = <88>, <41>;
+				interrupt-names = "gpmi-dma", "bch";
+				fsl,gpmi-dma-channel = <4>;
 				status = "disabled";
 			};
 
diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index 8401854..6fe6737 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -617,7 +617,6 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("duart", NULL, uart_clk)
 	_REGISTER_CLOCK("imx28-fec.0", NULL, fec_clk)
 	_REGISTER_CLOCK("imx28-fec.1", NULL, fec_clk)
-	_REGISTER_CLOCK("imx28-gpmi-nand", NULL, gpmi_clk)
 	_REGISTER_CLOCK("mxs-auart.0", NULL, uart_clk)
 	_REGISTER_CLOCK("mxs-auart.1", NULL, uart_clk)
 	_REGISTER_CLOCK("mxs-auart.2", NULL, uart_clk)
@@ -649,6 +648,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxs-saif.0", NULL, saif0_clk)
 	_REGISTER_CLOCK("mxs-saif.1", NULL, saif1_clk)
 	/* for DT */
+	_REGISTER_CLOCK("8000c000.gpmi-nand", NULL, gpmi_clk)
 	_REGISTER_CLOCK("80074000.serial", NULL, uart_clk)
 	_REGISTER_CLOCK("800f0000.ethernet", NULL, fec_clk)
 	_REGISTER_CLOCK("800f4000.ethernet", NULL, fec_clk)
-- 
1.7.0.4

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

* [PATCH v2 3/3] ARM: mx6q: add gpmi-nand dt support
  2012-04-25  3:06 ` Huang Shijie
@ 2012-04-25  3:06   ` Huang Shijie
  -1 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  3:06 UTC (permalink / raw)
  To: shawn.guo; +Cc: Huang Shijie, linux-mtd, linux-arm-kernel, dedekind1

add gpmi-nand dt support, and add the proper clock for gpmi-nand.
Also enable the gpmi for mx6q-arm2 board.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 arch/arm/boot/dts/imx6q-arm2.dts |    4 ++++
 arch/arm/boot/dts/imx6q.dtsi     |   12 ++++++++++++
 arch/arm/mach-imx/clock-imx6q.c  |    5 +++--
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/imx6q-arm2.dts b/arch/arm/boot/dts/imx6q-arm2.dts
index ce1c823..34d09da 100644
--- a/arch/arm/boot/dts/imx6q-arm2.dts
+++ b/arch/arm/boot/dts/imx6q-arm2.dts
@@ -26,6 +26,10 @@
 	};
 
 	soc {
+		gpmi-nand@00112000 {
+			status = "okay";
+		};
+
 		aips-bus@02100000 { /* AIPS2 */
 			enet@02188000 {
 				phy-mode = "rgmii";
diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index 4905f51..0a0ebf0 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -87,6 +87,18 @@
 		interrupt-parent = <&intc>;
 		ranges;
 
+		gpmi-nand@00112000 {
+			compatible = "fsl,imx6q-gpmi-nand";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			reg = <0x00112000 0x2000>, <0x00114000 0x2000>;
+			reg-names = "gpmi-nand", "bch";
+			interrupts = <0 13 0x04>, <0 15 0x04>;
+			interrupt-names = "gpmi-dma", "bch";
+			fsl,gpmi-dma-channel = <0>;
+			status = "disabled";
+		};
+
 		timer@00a00600 {
 			compatible = "arm,cortex-a9-twd-timer";
 			reg = <0x00a00600 0x20>;
diff --git a/arch/arm/mach-imx/clock-imx6q.c b/arch/arm/mach-imx/clock-imx6q.c
index 111c328..e3dc1b3 100644
--- a/arch/arm/mach-imx/clock-imx6q.c
+++ b/arch/arm/mach-imx/clock-imx6q.c
@@ -1859,7 +1859,8 @@ DEF_CLK(pwm1_clk,	  CCGR4, CG8,  &ipg_perclk,	  NULL);
 DEF_CLK(pwm2_clk,	  CCGR4, CG9,  &ipg_perclk,	  NULL);
 DEF_CLK(pwm3_clk,	  CCGR4, CG10, &ipg_perclk,	  NULL);
 DEF_CLK(pwm4_clk,	  CCGR4, CG11, &ipg_perclk,	  NULL);
-DEF_CLK(gpmi_bch_apb_clk, CCGR4, CG12, &usdhc3_clk,	  NULL);
+DEF_CLK(per1_bch_clk,     CCGR4, CG6,  &usdhc3_clk,	  NULL);
+DEF_CLK(gpmi_bch_apb_clk, CCGR4, CG12, &usdhc3_clk,	  &per1_bch_clk);
 DEF_CLK(gpmi_bch_clk,	  CCGR4, CG13, &usdhc4_clk,	  &gpmi_bch_apb_clk);
 DEF_CLK(gpmi_apb_clk,	  CCGR4, CG15, &usdhc3_clk,	  &gpmi_bch_clk);
 DEF_CLK(gpmi_io_clk,	  CCGR4, CG14, &enfc_clk,	  &gpmi_apb_clk);
@@ -1988,7 +1989,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK(NULL, "pwm2_clk", pwm2_clk),
 	_REGISTER_CLOCK(NULL, "pwm3_clk", pwm3_clk),
 	_REGISTER_CLOCK(NULL, "pwm4_clk", pwm4_clk),
-	_REGISTER_CLOCK(NULL, "gpmi_io_clk", gpmi_io_clk),
+	_REGISTER_CLOCK("112000.gpmi-nand", NULL, gpmi_io_clk),
 	_REGISTER_CLOCK(NULL, "usboh3_clk", usboh3_clk),
 	_REGISTER_CLOCK(NULL, "sata_clk", sata_clk),
 	_REGISTER_CLOCK(NULL, "cko1_clk", cko1_clk),
-- 
1.7.0.4

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

* [PATCH v2 3/3] ARM: mx6q: add gpmi-nand dt support
@ 2012-04-25  3:06   ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

add gpmi-nand dt support, and add the proper clock for gpmi-nand.
Also enable the gpmi for mx6q-arm2 board.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 arch/arm/boot/dts/imx6q-arm2.dts |    4 ++++
 arch/arm/boot/dts/imx6q.dtsi     |   12 ++++++++++++
 arch/arm/mach-imx/clock-imx6q.c  |    5 +++--
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/imx6q-arm2.dts b/arch/arm/boot/dts/imx6q-arm2.dts
index ce1c823..34d09da 100644
--- a/arch/arm/boot/dts/imx6q-arm2.dts
+++ b/arch/arm/boot/dts/imx6q-arm2.dts
@@ -26,6 +26,10 @@
 	};
 
 	soc {
+		gpmi-nand at 00112000 {
+			status = "okay";
+		};
+
 		aips-bus at 02100000 { /* AIPS2 */
 			enet at 02188000 {
 				phy-mode = "rgmii";
diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index 4905f51..0a0ebf0 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -87,6 +87,18 @@
 		interrupt-parent = <&intc>;
 		ranges;
 
+		gpmi-nand at 00112000 {
+			compatible = "fsl,imx6q-gpmi-nand";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			reg = <0x00112000 0x2000>, <0x00114000 0x2000>;
+			reg-names = "gpmi-nand", "bch";
+			interrupts = <0 13 0x04>, <0 15 0x04>;
+			interrupt-names = "gpmi-dma", "bch";
+			fsl,gpmi-dma-channel = <0>;
+			status = "disabled";
+		};
+
 		timer at 00a00600 {
 			compatible = "arm,cortex-a9-twd-timer";
 			reg = <0x00a00600 0x20>;
diff --git a/arch/arm/mach-imx/clock-imx6q.c b/arch/arm/mach-imx/clock-imx6q.c
index 111c328..e3dc1b3 100644
--- a/arch/arm/mach-imx/clock-imx6q.c
+++ b/arch/arm/mach-imx/clock-imx6q.c
@@ -1859,7 +1859,8 @@ DEF_CLK(pwm1_clk,	  CCGR4, CG8,  &ipg_perclk,	  NULL);
 DEF_CLK(pwm2_clk,	  CCGR4, CG9,  &ipg_perclk,	  NULL);
 DEF_CLK(pwm3_clk,	  CCGR4, CG10, &ipg_perclk,	  NULL);
 DEF_CLK(pwm4_clk,	  CCGR4, CG11, &ipg_perclk,	  NULL);
-DEF_CLK(gpmi_bch_apb_clk, CCGR4, CG12, &usdhc3_clk,	  NULL);
+DEF_CLK(per1_bch_clk,     CCGR4, CG6,  &usdhc3_clk,	  NULL);
+DEF_CLK(gpmi_bch_apb_clk, CCGR4, CG12, &usdhc3_clk,	  &per1_bch_clk);
 DEF_CLK(gpmi_bch_clk,	  CCGR4, CG13, &usdhc4_clk,	  &gpmi_bch_apb_clk);
 DEF_CLK(gpmi_apb_clk,	  CCGR4, CG15, &usdhc3_clk,	  &gpmi_bch_clk);
 DEF_CLK(gpmi_io_clk,	  CCGR4, CG14, &enfc_clk,	  &gpmi_apb_clk);
@@ -1988,7 +1989,7 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK(NULL, "pwm2_clk", pwm2_clk),
 	_REGISTER_CLOCK(NULL, "pwm3_clk", pwm3_clk),
 	_REGISTER_CLOCK(NULL, "pwm4_clk", pwm4_clk),
-	_REGISTER_CLOCK(NULL, "gpmi_io_clk", gpmi_io_clk),
+	_REGISTER_CLOCK("112000.gpmi-nand", NULL, gpmi_io_clk),
 	_REGISTER_CLOCK(NULL, "usboh3_clk", usboh3_clk),
 	_REGISTER_CLOCK(NULL, "sata_clk", sata_clk),
 	_REGISTER_CLOCK(NULL, "cko1_clk", cko1_clk),
-- 
1.7.0.4

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

* Re: [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
  2012-04-25  3:06 ` Huang Shijie
@ 2012-04-25  6:41   ` Dirk Behme
  -1 siblings, 0 replies; 28+ messages in thread
From: Dirk Behme @ 2012-04-25  6:41 UTC (permalink / raw)
  To: Huang Shijie; +Cc: shawn.guo, linux-mtd, linux-arm-kernel, dedekind1

Hi Huang Shijie,

On 25.04.2012 05:06, Huang Shijie wrote:
> The mx6q-arm2 and imx28evk have already support the device tree now.
> So i decide to add the gpmi-nand dt support to them.
> 
> The mx23 does not support the device tree now. I will add the gpmi dt support
> when it is ready.
> 
> Test this patch set on both MX6Q(arm2) and mx28(evk).
> 
> v1 --> v2
> 	[1] merge the gpmi/bch device node into one node.
> 	[2] add partitions support.
> 	[3] misc
> 
> Huang Shijie (3):
>   mtd: gpmi: add device tree support for mx6q and mx28
>   ARM: mx28: add gpmi-nand dt support
>   ARM: mx6q: add gpmi-nand dt support

For which kernel are these 3 patches? I tried to apply them on top of 
3.4-rc4 and got a lot of rejects.

Best regards

Dirk

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

* [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
@ 2012-04-25  6:41   ` Dirk Behme
  0 siblings, 0 replies; 28+ messages in thread
From: Dirk Behme @ 2012-04-25  6:41 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Huang Shijie,

On 25.04.2012 05:06, Huang Shijie wrote:
> The mx6q-arm2 and imx28evk have already support the device tree now.
> So i decide to add the gpmi-nand dt support to them.
> 
> The mx23 does not support the device tree now. I will add the gpmi dt support
> when it is ready.
> 
> Test this patch set on both MX6Q(arm2) and mx28(evk).
> 
> v1 --> v2
> 	[1] merge the gpmi/bch device node into one node.
> 	[2] add partitions support.
> 	[3] misc
> 
> Huang Shijie (3):
>   mtd: gpmi: add device tree support for mx6q and mx28
>   ARM: mx28: add gpmi-nand dt support
>   ARM: mx6q: add gpmi-nand dt support

For which kernel are these 3 patches? I tried to apply them on top of 
3.4-rc4 and got a lot of rejects.

Best regards

Dirk

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

* Re: [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
  2012-04-25  6:41   ` Dirk Behme
@ 2012-04-25  6:51     ` Huang Shijie
  -1 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  6:51 UTC (permalink / raw)
  To: Dirk Behme; +Cc: shawn.guo, linux-mtd, linux-arm-kernel, dedekind1

于 2012年04月25日 14:41, Dirk Behme 写道:
> Hi Huang Shijie,
>
> On 25.04.2012 05:06, Huang Shijie wrote:
>> The mx6q-arm2 and imx28evk have already support the device tree now.
>> So i decide to add the gpmi-nand dt support to them.
>>
>> The mx23 does not support the device tree now. I will add the gpmi dt 
>> support
>> when it is ready.
>>
>> Test this patch set on both MX6Q(arm2) and mx28(evk).
>>
>> v1 --> v2
>> [1] merge the gpmi/bch device node into one node.
>> [2] add partitions support.
>> [3] misc
>>
>> Huang Shijie (3):
>> mtd: gpmi: add device tree support for mx6q and mx28
>> ARM: mx28: add gpmi-nand dt support
>> ARM: mx6q: add gpmi-nand dt support
>
> For which kernel are these 3 patches? I tried to apply them on top of 
> 3.4-rc4 and got a lot of rejects.
>
They are based on 3.4-rc4. but I also applied some mxs-dma patches.

Which one cause the rejects?
I think the first patch "mtd:gpmi .." will not meet any rejects.
The other two small patches may meet rejects, but you can fix it by hand.

BR
Huang Shijie

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

* [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
@ 2012-04-25  6:51     ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  6:51 UTC (permalink / raw)
  To: linux-arm-kernel

? 2012?04?25? 14:41, Dirk Behme ??:
> Hi Huang Shijie,
>
> On 25.04.2012 05:06, Huang Shijie wrote:
>> The mx6q-arm2 and imx28evk have already support the device tree now.
>> So i decide to add the gpmi-nand dt support to them.
>>
>> The mx23 does not support the device tree now. I will add the gpmi dt 
>> support
>> when it is ready.
>>
>> Test this patch set on both MX6Q(arm2) and mx28(evk).
>>
>> v1 --> v2
>> [1] merge the gpmi/bch device node into one node.
>> [2] add partitions support.
>> [3] misc
>>
>> Huang Shijie (3):
>> mtd: gpmi: add device tree support for mx6q and mx28
>> ARM: mx28: add gpmi-nand dt support
>> ARM: mx6q: add gpmi-nand dt support
>
> For which kernel are these 3 patches? I tried to apply them on top of 
> 3.4-rc4 and got a lot of rejects.
>
They are based on 3.4-rc4. but I also applied some mxs-dma patches.

Which one cause the rejects?
I think the first patch "mtd:gpmi .." will not meet any rejects.
The other two small patches may meet rejects, but you can fix it by hand.

BR
Huang Shijie

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

* Re: [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
  2012-04-25  6:51     ` Huang Shijie
@ 2012-04-25  7:10       ` Dirk Behme
  -1 siblings, 0 replies; 28+ messages in thread
From: Dirk Behme @ 2012-04-25  7:10 UTC (permalink / raw)
  To: Huang Shijie; +Cc: shawn.guo, linux-mtd, linux-arm-kernel, dedekind1

On 25.04.2012 08:51, Huang Shijie wrote:
> 于 2012年04月25日 14:41, Dirk Behme 写道:
>> Hi Huang Shijie,
>>
>> On 25.04.2012 05:06, Huang Shijie wrote:
>>> The mx6q-arm2 and imx28evk have already support the device tree now.
>>> So i decide to add the gpmi-nand dt support to them.
>>>
>>> The mx23 does not support the device tree now. I will add the gpmi dt 
>>> support
>>> when it is ready.
>>>
>>> Test this patch set on both MX6Q(arm2) and mx28(evk).
>>>
>>> v1 --> v2
>>> [1] merge the gpmi/bch device node into one node.
>>> [2] add partitions support.
>>> [3] misc
>>>
>>> Huang Shijie (3):
>>> mtd: gpmi: add device tree support for mx6q and mx28
>>> ARM: mx28: add gpmi-nand dt support
>>> ARM: mx6q: add gpmi-nand dt support
>> For which kernel are these 3 patches? I tried to apply them on top of 
>> 3.4-rc4 and got a lot of rejects.
>>
> They are based on 3.4-rc4. but I also applied some mxs-dma patches.
> 
> Which one cause the rejects?

Could you kindly try to apply "mtd: gpmi: add device tree support for 
mx6q and mx28" on a clean 3.4-rc4?

Many thanks

Dirk

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

* [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
@ 2012-04-25  7:10       ` Dirk Behme
  0 siblings, 0 replies; 28+ messages in thread
From: Dirk Behme @ 2012-04-25  7:10 UTC (permalink / raw)
  To: linux-arm-kernel

On 25.04.2012 08:51, Huang Shijie wrote:
> ? 2012?04?25? 14:41, Dirk Behme ??:
>> Hi Huang Shijie,
>>
>> On 25.04.2012 05:06, Huang Shijie wrote:
>>> The mx6q-arm2 and imx28evk have already support the device tree now.
>>> So i decide to add the gpmi-nand dt support to them.
>>>
>>> The mx23 does not support the device tree now. I will add the gpmi dt 
>>> support
>>> when it is ready.
>>>
>>> Test this patch set on both MX6Q(arm2) and mx28(evk).
>>>
>>> v1 --> v2
>>> [1] merge the gpmi/bch device node into one node.
>>> [2] add partitions support.
>>> [3] misc
>>>
>>> Huang Shijie (3):
>>> mtd: gpmi: add device tree support for mx6q and mx28
>>> ARM: mx28: add gpmi-nand dt support
>>> ARM: mx6q: add gpmi-nand dt support
>> For which kernel are these 3 patches? I tried to apply them on top of 
>> 3.4-rc4 and got a lot of rejects.
>>
> They are based on 3.4-rc4. but I also applied some mxs-dma patches.
> 
> Which one cause the rejects?

Could you kindly try to apply "mtd: gpmi: add device tree support for 
mx6q and mx28" on a clean 3.4-rc4?

Many thanks

Dirk

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

* Re: [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
  2012-04-25  7:10       ` Dirk Behme
@ 2012-04-25  7:19         ` Huang Shijie
  -1 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  7:19 UTC (permalink / raw)
  To: Dirk Behme; +Cc: shawn.guo, linux-mtd, linux-arm-kernel, dedekind1

于 2012年04月25日 15:10, Dirk Behme 写道:
> On 25.04.2012 08:51, Huang Shijie wrote:
>> 于 2012年04月25日 14:41, Dirk Behme 写道:
>>> Hi Huang Shijie,
>>>
>>> On 25.04.2012 05:06, Huang Shijie wrote:
>>>> The mx6q-arm2 and imx28evk have already support the device tree now.
>>>> So i decide to add the gpmi-nand dt support to them.
>>>>
>>>> The mx23 does not support the device tree now. I will add the gpmi 
>>>> dt support
>>>> when it is ready.
>>>>
>>>> Test this patch set on both MX6Q(arm2) and mx28(evk).
>>>>
>>>> v1 --> v2
>>>> [1] merge the gpmi/bch device node into one node.
>>>> [2] add partitions support.
>>>> [3] misc
>>>>
>>>> Huang Shijie (3):
>>>> mtd: gpmi: add device tree support for mx6q and mx28
>>>> ARM: mx28: add gpmi-nand dt support
>>>> ARM: mx6q: add gpmi-nand dt support
>>> For which kernel are these 3 patches? I tried to apply them on top 
>>> of 3.4-rc4 and got a lot of rejects.
>>>
>> They are based on 3.4-rc4. but I also applied some mxs-dma patches.
>>
>> Which one cause the rejects?
>
> Could you kindly try to apply "mtd: gpmi: add device tree support for 
> mx6q and mx28" on a clean 3.4-rc4?
>
I tried just now, it works fine.

Huang Shijie
> Many thanks
>
> Dirk
>

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

* [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
@ 2012-04-25  7:19         ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-25  7:19 UTC (permalink / raw)
  To: linux-arm-kernel

? 2012?04?25? 15:10, Dirk Behme ??:
> On 25.04.2012 08:51, Huang Shijie wrote:
>> ? 2012?04?25? 14:41, Dirk Behme ??:
>>> Hi Huang Shijie,
>>>
>>> On 25.04.2012 05:06, Huang Shijie wrote:
>>>> The mx6q-arm2 and imx28evk have already support the device tree now.
>>>> So i decide to add the gpmi-nand dt support to them.
>>>>
>>>> The mx23 does not support the device tree now. I will add the gpmi 
>>>> dt support
>>>> when it is ready.
>>>>
>>>> Test this patch set on both MX6Q(arm2) and mx28(evk).
>>>>
>>>> v1 --> v2
>>>> [1] merge the gpmi/bch device node into one node.
>>>> [2] add partitions support.
>>>> [3] misc
>>>>
>>>> Huang Shijie (3):
>>>> mtd: gpmi: add device tree support for mx6q and mx28
>>>> ARM: mx28: add gpmi-nand dt support
>>>> ARM: mx6q: add gpmi-nand dt support
>>> For which kernel are these 3 patches? I tried to apply them on top 
>>> of 3.4-rc4 and got a lot of rejects.
>>>
>> They are based on 3.4-rc4. but I also applied some mxs-dma patches.
>>
>> Which one cause the rejects?
>
> Could you kindly try to apply "mtd: gpmi: add device tree support for 
> mx6q and mx28" on a clean 3.4-rc4?
>
I tried just now, it works fine.

Huang Shijie
> Many thanks
>
> Dirk
>

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

* Re: [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
  2012-04-25  3:06 ` Huang Shijie
@ 2012-04-28 12:00   ` Artem Bityutskiy
  -1 siblings, 0 replies; 28+ messages in thread
From: Artem Bityutskiy @ 2012-04-28 12:00 UTC (permalink / raw)
  To: Huang Shijie; +Cc: shawn.guo, linux-mtd, linux-arm-kernel

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

On Wed, 2012-04-25 at 11:06 +0800, Huang Shijie wrote:
> The mx6q-arm2 and imx28evk have already support the device tree now.
> So i decide to add the gpmi-nand dt support to them.
> 
> The mx23 does not support the device tree now. I will add the gpmi dt support
> when it is ready.

I cannot apply these patches to l2-mtd.git:

Applying: ARM: mx28: add gpmi-nand dt support
error: arch/arm/boot/dts/imx28-evk.dts: does not exist in index
error: arch/arm/boot/dts/imx28.dtsi: does not exist in index

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
@ 2012-04-28 12:00   ` Artem Bityutskiy
  0 siblings, 0 replies; 28+ messages in thread
From: Artem Bityutskiy @ 2012-04-28 12:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 2012-04-25 at 11:06 +0800, Huang Shijie wrote:
> The mx6q-arm2 and imx28evk have already support the device tree now.
> So i decide to add the gpmi-nand dt support to them.
> 
> The mx23 does not support the device tree now. I will add the gpmi dt support
> when it is ready.

I cannot apply these patches to l2-mtd.git:

Applying: ARM: mx28: add gpmi-nand dt support
error: arch/arm/boot/dts/imx28-evk.dts: does not exist in index
error: arch/arm/boot/dts/imx28.dtsi: does not exist in index

-- 
Best Regards,
Artem Bityutskiy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120428/6f581371/attachment-0001.sig>

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

* Re: [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
  2012-04-28 12:00   ` Artem Bityutskiy
@ 2012-04-28 13:31     ` Huang Shijie
  -1 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-28 13:31 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: Huang Shijie, shawn.guo, linux-mtd, linux-arm-kernel

Hi Artem:

On Sat, Apr 28, 2012 at 8:00 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> On Wed, 2012-04-25 at 11:06 +0800, Huang Shijie wrote:
>> The mx6q-arm2 and imx28evk have already support the device tree now.
>> So i decide to add the gpmi-nand dt support to them.
>>
>> The mx23 does not support the device tree now. I will add the gpmi dt support
>> when it is ready.
>
> I cannot apply these patches to l2-mtd.git:
Could you only apply the gpmi-nand patch? The other two patches are
for DT, and should be appled in Shawn's tree.

Best Regards
Huang Shijie






>
> Applying: ARM: mx28: add gpmi-nand dt support
> error: arch/arm/boot/dts/imx28-evk.dts: does not exist in index
> error: arch/arm/boot/dts/imx28.dtsi: does not exist in index
>
> --
> Best Regards,
> Artem Bityutskiy
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>

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

* [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28
@ 2012-04-28 13:31     ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-04-28 13:31 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Artem:

On Sat, Apr 28, 2012 at 8:00 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> On Wed, 2012-04-25 at 11:06 +0800, Huang Shijie wrote:
>> The mx6q-arm2 and imx28evk have already support the device tree now.
>> So i decide to add the gpmi-nand dt support to them.
>>
>> The mx23 does not support the device tree now. I will add the gpmi dt support
>> when it is ready.
>
> I cannot apply these patches to l2-mtd.git:
Could you only apply the gpmi-nand patch? The other two patches are
for DT, and should be appled in Shawn's tree.

Best Regards
Huang Shijie






>
> Applying: ARM: mx28: add gpmi-nand dt support
> error: arch/arm/boot/dts/imx28-evk.dts: does not exist in index
> error: arch/arm/boot/dts/imx28.dtsi: does not exist in index
>
> --
> Best Regards,
> Artem Bityutskiy
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>

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

* Re: [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
  2012-04-25  3:06   ` Huang Shijie
@ 2012-05-01  7:49     ` Shawn Guo
  -1 siblings, 0 replies; 28+ messages in thread
From: Shawn Guo @ 2012-05-01  7:49 UTC (permalink / raw)
  To: Huang Shijie; +Cc: linux-mtd, linux-arm-kernel, dedekind1

On Wed, Apr 25, 2012 at 11:06:22AM +0800, Huang Shijie wrote:
> add gpmi support for mx6q.
> add DT support to mx6q and mx28.
> 
> Signed-off-by: Huang Shijie <b32955@freescale.com>
> ---
>  .../devicetree/bindings/mtd/gpmi-nand.txt          |   34 +++++
>  drivers/mtd/nand/Kconfig                           |    2 +-
>  drivers/mtd/nand/gpmi-nand/bch-regs.h              |   42 +++++--
>  drivers/mtd/nand/gpmi-nand/gpmi-lib.c              |   18 ++--
>  drivers/mtd/nand/gpmi-nand/gpmi-nand.c             |  131 ++++++++++----------
>  drivers/mtd/nand/gpmi-nand/gpmi-nand.h             |    6 +-
>  include/linux/mtd/gpmi-nand.h                      |    8 +-
>  7 files changed, 152 insertions(+), 89 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/gpmi-nand.txt
> 
> diff --git a/Documentation/devicetree/bindings/mtd/gpmi-nand.txt b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
> new file mode 100644
> index 0000000..13fbb35
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
> @@ -0,0 +1,34 @@
> +* Freescale General-Purpose Media Interface (GPMI)
> +
> +The GPMI nand controller provides an interface to control the
> +NAND flash chips. We support only one NAND chip now.
> +
> +Required properties:
> +  - compatible : should be "fsl,<chip>-gpmi-nand"
> +  - reg : should contain registers location and length for gpmi and bch.
> +  - reg-names: Should contain the reg names "gpmi-nand" and "bch"
> +  - interrupts : The first is the DMA interrupt number for GPMI.
> +                 The second is the BCH interrupt number.
> +  - interrupt-names : The interrupt names "gpmi-dma", "bch";
> +  - fsl,gpmi-dma-channel : Should contain the dma channel it uses.
> +
> +Optional properties:
> +  - partition : contain sub-nodes describing partitions of the
> +                address space. See partition.txt for more detail.

The partition here is not a property but a sub-node, so you should
not document it as a property, but simply put a reference to
partition.txt probably like what
Documentation/devicetree/bindings/mtd/atmel-dataflash.txt does.

> +
> +Examples:
> +
> +gpmi-nand@8000c000 {
> +	compatible = "fsl,imx28-gpmi-nand";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	reg = <0x8000c000 2000>, <0x8000a000 2000>;
> +	reg-names = "gpmi-nand", "bch";
> +	interrupts = <88>, <41>;
> +	interrupt-names = "gpmi-dma", "bch";
> +	fsl,gpmi-dma-channel = <4>;
> +
> +	partition@0 {
> +	...
> +	};
> +};
> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
> index 7d17cec..bf0a28d 100644
> --- a/drivers/mtd/nand/Kconfig
> +++ b/drivers/mtd/nand/Kconfig
> @@ -440,7 +440,7 @@ config MTD_NAND_NANDSIM
>  
>  config MTD_NAND_GPMI_NAND
>          bool "GPMI NAND Flash Controller driver"
> -        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28)
> +        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28 || SOC_IMX6Q)
>          help
>  	 Enables NAND Flash support for IMX23 or IMX28.
>  	 The GPMI controller is very powerful, with the help of BCH
> diff --git a/drivers/mtd/nand/gpmi-nand/bch-regs.h b/drivers/mtd/nand/gpmi-nand/bch-regs.h
> index 4effb8c..a092451 100644
> --- a/drivers/mtd/nand/gpmi-nand/bch-regs.h
> +++ b/drivers/mtd/nand/gpmi-nand/bch-regs.h
> @@ -51,15 +51,26 @@
>  
>  #define BP_BCH_FLASH0LAYOUT0_ECC0		12
>  #define BM_BCH_FLASH0LAYOUT0_ECC0	(0xf << BP_BCH_FLASH0LAYOUT0_ECC0)
> -#define BF_BCH_FLASH0LAYOUT0_ECC0(v)		\
> -	(((v) << BP_BCH_FLASH0LAYOUT0_ECC0) & BM_BCH_FLASH0LAYOUT0_ECC0)
> +#define MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0		11
> +#define MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0	(0x1f << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)
> +#define BF_BCH_FLASH0LAYOUT0_ECC0(v, x)				\
> +	(GPMI_IS_MX6Q(x)					\
> +		? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)	\
> +			& MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0)	\
> +		: (((v) << BP_BCH_FLASH0LAYOUT0_ECC0)		\
> +			& BM_BCH_FLASH0LAYOUT0_ECC0)		\
> +	)
>  
>  #define BP_BCH_FLASH0LAYOUT0_DATA0_SIZE		0
>  #define BM_BCH_FLASH0LAYOUT0_DATA0_SIZE		\
>  			(0xfff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
> -#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v)	\
> -	(((v) << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)\
> -					 & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)
> +#define MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE	\
> +			(0x3ff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
> +#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v, x)				\
> +	(GPMI_IS_MX6Q(x)						\
> +		? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)	\
> +		: ((v) & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)		\
> +	)
>  
>  #define HW_BCH_FLASH0LAYOUT1			0x00000090
>  
> @@ -72,13 +83,24 @@
>  
>  #define BP_BCH_FLASH0LAYOUT1_ECCN		12
>  #define BM_BCH_FLASH0LAYOUT1_ECCN	(0xf << BP_BCH_FLASH0LAYOUT1_ECCN)
> -#define BF_BCH_FLASH0LAYOUT1_ECCN(v)		\
> -	(((v) << BP_BCH_FLASH0LAYOUT1_ECCN) & BM_BCH_FLASH0LAYOUT1_ECCN)
> +#define MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN		11
> +#define MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN	(0x1f << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)
> +#define BF_BCH_FLASH0LAYOUT1_ECCN(v, x)				\
> +	(GPMI_IS_MX6Q(x)					\
> +		? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)	\
> +			& MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN)	\
> +		: (((v) << BP_BCH_FLASH0LAYOUT1_ECCN)		\
> +			& BM_BCH_FLASH0LAYOUT1_ECCN)		\
> +	)
>  
>  #define BP_BCH_FLASH0LAYOUT1_DATAN_SIZE		0
>  #define BM_BCH_FLASH0LAYOUT1_DATAN_SIZE		\
>  			(0xfff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
> -#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v)	\
> -	(((v) << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE) \
> -					 & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)
> +#define MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE	\
> +			(0x3ff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
> +#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v, x)				\
> +	(GPMI_IS_MX6Q(x)						\
> +		? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)	\
> +		: ((v) & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)		\
> +	)
>  #endif
> diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
> index fa5200b..a1f4332 100644
> --- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
> +++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
> @@ -224,13 +224,13 @@ int bch_set_geometry(struct gpmi_nand_data *this)
>  	/* Configure layout 0. */
>  	writel(BF_BCH_FLASH0LAYOUT0_NBLOCKS(block_count)
>  			| BF_BCH_FLASH0LAYOUT0_META_SIZE(metadata_size)
> -			| BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength)
> -			| BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size),
> +			| BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this)
> +			| BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this),
>  			r->bch_regs + HW_BCH_FLASH0LAYOUT0);
>  
>  	writel(BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size)
> -			| BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength)
> -			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size),
> +			| BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this)
> +			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this),
>  			r->bch_regs + HW_BCH_FLASH0LAYOUT1);
>  
>  	/* Set *all* chip selects to use layout 0. */
> @@ -256,11 +256,12 @@ static unsigned int ns_to_cycles(unsigned int time,
>  	return max(k, min);
>  }
>  
> +#define DEF_MIN_PROP_DELAY	5
> +#define DEF_MAX_PROP_DELAY	9
>  /* Apply timing to current hardware conditions. */
>  static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
>  					struct gpmi_nfc_hardware_timing *hw)
>  {
> -	struct gpmi_nand_platform_data *pdata = this->pdata;
>  	struct timing_threshod *nfc = &timing_default_threshold;
>  	struct nand_chip *nand = &this->nand;
>  	struct nand_timing target = this->timing;
> @@ -277,8 +278,8 @@ static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
>  	int ideal_sample_delay_in_ns;
>  	unsigned int sample_delay_factor;
>  	int tEYE;
> -	unsigned int min_prop_delay_in_ns = pdata->min_prop_delay_in_ns;
> -	unsigned int max_prop_delay_in_ns = pdata->max_prop_delay_in_ns;
> +	unsigned int min_prop_delay_in_ns = DEF_MIN_PROP_DELAY;
> +	unsigned int max_prop_delay_in_ns = DEF_MAX_PROP_DELAY;
>  
>  	/*
>  	 * If there are multiple chips, we need to relax the timings to allow
> @@ -804,7 +805,8 @@ int gpmi_is_ready(struct gpmi_nand_data *this, unsigned chip)
>  	if (GPMI_IS_MX23(this)) {
>  		mask = MX23_BM_GPMI_DEBUG_READY0 << chip;
>  		reg = readl(r->gpmi_regs + HW_GPMI_DEBUG);
> -	} else if (GPMI_IS_MX28(this)) {
> +	} else if (GPMI_IS_MX28(this) || GPMI_IS_MX6Q(this)) {
> +		/* MX28 shares the same R/B register as MX6Q. */
>  		mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip);
>  		reg = readl(r->gpmi_regs + HW_GPMI_STAT);
>  	} else
> diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> index 75b1dde..e0ea598 100644
> --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> @@ -24,6 +24,9 @@
>  #include <linux/module.h>
>  #include <linux/mtd/gpmi-nand.h>
>  #include <linux/mtd/partitions.h>
> +#include <linux/of_address.h>

This line is probably not needed?

> +#include <linux/of_device.h>
> +#include <linux/of_irq.h>

Ditto?

>  #include "gpmi-nand.h"
>  
>  /* add our owner bbt descriptor */
> @@ -385,7 +388,7 @@ static void release_bch_irq(struct gpmi_nand_data *this)
>  static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
>  {
>  	struct gpmi_nand_data *this = param;
> -	struct resource *r = this->private;
> +	int dma_channel = (int)this->private;
>  
>  	if (!mxs_dma_is_apbh(chan))
>  		return false;
> @@ -397,7 +400,7 @@ static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
>  	 *	for mx28 :	MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7
>  	 *		(These eight channels share the same IRQ!)
>  	 */
> -	if (r->start <= chan->chan_id && chan->chan_id <= r->end) {
> +	if (dma_channel == chan->chan_id) {
>  		chan->private = &this->dma_data;
>  		return true;
>  	}
> @@ -417,57 +420,45 @@ static void release_dma_channels(struct gpmi_nand_data *this)
>  static int __devinit acquire_dma_channels(struct gpmi_nand_data *this)
>  {
>  	struct platform_device *pdev = this->pdev;
> -	struct gpmi_nand_platform_data *pdata = this->pdata;
> -	struct resources *res = &this->resources;
> -	struct resource *r, *r_dma;
> -	unsigned int i;
> +	struct resource *r_dma;
> +	struct device_node *dn;
> +	int dma_channel;
> +	unsigned int ret;
> +	struct dma_chan *dma_chan;
> +	dma_cap_mask_t mask;
> +
> +	/* dma channel, we only use the first one. */
> +	dn = pdev->dev.of_node;
> +	ret = of_property_read_u32(dn, "fsl,gpmi-dma-channel", &dma_channel);
> +	if (ret) {
> +		pr_err("unable to get DMA channel from dt.\n");
> +		goto acquire_err;
> +	}
> +	this->private = (void *)dma_channel;
>  
> -	r = platform_get_resource_byname(pdev, IORESOURCE_DMA,
> -					GPMI_NAND_DMA_CHANNELS_RES_NAME);

You are adding device tree support into a driver that is working fine
for non-DT probe.  So before all the users of this driver are converted
to DT, you have to ensure the driver works for both non-DT and DT users
in a single image when you add DT support for it.

So above code should be something like:

	if (dn) {
		/* get channel number from device tree */
		......
	} else {
		/* otherwise it works as before */
	}

> +	/* gpmi dma interrupt */
>  	r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
>  					GPMI_NAND_DMA_INTERRUPT_RES_NAME);
> -	if (!r || !r_dma) {
> +	if (!r_dma) {
>  		pr_err("Can't get resource for DMA\n");
> -		return -ENXIO;
> +		goto acquire_err;
>  	}
> +	this->dma_data.chan_irq = r_dma->start;
>  
> -	/* used in gpmi_dma_filter() */
> -	this->private = r;
> -
> -	for (i = r->start; i <= r->end; i++) {
> -		struct dma_chan *dma_chan;
> -		dma_cap_mask_t mask;
> -
> -		if (i - r->start >= pdata->max_chip_count)
> -			break;
> +	/* request dma channel */
> +	dma_cap_zero(mask);
> +	dma_cap_set(DMA_SLAVE, mask);
>  
> -		dma_cap_zero(mask);
> -		dma_cap_set(DMA_SLAVE, mask);
> -
> -		/* get the DMA interrupt */
> -		if (r_dma->start == r_dma->end) {
> -			/* only register the first. */
> -			if (i == r->start)
> -				this->dma_data.chan_irq = r_dma->start;
> -			else
> -				this->dma_data.chan_irq = NO_IRQ;
> -		} else
> -			this->dma_data.chan_irq = r_dma->start + (i - r->start);
> -
> -		dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
> -		if (!dma_chan)
> -			goto acquire_err;
> -
> -		/* fill the first empty item */
> -		this->dma_chans[i - r->start] = dma_chan;
> +	dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
> +	if (!dma_chan) {
> +		pr_err("dma_request_channel failed.\n");
> +		goto acquire_err;
>  	}
>  
> -	res->dma_low_channel = r->start;
> -	res->dma_high_channel = i;
> +	this->dma_chans[0] = dma_chan;
>  	return 0;
>  
>  acquire_err:
> -	pr_err("Can't acquire DMA channel %u\n", i);
>  	release_dma_channels(this);
>  	return -EINVAL;
>  }
> @@ -1461,9 +1452,9 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)
>  
>  static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
>  {
> -	struct gpmi_nand_platform_data *pdata = this->pdata;
>  	struct mtd_info  *mtd = &this->mtd;
>  	struct nand_chip *chip = &this->nand;
> +	struct mtd_part_parser_data ppdata = {};
>  	int ret;
>  
>  	/* init current chip */
> @@ -1501,14 +1492,14 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
>  	if (ret)
>  		goto err_out;
>  
> -	ret = nand_scan(mtd, pdata->max_chip_count);
> +	ret = nand_scan(mtd, 1);

Ditto, you should not break non-DT users.

>  	if (ret) {
>  		pr_err("Chip scan failed\n");
>  		goto err_out;
>  	}
>  
> -	ret = mtd_device_parse_register(mtd, NULL, NULL,
> -			pdata->partitions, pdata->partition_count);
> +	ppdata.of_node = this->pdev->dev.of_node;
> +	ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
>  	if (ret)
>  		goto err_out;
>  	return 0;
> @@ -1518,12 +1509,41 @@ err_out:
>  	return ret;
>  }
>  
> +static const struct platform_device_id gpmi_ids[] = {
> +	{ .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
> +	{ .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
> +	{ .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
> +	{},
> +};
> +
> +static const struct of_device_id gpmi_nand_id_table[] = {
> +	{
> +		.compatible = "fsl,imx23-gpmi-nand",
> +		.data = (void *)&gpmi_ids[IS_MX23]
> +	}, {
> +		.compatible = "fsl,imx28-gpmi-nand",
> +		.data = (void *)&gpmi_ids[IS_MX28]
> +	}, {
> +		.compatible = "fsl,imx6q-gpmi-nand",
> +		.data = (void *)&gpmi_ids[IS_MX6Q]
> +	}, {}
> +};
> +MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
> +
>  static int __devinit gpmi_nand_probe(struct platform_device *pdev)
>  {
> -	struct gpmi_nand_platform_data *pdata = pdev->dev.platform_data;
>  	struct gpmi_nand_data *this;
> +	const struct of_device_id *of_id;
>  	int ret;
>  
> +	of_id = of_match_device(gpmi_nand_id_table, &pdev->dev);
> +	if (of_id)
> +		pdev->id_entry = of_id->data;
> +	else {
> +		pr_err("Failed to find the right device id.\n");
> +		return -ENOMEM;
> +	}
> +

Ditto, it should still work for non-DT users.

BTW, it seems Documentation/CodingStyle suggest put brace like the
following.

	if (condition) {
		do_this();
	} else {
		otherwise_do_this();
		otherwise_do_that();
	}

Regards,
Shawn

>  	this = kzalloc(sizeof(*this), GFP_KERNEL);
>  	if (!this) {
>  		pr_err("Failed to allocate per-device memory\n");
> @@ -1533,13 +1553,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, this);
>  	this->pdev  = pdev;
>  	this->dev   = &pdev->dev;
> -	this->pdata = pdata;
> -
> -	if (pdata->platform_init) {
> -		ret = pdata->platform_init();
> -		if (ret)
> -			goto platform_init_error;
> -	}
>  
>  	ret = acquire_resources(this);
>  	if (ret)
> @@ -1557,7 +1570,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
>  
>  exit_nfc_init:
>  	release_resources(this);
> -platform_init_error:
>  exit_acquire_resources:
>  	platform_set_drvdata(pdev, NULL);
>  	kfree(this);
> @@ -1575,19 +1587,10 @@ static int __exit gpmi_nand_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -static const struct platform_device_id gpmi_ids[] = {
> -	{
> -		.name = "imx23-gpmi-nand",
> -		.driver_data = IS_MX23,
> -	}, {
> -		.name = "imx28-gpmi-nand",
> -		.driver_data = IS_MX28,
> -	}, {},
> -};
> -
>  static struct platform_driver gpmi_nand_driver = {
>  	.driver = {
>  		.name = "gpmi-nand",
> +		.of_match_table = gpmi_nand_id_table,
>  	},
>  	.probe   = gpmi_nand_probe,
>  	.remove  = __exit_p(gpmi_nand_remove),
> diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
> index ec6180d..ce5daa1 100644
> --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
> +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
> @@ -266,8 +266,10 @@ extern int gpmi_read_page(struct gpmi_nand_data *,
>  #define STATUS_UNCORRECTABLE	0xfe
>  
>  /* Use the platform_id to distinguish different Archs. */
> -#define IS_MX23			0x1
> -#define IS_MX28			0x2
> +#define IS_MX23			0x0
> +#define IS_MX28			0x1
> +#define IS_MX6Q			0x2
>  #define GPMI_IS_MX23(x)		((x)->pdev->id_entry->driver_data == IS_MX23)
>  #define GPMI_IS_MX28(x)		((x)->pdev->id_entry->driver_data == IS_MX28)
> +#define GPMI_IS_MX6Q(x)		((x)->pdev->id_entry->driver_data == IS_MX6Q)
>  #endif
> diff --git a/include/linux/mtd/gpmi-nand.h b/include/linux/mtd/gpmi-nand.h
> index 69b6dbf..ed3c4e0 100644
> --- a/include/linux/mtd/gpmi-nand.h
> +++ b/include/linux/mtd/gpmi-nand.h
> @@ -23,12 +23,12 @@
>  #define GPMI_NAND_RES_SIZE	6
>  
>  /* Resource names for the GPMI NAND driver. */
> -#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME  "GPMI NAND GPMI Registers"
> +#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME  "gpmi-nand"
>  #define GPMI_NAND_GPMI_INTERRUPT_RES_NAME  "GPMI NAND GPMI Interrupt"
> -#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME   "GPMI NAND BCH Registers"
> -#define GPMI_NAND_BCH_INTERRUPT_RES_NAME   "GPMI NAND BCH Interrupt"
> +#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME   "bch"
> +#define GPMI_NAND_BCH_INTERRUPT_RES_NAME   "bch"
>  #define GPMI_NAND_DMA_CHANNELS_RES_NAME    "GPMI NAND DMA Channels"
> -#define GPMI_NAND_DMA_INTERRUPT_RES_NAME   "GPMI NAND DMA Interrupt"
> +#define GPMI_NAND_DMA_INTERRUPT_RES_NAME   "gpmi-dma"
>  
>  /**
>   * struct gpmi_nand_platform_data - GPMI NAND driver platform data.
> -- 
> 1.7.0.4
> 
> 

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

* [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
@ 2012-05-01  7:49     ` Shawn Guo
  0 siblings, 0 replies; 28+ messages in thread
From: Shawn Guo @ 2012-05-01  7:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 25, 2012 at 11:06:22AM +0800, Huang Shijie wrote:
> add gpmi support for mx6q.
> add DT support to mx6q and mx28.
> 
> Signed-off-by: Huang Shijie <b32955@freescale.com>
> ---
>  .../devicetree/bindings/mtd/gpmi-nand.txt          |   34 +++++
>  drivers/mtd/nand/Kconfig                           |    2 +-
>  drivers/mtd/nand/gpmi-nand/bch-regs.h              |   42 +++++--
>  drivers/mtd/nand/gpmi-nand/gpmi-lib.c              |   18 ++--
>  drivers/mtd/nand/gpmi-nand/gpmi-nand.c             |  131 ++++++++++----------
>  drivers/mtd/nand/gpmi-nand/gpmi-nand.h             |    6 +-
>  include/linux/mtd/gpmi-nand.h                      |    8 +-
>  7 files changed, 152 insertions(+), 89 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/gpmi-nand.txt
> 
> diff --git a/Documentation/devicetree/bindings/mtd/gpmi-nand.txt b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
> new file mode 100644
> index 0000000..13fbb35
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
> @@ -0,0 +1,34 @@
> +* Freescale General-Purpose Media Interface (GPMI)
> +
> +The GPMI nand controller provides an interface to control the
> +NAND flash chips. We support only one NAND chip now.
> +
> +Required properties:
> +  - compatible : should be "fsl,<chip>-gpmi-nand"
> +  - reg : should contain registers location and length for gpmi and bch.
> +  - reg-names: Should contain the reg names "gpmi-nand" and "bch"
> +  - interrupts : The first is the DMA interrupt number for GPMI.
> +                 The second is the BCH interrupt number.
> +  - interrupt-names : The interrupt names "gpmi-dma", "bch";
> +  - fsl,gpmi-dma-channel : Should contain the dma channel it uses.
> +
> +Optional properties:
> +  - partition : contain sub-nodes describing partitions of the
> +                address space. See partition.txt for more detail.

The partition here is not a property but a sub-node, so you should
not document it as a property, but simply put a reference to
partition.txt probably like what
Documentation/devicetree/bindings/mtd/atmel-dataflash.txt does.

> +
> +Examples:
> +
> +gpmi-nand at 8000c000 {
> +	compatible = "fsl,imx28-gpmi-nand";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	reg = <0x8000c000 2000>, <0x8000a000 2000>;
> +	reg-names = "gpmi-nand", "bch";
> +	interrupts = <88>, <41>;
> +	interrupt-names = "gpmi-dma", "bch";
> +	fsl,gpmi-dma-channel = <4>;
> +
> +	partition at 0 {
> +	...
> +	};
> +};
> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
> index 7d17cec..bf0a28d 100644
> --- a/drivers/mtd/nand/Kconfig
> +++ b/drivers/mtd/nand/Kconfig
> @@ -440,7 +440,7 @@ config MTD_NAND_NANDSIM
>  
>  config MTD_NAND_GPMI_NAND
>          bool "GPMI NAND Flash Controller driver"
> -        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28)
> +        depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28 || SOC_IMX6Q)
>          help
>  	 Enables NAND Flash support for IMX23 or IMX28.
>  	 The GPMI controller is very powerful, with the help of BCH
> diff --git a/drivers/mtd/nand/gpmi-nand/bch-regs.h b/drivers/mtd/nand/gpmi-nand/bch-regs.h
> index 4effb8c..a092451 100644
> --- a/drivers/mtd/nand/gpmi-nand/bch-regs.h
> +++ b/drivers/mtd/nand/gpmi-nand/bch-regs.h
> @@ -51,15 +51,26 @@
>  
>  #define BP_BCH_FLASH0LAYOUT0_ECC0		12
>  #define BM_BCH_FLASH0LAYOUT0_ECC0	(0xf << BP_BCH_FLASH0LAYOUT0_ECC0)
> -#define BF_BCH_FLASH0LAYOUT0_ECC0(v)		\
> -	(((v) << BP_BCH_FLASH0LAYOUT0_ECC0) & BM_BCH_FLASH0LAYOUT0_ECC0)
> +#define MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0		11
> +#define MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0	(0x1f << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)
> +#define BF_BCH_FLASH0LAYOUT0_ECC0(v, x)				\
> +	(GPMI_IS_MX6Q(x)					\
> +		? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)	\
> +			& MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0)	\
> +		: (((v) << BP_BCH_FLASH0LAYOUT0_ECC0)		\
> +			& BM_BCH_FLASH0LAYOUT0_ECC0)		\
> +	)
>  
>  #define BP_BCH_FLASH0LAYOUT0_DATA0_SIZE		0
>  #define BM_BCH_FLASH0LAYOUT0_DATA0_SIZE		\
>  			(0xfff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
> -#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v)	\
> -	(((v) << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)\
> -					 & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)
> +#define MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE	\
> +			(0x3ff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
> +#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v, x)				\
> +	(GPMI_IS_MX6Q(x)						\
> +		? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)	\
> +		: ((v) & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)		\
> +	)
>  
>  #define HW_BCH_FLASH0LAYOUT1			0x00000090
>  
> @@ -72,13 +83,24 @@
>  
>  #define BP_BCH_FLASH0LAYOUT1_ECCN		12
>  #define BM_BCH_FLASH0LAYOUT1_ECCN	(0xf << BP_BCH_FLASH0LAYOUT1_ECCN)
> -#define BF_BCH_FLASH0LAYOUT1_ECCN(v)		\
> -	(((v) << BP_BCH_FLASH0LAYOUT1_ECCN) & BM_BCH_FLASH0LAYOUT1_ECCN)
> +#define MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN		11
> +#define MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN	(0x1f << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)
> +#define BF_BCH_FLASH0LAYOUT1_ECCN(v, x)				\
> +	(GPMI_IS_MX6Q(x)					\
> +		? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)	\
> +			& MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN)	\
> +		: (((v) << BP_BCH_FLASH0LAYOUT1_ECCN)		\
> +			& BM_BCH_FLASH0LAYOUT1_ECCN)		\
> +	)
>  
>  #define BP_BCH_FLASH0LAYOUT1_DATAN_SIZE		0
>  #define BM_BCH_FLASH0LAYOUT1_DATAN_SIZE		\
>  			(0xfff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
> -#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v)	\
> -	(((v) << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE) \
> -					 & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)
> +#define MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE	\
> +			(0x3ff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
> +#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v, x)				\
> +	(GPMI_IS_MX6Q(x)						\
> +		? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)	\
> +		: ((v) & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)		\
> +	)
>  #endif
> diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
> index fa5200b..a1f4332 100644
> --- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
> +++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
> @@ -224,13 +224,13 @@ int bch_set_geometry(struct gpmi_nand_data *this)
>  	/* Configure layout 0. */
>  	writel(BF_BCH_FLASH0LAYOUT0_NBLOCKS(block_count)
>  			| BF_BCH_FLASH0LAYOUT0_META_SIZE(metadata_size)
> -			| BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength)
> -			| BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size),
> +			| BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this)
> +			| BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this),
>  			r->bch_regs + HW_BCH_FLASH0LAYOUT0);
>  
>  	writel(BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size)
> -			| BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength)
> -			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size),
> +			| BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this)
> +			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this),
>  			r->bch_regs + HW_BCH_FLASH0LAYOUT1);
>  
>  	/* Set *all* chip selects to use layout 0. */
> @@ -256,11 +256,12 @@ static unsigned int ns_to_cycles(unsigned int time,
>  	return max(k, min);
>  }
>  
> +#define DEF_MIN_PROP_DELAY	5
> +#define DEF_MAX_PROP_DELAY	9
>  /* Apply timing to current hardware conditions. */
>  static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
>  					struct gpmi_nfc_hardware_timing *hw)
>  {
> -	struct gpmi_nand_platform_data *pdata = this->pdata;
>  	struct timing_threshod *nfc = &timing_default_threshold;
>  	struct nand_chip *nand = &this->nand;
>  	struct nand_timing target = this->timing;
> @@ -277,8 +278,8 @@ static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
>  	int ideal_sample_delay_in_ns;
>  	unsigned int sample_delay_factor;
>  	int tEYE;
> -	unsigned int min_prop_delay_in_ns = pdata->min_prop_delay_in_ns;
> -	unsigned int max_prop_delay_in_ns = pdata->max_prop_delay_in_ns;
> +	unsigned int min_prop_delay_in_ns = DEF_MIN_PROP_DELAY;
> +	unsigned int max_prop_delay_in_ns = DEF_MAX_PROP_DELAY;
>  
>  	/*
>  	 * If there are multiple chips, we need to relax the timings to allow
> @@ -804,7 +805,8 @@ int gpmi_is_ready(struct gpmi_nand_data *this, unsigned chip)
>  	if (GPMI_IS_MX23(this)) {
>  		mask = MX23_BM_GPMI_DEBUG_READY0 << chip;
>  		reg = readl(r->gpmi_regs + HW_GPMI_DEBUG);
> -	} else if (GPMI_IS_MX28(this)) {
> +	} else if (GPMI_IS_MX28(this) || GPMI_IS_MX6Q(this)) {
> +		/* MX28 shares the same R/B register as MX6Q. */
>  		mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip);
>  		reg = readl(r->gpmi_regs + HW_GPMI_STAT);
>  	} else
> diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> index 75b1dde..e0ea598 100644
> --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> @@ -24,6 +24,9 @@
>  #include <linux/module.h>
>  #include <linux/mtd/gpmi-nand.h>
>  #include <linux/mtd/partitions.h>
> +#include <linux/of_address.h>

This line is probably not needed?

> +#include <linux/of_device.h>
> +#include <linux/of_irq.h>

Ditto?

>  #include "gpmi-nand.h"
>  
>  /* add our owner bbt descriptor */
> @@ -385,7 +388,7 @@ static void release_bch_irq(struct gpmi_nand_data *this)
>  static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
>  {
>  	struct gpmi_nand_data *this = param;
> -	struct resource *r = this->private;
> +	int dma_channel = (int)this->private;
>  
>  	if (!mxs_dma_is_apbh(chan))
>  		return false;
> @@ -397,7 +400,7 @@ static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
>  	 *	for mx28 :	MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7
>  	 *		(These eight channels share the same IRQ!)
>  	 */
> -	if (r->start <= chan->chan_id && chan->chan_id <= r->end) {
> +	if (dma_channel == chan->chan_id) {
>  		chan->private = &this->dma_data;
>  		return true;
>  	}
> @@ -417,57 +420,45 @@ static void release_dma_channels(struct gpmi_nand_data *this)
>  static int __devinit acquire_dma_channels(struct gpmi_nand_data *this)
>  {
>  	struct platform_device *pdev = this->pdev;
> -	struct gpmi_nand_platform_data *pdata = this->pdata;
> -	struct resources *res = &this->resources;
> -	struct resource *r, *r_dma;
> -	unsigned int i;
> +	struct resource *r_dma;
> +	struct device_node *dn;
> +	int dma_channel;
> +	unsigned int ret;
> +	struct dma_chan *dma_chan;
> +	dma_cap_mask_t mask;
> +
> +	/* dma channel, we only use the first one. */
> +	dn = pdev->dev.of_node;
> +	ret = of_property_read_u32(dn, "fsl,gpmi-dma-channel", &dma_channel);
> +	if (ret) {
> +		pr_err("unable to get DMA channel from dt.\n");
> +		goto acquire_err;
> +	}
> +	this->private = (void *)dma_channel;
>  
> -	r = platform_get_resource_byname(pdev, IORESOURCE_DMA,
> -					GPMI_NAND_DMA_CHANNELS_RES_NAME);

You are adding device tree support into a driver that is working fine
for non-DT probe.  So before all the users of this driver are converted
to DT, you have to ensure the driver works for both non-DT and DT users
in a single image when you add DT support for it.

So above code should be something like:

	if (dn) {
		/* get channel number from device tree */
		......
	} else {
		/* otherwise it works as before */
	}

> +	/* gpmi dma interrupt */
>  	r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
>  					GPMI_NAND_DMA_INTERRUPT_RES_NAME);
> -	if (!r || !r_dma) {
> +	if (!r_dma) {
>  		pr_err("Can't get resource for DMA\n");
> -		return -ENXIO;
> +		goto acquire_err;
>  	}
> +	this->dma_data.chan_irq = r_dma->start;
>  
> -	/* used in gpmi_dma_filter() */
> -	this->private = r;
> -
> -	for (i = r->start; i <= r->end; i++) {
> -		struct dma_chan *dma_chan;
> -		dma_cap_mask_t mask;
> -
> -		if (i - r->start >= pdata->max_chip_count)
> -			break;
> +	/* request dma channel */
> +	dma_cap_zero(mask);
> +	dma_cap_set(DMA_SLAVE, mask);
>  
> -		dma_cap_zero(mask);
> -		dma_cap_set(DMA_SLAVE, mask);
> -
> -		/* get the DMA interrupt */
> -		if (r_dma->start == r_dma->end) {
> -			/* only register the first. */
> -			if (i == r->start)
> -				this->dma_data.chan_irq = r_dma->start;
> -			else
> -				this->dma_data.chan_irq = NO_IRQ;
> -		} else
> -			this->dma_data.chan_irq = r_dma->start + (i - r->start);
> -
> -		dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
> -		if (!dma_chan)
> -			goto acquire_err;
> -
> -		/* fill the first empty item */
> -		this->dma_chans[i - r->start] = dma_chan;
> +	dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
> +	if (!dma_chan) {
> +		pr_err("dma_request_channel failed.\n");
> +		goto acquire_err;
>  	}
>  
> -	res->dma_low_channel = r->start;
> -	res->dma_high_channel = i;
> +	this->dma_chans[0] = dma_chan;
>  	return 0;
>  
>  acquire_err:
> -	pr_err("Can't acquire DMA channel %u\n", i);
>  	release_dma_channels(this);
>  	return -EINVAL;
>  }
> @@ -1461,9 +1452,9 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)
>  
>  static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
>  {
> -	struct gpmi_nand_platform_data *pdata = this->pdata;
>  	struct mtd_info  *mtd = &this->mtd;
>  	struct nand_chip *chip = &this->nand;
> +	struct mtd_part_parser_data ppdata = {};
>  	int ret;
>  
>  	/* init current chip */
> @@ -1501,14 +1492,14 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
>  	if (ret)
>  		goto err_out;
>  
> -	ret = nand_scan(mtd, pdata->max_chip_count);
> +	ret = nand_scan(mtd, 1);

Ditto, you should not break non-DT users.

>  	if (ret) {
>  		pr_err("Chip scan failed\n");
>  		goto err_out;
>  	}
>  
> -	ret = mtd_device_parse_register(mtd, NULL, NULL,
> -			pdata->partitions, pdata->partition_count);
> +	ppdata.of_node = this->pdev->dev.of_node;
> +	ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
>  	if (ret)
>  		goto err_out;
>  	return 0;
> @@ -1518,12 +1509,41 @@ err_out:
>  	return ret;
>  }
>  
> +static const struct platform_device_id gpmi_ids[] = {
> +	{ .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
> +	{ .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
> +	{ .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
> +	{},
> +};
> +
> +static const struct of_device_id gpmi_nand_id_table[] = {
> +	{
> +		.compatible = "fsl,imx23-gpmi-nand",
> +		.data = (void *)&gpmi_ids[IS_MX23]
> +	}, {
> +		.compatible = "fsl,imx28-gpmi-nand",
> +		.data = (void *)&gpmi_ids[IS_MX28]
> +	}, {
> +		.compatible = "fsl,imx6q-gpmi-nand",
> +		.data = (void *)&gpmi_ids[IS_MX6Q]
> +	}, {}
> +};
> +MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
> +
>  static int __devinit gpmi_nand_probe(struct platform_device *pdev)
>  {
> -	struct gpmi_nand_platform_data *pdata = pdev->dev.platform_data;
>  	struct gpmi_nand_data *this;
> +	const struct of_device_id *of_id;
>  	int ret;
>  
> +	of_id = of_match_device(gpmi_nand_id_table, &pdev->dev);
> +	if (of_id)
> +		pdev->id_entry = of_id->data;
> +	else {
> +		pr_err("Failed to find the right device id.\n");
> +		return -ENOMEM;
> +	}
> +

Ditto, it should still work for non-DT users.

BTW, it seems Documentation/CodingStyle suggest put brace like the
following.

	if (condition) {
		do_this();
	} else {
		otherwise_do_this();
		otherwise_do_that();
	}

Regards,
Shawn

>  	this = kzalloc(sizeof(*this), GFP_KERNEL);
>  	if (!this) {
>  		pr_err("Failed to allocate per-device memory\n");
> @@ -1533,13 +1553,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, this);
>  	this->pdev  = pdev;
>  	this->dev   = &pdev->dev;
> -	this->pdata = pdata;
> -
> -	if (pdata->platform_init) {
> -		ret = pdata->platform_init();
> -		if (ret)
> -			goto platform_init_error;
> -	}
>  
>  	ret = acquire_resources(this);
>  	if (ret)
> @@ -1557,7 +1570,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
>  
>  exit_nfc_init:
>  	release_resources(this);
> -platform_init_error:
>  exit_acquire_resources:
>  	platform_set_drvdata(pdev, NULL);
>  	kfree(this);
> @@ -1575,19 +1587,10 @@ static int __exit gpmi_nand_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -static const struct platform_device_id gpmi_ids[] = {
> -	{
> -		.name = "imx23-gpmi-nand",
> -		.driver_data = IS_MX23,
> -	}, {
> -		.name = "imx28-gpmi-nand",
> -		.driver_data = IS_MX28,
> -	}, {},
> -};
> -
>  static struct platform_driver gpmi_nand_driver = {
>  	.driver = {
>  		.name = "gpmi-nand",
> +		.of_match_table = gpmi_nand_id_table,
>  	},
>  	.probe   = gpmi_nand_probe,
>  	.remove  = __exit_p(gpmi_nand_remove),
> diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
> index ec6180d..ce5daa1 100644
> --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
> +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
> @@ -266,8 +266,10 @@ extern int gpmi_read_page(struct gpmi_nand_data *,
>  #define STATUS_UNCORRECTABLE	0xfe
>  
>  /* Use the platform_id to distinguish different Archs. */
> -#define IS_MX23			0x1
> -#define IS_MX28			0x2
> +#define IS_MX23			0x0
> +#define IS_MX28			0x1
> +#define IS_MX6Q			0x2
>  #define GPMI_IS_MX23(x)		((x)->pdev->id_entry->driver_data == IS_MX23)
>  #define GPMI_IS_MX28(x)		((x)->pdev->id_entry->driver_data == IS_MX28)
> +#define GPMI_IS_MX6Q(x)		((x)->pdev->id_entry->driver_data == IS_MX6Q)
>  #endif
> diff --git a/include/linux/mtd/gpmi-nand.h b/include/linux/mtd/gpmi-nand.h
> index 69b6dbf..ed3c4e0 100644
> --- a/include/linux/mtd/gpmi-nand.h
> +++ b/include/linux/mtd/gpmi-nand.h
> @@ -23,12 +23,12 @@
>  #define GPMI_NAND_RES_SIZE	6
>  
>  /* Resource names for the GPMI NAND driver. */
> -#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME  "GPMI NAND GPMI Registers"
> +#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME  "gpmi-nand"
>  #define GPMI_NAND_GPMI_INTERRUPT_RES_NAME  "GPMI NAND GPMI Interrupt"
> -#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME   "GPMI NAND BCH Registers"
> -#define GPMI_NAND_BCH_INTERRUPT_RES_NAME   "GPMI NAND BCH Interrupt"
> +#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME   "bch"
> +#define GPMI_NAND_BCH_INTERRUPT_RES_NAME   "bch"
>  #define GPMI_NAND_DMA_CHANNELS_RES_NAME    "GPMI NAND DMA Channels"
> -#define GPMI_NAND_DMA_INTERRUPT_RES_NAME   "GPMI NAND DMA Interrupt"
> +#define GPMI_NAND_DMA_INTERRUPT_RES_NAME   "gpmi-dma"
>  
>  /**
>   * struct gpmi_nand_platform_data - GPMI NAND driver platform data.
> -- 
> 1.7.0.4
> 
> 

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

* Re: [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
  2012-05-01  7:49     ` Shawn Guo
@ 2012-05-02  2:50       ` Huang Shijie
  -1 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-05-02  2:50 UTC (permalink / raw)
  To: Shawn Guo; +Cc: linux-mtd, linux-arm-kernel, dedekind1

Hi Shawn:

thanks a lot for your review.
> You are adding device tree support into a driver that is working fine
> for non-DT probe.  So before all the users of this driver are converted
> to DT, you have to ensure the driver works for both non-DT and DT users
> in a single image when you add DT support for it.
The current gpmi-nand driver can not work in the non-DT, as you known, 
there are
several patches which are not accepted to you.

So, does it make sense to still maintain the support for non-DT?

So i prefer to convert the gpmi-nand to a pure DT driver. make the code 
clear and simple.

> So above code should be something like:
>
> 	if (dn) {
> 		/* get channel number from device tree */
> 		......
> 	} else {
> 		/* otherwise it works as before */
> 	}
>
>> >  +	/* gpmi dma interrupt */
>> >    	r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
>> >    					GPMI_NAND_DMA_INTERRUPT_RES_NAME);
>> >  -	if (!r || !r_dma) {
>> >  +	if (!r_dma) {
>> >    		pr_err("Can't get resource for DMA\n");
>> >  -		return -ENXIO;
>> >  +		goto acquire_err;
>> >    	}
>> >  +	this->dma_data.chan_irq = r_dma->start;
>> >  
>> >  -	/* used in gpmi_dma_filter() */
>> >  -	this->private = r;
>> >  -
>> >  -	for (i = r->start; i<= r->end; i++) {
>> >  -		struct dma_chan *dma_chan;
>> >  -		dma_cap_mask_t mask;
>> >  -
>> >  -		if (i - r->start>= pdata->max_chip_count)
>> >  -			break;
>> >  +	/* request dma channel */
>> >  +	dma_cap_zero(mask);
>> >  +	dma_cap_set(DMA_SLAVE, mask);
>> >  
>> >  -		dma_cap_zero(mask);
>> >  -		dma_cap_set(DMA_SLAVE, mask);
>> >  -
>> >  -		/* get the DMA interrupt */
>> >  -		if (r_dma->start == r_dma->end) {
>> >  -			/* only register the first. */
>> >  -			if (i == r->start)
>> >  -				this->dma_data.chan_irq = r_dma->start;
>> >  -			else
>> >  -				this->dma_data.chan_irq = NO_IRQ;
>> >  -		} else
>> >  -			this->dma_data.chan_irq = r_dma->start + (i - r->start);
>> >  -
>> >  -		dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
>> >  -		if (!dma_chan)
>> >  -			goto acquire_err;
>> >  -
>> >  -		/* fill the first empty item */
>> >  -		this->dma_chans[i - r->start] = dma_chan;
>> >  +	dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
>> >  +	if (!dma_chan) {
>> >  +		pr_err("dma_request_channel failed.\n");
>> >  +		goto acquire_err;
>> >    	}
>> >  
>> >  -	res->dma_low_channel = r->start;
>> >  -	res->dma_high_channel = i;
>> >  +	this->dma_chans[0] = dma_chan;
>> >    	return 0;
>> >  
>> >    acquire_err:
>> >  -	pr_err("Can't acquire DMA channel %u\n", i);
>> >    	release_dma_channels(this);
>> >    	return -EINVAL;
>> >    }
>> >  @@ -1461,9 +1452,9 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)
>> >  
>> >    static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
>> >    {
>> >  -	struct gpmi_nand_platform_data *pdata = this->pdata;
>> >    	struct mtd_info  *mtd =&this->mtd;
>> >    	struct nand_chip *chip =&this->nand;
>> >  +	struct mtd_part_parser_data ppdata = {};
>> >    	int ret;
>> >  
>> >    	/* init current chip */
>> >  @@ -1501,14 +1492,14 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
>> >    	if (ret)
>> >    		goto err_out;
>> >  
>> >  -	ret = nand_scan(mtd, pdata->max_chip_count);
>> >  +	ret = nand_scan(mtd, 1);
> Ditto, you should not break non-DT users.
>
>> >    	if (ret) {
>> >    		pr_err("Chip scan failed\n");
>> >    		goto err_out;
>> >    	}
>> >  
>> >  -	ret = mtd_device_parse_register(mtd, NULL, NULL,
>> >  -			pdata->partitions, pdata->partition_count);
>> >  +	ppdata.of_node = this->pdev->dev.of_node;
>> >  +	ret = mtd_device_parse_register(mtd, NULL,&ppdata, NULL, 0);
>> >    	if (ret)
>> >    		goto err_out;
>> >    	return 0;
>> >  @@ -1518,12 +1509,41 @@ err_out:
>> >    	return ret;
>> >    }
>> >  
>> >  +static const struct platform_device_id gpmi_ids[] = {
>> >  +	{ .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
>> >  +	{ .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
>> >  +	{ .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
>> >  +	{},
>> >  +};
>> >  +
>> >  +static const struct of_device_id gpmi_nand_id_table[] = {
>> >  +	{
>> >  +		.compatible = "fsl,imx23-gpmi-nand",
>> >  +		.data = (void *)&gpmi_ids[IS_MX23]
>> >  +	}, {
>> >  +		.compatible = "fsl,imx28-gpmi-nand",
>> >  +		.data = (void *)&gpmi_ids[IS_MX28]
>> >  +	}, {
>> >  +		.compatible = "fsl,imx6q-gpmi-nand",
>> >  +		.data = (void *)&gpmi_ids[IS_MX6Q]
>> >  +	}, {}
>> >  +};
>> >  +MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
>> >  +
>> >    static int __devinit gpmi_nand_probe(struct platform_device *pdev)
>> >    {
>> >  -	struct gpmi_nand_platform_data *pdata = pdev->dev.platform_data;
>> >    	struct gpmi_nand_data *this;
>> >  +	const struct of_device_id *of_id;
>> >    	int ret;
>> >  
>> >  +	of_id = of_match_device(gpmi_nand_id_table,&pdev->dev);
>> >  +	if (of_id)
>> >  +		pdev->id_entry = of_id->data;
>> >  +	else {
>> >  +		pr_err("Failed to find the right device id.\n");
>> >  +		return -ENOMEM;
>> >  +	}
>> >  +
> Ditto, it should still work for non-DT users.
>
> BTW, it seems Documentation/CodingStyle suggest put brace like the
> following.
>
> 	if (condition) {
> 		do_this();
> 	} else {
> 		otherwise_do_this();
> 		otherwise_do_that();
> 	}
thanks.
But the Documention/CodingStyle tells us "Do not unnecessarily use 
braces where a single statement will do."


Best Regards
Huang Shijie

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

* [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
@ 2012-05-02  2:50       ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-05-02  2:50 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Shawn:

thanks a lot for your review.
> You are adding device tree support into a driver that is working fine
> for non-DT probe.  So before all the users of this driver are converted
> to DT, you have to ensure the driver works for both non-DT and DT users
> in a single image when you add DT support for it.
The current gpmi-nand driver can not work in the non-DT, as you known, 
there are
several patches which are not accepted to you.

So, does it make sense to still maintain the support for non-DT?

So i prefer to convert the gpmi-nand to a pure DT driver. make the code 
clear and simple.

> So above code should be something like:
>
> 	if (dn) {
> 		/* get channel number from device tree */
> 		......
> 	} else {
> 		/* otherwise it works as before */
> 	}
>
>> >  +	/* gpmi dma interrupt */
>> >    	r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
>> >    					GPMI_NAND_DMA_INTERRUPT_RES_NAME);
>> >  -	if (!r || !r_dma) {
>> >  +	if (!r_dma) {
>> >    		pr_err("Can't get resource for DMA\n");
>> >  -		return -ENXIO;
>> >  +		goto acquire_err;
>> >    	}
>> >  +	this->dma_data.chan_irq = r_dma->start;
>> >  
>> >  -	/* used in gpmi_dma_filter() */
>> >  -	this->private = r;
>> >  -
>> >  -	for (i = r->start; i<= r->end; i++) {
>> >  -		struct dma_chan *dma_chan;
>> >  -		dma_cap_mask_t mask;
>> >  -
>> >  -		if (i - r->start>= pdata->max_chip_count)
>> >  -			break;
>> >  +	/* request dma channel */
>> >  +	dma_cap_zero(mask);
>> >  +	dma_cap_set(DMA_SLAVE, mask);
>> >  
>> >  -		dma_cap_zero(mask);
>> >  -		dma_cap_set(DMA_SLAVE, mask);
>> >  -
>> >  -		/* get the DMA interrupt */
>> >  -		if (r_dma->start == r_dma->end) {
>> >  -			/* only register the first. */
>> >  -			if (i == r->start)
>> >  -				this->dma_data.chan_irq = r_dma->start;
>> >  -			else
>> >  -				this->dma_data.chan_irq = NO_IRQ;
>> >  -		} else
>> >  -			this->dma_data.chan_irq = r_dma->start + (i - r->start);
>> >  -
>> >  -		dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
>> >  -		if (!dma_chan)
>> >  -			goto acquire_err;
>> >  -
>> >  -		/* fill the first empty item */
>> >  -		this->dma_chans[i - r->start] = dma_chan;
>> >  +	dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
>> >  +	if (!dma_chan) {
>> >  +		pr_err("dma_request_channel failed.\n");
>> >  +		goto acquire_err;
>> >    	}
>> >  
>> >  -	res->dma_low_channel = r->start;
>> >  -	res->dma_high_channel = i;
>> >  +	this->dma_chans[0] = dma_chan;
>> >    	return 0;
>> >  
>> >    acquire_err:
>> >  -	pr_err("Can't acquire DMA channel %u\n", i);
>> >    	release_dma_channels(this);
>> >    	return -EINVAL;
>> >    }
>> >  @@ -1461,9 +1452,9 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)
>> >  
>> >    static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
>> >    {
>> >  -	struct gpmi_nand_platform_data *pdata = this->pdata;
>> >    	struct mtd_info  *mtd =&this->mtd;
>> >    	struct nand_chip *chip =&this->nand;
>> >  +	struct mtd_part_parser_data ppdata = {};
>> >    	int ret;
>> >  
>> >    	/* init current chip */
>> >  @@ -1501,14 +1492,14 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
>> >    	if (ret)
>> >    		goto err_out;
>> >  
>> >  -	ret = nand_scan(mtd, pdata->max_chip_count);
>> >  +	ret = nand_scan(mtd, 1);
> Ditto, you should not break non-DT users.
>
>> >    	if (ret) {
>> >    		pr_err("Chip scan failed\n");
>> >    		goto err_out;
>> >    	}
>> >  
>> >  -	ret = mtd_device_parse_register(mtd, NULL, NULL,
>> >  -			pdata->partitions, pdata->partition_count);
>> >  +	ppdata.of_node = this->pdev->dev.of_node;
>> >  +	ret = mtd_device_parse_register(mtd, NULL,&ppdata, NULL, 0);
>> >    	if (ret)
>> >    		goto err_out;
>> >    	return 0;
>> >  @@ -1518,12 +1509,41 @@ err_out:
>> >    	return ret;
>> >    }
>> >  
>> >  +static const struct platform_device_id gpmi_ids[] = {
>> >  +	{ .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
>> >  +	{ .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
>> >  +	{ .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
>> >  +	{},
>> >  +};
>> >  +
>> >  +static const struct of_device_id gpmi_nand_id_table[] = {
>> >  +	{
>> >  +		.compatible = "fsl,imx23-gpmi-nand",
>> >  +		.data = (void *)&gpmi_ids[IS_MX23]
>> >  +	}, {
>> >  +		.compatible = "fsl,imx28-gpmi-nand",
>> >  +		.data = (void *)&gpmi_ids[IS_MX28]
>> >  +	}, {
>> >  +		.compatible = "fsl,imx6q-gpmi-nand",
>> >  +		.data = (void *)&gpmi_ids[IS_MX6Q]
>> >  +	}, {}
>> >  +};
>> >  +MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
>> >  +
>> >    static int __devinit gpmi_nand_probe(struct platform_device *pdev)
>> >    {
>> >  -	struct gpmi_nand_platform_data *pdata = pdev->dev.platform_data;
>> >    	struct gpmi_nand_data *this;
>> >  +	const struct of_device_id *of_id;
>> >    	int ret;
>> >  
>> >  +	of_id = of_match_device(gpmi_nand_id_table,&pdev->dev);
>> >  +	if (of_id)
>> >  +		pdev->id_entry = of_id->data;
>> >  +	else {
>> >  +		pr_err("Failed to find the right device id.\n");
>> >  +		return -ENOMEM;
>> >  +	}
>> >  +
> Ditto, it should still work for non-DT users.
>
> BTW, it seems Documentation/CodingStyle suggest put brace like the
> following.
>
> 	if (condition) {
> 		do_this();
> 	} else {
> 		otherwise_do_this();
> 		otherwise_do_that();
> 	}
thanks.
But the Documention/CodingStyle tells us "Do not unnecessarily use 
braces where a single statement will do."


Best Regards
Huang Shijie

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

* Re: [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
  2012-05-01  7:49     ` Shawn Guo
@ 2012-05-02  2:52       ` Huang Shijie
  -1 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-05-02  2:52 UTC (permalink / raw)
  To: Shawn Guo; +Cc: linux-mtd, linux-arm-kernel, dedekind1

于 2012年05月01日 15:49, Shawn Guo 写道:
> BTW, it seems Documentation/CodingStyle suggest put brace like the
> following.
>
> 	if (condition) {
> 		do_this();
> 	} else {
> 		otherwise_do_this();
> 		otherwise_do_that();
> 	}
sorry. you are right.

Best Regards
Huang Shijie

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

* [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
@ 2012-05-02  2:52       ` Huang Shijie
  0 siblings, 0 replies; 28+ messages in thread
From: Huang Shijie @ 2012-05-02  2:52 UTC (permalink / raw)
  To: linux-arm-kernel

? 2012?05?01? 15:49, Shawn Guo ??:
> BTW, it seems Documentation/CodingStyle suggest put brace like the
> following.
>
> 	if (condition) {
> 		do_this();
> 	} else {
> 		otherwise_do_this();
> 		otherwise_do_that();
> 	}
sorry. you are right.

Best Regards
Huang Shijie

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

* Re: [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
  2012-05-02  2:50       ` Huang Shijie
@ 2012-05-02  5:21         ` Shawn Guo
  -1 siblings, 0 replies; 28+ messages in thread
From: Shawn Guo @ 2012-05-02  5:21 UTC (permalink / raw)
  To: Huang Shijie; +Cc: linux-mtd, linux-arm-kernel, dedekind1

On Wed, May 02, 2012 at 10:50:21AM +0800, Huang Shijie wrote:
> Hi Shawn:
> 
> thanks a lot for your review.
> >You are adding device tree support into a driver that is working fine
> >for non-DT probe.  So before all the users of this driver are converted
> >to DT, you have to ensure the driver works for both non-DT and DT users
> >in a single image when you add DT support for it.
> The current gpmi-nand driver can not work in the non-DT, as you
> known, there are
> several patches which are not accepted to you.
> 
> So, does it make sense to still maintain the support for non-DT?
> 
> So i prefer to convert the gpmi-nand to a pure DT driver. make the
> code clear and simple.
> 
Yeah, I'm fine with that.

-- 
Regards,
Shawn

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

* [PATCH v2 1/3] mtd: gpmi: add device tree support for mx6q and mx28
@ 2012-05-02  5:21         ` Shawn Guo
  0 siblings, 0 replies; 28+ messages in thread
From: Shawn Guo @ 2012-05-02  5:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, May 02, 2012 at 10:50:21AM +0800, Huang Shijie wrote:
> Hi Shawn:
> 
> thanks a lot for your review.
> >You are adding device tree support into a driver that is working fine
> >for non-DT probe.  So before all the users of this driver are converted
> >to DT, you have to ensure the driver works for both non-DT and DT users
> >in a single image when you add DT support for it.
> The current gpmi-nand driver can not work in the non-DT, as you
> known, there are
> several patches which are not accepted to you.
> 
> So, does it make sense to still maintain the support for non-DT?
> 
> So i prefer to convert the gpmi-nand to a pure DT driver. make the
> code clear and simple.
> 
Yeah, I'm fine with that.

-- 
Regards,
Shawn

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

end of thread, other threads:[~2012-05-02  5:21 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-25  3:06 [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28 Huang Shijie
2012-04-25  3:06 ` Huang Shijie
2012-04-25  3:06 ` [PATCH v2 1/3] mtd: gpmi: add device tree " Huang Shijie
2012-04-25  3:06   ` Huang Shijie
2012-05-01  7:49   ` Shawn Guo
2012-05-01  7:49     ` Shawn Guo
2012-05-02  2:50     ` Huang Shijie
2012-05-02  2:50       ` Huang Shijie
2012-05-02  5:21       ` Shawn Guo
2012-05-02  5:21         ` Shawn Guo
2012-05-02  2:52     ` Huang Shijie
2012-05-02  2:52       ` Huang Shijie
2012-04-25  3:06 ` [PATCH v2 2/3] ARM: mx28: add gpmi-nand dt support Huang Shijie
2012-04-25  3:06   ` Huang Shijie
2012-04-25  3:06 ` [PATCH v2 3/3] ARM: mx6q: " Huang Shijie
2012-04-25  3:06   ` Huang Shijie
2012-04-25  6:41 ` [PATCH v2 0/3] add gpmi-nand dt support for mx6q and mx28 Dirk Behme
2012-04-25  6:41   ` Dirk Behme
2012-04-25  6:51   ` Huang Shijie
2012-04-25  6:51     ` Huang Shijie
2012-04-25  7:10     ` Dirk Behme
2012-04-25  7:10       ` Dirk Behme
2012-04-25  7:19       ` Huang Shijie
2012-04-25  7:19         ` Huang Shijie
2012-04-28 12:00 ` Artem Bityutskiy
2012-04-28 12:00   ` Artem Bityutskiy
2012-04-28 13:31   ` Huang Shijie
2012-04-28 13:31     ` Huang Shijie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.