u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: raw: convert nand_dt_init() to ofnode_xx() interface
@ 2021-09-13 14:25 Patrice Chotard
  2021-09-28  6:30 ` Heiko Schocher
  2021-09-28 18:44 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Patrice Chotard @ 2021-09-13 14:25 UTC (permalink / raw)
  To: u-boot
  Cc: Patrice CHOTARD, Patrick DELAUNAY, U-Boot STM32, Farhan Ali,
	Sean Anderson, Simon Glass

nand_dt_init() is still using fdtdec_xx() interface.
If OF_LIVE flag is enabled, dt property can't be get anymore.
Updating all fdtdec_xx() interface to ofnode_xx() to solve this issue.

For doing this, node parameter type must be ofnode.

First idea was to convert "node" parameter to ofnode type inside
nand_dt_init() using offset_to_ofnode(node). But offset_to_ofnode()
is not bijective, in case OF_LIVE flag is enabled, it performs an assert().

So, this leads to update nand_chip struct flash_node field from int to
ofnode and to update all nand_dt_init() callers.

Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
---

 drivers/mtd/nand/raw/denali.c          |  2 +-
 drivers/mtd/nand/raw/mxs_nand.c        |  2 +-
 drivers/mtd/nand/raw/nand_base.c       | 27 +++++++++++---------------
 drivers/mtd/nand/raw/stm32_fmc2_nand.c |  2 +-
 drivers/mtd/nand/raw/sunxi_nand.c      |  2 +-
 include/linux/mtd/rawnand.h            |  6 +++---
 6 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c
index ab91db8546..c827f80281 100644
--- a/drivers/mtd/nand/raw/denali.c
+++ b/drivers/mtd/nand/raw/denali.c
@@ -1246,7 +1246,7 @@ int denali_init(struct denali_nand_info *denali)
 
 	denali->active_bank = DENALI_INVALID_BANK;
 
-	chip->flash_node = dev_of_offset(denali->dev);
+	chip->flash_node = dev_ofnode(denali->dev);
 	/* Fallback to the default name if DT did not give "label" property */
 	if (!mtd->name)
 		mtd->name = "denali-nand";
diff --git a/drivers/mtd/nand/raw/mxs_nand.c b/drivers/mtd/nand/raw/mxs_nand.c
index e6bbfac4d6..748056a43e 100644
--- a/drivers/mtd/nand/raw/mxs_nand.c
+++ b/drivers/mtd/nand/raw/mxs_nand.c
@@ -1379,7 +1379,7 @@ int mxs_nand_init_ctrl(struct mxs_nand_info *nand_info)
 	nand->options |= NAND_NO_SUBPAGE_WRITE;
 
 	if (nand_info->dev)
-		nand->flash_node = dev_of_offset(nand_info->dev);
+		nand->flash_node = dev_ofnode(nand_info->dev);
 
 	nand->cmd_ctrl		= mxs_nand_cmd_ctrl;
 
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 3679ee727e..b1fd779884 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -29,9 +29,6 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 #include <common.h>
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-#include <fdtdec.h>
-#endif
 #include <log.h>
 #include <malloc.h>
 #include <watchdog.h>
@@ -4576,23 +4573,20 @@ ident_done:
 EXPORT_SYMBOL(nand_get_flash_type);
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-#include <asm/global_data.h>
-DECLARE_GLOBAL_DATA_PTR;
 
-static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node)
+static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node)
 {
 	int ret, ecc_mode = -1, ecc_strength, ecc_step;
-	const void *blob = gd->fdt_blob;
 	const char *str;
 
-	ret = fdtdec_get_int(blob, node, "nand-bus-width", -1);
+	ret = ofnode_read_s32_default(node, "nand-bus-width", -1);
 	if (ret == 16)
 		chip->options |= NAND_BUSWIDTH_16;
 
-	if (fdtdec_get_bool(blob, node, "nand-on-flash-bbt"))
+	if (ofnode_read_bool(node, "nand-on-flash-bbt"))
 		chip->bbt_options |= NAND_BBT_USE_FLASH;
 
-	str = fdt_getprop(blob, node, "nand-ecc-mode", NULL);
+	str = ofnode_read_string(node, "nand-ecc-mode");
 	if (str) {
 		if (!strcmp(str, "none"))
 			ecc_mode = NAND_ECC_NONE;
@@ -4608,9 +4602,10 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node)
 			ecc_mode = NAND_ECC_SOFT_BCH;
 	}
 
-
-	ecc_strength = fdtdec_get_int(blob, node, "nand-ecc-strength", -1);
-	ecc_step = fdtdec_get_int(blob, node, "nand-ecc-step-size", -1);
+	ecc_strength = ofnode_read_s32_default(node,
+					       "nand-ecc-strength", -1);
+	ecc_step = ofnode_read_s32_default(node,
+					   "nand-ecc-step-size", -1);
 
 	if ((ecc_step >= 0 && !(ecc_strength >= 0)) ||
 	    (!(ecc_step >= 0) && ecc_strength >= 0)) {
@@ -4627,13 +4622,13 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node)
 	if (ecc_step > 0)
 		chip->ecc.size = ecc_step;
 
-	if (fdt_getprop(blob, node, "nand-ecc-maximize", NULL))
+	if (ofnode_read_bool(node, "nand-ecc-maximize"))
 		chip->ecc.options |= NAND_ECC_MAXIMIZE;
 
 	return 0;
 }
 #else
-static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node)
+static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node)
 {
 	return 0;
 }
@@ -4657,7 +4652,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
 	struct nand_flash_dev *type;
 	int ret;
 
-	if (chip->flash_node) {
+	if (ofnode_valid(chip->flash_node)) {
 		ret = nand_dt_init(mtd, chip, chip->flash_node);
 		if (ret)
 			return ret;
diff --git a/drivers/mtd/nand/raw/stm32_fmc2_nand.c b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
index fd81a9500b..e17f1f8975 100644
--- a/drivers/mtd/nand/raw/stm32_fmc2_nand.c
+++ b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
@@ -823,7 +823,7 @@ static int stm32_fmc2_nfc_parse_child(struct stm32_fmc2_nfc *nfc, ofnode node)
 		nand->cs_used[i] = cs[i];
 	}
 
-	nand->chip.flash_node = ofnode_to_offset(node);
+	nand->chip.flash_node = node;
 
 	return 0;
 }
diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
index 7bc6ec7bee..c378f08f68 100644
--- a/drivers/mtd/nand/raw/sunxi_nand.c
+++ b/drivers/mtd/nand/raw/sunxi_nand.c
@@ -1711,7 +1711,7 @@ static int sunxi_nand_chip_init(int node, struct sunxi_nfc *nfc, int devnum)
 	 * in the DT.
 	 */
 	nand->ecc.mode = NAND_ECC_HW;
-	nand->flash_node = node;
+	nand->flash_node = offset_to_ofnode(node);
 	nand->select_chip = sunxi_nfc_select_chip;
 	nand->cmd_ctrl = sunxi_nfc_cmd_ctrl;
 	nand->read_buf = sunxi_nfc_read_buf;
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index 66febc6b72..2fba9dc317 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -891,7 +891,7 @@ struct nand_chip {
 	void __iomem *IO_ADDR_R;
 	void __iomem *IO_ADDR_W;
 
-	int flash_node;
+	ofnode flash_node;
 
 	uint8_t (*read_byte)(struct mtd_info *mtd);
 	u16 (*read_word)(struct mtd_info *mtd);
@@ -973,12 +973,12 @@ struct nand_chip {
 static inline void nand_set_flash_node(struct nand_chip *chip,
 				       ofnode node)
 {
-	chip->flash_node = ofnode_to_offset(node);
+	chip->flash_node = node;
 }
 
 static inline ofnode nand_get_flash_node(struct nand_chip *chip)
 {
-	return offset_to_ofnode(chip->flash_node);
+	return chip->flash_node;
 }
 
 static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
-- 
2.17.1


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

* Re: [PATCH] mtd: nand: raw: convert nand_dt_init() to ofnode_xx() interface
  2021-09-13 14:25 [PATCH] mtd: nand: raw: convert nand_dt_init() to ofnode_xx() interface Patrice Chotard
@ 2021-09-28  6:30 ` Heiko Schocher
  2021-09-28 18:44 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Schocher @ 2021-09-28  6:30 UTC (permalink / raw)
  To: Patrice Chotard, u-boot
  Cc: Patrick DELAUNAY, U-Boot STM32, Farhan Ali, Sean Anderson, Simon Glass

