* [PATCH 0/5] Add device tree support of Atmel NAND driver
@ 2014-08-01 13:23 Raphaël Poggi
2014-08-01 13:23 ` [PATCH 1/5] mtd: atmel_nand: add support for device tree Raphaël Poggi
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Raphaël Poggi @ 2014-08-01 13:23 UTC (permalink / raw)
To: barebox
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/5] mtd: atmel_nand: add support for device tree
2014-08-01 13:23 [PATCH 0/5] Add device tree support of Atmel NAND driver Raphaël Poggi
@ 2014-08-01 13:23 ` Raphaël Poggi
2014-08-04 17:43 ` Sascha Hauer
2014-08-01 13:23 ` [PATCH 2/5] mtd: nand: remove NAND_ATMEL_PMECC Raphaël Poggi
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Raphaël Poggi @ 2014-08-01 13:23 UTC (permalink / raw)
To: barebox; +Cc: Raphaël Poggi
Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
---
drivers/mtd/nand/atmel_nand.c | 108 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 107 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 337e225..b7b0e3a 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -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);
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/5] mtd: nand: remove NAND_ATMEL_PMECC
2014-08-01 13:23 [PATCH 0/5] Add device tree support of Atmel NAND driver Raphaël Poggi
2014-08-01 13:23 ` [PATCH 1/5] mtd: atmel_nand: add support for device tree Raphaël Poggi
@ 2014-08-01 13:23 ` Raphaël Poggi
2014-08-01 13:23 ` [PATCH 3/5] board: atmel: initialise the has_pmecc member Raphaël Poggi
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Raphaël Poggi @ 2014-08-01 13:23 UTC (permalink / raw)
To: barebox; +Cc: 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.
Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
---
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(-)
diff --git a/arch/arm/mach-at91/include/mach/board.h b/arch/arm/mach-at91/include/mach/board.h
index aa0fdae..e2307ed 100644
--- a/arch/arm/mach-at91/include/mach/board.h
+++ b/arch/arm/mach-at91/include/mach/board.h
@@ -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;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 04fe3c8..d49eae3 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -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"
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index b7b0e3a..eba7125 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -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);
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/5] board: atmel: initialise the has_pmecc member
2014-08-01 13:23 [PATCH 0/5] Add device tree support of Atmel NAND driver Raphaël Poggi
2014-08-01 13:23 ` [PATCH 1/5] mtd: atmel_nand: add support for device tree Raphaël Poggi
2014-08-01 13:23 ` [PATCH 2/5] mtd: nand: remove NAND_ATMEL_PMECC Raphaël Poggi
@ 2014-08-01 13:23 ` Raphaël Poggi
2014-08-01 13:23 ` [PATCH 4/5] mtd: atmel_nand: retrieve ecc_mode from pdata Raphaël Poggi
2014-08-01 13:23 ` [PATCH 5/5] board: atmel: initialise ecc_mode Raphaël Poggi
4 siblings, 0 replies; 8+ messages in thread
From: Raphaël Poggi @ 2014-08-01 13:23 UTC (permalink / raw)
To: barebox; +Cc: 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(+)
diff --git a/arch/arm/boards/at91sam9n12ek/init.c b/arch/arm/boards/at91sam9n12ek/init.c
index a206d6b..818a598 100644
--- a/arch/arm/boards/at91sam9n12ek/init.c
+++ b/arch/arm/boards/at91sam9n12ek/init.c
@@ -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,
diff --git a/arch/arm/boards/at91sam9x5ek/init.c b/arch/arm/boards/at91sam9x5ek/init.c
index 62e5652..183ddc7 100644
--- a/arch/arm/boards/at91sam9x5ek/init.c
+++ b/arch/arm/boards/at91sam9x5ek/init.c
@@ -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,
diff --git a/arch/arm/boards/sama5d3_xplained/init.c b/arch/arm/boards/sama5d3_xplained/init.c
index ae18863..b182802 100644
--- a/arch/arm/boards/sama5d3_xplained/init.c
+++ b/arch/arm/boards/sama5d3_xplained/init.c
@@ -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)
diff --git a/arch/arm/boards/sama5d3xek/init.c b/arch/arm/boards/sama5d3xek/init.c
index 743197f..49d2b37 100644
--- a/arch/arm/boards/sama5d3xek/init.c
+++ b/arch/arm/boards/sama5d3xek/init.c
@@ -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)
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/5] mtd: atmel_nand: retrieve ecc_mode from pdata
2014-08-01 13:23 [PATCH 0/5] Add device tree support of Atmel NAND driver Raphaël Poggi
` (2 preceding siblings ...)
2014-08-01 13:23 ` [PATCH 3/5] board: atmel: initialise the has_pmecc member Raphaël Poggi
@ 2014-08-01 13:23 ` Raphaël Poggi
2014-08-01 13:23 ` [PATCH 5/5] board: atmel: initialise ecc_mode Raphaël Poggi
4 siblings, 0 replies; 8+ messages in thread
From: Raphaël Poggi @ 2014-08-01 13:23 UTC (permalink / raw)
To: barebox; +Cc: 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.
Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
---
drivers/mtd/nand/atmel_nand.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index eba7125..82bee92 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -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) {
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/5] board: atmel: initialise ecc_mode
2014-08-01 13:23 [PATCH 0/5] Add device tree support of Atmel NAND driver Raphaël Poggi
` (3 preceding siblings ...)
2014-08-01 13:23 ` [PATCH 4/5] mtd: atmel_nand: retrieve ecc_mode from pdata Raphaël Poggi
@ 2014-08-01 13:23 ` Raphaël Poggi
4 siblings, 0 replies; 8+ messages in thread
From: Raphaël Poggi @ 2014-08-01 13:23 UTC (permalink / raw)
To: barebox; +Cc: Raphaël Poggi
This commit initialise the ecc_mode (NAND_ECC_SOFT) on atmel board init which missing it.
Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
---
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(+)
diff --git a/arch/arm/boards/at91sam9260ek/init.c b/arch/arm/boards/at91sam9260ek/init.c
index 1298dde..76e0195 100644
--- a/arch/arm/boards/at91sam9260ek/init.c
+++ b/arch/arm/boards/at91sam9260ek/init.c
@@ -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,
};
diff --git a/arch/arm/boards/at91sam9261ek/init.c b/arch/arm/boards/at91sam9261ek/init.c
index 9ebc16a..7b8ce98 100644
--- a/arch/arm/boards/at91sam9261ek/init.c
+++ b/arch/arm/boards/at91sam9261ek/init.c
@@ -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
diff --git a/arch/arm/boards/at91sam9263ek/init.c b/arch/arm/boards/at91sam9263ek/init.c
index 889b4c2..c8a9d5c 100644
--- a/arch/arm/boards/at91sam9263ek/init.c
+++ b/arch/arm/boards/at91sam9263ek/init.c
@@ -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
diff --git a/arch/arm/boards/at91sam9m10g45ek/init.c b/arch/arm/boards/at91sam9m10g45ek/init.c
index 6503ebb..cdd7806 100644
--- a/arch/arm/boards/at91sam9m10g45ek/init.c
+++ b/arch/arm/boards/at91sam9m10g45ek/init.c
@@ -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
diff --git a/arch/arm/boards/at91sam9m10ihd/init.c b/arch/arm/boards/at91sam9m10ihd/init.c
index fc37af4..a432e5c 100644
--- a/arch/arm/boards/at91sam9m10ihd/init.c
+++ b/arch/arm/boards/at91sam9m10ihd/init.c
@@ -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,
};
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/5] mtd: atmel_nand: add support for device tree
2014-08-01 13:23 ` [PATCH 1/5] mtd: atmel_nand: add support for device tree Raphaël Poggi
@ 2014-08-04 17:43 ` Sascha Hauer
2014-08-04 18:26 ` Raphaël Poggi
0 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2014-08-04 17:43 UTC (permalink / raw)
To: Raphaël Poggi; +Cc: barebox
On Fri, Aug 01, 2014 at 03:23:20PM +0200, Raphaël Poggi wrote:
> Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
> ---
> drivers/mtd/nand/atmel_nand.c | 108 ++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 107 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
> index 337e225..b7b0e3a 100644
> --- a/drivers/mtd/nand/atmel_nand.c
> +++ b/drivers/mtd/nand/atmel_nand.c
> @@ -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;
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.
> +
> + 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.
> + 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;
You only use this memory...
> +
> 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.
> + }
> + 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 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/5] mtd: atmel_nand: add support for device tree
2014-08-04 17:43 ` Sascha Hauer
@ 2014-08-04 18:26 ` Raphaël Poggi
0 siblings, 0 replies; 8+ messages in thread
From: Raphaël Poggi @ 2014-08-04 18:26 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
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 <s.hauer@pengutronix.de>:
> On Fri, Aug 01, 2014 at 03:23:20PM +0200, Raphaël Poggi wrote:
>> Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
>> ---
>> drivers/mtd/nand/atmel_nand.c | 108 ++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 107 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
>> index 337e225..b7b0e3a 100644
>> --- a/drivers/mtd/nand/atmel_nand.c
>> +++ b/drivers/mtd/nand/atmel_nand.c
>> @@ -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;
>
> 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.
>
>> +
>> + 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.
>
>> + 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;
>
> You only use this memory...
>
>> +
>> 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.
>
>> + }
>> + 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 |
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-08-04 18:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 13:23 [PATCH 0/5] Add device tree support of Atmel NAND driver Raphaël Poggi
2014-08-01 13:23 ` [PATCH 1/5] mtd: atmel_nand: add support for device tree Raphaël Poggi
2014-08-04 17:43 ` Sascha Hauer
2014-08-04 18:26 ` Raphaël Poggi
2014-08-01 13:23 ` [PATCH 2/5] mtd: nand: remove NAND_ATMEL_PMECC Raphaël Poggi
2014-08-01 13:23 ` [PATCH 3/5] board: atmel: initialise the has_pmecc member Raphaël Poggi
2014-08-01 13:23 ` [PATCH 4/5] mtd: atmel_nand: retrieve ecc_mode from pdata Raphaël Poggi
2014-08-01 13:23 ` [PATCH 5/5] board: atmel: initialise ecc_mode Raphaël Poggi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox