Skip to contentSkip to conversation

Add device tree support of Atmel NAND driver

PATCH Applied Raphaël Poggi 2 participants 5 messages Sep 1, 2014 – Sep 2, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover Add device tree support of Atmel NAND driver

Change since v2:
* Combine in one patch the creation and initialisation of "has_pmecc" structure member
* Combine patch "[PATCH 3/5] mtd: atmel_nand: retrieve ecc_mode from pdata" and "[PATCH 4/5] board: atmel: initialise ecc_mode"
* Let NAND_ATMEL_PMECC config, but change the test in atmel_nand

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 add the has_pmecc structure member to be able to retrieve pmecc from device tree and adds the has_pmecc on boards which need it.

The second 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. It also adds the ecc_mode on boards which are missing it (boards which use NAND_ECC_SOFT).

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

Raphaël Poggi (4):
(1) mtd: nand: add has_pmecc member
(2) mtd: atmel_nand: retrieve ecc_mode from pdata
(3) 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/atmel_nand.c           |  115 ++++++++++++++++++++++++++++++-
 11 files changed, 122 insertions(+), 3 deletions(-)

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

#1 lore raw

PATCH v3 1/3 mtd: nand: add has_pmecc member

By adding this structure member, we can retrieve the pmecc config, through the device tree.

---
 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/atmel_nand.c           |    2 +-
 6 files changed, 6 insertions(+), 1 deletion(-)
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)
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/atmel_nand.c +1 -1
index 337e225..220ec5c 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 (IS_ENABLED(CONFIG_NAND_ATMEL_PMECC) && 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

PATCH v3 2/3 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.

---
 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 +
 drivers/mtd/nand/atmel_nand.c           |    2 +-
 6 files changed, 6 insertions(+), 1 deletion(-)
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,
 };
drivers/mtd/nand/atmel_nand.c +1 -1
index 220ec5c..2246602 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
#3 lore raw

PATCH v3 3/3 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 2246602..910ecc3 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
Applied
#4 lore raw
In reply to Raphaël Poggi
Quoted 23 lines · Raphaël Poggi

Change since v2:
* Combine in one patch the creation and initialisation of "has_pmecc" structure member
* Combine patch "[PATCH 3/5] mtd: atmel_nand: retrieve ecc_mode from pdata" and "[PATCH 4/5] board: atmel: initialise ecc_mode"
* Let NAND_ATMEL_PMECC config, but change the test in atmel_nand

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 add the has_pmecc structure member to be able to retrieve pmecc from device tree and adds the has_pmecc on boards which need it.

The second 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. It also adds the ecc_mode on boards which are missing it (boards which use NAND_ECC_SOFT).

Quoted 6 lines

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

Raphaël Poggi (4):
(1) mtd: nand: add has_pmecc member
(2) mtd: atmel_nand: retrieve ecc_mode from pdata
(3) mtd: atmel_nand: add support for device tree

Applied, thanks

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