Hello Patrice,

On 13.09.21 16:25, Patrice Chotard wrote:
> nand_dt_init() is still using fdtdec_xx() interface.
> If OF_LIVE flag is enabled, dt property can't be get anymore.
> Updating all fdtdec_xx() interface to ofnode_xx() to solve this issue.
> 
> For doing this, node parameter type must be ofnode.
> 
> First idea was to convert "node" parameter to ofnode type inside
> nand_dt_init() using offset_to_ofnode(node). But offset_to_ofnode()
> is not bijective, in case OF_LIVE flag is enabled, it performs an assert().
> 
> So, this leads to update nand_chip struct flash_node field from int to
> ofnode and to update all nand_dt_init() callers.
> 
> Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
> ---
> 
>  drivers/mtd/nand/raw/denali.c          |  2 +-
>  drivers/mtd/nand/raw/mxs_nand.c        |  2 +-
>  drivers/mtd/nand/raw/nand_base.c       | 27 +++++++++++---------------
>  drivers/mtd/nand/raw/stm32_fmc2_nand.c |  2 +-
>  drivers/mtd/nand/raw/sunxi_nand.c      |  2 +-
>  include/linux/mtd/rawnand.h            |  6 +++---
>  6 files changed, 18 insertions(+), 23 deletions(-)

