Skip to contentSkip to conversation

Add device tree support of Atmel NAND driver

PATCH Superseded Raphaël Poggi 3 participants 11 messages Aug 5, 2014 – Sep 1, 2014

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add device tree support of Atmel NAND driver

Change since v1:
* Reorder patchs
* Fix some clean style issue.

This patchset adds the device tree support for the Atmel NAND driver.

The first patch removes the NAND_ATMEL_PMECC config. With this removal
we can manage in a better way the device tree / non device tree probing of the driver, because the plateform data and device tree share the same structure member and logics.

The second patch adds the has_pmecc on boards which need it.

The third patch retrieves the ecc_mode from the plateform data and remove this code:

        nand_chip->ecc.mode = NAND_ECC_SOFT;

which arbitrary sets the ecc.mode to NAND_ECC_SOFT and changes the value depending of the config and plateform data. With this, we can use the same logics for device tree and non device tree probing of the driver.

The fourth patch adds the ecc_mode on boards which are missing it (boards which use NAND_ECC_SOFT).

The fifth patch adds the device tree in the atmel_nand driver.

Raphaël Poggi (5) :
(1) mtd: nand: remove NAND_ATMEL_PMECC
(2) board: atmel: initialise the has_pmecc member
(3) mtd: atmel_nand: retrieve ecc_mode from pdata
(4) board: atmel: initialise ecc_mode
(5) mtd: atmel_nand: add support for device tree

 arch/arm/boards/at91sam9260ek/init.c    |    1 +
 arch/arm/boards/at91sam9261ek/init.c    |    1 +
 arch/arm/boards/at91sam9263ek/init.c    |    1 +
 arch/arm/boards/at91sam9m10g45ek/init.c |    1 +
 arch/arm/boards/at91sam9m10ihd/init.c   |    1 +
 arch/arm/boards/at91sam9n12ek/init.c    |    1 +
 arch/arm/boards/at91sam9x5ek/init.c     |    1 +
 arch/arm/boards/sama5d3_xplained/init.c |    1 +
 arch/arm/boards/sama5d3xek/init.c       |    1 +
 arch/arm/mach-at91/include/mach/board.h |    1 +
 drivers/mtd/nand/Kconfig                |    8 ---
 drivers/mtd/nand/atmel_nand.c           |  115 ++++++++++++++++++++++++++++++-
 12 files changed, 122 insertions(+), 11 deletions(-)

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH v2 1/5 mtd: nand: remove NAND_ATMEL_PMECC

By removing this CONFIG_, we can use a structure member to retrieve the config, either through the plateform data or through the device tree. So we can handle cases when the driver is probed using device tree or not.

---
 arch/arm/mach-at91/include/mach/board.h |    1 +
 drivers/mtd/nand/Kconfig                |    8 --------
 drivers/mtd/nand/atmel_nand.c           |    2 +-
 3 files changed, 2 insertions(+), 9 deletions(-)
arch/arm/mach-at91/include/mach/board.h +1 -0
index aa0fdae..e2307ed 100644
@@ -63,6 +63,7 @@ struct atmel_nand_data {
 	u8		bus_width_16;	/* buswidth is 16 bit */
 	u8		ecc_mode;	/* NAND_ECC_* */
 	u8		on_flash_bbt;	/* Use flash based bbt */
+	u8		has_pmecc;	/* Use PMECC */
 	u8		bus_on_d0;
 
 	u8		pmecc_corr_cap;
drivers/mtd/nand/Kconfig +0 -8
index 04fe3c8..d49eae3 100644
@@ -95,14 +95,6 @@ config NAND_ATMEL
 	prompt "Atmel (AT91SAM9xxx) NAND driver"
 	depends on ARCH_AT91
 
-config NAND_ATMEL_PMECC
-	bool
-	prompt "PMECC support"
-	depends on NAND_ATMEL
-	select NAND_ECC_HW
-	help
-	  Support for PMECC present on the SoC sam9x5 and sam9n12
-
 config NAND_S3C24XX
 	bool
 	prompt "Samsung S3C24XX NAND driver"
drivers/mtd/nand/atmel_nand.c +1 -1
index 337e225..3ec6450 100644
@@ -1219,7 +1219,7 @@ static int __init atmel_nand_probe(struct device_d *dev)
 
 	if (IS_ENABLED(CONFIG_NAND_ECC_HW) &&
 	    nand_chip->ecc.mode == NAND_ECC_HW) {
-		if (IS_ENABLED(CONFIG_NAND_ATMEL_PMECC))
+		if (pdata->has_pmecc)
 			res = atmel_pmecc_nand_init_params(dev, host);
 		else
 			res = atmel_hw_nand_init_params(dev, host);
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Re: [PATCH 1/5] mtd: nand: remove NAND_ATMEL_PMECC

Quoted 3 lines · Rapha??l Poggi

By removing this CONFIG_, we can use a structure member to retrieve the config, either through the plateform data or through the device tree. So we can handle cases when the driver is probed using device tree or not.

NACK

this is use to reduce barebox size

keep the NAND_ATMEL_PMECC

so we choose to enable it or not

Best Regards,
J.

Quoted 60 lines
---
 arch/arm/mach-at91/include/mach/board.h |    1 +
 drivers/mtd/nand/Kconfig                |    8 --------
 drivers/mtd/nand/atmel_nand.c           |    2 +-
 3 files changed, 2 insertions(+), 9 deletions(-)
arch/arm/mach-at91/include/mach/board.h +1 -0
index aa0fdae..e2307ed 100644
@@ -63,6 +63,7 @@ struct atmel_nand_data {
 	u8		bus_width_16;	/* buswidth is 16 bit */
 	u8		ecc_mode;	/* NAND_ECC_* */
 	u8		on_flash_bbt;	/* Use flash based bbt */
+	u8		has_pmecc;	/* Use PMECC */
 	u8		bus_on_d0;
 
 	u8		pmecc_corr_cap;
drivers/mtd/nand/Kconfig +0 -8
index 04fe3c8..d49eae3 100644
@@ -95,14 +95,6 @@ config NAND_ATMEL
 	prompt "Atmel (AT91SAM9xxx) NAND driver"
 	depends on ARCH_AT91
 
-config NAND_ATMEL_PMECC
-	bool
-	prompt "PMECC support"
-	depends on NAND_ATMEL
-	select NAND_ECC_HW
-	help
-	  Support for PMECC present on the SoC sam9x5 and sam9n12
-
 config NAND_S3C24XX
 	bool
 	prompt "Samsung S3C24XX NAND driver"
drivers/mtd/nand/atmel_nand.c +1 -1
index 337e225..3ec6450 100644
@@ -1219,7 +1219,7 @@ static int __init atmel_nand_probe(struct device_d *dev)
 
 	if (IS_ENABLED(CONFIG_NAND_ECC_HW) &&
 	    nand_chip->ecc.mode == NAND_ECC_HW) {
-		if (IS_ENABLED(CONFIG_NAND_ATMEL_PMECC))
+		if (pdata->has_pmecc)
 			res = atmel_pmecc_nand_init_params(dev, host);
 		else
 			res = atmel_hw_nand_init_params(dev, host);
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw

Re: [PATCH 1/5] mtd: nand: remove NAND_ATMEL_PMECC

Ok, I did it because we need a structure member to retrieve "atmel,has-pmecc" from device tree.

Is this ok if I add the has_pmecc member (feed by atmel_nand_of_init), let the NAND_ATMEL_PMECC, and the if will be like :

if (IS_ENABLED(CONFIG_NAND_ATMEL_PMECC) || pdata->has_pmecc)

With this we can handle device tree/non device tree probing.

Or maybe you have a better idea.

Best regards,
Raphaël Poggi

2014-08-06 6:08 GMT+02:00 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>:

Quoted 70 lines · Rapha??l Poggi
Quoted 3 lines

By removing this CONFIG_, we can use a structure member to retrieve the config, either through the plateform data or through the device tree. So we can handle cases when the driver is probed using device tree or not.

NACK

this is use to reduce barebox size

keep the NAND_ATMEL_PMECC

so we choose to enable it or not

Best Regards,
J.

Quoted 56 lines
---
 arch/arm/mach-at91/include/mach/board.h |    1 +
 drivers/mtd/nand/Kconfig                |    8 --------
 drivers/mtd/nand/atmel_nand.c           |    2 +-
 3 files changed, 2 insertions(+), 9 deletions(-)
arch/arm/mach-at91/include/mach/board.h +1 -0
index aa0fdae..e2307ed 100644
@@ -63,6 +63,7 @@ struct atmel_nand_data {
      u8              bus_width_16;   /* buswidth is 16 bit */
      u8              ecc_mode;       /* NAND_ECC_* */
      u8              on_flash_bbt;   /* Use flash based bbt */
+     u8              has_pmecc;      /* Use PMECC */
      u8              bus_on_d0;
 
      u8              pmecc_corr_cap;
drivers/mtd/nand/Kconfig +0 -8
index 04fe3c8..d49eae3 100644
@@ -95,14 +95,6 @@ config NAND_ATMEL
      prompt "Atmel (AT91SAM9xxx) NAND driver"
      depends on ARCH_AT91
 
-config NAND_ATMEL_PMECC
-     bool
-     prompt "PMECC support"
-     depends on NAND_ATMEL
-     select NAND_ECC_HW
-     help
-       Support for PMECC present on the SoC sam9x5 and sam9n12
-
 config NAND_S3C24XX
      bool
      prompt "Samsung S3C24XX NAND driver"
drivers/mtd/nand/atmel_nand.c +1 -2
index 337e225..3ec6450 100644
@@ -1219,7 +1219,7 @@ static int __init atmel_nand_probe(struct device_d *dev)
 
      if (IS_ENABLED(CONFIG_NAND_ECC_HW) &&
          nand_chip->ecc.mode == NAND_ECC_HW) {
-             if (IS_ENABLED(CONFIG_NAND_ATMEL_PMECC))
+             if (pdata->has_pmecc)
                      res = atmel_pmecc_nand_init_params(dev, host);
              else
                      res = atmel_hw_nand_init_params(dev, host);
--

1.7.9.5

Quoted 9 lines
Quoted 4 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH 1/5] mtd: nand: remove NAND_ATMEL_PMECC

Quoted 7 lines · Raphaël Poggi

Ok, I did it because we need a structure member to retrieve "atmel,has-pmecc" from device tree.

Is this ok if I add the has_pmecc member (feed by atmel_nand_of_init), let the NAND_ATMEL_PMECC, and the if will be like :

if (IS_ENABLED(CONFIG_NAND_ATMEL_PMECC) || pdata->has_pmecc)

Shouldn't this be && instead of ||?

Otherwise this approach should be fine.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH v2 2/5 board: atmel: initialise the has_pmecc member

In reply to Raphaël Poggi
---
 arch/arm/boards/at91sam9n12ek/init.c    |    1 +
 arch/arm/boards/at91sam9x5ek/init.c     |    1 +
 arch/arm/boards/sama5d3_xplained/init.c |    1 +
 arch/arm/boards/sama5d3xek/init.c       |    1 +
 4 files changed, 4 insertions(+)
arch/arm/boards/at91sam9n12ek/init.c +1 -0
index a206d6b..818a598 100644
@@ -47,6 +47,7 @@ static struct atmel_nand_data nand_pdata = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PD5,
 	.enable_pin	= AT91_PIN_PD4,
+	.has_pmecc	= 1,
 	.ecc_mode	= NAND_ECC_HW,
 	.pmecc_sector_size = 512,
 	.pmecc_corr_cap = 2,
arch/arm/boards/at91sam9x5ek/init.c +1 -0
index 62e5652..183ddc7 100644
@@ -57,6 +57,7 @@ static struct atmel_nand_data nand_pdata = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PD5,
 	.enable_pin	= AT91_PIN_PD4,
+	.has_pmecc	= 1,
 	.ecc_mode	= NAND_ECC_HW,
 	.pmecc_sector_size = 512,
 	.pmecc_corr_cap = 2,
arch/arm/boards/sama5d3_xplained/init.c +1 -0
index ae18863..b182802 100644
@@ -48,6 +48,7 @@ static struct atmel_nand_data nand_pdata = {
 	.rdy_pin	= -EINVAL,
 	.enable_pin	= -EINVAL,
 	.ecc_mode	= NAND_ECC_HW,
+	.has_pmecc	= 1,
 	.pmecc_sector_size = 512,
 	.pmecc_corr_cap = 4,
 #if defined(CONFIG_MTD_NAND_ATMEL_BUSWIDTH_16)
arch/arm/boards/sama5d3xek/init.c +1 -0
index 743197f..49d2b37 100644
@@ -63,6 +63,7 @@ static struct atmel_nand_data nand_pdata = {
 	.rdy_pin	= -EINVAL,
 	.enable_pin	= -EINVAL,
 	.ecc_mode	= NAND_ECC_HW,
+	.has_pmecc	= 1,
 	.pmecc_sector_size = 512,
 	.pmecc_corr_cap = 4,
 #if defined(CONFIG_MTD_NAND_ATMEL_BUSWIDTH_16)
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH v2 3/5 mtd: atmel_nand: retrieve ecc_mode from pdata

In reply to Raphaël Poggi

By retrieving the ecc_mode from pdata we can use the same code for device tree and non device tree probing. Which was not possible before, because ecc_mode was arbitrarily set to NAND_ECC_SOFT.

---
 drivers/mtd/nand/atmel_nand.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/atmel_nand.c +1 -1
index 3ec6450..780d266 100644
@@ -1157,7 +1157,7 @@ static int __init atmel_nand_probe(struct device_d *dev)
 		}
 	}
 
-	nand_chip->ecc.mode = NAND_ECC_SOFT;
+	nand_chip->ecc.mode = pdata->ecc_mode;
 
 	if (IS_ENABLED(CONFIG_NAND_ECC_HW) &&
 	    pdata->ecc_mode == NAND_ECC_HW) {
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH v2 4/5 board: atmel: initialise ecc_mode

In reply to Raphaël Poggi

This commit initialise the ecc_mode (NAND_ECC_SOFT) on atmel board init which missing it.

---
 arch/arm/boards/at91sam9260ek/init.c    |    1 +
 arch/arm/boards/at91sam9261ek/init.c    |    1 +
 arch/arm/boards/at91sam9263ek/init.c    |    1 +
 arch/arm/boards/at91sam9m10g45ek/init.c |    1 +
 arch/arm/boards/at91sam9m10ihd/init.c   |    1 +
 5 files changed, 5 insertions(+)
arch/arm/boards/at91sam9260ek/init.c +1 -0
index 1298dde..76e0195 100644
@@ -51,6 +51,7 @@ static struct atmel_nand_data nand_pdata = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.on_flash_bbt	= 1,
 };
 
arch/arm/boards/at91sam9261ek/init.c +1 -0
index 9ebc16a..7b8ce98 100644
@@ -46,6 +46,7 @@ static struct atmel_nand_data nand_pdata = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC15,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 #if defined(CONFIG_MTD_NAND_ATMEL_BUSWIDTH_16)
 	.bus_width_16	= 1,
 #else
arch/arm/boards/at91sam9263ek/init.c +1 -0
index 889b4c2..c8a9d5c 100644
@@ -43,6 +43,7 @@ static struct atmel_nand_data nand_pdata = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PA22,
 	.enable_pin	= AT91_PIN_PD15,
+	.ecc_mode	= NAND_ECC_SOFT,
 #if defined(CONFIG_MTD_NAND_ATMEL_BUSWIDTH_16)
 	.bus_width_16	= 1,
 #else
arch/arm/boards/at91sam9m10g45ek/init.c +1 -0
index 6503ebb..cdd7806 100644
@@ -67,6 +67,7 @@ static struct atmel_nand_data nand_pdata = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC8,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 #if defined(CONFIG_MTD_NAND_ATMEL_BUSWIDTH_16)
 	.bus_width_16	= 1,
 #else
arch/arm/boards/at91sam9m10ihd/init.c +1 -0
index fc37af4..a432e5c 100644
@@ -44,6 +44,7 @@ static struct atmel_nand_data nand_pdata = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC15,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,
 	.bus_width_16	= 0,
 	.on_flash_bbt	= 1,
 };
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

Re: [PATCH 4/5] board: atmel: initialise ecc_mode

Quoted 16 lines · Raphaël Poggi

This commit initialise the ecc_mode (NAND_ECC_SOFT) on atmel board init which missing it.

---
 arch/arm/boards/at91sam9260ek/init.c    |    1 +
 arch/arm/boards/at91sam9261ek/init.c    |    1 +
 arch/arm/boards/at91sam9263ek/init.c    |    1 +
 arch/arm/boards/at91sam9m10g45ek/init.c |    1 +
 arch/arm/boards/at91sam9m10ihd/init.c   |    1 +
 5 files changed, 5 insertions(+)
arch/arm/boards/at91sam9260ek/init.c +0 -0
index 1298dde..76e0195 100644

arch/arm/boards/at91sam9260ek/init.c static struct atmel_nand_data nand_pdata = { · line 54

Quoted 4 lines
arch/arm/boards/at91sam9260ek/init.c +1 -0
@@ -51,6 +51,7 @@ static struct atmel_nand_data nand_pdata = {
 	.det_pin	= -EINVAL,
 	.rdy_pin	= AT91_PIN_PC13,
 	.enable_pin	= AT91_PIN_PC14,
+	.ecc_mode	= NAND_ECC_SOFT,

You have to combine 3/5 and 4/5 in a single patch. Otherwise the ecc mode is not initialized correctly between both patches.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH v2 5/5 mtd: atmel_nand: add support for device tree

In reply to Raphaël Poggi
---
 drivers/mtd/nand/atmel_nand.c |  111 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 110 insertions(+), 1 deletion(-)
drivers/mtd/nand/atmel_nand.c +110 -1
index 780d266..a5d05d8 100644
@@ -28,6 +28,10 @@
 #include <init.h>
 #include <gpio.h>
 
+#include <of.h>
+#include <of_gpio.h>
+#include <of_mtd.h>
+
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 
@@ -1038,6 +1042,92 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
 #endif
 }
 
+static int atmel_nand_of_init(struct atmel_nand_host *host, struct device_node *np)
+{
+	u32 val;
+	u32 offset[2];
+	int ecc_mode;
+	struct atmel_nand_data *board = host->board;
+	enum of_gpio_flags flags = 0;
+
+	if (!IS_ENABLED(CONFIG_OFDEVICE))
+		return -ENOSYS;
+
+	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->enable_pin = of_get_gpio(np, 1);
+	board->det_pin = of_get_gpio(np, 2);
+
+	board->has_pmecc = of_property_read_bool(np, "atmel,has-pmecc");
+
+	if (!(board->ecc_mode == NAND_ECC_HW) || !board->has_pmecc)
+		return 0;	/* Not using PMECC */
+
+	/* use PMECC, get correction capability, sector size and lookup
+	* table offset.
+	* If correction bits and sector size are not specified, then
+	*   find
+	* them from NAND ONFI parameters.
+	*/
+	if (of_property_read_u32(np, "atmel,pmecc-cap", &val) == 0) {
+		if ((val != 2) && (val != 4) && (val != 8) && (val != 12) && (val != 24)) {
+			dev_err(host->dev, "Unsupported PMECC correction capability: %d"
+					" should be 2, 4, 8, 12 or 24\n", val);
+			return -EINVAL;
+		}
+
+		board->pmecc_corr_cap = (u8)val;
+	}
+
+	if (of_property_read_u32(np, "atmel,pmecc-sector-size", &val) == 0) {
+		if ((val != 512) && (val != 1024)) {
+				dev_err(host->dev, "Unsupported PMECC sector size: %d"
+					" should be 512 or 1024 bytes\n", val);
+			return -EINVAL;
+		}
+
+		board->pmecc_sector_size = (u16)val;
+	}
+
+	if (of_property_read_u32_array(np, "atmel,pmecc-lookup-table-offset", offset, 2) != 0) {
+		dev_err(host->dev, "Cannot get PMECC lookup table offset\n");
+		return -EINVAL;
+	}
+
+	if (!offset[0] && !offset[1]) {
+		dev_err(host->dev, "Invalid PMECC lookup table offset\n");
+		return -EINVAL;
+	}
+
+	board->pmecc_lookup_table_offset = (board->pmecc_sector_size == 512) ? offset[0] : offset[1];
+
+	return 0;
+}
+
 static int atmel_hw_nand_init_params(struct device_d *dev,
 					 struct atmel_nand_host *host)
 {
@@ -1093,7 +1183,7 @@ static int atmel_hw_nand_init_params(struct device_d *dev,
  */
 static int __init atmel_nand_probe(struct device_d *dev)
 {
-	struct atmel_nand_data *pdata = dev->platform_data;
+	struct atmel_nand_data *pdata = NULL;
 	struct atmel_nand_host *host;
 	struct mtd_info *mtd;
 	struct nand_chip *nand_chip;
@@ -1111,6 +1201,18 @@ static int __init atmel_nand_probe(struct device_d *dev)
 	host->board = pdata;
 	host->dev = dev;
 
+	if (dev->device_node) {
+		res = atmel_nand_of_init(host, dev->device_node);
+		if (res)
+			goto err_no_card;
+	} else {
+		pdata = kzalloc(sizeof(struct atmel_nand_data), GFP_KERNEL);
+		if (!pdata)
+			return -ENOMEM;
+
+		memcpy(host->board, dev->platform_data, sizeof(struct atmel_nand_data));
+	}
+
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
 	mtd->parent = dev;
@@ -1245,13 +1347,20 @@ err_hw_ecc:
 err_scan_ident:
 err_no_card:
 	atmel_nand_disable(host);
+	kfree(pdata);
 	kfree(host);
 	return res;
 }
 
+static struct of_device_id atmel_nand_dt_ids[] = {
+	{ .compatible = "atmel,at91rm9200-nand" },
+	{ /* sentinel */ }
+};
+
 static struct driver_d atmel_nand_driver = {
 	.name	= "atmel_nand",
 	.probe	= atmel_nand_probe,
+	.of_compatible	= DRV_OF_COMPAT(atmel_nand_dt_ids),
 };
 device_platform_driver(atmel_nand_driver);
 
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw
In reply to Raphaël Poggi

I forget to add a "v2" tag on the patches, do I need to resend all the serie ?

Thanks,
Raphaël Poggi

2014-08-05 11:14 GMT+02:00 Raphaël Poggi <[email protected]>:

Quoted 45 lines

Change since v1:
* Reorder patchs
* Fix some clean style issue.

This patchset adds the device tree support for the Atmel NAND driver.

The first patch removes the NAND_ATMEL_PMECC config. With this removal
we can manage in a better way the device tree / non device tree probing of the driver, because the plateform data and device tree share the same structure member and logics.

The second patch adds the has_pmecc on boards which need it.

The third patch retrieves the ecc_mode from the plateform data and remove this code:

        nand_chip->ecc.mode = NAND_ECC_SOFT;

which arbitrary sets the ecc.mode to NAND_ECC_SOFT and changes the value depending of the config and plateform data. With this, we can use the same logics for device tree and non device tree probing of the driver.

The fourth patch adds the ecc_mode on boards which are missing it (boards which use NAND_ECC_SOFT).

The fifth patch adds the device tree in the atmel_nand driver.

Raphaël Poggi (5) :
(1) mtd: nand: remove NAND_ATMEL_PMECC
(2) board: atmel: initialise the has_pmecc member
(3) mtd: atmel_nand: retrieve ecc_mode from pdata
(4) board: atmel: initialise ecc_mode
(5) mtd: atmel_nand: add support for device tree

 arch/arm/boards/at91sam9260ek/init.c    |    1 +
 arch/arm/boards/at91sam9261ek/init.c    |    1 +
 arch/arm/boards/at91sam9263ek/init.c    |    1 +
 arch/arm/boards/at91sam9m10g45ek/init.c |    1 +
 arch/arm/boards/at91sam9m10ihd/init.c   |    1 +
 arch/arm/boards/at91sam9n12ek/init.c    |    1 +
 arch/arm/boards/at91sam9x5ek/init.c     |    1 +
 arch/arm/boards/sama5d3_xplained/init.c |    1 +
 arch/arm/boards/sama5d3xek/init.c       |    1 +
 arch/arm/mach-at91/include/mach/board.h |    1 +
 drivers/mtd/nand/Kconfig                |    8 ---
 drivers/mtd/nand/atmel_nand.c           |  115 ++++++++++++++++++++++++++++++-
 12 files changed, 122 insertions(+), 11 deletions(-)
Quoted 4 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox