Skip to contentSkip to conversation

Add device tree support of Atmel NAND driver

PATCH Superseded Raphaël Poggi 3 participants 8 messages Aug 1, 2014 – Aug 4, 2014

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add device tree support of Atmel NAND driver

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

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

The second 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 third patch adds the has_pmecc on boards which need it.

The fourth 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 fifth patch adds the ecc_mode on boards which are missing it (boards which use NAND_ECC_SOFT).

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

 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           |  112 ++++++++++++++++++++++++++++++-
 12 files changed, 119 insertions(+), 11 deletions(-)

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

#4 lore raw

PATCH 2/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 b7b0e3a..eba7125 100644
@@ -1319,7 +1319,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
#5 lore raw

PATCH 3/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
#7 lore raw

PATCH 5/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
#6 lore raw

PATCH 4/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 |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/atmel_nand.c +2 -2
index eba7125..82bee92 100644
@@ -1208,7 +1208,7 @@ static int __init atmel_nand_probe(struct device_d *dev)
 		goto err_no_card;
 	}
 	else {
-	    pdata = dev->platform_data;
+	    memcpy(host->board, dev->platform_data, sizeof(struct atmel_nand_data));
 	}
 
 	nand_chip->priv = host;		/* link the private data structures */
@@ -1257,7 +1257,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
#1 lore raw

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

In reply to Raphaël Poggi
---
 drivers/mtd/nand/atmel_nand.c |  108 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 107 insertions(+), 1 deletion(-)
drivers/mtd/nand/atmel_nand.c +107 -1
index 337e225..b7b0e3a 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,89 @@ 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 (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 +1180,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;
 	struct atmel_nand_host *host;
 	struct mtd_info *mtd;
 	struct nand_chip *nand_chip;
@@ -1104,6 +1191,10 @@ static int __init atmel_nand_probe(struct device_d *dev)
 	if (!host)
 		return -ENOMEM;
 
+	pdata = kzalloc(sizeof(struct atmel_nand_data), GFP_KERNEL);
+	if (!pdata)
+		return -ENOMEM;
+
 	host->io_base = dev_request_mem_region(dev, 0);
 
 	mtd = &host->mtd;
@@ -1111,6 +1202,15 @@ 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 = dev->platform_data;
+	}
+
 	nand_chip->priv = host;		/* link the private data structures */
 	mtd->priv = nand_chip;
 	mtd->parent = dev;
@@ -1249,9 +1349,15 @@ err_no_card:
 	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
#2 lore raw

Re: [PATCH 1/5] mtd: atmel_nand: add support for device tree

Quoted 21 lines · Raphaël Poggi
---
 drivers/mtd/nand/atmel_nand.c |  108 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 107 insertions(+), 1 deletion(-)
drivers/mtd/nand/atmel_nand.c +4 -0
index 337e225..b7b0e3a 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>
 

drivers/mtd/nand/atmel_nand.c static void atmel_nand_hwctl(struct mtd_info *mtd, int mode) · line 1051

Quoted 10 lines
drivers/mtd/nand/atmel_nand.c +7 -0
@@ -1038,6 +1042,89 @@ 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;

Please add a:

	if (!IS_ENABLED(CONFIG_OFDEVICE))
		return -ENOSYS;

to this function. It will allow the compiler to throw it away when device tree support is disabled.

drivers/mtd/nand/atmel_nand.c static void atmel_nand_hwctl(struct mtd_info *mtd, int mode) · line 1054