Applied to u-boot-i2c next

Thanks!

bye,
Heiko


-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de

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

* Re: [PATCH] mtd: nand: raw: convert nand_dt_init() to ofnode_xx() interface
  2021-09-13 14:25 [PATCH] mtd: nand: raw: convert nand_dt_init() to ofnode_xx() interface Patrice Chotard
  2021-09-28  6:30 ` Heiko Schocher
@ 2021-09-28 18:44 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2021-09-28 18:44 UTC (permalink / raw)
  To: Patrice Chotard
  Cc: u-boot, Patrick DELAUNAY, U-Boot STM32, Farhan Ali,
	Sean Anderson, Simon Glass

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

On Mon, Sep 13, 2021 at 04:25:53PM +0200, Patrice Chotard wrote:

> nand_dt_init() is still using fdtdec_xx() interface.
> If OF_LIVE flag is enabled, dt property can't be get anymore.
> Updating all fdtdec_xx() interface to ofnode_xx() to solve this issue.
> 
> For doing this, node parameter type must be ofnode.
> 
> First idea was to convert "node" parameter to ofnode type inside
> nand_dt_init() using offset_to_ofnode(node). But offset_to_ofnode()
> is not bijective, in case OF_LIVE flag is enabled, it performs an assert().
> 
> So, this leads to update nand_chip struct flash_node field from int to
> ofnode and to update all nand_dt_init() callers.
> 
> Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

end of thread, other threads:[~2021-09-28 18:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13 14:25 [PATCH] mtd: nand: raw: convert nand_dt_init() to ofnode_xx() interface Patrice Chotard
2021-09-28  6:30 ` Heiko Schocher
2021-09-28 18:44 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).