All of lore.kernel.org
 help / color / mirror / Atom feed
* [FOR 3.3 PATCH 1/6] ATMEL: fix nand ecc support
@ 2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, Jean-Christophe PLAGNIOL-VILLARD, linux-mtd

so we can now choose for the board the ecc mode (ecc soft, soft bch, no ecc
and hardware)

set ecc mode in the boards to soft as currently in the driver

move platform data to a common header
include/linux/platform_data/atmel_nand.h

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: linux-mtd@lists.infradead.org
---
 arch/arm/mach-at91/board-afeb-9260v1.c      |    1 +
 arch/arm/mach-at91/board-cam60.c            |    1 +
 arch/arm/mach-at91/board-cap9adk.c          |    1 +
 arch/arm/mach-at91/board-cpu9krea.c         |    1 +
 arch/arm/mach-at91/board-dt.c               |    1 +
 arch/arm/mach-at91/board-kb9202.c           |    1 +
 arch/arm/mach-at91/board-neocore926.c       |    1 +
 arch/arm/mach-at91/board-qil-a9260.c        |    1 +
 arch/arm/mach-at91/board-rm9200dk.c         |    1 +
 arch/arm/mach-at91/board-sam9-l9260.c       |    1 +
 arch/arm/mach-at91/board-sam9260ek.c        |    1 +
 arch/arm/mach-at91/board-sam9261ek.c        |    1 +
 arch/arm/mach-at91/board-sam9263ek.c        |    1 +
 arch/arm/mach-at91/board-sam9g20ek.c        |    1 +
 arch/arm/mach-at91/board-sam9m10g45ek.c     |    1 +
 arch/arm/mach-at91/board-sam9rlek.c         |    1 +
 arch/arm/mach-at91/board-snapper9260.c      |    1 +
 arch/arm/mach-at91/board-stamp9g20.c        |    1 +
 arch/arm/mach-at91/board-usb-a926x.c        |    1 +
 arch/arm/mach-at91/board-yl-9200.c          |    1 +
 arch/arm/mach-at91/include/mach/board.h     |   13 +------------
 arch/avr32/boards/atngw100/setup.c          |    1 +
 arch/avr32/boards/atstk1000/atstk1002.c     |    1 +
 arch/avr32/mach-at32ap/include/mach/board.h |   13 +------------
 drivers/mtd/nand/atmel_nand.c               |   25 ++++++-------------------
 include/linux/platform_data/atmel.h         |   26 ++++++++++++++++++++++++++
 26 files changed, 56 insertions(+), 43 deletions(-)
 create mode 100644 include/linux/platform_data/atmel.h

diff --git a/arch/arm/mach-at91/board-afeb-9260v1.c b/arch/arm/mach-at91/board-afeb-9260v1.c
index 3bb4069..161efba 100644
--- a/arch/arm/mach-at91/board-afeb-9260v1.c
+++ b/arch/arm/mach-at91/board-afeb-9260v1.c
@@ -138,6 +138,7 @@ static struct atmel_nand_data __initdata afeb9260_nand_data = {
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
 	.bus_width_16	= 0,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= afeb9260_nand_partition,
 	.num_parts	= ARRAY_SIZE(afeb9260_nand_partition),
 	.det_pin	= -EINVAL,
diff --git a/arch/arm/mach-at91/board-cam60.c b/arch/arm/mach-at91/board-cam60.c
index 8510e9e..c6d44ee 100644
--- a/arch/arm/mach-at91/board-cam60.c
+++ b/arch/arm/mach-at91/board-cam60.c
@@ -140,6 +140,7 @@ static struct atmel_nand_data __initdata cam60_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PA9,
 	.enable_pin	= AT91_PIN_PA7,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= cam60_nand_partition,
 	.num_parts	= ARRAY_SIZE(cam60_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-cap9adk.c b/arch/arm/mach-at91/board-cap9adk.c
index e0165a2..9c05eea 100644
--- a/arch/arm/mach-at91/board-cap9adk.c
+++ b/arch/arm/mach-at91/board-cap9adk.c
@@ -178,6 +178,7 @@ static struct atmel_nand_data __initdata cap9adk_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= -EINVAL,
 	.enable_pin	= AT91_PIN_PD15,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= cap9adk_nand_partitions,
 	.num_parts	= ARRAY_SIZE(cap9adk_nand_partitions),
 };
diff --git a/arch/arm/mach-at91/board-cpu9krea.c b/arch/arm/mach-at91/board-cpu9krea.c
index 8c60e0d..e69e2a1 100644
--- a/arch/arm/mach-at91/board-cpu9krea.c
+++ b/arch/arm/mach-at91/board-cpu9krea.c
@@ -116,6 +116,7 @@ static struct atmel_nand_data __initdata cpu9krea_nand_data = {
 	.enable_pin	= AT91_PIN_PC14,
 	.bus_width_16	= 0,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 };
 
 #ifdef CONFIG_MACH_CPU9260
diff --git a/arch/arm/mach-at91/board-dt.c b/arch/arm/mach-at91/board-dt.c
index bb6b434..552390d 100644
--- a/arch/arm/mach-at91/board-dt.c
+++ b/arch/arm/mach-at91/board-dt.c
@@ -53,6 +53,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC8,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 };
 
 static struct sam9_smc_config __initdata ek_nand_smc_config = {
diff --git a/arch/arm/mach-at91/board-kb9202.c b/arch/arm/mach-at91/board-kb9202.c
index 4d23b6a..04d9b8e 100644
--- a/arch/arm/mach-at91/board-kb9202.c
+++ b/arch/arm/mach-at91/board-kb9202.c
@@ -107,6 +107,7 @@ static struct atmel_nand_data __initdata kb9202_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC29,
 	.enable_pin	= AT91_PIN_PC28,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= kb9202_nand_partition,
 	.num_parts	= ARRAY_SIZE(kb9202_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-neocore926.c b/arch/arm/mach-at91/board-neocore926.c
index 3f8617c..57d5f6a 100644
--- a/arch/arm/mach-at91/board-neocore926.c
+++ b/arch/arm/mach-at91/board-neocore926.c
@@ -190,6 +190,7 @@ static struct atmel_nand_data __initdata neocore926_nand_data = {
 	.rdy_pin		= AT91_PIN_PB19,
 	.rdy_pin_active_low	= 1,
 	.enable_pin		= AT91_PIN_PD15,
+	.ecc_mode		= NAND_ECC_SOFT,
 	.parts			= neocore926_nand_partition,
 	.num_parts		= ARRAY_SIZE(neocore926_nand_partition),
 	.det_pin		= -EINVAL,
diff --git a/arch/arm/mach-at91/board-qil-a9260.c b/arch/arm/mach-at91/board-qil-a9260.c
index e029d22..97907e4 100644
--- a/arch/arm/mach-at91/board-qil-a9260.c
+++ b/arch/arm/mach-at91/board-qil-a9260.c
@@ -138,6 +138,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-rm9200dk.c b/arch/arm/mach-at91/board-rm9200dk.c
index fe13640..55a5202 100644
--- a/arch/arm/mach-at91/board-rm9200dk.c
+++ b/arch/arm/mach-at91/board-rm9200dk.c
@@ -149,6 +149,7 @@ static struct atmel_nand_data __initdata dk_nand_data = {
 	.det_pin	= AT91_PIN_PB1,
 	.rdy_pin	= AT91_PIN_PC2,
 	.enable_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= dk_nand_partition,
 	.num_parts	= ARRAY_SIZE(dk_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9-l9260.c b/arch/arm/mach-at91/board-sam9-l9260.c
index 84bce58..e8b116b 100644
--- a/arch/arm/mach-at91/board-sam9-l9260.c
+++ b/arch/arm/mach-at91/board-sam9-l9260.c
@@ -139,6 +139,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9260ek.c b/arch/arm/mach-at91/board-sam9260ek.c
index be8233b..3118ab1 100644
--- a/arch/arm/mach-at91/board-sam9260ek.c
+++ b/arch/arm/mach-at91/board-sam9260ek.c
@@ -181,6 +181,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9261ek.c b/arch/arm/mach-at91/board-sam9261ek.c
index 4089507..60cf37b 100644
--- a/arch/arm/mach-at91/board-sam9261ek.c
+++ b/arch/arm/mach-at91/board-sam9261ek.c
@@ -187,6 +187,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC15,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9263ek.c b/arch/arm/mach-at91/board-sam9263ek.c
index 29f6605..aeabf85 100644
--- a/arch/arm/mach-at91/board-sam9263ek.c
+++ b/arch/arm/mach-at91/board-sam9263ek.c
@@ -187,6 +187,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PA22,
 	.enable_pin	= AT91_PIN_PD15,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9g20ek.c b/arch/arm/mach-at91/board-sam9g20ek.c
index 843d628..419e0d5 100644
--- a/arch/arm/mach-at91/board-sam9g20ek.c
+++ b/arch/arm/mach-at91/board-sam9g20ek.c
@@ -166,6 +166,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9m10g45ek.c b/arch/arm/mach-at91/board-sam9m10g45ek.c
index ea0d1b9..452ec37 100644
--- a/arch/arm/mach-at91/board-sam9m10g45ek.c
+++ b/arch/arm/mach-at91/board-sam9m10g45ek.c
@@ -146,6 +146,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PC8,
 	.enable_pin	= AT91_PIN_PC14,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9rlek.c b/arch/arm/mach-at91/board-sam9rlek.c
index c1366d0..70a026d 100644
--- a/arch/arm/mach-at91/board-sam9rlek.c
+++ b/arch/arm/mach-at91/board-sam9rlek.c
@@ -94,6 +94,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PD17,
 	.enable_pin	= AT91_PIN_PB6,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-snapper9260.c b/arch/arm/mach-at91/board-snapper9260.c
index 4770db0..8898c1a 100644
--- a/arch/arm/mach-at91/board-snapper9260.c
+++ b/arch/arm/mach-at91/board-snapper9260.c
@@ -110,6 +110,7 @@ static struct atmel_nand_data __initdata snapper9260_nand_data = {
 	.bus_width_16	= 0,
 	.enable_pin	= -EINVAL,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 };
 
 static struct sam9_smc_config __initdata snapper9260_nand_smc_config = {
diff --git a/arch/arm/mach-at91/board-stamp9g20.c b/arch/arm/mach-at91/board-stamp9g20.c
index 72eb3b4..7640049 100644
--- a/arch/arm/mach-at91/board-stamp9g20.c
+++ b/arch/arm/mach-at91/board-stamp9g20.c
@@ -86,6 +86,7 @@ static struct atmel_nand_data __initdata nand_data = {
 	.enable_pin	= AT91_PIN_PC14,
 	.bus_width_16	= 0,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 };
 
 static struct sam9_smc_config __initdata nand_smc_config = {
diff --git a/arch/arm/mach-at91/board-usb-a926x.c b/arch/arm/mach-at91/board-usb-a926x.c
index 26c36fc..cc93152 100644
--- a/arch/arm/mach-at91/board-usb-a926x.c
+++ b/arch/arm/mach-at91/board-usb-a926x.c
@@ -198,6 +198,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PA22,
 	.enable_pin	= AT91_PIN_PD15,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-yl-9200.c b/arch/arm/mach-at91/board-yl-9200.c
index 34ebdcf..40087b8 100644
--- a/arch/arm/mach-at91/board-yl-9200.c
+++ b/arch/arm/mach-at91/board-yl-9200.c
@@ -181,6 +181,7 @@ static struct atmel_nand_data __initdata yl9200_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC14,	/* R/!B (Sheet10) */
 	.enable_pin	= AT91_PIN_PC15,	/* !CE  (Sheet10) */
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= yl9200_nand_partition,
 	.num_parts	= ARRAY_SIZE(yl9200_nand_partition),
 };
diff --git a/arch/arm/mach-at91/include/mach/board.h b/arch/arm/mach-at91/include/mach/board.h
index 3b33f07..762930e 100644
--- a/arch/arm/mach-at91/include/mach/board.h
+++ b/arch/arm/mach-at91/include/mach/board.h
@@ -41,6 +41,7 @@
 #include <sound/atmel-ac97c.h>
 #include <linux/serial.h>
 #include <linux/platform_data/macb.h>
+#include <linux/platform_data/atmel.h>
 
  /* USB Device */
 struct at91_udc_data {
@@ -98,18 +99,6 @@ extern void __init at91_add_device_usbh(struct at91_usbh_data *data);
 extern void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data);
 extern void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data);
 
- /* NAND / SmartMedia */
-struct atmel_nand_data {
-	int		enable_pin;	/* chip enable */
-	int		det_pin;	/* card detect */
-	int		rdy_pin;	/* ready/busy */
-	u8              rdy_pin_active_low;     /* rdy_pin value is inverted */
-	u8		ale;		/* address line number connected to ALE */
-	u8		cle;		/* address line number connected to CLE */
-	u8		bus_width_16;	/* buswidth is 16 bit */
-	struct mtd_partition *parts;
-	unsigned int	num_parts;
-};
 extern void __init at91_add_device_nand(struct atmel_nand_data *data);
 
  /* I2C*/
diff --git a/arch/avr32/boards/atngw100/setup.c b/arch/avr32/boards/atngw100/setup.c
index 7c756fb..afeae89 100644
--- a/arch/avr32/boards/atngw100/setup.c
+++ b/arch/avr32/boards/atngw100/setup.c
@@ -97,6 +97,7 @@ static struct atmel_nand_data atngw100mkii_nand_data __initdata = {
 	.rdy_pin	= GPIO_PIN_PB(28),
 	.enable_pin	= GPIO_PIN_PE(23),
 	.bus_width_16	= true,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= nand_partitions,
 	.num_parts	= ARRAY_SIZE(nand_partitions),
 };
diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
index c56ddac..dc52633 100644
--- a/arch/avr32/boards/atstk1000/atstk1002.c
+++ b/arch/avr32/boards/atstk1000/atstk1002.c
@@ -95,6 +95,7 @@ static struct atmel_nand_data atstk1006_nand_data __initdata = {
 	.ale		= 22,
 	.rdy_pin	= GPIO_PIN_PB(30),
 	.enable_pin	= GPIO_PIN_PB(29),
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= nand_partitions,
 	.num_parts	= ARRAY_SIZE(num_partitions),
 };
diff --git a/arch/avr32/mach-at32ap/include/mach/board.h b/arch/avr32/mach-at32ap/include/mach/board.h
index 67b111c..7173386 100644
--- a/arch/avr32/mach-at32ap/include/mach/board.h
+++ b/arch/avr32/mach-at32ap/include/mach/board.h
@@ -7,6 +7,7 @@
 #include <linux/types.h>
 #include <linux/serial.h>
 #include <linux/platform_data/macb.h>
+#include <linux/platform_data/atmel_nand.h>
 
 #define GPIO_PIN_NONE	(-1)
 
@@ -116,18 +117,6 @@ struct platform_device *
 at32_add_device_cf(unsigned int id, unsigned int extint,
 		struct cf_platform_data *data);
 
-/* NAND / SmartMedia */
-struct atmel_nand_data {
-	int	enable_pin;	/* chip enable */
-	int	det_pin;	/* card detect */
-	int	rdy_pin;	/* ready/busy */
-	u8	rdy_pin_active_low;	/* rdy_pin value is inverted */
-	u8	ale;		/* address line number connected to ALE */
-	u8	cle;		/* address line number connected to CLE */
-	u8	bus_width_16;	/* buswidth is 16 bit */
-	struct mtd_partition *parts;
-	unsigned int	num_parts;
-};
 struct platform_device *
 at32_add_device_nand(unsigned int id, struct atmel_nand_data *data);
 
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 4dd056e..0d955e1 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -34,22 +34,10 @@
 #include <linux/dmaengine.h>
 #include <linux/gpio.h>
 #include <linux/io.h>
+#include <linux/platform_data/atmel.h>
 
-#include <mach/board.h>
 #include <mach/cpu.h>
 
-#ifdef CONFIG_MTD_NAND_ATMEL_ECC_HW
-#define hard_ecc	1
-#else
-#define hard_ecc	0
-#endif
-
-#ifdef CONFIG_MTD_NAND_ATMEL_ECC_NONE
-#define no_ecc		1
-#else
-#define no_ecc		0
-#endif
-
 static int use_dma = 1;
 module_param(use_dma, int, 0);
 
@@ -495,23 +483,22 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	if (gpio_is_valid(host->board->rdy_pin))
 		nand_chip->dev_ready = atmel_nand_device_ready;
 
+	nand_chip->ecc.mode = host->board->ecc_mode;
+
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (!regs && hard_ecc) {
+	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
 		printk(KERN_ERR "atmel_nand: can't get I/O resource "
 				"regs\nFalling back on software ECC\n");
+		nand_chip->ecc.mode = NAND_ECC_SOFT;
 	}
 
-	nand_chip->ecc.mode = NAND_ECC_SOFT;	/* enable ECC */
-	if (no_ecc)
-		nand_chip->ecc.mode = NAND_ECC_NONE;
-	if (hard_ecc && regs) {
+	if (nand_chip->ecc.mode == NAND_ECC_HW) {
 		host->ecc = ioremap(regs->start, resource_size(regs));
 		if (host->ecc == NULL) {
 			printk(KERN_ERR "atmel_nand: ioremap failed\n");
 			res = -EIO;
 			goto err_ecc_ioremap;
 		}
-		nand_chip->ecc.mode = NAND_ECC_HW;
 		nand_chip->ecc.calculate = atmel_nand_calculate;
 		nand_chip->ecc.correct = atmel_nand_correct;
 		nand_chip->ecc.hwctl = atmel_nand_hwctl;
diff --git a/include/linux/platform_data/atmel.h b/include/linux/platform_data/atmel.h
new file mode 100644
index 0000000..7b8a445
--- /dev/null
+++ b/include/linux/platform_data/atmel.h
@@ -0,0 +1,26 @@
+/*
+ * atmel platform data
+ *
+ * GPL v2 Only
+ */
+
+#ifndef __ATMEL_NAND_H__
+#define __ATMEL_NAND_H__
+
+#include <linux/mtd/nand.h>
+
+ /* NAND / SmartMedia */
+struct atmel_nand_data {
+	int		enable_pin;		/* chip enable */
+	int		det_pin;		/* card detect */
+	int		rdy_pin;		/* ready/busy */
+	u8		rdy_pin_active_low;	/* rdy_pin value is inverted */
+	u8		ale;			/* address line number connected to ALE */
+	u8		cle;			/* address line number connected to CLE */
+	u8		bus_width_16;		/* buswidth is 16 bit */
+	u8		ecc_mode;		/* ecc mode */
+	struct mtd_partition *parts;
+	unsigned int	num_parts;
+};
+
+#endif /* __ATMEL_NAND_H__ */
-- 
1.7.7

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

* [FOR 3.3 PATCH 1/6] ATMEL: fix nand ecc support
@ 2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel

so we can now choose for the board the ecc mode (ecc soft, soft bch, no ecc
and hardware)

set ecc mode in the boards to soft as currently in the driver

move platform data to a common header
include/linux/platform_data/atmel_nand.h

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: linux-mtd at lists.infradead.org
---
 arch/arm/mach-at91/board-afeb-9260v1.c      |    1 +
 arch/arm/mach-at91/board-cam60.c            |    1 +
 arch/arm/mach-at91/board-cap9adk.c          |    1 +
 arch/arm/mach-at91/board-cpu9krea.c         |    1 +
 arch/arm/mach-at91/board-dt.c               |    1 +
 arch/arm/mach-at91/board-kb9202.c           |    1 +
 arch/arm/mach-at91/board-neocore926.c       |    1 +
 arch/arm/mach-at91/board-qil-a9260.c        |    1 +
 arch/arm/mach-at91/board-rm9200dk.c         |    1 +
 arch/arm/mach-at91/board-sam9-l9260.c       |    1 +
 arch/arm/mach-at91/board-sam9260ek.c        |    1 +
 arch/arm/mach-at91/board-sam9261ek.c        |    1 +
 arch/arm/mach-at91/board-sam9263ek.c        |    1 +
 arch/arm/mach-at91/board-sam9g20ek.c        |    1 +
 arch/arm/mach-at91/board-sam9m10g45ek.c     |    1 +
 arch/arm/mach-at91/board-sam9rlek.c         |    1 +
 arch/arm/mach-at91/board-snapper9260.c      |    1 +
 arch/arm/mach-at91/board-stamp9g20.c        |    1 +
 arch/arm/mach-at91/board-usb-a926x.c        |    1 +
 arch/arm/mach-at91/board-yl-9200.c          |    1 +
 arch/arm/mach-at91/include/mach/board.h     |   13 +------------
 arch/avr32/boards/atngw100/setup.c          |    1 +
 arch/avr32/boards/atstk1000/atstk1002.c     |    1 +
 arch/avr32/mach-at32ap/include/mach/board.h |   13 +------------
 drivers/mtd/nand/atmel_nand.c               |   25 ++++++-------------------
 include/linux/platform_data/atmel.h         |   26 ++++++++++++++++++++++++++
 26 files changed, 56 insertions(+), 43 deletions(-)
 create mode 100644 include/linux/platform_data/atmel.h

diff --git a/arch/arm/mach-at91/board-afeb-9260v1.c b/arch/arm/mach-at91/board-afeb-9260v1.c
index 3bb4069..161efba 100644
--- a/arch/arm/mach-at91/board-afeb-9260v1.c
+++ b/arch/arm/mach-at91/board-afeb-9260v1.c
@@ -138,6 +138,7 @@ static struct atmel_nand_data __initdata afeb9260_nand_data = {
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
 	.bus_width_16	= 0,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= afeb9260_nand_partition,
 	.num_parts	= ARRAY_SIZE(afeb9260_nand_partition),
 	.det_pin	= -EINVAL,
diff --git a/arch/arm/mach-at91/board-cam60.c b/arch/arm/mach-at91/board-cam60.c
index 8510e9e..c6d44ee 100644
--- a/arch/arm/mach-at91/board-cam60.c
+++ b/arch/arm/mach-at91/board-cam60.c
@@ -140,6 +140,7 @@ static struct atmel_nand_data __initdata cam60_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PA9,
 	.enable_pin	= AT91_PIN_PA7,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= cam60_nand_partition,
 	.num_parts	= ARRAY_SIZE(cam60_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-cap9adk.c b/arch/arm/mach-at91/board-cap9adk.c
index e0165a2..9c05eea 100644
--- a/arch/arm/mach-at91/board-cap9adk.c
+++ b/arch/arm/mach-at91/board-cap9adk.c
@@ -178,6 +178,7 @@ static struct atmel_nand_data __initdata cap9adk_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= -EINVAL,
 	.enable_pin	= AT91_PIN_PD15,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= cap9adk_nand_partitions,
 	.num_parts	= ARRAY_SIZE(cap9adk_nand_partitions),
 };
diff --git a/arch/arm/mach-at91/board-cpu9krea.c b/arch/arm/mach-at91/board-cpu9krea.c
index 8c60e0d..e69e2a1 100644
--- a/arch/arm/mach-at91/board-cpu9krea.c
+++ b/arch/arm/mach-at91/board-cpu9krea.c
@@ -116,6 +116,7 @@ static struct atmel_nand_data __initdata cpu9krea_nand_data = {
 	.enable_pin	= AT91_PIN_PC14,
 	.bus_width_16	= 0,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 };
 
 #ifdef CONFIG_MACH_CPU9260
diff --git a/arch/arm/mach-at91/board-dt.c b/arch/arm/mach-at91/board-dt.c
index bb6b434..552390d 100644
--- a/arch/arm/mach-at91/board-dt.c
+++ b/arch/arm/mach-at91/board-dt.c
@@ -53,6 +53,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC8,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 };
 
 static struct sam9_smc_config __initdata ek_nand_smc_config = {
diff --git a/arch/arm/mach-at91/board-kb9202.c b/arch/arm/mach-at91/board-kb9202.c
index 4d23b6a..04d9b8e 100644
--- a/arch/arm/mach-at91/board-kb9202.c
+++ b/arch/arm/mach-at91/board-kb9202.c
@@ -107,6 +107,7 @@ static struct atmel_nand_data __initdata kb9202_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC29,
 	.enable_pin	= AT91_PIN_PC28,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= kb9202_nand_partition,
 	.num_parts	= ARRAY_SIZE(kb9202_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-neocore926.c b/arch/arm/mach-at91/board-neocore926.c
index 3f8617c..57d5f6a 100644
--- a/arch/arm/mach-at91/board-neocore926.c
+++ b/arch/arm/mach-at91/board-neocore926.c
@@ -190,6 +190,7 @@ static struct atmel_nand_data __initdata neocore926_nand_data = {
 	.rdy_pin		= AT91_PIN_PB19,
 	.rdy_pin_active_low	= 1,
 	.enable_pin		= AT91_PIN_PD15,
+	.ecc_mode		= NAND_ECC_SOFT,
 	.parts			= neocore926_nand_partition,
 	.num_parts		= ARRAY_SIZE(neocore926_nand_partition),
 	.det_pin		= -EINVAL,
diff --git a/arch/arm/mach-at91/board-qil-a9260.c b/arch/arm/mach-at91/board-qil-a9260.c
index e029d22..97907e4 100644
--- a/arch/arm/mach-at91/board-qil-a9260.c
+++ b/arch/arm/mach-at91/board-qil-a9260.c
@@ -138,6 +138,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-rm9200dk.c b/arch/arm/mach-at91/board-rm9200dk.c
index fe13640..55a5202 100644
--- a/arch/arm/mach-at91/board-rm9200dk.c
+++ b/arch/arm/mach-at91/board-rm9200dk.c
@@ -149,6 +149,7 @@ static struct atmel_nand_data __initdata dk_nand_data = {
 	.det_pin	= AT91_PIN_PB1,
 	.rdy_pin	= AT91_PIN_PC2,
 	.enable_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= dk_nand_partition,
 	.num_parts	= ARRAY_SIZE(dk_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9-l9260.c b/arch/arm/mach-at91/board-sam9-l9260.c
index 84bce58..e8b116b 100644
--- a/arch/arm/mach-at91/board-sam9-l9260.c
+++ b/arch/arm/mach-at91/board-sam9-l9260.c
@@ -139,6 +139,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9260ek.c b/arch/arm/mach-at91/board-sam9260ek.c
index be8233b..3118ab1 100644
--- a/arch/arm/mach-at91/board-sam9260ek.c
+++ b/arch/arm/mach-at91/board-sam9260ek.c
@@ -181,6 +181,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9261ek.c b/arch/arm/mach-at91/board-sam9261ek.c
index 4089507..60cf37b 100644
--- a/arch/arm/mach-at91/board-sam9261ek.c
+++ b/arch/arm/mach-at91/board-sam9261ek.c
@@ -187,6 +187,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC15,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9263ek.c b/arch/arm/mach-at91/board-sam9263ek.c
index 29f6605..aeabf85 100644
--- a/arch/arm/mach-at91/board-sam9263ek.c
+++ b/arch/arm/mach-at91/board-sam9263ek.c
@@ -187,6 +187,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PA22,
 	.enable_pin	= AT91_PIN_PD15,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9g20ek.c b/arch/arm/mach-at91/board-sam9g20ek.c
index 843d628..419e0d5 100644
--- a/arch/arm/mach-at91/board-sam9g20ek.c
+++ b/arch/arm/mach-at91/board-sam9g20ek.c
@@ -166,6 +166,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9m10g45ek.c b/arch/arm/mach-at91/board-sam9m10g45ek.c
index ea0d1b9..452ec37 100644
--- a/arch/arm/mach-at91/board-sam9m10g45ek.c
+++ b/arch/arm/mach-at91/board-sam9m10g45ek.c
@@ -146,6 +146,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PC8,
 	.enable_pin	= AT91_PIN_PC14,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9rlek.c b/arch/arm/mach-at91/board-sam9rlek.c
index c1366d0..70a026d 100644
--- a/arch/arm/mach-at91/board-sam9rlek.c
+++ b/arch/arm/mach-at91/board-sam9rlek.c
@@ -94,6 +94,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PD17,
 	.enable_pin	= AT91_PIN_PB6,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-snapper9260.c b/arch/arm/mach-at91/board-snapper9260.c
index 4770db0..8898c1a 100644
--- a/arch/arm/mach-at91/board-snapper9260.c
+++ b/arch/arm/mach-at91/board-snapper9260.c
@@ -110,6 +110,7 @@ static struct atmel_nand_data __initdata snapper9260_nand_data = {
 	.bus_width_16	= 0,
 	.enable_pin	= -EINVAL,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 };
 
 static struct sam9_smc_config __initdata snapper9260_nand_smc_config = {
diff --git a/arch/arm/mach-at91/board-stamp9g20.c b/arch/arm/mach-at91/board-stamp9g20.c
index 72eb3b4..7640049 100644
--- a/arch/arm/mach-at91/board-stamp9g20.c
+++ b/arch/arm/mach-at91/board-stamp9g20.c
@@ -86,6 +86,7 @@ static struct atmel_nand_data __initdata nand_data = {
 	.enable_pin	= AT91_PIN_PC14,
 	.bus_width_16	= 0,
 	.det_pin	= -EINVAL,
+	.ecc_mode	= NAND_ECC_SOFT,
 };
 
 static struct sam9_smc_config __initdata nand_smc_config = {
diff --git a/arch/arm/mach-at91/board-usb-a926x.c b/arch/arm/mach-at91/board-usb-a926x.c
index 26c36fc..cc93152 100644
--- a/arch/arm/mach-at91/board-usb-a926x.c
+++ b/arch/arm/mach-at91/board-usb-a926x.c
@@ -198,6 +198,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PA22,
 	.enable_pin	= AT91_PIN_PD15,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-yl-9200.c b/arch/arm/mach-at91/board-yl-9200.c
index 34ebdcf..40087b8 100644
--- a/arch/arm/mach-at91/board-yl-9200.c
+++ b/arch/arm/mach-at91/board-yl-9200.c
@@ -181,6 +181,7 @@ static struct atmel_nand_data __initdata yl9200_nand_data = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC14,	/* R/!B (Sheet10) */
 	.enable_pin	= AT91_PIN_PC15,	/* !CE  (Sheet10) */
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= yl9200_nand_partition,
 	.num_parts	= ARRAY_SIZE(yl9200_nand_partition),
 };
diff --git a/arch/arm/mach-at91/include/mach/board.h b/arch/arm/mach-at91/include/mach/board.h
index 3b33f07..762930e 100644
--- a/arch/arm/mach-at91/include/mach/board.h
+++ b/arch/arm/mach-at91/include/mach/board.h
@@ -41,6 +41,7 @@
 #include <sound/atmel-ac97c.h>
 #include <linux/serial.h>
 #include <linux/platform_data/macb.h>
+#include <linux/platform_data/atmel.h>
 
  /* USB Device */
 struct at91_udc_data {
@@ -98,18 +99,6 @@ extern void __init at91_add_device_usbh(struct at91_usbh_data *data);
 extern void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data);
 extern void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data);
 
- /* NAND / SmartMedia */
-struct atmel_nand_data {
-	int		enable_pin;	/* chip enable */
-	int		det_pin;	/* card detect */
-	int		rdy_pin;	/* ready/busy */
-	u8              rdy_pin_active_low;     /* rdy_pin value is inverted */
-	u8		ale;		/* address line number connected to ALE */
-	u8		cle;		/* address line number connected to CLE */
-	u8		bus_width_16;	/* buswidth is 16 bit */
-	struct mtd_partition *parts;
-	unsigned int	num_parts;
-};
 extern void __init at91_add_device_nand(struct atmel_nand_data *data);
 
  /* I2C*/
diff --git a/arch/avr32/boards/atngw100/setup.c b/arch/avr32/boards/atngw100/setup.c
index 7c756fb..afeae89 100644
--- a/arch/avr32/boards/atngw100/setup.c
+++ b/arch/avr32/boards/atngw100/setup.c
@@ -97,6 +97,7 @@ static struct atmel_nand_data atngw100mkii_nand_data __initdata = {
 	.rdy_pin	= GPIO_PIN_PB(28),
 	.enable_pin	= GPIO_PIN_PE(23),
 	.bus_width_16	= true,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= nand_partitions,
 	.num_parts	= ARRAY_SIZE(nand_partitions),
 };
diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
index c56ddac..dc52633 100644
--- a/arch/avr32/boards/atstk1000/atstk1002.c
+++ b/arch/avr32/boards/atstk1000/atstk1002.c
@@ -95,6 +95,7 @@ static struct atmel_nand_data atstk1006_nand_data __initdata = {
 	.ale		= 22,
 	.rdy_pin	= GPIO_PIN_PB(30),
 	.enable_pin	= GPIO_PIN_PB(29),
+	.ecc_mode	= NAND_ECC_SOFT,
 	.parts		= nand_partitions,
 	.num_parts	= ARRAY_SIZE(num_partitions),
 };
diff --git a/arch/avr32/mach-at32ap/include/mach/board.h b/arch/avr32/mach-at32ap/include/mach/board.h
index 67b111c..7173386 100644
--- a/arch/avr32/mach-at32ap/include/mach/board.h
+++ b/arch/avr32/mach-at32ap/include/mach/board.h
@@ -7,6 +7,7 @@
 #include <linux/types.h>
 #include <linux/serial.h>
 #include <linux/platform_data/macb.h>
+#include <linux/platform_data/atmel_nand.h>
 
 #define GPIO_PIN_NONE	(-1)
 
@@ -116,18 +117,6 @@ struct platform_device *
 at32_add_device_cf(unsigned int id, unsigned int extint,
 		struct cf_platform_data *data);
 
-/* NAND / SmartMedia */
-struct atmel_nand_data {
-	int	enable_pin;	/* chip enable */
-	int	det_pin;	/* card detect */
-	int	rdy_pin;	/* ready/busy */
-	u8	rdy_pin_active_low;	/* rdy_pin value is inverted */
-	u8	ale;		/* address line number connected to ALE */
-	u8	cle;		/* address line number connected to CLE */
-	u8	bus_width_16;	/* buswidth is 16 bit */
-	struct mtd_partition *parts;
-	unsigned int	num_parts;
-};
 struct platform_device *
 at32_add_device_nand(unsigned int id, struct atmel_nand_data *data);
 
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 4dd056e..0d955e1 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -34,22 +34,10 @@
 #include <linux/dmaengine.h>
 #include <linux/gpio.h>
 #include <linux/io.h>
+#include <linux/platform_data/atmel.h>
 
-#include <mach/board.h>
 #include <mach/cpu.h>
 
-#ifdef CONFIG_MTD_NAND_ATMEL_ECC_HW
-#define hard_ecc	1
-#else
-#define hard_ecc	0
-#endif
-
-#ifdef CONFIG_MTD_NAND_ATMEL_ECC_NONE
-#define no_ecc		1
-#else
-#define no_ecc		0
-#endif
-
 static int use_dma = 1;
 module_param(use_dma, int, 0);
 
@@ -495,23 +483,22 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	if (gpio_is_valid(host->board->rdy_pin))
 		nand_chip->dev_ready = atmel_nand_device_ready;
 
+	nand_chip->ecc.mode = host->board->ecc_mode;
+
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (!regs && hard_ecc) {
+	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
 		printk(KERN_ERR "atmel_nand: can't get I/O resource "
 				"regs\nFalling back on software ECC\n");
+		nand_chip->ecc.mode = NAND_ECC_SOFT;
 	}
 
-	nand_chip->ecc.mode = NAND_ECC_SOFT;	/* enable ECC */
-	if (no_ecc)
-		nand_chip->ecc.mode = NAND_ECC_NONE;
-	if (hard_ecc && regs) {
+	if (nand_chip->ecc.mode == NAND_ECC_HW) {
 		host->ecc = ioremap(regs->start, resource_size(regs));
 		if (host->ecc == NULL) {
 			printk(KERN_ERR "atmel_nand: ioremap failed\n");
 			res = -EIO;
 			goto err_ecc_ioremap;
 		}
-		nand_chip->ecc.mode = NAND_ECC_HW;
 		nand_chip->ecc.calculate = atmel_nand_calculate;
 		nand_chip->ecc.correct = atmel_nand_correct;
 		nand_chip->ecc.hwctl = atmel_nand_hwctl;
diff --git a/include/linux/platform_data/atmel.h b/include/linux/platform_data/atmel.h
new file mode 100644
index 0000000..7b8a445
--- /dev/null
+++ b/include/linux/platform_data/atmel.h
@@ -0,0 +1,26 @@
+/*
+ * atmel platform data
+ *
+ * GPL v2 Only
+ */
+
+#ifndef __ATMEL_NAND_H__
+#define __ATMEL_NAND_H__
+
+#include <linux/mtd/nand.h>
+
+ /* NAND / SmartMedia */
+struct atmel_nand_data {
+	int		enable_pin;		/* chip enable */
+	int		det_pin;		/* card detect */
+	int		rdy_pin;		/* ready/busy */
+	u8		rdy_pin_active_low;	/* rdy_pin value is inverted */
+	u8		ale;			/* address line number connected to ALE */
+	u8		cle;			/* address line number connected to CLE */
+	u8		bus_width_16;		/* buswidth is 16 bit */
+	u8		ecc_mode;		/* ecc mode */
+	struct mtd_partition *parts;
+	unsigned int	num_parts;
+};
+
+#endif /* __ATMEL_NAND_H__ */
-- 
1.7.7

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

* [FOR 3.3 PATCH 2/6] mtd/atmel_nand: add on_flash_bbt to enable the use of On Flash BBT
  2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, Jean-Christophe PLAGNIOL-VILLARD, linux-mtd

from the board

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/nand/atmel_nand.c       |    2 +-
 include/linux/platform_data/atmel.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 0d955e1..d3bde9b 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -525,7 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 		}
 	}
 
-	if (on_flash_bbt) {
+	if (host->board->on_flash_bbt || on_flash_bbt) {
 		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
 		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 	}
diff --git a/include/linux/platform_data/atmel.h b/include/linux/platform_data/atmel.h
index 7b8a445..d056263 100644
--- a/include/linux/platform_data/atmel.h
+++ b/include/linux/platform_data/atmel.h
@@ -19,6 +19,7 @@ struct atmel_nand_data {
 	u8		cle;			/* address line number connected to CLE */
 	u8		bus_width_16;		/* buswidth is 16 bit */
 	u8		ecc_mode;		/* ecc mode */
+	u8		on_flash_bbt;		/* bbt on flash */
 	struct mtd_partition *parts;
 	unsigned int	num_parts;
 };
-- 
1.7.7

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

* [FOR 3.3 PATCH 2/6] mtd/atmel_nand: add on_flash_bbt to enable the use of On Flash BBT
@ 2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel

from the board

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: linux-mtd at lists.infradead.org
---
 drivers/mtd/nand/atmel_nand.c       |    2 +-
 include/linux/platform_data/atmel.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 0d955e1..d3bde9b 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -525,7 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 		}
 	}
 
-	if (on_flash_bbt) {
+	if (host->board->on_flash_bbt || on_flash_bbt) {
 		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
 		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 	}
diff --git a/include/linux/platform_data/atmel.h b/include/linux/platform_data/atmel.h
index 7b8a445..d056263 100644
--- a/include/linux/platform_data/atmel.h
+++ b/include/linux/platform_data/atmel.h
@@ -19,6 +19,7 @@ struct atmel_nand_data {
 	u8		cle;			/* address line number connected to CLE */
 	u8		bus_width_16;		/* buswidth is 16 bit */
 	u8		ecc_mode;		/* ecc mode */
+	u8		on_flash_bbt;		/* bbt on flash */
 	struct mtd_partition *parts;
 	unsigned int	num_parts;
 };
-- 
1.7.7

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

* [FOR 3.3 PATCH 3/6] ARM: at91: enable on flash bbt for Atmel Reference and DT boards
  2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
  (?)
@ 2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel

enable it on Calao board too

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 arch/arm/mach-at91/board-cap9adk.c      |    1 +
 arch/arm/mach-at91/board-dt.c           |    1 +
 arch/arm/mach-at91/board-qil-a9260.c    |    1 +
 arch/arm/mach-at91/board-rm9200dk.c     |    1 +
 arch/arm/mach-at91/board-sam9260ek.c    |    1 +
 arch/arm/mach-at91/board-sam9261ek.c    |    1 +
 arch/arm/mach-at91/board-sam9263ek.c    |    1 +
 arch/arm/mach-at91/board-sam9g20ek.c    |    1 +
 arch/arm/mach-at91/board-sam9m10g45ek.c |    1 +
 arch/arm/mach-at91/board-sam9rlek.c     |    1 +
 arch/arm/mach-at91/board-usb-a926x.c    |    1 +
 11 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-at91/board-cap9adk.c b/arch/arm/mach-at91/board-cap9adk.c
index 9c05eea..3618dcf91 100644
--- a/arch/arm/mach-at91/board-cap9adk.c
+++ b/arch/arm/mach-at91/board-cap9adk.c
@@ -179,6 +179,7 @@ static struct atmel_nand_data __initdata cap9adk_nand_data = {
 	.rdy_pin	= -EINVAL,
 	.enable_pin	= AT91_PIN_PD15,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= cap9adk_nand_partitions,
 	.num_parts	= ARRAY_SIZE(cap9adk_nand_partitions),
 };
diff --git a/arch/arm/mach-at91/board-dt.c b/arch/arm/mach-at91/board-dt.c
index 552390d..a42cad8 100644
--- a/arch/arm/mach-at91/board-dt.c
+++ b/arch/arm/mach-at91/board-dt.c
@@ -54,6 +54,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PC8,
 	.enable_pin	= AT91_PIN_PC14,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 };
 
 static struct sam9_smc_config __initdata ek_nand_smc_config = {
diff --git a/arch/arm/mach-at91/board-qil-a9260.c b/arch/arm/mach-at91/board-qil-a9260.c
index 97907e4..b6ed5ed 100644
--- a/arch/arm/mach-at91/board-qil-a9260.c
+++ b/arch/arm/mach-at91/board-qil-a9260.c
@@ -139,6 +139,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-rm9200dk.c b/arch/arm/mach-at91/board-rm9200dk.c
index 55a5202..d49d004 100644
--- a/arch/arm/mach-at91/board-rm9200dk.c
+++ b/arch/arm/mach-at91/board-rm9200dk.c
@@ -150,6 +150,7 @@ static struct atmel_nand_data __initdata dk_nand_data = {
 	.rdy_pin	= AT91_PIN_PC2,
 	.enable_pin	= -EINVAL,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= dk_nand_partition,
 	.num_parts	= ARRAY_SIZE(dk_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9260ek.c b/arch/arm/mach-at91/board-sam9260ek.c
index 3118ab1..d5aec55 100644
--- a/arch/arm/mach-at91/board-sam9260ek.c
+++ b/arch/arm/mach-at91/board-sam9260ek.c
@@ -182,6 +182,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9261ek.c b/arch/arm/mach-at91/board-sam9261ek.c
index 60cf37b..c3f9944 100644
--- a/arch/arm/mach-at91/board-sam9261ek.c
+++ b/arch/arm/mach-at91/board-sam9261ek.c
@@ -188,6 +188,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PC15,
 	.enable_pin	= AT91_PIN_PC14,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9263ek.c b/arch/arm/mach-at91/board-sam9263ek.c
index aeabf85..66f0ddf 100644
--- a/arch/arm/mach-at91/board-sam9263ek.c
+++ b/arch/arm/mach-at91/board-sam9263ek.c
@@ -188,6 +188,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PA22,
 	.enable_pin	= AT91_PIN_PD15,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9g20ek.c b/arch/arm/mach-at91/board-sam9g20ek.c
index 419e0d5..8923ec9 100644
--- a/arch/arm/mach-at91/board-sam9g20ek.c
+++ b/arch/arm/mach-at91/board-sam9g20ek.c
@@ -167,6 +167,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.enable_pin	= AT91_PIN_PC14,
 	.det_pin	= -EINVAL,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9m10g45ek.c b/arch/arm/mach-at91/board-sam9m10g45ek.c
index 452ec37..31eb24a 100644
--- a/arch/arm/mach-at91/board-sam9m10g45ek.c
+++ b/arch/arm/mach-at91/board-sam9m10g45ek.c
@@ -147,6 +147,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.enable_pin	= AT91_PIN_PC14,
 	.det_pin	= -EINVAL,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-sam9rlek.c b/arch/arm/mach-at91/board-sam9rlek.c
index 70a026d..b109ce2 100644
--- a/arch/arm/mach-at91/board-sam9rlek.c
+++ b/arch/arm/mach-at91/board-sam9rlek.c
@@ -95,6 +95,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PD17,
 	.enable_pin	= AT91_PIN_PB6,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
diff --git a/arch/arm/mach-at91/board-usb-a926x.c b/arch/arm/mach-at91/board-usb-a926x.c
index cc93152..b7483a3 100644
--- a/arch/arm/mach-at91/board-usb-a926x.c
+++ b/arch/arm/mach-at91/board-usb-a926x.c
@@ -199,6 +199,7 @@ static struct atmel_nand_data __initdata ek_nand_data = {
 	.rdy_pin	= AT91_PIN_PA22,
 	.enable_pin	= AT91_PIN_PD15,
 	.ecc_mode	= NAND_ECC_SOFT,
+	.on_flash_bbt	= 1,
 	.parts		= ek_nand_partition,
 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
 };
-- 
1.7.7

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

* [FOR 3.4 PATCH 4/6] of/mtd/nand: add generic bindings and helpers
  2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, devicetree-discuss,
	Jean-Christophe PLAGNIOL-VILLARD, linux-mtd

- nand-ecc-mode : String, operation mode of the NAND ecc mode.
  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
  "soft_bch".
- nand-bus-width : 8 or 16 bus width if not present 8
- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss@lists.ozlabs.org
Cc: linux-mtd@lists.infradead.org
---
 Documentation/devicetree/bindings/mtd/nand.txt |    7 ++
 drivers/of/Kconfig                             |    4 +
 drivers/of/Makefile                            |    1 +
 drivers/of/of_mtd.c                            |   90 ++++++++++++++++++++++++
 include/linux/of_mtd.h                         |   19 +++++
 5 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/nand.txt
 create mode 100644 drivers/of/of_mtd.c
 create mode 100644 include/linux/of_mtd.h

diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt
new file mode 100644
index 0000000..03855c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/nand.txt
@@ -0,0 +1,7 @@
+* MTD generic binding
+
+- nand-ecc-mode : String, operation mode of the NAND ecc mode.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 268163d..fa666a9 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -90,4 +90,8 @@ config OF_PCI_IRQ
 	help
 	  OpenFirmware PCI IRQ routing helpers
 
+config OF_MTD
+	depends on MTD
+	def_bool y
+
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index a73f5a5..8c4980a 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
 obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
+obj-$(CONFIG_OF_NET)	+= of_mtd.o
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
new file mode 100644
index 0000000..199bf58
--- /dev/null
+++ b/drivers/of/of_mtd.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/of_mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/export.h>
+
+/**
+ * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
+ * into the device tree binding of 'phy-mode', so that Ethernet
+ * device driver can get phy interface from device tree.
+ */
+static const char *nand_ecc_modes[] = {
+	[NAND_ECC_NONE]		= "none",
+	[NAND_ECC_SOFT]		= "soft",
+	[NAND_ECC_HW]		= "hw",
+	[NAND_ECC_HW_SYNDROME]	= "hw_syndrome",
+	[NAND_ECC_HW_OOB_FIRST]	= "hw_oob_first",
+	[NAND_ECC_SOFT_BCH]	= "soft_bch",
+};
+
+/**
+ * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * The function gets ecc mode string from property 'nand-ecc-mode',
+ * and return its index in nand_ecc_modes table, or errno in error case.
+ */
+const int of_get_nand_ecc_mode(struct device_node *np)
+{
+	const char *pm;
+	int err, i;
+
+	err = of_property_read_string(np, "nand-ecc-mode", &pm);
+	if (err < 0)
+		return err;
+
+	for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
+		if (!strcasecmp(pm, nand_ecc_modes[i]))
+			return i;
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
+
+/**
+ * of_get_nand_bus_width - Get nand bus witdh for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return bus width option, or errno in error case.
+ */
+int of_get_nand_bus_width(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-bus-width", &val))
+		return 8;
+
+	switch(val) {
+	case 8:
+	case 16:
+		return val;
+	default:
+		return -EIO;
+	}
+}
+EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
+
+/**
+ * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return true if 1 false other wise
+ */
+bool of_get_nand_on_flash_bbt(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-on-flash-bbt", &val))
+		return false;
+
+	return val ? true : false;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
new file mode 100644
index 0000000..bae1b60
--- /dev/null
+++ b/include/linux/of_mtd.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_MTD_H
+#define __LINUX_OF_NET_H
+
+#ifdef CONFIG_OF_MTD
+#include <linux/of.h>
+extern const int of_get_nand_ecc_mode(struct device_node *np);
+int of_get_nand_bus_width(struct device_node *np);
+bool of_get_nand_on_flash_bbt(struct device_node *np);
+#endif
+
+#endif /* __LINUX_OF_MTD_H */
-- 
1.7.7

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

* [FOR 3.4 PATCH 4/6] of/mtd/nand: add generic bindings and helpers
@ 2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel

- nand-ecc-mode : String, operation mode of the NAND ecc mode.
  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
  "soft_bch".
- nand-bus-width : 8 or 16 bus width if not present 8
- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss at lists.ozlabs.org
Cc: linux-mtd at lists.infradead.org
---
 Documentation/devicetree/bindings/mtd/nand.txt |    7 ++
 drivers/of/Kconfig                             |    4 +
 drivers/of/Makefile                            |    1 +
 drivers/of/of_mtd.c                            |   90 ++++++++++++++++++++++++
 include/linux/of_mtd.h                         |   19 +++++
 5 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/nand.txt
 create mode 100644 drivers/of/of_mtd.c
 create mode 100644 include/linux/of_mtd.h

diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt
new file mode 100644
index 0000000..03855c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/nand.txt
@@ -0,0 +1,7 @@
+* MTD generic binding
+
+- nand-ecc-mode : String, operation mode of the NAND ecc mode.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 268163d..fa666a9 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -90,4 +90,8 @@ config OF_PCI_IRQ
 	help
 	  OpenFirmware PCI IRQ routing helpers
 
+config OF_MTD
+	depends on MTD
+	def_bool y
+
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index a73f5a5..8c4980a 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
 obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
+obj-$(CONFIG_OF_NET)	+= of_mtd.o
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
new file mode 100644
index 0000000..199bf58
--- /dev/null
+++ b/drivers/of/of_mtd.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/of_mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/export.h>
+
+/**
+ * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
+ * into the device tree binding of 'phy-mode', so that Ethernet
+ * device driver can get phy interface from device tree.
+ */
+static const char *nand_ecc_modes[] = {
+	[NAND_ECC_NONE]		= "none",
+	[NAND_ECC_SOFT]		= "soft",
+	[NAND_ECC_HW]		= "hw",
+	[NAND_ECC_HW_SYNDROME]	= "hw_syndrome",
+	[NAND_ECC_HW_OOB_FIRST]	= "hw_oob_first",
+	[NAND_ECC_SOFT_BCH]	= "soft_bch",
+};
+
+/**
+ * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * The function gets ecc mode string from property 'nand-ecc-mode',
+ * and return its index in nand_ecc_modes table, or errno in error case.
+ */
+const int of_get_nand_ecc_mode(struct device_node *np)
+{
+	const char *pm;
+	int err, i;
+
+	err = of_property_read_string(np, "nand-ecc-mode", &pm);
+	if (err < 0)
+		return err;
+
+	for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
+		if (!strcasecmp(pm, nand_ecc_modes[i]))
+			return i;
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
+
+/**
+ * of_get_nand_bus_width - Get nand bus witdh for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return bus width option, or errno in error case.
+ */
+int of_get_nand_bus_width(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-bus-width", &val))
+		return 8;
+
+	switch(val) {
+	case 8:
+	case 16:
+		return val;
+	default:
+		return -EIO;
+	}
+}
+EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
+
+/**
+ * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return true if 1 false other wise
+ */
+bool of_get_nand_on_flash_bbt(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-on-flash-bbt", &val))
+		return false;
+
+	return val ? true : false;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
new file mode 100644
index 0000000..bae1b60
--- /dev/null
+++ b/include/linux/of_mtd.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_MTD_H
+#define __LINUX_OF_NET_H
+
+#ifdef CONFIG_OF_MTD
+#include <linux/of.h>
+extern const int of_get_nand_ecc_mode(struct device_node *np);
+int of_get_nand_bus_width(struct device_node *np);
+bool of_get_nand_on_flash_bbt(struct device_node *np);
+#endif
+
+#endif /* __LINUX_OF_MTD_H */
-- 
1.7.7

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

* [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
  2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, devicetree-discuss,
	Jean-Christophe PLAGNIOL-VILLARD, linux-mtd

use a local copy of board informatin and fill with DT data

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss@lists.ozlabs.org
Cc: linux-mtd@lists.infradead.org
---
 .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
 drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
 2 files changed, 130 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
new file mode 100644
index 0000000..a910ab9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
@@ -0,0 +1,41 @@
+Atmel NAND flash
+
+Required properties:
+- compatible : "atmel,at91rm9200-nand".
+- reg : should specify localbus address and size used for the chip,
+	and if availlable the ECC.
+- atmel,nand-addr-offset : offset for the address latch.
+- atmel,nand-cmd-offset : offset for the command latch.
+- #address-cells, #size-cells : Must be present if the device has sub-nodes
+  representing partitions.
+
+- gpios : specifies the gpio pins to control the NAND device. detect is an
+  optional gpio and may be set to 0 if not present.
+
+Optional properties:
+- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
+
+Examples:
+nand0: nand@40000000,0 {
+	compatible = "atmel,at91rm9200-nand";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x40000000 0x10000000
+	       0xffffe800 0x200
+	      >;
+	atmel,nand-addr-offset = <21>;
+	atmel,nand-cmd-offset = <22>;
+	nand-on-flash-bbt = <1>;
+	nand-ecc-mode = "soft";
+	gpios = <&pioC 13 0
+		 &pioC 14 0
+		 0
+		>;
+	partition@0 {
+		...
+	};
+};
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index d3bde9b..ea7643a 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -27,6 +27,10 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -83,7 +87,7 @@ struct atmel_nand_host {
 	struct mtd_info		mtd;
 	void __iomem		*io_base;
 	dma_addr_t		io_phys;
-	struct atmel_nand_data	*board;
+	struct atmel_nand_data	board;
 	struct device		*dev;
 	void __iomem		*ecc;
 
@@ -101,8 +105,8 @@ static int cpu_has_dma(void)
  */
 static void atmel_nand_enable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 0);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 0);
 }
 
 /*
@@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
  */
 static void atmel_nand_disable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 1);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 1);
 }
 
 /*
@@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
 		return;
 
 	if (ctrl & NAND_CLE)
-		writeb(cmd, host->io_base + (1 << host->board->cle));
+		writeb(cmd, host->io_base + (1 << host->board.cle));
 	else
-		writeb(cmd, host->io_base + (1 << host->board->ale));
+		writeb(cmd, host->io_base + (1 << host->board.ale));
 }
 
 /*
@@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
 	struct nand_chip *nand_chip = mtd->priv;
 	struct atmel_nand_host *host = nand_chip->priv;
 
-	return gpio_get_value(host->board->rdy_pin) ^
-                !!host->board->rdy_pin_active_low;
+	return gpio_get_value(host->board.rdy_pin) ^
+                !!host->board.rdy_pin_active_low;
 }
 
 static void dma_complete_func(void *completion)
@@ -432,6 +436,54 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
 	}
 }
 
+static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
+					 struct device_node *np)
+{
+	u32 val;
+	int ecc_mode;
+	struct atmel_nand_data *board = &host->board;
+	enum of_gpio_flags flags;
+
+	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid addr-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->ale = val;
+	}
+
+	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid cmd-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->cle = val;
+	}
+
+	ecc_mode = of_get_nand_ecc_mode(np);
+
+	if (ecc_mode < 0)
+		board->ecc_mode = NAND_ECC_SOFT;
+	else
+		board->ecc_mode = ecc_mode;
+
+	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
+
+	if (of_get_nand_bus_width(np) == 16)
+		board->bus_width_16 = 1;
+
+	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
+	if (flags == OF_GPIO_ACTIVE_LOW)
+		board->rdy_pin_active_low = 1;
+	else
+		board->rdy_pin_active_low = 0;
+
+	board->enable_pin = of_get_gpio(np, 1);
+	board->det_pin = of_get_gpio(np, 2);
+
+	return 0;
+}
+
 /*
  * Probe for the NAND device.
  */
@@ -442,6 +494,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	struct nand_chip *nand_chip;
 	struct resource *regs;
 	struct resource *mem;
+	struct mtd_part_parser_data ppdata = {};
 	int res;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -468,8 +521,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	mtd = &host->mtd;
 	nand_chip = &host->nand_chip;
-	host->board = pdev->dev.platform_data;
 	host->dev = &pdev->dev;
+	if (pdev->dev.of_node) {
+		res = atmel_of_init_port(host, pdev->dev.of_node);
+		if (res)
+			goto err_nand_ioremap;
+	} else {
+		memcpy(&host->board, pdev->dev.platform_data,
+		       sizeof(struct atmel_nand_data));
+	}
 
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
@@ -480,10 +540,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	nand_chip->IO_ADDR_W = host->io_base;
 	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
 
-	if (gpio_is_valid(host->board->rdy_pin))
+	if (gpio_is_valid(host->board.rdy_pin))
 		nand_chip->dev_ready = atmel_nand_device_ready;
 
-	nand_chip->ecc.mode = host->board->ecc_mode;
+	nand_chip->ecc.mode = host->board.ecc_mode;
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
@@ -508,7 +568,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	nand_chip->chip_delay = 20;		/* 20us command delay time */
 
-	if (host->board->bus_width_16)	/* 16-bit bus width */
+	if (host->board.bus_width_16)	/* 16-bit bus width */
 		nand_chip->options |= NAND_BUSWIDTH_16;
 
 	nand_chip->read_buf = atmel_read_buf;
@@ -517,15 +577,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 	atmel_nand_enable(host);
 
-	if (gpio_is_valid(host->board->det_pin)) {
-		if (gpio_get_value(host->board->det_pin)) {
+	if (gpio_is_valid(host->board.det_pin)) {
+		if (gpio_get_value(host->board.det_pin)) {
 			printk(KERN_INFO "No SmartMedia card inserted.\n");
 			res = -ENXIO;
 			goto err_no_card;
 		}
 	}
 
-	if (host->board->on_flash_bbt || on_flash_bbt) {
+	if (host->board.on_flash_bbt || on_flash_bbt) {
 		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
 		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 	}
@@ -600,8 +660,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "atmel_nand";
-	res = mtd_device_parse_register(mtd, NULL, 0,
-			host->board->parts, host->board->num_parts);
+	ppdata.of_node = pdev->dev.of_node;
+	res = mtd_device_parse_register(mtd, NULL, &ppdata,
+			host->board.parts, host->board.num_parts);
 	if (!res)
 		return res;
 
@@ -645,11 +706,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id atmel_nand_dt_ids[] = {
+	{ .compatible = "atmel,at91rm9200-nand" },
+	{ /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
+#endif
+
 static struct platform_driver atmel_nand_driver = {
 	.remove		= __exit_p(atmel_nand_remove),
 	.driver		= {
 		.name	= "atmel_nand",
 		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
 	},
 };
 
-- 
1.7.7

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

* [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
@ 2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel

use a local copy of board informatin and fill with DT data

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss at lists.ozlabs.org
Cc: linux-mtd at lists.infradead.org
---
 .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
 drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
 2 files changed, 130 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
new file mode 100644
index 0000000..a910ab9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
@@ -0,0 +1,41 @@
+Atmel NAND flash
+
+Required properties:
+- compatible : "atmel,at91rm9200-nand".
+- reg : should specify localbus address and size used for the chip,
+	and if availlable the ECC.
+- atmel,nand-addr-offset : offset for the address latch.
+- atmel,nand-cmd-offset : offset for the command latch.
+- #address-cells, #size-cells : Must be present if the device has sub-nodes
+  representing partitions.
+
+- gpios : specifies the gpio pins to control the NAND device. detect is an
+  optional gpio and may be set to 0 if not present.
+
+Optional properties:
+- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
+
+Examples:
+nand0: nand at 40000000,0 {
+	compatible = "atmel,at91rm9200-nand";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x40000000 0x10000000
+	       0xffffe800 0x200
+	      >;
+	atmel,nand-addr-offset = <21>;
+	atmel,nand-cmd-offset = <22>;
+	nand-on-flash-bbt = <1>;
+	nand-ecc-mode = "soft";
+	gpios = <&pioC 13 0
+		 &pioC 14 0
+		 0
+		>;
+	partition at 0 {
+		...
+	};
+};
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index d3bde9b..ea7643a 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -27,6 +27,10 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -83,7 +87,7 @@ struct atmel_nand_host {
 	struct mtd_info		mtd;
 	void __iomem		*io_base;
 	dma_addr_t		io_phys;
-	struct atmel_nand_data	*board;
+	struct atmel_nand_data	board;
 	struct device		*dev;
 	void __iomem		*ecc;
 
@@ -101,8 +105,8 @@ static int cpu_has_dma(void)
  */
 static void atmel_nand_enable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 0);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 0);
 }
 
 /*
@@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
  */
 static void atmel_nand_disable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 1);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 1);
 }
 
 /*
@@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
 		return;
 
 	if (ctrl & NAND_CLE)
-		writeb(cmd, host->io_base + (1 << host->board->cle));
+		writeb(cmd, host->io_base + (1 << host->board.cle));
 	else
-		writeb(cmd, host->io_base + (1 << host->board->ale));
+		writeb(cmd, host->io_base + (1 << host->board.ale));
 }
 
 /*
@@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
 	struct nand_chip *nand_chip = mtd->priv;
 	struct atmel_nand_host *host = nand_chip->priv;
 
-	return gpio_get_value(host->board->rdy_pin) ^
-                !!host->board->rdy_pin_active_low;
+	return gpio_get_value(host->board.rdy_pin) ^
+                !!host->board.rdy_pin_active_low;
 }
 
 static void dma_complete_func(void *completion)
@@ -432,6 +436,54 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
 	}
 }
 
+static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
+					 struct device_node *np)
+{
+	u32 val;
+	int ecc_mode;
+	struct atmel_nand_data *board = &host->board;
+	enum of_gpio_flags flags;
+
+	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid addr-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->ale = val;
+	}
+
+	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid cmd-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->cle = val;
+	}
+
+	ecc_mode = of_get_nand_ecc_mode(np);
+
+	if (ecc_mode < 0)
+		board->ecc_mode = NAND_ECC_SOFT;
+	else
+		board->ecc_mode = ecc_mode;
+
+	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
+
+	if (of_get_nand_bus_width(np) == 16)
+		board->bus_width_16 = 1;
+
+	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
+	if (flags == OF_GPIO_ACTIVE_LOW)
+		board->rdy_pin_active_low = 1;
+	else
+		board->rdy_pin_active_low = 0;
+
+	board->enable_pin = of_get_gpio(np, 1);
+	board->det_pin = of_get_gpio(np, 2);
+
+	return 0;
+}
+
 /*
  * Probe for the NAND device.
  */
@@ -442,6 +494,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	struct nand_chip *nand_chip;
 	struct resource *regs;
 	struct resource *mem;
+	struct mtd_part_parser_data ppdata = {};
 	int res;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -468,8 +521,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	mtd = &host->mtd;
 	nand_chip = &host->nand_chip;
-	host->board = pdev->dev.platform_data;
 	host->dev = &pdev->dev;
+	if (pdev->dev.of_node) {
+		res = atmel_of_init_port(host, pdev->dev.of_node);
+		if (res)
+			goto err_nand_ioremap;
+	} else {
+		memcpy(&host->board, pdev->dev.platform_data,
+		       sizeof(struct atmel_nand_data));
+	}
 
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
@@ -480,10 +540,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	nand_chip->IO_ADDR_W = host->io_base;
 	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
 
-	if (gpio_is_valid(host->board->rdy_pin))
+	if (gpio_is_valid(host->board.rdy_pin))
 		nand_chip->dev_ready = atmel_nand_device_ready;
 
-	nand_chip->ecc.mode = host->board->ecc_mode;
+	nand_chip->ecc.mode = host->board.ecc_mode;
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
@@ -508,7 +568,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	nand_chip->chip_delay = 20;		/* 20us command delay time */
 
-	if (host->board->bus_width_16)	/* 16-bit bus width */
+	if (host->board.bus_width_16)	/* 16-bit bus width */
 		nand_chip->options |= NAND_BUSWIDTH_16;
 
 	nand_chip->read_buf = atmel_read_buf;
@@ -517,15 +577,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 	atmel_nand_enable(host);
 
-	if (gpio_is_valid(host->board->det_pin)) {
-		if (gpio_get_value(host->board->det_pin)) {
+	if (gpio_is_valid(host->board.det_pin)) {
+		if (gpio_get_value(host->board.det_pin)) {
 			printk(KERN_INFO "No SmartMedia card inserted.\n");
 			res = -ENXIO;
 			goto err_no_card;
 		}
 	}
 
-	if (host->board->on_flash_bbt || on_flash_bbt) {
+	if (host->board.on_flash_bbt || on_flash_bbt) {
 		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
 		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 	}
@@ -600,8 +660,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "atmel_nand";
-	res = mtd_device_parse_register(mtd, NULL, 0,
-			host->board->parts, host->board->num_parts);
+	ppdata.of_node = pdev->dev.of_node;
+	res = mtd_device_parse_register(mtd, NULL, &ppdata,
+			host->board.parts, host->board.num_parts);
 	if (!res)
 		return res;
 
@@ -645,11 +706,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id atmel_nand_dt_ids[] = {
+	{ .compatible = "atmel,at91rm9200-nand" },
+	{ /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
+#endif
+
 static struct platform_driver atmel_nand_driver = {
 	.remove		= __exit_p(atmel_nand_remove),
 	.driver		= {
 		.name	= "atmel_nand",
 		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
 	},
 };
 
-- 
1.7.7

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

* [FOR 3.4 PATCH 6/6] ARM: at91: board-dt nand switch to DT
  2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 preceding siblings ...)
  (?)
@ 2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-28  5:10 UTC (permalink / raw)
  To: linux-arm-kernel

remove the C nand devices registration

until we have the pinmux support let the bootloader initialise the pin

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 arch/arm/boot/dts/at91sam9g20.dtsi     |   17 ++++++++++
 arch/arm/boot/dts/at91sam9g45.dtsi     |   15 +++++++++
 arch/arm/boot/dts/at91sam9m10g45ek.dts |   27 ++++++++++++++++-
 arch/arm/boot/dts/usb_a9g20.dts        |   46 +++++++++++++++++++++++++++-
 arch/arm/mach-at91/board-dt.c          |   52 --------------------------------
 5 files changed, 103 insertions(+), 54 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9g20.dtsi b/arch/arm/boot/dts/at91sam9g20.dtsi
index 557b91f..dfbd4fb 100644
--- a/arch/arm/boot/dts/at91sam9g20.dtsi
+++ b/arch/arm/boot/dts/at91sam9g20.dtsi
@@ -178,6 +178,23 @@
 				interrupts = <20>;
 				status = "disabled";
 			};
+
+			nand0: nand at 40000000 {
+				compatible = "atmel,at91rm9200-nand";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				reg = <0x40000000 0x10000000
+				       0xffffe800 0x200
+				      >;
+				atmel,nand-addr-offset = <21>;
+				atmel,nand-cmd-offset = <22>;
+				gpios = <&pioC 13 0
+					 &pioC 14 0
+					 0
+					>;
+				status = "disabled";
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi b/arch/arm/boot/dts/at91sam9g45.dtsi
index 179ea52..be88fc5 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -178,6 +178,21 @@
 				interrupts = <22>;
 				status = "disabled";
 			};
+
+			nand0: nand at 40000000 {
+				compatible = "atmel,at91rm9200-nand";
+				reg = <0x40000000 0x10000000
+				       0xffffe200 0x200
+				      >;
+				atmel,nand-addr-offset = <21>;
+				atmel,nand-cmd-offset = <22>;
+				gpios = <&pioC 8 0
+					 &pioC 14 0
+					 0
+					>;
+				status = "disabled";
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/boot/dts/at91sam9m10g45ek.dts b/arch/arm/boot/dts/at91sam9m10g45ek.dts
index e538da8..30d9cd7 100644
--- a/arch/arm/boot/dts/at91sam9m10g45ek.dts
+++ b/arch/arm/boot/dts/at91sam9m10g45ek.dts
@@ -14,7 +14,7 @@
 	compatible = "atmel,at91sam9m10g45ek", "atmel,at91sam9g45", "atmel,at91sam9";
 
 	chosen {
-		bootargs = "mem=64M console=ttyS0,115200 mtdparts=atmel_nand:4M(bootstrap/uboot/kernel)ro,60M(rootfs),-(data) root=/dev/mtdblock1 rw rootfstype=jffs2";
+		bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2";
 	};
 
 	memory at 70000000 {
@@ -36,6 +36,31 @@
 				status = "okay";
 			};
 
+			nand0: nand at 40000000 {
+				nand-bus-width = <8>;
+				nand-ecc-mode = "soft";
+				nand-on-flash-bbt = <1>;
+				status = "okay";
+
+				boot at 0 {
+					label = "bootstrap/uboot/kernel";
+					reg = <0x0 0x400000>;
+				};
+
+				rootfs at 400000 {
+					label = "rootfs";
+					reg = <0x400000 0x3C00000>;
+				};
+
+				data at 4000000 {
+					label = "data";
+					reg = <0x4000000 0xC000000>;
+				};
+
+			};
+		};
+	};
+
 			usb0: ohci at 00700000 {
 				status = "okay";
 				num-ports = <2>;
diff --git a/arch/arm/boot/dts/usb_a9g20.dts b/arch/arm/boot/dts/usb_a9g20.dts
index 073afe4e..cf0fda2 100644
--- a/arch/arm/boot/dts/usb_a9g20.dts
+++ b/arch/arm/boot/dts/usb_a9g20.dts
@@ -13,7 +13,7 @@
 	compatible = "calao,usb-a9g20", "atmel,at91sam9g20", "atmel,at91sam9";
 
 	chosen {
-		bootargs = "mem=64M console=ttyS0,115200 mtdparts=atmel_nand:128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),4M(kernel),120M(rootfs),-(data) root=/dev/mtdblock5 rw rootfstype=ubifs";
+		bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock5 rw rootfstype=ubifs";
 	};
 
 	memory at 20000000 {
@@ -35,6 +35,50 @@
 				num-ports = <2>;
 				status = "okay";
 			};
+
+			nand0: nand at 40000000 {
+				nand-bus-width = <8>;
+				nand-ecc-mode = "soft";
+				nand-on-flash-bbt = <1>;
+				status = "okay";
+
+				at91bootstrap at 0 {
+					label = "at91bootstrap";
+					reg = <0x0 0x20000>;
+				};
+
+				barebox at 20000 {
+					label = "barebox";
+					reg = <0x20000 0x40000>;
+				};
+
+				bareboxenv at 60000 {
+					label = "bareboxenv";
+					reg = <0x60000 0x20000>;
+				};
+
+				bareboxenv2 at 80000 {
+					label = "bareboxenv2";
+					reg = <0x80000 0x20000>;
+				};
+
+				kernel at a0000 {
+					label = "kernel";
+					reg = <0xa0000 0x400000>;
+				};
+
+				rootfs at 4a0000 {
+					label = "rootfs";
+					reg = <0x4a0000 0x7800000>;
+				};
+
+				data at 7ca0000 {
+					label = "data";
+					reg = <0x7ca0000 0x8360000>;
+				};
+
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/mach-at91/board-dt.c b/arch/arm/mach-at91/board-dt.c
index a42cad8..6aaec27 100644
--- a/arch/arm/mach-at91/board-dt.c
+++ b/arch/arm/mach-at91/board-dt.c
@@ -19,10 +19,7 @@
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
 
-#include <mach/hardware.h>
 #include <mach/board.h>
-#include <mach/system_rev.h>
-#include <mach/at91sam9_smc.h>
 
 #include <asm/setup.h>
 #include <asm/irq.h>
@@ -30,10 +27,8 @@
 #include <asm/mach/map.h>
 #include <asm/mach/irq.h>
 
-#include "sam9_smc.h"
 #include "generic.h"
 
-
 static void __init ek_init_early(void)
 {
 	/* Initialize processor: 12.000 MHz crystal */
@@ -46,50 +41,6 @@ static void __init ek_init_early(void)
 	at91_set_serial_console(0);
 }
 
-/* det_pin is not connected */
-static struct atmel_nand_data __initdata ek_nand_data = {
-	.ale		= 21,
-	.cle		= 22,
-	.det_pin	= -EINVAL,
-	.rdy_pin	= AT91_PIN_PC8,
-	.enable_pin	= AT91_PIN_PC14,
-	.ecc_mode	= NAND_ECC_SOFT,
-	.on_flash_bbt	= 1,
-};
-
-static struct sam9_smc_config __initdata ek_nand_smc_config = {
-	.ncs_read_setup		= 0,
-	.nrd_setup		= 2,
-	.ncs_write_setup	= 0,
-	.nwe_setup		= 2,
-
-	.ncs_read_pulse		= 4,
-	.nrd_pulse		= 4,
-	.ncs_write_pulse	= 4,
-	.nwe_pulse		= 4,
-
-	.read_cycle		= 7,
-	.write_cycle		= 7,
-
-	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
-	.tdf_cycles		= 3,
-};
-
-static void __init ek_add_device_nand(void)
-{
-	ek_nand_data.bus_width_16 = board_have_nand_16bit();
-	/* setup bus-width (8 or 16) */
-	if (ek_nand_data.bus_width_16)
-		ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
-	else
-		ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
-
-	/* configure chip-select 3 (NAND) */
-	sam9_smc_configure(0, 3, &ek_nand_smc_config);
-
-	at91_add_device_nand(&ek_nand_data);
-}
-
 static const struct of_device_id aic_of_match[] __initconst = {
 	{ .compatible = "atmel,at91rm9200-aic", },
 	{},
@@ -104,9 +55,6 @@ static void __init at91_dt_init_irq(void)
 static void __init at91_dt_device_init(void)
 {
 	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
-
-	/* NAND */
-	ek_add_device_nand();
 }
 
 static const char *at91_dt_board_compat[] __initdata = {
-- 
1.7.7

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

* Re: [FOR 3.4 PATCH 4/6] of/mtd/nand: add generic bindings and helpers
  2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-01-28 20:05     ` Grant Likely
  -1 siblings, 0 replies; 64+ messages in thread
From: Grant Likely @ 2012-01-28 20:05 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: linux-mtd, devicetree-discuss, Nicolas Ferre, linux-arm-kernel

On Sat, Jan 28, 2012 at 06:10:42AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> - nand-ecc-mode : String, operation mode of the NAND ecc mode.
>   Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
>   "soft_bch".
> - nand-bus-width : 8 or 16 bus width if not present 8
> - nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss@lists.ozlabs.org
> Cc: linux-mtd@lists.infradead.org

Fine by me.

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

> ---
>  Documentation/devicetree/bindings/mtd/nand.txt |    7 ++
>  drivers/of/Kconfig                             |    4 +
>  drivers/of/Makefile                            |    1 +
>  drivers/of/of_mtd.c                            |   90 ++++++++++++++++++++++++
>  include/linux/of_mtd.h                         |   19 +++++
>  5 files changed, 121 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/nand.txt
>  create mode 100644 drivers/of/of_mtd.c
>  create mode 100644 include/linux/of_mtd.h
> 
> diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt
> new file mode 100644
> index 0000000..03855c8
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/nand.txt
> @@ -0,0 +1,7 @@
> +* MTD generic binding
> +
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> index 268163d..fa666a9 100644
> --- a/drivers/of/Kconfig
> +++ b/drivers/of/Kconfig
> @@ -90,4 +90,8 @@ config OF_PCI_IRQ
>  	help
>  	  OpenFirmware PCI IRQ routing helpers
>  
> +config OF_MTD
> +	depends on MTD
> +	def_bool y
> +
>  endmenu # OF
> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> index a73f5a5..8c4980a 100644
> --- a/drivers/of/Makefile
> +++ b/drivers/of/Makefile
> @@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
>  obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
>  obj-$(CONFIG_OF_PCI)	+= of_pci.o
>  obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
> +obj-$(CONFIG_OF_NET)	+= of_mtd.o
> diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
> new file mode 100644
> index 0000000..199bf58
> --- /dev/null
> +++ b/drivers/of/of_mtd.c
> @@ -0,0 +1,90 @@
> +/*
> + * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> + *
> + * OF helpers for mtd.
> + *
> + * This file is released under the GPLv2
> + *
> + */
> +#include <linux/kernel.h>
> +#include <linux/of_mtd.h>
> +#include <linux/mtd/nand.h>
> +#include <linux/export.h>
> +
> +/**
> + * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
> + * into the device tree binding of 'phy-mode', so that Ethernet
> + * device driver can get phy interface from device tree.
> + */
> +static const char *nand_ecc_modes[] = {
> +	[NAND_ECC_NONE]		= "none",
> +	[NAND_ECC_SOFT]		= "soft",
> +	[NAND_ECC_HW]		= "hw",
> +	[NAND_ECC_HW_SYNDROME]	= "hw_syndrome",
> +	[NAND_ECC_HW_OOB_FIRST]	= "hw_oob_first",
> +	[NAND_ECC_SOFT_BCH]	= "soft_bch",
> +};
> +
> +/**
> + * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * The function gets ecc mode string from property 'nand-ecc-mode',
> + * and return its index in nand_ecc_modes table, or errno in error case.
> + */
> +const int of_get_nand_ecc_mode(struct device_node *np)
> +{
> +	const char *pm;
> +	int err, i;
> +
> +	err = of_property_read_string(np, "nand-ecc-mode", &pm);
> +	if (err < 0)
> +		return err;
> +
> +	for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
> +		if (!strcasecmp(pm, nand_ecc_modes[i]))
> +			return i;
> +
> +	return -ENODEV;
> +}
> +EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
> +
> +/**
> + * of_get_nand_bus_width - Get nand bus witdh for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * return bus width option, or errno in error case.
> + */
> +int of_get_nand_bus_width(struct device_node *np)
> +{
> +	u32 val;
> +
> +	if (of_property_read_u32(np, "nand-bus-width", &val))
> +		return 8;
> +
> +	switch(val) {
> +	case 8:
> +	case 16:
> +		return val;
> +	default:
> +		return -EIO;
> +	}
> +}
> +EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
> +
> +/**
> + * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * return true if 1 false other wise
> + */
> +bool of_get_nand_on_flash_bbt(struct device_node *np)
> +{
> +	u32 val;
> +
> +	if (of_property_read_u32(np, "nand-on-flash-bbt", &val))
> +		return false;
> +
> +	return val ? true : false;
> +}
> +EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
> diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
> new file mode 100644
> index 0000000..bae1b60
> --- /dev/null
> +++ b/include/linux/of_mtd.h
> @@ -0,0 +1,19 @@
> +/*
> + * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> + *
> + * OF helpers for mtd.
> + *
> + * This file is released under the GPLv2
> + */
> +
> +#ifndef __LINUX_OF_MTD_H
> +#define __LINUX_OF_NET_H
> +
> +#ifdef CONFIG_OF_MTD
> +#include <linux/of.h>
> +extern const int of_get_nand_ecc_mode(struct device_node *np);
> +int of_get_nand_bus_width(struct device_node *np);
> +bool of_get_nand_on_flash_bbt(struct device_node *np);
> +#endif
> +
> +#endif /* __LINUX_OF_MTD_H */
> -- 
> 1.7.7
> 
> 
> _______________________________________________
> 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] 64+ messages in thread

* [FOR 3.4 PATCH 4/6] of/mtd/nand: add generic bindings and helpers
@ 2012-01-28 20:05     ` Grant Likely
  0 siblings, 0 replies; 64+ messages in thread
From: Grant Likely @ 2012-01-28 20:05 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Jan 28, 2012 at 06:10:42AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> - nand-ecc-mode : String, operation mode of the NAND ecc mode.
>   Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
>   "soft_bch".
> - nand-bus-width : 8 or 16 bus width if not present 8
> - nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss at lists.ozlabs.org
> Cc: linux-mtd at lists.infradead.org

Fine by me.

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

> ---
>  Documentation/devicetree/bindings/mtd/nand.txt |    7 ++
>  drivers/of/Kconfig                             |    4 +
>  drivers/of/Makefile                            |    1 +
>  drivers/of/of_mtd.c                            |   90 ++++++++++++++++++++++++
>  include/linux/of_mtd.h                         |   19 +++++
>  5 files changed, 121 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/nand.txt
>  create mode 100644 drivers/of/of_mtd.c
>  create mode 100644 include/linux/of_mtd.h
> 
> diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt
> new file mode 100644
> index 0000000..03855c8
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/nand.txt
> @@ -0,0 +1,7 @@
> +* MTD generic binding
> +
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> index 268163d..fa666a9 100644
> --- a/drivers/of/Kconfig
> +++ b/drivers/of/Kconfig
> @@ -90,4 +90,8 @@ config OF_PCI_IRQ
>  	help
>  	  OpenFirmware PCI IRQ routing helpers
>  
> +config OF_MTD
> +	depends on MTD
> +	def_bool y
> +
>  endmenu # OF
> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> index a73f5a5..8c4980a 100644
> --- a/drivers/of/Makefile
> +++ b/drivers/of/Makefile
> @@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
>  obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
>  obj-$(CONFIG_OF_PCI)	+= of_pci.o
>  obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
> +obj-$(CONFIG_OF_NET)	+= of_mtd.o
> diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
> new file mode 100644
> index 0000000..199bf58
> --- /dev/null
> +++ b/drivers/of/of_mtd.c
> @@ -0,0 +1,90 @@
> +/*
> + * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> + *
> + * OF helpers for mtd.
> + *
> + * This file is released under the GPLv2
> + *
> + */
> +#include <linux/kernel.h>
> +#include <linux/of_mtd.h>
> +#include <linux/mtd/nand.h>
> +#include <linux/export.h>
> +
> +/**
> + * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
> + * into the device tree binding of 'phy-mode', so that Ethernet
> + * device driver can get phy interface from device tree.
> + */
> +static const char *nand_ecc_modes[] = {
> +	[NAND_ECC_NONE]		= "none",
> +	[NAND_ECC_SOFT]		= "soft",
> +	[NAND_ECC_HW]		= "hw",
> +	[NAND_ECC_HW_SYNDROME]	= "hw_syndrome",
> +	[NAND_ECC_HW_OOB_FIRST]	= "hw_oob_first",
> +	[NAND_ECC_SOFT_BCH]	= "soft_bch",
> +};
> +
> +/**
> + * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * The function gets ecc mode string from property 'nand-ecc-mode',
> + * and return its index in nand_ecc_modes table, or errno in error case.
> + */
> +const int of_get_nand_ecc_mode(struct device_node *np)
> +{
> +	const char *pm;
> +	int err, i;
> +
> +	err = of_property_read_string(np, "nand-ecc-mode", &pm);
> +	if (err < 0)
> +		return err;
> +
> +	for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
> +		if (!strcasecmp(pm, nand_ecc_modes[i]))
> +			return i;
> +
> +	return -ENODEV;
> +}
> +EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
> +
> +/**
> + * of_get_nand_bus_width - Get nand bus witdh for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * return bus width option, or errno in error case.
> + */
> +int of_get_nand_bus_width(struct device_node *np)
> +{
> +	u32 val;
> +
> +	if (of_property_read_u32(np, "nand-bus-width", &val))
> +		return 8;
> +
> +	switch(val) {
> +	case 8:
> +	case 16:
> +		return val;
> +	default:
> +		return -EIO;
> +	}
> +}
> +EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
> +
> +/**
> + * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
> + * @np:	Pointer to the given device_node
> + *
> + * return true if 1 false other wise
> + */
> +bool of_get_nand_on_flash_bbt(struct device_node *np)
> +{
> +	u32 val;
> +
> +	if (of_property_read_u32(np, "nand-on-flash-bbt", &val))
> +		return false;
> +
> +	return val ? true : false;
> +}
> +EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
> diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
> new file mode 100644
> index 0000000..bae1b60
> --- /dev/null
> +++ b/include/linux/of_mtd.h
> @@ -0,0 +1,19 @@
> +/*
> + * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> + *
> + * OF helpers for mtd.
> + *
> + * This file is released under the GPLv2
> + */
> +
> +#ifndef __LINUX_OF_MTD_H
> +#define __LINUX_OF_NET_H
> +
> +#ifdef CONFIG_OF_MTD
> +#include <linux/of.h>
> +extern const int of_get_nand_ecc_mode(struct device_node *np);
> +int of_get_nand_bus_width(struct device_node *np);
> +bool of_get_nand_on_flash_bbt(struct device_node *np);
> +#endif
> +
> +#endif /* __LINUX_OF_MTD_H */
> -- 
> 1.7.7
> 
> 
> _______________________________________________
> 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] 64+ messages in thread

* Re: [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
  2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
@ 2012-01-28 20:08       ` Grant Likely
  -1 siblings, 0 replies; 64+ messages in thread
From: Grant Likely @ 2012-01-28 20:08 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Sat, Jan 28, 2012 at 06:10:43AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org

Nitpicks below, but otherwise:

Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

> ---
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
>  drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
>  2 files changed, 130 insertions(+), 18 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> +	and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> +  representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> +  optional gpio and may be set to 0 if not present.
> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand@40000000,0 {
> +	compatible = "atmel,at91rm9200-nand";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	reg = <0x40000000 0x10000000
> +	       0xffffe800 0x200
> +	      >;
> +	atmel,nand-addr-offset = <21>;
> +	atmel,nand-cmd-offset = <22>;
> +	nand-on-flash-bbt = <1>;
> +	nand-ecc-mode = "soft";
> +	gpios = <&pioC 13 0
> +		 &pioC 14 0
> +		 0
> +		>;
> +	partition@0 {
> +		...
> +	};
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index d3bde9b..ea7643a 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/nand.h>
>  #include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
>  	struct mtd_info		mtd;
>  	void __iomem		*io_base;
>  	dma_addr_t		io_phys;
> -	struct atmel_nand_data	*board;
> +	struct atmel_nand_data	board;
>  	struct device		*dev;
>  	void __iomem		*ecc;
>  
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
>   */
>  static void atmel_nand_enable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 0);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 0);
>  }
>  
>  /*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
>   */
>  static void atmel_nand_disable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 1);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 1);
>  }
>  
>  /*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
>  		return;
>  
>  	if (ctrl & NAND_CLE)
> -		writeb(cmd, host->io_base + (1 << host->board->cle));
> +		writeb(cmd, host->io_base + (1 << host->board.cle));
>  	else
> -		writeb(cmd, host->io_base + (1 << host->board->ale));
> +		writeb(cmd, host->io_base + (1 << host->board.ale));
>  }
>  
>  /*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
>  	struct nand_chip *nand_chip = mtd->priv;
>  	struct atmel_nand_host *host = nand_chip->priv;
>  
> -	return gpio_get_value(host->board->rdy_pin) ^
> -                !!host->board->rdy_pin_active_low;
> +	return gpio_get_value(host->board.rdy_pin) ^
> +                !!host->board.rdy_pin_active_low;
>  }
>  
>  static void dma_complete_func(void *completion)
> @@ -432,6 +436,54 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
>  	}
>  }
>  
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)
> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	if (ecc_mode < 0)
> +		board->ecc_mode = NAND_ECC_SOFT;
> +	else
> +		board->ecc_mode = ecc_mode;

Nit: board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;

> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	if (flags == OF_GPIO_ACTIVE_LOW)
> +		board->rdy_pin_active_low = 1;
> +	else
> +		board->rdy_pin_active_low = 0;

Nit: board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);

Just a bit more compact that way.

> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -442,6 +494,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -468,8 +521,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);
> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;
> @@ -480,10 +540,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	nand_chip->IO_ADDR_W = host->io_base;
>  	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>  
> -	if (gpio_is_valid(host->board->rdy_pin))
> +	if (gpio_is_valid(host->board.rdy_pin))
>  		nand_chip->dev_ready = atmel_nand_device_ready;
>  
> -	nand_chip->ecc.mode = host->board->ecc_mode;
> +	nand_chip->ecc.mode = host->board.ecc_mode;
>  
>  	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>  	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -508,7 +568,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	nand_chip->chip_delay = 20;		/* 20us command delay time */
>  
> -	if (host->board->bus_width_16)	/* 16-bit bus width */
> +	if (host->board.bus_width_16)	/* 16-bit bus width */
>  		nand_chip->options |= NAND_BUSWIDTH_16;
>  
>  	nand_chip->read_buf = atmel_read_buf;
> @@ -517,15 +577,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, host);
>  	atmel_nand_enable(host);
>  
> -	if (gpio_is_valid(host->board->det_pin)) {
> -		if (gpio_get_value(host->board->det_pin)) {
> +	if (gpio_is_valid(host->board.det_pin)) {
> +		if (gpio_get_value(host->board.det_pin)) {
>  			printk(KERN_INFO "No SmartMedia card inserted.\n");
>  			res = -ENXIO;
>  			goto err_no_card;
>  		}
>  	}
>  
> -	if (host->board->on_flash_bbt || on_flash_bbt) {
> +	if (host->board.on_flash_bbt || on_flash_bbt) {
>  		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
>  		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
>  	}
> @@ -600,8 +660,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	}
>  
>  	mtd->name = "atmel_nand";
> -	res = mtd_device_parse_register(mtd, NULL, 0,
> -			host->board->parts, host->board->num_parts);
> +	ppdata.of_node = pdev->dev.of_node;
> +	res = mtd_device_parse_register(mtd, NULL, &ppdata,
> +			host->board.parts, host->board.num_parts);
>  	if (!res)
>  		return res;
>  
> @@ -645,11 +706,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> +	{ .compatible = "atmel,at91rm9200-nand" },
> +	{ /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
>  static struct platform_driver atmel_nand_driver = {
>  	.remove		= __exit_p(atmel_nand_remove),
>  	.driver		= {
>  		.name	= "atmel_nand",
>  		.owner	= THIS_MODULE,
> +		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
>  	},
>  };
>  
> -- 
> 1.7.7
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
@ 2012-01-28 20:08       ` Grant Likely
  0 siblings, 0 replies; 64+ messages in thread
From: Grant Likely @ 2012-01-28 20:08 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: linux-mtd, devicetree-discuss, Nicolas Ferre, linux-arm-kernel

On Sat, Jan 28, 2012 at 06:10:43AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss@lists.ozlabs.org
> Cc: linux-mtd@lists.infradead.org

Nitpicks below, but otherwise:

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

> ---
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
>  drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
>  2 files changed, 130 insertions(+), 18 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> +	and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> +  representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> +  optional gpio and may be set to 0 if not present.
> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand@40000000,0 {
> +	compatible = "atmel,at91rm9200-nand";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	reg = <0x40000000 0x10000000
> +	       0xffffe800 0x200
> +	      >;
> +	atmel,nand-addr-offset = <21>;
> +	atmel,nand-cmd-offset = <22>;
> +	nand-on-flash-bbt = <1>;
> +	nand-ecc-mode = "soft";
> +	gpios = <&pioC 13 0
> +		 &pioC 14 0
> +		 0
> +		>;
> +	partition@0 {
> +		...
> +	};
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index d3bde9b..ea7643a 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/nand.h>
>  #include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
>  	struct mtd_info		mtd;
>  	void __iomem		*io_base;
>  	dma_addr_t		io_phys;
> -	struct atmel_nand_data	*board;
> +	struct atmel_nand_data	board;
>  	struct device		*dev;
>  	void __iomem		*ecc;
>  
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
>   */
>  static void atmel_nand_enable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 0);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 0);
>  }
>  
>  /*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
>   */
>  static void atmel_nand_disable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 1);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 1);
>  }
>  
>  /*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
>  		return;
>  
>  	if (ctrl & NAND_CLE)
> -		writeb(cmd, host->io_base + (1 << host->board->cle));
> +		writeb(cmd, host->io_base + (1 << host->board.cle));
>  	else
> -		writeb(cmd, host->io_base + (1 << host->board->ale));
> +		writeb(cmd, host->io_base + (1 << host->board.ale));
>  }
>  
>  /*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
>  	struct nand_chip *nand_chip = mtd->priv;
>  	struct atmel_nand_host *host = nand_chip->priv;
>  
> -	return gpio_get_value(host->board->rdy_pin) ^
> -                !!host->board->rdy_pin_active_low;
> +	return gpio_get_value(host->board.rdy_pin) ^
> +                !!host->board.rdy_pin_active_low;
>  }
>  
>  static void dma_complete_func(void *completion)
> @@ -432,6 +436,54 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
>  	}
>  }
>  
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)
> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	if (ecc_mode < 0)
> +		board->ecc_mode = NAND_ECC_SOFT;
> +	else
> +		board->ecc_mode = ecc_mode;

Nit: board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;

> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	if (flags == OF_GPIO_ACTIVE_LOW)
> +		board->rdy_pin_active_low = 1;
> +	else
> +		board->rdy_pin_active_low = 0;

Nit: board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);

Just a bit more compact that way.

> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -442,6 +494,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -468,8 +521,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);
> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;
> @@ -480,10 +540,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	nand_chip->IO_ADDR_W = host->io_base;
>  	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>  
> -	if (gpio_is_valid(host->board->rdy_pin))
> +	if (gpio_is_valid(host->board.rdy_pin))
>  		nand_chip->dev_ready = atmel_nand_device_ready;
>  
> -	nand_chip->ecc.mode = host->board->ecc_mode;
> +	nand_chip->ecc.mode = host->board.ecc_mode;
>  
>  	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>  	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -508,7 +568,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	nand_chip->chip_delay = 20;		/* 20us command delay time */
>  
> -	if (host->board->bus_width_16)	/* 16-bit bus width */
> +	if (host->board.bus_width_16)	/* 16-bit bus width */
>  		nand_chip->options |= NAND_BUSWIDTH_16;
>  
>  	nand_chip->read_buf = atmel_read_buf;
> @@ -517,15 +577,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, host);
>  	atmel_nand_enable(host);
>  
> -	if (gpio_is_valid(host->board->det_pin)) {
> -		if (gpio_get_value(host->board->det_pin)) {
> +	if (gpio_is_valid(host->board.det_pin)) {
> +		if (gpio_get_value(host->board.det_pin)) {
>  			printk(KERN_INFO "No SmartMedia card inserted.\n");
>  			res = -ENXIO;
>  			goto err_no_card;
>  		}
>  	}
>  
> -	if (host->board->on_flash_bbt || on_flash_bbt) {
> +	if (host->board.on_flash_bbt || on_flash_bbt) {
>  		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
>  		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
>  	}
> @@ -600,8 +660,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	}
>  
>  	mtd->name = "atmel_nand";
> -	res = mtd_device_parse_register(mtd, NULL, 0,
> -			host->board->parts, host->board->num_parts);
> +	ppdata.of_node = pdev->dev.of_node;
> +	res = mtd_device_parse_register(mtd, NULL, &ppdata,
> +			host->board.parts, host->board.num_parts);
>  	if (!res)
>  		return res;
>  
> @@ -645,11 +706,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> +	{ .compatible = "atmel,at91rm9200-nand" },
> +	{ /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
>  static struct platform_driver atmel_nand_driver = {
>  	.remove		= __exit_p(atmel_nand_remove),
>  	.driver		= {
>  		.name	= "atmel_nand",
>  		.owner	= THIS_MODULE,
> +		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
>  	},
>  };
>  
> -- 
> 1.7.7
> 
> 
> _______________________________________________
> 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] 64+ messages in thread

* [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
@ 2012-01-28 20:08       ` Grant Likely
  0 siblings, 0 replies; 64+ messages in thread
From: Grant Likely @ 2012-01-28 20:08 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Jan 28, 2012 at 06:10:43AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss at lists.ozlabs.org
> Cc: linux-mtd at lists.infradead.org

Nitpicks below, but otherwise:

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

> ---
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
>  drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
>  2 files changed, 130 insertions(+), 18 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> +	and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> +  representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> +  optional gpio and may be set to 0 if not present.
> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand at 40000000,0 {
> +	compatible = "atmel,at91rm9200-nand";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	reg = <0x40000000 0x10000000
> +	       0xffffe800 0x200
> +	      >;
> +	atmel,nand-addr-offset = <21>;
> +	atmel,nand-cmd-offset = <22>;
> +	nand-on-flash-bbt = <1>;
> +	nand-ecc-mode = "soft";
> +	gpios = <&pioC 13 0
> +		 &pioC 14 0
> +		 0
> +		>;
> +	partition at 0 {
> +		...
> +	};
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index d3bde9b..ea7643a 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/nand.h>
>  #include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
>  	struct mtd_info		mtd;
>  	void __iomem		*io_base;
>  	dma_addr_t		io_phys;
> -	struct atmel_nand_data	*board;
> +	struct atmel_nand_data	board;
>  	struct device		*dev;
>  	void __iomem		*ecc;
>  
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
>   */
>  static void atmel_nand_enable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 0);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 0);
>  }
>  
>  /*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
>   */
>  static void atmel_nand_disable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 1);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 1);
>  }
>  
>  /*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
>  		return;
>  
>  	if (ctrl & NAND_CLE)
> -		writeb(cmd, host->io_base + (1 << host->board->cle));
> +		writeb(cmd, host->io_base + (1 << host->board.cle));
>  	else
> -		writeb(cmd, host->io_base + (1 << host->board->ale));
> +		writeb(cmd, host->io_base + (1 << host->board.ale));
>  }
>  
>  /*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
>  	struct nand_chip *nand_chip = mtd->priv;
>  	struct atmel_nand_host *host = nand_chip->priv;
>  
> -	return gpio_get_value(host->board->rdy_pin) ^
> -                !!host->board->rdy_pin_active_low;
> +	return gpio_get_value(host->board.rdy_pin) ^
> +                !!host->board.rdy_pin_active_low;
>  }
>  
>  static void dma_complete_func(void *completion)
> @@ -432,6 +436,54 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
>  	}
>  }
>  
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)
> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	if (ecc_mode < 0)
> +		board->ecc_mode = NAND_ECC_SOFT;
> +	else
> +		board->ecc_mode = ecc_mode;

Nit: board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;

> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	if (flags == OF_GPIO_ACTIVE_LOW)
> +		board->rdy_pin_active_low = 1;
> +	else
> +		board->rdy_pin_active_low = 0;

Nit: board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);

Just a bit more compact that way.

> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -442,6 +494,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -468,8 +521,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);
> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;
> @@ -480,10 +540,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	nand_chip->IO_ADDR_W = host->io_base;
>  	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>  
> -	if (gpio_is_valid(host->board->rdy_pin))
> +	if (gpio_is_valid(host->board.rdy_pin))
>  		nand_chip->dev_ready = atmel_nand_device_ready;
>  
> -	nand_chip->ecc.mode = host->board->ecc_mode;
> +	nand_chip->ecc.mode = host->board.ecc_mode;
>  
>  	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>  	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -508,7 +568,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	nand_chip->chip_delay = 20;		/* 20us command delay time */
>  
> -	if (host->board->bus_width_16)	/* 16-bit bus width */
> +	if (host->board.bus_width_16)	/* 16-bit bus width */
>  		nand_chip->options |= NAND_BUSWIDTH_16;
>  
>  	nand_chip->read_buf = atmel_read_buf;
> @@ -517,15 +577,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, host);
>  	atmel_nand_enable(host);
>  
> -	if (gpio_is_valid(host->board->det_pin)) {
> -		if (gpio_get_value(host->board->det_pin)) {
> +	if (gpio_is_valid(host->board.det_pin)) {
> +		if (gpio_get_value(host->board.det_pin)) {
>  			printk(KERN_INFO "No SmartMedia card inserted.\n");
>  			res = -ENXIO;
>  			goto err_no_card;
>  		}
>  	}
>  
> -	if (host->board->on_flash_bbt || on_flash_bbt) {
> +	if (host->board.on_flash_bbt || on_flash_bbt) {
>  		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
>  		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
>  	}
> @@ -600,8 +660,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	}
>  
>  	mtd->name = "atmel_nand";
> -	res = mtd_device_parse_register(mtd, NULL, 0,
> -			host->board->parts, host->board->num_parts);
> +	ppdata.of_node = pdev->dev.of_node;
> +	res = mtd_device_parse_register(mtd, NULL, &ppdata,
> +			host->board.parts, host->board.num_parts);
>  	if (!res)
>  		return res;
>  
> @@ -645,11 +706,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> +	{ .compatible = "atmel,at91rm9200-nand" },
> +	{ /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
>  static struct platform_driver atmel_nand_driver = {
>  	.remove		= __exit_p(atmel_nand_remove),
>  	.driver		= {
>  		.name	= "atmel_nand",
>  		.owner	= THIS_MODULE,
> +		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
>  	},
>  };
>  
> -- 
> 1.7.7
> 
> 
> _______________________________________________
> 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] 64+ messages in thread

* Re: [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
  2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
@ 2012-01-29 18:31       ` Simon Glass
  -1 siblings, 0 replies; 64+ messages in thread
From: Simon Glass @ 2012-01-29 18:31 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Hi,

On Fri, Jan 27, 2012 at 9:10 PM, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org> wrote:
> use a local copy of board informatin and fill with DT data
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> ---
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
>  drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
>  2 files changed, 130 insertions(+), 18 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
>
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> +       and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> +  representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> +  optional gpio and may be set to 0 if not present.

What does this mean please? What is 'detect' and what 'control' do the
gpios provide?

Below you have two GPIOs pioC 13 and pioC 14. I think the binding
should document the two GPIOs, the order, and what they are for.

> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand@40000000,0 {
> +       compatible = "atmel,at91rm9200-nand";
> +       #address-cells = <1>;
> +       #size-cells = <1>;
> +       reg = <0x40000000 0x10000000
> +              0xffffe800 0x200
> +             >;
> +       atmel,nand-addr-offset = <21>;
> +       atmel,nand-cmd-offset = <22>;
> +       nand-on-flash-bbt = <1>;
> +       nand-ecc-mode = "soft";
> +       gpios = <&pioC 13 0
> +                &pioC 14 0
> +                0

Sorry, I haven't seen this before, perhaps it is a standard thing in
Linux. Does 0 mean end of list? Can we not just use the property's
size value for this?

Regards,
Simon

> +               >;
> +       partition@0 {
> +               ...
> +       };
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index d3bde9b..ea7643a 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/nand.h>
>  #include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
>        struct mtd_info         mtd;
>        void __iomem            *io_base;
>        dma_addr_t              io_phys;
> -       struct atmel_nand_data  *board;
> +       struct atmel_nand_data  board;
>        struct device           *dev;
>        void __iomem            *ecc;
>
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
>  */
>  static void atmel_nand_enable(struct atmel_nand_host *host)
>  {
> -       if (gpio_is_valid(host->board->enable_pin))
> -               gpio_set_value(host->board->enable_pin, 0);
> +       if (gpio_is_valid(host->board.enable_pin))
> +               gpio_set_value(host->board.enable_pin, 0);
>  }
>
>  /*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
>  */
>  static void atmel_nand_disable(struct atmel_nand_host *host)
>  {
> -       if (gpio_is_valid(host->board->enable_pin))
> -               gpio_set_value(host->board->enable_pin, 1);
> +       if (gpio_is_valid(host->board.enable_pin))
> +               gpio_set_value(host->board.enable_pin, 1);
>  }
>
>  /*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
>                return;
>
>        if (ctrl & NAND_CLE)
> -               writeb(cmd, host->io_base + (1 << host->board->cle));
> +               writeb(cmd, host->io_base + (1 << host->board.cle));
>        else
> -               writeb(cmd, host->io_base + (1 << host->board->ale));
> +               writeb(cmd, host->io_base + (1 << host->board.ale));
>  }
>
>  /*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
>        struct nand_chip *nand_chip = mtd->priv;
>        struct atmel_nand_host *host = nand_chip->priv;
>
> -       return gpio_get_value(host->board->rdy_pin) ^
> -                !!host->board->rdy_pin_active_low;
> +       return gpio_get_value(host->board.rdy_pin) ^
> +                !!host->board.rdy_pin_active_low;
>  }
>
>  static void dma_complete_func(void *completion)
> @@ -432,6 +436,54 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
>        }
>  }
>
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +                                        struct device_node *np)
> +{
> +       u32 val;
> +       int ecc_mode;
> +       struct atmel_nand_data *board = &host->board;
> +       enum of_gpio_flags flags;
> +
> +       if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +               if (val >= 32) {
> +                       dev_err(host->dev, "invalid addr-offset %u\n", val);
> +                       return -EINVAL;
> +               }
> +               board->ale = val;
> +       }
> +
> +       if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +               if (val >= 32) {
> +                       dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +                       return -EINVAL;
> +               }
> +               board->cle = val;
> +       }
> +
> +       ecc_mode = of_get_nand_ecc_mode(np);
> +
> +       if (ecc_mode < 0)
> +               board->ecc_mode = NAND_ECC_SOFT;
> +       else
> +               board->ecc_mode = ecc_mode;
> +
> +       board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +       if (of_get_nand_bus_width(np) == 16)
> +               board->bus_width_16 = 1;
> +
> +       board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +       if (flags == OF_GPIO_ACTIVE_LOW)
> +               board->rdy_pin_active_low = 1;
> +       else
> +               board->rdy_pin_active_low = 0;
> +
> +       board->enable_pin = of_get_gpio(np, 1);
> +       board->det_pin = of_get_gpio(np, 2);
> +
> +       return 0;
> +}
> +
>  /*
>  * Probe for the NAND device.
>  */
> @@ -442,6 +494,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>        struct nand_chip *nand_chip;
>        struct resource *regs;
>        struct resource *mem;
> +       struct mtd_part_parser_data ppdata = {};
>        int res;
>
>        mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -468,8 +521,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>
>        mtd = &host->mtd;
>        nand_chip = &host->nand_chip;
> -       host->board = pdev->dev.platform_data;
>        host->dev = &pdev->dev;
> +       if (pdev->dev.of_node) {
> +               res = atmel_of_init_port(host, pdev->dev.of_node);
> +               if (res)
> +                       goto err_nand_ioremap;
> +       } else {
> +               memcpy(&host->board, pdev->dev.platform_data,
> +                      sizeof(struct atmel_nand_data));
> +       }
>
>        nand_chip->priv = host;         /* link the private data structures */
>        mtd->priv = nand_chip;
> @@ -480,10 +540,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>        nand_chip->IO_ADDR_W = host->io_base;
>        nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>
> -       if (gpio_is_valid(host->board->rdy_pin))
> +       if (gpio_is_valid(host->board.rdy_pin))
>                nand_chip->dev_ready = atmel_nand_device_ready;
>
> -       nand_chip->ecc.mode = host->board->ecc_mode;
> +       nand_chip->ecc.mode = host->board.ecc_mode;
>
>        regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>        if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -508,7 +568,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>
>        nand_chip->chip_delay = 20;             /* 20us command delay time */
>
> -       if (host->board->bus_width_16)  /* 16-bit bus width */
> +       if (host->board.bus_width_16)   /* 16-bit bus width */
>                nand_chip->options |= NAND_BUSWIDTH_16;
>
>        nand_chip->read_buf = atmel_read_buf;
> @@ -517,15 +577,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>        platform_set_drvdata(pdev, host);
>        atmel_nand_enable(host);
>
> -       if (gpio_is_valid(host->board->det_pin)) {
> -               if (gpio_get_value(host->board->det_pin)) {
> +       if (gpio_is_valid(host->board.det_pin)) {
> +               if (gpio_get_value(host->board.det_pin)) {
>                        printk(KERN_INFO "No SmartMedia card inserted.\n");
>                        res = -ENXIO;
>                        goto err_no_card;
>                }
>        }
>
> -       if (host->board->on_flash_bbt || on_flash_bbt) {
> +       if (host->board.on_flash_bbt || on_flash_bbt) {
>                printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
>                nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
>        }
> @@ -600,8 +660,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>        }
>
>        mtd->name = "atmel_nand";
> -       res = mtd_device_parse_register(mtd, NULL, 0,
> -                       host->board->parts, host->board->num_parts);
> +       ppdata.of_node = pdev->dev.of_node;
> +       res = mtd_device_parse_register(mtd, NULL, &ppdata,
> +                       host->board.parts, host->board.num_parts);
>        if (!res)
>                return res;
>
> @@ -645,11 +706,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
>        return 0;
>  }
>
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> +       { .compatible = "atmel,at91rm9200-nand" },
> +       { /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
>  static struct platform_driver atmel_nand_driver = {
>        .remove         = __exit_p(atmel_nand_remove),
>        .driver         = {
>                .name   = "atmel_nand",
>                .owner  = THIS_MODULE,
> +               .of_match_table = of_match_ptr(atmel_nand_dt_ids),
>        },
>  };
>
> --
> 1.7.7
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
@ 2012-01-29 18:31       ` Simon Glass
  0 siblings, 0 replies; 64+ messages in thread
From: Simon Glass @ 2012-01-29 18:31 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: linux-mtd, devicetree-discuss, Nicolas Ferre, linux-arm-kernel

Hi,

On Fri, Jan 27, 2012 at 9:10 PM, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj@jcrosoft.com> wrote:
> use a local copy of board informatin and fill with DT data
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss@lists.ozlabs.org
> Cc: linux-mtd@lists.infradead.org
> ---
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
>  drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
>  2 files changed, 130 insertions(+), 18 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
>
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> +       and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> +  representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> +  optional gpio and may be set to 0 if not present.

What does this mean please? What is 'detect' and what 'control' do the
gpios provide?

Below you have two GPIOs pioC 13 and pioC 14. I think the binding
should document the two GPIOs, the order, and what they are for.

> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand@40000000,0 {
> +       compatible = "atmel,at91rm9200-nand";
> +       #address-cells = <1>;
> +       #size-cells = <1>;
> +       reg = <0x40000000 0x10000000
> +              0xffffe800 0x200
> +             >;
> +       atmel,nand-addr-offset = <21>;
> +       atmel,nand-cmd-offset = <22>;
> +       nand-on-flash-bbt = <1>;
> +       nand-ecc-mode = "soft";
> +       gpios = <&pioC 13 0
> +                &pioC 14 0
> +                0

Sorry, I haven't seen this before, perhaps it is a standard thing in
Linux. Does 0 mean end of list? Can we not just use the property's
size value for this?

Regards,
Simon

> +               >;
> +       partition@0 {
> +               ...
> +       };
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index d3bde9b..ea7643a 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/nand.h>
>  #include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
>        struct mtd_info         mtd;
>        void __iomem            *io_base;
>        dma_addr_t              io_phys;
> -       struct atmel_nand_data  *board;
> +       struct atmel_nand_data  board;
>        struct device           *dev;
>        void __iomem            *ecc;
>
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
>  */
>  static void atmel_nand_enable(struct atmel_nand_host *host)
>  {
> -       if (gpio_is_valid(host->board->enable_pin))
> -               gpio_set_value(host->board->enable_pin, 0);
> +       if (gpio_is_valid(host->board.enable_pin))
> +               gpio_set_value(host->board.enable_pin, 0);
>  }
>
>  /*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
>  */
>  static void atmel_nand_disable(struct atmel_nand_host *host)
>  {
> -       if (gpio_is_valid(host->board->enable_pin))
> -               gpio_set_value(host->board->enable_pin, 1);
> +       if (gpio_is_valid(host->board.enable_pin))
> +               gpio_set_value(host->board.enable_pin, 1);
>  }
>
>  /*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
>                return;
>
>        if (ctrl & NAND_CLE)
> -               writeb(cmd, host->io_base + (1 << host->board->cle));
> +               writeb(cmd, host->io_base + (1 << host->board.cle));
>        else
> -               writeb(cmd, host->io_base + (1 << host->board->ale));
> +               writeb(cmd, host->io_base + (1 << host->board.ale));
>  }
>
>  /*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
>        struct nand_chip *nand_chip = mtd->priv;
>        struct atmel_nand_host *host = nand_chip->priv;
>
> -       return gpio_get_value(host->board->rdy_pin) ^
> -                !!host->board->rdy_pin_active_low;
> +       return gpio_get_value(host->board.rdy_pin) ^
> +                !!host->board.rdy_pin_active_low;
>  }
>
>  static void dma_complete_func(void *completion)
> @@ -432,6 +436,54 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
>        }
>  }
>
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +                                        struct device_node *np)
> +{
> +       u32 val;
> +       int ecc_mode;
> +       struct atmel_nand_data *board = &host->board;
> +       enum of_gpio_flags flags;
> +
> +       if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +               if (val >= 32) {
> +                       dev_err(host->dev, "invalid addr-offset %u\n", val);
> +                       return -EINVAL;
> +               }
> +               board->ale = val;
> +       }
> +
> +       if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +               if (val >= 32) {
> +                       dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +                       return -EINVAL;
> +               }
> +               board->cle = val;
> +       }
> +
> +       ecc_mode = of_get_nand_ecc_mode(np);
> +
> +       if (ecc_mode < 0)
> +               board->ecc_mode = NAND_ECC_SOFT;
> +       else
> +               board->ecc_mode = ecc_mode;
> +
> +       board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +       if (of_get_nand_bus_width(np) == 16)
> +               board->bus_width_16 = 1;
> +
> +       board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +       if (flags == OF_GPIO_ACTIVE_LOW)
> +               board->rdy_pin_active_low = 1;
> +       else
> +               board->rdy_pin_active_low = 0;
> +
> +       board->enable_pin = of_get_gpio(np, 1);
> +       board->det_pin = of_get_gpio(np, 2);
> +
> +       return 0;
> +}
> +
>  /*
>  * Probe for the NAND device.
>  */
> @@ -442,6 +494,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>        struct nand_chip *nand_chip;
>        struct resource *regs;
>        struct resource *mem;
> +       struct mtd_part_parser_data ppdata = {};
>        int res;
>
>        mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -468,8 +521,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>
>        mtd = &host->mtd;
>        nand_chip = &host->nand_chip;
> -       host->board = pdev->dev.platform_data;
>        host->dev = &pdev->dev;
> +       if (pdev->dev.of_node) {
> +               res = atmel_of_init_port(host, pdev->dev.of_node);
> +               if (res)
> +                       goto err_nand_ioremap;
> +       } else {
> +               memcpy(&host->board, pdev->dev.platform_data,
> +                      sizeof(struct atmel_nand_data));
> +       }
>
>        nand_chip->priv = host;         /* link the private data structures */
>        mtd->priv = nand_chip;
> @@ -480,10 +540,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>        nand_chip->IO_ADDR_W = host->io_base;
>        nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>
> -       if (gpio_is_valid(host->board->rdy_pin))
> +       if (gpio_is_valid(host->board.rdy_pin))
>                nand_chip->dev_ready = atmel_nand_device_ready;
>
> -       nand_chip->ecc.mode = host->board->ecc_mode;
> +       nand_chip->ecc.mode = host->board.ecc_mode;
>
>        regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>        if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -508,7 +568,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>
>        nand_chip->chip_delay = 20;             /* 20us command delay time */
>
> -       if (host->board->bus_width_16)  /* 16-bit bus width */
> +       if (host->board.bus_width_16)   /* 16-bit bus width */
>                nand_chip->options |= NAND_BUSWIDTH_16;
>
>        nand_chip->read_buf = atmel_read_buf;
> @@ -517,15 +577,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>        platform_set_drvdata(pdev, host);
>        atmel_nand_enable(host);
>
> -       if (gpio_is_valid(host->board->det_pin)) {
> -               if (gpio_get_value(host->board->det_pin)) {
> +       if (gpio_is_valid(host->board.det_pin)) {
> +               if (gpio_get_value(host->board.det_pin)) {
>                        printk(KERN_INFO "No SmartMedia card inserted.\n");
>                        res = -ENXIO;
>                        goto err_no_card;
>                }
>        }
>
> -       if (host->board->on_flash_bbt || on_flash_bbt) {
> +       if (host->board.on_flash_bbt || on_flash_bbt) {
>                printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
>                nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
>        }
> @@ -600,8 +660,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>        }
>
>        mtd->name = "atmel_nand";
> -       res = mtd_device_parse_register(mtd, NULL, 0,
> -                       host->board->parts, host->board->num_parts);
> +       ppdata.of_node = pdev->dev.of_node;
> +       res = mtd_device_parse_register(mtd, NULL, &ppdata,
> +                       host->board.parts, host->board.num_parts);
>        if (!res)
>                return res;
>
> @@ -645,11 +706,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
>        return 0;
>  }
>
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> +       { .compatible = "atmel,at91rm9200-nand" },
> +       { /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
>  static struct platform_driver atmel_nand_driver = {
>        .remove         = __exit_p(atmel_nand_remove),
>        .driver         = {
>                .name   = "atmel_nand",
>                .owner  = THIS_MODULE,
> +               .of_match_table = of_match_ptr(atmel_nand_dt_ids),
>        },
>  };
>
> --
> 1.7.7
>
>
> _______________________________________________
> 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] 64+ messages in thread

* [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
@ 2012-01-29 18:31       ` Simon Glass
  0 siblings, 0 replies; 64+ messages in thread
From: Simon Glass @ 2012-01-29 18:31 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Fri, Jan 27, 2012 at 9:10 PM, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj@jcrosoft.com> wrote:
> use a local copy of board informatin and fill with DT data
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss at lists.ozlabs.org
> Cc: linux-mtd at lists.infradead.org
> ---
> ?.../devicetree/bindings/mtd/atmel-nand.txt ? ? ? ? | ? 41 ++++++++
> ?drivers/mtd/nand/atmel_nand.c ? ? ? ? ? ? ? ? ? ? ?| ?107 ++++++++++++++++----
> ?2 files changed, 130 insertions(+), 18 deletions(-)
> ?create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
>
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> + ? ? ? and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> + ?representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> + ?optional gpio and may be set to 0 if not present.

What does this mean please? What is 'detect' and what 'control' do the
gpios provide?

Below you have two GPIOs pioC 13 and pioC 14. I think the binding
should document the two GPIOs, the order, and what they are for.

> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> + ?Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> + ?"soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand at 40000000,0 {
> + ? ? ? compatible = "atmel,at91rm9200-nand";
> + ? ? ? #address-cells = <1>;
> + ? ? ? #size-cells = <1>;
> + ? ? ? reg = <0x40000000 0x10000000
> + ? ? ? ? ? ? ?0xffffe800 0x200
> + ? ? ? ? ? ? >;
> + ? ? ? atmel,nand-addr-offset = <21>;
> + ? ? ? atmel,nand-cmd-offset = <22>;
> + ? ? ? nand-on-flash-bbt = <1>;
> + ? ? ? nand-ecc-mode = "soft";
> + ? ? ? gpios = <&pioC 13 0
> + ? ? ? ? ? ? ? ?&pioC 14 0
> + ? ? ? ? ? ? ? ?0

Sorry, I haven't seen this before, perhaps it is a standard thing in
Linux. Does 0 mean end of list? Can we not just use the property's
size value for this?

Regards,
Simon

> + ? ? ? ? ? ? ? >;
> + ? ? ? partition at 0 {
> + ? ? ? ? ? ? ? ...
> + ? ? ? };
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index d3bde9b..ea7643a 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
> ?#include <linux/module.h>
> ?#include <linux/moduleparam.h>
> ?#include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
> ?#include <linux/mtd/mtd.h>
> ?#include <linux/mtd/nand.h>
> ?#include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
> ? ? ? ?struct mtd_info ? ? ? ? mtd;
> ? ? ? ?void __iomem ? ? ? ? ? ?*io_base;
> ? ? ? ?dma_addr_t ? ? ? ? ? ? ?io_phys;
> - ? ? ? struct atmel_nand_data ?*board;
> + ? ? ? struct atmel_nand_data ?board;
> ? ? ? ?struct device ? ? ? ? ? *dev;
> ? ? ? ?void __iomem ? ? ? ? ? ?*ecc;
>
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
> ?*/
> ?static void atmel_nand_enable(struct atmel_nand_host *host)
> ?{
> - ? ? ? if (gpio_is_valid(host->board->enable_pin))
> - ? ? ? ? ? ? ? gpio_set_value(host->board->enable_pin, 0);
> + ? ? ? if (gpio_is_valid(host->board.enable_pin))
> + ? ? ? ? ? ? ? gpio_set_value(host->board.enable_pin, 0);
> ?}
>
> ?/*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
> ?*/
> ?static void atmel_nand_disable(struct atmel_nand_host *host)
> ?{
> - ? ? ? if (gpio_is_valid(host->board->enable_pin))
> - ? ? ? ? ? ? ? gpio_set_value(host->board->enable_pin, 1);
> + ? ? ? if (gpio_is_valid(host->board.enable_pin))
> + ? ? ? ? ? ? ? gpio_set_value(host->board.enable_pin, 1);
> ?}
>
> ?/*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
> ? ? ? ? ? ? ? ?return;
>
> ? ? ? ?if (ctrl & NAND_CLE)
> - ? ? ? ? ? ? ? writeb(cmd, host->io_base + (1 << host->board->cle));
> + ? ? ? ? ? ? ? writeb(cmd, host->io_base + (1 << host->board.cle));
> ? ? ? ?else
> - ? ? ? ? ? ? ? writeb(cmd, host->io_base + (1 << host->board->ale));
> + ? ? ? ? ? ? ? writeb(cmd, host->io_base + (1 << host->board.ale));
> ?}
>
> ?/*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
> ? ? ? ?struct nand_chip *nand_chip = mtd->priv;
> ? ? ? ?struct atmel_nand_host *host = nand_chip->priv;
>
> - ? ? ? return gpio_get_value(host->board->rdy_pin) ^
> - ? ? ? ? ? ? ? ?!!host->board->rdy_pin_active_low;
> + ? ? ? return gpio_get_value(host->board.rdy_pin) ^
> + ? ? ? ? ? ? ? ?!!host->board.rdy_pin_active_low;
> ?}
>
> ?static void dma_complete_func(void *completion)
> @@ -432,6 +436,54 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
> ? ? ? ?}
> ?}
>
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct device_node *np)
> +{
> + ? ? ? u32 val;
> + ? ? ? int ecc_mode;
> + ? ? ? struct atmel_nand_data *board = &host->board;
> + ? ? ? enum of_gpio_flags flags;
> +
> + ? ? ? if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> + ? ? ? ? ? ? ? if (val >= 32) {
> + ? ? ? ? ? ? ? ? ? ? ? dev_err(host->dev, "invalid addr-offset %u\n", val);
> + ? ? ? ? ? ? ? ? ? ? ? return -EINVAL;
> + ? ? ? ? ? ? ? }
> + ? ? ? ? ? ? ? board->ale = val;
> + ? ? ? }
> +
> + ? ? ? if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> + ? ? ? ? ? ? ? if (val >= 32) {
> + ? ? ? ? ? ? ? ? ? ? ? dev_err(host->dev, "invalid cmd-offset %u\n", val);
> + ? ? ? ? ? ? ? ? ? ? ? return -EINVAL;
> + ? ? ? ? ? ? ? }
> + ? ? ? ? ? ? ? board->cle = val;
> + ? ? ? }
> +
> + ? ? ? ecc_mode = of_get_nand_ecc_mode(np);
> +
> + ? ? ? if (ecc_mode < 0)
> + ? ? ? ? ? ? ? board->ecc_mode = NAND_ECC_SOFT;
> + ? ? ? else
> + ? ? ? ? ? ? ? board->ecc_mode = ecc_mode;
> +
> + ? ? ? board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> + ? ? ? if (of_get_nand_bus_width(np) == 16)
> + ? ? ? ? ? ? ? board->bus_width_16 = 1;
> +
> + ? ? ? board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> + ? ? ? if (flags == OF_GPIO_ACTIVE_LOW)
> + ? ? ? ? ? ? ? board->rdy_pin_active_low = 1;
> + ? ? ? else
> + ? ? ? ? ? ? ? board->rdy_pin_active_low = 0;
> +
> + ? ? ? board->enable_pin = of_get_gpio(np, 1);
> + ? ? ? board->det_pin = of_get_gpio(np, 2);
> +
> + ? ? ? return 0;
> +}
> +
> ?/*
> ?* Probe for the NAND device.
> ?*/
> @@ -442,6 +494,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
> ? ? ? ?struct nand_chip *nand_chip;
> ? ? ? ?struct resource *regs;
> ? ? ? ?struct resource *mem;
> + ? ? ? struct mtd_part_parser_data ppdata = {};
> ? ? ? ?int res;
>
> ? ? ? ?mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -468,8 +521,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>
> ? ? ? ?mtd = &host->mtd;
> ? ? ? ?nand_chip = &host->nand_chip;
> - ? ? ? host->board = pdev->dev.platform_data;
> ? ? ? ?host->dev = &pdev->dev;
> + ? ? ? if (pdev->dev.of_node) {
> + ? ? ? ? ? ? ? res = atmel_of_init_port(host, pdev->dev.of_node);
> + ? ? ? ? ? ? ? if (res)
> + ? ? ? ? ? ? ? ? ? ? ? goto err_nand_ioremap;
> + ? ? ? } else {
> + ? ? ? ? ? ? ? memcpy(&host->board, pdev->dev.platform_data,
> + ? ? ? ? ? ? ? ? ? ? ?sizeof(struct atmel_nand_data));
> + ? ? ? }
>
> ? ? ? ?nand_chip->priv = host; ? ? ? ? /* link the private data structures */
> ? ? ? ?mtd->priv = nand_chip;
> @@ -480,10 +540,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
> ? ? ? ?nand_chip->IO_ADDR_W = host->io_base;
> ? ? ? ?nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>
> - ? ? ? if (gpio_is_valid(host->board->rdy_pin))
> + ? ? ? if (gpio_is_valid(host->board.rdy_pin))
> ? ? ? ? ? ? ? ?nand_chip->dev_ready = atmel_nand_device_ready;
>
> - ? ? ? nand_chip->ecc.mode = host->board->ecc_mode;
> + ? ? ? nand_chip->ecc.mode = host->board.ecc_mode;
>
> ? ? ? ?regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> ? ? ? ?if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -508,7 +568,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>
> ? ? ? ?nand_chip->chip_delay = 20; ? ? ? ? ? ? /* 20us command delay time */
>
> - ? ? ? if (host->board->bus_width_16) ?/* 16-bit bus width */
> + ? ? ? if (host->board.bus_width_16) ? /* 16-bit bus width */
> ? ? ? ? ? ? ? ?nand_chip->options |= NAND_BUSWIDTH_16;
>
> ? ? ? ?nand_chip->read_buf = atmel_read_buf;
> @@ -517,15 +577,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
> ? ? ? ?platform_set_drvdata(pdev, host);
> ? ? ? ?atmel_nand_enable(host);
>
> - ? ? ? if (gpio_is_valid(host->board->det_pin)) {
> - ? ? ? ? ? ? ? if (gpio_get_value(host->board->det_pin)) {
> + ? ? ? if (gpio_is_valid(host->board.det_pin)) {
> + ? ? ? ? ? ? ? if (gpio_get_value(host->board.det_pin)) {
> ? ? ? ? ? ? ? ? ? ? ? ?printk(KERN_INFO "No SmartMedia card inserted.\n");
> ? ? ? ? ? ? ? ? ? ? ? ?res = -ENXIO;
> ? ? ? ? ? ? ? ? ? ? ? ?goto err_no_card;
> ? ? ? ? ? ? ? ?}
> ? ? ? ?}
>
> - ? ? ? if (host->board->on_flash_bbt || on_flash_bbt) {
> + ? ? ? if (host->board.on_flash_bbt || on_flash_bbt) {
> ? ? ? ? ? ? ? ?printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
> ? ? ? ? ? ? ? ?nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
> ? ? ? ?}
> @@ -600,8 +660,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
> ? ? ? ?}
>
> ? ? ? ?mtd->name = "atmel_nand";
> - ? ? ? res = mtd_device_parse_register(mtd, NULL, 0,
> - ? ? ? ? ? ? ? ? ? ? ? host->board->parts, host->board->num_parts);
> + ? ? ? ppdata.of_node = pdev->dev.of_node;
> + ? ? ? res = mtd_device_parse_register(mtd, NULL, &ppdata,
> + ? ? ? ? ? ? ? ? ? ? ? host->board.parts, host->board.num_parts);
> ? ? ? ?if (!res)
> ? ? ? ? ? ? ? ?return res;
>
> @@ -645,11 +706,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
> ? ? ? ?return 0;
> ?}
>
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> + ? ? ? { .compatible = "atmel,at91rm9200-nand" },
> + ? ? ? { /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
> ?static struct platform_driver atmel_nand_driver = {
> ? ? ? ?.remove ? ? ? ? = __exit_p(atmel_nand_remove),
> ? ? ? ?.driver ? ? ? ? = {
> ? ? ? ? ? ? ? ?.name ? = "atmel_nand",
> ? ? ? ? ? ? ? ?.owner ?= THIS_MODULE,
> + ? ? ? ? ? ? ? .of_match_table = of_match_ptr(atmel_nand_dt_ids),
> ? ? ? ?},
> ?};
>
> --
> 1.7.7
>
>
> _______________________________________________
> 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] 64+ messages in thread

* Re: [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
  2012-01-29 18:31       ` Simon Glass
  (?)
@ 2012-01-30  5:56           ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-30  5:56 UTC (permalink / raw)
  To: Simon Glass
  Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 10:31 Sun 29 Jan     , Simon Glass wrote:
> Hi,
> 
> On Fri, Jan 27, 2012 at 9:10 PM, Jean-Christophe PLAGNIOL-VILLARD
> <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org> wrote:
> > use a local copy of board informatin and fill with DT data
> >
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> > Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> > Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> > Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> > ---
> >  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
> >  drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
> >  2 files changed, 130 insertions(+), 18 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> >
> > diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> > new file mode 100644
> > index 0000000..a910ab9
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> > @@ -0,0 +1,41 @@
> > +Atmel NAND flash
> > +
> > +Required properties:
> > +- compatible : "atmel,at91rm9200-nand".
> > +- reg : should specify localbus address and size used for the chip,
> > +       and if availlable the ECC.
> > +- atmel,nand-addr-offset : offset for the address latch.
> > +- atmel,nand-cmd-offset : offset for the command latch.
> > +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> > +  representing partitions.
> > +
> > +- gpios : specifies the gpio pins to control the NAND device. detect is an
> > +  optional gpio and may be set to 0 if not present.
> 
> What does this mean please? What is 'detect' and what 'control' do the
> gpios provide?
> 
> Below you have two GPIOs pioC 13 and pioC 14. I think the binding
> should document the two GPIOs, the order, and what they are for.
no as it's said in the binding the detect pin is optional
> 
> > +
> > +Optional properties:
> > +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> > +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> > +  "soft_bch".
> > +- nand-bus-width : 8 or 16 bus width if not present 8
> > +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> > +
> > +Examples:
> > +nand0: nand@40000000,0 {
> > +       compatible = "atmel,at91rm9200-nand";
> > +       #address-cells = <1>;
> > +       #size-cells = <1>;
> > +       reg = <0x40000000 0x10000000
> > +              0xffffe800 0x200
> > +             >;
> > +       atmel,nand-addr-offset = <21>;
> > +       atmel,nand-cmd-offset = <22>;
> > +       nand-on-flash-bbt = <1>;
> > +       nand-ecc-mode = "soft";
> > +       gpios = <&pioC 13 0
> > +                &pioC 14 0
> > +                0
> 
> Sorry, I haven't seen this before, perhaps it is a standard thing in
> Linux. Does 0 mean end of list? Can we not just use the property's
> size value for this?
0 means not used as specified in the DT

Best Regards,
J.

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

* Re: [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
@ 2012-01-30  5:56           ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-30  5:56 UTC (permalink / raw)
  To: Simon Glass
  Cc: linux-mtd, devicetree-discuss, Nicolas Ferre, linux-arm-kernel

On 10:31 Sun 29 Jan     , Simon Glass wrote:
> Hi,
> 
> On Fri, Jan 27, 2012 at 9:10 PM, Jean-Christophe PLAGNIOL-VILLARD
> <plagnioj@jcrosoft.com> wrote:
> > use a local copy of board informatin and fill with DT data
> >
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> > Cc: devicetree-discuss@lists.ozlabs.org
> > Cc: linux-mtd@lists.infradead.org
> > ---
> >  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
> >  drivers/mtd/nand/atmel_nand.c                      |  107 ++++++++++++++++----
> >  2 files changed, 130 insertions(+), 18 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> >
> > diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> > new file mode 100644
> > index 0000000..a910ab9
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> > @@ -0,0 +1,41 @@
> > +Atmel NAND flash
> > +
> > +Required properties:
> > +- compatible : "atmel,at91rm9200-nand".
> > +- reg : should specify localbus address and size used for the chip,
> > +       and if availlable the ECC.
> > +- atmel,nand-addr-offset : offset for the address latch.
> > +- atmel,nand-cmd-offset : offset for the command latch.
> > +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> > +  representing partitions.
> > +
> > +- gpios : specifies the gpio pins to control the NAND device. detect is an
> > +  optional gpio and may be set to 0 if not present.
> 
> What does this mean please? What is 'detect' and what 'control' do the
> gpios provide?
> 
> Below you have two GPIOs pioC 13 and pioC 14. I think the binding
> should document the two GPIOs, the order, and what they are for.
no as it's said in the binding the detect pin is optional
> 
> > +
> > +Optional properties:
> > +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> > +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> > +  "soft_bch".
> > +- nand-bus-width : 8 or 16 bus width if not present 8
> > +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> > +
> > +Examples:
> > +nand0: nand@40000000,0 {
> > +       compatible = "atmel,at91rm9200-nand";
> > +       #address-cells = <1>;
> > +       #size-cells = <1>;
> > +       reg = <0x40000000 0x10000000
> > +              0xffffe800 0x200
> > +             >;
> > +       atmel,nand-addr-offset = <21>;
> > +       atmel,nand-cmd-offset = <22>;
> > +       nand-on-flash-bbt = <1>;
> > +       nand-ecc-mode = "soft";
> > +       gpios = <&pioC 13 0
> > +                &pioC 14 0
> > +                0
> 
> Sorry, I haven't seen this before, perhaps it is a standard thing in
> Linux. Does 0 mean end of list? Can we not just use the property's
> size value for this?
0 means not used as specified in the DT

Best Regards,
J.

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

* [FOR 3.4 PATCH 5/6] atmel/nand: add DT support
@ 2012-01-30  5:56           ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-01-30  5:56 UTC (permalink / raw)
  To: linux-arm-kernel

On 10:31 Sun 29 Jan     , Simon Glass wrote:
> Hi,
> 
> On Fri, Jan 27, 2012 at 9:10 PM, Jean-Christophe PLAGNIOL-VILLARD
> <plagnioj@jcrosoft.com> wrote:
> > use a local copy of board informatin and fill with DT data
> >
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> > Cc: devicetree-discuss at lists.ozlabs.org
> > Cc: linux-mtd at lists.infradead.org
> > ---
> > ?.../devicetree/bindings/mtd/atmel-nand.txt ? ? ? ? | ? 41 ++++++++
> > ?drivers/mtd/nand/atmel_nand.c ? ? ? ? ? ? ? ? ? ? ?| ?107 ++++++++++++++++----
> > ?2 files changed, 130 insertions(+), 18 deletions(-)
> > ?create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> >
> > diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> > new file mode 100644
> > index 0000000..a910ab9
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> > @@ -0,0 +1,41 @@
> > +Atmel NAND flash
> > +
> > +Required properties:
> > +- compatible : "atmel,at91rm9200-nand".
> > +- reg : should specify localbus address and size used for the chip,
> > + ? ? ? and if availlable the ECC.
> > +- atmel,nand-addr-offset : offset for the address latch.
> > +- atmel,nand-cmd-offset : offset for the command latch.
> > +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> > + ?representing partitions.
> > +
> > +- gpios : specifies the gpio pins to control the NAND device. detect is an
> > + ?optional gpio and may be set to 0 if not present.
> 
> What does this mean please? What is 'detect' and what 'control' do the
> gpios provide?
> 
> Below you have two GPIOs pioC 13 and pioC 14. I think the binding
> should document the two GPIOs, the order, and what they are for.
no as it's said in the binding the detect pin is optional
> 
> > +
> > +Optional properties:
> > +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> > + ?Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> > + ?"soft_bch".
> > +- nand-bus-width : 8 or 16 bus width if not present 8
> > +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> > +
> > +Examples:
> > +nand0: nand at 40000000,0 {
> > + ? ? ? compatible = "atmel,at91rm9200-nand";
> > + ? ? ? #address-cells = <1>;
> > + ? ? ? #size-cells = <1>;
> > + ? ? ? reg = <0x40000000 0x10000000
> > + ? ? ? ? ? ? ?0xffffe800 0x200
> > + ? ? ? ? ? ? >;
> > + ? ? ? atmel,nand-addr-offset = <21>;
> > + ? ? ? atmel,nand-cmd-offset = <22>;
> > + ? ? ? nand-on-flash-bbt = <1>;
> > + ? ? ? nand-ecc-mode = "soft";
> > + ? ? ? gpios = <&pioC 13 0
> > + ? ? ? ? ? ? ? ?&pioC 14 0
> > + ? ? ? ? ? ? ? ?0
> 
> Sorry, I haven't seen this before, perhaps it is a standard thing in
> Linux. Does 0 mean end of list? Can we not just use the property's
> size value for this?
0 means not used as specified in the DT

Best Regards,
J.

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

* [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
  2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-06 10:35 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, devicetree-discuss,
	Jean-Christophe PLAGNIOL-VILLARD, linux-mtd

- nand-ecc-mode : String, operation mode of the NAND ecc mode.
  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
  "soft_bch".
- nand-bus-width : 8 or 16 bus width if not present 8
- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss@lists.ozlabs.org
Cc: linux-mtd@lists.infradead.org
---
 Documentation/devicetree/bindings/mtd/nand.txt |    7 ++
 drivers/of/Kconfig                             |    4 +
 drivers/of/Makefile                            |    1 +
 drivers/of/of_mtd.c                            |   90 ++++++++++++++++++++++++
 include/linux/of_mtd.h                         |   19 +++++
 5 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/nand.txt
 create mode 100644 drivers/of/of_mtd.c
 create mode 100644 include/linux/of_mtd.h

diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt
new file mode 100644
index 0000000..03855c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/nand.txt
@@ -0,0 +1,7 @@
+* MTD generic binding
+
+- nand-ecc-mode : String, operation mode of the NAND ecc mode.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 268163d..fa666a9 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -90,4 +90,8 @@ config OF_PCI_IRQ
 	help
 	  OpenFirmware PCI IRQ routing helpers
 
+config OF_MTD
+	depends on MTD
+	def_bool y
+
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index a73f5a5..8c4980a 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
 obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
+obj-$(CONFIG_OF_NET)	+= of_mtd.o
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
new file mode 100644
index 0000000..d7183de
--- /dev/null
+++ b/drivers/of/of_mtd.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/of_mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/export.h>
+
+/**
+ * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
+ * into the device tree binding of 'nand-ecc', so that MTD
+ * device driver can get nand ecc from device tree.
+ */
+static const char *nand_ecc_modes[] = {
+	[NAND_ECC_NONE]		= "none",
+	[NAND_ECC_SOFT]		= "soft",
+	[NAND_ECC_HW]		= "hw",
+	[NAND_ECC_HW_SYNDROME]	= "hw_syndrome",
+	[NAND_ECC_HW_OOB_FIRST]	= "hw_oob_first",
+	[NAND_ECC_SOFT_BCH]	= "soft_bch",
+};
+
+/**
+ * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * The function gets ecc mode string from property 'nand-ecc-mode',
+ * and return its index in nand_ecc_modes table, or errno in error case.
+ */
+const int of_get_nand_ecc_mode(struct device_node *np)
+{
+	const char *pm;
+	int err, i;
+
+	err = of_property_read_string(np, "nand-ecc-mode", &pm);
+	if (err < 0)
+		return err;
+
+	for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
+		if (!strcasecmp(pm, nand_ecc_modes[i]))
+			return i;
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
+
+/**
+ * of_get_nand_bus_width - Get nand bus witdh for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return bus width option, or errno in error case.
+ */
+int of_get_nand_bus_width(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-bus-width", &val))
+		return 8;
+
+	switch(val) {
+	case 8:
+	case 16:
+		return val;
+	default:
+		return -EIO;
+	}
+}
+EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
+
+/**
+ * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return true if 1 false other wise
+ */
+bool of_get_nand_on_flash_bbt(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-on-flash-bbt", &val))
+		return false;
+
+	return val ? true : false;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
new file mode 100644
index 0000000..bae1b60
--- /dev/null
+++ b/include/linux/of_mtd.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_MTD_H
+#define __LINUX_OF_NET_H
+
+#ifdef CONFIG_OF_MTD
+#include <linux/of.h>
+extern const int of_get_nand_ecc_mode(struct device_node *np);
+int of_get_nand_bus_width(struct device_node *np);
+bool of_get_nand_on_flash_bbt(struct device_node *np);
+#endif
+
+#endif /* __LINUX_OF_MTD_H */
-- 
1.7.7

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

* [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
@ 2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-06 10:35 UTC (permalink / raw)
  To: linux-arm-kernel

- nand-ecc-mode : String, operation mode of the NAND ecc mode.
  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
  "soft_bch".
- nand-bus-width : 8 or 16 bus width if not present 8
- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss at lists.ozlabs.org
Cc: linux-mtd at lists.infradead.org
---
 Documentation/devicetree/bindings/mtd/nand.txt |    7 ++
 drivers/of/Kconfig                             |    4 +
 drivers/of/Makefile                            |    1 +
 drivers/of/of_mtd.c                            |   90 ++++++++++++++++++++++++
 include/linux/of_mtd.h                         |   19 +++++
 5 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/nand.txt
 create mode 100644 drivers/of/of_mtd.c
 create mode 100644 include/linux/of_mtd.h

diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt
new file mode 100644
index 0000000..03855c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/nand.txt
@@ -0,0 +1,7 @@
+* MTD generic binding
+
+- nand-ecc-mode : String, operation mode of the NAND ecc mode.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 268163d..fa666a9 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -90,4 +90,8 @@ config OF_PCI_IRQ
 	help
 	  OpenFirmware PCI IRQ routing helpers
 
+config OF_MTD
+	depends on MTD
+	def_bool y
+
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index a73f5a5..8c4980a 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
 obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
+obj-$(CONFIG_OF_NET)	+= of_mtd.o
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
new file mode 100644
index 0000000..d7183de
--- /dev/null
+++ b/drivers/of/of_mtd.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/of_mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/export.h>
+
+/**
+ * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
+ * into the device tree binding of 'nand-ecc', so that MTD
+ * device driver can get nand ecc from device tree.
+ */
+static const char *nand_ecc_modes[] = {
+	[NAND_ECC_NONE]		= "none",
+	[NAND_ECC_SOFT]		= "soft",
+	[NAND_ECC_HW]		= "hw",
+	[NAND_ECC_HW_SYNDROME]	= "hw_syndrome",
+	[NAND_ECC_HW_OOB_FIRST]	= "hw_oob_first",
+	[NAND_ECC_SOFT_BCH]	= "soft_bch",
+};
+
+/**
+ * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * The function gets ecc mode string from property 'nand-ecc-mode',
+ * and return its index in nand_ecc_modes table, or errno in error case.
+ */
+const int of_get_nand_ecc_mode(struct device_node *np)
+{
+	const char *pm;
+	int err, i;
+
+	err = of_property_read_string(np, "nand-ecc-mode", &pm);
+	if (err < 0)
+		return err;
+
+	for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
+		if (!strcasecmp(pm, nand_ecc_modes[i]))
+			return i;
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
+
+/**
+ * of_get_nand_bus_width - Get nand bus witdh for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return bus width option, or errno in error case.
+ */
+int of_get_nand_bus_width(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-bus-width", &val))
+		return 8;
+
+	switch(val) {
+	case 8:
+	case 16:
+		return val;
+	default:
+		return -EIO;
+	}
+}
+EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
+
+/**
+ * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return true if 1 false other wise
+ */
+bool of_get_nand_on_flash_bbt(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-on-flash-bbt", &val))
+		return false;
+
+	return val ? true : false;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
new file mode 100644
index 0000000..bae1b60
--- /dev/null
+++ b/include/linux/of_mtd.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_MTD_H
+#define __LINUX_OF_NET_H
+
+#ifdef CONFIG_OF_MTD
+#include <linux/of.h>
+extern const int of_get_nand_ecc_mode(struct device_node *np);
+int of_get_nand_bus_width(struct device_node *np);
+bool of_get_nand_on_flash_bbt(struct device_node *np);
+#endif
+
+#endif /* __LINUX_OF_MTD_H */
-- 
1.7.7

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

* [PATCH 5/6 V2] atmel/nand: add DT support
  2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-06 10:35 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, devicetree-discuss,
	Jean-Christophe PLAGNIOL-VILLARD, linux-mtd

use a local copy of board informatin and fill with DT data

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss@lists.ozlabs.org
Cc: linux-mtd@lists.infradead.org
---
V2:
	comment from Grant
	rebase over rc3

Best Regards,
J.
 .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
 drivers/mtd/nand/atmel_nand.c                      |  105 ++++++++++++++++----
 2 files changed, 126 insertions(+), 20 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
new file mode 100644
index 0000000..a910ab9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
@@ -0,0 +1,41 @@
+Atmel NAND flash
+
+Required properties:
+- compatible : "atmel,at91rm9200-nand".
+- reg : should specify localbus address and size used for the chip,
+	and if availlable the ECC.
+- atmel,nand-addr-offset : offset for the address latch.
+- atmel,nand-cmd-offset : offset for the command latch.
+- #address-cells, #size-cells : Must be present if the device has sub-nodes
+  representing partitions.
+
+- gpios : specifies the gpio pins to control the NAND device. detect is an
+  optional gpio and may be set to 0 if not present.
+
+Optional properties:
+- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
+
+Examples:
+nand0: nand@40000000,0 {
+	compatible = "atmel,at91rm9200-nand";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x40000000 0x10000000
+	       0xffffe800 0x200
+	      >;
+	atmel,nand-addr-offset = <21>;
+	atmel,nand-cmd-offset = <22>;
+	nand-on-flash-bbt = <1>;
+	nand-ecc-mode = "soft";
+	gpios = <&pioC 13 0
+		 &pioC 14 0
+		 0
+		>;
+	partition@0 {
+		...
+	};
+};
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 045d174..7f91ed2 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -27,6 +27,10 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -83,7 +87,7 @@ struct atmel_nand_host {
 	struct mtd_info		mtd;
 	void __iomem		*io_base;
 	dma_addr_t		io_phys;
-	struct atmel_nand_data	*board;
+	struct atmel_nand_data	board;
 	struct device		*dev;
 	void __iomem		*ecc;
 
@@ -101,8 +105,8 @@ static int cpu_has_dma(void)
  */
 static void atmel_nand_enable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 0);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 0);
 }
 
 /*
@@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
  */
 static void atmel_nand_disable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 1);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 1);
 }
 
 /*
@@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
 		return;
 
 	if (ctrl & NAND_CLE)
-		writeb(cmd, host->io_base + (1 << host->board->cle));
+		writeb(cmd, host->io_base + (1 << host->board.cle));
 	else
-		writeb(cmd, host->io_base + (1 << host->board->ale));
+		writeb(cmd, host->io_base + (1 << host->board.ale));
 }
 
 /*
@@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
 	struct nand_chip *nand_chip = mtd->priv;
 	struct atmel_nand_host *host = nand_chip->priv;
 
-	return gpio_get_value(host->board->rdy_pin) ^
-                !!host->board->rdy_pin_active_low;
+	return gpio_get_value(host->board.rdy_pin) ^
+                !!host->board.rdy_pin_active_low;
 }
 
 /*
@@ -261,7 +265,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 		if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
 			return;
 
-	if (host->board->bus_width_16)
+	if (host->board.bus_width_16)
 		atmel_read_buf16(mtd, buf, len);
 	else
 		atmel_read_buf8(mtd, buf, len);
@@ -277,7 +281,7 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 		if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
 			return;
 
-	if (host->board->bus_width_16)
+	if (host->board.bus_width_16)
 		atmel_write_buf16(mtd, buf, len);
 	else
 		atmel_write_buf8(mtd, buf, len);
@@ -469,6 +473,48 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
 	}
 }
 
+static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
+					 struct device_node *np)
+{
+	u32 val;
+	int ecc_mode;
+	struct atmel_nand_data *board = &host->board;
+	enum of_gpio_flags flags;
+
+	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid addr-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->ale = val;
+	}
+
+	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid cmd-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->cle = val;
+	}
+
+	ecc_mode = of_get_nand_ecc_mode(np);
+
+	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
+
+	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
+
+	if (of_get_nand_bus_width(np) == 16)
+		board->bus_width_16 = 1;
+
+	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
+	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
+
+	board->enable_pin = of_get_gpio(np, 1);
+	board->det_pin = of_get_gpio(np, 2);
+
+	return 0;
+}
+
 /*
  * Probe for the NAND device.
  */
@@ -479,6 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	struct nand_chip *nand_chip;
 	struct resource *regs;
 	struct resource *mem;
+	struct mtd_part_parser_data ppdata = {};
 	int res;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -505,8 +552,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	mtd = &host->mtd;
 	nand_chip = &host->nand_chip;
-	host->board = pdev->dev.platform_data;
 	host->dev = &pdev->dev;
+	if (pdev->dev.of_node) {
+		res = atmel_of_init_port(host, pdev->dev.of_node);
+		if (res)
+			goto err_nand_ioremap;
+	} else {
+		memcpy(&host->board, pdev->dev.platform_data,
+		       sizeof(struct atmel_nand_data));
+	}
 
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
@@ -517,10 +571,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	nand_chip->IO_ADDR_W = host->io_base;
 	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
 
-	if (gpio_is_valid(host->board->rdy_pin))
+	if (gpio_is_valid(host->board.rdy_pin))
 		nand_chip->dev_ready = atmel_nand_device_ready;
 
-	nand_chip->ecc.mode = host->board->ecc_mode;
+	nand_chip->ecc.mode = host->board.ecc_mode;
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
@@ -545,7 +599,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	nand_chip->chip_delay = 20;		/* 20us command delay time */
 
-	if (host->board->bus_width_16)	/* 16-bit bus width */
+	if (host->board.bus_width_16)	/* 16-bit bus width */
 		nand_chip->options |= NAND_BUSWIDTH_16;
 
 	nand_chip->read_buf = atmel_read_buf;
@@ -554,15 +608,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 	atmel_nand_enable(host);
 
-	if (gpio_is_valid(host->board->det_pin)) {
-		if (gpio_get_value(host->board->det_pin)) {
+	if (gpio_is_valid(host->board.det_pin)) {
+		if (gpio_get_value(host->board.det_pin)) {
 			printk(KERN_INFO "No SmartMedia card inserted.\n");
 			res = -ENXIO;
 			goto err_no_card;
 		}
 	}
 
-	if (host->board->on_flash_bbt || on_flash_bbt) {
+	if (host->board.on_flash_bbt || on_flash_bbt) {
 		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
 		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 	}
@@ -637,8 +691,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "atmel_nand";
-	res = mtd_device_parse_register(mtd, NULL, 0,
-			host->board->parts, host->board->num_parts);
+	ppdata.of_node = pdev->dev.of_node;
+	res = mtd_device_parse_register(mtd, NULL, &ppdata,
+			host->board.parts, host->board.num_parts);
 	if (!res)
 		return res;
 
@@ -682,11 +737,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id atmel_nand_dt_ids[] = {
+	{ .compatible = "atmel,at91rm9200-nand" },
+	{ /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
+#endif
+
 static struct platform_driver atmel_nand_driver = {
 	.remove		= __exit_p(atmel_nand_remove),
 	.driver		= {
 		.name	= "atmel_nand",
 		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
 	},
 };
 
-- 
1.7.7

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

* [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-06 10:35 UTC (permalink / raw)
  To: linux-arm-kernel

use a local copy of board informatin and fill with DT data

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss at lists.ozlabs.org
Cc: linux-mtd at lists.infradead.org
---
V2:
	comment from Grant
	rebase over rc3

Best Regards,
J.
 .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
 drivers/mtd/nand/atmel_nand.c                      |  105 ++++++++++++++++----
 2 files changed, 126 insertions(+), 20 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
new file mode 100644
index 0000000..a910ab9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
@@ -0,0 +1,41 @@
+Atmel NAND flash
+
+Required properties:
+- compatible : "atmel,at91rm9200-nand".
+- reg : should specify localbus address and size used for the chip,
+	and if availlable the ECC.
+- atmel,nand-addr-offset : offset for the address latch.
+- atmel,nand-cmd-offset : offset for the command latch.
+- #address-cells, #size-cells : Must be present if the device has sub-nodes
+  representing partitions.
+
+- gpios : specifies the gpio pins to control the NAND device. detect is an
+  optional gpio and may be set to 0 if not present.
+
+Optional properties:
+- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
+
+Examples:
+nand0: nand at 40000000,0 {
+	compatible = "atmel,at91rm9200-nand";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x40000000 0x10000000
+	       0xffffe800 0x200
+	      >;
+	atmel,nand-addr-offset = <21>;
+	atmel,nand-cmd-offset = <22>;
+	nand-on-flash-bbt = <1>;
+	nand-ecc-mode = "soft";
+	gpios = <&pioC 13 0
+		 &pioC 14 0
+		 0
+		>;
+	partition at 0 {
+		...
+	};
+};
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 045d174..7f91ed2 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -27,6 +27,10 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -83,7 +87,7 @@ struct atmel_nand_host {
 	struct mtd_info		mtd;
 	void __iomem		*io_base;
 	dma_addr_t		io_phys;
-	struct atmel_nand_data	*board;
+	struct atmel_nand_data	board;
 	struct device		*dev;
 	void __iomem		*ecc;
 
@@ -101,8 +105,8 @@ static int cpu_has_dma(void)
  */
 static void atmel_nand_enable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 0);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 0);
 }
 
 /*
@@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
  */
 static void atmel_nand_disable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 1);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 1);
 }
 
 /*
@@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
 		return;
 
 	if (ctrl & NAND_CLE)
-		writeb(cmd, host->io_base + (1 << host->board->cle));
+		writeb(cmd, host->io_base + (1 << host->board.cle));
 	else
-		writeb(cmd, host->io_base + (1 << host->board->ale));
+		writeb(cmd, host->io_base + (1 << host->board.ale));
 }
 
 /*
@@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
 	struct nand_chip *nand_chip = mtd->priv;
 	struct atmel_nand_host *host = nand_chip->priv;
 
-	return gpio_get_value(host->board->rdy_pin) ^
-                !!host->board->rdy_pin_active_low;
+	return gpio_get_value(host->board.rdy_pin) ^
+                !!host->board.rdy_pin_active_low;
 }
 
 /*
@@ -261,7 +265,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 		if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
 			return;
 
-	if (host->board->bus_width_16)
+	if (host->board.bus_width_16)
 		atmel_read_buf16(mtd, buf, len);
 	else
 		atmel_read_buf8(mtd, buf, len);
@@ -277,7 +281,7 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 		if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
 			return;
 
-	if (host->board->bus_width_16)
+	if (host->board.bus_width_16)
 		atmel_write_buf16(mtd, buf, len);
 	else
 		atmel_write_buf8(mtd, buf, len);
@@ -469,6 +473,48 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
 	}
 }
 
+static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
+					 struct device_node *np)
+{
+	u32 val;
+	int ecc_mode;
+	struct atmel_nand_data *board = &host->board;
+	enum of_gpio_flags flags;
+
+	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid addr-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->ale = val;
+	}
+
+	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid cmd-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->cle = val;
+	}
+
+	ecc_mode = of_get_nand_ecc_mode(np);
+
+	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
+
+	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
+
+	if (of_get_nand_bus_width(np) == 16)
+		board->bus_width_16 = 1;
+
+	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
+	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
+
+	board->enable_pin = of_get_gpio(np, 1);
+	board->det_pin = of_get_gpio(np, 2);
+
+	return 0;
+}
+
 /*
  * Probe for the NAND device.
  */
@@ -479,6 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	struct nand_chip *nand_chip;
 	struct resource *regs;
 	struct resource *mem;
+	struct mtd_part_parser_data ppdata = {};
 	int res;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -505,8 +552,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	mtd = &host->mtd;
 	nand_chip = &host->nand_chip;
-	host->board = pdev->dev.platform_data;
 	host->dev = &pdev->dev;
+	if (pdev->dev.of_node) {
+		res = atmel_of_init_port(host, pdev->dev.of_node);
+		if (res)
+			goto err_nand_ioremap;
+	} else {
+		memcpy(&host->board, pdev->dev.platform_data,
+		       sizeof(struct atmel_nand_data));
+	}
 
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
@@ -517,10 +571,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	nand_chip->IO_ADDR_W = host->io_base;
 	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
 
-	if (gpio_is_valid(host->board->rdy_pin))
+	if (gpio_is_valid(host->board.rdy_pin))
 		nand_chip->dev_ready = atmel_nand_device_ready;
 
-	nand_chip->ecc.mode = host->board->ecc_mode;
+	nand_chip->ecc.mode = host->board.ecc_mode;
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
@@ -545,7 +599,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	nand_chip->chip_delay = 20;		/* 20us command delay time */
 
-	if (host->board->bus_width_16)	/* 16-bit bus width */
+	if (host->board.bus_width_16)	/* 16-bit bus width */
 		nand_chip->options |= NAND_BUSWIDTH_16;
 
 	nand_chip->read_buf = atmel_read_buf;
@@ -554,15 +608,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 	atmel_nand_enable(host);
 
-	if (gpio_is_valid(host->board->det_pin)) {
-		if (gpio_get_value(host->board->det_pin)) {
+	if (gpio_is_valid(host->board.det_pin)) {
+		if (gpio_get_value(host->board.det_pin)) {
 			printk(KERN_INFO "No SmartMedia card inserted.\n");
 			res = -ENXIO;
 			goto err_no_card;
 		}
 	}
 
-	if (host->board->on_flash_bbt || on_flash_bbt) {
+	if (host->board.on_flash_bbt || on_flash_bbt) {
 		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
 		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 	}
@@ -637,8 +691,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "atmel_nand";
-	res = mtd_device_parse_register(mtd, NULL, 0,
-			host->board->parts, host->board->num_parts);
+	ppdata.of_node = pdev->dev.of_node;
+	res = mtd_device_parse_register(mtd, NULL, &ppdata,
+			host->board.parts, host->board.num_parts);
 	if (!res)
 		return res;
 
@@ -682,11 +737,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id atmel_nand_dt_ids[] = {
+	{ .compatible = "atmel,at91rm9200-nand" },
+	{ /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
+#endif
+
 static struct platform_driver atmel_nand_driver = {
 	.remove		= __exit_p(atmel_nand_remove),
 	.driver		= {
 		.name	= "atmel_nand",
 		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
 	},
 };
 
-- 
1.7.7

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

* Re: [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
  2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-02-06 16:20     ` Stefan Roese
  -1 siblings, 0 replies; 64+ messages in thread
From: Stefan Roese @ 2012-02-06 16:20 UTC (permalink / raw)
  To: devicetree-discuss
  Cc: linux-mtd, Jean-Christophe PLAGNIOL-VILLARD, linux-arm-kernel

Hi Jean-Christophe,

On Monday 06 February 2012 11:35:11 Jean-Christophe PLAGNIOL-VILLARD wrote:
> - nand-ecc-mode : String, operation mode of the NAND ecc mode.
>   Supported values are: "none", "soft", "hw", "hw_syndrome",
> "hw_oob_first", "soft_bch".
> - nand-bus-width : 8 or 16 bus width if not present 8
> - nand-on-flash-bbt: boolean to enable on flash bbt option if not present
> false

Why not use an "empty" type (without argument) for nand-on-flash-bbt then?

Thanks,
Stefan

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

* [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
@ 2012-02-06 16:20     ` Stefan Roese
  0 siblings, 0 replies; 64+ messages in thread
From: Stefan Roese @ 2012-02-06 16:20 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Jean-Christophe,

On Monday 06 February 2012 11:35:11 Jean-Christophe PLAGNIOL-VILLARD wrote:
> - nand-ecc-mode : String, operation mode of the NAND ecc mode.
>   Supported values are: "none", "soft", "hw", "hw_syndrome",
> "hw_oob_first", "soft_bch".
> - nand-bus-width : 8 or 16 bus width if not present 8
> - nand-on-flash-bbt: boolean to enable on flash bbt option if not present
> false

Why not use an "empty" type (without argument) for nand-on-flash-bbt then?

Thanks,
Stefan

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

* Re: [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
  2012-02-06 16:20     ` Stefan Roese
  (?)
@ 2012-02-07  4:16       ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07  4:16 UTC (permalink / raw)
  To: Stefan Roese; +Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 17:20 Mon 06 Feb     , Stefan Roese wrote:
> Hi Jean-Christophe,
> 
> On Monday 06 February 2012 11:35:11 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > - nand-ecc-mode : String, operation mode of the NAND ecc mode.
> >   Supported values are: "none", "soft", "hw", "hw_syndrome",
> > "hw_oob_first", "soft_bch".
> > - nand-bus-width : 8 or 16 bus width if not present 8
> > - nand-on-flash-bbt: boolean to enable on flash bbt option if not present
> > false
> 
> Why not use an "empty" type (without argument) for nand-on-flash-bbt then?
I want to be able to disable it

I send a patch to add a helper to manage boolean

this will allow to disable a boolean

    is-ok;          => true
    is-ok = <1>;    => true
    is-ok = <0>;    => false

Best Regards,
J.

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

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

* Re: [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
@ 2012-02-07  4:16       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07  4:16 UTC (permalink / raw)
  To: Stefan Roese; +Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 17:20 Mon 06 Feb     , Stefan Roese wrote:
> Hi Jean-Christophe,
> 
> On Monday 06 February 2012 11:35:11 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > - nand-ecc-mode : String, operation mode of the NAND ecc mode.
> >   Supported values are: "none", "soft", "hw", "hw_syndrome",
> > "hw_oob_first", "soft_bch".
> > - nand-bus-width : 8 or 16 bus width if not present 8
> > - nand-on-flash-bbt: boolean to enable on flash bbt option if not present
> > false
> 
> Why not use an "empty" type (without argument) for nand-on-flash-bbt then?
I want to be able to disable it

I send a patch to add a helper to manage boolean

this will allow to disable a boolean

    is-ok;          => true
    is-ok = <1>;    => true
    is-ok = <0>;    => false

Best Regards,
J.

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

* [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
@ 2012-02-07  4:16       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07  4:16 UTC (permalink / raw)
  To: linux-arm-kernel

On 17:20 Mon 06 Feb     , Stefan Roese wrote:
> Hi Jean-Christophe,
> 
> On Monday 06 February 2012 11:35:11 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > - nand-ecc-mode : String, operation mode of the NAND ecc mode.
> >   Supported values are: "none", "soft", "hw", "hw_syndrome",
> > "hw_oob_first", "soft_bch".
> > - nand-bus-width : 8 or 16 bus width if not present 8
> > - nand-on-flash-bbt: boolean to enable on flash bbt option if not present
> > false
> 
> Why not use an "empty" type (without argument) for nand-on-flash-bbt then?
I want to be able to disable it

I send a patch to add a helper to manage boolean

this will allow to disable a boolean

    is-ok;          => true
    is-ok = <1>;    => true
    is-ok = <0>;    => false

Best Regards,
J.

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

* Re: [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
  2012-02-07  4:16       ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
@ 2012-02-07  9:45           ` Stefan Roese
  -1 siblings, 0 replies; 64+ messages in thread
From: Stefan Roese @ 2012-02-07  9:45 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ
  Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Tuesday 07 February 2012 05:16:06 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > - nand-on-flash-bbt: boolean to enable on flash bbt option if not
> > > present false
> > 
> > Why not use an "empty" type (without argument) for nand-on-flash-bbt
> > then?
> 
> I want to be able to disable it

Then just don't add this property.
 
> I send a patch to add a helper to manage boolean
> 
> this will allow to disable a boolean
> 
>     is-ok;          => true
>     is-ok = <1>;    => true
>     is-ok = <0>;    => false

Okay, fine with me.

Thanks,
Stefan

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

* Re: [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
@ 2012-02-07  9:45           ` Stefan Roese
  0 siblings, 0 replies; 64+ messages in thread
From: Stefan Roese @ 2012-02-07  9:45 UTC (permalink / raw)
  To: devicetree-discuss
  Cc: linux-mtd, Jean-Christophe PLAGNIOL-VILLARD, linux-arm-kernel

On Tuesday 07 February 2012 05:16:06 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > - nand-on-flash-bbt: boolean to enable on flash bbt option if not
> > > present false
> > 
> > Why not use an "empty" type (without argument) for nand-on-flash-bbt
> > then?
> 
> I want to be able to disable it

Then just don't add this property.
 
> I send a patch to add a helper to manage boolean
> 
> this will allow to disable a boolean
> 
>     is-ok;          => true
>     is-ok = <1>;    => true
>     is-ok = <0>;    => false

Okay, fine with me.

Thanks,
Stefan

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

* [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
@ 2012-02-07  9:45           ` Stefan Roese
  0 siblings, 0 replies; 64+ messages in thread
From: Stefan Roese @ 2012-02-07  9:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 07 February 2012 05:16:06 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > - nand-on-flash-bbt: boolean to enable on flash bbt option if not
> > > present false
> > 
> > Why not use an "empty" type (without argument) for nand-on-flash-bbt
> > then?
> 
> I want to be able to disable it

Then just don't add this property.
 
> I send a patch to add a helper to manage boolean
> 
> this will allow to disable a boolean
> 
>     is-ok;          => true
>     is-ok = <1>;    => true
>     is-ok = <0>;    => false

Okay, fine with me.

Thanks,
Stefan

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

* Re: [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
  2012-02-07  9:45           ` Stefan Roese
  (?)
@ 2012-02-07 10:10               ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07 10:10 UTC (permalink / raw)
  To: Stefan Roese
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 10:45 Tue 07 Feb     , Stefan Roese wrote:
> On Tuesday 07 February 2012 05:16:06 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > - nand-on-flash-bbt: boolean to enable on flash bbt option if not
> > > > present false
> > > 
> > > Why not use an "empty" type (without argument) for nand-on-flash-bbt
> > > then?
> > 
> > I want to be able to disable it
> 
> Then just don't add this property.
except if it's it done via include a cpu module enable it but the motherboard
dts want to disable it
>  
> > I send a patch to add a helper to manage boolean
> > 
> > this will allow to disable a boolean
> > 
> >     is-ok;          => true
> >     is-ok = <1>;    => true
> >     is-ok = <0>;    => false


Best Regrds,
J.

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

* Re: [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
@ 2012-02-07 10:10               ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07 10:10 UTC (permalink / raw)
  To: Stefan Roese; +Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 10:45 Tue 07 Feb     , Stefan Roese wrote:
> On Tuesday 07 February 2012 05:16:06 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > - nand-on-flash-bbt: boolean to enable on flash bbt option if not
> > > > present false
> > > 
> > > Why not use an "empty" type (without argument) for nand-on-flash-bbt
> > > then?
> > 
> > I want to be able to disable it
> 
> Then just don't add this property.
except if it's it done via include a cpu module enable it but the motherboard
dts want to disable it
>  
> > I send a patch to add a helper to manage boolean
> > 
> > this will allow to disable a boolean
> > 
> >     is-ok;          => true
> >     is-ok = <1>;    => true
> >     is-ok = <0>;    => false


Best Regrds,
J.

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

* [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers
@ 2012-02-07 10:10               ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07 10:10 UTC (permalink / raw)
  To: linux-arm-kernel

On 10:45 Tue 07 Feb     , Stefan Roese wrote:
> On Tuesday 07 February 2012 05:16:06 Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > - nand-on-flash-bbt: boolean to enable on flash bbt option if not
> > > > present false
> > > 
> > > Why not use an "empty" type (without argument) for nand-on-flash-bbt
> > > then?
> > 
> > I want to be able to disable it
> 
> Then just don't add this property.
except if it's it done via include a cpu module enable it but the motherboard
dts want to disable it
>  
> > I send a patch to add a helper to manage boolean
> > 
> > this will allow to disable a boolean
> > 
> >     is-ok;          => true
> >     is-ok = <1>;    => true
> >     is-ok = <0>;    => false


Best Regrds,
J.

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
  2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
@ 2012-02-07 10:30       ` Nicolas Ferre
  -1 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-07 10:30 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org

[..]

> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)

Maybe you will need to protect this function in case of !DT builds: I
suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.

> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -479,6 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -505,8 +552,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);

Called here: must compile with !CONFIG_OF

> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;

Best regards,
-- 
Nicolas Ferre

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-07 10:30       ` Nicolas Ferre
  0 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-07 10:30 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss@lists.ozlabs.org
> Cc: linux-mtd@lists.infradead.org

[..]

> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)

Maybe you will need to protect this function in case of !DT builds: I
suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.

> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -479,6 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -505,8 +552,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);

Called here: must compile with !CONFIG_OF

> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;

Best regards,
-- 
Nicolas Ferre

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

* [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-07 10:30       ` Nicolas Ferre
  0 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-07 10:30 UTC (permalink / raw)
  To: linux-arm-kernel

On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss at lists.ozlabs.org
> Cc: linux-mtd at lists.infradead.org

[..]

> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)

Maybe you will need to protect this function in case of !DT builds: I
suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.

> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -479,6 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -505,8 +552,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);

Called here: must compile with !CONFIG_OF

> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;

Best regards,
-- 
Nicolas Ferre

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
  2012-02-07 10:30       ` Nicolas Ferre
@ 2012-02-07 11:53         ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07 11:53 UTC (permalink / raw)
  To: Nicolas Ferre; +Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 11:30 Tue 07 Feb     , Nicolas Ferre wrote:
> On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
> > use a local copy of board informatin and fill with DT data
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > Acked-by: Grant Likely <grant.likely@secretlab.ca>
> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> > Cc: devicetree-discuss@lists.ozlabs.org
> > Cc: linux-mtd@lists.infradead.org
> 
> [..]
> 
> > +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> > +					 struct device_node *np)
> 
> Maybe you will need to protect this function in case of !DT builds: I
> suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.
no-need on the of_ function are static inline it !CONFIG_OF

Best Regards,
J.

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

* [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-07 11:53         ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07 11:53 UTC (permalink / raw)
  To: linux-arm-kernel

On 11:30 Tue 07 Feb     , Nicolas Ferre wrote:
> On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
> > use a local copy of board informatin and fill with DT data
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > Acked-by: Grant Likely <grant.likely@secretlab.ca>
> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> > Cc: devicetree-discuss at lists.ozlabs.org
> > Cc: linux-mtd at lists.infradead.org
> 
> [..]
> 
> > +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> > +					 struct device_node *np)
> 
> Maybe you will need to protect this function in case of !DT builds: I
> suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.
no-need on the of_ function are static inline it !CONFIG_OF

Best Regards,
J.

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

* [PATCH 4/6 v3] of/mtd/nand: add generic bindings and helpers
  2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-02-07 16:18       ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07 16:18 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

- nand-ecc-mode : String, operation mode of the NAND ecc mode.
  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
  "soft_bch".
- nand-bus-width : 8 or 16 bus width if not present 8
- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Cc: Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
---
v3:
	rebase over "of: introduce helper to manage boolean"

Best Regards,
J.
 Documentation/devicetree/bindings/mtd/nand.txt |    7 ++
 drivers/of/Kconfig                             |    4 +
 drivers/of/Makefile                            |    1 +
 drivers/of/of_mtd.c                            |   85 ++++++++++++++++++++++++
 include/linux/of_mtd.h                         |   19 +++++
 5 files changed, 116 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/nand.txt
 create mode 100644 drivers/of/of_mtd.c
 create mode 100644 include/linux/of_mtd.h

diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt
new file mode 100644
index 0000000..03855c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/nand.txt
@@ -0,0 +1,7 @@
+* MTD generic binding
+
+- nand-ecc-mode : String, operation mode of the NAND ecc mode.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 268163d..fa666a9 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -90,4 +90,8 @@ config OF_PCI_IRQ
 	help
 	  OpenFirmware PCI IRQ routing helpers
 
+config OF_MTD
+	depends on MTD
+	def_bool y
+
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index a73f5a5..8c4980a 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
 obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
+obj-$(CONFIG_OF_NET)	+= of_mtd.o
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
new file mode 100644
index 0000000..e6a1074
--- /dev/null
+++ b/drivers/of/of_mtd.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/of_mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/export.h>
+
+/**
+ * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
+ * into the device tree binding of 'nand-ecc', so that MTD
+ * device driver can get nand ecc from device tree.
+ */
+static const char *nand_ecc_modes[] = {
+	[NAND_ECC_NONE]		= "none",
+	[NAND_ECC_SOFT]		= "soft",
+	[NAND_ECC_HW]		= "hw",
+	[NAND_ECC_HW_SYNDROME]	= "hw_syndrome",
+	[NAND_ECC_HW_OOB_FIRST]	= "hw_oob_first",
+	[NAND_ECC_SOFT_BCH]	= "soft_bch",
+};
+
+/**
+ * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * The function gets ecc mode string from property 'nand-ecc-mode',
+ * and return its index in nand_ecc_modes table, or errno in error case.
+ */
+const int of_get_nand_ecc_mode(struct device_node *np)
+{
+	const char *pm;
+	int err, i;
+
+	err = of_property_read_string(np, "nand-ecc-mode", &pm);
+	if (err < 0)
+		return err;
+
+	for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
+		if (!strcasecmp(pm, nand_ecc_modes[i]))
+			return i;
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
+
+/**
+ * of_get_nand_bus_width - Get nand bus witdh for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return bus width option, or errno in error case.
+ */
+int of_get_nand_bus_width(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-bus-width", &val))
+		return 8;
+
+	switch(val) {
+	case 8:
+	case 16:
+		return val;
+	default:
+		return -EIO;
+	}
+}
+EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
+
+/**
+ * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return true if 1 false other wise
+ */
+bool of_get_nand_on_flash_bbt(struct device_node *np)
+{
+	return !!of_property_read_bool(np, "nand-on-flash-bbt");
+}
+EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
new file mode 100644
index 0000000..bae1b60
--- /dev/null
+++ b/include/linux/of_mtd.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_MTD_H
+#define __LINUX_OF_NET_H
+
+#ifdef CONFIG_OF_MTD
+#include <linux/of.h>
+extern const int of_get_nand_ecc_mode(struct device_node *np);
+int of_get_nand_bus_width(struct device_node *np);
+bool of_get_nand_on_flash_bbt(struct device_node *np);
+#endif
+
+#endif /* __LINUX_OF_MTD_H */
-- 
1.7.7

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

* [PATCH 4/6 v3] of/mtd/nand: add generic bindings and helpers
@ 2012-02-07 16:18       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-07 16:18 UTC (permalink / raw)
  To: linux-arm-kernel

- nand-ecc-mode : String, operation mode of the NAND ecc mode.
  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
  "soft_bch".
- nand-bus-width : 8 or 16 bus width if not present 8
- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Rob Herring <robherring2@gmail.com>
Cc: devicetree-discuss at lists.ozlabs.org
---
v3:
	rebase over "of: introduce helper to manage boolean"

Best Regards,
J.
 Documentation/devicetree/bindings/mtd/nand.txt |    7 ++
 drivers/of/Kconfig                             |    4 +
 drivers/of/Makefile                            |    1 +
 drivers/of/of_mtd.c                            |   85 ++++++++++++++++++++++++
 include/linux/of_mtd.h                         |   19 +++++
 5 files changed, 116 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/nand.txt
 create mode 100644 drivers/of/of_mtd.c
 create mode 100644 include/linux/of_mtd.h

diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt
new file mode 100644
index 0000000..03855c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/nand.txt
@@ -0,0 +1,7 @@
+* MTD generic binding
+
+- nand-ecc-mode : String, operation mode of the NAND ecc mode.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 268163d..fa666a9 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -90,4 +90,8 @@ config OF_PCI_IRQ
 	help
 	  OpenFirmware PCI IRQ routing helpers
 
+config OF_MTD
+	depends on MTD
+	def_bool y
+
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index a73f5a5..8c4980a 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
 obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
+obj-$(CONFIG_OF_NET)	+= of_mtd.o
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
new file mode 100644
index 0000000..e6a1074
--- /dev/null
+++ b/drivers/of/of_mtd.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/of_mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/export.h>
+
+/**
+ * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
+ * into the device tree binding of 'nand-ecc', so that MTD
+ * device driver can get nand ecc from device tree.
+ */
+static const char *nand_ecc_modes[] = {
+	[NAND_ECC_NONE]		= "none",
+	[NAND_ECC_SOFT]		= "soft",
+	[NAND_ECC_HW]		= "hw",
+	[NAND_ECC_HW_SYNDROME]	= "hw_syndrome",
+	[NAND_ECC_HW_OOB_FIRST]	= "hw_oob_first",
+	[NAND_ECC_SOFT_BCH]	= "soft_bch",
+};
+
+/**
+ * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * The function gets ecc mode string from property 'nand-ecc-mode',
+ * and return its index in nand_ecc_modes table, or errno in error case.
+ */
+const int of_get_nand_ecc_mode(struct device_node *np)
+{
+	const char *pm;
+	int err, i;
+
+	err = of_property_read_string(np, "nand-ecc-mode", &pm);
+	if (err < 0)
+		return err;
+
+	for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
+		if (!strcasecmp(pm, nand_ecc_modes[i]))
+			return i;
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
+
+/**
+ * of_get_nand_bus_width - Get nand bus witdh for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return bus width option, or errno in error case.
+ */
+int of_get_nand_bus_width(struct device_node *np)
+{
+	u32 val;
+
+	if (of_property_read_u32(np, "nand-bus-width", &val))
+		return 8;
+
+	switch(val) {
+	case 8:
+	case 16:
+		return val;
+	default:
+		return -EIO;
+	}
+}
+EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
+
+/**
+ * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
+ * @np:	Pointer to the given device_node
+ *
+ * return true if 1 false other wise
+ */
+bool of_get_nand_on_flash_bbt(struct device_node *np)
+{
+	return !!of_property_read_bool(np, "nand-on-flash-bbt");
+}
+EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
new file mode 100644
index 0000000..bae1b60
--- /dev/null
+++ b/include/linux/of_mtd.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * OF helpers for mtd.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_MTD_H
+#define __LINUX_OF_NET_H
+
+#ifdef CONFIG_OF_MTD
+#include <linux/of.h>
+extern const int of_get_nand_ecc_mode(struct device_node *np);
+int of_get_nand_bus_width(struct device_node *np);
+bool of_get_nand_on_flash_bbt(struct device_node *np);
+#endif
+
+#endif /* __LINUX_OF_MTD_H */
-- 
1.7.7

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

* Re: [PATCH 4/6 v3] of/mtd/nand: add generic bindings and helpers
  2012-02-07 16:18       ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-02-08  7:16           ` Stefan Roese
  -1 siblings, 0 replies; 64+ messages in thread
From: Stefan Roese @ 2012-02-08  7:16 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

On Tuesday 07 February 2012 17:18:30 Jean-Christophe PLAGNIOL-VILLARD wrote:
> - nand-ecc-mode : String, operation mode of the NAND ecc mode.
>   Supported values are: "none", "soft", "hw", "hw_syndrome",
> "hw_oob_first", "soft_bch".
> - nand-bus-width : 8 or 16 bus width if not present 8
> - nand-on-flash-bbt: boolean to enable on flash bbt option if not present
> false
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> Cc: Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org

Acked-by: Stefan Roese <sr-ynQEQJNshbs@public.gmane.org>

Thanks,
Stefan

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

* [PATCH 4/6 v3] of/mtd/nand: add generic bindings and helpers
@ 2012-02-08  7:16           ` Stefan Roese
  0 siblings, 0 replies; 64+ messages in thread
From: Stefan Roese @ 2012-02-08  7:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 07 February 2012 17:18:30 Jean-Christophe PLAGNIOL-VILLARD wrote:
> - nand-ecc-mode : String, operation mode of the NAND ecc mode.
>   Supported values are: "none", "soft", "hw", "hw_syndrome",
> "hw_oob_first", "soft_bch".
> - nand-bus-width : 8 or 16 bus width if not present 8
> - nand-on-flash-bbt: boolean to enable on flash bbt option if not present
> false
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> Cc: Rob Herring <robherring2@gmail.com>
> Cc: devicetree-discuss at lists.ozlabs.org

Acked-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
  2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
@ 2012-02-20 17:17       ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-20 17:17 UTC (permalink / raw)
  To: David Woodhouse
  Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 11:35 Mon 06 Feb     , Jean-Christophe PLAGNIOL-VILLARD wrote:
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> ---
> V2:
> 	comment from Grant
> 	rebase over rc3
HI David,

	I've depeancy on other at91 patch can I apply this series via at91
	tree?

Best Regards,
J.
> 
> Best Regards,
> J.
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
>  drivers/mtd/nand/atmel_nand.c                      |  105 ++++++++++++++++----
>  2 files changed, 126 insertions(+), 20 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> +	and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> +  representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> +  optional gpio and may be set to 0 if not present.
> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand@40000000,0 {
> +	compatible = "atmel,at91rm9200-nand";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	reg = <0x40000000 0x10000000
> +	       0xffffe800 0x200
> +	      >;
> +	atmel,nand-addr-offset = <21>;
> +	atmel,nand-cmd-offset = <22>;
> +	nand-on-flash-bbt = <1>;
> +	nand-ecc-mode = "soft";
> +	gpios = <&pioC 13 0
> +		 &pioC 14 0
> +		 0
> +		>;
> +	partition@0 {
> +		...
> +	};
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 045d174..7f91ed2 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/nand.h>
>  #include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
>  	struct mtd_info		mtd;
>  	void __iomem		*io_base;
>  	dma_addr_t		io_phys;
> -	struct atmel_nand_data	*board;
> +	struct atmel_nand_data	board;
>  	struct device		*dev;
>  	void __iomem		*ecc;
>  
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
>   */
>  static void atmel_nand_enable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 0);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 0);
>  }
>  
>  /*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
>   */
>  static void atmel_nand_disable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 1);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 1);
>  }
>  
>  /*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
>  		return;
>  
>  	if (ctrl & NAND_CLE)
> -		writeb(cmd, host->io_base + (1 << host->board->cle));
> +		writeb(cmd, host->io_base + (1 << host->board.cle));
>  	else
> -		writeb(cmd, host->io_base + (1 << host->board->ale));
> +		writeb(cmd, host->io_base + (1 << host->board.ale));
>  }
>  
>  /*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
>  	struct nand_chip *nand_chip = mtd->priv;
>  	struct atmel_nand_host *host = nand_chip->priv;
>  
> -	return gpio_get_value(host->board->rdy_pin) ^
> -                !!host->board->rdy_pin_active_low;
> +	return gpio_get_value(host->board.rdy_pin) ^
> +                !!host->board.rdy_pin_active_low;
>  }
>  
>  /*
> @@ -261,7 +265,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
>  		if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
>  			return;
>  
> -	if (host->board->bus_width_16)
> +	if (host->board.bus_width_16)
>  		atmel_read_buf16(mtd, buf, len);
>  	else
>  		atmel_read_buf8(mtd, buf, len);
> @@ -277,7 +281,7 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
>  		if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
>  			return;
>  
> -	if (host->board->bus_width_16)
> +	if (host->board.bus_width_16)
>  		atmel_write_buf16(mtd, buf, len);
>  	else
>  		atmel_write_buf8(mtd, buf, len);
> @@ -469,6 +473,48 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
>  	}
>  }
>  
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)
> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -479,6 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -505,8 +552,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);
> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;
> @@ -517,10 +571,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	nand_chip->IO_ADDR_W = host->io_base;
>  	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>  
> -	if (gpio_is_valid(host->board->rdy_pin))
> +	if (gpio_is_valid(host->board.rdy_pin))
>  		nand_chip->dev_ready = atmel_nand_device_ready;
>  
> -	nand_chip->ecc.mode = host->board->ecc_mode;
> +	nand_chip->ecc.mode = host->board.ecc_mode;
>  
>  	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>  	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -545,7 +599,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	nand_chip->chip_delay = 20;		/* 20us command delay time */
>  
> -	if (host->board->bus_width_16)	/* 16-bit bus width */
> +	if (host->board.bus_width_16)	/* 16-bit bus width */
>  		nand_chip->options |= NAND_BUSWIDTH_16;
>  
>  	nand_chip->read_buf = atmel_read_buf;
> @@ -554,15 +608,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, host);
>  	atmel_nand_enable(host);
>  
> -	if (gpio_is_valid(host->board->det_pin)) {
> -		if (gpio_get_value(host->board->det_pin)) {
> +	if (gpio_is_valid(host->board.det_pin)) {
> +		if (gpio_get_value(host->board.det_pin)) {
>  			printk(KERN_INFO "No SmartMedia card inserted.\n");
>  			res = -ENXIO;
>  			goto err_no_card;
>  		}
>  	}
>  
> -	if (host->board->on_flash_bbt || on_flash_bbt) {
> +	if (host->board.on_flash_bbt || on_flash_bbt) {
>  		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
>  		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
>  	}
> @@ -637,8 +691,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	}
>  
>  	mtd->name = "atmel_nand";
> -	res = mtd_device_parse_register(mtd, NULL, 0,
> -			host->board->parts, host->board->num_parts);
> +	ppdata.of_node = pdev->dev.of_node;
> +	res = mtd_device_parse_register(mtd, NULL, &ppdata,
> +			host->board.parts, host->board.num_parts);
>  	if (!res)
>  		return res;
>  
> @@ -682,11 +737,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> +	{ .compatible = "atmel,at91rm9200-nand" },
> +	{ /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
>  static struct platform_driver atmel_nand_driver = {
>  	.remove		= __exit_p(atmel_nand_remove),
>  	.driver		= {
>  		.name	= "atmel_nand",
>  		.owner	= THIS_MODULE,
> +		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
>  	},
>  };
>  
> -- 
> 1.7.7

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-20 17:17       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-20 17:17 UTC (permalink / raw)
  To: David Woodhouse
  Cc: linux-mtd, devicetree-discuss, Nicolas Ferre, linux-arm-kernel

On 11:35 Mon 06 Feb     , Jean-Christophe PLAGNIOL-VILLARD wrote:
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss@lists.ozlabs.org
> Cc: linux-mtd@lists.infradead.org
> ---
> V2:
> 	comment from Grant
> 	rebase over rc3
HI David,

	I've depeancy on other at91 patch can I apply this series via at91
	tree?

Best Regards,
J.
> 
> Best Regards,
> J.
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
>  drivers/mtd/nand/atmel_nand.c                      |  105 ++++++++++++++++----
>  2 files changed, 126 insertions(+), 20 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> +	and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> +  representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> +  optional gpio and may be set to 0 if not present.
> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand@40000000,0 {
> +	compatible = "atmel,at91rm9200-nand";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	reg = <0x40000000 0x10000000
> +	       0xffffe800 0x200
> +	      >;
> +	atmel,nand-addr-offset = <21>;
> +	atmel,nand-cmd-offset = <22>;
> +	nand-on-flash-bbt = <1>;
> +	nand-ecc-mode = "soft";
> +	gpios = <&pioC 13 0
> +		 &pioC 14 0
> +		 0
> +		>;
> +	partition@0 {
> +		...
> +	};
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 045d174..7f91ed2 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/nand.h>
>  #include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
>  	struct mtd_info		mtd;
>  	void __iomem		*io_base;
>  	dma_addr_t		io_phys;
> -	struct atmel_nand_data	*board;
> +	struct atmel_nand_data	board;
>  	struct device		*dev;
>  	void __iomem		*ecc;
>  
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
>   */
>  static void atmel_nand_enable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 0);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 0);
>  }
>  
>  /*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
>   */
>  static void atmel_nand_disable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 1);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 1);
>  }
>  
>  /*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
>  		return;
>  
>  	if (ctrl & NAND_CLE)
> -		writeb(cmd, host->io_base + (1 << host->board->cle));
> +		writeb(cmd, host->io_base + (1 << host->board.cle));
>  	else
> -		writeb(cmd, host->io_base + (1 << host->board->ale));
> +		writeb(cmd, host->io_base + (1 << host->board.ale));
>  }
>  
>  /*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
>  	struct nand_chip *nand_chip = mtd->priv;
>  	struct atmel_nand_host *host = nand_chip->priv;
>  
> -	return gpio_get_value(host->board->rdy_pin) ^
> -                !!host->board->rdy_pin_active_low;
> +	return gpio_get_value(host->board.rdy_pin) ^
> +                !!host->board.rdy_pin_active_low;
>  }
>  
>  /*
> @@ -261,7 +265,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
>  		if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
>  			return;
>  
> -	if (host->board->bus_width_16)
> +	if (host->board.bus_width_16)
>  		atmel_read_buf16(mtd, buf, len);
>  	else
>  		atmel_read_buf8(mtd, buf, len);
> @@ -277,7 +281,7 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
>  		if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
>  			return;
>  
> -	if (host->board->bus_width_16)
> +	if (host->board.bus_width_16)
>  		atmel_write_buf16(mtd, buf, len);
>  	else
>  		atmel_write_buf8(mtd, buf, len);
> @@ -469,6 +473,48 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
>  	}
>  }
>  
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)
> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -479,6 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -505,8 +552,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);
> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;
> @@ -517,10 +571,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	nand_chip->IO_ADDR_W = host->io_base;
>  	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>  
> -	if (gpio_is_valid(host->board->rdy_pin))
> +	if (gpio_is_valid(host->board.rdy_pin))
>  		nand_chip->dev_ready = atmel_nand_device_ready;
>  
> -	nand_chip->ecc.mode = host->board->ecc_mode;
> +	nand_chip->ecc.mode = host->board.ecc_mode;
>  
>  	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>  	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -545,7 +599,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	nand_chip->chip_delay = 20;		/* 20us command delay time */
>  
> -	if (host->board->bus_width_16)	/* 16-bit bus width */
> +	if (host->board.bus_width_16)	/* 16-bit bus width */
>  		nand_chip->options |= NAND_BUSWIDTH_16;
>  
>  	nand_chip->read_buf = atmel_read_buf;
> @@ -554,15 +608,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, host);
>  	atmel_nand_enable(host);
>  
> -	if (gpio_is_valid(host->board->det_pin)) {
> -		if (gpio_get_value(host->board->det_pin)) {
> +	if (gpio_is_valid(host->board.det_pin)) {
> +		if (gpio_get_value(host->board.det_pin)) {
>  			printk(KERN_INFO "No SmartMedia card inserted.\n");
>  			res = -ENXIO;
>  			goto err_no_card;
>  		}
>  	}
>  
> -	if (host->board->on_flash_bbt || on_flash_bbt) {
> +	if (host->board.on_flash_bbt || on_flash_bbt) {
>  		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
>  		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
>  	}
> @@ -637,8 +691,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	}
>  
>  	mtd->name = "atmel_nand";
> -	res = mtd_device_parse_register(mtd, NULL, 0,
> -			host->board->parts, host->board->num_parts);
> +	ppdata.of_node = pdev->dev.of_node;
> +	res = mtd_device_parse_register(mtd, NULL, &ppdata,
> +			host->board.parts, host->board.num_parts);
>  	if (!res)
>  		return res;
>  
> @@ -682,11 +737,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> +	{ .compatible = "atmel,at91rm9200-nand" },
> +	{ /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
>  static struct platform_driver atmel_nand_driver = {
>  	.remove		= __exit_p(atmel_nand_remove),
>  	.driver		= {
>  		.name	= "atmel_nand",
>  		.owner	= THIS_MODULE,
> +		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
>  	},
>  };
>  
> -- 
> 1.7.7

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

* [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-20 17:17       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-20 17:17 UTC (permalink / raw)
  To: linux-arm-kernel

On 11:35 Mon 06 Feb     , Jean-Christophe PLAGNIOL-VILLARD wrote:
> use a local copy of board informatin and fill with DT data
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss at lists.ozlabs.org
> Cc: linux-mtd at lists.infradead.org
> ---
> V2:
> 	comment from Grant
> 	rebase over rc3
HI David,

	I've depeancy on other at91 patch can I apply this series via at91
	tree?

Best Regards,
J.
> 
> Best Regards,
> J.
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 ++++++++
>  drivers/mtd/nand/atmel_nand.c                      |  105 ++++++++++++++++----
>  2 files changed, 126 insertions(+), 20 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> new file mode 100644
> index 0000000..a910ab9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
> @@ -0,0 +1,41 @@
> +Atmel NAND flash
> +
> +Required properties:
> +- compatible : "atmel,at91rm9200-nand".
> +- reg : should specify localbus address and size used for the chip,
> +	and if availlable the ECC.
> +- atmel,nand-addr-offset : offset for the address latch.
> +- atmel,nand-cmd-offset : offset for the command latch.
> +- #address-cells, #size-cells : Must be present if the device has sub-nodes
> +  representing partitions.
> +
> +- gpios : specifies the gpio pins to control the NAND device. detect is an
> +  optional gpio and may be set to 0 if not present.
> +
> +Optional properties:
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".
> +- nand-bus-width : 8 or 16 bus width if not present 8
> +- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
> +
> +Examples:
> +nand0: nand at 40000000,0 {
> +	compatible = "atmel,at91rm9200-nand";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +	reg = <0x40000000 0x10000000
> +	       0xffffe800 0x200
> +	      >;
> +	atmel,nand-addr-offset = <21>;
> +	atmel,nand-cmd-offset = <22>;
> +	nand-on-flash-bbt = <1>;
> +	nand-ecc-mode = "soft";
> +	gpios = <&pioC 13 0
> +		 &pioC 14 0
> +		 0
> +		>;
> +	partition at 0 {
> +		...
> +	};
> +};
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 045d174..7f91ed2 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -27,6 +27,10 @@
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_mtd.h>
>  #include <linux/mtd/mtd.h>
>  #include <linux/mtd/nand.h>
>  #include <linux/mtd/partitions.h>
> @@ -83,7 +87,7 @@ struct atmel_nand_host {
>  	struct mtd_info		mtd;
>  	void __iomem		*io_base;
>  	dma_addr_t		io_phys;
> -	struct atmel_nand_data	*board;
> +	struct atmel_nand_data	board;
>  	struct device		*dev;
>  	void __iomem		*ecc;
>  
> @@ -101,8 +105,8 @@ static int cpu_has_dma(void)
>   */
>  static void atmel_nand_enable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 0);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 0);
>  }
>  
>  /*
> @@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
>   */
>  static void atmel_nand_disable(struct atmel_nand_host *host)
>  {
> -	if (gpio_is_valid(host->board->enable_pin))
> -		gpio_set_value(host->board->enable_pin, 1);
> +	if (gpio_is_valid(host->board.enable_pin))
> +		gpio_set_value(host->board.enable_pin, 1);
>  }
>  
>  /*
> @@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
>  		return;
>  
>  	if (ctrl & NAND_CLE)
> -		writeb(cmd, host->io_base + (1 << host->board->cle));
> +		writeb(cmd, host->io_base + (1 << host->board.cle));
>  	else
> -		writeb(cmd, host->io_base + (1 << host->board->ale));
> +		writeb(cmd, host->io_base + (1 << host->board.ale));
>  }
>  
>  /*
> @@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
>  	struct nand_chip *nand_chip = mtd->priv;
>  	struct atmel_nand_host *host = nand_chip->priv;
>  
> -	return gpio_get_value(host->board->rdy_pin) ^
> -                !!host->board->rdy_pin_active_low;
> +	return gpio_get_value(host->board.rdy_pin) ^
> +                !!host->board.rdy_pin_active_low;
>  }
>  
>  /*
> @@ -261,7 +265,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
>  		if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
>  			return;
>  
> -	if (host->board->bus_width_16)
> +	if (host->board.bus_width_16)
>  		atmel_read_buf16(mtd, buf, len);
>  	else
>  		atmel_read_buf8(mtd, buf, len);
> @@ -277,7 +281,7 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
>  		if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
>  			return;
>  
> -	if (host->board->bus_width_16)
> +	if (host->board.bus_width_16)
>  		atmel_write_buf16(mtd, buf, len);
>  	else
>  		atmel_write_buf8(mtd, buf, len);
> @@ -469,6 +473,48 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
>  	}
>  }
>  
> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> +					 struct device_node *np)
> +{
> +	u32 val;
> +	int ecc_mode;
> +	struct atmel_nand_data *board = &host->board;
> +	enum of_gpio_flags flags;
> +
> +	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid addr-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->ale = val;
> +	}
> +
> +	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
> +		if (val >= 32) {
> +			dev_err(host->dev, "invalid cmd-offset %u\n", val);
> +			return -EINVAL;
> +		}
> +		board->cle = val;
> +	}
> +
> +	ecc_mode = of_get_nand_ecc_mode(np);
> +
> +	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
> +
> +	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
> +
> +	if (of_get_nand_bus_width(np) == 16)
> +		board->bus_width_16 = 1;
> +
> +	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
> +	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
> +
> +	board->enable_pin = of_get_gpio(np, 1);
> +	board->det_pin = of_get_gpio(np, 2);
> +
> +	return 0;
> +}
> +
>  /*
>   * Probe for the NAND device.
>   */
> @@ -479,6 +525,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	struct nand_chip *nand_chip;
>  	struct resource *regs;
>  	struct resource *mem;
> +	struct mtd_part_parser_data ppdata = {};
>  	int res;
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -505,8 +552,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	mtd = &host->mtd;
>  	nand_chip = &host->nand_chip;
> -	host->board = pdev->dev.platform_data;
>  	host->dev = &pdev->dev;
> +	if (pdev->dev.of_node) {
> +		res = atmel_of_init_port(host, pdev->dev.of_node);
> +		if (res)
> +			goto err_nand_ioremap;
> +	} else {
> +		memcpy(&host->board, pdev->dev.platform_data,
> +		       sizeof(struct atmel_nand_data));
> +	}
>  
>  	nand_chip->priv = host;		/* link the private data structures */
>  	mtd->priv = nand_chip;
> @@ -517,10 +571,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	nand_chip->IO_ADDR_W = host->io_base;
>  	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
>  
> -	if (gpio_is_valid(host->board->rdy_pin))
> +	if (gpio_is_valid(host->board.rdy_pin))
>  		nand_chip->dev_ready = atmel_nand_device_ready;
>  
> -	nand_chip->ecc.mode = host->board->ecc_mode;
> +	nand_chip->ecc.mode = host->board.ecc_mode;
>  
>  	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>  	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
> @@ -545,7 +599,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  
>  	nand_chip->chip_delay = 20;		/* 20us command delay time */
>  
> -	if (host->board->bus_width_16)	/* 16-bit bus width */
> +	if (host->board.bus_width_16)	/* 16-bit bus width */
>  		nand_chip->options |= NAND_BUSWIDTH_16;
>  
>  	nand_chip->read_buf = atmel_read_buf;
> @@ -554,15 +608,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, host);
>  	atmel_nand_enable(host);
>  
> -	if (gpio_is_valid(host->board->det_pin)) {
> -		if (gpio_get_value(host->board->det_pin)) {
> +	if (gpio_is_valid(host->board.det_pin)) {
> +		if (gpio_get_value(host->board.det_pin)) {
>  			printk(KERN_INFO "No SmartMedia card inserted.\n");
>  			res = -ENXIO;
>  			goto err_no_card;
>  		}
>  	}
>  
> -	if (host->board->on_flash_bbt || on_flash_bbt) {
> +	if (host->board.on_flash_bbt || on_flash_bbt) {
>  		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
>  		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
>  	}
> @@ -637,8 +691,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
>  	}
>  
>  	mtd->name = "atmel_nand";
> -	res = mtd_device_parse_register(mtd, NULL, 0,
> -			host->board->parts, host->board->num_parts);
> +	ppdata.of_node = pdev->dev.of_node;
> +	res = mtd_device_parse_register(mtd, NULL, &ppdata,
> +			host->board.parts, host->board.num_parts);
>  	if (!res)
>  		return res;
>  
> @@ -682,11 +737,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_nand_dt_ids[] = {
> +	{ .compatible = "atmel,at91rm9200-nand" },
> +	{ /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
> +#endif
> +
>  static struct platform_driver atmel_nand_driver = {
>  	.remove		= __exit_p(atmel_nand_remove),
>  	.driver		= {
>  		.name	= "atmel_nand",
>  		.owner	= THIS_MODULE,
> +		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
>  	},
>  };
>  
> -- 
> 1.7.7

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
  2012-02-20 17:17       ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
@ 2012-02-20 21:37           ` David Woodhouse
  -1 siblings, 0 replies; 64+ messages in thread
From: David Woodhouse @ 2012-02-20 21:37 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r


[-- Attachment #1.1: Type: text/plain, Size: 196 bytes --]

On Mon, 2012-02-20 at 18:17 +0100, Jean-Christophe PLAGNIOL-VILLARD 
> HI David,
> I've depeancy on other at91 patch can I apply this series via at91
> tree? 

Yes, please do.

-- 
dwmw2

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5818 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-20 21:37           ` David Woodhouse
  0 siblings, 0 replies; 64+ messages in thread
From: David Woodhouse @ 2012-02-20 21:37 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: linux-mtd, devicetree-discuss, Nicolas Ferre, linux-arm-kernel

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

On Mon, 2012-02-20 at 18:17 +0100, Jean-Christophe PLAGNIOL-VILLARD 
> HI David,
> I've depeancy on other at91 patch can I apply this series via at91
> tree? 

Yes, please do.

-- 
dwmw2

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5818 bytes --]

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

* [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-20 21:37           ` David Woodhouse
  0 siblings, 0 replies; 64+ messages in thread
From: David Woodhouse @ 2012-02-20 21:37 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 2012-02-20 at 18:17 +0100, Jean-Christophe PLAGNIOL-VILLARD 
> HI David,
> I've depeancy on other at91 patch can I apply this series via at91
> tree? 

Yes, please do.

-- 
dwmw2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120220/c1e046f9/attachment.bin>

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
  2012-02-07 11:53         ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
@ 2012-02-21  9:22             ` Nicolas Ferre
  -1 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-21  9:22 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 02/07/2012 12:53 PM, Jean-Christophe PLAGNIOL-VILLARD :
> On 11:30 Tue 07 Feb     , Nicolas Ferre wrote:
>> On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
>>> use a local copy of board informatin and fill with DT data
>>>
>>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
>>> Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
>>> Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
>>> Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
>>> Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
>>
>> [..]
>>
>>> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
>>> +					 struct device_node *np)
>>
>> Maybe you will need to protect this function in case of !DT builds: I
>> suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.
> no-need on the of_ function are static inline it !CONFIG_OF

Sorry to come back to this but:

of_get_nand_ecc_mode(np);
of_get_nand_on_flash_bbt(np);

for example are not available in case of non-DT compilation: so we must
protect the atmel_of_init_port() against this error.

Can you please rework another patch.

Bye,
-- 
Nicolas Ferre

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-21  9:22             ` Nicolas Ferre
  0 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-21  9:22 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 02/07/2012 12:53 PM, Jean-Christophe PLAGNIOL-VILLARD :
> On 11:30 Tue 07 Feb     , Nicolas Ferre wrote:
>> On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
>>> use a local copy of board informatin and fill with DT data
>>>
>>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
>>> Acked-by: Grant Likely <grant.likely@secretlab.ca>
>>> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
>>> Cc: devicetree-discuss@lists.ozlabs.org
>>> Cc: linux-mtd@lists.infradead.org
>>
>> [..]
>>
>>> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
>>> +					 struct device_node *np)
>>
>> Maybe you will need to protect this function in case of !DT builds: I
>> suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.
> no-need on the of_ function are static inline it !CONFIG_OF

Sorry to come back to this but:

of_get_nand_ecc_mode(np);
of_get_nand_on_flash_bbt(np);

for example are not available in case of non-DT compilation: so we must
protect the atmel_of_init_port() against this error.

Can you please rework another patch.

Bye,
-- 
Nicolas Ferre

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

* [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-21  9:22             ` Nicolas Ferre
  0 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-21  9:22 UTC (permalink / raw)
  To: linux-arm-kernel

On 02/07/2012 12:53 PM, Jean-Christophe PLAGNIOL-VILLARD :
> On 11:30 Tue 07 Feb     , Nicolas Ferre wrote:
>> On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
>>> use a local copy of board informatin and fill with DT data
>>>
>>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
>>> Acked-by: Grant Likely <grant.likely@secretlab.ca>
>>> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
>>> Cc: devicetree-discuss at lists.ozlabs.org
>>> Cc: linux-mtd at lists.infradead.org
>>
>> [..]
>>
>>> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
>>> +					 struct device_node *np)
>>
>> Maybe you will need to protect this function in case of !DT builds: I
>> suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.
> no-need on the of_ function are static inline it !CONFIG_OF

Sorry to come back to this but:

of_get_nand_ecc_mode(np);
of_get_nand_on_flash_bbt(np);

for example are not available in case of non-DT compilation: so we must
protect the atmel_of_init_port() against this error.

Can you please rework another patch.

Bye,
-- 
Nicolas Ferre

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

* Re: [PATCH 5/6 V2] atmel/nand: add DT support
  2012-02-21  9:22             ` Nicolas Ferre
@ 2012-02-21  9:32               ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-21  9:32 UTC (permalink / raw)
  To: Nicolas Ferre; +Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 10:22 Tue 21 Feb     , Nicolas Ferre wrote:
> On 02/07/2012 12:53 PM, Jean-Christophe PLAGNIOL-VILLARD :
> > On 11:30 Tue 07 Feb     , Nicolas Ferre wrote:
> >> On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
> >>> use a local copy of board informatin and fill with DT data
> >>>
> >>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> >>> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> >>> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> >>> Cc: devicetree-discuss@lists.ozlabs.org
> >>> Cc: linux-mtd@lists.infradead.org
> >>
> >> [..]
> >>
> >>> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> >>> +					 struct device_node *np)
> >>
> >> Maybe you will need to protect this function in case of !DT builds: I
> >> suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.
> > no-need on the of_ function are static inline it !CONFIG_OF
> 
> Sorry to come back to this but:
> 
> of_get_nand_ecc_mode(np);
> of_get_nand_on_flash_bbt(np);
> 
> for example are not available in case of non-DT compilation: so we must
> protect the atmel_of_init_port() against this error.
> 
> Can you please rework another patch.
yes seen too update send

Best Regards,
J.

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

* [PATCH 5/6 V2] atmel/nand: add DT support
@ 2012-02-21  9:32               ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-21  9:32 UTC (permalink / raw)
  To: linux-arm-kernel

On 10:22 Tue 21 Feb     , Nicolas Ferre wrote:
> On 02/07/2012 12:53 PM, Jean-Christophe PLAGNIOL-VILLARD :
> > On 11:30 Tue 07 Feb     , Nicolas Ferre wrote:
> >> On 02/06/2012 11:35 AM, Jean-Christophe PLAGNIOL-VILLARD :
> >>> use a local copy of board informatin and fill with DT data
> >>>
> >>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> >>> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> >>> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> >>> Cc: devicetree-discuss at lists.ozlabs.org
> >>> Cc: linux-mtd at lists.infradead.org
> >>
> >> [..]
> >>
> >>> +static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
> >>> +					 struct device_node *np)
> >>
> >> Maybe you will need to protect this function in case of !DT builds: I
> >> suspect that some of the of_xxxxx() calls are not provided if !CONFIG_OF.
> > no-need on the of_ function are static inline it !CONFIG_OF
> 
> Sorry to come back to this but:
> 
> of_get_nand_ecc_mode(np);
> of_get_nand_on_flash_bbt(np);
> 
> for example are not available in case of non-DT compilation: so we must
> protect the atmel_of_init_port() against this error.
> 
> Can you please rework another patch.
yes seen too update send

Best Regards,
J.

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

* [PATCH 5/6 V3] atmel/nand: add DT support
  2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-02-21  9:46     ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-21  9:46 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Nicolas Ferre, devicetree-discuss,
	Jean-Christophe PLAGNIOL-VILLARD, linux-mtd

Use a local copy of board informatin and fill with DT data.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss@lists.ozlabs.org
Cc: linux-mtd@lists.infradead.org
---
v3:

	protect against !CONFIG_OF

Best Regards,
J.
 .../devicetree/bindings/mtd/atmel-nand.txt         |   41 +++++++
 arch/arm/boot/dts/at91sam9g20.dtsi                 |   17 +++
 arch/arm/boot/dts/at91sam9g45.dtsi                 |   17 +++
 arch/arm/boot/dts/at91sam9m10g45ek.dts             |   26 +++++-
 arch/arm/boot/dts/usb_a9g20.dts                    |   46 ++++++++-
 arch/arm/mach-at91/at91sam9x5.c                    |    5 -
 arch/arm/mach-at91/board-dt.c                      |   52 ---------
 drivers/mtd/nand/atmel_nand.c                      |  113 ++++++++++++++++----
 8 files changed, 238 insertions(+), 79 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
new file mode 100644
index 0000000..a910ab9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
@@ -0,0 +1,41 @@
+Atmel NAND flash
+
+Required properties:
+- compatible : "atmel,at91rm9200-nand".
+- reg : should specify localbus address and size used for the chip,
+	and if availlable the ECC.
+- atmel,nand-addr-offset : offset for the address latch.
+- atmel,nand-cmd-offset : offset for the command latch.
+- #address-cells, #size-cells : Must be present if the device has sub-nodes
+  representing partitions.
+
+- gpios : specifies the gpio pins to control the NAND device. detect is an
+  optional gpio and may be set to 0 if not present.
+
+Optional properties:
+- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
+
+Examples:
+nand0: nand@40000000,0 {
+	compatible = "atmel,at91rm9200-nand";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x40000000 0x10000000
+	       0xffffe800 0x200
+	      >;
+	atmel,nand-addr-offset = <21>;
+	atmel,nand-cmd-offset = <22>;
+	nand-on-flash-bbt = <1>;
+	nand-ecc-mode = "soft";
+	gpios = <&pioC 13 0
+		 &pioC 14 0
+		 0
+		>;
+	partition@0 {
+		...
+	};
+};
diff --git a/arch/arm/boot/dts/at91sam9g20.dtsi b/arch/arm/boot/dts/at91sam9g20.dtsi
index 325989a..35abcd4 100644
--- a/arch/arm/boot/dts/at91sam9g20.dtsi
+++ b/arch/arm/boot/dts/at91sam9g20.dtsi
@@ -151,6 +151,23 @@
 				interrupts = <21 4>;
 				status = "disabled";
 			};
+
+			nand0: nand@40000000 {
+				compatible = "atmel,at91rm9200-nand";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				reg = <0x40000000 0x10000000
+				       0xffffe800 0x200
+				      >;
+				atmel,nand-addr-offset = <21>;
+				atmel,nand-cmd-offset = <22>;
+				gpios = <&pioC 13 0
+					 &pioC 14 0
+					 0
+					>;
+				status = "disabled";
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi b/arch/arm/boot/dts/at91sam9g45.dtsi
index a9dbbb5..6a72424 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -158,6 +158,23 @@
 				interrupts = <25 4>;
 				status = "disabled";
 			};
+
+			nand0: nand@40000000 {
+				compatible = "atmel,at91rm9200-nand";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				reg = <0x40000000 0x10000000
+				       0xffffe200 0x200
+				      >;
+				atmel,nand-addr-offset = <21>;
+				atmel,nand-cmd-offset = <22>;
+				gpios = <&pioC 8 0
+					 &pioC 14 0
+					 0
+					>;
+				status = "disabled";
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/boot/dts/at91sam9m10g45ek.dts b/arch/arm/boot/dts/at91sam9m10g45ek.dts
index a387e77..03a15c0 100644
--- a/arch/arm/boot/dts/at91sam9m10g45ek.dts
+++ b/arch/arm/boot/dts/at91sam9m10g45ek.dts
@@ -14,7 +14,7 @@
 	compatible = "atmel,at91sam9m10g45ek", "atmel,at91sam9g45", "atmel,at91sam9";
 
 	chosen {
-		bootargs = "mem=64M console=ttyS0,115200 mtdparts=atmel_nand:4M(bootstrap/uboot/kernel)ro,60M(rootfs),-(data) root=/dev/mtdblock1 rw rootfstype=jffs2";
+		bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2";
 	};
 
 	memory@70000000 {
@@ -35,6 +35,30 @@
 				phy-mode = "rmii";
 				status = "okay";
 			};
+
+			nand0: nand@40000000 {
+				nand-bus-width = <8>;
+				nand-ecc-mode = "soft";
+				nand-on-flash-bbt = <1>;
+				status = "okay";
+
+				boot@0 {
+					label = "bootstrap/uboot/kernel";
+					reg = <0x0 0x400000>;
+				};
+
+				rootfs@400000 {
+					label = "rootfs";
+					reg = <0x400000 0x3C00000>;
+				};
+
+				data@4000000 {
+					label = "data";
+					reg = <0x4000000 0xC000000>;
+				};
+
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/boot/dts/usb_a9g20.dts b/arch/arm/boot/dts/usb_a9g20.dts
index f04b535..feafede 100644
--- a/arch/arm/boot/dts/usb_a9g20.dts
+++ b/arch/arm/boot/dts/usb_a9g20.dts
@@ -13,7 +13,7 @@
 	compatible = "calao,usb-a9g20", "atmel,at91sam9g20", "atmel,at91sam9";
 
 	chosen {
-		bootargs = "mem=64M console=ttyS0,115200 mtdparts=atmel_nand:128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),4M(kernel),120M(rootfs),-(data) root=/dev/mtdblock5 rw rootfstype=ubifs";
+		bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock5 rw rootfstype=ubifs";
 	};
 
 	memory@20000000 {
@@ -30,6 +30,50 @@
 				phy-mode = "rmii";
 				status = "okay";
 			};
+
+			nand0: nand@40000000 {
+				nand-bus-width = <8>;
+				nand-ecc-mode = "soft";
+				nand-on-flash-bbt = <1>;
+				status = "okay";
+
+				at91bootstrap@0 {
+					label = "at91bootstrap";
+					reg = <0x0 0x20000>;
+				};
+
+				barebox@20000 {
+					label = "barebox";
+					reg = <0x20000 0x40000>;
+				};
+
+				bareboxenv@60000 {
+					label = "bareboxenv";
+					reg = <0x60000 0x20000>;
+				};
+
+				bareboxenv2@80000 {
+					label = "bareboxenv2";
+					reg = <0x80000 0x20000>;
+				};
+
+				kernel@a0000 {
+					label = "kernel";
+					reg = <0xa0000 0x400000>;
+				};
+
+				rootfs@4a0000 {
+					label = "rootfs";
+					reg = <0x4a0000 0x7800000>;
+				};
+
+				data@7ca0000 {
+					label = "data";
+					reg = <0x7ca0000 0x8360000>;
+				};
+
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/mach-at91/at91sam9x5.c b/arch/arm/mach-at91/at91sam9x5.c
index d17d426..19f28a5 100644
--- a/arch/arm/mach-at91/at91sam9x5.c
+++ b/arch/arm/mach-at91/at91sam9x5.c
@@ -316,11 +316,6 @@ void __init at91sam9x5_initialize(void)
 }
 
 /* --------------------------------------------------------------------
- *  AT91SAM9x5 devices (temporary before modification of code)
- * -------------------------------------------------------------------- */
-void __init at91_add_device_nand(struct atmel_nand_data *data) {}
-
-/* --------------------------------------------------------------------
  *  Interrupt initialization
  * -------------------------------------------------------------------- */
 /*
diff --git a/arch/arm/mach-at91/board-dt.c b/arch/arm/mach-at91/board-dt.c
index 285d9a4..ca25689 100644
--- a/arch/arm/mach-at91/board-dt.c
+++ b/arch/arm/mach-at91/board-dt.c
@@ -17,10 +17,7 @@
 #include <linux/gpio.h>
 #include <linux/of_platform.h>
 
-#include <mach/hardware.h>
 #include <mach/board.h>
-#include <mach/system_rev.h>
-#include <mach/at91sam9_smc.h>
 
 #include <asm/setup.h>
 #include <asm/irq.h>
@@ -28,54 +25,8 @@
 #include <asm/mach/map.h>
 #include <asm/mach/irq.h>
 
-#include "sam9_smc.h"
 #include "generic.h"
 
-
-/* det_pin is not connected */
-static struct atmel_nand_data __initdata ek_nand_data = {
-	.ale		= 21,
-	.cle		= 22,
-	.det_pin	= -EINVAL,
-	.rdy_pin	= AT91_PIN_PC8,
-	.enable_pin	= AT91_PIN_PC14,
-	.ecc_mode	= NAND_ECC_SOFT,
-	.on_flash_bbt	= 1,
-};
-
-static struct sam9_smc_config __initdata ek_nand_smc_config = {
-	.ncs_read_setup		= 0,
-	.nrd_setup		= 2,
-	.ncs_write_setup	= 0,
-	.nwe_setup		= 2,
-
-	.ncs_read_pulse		= 4,
-	.nrd_pulse		= 4,
-	.ncs_write_pulse	= 4,
-	.nwe_pulse		= 4,
-
-	.read_cycle		= 7,
-	.write_cycle		= 7,
-
-	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
-	.tdf_cycles		= 3,
-};
-
-static void __init ek_add_device_nand(void)
-{
-	ek_nand_data.bus_width_16 = board_have_nand_16bit();
-	/* setup bus-width (8 or 16) */
-	if (ek_nand_data.bus_width_16)
-		ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
-	else
-		ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
-
-	/* configure chip-select 3 (NAND) */
-	sam9_smc_configure(0, 3, &ek_nand_smc_config);
-
-	at91_add_device_nand(&ek_nand_data);
-}
-
 static void __init at91_dt_init_irq(void)
 {
 	/* Initialize processor: 12.000 MHz crystal */
@@ -87,9 +38,6 @@ static void __init at91_dt_init_irq(void)
 static void __init at91_dt_device_init(void)
 {
 	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
-
-	/* NAND */
-	ek_add_device_nand();
 }
 
 static const char *at91_dt_board_compat[] __initdata = {
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 045d174..ae7e37d 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -27,6 +27,10 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -83,7 +87,7 @@ struct atmel_nand_host {
 	struct mtd_info		mtd;
 	void __iomem		*io_base;
 	dma_addr_t		io_phys;
-	struct atmel_nand_data	*board;
+	struct atmel_nand_data	board;
 	struct device		*dev;
 	void __iomem		*ecc;
 
@@ -101,8 +105,8 @@ static int cpu_has_dma(void)
  */
 static void atmel_nand_enable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 0);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 0);
 }
 
 /*
@@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
  */
 static void atmel_nand_disable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 1);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 1);
 }
 
 /*
@@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
 		return;
 
 	if (ctrl & NAND_CLE)
-		writeb(cmd, host->io_base + (1 << host->board->cle));
+		writeb(cmd, host->io_base + (1 << host->board.cle));
 	else
-		writeb(cmd, host->io_base + (1 << host->board->ale));
+		writeb(cmd, host->io_base + (1 << host->board.ale));
 }
 
 /*
@@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
 	struct nand_chip *nand_chip = mtd->priv;
 	struct atmel_nand_host *host = nand_chip->priv;
 
-	return gpio_get_value(host->board->rdy_pin) ^
-                !!host->board->rdy_pin_active_low;
+	return gpio_get_value(host->board.rdy_pin) ^
+                !!host->board.rdy_pin_active_low;
 }
 
 /*
@@ -261,7 +265,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 		if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
 			return;
 
-	if (host->board->bus_width_16)
+	if (host->board.bus_width_16)
 		atmel_read_buf16(mtd, buf, len);
 	else
 		atmel_read_buf8(mtd, buf, len);
@@ -277,7 +281,7 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 		if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
 			return;
 
-	if (host->board->bus_width_16)
+	if (host->board.bus_width_16)
 		atmel_write_buf16(mtd, buf, len);
 	else
 		atmel_write_buf8(mtd, buf, len);
@@ -469,6 +473,56 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
 	}
 }
 
+#if defined(CONFIG_OF)
+static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
+					 struct device_node *np)
+{
+	u32 val;
+	int ecc_mode;
+	struct atmel_nand_data *board = &host->board;
+	enum of_gpio_flags flags;
+
+	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid addr-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->ale = val;
+	}
+
+	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid cmd-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->cle = val;
+	}
+
+	ecc_mode = of_get_nand_ecc_mode(np);
+
+	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
+
+	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
+
+	if (of_get_nand_bus_width(np) == 16)
+		board->bus_width_16 = 1;
+
+	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
+	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
+
+	board->enable_pin = of_get_gpio(np, 1);
+	board->det_pin = of_get_gpio(np, 2);
+
+	return 0;
+}
+#else
+static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
+					 struct device_node *np)
+{
+	return -EINVAL;
+}
+#endif
+
 /*
  * Probe for the NAND device.
  */
@@ -479,6 +533,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	struct nand_chip *nand_chip;
 	struct resource *regs;
 	struct resource *mem;
+	struct mtd_part_parser_data ppdata = {};
 	int res;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -505,8 +560,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	mtd = &host->mtd;
 	nand_chip = &host->nand_chip;
-	host->board = pdev->dev.platform_data;
 	host->dev = &pdev->dev;
+	if (pdev->dev.of_node) {
+		res = atmel_of_init_port(host, pdev->dev.of_node);
+		if (res)
+			goto err_nand_ioremap;
+	} else {
+		memcpy(&host->board, pdev->dev.platform_data,
+		       sizeof(struct atmel_nand_data));
+	}
 
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
@@ -517,10 +579,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	nand_chip->IO_ADDR_W = host->io_base;
 	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
 
-	if (gpio_is_valid(host->board->rdy_pin))
+	if (gpio_is_valid(host->board.rdy_pin))
 		nand_chip->dev_ready = atmel_nand_device_ready;
 
-	nand_chip->ecc.mode = host->board->ecc_mode;
+	nand_chip->ecc.mode = host->board.ecc_mode;
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
@@ -545,7 +607,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	nand_chip->chip_delay = 20;		/* 20us command delay time */
 
-	if (host->board->bus_width_16)	/* 16-bit bus width */
+	if (host->board.bus_width_16)	/* 16-bit bus width */
 		nand_chip->options |= NAND_BUSWIDTH_16;
 
 	nand_chip->read_buf = atmel_read_buf;
@@ -554,15 +616,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 	atmel_nand_enable(host);
 
-	if (gpio_is_valid(host->board->det_pin)) {
-		if (gpio_get_value(host->board->det_pin)) {
+	if (gpio_is_valid(host->board.det_pin)) {
+		if (gpio_get_value(host->board.det_pin)) {
 			printk(KERN_INFO "No SmartMedia card inserted.\n");
 			res = -ENXIO;
 			goto err_no_card;
 		}
 	}
 
-	if (host->board->on_flash_bbt || on_flash_bbt) {
+	if (host->board.on_flash_bbt || on_flash_bbt) {
 		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
 		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 	}
@@ -637,8 +699,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "atmel_nand";
-	res = mtd_device_parse_register(mtd, NULL, 0,
-			host->board->parts, host->board->num_parts);
+	ppdata.of_node = pdev->dev.of_node;
+	res = mtd_device_parse_register(mtd, NULL, &ppdata,
+			host->board.parts, host->board.num_parts);
 	if (!res)
 		return res;
 
@@ -682,11 +745,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id atmel_nand_dt_ids[] = {
+	{ .compatible = "atmel,at91rm9200-nand" },
+	{ /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
+#endif
+
 static struct platform_driver atmel_nand_driver = {
 	.remove		= __exit_p(atmel_nand_remove),
 	.driver		= {
 		.name	= "atmel_nand",
 		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
 	},
 };
 
-- 
1.7.7

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

* [PATCH 5/6 V3] atmel/nand: add DT support
@ 2012-02-21  9:46     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-21  9:46 UTC (permalink / raw)
  To: linux-arm-kernel

Use a local copy of board informatin and fill with DT data.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: devicetree-discuss at lists.ozlabs.org
Cc: linux-mtd at lists.infradead.org
---
v3:

	protect against !CONFIG_OF

Best Regards,
J.
 .../devicetree/bindings/mtd/atmel-nand.txt         |   41 +++++++
 arch/arm/boot/dts/at91sam9g20.dtsi                 |   17 +++
 arch/arm/boot/dts/at91sam9g45.dtsi                 |   17 +++
 arch/arm/boot/dts/at91sam9m10g45ek.dts             |   26 +++++-
 arch/arm/boot/dts/usb_a9g20.dts                    |   46 ++++++++-
 arch/arm/mach-at91/at91sam9x5.c                    |    5 -
 arch/arm/mach-at91/board-dt.c                      |   52 ---------
 drivers/mtd/nand/atmel_nand.c                      |  113 ++++++++++++++++----
 8 files changed, 238 insertions(+), 79 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
new file mode 100644
index 0000000..a910ab9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt
@@ -0,0 +1,41 @@
+Atmel NAND flash
+
+Required properties:
+- compatible : "atmel,at91rm9200-nand".
+- reg : should specify localbus address and size used for the chip,
+	and if availlable the ECC.
+- atmel,nand-addr-offset : offset for the address latch.
+- atmel,nand-cmd-offset : offset for the command latch.
+- #address-cells, #size-cells : Must be present if the device has sub-nodes
+  representing partitions.
+
+- gpios : specifies the gpio pins to control the NAND device. detect is an
+  optional gpio and may be set to 0 if not present.
+
+Optional properties:
+- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
+- nand-bus-width : 8 or 16 bus width if not present 8
+- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
+
+Examples:
+nand0: nand at 40000000,0 {
+	compatible = "atmel,at91rm9200-nand";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	reg = <0x40000000 0x10000000
+	       0xffffe800 0x200
+	      >;
+	atmel,nand-addr-offset = <21>;
+	atmel,nand-cmd-offset = <22>;
+	nand-on-flash-bbt = <1>;
+	nand-ecc-mode = "soft";
+	gpios = <&pioC 13 0
+		 &pioC 14 0
+		 0
+		>;
+	partition at 0 {
+		...
+	};
+};
diff --git a/arch/arm/boot/dts/at91sam9g20.dtsi b/arch/arm/boot/dts/at91sam9g20.dtsi
index 325989a..35abcd4 100644
--- a/arch/arm/boot/dts/at91sam9g20.dtsi
+++ b/arch/arm/boot/dts/at91sam9g20.dtsi
@@ -151,6 +151,23 @@
 				interrupts = <21 4>;
 				status = "disabled";
 			};
+
+			nand0: nand at 40000000 {
+				compatible = "atmel,at91rm9200-nand";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				reg = <0x40000000 0x10000000
+				       0xffffe800 0x200
+				      >;
+				atmel,nand-addr-offset = <21>;
+				atmel,nand-cmd-offset = <22>;
+				gpios = <&pioC 13 0
+					 &pioC 14 0
+					 0
+					>;
+				status = "disabled";
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi b/arch/arm/boot/dts/at91sam9g45.dtsi
index a9dbbb5..6a72424 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -158,6 +158,23 @@
 				interrupts = <25 4>;
 				status = "disabled";
 			};
+
+			nand0: nand at 40000000 {
+				compatible = "atmel,at91rm9200-nand";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				reg = <0x40000000 0x10000000
+				       0xffffe200 0x200
+				      >;
+				atmel,nand-addr-offset = <21>;
+				atmel,nand-cmd-offset = <22>;
+				gpios = <&pioC 8 0
+					 &pioC 14 0
+					 0
+					>;
+				status = "disabled";
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/boot/dts/at91sam9m10g45ek.dts b/arch/arm/boot/dts/at91sam9m10g45ek.dts
index a387e77..03a15c0 100644
--- a/arch/arm/boot/dts/at91sam9m10g45ek.dts
+++ b/arch/arm/boot/dts/at91sam9m10g45ek.dts
@@ -14,7 +14,7 @@
 	compatible = "atmel,at91sam9m10g45ek", "atmel,at91sam9g45", "atmel,at91sam9";
 
 	chosen {
-		bootargs = "mem=64M console=ttyS0,115200 mtdparts=atmel_nand:4M(bootstrap/uboot/kernel)ro,60M(rootfs),-(data) root=/dev/mtdblock1 rw rootfstype=jffs2";
+		bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2";
 	};
 
 	memory at 70000000 {
@@ -35,6 +35,30 @@
 				phy-mode = "rmii";
 				status = "okay";
 			};
+
+			nand0: nand at 40000000 {
+				nand-bus-width = <8>;
+				nand-ecc-mode = "soft";
+				nand-on-flash-bbt = <1>;
+				status = "okay";
+
+				boot at 0 {
+					label = "bootstrap/uboot/kernel";
+					reg = <0x0 0x400000>;
+				};
+
+				rootfs at 400000 {
+					label = "rootfs";
+					reg = <0x400000 0x3C00000>;
+				};
+
+				data at 4000000 {
+					label = "data";
+					reg = <0x4000000 0xC000000>;
+				};
+
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/boot/dts/usb_a9g20.dts b/arch/arm/boot/dts/usb_a9g20.dts
index f04b535..feafede 100644
--- a/arch/arm/boot/dts/usb_a9g20.dts
+++ b/arch/arm/boot/dts/usb_a9g20.dts
@@ -13,7 +13,7 @@
 	compatible = "calao,usb-a9g20", "atmel,at91sam9g20", "atmel,at91sam9";
 
 	chosen {
-		bootargs = "mem=64M console=ttyS0,115200 mtdparts=atmel_nand:128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),4M(kernel),120M(rootfs),-(data) root=/dev/mtdblock5 rw rootfstype=ubifs";
+		bootargs = "mem=64M console=ttyS0,115200 root=/dev/mtdblock5 rw rootfstype=ubifs";
 	};
 
 	memory at 20000000 {
@@ -30,6 +30,50 @@
 				phy-mode = "rmii";
 				status = "okay";
 			};
+
+			nand0: nand at 40000000 {
+				nand-bus-width = <8>;
+				nand-ecc-mode = "soft";
+				nand-on-flash-bbt = <1>;
+				status = "okay";
+
+				at91bootstrap at 0 {
+					label = "at91bootstrap";
+					reg = <0x0 0x20000>;
+				};
+
+				barebox at 20000 {
+					label = "barebox";
+					reg = <0x20000 0x40000>;
+				};
+
+				bareboxenv at 60000 {
+					label = "bareboxenv";
+					reg = <0x60000 0x20000>;
+				};
+
+				bareboxenv2 at 80000 {
+					label = "bareboxenv2";
+					reg = <0x80000 0x20000>;
+				};
+
+				kernel at a0000 {
+					label = "kernel";
+					reg = <0xa0000 0x400000>;
+				};
+
+				rootfs at 4a0000 {
+					label = "rootfs";
+					reg = <0x4a0000 0x7800000>;
+				};
+
+				data at 7ca0000 {
+					label = "data";
+					reg = <0x7ca0000 0x8360000>;
+				};
+
+			};
+
 		};
 	};
 };
diff --git a/arch/arm/mach-at91/at91sam9x5.c b/arch/arm/mach-at91/at91sam9x5.c
index d17d426..19f28a5 100644
--- a/arch/arm/mach-at91/at91sam9x5.c
+++ b/arch/arm/mach-at91/at91sam9x5.c
@@ -316,11 +316,6 @@ void __init at91sam9x5_initialize(void)
 }
 
 /* --------------------------------------------------------------------
- *  AT91SAM9x5 devices (temporary before modification of code)
- * -------------------------------------------------------------------- */
-void __init at91_add_device_nand(struct atmel_nand_data *data) {}
-
-/* --------------------------------------------------------------------
  *  Interrupt initialization
  * -------------------------------------------------------------------- */
 /*
diff --git a/arch/arm/mach-at91/board-dt.c b/arch/arm/mach-at91/board-dt.c
index 285d9a4..ca25689 100644
--- a/arch/arm/mach-at91/board-dt.c
+++ b/arch/arm/mach-at91/board-dt.c
@@ -17,10 +17,7 @@
 #include <linux/gpio.h>
 #include <linux/of_platform.h>
 
-#include <mach/hardware.h>
 #include <mach/board.h>
-#include <mach/system_rev.h>
-#include <mach/at91sam9_smc.h>
 
 #include <asm/setup.h>
 #include <asm/irq.h>
@@ -28,54 +25,8 @@
 #include <asm/mach/map.h>
 #include <asm/mach/irq.h>
 
-#include "sam9_smc.h"
 #include "generic.h"
 
-
-/* det_pin is not connected */
-static struct atmel_nand_data __initdata ek_nand_data = {
-	.ale		= 21,
-	.cle		= 22,
-	.det_pin	= -EINVAL,
-	.rdy_pin	= AT91_PIN_PC8,
-	.enable_pin	= AT91_PIN_PC14,
-	.ecc_mode	= NAND_ECC_SOFT,
-	.on_flash_bbt	= 1,
-};
-
-static struct sam9_smc_config __initdata ek_nand_smc_config = {
-	.ncs_read_setup		= 0,
-	.nrd_setup		= 2,
-	.ncs_write_setup	= 0,
-	.nwe_setup		= 2,
-
-	.ncs_read_pulse		= 4,
-	.nrd_pulse		= 4,
-	.ncs_write_pulse	= 4,
-	.nwe_pulse		= 4,
-
-	.read_cycle		= 7,
-	.write_cycle		= 7,
-
-	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
-	.tdf_cycles		= 3,
-};
-
-static void __init ek_add_device_nand(void)
-{
-	ek_nand_data.bus_width_16 = board_have_nand_16bit();
-	/* setup bus-width (8 or 16) */
-	if (ek_nand_data.bus_width_16)
-		ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
-	else
-		ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
-
-	/* configure chip-select 3 (NAND) */
-	sam9_smc_configure(0, 3, &ek_nand_smc_config);
-
-	at91_add_device_nand(&ek_nand_data);
-}
-
 static void __init at91_dt_init_irq(void)
 {
 	/* Initialize processor: 12.000 MHz crystal */
@@ -87,9 +38,6 @@ static void __init at91_dt_init_irq(void)
 static void __init at91_dt_device_init(void)
 {
 	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
-
-	/* NAND */
-	ek_add_device_nand();
 }
 
 static const char *at91_dt_board_compat[] __initdata = {
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 045d174..ae7e37d 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -27,6 +27,10 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -83,7 +87,7 @@ struct atmel_nand_host {
 	struct mtd_info		mtd;
 	void __iomem		*io_base;
 	dma_addr_t		io_phys;
-	struct atmel_nand_data	*board;
+	struct atmel_nand_data	board;
 	struct device		*dev;
 	void __iomem		*ecc;
 
@@ -101,8 +105,8 @@ static int cpu_has_dma(void)
  */
 static void atmel_nand_enable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 0);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 0);
 }
 
 /*
@@ -110,8 +114,8 @@ static void atmel_nand_enable(struct atmel_nand_host *host)
  */
 static void atmel_nand_disable(struct atmel_nand_host *host)
 {
-	if (gpio_is_valid(host->board->enable_pin))
-		gpio_set_value(host->board->enable_pin, 1);
+	if (gpio_is_valid(host->board.enable_pin))
+		gpio_set_value(host->board.enable_pin, 1);
 }
 
 /*
@@ -132,9 +136,9 @@ static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl
 		return;
 
 	if (ctrl & NAND_CLE)
-		writeb(cmd, host->io_base + (1 << host->board->cle));
+		writeb(cmd, host->io_base + (1 << host->board.cle));
 	else
-		writeb(cmd, host->io_base + (1 << host->board->ale));
+		writeb(cmd, host->io_base + (1 << host->board.ale));
 }
 
 /*
@@ -145,8 +149,8 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
 	struct nand_chip *nand_chip = mtd->priv;
 	struct atmel_nand_host *host = nand_chip->priv;
 
-	return gpio_get_value(host->board->rdy_pin) ^
-                !!host->board->rdy_pin_active_low;
+	return gpio_get_value(host->board.rdy_pin) ^
+                !!host->board.rdy_pin_active_low;
 }
 
 /*
@@ -261,7 +265,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 		if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
 			return;
 
-	if (host->board->bus_width_16)
+	if (host->board.bus_width_16)
 		atmel_read_buf16(mtd, buf, len);
 	else
 		atmel_read_buf8(mtd, buf, len);
@@ -277,7 +281,7 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 		if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
 			return;
 
-	if (host->board->bus_width_16)
+	if (host->board.bus_width_16)
 		atmel_write_buf16(mtd, buf, len);
 	else
 		atmel_write_buf8(mtd, buf, len);
@@ -469,6 +473,56 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
 	}
 }
 
+#if defined(CONFIG_OF)
+static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
+					 struct device_node *np)
+{
+	u32 val;
+	int ecc_mode;
+	struct atmel_nand_data *board = &host->board;
+	enum of_gpio_flags flags;
+
+	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid addr-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->ale = val;
+	}
+
+	if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
+		if (val >= 32) {
+			dev_err(host->dev, "invalid cmd-offset %u\n", val);
+			return -EINVAL;
+		}
+		board->cle = val;
+	}
+
+	ecc_mode = of_get_nand_ecc_mode(np);
+
+	board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
+
+	board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
+
+	if (of_get_nand_bus_width(np) == 16)
+		board->bus_width_16 = 1;
+
+	board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
+	board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
+
+	board->enable_pin = of_get_gpio(np, 1);
+	board->det_pin = of_get_gpio(np, 2);
+
+	return 0;
+}
+#else
+static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
+					 struct device_node *np)
+{
+	return -EINVAL;
+}
+#endif
+
 /*
  * Probe for the NAND device.
  */
@@ -479,6 +533,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	struct nand_chip *nand_chip;
 	struct resource *regs;
 	struct resource *mem;
+	struct mtd_part_parser_data ppdata = {};
 	int res;
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -505,8 +560,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	mtd = &host->mtd;
 	nand_chip = &host->nand_chip;
-	host->board = pdev->dev.platform_data;
 	host->dev = &pdev->dev;
+	if (pdev->dev.of_node) {
+		res = atmel_of_init_port(host, pdev->dev.of_node);
+		if (res)
+			goto err_nand_ioremap;
+	} else {
+		memcpy(&host->board, pdev->dev.platform_data,
+		       sizeof(struct atmel_nand_data));
+	}
 
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
@@ -517,10 +579,10 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	nand_chip->IO_ADDR_W = host->io_base;
 	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
 
-	if (gpio_is_valid(host->board->rdy_pin))
+	if (gpio_is_valid(host->board.rdy_pin))
 		nand_chip->dev_ready = atmel_nand_device_ready;
 
-	nand_chip->ecc.mode = host->board->ecc_mode;
+	nand_chip->ecc.mode = host->board.ecc_mode;
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
@@ -545,7 +607,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 
 	nand_chip->chip_delay = 20;		/* 20us command delay time */
 
-	if (host->board->bus_width_16)	/* 16-bit bus width */
+	if (host->board.bus_width_16)	/* 16-bit bus width */
 		nand_chip->options |= NAND_BUSWIDTH_16;
 
 	nand_chip->read_buf = atmel_read_buf;
@@ -554,15 +616,15 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 	atmel_nand_enable(host);
 
-	if (gpio_is_valid(host->board->det_pin)) {
-		if (gpio_get_value(host->board->det_pin)) {
+	if (gpio_is_valid(host->board.det_pin)) {
+		if (gpio_get_value(host->board.det_pin)) {
 			printk(KERN_INFO "No SmartMedia card inserted.\n");
 			res = -ENXIO;
 			goto err_no_card;
 		}
 	}
 
-	if (host->board->on_flash_bbt || on_flash_bbt) {
+	if (host->board.on_flash_bbt || on_flash_bbt) {
 		printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
 		nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 	}
@@ -637,8 +699,9 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
 	}
 
 	mtd->name = "atmel_nand";
-	res = mtd_device_parse_register(mtd, NULL, 0,
-			host->board->parts, host->board->num_parts);
+	ppdata.of_node = pdev->dev.of_node;
+	res = mtd_device_parse_register(mtd, NULL, &ppdata,
+			host->board.parts, host->board.num_parts);
 	if (!res)
 		return res;
 
@@ -682,11 +745,21 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id atmel_nand_dt_ids[] = {
+	{ .compatible = "atmel,at91rm9200-nand" },
+	{ /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
+#endif
+
 static struct platform_driver atmel_nand_driver = {
 	.remove		= __exit_p(atmel_nand_remove),
 	.driver		= {
 		.name	= "atmel_nand",
 		.owner	= THIS_MODULE,
+		.of_match_table	= of_match_ptr(atmel_nand_dt_ids),
 	},
 };
 
-- 
1.7.7

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

* Re: [PATCH 5/6 V3] atmel/nand: add DT support
  2012-02-21  9:46     ` Jean-Christophe PLAGNIOL-VILLARD
  (?)
@ 2012-02-21  9:59         ` Nicolas Ferre
  -1 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-21  9:59 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 02/21/2012 10:46 AM, Jean-Christophe PLAGNIOL-VILLARD :
> Use a local copy of board informatin and fill with DT data.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> ---
> v3:
> 
> 	protect against !CONFIG_OF
> 
> Best Regards,
> J.
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 +++++++
>  arch/arm/boot/dts/at91sam9g20.dtsi                 |   17 +++
>  arch/arm/boot/dts/at91sam9g45.dtsi                 |   17 +++
>  arch/arm/boot/dts/at91sam9m10g45ek.dts             |   26 +++++-
>  arch/arm/boot/dts/usb_a9g20.dts                    |   46 ++++++++-
>  arch/arm/mach-at91/at91sam9x5.c                    |    5 -

As we will put this series on top of 9x5, we may also add the entries in
at91sam9x5.dtsi / at91sam9x5cm.dtsi ...

>  arch/arm/mach-at91/board-dt.c                      |   52 ---------
>  drivers/mtd/nand/atmel_nand.c                      |  113 ++++++++++++++++----
>  8 files changed, 238 insertions(+), 79 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

Otherwise,

Acked-by: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>

Bye,
-- 
Nicolas Ferre

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

* Re: [PATCH 5/6 V3] atmel/nand: add DT support
@ 2012-02-21  9:59         ` Nicolas Ferre
  0 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-21  9:59 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD
  Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 02/21/2012 10:46 AM, Jean-Christophe PLAGNIOL-VILLARD :
> Use a local copy of board informatin and fill with DT data.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss@lists.ozlabs.org
> Cc: linux-mtd@lists.infradead.org
> ---
> v3:
> 
> 	protect against !CONFIG_OF
> 
> Best Regards,
> J.
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 +++++++
>  arch/arm/boot/dts/at91sam9g20.dtsi                 |   17 +++
>  arch/arm/boot/dts/at91sam9g45.dtsi                 |   17 +++
>  arch/arm/boot/dts/at91sam9m10g45ek.dts             |   26 +++++-
>  arch/arm/boot/dts/usb_a9g20.dts                    |   46 ++++++++-
>  arch/arm/mach-at91/at91sam9x5.c                    |    5 -

As we will put this series on top of 9x5, we may also add the entries in
at91sam9x5.dtsi / at91sam9x5cm.dtsi ...

>  arch/arm/mach-at91/board-dt.c                      |   52 ---------
>  drivers/mtd/nand/atmel_nand.c                      |  113 ++++++++++++++++----
>  8 files changed, 238 insertions(+), 79 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

Otherwise,

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

Bye,
-- 
Nicolas Ferre

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

* [PATCH 5/6 V3] atmel/nand: add DT support
@ 2012-02-21  9:59         ` Nicolas Ferre
  0 siblings, 0 replies; 64+ messages in thread
From: Nicolas Ferre @ 2012-02-21  9:59 UTC (permalink / raw)
  To: linux-arm-kernel

On 02/21/2012 10:46 AM, Jean-Christophe PLAGNIOL-VILLARD :
> Use a local copy of board informatin and fill with DT data.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: devicetree-discuss at lists.ozlabs.org
> Cc: linux-mtd at lists.infradead.org
> ---
> v3:
> 
> 	protect against !CONFIG_OF
> 
> Best Regards,
> J.
>  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 +++++++
>  arch/arm/boot/dts/at91sam9g20.dtsi                 |   17 +++
>  arch/arm/boot/dts/at91sam9g45.dtsi                 |   17 +++
>  arch/arm/boot/dts/at91sam9m10g45ek.dts             |   26 +++++-
>  arch/arm/boot/dts/usb_a9g20.dts                    |   46 ++++++++-
>  arch/arm/mach-at91/at91sam9x5.c                    |    5 -

As we will put this series on top of 9x5, we may also add the entries in
at91sam9x5.dtsi / at91sam9x5cm.dtsi ...

>  arch/arm/mach-at91/board-dt.c                      |   52 ---------
>  drivers/mtd/nand/atmel_nand.c                      |  113 ++++++++++++++++----
>  8 files changed, 238 insertions(+), 79 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt

Otherwise,

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

Bye,
-- 
Nicolas Ferre

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

* Re: [PATCH 5/6 V3] atmel/nand: add DT support
  2012-02-21  9:59         ` Nicolas Ferre
  (?)
@ 2012-02-21 11:00             ` Jean-Christophe PLAGNIOL-VILLARD
  -1 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-21 11:00 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On 10:59 Tue 21 Feb     , Nicolas Ferre wrote:
> On 02/21/2012 10:46 AM, Jean-Christophe PLAGNIOL-VILLARD :
> > Use a local copy of board informatin and fill with DT data.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> > Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> > Cc: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> > Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> > Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> > ---
> > v3:
> > 
> > 	protect against !CONFIG_OF
> > 
> > Best Regards,
> > J.
> >  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 +++++++
> >  arch/arm/boot/dts/at91sam9g20.dtsi                 |   17 +++
> >  arch/arm/boot/dts/at91sam9g45.dtsi                 |   17 +++
> >  arch/arm/boot/dts/at91sam9m10g45ek.dts             |   26 +++++-
> >  arch/arm/boot/dts/usb_a9g20.dts                    |   46 ++++++++-
> >  arch/arm/mach-at91/at91sam9x5.c                    |    5 -
> 
> As we will put this series on top of 9x5, we may also add the entries in
> at91sam9x5.dtsi / at91sam9x5cm.dtsi ...
will add the sam9x5 support on an other patch

Best Regards,
J.
> 
> >  arch/arm/mach-at91/board-dt.c                      |   52 ---------
> >  drivers/mtd/nand/atmel_nand.c                      |  113 ++++++++++++++++----
> >  8 files changed, 238 insertions(+), 79 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> Otherwise,
> 
> Acked-by: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
> 
> Bye,
> -- 
> Nicolas Ferre
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 5/6 V3] atmel/nand: add DT support
@ 2012-02-21 11:00             ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-21 11:00 UTC (permalink / raw)
  To: Nicolas Ferre; +Cc: devicetree-discuss, linux-mtd, linux-arm-kernel

On 10:59 Tue 21 Feb     , Nicolas Ferre wrote:
> On 02/21/2012 10:46 AM, Jean-Christophe PLAGNIOL-VILLARD :
> > Use a local copy of board informatin and fill with DT data.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > Acked-by: Grant Likely <grant.likely@secretlab.ca>
> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> > Cc: devicetree-discuss@lists.ozlabs.org
> > Cc: linux-mtd@lists.infradead.org
> > ---
> > v3:
> > 
> > 	protect against !CONFIG_OF
> > 
> > Best Regards,
> > J.
> >  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 +++++++
> >  arch/arm/boot/dts/at91sam9g20.dtsi                 |   17 +++
> >  arch/arm/boot/dts/at91sam9g45.dtsi                 |   17 +++
> >  arch/arm/boot/dts/at91sam9m10g45ek.dts             |   26 +++++-
> >  arch/arm/boot/dts/usb_a9g20.dts                    |   46 ++++++++-
> >  arch/arm/mach-at91/at91sam9x5.c                    |    5 -
> 
> As we will put this series on top of 9x5, we may also add the entries in
> at91sam9x5.dtsi / at91sam9x5cm.dtsi ...
will add the sam9x5 support on an other patch

Best Regards,
J.
> 
> >  arch/arm/mach-at91/board-dt.c                      |   52 ---------
> >  drivers/mtd/nand/atmel_nand.c                      |  113 ++++++++++++++++----
> >  8 files changed, 238 insertions(+), 79 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> Otherwise,
> 
> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> 
> Bye,
> -- 
> Nicolas Ferre
> 
> _______________________________________________
> 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] 64+ messages in thread

* [PATCH 5/6 V3] atmel/nand: add DT support
@ 2012-02-21 11:00             ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 64+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-21 11:00 UTC (permalink / raw)
  To: linux-arm-kernel

On 10:59 Tue 21 Feb     , Nicolas Ferre wrote:
> On 02/21/2012 10:46 AM, Jean-Christophe PLAGNIOL-VILLARD :
> > Use a local copy of board informatin and fill with DT data.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > Acked-by: Grant Likely <grant.likely@secretlab.ca>
> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> > Cc: devicetree-discuss at lists.ozlabs.org
> > Cc: linux-mtd at lists.infradead.org
> > ---
> > v3:
> > 
> > 	protect against !CONFIG_OF
> > 
> > Best Regards,
> > J.
> >  .../devicetree/bindings/mtd/atmel-nand.txt         |   41 +++++++
> >  arch/arm/boot/dts/at91sam9g20.dtsi                 |   17 +++
> >  arch/arm/boot/dts/at91sam9g45.dtsi                 |   17 +++
> >  arch/arm/boot/dts/at91sam9m10g45ek.dts             |   26 +++++-
> >  arch/arm/boot/dts/usb_a9g20.dts                    |   46 ++++++++-
> >  arch/arm/mach-at91/at91sam9x5.c                    |    5 -
> 
> As we will put this series on top of 9x5, we may also add the entries in
> at91sam9x5.dtsi / at91sam9x5cm.dtsi ...
will add the sam9x5 support on an other patch

Best Regards,
J.
> 
> >  arch/arm/mach-at91/board-dt.c                      |   52 ---------
> >  drivers/mtd/nand/atmel_nand.c                      |  113 ++++++++++++++++----
> >  8 files changed, 238 insertions(+), 79 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/mtd/atmel-nand.txt
> 
> Otherwise,
> 
> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> 
> Bye,
> -- 
> Nicolas Ferre
> 
> _______________________________________________
> 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] 64+ messages in thread

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

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-28  5:10 [FOR 3.3 PATCH 1/6] ATMEL: fix nand ecc support Jean-Christophe PLAGNIOL-VILLARD
2012-01-28  5:10 ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-28  5:10 ` [FOR 3.3 PATCH 2/6] mtd/atmel_nand: add on_flash_bbt to enable the use of On Flash BBT Jean-Christophe PLAGNIOL-VILLARD
2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-28  5:10 ` [FOR 3.3 PATCH 3/6] ARM: at91: enable on flash bbt for Atmel Reference and DT boards Jean-Christophe PLAGNIOL-VILLARD
2012-01-28  5:10 ` [FOR 3.4 PATCH 4/6] of/mtd/nand: add generic bindings and helpers Jean-Christophe PLAGNIOL-VILLARD
2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-28 20:05   ` Grant Likely
2012-01-28 20:05     ` Grant Likely
2012-01-28  5:10 ` [FOR 3.4 PATCH 5/6] atmel/nand: add DT support Jean-Christophe PLAGNIOL-VILLARD
2012-01-28  5:10   ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]   ` <1327727444-23908-5-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-01-28 20:08     ` Grant Likely
2012-01-28 20:08       ` Grant Likely
2012-01-28 20:08       ` Grant Likely
2012-01-29 18:31     ` Simon Glass
2012-01-29 18:31       ` Simon Glass
2012-01-29 18:31       ` Simon Glass
     [not found]       ` <CAPnjgZ0uTwFwaK2Dxdna7p6zrj9OZdV=CxT1eGsT+M5Aa+SJNA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-01-30  5:56         ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-30  5:56           ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-30  5:56           ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-28  5:10 ` [FOR 3.4 PATCH 6/6] ARM: at91: board-dt nand switch to DT Jean-Christophe PLAGNIOL-VILLARD
2012-02-06 10:35 ` [PATCH 4/6 V2] of/mtd/nand: add generic bindings and helpers Jean-Christophe PLAGNIOL-VILLARD
2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-06 16:20   ` Stefan Roese
2012-02-06 16:20     ` Stefan Roese
2012-02-07  4:16     ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-07  4:16       ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-07  4:16       ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]       ` <20120207041606.GD15647-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-07  9:45         ` Stefan Roese
2012-02-07  9:45           ` Stefan Roese
2012-02-07  9:45           ` Stefan Roese
     [not found]           ` <201202071045.30128.sr-ynQEQJNshbs@public.gmane.org>
2012-02-07 10:10             ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-07 10:10               ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-07 10:10               ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]   ` <1328524512-18159-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-02-07 16:18     ` [PATCH 4/6 v3] " Jean-Christophe PLAGNIOL-VILLARD
2012-02-07 16:18       ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]       ` <1328631510-11688-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-02-08  7:16         ` Stefan Roese
2012-02-08  7:16           ` Stefan Roese
2012-02-06 10:35 ` [PATCH 5/6 V2] atmel/nand: add DT support Jean-Christophe PLAGNIOL-VILLARD
2012-02-06 10:35   ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]   ` <1328524512-18159-2-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-02-07 10:30     ` Nicolas Ferre
2012-02-07 10:30       ` Nicolas Ferre
2012-02-07 10:30       ` Nicolas Ferre
2012-02-07 11:53       ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-07 11:53         ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]         ` <20120207115306.GF15647-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-21  9:22           ` Nicolas Ferre
2012-02-21  9:22             ` Nicolas Ferre
2012-02-21  9:22             ` Nicolas Ferre
2012-02-21  9:32             ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-21  9:32               ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-20 17:17     ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-20 17:17       ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-20 17:17       ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]       ` <20120220171731.GA9371-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 21:37         ` David Woodhouse
2012-02-20 21:37           ` David Woodhouse
2012-02-20 21:37           ` David Woodhouse
2012-02-21  9:46   ` [PATCH 5/6 V3] " Jean-Christophe PLAGNIOL-VILLARD
2012-02-21  9:46     ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]     ` <1329817573-6473-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-02-21  9:59       ` Nicolas Ferre
2012-02-21  9:59         ` Nicolas Ferre
2012-02-21  9:59         ` Nicolas Ferre
     [not found]         ` <4F436AF5.5030104-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
2012-02-21 11:00           ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-21 11:00             ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-21 11:00             ` Jean-Christophe PLAGNIOL-VILLARD

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.