Quoted 3 lines
drivers/mtd/nand/atmel_nand.c +3 -0
+
+	if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+	   if (val >= 32) {

Please fix the coding style. First indentation here is a tab, but the second is 4 spaces. Indentation should be tabs generally.

Quoted 86 lines
drivers/mtd/nand/atmel_nand.c +74 -1
+		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 +1180,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;
 	struct atmel_nand_host *host;
 	struct mtd_info *mtd;
 	struct nand_chip *nand_chip;

drivers/mtd/nand/atmel_nand.c static int __init atmel_nand_probe(struct device_d *dev) · line 1196

Quoted 6 lines
drivers/mtd/nand/atmel_nand.c +3 -0
@@ -1104,6 +1191,10 @@ static int __init atmel_nand_probe(struct device_d *dev)
 	if (!host)
 		return -ENOMEM;
 
+	pdata = kzalloc(sizeof(struct atmel_nand_data), GFP_KERNEL);
+	if (!pdata)
+		return -ENOMEM;

You only use this memory...

drivers/mtd/nand/atmel_nand.c static int __init atmel_nand_probe(struct device_d *dev) · line 1208

Quoted 12 lines
drivers/mtd/nand/atmel_nand.c +5 -0
+
 	host->io_base = dev_request_mem_region(dev, 0);
 
 	mtd = &host->mtd;
@@ -1111,6 +1202,15 @@ 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;

...in this code path. Please add the memory allocation here then.

drivers/mtd/nand/atmel_nand.c static int __init atmel_nand_probe(struct device_d *dev) · line 1213

Quoted 5 lines
drivers/mtd/nand/atmel_nand.c +5 -0
+	}
+	else {
+	    pdata = dev->platform_data;
+	}
+

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
#3 lore raw

Re: [PATCH 1/5] mtd: atmel_nand: add support for device tree

Hi Sascha,

Thanks for your review.

I will send a v2 with the modification. I will also reorder patches in the patchset.

Raphaël

2014-08-04 19:43 GMT+02:00 Sascha Hauer <[email protected]>:

Quoted 172 lines · Raphaël Poggi
Quoted 21 lines
---
 drivers/mtd/nand/atmel_nand.c |  108 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 107 insertions(+), 1 deletion(-)
drivers/mtd/nand/atmel_nand.c +4 -0
index 337e225..b7b0e3a 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>
 

drivers/mtd/nand/atmel_nand.c static void atmel_nand_hwctl(struct mtd_info *mtd, int mode) · line 1051

Quoted 10 lines
drivers/mtd/nand/atmel_nand.c +7 -0
@@ -1038,6 +1042,89 @@ 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;

Please add a:

        if (!IS_ENABLED(CONFIG_OFDEVICE))
                return -ENOSYS;

to this function. It will allow the compiler to throw it away when device tree support is disabled.

drivers/mtd/nand/atmel_nand.c static void atmel_nand_hwctl(struct mtd_info *mtd, int mode) · line 1054

Quoted 3 lines
drivers/mtd/nand/atmel_nand.c +3 -0
+
+     if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+        if (val >= 32) {

Please fix the coding style. First indentation here is a tab, but the second is 4 spaces. Indentation should be tabs generally.

Quoted 86 lines
drivers/mtd/nand/atmel_nand.c +74 -1
+             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 +1180,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;
      struct atmel_nand_host *host;
      struct mtd_info *mtd;
      struct nand_chip *nand_chip;

drivers/mtd/nand/atmel_nand.c static int __init atmel_nand_probe(struct device_d *dev) · line 1196

Quoted 6 lines
drivers/mtd/nand/atmel_nand.c +3 -0
@@ -1104,6 +1191,10 @@ static int __init atmel_nand_probe(struct device_d *dev)
      if (!host)
              return -ENOMEM;
 
+     pdata = kzalloc(sizeof(struct atmel_nand_data), GFP_KERNEL);
+     if (!pdata)
+             return -ENOMEM;

You only use this memory...

drivers/mtd/nand/atmel_nand.c static int __init atmel_nand_probe(struct device_d *dev) · line 1208

Quoted 12 lines
drivers/mtd/nand/atmel_nand.c +5 -0
+
      host->io_base = dev_request_mem_region(dev, 0);
 
      mtd = &host->mtd;
@@ -1111,6 +1202,15 @@ 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;

...in this code path. Please add the memory allocation here then.

drivers/mtd/nand/atmel_nand.c static int __init atmel_nand_probe(struct device_d *dev) · line 1213

Quoted 5 lines
drivers/mtd/nand/atmel_nand.c +5 -0
+     }
+     else {
+         pdata = dev->platform_data;
+     }
+

Sascha

--

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 |
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